import sequtils, strutils, algorithm, math, future, sets, tables, hashes

let read = iterator : string {.closure.} = (while true : (for s in stdin.readLine.split : yield s))


proc solve() =
   
   var
      n = read().parseInt
      a = newSeq[int](n).mapit(read().parseInt)
      acm = newSeq[int](n + 1)
      tab = initTable[int, int]()
      cnt = 0
      ans = 0
   
   acm[0] = 0
   tab[0] = 0
   for i in 1 .. n : 
      acm[i] = acm[i - 1] + a[i - 1]
      if acm[i] == 0 : 
         ans += 1
   
   acm.sort(system.cmp)
   cnt = 1
   for i in 1 .. n : 
      if acm[i] == acm[i - 1] : 
         cnt += 1
      else : 
         ans += cnt * (cnt - 1) div 2
         cnt = 1
   ans += (cnt - 2) * (cnt - 1) div 2
   echo ans  

solve()