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

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



from collections import Counter

c=Counter()

s=0

c[s]+=1

for i in range(n):

  s+=a[i]

  c[s%m]+=1



ans=0

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

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

print(ans)

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

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

from collections import Counter

c = Counter()

sum_val = 0

c[sum_val] += 1

for i in range(n):

    sum_val += a[i]

    sum_val %= m

    c[sum_val] += 1

ans = 0

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

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

print(ans)





n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
from collections import Counter

c = Counter()
s = 0
c[s] += 1
for i in range(n):
    s += a[i]
    c[s % m] += 1
ans = 0
for v in list(c.values()):
    ans += v * (v - 1) // 2
print(ans)

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
from collections import Counter

c = Counter()
sum_val = 0
c[sum_val] += 1
for i in range(n):
    sum_val += a[i]
    sum_val %= m
    c[sum_val] += 1
ans = 0
for v in list(c.values()):
    ans += v * (v - 1) // 2
print(ans)

-s = 0 -c[s] += 1 +sum_val = 0 +c[sum_val] += 1 -    s += a[i] -    c[s % m] += 1 +    sum_val += a[i] +    sum_val %= m +    c[sum_val] += 1