import numpy as np

N,M = map(int,input().split())
A = np.array(input().split(), dtype=np.int64)
np.cumsum(A, out = A)
A %= M

counter = np.bincount(A)
counter[0] += 1 # empty
answer = (counter * (counter-1)).sum() // 2
print(answer)
