
--{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE BangPatterns #-}

module Main where

import Debug.Trace
import Data.Bits
import Control.Monad
--import Data.List
--import Data.Char
--import qualified Data.Set.Strict as Set
--import qualified Data.Map.Strict as Map

main :: IO ()
main = do
  a <- read <$> getLine
  b <- binToInt <$> getLine
  --a `traceShow`
  forM_ (solve a b) $ \s -> do
    print s


solve :: Int -> Int -> [Int]
solve n x = map (\i -> func (x `xor` (2 ^ i)))$ [n-1, n-2 ..0]

binToInt :: String -> Int
binToInt xs = binToInt' 0 xs
  where
    binToInt' !n [] = n
    binToInt' !n (x:xs) = binToInt' (2 * n + (if x == '1' then 1 else 0)) xs

popcount :: Int -> Int
popcount 0 = 0
popcount !n = (if n `mod` 2 == 0 then 0 else 1) + popcount (n `div` 2)

func :: Int -> Int
func n = func' 0 n
  where
    func' !i 0 = i
    func' !i m = func' (i + 1) (m `mod` popcount m)
