#list_int 並べて出力 print (' '.join(map(str,ans_li)))

#list_str 並べて出力 print (' '.join(list))



from collections import defaultdict

import sys,heapq,bisect,math,itertools,string,queue,datetime

sys.setrecursionlimit(10**8)

INF = float('inf')

mod = 10**9+7

eps = 10**-7

AtoZ = [chr(i) for i in range(65,65+26)]

atoz = [chr(i) for i in range(97,97+26)]



def inpl(): return list(map(int, input().split()))

def inpl_s(): return list(input().split())



N,M = inpl()

aa = inpl()

ans = 0



ed = [0]

SUM_L = defaultdict(int)

SUM_R = defaultdict(int)

SUM_L[0] += 1

SUM_R[0] += 1

SUM = sum(aa) % M



tmpL = tmpR = 0

for i in range(N):

	tmpL += aa[i]

	tmpL %= M

	if SUM_L[tmpL] == 0:

		ed.append(tmpL)

	SUM_L[tmpL] += 1



	tmpR += aa[N-i-1]

	tmpR %= M

	SUM_R[tmpR] += 1



ans = 0

for l in ed:

	numL = SUM_L[l]

	r = (SUM - l) % M

	numR = SUM_R[r]

	ans += numL * (numR-1)



print((ans//2))

from collections import defaultdict

import sys,heapq,bisect,math,itertools,string,queue,datetime

sys.setrecursionlimit(10**8)

INF = float('inf')

mod = 10**9+7

eps = 10**-7

AtoZ = [chr(i) for i in range(65,65+26)]

atoz = [chr(i) for i in range(97,97+26)]



def inpl(): return list(map(int, input().split()))

def inpl_s(): return list(input().split())



N,M = inpl()

aa = inpl()

ans = 0

modSUM = defaultdict(int)



tmp = 0

modSUM[0] += 1

for a in aa:

	tmp += a

	tmp %= M

	ans += modSUM[tmp]

	modSUM[tmp] += 1



print(ans)

# list_int 並べて出力 print (' '.join(map(str,ans_li)))
# list_str 並べて出力 print (' '.join(list))
from collections import defaultdict
import sys, heapq, bisect, math, itertools, string, queue, datetime

sys.setrecursionlimit(10**8)
INF = float("inf")
mod = 10**9 + 7
eps = 10**-7
AtoZ = [chr(i) for i in range(65, 65 + 26)]
atoz = [chr(i) for i in range(97, 97 + 26)]


def inpl():
    return list(map(int, input().split()))


def inpl_s():
    return list(input().split())


N, M = inpl()
aa = inpl()
ans = 0
ed = [0]
SUM_L = defaultdict(int)
SUM_R = defaultdict(int)
SUM_L[0] += 1
SUM_R[0] += 1
SUM = sum(aa) % M
tmpL = tmpR = 0
for i in range(N):
    tmpL += aa[i]
    tmpL %= M
    if SUM_L[tmpL] == 0:
        ed.append(tmpL)
    SUM_L[tmpL] += 1
    tmpR += aa[N - i - 1]
    tmpR %= M
    SUM_R[tmpR] += 1
ans = 0
for l in ed:
    numL = SUM_L[l]
    r = (SUM - l) % M
    numR = SUM_R[r]
    ans += numL * (numR - 1)
print((ans // 2))

from collections import defaultdict
import sys, heapq, bisect, math, itertools, string, queue, datetime

sys.setrecursionlimit(10**8)
INF = float("inf")
mod = 10**9 + 7
eps = 10**-7
AtoZ = [chr(i) for i in range(65, 65 + 26)]
atoz = [chr(i) for i in range(97, 97 + 26)]


def inpl():
    return list(map(int, input().split()))


def inpl_s():
    return list(input().split())


N, M = inpl()
aa = inpl()
ans = 0
modSUM = defaultdict(int)
tmp = 0
modSUM[0] += 1
for a in aa:
    tmp += a
    tmp %= M
    ans += modSUM[tmp]
    modSUM[tmp] += 1
print(ans)

-# list_int 並べて出力 print (' '.join(map(str,ans_li))) -# list_str 並べて出力 print (' '.join(list)) -ed = [0] -SUM_L = defaultdict(int) -SUM_R = defaultdict(int) -SUM_L[0] += 1 -SUM_R[0] += 1 -SUM = sum(aa) % M -tmpL = tmpR = 0 -for i in range(N): -    tmpL += aa[i] -    tmpL %= M -    if SUM_L[tmpL] == 0: -        ed.append(tmpL) -    SUM_L[tmpL] += 1 -    tmpR += aa[N - i - 1] -    tmpR %= M -    SUM_R[tmpR] += 1 -ans = 0 -for l in ed: -    numL = SUM_L[l] -    r = (SUM - l) % M -    numR = SUM_R[r] -    ans += numL * (numR - 1) -print((ans // 2)) +modSUM = defaultdict(int) +tmp = 0 +modSUM[0] += 1 +for a in aa: +    tmp += a +    tmp %= M +    ans += modSUM[tmp] +    modSUM[tmp] += 1 +print(ans)