import Data.Bits
import Data.Array
main = do
  n <- read  <$> getLine
  x' <- getLine
  let x = listArray (0,n) x'
      p = length $ filter (=='1') x'
      pow2_0 = listArray (0,n) (take n (iterate (\t -> (2*t)  `mod` (p+1)) 1))
      pow2_1 = listArray (0,n) (take n (iterate (\t -> (2*t)  `mod` (p-1)) 1))
      r0 = sum [if x ! i == '1' then pow2_0 ! (n-1-i) else 0| i <- [0..n-1]]
      r1 = if p /= 1 
        then sum [if x ! i == '1' then pow2_1 ! (n-1-i) else 0| i <- [0..n-1]]
        else undefined 
      xs = [if x ! i == '1' && p /= 1 then 
        (r1 - pow2_1 ! (n-1-i)) `mod` (p-1) 
        else if x ! i == '1' && p == 1 then -1
        else (r0 + pow2_0 ! (n-1-i)) `mod` (p+1) | i <- [0..(n-1)]]
      ans = fmap (print . f) xs
  sequence ans

f :: Int -> Int
f n
  | n == -1 = 0
  | n == 0 = 1
  | otherwise = 1 + f n'
  where n' = n `mod` popCount n


