{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Data.Array.Unboxed    (UArray, (!))
import qualified Data.Array.Unboxed    as A
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  n <- readLn
  as <- map readInt . BS.words <$> BS.getLine
  print $ solve n as

solve :: Int -> [Int] -> Int
solve n as = maximum . map sum $ windows 3 bs where
  bs = A.accumArray (+) 0 (0, 10^5) [(a, 1) | a <- as]

windows :: Int -> UArray Int Int -> [[Int]]
windows n as = map (\i -> slice i n as) is where
  is = [l .. h-n]
  (l, h) = A.bounds as

slice :: Int -> Int -> UArray Int Int -> [Int]
slice i n as = map (as !) [i .. i+n-1]

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt
