import Control.Applicative import qualified Data.Set as S f set | S.null set = [] | t=="z" = h:f set' | otherwise = h:(f $ S.insert t set') where ((h:t),set') = S.deleteFindMin set main = do n:s <- lines <$> getContents putStrLn $ f $ S.fromList $ map (++"z") s