import sys

from collections import defaultdict



sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline

f_inf = float('inf')

mod = 10 ** 9 + 7





def resolve():

    n, m = list(map(int, input().split()))

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



    A_sum = [0]

    D = defaultdict(int)

    D[A_sum[-1]] += 1

    for a in A:

        A_sum.append((A_sum[-1] + a) % m)

        D[A_sum[-1]] += 1



    res = 0

    for v in list(D.values()):

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

    print(res)





if __name__ == '__main__':

    resolve()

import sys

from itertools import accumulate

from collections import Counter



sys.setrecursionlimit(10 ** 7)

f_inf = float('inf')

mod = 10 ** 9 + 7





def resolve():

    n, m = list(map(int, input().split()))

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



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

    R_mod = [r % m for r in R]



    D = Counter(R_mod)

    res = 0

    for v in list(D.values()):

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

    print(res)





if __name__ == '__main__':

    resolve()

import sys
from collections import defaultdict

sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7


def resolve():
    n, m = list(map(int, input().split()))
    A = list(map(int, input().split()))
    A_sum = [0]
    D = defaultdict(int)
    D[A_sum[-1]] += 1
    for a in A:
        A_sum.append((A_sum[-1] + a) % m)
        D[A_sum[-1]] += 1
    res = 0
    for v in list(D.values()):
        res += v * (v - 1) // 2
    print(res)


if __name__ == "__main__":
    resolve()

import sys
from itertools import accumulate
from collections import Counter

sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7


def resolve():
    n, m = list(map(int, input().split()))
    A = list(map(int, input().split()))
    R = [0] + list(accumulate(A))
    R_mod = [r % m for r in R]
    D = Counter(R_mod)
    res = 0
    for v in list(D.values()):
        res += (v - 1) * v // 2
    print(res)


if __name__ == "__main__":
    resolve()

-from collections import defaultdict +from itertools import accumulate +from collections import Counter -input = sys.stdin.readline -    A_sum = [0] -    D = defaultdict(int) -    D[A_sum[-1]] += 1 -    for a in A: -        A_sum.append((A_sum[-1] + a) % m) -        D[A_sum[-1]] += 1 +    R = [0] + list(accumulate(A)) +    R_mod = [r % m for r in R] +    D = Counter(R_mod) -        res += v * (v - 1) // 2 +        res += (v - 1) * v // 2