import numpy as np
N,M = map(int,input().split())
A = np.array([0]+[int(x) for x in input().split()],dtype=np.int64)
A_cum = np.mod(A.cumsum(),M)

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