object Solution { def isContains(x: List[Int], y: Map[Int, Int]): Boolean = { for (el <- x) { if(y.getOrElse(el, 0) <= 1) return false } true } def main(args: Array[String]) { import scala.io.StdIn._ var n = readInt() val buf = Array[(Int, Int)]().toBuffer for (_ <- 0 until n) { val l = readLine().split(" ").map(_.toInt) buf += Tuple2(l(0), l(1)) } val keysX = buf.groupBy(x => x._1).mapValues(_.map(_._2)).toList.filter(x=> x._2.size <= 1).map(_._2).flatten val keysY = buf.groupBy(x => x._2).mapValues(_.size) if (isContains(keysX, keysY)) println("YES") else println("NO") } }