from collections import defaultdict
from itertools import accumulate

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

acc=list(accumulate(A))

d=[defaultdict(int) for i in range(N+1)]

for i in range(N):
    d[i+1][acc[i]%M]+=1
    for n,m in d[i].items():
        d[i+1][n]+=m

ans=0
for g in range(N):
    if acc[g]%M==0:
        ans+=d[g+1][acc[g]%M]
    else:
        ans+=d[g+1][acc[g]%M]-1
print(ans)