N, M = [int(t) for t in input().split()]

a    = [int(t) for t in input().split()]

assert len(a) == N



def prefixsum(a):

    s = [0] * len(a)

    s[0] = a[0] % M

    for i in range(1, len(a)):

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

    return s



s = prefixsum(a)

t = [(s[i], i) for i in range(N)]

t.sort()



count = 0

prev = -1

c = 0

for v, i in t:

    if v == 0: count += 1

    if prev == v:

        c += 1

    else:

        count += c * (c - 1) // 2

        c = 1

        prev = v

count += c * (c - 1) // 2



print(count)
# -*- coding: utf-8 -*-



N, M = [int(t) for t in input().split()]

A    = [int(t) for t in input().split()]

assert len(A) == N



def prefixsum(A):

    '''S[i] == sum(A[:i]) % M かつ len(S) == len(A) + 1 であるSを返す.'''

    S = [0]

    for a in A:

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

    return S



def eqlen(S):

    '''Sは整列済みリスト. 等しい要素の個数からなるリストを返す.'''

    T = []

    p = None

    for s in S:

        if p == s:

            T[-1] += 1

        else:

            T.append(1)

            p = s

    return T



S = prefixsum(A)

S.sort()

T = eqlen(S)

print((sum(t * (t - 1) // 2 for t in T)))
N, M = [int(t) for t in input().split()]
a = [int(t) for t in input().split()]
assert len(a) == N


def prefixsum(a):
    s = [0] * len(a)
    s[0] = a[0] % M
    for i in range(1, len(a)):
        s[i] = (s[i - 1] + a[i]) % M
    return s


s = prefixsum(a)
t = [(s[i], i) for i in range(N)]
t.sort()
count = 0
prev = -1
c = 0
for v, i in t:
    if v == 0:
        count += 1
    if prev == v:
        c += 1
    else:
        count += c * (c - 1) // 2
        c = 1
        prev = v
count += c * (c - 1) // 2
print(count)

# -*- coding: utf-8 -*-
N, M = [int(t) for t in input().split()]
A = [int(t) for t in input().split()]
assert len(A) == N


def prefixsum(A):
    """S[i] == sum(A[:i]) % M かつ len(S) == len(A) + 1 であるSを返す."""
    S = [0]
    for a in A:
        S.append((S[-1] + a) % M)
    return S


def eqlen(S):
    """Sは整列済みリスト. 等しい要素の個数からなるリストを返す."""
    T = []
    p = None
    for s in S:
        if p == s:
            T[-1] += 1
        else:
            T.append(1)
            p = s
    return T


S = prefixsum(A)
S.sort()
T = eqlen(S)
print((sum(t * (t - 1) // 2 for t in T)))

+# -*- coding: utf-8 -*- -a = [int(t) for t in input().split()] -assert len(a) == N +A = [int(t) for t in input().split()] +assert len(A) == N -def prefixsum(a): -    s = [0] * len(a) -    s[0] = a[0] % M -    for i in range(1, len(a)): -        s[i] = (s[i - 1] + a[i]) % M -    return s +def prefixsum(A): +    """S[i] == sum(A[:i]) % M かつ len(S) == len(A) + 1 であるSを返す.""" +    S = [0] +    for a in A: +        S.append((S[-1] + a) % M) +    return S -s = prefixsum(a) -t = [(s[i], i) for i in range(N)] -t.sort() -count = 0 -prev = -1 -c = 0 -for v, i in t: -    if v == 0: -        count += 1 -    if prev == v: -        c += 1 -    else: -        count += c * (c - 1) // 2 -        c = 1 -        prev = v -count += c * (c - 1) // 2 -print(count) +def eqlen(S): +    """Sは整列済みリスト. 等しい要素の個数からなるリストを返す.""" +    T = [] +    p = None +    for s in S: +        if p == s: +            T[-1] += 1 +        else: +            T.append(1) +            p = s +    return T + + +S = prefixsum(A) +S.sort() +T = eqlen(S) +print((sum(t * (t - 1) // 2 for t in T)))