# -*- coding: utf-8 -*-
import collections
import math

lenums = int(input())
nums = [int(i) for i in input().split()]
answer = 0

dp = [0]

for i in range(lenums):
    dp.append(dp[i] + nums[i])

count_dict = collections.Counter(dp)

for i in count_dict.values():
    if i <= 1:
        continue
    answer = answer + math.factorial(i - 1)

print(answer)
