import Data.Bits
import Data.Array
main = do
  n <- read  <$> getLine
  x <- getLine
  let 
      p = length $ filter (=='1') x
      pow2_0 = reverse $ take n $ iterate (\t -> (2*t)  `mod` (p+1)) 1
      pow2_1 = reverse $ take n $ iterate (\t -> (2*t)  `mod` (p-1)) 1
      r0 = sum $ zipWith (\c m -> if c == '1' then m else 0) x pow2_0
      r1 = sum $ zipWith (\c m -> if c == '1' then m else 0) x pow2_1
      xs = zipWith3 (\c m0 m1 -> if c == '1' && p /= 1 then (r1 - m1) `mod` (p-1) else if c == '1' && p == 1 then -1 else (r0 + m0) `mod` (p+1)) x pow2_0 pow2_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


