import Data.List (sortBy) import Data.Ord (comparing) data Brother = Brother {height :: Int, weight :: Int} deriving (Eq, Show, Read) instance Ord Brother where compare x y = let c = compare (height y) (height x) in if c /= EQ then c else compare (weight x) (weight y) sortBrothers :: Ord a => [a] -> [String] sortBrothers = fmap fst . sortBy (comparing snd) . zip ["A", "B", "C"] readInt :: String -> Int readInt = read parseBrother :: [Int] -> Brother parseBrother [x, y] = Brother x y parseBrother _ = error "parse error" main :: IO () main = interact $ unlines . sortBrothers . fmap (parseBrother . fmap readInt . words) . take 3 . lines