A company of $$$n$$$ friends wants to order exactly two pizzas. It is known that in total there are $$$9$$$ pizza ingredients in nature, which are denoted by integers from $$$1$$$ to $$$9$$$.Each of the $$$n$$$ friends has one or more favorite ingredients: the $$$i$$$-th of friends has the number of favorite ingredients equal to $$$f_i$$$ ($$$1 \le f_i \le 9$$$) and your favorite ingredients form the sequence $$$b_{i1}, b_{i2}, \dots, b_{if_i}$$$ ($$$1 \le b_{it} \le 9$$$).The website of CodePizza restaurant has exactly $$$m$$$ ($$$m \ge 2$$$) pizzas. Each pizza is characterized by a set of $$$r_j$$$ ingredients $$$a_{j1}, a_{j2}, \dots, a_{jr_j}$$$ ($$$1 \le r_j \le 9$$$, $$$1 \le a_{jt} \le 9$$$) , which are included in it, and its price is $$$c_j$$$.Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas.

The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^5, 2 \le m \le 10^5$$$) — the number of friends in the company and the number of pizzas, respectively. Next, the $$$n$$$ lines contain descriptions of favorite ingredients of the friends: the $$$i$$$-th of them contains the number of favorite ingredients $$$f_i$$$ ($$$1 \le f_i \le 9$$$) and a sequence of distinct integers $$$b_{i1}, b_{i2}, \dots, b_{if_i}$$$ ($$$1 \le b_{it} \le 9$$$). Next, the $$$m$$$ lines contain pizza descriptions: the $$$j$$$-th of them contains the integer price of the pizza $$$c_j$$$ ($$$1 \le c_j \le 10^9$$$), the number of ingredients $$$r_j$$$ ($$$1 \le r_j \le 9$$$) and the ingredients themselves as a sequence of distinct integers $$$a_{j1}, a_{j2}, \dots, a_{jr_j}$$$ ($$$1 \le a_{jt} \le 9$$$).

Output two integers $$$j_1$$$ and $$$j_2$$$ ($$$1 \le j_1,j_2 \le m$$$, $$$j_1 \ne j_2$$$) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order.

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

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

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

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

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

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

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

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

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

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

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

  case class Restaurant(i: Int, cost: Int)

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

  def solve(): Unit = {
    val N, M = ni()
    val F = Array.ofDim[Int](N)
    REP(N) { i =>
      val f = ni()
      var fav = 0
      REP(f) { _ =>
        val k = ni() - 1
        fav |= 1 << k
      }
      F(i) = fav
    }

    val R = Array.ofDim[Restaurant](1 << 9, 2)
    REP(M) { i =>
      val c, r = ni()
      var offer = 0
      REP(r) { _ =>
        val k = ni() - 1
        offer |= 1 << k
      }
      if (R(offer)(0) == null) {
        R(offer)(0) = Restaurant(i, c)
      } else if (R(offer)(1) == null || R(offer)(1).cost > c) {
        R(offer)(1) = Restaurant(i, c)
        if (R(offer)(0).cost > R(offer)(1).cost) {
          val t = R(offer)(0)
          R(offer)(0) = R(offer)(1)
          R(offer)(1) = t
        }
      }
    }

    val C = Array.ofDim[Int](1 << 9)
    REP(1 << 9) { fav =>
      REP(N) { i =>
        if ((F(i) & fav) == F(i)) { // F(i) ∈ fav
          C(fav) += 1
        }
      }
    }

    var mxFriends = 0
    var minCost = 2e9.toInt + 1
    var ans = (-1, -1)
    REP(1 << 9) { o1 =>
      REP(1 << 9) { o2 =>
        val (r1, r2) = if (o1 != o2) {
          (R(o1)(0), R(o2)(0))
        } else {
          (R(o1)(0), R(o2)(1))
        }
        if (r1 != null && r2 != null) {
          if (C(o1 | o2) > mxFriends) {
            mxFriends = C(o1 | o2)
            minCost = r1.cost + r2.cost
            ans = (r1.i, r2.i)
          }
          if (C(o1 | o2) == mxFriends && r1.cost + r2.cost < minCost) {
            minCost = r1.cost + r2.cost
            ans = (r1.i, r2.i)
          }
        }
      }
    }
    out.println(s"${ans._1 + 1} ${ans._2 + 1}")
  }
}


You have a sequence of $$$n$$$ colored blocks. The color of the $$$i$$$-th block is $$$c_i$$$, an integer between $$$1$$$ and $$$n$$$.You will place the blocks down in sequence on an infinite coordinate grid in the following way.   Initially, you place block $$$1$$$ at $$$(0, 0)$$$.  For $$$2 \le i \le n$$$, if the $$$(i - 1)$$$-th block is placed at position $$$(x, y)$$$, then the $$$i$$$-th block can be placed at one of positions $$$(x + 1, y)$$$, $$$(x - 1, y)$$$, $$$(x, y + 1)$$$ (but not at position $$$(x, y - 1)$$$), as long no previous block was placed at that position. A tower is formed by $$$s$$$ blocks such that they are placed at positions $$$(x, y), (x, y + 1), \ldots, (x, y + s - 1)$$$ for some position $$$(x, y)$$$ and integer $$$s$$$. The size of the tower is $$$s$$$, the number of blocks in it. A tower of color $$$r$$$ is a tower such that all blocks in it have the color $$$r$$$.For each color $$$r$$$ from $$$1$$$ to $$$n$$$, solve the following problem independently:   Find the maximum size of a tower of color $$$r$$$ that you can form by placing down the blocks according to the rules.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.  The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$c_1, c_2, \ldots, c_n$$$ ($$$1 \le c_i \le n$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output $$$n$$$ integers. The $$$r$$$-th of them should be the maximum size of an tower of color $$$r$$$ you can form by following the given rules. If you cannot form any tower of color $$$r$$$, the $$$r$$$-th integer should be $$$0$$$.

NoteIn the first test case, one of the possible ways to form a tower of color $$$1$$$ and size $$$3$$$ is:   place block $$$1$$$ at position $$$(0, 0)$$$;  place block $$$2$$$ to the right of block $$$1$$$, at position $$$(1, 0)$$$;  place block $$$3$$$ above block $$$2$$$, at position $$$(1, 1)$$$;  place block $$$4$$$ to the left of block $$$3$$$, at position $$$(0, 1)$$$;  place block $$$5$$$ to the left of block $$$4$$$, at position $$$(-1, 1)$$$;  place block $$$6$$$ above block $$$5$$$, at position $$$(-1, 2)$$$;  place block $$$7$$$ to the right of block $$$6$$$, at position $$$(0, 2)$$$.   The blocks at positions $$$(0, 0)$$$, $$$(0, 1)$$$, and $$$(0, 2)$$$ all have color $$$1$$$, forming an tower of size $$$3$$$.In the second test case, note that the following placement is not valid, since you are not allowed to place block $$$6$$$ under block $$$5$$$:  It can be shown that it is impossible to form a tower of color $$$4$$$ and size $$$3$$$.

import scala.io.StdIn._

object Main {
  def main(args: Array[String]): Unit = {
      val t: Int = readInt()
      for (_ <- 1 to t){
          val n: Int = readInt()
          val a: Array[Int] = readLine().split(" ").map(_.toInt)
          val b: Array[Int] = Array.fill(n)(0)
          val parity_arr: Array[Int] = Array.fill(n)(-1)
            for (j <- 0 until n){
                val curr_color: Int = a(j)
                val last_parity: Int = parity_arr(a(j)-1)
                if (last_parity == -1 || (last_parity == 0 && j%2 == 1) || (last_parity == 1 && j%2 == 0)) {
                    b(a(j)-1) += 1
                    parity_arr(a(j)-1) = j%2
                }
            }
        println(b.mkString(" "))
        }
    }
}

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 A = new Array[Int](n)
      val B = new Array[Int](n)
      for (i <- 0 until n) {
        A(i) = 0
        B(i) = -1
      }
      tokenizer = new StringTokenizer(input.readLine())
      var pr = 0
      var now = 0
      var count = 0
      for (i <- 1 to n) {
        pr = now
        now = tokenizer.nextToken().toInt
        if (pr == now) {
          B(pr-1) = i
          A(pr-1) += 1
        }
        else if (B(now-1) == -1) {
          B(now-1) = i
          A(now-1) += 1
        }
        else if ((i - B(now-1) ) % 2 == 1) {
          B(now-1) = i
          A(now-1) += 1
        }
        else {
          B(now-1) = i
        }
      }
      println(A.mkString(" "))
    }
  }
}


An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $$$1$$$. More formally, a sequence $$$s_1, s_2, \ldots, s_{n}$$$ is beautiful if $$$|s_i - s_{i+1}| = 1$$$ for all $$$1 \leq i \leq n - 1$$$.Trans has $$$a$$$ numbers $$$0$$$, $$$b$$$ numbers $$$1$$$, $$$c$$$ numbers $$$2$$$ and $$$d$$$ numbers $$$3$$$. He wants to construct a beautiful sequence using all of these $$$a + b + c + d$$$ numbers.However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?

The only input line contains four non-negative integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$0 < a+b+c+d \leq 10^5$$$).

If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line. Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $$$a + b + c + d$$$ integers, separated by spaces — a beautiful sequence. There should be $$$a$$$ numbers equal to $$$0$$$, $$$b$$$ numbers equal to $$$1$$$, $$$c$$$ numbers equal to $$$2$$$ and $$$d$$$ numbers equal to $$$3$$$. If there are multiple answers, you can print any of them.

NoteIn the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $$$1$$$. Also, there are exactly two numbers, equal to $$$0$$$, $$$1$$$, $$$2$$$ and exactly one number, equal to $$$3$$$.It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.

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

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

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

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

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

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

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

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

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

object Workspace {
  import Main._

  import scala.collection.mutable.ArrayBuffer
  case class Edge(u: Int, id: Int)
  type G = Array[ArrayBuffer[Edge]]

object EulerianTrail {
  def makeUDPath(g: G, m: Int): Option[Array[Int]] = {
    makePath(g, m) { g =>
      val n = g.length
      var odds = 0
      var s = g.indexWhere(_.nonEmpty)
      REP(n) { v =>
        val odd = g(v).length % 2 == 1
        if (odd) {
          s = v
          odds += 1
        }
      }

      (s, odds == 0 || odds == 2)
    }
  }

  def makeDPath(g: G, m: Int, s0: Int): Option[Array[Int]] = {
    makePath(g, m) { g =>
      val n = g.length

      var s = ArrayBuffer[Int]()
      val in = Array.ofDim[Int](n)
      REP(n) { v =>
        REP(g(v).length) { i =>
          val u = g(v)(i).u
          in(u) += 1
        }
      }

      var plus, minus = 0
      var ok = true
      REP(n) { v =>
        // in - out
        if (in(v) == g(v).length + 1) {
          plus += 1
        } else if (in(v) + 1 == g(v).length) {
          minus += 1
          s += v // 収支マイナスの点から始める
        } else {
          //１こ以上ずれているとアウト
          ok &&= in(v) == g(v).length
        }
      }

      (s0, ok && (s.isEmpty || s.contains(s0)) && (plus == 0 && minus == 0 || plus == 1 && minus == 1))
    } map { path =>
      // ちょうど逆さまになっているので、有向グラフの場合はreverseしないといけない
      REP((m + 1)/2) { i =>
        val t = path(i)
        path(i) = path(m - i)
        path(m - i) = t
      }
      path
    }
  }

  private def makePath(g: G, m: Int)(f: G => (Int, Boolean)): Option[Array[Int]] = {
    val n = g.length
    val path = Array.ofDim[Int](m + 1)
    var pi = 0
    val used = Array.ofDim[Boolean](m)
    val ix = Array.ofDim[Int](n)

    val stack = Array.ofDim[Int](m + 1)
    var si = 0

    val (s, preCondition) = f(g)

    def dfs(s: Int): Unit = {
      stack(si) = s; si += 1
      while(si > 0) {
        val v = stack(si-1)
        while(ix(v) < g(v).length && used(g(v)(ix(v)).id)) ix(v) += 1
        if (ix(v) == g(v).length) {
          si -= 1
          path(pi) = v; pi += 1
        } else {
          used(g(v)(ix(v)).id) = true
          stack(si) = g(v)(ix(v)).u; si += 1; ix(v) += 1
        }
      }
    }

    if (!preCondition) {
      None
    } else {
      dfs(s)
      if (pi == m + 1) Some(path) else None
    }
  }

}
}

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

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

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

  def solve(): Unit = {
    val A, B, C, D = ni()
    val N = A + B + C + D
    val Cnt = Array(A, B, C, D)

    if (N == 1) {
      REP(4) { i =>
        if (Cnt(i) > 0) {
          out.println("YES")
          out.println(i)
          return
        }
      }
    }

    REP(4) { s =>
      REP(4) { t =>
        val cnt = Array.ofDim[Int](4)
        cnt(s) += 1; cnt(t) += 1
        var ok = true
        REP(4) { k =>
          ok &&= Cnt(k) >= cnt(k)
        }
        var e01, e10 = A
        var e23, e32 = D
        if (s == 0) e10 -= 1
        if (t == 0) e01 -= 1
        if (s == 3) e23 -= 1
        if (t == 3) e32 -= 1
        var e21 = B - e01
        var e12 = C - e32
        if (s == 1) e21 -= 1
        if (s == 2) e12 -= 1

        if (e01 >= 0 && e10 >= 0 && e12 >= 0 && e21 >= 0 && e23 >= 0 && e32 >= 0 &&
          e01 + e10 + e12 + e21 + e23 + e32 == N - 1 &&
          e10 + (if (s == 0) 1 else 0) == A &&
          e01 + e21 + (if (s == 1) 1 else 0) == B &&
          e32 + e12 + (if (s == 2) 1 else 0) == C &&
          e23 + (if (s == 3) 1 else 0) == D
        ) {
          val g = Array.fill(4)(ArrayBuffer[Edge]())
          REP(e01) { i => g(0) += Edge(1, i) }
          REP(e10, e01) { i => g(1) += Edge(0, i) }
          REP(e12, e01 + e10) { i => g(1) += Edge(2, i) }
          REP(e21, e01 + e10 + e12) { i => g(2) += Edge(1, i) }
          REP(e23, e01 + e10 + e12 + e21) { i => g(2) += Edge(3, i) }
          REP(e32, e01 + e10 + e12 + e21 + e23) { i => g(3) += Edge(2, i) }
          EulerianTrail.makeDPath(g, N - 1, s) match {
            case None =>
            case Some(path) =>
              debug(s"$s $t $e01 $e10 $e12 $e21 $e23 $e32")
              out.println("YES")
              out.println(path.mkString(" "))
              return
          }
        }
      }
    }
    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[this] val oj = System.getenv("ATCODER_DEBUG") == null
  @inline private final def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  @inline private final def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  @inline def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  @inline private final def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  @inline private final def debugDim(m: Array[Array[Int]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  @inline private final def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  @inline def debug(s: => String): Unit = DEBUG {
    System.err.println(s)
  }
  @inline private final def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }
  private def isDebug[A](debug: => A, online: => A): A = {
    if (oj) online else debug
  }

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

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

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

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

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

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

object Workspace {
  import Main._

  import scala.collection.mutable.ArrayBuffer
  case class Edge(u: Int, id: Int)
  type G = Array[ArrayBuffer[Edge]]

object EulerianTrail {
  def makeUDPath(g: G, m: Int): Option[Array[Int]] = {
    makePath(g, m) { g =>
      val n = g.length
      var odds = 0
      var s = g.indexWhere(_.nonEmpty)
      REP(n) { v =>
        val odd = g(v).length % 2 == 1
        if (odd) {
          s = v
          odds += 1
        }
      }

      (s, odds == 0 || odds == 2)
    }
  }

  def makeDPath(g: G, m: Int, s0: Int): Option[Array[Int]] = {
    makePath(g, m) { g =>
      val n = g.length

      var s = -1
      val in = Array.ofDim[Int](n)
      REP(n) { v =>
        REP(g(v).length) { i =>
          val u = g(v)(i).u
          in(u) += 1
        }
      }

      var plus, minus = 0
      REP(n) { v =>
        // in - out
        if (in(v) > g(v).length) {
          plus += 1
        } else if (in(v) < g(v).length) {
          minus += 1
          s = v // 収支マイナスの点から始める
        }
      }

      (s0, (s == -1 || s == s0) && (plus == 0 && minus == 0 || plus == 1 && minus == 1))
    } map { path =>
      // ちょうど逆さまになっているので、有向グラフの場合はreverseしないといけない
      REP((m + 1)/2) { i =>
        val t = path(i)
        path(i) = path(m - i)
        path(m - i) = t
      }
      path
    }
  }

  private def makePath(g: G, m: Int)(f: G => (Int, Boolean)): Option[Array[Int]] = {
    val n = g.length
    val path = Array.ofDim[Int](m + 1)
    var pi = 0
    val used = Array.ofDim[Boolean](m)
    val ix = Array.ofDim[Int](n)

    val stack = Array.ofDim[Int](m + 1)
    var si = 0

    val (s, preCondition) = f(g)

    def dfs(s: Int): Unit = {
      stack(si) = s; si += 1
      while(si > 0) {
        val v = stack(si-1)
        while(ix(v) < g(v).length && used(g(v)(ix(v)).id)) ix(v) += 1
        if (ix(v) == g(v).length) {
          si -= 1
          path(pi) = v; pi += 1
        } else {
          used(g(v)(ix(v)).id) = true
          stack(si) = g(v)(ix(v)).u; si += 1; ix(v) += 1
        }
      }
    }

    if (!preCondition) {
      None
    } else {
      dfs(s)
      if (pi == m + 1) Some(path) else None
    }
  }

}
}

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

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

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

  def solve(): Unit = {
    val A, B, C, D = ni()
    val N = A + B + C + D
    val Cnt = Array(A, B, C, D)

    if (N == 1) {
      REP(4) { i =>
        if (Cnt(i) > 0) {
          out.println("YES")
          out.println(i)
          return
        }
      }
    }

    REP(4) { s =>
      REP(4) { t =>
        val cnt = Array.ofDim[Int](4)
        cnt(s) += 1; cnt(t) += 1
        var ok = true
        REP(4) { k =>
          ok &&= Cnt(k) >= cnt(k)
        }
        var e01, e10 = A
        var e23, e32 = D
        if (s == 0) e10 -= 1
        if (t == 0) e01 -= 1
        if (s == 3) e23 -= 1
        if (t == 3) e32 -= 1
        var e21 = B - e01
        var e12 = C - e32
        if (s == 1) e21 -= 1
        if (s == 2) e12 -= 1

        if (e01 >= 0 && e10 >= 0 && e12 >= 0 && e21 >= 0 && e23 >= 0 && e32 >= 0 &&
          e01 + e10 + e12 + e21 + e23 + e32 == N - 1 &&
          e10 + (if (s == 0) 1 else 0) == A &&
          e01 + e21 + (if (s == 1) 1 else 0) == B &&
          e32 + e12 + (if (s == 2) 1 else 0) == C &&
          e23 + (if (s == 3) 1 else 0) == D
        ) {
          val g = Array.fill(4)(ArrayBuffer[Edge]())
          REP(e01) { i => g(0) += Edge(1, i) }
          REP(e10, e01) { i => g(1) += Edge(0, i) }
          REP(e12, e01 + e10) { i => g(1) += Edge(2, i) }
          REP(e21, e01 + e10 + e12) { i => g(2) += Edge(1, i) }
          REP(e23, e01 + e10 + e12 + e21) { i => g(2) += Edge(3, i) }
          REP(e32, e01 + e10 + e12 + e21 + e23) { i => g(3) += Edge(2, i) }
          EulerianTrail.makeDPath(g, N - 1, s) match {
            case None =>
            case Some(path) =>
              debug(s"$s $t $e01 $e10 $e12 $e21 $e23 $e32")
              out.println("YES")
              out.println(path.mkString(" "))
              return
          }
        }
      }
    }
    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[this] val oj = System.getenv("ATCODER_DEBUG") == null
  @inline private final def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  @inline private final def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  @inline def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  @inline private final def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  @inline private final def debugDim(m: Array[Array[Int]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  @inline private final def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  @inline def debug(s: => String): Unit = DEBUG {
    System.err.println(s)
  }
  @inline private final def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }
  private def isDebug[A](debug: => A, online: => A): A = {
    if (oj) online else debug
  }

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

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

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

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

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

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

object Workspace {
  import Main._

  import scala.collection.mutable.ArrayBuffer
  case class Edge(u: Int, id: Int)
  type G = Array[ArrayBuffer[Edge]]

object EulerianTrail {
  def makeUDPath(g: G, m: Int): Option[Array[Int]] = {
    makePath(g, m) { g =>
      val n = g.length
      var odds = 0
      var s = g.indexWhere(_.nonEmpty)
      REP(n) { v =>
        val odd = g(v).length % 2 == 1
        if (odd) {
          s = v
          odds += 1
        }
      }

      (s, odds == 0 || odds == 2)
    }
  }

  def makeDPath(g: G, m: Int): Option[Array[Int]] = {
    makePath(g, m) { g =>
      val n = g.length

      var s = 0
      val in = Array.ofDim[Int](n)
      REP(n) { v =>
        if (g(v).nonEmpty) s = v
        REP(g(v).length) { i =>
          val u = g(v)(i).u
          in(u) += 1
        }
      }

      var plus, minus = 0
      REP(n) { v =>
        // in - out
        if (in(v) > g(v).length) {
          plus += 1
        } else if (in(v) < g(v).length) {
          minus += 1
          s = v // 収支マイナスの点から始める
        }
      }

      (s, plus == 0 && minus == 0 || plus == 1 && minus == 1)
    } map { path =>
      // ちょうど逆さまになっているので、有向グラフの場合はreverseしないといけない
      REP((m + 1)/2) { i =>
        val t = path(i)
        path(i) = path(m - i)
        path(m - i) = t
      }
      path
    }
  }

  private def makePath(g: G, m: Int)(f: G => (Int, Boolean)): Option[Array[Int]] = {
    val n = g.length
    val path = Array.ofDim[Int](m + 1)
    var pi = 0
    val used = Array.ofDim[Boolean](m)
    val ix = Array.ofDim[Int](n)

    val stack = Array.ofDim[Int](m + 1)
    var si = 0

    val (s, preCondition) = f(g)

    def dfs(s: Int): Unit = {
      stack(si) = s; si += 1
      while(si > 0) {
        val v = stack(si-1)
        while(ix(v) < g(v).length && used(g(v)(ix(v)).id)) ix(v) += 1
        if (ix(v) == g(v).length) {
          si -= 1
          path(pi) = v; pi += 1
        } else {
          used(g(v)(ix(v)).id) = true
          stack(si) = g(v)(ix(v)).u; si += 1; ix(v) += 1
        }
      }
    }

    if (!preCondition) {
      None
    } else {
      dfs(s)
      if (pi == m + 1) Some(path) else None
    }
  }

}
}

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

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

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

  def test(e01: Int, e12: Int, e23: Int) = {
    val g = Array.fill(4)(ArrayBuffer[Edge]())
    REP(e01) { i =>
      g(0) += Edge(1, i)
      g(1) += Edge(0, i)
    }
    REP(e12, e01) { i =>
      g(1) += Edge(2, i)
      g(2) += Edge(1, i)
    }
    REP(e23, e01 + e12) { i =>
      g(2) += Edge(3, i)
      g(3) += Edge(2, i)
    }

    EulerianTrail.makeUDPath(g, e01 + e12 + e23)
  }

  def solve(): Unit = {
    val A, B, C, D = ni()
    val N = A + B + C + D
    val Cnt = Array(A, B, C, D)

    if (N == 1) {
      REP(4) { i =>
        if (Cnt(i) > 0) {
          out.println("YES")
          out.println(i)
          return
        }
      }
    }

    REP(4) { i =>
      REP(4) { j =>
        val cnt = Array.ofDim[Int](4)
        cnt(i) += 1; cnt(j) += 1
        var ok = true
        REP(4) { k =>
          ok &&= Cnt(k) >= cnt(k)
        }

        if (ok) {
          var e01 = A * 2
          var e23 = D * 2
          if (i == 0) e01 -= 1
          if (j == 0) e01 -= 1
          if (i == 3) e23 -= 1
          if (j == 3) e23 -= 1
          val e12 = N - 1 - e01 - e23
          if (e01 >= 0 && e12 >= 0 && e23 >= 0) {
            test(e01, e12, e23) match {
              case Some(path) =>
                val used = Array.ofDim[Int](4)
                REP(N) { k =>
                  used(path(k)) += 1
                }
                REP(4) { k =>
                  ok &&= Cnt(k) == used(k)
                }
                if (ok) {
                  debug(s"$i $j $e01 $e12 $e23")
                  out.println("YES")
                  out.println(path.mkString(" "))
                  return
                }

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

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

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

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

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

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

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

object Workspace {
  import Main._

  import scala.collection.mutable.ArrayBuffer
  case class Edge(u: Int, id: Int)
  type G = Array[ArrayBuffer[Edge]]

object EulerianTrail {
  def makeUDPath(g: G, m: Int): Option[Array[Int]] = {
    makePath(g, m) { g =>
      val n = g.length
      var odds = 0
      var s = g.indexWhere(_.nonEmpty)
      REP(n) { v =>
        val odd = g(v).length % 2 == 1
        if (odd) {
          s = v
          odds += 1
        }
      }

      (s, odds == 0 || odds == 2)
    }
  }

  def makeDPath(g: G, m: Int, s0: Int): Option[Array[Int]] = {
    makePath(g, m) { g =>
      val n = g.length

      var s = ArrayBuffer[Int]()
      val in = Array.ofDim[Int](n)
      REP(n) { v =>
        REP(g(v).length) { i =>
          val u = g(v)(i).u
          in(u) += 1
        }
      }

      var plus, minus = 0
      REP(n) { v =>
        // in - out
        if (in(v) > g(v).length) {
          plus += 1
        } else if (in(v) < g(v).length) {
          minus += 1
          s += v // 収支マイナスの点から始める
        }
      }

      (s0, (s.isEmpty || s.contains(s0)) && (plus == 0 && minus == 0 || plus == 1 && minus == 1))
    } map { path =>
      // ちょうど逆さまになっているので、有向グラフの場合はreverseしないといけない
      REP((m + 1)/2) { i =>
        val t = path(i)
        path(i) = path(m - i)
        path(m - i) = t
      }
      path
    }
  }

  private def makePath(g: G, m: Int)(f: G => (Int, Boolean)): Option[Array[Int]] = {
    val n = g.length
    val path = Array.ofDim[Int](m + 1)
    var pi = 0
    val used = Array.ofDim[Boolean](m)
    val ix = Array.ofDim[Int](n)

    val stack = Array.ofDim[Int](m + 1)
    var si = 0

    val (s, preCondition) = f(g)

    def dfs(s: Int): Unit = {
      stack(si) = s; si += 1
      while(si > 0) {
        val v = stack(si-1)
        while(ix(v) < g(v).length && used(g(v)(ix(v)).id)) ix(v) += 1
        if (ix(v) == g(v).length) {
          si -= 1
          path(pi) = v; pi += 1
        } else {
          used(g(v)(ix(v)).id) = true
          stack(si) = g(v)(ix(v)).u; si += 1; ix(v) += 1
        }
      }
    }

    if (!preCondition) {
      None
    } else {
      dfs(s)
      if (pi == m + 1) Some(path) else None
    }
  }

}
}

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

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

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

  def solve(): Unit = {
    val A, B, C, D = ni()
    val N = A + B + C + D
    val Cnt = Array(A, B, C, D)

    if (N == 1) {
      REP(4) { i =>
        if (Cnt(i) > 0) {
          out.println("YES")
          out.println(i)
          return
        }
      }
    }

    REP(4) { s =>
      REP(4) { t =>
        val cnt = Array.ofDim[Int](4)
        cnt(s) += 1; cnt(t) += 1
        var ok = true
        REP(4) { k =>
          ok &&= Cnt(k) >= cnt(k)
        }
        var e01, e10 = A
        var e23, e32 = D
        if (s == 0) e10 -= 1
        if (t == 0) e01 -= 1
        if (s == 3) e23 -= 1
        if (t == 3) e32 -= 1
        var e21 = B - e01
        var e12 = C - e32
        if (s == 1) e21 -= 1
        if (s == 2) e12 -= 1

        if (e01 >= 0 && e10 >= 0 && e12 >= 0 && e21 >= 0 && e23 >= 0 && e32 >= 0 &&
          e01 + e10 + e12 + e21 + e23 + e32 == N - 1 &&
          e10 + (if (s == 0) 1 else 0) == A &&
          e01 + e21 + (if (s == 1) 1 else 0) == B &&
          e32 + e12 + (if (s == 2) 1 else 0) == C &&
          e23 + (if (s == 3) 1 else 0) == D
        ) {
          val g = Array.fill(4)(ArrayBuffer[Edge]())
          REP(e01) { i => g(0) += Edge(1, i) }
          REP(e10, e01) { i => g(1) += Edge(0, i) }
          REP(e12, e01 + e10) { i => g(1) += Edge(2, i) }
          REP(e21, e01 + e10 + e12) { i => g(2) += Edge(1, i) }
          REP(e23, e01 + e10 + e12 + e21) { i => g(2) += Edge(3, i) }
          REP(e32, e01 + e10 + e12 + e21 + e23) { i => g(3) += Edge(2, i) }
          EulerianTrail.makeDPath(g, N - 1, s) match {
            case None =>
            case Some(path) =>
              debug(s"$s $t $e01 $e10 $e12 $e21 $e23 $e32")
              out.println("YES")
              out.println(path.mkString(" "))
              return
          }
        }
      }
    }
    out.println("NO")
  }
}


Vasya decided to pass a very large integer n to Kate. First, he wrote that number as a string, then he appended to the right integer k — the number of digits in n. Magically, all the numbers were shuffled in arbitrary order while this note was passed to Kate. The only thing that Vasya remembers, is a non-empty substring of n (a substring of n is a sequence of consecutive digits of the number n).Vasya knows that there may be more than one way to restore the number n. Your task is to find the smallest possible initial integer n. Note that decimal representation of number n contained no leading zeroes, except the case the integer n was equal to zero itself (in this case a single digit 0 was used).

The first line of the input contains the string received by Kate. The number of digits in this string does not exceed 1 000 000. The second line contains the substring of n which Vasya remembers. This string can contain leading zeroes.  It is guaranteed that the input data is correct, and the answer always exists.

Print the smalles integer n which Vasya could pass to Kate.

import scala.annotation.tailrec

object F670 {
  var t = 0L
  def findLength(finalLength: Int) = {
    var left = 0
    var right = finalLength

    // left <= finalLength, right > finalLength
    while (right - left > 1) {
      val mid = (left + right) / 2

      val len = mid + mid.toString.length

      if (len <= finalLength) left = mid else right = mid
    }

    left
  }
  def minusMap(left: Map[Char, Int], right: Map[Char, Int]): Map[Char, Int] = {
    left
      .flatMap {
        case (key, value) if (right.contains(key) && value == right(key)) => None
        case (key, value) if (right.contains(key)) => Some(key -> (value - right(key)))
        case (key, value) => Some(key -> value)
      }
      .toMap
  }

  def digitMapToString(digitsMap: Map[Char, Int]) = {
    val ret = ('0' to '9').map { case c =>
      c.toString * digitsMap.getOrElse(c, 0)
    }.mkString("")

    ret
  }

  def getPartition(digitsMap: Map[Char, Int], subString: String) = {
    val nonZero = digitsMap - '0'

    nonZero.size match {
      case 0 => Seq[String](subString + digitMapToString(digitsMap))
      case _ =>
        val (head, count) = nonZero.min
        val trimmedDigitsMap = if (count == 1)
            digitsMap - head
          else
            digitsMap.updated(head, count - 1)
        trimmedDigitsMap.map { case (key, _) =>
          val (before, equalOrAfter) = trimmedDigitsMap.partition { case (iKey, _) => iKey < key }

          head + digitMapToString(before) + subString + digitMapToString(equalOrAfter)
        } ++ Seq(
          head + digitMapToString(trimmedDigitsMap) + subString
        )
    }
  }

  def main(args: Array[String]) {
          t -= System.nanoTime()
    val unOrderedString = readLine
    val subString = readLine

    val length = findLength(unOrderedString.length)

    def stringToMap(str: String) = str.toString.groupBy{c => c}.map { case (key, value) => (key, value.length)}

    val lengthMap = stringToMap(length.toString)
    val fullMap = stringToMap(unOrderedString)
    val subStringMap = stringToMap(subString)
    val digitsMap = minusMap(minusMap(fullMap, lengthMap), subStringMap)

    val candidates = Seq(
      subString + digitMapToString(digitsMap),
      digitMapToString(digitsMap) + subString
    ) ++ getPartition(digitsMap, subString)

    val result = candidates.sorted.filter{ case str => str(0) != '0' }.headOption match {
      case Some(str) => str
      case _ => candidates(0)
    }

          t += System.nanoTime()
    println(result)
    //println(t / 1000000)
  }
}

object F670 {
  def findLength(finalLength: Int, length: Int): Int = {
    if (length + length.toString.length == finalLength) length
    else findLength(finalLength, length - 1)
  }

  def minusMap(left: Map[Char, Int], right: Map[Char, Int]): Map[Char, Int] = {
    left.flatMap {
        case (key, value) if (right.contains(key) && value == right(key)) => None
        case (key, value) if (right.contains(key)) => Some(key -> (value - right(key)))
        case (key, value) => Some(key -> value)
      }
      .toMap
  }

  def digitMapToString(digitsMap: Map[Char, Int]) = ('0' to '9').map { case c => c.toString * digitsMap.getOrElse(c, 0) }.mkString("")

  def getPartition(digitsMap: Map[Char, Int], subString: String) = {
    val nonZero = digitsMap - '0'

    nonZero.size match {
      case 0 => Seq[String](subString + digitMapToString(digitsMap))
      case _ =>
        val (head, count) = nonZero.min
        val trimmedDigitsMap = if (count == 1) digitsMap - head else digitsMap.updated(head, count - 1)
        trimmedDigitsMap.map { case (key, _) =>
          val (before, equalOrAfter) = trimmedDigitsMap.partition { case (iKey, _) => iKey < key }
          head + digitMapToString(before) + subString + digitMapToString(equalOrAfter)
        } ++ Seq(
          head + digitMapToString(trimmedDigitsMap) + subString
        )
    }
  }

  def main(args: Array[String]) {
    val unOrderedString = readLine
    val subString = readLine

    val length = findLength(unOrderedString.length, unOrderedString.length)

    def stringToMap(str: String) = str.toString.groupBy{c => c}.map { case (key, value) => (key, value.length)}

    val lengthMap = stringToMap(length.toString)
    val fullMap = stringToMap(unOrderedString)
    val subStringMap = stringToMap(subString)
    val digitsMap = minusMap(minusMap(fullMap, lengthMap), subStringMap)

    val candidates = Seq(
      subString + digitMapToString(digitsMap),
      digitMapToString(digitsMap) + subString
    ) ++ getPartition(digitsMap, subString)

    val result = candidates.sorted.filter{ case str => str(0) != '0' }.headOption match {
      case Some(str) => str
      case _ => candidates(0)
    }

    println(result)
  }
}

import scala.annotation.tailrec

object F670 {
  def findLength(finalLength: Int) = {
    var left = 0
    var right = finalLength

    // left <= finalLength, right > finalLength
    while (right - left > 1) {
      val mid = (left + right) / 2

      val len = mid + mid.toString.length

      if (len <= finalLength) {
        left = mid
      } else {
        right = mid
      }
    }

    left
  }

  def findHead(
    digitsMap: Map[Char, Int],
    head: Char,
    result: String
  ): (String, Map[Char, Int]) = {
    if (digitsMap.size == 0)
      (result, digitsMap)
    else {
      val (smallestKey, smallestValue) = digitsMap.min
      if (smallestKey > head) {
        (result, digitsMap)
      } else {
        findString(digitsMap, result, '1', head)
      }
    }
  }

  def consumeDigit(digitsMap: Map[Char, Int], start: Char) = {
    if (digitsMap(start) == 1)
      digitsMap - start
    else
      digitsMap.updated(start, digitsMap(start) - 1)
  }

  @tailrec def findString(
    digitsMap: Map[Char, Int],
    result: String,
    start: Char,
    top: Char
  ): (String, Map[Char, Int]) = {
    //println(s"findString with $result, $start, $top")
    if (start > '9' || digitsMap.size == 0 || digitsMap.min._1 > top)
      (result, digitsMap)
    else if (result.length == 0) {
      if (digitsMap.contains(start)) {
        findString(
          consumeDigit(digitsMap, start),
          result + start.toString,
          '0',
          top)
      } else {
        findString(
          digitsMap,
          result,
          (start + 1).asInstanceOf[Char],
          top)
      }
    } else {
      if (digitsMap.contains(start)) {
        val newDigitsMap = digitsMap - start
        findString(newDigitsMap, result + List.fill(digitsMap(start))(start).mkString(""), start, top)
      } else {
        findString(digitsMap, result, (start + 1).asInstanceOf[Char], top)
      }
    }
  }

  @tailrec def findTail(digitsMap: Map[Char, Int], result: String): String = {
    if (digitsMap.size == 0) {
      return result
    } else {
      val (digit, count) = digitsMap.min
      findTail(digitsMap - digit, result + List.fill(count)(digit).mkString(""))
    }
  }

  def minusMap(left: Map[Char, Int], right: Map[Char, Int]): Map[Char, Int] = {
    left
      .flatMap {
        case (key, value) if (right.contains(key) && value == right(key)) => None
        case (key, value) if (right.contains(key)) => Some(key -> (value - right(key)))
        case (key, value) => Some(key -> value)
      }
      .toMap
  }

  def shouldEqual(subString: String): Boolean = {
    if (subString.length == 0)
      true
    else if (subString.length == 1)
      true
    else {
      if (subString(0) == subString(1)) {
        shouldEqual(subString.tail)
      } else {
        subString(0) < subString(1)
      }
    }
  }

  var tt = 0

  def main(args: Array[String]) {
    val unOrderedString = readLine
    val subString = readLine

    val length = findLength(unOrderedString.length)

    def stringToMap(str: String) = str.toString.groupBy{c => c}.map { case (key, value) => (key, value.length)}

    val lengthMap = stringToMap(length.toString)
    val fullMap = stringToMap(unOrderedString)
    val subStringMap = stringToMap(subString)
    val digitsMap = minusMap(minusMap(fullMap, lengthMap), subStringMap)

    val top = if (shouldEqual(subString)) {
      subString(0)
    } else {
      (subString(0) - 1).asInstanceOf[Char]
    }
    val (prefix, updatedMap) = findHead(digitsMap, top, "")

    val (prefixPlus, tailDigitsMap) = if (updatedMap.size == 0) {
        (prefix + subString, updatedMap)
      }
      else if (prefix.length == 0 && subString(0) == '0') {
        val (head, size) = updatedMap.min
        (head + subString, consumeDigit(updatedMap, head))
      } else {
        (prefix + subString, updatedMap)
      }

    println(prefixPlus + findTail(tailDigitsMap, ""))
  }
}

import scala.annotation.tailrec

object F670 {
  def findLength(finalLength: Int) = {
    var left = 0
    var right = finalLength

    // left <= finalLength, right > finalLength
    while (right - left > 1) {
      val mid = (left + right) / 2

      val len = mid + mid.toString.length

      if (len <= finalLength) {
        left = mid
      } else {
        right = mid
      }
    }

    left
  }

  def findHead(
    digitsMap: Map[Char, Int],
    head: Char,
    top: Char,
    result: String
  ): (String, Map[Char, Int]) = {
    if (digitsMap.size == 0)
      (result, digitsMap)
    else {
      val (smallestKey, smallestValue) = digitsMap.min
      if (smallestKey > head) {
        (result, digitsMap)
      } else {
        findString(digitsMap, result, '1', if (head == '0') '9' else top)
      }
    }
  }

  def consumeDigit(digitsMap: Map[Char, Int], start: Char) = {
    if (digitsMap(start) == 1)
      digitsMap - start
    else
      digitsMap.updated(start, digitsMap(start) - 1)
  }

  @tailrec def findString(
    digitsMap: Map[Char, Int],
    result: String,
    start: Char,
    top: Char
  ): (String, Map[Char, Int]) = {
    // println(s"findString with $result, $start, $top")
    if (start > top || digitsMap.size == 0 || digitsMap.min._1 > top)
      (result, digitsMap)
    else if (result.length == 0) {
      if (digitsMap.contains(start)) {
        findString(
          consumeDigit(digitsMap, start),
          result + start.toString,
          '0',
          top)
      } else {
        findString(
          digitsMap,
          result,
          (start + 1).asInstanceOf[Char],
          top)
      }
    } else {
      if (digitsMap.contains(start)) {
        val newDigitsMap = digitsMap - start
        findString(newDigitsMap, result + List.fill(digitsMap(start))(start).mkString(""), start, top)
      } else {
        findString(digitsMap, result, (start + 1).asInstanceOf[Char], top)
      }
    }
  }

  @tailrec def findTail(digitsMap: Map[Char, Int], result: String): String = {
    if (digitsMap.size == 0) {
      return result
    } else {
      val (digit, count) = digitsMap.min
      findTail(digitsMap - digit, result + List.fill(count)(digit).mkString(""))
    }
  }

  def minusMap(left: Map[Char, Int], right: Map[Char, Int]): Map[Char, Int] = {
    left
      .flatMap {
        case (key, value) if (right.contains(key) && value == right(key)) => None
        case (key, value) if (right.contains(key)) => Some(key -> (value - right(key)))
        case (key, value) => Some(key -> value)
      }
      .toMap
  }

  def shouldEqual(subString: String): Boolean = {
    if (subString.length == 0)
      true
    else if (subString.length == 1)
      true
    else {
      if (subString(0) == subString(1)) {
        shouldEqual(subString.tail)
      } else {
        subString(0) < subString(1)
      }
    }
  }

  var tt = 0

  def main(args: Array[String]) {
    val unOrderedString = readLine
    val subString = readLine

    val length = findLength(unOrderedString.length)

    def stringToMap(str: String) = str.toString.groupBy{c => c}.map { case (key, value) => (key, value.length)}

    val lengthMap = stringToMap(length.toString)
    val fullMap = stringToMap(unOrderedString)
    val subStringMap = stringToMap(subString)
    val digitsMap = minusMap(minusMap(fullMap, lengthMap), subStringMap)

    val top = if (shouldEqual(subString)) {
      subString(0)
    } else {
      (subString(0) - 1).asInstanceOf[Char]
    }
    val (prefix, updatedMap) = findHead(digitsMap, subString(0), top, "")

    // println(top + ", " + prefix)

    val (prefixPlus, tailDigitsMap) = if (updatedMap.size == 0) {
        (prefix + subString, updatedMap)
      }
      else if (prefix.length == 0 && subString(0) == '0') {
        val (head, size) = updatedMap.min
        (head + subString, consumeDigit(updatedMap, head))
      } else {
        (prefix + subString, updatedMap)
      }

    println(prefixPlus + findTail(tailDigitsMap, ""))
  }
}

import scala.annotation.tailrec

object F670 {
  def findLength(finalLength: Int) = {
    var left = 0
    var right = finalLength

    // left <= finalLength, right > finalLength
    while (right - left > 1) {
      val mid = (left + right) / 2

      val len = mid + mid.toString.length

      if (len <= finalLength) left = mid else right = mid
    }

    left
  }

  def findHead(
    digitsMap: Map[Char, Int],
    head: Char,
    top: Char,
    result: String
  ): (String, Map[Char, Int]) = {
    if (digitsMap.size == 0)
      (result, digitsMap)
    else {
      val (smallestKey, smallestValue) = digitsMap.min
      if (head == '0') {
        val lowest = (digitsMap - '0').min._1
        (lowest + List.fill(digitsMap.getOrElse('0', 0))('0').mkString(""), consumeDigit(digitsMap, lowest) - '0')
      } else if (smallestKey >= head){
        (result, digitsMap)
      } else {
        findString(digitsMap, result, '1', top)
      }
    }
  }

  def consumeDigit(digitsMap: Map[Char, Int], start: Char) = {
    if (digitsMap(start) == 1)
      digitsMap - start
    else
      digitsMap.updated(start, digitsMap(start) - 1)
  }

  @tailrec def findString(
    digitsMap: Map[Char, Int],
    result: String,
    start: Char,
    top: Char
  ): (String, Map[Char, Int]) = {
    // println(s"findString with $result, $start, $top")
    if (start > top || digitsMap.size == 0 || digitsMap.min._1 > top)
      (result, digitsMap)
    else if (result.length == 0) {
      if (digitsMap.contains(start)) {
        findString(
          consumeDigit(digitsMap, start),
          result + start.toString,
          '0',
          top)
      } else {
        findString(
          digitsMap,
          result,
          (start + 1).asInstanceOf[Char],
          top)
      }
    } else {
      if (digitsMap.contains(start)) {
        val newDigitsMap = digitsMap - start
        findString(newDigitsMap, result + List.fill(digitsMap(start))(start).mkString(""), start, top)
      } else {
        findString(digitsMap, result, (start + 1).asInstanceOf[Char], top)
      }
    }
  }

  @tailrec def findTail(digitsMap: Map[Char, Int], result: String): String = {
    if (digitsMap.size == 0) {
      return result
    } else {
      val (digit, count) = digitsMap.min
      findTail(digitsMap - digit, result + List.fill(count)(digit).mkString(""))
    }
  }

  def minusMap(left: Map[Char, Int], right: Map[Char, Int]): Map[Char, Int] = {
    left
      .flatMap {
        case (key, value) if (right.contains(key) && value == right(key)) => None
        case (key, value) if (right.contains(key)) => Some(key -> (value - right(key)))
        case (key, value) => Some(key -> value)
      }
      .toMap
  }

  def shouldEqual(subString: String): Boolean = {
    if (subString.length == 0)
      true
    else if (subString.length == 1)
      true
    else {
      if (subString(0) == subString(1)) {
        shouldEqual(subString.tail)
      } else {
        subString(0) < subString(1)
      }
    }
  }

  var tt = 0

  def main(args: Array[String]) {
    val unOrderedString = readLine
    val subString = readLine

    val length = findLength(unOrderedString.length)

    def stringToMap(str: String) = str.toString.groupBy{c => c}.map { case (key, value) => (key, value.length)}

    val lengthMap = stringToMap(length.toString)
    val fullMap = stringToMap(unOrderedString)
    val subStringMap = stringToMap(subString)
    val digitsMap = minusMap(minusMap(fullMap, lengthMap), subStringMap)

    val top = if (shouldEqual(subString)) {
      subString(0)
    } else {
      (subString(0) - 1).asInstanceOf[Char]
    }
    val (prefix, updatedMap) = findHead(digitsMap, subString(0), top, "")

    // println(top + ", " + prefix)

    val (prefixPlus, tailDigitsMap) = if (updatedMap.size == 0) {
        (prefix + subString, updatedMap)
      }
      else if (prefix.length == 0 && subString(0) == '0') {
        val (head, size) = updatedMap.min
        (head + subString, consumeDigit(updatedMap, head))
      } else {
        (prefix + subString, updatedMap)
      }

    println(prefixPlus + findTail(tailDigitsMap, ""))
  }
}


You are given two even integers $$$n$$$ and $$$m$$$. Your task is to find any binary matrix $$$a$$$ with $$$n$$$ rows and $$$m$$$ columns where every cell $$$(i,j)$$$ has exactly two neighbours with a different value than $$$a_{i,j}$$$.Two cells in the matrix are considered neighbours if and only if they share a side. More formally, the neighbours of cell $$$(x,y)$$$ are: $$$(x-1,y)$$$, $$$(x,y+1)$$$, $$$(x+1,y)$$$ and $$$(x,y-1)$$$.It can be proven that under the given constraints, an answer always exists.

Each test contains multiple test cases. The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The following lines contain the descriptions of the test cases. The only line of each test case contains two even integers $$$n$$$ and $$$m$$$ ($$$2 \le n,m \le 50$$$) — the height and width of the binary matrix, respectively.

For each test case, print $$$n$$$ lines, each of which contains $$$m$$$ numbers, equal to $$$0$$$ or $$$1$$$ — any binary matrix which satisfies the constraints described in the statement. It can be proven that under the given constraints, an answer always exists.

NoteWhite means $$$0$$$, black means $$$1$$$. The binary matrix from the first test caseThe binary matrix from the second test caseThe binary matrix from the third test case

import scala.io.StdIn

object Main extends App {
  val t = StdIn.readInt()
  for(i <- 0 until t){
    val n = StdIn.readLine().split(" ").map(_.toInt)
    for(i <- 0 until n(0)) {
      for(j <- 0 until n(1)){
        var ans = i&3 ^ j&3
        ans = (ans&1) ^ (ans>>1)
        print(ans + " ")
      }
      println()
    }
  }
}

import scala.collection.mutable

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

class Resolver3(input: java.io.BufferedReader, output: java.io.PrintStream) {
  import java.util.StringTokenizer
  def run() {
    def str1(m:Int): String = {
      var l = new StringBuilder
      l ++=  "1"
      if ((m % 4) == 2) {
        if (m!=2) {
          for (i <- 1 to (m-2)/4 ) {
            l++= " 0 0 1 1"
          }
        }

        l++= " 0"
      }
      else {
        if (m != 4) {
          for (i <- 1 to (m - 4) / 4) {
            l ++= " 0 0 1 1"
          }
      }
        l ++= " 0 0 1"
      }
      l.toString
    }
    def str2(m:Int): String = {
      val l = new StringBuilder
      l++= "0"
      if ((m % 4) == 2) { if (m!=2) {
        for (i <- 1 to (m-2)/4 ) {
          l++= " 1 1 0 0"
        }
      }
        l++= " 1"
      }
      else {
        if (m!=4) {
          for (i <- 1 to (m - 4) / 4) {
          l ++= " 1 1 0 0"
        }
      }
      l ++= " 1 1 0"
      }
      l.toString
    }
    var tokenizer = new StringTokenizer(input.readLine())
    val q = tokenizer.nextToken().toInt
    for (i <- 1 to q){
      tokenizer = new StringTokenizer(input.readLine())
      val n = tokenizer.nextToken().toInt
      val m = tokenizer.nextToken().toInt
      val ch = str1(m)
      val ne = str2(m)
      if ((n % 4) == 0) {
        for (j <-1 to (n)/4) {
          output.println(ch)
          output.println(ne)
          output.println(ne)
          output.println(ch)
        }
      }
      else {
        if (n!=2){
          for (j <-1 to (n-2)/4) {
            output.println(ch)
            output.println(ne)
            output.println(ne)
            output.println(ch)
          }
        }

        output.println(ch)
        output.println(ne)
      }
    }
  }

}

import scala.io.StdIn

object Main extends App {
  val t = StdIn.readInt()
  for(i <- 0 until t){
    val n = StdIn.readLine().split(" ").map(_.toInt)
    for(i <- 0 until n(0)) {
      for(j <- 0 until n(1)){
        print(((i ^ j) ^ ((i ^ j) >> 1)) & 1 )
      }
      println()
    }
  }
}


After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game «Call of Soldiers 3».The game has (m + 1) players and n types of soldiers in total. Players «Call of Soldiers 3» are numbered form 1 to (m + 1). Types of soldiers are numbered from 0 to n - 1. Each player has an army. Army of the i-th player can be described by non-negative integer xi. Consider binary representation of xi: if the j-th bit of number xi equal to one, then the army of the i-th player has soldiers of the j-th type. Fedor is the (m + 1)-th player of the game. He assume that two players can become friends if their armies differ in at most k types of soldiers (in other words, binary representations of the corresponding numbers differ in at most k bits). Help Fedor and count how many players can become his friends.

The first line contains three integers n, m, k (1 ≤ k ≤ n ≤ 20; 1 ≤ m ≤ 1000). The i-th of the next (m + 1) lines contains a single integer xi (1 ≤ xi ≤ 2n - 1), that describes the i-th player's army. We remind you that Fedor is the (m + 1)-th player.

Print a single integer — the number of Fedor's potential friends.

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, m, k) = in.next().split(" ").map(_.toInt)
  val data = Range(0, m).map(_ => in.next().toInt)
  val f = in.next().toInt

  println(data.map(_ ^ f).map(_.toBinaryString.count(_ == '1')).count(_ <= k))
}

object B467 {
  @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, m, k) = readInts(3)
    val input = Array.fill(m+1)(readBigs(1)).map{ x =>
      val s = x(0).toString(2)
      Array.fill[Char](n - s.length)('0') ++  s.toCharArray
    }
    val compare = input(m)

    var res = 0
    for(i <- 0 until m) {
      var diff = 0
      for (j <- 0 until n) {
        if(input(i)(j) != compare(j))
          diff += 1
      }
      if(diff <= k)
        res += 1
    }

    println(res)
  }
}

import scala.io.StdIn

object A extends App {

  val Array(n, m, k) = StdIn.readLine().split(" ").map(_.toInt)
  val arr = (1 to m).map( _ => StdIn.readInt())
  val a = StdIn.readInt()
  val res = arr.map { x =>
    if((x ^ a).toBinaryString.filter(_ == '1').length <= k) 1 else 0
  }.sum
  println(res)
}

import scala.io.StdIn

/**
 * @author unit7
 */
object Main {
  def main(args: Array[String]) {
    val counters = StdIn
                    .readLine()
                    .split("\\s")
                    .map(_.toInt)

    val m = counters(1)

    val armies = new Array[Int](m + 1)

    val k = counters(2)
    for (i <- 0 to m) {
      armies(i) = StdIn.readInt()
    }

    val fedor = armies(m)
    var canFriendCount = 0

    for (i <- 0 until m) {
      val differ = (fedor ^ armies(i))
                      .toBinaryString
                      .count(_ == '1')

      if (differ <= k)
        canFriendCount += 1
    }

    println(canFriendCount)
  }
}

import scala.io.StdIn._

object FedorandNewGame extends App {
  val n :: m :: k :: Nil = readLine().split(" ").map(_.toInt).toList
  val a = Array.ofDim[Int](m)
  for (i <- 0 until m) {
    a(i) = readInt()
  }
  val p = readInt()
  val result = a.foldLeft(0) { (acc, x) =>
    val g = p ^ x
    if (Integer.bitCount(g) <= k) acc + 1
    else acc
  }
  println(result)
}

import java.io.PrintWriter
import java.util.Scanner

/**
 * Created by arseny on 18.09.14.
 */
object B extends App {
  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextInt = in.nextInt
  def nextLong = in.nextLong
  def nextDouble = in.nextDouble
  def nextString = in.next

  def solve() = {
    val n = nextInt
    val m = nextInt
    val k = nextInt
    val xs = Array.fill(m + 1)("")
    for(i <- 0 until m + 1) {
      xs(i) = nextInt.toBinaryString.reverse
    }
    def countDiff(s: String, t: String): Int = {
      var diff = 0
      for(i <- 0 until math.min(s.length, t.length)) {
        if(s(i) != t(i)) {
          diff += 1
        }
      }
      if(s.length < t.length) {
        for(i <- s.length until t.length) {
          if(t(i) == '1') {
            diff += 1
          }
        }
      } else {
        for(i <- t.length until s.length) {
          if(s(i) == '1') {
            diff += 1
          }
        }
      }
      diff
    }
    val nFriends = (for(i <- 0 until xs.length - 1) yield countDiff(xs(i), xs(m)) <= k).count(_ == true)
    out.print(nFriends)
  }

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

import java.util.StringTokenizer

object _467B extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val m = next.toInt
  val k = next.toInt
  val a = (0 to m).map(i => next.toInt)
  val ans = for {
    i <- 0 until m
    if (Integer.bitCount((a(i) ^ a(m))) <= k)
  } yield 1
  println(ans.sum)
}

object B467 {
  @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, m, k) = readInts(3)
    val input = Array.fill(m+1)(readBigs(1)).map(_(0))
    var res = 0
    for(i <- 0 until m) {
      val bits = (input(i) & input(m)).bitCount
      if(bits >= n-k) {
        res += 1
      }
    }
    println(res)
  }
}

import scala.io.StdIn

object A extends App {

  val Array(n, m, k) = StdIn.readLine().split(" ").map(_.toInt)
  val arr = (1 to m).map( _ => StdIn.readInt())
  val a = StdIn.readInt()
  val res = arr.map { x =>
    if(n - (x & a).toBinaryString.filter(_ == '1').length <= k) 1 else 0
  }.sum
  println(res)
}


Polycarp found a rectangular table consisting of $$$n$$$ rows and $$$m$$$ columns. He noticed that each cell of the table has its number, obtained by the following algorithm "by columns":   cells are numbered starting from one;  cells are numbered from left to right by columns, and inside each column from top to bottom;  number of each cell is an integer one greater than in the previous cell. For example, if $$$n = 3$$$ and $$$m = 5$$$, the table will be numbered as follows:$$$$$$ \begin{matrix} 1 & 4 & 7 & 10 & 13 \\ 2 & 5 & 8 & 11 & 14 \\ 3 & 6 & 9 & 12 & 15 \\ \end{matrix} $$$$$$However, Polycarp considers such numbering inconvenient. He likes the numbering "by rows":   cells are numbered starting from one;  cells are numbered from top to bottom by rows, and inside each row from left to right;  number of each cell is an integer one greater than the number of the previous cell. For example, if $$$n = 3$$$ and $$$m = 5$$$, then Polycarp likes the following table numbering: $$$$$$ \begin{matrix} 1 & 2 & 3 & 4 & 5 \\ 6 & 7 & 8 & 9 & 10 \\ 11 & 12 & 13 & 14 & 15 \\ \end{matrix} $$$$$$Polycarp doesn't have much time, so he asks you to find out what would be the cell number in the numbering "by rows", if in the numbering "by columns" the cell has the number $$$x$$$?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. Each test case consists of a single line containing three integers $$$n$$$, $$$m$$$, $$$x$$$ ($$$1 \le n, m \le 10^6$$$, $$$1 \le x \le n \cdot m$$$), where $$$n$$$ and $$$m$$$ are the number of rows and columns in the table, and $$$x$$$ is the cell number. Note that the numbers in some test cases do not fit into the $$$32$$$-bit integer type, so you must use at least the $$$64$$$-bit integer type of your programming language.

For each test case, output the cell number in the numbering "by rows".

import scala.io.StdIn.readLine

object MyNewClass extends App {
  val t = readLine.toInt
  for (_ <- 1 to t ) {
    val nmx: Seq[BigInt] = readLine.split(' ').toList.map(x => BigInt(x))
    val n = nmx(0)
    val m = nmx(1)
    val x = nmx(2)
    val row = Row(n)
    val col = Col(m)

    val indices = getIndicesForColumnOrdering(x, row)
    val numberForRowOrdering = getNumberForRowOrderingIndices(row, col, indices)
    println(numberForRowOrdering)
  }

  final case class Row(value : BigInt)
  final case class Col(value : BigInt)

  def getIndicesForColumnOrdering(number : BigInt, row : Row) : (Row, Col) = {
    val r = (number % row.value -1 + row.value) % row.value + 1
    val c = (number-1) / row.value + 1
    (Row(r), Col(c))
  }

  def getNumberForRowOrderingIndices(row : Row, col : Col, indices : (Row, Col)): BigInt ={
    (indices._1.value - 1) * col.value + indices._2 .value
  }
}


You are given a string $$$s$$$ consisting of lowercase Latin letters and $$$q$$$ queries for this string.Recall that the substring $$$s[l; r]$$$ of the string $$$s$$$ is the string $$$s_l s_{l + 1} \dots s_r$$$. For example, the substrings of "codeforces" are "code", "force", "f", "for", but not "coder" and "top".There are two types of queries:   $$$1~ pos~ c$$$ ($$$1 \le pos \le |s|$$$, $$$c$$$ is lowercase Latin letter): replace $$$s_{pos}$$$ with $$$c$$$ (set $$$s_{pos} := c$$$);  $$$2~ l~ r$$$ ($$$1 \le l \le r \le |s|$$$): calculate the number of distinct characters in the substring $$$s[l; r]$$$.

The first line of the input contains one string $$$s$$$ consisting of no more than $$$10^5$$$ lowercase Latin letters. The second line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^5$$$) — the number of queries. The next $$$q$$$ lines contain queries, one per line. Each query is given in the format described in the problem statement. It is guaranteed that there is at least one query of the second type.

For each query of the second type print the answer for it — the number of distinct characters in the required substring in this query.

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

  import Main._
  import fScanner._

  def solve(): Unit = {
    val s: Array[Char] = ns().toCharArray
    val segment = new SegmentTree(s.length, s)
    segment.build(1, 0, s.length - 1)
    val q = ni()
    REP(q) { _ =>
      ni() match {
        case 1 =>
          val pos = ni()
          val c = nc()
          segment.update(1, 0, s.length - 1, pos - 1, c)
        case 2 =>
          val l = ni()
          val r = ni()
          out.println(segment.get(1, 0, s.length - 1, l-1, r-1).distinctCount)
      }

    }
  }

  case class Node (distinctCount: Int, bits: Long)

  private class SegmentTree(n: Int, s: Array[Char]) {

    private val tree: Array[Node] = Array.ofDim[Node](4 * n)

    private def combine(x: Node, y: Node): Node = {
      val z = x.bits | y.bits
      Node(java.lang.Long.bitCount(z), z)
    }

    def build(v: Int, tl: Int, tr: Int): Unit = {
      if(tl == tr) {
        tree(v) = Node(1, 1 << (s(tl) - 'a'))
      } else {
        val tm = tl + (tr - tl) / 2
        build(v << 1, tl, tm)
        build(v << 1 | 1, tm + 1, tr)
        tree(v) = combine(tree(v << 1), tree(v << 1 | 1))
      }
    }

    def update(v: Int, tl: Int, tr: Int, pos: Int, value: Char): Unit = {
      if(tl == tr) {
        tree(v) = Node(1, 1 << (value - 'a'))
      } else {
        val tm = tl + (tr - tl) / 2
        if(pos <= tm) {
          update(v << 1, tl ,tm, pos, value)
        } else {
          update(v << 1 | 1, tm + 1, tr, pos, value)
        }
        tree(v) = combine(tree(v << 1), tree(v << 1 | 1))
      }
    }

    def get(v: Int, tl: Int, tr: Int, l: Int, r: Int): Node = {
      if(r < tl || l > tr || l > r) {
        Node(0, 0)
      }
      else if(l == tl && r == tr) tree(v)
      else {
        val tm = tl + (tr - tl) / 2
        combine(get(v << 1, tl, tm, l, Math.min(r, tm)), get(v << 1 | 1, tm+1, tr, Math.max(l, tm+1), r))
      }
    }
  }
}

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

  override def solve(io: IO) = {
    val s = io.read[String].toArray

    val table = ('a' to 'z').map(c => c -> new java.util.TreeSet[Int]).toMap
    s.zipWithIndex foreach {case (c, i) => table(c) add i}

    repeat(io.read[Int]) {
      io.read[Int] match {
        case 1 =>
          val pos = io.read[Int] - 1
          val c = io.read[String].head
          table(s(pos)) remove pos
          table(c) add pos
          s(pos) = c

        case _ =>
          val l = io.read[Int] - 1
          val r = io.read[Int] - 1
          val ans = table.values.count({ s => Option(s.ceiling(l)).exists(_ <= r)})
          io.writeLine(ans)
      }
    }
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def solve(io: IO): Any
  def main(args: Array[String]): Unit = {
    val io = new IO(System.in, System.out)
    try solve(io) finally io.close()
  }
}
/****************************[Scala Collection Utils]****************************************/
object Utils {
  import scala.collection.mutable

  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]

  def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None

  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)

  implicit class GenericExtensions[A](a: A) {
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }

  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](t: C[A]) {
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]

    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)

    def toMultiSet(withDefaultZero: Boolean): Map[A, Int] = {
      val freqTable = t.groupBy(identity).mapValues(_.size)
      if (withDefaultZero) freqTable.withDefaultValue(0) else freqTable
    }
  }

  implicit class PairExtensions[A, B](p: (A, B)) {
    def key = p._1
    def value = p._2
    def toSeq(implicit ev: B =:= A): Seq[A] = Seq(p.key, ev(p.value))
  }

  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C]).withDefaultValue(b().result())
  }

  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](m: C[K, V]) {
    def toMutable: mutable.Map[K, V] = mutable.Map.empty[K, V] ++ m
  }

  implicit class SetExtensions[A, C[A] <: Set[A]](s: C[A]) {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }

  implicit class IterableExtensions[A, C[A] <: Seq[A]](s: C[A]) {
    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
  }

  implicit class BooleanExtensions(x: Boolean) {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "Yes" else "No"
  }

  implicit class IntExtensions(val x: Int) extends AnyVal {
    @inline def isEven = x%2 == 0
    @inline def isOdd = x%2 == 1
  }

  def desc[A](implicit order: Ordering[A]): Ordering[A] = order.reverse  //e.g. students.sortBy(_.height)(desc)

  def map[K] = new {
    def to[V](default: => V): mutable.Map[K, V] = using(_ => default)
    def using[V](f: K => V): mutable.Map[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }

  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]

  def memoize[A, B](f: A => B): A => B = map[A] using f
}
/***********************************[Scala I/O]*********************************************/
import java.io._, java.util.StringTokenizer
import scala.collection.generic.CanBuild

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

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

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

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: CanBuild[A, C[A]]): C[A] = Iterator.fill(n)(read).to[C]
  def readTill(delim: String): String = tokenizer().get.nextToken(delim)
  def readTillEndOfLine(): String = readTill("\n\r")

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

  def write(obj: Any*): this.type = writeAll(obj)
  def writeLine(obj: Any*): this.type = {if (obj.isEmpty) printer.println() else obj.foreach(printer.println); this}
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = {printer.print(obj.mkString(separator)); this}
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  def repeat(f: => Unit): Unit = Utils.repeat(read[Int]){f; writeLine()}

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


Theofanis has a string $$$s_1 s_2 \dots s_n$$$ and a character $$$c$$$. He wants to make all characters of the string equal to $$$c$$$ using the minimum number of operations.In one operation he can choose a number $$$x$$$ ($$$1 \le x \le n$$$) and for every position $$$i$$$, where $$$i$$$ is not divisible by $$$x$$$, replace $$$s_i$$$ with $$$c$$$. Find the minimum number of operations required to make all the characters equal to $$$c$$$ and the $$$x$$$-s that he should use in his operations.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$3 \le n \le 3 \cdot 10^5$$$) and a lowercase Latin letter $$$c$$$ — the length of the string $$$s$$$ and the character the resulting string should consist of. The second line of each test case contains a string $$$s$$$ of lowercase Latin letters — the initial string. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For each test case, firstly print one integer $$$m$$$ — the minimum number of operations required to make all the characters equal to $$$c$$$. Next, print $$$m$$$ integers $$$x_1, x_2, \dots, x_m$$$ ($$$1 \le x_j \le n$$$) — the $$$x$$$-s that should be used in the order they are given. It can be proved that under given constraints, an answer always exists. If there are multiple answers, print any.

NoteLet's describe what happens in the third test case:   $$$x_1 = 2$$$: we choose all positions that are not divisible by $$$2$$$ and replace them, i. e. bzyx $$$\rightarrow$$$ bzbx;  $$$x_2 = 3$$$: we choose all positions that are not divisible by $$$3$$$ and replace them, i. e. bzbx $$$\rightarrow$$$ bbbb.

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

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

    case class myType(var social: Int, var cp:  Int, var ind: Int)extends Ordered[myType] {
        override def compare(that: myType): Int = {
            if (social < that.social)
                return -1
            else if (social == that.social)
                return 0
            else
                return 1
        }
    }
    val rem = 1000000007

    val t = readInt()
    for (tt <- 1 to t) {
        val n = readInt()
        val c = readString()(0)
        val s = readString()
        var cnt = 0
        for (ch <- s) {
            if (ch != c)
                cnt += 1
        }
        if (cnt == 0) {
            writer.println(0)
        } else {
            var ans = n+1
            var found = false
            while (ans > 1 && !found) {
                ans -= 1
                var ok = true
                var mul = ans
                while (mul <= n && ok) {
                    if (s(mul-1) != c)
                        ok = false
                    mul += ans
                }
                if (ok)
                    found = true
            }
            if (found) {
                writer.println(1)
                writer.println(ans)
            } else {
                writer.println(2)
                writer.print(n-1)
                writer.print(' ')
                writer.println(n)
            }
        }
    }
    writer.flush()
}

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

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

    case class myType(var social: Int, var cp:  Int, var ind: Int)extends Ordered[myType] {
        override def compare(that: myType): Int = {
            if (social < that.social)
                return -1
            else if (social == that.social)
                return 0
            else
                return 1
        }
    }
    val rem = 1000000007

    val t = readInt()
    for (tt <- 1 to t) {
        val n = readInt()
        val c = readString()(0)
        val s = readString()
        var cnt = 0
        for (ch <- s) {
            if (ch != c)
                cnt += 1
        }
        if (cnt == 0) {
            writer.println(0)
        } else {
            if (s(s.length-1) == c) {
                writer.println(1)
                writer.println(n)
            } else {
                if (cnt == 1) {
                    writer.println(1)
                    writer.println(n-1)
                } else {
                    writer.println(2)
                    writer.print(n-1)
                    writer.print(' ')
                    writer.println(n)
                }
            }
        }
    }
    writer.flush()
}


You are given three integers $$$a$$$, $$$b$$$, and $$$c$$$. Determine if one of them is the sum of the other two.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 9261$$$) — the number of test cases. The description of each test case consists of three integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$0 \leq a, b, c \leq 20$$$).

For each test case, output "YES" if one of the numbers is the sum of the other two, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

NoteIn the first test case, $$$1 + 3 = 4$$$.In the second test case, none of the numbers is the sum of the other two.In the third test case, $$$9 + 11 = 20$$$.

object HelloWorld {

  def main(args: Array[String]): Unit = {
    val tests = scala.io.StdIn.readInt()
    for (t <- 1 to tests) {
      val Array(a, b, c) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

      val works = a + b == c || a + c == b || b + c == a

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

import scala.io.StdIn.readLine
object Sum {

    def myFunc[T: Manifest](t: T): Manifest[T] = manifest[T]

    def solve_test() = {
        val a = readLine().split(' ').map(_.toInt).sorted
        if (a(0) + a(1) == a(2))
            println("YES")
        else
            println("NO")
    }

    def main(args: Array[String]): Unit = {
        val test = scala.io.StdIn.readInt()
        for(i <- 0 until test) solve_test()
    }
}