object Solution { def groupByDiff(acc: List[Vector[Int]], n: Int): List[Vector[Int]] = { val lastVec = acc.head val last = lastVec.headOption.getOrElse(n - 2) if (n - last <= 1) (lastVec :+ n) :: acc.drop(1) else Vector(n) :: acc } /* def main(args: Array[String]) { val n = readLine() val xs = readLine().split(" ").toVector.map(_.toInt).sorted val pairs = for { i <- (0 until xs.length) j <- (i + 1 until xs.length) r = Math.abs(xs(i) - xs(j)) if r <= 1 } yield ((xs(i), xs(j))) println(pairs) val sortedPairs = pairs.map(_._1).sorted val grouped = sortedPairs.groupBy(p => p).mapValues(_.size).map {case (k, v) => v} println(grouped) val res = grouped.max println(res) } */ def main(args: Array[String]) { val n = readLine() val xs = readLine().split(" ").toList.map(_.toInt).sorted val init = List(Vector[Int]()) val res = xs.foldLeft(init)(groupByDiff) println(res.map(_.length).max) } }