def cmb(n, r):
  if n - r < r: r = n - r
  if r == 0: return 1
  if r == 1: return n

  numerator = [n - r + k + 1 for k in range(r)]
  denominator = [k + 1 for k in range(r)]

  for p in range(2,r+1):
    pivot = denominator[p - 1]
    if pivot > 1:
      offset = (n - r) % p
      for k in range(p-1,r,p):
        numerator[k - offset] /= pivot
        denominator[k] /= pivot

  result = 1
  for k in range(r):
    if numerator[k] > 1:
      result *= int(numerator[k])

  return result

N=int(input())
A=list(map(int, input().split()))
R=[0]*(N+1)
for i in range(N):
  R[i+1]=R[i]+A[i]
  
#m=len(set(R[1:]))
#print((N-m)*m)
#print(R[:10],)
#print(R.count(4))

ans=0
for a in list(set(R[1:])):
  b=R.count(a)
  if b>=2:
    ans+=cmb(b,2)
print(ans)