import scala.io.StdIn

object Main {
  def main(args: Array[String]) {
    val solve = (s : (String, String)) => {
      val str_builder = new StringBuilder(s._1);

      def flip_at = (i : Int) =>
        str_builder.setCharAt(i,
          str_builder.charAt(i) match {
            case '0' => '1'
            case '1' => '0'
          }
        )

      val indices_to_flip : Seq[Int] = s.zipped.toIndexedSeq.zipWithIndex.filter{ case ((x,y),_) => x != y }.map(_._2)

      def flip = (xs : Seq[Int], f : Int => Unit) =>
        (xs.size % 2, xs.size / 2) match {
          case (1, _) => println("impossible"); false
          case (0, halfsz) => xs.take(halfsz) foreach f; true
        }

      if (flip(indices_to_flip, flip_at)) {
        println(str_builder);
      }
    }

    solve(( (f : () => String) => (f(), f()) ) ( StdIn.readLine ));
  }
}

import scala.io.StdIn

object Main {
  def main(args: Array[String]) {
    val solve = (s : (String, String)) => {
      val str_builder = new StringBuilder(s._1);

      def flip_at = (i : Int) =>
        str_builder.setCharAt(i,
          str_builder.charAt(i) match {
            case '0' => '1'
            case '1' => '0'
          }
        )

      val indices_to_flip : Seq[Int] = s.zipped.toIndexedSeq.zipWithIndex.filter{ case ((x,y),_) => x != y }.map(_._2)

      def flip = (xs : Seq[Int], f : Int => Unit) =>
        (xs.size % 2, xs.size / 2) match {
          case (1, _) => false
          case (0, halfsz) => xs.take(halfsz) foreach f; true
        }

      println(
        flip(indices_to_flip, flip_at) match {
          case true => str_builder;
          case false => "impossible"
        } )

    }

    solve(( (f : () => String) => (f(), f()) ) ( StdIn.readLine ));
  }
}

object P545_B_Equidistant_String {

  def find(s: String, t: String): String = {
    var flag = true
    val p: Seq[Char] = s.zip(t).map {
      case (a, b) =>
        if (a == b) a
        else {
          if (flag) {
            flag = false
            a
          } else {
            flag = true
            b
          }
        }
    }
    if (flag) p.mkString
    else "impossible"
  }

  def main(args: Array[String]) = {
    val s = scala.io.StdIn.readLine
    val t = scala.io.StdIn.readLine
    val p = find(s, t)
    println(p)
  }

}

import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._

object B extends App {
  val s = readLine().map(_.toString.toInt)
  val t = readLine().map(_.toString.toInt)
  val answer = new Array[Int](s.length)

  def dist(A: Seq[Int], B: Seq[Int]): Int = A.zip(B).map(x => Math.abs(x._1 - x._2)).sum

  def solve(): Boolean = {
    var dist1 = dist(s, answer)
    var dist2 = dist(t, answer)

    if (dist1 == dist2) true
    else {
      for (i <- 0 until s.length) {
        if (s(i) == 1 && t(i) == 0 && dist1 > dist2) {
          answer(i) = 1
          dist1 -= 1
          dist2 += 1
        } else if (s(i) == 0 && t(i) == 1 && dist2 > dist1) {
          answer(i) = 1
          dist1 += 1
          dist2 -= 1
        }

        if (dist1 == dist2) return true
      }
      false
    }
  }

  println(if (solve()) answer.mkString("") else "impossible")
}

import scala.io.StdIn
object b extends App {
  var l = List(StdIn.readLine, StdIn.readLine)
  var d = l(0).count(_=='1') - l(1).count(_=='1')
  if (d < 0) { d = -d; l=l.reverse }
  println(if (d%2 == 0) {
    d /= 2
    l(0).zip(l(1)).map(x =>
        if (x._1 != x._2 && x._2 == '0' && d > 0) {d-=1; '1'} else '0'
    ).mkString
  } else "impossible")
}

import scala.io.StdIn
object z1 extends App {
  var s = StdIn.readLine().toCharArray
  var t = StdIn.readLine().toCharArray
  var c = 0
  var p = StringBuilder.newBuilder
  (0 until s.length).foreach(i=>{
    if (s(i)!=t(i)) c+=1
    if (c%2==0) p+=s(i) else p+=t(i)
  })
  if (c%2==1) println("impossible") else println(p)
}

import java.util.StringTokenizer

object _545B extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val s = next
  val t = next
  val n = s.length
  val diff = (0 until n).map(i => if (s(i) == t(i)) 0 else 1).sum
  if (diff % 2 == 1) println("impossible")
  else {
    val ans = new StringBuilder
    def doit(i: Int, cnt: Int): Unit = {
      if (i < n) {
        if (s(i) == t(i)) {
          ans += s(i)
          doit(i + 1, cnt)
        }
        else {
          if (cnt < diff / 2) {
            ans += s(i)
            doit(i + 1, cnt + 1)
          }
          else {
            ans += t(i)
            doit(i + 1, cnt)
          }
        }
      }
    }

    doit(0, 0)
    println(ans.toString)
  }
}

object B545 {

  import IO._

  def main(args: Array[String]): Unit = {
    val s = read
    val t = read
    var dist = 0
    for(i <- 0 until s.length) {
      if(s(i) != t(i)) dist += 1
    }
    if(dist%2 == 0) {
      val res = Array.fill(s.length)('x')
      var j = 0
      for(i <- 0 until s.length) {
        if(s(i) != t(i)) {
          if(j%2 == 0)
            res(i) = s(i)
          else
            res(i) = t(i)
          j += 1
        } else {
          res(i) = s(i)
        }
      }
      println(res.mkString(""))
    } else {
      println("impossible")
    }
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

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

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

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

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

}

object B545 extends App{

  val s  = readLine
  val t  = readLine
  val ln = s.size
  var flag = false
  var counter = 0

  val result = for(i <- 0 until ln) yield {
    if(s(i) == t(i))
      s(i)
    else
    {
      counter += 1
      if(flag)
        { flag = false; s(i) }
      else
        { flag = true ; t(i) }
    }
  }

  if(counter % 2 != 0)
    print("impossible")
  else
    print(result.mkString(""))
}

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

import scala.collection.mutable

object B {

  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)

  class MultiHashSet[T <% Comparable[T]] {
    val map = new mutable.HashMap[T, Int]()

    def count(x: T): Int = {
      return map.getOrElse(x, 0)
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  class MultiTreeSet[T <% Comparable[T]] {
    val map = new TreeMap[T, Int]()

    def count(x: T): Int = {
      val res = map.get(x)
      if (res == null)
        return 0
      return res
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def first(): T = return map.firstKey()

    def last(): T = return map.lastKey()

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  def solve: Int = {
    val s = next.toCharArray
    val p = next.toCharArray
    val n = s.length
    var diff = 0
    for (i <- 0 until n) {
      if (s(i) != p(i))
        diff += 1
    }
    if (diff % 2 == 1) {
      out.println("impossible")
    } else {
      var first = 0
      var second = 0
      for (i <- 0 until n) {
        if (s(i) != p(i)) {
            if (first > second) {
              out.print(p(i))
              second += 1
            } else {
              out.print(s(i))
              first += 1
            }
        } else {
          out.print(s(i))
        }
      }
    }
    return 0
  }
}

object _545B extends CodeForcesApp {
  import scala.collection.mutable

  override type Input = (List[Char], List[Char])
  override type Output = Option[List[Char]]

  override def read(scanner: java.util.Scanner) = {
    import scanner._
    (next.toList, next.toList)
  }

  override def solve(input: Input) = {
    val (s, t) = input

    var count = 0

    val result = mutable.ListBuffer.empty[Char]

    for {
      (s1, t1) <- s zip t
    } {
      if (s1 == t1) {
        result += s1
      } else {
        if (count == 0) {
          result += s1
          count += 1
        } else {
          result += t1
          count -= 1
        }
      }
    }
    when(count == 0)(result.toList)
  }

  override def format(result: Output) = result match {
    case None => "impossible"
    case Some(sol) => sol.mkString
  }
}

/****************************** IGNORE BELOW *********************************/
abstract class CodeForcesApp extends App {
  /********************************[ I/O ]************************************/
  import java.util.Scanner
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  def apply(problem: String): String  = apply(new Scanner(problem))
  def apply(scanner: Scanner): String = format(solve(read(scanner)))
  println(apply(new Scanner(System.in)))
  /********************************[ lib ]************************************/
  import scala.collection.mutable
  case class Memo[I <% K, K, O](f: I => O) extends (I => O) {
    val cache = mutable.Map.empty[K, O]
    override def apply(x: I): O = cache.getOrElseUpdate(x, f(x))
  }
  type m_=>[I, O] = Memo[I, I, O]
  def when[A](condition: Boolean)(f: => A): Option[A] = if (condition) Some(f) else None
  /******************************[ solution ]*********************************/
  type Input
  type Output
  def read(scanner: Scanner): Input
  def solve(input: Input): Output
  def format(result: Output): String = result.toString
  def timeLimitSecond = 1
}

import scala.io.StdIn
object b extends App {
  var l = List(StdIn.readLine, StdIn.readLine)
  var d = l(0).count(_=='1') - l(1).count(_=='1')
  if (d < 0) { d = -d; l=l.reverse }
  println(if (d%2 == 0) {
    d /= 2
    val t = l(0).zip(l(1)).map(x =>
        if (x._1 != x._2 && x._2 == '0' && d > 0) {d-=1; '1'} else '0'
    ).mkString
  } else "impossible")
}

import scala.io.StdIn
object b extends App {
  val l = List(StdIn.readLine, StdIn.readLine)
  var d = l(0).count(_=='1') - l(1).count(_=='1')
  if (d < 0) { d = -d; l.reverse }
  println(if (d%2 == 0) {
    d /= 2
    l(0).zip(l(1)).map(x =>
        if (x._1 != x._2 && x._1 == '0' && d > 0) {d-=1; '1'} else '0'
    ).mkString
  } else "impossible")
}

import scala.io.StdIn
object b extends App {
  val (a, b) = (StdIn.readLine, StdIn.readLine)
  var d = (a.count(_=='1') - b.count(_=='1')).abs
  println(if (d%2 == 0) {
    d /= 2
    a.zip(b).map(x => if (x._1 != x._2 && d > 0) {d-=1; '1'} else '0').mkString
  } else "impossible")
}

object B545 {

  import IO._

  def main(args: Array[String]): Unit = {
    val s = read
    val t = read
    var dist = 0
    for(i <- 0 until s.length) {
      if(s(i) != t(i)) dist += 1
    }
    if(dist%2 == 0) {
      val res = Array.fill(s.length)('x')
      var j = 0
      for(i <- 0 until s.length) {
        if(s(i) != t(i)) {
          if(j%2 == 0)
            res(i) = '0'
          else
            res(i) = '1'
          j += 1
        } else {
          res(i) = s(i)
        }
      }
      println(res.mkString(""))
    } else {
      println("impossible")
    }
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

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

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

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

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

}


import scala.runtime.ScalaRunTime._

object Main
{
  def inv(p : Array[Int]) : Array[Int] =
  {
    var r = p.clone
    for(i <- 0 until p.length)
      r(p(i)-1) = i+1
    r
  }

  def permute(w : Array[Int], p : Array[Int]) : Array[Int] =
  {
    var r = w.clone
    for(i <- 0 until w.length)
      r(i) = p(w(i)-1)
    r
  }

  def main(args : Array[String]) : Unit =
  {
    val n = readInt
    val p1 = readLine split " " map (_.toInt)
    val p2 = readLine split " " map (_.toInt)
    val d = permute(p1,inv(p2))
    var i = 1
    while (i < n && d(i) > d(i-1))
      i += 1
    println(n-i)
  }
}

import java.util.Scanner

object CF119Div1A {
  def main(args: Array[String]): Unit = {
    val n = readInt()
    val xs = readIntArray(n)
    val ys = readIntArray(n)

    var px = 0
    var py = 0
    while (py < n) {
      if (xs(px) == ys(py)) {
        px += 1
        py += 1
      } else {
        py += 1
      }
    }
    println(n - px)
  }

  private def readIntArray(n: Int): Array[Int] = {
    val xs = new Array[Int](n)
    val line = readLine()
    val words = line.split(" ")
    for (i <- 0 until n) {
      xs(i) = words(i).toInt
    }
    xs
  }
}

import java.util.Scanner

object CF119Div1A {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val xs = new Array[Int](n)
    val ys = new Array[Int](n)
    for (i <- 0 until n) {
      xs(i) = sc.nextInt()
    }
    for (i <- 0 until n) {
      ys(i) = sc.nextInt()
    }

    var px = 0
    var py = 0
    while (py < n) {
      if (xs(px) == ys(py)) {
        px += 1
        py += 1
      } else {
        py += 1
      }
    }
    println(n - px)
  }
}

import annotation.tailrec

//package contest119.div2

/**
 * Created with IntelliJ IDEA.
 * User: Oleg
 * Date: 11.05.12
 * Time: 23:04
 * To change this template use File | Settings | File Templates.
 */

object C {
  val n = readInt()
  val List(from, to) = List.fill(2)(readLine().split(' ').map(_.toInt - 1))
  val invTo = Array.fill(n)(0)
  for (i <- 0 until n) invTo(to(i)) = i
  val convFrom = (for (i <- 0 until n) yield invTo(from(i))).toArray

  def grows: Int = {
    for (i <- 0 until n - 1) if (convFrom(i + 1) < convFrom(i)) return n - (i + 1)
    0
  }

  def main(args: Array[String]) {
    println(grows)
  }
}

object CF119Div1A {
  def main(args: Array[String]): Unit = {
    val n = readInt()
    val xs = toReversedIntArray(readLine().split(" "))
    val ys = toReversedIntArray(readLine().split(" "))

    val used = new Array[Boolean](n + 1)
    var xIndex = 0
    var yIndex = 0
    var cost = 0
    while (yIndex < n) {
      if (used(ys(yIndex))) {
        yIndex += 1
      } else if (used(xs(xIndex))) {
        xIndex += 1
      } else if (xs(xIndex) == ys(yIndex)) {
        used(ys(yIndex)) = true
        xIndex += 1
        yIndex += 1
      } else {
        used(xs(xIndex)) = true
        xIndex += 1
        cost += 1
      }
    }
    println(cost)
  }

  private def toReversedIntArray(strings: Array[String]): Array[Int] = {
    val intValues = new Array[Int](strings.length)
    for (i <- 0 until strings.length) {
      intValues((strings.length - 1) - i) = strings(i).toInt
    }
    intValues
  }
}

import scala.runtime.ScalaRunTime._

object Main
{
  def permute[T](w : Array[T], p : Array[Int]) : Array[T] =
  {
    var r = w.clone
    for(i <- 0 until w.length)
      r(p(i)-1) = w(i)
    r
  }

  def main(args : Array[String]) : Unit =
  {
    val n = readInt
    val p1 = readLine split " " map (_.toInt)
    val p2 = readLine split " " map (_.toInt)
    val d = permute(p1,p2)
    var i = 1
    while (i < n && d(i) > d(i-1))
      i += 1
    println(n-i)
  }
}


object C687 {
  def mark(
    n: Int,
    k: Int,
    subK: Int,
    dp: Array[Array[Array[Option[Boolean]]]],
    c: Array[Int]
  ): Boolean = {
    if (k == 0 && subK == 0) true
    else if (k < 0 || subK < 0) false
    else if (n == 0) false
    else if (dp(n % 2)(k)(subK) != null) dp(n)(k)(subK).get
    else {
      val ret = (mark(n - 1, k - c(n - 1), subK, dp, c) ||
          mark(n - 1, k - c(n - 1), subK - c(n - 1), dp, c) ||
          mark(n - 1, k, subK, dp, c))

      dp(n)(k)(subK) = Some(ret)

      ret
    }
  }

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

    val c = readLine.split(" ").map(_.toInt).toArray

    val dp = Array.ofDim[Boolean](2, k + 1, k + 1)

    dp(0)(0)(0) = true

    var nn = 1

    while (nn <= n) {
      val index = nn % 2
      val prev = 1 - index

      var kk = 0
      while (kk <= k) {

        var subK = 0

        while (subK <= kk) {
          dp(index)(kk)(subK) = (if (kk - c(nn - 1) >= 0) dp(prev)(kk - c(nn - 1))(subK) else false) ||
              (if (kk - c(nn - 1) >= 0 && subK - c(nn - 1) >= 0) dp(prev)(kk - c(nn - 1))(subK - c(nn - 1)) else false) ||
              dp(prev)(kk)(subK)
          if (dp(index)(kk)(subK)) {
            //println(s"$index, $kk, $subK")
            //readLine
          }

          subK += 1
        }

        kk += 1
      }

      nn += 1
    }

    val ret = (0 to k).filter { case sum => dp(n % 2)(k)(sum) }

    println(ret.length)
    println(ret.mkString(" "))
  }
}

object C687 {
  def main(args: Array[String]) = {
    val n :: k :: rest = readLine.split(" ").map(_.toInt).toList
    val c = readLine.split(" ").map(_.toInt).toArray
    val dp = Array.ofDim[Boolean](2, k + 1, k + 1)
    dp(0)(0)(0) = true
    var nn = 1
    while (nn <= n) {
      val index = nn % 2
      val prev = 1 - index
      var kk = 0
      while (kk <= k) {
        var subK = 0
        while (subK <= kk) {
          dp(index)(kk)(subK) = (if (kk - c(nn - 1) >= 0) dp(prev)(kk - c(nn - 1))(subK) else false) ||
              (if (kk - c(nn - 1) >= 0 && subK - c(nn - 1) >= 0) dp(prev)(kk - c(nn - 1))(subK - c(nn - 1)) else false) ||
              dp(prev)(kk)(subK)
          subK += 1
        }
        kk += 1
      }
      nn += 1
    }
    val ret = (0 to k).filter { case sum => dp(n % 2)(k)(sum) }
    println(ret.length)
    println(ret.mkString(" "))
  }
}


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

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

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

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

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

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

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

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

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }
  def cumSum(as: Array[Int]): 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にしろ
  final private[this] val MOD = 1000000007

  def solve(): Unit = {
    val n = ni()
    val s = ns(n)
    val c = Array.ofDim[Int](26)
    REP(n) { i =>
      c(s(i)-'a') += 1
    }
    val ones = c('n'-'a')
    val zeros = c('z'-'a')
    val ans = ArrayBuffer[Int]()
    REP(ones) { _ => ans += 1}
    REP(zeros) { _ => ans += 0}
    out.println(ans.mkString(" "))
  }
}

import scala.io.StdIn

object Codeforces1120A extends App {
  StdIn.readLine()
  val cards = StdIn.readLine().split("")
  val ones = cards.filter(a => a == "n").map(a => "1")
  val zeroes = cards.filter(a => a == "z").map(a => "0")
  println((ones ++ zeroes).mkString(" "))
}

import scala.io.StdIn

object Codeforces1120A extends App {
  StdIn.readLine()
  val word = StdIn.readLine()
  val ones = word.split("").filter(a => a == "n").map(a => "1")
  val zeroes = word.split("").filter(a => a == "z").map(a => "0")
  val n = ones ++ zeroes
  println(n.mkString(" "))
}

import scala.io.StdIn

object Codeforces1120A extends App {
  StdIn.readLine()
  val word = StdIn.readLine()
  val ones = word.split("").filter(a => a == "n").map(a => "1")
  val zeroes = word.split("").filter(a => a == "z").map(a => "0")
  if (ones.length > 0)
    println(ones.mkString(" ") + " " + zeroes.mkString(" "))
  else
    println("0")
}


import annotation._
import io.Source
// two lists: kayak list and catamaran list

// while we still have two metres available:
// choose either the biggest catamaran, or the two biggest kayaks (whichever is bigger)
// reduce the lists appropriately, and repeat
//
// we have one metre, or no metres:
// choose biggest kayak, or do nothing

object Lorry {
    val cataSize = 2
    val kayakSize = 1

    def main(args: Array[String]) = {
        val lines = Source.stdin.getLines()
        val firstLine = lines.next().split(" ")
        val numBoats = firstLine(0).toInt
        var truckVolume = firstLine(1).toInt

        // need to cover the case where truckVolume is odd:
        // choose the best kayak first
        val boats = getBoatLists(lines, numBoats)

        var kayaks = boats._1
        val catamarans = boats._2
        var accum: Pair[List[Int], Int] = Pair(Nil, 0)
        if (truckVolume % 2 == 1 && !kayaks.isEmpty) {
            accum = Pair(List(kayaks.head._1), kayaks.head._2)
            kayaks = kayaks.tail
            truckVolume -= kayakSize
        }
        val chosenBoatsAndCapacity = getOptimalSet(kayaks, catamarans, truckVolume, accum)
        println(chosenBoatsAndCapacity._2)
        // should split the output... put a space between the boats or something?
        chosenBoatsAndCapacity._1.foreach(x => print(x + " "))
        println()
    }

    def getBoatLists(lines: Iterator[String], numBoats: Int) = {
        var kayaks: List[Pair[Int, Int]] = Nil
        var catamarans: List[Pair[Int, Int]] = Nil

        for (i <- 1 to numBoats) {
            var current = lines.next().split(" ")
            if (current(0).toInt == 1)
                kayaks = Pair(i, current(1).toInt) :: kayaks
            else
                catamarans = Pair(i, current(1).toInt) :: catamarans
        }
        kayaks = kayaks.sortWith((first, second) => first._2 > second._2)
        catamarans = catamarans.sortWith((first, second) => first._2 > second._2)

        Pair(kayaks, catamarans)
    }

    @tailrec
    final def getOptimalSet(kayaks: List[Pair[Int, Int]], catas: List[Pair[Int, Int]], spaceLeft: Int, accum: Pair[List[Int], Int]):
    Pair[List[Int], Int] = {
        catas match {
            case Nil => finish(kayaks, spaceLeft, kayakSize, accum)
            case (cnum, ccargo) :: rcatas =>
                if (spaceLeft >= cataSize)
                    kayaks match {
                        case (knum1, kcargo1) :: (knum2, kcargo2) :: rkayaks =>
                            if (kcargo1 + kcargo2 > ccargo)
                                getOptimalSet(rkayaks, catas, spaceLeft - cataSize, Pair(knum1 :: knum2 :: accum._1, accum._2 + kcargo1 +
                                    kcargo2))
                            else
                                getOptimalSet(kayaks, rcatas, spaceLeft - cataSize, Pair(cnum :: accum._1, accum._2 + ccargo))
                        case List(Pair(knum, kcargo)) =>
                            if (kcargo > ccargo)
                                finish(catas, spaceLeft - kayakSize, cataSize, Pair(knum :: accum._1, accum._2 + kcargo))
                            else
                                getOptimalSet(kayaks, rcatas, spaceLeft - cataSize, Pair(cnum :: accum._1, accum._2 + ccargo))
                        case Nil =>
                            finish(catas, spaceLeft, cataSize, accum)
                    }
                else
                    finish(kayaks, spaceLeft, kayakSize, accum)
        }
    }

    def finish(boats: List[Pair[Int, Int]], spaceLeft: Int, boatSize: Int, accum: Pair[List[Int], Int]): Pair[List[Int], Int] = {

        @tailrec
        def finishHelper(boats: List[Pair[Int, Int]], spaceLeft: Int, accum: Pair[List[Int], Int]): Pair[List[Int], Int] = {
            boats match {
                case (bnum, bcargo) :: rboats if (spaceLeft >= boatSize) =>
                    finishHelper(rboats, spaceLeft - boatSize, Pair(bnum :: accum._1, accum._2 + bcargo))
                case _ => accum
            }
        }
        finishHelper(boats, spaceLeft, accum)
    }
}

object P3B {
  def main(args : Array[String]) {
    val Array(n, v) = readLine split " " map {_.toInt}
    val a = Array.fill(n) {
      val Array(t, p) = readLine split " " map {_.toInt}
      (t, p)
    }.zipWithIndex
    val a1 = a filter {_._1._1 == 1} sortBy {-_._1._2}
    val s1 = a1.scanLeft(0){_ + _._1._2}
    val a2 = a filter {_._1._1 == 2} sortBy {-_._1._2}
    val s2 = a2.scanLeft(0){_ + _._1._2}
    val vU = v min (a1.size + a2.size * 2)
    val s = for (i <- 0 to vU / 2) yield {
      s1(vU - i * 2 min a1.size) + s2(i min a2.size)
    }
    val m = s.max
    println(m)
    val k = s indexOf m
    val w = ((a1 take vU - k * 2) ++ (a2 take k)) map {_._2 + 1}
    println(w mkString " ")
  }
}

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

object Boats extends App {

  val scanner = new Scanner(System.in)

  val boatsNum = scanner.nextInt()
  val truckSize = scanner.nextInt()

  var light = mutable.PriorityQueue.empty[Boat]
  var heavy = mutable.PriorityQueue.empty[Boat]

  (1 until boatsNum + 1).foreach {
    cnt =>
      val t =scanner.next().toInt
      if (t == 1) {
        light += Boat(1, scanner.next().toInt, cnt)
      } else {
        heavy += Boat(2, scanner.next().toInt, cnt)
      }
  }

  var res = new StringBuffer()
  var sum = 0

  def append(b: Boat): Unit = {
    sum += b.weight
    res.append(b.order)
    res.append(" ")
  }

  solve(truckSize)

  def solve(sizeLeft: Int): Unit = {
    if (sizeLeft == 0) {
      printResult()
    } else if (sizeLeft == 1 && !light.isEmpty) {
      append(light.head)
      printResult()
    } else if (sizeLeft == 1 && light.isEmpty) {
      printResult()
    } else if (light.isEmpty && heavy.isEmpty) {
      printResult()
    } else if (light.isEmpty) {
      append(heavy.head)
      heavy = heavy.tail
      solve(sizeLeft - 2)
    } else if (heavy.isEmpty) {
      append(light.head)
      light = light.tail
      solve(sizeLeft - 1)
    } else if (light.size == 1) {
      if (heavy.head.weight > light.head.weight) {
        append(heavy.head)
        heavy = heavy.tail
        solve(sizeLeft - 2)
      } else {
        append(light.head)
        light = light.tail
        solve(sizeLeft - 1)
      }
    } else {
      val f = light.dequeue()
      val s = light.head
      if (heavy.head.weight > s.weight + f.weight) {
        append(heavy.dequeue())
        light += f
        solve(sizeLeft - 2)
      } else {
        append(f)
        solve(sizeLeft - 1)
      }
    }
  }

  def printResult(): Unit = {
    println(sum)
    println(res)
  }

  case class Boat(size: Int, weight: Int, order: Int) extends Ordered[Boat] {
    override def compare(that: Boat): Int = this.weight.compareTo(that.weight)
  }

  /*
  * 20 19
2 47
1 37
1 48
2 42
2 48
1 38
2 47
1 48
2 47
1 41
2 46
1 28
1 49
1 45
2 34
1 43
2 29
1 46
2 45
2 18
  * */

}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(n, v) = in.next().split(' ').map(_.toInt)
  val boats = in.take(n).toList.zipWithIndex.map(i => (i._1, (i._2 + 1).toString))
  val smallBoats = boats.filter(_._1.head == '1').map(i => (i._1.drop(2).toInt, i._2)).sorted.reverse
  val bigBoats: List[(Int, String)] = boats.filter(_._1.head == '2').map(i => (i._1.drop(2).toInt, i._2))
  val bigSmallBoat = if (v % 2 == 0 || smallBoats.length == 0) None else Some(smallBoats.head)
  val newSmallBoats = bigSmallBoat match {
    case None => smallBoats
    case Some(_) => smallBoats.tail
  }

  val pairsSmallBoats = newSmallBoats.grouped(2).map{l =>
    if (l.length == 2)
      (l.head._1 + l.last._1, l.head._2 + " " + l.last._2)
    else
      (l.head._1, l.head._2)
  }.toList
  val r = (pairsSmallBoats ::: bigBoats).sorted.reverse.take(v / 2)
  println(bigSmallBoat.map(_._1).getOrElse(0) + r.map(_._1).sum)
  println(r.map(_._2).mkString(bigSmallBoat.map(_._2 + " ").getOrElse(""), " ", ""))
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(n, v) = in.next().split(' ').map(_.toInt)
  val boats = in.take(n).toList.zipWithIndex.map(i => (i._1, (i._2 + 1).toString))
  val smallBoats = boats.filter(_._1.head == '1').map(i => (i._1.drop(2).toInt, i._2)).sorted.reverse
  val bigBoats: List[(Int, String)] = boats.filter(_._1.head == '2').map(i => (i._1.drop(2).toInt, i._2))
  val bigSmallBoat = if (v % 2 == 0) None else Some(smallBoats.head)
  val newSmallBoats = bigSmallBoat match {
    case None => smallBoats
    case Some(_) => smallBoats.tail
  }

  val pairsSmallBoats = newSmallBoats.grouped(2).map(l => (l.head._1 + l.last._1, l.head._2 + " " + l.last._2)).toList
  val r = (pairsSmallBoats ::: bigBoats).sorted.reverse.take(v / 2)
  println(bigSmallBoat.map(_._1).getOrElse(0) + r.map(_._1).sum)
  println(r.map(_._2).mkString(bigSmallBoat.map(_._2 + " ").getOrElse(""), " ", ""))
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(n, v) = in.next().split(' ').map(_.toInt)
  val boats = in.take(n).toList.zipWithIndex.map(i => (i._1, (i._2 + 1).toString))
  val smallBoats = boats.filter(_._1.head == '1').map(i => (i._1.drop(2).toInt, i._2)).sorted.reverse
  val bigBoats: List[(Int, String)] = boats.filter(_._1.head == '2').map(i => (i._1.drop(2).toInt, i._2))
  val bigSmallBoat = if (v % 2 == 0) None else Some(smallBoats.head)
  val newSmallBoats = bigSmallBoat match {
    case None => smallBoats
    case Some(_) => smallBoats.tail
  }

  val pairsSmallBoats = newSmallBoats.sliding(2).map(l => (l.head._1 + l.last._1, l.head._2 + " " + l.last._2)).toList
  val r = (pairsSmallBoats ::: bigBoats).sorted.reverse.take(v / 2)
  println(bigSmallBoat.map(_._1).getOrElse(0) + r.map(_._1).sum)
  println(r.map(_._2).mkString(bigSmallBoat.map(_._2 + " ").getOrElse(""), "\n", ""))
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(n, v) = in.next().split(' ').map(_.toInt)
  val boats = in.take(n).toList.zipWithIndex.map(i => (i._1, (i._2 + 1).toString))
  val smallBoats = boats.filter(_._1.head == '1').map(i => (i._1.drop(2).toInt, i._2)).sorted.reverse
  val bigBoats: List[(Int, String)] = boats.filter(_._1.head == '2').map(i => (i._1.drop(2).toInt, i._2))
  val bigSmallBoat = if (v % 2 == 0) None else Some(smallBoats.head)
  val newSmallBoats = bigSmallBoat match {
    case None => smallBoats
    case Some(_) => smallBoats.tail
  }

  val pairsSmallBoats = newSmallBoats.sliding(2).map(l => (l.head._1 + l.last._1, l.head._2 + " " + l.last._2)).toList
  val r = (pairsSmallBoats ::: bigBoats).sorted.reverse.take(v / 2)
  println(bigSmallBoat.map(_._1).getOrElse(0) + r.map(_._1).sum)
  println(r.map(_._2).mkString(bigSmallBoat.map(_._2).getOrElse(""), "\n", ""))
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(n, v) = in.next().split(' ').map(_.toInt)
  val boats = in.take(n).toList.zipWithIndex.map(i => (i._1, (i._2 + 1).toString))
  val smallBoats = boats.filter(_._1.head == '1').map(i => (i._1.drop(2).toInt, i._2)).sorted.reverse
  val bigBoats: List[(Int, String)] = boats.filter(_._1.head == '2').map(i => (i._1.drop(2).toInt, i._2))
  val bigSmallBoat = if (v % 2 == 0) None else Some(smallBoats.head)
  val newSmallBoats = bigSmallBoat match {
    case None => smallBoats
    case Some(_) => smallBoats.tail
  }

  val pairsSmallBoats = newSmallBoats.sliding(2).map(l => (l.head._1 + l.last._1, l.head._2 + " " + l.last._2)).toList
  val r = (pairsSmallBoats ::: bigBoats).sorted.reverse.take(v / 2)
  println(bigSmallBoat.map(_._1).getOrElse(0) + r.map(_._1).sum)
  println(r.map(_._2).mkString(bigSmallBoat.map(_._2 + " ").getOrElse(""), " ", ""))
}

import java.util.Scanner

object Boats extends App {

  val scanner = new Scanner(System.in)

  val boatsNum = scanner.nextInt()
  val truckSize = scanner.nextInt()

  var light = List.empty[Boat]
  var heavy = List.empty[Boat]

  (1 until boatsNum + 1).foreach { cnt =>
    val t = scanner.nextInt()
    if (t == 1) {
      light :+= Boat(1, scanner.nextInt(), cnt)
    } else {
      heavy :+= Boat(2, scanner.nextInt(), cnt)
    }
  }

  light = light.sortBy(_.weight).reverse
  heavy = heavy.sortBy(_.weight).reverse

  var res = List.empty[Boat]

  solve(truckSize)

  def solve(sizeLeft: Int): Unit = {
    if (sizeLeft == 0) {
      printResult()
    } else if (sizeLeft == 1 && !light.isEmpty) {
      res :+= light.head
      printResult()
    } else if (light.isEmpty && heavy.isEmpty) {
      printResult()
    } else if(light.isEmpty) {
      res :+= heavy.head
      heavy = heavy.tail
      solve(sizeLeft - 2)
    } else if (heavy.isEmpty) {
      res :+= light.head
      light = light.tail
      solve(sizeLeft - 1)
    } else if (light.size == 1) {
      if (heavy.head.weight > light.head.weight) {
        res :+= heavy.head
        heavy = heavy.tail
        solve(sizeLeft - 2)
      } else {
        res :+= light.head
        light = light.tail
        solve(sizeLeft - 1)
      }
    } else {
      if (heavy.head.weight > light.head.weight + light.tail.head.weight) {
        res :+= heavy.head
        heavy = heavy.tail
        solve(sizeLeft - 2)
      } else {
        res :+= light.head
        light = light.tail
        res :+= light.head
        light = light.tail
        solve(sizeLeft - 2)
      }
    }
  }

  def printResult(): Unit = {
    println(res.foldLeft(0)((acc, t) => acc + t.weight))
    println(res.map(_.order).mkString)
  }

  case class Boat(size: Int, weight: Int, order: Int) {

  }

}

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

object Boats extends App {

  val scanner = new Scanner(System.in)

  val boatsNum = scanner.nextInt()
  val truckSize = scanner.nextInt()

  var light = mutable.PriorityQueue.empty[Boat]
  var heavy = mutable.PriorityQueue.empty[Boat]

  (1 until boatsNum + 1).foreach {
    cnt =>
      val t =scanner.next().toInt
      if (t == 1) {
        light += Boat(1, scanner.next().toInt, cnt)
      } else {
        heavy += Boat(2, scanner.next().toInt, cnt)
      }
  }

  var res = ""
  var sum = 0

  def append(b: Boat): Unit = {
    sum += b.weight
    res += " " + b.order
  }

  solve(truckSize)

  def solve(sizeLeft: Int): Unit = {
    if (sizeLeft == 0) {
      printResult()
    } else if (sizeLeft == 1 && !light.isEmpty) {
      append(light.head)
      printResult()
    } else if (sizeLeft == 1 && light.isEmpty) {
      printResult()
    } else if (light.isEmpty && heavy.isEmpty) {
      printResult()
    } else if (light.isEmpty) {
      append(heavy.head)
      heavy = heavy.tail
      solve(sizeLeft - 2)
    } else if (heavy.isEmpty) {
      append(light.head)
      light = light.tail
      solve(sizeLeft - 1)
    } else if (light.size == 1) {
      if (heavy.head.weight > light.head.weight) {
        append(heavy.head)
        heavy = heavy.tail
        solve(sizeLeft - 2)
      } else {
        append(light.head)
        light = light.tail
        solve(sizeLeft - 1)
      }
    } else {
      val f = light.dequeue()
      val s = light.head
      if (heavy.head.weight > s.weight + f.weight) {
        append(heavy.dequeue())
        light += f
        solve(sizeLeft - 2)
      } else {
        append(f)
        solve(sizeLeft - 1)
      }
    }
  }

  def printResult(): Unit = {
    println(res)
    println(sum)
  }

  case class Boat(size: Int, weight: Int, order: Int) extends Ordered[Boat] {
    override def compare(that: Boat): Int = this.weight.compareTo(that.weight)
  }

  /*
  * 20 19
2 47
1 37
1 48
2 42
2 48
1 38
2 47
1 48
2 47
1 41
2 46
1 28
1 49
1 45
2 34
1 43
2 29
1 46
2 45
2 18
  * */

}

import java.util.Scanner

object Boats extends App {

  val scanner = new Scanner(System.in)

  val boatsNum = scanner.nextInt()
  val truckSize = scanner.nextInt()

  var light = List.empty[Boat]
  var heavy = List.empty[Boat]

  (1 until boatsNum + 1).foreach { cnt =>
    val t = scanner.nextInt()
    if (t == 1) {
      light :+= Boat(1, scanner.nextInt(), cnt)
    } else {
      heavy :+= Boat(2, scanner.nextInt(), cnt)
    }
  }

  light = light.sortBy(_.weight).reverse
  heavy = heavy.sortBy(_.weight).reverse

  var res = List.empty[Boat]

  solve(truckSize)

  def solve(sizeLeft: Int): Unit = {
    if (sizeLeft == 0) {
      printResult()
    } else if (sizeLeft == 1 && !light.isEmpty) {
      res :+= light.head
      printResult()
    } else if (light.isEmpty && heavy.isEmpty) {
      printResult()
    } else if(light.isEmpty) {
      res :+= heavy.head
      heavy = heavy.tail
      solve(sizeLeft - 2)
    } else if (heavy.isEmpty) {
      res :+= light.head
      light = light.tail
      solve(sizeLeft - 1)
    } else if (light.size == 1) {
      if (heavy.head.weight > light.head.weight) {
        res :+= heavy.head
        heavy = heavy.tail
        solve(sizeLeft - 2)
      } else {
        res :+= light.head
        light = light.tail
        solve(sizeLeft - 1)
      }
    } else {
      if (heavy.head.weight > light.head.weight + light.tail.head.weight) {
        res :+= heavy.head
        heavy = heavy.tail
        solve(sizeLeft - 2)
      } else {
        res :+= light.head
        light = light.tail
        res :+= light.head
        light = light.tail
        solve(sizeLeft - 2)
      }
    }
  }

  def printResult(): Unit = {
    println(res.foldLeft(0)((acc, t) => acc + t.weight))
    println(res.map(_.order).mkString(" "))
  }

  case class Boat(size: Int, weight: Int, order: Int) {

  }

}

object P3B {
    def main(args : Array[String]) {
        val Array(n, v) = readLine split " " map {_.toInt}
        val a = Array.fill(n) {
            val Array(t, p) = readLine split " " map {_.toInt}
            (t, p)
        }.zipWithIndex groupBy {_._1._1}
        val a1 = a(1) sortBy {_._1._2}
        val s1 = a1.scanLeft(0){_ + _._1._2}
        val a2 = a(2) sortBy {_._1._2}
        val s2 = a2.scanLeft(0){_ + _._1._2}
        val vU = v min (a1.size + a2.size * 2)
        val s = for (i <- 0 to vU / 2) yield s1(vU - i * 2) + s2(i)
        val m = s.max
        println(m)
        val k = s indexOf m
        val w = ((a1 take vU - k * 2) ++ (a2 take k)) map {_._2 + 1}
        println(w.mkString)
    }
}

object P3B {
    def main(args : Array[String]) {
        val Array(n, v) = readLine split " " map {_.toInt}
        val a = Array.fill(n) {
            val Array(t, p) = readLine split " " map {_.toInt}
            (t, p)
        }.zipWithIndex groupBy {_._1._1}
        val a1 = a(1) sortBy {_._1._2}
        val s1 = a1.scanLeft(0){_ + _._1._2}
        val a2 = a(2) sortBy {_._1._2}
        val s2 = a2.scanLeft(0){_ + _._1._2}
        val vU = v min (a1.size + a2.size * 2)
        val s = for {
            i <- 0 to vU / 2
            if (vU - i * 2 < s1.size)
            if (i < s2.size)
        } yield s1(vU - i * 2) + s2(i)
        val m = s.max
        println(m)
        val k = s indexOf m
        val w = ((a1 take vU - k * 2) ++ (a2 take k)) map {_._2 + 1}
        println(w mkString " ")
    }
}


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

  override def apply(io: IO): io.type = {
    val n, a, b, c, t = io.read[Int]
    val ts = io.read[Vector, Int](n)
    val ans = ts.sumWith(i => a + (((c - b)*(t - i)) max 0))
    io.write(ans)
  }

  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](t: C[A]) {
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}

  }
}
/****************************[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

class IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {
  import IO._
  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: 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")

  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 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 {
  private[IO] type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]

  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.head)
    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
      }
    }
  }
}

object Solution {
  def main(args: Array[String]) {
    val r = new Reader
    val n, A, B, C, T = r.read[Int]
    val xs = r.read[Array[Int]](n).filter(_ <= T)

    if (B >= C) {
      println(A * xs.length)
    } else {
      println(xs.map(x => A + (T - x) * (C - B)).sum)
    }
  }
}

import java.io.{ BufferedReader, InputStreamReader }
import java.util.StringTokenizer

class Reader(br: BufferedReader) {
  def this(isr: InputStreamReader) = this(new BufferedReader(isr))
  def this() = this(new InputStreamReader(System.in))

  def read[A](implicit read: Reader.Read[A]): A = read.apply(this)

  val tokenizer = new Tokenizer(br)
}

object Reader {
  class Read[A](val apply: Reader => A) {}

  object Read {
    implicit val string: Read[String] = new Read(_.tokenizer.next)
    implicit val int: Read[Int] = new Read(_.read[String].toInt)
    implicit val long: Read[Long] = new Read(_.read[String].toLong)
    implicit val double: Read[Double] = new Read(_.read[String].toDouble)

    implicit def tuple[A: Read, B: Read]: Read[(A, B)] = new Read(r => (r.read[A], r.read[B]))

    import scala.collection.generic.CanBuildFrom

    // what the f*ck??
    implicit def t[T[A], A: Read](n: Int)(implicit bf: CanBuildFrom[Nothing, A, T[A]]): Read[T[A]] =
      new Read(r => Iterator.continually(r.read[A]).take(n).to[T])
  }
}

class Tokenizer(br: BufferedReader) extends Iterator[String] {
  def this(isr: InputStreamReader) = this(new BufferedReader(isr))

  def hasNext = hasMoreTokens || {
    if (tokenizers.hasNext) {
      tokenizers.next()
      hasMoreTokens
    } else false
  }

  def next() = if (hasNext) { tokenizers.head.nextToken } else null

  private def hasMoreTokens = tokenizers.headOption.map(_.hasMoreTokens).getOrElse(false)

  private val tokenizers =
    Iterator.continually(br.readLine).takeWhile(_ != null).filter(_ != "").map(new StringTokenizer(_)).buffered
}


import java.io._
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import util.control.Breaks._

object Solution {
    val reader = new BufferedReader(new java.io.InputStreamReader(System.in))
    val writer =  new PrintWriter(System.out)
    def readInt(): Int = reader.readLine().toInt
    def readLong(): Long = reader.readLine().toLong
    def readArrayInt(): Array[Int] = reader.readLine().split(" ").map(_.toInt)
    def readArrayLong(): Array[Long] = reader.readLine().split(" ").map(_.toLong)
    def readString(): String = reader.readLine()

    def multiTest(f: Int => Unit): Unit = {
        val t = readInt()
        for (i <- 1 to t) f(i)
    }

    def GCD(a: Int, b: Int): Int = {
        if (a == 0) return b
        GCD(b % a, a)
    }

    def solve(t: Int = 0): Unit = {
        val n = readInt()
        val s = readString()
        var c = 0
        val R = Array('R','B')
        val B = Array('B','R')
        var last: Char = '?'
        for (i <- 0 until n) {
            if (s(i) == '?') c += 1
            else if (s(i) == 'R') {
                last = 'R'
                if (c > 0) {
                    if (c % 2 == 0) {
                        var j = 0
                        while (c > 0) {
                            writer.print(R(j))
                            j += 1
                            if (j == 2) j = 0
                            c -= 1
                        }
                    } else {
                        var j = 0
                        while (c > 0) {
                            writer.print(B(j))
                            j += 1
                            if (j == 2) j = 0
                            c -= 1
                        }
                    }
                }
                writer.print('R')
            } else {
                last = 'B'
                if (c > 0) {
                    if (c % 2 == 0) {
                        var j = 0
                        while (c > 0) {
                            writer.print(B(j))
                            j += 1
                            if (j == 2) j = 0
                            c -= 1
                        }
                    } else {
                        var j = 0
                        while (c > 0) {
                            writer.print(R(j))
                            j += 1
                            if (j == 2) j = 0
                            c -= 1
                        }
                    }
                }
                writer.print('B')
            }
        }

        if (c > 0) {
            if (last == 'R') {
                var j = 0
                while (c > 0) {
                    writer.print(B(j))
                    j += 1
                    if (j == 2) j = 0
                    c -= 1
                }
            } else {
                var j = 0
                while (c > 0) {
                    writer.print(R(j))
                    j += 1
                    if (j == 2) j = 0
                    c -= 1
                }
            }
        }

        writer.println()
    }

    def main(args: Array[String]) {
        multiTest(solve)
        //solve()
        writer.flush()
    }
}

object B extends App {
  import scala.io.StdIn._
  import scala.collection.immutable.TreeSet

  val t = readInt()

  (0 until t).foreach { _ =>
    val n = readInt()
    val s = readLine()

    val ans = {
      val set = TreeSet((0 until n).filterNot(i => s(i) == '?'): _*)

      def minAfter: Int => Option[Int]  = i => set.rangeImpl(Some(i), None).headOption
      def maxBefore: Int => Option[Int] = i => set.rangeImpl(None, Some(i)).lastOption

      (0 until n).map {
        case i if s(i) == '?' =>
          (minAfter(i) orElse maxBefore(i)) match {
            case Some(j) =>
              if (i % 2 == j % 2) s(j)
              else if (s(j) == 'R') 'B'
              else 'R'
            case _       =>
              if (i % 2 == 0) 'B' else 'R'
          }
        case i                => s(i)
      }
        .mkString("")
    }

    println(ans)
  }
}

import scala.io.StdIn

object Problem extends App {

  start()

  def start() = {
    println(parseInput().map(s => findSequence(s).mkString).mkString("\n"))
  }

  def parseInput(): Array[Array[Char]] = {
    val testCases = StdIn.readLine.stripLineEnd.toInt
    var result = Array[Array[Char]]()
    for(_ <- 1.to(testCases)) {
      StdIn.readLine
      val line = StdIn.readLine().stripLineEnd.trim.toCharArray
      result ++= Array(line)
    }
    result
  }

  def findSequence(seq: Array[Char]): Array[Char] = {
    def not(c: Char): Char = if (c == 'B') 'R' else 'B'

    val firstWildChar = seq.indexOf('?')
    if (firstWildChar > 0) {
      seq(firstWildChar) = not(seq(firstWildChar-1))
      findSequence(seq)
    } else if(firstWildChar == 0) {
      if (seq.length == 1) "B".toCharArray else {
        val (c, rest) = seq.splitAt(1)
        val s = if (rest(0) != '?') {
          Array(not(rest(0))) ++ rest
        } else {
          val newRest = findSequence(rest)
          Array(not(newRest(0))) ++ newRest
        }
        findSequence(s)
      }
    } else {
      seq
    }
  }
}

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

object Solution {
  // all ?????
  def solve(input: String): String = {
    def opposite(ch: Char): Char = if (ch == 'B') 'R' else 'B'

    val current = input.toCharArray

    if (current.forall(_ == '?')) current(0) = 'B'

    while (current.contains('?')) {
      val (_, pos) = current.zip(current.tail).zipWithIndex.find { case ((ch1, ch2), _) =>
        (ch1 == '?' && ch2 != '?') || (ch1 != '?' && ch2 == '?')
      }.get
      if (current(pos) == '?') current(pos) = opposite(current(pos + 1))
        else current(pos + 1) = opposite(current(pos))
    }

    new String(current)
  }

  def run(test: Int, input: Scanner, output: PrintWriter): Unit = {
    val n = input.nextInt()
    input.nextLine()
    val s = input.nextLine().substring(0, n)
    output.println(solve(s))
  }

  def run(input: Scanner, output: PrintWriter): Unit = {
    val tests = input.nextInt()

    (1 to tests).foreach { test =>
      run(test, input, output)
      output.flush()
    }
  }

  def main(args: Array[String]): Unit = {
    run(new Scanner(System.in), new PrintWriter(System.out))
  }
}

import scala.io.StdIn

object Problem extends App {

  start()

  def start() = {
    println(parseInput().map(s => findSequence(s).mkString).mkString("\n"))
  }

  def parseInput(): Array[Array[Char]] = {
    val testCases = StdIn.readLine.stripLineEnd.toInt
    var result = Array[Array[Char]]()
    for(_ <- 1.to(testCases)) {
      StdIn.readLine
      val line = StdIn.readLine().stripLineEnd.trim.toCharArray
      result ++= Array(line)
    }
    result
  }

  def findSequence(seq: Array[Char]): Array[Char] = {
    def not(c: Char): Char = if (c == 'B') 'R' else 'B'

    val firstWildChar = seq.indexOf('?')
    if (firstWildChar > 0) {
      seq(firstWildChar) = not(seq(firstWildChar-1))
      findSequence(seq)
    } else if(firstWildChar == 0) {
      if (seq.length == 1) "B".toCharArray else {
        val (c, rest) = seq.splitAt(1)
        val s = if (rest(0) != '?') {
          Array(not(rest(0))) ++ rest
        } else {
          findSequence(rest)
        }
        findSequence(s)
      }
    } else {
      seq
    }
  }
}


object CodeforcesRound641a {

  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
    val primes: Array[Int] = primeNumbers(1e6.toInt)
    (1 to t).foreach(_ => test(primes))
  }

  def test(primes: Array[Int])
          (implicit
           reader: BufferedReader,
           writer: PrintStream): Unit = {
    val Array(n, k) = rll_int
    val leastPrimeFactor: Int =
      primes.iterator
        .collectFirst { case i if n % i == 0 => i }
        .getOrElse(n)
    val res = n + leastPrimeFactor + (k - 1) * 2
    writer.println(res)
  }

  def primeNumbers(n: Int): Array[Int] = {
    val a = new Array[Boolean](n + 1)
    a(0) = true
    a(1) = true
    (2 to Math.sqrt(n).toInt).foreach { i =>
      if (!a(i)) {
        (i * i to n by i).foreach(j => a(j) = true)
      }
    }
    a.iterator.zipWithIndex.collect { case (v, k) if !v => k }.toArray
  }

  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 extends App {

  private def isPrime(n: Int): Boolean = primes.takeWhile(p => p * p <= n).forall(n % _ != 0)

  private lazy val primes: Stream[Int] = 2 #:: Stream.iterate(3)(_ + 2).filter(isPrime)

  val t = scala.io.StdIn.readInt()

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

    val r = 2L * 0.max(k - 1) + n + primes.find(n % _ == 0).get

    println(r)
  }
}

object ProblemA extends App {
  import java.io.{BufferedReader, InputStreamReader, PrintWriter}
  import java.util.StringTokenizer
  val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))
  val out = new PrintWriter(System.out)

  class FastScanner(val in: BufferedReader) {
    var st: StringTokenizer = _;

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

    def nextInt(): Integer = {
      Integer.parseInt(nextToken());
    }

    def nextLong(): Long = {
      nextToken().toLong;
    }

    def nextDouble(): Double = {
      nextToken().toDouble;
    }
  }

  def divider(n: Int, startFrom: Int = 2): Int = {
    for (i <- startFrom to math.max(startFrom, math.sqrt(n).floor.toInt)) {
      if (n % i == 0) {
        return i
      }
    }
    n
  }

  @scala.annotation.tailrec
  def solve(sum: Int, k: Int): Int = {
    if (sum % 2 == 0) {
      k * 2 + sum
    } else {
      val d = divider(sum)
      val newSum = d + sum

      if (k == 1) {
        newSum
      } else {
        solve(newSum, k - 1)
      }
    }
  }

  val n = in.nextInt()

  for (i <- 1 to n) {
    val n = in.nextInt()
    val k = in.nextInt()

    println(solve(n, k))
  }

}

object A extends App {
  val t = scala.io.StdIn.readInt()

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

    val r = n + 2 * 0.max(k - 1) + (2 #:: Stream.iterate(3)(_ + 2)).find(n % _ == 0).get

    println(r)
  }
}


import java.util.Scanner

object CF_528_2_D {

//  case class Edge(v1: Int, v2: Int)

  type In = (Int, Int, Scanner)
  type Out = Double

  def solve(in: In): Out = {
    val (n, s, sc) = in
    // Divide the weights equally amongst the leaves
    // Then return the leaf weight x 2
    val connectCount = Array.ofDim[Int](n+1)
    while(sc.hasNextInt) {
      connectCount(sc.nextInt) += 1
    }
    val leafcount = connectCount.count(_ == 1)
    s.toDouble / leafcount * 2
  }

//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   Specify Input and Output formats on RHS here:

  def formatIn(i: Input): In       = (i.int, i.int, {
    i.nextLine;
    i.sc
  })
  def formatOut(out: Out): String  = out.toString

//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   Boilerplate & utility methods that don't change:

  import java.util.Scanner
  import java.io.InputStream
  import language.implicitConversions

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    val resultStr = new Input(System.in).solveStr
    out.println(resultStr)
    out.close()
  }

  class Input(val sc: Scanner) {
    // This class is useful for convenience, and for mock stdin in test scripts
    // Remember to call nextLine to advance past the newline character (if required) before taking a whole line
    def this(i: InputStream) =       this(new Scanner(i))
    def this(s: String) =            this(new Scanner(s.stripMargin))
    def int =                        sc.nextInt()
    def long =                       sc.nextLong()
    def double =                     sc.nextDouble()
    def nextLine =                   sc.nextLine()
    def collect[T](f: String => T) = sc.nextLine().split(" ").toVector.map(f)
    def intSeq =                     collect(_.toInt)
    def doubleSeq =                  collect(_.toDouble)
    def getLines: Vector[String] =   if (!sc.hasNextLine) Vector.empty
                                     else sc.nextLine +: getLines
    def solveVal: Out =              (solve _).tupled(formatIn(this))
    def solveStr: String =           formatOut(solveVal)
  }

  // Ceiling division for Int & Long
  def ceil(a: Int, b: Int)   = (a - 1)/b + 1
  def ceil(a: Long, b: Long) = (a - 1)/b + 1

  // A frequently used number
  val modulo = 1000000007

  // For convenience in test scripts, treat a String as an Input
  implicit def stringToInput(s: String): Input = new Input(s)
  // Required to make `solveVal` work when input has just 1 value (i.e. not a Tuple)
  implicit class makeTupledWorkOnFunction1[-T,+R](f: T => R) {
    def tupled: T => R = x => f(x)
  }
}

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

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

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

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

  def solve(): Unit = {
    val N, S = ni()
    val (from, to) = na2(N - 1, -1)
    val d = Array.ofDim[Int](N)
    REP(N - 1) { i =>
      d(from(i)) += 1
      d(to(i)) += 1
    }

    val cntDig1 = d.count(_ == 1)
    val ans = S.doubleValue() / cntDig1 * 2
    out.println(f"$ans%.9f")
  }

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

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

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

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

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

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


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 t = for(i <- 1 to n) yield sc.nextInt
  val mx = t.max
  val mn = t.min
  val imax = t.indexOf(mx)
  val imin = t.lastIndexOf(mn)
  println(imax + (n-imin-1) + (if(imax > imin) -1 else 0))
}

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

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

  val N = sc.nextInt
  val hights = Array.fill(N)(sc.nextInt)

  val answer: Int = {
    val minValue = hights.min
    val maxValue = hights.max

    val rightMostMinPos = (0 until N).filter(hights(_) == minValue).last
    val leftMostMaxPos = (0 until N).filter(hights(_) == maxValue).head
    N - rightMostMinPos - 1 + leftMostMaxPos - (if (rightMostMinPos < leftMostMaxPos) 1 else 0)
  }

  out.println(answer)
  out.close
}

import scala.collection.mutable.MutableList

object ArrivaloftheGeneral {
	def main (args: Array[String]) {
		val scanner = new java.util.Scanner(System.in);
		// Initialization
		val n = scanner.nextInt()
				var theList = new MutableList[Int];
		for (i <- 1 to n) {
			theList += scanner.nextInt
		}
		val theMin = theList.min
				val theMax = theList.max
				val indexMin = theList.lastIndexOf(theMin)
				val indexMax = theList.indexOf(theMax);
		if (indexMax > indexMin)
			println(indexMax + theList.size - indexMin - 2)
			else
				println(indexMax + theList.size - indexMin - 1)

	}
}

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

  val n  = readInt()
  val an = readLine().split(" ").map(_.toInt)

  val ((_, h), (_, l)) = an.tail.zipWithIndex.foldLeft((an.head, 0), (an.head, 0)) {
    case (state @ ((higher, h), (lower, l)), (height, i)) =>
      if (height > higher) ((height, i + 1), state._2)
      else if (height <= lower) (state._1, (height, i + 1))
      else state
  }

  val ans = h + (n - l - 1) - (if (l <= h) 1 else 0)

  println(ans)
}

object Main {
  def main(args: Array[String]) {
    val i = readInt()
    val a = readLine().split(" ").map(_.toInt)
    var max, maxi = 0
    var (min, mini) = (100, a.size - 1);
    for (i <- 0 until a.size) {
      val e = a(i)
      if (e > max) {
        max = e
        maxi = i
      }
      if (e <= min) {
        min = e
        mini = i
      }
    }
    if (mini < maxi) println(maxi + a.size - mini - 2)
    else println(maxi + a.size - mini - 1)
  }
}

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

object General {

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

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

     val maxSeconds = soldiers.indexOf(soldiers.max)
     val minSeconds = soldiers.reverse.indexOf(soldiers.min)
     println(maxSeconds + minSeconds + (if (n - minSeconds - 1 < maxSeconds) -1 else 0))
   }

}

object Main extends App{
        val n = readInt
        val a = readLine.split(" ").map(i => i.toInt)
        val max = a.indexOf(a.max)
        val min = a.lastIndexOf(a.min)
        var s = if (max > min) -1 else 0
        println (s + max + (n - 1 - min))
}

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

object App {

  def main(args: Array[String]) {

    var n = StdIn.readLine().toInt
    var A:Array[Int] = StdIn.readLine().split(" ").map(_.toInt)

    val min = A.zipWithIndex.filter(_._1 == A.min).last._2 + 1
    val max = A.zipWithIndex.filter(_._1 == A.max)(0)._2 + 1

    val l = A.length
    var ans = (max - 1) + (l - min)
    if(min < max)
      ans-=1

    println(ans)
  }

}

object Solution extends App {
  val n = readInt
  val s = readLine.split(" ").map(_.toLong)

  val min = s.min
  val max = s.max

  val minIdx = s.size - s.reverse.indexWhere(_ == min) - 1
  val maxIdx = s.indexWhere(_ == max)

  if(minIdx > maxIdx) {
    println(maxIdx + s.size - minIdx - 1)
  } else {
    println(maxIdx + s.size - minIdx - 2)
  }
}

object General {

  def main(args: Array[String]): Unit  = {
    val n: Int = readLine.toInt
    val aa: Seq[Int] = readLine.split(' ').map(_.toInt)

    val min = aa.min
    val max = aa.max
    val highest = aa.indexOf(max)
    val lowest = aa.lastIndexOf(min)
    val len = aa.length
    val result: Int = highest + (len - lowest) - 1 - (if (highest > lowest) 1 else 0)

    println(result)
  }

}

import scala.io.StdIn._

object ArrivalOfTheGeneral extends App {
  val n = readLine.toInt
  val soldiers = readLine.split(" ").map(_.toInt)

  var minpos = 0
  var maxpos = 0

  for (i <- 0 until n) {
    val s = soldiers(i)
    if (s <= soldiers(minpos))
      minpos = i
    if (s > soldiers(maxpos))
      maxpos = i
  }

  var res = n-minpos-1 + maxpos
  if (maxpos > minpos)
    res -= 1

  println(res)
}

object One44A extends App {
	import java.io.PrintWriter
	import java.util.Scanner
	val in = new Scanner(System.in)
	val out = new PrintWriter(System.out)
	import in._
	import out._
	val n = nextInt
	var min = (-1, -1)
	var max = (-1, -1)
	(0 until n).foreach { i =>
		val num = nextInt
		if (min._1 >= num || min._1 == -1) min = (num, i + 1)
		if (max._1 < num || max._1 == -1) max = (num, i + 1)
	}
	if (min._2 > max._2) {
		println(n - min._2 + max._2 - 1)
	} else {
		println(n - min._2 + max._2 - 2)
	}
	in.close
	out.close
}

object Main extends App {
	def getMinMaxIndexTurple(array: Array[Int], maxIndex: Int, minIndex: Int, pointer: Int): (Int, Int) = {
		if (pointer == array.size) (minIndex, maxIndex)
		else if (array(pointer) > array(maxIndex)) getMinMaxIndexTurple(array, pointer, minIndex, pointer + 1)
		else if (array(pointer) <= array(minIndex)) getMinMaxIndexTurple(array, maxIndex, pointer, pointer + 1)
		else getMinMaxIndexTurple(array, maxIndex, minIndex, pointer + 1)
	}

	val numberOfSoldiers = readLine.toInt
	val soldiersArray = readLine.split(" ").map(_.toInt)

	val (minIndex, maxIndex) = getMinMaxIndexTurple(soldiersArray, 0, 0, 1)

	if (maxIndex < minIndex) println(maxIndex + numberOfSoldiers - 1 - minIndex)
	else println(maxIndex + numberOfSoldiers - minIndex - 2)
}

object Solution144A extends App {

  def solution() {
    val n = _int
    val arr = 1.to(n).map(_ => _int)
    val mm = arr.foldLeft((100000, 0))((memo, h) => {
      (scala.math.min(h, memo._1), scala.math.max(h, memo._2))
    })
    //println(mm)
    val fioMax = arr.indexOf(mm._2)
    val lioMin = arr.lastIndexOf(mm._1)
//    println(fioMax)
//    println(lioMin)
    val adj = if (fioMax > lioMin) 1 else 0
    val res = fioMax + (arr.size - 1 - lioMin) - adj
    println(res)
  }

  //////////////////////////////////////////////////
  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 P144A extends App {
  readLine
  val soldiers = readLine.split(" ").map(_.toInt).zipWithIndex
  val max = soldiers.maxBy(_._1)
  var min = soldiers.min
  min = soldiers.reverse.dropWhile(_._1 != min._1).head
  print(max._2 + soldiers.length - 1 - min._2 - (if (max._2 > min._2) 1 else 0))
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(" ").map(_.toInt)
  val max = data.max
  val min = data.min
  val indexMax = data.indexOf(max)
  val indexMin = data.lastIndexOf(min)
  if (indexMax < indexMin)
    println(data.length + indexMax - indexMin - 1)
  else
    println(data.length + indexMax - indexMin - 2)
}

object Main {
    def main(args: Array[String]) {
        val n = readInt
        val a = readLine.split(" ").map(i => i.toInt)

        val max = a.indexOf(a.max)
        val min = a.lastIndexOf(a.min)

        var s = if (max > min) -1 else 0
        println (s + max + (n - 1 - min))
    }
}

import scala.collection.JavaConversions._
import scala.collection.mutable.ArraySeq

object Codeforces144A {
    def main(args: Array[String]) {
        val elemCount = scala.io.StdIn.readLine().toInt
        val elems = scala.io.StdIn.readLine().split(" ").map(_.toInt)
        var max = elems(0)
        var min = elems(0)
        var maxIndex = 0
        var minIndex = 0
        var seconds = 0
        for (i <- 0 until elemCount) {
            if (elems(i) <= min) {          // choose the rightmost minimum element
                min = elems(i)
                minIndex = i
            }
            if (elems(i) > max) {
                max = elems(i)
                maxIndex = i
            }
        }
        seconds += maxIndex
        if (minIndex > maxIndex) {
            seconds += elemCount - 1 - minIndex
        }
        if (minIndex < maxIndex) {
            seconds += elemCount - 1 - (minIndex + 1)
        }
        println(seconds)
    }
}

object A144 {
  @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 = readInts(n)
    val max = input.max
    val min = input.min

    var i = 0
    while(i < n && input(i) != max) {
      i += 1
    }
    var res = i
    while(i > 0) {
      val temp = input(i)
      input(i) = input(i-1)
      input(i-1) = temp

      i -= 1
    }

    i = n-1
    while(i > 0 && input(i) != min) {
      i -= 1
    }
    res += (n-i-1)
    println(res)
  }
}

object One44A extends App {
	import java.io.PrintWriter
	import java.util.Scanner
	val in = new Scanner(System.in)
	val out = new PrintWriter(System.out)
	import in._
	import out._
	val n = nextInt
	var min = (-1, -1)
	var max = (-1, -1)
	(0 until n).foreach { i =>
		val num = nextInt
		if (min._1 >= num || min._1 == -1) min = (num, i + 1)
		if (max._1 < num || max._1 == -1) max = (num, i + 1)
	}
	println(n - min._2 + max._2 - 1)
	in.close
	out.close
}

object P144A extends App {
  readLine
  val soldiers = readLine.split(" ").map(_.toInt).zipWithIndex
  val max = soldiers.maxBy(_._1)
  val min = soldiers.min
  print(max._2 + soldiers.length - 1 - soldiers.reverse.dropWhile(_._1 != min._1).head._2 -
    (if (max._2 > min._2) 1 else 0))
}

object P144A extends App {
  readLine
  val soldiers = readLine.split(" ").map(_.toInt).zipWithIndex
  print(soldiers.maxBy(_._1)._2 + soldiers.length - 1 - soldiers.minBy(_._1)._2)
}

object P144A extends App {
  readLine
  val soldiers = readLine.split(" ").map(_.toInt).zipWithIndex
  val max = soldiers.maxBy(_._1)
  val min = soldiers.min
  print(max._2 + soldiers.length - 1 - soldiers.reverse.dropWhile(_._1 != min._1).head._2 -
    (if (max._2 > min._2) -1 else 0))
}