import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Maybe (fromJust)
import Data.List
import Data.Array.Unboxed
import Data.Array.ST

ary :: [Int] -> UArray Int Int
ary xs = runSTUArray $ do
    let zs = zip (nub xs) (map length . group $ xs)
    a <- newArray (head xs, last xs + 2) 0
    forM_ zs $ \(i,n) -> do
        x <- readArray a i
        writeArray a i (x+n)
    return a

solve :: UArray Int Int -> [Int] -> Int
solve a = foldr f 0
  where
    f x mx = let mx' = (a!x) + (a!(x+1)) + (a!(x+2))
              in max mx mx'

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