from collections import defaultdict



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

a = tuple(map(int, input().split()))



ans = 0

d = defaultdict(int)

d[0] = 1



t = 0

for aa in a:

    t += aa

    ans += d[t % M]

    d[t % M] += 1

print(ans)

def main():

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

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



    d = {0: 1}



    ans = 0



    t = 0

    for x in A:

        t = (t + x) % M

        ans += (cnt := d.get(t, 0))

        d[t] = cnt + 1

    print(ans)





if __name__ == '__main__':

    main()

from collections import defaultdict

N, M = list(map(int, input().split()))
a = tuple(map(int, input().split()))
ans = 0
d = defaultdict(int)
d[0] = 1
t = 0
for aa in a:
    t += aa
    ans += d[t % M]
    d[t % M] += 1
print(ans)

def main():
    N, M = list(map(int, input().split()))
    (*A,) = list(map(int, input().split()))
    d = {0: 1}
    ans = 0
    t = 0
    for x in A:
        t = (t + x) % M
        ans += (cnt := d.get(t, 0))
        d[t] = cnt + 1
    print(ans)


if __name__ == "__main__":
    main()

-from collections import defaultdict +def main(): +    N, M = list(map(int, input().split())) +    (*A,) = list(map(int, input().split())) +    d = {0: 1} +    ans = 0 +    t = 0 +    for x in A: +        t = (t + x) % M +        ans += (cnt := d.get(t, 0)) +        d[t] = cnt + 1 +    print(ans) -N, M = list(map(int, input().split())) -a = tuple(map(int, input().split())) -ans = 0 -d = defaultdict(int) -d[0] = 1 -t = 0 -for aa in a: -    t += aa -    ans += d[t % M] -    d[t % M] += 1 -print(ans) + +if __name__ == "__main__": +    main()