object B extends App {
  def fight(h1: Int, a1: Int, c1: Int, h2: Int, a2: Int, s: List[String] = List.empty): List[String] =
    if (h2 <= 0) s.reverse
    else if (h1 <= a2 && h2 > a1) fight(h1 + c1 - a2, a1, c1, h2, a2, "HEAL" :: s)
    else fight(h1 - a2, a1, c1, h2 - a1, a2, "STRIKE" :: s)

  val Array(h1, a1, c1) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val Array(h2, a2) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val strategy = fight(h1, a1, c1, h2, a2)
  println(strategy.length)
  strategy.foreach(println)
}

import java.io.FileReader
import java.util.Comparator

import collection.Searching._
import scala.collection.mutable

object Solution {
  //Console.setIn(new FileReader(new java.io.File("input")))
  //Console.setOut(new PrintStream(new java.io.File("output")))
  var caseNo = 1
  val magicMod = 1000000007

  def doCase() : Unit = {
    var Array(h1, a1, c1) = readIntLine()
    var Array(h2, a2) = readIntLine()

    var count = 0
    var history : List[String] = List()
    var notDone = true
    while (notDone) {
      count += 1
      if (h2 <= a1) {
        history ::= "STRIKE"
        notDone = false
      } else if (h1 <= a2) {
        h1 += c1
        h1 -= a2
        history ::= "HEAL"
      } else {
        h2 -= a1
        h1 -= a2
        history ::= "STRIKE"
      }
    }
    println(count)
    for (cmd <- history.reverse) {
      println(cmd)
    }
  }

  def main(args: Array[String]): Unit = {
    val noCases = 1
    for (i <- 0 until noCases) {
      doCase()
    }
  }

  def readIntLine(): Array[Int] = {
    readLine().split(" ").map(_.toInt)
  }

  def readLongLine(): Array[Long] = {
    readLine().split(" ").map(_.toLong)
  }

  def readBigIntLine(): Array[BigInt] = {
    readLine().split(" ").map(BigInt.apply)
  }
}

object B extends App {
  def fight(h1: Int, a1: Int, c1: Int, h2: Int, a2: Int, s: List[String] = List.empty): List[String] =
    if (h2 <= 0) s.reverse
    else if (h1 <= a2) fight(h1 + c1 - a2, a1, c1, h2, a2, "HEAL" :: s)
    else fight(h1 - a2, a1, c1, h2 - a1, a2, "STRIKE" :: s)

  val Array(h1, a1, c1) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val Array(h2, a2) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val strategy = fight(h1, a1, c1, h2, a2)
  println(strategy.length)
  strategy.foreach(println)
}

object B extends App {
  def fight(h1: Int, a1: Int, c1: Int, h2: Int, a2: Int, s: List[String] = List.empty): List[String] =
    if (h2 <= 0) s.reverse
    else if (h1 - a2 <= 0) fight(h1 + c1 - a2, a1, c1, h2, a2, "HEAL" :: s)
    else fight(h1 - a2, a1, c1, h2 - a1, a2, "STRIKE" :: s)

  val Array(h1, a1, c1) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val Array(h2, a2) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val strategy = fight(h1, a1, c1, h2, a2)
  println(strategy.length)
  strategy.foreach(println)
}


import sun.management.counter.Counter

import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.io.PrintWriter
import java.util.StringTokenizer
import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.util.Random

object Solution extends App {

  //=====Solution=========

  val reader = new BufferedReader(new InputStreamReader(System.in))
  val writer = new BufferedWriter(new OutputStreamWriter(System.out))

  val testNumber = reader.readLine().toInt
  1.to(testNumber).foreach { _ =>
    val size = reader.readLine().toInt
    val a = new Array[Int](size);
    {
      val tokenizer = new StringTokenizer(reader.readLine(), " ")
      var i = 0
      while (i < size) {
        a(i) = Integer.parseInt(tokenizer.nextToken())
        i += 1
      }
    }

    @tailrec
    def findAnswer(index: Int, previousEven: Int, previousOdd: Int): Boolean =
      if (index == size) true else {
        a(index) % 2 match {
          case 0 => if (previousEven == -1 || previousEven <= a(index))
            findAnswer(index + 1, a(index), previousOdd) else false
          case 1 => if (previousOdd == -1 || previousOdd <= a(index))
            findAnswer(index + 1, previousEven, a(index)) else false
        }
      }

    val answer = if (findAnswer(0, -1, -1)) "YES" else "NO"
    writer.append(answer)
    writer.append("\n")
  }
  writer.close()

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def isEmpty() = multiSet.isEmpty
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import sun.management.counter.Counter

import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.io.PrintWriter
import java.util.StringTokenizer
import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.util.Random

object Solution extends App {

  //=====Solution=========

  val reader = new BufferedReader(new InputStreamReader(System.in))
  val writer = new BufferedWriter(new OutputStreamWriter(System.out))

  val testNumber = reader.readLine().toInt
  1.to(testNumber).foreach { _ =>
    val size = reader.readLine().toInt
    val a = new Array[Int](size);
    {
      val tokenizer = new StringTokenizer(reader.readLine(), " ")
      var i = 0
      while (i < size) {
        a(i) = Integer.parseInt(tokenizer.nextToken())
        i += 1
      }
    }

    @tailrec
    def findAnswer(index: Int, previousEven: Int, previousOdd: Int): Boolean =
      if (index == size) true else {
        a(index) % 2 match {
          case 0 => if (previousEven == -1 || previousEven <= a(index))
            findAnswer(index + 1, a(index), previousOdd) else false
          case 1 => if (previousOdd == -1 || previousOdd <= a(index))
            findAnswer(index + 1, previousEven, a(index)) else false
        }
      }

    val answer = if (findAnswer(0, -1, -1)) "YES" else "NO"
    writer.append(StringBuilder.newBuilder.append(answer).append("\n"))
  }
  writer.close()

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def isEmpty() = multiSet.isEmpty
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import sun.management.counter.Counter

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.StringTokenizer
import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.util.Random

object Solution extends App {

  //=====Solution=========

  import java.nio.channels.Channels

  val reader = new BufferedReader(new InputStreamReader(System.in))
  val writer = new PrintWriter(System.out)

  val testNumber = reader.readLine().toInt
  1.to(testNumber).foreach { _ =>
    val size = reader.readLine().toInt
    val a = new Array[Int](size);
    {
      val tokenizer = new StringTokenizer(reader.readLine(), " ")
      var i = 0
      while (i < size) {
        a(i) = Integer.parseInt(tokenizer.nextToken())
        i += 1
      }
    }

    @tailrec
    def findAnswer(index: Int, previousEven: Int, previousOdd: Int): Boolean =
      if (index == size) true else {
        a(index) % 2 match {
          case 0 => if (previousEven == -1 || previousEven <= a(index))
            findAnswer(index + 1, a(index), previousOdd) else false
          case 1 => if (previousOdd == -1 || previousOdd <= a(index))
            findAnswer(index + 1, previousEven, a(index)) else false
        }
      }

    val answer = if (findAnswer(0, -1, -1)) "YES" else "NO"
    writer.println(answer)
  }
  writer.close()

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def isEmpty() = multiSet.isEmpty
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import sun.management.counter.Counter

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.StringTokenizer
import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.util.Random

object Solution extends App {

  //=====Solution=========

  import java.nio.channels.Channels

  val buffer = java.nio.ByteBuffer.allocate(4096000)
  val channel = Channels.newChannel(System.in)
  channel.read(buffer)
  val inputTokenizer = new StringTokenizer(new String(buffer.array),"\r\n\0")

  val writer = new PrintWriter(System.out)

  val testNumber = inputTokenizer.nextToken().toInt
  1.to(testNumber).foreach { _ =>
    val size = inputTokenizer.nextToken().toInt
    val a = new Array[Int](size);
    {
      val tokenizer = new StringTokenizer(inputTokenizer.nextToken(), " ")
      var i = 0
      while (i < size) {
        a(i) = Integer.parseInt(tokenizer.nextToken())
        i += 1
      }
    }

    @tailrec
    def findAnswer(index: Int, previousEven: Int, previousOdd: Int): Boolean =
      if (index == size) true else {
        a(index) % 2 match {
          case 0 => if (previousEven == -1 || previousEven <= a(index))
            findAnswer(index + 1, a(index), previousOdd) else false
          case 1 => if (previousOdd == -1 || previousOdd <= a(index))
            findAnswer(index + 1, previousEven, a(index)) else false
        }
      }

    val answer = if (findAnswer(0, -1, -1)) "YES" else "NO"
    writer.println(answer)
  }
  channel.close()
  writer.close()

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def isEmpty() = multiSet.isEmpty
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import sun.management.counter.Counter

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.StringTokenizer
import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.util.Random

object Solution extends App {

  //=====Solution=========

  import java.nio.channels.Channels

  val buffer = java.nio.ByteBuffer.allocate(10240000)
  val channel = Channels.newChannel(System.in)
  channel.read(buffer)
  val inputTokenizer = new StringTokenizer(new String(buffer.array),"\r\n\0")

  val writer = new PrintWriter(System.out)

  val testNumber = inputTokenizer.nextToken().toInt
  1.to(testNumber).foreach { _ =>
    val size = inputTokenizer.nextToken().toInt
    val a = new Array[Int](size);
    {
      val tokenizer = new StringTokenizer(inputTokenizer.nextToken(), " ")
      var i = 0
      while (i < size) {
        a(i) = Integer.parseInt(tokenizer.nextToken())
        i += 1
      }
    }

    @tailrec
    def findAnswer(index: Int, previousEven: Int, previousOdd: Int): Boolean =
      if (index == size) true else {
        a(index) % 2 match {
          case 0 => if (previousEven == -1 || previousEven <= a(index))
            findAnswer(index + 1, a(index), previousOdd) else false
          case 1 => if (previousOdd == -1 || previousOdd <= a(index))
            findAnswer(index + 1, previousEven, a(index)) else false
        }
      }

    val answer = if (findAnswer(0, -1, -1)) "YES" else "NO"
    writer.println(answer)
  }
  channel.close()
  writer.close()

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def isEmpty() = multiSet.isEmpty
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import sun.management.counter.Counter

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.StringTokenizer
import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.util.Random

object Solution extends App {

  //=====Solution=========

  import java.nio.channels.Channels

  val buffer = java.nio.ByteBuffer.allocate(20480000)
  val channel = Channels.newChannel(System.in)
  channel.read(buffer)
  val inputTokenizer = new StringTokenizer(new String(buffer.array),"\r\n\0")

  val writer = new PrintWriter(System.out)

  val testNumber = inputTokenizer.nextToken().toInt
  1.to(testNumber).foreach { _ =>
    val size = inputTokenizer.nextToken().toInt
    val a = new Array[Int](size);
    {
      val tokenizer = new StringTokenizer(inputTokenizer.nextToken(), " ")
      var i = 0
      while (i < size) {
        a(i) = Integer.parseInt(tokenizer.nextToken())
        i += 1
      }
    }

    @tailrec
    def findAnswer(index: Int, previousEven: Int, previousOdd: Int): Boolean =
      if (index == size) true else {
        a(index) % 2 match {
          case 0 => if (previousEven == -1 || previousEven <= a(index))
            findAnswer(index + 1, a(index), previousOdd) else false
          case 1 => if (previousOdd == -1 || previousOdd <= a(index))
            findAnswer(index + 1, previousEven, a(index)) else false
        }
      }

    val answer = if (findAnswer(0, -1, -1)) "YES" else "NO"
    writer.println(answer)
  }
  channel.close()
  writer.close()

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def isEmpty() = multiSet.isEmpty
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import sun.management.counter.Counter

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.StringTokenizer
import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.util.Random

object Solution extends App {

  //=====Solution=========

  import java.nio.channels.Channels

  val buffer = java.nio.ByteBuffer.allocate(40960000)
  val channel = Channels.newChannel(System.in)
  channel.read(buffer)
  val inputTokenizer = new StringTokenizer(new String(buffer.array),"\r\n\0")

  val writer = new PrintWriter(System.out)

  val testNumber = inputTokenizer.nextToken().toInt
  1.to(testNumber).foreach { _ =>
    val size = inputTokenizer.nextToken().toInt
    val a = new Array[Int](size);
    {
      val tokenizer = new StringTokenizer(inputTokenizer.nextToken(), " ")
      var i = 0
      while (i < size) {
        a(i) = Integer.parseInt(tokenizer.nextToken())
        i += 1
      }
    }

    @tailrec
    def findAnswer(index: Int, previousEven: Int, previousOdd: Int): Boolean =
      if (index == size) true else {
        a(index) % 2 match {
          case 0 => if (previousEven == -1 || previousEven <= a(index))
            findAnswer(index + 1, a(index), previousOdd) else false
          case 1 => if (previousOdd == -1 || previousOdd <= a(index))
            findAnswer(index + 1, previousEven, a(index)) else false
        }
      }

    val answer = if (findAnswer(0, -1, -1)) "YES" else "NO"
    writer.println(answer)
  }
  channel.close()
  writer.close()

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def isEmpty() = multiSet.isEmpty
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import sun.management.counter.Counter

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.StringTokenizer
import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.util.Random

object Solution extends App {

  //=====Solution=========
  val reader = new BufferedReader(new InputStreamReader(System.in))
  val writer = new PrintWriter(System.out)

  val testNumber = reader.readLine().toInt
  1.to(testNumber).foreach { _ =>
    val size = reader.readLine().toInt
    val a = new Array[Int](size);
    {
      val tokenizer = new StringTokenizer(reader.readLine(), " ")
      var i = 0
      while (i < size) {
        a(i) = Integer.parseInt(tokenizer.nextToken())
        i += 1
      }
    }

    @tailrec
    def findAnswer(index: Int, previousEven: Int, previousOdd: Int): Boolean =
      if (index == size) true else {
        a(index) % 2 match {
          case 0 => if (previousEven == -1 || previousEven <= a(index))
            findAnswer(index + 1, a(index), previousOdd) else false
          case 1 => if (previousOdd == -1 || previousOdd <= a(index))
            findAnswer(index + 1, previousEven, a(index)) else false
        }
      }

    val answer = if (findAnswer(0, -1, -1)) "YES" else "NO"
    writer.println(answer)
  }
  writer.close()

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def isEmpty() = multiSet.isEmpty
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import sun.management.counter.Counter

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.StringTokenizer
import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.util.Random

object Solution extends App {

  //=====Solution=========
  val reader = new BufferedReader(new InputStreamReader(System.in))
  val writer = new PrintWriter(System.out)

  val testNumber = reader.readLine().toInt
  1.to(testNumber).foreach { _ =>
    val size = reader.readLine().toInt
    val a = new Array[Int](size);
    {
      val tokenizer = new StringTokenizer(reader.readLine(), " ")
      var i = 0
      while (i < size) {
        a(i) = Integer.parseInt(tokenizer.nextToken())
        i += 1
      }
    }

    @tailrec
    def findAnswer(index: Int, previousEven: Option[Int], previousOdd: Option[Int]): Boolean =
      if (index == size) true else {
        a(index) % 2 match {
          case 0 => if (previousEven.isEmpty || previousEven.get <= a(index))
            findAnswer(index + 1, Some(a(index)), previousOdd) else false
          case 1 => if (previousOdd.isEmpty || previousOdd.get <= a(index))
            findAnswer(index + 1, previousEven, Some(a(index))) else false
        }
      }

    val answer = if (findAnswer(0, None, None)) "YES" else "NO"
    writer.println(answer)
  }
  writer.close()

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def isEmpty() = multiSet.isEmpty
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import sun.management.counter.Counter

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.StringTokenizer
import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.util.Random

object Solution extends App {

  //=====Solution=========
  val writer = new PrintWriter(System.out)

  val testNumber = readInt()
  1.to(testNumber).foreach { _ =>
    val size = readInt()
    val a = readInts()

    @tailrec
    def findAnswer(index: Int, previousEven: Option[Int], previousOdd: Option[Int]): Boolean =
      if (index == size) true else {
        a(index) % 2 match {
          case 0 => if (previousEven.isEmpty || previousEven.get <= a(index))
            findAnswer(index + 1, Some(a(index)), previousOdd) else false
          case 1 => if (previousOdd.isEmpty || previousOdd.get <= a(index))
            findAnswer(index + 1, previousEven, Some(a(index))) else false
        }
      }

    val answer = if (findAnswer(0, None, None)) "YES" else "NO"
    writer.println(answer)
  }
  writer.close()

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def isEmpty() = multiSet.isEmpty
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import sun.management.counter.Counter

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.StringTokenizer
import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.util.Random

object Solution extends App {

  //=====Solution=========
  val reader = new BufferedReader(new InputStreamReader(System.in))
  val writer = new PrintWriter(System.out)

  val testNumber = reader.readLine().toInt
  var testIndex = 0
  while( testIndex < testNumber) {
    testIndex += 1

    val size = reader.readLine().toInt
    val tokenizer = new StringTokenizer(reader.readLine(), " ")
    val a = new Array[Int](size);
    {
      var i = 0
      while (i < size) {
        a(i) = Integer.parseInt(tokenizer.nextToken())
        i += 1
      }
    }

    var index: Int = 0
    var previousEven: Int = -1
    var previousOdd: Int = -1
    var answer = "YES"
    while (index < size) {
      a(index) % 2 match {
        case 0 => if (previousEven == -1 || previousEven <= a(index)) {
          previousEven = a(index)
          index = index + 1
        } else {
          answer = "NO"
          index = size + 100
        }
        case 1 => if (previousOdd == -1 || previousOdd <= a(index)) {
          previousOdd = a(index)
          index = index + 1
        } else {
          answer = "NO"
          index = size + 100
        }
      }
    }

    writer.println(answer)
  }
  writer.close()

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def isEmpty() = multiSet.isEmpty
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import sun.management.counter.Counter

import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.StringTokenizer
import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.util.Random

object Solution extends App {

  //=====Solution=========
  val reader = new BufferedReader(new InputStreamReader(System.in))

  val testNumber = reader.readLine().toInt
  var testIndex = 0
  while( testIndex < testNumber) {
    testIndex += 1

    val size = reader.readLine().toInt
    val tokenizer = new StringTokenizer(reader.readLine(), " ")
    val a = new Array[Int](size);
    {
      var i = 0
      while (i < size) {
        a(i) = Integer.parseInt(tokenizer.nextToken())
        i += 1
      }
    }

    var index: Int = 0
    var previousEven: Int = -1
    var previousOdd: Int = -1
    var answer = "YES"
    while (index < size) {
      a(index) % 2 match {
        case 0 => if (previousEven == -1 || previousEven <= a(index)) {
          previousEven = a(index)
          index = index + 1
        } else {
          answer = "NO"
          index = size + 100
        }
        case 1 => if (previousOdd == -1 || previousOdd <= a(index)) {
          previousOdd = a(index)
          index = index + 1
        } else {
          answer = "NO"
          index = size + 100
        }
      }
    }

    System.out.println(answer)
  }

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def isEmpty() = multiSet.isEmpty
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import sun.management.counter.Counter

import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.StringTokenizer
import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.util.Random

object Solution extends App {

  //=====Solution=========
  val reader = new BufferedReader(new InputStreamReader(System.in))

  val testNumber = reader.readLine().toInt
  1.to(testNumber).foreach { _ =>
    val size = reader.readLine().toInt
    val tokenizer = new StringTokenizer(reader.readLine(), " ")
    val a = new Array[Int](size);
    {
      var i = 0
      while (i < size) {
        a(i) = Integer.parseInt(tokenizer.nextToken())
        i += 1
      }
    }

    var index: Int = 0
    var previousEven: Int = -1
    var previousOdd: Int = -1
    var answer = "YES"
    while (index < size) {
      a(index) % 2 match {
        case 0 => if (previousEven == -1 || previousEven <= a(index)) {
          previousEven = a(index)
          index = index + 1
        } else {
          answer = "NO"
          index = size + 100
        }
        case 1 => if (previousOdd == -1 || previousOdd <= a(index)) {
          previousOdd = a(index)
          index = index + 1
        } else {
          answer = "NO"
          index = size + 100
        }
      }
    }

    System.out.println(answer)
  }

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def isEmpty() = multiSet.isEmpty
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.ListBuffer
import scala.io.Source
import scala.util.control.Breaks

object Main extends App {
  val input = Source.fromInputStream(System.in).getLines()
  val t = input.next().toInt
  val res = new ArrayBuffer[String](t)
  for (i <- 0 until t) {
    input.next()
    val ch = new ListBuffer[Int]()
    val nch = new ListBuffer[Int]()
    input.next().split(' ').foreach(x => {
      val i = x.toInt
      if (i % 2 == 0) ch.append(i)
      else nch.append(i)
    })

    if (check(ch.toList) && check(nch.toList)) {
      res.append("YES")
    } else res.append("NO")
  }

  def check(arr: List[Int]): Boolean = {
    if (arr.isEmpty) true
    else {
      var res = true
      var max = arr.head
      Breaks.breakable {
        for (el <- arr.tail) {
          if (max > el) {
            res = false
            Breaks.break()
          } else max = el
        }
      }
      res
    }
  }

  println(res.mkString("\n"))
}

import sun.management.counter.Counter

import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.io.PrintWriter
import java.util.StringTokenizer
import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.Source
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.util.Random

object Solution extends App {

  //=====Solution=========

  val lines = Source.fromInputStream(System.in).getLines()
  val writer = new PrintWriter(System.out)

  val testNumber = lines.next().toInt
  1.to(testNumber).foreach { _ =>
    val size = lines.next().toInt
    val a = new Array[Int](size);
    {
      val tokenizer = new StringTokenizer(lines.next(), " ")
      var i = 0
      while (i < size) {
        a(i) = Integer.parseInt(tokenizer.nextToken())
        i += 1
      }
    }

    @tailrec
    def findAnswer(index: Int, previousEven: Int, previousOdd: Int): Boolean =
      if (index == size) true else {
        a(index) % 2 match {
          case 0 => if (previousEven == -1 || previousEven <= a(index))
            findAnswer(index + 1, a(index), previousOdd) else false
          case 1 => if (previousOdd == -1 || previousOdd <= a(index))
            findAnswer(index + 1, previousEven, a(index)) else false
        }
      }

    val answer = if (findAnswer(0, -1, -1)) "YES" else "NO"
    writer.append(StringBuilder.newBuilder.append(answer).append("\n"))
  }
  writer.close()

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def isEmpty() = multiSet.isEmpty
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import sun.management.counter.Counter

import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.StringTokenizer
import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine
import scala.util.Random

object Solution extends App {

  //=====Solution=========
  val reader = new BufferedReader(new InputStreamReader(System.in))
  val writer = new PrintWriter(System.out);

  val testNumber = reader.readLine().toInt
  var testIndex = 0
  while( testIndex < testNumber) {
    testIndex += 1

    val size = reader.readLine().toInt
    val tokenizer = new StringTokenizer(reader.readLine(), " ")
    val a = new Array[Int](size);
    {
      var i = 0
      while (i < size) {
        a(i) = Integer.parseInt(tokenizer.nextToken())
        i += 1
      }
    }

    var index: Int = 0
    var previousEven: Int = -1
    var previousOdd: Int = -1
    var answer = "YES"
    while (index < size) {
      a(index) % 2 match {
        case 0 => if (previousEven == -1 || previousEven <= a(index)) {
          previousEven = a(index)
          index = index + 1
        } else {
          answer = "NO"
          index = size + 100
        }
        case 1 => if (previousOdd == -1 || previousOdd <= a(index)) {
          previousOdd = a(index)
          index = index + 1
        } else {
          answer = "NO"
          index = size + 100
        }
      }
    }

    writer.println(answer)
  }

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def isEmpty() = multiSet.isEmpty
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}


import scala.io.Source

object Hello {

  def computeCount(a: Int, b: Int): Int = { // a > b
    if (b == 0) return 0

    a/b + computeCount(b, a%b)
  }

  def main(args: Array[String]) {
    val lineIter = Source.stdin.getLines
    lineIter.next
    while (lineIter.hasNext)
    {
      var Array(ele1, ele2) = lineIter.next.split(" ").map(_.toInt)
      if (ele1 > ele2) {
        var ele = ele1
        ele1 = ele2
        ele2 = ele
      }
      println(computeCount(ele2, ele1))
    }
  }

}

// codeforces 267A
object Vichitania extends App {
  var ss = (Console.readLine.split(" ")) map (_.toInt)
  val n = ss(0)

  def countVich(a: Int, b: Int): Int =
    if (a < b) countVich(b, a)
    else if (b == 0) 0
    else {
      val d = a / b
      val o = a % b
      d + countVich(b, o)
    }

  for (i <- 0 until n) {
    ss = (Console.readLine.split(" ")) map (_.toInt)
    val a = ss(0)
    val b = ss(1)
    val cnt = countVich(a, b)
    println(cnt)
  }
}

import java.util.StringTokenizer

object A {
  var tokenizer = new StringTokenizer("");

  def nextToken(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(readLine);
    }
    tokenizer.nextToken();
  }

  def nextInt: Int = {
    nextToken().toInt;
  }

  def gcd(a: Int, b: Int): Int = {
    if (b == 0) 0 else gcd(b, a % b) + a / b;
  }

  def main(args: Array[String]) {
    val n = nextInt;
    for (i <- 1 to n) {
      println(gcd(nextInt, nextInt))
    }
  }
}

import java.util.Scanner

object Substr {

  def main(args: Array[String]): Unit = {

    val src = new Scanner(System.in)
    val n = src.nextInt()
    for (i <- 1 to n) {
      println(sub(src.nextInt(), src.nextInt()))
    }
    src.close()
  }

  def sub(a: Int, b: Int) = {
    def iter(a: Int, b: Int, k: Int): Int = {
      if (a < 1 || b < 1) k
      else if (a > b) iter(a % b, b, k + a / b)
      else if (a < b) iter(a, b % a, k + b / a)
      else if (a == b) k + 1
      else k
    }
    iter(a, b, 0)
  }
}

object A{
  def main(args: Array[String]){

    val n =readLine.toInt

    (0 until n).foreach{i=>

      val sp=readLine.split(" ")

      println(
        count(sp(0).toInt,sp(1).toInt))

      def count(a:Int,b:Int):Int={
        if(b<a){
          count(b,a)
        }else if(a==0){
          0
        }else{
          val c:Int =b/a
          b/a + count(b%a,a)
        }
      }
    }
  }
}

import java.util.StringTokenizer

object A {
  var tokenizer = new StringTokenizer("");

  def nextToken(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(readLine);
    }
    tokenizer.nextToken();
  }

  def nextInt: Int = {
    nextToken().toInt;
  }

  def gcd(a: Int, b: Int): Int = {
    if (b == 0) 0 else gcd(b, a % b) + a / b;
  }

  def main(args: Array[String]) {
    val n = nextInt;
    for (i <- 1 to n) {
      print(gcd(nextInt, nextInt))
    }
  }
}


import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    //    val src = io.Source.fromFile("/usr/share/dict/words")
    //    val lines = src.getLines()
    //    src.close()
    val t = readLine().toInt
    for (i <- 1 to t) {
      val nxm = readIntLine()
      val operations = (1 to nxm.last).map(_ => readIntLine()).toList
      println(calc(nxm(1), nxm(1) + 1, operations))
    }
  }

  def calc(l: Int, r: Int, operations: List[List[Int]]): Int = operations match {
    case Nil => r - l
    case op :: ops =>
      calc(if (op.last >= l) math.min(l, op.head) else l, if (op.head + 1 <= r) math.max(op.last + 1, r) else r, ops)
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

//  def printArray[T](arr: Array[T]): Unit = {
//    val str = new StringBuilder()
//    str.addAll((if (arr.head == -1) 0 else arr.head).toString)
//    //    print(arr(0))
//    for (i <- 1 until arr.length) {
//      str.addAll(" " + (if (arr(i) == -1) 0 else arr(i)))
//    }
//    println(str)
//  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

}

object B extends App {
  val t = scala.io.StdIn.readInt()

  (0 until t).foreach { _ =>
    val Array(n, x, m) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    val (l, r) = (0 until m).foldLeft((x, x)) {
      case ((l, r), i) =>
        val Array(li, ri) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
        if (l <= ri && r >= li) (l min li, r max ri)
        else (l, r)
    }

    val ans = r - l + 1

    println(ans)
  }
}


import scala.io.StdIn

object CaseOfTheZerosAndOnes {
  def main(args: Array[String]): Unit = {
    StdIn.readLine()
    val bits = StdIn.readLine()
    val (zeros, ones) = bits.foldLeft((0, 0)) { case ((zeros, ones), bit) =>
      if (bit == '0') (zeros + 1, ones)
      else if (bit == '1') (zeros, ones + 1)
      else (zeros, ones)
    }
    println(Math.abs(zeros - ones))
  }
}

object Program{
	def main(ins:Array[String]){
		val n = readInt()
		val s = readLine()
		val a = s.partition(_ == '1')
		def ln(x:String)= x.length
		def check() =
		if (ln(a._1) > ln(a._2)) ln(a._1) - ln(a._2)
			else ln(a._2) - ln(a._1)
		println(check())
	}
}

import java.io.InputStream
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.StringTokenizer
import java.io.PrintWriter
import java.io.FileInputStream
import java.io.PrintStream
import java.io.FileOutputStream

import scala.util.Random

object CF556A {

  class InputReader(val stream:InputStream ) {
    var st:StringTokenizer=new StringTokenizer("")
    val reader=new BufferedReader(new InputStreamReader(stream), 32768);

    def next():String = {
      while (!st.hasMoreTokens()){
        val currentLine = reader.readLine
        st=new StringTokenizer(currentLine)
      }
      return st.nextToken
    }

    def nextInt():Int = {
      return next.toInt
    }

    def nextLong():Long = {
      return next.toLong
    }
    def nextDouble:Double = {
      return next.toDouble
    }
  }

  def main(args: Array[String]): Unit = {
    val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
    var in = new InputReader(System.in)
    var out = System.out
    if ( !isOnlineJudge ) {
      in = new InputReader(new FileInputStream("input.txt"))
      out = new PrintStream(new FileOutputStream("output.txt"))
    }
    solve(in,out)
  }

  def solve(in: InputReader, out: PrintStream) = {
    //Solution goes here
    in.nextInt();
    val s = in.next()
    val ch = s.toCharArray
    val cnt0 = ch.foldLeft(0)((cnt,c) => if (c=='0') cnt+1 else cnt )
    val cnt1 = ch.foldLeft(0)((cnt,c) => if (c=='1') cnt+1 else cnt )
    out.println(s.length - Math.min(cnt0,cnt1) * 2)
  }

}

import java.io.InputStream
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.StringTokenizer
import java.io.PrintWriter
import java.io.FileInputStream
import java.io.PrintStream
import java.io.FileOutputStream

import scala.util.Random

object CF556A {

  class InputReader(val stream:InputStream ) {
    var st:StringTokenizer=new StringTokenizer("")
    val reader=new BufferedReader(new InputStreamReader(stream), 32768);

    def next():String = {
      while (!st.hasMoreTokens()){
        val currentLine = reader.readLine
        st=new StringTokenizer(currentLine)
      }
      return st.nextToken
    }

    def nextInt():Int = {
      return next.toInt
    }

    def nextLong():Long = {
      return next.toLong
    }
    def nextDouble:Double = {
      return next.toDouble
    }
  }

  def main(args: Array[String]): Unit = {
    val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
    var in = new InputReader(System.in)
    var out = System.out
    if ( !isOnlineJudge ) {
      in = new InputReader(new FileInputStream("input.txt"))
      out = new PrintStream(new FileOutputStream("output.txt"))
    }
    solve(in,out)
  }

  def solve(in: InputReader, out: PrintStream) = {
    //Solution goes here
    in.nextInt();
    val s: String = in.next()
    val (z,o) = s.toCharArray.foldLeft((0,0))((p,c) => if (c=='0') (p._1+1,p._2) else (p._1,p._2+1))
    out.println(s.length - Math.min(z,o) * 2)
  }

}

object A556 {
  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)

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

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

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val input = scala.io.StdIn.readLine.count(_ == '0')
    println(n - 2*math.min(n-input, input))
  }
}

object _556A extends CodeForcesApp {
  import CodeForcesApp._, scala.annotation.tailrec, scala.collection.mutable

  override type Input = String
  override type Output = Int

  override def read(scanner: java.util.Scanner) = {
    import scanner._
    nextInt
    next
  }

  override def solve(input: Input) = {
    var s = List.empty[Boolean]
    for {
      c <- input
      i = c == '0'
    } {
      s = (i, s) match {
        case (x, y :: ys) if x != y => ys
        case _ => i :: s
      }
    }

    s.length
  }

  override def format(result: Output) = super.format(result)
}

/****************************** IGNORE BELOW *********************************/
abstract class CodeForcesApp {
  /********************************[ I/O ]************************************/
  import java.util.Scanner
  import CodeForcesApp._
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  def apply(problem: String): String  = apply(new Scanner(problem))
  def apply(scanner: Scanner): String = format(solve(read(scanner)))
  def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
/********************************[ solution ]*********************************/
  type Input
  type Output
  def read(scanner: Scanner): Input
  def solve(input: Input): Output
  def format(result: Output): String = result.toString
}
/**********************************[ lib ]************************************/
object CodeForcesApp {
  case class Memo[I <% K, K, O](f: I => O) extends (I => O) {
    val cache = collection.mutable.Map.empty[K, O]
    override def apply(x: I): O = cache.getOrElseUpdate(x, f(x))
  }
  type ==>[I, O] = Memo[I, I, O]
  def when[A](condition: Boolean)(f: => A) = if (condition) Some(f) else None
/*******************************[ constants ]*********************************/
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  val modulus = 1000000007
}

import java.io.BufferedInputStream
import java.io.BufferedReader
import java.io.InputStreamReader

object A_Zeros_Ones {

  def main(args: Array[String]): Unit = {
    val bis = new BufferedInputStream(System.in);
    val br = new BufferedReader(new InputStreamReader(bis));

    val n = Integer.parseInt(br.readLine().trim());
//    val line = br.readLine()

    var counter = 0
    for (i <- 0 until n) {
      if (br.read().toChar == '1') counter += 1
      else counter -= 1
    }

    println(Math.abs(counter))
  }
}

object WaterMelon{
	def main(args : Array[String]){
		var a = readInt()
		if ( a > 2 && a % 2 == 0){
			println("YES")
		}	else{
			println("NO")
		}
	}
}


import java.util.StringTokenizer

object _463 extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  println((1 to n).map(i => next.toInt).max)
}

  object Solution extends App {
    val in = scala.io.Source.stdin.getLines()
    val n = in.next()
    println(in.next().split(" ").map(_.toInt).max)
  }

object B463 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val h = readInts(n)
    var res = 0L
    var ret = h(0).toLong
    for(i <- 0 until n-1) {
      res += h(i) - h(i+1)
      if(res < 0) {
        ret += -res
        res = 0
      }
    }
    println(ret)
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

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

    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))
    }
  }

}

import java.util.Scanner

/**
 * Created by Kuang.Ru on 14-9-28.
 */
object B463 extends App{
  val sc = new Scanner(System.in)
  var n = sc.nextInt()
  var pay: Long = 0
  var curH = 0
  var e = 0

  while (n >= 1) {
    n -= 1
    val nextH = sc.nextInt()
    val decE = nextH - curH

    if (decE > e) {
      pay += nextH - curH - e
      e = 0
    } else {
      e -= decE
    }

    curH = nextH
  }

  println(pay)
}

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

/**
 * Created by arseny on 30.08.14.
 */
object B extends App {
  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextInt = in.nextInt
  def nextLong = in.nextLong
  def nextDouble = in.nextDouble
  def nextString = in.next

  def solve() = {
    val n = nextInt
    val hs = Array.fill(n + 1)(0L)
    for(i <- 1 to n) {
      hs(i) = nextLong
    }
    var min = 0L
    var e = 0L
    for(i <- 1 to n) {
      if(e + hs(i - 1) - hs(i) >= 0) {
         e += hs(i - 1) - hs(i)
      } else {
        min += -(hs(i - 1) - hs(i) + e)
        e = 0L
      }
    }
    out.print(min)
  }

  try {
    solve()
  } catch {
    case _: Exception => sys.exit(9999)
  } finally {
    out.flush()
    out.close()
  }
}

  object Solution extends App {
    val in = scala.io.Source.stdin.getLines()
    val n = in.next()
    println(in.next().split(" ").max)
  }

object B463 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val h = readInts(n)
    var res = 0L-h(0)
    var ret = 0L
    for(i <- 0 until n-1) {
      res += h(i) - h(i+1)
      if(res < 0) {
        ret += -res
        res = 0
      }
    }
    println(ret)
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

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

    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))
    }
  }

}


import scala.collection.mutable.ListBuffer

object prob2 {
  def main(args: Array[String]) = {
    new Resolver1(Console.in, Console.out).run()
  }
}

class Resolver1(input: java.io.BufferedReader, output: java.io.PrintStream) {
  import java.util.StringTokenizer

  def run() {
    var tokenizer = new StringTokenizer(input.readLine())
    val n = tokenizer.nextToken().toInt
    var q = tokenizer.nextToken().toInt
    val SS = ListBuffer.empty[Long]
    tokenizer = new StringTokenizer(input.readLine())
    for (i <- 0 until n) {
      SS+= tokenizer.nextToken().toLong
    }
    var S = SS.toArray.sorted.reverse
    S +:=0.toLong
    for (i <- 1 until S.length) {
      S(i) = S(i) + S(i - 1)
    }
    while (q > 0) {
      q -= 1
      tokenizer = new StringTokenizer(input.readLine())
      val x = tokenizer.nextToken().toInt
      val y = tokenizer.nextToken().toInt
      output.println(S(x) - S(x - y))
    }

  }
}

import scala.collection.mutable.ListBuffer

object prob {
  def main(args: Array[String]) = {
    new Resolver(Console.in, Console.out).run()
  }
}

class Resolver(input: java.io.BufferedReader, output: java.io.PrintStream) {
  import java.util.StringTokenizer

  def run() {
    var tokenizer = new StringTokenizer(input.readLine())
    val n = tokenizer.nextToken().toInt
    var q = tokenizer.nextToken().toInt
    val SS = ListBuffer.empty[Long]
    tokenizer = new StringTokenizer(input.readLine())
    for (i <- 0 until n) {
      SS+= tokenizer.nextToken().toLong
    }
    var S = SS.toArray.sorted.reverse
    S +:=0.toLong
    for (i <- 1 until S.length) {
      S(i) = S(i) + S(i - 1)
    }
    while (q > 0) {
      q -= 1
      tokenizer = new StringTokenizer(input.readLine())
      val x = tokenizer.nextToken().toInt
      val y = tokenizer.nextToken().toInt
      println(S(x) - S(x - y))
    }

  }
}

object prob extends App {
  var L = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  var q = L(1)
  var S = scala.io.StdIn.readLine().split(" ").map(_.toLong).sorted
  val a = S.length-1
  for (i <- 1 until S.length) {
    S(a-i) = S(a-i)+S(a-i+1)
  }
  while (q>0) {
    q-=1
    val LL = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    if (LL(0) != LL(1)) {
      println(S(LL(0)-1) - S(LL(0) - LL(1)-1))
    }
    else {
      println(S(LL(0)-1))
    }
  }
}

import scala.util.Sorting.quickSort

object prob extends App {
  val L = readLine().split(" ").map(_.toInt)
  val q = L(1)
  var S = readLine().split(" ").map(_.toLong)
  quickSort(S)
  S.reverse
  S +:= 0.toLong
  for (i <- 1 until S.length) {
    S(i) = S(i)+S(i-1)
  }
  for (i <- 1 to q) {
    val LL = readLine().split(" ").map(_.toInt)
    println(S(LL(0)) - S(LL(0) - LL(1)))
  }
}

import scala.util.Sorting.quickSort

object prob extends App {
  val L = readLine().split(" ").map(_.toInt)
  val q = L(1)
  var S = readLine().split(" ").map(_.toLong)
  quickSort(S)
  S +:= 0.toLong
  S = S.reverse
  for (i <- 1 until S.length) {
    S(i) = S(i)+S(i-1)
  }
  for (i <- 1 to q) {
    val LL = readLine().split(" ").map(_.toInt)
    println(S(LL(0)) - S(LL(0) - LL(1)))
  }
}

import scala.util.Sorting.quickSort

object prob extends App {
  val L = readLine().split(" ").map(_.toInt)
  val q = L(1)
  var S = readLine().split(" ").map(_.toLong)
  quickSort(S)
  S +:= 0.toLong
  for (i <- 1 until S.length) {
    S(i) = S(i)+S(i-1)
  }
  for (i <- 1 to q) {
    val LL = readLine().split(" ").map(_.toInt)
    println(S(LL(0)) - S(LL(0) - LL(1)))
  }
}

import scala.collection.mutable

object prob extends App {
  import scala.collection.mutable.ArrayBuilder
  val L = readLine().split(" ").map(_.toInt)
  val q = L(1)
  var S = readLine().split(" ").map(_.toInt).sorted.reverse
  for (i <- 1 until S.length) {
    S(i) = S(i)+S(i-1)
  }
  for (i <- 1 to q) {
    val LL = readLine().split(" ").map(_.toInt)
    if (LL(0) != LL(1)) {
      println(S(LL(0)-1) - S(LL(0) - LL(1)-1))
    }
    else {
      println(S(LL(0)-1))
    }
  }
}

import scala.collection.mutable

object prob extends App {
  import scala.collection.mutable.ArrayBuilder
  val L = readLine().split(" ").map(_.toInt)
  val q = L(1)
  val S = readLine().split(" ").map(_.toInt).sorted.reverse
  var SS = new ArrayBuilder.ofInt
  var s: Int = 0
  SS += s
  for (i <- S) {
    s += i
    SS += s
  }
  val SSS = SS.result
  for (i <- 1 to q) {
    val LL = readLine().split(" ").map(_.toInt)
    println(SSS(LL(0)) - SSS(LL(0) - LL(1)))
  }
}

object prob extends App {

  import scala.io.StdIn
  import scala.math.{max, min, pow,abs}
  import scala.List
  import scala.util.Sorting.quickSort
  import scala.collection.mutable.{ArrayBuffer, ListBuffer}
  val L = readLine().split(" ").map(_.toInt)
  val q = L(1)
  val S = readLine().split(" ").map(_.toInt)
  quickSort(S)
  val SS = ListBuffer.empty[Long]
  var s: Long = 0
  SS +=s
  for (i <- S) {
    s+=i
    SS +=s
  }
  for (i <- 1 to q){
    val LL = readLine().split(" ").map(_.toInt)
    println(SS(LL(0)) - SS(LL(0) - LL(1)))
  }
}


import java.util.StringTokenizer

import scala.annotation.tailrec
import scala.util.Try

object D extends App {
  val INF = 1 << 30
  var st: StringTokenizer = _
  def read() = { st = new StringTokenizer(readLine()) }
  def int() = st.nextToken().toInt

  read()
  val n = int()
  val k = int()
  var gc = int()
  var bc = int()
  var failed = false

  val G = 'G'
  val B = 'B'

  def anti(c: Char): Char = {
    if (c == G) B else G
  }

  @tailrec
  def s(start: String, prim: Char, fc: Int, sc: Int): String = {
    if ((fc == 0) && (sc == 0)) return start
    val c = if (fc >= sc) Math.min(fc, k) else 1
    if (c <= 0) sys.error("")
    s(start + Array.fill(c)(prim).mkString, anti(prim), sc, fc - c)
  }

  val ans = Try {
    if (gc > bc) s("", G, gc, bc) else s("", B, bc, gc)
  }.getOrElse("NO")
  println(ans)
}

import java.util.StringTokenizer

import scala.util.Try

object D extends App {
  val INF = 1 << 30
  var st: StringTokenizer = _
  def read() = { st = new StringTokenizer(readLine()) }
  def int() = st.nextToken().toInt

  read()
  val n = int()
  val k = int()
  var gc = int()
  var bc = int()
  var failed = false

  val G = 'G'
  val B = 'B'

  def anti(c: Char): Char = {
    if (c == G) B else G
  }

  def s(prim: Char, fc: Int, sc: Int): String = {
    if ((fc == 0) && (sc == 0)) return ""
    val c = if (fc >= sc) Math.min(fc, k) else 1
    if (c <= 0) sys.error("")
    Array.fill(c)(prim).mkString + s(anti(prim), sc, fc - c)
  }

  val ans = Try {
    if (gc > bc) s(G, gc, bc) else s(B, bc, gc)
  }.getOrElse("NO")
  println(ans)
}

import java.util.StringTokenizer

import scala.annotation.tailrec
import scala.util.Try

object D extends App {
  val INF = 1 << 30
  var st: StringTokenizer = _
  def read() = { st = new StringTokenizer(readLine()) }
  def int() = st.nextToken().toInt

  read()
  val n = int()
  val k = int()
  var gc = int()
  var bc = int()
  var failed = false

  val G = 'G'
  val B = 'B'

  def anti(c: Char): Char = {
    if (c == G) B else G
  }

  @tailrec
  def s(start: String, prim: Char, fc: Int, sc: Int): String = {
    if ((fc == 0) && (sc == 0)) return ""
    val c = if (fc >= sc) Math.min(fc, k) else 1
    if (c <= 0) sys.error("")
    s(Array.fill(c)(prim).mkString, anti(prim), sc, fc - c)
  }

  val ans = Try {
    if (gc > bc) s("", G, gc, bc) else s("", B, bc, gc)
  }.getOrElse("NO")
  println(ans)
}

import java.util.StringTokenizer

import scala.annotation.tailrec
import scala.util.Try

object D extends App {
  val INF = 1 << 30
  var st: StringTokenizer = _
  def read() = { st = new StringTokenizer(readLine()) }
  def int() = st.nextToken().toInt

  read()
  val n = int()
  val k = int()
  var gc = int()
  var bc = int()
  var failed = false

  val G = 'G'
  val B = 'B'

  def anti(c: Char): Char = {
    if (c == G) B else G
  }

  @tailrec
  def s(start: String, prim: Char, fc: Int, sc: Int): String = {
    if ((fc == 0) && (sc == 0)) return start
    val c = if (fc >= sc) Math.min(fc, k) else 1
    if (c <= 0) sys.error("")
    s(Array.fill(c)(prim).mkString, anti(prim), sc, fc - c)
  }

  val ans = Try {
    if (gc > bc) s("", G, gc, bc) else s("", B, bc, gc)
  }.getOrElse("NO")
  println(ans)
}


object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }

  val Array(n, a, b) = readInts(3)

  var even = n / 2
  var odd = n - even

  val grid = Array.fill(a, b){ 0 }
  var oddI = 1
  var evenI = 2

  for {
    i <- 0 until a
    j <- 0 until b
  } {
    if ((i + j) % 2 == 0) {
      if (odd > 0) {
        odd -= 1
        grid(i)(j) = oddI
        oddI += 2
      }
    } else {
      if (even > 0) {
        even -= 1
        grid(i)(j) = evenI
        evenI += 2
      }
    }
  }

  if (even == 0 && odd == 0) {
    grid.foreach { row => println(row.mkString(" ")) }
  } else println(-1)
}

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

object _644A extends CodeForcesApp {
  override def apply(io: IO) = {
    val n, a, b = io[Int]
    var (d, r) = (1, 2)

    val t = Array.tabulate(a, b) {
      case (i, j) if (i + j)%2 == 0 =>
        val x = d
        d += 2
        x
      case _ =>
        val x = r
        r += 2
        x
    }

    val ans = Array.tabulate(a, b) {
      case (i, j) => if (t(i)(j) > n) 0 else t(i)(j)
    }

    if (n > a*b) {
      io += -1
    } else {
      ans foreach {row =>
        io ++= row
        io.appendLine()
      }
    }
    io
  }
}
/****************************[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 partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A](val t: Traversable[A]) extends AnyVal {
    def onlyElement: A = t.head.ensuring(t.size == 1)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates: Traversable[A] = {
      val elems = mutable.Set.empty[A]
      t collect {case i if !elems.add(i) => i}
    }
    def zipWith[B](f: A => B): Traversable[(A, B)] = t map {i => i -> f(i)}
    def mapTo[B](f: 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
  }
  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 IndexedSeqExtensions[A](val s: IndexedSeq[A]) extends AnyVal {
    def withOffset(offset: Int): IndexedSeq[A] = Iterator.fill(offset)(null.asInstanceOf[A]) ++: s
  }
  implicit class PairsExtensions[A, B](val t: Traversable[(A, B)]) extends AnyVal {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_._1).mapValues(_._2)
    def toMultiMap: Map[A, Traversable[B]] = t.groupBy(_._1).mapValues(_.map(_._2))
    def swap: Traversable[(B, A)] = t.map(_.swap)
  }
  implicit class MapExtensions[K, V](val m: Map[K, V]) extends AnyVal {
    def invert: Map[V, Set[K]] = m.swap.toMultiMap.mapValues(_.toSet)
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    def bitCount: Int = java.lang.Long.bitCount(x)
  }
  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 nonNegative: Option[A] = when(n.gteq(x, n.zero))(x) //e.g. students.indexOf("Greg").nonNegative
  }
  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(n.min(x, y), n.max(x, y), n.one)
  }
  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] = Dict.empty[K, V] withDefaultValue default
  }
  def memoize[I] = new {
    def apply[O](f: I => O): I => O = new mutable.HashMap[I, O]() {
      override def apply(key: I) = getOrElseUpdate(key, f(key))
    }
  }
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  def repeat(n: Int)(f: => Unit): Unit = (1 to n).foreach(_ => f)
  val mod: Int = (1e9 + 7).toInt
}
/***********************************[Scala I/O]*********************************************/
import java.io._, java.util.StringTokenizer
import scala.collection.generic.{Growable, CanBuild}

class IO(in: BufferedReader, out: BufferedWriter) extends PrintWriter(out, true) with Iterator[String] with Growable[Any] {
  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

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

  def apply[A](implicit parse: IO.Parser[A]): A = parse.apply(this)
  def apply[C[_], A: IO.Parser](n: Int)(implicit builder: CanBuild[A, C[A]]): C[A] = (builder() ++= Iterator.fill(n)(apply)).result()

  def till(delim: String): String = tokenizer().get.nextToken(delim)
  def tillEndOfLine(): String = till("\n\r")

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

  var separator = " "
  private[this] var isNewLine = true

  override def +=(obj: Any) = {
    if (isNewLine) isNewLine = false else print(separator)
    print(obj)
    this
  }
  def ++=(t: TraversableOnce[_], ifEmpty: => Any): this.type = if (t.isEmpty) this += ifEmpty else this ++= t

  def appendLine(): this.type = {
    println()
    isNewLine = true
    this
  }

  override def clear() = flush()
  override def close() = {
    flush()
    in.close()
    super.close()
  }
}

object IO {
  class Parser[A](val apply: IO => A) {
    def map[B](f: A => B): Parser[B] = new Parser(apply andThen f)
  }
  implicit def collection[C[_], A: Parser](implicit cbf: CanBuild[A, C[A]])  : Parser[C[A]]            = new Parser(r => r[C, A](r[Int]))
  implicit val string                                                        : Parser[String]          = new Parser(_.next())
  implicit val char                                                          : Parser[Char]            = string.map(s => s.ensuring(_.length == 1, s"Expected Char; found $s").head)
  implicit val boolean                                                       : Parser[Boolean]         = string.map(_.toBoolean)
  implicit val int                                                           : Parser[Int]             = string.map(_.toInt)
  implicit val long                                                          : Parser[Long]            = string.map(_.toLong)
  implicit val bigInt                                                        : Parser[BigInt]          = string.map(BigInt(_))
  implicit val double                                                        : Parser[Double]          = string.map(_.toDouble)
  implicit val bigDecimal                                                    : Parser[BigDecimal]      = string.map(BigDecimal(_))
  implicit def tuple2[A: Parser, B: Parser]                                  : Parser[(A, B)]          = new Parser(r => (r[A], r[B]))
  implicit def tuple3[A: Parser, B: Parser, C: Parser]                       : Parser[(A, B, C)]       = new Parser(r => (r[A], r[B], r[C]))
  implicit def tuple4[A: Parser, B: Parser, C: Parser, D: Parser]            : Parser[(A, B, C, D)]    = new Parser(r => (r[A], r[B], r[C], r[D]))
  implicit def tuple5[A: Parser, B: Parser, C: Parser, D: Parser, E: Parser] : Parser[(A, B, C, D, E)] = new Parser(r => (r[A], r[B], r[C], r[D], r[E]))
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val Array(n, a, b) = in.next().split(' ').map(_.toInt)
  if (n > a * b)
    println(-1)
  else {
    val ans = Array.ofDim[Int](a, b)
    var odd = 1
    var even = 2
    (0 until a).foreach{ i =>
      (0 until b).foreach { j =>
        if ((i + j) % 2 == 0 && odd <= n) {
          ans(i)(j) = odd
          odd += 2
        }
        else if (even <= n) {
          ans(i)(j) = even
          even += 2
        }
      }
    }
    println(ans.map(_.mkString(" ")).mkString("\n"))
  }

}

import java.io._
import java.util.StringTokenizer
import java.util.TreeMap
import scala.collection.mutable

object A {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  class MultiHashSet[T <% Comparable[T]] {
    val map = new mutable.HashMap[T, Int]()

    def count(x: T): Int = {
      return map.getOrElse(x, 0)
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  class MultiTreeSet[T <% Comparable[T]] {
    val map = new TreeMap[T, Int]()

    def count(x: T): Int = {
      val res = map.get(x)
      if (res == null)
        return 0
      return res
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def first(): T = return map.firstKey()

    def last(): T = return map.lastKey()

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  /**
    * Segment tree for any commutative function
    * @param values Array of Int
    * @param commutative function like min, max, sum
    * @param zero zero value - e.g. 0 for sum, Inf for min, max
    */
  class SegmentTree(values: Array[Int])(commutative: (Int, Int) => Int)(zero: Int) {
    private val SIZE = 1e5.toInt
    private val n = values.length
    val t = new Array[Int](2 * n)
    Array.copy(values, 0, t, n, n)

    // build segment tree
    def build = {
      for (i <- n - 1 until 0 by -1) {
        t(i) = commutative(t(2 * i), t(2 * i + 1))
      }
    }

    // change value at position p to x
    // TODO beatify
    def modify(p: Int, x: Int) = {
      var pos = p + n
      t(pos) = x
      while (pos > 1) {
        t(pos / 2) = commutative(t(pos), t(pos ^ 1))
        pos /= 2
      }
    }

    // TODO implement me!
    def modify(p: Int, left: Int, right: Int) = ???

    def query(p: Int) = ???

    // sum [l, r)
    // min l = 0
    // max r = n
    // TODO beatify
    def query(left: Int, right: Int): Int = {
      var res = zero
      var r = right + n
      var l = left + n
      while (l < r) {
        if (l % 2 == 1) {
          res = commutative(res, t(l))
          l += 1
        }
        if (r % 2 == 1) {
          r -= 1
          res = commutative(res, t(r))
        }
        l /= 2
        r /= 2
      }
      res
    }
  }

  def solve: Int = {
    val n = nextInt
    val a = nextInt
    val b = nextInt
    if (a * b < n) {
      out.println(-1)
      return 0
    }
    var flag = true
    var fst = Stream.from(1, 2)
    var snd = Stream.from(2, 2)
    var cnt = n
    for (i <- 0 until a) {
      for (j <- 0 until b) {
        if (cnt > 0) {
          if (flag && fst.head <= n) {
            out.print(s"${fst.head} ")
            fst = fst.tail
            cnt -= 1
          } else if (!flag && snd.head <= n) {
            out.print(s"${snd.head} ")
            snd = snd.tail
            cnt -= 1
          } else {
            out.print("0 ")
          }
        } else {
          out.print("0 ")
        }
        if (j == b - 1 && b % 2 == 0) {
          flag = flag
        } else {
          flag = !flag
        }
      }
      out.println()
    }
    return 0
  }
}