import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import Data.Bits
import Data.Maybe

main = do
  li <- BS.getLine
  let Just (n,_) = BS.readInt li
  xs <- BS.getLine
  mapM_ print $ compute n xs

pcBS :: BS.ByteString -> Int
pcBS xs = BS.count '1' xs

-- 長さnのxs（ただし'1'の個数はpc）のi文字めを逆転させた2進数をそのpopCountで割った余り
-- pc1 == 0 の場合はf=0である！
stepBS :: Int -> BS.ByteString -> Int -> Int -> Maybe Int
stepBS n xs pc i
  | pc1 == 0 = Nothing
  | pc1 == 1 = Just 0
  | otherwise = Just $ foldl' (\acc b -> mod (acc+acc+b) pc1) 0 bs
  where
    pc1 = if BS.index xs i == '1' then pred pc else succ pc
    bs = [if i == j then 1-b else b | j <- [0..n-1], let b = digitToInt $ BS.index xs j]

compute :: Int -> BS.ByteString -> [Int]
compute n xs = [ maybe 0 f step1 | i <- [0..n-1], let step1 = stepBS n xs pc0 i ]
  where
	pc0 = pcBS xs

step x = x `mod` popCount x

f = succ . length . takeWhile (0 /=) . iterate step
{-
最大2万桁の2進数を扱うのは、Integerでやればできるかもしらんがどうかという。
最初のpopCountはたかだか2万なので、あまりもそれ未満。だから初回さえ乗り切ればあとは普通の整数で間に合う。
をちゃんと実装してみよう。
-}