You are given a string $$$s$$$ of length $$$n$$$ consisting only of lowercase Latin letters.A substring of a string is a contiguous subsequence of that string. So, string "forces" is substring of string "codeforces", but string "coder" is not.Your task is to calculate the number of ways to remove exactly one substring from this string in such a way that all remaining characters are equal (the number of distinct characters either zero or one).It is guaranteed that there is at least two different characters in $$$s$$$.Note that you can remove the whole string and it is correct. Also note that you should remove at least one character.Since the answer can be rather large (not very large though) print it modulo $$$998244353$$$.If you are Python programmer, consider using PyPy instead of Python when you submit your code.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of the string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$ consisting only of lowercase Latin letters. It is guaranteed that there is at least two different characters in $$$s$$$.

Print one integer — the number of ways modulo $$$998244353$$$ to remove exactly one substring from $$$s$$$ in such way that all remaining characters are equal.

NoteLet $$$s[l; r]$$$ be the substring of $$$s$$$ from the position $$$l$$$ to the position $$$r$$$ inclusive.Then in the first example you can remove the following substrings:   $$$s[1; 2]$$$;  $$$s[1; 3]$$$;  $$$s[1; 4]$$$;  $$$s[2; 2]$$$;  $$$s[2; 3]$$$;  $$$s[2; 4]$$$. In the second example you can remove the following substrings:   $$$s[1; 4]$$$;  $$$s[1; 5]$$$;  $$$s[1; 6]$$$;  $$$s[1; 7]$$$;  $$$s[2; 7]$$$;  $$$s[3; 7]$$$. In the third example you can remove the following substrings:   $$$s[1; 1]$$$;  $$$s[1; 2]$$$;  $$$s[2; 2]$$$.

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

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

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

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

  def solve(): Unit = {
    val N = ni()
    val S = ns(N)
    def countL() = {
      var l = 0
      while(l < N && S(l) == S(0)) {
        l += 1
      }
      l
    }

    def countR() = {
      var r = 0
      while (r < N && S(N - 1 - r) == S(N - 1)) {
        r += 1
      }
      r
    }

    val ans = if (S.forall(_ == S(0))) {
      // 全部一緒
      (N.toLong * (N + 1) / 2 - 1) % MOD

    } else if (S(0) == S(N - 1)) {
      // 左右が一緒
      val l = countL()
      val r = countR()
      (l + 1).toLong * (r + 1) % MOD
    } else {
      // 左右で違う
      val l = countL()
      val r = countR()
      l + r + 1
    }

    out.println(ans)
  }

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

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

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

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

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

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

  def debug(s: String): Unit = {
    System.err.println(s)
  }
}

import scala.io.StdIn

object SubstringRemoval extends App {

  val n = StdIn.readLine()
  val s = StdIn.readLine()

  val takeSimilar = (xs: IndexedSeq[(Char, Int)]) =>
    xs.takeWhile { case (c, i) =>
      if (i == 0) true
      else xs(i - 1)._1 == c
    }

  val first: Long = takeSimilar(s.zipWithIndex).length.toLong
  val second: Long = takeSimilar(s.reverse.zipWithIndex).length.toLong

  if (s.head == s.last) {
    println((2 * (first + second) + (first - 1) * (second - 1)) % 998244353)

  } else {
    println((first + second + 1) % 998244353)
  }
}

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

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

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

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

  def solve(): Unit = {
    val N = ni()
    val S = ns(N)
    def countL() = {
      var l = 0
      while(l < N && S(l) == S(0)) {
        l += 1
      }
      l
    }

    def countR() = {
      var r = 0
      while (r < N && S(N - 1 - r) == S(N - 1)) {
        r += 1
      }
      r
    }

    val ans = if (S.forall(_ == S(0))) {
      // 全部一緒
      N.toLong * (N + 1) / 2

    } else if (S(0) == S(N - 1)) {
      // 左右が一緒
      val l = countL()
      val r = countR()
      (l + 1).toLong * (r + 1)
    } else {
      // 左右で違う
      val l = countL()
      val r = countR()
      l + r + 1
    }

    out.println(ans)
  }

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

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

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

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

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

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

  def debug(s: String): Unit = {
    System.err.println(s)
  }
}

import scala.io.StdIn

object SubstringRemoval extends App {

  val n = StdIn.readLine()
  val s = StdIn.readLine()

  val takeSimilar = (xs: IndexedSeq[(Char, Int)]) =>
    xs.takeWhile { case (c, i) =>
      if (i == 0) true
      else xs(i - 1)._1 == c
    }

  val first = takeSimilar(s.zipWithIndex).length.toLong
  val second = takeSimilar(s.reverse.zipWithIndex).length.toLong

  if (s.head == s.last) {
    println((2 * (first + second) % 998244353) % 998244353)
  } else {
    println((first + second + 1) % 998244353)
  }

}

import scala.io.StdIn

object SubstringRemoval extends App {

  val n = StdIn.readLine()
  val s = StdIn.readLine()

  val takeSimilar = (xs: IndexedSeq[(Char, Int)]) =>
    xs.takeWhile { case (c, i) =>
      if (i == 0) true
      else xs(i - 1)._1 == c
    }

  val first = takeSimilar(s.zipWithIndex).length.toLong
  val second = takeSimilar(s.reverse.zipWithIndex).length.toLong

  if (s.head == s.last) {
    println((2 * ((first + second) % 998244353)) % 998244353)
  } else {
    println((first + second + 1) % 998244353)
  }

}

import scala.io.StdIn

object SubstringRemoval extends App {

  val n = StdIn.readLine()
  val s = StdIn.readLine()

  val takeSimilar = (xs: IndexedSeq[(Char, Int)]) =>
    xs.takeWhile { case (c, i) =>
      if (i == 0) true
      else xs(i - 1)._1 == c
    }

  val first = takeSimilar(s.zipWithIndex).length.toLong
  val second = takeSimilar(s.reverse.zipWithIndex).length.toLong

  if (s.head == s.last) {
    println((2 * (first + second)) % 998244353)
  } else {
    println((first + second + 1) % 998244353)
  }

}

import scala.io.StdIn

object SubstringRemoval extends App {

  val n = StdIn.readLine()
  val s = StdIn.readLine()

  val takeSimilar = (xs: IndexedSeq[(Char, Int)]) =>
    xs.takeWhile { case (c, i) =>
      if (i == 0) true
      else xs(i - 1)._1 == c
    }

  val first: Long = takeSimilar(s.zipWithIndex).length.toLong
  val second: Long = takeSimilar(s.reverse.zipWithIndex).length.toLong

  if (s.head == s.last) {
    val res: Long = (2 * ((first + second) % 998244353)) % 998244353
    println(res)
  } else {
    val res: Long = (first + second + 1) % 998244353
    println(res)
  }
}


You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains n bombs, the i-th bomb is at point with coordinates (xi, yi). We know that no two bombs are at the same point and that no bomb is at point with coordinates (0, 0). Initially, the robot is at point with coordinates (0, 0). Also, let's mark the robot's current position as (x, y). In order to destroy all the bombs, the robot can perform three types of operations:  Operation has format "1 k dir". To perform the operation robot have to move in direction dir k (k ≥ 1) times. There are only 4 directions the robot can move in: "R", "L", "U", "D". During one move the robot can move from the current point to one of following points: (x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1) (corresponding to directions). It is forbidden to move from point (x, y), if at least one point on the path (besides the destination point) contains a bomb.  Operation has format "2". To perform the operation robot have to pick a bomb at point (x, y) and put it in a special container. Thus, the robot can carry the bomb from any point to any other point. The operation cannot be performed if point (x, y) has no bomb. It is forbidden to pick a bomb if the robot already has a bomb in its container.  Operation has format "3". To perform the operation robot have to take a bomb out of the container and destroy it. You are allowed to perform this operation only if the robot is at point (0, 0). It is forbidden to perform the operation if the container has no bomb. Help the robot and find the shortest possible sequence of operations he can perform to destroy all bombs on the coordinate plane.

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of bombs on the coordinate plane. Next n lines contain two integers each. The i-th line contains numbers (xi, yi) ( - 109 ≤ xi, yi ≤ 109) — the coordinates of the i-th bomb. It is guaranteed that no two bombs are located at the same point and no bomb is at point (0, 0).

In a single line print a single integer k — the minimum number of operations needed to destroy all bombs. On the next lines print the descriptions of these k operations. If there are multiple sequences, you can print any of them. It is guaranteed that there is the solution where k ≤ 106.

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toInt
  val line = in.take(n).map(line => line.split(' ').map(_.toInt)).map(i => (i.head, i.last)).toList
  val result = line
    .sortBy(i => (Math.min(Math.abs(i._1), Math.abs(i._2)), Math.max(Math.abs(i._1), Math.abs(i._2))))
    .map {
      case (x, y) if x == 0 =>
        val up = if (y > 0) 'U' else 'D'
        val down = if (y > 0) 'D' else 'U'
        s"1 ${Math.abs(y)} $up\n2\n1 ${Math.abs(y)} $down\n3"
      case (x, y) if y == 0 =>
        val right = if (x > 0) 'R' else 'L'
        val left = if (x > 0) 'L' else 'R'
        s"1 ${Math.abs(x)} $right\n2\n1 ${Math.abs(x)} $left\n3"
      case (x, y) =>
        val right = if (x > 0) 'R' else 'L'
        val left = if (x > 0) 'L' else 'R'
        val up = if (y > 0) 'U' else 'D'
        val down = if (y > 0) 'D' else 'U'
        s"1 ${Math.abs(x)} $right\n1 ${Math.abs(y)} $up\n2\n1 ${Math.abs(x)} $left\n1 ${Math.abs(y)} $down\n3"
    }
  println(result.length * 6 - 2 * line.count(i => i._1 == 0 || i._2 == 0))
  println(result.mkString("\n"))
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toInt
  val line = in.take(n).map(line => line.split(' ').map(_.toInt)).map(i => (i.head, i.last)).toList
  val result = line
    .sortBy(i => (Math.min(Math.abs(i._1), Math.abs(i._2)), Math.max(Math.abs(i._1), Math.abs(i._2))))
    .map {
      case (x, y) if x == 0 =>
        val up = if (y > 0) 'U' else 'D'
        val down = if (y > 0) 'D' else 'U'
        s"1 ${Math.abs(y)} $up\n2\n1 ${Math.abs(y)} $down\n3"
      case (x, y) if y == 0 =>
        val right = if (x > 0) 'R' else 'L'
        val left = if (x > 0) 'L' else 'R'
        s"1 ${Math.abs(x)} $right\n2\n1 ${Math.abs(x)} $left\n3"
      case (x, y) =>
        val right = if (x > 0) 'R' else 'L'
        val left = if (x > 0) 'L' else 'R'
        val up = if (y > 0) 'U' else 'D'
        val down = if (y > 0) 'D' else 'U'
        s"1 ${Math.abs(x)} $right\n1 ${Math.abs(y)} $up\n2\n1 ${Math.abs(x)} $left\n1 ${Math.abs(y)} $down\n3"
    }
  println(result.length * 6 - 2 * line.count(i => i._1 == 0 || i._2 == 9))
  println(result.mkString("\n"))
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toInt
  val set = in.take(n).map(line => line.split(' ').map(_.toInt)).map(i => (i.head, i.last)).toSet
  val sorted = set.toList.sortBy(i => Math.min(i._1, i._2))
  val result = sorted.flatMap {
    case (x, y) =>
      val there = (if (x != 0) List(s"1 $x R") else Nil) ::: (if (y != 0) List(s"1 $y U") else Nil)
      val back = (if (x != 0) List(s"1 $x L") else Nil) ::: (if (y != 0) List(s"1 $y D") else Nil)
      there ::: List("2") ::: back ::: List("3")
  }
  println(result.length)
  println(result.mkString("\n"))
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toInt
  val result = in.take(n).map(line => line.split(' ').map(_.toInt))
    .map(i => (i.head, i.last)).toList
    .sortBy(i => (Math.min(Math.abs(i._1), Math.abs(i._2)), Math.max(Math.abs(i._1), Math.abs(i._2))))
    .map {
      case (x, y) if x == 0 =>
        val up = if (y > 0) 'U' else 'D'
        val down = if (y > 0) 'D' else 'U'
        s"1 ${Math.abs(y)} $up\n2\n1 ${Math.abs(y)} $down\n3"
      case (x, y) if y == 0 =>
        val right = if (x > 0) 'R' else 'L'
        val left = if (x > 0) 'L' else 'R'
        s"1 ${Math.abs(x)} $right\n2\n1 ${Math.abs(x)} $left\n3"
      case (x, y) =>
        val right = if (x > 0) 'R' else 'L'
        val left = if (x > 0) 'L' else 'R'
        val up = if (y > 0) 'U' else 'D'
        val down = if (y > 0) 'D' else 'U'
        s"1 ${Math.abs(x)} $right\n1 ${Math.abs(y)} $up\n2\n1 ${Math.abs(x)} $left\n1 ${Math.abs(y)} $down\n3"
    }
  println(result.length)
  println(result.mkString("\n"))
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toInt
  val line = in.take(n).map(line => line.split(' ').map(_.toInt)).map(i => (i.head, i.last)).toList
  val result = line
    .sortBy(i => (Math.min(Math.abs(i._1), Math.abs(i._2)), Math.max(Math.abs(i._1), Math.abs(i._2))))
    .map {
      case (x, y) if x == 0 =>
        val up = if (y > 0) 'U' else 'D'
        val down = if (y > 0) 'D' else 'U'
        s"1 ${Math.abs(y)} $up\n2\n1 ${Math.abs(y)} $down\n3"
      case (x, y) if y == 0 =>
        val right = if (x > 0) 'R' else 'L'
        val left = if (x > 0) 'L' else 'R'
        s"1 ${Math.abs(x)} $right\n2\n1 ${Math.abs(x)} $left\n3"
      case (x, y) =>
        val right = if (x > 0) 'R' else 'L'
        val left = if (x > 0) 'L' else 'R'
        val up = if (y > 0) 'U' else 'D'
        val down = if (y > 0) 'D' else 'U'
        s"1 ${Math.abs(x)} $right\n1 ${Math.abs(y)} $up\n2\n1 ${Math.abs(x)} $left\n1 ${Math.abs(y)} $down\n3"
    }
  println(result.length * 4 - line.count(i => i._1 == 0 || i._2 == 9))
  println(result.mkString("\n"))
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toInt
  val set = in.take(n).map(line => line.split(' ').map(_.toInt)).map(i => (i.head, i.last)).toSet
  val sorted = set.toList.sortBy(i => Math.min(Math.abs(i._1), Math.abs(i._2)))
  val result = sorted.flatMap {
    case (x, y) =>
      val right = if (x > 0) 'R' else 'L'
      val left = if (x > 0) 'L' else 'R'
      val up = if (y > 0) 'U' else 'D'
      val down = if (y > 0) 'D' else 'U'
      val there = (if (x != 0) List(s"1 ${Math.abs(x)} $right") else Nil) ::: (if (y != 0) List(s"1 ${Math.abs(y)} $up") else Nil)
      val back = (if (x != 0) List(s"1 ${Math.abs(x)} $left") else Nil) ::: (if (y != 0) List(s"1 ${Math.abs(y)} $down") else Nil)
      there ::: List("2") ::: back ::: List("3")
  }
  println(result.length)
  println(result.mkString("\n"))
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toInt
  val result = in.take(n).map(line => line.split(' ').map(_.toInt))
    .map(i => (i.head, i.last)).toList
    .sortBy(i => (Math.min(Math.abs(i._1), Math.abs(i._2)), Math.max(Math.abs(i._1), Math.abs(i._2))))
    .flatMap {
    case (x, y) =>
      val right = if (x > 0) 'R' else 'L'
      val left = if (x > 0) 'L' else 'R'
      val up = if (y > 0) 'U' else 'D'
      val down = if (y > 0) 'D' else 'U'
      List(if (x != 0) Some(s"1 ${Math.abs(x)} $right \n ") else None,
        if (y != 0) Some(s"1 ${Math.abs(y)} $up") else None,
        Some("2"),
        if (x != 0) Some(s"1 ${Math.abs(x)} $left") else None,
        if (y != 0) Some(s"1 ${Math.abs(y)} $down") else None,
        Some("3"))
  }
  println(result.length)
  println(result.mkString("\n"))
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toInt
  val set = in.take(n).map(line => line.split(' ').map(_.toInt)).map(i => (i.head, i.last)).toSet
  val sorted = set.toList.sortBy(i => (Math.min(Math.abs(i._1), Math.abs(i._2)), Math.max(Math.abs(i._1), Math.abs(i._2))))
  val result = sorted.flatMap {
    case (x, y) =>
      val right = if (x > 0) 'R' else 'L'
      val left = if (x > 0) 'L' else 'R'
      val up = if (y > 0) 'U' else 'D'
      val down = if (y > 0) 'D' else 'U'
      List(if (x != 0) Some(s"1 ${Math.abs(x)} $right \n ") else None,
           if (y != 0) List(s"1 ${Math.abs(y)} $up") else None,
           Some("2"),
           if (x != 0) List(s"1 ${Math.abs(x)} $left") else Nil,
           if (y != 0) List(s"1 ${Math.abs(y)} $down") else Nil,
           Some("3"))
  }
  println(result.length)
  println(result.mkString("\n"))
}


Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once.One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only.

The first line contains two integers n and m (1 ≤ n ≤ 109, 0 ≤ m ≤ 3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≤ di ≤ n) — the numbers of the dirty stairs (in an arbitrary order).

Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO".

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(" ").map(_.toInt)
  if (m == 0)
    println("YES")
  else {
    val dirty = in.next().split(" ").map(_.toInt).sorted
    if (dirty.head == 1 || dirty.last == n)
      println("NO")
    else {
      if ((2 until m).forall{j =>
        val first = dirty(j - 2)
        (dirty(j - 1) != first + 1) || (dirty(j) != first + 2)
      })
        println("YES")
      else
        println("NO")
    }
  }
}

object B extends App {

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

  val Array(n, m) = readInts(2)
  val dirty = if (m > 0) readInts(m).sorted else Array.ofDim[Int](0)
  val can = m == 0 || (dirty.head != 1 && dirty.last != n && !(0 until m - 2).exists(i => dirty(i + 1) == dirty(i) + 1 && dirty(i + 2) == dirty(i) + 2))

  println(if (can) "YES" else "NO")
}

/**
 * @author pvasilyev
 * @since 18 Jun 2016
 */
object B362 extends App {

  def solve() = {
    val Array(n, m): Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    if (m == 0) {
      println("YES")
    } else {
      val d: Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
      val sorted = d.sorted
      var can = sorted(0) != 1 && sorted(m - 1) != n
      var biggestConsecutive = 0
      if (can) {
        var currentConsecutive = 0
        for (i <- 1 until m) {
          if (sorted(i) == sorted(i - 1) + 1) {
            currentConsecutive += 1
            biggestConsecutive = Math.max(biggestConsecutive, currentConsecutive)
          } else {
            currentConsecutive = 0
          }
        }
      }

      if (can && biggestConsecutive < 2) {
        println("YES")
      } else {
        println("NO")
      }
    }
  }

  solve()

}

object Main {
  def main(args: Array[String]) {
    val nm = readLine().split(" ").map(_.toInt)
    val n = nm(0)
    val m = nm(1)
    val a =
      if (m == 0) Array.empty[Int]
      else readLine().split(" ").map(_.toInt).sorted

    var p1 = 0
    var p2 = 0
    var inc = false
    for (i <- 0 until m) {
      val e = a(i)
      if (p1 == e - 2 && p2 == e - 1) inc = true
      p1 = p2
      p2 = e
    }

    if (a.headOption == Some(1) || p2 == n || inc) println("NO")
    else println("YES")
  }
}

/**
 * @author pvasilyev
 * @since 18 Jun 2016
 */
object B362 extends App {

  def solve() = {
    val Array(n, m): Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    if (m == 0) {
      println("YES")
    } else {
      val d: Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
      val sorted = d.sorted
      var can = sorted(0) != 1 && sorted(m - 1) != n
      var biggestConsecutive = 0
      if (can) {
        var currentConsecutive = 0
        for (i <- 1 until m) {
          if (sorted(i) == sorted(i - 1) + 1) {
            currentConsecutive += 1
          } else {
            biggestConsecutive = Math.max(biggestConsecutive, currentConsecutive)
            currentConsecutive = 0
          }
        }
      }

      if (can && biggestConsecutive < 2) {
        println("YES")
      } else {
        println("NO")
      }
    }
  }

  solve()

}

object Main {
  def main(args: Array[String]) {
    val nm = readLine().split(" ").map(_.toInt)
    val n = nm(0)
    val m = nm(1)
    val a = readLine().split(" ").map(_.toInt).sorted

    var p1 = 0
    var p2 = 0
    var inc = false
    for (i <- 0 until m) {
      val e = a(i)
      if (p1 == e - 2 && p2 == e - 1) inc = true
      p1 = p2
      p2 = e
    }

    if (a.head == 1 || p2 == m || inc) println("NO")
    else println("YES")
  }
}


Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he can choose any index i and either add 1 to all elements ai, ai + 1, ... , an or subtract 1 from all elements ai, ai + 1, ..., an. His goal is to end up with the array b1, b2, ..., bn. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array ai. Initially ai = 0 for every position i, so this array is not given in the input. The second line of the input contains n integers b1, b2, ..., bn ( - 109 ≤ bi ≤ 109).

Print the minimum number of steps that Wilbur needs to make in order to achieve ai = bi for all i.

NoteIn the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes.In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.

/**
  * Created by MZKL7315 on 4/12/2016.
  */

object Main {

  def solve(s: List[Long], cur: Long): Long = s match {
    case Nil => 0
    case h :: t => math.abs(cur - h) + solve(t, h)
  }

  def main(args: Array[String]) = {
    val in = scala.io.Source.stdin.getLines()
    val n = in.next().toInt
    println(solve(in.next().split(' ').toList map (_.toLong), 0))
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(' ').map(_.toInt)
  println(data.foldLeft((0l, 0)) {
    case ((soFar, prev), el) =>
      val diff = Math.abs(prev - el)
      (soFar + diff, el)
  }._1)

}

object B596 {

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val b = readInts(n)
    var curr = 0
    var res = 0L
    for(i <- 0 until n) {
      res += math.abs(curr - b(i))
      curr = b(i)
    }
    println(res)
  }

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

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

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

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

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

}

import scala.annotation.tailrec
import scala.collection.mutable
import scala.util._
import scala.math.Ordering.Implicits._

object _596B extends CodeForcesApp {
  override type Result = Long

  override def solve(scanner: Scanner) = {
    import scanner._
    val n = nextInt()
    val bs = List.fill(n)(nextLong())
    (0L :: bs).sliding(2).collect{case a :: b :: Nil => (a - b).abs}.sum
  }

  override def format(result: Result) = super.format(result)
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  final val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val mod: Int = 1000000007
  type Result
  def solve(scanner: Scanner): Result
  def format(result: Result): String = result.toString
  def apply(scanner: Scanner): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer

import scala.io.Codec

/**
 * Scala implementation of a faster java.util.Scanner
 * See: http://codeforces.com/blog/entry/21125
 * All next methods throw NoSuchElementException when !hasNext
 */
class Scanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))
  def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))
  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)
  def this(str: String) = this(new StringReader(str))

  val lines = Iterator.continually(reader.readLine()).takeWhile(_ != null) //TODO: In Java 8 reader.lines().iterator

  private[this] val tokenizers = lines.map(new StringTokenizer(_)).filter(_.hasMoreTokens)
  private[this] var current: Option[StringTokenizer] = None

  @inline private[this] def tokenizer(): Option[StringTokenizer] = current.find(_.hasMoreTokens) orElse {
    current = if (tokenizers.hasNext) Some(tokenizers.next()) else None
    current
  }

  /**
   * Unlike Java's scanner which returns till end of current line, this actually returns the next line
   * @see line() if you want the Java behaviour
   */
  def nextLine(): String = {
    current = None   // reset
    lines.next()
  }
  def lineNumber: Int = reader.getLineNumber
  def line(): String = tokenizer().get.nextToken("\n\r")
  def nextString(): String = next()
  def nextChar(): Char = next().ensuring(_.length == 1).head
  def nextBoolean(): Boolean = next().toBoolean
  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)
  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)
  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)
  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)
  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)
  def nextFloat(): Float = next().toFloat
  def nextDouble(): Double = next().toDouble
  def nextBigDecimal(): BigDecimal = BigDecimal(next())
  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty
  override def close() = reader.close()
}

import scala.io.StdIn._

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

  var offset = 0L
  var moves = 0L
  for (i <- 0 until A.length) {
    moves += Math.abs(A(i) - offset)
    offset += A(i) - offset
//    println(s"$i -> $offset ($moves)")
  }

  println(moves)
}

/**
  * Created by MZKL7315 on 4/12/2016.
  */

object Main {

  def solve(s: List[Int], cur: Int): Int = s match {
    case Nil => 0
    case h :: t => math.abs(cur - h) + solve(t, h)
  }

  def main(args: Array[String]) = {
    val in = scala.io.Source.stdin.getLines()
    val n = in.next().toInt
    println(solve(in.next().split(' ').toList map (_.toInt), 0))
  }
}

/**
  * Created by MZKL7315 on 4/12/2016.
  */

object Main {

  def solve(s: List[Int], cur: Int): Int = s match {
    case Nil => 0
    case h :: t => math.abs(cur - h) + solve(t, math.max(cur, h))
  }

  def main(args: Array[String]) = {
    val in = scala.io.Source.stdin.getLines()
    val n = in.next().toInt
    println(solve(in.next().split(' ').toList map (_.toInt), 0))
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(' ').map(_.toInt)
  println(data.foldLeft((0, 0)) {
    case ((soFar, prev), el) =>
      val diff = Math.abs(prev - el)
      (soFar + diff, el)
  }._1)

}


You have $$$a$$$ coins of value $$$n$$$ and $$$b$$$ coins of value $$$1$$$. You always pay in exact change, so you want to know if there exist such $$$x$$$ and $$$y$$$ that if you take $$$x$$$ ($$$0 \le x \le a$$$) coins of value $$$n$$$ and $$$y$$$ ($$$0 \le y \le b$$$) coins of value $$$1$$$, then the total value of taken coins will be $$$S$$$.You have to answer $$$q$$$ independent test cases.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases. Then $$$q$$$ test cases follow. The only line of the test case contains four integers $$$a$$$, $$$b$$$, $$$n$$$ and $$$S$$$ ($$$1 \le a, b, n, S \le 10^9$$$) — the number of coins of value $$$n$$$, the number of coins of value $$$1$$$, the value $$$n$$$ and the required total value.

For the $$$i$$$-th test case print the answer on it — YES (without quotes) if there exist such $$$x$$$ and $$$y$$$ that if you take $$$x$$$ coins of value $$$n$$$ and $$$y$$$ coins of value $$$1$$$, then the total value of taken coins will be $$$S$$$, and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

import scala.io.StdIn

object Main extends App{

    val q = StdIn.readLine.toInt
    for (i <- 0 to q-1) {
        val Array(a, b, n, s) = StdIn.readLine().split(" ").map(_.toInt)
        val div = s / n
        if ((div min a) * n + b * 1 >= s)
            println("YES")
        else
            println("NO")
    }

}

//package codeforces.contest1256

object PaymentWithoutChange {
  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt()) {
      val Array(a, b, n, s) = io.StdIn.readLine().split(" ").map(_.toLong)

      println {
        if (b + (n * (s / n) min a * n) >= s) "YES" else "NO"
      }
    }
  }

}

import scala.math.min

object Main {
  def main(args: Array[String]) = {
    val q = readInt
    (0 until q).foreach((x) => f1)
  }

  def f1: Unit = {
    val Array(a, b, n, s) = readLine.split(" ").map(_.toLong)
    println(if (s - n * (min(s / n, a)) <= b) "YES" else "NO")
  }
}

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

  override def apply(implicit io: IO): io.type = repeat {
    val a, b, n, s = io.read[Int]
    val withA = ((s/n) min a)*n
    val remaining = s - withA
    debug(a, b, n, s, withA, remaining)
    val ans = remaining <= b
    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 apply(implicit io: IO): io.type
  def repeat(f: => Unit)(implicit io: IO): io.type = {Utils.repeat(io.read[Int]){f; io.writeLine()}; io}
  def main(args: Array[String]): Unit = apply(new IO(System.in, System.out)).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")

  def readAll[A: IO.Read]: (Int, Vector[A]) = {
    val data = read[Vector[A]]
    (data.length, data)
  }

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

  def write(obj: Any): this.type = {
    printer.print(obj)
    this
  }
  def writeLine(): this.type = {
    printer.println()
    this
  }
  def writeLine(obj: Any): this.type = {
    printer.println(obj)
    this
  }
  def writeLines(obj: Traversable[Any]): this.type = writeAll(obj, separator = "\n")
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }

  object Read {
    implicit def collection[C[_], A: Read](implicit b: CanBuild[A, C[A]]) : Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                                   : Read[String]       = new Read(_.next())
    implicit val int                                                      : Read[Int]          = string.map(_.toInt)
    implicit val long                                                     : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                                   : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                                   : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                               : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                                 : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]                        : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]               : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                                  : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

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

  override def apply(io: IO): io.type = {
    // val q = io.read[Int]
    val q = io.read[Int]
    repeat(q) {
      val arr = io.read[Array, Long](4)
      io.writeLine(if(arr(1) >= arr(3) % arr(2) && arr(1) + arr(0) * arr(2) >= arr(3)) { "YES" } else { "NO" })
    }
    io
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = apply(new IO(System.in, System.out)).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: Map[A, Int] = t.groupBy(identity).mapValues(_.size)
  }

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

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

  def readAll[A: IO.Read]: (Int, Vector[A]) = {
    val data = read[Vector[A]]
    (data.length, data)
  }

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

  def write(obj: Any): this.type = {
    printer.print(obj)
    this
  }
  def writeLine(): this.type = {
    printer.println()
    this
  }
  def writeLine(obj: Any): this.type = {
    printer.println(obj)
    this
  }
  def writeLines(obj: Traversable[Any]): this.type = writeAll(obj, separator = "\n")
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }

  object Read {
    implicit def collection[C[_], A: Read](implicit b: CanBuild[A, C[A]]) : Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                                   : Read[String]       = new Read(_.next())
    implicit val int                                                      : Read[Int]          = string.map(_.toInt)
    implicit val long                                                     : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                                   : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                                   : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                               : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                                 : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]                        : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]               : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                                  : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

import java.util.Scanner

import scala.language.postfixOps
import scala.math.min

object TaskA extends App {
  val sc = new Scanner(System.in)
  val q = sc.nextInt

  val out = 1 to q map { _ =>
    val (a, b, n, s) = (sc.nextInt, sc.nextInt, sc.nextInt, sc.nextInt)
    if (min(s / n, a) * n + b >= s) "YES" else "NO"
  } mkString "\n"

  println(out)
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers. You can perform the following operations arbitrary number of times (possibly, zero):  Choose a pair of indices $$$(i, j)$$$ such that $$$|i-j|=1$$$ (indices $$$i$$$ and $$$j$$$ are adjacent) and set $$$a_i := a_i + |a_i - a_j|$$$;  Choose a pair of indices $$$(i, j)$$$ such that $$$|i-j|=1$$$ (indices $$$i$$$ and $$$j$$$ are adjacent) and set $$$a_i := a_i - |a_i - a_j|$$$. The value $$$|x|$$$ means the absolute value of $$$x$$$. For example, $$$|4| = 4$$$, $$$|-3| = 3$$$.Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it.It is guaranteed that you always can obtain the array of equal elements using such operations.Note that after each operation each element of the current array should not exceed $$$10^{18}$$$ by absolute value.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 2 \cdot 10^5$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

In the first line print one integer $$$k$$$ — the minimum number of operations required to obtain the array of equal elements. In the next $$$k$$$ lines print operations itself. The $$$p$$$-th operation should be printed as a triple of integers $$$(t_p, i_p, j_p)$$$, where $$$t_p$$$ is either $$$1$$$ or $$$2$$$ ($$$1$$$ means that you perform the operation of the first type, and $$$2$$$ means that you perform the operation of the second type), and $$$i_p$$$ and $$$j_p$$$ are indices of adjacent elements of the array such that $$$1 \le i_p, j_p \le n$$$, $$$|i_p - j_p| = 1$$$. See the examples for better understanding. Note that after each operation each element of the current array should not exceed $$$10^{18}$$$ by absolute value. If there are many possible answers, you can print any.

object D1144Equal extends App {
  import scala.collection.mutable
  import scala.io.StdIn.{readInt, readLine}

  val n = readInt
  val arr = readLine.split(' ').map(_.toInt).toArray
  val freq = arr.groupBy(identity).mapValues(_.length).maxBy(_._2)._1
  val pivot = arr.zipWithIndex.find(_._1 == freq).get._2

  val res: mutable.ArrayBuffer[(Int, Int, Int)] = mutable.ArrayBuffer.empty

  for(i <- (0 until pivot).reverse) {
    if(arr(i) < freq) res.append((1, i, i + 1))
    else if (arr(i) > freq) res.append((2, i, i + 1))
  }

  for(i <- pivot + 1 until n) {
    if(arr(i) < freq) res.append((1, i, i - 1))
    else if (arr(i) > freq) res.append((2, i, i - 1))
  }

  println(res.length)
  println(res.map( x => s"${x._1} ${x._2 + 1} ${x._3 + 1}").mkString("\n"))

}

object D1144Equal extends App {
  import scala.io.StdIn.{readInt, readLine}

  val n = readInt
  val arr = readLine.split(' ').map(_.toInt).toList
  val freq = arr.groupBy(identity).mapValues(_.length).maxBy(_._2)._1
  val arrIdx = arr.zipWithIndex
  val pivot = arrIdx.find(_._1 == freq).get._2 + 1
  val tmp = arrIdx.take(pivot).reverse ++ arrIdx.drop(pivot)

  var res: List[(Int, Int, Int)] = List.empty
  var i_prev = tmp.head._2
  val master = tmp.head._1

  for((a, i) <- tmp.tail) {
    if (a < master) {
      res :+= (1, i_prev, i)
    } else if (a > master) {
      res :+= (2, i_prev, i)
    }
    i_prev = i
  }

  println(res.length)
  res.foreach( x => println(s"${x._1} ${x._2 + 1} ${x._3 + 1}"))

}


Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.For example:  the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";  the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo". When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.

Print the given word without any changes if there are no typos. If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.

object P861C {
  /** Input
    * The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
    *
    * Output
    * Print the given word without any changes if there are no typos.
    *
    * Formally, a word is typed with a typo
    * if there is a block of not less that three consonants in a row,
    * and there are at least two different letters in this block.
    *
    * For example:
    * the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
    * the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
    *
    * When Beroffice editor finds a word with a typo,
    * it inserts as little as possible number of spaces in this word (dividing it into several words)
    * in such a way that each of the resulting words is typed without any typos.
    *
    */
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val word = sc.next()

    val vowels = Seq('a', 'e', 'i', 'o', 'u')
    var previouslySplitted = false

    if (word.length < 3) println(word)
    else {
      val words = word.take(2) ++ word.sliding(3).flatMap { cs =>
        if (!previouslySplitted && cs.count(!vowels.contains(_)) > 2 && cs.distinct.length > 1) {
          previouslySplitted = true
          Seq(' ', cs.last)
        }
        else {
          previouslySplitted = false
          Seq(cs.last)
        }
      }
      println(words.mkString)
    }
  }
}

object P861C {
  /** Input
    * The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
    *
    * Output
    * Print the given word without any changes if there are no typos.
    *
    * Formally, a word is typed with a typo
    * if there is a block of not less that three consonants in a row,
    * and there are at least two different letters in this block.
    *
    * For example:
    * the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
    * the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
    *
    * When Beroffice editor finds a word with a typo,
    * it inserts as little as possible number of spaces in this word (dividing it into several words)
    * in such a way that each of the resulting words is typed without any typos.
    *
    */
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val word = sc.next()

    val vowels = Seq('a', 'e', 'i', 'o', 'u')

    if (word.length < 3) println(word)
    else {
      val words = word.take(2) ++ word.sliding(3).flatMap { cs =>
        if (cs.count(!vowels.contains(_)) > 2 && cs.distinct.length > 1) Seq(' ', cs.last)
        else Seq(cs.last)
      }
      println(words.mkString)
    }
  }
}

object P861C {
  /** Input
    * The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
    *
    * Output
    * Print the given word without any changes if there are no typos.
    *
    * Formally, a word is typed with a typo
    * if there is a block of not less that three consonants in a row,
    * and there are at least two different letters in this block.
    *
    * For example:
    * the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
    * the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
    *
    * When Beroffice editor finds a word with a typo,
    * it inserts as little as possible number of spaces in this word (dividing it into several words)
    * in such a way that each of the resulting words is typed without any typos.
    *
    */
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val word = sc.next()

    val vowels = Seq('a', 'e', 'i', 'o', 'u')
    var previouslySplitted = false

    if (word.length < 3) println(word)
    else {
      val words = word.take(2) ++ word.sliding(3).flatMap { cs =>
        if (cs.count(!vowels.contains(_)) > 2 && cs.distinct.length > 1) {
          previouslySplitted = true
          Seq(' ', cs.last)
        }
        else {
          previouslySplitted = false
          Seq(cs.last)
        }
      }
      println(words.mkString)
    }
  }
}

object P861C {
  /** Input
    * The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
    *
    * Output
    * Print the given word without any changes if there are no typos.
    *
    * Formally, a word is typed with a typo
    * if there is a block of not less that three consonants in a row,
    * and there are at least two different letters in this block.
    *
    * For example:
    * the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
    * the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
    *
    * When Beroffice editor finds a word with a typo,
    * it inserts as little as possible number of spaces in this word (dividing it into several words)
    * in such a way that each of the resulting words is typed without any typos.
    *
    */
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val word = sc.next()

    val vowels = Seq('a', 'e', 'i', 'o', 'u')

    if (word.length < 3) println(word)
    else {
      val words = word.take(2) ++ word.sliding(3).map { cs =>
        if (cs.count(!vowels.contains(_)) > 2 && cs.distinct.length > 1) Seq(' ' + cs.last).mkString
        else cs.last.toString
      }
      println(words)
    }
  }
}

object P861C {
  /** Input
    * The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
    *
    * Output
    * Print the given word without any changes if there are no typos.
    *
    * Formally, a word is typed with a typo
    * if there is a block of not less that three consonants in a row,
    * and there are at least two different letters in this block.
    *
    * For example:
    * the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
    * the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
    *
    * When Beroffice editor finds a word with a typo,
    * it inserts as little as possible number of spaces in this word (dividing it into several words)
    * in such a way that each of the resulting words is typed without any typos.
    *
    */
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val word = sc.next()

    val vowels = Seq('a', 'e', 'i', 'o', 'u')

    if (word.length < 3) println(word)
    else {
      val words = word.take(2) ++ word.sliding(3).flatMap { cs =>
        if (cs.count(!vowels.contains(_)) > 2 && cs.distinct.length > 1) Seq(' ' + cs.last)
        else Seq(cs.last)
      }
      println(words.mkString)
    }
  }
}


Alice and Bob play the following game. Alice has a set $$$S$$$ of disjoint ranges of integers, initially containing only one range $$$[1, n]$$$. In one turn, Alice picks a range $$$[l, r]$$$ from the set $$$S$$$ and asks Bob to pick a number in the range. Bob chooses a number $$$d$$$ ($$$l \le d \le r$$$). Then Alice removes $$$[l, r]$$$ from $$$S$$$ and puts into the set $$$S$$$ the range $$$[l, d - 1]$$$ (if $$$l \le d - 1$$$) and the range $$$[d + 1, r]$$$ (if $$$d + 1 \le r$$$). The game ends when the set $$$S$$$ is empty. We can show that the number of turns in each game is exactly $$$n$$$.After playing the game, Alice remembers all the ranges $$$[l, r]$$$ she picked from the set $$$S$$$, but Bob does not remember any of the numbers that he picked. But Bob is smart, and he knows he can find out his numbers $$$d$$$ from Alice's ranges, and so he asks you for help with your programming skill.Given the list of ranges that Alice has picked ($$$[l, r]$$$), for each range, help Bob find the number $$$d$$$ that Bob has picked.We can show that there is always a unique way for Bob to choose his number for a list of valid ranges picked by Alice.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$). Each of the next $$$n$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$), denoting the range $$$[l, r]$$$ that Alice picked at some point. Note that the ranges are given in no particular order. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$1000$$$, and the ranges for each test case are from a valid game.

For each test case print $$$n$$$ lines. Each line should contain three integers $$$l$$$, $$$r$$$, and $$$d$$$, denoting that for Alice's range $$$[l, r]$$$ Bob picked the number $$$d$$$. You can print the lines in any order. We can show that the answer is unique. It is not required to print a new line after each test case. The new lines in the output of the example are for readability only.

NoteIn the first test case, there is only 1 range $$$[1, 1]$$$. There was only one range $$$[1, 1]$$$ for Alice to pick, and there was only one number $$$1$$$ for Bob to pick.In the second test case, $$$n = 3$$$. Initially, the set contains only one range $$$[1, 3]$$$.   Alice picked the range $$$[1, 3]$$$. Bob picked the number $$$1$$$. Then Alice put the range $$$[2, 3]$$$ back to the set, which after this turn is the only range in the set.  Alice picked the range $$$[2, 3]$$$. Bob picked the number $$$3$$$. Then Alice put the range $$$[2, 2]$$$ back to the set.  Alice picked the range $$$[2, 2]$$$. Bob picked the number $$$2$$$. The game ended. In the fourth test case, the game was played with $$$n = 5$$$. Initially, the set contains only one range $$$[1, 5]$$$. The game's turn is described in the following table.  Game turnAlice's picked rangeBob's picked numberThe range set afterBefore the game start$$$ \{ [1, 5] \} $$$1$$$[1, 5]$$$$$$3$$$$$$ \{ [1, 2], [4, 5] \}$$$2$$$[1, 2]$$$$$$1$$$$$$ \{ [2, 2], [4, 5] \} $$$3$$$[4, 5]$$$$$$5$$$$$$ \{ [2, 2], [4, 4] \} $$$4$$$[2, 2]$$$$$$2$$$$$$ \{ [4, 4] \} $$$5$$$[4, 4]$$$$$$4$$$$$$ \{ \} $$$ (empty set)

import java.io._
import java.util.StringTokenizer
import scala.+:
import scala.collection.mutable
import scala.collection.mutable._
import scala.collection.immutable._
import scala.util.Sorting.quickSort
import scala.math._

object Main extends App {
    val writer =  new PrintWriter(System.out, false)
    val reader = new BufferedReader(new InputStreamReader(System.in))
    var st = new StringTokenizer("")
    def next(): String = {while (!st.hasMoreTokens) {st = new StringTokenizer(reader.readLine())};st.nextToken()}
    def readInt(): Int = next().toInt
    def readLong(): Long = next().toLong
    def readString(): String = next()

    case class fenwick(n: Int) {
        val tree = new Array[Long](n+1)
        def query(ind: Int): Long = {
            var idx = ind
            var ans = 0L
            while (idx > 0) {
                ans += tree(idx)
                idx -= (idx & -idx)
            }
            return ans
        }
        def update(ind: Int, value: Long): Unit = {
            var idx = ind
            while (idx <= n) {
                tree(idx) += value
                idx += (idx & -idx)
            }
        }
    }

    case class pair(val l: Int, val r: Int)extends Ordered[pair] {
        override def compare(that: pair): Int = {
            return (r-l).compareTo(that.r-that.l)
        }
    }

    def gcd(a: Int, b: Int): Int = b match {
        case 0 => a
        case n => gcd(b, a % b)
    }
    val rem = 1000000007
    val maxn = 200010
    val mp = mutable.Map[Char, Int]()

    val t = readInt()

    for (tt <- 1 to t) {
        val n = readInt()
        var q = Vector[pair]()
        val mark = new Array[Boolean](n+1)
        var l = 0
        var r = 0
        for (i <- 1 to n) {
            l = readInt()
            r = readInt()
            q :+= pair(l, r)
        }
        q = q.sorted
        for (qq <- q) {
            for (i <- qq.l to qq.r) {
                if (!mark(i)) {
                    writer.println(qq.l + " " + qq.r + " " + i)
                    mark(i) = true
                }
            }
        }
        writer.println()

        def check(kk: Long): Boolean = {
            return false
        }
        def bs(st:Long, en:Long): Long = {
            if (en - st <= 1L) {
                if (check(st))
                    return st
                else
                    return en
            }
            val mid = (st + en) / 2L
            if (check(mid))
                return bs(st, mid)
            else
                return bs(mid, en)
        }
    }
    writer.flush()
}

object B {
  import InOut._
  def main(args: Array[String]): Unit = {

    case class R(l: Int, r: Int)

    for (_ <- 1 to nextInt) {
      val n = nextInt
      val rs = Array.fill(n) {
        val l, r = nextInt
        R(l, r)
      }.sortBy {
        r => (r.l, -r.r)
      }

      val ds = Array.ofDim[Int](n)
      for (i <- rs.indices) {
        val r = rs(i)
        if (r.r == r.l) ds(i) = r.l
        else {
          val next = rs(i + 1)
          if (next.l == r.l) ds(i) = next.r + 1
          else ds(i) = next.l - 1
        }
      }

      for (i <- rs.indices) {
        out.println(s"${rs(i).l} ${rs(i).r} ${ds(i)}")
      }
    }

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


Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$.

The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively.

For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$.

NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$.

import scala.io.StdIn._

object Main extends App {

    val n = readLine().toInt

    for (i <- 0 until n) {
        val Array(c, sum) = readLine().split(" ").map(_.toInt)
        var arr = Seq.fill(c)(1)
        var res: Long = 0
        if (c > sum) {
            res = sum
        } else {
            val del: Int = sum / c
            val needUp = sum - del * c
            res = Math.pow(del, 2).asInstanceOf[Long] * (c-needUp) +
                    Math.pow(del+1, 2).asInstanceOf[Long] * needUp
        }
        println(res)
    }

}

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

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

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

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

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

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

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

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

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

object Workspace {
  import Main._
}

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

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

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

  def solve(): Unit = {
    val N = ni()
    REP(N) { _ =>
      val c, s = ni()
      val ans = if (c >= s) {
        s
      } else {
        if (s % c == 0) {
          val unit = s / c
          unit.toLong * unit * c
        } else {
          val unit1 = (s + c - 1) / c
          val unit2 = s / c
          val r = s % c
          unit1.toLong * unit1 * r + unit2.toLong * unit2 * (c - r)
        }
      }
      out.println(ans)
    }
  }
}

import scala.io.StdIn._
object Main{
  def main(args: Array[String]): Unit ={
    val N = readInt()
    val C = Array.ofDim[Int](N)
    val SUM = Array.ofDim[Int](N)
    for(i <- 0 until N){
      val line = readLine().split(" ").map(_.toInt)
      val c = line(0)
      val sum = line(1)
      val result =
      if(sum % c == 0){
        val k = sum / c
        k * k * c
      }else{
        val extra = sum % c
        val k = sum / c
        k * k * (c - extra) + (k+1) * (k+1) * extra
      }
      println(result)
    }
  }
}

import scala.io.StdIn._

object Main extends App {

    val n = readLine().toInt

    for (i <- 0 until n) {
        val Array(c, sum) = readLine().split(" ").map(_.toInt)
        var arr = Seq.fill(c)(1)
        var res: Long = 0
        if (c > sum) {
            res = 1
        } else {
            var del: Int = sum / c
            val needUp = sum - del * c
            res = Math.pow(del, 2).asInstanceOf[Long] * (c-needUp) +
                    Math.pow(del+1, 2).asInstanceOf[Long] * needUp
        }
        println(res)
    }

}


This is an interactive problem. In the output section below you will see the information about flushing the output.On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in Vičkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building.In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of n dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to n. After a little thought, the girl ordered exactly k different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better.The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers x and y (1 ≤ x, y ≤ n). After that Noora chooses some dish a for the number x such that, at first, a is among the dishes Noora ordered (x can be equal to a), and, secondly, the value  is the minimum possible. By the same rules the girl chooses dish b for y. After that Noora says «TAK» to Leha, if , and «NIE» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered.Help Leha to solve this problem!

There are two numbers n and k (2 ≤ k ≤ n ≤ 105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.

If you want to provide an answer, output a string of the form 2 x y (1 ≤ x, y ≤ n, x ≠ y), if you think the dishes x and y was among dishes ordered by Noora. After that, flush the output and terminate your program.

NoteThere are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (x = 1), then she'll choose the second dish (a = 2) as the dish with the minimum value . For the second (x = 2) and the third (x = 3) dishes themselves will be optimal, because in that case . Let Leha asks Noora about the next couple of dishes:  x = 1, y = 2, then he'll recieve «NIE» answer, because |1 - 2| > |2 - 2|  x = 2, y = 1, then he'll recieve «TAK» answer, because |2 - 2| ≤ |1 - 2|  x = 1, y = 3, then he'll recieve «NIE» answer, because |1 - 2| > |3 - 3|  x = 3, y = 1, then he'll recieve «TAK» answer, because |3 - 3| ≤ |1 - 2|  x = 2, y = 3, then he'll recieve «TAK» answer, because |2 - 2| ≤ |3 - 3|  x = 3, y = 2, then he'll recieve «TAK» answer, because |3 - 3| ≤ |2 - 2| According to the available information, it is possible to say that Nura ordered dishes with numbers 2 and 3.

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, k) = readInts(2)

  def solve(left: Int, right: Int): Int = {
    if (left == right) left
    else {
      val mid = (left + right + 1) / 2
      val lMid = (left + mid) / 2
      val rMid = (mid + right + 1) / 2

      //println(left, right, mid, lMid, rMid)

      println(s"1 $lMid $rMid")
      Console.flush

      readLine match {
        case "TAK" =>
          if (mid == right) solve(left, mid - 1)
          else solve(left, mid)
        case "NIE" =>
          if (mid == left) solve(mid + 1, right)
          else solve(mid, right)
      }
    }
  }

  val res1 = solve(1, n)
  //println(res1)
  val res2a = if (res1 > 1) solve(1, res1 - 1) else -1
  val res2b = if (res1 < n) solve(res1 + 1, n) else -1

  val res2 = if (res2a == -1) res2b
  else if (res2b == -1) res2a
  else {
    println(s"1 $res2a $res2b")
    Console.flush

    readLine match {
      case "TAK" =>
        res2a
      case "NIE" =>
        res2b
    }
  }

  println(s"2 $res1 $res2")
  Console.flush
}

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, k) = readInts(2)

  def solve(left: Int, right: Int): Int = {
    if (left == right) left
    else {
      val mid = (left + right + 1) / 2
      val lMid = (left + mid) / 2
      val rMid = (mid + right + 1) / 2

//      println(left, right, mid, lMid, rMid)

      println(s"1 $lMid $rMid")
      Console.flush

      readLine match {
        case "TAK" =>
          if (mid == right) solve(left, mid - 1)
          else solve(left, mid)
        case "NIE" =>
          if (mid == left) solve(mid + 1, right)
          else solve(mid, right)
      }
    }
  }

  val res1 = solve(1, n)
  //println(res1)
  val res2a = solve(1, res1 - 1)
  val res2b = solve(res1 + 1, n)

  println(s"1 $res2a $res2b")
  Console.flush

  val res2 = readLine match {
    case "TAK" =>
      res2a
    case "NIE" =>
      res2b
  }

  println(s"2 $res1 $res2")
  Console.flush
}

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, k) = readInts(2)

  def solve(left: Int, right: Int): Int = {
    //println(left, right)
    if (left == right) left
    else {
      val mid = (left + right) / 2
      val lMid = (left + mid) / 2
      val rMid = (mid + right + 1) / 2

      println(s"1 $lMid $rMid")
      Console.flush

      readLine match {
        case "TAK" =>
          solve(left, mid)
        case "NIE" =>
          solve(mid, right)
      }
    }
  }

  val res1 = solve(1, n)
  val res2a = solve(1, res1 - 1)
  val res2b = solve(res1 + 1, n)

  println(s"1 $res2a $res2b")
  Console.flush

  val res2 = readLine match {
    case "TAK" =>
      res2a
    case "NIE" =>
      res2b
  }

  println(s"2 $res1 $res2")
  Console.flush
}

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, k) = readInts(2)

  def solve(left: Int, right: Int): Int = {
    if (left == right) left
    else {
      val mid = (left + right + 1) / 2
      val lMid = (left + mid) / 2
      val rMid = (mid + right + 1) / 2

      println(left, right, mid, lMid, rMid)

      //println(s"1 $lMid $rMid")
      Console.flush

      readLine match {
        case "TAK" =>
          if (mid == right) solve(left, mid - 1)
          else solve(left, mid)
        case "NIE" =>
          solve(mid, right)
      }
    }
  }

  val res1 = solve(1, n)
  //println(res1)
  val res2a = solve(1, res1 - 1)
  val res2b = solve(res1 + 1, n)

  println(s"1 $res2a $res2b")
  Console.flush

  val res2 = readLine match {
    case "TAK" =>
      res2a
    case "NIE" =>
      res2b
  }

  println(s"2 $res1 $res2")
  Console.flush
}

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, k) = readInts(2)

  def solve(left: Int, right: Int): Int = {
    if (left == right) left
    else {
      val mid = (left + right + 1) / 2
      val lMid = (left + mid) / 2
      val rMid = (mid + right + 1) / 2

//      println(left, right, mid, lMid, rMid)

      println(s"1 $lMid $rMid")
      Console.flush

      readLine match {
        case "TAK" =>
          if (mid == right) solve(left, mid - 1)
          else solve(left, mid)
        case "NIE" =>
          solve(mid, right)
      }
    }
  }

  val res1 = solve(1, n)
  //println(res1)
  val res2a = solve(1, res1 - 1)
  val res2b = solve(res1 + 1, n)

  println(s"1 $res2a $res2b")
  Console.flush

  val res2 = readLine match {
    case "TAK" =>
      res2a
    case "NIE" =>
      res2b
  }

  println(s"2 $res1 $res2")
  Console.flush
}

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, k) = readInts(2)

  def solve(left: Int, right: Int): Int = {
    //println(left, right)
    if (left == right) left
    else {
      val mid = (left + right + 1) / 2
      val lMid = (left + mid + 1) / 2
      val rMid = (mid + right) / 2

      println(s"1 $lMid $rMid")
      Console.flush

      readLine match {
        case "TAK" =>
          solve(left, mid)
        case "NIE" =>
          solve(mid, right)
      }
    }
  }

  val res1 = solve(1, n)
  val res2a = solve(1, res1 - 1)
  val res2b = solve(res1 + 1, n)

  println(s"1 $res2a $res2b")
  Console.flush

  val res2 = readLine match {
    case "TAK" =>
      res2a
    case "NIE" =>
      res2b
  }

  println(s"2 $res1 $res2")
  Console.flush
}


Vlad likes to eat in cafes very much. During his life, he has visited cafes n times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe.

In first line there is one integer n (1 ≤ n ≤ 2·105) — number of cafes indices written by Vlad. In second line, n numbers a1, a2, ..., an (0 ≤ ai ≤ 2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted.

Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.

NoteIn first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with index 2, so the answer is 2. Note that Vlad could omit some numbers while numerating the cafes.

import java.io._
import java.util.Scanner
import scala.language.implicitConversions

object Template {

  class Lazy[A](x: => A) {
    lazy val value = x
    override def toString(): String = value.toString()
  }

  object Lazy {
    def apply[A](x: => A) = new Lazy(x)
    implicit def fromLazy[A](z: Lazy[A]): A = z.value
    implicit def toLazy[A](x: => A): Lazy[A] = Lazy(x)
  }

  import Lazy._

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val N = sc.nextInt()
    val A = for (i <- 0.until(N)) yield sc.nextInt()
    val valueToMaxIndex = A.zipWithIndex.groupBy(_._1).mapValues(list => list.map(_._2).max)
    val minIndex = valueToMaxIndex.map{case (v, index) => index}.min
    val answer = A(minIndex)

    println(answer)

  }
}

object B extends App {

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

  val Array(n) = readInts(1)
  val as = readInts(n)
  val last = Array.fill(as.max + 1)(Int.MaxValue / 2)

  for (i <- as.indices) last(as(i)) = i

  val min = as.minBy(last)

  println(min)
}

/**
  * @see http://codeforces.com/contest/890/problem/B
  */

object BVladAndCafes extends App {
  val n = scala.io.StdIn.readLine().toInt
  val as = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val last = Array.fill(as.max + 1)(20000)

  for (i <- as.indices) last(as(i)) = i

  println(as minBy last)
}

import java.io._
import java.util.Scanner
import scala.language.implicitConversions

object Template {

  class Lazy[A](x: => A) {
    lazy val value = x
    override def toString(): String = value.toString()
  }

  object Lazy {
    def apply[A](x: => A) = new Lazy(x)
    implicit def fromLazy[A](z: Lazy[A]): A = z.value
    implicit def toLazy[A](x: => A): Lazy[A] = Lazy(x)
  }

  import Lazy._

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val N = sc.nextInt()
    val A = for (i <- 0.until(N)) yield sc.nextInt()
    val valueToMaxIndex = A.zipWithIndex.groupBy(_._2).mapValues(list => list.map(_._2).max)
    val minIndex = valueToMaxIndex.map{case (v, index) => index}.min
    val answer = A(minIndex)

    println(answer)

  }
}


Bessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play! More specifically, he wants to get from $$$(0,0)$$$ to $$$(x,0)$$$ by making multiple hops. He is only willing to hop from one point to another point on the 2D plane if the Euclidean distance between the endpoints of a hop is one of its $$$n$$$ favorite numbers: $$$a_1, a_2, \ldots, a_n$$$. What is the minimum number of hops Rabbit needs to get from $$$(0,0)$$$ to $$$(x,0)$$$? Rabbit may land on points with non-integer coordinates. It can be proved that Rabbit can always reach his destination.Recall that the Euclidean distance between points $$$(x_i, y_i)$$$ and $$$(x_j, y_j)$$$ is $$$\sqrt{(x_i-x_j)^2+(y_i-y_j)^2}$$$.For example, if Rabbit has favorite numbers $$$1$$$ and $$$3$$$ he could hop from $$$(0,0)$$$ to $$$(4,0)$$$ in two hops as shown below. Note that there also exists other valid ways to hop to $$$(4,0)$$$ in $$$2$$$ hops (e.g. $$$(0,0)$$$ $$$\rightarrow$$$ $$$(2,-\sqrt{5})$$$ $$$\rightarrow$$$ $$$(4,0)$$$).    Here is a graphic for the first example. Both hops have distance $$$3$$$, one of Rabbit's favorite numbers. In other words, each time Rabbit chooses some number $$$a_i$$$ and hops with distance equal to $$$a_i$$$ in any direction he wants. The same number can be used multiple times.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Next $$$2t$$$ lines contain test cases — two lines per test case. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le x \le 10^9$$$)  — the number of favorite numbers and the distance Rabbit wants to travel, respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$)  — Rabbit's favorite numbers. It is guaranteed that the favorite numbers are distinct. It is guaranteed that the sum of $$$n$$$ over all the test cases will not exceed $$$10^5$$$.

For each test case, print a single integer — the minimum number of hops needed.

NoteThe first test case of the sample is shown in the picture above. Rabbit can hop to $$$(2,\sqrt{5})$$$, then to $$$(4,0)$$$ for a total of two hops. Each hop has a distance of $$$3$$$, which is one of his favorite numbers.In the second test case of the sample, one way for Rabbit to hop $$$3$$$ times is: $$$(0,0)$$$ $$$\rightarrow$$$ $$$(4,0)$$$ $$$\rightarrow$$$ $$$(8,0)$$$ $$$\rightarrow$$$ $$$(12,0)$$$.In the third test case of the sample, Rabbit can hop from $$$(0,0)$$$ to $$$(5,0)$$$.In the fourth test case of the sample, Rabbit can hop: $$$(0,0)$$$ $$$\rightarrow$$$ $$$(5,10\sqrt{2})$$$ $$$\rightarrow$$$ $$$(10,0)$$$.

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

  import scala.collection.mutable
  import scala.collection.mutable.ListBuffer
  def main(args: Array[String]): Unit = {
    solve(System.in,System.out)
  }
  def solve(inputStream: InputStream, out: PrintStream): Unit = {
    val in = new InputReader(inputStream)
    val t = in.nextInt()
    ( 1 to t).foreach{ _ =>
      val n = in.nextInt()
      val x = in.nextInt()
      val a = (1 to n).map(_ => in.nextInt())
      val m = a.max
      if(a.contains(x)){
        out.println(1)
      }else{
        if(m>x){
          out.println(2)
        }else{
          val res = (x+m-1)/m
          out.println(res)
        }
      }

    }
  }
  class InputReader(stream: InputStream){
    val reader: BufferedReader = new BufferedReader(new InputStreamReader(stream),32768)
    var tokenizer: StringTokenizer = _
    def next(): String = {
      while(tokenizer == null || !tokenizer.hasMoreTokens){
        try{
          tokenizer = new StringTokenizer(reader.readLine())
        }catch {
          case e: IOException => throw new RuntimeException(e)
        }
      }
      tokenizer.nextToken()
    }
    def nextInt(): Int =  next().toInt
    def nextLong(): Long =  next().toLong
  }
}


Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are n destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The n destinations are described by a non-negative integers sequence a1, a2, ..., an. The number ak represents that the kth destination is at distance ak kilometers from the starting point. No two destinations are located in the same place. Iahub wants to visit each destination only once. Note that, crossing through a destination is not considered visiting, unless Iahub explicitly wants to visit it at that point. Also, after Iahub visits his last destination, he doesn't come back to kilometer 0, as he stops his trip at the last destination. The distance between destination located at kilometer x and next destination, located at kilometer y, is |x - y| kilometers. We call a "route" an order of visiting the destinations. Iahub can visit destinations in any order he wants, as long as he visits all n destinations and he doesn't visit a destination more than once. Iahub starts writing out on a paper all possible routes and for each of them, he notes the total distance he would walk. He's interested in the average number of kilometers he would walk by choosing a route. As he got bored of writing out all the routes, he asks you to help him.

The first line contains integer n (2 ≤ n ≤ 105). Next line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 107).

Output two integers — the numerator and denominator of a fraction which is equal to the wanted average number. The fraction must be irreducible.

object CF340C_198 extends App{
  def gcd (x : Long, y : Long) : Long = {
    if (x % y == 0) y else gcd (y, x % y)
  }
  val n = Console.readLine.toInt
  val a = Console.readLine.split(' ').map(_.toLong).sorted.zip(1 to n).map{case (x, i) =>
    (4 * i - 2 * n - 1) * x
  }.reduce(_ + _)
  val d = gcd(a, n)
  printf("%d %d\n", a/d, n/d)
}

object CF340C_198 extends App{
  def gcd (x : Long, y : Long) : Long = {
    if (x % y == 0) y else gcd (y, x % y)
  }
  val n = Console.readLine.toInt
  val a = Console.readLine.split(' ').map(_.toLong).sorted.zip(1 to n).map{case (x, i) =>
    (4 * i - 2 * n - 1) * x
  }.reduce(_ + _)
  val d = gcd(a, n)
  println((a/d).toString + " " + (n/d).toString)
}

object CF340C_198 extends App{
  def gcd (x : Long, y : Long) : Long = {
    if (x % y == 0) y else gcd (y, x % y)
  }
  val n = Console.readLine.toInt
  val a = Console.readLine.split(' ').map(_.toLong).zip(1 to n).map{case (x, i) =>
    (4 * i - 2 * n - 1) * x
  }.reduce(_ + _)
  val d = gcd(a, n)
  printf ("%d %d", a/d, n/d)
}


There is an infinite set generated as follows:  $$$1$$$ is in this set.  If $$$x$$$ is in this set, $$$x \cdot a$$$ and $$$x+b$$$ both are in this set. For example, when $$$a=3$$$ and $$$b=6$$$, the five smallest elements of the set are:  $$$1$$$,  $$$3$$$ ($$$1$$$ is in this set, so $$$1\cdot a=3$$$ is in this set),  $$$7$$$ ($$$1$$$ is in this set, so $$$1+b=7$$$ is in this set),  $$$9$$$ ($$$3$$$ is in this set, so $$$3\cdot a=9$$$ is in this set),  $$$13$$$ ($$$7$$$ is in this set, so $$$7+b=13$$$ is in this set). Given positive integers $$$a$$$, $$$b$$$, $$$n$$$, determine if $$$n$$$ is in this set.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\leq t\leq 10^5$$$) — the number of test cases. The description of the test cases follows. The only line describing each test case contains three integers $$$n$$$, $$$a$$$, $$$b$$$ ($$$1\leq n,a,b\leq 10^9$$$) separated by a single space.

For each test case, print "Yes" if $$$n$$$ is in this set, and "No" otherwise. You can print each letter in any case.

NoteIn the first test case, $$$24$$$ is generated as follows:  $$$1$$$ is in this set, so $$$3$$$ and $$$6$$$ are in this set;  $$$3$$$ is in this set, so $$$9$$$ and $$$8$$$ are in this set;  $$$8$$$ is in this set, so $$$24$$$ and $$$13$$$ are in this set. Thus we can see $$$24$$$ is in this set.The five smallest elements of the set in the second test case is described in statements. We can see that $$$10$$$ isn't among them.

object B extends App {
  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val Array(n, a, b) = readLine().split(" ").map(_.toLong)

    val ans = {
      @annotation.tailrec
      def go(x: Long): Boolean = x <= n && ((n - x) % b == 0 || a != 1 && go(x * a))

      go(1)
    }

    ans match {
      case true => println("Yes")
      case _    => println("No")
    }
  }
}