fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val aList = readLine()?.split(" ")?.map { it.toInt() } ?: return

    val map = mutableMapOf<Int, Int>()

    for (a in aList) {
        val a1 = map.putIfAbsent2(a - 1, 0)
        val a2 = map.putIfAbsent2(a, 0)
        val a3 = map.putIfAbsent2(a + 1, 0)

        map[a - 1] = if (a1 != null) a1 + 1 else 1
        map[a] = if (a2 != null) a2 + 1 else 1
        map[a + 1] = if (a3 != null) a3 + 1 else 1
    }

    val max = map.maxBy { it.value }?.value ?: return

    println(max)
}

private fun <K, V> MutableMap<K, V>.putIfAbsent2(key: K, value: V): V? {
    return if (containsKey(key)) {
        get(key)
    } else {
        put(key, value)
    }
}