from collections import Counter
from scipy.misc import comb

N, M=list(map(int, input().split()))
A=list(map(int, input().split()))

B=[0]
tmp=0
for i in A:
    tmp+=i
    B.append(tmp)
C=[]
for i in B:
    C.append(i%M)
X=Counter(C)
ans=0
for i in X.values():
    ans+=comb(i, 2, 1)
    print(i, ans)
print(ans)
