object Main extends App {
  val src = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt).toList)

  def myFilter(li: List[Int], as: List[Int], bs: List[Int]): String = li match {
    case Nil => "YES"
    case h :: tail => if (as.head >= bs.head && as.head < h) myFilter(tail, h :: as, bs)
                      else if (as.head >= bs.head && as.head > h && bs.head < h) myFilter(tail, as, h :: bs)
                      else "NO"
  }

  for (li <- src if li.length != 1) println(s"${myFilter(li, List(0), List(0))}")

}