//package round111.div2

/**
 * Created by IntelliJ IDEA.
 * User: User
 * Date: 08.03.12
 * Time: 6:11
 * To change this template use File | Settings | File Templates.
 */

object A {
  readLine()
  val a = readLine() split ' ' map (_ toInt) sortBy (-_)
  var s = -a.sum / 2
  val b = for (coin <- a.iterator takeWhile (_ => s <= 0)) yield {
    s += coin
    coin
  }

  def main(args: Array[String]) = println(b.size)

}

import java.util.Scanner

import scala.io.StdIn._
import scala.util.Sorting

object HelloWorldMain {

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

    val sc = new Scanner(System.in)

    val n = sc.nextInt()

    var list = new Array[Int](n)

    var sum = 0
    for(i <- 0 until  n ) {
      list(i) = sc.nextInt()
      sum += list(i)
    }

    Sorting.quickSort(list)

    var takenAmount = 0
    var iterator = n-1
    var totalnumberOfCoins = 0
    while (takenAmount <= sum/2 ){
      takenAmount += list(iterator)
      totalnumberOfCoins += 1
      iterator -=1
    }

    println(totalnumberOfCoins)

  }
}

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

object Twins {

  def main(args: Array[String]) {
    val n = readInt
    val coins = readLine.split(' ').map(_.toInt).sorted.reverse
    val toTake = coins.sum/2 + 1
    println(coins.scanLeft(0)(_ + _)
      .zipWithIndex.find{ case (s,i) => s >= toTake}.getOrElse( (0,0))._2)
  }

}

import java.util.Scanner

/**
  * Created by dr0ff on 02/03/16.
  */
object Twins {

  def main(args: Array[String]): Unit = {
    val in = new Scanner(System.in)

    val num = in.nextLine().trim.toInt
    val coins = in.nextLine().trim.split(" ").map(_.toInt)
    print(minHalfNum(coins))
  }

  def minHalfNum(coins: Array[Int]): Int = {
    val half = coins.sum / 2.0
    def loop(coins: List[Int], num: Int, total: Long): Int =
      if (total > half)
        num
      else
        coins match {
          case c :: cs => loop(cs, num + 1, total + c)
          case Nil => num
        }

    loop(coins.sorted(Ordering[Int].reverse).toList, 0, 0)
  }
}

import scala.io.StdIn._

object Task extends App{
	val N = readLine.split(" ").map{_.toInt}.head
	val coins = readLine.split(" ").map{_.toInt}.sorted.reverse

	val leftSums = coins.scanLeft(0)((a,b) => a + b).tail
	val rightSums = coins.scanRight(0)((a,b) => a + b).tail

	//println(leftSums.mkString)
	//println(rightSums.mkString)

	val a = leftSums.zip(rightSums).filter{case (l,r) => l <= r}
	//println(a.mkString)

	println(a.size + 1)
}

import java.util.Scanner
import scala.collection.mutable.ListBuffer

object Main {
  def main(args: Array[String]) {
    val sc = new Scanner(System.in)
    val n = sc.nextInt
    val xs = new ListBuffer[Int]
    for (i <- 1 to n) {
      xs += sc.nextInt
    }
    val ys = xs.sortWith(_ > _).toList
    var sumA = 0
    var sumB = ys.sum
    var flag = false
    var index = ys.size
    for (i <- 0 until ys.size) {
      if (!flag) {
        if (sumA <= sumB) {
          sumA += ys(i)
          sumB -= ys(i)
        } else {
          index = i
          flag = true
        }
      }
    }
    println(index)
  }
}

import java.util.Scanner
import scala.util.control.Breaks._

import sun.swing.SwingUtilities2.RepaintListener

object Main {
  def main(args: Array[String]): Unit = {

    val s = new Scanner(System.in)
    val a = s.nextInt()
    val numbers: Array[Int] = Array.fill(a) {
      0
    }
    for (i <- 0 until a){
      numbers(i) = s.nextInt()
    }

    val list = numbers.toList.sorted

    val rev = list.reverse

    val llist = list.scanLeft(0)(_+_)

    val lllist = llist.reverse

    val rlist = rev.scanLeft(0)(_+_)

    def Index(al:(List[Int],List[Int])): Int =
      al match {
        case (Nil, Nil) => 999999
        case (xs :: xss, ys :: yss) => if (xs > ys) xs else Index((xss, yss))
      }

    println(rlist.indexOf( Index( (rlist,lllist)) ))

//    def minIndex(x: List[Int], y:List[Int]): List[Int] = {
//      var sol = List()
//      for(i <- 0 until a) {
//        if (x(i) > y(i)) {i :: sol} else sol
//      }
//    }

//    println(minIndex(rlist, lllist))
//
//    println(list)
//    println(rlist)
//    println(lllist)
//
//    println(rev)
//
  }
}

object One60A extends App {
	import java.io.{ PrintWriter => Out }
	import java.util.{ Scanner => In }
	import scala.util.control.Breaks._

	val in = new In(System.in)
	val out = new Out(System.out)
	val n = in.nextInt()
	var arr = new Array[Int](n)
	var left = 0
	var has = 0

	(0 until n).foreach { i =>
		arr(i) = in.nextInt()
		left += arr(i)
	}
	arr = arr.sortWith(_ > _)

	var buff = arr.takeWhile { x =>
		has += x
		left -= x
		has <= left
	}
	out.println(buff.size + 1)
	out.close
}

object Twins {
  def main(args: Array[String]): Unit = {
    readInt()
    val nums = readLine().split(" ").map(_.toInt).sorted
    var sum: Long = nums.sum
    var mySum: Long = 0
    var coinsCount = 0
    for (i <- nums.reverse) {
      if (mySum <= sum) coinsCount += 1
      mySum += i
      sum -= i
    }
    println(coinsCount)
  }
}

object CF0160A extends App {

  val n = readInt()
  val a = readLine().split(" ").map(_.toInt).toList.sorted.reverse

  var sum = a.sum

  var minSum = 0
  var min = 0

  a.foreach(n => {
    if (minSum <= sum) {
      minSum += n
      sum -= n
      min += 1
    }
  })
  println(min)

}

import scala.io.StdIn
import scala.util.Sorting

object Task {

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

    val n: Int = StdIn.readInt()
    var a: Array[Int] = StdIn.readLine().split(" ").map(_.toInt)
    println(solve(a))

  }

  private def solve(a: Array[Int]): Int = {
    Sorting.quickSort(a)
    var sum: Int = 0
    for (x <- a) {
      sum += x
    }
    var sol: Int = 0
    var currSum: Int = 0
    for (i <- a.length - 1 to 0 by -1) {
      sol += 1
      currSum += a(i)
      if (currSum > sum / 2) {
        return sol
      }
    }
    return -1
  }

}

object Solution160A extends App {

  def solution() {
    val n = _int
    val coins = 1.to(n).map(_ => _int).sortBy(-_)
    val sum = coins.foldLeft(0)((s, c) => s + c)
    val result = coins.foldLeft((0, 0))((memo, c) => memo._1 match {
      case l if l <= (sum - l) => (memo._1 + c, memo._2 + 1)
      case _ => memo
    })
    println(result._2)
  }

  //////////////////////////////////////////////////
  import java.util.Scanner
  val SC: Scanner = new Scanner(System.in)
  def _line: String = SC.nextLine
  def _int: Int = SC.nextInt
  def _long: Long = SC.nextLong
  def _string: String = SC.next
  solution()
}

object Competition extends App {

  import scala.io.StdIn._

  val k: Int = readInt()

  val coins: Seq[Int] = readLine().split(" ").map(Integer.parseInt).toSeq.sorted.reverse
  val amount: Int = coins.sum / 2

  def sumUp(half: Int, sum: Int, num: Int, coinsLeft: Seq[Int]): Int = {
    if (sum > half) num
    else sumUp(half, sum + coinsLeft.head, num + 1, coinsLeft.tail)
  }

  println(sumUp(amount, 0, 0, coins))
}

import scala.collection.mutable._
import scala.math._
import scala.util._
import scala.util.control.Breaks.break
import scala.util.control.Breaks.breakable
import java.util._
object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val tt = for(i <- 1 to n) yield sc.nextInt
  val t = Sorting.stableSort(tt).reverse
  val sum = t.foldLeft(0){_+_}
  var tmp = 0
  var res = -1
  for(i <- 0 until n) {
    tmp += t(i)
    if(res == -1 && tmp > (sum-tmp)) res = i+1
  }
  println(res)
}

import scala.io.StdIn

object Twins_160 {
  def main(args: Array[String]): Unit = {
    val numOfCoins = StdIn.readInt()
    val coins = StdIn.readLine().split(" ").map(_.toInt)

    val coinsSorted = coins.sorted
    println(getMinCoins(0, coins.sum, coins.sorted(Ordering[Int].reverse), 0))
  }

  def getMinCoins(mySum: Int, twinSum: Int, coins: Array[Int], numOfCoins: Int): Int = {
    if (mySum > twinSum) return numOfCoins
    getMinCoins(mySum + coins.head, twinSum - coins.head, coins.tail, numOfCoins + 1)
  }

}

import scala.io.StdIn.readLine

/**
  * @author traff
  */

object Main extends App {
  val n = readLine().toInt

  val a = readLine().split("\\s+").map(_.toInt).sortWith(_ > _)

  val sum = a.sum

  println(a.scanLeft(0)(_ + _).takeWhile(c => c <= sum - c).length)
}

import scala.io.StdIn.readLine

/**
  * @author traff
  */

object Main extends App {
  val n = readLine().toInt

  val a = readLine().split("\\s+").map(_.toInt).sortWith(_ > _)

  val sum = a.sum

  var i = 0
  var s1 = 0
  while (i<n && s1<= sum - s1) {
    s1 += a(i)
    i+=1
  }

  println (i)

}

object Solution extends App{
  val in = scala.io.Source.stdin.getLines()
  in.next()
  val a = in.next().split(" ").map(_.toInt).sorted.reverse
  val sum = a.sum
  var i = 0
  var count = 0
  while (i < a.length && sum - (count + a(i)) >= count + a(i)) {
    count = count + a(i)
    i += 1
  }
  println(i + 1)
}

object Main {

  def main(args: Array[String]) {
    val std = scala.io.StdIn

    val n = std.readLine().toInt
    val values = std.readLine().split(' ').map(_.toInt)

    val halfSum = values.sum / 2
    val result = values.sorted.foldRight((0,0))((y,x) => if (x._2 <= halfSum) (x._1 + 1, x._2 + y) else x)
    print(result._1)

  }
}

/**
 * Created by richard on 2015/6/9.
 */
import scala.io.StdIn
object cf160a {
  def main(args: Array[String]): Unit = {
    val n = StdIn.readInt()
    val c = StdIn.readLine().split(" ").map(_.toInt).toSeq.sortWith(_>_)
    var sum = c.sum
    var msum = 0
    println(c.takeWhile( i=>{sum-=i; msum+=i; msum-i<=sum+i}).length)
  }
}

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

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

  val N = sc.nextInt

  def solve: Int = {
    val coins = List.fill(N)(sc.nextInt)
    val half = coins.sum / 2

    @tailrec
    def loop(acc: Int, cs: List[Int], num: Int): Int =
      if (acc > half) num
      else loop(acc + cs.head, cs.tail, num + 1)
    loop(0, coins.sortBy(identity[Int]).reverse, 0)
  }

  out.println(solve)
  out.close
}

object Twins {
	def main (args: Array[String]) {
		val scanner = new java.util.Scanner(System.in)
				val _ = scanner.nextLine
				val input = scanner.nextLine
				var sequence = input.split(" ").map(s => s.toInt)
				sequence = sequence.sortWith(_ > _)
				val sum = sequence.foldLeft(0){
			(acc, num) => acc + num
		}
		var tmpSum = 0
				var number = 0
				while (tmpSum <= sum / 2) {
					val elt = sequence(number)
							number += 1
							tmpSum += elt
				}
		println(number)
	}
}

object Codeforces160A extends App{

  def DivideCoins(coinnumber:Int):Int={
    var coinarray:Array[Int]=scala.io.StdIn.readLine.split(" ").map(_.toInt)
    coinarray=coinarray.sorted
    for (i <- 0 until coinnumber){
      val (tempa,tempb)=coinarray.splitAt(coinnumber-i-1)
      if (tempa.sum < tempb.sum) return i+1
    }
    return coinnumber
  }
  val numberofcoin:Int=scala.io.StdIn.readInt
  println(DivideCoins(numberofcoin))

}

import java.io._

object Main {

  def main(args: Array[String]) {
    val n = readInt
    val list = (for(i <- 0 until n) yield readInt).sortWith(_ > _)
    val sum = (0 /: list)(_ + _)
    def getCnt(i: Int,  amount: Int) : Int = if(amount < 0) i else getCnt(i + 1, amount - list(i))
    println(getCnt(0, sum / 2))
  }

  val in = new StreamTokenizer(new InputStreamReader(System.in))

  def readInt = {
    in.nextToken()
    in.nval.asInstanceOf[Int]
  }
}

object Main {
  import java.io.{InputStreamReader, StreamTokenizer}

  def main(args: Array[String]) {
    val n = readInt
    val list = (for(i <- 0 until n) yield readInt).sortWith(_ > _)
    val sum = (0 /: list)(_ + _)
    def getCnt(i: Int,  amount: Int) : Int = if(amount < 0) i else getCnt(i + 1, amount - list(i))
    println(getCnt(0, sum / 2))
  }

  val in = new StreamTokenizer(new InputStreamReader(System.in))

  def readInt = {
    in.nextToken()
    in.nval.asInstanceOf[Int]
  }
}

object A extends App {
  val n = readLine
  val c = readLine.split(" ").map(_.toInt).toSeq.sortWith(_>_)
  var sum = c.sum
  var tsum = 0
  println (c.takeWhile( i => { sum -= i; tsum += i; tsum-i <= sum+i }).length)
}

object Main {
  def main(args: Array[String]) {
    val n = readInt
    val a = readLine().split(" ").map(_.toInt)
    val sum = a.sum / 2
    val sorted = a.sortWith(_ > _)
    val res = sorted.foldLeft((0, 0)) { (t, e) =>
      if (t._1 > sum) t
      else (t._1 + e, t._2 + 1)
    }
    println(res._2)
  }
}

import scala.io.StdIn._

object _160_A extends App {
  readInt()
  val coins = readLine().split(" ").map(_.toInt).sortWith(_ > _)

  var rest = coins.sum
  var current = 0
  var i = 0

  while (current <= rest) {
    current += coins(i)
    rest -= coins(i)
    i+=1
  }

  println(i)
}

import scala.io.StdIn.readLine
object problem {
  def main(args: Array[String]) {
  val n = readLine.toInt
    val A = readLine.split(' ').map(_.toInt).sortWith(_ > _)
    var s = A.sum
    var t = 0
    var cnt = 0
   while(s >= t){
     s = s - A(cnt)
     t = t + A(cnt)
     cnt = cnt + 1
   }
    println(cnt)
  }
}

import java.util.Scanner
import scala.util.control.Breaks._

import sun.swing.SwingUtilities2.RepaintListener

object Main {
  def main(args: Array[String]): Unit = {

    val s = new Scanner(System.in)
    val a = s.nextInt()
    val numbers: Array[Int] = Array.fill(a) {
      0
    }
    for (i <- 0 until a){
      numbers(i) = s.nextInt()
    }

    val list = numbers.toList.sorted

    val rev = list.reverse

    val llist = list.scanLeft(0)(_+_)

    val lllist = llist.reverse

    val rlist = rev.scanLeft(0)(_+_)

//
    val uno = lllist.zip(rlist).filter{case (l,r) => l <= r}
    println(uno.length)

  }
}

import java.util.Scanner
import scala.util.control.Breaks._

import sun.swing.SwingUtilities2.RepaintListener

object Main {
  def main(args: Array[String]): Unit = {

    val s = new Scanner(System.in)
    val a = s.nextInt()
    val numbers: Array[Int] = Array.fill(a) {
      0
    }
    for (i <- 0 until a){
      numbers(i) = s.nextInt()
    }

    val list = numbers.toList.sorted

    val rev = list.reverse

    val llist = list.scanLeft(0)(_+_)

    val lllist = llist.reverse

    val rlist = rev.scanLeft(0)(_+_)

    val uno = lllist.zip(rlist).filter{case (l,r) => l <= r}
    println(uno)

  }
}

object One60A extends App {
        import java.io.{ PrintWriter => Out }
        import java.util.{ Scanner => In }
        import scala.util.control.Breaks._

	val in = new In(System.in)
	val out = new Out(System.out)
	val n = in.nextInt()
	var arr = new Array[Int](n)
	var left = 0
	var has = 0

	(0 until n).foreach { i =>
		arr(i) = in.nextInt()
		left += arr(i)
	}
	arr = arr.sortWith(_ > _)

	var buff = arr.takeWhile { x =>
		has += x
		left -= x
		has < left
	}
	out.println(buff.size + 1)
	out.close
}

object One60A extends App {
        import java.io.{ PrintWriter => Out }
        import java.util.{ Scanner => In }
        import scala.util.control.Breaks._

	val in = new In(System.in)
	val out = new Out(System.out)
	val n = in.nextInt()
	var arr = new Array[Int](n)
	var left = 0
	var has = 0

	(0 until n).foreach { i =>
		arr(i) = in.nextInt()
		left += arr(i)
	}
	arr = arr.sortWith(_ > _)

	var buff = arr.takeWhile { x =>
		has += x
		has < left
	}
	out.println(buff.size + 1)
	out.close
}

object CF0160A extends App {

  val n = readInt()
  val a = readLine().split(" ").map(_.toInt).toList.sorted

  var sum = a.sum

  var minSum = 0
  var min = 0

  a.foreach(n => {
    if (minSum <= sum) {
      minSum += n
      sum -= n
      min += 1
    }
  })
  println(min)

}

//package round111.div2

/**
 * Created by IntelliJ IDEA.
 * User: User
 * Date: 08.03.12
 * Time: 6:11
 * To change this template use File | Settings | File Templates.
 */

object A {
  readLine()
  val a = readLine() split ' ' map (_ toInt) sorted
  var s = -a.sum / 2
  val b = for (coin <- a.iterator takeWhile (_ => s <= 0)) yield {
    s += coin
    coin
  }

  def main(args: Array[String]) = println(b.size)

}

object Solution extends App{
  val in = scala.io.Source.stdin.getLines()
  in.next()
  val a = in.next().split(" ").map(_.toInt).sorted.reverse
  val sum = a.sum
  var i = 0
  var count = 0
  while (i < a.size && count + a(i) > a.sum / 2) i += 1
  println(i)
}

object Solution extends App{
  val in = scala.io.Source.stdin.getLines()
  in.next()
  val a = in.next().split(" ").map(_.toInt).sorted.reverse
  val sum = a.sum
  var i = 0
  var count = 0
  while (i < a.length && count + a(i) <= sum / 2) i += 1
  println(i)
}

/**
 * Created by richard on 2015/6/9.
 */
import scala.io.StdIn
object cf160a {
  def main(args: Array[String]): Unit = {
    val n = StdIn.readInt()
    val c = StdIn.readLine().split(" ").map(_.toInt).sortWith(_>_)
    var sum = c.sum
    var msum = 0
    println(c.takeWhile( i=>{sum-=i; msum+=i; msum-i<sum+i}).length)
  }
}

import java.io._

object Main {

  def main(args: Array[String]) {
    val n = readInt
    val list = for(i <- 0 until n) yield readInt
    list.sortWith(_ > _)
    val sum = (0 /: list)(_ + _)
    def getCnt(i: Int,  amount: Int) : Int = if(amount < 0) i else getCnt(i + 1, amount - list(i))
    println(getCnt(0, sum / 2))
  }

  val in = new StreamTokenizer(new InputStreamReader(System.in))

  def readInt = {
    in.nextToken()
    in.nval.asInstanceOf[Int]
  }
}

import scala.io.StdIn._

object _160_A extends App {
  readInt()
  val coins = readLine().split(" ").map(_.toInt).sortWith(_ > _)
  println(coins.mkString(" "))

  var rest = coins.sum
  var current = 0
  var i = 0

  while (current <= rest) {
    current += coins(i)
    rest -= coins(i)
    i+=1
  }

  println(i)
}

import java.util.Scanner

import scala.io.StdIn._
import scala.util.Sorting

object HelloWorldMain {

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

    val sc = new Scanner(System.in)

    val n = sc.nextInt()

    var list = new Array[Int](n)

    var sum = 0
    for(i <- 0 until  n ) {
      list(i) = sc.nextInt()
      sum += list(i)
    }

    Sorting.quickSort(list)

    var takenAmount = 0
    var iterator = n-1
    var totalnumberOfCoins = 0
    while (takenAmount <= sum/2 ){
      takenAmount += list(iterator)
      totalnumberOfCoins += 1
    }

    println(totalnumberOfCoins)

  }
}

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

object Twins {

  def main(args: Array[String]) {
    val n = readInt
    val coins = readLine.split(' ').map(_.toInt).sorted
    val toTake = coins.sum/2 + 1
    println(coins.scanLeft(0)(_ + _)
      .zipWithIndex.find{ case (s,i) => s >= toTake}.getOrElse( (0,0))._2)
  }

}

import scala.io.StdIn._

object Task extends App{
	val N = readLine.split(" ").map{_.toInt}.head
	val coins = readLine.split(" ").map{_.toInt}.sorted

	val leftSums = coins.scanLeft(0)((a,b) => a + b).tail
	val rightSums = coins.scanRight(0)((a,b) => a + b).tail

	//println(leftSums.mkString)
	//println(rightSums.mkString)

	val a = leftSums.zip(rightSums).filter{case (l,r) => l <= r}
	//println(a.mkString)

	println(a.size + 1)
}


object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  var Array(x1, y1, x2, y2) = in.next().split(" ").map(_.toInt)
  if (x2 < x1 || (x2 == x2 && y2 < y1)) {
    val tmp = x2
    x2 = x1
    x1 = tmp
    val tmp2 = y2
    y2 = y1
    y1 = tmp2
  }

  val width = Math.max(Math.abs(x1 - x2), Math.abs(y1 - y2))
  if (Math.abs(x1 - x2) != 0 && Math.abs(y1 - y2) != 0 && Math.abs(x1 - x2) != Math.abs(y1 - y2))
    println(-1)
  else if (x1 == x2)
    println(List(x1 + width, y1, x2 + width, y2).mkString(" "))
  else if (y1 == y2)
    println(List(x1, y1 + width, x2, y2 + width).mkString(" "))
  else
    println(List(x1, y2, x2, y1).mkString(" "))
}

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

/**
 * Created by arseny on 15.08.14.
 */
object A extends App {

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

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

  def solve() = {
    val x1 = nextInt
    val y1 = nextInt
    val x2 = nextInt
    val y2 = nextInt
    if(x1 == x2) {
      val x3 = x1 + math.abs(y2 - y1)
      out.print(Array(x3, y1, x3, y2).mkString(" "))
    } else if(y1 == y2) {
      val y3 = y1 + math.abs(x2 - x1)
      out.print(Array(x1, y3, x2, y3).mkString(" "))
    } else {
      val x = math.abs(x2 - x1)
      val y = math.abs(y2 - y1)
      if(x != y) {
        out.print(-1)
      } else {
        if((x2 - x1) * (y2 - y1) > 0) {
          out.print(Array(math.min(x1, x2), math.max(y1, y2), math.max(x1, x2), math.min(y1, y2)).mkString(" "))
        } else {
          out.print(Array(math.min(x1, x2), math.min(y1, y2), math.max(x1, x2), math.max(y1, y2)).mkString(" "))
        }
      }
    }
  }

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

import java.util.StringTokenizer

object _459A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val x1 = next.toInt
  val y1 = next.toInt
  val x2 = next.toInt
  val y2 = next.toInt
  if (x1 == x2) {
    val len = (y1 - y2).abs
    println("%d %d %d %d".format(x1 - len, y1, x1 - len, y2))
  } else if (y1 == y2) {
    val len = (x1 - x2).abs
    println("%d %d %d %d".format(x1, y1 - len, x2, y1 - len));
  } else {
    if ((x1 - x2).abs != (y1 - y2).abs) println(-1)
    else {
      val len = (x1 - x2).abs
      println("%d %d %d %d".format(x1, y2, x2, y1));
    }
  }
}

/**
 * Created by lurker on 2014. 8. 15..
 */
object CF261_1 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(x1, y1, x2, y2) = readInts(4)

  val minx = x1 min x2
  val maxx = x1 max x2
  val miny = y1 min y2
  val maxy = y1 max y2

  if (minx == maxx) {
    val dist = maxy - miny
    val Array(x3, y3, x4, y4) = Array(minx + dist, miny, minx + dist, maxy)
    println(s"${x3} ${y3} ${x4} ${y4}")
  } else if (miny == maxy) {
    val dist = maxx - minx
    val Array(x3, y3, x4, y4) = Array(minx, miny + dist, maxx, miny + dist)
    println(s"${x3} ${y3} ${x4} ${y4}")
  } else {
    if (maxx - minx != maxy - miny) {
      println("-1")
    } else {
      val Array(x3, y3, x4, y4) = Array(x1, y2, x2, y1)
      println(s"${x3} ${y3} ${x4} ${y4}")
    }
  }
}

object A459 {
  @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(x1, y1, x2, y2) = readInts(4)
    if(x1 == x2) {
      if(y1 != y2) {
        println(s"${x1 + math.abs(y2 - y1)} $y2 ${x1 + math.abs(y2 - y1)} $y1")
      } else {
        println("-1")
      }
    } else if(y1 == y2) {
      if(x1 != x2) {
        println(s"$x2 ${y1 + math.abs(x2 - x1)} $x1 ${y1 + math.abs(x2 - x1)}")
      } else {
        println("-1")
      }
    } else {
      if(math.abs(x1-x2) == math.abs(y1-y2)) {
        println(s"$x1 $y2 $x2 $y1")
      } else {
        println("-1")
      }
    }
  }
}

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

object A {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

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

  def nextLong: Long = {
    return java.lang.Long.parseLong(next)
  }

  def solve: Int = {
    val x1 = nextInt
    val y1 = nextInt
    val x2 = nextInt
    val y2 = nextInt
    if (x1 != x2 && y1 != y2) {
      if (Math.abs(x1 - x2) != Math.abs(y1 - y2)) {
        out.println(-1)
      } else {
        out.print(x1 + " " + y2 + " " + x2 + " " + y1)
      }
    } else if (x1 == x2) {
      val d = Math.abs(y1 - y2)
      out.print((x1 + d) + " " + y1 + " " + (x1 + d) + " " + y2)
    } else if (y1 == y2) {
      val d = Math.abs(x1 - x2)
      out.print(x1 + " " + (y1 + d) + " " + x2 + " " + (y1 + d))
    }
    return 1
  }

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }
}

import java.util.Scanner

/**
 * Created by Kuang.Ru on 14-9-19.
 */
object A459 extends App{
  val sc = new Scanner(System.in)
  val x1, y1, x2, y2 = sc.nextInt()

  if (x1 == x2) {
    println((x1 + math.abs(y2 - y1)) + " " + y1 + " " + (x1 + math.abs(y2 - y1)) + " " + y2)
  } else if (y1 == y2){
    println(x1 + " " + (y1 + math.abs(x2 - x1)) + " " + x2 + " " + (y1 + math.abs(x2 - x1)))
  } else if (math.abs((x2 - x1) / (y2 - y1).toDouble) == 1) {
    println(x1 + " " + y2 + " " + x2 + " " + y1)
  } else {
    println(-1)
  }
}

object Main {

  def main(args: Array[String]): Unit = {
    println(findCoords(io.StdIn.readLine().split(' ').map(x => Integer.parseInt(x))))
  }

  def findCoords(points: Array[Int]): String = {
    if (points(0) == points(2)) {
      val side = points(3) - points(1)
      List(points(0) + side, points(1), points(2) + side, points(3)).mkString(" ")
    }
    else if (points(1) == points(3)) {
      val side = points(2) - points(0)
      List(points(0), points(1) + side, points(2), points(3) + side).mkString(" ")
    }
    else {
      val h = points(2) - points(0)
      val v = points(3) - points(1)
      if (Math.abs(h) - Math.abs(v) != 0) {
        return -1 + ""
      } else {
        List(points(0) + h, points(1), points(0), points(1) + v).mkString(" ")
      }
    }
  }

}

object main extends App with fastIO {

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

  var p1 = Point(nextInt, nextInt)
  var p2 = Point(nextInt, nextInt)
  var length = (p1.x - p2.x + p1.y - p2.y).abs

  var p3 = Point(0, 0)
  var p4 = Point(0, 0)

  var f = true
  if ((p1.x - p2.x).abs == (p1.y - p2.y).abs) { p3 = Point(p1.x, p2.y); p4 =  Point(p2.x, p1.y) }
  else if (p1.x == p2.x) { p3 = Point(p1.x + length, p1.y); p4 =  Point(p1.x + length, p2.y) }
  else if (p1.y == p2.y) { p3 = Point(p1.x, p1.y + length); p4 =  Point(p2.x, p1.y + length) }
  else f = false

  if (!f) println(-1) else
    println("%d %d %d %d" format (p3.x, p3.y, p4.x, p4.y))
  flush
}

trait fastIO {
  import java.io._

  val isFile = false
  val input = "io.in"
  val output = "io.out"

  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))
  val in = new StreamTokenizer(bf)
  val out = new PrintWriter(if(isFile) new FileWriter(output) else new OutputStreamWriter(System.out))

  def next: String = {
    in.ordinaryChars('0', '9')
    in.wordChars('0', '9')
    in.nextToken
    in.sval
  }

  def nextInt: Int = {
    in.nextToken
    in.nval.toInt
  }

  def nextLong:Long ={
    in.nextToken
    in.nval.toLong
  }

  def nextDouble: Double = {
    in.nextToken
    in.nval.toDouble
  }

  def readLine: String = bf.readLine()
  def println(o:Any) = out.println(o)
  def print(o:Any) = out.print(o)
  def printf(s:String,o:Any*) = out.printf(s,o)
  def flush = out.flush
}

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

/**
 * Created by arseny on 15.08.14.
 */
object A extends App {

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

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

  def solve() = {
    val x1 = nextInt
    val y1 = nextInt
    val x2 = nextInt
    val y2 = nextInt
    if(x1 == x2) {
      val x3 = x1 + math.abs(y2 - y1)
      out.print(Array(x3, y1, x3, y2).mkString(" "))
    } else if(y1 == y2) {
      val y3 = y1 + math.abs(x2 - x1)
      out.print(Array(x1, y3, x2, y3).mkString(" "))
    } else {
      val x = math.abs(x2 - x1)
      val y = math.abs(y2 - y1)
      if(x != y) {
        out.print(-1)
      } else {
        out.print(Array(math.min(x1, x2), math.max(y1, y2), math.max(x1, x2), math.min(y1, y2)).mkString(" "))
      }
    }
  }

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

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

/**
 * Created by arseny on 15.08.14.
 */
object A extends App {

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

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

  def solve() = {
    val x1 = nextInt
    val y1 = nextInt
    val x2 = nextInt
    val y2 = nextInt
    if(x1 == x2) {
      val x3 = x1 + math.abs(y2 - y1)
      out.print(Array(x3, y1, x3, y2).mkString(" "))
    } else if(y1 == y2) {
      val y3 = y1 + math.abs(y2 - y1)
      out.print(Array(x1, y3, x2, y3).mkString(" "))
    } else {
      val x = math.abs(x2 - x1)
      val y = math.abs(y2 - y1)
      if(x != y) {
        out.print(-1)
      } else {
        out.print(Array(math.min(x1, x2), math.max(y1, y2), math.max(x1, x2), math.min(y1, y2)).mkString(" "))
      }
    }
  }

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

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  var Array(x1, y1, x2, y2) = in.next().split(" ").map(_.toInt)
  if (x2 < x1 || (x2 == x2 && y2 < y1)) {
    val tmp = x2
    x2 = x1
    x1 = tmp
    val tmp2 = y2
    y2 = y1
    y1 = tmp2
  }

  val width = Math.max(Math.abs(x1 - x2), Math.abs(y1 - y2))
  if (Math.abs(x1 - x2) != 0 && Math.abs(y1 - y2) != 0 && Math.abs(x1 - x2) != Math.abs(y1 - y2))
    println(-1)
  else if (y2 < y1)
    println(List(x1, y2, x2, y1).mkString(" "))
  else if (x1 == x2)
    println(List(x1 + width, y1, x2 + width, y2).mkString(" "))
  else if (y1 == y2)
    println(List(x1, y1 + width, x2, y2 + width).mkString(" "))
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val data = in.next().split(" ").map(_.toInt)
  if (data.distinct.length != 2) println(-1)
  else {
    val min = data.min
    val max = data.max
    val s = Set((min, max), (max, min), (min, min), (max, max)) -- Set((data(0), data(1)), (data(2), data(3)))
    println(s.toList.flatMap(t => List(t._1, t._2)).mkString(" "))
  }

}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val data = in.next().split(" ").map(_.toInt)
  if (data.distinct.length != 2) println(-1)
  else {
    val min = data.min
    val max = data.max
    val s = Set((min, max), (max, min), (min, min), (max, max)) -- Set((data(0), data(1)), (data(2), data(3)))
    println(s.flatMap(t => List(t._1, t._2)).mkString(" "))
  }

}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  var Array(x1, y1, x2, y2) = in.next().split(" ").map(_.toInt)
  if (x2 < x1 || (x2 == x2 && y2 < y1)) {
    val tmp = x2
    x2 = x1
    x1 = tmp
    val tmp2 = y2
    y2 = y1
    y1 = tmp2
  }

  val width = Math.max(Math.abs(x1 - x2), Math.abs(y1 - y2))
  if (Math.abs(x1 - x2) != 0 && Math.abs(y1 - y2) != 0 && Math.abs(x1 - x2) != Math.abs(y1 - y2))
    println(-1)
  if (x1 == x2)
    println(List(x1 + width, y1, x2 + width, y2).mkString(" "))
  else if (y1 == y2)
    println(List(x1, y1 + width, x2, y2 + width).mkString(" "))
  else
    println(List(x1, y2, x2, y1).mkString(" "))
}

import java.util.Scanner

/**
 * Created by Kuang.Ru on 14-9-19.
 */
object A459 extends App{
  val sc = new Scanner(System.in)
  val x1, y1, x2, y2 = sc.nextInt()

  if (x1 == x2) {
    println((x1 + math.abs(y2 - y1)) + " " + y1 + " " + (x1 + math.abs(y2 - y1)) + " " + y2)
  } else if (y1 == y2){
    println(x1 + " " + (y1 + math.abs(x2 - x1)) + " " + x2 + " " + (y1 + math.abs(x2 - x1)))
  } else if ((x2 - x1) / (y2 - y1).toDouble == 1) {
    println(x1 + " " + y2 + " " + x2 + " " + y1)
  } else {
    println(-1)
  }
}


import scala.collection.mutable

object D 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 teams = Array.ofDim[Team](n - 1)

  val Array(_t0, w0) = readLongs(2)
  var t0 = _t0

  case class Team(t: Long, w: Long)

  for (i <- 0 until n - 1) {
    val Array(t, w) = readLongs(2)
    teams(i) = Team(t, w)
  }

  val above = mutable.PriorityQueue.empty[Team](Ordering.by(t => - (t.w - t.t)))
  val below = mutable.PriorityQueue.empty[Team](Ordering.by(_.t))

  for (t <- teams) if (t.t > t0) above += t
  else below += t

  var minPlace = above.size + 1
  var can = true

  while (can && !above.isEmpty) {
    val target = above.dequeue()
    if (target.w - target.t < t0) {
      t0 -= target.w - target.t + 1
      while (below.nonEmpty && below.head.t > t0) {
        above += below.dequeue()
      }
      minPlace = Math.min(minPlace, above.size + 1)
    } else can = false
  }

  println(minPlace)
}

object CF{
	import scala.io.StdIn.{readInt, readLine}
	import scala.collection.mutable.PriorityQueue
	import math.{max, min}

	def main(args: Array[String]){
		val n = readInt()

		val datasq = PriorityQueue.empty[(Long, Long)](Ordering.by((_:(Long, Long))._1))
		var (mdatat, mdataw) = {
			val line = readLine().split(" ").map(_.toLong)
			(line(0), line(1))
		}
		for(_ <- 1 to n-1) datasq += {
			val line = readLine().split(" ").map(_.toLong)
			(line(0), line(1))
		}

		val queue = PriorityQueue.empty[Long](Ordering.by((x:Long) => x).reverse)
		makeQueue(queue, datasq, mdatat)
		val cur = queue.length + 1
		var best = cur

		while(!queue.isEmpty && mdatat >= 0){
			val head = queue.dequeue()
			mdatat -= head

			if(mdatat >= 0){
				while(!datasq.isEmpty && datasq.head._1 > mdatat){
					val head = datasq.dequeue()
					queue += head._2 - head._1 + 1
				}
				best = min(best, queue.length + 1)
			}
		}
		println(best)
	}

	def makeQueue(q: PriorityQueue[Long], datasq:PriorityQueue[(Long, Long)], mdatat: Long){
		if(datasq.isEmpty) return
		if(datasq.head._1 > mdatat){
			val head = datasq.dequeue()
			q += head._2 - head._1 + 1
			makeQueue(q, datasq, mdatat)
		}
	}
}

object CF{
	import scala.io.StdIn.{readInt, readLine}
	import scala.collection.mutable.PriorityQueue

	def main(args: Array[String]){
		val n = readInt()
		val datasq = PriorityQueue.empty[Node](Ordering.by((_:Node).t))
		val mdata = {
			val line = readLine().split(" ").map(_.toLong)
			new Node(line(0), line(1))
		}
		for(_ <- 1 to n-1) datasq += {
			val line = readLine().split(" ").map(_.toLong)
			new Node(line(0), line(1))
		}
		val datas = pq2list(datasq)
		val queue = PriorityQueue.empty[Node](Ordering.by((_:Node).h).reverse)
		var i = 0
		while(i<datas.length && datas(i).t > mdata.t){
			queue += datas(i)
			i += 1
		}

		var best = queue.length+1
		var now = best
		var cur = best

		while(!queue.isEmpty && mdata.t>=0){
			val head = queue.dequeue()
			mdata.t -= head.h
			if(mdata.t >= 0){
				now -= 1
				var i = cur
				while(i<datas.length && datas(i).t > mdata.t){
					queue += datas(i)
					now += 1
					cur += 1
					i += 1
				}
				if(now<best) best=now;
				//println(queue)
				//println(best)
			}
		}
		println(best)
	}

	def pq2list(pq: PriorityQueue[Node]): List[Node] = {
		if(pq.isEmpty) return Nil
		return pq.head :: pq2list(pq.drop(1))
	}

	class Node(var t:Long, val w:Long){
		val h: Long = w-t

		override def toString():String = {
			f"[Node t:$t w:$w, h:$h]"
		}
	}
}

object CF{
	import scala.io.StdIn.{readInt, readLine}
	import scala.collection.mutable.PriorityQueue

	def main(args: Array[String]){
		val n = readInt()
		val datasq = PriorityQueue.empty[Node](Ordering.by((_:Node).t))
		val mdata = {
			val line = readLine().split(" ").map(_.toLong)
			new Node(line(0), line(1))
		}
		for(_ <- 1 to n-1) datasq += {
			val line = readLine().split(" ").map(_.toLong)
			new Node(line(0), line(1))
		}
		val datas = pq2list(datasq)
		val queue = PriorityQueue.empty[Node](Ordering.by((_:Node).h).reverse)
		var i = 0
		while(i<datas.length && datas(i).t > mdata.t){
			queue += datas(i)
			i += 1
		}

		var best = queue.length+1
		var now = best
		var cur = best

		while(!queue.isEmpty && mdata.t>=0){
			val head = queue.dequeue()
			now -= 1
			mdata.t -= head.h
			if(mdata.t >= 0){
				while(cur<datas.length && datas(cur).t > mdata.t){
					queue += datas(i)
					now += 1
					cur += 1
				}
				if(now<best) best=now;

			}
		}
		println(best)
	}

	def pq2list(pq: PriorityQueue[Node]): List[Node] = {
		if(pq.isEmpty) return Nil
		return pq.head :: pq2list(pq.drop(1))
	}

	class Node(var t:Long, val w:Long){
		val h: Long = w-t+1

		override def toString():String = {
			f"[Node t:$t w:$w, h:$h]"
		}
	}
}

object CF{
	import scala.io.StdIn.{readInt, readLine}
	import scala.collection.mutable.PriorityQueue
	import math.max

	def main(args: Array[String]){
		val n = readInt()

		val datasq = PriorityQueue.empty[Node](Ordering.by((_:Node).t))
		val mdata = {
			val line = readLine().split(" ").map(_.toLong)
			new Node(line(0), line(1))
		}
		for(_ <- 1 to n-1) datasq += {
			val line = readLine().split(" ").map(_.toLong)
			new Node(line(0), line(1))
		}

		val queue = PriorityQueue.empty[Node](Ordering.by((_:Node).h).reverse)
		var cur = makeQueue(queue, datasq, mdata) + 1
		var best = cur

		while(!queue.isEmpty && mdata.t >= 0){
			val head = queue.dequeue()
			mdata.t -= head.h

			if(mdata.t >= 0){
				while(!datasq.isEmpty && datasq.head.t > mdata.t){
					queue += datasq.dequeue()
				}
				best = max(best, queue.length + 1)
			}
		}
		println(best)
	}

	def makeQueue(q: PriorityQueue[Node], datasq:PriorityQueue[Node], mdata: Node):Long = {
		if(datasq.isEmpty) return 0
		if(datasq.head.t > mdata.t) {
			q += datasq.dequeue()
			return 1 + makeQueue(q, datasq, mdata)
		}
		return 0
	}

	class Node(var t:Long, val w:Long){
		val h:Long = w-t+1
	}
}


import scala.collection.mutable.Map
object C extends App {
  import java.io._
  import java.nio.file.{Files, Path}
  import java.util.StringTokenizer
  import scala.io.Source
  import scala.io.Codec

  /* Implicit methods */
  implicit def intWithTimes(n: Int) = {
    new {
      def times(f: => Unit): Unit = 1.to(n).foreach { _ => f }
    }
  }
  /* Implicit methods */

  //  val in = new CustomScanner(Source.fromResource("input.txt").mkString)
  val in  = new CustomScanner(System.in)
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val inputLines = in.nextInt()

    inputLines.times {
      val _         = in.nextInt()
      val intInputs = in.line().split("").map(x => x.toInt - 1)

      val map1: Map[Int, Int] = Map.empty[Int, Int]
//      val map1: Map[Int, Int] = Map((0, 1))

      val targetSum    = 0
      var result: Long = 0L
      var cumSum       = 0
      intInputs.foreach(x => {
        /*cumSum += x
        result += map1.getOrElse(cumSum - targetSum, 0)
        map1.put(cumSum, map1.getOrElse(cumSum, 0) + 1)
         */

        cumSum += x
        if (cumSum == targetSum) result += 1
        val rest = cumSum - targetSum
        result += map1.getOrElse(rest, 0)

        map1.put(cumSum, map1.getOrElse(cumSum, 0) + 1)
      })
      println(result)
    }
  }

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

  /**
    * Util methods
    */

  def printArr[T](in: Array[T]) = {
    in.foreach(print)
    println()
  }

  /**
    * Scala implementation of a faster java.util.Scanner
    * See: http://codeforces.com/blog/entry/7018
    */
  class CustomScanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {

    def this(reader: BufferedReader) = this(new LineNumberReader(reader))

    def this(reader: Reader) = this(new BufferedReader(reader))

    def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))

    def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))

    def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)

    def this(str: String) = this(new StringReader(str))

    private[this] val tokenizers = {
      Iterator
        .continually(reader.readLine())
        .takeWhile(_ != null)
        .map(new StringTokenizer(_))
        .filter(_.hasMoreTokens)
    }

    private[this] var current: Option[StringTokenizer] = None

    @inline private[this] def tokenizer(): Option[StringTokenizer] =
      current.find(_.hasMoreTokens) orElse {
        current = if (tokenizers.hasNext) Some(tokenizers.next()) else None
        current
      }

    /**
      * Unlike Java's scanner which returns till end of current line, this actually returns the next line
      * @see line() if you want the Java behaviour
      */
    def nextLine(): String = {
      current = None // reset
      reader.readLine()
    }

    def lineNumber: Int = reader.getLineNumber

    def line(): String = tokenizer().get.nextToken("\n\r")

    def nextString(): String = next()

    def nextChar(): Char = next().ensuring(_.length == 1).head

    def nextBoolean(): Boolean = next().toBoolean

    def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)

    def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)

    def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)

    def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)

    def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)

    def nextFloat(): Float = next().toFloat

    def nextDouble(): Double = next().toDouble

    def nextBigDecimal(): BigDecimal = BigDecimal(next())

    override def next(): String = tokenizer().get.nextToken()

    override def hasNext: Boolean = tokenizer().nonEmpty

    override def close(): Unit = reader.close()
  }
}

object C extends App {
  import scala.io.StdIn._
  import scala.collection.immutable.HashMap

  val t = readInt()

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

    val ans = an
      .map(_ - 1)
      .foldLeft((0L, 0L, HashMap(0L -> 1))) { // prefix_sum(0) = 0  -->  counts(0) = 1
        case ((answer, prefix, counts), a) =>
          val key = prefix + a
          val add = counts.getOrElse(key, 0) //

          (answer + add, key, counts + (key -> (add + 1)))
      }
      ._1

    println(ans)
  }
}

object C extends App {
  import scala.io.StdIn._
  import scala.collection.immutable.HashMap

  val t = readInt()

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

    val ans = an
      .map(_ - 1)
      .foldLeft((0, 0, HashMap(0 -> 1))) { // prefix_sum(0) = 0  -->  counts(0) = 1
        case ((answer, prefix, counts), a) =>
          val key = prefix + a
          val add = counts.getOrElse(key, 0) //

          (answer + add, key, counts + (key -> (add + 1)))
      }
      ._1

    println(ans)
  }
}

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

  val t = readInt()

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

    @annotation.tailrec
    def go(iter: Int, count: Int): Int =
      if (iter > n || iter > 9) count
      else go(iter + 1, count + an.sliding(iter).count(_.sum == iter))

    val ans = go(1, 0)

    println(ans)
  }
}

import scala.collection.mutable.Map
object C extends App {
  import java.io._
  import java.nio.file.{Files, Path}
  import java.util.StringTokenizer
  import scala.io.Source
  import scala.io.Codec

  /* Implicit methods */
  implicit def intWithTimes(n: Int) = {
    new {
      def times(f: => Unit): Unit = 1.to(n).foreach { _ => f }
    }
  }
  /* Implicit methods */

  //  val in = new CustomScanner(Source.fromResource("input.txt").mkString)
  val in  = new CustomScanner(System.in)
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val inputLines = in.nextInt()

    inputLines.times {
      val _         = in.nextInt()
      val intInputs = in.line().split("").map(x => x.toInt - 1)

      val map1: Map[Int, Int] = Map.empty[Int, Int]
//      val map1: Map[Int, Int] = Map((0, 1))

      val targetSum = 0
      var result    = 0
      var cumSum    = 0
      intInputs.foreach(x => {
        /*cumSum += x
        result += map1.getOrElse(cumSum - targetSum, 0)
        map1.put(cumSum, map1.getOrElse(cumSum, 0) + 1)
        */

        cumSum += x
        if(cumSum == targetSum) result += 1
        val rest = cumSum - targetSum
        result += map1.getOrElse(rest, 0)

        map1.put(cumSum, map1.getOrElse(cumSum, 0) + 1)
      })
      println(result)
    }
  }

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

  /**
    * Util methods
    */

  def printArr[T](in: Array[T]) = {
    in.foreach(print)
    println()
  }

  /**
    * Scala implementation of a faster java.util.Scanner
    * See: http://codeforces.com/blog/entry/7018
    */
  class CustomScanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {

    def this(reader: BufferedReader) = this(new LineNumberReader(reader))

    def this(reader: Reader) = this(new BufferedReader(reader))

    def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))

    def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))

    def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)

    def this(str: String) = this(new StringReader(str))

    private[this] val tokenizers = {
      Iterator
        .continually(reader.readLine())
        .takeWhile(_ != null)
        .map(new StringTokenizer(_))
        .filter(_.hasMoreTokens)
    }

    private[this] var current: Option[StringTokenizer] = None

    @inline private[this] def tokenizer(): Option[StringTokenizer] =
      current.find(_.hasMoreTokens) orElse {
        current = if (tokenizers.hasNext) Some(tokenizers.next()) else None
        current
      }

    /**
      * Unlike Java's scanner which returns till end of current line, this actually returns the next line
      * @see line() if you want the Java behaviour
      */
    def nextLine(): String = {
      current = None // reset
      reader.readLine()
    }

    def lineNumber: Int = reader.getLineNumber

    def line(): String = tokenizer().get.nextToken("\n\r")

    def nextString(): String = next()

    def nextChar(): Char = next().ensuring(_.length == 1).head

    def nextBoolean(): Boolean = next().toBoolean

    def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)

    def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)

    def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)

    def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)

    def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)

    def nextFloat(): Float = next().toFloat

    def nextDouble(): Double = next().toDouble

    def nextBigDecimal(): BigDecimal = BigDecimal(next())

    override def next(): String = tokenizer().get.nextToken()

    override def hasNext: Boolean = tokenizer().nonEmpty

    override def close(): Unit = reader.close()
  }
}


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

import scala.StringBuilder
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object C401 {

  var result = true
  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  def solve: Int = {
    var n = nextInt
    var m = nextInt
    if (n > m + 1)
      out.println(-1)
    else if (n == m + 1) {
      for (i <- 0 until (n + m - 1) / 2) {
        out.print("01")
      }
      out.println("0")
    } else if (m > 2 * n + 2) {
      out.println(-1)
    } else {
      val sb = new StringBuilder()
      while (n != m && n > 0 && m > 0 ) {
        sb.append("110")
        n -= 1
        m -= 2
      }
      while (m > 0 && n > 0) {
        sb.append("10")
        m -= 1
        n -= 1
      }
      var pos = sb.indexOf('1')
      while (n > 0) {
        sb.insert(pos + 1, '0')
        pos = sb.indexOf('1', pos + 2)
        n -= 1
      }
      while (m > 0) {
        sb.append('1')
        m -= 1
      }
      out.println(sb.toString())
    }
    return 0
  }
}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  var Array(n0, m1) = in.next().split(' ').map(_.toInt)
  val res = Array.ofDim[Int](n0 + m1)
  var solution = true
  (0 until n0 + m1).foreach{
    case el if !solution =>
    case el if el > 0 && res(el - 1) == 0 =>
      res(el) = 1
      m1 -= 1
      solution &&= m1 >= 0
    case el if el > 1 && (res(el - 1) == res(el - 2) && res(el - 1) == 1) || n0 > m1 =>
      res(el) = 0
      n0 -= 1
      solution &&= n0 >= 0
    case el =>
      res(el) = 1
      m1 -= 1
      solution &&= m1 >= 0
  }
  if (!solution)
    println(-1)
  else
    println(res.mkString)
}

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

/**
 * Created by hama_du on 2014/03/11.
 */
object ProblemC extends App {
  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val zero,one = in.nextInt

  if (zero >= one+2) {
    out.println(-1)
  } else {
    val maxOne = (zero+1)*2
    if (one > maxOne) {
      out.println(-1)
    } else {
      if (zero >= one) {
        printZO(zero, one)
      } else {
        printOOZ(zero, one, one - (zero+1))
      }
      out.println()
    }
  }
  out.flush()

  def printOOZ(zero: Int, one: Int, dblOne: Int) {
    if (zero == 0) {
      if (dblOne == 1) {
        out.print("11")
      } else {
        out.print("1")
      }
    } else {
      if (dblOne >= 1) {
        out.print("110")
      } else {
        out.print("10")
      }
      printOOZ(zero-1, one-1, dblOne-1)
    }
  }

  def printZO(zero: Int, one: Int) {
    if (one == 0) {
      if (zero == 1) {
        out.print('0')
      }
    } else {
      out.print("01")
      printZO(zero-1, one-1)
    }
  }
}

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

import scala.StringBuilder
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object C401 {

  var result = true
  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  def solve: Int = {
    var n = nextInt
    var m = nextInt
    if (n > m + 1)
      out.println(-1)
    else if (n == m + 1) {
      for (i <- 0 until (n + m - 1) / 2) {
        out.print("01")
      }
      out.println("0")
    } else if (m > 2 * n + 2) {
      out.println(-1)
    } else {
      val sb = new StringBuilder()
      while (n >= 1 && m >= 2) {
        sb.append("110")
        n -= 1
        m -= 2
      }
      while (m > 0) {
        sb.append('1')
        m -= 1
      }
      out.println(sb.toString())
    }
    return 0
  }
}

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

import scala.StringBuilder
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object C401 {

  var result = true
  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  def solve: Int = {
    var n = nextInt
    var m = nextInt
    if (n > m + 1)
      out.println(-1)
    else if (n == m + 1) {
      for (i <- 0 until (n + m - 1) / 2) {
        out.print("01")
      }
      out.println("0")
    } else if (m > 2 * n + 2) {
      out.println(-1)
    } else {
      val sb = new StringBuilder()
      while (n >= 1 && m >= 2) {
        sb.append("110")
        n -= 1
        m -= 2
      }
      while (m > 0) {
        sb.append('1')
        m -= 1
      }
      var pos = sb.indexOf('1')
      while (n > 0) {
        sb.insert(pos + 1, '0')
        pos = sb.indexOf('1', pos + 2)
        n -= 1
      }
      out.println(sb.toString())
    }
    return 0
  }
}

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

import scala.StringBuilder
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object C401 {

  var result = true
  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  def solve: Int = {
    var n = nextInt
    var m = nextInt
    if (n > m + 1)
      out.println(-1)
    else if (n == m + 1) {
      for (i <- 0 until (n + m - 1) / 2) {
        out.print("01")
      }
      out.println("0")
    } else if (m > 2 * n + 2) {
      out.println(-1)
    } else {
      val sb = new StringBuilder()
      while (n != m) {
        sb.append("110")
        n -= 1
        m -= 2
      }
      while (m > 0 && n > 0) {
        sb.append("10")
        m -= 1
        n -= 1
      }
      var pos = sb.indexOf('1')
      while (n > 0) {
        sb.insert(pos + 1, '0')
        pos = sb.indexOf('1', pos + 2)
        n -= 1
      }
      out.println(sb.toString())
    }
    return 0
  }
}

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

import scala.StringBuilder
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object C401 {

  var result = true
  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  def solve: Int = {
    var n = nextInt
    var m = nextInt
    if (n > m + 1)
      out.println(-1)
    else if (n == m + 1) {
      for (i <- 0 until n + m - 1) {
        out.print("01")
      }
      out.println("0")
    } else if (m > 2 * n + 2) {
      out.println(-1)
    } else {
      val sb = new StringBuilder()
      while (n >= 1 && m >= 1) {
        sb.append("10")
        n -= 1
        m -= 1
      }
      var pos = sb.indexOf('1')
      while (m > 0 && pos != -1) {
        sb.insert(pos + 1, '1')
        pos = sb.indexOf('1', pos + 2)
        m -= 1
      }
      while (m > 0) {
        sb.append('1')
        m -= 1
      }
      out.println(sb.toString())
    }
    return 0
  }
}

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

import scala.StringBuilder
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object C401 {

  var result = true
  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  def solve: Int = {
    var n = nextInt
    var m = nextInt
    if (n > m + 1)
      out.println(-1)
    else if (n == m + 1) {
      for (i <- 0 until (n + m - 1) / 2) {
        out.print("01")
      }
      out.println("0")
    } else if (m > 2 * n + 2) {
      out.println(-1)
    } else {
      val sb = new StringBuilder()
      while (n >= 1 && m >= 2) {
        sb.append("110")
        n -= 1
        m -= 2
      }
      while (m > 0) {
        sb.append('1')
        m -= 1
      }
      while (n > 0) {
        sb.insert(0, '0')
        n -= 1
      }
      out.println(sb.toString())
    }
    return 0
  }
}


object A711 {
  @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 = Array.fill(n)(scala.io.StdIn.readLine)
    if(input.exists(_.contains("OO"))) {
      println("YES")
      var break = false
      var i = 0
      while(!break) {
        if(input(i).contains("OO")) {
          input(i) = input(i).replaceFirst("OO", "++")
          break = true
        }
        i += 1
      }
      println(input.mkString("\n"))
    } else {
      println("NO")
    }
  }
}

object test {
  def main(args: Array[String]): Unit = {
    val in = Console.in
    val num = Integer.parseInt(in.readLine().trim)
    val out = 1 to num map (i => in.readLine()) mkString "\n"  replaceFirst("OO", "++")
    if (out.contains("++"))
      println(s"YES\n$out")
    else println("NO")
  }

}

import java.util.Scanner

object Main{
  // val n = sc.nextInt()
  // val s =
  // val str = sc.next()

  def main (args: Array[String]){
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    sc.nextLine()
    val seats = new Array[String](n)
    for(i <- 0 until n)
      seats(i) = sc.nextLine()

    //
    var flag = false
    var i = 0
    while(!flag && i < n){
      val now = seats(i)
      if(now.substring(0, 2) == "OO"){
        flag = true
        seats(i) = "++" + now.substring(2)
      }
      else if(now.substring(3) == "OO"){
        flag = true
        seats(i) = now.substring(0, 3) + "++"
      }

      i += 1
    }

    if(flag){
      println("YES")
      for(s <- seats)
        println(s)
    }
    else
      println("NO")
  }
}

object main extends App {
  import java.io.{InputStream, PrintStream}
  import java.util.Scanner
 // override
  def solve(input: InputStream, output: PrintStream): Unit = {
    val sc = new Scanner(input)
    val nrows = sc.nextInt()
    val busIndx = (1 to nrows)
              .map(_ => sc.next()).zipWithIndex.toArray
    val optRow = busIndx.find{case (str,_) => str.startsWith("OO") || str.endsWith("OO")}
    if(optRow.isDefined){
      val (row,indxRow) = optRow.get
      busIndx(indxRow) = (updateRow(row),indxRow)

      output.println("YES")
      busIndx.foreach{case (str,_) => output.println(str)}
    }else{
      output.println("NO")
    }

  }

  def updateRow(str: String): String = {
    if(str.startsWith("OO")) "++"+str.substring(2)
    else str.substring(0,3)+ "++"
  }
  solve(System.in,System.out)
}

import java.util

import scala.util.Sorting
import scala.io.StdIn

object App {

  def main(args: Array[String]) {

    val max = 1000000007;
    val n = readInt()

    val  A:Array[Array[String]] = Array.fill(n)(StdIn.readLine().split('|'))

    var i = 0
    while(i != n && !A(i)(0).equals("OO") && !A(i)(1).equals("OO")) {
      i+=1
    }

    if(i!=n) {
      println("YES")
      if(A(i)(0).equals("OO"))
        A(i)(0) = "++"
      else
        A(i)(1) = "++"

      A.foreach(a=>println(a(0) + "|" + a(1)))
    } else {
      println("NO")
    }
  }

  def readInt(): Int = StdIn.readInt()

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

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

}

import java.util.Scanner

object Main extends App {
    val scan = new Scanner(System.in)
    val n = scan.nextInt()
    val good = collection.immutable.HashMap("OO|XX" -> "++|XX", "OO|OX" -> "++|OX",
                                            "OO|XO" -> "++|XO", "OO|OO" -> "++|OO",
                                            "XX|OO" -> "XX|++", "XO|OO" -> "XO|++",
                                            "OX|OO"->"OX|++")

    val input = for (i <- 1 to n) yield scan.next()
    val yes = input.exists(good.contains(_))
    if (yes) {
        println("YES")
        var found = false
        input foreach { line =>
            if (!found && good.contains(line)) {
                found = true
                println(good.get(line).get)
            } else {
                println(line)
            }
        }
    } else {
        println("NO")
    }
}

import scala.io.StdIn._;

object Test extends App {
  val n = readInt();
  val ans = (for (i<-0 until n) yield readLine()).mkString("\n");
  if (ans.contains("OO")) {
    println("YES");
    println(ans.replaceFirst("OO", "++"));
  } else {
    println("NO\n");
  }
}

object Solution extends App {
  val lines = io.Source.stdin.getLines()
  val n = lines.next().toInt
  val (bus, ans) = (1 to n).map(_ => lines.next()).foldLeft(List.empty[String], false) {
    case ((xs, true), el) => (el :: xs, true)
    case ((xs, false), el) if el.contains("OO") => (el.replaceFirst("OO", "++") :: xs, true)
    case ((xs, false), el) => (el :: xs, false)
  }
  if (ans) {
    println("YES")
    println(bus.reverse.mkString("\n"))
  } else println("NO")
}

object A 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 rows = Array.fill(n){ readLine }

  val i = rows.indexWhere(_.contains("OO"))

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

  if (i == -1) println("NO")
  else {
    println("YES")
    rows(i) = rows(i).replaceFirst("OO", "++")
    println(rows.mkString("\n"))
  }

  Console.flush
}

import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._, collection.Searching._

object _711A extends CodeForcesApp {
  override def apply(io: IO) = {import io.{read, write, writeAll}
    val bus = read[Seq[String]].mkString("\n")
    val ans = if (bus.contains("OO")) {
      "YES\n" + bus.replaceFirst("OO", "++")
    } else {
      "NO"
    }

    write(ans)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    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)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    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 {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[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
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {
    val (xs, ys) = points.unzip
    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)
  }
  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {
    val shape = new java.awt.geom.GeneralPath()
    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}
    points.tail foreach {case (x, y) => shape.lineTo(x, y)}
    shape.closePath()
    shape
  }
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

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()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: C of 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, more: Any*): this.type = {
    printer.print(obj)
    more foreach {i =>
      printer.print(' ')
      printer.print(i)
    }
    this
  }
  def writeAll(obj: Traversable[Any], separator: String = "\n"): this.type = write(obj mkString separator)

  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: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    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._

object Solution {

  def main(args: Array[String]): Unit = {
    val n = readInt
    val bus = Array.fill(n)(readLine)
    val idx = bus.indexWhere(str => str.contains("OO"))
    if (idx == -1) {
      println("NO")
    } else {
      println("YES")
      bus.updated(idx, bus(idx).replaceFirst("OO", "++")).foreach(str => println(str))
    }
  }
}

import scala.io.StdIn._

object Solution {

  def main(args: Array[String]): Unit = {
    val bus = Array.fill(readInt)(readLine)
    val idx = bus.indexWhere(str => str.contains("OO"))
    if (idx == -1) {
      println("NO")
    } else {
      println("YES")
      bus.updated(idx, bus(idx).replaceFirst("OO", "++")).foreach(str => println(str))
    }
  }
}

object test {
  def main(args: Array[String]): Unit = {
    val num = Integer.parseInt(Console.readLine().trim)
    val out = Stream.continually(Console.readLine()).take(num).mkString("\n").replaceFirst("OO", "++")
    println(if (out.contains("++")) s"YES\n$out" else "NO")
  }

}

import java.util.Scanner

object Main extends App {
    val scan = new Scanner(System.in)
    val n = scan.nextInt()
    val good = collection.immutable.HashMap("OO|XX" -> "++|XX", "OO|OX" -> "++|OX",
                                            "OO|XO" -> "++|XO", "OO|OO" -> "++|OO",
                                            "XX|OO" -> "XX|++", "XO|OO" -> "XO|++",
                                            "OX|OO"->"OX|++")

    val input = for (i <- 1 to n) yield scan.next()
    val yes = input.exists(good.contains(_))
    if (yes) {
        println("YES")
        var found = false
        input foreach { line =>
            if (!found && good.contains(line)) {
                found = true
                println(good.get(line).get)
            } else {
                println(line)
            }
        }
    } else {
        println("NO")
        input foreach println
    }
}

object Solution extends App {
  val lines = io.Source.stdin.getLines()
  val n = lines.next().toInt
  val (bus, ans) = (1 to n).map(_ => lines.next()).foldLeft(List.empty[String], false) {
    case ((xs, true), el) => (el :: xs, true)
    case ((xs, false), el) if el.contains("OO") => (el.replace("OO", "++") :: xs, true)
    case ((xs, false), el) => (el :: xs, false)
  }
  if (ans) println("YES") else println("NO")
  println(bus.reverse.mkString("\n"))
}

object Solution extends App {
  val lines = io.Source.stdin.getLines()
  val n = lines.next().toInt
  val (bus, ans) = (1 to n).map(_ => lines.next()).foldLeft(List.empty[String], false) {
    case ((xs, true), el) => (el :: xs, true)
    case ((xs, false), el) if el.contains("OO") => (el.replace("OO", "++") :: xs, true)
    case ((xs, false), el) => (el :: xs, false)
  }
  if (ans) {
    println("YES")
    println(bus.reverse.mkString("\n"))
  } else println("NO")
}

object A711 {
  @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 = Array.fill(n)(scala.io.StdIn.readLine)
    if(input.exists(_.contains("OO"))) {
      println("YES")
      var break = false
      var i = 0
      while(!break) {
        if(input(i).contains("OO")) {
          input(i) = input(i).replace("OO", "++")
          break = true
        }
        i += 1
      }
      println(input.mkString("\n"))
    } else {
      println("NO")
    }
  }
}

object test {
  def main(args: Array[String]): Unit = {
    val num = Integer.parseInt(Console.readLine().trim)
    val out = Stream.continually(Console.readLine()).take(num).mkString("\n").replaceFirst("00", "++")
    println(if (out.contains("++")) s"YES\n$out" else "NO")
  }

}

object test {
  def main(args: Array[String]): Unit = {
    val in = Console.in
    val num = Integer.parseInt(in.readLine().trim)
    val out = 1 to num map (i => in.readLine()) mkString "\n"  replaceFirst("00", "++")
    if (out.contains("++"))
      println(s"YES\n$out")
    else println("NO")
  }

}


object Main extends App {
  val stdin = scala.io.Source.stdin.getLines()
  val t = stdin.next().toInt
  println(stdin
    .take(2 * t)
    .grouped(2)
    .map(_.last)
    .map(_
      .split(' ')
      .map(_.toInt)
      .map(x => if (x == 1) 1 else -1))
    .map(solve)
    .mkString("\n"))

  def solve(arr: Array[Int]) = {
    val n = arr.length / 2
//    val globalSum = arr.sum
    val leftSum = arr.take(n).sum
    val rightSum = arr.drop(n).sum
//    println(arr.mkString(" "))
//    println("leftSum " + leftSum)
//    println("rightSum " + rightSum)
//    println("globalSum " + globalSum)
    //1 1 1 -1 -1 1 ||| -1 1 -1 1 1 -1
    val map = arr.take(n).foldLeft(Map(0 -> n, leftSum -> 0), 0, n) {
      case ((map, sum, needToRemove), el) =>
        val nSum = sum + el
        val nNeedToRemove = needToRemove - 1
        val nMap = if (nSum != leftSum) map + (nSum -> nNeedToRemove) else map
        (nMap, nSum, nNeedToRemove)
    }._1
//    println(map)
    arr.drop(n).foldLeft(map.getOrElse(-rightSum, 2 * n), rightSum, 0) {
      case((res, sum, needToRemove), el) =>
//        println("el = " + el)
//        println(res)
        val nSum = sum - el
        val nNeedToRemove = needToRemove + 1
        val minRes = Math.min(res, map.get(-nSum).map(_ + nNeedToRemove).getOrElse(res))
        (minRes, nSum, nNeedToRemove)
    }._1
  }
}

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

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
  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  def debugDim(m: Array[Array[Int]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  def debug(s: => String): Unit = {
    if (!oj){ System.err.println(s) }
  }
  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 = _

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

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

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

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

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

object Workspace {
  import Main._
  import java.util.Arrays.sort

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

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 solve2(): Int = {
    val N = ni()
    val A = na(N).reverse
    val B = na(N)
    val cnt1 = A.count(_ == 1) + B.count(_ == 1)
    val cnt2 = 2 * N - cnt1
    val bal = cnt1 - cnt2
    val A2 = A.map(a => if (a == 1) 1 else -1)
    val B2 = B.map(a => if (a == 1) 1 else -1)
    val sumA = cumSum(A2).map(_.toInt)
    val sumB = cumSum(B2).map(_.toInt)
    debug(sumA)
    debug(sumB)
    debug(s"bal:$bal")
    val ref = mutable.Map[Int, Int]()
    REP(N + 1) { i =>
      val v = sumB(i)
      if (!ref.contains(v)) {
        ref(v) = i
      }
    }

    debug(ref.mkString(","))

    var ans = 2 * N
    REP(N + 1) { i =>
      val expectedB = bal - sumA(i)
//      debug(s"i:$i expectedB:$expectedB")
      if (ref.contains(expectedB)) {
        ans = min(ans, ref(expectedB) + i)
      }
    }
    ans
  }

  def solve(): Unit = {
    REP(ni()) { _ =>
      out.println(solve2())
    }
  }
}

object Main extends App {
  val stdin = scala.io.Source.stdin.getLines()
  val t = stdin.next().toInt
  println(stdin
    .take(2 * t)
    .grouped(2)
    .map(_.last)
    .map(_
      .split(' ')
      .map(_.toInt)
      .map(x => if (x == 1) 1 else -1))
    .map(solve)
    .mkString("\n"))

  def solve(arr: Array[Int]) = {
    val n = arr.length / 2
//    val globalSum = arr.sum
    val leftSum = arr.take(n).sum
    val rightSum = arr.drop(n).sum
//    println(arr.mkString(" "))
//    println("leftSum " + leftSum)
//    println("rightSum " + rightSum)
//    println("globalSum " + globalSum)
    //1 1 1 -1 -1 1 ||| -1 1 -1 1 1 -1
    val map = arr.take(n).foldLeft(Map(leftSum -> 0), 0, n) {
      case ((map, sum, needToRemove), el) =>
        val nSum = sum + el
        val nNeedToRemove = needToRemove - 1
        val nMap = if (nSum != leftSum) map + (nSum -> nNeedToRemove) else map
        (nMap, nSum, nNeedToRemove)
    }._1
    arr.drop(n).foldLeft(map.getOrElse(-rightSum, 2 * n), 0, 0) {
      case((res, sum, needToRemove), el) =>
//        println("el = " + el)
//        println(res)
        val nSum = sum + el
        val nNeedToRemove = needToRemove + 1
        val minRes = Math.min(res, map.get(-rightSum + nSum).map(_ + nNeedToRemove).getOrElse(res))
        (minRes, nSum, nNeedToRemove)
    }._1
  }
}

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

object Main extends App {
  val stdin = scala.io.Source.stdin.getLines()
  val t = stdin.next().toInt
  println(stdin
    .take(2 * t)
    .grouped(2)
    .map(_.last)
    .map(_
      .split(' ')
      .map(_.toInt)
      .map(x => if (x == 1) 1 else -1))
    .map(solve)
    .mkString("\n"))

  def solve(arr: Array[Int]) = {
    val n = arr.length / 2
//    val globalSum = arr.sum
    val leftSum = arr.take(n).sum
    val rightSum = arr.drop(n).sum
//    println(arr.mkString(" "))
//    println("leftSum " + leftSum)
//    println("rightSum " + rightSum)
//    println("globalSum " + globalSum)
    //1 1 1 -1 -1 1 ||| -1 1 -1 1 1 -1
    val map = arr.take(n).foldLeft(Map(leftSum -> 0, 0 -> n), 0, n) {
      case ((map, sum, needToRemove), el) =>
        val nSum = sum + el
        val nNeedToRemove = needToRemove - 1
        val nMap = if (nSum != leftSum) map + (nSum -> nNeedToRemove) else map
        (nMap, nSum, nNeedToRemove)
    }._1
//    println(map)
    arr.drop(n).foldLeft(map.getOrElse(-rightSum, 2 * n), rightSum, 0) {
      case((res, sum, needToRemove), el) =>
//        println("el = " + el)
//        println(res)
        val nSum = sum - el
        val nNeedToRemove = needToRemove + 1
        val minRes = Math.min(res, map.get(-nSum).map(_ + nNeedToRemove).getOrElse(res))
        (minRes, nSum, nNeedToRemove)
    }._1
  }
}

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

object Main extends App {
  val stdin = scala.io.Source.stdin.getLines()
  val t = stdin.next().toInt
  println(stdin
    .take(2 * t)
    .grouped(2)
    .map(_.last)
    .map(_
      .split(' ')
      .map(_.toInt)
      .map(x => if (x == 1) 1 else -1))
    .map(solve)
    .mkString("\n"))

  def solve(arr: Array[Int]) = {
    val n = arr.length / 2
//    val globalSum = arr.sum
    val leftSum = arr.take(n).sum
    val rightSum = arr.drop(n).sum
//    println(arr.mkString(" "))
//    println("leftSum " + leftSum)
//    println("rightSum " + rightSum)
//    println("globalSum " + globalSum)
    //1 1 1 -1 -1 1 ||| -1 1 -1 1 1 -1
    val map = arr.take(n).foldLeft(Map(leftSum -> 0), 0, n) {
      case ((map, sum, needToRemove), el) =>
        val nSum = sum + el
        val nNeedToRemove = needToRemove - 1
        val nMap = if (nSum != leftSum) map + (nSum -> nNeedToRemove) else map
        (nMap, nSum, nNeedToRemove)
    }._1
    arr.drop(n).foldLeft(map.getOrElse(-rightSum, 2 * n), rightSum, 0) {
      case((res, sum, needToRemove), el) =>
//        println("el = " + el)
//        println(res)
        val nSum = sum - el
        val nNeedToRemove = needToRemove + 1
        val minRes = Math.min(res, map.get(-nSum).map(_ + nNeedToRemove).getOrElse(res))
        (minRes, nSum, nNeedToRemove)
    }._1
  }
}

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