n,m=(int(i) for i in input().strip().split(" "))
ar=[int(i)%m for i in input().strip().split(" ")]
import sys
sys.setrecursionlimit(50000)

from collections import defaultdict
def find(l,r):

    if l==r:
        if ar[l]%m==0:
            return 1
        else:
            return 0
    if r-l==1:
        c=0
        if ar[l]%m==0:
            c+=1
        if ar[r]%m==0:
            c+=1
        if (ar[l]+ar[r])%m==0:
            c+=1
        return c
    mid= (l+r)//2
    a=find(l,mid)+find(mid+1,r)
    d1=defaultdict(int)
    d2=defaultdict(int)
    curr1=0

    for i in range(mid,l-1,-1):
        curr1=(ar[i]+curr1)%m
        d1[curr1]+=1
    curr2=0
    for i in range(r,mid,-1):
        curr2 = (ar[i] + curr2) % m
        d2[curr2] += 1
    c=0
    for i in d1.keys():
        c+= d1[i]*d2[(m-i)%m]

    return a+c

print(find(0,n-1))