import io.StdIn._
object Main extends App {
    val n = readInt
    val as = readLine.split(" ").map(_.toInt)
    
    val number = as.distinct
    val counts = number.map(n => as.count(_ == n))

    val length = number.length
    def rec(index: Int, acc: List[Int]): List[Int] = {
        if(length-1 < index) return acc
        else if(index == length-1) {
            val target = counts(index)
            val prev = counts(index-1)
            rec(index+1, acc:+(target+prev))
        }
        else if(0 < index && index < length-1) {
            val target = counts(index)
            val prev = counts(index-1)
            val next = counts(index+1)
            rec(index+1, acc:+(target+prev+next))
        }
        else {
            val target = counts(index)
            val next = counts(index+1)
            rec(index+1, acc:+(target+next))
        }
    }

    if(length == 1) println(1) else println(rec(0, Nil).max)

}