import Utils._, annotation._, collection._, util._, control._, math.Ordering.Implicits._, Searching._

object _776B extends CodeForcesApp {
  override def apply(io: IO) = {import io.{read, write, writeAll, writeLine}
    val n = read[Int]
    val ans = Array.ofDim[Int](n)

    for {
      i <- 0 until n if ans(i) == 0
      _ = ans(i) = 1
      j <- 2*(i+2) - 2 until n by (i + 2)
    } ans(j) = 2

    write(ans.max).writeLine().writeAll(ans)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)
    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
    def mapValuesSafely[V2](f: V => V2): Map[K, V2] = m.mapValues(f).view.force //Hack to get around https://issues.scala-lang.org/browse/SI-4776
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "YES" else "NO"
  }
  implicit class IntExtensions(val x: Int) extends AnyVal {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }
  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]
  def memoize[A, B](f: A => B): A ==> B = map[A] using f
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {
    val (xs, ys) = points.unzip
    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)
  }
  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {
    val shape = new java.awt.geom.GeneralPath()
    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}
    points.tail foreach {case (x, y) => shape.lineTo(x, y)}
    shape.closePath()
    shape
  }
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

class IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
  val printer = new PrintWriter(out, true)

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(read).to[C]

  def readTill(delim: String): String = tokenizer().get.nextToken(delim)
  def readTillEndOfLine(): String = readTill("\n\r")

  def readAll[A: IO.Read]: (Int, Vector[A]) = {
    val data = read[Vector[A]]
    (data.length, data)
  }

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  def write(obj: Any): this.type = {
    printer.print(obj)
    this
  }
  def writeLine(): this.type = {
    printer.println()
    this
  }
  def writeLine(obj: Any): this.type = {
    printer.println(obj)
    this
  }
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                      : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

//package solutions

import java.io.PrintWriter
import java.util.Scanner

import scala.annotation.tailrec
import scala.collection.parallel.mutable.ParSet

/**
  * @author traff
  */

object SolTaskB extends App {

  def sieveOfEratosthenes(limit: Int) = {
    val (primes: ParSet[Int], sqrtLimit) = (ParSet.empty ++ (2 to limit), math.sqrt(limit).toInt)

    @tailrec
    def prim(candidate: Int): Unit = {
      if (candidate <= sqrtLimit) {
        if (primes contains candidate) primes --= candidate * candidate to limit by candidate
        prim(candidate + 1)
      }
    }

    prim(2)
    primes
  }

  override def main(args: Array[String]): Unit = {
    val out = new PrintWriter(System.out)

    run(new Scanner(System.in), out)

    out.close()
  }

  def run(s: Scanner, out: PrintWriter): Unit = {
    val n = s.nextInt()

    val primes = sieveOfEratosthenes(n + 1)

    var colors = new Array[Int](n)

    if (n > 2) {
      out.println(2)

      for (i <- 2 to n + 1) {
        if (primes contains i) {
          out.print(s"1 ")
        } else {
          out.print(s"2 ")
        }
      }
    } else {
      out.println(1)
      for (i <- 2 to n + 1) {
        out.print(s"1 ")
      }
    }
  }

}

object B776 {

  import IO._
  import collection.{mutable => cu}
  import scala.collection.mutable.ArrayBuffer
  case class Sieve(to: Int) {
    val primes = scala.collection.mutable.ArrayBuffer.empty[Int]
    val isComposite = Array.fill(to + 1)(false)
    def sieve(): Unit = { // Works in linear time
      for (i <- 2 until to) {
        if (!isComposite(i)) primes.append(i)
        var j = 0
        var break = false
        while (j < primes.size && i * primes(j) < to && !break) {
          isComposite(i * primes(j)) = true
          if (i % primes(j) == 0)
            break = true
          j += 1
        }
      }
    }
  }
  val s = Sieve(100000 + 10)
  s.sieve()
  def main(args: Array[String]): Unit = {
    val n = readInt
    if (n <= 2)
      out.println(1)
    else
      out.println(2)
    out.println(
      s.isComposite
        .slice(2, n + 2)
        .map { if (_) 2 else 1 }
        .mkString(" ")
    )
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(
      new java.io.InputStreamReader(
        if (System.getProperty("ONLINE_JUDGE") != null) System.in
        else new java.io.FileInputStream("src/input")
      )
    )
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInt: Int = tokenizeLine.nextToken.toInt

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

//package solutions

import java.io.PrintWriter
import java.util.Scanner

import scala.annotation.tailrec
import scala.collection.parallel.mutable.ParSet

/**
  * @author traff
  */

object SolTaskB extends App {

  def sieveOfEratosthenes(limit: Int) = {
    val (primes: ParSet[Int], sqrtLimit) = (ParSet.empty ++ (2 to limit), math.sqrt(limit).toInt)

    @tailrec
    def prim(candidate: Int): Unit = {
      if (candidate <= sqrtLimit) {
        if (primes contains candidate) primes --= candidate * candidate to limit by candidate
        prim(candidate + 1)
      }
    }

    prim(2)
    primes
  }

  override def main(args: Array[String]): Unit = {
    val out = new PrintWriter(System.out)

    run(new Scanner(System.in), out)

    out.close()
  }

  def run(s: Scanner, out: PrintWriter): Unit = {
    val n = s.nextInt()

    val primes = sieveOfEratosthenes(n+1)

    var colors = new Array[Int](n)

    out.println(2)

    for (i <- 2 to n+1) {
      if (primes contains i) {
        out.print(s"1 ")
      } else {
        out.print(s"2 ")
      }
    }
  }
}

import Utils._, annotation._, collection._, util._, control._, math.Ordering.Implicits._, Searching._

object _776B extends CodeForcesApp {
  override def apply(io: IO) = {import io.{read, write, writeAll, writeLine}
    val n = read[Int]
    val ans = Array.ofDim[Int](n)
    val illegal = Array.fill(n)(mutable.Set.empty[Int])

    for {
      i <- 0 until n
      color <- (1 to n).find(not(illegal(i)))
      _ = ans(i) = color
      j <- i until n by (i + 2)
    } illegal(j) += color

    write(ans.toSet.size)
      .writeLine()
      .writeAll(ans)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)
    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
    def mapValuesSafely[V2](f: V => V2): Map[K, V2] = m.mapValues(f).view.force //Hack to get around https://issues.scala-lang.org/browse/SI-4776
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "YES" else "NO"
  }
  implicit class IntExtensions(val x: Int) extends AnyVal {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }
  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]
  def memoize[A, B](f: A => B): A ==> B = map[A] using f
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {
    val (xs, ys) = points.unzip
    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)
  }
  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {
    val shape = new java.awt.geom.GeneralPath()
    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}
    points.tail foreach {case (x, y) => shape.lineTo(x, y)}
    shape.closePath()
    shape
  }
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

class IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
  val printer = new PrintWriter(out, true)

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(read).to[C]

  def readTill(delim: String): String = tokenizer().get.nextToken(delim)
  def readTillEndOfLine(): String = readTill("\n\r")

  def readAll[A: IO.Read]: (Int, Vector[A]) = {
    val data = read[Vector[A]]
    (data.length, data)
  }

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  def write(obj: Any): this.type = {
    printer.print(obj)
    this
  }
  def writeLine(): this.type = {
    printer.println()
    this
  }
  def writeLine(obj: Any): this.type = {
    printer.println(obj)
    this
  }
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                      : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}


import scala.collection._

object D extends App {

  def readString = Console.readLine
  def readInts = readString.split(" ").map(_.toInt)

  val dim = 3001

  val n = readString.toInt

  val a = Array.fill(dim, dim)(0)
  val area = Array.ofDim[Int](dim, dim)
  val tl = Array.fill(dim)(new mutable.BitSet(dim))
  val tr = Array.fill(dim)(new mutable.BitSet(dim))
  val blx = Array.fill(dim)(new mutable.BitSet(dim))
  val br = Array.fill(dim)(new mutable.BitSet(dim))
  val te = Array.fill(dim)(new mutable.BitSet(dim))
  val be = Array.fill(dim)(new mutable.BitSet(dim))
  val lex = Array.fill(dim)(new mutable.BitSet(dim))
  val rex = Array.fill(dim)(new mutable.BitSet(dim))

  for (i <- 0 until dim) {
    area(0)(i) = 0
    area(i)(0) = 0
  }

  var i = 1
  while (i <= n) {
    val Array(x1, y1, x2, y2) = readInts
    tl(y1)(x1) = true
    tr(y1)(x2 - 1) = true
    blx(x1)(y2 - 1) = true
    br(y2 - 1)(x2 - 1) = true
    var x = x1
    while (x < x2) {
      te(y1)(x) = true
      be(y2 - 1)(x) = true
      x += 1
    }
    var y = y1
    while (y < y2) {
      lex(x1)(y) = true
      rex(x2 - 1)(y) = true
      y += 1
    }
    y = y1
    while (y < y2) {
      var x = x1
      while (x < x2) {
        a(y)(x) = i
        x += 1
      }
      y += 1
    }
    i += 1
  }

  y = 1
  while (y < dim) {
    var x = 1
    var horSum = 0
    while (x < dim) {
      if (a(y)(x) > 0) horSum += 1
      area(y)(x) = area(y - 1)(x) + horSum
      x += 1
    }
    y += 1
  }

  def full(x1: Int, y1: Int, x2: Int, y2: Int): Boolean = {
    x2 < x1 || y2 < y1 ||
    area(y2)(x2) - area(y1 - 1)(x2) - area(y2)(x1 - 1) + area(y1 - 1)(x1 - 1) == (x2 - x1 + 1) * (y2 - y1 + 1)
  }

  def rectIds(x1: Int, y1: Int, x2: Int, y2: Int) = {
    val ids = mutable.Set[Int]()
    var y = y1
    while (y <= y2) {
      var x = x1
      while (x <= x2) {
        ids += a(y)(x)
        x += 1
      }
      y += 1
    }
    ids
  }

  var y = 0
  while (y < dim) {
    var x = 0
    while (x < dim) {
      if (tl(y)(x)) {
        var nextX = 0
        var size = 0
        while (x + size < dim && y + size < dim && te(y)(x + size) && lex(x)(y + size)) {
          if (tr(y)(x + size) && blx(x)(y + size) && br(y + size)(x + size)) {
            var d = 1
            while (d < size && rex(x + size)(y + d) && be(y + size)(x + d)) d += 1
            if (d >= size) {
              if (full(x + 1, y + 1, x + size - 1, y + size - 1)) {
                val ids = rectIds(x, y, x + size, y + size)
                println("YES " + ids.size)
                println(ids.mkString(" "))
                exit
              } else size = dim - x - 2
            }
          }
          size += 1
          if (tl(y)(x + size) && nextX == 0) nextX = x + size
        }
        x = if (nextX > 0) nextX else x + size
      } else x += 1
    }
    y += 1
  }

  println("NO")
}

import scala.collection._

object D extends App {

  def readString = Console.readLine
  def readInts = readString.split(" ").map(_.toInt)

  val dim = 3001

  val n = readString.toInt

  val a = Array.fill(dim, dim)(0)
  val area = Array.ofDim[Int](dim, dim)
  val tl = Array.fill(dim)(new mutable.BitSet(dim))
  val tr = Array.fill(dim)(new mutable.BitSet(dim))
  val blx = Array.fill(dim)(new mutable.BitSet(dim))
  val br = Array.fill(dim)(new mutable.BitSet(dim))
  val te = Array.fill(dim)(new mutable.BitSet(dim))
  val be = Array.fill(dim)(new mutable.BitSet(dim))
  val lex = Array.fill(dim)(new mutable.BitSet(dim))
  val rex = Array.fill(dim)(new mutable.BitSet(dim))

  for (i <- 0 until dim) {
    area(0)(i) = 0
    area(i)(0) = 0
  }

  var i = 1
  while (i <= n) {
    val Array(x1, y1, x2, y2) = readInts
    tl(y1)(x1) = true
    tr(y1)(x2 - 1) = true
    blx(x1)(y2 - 1) = true
    br(y2 - 1)(x2 - 1) = true
    var x = x1
    while (x < x2) {
      te(y1)(x) = true
      be(y2 - 1)(x) = true
      x += 1
    }
    var y = y1
    while (y < y2) {
      lex(x1)(y) = true
      rex(x2 - 1)(y) = true
      y += 1
    }
    y = y1
    while (y < y2) {
      var x = x1
      val a2 = a(y)
      while (x < x2) {
        a2(x) = i
        x += 1
      }
      y += 1
    }
    i += 1
  }

  y = 1
  while (y < dim) {
    var x = 1
    val a2 = a(y)
    var horSum = 0
    while (x < dim) {
      if (a2(x) > 0) horSum += 1
      area(y)(x) = area(y - 1)(x) + horSum
      x += 1
    }
    y += 1
  }

  def holes(x1: Int, y1: Int, x2: Int, y2: Int): Boolean = {
    x2 >= x1 && y2 >= y1 &&
    area(y2)(x2) - area(y1 - 1)(x2) - area(y2)(x1 - 1) + area(y1 - 1)(x1 - 1) != (x2 - x1 + 1) * (y2 - y1 + 1)
//    var y = y1
//    while (y <= y2) {
//      var x = x1
//      val a2 = a(y)
//      while (x <= x2) {
//        if (a2(x) == 0) return true
//        x += 1
//      }
//      y += 1
//    }
//    false
  }

  def rectIds(x1: Int, y1: Int, x2: Int, y2: Int) = {
    val ids = mutable.Set[Int]()
    var y = y1
    while (y <= y2) {
      var x = x1
      val a2 = a(y)
      while (x <= x2) {
        ids += a2(x)
        x += 1
      }
      y += 1
    }
    ids
  }

  var y = 0
  while (y < dim) {
    var x = 0
    val te2 = te(y)
    val tr2 = tr(y)
    val tl2 = tl(y)
    while (x < dim) {
      if (tl2(x)) {
        var nextX = 0
        var size = 0
        val blx2 = blx(x)
        val lex2 = lex(x)
        while (x + size < dim && y + size < dim && te2(x + size) && lex2(y + size)) {
          if (tr2(x + size) && blx2(y + size) && br(y + size)(x + size)) {
            var d = 1
            val rex2 = rex(x + size)
            val be2 = be(y + size)
            while (d < size && rex2(y + d) && be2(x + d)) d += 1
            if (d >= size) {
              if (!holes(x + 1, y + 1, x + size - 1, y + size - 1)) {
                val ids = rectIds(x, y, x + size, y + size)
                println("YES " + ids.size)
                println(ids.mkString(" "))
                exit
              } else size = dim - x - 2
            }
          }
          size += 1
          if (tl2(x + size) && nextX == 0) nextX = x + size
        }
        x = if (nextX > 0) nextX else x + size
      } else x += 1
    }
    y += 1
  }

  println("NO")
}

import scala.collection._

object D extends App {

  def readString = Console.readLine
  def readInts = readString.split(" ").map(_.toInt)

  val dim = 3001

  val n = readString.toInt

  val a = Array.fill(dim, dim)(0)
  val area = Array.ofDim[Int](dim, dim)
  val tl = Array.fill(dim)(new mutable.BitSet(dim))
  val tr = Array.fill(dim)(new mutable.BitSet(dim))
  val blx = Array.fill(dim)(new mutable.BitSet(dim))
  val br = Array.fill(dim)(new mutable.BitSet(dim))
  val te = Array.fill(dim)(new mutable.BitSet(dim))
  val be = Array.fill(dim)(new mutable.BitSet(dim))
  val lex = Array.fill(dim)(new mutable.BitSet(dim))
  val rex = Array.fill(dim)(new mutable.BitSet(dim))

  for (i <- 0 until dim) {
    area(0)(i) = 0
    area(i)(0) = 0
  }

  var i = 1
  while (i <= n) {
    val Array(x1, y1, x2, y2) = readInts
    tl(y1)(x1) = true
    tr(y1)(x2 - 1) = true
    blx(x1)(y2 - 1) = true
    br(y2 - 1)(x2 - 1) = true
    var x = x1
    while (x < x2) {
      te(y1)(x) = true
      be(y2 - 1)(x) = true
      x += 1
    }
    var y = y1
    while (y < y2) {
      lex(x1)(y) = true
      rex(x2 - 1)(y) = true
      y += 1
    }
    y = y1
    while (y < y2) {
      var x = x1
      val a2 = a(y)
      while (x < x2) {
        a2(x) = i
        x += 1
      }
      y += 1
    }
    i += 1
  }

  y = 1
  while (y < dim) {
    var x = 1
    val a2 = a(y)
    var horSum = 0
    while (x < dim) {
      if (a2(x) > 0) horSum += 1
      area(y)(x) = area(y - 1)(x) + horSum
      x += 1
    }
    y += 1
  }

  def full(x1: Int, y1: Int, x2: Int, y2: Int): Boolean = {
    x2 < x1 || y2 < y1 ||
    area(y2)(x2) - area(y1 - 1)(x2) - area(y2)(x1 - 1) + area(y1 - 1)(x1 - 1) == (x2 - x1 + 1) * (y2 - y1 + 1)
  }

  def rectIds(x1: Int, y1: Int, x2: Int, y2: Int) = {
    val ids = mutable.Set[Int]()
    var y = y1
    while (y <= y2) {
      var x = x1
      val a2 = a(y)
      while (x <= x2) {
        ids += a2(x)
        x += 1
      }
      y += 1
    }
    ids
  }

  var y = 0
  while (y < dim) {
    var x = 0
    val te2 = te(y)
    val tr2 = tr(y)
    val tl2 = tl(y)
    while (x < dim) {
      if (tl2(x)) {
        var nextX = 0
        var size = 0
        val blx2 = blx(x)
        val lex2 = lex(x)
        while (x + size < dim && y + size < dim && te2(x + size) && lex2(y + size)) {
          if (tr2(x + size) && blx2(y + size) && br(y + size)(x + size)) {
            var d = 1
            val rex2 = rex(x + size)
            val be2 = be(y + size)
            while (d < size && rex2(y + d) && be2(x + d)) d += 1
            if (d >= size) {
              if (full(x + 1, y + 1, x + size - 1, y + size - 1)) {
                val ids = rectIds(x, y, x + size, y + size)
                println("YES " + ids.size)
                println(ids.mkString(" "))
                exit
              } else size = dim - x - 2
            }
          }
          size += 1
          if (tl2(x + size) && nextX == 0) nextX = x + size
        }
        x = if (nextX > 0) nextX else x + size
      } else x += 1
    }
    y += 1
  }

  println("NO")
}

import scala.collection._

object D extends App {

  def readString = Console.readLine
  def readInts = readString.split(" ").map(_.toInt)

  val dim = 3001

  val n = readString.toInt

  val a = Array.fill(dim, dim)(0)
  val area = Array.ofDim[Int](dim, dim)
  val tl = Array.fill(dim)(new mutable.BitSet(dim))
  val tr = Array.fill(dim)(new mutable.BitSet(dim))
  val blx = Array.fill(dim)(new mutable.BitSet(dim))
  val br = Array.fill(dim)(new mutable.BitSet(dim))
  val te = Array.fill(dim)(new mutable.BitSet(dim))
  val be = Array.fill(dim)(new mutable.BitSet(dim))
  val lex = Array.fill(dim)(new mutable.BitSet(dim))
  val rex = Array.fill(dim)(new mutable.BitSet(dim))

  for (i <- 0 until dim) {
    area(0)(i) = 0
    area(i)(0) = 0
  }

  var i = 1
  while (i <= n) {
    val Array(x1, y1, x2, y2) = readInts
    tl(y1)(x1) = true
    tr(y1)(x2 - 1) = true
    blx(y2 - 1)(x1) = true
    br(y2 - 1)(x2 - 1) = true
    var x = x1
    while (x < x2) {
      te(y1)(x) = true
      be(y2 - 1)(x) = true
      x += 1
    }
    var y = y1
    while (y < y2) {
      lex(y)(x1) = true
      rex(y)(x2 - 1) = true
      y += 1
    }
    y = y1
    while (y < y2) {
      var x = x1
      while (x < x2) {
        a(y)(x) = i
        x += 1
      }
      y += 1
    }
    i += 1
  }

  y = 1
  while (y < dim) {
    var x = 1
    var horSum = 0
    while (x < dim) {
      if (a(y)(x) > 0) horSum += 1
      area(y)(x) = area(y - 1)(x) + horSum
      x += 1
    }
    y += 1
  }

  def full(x1: Int, y1: Int, x2: Int, y2: Int): Boolean = {
    x2 < x1 || y2 < y1 ||
    area(y2)(x2) - area(y1 - 1)(x2) - area(y2)(x1 - 1) + area(y1 - 1)(x1 - 1) == (x2 - x1 + 1) * (y2 - y1 + 1)
  }

  def rectIds(x1: Int, y1: Int, x2: Int, y2: Int) = {
    val ids = mutable.Set[Int]()
    var y = y1
    while (y <= y2) {
      var x = x1
      while (x <= x2) {
        ids += a(y)(x)
        x += 1
      }
      y += 1
    }
    ids
  }

  var y = 0
  while (y < dim) {
    var x = 0
    while (x < dim) {
      if (tl(y)(x)) {
        var nextX = 0
        var size = 0
        while (x + size < dim && y + size < dim && te(y)(x + size) && lex(y + size)(x)) {
          if (tr(y)(x + size) && blx(y + size)(x) && br(y + size)(x + size)) {
            var d = 1
            while (d < size && rex(y + d)(x + size) && be(y + size)(x + d)) d += 1
            if (d >= size) {
              if (full(x + 1, y + 1, x + size - 1, y + size - 1)) {
                val ids = rectIds(x, y, x + size, y + size)
                println("YES " + ids.size)
                println(ids.mkString(" "))
                exit
              } else size = dim - x - 2
            }
          }
          size += 1
          if (tl(y)(x + size) && nextX == 0) nextX = x + size
        }
        x = if (nextX > 0) nextX else x + size
      } else x += 1
    }
    y += 1
  }

  println("NO")
}

object D extends App {

  def readString = Console.readLine
  def readInts = readString.split(" ").map(_.toInt)

  val dim = 3001

  val n = readString.toInt

  val a = Array.fill(dim, dim)(0)
  val tl = Array.fill(dim, dim)(false)
  val tr = Array.fill(dim, dim)(false)
  val bl = Array.fill(dim, dim)(false)
  val br = Array.fill(dim, dim)(false)
  val he = Array.fill(dim, dim)(false)
  val ve = Array.fill(dim, dim)(false)

  var i = 1
  while (i <= n) {
    val Array(x1, y1, x2, y2) = readInts
    tl(y1)(x1) = true
    tr(y1)(x2 - 1) = true
    bl(y2 - 1)(x1) = true
    br(y2 - 1)(x2 - 1) = true
    var x = x1
    while (x < x2) {
      he(y1)(x) = true
      he(y2 - 1)(x) = true
      x += 1
    }
    var y = y1
    while (y < y2) {
      ve(y)(x1) = true
      ve(y)(x2 - 1) = true
      y += 1
    }
    y = y1
    while (y <= y2) {
      var x = x1
      while (x <= x2) {
        a(y)(x) = i
        x += 1
      }
      y += 1
    }
    i += 1
  }

  def holes(x1: Int, y1: Int, x2: Int, y2: Int): Boolean = {
    var y = y1
    while (y <= y2) {
      var x = x1
      while (x <= x2) {
        if (a(y)(x) == 0) return true
        x += 1
      }
      y += 1
    }
    false
  }

  def rectIds(x1: Int, y1: Int, x2: Int, y2: Int) = {
    val ids = scala.collection.mutable.Set[Int]()
    var y = y1
    while (y <= y2) {
      var x = x1
      while (x <= x2) {
        ids += a(y)(x)
        x += 1
      }
      y += 1
    }
    ids
  }

  var y = 0
  while (y < dim) {
    var x = 0
    while (x < dim) {
      if (tl(y)(x)) {
        var dx = 0
        while (x + dx < dim && y + dx < dim && he(y)(x + dx)) {
          if (tr(y)(x + dx) && bl(y + dx)(x) && br(y + dx)(x + dx)) {
            var dy = 1
            var goodEdges = true
            while (dy < dx && goodEdges) {
              goodEdges = ve(y + dy)(x) && ve(y + dy)(x + dx) && he(y + dx)(x + dy)
              dy += 1
            }
            if (goodEdges && !holes(x + 1, y + 1, x + dx - 1, y + dx - 1)) {
              val ids = rectIds(x, y, x + dx, y + dx)
              println("YES " + ids.size)
              println(ids.mkString(" "))
              exit
            }
          }
          dx += 1
        }
      }
      x += 1
    }
    y += 1
  }

  println("NO")
}

import scala.collection._

object D extends App {

  def readString = Console.readLine
  def readInts = readString.split(" ").map(_.toInt)

  val dim = 3001

  val n = readString.toInt

  val a = Array.fill(dim, dim)(0)
  val area = Array.ofDim[Int](dim, dim)
  val tl = Array.fill(dim)(new mutable.BitSet(dim))
  val tr = Array.fill(dim)(new mutable.BitSet(dim))
  val blx = Array.fill(dim)(new mutable.BitSet(dim))
  val br = Array.fill(dim)(new mutable.BitSet(dim))
  val te = Array.fill(dim)(new mutable.BitSet(dim))
  val be = Array.fill(dim)(new mutable.BitSet(dim))
  val lex = Array.fill(dim)(new mutable.BitSet(dim))
  val rex = Array.fill(dim)(new mutable.BitSet(dim))

  for (i <- 0 until dim) {
    area(0)(i) = 0
    area(i)(0) = 0
  }

  var i = 1
  while (i <= n) {
    val Array(x1, y1, x2, y2) = readInts
    tl(y1)(x1) = true
    tr(y1)(x2 - 1) = true
    blx(x1)(y2 - 1) = true
    br(y2 - 1)(x2 - 1) = true
    var x = x1
    while (x < x2) {
      te(y1)(x) = true
      be(y2 - 1)(x) = true
      x += 1
    }
    var y = y1
    while (y < y2) {
      lex(x1)(y) = true
      rex(x2 - 1)(y) = true
      y += 1
    }
    y = y1
    while (y < y2) {
      var x = x1
      val a2 = a(y)
      while (x < x2) {
        a2(x) = i
        x += 1
      }
      y += 1
    }
    i += 1
  }

  y = 1
  while (y < dim) {
    var x = 1
    val a2 = a(y)
    var horSum = 0
    while (x < dim) {
      if (a2(x) > 0) horSum += 1
      area(y)(x) = area(y - 1)(x) + horSum
      x += 1
    }
    y += 1
  }

  def holes(x1: Int, y1: Int, x2: Int, y2: Int): Boolean = {
    area(y2)(x2) - area(math.min(y1 - 1, 0))(x2) - area(y2)(math.min(x1 - 1, 0)) +
    	area(math.min(y1 - 1, 0))(math.min(x1 - 1, 0)) != (x2 - x1 + 1) * (y2 - y1 + 1)
//    var y = y1
//    while (y <= y2) {
//      var x = x1
//      val a2 = a(y)
//      while (x <= x2) {
//        if (a2(x) == 0) return true
//        x += 1
//      }
//      y += 1
//    }
//    false
  }

  def rectIds(x1: Int, y1: Int, x2: Int, y2: Int) = {
    val ids = mutable.Set[Int]()
    var y = y1
    while (y <= y2) {
      var x = x1
      val a2 = a(y)
      while (x <= x2) {
        ids += a2(x)
        x += 1
      }
      y += 1
    }
    ids
  }

  var y = 0
  while (y < dim) {
    var x = 0
    val te2 = te(y)
    val tr2 = tr(y)
    val tl2 = tl(y)
    while (x < dim) {
      if (tl2(x)) {
        var nextX = 0
        var size = 0
        val blx2 = blx(x)
        val lex2 = lex(x)
        while (x + size < dim && y + size < dim && te2(x + size) && lex2(y + size)) {
          if (tr2(x + size) && blx2(y + size) && br(y + size)(x + size)) {
            var d = 1
            val rex2 = rex(x + size)
            val be2 = be(y + size)
            while (d < size && rex2(y + d) && be2(x + d)) d += 1
            if (d >= size) {
              if (!holes(x + 1, y + 1, x + size - 1, y + size - 1)) {
                val ids = rectIds(x, y, x + size, y + size)
                println("YES " + ids.size)
                println(ids.mkString(" "))
                exit
              } else size = dim - x - 2
            }
          }
          size += 1
          if (tl2(x + size) && nextX == 0) nextX = x + size
        }
        x = if (nextX > 0) nextX else x + size
      } else x += 1
    }
    y += 1
  }

  println("NO")
}

import scala.collection._

object D extends App {

  def readString = Console.readLine
  def readInts = readString.split(" ").map(_.toInt)

  val dim = 3001

  val n = readString.toInt

  val a = Array.fill(dim, dim)(0)
  val area = Array.ofDim[Int](dim, dim)
  val tl = Array.fill(dim)(new mutable.BitSet(dim))
  val tr = Array.fill(dim)(new mutable.BitSet(dim))
  val blx = Array.fill(dim)(new mutable.BitSet(dim))
  val br = Array.fill(dim)(new mutable.BitSet(dim))
  val te = Array.fill(dim)(new mutable.BitSet(dim))
  val be = Array.fill(dim)(new mutable.BitSet(dim))
  val lex = Array.fill(dim)(new mutable.BitSet(dim))
  val rex = Array.fill(dim)(new mutable.BitSet(dim))

  for (i <- 0 until dim) {
    area(0)(i) = 0
    area(i)(0) = 0
  }

  var i = 1
  while (i <= n) {
    val Array(x1, y1, x2, y2) = readInts
    tl(y1)(x1) = true
    tr(y1)(x2 - 1) = true
    blx(x1)(y2 - 1) = true
    br(y2 - 1)(x2 - 1) = true
    var x = x1
    while (x < x2) {
      te(y1)(x) = true
      be(y2 - 1)(x) = true
      x += 1
    }
    var y = y1
    while (y < y2) {
      lex(x1)(y) = true
      rex(x2 - 1)(y) = true
      y += 1
    }
    y = y1
    while (y < y2) {
      var x = x1
      val a2 = a(y)
      while (x < x2) {
        a2(x) = i
        x += 1
      }
      y += 1
    }
    i += 1
  }

  y = 1
  while (y < dim) {
    var x = 1
    val a2 = a(y)
    var horSum = 0
    while (x < dim) {
      if (a2(x) > 0) horSum += 1
      area(y)(x) = area(y - 1)(x) + horSum
      x += 1
    }
    y += 1
  }

  def holes(x1: Int, y1: Int, x2: Int, y2: Int): Boolean = {
    x2 < x1 || y2 < y1 ||
    area(y2)(x2) - area(y1 - 1)(x2) - area(y2)(x1 - 1) + area(y1 - 1)(x1 - 1) != (x2 - x1 + 1) * (y2 - y1 + 1)
//    var y = y1
//    while (y <= y2) {
//      var x = x1
//      val a2 = a(y)
//      while (x <= x2) {
//        if (a2(x) == 0) return true
//        x += 1
//      }
//      y += 1
//    }
//    false
  }

  def rectIds(x1: Int, y1: Int, x2: Int, y2: Int) = {
    val ids = mutable.Set[Int]()
    var y = y1
    while (y <= y2) {
      var x = x1
      val a2 = a(y)
      while (x <= x2) {
        ids += a2(x)
        x += 1
      }
      y += 1
    }
    ids
  }

  var y = 0
  while (y < dim) {
    var x = 0
    val te2 = te(y)
    val tr2 = tr(y)
    val tl2 = tl(y)
    while (x < dim) {
      if (tl2(x)) {
        var nextX = 0
        var size = 0
        val blx2 = blx(x)
        val lex2 = lex(x)
        while (x + size < dim && y + size < dim && te2(x + size) && lex2(y + size)) {
          if (tr2(x + size) && blx2(y + size) && br(y + size)(x + size)) {
            var d = 1
            val rex2 = rex(x + size)
            val be2 = be(y + size)
            while (d < size && rex2(y + d) && be2(x + d)) d += 1
            if (d >= size) {
              if (!holes(x + 1, y + 1, x + size - 1, y + size - 1)) {
                val ids = rectIds(x, y, x + size, y + size)
                println("YES " + ids.size)
                println(ids.mkString(" "))
                exit
              } else size = dim - x - 2
            }
          }
          size += 1
          if (tl2(x + size) && nextX == 0) nextX = x + size
        }
        x = if (nextX > 0) nextX else x + size
      } else x += 1
    }
    y += 1
  }

  println("NO")
}

object D extends App {

  def readString = Console.readLine
  def readInts = readString.split(" ").map(_.toInt)

  val dim = 3001

  val n = readString.toInt

  val a = Array.fill(dim, dim)(0)
  val tl = Array.fill(dim, dim)(false)
  val tr = Array.fill(dim, dim)(false)
  val bl = Array.fill(dim, dim)(false)
  val br = Array.fill(dim, dim)(false)
  val he = Array.fill(dim, dim)(false)
  val ve = Array.fill(dim, dim)(false)

  for (i <- 1 to n) {
    val Array(x1, y1, x2, y2) = readInts
    tl(y1)(x1) = true
    tr(y1)(x2 - 1) = true
    bl(y2 - 1)(x1) = true
    br(y2 - 1)(x2 - 1) = true
    for (x <- x1 until x2) {
      he(y1)(x) = true
      he(y2 - 1)(x) = true
    }
    for (y <- y1 until y2) {
      ve(y)(x1) = true
      ve(y)(x2 - 1) = true
    }
    for (y <- y1 until y2; x <- x1 until x2) a(y)(x) = i
  }

  def holes(x1: Int, y1: Int, x2: Int, y2: Int): Boolean = {
    var y = y1
    while (y <= y2) {
      var x = x1
      while (x <= x2) {
        if (a(y)(x) == 0) return true
        x += 1
      }
      y += 1
    }
    false
  }

  def rectIds(x1: Int, y1: Int, x2: Int, y2: Int) = {
    val ids = scala.collection.mutable.Set[Int]()
    var y = y1
    while (y <= y2) {
      var x = x1
      while (x <= x2) {
        ids += a(y)(x)
        x += 1
      }
      y += 1
    }
    ids
  }

  for (y <- 0 until dim) {
    var x = 0
    while (x < dim) {
      if (tl(y)(x)) {
        var dx = 0
        while (x + dx < dim && y + dx < dim && he(y)(x + dx)) {
          if (tr(y)(x + dx) && bl(y + dx)(x) && br(y + dx)(x + dx)) {
            var dy = 1
            var goodEdges = true
            while (dy < dx && goodEdges) {
              goodEdges = ve(y + dy)(x) && ve(y + dy)(x + dx) && he(y + dx)(x + dy)
              dy += 1
            }
            if (goodEdges && !holes(x + 1, y + 1, x + dx - 1, y + dx - 1)) {
              val ids = rectIds(x, y, x + dx, y + dx)
              println(ids.size)
              println(ids.mkString(" "))
              exit
            }
          }
          dx += 1
        }
      }
      x += 1
    }
  }

  println("NO")
}


import scala.io.StdIn.readLine

object task extends App {
  val t: Int = readLine.toInt
  for (i <- 1 to t) {
    val ln1 = readLine.split(" ").map(_.toInt)
    val b: Int = ln1(0)
    val r: Int = ln1(1)
    val barrels = readLine.split(" ").map(_.toLong).sorted
    val sum: Long = barrels.takeRight(r + 1).sum
    println(sum)
  }
}

object B extends App {
  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val Array(n, k) = readLine().split(" ").map(_.toInt)
    val an          = readLine().split(" ").map(_.toInt).sorted(Ordering.Int.reverse)

    val ans = an.take(k + 1).foldLeft(0L)(_ + _)

    println(ans)
  }
}

object B {
  import InOut._
  def main(args: Array[String]): Unit = {

    for (_ <- 1 to nextInt) {
      val n, k = nextInt
      val as = nextLongs(n).sorted.reverse
      val res = as.take(k + 1).sum

      out.println(res)

      out.flush()
    }
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}

import scala.io.StdIn.readLine

object task extends App {
  val t: Int = readLine.toInt
  for (i <- 1 to t) {
    val ln1 = readLine.split(" ").map(_.toInt)
    val b: Int = ln1(0)
    val r: Int = ln1(1)
    val barrels = readLine.split(" ").map(_.toInt).sorted
    val sum: Int = barrels.takeRight(r + 1).sum
    println(sum)
  }
}

import scala.io.StdIn.readLine

object task extends App {
  val t: Int = readLine.toInt
  for (i <- 1 to t) {
    val ln1 = readLine.split(" ").map(_.toInt)
    val b: Int = ln1(0)
    val r: Int = ln1(1)
    val barrels = readLine.split(" ").map(_.toInt).sorted
    val sum: Int = barrels.take(r + 1).sum
    println(sum)
  }
}