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(m):

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

    mod = {}

    ans = 0

    zi = 0

    for a in aa:

        mod.setdefault(zi, 0)

        mod[zi] += 1

        zi = (zi - a) % m

        ans += mod.get(zi, 0)

    print(ans)





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

f(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)


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

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


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

-def f(n, m): +def f(m): +        mod.setdefault(zi, 0) +        mod[zi] += 1 -        ai = (zi + a) % m -        mod.setdefault(ai, 0) -        mod[ai] += 1 -n, m = list(map(int, input().split())) -f(n, m) +_, m = list(map(int, input().split())) +f(m)