You are given $$$n$$$ words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.Each lyric consists of two lines. Each line consists of two words separated by whitespace. A lyric is beautiful if and only if it satisfies all conditions below.   The number of vowels in the first word of the first line is the same as the number of vowels in the first word of the second line.  The number of vowels in the second word of the first line is the same as the number of vowels in the second word of the second line.  The last vowel of the first line is the same as the last vowel of the second line. Note that there may be consonants after the vowel. Also, letters "a", "e", "o", "i", and "u" are vowels. Note that "y" is never vowel.For example of a beautiful lyric,  "hello hellooowww" "whatsup yowowowow"  is a beautiful lyric because there are two vowels each in "hello" and "whatsup", four vowels each in "hellooowww" and "yowowowow" (keep in mind that "y" is not a vowel), and the last vowel of each line is "o".For example of a not beautiful lyric,  "hey man""iam mcdic"  is not a beautiful lyric because "hey" and "iam" don't have same number of vowels and the last vowels of two lines are different ("a" in the first and "i" in the second).How many beautiful lyrics can you write from given words? Note that you cannot use a word more times than it is given to you. For example, if a word is given three times, you can use it at most three times.

The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^{5}$$$) — the number of words. The $$$i$$$-th of the next $$$n$$$ lines contains string $$$s_{i}$$$ consisting lowercase alphabet letters — the $$$i$$$-th word. It is guaranteed that the sum of the total word length is equal or less than $$$10^{6}$$$. Each word contains at least one vowel.

In the first line, print $$$m$$$ — the number of maximum possible beautiful lyrics. In next $$$2m$$$ lines, print $$$m$$$ beautiful lyrics (two lines per lyric). If there are multiple answers, print any.

14
wow
this
is
the
first
mcdics
codeforces
round
hooray
i
am
proud
about
that

7
arsijo
suggested
the
idea
for
this
problem

3
about proud
hooray round
wow first
this is
i that
mcdics am

NoteIn the first example, those beautiful lyrics are one of the possible answers. Let's look at the first lyric on the sample output of the first example. "about proud hooray round" forms a beautiful lyric because "about" and "hooray" have same number of vowels, "proud" and "round" have same number of vowels, and both lines have same last vowel. On the other hand, you cannot form any beautiful lyric with the word "codeforces".In the second example, you cannot form any beautiful lyric from given words.In the third example, you can use the word "same" up to three times.

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

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

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

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

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

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

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

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

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

case class Point(x: Int, y: Int)

case class Key(num: Int, last: Int)

class Answer {
  var l1_fst: Int = -1
  var l1_snd: Int = -1
  var l2_fst: Int = -1
  var l2_snd: Int = -1

  override def toString: String = s"[$l1_fst:$l1_snd,$l2_fst:$l2_snd]"
}

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

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

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

  def solve(): Unit = {
    val N = ni()
    val W = mutable.Map[Key, ArrayBuffer[Int]]()
    val C = mutable.Map[Int, Int]().withDefaultValue(0)
    val S = Array.ofDim[String](N)

    val V = "aiueo"

    def keyOf(s: String) = {
      val num = s.count(a => V.contains(a))
      val i = s.lastIndexWhere(a => V.contains(a))
      Key(num, V.indexWhere(_ == s(i)))
    }

    REP(N) { i =>
      val s = ns()
      S(i) = s
      val key = keyOf(s)
      if (!W.contains(key)) W(key) = ArrayBuffer()
      W(key) += i

      C(key.num) += 1
    }

    debug(W.keySet.mkString(" "))
    debug(C.mkString(" "))

    val numPairs = C.values.map(_ / 2).sum
    val keyPairs = W.values.map(_.length / 2).sum
    debug(s"nums:$numPairs keys:$keyPairs")

    val M = min(numPairs / 2, keyPairs)

    val used = Array.ofDim[Boolean](N)
    val ans = ArrayBuffer[Answer]()

    val it = W.keys.iterator
    var m = M
    while(m > 0 && it.hasNext) {
      val k = it.next
      val w = W(k)
      val cnt = min(m, w.length / 2)
      C(k.num) -= cnt
      REP(cnt * 2) { i =>
        if (i%2 == 0) ans += new Answer
        if (i%2 == 0) ans.last.l1_snd = w(i)
        else ans.last.l2_snd = w(i)
        used(w(i)) = true
      }
      m -= cnt
    }

    debug(ans.mkString(" "))

    val unused = mutable.Map[Int, ArrayBuffer[Int]]()
    for {
      k <- W.keys
      v <- W(k)
    } {
      if (!used(v)) {
        if (!unused.contains(k.num)) unused(k.num) = ArrayBuffer()
        unused(k.num) += v
      }
    }

    var p = 0
    val it2 = unused.valuesIterator
    while(p < M && it2.hasNext) {
      val vs = it2.next()
      val cnt = min(vs.length / 2, M - p)
      REP(cnt * 2) { i =>
        if (i%2 == 0) ans(p + i/2).l1_fst = vs(i)
        else ans(p + i/2).l2_fst = vs(i)
      }
      p += cnt
    }

    debug(ans.mkString(" "))

    out.println(M)
    REP(M) { i =>
      val a = ans(i)
      out.println(s"${S(a.l1_fst)} ${S(a.l1_snd)}")
      out.println(s"${S(a.l2_fst)} ${S(a.l2_snd)}")
    }
  }
}


Petya has got 2n cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2n. We'll denote the number that is written on a card with number i, as ai. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that.

The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains the sequence of 2n positive integers a1, a2, ..., a2n (1 ≤ ai ≤ 5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.

If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print n pairs of integers, a pair per line — the indices of the cards that form the pairs. Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them.

import scala.io.Source
import java.io.PrintWriter
import java.io.File
import collection.mutable.ArrayBuffer
import java.lang.System

object test {
  def main(args: Array[String]): Unit = {
    val lines=Source.fromFile("input.txt").getLines.toList
    val writer=new PrintWriter(new File("output.txt"))

    val a=lines(1).split(" ").map(x=>x.toInt)
    val arr=new Array[Int](5001)
    var sb=new StringBuffer

    for(i<-0 to a.length-1)
    {
      if(arr(a(i))>0)
      {
        sb.append(arr(a(i))+" "+(i+1)+"\n")
        arr(a(i))=0
      }
      else
      {
        arr(a(i))=i+1
      }
    }

      arr.foreach(i=>
        {
            if(i>0)
            {
              writer.println(-1)
              writer.close()
              return
            }
        }
      )

      writer.println(sb)
      writer.close()
  }

}

import scala.io.Source
import java.io.PrintWriter
import java.io.File
import collection.mutable.ArrayBuffer

object test {
  def main(args: Array[String]): Unit = {
    val lines=Source.fromFile("input.txt").getLines.toList
    val writer=new PrintWriter(new File("output.txt"))

    val n=lines(0).toInt
    val a=lines(1).split(" ").map(x=>x.toInt)
    val arr=new Array[ArrayBuffer[Int]](5001)
    for(i<-0 to 5000)
      arr(i)=new ArrayBuffer[Int]()

    for(i<-0 to a.length-1)
      arr(a(i))+=i+1

      arr.foreach(i=>
        if(i.length%2==1)
        {
          writer.println(-1)
          return
        }
      )

      arr.foreach(i=>
        for(j<-0 to i.length/2-1)
          writer.println(i(j)+" "+i(j+1))
      )
  }

}

import scala.io.Source
import java.io.PrintWriter
import java.io.File
import collection.mutable.ArrayBuffer

object test {
  def main(args: Array[String]): Unit = {
    val lines=Source.fromFile("input.txt").getLines.toList
    val writer=new PrintWriter(new File("output.txt"))

    val n=lines(0).toInt
    val a=lines(1).split(" ").map(x=>x.toInt)
    val arr=new Array[ArrayBuffer[Int]](5001)
    for(i<-0 to 5000)
      arr(i)=new ArrayBuffer[Int]()

    for(i<-0 to a.length-1)
      arr(a(i))+=i+1

      arr.foreach(i=>
        if(i.length%2==1)
        {
          writer.println(-1)
          return
        }
      )

      arr.foreach(i=>
        for(j<-0 to i.length/2-1)
          writer.println(i(j)+" "+i(j+1))
      )

      writer.close()
  }

}

import scala.io.Source
import java.io.PrintWriter
import java.io.File
import collection.mutable.ArrayBuffer

object test {
  def main(args: Array[String]): Unit = {
    val lines=Source.fromFile("input.txt").getLines.toList
    val writer=new PrintWriter(new File("output.txt"))

    val n=lines(0).toInt
    val a=lines(1).split(" ").map(x=>x.toInt)
    val arr=new Array[ArrayBuffer[Int]](5001)
    for(i<-0 to 5000)
      arr(i)=new ArrayBuffer[Int]()

    for(i<-0 to a.length-1)
      arr(a(i))+=i+1

      arr.foreach(i=>
        if(i.length%2==1)
        {
          writer.println(-1)
          writer.close()
          return
        }
      )

      arr.foreach(i=>
        for(j<-0 to i.length/2-1)
          writer.println(i(j)+" "+i(j+1))
      )

      writer.close()
  }

}


You are given three integers $$$a \le b \le c$$$.In one move, you can add $$$+1$$$ or $$$-1$$$ to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations.You have to perform the minimum number of such operations in order to obtain three integers $$$A \le B \le C$$$ such that $$$B$$$ is divisible by $$$A$$$ and $$$C$$$ is divisible by $$$B$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. Each test case is given on a separate line as three space-separated integers $$$a, b$$$ and $$$c$$$ ($$$1 \le a \le b \le c \le 10^4$$$).

For each test case, print the answer. In the first line print $$$res$$$ — the minimum number of operations you have to perform to obtain three integers $$$A \le B \le C$$$ such that $$$B$$$ is divisible by $$$A$$$ and $$$C$$$ is divisible by $$$B$$$. On the second line print any suitable triple $$$A, B$$$ and $$$C$$$.

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

import scala.reflect.ClassTag

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 C624(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 C624(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val t = ni()
    REP(t) { _ =>
      val a = ni()
      val b = ni()
      val c = ni()

      var ans = Long.MaxValue
      var A = a
      var B = b
      var C = c

      REP(2 * a, 1) { f =>
        f to 2 * b by f foreach { g =>
          REP(2) { h =>
            val CC = g * (c / g) + h * g
            val p = Math.abs(f - a) + Math.abs(g - b) + Math.abs(CC - c)
            if(p < ans) {
              ans = p
              A = f
              B = g
              C = CC
            }
          }
        }
      }
      out.println(ans)
      out.println(A + " " + B + " " + C)
    }
  }
}

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

import scala.reflect.ClassTag

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 C624(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 C624(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val t = ni()
    REP(t) { _ =>
      val a = ni()
      val b = ni()
      val c = ni()

      var ans = Long.MaxValue
      val ansA = Array.ofDim[Long](3)

      1 to 2 * a foreach { f =>
        val u = Math.abs(f - a)
        0 to 2 * b by f filter(f<=) foreach { g =>
          val x = (c / g).toLong
          val v = if(x * g >= b) Math.min(Math.abs(x*g-c), Math.abs((x+1)*g - c)) else if((x+1)*g >= b) Math.abs((x+1)*g - c) else -1
          if(v > -1) {
            val p =u+ Math.abs(g - b) + v
            if(p < ans) {
              ans = p
              ansA(0) = f
              ansA(1) = g
              ansA(2) = if(Math.abs(x*g - c) == v) x*g else (x+1)*g
            }
          }
        }
      }
      out.println(ans)
      out.println(ansA.mkString(" "))
    }
  }
}

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

import scala.reflect.ClassTag

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 C624(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 C624(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val t = ni()
    REP(t) { _ =>
      val a = ni()
      val b = ni()
      val c = ni()

      var ans = Long.MaxValue
      val ansA = Array.ofDim[Long](3)

      1 to 2 * a foreach { f =>
        var u = Math.abs(f - a)
        0 to 2 * b by f filter(f<=) foreach { g =>
          val x = c / g
          val v = if(x * g >= b) Math.min(Math.abs(x*g-c), Math.abs((x+1)*g - c)) else if((x+1)*g >= b) Math.abs((x+1)*g - c) else -1
          if(v > -1) {
            val p =u+ Math.abs(g - b) + v
            if(p < ans) {
              ans = p
              ansA(0) = f
              ansA(1) = g
              ansA(2) = if(Math.abs(x*g - c) == v) x*g else (x+1)*g
            }
          }
        }
      }
      out.println(ans)
      out.println(ansA.mkString(" "))
    }
  }
}


The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations.

The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106.

Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.

import scala.math
object C {
  def main(args: Array[String]) {
    val s0 = readLine()
    val s1 = readLine();
    if (s1.length() != s0.length() || math.min(s1.length, s0.length) < 0 || (!s1.contains("1") && s0.contains("1")) || (!s0.contains("1") && s1.contains("1"))) {
      println("NO")
      return;
    }
    println("YES");
  }
}

object Main {
  def main(args: Array[String]) {
    val s1 = readLine()
    val s2 = readLine()

    val zero1 = s1.count(_ == '0') == s1.size
    val zero2 = s2.count(_ == '0') == s2.size

    if(s1.size != s2.size || zero1 != zero2) println("NO")
    else println("YES")
  }
}

object CF173Div2C {
  def main(args: Array[String]){
    val a = readLine
    val b = readLine
    val res = {
      if(a==b) "YES"
      else if(a.length != b.length) "NO"
      else if(!a.contains('1') || !b.contains('1')) "NO"
      else "YES"
    }
    println(res)
  }
}

object C {
  def main(args: Array[String]) {
    val s0 = readLine()
    val s1 = readLine();
    if (s1.length() != s0.length() || (!s1.contains("1") && s0.contains("1"))) {
      println("NO")
      return;
    }
    println("YES");
  }
}


Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations.Initially, there are $$$n$$$ superheroes in avengers team having powers $$$a_1, a_2, \ldots, a_n$$$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $$$1$$$. They can do at most $$$m$$$ operations. Also, on a particular superhero at most $$$k$$$ operations can be done.Can you help the avengers team to maximize the average power of their crew?

The first line contains three integers $$$n$$$, $$$k$$$ and $$$m$$$ ($$$1 \le n \le 10^{5}$$$, $$$1 \le k \le 10^{5}$$$, $$$1 \le m \le 10^{7}$$$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^{6}$$$) — the initial powers of the superheroes in the cast of avengers.

Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$$$.

NoteIn the first example, the maximum average is obtained by deleting the first element and increasing the second element four times.In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $$$2$$$ each.

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

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

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

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

  def solve(): Unit = {
    val N, K, M = ni()
    val A = na(N)
    sort(A)
    val cum = cumSum(A)

//    debug(cum)

    var ans = cum(N).toDouble / N
    REP(N) { i =>
      // i人削除
      val num = N - i
      val remain = M - i // 削除後の残り

//      debug(s"$i $num $remain")

      if (remain >= 0) {
        val add = min(remain, num.toLong * K)
//        debug(s"$i $num $remain")
        val sum = cum(N) - cum(i)
        val v = (sum + add).toDouble / num
        ans = max(v, ans)
      }
    }

    out.println(f"$ans%.10f")
  }

  def sort(a: Array[Int]): Array[Int] = {
    val n = a.length
    REP(n) { i =>
      val j = scala.util.Random.nextInt(n - i) + i
      val tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
    }
    Sorting.stableSort(a)
    a
  }

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

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

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

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

  def debug(num: Long): Unit = {
    System.err.println(num)
  }

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

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

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

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

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

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


Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters.To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions.

The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.

Print a single number — the least number of actions needed to make the message fancy.

object Solution {
  def main(args: Array[String]) {
    val a = readLine()
    val toUpper = new Array[Int](a.length)
    val toLower = new Array[Int](a.length)
    toUpper(0) = if (a(0).isLower) 1 else 0
    for (i <- 1 to (a.length-1)) {
      toUpper(i) = if (a(i).isLower) toUpper(i - 1) + 1 else toUpper(i - 1)
    }
    toLower(a.length-1) = if (a(a.length-1).isUpper) 1 else 0
    for (i <- (a.length-2) to 0 by -1) {
      toLower(i) = if (a(i).isUpper) toLower(i + 1) + 1 else toLower(i + 1)
    }

    var ans = 1000000
    for (i <- 0 to a.length) {
      var target =
      if (0 == a.length - 1) {
        math.min(toLower(0), toUpper(0))
      }
      else if (i == 0) {
        toLower(0)
      } else if (i == a.length) {
        toUpper(i-1)
      } else {
        toLower(i) + toUpper(i-1)
      }

      if (ans > target) {
        ans = target
      }
    }

    // println(toUpper.mkString(", "))
    // println(toLower.mkString(", "))
    println(ans)
  }
}

object Solution {
  def main(args: Array[String]) {
    val a = readLine()
    val toUpper = new Array[Int](a.length)
    val toLower = new Array[Int](a.length)
    toUpper(0) = if (a(0).isLower) 1 else 0
    for (i <- 1 to (a.length-1)) {
      toUpper(i) = if (a(i).isLower) toUpper(i - 1) + 1 else toUpper(i - 1)
    }
    toLower(a.length-1) = if (a(a.length-1).isUpper) 1 else 0
    for (i <- (a.length-2) to 0 by -1) {
      toLower(i) = if (a(i).isUpper) toLower(i + 1) + 1 else toLower(i + 1)
    }

    var ans = 1000000
    for (i <- 0 to a.length-1) {
      var target =
      if (0 == a.length - 1) {
        math.min(toLower(0), toUpper(0))
      }
      else if (i == 0) {
        toLower(0)
      } else if (i == a.length - 1) {
        toUpper(i)
      } else {
        toLower(i) + toUpper(i-1)
      }

      if (ans > target) {
        ans = target
      }
    }

    // println(toUpper.mkString(", "))
    // println(toLower.mkString(", "))
    println(ans)
  }
}

object Solution {
  def main(args: Array[String]) {
    val a = readLine()
    val toUpper = new Array[Int](a.length)
    val toLower = new Array[Int](a.length)
    toUpper(0) = if (a(0).isLower) 1 else 0
    for (i <- 1 to (a.length-1)) {
      toUpper(i) = if (a(i).isLower) toUpper(i - 1) + 1 else toUpper(i - 1)
    }
    toLower(a.length-1) = if (a(a.length-1).isUpper) 1 else 0
    for (i <- (a.length-2) to 0 by -1) {
      toLower(i) = if (a(i).isUpper) toLower(i + 1) + 1 else toLower(i + 1)
    }

    var ans = 1000000
    for (i <- 0 to a.length-1) {
      var target =
      if (0 == a.length - 1) {
        math.min(toLower(0), toUpper(0))
      }
      else if (i == 0) {
        toLower(0)
      } else if (i == a.length) {
        toUpper(i-1)
      } else {
        toLower(i) + toUpper(i-1)
      }

      if (ans > target) {
        ans = target
      }
    }

    // println(toUpper.mkString(", "))
    // println(toLower.mkString(", "))
    println(ans)
  }
}

object Solution {
  def main(args: Array[String]) {
    val a = readLine()
    val toUpper = new Array[Int](a.length)
    val toLower = new Array[Int](a.length)
    toUpper(0) = if (a(0).isLower) 1 else 0
    for (i <- 1 to (a.length-1)) {
      toUpper(i) = if (a(i).isLower) toUpper(i - 1) + 1 else toUpper(i - 1)
    }
    toLower(a.length-1) = if (a(a.length-1).isUpper) 1 else 0
    for (i <- (a.length-2) to 0 by -1) {
      toLower(i) = if (a(i).isUpper) toLower(i + 1) + 1 else toLower(i + 1)
    }

    var ans = 1000000
    for (i <- 0 to a.length-1) {
      var target =
      if (i == 0) {
        toLower(0)
      } else if (i == a.length - 1) {
        toUpper(i)
      } else {
        toLower(i) + toUpper(i-1)
      }

      if (ans > target) {
        ans = target
      }
    }

    // println(toUpper.mkString(", "))
    // println(toLower.mkString(", "))
    println(ans)
  }
}

object Solution {
  def main(args: Array[String]) {
    val a = readLine()
    val toUpper = new Array[Int](a.length)
    val toLower = new Array[Int](a.length)
    toUpper(0) = if (a(0).isLower) 1 else 0
    for (i <- 1 to (a.length-1)) {
      toUpper(i) = if (a(i).isLower) toUpper(i - 1) + 1 else toUpper(i - 1)
    }
    toLower(a.length-1) = if (a(a.length-1).isUpper) 1 else 0
    for (i <- (a.length-2) to 0 by -1) {
      toLower(i) = if (a(i).isUpper) toLower(i + 1) + 1 else toLower(i + 1)
    }

    var ans = 1000000
    for (i <- 0 to a.length-1) {
      var target =
      if (i == 0) {
        toUpper(0)
      } else if (i == a.length - 1) {
        toLower(i)
      } else {
        toLower(i) + toUpper(i-1)
      }

      if (ans > target) {
        ans = target
      }
    }

    // println(toUpper.mkString(", "))
    // println(toLower.mkString(", "))
    println(ans)
  }
}


Kuznecov likes art, poetry, and music. And strings consisting of lowercase English letters.Recently, Kuznecov has found two strings, $$$a$$$ and $$$b$$$, of lengths $$$n$$$ and $$$m$$$ respectively. They consist of lowercase English letters and no character is contained in both strings. Let another string $$$c$$$ be initially empty. Kuznecov can do the following two types of operations:  Choose any character from the string $$$a$$$, remove it from $$$a$$$, and add it to the end of $$$c$$$.  Choose any character from the string $$$b$$$, remove it from $$$b$$$, and add it to the end of $$$c$$$. But, he can not do more than $$$k$$$ operations of the same type in a row. He must perform operations until either $$$a$$$ or $$$b$$$ becomes empty. What is the lexicographically smallest possible value of $$$c$$$ after he finishes?A string $$$x$$$ is lexicographically smaller than a string $$$y$$$ if and only if one of the following holds: $$$x$$$ is a prefix of $$$y$$$, but $$$x \neq y$$$;  in the first position where $$$x$$$ and $$$y$$$ differ, the string $$$x$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$y$$$.

There are several test cases in the input data. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. This is followed by the test cases description. The first line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1\leq n,m,k \leq 100$$$) — parameters from the statement. The second line of each test case contains the string $$$a$$$ of length $$$n$$$. The third line of each test case contains the string $$$b$$$ of length $$$m$$$.  The strings contain only lowercase English letters. It is guaranteed that no symbol appears in $$$a$$$ and $$$b$$$ simultaneously.

In each test case, output a single string $$$c$$$ — the answer to the problem.

3

6 4 2

aaaaaa

bbbb

5 9 3

caaca

bedededeb

7 7 1

noskill

wxhtzdy

NoteIn the first test case, it is optimal to take two 'a's from the string $$$a$$$ and add them to the string $$$c$$$. Then it is forbidden to take more characters from $$$a$$$, hence one character 'b' from the string $$$b$$$ has to be taken. Following that logic, we end up with $$$c$$$ being 'aabaabaa' when string $$$a$$$ is emptied.In the second test case it is optimal to take as many 'a's from string $$$a$$$ as possible, then take as many 'b's as possible from string $$$b$$$. In the end, we take two 'c's from the string $$$a$$$ emptying it.

object Solution {
  import java.io.PrintWriter
  import java.util.logging.{Level, Logger}
  import scala.io.StdIn
  def getSolution(size: Int, strOne: String, strTwo: String): String = {
    val lenA = 6
    val lenB = 4
    //val size = 2

    // passes -> result:aabaabaa
    //var strA = "aaaaaa".sortWith(_ < _)
    //var strB = "bbbb".sortWith(_ < _)
    //val size = 2

    //var strA = "caaca".sortWith(_ < _)
    //var strB = "bedededeb".sortWith(_ < _)println
    //val size = 3
    val logger = Logger.getGlobal
//    logger.setLevel(Level.INFO)
    logger.setLevel(Level.OFF)
    var strA = strOne.sortWith(_ < _)
    var strB = strTwo.sortWith(_ < _)

    //result = "aabaabaa

    var takenFromA = 0
    var takenFromB = 0
    var result = ""
    while(strA != "" && strB != "") {
      logger.info("=============================")
      logger.info("result:" + result)
      if(takenFromB != size && takenFromA != size) {
        logger.info("taken size is not exceeded")
        logger.info("takenFromA: " + takenFromA)
        logger.info("takenFromB: " + takenFromB)
        logger.info("strA: " + strA)
        logger.info("strB: " + strB)
        if (strA(0) < strB(0)) {
          logger.info("taking from A")
          result = result + strA(0)
          strA = strA.drop(1)
          takenFromA = takenFromA + 1
          takenFromB = 0
        } else {
          logger.info("taking from B")
          result = result + strB(0)
          strB = strB.drop(1)
          takenFromB = takenFromB + 1
          takenFromA = 0
        }
      } else {
        logger.info("!taken size for one string is exceeded")
        var once = false
        if(takenFromB == size) {
          logger.info("resetting B")
          result = result + strA(0)
          strA = strA.drop(1)
          takenFromA = takenFromA + 1
          takenFromB = 0
          once = true
        }
        if (takenFromA == size && !once) {
          logger.info("resetting A")
          result = result + strB(0)
          strB = strB.drop(1)
          takenFromB = takenFromB + 1
          takenFromA = 0
        }
      }

    }
    result
  }

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

    for (i <- 0 until N) {
      val size = StdIn.readLine().split(" ")(2).toInt
      val strOne = StdIn.readLine
      val strTwo = StdIn.readLine

      println(getSolution(size, strOne, strTwo))
    }
  }
}

object Solution {
  import java.io.PrintWriter
  import java.util.logging.{Level, Logger}
  import scala.io.StdIn
  def getSolution(size: Int, strOne: String, strTwo: String): String = {
    val lenA = 6
    val lenB = 4
    //val size = 2

    // passes -> result:aabaabaa
    //var strA = "aaaaaa".sortWith(_ < _)
    //var strB = "bbbb".sortWith(_ < _)
    //val size = 2

    //var strA = "caaca".sortWith(_ < _)
    //var strB = "bedededeb".sortWith(_ < _)println
    //val size = 3
    val logger = Logger.getGlobal
//    logger.setLevel(Level.INFO)
    logger.setLevel(Level.OFF)
    var strA = strOne.sortWith(_ < _)
    var strB = strTwo.sortWith(_ < _)

    //result = "aabaabaa

    var takenFromA = 0
    var takenFromB = 0
    var result = ""
    while(strA != "" && strB != "") {
      logger.info("=============================")
      logger.info("result:" + result)
      if(takenFromB != size && takenFromA != size) {
        logger.info("taken size is not exceeded")
        logger.info("takenFromA: " + takenFromA)
        logger.info("takenFromB: " + takenFromB)
        logger.info("strA: " + strA)
        logger.info("strB: " + strB)
        if (strA(0) < strB(0)) {
          logger.info("taking from A")
          result = result + strA(0)
          strA = strA.drop(1)
          takenFromA = takenFromA + 1
          takenFromB = 0
        } else {
          logger.info("taking from B")
          result = result + strB(0)
          strB = strB.drop(1)
          takenFromB = takenFromB + 1
          takenFromA = 0
        }
      } else {
        logger.info("!taken size for one string is exceeded")
        var once = false
        if(takenFromB == size) {
          logger.info("resetting B")
          result = result + strA(0)
          strA = strA.drop(1)
          takenFromA = takenFromA + 1
          takenFromB = 0
          once = true
        }
        if (takenFromA == size && !once) {
          logger.info("resetting A")
          result = result + strB(0)
          strB = strB.drop(1)
          takenFromB = takenFromB + 1
          takenFromA = 0
        }
      }

    }
    result
  }

  def main(args: Array[String]) {
    println("started")
    val N = StdIn.readLine().toInt

    for (i <- 0 until N) {
      val size = StdIn.readLine().split(" ")(2).toInt
      val strOne = StdIn.readLine
      val strTwo = StdIn.readLine

      println(getSolution(size, strOne, strTwo))
    }
  }
}

object Solution {
  import java.io.PrintWriter
  import java.util.logging.{Level, Logger}
  import scala.io.StdIn

  def getSolution(size: Int, strOne: String, strTwo: String): String = {
    val lenA = 6
    val lenB = 4

    val logger = Logger.getGlobal
    //logger.setLevel(Level.INFO)
    logger.setLevel(Level.OFF)
    var strA = strOne.sortWith(_ < _)
    var strB = strTwo.sortWith(_ < _)

    var takenFromA = 0
    var takenFromB = 0
    var result = ""
    while(strA != "" && strB != "") {
      logger.info("=============================")
      logger.info("result:" + result)
      if(takenFromB != size && takenFromA != size) {
        logger.info("taken size is not exceeded")
        logger.info("takenFromA: " + takenFromA)
        logger.info("takenFromB: " + takenFromB)
        logger.info("strA: " + strA)
        logger.info("strB: " + strB)
        if (strA(0) < strB(0)) {
          logger.info("taking from A")
          result = result + strA(0)
          strA = strA.drop(1)
          takenFromA = takenFromA + 1
          takenFromB = 0
        } else {
          logger.info("taking from B")
          result = result + strB(0)
          strB = strB.drop(1)
          takenFromB = takenFromB + 1
          takenFromA = 0
        }
      } else {
        logger.info("!taken size for one string is exceeded")
        var once = false
        if(takenFromB == size) {
          logger.info("resetting B")
          result = result + strA(0)
          strA = strA.drop(1)
          takenFromA = takenFromA + 1
          takenFromB = 0
          once = true
        }
        if (takenFromA == size) {
          logger.info("resetting A")
          result = result + strB(0)
          strB = strB.drop(1)
          takenFromB = takenFromB + 1
          takenFromA = 0
        }
      }

    }
    result
  }

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

    for (i <- 0 until N) {
      val size = StdIn.readLine().split(" ")(2).toInt
      val strOne = StdIn.readLine
      val strTwo = StdIn.readLine

      println(getSolution(size, strOne, strTwo))
    }
  }
}

object Solution {
  import java.io.PrintWriter
  import java.util.logging.{Level, Logger}
  import scala.io.StdIn

  def getSolution(size: Int, strOne: String, strTwo: String): String = {
    val lenA = 6
    val lenB = 4

    val logger = Logger.getGlobal
    //logger.setLevel(Level.INFO)
    logger.setLevel(Level.OFF)
    var strA = strOne.sortWith(_ < _)
    var strB = strTwo.sortWith(_ < _)

    var takenFromA = 0
    var takenFromB = 0
    var result = ""
    while(strA != "" && strB != "") {
      logger.info("=============================")
      logger.info("result:" + result)
      if(takenFromB != size && takenFromA != size) {
        logger.info("taken size is not exceeded")
        logger.info("takenFromA: " + takenFromA)
        logger.info("takenFromB: " + takenFromB)
        logger.info("strA: " + strA)
        logger.info("strB: " + strB)
        if (strA(0) < strB(0)) {
          logger.info("taking from A")
          result = result + strA(0)
          strA = strA.drop(1)
          takenFromA = takenFromA + 1
          takenFromB = 0
        } else {
          logger.info("taking from B")
          result = result + strB(0)
          strB = strB.drop(1)
          takenFromB = takenFromB + 1
          takenFromA = 0
        }
      } else {
        logger.info("!taken size for one string is exceeded")
        if(takenFromB == size) {
          logger.info("resetting B")
          result = result + strA(0)
          strA = strA.drop(1)
          takenFromA = takenFromA + 1
          takenFromB = 0
        }
        if (takenFromA == size) {
          logger.info("resetting A")
          result = result + strB(0)
          strB = strB.drop(1)
          takenFromB = takenFromB + 1
          takenFromA = 0
        }
      }

    }
    result
  }

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

    for (i <- 0 until N) {
      val size = StdIn.readLine().split(" ")(2).toInt
      val strOne = StdIn.readLine
      val strTwo = StdIn.readLine

      println(getSolution(size, strOne, strTwo))
    }
  }
}


In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so.

The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns.

Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output  - 1.

NoteIn the first sample, the train can take the route  and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.

object A601 {

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

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readInts(2)
    val graph = Array.fill(n)(cu.Set.empty[Int])
    for (_ <- 1 to m) {
      val Array(x, y) = readInts(2).map(_ - 1)
      graph(x).add(y)
      graph(y).add(x)
    }
    val isTrainDone = graph(0).contains(n - 1)
    var res = -1

    def canVisit(top: Int) = {
      if (isTrainDone) {
        (0 until n).filter(_ != top).toSet.diff(graph(top))
      } else {
        graph(top)
      }
    }

    val q = cu.Queue.empty[Int]
    val vis = Array.fill(n)(false)
    val dist = Array.fill(n)(0)
    q.enqueue(0)
    var curr = 0
    while (q.nonEmpty && res == -1) {
      curr += 1
      val top = q.dequeue()
      val connections = canVisit(top)
      for (edge <- connections) {
        if (!vis(edge)) {
          vis(edge) = true
          dist(edge) = dist(top) + 1
          if (edge == n - 1 && res == -1) {
            res = dist(edge)
          } else {
            q.enqueue(edge)
          }
        }
      }
    }
    out.println(res)
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(
      new java.io.InputStreamReader(
        if (System.getProperty("ONLINE_JUDGE") != null) System.in
        else new java.io.FileInputStream("src/input")
      )
    )
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

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

    def readInt: Int = tokenizeLine.nextToken.toInt

    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.collection.mutable

object Solution extends App {

  def bfs(iron: Array[mutable.Set[Int]], isIron: Boolean): Int = {
    val n = iron.length - 1
    val marked = Array.ofDim[Boolean](n + 1)
    marked(1) = true
    var fringe = List(1)
    var count = 0
    while (fringe.nonEmpty) {
      var newFringe = List.empty[Int]
      fringe.foreach { i =>
        if (i == n)
          return count
        else {
          if (isIron) {
            iron(i).foreach{ j =>
              if (!marked(j)) {
                marked(j) = true
                newFringe ::= j
              }
            }
          } else {
            (1 to n).foreach { j =>
              if (!iron(i).contains(j) && !marked(j)) {
                marked(j) = true
                newFringe ::= j
              }
            }
          }
        }
      }
      count += 1
      fringe = newFringe
    }
    -1
  }

  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(' ').map(_.toInt)
  val iron: Array[mutable.Set[Int]] = Array.fill(n + 1) {scala.collection.mutable.Set.empty[Int]}
  (1 to m).foreach { _ =>
    val Array(u, v) = in.next().split(' ').map(_.toInt)
    iron(u) += v
    iron(v) += u
  }
  println(bfs(iron, !iron(n).contains(1)))
}

object C{
  import scala.collection.mutable.Queue
  //import scala.collection.mutable.ArrayBuffer
  import util.control.Breaks._
  import java.io.{PrintWriter,InputStream,BufferedReader,InputStreamReader}
  import java.util.{Locale, Scanner,StringTokenizer}
  class InputReader(val stream:InputStream ) {
    var st:StringTokenizer=new StringTokenizer("")
    val reader=new BufferedReader(new InputStreamReader(stream), 32768);

    def next():String = {
        while (!st.hasMoreTokens()){
          val currentLine = reader.readLine
          st=new StringTokenizer(currentLine)
        }
        return st.nextToken
    }

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

    def nextLong():Long = {
    	return next.toLong
    }
    def nextDouble:Double = {
      return next.toDouble
    }
  }

  def main(args: Array[String]){

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

    def nextInt = in.nextInt
    def nextLong = in.nextLong
    def nextDouble = in.nextDouble
    def nextString = in.next
    //code starts here
    val (n,m)=(nextInt,nextInt)
    val bd=Array.ofDim[Int](n,n)
    for(i<-0 until m){
      val i0=nextInt-1
      val j=nextInt-1
      bd(i0)(j)=1
      bd(j)(i0)=1
    }
    val con=1-bd(0)(n-1)
    //con is the long way
    val q=new Queue[(Int,Int)]
    q+=((0,0))

    var le= -1
    val visited=Array.ofDim[Int](n)
    breakable{
    while(!q.isEmpty){
      val (cn,cl)=q.dequeue

      for(i<-0 until n if i!=cn){
        if(bd(i)(cn)==con){
          if(i==n-1){
            le=cl+1
            break
          }else{
            if(visited(i)==0){
              q+=((i,cl+1))
              visited(i)=1
            }
          }
        }
      }
    }
    }
    out.println(le)
    //code ends here
    out.flush
    out.close
  }
}

object C{
  import scala.collection.mutable.Queue
  //import scala.collection.mutable.ArrayBuffer
  import util.control.Breaks._
  import java.io.{PrintWriter,InputStream,BufferedReader,InputStreamReader}
  import java.util.{Locale, Scanner,StringTokenizer}
  class InputReader(val stream:InputStream ) {
    var st:StringTokenizer=new StringTokenizer("")
    val reader=new BufferedReader(new InputStreamReader(stream), 32768);

    def next():String = {
        while (!st.hasMoreTokens()){
          val currentLine = reader.readLine
          st=new StringTokenizer(currentLine)
        }
        return st.nextToken
    }

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

    def nextLong():Long = {
    	return next.toLong
    }
    def nextDouble:Double = {
      return next.toDouble
    }
  }

  def main(args: Array[String]){

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

    def nextInt = in.nextInt
    def nextLong = in.nextLong
    def nextDouble = in.nextDouble
    def nextString = in.next
    //code starts here
    val (n,m)=(nextInt,nextInt)
    val bd=Array.ofDim[Int](n,n)
    for(i<-0 until m){
      val i0=nextInt-1
      val j=nextInt-1
      bd(i0)(j)=1
      bd(j)(i0)=1
    }
    if(n==400 && m==42944){
      //I don't know why there is memory issue, testing
      out.println("reading finished")
      return
    }
    val con=1-bd(0)(n-1)
    //con is the long way
    val q=new Queue[(Int,Int)]
    q+=((0,0))
    var le= -1
    val visited=Array.ofDim[Int](n)
    breakable{
    while(!q.isEmpty){
      val (cn,cl)=q.dequeue
      //out.println(cn+" "+cl)
      visited(cn)=1
      for(i<-0 until n if i!=cn){
        if(bd(i)(cn)==con){
          if(i==n-1){
            le=cl+1
            break
          }else{
            if(visited(i)==0){
              q+=((i,cl+1))
            }
          }
        }
      }
    }
    }
    out.println(le)
    //code ends here
    out.flush
    out.close
  }
}

object C{
  import scala.collection.mutable.Queue
  //import scala.collection.mutable.ArrayBuffer
  import util.control.Breaks._
  import java.io.{PrintWriter,InputStream,BufferedReader,InputStreamReader}
  import java.util.{Locale, Scanner,StringTokenizer}
  class InputReader(val stream:InputStream ) {
    var st:StringTokenizer=new StringTokenizer("")
    val reader=new BufferedReader(new InputStreamReader(stream), 32768);

    def next():String = {
        while (!st.hasMoreTokens()){
          val currentLine = reader.readLine
          st=new StringTokenizer(currentLine)
        }
        return st.nextToken
    }

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

    def nextLong():Long = {
    	return next.toLong
    }
    def nextDouble:Double = {
      return next.toDouble
    }
  }

  def main(args: Array[String]){

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

    def nextInt = in.nextInt
    def nextLong = in.nextLong
    def nextDouble = in.nextDouble
    def nextString = in.next
    //code starts here
    val (n,m)=(nextInt,nextInt)
    val bd=Array.ofDim[Int](n,n)
    for(i<-0 until m){
      val i0=nextInt-1
      val j=nextInt-1
      bd(i0)(j)=1
      bd(j)(i0)=1
    }
    val con=1-bd(0)(n-1)
    //con is the long way
    val q=new Queue[(Int,Int)]
    q+=((0,0))
    if(n==400 && m==42944){
      //I don't know why there is memory issue, testing
      for(i<-0 until 400){
        q+=((i,i+1))
      }
      out.println("queue finished")
      out.flush
      out.close
      return
    }

    var le= -1
    val visited=Array.ofDim[Int](n)
    breakable{
    while(!q.isEmpty){
      val (cn,cl)=q.dequeue
      //out.println(cn+" "+cl)
      visited(cn)=1
      for(i<-0 until n if i!=cn){
        if(bd(i)(cn)==con){
          if(i==n-1){
            le=cl+1
            break
          }else{
            if(visited(i)==0){
              q+=((i,cl+1))
            }
          }
        }
      }
    }
    }
    out.println(le)
    //code ends here
    out.flush
    out.close
  }
}


In a certain video game, the player controls a hero characterized by a single integer value: power. The hero will have to beat monsters that are also characterized by a single integer value: armor.On the current level, the hero is facing $$$n$$$ caves. To pass the level, the hero must enter all the caves in some order, each cave exactly once, and exit every cave safe and sound. When the hero enters cave $$$i$$$, he will have to fight $$$k_i$$$ monsters in a row: first a monster with armor $$$a_{i, 1}$$$, then a monster with armor $$$a_{i, 2}$$$ and so on, finally, a monster with armor $$$a_{i, k_i}$$$.The hero can beat a monster if and only if the hero's power is strictly greater than the monster's armor. If the hero can't beat the monster he's fighting, the game ends and the player loses. Note that once the hero enters a cave, he can't exit it before he fights all the monsters in it, strictly in the given order.Each time the hero beats a monster, the hero's power increases by $$$1$$$.Find the smallest possible power the hero must start the level with to be able to enter all the caves in some order and beat all the monsters.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of caves. The $$$i$$$-th of the next $$$n$$$ lines contains an integer $$$k_i$$$ ($$$1 \le k_i \le 10^5$$$) — the number of monsters in the $$$i$$$-th cave, followed by $$$k_i$$$ integers $$$a_{i, 1}, a_{i, 2}, \ldots, a_{i, k_i}$$$ ($$$1 \le a_{i, j} \le 10^9$$$) — armor levels of the monsters in cave $$$i$$$ in order the hero has to fight them. It is guaranteed that the sum of $$$k_i$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print a single integer — the smallest possible power the hero must start the level with to be able to enter all the caves in some order and beat all the monsters.

NoteIn the first test case, the hero has to beat a single monster with armor $$$42$$$, it's enough to have power $$$43$$$ to achieve that.In the second test case, the hero can pass the level with initial power $$$13$$$ as follows:   enter cave $$$2$$$:   beat a monster with armor $$$12$$$, power increases to $$$14$$$;  beat a monster with armor $$$11$$$, power increases to $$$15$$$;   enter cave $$$1$$$:   beat a monster with armor $$$10$$$, power increases to $$$16$$$;  beat a monster with armor $$$15$$$, power increases to $$$17$$$;  beat a monster with armor $$$8$$$, power increases to $$$18$$$.

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val caves      = readInt()
    val (power, _) = Array
      .fill(caves) {
        val Array(k, ak @ _*) = readLine().split(" ").map(_.toInt)
        val power             = ak.zipWithIndex.foldLeft(0) { case (power, (ai, i)) => power max (ai - i + 1) }
        (power, k)
      }
      .sorted
      .reduce[(Int, Int)] { case ((a, ak), (b, bk)) => (a max (b - ak), ak + bk) }

    println(power)
  }

}

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val caves      = readInt()
    val (power, _) = Array
      .fill(caves) {
        val Array(k, ak @ _*) = readLine().split(" ").map(_.toInt)
        val power             = ak.zipWithIndex.foldLeft(0) { case (power, (ai, i)) => power max (ai - i + 1) }
        (power, k)
      }
      .sorted
      .reduce[(Int, Int)] {
        case ((a, ak), (b, bk)) if (b > a + ak) => (b - ak, ak + bk)
        case ((a, ak), (b, bk))                 => (a, ak + bk)
      }

    println(power)
  }

}

import java.io._
import java.util.StringTokenizer
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.util.Sorting.quickSort
import util.control.Breaks._

object Solution {
    val writer =  new PrintWriter(System.out)
    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() = next.toInt
    def readLong() = next.toLong
    def readString() = next()
    def readArrayInt(n: Int = 0): Array[Int] = {
        if (n == 0)
            return reader.readLine().split(" ").map(_.toInt)

        val a = new Array[Int](n)
        for (i <- 0 until n) {
            a(i) = readInt()
        }
        a
    }

    def pow(a: Int, b: Int): Long = {
        if (b == 0) return 1

        val rs = pow(a, b / 2)
        rs * rs * (if (b % 2 == 0) 1 else a)
    }

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

    def LCM(a: Int, b: Int): Int = (a / GCD(a,b)) * b

    def root(u: Int, p: Array[Int]): Int = {
        if (p(u) < 0) return u
        p(u) = root(p(u), p)
        p(u)
    }

    def join(u: Int, v: Int, p: Array[Int]): Unit = {
        var x = root(u, p)
        var y = root(v, p)
        if (x == y) return

        if (p(y) < p(x)) {
            val t = x
            x = y
            y = t
        }
        p(x) += p(y)
        p(y) = x
    }

    def solve(t: Int = 0): Unit = {
        val n = readInt()

        val f = new Array[(Int, Int)](n)
        for (i <- 0 until n) {
            val k = readInt()
            var max = -Int.MaxValue
            for (j <- 0 until k) {
                val a = readInt()
                val b = a - j + 1
                max = Math.max(b, max)
            }
            f(i) = ((max, max + k))
        }

        quickSort[(Int, Int)](f)(Ordering.by[(Int, Int), Int](_._1))

        var l = f(0)._1
        var r = f(0)._2
        for (i <- 1 until n) {
            if (f(i)._1 <= r) {
                r += f(i)._2 - f(i)._1
            } else {
                l += f(i)._1 - r
                r = f(i)._2
            }
        }

        writer.println(l)
    }

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

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

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val caves      = readInt()
    val (power, _) = Array
      .fill(caves) {
        val Array(k, ak @ _*) = readLine().split(" ").map(_.toInt)
        val power             = ak.zipWithIndex.foldLeft(0) { case (power, (ai, i)) => power max (ai - i + 1) }
        (power, k)
      }
      .sorted
      .reduce[(Int, Int)] {
        case ((a, ak), (b, bk)) if (b > a + ak) => (b - ak, bk)
        case ((a, ak), (b, bk))                 => (a, ak + bk)
      }

    println(power)
  }

}

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val caves      = readInt()
    val (power, _) = Array
      .fill(caves) {
        val Array(k, ak @ _*) = readLine().split(" ").map(_.toInt)
        val power             = ak.zipWithIndex.foldLeft(0) { case (power, (ai, i)) => power max (ai - i + 1) }
        (power, power + k)
      }
      .sorted
      .reduce[(Int, Int)] {
        case ((a1, a2), (b1, b2)) if (b1 > a2) => (b1 - (a2 - a1), b1 - (a2 - a1) + (b2 - b1))
        case ((a1, _), (_, b2))                => (a1, b2)
      }

    println(power)
  }

}

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val caves      = readInt()
    val (power, _) = Array
      .fill(caves) {
        val Array(k, ak @ _*) = readLine().split(" ").map(_.toInt)
        val power             = ak.zipWithIndex.foldLeft(0) { case (power, (ai, i)) => power max (ai - i + 1) }
        (power, power + k)
      }
      .sorted
      .reduce[(Int, Int)] {
        case ((_, a2), (b1, b2)) if (b1 > a2) => (b1, b2)
        case ((a1, _), (_, b2))               => (a1, b2)
      }

    println(power)
  }

}

import java.io._
import java.util.StringTokenizer
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.util.Sorting.quickSort
import util.control.Breaks._

object Solution {
    val writer =  new PrintWriter(System.out)
    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() = next.toInt
    def readLong() = next.toLong
    def readString() = next()
    def readArrayInt(n: Int = 0): Array[Int] = {
        if (n == 0)
            return reader.readLine().split(" ").map(_.toInt)

        val a = new Array[Int](n)
        for (i <- 0 until n) {
            a(i) = readInt()
        }
        a
    }

    def pow(a: Int, b: Int): Long = {
        if (b == 0) return 1

        val rs = pow(a, b / 2)
        rs * rs * (if (b % 2 == 0) 1 else a)
    }

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

    def LCM(a: Int, b: Int): Int = (a / GCD(a,b)) * b

    def root(u: Int, p: Array[Int]): Int = {
        if (p(u) < 0) return u
        p(u) = root(p(u), p)
        p(u)
    }

    def join(u: Int, v: Int, p: Array[Int]): Unit = {
        var x = root(u, p)
        var y = root(v, p)
        if (x == y) return

        if (p(y) < p(x)) {
            val t = x
            x = y
            y = t
        }
        p(x) += p(y)
        p(y) = x
    }

    def solve(t: Int = 0): Unit = {
        val n = readInt()

        val f = new Array[(Int, Int)](n)
        for (i <- 0 until n) {
            val k = readInt()
            var max = -Int.MaxValue
            for (j <- 0 until k) {
                val a = readInt()
                val b = a - j + 1
                max = Math.max(b, max)
            }
            f(i) = ((max, max + k))
        }

        quickSort[(Int, Int)](f)(Ordering.by[(Int, Int), Int](_._1))

        var l = f(0)._1
        var r = f(0)._2
        for (i <- 1 until n) {
            if (f(i)._1 <= r) {
                r += f(i)._2 - f(i)._1
            } else {
                l += f(i)._1 - r
                r += f(i)._2
            }
        }

        writer.println(l)
    }

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

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


You are given an array $$$a$$$ consisting of $$$n$$$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0.You may choose at most one consecutive subarray of $$$a$$$ and multiply all values contained in this subarray by $$$x$$$. You want to maximize the beauty of array after applying at most one such operation.

The first line contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 3 \cdot 10^5, -100 \le x \le 100$$$) — the length of array $$$a$$$ and the integer $$$x$$$ respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$) — the array $$$a$$$.

Print one integer — the maximum possible beauty of array $$$a$$$ after multiplying all values belonging to some consecutive subarray $$$x$$$.

NoteIn the first test case we need to multiply the subarray [-2, 1, -6], and the array becomes [-3, 8, 4, -2, 12] with beauty 22 ([-3, 8, 4, -2, 12]).In the second test case we don't need to multiply any subarray at all.In the third test case no matter which subarray we multiply, the beauty of array will be equal to 0.

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

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

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

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

  def solve(): Unit = {
    val N, X = ni()
    val A = nal(N)
    val B = Array.ofDim[Long](N)
    REP(N) { i =>
      B(i) = A(i) * X
    }
    val R = calcLRMax(B, A)
    val L = calcLRMax(B.reverse, A.reverse).reverse

    debug("L")
    debug(L)
    debug("R")
    debug(R)

    var ans = 0L
    REP(N) { i =>
      val v = R(i) + (if (i > 0) L(i - 1) else 0)
      ans = max(ans, v)
    }

    out.println(ans)
  }

  /**
    * LRの形を作る場合の、[i, j) {i <= j <= N} の範囲のsumの最大値
    */
  def calcLRMax(L: Array[Long], R: Array[Long]): Array[Long] = {
    val n = L.length
    val dp = Array.ofDim[Long](2, n + 1) // 0: L, 1: R
    REP_r(n) { i =>
      val ll = L(i) + dp(0)(i + 1)  // L + L
      val lr = L(i) + dp(1)(i + 1)  // L + R
      val l = L(i) // L + 0
      dp(0)(i) = max(max(ll, lr), l)
      val rr = R(i) + dp(1)(i + 1) // R + R
      val r = R(i) // R + 0
      dp(1)(i) = max(rr, r)
    }
    val A = Array.ofDim[Long](n)
    REP(n) { i =>
      // 0, L, R
      A(i) = max(0, max(dp(0)(i), dp(1)(i)))
    }
    A
  }

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

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

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

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

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

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

  def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }

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

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

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

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

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

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

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

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

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

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

  def solve(): Unit = {
    val N, X = ni()
    val A = nal(N)
    val B = Array.ofDim[Long](N)
    REP(N) { i =>
      B(i) = A(i) * X
    }

    // iから連続した部分列を足した時に、一番大きくなる値
    def mkMax(as: Array[Long]): Array[Long] = {
      val cum = cumSum(as)
      val res = Array.ofDim[Long](as.length)
      var mx = cum.last
      REP_r(as.length) { i =>
        mx = max(mx, cum(i + 1))
        res(i) = mx - cum(i)
      }
      res
    }

    def maxSubSum(as: Array[Long]): Long = {
      var ms = 0L
      var sum = 0L
      var res = 0L
      REP(as.length) { i =>
        sum += as(i)
        ms = min(ms, sum)
        res = max(res, sum - ms)
      }
      res
    }

    debug(s"maxSubSumA:${maxSubSum(A)} maxSubSumB:${maxSubSum(B)}")

    // ループで両端が0のケースをカバーしてないのでここでやる
    var ans = max(maxSubSum(A), maxSubSum(B))

    val max_A_R = mkMax(A)
    reverse(A)
    val max_A_L = mkMax(A)
    reverse(max_A_L)
    val max_B_R = mkMax(B)
    reverse(B)
    val max_B_L = mkMax(B)
    reverse(max_B_L)

    debug(max_A_R)
    debug(max_A_L)
    debug(max_B_R)
    debug(max_B_L)

    // 両端を必ず含む
    TO(0, N - 2) { i =>
      val ba = max_A_R(i + 1) + max_B_L(i)
      val ab = max_A_L(i) + max_B_R(i + 1)
      debug(s"i:$i ab:$ab ba:$ba")
      ans = max(ans, max(ba, ab))
    }

    out.println(ans)
  }

  def reverse(as: Array[Long]): Unit = {
    REP(as.length / 2) { i =>
      val t = as(i)
      as(i) = as(as.length - 1 - i)
      as(as.length - 1 - i) = t
    }
  }

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

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

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

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

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

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

  def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }

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

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

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

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

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

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

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

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

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

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

  def solve(): Unit = {
    val N, X = ni()
    val A = nal(N)
    val B = Array.ofDim[Long](N)
    REP(N) { i =>
      B(i) = A(i) * X
    }

    // Bにした方が得な度合い
    val C = Array.ofDim[Long](N)
    REP(N) { i =>
      C(i) = B(i) - A(i)
    }

    debug(C)

    def maxSubSum(as: Array[Long]): (Int, Int) = {
      var sum = 0L
      var ms = 0L
      var mx = 0L
      var ms_ix = -1
      var ans: (Int, Int) = (-1, -1)
      REP(as.length) { i =>
        sum += as(i)
        if (sum < ms) {
          ms = sum
          ms_ix = i
        }
        if (sum - ms > mx) {
          mx = sum - ms
          ans = (ms_ix + 1, i)
        }
      }
      ans
    }

    debug(maxSubSum(C).toString)

    var ans = 0L
    val (bl, br) = maxSubSum(C)
    // ABAのケース
    if (bl != -1 && br != -1) {
      TO(bl, br) { i =>
        ans += B(i)
      }

      debug(ans.toString)
      // 両端に広がる
      var rsum = 0L
      var rmax = 0L
      TO(br + 1, N - 1) { i =>
        rsum += A(i)
        rmax = max(rmax, rsum)
      }
      var lsum = 0L
      var lmax = 0L
      REP_r(bl) { i =>
        lsum += A(i)
        lmax = max(lmax, lsum)
      }

      debug(s"lmax:$lmax rmax:$rmax")
      ans += lmax + rmax
    }

    // Bがないケース
    val (al, ar) = maxSubSum(A)
    if (al != -1 && ar != -1) {
      var sum = 0L
      TO(al, ar) { i => sum += A(i) }
      ans = max(ans, sum)
    }

    out.println(ans)
  }

  def reverse(as: Array[Long]): Unit = {
    REP(as.length / 2) { i =>
      val t = as(i)
      as(i) = as(as.length - 1 - i)
      as(as.length - 1 - i) = t
    }
  }

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

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

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

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

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

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

  def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }

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

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

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

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

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

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

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

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

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

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

  def solve(): Unit = {
    val N, X = ni()
    val A = nal(N)
    val B = Array.ofDim[Long](N)
    REP(N) { i =>
      B(i) = A(i) * X
    }

    // Bにした方が得な度合い
    val C = Array.ofDim[Long](N)
    REP(N) { i =>
      C(i) = B(i) - A(i)
    }

    // iから連続した部分列を足した時に、一番大きくなるj
    def mkMax(as: Array[Long]): Array[(Int, Long)] = {
      val cum = cumSum(as)
      val res = Array.ofDim[(Int, Long)](as.length)
      var j = as.length - 1
      REP_r(as.length) { i =>
        if (cum(j + 1) < cum(i + 1)) j = i
        res(i) = (j, cum(j + 1) - cum(i))
      }
      res
    }

    def maxSubSum(as: Array[Long]): Long = {
      var sum = 0L
      var ms = 0L
      var mx = 0L
      REP(as.length) { i =>
        sum += as(i)
        if (sum < ms) {
          ms = sum
        }
        if (sum - ms > mx) {
          mx = sum - ms
        }
      }
      mx
    }

    // Bがない場合
    var ans = maxSubSum(A)

    val max_C = mkMax(C).map(_._1)

    val max_A = mkMax(A).map(_._2)
    reverse(A)
    val max_A_rev = mkMax(A).map(_._2)
    reverse(max_A_rev)
    val cumB = cumSum(B)

    debug(max_A)
    debug(max_A_rev)

    // ABA
    REP(N) { l =>
      val r = max_C(l)
      val la = if (l > 0) max_A_rev(l - 1) else 0
      val ra = if (r < N - 1) max_A(r + 1) else 0
      val b = cumB(r + 1) - cumB(l)
      ans = max(ans, la + b + ra)
    }

    out.println(ans)
  }

  def reverse(as: Array[Long]): Unit = {
    REP(as.length / 2) { i =>
      val t = as(i)
      as(i) = as(as.length - 1 - i)
      as(as.length - 1 - i) = t
    }
  }

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

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

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

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

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

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

  def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }

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

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

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

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

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

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