import qualified Data.Set as S main = readLn >>= putStrLn . unwords . map show . (\(n:ns) -> ns++[n]) . btree . (\n -> S.fromList [1..2^n-1]) btree s | S.null s = [] | otherwise = head (S.toList root) : concat [btree left, btree right] where [left,root,right] = S.splitRoot s