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

A = [0] * N

cnt = 0

for i, x in enumerate(input().split()):

  A[i] = int(x) % M

sumA = 0

for i in range(N):

  sumA += A[i]

  sumA %= M

  A[i] = sumA

A += [0]

index = {}

for i in set(set(A)):

  index[i] = 0

for a in A:

  index[a] += 1

for i in list(index.values()):

  cnt += i * (i - 1) // 2

print(cnt)
from collections import Counter

from itertools import accumulate

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

A = [int(x) for x in input().split()]

C = Counter([0] + [a % M for a in accumulate(A)])

cnt = 0

for c in list(C.values()):

  cnt += c * (c - 1) // 2

print(cnt)
N, M = list(map(int, input().split()))
A = [0] * N
cnt = 0
for i, x in enumerate(input().split()):
    A[i] = int(x) % M
sumA = 0
for i in range(N):
    sumA += A[i]
    sumA %= M
    A[i] = sumA
A += [0]
index = {}
for i in set(set(A)):
    index[i] = 0
for a in A:
    index[a] += 1
for i in list(index.values()):
    cnt += i * (i - 1) // 2
print(cnt)

from collections import Counter
from itertools import accumulate

N, M = list(map(int, input().split()))
A = [int(x) for x in input().split()]
C = Counter([0] + [a % M for a in accumulate(A)])
cnt = 0
for c in list(C.values()):
    cnt += c * (c - 1) // 2
print(cnt)

+from collections import Counter +from itertools import accumulate + -A = [0] * N +A = [int(x) for x in input().split()] +C = Counter([0] + [a % M for a in accumulate(A)]) -for i, x in enumerate(input().split()): -    A[i] = int(x) % M -sumA = 0 -for i in range(N): -    sumA += A[i] -    sumA %= M -    A[i] = sumA -A += [0] -index = {} -for i in set(set(A)): -    index[i] = 0 -for a in A: -    index[a] += 1 -for i in list(index.values()): -    cnt += i * (i - 1) // 2 +for c in list(C.values()): +    cnt += c * (c - 1) // 2