program test
implicit none
integer(8) :: n,a(200000),ruiseki(200000)=0,y(200000)=0.,t
integer    :: x=0,i,j,k,l,combo
read(*,*) n

  read(*,*) (a(i),i=1,n)

ruiseki(1) = a(1)
 
do i=2,n
  ruiseki(i) = ruiseki(i-1) + a(i)
enddo


do i=1,n
  if(ruiseki(i) == 0) then
    x = x+1
  endif
enddo

y = ruiseki
 
l = n/2+1
k = n
do while(k /= 1)
  if(l > 1) then
    l = l-1
    t = y(l)
  else
    t = y(k)
    y(k) = y(1)
    k = k-1
    if(k == 1) then
      y(1) = t
      exit
    endif
  endif
  i = l
  j = l+l
  do while(j <= k)
    if(j < k) then
      if(y(j) < y(j+1)) j = j+1
    endif
    if (t < y(j)) then
      y(i) = y(j)
      i = j
      j = j+j
    else
      j = k+1
    endif
  enddo
  y(i) = t
enddo

combo = 1

do i = 2,n
  if(y(i) == y(i-1)) then
    combo = combo + 1
  else if (combo >= 2) then
    x = x + combo * (combo-1) /2 
    combo = 1
  else
    combo = 1
  endif
enddo

  if (combo >= 2) then
    x = x + combo * (combo-1) /2 
  endif

write(*,*) x


end program