N,M=map(int,input().split())
A=list(map(int,input().split()))
aa = [0]*(N+1)
tbl = [0]*M
cnt = 0
for i in range(N):
  aa[i+1] = aa[i]+A[i]
  am = aa[i+1] % M
  tbl[am] += 1
  cnt += tbl[am]-1
am = aa[i+1] % M
tbl[am] += 1
cnt += tbl[am]-1
print(int(cnt))
