import itertools

import collections

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

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

B = [0] + list(itertools.accumulate(A))

d = collections.defaultdict(int)

for i in range(N+1):

    d[B[i]%M] += 1

d = list(d.items())

ans = 0

for i in d:

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

print(ans)
import itertools

import collections

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

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

B = [0] + list(itertools.accumulate(A))

d = collections.defaultdict(int)

for i in B:

    d[i%M] += 1

d = list(d.values())

ans = 0

for i in d:

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

print(ans)
import itertools
import collections

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0] + list(itertools.accumulate(A))
d = collections.defaultdict(int)
for i in range(N + 1):
    d[B[i] % M] += 1
d = list(d.items())
ans = 0
for i in d:
    ans += i[1] * (i[1] - 1) // 2
print(ans)

import itertools
import collections

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0] + list(itertools.accumulate(A))
d = collections.defaultdict(int)
for i in B:
    d[i % M] += 1
d = list(d.values())
ans = 0
for i in d:
    ans += i * (i - 1) // 2
print(ans)

-for i in range(N + 1): -    d[B[i] % M] += 1 -d = list(d.items()) +for i in B: +    d[i % M] += 1 +d = list(d.values()) -    ans += i[1] * (i[1] - 1) // 2 +    ans += i * (i - 1) // 2