import math

n = int(input())
a = [int(i) for i in input().split()]
total_zero = 0
find_zero = []
for i in range(n):
  if i in find_zero:
    continue
  total = 0
  zero = 0
  for j in range(i,n):
    total += a[j]
    if total == 0:
      zero += 1
      find_zero.append(j+1)
  if zero > 0:
    total_zero += math.factorial(zero)
  #for j in a[i:]:
  #  total += j
  #  if total == 0:
  #    zero += 1

print(total_zero)
