The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row.Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all the houses with larger numbers. In other words, a house is luxurious if the number of floors in it is strictly greater than in all the houses, which are located to the right from it. In this task it is assumed that the heights of floors in the houses are the same.The new architect is interested in n questions, i-th of them is about the following: "how many floors should be added to the i-th house to make it luxurious?" (for all i from 1 to n, inclusive). You need to help him cope with this task.Note that all these questions are independent from each other — the answer to the question for house i does not affect other answers (i.e., the floors to the houses are not actually added).

The first line of the input contains a single number n (1 ≤ n ≤ 105) — the number of houses in the capital of Berland. The second line contains n space-separated positive integers hi (1 ≤ hi ≤ 109), where hi equals the number of floors in the i-th house.

Print n integers a1, a2, ..., an, where number ai is the number of floors that need to be added to the house number i to make it luxurious. If the house is already luxurious and nothing needs to be added to it, then ai should be equal to zero. All houses are numbered from left to right, starting from one.

object B581 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = readLongs(n)
    val max = Array.fill(n)(0L)
    for(i <- n-2 to 0 by -1) {
      max(i) = math.max(max(i+1), in(i+1))
    }
    println(max.zip(in).map{case (m, i) => math.max(0, m-i+1)}.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))
    }
  }

}

object EliteHouse {

  val in = io.Source.stdin.getLines()

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

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

  case class Pair(elements: List[Int], max: Int)

  def solve(houses: Seq[Int]): List[Int] =
    houses.foldRight(Pair(List.empty, 0)) { (currentElement, statusToTheRight) =>
      val maxToTheRight = currentElement max statusToTheRight.max
      val stairsToAdd = if (currentElement > statusToTheRight.max) 0 else statusToTheRight.max - currentElement + 1

      Pair(statusToTheRight.elements.+:(stairsToAdd), maxToTheRight)
    }.elements

  def main(args: Array[String]) {
    val Array(numberOfHouses) = readInts(1)
    val housesHeight = readInts(numberOfHouses)

    println(solve(housesHeight) mkString " ")
  }

}

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

import scala.collection.mutable

object B {

  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 h = new Array[Int](n)
    for (i <- 0 until n) {
      h(i) = nextInt
    }
    val max = new Array[Int](n)
    max(n - 1) = h(n - 1)
    for (i <- n - 2 to 0 by -1) {
      max(i) = Math.max(max(i + 1), h(i))
    }
    for (i <- 0 until n - 1) {
      val m = max(i + 1)
      if (h(i) > m) {
        out.print(s"0 ")
      } else if (h(i) == m) {
        out.print(s"1 ")
      } else
        out.print((m - h(i) + 1) + " ")
    }
    out.print("0")
    return 0
  }
}

import scala.io.StdIn._

object B extends App {
  readLine()
  val A = readLine().split(" ").map(_.toLong)
  val Max = Array.ofDim[Long](A.length)
  val map = new scala.collection.mutable.HashMap[Long, Boolean]()

  var max = A.last
  for (i <- A.length - 1 to 0 by - 1) {
    Max(i) = Math.max(max, A(i))
    max = Max(i)
  }

//  println(Max.mkString(" "))
  println(A.zip(Max).reverse.map{ case (curr, max) =>
//    println(a + " " + b)
    if (max > curr) {
      max - curr + 1
    }
    else {
      val add = map.getOrElse(curr, false)
      map.put(curr, true)
      if (add) 1 else 0
    }
  }.reverse.mkString(" "))

}

import java.util.Scanner
import java.io.BufferedInputStream

object Main extends App {
  implicit val scanner = new Scanner(new BufferedInputStream(System.in))
  def nextInt(implicit in: Scanner) = in.nextInt
  def nextLong(implicit in: Scanner) = in.nextLong

  // main start

  val n = nextInt
  val hs = Array.fill(n)(nextInt)
  var hmax = 0
  for (i <- 1 to n) {
    if (hmax >= hs(n-i)) {
      hs(n-i) = hmax-hs(n-i)+1
    } else {
      hmax = hs(n-i)
      hs(n-i) = 0
    }
  }
  println(hs mkString " ")
}

//Main.main(args)

import java.io._

//581B
object B_LuxuriousHouses {

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

    val n = Integer.parseInt(br.readLine())
    val arrStr = br.readLine().split(" ")
    val arr = arrStr.map { _.toInt}
    val lux = new Array[Int](arr.length)

    var max = 0
    for (i <- n-1 to 0 by -1) {
      if (arr(i) <= max) {
        lux(i) = max + 1 - arr(i)
      } else {
        lux(i) = 0
      }

      if (arr(i) > max) max = arr(i)
    }

    println(lux.mkString(" "))

  }
}

import scala.io.StdIn._
import scala.language.postfixOps

object TaskB extends App {
  readLine
  var maxH = 0
  val res = readLine.split(" ").map(_.toInt).reverse.map { a =>
    val r = math.max(maxH - a + 1, 0)
    maxH = math.max(maxH, a)
    r
  }.reverse.mkString(" ")
  println(res)
}

/**
 * @author netman
 */

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

object HelloWorld {

  class InputReader(reader: BufferedReader) {

    var tokenizer: StringTokenizer = null;

    def this(stream: InputStream) = {
      this(new BufferedReader(new InputStreamReader(stream), (1 << 20)));
    }

    def this(f: File) = {
      this(new BufferedReader(new FileReader(f), (1 << 20)));
    }

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

    def nextInt(): Int = next().toInt

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

    def close() = reader.close();
  }

  class OutputWriter(writer: PrintWriter) {
    def this(stream: OutputStream) {
      this(new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream))));
    }

    def this(f: File) = {
      this(new PrintWriter(new BufferedWriter(new FileWriter(f))));
    }

    def print(x: Any) = writer.print(x);

    def println(x: Any) = writer.println(x);

    def close() = writer.close();
  }

  val in = new InputReader(System.in)
  val out = new OutputWriter(System.out)

  def main(args: Array[String]): Unit = {
    val n = in.nextInt

    val h = Array.fill[Int](n)(in.nextInt)
    var res = new Array[Int](n)

    var maximal = 0

    for (i <- n - 1 to 0 by -1) {
      res(i) = math.max(0, maximal - h(i) + 1)
      maximal = math.max(maximal, h(i))
    }

    for (i <- 0 to n - 1) {
      out.print(res(i) + " ")
    }
    out.println("")

    out.close
  }
}

object Sol {
  import scala.io.StdIn._
  import scala.collection.mutable._

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

    val ab = ArrayBuffer[Int]()
    var largest = scala.Int.MinValue

    for (i <- (0 until arr.length).reverse) {
      if (largest < arr(i)) {
        ab += 0
        largest = arr(i)
      } else {
        ab += largest - arr(i) + 1
      }
    }

    println(ab.reverse.mkString(" "))
  }
}

object Sol {
  import scala.io.StdIn._
  import scala.collection.mutable._

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

    var ab = Array.fill(n)(0)
    var largest = scala.Int.MinValue

    for (i <- (0 until arr.length).reverse) {
      if (largest < arr(i)) {
        ab(i) = 0
        largest = arr(i)
      } else {
        ab(i) = largest - arr(i) + 1
      }
    }

    println(ab.mkString(" "))
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(" ").map(_.toInt)
  val max = data.reverse.scanLeft(0){Math.max}.init.reverse
  val res = data.zip(max).map{
    case(now, max) => Math.max(0, max - now + 1)
  }
  println(res.mkString(" "))
}

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

import scala.collection.mutable

object B {

  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 h = new Array[Int](n)
    for (i <- 0 until n) {
      h(i) = nextInt
    }
    val max = new Array[Int](n)
    max(n - 1) = h(n - 1)
    for (i <- n - 2 to 0 by -1) {
      max(i) = Math.max(max(i + 1), h(i))
    }
    for (i <- 0 until n - 1) {
      val m = max(i)
      if (h(i) > max(i)) {
        out.print(s"0 ")
      } else
        out.print((max(i) - h(i) + 1) + " ")
    }
    out.print("0")
    return 0
  }
}

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

import scala.collection.mutable

object B {

  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 h = new Array[Int](n)
    for (i <- 0 until n) {
      h(i) = nextInt
    }
    val max = new Array[Int](n)
    max(n - 1) = h(n - 1)
    for (i <- n - 2 to 0 by -1) {
      max(i) = Math.max(max(i + 1), h(i))
    }
    for (i <- 0 until n - 1) {
      val m = max(i)
      if (h(i) >= max(i)) {
        out.print(s"0 ")
      } else
        out.print((max(i) - h(i) + 1) + " ")
    }
    out.print("0")
    return 0
  }
}

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

import scala.collection.mutable

object B {

  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 h = new Array[Int](n)
    for (i <- 0 until n) {
      h(i) = nextInt
    }
    val max = new Array[Int](n)
    max(n - 1) = h(n - 1)
    for (i <- n - 2 to 0 by -1) {
      max(i) = Math.max(max(i + 1), h(i))
    }
    for (i <- 0 until n - 1) {
      val m = max(i + 1)
      if (h(i) < max(i + 1)) {
        out.print((max(i + 1) - h(i) + 1) + " ")
      } else {
        out.print(0 + " ")
      }
    }
    out.print("0")
    return 0
  }
}

import scala.io.StdIn._

object B extends App {
  readLine()
  val A = readLine().split(" ").map(_.toLong)
  val Max = Array.ofDim[Long](A.length)
  val map = new scala.collection.mutable.HashMap[Long, Int]()

  var max = A.last
  for (i <- A.length - 1 to 0 by - 1) {
    Max(i) = Math.max(max, A(i))
    max = Max(i)
  }

//  println(Max.mkString(" "))
  println(A.zip(Max).reverse.map{ case (curr, max) =>
//    println(a + " " + b)
    if (max > curr) {
      max - curr + 1
    }
    else {
      val add = map.getOrElse(curr, 0)
      map.put(curr, add + 1)
      add
    }
  }.reverse.mkString(" "))

}

import scala.io.StdIn._

object B extends App {
  readLine()
  val A = readLine().split(" ").map(_.toLong)
  val Max = Array.ofDim[Long](A.length)

  var max = A.last
  for (i <- A.length - 1 to 0 by - 1) {
    Max(i) = Math.max(max, A(i))
    max = Max(i)
  }

//  println(Max.mkString(" "))
  println(A.zip(Max).map { case (a, b) =>
//    println(a + " " + b)
    if (b > a) b - a + 1
    else 0
  } mkString " ")

}

import java.util.Scanner
import java.io.BufferedInputStream

object Main extends App {
  implicit val scanner = new Scanner(new BufferedInputStream(System.in))
  def nextInt(implicit in: Scanner) = in.nextInt
  def nextLong(implicit in: Scanner) = in.nextLong

  // main start

  val n = nextInt
  val hs = Array.fill(n)(nextInt)
  var hmax = hs.last
  for (i <- 1 to n) {
    if (hmax >= hs(n-i)) {
      hs(n-i) = hmax-hs(n-i)+1
    } else {
      hmax = hs(n-i)
      hs(n-i) = 0
    }
  }
  println(hs mkString " ")
}

//Main.main(args)

import java.util.Scanner
import java.io.BufferedInputStream

object Main extends App {
  implicit val scanner = new Scanner(new BufferedInputStream(System.in))
  def nextInt(implicit in: Scanner) = in.nextInt
  def nextLong(implicit in: Scanner) = in.nextLong

  // main start

  val n = nextInt
  val hs = Array.fill(n)(nextInt)
  var hmax = hs.last
  for (i <- 1 to n) {
    val h = hs(n-i)
    hs(n-i) = hmax-h+1
    hmax = if (hmax>h) hmax else h
  }
  println(hs mkString " ")
}

//Main.main(args)

import java.util.Scanner
import java.io.BufferedInputStream

object Main extends App {
  implicit val scanner = new Scanner(new BufferedInputStream(System.in))
  def nextInt(implicit in: Scanner) = in.nextInt
  def nextLong(implicit in: Scanner) = in.nextLong

  // main start

  val n = nextInt
  val hs = Array.fill(n)(nextInt)
  var hmax = hs.last
  for (i <- 1 to n) {
    if (hmax > hs(n-i)) {
      hs(n-i) = hmax-hs(n-i)+1
    } else {
      hmax = hs(n-i)
      hs(n-i) = 0
    }
  }
  println(hs mkString " ")
}

//Main.main(args)

import java.util.Scanner
import java.io.BufferedInputStream

object Main extends App {
  implicit val scanner = new Scanner(new BufferedInputStream(System.in))
  def nextInt(implicit in: Scanner) = in.nextInt
  def nextLong(implicit in: Scanner) = in.nextLong

  // main start

  val n = nextInt
  val hs = Array.fill(n)(nextInt)
  var hmax = hs.last
  for (i <- 1 to n) {
    val h = hs(n-i)
    hs(n-i) = hmax-h+1
    hmax = if (hmax>h) hmax else h
  }
  println(hs.mkString)
}

object Sol {
  import scala.io.StdIn._
  import scala.collection.mutable._

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

    val ab = ArrayBuffer[Int]()
    var largest = scala.Int.MinValue

    for (i <- (0 until arr.length).reverse) {
      if (largest <= arr(i)) {
        ab += 0
        largest = arr(i)
      } else {
        ab += largest - arr(i) + 1
      }
    }

    println(ab.reverse.mkString(" "))
  }
}

object Sol {
  import scala.io.StdIn._
  import scala.collection.mutable._

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

    val ab = ArrayBuffer[Int]()
    var largest = scala.Int.MinValue

    for (i <- (0 until arr.length).reverse) {
      if (largest <= arr(i)) {
        ab += 0
        largest = arr(i)
      } else {
        ab += largest - arr(i) + 1
      }
    }

    println(ab.reverse)
  }
}


A map of some object is a rectangular field consisting of n rows and n columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly k islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to each of them by moving only through sand cells and by moving from a cell only to a side-adjacent cell. The cells are called to be side-adjacent if they share a vertical or horizontal side. It is easy to see that islands do not share cells (otherwise they together form a bigger island).Find a way to cover some cells with sand so that exactly k islands appear on the n × n map, or determine that no such way exists.

The single line contains two positive integers n, k (1 ≤ n ≤ 100, 0 ≤ k ≤ n2) — the size of the map and the number of islands you should form.

If the answer doesn't exist, print "NO" (without the quotes) in a single line. Otherwise, print "YES" in the first line. In the next n lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is the cell covered with sand. The length of each line of the description must equal n. If there are multiple answers, you may print any of them. You should not maximize the sizes of islands.

/**
 *
 * Created by ronaflx on 15-4-3.
 */

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

import scala.Ordering.Implicits._
import scala.collection.mutable.ArrayBuffer

object Codeforces {
  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)
    }
    st.nextToken
  }

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

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

  def lowerBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (!(array(mid) < value)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  def upperBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (value < array(mid)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  val N = 210001;
  val bit: Array[Int] = new Array[Int](N)

  def addBit(pos: Int, value: Int): Unit = {
    var i = pos
    while (i < N) {
      bit(i) += value
      i += (i & (i ^ (i - 1)))
    }
  }

  def getBit(pos: Int): Int = {
    var (i, res) = (pos, 0)
    while (i > 0) {
      res += bit(i)
      i -= (i & (i ^ (i - 1)))
    }
    return res
  }

  def getRange(from: Int, to: Int): Int = {
    return getBit(to) - getBit(from - 1)
  }

  def solve(): Unit = {
    val (n, m) = (nextInt, nextInt)
    val map = Array.ofDim[Char](n, n)
    if ((n * n + 1) / 2 < m) {
      out.println("NO")
    } else {
      out.println("YES")
      var num_land = 0
      for (i <- 0 until n; j <- 0 until n) {
        if (num_land < m && (n & 1) != ((i + j) & 1)) {
          num_land += 1
          map(i)(j) = 'L'
        } else {
          map(i)(j) = 'S'
        }
      }
      map.foreach(line => out.println(line.mkString("")))
    }
  }

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

object B544 extends App {
  import java.util.Scanner
  def apply(problem: String): String = apply(new Scanner(problem))
  def apply(scanner: Scanner): String = format(solve(read(scanner)))
  println(apply(new Scanner(System.in)))
  /***************************************************************************/
  type Input = (Int, Int)

  type Output = Option[List[String]]

  def read(scanner: Scanner): Input = {
    import scanner._
    (nextInt, nextInt)
  }

  def solve(input: Input): Output = {
    val (n, k) = input
    if (k > ((n*n) + 1)/2) {
      None
    } else {
      var tk = k
      val sol = List.tabulate(n, n) {(r, c) =>
        (r%2, c%2) match {
          case (m1, m2) if m1 == m2 && tk > 0 =>
            tk = tk - 1
            'L'
          case _ => 'S'
        }
      }
      Some (sol map {_.mkString})
    }
  }

  def format(result: Output): String = result match {
    case Some(sol) => ("YES" :: sol).mkString("\n")
    case None => "NO"
  }
}

import scala.io.StdIn._

import Math.min

/**
 * Created by slie742 on 18/09/2015.
 */
object SeaAndIslands {

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

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

  def getIsland(n: Int, k: Int) : Option[List[String]] = {
    def go(lineNr: Int, islands: Int, acc: List[String]) : Option[List[String]] = {
      if (lineNr >= n) {
        if (islands == 0) Some(acc) else None
      } else {
        if (islands == 0) {
          go(lineNr + 1, islands, ("S"*n) :: acc)
        } else {
          if (lineNr % 2 == 0) {
            if (islands >= (n+1)/2) { // full line
              val line = "LS"*(n/2) + (if (n%2 == 0) "" else "L")
              go(lineNr+1, islands - (n+1)/2, line :: acc)
            } else {
              val line = "LS"*islands + "S"*(n-2*islands)
              go(lineNr+1, 0, line :: acc)
            }
          } else { // odd Line
            if (islands >= n/2) { // full line
              val line = "SL"*(n/2) + (if (n%2 == 0) "" else "S")
              go(lineNr+1, islands - n/2, line :: acc)
            } else {
              val line = "SL"*islands + "S"*(n-2*islands)
              go(lineNr+1, 0, line :: acc)
            }
          }
        }
      }
    }
    go(0, k, Nil)
  }

  def main(args: Array[String]) {
    val (n,k) = readTuple()

    getIsland(n,k) match {
      case Some(list) =>
        println("YES")
        println(list.mkString("\n"))
      case None       => println("NO")
    }
  }
}

object B544{
  def main(args: Array[String]){
    var Array(n,k) = readLine.split(" ").map(_.toInt)
    if((n*n+1)/2<k){
      println("NO")
    }
    else {
      println("YES")
      for(i <- 0 to n-1){
        if(i%2==0){
          for(j <- 0 to n-1){
            if(j%2==0&&k>0){
              k=k-1
              print("L")
            }
            else {
              print("S")
            }
          }
        }
        else {
          for(j <- 0 to n-1){
            if(j%2==1&&k>0){
              k=k-1
              print("L")
            }
            else {
              print("S")
            }
          }
        }
        println("")
      }
    }

  }
}

/**
 *
 * Created by ronaflx on 15-4-3.
 */

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

import scala.Ordering.Implicits._
import scala.collection.mutable.ArrayBuffer

object Codeforces {
  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)
    }
    st.nextToken
  }

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

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

  def lowerBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (!(array(mid) < value)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  def upperBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (value < array(mid)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  val N = 210001;
  val bit: Array[Int] = new Array[Int](N)

  def addBit(pos: Int, value: Int): Unit = {
    var i = pos
    while (i < N) {
      bit(i) += value
      i += (i & (i ^ (i - 1)))
    }
  }

  def getBit(pos: Int): Int = {
    var (i, res) = (pos, 0)
    while (i > 0) {
      res += bit(i)
      i -= (i & (i ^ (i - 1)))
    }
    return res
  }

  def getRange(from: Int, to: Int): Int = {
    return getBit(to) - getBit(from - 1)
  }

  def solve(): Unit = {
    val (n, m) = (nextInt, nextInt)
    val map = Array.ofDim[Char](n, n)
    if ((n + 1) / 2 < m) {
      out.println("NO")
    } else {
      out.println("YES")
      var num_land = 0
      for (i <- 0 until n; j <- 0 until n) {
        if (num_land < m && (n & 1) == ((i + j) & 1)) {
          num_land += 1
          map(i)(j) = 'L'
        } else {
          map(i)(j) = 'S'
        }
      }
      map.foreach(line => out.println(line.mkString("")))
    }
  }

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

object B544 extends App {
  /********************************[ I/O ]************************************/
  import java.util.Scanner
  val isOnlineJudge = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  //import com.softwaremill.debug.DebugConsole.debug
  def debug(x: Any) = if (!isOnlineJudge) println(x)
  def apply(problem: String): String = apply(new Scanner(problem))
  def apply(scanner: Scanner): String = format(solve(read(scanner)))
  println(apply(new Scanner(System.in)))
  /********************************[ lib ]************************************/
  import scala.collection.mutable
  case class Memo[I, K, O](f: I => O)(implicit encoder: I => K) extends (I => O) {
    val cache = mutable.Map.empty[K, O]
    override def apply(x: I): O = cache.getOrElseUpdate(x, f(x))
  }
  type m_=>[I, O] = Memo[I, I, O]
  /******************************[ solution ]*********************************/
  type Input = (Int, Int)

  type Output = List[String]

  def read(scanner: Scanner): Input = {
    import scanner._
    (nextInt, nextInt)
  }

  def solve(input: Input): Output = {
    val (n, k) = input
    if (k >= (n*n + 1)/2) {
      List("NO")
    } else {
      var tk = k
      val sol = List.tabulate(n, n) {(r, c) =>
        (r%2, c%2) match {
          case (m1, m2) if m1 == m2 && tk > 0 => tk -= 1; 'L'
          case _ => 'S'
        }
      }
      "YES" :: (sol map {_.mkString})
    }
  }

  def format(result: Output): String = result mkString "\n"
}

import scala.io.StdIn._

import Math.min

/**
 * Created by slie742 on 18/09/2015.
 */
object SeaAndIslands {

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

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

  def getIsland(n: Int, k: Int) : Option[List[String]] = {
    def go(lineNr: Int, islands: Int, acc: List[String]) : Option[List[String]] = {
      if (lineNr >= n) {
        if (islands == 0) Some(acc) else None
      } else {
        if (islands == 0) {
          go(lineNr + 1, islands, ("S"*n) :: acc)
        } else {
          if (lineNr % 2 == 0) {
            if (islands >= (n+1)/2) { // full line
              val line = "LS"*(n/2) + (if (n%2 == 0) "" else "L")
              go(lineNr+1, islands - (n+1)/2, line :: acc)
            } else {
              val line = "LS"*islands + "S"*(n-2*islands)
              go(lineNr+1, 0, line :: acc)
            }
          } else { // odd Line
            if (islands >= n/2) { // full line
              val line = "SL"*(n/2) + (if (n%2 == 0) "" else "S")
              go(lineNr+1, islands - n/2, line :: acc)
            } else {
              val line = "SL"*islands + "S"*(n-2*islands)
              go(lineNr+1, 0, line :: acc)
            }
          }
        }
      }
    }
    go(0, k, Nil)
  }

  def main(args: Array[String]) {
    val (n,k) = readTuple()

    getIsland(n,k) match {
      case Some(list) => println(list.mkString("\n"))
      case None       => println("No")
    }
  }
}

import scala.io.StdIn._

import Math.min

/**
 * Created by slie742 on 18/09/2015.
 */
object SeaAndIslands {

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

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

  def getIsland(n: Int, k: Int) : Option[List[String]] = {
    def go(lineNr: Int, islands: Int, acc: List[String]) : Option[List[String]] = {
      if (lineNr >= n) {
        if (islands == 0) Some(acc) else None
      } else {
        if (islands == 0) {
          go(lineNr + 1, islands, ("S"*n) :: acc)
        } else {
          if (lineNr % 2 == 0) {
            if (islands >= (n+1)/2) { // full line
              val line = "LS"*(n/2) + (if (n%2 == 0) "" else "L")
              go(lineNr+1, islands - (n+1)/2, line :: acc)
            } else {
              val line = "LS"*islands + "S"*(n-2*islands)
              go(lineNr+1, 0, line :: acc)
            }
          } else { // odd Line
            if (islands >= n/2) { // full line
              val line = "SL"*(n/2) + (if (n%2 == 0) "" else "S")
              go(lineNr+1, islands - n/2, line :: acc)
            } else {
              val line = "SL"*islands + "S"*(n-2*islands)
              go(lineNr+1, 0, line :: acc)
            }
          }
        }
      }
    }
    go(0, k, Nil)
  }

  def main(args: Array[String]) {
    val (n,k) = readTuple()

    getIsland(n,k) match {
      case Some(list) =>
        println("YES")
        println(list.mkString("\n"))
      case None       => println("No")
    }
  }
}

/**
 *
 * Created by ronaflx on 15-4-3.
 */

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

import scala.Ordering.Implicits._
import scala.collection.mutable.ArrayBuffer

object Codeforces {
  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)
    }
    st.nextToken
  }

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

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

  def lowerBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (!(array(mid) < value)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  def upperBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (value < array(mid)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  val N = 210001;
  val bit: Array[Int] = new Array[Int](N)

  def addBit(pos: Int, value: Int): Unit = {
    var i = pos
    while (i < N) {
      bit(i) += value
      i += (i & (i ^ (i - 1)))
    }
  }

  def getBit(pos: Int): Int = {
    var (i, res) = (pos, 0)
    while (i > 0) {
      res += bit(i)
      i -= (i & (i ^ (i - 1)))
    }
    return res
  }

  def getRange(from: Int, to: Int): Int = {
    return getBit(to) - getBit(from - 1)
  }

  def solve(): Unit = {
    val (n, m) = (nextInt, nextInt)
    val map = Array.ofDim[Char](n, n)
    if ((n + 1) / 2 < m) {
      out.println("NO")
    } else {
      out.println("YES")
      var num_land = 0
      for (i <- 0 until n; j <- 0 until n) {
        if (num_land < m && (n & 1) == ((i + j) & 1)) {
          num_land += 1
          map(i)(j) = 'L'
        } else {
          map(i)(j) = 'S'
        }
      }
      map.foreach(line => println(line.mkString("")))
    }
  }

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

/**
 *
 * Created by ronaflx on 15-4-3.
 */

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

import scala.Ordering.Implicits._
import scala.collection.mutable.ArrayBuffer

object Codeforces {
  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)
    }
    st.nextToken
  }

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

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

  def lowerBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (!(array(mid) < value)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  def upperBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (value < array(mid)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  val N = 210001;
  val bit: Array[Int] = new Array[Int](N)

  def addBit(pos: Int, value: Int): Unit = {
    var i = pos
    while (i < N) {
      bit(i) += value
      i += (i & (i ^ (i - 1)))
    }
  }

  def getBit(pos: Int): Int = {
    var (i, res) = (pos, 0)
    while (i > 0) {
      res += bit(i)
      i -= (i & (i ^ (i - 1)))
    }
    return res
  }

  def getRange(from: Int, to: Int): Int = {
    return getBit(to) - getBit(from - 1)
  }

  def solve(): Unit = {
    val (n, m) = (nextInt, nextInt)
    val map = Array.ofDim[Char](n, n)
    if ((n * n + 1) / 2 < m) {
      out.println("NO")
    } else {
      out.println("YES")
      var num_land = 0
      for (i <- 0 until n; j <- 0 until n) {
        if (num_land < m && (n & 1) == ((i + j) & 1)) {
          num_land += 1
          map(i)(j) = 'L'
        } else {
          map(i)(j) = 'S'
        }
      }
      map.foreach(line => out.println(line.mkString("")))
    }
  }

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


You are given $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$. Consider graph on $$$n$$$ nodes, in which nodes $$$i$$$, $$$j$$$ ($$$i\neq j$$$) are connected if and only if, $$$a_i$$$ AND $$$a_j\neq 0$$$, where AND denotes the bitwise AND operation.Find the length of the shortest cycle in this graph or determine that it doesn't have cycles at all.

The first line contains one integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ — number of numbers. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^{18}$$$).

If the graph doesn't have any cycles, output $$$-1$$$. Else output the length of the shortest cycle.

NoteIn the first example, the shortest cycle is $$$(9, 3, 6, 28)$$$.In the second example, the shortest cycle is $$$(5, 12, 9)$$$.The graph has no cycles in the third example.

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object B extends App {

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

  val Array(n) = readInts(1)
  val as = readLongs(n).filterNot(_ == 0)

  val edges = ArrayBuffer.empty[ArrayBuffer[Int]]
  val bits = Array.fill(64)(0)

  var res = -1

  var i = 0
  while (i < as.length) {
    val a = as(i)
    edges += ArrayBuffer.empty[Int]
    for (j <- 0 until i) {
      if ((a & as(j)) != 0) {
        edges(i) += j
        edges(j) += i
      }
    }
    for (b <- 0 to 63) {
      val bit = 1L << b
      if ((a & bit) != 0) {
        bits(b) += 1
        if (bits(b) >= 3) {
          i = n
          res = 3
        }
      }
    }
    i += 1
  }

  val visited = mutable.BitSet.empty

  def dfs(start: Int, u: Int, prev: Int, depth: Int): Unit = {
    if (u == start && prev >= 0) {
      if (res == -1 || depth < res) {
        res = depth
      }
    } else if (res == -1 || depth + 1 < res) {
      visited(u) = true
      for (v <- edges(u)) {
        if ((!visited(v) || v == start) && v != prev) dfs(start, v, u, depth + 1)
      }
      visited(u) = false
    }
  }

  if (res == -1) {
    for (u <- edges.indices) dfs(u, u, -1, 0)
  }

  println(res)
}

object B extends App {

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

  val Array(n) = readInts(1)
  //val as = Array.fill(n)(Long.MaxValue)
  val as = readLongs(n)

  val edges = Array.fill(64, 64)(0)
  val edges2 = Array.fill(64, 64)(0)

  var res = -1

  var k = 0
  while (k < n) {
    val a = as(k)
    var i = 0
    while (i < 63) {
      val bit = 1L << i
      if ((a & bit) != 0) {
        var j = i + 1
        while (j < 64) {
          val bit2 = 1L << j
          if ((a & bit2) != 0) {
            edges(i)(j) += 1
            edges(j)(i) += 1
            edges2(i)(j) = k
            edges2(j)(i) = k
            if (edges(i)(j) >= 3) {
              k = n
              res = 3
            }
          }
          j += 1
        }
      }
      i += 1
    }
    k += 1
  }

  val visited = Array.fill(64)(false)
  //val used = Array.fill(n)(false)

  def dfs(start: Int, u: Int, prev: Int, depth: Int, prevA: Int): Unit = {
    //println(start, u, prev, depth)
    if (u == start && prev >= 0) {
      if (res == -1 || depth < res) {
        //println((0 to 63).filter(visited), depth)
        res = depth
      }
    } else if (res == -1 || depth + 1 < res) {
      //println(start, u, prev, depth)
      //if (prev >= 0) used(edges2(u)(prev)) = true
      visited(u) = true
      var v = 0
      while (v < 64) {
        if ((!visited(v) || v == start) && v != prev &&
          (edges(u)(v) > 1 || (edges(u)(v) == 1 && edges2(u)(v) != prevA))) dfs(start, v, u, depth + 1, edges2(u)(v))
        v += 1
      }
      //if (prev >= 0) used(edges2(u)(prev)) = true
      visited(u) = false
    }
  }

  if (res == -1) {
    for (u <- 0 until 64) dfs(u, u, -1, 0, -1)
  }

//  val range = 0 until
//  for (k <- range) {
//    for (i <- range) if (w(i)(k) != Int.MaxValue) {
//      for (j <- range) if (w(k)(j) != Int.MaxValue) {
//        val ww = w(i)(k) + w(k)(j)
//        if (ww < w(i)(j)) {
//          w(i)(j) = ww
//          next(i)(j) = k
//          // The path from i to j is the path from i to next(i)(j), followed by the path from next(i)(j) to j
//        }
//      }
//    }
//  }
//
  println(res)
}

object B extends App {

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

  val Array(n) = readInts(1)
  //val as = Array.fill(n)(Long.MaxValue)
  val as = readLongs(n)

  val edges = Array.fill(64, 64)(0)
  val edges2 = Array.fill(64, 64)(0)
  val bits = Array.fill(64)(0)

  var res = -1

  var k = 0
  while (k < n) {
    val a = as(k)
    var i = 0
    while (i < 63) {
      val bit = 1L << i
      if ((a & bit) != 0) {
        bits(i) += 1
        if (bits(i) >= 3) {
          k = n
          res = 3
        }
        var j = i + 1
        while (j < 64) {
          val bit2 = 1L << j
          if ((a & bit2) != 0) {
            edges(i)(j) += 1
            edges(j)(i) += 1
            edges2(i)(j) = k
            edges2(j)(i) = k
          }
          j += 1
        }
      }
      i += 1
    }
    k += 1
  }

  val visited = Array.fill(64)(false)
  val used = Array.fill(n)(false)

  def dfs(start: Int, u: Int, prev: Int, depth: Int, prevA: Int): Unit = {
    if (u == start && prev >= 0) {
      if (res == -1 || depth < res) {
        res = depth
      }
    } else if (res == -1 || depth < res) {
      visited(u) = true
      var v = 0
      while (v < 64) {
        if ((!visited(v) || v == start) && v != prev &&
          (edges(u)(v) > 1 || (edges(u)(v) == 1 && edges2(u)(v) != prevA))) dfs(start, v, u, depth + 1, edges2(u)(v))
        v += 1
      }
      visited(u) = false
    }
  }

  if (res == -1) {
    for (u <- 0 until 64) dfs(u, u, -1, 0, -1)
  }

  println(res)
}

object B extends App {

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

  val Array(n) = readInts(1)
  //val as = Array.fill(n)(Long.MaxValue)
  val as = readLongs(n)

  val edges = Array.fill(64, 64)(0)
  val edges2 = Array.fill(64, 64)(0)

  var res = -1

  var k = 0
  while (k < n) {
    val a = as(k)
    var i = 0
    while (i < 63) {
      val bit = 1L << i
      if ((a & bit) != 0) {
        var j = i + 1
        while (j < 64) {
          val bit2 = 1L << j
          if ((a & bit2) != 0) {
            edges(i)(j) += 1
            edges(j)(i) += 1
            edges2(i)(j) = k
            edges2(j)(i) = k
            if (edges(i)(j) >= 3) {
              k = n
              res = 3
            }
          }
          j += 1
        }
      }
      i += 1
    }
    k += 1
  }

  val visited = Array.fill(64)(false)
  val used = Array.fill(n)(false)

  def dfs(start: Int, u: Int, prev: Int, depth: Int): Unit = {
    //println(start, u, prev, depth)
    if (u == start && prev >= 0) {
      if (res == -1 || depth < res) {
        //println((0 to 63).filter(visited), depth)
        res = depth
      }
    } else if (res == -1 || depth + 1 < res) {
      //println(start, u, prev, depth)
      if (prev >= 0) used(edges2(u)(prev)) = true
      visited(u) = true
      var v = 0
      while (v < 64) {
        if ((!visited(v) || v == start) && v != prev &&
          (edges(u)(v) > 1 || (edges(u)(v) == 1 && !used(edges2(u)(v))))) dfs(start, v, u, depth + 1)
        v += 1
      }
      if (prev >= 0) used(edges2(u)(prev)) = true
      visited(u) = false
    }
  }

  if (res == -1) {
    for (u <- 0 until 64) dfs(u, u, -1, 0)
  }

//  val range = 0 until
//  for (k <- range) {
//    for (i <- range) if (w(i)(k) != Int.MaxValue) {
//      for (j <- range) if (w(k)(j) != Int.MaxValue) {
//        val ww = w(i)(k) + w(k)(j)
//        if (ww < w(i)(j)) {
//          w(i)(j) = ww
//          next(i)(j) = k
//          // The path from i to j is the path from i to next(i)(j), followed by the path from next(i)(j) to j
//        }
//      }
//    }
//  }
//
  println(res)
}

object B extends App {

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

  val Array(n) = readInts(1)
  //val as = Array.fill(n)(Long.MaxValue)
  val as = readLongs(n)

  val edges = Array.fill(64, 64)(0)
  val edges2 = Array.fill(64, 64)(0)

  var k = 0
  while (k < n) {
    val a = as(k)
    var i = 0
    while (i < 63) {
      val bit = 1L << i
      if ((a & bit) != 0) {
        var j = i + 1
        while (j < 64) {
          val bit2 = 1L << j
          if ((a & bit2) != 0) {
            edges(i)(j) += 1
            edges(j)(i) += 1
            edges2(i)(j) = k
            edges2(j)(i) = k
            if (edges(i)(j) >= 3) k = n
          }
          j += 1
        }
      }
      i += 1
    }
    k += 1
  }

  var res = -1
  val visited = Array.fill(64)(false)
  //val used = Array.fill(n)(false)

  def dfs(start: Int, u: Int, prev: Int, depth: Int, prevA: Int): Unit = {
    //println(start, u, prev, depth)
    if (u == start && prev >= 0) {
      if (res == -1 || depth < res) {
        //println((0 to 63).filter(visited), depth)
        res = depth
      }
    } else if (res == -1 || depth + 1 < res) {
      //println(start, u, prev, depth)
      //if (prev >= 0) used(edges2(u)(prev)) = true
      visited(u) = true
      var v = 0
      while (v < 64) {
        if ((!visited(v) || v == start) && v != prev &&
          (edges(u)(v) > 1 || (edges(u)(v) == 1 && edges2(u)(v) != prevA))) dfs(start, v, u, depth + 1, edges2(u)(v))
        v += 1
      }
      //if (prev >= 0) used(edges2(u)(prev)) = true
      visited(u) = false
    }
  }

  for (i <- 0 until 64) {
    for (j <- i + 1 until 63) {
      if (edges(i)(j) >= 3) res = 3
    }
  }

  if (res == -1) {
    for (u <- 0 until 64) dfs(u, u, -1, 0, -1)
  }

//  val range = 0 until
//  for (k <- range) {
//    for (i <- range) if (w(i)(k) != Int.MaxValue) {
//      for (j <- range) if (w(k)(j) != Int.MaxValue) {
//        val ww = w(i)(k) + w(k)(j)
//        if (ww < w(i)(j)) {
//          w(i)(j) = ww
//          next(i)(j) = k
//          // The path from i to j is the path from i to next(i)(j), followed by the path from next(i)(j) to j
//        }
//      }
//    }
//  }
//
  println(res)
}

object B extends App {

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

  val Array(n) = readInts(1)
  //val as = Array.fill(n)(Long.MaxValue)
  val as = readLongs(n)

  val edges = Array.fill(64, 64)(0)
  val edges2 = Array.fill(64, 64)(0)

  var res = -1

  var k = 0
  while (k < n) {
    val a = as(k)
    var i = 0
    while (i < 63) {
      val bit = 1L << i
      if ((a & bit) != 0) {
        var j = i + 1
        while (j < 64) {
          val bit2 = 1L << j
          if ((a & bit2) != 0) {
            edges(i)(j) += 1
            edges(j)(i) += 1
            edges2(i)(j) = k
            edges2(j)(i) = k
            if (edges(i)(j) >= 3) {
              k = n
              res = 3
            }
          }
          j += 1
        }
      }
      i += 1
    }
    k += 1
  }

  val visited = Array.fill(64)(false)
  val used = Array.fill(n)(false)

  def dfs(start: Int, u: Int, prev: Int, depth: Int, prevA: Int): Unit = {
    //println(start, u, prev, depth)
    if (u == start && prev >= 0) {
      if (res == -1 || depth < res) {
        //println((0 to 63).filter(visited), depth)
        res = depth
      }
    } else if (res == -1 || depth < res) {
      //println(start, u, prev, depth)
      //if (prev >= 0) used(edges2(u)(prev)) = true
      visited(u) = true
      var v = 0
      while (v < 64) {
        if ((!visited(v) || v == start) && v != prev &&
          (edges(u)(v) > 1 || (edges(u)(v) == 1 && edges2(u)(v) != prevA))) dfs(start, v, u, depth + 1, edges2(u)(v))
        v += 1
      }
      //if (prev >= 0) used(edges2(u)(prev)) = true
      visited(u) = false
    }
  }

  if (res == -1) {
    for (u <- 0 until 64) dfs(u, u, -1, 0, -1)
  }

//  val range = 0 until
//  for (k <- range) {
//    for (i <- range) if (w(i)(k) != Int.MaxValue) {
//      for (j <- range) if (w(k)(j) != Int.MaxValue) {
//        val ww = w(i)(k) + w(k)(j)
//        if (ww < w(i)(j)) {
//          w(i)(j) = ww
//          next(i)(j) = k
//          // The path from i to j is the path from i to next(i)(j), followed by the path from next(i)(j) to j
//        }
//      }
//    }
//  }
//
  println(res)
}


Polycarp has built his own web service. Being a modern web service it includes login feature. And that always implies password security problems.Polycarp decided to store the hash of the password, generated by the following algorithm:  take the password $$$p$$$, consisting of lowercase Latin letters, and shuffle the letters randomly in it to obtain $$$p'$$$ ($$$p'$$$ can still be equal to $$$p$$$);  generate two random strings, consisting of lowercase Latin letters, $$$s_1$$$ and $$$s_2$$$ (any of these strings can be empty);  the resulting hash $$$h = s_1 + p' + s_2$$$, where addition is string concatenation. For example, let the password $$$p =$$$ "abacaba". Then $$$p'$$$ can be equal to "aabcaab". Random strings $$$s1 =$$$ "zyx" and $$$s2 =$$$ "kjh". Then $$$h =$$$ "zyxaabcaabkjh".Note that no letters could be deleted or added to $$$p$$$ to obtain $$$p'$$$, only the order could be changed.Now Polycarp asks you to help him to implement the password check module. Given the password $$$p$$$ and the hash $$$h$$$, check that $$$h$$$ can be the hash for the password $$$p$$$.Your program should answer $$$t$$$ independent test cases.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains a non-empty string $$$p$$$, consisting of lowercase Latin letters. The length of $$$p$$$ does not exceed $$$100$$$. The second line of each test case contains a non-empty string $$$h$$$, consisting of lowercase Latin letters. The length of $$$h$$$ does not exceed $$$100$$$.

For each test case print the answer to it — "YES" if the given hash $$$h$$$ could be obtained from the given password $$$p$$$ or "NO" otherwise.

5
abacaba
zyxaabcaabkjh
onetwothree
threetwoone
one
zzonneyy
one
none
twenty
ten

NoteThe first test case is explained in the statement.In the second test case both $$$s_1$$$ and $$$s_2$$$ are empty and $$$p'=$$$ "threetwoone" is $$$p$$$ shuffled.In the third test case the hash could not be obtained from the password.In the fourth test case $$$s_1=$$$ "n", $$$s_2$$$ is empty and $$$p'=$$$ "one" is $$$p$$$ shuffled (even thought it stayed the same). In the fifth test case the hash could not be obtained from the password.

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
  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[Int]]): 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 = {
    if (oj){ System.err.println(s) }
  }
  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 = _

    private[this] 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._
  import java.util.Arrays.sort

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

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 solve2(): Boolean = {
    val P, H = ns()
    if (P.length > H.length) return false

    val C = Array.ofDim[Int](26)
    REP(P.length) { i =>
      C(P(i)-'a') += 1
    }

    REP(H.length - P.length + 1) { i =>
      val D = Array.ofDim[Int](26)
      REP(P.length) { j =>
        D(H(i + j)-'a') += 1
      }
      var ok = true
      REP(26) { c =>
        ok &&= C(c) == D(c)
      }
      if (ok) return true
    }
    false
  }

  def solve(): Unit = {
    REP(ni()) { _ =>
      if (solve2()) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    }
  }
}

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

  override def solve(io: IO) = io.repeat {
    val p = io.read[String].sorted
    val h = io.read[String]
    val ans = h.sliding(p.length).exists(_.sorted == p)
    io.write(ans.toEnglish.toUpperCase)
  }
}
/****************************[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 solve(io: IO): Any
  def main(args: Array[String]): Unit = {
    val io = new IO(System.in, System.out)
    try solve(io) finally io.close()
  }
}
/****************************[Scala Collection Utils]****************************************/
object Utils {
  import scala.collection.mutable

  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]

  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)

  implicit class GenericExtensions[A](a: A) {
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }

  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](t: C[A]) {
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]

    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)

    def toMultiSet(withDefaultZero: Boolean): Map[A, Int] = {
      val freqTable = t.groupBy(identity).mapValues(_.size)
      if (withDefaultZero) freqTable.withDefaultValue(0) else freqTable
    }
  }

  implicit class PairExtensions[A, B](p: (A, B)) {
    def key = p._1
    def value = p._2
    def toSeq(implicit ev: B =:= A): Seq[A] = Seq(p.key, ev(p.value))
  }

  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C]).withDefaultValue(b().result())
  }

  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](m: C[K, V]) {
    def toMutable: mutable.Map[K, V] = mutable.Map.empty[K, V] ++ m
  }

  implicit class SetExtensions[A, C[A] <: Set[A]](s: C[A]) {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }

  implicit class IterableExtensions[A, C[A] <: Seq[A]](s: C[A]) {
    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
  }

  implicit class BooleanExtensions(x: Boolean) {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "Yes" else "No"
  }

  implicit class IntExtensions(val x: Int) extends AnyVal {
    @inline def isEven = x%2 == 0
    @inline def isOdd = x%2 == 1
  }

  def desc[A](implicit order: Ordering[A]): Ordering[A] = order.reverse  //e.g. students.sortBy(_.height)(desc)

  def map[K] = new {
    def to[V](default: => V): mutable.Map[K, V] = using(_ => default)
    def using[V](f: K => V): mutable.Map[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }

  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]

  def memoize[A, B](f: A => B): A => B = map[A] using f
}
/***********************************[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")

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

  def write(obj: Any*): this.type = writeAll(obj)
  def writeLine(obj: Any*): this.type = {if (obj.isEmpty) printer.println() else obj.foreach(printer.println); this}
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = {printer.print(obj.mkString(separator)); this}
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  def repeat(f: => Unit): Unit = Utils.repeat(read[Int]){f; writeLine()}

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


Valera had two bags of potatoes, the first of these bags contains x (x ≥ 1) potatoes, and the second — y (y ≥ 1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains x potatoes) Valera lost. Valera remembers that the total amount of potatoes (x + y) in the two bags, firstly, was not gerater than n, and, secondly, was divisible by k.Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.

The first line of input contains three integers y, k, n (1 ≤ y, k, n ≤ 109;   ≤ 105).

Print the list of whitespace-separated integers — all possible values of x in ascending order. You should print each possible value of x exactly once. If there are no such values of x print a single integer -1.

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(y, k, n) = in.next().split(" ").map(_.toInt)
  val res = (y / k to n / k + 1).map(i => i * k - y)
    .filter(j => j > 0 && j + y <= n)
    .mkString(" ")
  if (res.isEmpty)
    println(-1)
  else
    println(res)
}

import java.util.Scanner

object A extends App {
	val in = new Scanner(System.in)
	val y = in.nextInt()
	val k = in.nextInt()
	val n = in.nextInt()
	val m = ((1 + y).toDouble / k.toDouble).ceil.toInt
	if (m * k > n) {
		println(-1)
	} else {
		val sb = new StringBuilder
		for (i <- m * k to n by k) {
			sb.append(i - y)
			sb.append(' ')
		}
		sb.deleteCharAt(sb.length - 1)
		println(sb)
	}
}

import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val y, k, n = sc.nextInt()
  val ans = List.range(k - (y % k), n - y + 1, k)
  println(if (ans.isEmpty) "-1" else ans.mkString(" "))
}

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

object P239A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  val Y, K, N = sc.nextInt

  def solve(): String = {
    val xys = List.range((Y / K + 1) * K, N + 1, K)
    if (xys.size == 0) "-1"
    else xys.map(_ - Y).mkString(" ")
  }

  out.println(solve)
  out.close
}

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

object Main extends App {
  val in = new MyScanner()
  var y, k, n = in.nextInt

  var ost = k - (y % k)
  if (ost + y > n)
    println(-1)
  else
    while (y + ost <= n) {
      print(ost + " ")
      ost += k
    }
}

class MyScanner {
  val in = new BufferedReader(new InputStreamReader(System.in))
  var buffer = in.readLine().split(" ")
  var pos = 0

  def nextInt: Int = {
    if (buffer == null) {
      buffer = in.readLine().split(" ")
      pos = 0
    }
    if (buffer.length <= pos) {
      buffer = in.readLine().split(" ")
      pos = 0
    }
    pos = pos + 1
    buffer(pos - 1).toInt
  }

  def nextString: String = {
    if (buffer == null) {
      buffer = in.readLine().split(" ")
      pos = 0
    }
    if (buffer.length <= pos) {
      buffer = in.readLine().split(" ")
      pos = 0
    }
    pos += 1
    buffer(pos - 1)
  }
}

import java.io.InputStreamReader
import java.io.BufferedReader
import java.util.Scanner

object Main extends App {
  val in = new Scanner(new InputStreamReader(System.in))
  var y, k, n = in.nextInt()

  var ost = k - (y % k)
  if (ost + y > n)
    println(-1)
  else
    while (y + ost <= n) {
      print(ost + " ")
      ost += k
    }
}

class MyScanner {
  val in = new BufferedReader(new InputStreamReader(System.in))
  var buffer = in.readLine().split(" ")
  var pos = 0

  def nextInt: Int = {
    if (buffer == null) {
      buffer = in.readLine().split(" ")
      pos = 0
    }
    if (buffer.length <= pos) {
      buffer = in.readLine().split(" ")
      pos = 0
    }
    pos = pos + 1
    buffer(pos - 1).toInt
  }

  def nextString: String = {
    if (buffer == null) {
      buffer = in.readLine().split(" ")
      pos = 0
    }
    if (buffer.length <= pos) {
      buffer = in.readLine().split(" ")
      pos = 0
    }
    pos += 1
    buffer(pos - 1)
  }
}

object Main extends App {
  val in = new MyScanner
  var y, k, n = in.nextInt

  var ost = k - (y % k)
  if (ost + y > n)
    println(-1)
  else
    while (y + ost <= n) {
      print(ost + " ")
      ost += k
    }
}

class MyScanner {
  var buffer = readLine().split(" ")
  var pos = 0

  def nextInt: Int = {
    if (buffer == null) {
      buffer = readLine().split(" ")
      pos = 0
    }
    if (buffer.length <= pos) {
      buffer = readLine().split(" ")
      pos = 0
    }
    pos = pos + 1
    buffer(pos - 1).toInt
  }

  def nextString: String = {
    if (buffer == null) {
      buffer = readLine().split(" ")
      pos = 0
    }
    if (buffer.length <= pos) {
      buffer = readLine().split(" ")
      pos = 0
    }
    pos += 1
    buffer(pos - 1)
  }
}

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

object Main extends App {
  val Array(y, k, n) = readLine().split(' ').map(Integer.parseInt(_))
  var ost = k - (y % k)
  if (ost + y > n)
    println(-1)
  else
    while (y + ost <= n) {
      print(ost + " ")
      ost += k
    }
}

class MyScanner {
  val in = new BufferedReader(new InputStreamReader(System.in))
  var buffer = in.readLine().split(" ")
  var pos = 0

  def nextInt: Int = {
    if (buffer == null) {
      buffer = in.readLine().split(" ")
      pos = 0
    }
    if (buffer.length <= pos) {
      buffer = in.readLine().split(" ")
      pos = 0
    }
    pos = pos + 1
    buffer(pos - 1).toInt
  }

  def nextString: String = {
    if (buffer == null) {
      buffer = in.readLine().split(" ")
      pos = 0
    }
    if (buffer.length <= pos) {
      buffer = in.readLine().split(" ")
      pos = 0
    }
    pos += 1
    buffer(pos - 1)
  }
}

object CodeForces {

  def main(args: Array[String]) = {
    val cin = new java.util.Scanner(System.in)
    val y = cin.nextInt()
    val k = cin.nextInt()
    val n = cin.nextInt()
    val res = for ( it <- 1 to n / k; if  it * k -  y > 0 ) yield it * k -  y
    if (res.length == 0) System.out.println(-1)
    else for (it <- res) System.out.print(it + " ")

  }
}

import java.util.Scanner

object A extends App
{
    val cin=new Scanner(System.in);
    while(cin.hasNext())
    {
        val y,k,n=cin.nextInt();
        val ans =for { x_y <- List.range(0,n+1,k) ; if x_y>y } yield(x_y-y);
        if(ans.isEmpty) System.out.println(-1);
        else System.out.println(ans.mkString(" "));
    }
}

object Main {
  def main(args: Array[String]): Unit = {
    val ynk = readLine().split(" ").map(_.toInt)
    val y = ynk(0)
    val n = ynk(2)
    val k = ynk(1)

    val start =
      if (k == 1) y + 1
      else (y / k + 1) * k
    if (start > n) println("-1")
    else println( (start to n by k).map(_ - y).mkString(" ") )
  }
}

object Olymp{
  def main(args: Array[String]): Unit = {
	val Array(y, k, n) = readLine.split(' ').map(Integer.parseInt(_))

	def from(x: Int): Stream[Int] = x #:: from(x + k)

	val ans = from(k - y % k).takeWhile(_ + y <= n)

	if (ans.isEmpty) println(-1)
	else for { i <- ans } print(i + " ")
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(y, k, n) = in.next().split(" ").map(_.toInt)
  val res = (1 to (n - y) / k + 1).map(i => i * k - y).filter(j => j > 0 && j + y <= n).mkString(" ")
  if (res.isEmpty)
    println(-1)
  else
    println(res)
}

import java.util.Scanner

object A extends App {
	val in = new Scanner(System.in)
	val y = in.nextInt()
	val k = in.nextInt()
	val n = in.nextInt()
	val begin = (y / k + 1) * k
	if (n - begin < 1) {
		println(-1)
	} else {
		val sb = new StringBuilder
		for (i <- begin to n by k) {
			sb.append(i - y)
			sb.append(' ')
		}
		sb.deleteCharAt(sb.size - 1)
		println(sb)
	}
}

object Main {
  def main(args: Array[String]): Unit = {
    val ynk = readLine().split(" ").map(_.toInt)
    val y = ynk(0)
    val n = ynk(2)
    val k = ynk(1)

    val start = ((y + k - 1) / k) * k
    if (start >= n) println("-1")
    else println( (start until n by k).map(_ - y).mkString(" ") )
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val ynk = readLine().split(" ").map(_.toInt)
    val y = ynk(0)
    val n = ynk(2)
    val k = ynk(1)

    val start = ((y + k - 1) / k) * k
    if (start >= n) println(n)
    else println( (start to n by k).map(_ - y).mkString(" ") )
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val ynk = readLine().split(" ").map(_.toInt)
    val y = ynk(0)
    val n = ynk(2)
    val k = ynk(1)

    val start =
      if (k == 1) y + 1
      else ((y + k - 1) / k) * k
    if (start > n) println("-1")
    else println( (start to n by k).map(_ - y).mkString(" ") )
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val ynk = readLine().split(" ").map(_.toInt)
    val y = ynk(0)
    val n = ynk(2)
    val k = ynk(1)

    val start =
      if (k == 1) y + 1
      else ((y + k - 1) / k) * k
    if (start >= n) println("-1")
    else println( (start to n by k).map(_ - y).mkString(" ") )
  }
}


Today, Marin is at a cosplay exhibition and is preparing for a group photoshoot!For the group picture, the cosplayers form a horizontal line. A group picture is considered beautiful if for every contiguous segment of at least $$$2$$$ cosplayers, the number of males does not exceed the number of females (obviously).Currently, the line has $$$n$$$ cosplayers which can be described by a binary string $$$s$$$. The $$$i$$$-th cosplayer is male if $$$s_i = 0$$$ and female if $$$s_i = 1$$$. To ensure that the line is beautiful, you can invite some additional cosplayers (possibly zero) to join the line at any position. You can't remove any cosplayer from the line.Marin wants to know the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is beautiful. She can't do this on her own, so she's asking you for help. Can you help her?

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases.  The first line of each test case contains a positive integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of cosplayers in the initial line. The second line of each test case contains a binary string $$$s$$$ of length $$$n$$$ — describing the cosplayers already in line. Each character of the string is either 0 describing a male, or 1 describing a female. Note that there is no limit on the sum of $$$n$$$.

For each test case, print the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is beautiful.

NoteIn the first test case, for each pair of adjacent cosplayers, you can invite two female cosplayers to stand in between them. Then, $$$000 \rightarrow 0110110$$$.In the third test case, you can invite one female cosplayer to stand next to the second cosplayer. Then, $$$010 \rightarrow 0110$$$.

import scala.io.StdIn.readLine

object Solution {

  def solve() = {

    def recur(s: String, count: Int = 0): Int = {
      if (s.isEmpty) 0
      else if (s.head == '1') recur(s.tail, count + 1)
      else if (count < 2) 2 - count + recur(s.tail, 0)
      else recur(s.tail, 0)
    }
    val cos = readLine().toInt
    val line = readLine()
    // male, female
    recur(line.dropWhile(_ == '1'), '1')
  }

  def main(args: Array[String]): Unit = {
    val cases = readLine.toInt

    for (
      i <- 0 until cases
    ) println(solve())
  }
}


While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots operate under deterministic algorithms. In particular, robot i will beat robot j if and only if robot i has a higher skill level than robot j. And if robot i beats robot j and robot j beats robot k, then robot i will beat robot k. Since rapping is such a subtle art, two robots can never have the same skill level.Given the results of the rap battles in the order in which they were played, determine the minimum number of first rap battles that needed to take place before Bessie could order all of the robots by skill level.

The first line of the input consists of two integers, the number of robots n (2 ≤ n ≤ 100 000) and the number of rap battles m (). The next m lines describe the results of the rap battles in the order they took place. Each consists of two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi), indicating that robot ui beat robot vi in the i-th rap battle. No two rap battles involve the same pair of robots. It is guaranteed that at least one ordering of the robots satisfies all m relations.

Print the minimum k such that the ordering of the robots by skill level is uniquely defined by the first k rap battles. If there exists more than one ordering that satisfies all m relations, output -1.

NoteIn the first sample, the robots from strongest to weakest must be (4, 2, 1, 3), which Bessie can deduce after knowing the results of the first four rap battles.In the second sample, both (1, 3, 2) and (3, 1, 2) are possible orderings of the robots from strongest to weakest after both rap battles.

import java.util

import scala.collection._

object D 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, m) = readInts(2)

  val preceedingBuilders, onStepBuilders = Array.fill(n){ new mutable.ArrayBuilder.ofInt }

  for (step <- 1 to m) {
    val Array(u, v) = readInts(2).map(_ - 1)
    preceedingBuilders(u) += v
    onStepBuilders(u) += step
  }

  val preceeding = preceedingBuilders.map(_.result)
  val onStep = onStepBuilders.map(_.result)

  def can(toStep: Int): Boolean = {

    val sortedBuilder = new mutable.ArrayBuilder.ofInt
    val color = Array.fill(n)(0)

    def dfs1(u: Int): Unit = {
      color(u) = 1
      var i = 0
      while (i < preceeding(u).length) {
        if (onStep(u)(i) <= toStep) {
          val v = preceeding(u)(i)
          if (color(v) == 0) dfs1(v)
        }
        i += 1
      }
      color(u) = 2
      sortedBuilder += u
    }

    for (i <- 0 until n) {
      if (color(i) == 0) dfs1(i)
    }

    val sorted = sortedBuilder.result
    val topologicalOrder = Array.ofDim[Int](n)
    for (i <- sorted.indices) topologicalOrder(sorted(i)) = i

    val maxDepth = Array.fill(n){ -1 }

    def dfs2(u: Int): Int = {
      if (maxDepth(u) < 0){
        var depth = 0
        var i = 0
        while (i < preceeding(u).length) {
          val v = preceeding(u)(i)
          if (onStep(u)(i) <= toStep && topologicalOrder(v) < topologicalOrder(u)) {
            depth = depth max dfs2(v)
          }
          i += 1
        }
        maxDepth(u) = depth + 1
      }
      maxDepth(u)
    }
    //println(sorted.mkString(" "), dfs2(sorted.last))
    dfs2(sorted.last) == n
  }

  @annotation.tailrec
  def binSearch(low: Int, hi: Int): Int = {
    if (hi < low) low
    else {
      val mid = (low + hi) >>> 1
      if (can(mid)) binSearch(low, mid - 1)
      else binSearch(mid + 1, hi)
    }
  }

  if (!can(m)) println(-1)
  else println(binSearch(0, m))
}

import java.util

import scala.collection._

object D 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, m) = readInts(2)

  val preceedingBuilders, onStepBuilders = Array.fill(n){ new mutable.ArrayBuilder.ofInt }

  for (step <- 1 to m) {
    val Array(u, v) = readInts(2).map(_ - 1)
    preceedingBuilders(u) += v
    onStepBuilders(u) += step
  }

  val preceeding = preceedingBuilders.map(_.result)
  val onStep = onStepBuilders.map(_.result)

  def can(toStep: Int): Boolean = {

    val sb1, sb2, sb3, sb4 = new mutable.ArrayBuilder.ofInt
    val c1, c2, c3, c4 = Array.fill(n)(0)

    def dfs1(u: Int, sb: mutable.ArrayBuilder.ofInt, color: Array[Int]): Unit = {
      color(u) = 1
      var i = 0
      while (i < preceeding(u).length) {
        if (onStep(u)(i) <= toStep) {
          val v = preceeding(u)(i)
          if (color(v) == 0) dfs1(v, sb, color)
        }
        i += 1
      }
      color(u) = 2
      sb += u
    }

    def dfs2(u: Int, sb: mutable.ArrayBuilder.ofInt, color: Array[Int]): Unit = {
      color(u) = 1
      var i = preceeding(u).length - 1
      while (i >= 0) {
        if (onStep(u)(i) <= toStep) {
          val v = preceeding(u)(i)
          if (color(v) == 0) dfs2(v, sb, color)
        }
        i -= 1
      }
      color(u) = 2
      sb += u
    }

    for (i <- 0 until n) {
      if (c1(i) == 0) dfs1(i, sb1, c1)
      if (c2(i) == 0) dfs2(i, sb2, c2)
    }

    for (i <- n - 1 to 0 by -1) {
      if (c3(i) == 0) dfs1(i, sb3, c3)
      if (c4(i) == 0) dfs2(i, sb4, c4)
    }

    val ts1 = sb1.result
    val ts2 = sb2.result
    val ts3 = sb3.result
    val ts4 = sb4.result
    ////println(toStep, ts1.mkString(" "), ts2.mkString(" "))
    util.Arrays.equals(ts1, ts2) && util.Arrays.equals(ts1, ts3) && util.Arrays.equals(ts1, ts4)
  }

  @annotation.tailrec
  def binSearch(low: Int, hi: Int): Int = {
    if (hi < low) low
    else {
      val mid = (low + hi) >>> 1
      if (can(mid)) binSearch(low, mid - 1)
      else binSearch(mid + 1, hi)
    }
  }

  if (!can(m)) println(-1)
  else println(binSearch(0, m))
}


There is a graph of $$$n$$$ rows and $$$10^6 + 2$$$ columns, where rows are numbered from $$$1$$$ to $$$n$$$ and columns from $$$0$$$ to $$$10^6 + 1$$$:  Let's denote the node in the row $$$i$$$ and column $$$j$$$ by $$$(i, j)$$$.Initially for each $$$i$$$ the $$$i$$$-th row has exactly one obstacle — at node $$$(i, a_i)$$$. You want to move some obstacles so that you can reach node $$$(n, 10^6+1)$$$ from node $$$(1, 0)$$$ by moving through edges of this graph (you can't pass through obstacles). Moving one obstacle to an adjacent by edge free node costs $$$u$$$ or $$$v$$$ coins, as below:  If there is an obstacle in the node $$$(i, j)$$$, you can use $$$u$$$ coins to move it to $$$(i-1, j)$$$ or $$$(i+1, j)$$$, if such node exists and if there is no obstacle in that node currently.  If there is an obstacle in the node $$$(i, j)$$$, you can use $$$v$$$ coins to move it to $$$(i, j-1)$$$ or $$$(i, j+1)$$$, if such node exists and if there is no obstacle in that node currently.  Note that you can't move obstacles outside the grid. For example, you can't move an obstacle from $$$(1,1)$$$ to $$$(0,1)$$$. Refer to the picture above for a better understanding. Now you need to calculate the minimal number of coins you need to spend to be able to reach node $$$(n, 10^6+1)$$$ from node $$$(1, 0)$$$ by moving through edges of this graph without passing through obstacles.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains three integers $$$n$$$, $$$u$$$ and $$$v$$$ ($$$2 \le n \le 100$$$, $$$1 \le u, v \le 10^9$$$) — the number of rows in the graph and the numbers of coins needed to move vertically and horizontally respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — where $$$a_i$$$ represents that the obstacle in the $$$i$$$-th row is in node $$$(i, a_i)$$$. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^4$$$.

For each test case, output a single integer — the minimal number of coins you need to spend to be able to reach node $$$(n, 10^6+1)$$$ from node $$$(1, 0)$$$ by moving through edges of this graph without passing through obstacles. It can be shown that under the constraints of the problem there is always a way to make such a trip possible.

NoteIn the first sample, two obstacles are at $$$(1, 2)$$$ and $$$(2,2)$$$. You can move the obstacle on $$$(2, 2)$$$ to $$$(2, 3)$$$, then to $$$(1, 3)$$$. The total cost is $$$u+v = 7$$$ coins.  In the second sample, two obstacles are at $$$(1, 3)$$$ and $$$(2,2)$$$. You can move the obstacle on $$$(1, 3)$$$ to $$$(2, 3)$$$. The cost is $$$u = 3$$$ coins.

object B {
  import InOut._
  def main(args: Array[String]): Unit = {
    for (_ <- 1 to nextInt) {
      val n, u, v = nextInt
      val as = nextInts(n)
      val minA = as.min
      val maxA = as.max
      var res = 0
      if (minA == maxA) {
        res = Math.min(2 * v, u + v)
      } else {
        var gap = false
        for (i <- 1 until as.length) {
          if (Math.abs(as(i) - as(i - 1)) > 1) gap = true
        }
        res = if (gap) 0  else Math.min(u, v)
      }

      out.println(res)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}


You are given two integers $$$a$$$ and $$$b$$$. Print $$$a+b$$$.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is given as a line of two integers $$$a$$$ and $$$b$$$ ($$$-1000 \le a, b \le 1000$$$).

Print $$$t$$$ integers — the required numbers $$$a+b$$$.

import scala.io.StdIn.readLine

object A {

  def solution(a: Int, b: Int): Int = {
    a + b
  }

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


Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).

The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly. Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.

Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.

Note  First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.

object B
{
  def main(args: Array[String])
  {
    val input = readLine.split(" ").map{_.toInt}
    val n = input(0)
    val t1 = input(1)*(100-input(3))
    val t2 = input(2)*100

    var dwarves = Array.tabulate(n){i: Int => (0,0)}

    for(i <- 0 until n)
    {
      val speed = readLine.split(" ").map{_.toInt}
      dwarves(i) = (i+1, (speed(0)*t1+speed(1)*t2) max (speed(0)*t2+speed(1)*t1))
    }
    val rankedDwarves = dwarves.sortWith((d1,d2) => d1._2>d2._2)
    for((i,h) <- rankedDwarves)
    {
      println("%d %d.%02d".format(i, h/100, h%100))
    }
  }
}