import Data.Bits
import Data.Array
main = do
  n <- read  <$> getLine
  x <- getLine
  let x' = bin2dec (reverse x) 1
      p  = toInteger (popCount x')
      xs = [let nx = complementBit x' i
            in (nx,if nx < x' then -1 else 1) | i <- reverse [0..n-1]]
      ans = map (print . f . g p) xs
  sequence ans

bin2dec :: String -> Integer -> Integer
bin2dec [] _ = 0
bin2dec (x:xs) mul = mul * (read [x]) + bin2dec xs (2*mul)

f :: Integer -> Integer
f 0 = 1
f n = 1 + f n'
  where n' = n `mod` toInteger (popCount n)

g :: Integer -> (Integer,Integer) -> Integer
g p (n,m)= if n /= 0 then n `mod` (p+m) else -1