# coding:utf-8





def inpl(): return list(map(int, input().split()))





N, M = inpl()

A = inpl()



S = [0]

for i in range(N):

    S.append((S[-1] + A[i]) % M)

del S[0]



D = dict()

D[0] = 0

for i in range(N):

    if S[i] in D:

        D[S[i]] += 1

    else:

        D[S[i]] = 1



ans = 0

for num in D:

    tmp = D[num]

    # cmb(x, 2)を計算

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



# l, rが等しく（1箱で）分配できるパターンを最後に足す

ans += D[0]

print(ans)

# coding:utf-8



import sys

from collections import Counter





input = sys.stdin.readline





def inpl(): return list(map(int, input().split()))





# Counterを使ったD - Candy Distributionの解法

def solve(N, M, A):

    # 累積和(mod M)を求める

    S = [0]

    for i in range(N):

        S.append((S[-1] + A[i]) % M)

    del S[0]



    # 各要素の個数を数える

    C = Counter(S)



    ans = 0

    for num in C:

        if C[num] <= 1:

            continue

        # C[num]個から2つ選ぶ組み合わせ

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



    # 1箱で条件を満たす(Si = 0, l=r)場合を加算

    return ans + C[0]





N, M = inpl()

A = inpl()

print((solve(N, M, A)))

# coding:utf-8
def inpl():
    return list(map(int, input().split()))


N, M = inpl()
A = inpl()
S = [0]
for i in range(N):
    S.append((S[-1] + A[i]) % M)
del S[0]
D = dict()
D[0] = 0
for i in range(N):
    if S[i] in D:
        D[S[i]] += 1
    else:
        D[S[i]] = 1
ans = 0
for num in D:
    tmp = D[num]
    # cmb(x, 2)を計算
    ans += tmp * (tmp - 1) // 2
# l, rが等しく（1箱で）分配できるパターンを最後に足す
ans += D[0]
print(ans)

# coding:utf-8
import sys
from collections import Counter

input = sys.stdin.readline


def inpl():
    return list(map(int, input().split()))


# Counterを使ったD - Candy Distributionの解法
def solve(N, M, A):
    # 累積和(mod M)を求める
    S = [0]
    for i in range(N):
        S.append((S[-1] + A[i]) % M)
    del S[0]
    # 各要素の個数を数える
    C = Counter(S)
    ans = 0
    for num in C:
        if C[num] <= 1:
            continue
        # C[num]個から2つ選ぶ組み合わせ
        ans += C[num] * (C[num] - 1) // 2
    # 1箱で条件を満たす(Si = 0, l=r)場合を加算
    return ans + C[0]


N, M = inpl()
A = inpl()
print((solve(N, M, A)))

+import sys +from collections import Counter + +input = sys.stdin.readline + + +# Counterを使ったD - Candy Distributionの解法 +def solve(N, M, A): +    # 累積和(mod M)を求める +    S = [0] +    for i in range(N): +        S.append((S[-1] + A[i]) % M) +    del S[0] +    # 各要素の個数を数える +    C = Counter(S) +    ans = 0 +    for num in C: +        if C[num] <= 1: +            continue +        # C[num]個から2つ選ぶ組み合わせ +        ans += C[num] * (C[num] - 1) // 2 +    # 1箱で条件を満たす(Si = 0, l=r)場合を加算 +    return ans + C[0] + + -S = [0] -for i in range(N): -    S.append((S[-1] + A[i]) % M) -del S[0] -D = dict() -D[0] = 0 -for i in range(N): -    if S[i] in D: -        D[S[i]] += 1 -    else: -        D[S[i]] = 1 -ans = 0 -for num in D: -    tmp = D[num] -    # cmb(x, 2)を計算 -    ans += tmp * (tmp - 1) // 2 -# l, rが等しく（1箱で）分配できるパターンを最後に足す -ans += D[0] -print(ans) +print((solve(N, M, A)))