import numpy as np
import collections
from math import factorial

N,M = list(map(int,input().split()))
a = list(map(int,input().split()))
s = np.cumsum(a)
s = np.insert(s,0,0)
s = s%M
ans = 0

c = collections.Counter(s)

for i in c:
	if c[i] > 1:
		ans += factorial(c[i])/factorial(2)/factorial(c[i]-2)
print(int(ans))
