import java.util.Scanner import scala.collection.immutable.Range.Inclusive object Problem274 { def proc(row: Int, col: Int, fromTo: Seq[(Int, Int)]): String = { val ranges: Seq[Inclusive] = fromTo flatMap { case (from, to) => val oppositeFrom = col - 1 - to val oppositeTo = col - 1 - from Seq((from to to), (oppositeFrom to oppositeTo)) } val isGoodWall = (0 until col / 2) forall { i => val cnt = ranges count { range => range.contains(i) } cnt <= 2 } if (isGoodWall) "YES" else "NO" } def main(args: Array[String]) { val sc = new Scanner(System.in) val n = sc.nextInt() val m = sc.nextInt() val fromTo = Seq.fill(n)(sc.nextInt(), sc.nextInt()) val result = proc(n, m, fromTo) println(result) } }