import Control.Applicative ((<$>)) import Data.List main :: IO () main = solve <$> getLine >>= putStrLn solve :: String -> String solve [] = [] solve s@(x:xs) | x == maxc = x : solve xs | otherwise = [maxc] ++ (take (ix - 2) xs) ++ [x] ++ drop (ix - 1) xs where ys = zip [1 .. length s] s maxc = maximum s ix = fst $ head $ reverse $ sort $ filter (\(x, y) -> y == maxc) ys