import math

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

b=0

c={}

for a in input().split():

  b+=int(a)

  c[b%m]=c.get(b%m,0)+1

print((sum([math.factorial(x)//(math.factorial(x-2)*math.factorial(2))if x>1else 0 for x in list(c.values())])+c.get(0,0)))
n,m=list(map(int,input().split()));d={0:1};r=s=0

for i in input().split():s+=int(i);s%=m;x=d.get(s,0);r+=x;d[s]=x+1

print(r)
import math

n, m = list(map(int, input().split()))
b = 0
c = {}
for a in input().split():
    b += int(a)
    c[b % m] = c.get(b % m, 0) + 1
print(
    (
        sum(
            [
                math.factorial(x) // (math.factorial(x - 2) * math.factorial(2))
                if x > 1
                else 0
                for x in list(c.values())
            ]
        )
        + c.get(0, 0)
    )
)

n, m = list(map(int, input().split()))
d = {0: 1}
r = s = 0
for i in input().split():
    s += int(i)
    s %= m
    x = d.get(s, 0)
    r += x
    d[s] = x + 1
print(r)

-import math - -b = 0 -c = {} -for a in input().split(): -    b += int(a) -    c[b % m] = c.get(b % m, 0) + 1 -print( -    ( -        sum( -            [ -                math.factorial(x) // (math.factorial(x - 2) * math.factorial(2)) -                if x > 1 -                else 0 -                for x in list(c.values()) -            ] -        ) -        + c.get(0, 0) -    ) -) +d = {0: 1} +r = s = 0 +for i in input().split(): +    s += int(i) +    s %= m +    x = d.get(s, 0) +    r += x +    d[s] = x + 1 +print(r)