from collections import Counter
from math import factorial
n = int(input())
a = list(map(int, input().split()))
s = [0]
for i in a:
    s.append(s[-1]+i)
a = Counter(s)
ans = 0
for v in a.values():
    ans += factorial(v-1) if v > 1 else 0
print(ans)