Problem:
Score : 300 points

Problem Statement

You are given an integer sequence of length N, a_1,a_2,...,a_N.

For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.

After these operations, you select an integer X and count the number of i such that a_i=X.

Maximize this count by making optimal choices.

Constraints

1≤N≤10^5

0≤a_i<10^5 (1≤i≤N)

a_i is an integer.

Input

The input is given from Standard Input in the following format:

N
a_1 a_2 .. a_N

Output

Print the maximum possible number of i such that a_i=X.

Sample Input 1

7
3 1 4 1 5 9 2

Sample Output 1

4

For example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4, the maximum possible count.

Sample Input 2

10
0 1 2 3 4 5 6 7 8 9

Sample Output 2

3

Sample Input 3

1
99999

Sample Output 3

1

Solution in Rust (1.15.1) (judge verdict: Runtime Error)

#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    if n == 1 {
        println!("1");
        return;
    } else if n == 2 {
        if a[0] + 1 == a[1] || a[0] - 1 == a[1] || a[0] == a[1] {
            println!("2");
            return;
        } else {
            println!("1");
            return;
        }
    }
    let mut a = a;
    let mut ms = HashMap::new();
    for i in a.iter() {
        if ms.contains_key(&i) {
            let x= ms.get_mut(&i).unwrap();
            *x += 1;
        } else {
            ms.insert(i, 1_i64);
        }
    }

    let mut vs = Vec::new();
    for (k, v) in ms.clone() {
        vs.push((k, v));
    }
    vs.sort_by_key(|c| c.0);

    if vs[0].0 + 1 == *vs[1].0 {
        vs[0].1 += ms[vs[1].0].clone();
    }
    for i in 1..vs.len() - 1 {
        if vs[i].0 + 1 == *vs[i + 1].0 {
            vs[i].1 += ms[vs[i + 1].0].clone();
        }
        if vs[i].0 - 1 == *vs[i - 1].0 {
            vs[i].1 += ms[vs[i - 1].0].clone();
        }
    }
    let len = vs.len().clone();
    if vs[len - 1].0 - 1 == *vs[len - 2].0 {
        vs[len - 1].1 += ms[vs[len - 2].0].clone();
    }
    let mut ma = std::i64::MIN;
    for i in vs.into_iter() {
        ma = std::cmp::max(i.1, ma);
    }
    println!("{}", ma);
}