import sys

import numpy as np

from collections import Counter

from math import factorial



stdin = sys.stdin

 

ri = lambda: int(rs())

rl = lambda: list(map(int, stdin.readline().split()))

rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces



N, M = rl()

A = np.array(rl())

A_cum = A.cumsum()

A_cum %= M

A_cum = A_cum.tolist()

c = Counter(A_cum)

answer = 0



for k, v in list(c.items()):

    if k == 0:

        answer += v

    if v >= 2:

        answer += factorial(v) // factorial(2) // factorial(v-2)



print(answer)

#13

# coding: utf-8

import sys

from collections import defaultdict



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



# 左から累積和のリストを持ちながらApplePen

N, M = lr()

A = lr()

dic = defaultdict(int)

dic[0] = 1

answer = 0

cur = 0

for a in A:

    cur += a

    cur %= M

    answer += dic[cur]

    dic[cur] += 1



print(answer)

import sys
import numpy as np
from collections import Counter
from math import factorial

stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces
N, M = rl()
A = np.array(rl())
A_cum = A.cumsum()
A_cum %= M
A_cum = A_cum.tolist()
c = Counter(A_cum)
answer = 0
for k, v in list(c.items()):
    if k == 0:
        answer += v
    if v >= 2:
        answer += factorial(v) // factorial(2) // factorial(v - 2)
print(answer)
# 13

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

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# 左から累積和のリストを持ちながらApplePen
N, M = lr()
A = lr()
dic = defaultdict(int)
dic[0] = 1
answer = 0
cur = 0
for a in A:
    cur += a
    cur %= M
    answer += dic[cur]
    dic[cur] += 1
print(answer)

+# coding: utf-8 -import numpy as np -from collections import Counter -from math import factorial +from collections import defaultdict -stdin = sys.stdin -ri = lambda: int(rs()) -rl = lambda: list(map(int, stdin.readline().split())) -rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces -N, M = rl() -A = np.array(rl()) -A_cum = A.cumsum() -A_cum %= M -A_cum = A_cum.tolist() -c = Counter(A_cum) +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) +# 左から累積和のリストを持ちながらApplePen +N, M = lr() +A = lr() +dic = defaultdict(int) +dic[0] = 1 -for k, v in list(c.items()): -    if k == 0: -        answer += v -    if v >= 2: -        answer += factorial(v) // factorial(2) // factorial(v - 2) +cur = 0 +for a in A: +    cur += a +    cur %= M +    answer += dic[cur] +    dic[cur] += 1 -# 13