from math import factorial

from math import sqrt

from math import ceil

from itertools import permutations

from heapq import *

from collections import defaultdict

from copy import deepcopy

from math import log



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

def nCr(n,r):

    a=factorial(n)

    b=factorial(n-r)

    c=factorial(r)

    return int(a//(b*c))

A=[int(i)%M for i in input().split()]

L=[0]

dic=defaultdict(int)

dic[0]+=1

for i in range(N):

    a=(L[-1]+A[i])%M

    L.append(a)

    dic[a]+=1

sum=0

for i in list(dic.keys()):

    if dic[i]>=2:

        sum+=nCr(dic[i],2)

print(sum)

from collections import defaultdict



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

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

B=[0]*(N+1)

C=defaultdict(int)

C[0]+=1

for i in range(N):

    B[i+1]=(B[i]+A[i])%M

    C[B[i+1]]+=1

ans=0

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

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

print(ans)

from math import factorial
from math import sqrt
from math import ceil
from itertools import permutations
from heapq import *
from collections import defaultdict
from copy import deepcopy
from math import log

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


def nCr(n, r):
    a = factorial(n)
    b = factorial(n - r)
    c = factorial(r)
    return int(a // (b * c))


A = [int(i) % M for i in input().split()]
L = [0]
dic = defaultdict(int)
dic[0] += 1
for i in range(N):
    a = (L[-1] + A[i]) % M
    L.append(a)
    dic[a] += 1
sum = 0
for i in list(dic.keys()):
    if dic[i] >= 2:
        sum += nCr(dic[i], 2)
print(sum)

from collections import defaultdict

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0] * (N + 1)
C = defaultdict(int)
C[0] += 1
for i in range(N):
    B[i + 1] = (B[i] + A[i]) % M
    C[B[i + 1]] += 1
ans = 0
for i in list(C.values()):
    ans += i * (i - 1) // 2
print(ans)

-from math import factorial -from math import sqrt -from math import ceil -from itertools import permutations -from heapq import * -from copy import deepcopy -from math import log - - -def nCr(n, r): -    a = factorial(n) -    b = factorial(n - r) -    c = factorial(r) -    return int(a // (b * c)) - - -A = [int(i) % M for i in input().split()] -L = [0] -dic = defaultdict(int) -dic[0] += 1 +A = list(map(int, input().split())) +B = [0] * (N + 1) +C = defaultdict(int) +C[0] += 1 -    a = (L[-1] + A[i]) % M -    L.append(a) -    dic[a] += 1 -sum = 0 -for i in list(dic.keys()): -    if dic[i] >= 2: -        sum += nCr(dic[i], 2) -print(sum) +    B[i + 1] = (B[i] + A[i]) % M +    C[B[i + 1]] += 1 +ans = 0 +for i in list(C.values()): +    ans += i * (i - 1) // 2 +print(ans)