import numpy as np


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

r = 0
A = A % M
A = np.cumsum(A)
A = A % M

for i in range(len(A)):
    print(A)
    r += np.sum((A == 0) | (A == M))
    A = A[1:] - A[0]

print(r)