n = gets.to_i
needsCalc = Array.new(n + 1) {|i| true}
inputs = gets.split(" ").map{|v| v.to_i}

comb = 0
n.times{|i|
  next if !needsCalc[i]
  total = 0
  c = 0
  for j in i...n
    total += inputs[j]
    if total == 0
      needsCalc[j + 1] = false
      c += 1
    end
  end
  comb += (c + 1) * c / 2
}
puts comb
