import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List
import qualified Data.IntMap as M

solve :: [Int] -> Int
solve a = let sa = sort a
              ga = map length . group $ sa
              m = M.fromList $ zip (nub sa) ga
           in foldr (f m) 0 $ nub a
  where
    findSum m x = sum . map (flip (M.findWithDefault 0) m) $ [x, x+1, x+2]
    f m a mx = max mx (findSum m a)

main :: IO ()
main = do
    _ <- getLine
    a <- map (fst . fromJust . BS.readInt)
        . BS.words <$> BS.getLine :: IO [Int]
    print $ solve a
