import qualified Data.IntMap.Lazy as M

main = do
  getLine
  as <- map read . words <$> getLine
  print $ solve as

solve as = f M.empty as

f m [] = snd $ M.findMax m
f m (a:as) = f m' as
  where
    m' = M.insertWith (+) (a+1) . M.insertWith (+) (a-1) . M.insertWith (+) a 1 $ m