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

aa = [int(ak) % m for ak in input().split()]

mod = {}

ans = 0

zi = 0

for a in aa:

    zi = (zi - a) % m

    ai = (zi + a) % m

    mod.setdefault(ai,0)

    mod[ai] += 1

    ans += mod.get(zi,0)

print(ans)

def f(n, m):

    aa = [int(ak) % m for ak in input().split()]

    mod = {}

    ans = 0

    zi = 0

    for a in aa:

        zi = (zi - a) % m

        ai = (zi + a) % m

        mod.setdefault(ai, 0)

        mod[ai] += 1

        ans += mod.get(zi, 0)

    print(ans)





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

f(n, m)

n, m = list(map(int, input().split()))
aa = [int(ak) % m for ak in input().split()]
mod = {}
ans = 0
zi = 0
for a in aa:
    zi = (zi - a) % m
    ai = (zi + a) % m
    mod.setdefault(ai, 0)
    mod[ai] += 1
    ans += mod.get(zi, 0)
print(ans)

def f(n, m):
    aa = [int(ak) % m for ak in input().split()]
    mod = {}
    ans = 0
    zi = 0
    for a in aa:
        zi = (zi - a) % m
        ai = (zi + a) % m
        mod.setdefault(ai, 0)
        mod[ai] += 1
        ans += mod.get(zi, 0)
    print(ans)


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

+def f(n, m): +    aa = [int(ak) % m for ak in input().split()] +    mod = {} +    ans = 0 +    zi = 0 +    for a in aa: +        zi = (zi - a) % m +        ai = (zi + a) % m +        mod.setdefault(ai, 0) +        mod[ai] += 1 +        ans += mod.get(zi, 0) +    print(ans) + + -aa = [int(ak) % m for ak in input().split()] -mod = {} -ans = 0 -zi = 0 -for a in aa: -    zi = (zi - a) % m -    ai = (zi + a) % m -    mod.setdefault(ai, 0) -    mod[ai] += 1 -    ans += mod.get(zi, 0) -print(ans) +f(n, m)