import Control.Applicative ((<$>)) import Control.Monad (forM_, when) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.Char (isSpace) import Data.Vector (Vector, (!)) import qualified Data.Vector as V import Data.Vector.Mutable (IOVector) import qualified Data.Vector.Mutable as VM main :: IO () main = do n <- readLn v <- getl (readiv B.readInt) solve n v solve :: Int -> Vector Int -> IO () solve n v = do mv <- V.thaw v yukisort n mv printVector n mv getl :: (ByteString -> a) -> IO a getl f = f <$> B.getLine readiv :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> Vector a readiv f = V.unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s') yukisort :: (Ord a, Eq a) => Int -> IOVector a -> IO () yukisort n mv = do forM_ [1 .. 2*n-4] $ \i -> do forM_ [0 .. i `div` 2] $ \p -> do let q = i - p when (p < q && q <= n - 1) $ do pa <- VM.read mv p qa <- VM.read mv q when (pa > qa) $ do VM.swap mv p q printVector :: Show a => Int -> IOVector a -> IO () printVector n mv = do forM_ [0..n-1] $ \i -> do x <- VM.read mv i if i /= 0 then putStr (" " ++ (show x)) else putStr (show x) putStrLn ""