module Main where import Data.List (sortBy) type Input = [Int] type Output = Int data Model = Model { current :: Int , remain :: [Int] , tops :: [Int] } parse :: String -> Input parse s = let (_ : a) = map read (lines s) in a solve :: Input -> Output solve input = let (x : xs) = sortBy (flip compare) input model' = run Model { current = x , remain = xs , tops = [] } in length (tops model') run :: Model -> Model run model = case model of Model x [] tops -> model { tops = run' x tops } Model x xs tops -> let next = head xs xs' = tail xs in run Model { current = next , remain = xs' , tops = run' x tops } run' :: Int -> [Int] -> [Int] run' x [] = [x] run' x (y : ys) = if x + 1 < y then x : ys else y : run' x ys render :: Output -> String render = show main :: IO () main = interact ( render . solve . parse )