program sample
    implicit none
    character(200000)::s
    integer(8) :: i,j,m,n,a,b,c,time,sa,sa0,m0
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n
    read(*,*)s
    allocate(x(n),y(n))

    do i=1,n
        if(s(i:i) .eq. '0')then
            x(i)=0
        else
            x(i)=1
        end if
    end do
    m0=0
    do i=1,n
        m0=m0+x(i)*2**(n-i)
    end do
    sa0=sum(x)
    time=0
    do i=1,n
        if(x(i)==0)then
            sa=sa0+1
            m=m0+2**(n-i)
            do
                time=time+1
                call rou(m,sa,a,b)
                if (a==0)then
                    exit
                end if
                m=a
                sa=b
            end do
            write(*,*)time
            time=0
            


        else
            sa=sa0-1
            if(sa==0)then
                write(*,*)0
                cycle
            end if
            m=m0-2**(n-i)
            time=0
            do
                time=time+1
                call rou(m,sa,a,b)
                if (a==0)then
                    exit
                end if
                m=a
                sa=b
            end do
            write(*,*)time
            time=0
        end if
    end do


  
   
    stop
    contains

    
        subroutine rou(m,s,m1,s1)
        implicit none
        integer(8),intent(in) :: m,s
        integer(8),intent(out) ::m1,s1
        
        integer(8)::i,n,a

        m1=mod(m,s)
        a=m1
        s1=0
        do while(a>0)
            s1=s1+mod(a,2)
            a=a/2
        enddo
        end subroutine rou
end program sample
  

