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

t = [0] * M
c = 0
for a in A:
    c += a
    c %= M
    t[c] += 1

result = t[0]
c = 0
for a in A:
    c += a
    c %= M
    t[c] -= 1
    result += t[c]
print(result)