import Control.Monad.Primitive (PrimState)
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    _ <- B.getLine
    vs <- V.fromList . map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    mv <- MV.replicate (V.maximum vs + 3) 0 :: IO (MV.MVector (PrimState IO) Int)
    V.forM_ vs $ \i -> MV.unsafeModify mv succ (i + 1)
    v <- V.unsafeFreeze mv
    let v1 = v
        v2 = V.tail v1
        v3 = V.tail v2
    print $ V.maximum $ V.zipWith3 (\x y z -> x + y + z) v1 v2 v3
