n,m=list(map(int,input().split()))

a=[0]+list(map(int,input().split()))

from collections import defaultdict

mods=defaultdict(int)

mods[0]=1

for i in range(1,len(a)):

  a[i]=a[i-1]+a[i]%m

  mods[a[i]%m]+=1

ans=0

for v in list(mods.values()):

  if v>1:

    ans+=v*(v-1)//2

print(ans)
# 頭に0を足して、累積和のmod Mを取る

# 各mod Mの個数に対して、個数C2を取って足し合わせる



import sys

readline = sys.stdin.readline



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

A = [0] + list(map(int,readline().split()))



for i in range(1,len(A)):

  A[i] = A[i - 1] + A[i]

  

A = list([x % M for x in A])



from collections import Counter

c = Counter(A)



ans = 0

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

  ans += (v * (v - 1)) // 2

  

print(ans)
n, m = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
from collections import defaultdict

mods = defaultdict(int)
mods[0] = 1
for i in range(1, len(a)):
    a[i] = a[i - 1] + a[i] % m
    mods[a[i] % m] += 1
ans = 0
for v in list(mods.values()):
    if v > 1:
        ans += v * (v - 1) // 2
print(ans)

# 頭に0を足して、累積和のmod Mを取る
# 各mod Mの個数に対して、個数C2を取って足し合わせる
import sys

readline = sys.stdin.readline
N, M = list(map(int, readline().split()))
A = [0] + list(map(int, readline().split()))
for i in range(1, len(A)):
    A[i] = A[i - 1] + A[i]
A = list([x % M for x in A])
from collections import Counter

c = Counter(A)
ans = 0
for v in list(c.values()):
    ans += (v * (v - 1)) // 2
print(ans)

-n, m = list(map(int, input().split())) -a = [0] + list(map(int, input().split())) -from collections import defaultdict +# 頭に0を足して、累積和のmod Mを取る +# 各mod Mの個数に対して、個数C2を取って足し合わせる +import sys -mods = defaultdict(int) -mods[0] = 1 -for i in range(1, len(a)): -    a[i] = a[i - 1] + a[i] % m -    mods[a[i] % m] += 1 +readline = sys.stdin.readline +N, M = list(map(int, readline().split())) +A = [0] + list(map(int, readline().split())) +for i in range(1, len(A)): +    A[i] = A[i - 1] + A[i] +A = list([x % M for x in A]) +from collections import Counter + +c = Counter(A) -for v in list(mods.values()): -    if v > 1: -        ans += v * (v - 1) // 2 +for v in list(c.values()): +    ans += (v * (v - 1)) // 2