All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi — a coordinate on the Ox axis. No two cities are located at a single point.Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.For each city calculate two values mini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city

The first line of the input contains integer n (2 ≤ n ≤ 105) — the number of cities in Lineland. The second line contains the sequence of n distinct integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.

Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.

// package c567.a
object Solution extends App {
  import scala.io.StdIn
  import scala.math.{min, max}
  val n = StdIn.readInt()
  val xs = StdIn.readLine().split(" ").map(_.toInt).toVector
  val first = xs.head
  val last = xs.last
  def m(i: Int, ai: Int): Unit = ()
  println(s"${xs.tail.head - first} ${last - first}")
  xs.zipWithIndex
    .slice(1, xs.length - 1)
    .foreach { case (a: Int, i: Int) ⇒
      println(s"${min(a - xs(i - 1), xs(i + 1) - a)} ${max(a - first, last - a)}")
    }
  println(s"${last - xs(xs.size - 2)} ${last - first}")
}

import scala.io.StdIn._

object Main extends App {
  val n = readInt()
  val LeftInf = 10L * Int.MinValue
  val RightInf = 10L * Int.MaxValue
  val a = LeftInf +: readLine().split(" ").map(_.toLong) :+ RightInf
  for (i <- 1 to n) {
    val max = (a(i) - a(1)) max (a(n) - a(i))
    val min = (a(i) - a(i - 1)) min (a(i + 1) - a(i))
    println(min + " " + max)
  }
}

import scala.io.StdIn._

object CF567A extends App {
  val n = readInt()
  val x = readLine().split(" ").map(_.toLong)

  for (i <- 0 to x.length - 1) {
    val max = Math.max(Math.abs(x(i) - x.head), Math.abs(x.last - x(i)))
    val min = Math.min(
      Math.abs(x(i) - x.lift(i - 1).getOrElse(Long.MinValue)),
      Math.abs(x.lift(i + 1).getOrElse(Long.MaxValue) - x(i))
    )
    println(min + " " + max)
  }
}

import java.util.Scanner
import Array._

object Codeforces extends App {
  val in = new Scanner(System.in)
  val n = in.nextInt()
  val x = ofDim[Long](n + 2)
  x(0) = (-1e18).toLong
  x(n + 1) = (1e18).toLong
  for (i <- 1 to n) {
    x(i) = in.nextLong()
  }
  for (i <- 1 to n) {
    var p = math.min(x(i) - x(i - 1), x(i + 1) - x(i))
    var q = math.max(x(i) - x(1), x(n) - x(i))
    printf("%d %d\n", p, q)
  }
}

object A567 {
  @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 = readLongs(n)
    val ans = Array.fill(n){Array(Long.MaxValue, 0L)}
    for(i <- 0 until n) {
      // min
      if(i-1 >= 0) {
        ans(i)(0) = math.min(ans(i)(0), math.abs(input(i) - input(i-1)))
      }
      if(i+1 < n) {
        ans(i)(0) = math.min(ans(i)(0), math.abs(input(i) - input(i+1)))
      }
      // max
      if(i != 0) {
        ans(i)(1) = math.max(ans(i)(1), math.abs(input(i) - input(0)))
      }
      if(i != n-1) {
        ans(i)(1) = math.max(ans(i)(1), math.abs(input(i) - input(n-1)))
      }
    }
    println(ans.map(_.mkString(" ")).mkString("\n"))
  }
}

object A extends App {
 val n = readLine.toInt
 val str = readLine
 val arr = str.split(" ").map(_.toInt)
 val mn = arr(0)
 val mx = arr(n - 1)

 import scala.math._

 print(arr(1) - arr(0))
 print(" ")
 println(mx - arr(0))

 for(i <- (1 until n - 1)) {
    print(min(abs(arr(i) - arr(i-1)), abs(arr(i + 1) - arr(i))))
    print(" ")
    println(
            max(
                abs(arr(i) - mn),
                abs(mx - arr(i))
               )
           )
 }

 print(mx - arr(n - 2))
 print(" ")
 println(mx - mn)
}

// So you like object Task
import java.io.{IOException, InputStream, PrintWriter}
import java.util.InputMismatchException

object Task {

    def solve(in: InputReader, out: PrintWriter): Unit = {
        val n = in.nextInt()
        val a = Array.fill(n)(in.nextInt())
        for (i <- 0 until n) {
            val minCost = (if (i == 0) Long.MaxValue else (a(i) - a(i - 1)).abs) min (if (i == n - 1) Long.MaxValue else (a(i) - a(i + 1)).abs)
            val maxCost = (if (i == 0) Long.MinValue else (a(i) - a(0)).abs) max (if (i == n - 1) Long.MinValue else (a(i) - a(n - 1)).abs)
            println("%d %d".format(minCost, maxCost))
        }
    }

    def main(args: Array[String]) {
        val in = new InputReader(System.in)
        val out = new PrintWriter(System.out)

        solve(in, out)

        in.close()
        out.close()
    }
}

class InputReader(val inputStream: InputStream) {
    val buf = new Array[Byte](1 << 16)
    var curChar = 0
    var numChars = 0

    def read(): Int = {
        if (numChars == -1) {
            throw new InputMismatchException()
        }
        if (curChar >= numChars) {
            curChar = 0
            try {
                numChars = inputStream.read(buf)
            } catch  {
                case _: IOException => throw new InputMismatchException()
            }
            if (numChars <= 0)
                return -1
        }
        curChar += 1
        buf(curChar - 1)
    }

    def peek(): Int = {
        if (numChars == -1) {
            return -1
        }
        if (curChar >= numChars) {
            curChar = 0
            try {
                numChars = inputStream.read(buf)
            } catch {
                case _: IOException => return -1
            }
            if (numChars <= 0)
                return -1
        }
        buf(curChar)
    }

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

    def nextInt(): Int = {
        var c = read()
        while (isSpaceChar(c)) c = read()
        var sgn = 1
        if (c == '-') {
            sgn = -1
            c = read()
        }
        var res = 0
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException()
            res *= 10
            res += c & 15
            c = read()
        } while (!isSpaceChar(c))
        res * sgn
    }

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

    def next(): String = {
        var c = read()
        while (isSpaceChar(c)) c = read()
        val res = new StringBuilder()
        do {
            res += c.toChar
            c = read()
        } while(!isSpaceChar(c))
        res.toString()
    }

    def nextChar(): Char = {
        var c = read()
        while (isSpaceChar(c)) c = read()
        c.toChar
    }

    //noinspection AccessorLikeMethodIsEmptyParen
    def hasNext(): Boolean = {
        var value = peek()
        do {
            read()
            value = peek()
        } while (isSpaceChar(value) && value != -1)
        value != -1
    }

    def rawNextLine(): String = {
        val builder = new StringBuilder
        var c = read()
        while (c != '\n' && c != -1) {
            if (c != '\r')
                builder += c.toChar
            c = read()
        }
        builder.toString()
    }

    def nextLine(): String = {
        var s = rawNextLine()
        while (s.trim().length == 0) s = rawNextLine()
        s
    }

    def nextDouble(): Double = {
        next().toDouble
    }

    def close(): Unit = {
        inputStream.close()
    }
}

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

import scala.collection.mutable

object A {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    def query(p: Int) = ???

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

  def solve: Int = {
    val n = nextInt
    val cities = new Array[Int](n)
    val min = new Array[Int](n)
    val max = new Array[Int](n)
    for (i <- 0 until n) {
      cities(i) = nextInt
    }
    for (i <- 1 until n - 1) {
      min(i) = Math.min(cities(i + 1) - cities(i), cities(i) - cities(i - 1))
      max(i) = Math.max(cities(n - 1) - cities(i), cities(i) - cities(0))
    }
    min(n - 1) = cities(n - 1) - cities(n - 2)
    max(n - 1) = cities(n - 1) - cities(0)
    min(0) = cities(1) - cities(0)
    max(0) = cities(n - 1) - cities(0)
    for (i <- 0 until n) {
      println(min(i) + " " + max(i))
    }
    return 0
  }
}

import io.StdIn._

object Solution {

  def main(args: Array[String]) {
    val n = readInt()
    val cities = readLine().split(" ").map(_.toInt)

    for ((c, i) <- cities.zipWithIndex) {
      if (i == 0) println((cities(i+1) - c) + " " + (cities.last - c))
      else if (i == cities.length - 1) println((c - cities(i-1)) + " " + (c - cities.head))
      else println(Math.min(cities(i+1) - c, c - cities(i-1)) + " " + Math.max(cities.last - c, c - cities.head))
    }

  }

}

import annotation.tailrec, collection.mutable, util.control.Breaks._, math.Ordering.Implicits._
import CodeForcesApp._
object _567A extends CodeForcesApp[Seq[String]]({scanner => import scanner._
  val n = nextInt
  val p = IndexedSeq.fill(n)(nextInt)
  for {
    i <- p.indices
  } yield {
    def d(x: Int) = (p(i) - p(x)).abs
    val (u, v) = if(i == 0) {
      d(1) -> d(n-1)
    } else if (i == n-1) {
      d(n-2) -> d(0)
    } else {
      (d(i-1) min d(i+1)) -> (d(0) max d(n-1))
    }
    s"$u $v"
  }
}) {
  override def format(result: Seq[String]) = result.mkString("", "\n", "")
}
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: A): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  import scala.collection.mutable.{Map => Dict}
  final def isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val modulus: Int = 1000000007
  final val eps: Double = 1e-9
  final def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  final def counter[A]: Dict[A, Int] = Dict.empty[A, Int] withDefaultValue 0
}

import scala.io.StdIn._

object A extends App {
  readLine()
  val x = readLine().split(" ").map(_.toInt)

  val LastIndex = x.length - 1

  for (i <- x.indices) {
    val min = i match {
      case 0 => Math.abs(x(0) - x(1))
      case LastIndex => Math.abs(x(i - 1) - x(i))
      case _ => Math.min(Math.abs(x(i) - x(i - 1)), Math.abs(x(i) - x(i + 1)))
    }

    val max = Math.max(Math.abs(x(0) - x(i)), Math.abs(x.last - x(i)))

    println(s"$min $max")
  }

}

import java.util.Scanner
import scala.annotation._
import scala.math._

object Solution {
  def main(args: Array[String]) {
    val scanner = new Scanner(System.in)

    val n = scanner.nextInt

    val nums = Array.fill(n)(scanner.nextLong)

    println(s"${nums(1)-nums(0)} ${nums(n-1)-nums(0)}")

    for (i <- 1 until (n-1)) {
      val minCost = min(nums(i)-nums(i-1), nums(i+1)-nums(i))
      val maxCost = max(nums(n-1)-nums(i), nums(i)-nums(0))
      println(s"$minCost $maxCost")
    }

    println(s"${nums(n-1)-nums(n-2)} ${nums(n-1)-nums(0)}")
  }
}

import scala.io.StdIn.readLine
import scala.io.StdIn.readInt

import Math.min
import Math.max

object LinelandMail {

   def readInts() : Array[Int] =
     readLine.split(' ').map(_.toInt)

   def readLongs() : Array[Long] =
      readLine.split(' ').map(_.toLong)

   def readTuple() : (Int,Int) = {
     val line = readInts
     (line(0),line(1))
   }
   def readTupleLong() : (Long,Long) = {
     val line = readLongs
     (line(0),line(1))
   }

   def readTriple() : (Int,Int,Int) = {
     val line = readInts
     (line(0),line(1),line(2))
   }
   def readQuad() : (Int,Int,Int,Int) = {
     val line = readInts
     (line(0),line(1),line(2),line(3))
   }

   def main(args: Array[String]) : Unit = {
     val n = readInt
     val xs = readInts
     val first = xs(0)
     val last = xs(n-1)
     println( xs(1)-first + " " + (last-first))
     xs.zipWithIndex.tail.init.foreach {
       case (x,i) =>
         println( min(x-xs(i-1),xs(i+1)-x) + " "
                  + max(x-first,last-x)  )
     }
     println( last - xs(n-2) + " " + (last-first))
   }

}

import scala.io.StdIn._

object Main extends App {
  val n = readInt()
  val a = Int.MinValue.toLong +: readLine().split(" ").map(_.toLong) :+ Int.MaxValue.toLong
  for (i <- 1 to n) {
    val max = (a(i) - a(1)) max (a(n) - a(i))
    val min = (a(i) - a(i - 1)) min (a(i + 1) - a(i))
    println(min + " " + max)
  }
}

import scala.io.StdIn._

object Main extends App {
  val n = readInt()
  val a = Int.MinValue +: readLine().split(" ").map(_.toInt) :+ Int.MaxValue
  for (i <- 1 to n) {
    val max = (a(i) - a(1)) max (a(n) - a(i))
    val min = (a(i) - a(i - 1)) min (a(i + 1) - a(i))
    println(min + " " + max)
  }
}

import scala.io.StdIn._

object Main extends App {
  val n = readInt()
  val a = Long.MinValue +: readLine().split(" ").map(_.toLong) :+ Long.MaxValue
  for (i <- 1 to n) {
    val max = (a(i) - a(1)) max (a(n) - a(i))
    val min = (a(i) - a(i - 1)) min (a(i + 1) - a(i))
    println(min + " " + max)
  }
}

import scala.io.StdIn._

object CF567A extends App {
  val n = readInt()
  val x = readLine().split(" ").map(_.toInt)

  for (i <- 0 to x.length - 1) {
    val max = Math.max(x(i) - x.head, x.last - x(i))
    val min = Math.min(x(i) - x.lift(i - 1).getOrElse(Int.MaxValue), x.lift(i + 1).getOrElse(Int.MaxValue) - x(i))
    println(min + " " + max)
  }
}

import scala.io.StdIn._

object CF567A extends App {
  val n = readInt()
  val x = readLine().split(" ").map(_.toLong)

  for (i <- 0 to x.length - 1) {
    val max = Math.max(x(i) - x.head, x.last - x(i))
    val min = Math.min(x(i) - x.lift(i - 1).getOrElse(Long.MaxValue), x.lift(i + 1).getOrElse(Long.MaxValue) - x(i))
    println(min + " " + max)
  }
}

object A extends App {
 val n = readLine.toInt
 val str = readLine
 val arr = str.split(" ").map(_.toInt)
 val mn = arr(0)
 val mx = arr(n - 1)

 import scala.math._

 print(arr(1) - arr(0))
 print(" ")
 println(mx - arr(0))

 for(i <- (1 until n - 1)) {
    print(max(abs(arr(i) - arr(i-1)), abs(arr(i + 1) - arr(i))))
    print(" ")
    println(
            max(
                abs(arr(i) - mn),
                abs(mx - arr(i))
               )
           )
 }

 print(mx - arr(n - 2))
 print(" ")
 println(mx - mn)
}


You are given a tree consisting exactly of $$$n$$$ vertices. Tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a value $$$a_v$$$ assigned to it.Let $$$dist(x, y)$$$ be the distance between the vertices $$$x$$$ and $$$y$$$. The distance between the vertices is the number of edges on the simple path between them.Let's define the cost of the tree as the following value: firstly, let's fix some vertex of the tree. Let it be $$$v$$$. Then the cost of the tree is $$$\sum\limits_{i = 1}^{n} dist(i, v) \cdot a_i$$$.Your task is to calculate the maximum possible cost of the tree if you can choose $$$v$$$ arbitrarily.

The first line contains one integer $$$n$$$, the number of vertices in the tree ($$$1 \le n \le 2 \cdot 10^5$$$). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2 \cdot 10^5$$$), where $$$a_i$$$ is the value of the vertex $$$i$$$. Each of the next $$$n - 1$$$ lines describes an edge of the tree. Edge $$$i$$$ is denoted by two integers $$$u_i$$$ and $$$v_i$$$, the labels of vertices it connects ($$$1 \le u_i, v_i \le n$$$, $$$u_i \ne v_i$$$). It is guaranteed that the given edges form a tree.

Print one integer — the maximum possible cost of the tree if you can choose any vertex as $$$v$$$.

NotePicture corresponding to the first example: You can choose the vertex $$$3$$$ as a root, then the answer will be $$$2 \cdot 9 + 1 \cdot 4 + 0 \cdot 1 + 3 \cdot 7 + 3 \cdot 10 + 4 \cdot 1 + 4 \cdot 6 + 4 \cdot 5 = 18 + 4 + 0 + 21 + 30 + 4 + 24 + 20 = 121$$$.In the second example tree consists only of one vertex so the answer is always $$$0$$$.

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val A = na(N)
    val (from, to) = na2(N - 1, -1)
    val t = packUGraph(N, from, to)
    val (_, p, q) = traceBfs(t)

    val D = Array.ofDim[Long](N) // このサブツリーの距離かけるAiの合計
    val S = Array.ofDim[Long](N) // このサブツリーのAiの合計

    REP_r(N) { i =>
      val v = q(i)
      val E = t(v)
      S(v) += A(v)
      REP(E.length) { j =>
        val u = E(j)
        if (p(v) != u) {
          D(v) += D(u) + S(u)
          S(v) += S(u)
        }
      }
    }

    val calc = Array.ofDim[Long](N)
    calc(0) = D(0)
    REP(N - 1, 1) { i =>
      val v = q(i)
      val sumA0 = S(0) - S(v)
      val res = calc(p(v)) - S(v) + sumA0
      calc(v) = res
    }

    val ans = calc.max
    out.println(ans)
  }

  def packUGraph(n: Int, from: Array[Int], to: Array[Int]): Array[Array[Int]] = {
    val t = new Array[Array[Int]](n)
    val p = new Array[Int](n)
    val m = from.length
    REP(m)(i => p(from(i)) += 1)
    REP(m)(i => p(to(i)) += 1)
    REP(n)(i => t(i) = new Array(p(i)))
    REP(m) { i =>
      p(from(i)) -= 1
      t(from(i))(p(from(i))) = to(i)
      p(to(i)) -= 1
      t(to(i))(p(to(i))) = from(i)
    }
    t
  }

  /**
    * @return (depth, parent, queue)
    */
  def traceBfs(g: Array[Array[Int]], rt: Int = 0): (Array[Int], Array[Int], Array[Int]) = {
    val n = g.length
    val INF = 1e9.toInt + 10
    val q, p = Array.ofDim[Int](n)
    q(0) = rt
    p(rt) = -1
    val d = Array.fill[Int](n)(INF)
    d(rt) = 0
    var cur = 0
    var last = 1
    while (cur < last) {
      val v = q(cur)
      REP(g(v).length) { i =>
        val u = g(v)(i)
        if (d(u) == INF) {
          d(u) = d(v) + 1
          p(u) = v
          q(last) = u
          last += 1
        }
      }
      cur += 1
    }
    (d, p, q)
  }

  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 = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.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 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]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}


During the quarantine, Sicromoft has more free time to create the new functions in "Celex-2021". The developers made a new function GAZ-GIZ, which infinitely fills an infinite table to the right and down from the upper left corner as follows:   The cell with coordinates $$$(x, y)$$$ is at the intersection of $$$x$$$-th row and $$$y$$$-th column. Upper left cell $$$(1,1)$$$ contains an integer $$$1$$$.The developers of the SUM function don't sleep either. Because of the boredom, they teamed up with the developers of the RAND function, so they added the ability to calculate the sum on an arbitrary path from one cell to another, moving down or right. Formally, from the cell $$$(x,y)$$$ in one step you can move to the cell $$$(x+1, y)$$$ or $$$(x, y+1)$$$. After another Dinwows update, Levian started to study "Celex-2021" (because he wants to be an accountant!). After filling in the table with the GAZ-GIZ function, he asked you to calculate the quantity of possible different amounts on the path from a given cell $$$(x_1, y_1)$$$ to another given cell $$$(x_2, y_2$$$), if you can only move one cell down or right.Formally, consider all the paths from the cell $$$(x_1, y_1)$$$ to cell $$$(x_2, y_2)$$$ such that each next cell in the path is located either to the down or to the right of the previous one. Calculate the number of different sums of elements for all such paths.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 57179$$$) — the number of test cases. Each of the following $$$t$$$ lines contains four natural numbers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ ($$$1 \le x_1 \le x_2 \le 10^9$$$, $$$1 \le y_1 \le y_2 \le 10^9$$$) — coordinates of the start and the end cells.

For each test case, in a separate line, print the number of possible different sums on the way from the start cell to the end cell.

NoteIn the first test case there are two possible sums: $$$1+2+5=8$$$ and $$$1+3+5=9$$$.

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

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

  def main(args: Array[String]): Unit = {
    val t = readLine().toInt
    for (i <- 1 to t) {
      val arr = readIntLine()
      println(calcWays(arr(2) - arr.head, arr.last - arr(1)))
    }
    //      println(calcWays(4, 5))
  }

  def calcWays(x: Int, y: Int): Long = x.toLong * y + 1

  def makeArray(n: Int) {
    class QueueElement(val left: Int, val right: Int) {}

    val arr = Array.ofDim[Int](n)
    val intervals = (0 to n).map(_ => ListBuffer[QueueElement]()).toArray
    intervals(n) += new QueueElement(0, n - 1)
    var count = 1
    for (i <- (0 to n).reverse) {
      var intOfLengthI = intervals(i)
      intOfLengthI = intOfLengthI.sortBy(_.left)
      for (j <- intOfLengthI.indices) {
        val head = intOfLengthI(j)
        if (head.left == head.right) {
          arr(head.left) = count
        } else {
          val mid = (head.left + head.right) / 2
          arr(mid) = count
          if (mid != head.left) intervals(mid - head.left) += new QueueElement(head.left, mid - 1)
          intervals(head.right - mid) += new QueueElement(mid + 1, head.right)
        }
        count += 1
      }
    }

    printArray(arr)
  }

  def printArray[T](arr: Array[T]) {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

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

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

}

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

  (0 until t).foreach { _ =>
    val Array(x1, y1, x2, y2) = scala.io.StdIn.readLine().split(" ").map(_.toLong)

    val ans = (x2 - x1) * (y2 - y1) + 1

    println(ans)
  }
}

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

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

  def main(args: Array[String]): Unit = {
    val t = readLine().toInt
    for (i <- 1 to t) {
      val arr = readIntLine()
      println(calcWays(arr(2) - arr.head, arr.last - arr(1)))
    }
//      println(calcWays(4, 5))
  }

  def calcWays(x: Int, y: Int):  BigInt = {
    if (x < 0 || y < 0) 0
    if (x == 0 || y == 0) 1 else {
      val i = Math.max(x + 1, y + 1)
      val j = Math.min(x + 1, y + 1)

      def sum(list: List[BigInt], acc: BigInt, listAcc: List[BigInt]): List[BigInt] = list match {
        case Nil => listAcc.reverse
        case s :: ss => sum(ss, acc + s, (acc + s) :: listAcc)
      }

      def helper(prev: List[BigInt], j: Int): BigInt = if (j == 1) prev.last
      else helper(sum(prev, 0, Nil), j - 1)

      helper((1 to i).map(_ => BigInt(1)).toList, j)
    }
  }

  def makeArray(n: Int) {
    class QueueElement(val left: Int, val right: Int) {}

    val arr = Array.ofDim[Int](n)
    val intervals = (0 to n).map(_ => ListBuffer[QueueElement]()).toArray
    intervals(n) += new QueueElement(0, n - 1)
    var count = 1
    for (i <- (0 to n).reverse) {
      var intOfLengthI = intervals(i)
      intOfLengthI = intOfLengthI.sortBy(_.left)
      for (j <- intOfLengthI.indices) {
        val head = intOfLengthI(j)
        if (head.left == head.right) {
          arr(head.left) = count
        } else {
          val mid = (head.left + head.right) / 2
          arr(mid) = count
          if (mid != head.left) intervals(mid - head.left) += new QueueElement(head.left, mid - 1)
          intervals(head.right - mid) += new QueueElement(mid + 1, head.right)
        }
        count += 1
      }
    }

    printArray(arr)
  }

  def printArray[T](arr: Array[T]) {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

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

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

}

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

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

  def main(args: Array[String]): Unit = {
    val t = readLine().toInt
    for (i <- 1 to t) {
      val arr = readIntLine()
      println(calcWays(arr(2) - arr.head, arr.last - arr(1)))
    }
//      println(calcWays(1, 2))
  }

  def calcWays(x: Int, y: Int):  BigInt = {
    if (x == 0 || y == 0) 1 else {
      val i = Math.max(x + 1, y + 1)
      val j = Math.min(x + 1, y + 1)

      def sum(list: List[BigInt], acc: BigInt, listAcc: List[BigInt]): List[BigInt] = list match {
        case Nil => listAcc.reverse
        case s :: ss => sum(ss, acc + s, (acc + s) :: listAcc)
      }

      def helper(prev: List[BigInt], j: Int): BigInt = if (j == 1) prev.last
      else helper(sum(prev, 0, Nil), j - 1)

      helper((1 to i).map(_ => BigInt(1)).toList, j)
    }
  }

  def makeArray(n: Int) {
    class QueueElement(val left: Int, val right: Int) {}

    val arr = Array.ofDim[Int](n)
    val intervals = (0 to n).map(_ => ListBuffer[QueueElement]()).toArray
    intervals(n) += new QueueElement(0, n - 1)
    var count = 1
    for (i <- (0 to n).reverse) {
      var intOfLengthI = intervals(i)
      intOfLengthI = intOfLengthI.sortBy(_.left)
      for (j <- intOfLengthI.indices) {
        val head = intOfLengthI(j)
        if (head.left == head.right) {
          arr(head.left) = count
        } else {
          val mid = (head.left + head.right) / 2
          arr(mid) = count
          if (mid != head.left) intervals(mid - head.left) += new QueueElement(head.left, mid - 1)
          intervals(head.right - mid) += new QueueElement(mid + 1, head.right)
        }
        count += 1
      }
    }

    printArray(arr)
  }

  def printArray[T](arr: Array[T]) {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

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

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

}

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

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

  def main(args: Array[String]): Unit = {
    val t = readLine().toInt
    for (i <- 1 to t) {
      val arr = readIntLine()
      println(calcWays(arr(2) - arr.head, arr.last - arr(1)))
    }
//      println(calcWays(4, 5))
  }

  def calcWays(x: Int, y: Int):  BigInt = {
    if (x < 0 || y < 0) 0
    else if (x == 0 || y == 0) 1 else {
      val i = Math.max(x + 1, y + 1)
      val j = Math.min(x + 1, y + 1)

      def sum(list: List[BigInt], acc: BigInt, listAcc: List[BigInt]): List[BigInt] = list match {
        case Nil => listAcc.reverse
        case s :: ss => sum(ss, acc + s, (acc + s) :: listAcc)
      }

      def helper(prev: List[BigInt], j: Int): BigInt = if (j == 1) prev.last
      else helper(sum(prev, 0, Nil), j - 1)

      helper((1 to i).map(_ => BigInt(1)).toList, j)
    }
  }

  def makeArray(n: Int) {
    class QueueElement(val left: Int, val right: Int) {}

    val arr = Array.ofDim[Int](n)
    val intervals = (0 to n).map(_ => ListBuffer[QueueElement]()).toArray
    intervals(n) += new QueueElement(0, n - 1)
    var count = 1
    for (i <- (0 to n).reverse) {
      var intOfLengthI = intervals(i)
      intOfLengthI = intOfLengthI.sortBy(_.left)
      for (j <- intOfLengthI.indices) {
        val head = intOfLengthI(j)
        if (head.left == head.right) {
          arr(head.left) = count
        } else {
          val mid = (head.left + head.right) / 2
          arr(mid) = count
          if (mid != head.left) intervals(mid - head.left) += new QueueElement(head.left, mid - 1)
          intervals(head.right - mid) += new QueueElement(mid + 1, head.right)
        }
        count += 1
      }
    }

    printArray(arr)
  }

  def printArray[T](arr: Array[T]) {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

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

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

}

object C extends App {
  private def gazGiz(x: Long, y: Long): Long =
    x + (x + y - 1) * (x + y - 2) / 2

  private def binomial(n: Int, k: Int): Long =
    if (k > n - k) binomial(n, n - k)
    else (1 to k).foldLeft(1L)((b, i) => b * (n - k + i) / i)

  val t = scala.io.StdIn.readInt()

  (0 until t).foreach { _ =>
    val Array(x1, y1, x2, y2) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    val r = y2 - y1
    val d = x2 - x1 + y2 - y1

    val ans = binomial(d, r)

    println(ans)
  }
}

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

  (0 until t).foreach { _ =>
    val Array(x1, y1, x2, y2) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    val ans = (x2 - x1) * (y2 - y1) + 1

    println(ans)
  }
}


Ramesses came to university to algorithms practice, and his professor, who is a fairly known programmer, gave him the following task.You are given two matrices $$$A$$$ and $$$B$$$ of size $$$n \times m$$$, each of which consists of $$$0$$$ and $$$1$$$ only. You can apply the following operation to the matrix $$$A$$$ arbitrary number of times: take any submatrix of the matrix $$$A$$$ that has at least two rows and two columns, and invert the values in its corners (i.e. all corners of the submatrix that contain $$$0$$$, will be replaced by $$$1$$$, and all corners of the submatrix that contain $$$1$$$, will be replaced by $$$0$$$). You have to answer whether you can obtain the matrix $$$B$$$ from the matrix $$$A$$$.  An example of the operation. The chosen submatrix is shown in blue and yellow, its corners are shown in yellow. Ramesses don't want to perform these operations by himself, so he asks you to answer this question.A submatrix of matrix $$$M$$$ is a matrix which consist of all elements which come from one of the rows with indices $$$x_1, x_1+1, \ldots, x_2$$$ of matrix $$$M$$$ and one of the columns with indices $$$y_1, y_1+1, \ldots, y_2$$$ of matrix $$$M$$$, where $$$x_1, x_2, y_1, y_2$$$ are the edge rows and columns of the submatrix. In other words, a submatrix is a set of elements of source matrix which form a solid rectangle (i.e. without holes) with sides parallel to the sides of the original matrix. The corners of the submatrix are cells $$$(x_1, y_1)$$$, $$$(x_1, y_2)$$$, $$$(x_2, y_1)$$$, $$$(x_2, y_2)$$$, where the cell $$$(i,j)$$$ denotes the cell on the intersection of the $$$i$$$-th row and the $$$j$$$-th column.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 500$$$) — the number of rows and the number of columns in matrices $$$A$$$ and $$$B$$$. Each of the next $$$n$$$ lines contain $$$m$$$ integers: the $$$j$$$-th integer in the $$$i$$$-th line is the $$$j$$$-th element of the $$$i$$$-th row of the matrix $$$A$$$ ($$$0 \leq A_{ij} \leq 1$$$).  Each of the next $$$n$$$ lines contain $$$m$$$ integers: the $$$j$$$-th integer in the $$$i$$$-th line is the $$$j$$$-th element of the $$$i$$$-th row of the matrix $$$B$$$ ($$$0 \leq B_{ij} \leq 1$$$).

Print "Yes" (without quotes) if it is possible to transform the matrix $$$A$$$ to the matrix $$$B$$$ using the operations described above, and "No" (without quotes), if it is not possible. You can print each letter in any case (upper or lower).

NoteThe examples are explained below.  Example 1.   Example 2.   Example 3.

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer
  import java.util.Arrays

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, M = ni()
    val A, B = nm(N, M)
    val C = Array.ofDim[Boolean](N, M)
    val X = Array.ofDim[Int](N)
    val Y = Array.ofDim[Int](M)
    REP(N) { i =>
      REP(M) { j =>
        C(i)(j) = A(i)(j) != B(i)(j)
      }
    }
    DEBUG{
      REP(N) { i =>
        debug(C(i))
      }
    }

    REP(N) { i =>
      REP(M) { j =>
        if (C(i)(j)) {
          X(i) += 1
          Y(j) += 1
        }
      }
    }

    debug(X)
    debug(Y)
    val ok = X.forall(_ % 2 == 0) && Y.forall(_ % 2 == 0)
    if (ok) out.println("Yes")
    else out.println("No")
  }

  private val oj = System.getenv("ATCODER_DEBUG") == null

  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }

  def debug(as: Array[Boolean]): Unit = DEBUG {
    debug(as.map(x => if(x) "1" else "0").mkString)
  }

  def debug(as: Array[Int]): Unit = DEBUG {
    debug(as.mkString(" "))
  }

  def debug(as: Array[Long]): Unit = DEBUG {
    debug(as.mkString(" "))
  }

  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 = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.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]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}


There are two infinite sources of water:  hot water of temperature $$$h$$$;  cold water of temperature $$$c$$$ ($$$c < h$$$). You perform the following procedure of alternating moves:  take one cup of the hot water and pour it into an infinitely deep barrel;  take one cup of the cold water and pour it into an infinitely deep barrel;  take one cup of the hot water $$$\dots$$$  and so on $$$\dots$$$ Note that you always start with the cup of hot water.The barrel is initially empty. You have to pour at least one cup into the barrel. The water temperature in the barrel is an average of the temperatures of the poured cups.You want to achieve a temperature as close as possible to $$$t$$$. So if the temperature in the barrel is $$$t_b$$$, then the absolute difference of $$$t_b$$$ and $$$t$$$ ($$$|t_b - t|$$$) should be as small as possible.How many cups should you pour into the barrel, so that the temperature in it is as close as possible to $$$t$$$? If there are multiple answers with the minimum absolute difference, then print the smallest of them.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 3 \cdot 10^4$$$) — the number of testcases. Each of the next $$$T$$$ lines contains three integers $$$h$$$, $$$c$$$ and $$$t$$$ ($$$1 \le c < h \le 10^6$$$; $$$c \le t \le h$$$) — the temperature of the hot water, the temperature of the cold water and the desired temperature in the barrel.

For each testcase print a single positive integer — the minimum number of cups required to be poured into the barrel to achieve the closest temperature to $$$t$$$.

NoteIn the first testcase the temperature after $$$2$$$ poured cups: $$$1$$$ hot and $$$1$$$ cold is exactly $$$20$$$. So that is the closest we can achieve.In the second testcase the temperature after $$$7$$$ poured cups: $$$4$$$ hot and $$$3$$$ cold is about $$$29.857$$$. Pouring more water won't get us closer to $$$t$$$ than that.In the third testcase the temperature after $$$1$$$ poured cup: $$$1$$$ hot is $$$18$$$. That's exactly equal to $$$t$$$.

//package codeforces.contests._1359

object _3 {

  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(h, c, t) = io.StdIn.readLine.split(" ").map(_.toLong)

      println {
        if (t >= h) 1
        else if (t <= (h + c) / 2.0) 2
        else {
          def nearest(y: Long): BigDecimal = (BigDecimal((y + 1) * h + y * c) / BigDecimal(2.0 * y + 1) - BigDecimal(t)).abs

          def solve(y: Long): (BigDecimal, Long) = (nearest(y), 2 * y + 1)

          val y = (t - h) / (h + c - 2 * t)

          val ls = List(solve(y - 1), solve(y), solve(y + 1))

          val min = ls.minBy(_._1)._1

          ls.filter(_._1 == min).minBy(_._2)._2
        }
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toLong)
      val (h, c, t) = (input(0), input(1), input(2))
      if (2*t <= h +c) println(2)
      else {
        val n = (h-t)/(2 *t-h-c)
        val (n1, n2) = (n, n+1)
        val d1 = (n1*c+(n1+1)*h)-t*(2*n1+1)
        val d2 = t*(2*n2+1)-(n2*c+(n2+1)*h)
        val res = if (d1*(2*n2+1) > d2*(2*n1+1)) 2*n2+1 else 2*n1+1
        println(res)
      }
    }
  }
}

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

  (0 until t).foreach { _ =>
    val Array(h, c, t) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    val d = c + h - 2 * t

    val ans =
      if (d >= 0) 2
      else if (h <= t) 1
      else if (c >= t) 2
      else { // c < t < h
        val k  = (t - h) / d.toDouble
        val ks = List(k.ceil, k.floor).sorted.sortBy(k => math.abs((h - t + k * d) / (1.0 + 2 * k)))

        (1 + 2 * ks.head).toInt
      }

    println(ans)
  }
}

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

  (0 until t).foreach { _ =>
    val Array(h, c, t) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    val d = c + h - 2 * t

    val ans =
      if (d >= 0) 2
      else if (h <= t) 1
      else if (c >= t) 2
      else { // c < t < h
        val k  = (t - h) / d.toDouble
        val ks = List(k.floor, k.ceil).sortBy(k => math.abs((h - t + k * d) / (1.0 + 2 * k)))

        (1 + 2 * ks.head).toInt
      }

    println(ans)
  }
}

//package codeforces.contests._1359

object _3 {

  import math._

  // 999977 17 499998
  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(h, c, t) = io.StdIn.readLine.split(" ").map(_.toLong)

      val second = (abs((h + c) - 2 * t).toDouble, 2L)

      def nearest(y: Long): Long = abs(((y + 1) * h + y * c) - (y + 1 + y) * t)

      def solve(y: Long): (Double, Long) = (nearest(y), 2 * y + 1)

      val y = {
        val temp = ((t - h) * 1.0) / (h + c - 2 * t)
        if (temp < 0) 0 else temp.ceil.toLong
      }

      val third = solve(y)

      val ls = List(second, third)

      val min = ls.minBy(_._1)._1

      println {
        ls.filter(_._1 == min).minBy(_._2)._2
      }
    }
  }
}

//package codeforces.contests._1359

object _3 {

  import math._

  // 999977 17 499998
  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(h, c, t) = io.StdIn.readLine.split(" ").map(_.toLong)

      val second = (abs((h + c) - 2 * t).toDouble, 2L)

      def nearest(y: Long): Long = abs(((y + 1) * h + y * c) - (y + 1 + y) * t)

      def solve(y: Long): (Double, Long) = (nearest(y), 2 * y + 1)

      val y = {
        val temp = ((t - h) * 1.0) / (h + c - 2 * t)
        if (temp < 0) 0 else temp.floor.toLong
      }

      val (df, dfy) = solve(y)
      val (dc, dcy) = solve(y + 1)

      val odd = if(df >= dc) (dc, dcy) else (df, dfy)

      val ls = List(second, odd)

      val min = ls.minBy(_._1)._1

      println {
        ls.filter(_._1 == min).minBy(_._2)._2
      }
    }
  }
}

//package codeforces.contests._1359

object _3 {

  import math._

  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(h, c, t) = io.StdIn.readLine.split(" ").map(_.toLong)

      val first = (abs(h - t).toDouble, 1L)
      val second = (abs((h + c) - 2 * t).toDouble, 2L)

      def nearest(y: Long): Double = abs(((y + 1) * h + y * c) * 1.0 / (y + 1 + y) - t)

      def solve(y: Long): (Double, Long) = (nearest(y), 2 * y + 1)

      val y = {
        val temp = ((t - h) * 1.0) / (h + c - 2 * t)
        if (temp < 0) 0 else temp.floor.toLong
      }

      val third = solve(y)
      val fourth = solve(y + 1)

      val ls = List(first, second, third, fourth)

      val min = ls.minBy(_._1)._1

      println {
        ls.filter(_._1 == min).minBy(_._2)._2
      }
    }
  }
}

//package codeforces.contests._1359

object _3 {

  import math._

  // 999977 17 499998
  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(h, c, t) = io.StdIn.readLine.split(" ").map(_.toLong)

      val second = (abs((h + c) - 2 * t).toDouble, 2L)

      def nearest(y: Long): Long = abs(((y + 1) * h + y * c) - (y + 1 + y) * t)

      def solve(y: Long): (Double, Long) = (nearest(y), 2 * y + 1)

      val y = {
        val temp = ((t - h) * 1.0) / (h + c - 2 * t)
        if (temp < 0) 0 else temp.round
      }

      val third = solve(y)

      val ls = List(second, third)

      val min = ls.minBy(_._1)._1

      println {
        ls.filter(_._1 == min).minBy(_._2)._2
      }
    }
  }
}

//package codeforces.contests._1359

object _3 {

  import math._

  // 999977 17 499998
  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(h, c, t) = io.StdIn.readLine.split(" ").map(_.toLong)

      val second = (abs((h + c) - 2 * t).toDouble, 2L)

      def nearest(y: Long): Double = abs(((y + 1) * h + y * c) * 1.0 / (y + 1 + y) - t)

      def solve(y: Long): (Double, Long) = (nearest(y), 2 * y + 1)

      val y = {
        val temp = ((t - h) * 1.0) / (h + c - 2 * t)
        if (temp < 0) 0 else temp.floor.toLong
      }

      val (df, dfy) = solve(y)
      val (dc, dcy) = solve(y + 1)

      val odd = if (df >= dc) (dc, dcy) else (df, dfy)

      val ls = List(second, odd)

      val min = ls.minBy(_._1)._1

      println {
        ls.filter(_._1 == min).minBy(_._2)._2
      }
    }
  }
}

//package codeforces.contests._1359

object _3 {

  import math._

  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(h, c, t) = io.StdIn.readLine.split(" ").map(_.toLong)

      val first = (abs(h - t).toDouble, 1L)
      val second = (abs((h + c) / 2 - t).toDouble, 2L)

      val y = {
        val temp = (t - h) * 1.0 / (h + c - 2 * t)
        if (temp < 0) 0 else temp.floor.toLong
      }

      def nearest(y: Long): Double = ((y + 1) * h + y * c) * 1.0 / (y + 1 + y)

      val third: (Double, Long) = (abs(nearest(y) - t), 2 * y + 1)

      val fourth = (abs(nearest(y + 1) - t), 2 * (y + 1) + 1)

      val fifth = {
        val ty = (y - 1) max 0
        (abs(nearest(ty) - t), 2 * ty + 1)
      }

      val ls = List(first, second, third, fourth, fifth)

      val min = ls.minBy(_._1)._1

      println {
        ls.filter(_._1 == min).minBy(_._2)._2
      }
    }
  }
}

//package codeforces.contests._1359

object _3 {

  import math._

  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(h, c, t) = io.StdIn.readLine.split(" ").map(_.toLong)

      val first = (abs(h - t).toDouble, 1L)
      val second = (abs((h + c) / 2 - t).toDouble, 2L)

      def nearest(y: Long): Double = abs(((y + 1) * h + y * c) * 1.0 / (y + 1 + y) - t)

      def solve(y: Long): (Double, Long) = (nearest(y), 2 * y + 1)

      val y = {
        val temp = ((t - h) * 1.0) / (h + c - 2 * t)
        if (temp < 0) 0 else temp.floor.toLong
      }

      val third = solve(y)
      val fourth = solve(y + 1)

      val ls = List(first, second, third, fourth)

      val min = ls.minBy(_._1)._1

      println {
        ls.filter(_._1 == min).minBy(_._2)._2
      }
    }
  }
}

//package codeforces.contests._1359

object _3 {

  import math._

  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(h, c, t) = io.StdIn.readLine.split(" ").map(_.toLong)

      val first = (abs(h - t).toDouble, 1L)
      val second = (abs((h + c) - 2*t).toDouble, 2L)

      def nearest(y: Long): Long = abs(((y + 1) * h + y * c) - (y + 1 + y) * t)

      def solve(y: Long): (Double, Long) = (nearest(y), 2 * y + 1)

      val y = {
        val temp = ((t - h) * 1.0) / (h + c - 2 * t)
        if (temp < 0) 0 else temp.floor.toLong
      }

      val third: (Double, Long) = solve((y - 1) max 0)
      val fourth = solve(y)
      val fifth = solve(y + 1)
      val sixth = solve(y + 2)
      val seventh = solve(y + 3)
      val eigth = solve((y - 2) max 0)

      val ls = List(first, second, third, fourth, fifth, sixth, seventh, eigth)

      val min = ls.minBy(_._1)._1

      println {
        ls.filter(_._1 == min).minBy(_._2)._2
      }
    }
  }
}

//package codeforces.contests._1359

object _3 {

  import math._

  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(h, c, t) = io.StdIn.readLine.split(" ").map(_.toInt)

      val first = (abs(h - t).toDouble, 1)
      val second = (abs((h + c) / 2 - t).toDouble, 2)

      val y = {
        val temp = (t - h) * 1.0 / (h + c - 2 * t)
        if (temp < 0) 0 else temp.floor.toInt
      }

      def nearest(y: Int): Double = ((y + 1) * h + y * c) * 1.0 / (y + 1 + y)

      val third = (abs(nearest(y) - t), 2*y+1)

      val fourth = (abs(nearest(y + 1) - t), 2*(y+1) + 1)

      val ls = List(first, second, third, fourth)

      val min = ls.minBy(_._1)._1

      println {
        ls.filter(_._1 == min).minBy(_._2)._2
      }
    }
  }
}

//package codeforces.contests._1359

object _3 {

  import math._

  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(h, c, t) = io.StdIn.readLine.split(" ").map(_.toLong)

      val first = (abs(h - t).toDouble, 1L)
      val second = (abs((h + c) / 2 - t).toDouble, 2L)

      def nearest(y: Long): Double = ((y + 1) * h + y * c) * 1.0 / (y + 1 + y)

      def solve(y: Long): (Double, Long) = (abs(nearest(y) - t), 2 * y + 1)

      val y = {
        val temp = (t - h) * 1.0 / (h + c - 2 * t)
        if (temp < 0) 0 else temp.floor.toLong
      }

      val third: (Double, Long) = solve((y - 1) max 0)
      val fourth = solve(y)
      val fifth = solve(y + 1)
      val sixth = solve(y + 2)
      val seventh = solve(y + 3)
      val eigth = solve((y - 2) max 0)

      val ls = List(first, second, third, fourth, fifth, sixth, seventh, eigth)

      val min = ls.minBy(_._1)._1

      println {
        ls.filter(_._1 == min).minBy(_._2)._2
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toInt)
      val (h, c, t) = (input(0), input(1), input(2))
      require(t <= h && t >= c)
      if (4*t >= 3*h+c) println(1)
      else if (2*t >= h+c) println(2)
      else {
        val dn = (t-c)/(2.0*t-h-c)
        val n1 = dn.toDouble.toInt
        val n2 = n1 + 1
        def ft(n: Int) = ((n*h)+(n-1)*c)/(2.0*n-1)
        val c1 = (ft(n1)-t).abs
        val c2 = (ft(n2)-t).abs
        if (c1 < c2) println(n1*2-1) else println(n2*2-1)
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toInt)
      val (h, c, t) = (input(0), input(1), input(2))
      if (2*t <= h +c) println(2)
      else {
        val n1 = (t-c)/(2 *t-h-c)
        def ft(n: Int) = (((n*h)+(n-1)*c)/(2.0*n-1) - t).abs

        val ress = (n1 to n1 + 2).map(ft)
        val res = ress.indexOf(ress.min) + n1
        println((res*2-1) max 1)
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toInt)
      val (h, c, t) = (input(0), input(1), input(2))
      require(t <= h && t >= c)
      if (4*t >= 3*h+c) println(1)
      else if (2*t <= h +c) println(2)
      else {
        val n1 = (t-c)/(2 *t-h-c)
        val n2 = n1 + 1
        def ft(n: Int) = ((n*h)+(n-1)*c)/(2.0*n-1) - t
        val c1 = ft(n1).abs
        val c2 = ft(n2).abs
        val res = if ((t-c) % (2*t-h-c) == 0 || c1 <= c2) (n1*2-1) else (n2*2-1)
        println(res max 1)
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toLong)
      val (h, c, t) = (input(0), input(1), input(2))
      if (2*t <= h +c) println(2)
      else {
        val n1 = (t-c)/(2 *t-h-c)
        def ft(n: Long) = ((((n.toLong*h)+(n-1)*c)/(2.0*n-1)) - t).abs
        val f1 = ft(n1)
        val f2 = ft(n1+1)
        val res = if (f1<=f2) n1 else n1+1
        println(res*2-1)
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toLong)
      val (h, c, t) = (input(0), input(1), input(2))

      if (2*t <= h +c) println(2)
      else {
        val n1 = (h-t)/(2 *t-h-c)
        def ft(n: Long) = ((n*h+n*c-c)- t*(2*n+1)).abs
        val f1 = ft(n1)
        val f2 = ft(n1+1)
        val res = if (f1<=f2) n1 else n1+1
        println(res*2+1)
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toLong)
      val (h, c, t) = (input(0), input(1), input(2))

      if (2*t <= h +c) println(2)
      else {
        val n1 = (h-t)/(2 *t-h-c)
        val n2 = n1 + 1

        val f1 = n1*c+(n1+1)*h-(2*n1+1)*t
        val f2 = 2*(n2+1)*t-n2*c-(n2+1)*h
        val res =
          if (f1 <= f2) n1 else n2
        println(res*2+1)
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toInt)
      val (h, c, t) = (input(0), input(1), input(2))
      require(t <= h && t >= c)
      if (4*t >= 3*h+c) println(1)
      else if (2*t <= h+c) println(2)
      else {
        val dn = (t-c)/(2.0*t-h-c)
        val n1 = dn.toDouble.toInt
        val n2 = n1 + 1
        def ft(n: Int) = ((n*h)+(n-1)*c)/(2.0*n-1)
        val c1 = (ft(n1)-t).abs
        val c2 = (ft(n2)-t).abs
        if (c1 < c2) println(n1*2-1) else println(n2*2-1)
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toInt)
      val (h, c, t) = (input(0), input(1), input(2))
      if (2*t <= h +c) println(2)
      else {
        val n1 = (t-c)/(2 *t-h-c)
        def ft(n: Int) = (((n*h)+(n-1)*c)/(2.0*n-1) - t).abs
        val f1 = ft(n1)
        val f2 = ft(n1+1)
        val res = if (f1<=f2) n1 else n1+1
        println((res*2-1) max 1)
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toInt)
      val (h, c, t) = (input(0), input(1), input(2))
      if (2*t <= h +c) println(2)
      else {
        val n1: Long = (t-c)/(2 *t-h-c)
        def ft(n: Long) = ((((n.toLong*h)+(n-1L)*c)/(2.0*n-1)) - t).abs
        val f1 = ft(n1)
        val f2 = ft(n1+1)
        val res = if (f1<=f2) n1 else n1+1
        println(res*2-1)
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toLong)
      val (h, c, t) = (input(0), input(1), input(2))

      if (2*t <= h +c) println(2)
      else {
        val n1 = (h-t)/(2 *t-h-c)
        val n2 = n1 + 1

        val f1 = n1*c+(n1+1)*h-(2*n1+1)*t
        val f2 = 2*(n2+1)*t-n1*c-(n1+1)*h
        val res =
          if (f1 <= f2) n1 else n2
        println(res*2+1)
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toInt)
      val (h, c, t) = (input(0), input(1), input(2))
      if (2*t <= h +c) println(2)
      else {
        val n1 = (t-c)/(2 *t-h-c)
        def ft(n: Int) = (BigDecimal(((n*h)+(n-1)*c)/(2.0*n-1)) - t).abs
        val f1 = ft(n1)
        val f2 = ft(n1+1)
        val res = if (f1<=f2) n1 else n1+1
        println(res*2-1)
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toLong)
      val (h, c, t) = (input(0), input(1), input(2))

      if (2*t <= h +c) println(2)
      else {
        val n1 = (t-c)/(2 *t-h-c)
        def ft(n: Long) = ((n*h+n*c+h)- t*(2*n+1)).abs
        val f1 = ft(n1)
        val f2 = ft(n1+1)
        val res = if (f1<=f2) n1 else n1+1
        println(res*2-1)
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toInt)
      val (h, c, t) = (input(0), input(1), input(2))
      if (t >= h) println(1)
      else if (2*t <= h+c) println(2)
      else {
        val dn = (t-c)/(2.0*t-h-c)
        val n1 = dn.toDouble.toInt
        val n2 = n1 + 1
        def ft(n: Int) = ((n*h)+(n-1)*c)/(2.0*n-1)
        val c1 = (ft(n1)-t).abs
        val c2 = (ft(n2)-t).abs
        if (c1 < c2) println(n1*2-1) else println(n2*2-1)
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toInt)
      val (h, c, t) = (input(0), input(1), input(2))
      require(t <= h && t >= c)
      if (4*t >= 3*h+c) println(1)
      else if (2*t <= h +c) println(2)
      else {
        val dn = (t-c)/(2.0*t-h-c)
        val n1 = dn.toDouble.toInt
        val n2 = n1 + 1
        def ft(n: Int) = ((n*h)+(n-1)*c)/(2.0*n-1)
        val c1 = (ft(n1)-t).abs
        val c2 = (ft(n2)-t).abs
        if ((t-c) % (2*t-h-c) == 0 || c1 <= c2) println(n1*2-1) else println(n2*2-1)
      }
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine().toInt
    for (_ <- 0 until t){
      val input = StdIn.readLine.trim.split(" ").map(_.toInt)
      val (h, c, t) = (input(0), input(1), input(2))
      if (2*t <= h +c) println(2)
      else {
        val n1 = (t-c)/(2 *t-h-c)
        val n2 = n1 + 1
        def ft(n: Int) = ((n*h)+(n-1)*c)/(2.0*n-1) - t
        val c1 = ft(n1).abs
        val c2 = ft(n2).abs
        val res = if ((t-c) % (2*t-h-c) == 0 || c1 <= c2) (n1*2-1) else (n2*2-1)
        println(res max 1)
      }
    }
  }
}

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

  (0 until t).foreach { _ =>
    val Array(h, c, t) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    val d = c + h - 2.0 * t

    val ans =
      if (d == 0) 2
      else 2 * math.ceil((t - h) / d).toInt + 1

    println(ans)
  }
}

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

  (0 until t).foreach { _ =>
    val Array(h, c, t) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    val d = c + h - 2.0 * t

    val ans =
      if (d == 0) 2
      else {
        val r = math.ceil(2 * (t - h) / d + 1).toInt

        if (r == 0) 2
        else r
      }

    println(ans)
  }
}

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

  (0 until t).foreach { _ =>
    val Array(h, c, t) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    val d = c + h - 2.0 * t

    val ans =
      if (d == 0) 2
      else {
        val k = (t - h) / d

        val ks = List(0, 0.5, k.ceil, k.floor)
          .filter(_ >= 0)
          .sortBy(k => math.abs(h - t + k * (c + h - 2 * t)) / (2 * k + 1.0))

        2 * ks.head.toInt + 1
      }

    println(ans)
  }
}

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

  (0 until t).foreach { _ =>
    val Array(h, c, t) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    val d = c + h - 2.0 * t

    val ans =
      if (d == 0) 2
      else if (h <= t) 1
      else {
        val r = math.ceil(2 * (t - h) / d + 1).toInt
        if (r <= 0) 2 else r
      }

    println(ans)
  }
}

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

  (0 until t).foreach { _ =>
    val Array(h, c, t) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    val d = c + h - 2.0 * t

    def diff(k: Double): Double = math.abs((h - t + k * d) / (2 * k + 1))

    val ans =
      if (d == 0) 2
      else {
        val k = (t - h) / d

        if (k < 0) List(1.0, 2.0).sortBy(diff).head.toInt
        else List(k.ceil, k.floor).sortBy(diff).map(2 * _ + 1).head.toInt
      }

    println(ans)
  }
}

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

  (0 until t).foreach { _ =>
    val Array(h, c, t) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    val d = c + h - 2 * t

    val ans =
      if (d >= 0) 2
      else if (h <= t) 1
      else if (c >= t) 2
      else { // c < t < h
        val k  = (t - h) / d.toDouble
        val ks = List(k.ceil, k.floor).sortBy(k => math.abs((h - t + k * d) / (1.0 + 2 * k)))

//        println()
//        println(s"(c + h / 2) ? t = ${c + h - 2 * t}")
//        println(s"ks: ${ks.mkString(", ")}")

        (1 + 2 * ks.head).toInt
      }

    println(ans)
  }
}

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

  (0 until t).foreach { _ =>
    val Array(h, c, t) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    val d = c + h - 2.0 * t

    val ans =
      if (d == 0) 2
      else {
        val r = math.ceil(2 * (t - h) / d + 1).toInt

        if (r <= 0) 2
        else r
      }

    println(ans)
  }
}

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

  (0 until t).foreach { _ =>
    val Array(h, c, t) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    val d = c + h - 2.0 * t

    val ans =
      if (d == 0) 2
      else {
        val k = (t - h) / d

        val ks = List(0.5, k.ceil, k.floor)
          .filter(_ >= 0)
          .sortBy(k => math.abs(h - t + k * (c + h - 2 * t)) / (2 * k + 1.0))

        (2 * ks.head + 1).toInt
      }

    println(ans)
  }
}

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

  (0 until t).foreach { _ =>
    val Array(h, c, t) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

    val d = c + h - 2.0 * t

    def diff(k: Double): Double = math.abs((h - t + k * d) / (2 * k + 1))

    val ans =
      if (d == 0) 2
      else {
        val k = (t - h) / d

        if (k < 0) List(1.0, 2.0).sortBy(k => diff((k - 1) / 2)).head.toInt
        else List(k.ceil, k.floor).sortBy(diff).map(2 * _ + 1).head.toInt
      }

    println(ans)
  }
}


You have a list of numbers from $$$1$$$ to $$$n$$$ written from left to right on the blackboard.You perform an algorithm consisting of several steps (steps are $$$1$$$-indexed). On the $$$i$$$-th step you wipe the $$$i$$$-th number (considering only remaining numbers). You wipe the whole number (not one digit).  When there are less than $$$i$$$ numbers remaining, you stop your algorithm. Now you wonder: what is the value of the $$$x$$$-th remaining number after the algorithm is stopped?

The first line contains one integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. The next $$$T$$$ lines contain queries — one per line. All queries are independent. Each line contains two space-separated integers $$$n$$$ and $$$x$$$ ($$$1 \le x < n \le 10^{9}$$$) — the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least $$$x$$$ numbers.

Print $$$T$$$ integers (one per query) — the values of the $$$x$$$-th number after performing the algorithm for the corresponding queries.

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 private final 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 private final 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 n, x = ni()
      out.println(x * 2)
    }
  }
}

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
  def solve(): Unit = {
    val n = ni()
    val A = na(2*n)
    var i = 1;
    while(i < 2*n){
    	var a = A(i)
		println(2*A(i))
    	i += 2;
    }

  }
}

import Array._
import scala.collection.mutable.ListBuffer

/**
1 2 3 4 5 6 7 8 9 10 11 12
  2 3 4 5 6 7 8 9 10 11 12
  2   4 5 6 7 8 9 10 11 12
  2   4   6 7 8 9 10 11 12
  2   4   6   8 9 10 11 12
  2   4   6   8   10 11 12
  2   4   6   8   10    12
**/

object Main {
    def main(args: Array[String]) {
        val in = new java.util.Scanner(System.in)
        val lineNumber = in.next().toInt
        for ( i <- 0 until lineNumber ) {
            val n = in.next().toInt
            val x = in.next().toInt
            println(x*2)
        }
    }
}


Little X has n distinct integers: p1, p2, ..., pn. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied:  If number x belongs to set A, then number a - x must also belong to set A.  If number x belongs to set B, then number b - x must also belong to set B. Help Little X divide the numbers into two sets or determine that it's impossible.

The first line contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The next line contains n space-separated distinct integers p1, p2, ..., pn (1 ≤ pi ≤ 109).

If there is a way to divide the numbers into two sets, then print "YES" in the first line. Then print n integers: b1, b2, ..., bn (bi equals either 0, or 1), describing the division. If bi equals to 0, then pi belongs to set A, otherwise it belongs to set B. If it's impossible, print "NO" (without the quotes).

NoteIt's OK if all the numbers are in the same set, and the other one is empty.

import scala.collection._

object B 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, a, b) = readInts(3)
  val ps = readInts(n)
  val is = mutable.HashSet.empty ++ ps
  val assign = mutable.HashMap.empty[Int, Int]
  val sorted = ps.zipWithIndex.sortBy(_._1)

  for ((p, i) <- sorted) {
    if (!assign.contains(p)) {
      val ap = a - p
      val bp = b - p
      if (is(ap) && !assign.contains(ap) &&
          !(is(bp) && is(b - ap) && !assign.contains(bp) && !assign.contains(b - ap))) {
        assign.put(p, 0)
        assign.put(ap, 0)
      } else if (is(bp) && !assign.contains(bp)) {
        assign.put(p, 1)
        assign.put(bp, 1)
      } else {
        println("NO")
        System.exit(0)
      }
    }
  }

  println("YES")
  println(ps.map(assign).mkString(" "))
}

import scala.collection._

object B 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, a, b) = readInts(3)
  val ps = readLongs(n)
  val is = mutable.HashSet.empty ++ ps
  val assign = mutable.HashMap.empty[Long, Int]
  val order = ps.zipWithIndex.sortBy(_._1)

  for ((p, i) <- order) {
    if (!assign.contains(ps(i))) {
      if ((is(a - ps(i)) && assign.getOrElse(a - ps(i), 0) == 0 && ps(i) * 2 != a)
          || (ps(i) * 2 == a && !(is(b - ps(i)) && assign.getOrElse(b - ps(i), 1) == 1))) {
        assign.put(ps(i), 0)
        assign.put(a - ps(i), 0)
      } else if (is(b - ps(i)) && assign.getOrElse(b - ps(i), 1) == 1) {
        assign.put(ps(i), 1)
        assign.put(b - ps(i), 1)
      } else {
        println("NO")
        System.exit(0)
      }
    }
  }

  println("YES")
  println(ps.map(assign).mkString(" "))
}

import scala.collection._

object B 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, a, b) = readInts(3)
  val ps = readLongs(n)
  val is = mutable.HashSet.empty ++ ps
  val assign = mutable.HashMap.empty[Long, Int]

  for (i <- ps.indices) {
    if (!assign.contains(ps(i))) {
      if ((is(a - ps(i)) && !assign.contains(a - ps(i)) && ps(i) * 2 != a)
          || (ps(i) * 2 != a && !(is(b - ps(i)) && !assign.contains(b - ps(i))))) {
        assign.put(ps(i), 0)
        assign.put(a - ps(i), 0)
      } else if (is(b - ps(i)) && !assign.contains(b - ps(i))) {
        assign.put(ps(i), 1)
        assign.put(b - ps(i), 1)
      } else {
        println("NO")
        System.exit(0)
      }
    }
  }

  println("YES")
  println(ps.map(assign).mkString(" "))
}

import scala.collection._

object B 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, a, b) = readInts(3)
  val ps = readLongs(n)
  val is = mutable.HashSet.empty ++ ps
  val assign = mutable.HashMap.empty[Long, Int]
  val order = ps.zipWithIndex.sortBy(_._1)

  for ((p, i) <- order) {
    if (!assign.contains(ps(i))) {
      if ((is(a - ps(i)) && !assign.contains(a - ps(i)) && ps(i) * 2 != a)
          || (ps(i) * 2 == a && !(is(b - ps(i)) && !assign.contains(b - ps(i))))) {
        assign.put(ps(i), 0)
        assign.put(a - ps(i), 0)
      } else if (is(b - ps(i)) && !assign.contains(b - ps(i))) {
        assign.put(ps(i), 1)
        assign.put(b - ps(i), 1)
      } else {
        println("NO")
        System.exit(0)
      }
    }
  }

  println("YES")
  println(ps.map(assign).mkString(" "))
}

import scala.collection._

object B 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, a, b) = readInts(3)
  val ps = readLongs(n)
  val is = mutable.HashSet.empty ++ ps
  val assign = mutable.HashMap.empty[Long, Int]

  for (i <- ps.indices) {
    if (!assign.contains(ps(i))) {
      if ((is(a - ps(i)) && !assign.contains(a - ps(i)) && ps(i) * 2 != a)
          || (ps(i) * 2 == a && !(is(b - ps(i)) && !assign.contains(b - ps(i))))) {
        assign.put(ps(i), 0)
        assign.put(a - ps(i), 0)
      } else if (is(b - ps(i)) && !assign.contains(b - ps(i))) {
        assign.put(ps(i), 1)
        assign.put(b - ps(i), 1)
      } else {
        println("NO")
        System.exit(0)
      }
    }
  }

  println("YES")
  println(ps.map(assign).mkString(" "))
}

import scala.collection._

object B 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, a, b) = readInts(3)
  val ps = readInts(n)
  val is = mutable.HashSet.empty ++ ps
  val assign = mutable.HashMap.empty[Int, Int]

  for (i <- ps.indices) {
    val p = ps(i)
    if (!assign.contains(p)) {
      val ap = a - p
      val bp = b - p
      if (is(ap) && !assign.contains(ap) &&
          !(is(bp) && is(b - ap) && !assign.contains(bp) && !assign.contains(b - ap))) {
        assign.put(p, 0)
        assign.put(ap, 0)
      } else if (is(bp) && !assign.contains(bp)) {
        assign.put(p, 1)
        assign.put(bp, 1)
      } else {
        println("NO")
        System.exit(0)
      }
    }
  }

  println("YES")
  println(ps.map(assign).mkString(" "))
}

import scala.collection._

object B 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, a, b) = readInts(3)
  val ps = readInts(n)
  val is = mutable.HashSet.empty ++ ps
  val assign = mutable.HashMap.empty[Int, Int]

  for (i <- ps.indices) {
    if (!assign.contains(ps(i))) {
      if (is(a - ps(i)) && !assign.contains(a - ps(i))) {
        assign.put(ps(i), 0)
        assign.put(a - ps(i), 0)
      } else if (is(b - ps(i)) && !assign.contains(b - ps(i))) {
        assign.put(ps(i), 1)
        assign.put(b - ps(i), 1)
      } else {
        println("NO")
        System.exit(0)
      }
    }
  }

  println("YES")
  println(ps.map(assign).mkString(" "))
}

import scala.collection._

object B 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, a, b) = readInts(3)
  val ps = readInts(n)
  val is = mutable.Set.empty ++ ps
  val assign = mutable.Map.empty[Int, Int]

  for (i <- ps.indices) {
    if (!assign.contains(ps(i))) {
      if (is(a - ps(i)) && !assign.contains(a - ps(i))) {
        assign.put(ps(i), 0)
        assign.put(a - ps(i), 0)
      } else if (is(b - ps(i)) && !assign.contains(b - ps(i))) {
        assign.put(ps(i), 1)
        assign.put(b - ps(i), 1)
      } else {
        println("NO")
        System.exit(0)
      }
    }
  }

  println("YES")
  println(ps.map(assign).mkString(" "))
}

import scala.collection._

object B 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, a, b) = readInts(3)
  val ps = readInts(n)
  val is = mutable.HashSet.empty ++ ps
  val assign = mutable.HashMap.empty[Int, Int]

  for (i <- ps.indices) {
    if (!assign.contains(ps(i))) {
      if (is(a - ps(i)) && !assign.contains(a - ps(i)) && ps(i) * 2 != a) {
        assign.put(ps(i), 0)
        assign.put(a - ps(i), 0)
      } else if (is(b - ps(i)) && !assign.contains(b - ps(i)) && ps(i) * 2 != b) {
        assign.put(ps(i), 1)
        assign.put(b - ps(i), 1)
      } else {
        println("NO")
        System.exit(0)
      }
    }
  }

  println("YES")
  println(ps.map(assign).mkString(" "))
}


Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris.There are exactly s blocks in Chris's set, each block has a unique number from 1 to s. Chris's teacher picks a subset of blocks X and keeps it to himself. He will give them back only if Chris can pick such a non-empty subset Y from the remaining blocks, that the equality holds:  "Are you kidding me?", asks Chris.For example, consider a case where s = 8 and Chris's teacher took the blocks with numbers 1, 4 and 5. One way for Chris to choose a set is to pick the blocks with numbers 3 and 6, see figure. Then the required sums would be equal: (1 - 1) + (4 - 1) + (5 - 1) = (8 - 3) + (8 - 6) = 7.  However, now Chris has exactly s = 106 blocks. Given the set X of blocks his teacher chooses, help Chris to find the required set Y!

The first line of input contains a single integer n (1 ≤ n ≤ 5·105), the number of blocks in the set X. The next line contains n distinct space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 106), the numbers of the blocks in X. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.

In the first line of output print a single integer m (1 ≤ m ≤ 106 - n), the number of blocks in the set Y. In the next line output m distinct space-separated integers y1, y2, ..., ym (1 ≤ yi ≤ 106), such that the required equality holds. The sets X and Y should not intersect, i.e. xi ≠ yj for all i, j (1 ≤ i ≤ n; 1 ≤ j ≤ m). It is guaranteed that at least one solution always exists. If there are multiple solutions, output any of them.

import scala.collection._

object B extends App {

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

  val n = readInt
  val xSet = mutable.BitSet.empty ++ readInts(n)

  val S = 1000000

  val res = mutable.ArrayBuffer[Int]()
  var debt = 0

  for (x <- 1 to S / 2) {
    val y = S - x + 1
    if (xSet(x) && !xSet(y)) res += y
    else if (!xSet(x) && xSet(y)) res += x
    else if (xSet(x) && xSet(y)) debt += 1
  }

  for (x <- 1 to S / 2) {
    val y = S - x + 1
    if (debt > 0 && !xSet(x) && !xSet(y)) {
      res += x
	  res += y
      debt -= 1
    }
  }

  println(res.size)
  println(res.mkString(" "))
}

import scala.collection._

object B extends App {

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

  val n = readInt
  val xSet = mutable.BitSet.empty ++ readInts(n)

  val S = 1000000

  val res = mutable.ArrayBuffer[Int]()
  var debt = 0

  for (x <- 1 to S / 2) {
    val y = S - x + 1
    if (xSet(x) && !xSet(y)) {
      res += y
      xSet += y
    } else if (!xSet(x) && xSet(y)) {
      res += x
      xSet += x
    } else if (xSet(x) && xSet(y)) {
      debt += 1
    }
  }

  for (x <- 1 to S / 2) {
    val y = S - x + 1
    if (debt > 0 && !xSet(x) && !xSet(y)) {
      res += y
      res += x
      debt -= 1
    }
  }

  println(res.size)
  println(res.mkString(" "))
}

/**
 * I've tried to make this piece of code as readable as possible.
 * Enjoy hacking it!
 */
import scala.collection._

object B extends App {

  def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toInt) }
  def readLongs(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toLong) }
  def readBigs(n: Int) = { val t = tokenizeLine; Array.fill(n)(BigInt(t.nextToken)) }

  val n = readInt
  val xs = readInts(n)
  var xSum = 0L
  for (x <- xs) xSum += x
  xSum -= n

  val xSet = mutable.BitSet.empty ++ xs

  val S = 1000000

  val res = mutable.ArrayBuffer[Int]()
  val used = mutable.BitSet.empty

  for (x <- 1 to S if ! used(x)) {
    val sy = S - x + 1
    if (!xSet(sy)) {
      res += sy
      xSet += sy
    } else {

    }
  }

  println(res.size)
  println(res.mkString(" "))
}