N, M = map(int, input().split())
A = list(map(int, input().split()))
cumS = [0]
for a in A:
    cumS.append(a + cumS[-1])
cumS_rem = {i: 0 for i in range(M)}
for c in cumS:
    r = c % M
    cumS_rem[r] += 1
ans = 0
for r in range(M):
    n_r = cumS_rem[r]
    if n_r > 1:
        ans += n_r*(n_r-1)//2
print(ans)