from collections import Counter



n,m = list(map(int,input().split()))

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



S = [0]

s = 0



for i in range(n):

  s += A[i]

  S += [s]



R = []



for i in range(n+1):

  R += [S[i]%m]

  

R = Counter(R)



ans = 0



for r in list(R.values()):

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



print(ans)
from collections import Counter



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

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



S = [0]



for i in range(N):

    S.append((S[-1]+A[i])%M)



C = Counter(S)



ans = 0



for v in list(C.values()):

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



print(ans)
from collections import Counter

n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
S = [0]
s = 0
for i in range(n):
    s += A[i]
    S += [s]
R = []
for i in range(n + 1):
    R += [S[i] % m]
R = Counter(R)
ans = 0
for r in list(R.values()):
    ans += r * (r - 1) // 2
print(ans)

from collections import Counter

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
S = [0]
for i in range(N):
    S.append((S[-1] + A[i]) % M)
C = Counter(S)
ans = 0
for v in list(C.values()):
    ans += v * (v - 1) // 2
print(ans)

-n, m = list(map(int, input().split())) +N, M = list(map(int, input().split())) -s = 0 -for i in range(n): -    s += A[i] -    S += [s] -R = [] -for i in range(n + 1): -    R += [S[i] % m] -R = Counter(R) +for i in range(N): +    S.append((S[-1] + A[i]) % M) +C = Counter(S) -for r in list(R.values()): -    ans += r * (r - 1) // 2 +for v in list(C.values()): +    ans += v * (v - 1) // 2