from itertools import accumulate

from collections import defaultdict



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

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



#1 累積和をとる

B = [0] + list(accumulate(A))



#2 そのmodをとる

B = [b%M for b in B]



#3 1～Nまで、辞書内の当該キーをansにプラスしながら進む

cnt = defaultdict(int)

ans = 0



for b in B:

    ans += cnt[b]

    cnt[b] += 1

    

print(ans)

import sys

stdin = sys.stdin



sys.setrecursionlimit(10**5)



def li(): return list(map(int, stdin.readline().split()))

def li_(): return [int(x)-1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())



from collections import Counter

from itertools import accumulate



n,m = li()

a = list(li())



acum = list(accumulate(a))

acum = [acumi%m for acumi in acum]



cnt = Counter(acum)



ans = cnt[0]

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

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

    

print(ans)
from itertools import accumulate
from collections import defaultdict

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
# 1 累積和をとる
B = [0] + list(accumulate(A))
# 2 そのmodをとる
B = [b % M for b in B]
# 3 1～Nまで、辞書内の当該キーをansにプラスしながら進む
cnt = defaultdict(int)
ans = 0
for b in B:
    ans += cnt[b]
    cnt[b] += 1
print(ans)

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**5)


def li():
    return list(map(int, stdin.readline().split()))


def li_():
    return [int(x) - 1 for x in stdin.readline().split()]


def lf():
    return list(map(float, stdin.readline().split()))


def ls():
    return stdin.readline().split()


def ns():
    return stdin.readline().rstrip()


def lc():
    return list(ns())


def ni():
    return int(stdin.readline())


def nf():
    return float(stdin.readline())


from collections import Counter
from itertools import accumulate

n, m = li()
a = list(li())
acum = list(accumulate(a))
acum = [acumi % m for acumi in acum]
cnt = Counter(acum)
ans = cnt[0]
for k, v in list(cnt.items()):
    ans += v * (v - 1) // 2
print(ans)

+import sys + +stdin = sys.stdin +sys.setrecursionlimit(10**5) + + +def li(): +    return list(map(int, stdin.readline().split())) + + +def li_(): +    return [int(x) - 1 for x in stdin.readline().split()] + + +def lf(): +    return list(map(float, stdin.readline().split())) + + +def ls(): +    return stdin.readline().split() + + +def ns(): +    return stdin.readline().rstrip() + + +def lc(): +    return list(ns()) + + +def ni(): +    return int(stdin.readline()) + + +def nf(): +    return float(stdin.readline()) + + +from collections import Counter -from collections import defaultdict -N, M = list(map(int, input().split())) -A = list(map(int, input().split())) -# 1 累積和をとる -B = [0] + list(accumulate(A)) -# 2 そのmodをとる -B = [b % M for b in B] -# 3 1～Nまで、辞書内の当該キーをansにプラスしながら進む -cnt = defaultdict(int) -ans = 0 -for b in B: -    ans += cnt[b] -    cnt[b] += 1 +n, m = li() +a = list(li()) +acum = list(accumulate(a)) +acum = [acumi % m for acumi in acum] +cnt = Counter(acum) +ans = cnt[0] +for k, v in list(cnt.items()): +    ans += v * (v - 1) // 2