program anything_goes_to_zero
  implicit none
  integer :: n, i, m, k
  integer(8) :: cnt = 0, rem1to0 = 0, rem0to1 = 0, rem
  character(200000) :: x
  read(*,*) n
  read(*,*) x
  do i = 1, n
    if (x(i:i) == '1') cnt = cnt + 1
  end do
  do i = 1, n
    k = ichar(x(i:i)) - 48
    if (cnt > 1) rem1to0 = mod(2 * rem1to0 + k, cnt - 1)
    rem0to1 = mod(2 * rem0to1 + k, cnt + 1)
  end do
  do i = 1, n
    if (x(i:i) == '1') then
      if (cnt < 2) then
        write(*,'(i0)') 0
        cycle
      end if
      rem = modulo(rem1to0 - pow(2_8, n - i, cnt - 1), cnt - 1)
    else
      rem = mod(rem0to1 + pow(2_8, n - i, cnt + 1), cnt + 1)
    end if
    m = 1
    do while (rem > 0)
      k = popcnt(rem)
      rem = mod(rem, k)
      m = m + 1
    end do
    write(*,'(i0)') m
  end do
contains
  pure elemental integer function pow(a, n, modu) result(res)
    integer(8), intent(in) :: a, modu
    integer, intent(in) :: n
    integer(8) :: b
    integer :: m
    res = 1
    b = a
    m = n
    do while (m > 0)
      if (btest(m, 0)) res = mod(res * b, modu)
      b = mod(b * b, modu)
      m = rshift(m, 1)
    end do
  end
end program anything_goes_to_zero