class Node:
    def __init__(self,mod):
        self.mod = mod
        self.samemod = 1
        self.right = None
        self.left = None
def sumx(node,s):
    if node.left != None:
        s = sumx(node.left,s)
    s += node.samemod*(node.samemod-1)//2
    if node.right != None:
        s = sumx(node.right,s)
    return s
def add(node,x):
    if node == None:
        return Node(x)
    elif node.mod == x:
        node.samemod += 1
    elif node.mod > x:
        node.left = add(node.left,x)
    else:
        node.right = add(node.right,x)
    return node

n,m = map(int,input().split())
A = list(map(int,input().split()))
B = [0]
tmp = 0
root = None
root = add(root,0)
for i in range(n):
    tmp = B[i]+A[i]
    B.append(tmp)
    root = add(root,tmp%m)
ans = sumx(root,0)
print(ans)