n, m = map(int, input().split())
aa = [int(ak) % m for ak in input().split()]
mod = {}
ans = 0
zi = 0
for a in aa:
    zi = (zi - a) % m
    ai = (zi + a) % m
    mod.setdefault(ai,0)
    mod[ai] += 1
    ans += mod.get(zi,0)
print(ans)
