N = gets.to_i
A = gets.split(" ").map { |e| e.to_i }

cur = 0
sum = []
sum << 0
for i in 0..N-1 do
  cur += A[i]
  sum << cur
end

# count = 0
# for k in 0..N-1 do
#   if sum[k] == 0 #0番目からk番目までが0
#     count += 1
#   end
#   for i in k+1..N-1 do
#     if sum[i]-sum[k] == 0 #k+1番目からi番目までの和が0
#       count += 1
#     end
#   end
# end
# print sum
# puts count

# sumの同じ値が何個あるか

count = 0
sum.sort!
for i in 0..N do
  if i == 0 or sum[i] != sum[i-1]

    num = sum.find_all{|e| e == sum[i]}.count
    if num > 1
      count += num*(num-1)/2
    end
  end
end
puts count
