n = int(input())
a = list(map(int, input().split()))

count_list = [[0,0]]*(n*10**9+1)
s = 0
for i in range(n):
  s += a[i]
  if s > 0:
    count_list[s][0] += 1
  elif s < 0:
    count_list[s][1] += 1
  else:
    count_list[s][0] += 1
count = 0
count += count_list[0][0] * (count_list[0][0] + 1) // 2
for i in range(1, len(count_list)):
  count+= count_list[i][0] * count_list[i][1]
print(count)