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

  val t = readInt()

  (0 until t).foreach { _ =>
    val Array(n, m) = readLine().split(" ").map(_.toInt)

    var a = Array.ofDim[Array[Int]](n)
    (0 until n).foreach(a(_) = readLine().split(" ").map(_.toInt))

    var b = Array.fill((n + m) / 2)(Array(0, 0))
    for {
      i <- 1 to n
      j <- 1 to m
      k = i + j - 2
      d = k min (n + m - 2 - k)
    } b(d)(a(i - 1)(j - 1)) += 1

    val ans = b.take((n + m - 1) / 2).foldLeft(0)((a, t) => a + t.min)

    println(ans)
  }
}

import scala.io.StdIn.readLine

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

  def main(args: Array[String]): Unit = {
    //    val src = io.Source.fromFile("/usr/share/dict/words")
    //    val lines = src.getLines()
    //    src.close()
    val t = readLine().toInt
    for (i <- 1 to t) {
      val nm = readIntLine()
      val grid = (1 to nm.head).map(_ => readIntLine().toArray).toArray
      val isNSmall = nm.head <= nm.last
      println(calc(math.min(nm.head, nm.last), math.max(nm.head, nm.last),
        if (isNSmall) grid else grid.transpose))
    }
  }

  // assume n <= m
  def calc(n: Int, m: Int, grid: Array[Array[Int]]): Int = {
    var total = 0
    for (i <- 0 to (m + n - 3) / 2) {
      var zeroCount = 0
      var oneCount = 0
      for (j <- 0 to math.min(i, n - 1)) {
        if (grid(j)(i - j) == 0) zeroCount += 1 else oneCount += 1
        if (grid(n - 1 - j)(m - 1 - i + j) == 0) zeroCount += 1 else oneCount += 1
      }
      total += math.min(zeroCount, oneCount)
    }

    total
  }

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

//  def printArray[T](arr: Array[T]): Unit = {
//    val str = new StringBuilder()
//    str.addAll((if (arr.head == -1) 0 else arr.head).toString)
//    //    print(arr(0))
//    for (i <- 1 until arr.length) {
//      str.addAll(" " + (if (arr(i) == -1) 0 else arr(i)))
//    }
//    println(str)
//  }

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

}

import scala.io.StdIn.readLine

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

  def main(args: Array[String]): Unit = {
    //    val src = io.Source.fromFile("/usr/share/dict/words")
    //    val lines = src.getLines()
    //    src.close()
    val t = readLine().toInt
    for (i <- 1 to t) {
      val nm = readIntLine()
      val grid = (1 to nm.head).map(_ => readIntLine().toArray).toArray
      val isNSmall = nm.head <= nm.last
      println(calc(math.min(nm.head, nm.last), math.max(nm.head, nm.last),
        if (isNSmall) grid else grid.transpose))
    }
  }

  // assume n <= m
  def calc(n: Int, m: Int, grid: Array[Array[Int]]): Int = {
    var total = 0
    for (i <- 0 to m / 2) {
      var zeroCount = 0
      var oneCount = 0
      for (j <- 0 to math.min(i, n - 1)) {
        if (grid(j)(i - j) == 0) zeroCount += 1 else oneCount += 1
        if (grid(n - 1 - j)(m - 1 - i + j) == 0) zeroCount += 1 else oneCount += 1
      }
      total += math.min(zeroCount, oneCount)
    }

    total
  }

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

//  def printArray[T](arr: Array[T]): Unit = {
//    val str = new StringBuilder()
//    str.addAll((if (arr.head == -1) 0 else arr.head).toString)
//    //    print(arr(0))
//    for (i <- 1 until arr.length) {
//      str.addAll(" " + (if (arr(i) == -1) 0 else arr(i)))
//    }
//    println(str)
//  }

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

}

import scala.io.StdIn.readLine

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

  def main(args: Array[String]): Unit = {
    //    val src = io.Source.fromFile("/usr/share/dict/words")
    //    val lines = src.getLines()
    //    src.close()
    val t = readLine().toInt
    for (i <- 1 to t) {
      val nm = readIntLine()
      val grid = (1 to nm.head).map(_ => readIntLine().toArray).toArray
      val isNSmall = nm.head <= nm.last
      println(calc(math.min(nm.head, nm.last), math.max(nm.head, nm.last),
        if (isNSmall) grid else grid.transpose))
    }
  }

  // assume n <= m
  def calc(n: Int, m: Int, grid: Array[Array[Int]]): Int = {
    var total = 0
    for (i <- 0 to (m - (n - 1) % 2) / 2) {
      var zeroCount = 0
      var oneCount = 0
      for (j <- 0 to math.min(i, n - 1)) {
        if (grid(j)(i - j) == 0) zeroCount += 1 else oneCount += 1
        if (grid(n - 1 - j)(m - 1 - i + j) == 0) zeroCount += 1 else oneCount += 1
      }
      total += math.min(zeroCount, oneCount)
    }

    total
  }

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

//  def printArray[T](arr: Array[T]): Unit = {
//    val str = new StringBuilder()
//    str.addAll((if (arr.head == -1) 0 else arr.head).toString)
//    //    print(arr(0))
//    for (i <- 1 until arr.length) {
//      str.addAll(" " + (if (arr(i) == -1) 0 else arr(i)))
//    }
//    println(str)
//  }

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

}

import scala.io.StdIn.readLine

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

  def main(args: Array[String]): Unit = {
    //    val src = io.Source.fromFile("/usr/share/dict/words")
    //    val lines = src.getLines()
    //    src.close()
    val t = readLine().toInt
    for (i <- 1 to t) {
      val nm = readIntLine()
      val grid = (1 to nm.head).map(_ => readIntLine().toArray).toArray
      val isNSmall = nm.head <= nm.last
      println(calc(math.min(nm.head, nm.last), math.max(nm.head, nm.last),
        if (isNSmall) grid else grid.transpose))
    }
  }

  // assume n <= m
  def calc(n: Int, m: Int, grid: Array[Array[Int]]): Int = {
    var total = 0
    for (i <- 0 to (m - 1) / 2) {
      var zeroCount = 0
      var oneCount = 0
      for (j <- 0 to math.min(i, n - 1)) {
        if (grid(j)(i - j) == 0) zeroCount += 1 else oneCount += 1
        if (grid(n - 1 - j)(m - 1 - i + j) == 0) zeroCount += 1 else oneCount += 1
      }
      total += math.min(zeroCount, oneCount)
    }

    total
  }

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

//  def printArray[T](arr: Array[T]): Unit = {
//    val str = new StringBuilder()
//    str.addAll((if (arr.head == -1) 0 else arr.head).toString)
//    //    print(arr(0))
//    for (i <- 1 until arr.length) {
//      str.addAll(" " + (if (arr(i) == -1) 0 else arr(i)))
//    }
//    println(str)
//  }

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

}


object B extends App {

  def swaps(an: IndexedSeq[Int], bn: IndexedSeq[Int]): Int = {
    val n             = an.length
    val element2index = Array.fill(2 * n + 1)(0)
    (0 until n).foreach { i =>
      element2index(an(i)) = i
      element2index(bn(i)) = i
    }

    val minOddIndex  = element2index(1)
    val minEvenIndex = element2index(2)

    (3 to (2 * n))
      .foldLeft((minOddIndex + minEvenIndex, minOddIndex, minEvenIndex)) {
        case ((count, minOddIndex, minEvenIndex), element) =>
          val index = element2index(element)
          if (element % 2 == 0) {
            (count min (index + minOddIndex), minOddIndex, minEvenIndex min index)
          } else {
            (count, minOddIndex min index, minEvenIndex)
          }
      }
      ._1

    // val aj2j = Array.fill(2 * an.length)(0)
    // an.indices.foreach(j => aj2j(an(j)) = j)

    // bn.indices.foldLeft(Int.MaxValue) { (count, i) =>
    //   val bi = bn(i)
    //   val aj = (1 to (bi, 2)).minBy(aj2j)
    //   val j  = aj2j(aj)
    //   count min (i + j)
    // }
  }

  import InOut._

  val t = nextInt()

  (0 until t).foreach { _ =>
    val n  = nextInt()
    val an = nextInts(n)
    val bn = nextInts(n)

    out.println(swaps(an, bn))
    out.flush()
  }

  final object InOut {
    val in  = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)

    def nextInt()        = Integer.parseInt(nextToken())
    def nextInts(n: Int) = Array.fill(n)(nextInt())

    def nextLong()        = java.lang.Long.parseLong(nextToken())
    def nextLongs(n: Int) = Array.fill(n)(nextLong())

    def nextBig()        = BigInt(nextToken())
    def nextBigs(n: Int) = Array.fill(n)(nextBig())

    def nextLine() = in.readLine()

    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens())
        tokenizer = new java.util.StringTokenizer(in.readLine())
      tokenizer.nextToken()
    }
  }
}

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

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

    def RecursiveBinarySearch(Element_to_Search: Int)
                             (low: Int,
                              high: Int): Int =
    {
        // If element not found
        if (high - low <= 1) {
            if (a_row(low) < Element_to_Search)
                return low
            else
                return high
        }

        // Getting the middle element
        var middle = low + (high - low + 1) / 2

        // If element found

        // Searching in the left half
        if (a_row(middle) < Element_to_Search)
            return RecursiveBinarySearch(Element_to_Search)(low, middle)

        // Searching in the right half
        else
            return RecursiveBinarySearch(Element_to_Search)(middle + 1, high)
    }
    val a_row = new ArrayBuffer[Int]()

    def main(args: Array[String]): Unit = {
        val t = readInt()
        for (tt <- 1 to t) {
            val n = readInt()
            a_row.clear()
            var min_s = 2 * n + 1
            for (i <- 1 to n) {
                val tmp = readInt()
                min_s = min(min_s, tmp)
                a_row.append(min_s)
            }
            var ans = n + 1
            for (i <- 1 to n) {
                val tmp = readInt()
                ans = min(ans, i-1+RecursiveBinarySearch(tmp)(0, n-1))
            }
            writer.println(ans)
            writer.flush()
        }
    }
}

object B extends App {

  def swaps(an: IndexedSeq[Int], bn: IndexedSeq[Int]): Int = {
    val n    = an.length
    val ab2i = Array.fill(2 * n + 1)(0)
    (0 until n).foreach { i => ab2i(an(i)) = i; ab2i(bn(i)) = i }

    (3 to (2 * n))
      .foldLeft((ab2i(1) + ab2i(2), ab2i(1), ab2i(2))) { case ((count, odd, even), ab) =>
        val i = ab2i(ab)
        (ab % 2) match {
          case 0 => (count min (i + odd), odd, even min i)
          case _ => (count, odd min i, even)
        }
      }
      ._1
  }

  import InOut._

  val t = nextInt()

  (0 until t).foreach { _ =>
    val n  = nextInt()
    val an = nextInts(n)
    val bn = nextInts(n)

    out.println(swaps(an, bn))
    out.flush()
  }

  final object InOut {
    val in  = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)

    def nextInt()        = Integer.parseInt(nextToken())
    def nextInts(n: Int) = Array.fill(n)(nextInt())

    def nextLong()        = java.lang.Long.parseLong(nextToken())
    def nextLongs(n: Int) = Array.fill(n)(nextLong())

    def nextBig()        = BigInt(nextToken())
    def nextBigs(n: Int) = Array.fill(n)(nextBig())

    def nextLine() = in.readLine()

    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens())
        tokenizer = new java.util.StringTokenizer(in.readLine())
      tokenizer.nextToken()
    }
  }
}

object B extends App {

  def swaps(an: Seq[Int], bn: Seq[Int]): Int = {

    def search(from: Int, to: Int, f: Int => Boolean): Int = {
      @annotation.tailrec
      def go(left: Int, right: Int): Int =
        if (left + 1 >= right) left
        else {
          val middle = (left + right) >>> 1

          f(middle) match {
            case true  => go(middle, right)
            case false => go(left, middle)
          }
        }
      go(from, to)
    }

    val cn = an.zipWithIndex.sorted

    bn.zipWithIndex.foldLeft(Int.MaxValue) { case (count, (bi, i)) =>
      val j = search(0, cn.length, j => cn(j)._1 < bi)
      count min (i + cn(j)._2)
    }
  }

  import InOut._

  val t = nextInt()

  (0 until t).foreach { _ =>
    val n  = nextInt()
    val an = nextInts(n)
    val bn = nextInts(n)

    out.println(swaps(an, bn))
    out.flush()
  }

  final object InOut {
    val in  = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)

    def nextInt()        = Integer.parseInt(nextToken())
    def nextInts(n: Int) = Array.fill(n)(nextInt())

    def nextLong()        = java.lang.Long.parseLong(nextToken())
    def nextLongs(n: Int) = Array.fill(n)(nextLong())

    def nextBig()        = BigInt(nextToken())
    def nextBigs(n: Int) = Array.fill(n)(nextBig())

    def nextLine() = in.readLine()

    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens())
        tokenizer = new java.util.StringTokenizer(in.readLine())
      tokenizer.nextToken()
    }
  }
}

object B extends App {

  def swaps(an: Seq[Int], bn: Seq[Int]): Int = {

    def search(from: Int, to: Int, f: Int => Boolean): Int = {
      @annotation.tailrec
      def go(left: Int, right: Int): Int =
        if (left + 1 >= right) left
        else {
          val middle = (left + right) >>> 1

          f(middle) match {
            case true  => go(middle, right)
            case false => go(left, middle)
          }
        }
      go(from, to)
    }

    val cn = an.zipWithIndex.sorted

    bn.zipWithIndex.foldLeft(Int.MaxValue) { case (count, (bi, i)) =>
      val j = search(0, cn.length, j => cn(j)._1 < bi)
      count min (i + cn(j)._2)
    }
  }

  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val an = readLine().split(" ").map(_.toInt)
    val bn = readLine().split(" ").map(_.toInt)

    println(swaps(an, bn))
  }
}


object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(" ").map(_.toLong)
  val sum = data.tail.scan(data.head){_ + _}
  val sorted = data.sorted
  val sorsum = sorted.tail.scan(sorted.head){_ + _}
  val q = in.next().toInt
  val res = (1 to q).map { _ =>
    val Array(queryType, l, r) = in.next().split(" ").map(_.toInt)
    if (queryType == 1) {
      sum(r - 1) - (if (l >= 2) sum(l - 2) else 0)
    } else {
      sorsum(r - 1) - (if (l >= 2) sorsum(l - 2) else 0)
    }
  }
  println(res.mkString("\n"))
}

import scala.util.Try

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

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

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

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val input = readLongs(n)
    val sorted = input.sortBy(identity)
    for(i <- 1 until n) {
      input(i) += input(i-1)
    }
    for(i <- 1 until n) {
      sorted(i) += sorted(i-1)
    }

    val Array(m) = readInts(1)
    for(_ <- 0 until m) {
      val Array(t, l, r) = readInts(3)
      if(t == 1) {
        if(l-2 >= 0)
          println(input(r-1) - input(l-2))
        else
          println(input(r-1))
      } else {
        if(l-2 >= 0)
          println(sorted(r-1) - sorted(l-2))
        else
          println(sorted(r-1))
      }
    }
  }
}

import java.util.Scanner
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.Long.bitCount
import java.nio.CharBuffer
import java.util.Arrays.binarySearch
import scala.annotation.tailrec
import scala.annotation.switch
import scala.annotation.unchecked
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.PriorityQueue
import scala.math.Ordering.Implicits._
import scala.util.Random
import scala.util.control.Breaks._

object B extends App {
  // val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  object Input {
    import java.lang.Character._

    lazy val in = new BufferedReader(new InputStreamReader(java.lang.System.in))
    var buf: Array[Char] = Array()
    var pos: Int = 0

    def next(): String = {
      while (pos == buf.length) {
        buf = in.readLine.toArray
        pos = 0
      }
      while (isWhitespace(buf(pos))) {
        pos += 1
      }
      while (pos == buf.length) {
        buf = in.readLine.toArray
        pos = 0
      }
      val s = pos
      while (pos < buf.length && !isWhitespace(buf(pos))) {
        pos += 1
      }
      new java.lang.String(buf, s, pos - s)
    }

    def nextInt(): Int = next.toInt

    def nextLong(): Long = next.toLong

    def nextFloat(): Float = next.toFloat

    def nextDouble(): Double = next.toDouble

    val nextString: () => String = next _
  }

  import Input._

  val N = nextInt
  val V = Array.fill(N)(nextLong)
  val U = V.sorted
  val vv = Array.fill(N + 1)(0L)
  val uu = Array.fill(N + 1)(0L)
  (0 until N).foreach { i =>
    vv(i + 1) = vv(i) + V(i)
    uu(i + 1) = uu(i) + U(i)
  }
  val M = nextInt

  def solve(): Long = {

    def type1(l: Int, r: Int): Long = vv(r + 1) - vv(l)

    def type2(l: Int, r: Int): Long = uu(r + 1) - uu(l)

    val t = nextInt
    val l, r = nextInt - 1
    t match {
      case 1 => type1(l, r)
      case 2 => type2(l, r)
      case _ => throw new Exception("something wrong")
    }
  }

  for (_ <- 0 until M) out.println(solve)
  out.flush
}


object Solver {
  import InOut._
  def main(args: Array[String]): Unit = {
    for (_ <- 1 to nextInt) {
      val n = nextInt
      val arr = nextInts(n)
      var ans = "NO"
      for (num <- arr) {
        val rt = Math.round(Math.sqrt(num))
        if (rt * rt != num)
          ans = "YES"
      }
      out.println(ans)
    }
    out.flush()
  }
}

final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
}

object cf1514a {

  def readInt(): Int = {
		Console.in.readLine().toInt
	}

  def readLong(): Long= {
		Console.in.readLine().toLong
	}

	def readInts(): Array[Int] = {
		val line = Console.in.readLine()
		line.split(' ').map( _.toInt)
	}

	def main(args: Array[String]): Unit = {
		val cases = readInt()
		var nCase = 0
		val res = for (nCase <- 1 to cases) yield {
			readInt()
			val data = readInts()

			!data.forall( v => {
				val sq = Math.floor(Math.sqrt(v)).toInt
				sq*sq == v
			})
		}
		res.foreach(if (_) println("YES") else println("NO"))
  }
}


import java.io._

object C extends App {
	val n = InputReader.readLine.toInt
	var arr = InputReader.readLine.split(" ").map(_.toLong)

	def op(par: Array[Long], e: Long) = {
		if(e > par(0))
			Array(e, par(0))

		else if(e > par(1))
			Array(par(0), e)

		else par
	}

	val res = arr.foldLeft(Array(0L, 0L))(op)
	val s = arr.sum

	def whom = (x: Long) => if (x == res(0)) res(1) else res(0)
	val ans = arr.zipWithIndex.filter(x => s - x._1 == 2 * whom(x._1))

	val out = new PrintWriter(System.out)
	out.println(ans.length)
	ans.foreach(x => out.print(s"${x._2 + 1} "))
	out.close
}

object InputReader {
	val rd = new BufferedReader(new InputStreamReader(System.in), 32768);
	def readLine() = rd.readLine
}

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

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

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

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

  def solve(): Unit = {
    val N = ni()
    val A = na(N)
    val S = sumL(A)
    val mx = A.max
    val mxIx = A.indexWhere(_ == mx)
    val A2 = A.take(mxIx) ++ A.drop(mxIx + 1)
    val mx2 = A2.max
    val mx2Ix = A2.indexWhere(_ == mx2)
    val S1 = S - mx

    val ans = ArrayBuffer[Int]()
    rep(N) { i =>
      if (A(i) == mx) {
        if (S1 - mx2 == mx2) ans += i + 1
      } else {
        if (S1 - A(i) == mx) ans += i + 1
      }
    }

    out.println(ans.length)
    out.println(ans.mkString(" "))
  }

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

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

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

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

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

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

object CF_521_3_C {
    // The "good" number must always be the largest
    // In the case where we're examining the max for niceness, use the second largest
    // An element e is nice if the subtotal of the rest is 2 * the max, i.e. total - e = 2 *

  def solve(n: Int, as: Seq[Long]): (Int, Seq[Int]) = {
    val total = as.sum
    val max = as.max
    val secondMax = as.diff(Seq(max)).max
    val nices = for {
      (e, i) <- as.zipWithIndex
      if (e != max && total - e == 2 * max) || (e == max && total - e == 2 * secondMax)
    } yield i + 1
    (nices.size, nices)
  }

  // `solution` is defined by the input format - and can be called both from main and test script without repeating
  def solution(i: Input) = solve(i.int, {i.nextLine; i.collect(_.toLong)})

//     ~~~ Boilerplate that doesn't change ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def main(args: Array[String]) = {
    val out = new java.io.PrintWriter(System.out)
    val sol = solution(new Input(System.in))
    out.println(sol._1)
    out.println(sol._2 mkString " ")
    out.close()
  }

//     ~~~ Utility methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  import java.util.Scanner
  class Input(sc: Scanner) {
    def this(i: java.io.InputStream) = this(new Scanner(i))
    def this(s: String) = this(new Scanner(s.stripMargin))
    def int = sc.nextInt()
    def long = sc.nextLong()
    def double = sc.nextDouble()
    def nextLine = sc.nextLine()
    // If there are prior values, remember to call nextLine to advance past the newline character before collecting the line:
    def collect[T](f: String => T) = {sc.nextLine().split(" ").toVector.map(f)}
    def intSeq() = collect(_.toInt)
    def doubleSeq() = collect(_.toDouble)
  }

  def ceil(a: Int, b: Int) = (a - 1) / b + 1
  def ceil(a: Long, b: Long) = (a - 1) / b + 1

  import language.implicitConversions
  implicit def stringToInput(s: String): Input = new Input(s)
}

import java.io._

object C extends App {
	val n = InputReader.readLine.toInt
	var arr = InputReader.readLine.split(" ").map(_.toLong)

	val res = arr.foldLeft(Array(0L, 0L)) (
		(par, e) => {
			if(e > par(0))
				Array(e, par(0))

			else if(e > par(1))
				Array(par(0), e)

			else par
		}
	)

	val s = arr.sum
	def whom(x: Long) = if (x == res(0)) res(1) else res(0)
	val ans = arr.zipWithIndex.filter(x => s - x._1 == 2 * whom(x._1))

	val out = new PrintWriter(System.out)
	out.println(ans.length)
	ans.foreach(x => out.print(s"${x._2 + 1} "))
	out.close
}

object InputReader {
	val rd = new BufferedReader(new InputStreamReader(System.in), 32768);
	def readLine() = rd.readLine
}

import java.io._

object C extends App {
	val n = InputReader.readLine.toInt
	var arr = InputReader.readLine.split(" ").map(_.toInt)

	def op(par: Array[Int], e: Int) = {
		if(e > par(0))
			Array(e, par(1))

		else if(e > par(1))
			Array(par(0), e)

		else par
	}

	val res = arr.foldLeft(Array(0, 0))(op)
	val s = arr.sum

	def whom = (x: Int) => if (x == res(0)) res(1) else res(0)
	val ans = arr.zipWithIndex.filter(x => s - x._1 == 2 * whom(x._1))

	// println(ans.length)
	// ans.foreach(x => print(s"${x._2 + 1} "))

	val out = new PrintWriter(System.out)
	out.println(ans.length)
	ans.foreach(x => out.print(s"${x._2 + 1} "))
	out.close
}

object InputReader {
	val rd = new BufferedReader(new InputStreamReader(System.in), 32768);
	def readLine() = rd.readLine
}

import java.io._

object C extends App {
	val n = InputReader.readLine.toInt
	var arr = InputReader.readLine.split(" ").map(_.toLong)

	def op(par: Array[Long], e: Long) = {
		if(e > par(0))
			Array(e, par(1))

		else if(e > par(1))
			Array(par(0), e)

		else par
	}

	val res = arr.foldLeft(Array(0L, 0L))(op)
	val s = arr.sum

	def whom = (x: Long) => if (x == res(0)) res(1) else res(0)
	val ans = arr.zipWithIndex.filter(x => s - x._1 == 2 * whom(x._1))

	val out = new PrintWriter(System.out)
	out.println(ans.length)
	ans.foreach(x => out.print(s"${x._2 + 1} "))
	out.close
}

object InputReader {
	val rd = new BufferedReader(new InputStreamReader(System.in), 32768);
	def readLine() = rd.readLine
}

import java.io._

object C extends App {
	val n = InputReader.readLine.toInt
	var arr = InputReader.readLine.split(" ").map(_.toInt)

	def op(par: Array[Int], e: Int) = {
		if(e > par(0))
			Array(e, par(1))

		else if(e > par(1))
			Array(par(0), e)

		else par
	}

	val res = arr.foldLeft(Array(0, 0))(op)
	val s = arr.sum

	def whom = (x: Int) => if (x == res(0)) res(1) else res(0)
	val ans = arr.zipWithIndex.filter(x => s - x._1 == 2 * whom(x._1))

	// println(ans.length)
	// ans.foreach(x => print(s"${x._2 + 1} "))

	val out = new PrintWriter(System.out)
	out.println(ans.length)
	ans.foreach(x => out.print(s"${x._2 + 1} "))
}

object InputReader {
	val rd = new BufferedReader(new InputStreamReader(System.in), 32768);
	def readLine() = rd.readLine
}

object CF_521_3_C {
  def isGood(xs: Map[Long,Int], sum: Long) = sum % 2 == 0 && xs(sum/2) > 0

  def solve(n: Int, as: Seq[Long]): (Int, Seq[Int]) = {
    val total = as.sum
    val counts: Map[Long, Int] = as.groupBy(identity).mapValues(_.size).withDefaultValue(0)
    val nices = for {
      (a, i) <- as.zipWithIndex
      if isGood(counts + (a -> (counts(a) - 1)), total - a)
    } yield i + 1
    (nices.size, nices)
  }

  // `solution` is defined by the input format - and can be called both from main and test script without repeating
  def solution(i: Input) = solve(i.int, {i.nextLine; i.collect(_.toLong)})

//     ~~~ Boilerplate that doesn't change ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def main(args: Array[String]) = {
    val out = new java.io.PrintWriter(System.out)
    val sol = solution(new Input(System.in))
    out.println(sol)
    out.close()
  }

//     ~~~ Utility methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  import java.util.Scanner
  class Input(sc: Scanner) {
    def this(i: java.io.InputStream) = this(new Scanner(i))
    def this(s: String) = this(new Scanner(s.stripMargin))
    def int = sc.nextInt()
    def long = sc.nextLong()
    def double = sc.nextDouble()
    def nextLine = sc.nextLine()
    // If there are prior values, remember to call nextLine to advance past the newline character before collecting the line:
    def collect[T](f: String => T) = {sc.nextLine().split(" ").toVector.map(f)}
    def intSeq() = collect(_.toInt)
    def doubleSeq() = collect(_.toDouble)
  }

  def ceil(a: Int, b: Int) = (a - 1) / b + 1
  def ceil(a: Long, b: Long) = (a - 1) / b + 1

  import language.implicitConversions
  implicit def stringToInput(s: String): Input = new Input(s)
}


import scala.collection._
import java.util.Arrays
import scala.util.Random

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 as = readInts(n)
  //var as = Array.fill(n){ if (Random.nextInt(100) < 49) 1 else 0}
  val cs = Array.ofDim[Int](n)

  var bs = Array.ofDim[Int](n)

  cs(0) = as(0)
  cs(n - 1) = as(n - 1)

  var prev = as(0)
  var max = 0
  var cnt0 = 1
  var start = 0
  for (i <- 1 until n) {
    if (as(i) != prev) {
      if (cnt0 > max) max = cnt0
      cnt0 += 1
      prev = as(i)
    } else {
      val half = cnt0 / 2
      for (j <- start until start + half) cs(j) = as(start)
      for (j <- start + half until i) cs(j) = as(i)
      cnt0 = 1
      start = i
    }
  }
      val half = cnt0 / 2
      for (j <- start until start + half) cs(j) = as(start)
      for (j <- start + half to n - 1) cs(j) = as(n - 1)
  //println(as.mkString(" "))
  println(max / 2)
  println(cs.mkString(" "))

//  def process(as: Array[Int], bs: Array[Int]) {
//    bs(0) = as(0)
//    bs(n - 1) = as(n - 1)
//    for (i <- 1 until n - 1) {
//      val sum = as(i - 1) + as(i) + as(i + 1)
//      bs(i) = if (sum > 1) 1 else 0
//    }
//  }
//
//  var cnt = 0
//  var changed = true
//  while (changed) {
//    process(as, bs)
//    changed = false
//    if (!Arrays.equals(as, bs)) {
//      cnt += 1
//      changed = true
//      val tmp = as
//      as = bs
//      bs = tmp
//    }
//  }
//
//  Console.setOut(new java.io.BufferedOutputStream(Console.out))
//
//  println(cnt)
//  println(Arrays.equals(as, cs))
//  println(as.mkString(" "))
//
//  Console.flush
}

import java.io._
import java.util.ArrayList
import java.util.StringTokenizer
import java.security.SecureRandom

object C_Median_c {

  def main(args: Array[String]): Unit = {
    var debugV = false
    def db(x: => String) = if (debugV)  println(x) // nullary function

    val is = System.in

    //COMMENT ME !
//    val is = new ByteArrayInputStream(t33.trim.getBytes("ISO-8859-1"))
//    debugV = true

    val bis = new BufferedInputStream(is);
    val br = new BufferedReader(new InputStreamReader(bis));

    //---------------------------- parameters reading ------------------------------------
    val line1 = new StringTokenizer(br.readLine())
    var number = line1.nextToken().toInt
//    number = 50000

    var seq = new Array[Int](number)
    val line2 = new StringTokenizer(br.readLine())

//    var value = true
    val rnd = new SecureRandom()
    for (i <- 0 until number) {
      seq(i) = line2.nextToken().toInt
//      seq(i) = if (rnd.nextBoolean()) 1 else 1
//      seq(i) = if (value) 1 else 0
//      value = !value
    }

//     if (number == 499) {
//      for (i <- 400 until 600) {
//        print(seq(i) + " ")
//        if (i % 50 == 0) {
//          println()
//        }
//      }
//      println("debug output end")
//     }
    //---------------------------- parameters reading end --------------------------------

    var ind = 0
    var curLength = 0
    var maxLength = 0
    var curStart = 0
    var maxStart = -1
    var maxEnd = -1
    var atleastOne = false
    while (ind < seq.length) {
      if (check(ind, 0,1,0)) atleastOne = true
      if (check(ind, 1,0,1)) {
        if (curLength == 0) {
          curStart = ind
        }
        curLength += 2;
        ind += 1
        if (maxLength < curLength ) {
          maxLength = curLength;
          maxStart = curStart
         }
      } else {
        if (curLength != 0) {
//          if (maxLength == curLength) {
          if (ind == maxStart + maxLength) {
            maxEnd = ind
          }
        }
        curLength = 0
      }

      ind += 1

      def check(ind:Int, c1:Int, c2:Int, c3:Int):Boolean = {
        if (ind > seq.length-3) return false
        return seq(ind) == c1 && seq(ind+1) == c2 && seq(ind+2) == c3
      }
    }
    if (maxLength !=0 && maxStart != 0 && maxEnd != seq.length-1 &&
        !(maxStart > 0 && seq(maxStart-1) == 1) && !(maxEnd < seq.length-1 && seq(maxEnd+1) == 1)) {
      maxLength += 1
    }
    if (atleastOne && maxLength == 0) {
      maxLength = 1
    }
    db("Max " + maxLength + " start:" + maxStart + " end:" + maxEnd)

    if (maxLength == 0) {
      println(0)
    } else {
      println((maxLength +1)/2.toInt)
    }

    var res = Array.fill[Int](number)(0)
    var i = 0
    while (i < seq.length) {
      if (i ==0 || i == seq.length-1 || (i > 0 && seq(i) == 1 && seq(i-1) == 1)
          || (i+1 < seq.length && seq(i)==1 && seq(i+1) == 1)) {
        res(i) = seq(i)
      }
      i += 1
    }

    var const = res.clone()
    for (i <- 0 until res.length) {
      if (const(i) == 1 && i+1 < const.length && const(i+1) == 0) {
        //right edge
        var j = 1
        var ind = j *2 + i
        while (ind < seq.length && seq(ind) == 1 && seq(ind-1) == 0) {
          res(i+j) = 1
          j += 1
          ind = j *2 + i
        }
      }
    }
    for (i <- 0 until res.length) {
      if (const(i) == 0 && i+1 < const.length && const(i+1) == 1) {
        //left edge
        var j = 1
        var ind = i+1 - j *2
        while (ind > 0 && seq(ind) == 1 && seq(ind+1) == 0) {
          res(i+1-j) = 1
          j += 1
          ind = i+1 - j *2
        }
      }
    }

    var resStr = new StringBuffer()
    for(i<- 0 until res.length) {
      resStr.append(res(i)).append(" ")
    }

    println(resStr)

  }
}

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

import scala.annotation.tailrec

object A {
  def change(seq: Array[Int], left: Int, right: Int): Unit = {
    if (left <= right) {
      seq(left) = seq(left - 1)
      seq(right) = seq(right + 1)
      change(seq, left + 1, right - 1)
    }
  }

  def patchSeq(seq: Array[Int], marks: Array[Boolean], maxLength: Int, index: Int): Int = {
    if (index == seq.length) {
      maxLength
    } else if (marks(index)) {
      patchSeq(seq, marks, maxLength, index + 1)
    } else {
      val end = marks.indexWhere(v => v, index)
      change(seq, index, end - 1)
      patchSeq(seq, marks, math.max(maxLength, end - index), end)
    }
  }

  def work(in: Scanner, out: PrintWriter): Unit = {
    val n = in.nextInt()
    val seq = Array.fill(n)(in.nextInt())
    val marks = Array.tabulate(n)(i => i == 0 || i == n - 1 || seq(i) == seq(i - 1) || seq(i) == seq(i + 1))
    val answer = patchSeq(seq, marks, 0, 0)
    println((answer + 1) / 2)
    println(seq.mkString(" "))
  }

   def main(args: Array[String]): Unit = {
     val sc = new Scanner(new InputStreamReader(System.in))
     val pw = new PrintWriter(System.out)
     work(sc, pw)
     pw.close()
     sc.close()
   }

   class Scanner(reader: Reader) extends Closeable {
     private val br = new BufferedReader(reader)
     private var st = new StringTokenizer(br.readLine())

     override def close(): Unit = {
       br.close()
       st = null
     }

     @tailrec
     final def next(): String = if (st.hasMoreTokens) st.nextToken() else {
       st = new StringTokenizer(br.readLine())
       next()
     }

     final def nextInt()    = next().toInt
     final def nextLong()   = next().toLong
     final def nextDouble() = next().toDouble
   }
 }

object Main extends App{

import java.util.{Scanner,Random}

	def knots(v:Vector[Int]) = {
		val n = v.size
		var l = 0
		var r = 0
		var result:Vector[Vector[Int]] = Vector.empty
		while (l<n-1){
			r = l+1
			var log=false
			while ( r <=n-1 && v(l) == v(r) ){
				r+=1
				log = true
			}
				result = result :+ v.slice(l,r)
			l=r
		}
		result
	}

	def work() = {
		val s = new Scanner(System.in)
		val n = s.nextInt()
		s.nextLine()
		var arr = s.nextLine.trim.split(" ").map(_.toInt).toVector

		arr = Vector(arr.head) ++ arr ++ Vector(arr.last)
		val parts = knots(arr)

		var result:Vector[Int] = parts.head
		var step = 0;
		var last = result.head
		var len = 0
		for {
			i <- parts.tail
		} {
			//println(s"i:  $i")//debug
			if (i.size > 1){
				if (i.head == last && len >0){
					result = result ++ Vector.fill(len)(last)
					step = math.max(step,(len+1)/2)
				}
				else if (len > 0){
					result = result ++ Vector.fill(len/2)(last)
					result = result ++ Vector.fill(len/2)(i.head)
					step = math.max(step,len/2)
				}
				result = result ++ i
				last = i.head
				len = 0
			}
			else {
				len += 1
			}
			//println(len,result)//debug
		}
		result = result.slice(1,result.size-1)
		println(step)
		println(result.mkString(" "))
	}

	work()
}

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

import scala.annotation.tailrec

object A {
  def change(seq: Array[Int], left: Int, right: Int): Unit = {
    if (left < right) {
      seq(left) = seq(left - 1)
      seq(right) = seq(right + 1)
      change(seq, left + 1, right - 1)
    }
  }

  def patchSeq(seq: Array[Int], marks: Array[Boolean], maxLength: Int, index: Int): Int = {
    if (index == seq.length) {
      maxLength
    } else if (marks(index)) {
      patchSeq(seq, marks, maxLength, index + 1)
    } else {
      val end = marks.indexWhere(v => v, index)
      change(seq, index, end - 1)
      patchSeq(seq, marks, math.max(maxLength, end - index), end)
    }
  }

  def work(in: Scanner, out: PrintWriter): Unit = {
    val n = in.nextInt()
    val seq = Array.fill(n)(in.nextInt())
    val marks = Array.tabulate(n)(i => i == 0 || i == n - 1 || seq(i) == seq(i - 1) || seq(i) == seq(i + 1))
    val answer = patchSeq(seq, marks, 0, 0)
    println((answer + 1) / 2)
    println(seq.mkString(" "))
  }

   def main(args: Array[String]): Unit = {
     val sc = new Scanner(new InputStreamReader(System.in))
     val pw = new PrintWriter(System.out)
     work(sc, pw)
     pw.close()
     sc.close()
   }

   class Scanner(reader: Reader) extends Closeable {
     private val br = new BufferedReader(reader)
     private var st = new StringTokenizer(br.readLine())

     override def close(): Unit = {
       br.close()
       st = null
     }

     @tailrec
     final def next(): String = if (st.hasMoreTokens) st.nextToken() else {
       st = new StringTokenizer(br.readLine())
       next()
     }

     final def nextInt()    = next().toInt
     final def nextLong()   = next().toLong
     final def nextDouble() = next().toDouble
   }
 }

import java.io._
import java.util.ArrayList
import java.util.StringTokenizer
import java.security.SecureRandom

object C_Median_c {

  def main(args: Array[String]): Unit = {
    var debugV = false
    def db(x: => String) = if (debugV)  println(x) // nullary function

    val is = System.in

    //COMMENT ME !
//    val is = new ByteArrayInputStream(t6.trim.getBytes("ISO-8859-1"))
//    debugV = true

    val bis = new BufferedInputStream(is);
    val br = new BufferedReader(new InputStreamReader(bis));

    //---------------------------- parameters reading ------------------------------------
    val line1 = new StringTokenizer(br.readLine())
    var number = line1.nextToken().toInt
//    number = 50000

    var seq = new Array[Int](number)
    val line2 = new StringTokenizer(br.readLine())

//    var value = true
    val rnd = new SecureRandom()
    for (i <- 0 until number) {
      seq(i) = line2.nextToken().toInt
//      seq(i) = if (rnd.nextBoolean()) 1 else 1
//      seq(i) = if (value) 1 else 0
//      value = !value
    }

//     if (number == 499) {
//      for (i <- 400 until 600) {
//        print(seq(i) + " ")
//        if (i % 50 == 0) {
//          println()
//        }
//      }
//      println("debug output end")
//     }
    //---------------------------- parameters reading end --------------------------------

    var ind = 0
    var curLength = 0
    var maxLength = 0
    var curStart = 0
    var maxStart = -1
    var maxEnd = -1
    while (ind < seq.length) {
      if (check(ind, 1,0,1)) {
        if (curLength == 0) {
          curStart = ind
        }
        curLength += 2;
        ind += 1
        if (maxLength < curLength ) {
          maxLength = curLength;
          maxStart = curStart
         }
      } else {
        if (curLength != 0) {
//          if (maxLength == curLength) {
          if (ind == maxStart + maxLength) {
            maxEnd = ind
          }
        }
        curLength = 0
      }

      ind += 1

      def check(ind:Int, c1:Int, c2:Int, c3:Int):Boolean = {
        if (ind > seq.length-3) return false
        return seq(ind) == c1 && seq(ind+1) == c2 && seq(ind+2) == c3
      }
    }
    if (maxLength !=0 && maxStart != 0 && maxEnd != seq.length-1 &&
        !(maxStart > 0 && seq(maxStart-1) == 1) && !(maxEnd < seq.length-1 && seq(maxEnd+1) == 1)) {
      maxLength += 1
    }
    db("Max " + maxLength + " start:" + maxStart + " end:" + maxEnd)

    if (maxLength == 0) {
      println(0)
    } else {
      println((maxLength +1)/2.toInt)
    }

    var res = Array.fill[Int](number)(0)
    var i = 0
    while (i < seq.length) {
      if (i ==0 || i == seq.length-1 || (i > 0 && seq(i) == 1 && seq(i-1) == 1)
          || (i+1 < seq.length && seq(i)==1 && seq(i+1) == 1)) {
        res(i) = seq(i)
      }
      i += 1
    }

    var const = res.clone()
    for (i <- 0 until res.length) {
      if (const(i) == 1 && i+1 < const.length && const(i+1) == 0) {
        //right edge
        var j = 1
        var ind = j *2 + i
        while (ind < seq.length && seq(ind) == 1 && seq(ind-1) == 0) {
          res(i+j) = 1
          j += 1
          ind = j *2 + i
        }
      }
    }
    for (i <- 0 until res.length) {
      if (const(i) == 0 && i+1 < const.length && const(i+1) == 1) {
        //left edge
        var j = 1
        var ind = i+1 - j *2
        while (ind > 0 && seq(ind) == 1 && seq(ind+1) == 0) {
          res(i+1-j) = 1
          j += 1
          ind = i+1 - j *2
        }
      }
    }

    var resStr = new StringBuffer()
    for(i<- 0 until res.length) {
      resStr.append(res(i)).append(" ")
    }

    println(resStr)

  }
}

import java.io._
import java.util.ArrayList
import java.util.StringTokenizer
import java.security.SecureRandom

object C_Median_c {

  def main(args: Array[String]): Unit = {
    var debugV = false
    def db(x: => String) = if (debugV)  println(x) // nullary function

    val is = System.in

    //COMMENT ME !
//    val is = new ByteArrayInputStream(t8.trim.getBytes("ISO-8859-1"))
//    debugV = true

    val bis = new BufferedInputStream(is);
    val br = new BufferedReader(new InputStreamReader(bis));

    //---------------------------- parameters reading ------------------------------------
    val line1 = new StringTokenizer(br.readLine())
    var number = line1.nextToken().toInt
//    number = 50000

    var seq = new Array[Int](number)
    val line2 = new StringTokenizer(br.readLine())

//    var value = true
    val rnd = new SecureRandom()
    for (i <- 0 until number) {
      seq(i) = line2.nextToken().toInt
//      seq(i) = if (rnd.nextBoolean()) 1 else 1
//      seq(i) = if (value) 1 else 0
//      value = !value
    }

     if (number == 499) {
       for (i <- 0 until 200) {
         print(seq(i) + " ")
         if (i % 50 == 0) {
          println()
        }
         println("debug output end")
       }
     }
    //---------------------------- parameters reading end --------------------------------

    var ind = 0
    var curLength = 0
    var maxLength = 0
    var curStart = 0
    var maxStart = -1
    var maxEnd = -1
    while (ind < seq.length) {
      if (check(ind, 1,0,1)) {
        if (curLength == 0) {
          curStart = ind
        }
        curLength += 2;
        ind += 1
        if (maxLength < curLength ) {
          maxLength = curLength;
          maxStart = curStart
         }
      } else {
        if (curLength != 0) {
          if (maxLength == curLength) {
            maxEnd = ind
          }
        }
        curLength = 0
      }

      ind += 1

      def check(ind:Int, c1:Int, c2:Int, c3:Int):Boolean = {
        if (ind > seq.length-3) return false
        return seq(ind) == c1 && seq(ind+1) == c2 && seq(ind+2) == c3
      }
    }
    if (maxLength !=0 && maxStart != 0 && maxEnd != seq.length-1 &&
        !(maxStart > 0 && seq(maxStart-1) == 1) && !(maxEnd < seq.length-1 && seq(maxEnd+1) == 1)) {
      maxLength += 1
    }
    db("Max " + maxLength + " start:" + maxStart + " end:" + maxEnd)

    if (maxLength == 0) {
      println(0)
    } else {
      println((maxLength +1)/2.toInt)
    }

    var res = Array.fill[Int](number)(0)
    var i = 0
    while (i < seq.length) {
      if (i ==0 || i == seq.length-1 || (i > 0 && seq(i) == 1 && seq(i-1) == 1)
          || (i+1 < seq.length && seq(i)==1 && seq(i+1) == 1)) {
        res(i) = seq(i)
      }
      i += 1
    }

    var const = res.clone()
    for (i <- 0 until res.length) {
      if (const(i) == 1 && i+1 < const.length && const(i+1) == 0) {
        //right edge
        var j = 1
        var ind = j *2 + i
        while (ind < seq.length && seq(ind) == 1 && seq(ind-1) == 0) {
          res(i+j) = 1
          j += 1
          ind = j *2 + i
        }
      }
    }
    for (i <- 0 until res.length) {
      if (const(i) == 0 && i+1 < const.length && const(i+1) == 1) {
        //left edge
        var j = 1
        var ind = i+1 - j *2
        while (ind > 0 && seq(ind) == 1 && seq(ind+1) == 0) {
          res(i+1-j) = 1
          j += 1
          ind = i+1 - j *2
        }
      }
    }

    var resStr = new StringBuffer()
    for(i<- 0 until res.length) {
      resStr.append(res(i)).append(" ")
    }

    println(resStr)

  }
}

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

object C {

  def main(args: Array[String]): Unit = {
    var debugV = false
    def db(x: => String) = if (debugV)  println(x) // nullary function

    val is = System.in

    //COMMENT ME !
//    val is = new ByteArrayInputStream(sa1.trim.getBytes("ISO-8859-1"))
//    debugV = true

    val bis = new BufferedInputStream(is);
    val br = new BufferedReader(new InputStreamReader(bis));

    //---------------------------- parameters reading ------------------------------------
    val line1 = new StringTokenizer(br.readLine())
    val number = line1.nextToken().toInt

    var seq = new Array[Int](number)
    val cur = new Array[Int](number)
    val line2 = new StringTokenizer(br.readLine())

    for (i <- 0 until number) {
      seq(i) = line2.nextToken().toInt
      cur(i) = seq(i)
    }
    //---------------------------- parameters reading end --------------------------------

    var steps = 0
    var changed = true
    var res = new StringBuffer()

    while (changed) {
      changed = false
      for (i <- 0 until number) {
        derive(i)
      }
      if (changed) {
        steps += 1
      }
      seq = cur
    }

    def derive(i:Int) {
      if (i == 0 || i == number-1) {
          cur(i) = seq(i)
        } else {
          if (comp(i, Array(0,1,0))) { // || ) {
            cur(i) = 0
            changed = true
          } else if (comp(i, Array(1,0,1))) {
            cur(i) = 1
            changed = true
          } else {
            cur(i) = seq(i)
          }
        }
      db("replaced " + i + " " + seq(i) + " to " + cur(i))
    }

    println(steps)

    for (i <- 0 until number) {
      res.append(cur(i)).append(" ")
    }
    println(res)

    def comp(ind:Int, num:Array[Int]): Boolean ={
      return seq(ind-1) ==
        num(0) &&
        seq(ind) ==
          num(1) &&
          seq(ind+1) ==
            num(2)
    }

  }

//========================= samples ========================
val sa1 = """
5
0 1 0 1 0
"""

//========================= samples end ====================
}

import java.io._
import java.util.ArrayList
import java.util.StringTokenizer
import java.security.SecureRandom

object C_Median_c {

  def main(args: Array[String]): Unit = {
    var debugV = false
    def db(x: => String) = if (debugV)  println(x) // nullary function

    val is = System.in

    //COMMENT ME !
//    val is = new ByteArrayInputStream(t8.trim.getBytes("ISO-8859-1"))
//    debugV = true

    val bis = new BufferedInputStream(is);
    val br = new BufferedReader(new InputStreamReader(bis));

    //---------------------------- parameters reading ------------------------------------
    val line1 = new StringTokenizer(br.readLine())
    var number = line1.nextToken().toInt
//    number = 50000

    var seq = new Array[Int](number)
    val line2 = new StringTokenizer(br.readLine())

//    var value = true
    val rnd = new SecureRandom()
    for (i <- 0 until number) {
      seq(i) = line2.nextToken().toInt
//      seq(i) = if (rnd.nextBoolean()) 1 else 1
//      seq(i) = if (value) 1 else 0
//      value = !value
    }

     if (number == 499) {
      for (i <- 0 until 200) {
        print(seq(i) + " ")
        if (i % 50 == 0) {
          println()
        }
      }
      println("debug output end")
     }
    //---------------------------- parameters reading end --------------------------------

    var ind = 0
    var curLength = 0
    var maxLength = 0
    var curStart = 0
    var maxStart = -1
    var maxEnd = -1
    while (ind < seq.length) {
      if (check(ind, 1,0,1)) {
        if (curLength == 0) {
          curStart = ind
        }
        curLength += 2;
        ind += 1
        if (maxLength < curLength ) {
          maxLength = curLength;
          maxStart = curStart
         }
      } else {
        if (curLength != 0) {
          if (maxLength == curLength) {
            maxEnd = ind
          }
        }
        curLength = 0
      }

      ind += 1

      def check(ind:Int, c1:Int, c2:Int, c3:Int):Boolean = {
        if (ind > seq.length-3) return false
        return seq(ind) == c1 && seq(ind+1) == c2 && seq(ind+2) == c3
      }
    }
    if (maxLength !=0 && maxStart != 0 && maxEnd != seq.length-1 &&
        !(maxStart > 0 && seq(maxStart-1) == 1) && !(maxEnd < seq.length-1 && seq(maxEnd+1) == 1)) {
      maxLength += 1
    }
    db("Max " + maxLength + " start:" + maxStart + " end:" + maxEnd)

    if (maxLength == 0) {
      println(0)
    } else {
      println((maxLength +1)/2.toInt)
    }

    var res = Array.fill[Int](number)(0)
    var i = 0
    while (i < seq.length) {
      if (i ==0 || i == seq.length-1 || (i > 0 && seq(i) == 1 && seq(i-1) == 1)
          || (i+1 < seq.length && seq(i)==1 && seq(i+1) == 1)) {
        res(i) = seq(i)
      }
      i += 1
    }

    var const = res.clone()
    for (i <- 0 until res.length) {
      if (const(i) == 1 && i+1 < const.length && const(i+1) == 0) {
        //right edge
        var j = 1
        var ind = j *2 + i
        while (ind < seq.length && seq(ind) == 1 && seq(ind-1) == 0) {
          res(i+j) = 1
          j += 1
          ind = j *2 + i
        }
      }
    }
    for (i <- 0 until res.length) {
      if (const(i) == 0 && i+1 < const.length && const(i+1) == 1) {
        //left edge
        var j = 1
        var ind = i+1 - j *2
        while (ind > 0 && seq(ind) == 1 && seq(ind+1) == 0) {
          res(i+1-j) = 1
          j += 1
          ind = i+1 - j *2
        }
      }
    }

    var resStr = new StringBuffer()
    for(i<- 0 until res.length) {
      resStr.append(res(i)).append(" ")
    }

    println(resStr)

  }
}

import java.io._
import java.util.ArrayList
import java.util.StringTokenizer
import java.security.SecureRandom

object C_Median_c {

  def main(args: Array[String]): Unit = {
    var debugV = false
    def db(x: => String) = if (debugV)  println(x) // nullary function

    val is = System.in

    //COMMENT ME !
//    val is = new ByteArrayInputStream(t8.trim.getBytes("ISO-8859-1"))
//    debugV = true

    val bis = new BufferedInputStream(is);
    val br = new BufferedReader(new InputStreamReader(bis));

    //---------------------------- parameters reading ------------------------------------
    val line1 = new StringTokenizer(br.readLine())
    var number = line1.nextToken().toInt
//    number = 50000

    var seq = new Array[Int](number)
    val line2 = new StringTokenizer(br.readLine())

//    var value = true
    val rnd = new SecureRandom()
    for (i <- 0 until number) {
      seq(i) = line2.nextToken().toInt
//      seq(i) = if (rnd.nextBoolean()) 1 else 1
//      seq(i) = if (value) 1 else 0
//      value = !value
    }

     if (number == 499) {
       for (i <- 0 until 200) {
         print(seq(i) + " ")
         if (i % 50 == 0) {
          println()
        }
       }
     }
    //---------------------------- parameters reading end --------------------------------

    var ind = 0
    var curLength = 0
    var maxLength = 0
    var curStart = 0
    var maxStart = -1
    var maxEnd = -1
    while (ind < seq.length) {
      if (check(ind, 1,0,1)) {
        if (curLength == 0) {
          curStart = ind
        }
        curLength += 2;
        ind += 1
        if (maxLength < curLength ) {
          maxLength = curLength;
          maxStart = curStart
         }
      } else {
        if (curLength != 0) {
          if (maxLength == curLength) {
            maxEnd = ind
          }
        }
        curLength = 0
      }

      ind += 1

      def check(ind:Int, c1:Int, c2:Int, c3:Int):Boolean = {
        if (ind > seq.length-3) return false
        return seq(ind) == c1 && seq(ind+1) == c2 && seq(ind+2) == c3
      }
    }
    if (maxLength !=0 && maxStart != 0 && maxEnd != seq.length-1 &&
        !(maxStart > 0 && seq(maxStart-1) == 1) && !(maxEnd < seq.length-1 && seq(maxEnd+1) == 1)) {
      maxLength += 1
    }
    db("Max " + maxLength + " start:" + maxStart + " end:" + maxEnd)

    if (maxLength == 0) {
      println(0)
    } else {
      println((maxLength +1)/2.toInt)
    }

    var res = Array.fill[Int](number)(0)
    var i = 0
    while (i < seq.length) {
      if (i ==0 || i == seq.length-1 || (i > 0 && seq(i) == 1 && seq(i-1) == 1)
          || (i+1 < seq.length && seq(i)==1 && seq(i+1) == 1)) {
        res(i) = seq(i)
      }
      i += 1
    }

    var const = res.clone()
    for (i <- 0 until res.length) {
      if (const(i) == 1 && i+1 < const.length && const(i+1) == 0) {
        //right edge
        var j = 1
        var ind = j *2 + i
        while (ind < seq.length && seq(ind) == 1 && seq(ind-1) == 0) {
          res(i+j) = 1
          j += 1
          ind = j *2 + i
        }
      }
    }
    for (i <- 0 until res.length) {
      if (const(i) == 0 && i+1 < const.length && const(i+1) == 1) {
        //left edge
        var j = 1
        var ind = i+1 - j *2
        while (ind > 0 && seq(ind) == 1 && seq(ind+1) == 0) {
          res(i+1-j) = 1
          j += 1
          ind = i+1 - j *2
        }
      }
    }

    var resStr = new StringBuffer()
    for(i<- 0 until res.length) {
      resStr.append(res(i)).append(" ")
    }

    println(resStr)

  }
  }

import java.io._
import java.util.ArrayList
import java.util.StringTokenizer
import java.security.SecureRandom

object C_Median_c {

  def main(args: Array[String]): Unit = {
    var debugV = false
    def db(x: => String) = if (debugV)  println(x) // nullary function

    val is = System.in

    //COMMENT ME !
//    val is = new ByteArrayInputStream(t6.trim.getBytes("ISO-8859-1"))
//    debugV = true

    val bis = new BufferedInputStream(is);
    val br = new BufferedReader(new InputStreamReader(bis));

    //---------------------------- parameters reading ------------------------------------
    val line1 = new StringTokenizer(br.readLine())
    var number = line1.nextToken().toInt
//    number = 50000

    var seq = new Array[Int](number)
    val line2 = new StringTokenizer(br.readLine())

//    var value = true
    val rnd = new SecureRandom()
    for (i <- 0 until number) {
      seq(i) = line2.nextToken().toInt
//      seq(i) = if (rnd.nextBoolean()) 1 else 1
//      seq(i) = if (value) 1 else 0
//      value = !value
    }
    //---------------------------- parameters reading end --------------------------------

    var ind = 0
    var curLength = 0
    var maxLength = 0
    var curStart = 0
    var maxStart = -1
    var maxEnd = -1
    while (ind < seq.length) {
      if (check(ind, 1,0,1)) {
        if (curLength == 0) {
          curStart = ind
        }
        curLength += 2;
        ind += 1
        if (maxLength < curLength ) {
          maxLength = curLength;
          maxStart = curStart
         }
      } else {
        if (curLength != 0) {
          if (maxLength == curLength) {
            maxEnd = ind
          }
        }
        curLength = 0
      }

      ind += 1

      def check(ind:Int, c1:Int, c2:Int, c3:Int):Boolean = {
        if (ind > seq.length-3) return false
        return seq(ind) == c1 && seq(ind+1) == c2 && seq(ind+2) == c3
      }
    }
    if (maxLength !=0 && maxStart != 0 && maxEnd != seq.length-1 &&
        !(maxStart > 0 && seq(maxStart-1) == 1) && !(maxEnd < seq.length-1 && seq(maxEnd+1) == 1)) {
      maxLength += 1
    }
    db("Max " + maxLength + " start:" + maxStart + " end:" + maxEnd)

    if (maxLength == 0) {
      println(0)
    } else {
      println((maxLength +1)/2.toInt)
    }

    var res = Array.fill[Int](number)(0)
    var i = 0
    while (i < seq.length) {
      if (i ==0 || i == seq.length-1 || (i > 0 && seq(i) == 1 && seq(i-1) == 1)
          || (i+1 < seq.length && seq(i)==1 && seq(i+1) == 1)) {
        res(i) = seq(i)
      }
      i += 1
    }

    var const = res.clone()
    for (i <- 0 until res.length) {
      if (const(i) == 1 && i+1 < const.length && const(i+1) == 0) {
        //right edge
        var j = 1
        var ind = j *2 + i
        while (ind < seq.length && seq(ind) == 1 && seq(ind-1) == 0) {
          res(i+j) = 1
          j += 1
          ind = j *2 + i
        }
      }
    }
    for (i <- 0 until res.length) {
      if (const(i) == 0 && i+1 < const.length && const(i+1) == 1) {
        //left edge
        var j = 1
        var ind = i+1 - j *2
        while (ind > 0 && seq(ind) == 1 && seq(ind+1) == 0) {
          res(i+1-j) = 1
          j += 1
          ind = i+1 - j *2
        }
      }
    }

    var resStr = new StringBuffer()
    for(i<- 0 until res.length) {
      resStr.append(res(i)).append(" ")
    }

    println(resStr)

  }
}

import java.io._
import java.util.ArrayList
import java.util.StringTokenizer
import java.security.SecureRandom

object C_Median_c {

  def main(args: Array[String]): Unit = {
    var debugV = false
    def db(x: => String) = if (debugV)  println(x) // nullary function

    val is = System.in

    //COMMENT ME !
//    val is = new ByteArrayInputStream(m13.trim.getBytes("ISO-8859-1"))
//    debugV = true

    val bis = new BufferedInputStream(is);
    val br = new BufferedReader(new InputStreamReader(bis));

    //---------------------------- parameters reading ------------------------------------
    val line1 = new StringTokenizer(br.readLine())
    var number = line1.nextToken().toInt
//    number = 50000

    var seq = new Array[Int](number)
    val line2 = new StringTokenizer(br.readLine())

//    var value = true
    val rnd = new SecureRandom()
    for (i <- 0 until number) {
      seq(i) = line2.nextToken().toInt
//      seq(i) = if (rnd.nextBoolean()) 1 else 1
//      seq(i) = if (value) 1 else 0
//      value = !value
    }
    //---------------------------- parameters reading end --------------------------------

    var ind = 0
    var curLength = 0
    var maxLength = 0
    var curStart = 0
    var maxStart = -1
    var maxEnd = -1
    while (ind < seq.length) {
      if (check(ind, 1,0,1)) {
        if (curLength == 0) {
          curStart = ind
        }
        curLength += 2;
        ind += 1
        if (maxLength < curLength ) {
          maxLength = curLength;
          maxStart = curStart
         }
      } else {
        if (curLength != 0) {
          if (maxLength == curLength) {
            maxEnd = ind
          }
        }
        curLength = 0
      }

      ind += 1

      def check(ind:Int, c1:Int, c2:Int, c3:Int):Boolean = {
        if (ind > seq.length-3) return false
        return seq(ind) == c1 && seq(ind+1) == c2 && seq(ind+2) == c3
      }
    }
    if (maxLength !=0 && maxStart != 0 && maxEnd != seq.length-1 &&
        !(maxStart == 1 && seq(0) == 1) && !(maxStart == seq.length-2 && seq(seq.length-1) == 1)) {
      maxLength += 1
    }
//    db("Max " + maxLength + " start:" + maxStart + " end:" + maxEnd)

    if (maxLength == 0) {
      println(0)
    } else {
      println((maxLength +1)/2.toInt)
    }

    var res = Array.fill[Int](number)(0)
    var i = 0
    var pStart = -1;
    while (i < seq.length) {
      if (i ==0 || i == seq.length-1 || (i > 0 && seq(i) == 1 && seq(i-1) == 1)
          || (i+1 < seq.length && seq(i)==1 && seq(i+1) == 1)) {
        res(i) = seq(i)
      }
      i += 1
    }

    var const = res.clone()
    for (i <- 0 until res.length) {
      if (const(i) == 1 && i+1 < const.length && const(i+1) == 0) {
        //right edge
        var j = 1
        var ind = j *2 + i
        while (ind < seq.length && seq(ind) == 1 && seq(ind-1) == 0) {
          res(i+j) = 1
          j += 1
          ind = j *2 + i
        }
      }
    }
    for (i <- 0 until res.length) {
      if (const(i) == 0 && i+1 < const.length && const(i+1) == 1) {
        //left edge
        var j = 1
        var ind = i+1 - j *2
        while (ind > 0 && seq(ind) == 1 && seq(ind+1) == 0) {
          res(i+1-j) = 1
          j += 1
          ind = i+1 - j *2
        }
      }
    }

    var resStr = new StringBuffer()
    for(i<- 0 until res.length) {
      resStr.append(res(i)).append(" ")
    }

    println(resStr)

  }
}

import java.io._
import java.util.ArrayList
import java.util.StringTokenizer
import java.security.SecureRandom

object C_Median_c {

  def main(args: Array[String]): Unit = {
    var debugV = false
    def db(x: => String) = if (debugV)  println(x) // nullary function

    val is = System.in

    //COMMENT ME !
//    val is = new ByteArrayInputStream(t8.trim.getBytes("ISO-8859-1"))
//    debugV = true

    val bis = new BufferedInputStream(is);
    val br = new BufferedReader(new InputStreamReader(bis));

    //---------------------------- parameters reading ------------------------------------
    val line1 = new StringTokenizer(br.readLine())
    var number = line1.nextToken().toInt
//    number = 50000

    var seq = new Array[Int](number)
    val line2 = new StringTokenizer(br.readLine())

//    var value = true
    val rnd = new SecureRandom()
    for (i <- 0 until number) {
      seq(i) = line2.nextToken().toInt
//      seq(i) = if (rnd.nextBoolean()) 1 else 1
//      seq(i) = if (value) 1 else 0
//      value = !value
    }

     if (number == 499) {
      for (i <- 200 until 400) {
        print(seq(i) + " ")
        if (i % 50 == 0) {
          println()
        }
      }
      println("debug output end")
     }
    //---------------------------- parameters reading end --------------------------------

    var ind = 0
    var curLength = 0
    var maxLength = 0
    var curStart = 0
    var maxStart = -1
    var maxEnd = -1
    while (ind < seq.length) {
      if (check(ind, 1,0,1)) {
        if (curLength == 0) {
          curStart = ind
        }
        curLength += 2;
        ind += 1
        if (maxLength < curLength ) {
          maxLength = curLength;
          maxStart = curStart
         }
      } else {
        if (curLength != 0) {
          if (maxLength == curLength) {
            maxEnd = ind
          }
        }
        curLength = 0
      }

      ind += 1

      def check(ind:Int, c1:Int, c2:Int, c3:Int):Boolean = {
        if (ind > seq.length-3) return false
        return seq(ind) == c1 && seq(ind+1) == c2 && seq(ind+2) == c3
      }
    }
    if (maxLength !=0 && maxStart != 0 && maxEnd != seq.length-1 &&
        !(maxStart > 0 && seq(maxStart-1) == 1) && !(maxEnd < seq.length-1 && seq(maxEnd+1) == 1)) {
      maxLength += 1
    }
    db("Max " + maxLength + " start:" + maxStart + " end:" + maxEnd)

    if (maxLength == 0) {
      println(0)
    } else {
      println((maxLength +1)/2.toInt)
    }

    var res = Array.fill[Int](number)(0)
    var i = 0
    while (i < seq.length) {
      if (i ==0 || i == seq.length-1 || (i > 0 && seq(i) == 1 && seq(i-1) == 1)
          || (i+1 < seq.length && seq(i)==1 && seq(i+1) == 1)) {
        res(i) = seq(i)
      }
      i += 1
    }

    var const = res.clone()
    for (i <- 0 until res.length) {
      if (const(i) == 1 && i+1 < const.length && const(i+1) == 0) {
        //right edge
        var j = 1
        var ind = j *2 + i
        while (ind < seq.length && seq(ind) == 1 && seq(ind-1) == 0) {
          res(i+j) = 1
          j += 1
          ind = j *2 + i
        }
      }
    }
    for (i <- 0 until res.length) {
      if (const(i) == 0 && i+1 < const.length && const(i+1) == 1) {
        //left edge
        var j = 1
        var ind = i+1 - j *2
        while (ind > 0 && seq(ind) == 1 && seq(ind+1) == 0) {
          res(i+1-j) = 1
          j += 1
          ind = i+1 - j *2
        }
      }
    }

    var resStr = new StringBuffer()
    for(i<- 0 until res.length) {
      resStr.append(res(i)).append(" ")
    }

    println(resStr)

  }
}


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

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

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

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

  def solve(): Unit = {
    var x = ni()
    val ans = ArrayBuffer[Int]()

    def isPerfect(n: Int): Boolean = {
      REP(60) { i =>
        if (n == (1L << i) - 1) return true
      }
      false
    }

    // 左から最初に0になる場所
    def findT(n: Int): Int = {
      if (n == 0) return 1

      var t = log2(Integer.highestOneBit(n))
      while((n & (1 << t)) > 0) {
        t -= 1
      }
      t + 1
    }

    var i = 0
    while(!isPerfect(x)) {
      if (i % 2 == 0) {
        val t = findT(x)
        val y = (1 << t) - 1
        //      debug(s"t: $t x:$x y:$y => ${(x ^ y) + 1}")
        x = x ^ y
        debug(s"t: $t x:$x")
        ans += t
      } else {
        x += 1
      }
      i += 1
    }

    out.println(i)
    out.println(ans.mkString(" "))
  }

  def log2(x: Int): Int = {
    assert(x > 0)
    var a = x
    var i = 0 // 何回2で割ったら1になるか
    while(a > 1) {
      i += 1
      a >>>= 1
    }
    i
  }

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

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

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

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

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

  def debugDim(m: Array[Array[Long]]): Unit = DEBUG {
    REP(m.length) { i =>
      debug(m(i))
    }
  }

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

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

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

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

object b extends App{
  import scala.math.log
  import scala.io.StdIn.readInt

  def log2(x: Double) = log(x) / log(2)
  def binLength(x: Int) = if (x == 0) 1 else log2(x).toInt + 1
  def inversion(x: Int):Int = (~x) & ((1 << binLength(x)) - 1)

  /**
    * Returns a number of digits for the left most zero
    * 01101 -> 2
    * 10    -> 1
    */
  def asd(n: Int): Int =  {
    def helper(m: Int, acc: Int): Int = {
      if(m == 0) acc
      else helper(m >> 1, acc + 1)
    }
    helper(inversion(n), 0)
  }

  def iterate(x: Int, cnt: Int, acc: List[Int]): (Int, List[Int]) = {
    if (x + 1 == (1 << binLength(x))) (cnt - 1, acc)
    else if (cnt % 2 == 1) {
      val n = asd(x)
      //    println(s"n -> $n")
      iterate(x ^ ((1 << n) - 1), cnt + 1, n::acc)
    } else {
      //    println("Add 1")
      iterate(x + 1, cnt + 1, acc)
    }
  }

  val n = readInt()

  if (n + 1 == (1 << binLength(n))) {
    println(0)
  } else {
    val (cnt, acc) = iterate(n, 1, List())
    println(cnt)
    println(acc.reverse.mkString(" "))
  }

}


import scala.Array._

object A523 extends App{

  def readInp = {
    val arr = ofDim[String](h)
    (0 until h).foreach(i => arr(i) = readLine)
    arr
  }

  def output(arr : Array[String]): Unit = {
    var line : Array[Char] = new Array[Char](h * 2)
    var result = ""
    for(i <- 0 until w) {
      for (j <- 0 until h) {
        line(2 * j) = arr(j)(i)
        line(2 * j + 1) = arr(j)(i)
      }
      var ln = line.mkString("")
      result += ln + "\n" + ln + "\n"
    }

    print(result)
  }
  val (w, h) = {val str = readLine.split(" ").map(_.toInt); (str(0), str(1))}
  val arr = readInp
  output(arr)
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(w, h) = in.next().split(" ").map(_.toInt)
  val image = (1 to h).map(_ => in.next())
  println((0 until w).flatMap{
    i => val s = image.map(t => "" + t(i) + t(i)).mkString
      List(s, s)
  }.mkString("\n"))
}

object Main extends App {
 val Array(w, h) = readLine.split(" ").map(_.toInt)
 //val (w,h) = (3,2)
 var img_row:Array[Array[_ >: Image]] = Array()
 (1 to h).foreach { h =>
     var row: Array[_ >: Image] = Array()
     //Array(".*.").head
       var line = readLine
       line.toCharArray.foreach(ch => ch.toString match {
       case "." => row = row :+ Dot()
       case "*" => row = row :+ Star()
       case _ =>
     })
     img_row = img_row :+ row
 }

 def rotate(img_rws: Array[Array[_ >: Image]]) {
   val rows:List[List[Image]] = img_rws.map(c => c.toList.asInstanceOf[List[Image]]).toList
   val z = rows.reverse.transpose // ROTATE

  z.map(re => re.map(ze => Array(ze,ze) ).flatten).foreach { fin =>
       fin.reverse.foreach { result =>
                      if (result.getClass.getName == "Dot")   { print(".") }
                      if (result.getClass.getName == "Star") { print("*") }

                    }

       println()
         fin.reverse.foreach { result =>
                      if (result.getClass.getName == "Dot")   { print(".") }
                      if (result.getClass.getName == "Star") { print("*") }

                    }
println()
  }

 }
 rotate(img_row)

}
trait Image {}
case class Dot() extends Image
case class Star() extends Image

import scala.Array._

object A523 extends App{

  def readInp = {
    val arr = ofDim[Char](h, w)
    (0 until h).foreach(i => arr(i) = readLine.toCharArray)
    arr
  }

  def rotate(arr : Array[Array[Char]]) = {
    val buf = ofDim[Char](w, h)
    for(i <- 0 until w)
      for(j <- 0 until h)
        buf(i)(j) = arr(h - j - 1)(i)
    buf
  }

  def mirror(arr : Array[Array[Char]]) = {
    val buf = ofDim[Char](w, h)
    for(i <- 0 until w)
      for(j <- 0 until h)
        buf(i)(j) = arr(i)(h - j - 1)
    buf
  }

  def output(arr : Array[Array[Char]]): Unit = {
    var line : Array[Char] = new Array[Char](h * 2)
    for(i <- 0 until arr.length) {
      for (j <- 0 until arr(0).length) {
        line(2 * j) = arr(i)(j)
        line(2 * j + 1) = arr(i)(j)
      }
      val ln = line.mkString("")
      println(ln + "\n" + ln)
    }
  }
  val (w, h) = {val str = readLine.split(" ").map(_.toInt); (str(0), str(1))}
  val arr = readInp
  output(mirror(rotate(arr)))
}

import scala.Array._

object A523 extends App{

  def readInp = {
    val arr = ofDim[Char](h, w)
    (0 until h).foreach(i => arr(i) = readLine.toCharArray)
    arr
  }

  def output(arr : Array[Array[Char]]): Unit = {
    var line : Array[Char] = new Array[Char](h * 2)
    for(i <- 0 until arr(0).length) {
      for (j <- 0 until arr.length) {
        line(2 * j) = arr(j)(i)
        line(2 * j + 1) = arr(j)(i)
      }
      val ln = line.mkString("")
      println(ln + "\n" + ln)
    }
  }
  val (w, h) = {val str = readLine.split(" ").map(_.toInt); (str(0), str(1))}
  val arr = readInp
  output(arr)
}

import scala.Array._

object A523 extends App{

  def readInp = {
    val arr = ofDim[Char](h, w)
    (0 until h).foreach(i => arr(i) = readLine.toCharArray)
    arr
  }

  def rotate(arr : Array[Array[Char]]) = {
    val buf = ofDim[Char](w, h)
    for(i <- 0 until w)
      for(j <- 0 until h)
        buf(i)(j) = arr(h - j - 1)(i)
    buf
  }

  def mirror(arr : Array[Array[Char]]) = {
    val buf = ofDim[Char](w, h)
    for(i <- 0 until w)
      for(j <- 0 until h)
        buf(i)(j) = arr(i)(h - j - 1)
    buf
  }

  def output(arr : Array[Array[Char]]): Unit = {
    var line = ""
    for(i <- 0 until arr.length) {
      for (j <- 0 until arr(0).length)
        line += arr(i)(j).toString + arr(i)(j).toString
      println(line)
      println(line)
      line = ""
    }
  }
  val (w, h) = {val str = readLine.split(" ").map(_.toInt); (str(0), str(1))}
  val arr = readInp
  output(mirror(rotate(arr)))
}

import scala.Array._

object A523 extends App{

  def readInp = {
    val arr = ofDim[String](h)
    (0 until h).foreach(i => arr(i) = readLine)
    arr
  }

  def output(arr : Array[String]): Unit = {
    var line : Array[Char] = new Array[Char](h * 2)
    for(i <- 0 until w) {
      for (j <- 0 until h) {
        line(2 * j) = arr(j)(i)
        line(2 * j + 1) = arr(j)(i)
      }
      val ln = line.mkString("")
      println(ln + "\n" + ln)
    }
  }
  val (w, h) = {val str = readLine.split(" ").map(_.toInt); (str(0), str(1))}
  val arr = readInp
  output(arr)
}

object Main extends App {
 val Array(w, h) = readLine.split(" ").map(_.toInt)
 //val (w,h) = (3,2)
 var img_row:Array[Array[_ >: Image]] = Array()
 (1 to h).foreach { h =>
     var row: Array[_ >: Image] = Array()
     //Array(".*.").head
       var line = readLine
       line.toCharArray.foreach(ch => ch.toString match {
       case "." => row = row :+ Dot()
       case "*" => row = row :+ Star()
       case _ =>
     })
     img_row = img_row :+ row
 }

 def rotate(img_rws: Array[Array[_ >: Image]]) {
   val rows:List[List[Image]] = img_rws.map(c => c.toList.asInstanceOf[List[Image]]).toList
   val z = rows.reverse.transpose // ROTATE

  z.map(re => re.map(ze => Array(ze,ze) ).flatten).foreach { fin =>
       fin.foreach { result =>
                      if (result.getClass.getName == "Dot")   { print(".") }
                      if (result.getClass.getName == "Star") { print("*") }
                    }
       println()
  }

 }
 rotate(img_row)

}
trait Image {}
case class Dot() extends Image
case class Star() extends Image

object Main extends App {
 val Array(w, h) = readLine.split(" ").map(_.toInt)
 //val (w,h) = (3,2)
 var img_row:Array[Array[_ >: Image]] = Array()
 (1 to h).foreach { h =>
     var row: Array[_ >: Image] = Array()
     //Array(".*.").head
       var line = readLine
       line.toCharArray.foreach(ch => ch.toString match {
       case "." => row = row :+ Dot()
       case "*" => row = row :+ Star()
       case _ =>
     })
     img_row = img_row :+ row
 }

 //val x = readLine.split(" ").map(_.toLong)
 //def roundUp(x: Long) = x / a + (if (x % a > 0) 1 else 0)
 //println(roundUp(n) * roundUp(m))
 //img_row.foreach(r => println(r.foreach(print(_))))
 def rotate(img_rws: Array[Array[_ >: Image]]) {
   val rows:List[List[Image]] = img_rws.map(c => c.toList.asInstanceOf[List[Image]]).toList
   val z = rows.reverse.transpose
     var finalize:Array[Array[Image]] = Array()
     z.foreach(r => {
     r.reverse.foreach { obj =>
       finalize = finalize :+ Array(obj,obj, obj,obj)
     }
   }
  )
  finalize.foreach(c => println(c.foreach { cc =>
     if (cc.getClass.getName == "Dot") {
       print(".")
     }
     else { print("*") }
       }
                               ))
 }
 rotate(img_row)

}
trait Image {}
case class Dot() extends Image
case class Star() extends Image


import scala.io.StdIn._

object main{
    def main(args: Array[String]): Unit = {
        val t = readInt()
        for (_ <- 0 until t) {
            val s: String = readLine().map(_.toUpper)
            if (s == "YES") {
                println("YES")
            } else {
                println("NO")
            }
        }

    }
}

import scala.io.StdIn._

object Main extends App{
    val t=readInt()
    for(i<- 1 to t){
        if((readLine().toLowerCase()=="yes"))
        println("YES")
        else println("NO")
    }
}

import scala.io.StdIn._

object main{
    def main(args: Array[String]): Unit = {
        val t = readInt()
        for (_ <- 0 until t) {
            val s: String = readLine().map(_.toUpper)
            if (s == "YES") {
                print("YES")
            } else {
                print("NO")
            }
        }

    }
}