You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.

The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.

Print a single number — the sum of all edges of the parallelepiped.

NoteIn the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3.

import collection.mutable.ArrayBuffer
import java.io.InputStreamReader
import java.io.BufferedReader
import scala.collection.JavaConversions._

object CodeForces138_1 {

  val in = System.in
  val out = System.out

  def grabData {
    val reader = new BufferedReader(new InputStreamReader(in))
    //val array = new ArrayBuffer[]()
    var line = reader.readLine()
    while(line != null) {

      line = reader.readLine()
    }
    //array
  }

  def grabData2 = {
    val reader = new BufferedReader(new InputStreamReader(in))
    val line = reader.readLine()
    line.split(' ').toSeq.map(_.toInt)
  }

  def main(args: Array[String]) {
    val sses = grabData2
    val s1:Double = sses(0)
    val s2:Double = sses(1)
    val s3:Double = sses(2)
    val c = Math.sqrt(s2*s3/s1)
    val a = s3/c
    val b = s2/c
    out.print(((c+a+b)*4).toInt)
  }

}

object A {
    def main(args : Array[String]) : Unit = {
        val Array(x, y, z) = readLine.split(" ").map(s => s toInt);

        def side(x : Int, y : Int, z : Int) : Double = {
            scala.math.sqrt(x * y / z)
        }

        val sm = side(x, y, z) + side(y, z, x) + side(z, x, y)

        println((4 * sm) toInt)
    }
}

import java.util.StringTokenizer

object _224A extends App {
  var token = new StringTokenizer("")

  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }

  val a = next.toInt
  val b = next.toInt
  val c = next.toInt
  val cb = a.toLong * b * c
  val wb = Math.sqrt(cb).round
  val zb = (for {
    i <- (wb - 10) to (wb + 10)
    if (i > 0)
    if (i * i == cb)
  } yield i).head

  val t = zb / a
  val tt = zb / b
  val ttt = zb / c
  println(4 * (t + tt + ttt))
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(x1, x2, x3) = in.next().split(' ').map(_.toInt)

  def findSolution(x1: Int, x2: Int, x3: Int) = {
    (1 to x1).collectFirst {
      case a if x3 == x2 / a * x1 / a =>
        (a, x2 / a, x1 / a)
      case a if x2 == x3 / a * x1 / a =>
        (a, x3 / a, x1 / a)
    }
  }

  println(findSolution(x1, x2, x3).map(i => 4 * (i._1 + i._2 + i._3)).get)

}

object A224 {

  import IO._
  import collection.{mutable => cu}
  def gcd(a: Long, b: Long): Long = {
    if(b == 0) a else gcd(b, a%b)
  }
  def main(args: Array[String]): Unit = {
    val in = readLongs(3).sorted
    var break = false
    for(i <- 1 to in.min.toInt if !break) {
      val a = i
      val b = in(0)/a
      val c = in(2)/a
      if(b*c == in(1)) {
        println(4 * (a + b + c))
        break = true
      }
    }
  }

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

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

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

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

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

}

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

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

  val X, Y, Z = sc.nextLong

  val xyz = math.sqrt(X * Y * Z).round

  val a = xyz / X
  val b = xyz / Y
  val c = xyz / Z

  val answer = 4 * (a + b + c)

  out.println(answer)
  out.close
}

// codeforces 224A
object Parallelipiped extends App {
  val ss = (Console.readLine.split(" ")) map (_.toInt)
  val sxy = ss(0)
  val syz = ss(1)
  val sxz = ss(2)

  def lxyz():Int = {
    val vars = for {
      x <- 1 to 10000
      if sxy % x == 0
      val y = sxy / x
      if syz % y == 0
      val z = syz / y
      if x*z == sxz
    } yield (x + y + z)
    vars(0) * 4
  }

  println(lxyz())
}

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

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

  val Array(ab, bc, ac) = readInts
  def intStream(i: Int): Stream[Int] = i #:: intStream(i + 1)
  def a = intStream(1).filter(ab % _ == 0).filter(ac % _ == 0)
  def ans = a.filter(a => ab / a  * ac / a == bc).head

  def main(a: Array[String]) {
    println(4 * (ans + ab / ans + ac / ans))
  }
}

object test5 extends App {
    val Array(x,y,z)=readLine.split(" ").map(_.toInt)
    for(a<-1 to x if x%a==0)
    {
		val b=x/a
		if(y%a==0)
		{
			val c=y/a
			if(b*c==z)
			{
				println((a+b+c)*4)
				exit
			}
		}
    }
}

/*
a*b=x

a*c=y && b*c=z ||
b*c=y && a*c=z
*/

object Main {
  def main(args: Array[String]) {
    val ss = readLine().split(" ").map(_.toInt).sorted
    val s1 = ss(0)
    val s2 = ss(1)
    val s3 = ss(2)

    val ls0 = for {
      i <- 1 to s1
      j = (s1 / i).toInt
      if i * j == s1
    } yield(i, j)
    val ls = for {
      (i, j) <- ls0
      k = (ss(1) / i).toInt
      if i * k == s2
      if j * k == s3
    } yield(i, j, k)
    println((ls(0)._1 + ls(0)._2 + ls(0)._3) * 4)
  }
}

object A224 {

  import IO._
  import collection.{mutable => cu}
  def gcd(a: Long, b: Long): Long = {
    if(b == 0) a else gcd(b, a%b)
  }
  def main(args: Array[String]): Unit = {
    val in = readLongs(3)
    var break = false
    for(i <- 1 to in.min.toInt if !break) {
      val a = i
      val b = in(0)/a
      val c = in(2)/a
      if(b*c == in(1)) {
        println(4 * (a + b + c))
        break = true
      }
    }
  }

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

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

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

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

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

}


Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given a, b and n who wins the game.

The only string contains space-separated integers a, b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.

If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).

NoteThe greatest common divisor of two non-negative integers a and b is such maximum positive integer k, that a is divisible by k without remainder and similarly, b is divisible by k without remainder. Let gcd(a, b) represent the operation of calculating the greatest common divisor of numbers a and b. Specifically, gcd(x, 0) = gcd(0, x) = x.In the first sample the game will go like that: Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left. Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left. Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left. Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left. Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left. Antisimon should take gcd(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.In the second sample each player during each move takes one stone from the heap. As n is even, Antisimon takes the last stone and Simon can't make a move after that.

import scala.io.StdIn.readLine

/**
 * @author slie742
 */
object EpicGame {

  def gcd(a: Int,b:Int) : Int = {
    b match {
      case 0 => a
      case _ => gcd(b,a%b)
    }
  }

  def solve(a: Int, b: Int, n:Int) : Int = {
    def go(rem: Int, turn: Int) : Int = turn match {
        case 0 => if (rem < gcd(a,rem)) 1
                  else go(rem - gcd(a,rem),1)
        case _ => if (rem < gcd(b,rem)) 0
                  else go(rem - gcd(b,rem),0)
      }
    go(n,0)
  }

  def main(args: Array[String]) {
    val line = readLine.split(' ').map(_.toInt)
    println(solve(line(0),line(1),line(2)))
  }

}

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

object App {

  def main(args: Array[String]) {

    val Array(a, b, n) = StdIn.readLine().split(" ").map(_.toInt)

    val A:Array[Int] = Array(a,b)
    var cur = 0
    var curn = n
    while(gcd(curn,A(cur)) <= curn) {
      curn-=gcd(curn,A(cur));
      if(cur == 0) {
        cur = 1
      } else {
        cur = 0
      }
    }
    if(cur == 0) {
      cur = 1
    } else {
      cur = 0
    }
    print(cur)

    def gcd(x:Int, y:Int):Int = {
      if(x % y == 0)
        y
      else
        gcd( y % x, x)
    }

  }

}

import java.util.Scanner

object TEST extends App {
  val a : Array[Int] = readLine.split(" ").map(_.toInt)

  def gcd(x: Int, y: Int): Int = if(y==0) x else gcd(y,x%y)

  def play(state :Int,n: Int):Int =if(n==0)  state^1 else  play(state^1,n-gcd(n,a(state)))

  print(play(0,a(2)))
}

import scala.annotation.tailrec
object Main {

  def main(args: Array[String]): Unit = {
    @tailrec
    def gcd(x:Int,y:Int):Int= y match{
      case 0 => return x;
      case _ => return gcd(y,x%y);
    }
    var fix = readLine().split(" ").map(_.toInt)
    @tailrec
    def rec(t:Int,n:Int):Int= n match{
      case _ if gcd(fix(t),n)>n => return 1-t;
      case _ => return rec(1-t,n-gcd(fix(t),n))
    }
    println(rec(0,fix(2)))
  }

}

import scala.annotation.tailrec
object Main {

  def main(args: Array[String]): Unit = {
    @tailrec
    def gcd(x:Int,y:Int):Int={
      if(y==0)return x;
      return gcd(y,x%y);
    }
    var fix = readLine().split(" ").map(_.toInt)
    @tailrec
    def rec(t:Int,n:Int):Int={
      val req = gcd(fix(t),n)
      if(req>n)return 1-t;
      return rec(1-t,n-req)
    }
    println(rec(0,fix(2)))
  }

}

import scala.collection.immutable.Nil

object A00119 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 gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)

  def nextVals(x: (Int, Int, Int)): (Int, Int, Int) =
    if (x._3 == 0) null
    else (x._2, x._1, x._3 - gcd(x._1, x._3))

  def valStream(x: (Int, Int, Int)): Stream[(Int, Int, Int)] = {
    val n = nextVals(x)
    if (n == null) Stream.Empty
    else x #:: valStream(n)
  }

  val Seq(a, b, n) = readMatrix(1, 3).head

  println((valStream((a, b, n)).length - 1) % 2)

}

object Main {

    def gcd(x: Int, y: Int): Int = {
        var a = x; var b = y
        while (b > 0) {
            a %= b
            val k = a
            a = b
            b = k
        }
        return a
    }

    def main(args: Array[String]): Unit = {
        var Array(a, b, n) = readLine split " " map(_.toInt)
        var cur = 1
        while (n > 0) {
            val k = if (cur == 1) a else b
            n -= gcd(k, n)
            cur += 1;
            cur %= 2
        }

        println (cur)
    }
}

object One19A extends App {

	val Array(a, b, n) = readLine.split(' ').map(_.toInt)

	def recursive(tog: Boolean, left: Int): Boolean = if (tog) {
		val cal = left - gcd(a, left)
		if (cal >= 0) recursive(!tog, cal) else tog
	} else {
		val cal = left - gcd(b, left)
		if (cal >= 0) recursive(!tog, cal) else tog
	}

	def gcd(a: Int, b: Int): Int = if (a == 0) b else gcd(b % a, a)

	if (recursive(true, n)) {
		println(1)
	} else {
		println(0)
	}
}

import scala.io.StdIn

object Main extends App {
  val str = StdIn.readLine().split(" ").map(_.toInt)
  val a = str(0)
  val b = str(1)
  var n = str(2)
  var moveCount = 0

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  while(n >= 0) {
    if (moveCount == 0) {
      val move = gcd(a, n)
      n = n - move
      moveCount = 1
    } else {
      val move = gcd(b, n)
      n = n - move
      moveCount = 0
    }
  }

  if (moveCount == 1) println(1)
  else println(0)
}

object Solutuin119A extends App {

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

  def gcd(a: Int, b: Int): Int = {
    val n = norm(a, b)
    n._2 % n._1 match {
      case 0 => n._1
      case m => gcd(m, n._1)
    }
  }

  def solution() {
    val a = _int
    val b = _int
    val n = _int
    val qqq = Map(0 -> a, 1 -> b)

    def wins(n: Int, turn: Int): Int = n match {
      case 0 => (turn + 1) % 2
      case _ => wins(n - gcd(n, qqq(turn)), (turn + 1) % 2)
    }

    println(wins(n, 0))
  }

  //////////////////////////////////////////////////
  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.collection.mutable._
import scala.math._
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)
  def gcd(a: Int, b: Int): Int = if(b == 0) a else gcd(b, a%b)
  var t = Array[Int](sc.nextInt,sc.nextInt)
  var n = sc.nextInt
  def sim(s: Int): Int = {
    val g = gcd(n,t(s))
    val ns = (s+1)%2
    if(n < g) ns
    else { n-=g; sim(ns) }
  }
  println(sim(0))
}

object Solution extends App{
  def gcd(a: Int, b: Int): Int = {
    if(b == 0) a else gcd(b, a % b)
  }

  val in = scala.io.Source.stdin.getLines()
  var Array(a, b, n) = in.next().split(" ").map(_.toInt)
  var count = 0
  var take = gcd(a, n)
  while (n > take) {
    n -= take
    count += 1
    if (count % 2 == 1)
      take = gcd(b, n)
    else
      take = gcd(a, n)
  }
  println(count % 2)
}

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

object Codeforces119A {
    def gcd(a: Int,b: Int): Int = {
       if(b ==0) a else gcd(b, a%b)
    }

    def main(args: Array[String]) {
        val arr: ArraySeq[Int] = scala.io.StdIn.readLine().split(" ").map(Integer.parseInt)
        var currentPlayer = 0       // Simon
        var g: Int = 0
        while (arr(2) >= 0) {
            g = gcd(arr(currentPlayer), arr(2))
            if (arr(2) < g) {
                println(1-currentPlayer)
                return
            }
            else {
                arr(2) -= g
                currentPlayer = 1 - currentPlayer
            }
        }
    }
}

object A119 {
  @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 gcd(a: Int, b: Int): Int = if(b==0) a else gcd(b, a%b)
  def main(args: Array[String]): Unit = {
    var Array(a, b, n) = readInts(3)
    val arr = Array(a, b)
    var player = 0
    while(n > 0) {
      val gc = gcd(arr(player), n)
      n -= gc
      player = 1-player
    }
    println(1-player)
  }
}

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

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

  val A, B, N = sc.nextInt

  @tailrec
  def euclid(a: Int, b: Int): Int =
    if (b == 0) a
    else euclid(b, a % b)

  def gcd(a: Int, b: Int): Int =
    if (a > b) euclid(a, b)
    else euclid(b, a)

  def antisimon(x: Int): Int = {
    val r = gcd(x, B)
    if (x < r) 0
    else simon(x - r)
  }

  def simon(x: Int): Int = {
    val r = gcd(x, A)
    if (x < r) 1
    else antisimon(x - r)
  }

  val solve: Int = simon(N)

  out.println(solve)
  out.close
}

object EpicGame {
	def main (args: Array[String]) {
		val scanner = new java.util.Scanner(System.in);
		val a = scanner.nextInt();
		val b = scanner.nextInt();
		var n = scanner.nextInt();
		var turn = 0 // 0 for Simon's turn
		while (n > 0) {
		  n -= gcd(n, if (turn == 0) a else b)
		  turn = 1 - turn
		}
		print(1 - turn)
	}

	def gcd (x: Int, y: Int) : Int = {
	  if (x > y) {
	    gcd(x - y, y)
	  }
	  else {
	    if (x == y) {
	      x
	    }
	    else {
	      gcd (x, y - x)
	    }
	  }

	}
}

object Codeforces119A extends App{

  def GCDFind(first:Int,second:Int):Int={
    var a:Int=first
    var b:Int=second
    var temp:Int=0
    if (b>a){
      temp=a
      a=b
      b=temp
    }
    temp=b
    while((a%temp!=0)||(b%temp!=0)){
      temp=a-(a/b)*b
      a=b
      b=temp
    }
    return temp
  }

  def EpicGame(simon:Int,antisimon:Int,totalstone:Int):Int={
    var currentstone:Int=totalstone
    var temp:Int=0
    while(currentstone!=0){
      temp=GCDFind(simon,currentstone)
      currentstone = currentstone-temp
      if (currentstone==0){
        return 0
      }
      temp=GCDFind(antisimon,currentstone)
      currentstone = currentstone-temp
      if (currentstone==0){
        return 1
      }
    }
    return 1
  }
  val oldgroup=scala.io.StdIn.readLine.split(" ")
  var ingroup=oldgroup.map(_.toInt)
  println(EpicGame(ingroup(0),ingroup(1),ingroup(2)))

}

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

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

  @tailrec
  def gcd(a: Int, b: Int): Int = if(b == 0) a else gcd(b, a % b)

  @tailrec
  def ans(a: Array[Int], i: Int, n: Int): Int = if(n == 0) 1 - i else ans(a, (i + 1) % 2, n - gcd(n, a(i)))

  def main(a: Array[String]) {
    val a = readInts
    println(ans(a, 0, a(2)))
  }
}

object Main {
  def gcd(a: Int, b: Int): Int =
    if (a % b == 0) b
    else gcd(b, a % b)

  def main(args: Array[String]) {
    val arr = readLine().split(" ").map(_.toInt)
    val a = arr(0)
    val b = arr(1)
    var n = arr(2)
    var turn = 1
    while (n != 0) {
      if (turn == 1) {
        n -= gcd(n, a)
        turn = 0
      } else {
        n -= gcd(n, b)
        turn = 1
      }
    }
    println(turn)
  }
}

import java.util.Scanner

object CF119A {
  def gcd(a:Int,b:Int):Int = b match{
    case 0=> a
    case b=> gcd(b,a%b)
  }

  def main(args: Array[String]){
    val sc:Scanner = new Scanner(System.in)
    val a = sc.nextInt; val b = sc.nextInt; var s = sc.nextInt
    var turn = 0
    while(gcd(if (turn==0) a else b,s) <= s){
      s -= gcd(if (turn==0) a else b,s)
      turn = (turn+1)%2
    }
    turn = (turn+1)%2
    println(turn);
  }
}

import scala.collection.mutable._
import scala.math._
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)
  def gcd(a: Int, b: Int): Int = if(b == 0) a else gcd(b, a%b)
  var t = Array[Int](sc.nextInt,sc.nextInt)
  var n = sc.nextInt
  def sim(s: Int): Int = {
    val g = gcd(n,t(s))
    if(n > g) return (s+1)%2
    else { n-=g; sim((s+1)%2) }
  }
  println(sim(0))
}


Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least x blue, y violet and z orange spheres. Can he get them (possible, in multiple actions)?

The first line of the input contains three integers a, b and c (0 ≤ a, b, c ≤ 1 000 000) — the number of blue, violet and orange spheres that are in the magician's disposal. The second line of the input contains three integers, x, y and z (0 ≤ x, y, z ≤ 1 000 000) — the number of blue, violet and orange spheres that he needs to get.

If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No".

NoteIn the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs.

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val r = in.next().split(' ').map(_.toInt).zip(in.next().split(' ').map(_.toInt)).foldLeft(0, 0) {
    case((minus, plus), (have, need)) if need <= have => (minus, plus + (have - need) / 2)
    case((minus, plus), (have, need)) => (minus + need - have, plus)
  }
  if (r._1 > r._2)
    println("No")
  else
    println("Yes")
}

object A606 {

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

  def main(args: Array[String]): Unit = {
    val Array(a,b,c) = readInts(3)
    val Array(x,y,z) = readInts(3)
    if(solve(a,b,c,x,y,z)) {
      println("Yes")
    } else {
      println("No")
    }
  }

  def solve(a: Int, b: Int, c: Int, x: Int, y: Int, z: Int): Boolean = {
    if(x == 0 && y == 0 && z == 0)
      true
    else {
      if (a >= x) {
        solve(b, c, a - x, y, z, 0)
      } else {
        val short = x-a
        if((c-z)/2 > 0) {
          val extra = math.min(short, (c-z)/2)
          solve(a+extra, b, c - extra*2, x, y, z)
        } else if((b-y)/2 > 0) {
          val extra = math.min(short, (b-y)/2)
          solve(a+extra, b - extra*2, c, x, y, z)
        } else {
          false
        }
      }
    }
  }

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

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

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

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

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

}

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  val as = readInts(3)
  val bs = readInts(3)

  val have = (0 to 2).map(i => ((as(i) - bs(i)) / 2) max 0).sum
  val need = (0 to 2).map(i => (bs(i) - as(i)) max 0).sum

  println(if (have >= need) "Yes" else "No")
}

import io.StdIn._

object Main{
  def main (args: Array[String]){
    val yes = "Yes"
    val no = "No"

    val Array(a, b, c) = readLine.split(' ').map(_.toInt)
    val Array(x, y, z) = readLine.split(' ').map(_.toInt)

    var dif = new Array[Int](3)
    dif(0) = a - x
    dif(1) = b - y
    dif(2) = c - z

    var over = 0
    var husoku = 0
    for(i <- 0 to 2){
      if (dif(i) >= 0) over += dif(i) / 2
      else husoku += Math.abs(dif(i))
    }

    if(over >= husoku) println(yes)
    else println(no)
  }
}

object A{
  //import scala.collection.mutable.PriorityQueue
  //import scala.collection.mutable.ArrayBuffer
  import util.control.Breaks._
  import java.io.{PrintWriter,InputStream,BufferedReader,InputStreamReader}
  import java.util.{Locale, Scanner,StringTokenizer}
  class InputReader(val stream:InputStream ) {
    var st:StringTokenizer=new StringTokenizer("")
    val reader=new BufferedReader(new InputStreamReader(stream), 32768);

    def next():String = {
        while (!st.hasMoreTokens()){
          val currentLine = reader.readLine
          st=new StringTokenizer(currentLine)
        }
        return st.nextToken
    }

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

    def nextLong():Long = {
    	return next.toLong
    }
    def nextDouble:Double = {
      return next.toDouble
    }
  }

  def main(args: Array[String]){

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

    def nextInt = in.nextInt
    def nextLong = in.nextLong
    def nextDouble = in.nextDouble
    def nextString = in.next
    //code starts here
    val has=for(i<-0 until 3) yield nextInt
    val want=for(i<-0 until 3) yield nextInt
    var sum=0
    for(i<-0 until 3){
      if(has(i)>want(i)){
        sum+=(has(i)-want(i))/2
      }else{
        sum+=has(i)-want(i)
      }

    }
    if(sum>=0){
      out.print("Yes")
    }else{
      out.print("No")
    }

    //code ends here
    out.flush
    out.close
  }
}

object A606 {

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

  def main(args: Array[String]): Unit = {
    val Array(a,b,c) = readInts(3)
    val Array(x,y,z) = readInts(3)
    if(solve(a,b,c,x,y,z)) {
      println("Yes")
    } else {
      println("No")
    }
  }

  def solve(a: Int, b: Int, c: Int, x: Int, y: Int, z: Int): Boolean = {
    if(x == 0 && y == 0 && z == 0)
      true
    else {
      if (a >= x) {
        solve(b, c, a - x, y, z, 0)
      } else {
        val short = x-a
        if((b-y)/2 > 0) {
          val extra = (b-y)/2
          solve(a+extra, b - extra*2, c, x, y, z)
        } else if((c-z)/2 > 0) {
          val extra = (c-z)/2
          solve(a+extra, b, c - extra*2, x, y, z)
        } else {
          false
        }
      }
    }
  }

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

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

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

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

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

}

import scala.collection._

object A extends App {

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

  case class X(a: Int, b: Int, c: Int)

  val Array(a, b, c) = readInts(3)
  val start = X(a, b, c)

  val Array(x, y, z) = readInts(3)
  val goal = X(x, y, z)

  val end = System.currentTimeMillis() + 1500
  val visited = mutable.Set.empty[X]

  def check(q: X): Unit = {
    //println(q)
    if (!visited(q) && System.currentTimeMillis < end) {
      visited += q
      if (q == goal) {
        println("Yes")
        System.exit(0)
      } else {
        if (q.a > goal.a) {
          check(X(q.a - 2, q.b + 1, q.c))
          check(X(q.a - 2, q.b, q.c + 1))
        }
        if (q.b > goal.b) {
          check(X(q.a + 1, q.b - 2, q.c))
          check(X(q.a, q.b - 2, q.c + 1))
        }
        if (q.c > goal.c) {
          check(X(q.a + 1, q.b, q.c - 2))
          check(X(q.a, q.b + 1, q.c - 2))
        }
      }
    }
  }

  check(start)

  println("No")
}

import scala.collection._

object A extends App {

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

  case class X(a: Int, b: Int, c: Int)

  val Array(a, b, c) = readInts(3)
  val start = X(a, b, c)

  val Array(x, y, z) = readInts(3)
  val goal = X(x, y, z)

  val end = System.currentTimeMillis() + 1500
  val visited = mutable.Set.empty[X]

  def check(q: X): Unit = {
    //println(q)
    if (!visited(q) && System.currentTimeMillis < end) {
      visited += q
      if (q.a >= goal.a && q.b >= goal.b && q.c >= goal.c) {
        println("Yes")
        System.exit(0)
      } else {
        if (q.a > goal.a + 2000) {
          check(X(q.a - 1000, q.b + 500, q.c))
          check(X(q.a - 1000, q.b, q.c + 500))
        }
        if (q.b > goal.b + 2000) {
          check(X(q.a + 500, q.b - 1000, q.c))
          check(X(q.a, q.b - 1000, q.c + 500))
        }
        if (q.c > goal.c + 2000) {
          check(X(q.a + 500, q.b, q.c - 1000))
          check(X(q.a, q.b + 500, q.c - 1000))
        }
        if (q.a > goal.a) {
          check(X(q.a - 2, q.b + 1, q.c))
          check(X(q.a - 2, q.b, q.c + 1))
        }
        if (q.b > goal.b) {
          check(X(q.a + 1, q.b - 2, q.c))
          check(X(q.a, q.b - 2, q.c + 1))
        }
        if (q.c > goal.c) {
          check(X(q.a + 1, q.b, q.c - 2))
          check(X(q.a, q.b + 1, q.c - 2))
        }
      }
    }
  }

  check(start)

  println("No")
}

import scala.collection._

object A extends App {

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

  case class X(a: Int, b: Int, c: Int)

  val Array(a, b, c) = readInts(3)
  val start = X(a, b, c)

  val Array(x, y, z) = readInts(3)
  val goal = X(x, y, z)

  val end = System.currentTimeMillis() + 1500
  val visited = mutable.Set.empty[X]

  def check(q: X): Unit = {
    //println(q)
    if (!visited(q) && System.currentTimeMillis < end) {
      visited += q
      if (q.a >= goal.a && q.b >= goal.b && q.c >= goal.c) {
        println("Yes")
        System.exit(0)
      } else {
        if (q.a > goal.a + 4000) {
          check(X(q.a - 1000, q.b + 500, q.c))
          check(X(q.a - 1000, q.b, q.c + 500))
        }
        if (q.b > goal.b + 4000) {
          check(X(q.a + 500, q.b - 1000, q.c))
          check(X(q.a, q.b - 1000, q.c + 500))
        }
        if (q.c > goal.c + 4000) {
          check(X(q.a + 500, q.b, q.c - 1000))
          check(X(q.a, q.b + 500, q.c - 1000))
        }
        if (q.a > goal.a) {
          check(X(q.a - 2, q.b + 1, q.c))
          check(X(q.a - 2, q.b, q.c + 1))
        }
        if (q.b > goal.b) {
          check(X(q.a + 1, q.b - 2, q.c))
          check(X(q.a, q.b - 2, q.c + 1))
        }
        if (q.c > goal.c) {
          check(X(q.a + 1, q.b, q.c - 2))
          check(X(q.a, q.b + 1, q.c - 2))
        }
      }
    }
  }

  check(start)

  println("No")
}


There are n students who have taken part in an olympiad. Now it's time to award the students.Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners.You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.

The first (and the only) line of input contains two integers n and k (1 ≤ n, k ≤ 1012), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas.

Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.

import scala.io.StdIn

object A extends App {

  var Array(n, k) = StdIn.readLine().split(" ").map(_.toLong)
  val x = n/(2*(k+1))
  println(x + " " + x*k + " " + (n - x*k -x))
}


You are given a square board, consisting of $$$n$$$ rows and $$$n$$$ columns. Each tile in it should be colored either white or black.Let's call some coloring beautiful if each pair of adjacent rows are either the same or different in every position. The same condition should be held for the columns as well.Let's call some coloring suitable if it is beautiful and there is no rectangle of the single color, consisting of at least $$$k$$$ tiles.Your task is to count the number of suitable colorings of the board of the given size.Since the answer can be very large, print it modulo $$$998244353$$$.

A single line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 500$$$, $$$1 \le k \le n^2$$$) — the number of rows and columns of the board and the maximum number of tiles inside the rectangle of the single color, respectively.

Print a single integer — the number of suitable colorings of the board of the given size modulo $$$998244353$$$.

NoteBoard of size $$$1 \times 1$$$ is either a single black tile or a single white tile. Both of them include a rectangle of a single color, consisting of $$$1$$$ tile.Here are the beautiful colorings of a board of size $$$2 \times 2$$$ that don't include rectangles of a single color, consisting of at least $$$3$$$ tiles:  The rest of beautiful colorings of a board of size $$$2 \times 2$$$ are the following:

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

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

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

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, K = sc.nextInt()
    val s = System.nanoTime()
    var dp, ndp = Array.ofDim[Int](N + 2, N + 2)
    dp(0)(0) = 1
    rep(N) { i =>
      import java.util
      rep(ndp.length)(i => util.Arrays.fill(ndp(i), 0))
      rep(i + 1) { j =>
        rep(i + 1) { k =>
          ndp(j + 1)(max(k, j + 1)) = (ndp(j + 1)(max(k, j + 1)) + dp(j)(k)) % MOD
          ndp(1)(max(k, 1)) = (ndp(1)(max(k, 1)) + dp(j)(k)) % MOD
        }
      }
      val tmp = dp
      dp = ndp
      ndp = tmp
    }

    val cnt = Array.ofDim[Long](N + 1)
    rep(N + 1) { j =>
      rep(N + 1) { k =>
        cnt(k) = (cnt(k) + dp(j)(k)) % MOD
      }
    }
    val cum = Array.ofDim[Long](N + 1)
    cum(0) = cnt(0)
    rep(N){ k =>
      cum(k + 1) = (cum(k + 1) + cum(k) + cnt(k + 1)) % MOD
    }

    var ans = 0L
    rep(N, 1) { i =>
      val j = min(N, (K - 1) / i)
      ans = (ans + cnt(i) * cum(j)) % MOD
    }

    ans = ans * (MOD + 1) / 2 % MOD

    out.println(ans)

    val e = System.nanoTime()
    System.err.println(s"${(e-s)/1000000}")
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

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

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

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

object E extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }

  val Array(n, k) = readInts(2)
  val MOD = 998244353L
  val MODB = BigInt(MOD)
  val TWO = BigInt(2)

  val counts = Array.fill(n + 1)(0L)
  var prev = 0L
  for (kh <- 1 to (k min n)) {
    val dp = Array.fill(n + 1, 2)(0L)
    for (i <- 1 to n) {
      if (i <= kh) {
        val pp = TWO.modPow((i min kh) - 1, MODB).toLong
        dp(i)(0) = pp
        dp(i)(1) = pp
      } else {
        var p = 1L
        for (j <- 1 to (i min kh)) {
          dp(i)(0) = (dp(i)(0) + dp(i - j)(1)) % MOD
          dp(i)(1) = (dp(i)(1) + dp(i - j)(0)) % MOD
          p = 2 * p % MOD
        }
      }
    }
    val total = (dp(n)(0) + dp(n)(1)) % MOD
    counts(kh) = (total - prev + MOD) % MOD
    prev = total
  }

  var res = 0L
  for (kh <- 1 to n) {
    for (kv <- 1 to n) {
      if (kh * kv < k) res = (res + counts(kh) * counts(kv)) % MOD
    }
  }

  println(res * TWO.modInverse(MODB) % MOD)
}

object E extends App {

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

  val Array(n, k) = readInts(2)
  val MOD = 998244353L
  val MODB = BigInt(MOD)
  val TWO = BigInt(2)

  val counts = Array.fill(n + 1)(0L)
  for (kh <- 1 to (k min n)) {
    val dp = Array.fill(n + 1, 2)(0L)
    for (i <- 1 to n) {
      if (i <= kh) {
        val pp = TWO.modPow((i min kh) - 1, MODB).toLong
        dp(i)(0) = pp
        dp(i)(1) = pp
      } else {
        var p = 1L
        for (j <- 1 to (i min kh)) {
          dp(i)(0) = (dp(i)(0) + dp(i - j)(1)) % MOD
          dp(i)(1) = (dp(i)(1) + dp(i - j)(0)) % MOD
          p = 2 * p % MOD
        }
      }
//      val p = TWO.modPow((i min kh) - 1, MODB).toLong
//      if (i <= kh) {
//        dp(i)(0) = p
//        dp(i)(1) = p
//      } else {
//        dp(i)(0) = p * dp(i - kh)(1) % MOD
//        dp(i)(1) = p * dp(i - kh)(0) % MOD
//      }
    }
    //println(kh, dp.map(_.sum).mkString(" "))
    counts(kh) = (dp(n)(0) + dp(n)(1) + MOD - counts(kh - 1)) % MOD
  }
//println(counts.mkString(" "))
  var res = 0L
  for (kh <- 1 to n) {
    for (kv <- 1 to n) {
      //println(res, counts(kh), counts(kv))
      if (kh * kv < k) res = (res + counts(kh) * counts(kv)) % MOD
    }
  }

  println(res * TWO.modInverse(MODB) % MOD)
}


Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.Help Pasha count the maximum number he can get if he has the time to make at most k swaps.

The single line contains two integers a and k (1 ≤ a ≤ 1018; 0 ≤ k ≤ 100).

Print the maximum number that Pasha can get if he makes at most k swaps.

import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val in = new Scanner(System.in)
    val s = in.next
    var k = in.nextInt

    val arr = s.toCharArray()

    for (i <- 0 to arr.length - 2) {
      var maxPos = -1
      for (j <- i to Math.min(i + k, arr.length - 1))
        if (maxPos == -1 || arr(j) > arr(maxPos))
          maxPos = j
      if (maxPos != 0) {
        while (maxPos > i) {
          var t = arr(maxPos)
          arr(maxPos) = arr(maxPos - 1)
          arr(maxPos - 1) = t
          k = k - 1
          maxPos = maxPos - 1
        }
      }
    }

    println(arr.mkString)
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(az, kz) = in.next().split(' ')
  val k = kz.toInt
  val a = az.toCharArray

  def solve(data: Array[Char], index: Int, k: Int, ch: Char): Array[Char] =
    if (k == 0 || index == data.length - 1)
      a
    else if (ch <= data(index))
      solve(data, index + 1, k, '9')
    else {
      ((index + 1) to Math.min(data.length - 1, index + k)).find(i => data(i) == ch) match {
        case None => solve(data, index, k, (ch - 1).toChar)
        case Some(i) =>
          val tmp = data(i)
          (i until index by - 1).foreach {
            j => data(j) = data(j - 1)
          }
          data(index) = tmp
          solve(data, index + 1, k + index - i, '9')
      }
    }

  def sol(data: Array[Char], k: Int) = {
    solve(data, 0, k, '9')
  }

  println(sol(a, k).mkString)

}

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

object Codeforces435B {
    def main(args: Array[String]) {
        var Array(num, swaps) = scala.io.StdIn.readLine().split(" ").map(_.toLong)
        val numSeq = ArraySeq(num.toString.toList: _*)
        var i = 0
        while (i < numSeq.length-1 && swaps > 0) {
            var temp = 1
            var maxIndex = 0
            while (temp <= swaps && (i+temp) <= (numSeq.length-1)) {
                if (Integer.parseInt(numSeq(i+maxIndex).toString) < Integer.parseInt(numSeq(i+temp).toString))
                    maxIndex = temp
                temp += 1
            }
            swaps -= maxIndex
            while (maxIndex > 0) {
                val t = numSeq(i+maxIndex)
                numSeq(i+maxIndex) = numSeq(i+maxIndex-1)
                numSeq(i+maxIndex-1) = t
                maxIndex -= 1
            }
            i += 1
        }
        println(numSeq.mkString(""))
    }
}

/**
 * Created by ashione on 14-6-19.
 */
import java.util.Scanner
object swapNum {
  def main(Arg:Array[String]): Unit= {
    val s = new Scanner(System.in)
    val sl:String = s.next
    val dist = s.nextInt
    val (ans,_,_)=findNum(sl.toList,1,dist)
    ans foreach print
  }
  def findNum(sl:List[Char],start:Int,dist:Int):(List[Char],Int,Int) = {
    if(dist<=0 || start>=sl.length) return (sl,0,0)
    var localtion = start-1
    for(i <- start to start + dist-1 if i<sl.length)
      if(sl(i)>sl(localtion)) localtion = i
    if(localtion!=start-1) {
      val (sl1, sl2) = sl.splitAt(localtion)
      val (d, e) = sl2.splitAt(1)
      val (a, sl1t) = sl1.splitAt(start - 1)
      val (b, c) = sl1t.splitAt(1)
      findNum(a ::: d ::: b ::: c ::: e, start + 1, dist-(localtion - start+1))
    }
    else findNum(sl,start+1,dist)

  }

}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(as, ks) = in.next().split(' ')
  val k = ks.toInt
  val a = as.toCharArray
  val r = (1 to k).foreach { _ =>
    val i = (1 until a.length).find(i => a(i) > a(i - 1))
    if (i.nonEmpty) {
      val tmp = a(i.get)
      a(i.get) = a(i.get - 1)
      a(i.get - 1) = tmp
    }

  }
  println(a.mkString)
}

/**
 * Created by ashione on 14-6-19.
 */
import java.util.Scanner
object swapNum {
  def main(Arg:Array[String]): Unit= {
    val s = new Scanner(System.in)
    val sl:String = s.next
    val dist = s.nextInt
    val (ans,_,_)=findNum(sl.toList,1,dist)
    ans foreach print
  }
  def findNum(sl:List[Char],start:Int,dist:Int):(List[Char],Int,Int) = {
    if(dist<=0 || start>=sl.length) return (sl,0,0)
    var localtion = start-1
    for(i <- start to start + dist-1 if i<sl.length)
      if(sl(i)>sl(localtion)) localtion = i
    if(localtion!=start-1) {
      val (sl1, sl2) = sl.splitAt(localtion)
      val (d, e) = sl2.splitAt(1)
      val (a, sl1t) = sl1.splitAt(start - 1)
      val (b, c) = sl1t.splitAt(1)
      findNum(a ::: d ::: c ::: b ::: e, start + 1, localtion - start)
    }
    else findNum(sl,start+1,dist)

  }

}

import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val in = new Scanner(System.in)
    val s = in.next
    var k = in.nextInt

    val arr = s.toCharArray()

    while (k > 0) {
      k = k - 1
      def loop(i: Int): Unit =
        if (i < arr.length - 1) {
          if (arr(i) < arr(i + 1)) {
            val t = arr(i)
            arr(i) = arr(i + 1)
            arr(i + 1) = t
          } else loop(i + 1)
        }
      loop(0)
    }

    println(arr.mkString)
  }
}

import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val in = new Scanner(System.in)
    val s = in.next
    var k = in.nextInt

    val arr = s.toCharArray()

    for (i <- 0 to arr.length - 2) {
      var maxPos = 0
      for (j <- i to Math.min(i + k, arr.length - 1))
        if (arr(j) > arr(maxPos) || maxPos == 0)
          maxPos = j
      if (maxPos != 0) {
        while (maxPos > i) {
          var t = arr(maxPos)
          arr(maxPos) = arr(maxPos - 1)
          arr(maxPos - 1) = t
          k = k - 1
          maxPos = maxPos - 1
        }
      }
    }

    println(arr.mkString)
  }
}


Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?

The first and the only line of the input contains two distinct integers n and m (1 ≤ n, m ≤ 104), separated by a space .

Print a single number — the minimum number of times one needs to push the button required to get the number m out of number n.

NoteIn the first example you need to push the blue button once, and then push the red button once.In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.

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

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

  class Task {
    private val INF = 1e6.asInstanceOf[Int]

    def solve(in: InputReader, out: PrintWriter): Unit = {
      val n = in.nextInt()
      val m = in.nextInt()
      val ans = dfs(n, m, Array.ofDim[Int](math.max(n, m) + 1))
      out.println(ans)
    }

    private def dfs(n: Int, m: Int, memo: Array[Int]): Int = {
      if (n >= m) n - m
      else if (n <= 0) INF
      else if (memo(n) > 0) memo(n)
      else {
        memo(n) = INF
        memo(n) = math.min(dfs(n * 2, m, memo), dfs(n - 1, m, memo)) + 1
        memo(n)
      }
    }
  }

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

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

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

}

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

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

  class Task {
    private val INF = 1e6.asInstanceOf[Int]

    def solve(in: InputReader, out: PrintWriter): Unit = {
      val n = in.nextInt()
      val m = in.nextInt()
      val ans = dfs(n, m, Array.ofDim[Int](math.max(n, m) + 1))
      out.println(ans)
    }

    private def dfs(n: Int, m: Int, memo: Array[Int]): Int = {
      if (n >= m) n - m
      else if (n <= 0) INF
      else if (memo(n) > 0) memo(n)
      else {
        memo(n) = INF
        memo(n) = math.min(dfs(n * 2, m, memo), dfs(n - 1, m, memo)) + 1
        memo(n)
      }
    }
  }

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

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

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

}

object TwoButtons {
  case class Pair(e:Int,stp:Int)
  def main(args: Array[String]): Unit = {
    val in =scala.io.StdIn
    var line=in.readLine()
    var n=line.split(" ")(0).toInt
    var m=line.split(" ")(1).toInt
    //val n=4 ; val m=6
    //val n=10 ; val m=1
    //Applying BSF and in level order search the first occurrence of m is the minimum step
    var click=0
	while (m!=n){
	  click+=1
	  if(m>n) {
		if (m % 2 == 0) {
		  m /= 2
		} else {
		  m = (m + 1) / 2
		  click+=1
		}
	  }else{
		m+=1
	  }
	}
	println(click)
  }
}

import scala.collection.mutable

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

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

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

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

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

  val MAX = 2*10000
  val graph = Array.fill(MAX+1)(List.empty[Int])
  graph(1) = List(2)
  for(i <- 2 to MAX) {
    graph(i) = List(2*i, i-1)
  }
  def bfs(src: Int, des: Int): Int = {
    val vis = Array.fill(MAX+1)(false)
    val q = mutable.Queue.empty[(Int, Int)]
    q.enqueue((0, src))
    vis(src) = true
    while(q.nonEmpty) {
      val (dist, ele) = q.dequeue()
      if(des == ele) {
        return dist
      }
      if(ele <= MAX) {
        for (i <- graph(ele) if i <= MAX && !vis(i)) {
          q.enqueue((dist + 1, i))
          vis(i) = true
        }
      }
    }
    -1
  }
  def main(args: Array[String]): Unit = {
    var Array(n, m) = readInts(2)
    println(bfs(n, m))
  }

}

/**
 * Created by yangchaozhong on 3/16/15.
 */
object CF520B extends App {
  import scala.collection.mutable.HashSet
  import java.util.{Scanner}
  import java.io.{PrintWriter}

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

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

  def solve = {
    val n = nextInt
    val m = nextInt

    if (n >= m) {
      out.println(n - m)
    } else {

      def dfs(x: Int): Int = {
        if (x == n) 0
        else if (x < n) {
          n - x
        } else {
          if (x % 2 == 0) {
            dfs(x / 2) + 1
          } else {
            dfs(x + 1) + 1
          }
        }
      }

      out.println(dfs(m))
    }
  }

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

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

import scala.collection.mutable

object B {

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

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

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

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

  def f(n: Int, m: Int, dp: Array[Int]): Int = {
    if (n >= m) {
      return n - m
    }
    if (n <= 0) {
      return 1e6.toInt
    }
    if (dp(n) > 0) {
      return dp(n)
    }
    dp(n) = 1e6.toInt
    dp(n) = Math.min(f(2 * n, m, dp), f(n - 1, m, dp)) + 1
    return dp(n)
  }

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    val sz = Math.max(n, m)
    val dp = new Array[Int](sz + 1)
    out.println(f(n, m, dp))
    return 1
  }

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

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

object Main2 extends App {
  val Array(initialNumber, desiredNumber) = readLine().split(" ").map(_.toInt)
  val queue = mutable.Queue((initialNumber, 0))
  var answers = ArrayBuffer.fill(20001)(-1)
  while (queue.nonEmpty) {
    val (value, actionCount) = queue.dequeue()
    if (value - 1 > 0 && answers(value - 1) == -1) {
      answers(value - 1) = actionCount + 1
      queue.enqueue((value - 1, actionCount + 1))
    }
    if (value * 2 < 20001 && answers(value * 2) == -1) {
      answers(value * 2) = actionCount + 1
      queue.enqueue((value * 2, actionCount + 1))
    }
  }
  println(answers(desiredNumber))
}

object TwoButtons {
  case class Pair(e:Int,stp:Int)
  def main(args: Array[String]): Unit = {
    val in =scala.io.StdIn
    var line=in.readLine()
    var n=line.split(" ")(0).toInt
    var m=line.split(" ")(1).toInt
    //val n=4 ; val m=6
    //val n=10 ; val m=1
    //Applying BSF and in level order search the first occurrence of m is the minimum step
    var click=0
	while (m!=n){
	  click+=1
	  if(m>n) {
		if (m % 2 == 0) {
		  m /= 2
		} else {
		  m = (m + 1) / 2
		}
	  }else{
		m+=1
	  }
	}
	println(click)
  }
}

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

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

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

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

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

  def main(args: Array[String]): Unit = {
    var Array(n, m) = readInts(2)
    if(n > m) {
      println(n-m)
    } else {
      if (m % 2 == 0) {
        var res = 0
        while(m % 2 == 0 && n < m) {
          m /= 2
          res += 1
        }
        println(res + (n-m))
      } else {
        var res = 0
        while(n < m) {
          n *= 2
          res += 1
        }
        println(res + n-m)
      }
    }
  }

}

/**
 * Created by yangchaozhong on 3/16/15.
 */
object CF520B extends App {
  import java.util.{Scanner}
  import java.io.{PrintWriter}

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

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

  def solve = {
    val n = nextInt
    val m = nextInt

    if (n >= m) {
      out.println(n - m)
    } else {
      def dfs(x: Int): Int = {
        if (x == m) 0
        else if (x > m) {
          x - m
        } else {
          if (x > m / 2 && x > 2)
            Math.min(dfs(x * 2) + 1, dfs(x - 1) + 1)
          else
            dfs(x * 2) + 1
        }
      }

      out.println(dfs(n))
    }
  }

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

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

object B {

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

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

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

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

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    if (m < n) {
      out.println(n - m)
      return 1
    }
    if (m == n) {
      out.println(0)
      return 1
    }
    var y = m
    var ans = 0
    while (y % 2 == 0) {
      y /= 2
      ans += 1
    }
    val sz = Math.max(n, y)
    val dp = new Array[Array[Int]](sz + 1)
    for (i <- 0 until sz + 1) {
      dp(i) = new Array[Int](sz + 1)
    }

    for (i <- 0 to sz) {
      for (j <- i + 1 until sz) {
        dp(i)(j) = j - i
      }
    }
    for (i <- 1 to sz) {
      for (j <- 1 to sz) {
        if (i * 2 <= sz) {
          dp(i)(j) = Math.min(dp(i - 1)(j), dp(i * 2)(j)) + 1
        }
        else {
          dp(i)(j) = dp(i - 1)(j) + 1
        }
      }
    }
    out.println(dp(y - 1)(y - 1) + ans)
    return 1
  }

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

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

object B {

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

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

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

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

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    if (m < n) {
      out.println(n - m)
      return 1
    }
    if (m == n) {
      out.println(0)
      return 1
    }
    var x = n
    var y = m
    var ans = 0
    while (y > n && y % 2 == 0) {
      y /= 2
      ans += 1
    }
    while (x < y) {
      x *= 2
      ans += 1
    }
    if (y < x) {
      out.println(ans + x - y)
      return 1
    }
    if (y == x) {
      out.println(ans)
      return 1
    }
    return 1
  }

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

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

object B {

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

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

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

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

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    if (m < n) {
      out.println(n - m)
      return 1
    }
    if (m == n) {
      out.println(0)
      return 1
    }
    var x = n
    var ans = 0
    while (x < m) {
      x *= 2
      ans += 1
    }
    if (m % 2 == 0 && n > m / 2) {
      out.println(Math.min(n - m / 2 + 1, ans + x - m))
    } else {
      out.println(ans + x - m)
    }
    return 1
  }

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


InputThe input contains a single integer a (0 ≤ a ≤ 35).OutputOutput a single integer.ExamplesInput3Output8Input10Output1024

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  println(1l << in.next().toInt)
}


Two beavers, Timur and Marsel, play the following game.There are n logs, each of exactly m meters in length. The beavers move in turns. For each move a beaver chooses a log and gnaws it into some number (more than one) of equal parts, the length of each one is expressed by an integer and is no less than k meters. Each resulting part is also a log which can be gnawed in future by any beaver. The beaver that can't make a move loses. Thus, the other beaver wins.Timur makes the first move. The players play in the optimal way. Determine the winner.

The first line contains three integers n, m, k (1 ≤ n, m, k ≤ 109).

Print "Timur", if Timur wins, or "Marsel", if Marsel wins. You should print everything without the quotes.

NoteIn the first sample the beavers only have one log, of 15 meters in length. Timur moves first. The only move he can do is to split the log into 3 parts each 5 meters in length. Then Marsel moves but he can't split any of the resulting logs, as k = 4. Thus, the winner is Timur.In the second example the beavers have 4 logs 9 meters in length. Timur can't split any of them, so that the resulting parts possessed the length of not less than 5 meters, that's why he loses instantly.

import java.io.ByteArrayInputStream

object Main {

  def main(args: Array[String]) = {
    /** setup **/
    var debug: Object => Unit = null
    if (!args.isEmpty && args.head == "test") {
      debug = println
      val TEST = "2 100000 569\n605 986"
      System.setIn(new ByteArrayInputStream(TEST.getBytes))
    } else {
      debug = a => Unit
    }
    val input = scala.io.Source.stdin.getLines()

    /** parse **/

    val line = input.next().split(" ").map(_.toInt)
    val (n, m, k) = (line(0), line(1), line(2))

    var sol = ""
    val p1 = "Timur"
    val p2 = "Marsel"
    /** algorithm **/

    if (n % 2 == 0) sol = p2
    else if (k == m) sol = p2
    else if (k != 0 && k != 1 && (2 to (Math.ceil(Math.sqrt(m)).toInt)).find(i => m % i == 0 && m / i >= k).isEmpty) sol = p2
    else sol = p1
    /** print **/
    println(sol)
  }
}

object Main {

  def main(args: Array[String]) = {
    val input = scala.io.Source.stdin.getLines()

    val a = input.next().split(" ").map(_.toInt).toList.toArray

    val sum = a.sum

    var cu = 0
    var p = 0

    var l = List.empty[Char]
    while (cu < sum) {
      if (a(p) == 0) {
        l = 'R' :: l
        p += 1
      } else if (p == a.length - 1) {
        l = 'R' :: 'L' :: 'P' :: l
        a(p) -= 1
        cu += 1
      } else if (p+1 < a.size && a(p+1) > 0 && a(p) > 1) {
        l = 'L' :: 'P' :: 'R' :: 'P' :: l
        cu += 2
        a(p) -= 1
        a(p+1) -= 1
      } else if (a(p) > 1) {
        l = 'L' :: 'R' :: 'P' :: l
        a(p) -= 1
        cu += 1
      } else {
        l = 'R' :: 'P' :: l
        a(p) -= 1
        cu += 1
        p += 1
      }
    }
    while (l.head != 'P') l = l.tail
    print(l.reverse.mkString)
  }
}

import java.io.ByteArrayInputStream

object Main {

  def main(args: Array[String]) = {
    /** setup **/
    var debug: Object => Unit = null
    if (!args.isEmpty && args.head == "test") {
      debug = println
      val TEST = "2 100000 569\n605 986"
      System.setIn(new ByteArrayInputStream(TEST.getBytes))
    } else {
      debug = a => Unit
    }
    val input = scala.io.Source.stdin.getLines()

    /** parse **/

    val line = input.next().split(" ").map(_.toInt)
    val (n, m, k) = (line(0), line(1), line(2))

    var sol = ""
    val p1 = "Timur"
    val p2 = "Marsel"
    /** algorithm **/

    if (n % 2 == 0) sol = p2
    else if (m % k != 0) sol = p2
    else sol = p1
    /** print **/
    println(sol)
  }
}

import java.io.ByteArrayInputStream

object Main {

  def main(args: Array[String]) = {
    /** setup **/
    var debug: Object => Unit = null
    if (!args.isEmpty && args.head == "test") {
      debug = println
      val TEST = "2 100000 569\n605 986"
      System.setIn(new ByteArrayInputStream(TEST.getBytes))
    } else {
      debug = a => Unit
    }
    val input = scala.io.Source.stdin.getLines()

    /** parse **/

    val line = input.next().split(" ").map(_.toInt)
    val (n, m, k) = (line(0), line(1), line(2))

    var sol = ""
    val p1 = "Timur"
    val p2 = "Marsel"
    /** algorithm **/

    if (n % 2 == 0) sol = p2
    else if ((k until m).find(i => m % i == 0).nonEmpty) sol = p2
    else sol = p1
    /** print **/
    println(sol)
  }
}

import java.io.ByteArrayInputStream

object Main {

  def main(args: Array[String]) = {
    /** setup **/
    var debug: Object => Unit = null
    if (!args.isEmpty && args.head == "test") {
      debug = println
      val TEST = "2 100000 569\n605 986"
      System.setIn(new ByteArrayInputStream(TEST.getBytes))
    } else {
      debug = a => Unit
    }
    val input = scala.io.Source.stdin.getLines()

    /** parse **/

    val line = input.next().split(" ").map(_.toInt)
    val (n, m, k) = (line(0), line(1), line(2))

    var sol = ""
    val p1 = "Timur"
    val p2 = "Marsel"
    /** algorithm **/

    if (n % 2 == 0) sol = p2
    else if (k != 0 && k != 1 && (2 to (Math.ceil(Math.sqrt(m)).toInt)).find(i => m % i == 0 && m / i >= k).isEmpty) sol = p2
    else sol = p1
    /** print **/
    println(sol)
  }
}

import java.io.ByteArrayInputStream

object Main {

  def main(args: Array[String]) = {
    /** setup **/
    var debug: Object => Unit = null
    if (!args.isEmpty && args.head == "test") {
      debug = println
      val TEST = "2 100000 569\n605 986"
      System.setIn(new ByteArrayInputStream(TEST.getBytes))
    } else {
      debug = a => Unit
    }
    val input = scala.io.Source.stdin.getLines()

    /** parse **/

    val line = input.next().split(" ").map(_.toInt)
    val (n, m, k) = (line(0), line(1), line(2))

    var sol = ""
    val p1 = "Timur"
    val p2 = "Marsel"
    /** algorithm **/

    if (n % 2 == 0) sol = p2
    else if ((k until (Math.sqrt(m).toInt + 1)).find(i => m % i == 0).isEmpty) sol = p2
    else sol = p1
    /** print **/
    println(sol)
  }
}

import java.io.ByteArrayInputStream

object Main {

  def main(args: Array[String]) = {
    /** setup **/
    var debug: Object => Unit = null
    if (!args.isEmpty && args.head == "test") {
      debug = println
      val TEST = "2 100000 569\n605 986"
      System.setIn(new ByteArrayInputStream(TEST.getBytes))
    } else {
      debug = a => Unit
    }
    val input = scala.io.Source.stdin.getLines()

    /** parse **/

    val line = input.next().split(" ").map(_.toInt)
    val (n, m, k) = (line(0), line(1), line(2))

    var sol = ""
    val p1 = "Timur"
    val p2 = "Marsel"
    /** algorithm **/

    if (n % 2 == 0) sol = p2
    else if ((k to (Math.sqrt(m).toInt + 1)).find(i => m % i == 0).isEmpty) sol = p2
    else sol = p1
    /** print **/
    println(sol)
  }
}


Let's define a split of $$$n$$$ as a nonincreasing sequence of positive integers, the sum of which is $$$n$$$. For example, the following sequences are splits of $$$8$$$: $$$[4, 4]$$$, $$$[3, 3, 2]$$$, $$$[2, 2, 1, 1, 1, 1]$$$, $$$[5, 2, 1]$$$.The following sequences aren't splits of $$$8$$$: $$$[1, 7]$$$, $$$[5, 4]$$$, $$$[11, -3]$$$, $$$[1, 1, 4, 1, 1]$$$.The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $$$[1, 1, 1, 1, 1]$$$ is $$$5$$$, the weight of the split $$$[5, 5, 3, 3, 3]$$$ is $$$2$$$ and the weight of the split $$$[9]$$$ equals $$$1$$$.For a given $$$n$$$, find out the number of different weights of its splits.

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^9$$$).

Output one integer — the answer to the problem.

NoteIn the first sample, there are following possible weights of splits of $$$7$$$:Weight 1: [$$$\textbf 7$$$] Weight 2: [$$$\textbf 3$$$, $$$\textbf 3$$$, 1] Weight 3: [$$$\textbf 2$$$, $$$\textbf 2$$$, $$$\textbf 2$$$, 1] Weight 7: [$$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$, $$$\textbf 1$$$]

object CF964A extends App {
  import scala.io.Source

  //val src = Source.fromFile("data.txt")
  val src = Source.stdin
  val lines = src.getLines

  def readInts(): Array[Int] =  {
    val line = if (lines.hasNext) lines.next else null
    if (line == null) throw new RuntimeException("Premature end of source encountered")
    line.split(" ").map(x => x.toInt)
  }
  val ints = readInts()
  println(ints(0)/2 + 1)

}

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

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

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

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

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

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

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

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

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

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

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  private[IO] type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]

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


Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.

The only line of the input contains a single integer n (2 ≤ n ≤ 1018) — the number of players to participate in the tournament.

Print the maximum number of games in which the winner of the tournament can take part.

NoteIn all samples we consider that player number 1 is the winner.In the first sample, there would be only one game so the answer is 1.In the second sample, player 1 can consequently beat players 2 and 3. In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners.

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toLong
  var i = 0
  var a = 1l
  var b = 1l
  while (b <= n) {
    val tmp = a + b
    a = b
    b = tmp
    i += 1
  }
  println(i - 1)
}

import java.io._
import scala.io.Source

import scala.annotation.tailrec

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

  def processStdInOut(): Unit = {
    val src = Source.fromInputStream(System.in)
    processFromSource(src)
  }

  def processFromSource(src: Source): Unit = {
    try {
      val bw = new BufferedWriter(new OutputStreamWriter(System.out));
      try {
        val lines = src.getLines()
        processLines(lines, bw)
      } finally {
        bw.flush()
      }
    } finally {
      src.close();
    }
  }

  // Standard code above, custom code below
  def processLines(lines: Iterator[String], bw: BufferedWriter): Unit = {
    val n = lines.next().toLong
    val soln = solve(n)
    bw.write(soln.toString)
    bw.newLine()
  }

  // Cache the Fibonacci lookup for good performance:
  var minPlayersByChampionsWinsLookup = Map[Long, Long](
    0L -> 1L,  // A single player is champion without playing a single match
    1L -> 2L   // With 2 players the champion wins after a single match
  )

  // The following function is equivalent to fib(wins + 2) where fib is the Fibonacci sequence
  def minPlayersForChampionWithWins(wins: Long): Long = {
    if (minPlayersByChampionsWinsLookup.contains(wins)) {
      minPlayersByChampionsWinsLookup(wins)
    } else {
      val result = minPlayersForChampionWithWins(wins - 1) + minPlayersForChampionWithWins(wins - 2)
      minPlayersByChampionsWinsLookup += wins -> result
      result
    }
  }

  def solve(n: Long): Long = {
    @tailrec
    def search(candidateWins: Long): Long = {
      val minTournamentSize = minPlayersForChampionWithWins(candidateWins)

      if (minTournamentSize == n) candidateWins
      else if (minTournamentSize > n) (candidateWins - 1)  // overshot the target, so use previous value
      else search(candidateWins + 1)
    }

    search(0)
  }
}

import scala.collection.mutable

object A extends App {
  def readLongs = scala.io.StdIn.readLine().split(" ").map(_.toLong)

  val Array(n) = readLongs

  case class E(prev: Long, cur: Long, games : Int) {
    def next = E(cur, prev+cur, games+1)
  }

  var e = E(1, 1, 0)
  while (e.cur <= n) {
    e = e.next
   // println(e)
  }

  println(e.games-1)
}

object A extends App {

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

  val Array(n) = readLongs(1)

  var res = 1
  val memo = Array.fill(100000){ -1L }

  memo(1) = 2
  memo(2) = 3

  def minPlayers(moves: Int): Long = {
    if (memo(moves) < 0) memo(moves) = minPlayers(moves - 1) + minPlayers(moves - 2)
    memo(moves)
  }

  while (minPlayers(res) <= n) res += 1

  println(res - 1)
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toLong
  var i = 0
  var a = 1l
  var b = 1l
  while (b < n) {
    val tmp = a + b
    a = b
    b = tmp
    i += 1
  }
  println(i - 1)
}

import java.io._
import scala.io.Source

import scala.annotation.tailrec

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

  def processStdInOut(): Unit = {
    val src = Source.fromInputStream(System.in)
    processFromSource(src)
  }

  def processFromSource(src: Source): Unit = {
    try {
      val bw = new BufferedWriter(new OutputStreamWriter(System.out));
      try {
        val lines = src.getLines()
        processLines(lines, bw)
      } finally {
        bw.flush()
      }
    } finally {
      src.close();
    }
  }

  // Standard code above, custom code below
  def processLines(lines: Iterator[String], bw: BufferedWriter): Unit = {
    val n = lines.next().toLong
    val log2 = math.log(2)
    val rounds = math.ceil(math.log(n) / log2) + 0.1
      // note: bump it slightly in case of round errors like a ?.999999 "integer"
    bw.write(rounds.toLong.toString)
    bw.newLine()
  }
}

import java.io._
import scala.io.Source

import scala.annotation.tailrec

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

  def processStdInOut(): Unit = {
    val src = Source.fromInputStream(System.in)
    processFromSource(src)
  }

  def processFromSource(src: Source): Unit = {
    try {
      val bw = new BufferedWriter(new OutputStreamWriter(System.out));
      try {
        val lines = src.getLines()
        processLines(lines, bw)
      } finally {
        bw.flush()
      }
    } finally {
      src.close();
    }
  }

  // Standard code above, custom code below
  def processLines(lines: Iterator[String], bw: BufferedWriter): Unit = {
    val n = lines.next().toLong
    val soln = solve(n)
    bw.write(soln.toString)
    bw.newLine()
  }

  def solve(n: Long): Long = {
    @tailrec
    def loop(minGames: Long, counts: List[Long]): Long = counts match {
      case 0 :: tl           => loop(minGames + 1, tl)
      case 1 :: Nil          => minGames
      case a :: Nil          => loop(minGames, List(a - 2, 1))
      case 1 :: 1 :: Nil     => minGames + 2
      case 1 :: 1 :: c :: tl => loop(minGames + 2, (c + 1) :: tl)
      case 2 :: 1 :: tl      => loop(minGames + 1, 2 :: tl)  // Don't leave an "orphaned" player
      case a :: 0 :: tl      => loop(minGames, (a - 2) :: 1l :: tl)
      case a :: b :: Nil     => loop(minGames, List(a - 1, b - 1, 1))
      case a :: b :: c :: tl => loop(minGames, (a - 1) :: (b - 1) :: (c + 1) :: tl)
      case Nil => 0
    }

    val maxGamesPlayed = loop(0, List(n))
    maxGamesPlayed
  }
}

import java.io._
import scala.io.Source

import scala.annotation.tailrec

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

  def processStdInOut(): Unit = {
    val src = Source.fromInputStream(System.in)
    processFromSource(src)
  }

  def processFromSource(src: Source): Unit = {
    try {
      val bw = new BufferedWriter(new OutputStreamWriter(System.out));
      try {
        val lines = src.getLines()
        processLines(lines, bw)
      } finally {
        bw.flush()
      }
    } finally {
      src.close();
    }
  }

  // Standard code above, custom code below
  def processLines(lines: Iterator[String], bw: BufferedWriter): Unit = {
    val n = lines.next().toDouble
    val log2 = math.log(2)
    val rounds = math.ceil(math.log(n) / log2).toLong
    val adjRounds = if (math.pow(2, rounds) < n) rounds + 1
      else if (math.pow(2, rounds - 1) >= n) rounds - 1
      else rounds
    bw.write(adjRounds.toString)
    bw.newLine()
  }
}