import Data.List sortSnd x y | snd x < snd y = LT | otherwise = GT rInt :: String -> Int rInt = read divcards (c:cs) = (c, n) where n | head cs == 'A' = 1 | head cs == 'T' = 10 | head cs == 'J' = 11 | head cs == 'Q' = 12 | head cs == 'K' = 13 | otherwise = rInt cs isfstChar c x = c == fst x sTupleList :: [(Char, Int)] -> [String] sTupleList [] = [] sTupleList (t:ts) = (fc ++ sc) : sTupleList ts where fc = [fst t] sc | snd t == 1 = "A" | snd t == 10 = "T" | snd t == 11 = "J" | snd t == 12 = "Q" | snd t == 13 = "K" | otherwise = show $ snd t main = do getLine cards <- sortBy sortSnd . map divcards . words <$> getLine putStrLn $ unwords $ sTupleList $ (filter (isfstChar 'D') cards) ++ (filter (isfstChar 'C') cards) ++ (filter (isfstChar 'H') cards) ++ (filter (isfstChar 'S') cards)