
--{-# 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 -> Integer -> [Integer]
solve n x = map (\i -> func (x `complementBit` i)) $ [n-1, n-2 .. 0]

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

func :: Integer -> Integer
func 0 = 0
func !n = 1 + func (n `mod` fromIntegral(popCount n))
