from collections import defaultdict



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

A = [int(x) for x in input().split()]



B = [0] * N

B[0] = A[0]

for i in range(1, N):

    B[i] = B[i - 1] + A[i]

B = [0] + B



c = defaultdict(int)

for i in range(N + 1):

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



ans = 0

for k, v in list(c.items()):

    if v >= 2:

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

print(ans)
from collections import Counter

from itertools import accumulate



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

A = [int(x) for x in input().split()]



c = Counter([0] + [x % M for x in accumulate(A)])

ans = 0

for k, v in list(c.items()):

    if v >= 2:

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

print(ans)
from collections import defaultdict

N, M = list(map(int, input().split()))
A = [int(x) for x in input().split()]
B = [0] * N
B[0] = A[0]
for i in range(1, N):
    B[i] = B[i - 1] + A[i]
B = [0] + B
c = defaultdict(int)
for i in range(N + 1):
    c[B[i] % M] += 1
ans = 0
for k, v in list(c.items()):
    if v >= 2:
        ans += v * (v - 1) // 2
print(ans)

from collections import Counter
from itertools import accumulate

N, M = list(map(int, input().split()))
A = [int(x) for x in input().split()]
c = Counter([0] + [x % M for x in accumulate(A)])
ans = 0
for k, v in list(c.items()):
    if v >= 2:
        ans += v * (v - 1) // 2
print(ans)

-from collections import defaultdict +from collections import Counter +from itertools import accumulate -B = [0] * N -B[0] = A[0] -for i in range(1, N): -    B[i] = B[i - 1] + A[i] -B = [0] + B -c = defaultdict(int) -for i in range(N + 1): -    c[B[i] % M] += 1 +c = Counter([0] + [x % M for x in accumulate(A)])