import Control.Arrow
import Data.List
import qualified Data.IntMap.Strict as M

main = do
  getLine
  as <- map read . words <$> getLine
  print (together as)

(!?) m k = M.findWithDefault 0 k m

together as = foldr (\a acc -> max acc (ans!?a + ans!?(a-1) + ans!?(a+1))) 0 [minimum as .. maximum as]
  where
     ans = M.fromDistinctAscList $ map (head &&& length) $ group $ sort as

