def solve(string):
    n, m, *a = map(int, string.split())
    for i in range(1, n):
        a[i] += a[i - 1]
    l = [0] * m
    print(a)
    for i in range(n):
        l[a[i] % m] += 1
    ans = l[0]
    for i in range(m):
        ans += l[i] * (l[i] - 1) // 2
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))
