program AGC023A
    implicit none
    integer(8)::N,i,ans,scount
    integer(8),allocatable,dimension(:)::A,S
    read*,N
    allocate(A(N))
    allocate(S(N+1))
    read*,A
    S(1)=0
    ans=0

    do i=2,N+1
        S(i)=S(i-1)+A(i-1)
    end do
    S=iqsort(S)

    do i=1,N+1
        if(i==1)then
            scount=1
        else if(S(i)==S(i-1))then
            scount=scount+1
        else
            ans=ans+(scount*(scount-1))/2
            scount=1
        end if
    end do
    ans=ans+(scount*(scount-1))/2

    print'(i0)',ans
contains
    recursive function iqsort(ix) result(ires)
      integer(8), allocatable :: ires(:)
      integer(8), intent(in)  :: ix(:)
      integer :: k
      if (size(ix) <= 1) then 
        ires = ix
      else  
        k = ix(size(ix) / 2)
        ires = [iqsort(pack(ix, ix < k)), pack(ix, ix == k), iqsort(pack(ix, ix > k))] 
      end if
    end function iqsort
end program AGC023A