from collections import Counter

c = Counter()



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

a = list(map(int,input().split())) 

s = 0

c[s] += 1

for i in range(N):

  s = (s + a[i]) % M

  c[s] += 1

# print(c)

S=0

# t=0

for (i,k) in list(c.items()):

  if k > 1:

    S += (k-1)*k//2

  # t += k

print(S)

# print(t)
from collections import Counter

from itertools import accumulate

from functools import reduce



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

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



c = Counter([0] + [x % M for x in accumulate(A)])

ans = reduce(lambda x,y:x+y, [v*(v-1)//2 for v in list(c.values())])

print(ans)

from collections import Counter

c = Counter()
N, M = list(map(int, input().split()))
a = list(map(int, input().split()))
s = 0
c[s] += 1
for i in range(N):
    s = (s + a[i]) % M
    c[s] += 1
# print(c)
S = 0
# t=0
for (i, k) in list(c.items()):
    if k > 1:
        S += (k - 1) * k // 2
    # t += k
print(S)
# print(t)

from collections import Counter
from itertools import accumulate
from functools import reduce

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

+from itertools import accumulate +from functools import reduce -c = Counter() -a = list(map(int, input().split())) -s = 0 -c[s] += 1 -for i in range(N): -    s = (s + a[i]) % M -    c[s] += 1 -# print(c) -S = 0 -# t=0 -for (i, k) in list(c.items()): -    if k > 1: -        S += (k - 1) * k // 2 -    # t += k -print(S) -# print(t) +A = [int(x) for x in input().split()] +c = Counter([0] + [x % M for x in accumulate(A)]) +ans = reduce(lambda x, y: x + y, [v * (v - 1) // 2 for v in list(c.values())]) +print(ans)