The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.If $$$x$$$ is the number of passengers in a bus just before the current bus stop and $$$y$$$ is the number of passengers in the bus just after current bus stop, the system records the number $$$y-x$$$. So the system records show how number of passengers changed.The test run was made for single bus and $$$n$$$ bus stops. Thus, the system recorded the sequence of integers $$$a_1, a_2, \dots, a_n$$$ (exactly one number for each bus stop), where $$$a_i$$$ is the record for the bus stop $$$i$$$. The bus stops are numbered from $$$1$$$ to $$$n$$$ in chronological order.Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $$$w$$$ (that is, at any time in the bus there should be from $$$0$$$ to $$$w$$$ passengers inclusive).

The first line contains two integers $$$n$$$ and $$$w$$$ $$$(1 \le n \le 1\,000, 1 \le w \le 10^{9})$$$ — the number of bus stops and the capacity of the bus. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(-10^{6} \le a_i \le 10^{6})$$$, where $$$a_i$$$ equals to the number, which has been recorded by the video system after the $$$i$$$-th bus stop.

Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $$$w$$$. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0.

NoteIn the first example initially in the bus could be $$$0$$$, $$$1$$$ or $$$2$$$ passengers.In the second example initially in the bus could be $$$1$$$, $$$2$$$, $$$3$$$ or $$$4$$$ passengers.In the third example initially in the bus could be $$$0$$$ or $$$1$$$ passenger.

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, W = ni()
    val A = na(N)
    var upper = W
    var lower = 0
    REP(N) { i =>
      upper = min(W, upper + A(i))
      lower = max(0, lower + A(i))
    }
    out.println(max(0, upper - lower + 1))
  }

  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[Long]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

import scala.io.StdIn
object CF978E extends App {
  val Array(n, w) = StdIn.readLine.split(' ').map(_.toInt)
  val as = StdIn.readLine.split(' ').map(_.toInt)
  val passengers = as.scanLeft(0){_+_}
  // x >= -passengers.min
  // x <= w - passengers.max
  val possibilities = (w - passengers.max + passengers.min + 1) max 0
  println(possibilities)
}


Recall that MEX of an array is a minimum non-negative integer that does not belong to the array. Examples:  for the array $$$[0, 0, 1, 0, 2]$$$ MEX equals to $$$3$$$ because numbers $$$0, 1$$$ and $$$2$$$ are presented in the array and $$$3$$$ is the minimum non-negative integer not presented in the array;  for the array $$$[1, 2, 3, 4]$$$ MEX equals to $$$0$$$ because $$$0$$$ is the minimum non-negative integer not presented in the array;  for the array $$$[0, 1, 4, 3]$$$ MEX equals to $$$2$$$ because $$$2$$$ is the minimum non-negative integer not presented in the array. You are given an empty array $$$a=[]$$$ (in other words, a zero-length array). You are also given a positive integer $$$x$$$.You are also given $$$q$$$ queries. The $$$j$$$-th query consists of one integer $$$y_j$$$ and means that you have to append one element $$$y_j$$$ to the array. The array length increases by $$$1$$$ after a query.In one move, you can choose any index $$$i$$$ and set $$$a_i := a_i + x$$$ or $$$a_i := a_i - x$$$ (i.e. increase or decrease any element of the array by $$$x$$$). The only restriction is that $$$a_i$$$ cannot become negative. Since initially the array is empty, you can perform moves only after the first query.You have to maximize the MEX (minimum excluded) of the array if you can perform any number of such operations (you can even perform the operation multiple times with one element).You have to find the answer after each of $$$q$$$ queries (i.e. the $$$j$$$-th answer corresponds to the array of length $$$j$$$).Operations are discarded before each query. I.e. the array $$$a$$$ after the $$$j$$$-th query equals to $$$[y_1, y_2, \dots, y_j]$$$.

The first line of the input contains two integers $$$q, x$$$ ($$$1 \le q, x \le 4 \cdot 10^5$$$) — the number of queries and the value of $$$x$$$. The next $$$q$$$ lines describe queries. The $$$j$$$-th query consists of one integer $$$y_j$$$ ($$$0 \le y_j \le 10^9$$$) and means that you have to append one element $$$y_j$$$ to the array.

Print the answer to the initial problem after each query — for the query $$$j$$$ print the maximum value of MEX after first $$$j$$$ queries. Note that queries are dependent (the array changes after each query) but operations are independent between queries.

NoteIn the first example:  After the first query, the array is $$$a=[0]$$$: you don't need to perform any operations, maximum possible MEX is $$$1$$$.  After the second query, the array is $$$a=[0, 1]$$$: you don't need to perform any operations, maximum possible MEX is $$$2$$$.  After the third query, the array is $$$a=[0, 1, 2]$$$: you don't need to perform any operations, maximum possible MEX is $$$3$$$.  After the fourth query, the array is $$$a=[0, 1, 2, 2]$$$: you don't need to perform any operations, maximum possible MEX is $$$3$$$ (you can't make it greater with operations).  After the fifth query, the array is $$$a=[0, 1, 2, 2, 0]$$$: you can perform $$$a[4] := a[4] + 3 = 3$$$. The array changes to be $$$a=[0, 1, 2, 2, 3]$$$. Now MEX is maximum possible and equals to $$$4$$$.  After the sixth query, the array is $$$a=[0, 1, 2, 2, 0, 0]$$$: you can perform $$$a[4] := a[4] + 3 = 0 + 3 = 3$$$. The array changes to be $$$a=[0, 1, 2, 2, 3, 0]$$$. Now MEX is maximum possible and equals to $$$4$$$.  After the seventh query, the array is $$$a=[0, 1, 2, 2, 0, 0, 10]$$$. You can perform the following operations:   $$$a[3] := a[3] + 3 = 2 + 3 = 5$$$,  $$$a[4] := a[4] + 3 = 0 + 3 = 3$$$,  $$$a[5] := a[5] + 3 = 0 + 3 = 3$$$,  $$$a[5] := a[5] + 3 = 3 + 3 = 6$$$,  $$$a[6] := a[6] - 3 = 10 - 3 = 7$$$,  $$$a[6] := a[6] - 3 = 7 - 3 = 4$$$.  The resulting array will be $$$a=[0, 1, 2, 5, 3, 6, 4]$$$. Now MEX is maximum possible and equals to $$$7$$$.

object Main extends App {
  val stdin = scala.io.Source.stdin.getLines()
  val Array(q, x) = stdin.next().split(' ').map(_.toInt)
  val r = stdin.take(q).map(_.toInt).foldLeft(List[Int] (0), Map.empty[Int, Int]) {
    case((l@(h::xs), map), el)  => // replacements contains temporary elements
     // while replacements contains el -> move replacements to fixed
      val key = el % x
      val nMap = map + (key -> (map.getOrElse(el % x, 0) + 1))
      (solve(h, nMap) :: l, nMap)
  }._1.reverse.tail

  println(r.mkString("\n"))

  def solve(max: Int, map: Map[Int, Int]) = {
//    println(s"max = ${max}")
//    println(s"map = ${map}")
    var res = max;
    while (res < res % x + map.getOrElse(res % x, 0) * x) {
      res += 1
    }
    res
  }
}

//1
//6
//1 1 1 2 2 1 2 1 2 1 1 2

object Main extends App {
  val stdin = scala.io.Source.stdin.getLines()
  val Array(q, x) = stdin.next().split(' ').map(_.toInt)
  val r = stdin.take(q).map(_.toInt).foldLeft(List[Int] (0), Map.empty[Int, Int]) {
    case((l@(h::xs), map), el)  => // replacements contains temporary elements
     // while replacements contains el -> move replacements to fixed
      val key = el % x
      val nMap = map + (key -> (map.getOrElse(el % x, 0) + 1))
      (solve(h, nMap) :: l, nMap)
  }._1.reverse.tail

//  println(r.mkString("\n"))

  def solve(max: Int, map: Map[Int, Int]) = {
//    println(s"max = ${max}")
//    println(s"map = ${map}")
    var res = max;
    while (res < res % x + map.getOrElse(res % x, 0) * x) {
      res += 1
    }
    res
  }
}

//1
//6
//1 1 1 2 2 1 2 1 2 1 1 2


Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.

The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.

Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.

object P025A {
  def main(args: Array[String]) = {
    val n = readInt
    val a = readLine.split(' ').map(x => x.toInt).map(x => x % 2)
    val parity = if (a.reduceLeft(_ + _) > 1) 0 else 1
    println(a.indexOf((a.filter(x => x % 2 == parity))(0)) + 1)
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val n = readLine()
    val list = readLine().split(" ").map(_.toInt).toList
    val (elist, olist) = list.partition(x => x % 2 == 0)
    if (elist.length <= 1) println(list.indexOf(elist.head) +1) else println(list.indexOf(olist.head) +1)
  }
}

import scala.io.StdIn._

object Main extends App {
  readInt()
  val a = readLine().split(" ").map(_.toInt)
  val (even, odd) = a.zipWithIndex.partition { case (e, _) => e % 2 == 0 }
  val ans = if (even.length == 1) even.head._2 else odd.head._2
  println(ans + 1)
}

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

object CodeForces extends App {

  StdIn.readLine()
  val numbers = StdIn.readLine().split(" ").map(_.toInt)

  val (odd,even) = numbers.partition(_%2==0)
  if (odd.length == 1){
    println(numbers.indexOf(odd.head) + 1)
  }else {
    println(numbers.indexOf(even.head) + 1)
  }

}

object CF0025A extends App {

  val n = readInt()
  val ar = readLine().split(" ").map(_.toInt)

  var pos = 0

  if(ar.filter(_%2 ==0 ).size == n -1) {
    val value = ar.filter(_%2 == 1).head
    (1 to ar.size).foreach(n => {
      if(ar(n-1) == value) {
        pos = n
      }
    })
  } else {
    val value = ar.filter(_%2 == 0).head
    (1 to ar.size).foreach(n => {
      if(ar(n-1) == value) {
        pos = n
      }
    })
  }

  println(pos)

}

object CF025A_IQTest extends App {

  override def main(args: Array[String]): Unit = {
    val in = new java.util.Scanner(System.in)
    val out = new java.io.PrintWriter(System.out)

    def solution(): Unit = {
      val n: Int = in.nextInt()
      var sum: Int = 0
      for (_ <- 0 until 3) {
        sum = (sum << 1) | (in.nextInt() % 2)
      }

      val ind: Int = sum match {
        case sum if (sum == 3 || sum == 4) => 1
        case sum if (sum == 2 || sum == 5) => 2
        case sum if (sum == 1 || sum == 6) => 3
        case _ => {
          val item = sum match {
            case 0 => 1
            case _ => 0
          }

          var t = 0
          for (i <- 4 to n) {
            if (item == (in.nextInt() % 2)) {
              t = i
            }
          }

          t
        }
      }

      out.println(ind)
    }

    try {
      solution()

    } catch {
      case e: Exception => out.println(e.toString)

    } finally {
      out.flush()
      out.close()
    }
  }
}

object CF025A_IQTest extends App {

  class FastReader() {
    val br = new java.io.BufferedReader(
      new java.io.InputStreamReader(System.in))
    var st: java.util.StringTokenizer = null

    def next: String = {
      if (st == null || !st.hasMoreElements) {
        st = new java.util.StringTokenizer(br.readLine)
      }

      st.nextToken
    }

    def nextInt: Int = next.toInt
    def nextLong: Long = next.toLong
    def nextDouble: Double = next.toDouble
    def nextLine: String = br.readLine
  }

  override def main(args: Array[String]): Unit = {
    val in = new FastReader()
    val out = new java.io.PrintWriter(System.out)

    def solution(): Unit = {
      val n = in.nextInt
      var sum = 0
      for (_ <- 0 until 3) {
        sum = (sum << 1) | (in.nextInt % 2)
      }

      val ind = sum match {
        case sum if (sum == 3 || sum == 4) => 1
        case sum if (sum == 2 || sum == 5) => 2
        case sum if (sum == 1 || sum == 6) => 3
        case _ => {
          val item = sum match {
            case 0 => 1
            case _ => 0
          }

          var t = 0
          for (i <- 4 to n) {
            if (item == (in.nextInt % 2)) {
              t = i
            }
          }

          t
        }
      }

      out.println(ind)
    }

    try {
      solution()

    } catch {
      case e: Exception => out.println(e.toString)

    } finally {
      out.flush()
      out.close()
    }
  }
}

import collection.mutable._

object P25A extends App {

    readLine
    val evens, odds = new java.util.LinkedList[(Int,Int)]()

    for (e <- readLine.split(" ").map(_.toInt).zipWithIndex)
        (if(e._1 % 2 == 0) evens else odds).add(e)

    print(Array(evens,odds).minBy(_.size).get(0)._2+1)

}

import java.util.StringTokenizer

object _25A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val a = (1 to n).map(i => next.toInt);
  val odd = a.filter(i => i % 2 == 1)
  val even = a.filter(i => i % 2 == 0)
  val ans = if (odd.size == 1) a.indexOf(odd.head) + 1 else a.indexOf(even.head) + 1
  println(ans)
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(" ").map(_.toInt)
  if (data.count(_ % 2 == 1) == 1)
    println(data.indexOf(data.find(_ % 2 == 1).get) + 1)
  else
    println(data.indexOf(data.find(_ % 2 == 0).get) + 1)
}

object A25 {
  @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 input = readInts(n).zipWithIndex
    val odd = input.filter(_._1 % 2 == 1)
    val even = input.filter(_._1 % 2 == 0)
    if(odd.length == 1) {
      println(odd.head._2 + 1)
    } else {
      println(even.head._2 + 1)
    }
  }
}

object IQ {
  def main(args: Array[String]) {
    val n = io.StdIn.readLine.toInt
    val arr = io.StdIn.readLine.split(" ").map(_.toInt).zipWithIndex
    val evens = arr.filter(_._1 % 2 == 0)
    val odds = arr.filter(_._1 % 2 != 0)
    if (evens.length == 1) println(evens(0)._2 + 1)
    else println(odds(0)._2 + 1)
  }
}

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

object P025A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  val V = List.fill(N)(sc.nextInt)

  val answer = if (V.count(_ % 2 == 1) == 1) (V takeWhile (_ % 2 == 0)).size + 1
               else (V takeWhile (_ % 2 == 1)).size + 1

  out.println(answer)
  out.close
}

object  IQtest {
	def main (args: Array[String]) {
		val scanner = new java.util.Scanner(System.in);
		val n = scanner.nextInt();
		var previousArity = scanner.nextInt() % 2;
		var currentArity = scanner.nextInt() % 2;
		var index = 2;
		while (index <= n && previousArity == currentArity) {
			previousArity = currentArity;
			currentArity = scanner.nextInt() % 2;
			index += 1
		}
		if (index == 2) {
			val nextArity = scanner.nextInt() % 2
					if (nextArity == previousArity)
						println(2);
					else
						println(1);
		}
		else {
			println(index)
		}
	}
}

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

object HelloWorld {

  def main(args: Array[String]): Unit = {
    var n = readInt;
    var evenCount = 0;
    var oddCount = 0;
    var lastEven = 0;
    var lastOdd = 0;
    var arr = readLine.split(" ").map(_.toInt);
    for (i <- 0 until arr.length) {
      if (arr(i) % 2 == 0) {
        lastEven = i;
        evenCount += 1;
      } else {
        lastOdd = i;
        oddCount += 1;
      }
    }
    if (evenCount > oddCount) {
      println(lastOdd + 1);
    } else {
      println(lastEven + 1);
    }
  }

}

import annotation.tailrec
import java.io._

object Easy {
  val reader = new BufferedReader(new InputStreamReader(System.in))
  def readInts = reader.readLine().split(" ").map(_.toInt)
  def readInt = reader.readLine().toInt

  val n = readInt
  val a = readInts
  val foo = a.groupBy(_ % 2).mapValues(_.length)
  def ans = (a zip (1 to n)).filter(x => foo(x._1 % 2) == 1).map(_._2)

  def main(args: Array[String]) {
    println(ans.mkString)
  }
}

object Main {
  def main(args: Array[String]) {
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val map = a.zipWithIndex.groupBy(_._1 % 2)
    if (map(1).size == 1) println(map(1)(0)._2 + 1)
    else println(map(0)(0)._2 + 1)
  }
}

import scala.io._

object main {

  def solution(n: Int) = {
    val input = StdIn.readLine().split(' ').map(_.toInt)
    val groups = input.groupBy(_ % 2 == 0)

    val (evns, odds) =
      (groups(true), groups(false))

    val number = if (evns.length > odds.length)
      odds.last else evns.last

    var i = 0
    var ans = 0

    while (i < input.length) {
      if (input(i) == number)
        ans = i
      i += 1
    }

    ans + 1
  }

  def run() = {
    val n = StdIn.readInt()
    val ans = solution(n)

    println(ans)
  }

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

}

import scala.io.StdIn.readLine
import scala.io.StdIn.readInt

object IQTest {

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

   def readLongs() : Array[Long] =
      readLine.split(' ').map(_.toLong)

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

   def readTriple() : (Int,Int,Int) = {
     val line = readInts
     (line(0),line(1),line(2))
   }
   def readQuad() : (Int,Int,Int,Int) = {
     val line = readInts
     (line(0),line(1),line(2),line(3))
   }

   def main(args: Array[String]) {
     val n = readInt
     val as = readInts
     if (as.count { _ % 2 == 0 } > 1) {
       println(as.indexWhere(_ % 2 == 1) + 1)
     } else {
       println(as.indexWhere(_ % 2 == 0) + 1)
     }

   }

}

import java.io._

object Solution extends App {
  val n = readInt

  val a = readLine.split(" ").map(_.toInt)

  if(a.count(_ % 2 == 0) == 1) {
    println(a.indexWhere(_ % 2 == 0) + 1)
  } else {
    println(a.indexWhere(_ % 2 != 0) + 1)
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val n = readLine()
    val list = readLine().split(" ").map(_.toInt).toList
    val (elist, olist) = list.partition(x => x % 2 == 0)
    if (elist.length <= 1) println(list.indexOf(elist.head)) else println(list.indexOf(olist.head))
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val n = readLine()
    val list = readLine().split(" ").map(_.toInt).toList
    val (elist, olist) = list.partition(x => x % 2 == 0)
    if (elist.length <= 1) println(elist.head) else println(olist.head)
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(" ").map(_.toInt)
  if (data.count(_ % 2 == 1) == 1)
    println(data.find(_ % 2 == 1).get)
  else
    println(data.find(_ % 2 == 0).get)
}

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

object P025A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  val V = List.fill(N)(sc.nextInt)

  val v0 = V takeWhile (_ % 2 == 0)
  val v1 = V dropWhile (_ % 2 == 0) takeWhile(_ % 2 == 1)
  val answer = if (v0.size > 0) v0.size + 1
               else v1.size + 1

  out.println(answer)
  out.close
}

object Main {
  def main(args: Array[String]) {
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val map = a.groupBy(_ % 2)
    if (map(1).size == 1) println(map(1)(0))
    else println(map(0)(0))
  }
}

object Main {
  def main(args: Array[String]) {
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val map = a.groupBy(_ % 2)

    println(a)
    if (map(1).size == 1) println(map(1)(0))
    else println(map(0)(0))
  }
}

object Main extends App {

  val n = Console.readInt()
  Console.println(solution(n))

  def solution(n: Int) = {
    var odd = 0
    var even = 0

    var d = 0
    var fOdd = -1
    var fEvn = -1

    val input: Array[String] =
      Console.readLine().split(' ')

    input
      .map(x => x.toInt)
      .foreach(d => {
        if (d % 2 == 0) {
          even += 1
          if (fEvn == -1) fEvn = d
        } else {
          odd += 1
          if (fOdd == -1) fOdd = d
        }
      })

    val ans = if (odd > even) fOdd else fEvn
    ans + 1
  }

}


You came to a local shop and want to buy some chocolate bars. There are $$$n$$$ bars in the shop, $$$i$$$-th of them costs $$$a_i$$$ coins (and you want to buy all of them).You have $$$m$$$ different coupons that allow you to buy chocolate bars. $$$i$$$-th coupon allows you to buy $$$q_i$$$ chocolate bars while you have to pay only for the $$$q_i - 1$$$ most expensive ones (so, the cheapest bar of those $$$q_i$$$ bars is for free).You can use only one coupon; if you use coupon $$$i$$$, you have to choose $$$q_i$$$ bars and buy them using the coupon, and buy all the remaining $$$n - q_i$$$ bars without any discounts.To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$) — the number of chocolate bars in the shop. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the cost of $$$i$$$-th chocolate bar. The third line contains one integer $$$m$$$ ($$$1 \le m \le n - 1$$$) — the number of coupons you have. The fourth line contains $$$m$$$ integers $$$q_1$$$, $$$q_2$$$, ..., $$$q_m$$$ ($$$2 \le q_i \le n$$$), where $$$q_i$$$ is the number of chocolate bars you have to buy using $$$i$$$-th coupon so that the least expensive of them will be for free. All values of $$$q_i$$$ are pairwise distinct.

Print $$$m$$$ integers, $$$i$$$-th of them should be the minimum amount of money you have to pay if you buy $$$q_i$$$ bars with $$$i$$$-th coupon, and all the remaining bars one by one for their full price.

NoteConsider the first example.If we use the first coupon, we may choose chocolate bars having indices $$$1$$$, $$$6$$$ and $$$7$$$, and we pay $$$18$$$ coins for them and $$$9$$$ coins for all other bars.If we use the second coupon, we may choose chocolate bars having indices $$$1$$$, $$$5$$$, $$$6$$$ and $$$7$$$, and we pay $$$25$$$ coins for them and $$$5$$$ coins for all other bars.

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

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

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

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

  def solve(): Unit = {
    val N = ni()
    val A = na(N)
    sort(A)
    val M = ni()
    val S = sumL(A)
    REP(M) { _ =>
      val q = ni()
      val ans = S - A(N - q)
      out.println(ans)
    }
  }

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

object CF_E61_B {
// date: 05/03/2019

  type In  = (Int, Seq[Int], Int, Seq[Int])
  type Out = Seq[Long]

  def solve(in: In): Out = {
    val (n, as, m, qs) = in

    val ss = as.sorted
    val total = ss.foldLeft(0L)(_+_)
    def mincost(q: Int): Long = total - ss(n - q)
    for {
      q <- qs
    } yield mincost(q)
  }

//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   Specify Input and Output formats on RHS here:

  def formatIn(i: Input): In       = (i.int, {i.nextLine; i.intSeq}, {i.int}, {i.nextLine; i.intSeq})
  def formatOut(out: Out): String  = out.mkString("\n")

//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   Boilerplate & utility methods that don't change (so ignore):

  import java.util.Scanner
  import java.io.InputStream
  import language.implicitConversions

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    val resultStr = new Input(System.in).solveStr
    out.println(resultStr)
    out.close()
  }

  class Input(val sc: Scanner) {
    // This class is useful for convenience, and for mock stdin in test scripts
    // Remember to call nextLine to advance past the newline character (if required) before taking a whole line
    def this(i: InputStream)       = this(new Scanner(i))
    def this(s: String)            = this(new Scanner(s.stripMargin))
    def int                        = sc.nextInt()
    def long                       = sc.nextLong()
    def double                     = sc.nextDouble()
    def nextLine                   = sc.nextLine()
    def collect[T](f: String => T) = sc.nextLine().split(" ").toVector.map(f)
    def intSeq                     = collect(_.toInt)
    def doubleSeq                  = collect(_.toDouble)
    def getLines: Vector[String]   = if (!sc.hasNextLine) Vector.empty
                                     else sc.nextLine +: getLines
    def getLines(lineCount: Int)   = {nextLine; (1 to lineCount).map(_ => sc.nextLine)}
    def solveVal: Out              = (solve _).tupled(formatIn(this))
    def solveStr: String           = formatOut(solveVal)
  }

  // Ceiling division for Int & Long
  // `a` MUST be > 0. Incorrect otherwise.
  def divideCeil(a: Int, b: Int)   = (a - 1)/b + 1
  def divideCeil(a: Long, b: Long) = (a - 1)/b + 1

  // A frequently used number in these comps
  val modulo = 1000000007

  // For convenience in test scripts, treat a String as an Input
  implicit def stringToInput(s: String): Input = new Input(s)
  // Required to make `solveVal` work when input has just 1 value (i.e. not a Tuple)
  implicit class makeTupledWorkOnFunction1[-T,+R](f: T => R) {
    def tupled: T => R = x => f(x)
  }
}


You are given an undirected tree consisting of $$$n$$$ vertices. An undirected tree is a connected undirected graph with $$$n - 1$$$ edges.Your task is to add the minimum number of edges in such a way that the length of the shortest path from the vertex $$$1$$$ to any other vertex is at most $$$2$$$. Note that you are not allowed to add loops and multiple edges.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The following $$$n - 1$$$ lines contain edges: edge $$$i$$$ is given as a pair of vertices $$$u_i, v_i$$$ ($$$1 \le u_i, v_i \le n$$$). It is guaranteed that the given edges form a tree. It is guaranteed that there are no loops and multiple edges in the given edges.

Print a single integer — the minimum number of edges you have to add in order to make the shortest distance from the vertex $$$1$$$ to any other vertex at most $$$2$$$. Note that you are not allowed to add loops and multiple edges.

NoteThe tree corresponding to the first example:  The answer is $$$2$$$, some of the possible answers are the following: $$$[(1, 5), (1, 6)]$$$, $$$[(1, 4), (1, 7)]$$$, $$$[(1, 6), (1, 7)]$$$.The tree corresponding to the second example:  The answer is $$$0$$$.The tree corresponding to the third example:  The answer is $$$1$$$, only one possible way to reach it is to add the edge $$$(1, 3)$$$.

object 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 sc = new InputReader(System.in)
    val N = sc.nextInt()
    val U, V = Array.ofDim[Int](N)
    rep(N - 1) { i =>
      val v, u = sc.nextInt() - 1
      V(i) = v
      U(i) = u
    }
    val t = packTree(N, U, V)

    val INF = Integer.MAX_VALUE
    val d = Array.fill[Int](N)(INF)
    d(0) = 0
    val bfs = Array.ofDim[Int](N)
    val p = Array.ofDim[Int](N)
    p(0) = -1

    var cur = 0
    var last = 1
    def addChildren(i: Int): Unit = {
      rep(t(i).length) { k =>
        val j = t(i)(k)
        if (d(j) == INF) {
          d(j) = d(i) + 1
          p(j) = i
          bfs(last) = j
          last += 1
        }
      }
    }

    addChildren(cur)
    while(cur < last) {
      addChildren(bfs(cur))
      cur += 1
    }

    var ans = 0
    rep_r(N) { i =>
      val v = bfs(i)
      if (d(v) > 2) {
        if (d(p(v)) < 2) {
          d(v) = d(p(v)) + 1
        } else {
          ans += 1
          d(v) = 2
          d(p(v)) = 1
          if (d(p(p(v))) > 2) d(p(p(v))) = 2 // dist of grand parent
        }
      }
    }

    out.println(ans)
  }

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

  def packTree(n: Int, from: Array[Int], to: Array[Int]): Array[Array[Int]] = {
    val t = new Array[Array[Int]](n)
    val p = new Array[Int](n)
    val m = from.length
    rep(m)(i => p(from(i)) += 1)
    rep(m)(i => p(to(i)) += 1)
    rep(n)(i => t(i) = new Array(p(i)))
    rep(m) { i =>
      p(from(i)) -= 1
      t(from(i))(p(from(i))) = to(i)
      p(to(i)) -= 1
      t(to(i))(p(to(i))) = from(i)
    }
    t
  }

  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)
  }
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

object 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 sc = new InputReader(System.in)
    val N = sc.nextInt()
    val t = Array.fill[ArrayBuffer[Int]](N)(ArrayBuffer())
    rep(N - 1) { _ =>
      val v, u = sc.nextInt() - 1
      t(v) += u
      t(u) += v
    }

    val INF = Integer.MAX_VALUE
    val d = Array.fill[Int](N)(INF)
    d(0) = 0
    val bfs = Array.ofDim[Int](N)
    val p = Array.ofDim[Int](N)
    p(0) = -1

    var cur = 0
    var last = 1
    def addChildren(i: Int): Unit = {
      t(i) foreach { j =>
        if (d(j) == INF) {
          d(j) = d(i) + 1
          bfs(last) = j
          p(j) = i
          last += 1
        }
      }
    }

    addChildren(cur)
    while(cur < last) {
      addChildren(cur)
      cur += 1
    }

    var ans = 0
    rep_r(N) { i =>
      val v = bfs(i)
      if (d(v) > 2) {
        if (d(p(v)) < 2) {
          d(v) = d(p(v)) + 1
        } else {
          ans += 1
          d(v) = 2
          d(p(v)) = 1
          if (d(p(p(v))) > 2) d(p(p(v))) = 2 // dist of grand parent
        }
      }
    }

    out.println(ans)
  }

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

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

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

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}


You are given an array a of size n, and q queries to it. There are queries of two types:   1 li ri — perform a cyclic shift of the segment [li, ri] to the right. That is, for every x such that li ≤ x < ri new value of ax + 1 becomes equal to old value of ax, and new value of ali becomes equal to old value of ari;  2 li ri — reverse the segment [li, ri].  There are m important indices in the array b1, b2, ..., bm. For each i such that 1 ≤ i ≤ m you have to output the number that will have index bi in the array after all queries are performed.

The first line contains three integer numbers n, q and m (1 ≤ n, q ≤ 2·105, 1 ≤ m ≤ 100).  The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).  Then q lines follow. i-th of them contains three integer numbers ti, li, ri, where ti is the type of i-th query, and [li, ri] is the segment where this query is performed (1 ≤ ti ≤ 2, 1 ≤ li ≤ ri ≤ n).  The last line contains m integer numbers b1, b2, ..., bm (1 ≤ bi ≤ n) — important indices of the array.

Print m numbers, i-th of which is equal to the number at index bi after all queries are done.

//package edu29

import scala.io.StdIn

object D extends App {
  def readInts = StdIn.readLine().split(" ").map(_.toInt)
  val Array(n, q, m) = readInts
  val nums = readInts
  val qs = Array.fill(q)(readInts)
  val ms = readInts

  for (q <- qs.reverseIterator) {
    var i = 0
    q match {
      case Array(1, l, r) => while (i < ms.length) {
        val k = ms(i)
        if (k == l) ms(i) = r
        else if (k > l && k <= r) ms(i) = k - 1
        i += 1
      }
      case Array(2, l, r) => while (i < ms.length) {
        val k = ms(i)
        if (k >= l && k <= r) ms(i) = l + r - k
        i += 1
      }
      case _              =>
    }
  }

  println(ms.map(_ - 1).map(nums).mkString(" "))
}

//package edu29

import scala.io.StdIn

object D extends App {
  def readInts = StdIn.readLine().split(" ").map(_.toInt)
  val Array(n, q, m) = readInts
  val nums = readInts
  val qs = Array.fill(q)(readInts)
  val ms = readInts

  for (q <- qs.reverseIterator;i <- ms.indices)
      ms(i) = q match {
        case Array(1, l, r) if ms(i) == l               => r
        case Array(1, l, r) if l < ms(i) && ms(i) <= r  => ms(i) - 1
        case Array(2, l, r) if l <= ms(i) && ms(i) <= r => r + l - ms(i)
        case _                                          => ms(i)
      }

  println(ms.mkString(" "))
}


In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?).A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't.You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not.You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO".   The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise).  The string s2 describes a group of soldiers 2 through k + 1.  And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example.Find and print any solution. It can be proved that there always exists at least one solution.

The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise.

Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them.

Adam Bob Bob Cpqepqwer Limak Adam Bob Adam

R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc

NoteIn the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output:  First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO".  Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO".  Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES".  ...,  Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO".

import scala.io.StdIn._

object TaskA extends App {
  val l = readLine().split(" ")

  val n = l(0).toInt
  val k = l(1).toInt

  val names = (for {
    f <- 'A' to 'Z'
    s <- 'a' to 'z'
  } yield s"$f$s").take(n).toArray

  readLine().split(" ").toList.zipWithIndex
    .filter(_._1 == "NO")
    .map(_._2)
    .foreach { i => names(i + k - 1) = names(i) }

  println(names.mkString(" "))
}


Vova had a pretty weird sleeping schedule. There are $$$h$$$ hours in a day. Vova will sleep exactly $$$n$$$ times. The $$$i$$$-th time he will sleep exactly after $$$a_i$$$ hours from the time he woke up. You can assume that Vova woke up exactly at the beginning of this story (the initial time is $$$0$$$). Each time Vova sleeps exactly one day (in other words, $$$h$$$ hours).Vova thinks that the $$$i$$$-th sleeping time is good if he starts to sleep between hours $$$l$$$ and $$$r$$$ inclusive.Vova can control himself and before the $$$i$$$-th time can choose between two options: go to sleep after $$$a_i$$$ hours or after $$$a_i - 1$$$ hours.Your task is to say the maximum number of good sleeping times Vova can obtain if he acts optimally.

The first line of the input contains four integers $$$n, h, l$$$ and $$$r$$$ ($$$1 \le n \le 2000, 3 \le h \le 2000, 0 \le l \le r < h$$$) — the number of times Vova goes to sleep, the number of hours in a day and the segment of the good sleeping time. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i < h$$$), where $$$a_i$$$ is the number of hours after which Vova goes to sleep the $$$i$$$-th time.

Print one integer — the maximum number of good sleeping times Vova can obtain if he acts optimally.

NoteThe maximum number of good times in the example is $$$3$$$.The story starts from $$$t=0$$$. Then Vova goes to sleep after $$$a_1 - 1$$$ hours, now the time is $$$15$$$. This time is not good. Then Vova goes to sleep after $$$a_2 - 1$$$ hours, now the time is $$$15 + 16 = 7$$$. This time is also not good. Then Vova goes to sleep after $$$a_3$$$ hours, now the time is $$$7 + 14 = 21$$$. This time is good. Then Vova goes to sleep after $$$a_4 - 1$$$ hours, now the time is $$$21 + 19 = 16$$$. This time is not good. Then Vova goes to sleep after $$$a_5$$$ hours, now the time is $$$16 + 20 = 12$$$. This time is not good. Then Vova goes to sleep after $$$a_6$$$ hours, now the time is $$$12 + 11 = 23$$$. This time is good. Then Vova goes to sleep after $$$a_7$$$ hours, now the time is $$$23 + 22 = 21$$$. This time is also good.

import java.util.Scanner

object E_3_627 extends App {
  var scanner = new Scanner(System.in)

  val sleepCount = scanner.nextInt()
  val hoursInDay = scanner.nextInt()
  val goodHourStart = scanner.nextInt()
  val goodHourEnd = scanner.nextInt()

  val untilSleeps = Array.ofDim[Int](sleepCount)
  untilSleeps.indices.foreach { index =>
    untilSleeps(index) = scanner.nextInt()
  }

  def asDayHour(hour: Int): Int = {
    Math.floorMod(hour, hoursInDay)
  }

  def isGoodHour(hour: Int): Boolean = {
    (hour >= goodHourStart) && (hour <= goodHourEnd)
  }

  val goodDays = Array.ofDim[Int](sleepCount + 1, hoursInDay)
  goodDays(0)(0) = 0

  def calculateGoodDays(sleepIndex: Int, hourIndex: Int, wakeupGoodDays: Int): Int = {
    val newGoodDays = {
      if (isGoodHour(hourIndex)) {
        wakeupGoodDays + 1
      }
      else {
        wakeupGoodDays
      }
    }

    val maxGoodDays = Math.max(goodDays(sleepIndex)(hourIndex), newGoodDays)
    goodDays(sleepIndex)(hourIndex) = maxGoodDays

    maxGoodDays
  }

  var wakeupHours = Set(0)
  untilSleeps.zipWithIndex.foreach { case (untilSleep, sleepIndex) =>
    var newWakeupHours = Set.empty[Int]
    wakeupHours.foreach { wakeupHour =>
      val newWakeupHour = asDayHour(wakeupHour + untilSleep)

      // in time
      calculateGoodDays(sleepIndex + 1, newWakeupHour, goodDays(sleepIndex)(wakeupHour))

      // 1h before
      val improvedNewWakeupHour = asDayHour(newWakeupHour - 1)
      calculateGoodDays(sleepIndex + 1, improvedNewWakeupHour, goodDays(sleepIndex)(wakeupHour))

      newWakeupHours += newWakeupHour
      newWakeupHours += improvedNewWakeupHour
    }
    wakeupHours = newWakeupHours
  }

  val maxGoodDaysHour = wakeupHours.maxBy(goodDays(sleepCount))
  val maxGoodDays = goodDays(sleepCount)(maxGoodDaysHour)
  println(maxGoodDays)
}

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

  import Main._
  import fScanner._

  def solve(): Unit = {
    val n = ni()
    val h = ni()
    val l = ni()
    val r = ni()

    val a = na(n)

    val dp = Array.fill[Int](n+1,n+1)(Int.MinValue)
    dp(0)(0) = 0
    var sum = 0L
    REP(n) { i =>
      sum += a(i)
      REP(n+1) { j =>
        dp(i+1)(j) = scala.math.max(dp(i+1)(j), dp(i)(j) + inside((sum - j) % h, l , r))
        if(j < n) dp(i+1)(j+1) = scala.math.max(dp(i+1)(j+1), dp(i)(j) + inside((sum - j - 1) % h, l , r))
      }
    }
    out.println(dp(n).max)
  }

  def inside(v: Long, l: Int, r: Int): Int = {
    if(r >= v && v >= l) 1 else 0
  }
}


This is an interactive problem.In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontrollable train in the subway. It can be dangerous! Your task is to find the train and stop the AI.The subway of the Metropolis is one line (regular straight line with no self-intersections) with $$$n$$$ stations, indexed consecutively from $$$1$$$ to $$$n$$$. At each moment the train is at some station. You need to determine the index of this station, so that the train would be secured.To find the train, dispatcher Sarah gave you a gadget that allows you to select arbitrary numbers $$$l$$$ and $$$r$$$ ($$$l \le r$$$), and then check, whether the train is located on a station with index between $$$l$$$ and $$$r$$$, inclusive. Unfortunately, recharging of the gadget takes some time (and every time you use it as soon as possible), so between two applications of the gadget the train can move to any station that is at most $$$k$$$ stations away. Formally, if the train was at the station $$$x$$$ when the gadget was applied, then at the next application of the gadget the train can appear at any station $$$y$$$ such that $$$\max(1, x - k) \leq y \leq \min(n, x + k)$$$.Note that AI is not aware that you are trying to catch the train, so it makes all moves according to its predefined plan.After an examination of the gadget you found that it is very old and can hold no more than $$$4500$$$ applications, after which it will break and your mission will be considered a failure.Can you find the station with the train using no more than $$$4500$$$ applications of the gadgets?

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^{18}$$$, $$$0 \leq k \leq 10$$$) — the number of stations and the maximum number of stations the train can move between two applications of the gadget.

NoteIn the first sample, the train was initially at the station $$$5$$$, after the first application of the gadget it did not move, after the second application it moved to the station $$$3$$$, and after the third application moved again to the station $$$5$$$.

object 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

  def solve(): Unit = {
    val N = nl()
    val K = ni()
    var l = 1L
    var h = N
    while(true) {
      if (h - l > 4 * K + 5) {
        val m = (h + l) / 2
        println(s"$l $m")
        ns() match {
          case "Bad" => return ()
          case "Yes" => h = m
          case "No" => l = m + 1
        }
        l = max(l - K, 1)
        h = min(N, h + K)
      } else {
        import scala.util.Random
        val i = Random.nextInt((h - l + 1).toInt) + l
        println(s"$i $i")
        ns() match {
          case "Bad" => return ()
          case "Yes" => return ()
          case "No" =>
            l = max(l - K, 1)
            h = min(N, h + K)
        }
      }
    }
  }

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

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

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

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

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

object 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

  def solve(): Unit = {
    val N = nl()
    val K = ni()
    var l = 1L
    var h = N
    while(true) {
      if (h - l > 4 * K + 5) {
        val m = (h + l) / 2
        println(s"$l $m")
        ns() match {
          case "Bad" => return ()
          case "Yes" => h = m
          case "No" => l = m + 1
        }
        l = max(l - K, 1)
        h = min(N, h + K)
      } else {
        import scala.util.Random
        val i = Random.nextInt((h - l).toInt) + l
        println(s"$i $i")
        ns() match {
          case "Bad" => return ()
          case "Yes" => return ()
          case "No" =>
            l = max(l - K, 1)
            h = min(N, h + K)
        }
      }
    }
  }

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

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

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

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

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

object 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

  def solve(): Unit = {
    val N = nl()
    val K = ni()
    var l = 1L
    var h = N
    while(true) {
      if (h - l > 4 * K + 5) {
        val m = (h + l) / 2
        println(s"$l $m")
        ns() match {
          case "Bad" => return ()
          case "Yes" => h = m
          case "No" => l = m + 1
        }
        l = max(l - K, 0)
        h = min(N, h + K)
      } else {
        import scala.util.Random
        val i = Random.nextInt((h - l).toInt) + l
        println(s"$i $i")
        ns() match {
          case "Bad" => return ()
          case "Yes" => return ()
          case "No" =>
            l = max(l - K, 0)
            h = min(N, h + K)
        }
      }
    }
  }

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

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

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

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

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


Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).For example, as a result of typing the word "hello", the following words could be printed: "hello", "hhhhello", "hheeeellllooo", but the following could not be printed: "hell", "helo", "hhllllooo".Note, that when you press a key, the corresponding symbol must appear (possibly, more than once). The keyboard is broken in a random manner, it means that pressing the same key you can get the different number of letters in the result.For each word in the letter, Methodius has guessed what word Polycarp actually wanted to write, but he is not sure about it, so he asks you to help him.You are given a list of pairs of words. For each pair, determine if the second word could be printed by typing the first one on Polycarp's keyboard.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of pairs to check. Further input contains $$$n$$$ descriptions of pairs. The first line of each description contains a single non-empty word $$$s$$$ consisting of lowercase Latin letters. The second line of the description contains a single non-empty word $$$t$$$ consisting of lowercase Latin letters. The lengths of both strings are not greater than $$$10^6$$$. It is guaranteed that the total length of all words $$$s$$$ in the input is not greater than $$$10^6$$$. Also, it is guaranteed that the total length of all words $$$t$$$ in the input is not greater than $$$10^6$$$.

Output $$$n$$$ lines. In the $$$i$$$-th line for the $$$i$$$-th pair of words $$$s$$$ and $$$t$$$ print YES if the word $$$t$$$ could be printed by typing the word $$$s$$$. Otherwise, print NO.

4
hello
hello
hello
helloo
hello
hlllloo
hello
helo

5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz

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 Entry(ch: Char, cnt: Int)

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 calc(s: String): ArrayBuffer[Entry] = {
    val n = s.length
    var i = 0
    val res = ArrayBuffer[Entry]()
    while(i < n) {
      var j = i
      while(j + 1 < n && s(i) == s(j + 1)) {
        j += 1
      }
      res += Entry(s(i), j - i + 1)
      i = j + 1
    }
    res
  }

  def test(): Boolean = {
    val S, T = ns()
    val E1 = calc(S)
    val E2 = calc(T)

    debug(E1.mkString(" "))
    debug(E2.mkString(" "))

    E1.length == E2.length && {
      var ok = true
      REP(E1.length) { i =>
        ok &&= E1(i).ch == E2(i).ch && E1(i).cnt <= E2(i).cnt
      }
      ok
    }
  }

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

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

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 test(): Boolean = {
    val S, T = ns()
    var i, j = 0
    val N = S.length
    val M = T.length

    debug(s"N:$N M:$M")

    debug(S)
    debug(T)

    while(i < N) {
      if (j == M || S(i) != T(j)) return false
      var ii = i
      var jj = j
      while (ii + 1 < N && S(i) == S(ii + 1)) {
        ii += 1
      }
      while (jj + 1 < M && T(j) == T(jj + 1)) {
        jj += 1
      }
      debug(s"i:$i j:$j ii:$ii jj:$jj")
      if (jj - j < ii - i) return false
      i = ii + 1
      j = jj + 1
    }

    j == M
  }

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

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

  override def apply(io: IO): io.type = {
    val input = io.read[Seq[(String, String)]]
    val ans = input map { case (a, b) => check(a.toList, b.toList).toEnglish }
    io.writeLines(ans)
  }

  @tailrec
  def check[A](as: List[A], bs: List[A]): Boolean =
    (as, bs) match {
      case (Nil, Nil) => true
      case (a1 :: at, b1 :: bt) if a1 == b1 =>
        val (ad, an) = at.span(_ == a1)
        val (bd, bn) = bt.span(_ == b1)
        bd.length >= ad.length && check(an, bn)
      case _ => false
    }

  implicit class BooleanExtensions(x: Boolean) {
    def toEnglish = if(x) "YES" else "NO"
  }
}
/****************************[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()
}
/***********************************[Scala I/O]*********************************************/
import java.io._, java.util.StringTokenizer
import scala.collection.generic.CanBuild

class IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
  val printer = new PrintWriter(out, true)

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    tokenizers.headOption
  }

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

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

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

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

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

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

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

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

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 test(): Boolean = {
    val S, T = ns()
    var i, j = 0
    val N = S.length
    val M = T.length

    debug(S)
    debug(T)

    while(i < N) {
      if (j == M || S(i) != T(j)) return false
      var ii = i
      var jj = j
      if (ii + 1 < N && S(i) == S(ii + 1)) {
        ii += 1
      }
      if (jj + 1 < M && T(j) == T(jj + 1)) {
        jj += 1
      }
      debug(s"i:$i j:$j ii:$ii jj:$jj")
      if (jj - j < ii - i) return false
      i = ii + 1
      j = jj + 1
    }

    j == M
  }

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


There are $$$n$$$ workers and $$$m$$$ tasks. The workers are numbered from $$$1$$$ to $$$n$$$. Each task $$$i$$$ has a value $$$a_i$$$ — the index of worker who is proficient in this task.Every task should have a worker assigned to it. If a worker is proficient in the task, they complete it in $$$1$$$ hour. Otherwise, it takes them $$$2$$$ hours.The workers work in parallel, independently of each other. Each worker can only work on one task at once.Assign the workers to all tasks in such a way that the tasks are completed as early as possible. The work starts at time $$$0$$$. What's the minimum time all tasks can be completed by?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le m \le 2 \cdot 10^5$$$) — the number of workers and the number of tasks. The second line contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_i \le n$$$) — the index of the worker proficient in the $$$i$$$-th task. The sum of $$$m$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print a single integer — the minimum time all tasks can be completed by.

NoteIn the first testcase, the first worker works on tasks $$$1$$$ and $$$3$$$, and the second worker works on tasks $$$2$$$ and $$$4$$$. Since they both are proficient in the corresponding tasks, they take $$$1$$$ hour on each. Both of them complete $$$2$$$ tasks in $$$2$$$ hours. Thus, all tasks are completed by $$$2$$$ hours.In the second testcase, it's optimal to assign the first worker to tasks $$$1, 2$$$ and $$$3$$$ and the second worker to task $$$4$$$. The first worker spends $$$3$$$ hours, the second worker spends $$$2$$$ hours (since they are not proficient in the taken task).In the third example, each worker can be assigned to the task they are proficient at. Thus, each of them complete their task in $$$1$$$ hour.

object prob2 {
  def main(args: Array[String]) = {
    new Resolver3(Console.in, Console.out).run()
  }
}

class Resolver3(input: java.io.BufferedReader, output: java.io.PrintStream) {

  import java.util.StringTokenizer
  import scala.collection.mutable
  import scala.collection.mutable._
  import scala.math.{abs,pow,min,max}
  import scala.collection.mutable.ListBuffer

  def run() {
    var tokenizer = new StringTokenizer(input.readLine())
    val q = tokenizer.nextToken().toInt
    for (sss <- 0 until q) {
      tokenizer = new StringTokenizer(input.readLine())
      val n = tokenizer.nextToken().toInt
      val m = tokenizer.nextToken().toInt
      val A = new Array[Long](n)
      for (i<- A.indices){
        A(i) = 0
      }
      tokenizer = new StringTokenizer(input.readLine())
      for (i <- 1 to m) {
        val a = tokenizer.nextToken().toInt
        A(a-1)= A(a-1)+ 1
      }
      var l = 0
      var r = A.max
      while ((r - l) > 1) {
        val t = (l+r)/2
        var sum: Long = 0
        for (i <- A){
          sum+= {if (i>=t) t else i + ((t-i) / 2)}
        }
        if (sum >= m){
          r = t.toInt
        }
        else {
          l = t.toInt
        }
      }
      println(r)
    }
  }
}

object prob2 {
  def main(args: Array[String]) = {
    new Resolver3(Console.in, Console.out).run()
  }
}

class Resolver3(input: java.io.BufferedReader, output: java.io.PrintStream) {

  import java.util.StringTokenizer
  import scala.collection.mutable
  import scala.collection.mutable._
  import scala.math.{abs,pow,min,max}
  import scala.collection.mutable.ListBuffer

  def run() {
    var tokenizer = new StringTokenizer(input.readLine())
    val q = tokenizer.nextToken().toInt
    for (sss <- 0 until q) {
      tokenizer = new StringTokenizer(input.readLine())
      val n = tokenizer.nextToken().toInt
      val m = tokenizer.nextToken().toInt
      val A = new Array[Int](n)
      for (i<- A.indices){
        A(i) = 0
      }
      tokenizer = new StringTokenizer(input.readLine())
      for (i <- 1 to m) {
        val a = tokenizer.nextToken().toInt
        A(a-1)= A(a-1)+ 1
      }
      var l = 0
      var r = A.max
      while ((r - l) > 1) {
        val t = (l+r)/2
        var sum = 0
        for (i <- A){
          sum+= {if (i>=t) t else i + ((t-i) / 2)}
        }
        if (sum >= m){
          r = t
        }
        else {
          l = t
        }
      }
      println(r)
    }
  }
}

object prob2 {
  def main(args: Array[String]) = {
    new Resolver3(Console.in, Console.out).run()
  }
}

class Resolver3(input: java.io.BufferedReader, output: java.io.PrintStream) {

  import java.util.StringTokenizer
  import scala.collection.mutable
  import scala.collection.mutable._
  import scala.math.{abs,pow,min,max}
  import scala.collection.mutable.ListBuffer

  def run() {
    var tokenizer = new StringTokenizer(input.readLine())
    val q = tokenizer.nextToken().toInt
    for (sss <- 0 until q) {
      tokenizer = new StringTokenizer(input.readLine())
      val n = tokenizer.nextToken().toInt
      val m = tokenizer.nextToken().toInt
      val A = new Array[Int](n)
      for (i<- A.indices){
        A(i) = 0
      }
      tokenizer = new StringTokenizer(input.readLine())
      for (i <- 1 to m) {
        val a = tokenizer.nextToken().toInt
        A(a-1)= A(a-1)+ 1
      }
      var l = 0
      var r = A.max
      while ((r - l) > 1) {
        var t = (l+r)/2
        var sum = 0
        for (i <- A){
          sum+= min(i,t) + max(0, (t - i) / 2)
        }
        if (sum >= m){
          r = t
        }
        else {
          l = t
        }
      }
      println(r)
    }
  }
}