from collections import defaultdict



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

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



accum = [0] * (n + 1)



for i in range(n):

  accum[i + 1] = accum[i] + A[i]

  

box = defaultdict(int)



for i in accum:

  box[i % m] += 1

  

ans = 0

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

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

  

print(ans)
# D - Candy Distribution

# https://atcoder.jp/contests/abc105/tasks/abc105_d



from collections import Counter



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

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



accr = [0] * (n + 1)



for i in range(n):

  accr[i + 1] = accr[i] + A[i]



li = [i % m for i in accr]



C = Counter(li)



ans = 0

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

  if v > 1:

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



print(ans)

from collections import defaultdict

n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
accum = [0] * (n + 1)
for i in range(n):
    accum[i + 1] = accum[i] + A[i]
box = defaultdict(int)
for i in accum:
    box[i % m] += 1
ans = 0
for v in list(box.values()):
    ans += v * (v - 1) // 2
print(ans)

# D - Candy Distribution
# https://atcoder.jp/contests/abc105/tasks/abc105_d
from collections import Counter

n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
accr = [0] * (n + 1)
for i in range(n):
    accr[i + 1] = accr[i] + A[i]
li = [i % m for i in accr]
C = Counter(li)
ans = 0
for v in list(C.values()):
    if v > 1:
        ans += v * (v - 1) // 2
print(ans)

-from collections import defaultdict +# D - Candy Distribution +# https://atcoder.jp/contests/abc105/tasks/abc105_d +from collections import Counter -accum = [0] * (n + 1) +accr = [0] * (n + 1) -    accum[i + 1] = accum[i] + A[i] -box = defaultdict(int) -for i in accum: -    box[i % m] += 1 +    accr[i + 1] = accr[i] + A[i] +li = [i % m for i in accr] +C = Counter(li) -for v in list(box.values()): -    ans += v * (v - 1) // 2 +for v in list(C.values()): +    if v > 1: +        ans += v * (v - 1) // 2