N,M = map(int,input().split())
A = list(map(int,input().split()))

def fact(n):
    res = 1
    for i in range(1,n+1):
        res *= i
    return res


count = res = tmp = tmp2 = 0
for i in range(N):
    count += A[i]
    if count%M == 0:
        tmp2 += 1
    else:
        res += fact(tmp2)
        while count%M != 0 and i==tmp:
            count-= A[tmp]
            tmp += 1
        tmp2 = 0

       
res += fact(tmp2)
    
print(res)
