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

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

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

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

  def solve(): Unit = {
    val N = nl()
    var h, w = 1
    while(h.toLong * w < N) {
      if (h < w) h += 1
      else w += 1
    }

    out.println(h + w)
  }

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

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

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

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

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

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


/**
 * @author pvasilyev
 * @since 16 Jun 2016
 */
object A437 extends App {

  val problemA: String = scala.io.StdIn.readLine().split("\\.")(1)
  val problemB: String = scala.io.StdIn.readLine().split("\\.")(1)
  val problemC: String = scala.io.StdIn.readLine().split("\\.")(1)
  val problemD: String = scala.io.StdIn.readLine().split("\\.")(1)
  val problems = List(("A", problemA), ("B", problemB), ("C", problemC), ("D", problemD))
  val sizes = problems.map(pair => (pair._1, pair._2.length))
  val sortedAsc = sizes.sortWith(_._2 < _._2)
  val sortedDesc = sizes.sortWith(_._2 >= _._2)

  if (2 * sortedAsc(0)._2 <= sortedAsc(1)._2 && sortedDesc(0)._2 < 2 * sortedDesc(1)._2) {
    println(sortedAsc(0)._1)
  } else if (sortedDesc(0)._2 >= 2 * sortedDesc(1)._2 && 2 * sortedAsc(0)._2 > sortedAsc(1)._2) {
    println(sortedDesc(0)._1)
  } else {
    println("C")
  }
}


object objecta {
    import java.io.{BufferedReader, FileInputStream, InputStreamReader}

    val source = System.in
    //new FileInputStream("D://in.txt")
    implicit val reader = new BufferedReader(new InputStreamReader(source))
    def readInt()(implicit reader: BufferedReader): Array[Int] = reader.readLine().split(" ").map(_.toInt)
    def readString()(implicit reader: BufferedReader): String = reader.readLine()

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

        var result = n
        for (i <- n / 2 until 0 by -1)
            if (s.substring(0, i) == s.substring(i, 2*i)) {
                println(i + 1 + n - 2*i)
                return
            }

        println(result)
    }
}


object PashaandHamsters421A 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 n = scanner.nextInt()
      val a = scanner.nextInt()
      val b = scanner.nextInt()
      val setA = (1 to a).map(_ => scanner.nextInt()).toSet
      val setB = (1 to b).map(_ => scanner.nextInt()).toSet
      val result = (1 to n).map{ i =>
        if(setA.contains(i))
          1
        else
          2
      }.mkString(" ")
      out.println(result)
    }
}


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

object Solution {

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

  def main(args: Array[String]) {
    val Array(x1, y1) = readInts(2)
    val Array(x2, y2) = readInts(2)

    println(Math.max(Math.abs(x1-x2), Math.abs(y1-y2)))

//    Console.withOut(new java.io.BufferedOutputStream(Console.out))
//    println(res.mkString("\n"))
//    Console.flush
  }
}


object Main {
  def main(args: Array[String]) {
    val std = scala.io.StdIn
    val n = std.readInt()
    val s = std.readLine()

    var res = "no"
    for( step <- 1 to s.length / 4 ) {
      for ( i <- 0 until step ) {
        var ss = ""
        for ( j <- i until s.length by step ) {
          ss += s(j)
        }

        if ( ss.contains("*****") ) {
          res = "yes"
        }
      }
    }
    println( res )
  }
}


import java.util.Scanner

object CF353A {

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

    val (n, a, b, c, d) = (scn.nextInt, scn.nextInt, scn.nextInt, scn.nextInt, scn.nextInt)

    val lst = List(a+b, a+c, b+d, c+d).sorted
    val (xmin, xmax) = (lst.head, lst.last)

    val result = math.max(0, n + xmin - 1 - xmax + 1) * n.toLong

    println(result)
  }

}


object Solution extends App {
  val in = io.Source.stdin.getLines()
  in.next()
  println(in.next().replaceAll("o(go)+", "***"))
}


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

  val MOD = 1000000007L
  val n, m = nextInt

  def fibonacci(n: Int): Long = {
    var prev, cur = 1L
    for (_ <- 1 until n) {
      val tmp = cur
      cur = (cur + prev) % MOD
      prev = tmp
    }
    cur
  }

  val res = 2 * (fibonacci(n) + fibonacci(m) - 1) % MOD

  out.println(res)
  out.flush()

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}


import java.util.Scanner

/**
  * Created by aarav on 3/17/18.
  */
object ChoosePlace {

  def main(args: Array[String]) {
    var values:Array[Array[Int]] = new Array[Array[Int]](6)

    for (a <- 0 until 6) {
      values(a) = new Array[Int](8)
    }

    values(0)(0) = 3
    values(0)(1) = 3
    values(0)(2) = 0
    values(0)(3) = 4
    values(0)(4) = 4
    values(0)(5) = 0
    values(0)(6) = 3
    values(0)(7) = 3

    values(1)(0) = 3
    values(1)(1) = 3
    values(1)(2) = 0
    values(1)(3) = 4
    values(1)(4) = 4
    values(1)(5) = 0
    values(1)(6) = 3
    values(1)(7) = 3

    values(2)(0) = 2
    values(2)(1) = 2
    values(2)(2) = 0
    values(2)(3) = 3
    values(2)(4) = 3
    values(2)(5) = 0
    values(2)(6) = 2
    values(2)(7) = 2

    values(3)(0) = 2
    values(3)(1) = 2
    values(3)(2) = 0
    values(3)(3) = 3
    values(3)(4) = 3
    values(3)(5) = 0
    values(3)(6) = 2
    values(3)(7) = 2

    values(4)(0) = 1
    values(4)(1) = 1
    values(4)(2) = 0
    values(4)(3) = 2
    values(4)(4) = 2
    values(4)(5) = 0
    values(4)(6) = 1
    values(4)(7) = 1

    values(5)(0) = 1
    values(5)(1) = 1
    values(5)(2) = 0
    values(5)(3) = 2
    values(5)(4) = 2
    values(5)(5) = 0
    values(5)(6) = 1
    values(5)(7) = 1

    /*for (i <- 0 to 5) {
      for ( j <- 0 to 7) {
        print(" " + values(i)(j));
      }
      println();
    }*/

    var charArr:Array[Array[Char]] = new Array[Array[Char]](6)
    val s:Scanner = new Scanner(System.in);
    for (i <- 0 to 5) {
      charArr(i) = s.next().toCharArray
    }

    /*for (i <- 0 to 5) {
      for ( j <- 0 to 7) {
        print(" " + charArr(i)(j));
      }
      println();
    }*/

    var notChanged = true;
    for (v <- 0 to 3) {
      val lookingfor:Int = 4 - v
      for (i <- 0 to 5) {
        for (j <- 0 to 7) {
          if (notChanged && charArr(i)(j) == '.' && values(i)(j) == lookingfor) {
            charArr(i)(j) = 'P';
            notChanged = false;
          }
        }
      }
    }

    for (i <- 0 to 5) {
      for ( j <- 0 to 7) {
        print(charArr(i)(j));
      }
      println();
    }

  }

}


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

object _602A extends CodeForcesApp {
  override type Result = String

  override def solve(scanner: Scanner) = {
    import scanner._

    def parse(): BigInt = {
      val (n, b) = (nextInt(), nextBigInt())
      Seq.tabulate(n)(i => nextInt() * (b pow (n-i-1))).sum
    }

    val (x, y) = (parse(), parse())
    (x - y).signum match {
      case -1 => "<"
      case 1 => ">"
      case _ => "="
    }
  }
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  final val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val mod: Int = 1000000007
  type Result
  def solve(scanner: Scanner): Result
  def format(result: Result): String = result.toString
  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) //TODO: In Java 8 reader.lines().iterator

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


import scala.io.StdIn._
/**
 * Created by omarsaber on 10/12/16.
 */
object A extends App {
  val Array(a, b, c) = (readLine split " ") map (_.toInt)
  val homes = Seq(a, b, c).sorted
  println((homes(2) - homes(1)) + (homes(1) - homes(0)))
}


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

  val Array(n) = readLongs

  def isPrime(x: Long): Boolean = {
    for (i <- 2 to Math.sqrt(n.toDouble).floor.toInt) {
      if (x % i == 0) return false
    }
    true
  }

  if (isPrime(n)) println(1) else
    if (n % 2 == 0) println(2) else
    if (isPrime(n-2)) println(2) else
    println(3)
}


import scala.io.Source

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

}


object EightPointSets {
  case class Point(x: Int, y: Int)

  def main(args: Array[String]): Unit = {
    val lines = for(i <- 1 to 8) yield(readLine())
    // val lines = List("0 0", "0 1", "0 2", "1 0", "1 2", "2 0", "2 1","2 2")
    // val lines = List("0 0", "2 1", "1 0", "0 2", "2 2", "1 0", "2 1", "0 2")
    val res = if (isRespectable(lines)) {
      "respectable"
    } else "ugly"

    println(res)
  }

  def isRespectable(lines: Seq[String]): Boolean = {
    val points = Set.empty[Point] ++ lines.map(_.split(" ")).map(a => Point(a(0).toInt, a(1).toInt))

    val x = Set.empty[Int] ++ points.map(_.x)
    val y = Set.empty[Int] ++ points.map(_.y)

    if (x.size != 3 || y.size != 3 || points.size != 8) false
    else {
      val sortedX = x.toList.sorted
      val sortedY = y.toList.sorted
      val point2 = Point(sortedX(1), sortedY(1))
      !points.contains(point2)
    }
  }
}


import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val str1 = in.next()
  val str2 = in.next()
  val count = str1.count(_ == '0')
  val count2 = str2.count(_ == '0')
  val sorted = str1.filter(_ != '0').sorted
  if (str1.length != str2.length || (str2.head == '0' && str2.length > 1) || count != count2)
    println("WRONG_ANSWER")
  else if (str1 == str2 && str1 == "0")
    println("OK")
  else {
    val res = sorted.head + "0" * count + sorted.tail
    if (res == str2)
      println("OK")
    else
      println("WRONG_ANSWER")
  }
}


object C {
  def split(x: Array[Int], s: Int) = {
    val it = x.toIterator.buffered
    var cur = 0
    var ans = true
    var count = 0
    while (it.hasNext) {
      if (cur + it.head < s) {
        cur += it.next()
      } else if (cur + it.head == s) {
        cur = 0
        it.next()
        count += 1
      } else {
        ans = false
        it.next()
      }
    }
    ans && cur == 0 && count > 1
  }

  def main(args: Array[String]) = {
    val _ = scala.io.StdIn.readLine().split(" ")
    val x = scala.io.StdIn.readLine().toCharArray.map(_.toString.toInt)
    if (!x.exists(_ > 0)) {
      System.out.println("YES")
    } else if ((1 until 900).exists {sum =>split(x, sum)}) {
      System.out.println("YES")
    } else {
      System.out.println("NO")
    }

  }

}


import scala.io.StdIn._

object B940 {
  def main(args: Array[String]): Unit = {
    var IndexedSeq(n, k, a, b) = for (i <- 0 until 4) yield readLong()
    var res = 0L
    if (k == 1) {
      println((n - 1L) * a)
      return
    }
    while (n != 1) {
      if (n % k == 0) {
        val t = n / k
        if ((n - t) * a < b) {
          res += (n - t) * a
          n = t
        } else {
          res += b
          n /= k
        }
      } else {
        val t = math.max((n / k) * k, 1)
        res += (n - t) * a
        n = t
      }
    }
    println(res)
  }
}


import java.util.Scanner

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

    val line = 40000
    var pos = 0
    var flag = true

    for(k <- 1 to n){
      // norm pos
      pos = pos % line
      if(pos < 0)
        pos = line + pos
      if(pos > line / 2)
        pos = line - pos

      val t = sc.nextInt(); val dir = sc.next()

      if((dir == "East" || dir == "West") && (pos == 0 || pos == line / 2))
        flag = false
      else if(dir == "East" || dir == "West")
        ()
      else{ // dir is north or south
        if(pos == 0){
          if(dir == "North")
            flag = false
          else{
            if(pos + t > line / 2)
              flag = false
            pos += t
          }
        }
        else if(pos == line / 2){
          if(dir == "South")
            flag = false
          else{
            if(pos - t < 0)
              flag = false
            pos -= t
          }
        }
        else{
          if(dir == "North"){
            if(pos - t < 0)
              flag = false
            pos -= t
          }
          else{
            if(pos + t > line / 2)
              flag = false
            pos += t
          }
        }
      }
    }

    // norm pos
    pos = pos % line
    if(pos < 0)
      pos = line + pos
    if(pos > line / 2)
      pos = line - pos

    if(flag){
      if(pos == 0)
        println("YES")
      else
        println("NO")
    }
    else
      println("NO")
  }
}


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

import scala.annotation.tailrec

/**
  * Created by amir.
  */

object A extends App {

  class RW(val inputFile: String, val outputFile: String) {
    private var br = new BufferedReader(new InputStreamReader(System.in))
    private var out = new PrintWriter(new OutputStreamWriter(System.out))

    /* val f = new File(inputFile)
    if (f.exists && f.canRead)
    try {
    br = new BufferedReader(new FileReader(f))
    out = new PrintWriter(new FileWriter(outputFile))
    } catch {
    case e: IOException =>
    e.printStackTrace()
    }*/

    private var st: StringTokenizer = _
    var eof = false

    def nextLine: String = {
      var s = ""
      try
        s = br.readLine()
      catch {
        case e: IOException =>
          e.printStackTrace()
      }
      s
    }

    def next: String = {
      while (st == null || !st.hasMoreTokens)
        try
          st = new StringTokenizer(br.readLine)
        catch {
          case _: IOException =>
            eof = true
            ""
        }
      st.nextToken
    }

    def nextLong: Long = next.toLong

    def nextInt: Int = next.toInt

    def println(): Unit = out.println()

    def println(o: Any): Unit = out.println(o)

    def print(o: Any): Unit = out.print(o)

    def close(): Unit = {
      try {
        br.close()
      } catch {
        case e: IOException =>
          e.printStackTrace()
      }

      out.close()
    }
  }

  override def main(args: Array[String]) {
    val rw = new RW("input.txt", "output.txt")

    @tailrec def sum(x: Int, s: Int): Int = x match {
      case 0 => s
      case _ => sum(x / 10, s + x % 10)
    }

    val r = 7792
    val n = rw.nextInt
    if (n <= r) {
      val ans = for (i <- (1 until 6000000).toStream if sum(i, 0) == 10) yield i
      rw.println(ans(n - 1))
    } else {
      val ans = for (i <- (6000000 to 12000000).toStream if sum(i, 0) == 10) yield i
      rw.println(ans(n - r - 1))
    }
    rw.close()
  }
}


import scala.io.StdIn

object Codeforces1186A extends App {
  val Array(n, m, k) = StdIn.readLine().split("\\s+").map(a => a.toInt)
  println(if (n <= m && n <= k) "Yes" else "No")
}


object _979A 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] + 1
    val ans = if (n%2 == 0) n/2 else if (n == 1) 0 else n
    io.write(ans)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
/***********************************[Scala I/O]*********************************************/
import java.io._, java.util.StringTokenizer
import scala.collection.generic.CanBuild

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

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

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

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

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

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

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

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

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

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


object tanya extends App{
var nums = readLine().split(" ")
val frs = nums(0).toInt
val sc = nums(1).toInt
val th = nums(2).toInt
val fr = nums(3).toInt

if(frs + sc == th + fr){
    println("YES")
}else if(frs + th == sc + fr){
    println("YES")
}else if(frs + fr == th + sc){
    println("YES")
}else if(frs + sc + th == fr){
    println("YES")
}else if(frs + th + fr == sc){
    println("YES")
}else if(frs + sc + fr == th){
    println("YES")
}else if(sc + th + fr == frs){
    println("YES")
}else{
    println("NO")
}
}


object Solution extends App {
  val in = io.Source.stdin.getLines()
  val field = (1 to 4).map { _ => in.next()}

  def isX(column: Int, row: Int) = {
    column >= 0 && column < 4 && row >= 0 && row < 4 && field(column)(row) == 'x'
  }

  def isGood(column: Int, row: Int): Boolean = field(column)(row) match {
    case '.' =>
      (isX(column, row - 1) && isX(column, row - 2)) || // horizontal to left
      (isX(column, row + 1) && isX(column, row + 2)) || // horizontal to right
      (isX(column, row + 1) && isX(column, row - 1)) || // horizontal central
      (isX(column - 1, row) && isX(column - 2, row)) || // vertical to left
      (isX(column + 1, row) && isX(column + 2, row)) || // vertical to right
      (isX(column + 1, row) && isX(column - 1, row)) || // vertical central
      (isX(column + 1, row + 1) && isX(column - 1, row - 1)) || // diagonal central
      (isX(column + 1, row - 1) && isX(column - 1, row + 1)) || // diagonal central
      (isX(column + 1, row + 1) && isX(column + 2, row + 2)) || // diagonal
      (isX(column - 1, row - 1) && isX(column - 2, row - 2)) || // diagonal
      (isX(column - 1, row + 1) && isX(column - 2, row + 2)) || // diagonal
      (isX(column + 1, row - 1) && isX(column + 2, row - 2)) // diagonal

    case _ => false
  }

  val res = (0 until 4).exists {c =>
    (0 until 4).exists {
      r => isGood(c, r)
    }
  }

  if (res)
    println("YES")
  else
    println("NO")

}


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

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

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

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

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

  def main(args: Array[String]): Unit = {
    val Array(a, b, c) = readLongs(3)
    if(c == 0) {
      if(a == b) {
        println("YES")
      } else {
        println("NO")
      }
    } else if((b-a)%c == 0) {
      val n = (b-a)/c +1
      if(n > 0) {
        println("YES")
      } else {
        println("NO")
      }
    } 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 Array(n, m, i, j, a, b) = readInts(6)

  val x1 = i - 1
  val y1 = j - 1
  val x2 = n - i
  val y2 = m - j

  val stepsX1 = if (x1 % a == 0) x1 / a else -1
  val stepsX2 = if (x2 % a == 0) x2 / a else -1
  val stepsY1 = if (y1 % b == 0) y1 / b else -1
  val stepsY2 = if (y2 % b == 0) y2 / b else -1
  val steps11 = if (stepsX1 >= 0 && stepsY1 >= 0 && stepsX1 % 2 == stepsY1 % 2) Math.max(stepsX1, stepsY1) else Int.MaxValue
  val steps12 = if (stepsX1 >= 0 && stepsY2 >= 0 && stepsX1 % 2 == stepsY2 % 2) Math.max(stepsX1, stepsY2) else Int.MaxValue
  val steps21 = if (stepsX2 >= 0 && stepsY1 >= 0 && stepsX2 % 2 == stepsY1 % 2) Math.max(stepsX2, stepsY1) else Int.MaxValue
  val steps22 = if (stepsX2 >= 0 && stepsY2 >= 0 && stepsX2 % 2 == stepsY2 % 2) Math.max(stepsX2, stepsY2) else Int.MaxValue
  val steps = Seq(steps11, steps12, steps21, steps22).min
  if (steps == Int.MaxValue || (steps > 0 && ((i - a < 1 && i + a > n) || (j - b < 1 && j + b > m)))) println("Poor Inna and pony!")
  else println(steps)
}


object CF912B extends App {
  val sc = new java.util.Scanner(System.in)
  val n, k = sc.nextLong

  println(find(n, k))

  def find(n: Long, k: Long): Long = {
    val nn = n.toBinaryString.length
    val tmpmax = Math.pow(2, nn).toLong - 1
    if (k > 1) tmpmax else n
  }
}


import scala.collection.mutable

object Main1 {

  def count(s: String): Int = {
    var acount = 0
    for (ch <- s) {
      if ('a' == ch) {
        acount = acount + 1
      }
    }

    Array(acount * 2 - 1, s.length).min
  }

  def main(args: Array[String]) {

    val stdin = scala.io.StdIn

    val s = stdin.readLine.trim

    println(count(s))
  }
}


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

import scala.collection.mutable

object B {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  /**
   * 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 str = next
    val n = str.length
    val k = nextInt
    var ans = 0
    for {
      i <- 0 until n + k
      j <- 2 to n + k by 2
    } yield {
      if (i + j <= n + k) {
        var ind = i
        while (ind < i + j / 2) {
          if (ind < n && ind + j / 2 < n) {
            if (str(ind) != str(ind + j / 2)) {
              ind = 10000
            }
          }
          ind += 1
        }
        if (ind == i + j / 2) {
          ans = Math.max(ans, j)
        }
      }
    }
    out.println(ans)
    return 0
  }
}


import java.util.Scanner

object div64 extends App {
  val sc = new Scanner(System.in)
  val s = sc.next().toCharArray()
  val can = s.dropWhile(ch => ch == '0').count(ch => ch == '0') >= 6
  println(if (can) "yes" else "no")
}


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

  override def apply(io: IO): io.type = {
    val (n, nums) = io.readAll[Int]
    val ans = (-1000 to 1000).filter(_ != 0).find({d => nums.count(i => i/d > 0) >= (n+1)/2})
    io.write(ans.getOrElse(0))
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
/***********************************[Scala I/O]*********************************************/
import java.io._, java.util.StringTokenizer
import scala.collection.generic.CanBuild

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

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

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

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

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

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

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

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

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

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


import scala.io.StdIn._

object C extends App {
  val n = readInt()
  val P1 = readLine().split(" ").map(_.toInt).drop(1).toList
  val P2 = readLine().split(" ").map(_.toInt).drop(1).toList

  def solve(): Unit = {
    var counter = 0
    var player1 = scala.collection.mutable.ListBuffer(P1:_*)
    var player2 = scala.collection.mutable.ListBuffer(P2:_*)

    while (player1.nonEmpty && player2.nonEmpty) {
      counter += 1

      val c1 = player1.head
      player1 = player1.tail
      val c2 = player2.head
      player2 = player2.tail
      if (c1 > c2) {
        player1 += c2
        player1 += c1
      } else {
        player2 += c1
        player2 += c2
      }

      if (counter > 1000000) {
//       if (player1.diff(P1).isEmpty && player2.diff(P2).isEmpty) {
         println(-1)
         return
       }
    }

    println(counter + " " + (if (player2.isEmpty) 1 else 2))
  }

  solve()
}


/**
 * Created by ashione on 14-6-17.
 */
import java.util.Scanner
object tt {

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

      val sn = new Scanner(System.in)
      val n = sn.nextInt
      val total = sn.nextInt
      var s:List[Int] = List[Int]()
      for (i <- 1 to n) {
        val t:List[Int] = List[Int](sn.nextInt)
        s = s:::t
      }

      println(getBus(s, total, total))
    }
      def getBus(xs:List[Int],space:Int,total:Int):Int = {
        if (xs.isEmpty == true) {
          if (space > 0) 1 else 0
        }
        else {
          (space - xs.head) match {
            case 0 =>1 + { if(xs.tail.isEmpty==true) 0 else getBus (xs.tail, total, total) }
            case x if x > 0 => getBus(xs.tail, x, total)
            case x if x < 0 => 1+getBus(xs, total, total)
          }
        }
      }

 }


import scala.io.StdIn._

object A extends App {
  val Board = Array.ofDim[Int](8, 8)

  for (i <- 0 until 8) {
    val line = readLine().toCharArray
    for (j <- 0 until 8) Board(i)(j) = line(j)
  }

  def getTheClosestPawnPos(col: Int): (Int, Int) = {
    var blackIdx = -1
    var whiteIdx = -1
    for (i <- 0 until 8) {
      if (Board(i)(col) == 'W' && whiteIdx == -1) {
        var hasBlack = false
        for (j <- 0 until i) {
          if (Board(j)(col) == 'B') hasBlack = true
        }
        if (!hasBlack) {
          whiteIdx = i
        }
      } else if (Board(i)(col) == 'B') {
        var hasWhite = false
        for (j <- i + 1 until 8) {
          if (Board(j)(col) == 'W') hasWhite = true
        }
        if (!hasWhite) {
          blackIdx = i
        }
      }
    }

    (whiteIdx, if (blackIdx != -1) 8 - blackIdx - 1 else -1)
  }

  var minWhiteMovesToWin = Integer.MAX_VALUE
  var minBlackMovesToWin = Integer.MAX_VALUE

  for (i <- 0 until 8) {
    val (w, b) = getTheClosestPawnPos(i)
    if (w != -1) minWhiteMovesToWin = Math.min(minWhiteMovesToWin, w)
    if (b != -1) minBlackMovesToWin = Math.min(minBlackMovesToWin, b)

//    println(w + " " + b + " " + minWhiteMovesToWin  + " " + minBlackMovesToWin)
  }

  if (minWhiteMovesToWin <= minBlackMovesToWin) println("A") else println("B")
}


object Main extends App {
  val Array(a,b,c,d) = readLine.split(" ").map(_.toInt)
  def code(time: Int, p: Int): Int = List(3*p/10, p-(p*time/250)).max
  val ac = code(c, a)
  val bd = code(d, b)
  if(ac > bd) println("Misha")
  else if (ac == bd) println("Tie")
  else println("Vasya")
}


/**
  * Created by netman on 3/4/17.
  */
object Main {
  def main(args: Array[String]): Unit = {
    val lines = io.Source.fromInputStream(System.in).getLines().toArray
    val n = lines(0).toInt
    val arr = lines(1).split(" ").map(_.toInt)
    println((arr.max + arr.min) / 2)
  }
}


import scala.io.StdIn

object DiceRolling extends App {

  val t = StdIn.readLine().toInt

  for {
    _ <- 1 to t
  } println(findSol(StdIn.readLine().toInt))

  def findSol(x: Int) = {
    math.ceil(x / 7.0).toInt
  }
}


object duplRemove extends App{
var times = readLine()
var list = readLine().split(" ").toList.reverse

def removeDupl[T](list: List[T]): List[T] = {
    def inner(acc: List[T] = List.empty[T], curList: List[T] = list): List[T] = curList match {
      case Nil => acc
      case x :: xs if acc.contains(x) => inner(acc, xs)
      case x :: xs => inner(acc :+ x, xs)
    }
    inner()
  }

  println(removeDupl(list).length)
  removeDupl(list).reverse.foreach(x => print(x + " "))

}


object Main {
  def main(args: Array[String]) {
    val s = readLine()
    val i = BigInt(s)
    if (i <= Byte.MaxValue) println("byte")
    else if (i <= Short.MaxValue) println("short")
    else if (i <= Int.MaxValue) println("int")
    else if (i <= Long.MaxValue) println("long")
    else println("BigInteger")
  }
}


import scala.io.StdIn.readLine

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


//package codeforce520

object A {
  def main(args: Array[String]): Unit = {
    val reader = scala.io.StdIn

    val n = reader.readInt()
    val a = ("0 " + reader.readLine() + " 1001").split("\\s+").map(_.toInt).toList
    var res = 0
    //println(a.mkString(" "))
    (0 until n).foreach{i =>
      (i + 2 until n + 2).foreach{j =>
        //println(s"i $i j $j ai ${a(i)} aj ${a(j)}")
        //println(a(j) - a(i))
        //println(j - i)
        if (a(j) - a(i) == j - i) {
          res = math.max(res, j - i - 1)
        }
      }
    }

    println(res)
  }
}


import scala.io.StdIn._

object Solution {
  def main(args: Array[String]): Unit = {
    println(readLine.split("A|E|I|O|U|Y", -1).maxBy(_.length).length + 1)
  }
}


import java.util.Scanner

object Soroban extends App {
    val scan = new Scanner(System.in)
    var n = scan.nextInt

    do {
        val k = n % 10
        println(output(k))
        n = n / 10
    } while (n != 0)

    def output(number: Int): String = {
        number match {
            case 0 => "O-|-OOOO"
            case 1 => "O-|O-OOO"
            case 2 => "O-|OO-OO"
            case 3 => "O-|OOO-O"
            case 4 => "O-|OOOO-"
            case 5 => "-O|-OOOO"
            case 6 => "-O|O-OOO"
            case 7 => "-O|OO-OO"
            case 8 => "-O|OOO-O"
            case 9 => "-O|OOOO-"
        }
    }
}


object SpecialTask extends App {

	val in = new java.util.Scanner(System.in);
	val s = in.next();
	val startTime = System.currentTimeMillis()

	val letters = new scala.collection.mutable.HashSet[Char]();
	var numQuestionMarks = 0;
	for (c <- s) {
	  if (c == '?')
	    numQuestionMarks+=1;
	  else if (c.isLetter)
	    letters+=c;
	}

	var combinations = 1;
	val numLetters = letters.size;
	for(i <- 10-(numLetters-1) to 10)
	  combinations*=i;

	if (s(0) == '?') {
	  combinations*=9;
	  numQuestionMarks-=1;
	} else if (s(0).isLetter) {
	  combinations/=10;
	  combinations*=9;
	}

    println(combinations+("0"*numQuestionMarks));
//	println("%d ms".format(System.currentTimeMillis()-startTime));
	in.close();
}


object A741 {

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

  def gcd(x: Long, y: Long): Long = {
    if(x == 0) y else gcd(y % x, x)
  }
  def lcm(x: Long, y: Long): Long = {
    x / gcd(x, y) * y
  }
  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val c = readInts(n).map(_-1)
    var vis = Array.fill(n)(false)
    var res = 1L
    if(c.distinct.length == n) {
      var break = false
      for (i <- 0 until n if !vis(i) && !break) {
        var len = 0L
        var j = i
        while (!vis(j)) {
          vis(j) = true
          j = c(j)
          len += 1
        }
        if (len == 0) {
          break = true
        }
        if (len % 2 == 0) len /= 2
        res = lcm(res, len)
      }
      println(res)
    } else {
      println("-1")
    }
  }

  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.io.StdIn.readLine

object Task3 extends App {
  val n = readLine().split(' ').map(_.toLong).head

  def eating(n: Long, k: Long) = {
    var cur = n
    var had = 0L

    while (cur != 0L) {
      had = had + math.min(cur, k)
      cur = cur - math.min(cur, k)
      cur = cur - cur/10
    }

    2*had >= n
  }

  def sol(n: Long) = {
    var left = 1L
    var right = n
    while ( left != right) {
      val now = (left+right)/2
      if (!eating(n, now)) left = now + 1 else right = now
    }

    left
  }

  println(sol(n))
}


object Solution {
    def main(args: Array[String]) {
        val n_k = readLine().split(' ').map(_.toInt)
        val n = n_k(0)
        val k = n_k(1)
        val tabs = readLine().split(' ').map(_.toInt)

        val totalSum = tabs.sum

        val partialSums = new Array[Int](k)
        tabs.zipWithIndex.foreach {case (tab, index) =>
          partialSums(index % k) -= tab
        }
        val differences = partialSums.map{sum => Math.abs(sum+totalSum)}
        val result = differences.max

       println(result)
    }
}


/**
 *
 * Created by ronaflx on 15-4-3.
 */

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

import scala.Ordering.Implicits._

object Codeforces {
  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)
    }
    st.nextToken
  }

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

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

  def lowerBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (!(array(mid) < value)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  def upperBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (value < array(mid)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  val N = 210001;
  val bit: Array[Int] = new Array[Int](N)

  def addBit(pos: Int, value: Int): Unit = {
    var i = pos
    while (i < N) {
      bit(i) += value
      i += (i & (i ^ (i - 1)))
    }
  }

  def getBit(pos: Int): Int = {
    var (i, res) = (pos, 0)
    while (i > 0) {
      res += bit(i)
      i -= (i & (i ^ (i - 1)))
    }
    return res
  }

  def getRange(from: Int, to: Int): Int = {
    return getBit(to) - getBit(from - 1)
  }

  def solve(): Unit = {
    val k = nextInt
    val s = next
    val charSet = s.toSet
    if (charSet.size >= k) {
      out.println("YES")
      var start = 0
      val find = collection.mutable.Set[Char]()
      object AllDone extends Exception {}
      for (i <- 0 until k - 1) {
        try {
          for (j <- start until s.length) {
            find += s(start)
            if (!find.contains(s(j))) {
              out.println(s.substring(start, j))
              start = j
              find += s(j)
              throw AllDone
            }
          }
        } catch {
          case AllDone =>
        }
      }
      out.println(s.substring(start))
    } else {
      out.println("NO")
    }
  }

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


import math._

object Main extends App {
    val n = readInt
    val a = readLine split " " map (_ toInt) sorted

    println(
        min(
            (2 to n by 2) zip(a) map(t => abs(t._1 - t._2)) sum,
            (1 to n by 2) zip(a) map(t => abs(t._1 - t._2)) sum
        )
    )
}


object A extends App {
  val Array(y, x) = scala.io.StdIn.readLine().split(" ").map(_.toLong)

  if (x == 0) println("No")
  else if (x == 1 && y != 0) println("No")
  else if (x > 1 && (y + 1 < x || (y - x + 1) % 2 != 0)) println("No")
  else println("Yes")
}


import scala.io.StdIn._

object B extends App {

  val t = readInt()

  def lcm(originalA: Int, originalB: Int): Int = {
    var a = originalA
    var b = originalB

    var temp = a
    if (a < b) {
      a = b
      b = temp
    }

    // a > b
    while (b > 0) {
      temp = a
      a = b
      b = temp % b
    }
    val gcd = a
    ((originalA.toLong * originalB) / gcd).toInt
  }

  1 to t foreach { _ =>
    val n = readInt()
    if (n % 2 == 0) {
      println(n / 2 + " " + n / 2)
    } else {
      var answer  = Int.MaxValue
      var answerA = 0
      var answerB = 0

      for {
        k <- 2 to (Math.sqrt(n).toInt + 1)
        a = n / k if n % k == 0
        b = n - a
      } {
        val x = lcm(a, b)
        if (x < answer) {
          answer = x
          answerA = a
          answerB = b
        }
      }

      if (answer == Int.MaxValue || n - 1 <= answer) {
        println(1 + " " + (n - 1))
      } else {
        println(answerA + " " + answerB)
      }
    }
  }

}


import java.util.StringTokenizer

object A extends App {
  val INF = 1 << 30

  var st: StringTokenizer = _
  def read() = { st = new StringTokenizer(readLine()) }
  def int() = st.nextToken().toInt
  def long() = st.nextToken().toLong

  read()
  val n = int()
  val d = int()
  read()
  val a = Array.fill(n)(int()).sorted

  val ans = (0 until n).map { i =>
    val s = a(i)
    val f = s + d
    a.count{c => c >= s && c <= f}
  }.max

  println(n - ans)

}


object D extends App {

  val mod = 1000000007

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

  val fact = Array.ofDim[Long](200001)
  val factInv = Array.ofDim[Long](200001)

  var f = 1L
  for (i <- 0 until fact.size) {
    fact(i) = f.toInt
    factInv(i) = if (f == 1) 1 else BigInt(f).modInverse(mod).toInt
    f = (f * (i + 1)) % mod
  }

  def c(k: Int, n: Int): Long = {
    ((fact(n) * factInv(k) % mod) * factInv(n - k)) % mod
  }

  @scala.annotation.tailrec
  def count(n: Int, m: Int, g: Byte, acc: Long): Long = {
    if (n < 0 || m < 0) acc
    else (n, m, g) match {
      case (0, 0, _) => acc
      case (1, 0, 0) => 1 + acc
      case (1, 0, 1) => acc
      case (0, 1, 0) => acc
      case (1, 1, 0) => 2 + acc
      case (0, 1, 1) => 1 + acc
      case (n, m, 1) => count(n - 1, m, 0, acc)
      case (n, m, 0) => count(n - 2, m, 0, ((if (m > 0) c(n, n + m - 1) else 0) + acc) % mod)
    }
  }

  val Array(n, m, g) = readInts

  println(count(n, m, g.toByte, 0))
}


import scala.io.StdIn

object ProblemA extends App {

  val result = StdIn.readInt() match {
    case 2 => 2
    case _ => 1
  }

  println(result)
}


import scala.io.StdIn

object A extends App {

  val in = StdIn.readLine().split(" ").map(_.toInt)

  val c = in(0)
  val v0 = in(1)
  val v1 = in(2)
  val a = in(3)
  val l = in(4)

  var cp = v0
  var days = 1
  while (cp < c) {
    cp = cp - l + Math.min(v1, v0 + days * a)
    days = days + 1
  }
  println(days)

}


object C extends App {
    val sc = new java.util.Scanner(System.in)
    println(Seq(
        sc.nextInt(),
        sc.nextInt(),
        sc.nextInt() / 2,
        sc.nextInt() / 7,
        sc.nextInt() / 4
    ).min)
    sc.close()
}


import java.util.Scanner
import java.io.PrintWriter
import java.util.Arrays.binarySearch
import scala.annotation.tailrec
import scala.annotation.switch
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 P122B extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def solve(): String = {
    val S = sc.nextLine
    val num4 = S.count(_ == '4')
    val num7 = S.count(_ == '7')
    if (num4 == 0 && num7 == 0) "-1"
    else if (num4 >= num7) "4"
    else "7"
  }

  out.println(solve)
  out.close
}


object CF_526_2_A {
  def solve(n: Int, as: Seq[Int]): Int = {
    import math.abs
    def e(floor: Int, x: Int) = (abs(floor -x) + (floor - 1) + (x - 1)) * 2
    def total(x: Int) = as.zip(1 to n).map{case (p,f) => p * e(f, x)}.sum
    val X = 1 to n minBy total
    total(X)
  }

  // Specify Input and Output formats here:
  def formatIn(i: Input) = (i.int, {i.nextLine; i.intSeq})
  def formatOut(out: Int) = out.toString

//     ~~~ Boilerplate that doesn't change ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

//     ~~~ Utility methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  import java.util.Scanner
  class Input(sc: Scanner) {
    def this(i: java.io.InputStream) = this(new Scanner(i))
    def this(s: String) = this(new Scanner(s.stripMargin))
    def int = sc.nextInt()
    def long = sc.nextLong()
    def double = sc.nextDouble()
    def nextLine = sc.nextLine()
    // If there are prior values, remember to call nextLine to advance past the newline character before collecting the line:
    def collect[T](f: String => T) = {sc.nextLine().split(" ").toVector.map(f)}
    def intSeq() = collect(_.toInt)
    def doubleSeq() = collect(_.toDouble)
    def solveVals = (solve _).tupled(formatIn(this))
    def solveStr = formatOut(solveVals)
  }

  def ceil(a: Int, b: Int) = (a - 1) / b + 1
  def ceil(a: Long, b: Long) = (a - 1) / b + 1

  import language.implicitConversions
  implicit def stringToInput(s: String): Input = new Input(s)
}


import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt
  val mod = (1e9 + 7).toInt
  if (n == 1)
    println(0)
  else {
    var pp = 1l
    var p = 0l
    var f3 = 1l
    val res = (2 to n).foreach { _ =>
      val tmp = p
      p = (pp + f3 * 2) % mod
      f3 = f3 * 3 % mod
      pp = tmp
    }
    println(p)
  }
}


import scala.collection.immutable

/**
 * Created by admin on 10/5/2014.
 */
object B {

  class BB{
    var col:Int = 0
    var row:Int = 0
    var data_row:immutable.IndexedSeq[Char] = null
    var data_col:immutable.IndexedSeq[Char] = null
    var queue:Vector[(Int,Int,Int)] = Vector((0,0,1))
    var board = Array.fill[Int](0,0)(1)

    var fail = false

    def bfs(r:Int,c:Int,step:Int)={
      var notcheck = false
      val arr1 = data_row(r) match {
        case '<' => for ( r2 <- 0 until r
            if (board(r2)(c) == 0 ) ) yield ( (r2,c,step) )
        case '>' => for ( r2 <- (r+1) until col
                          if (board(r2)(c) == 0 ) ) yield ( (r2,c,step) )
      }

      val arr2 = data_col(c) match {
        case '^' => for ( c2 <- 0 until c
                          if (board(r)(c) == 0 ) ) yield ( (r,c2,step) )
        case 'v' => for ( c2 <- (r+1) until row
                          if (board(r)(c) == 0 ) ) yield ( (r,c2,step) )
      }
      arr1 ++ arr2 foreach( x => {board(x._1)(x._2) = step} )
      if ((arr1 ++ arr2).length <1) fail = true
      queue = queue ++ arr1 ++ arr2
    }

    def search(idx:Int): Unit ={
      val head = queue(idx)
      println("Current at ",head)
      bfs(head._1,head._2,head._3+1)
      println(queue.mkString(","))
    }

    def work2() ={
      var result = true
      if (data_row(0) == '<' && data_col(0) == '^') result = false
      if (data_row(0) == '>' && data_col( col-1 ) == '^') result = false
      if (data_row( row-1 ) == '<' && data_col(0) == 'v') result = false
      if (data_row( row-1 ) == '>' && data_col( col-1 ) == 'v') result = false
      if (result)
        println("YES")
      else println("NO")
    }

    def work() ={
      val temp = readLine().split("\\s") map (_.toInt)
      row = temp(0)
      col = temp(1)
      board = Array.fill(row,col)(0)
      data_row = readLine().toList.toIndexedSeq
      data_col = readLine().toList.toIndexedSeq
      //search(0)
      work2()
    }

  }

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

  }
}


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

object _633A extends CodeForcesApp {
  override type Result = Boolean

  override def solve(read: InputReader) = {
    val (a, b, c) = read[(Int, Int, Int)]
    (0 to c/a) exists {i =>
      val j = (c - a*i)/b
      a*i + b*j == c
    }
  }

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

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

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

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

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

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

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

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

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


import java.util.Scanner

object Main extends App {
  def min(x: Long, y: Long) = if (x < y) x else y
  val scanner = new Scanner(System.in)
  val n = scanner.nextInt()
  val x = scanner.nextLong()
  val y = scanner.nextLong()

  val cost = new Array[Long](2 * n + 1)
  cost(0) = 0
  for (i <- 1 to cost.length - 1)
    cost(i) = 0xffffffffffffL
  for (i <- 1 to n) {
    cost(i) = min(cost(i), cost(i-1) + x)
    cost(i) = min(cost(i), cost(i+1) + x)
    cost(2*i) = min(cost(2 * i), cost(i) + y)
  }
  println(cost(n))
}


import scala.io.StdIn

/**
 * Author: Odomontois
 * Date  : 16-Apr-15
 * Time  : 21:17
 */
object Round299D2B extends App {
  val line = StdIn.readLine()
  println(((1 << line.length) - 1) + Integer.parseInt(line.replace('4', '0').replace('7', '1'), 2))
}


import scala.io.StdIn

object ARectangle {

  def main(args: Array[String]) {
    val in = StdIn.readLine().split("\\s+").map(_.toInt)

    val a = Math.abs(in(2) - in(0)) / 2 + 1
    val b = Math.abs(in(3) - in(1)) / 2 + 1
    println(a.toLong * b + (a - 1).toLong * (b - 1))
  }

}


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

/**
 * Created by arseny on 17.07.14.
 */
object A extends App {
  val home = true
  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

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

  def solve() = {
    val a1 = nextInt
    val a2 = nextInt
    val a3 = nextInt
    val b1 = nextInt
    val b2 = nextInt
    val b3 = nextInt
    val n = nextInt
    val a = a1 + a2 + a3
    var n1 = 0
    val b = b1 + b2 + b3
    var n2 = 0
    if (a % 5 == 0) {
      n1 = a / 5
    } else {
      n1 = a / 5 + 1
    }
    if (b % 10 == 0) {
      n2 = b / 10
    } else {
      n2 = b / 10 + 1
    }
    if (n1 + n2 <= n) {
      out.println("YES")
    } else {
      out.println("NO")
    }
  }

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


object A extends App {
  val s = 3
  val b = 7

  def check(x: Int): Boolean =
    if (x < 0) false
    else if (x % 3 == 0) true
    else check(x - 7)

  val n = scala.io.StdIn.readInt()
  (0 until n).foreach(_ => {
    val x = scala.io.StdIn.readInt()
    if (check(x)) println("YES")
    else println("NO")
  })
}


import scala.io.Source

object CodefOne extends App {

  val in = Source.stdin.getLines()
  val data = in.next().split(' ').map(_.toInt)

  private val mapa: Map[Int, Int] = data.groupBy(w => w).mapValues(_.length)

  val maxVals = mapa.filter((t) => t._2 >= 2).map(t => t._1 * (if (t._2 > 3) 3 else t._2))
  if (maxVals isEmpty) {
    println(data.sum)
  } else {
    println(data.sum - maxVals.max)
  }

}


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

/**
 * Created by hama_du on 2014/03/11.
 */
object ProblemD extends App {
  val in = new Scanner(System.in)
  val n = in.nextLong
  val m = in.nextInt

  val cnt0to9 = (0 to 9).map(d => n.toString.toCharArray.filter(c => c == ('0' + d)).length).toArray
  val bit0to9 = cnt0to9.map(b =>  {
    def bc(current: Int, limit: Int): Int = {
      if (current > limit) {
        0
      } else {
        bc(current<<1, limit)+1
      }
    }
    bc(1, b)
  })

  val rng0to9 = bit0to9.scanLeft((0,0))((a, b) => (a._2, a._2+b)).toArray
  val maxBit = rng0to9.last._2

  val maxP = 1<<maxBit
  val dp = Array.ofDim[Long](m,maxP)
  dp(0)(0) = 1L

  val mpMap = (0 to 24).scanLeft(1L)((a, b) => (a * 10)).map(x => (x % m).toInt).toArray
  val cntSum = cnt0to9.sum

  var pi = -1
  while (pi < maxP-1) {
    pi += 1
    val used = decode(pi, rng0to9)
    val usedSum = used.sum
    if (cntSum > usedSum) {
      val factor = mpMap(cntSum-usedSum-1)
      val usedAtLeastOne = (usedSum >= 1)
      var mi = -1
      while (mi < m-1) {
        mi += 1
        if (dp(mi)(pi) >= 1) {
          var num = -1
          while (num < 9) {
            num += 1
            if (used(num) < cnt0to9(num) && (num >= 1 || (num == 0 && usedAtLeastOne))) {
              val pair = rng0to9(num+1)
              val unn = used(num) + 1
              val np = (pi + (unn << pair._1) - (used(num) << pair._1))
              val nm = (mi + num * factor) % m
              dp(nm)(np) += dp(mi)(pi)
            }
          }
        }
      }
    }
  }
  println(dp(0)(encode(cnt0to9, -1, rng0to9)))

  def decode(p: Int, rng0to9: Array[(Int,Int)]): Array[Int] = {
    val ret = new Array[Int](10)
    var d = 0
    while (d <= 9) {
      val pair = rng0to9(d+1)
      val length = pair._2 - pair._1
      ret(d) = (p >> pair._1) & ((1<<length)-1)
      d += 1
    }
    ret
  }

  def encode(used: Array[Int], use: Int, rng0to9: Array[(Int,Int)]): Int = {
    (0 to 9).map(d => {
      val pair = rng0to9(d+1)
      val f = if (d == use) { used(d) + 1 } else { used(d) }
      f << pair._1
    }).foldLeft(0)((a,b) => a | b)
  }
}


import scala.io.StdIn

object FileName extends App {

  val l1 = StdIn.readLine()
  val l2 = StdIn.readLine()

  print(impl(l2))

  def impl(in: String): Int = {
    var toRemove = 0
    var consX = 0

    for (char <- in) {
      char match {
        case 'x' => consX += 1
        case _ =>
          if (consX >= 3) toRemove += (consX - 2)
          consX = 0
      }
    }
    if (consX >= 3) toRemove += (consX - 2)

    toRemove
  }
}


import java.util.Scanner

object T1 extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val s = sc.nextLong
  if (s % n > 0) println(s / n + 1) else println(s / n)
}


object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(r, b) = in.next().split(" ").map(_.toInt)
  val different = Math.min(r, b)
  val left = Math.max(r, b) - different
  println(s"$different ${left/2}")
}


object CF{
	def main(args:Array[String]){
		import scala.io.StdIn.readLine
		val string = readLine().map(_.toInt)

		var cur = 'a'.toInt
		var total = 0
		for(c <- string){
			total += diff(cur, c)
			//println(f"$cur, $c")
			//println(f"$total")
			cur = c
		}

		println(total)
	}

	def diff(a: Int, b:Int): Int = {
		val d = math.abs(a-b)
		return math.min(d, 26-d)
	}
}


import scala.annotation.tailrec

object Table {

  def parse(as: String) = as.split("\\s+").toList.map(_.toLong)

  def solve(n: Long, m: Long, k: Long) = {

    def partition(pivot: Long) = {
      var i: Long = 1
      var sum: Long = 0
      while (i <= n) {
        sum += Math.min((pivot-1)/i, m)
        i += 1
      }
      sum
    }

    @tailrec
    def go(left: Long, right: Long, target: Long): Long = {
      if (left <= right) {
        val mid = left + (right - left) / 2
        val s = partition(mid)
        if (s < k) go(mid+1, right, mid)
        else go(left, mid-1, target)
      } else {
        target
      }
    }

    go(1, n*m, 0)
  }

  def main(args: Array[String]) {
    val List(input) = io.Source.stdin.getLines.take(1).toList
    val List(n, m, k) = parse(input)
    println(solve(n, m, k))
  }
}


import scala.io.StdIn

/**
 * @author chengyi
 */
object MagicBox {

  def canSee(vp:(Int,Int,Int), vt:(Int,Int,Int), asl:String):Int={
    val ap: Array[(Float, Float, Float)] = Array.fill(6)((0,0,0))
    val as = asl.split(" ").map { x => x.toInt }.toList
    ap(0) = (vt._1/2f, 0, vt._3/2f)
    ap(1) = (vt._1/2f, vt._2, vt._3/2f)
    ap(2) = (vt._1/2f, vt._2/2f, 0)
    ap(3) = (vt._1/2f, vt._2/2f, vt._3)
    ap(4) = (0, vt._2/2f, vt._3/2f)
    ap(5) = (vt._1, vt._2/2f, vt._3/2f)
    val api: Array[(Float, Float, Float)] = Array.fill(6)((0,0,0))
    api(0) = (0, -1, 0)
    api(1) = (0, 1, 0)
    api(2) = (0, 0, -1)
    api(3) = (0, 0, 1)
    api(4) = (-1, 0, 0)
    api(5) = (1, 0, 0)
    var sv=0
    (0 to 5).foreach(x=>{
      val v = (vp._1 - ap(x)._1, vp._2 - ap(x)._2, vp._3 - ap(x)._3)
      val dot = api(x)._1 * v._1 + api(x)._2 * v._2 + api(x)._3 * v._3
      if (dot>0){
        sv = sv + as(x)
      }
    })
    sv
  }

  def main(args:Array[String]){
    val view = StdIn.readLine().split(" ").map { x => x.toInt }
    val vp:(Int, Int, Int) = (view(0), view(1), view(2))
    val l = StdIn.readLine().split(" ").map { x => x.toInt }
    val vt:(Int, Int, Int) = (l(0), l(1), l(2))
    val as = StdIn.readLine()
    println(canSee(vp, vt, as))
  }
}


object Main {

  def main(args: Array[String]) {

    val std = scala.io.StdIn
    val values = std.readLine().split(" ").map(_.toInt)
    val values1 = std.readLine().split(" ").map(_.toInt)
    val values2 = std.readLine().split(" ").map(_.toInt)

    var w = values(0)
    var h = values(1)
    val u1 = values1(0)
    val d1 = values1(1)
    val u2 = values2(0)
    val d2 = values2(1)

    while (h > 0) {
      w += h
      if (h == d1) {
        w -= u1
      }
      else if (h == d2) {
        w -= u2
      }
      w = w.max(0)
      h -= 1
    }
    println(w)
  }
}


//package com.umeng.test

/**
 * Created by bright on 5/28/14.
 */
object cf248_1 {
  def main(args:Array[String]){
    val total=readInt()
    val cnt100= readLine().split(" ").filter(x=>x.equals("100")).length
    if(cnt100%2!=0 || cnt100==0&&total%2!=0 )
      println("NO")
    else
      println("YES")
  }

}


import scala.io.StdIn

object Task474A {
	def main(args: Array[String]) {
		val a = "qwertyuiopasdfghjkl;zxcvbnm,./"
		val shift = if (StdIn.readLine().charAt(0) == 'L') 1 else -1
		println(StdIn.readLine().map(c => a.charAt(a.indexOf(c) + shift)))
	}
}


import java.util.Scanner

/**
 * Created by Kuang.Ru on 14-9-28.
 */
object A465 extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  val num = sc.next()
  var i = 0
  var count = 0

  while (i < num.length && num(i) == '1') {
    count += 1
    i += 1
  }

  println(if (count == n) {
    n
  }else {
    count + 1
  })
}


import java.util.Scanner

object Main {

  def sqr(x: Long) = x * x

  def powmod(x: Long, n: Long, p: Long): Long = {
    if (n == 1) x
    else if (n % 2 == 1) (powmod(x, n - 1, p) * x) % p
    else sqr(powmod(x, n / 2, p)) % p
  }

  def C(n: Int, k: Int) = {
    var res = BigInt(1)
    for (i <- n - k + 1 to n) {
      res = res * i
    }
    for (i <- 1 to k.toInt) {
      res = res / i
    }
    res
  }

  def fact(n: Int) = {
    var res = BigInt(1)
    for (i <- 1 to n) {
      res = res * i
    }
    res
  }

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

  def lcm(a: Long, b: Long) = a / gcd(a, b) * b

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

    var l = 1L

    for (i <- 2 to 10) {
      l = lcm(l, i)
    }

    println(in.nextLong() / l)
  }
}


import scala.math._

object NonSquareEquation extends App {
    def upperBound(n : Long) : Long = {
        ceil(sqrt(n)).toLong
    }                                                 //> upperBound: (n: Long)Long

    def magicNumber(n : Long) : Long = {
      (9 * log10(upperBound(n))).toLong
    }

    def lowerBound(n : Long) : Long = {
            val b = magicNumber(n)
            floor(((-b + sqrt(b * b + 4*n))/2)).toLong
    }   //> lowerBound: (n: Long)Long

    def bounds(n : Long) : (Long, Long) = {
        (lowerBound(n), upperBound(n))
    }                                                 //> bounds: (n: Long)(Long, Long)

    def digitFunction(x : Long) : Long = {
        if (x == 0) 0 else x % 10 + digitFunction(x / 10)
    }                                                 //> digitFunction: (x: Long)Long

    def function(n : Long)(x : Long) : Long = {
        x * x + digitFunction(x)*x - n
    }                                                 //> function: (n: Long)(x: Long)Long

    def findRootOnBounds(x : (Long => Long), bounds : (Long, Long)) : Long = {
        if (bounds._1 > bounds._2) -1
        else if (x(bounds._1) == 0L) bounds._1
        else findRootOnBounds(x, (bounds._1 + 1L, bounds._2))
    }                                                 //> findRootOnBounds: (x: Long => Long, bounds: (Long, Long))Long

    def findRoot(n : Long) : Long = {
        findRootOnBounds(function(n), bounds(n))
    }

    for( ln <- io.Source.stdin.getLines ) println(findRoot( ln.toLong ))
}


/**
  * @see http://codeforces.com/contest/909/problem/A
  */

object A extends App {
  def login(n: String, e: Char, l: String = ""): String =
    if (n.isEmpty) l + e
    else if (l.isEmpty) login(n.tail, e, l + n.head)
    else if (n.head < e) login(n.tail, e, l + n.head)
    else login("", e, l)

  val Array(n, s) = scala.io.StdIn.readLine().split(" ")

  println(login(n, s.head))
}


object P8C {
    import io.StdIn._

    def main(args:Array[String]) {
        val s = readLine.split(' ').map{_.toInt}
        val a = Array.fill(readInt){readLine.split(' ').map{_.toInt}}
        def dis(a1:Array[Int], a2:Array[Int]) = {
            val d0 = a1(0) - a2(0)
            val d1 = a1(1) - a2(1)
            d0 * d0 + d1 * d1
        }
        val d = Array.tabulate(a.size, a.size){case (i1, i2) =>
            dis(s, a(i1)) + dis(a(i1), a(i2)) + dis(a(i2), s)
        }
        val c = Array.ofDim[Int](1 << a.size)
        for (i <- 1 until 1 << a.size) {
            var i1 = 0
            while (((i >> i1) & 1) == 0) i1 += 1
            var v = c(i & ~(1 << i1)) + d(i1)(i1)
            var i2 = i1 + 1
            while (i2 < a.size) {
                if (((i >> i2) & 1) != 0) {
                    val v2 = c(i & ~(1 << i1) & ~(1 << i2)) + d(i1)(i2)
                    if (v2 < v) v = v2
                }; i2 += 1
            }; c(i) = v
        }
        println(c((1 << a.size) - 1))
        def visit(i:Int) {
            if (i == 0) return
            var i1 = 0
            while (((i >> i1) & 1) == 0) i1 += 1
            var v = c(i & ~(1 << i1)) + d(i1)(i1)
            var k = i1
            for (i2 <- i1 + 1 until a.size) if (((i >> i2) & 1) != 0) {
                val v2 = c(i & ~(1 << i1) & ~(1 << i2)) + d(i1)(i2)
                if (v2 < v) {v = v2; k = i2}
            }; c(i) = v
            print(' '); print(i1 + 1)
            if (k != i1) {print(' '); print(k + 1)}
            print(" 0")
            visit(i & ~(1 << i1) & ~(1 << k))
        }; print('0'); visit((1 << a.size) - 1); println
    }
}


import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val Array(n, q) = in.next().split(' ').map(_.toInt)
  val transitions = Array.ofDim[Int](6, 6)
  (1 to q).foreach { _ =>
    val Array(from, to) = in.next().split(' ').map(_.head - 'a')
    transitions(to)(from) += 1
  }
  var first = Array(1, 0, 0, 0, 0, 0)
  var i = 1
  while (i != n) {
    val second = Array.ofDim[Int](6)
    (0 until 6).foreach { fromIndex =>
      (0 until 6).foreach { toIndex =>
        second(toIndex) += first(fromIndex) * transitions(fromIndex)(toIndex)
      }
    }
    first = second
    i += 1
  }
  println(first.sum)
}


object Algorithm {
  def main(args: Array[String]): Unit = {
    val nums = List(100, 20, 10, 5, 1)
    var num = scala.io.StdIn.readInt()

    var ans = 0
    for (i <- 0 until 5) {
      if (num >= nums(i)) {
        ans += num / nums(i)
        num %= nums(i)
      }
    }
    println(ans)
  }
}


import java.util.StringTokenizer

import scala.collection.mutable

object A extends App {
  val INF = 1 << 30
  var st: StringTokenizer = _
  def read() = { st = new StringTokenizer(readLine()) }
  def int() = st.nextToken().toInt

  read()
  val n = int()
  val k = int()
  read()
  val a = (1 to n).map(_ => int()).toArray
  val ab = Array.fill(n+1)(mutable.ArrayBuilder.make[Int])
  for {
    i <- 0 until n
  } ab(a(i)) += i
  val pos = ab.map(_.result().iterator)

  val set = new mutable.HashSet[Int]()
  val pq = new mutable.PriorityQueue[(Int, Int)]

  def addToPQ(i : Int, v: Int) = {
    val it = pos(v)
    var q = -1
    while (it.hasNext && q <= i) q = it.next
    if (q == -1 || q <= i) q = INF
    pq += ((q, v))
  }

  var ans = 0
  (0 until n).foreach { i =>
    val v = a(i)
    if (!set.contains(v)) {
      if (set.size == k)
        set.remove(pq.dequeue._2)
      set.add(v)
      ans += 1
    }
    addToPQ(i, v)
  }

  println(ans)
}


object C{
  //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 w=nextInt
    var m=nextInt
    var yes=true
    if(w==2){
      out.println("YES")
    }else{
      while(m!=0){
        val r=m%w
        if(r==0){

        }else if(r==1){
          m-=1
        }else if(r==w-1){
          m+=1
        }else{
          yes=false
        }
        m/=w
      }
      if(yes){
        out.println("YES")
      }else{
        out.println("NO")
      }
    }

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


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

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

  def ans = reader.readLine().map(_.toInt).zip(reader.readLine().map(_.toInt)).map {
    case (a, b) => a ^ b
  }.mkString

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


import scala.collection.mutable.Stack
import scala.collection.mutable.Queue
import java.io.FileInputStream

object Main {

    def main(args: Array[String]): Unit = {
      var s = new java.util.Scanner(System.in)
      val (r, g, b) = (s.nextInt(), s.nextInt(), s.nextInt())
      val l = List(r, g, b)
      var m = List(l.min)
      if (l.min > 1) m = m :+ (l.min-1)
      if (l.min > 2) m = m :+ l.min-2
      println ((m map (y => y + (l map (x => (x- y) / 3) foldLeft 0)(_+_))).max)

    }
}


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

object A {
  def f(arg:Int): Int ={
    var ans=1;
    var x:Int=arg;

    while(x>=10)
      {
        ans+=1;
        x+=1;
        while(x%10==0) x/=10
      }

    return ans+8
  }

  def main(args: Array[String]) = {
    val n=readLine().toInt;
    println(f(n));
  }

}


object HelloWorld {
  def main(args: Array[String]): Unit = {
    val input = scala.io.StdIn.readInt()
    println(beautifuls.map(binaryToDec(_)).takeWhile(_<=input).filter(input%_ == 0).toList.max)
  }

  def beautifuls: Stream[String] = "1" #:: beautifuls.map("1" + _ + "0")

  def binaryToDec: String => Int = x => Integer.parseInt(x, 2)
}


object B 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(p, x, y) = readLongs(3)

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

  def check(s: Long): Boolean = {
    var i = (s / 50) % 475
    var j = 0
    var ok = false
    while (j < 25) {
      i = (i * 96 + 42) % 475
      j += 1
      if (26 + i == p) ok = true
    }
    ok
  }

  var hacks = 0
  var res = -1
  var score = x
  while (res < 0 && score >= y) {
    if (check(score)) res = hacks
    score -= 50
  }

  score = x
  while (res < 0) {
    if (check(score)) res = hacks
    else {
      score += 50
      hacks += 1
      if (check(score)) res = hacks
      score += 50
    }
  }

  println(res)
}


object test6 extends App {
    val Array(a,b,c)=readLine.split(" ").map(_.toInt).sortBy(x=>x)
    val rows=(b+a-1)
    var sum=0
    for(i<-0 until rows/2) if(i<a) sum+=c+i else sum+=c+a-1
    sum*=2
    if(rows%2==1)
    	if(rows/2<a) sum+=rows/2+c else sum+=c+a-1

    println(sum)
}


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(x, y) = readInts
  val s = x.abs + y.abs
  val ans = if(x < 0 && y < 0) Array(-s, 0, 0, -s) else
    if(x < 0 && y > 0) Array(-s, 0, 0, s) else
    if(x > 0 && y < 0) Array(0, -s, s, 0) else
    Array(0, s, s, 0)

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


//package me.jetblack.cf

import java.util.Scanner

object CipherSquare extends App {

  val n = new Scanner(System.in).nextInt()

  val cnt = Array.ofDim[Long](9)

  (1 to n).foreach { i => cnt(i % 9) += 1 }

  val all = (for {
    i <- 0 until 9
    j <- 0 until 9
  } yield {
    cnt(i) * cnt(j) * cnt((i * j) % 9)
  }).sum

  var sum = 0L
  var i = 1
  while (i <= n) {
    var j = 1
    while (j <= n / i) {
      sum += 1
      j += 1
    }
    i += 1
  }

  println(all - sum)

}


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

  val n, p, w, d = nextBig

  val g = w.gcd(d)

  if (p % g == 0) {
    val pp = p / g
    val ww = w / g
    val dd = d / g
    val draw = pp * dd.modInverse(ww) % ww
    val won = (p - draw * d) / w
    val lost = n - won - draw
    if (won >= 0 && draw >= 0 && lost >= 0 && won * w + draw * d == p) out.println(s"$won $draw $lost")
    else out.println(-1)
  } else out.println(-1)
  out.flush()

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}


import java.util.Scanner

/**
 * Created by hama_du on 2014/06/21.
 */
object ProblemA extends App {
  class Card(_color: Int, _number: Int) extends Ordered[Card] {
    val color = _color
    val number = _number
    val colorNumber = color * 10 + number

    def compare(that: Card) = {
      this.colorNumber - that.colorNumber
    }
  }

  class Detecting(_card: Card, colorHint: Int, numberHint: Int) {
    val color = _card.color
    val number = _card.number
    var foundColor = ((1<<color) & colorHint) >= 1
    var foundNumber = ((1<<number) & numberHint) >= 1
  }

  def colorToNum(c: Char): Int = {
    c match {
      case 'R' => 0
      case 'G' => 1
      case 'B' => 2
      case 'Y' => 3
      case 'W' => 4
      case _ => -1
    }
  }

  def doit(initialCards: Array[Card], colorHint: Int, numberHint: Int): Boolean = {
    val cards = initialCards.map(c => {
      new Detecting(c, colorHint, numberHint)
    })

    var upd = true
    while (upd) {
      upd = false

      // color ok
      if (cards.filterNot(c =>  c.foundColor).map(c => c.color).distinct.size == 1) {
        cards.foreach(c => c.foundColor = true)
      }

      // number ok
      if (cards.filterNot(c =>  c.foundNumber).map(c => c.number).distinct.size == 1) {
        cards.foreach(c => c.foundNumber = true)
      }

      // distinct card
      val leftCards = cards.filterNot(c => c.foundColor && c.foundNumber)
      leftCards.foreach(c => {
        val sameCards = leftCards.filter({
          c2 => (c.foundColor && c.color == c2.color) || (c.foundNumber && c.number == c2.number)
        }).map(c2 => (c2.color, c2.number)).distinct
        if (sameCards.size == 1) {
          c.foundColor = true
          c.foundNumber = true
          upd = true
        }
      })
    }
    cards.filter(c => c.foundColor && c.foundNumber).size == cards.size
  }

  def solve(cards: Array[Card]): Int = {
    val list = for {
      i <- 0 until (1<<5)
      j <- 0 until (1<<5)
      if doit(cards, i, j)
    } yield {
      // println(i + "/" + j)
      Integer.bitCount(i) + Integer.bitCount(j)
    }
    list.min
  }

  val in = new Scanner(System.in)
  val n = in.nextInt
  val cards = (0 until n).map(i => {
    val ch = in.next.toCharArray
    new Card(colorToNum((ch(0))), ch(1)-'1')
  }).toArray

  println(solve(cards))
}


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 P371A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  val N, K = sc.nextInt

  val diff = (ls: List[Int]) => {
      ls.count(_ == 1) min ls.count(_ == 2)
    }
  val res = List.fill(N / K, K)(sc.nextInt).transpose.map(diff).sum

  out.println(res)
  out.close
}


object CF_E61_A {
// date: 05/03/2019

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

  def solve(in: In): Out = {
    val (c1, c2, c3, c4) = in
    if(c1 == c4 && (c3 == 0 || c1 > 0)) 1 else 0
  }

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

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

//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   Boilerplate & utility methods that don't change (so ignore):

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

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

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

  // Ceiling division for Int & Long
  // `a` MUST be > 0. Incorrect otherwise.
  def divideCeil(a: Int, b: Int)   = (a - 1)/b + 1
  def divideCeil(a: Long, b: Long) = (a - 1)/b + 1

  // A frequently used number in these comps
  val modulo = 1000000007

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


/**
  * @see http://codeforces.com/contest/911/problem/B
  */

object BTwoCakes extends App {
  val Array(n, a, b) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val l = for (i <- 1 until n) yield (a / i) min (b / (n - i))
  println(l max)
}


import java.util.Scanner

object C635_Scala extends App {
  val sc = new Scanner(System.in)
  val sum = sc.nextLong()
  val xor = sc.nextLong()

  def solve(sum: Long, xor: Long, solutionWithCarry: Long, solutionWithoutCarry: Long): Long = {
    if (sum == 0 && xor == 0) {
      solutionWithoutCarry
    } else (sum % 2, xor % 2) match {
      case (1, 1) => solve(sum / 2, xor / 2, 0, solutionWithoutCarry * 2)
      case (1, 0) => solve(sum / 2, xor / 2, solutionWithCarry, solutionWithCarry)
      case (0, 1) => solve(sum / 2, xor / 2, solutionWithCarry * 2, 0)
      case (0, 0) => solve(sum / 2, xor / 2, solutionWithoutCarry, solutionWithoutCarry)
    }
  }

  def solve2(sum: Long, xor: Long): Long = {
    solve(sum, xor, 0, 1) - (if (sum == xor) 2 else 0)
  }

  println(solve2(sum, xor))
}


object Main {
  def main(args: Array[String]) {
    val n = readInt();
    var primes = Seq(2, 3)
    var count = 0
    for (i <- 4 to n) {
      var divs = Set[Int]()
      for (div <- primes) {
        if (i % div == 0) {
          if (i / div == div) divs += (div)
          else if (primes.find(_ == i / div) != None) divs += (div, i / div)
          else divs += (div)
        }
      }
      if (divs.size == 0) primes ++= Seq(i)
      else if (divs.size == 2) count += 1
    }
    println(count)
  }
}


object A574 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = readInts(n)
    val ini = in(0)
    while(in.max > in(0) || in.count(_ == in.max) != 1) {
      //take 1 from max
      var break = false
      var i = 1
      while(!break && i < n) {
        if(in(i) == in.max) {
          in(i) -= 1
          in(0) += 1
          break = true
        }
        i += 1
      }
    }
    println(in(0) - ini)
  }

  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 problemA {
    import java.io.{BufferedReader, FileInputStream, InputStreamReader}
    import scala.collection.mutable.ArrayBuffer
    import scala.collection.mutable
    import scala.util.control.Breaks._
    import scala.collection.JavaConverters._

    val source = System.in
    implicit val reader = new BufferedReader(new InputStreamReader(source))

    def read()(implicit reader: BufferedReader): String = reader.readLine().split(" ")(0)
    def readArray()(implicit reader: BufferedReader): Array[String] = reader.readLine().split(" ")
    def readString()(implicit reader: BufferedReader): String = reader.readLine()

    def main(args: Array[String]): Unit = {
        val s = readString().toCharArray
        if (s.filter(_ == 'o').size == 0 || s.filter(_ == '-').size % s.filter(_ == 'o').size == 0) print("YES")
        else print("NO")
    }
}


import scala.io.StdIn

/**
  * Created by vladimir on 08.06.17.
  */
object A339 extends App {
  print(StdIn.readLine().split('+').sorted.mkString("+"))
}


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)

  val switches = for(_ <- 1 to 3) yield readInts.map(_ % 2)
  val ans = Array.ofDim[Int](3, 3)
  val dx = Array(0, 1, 0, -1)
  for(r <- 0 until 3) for(c <- 0 until 3) {
    ans(r)(c) ^= switches(r)(c)
    (for(k <- 0 until 4) yield Array(r + dx(k), c + dx(k ^ 1))).filterNot(_.exists(x => x < 0 || x >= 3)).foreach {
      case Array(rr, cc) => ans(rr)(cc) ^= switches(r)(c)
    }
  }

  def main(a: Array[String]) {
    println(ans.map(_.map(1 -).mkString).mkString("\n"))
  }
}


object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, fine) = in.next().split(" ").map(_.toInt)
  val data = in.next().split(" ").map(_.toInt).sorted
  val m = in.next().toInt

  println(data.take(m).sum - fine * Math.max(m - n, 0))

}


import scala.collection.mutable
import util.control.Breaks._

object Main {
  def main(args: Array[String]): Unit = {
    val line = readLine().split(" ").map(_.toInt)
    val n = line(0)
    val k = line(1)

    val dist = Math.min(Math.abs(k-1), Math.abs(n-k))
    println(n * 3 + dist)
  }
}


import scala.io.StdIn._

object Main extends App {
  val Array(n, k) = readLine().split(" ").map(_.toInt)
  val minutes = 4 * 60 - k
  val gen = Stream.from(1).map(_ * 5)
  val ans = gen.scanLeft(0)(_ + _).takeWhile(_ <= minutes).length
  println(math.min(ans - 1, n))
}


import java.util.Scanner

import scala.io.StdIn._

/**
  * Created by roman on 21.03.2016.
  */
object Task1 {
  def main(args: Array[String]) {
    val sc = new Scanner(System.in)

    val n = sc.nextInt()
    val a = sc.nextInt()

    println(if (a%2==0) (n-a)/2+1 else (a+1)/2)
  }
}


import scala.collection.mutable.MutableList

object GameWithSticks {
	def main (args: Array[String]) {
		val scanner = new java.util.Scanner(System.in);
		var width = scanner.nextInt();
		var height = scanner.nextInt();
		val min = Math.min(width, height)
		if (min % 2 == 1) {
			println("Akshat")
		}
		else {
			println("Malvika")
		}
	}
}


/**
  * Created by MacDrive on 22.09.2017.
  */
object ProblemA extends App{
  val input = scala.io.StdIn.readLine()

  val noZero  = input.reverse.dropWhile(x => x == '0')

  val split = noZero.splitAt(noZero.length/2)

  val ready = if (split._1.length != split._2.length) (split._1, split._2.tail) else split

  if (ready._1 == ready._2.reverse) print("YES") else print("NO")

}


object A353 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = Array.fill(n)(readInts(2))
    if(in.map(_.sum).sum%2 == 0) {
      val first = in.map(_(0)).sum % 2
      val second = in.map(_(1)).sum % 2
      if(first == 0 && second == 0) {
        println("0")
      } else {
        val index = in.exists{ arr =>
          if(arr(0)%2 == 0)
            arr(1)%2 == 1
          else
            arr(1)%2 == 0
        }

        if(index) {
          println("1")
        } else {
          println("-1")
        }
      }
    } else {
      println("-1")
    }
  }

  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.io.StdIn._

object Codeforces extends App {
  val Array(n, m) = readLine split ' ' map(_.toInt)
  val first = readLine split ' ' map(_.toInt) toSet
  val second = readLine split ' ' map(_.toInt) toSet

  val Array(minFirst, minSecond) = Array(first min, second min) sorted
  val minIntersect = first intersect second match {
    case s if s nonEmpty => s.min
    case _ => Int.MaxValue
  }

  if (minIntersect < 10)
    println(minIntersect)
  else
    println(s"$minFirst$minSecond")
}


// cf 171A not done

object MysteryNumbers extends App {
  val ln = (Console.readLine()).split(" ") map (_.toInt)
  val a = ln(0)
  val b = ln(1)

  def invert(n:Int, acc:Int):Int = n match {
    case 0 => acc
    case _ => invert(n/10, acc*10 + (n%10))
  }

  val bb = invert(b,0)
  println(a + bb)
}