from itertools import accumulate as ac

from math import factorial as fc

from collections import Counter



f=lambda a,b:fc(a)//(fc(a-b)*fc(b)) if a>=b>=0 else 0



n,m=list(map(int,input().split()))

*a,=list(map(int,input().split()))

*aa,=[x%m for x in ac([0]+a)]

d=Counter(aa)



v=sum(f(i,2) for i in list(d.values()))

print(v)

from collections import Counter



N, M = list(map(int, input().split()))

*A, = list(map(int, input().split()))

ac = [0]*(N+1)



for i in range(1, N+1):

    ac[i] = (ac[i-1]+A[i-1])%M



c = Counter(ac)

ans = 0

for i in list(c.values()):

    ans += i*(i-1)//2

print(ans)

from itertools import accumulate as ac
from math import factorial as fc
from collections import Counter

f = lambda a, b: fc(a) // (fc(a - b) * fc(b)) if a >= b >= 0 else 0
n, m = list(map(int, input().split()))
(*a,) = list(map(int, input().split()))
(*aa,) = [x % m for x in ac([0] + a)]
d = Counter(aa)
v = sum(f(i, 2) for i in list(d.values()))
print(v)

from collections import Counter

N, M = list(map(int, input().split()))
(*A,) = list(map(int, input().split()))
ac = [0] * (N + 1)
for i in range(1, N + 1):
    ac[i] = (ac[i - 1] + A[i - 1]) % M
c = Counter(ac)
ans = 0
for i in list(c.values()):
    ans += i * (i - 1) // 2
print(ans)

-from itertools import accumulate as ac -from math import factorial as fc -f = lambda a, b: fc(a) // (fc(a - b) * fc(b)) if a >= b >= 0 else 0 -n, m = list(map(int, input().split())) -(*a,) = list(map(int, input().split())) -(*aa,) = [x % m for x in ac([0] + a)] -d = Counter(aa) -v = sum(f(i, 2) for i in list(d.values())) -print(v) +N, M = list(map(int, input().split())) +(*A,) = list(map(int, input().split())) +ac = [0] * (N + 1) +for i in range(1, N + 1): +    ac[i] = (ac[i - 1] + A[i - 1]) % M +c = Counter(ac) +ans = 0 +for i in list(c.values()): +    ans += i * (i - 1) // 2 +print(ans)