main :: IO () main = interact $ solve . map read . words solve :: [Int] -> String solve (x:_:xs) = if y `mod` 10 == 1 then show y ++ "st" else if y `mod` 10 == 2 then show y ++ "nd" else if y `mod` 10 == 3 then show y ++ "rd" else show y ++ "th" where y = fst $ foldl (\(rank, nama) x -> if nama > x then (rank, nama) else (rank + 1, nama)) (1, x) xs