(* O(n) *)
let kMax = 100000
let n = Scanf.scanf " %d" @@ (+) 0
let ns = Array.make (kMax + 10) 0
let ans = ref 0
let _ =
  for i = 0 to n - 1 do
    let a = Scanf.scanf " %d" @@ (+) 0 in
    ns.(a) <- ns.(a) + 1
  done;
  for i = 0 to kMax - 1 do
    ans := max !ans @@ ns.(i) + ns.(i + 1) + ns.(i + 2)
  done;
  Printf.printf "%d\n" !ans