from collections import defaultdict

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

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



amount = [0] * (N+1)

for i in range(N):

    amount[i+1] = amount[i] + A[i]

    amount[i+1] %= M



ans = 0

di = defaultdict(int)

for i in range(N):

    ans += di[amount[i+1]]

    di[amount[i+1]] += 1



print((ans + di[0]))



from collections import Counter

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

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

tmp = 0

for i in range(N):

    A[i] += tmp

    A[i] %= M

    tmp = A[i]



c = Counter(A)

ans = 0

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

    if k == 0:

        ans += v

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



print(ans)

from collections import defaultdict

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
amount = [0] * (N + 1)
for i in range(N):
    amount[i + 1] = amount[i] + A[i]
    amount[i + 1] %= M
ans = 0
di = defaultdict(int)
for i in range(N):
    ans += di[amount[i + 1]]
    di[amount[i + 1]] += 1
print((ans + di[0]))

from collections import Counter

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

-from collections import defaultdict +from collections import Counter -amount = [0] * (N + 1) +tmp = 0 -    amount[i + 1] = amount[i] + A[i] -    amount[i + 1] %= M +    A[i] += tmp +    A[i] %= M +    tmp = A[i] +c = Counter(A) -di = defaultdict(int) -for i in range(N): -    ans += di[amount[i + 1]] -    di[amount[i + 1]] += 1 -print((ans + di[0])) +for k, v in list(c.items()): +    if k == 0: +        ans += v +    ans += v * (v - 1) // 2 +print(ans)