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 [] = M.size $ M.filter (== x) m
  when x = M.foldr max 0 m
f m (a:as) = f m' as
  where
    m' = M.insertWith (+) (a+1) 1 . M.insertWith (+) (a-1) 1 . M.insertWith (+) a 1 $ m