import math
import collections
N = int(input())
A = list(map(int, input().split()))
ans = 0
# print(A)
sumA = [sum(A[:i+1]) for i in range(N)]
# print(sumA)
countSum = collections.Counter(sumA)
# print(countSum)
for k,v in countSum.items():
    if k == 0:
        ans += math.factorial(v)
        continue
    if v == 1:
        continue
    # print(k)
    # print(v)
    # print(math.factorial(v-1))
    ans += math.factorial(v-1)
print(ans)