import itertools

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

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

acc = itertools.accumulate(A)

acc = [e % M for e in acc]

cnt_dict = {}

ans = 0

for e in acc:

    if e == 0:

        ans += 1

    if e in cnt_dict:

        cnt_dict[e] += 1

    else:

        cnt_dict[e] = 0

    ans += cnt_dict[e]

print(ans)
def main():

    import itertools

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

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

    acc = itertools.accumulate(A)

    acc = [e % M for e in acc]

    cnt_dict = {}

    ans = 0

    for e in acc:

        if e == 0:

            ans += 1

        if e in cnt_dict:

            cnt_dict[e] += 1

        else:

            cnt_dict[e] = 0

        ans += cnt_dict[e]

    print(ans)



main()
import itertools

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
acc = itertools.accumulate(A)
acc = [e % M for e in acc]
cnt_dict = {}
ans = 0
for e in acc:
    if e == 0:
        ans += 1
    if e in cnt_dict:
        cnt_dict[e] += 1
    else:
        cnt_dict[e] = 0
    ans += cnt_dict[e]
print(ans)

def main():
    import itertools

    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    acc = itertools.accumulate(A)
    acc = [e % M for e in acc]
    cnt_dict = {}
    ans = 0
    for e in acc:
        if e == 0:
            ans += 1
        if e in cnt_dict:
            cnt_dict[e] += 1
        else:
            cnt_dict[e] = 0
        ans += cnt_dict[e]
    print(ans)


main()

-import itertools +def main(): +    import itertools -N, M = list(map(int, input().split())) -A = list(map(int, input().split())) -acc = itertools.accumulate(A) -acc = [e % M for e in acc] -cnt_dict = {} -ans = 0 -for e in acc: -    if e == 0: -        ans += 1 -    if e in cnt_dict: -        cnt_dict[e] += 1 -    else: -        cnt_dict[e] = 0 -    ans += cnt_dict[e] -print(ans) +    N, M = list(map(int, input().split())) +    A = list(map(int, input().split())) +    acc = itertools.accumulate(A) +    acc = [e % M for e in acc] +    cnt_dict = {} +    ans = 0 +    for e in acc: +        if e == 0: +            ans += 1 +        if e in cnt_dict: +            cnt_dict[e] += 1 +        else: +            cnt_dict[e] = 0 +        ans += cnt_dict[e] +    print(ans) + + +main()