N=gets.to_i
as=gets.split.map(&:to_i)
s1=Array.new(N,0)
s2=Array.new(N,0)
s1[0]=as[0]
N.times do |i|
    next if i==0
    s1[i]=s1[i-1]+as[i]
end
N.times do |i|
    i=N-i-1
    next if i==N-1
    s2[i]=s2[i+1]+as[i]
end
hs=Hash.new{0}
hs_rev=Hash.new{0}
N.times do |i|
    hs[s1[i]]+=1
    hs_rev[s2[i]]+=1
end
cnt=0
hs.values.each do |e|
    cnt+=e*(e-1)/2
end
hs_rev.values.each do |e|
    cnt+=e*(e-1)/2
end
p hs.values
p hs_rev.values
puts cnt