from itertools import accumulate

from collections import Counter

import math



def combinations_count(n, r):

    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))



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

s=list([x%m for x in list(accumulate(list(map(int,input().split()))))])

s.append(0)

#print(s)

d=Counter(s)

#print(d)

ans=0

for i in d:

    if d[i]>=2:

        ans+=combinations_count(d[i],2)

print(ans)
from itertools import accumulate

from collections import Counter

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

s=[0]+list([x%m for x in list(accumulate(list(map(int,input().split()))))])

ans=0

for i in list(Counter(s).values()):

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

print(ans)
from itertools import accumulate
from collections import Counter
import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, m = list(map(int, input().split()))
s = list([x % m for x in list(accumulate(list(map(int, input().split()))))])
s.append(0)
# print(s)
d = Counter(s)
# print(d)
ans = 0
for i in d:
    if d[i] >= 2:
        ans += combinations_count(d[i], 2)
print(ans)

from itertools import accumulate
from collections import Counter

n, m = list(map(int, input().split()))
s = [0] + list([x % m for x in list(accumulate(list(map(int, input().split()))))])
ans = 0
for i in list(Counter(s).values()):
    ans += i * (i - 1) // 2
print(ans)

-import math - - -def combinations_count(n, r): -    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) - -s = list([x % m for x in list(accumulate(list(map(int, input().split()))))]) -s.append(0) -# print(s) -d = Counter(s) -# print(d) +s = [0] + list([x % m for x in list(accumulate(list(map(int, input().split()))))]) -for i in d: -    if d[i] >= 2: -        ans += combinations_count(d[i], 2) +for i in list(Counter(s).values()): +    ans += i * (i - 1) // 2