import Data.Array import Data.List main = do n <- read <$> getLine as <- map read . words <$> getLine putStrLn $ concat $ intersperse " " $ map show $ elems $ yukiSort n as yukiSort :: Int -> [Int] -> Array Int Int yukiSort n as = yS (listArray (0,n-1) as) [1..2*n-3] where yS aa [] = aa yS aa (i:is) = yS (foldl (\a p->if a!p>a!(i-p) then a//[(p,a!(i-p)),(i-p,a!p)] else a) aa ps) is where ps = takeWhile ((i>).(*2)) $ dropWhile ((n-1<).(i-)) [0..]