Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.After how many full years will Limak become strictly larger (strictly heavier) than Bob?

The only line of the input contains two integers a and b (1 ≤ a ≤ b ≤ 10) — the weight of Limak and the weight of Bob respectively.

Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.

NoteIn the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.

object Problem extends App{
  val ln = readLine
  val vals = ln.split(" ")
  var a = vals(0).toInt
  var b = vals(1).toInt
  var counter = 0
  do{
    a *= 3
    b *= 2
    counter += 1
  } while (a <= b)
  println(counter)
}

object BearAndBigBrother extends App {

    val inputs = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    val liak = inputs(0)
    val bob = inputs(1)

    def solution(x: Int, y: Int): Int = {
        def helper(a: Int, b:Int, c: Int):Int = {

            if (a > b) c
            else {
                helper(a*3, b*2, c+1)
        }

    }
        helper(x,y,0)
}

    println(solution(liak,bob))
}

object tanya extends App{
var twoNum = readLine().split(" ")
var a = twoNum(0).toInt
var b = twoNum(1).toInt
var c = 0

while(a <= b){
    c += 1
    a = a * 3
    b = b * 2
}
println(c)
}

//package solutions

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

import scala.math

/**
  * @author traff
  */

object SolTaskA extends App {
  override def main(args: Array[String]): Unit = {
    val out = new PrintWriter(System.out)

    run(new Scanner(System.in), out)

    out.close()
  }

  def run(s: Scanner, out: PrintWriter): Unit = {
    val a = s.nextInt()
    val b = s.nextInt()

    val n = (math.log(b) - math.log(a)) / (math.log(3) - math.log(2))
    var res = math.ceil(n).toInt
    if (res < n + 0.0000001) {
      res += 1
    }
    out.print(res)
  }
}

import scala.io.StdIn

object BearAndBigBrother extends App {

  val l1 = StdIn.readLine().split(" ")
  val a = l1(0).toInt
  val b = l1(1).toInt
  print(impl(a, b))

  def impl(a: Int, b: Int): Int = {
    var years = 0
    var currA = a
    var currB = b
    while (currA <= currB) {
      currA = 3 * currA
      currB = 2 * currB
      years += 1
    }
    years
  }
}

import scala.io.StdIn.readLine
object BearBrother extends App
{
    val input = readLine().split(' ').map(_.toInt)
    var sum = 0
    var a: Int = input(0)
    var b: Int = input(1)
    while(!(a > b))
    {
        a *= 3
        b *= 2
        sum += 1
    }
    println(sum)
}

import scala.io.StdIn.readLine

object A791 {
  def main(args: Array[String]): Unit = {
    val List(limak, bob) = readToListInts
    println(solve(limak, bob))
  }

  def solve(limak: Int, bob: Int): Int = {
    def aux(a: Int, b: Int, count: Int): Int = {
      if (a > b) {
        count
      } else {
        aux(a*3, b*2, count + 1)
      }
    }
    aux(limak, bob, 0)
  }

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

import io.StdIn._
object BearAndBigBrother {

  def main(args: Array[String]): Unit = {
    var inputs:Array[Int] = readLine().split(" ").map(t=> s"$t".toInt)
    var i = 0
    while(inputs(0) <= inputs(1)){
      inputs(0) *= 3
      inputs(1) *= 2
      i += 1
    }
    println(i)
  }

}

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

  override def apply(io: IO) = {import io.{read, readAll, write, writeAll, writeLine}
    val a, b = read[Long]
    write(solve(a, b))
  }

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

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

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

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

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

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

  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 {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                      : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

import java.util.Scanner

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

    var a = sc.nextInt()
    var b = sc.nextInt()

    var flag = true

    var ans = 0
    while(flag){
      ans += 1
      a = a*3
      b = b*2

      if(a > b)
        flag = false
    }

    println(ans)
  }
}

object BearandBigBrother791A // extends TSolver {
                     extends App {
    import java.io.{InputStream, PrintStream}
    import java.util.Scanner
    solve(System.in,System.out)
    def solve(in: InputStream, out: PrintStream): Unit = {
      val scanner = new Scanner(in)
      val a = scanner.nextInt()
      val b = scanner.nextInt()

      val numYears = (1 to 10).
        scanLeft((a,b,0: Int)){case ((ap,bp,_),year) => (ap*3,bp*2,year)}.
        filter{case (at,bt,_) => at>bt}.
        head._3

      out.println(numYears)

    }
}

import scala.io.StdIn

object Codeforces791a extends App {
  var Array(a, b) = StdIn.readLine().split("\\s").map(s => s.toInt)
  var years = 0
  while (a <= b) {
    a *= 3
    b *= 2
    years += 1
  }
  println(years)
}

import java.util.Scanner

object Main2 {
  def main(args: Array[String]): Unit = {
    val scanner = new Scanner(System.in)
    val limakWeight = scanner.nextInt()
    val bobWeight = scanner.nextInt()
    println(Math.ceil(Math.log(bobWeight.toDouble / limakWeight + 0.00001)/Math.log(1.5)).toInt)
  }
}

/**
  * Created by ruslan on 3/18/17.
  */
object ProblemA extends App {

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

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

    val br = new BufferedReader(new InputStreamReader(System.in))
    var st: StringTokenizer = null
    val out = new PrintWriter(System.out)

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

    def nextInt: Int = next.toInt

    var massLimak: Long = nextInt
    var massBoba: Long = nextInt
    var res = 0

    while (massLimak <= massBoba) {
      res += 1
      massLimak *= 3
      massBoba *= 2
    }

    println(res)

  }
}

import scala.io.StdIn._
import scala.math.pow

object TaskA extends App {
  var a :: b :: Nil = readLine().split(" ").map(_.toInt).toList
  var year = 1
  while (a * pow(3, year) <= b * pow(2, year)) year += 1
  print(year)
}

import scala.io.StdIn._

object Solution {
	var Array(a, b) = readLine.split(" ").map(_.toInt)

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

		var n = 0
		while(a <= b) {
			a *= 3
			b *= 2
			n += 1
		}
		println(n)

	}
}

object BearAndBigBrother extends App {

    val inputs = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    val liak = inputs(0)
    val bob = inputs(1)

    def solution(x: Int, y: Int): Int = {
        def helper(a: Int, b:Int, c: Int):Int = {
            if (a == b) 1
            else if (a > b) c
            else {
                helper(a*3, b*2, c+1)
        }

    }
        helper(x,y,2)
}

    println(solution(liak,bob))
}

object BearAndBigBrother extends App {

    /*val weights = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    var iLiak = weights(0)
    var iBob = weights(1)
    var years = 1
    while(iLiak <= iBob){
        iLiak*=3
        iBob*=2
        years +=1
    }
    println(years)

    */
    val inputs = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    val liak = inputs(0)
    val bob = inputs(1)

    def solution(x: Int, y: Int): Int = {
        def helper(a: Int, b:Int, c: Int):Int = {
            if (a == b) 1
            else if (a > b) c
            else {
                helper(a*3, b*2, c+1)
        }

    }
        helper(x,y,0)
}

    println(solution(liak,bob))
}

object BearAndBigBrother extends App {
    def solution(x: Int, y: Int): Int = {
        def helper(a: Int, b:Int, c: Int):Int = {
            if (a == b) 1
            else if (a > b) c
            else {
                helper(a*3, b*2, c+1)
            }
        }
        helper(x,y,1)
    }
    println(solution(4,7))
}

object BearAndBigBrother extends App {

    val inputs = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    val liak = inputs(0)
    val bob = inputs(1)

    def solution(x: Int, y: Int): Int = {
        def helper(a: Int, b:Int, c: Int):Int = {
            if (a == b) 1
            else if (a > b) c
            else {
                helper(a*3, b*2, c+1)
        }

    }
        helper(x,y,1)
}

    println(solution(liak,bob))
}

object tanya extends App{
var twoNum = readLine().split(" ")
var a = twoNum(0).toInt
var b = twoNum(1).toInt

for (n <- 1 to b){
if(a % 10 == 0){
    a = a/10
}else{
    a = a - 1
}
}
println(a)
}

object tanya extends App{
var twoNum = readLine().split(" ")
var a = twoNum(0).toInt
var b = twoNum(1).toInt
var c = 0

while(a < b){
    c += 1
    a = a * 3
    b = b * 2
}
println(c)
}

import scala.io.StdIn.readLine

object A791 {
  def main(args: Array[String]): Unit = {
    val List(limak, bob) = readToListInts
    println(solve(limak, bob))
  }

  def solve(limak: Int, bob: Int): Int = {
    def aux(a: Int, b: Int, count: Int): Int = {
      if (a >= b) {
        count
      } else {
        aux(a*3, b*2, count + 1)
      }
    }
    aux(limak, bob, 0)
  }

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

import scala.io.StdIn

object Codeforces971A extends App {
  val Array(a, b) = StdIn.readLine().split("\\s").map(a => a.toDouble)

  if (a == b) {
    println("1")
  } else {
    val r = Math.log(b/a) / (Math.log(3) - Math.log(2))
    println(Math.ceil(r).toInt.toString)
  }
}

import java.util.Scanner

object Main2 {
  def main(args: Array[String]): Unit = {
    val scanner = new Scanner(System.in)
    val limakWeight = scanner.nextInt()
    val bobWeight = scanner.nextInt()
    println(Math.ceil(Math.log(((bobWeight + 0000.1) / limakWeight))/Math.log(1.5)).toInt)
  }
}


Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.There are n teams taking part in the national championship. The championship consists of n·(n - 1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.

The first line contains an integer n (2 ≤ n ≤ 30). Each of the following n lines contains a pair of distinct space-separated integers hi, ai (1 ≤ hi, ai ≤ 100) — the colors of the i-th team's home and guest uniforms, respectively.

In a single line print the number of games where the host team is going to play in the guest uniform.

NoteIn the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).

object Two68A 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
	val arr = new Array[(Int, Int)](n)
	for (i <- 0 until n) {
		arr(i) = (nextInt, nextInt)
	}
	var sum = 0
	for (i <- 0 until n; j <- i + 1 until n) {
		val x1 = arr(i)
		val x2 = arr(j)
		if (x1._1 == x2._2) sum += 1
		if (x2._1 == x1._2) sum += 1
	}
	println(sum)
	in.close
	out.close
}

import scala.annotation.tailrec
import scala.io.StdIn.readInt
import scala.io.StdIn.readLine

object Main extends App {
  case class Team(homeColor: Int, guestColor: Int)

  val n = readInt()
  val teams = (for {
    _ <- 0 until n
    Array(hColor, gColor) = readLine().split(" ").map(_.toInt)
  } yield Team(hColor, gColor)).toList

  val ans = teams.foldLeft(0)((sum, host) => sum + count(host, teams, 0))
  println(ans)

  @tailrec
  def count(host: Team, others: List[Team], acc: Int): Int = others match {
    case Nil => acc
    case x :: xs =>
      if (x.guestColor == host.homeColor) count(host, xs, acc + 1)
      else count(host, xs, acc)
  }
}

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

object Main extends App {
  val n = StdIn.readInt()
  val array = ArrayBuffer[(Int, Int)]()

  for (_ <- 1 to n) {
    val str = StdIn.readLine().split(" ").map(_.toInt)
    array += ((str(0), str(1)))
  }

  var count = 0

  for (i <- 1 to n) {
    for (j <- (i + 1) to n) {
      if (array(i - 1)._1 == array(j - 1)._2) count += 1
      if (array(i - 1)._2 == array(j - 1)._1) count += 1
    }
  }

  println(count)
}

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, sc.nextInt)
  var cnt = 0
  for(i <- t) for(j <- t) if(i._1 == j._2) cnt += 1
  println(cnt)
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = Range(0, n).map{ i => in.next().split(" ")}
  println(data.map(el => data.count{t => t.last == el.head}).sum)
}

object Main {
  def main(args: Array[String]) {
    val n = readLine().toInt
    val h = new Array[Int](n)
    val a = new Array[Int](n)
    for (i <- 0 to n-1) {
      val Array(vh, va) = readLine().split(" ").map(_.toInt)
      h(i) = vh
      a(i) = va
    }

    println((for (x <- h.iterator; y <- a.iterator) yield (x, y)).filter(x => x._1 == x._2).length)
  }
}

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

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

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

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

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

    var res = 0
    for(i <- 0 until n) {
      for(j <- 0 until n if i != j) {
        if(input(i)(0) == input(j)(1)) res += 1
      }
    }

    println(res)
  }
}

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

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

  val N = sc.nextInt
  val hs = new Array[Int](N)
  val as = new Array[Int](N)
  for (i <- 0 until N) {
    hs(i) = sc.nextInt
    as(i) = sc.nextInt
  }

  val answer: Int = {
    for {
      h <- hs
      a <- as
      if h == a
    } yield 1
  } sum

  out.println(answer)
  out.close
}

object Games {
	def main (args: Array[String]) {
		val scanner = new java.util.Scanner(System.in);
		val n = scanner.nextInt();
		// Parsing input
		var teams = new Array[(Int,Int)](n);
		for (i <- 0 to n-1) {
		  teams(i) = (scanner.nextInt(), scanner.nextInt());
		}
		// Computation
		var output = 0
		for (i <- 0 to n-1) {
		  for (j <- 0 to n-1) {
		    if (i!=j) {
		      val (home,_) = teams(i)
		      val (_, guest) = teams(j)
		      if (home == guest)
		        output += 1
		    }
		  }
		}
		println(output)
	}
}

object Matchi extends App {
  var ss = (Console.readLine.split(" ")) map (_.toInt)
  val n = ss(0)

  def readMatches(nn:Int):List[(Int,Int)] =
    if (nn == 0) List()
    else {
        val sss = (Console.readLine.split(" ")) map (_.toInt)
        (sss(0), sss(1)) :: readMatches(nn-1)
    }

  def cntMatch(pl:List[(Int,Int)], ac:Int, bc:Int):Int =
  	pl match {
  	case Nil => 0
  	case (a,b) :: tl => ((if (b==ac) 1 else 0) +
  		(if (a==bc) 1 else 0) +
  		cntMatch(tl, ac,bc))
  	}                                         //> cntMatch: (pl: List[(Int, Int)], ac: Int, bc: Int)Int

  def cntSame(pl:List[(Int,Int)]):Int =
  	pl match {
  	case Nil => 0
  	case (a,b) :: tl => cntMatch(tl, a,b) + cntSame(tl)
  	}

  val pl = readMatches(n)
  println(cntSame(pl))
}

object A
{
    def main(args: Array[String])
    {
        val n = readLine().toInt
        val colors=Array.ofDim[Int](n,2)
        for (i <- 0 until n)
        {
            colors(i)=readLine.split(" ").map(_.toInt)
        }
        println((for(x<- colors.iterator; y<-colors.iterator) yield(x,y)).filter(x => x._1(0) == x._2(1)).length)
    }
}

import java.util._

object CF268A {

    def main(args: Array[String]) {
        var list1 = Array[Int]()
        var list2 = Array[Int]()
        val in = new Scanner(System.in)

        val n = in.nextInt

        for (i <- 0 to n - 1) {
            list1 = list1 :+ in.nextInt
            list2 = list2 :+ in.nextInt
        }

        var count = 0
        for (i <- 0 to n - 1) {
            for (j <- 0 to n - 1) {
                if (i != j && list2(j) == list1(i)) {
                    count += 1
                }
            }
        }

        println(count)
    }

}

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

object test5 extends App {
    val n=readLine.toInt
    val colors=Array.ofDim[Int](n,2)
    for(i<-0 until n){
        colors(i)=readLine.split(" ").map(_.toInt)
    }

    val list=for(i<-0 until n; j<-0 until n if i!=j) yield
        if(colors(i)(0)==colors(j)(1)) 1 else 0

    println(list.sum)
}

object Main {
  def main(args: Array[String]) {
    val num = readInt()
    var s = List[(Int, Int)]()
    for (i <- 0 until num) {
      val a = readLine().split(" ").map(_.toInt)
      s = (a(0), a(1)) :: s
    }
    val r = s.foldLeft(0) { (acc, t) =>
      acc + s.foldLeft(0) { (acc, tt) => if (t._1 == tt._2) acc + 1 else acc }
    }
    println(r)
  }
}

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 problem extends App {
  val cin = new Scanner(System.in)
  val n = cin.nextInt()
  var cnt = 0
  val t = for(i <- 1 to n) yield (cin.nextInt(), cin.nextInt())
  for(i <-  t) for(j <- t) if(i._1 == j._2) cnt += 1
  println(cnt)
}

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

object Games {

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

   def main(args: Array[String]) {
     val n = readInt
     val colors = for {
       i <- 1 to n
       line = readInts
     } yield(line(0),line(1))
     val games =
       for {
         i <- 0 to n-1
         j <- 0 to n-1
         if (i != j)
       } yield (i,j)
     println(games.count(p => colors(p._1)._1 == colors(p._2)._2))
   }

}

import scala.Math.pow;
import scala.collection.mutable.LinkedList

object App {
	def readInts:Array[Int] = (readLine split " ") map (_.toInt)
                                                  //> readInts: => Array[Int]                              //> solve: (n: Int, m: Int, prev: Int, a: Int, b: Int)(Int, Int)

	def f1_io() = {
		val Array(n) = readInts
		val homeColor = new Array[Int](n)
		val outColor = new Array[Int](n)
		for (i <- 1 to n) {
		  val a = readInts
		  homeColor(i - 1) = a(0)
		  outColor(i - 1) = a(1)
		}

		print ((homeColor map (x => (outColor filter (y => x == y)).length)).sum)
	}
  def main(args: Array[String]): Unit = {
	f1_io
  }

}

  object Games extends App {
  	def resolve(): Int = {
  		var hs = Map[Int, Int]()
  		var as = Map[Int, Int]()

  		val lines = io.Source.stdin.getLines.toList.tail

  		for (elem <- lines) {
  			val (homekit: Int, awaykit: Int) = {
  				val tokens = elem.split(" ")
  				(tokens(0).toInt, tokens(1).toInt)
  			}

  			hs = hs + (homekit -> (hs.getOrElse(homekit, 0) + 1))
  			as = as + (awaykit -> (as.getOrElse(awaykit, 0) + 1))
  		}

  		var sum = 0
  		for ((k, v) <- hs) {
  			sum += v * as.getOrElse(k, 0)
  		}

  		sum
  	}

	print(resolve())
  }

object A00268 extends App {
  def parseInt(str: String, count: Int): Seq[Int] = {
    val scanner = new java.util.Scanner(str)
    val res = (1 to count) map (_ => scanner.nextInt())
    scanner.close()
    res
  }
  def scanInts(count: Int): Seq[Int] = parseInt(Console.readLine, count)
  def readMatrix(row: Int, col: Int) = (1 to row) map (x => scanInts(col))

  def oneIntLine = {
    val Seq(count) = parseInt(Console.readLine(), 1);
    count
  }

  def frequency[T](seq: Seq[T]) = seq.groupBy(identity).mapValues(_.size).withDefaultValue(0)

  val nTeams = oneIntLine
  val colors = readMatrix(nTeams, 2)
  val guestColorFreq = frequency(colors.map(_(1)))
  val result = colors.map(x => guestColorFreq(x(0))).sum
  println(result)
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  println(in.next().split("WUB").filter(_.nonEmpty).mkString(" "))
}

  object Games extends App {
  	def resolve(): Int = {
  		var hs = Map[Int, Int]()
  		var as = Map[Int, Int]()

  		val lines = io.Source.stdin.getLines.toList.tail

  		for (elem <- lines) {
  			val (homekit: Int, awaykit: Int) = {
  				val tokens = elem.split(" ")
  				(tokens(0).toInt, tokens(1).toInt)
  			}

  			hs = hs + (homekit -> (hs.getOrElse(homekit, 0) + 1))
  			as = as + (awaykit -> (as.getOrElse(awaykit, 0) + 1))
  		}

  		var sum = 0
  		for ((k, v) <- hs) {
  			sum += v * as.getOrElse(k, 0)
  		}

  		sum
  	}
  }


You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:   the i-th letter occurs in the string no more than ai times;  the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once.

The first line of the input contains a single integer n (2  ≤  n  ≤  26) — the number of letters in the alphabet. The next line contains n integers ai (1 ≤ ai ≤ 109) — i-th of these integers gives the limitation on the number of occurrences of the i-th character in the string.

Print a single integer — the maximum length of the string that meets all the requirements.

NoteFor convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc".

/**
  * Created by octavian on 06/02/2016.
  */
object MakeClass {

  val INF = 1000000005

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

    //System.setIn(new FileInputStream("./src/makeClass.in"))
    //System.setOut(new PrintStream(new FileOutputStream("./src/makeClass.out")))

    val N = readInt()
    val vals = readLine().split(" ").map(_.toInt).sorted

    var res: BigInt = 0
    var last = INF
    for(i <- vals.length - 1 to 0 by -1) {
      val toAdd = Math.min(vals(i), last - 1)
      last = toAdd
      if(toAdd > 0) {
        res += toAdd
      }
    }

    println(res)

  }

}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt
  var used = Set.empty[Int]
  println(in.next().split(' ').map(_.toInt).zipWithIndex.foldLeft(0l) {
    case (acc, (count, index)) =>
      var nc = count
      while (nc > 0 && used.contains(nc)) nc -= 1
      if (nc != 0) {
        used += nc
      }
      acc + nc
  })
}

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

import scala.annotation.implicitNotFound
import scala.collection.mutable
import scala.reflect.ClassTag

/**
  * Created by nimas on 2/4/16.
  */
object MakingAString extends App{

  class Template(val delim: String = " ") {

    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))
    val it = Iterator.iterate(new StringTokenizer(""))(tok => if (tok.hasMoreTokens) tok else new StringTokenizer(in.readLine(), delim))

    def nextTs[T: ParseAble](n: Int)(delim: String = " ")(implicit ev: ClassTag[T]) = (Array fill n) {
      nextT[T](delim)
    }

    def nextT[T: ParseAble](delim: String = " ") = {
      val x = it.find(_.hasMoreTokens)
      implicitly[ParseAble[T]].parse(x get)
    }

    def close(): Unit = {
      in.close()
      out.close()
    }

    @implicitNotFound("No member of type class ParseAble in scope for ${T}")
    trait ParseAble[T] {
      def parse(strTok: StringTokenizer): T
    }

    object ParseAble {

      implicit object ParseAbleInt extends ParseAble[Int] {
        override def parse(strTok: StringTokenizer): Int = strTok nextToken() toInt
      }

      implicit object ParseAbleLong extends ParseAble[Long] {
        override def parse(strTok: StringTokenizer): Long = strTok nextToken() toLong
      }

      implicit object ParseAbleDouble extends ParseAble[Double] {
        override def parse(strTok: StringTokenizer): Double = strTok nextToken() toDouble
      }

      implicit object ParseAbleBigInt extends ParseAble[BigInt] {
        override def parse(strTok: StringTokenizer): BigInt = BigInt(strTok nextToken())
      }

    }

  }

  val io = new Template()

  import io._

  val n = nextT[Int]()
  val a = nextTs[Long](n)() sorted Ordering.Long

  val map = new mutable.HashMap[Long, Boolean]()

  out.println((a.iterator map {
    x => {
      if (map getOrElse(x, true)) {
        map put(x, false)
        x
      } else {
        val find = x - 1 to(1, -1) find {
          !map.contains(_)
        } getOrElse 0l
        if (find != 0) map put(find, false)
        find
      }
    }
  }).sum)

  close()

}

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

object _624B extends CodeForcesApp {
  override type Result = Long

  override def solve(read: Scanner) = {
    val n = read[Int]
    val seen = mutable.Set.empty[Long]
    @tailrec def add(i: Long): Unit = if (seen(i)) add(i-1) else if (i > 0) {val _ = seen += i}
    repeat(n)(add(read[Long]))
    seen.sum
  }

  def repeat(n: Int)(f: => Unit): Unit = (1 to n).foreach(_ => 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: Scanner): Result
  def format(result: Result): String
  def apply(scanner: Scanner): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io.{BufferedReader, Reader, InputStreamReader, StringReader, InputStream}
import java.util.StringTokenizer

class Scanner(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(_)).filter(_.hasMoreTokens)
  private[this] var current: Option[StringTokenizer] = None

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

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

  def nextLine(): String = tokenizer().get.nextToken("\n\r")
  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty
  override def close() = reader.close()
}

trait Parser[A] {
  def apply(s: String): A
}
object Parser {
  def apply[A](f: String => A) = new Parser[A] {
    override def apply(s: String) = f(s)
  }
  implicit val tokenString: Parser[String] = Parser(identity)
  implicit val tokenChar: Parser[Char] = Parser(s => s.ensuring(_.length == 1, s"Expected Char; found $s").head)
  implicit val tokenBool: Parser[Boolean] = Parser(_.toBoolean)
  implicit val tokenInt: Parser[Int] = Parser(_.toInt)
  implicit val tokenLong: Parser[Long] = Parser(_.toLong)
  implicit val tokenBigInt: Parser[BigInt] = Parser(BigInt(_))
  implicit val tokenDouble: Parser[Double] = Parser(_.toDouble)
  implicit val tokenBigDecimal: Parser[BigDecimal] = Parser(BigDecimal(_))
}

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

object _624B extends CodeForcesApp {
  override type Result = Long

  override def solve(read: InputReader) = {
    val n = read[Int]
    val seen = mutable.Set.empty[Long]
    @tailrec def add(i: Long): Unit = if (seen(i)) add(i-1) else if (i > 0) {val _ = seen += i}
    repeat(n)(add(read[Long]))
    seen.sum
  }

  def repeat(n: Int)(f: => Unit): Unit = (1 to n).foreach(_ => 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 {i <- 1 to n} builder += apply[A]
    builder.result()
  }

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

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

trait Parser[A] {
  def apply(reader: InputReader): A
}
object Parser {
  def apply[A](f: String => A) = new Parser[A] {
    override def apply(reader: InputReader) = f(reader.next())
  }
  type Collection[C[_], A] = scala.collection.generic.CanBuildFrom[C[A], A, C[A]]
  implicit def collectionParser[C[_], A: Parser](implicit cbf: Collection[C, A]): Parser[C[A]] = new Parser[C[A]] {
    override def apply(reader: InputReader) = reader[C, A](reader[Int])
  }
  implicit val stringParser: Parser[String] = Parser(identity)
  implicit val charParser: Parser[Char] = Parser(s => s.ensuring(_.length == 1, s"Expected Char; found $s").head)
  implicit val booleanParser: Parser[Boolean] = Parser(_.toBoolean)
  implicit val intParser: Parser[Int] = Parser(_.toInt)
  implicit val longParser: Parser[Long] = Parser(_.toLong)
  implicit val bigIntParser: Parser[BigInt] = Parser(BigInt(_))
  implicit val doubleParser: Parser[Double] = Parser(_.toDouble)
  implicit val bigDecimalParser: Parser[BigDecimal] = Parser(BigDecimal(_))
}

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

object _624B extends CodeForcesApp {
  override type Result = Long

  override def solve(read: InputReader) = {
    val n = read[Int]
    val seen = mutable.Set.empty[Long]
    @tailrec def add(i: Long): Unit = if (seen(i)) add(i-1) else if (i > 0) {val _ = seen += i}
    repeat(n)(add(read[Long]))
    seen.sum
  }

  def repeat(n: Int)(f: => Unit): Unit = (1 to n).foreach(_ => 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(next())

  def tillEndOfLine(): String = tokenizer().get.nextToken("\n\r")
  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty
  override def close() = reader.close()
}

trait Parser[A] {
  def apply(s: String): A
}
object Parser {
  def apply[A](f: String => A) = new Parser[A] {
    override def apply(s: String) = f(s)
  }
  implicit val stringParser: Parser[String] = Parser(identity)
  implicit val charParser: Parser[Char] = Parser(s => s.ensuring(_.length == 1, s"Expected Char; found $s").head)
  implicit val booleanParser: Parser[Boolean] = Parser(_.toBoolean)
  implicit val intParser: Parser[Int] = Parser(_.toInt)
  implicit val longParser: Parser[Long] = Parser(_.toLong)
  implicit val bigIntParser: Parser[BigInt] = Parser(BigInt(_))
  implicit val doubleParser: Parser[Double] = Parser(_.toDouble)
  implicit val bigDecimalParser: Parser[BigDecimal] = Parser(BigDecimal(_))
}

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

object _624B extends CodeForcesApp {
  override type Result = Long

  override def solve(scanner: Scanner) = {
    import scanner._
    val seen = mutable.Set.empty[Long]
    @tailrec def add(i: Long): Unit = if (seen(i)) add(i-1) else if (i > 0) seen += i
    repeat(nextInt())(add(nextLong()))
    seen.sum
  }

  def repeat(n: Int)(f: => Unit): Unit = (1 to n).foreach(_ => 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)
  val mod: Int = 1000000007
  type Result
  def solve(scanner: Scanner): Result
  def format(result: Result): String
  def apply(scanner: Scanner): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer

import scala.io.Codec

/**
 * Scala implementation of a faster java.util.Scanner
 * See: http://codeforces.com/blog/entry/21125
 * All next methods throw NoSuchElementException when !hasNext
 */
class Scanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))
  def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))
  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)
  def this(str: String) = this(new StringReader(str))

  val lines = Iterator.continually(reader.readLine()).takeWhile(_ != null)

  private[this] val tokenizers = lines.map(new StringTokenizer(_)).filter(_.hasMoreTokens)
  private[this] var current: Option[StringTokenizer] = None

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

  /**
   * Unlike Java's scanner which returns till end of current line, this actually returns the next line
   * @see line() if you want the Java behaviour
   */
  def nextLine(): String = {
    current = None   // reset
    lines.next()
  }
  def lineNumber: Int = reader.getLineNumber
  def line(): String = tokenizer().get.nextToken("\n\r")
  def nextString(): String = next()
  def nextChar(): Char = next().ensuring(_.length == 1).head
  def nextBoolean(): Boolean = next().toBoolean
  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)
  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)
  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)
  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)
  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)
  def nextFloat(): Float = next().toFloat
  def nextDouble(): Double = next().toDouble
  def nextBigDecimal(): BigDecimal = BigDecimal(next())
  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty
  override def close() = reader.close()
}

/**
  * Created by Andrew Tsibin https://github.com/Evilnef.
  */
object Problemset624 {
  def main(args: Array[String]): Unit = {
    val problem = new ProblemB
    problem.solve()
  }

  private abstract class Problem {
    def solve()
  }

  private class ProblemA extends Problem {
    override def solve(): Unit = {
      val Array(d, l, v1, v2) = scala.io.StdIn.readLine().split(" ").map(_.toDouble)
      val result = (l - d) / (v1 + v2)
      println(result)
    }
  }

  private class ProblemB extends Problem {
    override def solve(): Unit = {
      var maxStringLengths: BigInt = 0
      val n = scala.io.StdIn.readInt()
      val a = scala.io.StdIn.readLine().split(" ").map(BigInt(_)).sortWith(_ > _)
      for (i <- a.indices) {
        if (i == 0) maxStringLengths += a(i)
        else maxStringLengths += {
          if (a(i) >= a(i - 1))
            a(i) = a(i - 1) - 1
          if (a(i) < 0) 0 else a(i)
        }
      }
      println(maxStringLengths)
    }
  }

}

import scala.util.Sorting
import scala.io.StdIn
object App {
  def main(args: Array[String]) {

    val n = scala.io.StdIn.readInt()
    val A:Array[Long] = StdIn.readLine().split(" ").map(_.toLong)
    Sorting.quickSort(A)

    print(A.reverse.zipWithIndex.foldLeft((0L,0L))({
      case(b,(a,i)) =>
        if(i == 0) {
          (a,a)
        } else {
          val k = math.max(0, math.min(b._2 - 1, a))
          (b._1 + k, k)
        }
    })._1)
  }

}

import scala.util.Sorting
import scala.io.StdIn
object App {
  def main(args: Array[String]) {

    val n = scala.io.StdIn.readInt()
    val A:Array[Long] = StdIn.readLine().split(" ").map(_.toLong)
    Sorting.quickSort(A)

    var acc:Long = 0
    A.reverse.zipWithIndex.foldLeft(0L)({
      case(b,(a,i)) =>
        if(i == 0) {
          acc+=a
          a
        } else {
          acc += math.max(math.min(b - 1, a),0)
          math.max(math.min(b - 1, a),0)
        }
    })

    print(acc)

  }

}

import scala.util.Sorting
import scala.io.StdIn
object App {
  def main(args: Array[String]) {

    val n = scala.io.StdIn.readInt()
    val A:Array[Long] = StdIn.readLine().split(" ").map(_.toLong).sortWith( _ > _)

    print(A.zipWithIndex.foldLeft((0L,0L))({
      case(b,(a,i)) =>
        if(i == 0) {
          (a,a)
        } else {
          val k = math.max(0, math.min(b._2 - 1, a))
          (b._1 + k, k)
        }
    })._1)
  }

}

import scala.util.Sorting
import scala.io.StdIn
object App {
  def main(args: Array[String]) {

    val n = scala.io.StdIn.readInt()
    val A:Array[Long] = StdIn.readLine().split(" ").map(_.toLong).sorted.reverse

    print(A.zipWithIndex.foldLeft((0L,0L))({
      case(b,(a,i)) =>
        if(i == 0) {
          (a,a)
        } else {
          val k = math.max(0, math.min(b._2 - 1, a))
          (b._1 + k, k)
        }
    })._1)
  }

}

/**
  * Created by octavian on 06/02/2016.
  */
object MakeClass {

  val INF = 1000000005

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

    //System.setIn(new FileInputStream("./src/makeClass.in"))
    //System.setOut(new PrintStream(new FileOutputStream("./src/makeClass.out")))

    val N = readInt()
    var vals = readLine().split(" ").map(_.toInt)

    var res = 0
    var last = INF
    for(i <- vals.length - 1 to 0 by -1) {
      val toAdd = Math.min(vals(i), last - 1)
      last = toAdd
      if(toAdd > 0) {
        res += toAdd
      }
    }

    println(res)

  }

}

/**
  * Created by octavian on 06/02/2016.
  */
object MakeClass {

  val INF = 1000000005

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

    //System.setIn(new FileInputStream("./src/makeClass.in"))
    //System.setOut(new PrintStream(new FileOutputStream("./src/makeClass.out")))

    val N = readInt()
    val vals = readLine().split(" ").map(_.toInt).sorted

    var res = 0
    var last = INF
    for(i <- vals.length - 1 to 0 by -1) {
      val toAdd = Math.min(vals(i), last - 1)
      last = toAdd
      if(toAdd > 0) {
        res += toAdd
      }
    }

    println(res)

  }

}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt
  val arr = Array.ofDim[Int](26)
  var used = Set.empty[Int]
  in.next().split(' ').map(_.toInt).zipWithIndex.foreach {
    case (count, index) =>
      var nc = count
      while (nc > 0 && used.contains(nc)) nc -= 1
      if (nc != 0) {
        arr(index) = nc
        used += nc
      }
  }
  println(arr.sum)

}

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

import scala.annotation.implicitNotFound
import scala.collection.mutable
import scala.reflect.ClassTag

/**
  * Created by nimas on 2/4/16.
  */
object MakingAString extends App{

  class Template(val delim: String = " ") {

    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))
    val it = Iterator.iterate(new StringTokenizer(""))(tok => if (tok.hasMoreTokens) tok else new StringTokenizer(in.readLine(), delim))

    def nextTs[T: ParseAble](n: Int)(delim: String = " ")(implicit ev: ClassTag[T]) = (Array fill n) {
      nextT[T](delim)
    }

    def nextT[T: ParseAble](delim: String = " ") = {
      val x = it.find(_.hasMoreTokens)
      implicitly[ParseAble[T]].parse(x get)
    }

    def close(): Unit = {
      in.close()
      out.close()
    }

    @implicitNotFound("No member of type class ParseAble in scope for ${T}")
    trait ParseAble[T] {
      def parse(strTok: StringTokenizer): T
    }

    object ParseAble {

      implicit object ParseAbleInt extends ParseAble[Int] {
        override def parse(strTok: StringTokenizer): Int = strTok nextToken() toInt
      }

      implicit object ParseAbleLong extends ParseAble[Long] {
        override def parse(strTok: StringTokenizer): Long = strTok nextToken() toLong
      }

      implicit object ParseAbleDouble extends ParseAble[Double] {
        override def parse(strTok: StringTokenizer): Double = strTok nextToken() toDouble
      }

      implicit object ParseAbleBigInt extends ParseAble[BigInt] {
        override def parse(strTok: StringTokenizer): BigInt = BigInt(strTok nextToken())
      }

    }

  }

  val io = new Template()

  import io._

  val n = nextT[Int]()
  val a = nextTs[Int](n)() sorted Ordering.Int

  val map = new mutable.HashMap[Int, Boolean]()

  out.println((a.iterator map {
    x => {
      if (map getOrElse(x, true)) {
        map put(x, false)
        x
      } else {
        x - 1 to(1, -1) find {
          !map.contains(_)
        } getOrElse 0
      }
    }
  }).sum)

  close()

}

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

import scala.annotation.implicitNotFound
import scala.collection.mutable
import scala.reflect.ClassTag

/**
  * Created by nimas on 2/4/16.
  */
object MakingAString extends App{

  class Template(val delim: String = " ") {

    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))
    val it = Iterator.iterate(new StringTokenizer(""))(tok => if (tok.hasMoreTokens) tok else new StringTokenizer(in.readLine(), delim))

    def nextTs[T: ParseAble](n: Int)(delim: String = " ")(implicit ev: ClassTag[T]) = (Array fill n) {
      nextT[T](delim)
    }

    def nextT[T: ParseAble](delim: String = " ") = {
      val x = it.find(_.hasMoreTokens)
      implicitly[ParseAble[T]].parse(x get)
    }

    def close(): Unit = {
      in.close()
      out.close()
    }

    @implicitNotFound("No member of type class ParseAble in scope for ${T}")
    trait ParseAble[T] {
      def parse(strTok: StringTokenizer): T
    }

    object ParseAble {

      implicit object ParseAbleInt extends ParseAble[Int] {
        override def parse(strTok: StringTokenizer): Int = strTok nextToken() toInt
      }

      implicit object ParseAbleLong extends ParseAble[Long] {
        override def parse(strTok: StringTokenizer): Long = strTok nextToken() toLong
      }

      implicit object ParseAbleDouble extends ParseAble[Double] {
        override def parse(strTok: StringTokenizer): Double = strTok nextToken() toDouble
      }

      implicit object ParseAbleBigInt extends ParseAble[BigInt] {
        override def parse(strTok: StringTokenizer): BigInt = BigInt(strTok nextToken())
      }

    }

  }

  val io = new Template()

  import io._

  val n = nextT[Int]()
  val a = nextTs[Int](n)() sorted Ordering.Int

  val map = new mutable.HashMap[Int, Boolean]()

  out.println((a.iterator map {
    x => {
      if (map getOrElse(x, true)) {
        map put(x, false)
        x
      } else {
        val find = x - 1 to(1, -1) find {
          !map.contains(_)
        } getOrElse 0
        if (find != 0) map put(find, false)
        find
      }
    }
  }).sum)

  close()

}

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

object _624B extends CodeForcesApp {
  override type Result = Int

  override def solve(scanner: Scanner) = {
    import scanner._
    val n = nextInt()
    val seen = mutable.Set.empty[Int]
    @tailrec def add(i: Int): Unit = if (seen(i)) add(i-1) else if (i > 0) seen += i
    repeat(n)(add(nextInt()))
    seen.sum
  }

  def repeat(n: Int)(f: => Unit): Unit = (1 to n).foreach(_ => 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)
  val mod: Int = 1000000007
  type Result
  def solve(scanner: Scanner): Result
  def format(result: Result): String
  def apply(scanner: Scanner): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer

import scala.io.Codec

/**
 * Scala implementation of a faster java.util.Scanner
 * See: http://codeforces.com/blog/entry/21125
 * All next methods throw NoSuchElementException when !hasNext
 */
class Scanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))
  def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))
  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)
  def this(str: String) = this(new StringReader(str))

  val lines = Iterator.continually(reader.readLine()).takeWhile(_ != null)

  private[this] val tokenizers = lines.map(new StringTokenizer(_)).filter(_.hasMoreTokens)
  private[this] var current: Option[StringTokenizer] = None

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

  /**
   * Unlike Java's scanner which returns till end of current line, this actually returns the next line
   * @see line() if you want the Java behaviour
   */
  def nextLine(): String = {
    current = None   // reset
    lines.next()
  }
  def lineNumber: Int = reader.getLineNumber
  def line(): String = tokenizer().get.nextToken("\n\r")
  def nextString(): String = next()
  def nextChar(): Char = next().ensuring(_.length == 1).head
  def nextBoolean(): Boolean = next().toBoolean
  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)
  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)
  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)
  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)
  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)
  def nextFloat(): Float = next().toFloat
  def nextDouble(): Double = next().toDouble
  def nextBigDecimal(): BigDecimal = BigDecimal(next())
  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty
  override def close() = reader.close()
}

/**
  * Created by Andrew Tsibin https://github.com/Evilnef.
  */
object Problemset624 {
  def main(args: Array[String]): Unit = {
    val problem = new ProblemB
    problem.solve()
  }

  private abstract class Problem {
    def solve()
  }

  private class ProblemA extends Problem {
    override def solve(): Unit = {
      val Array(d, l, v1, v2) = scala.io.StdIn.readLine().split(" ").map(_.toDouble)
      val result = (l - d) / (v1 + v2)
      println(result)
    }
  }

  private class ProblemB extends Problem {
    override def solve(): Unit = {
      var maxStringLengths = 0
      val n = scala.io.StdIn.readInt()
      val a = scala.io.StdIn.readLine().split(" ").map(_.toInt).sortWith(_ > _)
      for (i <- a.indices) {
        if (i == 0) maxStringLengths += a(i)
        else maxStringLengths += {
          if (a(i) >= a(i - 1))
            a(i) = a(i - 1) - 1
          if (a(i) < 0) 0 else a(i)
        }
      }
      println(maxStringLengths)
    }
  }

}

import scala.util.Sorting
import scala.io.StdIn
object App {
  def main(args: Array[String]) {

    val n = scala.io.StdIn.readInt()
    val A:Array[Int] = StdIn.readLine().split(" ").map(_.toInt)
    Sorting.quickSort(A)

    var acc = 0
    A.reverse.zipWithIndex.foldLeft(0)({
      case(b,(a,i)) =>
        if(i == 0) {
          acc+=a
          a
        } else {
          acc += math.max(math.min(b - 1, a),0)
          math.max(math.min(b - 1, a),0)
        }
    })

    print(acc)

  }

}


Unary is a minimalistic Brainfuck dialect in which programs are written using only one token. Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm. First, replace each command with a corresponding binary code, using the following conversion table:   ">"  →  1000,  "<"  →  1001,  "+"  →  1010,  "-"  →  1011,  "."  →  1100,  ","  →  1101,  "["  →  1110,  "]"  →  1111. Next, concatenate the resulting binary codes into one binary number in the same order as in the program. Finally, write this number using unary numeral system — this is the Unary program equivalent to the original Brainfuck one.You are given a Brainfuck program. Your task is to calculate the size of the equivalent Unary program, and print it modulo 1000003 (106 + 3).

The input will consist of a single line p which gives a Brainfuck program. String p will contain between 1 and 100 characters, inclusive. Each character of p will be "+", "-", "[", "]", "<", ">", "." or ",".

Output the size of the equivalent Unary program modulo 1000003 (106 + 3).

NoteTo write a number n in unary numeral system, one simply has to write 1 n times. For example, 5 written in unary system will be 11111.In the first example replacing Brainfuck commands with binary code will give us 1101 1100. After we concatenate the codes, we'll get 11011100 in binary system, or 220 in decimal. That's exactly the number of tokens in the equivalent Unary program.

object Main {
    def main(args : Array[String]) =
        println (readLine.foldLeft (0) (
            (ans, x) => ((ans << 4) | (("><+-.,[]" indexOf x) + 8)) % 1000003
        ))
}

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

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

    // ">"  →  1000,
    // "<"  →  1001,
    // "+"  →  1010,
    // "-"  →  1011,
    // "."  →  1100,
    // ","  →  1101,
    // "["  →  1110,
    // "]"  →  1111.

  val M = Map('>' -> 8,
              '<' -> 9,
              '+' -> 10,
              '-' -> 11,
              '.' -> 12,
              ',' -> 13,
              '[' -> 14,
              ']' -> 15)

  val P = 1000003

  def solve(): Int = {
    val BF = sc.nextLine

    BF.foldLeft(0) { (b, a) =>
      ((b << 4) | M(a)) % P
    }
  }

  out.println(solve)
  out.close
}

object Main {
  def main(args: Array[String]) {
    val s = readLine()
    val tr = s.map{
      case '>' => 8
      case '<' => 9
      case '+' => 10
      case '-' => 11
      case '.' => 12
      case ',' => 13
      case '[' => 14
      case ']' => 15
    }
    println(tr.foldLeft(0){ (acc, i) => (acc * 16 + i) % 1000003} )
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val str = in.next()

  val map = Map(
    '>' -> 8,
    '<' -> 9,
    '+' -> 10,
    '-' -> 11,
    '.' -> 12,
    ',' -> 13,
    '[' -> 14,
    ']' -> 15)

  println(str.foldLeft(0l) {
    case (acc, ch) => Math.abs(acc << 4) + map(ch)
  } % 1000003)

}


Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is T seconds. Lesha downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For q seconds of real time the Internet allows you to download q - 1 seconds of the track.Tell Lesha, for how many times he will start the song, including the very first start.

The single line contains three integers T, S, q (2 ≤ q ≤ 104, 1 ≤ S < T ≤ 105).

Print a single integer — the number of times the song will be restarted.

NoteIn the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.In the second test, the song is almost downloaded, and Lesha will start it only once.In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.

object A569 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    var Array(t, s, q) = readInts(3)
    var res = 0
    while(s < t) {
      s *= q
      res += 1
    }
    out.println(res)
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

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

    def readInt: Int = tokenizeLine.nextToken.toInt

    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 java.io._
import java.util._

import scala.collection.mutable

object A {

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

  /**
   * Segment tree for any commutative function
   * @param values Array of Int
   * @param commutative function like min, max, sum
   * @param zero zero value - e.g. 0 for sum, Inf for min, max
   */
  class SegmentTree(values: Array[Int])(commutative: (Int, Int) => Int)(zero: Int) {
    private val SIZE = 1e5.toInt
    private val n = values.length
    val t = new Array[Int](2 * n)
    Array.copy(values, 0, t, n, n)

    // build segment tree
    def build = {
      for (i <- n - 1 until 0 by -1) {
        t(i) = commutative(t(2 * i), t(2 * i + 1))
      }
    }

    // change value at position p to x
    // TODO beatify
    def modify(p: Int, x: Int) = {
      var pos = p + n
      t(pos) = x
      while (pos > 1) {
        t(pos / 2) = commutative(t(pos), t(pos ^ 1))
        pos /= 2
      }
    }

    // TODO implement me!
    def modify(p: Int, left: Int, right: Int) = ???

    def query(p: Int) = ???

    // sum [l, r)
    // min l = 0
    // max r = n
    // TODO beatify
    def query(left: Int, right: Int): Int = {
      var res = zero
      var r = right + n
      var l = left + n
      while (l < r) {
        if (l % 2 == 1) {
          res = commutative(res, t(l))
          l += 1
        }
        if (r % 2 == 1) {
          r -= 1
          res = commutative(res, t(r))
        }
        l /= 2
        r /= 2
      }
      res
    }
  }

  def solve: Int = {
    val t = nextInt
    var s = nextInt
    val q = nextInt
    var count = 0
    while (s < t) {
      s *= q
      count += 1
    }
    out.println(count)
    return 0
  }
}

import scala.io.StdIn._

object A extends App {
  val Array(t, s, q) = readLine().split(" ").map(_.toInt)

  var played = 0
  var started = 1
  var current = 0

  while (s + (current * ((q - 1.0) / q)) < t) {
    if (played + 1 <= s + ((current + 1) * ((q - 1.0) / q))) {
      played += 1
    } else {
      played = 1
      started += 1
    }

    current += 1
  }

  println(started)
}

import java.util.Scanner

object PA extends App {
    var in = new Scanner(System.in)
    val Vector(t, s, q) = (1 to 3).map(_ => in.nextInt())
    def sol(ns:Int):Int = if(ns >= t) 0 else sol(ns*q) + 1
    println(sol(s).toString)
}

object Solution extends App{
  val in = scala.io.Source.stdin.getLines()
  var Array(t, s, q) = in.next().split(" ").map(_.toInt)
  var count = 0
  while (s < t) {
    s *= q
    count += 1
  }
  println(count)

}

import scala.io.StdIn._

object A extends App {
  val Array(t, s, q) = readLine().split(" ").map(_.toInt)

  var downloaded = s.toDouble
  var played = 0
  var started = 1

  var speed = (q - 1.0) / q

  while (downloaded < t) {
    downloaded += speed

    if (played + 1 <= downloaded) {
      played += 1
    } else {
      played = 0
      started += 1
    }
  }

  println(started)
}

import scala.io.StdIn._

object A extends App {
  val Array(t, s, q) = readLine().split(" ").map(_.toInt)

  var downloaded = s.toDouble
  var played = 0
  var started = 1

  var speed = (q - 1.0) / q

  while (downloaded < t) {
    downloaded += speed

    if (played + 1 <= downloaded) {
      played += 1
    } else {
      played = 1
      started += 1
    }
  }

  println(started)
}

import scala.io.StdIn._

object A extends App {
  val Array(t, s, q) = readLine().split(" ").map(_.toInt)

  var downloaded = s.toDouble
  var played = 0
  var started = 1

  var speed = (q - 1.0) / q

  downloaded += speed

  while (downloaded < t) {

    if (played + 1 <= downloaded) {
      played += 1
    } else {
      played = 1
      started += 1
    }

    downloaded += speed
  }

  println(started)
}

import scala.io.StdIn._

object A extends App {
  val Array(t, s, q) = readLine().split(" ").map(_.toInt)

  var downloaded = s.toDouble
  var played = 0
  var started = 1

  var speed = (q - 1.0) / q

  downloaded += speed

  while (downloaded < t) {

    if (played + 1 <= downloaded) {
      played += 1
    } else {
      played = 0
      started += 1
    }

    downloaded += speed
  }

  println(started)
}

import scala.io.StdIn._

object A extends App {
  val Array(t, s, q) = readLine().split(" ").map(_.toInt)

  var downloaded = s.toDouble
  var played = 0
  var started = 1

  var speed = (q - 1.0) / q

  while (downloaded < t) {
    downloaded += speed

    if (downloaded < t && played + 1 <= downloaded) {
      played += 1
    } else if (downloaded < t) {
      played = 0
      started += 1
    }
  }

  println(started)
}

object Solution extends App{
  val in = scala.io.Source.stdin.getLines()
  val Array(t, s, q) = in.next().split(" ").map(_.toInt)
  var downloaded = 2 * s * (q - 1)
  var count = 1
  while (downloaded < t) {
    downloaded += downloaded * (q - 1)
    count += 1
  }
  println(count)

}


Gerald is setting the New Year table. The table has the form of a circle; its radius equals R. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider all plates to be round and have the same radii that equal r. Each plate must be completely inside the table and must touch the edge of the table. Of course, the plates must not intersect, but they can touch each other. Help Gerald determine whether the table is large enough for n plates.

The first line contains three integers n, R and r (1 ≤ n ≤ 100, 1 ≤ r, R ≤ 1000) — the number of plates, the radius of the table and the plates' radius.

Print "YES" (without the quotes) if it is possible to place n plates on the table by the rules given above. If it is impossible, print "NO". Remember, that each plate must touch the edge of the table.

NoteThe possible arrangement of the plates for the first sample is:

object main {

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

        val tokens = (readLine()) split " " map Integer.parseInt
        val n = tokens apply 0
        val R = tokens apply 1
        val r = tokens apply 2
        if (n == 1) {if (R >= r) println ("YES") else println("NO")}
        else if ((R-r)*math.sin(math.Pi/n)>=r-0.00000001) println ("YES") else println("NO")
    }
}

object P140A extends App {

  val Array(n, bigR, r) = readLine.split(" ").map(_.toInt)

  def findSide(angle: Double, a: Double) = a / math.sin(math.toRadians(angle))

  val condition = if (n < 3) bigR >= n * r else math.abs(findSide(180.0 / n, r)) + r <= bigR

  print(if (condition) "YES" else "NO")

}

import scala.io.Source
object A {

  def main(arg: Array[String]) = {
    val in = Source.stdin.getLine(0).split(" ").map(_.toInt)
    val n = in(0)
    val R = in(1).toDouble
    val r = in(2).toDouble

    if (n == 1) {
      if (r <= R)
        println("YES")
      else
        println("NO")
    } else if (r*2.0 > R)
      println("NO")
    else {
      val a = Math.asin(r / (R - r))
      val fit = Math.floor(2 * Math.Pi / a + 1E-7).toInt / 2

      if (n <= fit)
        println("YES")
      else
        println("NO")
    }
  }
}

object Main {
  def main(args: Array[String]) {
    val Array(n, r1, r0) = readLine().split(" ").map(_.toInt)
    if (n == 1 && r1 >= r0) println("YES")
    else if (r1 > r0) {
      val angle = math.Pi / n
      if (r0.toDouble / (r1 - r0).toDouble - math.sin(angle) <= 0.000000001) println("YES")
      else (println("NO"))
    } else println("NO")
  }
}

import scala.io.Source
object A {

  def main(arg: Array[String]) = {
    val in = Source.stdin.getLine(0).split(" ").map(_.toInt)
    val n = in(0)
    val R = in(1).toDouble
    val r = in(2).toDouble

    if (n == 1) {
      if (r <= R)
        println("YES")
      else
        println("NO")
    } else if (r*2.0 > R)
      println("NO")
    else {
      val a = Math.asin(r / (R - r))
      val fit = Math.floor(2 * Math.Pi / (a-(1E-7))).toInt / 2

      if (n <= fit)
        println("YES")
      else
        println("NO")
    }
  }
}

import scala.io.Source
object A {

  def main(arg: Array[String]) = {
    val in = Source.stdin.getLine(0).split(" ").map(_.toInt)
    val n = in(0)
    val R = in(1).toDouble
    val r = in(2).toDouble

    if (n == 1) {
      if (r <= R)
        println("YES")
      else
        println("NO")
    } else if (r*2.0 > R)
      println("NO")
    else {
      val a = Math.asin(r / (R - r))
      val fit = Math.floor(2 * Math.Pi / (a-0.001)).toInt / 2

      if (n <= fit)
        println("YES")
      else
        println("NO")
    }
  }
}

import scala.io.Source
object A {

  def main(arg: Array[String]) = {
    val in = Source.stdin.getLine(0).split(" ").map(_.toInt)
    val n = in(0)
    val R = in(1).toDouble
    val r = in(2).toDouble

    if (n == 1) {
      if (r <= R)
        println("YES")
      else
        println("NO")
    } else if (r*2.0 > R)
      println("NO")
    else {
      val a = Math.asin(r / (R - r))
      val fit = Math.floor(2 * Math.Pi / a).toInt / 2

      if (n <= fit)
        println("YES")
      else
        println("NO")
    }
  }
}

import scala.io.Source
object A {

  def main(arg: Array[String]) = {
    val in = Source.stdin.getLine(0).split(" ").map(_.toInt)
    val n = in(0)
    val R = in(1).toDouble
    val r = in(2).toDouble

    if (n == 1) {
      if (r <= R)
        println("YES")
      else
        println("NO")
    } else if (r*2.0 > R)
      println("NO")
    else {
      val a = Math.asin(r / (R - r))
      val fit = Math.floor(2 * Math.Pi / a + Math.EPS_DOUBLE).toInt / 2

      if (n <= fit)
        println("YES")
      else
        println("NO")
    }
  }
}

import scala.io.Source
object A {

  def main(arg: Array[String]) = {
    val in = Source.stdin.getLine(0).split(" ").map(_.toInt)
    val n = in(0)
    val R = in(1).toDouble
    val r = in(2).toDouble

    if (n == 1) {
      if (r <= R)
        println("YES")
      else
        println("NO")
    } else if (r*2.0 > R)
      println("NO")
    else {
      val a = Math.asin(r / (R - r))
      val fit = Math.floor(2 * Math.Pi / (a-(Math.EPS_DOUBLE))).toInt / 2

      if (n <= fit)
        println("YES")
      else
        println("NO")
    }
  }
}

import scala.io.Source
object A {

  def main(arg: Array[String]) = {
    val in = Source.stdin.getLine(0).split(" ").map(_.toInt)
    val n = in(0)
    val R = in(1).toDouble
    val r = in(2).toDouble

    if (n == 1) {
      if (r <= R)
        println("YES")
      else
        println("NO")
    } else if (r*2.0 > R)
      println("NO")
    else {
      val a = Math.asin(r / (R - r))
      val fit = Math.floor(2 * Math.Pi / (a+(Math.EPS_DOUBLE))).toInt / 2

      if (n <= fit)
        println("YES")
      else
        println("NO")
    }
  }
}

import scala.io.Source
object A {

  def main(arg: Array[String]) = {
    val in = Source.stdin.getLine(0).split(" ").map(_.toInt)
    val n = in(0)
    val R = in(1).toDouble
    val r = in(2).toDouble

    if (n == 1) {
      if (r <= R)
        println("YES")
      else
        println("NO")
    } else if (r*2.0 > R)
      println("NO")
    else {
      val a = Math.asin(r / (R - r))

      println (a)
      val fit = Math.floor(2 * Math.Pi / a + Math.EPS_DOUBLE).toInt / 2

      println (fit)
      if (n <= fit)
        println("YES")
      else
        println("NO")
    }
  }
}

object Main {
  def main(args: Array[String]) {
    val Array(n, r1, r0) = readLine().split(" ").map(_.toInt)
    if (n == 1 && r1 >= r0) println("YES")
    else if (r1 > r0) {
      val angle = math.Pi / n
      if (r0.toDouble / (r1 - r0).toDouble <= math.sin(angle)) println("YES")
      else (println("NO"))
    } else println("NO")
  }
}

object Main {
  def main(args: Array[String]) {
    val Array(n, r1, r0) = readLine().split(" ").map(_.toInt)
    if (n == 1 && r1 >= r0) println("YES")
    else if (r1 > r0) {
      val angle = math.Pi / n
      if (r0.toDouble / (r1 - r0).toDouble - math.sin(angle) <= 0.0000001) println("YES")
      else (println("NO"))
    } else println("NO")
  }
}

object Main {
  def main(args: Array[String]) {
    val Array(n, r1, r0) = readLine().split(" ").map(_.toInt)
    if (n == 1 && r1 >= r0) println("YES")
    else if (r1 > r0) {
      val angle = math.Pi / n
      if (r0.toDouble / (r1 - r0).toDouble - math.sin(angle) <= 0.001) println("YES")
      else (println("NO"))
    } else println("NO")
  }
}


Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).  Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.

The first line contains a single integer n (1 ≤ n ≤ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 ≤ xi ≤ 106) — the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.

In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).

NoteThe first test from the statement is on the picture to the left, the second test is on the picture to the right.

object Main {
  def main(args: Array[String]) {
    val n=readLine().toInt
    val a=readLine().split(" ").map(_ toInt)
    val b=(0 until n-1).map(i=>(math.min(a(i),a(i+1)),math.max(a(i),a(i+1))))
    println(  if (b.exists(e1=>b.exists(e2=>(e1._1<e2._1 && e2._1<e1._2 && e1._2<e2._2)
     || (e2._1<e1._1 && e1._1<e2._2 && e2._2<e1._2))))
        "yes"
    else "no")
  }
}

object Solution358A extends App {

  def solution() {
    val n = _int
    val coords = 1.to(n).map(_ => _int)
    val intervals = coords.zip(coords.tail)

    def norm(a: (Int, Int)): (Int, Int) = (scala.math.min(a._1, a._2), scala.math.max(a._1, a._2))

    def inside(a: (Int, Int), x: Int): Boolean = a._1 < x && x < a._2
    def oneInside(a: (Int, Int), b: (Int, Int)): Boolean = inside(a, b._1) ^ inside(a, b._2)

    def intersects(a: (Int,Int), b: (Int, Int)): Boolean = {
      val x = norm(a)
      val y = norm(b)
      val res = oneInside(x, y) && oneInside(y, x)
      if (res) {
        //println(a)
        //println(b)
      }
      res
    }

    val hasInt = intervals.find(a => {
      intervals.find(b => intersects(a, b)).isDefined
    }).isDefined

    if (hasInt) {
      println("yes")
    } else {
      println("no")
    }
  }

  //////////////////////////////////////////////////
  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()
}

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).sliding(2).toList
  val r = data.forall{i => data.forall { j =>
    val minFirst = Math.min(i.head, i.last)
    val maxFirst = Math.max(i.head, i.last)
    val minSecond = Math.min(j.head, j.last)
    val maxSecond = Math.max(j.head, j.last)
    if (i == j)
      true
    else {
      val r = maxFirst <= minSecond || minFirst >= maxSecond || (maxFirst <= maxSecond && minFirst >= minSecond) ||
        (maxSecond <= maxFirst && minSecond >= minFirst)
      r
    }}}
  if (!r)
    println("yes")
  else
    println("no")
}

object A358 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = readInts(n)
    val x = cu.ArrayBuffer.empty[(Int, Int)]
    for(i <- 1 until n)
      x.append((math.min(in(i-1), in(i)), math.max(in(i-1), in(i))))
    val res = x.sorted
    var break = false
    for(i <- res.indices; j <- res.indices if i!=j && !break) {
      if(res(i)._1 < res(j)._1 && res(i)._2 > res(j)._1 && res(j)._2 > res(i)._2) {
        println("yes")
        break = true
      }
    }
    if(!break){
      println("no")
    }
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))

    @inline def read: String = input.readLine()

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

object A extends App {

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

  val n = readInt
  val xs = readInts(n)

  for (i <- 1 until n) {
    val l1 = math.min(xs(i - 1), xs(i))
    val r1 = math.max(xs(i - 1), xs(i))
    for (j <- 1 until n) {
      val l2 = math.min(xs(j - 1), xs(j))
      val r2 = math.max(xs(j - 1), xs(j))
      if ((l1 < l2 && r1 > l2 && r1 < r2) || (r1 > r2 && l1 > l2 && l1 < r2) ||
          (l2 < l1 && r2 > l1 && r2 < r1) || (r2 > r1 && l2 > l1 && l2 < r1)) {
        println("yes")
        //println(i, j)
        exit
      }
    }
  }

  println("no")
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.util.Random
import scala.util.control.Breaks._

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

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

  var flag = false
  breakable {
    for (i <- 0 until N - 2; j <- (i + 2) until N - 1) {
      val a = P(i)
      val b = P(i + 1)
      val c = P(j)
      val d = P(j + 1)
      if ((c - a).signum * (c - b).signum * (d - a).signum * (d - b).signum < 0) {
        flag = true
        break
      }
    }
  }

  val res = if (flag) "yes" else "no"

  out.println(res)
  out.close
}

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

object Solver extends App {
  val cin = new Scanner(System.in)

  val n = cin.nextInt
  cin.nextLine
  val points = cin.nextLine.split(" ").map(_.toInt).toSeq

  val connections = for (i <- 0 until n - 1) yield (points(i), points(i + 1))

  var intersection = "no"
  connections.foreach { case (a, d) =>
    val p1 = Seq(a, d)
    val A = p1.min
    val D = p1.max

    connections.foreach { case (b, c) =>
      val p2 = Seq(b, c)
      val B = p2.min
      val C = p2.max

      if (B < D && D < C && A < B)
        intersection = "yes"
    }
  }

  println(intersection)
}

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).sliding(2)
  val r = data.forall{i => data.forall { j =>
    val minFirst = Math.min(i.head, i.last)
    val maxFirst = Math.max(i.head, i.last)
    val minSecond = Math.min(j.head, j.last)
    val maxSecond = Math.max(j.head, j.last)
    if (i == j)
      true
    else {
      maxFirst <= minSecond || minFirst >= maxSecond || (maxFirst <= maxSecond && minFirst >= minSecond) ||
        (maxSecond <= maxFirst && minSecond >= minFirst)
    }}}
  if (!r)
    println("yes")
  else
    println("no")
}

import scala.collection._

object A extends App {

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

  val n = readInt
  val xs = readInts(n)

  for (i <- 1 until n) {
    val l1 = xs(i - 1)
    val r1 = xs(i)
    for (j <- 1 until n) {
      val l2 = xs(j - 1)
      val r2 = xs(j)
      if ((l1 < l2 && r1 > l2 && r1 < r2) || (r1 > r2 && l1 > l2 && l1 < r2) ||
          (l2 < l1 && r2 > l1 && r2 < r1) || (r2 > r1 && l2 > l1 && l2 < r1)) {
        println("yes")
        //println(i, j)
        exit
      }
    }
  }

  println("no")
}

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

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

  val N = sc.nextInt
  val ps = List.fill(N / 2, 2)(sc.nextInt)
  val res = if (ps(0) == ps(0).sorted && ps(1) == ps(1).sorted.reverse) "no"
            else "yes"

  out.println(res)
  out.close
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.util.Random
import scala.util.control.Breaks._

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

  val N = sc.nextInt
  val P = Array.fill(N)(sc.nextLong)

  var flag = false
  breakable {
    for (i <- 0 until N - 2; j <- (i + 1) until N - 1) {
      val a = P(i)
      val b = P(i + 1)
      val c = P(j)
      val d = P(j + 1)
      if ((c - a) * (c - b) * (d - a) * (d - b) < 0) {
        flag = true
        break
      }
    }
  }

  val res = if (flag) "YES" else "NO"

  out.println(res)
  out.close
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.util.Random
import scala.util.control.Breaks._

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

  val N = sc.nextInt
  val P = Array.fill(N)(sc.nextLong)

  var flag = false
  breakable {
    for (i <- 0 until N - 2; j <- (i + 1) until N - 1) {
      val a = P(i)
      val b = P(i + 1)
      val c = P(j)
      val d = P(j + 1)
      if ((c - a) * (c - b) * (d - a) * (d - b) < 0) {
        flag = true
        break
      }
    }
  }

  val res = if (flag) "yes" else "no"

  out.println(res)
  out.close
}

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

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

  val N = sc.nextInt
  val ps = List.fill(N / 2, 2)(sc.nextInt).transpose
  val res = if (ps(0) == ps(0).sorted && ps(1) == ps(1).sorted.reverse) "no"
            else "yes"

  out.println(res)
  out.close
}