import scala.io.StdIn

object F {

   def check(s: String) = {
      val pairs = s zip s.tail
      (pairs.count { case (a, b) => a == b && a == '0'},
        pairs.count { case (a, b) => a != b},
        pairs.count { case (a, b) => a == b && a == '1'})
   }

   def solution(n00: Int, n01: Int, n11: Int): String = {
      if (n01 == 0)
         if (n00 == 0)
            Seq.fill(n11 + 1)("1")
         else // n11 == 0
            Seq.fill(n00 + 1)("0")
      else {
         val s01 = Stream.continually(Seq("0", "1")).flatten.take(n01 - 1).toSeq
         val s00 = Seq.fill(n00 + 1)("0")
         val s11 = Seq.fill(n11 + 1)("1")
         s01 ++ (if (n01 % 2 == 1) s00 ++ s11 else s11 ++ s00)
      }
   }
     .mkString("")

   def main(args: Array[String]): Unit = {
      for (_ <- (0 until StdIn.readLine.toInt)) {
         val Seq(n00, n01, n11) = StdIn.readLine.split(" ").toSeq.map(_.toInt)
         println(F.solution(n00, n01, n11))
      }
   }
}

import java.io._
import java.util.StringTokenizer

import scala.collection.immutable
import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new C640B(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

  class FastScanner(val streamReader: InputStreamReader) {
    private[this] val reader = new BufferedReader(streamReader, 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

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

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

    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

    def ns(n: Int): Array[Char] = ns().toCharArray

    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)

    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }

    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }

    def nal(n: Int): Array[Long] = map(n)(_ => nl())

    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n)(_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while (i < N) {
      f(i);
      i += 1
    }
  }

  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while (i >= offset) {
      f(i);
      i -= 1
    }
  }

  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class C640B(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val t =ni()
    REP(t) { _ =>
      val n0 = ni()
      val n1 = ni()
      val n2 = ni()

      val sb = new StringBuilder
      if(n1 > 0) {
        REP(n1+1) { i =>
          if(i%2 == 0) sb.append("1")
          else sb.append("0")
        }
        sb.insert(1, (0 until n0 map(_ => '0')).mkString(""))
        sb.insert(0, (0 until n2 map(_ => '1')).mkString(""))
        out.println(sb.toString())
      } else {
        if(n0 > 0) 0 to n0 foreach(_ => sb.append("0"))
        if(n2 > 0) 0 to n2 foreach(_ => sb.append("1"))
        out.println(sb.toString())
      }
    }
  }
}

import scala.annotation.tailrec
import scala.io.StdIn

object F {

   def check(s: String) = {
      val pairs = s zip s.tail
      (pairs.count { case (a, b) => a == b && a == '0'},
        pairs.count { case (a, b) => a != b},
        pairs.count { case (a, b) => a == b && a == '1'})
   }

   def solution(n00: Int, n01: Int, n11: Int): String = {
      if (n01 == 0)
         if (n00 == 0)
            Seq.fill(n11 + 1)("1")
         else // n11 == 0
            Seq.fill(n00 + 1)("0")
      else {
           Seq.fill(n01 / 2)("01").take(n01 - 1) ++
             Seq.fill(n00 + 1)("0") ++
             Seq.fill(n11 + 1)("1")
      }
      /*
      01      1
      01 0    2
      01 01   3
      01 010  4
      01 0100 5
       */
   }
     .mkString("")

   def main(args: Array[String]): Unit = {
      for (_ <- (0 until StdIn.readLine.toInt)) {
         val Seq(n00, n01, n11) = StdIn.readLine.split(" ").toSeq.map(_.toInt)
         println(F.solution(n00, n01, n11))
      }
   }
}

import scala.annotation.tailrec
import scala.io.StdIn

object F {

   def check(s: String) = {
      val pairs = s zip s.tail
      (pairs.count { case (a, b) => a == b && a == '0'},
        pairs.count { case (a, b) => a != b},
        pairs.count { case (a, b) => a == b && a == '1'})
   }

   def solution(n00: Int, n01: Int, n11: Int): String = {
      if (n01 == 0)
         if (n00 == 0)
            Seq.fill(n11 + 1)("1")
         else // n11 == 0
            Seq.fill(n00 + 1)("0")
      else {
         Seq.fill(n11 + 1)("1") ++
           Seq.fill(n00 + 1)("0") ++
           Seq.fill(n01 / 2)("01").take(n01 - 1)
      }
      /*
      01      1
      01 0    2
      01 01   3
      01 010  4
      01 0100 5
       */
   }
     .mkString("")

   def main(args: Array[String]): Unit = {
      for (_ <- (0 until StdIn.readLine.toInt)) {
         val Seq(n00, n01, n11) = StdIn.readLine.split(" ").toSeq.map(_.toInt)
         println(F.solution(n00, n01, n11))
      }
   }
}

import scala.annotation.tailrec
import scala.io.StdIn

object F {

   def check(s: String) = {
      val pairs = s zip s.tail
      (pairs.count { case (a, b) => a == b && a == '0'},
        pairs.count { case (a, b) => a != b},
        pairs.count { case (a, b) => a == b && a == '1'})
   }

   def solution(n00: Int, n01: Int, n11: Int): String = {
      if (n01 == 0)
         if (n00 == 0)
            Seq.fill(n11 + 1)("1")
         else // n11 == 0
            Seq.fill(n00 + 1)("0")
      else {
         Seq.fill(n11)("1") ++
           Seq.fill(n00)("0") ++
           Seq.fill(n01 / 2)("01").take(n01 - 1)
      }
      /*
      01      1
      01 0    2
      01 01   3
      01 010  4
      01 0100 5
       */
   }
     .mkString("")

   def main(args: Array[String]): Unit = {
      for (_ <- (0 until StdIn.readLine.toInt)) {
         val Seq(n00, n01, n11) = StdIn.readLine.split(" ").toSeq.map(_.toInt)
         println(F.solution(n00, n01, n11))
      }
   }
}

import java.io._
import java.util.StringTokenizer

import scala.collection.immutable
import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new C640B(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

  class FastScanner(val streamReader: InputStreamReader) {
    private[this] val reader = new BufferedReader(streamReader, 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

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

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

    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

    def ns(n: Int): Array[Char] = ns().toCharArray

    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)

    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }

    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }

    def nal(n: Int): Array[Long] = map(n)(_ => nl())

    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n)(_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while (i < N) {
      f(i);
      i += 1
    }
  }

  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while (i >= offset) {
      f(i);
      i -= 1
    }
  }

  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class C640B(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val t =ni()
    REP(t) { _ =>
      val n0 = ni()
      val n1 = ni()
      val n2 = ni()

      val sb = new StringBuilder
      if(n1 > 0) {
        0 until (n1+1)/2 foreach(_ => sb.append("10"))
        0 until n0 foreach(_ => sb.append("0"))
        out.println((1 to n2 map(_ => "1")).mkString("") + sb.toString())
      } else {
        if(n0 > 0) 0 to n0 foreach(_ => sb.append("0"))
        if(n2 > 0) 0 to n2 foreach(_ => sb.append("1"))
        out.println(sb.toString())
      }
    }
  }
}

import java.io._
import java.util.StringTokenizer

import scala.collection.immutable
import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new C640B(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

  class FastScanner(val streamReader: InputStreamReader) {
    private[this] val reader = new BufferedReader(streamReader, 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

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

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

    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

    def ns(n: Int): Array[Char] = ns().toCharArray

    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)

    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }

    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }

    def nal(n: Int): Array[Long] = map(n)(_ => nl())

    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n)(_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while (i < N) {
      f(i);
      i += 1
    }
  }

  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while (i >= offset) {
      f(i);
      i -= 1
    }
  }

  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class C640B(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val t =ni()
    REP(t) { _ =>
      val n0 = ni()
      val n1 = ni()
      val n2 = ni()

      val sb = new StringBuilder
      if(n1 > 0) {
        0 until (n1+1)/2 foreach(_ => sb.append("10"))
        0 until n0 foreach(_ => sb.append("0"))
        out.println((1 until n2 map(_ => "1")).mkString("") + sb.toString())
      } else {
        if(n0 > 0) 0 to n0 foreach(_ => sb.append("0"))
        if(n2 > 0) 0 to n2 foreach(_ => sb.append("1"))
        out.println(sb.toString())
      }
    }
  }
}

import java.io._
import java.util.StringTokenizer

import scala.collection.immutable
import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new C640B(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

  class FastScanner(val streamReader: InputStreamReader) {
    private[this] val reader = new BufferedReader(streamReader, 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

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

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

    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

    def ns(n: Int): Array[Char] = ns().toCharArray

    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)

    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }

    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }

    def nal(n: Int): Array[Long] = map(n)(_ => nl())

    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n)(_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while (i < N) {
      f(i);
      i += 1
    }
  }

  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while (i >= offset) {
      f(i);
      i -= 1
    }
  }

  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class C640B(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val t =ni()
    REP(t) { _ =>
      val n0 = ni()
      val n1 = ni()
      val n2 = ni()

      val sb = new StringBuilder
      if(n1 > 0) {
        REP(n1+1) { i =>
          if(i%2 == 0) sb.append("1")
          else sb.append("0")
        }
        sb.insert(1, (0 until n0 map(_ => '0')).mkString(""))
        sb.insert(0, (0 until n1 map(_ => '1')).mkString(""))
        out.println(sb.toString())
      } else {
        if(n0 > 0) 0 to n0 foreach(_ => sb.append("0"))
        if(n2 > 0) 0 to n2 foreach(_ => sb.append("1"))
        out.println(sb.toString())
      }
    }
  }
}


object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    new Main(out, new InputReader(System.in)).solve()
    out.flush()
  }

  private[this] val oj = System.getenv("ATCODER_DEBUG") == null
  @inline private final def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  @inline private final def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  @inline def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  @inline private final def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  @inline private final def debugDim(m: Array[Array[Int]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  @inline private final def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  @inline def debug(s: => String): Unit = DEBUG {
    System.err.println(s)
  }
  @inline private final def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }
  private def isDebug[A](debug: => A, online: => A): A = {
    if (oj) online else debug
  }

  class InputReader(val stream: InputStream) {
    private[this] val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()
    def nl(): Long = nextLong()
    def nc(): Char = nextChar()
    def ns(): String = next()
    def ns(n: Int): Array[Char] = ns().toCharArray
    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }
    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }
    def nal(n: Int): Array[Long] = map(n)(_ => nl())
    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }
  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }
  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }
  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Workspace {
  import Main._
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer
  import Workspace._

  // toIntとか+7とかするならvalにしろ
  final private[this] val MOD = 1000000007

  def solve(): Unit = {
    REP(ni()) { _ =>
      val x, y = ni()
      val ok = y <= x ||
        x == 2 && y == 3 ||
        x >= 4
      if (ok) out.println("YES")
      else out.println("NO")
    }
  }
}

object B1257 {

  import IO._
  import collection.{mutable => cu}
  import scala.collection.mutable.ArrayBuffer

  def main(args: Array[String]): Unit = {
    var t = readInt
    while (t > 0) {
      val Array(x, y) = readInts(2)
      val res = if (x == 1) {
        if (y == 1)
          "YES"
        else
          "NO"
      } else if (x == 2) {
        if (Array(1, 2, 3).contains(y))
          "YES"
        else
          "NO"
      } else if (x == 3) {
        if (Array(1, 2, 3).contains(y))
          "YES"
        else
          "NO"
      } else "YES"

      out.println(res)
      t -= 1
    }
    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))
    }
  }

}


import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn

object B {
  def main(args: Array[String]): Unit = {
    val s = StdIn.readLine
    val seq = s.to[ArrayBuffer]
    val n = StdIn.readInt
    for (_ <- 1 to n) {
      var Array(l, r, k) = StdIn.readLine.split(" ").map(_.toInt)
      val len = r - l + 1
      k %= len
      r -= 1
      l -= 1
      val nseq = new ArrayBuffer[Char]
      for (i <- 0 to r-l) {
        nseq += seq(l + (i - k + len) % len)
      }
      for (i <- l to r) {
        seq(i) = nseq(i - l)
      }
    }
    println(seq.mkString)
  }
}

import scala.io.StdIn

object B {
  def main(args: Array[String]): Unit = {
    val seq = StdIn.readLine.toCharArray
    val n = StdIn.readInt
    (1 to n).foreach { _ =>
      var Array(l, r, k) = StdIn.readLine.split(" ").map(_.toInt)
      val len = r - l + 1
      k %= len; r -= 1; l -= 1
      val tmp = Array.ofDim[Char](len)
      tmp.indices.foreach { i => tmp(i) = seq(l + (i - k + len) % len) }
      tmp.indices.foreach { i => seq(i+l) = tmp(i) }
    }
    println(seq.mkString)
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val str = in.next().toCharArray
  val m = in.next().toInt
  (1 to m).foreach { _ =>
    val Array(l, r, k) = in.next().split(' ').map(_.toInt)
    val distance = r - l + 1
    val leftover = k % distance
    val temp = Array.ofDim[Char](distance)
    (0 until distance).foreach { i =>
      temp((i + k) % distance) = str(i + l - 1)
    }
    temp.indices.foreach(i => str(i + l - 1) = temp(i))
  }
  println(str.mkString(""))

}

object B598 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val in = read.toCharArray
    val Array(m) = readInts(1)
    for(_ <- 0 until m) {
      var Array(l, r, k) = readInts(3)
      k %= (r-l+1)
      l -= 1
      val temp = in.slice(l, r)
      val left = temp.takeRight(k).clone()
      val right = temp.take(r-l-k).clone()
      for(i <- 0 until k){
        in(l+i) = left(i)
      }
      for(i <- 0 until r-l-k){
        in(l+k+i) = right(i)
      }
    }
    println(in.mkString(""))
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))

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

}

import java.util.Scanner

/**
 * Created by enxhell on 11/25/15.
 */
object StringShift {

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

  def mod(v: Long, m: Int)  = {
    if(v >= 0){
      v % m
    }else if((-v) % m == 0) {
      0l
    }else{
        m - ((-v) % m)
    }
  }

  def processQuery(l: Int, r: Int, k: Int, str: Array[Char]) = {
//    println(l,r,k)
//    println(gcd(k,r-l+1))
    for(i <- 0 until gcd(k,r-l+1)){
      val tmp = str(i+l)
      var j : Long = i
      while(mod(j-k,r-l+1)!=i){
//        println(j,mod(j,r-l+1),mod(j-k, r-l+1))
        str((mod(j, r-l+1)+l).toInt) = str((mod(j-k, r-l+1)+l).toInt)
        j -= k
      }
      str((mod(j, (r-l+1))+l).toInt) = tmp
    }
  }

  def main(args: Array[String]): Unit = {
    val scanner = new Scanner(System.in)
    val str = scanner.next().toCharArray
    scanner.nextLine()

    val n = scanner.nextInt()
    (1 to n).foreach(x => processQuery(scanner.nextInt()-1, scanner.nextInt()-1, scanner.nextInt(), str))

    println(str.foldLeft("")((r,c)=> r+c))

  }
}

import java.util.Scanner

/**
 * Created by enxhell on 11/25/15.
 */
object StringShift {

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

  def mod(v: Int, m: Int) = {
    if(v >= 0){
      v % m
    }else if((-v) % m == 0) {
      0
    }else{
        m - ((-v) % m)
    }
  }

  def processQuery(l: Int, r: Int, k: Int, str: Array[Char]) = {
//    println(l,r,k)
//    println(gcd(k,r-l+1))
    for(i <- 0 until gcd(k,r-l+1)){
      val tmp = str(i+l)
      var j = i
      while(mod(j-k,r-l+1)!=i){
//        println(j,mod(j,r-l+1),mod(j-k, r-l+1))
        str(mod(j, r-l+1)+l) = str(mod(j-k, r-l+1)+l)
        j -= k
      }
      str(mod(j, (r-l+1))+l) = tmp
    }
  }

  def main(args: Array[String]): Unit = {
    val scanner = new Scanner(System.in)
    val str = scanner.next().toCharArray
    scanner.nextLine()

    val n = scanner.nextInt()
    (1 to n).foreach(x => processQuery(scanner.nextInt()-1, scanner.nextInt()-1, scanner.nextInt(), str))

    println(str.foldLeft("")((r,c)=> r+c))

  }
}

import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn

object B {
  def main(args: Array[String]): Unit = {
    val s = StdIn.readLine
    val seq = s.to[ArrayBuffer]
    val n = StdIn.readInt
    for (j <- 1 to n) {
      var Array(l, r, k) = StdIn.readLine.split(" ").map(_.toInt)
      val len = r - l + 1
      k %= len
      r -= 1
      l -= 1
      val nseq = new ArrayBuffer[Char]
      for (i <- l to r) {
        nseq += seq((i - k + len) % len)
      }
      for (i <- l to r) {
        seq(i) = nseq(i - l)
      }
    }
    println(seq.mkString)
  }
}


object C659 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    var Array(n, m) = readInts(2)
    val a = Array(0) ++ readInts(n).sorted
    val res = cu.ArrayBuffer.empty[Int]

    var curr = 0L
    var max = a.max + 1
    for(i <- 1 to n if m > 0) {
      if(a(i) > a(i-1)+1) {
        var x = a(i-1)+1
        while(x < a(i) && curr + x <= m) {
          res.append(x)
          m -= x
          x += 1
        }
      }
    }
    while(max + curr <= m) {
      res.append(max)
      m -= max
      max += 1
    }
    println(res.length)
    println(res.mkString(" "))
  }

  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 Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._

object _659C extends CodeForcesApp {
  override def apply(io: IO) = {
    var n, m = io[Int]
    val has = io[Set, Int](n)
    var ans = Vector.empty[Int]

    var t = 1
    while(m >= t) {
      if(!has(t)) {
        ans = ans :+ t
        m -= t
      }
      t += 1
    }

    io.+=(ans.length).appendNewLine().+=(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 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 = t.head.ensuring(t.size == 1)
    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 sum[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    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
  }
  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 PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_._1).mapValues(_._2)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_._1).mapValues(_.map(_._2).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 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
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
  }
  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)
    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(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[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  val mod: Int = (1e9 + 7).toInt
  val newLine: String = "\n"
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

class IO(in: BufferedReader, out: BufferedWriter) extends PrintWriter(out, true) with Iterator[String] {
  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 read: IO.Read[A]): A = read.apply(this)
  def apply[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(apply).to[C]

  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

  def +=[A](x: A)(implicit write: IO.Write[A]): this.type = {
    write(this)(x)
    this
  }
  def appendNewLine(): this.type = {
    println()
    this
  }

  override def print(obj: String) = {
    if (isNewLine) isNewLine = false else super.print(separator)
    super.print(obj)
  }
  override def println() = if (!isNewLine) {
    super.println()
    isNewLine = true
  }
  override def close() = {
    flush()
    in.close()
    super.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[C, A](r[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val boolean                                      : Read[Boolean]      = string.map(_.toBoolean)
    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[A], r[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r[A], r[B], r[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r[A], r[B], r[C], r[D]))
  }
  trait Write[-A] {
    def apply(out: PrintWriter)(x: A): Unit
  }
  trait DefaultWrite {
    implicit def any[A]: Write[A] = Write(_.toString)
  }
  object Write extends DefaultWrite {
    def apply[A](f: A => String) = new Write[A] {
      override def apply(out: PrintWriter)(x: A) = out.print(f(x))
    }
    implicit val boolean: Write[Boolean] = Write(b => if (b) "YES" else "NO")
    implicit def tuple2[A, B]: Write[(A, B)] = Write {case (a, b) => s"$a $b"}
    implicit def iterable[A](implicit write: Write[A]): Write[Traversable[A]] = new Write[Traversable[A]] {
      override def apply(out: PrintWriter)(xs: Traversable[A]) = {
        xs foreach write(out)
        out.println()
      }
    }
  }
}

import scala.io.StdIn
import scala.collection.mutable.ListBuffer

object Main {
  def main(args: Array[String]) {
    val (n, m) = StdIn.readLine.split(" ").map(_.toInt) match {
      case xy: Array[Int] => (xy(0), xy(1))
    }
    val a = StdIn.readLine.split(" ").map(_.toInt).toSet
    var picks = new ListBuffer[Int]()
    var cost = 0
    var i = 1
    while (cost <= m) {
      // println(i, cost)
      if (!a.contains(i)) { // pick
        picks.append(i)
        cost += i
      }
      i += 1
    }
    val ans = picks.init.toList
    println(ans.length)
    println(ans.mkString(" "))
  }

}

import scala.collection.mutable.ListBuffer

object E {
  def main(args: Array[String]) {
    var Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val a = scala.io.StdIn.readLine.split(" ").map(_.toInt).sorted
    var k = 1
    val res = ListBuffer[Int]()
    var t = a(0)
    var i = 0
    while (k <= m){
      if (k != t){
        res += k
        m -= k
      } else {
        i += 1
        if (i < a.length){
          t = a(i)
        }
      }
      k += 1
    }
    val rr = res.result()
    println(rr.length)
    println(rr.mkString(" "))
  }
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  var Array(n, m) = in.next().split(' ').map(_.toInt)
  val data = in.next().split(' ').map(_.toInt).toSet
  var result = List.empty[Int]
  var i = 1
  while (m >= i) {
    if (!data.contains(i)) {
      result ::= i
      m -= i
    }
    i += 1
  }
  println(result.length)
  println(result.mkString(" "))
}

import scala.collection.mutable.ListBuffer

object E {
  def main(args: Array[String]) {
    var Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val a = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    var suma = a.sum
    var k = 1
    val res = ListBuffer[Int]()
    var t = a(0)
    var i = 0
    while (k <= m){
      if (k != t){
        res += k
        m -= k
      } else {
        i += 1
        if (i < a.length){
          t = a(i)
        }
      }
      k += 1
    }
    val rr = res.result()
    println(rr.length)
    println(rr.mkString(" "))
  }
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  var Array(n, m) = in.next().split(' ').map(_.toInt)
  val data = in.next().split(' ').map(_.toInt).toSet
  var result = List.empty[Int]
  var i = 1
  while (m >= i) {
    if (!data.contains(i)) {
      result ::= i
      m -= i
    }
    i += 1
  }
  println(result.mkString(" "))
}

object C659 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    var Array(n, m) = readInts(2)
    val a = Array(0) ++ readInts(n).sorted
    val res = cu.ArrayBuffer.empty[Int]

    var curr = 0L
    var max = a.max + 1
    for(i <- 1 until n if m > 0) {
      if(a(i) > a(i-1)+1) {
        var x = a(i-1)+1
        while(x < a(i) && curr + x <= m) {
          res.append(x)
          m -= x
          x += 1
        }
      }
    }
    while(max + curr <= m) {
      res.append(max)
      m -= max
      max += 1
    }
    println(res.length)
    println(res.mkString(" "))
  }

  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.math.min
import scala.math.max
import scala.util.control.Breaks._

import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.util.StringTokenizer

object A{
	def main(args: Array[String]) = {
		var br = new BufferedReader(new InputStreamReader(System.in));
        	var a = br.readLine().split(" ")
		var n: Int = a(0).toInt
		var x: Int = a(1).toInt
		var y: Int = a(2).toInt
		var b = br.readLine().split(" ")
		var c: Array[Int] = new Array[Int](n)
		var i = 0
		for(i <- 0 to n-1)
		{
			c(i) = b(i).toInt
		}
		var ans: Int = -1
		for(i <- 0 to n-1)
		{
			var f: Int = 0
			var j: Int = 0
			for(j <- max(0,i-x) to min(i+y,n-1) )
			{
				if(j!=i && c(i)>=c(j))
					f=1
			}
			if(f==0)
			{
				if(ans equals -1)
					ans = i
			}
		}
		println(ans+1)
	}
}

object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    new Main(out, new InputReader(System.in)).solve()
    out.flush()
  }

  private val oj = System.getenv("ATCODER_DEBUG") == null
  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  def debugDim(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  def debug(s: => String): Unit = DEBUG {
    System.err.println(s)
  }
  def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()
    def nl(): Long = nextLong()
    def nc(): Char = nextChar()
    def ns(): String = next()
    def ns(n: Int): Array[Char] = ns().toCharArray
    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }
    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }
    def nal(n: Int): Array[Long] = map(n)(_ => nl())
    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }
  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from) { i =>
      f(i)
    }
  }
  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }
  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer

  // toIntとか+7とかするならvalにしろ
  @inline private def MOD = 1000000007

  def solve(): Unit = {
    val N, X, Y = ni()
    val A = na(N)
    REP(N) { i =>
      var ok = true
      REP(X, 1) { j =>
        if (i - j >= 0) {
          ok &&= A(i) < A(i - j)
        }
      }
      REP(Y, 1) { j =>
        if (i + j < N) {
          ok &&= A(i) < A(i + j)
        }
      }
      if (ok) {
        out.println(i + 1)
        return
      }
    }
  }
}

object _1199A extends CodeForcesApp {
  import annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._, Math._

  override def apply(io: IO): io.type = {
    val n, x, y = io.read[Int]
    val as = io.read[Vector, Int](n)

    val ans = as.indices find {i =>
      val a = as(i)
      (max(i - x, 0) until i).forall(j => a < as(j)) &&
      ((i+1) to min(i + y, n - 1)).forall(j => a < as(j))
    }

    io.write(ans.get+1)
  }
}
/****************************[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()
}
/***********************************[Scala I/O]*********************************************/
import java.io._, java.util.StringTokenizer
import scala.collection.generic.CanBuild

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()
    tokenizers.headOption
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: CanBuild[A, C[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 writeLines(obj: Traversable[Any]): this.type = writeAll(obj, separator = "\n")
  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: CanBuild[A, C[A]]) : Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                                   : Read[String]       = new Read(_.next())
    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 C extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(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)) }

  val Array(n, k) = readInts(2)
  val rooms = readLine

  var min = Int.MaxValue
  var left = 0

  while (rooms(left) == '1') left += 1
  var right = left
  var mid = left
  var cnt = 0

  while (cnt < k) {
    right += 1
    if (rooms(right) == '0') cnt += 1
  }

  def toLeft = mid - left
  def toRight = right - mid

  while (toLeft < toRight) {
    mid += 1
    if (rooms(mid) == '0') min = math.min(min, math.max(toLeft, toRight))
  }
  while (mid < n && rooms(mid) == '1') mid += 1

  while (right < n) {
    if (rooms(mid) == '0') min = math.min(min, math.max(toLeft, toRight))
    right += 1
    while (right < n && rooms(right) == '1') right += 1
    if (right < n) {
      left += 1
      while (rooms(left) == '1') left += 1
      if (rooms(mid) == '0') min = math.min(min, math.max(toLeft, toRight))
      while (toLeft < toRight) {
        mid += 1
        if (rooms(mid) == '0') min = math.min(min, math.max(toLeft, toRight))
      }
      while (mid < n && rooms(mid) == '1') mid += 1
    }
  }

  if (rooms(mid) == '0') min = math.min(min, math.max(toLeft, toRight))

  println(min)
}

object E {
  def main(args: Array[String]) {
    val Array(n, k) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val hotel = scala.io.StdIn.readLine.zipWithIndex
    val rooms = hotel.filter(_._1 == '0').map(_._2)
    var s = 0
    var e = k
    var x1 = 0
    var x2 = 1
    var zeros = 0
    var mmin = 100000
    while (s < rooms.length - k){
      while (!((2*rooms(x1) < rooms(s)+rooms(e)) && (2*rooms(x2) >= rooms(s)+rooms(e)))){
        x1 += 1
        x2 += 1
      }
      if ((rooms(e) - rooms(x1)) < mmin){
        mmin = rooms(e)-rooms(x1)
      }
      if ((rooms(x2) - rooms(s)) < mmin){
        mmin = rooms(x2) - rooms(s)
      }
      e += 1
      s += 1
    }
    println(mmin)
  }
}

import scala.collection._

object C extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(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)) }

  val Array(n, k) = readInts(2)
  val rooms = readLine

  var min = Int.MaxValue
  var left = 0

  while (rooms(left) == '1') left += 1
  var right = left
  var mid = left
  var cnt = 0

  while (cnt < k) {
    right += 1
    if (rooms(right) == '0') cnt += 1
  }

  def toLeft = mid - left
  def toRight = right - mid

  while (toLeft < toRight || rooms(mid) == '1') mid += 1

  while (right < n) {
    if (rooms(mid) == '0') min = math.min(min, math.max(toLeft, toRight))
    right += 1
    while (right < n && rooms(right) == '1') right += 1
    if (right < n) {
      left += 1
      if (rooms(mid) == '0') while (rooms(left) == '1') left += 1
      min = math.min(min, math.max(toLeft, toRight))
      while (toLeft < toRight) {
        mid += 1
        if (rooms(mid) == '0') min = math.min(min, math.max(toLeft, toRight))
      }
    }
  }

  if (rooms(mid) == '0') min = math.min(min, math.max(toLeft, toRight))

  println(min)
}

import scala.collection._

object C extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(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)) }

  val Array(n, k) = readInts(2)
  val rooms = readLine

  var min = Int.MaxValue
  var left = 0

  while (rooms(left) == '1') left += 1
  var right = left
  var mid = left
  var cnt = 0

  while (cnt < k) {
    right += 1
    if (rooms(right) == '0') cnt += 1
  }

  def toLeft = mid - left
  def toRight = right - mid

  while (toLeft < toRight || rooms(mid) == '1') mid += 1

  while (right < n) {
    min = math.min(min, math.max(toLeft, toRight))
    right += 1
    while (right < n && rooms(right) == '1') right += 1
    if (right < n) {
      left += 1
      while (rooms(left) == '1') left += 1
      min = math.min(min, math.max(toLeft, toRight))
      while (toLeft < toRight || rooms(mid) == '1') mid += 1
    }
  }

  min = math.min(min, math.max(toLeft, toRight))

  println(min)
}

import scala.collection._

object C extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(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)) }

  val Array(n, k) = readInts(2)
  val rooms = readLine

  var min = Int.MaxValue
  var left = 0

  while (rooms(left) == '1') left += 1
  var right = left
  var mid = left
  var cnt = 0

  while (cnt < k) {
    right += 1
    if (rooms(right) == '0') cnt += 1
  }

  def toLeft = mid - left
  def toRight = right - mid

  while (toLeft < toRight || rooms(mid) == '1') mid += 1

  while (right < n) {
    if (rooms(mid) == '0') min = math.min(min, math.max(toLeft, toRight))
    right += 1
    while (right < n && rooms(right) == '1') right += 1
    if (right < n) {
      left += 1
      if (rooms(mid) == '0') while (rooms(left) == '1') left += 1
      min = math.min(min, math.max(toLeft, toRight))
      while (toLeft < toRight) {
        mid += 1
        if (rooms(mid) == '0') min = math.min(min, math.max(toLeft, toRight))
      }
      while (mid < n && rooms(mid) == '1') mid += 1
    }
  }

  if (rooms(mid) == '0') min = math.min(min, math.max(toLeft, toRight))

  println(min)
}


import java.util._
import java.io._

object B {

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

  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 solve: Int = {
    val n = nextInt
    val b = new Array[Int](n)
    var max = Int.MinValue
    var min = Int.MaxValue
    for (i <- 0 until n) {
      b(i) = nextInt
      max = Math.max(max, b(i))
      min = Math.min(min, b(i))
    }
    var maxN = 0
    var minN = 0
    out.print(Math.abs(max - min) + " ")
    for (i <- 0 until n) {
      if (b(i) == max) {
        maxN += 1
      }
      if (b(i) == min) {
        minN += 1
      }
    }
    if (max != min) {
      out.print(maxN.toLong * minN.toLong)
    } else {
      out.print((maxN.toLong * (maxN.toLong - 1)) / 2)
    }
    return 1
  }

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

import java.util.InputMismatchException
import java.io.InputStream

/**
 * Created by hama_du on 2014/08/24.
 */
object ProblemB extends App {
  val in = new InputReader(System.in)

  val n = in.nextInt()
  val f = (0 until n).map(_ => in.nextInt())
  val min = f.min
  val max = f.max
  val minCount: Long = f.count(b => b == min)
  val maxCount: Long = f.count(b => b == max)
  if (min == max) {
    println(0 + " " + (1L * n * (n - 1) / 2))
  } else {
    println((max - min) + " " + minCount * maxCount)
  }
}

class InputReader(stream: InputStream) {
  val buf = new Array[Byte](1024)
  var curChar = 0
  var numChars = 0

  def next(): Int = {
    if (numChars == -1)
      throw new InputMismatchException();
    if (curChar >= numChars) {
      curChar = 0;
      numChars = stream.read(buf);
      if (numChars <= 0) {
        -1;
      }
    }
    val res = buf(curChar)
    curChar += 1
    res
  }

  def nextLong(): Long = {
    var c = next()
    while (isSpaceChar(c)) {
      c = next()
    }
    var sgn = 1
    if (c == '-') {
      sgn = -1
      c = next()
    }
    var res = 0L
    do {
      if (c < '0' || c > '9')
        throw new InputMismatchException()
      res *= 10
      res += c - '0'
      c = next()
    } while (!isSpaceChar(c))
    res * sgn
  }

  def nextInt(): Int = {
    nextLong.toInt
  }

  def isSpaceChar(c: Int) = {
    c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    io.StdIn.readLine()
    sol(io.StdIn.readLine().split(' ').map(Integer.parseInt(_)))
  }

  def sol(bs: Array[Int]): Unit = {
    def extrema(nums: List[Int]): (Int, Int, Int, Int) = {
      ((nums.head, 1, nums.head, 1) /: nums.tail) { (e, b) =>
        val _min = math.min(e._1, b)
        val _max = math.max(e._3, b)
        val minCount = if (_min != e._1) 1 else if (b == _min) e._2 + 1 else e._2
        val maxCount = if (_max != e._3) 1 else if (b == _max) e._4 + 1 else e._4
        (_min, minCount, _max, maxCount)
      }
    }
    extrema(bs.toList) match {
      case (x, y, z, w) =>
        println(s"${z-x} ${if (z == x) y.toLong * (y - 1) / 2  else y.toLong * w}")
    }
  }
}

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

/**
 * Created by arseny on 15.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 bs = Array.fill(n)(0L)
    (0 until n).foreach(i => bs(i) = nextLong)
    val sorted = bs.sorted
    val minBeauty = sorted(0)
    val maxBeauty = sorted(n - 1)
    var maxDiff = maxBeauty - minBeauty
    var minCount = 0L
    var maxCount = 0L
    while (minCount < n && sorted(minCount.toInt) == minBeauty) {
      minCount += 1L
    }
    while (maxCount < n && sorted(n - 1 - maxCount.toInt) == maxBeauty) {
      maxCount += 1L
    }
    val maxDiffCount = if(minBeauty == maxBeauty) n.toLong * (n.toLong - 1) / 2L else maxCount * minCount
    out.print(maxDiff + " " + maxDiffCount)
  }

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

object main extends App with fastIO {

  val Array(n) = readLine split(" ") map(_.toLong)
  var a = readLine split(" ") map(_.toInt)

  val (max, min) = (a.max, a.min)
  val res = if (max == min) n * (n - 1) / 2 else
    a.count(_ == min).toLong * a.count(_ == max).toLong

  println((max - min) + " " + res)
  flush
}

trait fastIO {
  import java.io._

  val isFile = false
  val input = "io.in"
  val output = "io.out"

  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))
  val in = new StreamTokenizer(bf)
  val out = new PrintWriter(if(isFile) new FileWriter(output) else new OutputStreamWriter(System.out))

  def next: String = {
    in.ordinaryChars('0', '9')
    in.wordChars('0', '9')
    in.nextToken
    in.sval
  }

  def nextInt: Int = {
    in.nextToken
    in.nval.toInt
  }

  def nextLong:Long ={
    in.nextToken
    in.nval.toLong
  }

  def nextDouble: Double = {
    in.nextToken
    in.nval.toDouble
  }

  def readLine: String = bf.readLine()
  def println(o:Any) = out.println(o)
  def print(o:Any) = out.print(o)
  def printf(s:String,o:Any*) = out.printf(s,o)
  def flush = out.flush
}

import java.util.StringTokenizer

object _459B extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val a = (1 to n).map(i => next.toInt)
  val max = a.max
  val min = a.min
  if (max == min) {
    println("%d %d".format(0, 1L * a.length * (a.length - 1) / 2))
  } else {
    println("%d %d".format(max - min, 1L * a.count(i => i == max) * a.count(i => i == min)))
  }
}

/**
 * Created by lurker on 2014. 8. 15..
 */
object CF261_2 extends App {
  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)

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

  val Array(n) = readInts(1)
  val b = readInts(n.toInt)

  val maxb = b.max
  val minb = b.min

  val nmax:Long = b.filter(_ == maxb).length
  val nmin:Long = b.filter(_ == minb).length

  val r:Long = maxb - minb
  val result = nmax * nmin

  val rcases:Long = if(maxb != minb){
    nmax * nmin
  } else {
    nmax * (nmax - 1) / 2L
  }
  println(s"$r $rcases")
}

object B459 {
  @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 = readInts(n)

    val max = input.max
    val min = input.min

    val ways = if(min == max) {
      val count = input.count(_ == max).toLong
      (count*(count-1))/2L
    } else {
      input.count(_ == max).toLong * input.count(_ == min).toLong
    }

    println(s"${max-min} $ways")
  }
}

/**
 * @author pvasilyev
 * @since 05 May 2016
 */
object B459 extends App {

  val n: Int = scala.io.StdIn.readInt()
  val a: Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  var min = Integer.MAX_VALUE
  var minCount = 1
  var max = 0
  var maxCount = 1
  a.foreach(b => {
    if (min > b) {
      min = b
      minCount = 1
    } else if (min == b) {
      minCount += 1
    }
    if (max < b) {
      max = b
      maxCount = 1
    } else if (max == b) {
      maxCount += 1
    }
  })

  print(max - min)
  print(" ")
  if (max == min) {
    println(1L * maxCount * (maxCount - 1) / 2)
  } else {
    println(1L * maxCount * minCount)
  }

}

import java.util._
import java.io._

object B {

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

  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 solve: Int = {
    val n = nextInt
    val b = new Array[Long](n)
    var max: Long = Long.MinValue
    var min: Long = Long.MaxValue
    for (i <- 0 until n) {
      b(i) = nextLong
      max = Math.max(max, b(i))
      min = Math.min(min, b(i))
    }
    var maxN: Long = 0L
    var minN: Long = 0L
    out.print(Math.abs(max - min) + " ")
    for (i <- 0 until n) {
      if (b(i) == max) {
        maxN += 1
      }
      if (b(i) == min) {
        minN += 1
      }
    }
    if (max != min) {
      out.print(maxN * minN * 1L)
    } else {
      out.print((maxN * 1L * (maxN * 1L - 1L)) / 2L)
    }
    return 1
  }

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

import scala.io.StdIn
import scala.util.Sorting

object PashmakFlowers {

  def pashmakFlowers(inputA:Array[Int]):String = {
    Sorting.quickSort(inputA)
    val cnt:Int = inputA.length
    if (cnt>1){
      val small = inputA(0);
      val large = inputA(cnt-1)
      if (small == large){
        0 + " " + cnt.toLong*(cnt-1).toLong/2
      }else{
        var sc=0
        while(inputA(sc)==small){
          sc = sc + 1
        }
        var lc=0
        while(inputA(cnt-1-lc)==large){
          lc = lc + 1
        }
        val comb:Long = sc.toLong * lc.toLong
        large-small + " " + comb
      }
    }else{
      "Error Input: Input has less then 2 numbers"
    }
  }

  def pashmakFlowers(num:Int, ln2:String):String = {
    val input = ln2.split(" ");
    val inputA:Array[Int] = new Array(num);
    for (a<-1 to num){
      inputA(a-1)=input(a-1).toInt
    }
    pashmakFlowers(inputA)
  }
  def main(args: Array[String]) {
    val ln1:String = StdIn.readLine()
    val ln2:String = StdIn.readLine()
    val num = ln1.toInt
    println(pashmakFlowers(num, ln2))
  }

}

/**
 * Created by lurker on 2014. 8. 15..
 */
object CF261_2 extends App {
  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)

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

  val Array(n) = readInts(1)
  val b = readInts(n.toInt)

  val maxb = b.max
  val minb = b.min

  val nmax = b.filter(_ == maxb).length
  val nmin = b.filter(_ == minb).length

  val r = maxb - minb
  val rcases = if(maxb != minb){
    nmax * nmin
  } else {
    nmax * (nmax - 1) / 2
  }
  println(s"$r $rcases")
}

/**
 * Created by lurker on 2014. 8. 15..
 */
object CF261_2 extends App {
  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)

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

  val Array(n) = readInts(1)
  val b = readInts(n.toInt)

  val maxb = b.max
  val minb = b.min

  val nmax = b.filter(_ == maxb).length
  val nmin = b.filter(_ == minb).length

  val r:Long = maxb - minb
  val result = nmax * nmin

  if(n==200000){
    println(s"$maxb $minb $nmax $nmin $r $result")
    println(result)
  }

  val rcases:Long = if(maxb != minb){
    nmax * nmin
  } else {
    nmax * (nmax - 1) / 2L
  }
  println(s"$r $rcases")
}

/**
 * Created by lurker on 2014. 8. 15..
 */
object CF261_2 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) = readInts(1)
  val b = readInts(n)

  val maxb = b.max
  val minb = b.min

  val nmax = b.filter(_ == maxb).length
  val nmin = b.filter(_ == minb).length

  val r = maxb - minb
  val rcases = nmax * nmin
  println(s"$r $rcases")
}

/**
 * Created by lurker on 2014. 8. 15..
 */
object CF261_2 extends App {
  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)

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

  val Array(n) = readInts(1)
  val b = readInts(n.toInt)

  val maxb = b.max
  val minb = b.min

  val nmax = b.filter(_ == maxb).length
  val nmin = b.filter(_ == minb).length

  val r:Long = maxb - minb

  val rcases:Long = if(maxb != minb){
    nmax * nmin
  } else {
    nmax * (nmax - 1) / 2L
  }
  println(s"$r $rcases")
}

/**
 * Created by lurker on 2014. 8. 15..
 */
object CF261_2 extends App {
  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)

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

  val Array(n) = readInts(1)
  val b = readInts(n.toInt)

  val maxb = b.max
  val minb = b.min

  val nmax = b.filter(_ == maxb).length
  val nmin = b.filter(_ == minb).length

  val r:Long = maxb - minb
  if(n==200000){
    println(s"$maxb $minb $nmax $nmin $r")
  }

  val rcases:Long = if(maxb != minb){
    nmax * nmin
  } else {
    nmax * (nmax - 1) / 2L
  }
  println(s"$r $rcases")
}

object B459 {
  @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 = readInts(n)

    val max = input.max
    val min = input.min

    val ways = if(min == max) {
      val count = input.count(_ == max).toLong
      (count*count-1)/2L
    } else {
      input.count(_ == max).toLong * input.count(_ == min).toLong
    }

    println(s"${max-min} $ways")
  }
}

object B459 {
  @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 = readInts(n)

    val max = input.max
    val min = input.min

    val ways = input.count(_ == max) * input.count(_ == min)

    println(s"${max-min} $ways")
  }
}

object B459 {
  @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 = readInts(n)

    val max = input.max
    val min = input.min

    val ways = input.count(_ == max).toLong * input.count(_ == min).toLong

    println(s"${max-min} $ways")
  }
}

/**
 * @author pvasilyev
 * @since 05 May 2016
 */
object B459 extends App {

  val n: Int = scala.io.StdIn.readInt()
  val a: Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  var min = Integer.MAX_VALUE
  var minCount = 1
  var max = 0
  var maxCount = 1
  a.foreach(b => {
    if (min > b) {
      min = b
      minCount = 1
    } else if (min == b) {
      minCount += 1
    }
    if (max < b) {
      max = b
      maxCount = 1
    } else if (max == b) {
      maxCount += 1
    }
  })

  print(max - min)
  print(" ")
  println(1L * maxCount * minCount)

}

/**
 * @author pvasilyev
 * @since 05 May 2016
 */
object B459 extends App {

  val n: Int = scala.io.StdIn.readInt()
  val a: Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  var min = Integer.MAX_VALUE
  var minCount = 1
  var max = 0
  var maxCount = 1
  a.foreach(b => {
    if (min > b) {
      min = b
      minCount = 1
    } else if (min == b) {
      minCount += 1
    }
    if (max < b) {
      max = b
      maxCount = 1
    } else if (max == b) {
      maxCount += 1
    }
  })

  print(max - min)
  print(" ")
  println(maxCount * minCount)

}

import java.util._
import java.io._

object B {

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

  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 solve: Int = {
    val n = nextInt
    val b = new Array[Int](n)
    var max = Int.MinValue
    var min = Int.MaxValue
    for (i <- 0 until n) {
      b(i) = nextInt
      max = Math.max(max, b(i))
      min = Math.min(min, b(i))
    }
    var maxN = 0
    var minN = 0
    out.print((max - min) + " ")
    for (i <- 0 until n) {
      if (b(i) == max) {
        maxN += 1
      }
      if (b(i) == min) {
        minN += 1
      }
    }
    if (max - min > 0) {
      out.print(maxN * minN * 1L)
    } else {
      out.print((maxN * 1L * (maxN * 1L - 1L)) / 2L)
    }
    return 1
  }

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

import java.util._
import java.io._

object B {

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

  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 solve: Int = {
    val n = nextInt
    val b = new Array[Int](n)
    var max = Int.MinValue
    var min = Int.MaxValue
    for (i <- 0 until n) {
      b(i) = nextInt
      max = Math.max(max, b(i))
      min = Math.min(min, b(i))
    }
    var maxN = 0
    var minN = 0
    out.print(Math.abs(max - min) + " ")
    for (i <- 0 until n) {
      if (b(i) == max) {
        maxN += 1
      }
      if (b(i) == min) {
        minN += 1
      }
    }
    if (max != min) {
      out.print(maxN * minN * 1L)
    } else {
      out.print((maxN * 1L * (maxN * 1L - 1L)) / 2L)
    }
    return 1
  }

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

import java.util._
import java.io._

object B {

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

  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 solve: Int = {
    val n = nextInt
    val b = new Array[Int](n)
    var max = Int.MinValue
    var min = Int.MaxValue
    for (i <- 0 until n) {
      b(i) = nextInt
      max = Math.max(max, b(i))
      min = Math.min(min, b(i))
    }
    var maxN = 0
    var minN = 0
    out.print((max - min) + " ")
    for (i <- 0 until n) {
      if (b(i) == max) {
        maxN += 1
      }
      if (b(i) == min) {
        minN += 1
      }
    }
    if (max - min > 0) {
      out.print(maxN * minN * 1L)
    } else {
      out.print(maxN * 1L * (maxN - 1) / 2L)
    }
    return 1
  }

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

import scala.io.StdIn
import scala.util.Sorting

object PashmakFlowers {

  def pashmakFlowers(inputA:Array[Int]):String = {
    Sorting.quickSort(inputA)
    val cnt:Int = inputA.length
    if (cnt>1){
      val small = inputA(0);
      val large = inputA(cnt-1)
      if (small == large){
        0 + " " + cnt*(cnt-1)/2
      }else{
        var sc=0
        while(inputA(sc)==small){
          sc = sc + 1
        }
        var lc=0
        while(inputA(cnt-1-lc)==large){
          lc = lc + 1
        }
        large-small + " " + sc*lc
      }
    }else{
      "Error Input: Input has less then 2 numbers"
    }
  }

  def main(args: Array[String]) {
    val ln1:String = StdIn.readLine()
    val ln2:String = StdIn.readLine()
    val num = ln1.toInt
    val input = ln2.split(" ");
    val inputA:Array[Int] = new Array(num);
    for (a<-1 to num){
      inputA(a-1)=input(a-1).toInt
    }
    println(pashmakFlowers(inputA))
  }

}

import scala.io.StdIn
import scala.util.Sorting

object PashmakFlowers {

  def pashmakFlowers(inputA:Array[Int]):String = {
    Sorting.quickSort(inputA)
    val cnt:Int = inputA.length
    if (cnt>1){
      val small = inputA(0);
      val large = inputA(cnt-1)
      if (small == large){
        0 + " " + cnt*(cnt-1)/2
      }else{
        var sc=0
        while(inputA(sc)==small){
          sc = sc + 1
        }
        var lc=0
        while(inputA(cnt-1-lc)==large){
          lc = lc + 1
        }
        val comb:Long = sc.toLong * lc.toLong
        large-small + " " + comb
      }
    }else{
      "Error Input: Input has less then 2 numbers"
    }
  }

  def pashmakFlowers(num:Int, ln2:String):String = {
    val input = ln2.split(" ");
    val inputA:Array[Int] = new Array(num);
    for (a<-1 to num){
      inputA(a-1)=input(a-1).toInt
    }
    pashmakFlowers(inputA)
  }
  def main(args: Array[String]) {
    val ln1:String = StdIn.readLine()
    val ln2:String = StdIn.readLine()
    val num = ln1.toInt
    println(pashmakFlowers(num, ln2))
  }

}

object Main {
  def main(args: Array[String]): Unit = {
    io.StdIn.readLine()
    sol(io.StdIn.readLine().split(' ').map(Integer.parseInt(_)))
  }

  def sol(bs: Array[Int]): Unit = {
    def extrema(nums: List[Int]): (Int, Int, Int, Int) = {
      ((nums.head, 1, nums.head, 1) /: nums.tail) { (e, b) =>
        val _min = math.min(e._1, b)
        val _max = math.max(e._3, b)
        val minCount = if (_min != e._1) 1 else if (b == _min) e._2 + 1 else e._2
        val maxCount = if (_max != e._3) 1 else if (b == _max) e._4 + 1 else e._4
        (_min, minCount, _max, maxCount)
      }
    }
    extrema(bs.toList) match {
      case (x, y, z, w) =>
        println(s"${z-x} ${if (z == x) (if (y == 2) 1 else y.toLong*y/2) else y.toLong * w}")
    }
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    io.StdIn.readLine()
    sol(io.StdIn.readLine().split(' ').map(Integer.parseInt(_)))
  }

  def sol(bs: Array[Int]): Unit = {
    def extrema(nums: List[Int]): (Int, Int, Int, Int) = {
      ((nums.head, 1, nums.head, 1) /: nums.tail) { (e, b) =>
        val _min = math.min(e._1, b)
        val _max = math.max(e._3, b)
        val minCount = if (_min != e._1) 1 else if (b == _min) e._2 + 1 else e._2
        val maxCount = if (_max != e._3) 1 else if (b == _max) e._4 + 1 else e._4
        (_min, minCount, _max, maxCount)
      }
    }
    extrema(bs.toList) match {
      case (x, y, z, w) =>
        println(s"${z-x} ${if (z == x) (if (y == 2) 1 else y) else y.toLong * w}")
    }
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    io.StdIn.readLine()
    sol(io.StdIn.readLine().split(' ').map(Integer.parseInt(_)))
  }

  def sol(bs: Array[Int]): Unit = {
    def extrema(nums: List[Int]): (Int, Int, Int, Int) = {
      ((nums.head, 1, nums.head, 1) /: nums.tail) { (e, b) =>
        val _min = math.min(e._1, b)
        val _max = math.max(e._3, b)
        val minCount = if (_min != e._1) 1 else if (b == _min) e._2 + 1 else e._2
        val maxCount = if (_max != e._3) 1 else if (b == _max) e._4 + 1 else e._4
        (_min, minCount, _max, maxCount)
      }
    }
    extrema(bs.toList) match {
      case (x,y,z,w) =>
        println(s"${z-x} ${y*w}")
    }
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    io.StdIn.readLine()
    sol(io.StdIn.readLine().split(' ').map(Integer.parseInt(_)))
  }

  def sol(bs: Array[Int]): Unit = {
    def extrema(nums: List[Int]): (Int, Int, Int, Int) = {
      ((nums.head, 1, nums.head, 1) /: nums.tail) { (e, b) =>
        val _min = math.min(e._1, b)
        val _max = math.max(e._3, b)
        val minCount = if (_min != e._1) 1 else if (b == _min) e._2 + 1 else e._2
        val maxCount = if (_max != e._3) 1 else if (b == _max) e._4 + 1 else e._4
        (_min, minCount, _max, maxCount)
      }
    }
    extrema(bs.toList) match {
      case (x,y,z,w) =>
        println(s"${z-x} ${y.toLong*w.toLong}")
    }
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    io.StdIn.readLine()
    sol(io.StdIn.readLine().split(' ').map(Integer.parseInt(_)))
  }

  def sol(bs: Array[Int]): Unit = {
    def extrema(nums: List[Int]): (Int, Int, Int, Int) = {
      ((nums.head, 1, nums.head, 1) /: nums.tail) { (e, b) =>
        val _min = math.min(e._1, b)
        val _max = math.max(e._3, b)
        val minCount = if (_min != e._1) 1 else if (b == _min) e._2 + 1 else e._2
        val maxCount = if (_max != e._3) 1 else if (b == _max) e._4 + 1 else e._4
        (_min, minCount, _max, maxCount)
      }
    }
    extrema(bs.toList) match {
      case (x, y, z, w) =>
        println(s"${z-x} ${if (z == x) y else y.toLong * w}")
    }
  }
}

object main extends App with fastIO {

  val Array(n) = readLine split(" ") map(_.toInt)
  var a = readLine split(" ") map(_.toInt)

  val (max, min) = (a.max, a.min)
  val res = if (max == min) n * (n - 1) / 2 else
    a.count(_ == min) * a.count(_ == max)

  println((max - min) + " " + res)
  flush
}

trait fastIO {
  import java.io._

  val isFile = false
  val input = "io.in"
  val output = "io.out"

  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))
  val in = new StreamTokenizer(bf)
  val out = new PrintWriter(if(isFile) new FileWriter(output) else new OutputStreamWriter(System.out))

  def next: String = {
    in.ordinaryChars('0', '9')
    in.wordChars('0', '9')
    in.nextToken
    in.sval
  }

  def nextInt: Int = {
    in.nextToken
    in.nval.toInt
  }

  def nextLong:Long ={
    in.nextToken
    in.nval.toLong
  }

  def nextDouble: Double = {
    in.nextToken
    in.nval.toDouble
  }

  def readLine: String = bf.readLine()
  def println(o:Any) = out.println(o)
  def print(o:Any) = out.print(o)
  def printf(s:String,o:Any*) = out.printf(s,o)
  def flush = out.flush
}


object HelloWorld {
    def main (args: Array[String]) {
      val N = readInt
      val first = readInt
      var pred = 7-first
      var i = 0;
      var res = true
      while (i < N) {
        var s = readLine
        val tokens = s.split(" ")
        val one = tokens(0).toInt
        val two = tokens(1).toInt
        if (!((one != pred) && (two != pred) && (7-one != pred) && (7-two != pred))) res = false
        i+=1;
      }
      if (res) println("YES") else println("NO")
    }
  }

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val top = in.next().toInt
  val Array(l, r) = in.next().split(' ').map(_.toInt)
  val res = (2 to n).foldLeft((7 - top, Set(l, r, 7 - l, 7 - r, top).size == 5)) {
    case ((s, false), _) => (s, false)
    case ((s, true), _) =>
      val Array(l, r) = in.next().split(' ').map(_.toInt)
      val set = Set(l, r, s, 7 - l, 7 - r)
      if (set.size < 5)
        (s, false)
      else {
        val nt = (1 to 6).find(i => !set.contains(i)).get
        (nt, true)
      }
  }
  if (res._2)
    println("YES")
  else
    println("NO")
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.collection.immutable.Queue
import scala.util.Random

object P225A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt // the number of dice in the tower
  val X = sc.nextInt // the number on the top of the tower
  val AB = List.fill(N, 2)(sc.nextInt) // two side long faces-es

  def solve(): Unit = {

    @tailrec
    def loop(acc: Int, dices: List[List[Int]]): Unit = {
      dices match {
        case Nil              => out.println("YES")
        case List(x, y) :: ds => {
          val known = acc :: List(x, y, 7 - x, 7 - y)
          val rest = List.range(1, 7) diff known
          rest match {
            case r :: Nil => loop(r, ds)
            case _        => out.println("NO")
          }
        }
      }
    }

    loop(X, AB)
  }

  solve
  out.close
}

import java.io._
import java.util.Locale
import scala.annotation.tailrec

object Easy {
  val reader = new BufferedReader(new InputStreamReader(System.in))
  def readInt = reader.readLine().toInt
  def readInts = reader.readLine().split(" ").map(_.toInt)
  def readLongs = reader.readLine().split(" ").map(_.toLong)
  def readLine = reader.readLine

  val n = readInt
  val x = readInt
  def ans = if((for(_ <- 1 to n) yield readInts.count(y => y == x || y == 7 - x)).sum == 0) "YES" else "NO"

  def main(a: Array[String]) {
    println(ans)
  }
}

object Main {
  def main(args: Array[String]) = {
    val n = readInt()
    val up = readInt()
    val a = (1 to n) map (_ => readLine() split (" ") map (_.toInt))
    val s = Set[Int]() ++ (1 to 6)

    var low = 7 - up
    val r = a.foldLeft(true) { (ac, a0) =>
      val next = s - (a0(0), 7 - a0(0), a0(1), 7 - a0(1), low)
      if (next.size == 1) {
        low = next.toList(0)
        ac
      } else {
        false
      }
    }
    if (r) println("YES")
    else println("NO")
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val top = in.next().toInt
  val Array(l, r) = in.next().split(' ').map(_.toInt)
  val res = (2 to n).foldLeft((7 - top, Set(l, r, 7 - l, 7 - r, top).size == 5)) {
    case ((s, false), _) => (s, false)
    case ((s, true), _) =>
      val Array(l, r) = in.next().split(' ').map(_.toInt)
      val set = Set(l, r, s, 7 - l, s - r)
      if (set.size < 5)
        (s, false)
      else {
        val nt = (1 to 6).find(i => !set.contains(i)).get
        (nt, true)
      }
  }
  if (res._2)
    println("YES")
  else
    println("NO")
}

object HelloWorld {
    def main (args: Array[String]) {
      val N = readInt
      val first = readInt
      var pred = 7-first
      var i = 0;
      var res = true
      while (i < N) {
        var s = readLine
        val tokens = s.split(" ")
        val one = tokens(0).toInt
        val two = tokens(1).toInt
        if (!(one != pred) && (two != pred) && (7-one != pred) && (7-two != pred)) res = false
        i+=1;
      }
      if (res) println("YES") else println("NO")
    }
  }


object main extends App with fastIO {

  var a = readLine split(" ") map(_.toInt)
  println(readLine.foldLeft(0)((s, c) => s + a(c - '1')))

  flush
}

trait fastIO {
  import java.io._

  val isFile = false
  val input = "io.in"
  val output = "io.out"

  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))
  val in = new StreamTokenizer(bf)
  val out = new PrintWriter(if(isFile) new FileWriter(output) else new OutputStreamWriter(System.out))

  def next: String = {
    in.ordinaryChars('0', '9')
    in.wordChars('0', '9')
    in.nextToken
    in.sval
  }

  def nextInt: Int = {
    in.nextToken
    in.nval.toInt
  }

  def nextLong:Long ={
    in.nextToken
    in.nval.toLong
  }

  def nextDouble: Double = {
    in.nextToken
    in.nval.toDouble
  }

  def readLine: String = bf.readLine()
  def println(o:Any) = out.println(o)
  def print(o:Any) = out.print(o)
  def printf(s:String,o:Any*) = out.printf(s,o)
  def flush = out.flush
}

object BlackSquareGame {
  def main(args: Array[String]): Unit = {
    val A = readLine.split(" ")
    val S = readLine
    var sum = 0
    S.foreach(c => {
      sum = sum + A(c.asDigit-1).toInt
    })
    println(sum)
  }

}

import java.util.StringTokenizer

object _431 extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val a = (0 until 4).map(i => next.toInt).toArray
  val s = next
  val ans = s.map(i => a(i - '0' - 1)).sum
  println(ans)
}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val call = in.next().split(" ").zipWithIndex.map {
    case(en, index) => (index + 1) -> en.toInt
  }.toMap
  println(in.next().map(t => call(t.asDigit)).sum)
}

//package codeblocks
import java.util.Scanner
object cf413A {
	def main(args : Array[String]) : Unit = {
	val scn = new Scanner(System.in)
	val caroli :List[Int] = {for(i <- 1 to 4 ) yield scn.nextInt}.toList
	val seq:List[Int] = scn.next.toList.map(_-'0')
	var sum =0
	seq.foreach(x=>sum+=caroli(x - 1))
	println(sum)

	}

//	def getResult(seq:List[Int],caroli:List[Int]):Int = {
//		val (head,tail) = seq.splitAt(4)
//		if(head.isEmpty) 0
//		else{
//
//			val place = getRightPlace(head,head.length)
//			if(place!=0)
//			{
//				val (shead,thead) = head splitAt place-1
//				caroli(place-1)+getResult(shead:::thead.tail:::tail,caroli)
//			}
//			else
//				0
//
//		}
//	}
//	def getRightPlace(xs:List[Int],n:Int ):Int = {
//		if(n == 0) 0
//
//		if(xs(n-1)==n) n
//		else getRightPlace(xs take n-1,n-1)
//
//	}

}

object B {

  def main(args: Array[String]): Unit = {
    var a = readLine.split(" ").map(_.toInt)
    var s = readLine
    var ans = 0;

    for (i <- 0 to s.length()-1)
    	if (s.charAt(i)=='1')
    		ans = ans + a(0)
    	else if (s.charAt(i)=='2')
    		ans = ans + a(1)
    	else if (s.charAt(i)=='3')
    		ans = ans + a(2)
    	else if (s.charAt(i)=='4')
    		ans = ans + a(3)
  println(ans)
  }

}

import java.util.Scanner

object ASquare extends App {

  val scanner = new Scanner(System.in)

  val cal = (0 until 4).map(i => scanner.nextInt())

  val in = scanner.next().map(_.toString.toInt)

  val res = in.foldLeft(0)((acc, i) => acc + cal(i - 1))

  println(res)

}

object A431 {
  @inline def read = scala.io.StdIn.readLine

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

  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 input = readInts(4)
    val strip = read
    println(strip.map(ch => input(ch - '1')).sum)
  }
}

import java.util.Scanner

/**
 * Created by hama_du on 2014/05/22.
 */
object ProblemA extends App {
  val in = new Scanner(System.in)
  val table = Array(in.nextInt, in.nextInt, in.nextInt, in.nextInt)
  val s = in.next().toCharArray.foldLeft(0)((a, b) => a + table(b-'1'))
  println(s)
}

import java.util.Scanner

/**
 * Created by Kuang.Ru on 14-9-19.
 */
object A431 extends App{
  val sc = new Scanner(System.in)
  val a1, a2, a3, a4 = sc.nextInt()
  val input = sc.next()

  println(input.toCharArray.map {
    case '1' => a1
    case '2' => a2
    case '3' => a3
    case '4' => a4
  }.sum)
}

object A {
  def main(args: Array[String]): Unit = {
    val a: Array[Int] = new Array[Int](4)
    val words:Array[String] = scala.io.StdIn.readLine().split(" ")
    for (i <- 0 to 3)
      a(i) = words(i).toInt
    val s = scala.io.StdIn.readLine()
    var res = 0
    val n = s.length()
    for (i <- 0 to n - 1) {
      val j = s.charAt(i).toInt - '1'
      res = res + a(j)
    }
    println(res)
  }
}

/**
 * Created by Amit on 5/21/2014.
 */
object Testing {
  def main (args: Array[String]) {
    val first = Console.readLine()
    val nums = first.split(" ")
    val str = Console.readLine()
    var count = 0
    for(c <- str){
      count += nums(c-49).toInt
    }
    println(count)
  }
}