You are given four integers $$$a$$$, $$$b$$$, $$$x$$$ and $$$y$$$. Initially, $$$a \ge x$$$ and $$$b \ge y$$$. You can do the following operation no more than $$$n$$$ times:  Choose either $$$a$$$ or $$$b$$$ and decrease it by one. However, as a result of this operation, value of $$$a$$$ cannot become less than $$$x$$$, and value of $$$b$$$ cannot become less than $$$y$$$. Your task is to find the minimum possible product of $$$a$$$ and $$$b$$$ ($$$a \cdot b$$$) you can achieve by applying the given operation no more than $$$n$$$ times.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains five integers $$$a$$$, $$$b$$$, $$$x$$$, $$$y$$$ and $$$n$$$ ($$$1 \le a, b, x, y, n \le 10^9$$$). Additional constraint on the input: $$$a \ge x$$$ and $$$b \ge y$$$ always holds.

For each test case, print one integer: the minimum possible product of $$$a$$$ and $$$b$$$ ($$$a \cdot b$$$) you can achieve by applying the given operation no more than $$$n$$$ times.

NoteIn the first test case of the example, you need to decrease $$$b$$$ three times and obtain $$$10 \cdot 7 = 70$$$.In the second test case of the example, you need to decrease $$$a$$$ one time, $$$b$$$ one time and obtain $$$11 \cdot 7 = 77$$$.In the sixth test case of the example, you need to decrease $$$a$$$ five times and obtain $$$5 \cdot 11 = 55$$$.In the seventh test case of the example, you need to decrease $$$b$$$ ten times and obtain $$$10 \cdot 1 = 10$$$.

object CodeforcesRound667b {

  import java.io.{BufferedReader, PrintStream}

  import scala.io.Source

  def main(args: Array[String]): Unit = {
    exec(Source.stdin.bufferedReader, System.out)
  }

  def exec(implicit
           reader: BufferedReader,
           writer: PrintStream): Unit = {
    val t: Int = rl_int
    (1 to t).foreach(_ => test())
  }

  def test()
          (implicit
           reader: BufferedReader,
           writer: PrintStream): Unit = {
    var Array(a, b, x, y, n) = rll_long
    val res =
      Math.min(
        cmp(a, b, x, y, n),
        cmp(b, a, y, x, n),
      )
    writer.println(res)
  }

  def cmp(a_ : Long, b_ : Long, x_ : Long, y_ : Long, n_ : Long): Long = {
    var a = a_
    var b = b_
    var x = x_
    var y = y_
    var n = n_
    val diff1 = Math.min(a - x, n)
    a -= diff1
    n -= diff1
    val diff2 = Math.min(b - y, n)
    b -= diff2
    n -= diff2
    a * b
  }

  def sqr(a: Long): Long = a * a

  def rl(implicit reader: BufferedReader): String = reader.readLine
  def rll(implicit reader: BufferedReader): Array[String] = reader.readLine.split(' ')

  def rl_bool(implicit reader: BufferedReader): Boolean = rl.toBoolean
  def rl_byte(implicit reader: BufferedReader): Byte = rl.toByte
  def rl_short(implicit reader: BufferedReader): Short = rl.toShort
  def rl_int(implicit reader: BufferedReader): Int = rl.toInt
  def rl_long(implicit reader: BufferedReader): Long = rl.toLong
  def rl_float(implicit reader: BufferedReader): Float = rl.toFloat
  def rl_double(implicit reader: BufferedReader): Double = rl.toDouble

  def rll_bool(implicit reader: BufferedReader): Array[Boolean] = rll.map(_.toBoolean)
  def rll_byte(implicit reader: BufferedReader): Array[Byte] = rll.map(_.toByte)
  def rll_short(implicit reader: BufferedReader): Array[Short] = rll.map(_.toShort)
  def rll_int(implicit reader: BufferedReader): Array[Int] = rll.map(_.toInt)
  def rll_long(implicit reader: BufferedReader): Array[Long] = rll.map(_.toLong)
  def rll_float(implicit reader: BufferedReader): Array[Float] = rll.map(_.toFloat)
  def rll_double(implicit reader: BufferedReader): Array[Double] = rll.map(_.toDouble)

}

//package codeforces.contests._1409

object MinimumProduct {
  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {

      val Array(a, b, x, y, n) = io.StdIn.readLine.split(" ").map(_.toInt)

      val (f, s) = {
        val aD = (a - n) max x
        val bD = (b - n) max y

        if (aD <= bD) (aD, (b - (n - (a - aD))) max y)
        else ((a - (n - (b - bD))) max x, bD)
      }

      println(f.toLong * s.toLong)
    }
  }
}

/**
 * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
 */
import scala.io.StdIn._

object Main {
  def main(args: Array[String]): Unit = {
    // Write your solution here
    /*
    int t;
      cin >> t;
      while (t--) {
        int a, b, x, y, n;
        cin >> a >> b >> x >> y >> n;
        long long ans = 1e18;
        for (int i = 0; i < 2; ++i) {
          int da = min(n, a - x);
          int db = min(n - da, b - y);
          ans = min(ans, (a - da) * 1ll * (b - db));
          swap(a, b);
          swap(x, y);
        }
        cout << ans << endl;
      }

      return 0;
     */

    def swap(x: Long, y: Long) = {

    }
    val t = readInt

    for (_ <- 0 until t) {
      val splitLine = readLine.split(" ").map(_.toLong)
      var a = splitLine(0)
      var b = splitLine(1)
      var x = splitLine(2)
      var y = splitLine(3)
      val n = splitLine(4)

      var ans = 1000000000000000000L

      for (_ <- 0 until 2) {
        val da = math.min(n, a - x)
        val db = math.min(n - da, b- y)
        ans = math.min(ans, (a - da) * (b - db))

        val tmpab = b
        b = a
        a = tmpab

        val tmpxy = y
        y = x
        x = tmpxy
      }

      println(ans)
    }
  }
}

/**
 * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
 */
import scala.io.StdIn._

object Main {
  def main(args: Array[String]): Unit = {
    // Write your solution here
    val t = readInt

    for (_ <- 0 until t) {
      val splitLine = readLine.split(" ").map(_.toLong)
      var a = splitLine(0)
      var b = splitLine(1)
      var x = splitLine(2)
      var y = splitLine(3)
      val n = splitLine(4)

      var ans = 1000000000000000000L

      for (_ <- 0 until 2) {
        val da = math.min(n, a - x)
        val db = math.min(n - da, b- y)
        ans = math.min(ans, (a - da) * (b - db))

        val tmpab = b
        b = a
        a = tmpab

        val tmpxy = y
        y = x
        x = tmpxy
      }

      println(ans)
    }
  }
}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val t = StdIn.readLine.toInt
    for (_ <- 0 until t) {
      val arr = StdIn.readLine.split(" ").map(_.toLong)
      val (a,b,x,y,n) = (arr(0), arr(1), arr(2), arr(3), arr(4))

      def cal(a: Long, b: Long, x: Long, y: Long, n: Long) = {
        val sub = math.min(a - x, n)
        val sub2 = math.min(b-y, n - sub)
        (a-sub) * (b-sub2)
      }

      println(cal(a,b,x,y,n) min cal(b,a,y,x,n))
    }
  }
}

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

  val t = readInt()

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

    val ans = {
      val c = (a - n) max x
      val d = (b - n + a - c) max y
      c * d
    } min {
      val c = (b - n) max y
      val d = (a - n + b - c) max x
      c * d
    }

    println(ans)
  }
}

import scala.collection.mutable.ArrayBuffer

object B extends App {
  import java.io._
  import java.nio.file.{Files, Path}
  import java.util.StringTokenizer
  import scala.io.Source
  import scala.io.Codec

  /* Implicit methods */
  implicit def intWithTimes(n: Int) = {
    new {
      def times(f: => Unit): Unit = 1.to(n).foreach { _ => f }
    }
  }
  /* Implicit methods */

  //  val in = new CustomScanner(Source.fromResource("input.txt").mkString)
  val in  = new CustomScanner(System.in)
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val inputLines = in.nextInt()

    1.to(inputLines)
      .foreach(i => {
        val a = in.nextInt()
        val b = in.nextInt()
        val x = in.nextInt()
        val y = in.nextInt()
        val n = in.nextInt()

        val r1     = findR(a, b, x, y, n)
        val r2     = findR(b, a, y, x, n)
        val result = math.min(r1, r2)
        println(result)

      })
  }

  def findR(a: Int, b: Int, x: Int, y: Int, n: Int) = {
    val (a1, r) = if (a - x <= n) (a - (a - x), n - (a - x)) else (a - n, 0)
    val b1      = if (b - y <= r) b - (b - y) else b - r
    a1.toLong * b1.toLong
  }

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

  /**
    * Util methods
    */

  def printArr[T](in: Array[T]) = {
    in.foreach(print)
    println()
  }

  /**
    * Scala implementation of a faster java.util.Scanner
    * See: http://codeforces.com/blog/entry/7018
    */
  class CustomScanner(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))

    private[this] val tokenizers = {
      Iterator
        .continually(reader.readLine())
        .takeWhile(_ != null)
        .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
      reader.readLine()
    }

    def lineNumber: Int = reader.getLineNumber

    def line(): String = tokenizer().get.nextToken("\n\r")

    def nextLineInt(n: Int): ArrayBuffer[Int] = {
      var data = ArrayBuffer[Int]()
      n.times({
        data += nextInt()
      })
      data
    }

    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(): String = tokenizer().get.nextToken()

    override def hasNext: Boolean = tokenizer().nonEmpty

    override def close(): Unit = reader.close()
  }
}

//package codeforces.contests._1409

object MinimumProduct {
  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {

      val Array(a, b, x, y, n) = io.StdIn.readLine.split(" ").map(_.toInt)

      val (f, s) = {
        if (n == 0) (a, b)
        else if (n == 1) ((a max b) - 1, a min b)
        else if (a == x) (a, (b - n) max y)
        else if (b == y) ((a - n) max x, b)
        else {
          val aD = (a - n) max x
          val bD = (b - n) max y

          if (aD <= bD) (aD, (b - (n - (a - aD))) max y)
          else ((a - (n - (b - bD))) max x, bD)
        }
      }

      println(f.toLong * s.toLong)
    }
  }
}

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

  val t = readInt()

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

    val ans =
      if (a < b) {
        val c = (a - n) max x
        val d = (b - n + a - c) max y
        c * d
      } else {
        val c = (b - n) max y
        val d = (a - n + b - c) max x
        c * d
      }

    println(ans)
  }
}

import scala.collection.mutable.ArrayBuffer

object B extends App {
  import java.io._
  import java.nio.file.{Files, Path}
  import java.util.StringTokenizer
  import scala.io.Source
  import scala.io.Codec

  /* Implicit methods */
  implicit def intWithTimes(n: Int) = {
    new {
      def times(f: => Unit): Unit = 1.to(n).foreach { _ => f }
    }
  }
  /* Implicit methods */

  //  val in = new CustomScanner(Source.fromResource("input.txt").mkString)
  val in  = new CustomScanner(System.in)
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val inputLines = in.nextInt()

    inputLines.times {
      val a = in.nextInt()
      val b = in.nextInt()
      val x = in.nextInt()
      val y = in.nextInt()
      val n = in.nextInt()

      val r1 = findR(a, b, x, y, n)
      val r2 = findR(b, a, y, x, n)
      printf("%.0f\n", math.min(r1, r2))
    }
  }

  def findR(a: Int, b: Int, x: Int, y: Int, n: Int) = {
    val (a1, r) = if (a - x <= n) (a - (a - x), n - (a - x)) else (a - n, 0)
    val b1      = if (b - y <= r) b - (b - y) else b - r
    a1.toDouble * b1.toDouble
  }

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

  /**
    * Util methods
    */

  def printArr[T](in: Array[T]) = {
    in.foreach(print)
    println()
  }

  /**
    * Scala implementation of a faster java.util.Scanner
    * See: http://codeforces.com/blog/entry/7018
    */
  class CustomScanner(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))

    private[this] val tokenizers = {
      Iterator
        .continually(reader.readLine())
        .takeWhile(_ != null)
        .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
      reader.readLine()
    }

    def lineNumber: Int = reader.getLineNumber

    def line(): String = tokenizer().get.nextToken("\n\r")

    def nextLineInt(n: Int): ArrayBuffer[Int] = {
      var data = ArrayBuffer[Int]()
      n.times({
        data += nextInt()
      })
      data
    }

    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(): String = tokenizer().get.nextToken()

    override def hasNext: Boolean = tokenizer().nonEmpty

    override def close(): Unit = reader.close()
  }
}

import scala.collection.mutable.ArrayBuffer

object B extends App {
  import java.io._
  import java.nio.file.{Files, Path}
  import java.util.StringTokenizer
  import scala.io.Source
  import scala.io.Codec

  /* Implicit methods */
  implicit def intWithTimes(n: Int) = {
    new {
      def times(f: => Unit): Unit = 1.to(n).foreach { _ => f }
    }
  }
  /* Implicit methods */

  //  val in = new CustomScanner(Source.fromResource("input.txt").mkString)
  val in  = new CustomScanner(System.in)
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val inputLines = in.nextInt()

    1.to(inputLines)
      .foreach(i => {
        val a = in.nextInt()
        val b = in.nextInt()
        val x = in.nextInt()
        val y = in.nextInt()
        val n = in.nextInt()

        if (i == 4918) {
          println(a, b, x, y, n)
          val r1 = findR(a, b, x, y, n)
          val r2 = findR(b, a, y, x, n)
          printf("%.0f\n", math.min(r1, r2))
        }

      })
  }

  def findR(a: Int, b: Int, x: Int, y: Int, n: Int) = {
    val (a1, r) = if (a - x <= n) (a - (a - x), n - (a - x)) else (a - n, 0)
    val b1      = if (b - y <= r) b - (b - y) else b - r
    a1.toDouble * b1.toDouble
  }

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

  /**
    * Util methods
    */

  def printArr[T](in: Array[T]) = {
    in.foreach(print)
    println()
  }

  /**
    * Scala implementation of a faster java.util.Scanner
    * See: http://codeforces.com/blog/entry/7018
    */
  class CustomScanner(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))

    private[this] val tokenizers = {
      Iterator
        .continually(reader.readLine())
        .takeWhile(_ != null)
        .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
      reader.readLine()
    }

    def lineNumber: Int = reader.getLineNumber

    def line(): String = tokenizer().get.nextToken("\n\r")

    def nextLineInt(n: Int): ArrayBuffer[Int] = {
      var data = ArrayBuffer[Int]()
      n.times({
        data += nextInt()
      })
      data
    }

    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(): String = tokenizer().get.nextToken()

    override def hasNext: Boolean = tokenizer().nonEmpty

    override def close(): Unit = reader.close()
  }
}

import scala.collection.mutable.ArrayBuffer

object B extends App {
  import java.io._
  import java.nio.file.{Files, Path}
  import java.util.StringTokenizer
  import scala.io.Source
  import scala.io.Codec

  /* Implicit methods */
  implicit def intWithTimes(n: Int) = {
    new {
      def times(f: => Unit): Unit = 1.to(n).foreach { _ => f }
    }
  }
  /* Implicit methods */

  //  val in = new CustomScanner(Source.fromResource("input.txt").mkString)
  val in  = new CustomScanner(System.in)
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val inputLines = in.nextInt()

    1.to(inputLines)
      .foreach(i => {
        val a = in.nextInt()
        val b = in.nextInt()
        val x = in.nextInt()
        val y = in.nextInt()
        val n = in.nextInt()

        if (i == 4918) {
          println(a, b, x, y, n)
          val r1 = findR(a, b, x, y, n)
          val r2 = findR(b, a, y, x, n)
          printf("%.0f\n", math.min(r1, r2))
        } else if( i <= 7){

          val r1 = findR(a, b, x, y, n)
          val r2 = findR(b, a, y, x, n)
          printf("%.0f\n", math.min(r1, r2))
        }

      })
  }

  def findR(a: Int, b: Int, x: Int, y: Int, n: Int) = {
    val (a1, r) = if (a - x <= n) (a - (a - x), n - (a - x)) else (a - n, 0)
    val b1      = if (b - y <= r) b - (b - y) else b - r
    a1.toDouble * b1.toDouble
  }

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

  /**
    * Util methods
    */

  def printArr[T](in: Array[T]) = {
    in.foreach(print)
    println()
  }

  /**
    * Scala implementation of a faster java.util.Scanner
    * See: http://codeforces.com/blog/entry/7018
    */
  class CustomScanner(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))

    private[this] val tokenizers = {
      Iterator
        .continually(reader.readLine())
        .takeWhile(_ != null)
        .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
      reader.readLine()
    }

    def lineNumber: Int = reader.getLineNumber

    def line(): String = tokenizer().get.nextToken("\n\r")

    def nextLineInt(n: Int): ArrayBuffer[Int] = {
      var data = ArrayBuffer[Int]()
      n.times({
        data += nextInt()
      })
      data
    }

    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(): String = tokenizer().get.nextToken()

    override def hasNext: Boolean = tokenizer().nonEmpty

    override def close(): Unit = reader.close()
  }
}


A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba".If string s has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible.Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.

The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s. The second line contains the string s of length n consisting of only lowercase English letters.

If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.

NoteIn the first sample one of the possible solutions is to change the first character to 'b'.In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".

object Solution {

	def main(arg: Array[String]) {
		val sc = new java.util.Scanner(System.in)
		val n = sc.nextInt
		val s = sc.next
		val charCounts = new Array[Int](26)
		for (i <- 0 until s.length) {
			val idx = s.charAt(i) - 'a'
			charCounts(idx) = charCounts(idx) + 1
		}
		val unused = charCounts.foldLeft(0)((a,b) => a + (if (b == 0) 1 else 0))
		val sum = charCounts.foldLeft(0)((a,b) => a + (if (b > 1) b-1 else 0))
		println(if (unused >= sum) sum else -1)
	}
}

object Solution extends App {
  val lines = io.Source.stdin.getLines()
  val n = lines.next().toInt
  val line = lines.next()
  if (n > 26)
    println(-1)
  else
    println(n - line.distinct.length)
}

object B672 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = read
    if(in.length > 26) {
      println("-1")
    } else {
      val res = in.length - in.distinct.length
      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.io.StdIn

/**
  * Created by whimsy on 16/7/17.
  */

object P672B extends App {
    val n = StdIn.readInt()

    val content = StdIn.readLine()

    var set = Set[Char]()

    val answer = if (n > 26) {
        -1
    } else {
        content.foreach(e =>
            set += e
        )

        content.size - set.size
    }

    println(answer)
}


Valera is a collector. Once he wanted to expand his collection with exactly one antique item.Valera knows n sellers of antiques, the i-th of them auctioned ki items. Currently the auction price of the j-th object of the i-th seller is sij. Valera gets on well with each of the n sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him.Unfortunately, Valera has only v units of money. Help him to determine which of the n sellers he can make a deal with.

The first line contains two space-separated integers n, v (1 ≤ n ≤ 50; 104 ≤ v ≤ 106) — the number of sellers and the units of money the Valera has. Then n lines follow. The i-th line first contains integer ki (1 ≤ ki ≤ 50) the number of items of the i-th seller. Then go ki space-separated integers si1, si2, ..., siki (104 ≤ sij ≤ 106) — the current prices of the items of the i-th seller.

In the first line, print integer p — the number of sellers with who Valera can make a deal. In the second line print p space-separated integers q1, q2, ..., qp (1 ≤ qi ≤ n) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.

NoteIn the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller.In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him.

import java.util.StringTokenizer

import scala.collection.mutable.ArrayBuilder

object _441A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val v = next.toInt
  val builder = new ArrayBuilder.ofInt
  for (i <- 1 to n) {
    val m = next.toInt
    if ((1 to m).map(i => next.toInt).min < v) builder += i
  }
  val res = builder.result
  println(res.length)
  println(res.mkString(" "))
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, v) = in.next().split(" ").map(_.toInt)
  val r = Range(1, n + 1).map(i => (i, in.next().split(" ").map(_.toInt).tail.min)).filter(_._2 < v).map(_._1)
  println(r.length)
  println(r.mkString(" "))
}

/**
 * Created by ashione on 14-6-19.
 */
object CF441A {
  import java.util.Scanner
  val in = new Scanner(System.in)

  def main(arg:Array[String]):Unit = {

    val itemNum = in.nextInt
    val valeraPrice = in.nextInt
    val ans:List[Int] = (for(i <- 1 to itemNum if isDeal(valeraPrice)) yield i).toList
    println(ans.length)
    ans.foreach(x=>print(x+" "))
  }
  def isDeal(price:Int):Boolean = {
    val sellerNum = in.nextInt
    val sl: List[Int] = {
      for (i <- 1 to sellerNum) yield in.nextInt
    }.toList
    !sl.forall(x => x >= price)
  }
}

object a {

  def main (args: Array[String]){
    var Array(n,k) = readLine.split(" ").map(_.toInt)
    var ans = 0
    var used = new Array[Int](n+1)
    for (i <- 0 until n){
      var x = readLine.split(" ").map(_.toInt)
      var bl =false
      for (j <- 1 to x(0))
        if (x(j)<k && !bl)
        	{ans +=1;bl=true;used(ans)=i+1}
    }
    println(ans)
    for (i <- 1 to ans)
      print(used(i)+" ")
  }

}

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

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

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

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

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

  def main(args: Array[String]): Unit = {
    val Array(n, v) = readInts(2)
    var arr = Array[Int]()
    for(i <- 0 until n) {
      val tl = tokenizeLine
      val num = tl.nextToken.toInt
      if(Array.fill(num)(tl.nextToken.toInt).min < v) {
        arr ++= Array(i+1)
      }
    }
    println(arr.length)
    println(arr.mkString(" "))
  }
}

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

object A extends App {

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

  val Array(n, v) = readInts(2)
  val res = mutable.Buffer.empty[Int]

  for (i <- 1 to n) {
    val t2 = tokenizeLine
    val k = t2.nextToken.toInt
    val min = Array.fill(k)(t2.nextToken.toInt).min
    if (min < v) res += i
  }

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

object Template {
	def main(args: Array[String]) {
		var Array(n, l) = readLine.split(" ").map(_.toInt)
		var array : Array[Int] = new Array[Int](n)
		var result = 0
		for(i <- 1 to n){
			var line = readLine.split(" ").map(_.toInt)
			var added = false
			for(j <- 1 to line(0)){
				if(line(j) < l && !added){
					result += 1
					array(i-1) = i
					added = true
				}
			}
		}
		println(result)
		for(i <- array){
			if(i != 0) print(i + " ")
		}
	}
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, v) = in.next().split(" ").map(_.toInt)
  println(Range(0, n).map(_ => in.next().split(" ").map(_.toInt).tail.min).count(_ > v))
}


The sequence of $$$m$$$ integers is called the permutation if it contains all integers from $$$1$$$ to $$$m$$$ exactly once. The number $$$m$$$ is called the length of the permutation.Dreamoon has two permutations $$$p_1$$$ and $$$p_2$$$ of non-zero lengths $$$l_1$$$ and $$$l_2$$$.Now Dreamoon concatenates these two permutations into another sequence $$$a$$$ of length $$$l_1 + l_2$$$. First $$$l_1$$$ elements of $$$a$$$ is the permutation $$$p_1$$$ and next $$$l_2$$$ elements of $$$a$$$ is the permutation $$$p_2$$$. You are given the sequence $$$a$$$, and you need to find two permutations $$$p_1$$$ and $$$p_2$$$. If there are several possible ways to restore them, you should find all of them. (Note that it is also possible that there will be no ways.)

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) denoting the number of test cases in the input. Each test case contains two lines. The first line contains one integer $$$n$$$ ($$$2 \leq n \leq 200\,000$$$): the length of $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq n-1$$$). The total sum of $$$n$$$ is less than $$$200\,000$$$.

For each test case, the first line of output should contain one integer $$$k$$$: the number of ways to divide $$$a$$$ into permutations $$$p_1$$$ and $$$p_2$$$. Each of the next $$$k$$$ lines should contain two integers $$$l_1$$$ and $$$l_2$$$ ($$$1 \leq l_1, l_2 \leq n, l_1 + l_2 = n$$$), denoting, that it is possible to divide $$$a$$$ into two permutations of length $$$l_1$$$ and $$$l_2$$$ ($$$p_1$$$ is the first $$$l_1$$$ elements of $$$a$$$, and $$$p_2$$$ is the last $$$l_2$$$ elements of $$$a$$$). You can print solutions in any order.

NoteIn the first example, two possible ways to divide $$$a$$$ into permutations are $$$\{1\} + \{4, 3, 2, 1\}$$$ and $$$\{1,4,3,2\} + \{1\}$$$.In the second example, the only way to divide $$$a$$$ into permutations is $$$\{2,4,1,3\} + \{2,1\}$$$.In the third example, there are no possible ways.

object B extends App {

  private def restore(as: List[Int]): List[(Int, Int)] = {
    val n = as.length
    val ma = as.max

    List(ma, n - ma)
      .foldLeft(List.empty[(Int, Int)]) {
        case (ls, i) =>
          val (l1, l2) = (i, n - i)

          val (q1, q2) = as.splitAt(i)
          val (p1, p2) = (q1.distinct, q2.distinct)

          if (p1.length == l1 && p1.min == 1 && p1.max == l1 &&
              p2.length == l2 && p2.min == 1 && p2.max == l2)
            (l1, l2) :: ls
          else
            ls
      }
      .distinct
  }

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

  val input: List[List[Int]] = (0 until t)
    .foldLeft(List.empty[List[Int]]) { (input, _) =>
      val n = scala.io.StdIn.readInt()
      val as = scala.io.StdIn.readLine().split(" ").map(_.toInt).toList

      as :: input
    }
    .reverse

  val output = input.map(restore)

  output.foreach { ls =>
    println(ls.length)
    if (ls.nonEmpty) ls.foreach { case (l1, l2) => println(s"$l1 $l2") }
  }
}

object B extends App {

  private def restore(as: List[Int]): List[(Int, Int)] = {
    val n = as.length
    val ma = as.max

    List(ma, n - ma).foldLeft(List.empty[(Int, Int)]) {
      case (ls, i) =>
        val (q1, q2) = as.splitAt(i)
        val (p1, p2) = (q1.distinct, q2.distinct)
        val (l1, l2) = (i, n - i)

        if (p1.min == 1 && p2.min == 1 && p1.length == l1 && p2.length == l2)
          (l1, l2) :: ls
        else
          ls
    }
  }

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

  val input: List[List[Int]] = (0 until t)
    .foldLeft(List.empty[List[Int]]) { (input, _) =>
      val n = scala.io.StdIn.readInt()
      val as = scala.io.StdIn.readLine().split(" ").map(_.toInt).toList

      as :: input
    }
    .reverse

  val output = input.map(restore)

  output.foreach { ls =>
    println(ls.length)
    if (ls.nonEmpty) ls.foreach { case (l1, l2) => println(s"$l1 $l2") }
  }
}

object B extends App {

  private def restore(as: List[Int]): List[(Int, Int)] = {
    val n = as.length
    val ma = as.max

    List(ma, n - ma).foldLeft(List.empty[(Int, Int)]) {
      case (ls, i) =>
        val (l1, l2) = (i, n - i)

        val (q1, q2) = as.splitAt(i)
        val (p1, p2) = (q1.distinct, q2.distinct)

        if (p1.length == l1 && p2.length == l2 &&
            p1.min == 1 && p1.max == l1 &&
            p2.min == 1 && p2.max == l2)
          (l1, l2) :: ls
        else
          ls
    }
  }

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

  val input: List[List[Int]] = (0 until t)
    .foldLeft(List.empty[List[Int]]) { (input, _) =>
      val n = scala.io.StdIn.readInt()
      val as = scala.io.StdIn.readLine().split(" ").map(_.toInt).toList

      as :: input
    }
    .reverse

  val output = input.map(restore)

  output.foreach { ls =>
    println(ls.length)
    if (ls.nonEmpty) ls.foreach { case (l1, l2) => println(s"$l1 $l2") }
  }
}

object B extends App {

  private def restore(as: List[Int]): List[(Int, Int)] = {
    val n = as.length
    val ma = as.max

    List(ma, n - ma).foldLeft(List.empty[(Int, Int)]) {
      case (ls, i) =>
        val (p1, p2) = as.splitAt(i)
        val (l1, l2) = (i, n - i)

        if (p1.distinct.length == l1 && p2.distinct.length == l2)
          (l1, l2) :: ls
        else
          ls
    }
  }

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

  val input: List[List[Int]] = (0 until t)
    .foldLeft(List.empty[List[Int]]) { (input, _) =>
      val n = scala.io.StdIn.readInt()
      val as = scala.io.StdIn.readLine().split(" ").map(_.toInt).toList

      as :: input
    }
    .reverse

  val output = input.map(restore)

  output.foreach { ls =>
    println(ls.length)
    if (ls.nonEmpty) ls.foreach { case (l1, l2) => println(s"$l1 $l2") }
  }
}


Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, second one is love, third one is hate and so on...For example if n = 1, then his feeling is "I hate it" or if n = 2 it's "I hate that I love it", and if n = 3 it's "I hate that I love that I hate it" and so on.Please help Dr. Banner.

The only line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of layers of love and hate.

I hate it
I hate that I love it
I hate that I love that I hate it

object tanya extends App{
var a = readInt
var str = ""
val hate = "I hate"
val love = "I love"

for(i <- 0 to a){
    if(i == 1){
        str = str.concat(hate)
    }else if(i >= 2){
        str = str.concat(" that ")
        if(i % 2 == 1){
            str = str.concat(hate)
        }else{
            str = str.concat(love)
        }
    }
}
str = str.concat(" it")
println(str)
}

object Solution extends App {
  val lines = io.Source.stdin.getLines()
  val n = lines.next().toInt
  println((1 to n).map(i => if (i % 2 == 0) "I love " else "I hate ").mkString("", "that ", "it"))
}

object A705 {
  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)

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

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

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val str = Array("I hate", "I love")
    println(
      (0 until n).foldLeft(""){ (s, i) =>
        s + " " + str(i%2) + (if(i == n-1) " it" else " that")
      }.trim)
  }
}

import java.util._;

object Main extends App {

  def fun(n: Int, flip: Boolean, acc: String): String = {
    def addPhrase(): String = if (flip) "I hate" else "I love"

    if (n == 0) acc
    else if (n == 1) {
      fun(n - 1, !flip, acc ++ addPhrase() ++ " it ")
    } else {
      fun(n - 1, !flip, acc ++ addPhrase() ++ " that ")
    }
  }

  val sc = new Scanner(System.in);
  val n: Int = sc.nextInt()
  println(fun(n, flip = true, ""))
}

import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._

object _705A extends CodeForcesApp {
  override def apply(io: IO) = {import io.{read, write}
    val n = read[Int]
    val tokens = (1 to n) map {
      case i if i%2 == 1 => "I hate"
      case _ => "I love"
    }
    val ans = tokens.mkString("", " that ", " it")
    write(ans)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    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)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    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 {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[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
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

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()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(read).to[C]

  def readTill(delim: String): String = tokenizer().get.nextToken(delim)
  def readTillEndOfLine(): String = readTill("\n\r")

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

  def write(obj: Any, more: Any*): this.type = {
    printer.print(obj)
    more foreach {i =>
      printer.print(' ')
      printer.print(i)
    }
    this
  }
  def writeOnNextLine(obj: Any, more: Any*): this.type = {
    printer.println()
    write(obj, more: _*)
    this
  }
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)

  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: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                      : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

import scala.io.StdIn._

object Solution {

  def main(args: Array[String]): Unit = {
    val n = readInt
    val ans =
      (1 to n).foldLeft("") {
        case (acc, `n`) if n % 2 == 1 => acc + "I hate it"
        case (acc, `n`) => acc + "I love it"
        case (acc, i) if i % 2 == 1 => acc + "I hate that "
        case (acc, i) => acc + "I love that "
      }
    print(ans)
  }
}

import scala.io.StdIn._

object A extends App {
  val n = readInt()
  val A = Array("I hate", "I love")

  val B = (0 until n).map { i =>
    A(i % 2)
  }

  println(B.mkString(" that ") + " it")

}

object Hulk705A // extends TSolver {
                     extends App {
    import java.io.{InputStream, PrintStream}
    import java.util.Scanner
    solve(System.in,System.out)
    def solve(in: InputStream, out: PrintStream): Unit = {
        val scanner = new Scanner(in)
      val n = scanner.nextInt()
      val s = (1 to n).map{i => s"I ${if(i%2==1)"hate" else "love" }"}.mkString(" that ") + " it"
      out.println(s)
    }
}

import scala.io.StdIn

object Codeforces705A extends App {
  var n = StdIn.readLine().toInt
  var love = false
  while (n > 0) {
    if (love) {
      print("I love " + (if (n == 1) "it" else "that "))
    } else {
      print("I hate " + (if (n == 1) "it" else "that "))
    }
    love = !love
    n -= 1
  }
}

import scala.io.StdIn

object Main2 extends App {
  val feelingNumber = StdIn.readInt()
  val res = 0.until(feelingNumber)
    .map(index => s"I ${if (index % 2 == 0) "hate" else "love"}")
    .mkString(" that ") + " it"
  println(res)
}

import java.util

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

object App {

  def main(args: Array[String]) {

    val max = 1000000007;
    val n = readInt()

    var s = ""

    for(i <- 0 until n) {
      if(i % 2 == 0) {
        s+="I hate that "
      } else {
        s+="I love that "
      }
    }

    println(s.reverse.replaceFirst("taht", "ti").reverse)

  }

  def readInt(): Int = StdIn.readInt()

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

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

}

import scala.io.StdIn._

object TaskA extends App {
  println((1 to readInt map(i => if (i % 2 == 0) "I love" else "I hate" ) mkString " that ") + " it")
}

import scala.io.StdIn._

object Solution {
	var n = readInt

	def main(args:Array[String]):Unit = {

		for(i <- 1 to n-1) {
			if(i%2 == 0) print("I love that ")
			else print("I hate that ")
		}

		if(n % 2 == 0) print("I love it\n")
		else print("I hate it\n")

	}
}

object Main {
  def main(args: Array[String]) : Unit = {
    val n = readInt
    val feelings = List("hate", "love")

    def loop(index: Int, res: String): String = {
      val feeling = feelings(index % 2)

      if(index == n-1) return res + s"I $feeling it"

      loop(index + 1, res + s"I $feeling that ")
    }

    println(loop(0, ""))
  }
}

object Main {
def main(args: Array[String]) : Unit = {
    val n = readInt
    val feelings = List("hate", "love")

    def loop(index: Int): String = {
      val feeling = feelings(index % 2)

      if(index == n-1) return s"I $feeling it"

      s"I $feeling that " + loop(index + 1)
    }

    println(loop(0))
  }
}

object A705 {
  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)

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

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

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val str = Array("I hate that", "I love that")
    println((0 until n).foldLeft(""){(s, i) => s + " " + str(i%2)}.trim)
  }
}

import scala.io.StdIn

object Codeforces705A extends App {
  var n = StdIn.readLine().toInt
  while (n > 0) {
    if (n % 2 == 0) {
      print("I love " + (if (n == 1) "it" else "that "))
    } else {
      print("I hate " + (if (n == 1) "it" else "that "))
    }
    n -= 1
  }
}


Stepan likes to repeat vowel letters when he writes words. For example, instead of the word "pobeda" he can write "pobeeeedaaaaa".Sergey does not like such behavior, so he wants to write a program to format the words written by Stepan. This program must combine all consecutive equal vowels to a single vowel. The vowel letters are "a", "e", "i", "o", "u" and "y".There are exceptions: if letters "e" or "o" repeat in a row exactly 2 times, like in words "feet" and "foot", the program must skip them and do not transform in one vowel. For example, the word "iiiimpleeemeentatiioon" must be converted to the word "implemeentatioon".Sergey is very busy and asks you to help him and write the required program.

The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of letters in the word written by Stepan. The second line contains the string s which has length that equals to n and contains only lowercase English letters — the word written by Stepan.

Print the single string — the word written by Stepan converted according to the rules described in the statement.

pobeda implemeentatioon aeiouyaeeioouy aoiuyeggghhh

object Main {
    def main(args: Array[String]) {
        var n = readInt
        var s = readLine
        var i = 0
        if ( n == 0 ) {
            sys.exit(0)
        }
        print(s.charAt(0))
        for (i <- 1 to n-1) {
                if ( ! ( ( s.charAt(i) == s.charAt(i-1) && ( s.charAt(i) == 'a' || s.charAt(i) == 'i' || s.charAt(i) == 'u' || s.charAt(i) == 'y'  ) ) ||
                       ( s.charAt(i) == s.charAt(i-1) && ( ( i > 1 && s.charAt(i) == s.charAt(i-2) ) || ( i != n-1 && s.charAt(i+1) == s.charAt(i) ) ) && ( s.charAt(i) == 'o' || s.charAt(i) == 'e' ) ) ) )
                print(s.charAt(i))
        }
        println("")
    }
}

object CF {
   def isVowel(c: Char): Boolean =
  	List('a','e','i','o','u', 'y') exists (a => a == Character.toLowerCase(c))
  def main(args: Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    var n = sc.nextInt()
    var s = sc.next()
    var i = 0
    while (i < n) {
      var j = i + 1
      if(isVowel(s(i))) {
        var cnt = 1
        while (j < n && s(j) == s(i)) {
          j = j + 1
          cnt = cnt + 1
        }
        if (s(i) == 'e' || s(i) == 'o') {
          if (cnt == 2) {
            print(s(i))
          }
        }
      }
      print(s(i))
      i = j
    }
  }
}

object Main extends App {
    val n = readInt
    val s = readLine
    var pc = ' '
    var count = 0
    for (c <- s) {
        if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') {
            if (c == pc) {
                count += 1
            } else {
                if (count > 0) {
                    if (count == 2 && ((pc == 'o' || pc == 'e'))) {
                        print(pc)
                        print(pc)
                    } else {
                        print(pc)
                    }
                }
                pc = c
                count = 1
            }
        } else {
            if (count > 0) {
                if (count == 2 && ((pc == 'o' || pc == 'e'))) {
                    print(pc)
                    print(pc)
                } else {
                    print(pc)
                }
            }

            count = 0
            print(c)
        }
        pc = c
    }
    if (count > 0) {
        if (count == 2 && ((pc == 'o' || pc == 'e'))) {
            print(pc)
            print(pc)
        } else {
            print(pc)
        }
    }
    println()
}

object CF {
   def isVowel(c: Char): Boolean =
  	List('a','e','i','o','u') exists (a => a == Character.toLowerCase(c))
  def main(args: Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    var n = sc.nextInt()
    var s = sc.next()
    var i = 0
    while (i < n) {
      var j = i + 1
      if(isVowel(s(i))) {
        while (j < n && s(j) == s(i)) {
          j = j + 1
        }
      }
      print(s(i))
      i = j
    }
  }
}

object CF {
   def isVowel(c: Char): Boolean =
  	List('a','e','i','o','u') exists (a => a == Character.toLowerCase(c))
  def main(args: Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    var n = sc.nextInt()
    var s = sc.next()
    var i = 0
    while (i < n) {
      var j = i + 1
      if(isVowel(s(i))) {
        var cnt = 1
        while (j < n && s(j) == s(i)) {
          j = j + 1
          cnt = cnt + 1
        }
        if (s(i) == 'e' || s(i) == 'o') {
          if (cnt == 2) {
            print(s(i))
          }
        }
      }
      print(s(i))
      i = j
    }
  }
}


People worry that computers will get too smart and take over the world, but the real problem is that they're too stupid and they've already taken over the world.— Pedro DomingosYou work for a well-known department store that uses leading technologies and employs mechanistic work — that is, robots!The department you work in sells $$$n \cdot k$$$ items. The first item costs $$$1$$$ dollar, the second item costs $$$2$$$ dollars, and so on: $$$i$$$-th item costs $$$i$$$ dollars. The items are situated on shelves. The items form a rectangular grid: there are $$$n$$$ shelves in total, and each shelf contains exactly $$$k$$$ items. We will denote by $$$a_{i,j}$$$ the price of $$$j$$$-th item (counting from the left) on the $$$i$$$-th shelf, $$$1 \le i \le n, 1 \le j \le k$$$.Occasionally robots get curious and ponder on the following question: what is the mean price (arithmetic average) of items $$$a_{i,l}, a_{i,l+1}, \ldots, a_{i,r}$$$ for some shelf $$$i$$$ and indices $$$l \le r$$$? Unfortunately, the old robots can only work with whole numbers. If the mean price turns out not to be an integer, they break down.You care about robots' welfare. You want to arrange the items in such a way that the robots cannot theoretically break. Formally, you want to choose such a two-dimensional array $$$a$$$ that:  Every number from $$$1$$$ to $$$n \cdot k$$$ (inclusively) occurs exactly once.  For each $$$i, l, r$$$, the mean price of items from $$$l$$$ to $$$r$$$ on $$$i$$$-th shelf is an integer. Find out if such an arrangement is possible, and if it is, give any example of such arrangement.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. The first and only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 500$$$) — the number of shelves and length of each shelf, respectively. It is guaranteed that the sum $$$n$$$ over all test cases does not exceed $$$500$$$ and the sum $$$k$$$ over all test cases does not exceed $$$500$$$.

Print the answer for each test case. If such an arrangement exists, print "YES" on a single line. After that, print any example on $$$n$$$ lines of $$$k$$$ numbers each, one line per shelf. Each number from $$$1$$$ to $$$n \cdot k$$$ must occur exactly once in the output. If no good arrangement exists, print a single word "NO" on its own line.

import scala.io.Source

object Contest extends App {
  def logic(n: Int, k: Int): Unit = {
    val max = n * k
    if (k == 1) {
      println("YES")
      println(Range.inclusive(1, max).mkString("\n"))
    } else if (max % 2 == 0 && n != 1 && (max / 2) % k == 0) {
      println("YES")
      Range(1, max, 2).grouped(k).map(_.mkString(" "))
        .foreach(println)
      Range.inclusive(2, max, 2).grouped(k).map(_.mkString(" "))
        .foreach(println)
    } else println("NO")
  }

  val input = Source.fromInputStream(System.in).getLines()
  val t = input.next().toInt
  val nk = new Array[(Int, Int)](t)
  for (i <- 0 until t) {
    val Array(n, k) = input.next().split(" ")
    nk(i) = (n.toInt, k.toInt)
  }

  for (i <- 0 until t) {
    val (n, k) = nk(i)
    logic(n, k)
  }
}

import sun.management.counter.Counter

import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine

object Solution extends App {

  //=====Solution=========
  val testNumber = readInt()
  1.to(testNumber).foreach { _ =>
    val Array(n, k) = readInts()
    k match {
      case 1 =>
        println("YES")
        1.to(n).foreach(v => println(v))
      case _ if (n % 2 == 0) =>
        println("YES")
        val a = 1.to(k * n / 2).map(_ * 2 - 1)
        val b = 1.to(k * n / 2).map(_ * 2)
        a.grouped(k).map(_.mkString(" ")).foreach(println(_))
        b.grouped(k).map(_.mkString(" ")).foreach(println(_))
      case _ => println("NO")
    }
  }

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

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

  //1 3 5 7 9 11
  //2 4 6 8 10 12
  //13 15 17 19 21 23
  //14 16 18 20 22 24
  //25 27 29 31 33 35
  //26 28 30 32 34 36

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

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

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(var a: Int, var b: Int)extends Ordered[pair] {
        override def compare(that: pair): Int = {
            return (a).compareTo(that.a)
        }
    }

    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 mapp = mutable.Map[pair, Int]()

    val t = readInt()

    for (tt <- 1 to t) {
        val n = readInt()
        val k = readInt()
        if (n % 2 == 1 && k > 1) {
            writer.println("NO")
        } else {
            writer.println("YES")
            var pl = 1
            var pr = 2
            for (i <- 1 to n) {
                for (j <- 1 to k) {
                    if (i % 2 == 1) {
                        writer.print(pl + " ")
                        pl += 2
                    } else {
                        writer.print(pr + " ")
                        pr += 2
                    }
                }
                writer.println()
            }
        }

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

import scala.io.Source

object Contest extends App {
  def logic(n: Int, k: Int): Unit = {
    val max = n * k
    if (k == 1) {
      println("YES")
      println(Range.inclusive(1, max).mkString("\n"))
    } else if (max % 2 == 0 && n != 1) {
      println("YES")
      Range(1, max, 2).grouped(k).map(_.mkString(" "))
        .foreach(println)
      Range.inclusive(2, max, 2).grouped(k).map(_.mkString(" "))
        .foreach(println)
    } else println("NO")
  }

  val input = Source.fromInputStream(System.in).getLines()
  val t = input.next().toInt
  val nk = new Array[(Int, Int)](t)
  for (i <- 0 until t) {
    val Array(n, k) = input.next().split(" ")
    nk(i) = (n.toInt, k.toInt)
  }

  for (i <- 0 until t) {
    val (n, k) = nk(i)
    logic(n, k)
  }
}

import scala.io.Source

object Contest extends App {
  def logic(n: Int, k: Int): Unit = {
    val max = n * k
    if (k == 1) {
      println("YES")
      println(Range.inclusive(1, max).mkString("\n"))
    } else if (max % 2 == 0) {
      println("YES")
      Range(1, max, 2).grouped(k).map(_.mkString(" "))
        .foreach(println)
      Range.inclusive(2, max, 2).grouped(k).map(_.mkString(" "))
        .foreach(println)
    } else println("NO")
  }

  val input = Source.fromInputStream(System.in).getLines()
  val t = input.next().toInt
  val nk = new Array[(Int, Int)](t)
  for (i <- 0 until t) {
    val Array(n, k) = input.next().split(" ")
    nk(i) = (n.toInt, k.toInt)
  }

  for (i <- 0 until t) {
    val (n, k) = nk(i)
    logic(n, k)
  }
}

import scala.io.Source

object Contest extends App {
  def logic(n: Int, k: Int): Unit = {
    val max = n * k
    if (k == 1) {
      println("YES")
      println(Range.inclusive(1, max).mkString("\n"))
    } else if (max % 2 == 0) {
      println("YES")
      Range(1, max, 2).sliding(k).map(_.mkString(" "))
        .foreach(println)
      val b = Range.inclusive(2, max, 2).sliding(k).map(_.mkString(" "))
        .foreach(println)
    } else println("NO")
  }

  val input = Source.fromInputStream(System.in).getLines()
  val t = input.next().toInt
  val nk = new Array[(Int, Int)](t)
  for (i <- 0 until t) {
    val Array(n, k) = input.next().split(" ")
    nk(i) = (n.toInt, k.toInt)
  }

  for (i <- 0 until t) {
    val (n, k) = nk(i)
    logic(n, k)
  }
}

import scala.collection.mutable.ArrayBuffer
import scala.io.Source

object Contest extends App {
  def logic(n: Int, k: Int): Unit = {
    if (k == 1) {
      println("YES")
      val max = n * k
      println(Range.inclusive(1, max).mkString("\n"))
    } else if (k == 2) {
      println("YES")
      val max = n * k
      val res = new ArrayBuffer[String](n)
      for (i <- 1 until max by 4) {
        res.append(s"$i ${i + 2}")
      }
      for (i <- 2 until max by 4) {
        res.append(s"$i ${i + 2}")
      }
      println(res.mkString("\n"))
    } else println("NO")
  }

  val input = Source.fromInputStream(System.in).getLines()
  val t = input.next().toInt
  val nk = new Array[(Int, Int)](t)
  for (i <- 0 until t) {
    val Array(n, k) = input.next().split(" ")
    nk(i) = (n.toInt, k.toInt)
  }

  for (i <- 0 until t) {
    val (n, k) = nk(i)
    logic(n, k)
  }
}

import sun.management.counter.Counter

import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine

object Solution extends App {

  //=====Solution=========
  val testNumber = readInt()
  1.to(testNumber).foreach { _ =>
    val Array(n, k) = readInts()
    k match {
      case 1 =>
        println("YES")
        1.to(n).foreach(v => println(v))
      case 2 if n % 2 == 0 =>
        println("YES")
        1.to(n).foreach(v => println(s"$v ${v + n}"))
      case _ if (n == 2) =>
        println("YES")
        println(1.to(k).map(_ * 2 - 1).mkString(" "))
        println(1.to(k).map(_ * 2).mkString(" "))
      case _ => println("NO")
    }
  }

  //1 3 5
  //2 4 6

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

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

import sun.management.counter.Counter

import scala.:+
import scala.+:
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLong
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine

object Solution extends App {

  //=====Solution=========
  val testNumber = readInt()
  1.to(testNumber).foreach { _ =>
    val Array(n, k) = readInts()
    k match {
      case 1 =>
        println("YES")
        1.to(n).foreach(v => println(v))
      case 2 if n % 2 == 0 =>
        println("YES")
        1.to(n).foreach(v => println(s"$v ${v + n}"))
      case _ => println("NO")
    }
  }

  //=====Template=========
  def readInts(): Array[Int] = readLine().split(" ").map(_.toInt)
  def readLongs(): Array[Long] = readLine().split(" ").map(_.toLong)
  def readChars(): Array[Char] = readLine().toCharArray
  def asInt(b: Boolean) = if (b) 1 else 0

  class MutableMultiSet[T](seq: Seq[T])(implicit val ord: Ordering[T]) {
    val multiSet: mutable.TreeMap[T, Int] = new mutable.TreeMap[T, Int]()
    seq.foreach { value => add(value) }
    def contains(value: T) = multiSet.contains(value)
    def max: T = multiSet.last._1
    def min: T = multiSet.head._1
    def add(value: T) = multiSet.get(value) match {
      case None => multiSet(value) = 1
      case Some(counter) => multiSet(value) = counter + 1
    }
    def remove(value: T) = multiSet.get(value) match {
      case None => None
      case Some(1) => multiSet.remove(value)
      case Some(counter) => multiSet(value) = counter - 1
    }
  }
}

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(var a: Int, var b: Int)extends Ordered[pair] {
        override def compare(that: pair): Int = {
            return (a).compareTo(that.a)
        }
    }

    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 mapp = mutable.Map[pair, Int]()

    val t = readInt()

    for (tt <- 1 to t) {
        val n = readInt()
        val k = readInt()
        if (n * k % 2 == 1 && k > 1) {
            writer.println("NO")
        } else {
            writer.println("YES")
            var pl = 1
            var pr = 2
            for (i <- 1 to n) {
                for (j <- 1 to k) {
                    if (i % 2 == 1) {
                        writer.print(pl + " ")
                        pl += 2
                    } else {
                        writer.print(pr + " ")
                        pr += 2
                    }
                }
                writer.println()
            }
        }

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


The next lecture in a high school requires two topics to be discussed. The $$$i$$$-th topic is interesting by $$$a_i$$$ units for the teacher and by $$$b_i$$$ units for the students.The pair of topics $$$i$$$ and $$$j$$$ ($$$i < j$$$) is called good if $$$a_i + a_j > b_i + b_j$$$ (i.e. it is more interesting for the teacher).Your task is to find the number of good pairs of topics.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of topics. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the interestingness of the $$$i$$$-th topic for the teacher. The third line of the input contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 10^9$$$), where $$$b_i$$$ is the interestingness of the $$$i$$$-th topic for the students.

Print one integer — the number of good pairs of topic.

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

import scala.reflect.ClassTag
import scala.collection.Searching._

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

  private[this] val isOnlineJudge = true

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

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

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

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

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

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

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

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

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

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

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

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

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

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

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

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

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

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

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

  import Main._
  import fScanner._

  def solve(): Unit = {
    val n = ni()
    val a = na(n)
    val b = na(n)
    val c = Array.ofDim[Int](n)
    REP(n) { i =>
      c(i) = a(i) - b(i)
    }
    s = c.toIndexedSeq.sorted
    var ans = 0L
    REP(n) { i =>
      if(s(i) > 0) {
        ans += (i - bs(0, i, -1 * s(i) + 1))
      }
    }
    out.println(ans)
  }

  var s: IndexedSeq[Int] = _

  def bs(l: Int, h: Int, n: Int): Int = {
    var lo = l
    var hi = h
    while (hi - lo > 0) {
      val md = lo + (hi - lo) / 2
      if(s(md) < n) lo = md + 1
      else hi = md
    }
    if(s(lo) >= n) lo
    else hi
  }
}

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

import scala.reflect.ClassTag
import scala.collection.Searching._

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

  private[this] val isOnlineJudge = true

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

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

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

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

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

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

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

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

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

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

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

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

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

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

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

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

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

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

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

  import Main._
  import fScanner._

  def solve(): Unit = {
    val n = ni()
    val a = na(n)
    val b = na(n)
    val c = Array.ofDim[Int](n)
    REP(n) { i =>
      c(i) = a(i) - b(i)
    }
    s = c.toIndexedSeq.sorted
    var ans = 0L
    REP(n) { i =>
      if(s(i) > 0) {
        ans += (i - bs(0, i-1, -1 * s(i) + 1))
      }
    }
    out.println(ans)
  }

  var s: IndexedSeq[Int] = _

  def bs(l: Int, h: Int, n: Int): Int = {
    var lo = l
    var hi = h
    while (hi - lo > 0) {
      val md = lo + (hi - lo) / 2
      if(s(md) < n) lo = md + 1
      else hi = md
    }
    if(s(lo) >= n) lo
    else hi
  }
}

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

import scala.reflect.ClassTag
import scala.collection.Searching._

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

  private[this] val isOnlineJudge = true

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

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

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

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

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

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

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

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

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

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

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

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

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

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

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

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

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

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

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

  import Main._
  import fScanner._

  def solve(): Unit = {
    val n = ni()
    val a = na(n)
    val b = na(n)
    val c = Array.ofDim[Int](n)
    REP(n) { i =>
      c(i) = a(i) - b(i)
    }
    s = c.toIndexedSeq.sorted
    var ans = 0L
    REP(n) { i =>
      if(s(i) > 0) {
        ans += (i - bs(0, i-1, -1 * s(i) + 1))
      }
    }
    out.println(ans)
  }

  var s: IndexedSeq[Int] = _

  def bs(l: Int, h: Int, n: Int): Int = {
    var lo = l
    var hi = h
    while (hi - lo > 1) {
      val md = lo + (hi - lo) / 2
      if(s(md) < n) lo = md + 1
      else hi = md
    }
    if(s(lo) >= n) lo
    else hi
  }
}

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

import scala.reflect.ClassTag
import scala.collection.Searching._

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

  private[this] val isOnlineJudge = true

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

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

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

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

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

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

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

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

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

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

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

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

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

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

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

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

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

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

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

  import Main._
  import fScanner._

  def solve(): Unit = {
    val n = ni()
    val a = na(n)
    val b = na(n)
    val c = Array.ofDim[Int](n)
    REP(n) { i =>
      c(i) = a(i) - b(i)
    }
    val s = c.toIndexedSeq.sorted
    var ans = 0L
    REP(n) { i =>
      if(s(i) > 0) {
        ans += (s.search(-1 * s(i) + 1) match {
          case Found(u) => i - u
          case InsertionPoint(v) => i - v
        })
      }
    }
    out.println(ans)
  }
}