from collections import defaultdict

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

a = [int(c)%M for c in input().split()]

L = [0]

for i in range(N):

  L += [(L[-1]+a[i])%M]

log = defaultdict(int)

log[0] = 1

ans = 0

for i in range(1,N+1):

  x = L[i]%M

  ans += log[x]

  log[x] += 1

print(ans)
from collections import Counter

from itertools import accumulate

N, M, *A = list(map(int, open(0).read().split()))

B = [b%M for b in accumulate(A)]

C = Counter(B)

ans = C[0]

for k in list(C.keys()):

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

print(ans)
from collections import defaultdict

N, M = list(map(int, input().split()))
a = [int(c) % M for c in input().split()]
L = [0]
for i in range(N):
    L += [(L[-1] + a[i]) % M]
log = defaultdict(int)
log[0] = 1
ans = 0
for i in range(1, N + 1):
    x = L[i] % M
    ans += log[x]
    log[x] += 1
print(ans)

from collections import Counter
from itertools import accumulate

N, M, *A = list(map(int, open(0).read().split()))
B = [b % M for b in accumulate(A)]
C = Counter(B)
ans = C[0]
for k in list(C.keys()):
    ans += C[k] * (C[k] - 1) // 2
print(ans)

-from collections import defaultdict +from collections import Counter +from itertools import accumulate -N, M = list(map(int, input().split())) -a = [int(c) % M for c in input().split()] -L = [0] -for i in range(N): -    L += [(L[-1] + a[i]) % M] -log = defaultdict(int) -log[0] = 1 -ans = 0 -for i in range(1, N + 1): -    x = L[i] % M -    ans += log[x] -    log[x] += 1 +N, M, *A = list(map(int, open(0).read().split())) +B = [b % M for b in accumulate(A)] +C = Counter(B) +ans = C[0] +for k in list(C.keys()): +    ans += C[k] * (C[k] - 1) // 2