import qualified Control.Monad as M import qualified Control.Monad.ST as S import qualified Data.IntMap.Lazy as Map import qualified Data.Vector.Unboxed as V import qualified Data.Vector.Unboxed.Mutable as VM main :: IO () main = do n <- readLn xs <- map read . words <$> getLine putStrLn . unwords . map show $ yukisort n xs yukisort :: Int -> [Int] -> [Int] yukisort n xs = V.toList $ S.runST $ do vec <- VM.unsafeNew n mapM_ (\(k, v) -> VM.write vec k v) $ zip [0..] xs mapM_ (proc vec) [1..(2 * n - 4)] V.freeze vec where calcMap = createMap n proc vec i = do let comb = (Map.!) calcMap i M.forM_ comb $ \(p, q) -> do a <- VM.unsafeRead vec p b <- VM.unsafeRead vec q M.when (a > b) $ VM.unsafeSwap vec p q createMap :: Int -> Map.IntMap [(Int, Int)] createMap n = foldl (\m (p, q) -> Map.insertWith insertFunc (p + q) [(p, q)] m) Map.empty comb where comb = [(p, q) | p <- [0..n - 1], q <- [0..n - 1], p < q] insertFunc new old = new !! 0 : old