import Control.Applicative ((<$>)) import Data.List (foldl') main :: IO () main = solve <$> getLine >>= putStrLn solve :: String -> String solve s = foldl' f s [0 .. sl-2] where sl = length s f x i = foldl' (g i) x [i .. sl - 1] g i y j = max y (swap i j) swap i j = let (as, b:bs) = splitAt i s (cs, d:ds) = splitAt (j - i - 1) bs in as ++ (d : cs) ++ (b : ds)