import sys
import itertools
from collections import Counter
import math
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
cumsum = itertools.accumulate(a)
counter = Counter(cumsum)
ans = 0

for key, value in counter.items():
    if key == 0:
        value += 1
    if value == 1:
        continue
    ans += math.factorial(value - 1)
print(ans)
