# 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



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):

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

    S = [0]

    for i in range(N):

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



    ans = 0

    # 各要素の個数を数える

    for v in list(Counter(S).values()):

        # v個から2個選ぶ組み合わせ

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



    return ans





N, M = inpl()

A = inpl()

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

# 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
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):
    # 累積和S (mod M)を求める
    S = [0]
    for i in range(N):
        S.append((S[-1] + A[i]) % M)
    ans = 0
    # 各要素の個数を数える
    for v in list(Counter(S).values()):
        # v個から2個選ぶ組み合わせ
        ans += v * (v - 1) // 2
    return ans


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

-    # 累積和(mod M)を求める +    # 累積和S (mod M)を求める -    del S[0] +    ans = 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] +    for v in list(Counter(S).values()): +        # v個から2個選ぶ組み合わせ +        ans += v * (v - 1) // 2 +    return ans