N, M = [int(_) for _ in input().split()]

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

cumsum = 0

count = {}

for i in range(N):

    cumsum += A[i]

    cumsum %= M

    count[cumsum] = count.get(cumsum, 0) + 1

ans = count.get(0, 0)

for k in count:

    n = count[k]

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

print(ans)
import itertools, collections

N, M = [int(_) for _ in input().split()]

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

cum = [0] + [c % M for c in itertools.accumulate(A)]

cnt = collections.Counter(cum)

ans = sum(v * (v - 1) // 2 for v in list(cnt.values()))

print(ans)

N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
cumsum = 0
count = {}
for i in range(N):
    cumsum += A[i]
    cumsum %= M
    count[cumsum] = count.get(cumsum, 0) + 1
ans = count.get(0, 0)
for k in count:
    n = count[k]
    ans += (n * (n - 1)) // 2
print(ans)

import itertools, collections

N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
cum = [0] + [c % M for c in itertools.accumulate(A)]
cnt = collections.Counter(cum)
ans = sum(v * (v - 1) // 2 for v in list(cnt.values()))
print(ans)

+import itertools, collections + -cumsum = 0 -count = {} -for i in range(N): -    cumsum += A[i] -    cumsum %= M -    count[cumsum] = count.get(cumsum, 0) + 1 -ans = count.get(0, 0) -for k in count: -    n = count[k] -    ans += (n * (n - 1)) // 2 +cum = [0] + [c % M for c in itertools.accumulate(A)] +cnt = collections.Counter(cum) +ans = sum(v * (v - 1) // 2 for v in list(cnt.values()))