N = int(input())
A = list(map(int, input().split()))

ct = {}
s = 0
for i in range(N):
  s += A[i]
  ct[s] = ct.get(s, 0) + 1

ans = 0
s = 0
for a in A:
  ans += ct.get(s, 0)
  s += a
  ct[s] -= 1

print(ans)