n =gets.to_i
as=gets.strip.split(//).collect{|x|x.to_i}
ts=[0]
n.times{|i|
ts<<(ts[-1]+as[i+1])
}
ts.sort!
ts<<'end'
def c(n)
if n>0
n*(n-1)/2
else
0
end
end
l=nil
t=nil
i=nil
sum=0
(n+2).times{|j|
if ts[j]!=t
    if t!=nil
        sum+=c(j-i)
        i=j
        t=ts[j]
    end
}
puts sum
