import qualified Data.ByteString.Lazy.Char8 as C import qualified Data.IntMap.Strict as M import Data.Maybe (fromJust) unsafeReadInt :: C.ByteString -> Int unsafeReadInt = fst . fromJust . C.readInt -- Based on https://rosettacode.org/wiki/Averages/Mode#Haskell maxMode :: [Int] -> Int maxMode xs = fst $ M.findMax $ M.filter (== m) ctr where ctr = foldr (\x -> M.insertWith (+) x 1) M.empty xs m = maximum $ M.elems ctr main :: IO () main = print . maxMode . map unsafeReadInt . tail . C.words =<< C.getContents