main = do
    getLine
    str <- getLine
    let ls = map b2i $ okikaeList str
    mapM_ print $ map func ls
    
popcount 0 = 0
popcount 1 = 1
popcount x
    | mod x 2 == 0  = popcount $ div x 2
    | otherwise     = 1 + (popcount (div x 2))
    
func n
    | n == 0        = 0
    | pop == 0      = 1
    | otherwise     = 1 + func m
    where pop = popcount n
          m   = mod n pop
          
okikae '0' = '1'
okikae '1' = '0'
          
okikaeN str n = (take n str) ++ [okikae (str!!n)] ++ (drop (n+1) str)

okikaeList str = zipWith okikaeN (replicate (length str) str) [0,1..]

b2i xs = foldl (\x y -> 2 * x + y) 0 $ map (\x -> read [x]) xs


