import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt
  val data = (1 to n).map { _ =>
    val Array(sex, start, end) = in.next().split(' ')
    (sex.head, start.toInt, end.toInt)
  }
  println(2 * (1 to 366).foldLeft(0) {
    case(acc, i) =>
      val res = data.foldLeft((0, 0)) {
        case((m, f), ('M', start, end)) if i >= start && i <= end => (m + 1, f)
        case((m, f), ('F', start, end)) if i >= start && i <= end => (m, f + 1)
        case(acc, _) => acc
      }
      Math.max(acc, Math.min(res._1, res._2))
  })
}

import scala.io.Source

object CF343_B extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt

  val mens = new Array[Int](367)
  val wms = new Array[Int](367)

  for(r <- 0 to n-1) {
      val line = in.next()
      val info = line.split(" ")
      var arr = mens
      if(info(0).equals("F")) {
         arr = wms
      }
      for(idx <- info(1).toInt to info(2).toInt) {
        arr(idx) += 1
      }
  }

  var max = 0

  for(i <- 0 to 366) {
    val cand = mens(i).min(wms(i)) * 2
    max = max.max(cand)
  }

println(max)

}

import io.StdIn._
import java.lang.Math._
object div2_B {
    def main(args: Array[String]){
        val n = readInt()
        var F = Vector[(String,(Int,Int))]()
        for (i <- 0 until n) {
            val ln = readLine().split(" ")
            val v = (ln(0).toString,(ln(1).toInt, ln(2).toInt))

            F = F :+ v
        }
        var res = 0
        for(i <- 1 to 366) {
            var m = 0
            var f = 0
            for(j <- 0 until F.length){
                if (F(j)._2._1 <= i && F(j)._2._2 >= i) {
                    if (F(j)._1 == "M") {
                        m = m + 1
                    }
                    else {
                        f = f + 1
                    }
                }
            }
            res = max(res, min(m,f))
        }
        println(res*2)
    }
}

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

object _629B extends CodeForcesApp {
  override type Result = Int

  override def solve(read: InputReader) = {
    val (males, females) = (Array.ofDim[Int](367), Array.ofDim[Int](367))
    val n = read[Int]
    repeat(n) {
      val (s, a, b) = read[(Char, Int, Int)]
      val arr = if (s == 'M') males else females
      for {i <- a to b} arr(i) += 1
    }

    val couples = males zip females map { case (a, b) => a min b}
    couples.max * 2
  }

  @inline def repeat(n: Int)(f: => Unit): Unit = for {_ <- 1 to n} f

  override def format(result: Result) = result.toString
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  type Result
  def solve(scanner: InputReader): Result
  def format(result: Result): String
  def apply(scanner: InputReader): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new InputReader(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io.{BufferedReader, Reader, InputStreamReader, StringReader, InputStream}
import java.util.StringTokenizer

class InputReader(reader: BufferedReader) extends Iterator[String] with AutoCloseable {
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream) = this(new InputStreamReader(inputStream))
  def this(str: String) = this(new StringReader(str))

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

  @inline private[this] def tokenizer(): Option[StringTokenizer] = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    if (tokenizers.nonEmpty) Some(tokenizers.head) else None
  }

  def apply[A: Parser]: A = implicitly[Parser[A]].apply(this)

  def apply[C[_], A: Parser](n: Int)(implicit cbf: Parser.Collection[C, A]): C[A] = {
    val builder = cbf()
    for {_ <- 1 to n} builder += apply[A]
    builder.result()
  }

  def till(delim: String): String = tokenizer().get.nextToken(delim)
  def tillEndOfLine() = till("\n\r")

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

class Parser[A](val apply: InputReader => A) {
  def map[B](f: A => B): Parser[B] = new Parser(apply andThen f)
}
object Parser {
  type Collection[C[_], A] = scala.collection.generic.CanBuildFrom[C[A], A, C[A]]
  implicit def collection[C[_], A: Parser](implicit cbf: Collection[C, A])   : Parser[C[A]]            = new Parser(r => r[C, A](r[Int]))
  implicit val string                                                        : Parser[String]          = new Parser(_.next())
  implicit val char                                                          : Parser[Char]            = string.map(s => s.ensuring(_.length == 1, s"Expected Char; found $s").head)
  implicit val boolean                                                       : Parser[Boolean]         = string.map(_.toBoolean)
  implicit val int                                                           : Parser[Int]             = string.map(_.toInt)
  implicit val long                                                          : Parser[Long]            = string.map(_.toLong)
  implicit val bigInt                                                        : Parser[BigInt]          = string.map(BigInt(_))
  implicit val double                                                        : Parser[Double]          = string.map(_.toDouble)
  implicit val bigDecimal                                                    : Parser[BigDecimal]      = string.map(BigDecimal(_))
  implicit def tuple2[A: Parser, B: Parser]                                  : Parser[(A, B)]          = new Parser(r => (r[A], r[B]))
  implicit def tuple3[A: Parser, B: Parser, C: Parser]                       : Parser[(A, B, C)]       = new Parser(r => (r[A], r[B], r[C]))
  implicit def tuple4[A: Parser, B: Parser, C: Parser, D: Parser]            : Parser[(A, B, C, D)]    = new Parser(r => (r[A], r[B], r[C], r[D]))
  implicit def tuple5[A: Parser, B: Parser, C: Parser, D: Parser, E: Parser] : Parser[(A, B, C, D, E)] = new Parser(r => (r[A], r[B], r[C], r[D], r[E]))
}

import java.util.Scanner

object Main{
  def main (args: Array[String]){
    val sc = new Scanner(System.in)
    val n = sc.nextInt()

    var imosM = new Array[Int](370)
    var imosF = new Array[Int](370)

    for(i <- 1 to n){
      val c = sc.next()
      val a = sc.nextInt()
      val b = sc.nextInt()
      if(c == "M"){
        imosM(a) += 1
        imosM(b+1) -= 1
      }
      else{
        imosF(a) += 1
        imosF(b+1) -= 1
      }
    }

    //
    for(i <- 1 to 366){
      imosM(i+1) += imosM(i)
      imosF(i+1) += imosF(i)
    }

    var ans = 0
    for(i <- 1 to 366){
      val tmp = Math.min(imosM(i), imosF(i))
      ans = Math.max(ans, tmp)
    }

    println(ans*2)
  }
}

import java.util.ArrayList
import java.util.StringTokenizer
//import scala.reflect.io.File
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream

object B_343 {   var br = createBufferedReader(); var debugV = false

      //COMMENT ME !
    runTest(Test.sa2)
    debugV = true
//    file = File("C:\\temp\\google cj\\2014q\\c-small.res")

  def main(args: Array[String]): Unit = {
    //---------------------------- parameters reading --------------------------
    val n = readLine.int
    val males, females = new Array[Int](367)
    debug("n = " + n)

    (1 to n).foreach{ x =>
      val line = readLine
      val arr = if (line.string == "M") males else females
      (line.int to line.int).foreach(arr(_) += 1)
    }
    //---------------------------- parameters reading end ----------------------
    val res = (1 to 366).map(i => males(i).min(females(i)) ).max * 2
    outLn(res+"")
    finish
  }

  //============================ service code ======================

//  var file:File = null
  val resultStr = new StringBuilder
  def outLn(str:String) {
    resultStr.append(str).append("\n")
  }
  def finish() {
//    if (file == null) {
      println(resultStr.toString())
//    } else {
//      file.writeAll(resultStr.toString())
//    }
  }

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {
    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);
    new BufferedReader(new InputStreamReader(bis));
  }

  def runTest(str:String) = if (devEnv) {
    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1")))
  }

  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function

  lazy val devEnv = this.getClass.getCanonicalName.contains(".")

//============================================================================================
object Test {

val sa1 = """
4
M 151 307
F 343 352
F 117 145
M 24 128
"""

val sa2 = """
6
M 128 130
F 128 131
F 131 140
F 131 141
M 131 200
M 140 200
"""

}

}

import java.util.ArrayList
import java.util.StringTokenizer
//import scala.reflect.io.File
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream

object B_343 {   var br = createBufferedReader(); var debugV = false

      //COMMENT ME !
    runTest(Test.sa2)
    debugV = true
//    file = File("C:\\temp\\google cj\\2014q\\c-small.res")

  def main(args: Array[String]): Unit = {
    //---------------------------- parameters reading --------------------------
    val n = readLine.int
    val males = new Array[Int](367)
    val females = new Array[Int](367)
    debug("n = " + n)

    (1 to n).foreach{ x =>
      val line = readLine
      val male = line.string == "M"
      val start = line.int
      val end = line.int
      for (i <- start to end) {
        if (male) males(i) += 1
        else females(i) += 1
      }
    }

    //---------------------------- parameters reading end ----------------------
    var res = 0
    for (i <- 1 to 366) {
      val possible = males(i).min(females(i))
      if (res < possible) res = possible
    }
    res = res *2

    outLn(res+"")

    finish
  }

  //============================ service code ======================

//  var file:File = null
  val resultStr = new StringBuilder
  def outLn(str:String) {
    resultStr.append(str).append("\n")
  }
  def finish() {
//    if (file == null) {
      println(resultStr.toString())
//    } else {
//      file.writeAll(resultStr.toString())
//    }
  }

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {
    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);
    new BufferedReader(new InputStreamReader(bis));
  }

  def runTest(str:String) = if (devEnv) {
    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1")))
  }

  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function

  lazy val devEnv = this.getClass.getCanonicalName.contains(".")

//============================================================================================
object Test {

val sa1 = """
4
M 151 307
F 343 352
F 117 145
M 24 128
"""

val sa2 = """
6
M 128 130
F 128 131
F 131 140
F 131 141
M 131 200
M 140 200
"""

}

}

import scala.io.Source

object CF343_B extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt

  val mens = new Array[Int](367)
  val wms = new Array[Int](367)

  for(r <- 0 to n-1) {
      val line = in.next()
      val info = line.split(" ")
      var arr = mens
      if(info(0).equals("W")) {
         arr = wms
      }
      for(idx <- info(1).toInt to info(2).toInt) {
        arr(idx) += 1
      }
  }

  var max = 0

  for(i <- 0 to 366) {
    val cand = mens(i).min(wms(i))
    max = max.max(cand)
  }

println(max)

}

import scala.io.Source

object CF343_B extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt

  val mens = new Array[Int](367)
  val wms = new Array[Int](367)

  for(r <- 0 to n-1) {
      val line = in.next()
      val info = line.split(" ")
      var arr = mens
      if(info(0).equals("W")) {
         arr = wms
      }
      for(idx <- info(1).toInt to info(2).toInt) {
        arr(idx) += 1
      }
  }

  var max = 0

  for(i <- 0 to 366) {
    val cand = mens(i).max(wms(i))
    max = max.max(cand)
  }

println(max)

}


import scala.io.StdIn._

object A extends App {
  for (_ <- 0 until readInt) {
    val n = readInt
    val a = readLine.split(" ").map(_.toInt)
    if (a.count(_ % 2 != 0) == n)
      println("Yes")
    else
      println("No")
  }
}

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

  val t = readInt()

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

    val ans = an.count(_ % 2 == 1) == an.count(_ % 2 == 0)

    ans match {
      case true => println("Yes")
      case _    => println("No")
    }
  }
}


import java.util.Scanner

object CF2 {
  def main(args: Array[String]) {
    val sc = new Scanner(System.in)
    val as = sc.nextLine()
    val bs = sc.nextLine()
    val a = as.toCharArray
    val b = bs.toCharArray
    var b0 = 0L
    var b1 = 0L
    val lengthDiff = b.length - a.length
    for (i <- 0 to lengthDiff)
      if (b(i) == '0') b0 += 1 else b1 += 1
    var sum = 0L
    for (i <- 0 to a.length - 1) {
      if (a(i) == '0') sum += b1 else sum += b0
      if (i != a.length - 1) {
        if (b(i) == '0') b0 -= 1 else b1 -= 1
        if (b(lengthDiff + i + 1) == '0') b0 += 1 else b1 += 1
      }
    }
    System.out.print(sum)
  }
}

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

object B_336 {

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

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

    //---------------------------- parameters reading --------------------------
    br = setupInputOutput();
    val a = br.readLine()
    val b = br.readLine()

    val itN = b.length() - a.length() + 1
    db(itN+"")
    val sums = new Array[Int](b.length())

    var total = 0l

    var curSum = 0
    for (i <- 0 until b.length()) {
      curSum += value(b, i)
      sums(i) = curSum
      db(i + " - " + sums(i))
    }

    for (i <- 0 until a.length()) {
      val vv = value(a, i)
      var dSum = sums(itN-1+i)
      if (i > 0) {
        dSum -= sums(i-1)
      }
      var dif = 0
      if (vv == 0) {
        dif = dSum
      } else {
        dif = itN - dSum
      }
      total += dif
    }

    def value(str:String, ind:Int) = if (str.charAt(ind) == '0') 0 else 1

    println(total)

    //---------------------------- parameters reading end ----------------------

  }

  def readLine() = new Line
  class Line {
    val tok = new StringTokenizer(br.readLine(), " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def hasNext = tok.hasMoreElements()
  }

  var debugV = false
  var is = System.in
  var br = setupInputOutput();
  def db(x: => String) = if (debugV) println(x) // nullary function
  def setupInputOutput(): BufferedReader = {
    val devEnv = this.getClass.getCanonicalName.contains(".")
    if (!devEnv) {
      is = System.in
      debugV = false
    }
    val bis = new BufferedInputStream(is);
    new BufferedReader(new InputStreamReader(bis));
  }

  //============================================================================================
object Test {

val sa1 = """
01
101
"""

val sa2 = """
0
101
"""

val sa3 = """
1
101
"""

}

}

import scala.io.StdIn

/**
  * Created by hsleep on 2016. 1. 8..
  */
object BSolution extends App {
  val a = StdIn.readLine()
  val b = StdIn.readLine()

  def binaryCount(s: String): (Long, Long) = {
    var i, j = 0l
    s.foreach {
      case '0' => i += 1
      case _ => j += 1
    }
    i -> j
  }
  val initialSub = b.take(b.length - a.length + 1)
  val (headIt, nextIt) = (b.iterator, b.substring(initialSub.length).iterator)
  var (count0, count1) = binaryCount(initialSub)

  val listOfDist = {
    for {
      c <- a
    } yield {
      val dist = c match {
        case '0' => count1
        case '1' => count0
      }

      if (nextIt.hasNext) {
        headIt.next() match {
          case '0' => count0 -= 1
          case '1' => count1 -= 1
        }

        nextIt.next() match {
          case '0' => count0 += 1
          case '1' => count1 += 1
        }
      }

      dist
    }
  }

  println(listOfDist.sum)
}

import scala.io.StdIn

/**
  * Created by hsleep on 2016. 1. 8..
  */
object BSolution extends App {
  val a = StdIn.readLine()
  val b = StdIn.readLine()

  def binaryCount(s: String): (Int, Int) = {
    var i, j = 0
    s.foreach {
      case '0' => i += 1
      case _ => j += 1
    }
    i -> j
  }
  val initialSub = b.take(b.length - a.length + 1)
  val (headIt, nextIt) = (b.iterator, b.substring(initialSub.length).iterator)
  var (count0, count1) = binaryCount(initialSub)

  val listOfDist = {
    for {
      c <- a
    } yield {
      val dist = c match {
        case '0' => count1
        case '1' => count0
      }

      if (nextIt.hasNext) {
        headIt.next() match {
          case '0' => count0 -= 1
          case '1' => count1 -= 1
        }

        nextIt.next() match {
          case '0' => count0 += 1
          case '1' => count1 += 1
        }
      }

      dist
    }
  }

  println(listOfDist.sum)
}

import java.util.Scanner

object CF2 {
  def main(args: Array[String]) {
    val sc = new Scanner(System.in)
    val as = sc.nextLine()
    val bs = sc.nextLine()
    val a = as.toCharArray
    val b = bs.toCharArray
    var b0 = 0
    var b1 = 0
    val lengthDiff = b.length - a.length
    for (i <- 0 to lengthDiff)
      if (b(i) == '0') b0 += 1 else b1 += 1
    var sum = 0
    for (i <- 0 to a.length - 1) {
      if (a(i) == '0') sum += b1 else sum += b0
      if (i != a.length - 1) {
        if (b(i) == '0') b0 -= 1 else b1 -= 1
        if (b(lengthDiff + i + 1) == '0') b0 += 1 else b1 += 1
      }
    }
    System.out.print(sum)
  }
}

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

object B_336 {

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

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

    //---------------------------- parameters reading --------------------------
    val a = br.readLine()
    val b = br.readLine()

    val itN = b.length() - a.length() + 1
    db(itN+"")
    val sums = new Array[Int](b.length())

    var total = 0

    var curSum: Integer = 0
    for (i <- 0 until b.length()) {
      curSum += value(b, i)
      sums(i) = curSum
    }

    for (i <-0 until a.length()) {
      val vv = value(a, i)
      var dif = 0
      if (vv == 0) {
        dif = sums(itN-1+i)
      } else {
        dif = itN - sums(itN-1+i)
      }
      total += dif
    }

//    var total = 0l
//    var curSum = 0l
//    val
//
//    for(i <- 0 until itN) {
////      if (i == 0) {
//      curSum = 0
//        for (j <- 0 until a.length()) {
//          val dist = Math.abs(value(a, j) - value(b, j+i))
//          curSum += dist
//        }
//      db("- " + curSum)
////      } else {
////        curSum -= Math.abs(value(a, j) - value(b, j))
////      }
//      total += curSum
//
//    }

    def value(str:String, ind:Int) = if (str.charAt(ind) == '0') 0 else 1

    println(total)

    //---------------------------- parameters reading end ----------------------

  }

  def readLine() = new Line
  class Line {
    val tok = new StringTokenizer(br.readLine(), " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def hasNext = tok.hasMoreElements()
  }

  var debugV = false
  var is = System.in
  val br = setupInputOutput();
  def db(x: => String) = if (debugV) println(x) // nullary function
  def setupInputOutput(): BufferedReader = {
    val devEnv = this.getClass.getCanonicalName.contains(".")
    if (!devEnv) {
      is = System.in
      debugV = false
    }
    val bis = new BufferedInputStream(is);
    new BufferedReader(new InputStreamReader(bis));
  }

  //============================================================================================
object Test {

val sa1 = """

"""

}

}

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

object B_336 {

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

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

    //---------------------------- parameters reading --------------------------
    br = setupInputOutput();
    val a = br.readLine()
    val b = br.readLine()

    val itN = b.length() - a.length() + 1
    db(itN+"")
    val sums = new Array[Int](b.length())

    var total = 0

    var curSum: Integer = 0
    for (i <- 0 until b.length()) {
      curSum += value(b, i)
      sums(i) = curSum
      db(i + " - " + sums(i))
    }

    for (i <-0 until a.length()) {
      val vv = value(a, i)
      var dSum = sums(itN-1+i)
      if (i > 0) {
        dSum -= sums(i-1)
      }
      var dif = 0
      if (vv == 0) {
        dif = dSum
      } else {
        dif = itN - dSum
      }
      total += dif
    }

    def value(str:String, ind:Int) = if (str.charAt(ind) == '0') 0 else 1

    println(total)

    //---------------------------- parameters reading end ----------------------

  }

  def readLine() = new Line
  class Line {
    val tok = new StringTokenizer(br.readLine(), " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def hasNext = tok.hasMoreElements()
  }

  var debugV = false
  var is = System.in
  var br = setupInputOutput();
  def db(x: => String) = if (debugV) println(x) // nullary function
  def setupInputOutput(): BufferedReader = {
    val devEnv = this.getClass.getCanonicalName.contains(".")
    if (!devEnv) {
      is = System.in
      debugV = false
    }
    val bis = new BufferedInputStream(is);
    new BufferedReader(new InputStreamReader(bis));
  }

  //============================================================================================
object Test {

val sa1 = """
01
101
"""

val sa2 = """
0
101
"""

val sa3 = """
1
101
"""

}

}


object CodeforcesRound1392A {

  import java.io.{BufferedReader, PrintStream}

  import scala.io.Source

  def main(args: Array[String]): Unit = {
    exec(Source.stdin.bufferedReader, System.out)
  }

  def exec(implicit
           reader: BufferedReader,
           writer: PrintStream): Unit = {
    val t: Int = rl_int
    (1 to t).foreach(_ => test())
  }

  def test()
          (implicit
           reader: BufferedReader,
           writer: PrintStream): Unit = {
    val n = rl_int
    val a = rll_int
    val allAreEqual = a.forall(_ == a(0))
    val res = if (allAreEqual) n else 1
    writer.println(res)
  }

  def rl(implicit reader: BufferedReader): String = reader.readLine
  def rll(implicit reader: BufferedReader): Array[String] = reader.readLine.split(' ')

  def rl_bool(implicit reader: BufferedReader): Boolean = rl.toBoolean
  def rl_byte(implicit reader: BufferedReader): Byte = rl.toByte
  def rl_short(implicit reader: BufferedReader): Short = rl.toShort
  def rl_int(implicit reader: BufferedReader): Int = rl.toInt
  def rl_long(implicit reader: BufferedReader): Long = rl.toLong
  def rl_float(implicit reader: BufferedReader): Float = rl.toFloat
  def rl_double(implicit reader: BufferedReader): Double = rl.toDouble

  def rll_bool(implicit reader: BufferedReader): Array[Boolean] = rll.map(_.toBoolean)
  def rll_byte(implicit reader: BufferedReader): Array[Byte] = rll.map(_.toByte)
  def rll_short(implicit reader: BufferedReader): Array[Short] = rll.map(_.toShort)
  def rll_int(implicit reader: BufferedReader): Array[Int] = rll.map(_.toInt)
  def rll_long(implicit reader: BufferedReader): Array[Long] = rll.map(_.toLong)
  def rll_float(implicit reader: BufferedReader): Array[Float] = rll.map(_.toFloat)
  def rll_double(implicit reader: BufferedReader): Array[Double] = rll.map(_.toDouble)

}

object A {
  import InOut._
  def main(args: Array[String]): Unit = {

    for (_ <- 1 to nextInt) {
      val n = nextInt
      val as = nextInts(n)
      val d = as.distinct.size
      val res = if (d == 1) n else 1

      out.println(res)
    }

    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 CodeforcesRound1392A {

  import java.io.{BufferedReader, PrintStream}

  import scala.io.Source

  def main(args: Array[String]): Unit = {
    exec(Source.stdin.bufferedReader, System.out)
  }

  def exec(implicit
           reader: BufferedReader,
           writer: PrintStream): Unit = {
    val t: Int = rl_int
    (1 to t).foreach(_ => test())
  }

  def test()
          (implicit
           reader: BufferedReader,
           writer: PrintStream): Unit = {
    val n = rl_int
    val a = rll_int
    val res = if (n == 2 && a(0) == a(1)) 2 else 1
    writer.println(res)
  }

  def rl(implicit reader: BufferedReader): String = reader.readLine
  def rll(implicit reader: BufferedReader): Array[String] = reader.readLine.split(' ')

  def rl_bool(implicit reader: BufferedReader): Boolean = rl.toBoolean
  def rl_byte(implicit reader: BufferedReader): Byte = rl.toByte
  def rl_short(implicit reader: BufferedReader): Short = rl.toShort
  def rl_int(implicit reader: BufferedReader): Int = rl.toInt
  def rl_long(implicit reader: BufferedReader): Long = rl.toLong
  def rl_float(implicit reader: BufferedReader): Float = rl.toFloat
  def rl_double(implicit reader: BufferedReader): Double = rl.toDouble

  def rll_bool(implicit reader: BufferedReader): Array[Boolean] = rll.map(_.toBoolean)
  def rll_byte(implicit reader: BufferedReader): Array[Byte] = rll.map(_.toByte)
  def rll_short(implicit reader: BufferedReader): Array[Short] = rll.map(_.toShort)
  def rll_int(implicit reader: BufferedReader): Array[Int] = rll.map(_.toInt)
  def rll_long(implicit reader: BufferedReader): Array[Long] = rll.map(_.toLong)
  def rll_float(implicit reader: BufferedReader): Array[Float] = rll.map(_.toFloat)
  def rll_double(implicit reader: BufferedReader): Array[Double] = rll.map(_.toDouble)

}


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

object Towers {
  def main(args: Array[String]): Unit = {
    val inputStream = System.in
    val outputStream = System.out
    val in = new InputReader(inputStream)
    val out = new PrintWriter(outputStream)
    val solver = new Task()
    solver.solve(in, out)
    out.close()
  }

  class Task {
    def solve(in: InputReader, out: PrintWriter): Unit = {
      val n = in.nextInt()
      val a = Array.ofDim[Int](n)
      for (i <- 0 until n) a(i) = in.nextInt()
      val group = a.groupBy(x => x).values
      out.println(group.maxBy(x => x.length).length + " " + group.size)
    }
  }

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

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens) {
        try {
          tokenizer = new StringTokenizer(reader.readLine())
        } catch {
          case _: IOException => throw new RuntimeException
        }
      }
      tokenizer.nextToken()
    }

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

}

object Main
{
	def sort(xs: Array[Int]): Array[Int] =
	  if (xs.length <= 1) xs
	  else {
		val pivot = xs(xs.length / 2)
		Array.concat(
		  sort(xs filter (pivot >)),
			   xs filter (pivot ==),
		  sort(xs filter (pivot <)))
	  }

	def main(args:Array[String])
	{
		readLine;
		val a1 = sort(readLine.split(" ").map(i => i.toInt)).toList;
		val counts = sort((1 to 1000).map(i => a1.count(j => i == j )).toArray).toList;
		println(counts.last + " " + counts.count(i => i > 0))
	}
}

object A37 {
  @inline def read = scala.io.StdIn.readLine

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

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

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

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val input = readInts(n)

    val max = input.groupBy(identity).mapValues(_.length).maxBy(_._2)._2

    val diff = input.toSet.size

    println(s"$max $diff")
  }
}

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

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

  val N = sc.nextInt
  val bars = List.fill(N)(sc.nextInt).groupBy(identity[Int])
  val highest = bars.map(_._2.length).max
  val towers = bars.size

  out.println(List(highest, towers).mkString(" "))
  out.close
}

import java.io._
import scala.annotation.tailrec

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

  reader.readLine()
  val ans = readInts.groupBy(x => x).values.map(_.size)

  def main(a: Array[String]) {
    println(ans.max + " " + ans.size)
  }
}

object Main {
  def main(args: Array[String]) {
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val map = scala.collection.mutable.Map[Int, Int]()
    a.foreach(n => map(n) = map.getOrElse(n, 0) + 1)
    println(map.values.max + " " + map.size)
  }
}

object Andrei {
  def main (args : Array[String]) {
    val n = readInt
    var A = readLine().split(" ").map(_.toInt)

    val w = A.distinct
    val T = w.map(x => A.count(_ == x))
    println(T.max + " " + w.size)

  }

}

object Andrei {
  def main (args : Array[String]) {
    val n = readInt
    val A = readLine().split(" ").map(_.toInt)

    def swap(a : Int, b : Int) {
      val temp = A(a)
      A(a) = A(b)
      A(b) = temp
    }

    for(i <- 0 until n)
      for(j <- i until n)
        if(A(i) > A(j))
          swap(i, j)

    val w = A.distinct
    val T = w.map(x => A.count(_ == x))
    println(T.max + " " + w.size)

  }

}

object Andrei {
  class Heap {
    private type Node = Heap.Node
    private def Node(rank : Int, datum : Int, left : Node, right : Node) = new Node(rank, datum, left, right)
    private var root : Node = null

    private def mergeHeaps(a : Node, b : Node) : Node = {
      if(a == null) return b
      if(b == null) return a

      //keep the minimum up
      var x = a
      var y = b
      if(x.datum > y.datum) {
        val temp = x
        x = y
        y = temp
      }

      // completing the right part
      x.right = mergeHeaps(x.right, y)

      //keeping the balance
      if(x.left == null) {
        //left child doesn't exist we will therefore swap the 2
        x.left = x.right
        x.right = null
        x.rank = 1
      }
      else {
        //left child does exist, we therefore compare the 2 ranks
        if(x.left.rank < x.right.rank) {
          //we need to swap
          val temp = x.left
          x.left = x.right
          x.right = temp
        }
        x.rank = x.right.rank + 1
      }
      x
    }

    private def out(x : Node, level : Int) : Unit  = {
      if(x != null) {
        for(i <- 1 to level) print (" " )

        println(x.datum)
        if(x.left != null) {
          for(i <- 1 to level) print (" " )
          println("left")
          out(x.left, level + 1)
        }
        if(x.right != null) {
          println("right")
          for(i <- 1 to level) print (" " )
          out(x.right, level + 1)
        }
      }
    }

    def myprint = out(root, 0)

    def insert(x : Int) {
      root = mergeHeaps(root, Node(1, x, null, null))
    }

    def getMin : Int = {
      val min = root.datum
      root = mergeHeaps(root.right, root.left)
      min
    }
  }

  object Heap {
    private class Node(var rank : Int, var datum : Int, var left : Node, var right : Node)

    def apply(a : Array[Int]) = {
      val h = new Heap;
      a.foreach(h.insert(_))
      h
    }
  }

  def main (args : Array[String]) {
    val n = readInt
    val A = readLine().split(" ").map(_.toInt)

    val H = Heap(A)

    for(i <- 0 until n) A(i) = H.getMin

    var cnt = 1
    var nr = 1
    var max = 1
    for(i <- 1 until n)
      if(A(i - 1) != A(i)) {
        if(max < cnt) max = cnt
        cnt = 1
        nr += 1
      }
      else cnt += 1
    if(cnt > max) max = cnt
    println(max + " " + nr)

  }

}

object Andrei {
  class Heap {
    private type Node = Heap.Node
    private def Node(rank : Int, datum : Int, left : Node, right : Node) = new Node(rank, datum, left, right)
    private var root : Node = null

    private def mergeHeaps(a : Node, b : Node) : Node = {
      if(a == null) return b
      if(b == null) return a

      //keep the minimum up
      var x = a
      var y = b
      if(x.datum > y.datum) {
        val temp = x
        x = y
        y = temp
      }

      // completing the right part
      x.right = mergeHeaps(x.right, y)

      //keeping the balance
      if(x.left == null) {
        //left child doesn't exist we will therefore swap the 2
        x.left = x.right
        x.right = null
        x.rank = 1
      }
      else {
        //left child does exist, we therefore compare the 2 ranks
        if(x.left.rank < x.right.rank) {
          //we need to swap
          val temp = x.left
          x.left = x.right
          x.right = temp
        }
        x.rank = x.right.rank + 1
      }
      x
    }

    private def out(x : Node, level : Int) : Unit  = {
      if(x != null) {
        for(i <- 1 to level) print (" " )

        println(x.datum)
        if(x.left != null) {
          for(i <- 1 to level) print (" " )
          println("left")
          out(x.left, level + 1)
        }
        if(x.right != null) {
          println("right")
          for(i <- 1 to level) print (" " )
          out(x.right, level + 1)
        }
      }
    }

    def myprint = out(root, 0)

    def insert(x : Int) {
      root = mergeHeaps(root, Node(1, x, null, null))
    }

    def getMin : Int = {
      val min = root.datum
      root = mergeHeaps(root.right, root.left)
      min
    }
  }

  object Heap {
    private class Node(var rank : Int, var datum : Int, var left : Node, var right : Node)

    def apply(a : Array[Int]) = {
      val h = new Heap;
      a.foreach(h.insert(_))
      h
    }
  }

  def main (args : Array[String]) {
    val n = readInt
    val A = readLine().split(" ").map(_.toInt)

    val H = Heap(A)

    for(i <- 0 until n) A(i) = H.getMin

   val w = A.distinct
    val T = w.map(x => A.count(_ == x))
    println(T.max + " " + w.size)

  }
}

object Andrei {
  def main (args : Array[String]) {
    val n = readInt
    var A = readLine().split(" ").map(_.toInt)

    A = A.sortBy(x => x)
    var cnt = 1
    var nr = 1
    var max = 1
    for(i <- 1 until n)
      if(A(i - 1) != A(i)) {
        if(max < cnt) max = cnt
        cnt = 1
        nr += 1
      }
      else cnt += 1
    if(cnt > max) max = cnt
    println(max + " " + nr)

  }

}

object P037A extends App {
  val n = readInt
  val a = readLine.split(' ').map(_.toInt)
  val b = a.groupBy(identity).map(x => (x._1, x._2.size))
  printf("%d %d\n", b.maxBy(x => x._2)._2, b.size)
}

import java.util.Scanner
object Towers {

  val scanner = new Scanner(System.in)
  def main(args: Array[String]): Unit = {
    val c = scanner.nextInt();
    val res = ((1 to c) map {i => scanner.nextInt()});
    var count = res.map(a => res.count(x => x==a));
    print((Int.MinValue/: res) {(m:Int,c:Int)=> m max(res.count(a => a == c))})
    print(" ")
    var filtered = res.toSet
    println(filtered.size)
  }

}

import java.util.StringTokenizer

object _37A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val a = (1 to n).map(i => next.toInt).groupBy(i => i)
  println("%d %d".format(a.map(g => g._2.length).max, a.size))
}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  in.next()
  val data = in.next().split(" ").groupBy(t => t)

  println(data.maxBy(t => t._2.length)._2.length + " " + data.size)
}

object Main
{
	def sort(xs: Array[Int]): Array[Int] =
	  if (xs.length <= 1) xs
	  else {
		val pivot = xs(xs.length / 2)
		Array.concat(
		  sort(xs filter (pivot >)),
			   xs filter (pivot ==),
		  sort(xs filter (pivot <)))
	  }

	def main(args:Array[String])
	{
		readLine;
		val a1 = sort(readLine.split(" ").map(i => i.toInt)).toList;
		val counts = sort((1 to 1000).map(i => a1.count(j => i == j )).toArray).toList;
		println(counts.count(i => i > 0) + " " + counts.last)
	}
}

object Main
{
	def sort(xs: Array[Int]): Array[Int] =
	  if (xs.length <= 1) xs
	  else {
		val pivot = xs(xs.length / 2)
		Array.concat(
		  sort(xs filter (pivot >)),
			   xs filter (pivot ==),
		  sort(xs filter (pivot <)))
	  }

	def main(args:Array[String])
	{
		val a1 = sort(readLine.split(" ").map(i => i.toInt)).toList;
		val counts = sort((1 to 1000).map(i => a1.count(j => i == j )).toArray).toList;
		println(counts.count(i => i > 0) + " " + counts.last)
	}
}

object Andrei {
  def main (args : Array[String]) {
    val n = readInt
    var A = readLine().split(" ").map(_.toInt)

    A = A.sortBy(x => x)
    A.foreach(println(_))
    var cnt = 1
    var nr = 1
    var max = 1
    for(i <- 1 until n)
      if(A(i - 1) != A(i)) {
        if(max < cnt) max = cnt
        cnt = 1
        nr += 1
      }
      else cnt += 1

    println(max + " " + nr)

  }

}

object Andrei {
  def main (args : Array[String]) {
    val n = readInt
    var A = readLine().split(" ").map(_.toInt)

    A = A.sortBy(x => x)
    var cnt = 1
    var nr = 1
    var max = 1
    for(i <- 1 until n)
      if(A(i - 1) != A(i)) {
        if(max < cnt) max = cnt
        cnt = 1
        nr += 1
      }
      else cnt += 1

    println(max + " " + nr)

  }

}


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

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

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

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

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

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

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

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

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

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

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

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

  def solve(): Unit = {
    val H, L = ni()
    val a = (H.toDouble * H + L.toDouble * L) / 2 / H
    out.println(f"${a-H}%.13f")
  }
}

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

  override def apply(io: IO): io.type = {
    val h, l = io.read[Long]
    val a = (l*l - h*h)/(2.0 * h)
    io.write(a)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
/***********************************[Scala I/O]*********************************************/
import java.io._, java.util.StringTokenizer
import scala.collection.generic.CanBuild

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

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

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

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

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

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

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

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

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

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


import java.util.Scanner

object MainC extends App {
  val sc = new Scanner(System.in)

  val N = sc.nextInt
  val arr = for (i <- 0 until N) yield sc.nextInt
  if (arr.forall(1 ==)) {
    print(List.make(arr.size - 1, 1).mkString(" "))
    if(arr.size != 1) print(" ")
    println(2)
  } else {
    val vmax = arr.max
    val after = arr.updated(arr.indexOf(vmax), 1).sorted
    println(after.mkString(" "))
  }
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(' ').map(_.toInt)
  val max = data.max
  if (max == 1)
    data(data.length - 1) = 2
  else {
    val index = data.indexOf(max)
    data(index) = 1
  }
  println(data.sorted.mkString(" "))
}

object Main {

    def main(args: Array[String]) {
        val n = nextInt()
        val a = (for (i <- 0 until n) yield nextInt()).toList.sorted
        val s = if (a.last == 1) ((a.init):::List(2)) else 1 :: a.init
        println(s.mkString(" "))
    }

    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
    var st = new java.util.StringTokenizer("");

    def next() = {
        while (!st.hasMoreTokens())
            st = new java.util.StringTokenizer(in.readLine());
        st.nextToken();
    }

    def nextInt() = java.lang.Integer.parseInt(next());
    def nextDouble() = java.lang.Double.parseDouble(next());
    def nextLong() = java.lang.Long.parseLong(next());
}

/**
 * @author pvasilyev
 * @since 29 Jun 2016
 */
object A135 extends App {

  def solve() = {
    val n: Int = scala.io.StdIn.readInt()
    val a: Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt).sorted

    if (n == 1) {
      if (a(0) == 1) {
        println("2")
      } else {
        println("1")
      }
    } else {
      val buf = new StringBuilder
      if (a(0) != 1) {
        for (i <- 0 until n) {
          if (i == 0) {
            buf ++= "1 "
          } else {
            buf ++= (a(i - 1) + " ")
          }
        }
      } else {
        for (i <- 0 until n) {
          if (i == 0) {
            buf ++= "1 "
          } else if (a(i) == 1) {
            if (i < n - 1 && a(i + 1) == 1) {
              buf ++= "1 "
            } else if (i < n - 1 && a(i + 1) != 1) {
              buf ++= "1 "
            } else {
              buf ++= "2 "
            }
          } else {
            buf ++= (a(i - 1) + " ")
          }
        }
      }
      println(buf.toString())
    }

  }

  solve()

}

import scala.util.Sorting
object Main {
  def printArr(a: Array[Int], end: Int) {
    for (i <- 0 to end) {
      if (i != 0)
        print(" ")
      print(a(i))
    }
  }
  def main(args: Array[String]) {
    val n = readInt()
    val a = readLine().split(' ').map(_.toInt)
    Sorting.quickSort(a)
    if (a.last == 1) {
      a(a.length-1) = 2
      printArr(a, a.length - 1)
    }
    else {
      print("1 ")
      printArr(a, a.length - 2)
    }
  }
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(' ').map(_.toInt)
  val max = data.max
  val index = data.indexOf(max)
  data(index) = 1
  println(data.sorted.mkString(" "))
}

import java.util.Scanner

object MainC extends App {
  val sc = new Scanner(System.in)

  val N = sc.nextInt
  val arr = for(i <- 0 until N) yield sc.nextInt

  val vmax = arr.max
  val after = arr.updated(arr.indexOf(vmax), 1).sorted
  println(after.mkString(" "))
}


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

object B {

  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 a = nextLong
    val b = nextLong
    val c = nextLong
    if (a == 0 && b == 0 && c == 0) {
      out.println(-1)
      return 1
    }
    if (a == 0 && b == 0) {
      out.println(0)
      return 1
    }
    if (a == 0) {
      out.println(1)
      out.println((1.0d * (-c)) / b)
      return 1
    }
    val d = b * b - 4L * a * c
    if (d < 0) {
      out.println(0)
      return 1
    }
    if (d == 0) {
      out.println(1)
      out.println((1.0d * (-b)) / (2.0d * a))
      return 1
    }
    out.println(2)
    out.println(Math.min( ((1.0d * (-b)) - Math.sqrt(d) )/ (2.0d * a), ((1.0d * (-b)) + Math.sqrt(d) )/ (2.0d * a)))
    out.println(Math.max( ((1.0d * (-b)) - Math.sqrt(d) )/ (2.0d * a), ((1.0d * (-b)) + Math.sqrt(d) )/ (2.0d * a)))
    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
  }
}

object P020B extends App {
  def solve(a: List[Long]): Tuple3[Int, Any, Any] = {
    val det = a(1)*a(1) - 4*a(0)*a(2)
    if (det < 0) return new Tuple3(0, Unit, Unit);
    val x1 = -0.5*a(1)/a(0)
    if (det == 0) return new Tuple3(1, x1, Unit);
    val x2 = 0.5*math.sqrt(det)/a(0)
    return new Tuple3(2, x1-x2, x1+x2)
  }

  var a = readLine.split(' ').map(_.toLong).toList
  if (a(0) < 0) a = a.map(-_)
  val result = a match {
    case List(0, 0, 0) => (-1, Unit, Unit)
    case 0::0::tail => (0, Unit, Unit)
    case 0::tail => (1, -1.0*a(2)/a(1), Unit)
    case _ => solve(a)
  }
  println(result._1)
  if (result._1 >= 1) printf("%.8f\n", result._2);
  if (result._1 >= 2) printf("%.8f\n", result._3);
}

object P020B extends App {
  def solve(a: List[Int]): Tuple3[Int, Any, Any] = {
    val det = a(1)*a(1) - 4*a(0)*a(2)
    if (det < 0) return new Tuple3(0, Unit, Unit);
    val x1 = -0.5*a(1)/a(0)
    if (det == 0) return new Tuple3(1, x1, Unit);
    val x2 = 0.5*math.sqrt(det)/a(0)
    return new Tuple3(2, x1-x2, x1+x2)
  }

  val a = readLine.split(' ').map(_.toInt).toList
  val result = a match {
    case List(0, 0, 0) => (-1, Unit, Unit)
    case 0::0::tail => (0, Unit, Unit)
    case 0::tail => (1, -1.0*a(2)/a(1), Unit)
    case _ => solve(a)
  }
  println(result._1)
  if (result._1 >= 1) printf("%.8f\n", result._2);
  if (result._1 >= 2) printf("%.8f\n", result._3);
}

object P020B extends App {
  def solve(a: List[Long]): Tuple3[Int, Any, Any] = {
    val det = a(1)*a(1) - 4*a(0)*a(2)
    if (det < 0) return new Tuple3(0, Unit, Unit);
    val x1 = -0.5*a(1)/a(0)
    if (det == 0) return new Tuple3(1, x1, Unit);
    val x2 = 0.5*math.sqrt(det)/a(0)
    return new Tuple3(2, x1-x2, x1+x2)
  }

  val a = readLine.split(' ').map(_.toLong).toList
  val result = a match {
    case List(0, 0, 0) => (-1, Unit, Unit)
    case 0::0::tail => (0, Unit, Unit)
    case 0::tail => (1, -1.0*a(2)/a(1), Unit)
    case _ => solve(a)
  }
  println(result._1)
  if (result._1 >= 1) printf("%.8f\n", result._2);
  if (result._1 >= 2) printf("%.8f\n", result._3);
}

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

object B {

  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 a = nextLong
    val b = nextLong
    val c = nextLong
    if (a == 0 && b == 0 && c == 0) {
      out.println(-1)
      return 1
    }
    if (a == 0 && b == 0) {
      out.println(0)
      return 1
    }
    if (a == 0) {
      out.println(1)
      out.println((1.0d * (-c)) / b)
      return 1
    }
    val d = b * b - 4L * a * c
    if (d < 0) {
      out.println(0)
      return 1
    }
    if (d == 0) {
      out.println(1)
      out.println((1.0d * (-b)) / (2.0d * a))
      return 1
    }
    out.println(2)
    out.println(((1.0d * (-b)) - Math.sqrt(d) )/ (2.0d * a))
    out.println(((1.0d * (-b)) + Math.sqrt(d) )/ (2.0d * a))
    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
  }
}


object Solution extends App {

  def solution(n: Long, k: Long, d1: Long, d2: Long, first: Long, second: Long, third: Long): Boolean = {
    val shouldWin = n / 3
    val unknown = (k - d1 + d2) % 3
    if (unknown != 0 || first < 0 || second < 0 || third < 0 || first > k
      || second > k || third > k || n % 3 != 0
      || first > shouldWin || second > shouldWin || third > shouldWin)
      return false
    return true
  }

//  for (int sign1 = -1; sign1 <= 1; sign1++) {
//    for (int sign2 = -1; sign2 <= 1; sign2++) {
//      if (sign1 == 0 || sign2 == 0) {
//        continue;
//      }
//      LL D1 = d1 * sign1;
//      LL D2 = d2 * sign2;
//
//      LL x2 = (k - D1 + D2) / 3;
//      if ((k - D1 + D2) % 3 != 0) {
//        continue;
//      }
//      if (x2 >= 0 && x2 <= k) {
//        LL x1 = D1 + x2;
//        LL x3 = x2 - D2;
//        if (x1 >= 0 && x1 <= k && x3 >= 0 && x3 <= k) {
//          if (x1 <= n / 3 && x2 <= n / 3 && x3 <= n / 3) {
//            assert(abs(x1 - x2) == d1);
//            assert(abs(x2 - x3) == d2);
//            return true;
//          }
//        }
//      }
//    }
//  }

  def solve(n: Long, k: Long, d1: Long, d2: Long): Boolean = {
    if (n % 3 != 0)
      return false

    (-1 to 1).foreach { sign1 =>
      if (sign1 != 0)
        (-1 to 1).foreach { sign2 =>
          if (sign2 != 0) {
            val D1 = d1 * sign1
            val D2 = d2 * sign2

            val x2 = (k - D1 + D2) / 3
            if ((k - D1 + D2) % 3 == 0 && x2 >= 0 && x2 <= k) {
              val x1 = D1 + x2
              val x3 = x2 - D2
              if (x1 >= 0 && x1 <= k && x3 >= 0 && x3 <= k) {
                if (x1 <= n / 3 && x2 <= n / 3 && x3 <= n / 3) {
                  if (Math.abs(x1 - x2) == d1 && Math.abs(x2 - x3) == d2)
                    return true
                }
              }
            }
          }
      }
    }

    false
  }

  val in = scala.io.Source.stdin.getLines()
  val t = in.next().toInt
  val res = (1 to t).map { _ =>
    val Array(n, k, d1, d2) = in.next().split(' ').map(_.toLong)
    if (solve(n, k, d1, d2)) "yes" else "no"
  }
  println(res.mkString("\n"))
}

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

/**
 * Created by arseny on 24.07.14.
 */
object C extends App {
  val home = true
  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 t = nextInt
    for (i <- 0 until t) {
      val n = nextLong
      val k = nextLong
      val d1 = nextLong
      val d2 = nextLong

      def getPossiblePoints(): List[(Long, Long, Long)] = {
        val x1 = k - d2 - 2 * d1
        val x2 = k + d2 - 2 * d1
        val x3 = k - d2 + 2 * d1
        val x4 = k + d2 + 2 * d1
        var ans = List((-1.toLong, -1.toLong, -1.toLong))
        if (x1 >= 0 && x1 % 3 == 0) {
          val y1 = x1 / 3
          ans = (y1, y1 + d1, y1 + d1 + d2) :: ans
        }
        if (x2 >= 0 && x2 % 3 == 0) {
          val y2 = x2 / 3
          if (y2 + d1 - d2 >= 0) {
            ans = (y2, y2 + d1, y2 + d1 - d2) :: ans
          }
        }
        if (x3 >= 0 && x3 % 3 == 0) {
          val y3 = x3 / 3
          if (y3 - d1 >= 0) {
            ans = (y3, y3 - d1, y3 - d1 + d2) :: ans
          }
        }
        if (x4 >= 0 && x4 % 3 == 0) {
          val y4 = x4 / 3
          if (y4 - d1 - d2 >= 0) {
            ans = (y4, y4 - d1, y4 - d1 - d2) :: ans
          }
        }
        ans.init
      }
      val can = getPossiblePoints()
      val left = n - k
      var g = true
      //out.println(can)
      for (c <- can if g) {
        if ((left + c._1 + c._2 + c._3) % 3 == 0) {
          val z = (left + c._1 + c._2 + c._3) / 3
          if (z >= c._1 && z >= c._2 && z >= c._3 && z >= 0) {
            g = false
          }
        }
      }
      if (!g) {
        out.println("yes")
      } else {
        out.println("no")
      }
    }
  }

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

object Solution extends App {

  def solution(n: Long, k: Long, d1: Long, d2: Long, first: Long, second: Long, third: Long): Boolean = {
    val shouldWin = n / 3
    val unknown = (k - d1 + d2) % 3
    if (unknown != 0 || first < 0 || second < 0 || third < 0 || first > k
      || second > k || third > k || n % 3 != 0
      || first > shouldWin || second > shouldWin || third > shouldWin)
      return false
    return true
  }

//  for (int sign1 = -1; sign1 <= 1; sign1++) {
//    for (int sign2 = -1; sign2 <= 1; sign2++) {
//      if (sign1 == 0 || sign2 == 0) {
//        continue;
//      }
//      LL D1 = d1 * sign1;
//      LL D2 = d2 * sign2;
//
//      LL x2 = (k - D1 + D2) / 3;
//      if ((k - D1 + D2) % 3 != 0) {
//        continue;
//      }
//      if (x2 >= 0 && x2 <= k) {
//        LL x1 = D1 + x2;
//        LL x3 = x2 - D2;
//        if (x1 >= 0 && x1 <= k && x3 >= 0 && x3 <= k) {
//          if (x1 <= n / 3 && x2 <= n / 3 && x3 <= n / 3) {
//            assert(abs(x1 - x2) == d1);
//            assert(abs(x2 - x3) == d2);
//            return true;
//          }
//        }
//      }
//    }
//  }

  def solve(n: Long, k: Long, d1: Long, d2: Long) = {
    val s = List((d1, 0l, d2), (0l, d1, d1 + d2), (0l, d1, d1 - d2), (d2 - d1, d2, 0l), (d1 + d2, d2, 0l)).find{
      case (f, s, t1) => solution(n, k, d1, d2, f, s, t1)
    }
//    println(s)
    s.nonEmpty
  }

  val in = scala.io.Source.stdin.getLines()
  val t = in.next().toInt
  val res = (1 to t).map { _ =>
    val Array(n, k, d1, d2) = in.next().split(' ').map(_.toLong)
    if (solve(n, k, d1, d2)) "yes" else "no"
  }
  println(res.mkString("\n"))
}

object Solution extends App {

  def solution(n: Long, k: Long, d1: Long, d2: Long, first: Long, second: Long, third: Long): Boolean = {
    val shouldWin = n / 3
    val unknown = (k - d1 + d2) % 3
    if (unknown != 0 || first < 0 || second < 0 || third < 0 || first > k
      || second > k || third > k || n % 3 != 0
      || first > shouldWin || second > shouldWin || third > shouldWin)
      return false
    return true
  }

//  for (int sign1 = -1; sign1 <= 1; sign1++) {
//    for (int sign2 = -1; sign2 <= 1; sign2++) {
//      if (sign1 == 0 || sign2 == 0) {
//        continue;
//      }
//      LL D1 = d1 * sign1;
//      LL D2 = d2 * sign2;
//
//      LL x2 = (k - D1 + D2) / 3;
//      if ((k - D1 + D2) % 3 != 0) {
//        continue;
//      }
//      if (x2 >= 0 && x2 <= k) {
//        LL x1 = D1 + x2;
//        LL x3 = x2 - D2;
//        if (x1 >= 0 && x1 <= k && x3 >= 0 && x3 <= k) {
//          if (x1 <= n / 3 && x2 <= n / 3 && x3 <= n / 3) {
//            assert(abs(x1 - x2) == d1);
//            assert(abs(x2 - x3) == d2);
//            return true;
//          }
//        }
//      }
//    }
//  }

  def solve(n: Long, k: Long, d1: Long, d2: Long): Boolean = {
    if (n % 3 != 0)
      return false

    (-1 to 1).foreach { sign1 =>
      if (sign1 != 0)
        (-1 to 1).foreach { sign2 =>
          if (sign2 == 0) {
            val D1 = d1 * sign1
            val D2 = d2 * sign2

            val x2 = (k - D1 + D2) / 3
            if ((k - D1 + D2) % 3 == 0 && x2 >= 0 && x2 <= k) {
              val x1 = D1 + x2
              val x3 = x2 - D2
              if (x1 >= 0 && x1 <= k && x3 >= 0 && x3 <= k) {
                if (x1 <= n / 3 && x2 <= n / 3 && x3 <= n / 3) {
                  if (Math.abs(x1 - x2) == d1 && Math.abs(x2 - x3) == d2)
                    return true
                }
              }
            }
          }
      }
    }

    false
  }

  val in = scala.io.Source.stdin.getLines()
  val t = in.next().toInt
  val res = (1 to t).map { _ =>
    val Array(n, k, d1, d2) = in.next().split(' ').map(_.toLong)
    if (solve(n, k, d1, d2)) "yes" else "no"
  }
  println(res.mkString("\n"))
}

object Solution extends App {

  def solution(n: Long, k: Long, d1: Long, d2: Long, first: Long, second: Long, third: Long): Boolean = {
    val shouldWin = n / 3
    if (first < 0 || second < 0 || third < 0 || first > k
      || second > k || third > k || n % 3 != 0
      || first > shouldWin || second > shouldWin || third > shouldWin)
      return false
    return true
  }

  def solve(n: Long, k: Long, d1: Long, d2: Long) = {
    val s = List((d1, 0l, d2), (0l, d1, d1 + d2), (0l, d1, d1 - d2), (d2 - d1, d2, 0l), (d1 + d2, d2, 0l)).find{
      case (f, s, t1) => solution(n, k, d1, d2, f, s, t1)
    }
//    println(s)
    s.nonEmpty
  }

  val in = scala.io.Source.stdin.getLines()
  val t = in.next().toInt
  val res = (1 to t).map { _ =>
    val Array(n, k, d1, d2) = in.next().split(' ').map(_.toLong)
    if (solve(n, k, d1, d2)) "yes" else "no"
  }
  println(res.mkString("\n"))
}


import java.util.Scanner
import java.io.PrintWriter
import java.util.Arrays.binarySearch
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.collection.mutable.ArrayBuffer
import scala.collection.immutable.TreeSet
import scala.util.Random
import scala.util.control.Breaks._

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

  val res = List.fill(sc.nextInt)(sc.nextInt).groupBy(identity).values.map(_.size / 2).sum / 2

  out.println(res)
  out.close
}

object Main {
  def main(args: Array[String]) = {
    val n = readInt()
    val a = readLine() split(" ") map(_.toInt)
    val map = scala.collection.mutable.Map[Int, Int]()
    a.foreach(i => map(i) = map.getOrElse(i, 0) + 1)
    val count = map.values.map(_ / 2).sum / 2
    println(count)
  }
}

object Flask {

  def main(args: Array[String]): Unit = {
    readLine
    var input = readLine.split(" ").map(_.toInt)
    var index: Map[Int, Int] = Map[Int, Int]()

    for (x <- input) {
      if (index.contains(x))
        index += (x -> (index(x) + 1))
      else
        index += (x -> 1)
    }

    var total = index.keys.foldLeft(0)((res, x) => res + index(x) / 2) / 2
    println(total)
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  println(in.next().split(' ').map(_.toInt).groupBy(x => x).map(_._2.length / 2).sum / 2)
}

import java.io._
import java.util.Locale
import scala.annotation.tailrec

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

  readInt
  def ans = readInts.groupBy(x => x).values.map(_.size / 2).sum / 2

  def main(a: Array[String]) {
    println(ans)
  }
}


import scala.io.StdIn._

object B_1206 extends App {
  val n = readInt()
  val A = readLine().split(" ").map(_.toInt)

  var value = 0L
  var pos = 0
  var neg = 0

  for (i <- 0 until n) {
    A(i) = if (A(i) > 0) {
      value += A(i) - 1
      pos += 1
      1
    } else if (A(i) < 0) {
      value += -A(i) - 1
      neg += 1
      -1
    } else {
      0
    }
  }

  val zeroes = n - pos - neg
  if (zeroes == 0) {
    if (neg % 2 == 1) value += 2
  } else {
    value += zeroes
  }

  println(value)
}

import scala.annotation.tailrec
import scala.collection.immutable
import scala.io.StdIn._
object Main extends App {
  val n = readInt
  val numbers = readLine.trim.split(' ').map(_.toLong)
  val (positive, negative) = numbers.partition(_ >= 0)
  val zero = numbers.filter(_ == 0L)
  val forPos = positive.sum - positive.length + zero.length
  val forNeg = - negative.sum - negative.length
  if (negative.length % 2 == 0 || zero.nonEmpty){
    println(forPos + forNeg + zero.length)
  }else {
    println(forPos + forNeg + 2)
  }
}

import scala.io.StdIn._

object B_1206 extends App {
  val n = readInt()
  val A = readLine().split(" ").map(_.toInt)

  var cost  = 0L
  var value = 0
  var pos = 0
  var neg = 0

  for (i <- 0 until n) {
    A(i) = if (A(i) > 0) {
      value += A(i) - 1
      pos += 1
      1
    } else if (A(i) < 0) {
      value += -A(i) - 1
      neg += 1
      -1
    } else {
      0
    }
  }

  val zeroes = n - pos - neg
  if (zeroes == 0) {
    if (neg % 2 == 1) value += 2
  } else {
    value += zeroes
  }

  println(value)
}


import scala.collection.mutable.DoubleLinkedList
import java.util._

object CodeForces {

  def SolveSubTask(seq: String) {
    val ans = new Array[Int](10)
    def go(CP: DoubleLinkedList[Char], DP : Boolean  ) {
      val c = CP(0)
      val nDP = c match {
        case '>' => true
        case '<' => false
        case _ => DP
      }
      val nCP = if(nDP) CP.next else CP.prev
      if( c.isDigit ){
        ans(c - '0') += 1
        if(c == '0') CP.remove()
        else CP(0) = (c - 1).toChar
      }
      if(nCP == null || nCP.isEmpty) return
      val nc = nCP(0)
      if( !nc.isDigit && !c.isDigit )
          CP.remove()
      go(nCP,nDP)
    }
    go(DoubleLinkedList(seq: _*) , true)
    System.out.println( ans.mkString(" ") )
  }
  def main(args: Array[String]) {
    val cin = new Scanner(System.in)
    val n = cin.nextInt()
    val q = cin.nextInt()
    val s = cin.next()

    for (i <- 0 until q) {
      val l = cin.nextInt()
      val r = cin.nextInt()
      val seq = s.substring(l - 1, r)
      SolveSubTask(seq)
    }

  }
}

object Olymp{
  def main(args: Array[String]): Unit = {
	val Array(n, q) = readLine.split(' ').map(Integer.parseInt(_))
	val s = readLine.toList
	for (i <- 1 to q) {
	  val Array(l, r) = readLine.split(' ').map(Integer.parseInt(_))
	  solve(Nil, s.drop(l-1).take(r-l+1), '>', Vector.fill(10)(0))
	}
  }

  def solve(prev: List[Char], cur: List[Char], dir: Char, cnt: Vector[Int]): Unit = (prev, cur, dir) match {
    case (_, '0' :: xs, '>') => solve(prev, xs, '>', cnt.updated(0, cnt(0)+1))
    case (y :: ys, '0' :: xs, '<') => solve(ys, y :: xs, '<', cnt.updated(0, cnt(0) + 1))
    case (_, x :: xs, '>') if x.isDigit => solve((x-1).toChar :: prev, xs, '>', cnt.updated(x - '0', cnt(x - '0')+1))
    case (y :: ys, x :: xs, '<') if x.isDigit => solve(ys, y :: (x-1).toChar :: xs, '<', cnt.updated(x - '0', cnt(x - '0') + 1))
    case (_, '>' :: x :: xs, _) if !x.isDigit => solve(prev, x :: xs, '>', cnt)
    case (y :: ys, '<' :: xs, _) if !y.isDigit => solve(ys, y :: xs, '<', cnt)
    case (_, '>' :: xs, _) => solve('>' :: prev, xs, '>', cnt)
    case (y :: ys, '<' :: xs, _) => solve(ys, y :: '<' :: xs, '<', cnt)
    case (_, x :: xs, _) if x.isDigit => for { i <- cnt.updated(x - '0', cnt(x - '0') + 1) } print(i + " "); println
    case _ => for { i <- cnt } print(i + " "); println
  }
}

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

object Main extends App {
  val sc = new Scanner(System.in)
  val n, q = sc.nextInt()
  val s = sc.next()

  def simulate(str: String): Seq[Int] = {
    val res = Array.tabulate(10)(_ => 0)
    def run(cp: DoubleLinkedList[Char], dp: Boolean) {
      val c = cp(0)
      val ndp = c match {
        case '>' => true
        case '<' => false
        case _ => dp
      }
      val ncp = if (ndp) cp.next else cp.prev
      if (c >= '0' && c <= '9') {
        res(c - '0') += 1
        if (c != '0') cp(0) = (cp(0) - 1).toChar
        else cp.remove()
      }
      if (ncp == null || ncp.isEmpty) return
      val nc = ncp(0)
      if ((c == '>' || c == '<') && (nc == '>' || nc == '<')) {
        cp.remove()
      }
      run(ncp, ndp)
    }
    run(DoubleLinkedList(str: _*), true)
    return res
  }

  for(_ <- 1 to q) {
    val l, r = sc.nextInt
    println(simulate(s.substring(l - 1, r)).mkString(" "))
  }
}

object CodeForces {

  def SolveSubTask(seq: java.lang.String) {
    val ans = new Array[Int](10)
    def go(CP: Int, DP: Int, subseq: java.lang.String, pos: Int) { // DP 1 right -1 left
      val len = subseq.length()
      if (CP >= 0 && CP < len) {
        pos match {
          case -1 => {
            subseq.charAt(CP) match {
              case '<' => go(CP - 1, -1, subseq, CP)
              case '>' => go(CP + 1, 1, subseq, CP)
              case x => {
                ans(x - '0') += 1
                x match {
                  case '0' => {
                    val nextseq = subseq.subSequence(0, CP).toString() + subseq.subSequence(CP + 1, subseq.length()).toString()
                    DP match{
                      case 1 => go(CP, DP, nextseq, -1)
                      case -1 => go(CP + DP, DP, nextseq, -1)
                    }

                  }
                  case y => {
                    val nextseq = subseq.subSequence(0, CP).toString() + (x - 1).toChar + subseq.subSequence(CP + 1, subseq.length()).toString()
                    go(CP + DP, DP, nextseq, CP)
                  }
                }
              }
            }
          }
          case others => {
            subseq.charAt(CP) match {
              case '<' => {
                if (!subseq.charAt(pos).isDigit) {
                  val nextseq = subseq.subSequence(0, pos).toString() + subseq.subSequence(pos + 1, subseq.length()).toString()
                  go(CP - 1, -1, nextseq, -1)
                } else {
                  go(CP - 1, -1, subseq, CP)
                }
              }
              case '>' => {
                if (!subseq.charAt(pos).isDigit) {
                  val nextseq = subseq.subSequence(0, pos).toString() + subseq.subSequence(pos + 1, subseq.length()).toString()
                  go(CP, 1, nextseq, -1)
                } else {
                  go(CP + 1, 1, subseq, CP)
                }
              }
              case x => {
                ans(x - '0') += 1
                x match {
                  case '0' => {
                    val nextseq = subseq.subSequence(0, CP).toString() + subseq.subSequence(CP + 1, subseq.length()).toString()
                    DP match{
                      case 1 => go(CP, DP, nextseq, -1)
                      case -1 => go(CP + DP, DP, nextseq, -1)
                    }
                  }

                  case y => {
                    val nextseq = subseq.subSequence(0, CP).toString() + (x - 1).toChar + subseq.subSequence(CP + 1, subseq.length()).toString()
                    go(CP + DP, DP, nextseq, CP)
                  }
                }
              }
            }
          }
        }
      } else {
        for (it <- ans) System.out.print(it + " ")
        System.out.println()
      }
    }

    go(0, 1, seq, -1)
  }
  def main(args: Array[String]) = {
    val cin = new java.util.Scanner(System.in)
    val n = cin.nextInt()
    val q = cin.nextInt()
    val s = cin.next()

    for (i <- 0 until q) {
      val l = cin.nextInt()
      val r = cin.nextInt()
      val seq = s.subSequence(l - 1, r).toString()
      SolveSubTask(seq)
    }

  }
}

object CodeForces {

  def SolveSubTask(seq: java.lang.String) {
    val ans = new Array[Int](10)
    def go(CP: Int, DP: Int, subseq: java.lang.String, pos: Int) { // DP 1 right -1 left
      val len = subseq.length()
      if (CP >= 0 && CP < len) {
        pos match {
          case -1 => {
            subseq.charAt(CP) match {
              case '<' => go(CP - 1, -1, subseq, CP)
              case '>' => go(CP + 1, 1, subseq, CP)
              case x => {
                ans(x - '0') += 1
                x match {
                  case '0' => {
                    val nextseq = subseq.subSequence(0, CP).toString() + subseq.subSequence(CP + 1, subseq.length()).toString()
                    DP match{
                      case 1 => go(CP, DP, nextseq, -1)
                      case 0 => go(CP + DP, DP, nextseq, -1)
                    }

                  }
                  case y => {
                    val nextseq = subseq.subSequence(0, CP).toString() + (x - 1).toChar + subseq.subSequence(CP + 1, subseq.length()).toString()
                    go(CP + DP, DP, subseq, CP)
                  }
                }
              }
            }
          }
          case others => {
            subseq.charAt(CP) match {
              case '<' => {
                if (!subseq.charAt(pos).isDigit) {
                  val nextseq = subseq.subSequence(0, pos).toString() + subseq.subSequence(pos + 1, subseq.length()).toString()
                  go(CP - 1, -1, nextseq, -1)
                } else {
                  go(CP - 1, -1, subseq, CP)
                }
              }
              case '>' => {
                if (!subseq.charAt(pos).isDigit) {
                  val nextseq = subseq.subSequence(0, pos).toString() + subseq.subSequence(pos + 1, subseq.length()).toString()
                  go(CP, 1, nextseq, -1)
                } else {
                  go(CP + 1, 1, subseq, CP)
                }
              }
              case x => {
                ans(x - '0') += 1
                x match {
                  case '0' => {
                    val nextseq = subseq.subSequence(0, CP).toString() + subseq.subSequence(CP + 1, subseq.length()).toString()
                    DP match{
                      case 1 => go(CP, DP, nextseq, -1)
                      case 0 => go(CP + DP, DP, nextseq, -1)
                    }
                  }

                  case y => {
                    val nextseq = subseq.subSequence(0, CP).toString() + (x - 1).toChar + subseq.subSequence(CP + 1, subseq.length()).toString()
                    go(CP + DP, DP, nextseq, CP)
                  }
                }
              }
            }
          }
        }
      } else {
        for (it <- ans) System.out.print(it + " ")
        System.out.println()
      }
    }

    go(0, 1, seq, -1)
  }
  def main(args: Array[String]) = {
    val cin = new java.util.Scanner(System.in)
    val n = cin.nextInt()
    val q = cin.nextInt()
    val s = cin.next()

    for (i <- 0 until q) {
      val l = cin.nextInt()
      val r = cin.nextInt()
      val seq = s.subSequence(l - 1, r).toString()
      SolveSubTask(seq)
    }

  }
}

object CodeForces {

  def SolveSubTask(seq: java.lang.String) {
    val ans = new Array[Int](10)
    def go(CP: Int, DP: Int, subseq: java.lang.String, pos: Int) { // DP 1 right -1 left
      val len = subseq.length()
      if (CP >= 0 && CP < len) {
        pos match {
          case -1 => {
            subseq.charAt(CP) match {
              case '<' => go(CP - 1, -1, subseq, CP)
              case '>' => go(CP + 1, 1, subseq, CP)
              case x => {
                ans(x - '0') += 1
                x match {
                  case '0' => {
                    val nextseq = subseq.subSequence(0, CP).toString() + subseq.subSequence(CP + 1, subseq.length()).toString()

                    go(CP + DP, DP, nextseq, CP)
                  }
                  case y => {
                    val nextseq = subseq.subSequence(0, CP).toString() + (x - 1).toChar + subseq.subSequence(CP + 1, subseq.length()).toString()
                    go(CP + DP, DP, subseq, CP)
                  }
                }
              }
            }
          }
          case others => {
            subseq.charAt(CP) match {
              case '<' => {
                if (!subseq.charAt(pos).isDigit) {
                  val nextseq = subseq.subSequence(0, pos).toString() + subseq.subSequence(pos + 1, subseq.length()).toString()
                  go(CP - 1, -1, nextseq, CP)
                } else {
                  go(CP - 1, -1, subseq, CP)
                }
              }
              case '>' => {
                if (!subseq.charAt(pos).isDigit) {
                  val nextseq = subseq.subSequence(0, pos).toString() + subseq.subSequence(pos + 1, subseq.length()).toString()
                  go(CP + 1, 1, nextseq, CP)
                } else {
                  go(CP + 1, 1, subseq, CP)
                }
              }
              case x => {
                ans(x - '0') += 1
                x match {
                  case '0' => {
                    val nextseq = subseq.subSequence(0, CP).toString() + subseq.subSequence(CP + 1, subseq.length()).toString()
                    go(CP + DP, DP, nextseq, CP)
                  }

                  case y => {
                    val nextseq = subseq.subSequence(0, CP).toString() + (x - 1).toChar + subseq.subSequence(CP + 1, subseq.length()).toString()
                    go(CP + DP, DP, nextseq, CP)
                  }
                }
              }
            }
          }
        }
      } else {
        for (it <- ans) System.out.print(it + " ")
        System.out.println()
      }
    }

    go(0, 1, seq, -1)
  }
  def main(args: Array[String]) = {
    val cin = new java.util.Scanner(System.in)
    val n = cin.nextInt()
    val q = cin.nextInt()
    val s = cin.next()

    for (i <- 0 until q) {
      val l = cin.nextInt()
      val r = cin.nextInt()
      val seq = s.subSequence(l - 1, r).toString()
      SolveSubTask(seq)
    }

  }
}

object Olymp{
  def main(args: Array[String]): Unit = {
	val Array(n, q) = readLine.split(' ').map(Integer.parseInt(_))
	val s = readLine.toList
	for (i <- 1 to q) {
	  val Array(l, r) = readLine.split(' ').map(Integer.parseInt(_))
	  solve(Nil, s.drop(l-1).take(r-l+1), '>', Vector.fill(10)(0))
	}
  }

  def solve(prev: List[Char], cur: List[Char], dir: Char, cnt: Vector[Int]): Unit = (prev, cur, dir) match {
    case (_, '0' :: xs, '>') => solve(prev, xs, '>', cnt.updated(0, cnt(0)+1))
    case (y :: ys, '0' :: xs, '<') => solve(ys, y :: xs, '<', cnt.updated(0, cnt(0) + 1))
    case (_, x :: xs, '>') if x.isDigit => solve((x-1).toChar :: prev, xs, '>', cnt.updated(x - '0', cnt(x - '0')+1))
    case (y :: ys, x :: xs, '<') if x.isDigit => solve(ys, y :: (x-1).toChar :: xs, '<', cnt.updated(x - '0', cnt(x - '0') + 1))
    case (_, '>' :: x :: xs, _) if !x.isDigit => solve(prev, x :: xs, '>', cnt)
    case (y :: ys, '<' :: xs, _) if !y.isDigit => solve(ys, y :: xs, '<', cnt)
    case (_, '>' :: xs, _) => solve('>' :: prev, xs, '>', cnt)
    case (y :: ys, '<' :: xs, _) => solve(ys, y :: '<' :: xs, '<', cnt)
    case _ => for { i <- cnt } print(i + " "); println
  }
}


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

  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 (p, c) = na2(N)

    val revP = Array.fill[ArrayBuffer[Int]](N)(ArrayBuffer())
    REP(N) { i =>
      if (p(i) != -1) revP(p(i) - 1) += i
    }

    debug(revP.mkString(","))

    val del = Array.ofDim[Boolean](N)
    REP(N) { i =>
      if (p(i) != -1 && c(i) == 1 && revP(i).forall(j => c(j) == 1)) {
        del(i) = true
      }
    }

    val ans = del.zipWithIndex.filter(_._1).map(_._2 + 1)
    if (ans.isEmpty) out.println(-1)
    else out.println(ans.mkString(" "))
  }

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

import scala.math._, scala.io.StdIn._

object C extends App {
  val n = readInt

  val p = Array.ofDim[Int](n)
  val c = Array.ofDim[Boolean](n)

  for (i <- 0 until n) {
    val Array(pi, ci) = readInts
    p(i) = pi - 1
    c(i) = ci == 1
  }

  val bad = c.clone
  for (i <- 0 until n) {
    if (!c(i) && p(i) >= 0)
      bad(p(i)) = false
  }

  var nothing = true
  for (i <- 1 to n) {
    if (bad(i-1)) {
      print(s"$i ")
      nothing = false
    }
  }
  if (nothing)
    println(-1)
  else
    println()

  def readInts() = readLine.split(" ").map(_.toInt)
}