class Combination:
    def __init__(self, size):
        self.size = size + 2
        self.fact = [1, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] // self.fact[r] // self.fact[n - r]


from collections import defaultdict

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [a % M for a in A]

accA = [0] * (N + 1)
for i, a in enumerate(A, start=1):
    accA[i] = accA[i - 1] + a

cnt = defaultdict(int)
for a in accA:
    cnt[a % M] += 1

comb = Combination(N + 100)
ans = 0
for c in cnt.values():
    ans += comb.ncr(c, 2)

print(ans)