import Data.Array
import Data.Bits
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt

getInt = readInt <$> BS.getLine

getVU n = VU.reverse . VU.unfoldrN n BS.uncons <$> BS.getLine

solve' :: Integer -> Integer -> Integer
solve' d i = do
  let p = popCount d
  let i' = i + 1
  let r = d `mod` (fromIntegral p)
  if r /= 0
    then solve' r i'
    else i'

solve :: Int -> Integer -> Int -> Integer -> Integer -> Integer -> Integer -> Integer
solve b x n p0 p1 s0 s1 = do
  let x' = complementBit x b
  if x' == 0
    then 0
    else do
      let b' = testBit x' (fromIntegral b)
      let d = if b' then (2 ^ (fromIntegral b) `mod` p0 + s0) `mod` p0 else (- 2 ^ (fromIntegral b) `mod` p1 + s1) `mod` p1
      if d == 0
        then 1
        else solve' d 1

createBits :: VU.Vector Char -> Integer
createBits = VU.ifoldl' (\bit index value -> if value == '1' then setBit bit index else bit) zeroBits

main = do
  n <- getInt
  x <- getVU n
  let x' = createBits x
  let ppc = fromIntegral (popCount x')
  let p0 = ppc + 1
  let p1 = ppc - 1
  let s0 = x' `mod` p0
  let s1 = x' `mod` p1
  let bs = reverse [0 .. (fromIntegral n -1)]
  let x'' = map (\b -> solve b x' n p0 p1 s0 s1) bs
  mapM_ print x''
