#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict

def solve():
    n, m = map(int, input().split())
    al = [int(i) for i in input().split()]
    bl = [0]*n
    d = defaultdict(int)
    for i in range(n):
        bl[i] = al[i] + bl[max(0, i - 1)]
        d[bl[i] % m] += 1
    ans = 0
    for k, v in d.items():
        t = (m - k) % m
        if d.get(t):
            ans += (v * v) // 2 + 1
    print(max(ans - 1, 0))

if __name__=="__main__":
    solve()