f :: [Int] -> [Int] f [] = [] f ks = ks !! l : f a ++ f b where l = length ks `div` 2 a = take l ks b = tail $ drop l ks main = readLn >>= putStrLn . unwords . map show . swap . f . (\k -> [1 .. 2^k - 1]) where swap (n:ns) = ns ++ [n]