from collections import Counter

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

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

A.insert(0,0)

cnt = Counter()

for i in range(N): A[i+1] += A[i]

for i in range(N+1): cnt[A[i]%M] += 1

print((sum(n*(n-1)//2 for n in list(cnt.values()))))

from collections import Counter

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

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

A[0] = A[0] % M

for i in range(1,N): A[i] = (A[i]+A[i-1])%M

cnt = Counter([0]+A)

print((sum(n*(n-1)//2 for n in list(cnt.values()))))

from collections import Counter

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

from collections import Counter

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

-A.insert(0, 0) -cnt = Counter() -for i in range(N): -    A[i + 1] += A[i] -for i in range(N + 1): -    cnt[A[i] % M] += 1 +A[0] = A[0] % M +for i in range(1, N): +    A[i] = (A[i] + A[i - 1]) % M +cnt = Counter([0] + A)