You play your favourite game yet another time. You chose the character you didn't play before. It has $$$str$$$ points of strength and $$$int$$$ points of intelligence. Also, at start, the character has $$$exp$$$ free experience points you can invest either in strength or in intelligence (by investing one point you can either raise strength by $$$1$$$ or raise intelligence by $$$1$$$).Since you'd like to make some fun you want to create a jock character, so it has more strength than intelligence points (resulting strength is strictly greater than the resulting intelligence).Calculate the number of different character builds you can create (for the purpose of replayability) if you must invest all free points. Two character builds are different if their strength and/or intellect are different.

The first line contains the single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. Next $$$T$$$ lines contain descriptions of queries — one per line. This line contains three integers $$$str$$$, $$$int$$$ and $$$exp$$$ ($$$1 \le str, int \le 10^8$$$, $$$0 \le exp \le 10^8$$$) — the initial strength and intelligence of the character and the number of free points, respectively.

Print $$$T$$$ integers — one per query. For each query print the number of different character builds you can create.

NoteIn the first query there are only three appropriate character builds: $$$(str = 7, int = 5)$$$, $$$(8, 4)$$$ and $$$(9, 3)$$$. All other builds are either too smart or don't use all free points.In the second query there is only one possible build: $$$(2, 1)$$$.In the third query there are two appropriate builds: $$$(7, 6)$$$, $$$(8, 5)$$$.In the fourth query all builds have too much brains.

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

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

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

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

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

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

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

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

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

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

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

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

  def solve(): Unit = {
    REP(ni()) { _ =>
      var str, int, exp = ni()
      val s = str + int + exp
      val d = max(0 ,int - str + 1)
      str += d
      exp -= d
      val intMin = int
      val intMax = min(int + exp, s / 2 + (if (s % 2 == 0) -1 else 0))
      val ans = max(0, intMax - intMin + 1)
      out.println(ans)
    }
  }
}

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

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

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

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

    def nextInt(): Int = Integer.parseInt(next())
//    def tokenizer = new java.util.StringTokenizer(reader.readLine)
//    def readLine = reader.readLine
//    def readInts(n: Int) = { val tl = tokenizer; Array.fill(n)(tl.nextToken.toInt) }
//    def readLongs(n: Int) = { val tl = tokenizer; Array.fill(n)(tl.nextToken.toLong) }
  }

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

}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import Math.{max, min}

  def solve(): Unit = {
    //for (_ <- 1 to nextInt()) {
    REP(nextInt()) { _ =>
      var str, int, exp = nextInt()
      val s = str + int + exp
      val d = max(0 ,int - str + 1)
      str += d
      exp -= d
      val intMin = int
      val intMax = min(int + exp, s / 2 + (if (s % 2 == 0) -1 else 0))
      val ans = max(0, intMax - intMin + 1)
      out.println(ans)
    }
  }
}

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

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

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

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

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

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

}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import Math.{max, min}

  def solve(): Unit = {
    REP(nextInt()) { _ =>
      var str, int, exp = nextInt()
      val s = str + int + exp
      val d = max(0 ,int - str + 1)
      str += d
      exp -= d
      val intMin = int
      val intMax = min(int + exp, s / 2 + (if (s % 2 == 0) -1 else 0))
      val ans = max(0, intMax - intMin + 1)
      out.println(ans)
    }
  }
}

object A {

  def main(args: Array[String]): Unit = {
    (new A).solve()
  }

}

class A {
  val out = new java.io.PrintWriter(System.out)
  val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
  def tokenizer = new java.util.StringTokenizer(in.readLine)
  def readInts(n: Int) = { val tl = tokenizer; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizer; Array.fill(n)(tl.nextToken.toLong) }
  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 solve() = {
    val Array(t) = readInts(1)

    REP(t) { _ =>
      val Array(str, int, exp) = readLongs(3)

      def can(i: Long) = {
        str + i > int + (exp - i)
      }

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

      val res = exp - binSearch(0, exp) + 1

      out.println(res)
    }

    out.flush()
  }
}

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

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

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

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

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

    def ni(): Int = nextInt()
  }

}

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

  import math.{max, min}

  def solve(): Unit = {
    val t = ni()
    for (_ <- 1 to t) {
      var str, int, exp = ni()
      val s = str + int + exp
      val d = max(0 ,int - str + 1)
      str += d
      exp -= d
      val intMin = int
      val intMax = min(int + exp, s / 2 + (if (s % 2 == 0) -1 else 0))
      val ans = max(0, intMax - intMin + 1)
      out.println(ans)
    }
  }
}

object A {

  def main(args: Array[String]): Unit = {}
  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(t) = readInts(1)

  for (_ <- 1 to t) {
    val Array(str, int, exp) = readLongs(3)

    def can(i: Long) = {
      str + i > int + (exp - i)
    }

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

    val res = exp - binSearch(0, exp) + 1

    println(res)
  }
}

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

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

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

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

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

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

}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import Math.{max, min}

  def solve(): Unit = {
    //for (_ <- 1 to nextInt()) {
    REP(nextInt()) { _ =>
      var str, int, exp = nextInt()
      val s = str + int + exp
      val d = max(0 ,int - str + 1)
      str += d
      exp -= d
      val intMin = int
      val intMax = min(int + exp, s / 2 + (if (s % 2 == 0) -1 else 0))
      val ans = max(0, intMax - intMin + 1)
      out.println(ans)
    }
  }
}

object A {

  def main(args: Array[String]): Unit = {}
  val out = new java.io.PrintWriter(System.out)
  val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
  def tokenizer = new java.util.StringTokenizer(in.readLine)
  def readInts(n: Int) = { val tl = tokenizer; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizer; Array.fill(n)(tl.nextToken.toLong) }

  val Array(t) = readInts(1)

  for (_ <- 1 to t) {
    val Array(str, int, exp) = readLongs(3)

    def can(i: Long) = {
      str + i > int + (exp - i)
    }

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

    val res = exp - binSearch(0, exp) + 1

    out.println(res)
  }

  out.flush()
}

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

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

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

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

    def nextInt(): Int = Integer.parseInt(next())
//    def tokenizer = new java.util.StringTokenizer(reader.readLine)
//    def readLine = reader.readLine
//    def readInts(n: Int) = { val tl = tokenizer; Array.fill(n)(tl.nextToken.toInt) }
//    def readLongs(n: Int) = { val tl = tokenizer; Array.fill(n)(tl.nextToken.toLong) }
  }

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

}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import Math.{max, min}

  def solve(): Unit = {
    //for (_ <- 1 to nextInt()) {
    REP(nextInt()) { _ =>
      var str, int, exp = nextInt()
      val s = str + int + exp
      val d = max(0 ,int - str + 1)
      str += d
      exp -= d
      val intMin = int
      val intMax = min(int + exp, s / 2 + (if (s % 2 == 0) -1 else 0))
      val ans = max(0, intMax - intMin + 1)
      out.println(ans)
    }
  }
}

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

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

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
//    private var tokenizer: StringTokenizer = _
//
//    def next(): String = {
//      while (tokenizer == null || !tokenizer.hasMoreTokens)
//        tokenizer = new StringTokenizer(reader.readLine)
//      tokenizer.nextToken
//    }
//
//    def nextInt(): Int = Integer.parseInt(next())
    def tokenizer = new java.util.StringTokenizer(reader.readLine)
    def readLine = reader.readLine
    def readInts(n: Int) = { val tl = tokenizer; Array.fill(n)(tl.nextToken.toInt) }
    def readLongs(n: Int) = { val tl = tokenizer; Array.fill(n)(tl.nextToken.toLong) }
  }

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

}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import Math.{max, min}

  def solve(): Unit = {
    //for (_ <- 1 to nextInt()) {
    REP(readLine.toInt) { _ =>
      var Array(str, int, exp) = readLongs(3)
      val s = str + int + exp
      val d = max(0 ,int - str + 1)
      str += d
      exp -= d
      val intMin = int
      val intMax = min(int + exp, s / 2 + (if (s % 2 == 0) -1 else 0))
      val ans = max(0, intMax - intMin + 1)
      out.println(ans)
    }
  }
}

object A {

  def main(args: Array[String]): Unit = {}
  val out = new java.io.PrintWriter(System.out)
  val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
  def tokenizer = new java.util.StringTokenizer(in.readLine)
  def readInts(n: Int) = { val tl = tokenizer; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizer; Array.fill(n)(tl.nextToken.toLong) }
  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 }
  }

  val Array(t) = readInts(1)

  REP(t) { _ =>
    val Array(str, int, exp) = readLongs(3)

    def can(i: Long) = {
      str + i > int + (exp - i)
    }

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

    val res = exp - binSearch(0, exp) + 1

    out.println(res)
  }

  out.flush()
}

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

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

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

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

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

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

}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import Math.{max, min}

  def solve(): Unit = {
    for (_ <- 1 to nextInt()) {
      var str, int, exp = nextInt()
      val s = str + int + exp
      val d = max(0 ,int - str + 1)
      str += d
      exp -= d
      val intMin = int
      val intMax = min(int + exp, s / 2 + (if (s % 2 == 0) -1 else 0))
      val ans = max(0, intMax - intMin + 1)
      out.println(ans)
    }
  }
}

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

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

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

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

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

    def ni(): Int = nextInt()
  }

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

}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import Math.{max, min}

  def solve(): Unit = {
    REP(ni()) { _ =>
      var str, int, exp = ni()
      val s = str + int + exp
      val d = max(0 ,int - str + 1)
      str += d
      exp -= d
      val intMin = int
      val intMax = min(int + exp, s / 2 + (if (s % 2 == 0) -1 else 0))
      val ans = max(0, intMax - intMin + 1)
      out.println(ans)
    }
  }
}

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

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

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

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

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

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

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

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

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

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

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

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

  def solve(): Unit = {
    REP(ni()) { _ =>
      val str, int, exp = ni()
      val s = str + int + exp
      val intMin = int
      val intMax = s / 2 + (if (s % 2 == 0) -1 else 0)
      val ans = max(0, intMax - intMin + 1)
      out.println(ans)
    }
  }
}

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

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

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

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

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

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

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

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

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

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

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

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

  def solve(): Unit = {
    REP(ni()) { _ =>
      val str, int, exp = ni()
      val init = str + exp
      if (init <= int) out.println(0)
      else {
        val d = init - int
        val ans = d / 2 + (if(d % 2 == 1) 1 else 0)
        out.println(ans)
      }
    }
  }
}


Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside.The text is a string $$$s$$$ of lowercase Latin letters. She considers a string $$$t$$$ as hidden in string $$$s$$$ if $$$t$$$ exists as a subsequence of $$$s$$$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $$$1$$$, $$$3$$$, and $$$5$$$, which form an arithmetic progression with a common difference of $$$2$$$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $$$S$$$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!For example, in the string aaabb, a is hidden $$$3$$$ times, b is hidden $$$2$$$ times, ab is hidden $$$6$$$ times, aa is hidden $$$3$$$ times, bb is hidden $$$1$$$ time, aab is hidden $$$2$$$ times, aaa is hidden $$$1$$$ time, abb is hidden $$$1$$$ time, aaab is hidden $$$1$$$ time, aabb is hidden $$$1$$$ time, and aaabb is hidden $$$1$$$ time. The number of occurrences of the secret message is $$$6$$$.

The first line contains a string $$$s$$$ of lowercase Latin letters ($$$1 \le |s| \le 10^5$$$) — the text that Bessie intercepted.

Output a single integer  — the number of occurrences of the secret message.

NoteIn the first example, these are all the hidden strings and their indice sets:   a occurs at $$$(1)$$$, $$$(2)$$$, $$$(3)$$$  b occurs at $$$(4)$$$, $$$(5)$$$  ab occurs at $$$(1,4)$$$, $$$(1,5)$$$, $$$(2,4)$$$, $$$(2,5)$$$, $$$(3,4)$$$, $$$(3,5)$$$  aa occurs at $$$(1,2)$$$, $$$(1,3)$$$, $$$(2,3)$$$  bb occurs at $$$(4,5)$$$  aab occurs at $$$(1,3,5)$$$, $$$(2,3,4)$$$  aaa occurs at $$$(1,2,3)$$$  abb occurs at $$$(3,4,5)$$$  aaab occurs at $$$(1,2,3,4)$$$  aabb occurs at $$$(2,3,4,5)$$$  aaabb occurs at $$$(1,2,3,4,5)$$$  Note that all the sets of indices are arithmetic progressions.In the second example, no hidden string occurs more than once.In the third example, the hidden string is the letter l.

import collection.mutable.HashMap

object Main {
  def main(args: Array[String]): Unit = {
    val s = readLine
    val cArr = Array.ofDim[Long](26)
    val iArr = Array.ofDim[Long](s.length, 26)
    for(i <- 0 until s.length) {
      val c = s.charAt(i) - 'a'
      cArr(c) += 1
      Array.copy(cArr, 0, iArr(i), 0, cArr.size)
    }
    val pArr = Array.ofDim[Long](26, 26)
    for(i <- 1 until s.length) {
      val c = s.charAt(i) - 'a'
      for(j <- 0 until 26) {
        val cp = iArr(i - 1)(j)
        pArr(j)(c) += cp
      }
    }
    println(Math.max(pArr.map(_.max).max, cArr.max))
  }
}

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 a = Array.fill(30*31)(0L)
    val s = in.next()
    def toIndx2(x: Int, y: Int): Int = x*30+y
    def toIndx(ch: Char): Int = (ch-'a'+1).toInt
    val count = Array.fill(30)(0L)
    s.zipWithIndex.foreach{ case (ch,i) =>
      val chIndex = toIndx(ch)

      (0 to 29).foreach(k => {
        a(toIndx2(k,chIndex)) += count(k)
      })

      count(chIndex) += 1

    }
    val res = Math.max(a.max,count.max)
    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
  }
}

import collection.mutable.HashMap

object Main {
  def main(args: Array[String]): Unit = {
    val s = readLine
    val cArr = Array.ofDim[Int](26)
    val iArr = Array.ofDim[Int](s.length, 26)
    for(i <- 0 until s.length) {
      val c = s.charAt(i) - 'a'
      cArr(c) += 1
      Array.copy(cArr, 0, iArr(i), 0, cArr.size)
    }
    val pArr = Array.ofDim[Int](26, 26)
    for(i <- 1 until s.length) {
      val c = s.charAt(i) - 'a'
      for(j <- 0 until 26) {
        val cp = iArr(i - 1)(j)
        pArr(j)(c) += cp
      }
    }
    println(Math.max(pArr.map(_.max).max, cArr.max))
  }
}

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 a = Array.fill(27*27+27)(0)
    val s = in.next()
    def toIndx2(x: Int, y: Int): Int = x*27+y
    def toIndx(ch: Char): Int = (ch-'a').toInt
    val count = Array.fill(27)(0)
    s.zipWithIndex.foreach{ case (ch,i) =>
      val chIndex = toIndx(ch)

      (0 to 26).foreach(k => {
        a(toIndx2(k,chIndex)) += count(k)
      })

      count(chIndex) += 1

    }
    val res = Math.max(a.max,count.max)
    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
  }
}


Lately, a national version of a bingo game has become very popular in Berland. There are n players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the i-th player contains mi numbers.During the game the host takes numbered balls one by one from a bag. He reads the number aloud in a high and clear voice and then puts the ball away. All participants cross out the number if it occurs on their cards. The person who crosses out all numbers from his card first, wins. If multiple people cross out all numbers from their cards at the same time, there are no winners in the game. At the beginning of the game the bag contains 100 balls numbered 1 through 100, the numbers of all balls are distinct.You are given the cards for each player. Write a program that determines whether a player can win the game at the most favorable for him scenario or not.

The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of the players. Then follow n lines, each line describes a player's card. The line that describes a card starts from integer mi (1 ≤ mi ≤ 100) that shows how many numbers the i-th player's card has. Then follows a sequence of integers ai, 1, ai, 2, ..., ai, mi (1 ≤ ai, k ≤ 100) — the numbers on the i-th player's card. The numbers in the lines are separated by single spaces. It is guaranteed that all the numbers on each card are distinct.

Print n lines, the i-th line must contain word "YES" (without the quotes), if the i-th player can win, and "NO" (without the quotes) otherwise.

object Probb{
    def main(args:Array[String]){
        var n=readInt()
        var list=new Array[Set[Int]](n)
        var listans=new Array[String](n)
        for(i<-0 until n){
            var buff=readLine.split(' ').map(x=>x.toInt)
            list(i)=buff.slice(1,buff(0)+1).toSet
        }
        for(i<-0 until n){
            for(j<-0 until n){
                if(i!=j){
                    if(list(i) subsetOf list(j)){
                        listans(j)="NO"
                    }
                }
            }
        }
        for(i<-0 until n){
            if(listans(i)!=null)
                println("NO")
            else
                println("YES")
        }
    }
}

object Probb{
    def main(args:Array[String]){
        var n=readInt()
        var list=new Array[Set[Int]](n)
        var listans=new Array[String](n)
        for(i<-0 until n){
            var buff=readLine.split(' ').map(x=>x.toInt)
            list(i)=buff.slice(1,buff(0)+1).toSet
        }
        for(i<-0 until n){
            for(j<-0 until n){
                if(i!=j){
                    if(list(i) subsetOf list(j)){
                        listans(j)="NO"
                    }
                }
            }
        }
        for(i<-0 until n){
            if(listans(i)!=null)
                println("No")
            else
                println("Yes")
        }
    }
}


Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position a1 to position b1, the second — from a2 to b2What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.

The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi).

Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(n, x0) = in.next().split(' ').map(_.toInt)
  val answer = Array.ofDim[Int](1002)

  in.take(n).foreach { line =>
    val Array(a, b) = line.split(' ').map(_.toInt).sorted
    answer(a) += 1
    answer(b + 1) -= 1
  }

  val (a, _) = answer.indices.foldLeft(-1, 0) {
    case ((distance, sumSoFar), i) =>
      val nSum = sumSoFar + answer(i)
      if (nSum == n && (distance == -1 || Math.abs(x0 - i) < distance))
        (Math.abs(x0 - i), nSum)
      else
        (distance, nSum)
  }

  println(a)
}

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

object B {

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

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

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

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

  def comp(x: (Int, Int), y: (Int, Int)): Boolean = {
    if (x._1 != y._1) x._1 < y._1 else x._2 < y._2
  }

  def solve = {
    val n = nextInt
    val x0 = nextInt
    val ranges = new Array[(Int, Int)](n)
    for (i <- 0 until n) {
      val a = nextInt
      val b = nextInt
      ranges(i) = (Math.min(a, b), Math.max(a, b))
    }
    ranges.sortWith(comp)
    var start = 0
    var finish = Int.MaxValue
    for (i <- 0 until n) {
      start = Math.max(start, ranges(i)._1)
      finish = Math.min(finish, ranges(i)._2)
    }
    if (start > finish) {
      out.println(-1)
    } else {
      var ans = Int.MaxValue
      for (i <- start to finish) {
        if (Math.abs(x0 - i) < ans) {
          ans = Math.abs(x0 - i)
        }
      }
      out.println(ans)
    }
  }

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


The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vector is 1 or  - 1 and any two vectors are orthogonal. Just as a reminder, two vectors in n-dimensional space are considered to be orthogonal if and only if their scalar product is equal to zero, that is: .Danil quickly managed to come up with the solution for this problem and the teacher noticed that the problem can be solved in a more general case for 2k vectors in 2k-dimensinoal space. When Danil came home, he quickly came up with the solution for this problem. Can you cope with it?

The only line of the input contains a single integer k (0 ≤ k ≤ 9).

Print 2k lines consisting of 2k characters each. The j-th character of the i-th line must be equal to ' * ' if the j-th coordinate of the i-th vector is equal to  - 1, and must be equal to ' + ' if it's equal to  + 1. It's guaranteed that the answer always exists. If there are many correct answers, print any.

NoteConsider all scalar products in example:  Vectors 1 and 2: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( + 1) + ( - 1)·( - 1) = 0  Vectors 1 and 3: ( + 1)·( + 1) + ( + 1)·( + 1) + ( - 1)·( + 1) + ( - 1)·( + 1) = 0  Vectors 1 and 4: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( - 1) + ( - 1)·( + 1) = 0  Vectors 2 and 3: ( + 1)·( + 1) + ( - 1)·( + 1) + ( + 1)·( + 1) + ( - 1)·( + 1) = 0  Vectors 2 and 4: ( + 1)·( + 1) + ( - 1)·( - 1) + ( + 1)·( - 1) + ( - 1)·( + 1) = 0  Vectors 3 and 4: ( + 1)·( + 1) + ( + 1)·( - 1) + ( + 1)·( - 1) + ( + 1)·( + 1) = 0

import scala.io.StdIn

/**
  * Created by hsleep on 2016. 1. 7..
  */
object CSolution extends App {
  val k = StdIn.readInt()

  def makeOpposite(s: String): String = {
    s.map {
      case '+' => '*'
      case '*' => '+'
    }
  }

  def makeOutput(k: Int): Seq[String] = {
    k match {
      case 0 => Seq("+")
      case _ =>
        val input = makeOutput(k - 1)
        input.flatMap { s =>
          Seq(s + s, s + makeOpposite(s))
        }
    }
  }

  makeOutput(k).foreach(println)
}

import scala.io.StdIn

/**
  * Created by hsleep on 2016. 1. 7..
  */
object C {
  def main(args: Array[String]): Unit = {
    val k = StdIn.readInt()
    makeOutput(k).foreach(println)
  }

  def makeOutput(k: Int): Seq[String] = {
    k match {
      case 0 => Seq("+")
      case _ =>
        val input = makeOutput(k - 1)
        input.flatMap { s =>
          Seq(s + s, s + makeOpposite(s))
        }
    }
  }

  def makeOpposite(s: String): String = {
    s.map {
      case '+' => '*'
      case '*' => '+'
    }
  }
}


The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of r1 cm, inner radius of r2 cm, (0 < r2 < r1) made of metal with density p1 g/cm3. The second part is an inner disk with radius r2 cm, it is made of metal with density p2 g/cm3. The disk is nested inside the ring.The Olympic jury decided that r1 will take one of possible values of x1, x2, ..., xn. It is up to jury to decide which particular value r1 will take. Similarly, the Olympic jury decided that p1 will take one of possible value of y1, y2, ..., ym, and p2 will take a value from list z1, z2, ..., zk.According to most ancient traditions the ratio between the outer ring mass mout and the inner disk mass min must equal , where A, B are constants taken from ancient books. Now, to start making medals, the jury needs to take values for r1, p1, p2 and calculate the suitable value of r2.The jury wants to choose the value that would maximize radius r2. Help the jury find the sought value of r2. Value r2 doesn't have to be an integer.Medal has a uniform thickness throughout the area, the thickness of the inner disk is the same as the thickness of the outer ring.

The first input line contains an integer n and a sequence of integers x1, x2, ..., xn. The second input line contains an integer m and a sequence of integers y1, y2, ..., ym. The third input line contains an integer k and a sequence of integers z1, z2, ..., zk. The last line contains two integers A and B. All numbers given in the input are positive and do not exceed 5000. Each of the three sequences contains distinct numbers. The numbers in the lines are separated by spaces.

Print a single real number — the sought value r2 with absolute or relative error of at most 10 - 6. It is guaranteed that the solution that meets the problem requirements exists.

NoteIn the first sample the jury should choose the following values: r1 = 3, p1 = 2, p2 = 1.

object Main {
  def rins(rout: Float, p1: Float, p2: Float, a: Float, b: Float): Float = {
    val den = p2 * a + p1 * b
    rout * rout * p1 * b / den
  }

  def main(args: Array[String]) {
    val n :: xs = readLine().split(" ").map(_.toInt).toList
    val m :: ys = readLine().split(" ").map(_.toInt).toList
    val k :: zs = readLine().split(" ").map(_.toInt).toList
    val Array(a, b) = readLine().split(" ").map(_.toInt)
    val r = rins(xs.max.toFloat, ys.max.toFloat, zs.min.toFloat, a.toFloat, b.toFloat)
    println(math.sqrt(r))
  }
}


You are given a string, consisting of lowercase Latin letters.A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $$$(1, 2)$$$ — "ab" and $$$(2, 3)$$$ — "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.If there are multiple answers, print any of them.You also have to answer $$$T$$$ separate queries.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. Each of the next $$$T$$$ lines contains string $$$s$$$ $$$(1 \le |s| \le 100)$$$ — the string for the next query. It is guaranteed that it contains only lowercase Latin letters. Note that in hacks you have to set $$$T = 1$$$.

Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th query. If the answer for the $$$i$$$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same. If there are multiple answers, print any of them. Otherwise print "No answer" for that query.

NoteIn the first example answer "bdac" is also correct.The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.There are lots of valid answers for the third example.

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

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

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

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

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

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

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

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

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

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

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

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

  def solve(): Unit = {
    REP(ni()) { _ =>
      val S = ns()
      val C = Array.ofDim[Int](26)
      REP(S.length) { i =>
        C(S(i) - 'a') += 1
      }
      val even, odd = ArrayBuffer[Int]()
      REP(26) { i =>
        if (C(i) > 0) {
          (if (i % 2 == 0) even else odd) += i
        }
      }

      def sort(): Boolean = {
        REP(even.length) { i =>
          REP(odd.length) { j =>
            if (abs(even(i) - odd(j)) > 1) {
              even += even.remove(i)
              odd.insert(0, odd.remove(j))
              return true
            }
          }
        }
        false
      }

      def printAns(): Unit = {
        (even ++ odd).foreach { i =>
          REP(C(i)) { _ =>
            out.print(('a' + i).toChar)
          }
        }
        out.println()
      }

      if (even.isEmpty || odd.isEmpty) {
        printAns()
      } else {
        if (!sort()) {
          out.println("No answer")
        } else {
          printAns()
        }
      }

    }
  }
}

import java.util.Scanner

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

object Btask extends App {

  var line = new Scanner(StdIn.readLine())
  val n = line.nextInt()
  var matrix = ArrayBuffer[String]()
  for (i <- 0 until n) {
    line = new Scanner(StdIn.readLine())
    var matrixString = line.next()
    matrix.append(matrixString)
  }
  for (i <- 0 until n) {
    val evenChars = matrix(i).chars.filter(_ % 2 == 0).sorted().toArray
    val oddChars = matrix(i).chars.filter(_ % 2 == 1).sorted().toArray
    if (evenChars.isEmpty) {
      println(oddChars.map(_.toChar).mkString)
    } else {
      if (oddChars.isEmpty) {
        println(evenChars.map(_.toChar).mkString)
      } else {
        if (Math.abs(evenChars(evenChars.size - 1) - oddChars(0)) != 1) {
          println(evenChars.map(_.toChar).mkString + oddChars.map(_.toChar).mkString)
        } else {
          if (Math.abs(oddChars(oddChars.size - 1) - evenChars(0)) != 1) {
            println(oddChars.map(_.toChar).mkString + evenChars.map(_.toChar).mkString)
          } else {
            println("No answer")
          }
        }
      }
    }
  }
}


Given a string s, process q queries, each having one of the following forms:  1 i c — Change the i-th character in the string to c.  2 l r y — Consider the substring of s starting at position l and ending at position r. Output the number of times y occurs as a substring in it.

The first line of the input contains the string s (1 ≤ |s| ≤ 105) of lowercase English letters. The second line contains an integer q (1 ≤ q ≤ 105)  — the number of queries to process. The next q lines describe the queries and may have one of the following forms:   1 i c (1 ≤ i ≤ |s|)  2 l r y (1 ≤ l ≤ r ≤ |s|)  c is a lowercase English letter and y is a non-empty string consisting of only lowercase English letters. The sum of |y| over all queries of second type is at most 105. It is guaranteed that there is at least one query of second type. All strings are 1-indexed. |s| is the length of the string s.

For each query of type 2, output the required answer in a separate line.

abcdcbc
5
2 1 7 bc
1 4 b
2 4 7 bc
1 2 a
2 1 4 aa

NoteConsider the first sample case. Initially, the string aba occurs 3 times in the range [1, 7]. Note that two occurrences may overlap. After the update, the string becomes ababcbaba and now aba occurs only once in the range [1, 7].

import scala.collection.mutable

// https://codeforces.com/contest/914/problem/F
object F extends App {

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

  val s = readLine.toCharArray.map(_ - 'a')
  val n = s.length
  val Array(q) = readInts(1)

  val masks = Array.fill('z' - 'a' + 1) { new BitSetWithShift(n) }
  for (i <- 0 until n) masks(s(i)) += i

  Console.setOut(new java.io.BufferedOutputStream(Console.out))

  val ones = new mutable.BitSet(n)
  for (i <- 0 until n) ones += i
  val onesBits = ones.toBitMask

  for (_ <- 1 to q) {
    val cmd = readLine
    if (cmd.head == '1') {
      val Array(_, posS, cs) = cmd.split(" ")
      val pos = posS.toInt - 1
      val c = cs.head - 'a'
      masks(s(pos)) -= pos
      masks(c) += pos
      s(pos) = c
    } else {
      val Array(_, lS, rS, y) = cmd.split(" ")
      val l = lS.toInt - 1
      val r = rS.toInt - 1
      val cnt = if (r - l + 1 < y.length) 0
      else {
        val bits = new BitSetWithShift(onesBits)
        for (i <- 0 until y.length) bits &= masks(y(i) - 'a') >> i
        (bits >> l).size - (bits >> (r - y.length + 2)).size
      }
      println(cnt)
    }
  }

  Console.flush

  class BitSetWithShift(elems: Array[Long]) extends mutable.BitSet(elems.clone) {

    def this(initSize: Int) = this(new Array[Long]((initSize + 63) >> 6 max 1))

    def >>(shiftBy: Int): mutable.BitSet = {

      val bitOffset = shiftBy & 63

      val bits = if (bitOffset == 0) {
        val wordOffset = shiftBy >>> 6
        val newSize = this.nwords - wordOffset
        if (newSize > 0) {
          val newBits = Array.ofDim[Long](newSize)
          var i = 0
          while (i < newSize) {
            newBits(i) = this.word(i + wordOffset)
            i += 1
          }
          newBits
        } else Array.emptyLongArray
      } else {
        val wordOffset = (shiftBy >>> 6) + 1
        val extraBits = this.word(this.nwords - 1) >>> bitOffset
        val extraWordCount = if (extraBits == 0) 0 else 1
        val newSize = this.nwords - wordOffset + extraWordCount
        if (newSize > 0) {
          val revBitOffset = 64 - bitOffset
          val newBits = Array.ofDim[Long](newSize)
          var previous = this.word(wordOffset - 1)
          var i = wordOffset
          while (i < this.nwords) {
            val current = this.word(i)
            newBits(i - wordOffset) = (previous >>> bitOffset) | (current << revBitOffset)
            previous = current
            i += 1
          }
          if (extraWordCount != 0) newBits(newSize - 1) = extraBits
          newBits
        } else Array.emptyLongArray
      }

      mutable.BitSet.fromBitMaskNoCopy(bits)
    }
  }

}

import scala.collection.mutable

// https://codeforces.com/contest/914/problem/F
object F extends App {

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

  val s = readLine.toCharArray.map(_ - 'a')
  val n = s.length
  val Array(q) = readInts(1)

  val masks = Array.fill('z' - 'a' + 1) { new mutable.BitSet(n) with BitShifts }
  for (i <- 0 until n) masks(s(i)) += i

  Console.setOut(new java.io.BufferedOutputStream(Console.out))

  val ones = new mutable.BitSet(n)
  for (i <- 0 until n) ones += i
  val onesBits = ones.toBitMask

  for (_ <- 1 to q) {
    val cmd = readLine
    if (cmd.head == '1') {
      val Array(_, posS, cs) = cmd.split(" ")
      val pos = posS.toInt - 1
      val c = cs.head - 'a'
      masks(s(pos)) -= pos
      masks(c) += pos
      s(pos) = c
    } else {
      val Array(_, lS, rS, y) = cmd.split(" ")
      val l = lS.toInt - 1
      val r = rS.toInt - 1
      val cnt = if (r - l + 1 < y.length) 0
      else {
        val bits = new mutable.BitSet(onesBits.clone) with BitShifts
        for (i <- 0 until y.length) bits &= masks(y(i) - 'a') >> i
        (bits >> l).size - (bits >> (r - y.length + 2)).size
      }
      println(cnt)
    }
  }

  Console.flush

  trait BitShifts {
    this: mutable.BitSet =>

    private def <<(shiftBy: Int): mutable.BitSet = {

      val bitOffset = shiftBy & 63
      val wordOffset = shiftBy >>> 6

      var significantWordCount = this.nwords
      while (significantWordCount > 0 && this.word(significantWordCount - 1) == 0) {
        significantWordCount -= 1
      }

      val bits = if (bitOffset == 0) {
        val newSize = significantWordCount + wordOffset
        val newBits = Array.ofDim[Long](newSize)
        var i = wordOffset
        while (i < newSize) {
          newBits(i) = this.word(i - wordOffset)
          i += 1
        }
        newBits
      } else {
        val revBitOffset = 64 - bitOffset
        val extraBits = this.word(significantWordCount - 1) >>> revBitOffset
        val extraWordCount = if (extraBits == 0) 0 else 1
        val newSize = significantWordCount + wordOffset + extraWordCount
        val newBits = Array.ofDim[Long](newSize)
        var previous = 0L
        var i = 0
        while (i < significantWordCount) {
          val current = this.word(i)
          newBits(i + wordOffset) = (previous >>> revBitOffset) | (current << bitOffset)
          previous = current
          i += 1
        }
        if (extraWordCount != 0) newBits(newSize - 1) = extraBits
        newBits
      }

      this.fromBitMaskNoCopy(bits)
    }

    def >>(shiftBy: Int): mutable.BitSet = {

      val bitOffset = shiftBy & 63

      val bits = if (bitOffset == 0) {
        val wordOffset = shiftBy >>> 6
        val newSize = this.nwords - wordOffset
        if (newSize > 0) {
          val newBits = Array.ofDim[Long](newSize)
          var i = 0
          while (i < newSize) {
            newBits(i) = this.word(i + wordOffset)
            i += 1
          }
          newBits
        } else Array.emptyLongArray
      } else {
        val wordOffset = (shiftBy >>> 6) + 1
        val extraBits = this.word(this.nwords - 1) >>> bitOffset
        val extraWordCount = if (extraBits == 0) 0 else 1
        val newSize = this.nwords - wordOffset + extraWordCount
        if (newSize > 0) {
          val revBitOffset = 64 - bitOffset
          val newBits = Array.ofDim[Long](newSize)
          var previous = this.word(wordOffset - 1)
          var i = wordOffset
          while (i < this.nwords) {
            val current = this.word(i)
            newBits(i - wordOffset) = (previous >>> bitOffset) | (current << revBitOffset)
            previous = current
            i += 1
          }
          if (extraWordCount != 0) newBits(newSize - 1) = extraBits
          newBits
        } else Array.emptyLongArray
      }

      this.fromBitMaskNoCopy(bits)
    }
  }

}

import scala.collection.mutable

// https://codeforces.com/contest/914/problem/F
object F extends App {

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

  val s = readLine.toCharArray.map(_ - 'a')
  val n = s.length
  val Array(q) = readInts(1)

  val masks = Array.fill('z' - 'a' + 1) { new mutable.BitSet(n) with BitShifts }
  for (i <- 0 until n) masks(s(i)) += i

  Console.setOut(new java.io.BufferedOutputStream(Console.out))

  val ones = new mutable.BitSet(n)
  for (i <- 0 until n) ones += i
  val onesBits = ones.toBitMask

  for (_ <- 1 to q) {
    val cmd = readLine
    if (cmd.head == '1') {
      val Array(_, posS, cs) = cmd.split(" ")
      val pos = posS.toInt - 1
      val c = cs.head - 'a'
      masks(s(pos)) -= pos
      masks(c) += pos
      s(pos) = c
    } else {
      val Array(_, lS, rS, y) = cmd.split(" ")
      val l = lS.toInt - 1
      val r = rS.toInt - 1
      val cnt = if (r - l + 1 < y.length) 0
      else {
        val bits = new mutable.BitSet(onesBits.clone) with BitShifts
        for (i <- 0 until y.length) bits &= masks(y(i) - 'a') >> i
        (bits >> l).size - (bits >> (r - y.length + 2)).size
      }
      println(cnt)
    }
  }

  Console.flush

  trait BitShifts {
    this: mutable.BitSet =>

    val LogWL = 6
    val WordLength = 1 << LogWL
    val WordMask = WordLength - 1
    val MaxSize = (Int.MaxValue >> LogWL) + 1

    def <<(shiftBy: Int): mutable.BitSet = {

      val shiftedBits = if (this.nwords == 0 || this.nwords == 1 && this.word(0) == 0) Array.emptyLongArray
      else if (shiftBy > 0) shiftLeft(shiftBy)
      else if (shiftBy == 0) this.elems.clone()
      else shiftRight(-shiftBy)

      new mutable.BitSet(shiftedBits) with BitShifts
    }

    def >>(shiftBy: Int): mutable.BitSet = {

      val shiftedBits = if (this.nwords == 0 || this.nwords == 1 && this.word(0) == 0) Array.emptyLongArray
      else if (shiftBy > 0) shiftRight(shiftBy)
      else if (shiftBy == 0) this.elems.clone()
      else shiftLeft(-shiftBy)

      new mutable.BitSet(shiftedBits) with BitShifts
    }

    def <<=(shiftBy: Int): mutable.BitSet = {

      if (this.nwords == 0 || this.nwords == 1 && this.word(0) == 0) ()
      else if (shiftBy > 0) shiftLeftInPlace(shiftBy)
      else if (shiftBy < 0) shiftRightInPlace(-shiftBy)

      this
    }

    def >>=(shiftBy: Int): mutable.BitSet = {

      if (this.nwords == 0 || this.nwords == 1 && this.word(0) == 0) ()
      else if (shiftBy > 0) shiftRightInPlace(shiftBy)
      else if (shiftBy < 0) shiftLeftInPlace(-shiftBy)

      this
    }

    private def shiftLeft(shiftBy: Int): Array[Long] = {

      val bitOffset = shiftBy & WordMask
      val wordOffset = shiftBy >>> LogWL

      var significantWordCount = this.nwords
      while (significantWordCount > 0 && this.word(significantWordCount - 1) == 0) {
        significantWordCount -= 1
      }

      if (bitOffset == 0) {
        val newSize = significantWordCount + wordOffset
        require(newSize <= MaxSize)
        val newBits = Array.ofDim[Long](newSize)
        var i = wordOffset
        while (i < newSize) {
          newBits(i) = this.word(i - wordOffset)
          i += 1
        }
        newBits
      } else {
        val revBitOffset = WordLength - bitOffset
        val extraBits = this.word(significantWordCount - 1) >>> revBitOffset
        val extraWordCount = if (extraBits == 0) 0 else 1
        val newSize = significantWordCount + wordOffset + extraWordCount
        require(newSize <= MaxSize)
        val newBits = Array.ofDim[Long](newSize)
        var previous = 0L
        var i = 0
        while (i < significantWordCount) {
          val current = this.word(i)
          newBits(i + wordOffset) = (previous >>> revBitOffset) | (current << bitOffset)
          previous = current
          i += 1
        }
        if (extraWordCount != 0) newBits(newSize - 1) = extraBits
        newBits
      }
    }

    private def shiftRight(shiftBy: Int): Array[Long] = {

      val bitOffset = shiftBy & WordMask

      if (bitOffset == 0) {
        val wordOffset = shiftBy >>> LogWL
        val newSize = this.nwords - wordOffset
        if (newSize > 0) {
          val newBits = Array.ofDim[Long](newSize)
          var i = 0
          while (i < newSize) {
            newBits(i) = this.word(i + wordOffset)
            i += 1
          }
          newBits
        } else Array.emptyLongArray
      } else {
        val wordOffset = (shiftBy >>> LogWL) + 1
        val extraBits = this.word(this.nwords - 1) >>> bitOffset
        val extraWordCount = if (extraBits == 0) 0 else 1
        val newSize = this.nwords - wordOffset + extraWordCount
        if (newSize > 0) {
          val revBitOffset = WordLength - bitOffset
          val newBits = Array.ofDim[Long](newSize)
          var previous = this.word(wordOffset - 1)
          var i = wordOffset
          while (i < this.nwords) {
            val current = this.word(i)
            newBits(i - wordOffset) = (previous >>> bitOffset) | (current << revBitOffset)
            previous = current
            i += 1
          }
          if (extraWordCount != 0) newBits(newSize - 1) = extraBits
          newBits
        } else Array.emptyLongArray
      }
    }

    private def shiftLeftInPlace(shiftBy: Int): Unit = {

      val bitOffset = shiftBy & WordMask
      val wordOffset = shiftBy >>> LogWL

      var significantWordCount = this.nwords
      while (significantWordCount > 0 && this.word(significantWordCount - 1) == 0) {
        significantWordCount -= 1
      }

      if (bitOffset == 0) {
        val newSize = significantWordCount + wordOffset
        require(newSize <= MaxSize)
        ensureCap(newSize)
        System.arraycopy(this.elems, 0, this.elems, wordOffset, significantWordCount)
      } else {
        val revBitOffset = WordLength - bitOffset
        val extraBits = this.elems(significantWordCount - 1) >>> revBitOffset
        val extraWordCount = if (extraBits == 0) 0 else 1
        val newSize = significantWordCount + wordOffset + extraWordCount
        require(newSize <= MaxSize)
        ensureCap(newSize)
        var i = significantWordCount - 1
        var previous = this.elems(i)
        while (i > 0) {
          val current = this.elems(i - 1)
          this.elems(i + wordOffset) = (current >>> revBitOffset) | (previous << bitOffset)
          previous = current
          i -= 1
        }
        this.elems(wordOffset) = previous << bitOffset
        if (extraWordCount != 0) this.elems(newSize - 1) = extraBits
      }
      java.util.Arrays.fill(this.elems, 0, wordOffset, 0)
    }

    private def shiftRightInPlace(shiftBy: Int): Unit = {

      val bitOffset = shiftBy & WordMask

      if (bitOffset == 0) {
        val wordOffset = shiftBy >>> LogWL
        val newSize = this.nwords - wordOffset
        if (newSize > 0) {
          System.arraycopy(this.elems, wordOffset, this.elems, 0, newSize)
          java.util.Arrays.fill(this.elems, newSize, this.nwords, 0)
        } else this.clear()
      } else {
        val wordOffset = (shiftBy >>> LogWL) + 1
        val extraBits = this.elems(this.nwords - 1) >>> bitOffset
        val extraWordCount = if (extraBits == 0) 0 else 1
        val newSize = this.nwords - wordOffset + extraWordCount
        if (newSize > 0) {
          val revBitOffset = WordLength - bitOffset
          var previous = this.elems(wordOffset - 1)
          var i = wordOffset
          while (i < this.nwords) {
            val current = this.elems(i)
            this.elems(i - wordOffset) = (previous >>> bitOffset) | (current << revBitOffset)
            previous = current
            i += 1
          }
          if (extraWordCount != 0) this.elems(newSize - 1) = extraBits
          java.util.Arrays.fill(this.elems, newSize, this.nwords, 0)
        } else this.clear()
      }
    }

    protected final def ensureCap(idx: Int): Unit = {
      // Copied from mutable.BitSet.ensureCapacity (which is inaccessible from here).
      require(idx < MaxSize)
      if (idx >= this.nwords) {
        var newlen = this.nwords
        while (idx >= newlen) newlen = math.min(newlen * 2, MaxSize)
        val elems1 = new Array[Long](newlen)
        Array.copy(this.elems, 0, elems1, 0, this.nwords)
        this.elems = elems1
      }
    }

  }

}

import scala.collection.mutable

// https://codeforces.com/contest/914/problem/F
object F extends App {

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

  val s = readLine.toCharArray.map(_ - 'a')
  val n = s.length
  val Array(q) = readInts(1)

  val masks = Array.fill('z' - 'a' + 1) { new BitSetWithShift(n) }
  for (i <- 0 until n) masks(s(i)) += i

  Console.setOut(new java.io.BufferedOutputStream(Console.out))

  val ones = new mutable.BitSet(n)
  for (i <- 0 until n) ones += i
  val onesBits = ones.toBitMask

  for (_ <- 1 to q) {
    val cmd = readLine
    if (cmd.head == '1') {
      val Array(_, posS, cs) = cmd.split(" ")
      val pos = posS.toInt - 1
      val c = cs.head - 'a'
      masks(s(pos)) -= pos
      masks(c) += pos
      s(pos) = c
    } else {
      val Array(_, lS, rS, y) = cmd.split(" ")
      val l = lS.toInt - 1
      val r = rS.toInt - 1
      val ans = new BitSetWithShift(onesBits)
      for (i <- 0 until y.length) ans &= masks(y(i) - 'a') >> i
      val cnt = (ans >> (l)).size - (ans >> (r - y.length + 2)).size
      println(cnt)
    }
  }

  Console.flush

  class BitSetWithShift(elems: Array[Long]) extends mutable.BitSet(elems.clone) {

    def this(initSize: Int) = this(new Array[Long]((initSize + 63) >> 6 max 1))

    def >>(shiftBy: Int): mutable.BitSet = {

      val bitOffset = shiftBy & 63

      val bits = if (bitOffset == 0) {
        val wordOffset = shiftBy >>> 6
        val newSize = this.nwords - wordOffset
        if (newSize > 0) {
          val newBits = Array.ofDim[Long](newSize)
          var i = 0
          while (i < newSize) {
            newBits(i) = this.word(i + wordOffset)
            i += 1
          }
          newBits
        } else Array.emptyLongArray
      } else {
        val wordOffset = (shiftBy >>> 6) + 1
        val extraBits = this.word(this.nwords - 1) >>> bitOffset
        val extraWordCount = if (extraBits == 0) 0 else 1
        val newSize = this.nwords - wordOffset + extraWordCount
        if (newSize > 0) {
          val revBitOffset = 64 - bitOffset
          val newBits = Array.ofDim[Long](newSize)
          var previous = this.word(wordOffset - 1)
          var i = wordOffset
          while (i < this.nwords) {
            val current = this.word(i)
            newBits(i - wordOffset) = (previous >>> bitOffset) | (current << revBitOffset)
            previous = current
            i += 1
          }
          if (extraWordCount != 0) newBits(newSize - 1) = extraBits
          newBits
        } else Array.emptyLongArray
      }

      mutable.BitSet.fromBitMaskNoCopy(bits)
    }
  }

}


You are standing at the point $$$0$$$ on a coordinate line. Your goal is to reach the point $$$n$$$. In one minute, you can move by $$$2$$$ or by $$$3$$$ to the left or to the right (i. e., if your current coordinate is $$$x$$$, it can become $$$x-3$$$, $$$x-2$$$, $$$x+2$$$ or $$$x+3$$$). Note that the new coordinate can become negative.Your task is to find the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ lines describing the test cases follow. The $$$i$$$-th of these lines contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the goal of the $$$i$$$-th test case.

For each test case, print one integer — the minimum number of minutes required to get from the point $$$0$$$ to the point $$$n$$$ for the corresponding test case.

//scala ACM模式读入读出
import scala.io.StdIn
import scala.math._

object Problem_1716A {
  def main(args: Array[String]): Unit = {
	var t=StdIn.readInt;
	while(t>0){
		t=t-1;
		var n=StdIn.readInt;
		if(n%3==0) println(n/3);
	    if(n%3==1) println(n/3+2- {if(n!=1) 1; else 0;});
	    if(n%3==2) println(n/3+1);

	}
  }
}

import scala.io.StdIn._

object Solution {
  def main(args: Array[String]): Unit = {
    for (t <- 1 to readInt()) {
      val n = readInt()
      val ans = if (n == 1) {
        2
      } else if (n == 2) {
        1
      } else {
        (n + 2) / 3
      }
      println(ans)
    }
  }
}

object A extends App {
  import java.io.{BufferedReader, InputStreamReader, StreamTokenizer}

  solve()

  @inline def operations(n: Int): Int = {
    if (n == 1){
      2
    } else
    if (n == 2) {
      1
    } else {
      val s = n / 3
      n % 3 match {
        case 0 => s
        case _ => s + 1
      }
    }
  }

  def solve(): Unit = {
    val in = new StreamTokenizer(new BufferedReader(new InputStreamReader((System.in))))

    @inline def nextInt = {
      in.nextToken()
      in.nval.asInstanceOf[Int]
    }

    val t = nextInt
    for (_ <- 1 to t) {
      val n = nextInt
      println(operations(n))
    }
  }

}

//scala ACM模式读入读出
import scala.io.StdIn
import scala.math._

object Problem_1716A {
  def main(args: Array[String]): Unit = {
	var t=StdIn.readInt;
	while(t>0){
		t=t-1;
		var n=StdIn.readInt;
		if(n%3==0) println(n/3);
	    if(n%3==1) println(n/3-2- {if(n!=1) 1; else 0;});
	    if(n%3==2) println(n/3+1);

	}
  }
}

//scala ACM模式读入读出
import scala.io.StdIn
import scala.math._

object Problem_1716A {
  def main(args: Array[String]): Unit = {
	var t=StdIn.readInt;
	while(t>0){
		t=t-1;
		var n=StdIn.readInt;
		if(n%3==0) println(n/3);
	    if(n%3==1) println(n/3-n- {if(n!=1) 1; else 0;});
	    if(n%3==2) println(n/3+1);

	}
  }
}


There are $$$n$$$ students numerated from $$$1$$$ to $$$n$$$. The level of the $$$i$$$-th student is $$$a_i$$$. You need to split the students into stable groups. A group of students is called stable, if in the sorted array of their levels no two neighboring elements differ by more than $$$x$$$.For example, if $$$x = 4$$$, then the group with levels $$$[1, 10, 8, 4, 4]$$$ is stable (because $$$4 - 1 \le x$$$, $$$4 - 4 \le x$$$, $$$8 - 4 \le x$$$, $$$10 - 8 \le x$$$), while the group with levels $$$[2, 10, 10, 7]$$$ is not stable ($$$7 - 2 = 5 > x$$$).Apart from the $$$n$$$ given students, teachers can invite at most $$$k$$$ additional students with arbitrary levels (at teachers' choice). Find the minimum number of stable groups teachers can form from all students (including the newly invited).For example, if there are two students with levels $$$1$$$ and $$$5$$$; $$$x = 2$$$; and $$$k \ge 1$$$, then you can invite a new student with level $$$3$$$ and put all the students in one stable group.

The first line contains three integers $$$n$$$, $$$k$$$, $$$x$$$ ($$$1 \le n \le 200\,000$$$, $$$0 \le k \le 10^{18}$$$, $$$1 \le x \le 10^{18}$$$) — the initial number of students, the number of students you can additionally invite, and the maximum allowed level difference. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{18}$$$) — the students levels.

In the only line print a single integer: the minimum number of stable groups you can split the students into.

NoteIn the first example you can invite two students with levels $$$2$$$ and $$$11$$$. Then you can split the students into two stable groups:   $$$[1, 1, 2, 5, 8, 11, 12, 13]$$$,  $$$[20, 22]$$$. In the second example you are not allowed to invite new students, so you need $$$3$$$ groups:   $$$[1, 1, 5, 5, 20, 20]$$$  $$$[60, 70, 70, 70, 80, 90]$$$  $$$[420]$$$

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

  val Array(_, k, x) = readLine().split(" ").map(_.toLong)
  val an             = readLine().split(" ").map(_.toLong).sorted
  val n              = an.length

  val indices = for {
    i <- 0 until (n - 1) if an(i + 1) > x + an(i)
  } yield i
  val weights = indices.map(i => (an(i + 1) - an(i) + x - 1) / x - 1).sorted

  @annotation.tailrec
  def go(k: Long, weights: Seq[Long]): Long =
    weights match {
      case weight +: weights if k - weight >= 0 => go(k - weight, weights)
      case _                                    => weights.length + 1
    }

  val ans = go(k, weights)

  println(ans)
}


XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $$$n$$$ booths, arranged in a circle. The booths are numbered $$$1$$$ through $$$n$$$ clockwise with $$$n$$$ being adjacent to $$$1$$$. The $$$i$$$-th booths sells some candies for the price of $$$a_i$$$ burles per item. Each booth has an unlimited supply of candies.Polycarp has decided to spend at most $$$T$$$ burles at the fair. However, he has some plan in mind for his path across the booths:  at first, he visits booth number $$$1$$$;  if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately;  then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not). Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.Calculate the number of candies Polycarp will buy.

The first line contains two integers $$$n$$$ and $$$T$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le T \le 10^{18}$$$) — the number of booths at the fair and the initial amount of burles Polycarp has. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the price of the single candy at booth number $$$i$$$.

Print a single integer — the total number of candies Polycarp will buy.

NoteLet's consider the first example. Here are Polycarp's moves until he runs out of money:  Booth $$$1$$$, buys candy for $$$5$$$, $$$T = 33$$$;  Booth $$$2$$$, buys candy for $$$2$$$, $$$T = 31$$$;  Booth $$$3$$$, buys candy for $$$5$$$, $$$T = 26$$$;  Booth $$$1$$$, buys candy for $$$5$$$, $$$T = 21$$$;  Booth $$$2$$$, buys candy for $$$2$$$, $$$T = 19$$$;  Booth $$$3$$$, buys candy for $$$5$$$, $$$T = 14$$$;  Booth $$$1$$$, buys candy for $$$5$$$, $$$T = 9$$$;  Booth $$$2$$$, buys candy for $$$2$$$, $$$T = 7$$$;  Booth $$$3$$$, buys candy for $$$5$$$, $$$T = 2$$$;  Booth $$$1$$$, buys no candy, not enough money;  Booth $$$2$$$, buys candy for $$$2$$$, $$$T = 0$$$. No candy can be bought later. The total number of candies bought is $$$10$$$.In the second example he has $$$1$$$ burle left at the end of his path, no candy can be bought with this amount.

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()
    var T = nl()
    val A = na(N)
    val flag = Array.ofDim[Boolean](N)

    var S = sumL(A)
    var c = N
    var ans = 0L
    while(c > 0) {
      val x = T / S
      ans += x * c
      T -= x * S

      rep(N) { i =>
        if (!flag(i) && A(i) <= T) {
          T -= A(i)
          ans += 1
        } else if (!flag(i)){
          flag(i) = true
          c -= 1
          S -= A(i)
        }
      }
    }

    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): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(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)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

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


It's a walking tour day in SIS.Winter, so $$$t$$$ groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.Initially, some students are angry. Let's describe a group of students by a string of capital letters "A" and "P":   "A" corresponds to an angry student  "P" corresponds to a patient student Such string describes the row from the last to the first student.Every minute every angry student throws a snowball at the next student. Formally, if an angry student corresponds to the character with index $$$i$$$ in the string describing a group then they will throw a snowball at the student that corresponds to the character with index $$$i+1$$$ (students are given from the last to the first student). If the target student was not angry yet, they become angry. Even if the first (the rightmost in the string) student is angry, they don't throw a snowball since there is no one in front of them.Let's look at the first example test. The row initially looks like this: PPAP. Then, after a minute the only single angry student will throw a snowball at the student in front of them, and they also become angry: PPAA. After that, no more students will become angry.Your task is to help SIS.Winter teachers to determine the last moment a student becomes angry for every group.

The first line contains a single integer $$$t$$$ — the number of groups of students ($$$1 \le t \le 100$$$). The following $$$2t$$$ lines contain descriptions of groups of students. The description of the group starts with an integer $$$k_i$$$ ($$$1 \le k_i \le 100$$$) — the number of students in the group, followed by a string $$$s_i$$$, consisting of $$$k_i$$$ letters "A" and "P", which describes the $$$i$$$-th group of students.

For every group output single integer — the last moment a student becomes angry.

NoteIn the first test, after $$$1$$$ minute the state of students becomes PPAA. After that, no new angry students will appear.In the second tets, state of students in the first group is:   after $$$1$$$ minute — AAPAAPPAAPPP  after $$$2$$$ minutes — AAAAAAPAAAPP  after $$$3$$$ minutes — AAAAAAAAAAAP  after $$$4$$$ minutes all $$$12$$$ students are angry In the second group after $$$1$$$ minute, all students are angry.

import scala.io.StdIn

object AngryStudents extends App {

  val tests = StdIn.readLine().toInt

  for (i <- 1 to tests) {
    val k = StdIn.readLine().toInt
    val s = StdIn.readLine().toCharArray

    if (i == tests) {
      print(impl(s, k))
    } else {
      println(impl(s, k))
    }
  }

  def impl(students: Array[Char], len: Int): Int = {
    var time = 0
    var canChange = true
    var changedThisMinute = false

    while (canChange) {
      changedThisMinute = false
      for (i <- len - 1 to 1 by -1) {
        if ((i - 1) >= 0 && students(i - 1) == 'A' && students(i) == 'P') {
          students(i) = 'A'
          changedThisMinute = true
        }
      }
      if (!changedThisMinute) {
        canChange = false
      }

      if (canChange) {
        time += 1
      }
    }

    time
  }
}


You are given $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$. Find the maximum value of $$$max(a_l, a_{l + 1}, \ldots, a_r) \cdot min(a_l, a_{l + 1}, \ldots, a_r)$$$ over all pairs $$$(l, r)$$$ of integers for which $$$1 \le l < r \le n$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.

For each test case, print a single integer  — the maximum possible value of the product from the statement.

import scala.io.StdIn._;

object Main extends App {

  def a(ignored: Int, z: Array[Long]): Long = z.zip(z.slice(1, z.length)).map(l => l._1 * l._2).max

  for (_ <- 0 until readInt()) println(a(readInt(), readLine().split(" ").map(_.toLong)))
}

import java.io.PrintWriter

import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import util.control.Breaks._

object Solution {
    val reader = scala.io.StdIn
    def readInt(): Int = reader.readLine().toInt
    def readArrayInt(): Array[Int] = reader.readLine().split(" ").map(_.toInt)
    def readArrayLong(): Array[Long] = reader.readLine().split(" ").map(_.toLong)
    def readString(): String = reader.readLine()

    def multiTest(f: Int => Unit): Unit = {
        val t = readInt()
        for (i <- 1 to t) f(i)
    }

    def GCD(a: Int, b: Int): Int = {
        if (a == 0) return b
        GCD(b % a, a)
    }

    def solve(t: Int = 0): Unit = {
        var t = readInt()
        while (t > 0) {
            val n =readInt()
            val a = readArrayInt()
            var max = 0L
            for (i <- 0 until n - 1) {
                if (a(i).toLong * a(i+1) > max) {
                    max = a(i).toLong * a(i+1)
                }
            }
            println(max)
            t -= 1
        }

    }

    def main(args: Array[String]) {
        //multiTest(solve)
        solve()
    }
}

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val an = readLine().split(" ").map(_.toLong)

    val (l, r) = (an zip an.tail).maxBy { case (l, r) => l * r }

    val ans = l * r

    println(ans)
  }
}

import scala.io.StdIn._;

object Main extends App {

  def a(ignored: Int, z: Array[Int]): Int = z.zip(z.slice(1, z.length)).map(l => l._1 * l._2).max

  for (_ <- 0 until readInt()) print(a(readInt(), readLine().split(" ").map(_.toInt)))
}