import Data.List (sortBy) main :: IO () main = getLine >> solve <$> f >>= print where f = map read <$> words <$> getLine solve :: [Int] -> Int solve = f 0 . sortBy (flip compare) where f ct [x] = ct + x f ct (x:y:ys) | x == y + 1 = f ct (y:ys) | otherwise = f (ct + x) (y:ys)