from collections import Counter

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

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

ans = 0



S = [0 for k in range(N)]

S[0] = A[0]

for k in range(1,N):

    S[k] = S[k-1] + A[k]

S = [0] + S

for k in range(N+1):

    S[k] %= M



C = Counter(S)

for a in C:

    if C[a] >= 2:

        ans += (C[a]*(C[a]-1))//2

print(ans)
import sys

from collections import Counter

def input():

    return sys.stdin.readline()[:-1]

def main():

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

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

    S = [0]*N

    S[0] = A[0]%M

    for k in range(1,N):

        S[k] = (S[k-1] + A[k])%M

    C = Counter(S)

    C[0] += 1

    ans = 0

    for e in C:

        ans += (C[e]*(C[e]-1))//2

    print(ans)

if __name__ == '__main__':

    main()

from collections import Counter

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

import sys
from collections import Counter


def input():
    return sys.stdin.readline()[:-1]


def main():
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    S = [0] * N
    S[0] = A[0] % M
    for k in range(1, N):
        S[k] = (S[k - 1] + A[k]) % M
    C = Counter(S)
    C[0] += 1
    ans = 0
    for e in C:
        ans += (C[e] * (C[e] - 1)) // 2
    print(ans)


if __name__ == "__main__":
    main()

+import sys -N, M = list(map(int, input().split())) -A = list(map(int, input().split())) -ans = 0 -S = [0 for k in range(N)] -S[0] = A[0] -for k in range(1, N): -    S[k] = S[k - 1] + A[k] -S = [0] + S -for k in range(N + 1): -    S[k] %= M -C = Counter(S) -for a in C: -    if C[a] >= 2: -        ans += (C[a] * (C[a] - 1)) // 2 -print(ans) + +def input(): +    return sys.stdin.readline()[:-1] + + +def main(): +    N, M = list(map(int, input().split())) +    A = list(map(int, input().split())) +    S = [0] * N +    S[0] = A[0] % M +    for k in range(1, N): +        S[k] = (S[k - 1] + A[k]) % M +    C = Counter(S) +    C[0] += 1 +    ans = 0 +    for e in C: +        ans += (C[e] * (C[e] - 1)) // 2 +    print(ans) + + +if __name__ == "__main__": +    main()