Shubham has an array $$$a$$$ of size $$$n$$$, and wants to select exactly $$$x$$$ elements from it, such that their sum is odd. These elements do not have to be consecutive. The elements of the array are not guaranteed to be distinct.Tell him whether he can do so.

The first line of the input contains a single integer $$$t$$$ $$$(1\le t \le 100)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ $$$(1 \le x \le n \le 1000)$$$ — the length of the array and the number of elements you need to choose. The next line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 1000)$$$ — elements of the array.

For each test case, print "Yes" or "No" depending on whether it is possible to choose $$$x$$$ elements such that their sum is odd. You may print every letter in any case you want.

NoteFor $$$1$$$st case: We must select element $$$999$$$, and the sum is odd.For $$$2$$$nd case: We must select element $$$1000$$$, so overall sum is not odd.For $$$3$$$rd case: We can select element $$$51$$$.For $$$4$$$th case: We must select both elements $$$50$$$ and $$$51$$$  — so overall sum is odd.For $$$5$$$th case: We must select all elements  — but overall sum is not odd.

//package codeforces.contests._1363

object OddSelection {
  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(n, x) = io.StdIn.readLine.split(" ").map(_.toInt)

      val odds = io.StdIn.readLine.split(" ").map(_.toInt).count(_ % 2 == 1)
      val evens = n - odds

      if (evens == 0) {
        println(if (x % 2 == 1) "Yes" else "No")
      } else {
        val requested = { // 5 then need 5 odds, if 6 then need 7 odds, if evens == 0
          val r = (x - evens) max 0
          r + (if (r % 2 == 0) 1 else 0)
        }

        val available = requested <= odds

        println(if (available) "Yes" else "No")
      }
    }
  }
}

import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    val t = readLine().toInt
    for (i <- 1 to t) {
      val nx = readIntLine()
      val arr = readIntLine()
      val ans = can(arr, nx.last)
      println(if (ans) "Yes" else "No")
    }
    //      println(calcWays(4, 5))
  }

  def can(list: List[Int], x: Int) = {
    (1 to (x + 1) / 2).exists(i => list.count(_ % 2 == 1) >= 2 * i - 1 && list.count(_ % 2 == 0) >= x - 2 * i + 1)
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

  def printArray[T](arr: Array[T]) {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

}

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

  import Main._
  import fScanner._

  def solve(): Unit = {
    val T = ni()
    REP(T) { _ =>
      val n = ni()
      val x = ni()
      val a = na(n)

      var cntO = 0
      var cntE = 0

      REP(n) { i =>
        if(a(i) % 2 == 0) cntE += 1
        else cntO += 1
      }

      if(cntE >= x && cntO > 0) {
        out.println("Yes")
      } else if(cntO > 0) {
        val rm = x - cntE
        if(rm % 2 != 0 && cntO >= rm) out.println("Yes")
        else if(cntE > 0 && cntO >= rm + 1) out.println("Yes")
        else out.println("No")
      } else out.println("No")
    }
  }
}

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

  override def solve(io: IO) = io.repeat {
    val n, x = io.read[Int]
    val xs = io.read[List, Int](n)
    val evens = xs.count(_%2 == 0)
    val odds = n - evens
    val ans = (1 to odds by 2).exists(o => (x - o) >= 0 && (x - o) <= evens)
    io.write(ans.toEnglish)
  }
}
/****************************[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)

  val charToInt: Char => Int = Character.getNumericValue
  val intToChar: Int => Char = Character.forDigit(_, 10)

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

import scala.io.StdIn.readLine

object A {

  def solution(a: Seq[Int], k: Int): Boolean = {
    val cc = a.count(_ % 2 == 0)
    if (cc == a.length)
      false
    else if (cc == 0)
      k % 2 != 0
    else
      k < a.length || (a.length - cc) % 2 == 1
  }

  def main(args: Array[String]): Unit = {
    for {_ <- 0 until readLine.toInt} {
      val Seq(_, k) = readLine.split(" ").toSeq.map(_.toInt)
      val a = readLine.split(" ").toSeq.map(_.toInt)
      println(if (solution(a, k)) "Yes" else "No")
    }
  }
}

//package codeforces.contests._1363

object OddSelection {
  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(n, x) = io.StdIn.readLine.split(" ").map(_.toInt)

      val odds = io.StdIn.readLine.split(" ").map(_.toInt).count(_ % 2 == 1)
      val evens = n - odds

      val requested = { // 5 then need 5 odds, if 6 then need 7 odds
        val r = (x - evens) max 0
        r + (if (r % 2 == 0) 1 else 0)
      }

      val available = requested <= odds

      println(if (available) "Yes" else "No")
    }
  }
}

import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    val t = readLine().toInt
    for (i <- 1 to t) {
      val nx = readIntLine()
      val arr = readIntLine()
      val ans = can(arr, nx.last)
      println(if (ans) "Yes" else "No")
    }
    //      println(calcWays(4, 5))
  }

  def can(list: List[Int], x: Int) = {
    (1 to (x + 1) / 2).exists(i => list.count(_ % 2 == 1) >= 2 * i + 1 && list.count(_ % 2 == 0) >= x - 2 * i - 1)
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

  def printArray[T](arr: Array[T]) {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

}

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

  import Main._
  import fScanner._

  def solve(): Unit = {
    val T = ni()
    REP(T) { _ =>
      val n = ni()
      val x = ni()
      val a = na(n)

      var cntO = 0
      var cntE = 0

      a.foreach { f =>
        if(f%2 == 0) cntE += 1
        else cntO += 1
      }

      if(cntO % 2 != 0) {
        out.println("Yes")
      } else {
        if(cntO > 0) {
          if(cntO + cntE - 1 >= x) {
            out.println("Yes")
          } else out.println("No")
        } else out.println("No")
      }
    }
  }
}


You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones.Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$. You can apply the following operations any number of times:  Choose some substring of string $$$a$$$ (for example, you can choose entire string) and reverse it, paying $$$x$$$ coins for it (for example, «0101101» $$$\to$$$ «0111001»);  Choose some substring of string $$$a$$$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $$$y$$$ coins for it (for example, «0101101» $$$\to$$$ «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.What is the minimum number of coins you need to spend to get a string consisting only of ones?

The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $$$a$$$ of length $$$n$$$, consisting of zeros and ones.

Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations.

NoteIn the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$. Then the string was changed as follows:«01000» $$$\to$$$ «10000» $$$\to$$$ «11111».The total cost of operations is $$$1 + 10 = 11$$$.In the second sample, at first you need to invert substring $$$[1 \dots 1]$$$, and then you need to invert substring $$$[3 \dots 5]$$$. Then the string was changed as follows:«01000» $$$\to$$$ «11000» $$$\to$$$ «11111».The overall cost is $$$1 + 1 = 2$$$.In the third example, string already consists only of ones, so the answer is $$$0$$$.

import scala.annotation.tailrec

object Multiple extends App{

  @tailrec
  def countZeroRanges(row: List[Char], prevZero: Boolean = false, count: Int = 0): Int = row match {
    case head :: tail => countZeroRanges(row.tail, row.head == '0',
      if (row.head == '0' && !prevZero) count + 1 else count)
    case Nil => count
  }

  val n :: x :: y :: Nil = Console.in.readLine().split(' ').map(_.toLong).toList
  val row = Console.in.readLine().toList

  val zeroRanges = countZeroRanges(row)
  if (zeroRanges == 0) {
    println(0)
  }
  else if (x > y) {
    println(zeroRanges * y)
  }
  else {
    println((zeroRanges - 1) * x  + y)
  }

}

import scala.annotation.tailrec

object Multiple extends App{

  @tailrec
  def countZeroRanges(row: List[Char], prevZero: Boolean = false, count: Int = 0): Int = row match {
    case head :: tail => countZeroRanges(row.tail, row.head == '0',
      if (row.head == '0' && !prevZero) count + 1 else count)
    case Nil => count
  }

  val n :: x :: y :: Nil = Console.in.readLine().split(' ').map(_.toLong).toList
  val row = Console.in.readLine().toList

  val zeroRanges = countZeroRanges(row)
  if (x > y) {
    println(zeroRanges * y)
  }
  else {
    println((zeroRanges - 1) * x  + y)
  }

}


You are given an integer array of length $$$n$$$.You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to $$$[x, x + 1, \dots, x + k - 1]$$$ for some value $$$x$$$ and length $$$k$$$.Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array $$$[5, 3, 1, 2, 4]$$$ the following arrays are subsequences: $$$[3]$$$, $$$[5, 3, 1, 2, 4]$$$, $$$[5, 1, 4]$$$, but the array $$$[1, 3]$$$ is not.

The first line of the input containing integer number $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the array. The second line of the input containing $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the array itself.

On the first line print $$$k$$$ — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers. On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.

NoteAll valid answers for the first example (as sequences of indices):   $$$[1, 3, 5, 6]$$$  $$$[2, 3, 5, 6]$$$ All valid answers for the second example:   $$$[1, 4]$$$  $$$[2, 5]$$$  $$$[3, 6]$$$ All valid answers for the third example:   $$$[1]$$$  $$$[2]$$$  $$$[3]$$$  $$$[4]$$$ All valid answers for the fourth example:   $$$[1, 2, 3, 7, 8, 9]$$$

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

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

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

  def solve(): Unit = {
    val N = ni()
    val A = na(N)
    val cnt = mutable.Map[Int, Int]() withDefaultValue 0
    A foreach { a =>
      cnt(a) = cnt(a - 1) + 1
    }
    val (xmx, k) = cnt.maxBy(_._2)

    val ix = ArrayBuffer[Int]()
    val x = xmx - k + 1
    var j = 0
    rep(N){  i =>
      if (j < k && A(i) == x + j) {
        ix += i
        j += 1
      }
    }

    out.println(k)
    out.println(ix.map(_ + 1).mkString(" "))
  }

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

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

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

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

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


Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types:   replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4);  swap any pair of digits in string a. Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task.

The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105.

Print on the single line the single number — the minimum number of operations needed to convert string a into string b.

NoteIn the first sample it is enough simply to swap the first and the second digit.In the second sample we should replace the second digit with its opposite.In the third number we should replace all three digits with their opposites.

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val r = in.next().zip(in.next()).foldLeft((0, 0)) {
    case ((c47, c74), ('4', '7')) => (c47 + 1, c74)
    case ((c47, c74), ('7', '4')) => (c47, c74 + 1)
    case (acc, el) => acc
  }

  println(Math.min(r._1, r._2) + Math.abs(r._1 - r._2))
}


Tree is a connected acyclic graph. Suppose you are given a tree consisting of n vertices. The vertex of this tree is called centroid if the size of each connected component that appears if this vertex is removed from the tree doesn't exceed .You are given a tree of size n and can perform no more than one edge replacement. Edge replacement is the operation of removing one edge from the tree (without deleting incident vertices) and inserting one new edge (without adding new vertices) in such a way that the graph remains a tree. For each vertex you have to determine if it's possible to make it centroid by performing no more than one edge replacement.

The first line of the input contains an integer n (2 ≤ n ≤ 400 000) — the number of vertices in the tree. Each of the next n - 1 lines contains a pair of vertex indices ui and vi (1 ≤ ui, vi ≤ n) — endpoints of the corresponding edge.

Print n integers. The i-th of them should be equal to 1 if the i-th vertex can be made centroid by replacing no more than one edge, and should be equal to 0 otherwise.

NoteIn the first sample each vertex can be made a centroid. For example, in order to turn vertex 1 to centroid one have to replace the edge (2, 3) with the edge (1, 3).

import scala.collection.mutable

object C extends App {

  val task = new Runnable {

    override def run(): Unit = {
      @inline def tokenizeLine = new java.util.StringTokenizer(readLine)

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

      final case class AB(a: Int, b: Int)

      val Array(n) = readInts(1)
      val m = n / 2

      val adjBuilders = Array.fill(n) {
        new mutable.ArrayBuilder.ofInt
      }

      for (_ <- 1 until n) {
        val Array(u, v) = readInts(2)
        adjBuilders(u - 1) += v - 1
        adjBuilders(v - 1) += u - 1
      }

      val adjs = adjBuilders.map(_.result)
      val res = Array.fill(n) {
        0
      }
      val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length) }
      val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) {
        0
      }
      }

      def dfs1(u: Int, parent: Int): AB = {

        var i = 0
        var childrenSize = 1
        var parentPos = -1
        var maxSubtreeSize = 0

        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (adjs(u)(i) == parent) parentPos = i
          else {
            val ab = dfs1(v, u)
            childrenSize += ab.a
            sizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSize) maxSubtreeSize = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSize) maxSubtreeSize = ab.a
          }
          i += 1
        }

        if (parentPos >= 0) {
          sizeFrom(u)(parentPos) = n - childrenSize
          if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
        }

        AB(childrenSize, maxSubtreeSize)
      }

      dfs1(0, -1)

      val maxSubtreeSize2a = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      def find(arr: Array[AB], v: Int): Option[Int] = {
        if (arr.size > 0 && arr(0).b != v) Some(arr(0).a)
        else if (arr.size > 1 && arr(1).b != v) Some(arr(1).a)
        else None
      }

      def dfs2(u: Int, parent: Int, parentMaxSubtreeSize: Int): Unit = {

        var i = 0
        while (i < adjs(u).length) {
          if (adjs(u)(i) == parent) {
            if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = parentMaxSubtreeSize
          }
          i += 1
        }

        i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (v != parent) {
            val sub = find(maxSubtreeSize2a(u), v)
            dfs2(v, u, sub.map(Math.max(_, parentMaxSubtreeSize)).getOrElse(parentMaxSubtreeSize))
          }
          i += 1
        }
      }

      dfs2(0, -1, 0)

      val maxSubtreeSize2 = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      for (u <- 0 until n) {
        var ok = true
        for (i <- adjs(u).indices) {
          val v = adjs(u)(i)
          if (sizeFrom(u)(i) > m) {
            val sub = find(maxSubtreeSize2(v), u)
            if (sub == None || sizeFrom(u)(i) - sub.get > m) ok = false
          }
        }
        res(u) = if (ok) 1 else 0
      }

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

      println(res.mkString(" "))

      Console.flush
    }
  }

  new Thread(null, task, "1", 80000000).start()
}

import scala.collection.mutable

object C extends App {

  val task = new Runnable {

    override def run(): Unit = {
      @inline def tokenizeLine = new java.util.StringTokenizer(readLine)

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

      final case class AB(a: Int, b: Int)

      val Array(n) = readInts(1)
      val m = n / 2

      val adjBuilders = Array.fill(n) {
        new mutable.ArrayBuilder.ofInt
      }

      for (_ <- 1 until n) {
        val Array(u, v) = readInts(2)
        adjBuilders(u - 1) += v - 1
        adjBuilders(v - 1) += u - 1
      }

      val adjs = adjBuilders.map(_.result)
      val res = Array.fill(n) {
        0
      }
      val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length) }
      val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) {
        0
      }
      }

      def dfs1(u: Int, parent: Int): AB = {

        var i = 0
        var childrenSize = 1
        var parentPos = -1
        var maxSubtreeSize = 0

        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (adjs(u)(i) == parent) parentPos = i
          else {
            val ab = dfs1(v, u)
            childrenSize += ab.a
            sizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSize) maxSubtreeSize = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSize) maxSubtreeSize = ab.a
          }
          i += 1
        }

        if (parentPos >= 0) {
          sizeFrom(u)(parentPos) = n - childrenSize
          if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
        }

        AB(childrenSize, maxSubtreeSize)
      }

      dfs1(0, -1)

      val maxSubtreeSize2a = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      def find(arr: Array[AB], v: Int): Int = {
        if (arr.length > 0 && arr(0).b != v) arr(0).a
        else if (arr.length > 1 && arr(1).b != v) arr(1).a
        else -1
      }

      def dfs2(u: Int, parent: Int, parentMaxSubtreeSize: Int): Unit = {

        var i = 0
        while (i < adjs(u).length) {
          if (adjs(u)(i) == parent) {
            if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = parentMaxSubtreeSize
          }
          i += 1
        }

        i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (v != parent) {
            val sub = find(maxSubtreeSize2a(u), v)
            dfs2(v, u, Math.max(sub, parentMaxSubtreeSize))
          }
          i += 1
        }
      }

      dfs2(0, -1, 0)

      val maxSubtreeSize2 = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      for (u <- 0 until n) {
        var ok = true
        for (i <- adjs(u).indices) {
          val v = adjs(u)(i)
          if (sizeFrom(u)(i) > m) {
            val sub = find(maxSubtreeSize2(v), u)
            if (sub == -1 || sizeFrom(u)(i) - sub > m) ok = false
          }
        }
        res(u) = if (ok) 1 else 0
      }

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

      println(res.mkString(" "))

      Console.flush
    }
  }

  new Thread(null, task, "1", 80000000).start()
}

import scala.collection.mutable

object C extends App {

  val task = new Runnable {

    override def run(): Unit = {
      @inline def tokenizeLine = new java.util.StringTokenizer(readLine)

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

      final case class AB(a: Int, b: Int)

      val Array(n) = readInts(1)
      val m = n / 2

      val adjBuilders = Array.fill(n) {
        new mutable.ArrayBuilder.ofInt
      }

      for (_ <- 1 until n) {
        val Array(u, v) = readInts(2)
        adjBuilders(u - 1) += v - 1
        adjBuilders(v - 1) += u - 1
      }

      val adjs = adjBuilders.map(_.result)
      val res = Array.fill(n) {
        0
      }
      val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length) }
      val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) {
        0
      }
      }

      def dfs1(u: Int, parent: Int): AB = {

        var i = 0
        var childrenSize = 1
        var parentPos = -1
        var maxSubtreeSize = 0

        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (adjs(u)(i) == parent) parentPos = i
          else {
            val ab = dfs1(v, u)
            childrenSize += ab.a
            sizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSize) maxSubtreeSize = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSize) maxSubtreeSize = ab.a
          }
          i += 1
        }

        if (parentPos >= 0) {
          sizeFrom(u)(parentPos) = n - childrenSize
          if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
        }

        AB(childrenSize, maxSubtreeSize)
      }

      dfs1(0, -1)

      val maxSubtreeSize2a = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      def find(arr: Array[AB], v: Int): Option[Int] = {
        if (arr.length > 0 && arr(0).b != v) Some(arr(0).a)
        else if (arr.length > 1 && arr(1).b != v) Some(arr(1).a)
        else None
      }

      def dfs2(u: Int, parent: Int, parentMaxSubtreeSize: Int): Unit = {

        var i = 0
        while (i < adjs(u).length) {
          if (adjs(u)(i) == parent) {
            if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = parentMaxSubtreeSize
          }
          i += 1
        }

        i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (v != parent) {
            val sub = find(maxSubtreeSize2a(u), v)
            dfs2(v, u, sub.map(Math.max(_, parentMaxSubtreeSize)).getOrElse(parentMaxSubtreeSize))
          }
          i += 1
        }
      }

      dfs2(0, -1, 0)

      val maxSubtreeSize2 = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      for (u <- 0 until n) {
        var ok = true
        for (i <- adjs(u).indices) {
          val v = adjs(u)(i)
          if (sizeFrom(u)(i) > m) {
            val sub = find(maxSubtreeSize2(v), u)
            if (sub == None || sizeFrom(u)(i) - sub.get > m) ok = false
          }
        }
        res(u) = if (ok) 1 else 0
      }

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

      println(res.mkString(" "))

      Console.flush
    }
  }

  new Thread(null, task, "1", 80000000).start()
}

import scala.collection.mutable

object C extends App {

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

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

  final case class AB(a: Int, b: Int)

  val Array(n) = readInts(1)
  val m = n / 2

  val adjBuilders = Array.fill(n) {
    new mutable.ArrayBuilder.ofInt
  }

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n) {
    0
  }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length) }
  val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) {
    0
  }
  }

  def dfs1(u: Int, parent: Int): AB = {

    var i = 0
    var childrenSize = 1
    var parentPos = -1
    var maxSubtreeSize = 0

    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (adjs(u)(i) == parent) parentPos = i
      else {
        val ab = dfs1(v, u)
        childrenSize += ab.a
        sizeFrom(u)(i) = ab.a
        if (ab.b <= m && ab.b > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.b
        if (ab.a <= m && ab.a > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.a
        if (ab.b <= m && ab.b > maxSubtreeSize) maxSubtreeSize = ab.b
        if (ab.a <= m && ab.a > maxSubtreeSize) maxSubtreeSize = ab.a
      }
      i += 1
    }

    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
      if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
    }

    AB(childrenSize, maxSubtreeSize)
  }

  dfs1(0, -1)

  val maxSubtreeSize2a = Array.tabulate(n) { u =>
    val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
    maxWithInd.sortBy(-_.a).take(2)
  }

  def find(arr: Array[AB], v: Int): Int = {
    if (arr.length > 0 && arr(0).b != v) arr(0).a
    else if (arr.length > 1 && arr(1).b != v) arr(1).a
    else -1
  }

  def dfs2(u: Int, parent: Int, parentMaxSubtreeSize: Int): Unit = {

    var i = 0
    while (i < adjs(u).length) {
      if (adjs(u)(i) == parent) {
        if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = parentMaxSubtreeSize
      }
      i += 1
    }

    i = 0
    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v != parent) {
        val sub = find(maxSubtreeSize2a(u), v)
        dfs2(v, u, Math.max(sub, parentMaxSubtreeSize))
      }
      i += 1
    }
  }

  dfs2(0, -1, 0)

  val maxSubtreeSize2 = Array.tabulate(n) { u =>
    val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
    maxWithInd.sortBy(-_.a).take(2)
  }

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        val sub = find(maxSubtreeSize2(v), u)
        if (sub == -1 || sizeFrom(u)(i) - sub > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}

import scala.collection.mutable

object C extends App {

  val task = new Runnable {

    override def run(): Unit = {
      @inline def tokenizeLine = new java.util.StringTokenizer(readLine)

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

      final case class AB(a: Int, b: Int)

      val Array(n) = readInts(1)
      val m = n / 2

      val adjBuilders = Array.fill(n) {
        new mutable.ArrayBuilder.ofInt
      }

      for (_ <- 1 until n) {
        val Array(u, v) = readInts(2)
        adjBuilders(u - 1) += v - 1
        adjBuilders(v - 1) += u - 1
      }

      val adjs = adjBuilders.map(_.result)
      val res = Array.fill(n) {
        0
      }
      val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length) }
      val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) {
        0
      }
      }

      def dfs1(u: Int, parent: Int): AB = {

        var i = 0
        var childrenSize = 1
        var parentPos = -1
        var maxSubtreeSize = 0

        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (adjs(u)(i) == parent) parentPos = i
          else {
            val ab = dfs1(v, u)
            childrenSize += ab.a
            sizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSize) maxSubtreeSize = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSize) maxSubtreeSize = ab.a
          }
          i += 1
        }

        if (parentPos >= 0) {
          sizeFrom(u)(parentPos) = n - childrenSize
          if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
        }

        AB(childrenSize, maxSubtreeSize)
      }

      dfs1(0, -1)

      val maxSubtreeSize2a = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      def find(arr: Array[AB], v: Int): Int = {
        if (arr.length > 0 && arr(0).b != v) arr(0).a
        else if (arr.length > 1 && arr(1).b != v) arr(1).a
        else -1
      }

      def dfs2(u: Int, parent: Int, parentMaxSubtreeSize: Int): Unit = {

        var i = 0
        while (i < adjs(u).length) {
          if (adjs(u)(i) == parent) {
            if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = parentMaxSubtreeSize
          }
          i += 1
        }

        i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (v != parent) {
            val sub = find(maxSubtreeSize2a(u), v)
            dfs2(v, u, Math.max(sub, parentMaxSubtreeSize))
          }
          i += 1
        }
      }

      dfs2(0, -1, 0)

      val maxSubtreeSize2 = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      for (u <- 0 until n) {
        var ok = true
        for (i <- adjs(u).indices) {
          val v = adjs(u)(i)
          if (sizeFrom(u)(i) > m) {
            val sub = find(maxSubtreeSize2(v), u)
            if (sub == -1 || sizeFrom(u)(i) - sub > m) ok = false
          }
        }
        res(u) = if (ok) 1 else 0
      }

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

      println(res.mkString(" "))

      Console.flush
    }
  }

  new Thread(null, task, "1", 64000000).start()
}

import scala.collection.mutable

object C extends App {

  val task = new Runnable {

    override def run(): Unit = {
      @inline def tokenizeLine = new java.util.StringTokenizer(readLine)

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

      final case class AB(a: Int, b: Int)

      val Array(n) = readInts(1)
      val m = n / 2

      val adjBuilders = Array.fill(n) {
        new mutable.ArrayBuilder.ofInt
      }

      for (_ <- 1 until n) {
        val Array(u, v) = readInts(2)
        adjBuilders(u - 1) += v - 1
        adjBuilders(v - 1) += u - 1
      }

      val adjs = adjBuilders.map(_.result)
      val res = Array.fill(n) {
        0
      }
      val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length) }
      val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) {
        0
      }
      }

      def dfs1(u: Int, parent: Int): AB = {

        var i = 0
        var childrenSize = 1
        var parentPos = -1
        var maxSubtreeSize = 0

        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (adjs(u)(i) == parent) parentPos = i
          else {
            val ab = dfs1(v, u)
            childrenSize += ab.a
            sizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSize) maxSubtreeSize = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSize) maxSubtreeSize = ab.a
          }
          i += 1
        }

        if (parentPos >= 0) {
          sizeFrom(u)(parentPos) = n - childrenSize
          if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
        }

        AB(childrenSize, maxSubtreeSize)
      }

      dfs1(0, -1)

      val maxSubtreeSize2a = for (u <- 0 until n) yield {
        val maxWithInd = for (i <- adjs(u).indices) yield AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i))
        maxWithInd.sortBy(-_.a).take(2)
      }

      def find(u: Int, v: Int): Option[Int] = {
        if (maxSubtreeSize2a(u).size > 0 && maxSubtreeSize2a(u)(0).b != v) Some(maxSubtreeSize2a(u)(0).a)
        else if (maxSubtreeSize2a(u).size > 1 && maxSubtreeSize2a(u)(1).b != v) Some(maxSubtreeSize2a(u)(1).a)
        else None
      }

      def dfs2(u: Int, parent: Int, parentMaxSubtreeSize: Int): Unit = {

        var i = 0
        while (i < adjs(u).length) {
          if (adjs(u)(i) == parent) {
            if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = parentMaxSubtreeSize
          }
          i += 1
        }

        i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (v != parent) {
            val sub = find(u, v)
            dfs2(v, u, sub.map(Math.max(_, parentMaxSubtreeSize)).getOrElse(parentMaxSubtreeSize))
          }
          i += 1
        }
      }

      dfs2(0, -1, 0)

      val maxSubtreeSize2 = for (u <- 0 until n) yield {
        val maxWithInd = for (i <- adjs(u).indices) yield AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i))
        maxWithInd.sortBy(-_.a).take(2)
      }

      for (u <- 0 until n) {
        var ok = true
        for (i <- adjs(u).indices) {
          val v = adjs(u)(i)
          if (sizeFrom(u)(i) > m) {
            val sub = find(v, u)
            if (sub == None || sizeFrom(u)(i) - sub.get > m) ok = false
          }
        }
        res(u) = if (ok) 1 else 0
      }

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

      println(res.mkString(" "))

      Console.flush
    }
  }

  new Thread(null, task, "1", 80000000).start()
}

import scala.collection.mutable

object C extends App {

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

  val Array(n) = readInts(1)
  val m = n / 2

  val adjBuilders = Array.fill(n) { new mutable.ArrayBuilder.ofInt }

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n){ 0 }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length)}
  val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) { 0 } }
  var last = 0
  var maxDepth = -1

  def dfs(u: Int, parent: Int, size: Int, depth: Int): (Int, Int) = {

    if (depth > maxDepth) {
      last = u
      maxDepth = depth
    }

    var i = 0
    var childrenSize = 1
    var parentPos = -1
    var maxSubtreeSize = 0

    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v == parent) {
        parentPos = i
      } else {
        val (vSubtreeSize, vMaxSubtreeSize) = dfs(v, u, size + 1, depth + 1)
        childrenSize += vSubtreeSize
        sizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSize) maxSubtreeSize = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSize) maxSubtreeSize = vSubtreeSize
      }
      i += 1
    }
    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
    }
    (childrenSize, maxSubtreeSize)
  }

  dfs(0, -1, 0, 0)
  dfs(last, -1, 0, 0)

  val maxSubtreeSize2 = for (u <- 0 until n) yield {
    val maxWithInd = for (i <- adjs(u).indices) yield maxSubtreeSizeFrom(u)(i) -> adjs(u)(i)
    maxWithInd.sortBy(- _._1).take(2)
  }

  //sizeFrom.foreach(s => println(s.mkString(" ")))
  //println(maxSubtreeSize.mkString(" "))

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        val sub = maxSubtreeSize2(v).filter(_._2 != u).headOption.map(_._1)
        if (sub == None || sizeFrom(u)(i) - sub.get > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}

import scala.collection.mutable

object C extends App {

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

  val Array(n) = readInts(1)
  val m = n / 2

  val adjBuilders = Array.fill(n) { new mutable.ArrayBuilder.ofInt }

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n){ 0 }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length)}
  val maxSubtreeSize = Array.fill(n) { 0 }

  def dfs(u: Int, parent: Int, size: Int): (Int, Int) = {
    var i = 0
    var childrenSize = 1
    var parentPos = -1
    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v == parent) {
        parentPos = i
      } else {
        val (vSubtreeSize, vMaxSubtreeSize) = dfs(v, u, size + 1)
        childrenSize += vSubtreeSize
        sizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vSubtreeSize
      }
      i += 1
    }
    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
    }
    (childrenSize, maxSubtreeSize(u))
  }

  dfs(0, -1, 0)
  dfs(1, -1, 0)

  //sizeFrom.foreach(s => println(s.mkString(" ")))
  //println(maxSubtreeSize.mkString(" "))

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        if (sizeFrom(u)(i) - maxSubtreeSize(v) > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}

import scala.collection.mutable

object C extends App {

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

  val Array(n) = readInts(1)
  val m = n / 2

  val adjBuilders = Array.fill(n) { new mutable.ArrayBuilder.ofInt }

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n){ 0 }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length)}
  val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) { 0 } }
  var last = 0
  var maxDepth = -1

  def dfs(u: Int, parent: Int, size: Int, depth: Int, parentMaxSubtreeSize: Int): (Int, Int) = {

    if (depth > maxDepth) {
      last = u
      maxDepth = depth
    }

    var i = 0
    var childrenSize = 1
    var parentPos = -1
    var maxSubtreeSize = 0

    val maxForward = maxSubtreeSizeFrom(u).max

    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v == parent) {
        parentPos = i
      } else {
        val (vSubtreeSize, vMaxSubtreeSize) = dfs(v, u, size + 1, depth + 1, maxForward)
        childrenSize += vSubtreeSize
        sizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSize) maxSubtreeSize = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSize) maxSubtreeSize = vSubtreeSize
      }
      i += 1
    }
    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
      if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = parentMaxSubtreeSize
      if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
    }
    (childrenSize, maxSubtreeSize)
  }

  dfs(0, -1, 0, 0, 0)
  dfs(last, -1, 0, 0, 0)

  val maxSubtreeSize2 = for (u <- 0 until n) yield {
    val maxWithInd = for (i <- adjs(u).indices) yield maxSubtreeSizeFrom(u)(i) -> adjs(u)(i)
    maxWithInd.sortBy(- _._1).take(2)
  }

 // sizeFrom.foreach(s => println(s.mkString(" ")))
  //maxSubtreeSizeFrom.foreach(s => println(s.mkString(" ")))

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        val sub = maxSubtreeSize2(v).filter(_._2 != u).headOption.map(_._1)
        if (sub == None || sizeFrom(u)(i) - sub.get > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}

import scala.collection.mutable

object C extends App {

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

  val Array(n) = readInts(1)
  val m = n / 2

  val adjBuilders = Array.fill(n) { new mutable.ArrayBuilder.ofInt }

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n){ 0 }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length)}
  val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) { 0 } }
  var last = 0
  var maxDepth = -1

  def dfs(u: Int, parent: Int, size: Int, depth: Int, parentMaxSubtreeSize: Int): (Int, Int) = {

    if (depth > maxDepth) {
      last = u
      maxDepth = depth
    }

    var i = 0
    var childrenSize = 1
    var parentPos = -1
    var maxSubtreeSize = 0

    while (i < adjs(u).length) {
      if (adjs(u)(i) == parent) parentPos = i
      i += 1
    }

    if (parentPos >= 0) {
      if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = parentMaxSubtreeSize
      //if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
    }

    val maxForwardA = maxSubtreeSizeFrom(u).max
    val maxForwardB = maxSubtreeSizeFrom(u).sum + 1
    var maxForward = 0
    if (maxForwardA <= m) maxForward = maxForwardA
    //if (maxForwardB <= m && maxForwardB > maxForward) maxForward = maxForwardB

    i = 0
    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v != parent) {
        val (vSubtreeSize, vMaxSubtreeSize) = dfs(v, u, size + 1, depth + 1, maxForward)
        childrenSize += vSubtreeSize
        sizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSize) maxSubtreeSize = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSize) maxSubtreeSize = vSubtreeSize
      }
      i += 1
    }

    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
    }

    (childrenSize, maxSubtreeSize)
  }

  dfs(0, -1, 0, 0, 0)
  dfs(last, -1, 0, 0, 0)
  dfs(last, -1, 0, 0, 0)

  //maxSubtreeSizeFrom.foreach(s => println(s.mkString(" ")))

  val maxSubtreeSize2 = for (u <- 0 until n) yield {
    val maxWithInd = for (i <- adjs(u).indices) yield maxSubtreeSizeFrom(u)(i) -> adjs(u)(i)
    maxWithInd.sortBy(- _._1).take(2)
  }

  //maxSubtreeSize2.foreach(s => println(s.mkString(" ")))

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        val sub = maxSubtreeSize2(v).filter(_._2 != u).headOption.map(_._1)
        if (sub == None || sizeFrom(u)(i) - sub.get > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}

import scala.collection.mutable

object C extends App {

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

  val Array(n) = readInts(1)
  val m = n / 2

  val adjBuilders = Array.fill(n) { new mutable.ArrayBuilder.ofInt }

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n){ 0 }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length)}
  val maxSubtreeSize = Array.fill(n) { 0 }
  var last = 0
  var maxDepth = -1

  def dfs(u: Int, parent: Int, size: Int, depth: Int): (Int, Int) = {
    if (depth > maxDepth) {
      last = u
      maxDepth = depth
    }
    var i = 0
    var childrenSize = 1
    var parentPos = -1
    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v == parent) {
        parentPos = i
      } else {
        val (vSubtreeSize, vMaxSubtreeSize) = dfs(v, u, size + 1, depth + 1)
        childrenSize += vSubtreeSize
        sizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vSubtreeSize
      }
      i += 1
    }
    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
    }
    (childrenSize, maxSubtreeSize(u))
  }

  dfs(0, -1, 0, 0)
  dfs(last, -1, 0, 0)

  //sizeFrom.foreach(s => println(s.mkString(" ")))
  //println(maxSubtreeSize.mkString(" "))

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        if (sizeFrom(u)(i) - maxSubtreeSize(v) > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}

import scala.collection.mutable

object C extends App {

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

  val Array(n) = readInts(1)
  val m = (n - 1) / 2

  val adjBuilders = Array.fill(n) { new mutable.ArrayBuilder.ofInt }

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n){ 0 }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length)}
  val maxSubtreeSize = Array.fill(n) { 0 }
  var last = 0
  var maxDepth = -1

  def dfs(u: Int, parent: Int, size: Int, depth: Int): (Int, Int) = {
    if (depth > maxDepth) {
      last = u
      maxDepth = depth
    }
    var i = 0
    var childrenSize = 1
    var parentPos = -1
    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v == parent) {
        parentPos = i
      } else {
        val (vSubtreeSize, vMaxSubtreeSize) = dfs(v, u, size + 1, depth + 1)
        childrenSize += vSubtreeSize
        sizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vSubtreeSize
      }
      i += 1
    }
    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
    }
    (childrenSize, maxSubtreeSize(u))
  }

  dfs(0, -1, 0, 0)
  dfs(last, -1, 0, 0)

  //sizeFrom.foreach(s => println(s.mkString(" ")))
  //println(maxSubtreeSize.mkString(" "))

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        if (sizeFrom(u)(i) - maxSubtreeSize(v) > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}

import scala.collection.mutable

object C extends App {

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

  val Array(n) = readInts(1)
  val m = n / 2

  val adjBuilders = Array.fill(n) { new mutable.ArrayBuilder.ofInt }

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n){ 0 }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length)}
  val maxSubtreeSize = Array.fill(n) { 0 }

  def dfs(u: Int, parent: Int, size: Int): (Int, Int) = {
    var i = 0
    var childrenSize = 1
    var parentPos = -1
    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v == parent) {
        parentPos = i
      } else {
        val (vSubtreeSize, vMaxSubtreeSize) = dfs(v, u, size + 1)
        childrenSize += vSubtreeSize
        (vSubtreeSize, vMaxSubtreeSize)
        sizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vSubtreeSize
      }
      i += 1
    }
    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
    }
    (childrenSize, maxSubtreeSize(u))
  }

  dfs(0, -1, 0)

  //sizeFrom.foreach(s => println(s.mkString(" ")))
  //println(maxSubtreeSize.mkString(" "))

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        if (sizeFrom(u)(i) - maxSubtreeSize(v) > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}


A team of three programmers is going to play a contest. The contest consists of $$$n$$$ problems, numbered from $$$1$$$ to $$$n$$$. Each problem is printed on a separate sheet of paper. The participants have decided to divide the problem statements into three parts: the first programmer took some prefix of the statements (some number of first paper sheets), the third contestant took some suffix of the statements (some number of last paper sheets), and the second contestant took all remaining problems. But something went wrong — the statements were printed in the wrong order, so the contestants have received the problems in some random order.The first contestant has received problems $$$a_{1, 1}, a_{1, 2}, \dots, a_{1, k_1}$$$. The second one has received problems $$$a_{2, 1}, a_{2, 2}, \dots, a_{2, k_2}$$$. The third one has received all remaining problems ($$$a_{3, 1}, a_{3, 2}, \dots, a_{3, k_3}$$$).The contestants don't want to play the contest before they redistribute the statements. They want to redistribute them so that the first contestant receives some prefix of the problemset, the third contestant receives some suffix of the problemset, and the second contestant receives all the remaining problems.During one move, some contestant may give one of their problems to other contestant. What is the minimum number of moves required to redistribute the problems?It is possible that after redistribution some participant (or even two of them) will not have any problems.

The first line contains three integers $$$k_1, k_2$$$ and $$$k_3$$$ ($$$1 \le k_1, k_2, k_3 \le 2 \cdot 10^5, k_1 + k_2 + k_3 \le 2 \cdot 10^5$$$) — the number of problems initially taken by the first, the second and the third participant, respectively. The second line contains $$$k_1$$$ integers $$$a_{1, 1}, a_{1, 2}, \dots, a_{1, k_1}$$$ — the problems initially taken by the first participant. The third line contains $$$k_2$$$ integers $$$a_{2, 1}, a_{2, 2}, \dots, a_{2, k_2}$$$ — the problems initially taken by the second participant. The fourth line contains $$$k_3$$$ integers $$$a_{3, 1}, a_{3, 2}, \dots, a_{3, k_3}$$$ — the problems initially taken by the third participant. It is guaranteed that no problem has been taken by two (or three) participants, and each integer $$$a_{i, j}$$$ meets the condition $$$1 \le a_{i, j} \le n$$$, where $$$n = k_1 + k_2 + k_3$$$.

Print one integer — the minimum number of moves required to redistribute the problems so that the first participant gets the prefix of the problemset, the third participant gets the suffix of the problemset, and the second participant gets all of the remaining problems.

NoteIn the first example the third contestant should give the problem $$$2$$$ to the first contestant, so the first contestant has $$$3$$$ first problems, the third contestant has $$$1$$$ last problem, and the second contestant has $$$1$$$ remaining problem.In the second example the distribution of problems is already valid: the first contestant has $$$3$$$ first problems, the third contestant has $$$1$$$ last problem, and the second contestant has $$$2$$$ remaining problems.The best course of action in the third example is to give all problems to the third contestant.The best course of action in the fourth example is to give all problems to the second contestant.

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._

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

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 k1, k2, k3 = ni()
    val n = k1 + k2 + k3
    val A1 = na(k1)
    val A2 = na(k2)
    val A3 = na(k3)
    sort(A1)
    sort(A2)
    sort(A3)

    // 全部１つの場所に移動するケース
    val calc1 = n - max(k1, max(k2, k3))

    val inf = 1e9.toInt

    // 3つともに数値があるケースと、２つにだけ数値があるケース
    def calc23: Int = {
      var p1, p2, p3 = 0
      var res = 1e9.toInt
      var best, next = Array.fill[Int](3)(inf)
      TO(1, n) { k =>
        if(p1 < k1 && A1(p1) == k) {
          p1 += 1
          next(0) = if (best(0) == inf) 0 else best(0)
          next(1) = if (best(1) == inf) 1 else best(1) + 1
          next(2) = min(inf, min(best(2) + 1, best(0) + 1))
        }
        if(p2 < k2 && A2(p2) == k) {
          p2 += 1
          next(0) = if (best(0) == inf) 1 else best(0) + 1
          next(1) = if (best(1) == inf) 0 else best(1)
          next(2) = min(inf, min(best(2), best(0)))
        }
        if(p3 < k3 && A3(p3) == k) {
          p3 += 1
          Array.copy(best, 0, next, 0, 3)
        }
        debug(next)

        var v = next.min
        if (v == inf) v = 0 // まだ数値が１こもでてきていない

        res = min(res, p3 + v + (k1 - p1) + (k2 - p2))
        val t = best
        best = next
        next = t
      }
      res
    }
    val ans = min(calc1, calc23)
    out.println(ans)
  }
}

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

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

  private[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._

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

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 k1, k2, k3 = ni()
    val n = k1 + k2 + k3
    val A1 = na(k1)
    val A2 = na(k2)
    val A3 = na(k3)
    sort(A1)
    sort(A2)
    sort(A3)

    // 全部１つの場所に移動するケース
    val calc1 = n - max(k1, max(k2, k3))

    val inf = 1e9.toInt

    // 3つともに数値があるケースと、２つにだけ数値があるケース
    def calc23: Int = {
      var p1, p2, p3 = 0
      var res = 1e9.toInt
      var best, next = Array.fill[Int](3)(inf)
      TO(1, n) { k =>
        Array.copy(best, 0, next, 0, 3)
        if(p1 < k1 && A1(p1) == k) {
          p1 += 1
          if (best(0) == inf) next(0) = 0
          next(1) = if (best(1) == inf) 1 else best(1) + 1
          next(2) = min(inf, min(best(2) + 1, best(0) + 1))
        }
        if(p2 < k2 && A2(p2) == k) {
          p2 += 1
          next(0) = if (best(0) == inf) 1 else best(0) + 1
          if (best(1) == inf) next(1) = 0
          next(2) = min(inf, min(best(2), best(0)))
        }
        debug(next)
        if(p3 < k3 && A3(p3) == k) p3 += 1

        var v = best.min
        if (v == inf) v = 0 // まだ数値が１こもでてきていない

        res = min(res, p3 + v + (k1 - p1) + (k2 - p2))
        val t = best
        best = next
        next = t
      }
      res
    }
    val ans = min(calc1, calc23)
    out.println(ans)
  }
}

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

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

  private[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._

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

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 k1, k2, k3 = ni()
    val n = k1 + k2 + k3
    val A1 = na(k1)
    val A2 = na(k2)
    val A3 = na(k3)
    sort(A1)
    sort(A2)
    sort(A3)

    // 全部１つの場所に移動するケース
    val calc1 = n - max(k1, max(k2, k3))

    val inf = 1e9.toInt

    // 3つともに数値があるケースと、２つにだけ数値があるケース
    def calc23: Int = {
      var p1, p2, p3 = 0
      var res = 1e9.toInt
      var best, next = Array.fill[Int](3)(inf)
      TO(1, n) { k =>
        if(p1 < k1 && A1(p1) == k) {
          p1 += 1
          if (best(0) == inf) next(0) = 0
          next(1) = if (best(1) == inf) 1 else best(1) + 1
          next(2) = min(inf, min(best(2) + 1, best(0) + 1))
        }
        if(p2 < k2 && A2(p2) == k) {
          p2 += 1
          next(0) = if (best(0) == inf) 1 else best(0) + 1
          if (best(1) == inf) next(1) = 0
          next(2) = min(inf, min(best(2), best(0)))
        }
        if(p3 < k3 && A3(p3) == k) {
          p3 += 1
          Array.copy(best, 0, next, 0, 3)
        }
        debug(next)

        var v = next.min
        if (v == inf) v = 0 // まだ数値が１こもでてきていない

        res = min(res, p3 + v + (k1 - p1) + (k2 - p2))
        val t = best
        best = next
        next = t
      }
      res
    }
    val ans = min(calc1, calc23)
    out.println(ans)
  }
}