import collections

N = int(input())
A = list(map(int, input().split()))
A_ = [0]
count = 0

def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)

for a in A:
    A_.append(a+A_[-1])

for v in collections.Counter(A_).values():
    if v-1 != 0:
        count += factorial(v-1)

print(count)