module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = 
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  Array.fold_left (fun m a ->
    IntMap.add a (1 + try IntMap.find a m with Not_found -> 0) m) IntMap.empty as_
  |> (fun m -> IntMap.fold (fun a n m ->
      IntMap.add (a - 1) (n + try IntMap.find (a - 1) m with Not_found -> 0) m
      |> IntMap.add (a + 1) (n + try IntMap.find (a + 1) m with Not_found -> 0)) m m)
  |> IntMap.bindings
  |> List.map snd
  |> List.fold_left max 0
  |> Printf.printf "%d\n"