import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List (length, sort, group)
import Data.Array.Unboxed
import Prelude hiding ((!!))

solve :: [Int] -> Int
solve xs = foldr f 0 xs
  where
    hx = head xs
    lx = last xs
    gs = group xs
    zs = zip (map head gs) (map length gs)
    aa = accumArray (+) 0 (hx, lx) zs :: UArray Int Int
    (!!) a i = let (_,e) = bounds a in if i <= e then a!i else 0
    f x a = let a' = aa!x + aa!!(x+1) + aa!!(x+2) in max a a'

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