import Data.Bits
import Data.Array
main = do
  n <- read  <$> getLine
  x <- getLine
  let x' = bin2dec (reverse x) 1
      xs = [complementBit x' i | i <- reverse [0..n-1]]
      ans = map (print . f) 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 = 0
f n = 1 + f n'
  where n' = n `mod` toInteger (popCount n)

