from collections import Counter

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

A = [0] + [int(i) for i in input().split()]



for i in range(N):

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

    A[i + 1] %= M

    

def comb(n, k):

    k = min(k, n - k)

    result = 1

    for i in range(n, n - k, -1):

        result *= i

    for i in range(1, k + 1):

        result //= i 

    return result



ans = 0

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

    if i > 1:

        ans += comb(i, 2)



print(ans)
from collections import Counter

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

A = [0] + [int(i) for i in input().split()]



for i in range(N):

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

    A[i + 1] %= M



ans = 0

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

    if i > 1:

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



print(ans)
from collections import Counter

N, M = list(map(int, input().split()))
A = [0] + [int(i) for i in input().split()]
for i in range(N):
    A[i + 1] += A[i]
    A[i + 1] %= M


def comb(n, k):
    k = min(k, n - k)
    result = 1
    for i in range(n, n - k, -1):
        result *= i
    for i in range(1, k + 1):
        result //= i
    return result


ans = 0
for i in list(Counter(A).values()):
    if i > 1:
        ans += comb(i, 2)
print(ans)

from collections import Counter

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

- - -def comb(n, k): -    k = min(k, n - k) -    result = 1 -    for i in range(n, n - k, -1): -        result *= i -    for i in range(1, k + 1): -        result //= i -    return result - - -        ans += comb(i, 2) +        ans += i * (i - 1) // 2