{"source_code": "import scala.Predef._\n\nobject Main {\n  def main(args: Array[String]) {\n    val a = readLine().split(\" \").map(_.toInt)\n    val t = a(1)\n    val raw = readLine()\n    var s = raw.toCharArray\n    for (_ <- 1 to t) {\n      var bi = -1\n      for (i <- 0 until s.size) {\n        if (bi == -1) {\n          if (s(i) == 'B') {\n            bi = i\n          }\n        } else {\n          if (s(i) == 'G') {\n            s(i) = 'B'\n            s(bi) = 'G'\n            bi = -1\n          } else {\n            bi = i\n          }\n        }\n      } \n    }\n    println(s.mkString(\"\"))\n  }\n}", "src_uid": "964ed316c6e6715120039b0219cc653a"}
{"source_code": "import scala.io.StdIn.readLine\n\nobject Puzzles {\n  def main(args: Array[String]): Unit = {\n    val Array(n, m) = readLine().split(\" \").map(_.toInt)\n    val nums = readLine().split(\" \").map(_.toInt).sorted\n    val ans = nums.sliding(n).map(x => x.last - x.head).min\n    println(ans)\n  }\n}", "src_uid": "7830aabb0663e645d54004063746e47f"}
{"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P246A extends App {\n  val sc = new Scanner(System.in)\n  val out = new PrintWriter(System.out)\n\n  val N = sc.nextInt\n  val answer: String = {\n    if (N <= 2) \"-1\"\n    else List.range(1, N + 1).reverse.mkString(\" \")\n  }\n\n  out.println(answer)\n  out.close\n}\n", "src_uid": "fe8a0332119bd182a0a5b7758716317e"}
{"source_code": "import java.io._\nimport java.util.StringTokenizer\n\nimport scala.annotation.tailrec\n\nobject A {\n  def solve(in: Input, out: Output): Unit = {\n    val n, m = in.nextInt()\n    out.println(if (n < 31) m & ((1 << n) - 1) else m)\n  }\n\n  class Input(in: InputStream) extends Closeable {\n    private[this] val br = new BufferedReader(new InputStreamReader(in))\n    private[this] var st = new StringTokenizer(br.readLine())\n\n    override def close(): Unit = br.close()\n\n    @tailrec\n    final def next(): String = if (st.hasMoreTokens) st.nextToken() else {\n      st = new StringTokenizer(br.readLine())\n      next()\n    }\n\n    final def nextInt(): Int = next().toInt\n    final def nextLong(): Long = next().toLong\n    final def nextDouble(): Double = next().toDouble\n  }\n\n  final type Output = PrintWriter\n\n  def main(args: Array[String]): Unit = {\n    val in = new Input(System.in)\n    val out = new Output(System.out)\n    solve(in, out)\n    out.close()\n    in.close()\n  }\n}\n", "src_uid": "c649052b549126e600691931b512022f"}
{"source_code": "object test5 extends App {\n    val mod=1073741824\n    var sum=0\n    val map=collection.mutable.Map[Int,Int]()\n    map(1)=1\n    val Array(a,b,c)=readLine.split(\" \").map(_.toInt)\n    \n    val list=for(i<-1 to a; j<-1 to b; k<-1 to c) yield\n    {\n        getNum(i*j*k)\n    }:Long\n\n    println(list.sum%mod)\n    \n    def getNum(num:Int)={\n        def count()={\n            var total=2\n            for(i<-2 to math.sqrt(num).toInt) \n            \t if(num%i==0)\n            \t     if(i*i==num) total+=1 else total+=2\n            \n            map(num)=total\n            total\n        }\n                 \n        map.get(num) match{\n            case None=>count()\n            case _=>map(num)\n        }\n    }\n}   \n", "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401"}
{"source_code": "import scala.io.StdIn\n\nobject Cookies {\n  \n  var result:Array[Int] = null\n  \n  def cookNum(n:Int):Int={\n    if (n==0)\n      return 1\n    result = Array.fill(n)(1)\n    for (a<-1 to n-1){\n      result(a) = result(a-1)*3 % (1000003)\n    }\n    result(n-1)\n  }\n  \n  def main(args:Array[String])={\n    val n = StdIn.readLine().toInt\n    println(cookNum(n))\n  }\n\n}", "src_uid": "1a335a9638523ca0315282a67e18eec7"}
{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n  val in = Source.stdin.getLines()\n  val Array(a, b) = in.next().split(' ').map(_.toLong)\n  if (a == b)\n    println(\"infinity\")\n  else if (b > a)\n    println(0)\n  else {\n    val ab = a - b\n    println((1 to Math.sqrt(ab).toInt).foldLeft(0){\n      case(acc, j) =>\n        if (ab % j == 0 && a % (ab / j) == b) {\n          if (ab / j != j && a % j == b)\n            acc + 2\n          else\n            acc + 1\n        }\n        else acc\n    })\n  }\n}", "src_uid": "6e0715f9239787e085b294139abb2475"}
{"source_code": "object Main {\n  def main(args: Array[String]): Unit = {\n    val s = new Main()\n    s.solve()\n    s.out.flush()\n  }\n}\n\nclass Main {\n  import java.io._\n  import java.util.StringTokenizer\n\n  import scala.collection.mutable\n  import scala.util.Sorting\n  import math.{abs, max, min}\n  import mutable.{ArrayBuffer, ListBuffer}\n  import scala.reflect.ClassTag\n\n  val MOD = 1000000007\n  val out = new PrintWriter(System.out)\n\n  def solve(): Unit = {\n    val N, B = nl()\n    val F = factorize(B)\n    val C = mutable.HashMap[Long, Long]().withDefaultValue(0)\n    F.keys.foreach { f =>\n      var c = 0L\n      var d = f\n      while(d <= N) {\n        c += N / d\n        if (d <= (N - 1) / f + 1) d *= f\n        else d = N + 1\n      }\n//      debug(s\"$f $c\")\n      C(f) = c\n    }\n\n//    C.foreach { case (k, v) => debug(s\"$k $v\") }\n    val ans = F.map { case (f, cnt) =>\n//      debug(s\"$f $cnt\")\n      C(f) / cnt\n    }.min\n\n    out.println(ans)\n  }\n\n  /**\n    * *\u6ce8\u610f* 10^12\u4ee5\u4e0a\u3050\u3089\u3044\u304b\u3089\u306f\u4f7f\u308f\u306a\u3044\u3053\u3068\n    */\n  def factorize(n: Long): mutable.Map[Long, Long] = {\n    import scala.collection.mutable\n    val res = mutable.Map[Long, Long]() withDefaultValue 0\n\n    def minFactor(n0: Long, rt: Int, i: Int): Long = {\n      if (i > rt) n0 // \u221an \u307e\u3067\u898b\u3064\u304b\u3089\u306a\u304b\u3063\u305f\u3089 n0\u306f\u7d20\u6570\u304b1\n      else if (n0 % i == 0) i\n      else minFactor(n0, rt, i + 1)\n    }\n\n    def step(n0: Long): Unit = {\n      minFactor(n0, math.sqrt(n0).toInt, 2) match {\n        case 1 =>\n        case f =>\n          res(f) = res(f) + 1\n          step(n0 / f)\n      }\n    }\n\n    step(n)\n    res\n  }\n\n  def debug(as: Array[Boolean]): Unit = {\n    System.err.println(as.map(x => if(x) \"1\" else \"0\").mkString)\n  }\n\n  def debug(as: Array[Int]): Unit = {\n    System.err.println(as.mkString(\" \"))\n  }\n\n  def debug(as: Array[Long]): Unit = {\n    System.err.println(as.mkString(\" \"))\n  }\n\n  def debug(s: String): Unit = {\n    System.err.println(s)\n  }\n\n  def debug(num: Long): Unit = {\n    System.err.println(num)\n  }\n\n  class InputReader(val stream: InputStream) {\n    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n    private var tokenizer: StringTokenizer = _\n\n    def next(): String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new StringTokenizer(reader.readLine)\n      tokenizer.nextToken\n    }\n\n    def nextInt(): Int = next().toInt\n    def nextLong(): Long = next().toLong\n    def nextChar(): Char = next().charAt(0)\n  }\n  val sc = new InputReader(System.in)\n  def ni(): Int = sc.nextInt()\n  def nl(): Long = sc.nextLong()\n  def nc(): Char = sc.nextChar()\n  def ns(): String = sc.next()\n  def ns(n: Int): Array[Char] = ns().toCharArray\n  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)\n  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {\n    val A1, A2 = Array.ofDim[Int](n)\n    REP(n) { i =>\n      A1(i) = ni() + offset\n      A2(i) = ni() + offset\n    }\n    (A1, A2)\n  }\n  def nm(n: Int, m: Int): Array[Array[Int]] = {\n    val A = Array.ofDim[Int](n, m)\n    REP(n) { i =>\n      REP(m) { j =>\n        A(i)(j) = ni()\n      }\n    }\n    A\n  }\n  def nal(n: Int): Array[Long] = map(n)(_ => nl())\n  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))\n  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = offset\n    val N = n + offset\n    while(i < N) { f(i); i += 1 }\n  }\n  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = n - 1 + offset\n    while(i >= offset) { f(i); i -= 1 }\n  }\n\n  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {\n    val res = Array.ofDim[A](n)\n    REP(n)(i => res(i) = f(i + offset))\n    res\n  }\n\n\n  def sumL(as: Array[Int]): Long = {\n    var s = 0L\n    REP(as.length)(i => s += as(i))\n    s\n  }\n\n  def cumSum(as: Array[Int]) = {\n    val cum = Array.ofDim[Long](as.length + 1)\n    REP(as.length) { i =>\n      cum(i + 1) = cum(i) + as(i)\n    }\n    cum\n  }\n}\n", "src_uid": "491748694c1a53771be69c212a5e0e25"}
{"source_code": "import java.util\nimport scala.collection.JavaConverters._\n\n\nobject CF518_2_B {\n  def solve(b: Long): Long = {\n    val pfs = Utility.primeFactors(b)\n//    println(\"b = \"+b)\n//    println(pfs.asScala.toList)\n    val ns = pfs.asScala.groupBy(identity).mapValues(_.size).values\n    ns.map(_+1).product\n  }\n  \n  def main(args: Array[String]) = {\n    val io = new IO(System.in)\n//    val io = new IO(\"7169516929\")\n    val solution = solve(io.long())\n    println(solution)\n  }\n\n\n\n\n\n/// boilerplate utility methods: ///\n    import java.util.Scanner\n    class IO(sc: Scanner) {\n      def this(i: java.io.InputStream) = this(new Scanner(i))\n      def this(s: String) = this(new Scanner(s))\n      def nextLine = sc.nextLine() // do this if still on previous line before collecting line of data\n      def collect[T](f: String => T) = {sc.nextLine().split(\" \").toVector.map(f)}\n      def intSeq() = collect(_.toInt)\n      def doubleSeq() = collect(_.toDouble)\n      def int() = sc.nextInt()\n      def long() = sc.nextLong()\n      def double() = sc.nextDouble()\n    }\n\n    object Utility {\n      def intCeil(a: Int, b: Int) = (a - 1) / b + 1\n      def longCeil(a: Long, b: Long) = (a - 1) / b + 1\n      // Euclid's algorithm\n      def gcd(a: Long, b: Long): Long = b match {\n        case 0 => a\n        case _ => gcd(b, a % b)\n      }\n      // lcm(a,b) = abs(a*b)/gcd(a,b)\n      def lcm(a: Long, b: Long) = math.abs(a)/gcd(a,b)*math.abs(b)\n\n      // These were written in Java then auto-converted by IntelliJ to Scala... so ugly!\n      def primesFromSieve(upto: Int): util.BitSet = { // true means it's a prime\n        val bs: util.BitSet = new util.BitSet(upto + 1)\n        // even numbers aren't prime, so we initialize intelligently. Takes ~ 15% of total method run time for 1e8\n        // (future optimization if required: try initializing as longs with value 0x01010101010101...)\n        bs.set(2)\n        locally {var i: Int = 3\n        while ( {\n          i <= upto\n        }) {\n          bs.set(i)\n          i += 2\n        }}\n        // end of initialization.\n        val max: Int = Math.sqrt(upto).toInt\n        // nextSetBit returns -1 if none exists so we have to check that i is still > 0\n        locally { var i: Int = 3\n        while ( {\n          i <= max && i > 0\n        }) {\n          var j: Int = i * 2\n          while ( {\n            j < upto\n          }) {\n            bs.clear(j)\n\n            j += i\n          }\n\n          i = bs.nextSetBit(i + 2)\n        }}\n        bs\n      }\n\n      def primeFactors(x: Long): util.ArrayList[Long] = {\n        val factors = new util.ArrayList[Long]\n        if (x < 2) return factors\n        val maxPrimeFactor = Math.sqrt(x).toInt\n        val allPrimes = primesFromSieve(maxPrimeFactor)\n        var remaining = x\n        var trial = 2L\n        while ( {\n          trial * trial <= remaining && trial > -1\n        }) if (remaining % trial == 0) { // trial is prime factor of x\n          factors.add(trial)\n          remaining = remaining / trial\n        }\n        else trial = allPrimes.nextSetBit(trial.toInt + 1)\n        factors.add(remaining)\n        factors\n      }\n\n    }\n}", "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1"}
{"source_code": "import annotation.tailrec, collection.mutable, util.control.Breaks._, math.Ordering.Implicits._\nimport CodeForcesApp._\nobject _560C extends CodeForcesApp[Int]({scanner => import scanner._\n  val Seq(a1, a2, a3, a4, a5, a6) = Seq.fill(6)(nextInt)\n  val t1 = a1 + a2 + a3\n  val t2 = a3 + a4 + a5\n  val t3 = a5 + a6 + a1\n  require(t1 == t2 && t2 == t3)\n  t1*t1 - a1*a1 - a3*a3 - a5*a5\n})\nimport java.util.Scanner\nabstract class CodeForcesApp[A](solver: Scanner => A) {\n  final def apply(problem: String): String = apply(new Scanner(problem))\n  final def apply(scanner: Scanner): String = format(solver(scanner))\n  def format(result: A): String = result.toString\n  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))\n}\nobject CodeForcesApp {\n  final def isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)\n  final val modulus: Int = 1000000007\n  final val eps: Double = 1e-9\n  final def when[B](x: Boolean)(f: => B): Option[B] = if (x) Some(f) else None\n  final def counter[A] = collection.mutable.Map.empty[A, Int] withDefaultValue 0\n  final def yesNo(result: Boolean) = if (result) \"YES\" else \"NO\"\n}\n", "src_uid": "382475475427f0e76c6b4ac6e7a02e21"}
{"source_code": "\nobject Codeforces158A extends App {\n\n  import io.StdIn._\n\n  val Array(n, k) = readLine().split(\" \").map(_.toInt)\n  val nn = readLine().split(\" \").map(_.toInt)\n\n  val limit = nn(k - 1)\n\n  val count = nn.fold(0) { (count, i) => if (i >= limit && i > 0) count + 1 else count}\n  println(count)\n\n}\n", "src_uid": "193ec1226ffe07522caf63e84a7d007f"}
{"source_code": "import java.util.Scanner\n\nobject Solution {\n  def main(args: Array[String]) : Unit =  {\n    solve()\n  }\n  def solve() = {\n    val sc = new Scanner(System.in)\n    val (x1 , y1 , x2 , y2 , a , b) = (sc.nextInt() , sc.nextInt() , sc.nextInt(), sc.nextInt() , sc.nextInt() , sc.nextInt())\n\n    val result =\n      if (Math.abs(x2 - x1) % a != 0 | Math.abs(y2 - y1) % b != 0) {\n        false\n      } else {\n        (Math.abs(x2 - x1)/a)%2 == (Math.abs(y2 - y1)/b)%2\n      }\n    print(if(result)\"YES\" else \"NO\")\n  }\n}", "src_uid": "1c80040104e06c9f24abfcfe654a851f"}
{"source_code": "import java.util.Scanner\n\nobject Main {\n  case class Point(var x: Int, y: Int)\n\n  val in = new Scanner(System.in)\n\n  def main(args: Array[String]): Unit = {\n    val n = in.nextInt()\n    if (n <= 2) {\n      print(0)\n      return\n    }\n    print(n/2 + n%2 - 1)\n  }\n}", "src_uid": "dfe9446431325c73e88b58ba204d0e47"}
{"source_code": "object B extends App {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n\n  val Array(n, t) = readInts(2)\n  val as = readInts(n)\n  val cnts = Array.fill(as.max + 1) { 0L }\n  for (a <- as) cnts(a) += 1\n\n  val l = n * t min 2 * n * n\n\n  val minByLen = Array.fill(l) { 0 }\n\n  var i, len = 0\n\n  while (i < l) {\n\n    var lo = 0\n    var hi = len - 1\n    val a = as(i % n)\n\n    while (lo <= hi) {\n      val mid = (lo + hi) >> 1\n      if (as(minByLen(mid) % n) <= a) lo = mid + 1\n      else hi = mid - 1\n    }\n\n    minByLen(lo) = i\n    if (lo == len) len += 1\n\n    i += 1\n  }\n\n  val res = len + (if (2 * n < t) (t - 2 * n) * cnts.max else 0)\n\n  println(res)\n}\n", "src_uid": "26cf484fa4cb3dc2ab09adce7a3fc9b2"}
{"source_code": "import scala.io.StdIn\n\nobject Task479A {\n\tdef main(args: Array[String]) {\n\t\tprintln(max(Array(StdIn.readInt(), StdIn.readInt(), StdIn.readInt())))\n\t}\n\n\tdef max(nums: Array[Int]) = nums.count(_ == 1) match {\n\t\tcase 0 => var m = 1; nums.foreach(m *= _); m\n\t\tcase (1 | 2) => nums indexOf 1 match {\n\t\t\tcase 0 => if (nums(2) == 1) nums.sum else (1 + nums(1)) * nums(2)\n\t\t\tcase 2 => nums(0) * (nums(1) + 1)\n\t\t\tcase 1 => if (nums(0) <= nums(2)) (nums(0) + 1) * nums(2) else nums(0) * (1 + nums(2))\n\t\t}\n\t\tcase _ => nums.sum\n\t}\n}", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27"}
{"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P265A extends App {\n  val sc = new Scanner(System.in)\n  val out = new PrintWriter(System.out)\n\n  val S = sc.nextLine.toCharArray\n  val T = sc.nextLine.toCharArray.toList\n\n  val answer: Int = {\n    @tailrec\n    def loop(i: Int, ts: List[Char]): Int = ts match {\n        case Nil => i\n        case x :: xs => {\n          if (x == S(i)) loop(i + 1, xs)\n          else loop(i, xs)\n        }\n      }\n    loop(0, T) + 1\n  }\n\n  out.println(answer)\n  out.close\n}\n", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252"}
{"source_code": "object scala{\r\n    def main(args: Array[String]): Unit ={\r\n        val a = readLine.toInt\r\n        (0 until a).foreach{\r\n            _ =>\r\n            val N = readLine.toInt\r\n            val res = Math.sqrt(N).toInt +\r\n              Math.cbrt(N).toInt -\r\n             (Math.sqrt(Math.cbrt(N))).toInt\r\n             println(res)\r\n        }\r\n    }\r\n}", "src_uid": "015afbefe1514a0e18fcb9286c7b6624"}
{"source_code": "object Solution extends App {\n  val in = scala.io.Source.stdin.getLines()\n  val Array(r, c) = in.next().split(\" \").map(_.toInt)\n  val rows = Array.ofDim[Boolean](r)\n  val columns = Array.ofDim[Boolean](c)\n  Range(0, r).foreach { i =>\n    val str = in.next()\n    Range(0, str.length).foreach { j =>\n      if (str.charAt(j) == 'S') {\n        rows(i) = true\n        columns(j) = true\n      }\n    }\n  }\n\n  val rc = rows.count(!_)\n  val cc = columns.count(!_)\n  println(rc * c + cc * (r - rc) )\n}\n", "src_uid": "ebaf7d89c623d006a6f1ffd025892102"}
{"source_code": "/**\n  * Created by octavian on 28/02/2016.\n  */\nobject Orchestra {\n\n  def main(args: Array[String]) = {\n\n    //System.setIn(new FileInputStream(\"./src/orchestra.in\"))\n    //System.setOut(new PrintStream(new FileOutputStream(\"./src/orchestra.out\")))\n\n    val Array(r, c, n, k) = readLine().split(\" \").map(_.toInt)\n    var grid: Array[Array[Int]] = Array.ofDim[Int](r, c)\n\n    for(i <- 0 until r) {\n      for(j <- 0 until c) {\n        grid(i)(j) = 0\n      }\n    }\n\n    for(i <- 0 until n) {\n      val Array(x, y): Array[Int] = readLine().split(\" \").map(_.toInt)\n      grid(x - 1)(y - 1) = 1\n      //println(\"grid is: \" + grid(x - 1)(y - 1))\n    }\n\n    var res = 0\n    for(lb <- 0 until r) {\n      for(le <- lb until r) {\n        for(rb <- 0 until c) {\n          for(re <- 0 until c) {\n            if(matches(grid, lb, le, rb, re, k)) {\n              res += 1\n            }\n          }\n        }\n      }\n    }\n    println(res)\n  }\n\n  def matches(grid: Array[Array[Int]], lb: Int, le: Int, rb: Int, re: Int, k: Int): Boolean = {\n    //println(\"testing: \" + lb + \", \" + le + \", \" + rb + \", \" + re)\n    var count = 0\n    for(i <- lb to le) {\n      for(j <- rb to re) {\n        if(grid(i)(j) == 1) {\n          count += 1\n        }\n      }\n    }\n    return count >= k\n  }\n\n}\n", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4"}
{"source_code": "object Main {\n  def main(args: Array[String]) {\n    val s = readLine()\n    val danger = s.sliding(7).foldLeft(false) { (acc, s) => \n      if (s == \"1111111\" || s == \"0000000\") true\n      else acc\n    }\n    if (danger) println(\"YES\")\n    else println(\"NO\")\n  }\n}", "src_uid": "ed9a763362abc6ed40356731f1036b38"}
{"source_code": "object A761 {\n\n  import IO._\n  import collection.{mutable => cu}\n\n  def main(args: Array[String]): Unit = {\n    val Array(a,b) = readInts(2)\n    if(a == 0 && b == 0)\n      println(\"NO\")\n    else if(a == b || a+1 == b || b+1 == a)\n      println(\"YES\")\n    else\n      println(\"NO\")\n  }\n\n  object IO {\n    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n\n    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(\"src/input\")))\n    @inline def read: String = input.readLine()\n\n    @inline def tokenizeLine = new java.util.StringTokenizer(read)\n\n    def readInt: Int = tokenizeLine.nextToken.toInt\n\n    def readInts(n: Int): Array[Int] = {\n      val tl = tokenizeLine\n      Array.fill(n)(tl.nextToken.toInt)\n    }\n\n    def readLongs(n: Int): Array[Long] = {\n      val tl = tokenizeLine\n      Array.fill(n)(tl.nextToken.toLong)\n    }\n\n    def readBigs(n: Int): Array[BigInt] = {\n      val tl = tokenizeLine\n      Array.fill(n)(BigInt(tl.nextToken))\n    }\n  }\n\n}\n", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037"}
{"source_code": "object Main {\n  import java.io.{BufferedReader, InputStream, InputStreamReader}\n  import java.util.StringTokenizer\n  import scala.reflect.ClassTag\n\n  def main(args: Array[String]): Unit = {\n    val out = new java.io.PrintWriter(System.out)\n    new Main(out, new InputReader(System.in)).solve()\n    out.flush()\n  }\n\n  private val oj = System.getenv(\"ATCODER_DEBUG\") == null\n  def DEBUG(f: => Unit): Unit = {\n    if (!oj){ f }\n  }\n  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) \"1\" else \"0\").mkString) }\n  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(\" \")) }\n  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(\" \")) }\n  def debugDim(m: Array[Array[Int]]): Unit = if (!oj){\n    REP(m.length) { i =>\n      debug(m(i))\n    }\n  }\n  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){\n    REP(m(0).length) { j =>\n      REP(m.length) { i =>\n        System.err.print(m(i)(j))\n        System.err.print(\" \")\n      }\n      System.err.println()\n    }\n  }\n  def debug(s: => String): Unit = DEBUG {\n    System.err.println(s)\n  }\n  def debugL(num: => Long): Unit = DEBUG {\n    System.err.println(num)\n  }\n\n  class InputReader(val stream: InputStream) {\n    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n    private var tokenizer: StringTokenizer = _\n\n    def next(): String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new StringTokenizer(reader.readLine)\n      tokenizer.nextToken\n    }\n\n    def nextInt(): Int = Integer.parseInt(next())\n    def nextLong(): Long = java.lang.Long.parseLong(next())\n    def nextChar(): Char = next().charAt(0)\n\n    def ni(): Int = nextInt()\n    def nl(): Long = nextLong()\n    def nc(): Char = nextChar()\n    def ns(): String = next()\n    def ns(n: Int): Array[Char] = ns().toCharArray\n    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)\n    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {\n      val A1, A2 = Array.ofDim[Int](n)\n      REP(n) { i =>\n        A1(i) = ni() + offset\n        A2(i) = ni() + offset\n      }\n      (A1, A2)\n    }\n    def nm(n: Int, m: Int): Array[Array[Int]] = {\n      val A = Array.ofDim[Int](n, m)\n      REP(n) { i =>\n        REP(m) { j =>\n          A(i)(j) = ni()\n        }\n      }\n      A\n    }\n    def nal(n: Int): Array[Long] = map(n)(_ => nl())\n    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))\n  }\n\n  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = offset\n    val N = n + offset\n    while(i < N) { f(i); i += 1 }\n  }\n  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = n - 1 + offset\n    while(i >= offset) { f(i); i -= 1 }\n  }\n  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {\n    REP(to - from + 1, from) { i =>\n      f(i)\n    }\n  }\n  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {\n    val res = Array.ofDim[A](n)\n    REP(n)(i => res(i) = f(i + offset))\n    res\n  }\n\n  def sumL(as: Array[Int]): Long = {\n    var s = 0L\n    REP(as.length)(i => s += as(i))\n    s\n  }\n  def cumSum(as: Array[Int]): Array[Int] = {\n    val cum = Array.ofDim[Int](as.length + 1)\n    REP(as.length) { i =>\n      cum(i + 1) = cum(i) + as(i)\n    }\n    cum\n  }\n}\n\nclass Main(out: java.io.PrintWriter, sc: Main.InputReader) {\n  import sc._\n  import Main._\n  import java.util.Arrays.sort\n\n  import scala.collection.mutable\n  import math.{abs, max, min}\n  import mutable.ArrayBuffer\n\n  // toInt\u3068\u304b+7\u3068\u304b\u3059\u308b\u306a\u3089val\u306b\u3057\u308d\n  @inline private def MOD = 1000000007\n\n  def solve(): Unit = {\n    val N, M = ni()\n    val T = na(N)\n    val ans = Array.ofDim[Int](N)\n\n    REP(N - 1, 1) { i =>\n      sort(T, 0, i)\n      var m = 0\n      var j = 0\n      while(j < i && m + T(j) <= M - T(i)) {\n        m += T(j)\n        j += 1\n      }\n      ans(i) = i - j\n    }\n\n    out.println(ans.mkString(\" \"))\n  }\n}", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346"}
{"source_code": "/**\n  * Created by armanmac on 3/22/17.\n  */\n\nimport util.control.Breaks._\n\nobject Code {\n\n\n  //remove an element from array\n  def remover(input: Array[Int], index: Int): Array[Int] = {\n    var result: Array[Int] = new Array[Int](input.length - 1)\n    var counter = 0\n\n    for (i <- 0 to index - 1) {\n      result(counter) = input(i)\n      counter += 1\n    }\n    if (index != input.length - 1) {\n      for (i <- index + 1 to input.length - 1) {\n        result(counter) = input(i)\n        counter += 1\n      }\n    }\n\n    return result\n  }\n\n  def main(args: Array[String]): Unit = {\n    val str = scala.io.StdIn.readLine().split(' ')\n\n    val input = str(0).toInt\n    var copyInput = str(0).toInt\n    val size = str(0).length\n    val k = str(1).toInt\n\n\n    //converting to array\n    var arr: Array[Int] = new Array[Int](size)\n    for (i <- (0 to size - 1).reverse) {\n      arr(i) = copyInput % 10\n      copyInput /= 10\n    }\n\n    var iterSize = arr.length\n    var counter = 0\n    var removeCount = 0\n\n    breakable {\n      for (i <- (0 to arr.length - 1).reverse) {\n\n        if (arr(i) == 0) {\n          counter += 1\n        }\n        if (counter == k) {\n          break()\n        }\n        if (arr(i) != 0) {\n          arr = remover(arr, i)\n          removeCount += 1\n        }\n      }\n    }\n\n\n    if(k>= size || k > counter)\n      println(size-1)\n    else\n    println(removeCount)\n\n\n  }\n}\n", "src_uid": "7a8890417aa48c2b93b559ca118853f9"}
{"source_code": "object H extends App {\n\n  def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toInt) }\n  val Array(a, b) = readInts(2)\n\n  println(a + b)\n}", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add"}
{"source_code": "import scala.collection.mutable._\n\nobject Main{\n  def main(arr: Array[String]): Unit = {\n    val x = readLine.split(\" \").map(_.toInt);\n    val A = x(0)\n    val B = x(1)\n    val C = x(2)\n    val N = x(3)\n\n    if(List(A, B, C).filter(_ > N).size > 0){\n      println(-1)\n      return\n    }\n\n    if(C > A || C > B){\n      println(-1)\n      return\n    }\n\n    val totalFailed = N - (A + B - C)\n\n    if(totalFailed < 1){\n      println(-1)\n      return\n    }\n\n    println(totalFailed)\n  }\n}", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce"}
{"source_code": "object _1033B extends CodeForcesApp {\n  import annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._, Math._\n\n  override def apply(io: IO): io.type = {\n    val tests = io.read[Iterator[(Long, Long)]]\n    val ans = tests.map({case (a, b) => (a - b) == 1 && BigInt(a + b).isProbablePrime(20)})\n        .map(x => if (x) \"YES\" else \"NO\")\n    io.writeAll(ans.toTraversable, separator = \"\\n\")\n  }\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n  lazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)\n  def apply(io: IO): io.type\n  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()\n}\n/***********************************[Scala I/O]*********************************************/\nimport java.io._, java.util.StringTokenizer\nimport scala.collection.generic.CanBuild\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {\n  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n  val printer = new PrintWriter(out, true)\n\n  @inline private[this] def tokenizer() = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    tokenizers.headOption\n  }\n\n  def read[A](implicit read: IO.Read[A]): A = read.apply(this)\n  def read[C[_], A: IO.Read](n: Int)(implicit b: CanBuild[A, C[A]]): C[A] = Iterator.fill(n)(read).to[C]\n\n  def readTill(delim: String): String = tokenizer().get.nextToken(delim)\n  def readTillEndOfLine(): String = readTill(\"\\n\\r\")\n\n  def readAll[A: IO.Read]: (Int, Vector[A]) = {\n    val data = read[Vector[A]]\n    (data.length, data)\n  }\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n\n  def write(obj: Any): this.type = {\n    printer.print(obj)\n    this\n  }\n  def writeLine(): this.type = {\n    printer.println()\n    this\n  }\n  def writeLine(obj: Any): this.type = {\n    printer.println(obj)\n    this\n  }\n  def writeAll(obj: Traversable[Any], separator: String = \" \"): this.type = write(obj mkString separator)\n  def query[A: IO.Read](question: Any): A = writeLine(question).read\n\n  override def flush() = printer.flush()\n  def close() = {\n    flush()\n    in.close()\n    printer.close()\n  }\n}\nobject IO {\n  class Read[A](val apply: IO => A) {\n    def map[B](f: A => B): Read[B] = new Read(apply andThen f)\n  }\n\n  object Read {\n    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]))\n    implicit val string                                                   : Read[String]       = new Read(_.next())\n    implicit val int                                                      : Read[Int]          = string.map(_.toInt)\n    implicit val long                                                     : Read[Long]         = string.map(_.toLong)\n    implicit val bigInt                                                   : Read[BigInt]       = string.map(BigInt(_))\n    implicit val double                                                   : Read[Double]       = string.map(_.toDouble)\n    implicit val bigDecimal                                               : Read[BigDecimal]   = string.map(BigDecimal(_))\n    implicit def tuple2[A: Read, B: Read]                                 : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))\n    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]))\n    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]))\n    implicit val boolean                                                  : Read[Boolean]      = string map {s =>\n      s.toLowerCase match {\n        case \"yes\" | \"true\" | \"1\" => true\n        case \"no\" | \"false\" | \"0\" => false\n        case _ => s.toBoolean\n      }\n    }\n  }\n}\n\n", "src_uid": "5a052e4e6c64333d94c83df890b1183c"}
{"source_code": "/**\n * Created by vinaysaini on 7/18/15.\n */\n\n//    val Array(x,y,z) = io.StdIn.readLine().split(\" \").map(_.toInt)\n\nobject Test {\n  def main(args: Array[String]) {\n  //  val x =\n    val x = io.StdIn.readLine.split(\"\").filter(_ != \"\").map(_.toInt)\n    def forFirst(a: Int) = if(a == 9) 9 else revert(a)\n    def revert(a: Int) = if(a < 5) a else 9-a\n    println(\"%d%s\".format(forFirst(x.head),x.tail.map(revert).mkString))\n  }\n\n}\n", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61"}
{"source_code": "object Main399A {\n\n  def main(args: Array[String]): Unit = {\n    val input = readLine.split(\" \")\n    val n = input(0).toInt\n    val p = input(1).toInt\n    val k = input(2).toInt\n    println(\n        (if(p-k > 1)\"<< \"else\"\") + \n        ((if(p-k > 1)p-k else 1) to p-1).mkString(\" \") +\n        \" (\" + p + \") \" +\n        (p+1 to (if(p+k < n)p+k else n)).mkString(\" \") +\n        (if(p+k < n)\" >>\"else\"\")\n        )\n  }\n\n}", "src_uid": "526e2cce272e42a3220e33149b1c9c84"}
{"source_code": "import scala.io.StdIn\n\nobject Main extends App {\n  io.Source.stdin.getLines()\n  val Array(a, b) = StdIn.readLine().split(' ').map(_.toLong)\n  val Array(x, y, z) = StdIn.readLine().split(' ').map(_.toLong)\n  print((2 * x + y - a).max(0) + (y + 3 * z - b).max(0))\n}\n", "src_uid": "35202a4601a03d25e18dda1539c5beba"}
{"source_code": "object A579 {\n  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)\n\n  def readInts(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)\n  }\n\n  def readLongs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong)\n  }\n\n  def readBigs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken))\n  }\n\n  def main(args: Array[String]): Unit = {\n    val Array(n) = readBigs(1)\n    println(n.bitCount)\n  }\n}", "src_uid": "03e4482d53a059134676f431be4c16d2"}
{"source_code": "object Main extends App {\n  //  val INF = Integer.MAX_VALUE\n  //  val source = Source.stdin\n  //  val lines = source.getLines().toArray\n  //  source.close()\n  //  val Array(n, m) = lines(0).split(\" \").map(_.toInt)\n\n  //  val s = scala.io.StdIn.readLine()\n  //  println(s + \"!\")\n\n  val n = scala.io.StdIn.readLine().toInt\n  val x = scala.io.StdIn.readLine().split(\" \")\n  val y = scala.io.StdIn.readLine().split(\" \")\n\n  if(x.map(x => x.toInt).sum >= y.map(y => y.toInt).sum) {\n    println(\"Yes\")\n  } else {\n    println(\"No\")\n  }\n}\n", "src_uid": "e0ddac5c6d3671070860dda10d50c28a"}
{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n  val in = Source.stdin.getLines()\n  val n = in.next().toInt\n  println((1 to n).foldLeft(0l, 1l) {\n    case ((sum, prev), _) => (sum + prev * 2, prev * 2)\n  }._1)\n}\n", "src_uid": "f1b43baa14d4c262ba616d892525dfde"}
{"source_code": "\nobject Main {\n\n  def main(args: Array[String]) {\n    val Array(n,k)=io.StdIn.readLine().split(\" \").map(_.toInt)\n    val a=io.StdIn.readLine().split(\" \").map(_.toInt).toList.zipWithIndex.sortWith(_._1<_._1)\n    var s=0\n    var i=0\n    while(i<a.length && s+a(i)._1<=k){\n      s+=a(i)._1\n      i+=1\n    }\n    println(i)\n    if (i!=0)\n      println(a.take(i).map(_._2+1).mkString(\" \"))\n  }\n\n}\n", "src_uid": "dbb164a8dd190e63cceba95a31690a7c"}
{"source_code": "import java.util._\nimport java.lang._\nimport java.io._\n\nobject A {\n\n  var out: PrintWriter = null\n  var br: BufferedReader = null\n  var st: StringTokenizer = null\n\n  def next: String = {\n    while (st == null || !st.hasMoreTokens) {\n      st = new StringTokenizer(br.readLine)\n    }\n    return st.nextToken\n  }\n\n  def nextInt: Int = {\n    return Integer.parseInt(next)\n  }\n\n  def nextLong: Long = {\n    return Long.parseLong(next)\n  }\n\n  def sqDist(x1: Int, y1: Int, x2: Int, y2: Int): Int = {\n    return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)\n  }\n\n  def dist(x1: Int, y1: Int, x2: Int, y2: Int): Double = {\n    return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))\n  }\n\n  def isSquareTriangle(x1: Int, y1: Int, x2: Int, y2: Int, x3: Int, y3: Int): Boolean = {\n    val ab2 = sqDist(x1, y1, x2, y2)\n    val bc2 = sqDist(x2, y2, x3, y3)\n    val ac2 = sqDist(x1, y1, x3, y3)\n    val ab = dist(x1, y1, x2, y2)\n    val bc = dist(x3, y3, x2, y2)\n    val ac = dist(x1, y1, x3, y3)\n    if (ac < ab + bc && ab < ac + bc && bc < ac + ab) {\n      if (ab2 + bc2 == ac2 || ab2 + ac2 == bc2 || bc2 + ac2 == ab2) {\n        return true\n      }\n    }\n    return false\n  }\n\n  def solve: Int = {\n    val x1 = nextInt\n    val y1 = nextInt\n    val x2 = nextInt\n    val y2 = nextInt\n    val x3 = nextInt\n    val y3 = nextInt\n    if (isSquareTriangle(x1, y1, x2, y2, x3, y3)) {\n      out.println(\"RIGHT\")\n      return 1\n    }\n    if (isSquareTriangle(x1 + 1, y1, x2, y2, x3, y3)) {\n      out.println(\"ALMOST\")\n      return 1\n    }\n    if (isSquareTriangle(x1 - 1, y1, x2, y2, x3, y3)) {\n      out.println(\"ALMOST\")\n      return 1\n    }\n    if (isSquareTriangle(x1, y1 + 1, x2, y2, x3, y3)) {\n      out.println(\"ALMOST\")\n      return 1\n    }\n    if (isSquareTriangle(x1, y1 - 1, x2, y2, x3, y3)) {\n      out.println(\"ALMOST\")\n      return 1\n    }\n    if (isSquareTriangle(x1, y1, x2 + 1, y2, x3, y3)) {\n      out.println(\"ALMOST\")\n      return 1\n    }\n    if (isSquareTriangle(x1, y1, x2 - 1, y2, x3, y3)) {\n      out.println(\"ALMOST\")\n      return 1\n    }\n    if (isSquareTriangle(x1, y1, x2, y2 + 1, x3, y3)) {\n      out.println(\"ALMOST\")\n      return 1\n    }\n    if (isSquareTriangle(x1, y1, x2, y2 - 1, x3, y3)) {\n      out.println(\"ALMOST\")\n      return 1\n    }\n    if (isSquareTriangle(x1, y1, x2, y2, x3 + 1, y3)) {\n      out.println(\"ALMOST\")\n      return 1\n    }\n    if (isSquareTriangle(x1, y1, x2, y2, x3 - 1, y3)) {\n      out.println(\"ALMOST\")\n      return 1\n    }\n    if (isSquareTriangle(x1, y1, x2, y2, x3, y3 + 1)) {\n      out.println(\"ALMOST\")\n      return 1\n    }\n    if (isSquareTriangle(x1, y1, x2, y2, x3, y3 - 1)) {\n      out.println(\"ALMOST\")\n      return 1\n    }\n    out.println(\"NEITHER\")\n    return 1\n  }\n\n  def main(args: Array[String]): Unit = {\n    br = new BufferedReader(new InputStreamReader(System.in))\n    out = new PrintWriter(new BufferedOutputStream(System.out))\n    solve\n    out.close\n  }\n}\n", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d"}
{"source_code": "object C extends App {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }\n\n  val Array(n, m, k) = readInts(3)\n  val MOD = 998244353L\n\n  val pascal = Array.ofDim[Long](n + 1, n + 1)\n  for (i <- pascal.indices) pascal(i)(0) = 1L\n  for (i <- 1 until pascal.length) {\n    for (j <- 1 until pascal(i).length) pascal(i)(j) = (pascal(i - 1)(j - 1) + pascal(i - 1)(j)) % MOD\n  }\n\n  val pow = pascal(n - 1)(k)\n  val res = ((m * pow) % MOD) * BigInt(m - 1).modPow(k, MOD) % MOD\n\n  println(res)\n}\n", "src_uid": "b2b9bee53e425fab1aa4d5468b9e578b"}
{"source_code": "import java.io._\nimport java.util.StringTokenizer\n\nimport scala.collection.mutable\n\nobject A extends App {\n\n  def solve(in: InputReader): Unit = {\n    val n = in.nextInt\n    val arr = Array.fill(n)(in.nextInt)\n    val sum = arr.sum\n    var ans = arr.max\n\n    while (sum >= ans * n - sum)\n      ans += 1\n\n    println(ans)\n  }\n\n  solve(new InputReader(System.in))\n\n  private class InputReader(val in: InputStream) {\n\n    private val reader: BufferedReader = new BufferedReader(new InputStreamReader(in))\n    private var tokenizer: StringTokenizer = _\n\n    def nextInt: Int = {\n      next.toInt\n    }\n\n    def nextDouble: Double = {\n      next.toInt\n    }\n\n    def nextLong: Double = {\n      next.toInt\n    }\n\n    def next: String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens) {\n        tokenizer = new StringTokenizer(readLine)\n      }\n      tokenizer.nextToken\n    }\n\n    def readLine: String = {\n      try {\n        reader.readLine()\n      } catch {\n        case e: IOException => throw new RuntimeException(e)\n      }\n    }\n  }\n\n}", "src_uid": "d215b3541d6d728ad01b166aae64faa2"}
{"source_code": "object Solve {\n  import io.StdIn._\n  def main(args: Array[String]): Unit = {\n    val Array(n, m) = readLine.split(\" \").map(s => s.toInt)\n    val isBlackAndWhite = (1 to n).forall(_ => readLine.forall(c => !\"CMY\".contains(c)))\n    println (if (isBlackAndWhite) \"#Black&White\" else \"#Color\")\n  }\n}\n", "src_uid": "19c311c02380f9a73cd477e4fde27454"}
{"source_code": "object A extends App {\n  val Array(n, k) = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n\n  var r = k\n  var a = n\n\n  while (r > 0) {\n    val t = a % 10 + 1\n\n    if (t > r) a = a - r\n    else a = a / 10\n\n    r -= t\n  }\n\n  println(a)\n}\n", "src_uid": "064162604284ce252b88050b4174ba55"}
{"source_code": "object A141 {\n  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)\n\n  def readInts(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)\n  }\n\n  def readLongs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong)\n  }\n\n  def readBigs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken))\n  }\n\n  def main(args: Array[String]): Unit = {\n    val input1 = scala.io.StdIn.readLine\n    val input2 = scala.io.StdIn.readLine\n    val input3 = scala.io.StdIn.readLine\n\n    val map1 = (input1 + input2).sortBy(identity)\n    val map2 = input3.toCharArray.sortBy(identity)\n\n    if(map1.sameElements(map2)) {\n      println(\"YES\")\n    } else {\n      println(\"NO\")\n    }\n\n  }\n}", "src_uid": "b6456a39d38fabcd25267793ed94d90c"}
{"source_code": "object CubicalPlanet39D  extends App {\n  import java.io.{InputStream, PrintStream}\n  import java.util.Scanner\n  solve(System.in,System.out)\n  def solve(in: InputStream, out: PrintStream): Unit = {\n    val scanner = new Scanner(in)\n    val f1 = List(scanner.nextInt(),scanner.nextInt(),scanner.nextInt())\n    val f2 = List(scanner.nextInt(),scanner.nextInt(),scanner.nextInt())\n    val r = f1.zip(f2).map{case (a,b) => (a-b)*(a-b)}.sum\n    if(r<=2)\n      out.println(\"YES\")\n    else\n      out.println(\"NO\")\n  }\n}", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6"}
{"source_code": "object MyClass {\n      def add(x:Int, y:Int) = x + y;\n\n      def main(args: Array[String]) {\n         \n         var lines = io.Source.stdin.getLines;\n         /*var n = 0;\n         var k = 0;\n         var x = 0;*/\n         var Array(n,k,x) = lines.next.split(' ').map(_.toInt);\n         //var n = ln1.next.toInt;\n         //var k = ln1.next.toInt;\n         //var x = ln1.next.toInt;\n         \n         var total = 0;\n         var A = lines.next.split(' ').map(_.toInt);\n         var i = 1;\n         for ( i <- 0 to n - k - 1) {\n             var temp = A(i);\n             total = total + temp;\n         }\n         \n         if (k > n) total = total + x * n;\n         else total = total + x * k;\n         \n         print(total)\n         //for (ln <- io.Source.stdin.getLines) {\n             \n         //}\n      }\n   }\n", "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96"}
{"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P266A extends App {\n  val sc = new Scanner(System.in)\n  val out = new PrintWriter(System.out)\n\n  val N = sc.nextLine.toInt\n  val stones = sc.nextLine\n\n  def solve(s0: String): Int = {\n    @tailrec\n    def loop(acc: Int, c: Char, s: String): Int =\n      if (s.isEmpty) acc\n      else if (c == s.head) loop(acc + 1, c, s.tail)\n      else loop(acc, s.head, s.tail)\n    loop(0, s0.head, s0.tail)\n  }\n\n  out.println(solve(stones))\n  out.close\n}\n", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8"}
{"source_code": "import java.util._\nimport java.io._\n\nobject A {\n\n  var out: PrintWriter = null\n  var br: BufferedReader = null\n  var st: StringTokenizer = null\n\n  def next: String = {\n    while (st == null || !st.hasMoreTokens) {\n      st = new StringTokenizer(br.readLine)\n    }\n    return st.nextToken\n  }\n\n  def nextInt: Int = {\n    return Integer.parseInt(next)\n  }\n\n  def nextLong: Long = {\n    return java.lang.Long.parseLong(next)\n  }\n\n  def solve: Int = {\n    val path = next\n    var i = 1\n    var ans = \"\"\n    while (i < path.length) {\n      if (path(i) == '/' && path(i - 1) == '/') {\n      } else {\n        ans += path(i)\n      }\n      i += 1\n    }\n    i = ans.length - 1\n    while (i >= 0 && ans(i) == '/') {\n      i -= 1\n    }\n    out.println(\"/\" + ans.substring(0, i + 1))\n    return 1\n  }\n\n  def main(args: Array[String]): Unit = {\n    br = new BufferedReader(new InputStreamReader(System.in))\n    out = new PrintWriter(new BufferedOutputStream(System.out))\n    solve\n    out.close\n  }\n}\n", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031"}
{"source_code": "import java.util.StringTokenizer\n\nobject _554A extends App {\n  var token = new StringTokenizer(\"\")\n  def next = {\n    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)\n    token.nextToken()\n  }\n  val s = next\n  var set = Set[String]()\n  for (i <- 0 to s.length) {\n    val cb = s.splitAt(i)\n    for (j <- 'a' to 'z') set = set + (cb._1 + j + cb._2)\n  }\n  println(set.size)\n}\n", "src_uid": "556684d96d78264ad07c0cdd3b784bc9"}
{"source_code": "object CF411A {\n    def main(args: Array[String]) {\n        val pass = readLine()\n        println (\n            if (pass.length >= 5 && pass.exists(_.isUpper) && \n                pass.exists(_.isLower) && pass.exists(_.isDigit)) {\n                \"Correct\"\n            } else {\n                \"Too weak\"\n            }\n        )\n    }\n}", "src_uid": "42a964b01e269491975965860ec92be7"}
{"source_code": "//package template\n\nobject Template {\n\tdef main(args: Array[String]) {\n\t\tvar Array(n, d) = readLine.split(\" \").map(_.toInt)\n\t\tvar input = readLine.split(' ').map(_.toLong).reduceLeft(_ + _)\n\t\tif((n - 1) * 10 + input > d) print(-1)\n\t\telse print((d - ((n - 1) * 10 + input)) / 5 + (n - 1) * 2)\n\t}\n}", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea"}
{"source_code": "object P143A extends App {\n  val reqs = (readLine + \" \" + readLine + \" \" + readLine).split(\" \").map(_.toInt).toList\n  def f {\n    val r = 1 to 9\n    for (a <- r; b <- r; c <- r; d <- r)\n      if (Set(a, b, c, d).size == 4 && List(a + b, c + d, a + c, b + d, a + d, b + c) == reqs) {\n        print(\"%d %d\\n%d %d\".format(a, b, c, d))\n        return\n      }\n    print(\"-1\")\n  }\n  f\n}", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3"}
{"source_code": "object probA extends App{\n   def turns(n1 : Int,m1 : Int) = {        \n      var ret : Int = n1\n      var n : Int= m1\n      var m : Int= ret\n      /*\n      * (-n,-n) (-n,n+1)\n      * (-n,n+1) (n+1,n+1)\n      * (n+1,n+1)    (n+1,-n-1)\n      * (n+1,-n-1)   (-n-1,-n-1)\n      */\n      if( n<=0 && m>(n) && m<=(-n+1) ) ret = -4*n\n      else if (m>0 && n<=m && n>(-m+1)) ret=4*(m-1)+1\n      else if(n>0 && (m+n)>=0 && m<=n ) ret = 4*(n-1)+2\n      else ret = -4*(m+1)+3\n      \n      math.max(0,ret)\n   }\n   var line : String = readLine()\n   var Array(v1,v2)  = line.split(\" \")\n   println(turns(v1.toInt,v2.toInt))\n}", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382"}
{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n  val in = Source.stdin.getLines()\n  val Array(a, b) = in.next().split(' ').map(_.toInt)\n  var x = a\n  var xValue = (0, 0, 0)\n  while (x % 2 == 0 || x % 5 == 0 || x % 3 == 0) {\n    xValue = if (x % 2 == 0) {\n      x /= 2\n      (xValue._1 + 1, xValue._2, xValue._3)\n    } else if (x % 3 == 0) {\n      x /= 3\n      (xValue._1, xValue._2 + 1, xValue._3)\n    } else {\n      x /= 5\n      (xValue._1, xValue._2, xValue._3 + 1)\n    }\n  }\n  var y = b\n  var yValue = (0, 0, 0)\n  while (y % 2 == 0 || y % 5 == 0 || y % 3 == 0) {\n    yValue = if (y % 2 == 0) {\n      y /= 2\n      (yValue._1 + 1, yValue._2, yValue._3)\n    } else if (y % 3 == 0) {\n      y /= 3\n      (yValue._1, yValue._2 + 1, yValue._3)\n    } else {\n      y /= 5\n      (yValue._1, yValue._2, yValue._3 + 1)\n    }\n  }\n  if (x != y)\n    println(-1)\n  else\n    println(Math.abs(xValue._1 - yValue._1) + Math.abs(xValue._2 - yValue._2) + Math.abs(xValue._3 - yValue._3))\n}", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49"}
{"source_code": "object A527 {\n  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)\n\n  def readInts(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)\n  }\n\n  def readLongs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong)\n  }\n\n  def readBigs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken))\n  }\n\n  def main(args: Array[String]): Unit = {\n    var Array(a, b) = readLongs(2)\n    var res = 0L\n    while(a != b) {\n      if((a-b) % b == 0) {\n        res += (a-b)/b + 1L\n        a = 0\n        b = 0\n      } else {\n        res += (a/b)\n        val x = Array(a%b, b)\n        a = x.max\n        b = x.min\n      }\n    }\n    if(a == b && a != 0) {\n      res += 1\n    }\n    println(res)\n  }\n}", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83"}
{"source_code": "object Try1 {\n  def main(args: Array[String]) {\n    var m,x,c, n, i: Int = 0\n    var a = new Array[Int](101)\n    n = readInt()\n    m=0;\n    for (i <- 1 to n) {\n      x = readInt()\n      a(x) = a(x)+1\n    }\n    for (i<- 0 to 100)\n      if (a(i)>0){\n        m=m+1\n        c=i\n      }\n    if (m==2 && a(c)+a(c)==n) {\n      println(\"YES\")\n      i=0;\n      while (a(i)==0) i+=1\n      print(i+\" \")\n      i+=1\n      while (a(i)==0) i+=1\n      println(i)\n    }\n    else println(\"NO\")\n  }\n}", "src_uid": "2860b4fb22402ea9574c2f9e403d63d8"}
{"source_code": "object _935A extends CodeForcesApp {\n  import Utils._, annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._\n\n  override def apply(io: IO): io.type = {\n    val n = io.read[Int]\n    val ans = (1 until n).count(l => (n-l) % l == 0)\n    io.write(ans)\n  }\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n  lazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)\n  def apply(io: IO): io.type\n  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()\n}\nobject Utils {\n  import scala.collection.mutable, mutable.{Map => Dict}\n  implicit class GenericExtensions[A](val a: A) extends AnyVal {\n    def in(set: collection.Set[A]): Boolean = set(a)\n    def some: Option[A] = Some(a)\n    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a\n  }\n  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {\n    def onlyElement: A = assuming(t.size == 1)(t.head)\n    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)\n    def duplicates(implicit b: C of A): C[A] = {\n      val elems = mutable.Set.empty[A]\n      (t collect {case i if !elems.add(i) => i}).to[C]\n    }\n    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}\n    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)\n    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)\n    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]\n    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap\n    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)\n    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}\n    def toMutableMultiSet: Dict[A, Int] = {\n      val c = map[A] to 0\n      t.foreach(i => c(i) += 1)\n      c\n    }\n    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0\n    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)\n  }\n  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {\n    def sort(from: Int = 0, until: Int = a.length)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)\n  }\n  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {\n    def sort(from: Int = 0, until: Int = a.length)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)\n  }\n  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {\n    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t\n  }\n  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {\n    def key = p._1\n    def value = p._2\n    def toSeq(implicit ev: B =:= A): Seq[A] = Seq(p._1, ev(p._2))\n  }\n  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {\n    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)\n    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C]).withDefaultValue(b().result())\n    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]\n  }\n  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {\n    def lastKeyOption: Option[K] = m.lastOption.map(_.key)\n    def firstKeyOption: Option[K] = m.headOption.map(_.key)\n    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap\n    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}\n    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m\n    def mapValuesSafely[V2](f: V => V2): Map[K, V2] = m.mapValues(f).view.force //Hack to get around https://issues.scala-lang.org/browse/SI-4776\n  }\n  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {\n    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)\n    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)\n    private def removeNode(kv: (K, V)): (K, V) = {\n      m -= kv.key\n      kv\n    }\n  }\n  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {\n    def notContains(x: A): Boolean = !(s contains x)\n    def toMutable = mutable.Set.empty[A] ++ s\n  }\n  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {\n    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}\n    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)\n    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)\n    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}\n    //def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)\n  }\n  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {\n    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero\n    def toEnglish = if(x) \"Yes\" else \"No\"\n  }\n  implicit class IntExtensions(val x: Int) extends AnyVal {\n    import java.lang.{Integer => JInt}\n    def withHighestOneBit: Int = JInt.highestOneBit(x)\n    def withLowestOneBit: Int = JInt.lowestOneBit(x)\n    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)\n    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)\n    def bitCount: Int = JInt.bitCount(x)\n    def setLowestBits(n: Int): Int = x | (left(n) - 1)\n    def clearLowestBits(n: Int): Int = x & left(n, ~0)\n    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)\n    def setBit(i: Int): Int = x | left(i)\n    def clearBit(i: Int): Int = x & ~left(i)\n    def toggleBit(i: Int): Int = x ^ left(i)\n    def getBit(i: Int): Int = (x >> i) & 1\n    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)\n    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)\n  }\n  implicit class LongExtensions(val x: Long) extends AnyVal {\n    import java.lang.{Long => JLong}\n    def withHighestOneBitSet: Long = JLong.highestOneBit(x)\n    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)\n    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)\n    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)\n    def bitCount: Int = JLong.bitCount(x)\n    def setLowestBits(n: Int): Long = x | (left(n) - 1)\n    def clearLowestBits(n: Int): Long = x & left(n, ~0L)\n    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)\n    def setBit(i: Int): Long = x | left(i)\n    def clearBit(i: Int): Long = x & ~left(i)\n    def toggleBit(i: Int): Long = x ^ left(i)\n    def getBit(i: Int): Long = (x >> i) & 1\n    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)\n  }\n  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {\n    import Numeric.Implicits._\n    def **(i: Int): A = if (i == 0) n.one else {\n      val h = x ** (i/2)\n      if (i%2 == 0) h * h else h * h * x\n    }\n    def distance(y: A) = (x - y).abs()\n    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)\n    def whenNegative(f: => A): A = nonNegative.getOrElse(f)   //e.g. students.indexOf(\"Greg\").whenNegative(Int.MaxValue)\n  }\n  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {\n    import scala.collection.immutable.NumericRange, Integral.Implicits._\n    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x\n    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)\n    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)\n  }\n  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))\n  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)\n  def asc[A](implicit order: Ordering[A]): Ordering[A] = order\n  def map[K] = new {\n    def to[V](default: => V): Dict[K, V] = using(_ => default)\n    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {\n      override def apply(key: K) = getOrElseUpdate(key, f(key))\n    }\n  }\n  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]\n  def memoize[A, B](f: A => B): A ==> B = map[A] using f\n  implicit class FuzzyDouble(val x: Double) extends AnyVal {\n    def  >~(y: Double) = x > y + eps\n    def >=~(y: Double) = x >= y + eps\n    def  ~<(y: Double) = y >=~ x\n    def ~=<(y: Double) = y >~ x\n    def  ~=(y: Double) = (x distance y) <= eps\n  }\n  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {\n    val (xs, ys) = points.unzip\n    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)\n  }\n  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {\n    val shape = new java.awt.geom.GeneralPath()\n    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}\n    points.tail foreach {case (x, y) => shape.lineTo(x, y)}\n    shape.closePath()\n    shape\n  }\n  def until(until: Int): Range = 0 until until\n  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}\n  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}\n  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None\n  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)\n  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]\n  type ==>[A, B] = collection.Map[A, B]\n  val mod: Int = (1e9 + 7).toInt\n  val eps: Double = 1e-9\n}\n/***********************************[Scala I/O]*********************************************/\nimport Utils._, java.io._, java.util.StringTokenizer\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {\n  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n  val printer = new PrintWriter(out, true)\n\n  @inline private[this] def tokenizer() = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    when(tokenizers.nonEmpty)(tokenizers.head)\n  }\n\n  def read[A](implicit read: IO.Read[A]): A = read.apply(this)\n  def read[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(read).to[C]\n\n  def readTill(delim: String): String = tokenizer().get.nextToken(delim)\n  def readTillEndOfLine(): String = readTill(\"\\n\\r\")\n\n  def readAll[A: IO.Read]: (Int, Vector[A]) = {\n    val data = read[Vector[A]]\n    (data.length, data)\n  }\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n\n  def write(obj: Any): this.type = {\n    printer.print(obj)\n    this\n  }\n  def writeLine(): this.type = {\n    printer.println()\n    this\n  }\n  def writeLine(obj: Any): this.type = {\n    printer.println(obj)\n    this\n  }\n  def writeAll(obj: Traversable[Any], separator: String = \" \"): this.type = write(obj mkString separator)\n  def query[A: IO.Read](question: Any): A = writeLine(question).read\n\n  override def flush() = printer.flush()\n  def close() = {\n    flush()\n    in.close()\n    printer.close()\n  }\n}\nobject IO {\n  class Read[A](val apply: IO => A) {\n    def map[B](f: A => B): Read[B] = new Read(apply andThen f)\n  }\n  object Read {\n    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))\n    implicit val string                                       : Read[String]       = new Read(_.next())\n    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)\n    implicit val int                                          : Read[Int]          = string.map(_.toInt)\n    implicit val long                                         : Read[Long]         = string.map(_.toLong)\n    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))\n    implicit val double                                       : Read[Double]       = string.map(_.toDouble)\n    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))\n    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))\n    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]))\n    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]))\n    implicit val boolean                                      : Read[Boolean]      = string map {s =>\n      s.toLowerCase match {\n        case \"yes\" | \"true\" | \"1\" => true\n        case \"no\" | \"false\" | \"0\" => false\n        case _ => s.toBoolean\n      }\n    }\n  }\n}\n\n", "src_uid": "89f6c1659e5addbf909eddedb785d894"}
{"source_code": "object Main {\n  def main(args: Array[String]): Unit = {\n    val s = new Main()\n    s.solve()\n    s.out.flush()\n  }\n}\n\nclass Main {\n  import java.io._\n  import java.util.StringTokenizer\n\n  import scala.collection.mutable\n  import scala.util.Sorting\n  import math.{abs, max, min}\n  import mutable.{ArrayBuffer, ListBuffer}\n  import scala.reflect.ClassTag\n\n  val MOD = 1000000007\n  val out = new PrintWriter(System.out)\n\n  def solve(): Unit = {\n    val w, h, k = ni()\n    val ans = (map(k) { i =>\n      (h - 4 * i) * 2 + (w - 4 * i) * 2 - 4\n    }).sum\n    out.println(ans)\n  }\n\n\n  class InputReader(val stream: InputStream) {\n    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n    private var tokenizer: StringTokenizer = _\n\n    def next(): String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new StringTokenizer(reader.readLine)\n      tokenizer.nextToken\n    }\n\n    def nextInt(): Int = next().toInt\n    def nextLong(): Long = next().toLong\n    def nextChar(): Char = next().charAt(0)\n  }\n  val sc = new InputReader(System.in)\n  def ni(): Int = sc.nextInt()\n  def nl(): Long = sc.nextLong()\n  def nc(): Char = sc.nextChar()\n  def ns(): String = sc.next()\n  def ns(n: Int): Array[Char] = ns().toCharArray\n  def na(n: Int): Array[Int] = map(n)(_ => ni())\n  def nal(n: Int): Array[Long] = map(n)(_ => nl())\n  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))\n  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = offset\n    val N = n + offset\n    while(i < N) { f(i); i += 1 }\n  }\n  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = n - 1 + offset\n    while(i >= offset) { f(i); i -= 1 }\n  }\n\n  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {\n    val res = Array.ofDim[A](n)\n    rep(n)(i => res(i) = f(i))\n    res\n  }\n\n  def sumL(as: Array[Int]): Long = {\n    var s = 0L\n    rep(as.length)(i => s += as(i))\n    s\n  }\n}", "src_uid": "2c98d59917337cb321d76f72a1b3c057"}
{"source_code": "\n\n\nimport java.util.ArrayList\nimport java.util.StringTokenizer\n//import scala.reflect.io.File\nimport java.io.BufferedReader\nimport java.io.BufferedInputStream\nimport java.io.InputStreamReader\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\n\n/**\n * Educational round 16\n */\nobject A_ED16 {   var br = createBufferedReader(); var debugV = false \n    \n    //COMMENT ME !\n//    runTest(Test.sa2)\n//    debugV = true\n//    file = File(\"C:\\\\temp\\\\google cj\\\\2014q\\\\c-small.res\")\n  \n  def main(args: Array[String]): Unit = {\n    //---------------------------- parameters reading \n    val cd = readLine.string\n    val col = cd.charAt(0)\n    val row = cd.charAt(1)\n    \n    var res = 8\n    if (col == 'a' || col == 'h') res = 5\n    if (row == '1' || row == '8') if (res == 8) res = 5 else res = 3\n    \n    \n    //---------------------------- parameters reading :end \n    \n    outLn(res)\n    finish\n  }\n  \n  \n  //============================ service code ======================\n\n//  var file:File = null\n  val resultStr = new StringBuilder\n  def outLn(str:String) = resultStr.append(str).append(\"\\n\")\n  def outLn(number:Integer) = resultStr.append(number+\"\").append(\"\\n\")\n  def finish() {\n//    if (file == null || !devEnv) {\n      println(resultStr.toString())\n//    } else {\n//      file.writeAll(resultStr.toString())\n//    }\n  }\n  \n  def readLine() = new Line  \n  class Line {\n    val fullLine = br.readLine()\n    val tok = new StringTokenizer(fullLine, \" \")\n    def int = tok.nextToken().toInt\n    def long = tok.nextToken().toLong\n    def double = tok.nextToken().toDouble\n    def string = tok.nextToken()\n  }\n  \n  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {\n    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);\n    new BufferedReader(new InputStreamReader(bis));\n  }\n  \n  def runTest(str:String) = if (devEnv) { \n    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes(\"ISO-8859-1\")))\n  }\n  \n  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function\n  \n  lazy val devEnv = this.getClass.getCanonicalName.contains(\".\")\n  \n//============================================================================================\nobject Test {\n  \nval sa1 = \"\"\"\n\"\"\"\n\nval sa2 = \"\"\"\n\"\"\"\n\nval sa3 = \"\"\"\n\"\"\"\n}\n\n}\n", "src_uid": "6994331ca6282669cbb7138eb7e55e01"}
{"source_code": "import java.io.FileReader\nimport java.util.Comparator\n\nimport collection.Searching._\nimport scala.collection.mutable\n\nobject Solution {\n  //Console.setIn(new FileReader(new java.io.File(\"input\")))\n  //Console.setOut(new PrintStream(new java.io.File(\"output\")))\n  var caseNo = 1\n  val magicMod = 1000000007\n\n  def doCase() : Unit = {\n    val Array(n, m, k) = readBigIntLine()\n    //println(allBlocks(n, m).count(goodBlock(_, k)))\n    //println(goodBlock(allBlocks(3, 3).head, -1))\n    /*    allBlocks(n, m).foreach{\n          a =>\n            println(\"-\")\n            a.foreach(aa => println(aa.mkString(\" \")))\n        }*/\n\n    if (((n % 2 == 1) ^ (m % 2 == 1)) && k == -1) {\n      println(0)\n    } else {\n      println(BigInt(2).modPow((n - 1) * (m - 1), magicMod))\n    }\n  }\n\n  /*def goodBlock(block : Array[Array[Int]], k : Int): Boolean = {\n    val goodRow = (0 until block.length).map(r => block(r).product  == k).reduce(_ && _)\n    val goodCol = (0 until block(0).length).map(c => block.indices.map(block(_)(c)).product == k).reduce(_ && _)\n    goodRow && goodCol\n  }\n\n  def allBlocks(w : Int, h : Int) : Iterable[Array[Array[Int]]] = {\n    (0L until 1L << (w * h)).map {\n      i =>\n        (0 until h).map {\n          r =>\n            (0 until w).map(c => if (((i >> (w * r + c)) & 1) == 1) 1 else -1).toArray\n        }.toArray\n    }.view\n  }*/\n\n  def main(args: Array[String]) {\n    var tests = 1\n    for (test <- 0 until tests) {\n      doCase()\n      caseNo += 1\n    }\n  }\n\n  def readIntLine(): Array[Int] = {\n    readLine().split(\" \").map(_.toInt)\n  }\n\n  def readLongLine(): Array[Long] = {\n    readLine().split(\" \").map(_.toLong)\n  }\n\n  def readBigIntLine(): Array[BigInt] = {\n    readLine().split(\" \").map(BigInt.apply)\n  }\n}", "src_uid": "6b9eff690fae14725885cbc891ff7243"}
{"source_code": "object bearAndGame extends App{\n  val n = readInt()\n  val mins = readLine().split(\" \").map(_.toInt)\n  var temp : Int = 0\n\n  for(i <- 0 until(mins.length)){\n    if (mins(i)-temp > 15) temp+15\n    else temp = mins(i)\n  }\n\n  if(temp<=75) println(temp+15)\n  else println(90)\n}", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27"}
{"source_code": "\nimport java.io._\nimport java.util._\n\nimport scala.collection.mutable\n\nobject B {\n\n  var out: PrintWriter = null\n  var br: BufferedReader = null\n  var st: StringTokenizer = null\n\n  def main(args: Array[String]): Unit = {\n    br = new BufferedReader(new InputStreamReader(System.in))\n    out = new PrintWriter(new BufferedOutputStream(System.out))\n    solve\n    out.close\n  }\n\n  def next: String = {\n    while (st == null || !st.hasMoreTokens) {\n      st = new StringTokenizer(br.readLine)\n    }\n    return st.nextToken\n  }\n\n  def nextInt: Int = return Integer.parseInt(next)\n\n  def nextBoolean: Boolean = next.equalsIgnoreCase(\"1\")\n\n  def nextLong: Long = return java.lang.Long.parseLong(next)\n\n  def nextDouble: Double = return java.lang.Double.parseDouble(next)\n\n  class MultiHashSet[T <% Comparable[T]] {\n    val map = new mutable.HashMap[T, Int]()\n\n    def count(x: T): Int = {\n      return map.getOrElse(x, 0)\n    }\n\n    def add(x: T): Unit = map.put(x, count(x) + 1)\n\n    def remove(x: T): Boolean = {\n      val prev = count(x)\n      if (prev == 0)\n        return false\n      if (prev == 1) {\n        map.remove(x)\n      } else {\n        map.put(x, prev - 1)\n      }\n      return true\n    }\n\n    override def toString = s\"MultiHashSet($map)\"\n  }\n\n  class MultiTreeSet[T <% Comparable[T]] {\n    val map = new TreeMap[T, Int]()\n\n    def count(x: T): Int = {\n      val res = map.get(x)\n      if (res == null)\n        return 0\n      return res\n    }\n\n    def add(x: T): Unit = map.put(x, count(x) + 1)\n\n    def first(): T = return map.firstKey()\n\n    def last(): T = return map.lastKey()\n\n    def remove(x: T): Boolean = {\n      val prev = count(x)\n      if (prev == 0)\n        return false\n      if (prev == 1) {\n        map.remove(x)\n      } else {\n        map.put(x, prev - 1)\n      }\n      return true\n    }\n  }\n\n  /**\n    * Segment tree for any commutative function\n    *\n    * @param values      Array of Int\n    * @param commutative function like min, max, sum\n    * @param zero        zero value - e.g. 0 for sum, Inf for min, max\n    */\n  class SegmentTree(values: Array[Int])(commutative: (Int, Int) => Int)(zero: Int) {\n    private val SIZE = 1e5.toInt\n    private val n = values.length\n    val t = new Array[Int](2 * n)\n    Array.copy(values, 0, t, n, n)\n\n    // build segment tree\n    def build = {\n      for (i <- n - 1 until 0 by -1) {\n        t(i) = commutative(t(2 * i), t(2 * i + 1))\n      }\n    }\n\n    // change value at position p to x\n    // TODO beatify\n    def modify(p: Int, x: Int) = {\n      var pos = p + n\n      t(pos) = x\n      while (pos > 1) {\n        t(pos / 2) = commutative(t(pos), t(pos ^ 1))\n        pos /= 2\n      }\n    }\n\n    // TODO implement me!\n    def modify(p: Int, left: Int, right: Int) = ???\n\n    def query(p: Int) = ???\n\n    // sum [l, r)\n    // min l = 0\n    // max r = n\n    // TODO beatify\n    def query(left: Int, right: Int): Int = {\n      var res = zero\n      var r = right + n\n      var l = left + n\n      while (l < r) {\n        if (l % 2 == 1) {\n          res = commutative(res, t(l))\n          l += 1\n        }\n        if (r % 2 == 1) {\n          r -= 1\n          res = commutative(res, t(r))\n        }\n        l /= 2\n        r /= 2\n      }\n      res\n    }\n  }\n\n  def naiveCalc(x: Int, m: Int, b: Int): Long = {\n    var sum = 0L\n    val y = (-x / m + b).toLong\n    val k = y + 1.toLong\n    sum += (x * (x + 1.toLong)) / 2\n    sum *= k\n    sum += ((y * k) / 2.toLong) * (x + 1)\n    sum\n  }\n\n  def solve: Int = {\n    val m = nextInt\n    val b = nextInt\n    var maxSum = Long.MinValue\n    for (i <- 0 to b) {\n      val z = i * m\n      maxSum = Math.max(maxSum, naiveCalc(z, m, b))\n    }\n//    for (i <- 0 to m * b) {\n//      if (i % m == 0) {\n//        val y = -i / m + b\n//        if (i.toLong * y.toLong > maxSum) {\n//          maxSum = i.toLong * y.toLong\n//          maxX = i\n//        } else if (i.toLong * y.toLong == maxSum) {\n//          if (naiveCalc(i, m, b) > naiveCalc(maxX, m, b)) {\n//            maxX = i\n//          }\n//        }\n//      }\n//    }\n    out.println(maxSum)\n    return 0\n  }\n}\n", "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2"}
{"source_code": "//package com.codility.challenge._codeforces_cyclic_shift\n\n/**\n  * Created by obarros on 17/12/2016.\n  */\nobject Main {\n  def main(args: Array[String]): Unit = {\n    val word = scala.io.StdIn.readLine()\n    print(solution(word))\n\n  }\n\n  def solution(s: String): Int = {\n    mapListOfShiftStrinf(s).length\n  }\n\n  def shifString(s: String): String = {\n    s.substring(1, s.length) + s.charAt(0)\n  }\n\n  def mapListOfShiftStrinf(s: String): List[String] = {\n    var result = List[String]()\n    var value = s\n    var resultI = s\n    result =   s :: result\n    for (i <- 0 until s.length) {\n      result = shifString(resultI) :: result\n      value = shifString(value)\n      resultI =  value\n  //    println(value)\n    }\n    result.distinct\n  }\n\n}\n", "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e"}
{"source_code": "object C extends App {\n  val Array(a, b, c, d) = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n\n  val pref = (a to b)\n    .foldLeft(Array.fill[Int](b + c + 2)(0)) { (pref, x) =>\n      pref(x + b) += 1\n      pref(x + c + 1) -= 1\n      pref\n    }\n    .scanLeft(0L)(_ + _)\n    .tail\n    .scanRight(0L)(_ + _)\n\n  val ans = (c to d.min(b + c)).foldLeft(0L)((s, z) => s + pref(z + 1))\n\n  println(ans)\n}\n", "src_uid": "4f92791b9ec658829f667fcea1faee01"}
{"source_code": "object A00131 extends Application {\n  def isAllCaps(str: String) = str forall (_.isUpper)\n  def switchCase(ch: Char) = if (ch.isLower) ch.toUpper else ch.toLower\n  def changeString(str: String) = str map switchCase\n  val str = Console.readLine();\n  val changed = if (isAllCaps(str.tail)) changeString(str) else str\n  println(changed)\n}\n", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf"}
{"source_code": "import scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util._, control._\nimport scala.math.Ordering.Implicits._\n\nobject _633B extends CodeForcesApp {\n  override type Result = Stream[Int]\n\n  override def solve(read: InputReader) = {\n    val n = read[Int]\n    val fives = Stream.iterate(5)(_ * 5)\n    def zeroes(i: Int) = fives.map(i / _).takeWhile(_ > 0).sum\n    Stream.range(1, 500000).filter(i => zeroes(i) == n)\n  }\n\n  override def format(result: Result) = {\n    val s = result.size\n    if (s > 0) s\"$s\\n${result mkString \" \"}\" else s.toString\n  }\n}\n/****************************[Ignore Template Below]****************************************/\nabstract class CodeForcesApp {\n  val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)\n  type Result\n  def solve(scanner: InputReader): Result\n  def format(result: Result): String\n  def apply(scanner: InputReader): String = format(solve(scanner))\n  def main(args: Array[String]): Unit = println(apply(new InputReader(System.in)))\n}\n/*********************************[Scala Scanner]*******************************************/\nimport java.io.{BufferedReader, Reader, InputStreamReader, StringReader, InputStream}\nimport java.util.StringTokenizer\n\nclass InputReader(reader: BufferedReader) extends Iterator[String] with AutoCloseable {\n  def this(reader: Reader) = this(new BufferedReader(reader))\n  def this(inputStream: InputStream) = this(new InputStreamReader(inputStream))\n  def this(str: String) = this(new StringReader(str))\n\n  private[this] val tokenizers = Iterator.continually(reader.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n\n  @inline private[this] def tokenizer(): Option[StringTokenizer] = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    if (tokenizers.nonEmpty) Some(tokenizers.head) else None\n  }\n\n  def apply[A: Parser]: A = implicitly[Parser[A]].apply(this)\n\n  def apply[C[_], A: Parser](n: Int)(implicit cbf: Parser.Collection[C, A]): C[A] = {\n    val builder = cbf()\n    for {_ <- 1 to n} builder += apply[A]\n    builder.result()\n  }\n\n  def till(delim: String): String = tokenizer().get.nextToken(delim)\n  def tillEndOfLine() = till(\"\\n\\r\")\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n  override def close() = reader.close()\n}\n\nclass Parser[A](val apply: InputReader => A) {\n  def map[B](f: A => B): Parser[B] = new Parser(apply andThen f)\n}\nobject Parser {\n  type Collection[C[_], A] = scala.collection.generic.CanBuildFrom[C[A], A, C[A]]\n  implicit def collection[C[_], A: Parser](implicit cbf: Collection[C, A])   : Parser[C[A]]            = new Parser(r => r[C, A](r[Int]))\n  implicit val string                                                        : Parser[String]          = new Parser(_.next())\n  implicit val char                                                          : Parser[Char]            = string.map(s => s.ensuring(_.length == 1, s\"Expected Char; found $s\").head)\n  implicit val boolean                                                       : Parser[Boolean]         = string.map(_.toBoolean)\n  implicit val int                                                           : Parser[Int]             = string.map(_.toInt)\n  implicit val long                                                          : Parser[Long]            = string.map(_.toLong)\n  implicit val bigInt                                                        : Parser[BigInt]          = string.map(BigInt(_))\n  implicit val double                                                        : Parser[Double]          = string.map(_.toDouble)\n  implicit val bigDecimal                                                    : Parser[BigDecimal]      = string.map(BigDecimal(_))\n  implicit def tuple2[A: Parser, B: Parser]                                  : Parser[(A, B)]          = new Parser(r => (r[A], r[B]))\n  implicit def tuple3[A: Parser, B: Parser, C: Parser]                       : Parser[(A, B, C)]       = new Parser(r => (r[A], r[B], r[C]))\n  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]))\n  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]))\n}\n", "src_uid": "c27ecc6e4755b21f95a6b1b657ef0744"}
{"source_code": "object C extends App {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }\n\n  val s = readLine\n  val double = ('A' to 'Z').find(c => s.count(_ == c) > 1).get\n  val _p1 = s.indexOf(double)\n  val _p2 = s.indexOf(double, _p1 + 1)\n\n  def solve(s: String, i: Int): Boolean = {\n\n    val p1 = s.indexOf(double)\n    val p2 = s.indexOf(double, p1 + 1)\n      //println(i, s, double, p1, p2)\n\n    if (p1 != p2 - 1 && (p1 == 25 - p2 || p1 == 26 - p2) /*|| (p1 == 27 - p2 && p1 == 1)*/ ) {\n      println(s.take(13))\n      println(s.drop(13).filter(_ != double).reverse)\n      true\n    } else if (p1 != p2 - 1 && (p1 == 27 - p2 /*&& p1 == 1*/)) {\n      println(s.take(14).filter(_ != double))\n      println(s.drop(14).reverse)\n      true\n    } else false\n  }\n\n  var ok = false\n\n  var i = 0\n  while (i < 27 && !ok && _p2 != _p1 + 1) {\n    val ss = s.drop(i) ++ s.take(i)\n    ok = solve(ss, i)\n    i += 1\n  }\n\n  if (!ok) println(\"Impossible\")\n}\n", "src_uid": "56c5ea443dec7a732802b16aed5b934d"}
{"source_code": "object B444 {\n  def main(args: Array[String]){\n    val n = Console.in.readLine().toInt\n    \n    val cubesOrder = 0 to n-1\n    \n    val matrix = for(_ <- 0 until n)\n        yield Console.in.readLine.split(\" \").map(_.toInt)\n    \n    var continue = true;\n        \n    for(i <- 1 to ('9'*n).toInt if(continue == true)) {\n      val digits = i.toString.map(_.asDigit).toList\n      var possible = false\n      \n      cubesOrder.permutations.takeWhile(_ => possible == false).foreach(perm => {\n        var result = true;\n        for(j <- 0 until digits.size) {\n          result &= matrix(perm(j)).contains(digits(j))  \n        }\n        possible |= result\n      })\n      \n      if(!possible) {\n        continue = false;\n        print(i-1)\n      }\n      \n    }\n    \n  }\n}", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b"}
{"source_code": "import scala.math._\nimport scala.util.Sorting._\nimport scala.collection.mutable.Map\n\nobject Main extends App{\n  \n var result = (1 to 8)\n.map(x => readLine)\n.flatMap(x => x.toList)\n.map(x => \n  (\n  x.toLower\n  match\n  {\n  case 'q' => 9\n  case 'r' => 5\n  case 'b' => 3\n  case 'n' => 3\n  case 'p' => 1\n  case _ => 0\n  },\n  if(x == x.toUpper) 1 else 0\n  )\n).groupBy(x => x._2).map(x => (x._1, x._2.map(x => x._1).sum))\n\nif(result.getOrElse(0,0) < result.getOrElse(1,0))\n  println(\"White\")\nelse if (result.getOrElse(0,0) > result.getOrElse(1,0))\n  println(\"Black\")\nelse\n  println(\"Draw\")\n}", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442"}
{"source_code": "import java.util.StringTokenizer\n\nobject _507B extends App {\n  var token = new StringTokenizer(\"\")\n  def next = {\n    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)\n    token.nextToken()\n  }\n  val r = next.toLong\n  val x = next.toLong\n  val y = next.toLong\n  val xx = next.toLong\n  val yy = next.toLong\n\n  def sqr(x: Long) = x * x\n\n  val dist2 = sqr(x - xx) + sqr(y - yy)\n  val hehe = sqr(2 * r)\n\n  println((Math.sqrt(dist2) / Math.sqrt(hehe)).ceil.round)\n}\n", "src_uid": "698da80c7d24252b57cca4e4f0ca7031"}
{"source_code": "import java.io._\nimport scala.annotation.tailrec\n\nobject Easy {\n  val reader = new BufferedReader(new InputStreamReader(System.in))\n  def readInt = reader.readLine().toInt\n  def readInts = reader.readLine().split(\" \").map(_.toInt)\n\n  val s = reader.readLine()\n  def ans = s.take(1).toUpperCase + s.drop(1)\n\n  def main(a: Array[String]) {\n    println(ans)\n  }\n}\n", "src_uid": "29e0fc0c5c0e136ac8e58011c91397e4"}
{"source_code": "object B extends App {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }\n\n  val ss = readLine\n  val n = BigInt(ss.dropRight(1).toLong - 1)\n  val s = ss.last\n\n  val pos = \"fedabc\"\n\n  val r1 = (n / 4) * 16\n  val r2 = (n % 2) * 7\n  val r3 = pos.indexOf(s) + 1\n\n  println(r1 + r2 + r3)\n}\n", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45"}
{"source_code": "object CF_525_2_A {\n  def solve(x: Int):Option[(Int, Int)] = {\n    for {\n      a <- 1 to x\n      b <- 1 to a\n      if a % b == 0 && a * b > x && a / b < x\n    } return Some(a, b)\n  return None\n  }\n\n  \n  def main(args: Array[String]) = {\n    val io = new IO(System.in)\n    val solution = solve(io.int).fold(\"-1\"){case(a,b) => s\"$a $b\"}\n    println(solution)\n  }\n\n\n/// boilerplate utility methods: ///\n    import java.util.Scanner\n    class IO(sc: Scanner) {\n      def this(i: java.io.InputStream) = this(new Scanner(i))\n      def this(s: String) = this(new Scanner(s))\n      def nextLine = sc.nextLine() // do this if still on previous line before collecting line of data\n      def collect[T](f: String => T) = {sc.nextLine().split(\" \").toVector.map(f)}\n      def intSeq() = collect(_.toInt)\n      def doubleSeq() = collect(_.toDouble)\n      def int() = sc.nextInt()\n      def long() = sc.nextLong()\n      def double() = sc.nextDouble()\n    }\n\n    object Utility {\n      def intCeil(a: Int, b: Int) = (a - 1) / b + 1\n      def longCeil(a: Long, b: Long) = (a - 1) / b + 1\n    }\n}", "src_uid": "883f67177474d23d7a320d9dbfa70dd3"}
{"source_code": "import java.util.Scanner\n\n/**\n * Created by hama_du on 2014/05/22.\n */\nobject ProblemC extends App {\n  val MOD = 1000000007\n\n  val in = new Scanner(System.in)\n  val n,k,d = in.nextInt()\n\n\n  val dp = Array.ofDim[Long](n+1,2)\n  dp(0)(0) = 1\n  for (i <- 0 until n) {\n    for (flag <- 0 to 1) {\n      for (j <- 1 to k) {\n        val ti = i + j\n        val tflag = if ((flag == 1) || (j >= d)) { 1 } else { 0 }\n        if (ti <= n) {\n          dp(ti)(tflag) += dp(i)(flag)\n          dp(ti)(tflag) %= MOD\n        }\n      }\n    }\n  }\n  println(dp(n)(1))\n}\n", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d"}
{"source_code": "import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._\n\nobject _680B extends CodeForcesApp {\n  override def apply(io: IO) = {\n    val n, a = io[Int]\n    val isCriminal = io[Vector, Int](n).map(_ == 1)\n\n    var ans = 0\n    var l = a - 1\n    var r = a - 1\n\n    while(l >= 0 && r < n) {\n      if (isCriminal(l) && isCriminal(r)) {\n        ans += (if (l == r) 1 else 2)\n      }\n      //debug(l, r, isCriminal(l), isCriminal(r), ans)\n      l -= 1\n      r += 1\n    }\n    ans = ans + isCriminal.slice(0, l+1).count(identity)\n    ans = ans + isCriminal.slice(r, n).count(identity)\n    io += ans\n  }\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n  lazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)\n  def apply(io: IO): io.type\n  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()\n}\nobject Utils {\n  import scala.collection.mutable, mutable.{Map => Dict}\n  implicit class GenericExtensions[A](val a: A) extends AnyVal {\n    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a\n  }\n  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {\n    def onlyElement: A = t.head.ensuring(t.size == 1)\n    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)\n    def duplicates(implicit b: C of A): C[A] = {\n      val elems = mutable.Set.empty[A]\n      (t collect {case i if !elems.add(i) => i}).to[C]\n    }\n    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}\n    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]\n    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap\n    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)\n    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}\n    def toMutableMultiSet: Dict[A, Int] = {\n      val c = map[A] to 0\n      t.foreach(i => c(i) += 1)\n      c\n    }\n    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0\n  }\n  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)\n  }\n  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)\n  }\n  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {\n    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t\n  }\n  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {\n    def key = p._1\n    def value = p._2\n  }\n  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {\n    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)\n    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])\n    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]\n  }\n  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {\n    def lastKeyOption: Option[K] = m.lastOption.map(_.key)\n    def firstKeyOption: Option[K] = m.headOption.map(_.key)\n    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap\n    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}\n    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m\n  }\n  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {\n    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)\n    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)\n    private def removeNode(kv: (K, V)): (K, V) = {\n      m -= kv.key\n      kv\n    }\n  }\n  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {\n    def notContains(x: A): Boolean = !(s contains x)\n    def toMutable = mutable.Set.empty[A] ++ s\n  }\n  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {\n    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}\n    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f) findWithIndex c\n  }\n  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {\n    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero\n  }\n  implicit class IntExtensions(val x: Int) extends AnyVal {\n    def bitCount: Int = java.lang.Integer.bitCount(x)\n  }\n  implicit class LongExtensions(val x: Long) extends AnyVal {\n    def bitCount: Int = java.lang.Long.bitCount(x)\n  }\n  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {\n    import Numeric.Implicits._\n    def **(i: Int): A = if (i == 0) n.one else {\n      val h = x ** (i/2)\n      if (i%2 == 0) h * h else h * h * x\n    }\n    def distance(y: A) = (x - y).abs()\n    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)\n    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf \"Greg\" whenNegative Int.MaxValue\n  }\n  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {\n    import scala.collection.immutable.NumericRange, Integral.Implicits._\n    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x\n    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(n.min(x, y), n.max(x, y), n.one)\n    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)\n  }\n  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))\n  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)\n  def asc[A](implicit order: Ordering[A]): Ordering[A] = order\n  def map[K] = new {\n    def to[V](default: V): Dict[K, V] = Dict.empty[K, V] withDefaultValue default // also to(Dict.empty[K2, V])\n  }\n  def newMultiMap[K, V]: mutable.MultiMap[K, V] = new mutable.HashMap[K, mutable.Set[V]] with mutable.MultiMap[K, V]\n  def memoize[A, B](f: A => B): A ==> B = new mutable.HashMap[A, B]() {\n    override def apply(key: A) = getOrElseUpdate(key, f(key))\n  }\n  implicit class FuzzyDouble(val x: Double) extends AnyVal {\n    def  >~(y: Double) = x > y + eps\n    def >=~(y: Double) = x >= y + eps\n    def  ~<(y: Double) = y >=~ x\n    def ~=<(y: Double) = y >~ x\n    def  ~=(y: Double) = (x distance y) <= eps\n  }\n  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None\n  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)\n  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]\n  type ==>[A, B] = collection.Map[A, B]\n  val mod: Int = (1e9 + 7).toInt\n  val eps: Double = 1e-9\n}\n/***********************************[Scala I/O]*********************************************/\nimport Utils._, java.io._, java.util.StringTokenizer\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends PrintWriter(out) with Iterator[String] {\n  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n\n  @inline private[this] def tokenizer() = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    when(tokenizers.nonEmpty)(tokenizers.head)\n  }\n\n  def apply[A](implicit read: IO.Read[A]): A = read.apply(this)\n  def apply[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(apply).to[C]\n\n  def till(delim: String): String = tokenizer().get.nextToken(delim)\n  def tillEndOfLine(): String = till(\"\\n\\r\")\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n\n  var separator = \" \"\n  private[this] var isNewLine = true\n\n  def +=[A](x: A)(implicit write: IO.Write[A]): this.type = {\n    write(this)(x)\n    this\n  }\n  def ++=[A: IO.Write](xs: Traversable[A]): this.type = (this += xs.size) appendNewLine xs\n\n  def appendNewLine[A: IO.Write](x: A): this.type = {\n    println()\n    this += x\n  }\n\n  override def print(obj: String) = {\n    if (isNewLine) isNewLine = false else super.print(separator)\n    super.print(obj)\n  }\n  override def println() = if (!isNewLine) {\n    super.println()\n    isNewLine = true\n  }\n  override def close() = {\n    flush()\n    in.close()\n    super.close()\n  }\n}\nobject IO {\n  class Read[A](val apply: IO => A) {\n    def map[B](f: A => B): Read[B] = new Read(apply andThen f)\n  }\n  object Read {\n    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r[C, A](r[Int]))\n    implicit val string                                       : Read[String]       = new Read(_.next())\n    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)\n    implicit val boolean                                      : Read[Boolean]      = string.map(_.toBoolean)\n    implicit val int                                          : Read[Int]          = string.map(_.toInt)\n    implicit val long                                         : Read[Long]         = string.map(_.toLong)\n    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))\n    implicit val double                                       : Read[Double]       = string.map(_.toDouble)\n    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))\n    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r[A], r[B]))\n    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r[A], r[B], r[C]))\n    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r[A], r[B], r[C], r[D]))\n  }\n  trait Write[-A] {\n    def apply(out: PrintWriter)(x: A): Unit\n  }\n  trait DefaultWrite {\n    implicit def any[A]: Write[A] = Write(_.toString)\n  }\n  object Write extends DefaultWrite {\n    def apply[A](f: A => String) = new Write[A] {\n      override def apply(out: PrintWriter)(x: A) = out.print(f(x))\n    }\n    implicit val boolean: Write[Boolean] = Write(b => if (b) \"YES\" else \"NO\")\n    implicit def tuple2[A, B]: Write[(A, B)] = Write {case (a, b) => s\"$a $b\"}\n    implicit def array[A]: Write[Array[A]] = Write(_ mkString \" \")\n    implicit def iterable[A](implicit write: Write[A]): Write[Traversable[A]] = new Write[Traversable[A]] {\n      override def apply(out: PrintWriter)(xs: Traversable[A]) = {\n        xs foreach write(out)\n        out.println()\n      }\n    }\n  }\n}\n\n", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5"}
{"source_code": "object Solution extends App {\n  val in = io.Source.stdin.getLines()\n  val n = in.next().toInt\n  val a = 1234567\n  val b = 123456\n  val c = 1234\n  val res = (0 to n / a).exists{ ac =>\n      val left = n - (ac * a)\n      (0 to left / b).exists(bc => (left - (bc * b)) % c == 0)\n  }\n  if (res)\n    println(\"YES\")\n  else\n    println(\"NO\")\n}\n", "src_uid": "72d7e422a865cc1f85108500bdf2adf2"}
{"source_code": "object AAryaAndBran extends App {\n  def days(k: Int, a: Array[Int]): (Int, Int, Int) =\n    a.foldLeft((k, 0, 0)) { case ((k, r, i), a) =>\n      if (k > 0) {\n        val t = r + a\n        val p = t min 8\n        (k - p, t - p, i + 1)\n      }\n      else (k, r, i)\n    }\n\n  val Array(n, k) = scala.io.StdIn.readLine.split(\" \").map(_.toInt)\n  val a: Array[Int] = scala.io.StdIn.readLine.split(\" \").map(_.toInt)\n\n  val (nk, r, d) = this.days(k, a)\n  if (nk > 0) println(\"-1\")\n  else println(d)\n}\n", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a"}
{"source_code": "import scala.io.StdIn\nimport scala.io.StdIn.readLine\nobject problem {\n  def main(args: Array[String]) {\n    val Array(k, n, w) = readLine.split(\" \").map(_.toLong)\n    val s = (w * (w + 1) / 2) * k - n\n    if(s > 0 ) println(s) else println(0)\n  }\n}", "src_uid": "e87d9798107734a885fd8263e1431347"}
{"source_code": "import java.io._\nimport java.util.StringTokenizer\n\n/**\n  * @author Aydar Gizatullin a.k.a. lightning95 on 30.05.17.\n  */\n\nobject Main {\n\n  def main(args: Array[String]) {\n    val rw = new RW(\"input.txt\", \"output.txt\")\n    val n = rw nextInt\n    var beg = false\n    var mid = false\n    var end = false\n    var last = 0\n    var ok = true\n    for (_ <- 1 to n) {\n      val x = rw.nextInt\n      if (last < x) {\n        if (!mid && !end)\n          beg = true\n        else\n          ok = false\n      }\n      if (x == last) {\n        if (end)\n          ok = false\n        else\n          mid = true\n      }\n      if (last > x)\n        end = true\n\n      last = x\n    }\n\n    rw println (if (ok) \"YES\" else \"NO\")\n    rw.close()\n  }\n\n  class RW(val inputFile: String, val outputFile: String) {\n    private var br = new BufferedReader(new InputStreamReader(System.in))\n    private var out = new PrintWriter(new OutputStreamWriter(System.out))\n\n    private val f = new File(inputFile)\n    if (f.exists && f.canRead)\n      try {\n        br = new BufferedReader(new FileReader(inputFile))\n        out = new PrintWriter(new FileWriter(outputFile))\n      } catch {\n        case e: IOException =>\n          e.printStackTrace()\n      }\n\n    private var st = null: StringTokenizer\n    var eof = false\n\n    def nextLine: String = {\n      var s = \"\"\n      try\n        s = br.readLine()\n      catch {\n        case e: IOException =>\n          e.printStackTrace()\n      }\n      s\n    }\n\n    def next: String = {\n      while (st == null || !st.hasMoreTokens)\n        try\n          st = new StringTokenizer(br.readLine)\n        catch {\n          case _: IOException =>\n            eof = true\n            \"\"\n        }\n      st.nextToken\n    }\n\n    def nextLong: Long = next.toLong\n\n    def nextInt: Int = next.toInt\n\n    def println(): Unit = out.println()\n\n    def println(o: Any): Unit = out.println(o)\n\n    def print(o: Any): Unit = out.print(o)\n\n    def close(): Unit = {\n      try\n        br.close()\n      catch {\n        case e: IOException =>\n          e.printStackTrace()\n      }\n\n      out.close()\n    }\n  }\n\n}\n\n", "src_uid": "5482ed8ad02ac32d28c3888299bf3658"}
{"source_code": "\n\nobject EvenOdds {\n\tdef main (args: Array[String]) {\n\t\tval scanner = new java.util.Scanner(System.in);\n\t\tval n = scanner.nextLong();\n\t\tval k = scanner.nextLong();\n\t\tval midway = (n >> 1) + n%2\n\t\tif (k > midway) {\n\t\t  val offset = k - midway\n\t\t  println(offset << 1)\n\t\t}\n\t\telse {\n\t\t  println( ((k-1) << 1) + 1)\n\t\t}\n\t}\n}", "src_uid": "1f8056884db00ad8294a7cc0be75fe97"}
{"source_code": "//package round328.c\n\nimport java.util.Scanner\n\nimport scala.annotation.tailrec\n\nobject Main extends App {\n  val sc = new Scanner(System.in)\n\n  @tailrec\n  def gcd(a: BigInt, b: BigInt): BigInt = {\n    if (b == BigInt(0)) a else gcd(b, a % b)\n  }\n\n  val t = BigInt(sc.nextBigInteger())\n  val l1 = BigInt(sc.nextBigInteger())\n  val l2 = BigInt(sc.nextBigInteger())\n  val (w, b) = (l1 max l2, l1 min l2)\n\n  val nww = w * b / gcd(w, b)\n  val c = t / nww\n  val l = t % nww\n\n  val licznik = (c + 1) * b - 1 + (if (l < b) l + 1 - b else 0)\n\n  val d = gcd(licznik, t)\n\n  val (li, mi) = (licznik / d, t / d)\n\n  println(s\"$li/$mi\")\n\n}\n\n", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5"}
{"source_code": "import scala.io.StdIn\n\n/**\n * Created by dmitry on 04.02.17.\n */\nobject Main {\n  def main(args: Array[String]) {\n    val line: String = StdIn.readLine()\n    val digits: Array[String] = line.split(' ')\n    val n = digits(0).toInt\n    val m = digits(1).toInt\n    val z = digits(2).toInt\n    println((1 to z).toStream.count(i => i % n == 0 & i % m == 0))\n\n    /*val str = (1 to 100).toStream\n    val lst = str.filter(_ < 50).map(_ * 10).foreach(println(_))*/\n  }\n}", "src_uid": "e7ad55ce26fc8610639323af1de36c2d"}
{"source_code": "object Solution extends App {\n\n  val in = scala.io.Source.stdin.getLines()\n  val Array(a, b, c) = in.next().split(\" \").map(_.toLong)\n  val r = (1 to 81).flatMap{i =>\n    val f = b * Math.pow(i, a).toLong + c\n    if (f > 0 && f < 1000000000 && f.toString.map(_ - '0').sum == i) Some(f) else None\n  }\n  println(r.length)\n  println(r.mkString(\" \"))\n}", "src_uid": "e477185b94f93006d7ae84c8f0817009"}
{"source_code": "//package com.omar\nimport scala.io.StdIn._\n\nobject Bla{\n  def main(args: Array[String]): Unit = {\n    readInt()\n    val line = readLine()\n    val res = line.foldLeft(0)((re,x)=>(re,x) match {\n      case (y,'+') => y+1\n      case (0,'-') => 0\n      case (y,'-') => y-1\n      case _ => 0\n    })\n    println(res)\n\n  }\n}\n", "src_uid": "a593016e4992f695be7c7cd3c920d1ed"}
{"source_code": "import java.io.FileReader\nimport java.util\nimport java.util.Comparator\n\nimport collection.Searching._\nimport scala.collection.mutable\nimport scala.collection.mutable.ArrayBuffer\nimport scala.io.StdIn\n\nobject Solution {\n  //Console.setIn(new FileReader(new java.io.File(\"in\")))\n  //Console.setOut(new PrintStream(new java.io.File(\"output\")))\n  var caseNo = 1\n  val magicMod = 1000000007\n\n  def doCase() : Unit = {\n    val intervals = readIntLine().sorted\n    if ((intervals(0) == 2 && intervals(1) == 2) || (intervals.toSet.size == 1 && intervals(0) == 3) || (intervals.toSet contains 1) || (intervals(0) == 2 && intervals(1) == 4) && intervals(2) == 4) {\n      println(\"YES\")\n    } else {\n      println(\"NO\")\n    }\n  }\n\n  def main(args: Array[String]): Unit = {\n    val noCases = 1\n    for (i <- 0 until noCases) {\n      doCase()\n    }\n  }\n\n  def readIntLine(): Array[Int] = {\n    StdIn.readLine().split(\" \").map(_.toInt)\n  }\n\n  def readLongLine(): Array[Long] = {\n    StdIn.readLine().split(\" \").map(_.toLong)\n  }\n\n  def readBigIntLine(): Array[BigInt] = {\n    StdIn.readLine().split(\" \").map(BigInt.apply)\n  }\n}", "src_uid": "df48af9f5e68cb6efc1214f7138accf9"}
{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n  val in = Source.stdin.getLines()\n  val Array(r1, c1, r2, c2) = in.next().split(' ').map(_.toInt)\n  val dr = Math.abs(r1 - r2)\n  val dc = Math.abs(c1 - c2)\n  val rook = if (dr + dc == 0) 0 else if (r1 == r2 || c1 == c2) 1 else 2\n  val bishop = if ((dr + dc) % 2 == 1 || dr + dc == 0) 0 else if (dr == dc) 1 else 2\n  val king = Math.max(dr, dc)\n  println(s\"$rook $bishop $king\")\n}\n", "src_uid": "7dbf58806db185f0fe70c00b60973f4b"}
{"source_code": "object A13 {\n\n  import IO._\n  import collection.{mutable => cu}\n\n  def sumOfDigitsInBase(n1: Int, x: Int): Int = {\n    var res = 0\n    var n = n1\n    while(n > 0) {\n      res += (n%x)\n      n /= x\n    }\n    res\n  }\n\n  def gcd(a: Int, b: Int): Int = {\n    if(b == 0) a else gcd(b, a%b)\n  }\n\n\n  def main(args: Array[String]): Unit = {\n    val Array(n) = readInts(1)\n    val res = (2 until n).foldLeft(0)((sum, b) => sum+sumOfDigitsInBase(n, b))\n    val tot = n-2\n    println(s\"${res/gcd(res, tot)}/${tot/gcd(res, tot)}\")\n  }\n\n  object IO {\n    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n\n    @inline def read: String = input.readLine()\n\n    @inline def tokenizeLine = new java.util.StringTokenizer(read)\n\n    def readInt: Int = tokenizeLine.nextToken.toInt\n\n    def readInts(n: Int): Array[Int] = {\n      val tl = tokenizeLine\n      Array.fill(n)(tl.nextToken.toInt)\n    }\n\n    def readLongs(n: Int): Array[Long] = {\n      val tl = tokenizeLine\n      Array.fill(n)(tl.nextToken.toLong)\n    }\n\n    def readBigs(n: Int): Array[BigInt] = {\n      val tl = tokenizeLine\n      Array.fill(n)(BigInt(tl.nextToken))\n    }\n  }\n\n}\n", "src_uid": "1366732dddecba26db232d6ca8f35fdc"}
{"source_code": "object Main {\n  def main(args: Array[String]): Unit = {\n    val s = new Main()\n    s.solve()\n    s.out.flush()\n  }\n}\n\nclass Main {\n  import java.io._\n  import java.util.StringTokenizer\n\n  import scala.collection.mutable\n  import scala.util.Sorting\n  import math.{abs, max, min}\n  import mutable.{ArrayBuffer, ListBuffer}\n  import scala.reflect.ClassTag\n\n  val MOD = 1000000007\n  val out = new PrintWriter(System.out)\n\n  def solve(): Unit = {\n    val N = nl()\n    var h, w = 1\n    while(h.toLong * w < N) {\n      if (h < w) h += 1\n      else w += 1\n    }\n\n    out.println(h + w)\n  }\n\n  class InputReader(val stream: InputStream) {\n    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n    private var tokenizer: StringTokenizer = _\n\n    def next(): String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new StringTokenizer(reader.readLine)\n      tokenizer.nextToken\n    }\n\n    def nextInt(): Int = next().toInt\n    def nextLong(): Long = next().toLong\n    def nextChar(): Char = next().charAt(0)\n  }\n  val sc = new InputReader(System.in)\n  def ni(): Int = sc.nextInt()\n  def nl(): Long = sc.nextLong()\n  def nc(): Char = sc.nextChar()\n  def ns(): String = sc.next()\n  def ns(n: Int): Array[Char] = ns().toCharArray\n  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)\n  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {\n    val A1, A2 = Array.ofDim[Int](n)\n    REP(n) { i =>\n      A1(i) = ni() + offset\n      A2(i) = ni() + offset\n    }\n    (A1, A2)\n  }\n  def nm(n: Int, m: Int): Array[Array[Int]] = {\n    val A = Array.ofDim[Int](n, m)\n    REP(n) { i =>\n      REP(m) { j =>\n        A(i)(j) = ni()\n      }\n    }\n    A\n  }\n  def nal(n: Int): Array[Long] = map(n)(_ => nl())\n  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))\n  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = offset\n    val N = n + offset\n    while(i < N) { f(i); i += 1 }\n  }\n  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = n - 1 + offset\n    while(i >= offset) { f(i); i -= 1 }\n  }\n\n  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {\n    val res = Array.ofDim[A](n)\n    REP(n)(i => res(i) = f(i + offset))\n    res\n  }\n\n\n  def sumL(as: Array[Int]): Long = {\n    var s = 0L\n    REP(as.length)(i => s += as(i))\n    s\n  }\n\n  def cumSum(as: Array[Int]) = {\n    val cum = Array.ofDim[Int](as.length + 1)\n    REP(as.length) { i =>\n      cum(i + 1) = cum(i) + as(i)\n    }\n    cum\n  }\n}", "src_uid": "eb8212aec951f8f69b084446da73eaf7"}
{"source_code": "\n/**\n * @author pvasilyev\n * @since 16 Jun 2016\n */\nobject A437 extends App {\n\n  val problemA: String = scala.io.StdIn.readLine().split(\"\\\\.\")(1)\n  val problemB: String = scala.io.StdIn.readLine().split(\"\\\\.\")(1)\n  val problemC: String = scala.io.StdIn.readLine().split(\"\\\\.\")(1)\n  val problemD: String = scala.io.StdIn.readLine().split(\"\\\\.\")(1)\n  val problems = List((\"A\", problemA), (\"B\", problemB), (\"C\", problemC), (\"D\", problemD))\n  val sizes = problems.map(pair => (pair._1, pair._2.length))\n  val sortedAsc = sizes.sortWith(_._2 < _._2)\n  val sortedDesc = sizes.sortWith(_._2 >= _._2)\n\n  if (2 * sortedAsc(0)._2 <= sortedAsc(1)._2 && sortedDesc(0)._2 < 2 * sortedDesc(1)._2) {\n    println(sortedAsc(0)._1)\n  } else if (sortedDesc(0)._2 >= 2 * sortedDesc(1)._2 && 2 * sortedAsc(0)._2 > sortedAsc(1)._2) {\n    println(sortedDesc(0)._1)\n  } else {\n    println(\"C\")\n  }\n}\n", "src_uid": "30725e340dc07f552f0cce359af226a4"}
{"source_code": "object objecta {\n    import java.io.{BufferedReader, FileInputStream, InputStreamReader}\n\n    val source = System.in\n    //new FileInputStream(\"D://in.txt\")\n    implicit val reader = new BufferedReader(new InputStreamReader(source))\n    def readInt()(implicit reader: BufferedReader): Array[Int] = reader.readLine().split(\" \").map(_.toInt)\n    def readString()(implicit reader: BufferedReader): String = reader.readLine()\n\n    def main(args: Array[String]): Unit = {\n        val Array(n) = readInt()\n        val s = readString()\n\n        var result = n\n        for (i <- n / 2 until 0 by -1)\n            if (s.substring(0, i) == s.substring(i, 2*i)) {\n                println(i + 1 + n - 2*i)\n                return\n            }\n\n        println(result)\n    }\n}\n", "src_uid": "ed8725e4717c82fa7cfa56178057bca3"}
{"source_code": "object PashaandHamsters421A extends App {\n    import java.io.{InputStream, PrintStream}\n    import java.util.Scanner\n    solve(System.in,System.out)\n    def solve(in: InputStream, out: PrintStream): Unit = {\n        val scanner = new Scanner(in)\n      val n = scanner.nextInt()\n      val a = scanner.nextInt()\n      val b = scanner.nextInt()\n      val setA = (1 to a).map(_ => scanner.nextInt()).toSet\n      val setB = (1 to b).map(_ => scanner.nextInt()).toSet\n      val result = (1 to n).map{ i =>\n        if(setA.contains(i))\n          1\n        else\n          2\n      }.mkString(\" \")\n      out.println(result)\n    }\n}", "src_uid": "a35a27754c9c095c6f1b2d4adccbfe93"}
{"source_code": "import io.StdIn._\nimport scala.collection.mutable._\n\nobject Solution {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }\n\n  def main(args: Array[String]) {\n    val Array(x1, y1) = readInts(2)\n    val Array(x2, y2) = readInts(2)\n\n    println(Math.max(Math.abs(x1-x2), Math.abs(y1-y2)))\n\n//    Console.withOut(new java.io.BufferedOutputStream(Console.out))\n//    println(res.mkString(\"\\n\"))\n//    Console.flush\n  }\n}", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4"}
{"source_code": "object Main {\n  def main(args: Array[String]) {\n    val std = scala.io.StdIn\n    val n = std.readInt()\n    val s = std.readLine()\n\n    var res = \"no\"\n    for( step <- 1 to s.length / 4 ) {\n      for ( i <- 0 until step ) {\n        var ss = \"\"\n        for ( j <- i until s.length by step ) {\n          ss += s(j)\n        }\n\n        if ( ss.contains(\"*****\") ) {\n          res = \"yes\"\n        }\n      }\n    }\n    println( res )\n  }\n}", "src_uid": "12d451eb1b401a8f426287c4c6909e4b"}
{"source_code": "import java.util.Scanner\n\n\nobject CF353A {\n\n  def main(args: Array[String]) = {\n    val scn = new Scanner(System.in)\n\n    val (n, a, b, c, d) = (scn.nextInt, scn.nextInt, scn.nextInt, scn.nextInt, scn.nextInt)\n\n    val lst = List(a+b, a+c, b+d, c+d).sorted\n    val (xmin, xmax) = (lst.head, lst.last)\n\n    val result = math.max(0, n + xmin - 1 - xmax + 1) * n.toLong\n\n    println(result)\n  }\n\n}\n", "src_uid": "b732869015baf3dee5094c51a309e32c"}
{"source_code": "object Solution extends App {\n  val in = io.Source.stdin.getLines()\n  in.next()\n  println(in.next().replaceAll(\"o(go)+\", \"***\"))\n}", "src_uid": "619665bed79ecf77b083251fe6fe7eb3"}
{"source_code": "object A {\n  import InOut._\n  def main(args: Array[String]): Unit = {}\n\n  val MOD = 1000000007L\n  val n, m = nextInt\n\n  def fibonacci(n: Int): Long = {\n    var prev, cur = 1L\n    for (_ <- 1 until n) {\n      val tmp = cur\n      cur = (cur + prev) % MOD\n      prev = tmp\n    }\n    cur\n  }\n\n  val res = 2 * (fibonacci(n) + fibonacci(m) - 1) % MOD\n\n  out.println(res)\n  out.flush()\n\n  final object InOut {\n    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n    val out = new java.io.PrintWriter(System.out, false)\n    private[this] var tokenizer: java.util.StringTokenizer = _\n    def nextToken: String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new java.util.StringTokenizer(in.readLine)\n      tokenizer.nextToken\n    }\n    def nextInt = Integer.parseInt(nextToken)\n    def nextLong = java.lang.Long.parseLong(nextToken)\n    def nextBig = BigInt(nextToken)\n    def nextInts(n: Int) = Array.fill(n) { nextInt }\n    def nextLongs(n: Int) = Array.fill(n) { nextLong }\n    def nextBigs(n: Int) = Array.fill(n) { nextBig }\n    def nextLine = in.readLine\n  }\n}\n", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b"}
{"source_code": "import java.util.Scanner\n\n/**\n  * Created by aarav on 3/17/18.\n  */\nobject ChoosePlace {\n\n  def main(args: Array[String]) {\n    var values:Array[Array[Int]] = new Array[Array[Int]](6)\n\n    for (a <- 0 until 6) {\n      values(a) = new Array[Int](8)\n    }\n\n    values(0)(0) = 3\n    values(0)(1) = 3\n    values(0)(2) = 0\n    values(0)(3) = 4\n    values(0)(4) = 4\n    values(0)(5) = 0\n    values(0)(6) = 3\n    values(0)(7) = 3\n\n    values(1)(0) = 3\n    values(1)(1) = 3\n    values(1)(2) = 0\n    values(1)(3) = 4\n    values(1)(4) = 4\n    values(1)(5) = 0\n    values(1)(6) = 3\n    values(1)(7) = 3\n\n    values(2)(0) = 2\n    values(2)(1) = 2\n    values(2)(2) = 0\n    values(2)(3) = 3\n    values(2)(4) = 3\n    values(2)(5) = 0\n    values(2)(6) = 2\n    values(2)(7) = 2\n\n    values(3)(0) = 2\n    values(3)(1) = 2\n    values(3)(2) = 0\n    values(3)(3) = 3\n    values(3)(4) = 3\n    values(3)(5) = 0\n    values(3)(6) = 2\n    values(3)(7) = 2\n\n    values(4)(0) = 1\n    values(4)(1) = 1\n    values(4)(2) = 0\n    values(4)(3) = 2\n    values(4)(4) = 2\n    values(4)(5) = 0\n    values(4)(6) = 1\n    values(4)(7) = 1\n\n    values(5)(0) = 1\n    values(5)(1) = 1\n    values(5)(2) = 0\n    values(5)(3) = 2\n    values(5)(4) = 2\n    values(5)(5) = 0\n    values(5)(6) = 1\n    values(5)(7) = 1\n\n    /*for (i <- 0 to 5) {\n      for ( j <- 0 to 7) {\n        print(\" \" + values(i)(j));\n      }\n      println();\n    }*/\n\n    var charArr:Array[Array[Char]] = new Array[Array[Char]](6)\n    val s:Scanner = new Scanner(System.in);\n    for (i <- 0 to 5) {\n      charArr(i) = s.next().toCharArray\n    }\n\n    /*for (i <- 0 to 5) {\n      for ( j <- 0 to 7) {\n        print(\" \" + charArr(i)(j));\n      }\n      println();\n    }*/\n\n    var notChanged = true;\n    for (v <- 0 to 3) {\n      val lookingfor:Int = 4 - v\n      for (i <- 0 to 5) {\n        for (j <- 0 to 7) {\n          if (notChanged && charArr(i)(j) == '.' && values(i)(j) == lookingfor) {\n            charArr(i)(j) = 'P';\n            notChanged = false;\n          }\n        }\n      }\n    }\n\n    for (i <- 0 to 5) {\n      for ( j <- 0 to 7) {\n        print(charArr(i)(j));\n      }\n      println();\n    }\n\n  }\n\n}\n", "src_uid": "35503a2aeb18c8c1b3eda9de2c6ce33e"}
{"source_code": "import scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util._, control._\nimport scala.math.Ordering.Implicits._\n\nobject _602A extends CodeForcesApp {\n  override type Result = String\n\n  override def solve(scanner: Scanner) = {\n    import scanner._\n\n    def parse(): BigInt = {\n      val (n, b) = (nextInt(), nextBigInt())\n      Seq.tabulate(n)(i => nextInt() * (b pow (n-i-1))).sum\n    }\n\n    val (x, y) = (parse(), parse())\n    (x - y).signum match {\n      case -1 => \"<\"\n      case 1 => \">\"\n      case _ => \"=\"\n    }\n  }\n}\n/****************************[Ignore Template Below]****************************************/\nabstract class CodeForcesApp {\n  final val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)\n  final val mod: Int = 1000000007\n  type Result\n  def solve(scanner: Scanner): Result\n  def format(result: Result): String = result.toString\n  def apply(scanner: Scanner): String = format(solve(scanner))\n  def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))\n}\n/*********************************[Scala Scanner]*******************************************/\nimport java.io._\nimport java.nio.file.{Files, Path}\nimport java.util.StringTokenizer\n\nimport scala.io.Codec\n\n/**\n * Scala implementation of a faster java.util.Scanner\n * See: http://codeforces.com/blog/entry/21125\n * All next methods throw NoSuchElementException when !hasNext\n */\nclass Scanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {\n  def this(reader: BufferedReader) = this(new LineNumberReader(reader))\n  def this(reader: Reader) = this(new BufferedReader(reader))\n  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))\n  def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))\n  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)\n  def this(str: String) = this(new StringReader(str))\n\n  val lines = Iterator.continually(reader.readLine()).takeWhile(_ != null) //TODO: In Java 8 reader.lines().iterator\n\n  private[this] val tokenizers = lines.map(new StringTokenizer(_)).filter(_.hasMoreTokens)\n  private[this] var current: Option[StringTokenizer] = None\n\n  @inline private[this] def tokenizer(): Option[StringTokenizer] = current.find(_.hasMoreTokens) orElse {\n    current = if (tokenizers.hasNext) Some(tokenizers.next()) else None\n    current\n  }\n\n  /**\n   * Unlike Java's scanner which returns till end of current line, this actually returns the next line\n   * @see line() if you want the Java behaviour\n   */\n  def nextLine(): String = {\n    current = None   // reset\n    lines.next()\n  }\n  def lineNumber: Int = reader.getLineNumber\n  def line(): String = tokenizer().get.nextToken(\"\\n\\r\")\n  def nextString(): String = next()\n  def nextChar(): Char = next().ensuring(_.length == 1).head\n  def nextBoolean(): Boolean = next().toBoolean\n  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)\n  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)\n  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)\n  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)\n  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)\n  def nextFloat(): Float = next().toFloat\n  def nextDouble(): Double = next().toDouble\n  def nextBigDecimal(): BigDecimal = BigDecimal(next())\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n  override def close() = reader.close()\n}\n", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67"}
{"source_code": "import scala.io.StdIn._\n/**\n * Created by omarsaber on 10/12/16.\n */\nobject A extends App {\n  val Array(a, b, c) = (readLine split \" \") map (_.toInt)\n  val homes = Seq(a, b, c).sorted\n  println((homes(2) - homes(1)) + (homes(1) - homes(0)))\n}\n", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319"}
{"source_code": "object B extends App {\n  def readLongs = scala.io.StdIn.readLine().split(\" \").map(_.toLong)\n\n  val Array(n) = readLongs\n\n  def isPrime(x: Long): Boolean = {\n    for (i <- 2 to Math.sqrt(n.toDouble).floor.toInt) {\n      if (x % i == 0) return false\n    }\n    true\n  }\n\n  if (isPrime(n)) println(1) else\n    if (n % 2 == 0) println(2) else\n    if (isPrime(n-2)) println(2) else\n    println(3)\n}\n", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b"}
{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n  val in = Source.stdin.getLines()\n  val n = in.next().toLong\n  var m = 0l\n  var i = 1l\n  while (m + i < n) {\n    m += i\n    i += 1\n  }\n  println(n - m)\n\n}", "src_uid": "1db5631847085815461c617854b08ee5"}
{"source_code": "object EightPointSets {\n  case class Point(x: Int, y: Int)\n\n  def main(args: Array[String]): Unit = {\n    val lines = for(i <- 1 to 8) yield(readLine())\n    // val lines = List(\"0 0\", \"0 1\", \"0 2\", \"1 0\", \"1 2\", \"2 0\", \"2 1\",\"2 2\")\n    // val lines = List(\"0 0\", \"2 1\", \"1 0\", \"0 2\", \"2 2\", \"1 0\", \"2 1\", \"0 2\")\n    val res = if (isRespectable(lines)) {\n      \"respectable\"\n    } else \"ugly\"\n\n    println(res)\n  }\n\n  def isRespectable(lines: Seq[String]): Boolean = {\n    val points = Set.empty[Point] ++ lines.map(_.split(\" \")).map(a => Point(a(0).toInt, a(1).toInt))\n\n    val x = Set.empty[Int] ++ points.map(_.x)\n    val y = Set.empty[Int] ++ points.map(_.y)\n\n    if (x.size != 3 || y.size != 3 || points.size != 8) false\n    else {\n      val sortedX = x.toList.sorted\n      val sortedY = y.toList.sorted\n      val point2 = Point(sortedX(1), sortedY(1))\n      !points.contains(point2)\n    }\n  }\n}", "src_uid": "f3c96123334534056f26b96f90886807"}
{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n  val in = Source.stdin.getLines()\n  val str1 = in.next()\n  val str2 = in.next()\n  val count = str1.count(_ == '0')\n  val count2 = str2.count(_ == '0')\n  val sorted = str1.filter(_ != '0').sorted\n  if (str1.length != str2.length || (str2.head == '0' && str2.length > 1) || count != count2)\n    println(\"WRONG_ANSWER\")\n  else if (str1 == str2 && str1 == \"0\")\n    println(\"OK\")\n  else {\n    val res = sorted.head + \"0\" * count + sorted.tail\n    if (res == str2)\n      println(\"OK\")\n    else\n      println(\"WRONG_ANSWER\")\n  }\n}", "src_uid": "d1e381b72a6c09a0723cfe72c0917372"}
{"source_code": "object C {\n  def split(x: Array[Int], s: Int) = {\n    val it = x.toIterator.buffered\n    var cur = 0\n    var ans = true\n    var count = 0\n    while (it.hasNext) {\n      if (cur + it.head < s) {\n        cur += it.next()\n      } else if (cur + it.head == s) {\n        cur = 0\n        it.next()\n        count += 1\n      } else {\n        ans = false\n        it.next()\n      }\n    }\n    ans && cur == 0 && count > 1\n  }\n\n  def main(args: Array[String]) = {\n    val _ = scala.io.StdIn.readLine().split(\" \")\n    val x = scala.io.StdIn.readLine().toCharArray.map(_.toString.toInt)\n    if (!x.exists(_ > 0)) {\n      System.out.println(\"YES\")\n    } else if ((1 until 900).exists {sum =>split(x, sum)}) {\n      System.out.println(\"YES\")\n    } else {\n      System.out.println(\"NO\")\n    }\n\n  }\n\n\n}\n", "src_uid": "410296a01b97a0a39b6683569c84d56c"}
{"source_code": "import scala.io.StdIn._\n\nobject B940 {\n  def main(args: Array[String]): Unit = {\n    var IndexedSeq(n, k, a, b) = for (i <- 0 until 4) yield readLong()\n    var res = 0L\n    if (k == 1) {\n      println((n - 1L) * a)\n      return\n    }\n    while (n != 1) {\n      if (n % k == 0) {\n        val t = n / k\n        if ((n - t) * a < b) {\n          res += (n - t) * a\n          n = t\n        } else {\n          res += b\n          n /= k\n        }\n      } else {\n        val t = math.max((n / k) * k, 1)\n        res += (n - t) * a\n        n = t\n      }\n    }\n    println(res)\n  }\n}\n", "src_uid": "f838fae7c98bf51cfa0b9bd158650b10"}
{"source_code": "import java.util.Scanner\n\nobject Main{\n  def main (args: Array[String]){\n    val sc = new Scanner(System.in)\n    val n = sc.nextInt()\n\n    val line = 40000\n    var pos = 0\n    var flag = true\n\n    for(k <- 1 to n){\n      // norm pos\n      pos = pos % line\n      if(pos < 0)\n        pos = line + pos\n      if(pos > line / 2)\n        pos = line - pos\n\n      val t = sc.nextInt(); val dir = sc.next()\n\n      if((dir == \"East\" || dir == \"West\") && (pos == 0 || pos == line / 2))\n        flag = false\n      else if(dir == \"East\" || dir == \"West\")\n        ()\n      else{ // dir is north or south\n        if(pos == 0){\n          if(dir == \"North\")\n            flag = false\n          else{\n            if(pos + t > line / 2)\n              flag = false\n            pos += t\n          }\n        }\n        else if(pos == line / 2){\n          if(dir == \"South\")\n            flag = false\n          else{\n            if(pos - t < 0)\n              flag = false\n            pos -= t\n          }\n        }\n        else{\n          if(dir == \"North\"){\n            if(pos - t < 0)\n              flag = false\n            pos -= t\n          }\n          else{\n            if(pos + t > line / 2)\n              flag = false\n            pos += t\n          }\n        }\n      }\n    }\n\n    // norm pos\n    pos = pos % line\n    if(pos < 0)\n      pos = line + pos\n    if(pos > line / 2)\n      pos = line - pos\n\n    if(flag){\n      if(pos == 0)\n        println(\"YES\")\n      else\n        println(\"NO\")\n    }\n    else\n      println(\"NO\")\n  }\n}\n", "src_uid": "11ac96a9daa97ae1900f123be921e517"}
{"source_code": "import java.io._\nimport java.util.StringTokenizer\n\nimport scala.annotation.tailrec\n\n/**\n  * Created by amir.\n  */\n\nobject A extends App {\n\n  class RW(val inputFile: String, val outputFile: String) {\n    private var br = new BufferedReader(new InputStreamReader(System.in))\n    private var out = new PrintWriter(new OutputStreamWriter(System.out))\n\n    /* val f = new File(inputFile)\n    if (f.exists && f.canRead)\n    try {\n    br = new BufferedReader(new FileReader(f))\n    out = new PrintWriter(new FileWriter(outputFile))\n    } catch {\n    case e: IOException =>\n    e.printStackTrace()\n    }*/\n\n    private var st: StringTokenizer = _\n    var eof = false\n\n    def nextLine: String = {\n      var s = \"\"\n      try\n        s = br.readLine()\n      catch {\n        case e: IOException =>\n          e.printStackTrace()\n      }\n      s\n    }\n\n    def next: String = {\n      while (st == null || !st.hasMoreTokens)\n        try\n          st = new StringTokenizer(br.readLine)\n        catch {\n          case _: IOException =>\n            eof = true\n            \"\"\n        }\n      st.nextToken\n    }\n\n    def nextLong: Long = next.toLong\n\n    def nextInt: Int = next.toInt\n\n    def println(): Unit = out.println()\n\n    def println(o: Any): Unit = out.println(o)\n\n    def print(o: Any): Unit = out.print(o)\n\n    def close(): Unit = {\n      try {\n        br.close()\n      } catch {\n        case e: IOException =>\n          e.printStackTrace()\n      }\n\n      out.close()\n    }\n  }\n\n\n  override def main(args: Array[String]) {\n    val rw = new RW(\"input.txt\", \"output.txt\")\n\n    @tailrec def sum(x: Int, s: Int): Int = x match {\n      case 0 => s\n      case _ => sum(x / 10, s + x % 10)\n    }\n\n    val r = 7792\n    val n = rw.nextInt\n    if (n <= r) {\n      val ans = for (i <- (1 until 6000000).toStream if sum(i, 0) == 10) yield i\n      rw.println(ans(n - 1))\n    } else {\n      val ans = for (i <- (6000000 to 12000000).toStream if sum(i, 0) == 10) yield i\n      rw.println(ans(n - r - 1))\n    }\n    rw.close()\n  }\n}", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a"}
{"source_code": "import scala.io.StdIn\n\nobject Codeforces1186A extends App {\n  val Array(n, m, k) = StdIn.readLine().split(\"\\\\s+\").map(a => a.toInt)\n  println(if (n <= m && n <= k) \"Yes\" else \"No\")\n}\n", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4"}
{"source_code": "object _979A extends CodeForcesApp {\n  import annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._, Math._\n\n  override def apply(io: IO): io.type = {\n    val n = io.read[Long] + 1\n    val ans = if (n%2 == 0) n/2 else if (n == 1) 0 else n\n    io.write(ans)\n  }\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n  lazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)\n  def apply(io: IO): io.type\n  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()\n}\n/***********************************[Scala I/O]*********************************************/\nimport java.io._, java.util.StringTokenizer\nimport scala.collection.generic.CanBuild\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {\n  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n  val printer = new PrintWriter(out, true)\n\n  @inline private[this] def tokenizer() = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    tokenizers.headOption\n  }\n\n  def read[A](implicit read: IO.Read[A]): A = read.apply(this)\n  def read[C[_], A: IO.Read](n: Int)(implicit b: CanBuild[A, C[A]]): C[A] = Iterator.fill(n)(read).to[C]\n\n  def readTill(delim: String): String = tokenizer().get.nextToken(delim)\n  def readTillEndOfLine(): String = readTill(\"\\n\\r\")\n\n  def readAll[A: IO.Read]: (Int, Vector[A]) = {\n    val data = read[Vector[A]]\n    (data.length, data)\n  }\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n\n  def write(obj: Any): this.type = {\n    printer.print(obj)\n    this\n  }\n  def writeLine(): this.type = {\n    printer.println()\n    this\n  }\n  def writeLine(obj: Any): this.type = {\n    printer.println(obj)\n    this\n  }\n  def writeAll(obj: Traversable[Any], separator: String = \" \"): this.type = write(obj mkString separator)\n  def query[A: IO.Read](question: Any): A = writeLine(question).read\n\n  override def flush() = printer.flush()\n  def close() = {\n    flush()\n    in.close()\n    printer.close()\n  }\n}\nobject IO {\n  class Read[A](val apply: IO => A) {\n    def map[B](f: A => B): Read[B] = new Read(apply andThen f)\n  }\n\n  object Read {\n    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]))\n    implicit val string                                                   : Read[String]       = new Read(_.next())\n    implicit val int                                                      : Read[Int]          = string.map(_.toInt)\n    implicit val long                                                     : Read[Long]         = string.map(_.toLong)\n    implicit val bigInt                                                   : Read[BigInt]       = string.map(BigInt(_))\n    implicit val double                                                   : Read[Double]       = string.map(_.toDouble)\n    implicit val bigDecimal                                               : Read[BigDecimal]   = string.map(BigDecimal(_))\n    implicit def tuple2[A: Read, B: Read]                                 : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))\n    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]))\n    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]))\n    implicit val boolean                                                  : Read[Boolean]      = string map {s =>\n      s.toLowerCase match {\n        case \"yes\" | \"true\" | \"1\" => true\n        case \"no\" | \"false\" | \"0\" => false\n        case _ => s.toBoolean\n      }\n    }\n  }\n}\n\n", "src_uid": "236177ff30dafe68295b5d33dc501828"}
{"source_code": "object tanya extends App{\nvar nums = readLine().split(\" \")\nval frs = nums(0).toInt\nval sc = nums(1).toInt\nval th = nums(2).toInt\nval fr = nums(3).toInt\n\nif(frs + sc == th + fr){\n    println(\"YES\")\n}else if(frs + th == sc + fr){\n    println(\"YES\")\n}else if(frs + fr == th + sc){\n    println(\"YES\")\n}else if(frs + sc + th == fr){\n    println(\"YES\")\n}else if(frs + th + fr == sc){\n    println(\"YES\")\n}else if(frs + sc + fr == th){\n    println(\"YES\")\n}else if(sc + th + fr == frs){\n    println(\"YES\")\n}else{\n    println(\"NO\")\n}\n}", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37"}
{"source_code": "object Solution extends App {\n  val in = io.Source.stdin.getLines()\n  val field = (1 to 4).map { _ => in.next()}\n\n  def isX(column: Int, row: Int) = {\n    column >= 0 && column < 4 && row >= 0 && row < 4 && field(column)(row) == 'x'\n  }\n\n\n  def isGood(column: Int, row: Int): Boolean = field(column)(row) match {\n    case '.' =>\n      (isX(column, row - 1) && isX(column, row - 2)) || // horizontal to left\n      (isX(column, row + 1) && isX(column, row + 2)) || // horizontal to right\n      (isX(column, row + 1) && isX(column, row - 1)) || // horizontal central\n      (isX(column - 1, row) && isX(column - 2, row)) || // vertical to left\n      (isX(column + 1, row) && isX(column + 2, row)) || // vertical to right\n      (isX(column + 1, row) && isX(column - 1, row)) || // vertical central\n      (isX(column + 1, row + 1) && isX(column - 1, row - 1)) || // diagonal central\n      (isX(column + 1, row - 1) && isX(column - 1, row + 1)) || // diagonal central\n      (isX(column + 1, row + 1) && isX(column + 2, row + 2)) || // diagonal\n      (isX(column - 1, row - 1) && isX(column - 2, row - 2)) || // diagonal\n      (isX(column - 1, row + 1) && isX(column - 2, row + 2)) || // diagonal\n      (isX(column + 1, row - 1) && isX(column + 2, row - 2)) // diagonal\n\n    case _ => false\n  }\n\n  val res = (0 until 4).exists {c =>\n    (0 until 4).exists {\n      r => isGood(c, r)\n    }\n  }\n\n  if (res)\n    println(\"YES\")\n  else\n    println(\"NO\")\n\n\n}", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917"}
{"source_code": "object A675 {\n  @inline def read = scala.io.StdIn.readLine\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(read)\n\n  def readInts(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)\n  }\n\n  def readLongs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong)\n  }\n\n  def readBigs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken))\n  }\n\n  def main(args: Array[String]): Unit = {\n    val Array(a, b, c) = readLongs(3)\n    if(c == 0) {\n      if(a == b) {\n        println(\"YES\")\n      } else {\n        println(\"NO\")\n      }\n    } else if((b-a)%c == 0) {\n      val n = (b-a)/c +1\n      if(n > 0) {\n        println(\"YES\")\n      } else {\n        println(\"NO\")\n      }\n    } else {\n      println(\"NO\")\n    }\n  }\n}", "src_uid": "9edf42c20ddf22a251b84553d7305a7d"}
{"source_code": "import scala.collection._\n\nobject A extends App {\n\n  def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toInt) }\n  def readLongs(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toLong) }\n  def readBigs(n: Int) = { val t = tokenizeLine; Array.fill(n)(BigInt(t.nextToken)) }\n\n  val Array(n, m, i, j, a, b) = readInts(6)\n\n  val x1 = i - 1\n  val y1 = j - 1\n  val x2 = n - i\n  val y2 = m - j\n\n  val stepsX1 = if (x1 % a == 0) x1 / a else -1\n  val stepsX2 = if (x2 % a == 0) x2 / a else -1\n  val stepsY1 = if (y1 % b == 0) y1 / b else -1\n  val stepsY2 = if (y2 % b == 0) y2 / b else -1\n  val steps11 = if (stepsX1 >= 0 && stepsY1 >= 0 && stepsX1 % 2 == stepsY1 % 2) Math.max(stepsX1, stepsY1) else Int.MaxValue\n  val steps12 = if (stepsX1 >= 0 && stepsY2 >= 0 && stepsX1 % 2 == stepsY2 % 2) Math.max(stepsX1, stepsY2) else Int.MaxValue\n  val steps21 = if (stepsX2 >= 0 && stepsY1 >= 0 && stepsX2 % 2 == stepsY1 % 2) Math.max(stepsX2, stepsY1) else Int.MaxValue\n  val steps22 = if (stepsX2 >= 0 && stepsY2 >= 0 && stepsX2 % 2 == stepsY2 % 2) Math.max(stepsX2, stepsY2) else Int.MaxValue\n  val steps = Seq(steps11, steps12, steps21, steps22).min\n  if (steps == Int.MaxValue || (steps > 0 && ((i - a < 1 && i + a > n) || (j - b < 1 && j + b > m)))) println(\"Poor Inna and pony!\")\n  else println(steps)\n}", "src_uid": "51155e9bfa90e0ff29d049cedc3e1862"}
{"source_code": "object CF912B extends App {\n  val sc = new java.util.Scanner(System.in)\n  val n, k = sc.nextLong\n\n  println(find(n, k))\n\n  def find(n: Long, k: Long): Long = {\n    val nn = n.toBinaryString.length\n    val tmpmax = Math.pow(2, nn).toLong - 1\n    if (k > 1) tmpmax else n\n  }\n}\n", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9"}
{"source_code": "import scala.collection.mutable\n\nobject Main1 {\n\n  def count(s: String): Int = {\n    var acount = 0\n    for (ch <- s) {\n      if ('a' == ch) {\n        acount = acount + 1\n      }\n    }\n\n    Array(acount * 2 - 1, s.length).min\n  }\n\n  def main(args: Array[String]) {\n\n    val stdin = scala.io.StdIn\n\n    val s = stdin.readLine.trim\n\n    println(count(s))\n  }\n}\n", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219"}
{"source_code": "import java.io._\nimport java.util._\n\nimport scala.collection.mutable\n\nobject B {\n\n  var out: PrintWriter = null\n  var br: BufferedReader = null\n  var st: StringTokenizer = null\n\n  def main(args: Array[String]): Unit = {\n    br = new BufferedReader(new InputStreamReader(System.in))\n    out = new PrintWriter(new BufferedOutputStream(System.out))\n    solve\n    out.close\n  }\n\n  def next: String = {\n    while (st == null || !st.hasMoreTokens) {\n      st = new StringTokenizer(br.readLine)\n    }\n    return st.nextToken\n  }\n\n  def nextInt: Int = return Integer.parseInt(next)\n\n  def nextLong: Long = return java.lang.Long.parseLong(next)\n\n  def nextDouble: Double = return java.lang.Double.parseDouble(next)\n\n  class MultiHashSet[T <% Comparable[T]] {\n    val map = new mutable.HashMap[T, Int]()\n\n    def count(x: T): Int = {\n      return map.getOrElse(x, 0)\n    }\n\n    def add(x: T): Unit = map.put(x, count(x) + 1)\n\n    def remove(x: T): Boolean = {\n      val prev = count(x)\n      if (prev == 0)\n        return false\n      if (prev == 1) {\n        map.remove(x)\n      } else {\n        map.put(x, prev - 1)\n      }\n      return true\n    }\n  }\n\n  class MultiTreeSet[T <% Comparable[T]] {\n    val map = new TreeMap[T, Int]()\n\n    def count(x: T): Int = {\n      val res = map.get(x)\n      if (res == null)\n        return 0\n      return res\n    }\n\n    def add(x: T): Unit = map.put(x, count(x) + 1)\n\n    def first(): T = return map.firstKey()\n\n    def last(): T = return map.lastKey()\n\n    def remove(x: T): Boolean = {\n      val prev = count(x)\n      if (prev == 0)\n        return false\n      if (prev == 1) {\n        map.remove(x)\n      } else {\n        map.put(x, prev - 1)\n      }\n      return true\n    }\n  }\n\n  /**\n   * Segment tree for any commutative function\n   * @param values Array of Int\n   * @param commutative function like min, max, sum\n   * @param zero zero value - e.g. 0 for sum, Inf for min, max\n   */\n  class SegmentTree(values: Array[Int])(commutative: (Int, Int) => Int)(zero: Int) {\n    private val SIZE = 1e5.toInt\n    private val n = values.length\n    val t = new Array[Int](2 * n)\n    Array.copy(values, 0, t, n, n)\n\n    // build segment tree\n    def build = {\n      for (i <- n - 1 until 0 by -1) {\n        t(i) = commutative(t(2 * i), t(2 * i + 1))\n      }\n    }\n\n    // change value at position p to x\n    // TODO beatify\n    def modify(p: Int, x: Int) = {\n      var pos = p + n\n      t(pos) = x\n      while (pos > 1) {\n        t(pos / 2) = commutative(t(pos), t(pos ^ 1))\n        pos /= 2\n      }\n    }\n\n    // TODO implement me!\n    def modify(p: Int, left: Int, right: Int) = ???\n\n    def query(p: Int) = ???\n\n    // sum [l, r)\n    // min l = 0\n    // max r = n\n    // TODO beatify\n    def query(left: Int, right: Int): Int = {\n      var res = zero\n      var r = right + n\n      var l = left + n\n      while (l < r) {\n        if (l % 2 == 1) {\n          res = commutative(res, t(l))\n          l += 1\n        }\n        if (r % 2 == 1) {\n          r -= 1\n          res = commutative(res, t(r))\n        }\n        l /= 2\n        r /= 2\n      }\n      res\n    }\n  }\n\n  def solve: Int = {\n    val str = next\n    val n = str.length\n    val k = nextInt\n    var ans = 0\n    for {\n      i <- 0 until n + k\n      j <- 2 to n + k by 2\n    } yield {\n      if (i + j <= n + k) {\n        var ind = i\n        while (ind < i + j / 2) {\n          if (ind < n && ind + j / 2 < n) {\n            if (str(ind) != str(ind + j / 2)) {\n              ind = 10000\n            }\n          }\n          ind += 1\n        }\n        if (ind == i + j / 2) {\n          ans = Math.max(ans, j)\n        }\n      }\n    }\n    out.println(ans)\n    return 0\n  }\n}\n", "src_uid": "bb65667b65ff069a9c0c9e8fe31da8ab"}
{"source_code": "import java.util.Scanner\n\nobject div64 extends App {\n  val sc = new Scanner(System.in)\n  val s = sc.next().toCharArray()\n  val can = s.dropWhile(ch => ch == '0').count(ch => ch == '0') >= 6\n  println(if (can) \"yes\" else \"no\")\n}\n", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca"}
{"source_code": "object _1130A extends CodeForcesApp {\n  import annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._, Math._\n\n  override def apply(io: IO): io.type = {\n    val (n, nums) = io.readAll[Int]\n    val ans = (-1000 to 1000).filter(_ != 0).find({d => nums.count(i => i/d > 0) >= (n+1)/2})\n    io.write(ans.getOrElse(0))\n  }\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n  lazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)\n  def apply(io: IO): io.type\n  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()\n}\n/***********************************[Scala I/O]*********************************************/\nimport java.io._, java.util.StringTokenizer\nimport scala.collection.generic.CanBuild\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {\n  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n  val printer = new PrintWriter(out, true)\n\n  @inline private[this] def tokenizer() = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    tokenizers.headOption\n  }\n\n  def read[A](implicit read: IO.Read[A]): A = read.apply(this)\n  def read[C[_], A: IO.Read](n: Int)(implicit b: CanBuild[A, C[A]]): C[A] = Iterator.fill(n)(read).to[C]\n\n  def readTill(delim: String): String = tokenizer().get.nextToken(delim)\n  def readTillEndOfLine(): String = readTill(\"\\n\\r\")\n\n  def readAll[A: IO.Read]: (Int, Vector[A]) = {\n    val data = read[Vector[A]]\n    (data.length, data)\n  }\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n\n  def write(obj: Any): this.type = {\n    printer.print(obj)\n    this\n  }\n  def writeLine(): this.type = {\n    printer.println()\n    this\n  }\n  def writeLine(obj: Any): this.type = {\n    printer.println(obj)\n    this\n  }\n  def writeAll(obj: Traversable[Any], separator: String = \" \"): this.type = write(obj mkString separator)\n  def query[A: IO.Read](question: Any): A = writeLine(question).read\n\n  override def flush() = printer.flush()\n  def close() = {\n    flush()\n    in.close()\n    printer.close()\n  }\n}\nobject IO {\n  class Read[A](val apply: IO => A) {\n    def map[B](f: A => B): Read[B] = new Read(apply andThen f)\n  }\n\n  object Read {\n    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]))\n    implicit val string                                                   : Read[String]       = new Read(_.next())\n    implicit val int                                                      : Read[Int]          = string.map(_.toInt)\n    implicit val long                                                     : Read[Long]         = string.map(_.toLong)\n    implicit val bigInt                                                   : Read[BigInt]       = string.map(BigInt(_))\n    implicit val double                                                   : Read[Double]       = string.map(_.toDouble)\n    implicit val bigDecimal                                               : Read[BigDecimal]   = string.map(BigDecimal(_))\n    implicit def tuple2[A: Read, B: Read]                                 : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))\n    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]))\n    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]))\n    implicit val boolean                                                  : Read[Boolean]      = string map {s =>\n      s.toLowerCase match {\n        case \"yes\" | \"true\" | \"1\" => true\n        case \"no\" | \"false\" | \"0\" => false\n        case _ => s.toBoolean\n      }\n    }\n  }\n}\n\n", "src_uid": "a13cb35197f896cd34614c6c0b369a49"}
{"source_code": "import scala.io.StdIn._\n\nobject C extends App {\n  val n = readInt()\n  val P1 = readLine().split(\" \").map(_.toInt).drop(1).toList\n  val P2 = readLine().split(\" \").map(_.toInt).drop(1).toList\n\n  def solve(): Unit = {\n    var counter = 0\n    var player1 = scala.collection.mutable.ListBuffer(P1:_*)\n    var player2 = scala.collection.mutable.ListBuffer(P2:_*)\n\n    while (player1.nonEmpty && player2.nonEmpty) {\n      counter += 1\n\n      val c1 = player1.head\n      player1 = player1.tail\n      val c2 = player2.head\n      player2 = player2.tail\n      if (c1 > c2) {\n        player1 += c2\n        player1 += c1\n      } else {\n        player2 += c1\n        player2 += c2\n      }\n\n      if (counter > 1000000) {\n//       if (player1.diff(P1).isEmpty && player2.diff(P2).isEmpty) {\n         println(-1)\n         return\n       }\n    }\n\n    println(counter + \" \" + (if (player2.isEmpty) 1 else 2))\n  }\n\n  solve()\n}\n", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e"}
{"source_code": "/**\n * Created by ashione on 14-6-17.\n */\nimport java.util.Scanner\nobject tt {\n\n    def main(args:Array[String])= {\n\n      val sn = new Scanner(System.in)\n      val n = sn.nextInt\n      val total = sn.nextInt\n      var s:List[Int] = List[Int]()\n      for (i <- 1 to n) {\n        val t:List[Int] = List[Int](sn.nextInt)\n        s = s:::t\n      }\n\n      println(getBus(s, total, total))\n    }\n      def getBus(xs:List[Int],space:Int,total:Int):Int = {\n        if (xs.isEmpty == true) {\n          if (space > 0) 1 else 0\n        }\n        else {\n          (space - xs.head) match {\n            case 0 =>1 + { if(xs.tail.isEmpty==true) 0 else getBus (xs.tail, total, total) }\n            case x if x > 0 => getBus(xs.tail, x, total)\n            case x if x < 0 => 1+getBus(xs, total, total)\n          }\n        }\n      }\n\n\n }\n\n\n", "src_uid": "5c73d6e3770dff034d210cdd572ccf0f"}
{"source_code": "import scala.io.StdIn._\n\nobject A extends App {\n  val Board = Array.ofDim[Int](8, 8)\n\n  for (i <- 0 until 8) {\n    val line = readLine().toCharArray\n    for (j <- 0 until 8) Board(i)(j) = line(j)\n  }\n\n  def getTheClosestPawnPos(col: Int): (Int, Int) = {\n    var blackIdx = -1\n    var whiteIdx = -1\n    for (i <- 0 until 8) {\n      if (Board(i)(col) == 'W' && whiteIdx == -1) {\n        var hasBlack = false\n        for (j <- 0 until i) {\n          if (Board(j)(col) == 'B') hasBlack = true\n        }\n        if (!hasBlack) {\n          whiteIdx = i\n        }\n      } else if (Board(i)(col) == 'B') {\n        var hasWhite = false\n        for (j <- i + 1 until 8) {\n          if (Board(j)(col) == 'W') hasWhite = true\n        }\n        if (!hasWhite) {\n          blackIdx = i\n        }\n      }\n    }\n\n    (whiteIdx, if (blackIdx != -1) 8 - blackIdx - 1 else -1)\n  }\n\n  var minWhiteMovesToWin = Integer.MAX_VALUE\n  var minBlackMovesToWin = Integer.MAX_VALUE\n\n  for (i <- 0 until 8) {\n    val (w, b) = getTheClosestPawnPos(i)\n    if (w != -1) minWhiteMovesToWin = Math.min(minWhiteMovesToWin, w)\n    if (b != -1) minBlackMovesToWin = Math.min(minBlackMovesToWin, b)\n\n//    println(w + \" \" + b + \" \" + minWhiteMovesToWin  + \" \" + minBlackMovesToWin)\n  }\n\n  if (minWhiteMovesToWin <= minBlackMovesToWin) println(\"A\") else println(\"B\")\n}\n", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd"}
{"source_code": "object Main extends App {\n  val Array(a,b,c,d) = readLine.split(\" \").map(_.toInt)\n  def code(time: Int, p: Int): Int = List(3*p/10, p-(p*time/250)).max\n  val ac = code(c, a)\n  val bd = code(d, b)\n  if(ac > bd) println(\"Misha\")\n  else if (ac == bd) println(\"Tie\")\n  else println(\"Vasya\")\n}", "src_uid": "95b19d7569d6b70bd97d46a8541060d0"}
{"source_code": "/**\n  * Created by netman on 3/4/17.\n  */\nobject Main {\n  def main(args: Array[String]): Unit = {\n    val lines = io.Source.fromInputStream(System.in).getLines().toArray\n    val n = lines(0).toInt\n    val arr = lines(1).split(\" \").map(_.toInt)\n    println((arr.max + arr.min) / 2)\n  }\n}\n", "src_uid": "f03773118cca29ff8d5b4281d39e7c63"}
{"source_code": "import scala.io.StdIn\n\nobject DiceRolling extends App {\n\n  val t = StdIn.readLine().toInt\n\n  for {\n    _ <- 1 to t\n  } println(findSol(StdIn.readLine().toInt))\n\n  def findSol(x: Int) = {\n    math.ceil(x / 7.0).toInt\n  }\n}\n", "src_uid": "a661b6ce166fe4b2bbfd0ace56a7dc2c"}
{"source_code": "object duplRemove extends App{\nvar times = readLine()\nvar list = readLine().split(\" \").toList.reverse\n\ndef removeDupl[T](list: List[T]): List[T] = {\n    def inner(acc: List[T] = List.empty[T], curList: List[T] = list): List[T] = curList match {\n      case Nil => acc\n      case x :: xs if acc.contains(x) => inner(acc, xs)\n      case x :: xs => inner(acc :+ x, xs)\n    }\n    inner()\n  }\n  \n  println(removeDupl(list).length)\n  removeDupl(list).reverse.foreach(x => print(x + \" \"))\n  \n}", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a"}
{"source_code": "object Main {\n  def main(args: Array[String]) {\n    val s = readLine()\n    val i = BigInt(s)\n    if (i <= Byte.MaxValue) println(\"byte\")\n    else if (i <= Short.MaxValue) println(\"short\")\n    else if (i <= Int.MaxValue) println(\"int\")\n    else if (i <= Long.MaxValue) println(\"long\")\n    else println(\"BigInteger\")\n  }\n}", "src_uid": "33041f1832fa7f641e37c4c638ab08a1"}
{"source_code": "import scala.io.StdIn.readLine\n\n\nobject DominoPiling {\n   def main(args: Array[String]) {\n     val line = readLine.split(' ').map(_.toInt)\n     println(line(0)*line(1)/2)\n   }\n}", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd"}
{"source_code": "//package codeforce520\n\nobject A {\n  def main(args: Array[String]): Unit = {\n    val reader = scala.io.StdIn\n\n    val n = reader.readInt()\n    val a = (\"0 \" + reader.readLine() + \" 1001\").split(\"\\\\s+\").map(_.toInt).toList\n    var res = 0\n    //println(a.mkString(\" \"))\n    (0 until n).foreach{i =>\n      (i + 2 until n + 2).foreach{j =>\n        //println(s\"i $i j $j ai ${a(i)} aj ${a(j)}\")\n        //println(a(j) - a(i))\n        //println(j - i)\n        if (a(j) - a(i) == j - i) {\n          res = math.max(res, j - i - 1)\n        }\n      }\n    }\n\n    println(res)\n  }\n}\n", "src_uid": "858b5e75e21c4cba6d08f3f66be0c198"}
{"source_code": "import scala.io.StdIn._\n\nobject Solution {\n  def main(args: Array[String]): Unit = {\n    println(readLine.split(\"A|E|I|O|U|Y\", -1).maxBy(_.length).length + 1)\n  }\n}\n", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee"}
{"source_code": "import java.util.Scanner\n\nobject Soroban extends App {\n    val scan = new Scanner(System.in)\n    var n = scan.nextInt\n\n    do {\n        val k = n % 10\n        println(output(k))\n        n = n / 10\n    } while (n != 0)\n\n    def output(number: Int): String = {\n        number match {\n            case 0 => \"O-|-OOOO\"\n            case 1 => \"O-|O-OOO\"\n            case 2 => \"O-|OO-OO\"\n            case 3 => \"O-|OOO-O\"\n            case 4 => \"O-|OOOO-\"\n            case 5 => \"-O|-OOOO\"\n            case 6 => \"-O|O-OOO\"\n            case 7 => \"-O|OO-OO\"\n            case 8 => \"-O|OOO-O\"\n            case 9 => \"-O|OOOO-\"\n        }\n    }\n}\n", "src_uid": "c2e3aced0bc76b6484360563355d23a7"}
{"source_code": "object SpecialTask extends App {\n  \n\tval in = new java.util.Scanner(System.in);\n\tval s = in.next();\n\tval startTime = System.currentTimeMillis()\n\n\tval letters = new scala.collection.mutable.HashSet[Char]();\n\tvar numQuestionMarks = 0;\n\tfor (c <- s) {\n\t  if (c == '?')\n\t    numQuestionMarks+=1;\n\t  else if (c.isLetter)\n\t    letters+=c;\n\t}\n\t\n\tvar combinations = 1;\n\tval numLetters = letters.size;\n\tfor(i <- 10-(numLetters-1) to 10)\n\t  combinations*=i;\n\t\n\tif (s(0) == '?') {\n\t  combinations*=9;\n\t  numQuestionMarks-=1;\n\t} else if (s(0).isLetter) {  \n\t  combinations/=10;\n\t  combinations*=9;\n\t}\n\t\n    println(combinations+(\"0\"*numQuestionMarks));\n//\tprintln(\"%d ms\".format(System.currentTimeMillis()-startTime));\n\tin.close();\n}", "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82"}
{"source_code": "object A741 {\n\n  import IO._\n  import collection.{mutable => cu}\n\n  def gcd(x: Long, y: Long): Long = {\n    if(x == 0) y else gcd(y % x, x)\n  }\n  def lcm(x: Long, y: Long): Long = {\n    x / gcd(x, y) * y\n  }\n  def main(args: Array[String]): Unit = {\n    val Array(n) = readInts(1)\n    val c = readInts(n).map(_-1)\n    var vis = Array.fill(n)(false)\n    var res = 1L\n    if(c.distinct.length == n) {\n      var break = false\n      for (i <- 0 until n if !vis(i) && !break) {\n        var len = 0L\n        var j = i\n        while (!vis(j)) {\n          vis(j) = true\n          j = c(j)\n          len += 1\n        }\n        if (len == 0) {\n          break = true\n        }\n        if (len % 2 == 0) len /= 2\n        res = lcm(res, len)\n      }\n      println(res)\n    } else {\n      println(\"-1\")\n    }\n  }\n\n  object IO {\n    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n\n    @inline def read: String = input.readLine()\n\n    @inline def tokenizeLine = new java.util.StringTokenizer(read)\n\n    def readInt: Int = tokenizeLine.nextToken.toInt\n\n    def readInts(n: Int): Array[Int] = {\n      val tl = tokenizeLine\n      Array.fill(n)(tl.nextToken.toInt)\n    }\n\n    def readLongs(n: Int): Array[Long] = {\n      val tl = tokenizeLine\n      Array.fill(n)(tl.nextToken.toLong)\n    }\n\n    def readBigs(n: Int): Array[BigInt] = {\n      val tl = tokenizeLine\n      Array.fill(n)(BigInt(tl.nextToken))\n    }\n  }\n\n}\n", "src_uid": "149221131a978298ac56b58438df46c9"}
{"source_code": "import scala.io.StdIn.readLine\n\nobject Task3 extends App {\n  val n = readLine().split(' ').map(_.toLong).head\n\n  def eating(n: Long, k: Long) = {\n    var cur = n\n    var had = 0L\n\n    while (cur != 0L) {\n      had = had + math.min(cur, k)\n      cur = cur - math.min(cur, k)\n      cur = cur - cur/10\n    }\n\n    2*had >= n\n  }\n\n  def sol(n: Long) = {\n    var left = 1L\n    var right = n\n    while ( left != right) {\n      val now = (left+right)/2\n      if (!eating(n, now)) left = now + 1 else right = now\n    }\n\n    left\n  }\n\n  println(sol(n))\n}", "src_uid": "db1a50da538fa82038f8db6104d2ab93"}
{"source_code": "object Solution {\n    def main(args: Array[String]) {\n        val n_k = readLine().split(' ').map(_.toInt)\n        val n = n_k(0)\n        val k = n_k(1)\n        val tabs = readLine().split(' ').map(_.toInt)\n      \n        val totalSum = tabs.sum\n      \n        val partialSums = new Array[Int](k)\n        tabs.zipWithIndex.foreach {case (tab, index) =>\n          partialSums(index % k) -= tab\n        }\n        val differences = partialSums.map{sum => Math.abs(sum+totalSum)}\n        val result = differences.max\n      \n       println(result)\n    }\n}\n", "src_uid": "6119258322e06fa6146e592c63313df3"}
{"source_code": "/**\n *\n * Created by ronaflx on 15-4-3.\n */\n\nimport java.io._\nimport java.util.StringTokenizer\n\nimport scala.Ordering.Implicits._\n\n\nobject Codeforces {\n  var out: PrintWriter = null\n  var br: BufferedReader = null\n  var st: StringTokenizer = null\n\n  def next: String = {\n    while (st == null || !st.hasMoreTokens) {\n      st = new StringTokenizer(br.readLine)\n    }\n    st.nextToken\n  }\n\n  def nextInt: Int = {\n    Integer.parseInt(next)\n  }\n\n  def nextLong: Long = {\n    java.lang.Long.parseLong(next)\n  }\n\n  def lowerBound[T: Ordering](array: Array[T], value: T) = {\n    var low = 0\n    var high = array.length\n    var res = array.length\n    while (low <= high) {\n      val mid = (low + high) / 2\n      if (!(array(mid) < value)) {\n        res = mid\n        high = mid - 1\n      } else {\n        low = mid + 1\n      }\n    }\n    res\n  }\n\n  def upperBound[T: Ordering](array: Array[T], value: T) = {\n    var low = 0\n    var high = array.length\n    var res = array.length\n    while (low <= high) {\n      val mid = (low + high) / 2\n      if (value < array(mid)) {\n        res = mid\n        high = mid - 1\n      } else {\n        low = mid + 1\n      }\n    }\n    res\n  }\n\n\n  val N = 210001;\n  val bit: Array[Int] = new Array[Int](N)\n\n  def addBit(pos: Int, value: Int): Unit = {\n    var i = pos\n    while (i < N) {\n      bit(i) += value\n      i += (i & (i ^ (i - 1)))\n    }\n  }\n\n  def getBit(pos: Int): Int = {\n    var (i, res) = (pos, 0)\n    while (i > 0) {\n      res += bit(i)\n      i -= (i & (i ^ (i - 1)))\n    }\n    return res\n  }\n\n  def getRange(from: Int, to: Int): Int = {\n    return getBit(to) - getBit(from - 1)\n  }\n\n  def solve(): Unit = {\n    val k = nextInt\n    val s = next\n    val charSet = s.toSet\n    if (charSet.size >= k) {\n      out.println(\"YES\")\n      var start = 0\n      val find = collection.mutable.Set[Char]()\n      object AllDone extends Exception {}\n      for (i <- 0 until k - 1) {\n        try {\n          for (j <- start until s.length) {\n            find += s(start)\n            if (!find.contains(s(j))) {\n              out.println(s.substring(start, j))\n              start = j\n              find += s(j)\n              throw AllDone\n            }\n          }\n        } catch {\n          case AllDone =>\n        }\n      }\n      out.println(s.substring(start))\n    } else {\n      out.println(\"NO\")\n    }\n  }\n\n\n  def main(args: Array[String]): Unit = {\n    br = new BufferedReader(new InputStreamReader(System.in))\n    out = new PrintWriter(new BufferedOutputStream(System.out))\n    solve\n    out.close\n  }\n}\n", "src_uid": "c1b071f09ef375f19031ce99d10e90ab"}
{"source_code": "import math._\n\nobject Main extends App {\n    val n = readInt\n    val a = readLine split \" \" map (_ toInt) sorted\n    \n    println(\n        min(\n            (2 to n by 2) zip(a) map(t => abs(t._1 - t._2)) sum,\n            (1 to n by 2) zip(a) map(t => abs(t._1 - t._2)) sum\n        )\n    )\n}\n", "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a"}
{"source_code": "object A extends App {\n  val Array(y, x) = scala.io.StdIn.readLine().split(\" \").map(_.toLong)\n\n  if (x == 0) println(\"No\")\n  else if (x == 1 && y != 0) println(\"No\")\n  else if (x > 1 && (y + 1 < x || (y - x + 1) % 2 != 0)) println(\"No\")\n  else println(\"Yes\")\n}\n", "src_uid": "1527171297a0b9c5adf356a549f313b9"}
{"source_code": "import scala.io.StdIn._\n\nobject B extends App {\n\n  val t = readInt()\n\n  def lcm(originalA: Int, originalB: Int): Int = {\n    var a = originalA\n    var b = originalB\n\n    var temp = a\n    if (a < b) {\n      a = b\n      b = temp\n    }\n\n    // a > b\n    while (b > 0) {\n      temp = a\n      a = b\n      b = temp % b\n    }\n    val gcd = a\n    ((originalA.toLong * originalB) / gcd).toInt\n  }\n\n  1 to t foreach { _ =>\n    val n = readInt()\n    if (n % 2 == 0) {\n      println(n / 2 + \" \" + n / 2)\n    } else {\n      var answer  = Int.MaxValue\n      var answerA = 0\n      var answerB = 0\n\n      for {\n        k <- 2 to (Math.sqrt(n).toInt + 1)\n        a = n / k if n % k == 0\n        b = n - a\n      } {\n        val x = lcm(a, b)\n        if (x < answer) {\n          answer = x\n          answerA = a\n          answerB = b\n        }\n      }\n\n      if (answer == Int.MaxValue || n - 1 <= answer) {\n        println(1 + \" \" + (n - 1))\n      } else {\n        println(answerA + \" \" + answerB)\n      }\n    }\n  }\n\n}\n", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5"}
{"source_code": "import java.util.StringTokenizer\n\nobject A extends App {\n  val INF = 1 << 30\n\n  var st: StringTokenizer = _\n  def read() = { st = new StringTokenizer(readLine()) }\n  def int() = st.nextToken().toInt\n  def long() = st.nextToken().toLong\n\n  read()\n  val n = int()\n  val d = int()\n  read()\n  val a = Array.fill(n)(int()).sorted\n\n  val ans = (0 until n).map { i =>\n    val s = a(i)\n    val f = s + d\n    a.count{c => c >= s && c <= f}\n  }.max\n\n  println(n - ans)\n\n}\n", "src_uid": "6bcb324c072f796f4d50bafea5f624b2"}
{"source_code": "object D extends App {\n\n  val mod = 1000000007\n\n  def readString = Console.readLine\n  def readInts = readString.split(\" \").map(_.toInt)\n  \n  val fact = Array.ofDim[Long](200001)\n  val factInv = Array.ofDim[Long](200001)\n  \n  var f = 1L\n  for (i <- 0 until fact.size) {\n    fact(i) = f.toInt\n    factInv(i) = if (f == 1) 1 else BigInt(f).modInverse(mod).toInt\n    f = (f * (i + 1)) % mod\n  }\n  \n  def c(k: Int, n: Int): Long = {\n    ((fact(n) * factInv(k) % mod) * factInv(n - k)) % mod\n  }\n\n  @scala.annotation.tailrec\n  def count(n: Int, m: Int, g: Byte, acc: Long): Long = {\n    if (n < 0 || m < 0) acc\n    else (n, m, g) match {\n      case (0, 0, _) => acc\n      case (1, 0, 0) => 1 + acc\n      case (1, 0, 1) => acc\n      case (0, 1, 0) => acc\n      case (1, 1, 0) => 2 + acc\n      case (0, 1, 1) => 1 + acc\n      case (n, m, 1) => count(n - 1, m, 0, acc)\n      case (n, m, 0) => count(n - 2, m, 0, ((if (m > 0) c(n, n + m - 1) else 0) + acc) % mod)\n    }\n  }\n  \n  val Array(n, m, g) = readInts\n\n  println(count(n, m, g.toByte, 0))\n}", "src_uid": "066dd9e6091238edf2912a6af4d29e7f"}
{"source_code": "import scala.io.StdIn\n\nobject ProblemA extends App {\n\n  val result = StdIn.readInt() match {\n    case 2 => 2\n    case _ => 1\n  }\n\n  println(result)\n}\n", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d"}
{"source_code": "import scala.io.StdIn\n\nobject A extends App {\n\n  val in = StdIn.readLine().split(\" \").map(_.toInt)\n\n  val c = in(0)\n  val v0 = in(1)\n  val v1 = in(2)\n  val a = in(3)\n  val l = in(4)\n\n  var cp = v0\n  var days = 1\n  while (cp < c) {\n    cp = cp - l + Math.min(v1, v0 + days * a)\n    days = days + 1\n  }\n  println(days)\n\n}\n", "src_uid": "b743110117ce13e2090367fd038d3b50"}
{"source_code": "object C extends App {\n    val sc = new java.util.Scanner(System.in)\n    println(Seq(\n        sc.nextInt(),\n        sc.nextInt(),\n        sc.nextInt() / 2,\n        sc.nextInt() / 7,\n        sc.nextInt() / 4\n    ).min)\n    sc.close()\n}\n", "src_uid": "f914f9b7884cc04b990c7800c6be7b10"}
{"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport java.util.Arrays.binarySearch\nimport scala.annotation.tailrec\nimport scala.annotation.switch\nimport scala.collection.mutable\nimport scala.collection.mutable.ListBuffer\nimport scala.collection.mutable.ArrayBuffer\nimport scala.collection.immutable.TreeSet\nimport scala.util.Random\nimport scala.util.control.Breaks._\n\n\nobject P122B extends App {\n  val sc = new Scanner(System.in)\n  val out = new PrintWriter(System.out)\n\n  def solve(): String = {\n    val S = sc.nextLine\n    val num4 = S.count(_ == '4')\n    val num7 = S.count(_ == '7')\n    if (num4 == 0 && num7 == 0) \"-1\"\n    else if (num4 >= num7) \"4\"\n    else \"7\"\n  }\n\n  out.println(solve)\n  out.close\n}\n", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a"}
{"source_code": "object CF_526_2_A {\n  def solve(n: Int, as: Seq[Int]): Int = {\n    import math.abs\n    def e(floor: Int, x: Int) = (abs(floor -x) + (floor - 1) + (x - 1)) * 2\n    def total(x: Int) = as.zip(1 to n).map{case (p,f) => p * e(f, x)}.sum\n    val X = 1 to n minBy total\n    total(X)\n  }\n\n  // Specify Input and Output formats here:\n  def formatIn(i: Input) = (i.int, {i.nextLine; i.intSeq})\n  def formatOut(out: Int) = out.toString\n\n//     ~~~ Boilerplate that doesn't change ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n  def main(args: Array[String]) = {\n    val out = new java.io.PrintWriter(System.out)\n    val resultStr = new Input(System.in).solveStr\n    out.println(resultStr)\n    out.close()\n  }\n\n//     ~~~ Utility methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n  import java.util.Scanner\n  class Input(sc: Scanner) {\n    def this(i: java.io.InputStream) = this(new Scanner(i))\n    def this(s: String) = this(new Scanner(s.stripMargin))\n    def int = sc.nextInt()\n    def long = sc.nextLong()\n    def double = sc.nextDouble()\n    def nextLine = sc.nextLine() \n    // If there are prior values, remember to call nextLine to advance past the newline character before collecting the line:\n    def collect[T](f: String => T) = {sc.nextLine().split(\" \").toVector.map(f)}\n    def intSeq() = collect(_.toInt)\n    def doubleSeq() = collect(_.toDouble)\n    def solveVals = (solve _).tupled(formatIn(this))\n    def solveStr = formatOut(solveVals)\n  }\n\n  def ceil(a: Int, b: Int) = (a - 1) / b + 1\n  def ceil(a: Long, b: Long) = (a - 1) / b + 1\n\n  import language.implicitConversions\n  implicit def stringToInput(s: String): Input = new Input(s)\n}", "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f"}
{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n  val in = Source.stdin.getLines()\n  val n = in.next().toInt\n  val mod = (1e9 + 7).toInt\n  if (n == 1)\n    println(0)\n  else {\n    var pp = 1l\n    var p = 0l\n    var f3 = 1l\n    val res = (2 to n).foreach { _ =>\n      val tmp = p\n      p = (pp + f3 * 2) % mod\n      f3 = f3 * 3 % mod\n      pp = tmp\n    }\n    println(p)\n  }\n}\n", "src_uid": "77627cc366a22e38da412c3231ac91a8"}
{"source_code": "import scala.collection.immutable\n\n/**\n * Created by admin on 10/5/2014.\n */\nobject B {\n\n\n  class BB{\n    var col:Int = 0\n    var row:Int = 0\n    var data_row:immutable.IndexedSeq[Char] = null\n    var data_col:immutable.IndexedSeq[Char] = null\n    var queue:Vector[(Int,Int,Int)] = Vector((0,0,1))\n    var board = Array.fill[Int](0,0)(1)\n\n    var fail = false\n\n    def bfs(r:Int,c:Int,step:Int)={\n      var notcheck = false\n      val arr1 = data_row(r) match {\n        case '<' => for ( r2 <- 0 until r\n            if (board(r2)(c) == 0 ) ) yield ( (r2,c,step) )\n        case '>' => for ( r2 <- (r+1) until col\n                          if (board(r2)(c) == 0 ) ) yield ( (r2,c,step) )\n      }\n\n      val arr2 = data_col(c) match {\n        case '^' => for ( c2 <- 0 until c\n                          if (board(r)(c) == 0 ) ) yield ( (r,c2,step) )\n        case 'v' => for ( c2 <- (r+1) until row\n                          if (board(r)(c) == 0 ) ) yield ( (r,c2,step) )\n      }\n      arr1 ++ arr2 foreach( x => {board(x._1)(x._2) = step} )\n      if ((arr1 ++ arr2).length <1) fail = true\n      queue = queue ++ arr1 ++ arr2\n    }\n\n    def search(idx:Int): Unit ={\n      val head = queue(idx)\n      println(\"Current at \",head)\n      bfs(head._1,head._2,head._3+1)\n      println(queue.mkString(\",\"))\n    }\n\n    def work2() ={\n      var result = true\n      if (data_row(0) == '<' && data_col(0) == '^') result = false\n      if (data_row(0) == '>' && data_col( col-1 ) == '^') result = false\n      if (data_row( row-1 ) == '<' && data_col(0) == 'v') result = false\n      if (data_row( row-1 ) == '>' && data_col( col-1 ) == 'v') result = false\n      if (result)\n        println(\"YES\")\n      else println(\"NO\")\n    }\n\n    def work() ={\n      val temp = readLine().split(\"\\\\s\") map (_.toInt)\n      row = temp(0)\n      col = temp(1)\n      board = Array.fill(row,col)(0)\n      data_row = readLine().toList.toIndexedSeq\n      data_col = readLine().toList.toIndexedSeq\n      //search(0)\n      work2()\n    }\n\n  }\n\n\n  def main(args:Array[String]) = {\n    new BB() work\n\n  }\n}\n", "src_uid": "eab5c84c9658eb32f5614cd2497541cf"}
{"source_code": "import scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util._, control._\nimport scala.math.Ordering.Implicits._\n\nobject _633A extends CodeForcesApp {\n  override type Result = Boolean\n\n  override def solve(read: InputReader) = {\n    val (a, b, c) = read[(Int, Int, Int)]\n    (0 to c/a) exists {i =>\n      val j = (c - a*i)/b\n      a*i + b*j == c\n    }\n  }\n\n  override def format(result: Result) = if (result) \"Yes\" else \"No\"\n}\n/****************************[Ignore Template Below]****************************************/\nabstract class CodeForcesApp {\n  val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)\n  type Result\n  def solve(scanner: InputReader): Result\n  def format(result: Result): String\n  def apply(scanner: InputReader): String = format(solve(scanner))\n  def main(args: Array[String]): Unit = println(apply(new InputReader(System.in)))\n}\n/*********************************[Scala Scanner]*******************************************/\nimport java.io.{BufferedReader, Reader, InputStreamReader, StringReader, InputStream}\nimport java.util.StringTokenizer\n\nclass InputReader(reader: BufferedReader) extends Iterator[String] with AutoCloseable {\n  def this(reader: Reader) = this(new BufferedReader(reader))\n  def this(inputStream: InputStream) = this(new InputStreamReader(inputStream))\n  def this(str: String) = this(new StringReader(str))\n\n  private[this] val tokenizers = Iterator.continually(reader.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n\n  @inline private[this] def tokenizer(): Option[StringTokenizer] = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    if (tokenizers.nonEmpty) Some(tokenizers.head) else None\n  }\n\n  def apply[A: Parser]: A = implicitly[Parser[A]].apply(this)\n\n  def apply[C[_], A: Parser](n: Int)(implicit cbf: Parser.Collection[C, A]): C[A] = {\n    val builder = cbf()\n    for {_ <- 1 to n} builder += apply[A]\n    builder.result()\n  }\n\n  def till(delim: String): String = tokenizer().get.nextToken(delim)\n  def tillEndOfLine() = till(\"\\n\\r\")\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n  override def close() = reader.close()\n}\n\nclass Parser[A](val apply: InputReader => A) {\n  def map[B](f: A => B): Parser[B] = new Parser(apply andThen f)\n}\nobject Parser {\n  type Collection[C[_], A] = scala.collection.generic.CanBuildFrom[C[A], A, C[A]]\n  implicit def collection[C[_], A: Parser](implicit cbf: Collection[C, A])   : Parser[C[A]]            = new Parser(r => r[C, A](r[Int]))\n  implicit val string                                                        : Parser[String]          = new Parser(_.next())\n  implicit val char                                                          : Parser[Char]            = string.map(s => s.ensuring(_.length == 1, s\"Expected Char; found $s\").head)\n  implicit val boolean                                                       : Parser[Boolean]         = string.map(_.toBoolean)\n  implicit val int                                                           : Parser[Int]             = string.map(_.toInt)\n  implicit val long                                                          : Parser[Long]            = string.map(_.toLong)\n  implicit val bigInt                                                        : Parser[BigInt]          = string.map(BigInt(_))\n  implicit val double                                                        : Parser[Double]          = string.map(_.toDouble)\n  implicit val bigDecimal                                                    : Parser[BigDecimal]      = string.map(BigDecimal(_))\n  implicit def tuple2[A: Parser, B: Parser]                                  : Parser[(A, B)]          = new Parser(r => (r[A], r[B]))\n  implicit def tuple3[A: Parser, B: Parser, C: Parser]                       : Parser[(A, B, C)]       = new Parser(r => (r[A], r[B], r[C]))\n  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]))\n  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]))\n}\n", "src_uid": "e66ecb0021a34042885442b336f3d911"}
{"source_code": "import java.util.Scanner\n\nobject Main extends App {\n  def min(x: Long, y: Long) = if (x < y) x else y\n  val scanner = new Scanner(System.in)\n  val n = scanner.nextInt()\n  val x = scanner.nextLong()\n  val y = scanner.nextLong()\n\n  val cost = new Array[Long](2 * n + 1)\n  cost(0) = 0\n  for (i <- 1 to cost.length - 1)\n    cost(i) = 0xffffffffffffL\n  for (i <- 1 to n) {\n    cost(i) = min(cost(i), cost(i-1) + x)\n    cost(i) = min(cost(i), cost(i+1) + x)\n    cost(2*i) = min(cost(2 * i), cost(i) + y)\n  }\n  println(cost(n))\n}\n", "src_uid": "0f270af00be2a523515d5e7bd66800f6"}
{"source_code": "import scala.io.StdIn\n\n/**\n * Author: Odomontois\n * Date  : 16-Apr-15\n * Time  : 21:17\n */\nobject Round299D2B extends App {\n  val line = StdIn.readLine()\n  println(((1 << line.length) - 1) + Integer.parseInt(line.replace('4', '0').replace('7', '1'), 2))\n}\n", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3"}
{"source_code": "import scala.io.StdIn\n\nobject ARectangle {\n\n  def main(args: Array[String]) {\n    val in = StdIn.readLine().split(\"\\\\s+\").map(_.toInt)\n\n    val a = Math.abs(in(2) - in(0)) / 2 + 1\n    val b = Math.abs(in(3) - in(1)) / 2 + 1\n    println(a.toLong * b + (a - 1).toLong * (b - 1))\n  }\n\n}\n", "src_uid": "00cffd273df24d1676acbbfd9a39630d"}
{"source_code": "\n\nimport java.io.PrintWriter\nimport java.util.Scanner\n\n/**\n * Created by arseny on 17.07.14.\n */\nobject A extends App {\n  val home = true\n  val in = new Scanner(System.in)\n  val out = new PrintWriter(System.out)\n\n\n  def nextInt = in.nextInt\n  def nextLong = in.nextLong\n  def nextDouble = in.nextDouble\n  def nextString = in.next\n\n  def solve() = {\n    val a1 = nextInt\n    val a2 = nextInt\n    val a3 = nextInt\n    val b1 = nextInt\n    val b2 = nextInt\n    val b3 = nextInt\n    val n = nextInt\n    val a = a1 + a2 + a3\n    var n1 = 0\n    val b = b1 + b2 + b3\n    var n2 = 0\n    if (a % 5 == 0) {\n      n1 = a / 5\n    } else {\n      n1 = a / 5 + 1\n    }\n    if (b % 10 == 0) {\n      n2 = b / 10\n    } else {\n      n2 = b / 10 + 1\n    }\n    if (n1 + n2 <= n) {\n      out.println(\"YES\")\n    } else {\n      out.println(\"NO\")\n    }\n  }\n\n  try {\n    solve()\n  } catch {\n    case _: Exception => sys.exit(9999)\n  } finally {\n    out.flush()\n    out.close()\n  }\n}\n", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e"}
{"source_code": "object A extends App {\n  val s = 3\n  val b = 7\n\n  def check(x: Int): Boolean =\n    if (x < 0) false\n    else if (x % 3 == 0) true\n    else check(x - 7)\n\n  val n = scala.io.StdIn.readInt()\n  (0 until n).foreach(_ => {\n    val x = scala.io.StdIn.readInt()\n    if (check(x)) println(\"YES\")\n    else println(\"NO\")\n  })\n}\n", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452"}
{"source_code": "import scala.io.Source\n\nobject CodefOne extends App {\n\n  val in = Source.stdin.getLines()\n  val data = in.next().split(' ').map(_.toInt)\n\n  private val mapa: Map[Int, Int] = data.groupBy(w => w).mapValues(_.length)\n\n  val maxVals = mapa.filter((t) => t._2 >= 2).map(t => t._1 * (if (t._2 > 3) 3 else t._2))\n  if (maxVals isEmpty) {\n    println(data.sum)\n  } else {\n    println(data.sum - maxVals.max)\n  }\n\n}\n", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a"}
{"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\n\n/**\n * Created by hama_du on 2014/03/11.\n */\nobject ProblemD extends App {\n  val in = new Scanner(System.in)\n  val n = in.nextLong\n  val m = in.nextInt\n\n  val cnt0to9 = (0 to 9).map(d => n.toString.toCharArray.filter(c => c == ('0' + d)).length).toArray\n  val bit0to9 = cnt0to9.map(b =>  {\n    def bc(current: Int, limit: Int): Int = {\n      if (current > limit) {\n        0\n      } else {\n        bc(current<<1, limit)+1\n      }\n    }\n    bc(1, b)\n  })\n\n\n  val rng0to9 = bit0to9.scanLeft((0,0))((a, b) => (a._2, a._2+b)).toArray\n  val maxBit = rng0to9.last._2\n\n  val maxP = 1<<maxBit\n  val dp = Array.ofDim[Long](m,maxP)\n  dp(0)(0) = 1L\n\n  val mpMap = (0 to 24).scanLeft(1L)((a, b) => (a * 10)).map(x => (x % m).toInt).toArray\n  val cntSum = cnt0to9.sum\n\n  var pi = -1\n  while (pi < maxP-1) {\n    pi += 1\n    val used = decode(pi, rng0to9)\n    val usedSum = used.sum\n    if (cntSum > usedSum) {\n      val factor = mpMap(cntSum-usedSum-1)\n      val usedAtLeastOne = (usedSum >= 1)\n      var mi = -1\n      while (mi < m-1) {\n        mi += 1\n        if (dp(mi)(pi) >= 1) {\n          var num = -1\n          while (num < 9) {\n            num += 1\n            if (used(num) < cnt0to9(num) && (num >= 1 || (num == 0 && usedAtLeastOne))) {\n              val pair = rng0to9(num+1)\n              val unn = used(num) + 1\n              val np = (pi + (unn << pair._1) - (used(num) << pair._1))\n              val nm = (mi + num * factor) % m\n              dp(nm)(np) += dp(mi)(pi)\n            }\n          }\n        }\n      }\n    }\n  }\n  println(dp(0)(encode(cnt0to9, -1, rng0to9)))\n\n\n  def decode(p: Int, rng0to9: Array[(Int,Int)]): Array[Int] = {\n    val ret = new Array[Int](10)\n    var d = 0\n    while (d <= 9) {\n      val pair = rng0to9(d+1)\n      val length = pair._2 - pair._1\n      ret(d) = (p >> pair._1) & ((1<<length)-1)\n      d += 1\n    }\n    ret\n  }\n\n\n  def encode(used: Array[Int], use: Int, rng0to9: Array[(Int,Int)]): Int = {\n    (0 to 9).map(d => {\n      val pair = rng0to9(d+1)\n      val f = if (d == use) { used(d) + 1 } else { used(d) }\n      f << pair._1\n    }).foldLeft(0)((a,b) => a | b)\n  }\n}\n", "src_uid": "5eb90c23ffa3794fdddc5670c0373829"}
{"source_code": "\nimport scala.io.StdIn\n\nobject FileName extends App {\n\n  val l1 = StdIn.readLine()\n  val l2 = StdIn.readLine()\n\n  print(impl(l2))\n\n  def impl(in: String): Int = {\n    var toRemove = 0\n    var consX = 0\n\n    for (char <- in) {\n      char match {\n        case 'x' => consX += 1\n        case _ =>\n          if (consX >= 3) toRemove += (consX - 2)\n          consX = 0\n      }\n    }\n    if (consX >= 3) toRemove += (consX - 2)\n\n    toRemove\n  }\n}\n", "src_uid": "8de14db41d0acee116bd5d8079cb2b02"}
{"source_code": "import java.util.Scanner\n\nobject T1 extends App {\n  val sc = new Scanner(System.in)\n  val n = sc.nextInt\n  val s = sc.nextLong\n  if (s % n > 0) println(s / n + 1) else println(s / n)\n}", "src_uid": "04c067326ec897091c3dbcf4d134df96"}
{"source_code": "object Solution extends App {\n  val in = scala.io.Source.stdin.getLines()\n  val Array(r, b) = in.next().split(\" \").map(_.toInt)\n  val different = Math.min(r, b)\n  val left = Math.max(r, b) - different\n  println(s\"$different ${left/2}\")\n}", "src_uid": "775766790e91e539c1cfaa5030e5b955"}
{"source_code": "object CF{\n\tdef main(args:Array[String]){\n\t\timport scala.io.StdIn.readLine\n\t\tval string = readLine().map(_.toInt)\n\n\t\tvar cur = 'a'.toInt\n\t\tvar total = 0\n\t\tfor(c <- string){\n\t\t\ttotal += diff(cur, c)\n\t\t\t//println(f\"$cur, $c\")\n\t\t\t//println(f\"$total\")\n\t\t\tcur = c\n\t\t}\n\n\t\tprintln(total)\n\t}\n\n\tdef diff(a: Int, b:Int): Int = {\n\t\tval d = math.abs(a-b)\n\t\treturn math.min(d, 26-d)\n\t}\n}", "src_uid": "ecc890b3bdb9456441a2a265c60722dd"}
{"source_code": "import scala.annotation.tailrec\n\nobject Table {\n\n  def parse(as: String) = as.split(\"\\\\s+\").toList.map(_.toLong)\n\n  def solve(n: Long, m: Long, k: Long) = {\n\n    def partition(pivot: Long) = {\n      var i: Long = 1\n      var sum: Long = 0\n      while (i <= n) {\n        sum += Math.min((pivot-1)/i, m)\n        i += 1\n      }\n      sum\n    }\n\n    @tailrec\n    def go(left: Long, right: Long, target: Long): Long = {\n      if (left <= right) {\n        val mid = left + (right - left) / 2\n        val s = partition(mid)\n        if (s < k) go(mid+1, right, mid)\n        else go(left, mid-1, target)\n      } else {\n        target\n      }\n    }\n      \n    go(1, n*m, 0)\n  }\n\n  def main(args: Array[String]) {\n    val List(input) = io.Source.stdin.getLines.take(1).toList\n    val List(n, m, k) = parse(input)\n    println(solve(n, m, k))\n  }\n}\n\n", "src_uid": "13a918eca30799b240ceb9de47507a26"}
{"source_code": "import scala.io.StdIn\n\n/**\n * @author chengyi\n */\nobject MagicBox {\n  \n  def canSee(vp:(Int,Int,Int), vt:(Int,Int,Int), asl:String):Int={\n    val ap: Array[(Float, Float, Float)] = Array.fill(6)((0,0,0))\n    val as = asl.split(\" \").map { x => x.toInt }.toList\n    ap(0) = (vt._1/2f, 0, vt._3/2f)\n    ap(1) = (vt._1/2f, vt._2, vt._3/2f)\n    ap(2) = (vt._1/2f, vt._2/2f, 0)\n    ap(3) = (vt._1/2f, vt._2/2f, vt._3)\n    ap(4) = (0, vt._2/2f, vt._3/2f)\n    ap(5) = (vt._1, vt._2/2f, vt._3/2f)\n    val api: Array[(Float, Float, Float)] = Array.fill(6)((0,0,0))\n    api(0) = (0, -1, 0)\n    api(1) = (0, 1, 0)\n    api(2) = (0, 0, -1)\n    api(3) = (0, 0, 1)\n    api(4) = (-1, 0, 0)\n    api(5) = (1, 0, 0)\n    var sv=0\n    (0 to 5).foreach(x=>{\n      val v = (vp._1 - ap(x)._1, vp._2 - ap(x)._2, vp._3 - ap(x)._3)\n      val dot = api(x)._1 * v._1 + api(x)._2 * v._2 + api(x)._3 * v._3\n      if (dot>0){\n        sv = sv + as(x)\n      }\n    })\n    sv\n  }\n  \n  def main(args:Array[String]){\n    val view = StdIn.readLine().split(\" \").map { x => x.toInt }\n    val vp:(Int, Int, Int) = (view(0), view(1), view(2))\n    val l = StdIn.readLine().split(\" \").map { x => x.toInt }\n    val vt:(Int, Int, Int) = (l(0), l(1), l(2))\n    val as = StdIn.readLine()\n    println(canSee(vp, vt, as))\n  }\n}", "src_uid": "c7889a8f64c57cf7be4df870f68f749e"}
{"source_code": "object Main {\n\n  def main(args: Array[String]) {\n\n    val std = scala.io.StdIn\n    val values = std.readLine().split(\" \").map(_.toInt)\n    val values1 = std.readLine().split(\" \").map(_.toInt)\n    val values2 = std.readLine().split(\" \").map(_.toInt)\n\n    var w = values(0)\n    var h = values(1)\n    val u1 = values1(0)\n    val d1 = values1(1)\n    val u2 = values2(0)\n    val d2 = values2(1)\n\n    while (h > 0) {\n      w += h\n      if (h == d1) {\n        w -= u1\n      }\n      else if (h == d2) {\n        w -= u2\n      }\n      w = w.max(0)\n      h -= 1\n    }\n    println(w)\n  }\n}", "src_uid": "084a12eb3a708b43b880734f3ee51374"}
{"source_code": "//package com.umeng.test\n\n/**\n * Created by bright on 5/28/14.\n */\nobject cf248_1 {\n  def main(args:Array[String]){\n    val total=readInt()\n    val cnt100= readLine().split(\" \").filter(x=>x.equals(\"100\")).length\n    if(cnt100%2!=0 || cnt100==0&&total%2!=0 )\n      println(\"NO\")\n    else\n      println(\"YES\")\n  }\n\n}\n", "src_uid": "9679acef82356004e47b1118f8fc836a"}
{"source_code": "import scala.io.StdIn\n\nobject Task474A {\n\tdef main(args: Array[String]) {\n\t\tval a = \"qwertyuiopasdfghjkl;zxcvbnm,./\"\n\t\tval shift = if (StdIn.readLine().charAt(0) == 'L') 1 else -1\n\t\tprintln(StdIn.readLine().map(c => a.charAt(a.indexOf(c) + shift)))\n\t}\n}\n", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6"}
{"source_code": "import java.util.Scanner\n\n/**\n * Created by Kuang.Ru on 14-9-28.\n */\nobject A465 extends App {\n  val sc = new Scanner(System.in)\n  val n = sc.nextInt()\n  val num = sc.next()\n  var i = 0\n  var count = 0\n\n  while (i < num.length && num(i) == '1') {\n    count += 1\n    i += 1\n  }\n\n  println(if (count == n) {\n    n\n  }else {\n    count + 1\n  })\n}\n", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab"}
{"source_code": "import java.util.Scanner\n\nobject Main {\n\n  def sqr(x: Long) = x * x\n\n  def powmod(x: Long, n: Long, p: Long): Long = {\n    if (n == 1) x\n    else if (n % 2 == 1) (powmod(x, n - 1, p) * x) % p\n    else sqr(powmod(x, n / 2, p)) % p\n  }\n\n  def C(n: Int, k: Int) = {\n    var res = BigInt(1)\n    for (i <- n - k + 1 to n) {\n      res = res * i\n    }\n    for (i <- 1 to k.toInt) {\n      res = res / i\n    }\n    res\n  }\n\n  def fact(n: Int) = {\n    var res = BigInt(1)\n    for (i <- 1 to n) {\n      res = res * i\n    }\n    res\n  }\n\n  def gcd(a: Long, b: Long): Long = if (b == 0) a else gcd(b, a % b)\n\n  def lcm(a: Long, b: Long) = a / gcd(a, b) * b\n\n  def main(args: Array[String]): Unit = {\n    val in = new Scanner(System.in)\n\n    var l = 1L\n\n    for (i <- 2 to 10) {\n      l = lcm(l, i)\n    }\n\n    println(in.nextLong() / l)\n  }\n}\n", "src_uid": "8551308e5ff435e0fc507b89a912408a"}
{"source_code": "import scala.math._\n\nobject NonSquareEquation extends App {\n    def upperBound(n : Long) : Long = {\n        ceil(sqrt(n)).toLong\n    }                                                 //> upperBound: (n: Long)Long\n    \n    def magicNumber(n : Long) : Long = {\n      (9 * log10(upperBound(n))).toLong \n    }\n    \n    def lowerBound(n : Long) : Long = {\n            val b = magicNumber(n)\n            floor(((-b + sqrt(b * b + 4*n))/2)).toLong\n    }   //> lowerBound: (n: Long)Long\n    \n    def bounds(n : Long) : (Long, Long) = {\n        (lowerBound(n), upperBound(n))\n    }                                                 //> bounds: (n: Long)(Long, Long)\n    \n    def digitFunction(x : Long) : Long = {\n        if (x == 0) 0 else x % 10 + digitFunction(x / 10)\n    }                                                 //> digitFunction: (x: Long)Long\n    \n    def function(n : Long)(x : Long) : Long = {\n        x * x + digitFunction(x)*x - n\n    }                                                 //> function: (n: Long)(x: Long)Long\n    \n    def findRootOnBounds(x : (Long => Long), bounds : (Long, Long)) : Long = {\n        if (bounds._1 > bounds._2) -1\n        else if (x(bounds._1) == 0L) bounds._1\n        else findRootOnBounds(x, (bounds._1 + 1L, bounds._2))\n    }                                                 //> findRootOnBounds: (x: Long => Long, bounds: (Long, Long))Long\n    \n    def findRoot(n : Long) : Long = {\n        findRootOnBounds(function(n), bounds(n))\n    }    \n    \n    for( ln <- io.Source.stdin.getLines ) println(findRoot( ln.toLong ))\n}", "src_uid": "e1070ad4383f27399d31b8d0e87def59"}
{"source_code": "/**\n  * @see http://codeforces.com/contest/909/problem/A\n  */\n\nobject A extends App {\n  def login(n: String, e: Char, l: String = \"\"): String =\n    if (n.isEmpty) l + e\n    else if (l.isEmpty) login(n.tail, e, l + n.head)\n    else if (n.head < e) login(n.tail, e, l + n.head)\n    else login(\"\", e, l)\n\n  val Array(n, s) = scala.io.StdIn.readLine().split(\" \")\n\n  println(login(n, s.head))\n}\n", "src_uid": "aed892f2bda10b6aee10dcb834a63709"}
{"source_code": "object P8C {\n    import io.StdIn._\n\n    def main(args:Array[String]) {\n        val s = readLine.split(' ').map{_.toInt}\n        val a = Array.fill(readInt){readLine.split(' ').map{_.toInt}}\n        def dis(a1:Array[Int], a2:Array[Int]) = {\n            val d0 = a1(0) - a2(0)\n            val d1 = a1(1) - a2(1)\n            d0 * d0 + d1 * d1\n        }\n        val d = Array.tabulate(a.size, a.size){case (i1, i2) =>\n            dis(s, a(i1)) + dis(a(i1), a(i2)) + dis(a(i2), s)\n        }\n        val c = Array.ofDim[Int](1 << a.size)\n        for (i <- 1 until 1 << a.size) {\n            var i1 = 0\n            while (((i >> i1) & 1) == 0) i1 += 1\n            var v = c(i & ~(1 << i1)) + d(i1)(i1)\n            var i2 = i1 + 1\n            while (i2 < a.size) {\n                if (((i >> i2) & 1) != 0) {\n                    val v2 = c(i & ~(1 << i1) & ~(1 << i2)) + d(i1)(i2)\n                    if (v2 < v) v = v2\n                }; i2 += 1\n            }; c(i) = v\n        }\n        println(c((1 << a.size) - 1))\n        def visit(i:Int) {\n            if (i == 0) return\n            var i1 = 0\n            while (((i >> i1) & 1) == 0) i1 += 1\n            var v = c(i & ~(1 << i1)) + d(i1)(i1)\n            var k = i1\n            for (i2 <- i1 + 1 until a.size) if (((i >> i2) & 1) != 0) {\n                val v2 = c(i & ~(1 << i1) & ~(1 << i2)) + d(i1)(i2)\n                if (v2 < v) {v = v2; k = i2}\n            }; c(i) = v\n            print(' '); print(i1 + 1)\n            if (k != i1) {print(' '); print(k + 1)}\n            print(\" 0\")\n            visit(i & ~(1 << i1) & ~(1 << k))\n        }; print('0'); visit((1 << a.size) - 1); println\n    }\n}\n", "src_uid": "2ecbac20dc5f4060bc873553946281bc"}
{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n  val in = Source.stdin.getLines()\n  val Array(n, q) = in.next().split(' ').map(_.toInt)\n  val transitions = Array.ofDim[Int](6, 6)\n  (1 to q).foreach { _ =>\n    val Array(from, to) = in.next().split(' ').map(_.head - 'a')\n    transitions(to)(from) += 1\n  }\n  var first = Array(1, 0, 0, 0, 0, 0)\n  var i = 1\n  while (i != n) {\n    val second = Array.ofDim[Int](6)\n    (0 until 6).foreach { fromIndex =>\n      (0 until 6).foreach { toIndex =>\n        second(toIndex) += first(fromIndex) * transitions(fromIndex)(toIndex)\n      }\n    }\n    first = second\n    i += 1\n  }\n  println(first.sum)\n}", "src_uid": "c42abec29bfd17de3f43385fa6bea534"}
{"source_code": "object Algorithm {\n  def main(args: Array[String]): Unit = {\n    val nums = List(100, 20, 10, 5, 1)\n    var num = scala.io.StdIn.readInt()\n\n    var ans = 0\n    for (i <- 0 until 5) {\n      if (num >= nums(i)) {\n        ans += num / nums(i)\n        num %= nums(i)\n      }\n    }\n    println(ans)\n  }\n}\n", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc"}
{"source_code": "import java.util.StringTokenizer\n\nimport scala.collection.mutable\n\nobject A extends App {\n  val INF = 1 << 30\n  var st: StringTokenizer = _\n  def read() = { st = new StringTokenizer(readLine()) }\n  def int() = st.nextToken().toInt\n\n  read()\n  val n = int()\n  val k = int()\n  read()\n  val a = (1 to n).map(_ => int()).toArray\n  val ab = Array.fill(n+1)(mutable.ArrayBuilder.make[Int])\n  for {\n    i <- 0 until n\n  } ab(a(i)) += i\n  val pos = ab.map(_.result().iterator)\n\n  val set = new mutable.HashSet[Int]()\n  val pq = new mutable.PriorityQueue[(Int, Int)]\n\n  def addToPQ(i : Int, v: Int) = {\n    val it = pos(v)\n    var q = -1\n    while (it.hasNext && q <= i) q = it.next\n    if (q == -1 || q <= i) q = INF\n    pq += ((q, v))\n  }\n\n  var ans = 0\n  (0 until n).foreach { i =>\n    val v = a(i)\n    if (!set.contains(v)) {\n      if (set.size == k)\n        set.remove(pq.dequeue._2)\n      set.add(v)\n      ans += 1\n    }\n    addToPQ(i, v)\n  }\n\n  println(ans)\n}\n", "src_uid": "956228e31679caa9952b216e010f9773"}
{"source_code": "object C{\n  //import scala.collection.mutable.PriorityQueue\n  //import scala.collection.mutable.ArrayBuffer\n  import util.control.Breaks._\n  import java.io.{PrintWriter,InputStream,BufferedReader,InputStreamReader}\n  import java.util.{Locale, Scanner,StringTokenizer}\n  class InputReader(val stream:InputStream ) {\n    var st:StringTokenizer=new StringTokenizer(\"\")\n    val reader=new BufferedReader(new InputStreamReader(stream), 32768);\n\n    def next():String = {\n        while (!st.hasMoreTokens()){\n          val currentLine = reader.readLine\n          st=new StringTokenizer(currentLine)\n        }\n        return st.nextToken\n    }\n\n    def nextInt():Int = {\n        return next.toInt\n    }\n\n    def nextLong():Long = {\n    \treturn next.toLong\n    }\n    def nextDouble:Double = {\n      return next.toDouble\n    }\n  }\n\n  def main(args: Array[String]){\n\n\n    val in = new InputReader(System.in)\n    val out = new PrintWriter(System.out)\n\n    def nextInt = in.nextInt\n    def nextLong = in.nextLong\n    def nextDouble = in.nextDouble\n    def nextString = in.next\n    //code starts here\n    val w=nextInt\n    var m=nextInt\n    var yes=true\n    if(w==2){\n      out.println(\"YES\")\n    }else{\n      while(m!=0){\n        val r=m%w\n        if(r==0){\n\n        }else if(r==1){\n          m-=1\n        }else if(r==w-1){\n          m+=1\n        }else{\n          yes=false\n        }\n        m/=w\n      }\n      if(yes){\n        out.println(\"YES\")\n      }else{\n        out.println(\"NO\")\n      }\n    }\n\n    //code ends here\n    out.flush\n    out.close\n  }\n}\n\n", "src_uid": "a74adcf0314692f8ac95f54d165d9582"}
{"source_code": "import java.io._\nimport scala.annotation.tailrec\n\nobject Easy {\n  val reader = new BufferedReader(new InputStreamReader(System.in))\n  def readInt = reader.readLine().toInt\n  def readInts = reader.readLine().split(\" \").map(_.toInt)\n\n  def ans = reader.readLine().map(_.toInt).zip(reader.readLine().map(_.toInt)).map {\n    case (a, b) => a ^ b\n  }.mkString\n\n  def main(a: Array[String]) {\n    println(ans)\n  }\n}\n", "src_uid": "3714b7596a6b48ca5b7a346f60d90549"}
{"source_code": "import scala.collection.mutable.Stack\nimport scala.collection.mutable.Queue\nimport java.io.FileInputStream\n\nobject Main {\n\n    def main(args: Array[String]): Unit = {\n      var s = new java.util.Scanner(System.in)\n      val (r, g, b) = (s.nextInt(), s.nextInt(), s.nextInt())\n      val l = List(r, g, b)\n      var m = List(l.min)\n      if (l.min > 1) m = m :+ (l.min-1)\n      if (l.min > 2) m = m :+ l.min-2\n      println ((m map (y => y + (l map (x => (x- y) / 3) foldLeft 0)(_+_))).max)\n      \n    }\n}", "src_uid": "acddc9b0db312b363910a84bd4f14d8e"}
{"source_code": "import scala.collection.mutable._\nimport scala.io.StdIn._;\n\nobject A {\n  def f(arg:Int): Int ={\n    var ans=1;\n    var x:Int=arg;\n\n    while(x>=10)\n      {\n        ans+=1;\n        x+=1;\n        while(x%10==0) x/=10\n      }\n\n    return ans+8\n  }\n\n\n  def main(args: Array[String]) = {\n    val n=readLine().toInt;\n    println(f(n));\n  }\n\n}", "src_uid": "055fbbde4b9ffd4473e6e716da6da899"}
{"source_code": "object HelloWorld {\n  def main(args: Array[String]): Unit = {\n    val input = scala.io.StdIn.readInt()\n    println(beautifuls.map(binaryToDec(_)).takeWhile(_<=input).filter(input%_ == 0).toList.max)\n  }\n  \n  def beautifuls: Stream[String] = \"1\" #:: beautifuls.map(\"1\" + _ + \"0\")\n\n  def binaryToDec: String => Int = x => Integer.parseInt(x, 2)\n}", "src_uid": "339246a1be81aefe19290de0d1aead84"}
{"source_code": "object B extends App {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }\n\n  val Array(p, x, y) = readLongs(3)\n\n  //FIXME Console.setOut(new java.io.BufferedOutputStream(Console.out))\n\n  def check(s: Long): Boolean = {\n    var i = (s / 50) % 475\n    var j = 0\n    var ok = false\n    while (j < 25) {\n      i = (i * 96 + 42) % 475\n      j += 1\n      if (26 + i == p) ok = true\n    }\n    ok\n  }\n\n  var hacks = 0\n  var res = -1\n  var score = x\n  while (res < 0 && score >= y) {\n    if (check(score)) res = hacks\n    score -= 50\n  }\n\n  score = x\n  while (res < 0) {\n    if (check(score)) res = hacks\n    else {\n      score += 50\n      hacks += 1\n      if (check(score)) res = hacks\n      score += 50\n    }\n  }\n\n  println(res)\n}\n", "src_uid": "c9c22e03c70a94a745b451fc79e112fd"}
{"source_code": "object test6 extends App {\n    val Array(a,b,c)=readLine.split(\" \").map(_.toInt).sortBy(x=>x)\n    val rows=(b+a-1)\n    var sum=0\n    for(i<-0 until rows/2) if(i<a) sum+=c+i else sum+=c+a-1\n    sum*=2\n    if(rows%2==1)\n    \tif(rows/2<a) sum+=rows/2+c else sum+=c+a-1\n    \t\n    println(sum)\n}", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da"}
{"source_code": "import java.io._\nimport java.util.Locale\nimport scala.annotation.tailrec\n\nobject Easy {\n  val reader = new BufferedReader(new InputStreamReader(System.in))\n  def readInt = reader.readLine().toInt\n  def readInts = reader.readLine().split(\" \").map(_.toInt)\n  def readLongs = reader.readLine().split(\" \").map(_.toLong)\n\n  val Array(x, y) = readInts\n  val s = x.abs + y.abs\n  val ans = if(x < 0 && y < 0) Array(-s, 0, 0, -s) else\n    if(x < 0 && y > 0) Array(-s, 0, 0, s) else\n    if(x > 0 && y < 0) Array(0, -s, s, 0) else\n    Array(0, s, s, 0)\n\n\n  def main(a: Array[String]) {\n    println(ans.mkString(\" \"))\n  }\n}\n", "src_uid": "e2f15a9d9593eec2e19be3140a847712"}
{"source_code": "//package me.jetblack.cf\n\nimport java.util.Scanner\n\nobject CipherSquare extends App {\n\n  val n = new Scanner(System.in).nextInt()\n\n  val cnt = Array.ofDim[Long](9)\n\n  (1 to n).foreach { i => cnt(i % 9) += 1 }\n\n  val all = (for {\n    i <- 0 until 9\n    j <- 0 until 9\n  } yield {\n    cnt(i) * cnt(j) * cnt((i * j) % 9)\n  }).sum\n\n  var sum = 0L\n  var i = 1\n  while (i <= n) {\n    var j = 1\n    while (j <= n / i) {\n      sum += 1\n      j += 1\n    }\n    i += 1\n  }\n\n  println(all - sum)\n\n}\n", "src_uid": "fc133fe6353089a0ebee08dec919f608"}
{"source_code": "object A {\n  def main(args: Array[String])  {\n    val sc = new java.util.Scanner(System.in)\n    val l, r = sc.nextInt()\n    var myList1 = Array(1, 2, 3, 4, 6, 9, 8, 12, 18, 27, 16, 24, 36, 54, 81, 32, 48, 72, 108, 162, 243, 64, 96, 144, 216, 324, 486, 729, 128, 192, 288, 432, 648, 972, 1458, 2187, 256, 384, 576, 864, 1296, 1944, 2916, 4374, 6561, 512, 768, 1152, 1728, 2592, 3888, 5832, 8748, 13122, 19683, 1024, 1536, 2304, 3456, 5184, 7776, 11664, 17496, 26244, 39366, 59049, 2048, 3072, 4608, 6912, 10368, 15552, 23328, 34992, 52488, 78732, 118098, 177147, 4096, 6144, 9216, 13824, 20736, 31104, 46656, 69984, 104976, 157464, 236196, 354294, 531441, 8192, 12288, 18432, 27648, 41472, 62208, 93312, 139968, 209952, 314928, 472392, 708588, 1062882, 1594323, 16384, 24576, 36864, 55296, 82944, 124416, 186624, 279936, 419904, 629856, 944784, 1417176, 2125764, 3188646, 4782969, 32768, 49152, 73728, 110592, 165888, 248832, 373248, 559872, 839808, 1259712, 1889568, 2834352, 4251528, 6377292, 9565938, 14348907, 65536, 98304, 147456, 221184, 331776, 497664, 746496, 1119744, 1679616, 2519424, 3779136, 5668704, 8503056, 12754584, 19131876, 28697814, 43046721, 131072, 196608, 294912, 442368, 663552, 995328, 1492992, 2239488, 3359232, 5038848, 7558272, 11337408, 17006112, 25509168, 38263752, 57395628, 86093442, 129140163, 262144, 393216, 589824, 884736, 1327104, 1990656, 2985984, 4478976, 6718464, 10077696, 15116544, 22674816, 34012224, 51018336, 76527504, 114791256, 172186884, 258280326, 387420489, 524288, 786432, 1179648, 1769472, 2654208, 3981312, 5971968, 8957952, 13436928, 20155392, 30233088, 45349632, 68024448, 102036672, 153055008, 229582512, 344373768, 516560652, 774840978, 1162261467, 1048576, 1572864, 2359296, 3538944, 5308416, 7962624, 11943936, 17915904, 26873856, 40310784, 60466176, 90699264, 136048896, 204073344, 306110016, 459165024, 688747536, 1033121304, 1549681956, 2097152, 3145728, 4718592, 7077888, 10616832, 15925248, 23887872, 35831808, 53747712, 80621568, 120932352, 181398528, 272097792, 408146688, 612220032, 918330048, 1377495072, 4194304, 6291456, 9437184, 14155776, 21233664, 31850496, 47775744, 71663616, 107495424, 161243136, 241864704, 362797056, 544195584, 816293376, 1224440064, 1836660096, 8388608, 12582912, 18874368, 28311552, 42467328, 63700992, 95551488, 143327232, 214990848, 322486272, 483729408, 725594112, 1088391168, 1632586752, 16777216, 25165824, 37748736, 56623104, 84934656, 127401984, 191102976, 286654464, 429981696, 644972544, 967458816, 1451188224, 33554432, 50331648, 75497472, 113246208, 169869312, 254803968, 382205952, 573308928, 859963392, 1289945088, 1934917632, 67108864, 100663296, 150994944, 226492416, 339738624, 509607936, 764411904, 1146617856, 1719926784, 134217728, 201326592, 301989888, 452984832, 679477248, 1019215872, 1528823808, 268435456, 402653184, 603979776, 905969664, 1358954496, 536870912, 805306368, 1207959552, 1811939328, 1073741824, 1610612736 )\n    var total = 0;\n    for ( x <- myList1  ) {\n         if (x >= l){\n            if(x <= r){\n             total += 1; \n            }\n         }\n      }\n\n      println(total);      \n  }\n}", "src_uid": "05fac54ed2064b46338bb18f897a4411"}
{"source_code": "object C {\n  import InOut._\n  def main(args: Array[String]): Unit = {}\n\n  val n, p, w, d = nextBig\n\n  val g = w.gcd(d)\n\n  if (p % g == 0) {\n    val pp = p / g\n    val ww = w / g\n    val dd = d / g\n    val draw = pp * dd.modInverse(ww) % ww\n    val won = (p - draw * d) / w\n    val lost = n - won - draw\n    if (won >= 0 && draw >= 0 && lost >= 0 && won * w + draw * d == p) out.println(s\"$won $draw $lost\")\n    else out.println(-1)\n  } else out.println(-1)\n  out.flush()\n\n  final object InOut {\n    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n    val out = new java.io.PrintWriter(System.out, false)\n    private[this] var tokenizer: java.util.StringTokenizer = _\n    def nextToken: String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new java.util.StringTokenizer(in.readLine)\n      tokenizer.nextToken\n    }\n    def nextInt = Integer.parseInt(nextToken)\n    def nextLong = java.lang.Long.parseLong(nextToken)\n    def nextBig = BigInt(nextToken)\n    def nextInts(n: Int) = Array.fill(n) { nextInt }\n    def nextLongs(n: Int) = Array.fill(n) { nextLong }\n    def nextBigs(n: Int) = Array.fill(n) { nextBig }\n    def nextLine = in.readLine\n  }\n}\n", "src_uid": "503116e144d19eb953954d99c5526a7d"}
{"source_code": "import java.util.Scanner\n\n/**\n * Created by hama_du on 2014/06/21.\n */\nobject ProblemA extends App {\n  class Card(_color: Int, _number: Int) extends Ordered[Card] {\n    val color = _color\n    val number = _number\n    val colorNumber = color * 10 + number\n\n    def compare(that: Card) = {\n      this.colorNumber - that.colorNumber\n    }\n  }\n\n  class Detecting(_card: Card, colorHint: Int, numberHint: Int) {\n    val color = _card.color\n    val number = _card.number\n    var foundColor = ((1<<color) & colorHint) >= 1\n    var foundNumber = ((1<<number) & numberHint) >= 1\n  }\n\n  def colorToNum(c: Char): Int = {\n    c match {\n      case 'R' => 0\n      case 'G' => 1\n      case 'B' => 2\n      case 'Y' => 3\n      case 'W' => 4\n      case _ => -1\n    }\n  }\n\n  def doit(initialCards: Array[Card], colorHint: Int, numberHint: Int): Boolean = {\n    val cards = initialCards.map(c => {\n      new Detecting(c, colorHint, numberHint)\n    })\n\n    var upd = true\n    while (upd) {\n      upd = false\n\n      // color ok\n      if (cards.filterNot(c =>  c.foundColor).map(c => c.color).distinct.size == 1) {\n        cards.foreach(c => c.foundColor = true)\n      }\n\n      // number ok\n      if (cards.filterNot(c =>  c.foundNumber).map(c => c.number).distinct.size == 1) {\n        cards.foreach(c => c.foundNumber = true)\n      }\n\n      // distinct card\n      val leftCards = cards.filterNot(c => c.foundColor && c.foundNumber)\n      leftCards.foreach(c => {\n        val sameCards = leftCards.filter({\n          c2 => (c.foundColor && c.color == c2.color) || (c.foundNumber && c.number == c2.number)\n        }).map(c2 => (c2.color, c2.number)).distinct\n        if (sameCards.size == 1) {\n          c.foundColor = true\n          c.foundNumber = true\n          upd = true\n        }\n      })\n    }\n    cards.filter(c => c.foundColor && c.foundNumber).size == cards.size\n  }\n\n  def solve(cards: Array[Card]): Int = {\n    val list = for {\n      i <- 0 until (1<<5)\n      j <- 0 until (1<<5)\n      if doit(cards, i, j)\n    } yield {\n      // println(i + \"/\" + j)\n      Integer.bitCount(i) + Integer.bitCount(j)\n    }\n    list.min\n  }\n\n  val in = new Scanner(System.in)\n  val n = in.nextInt\n  val cards = (0 until n).map(i => {\n    val ch = in.next.toCharArray\n    new Card(colorToNum((ch(0))), ch(1)-'1')\n  }).toArray\n\n  println(solve(cards))\n}\n", "src_uid": "3b12863997b377b47bae43566ec1a63b"}
{"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.collection.mutable.ListBuffer\nimport scala.util.Random\nimport scala.util.control.Breaks._\n\nobject P371A extends App {\n  val sc = new Scanner(System.in)\n  val out = new PrintWriter(System.out)\n\n  val N, K = sc.nextInt\n\n  val diff = (ls: List[Int]) => {\n      ls.count(_ == 1) min ls.count(_ == 2)\n    }\n  val res = List.fill(N / K, K)(sc.nextInt).transpose.map(diff).sum\n\n  out.println(res)\n  out.close\n}\n\n\n\n\n\n", "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281"}
{"source_code": "object CF_E61_A {\n// date: 05/03/2019\n\n  type In  = (Int, Int, Int, Int)\n  type Out = Int\n  \n  def solve(in: In): Out = {\n    val (c1, c2, c3, c4) = in\n    if(c1 == c4 && (c3 == 0 || c1 > 0)) 1 else 0\n  }\n\n//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n//   Specify Input and Output formats on RHS here:\n\n  def formatIn(i: Input): In       = (i.int, {i.nextLine; i.int}, {i.nextLine; i.int}, {i.nextLine; i.int})\n  def formatOut(out: Out): String  = out.toString\n\n//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n//   Boilerplate & utility methods that don't change (so ignore): \n\n  import java.util.Scanner\n  import java.io.InputStream\n  import language.implicitConversions\n \n  def main(args: Array[String]): Unit = {\n    val out = new java.io.PrintWriter(System.out)\n    val resultStr = new Input(System.in).solveStr\n    out.println(resultStr)\n    out.close()\n  }\n  \n  class Input(val sc: Scanner) {\n    // This class is useful for convenience, and for mock stdin in test scripts\n    // Remember to call nextLine to advance past the newline character (if required) before taking a whole line\n    def this(i: InputStream)       = this(new Scanner(i))\n    def this(s: String)            = this(new Scanner(s.stripMargin))\n    def int                        = sc.nextInt()\n    def long                       = sc.nextLong()\n    def double                     = sc.nextDouble()\n    def nextLine                   = sc.nextLine()\n    def collect[T](f: String => T) = sc.nextLine().split(\" \").toVector.map(f)\n    def intSeq                     = collect(_.toInt)\n    def doubleSeq                  = collect(_.toDouble)\n    def getLines: Vector[String]   = if (!sc.hasNextLine) Vector.empty \n                                     else sc.nextLine +: getLines\n    def getLines(lineCount: Int)   = {nextLine; (1 to lineCount).map(_ => sc.nextLine)}\n    def solveVal: Out              = (solve _).tupled(formatIn(this))\n    def solveStr: String           = formatOut(solveVal)\n  }\n\n  // Ceiling division for Int & Long\n  // `a` MUST be > 0. Incorrect otherwise.\n  def divideCeil(a: Int, b: Int)   = (a - 1)/b + 1\n  def divideCeil(a: Long, b: Long) = (a - 1)/b + 1\n  \n  // A frequently used number in these comps\n  val modulo = 1000000007\n\n  // For convenience in test scripts, treat a String as an Input \n  implicit def stringToInput(s: String): Input = new Input(s)\n  // Required to make `solveVal` work when input has just 1 value (i.e. not a Tuple)\n  implicit class makeTupledWorkOnFunction1[-T,+R](f: T => R) { \n    def tupled: T => R = x => f(x) \n  }\n}\n", "src_uid": "b99578086043537297d374dc01eeb6f8"}
{"source_code": "/**\n  * @see http://codeforces.com/contest/911/problem/B\n  */\n\nobject BTwoCakes extends App {\n  val Array(n, a, b) = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n\n  val l = for (i <- 1 until n) yield (a / i) min (b / (n - i))\n  println(l max)\n}\n", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e"}
{"source_code": "import java.util.Scanner\n\nobject C635_Scala extends App {\n  val sc = new Scanner(System.in)\n  val sum = sc.nextLong()\n  val xor = sc.nextLong()\n\n  def solve(sum: Long, xor: Long, solutionWithCarry: Long, solutionWithoutCarry: Long): Long = {\n    if (sum == 0 && xor == 0) {\n      solutionWithoutCarry\n    } else (sum % 2, xor % 2) match {\n      case (1, 1) => solve(sum / 2, xor / 2, 0, solutionWithoutCarry * 2)\n      case (1, 0) => solve(sum / 2, xor / 2, solutionWithCarry, solutionWithCarry)\n      case (0, 1) => solve(sum / 2, xor / 2, solutionWithCarry * 2, 0)\n      case (0, 0) => solve(sum / 2, xor / 2, solutionWithoutCarry, solutionWithoutCarry)\n    }\n  }\n\n  def solve2(sum: Long, xor: Long): Long = {\n    solve(sum, xor, 0, 1) - (if (sum == xor) 2 else 0)\n  }\n\n  println(solve2(sum, xor))\n}", "src_uid": "18410980789b14c128dd6adfa501aea5"}
{"source_code": "object Main {\n  def main(args: Array[String]) {\n    val n = readInt();\n    var primes = Seq(2, 3)\n    var count = 0\n    for (i <- 4 to n) {\n      var divs = Set[Int]()\n      for (div <- primes) {\n        if (i % div == 0) {\n          if (i / div == div) divs += (div)\n          else if (primes.find(_ == i / div) != None) divs += (div, i / div)\n          else divs += (div)\n        }\n      }\n      if (divs.size == 0) primes ++= Seq(i)\n      else if (divs.size == 2) count += 1\n    }\n    println(count)\n  }\n}", "src_uid": "356666366625bc5358bc8b97c8d67bd5"}
{"source_code": "object A574 {\n\n  import IO._\n\n  def main(args: Array[String]): Unit = {\n    val Array(n) = readInts(1)\n    val in = readInts(n)\n    val ini = in(0)\n    while(in.max > in(0) || in.count(_ == in.max) != 1) {\n      //take 1 from max\n      var break = false\n      var i = 1\n      while(!break && i < n) {\n        if(in(i) == in.max) {\n          in(i) -= 1\n          in(0) += 1\n          break = true\n        }\n        i += 1\n      }\n    }\n    println(in(0) - ini)\n  }\n\n  object IO {\n    @inline def read: String = scala.io.StdIn.readLine\n\n    @inline def tokenizeLine = new java.util.StringTokenizer(read)\n\n    def readInts(n: Int): Array[Int] = {\n      val tl = tokenizeLine;\n      Array.fill(n)(tl.nextToken.toInt)\n    }\n\n    def readLongs(n: Int): Array[Long] = {\n      val tl = tokenizeLine;\n      Array.fill(n)(tl.nextToken.toLong)\n    }\n\n    def readBigs(n: Int): Array[BigInt] = {\n      val tl = tokenizeLine;\n      Array.fill(n)(BigInt(tl.nextToken))\n    }\n  }\n\n}\n", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58"}
{"source_code": "\nobject problemA {\n    import java.io.{BufferedReader, FileInputStream, InputStreamReader}\n    import scala.collection.mutable.ArrayBuffer\n    import scala.collection.mutable\n    import scala.util.control.Breaks._\n    import scala.collection.JavaConverters._\n\n    val source = System.in\n    implicit val reader = new BufferedReader(new InputStreamReader(source))\n\n    def read()(implicit reader: BufferedReader): String = reader.readLine().split(\" \")(0)\n    def readArray()(implicit reader: BufferedReader): Array[String] = reader.readLine().split(\" \")\n    def readString()(implicit reader: BufferedReader): String = reader.readLine()\n\n    def main(args: Array[String]): Unit = {\n        val s = readString().toCharArray\n        if (s.filter(_ == 'o').size == 0 || s.filter(_ == '-').size % s.filter(_ == 'o').size == 0) print(\"YES\")\n        else print(\"NO\")\n    }\n}\n", "src_uid": "6e006ae3df3bcd24755358a5f584ec03"}
{"source_code": "import scala.io.StdIn\n\n/**\n  * Created by vladimir on 08.06.17.\n  */\nobject A339 extends App {\n  print(StdIn.readLine().split('+').sorted.mkString(\"+\"))\n}\n", "src_uid": "76c7312733ef9d8278521cf09d3ccbc8"}
{"source_code": "import java.io._\nimport scala.annotation.tailrec\n\nobject Easy {\n  val reader = new BufferedReader(new InputStreamReader(System.in))\n  def readInt = reader.readLine().toInt\n  def readInts = reader.readLine().split(\" \").map(_.toInt)\n\n  val switches = for(_ <- 1 to 3) yield readInts.map(_ % 2)\n  val ans = Array.ofDim[Int](3, 3)\n  val dx = Array(0, 1, 0, -1)\n  for(r <- 0 until 3) for(c <- 0 until 3) {\n    ans(r)(c) ^= switches(r)(c)\n    (for(k <- 0 until 4) yield Array(r + dx(k), c + dx(k ^ 1))).filterNot(_.exists(x => x < 0 || x >= 3)).foreach {\n      case Array(rr, cc) => ans(rr)(cc) ^= switches(r)(c)\n    }\n  }\n\n  def main(a: Array[String]) {\n    println(ans.map(_.map(1 -).mkString).mkString(\"\\n\"))\n  }\n}\n", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6"}
{"source_code": "object Solution extends App {\n  val in = scala.io.Source.stdin.getLines()\n  val Array(n, fine) = in.next().split(\" \").map(_.toInt)\n  val data = in.next().split(\" \").map(_.toInt).sorted\n  val m = in.next().toInt\n\n  println(data.take(m).sum - fine * Math.max(m - n, 0))\n\n}\n", "src_uid": "5c21e2dd658825580522af525142397d"}
{"source_code": "\nimport scala.collection.mutable\nimport util.control.Breaks._\n\nobject Main {\n  def main(args: Array[String]): Unit = {\n    val line = readLine().split(\" \").map(_.toInt)\n    val n = line(0)\n    val k = line(1)\n\n    val dist = Math.min(Math.abs(k-1), Math.abs(n-k))\n    println(n * 3 + dist)\n  }\n}\n", "src_uid": "24b02afe8d86314ec5f75a00c72af514"}
{"source_code": "import scala.io.StdIn._\n\nobject Main extends App {\n  val Array(n, k) = readLine().split(\" \").map(_.toInt)\n  val minutes = 4 * 60 - k\n  val gen = Stream.from(1).map(_ * 5)\n  val ans = gen.scanLeft(0)(_ + _).takeWhile(_ <= minutes).length\n  println(math.min(ans - 1, n))\n}", "src_uid": "41e554bc323857be7b8483ee358a35e2"}
{"source_code": "import java.util.Scanner\n\nimport scala.io.StdIn._\n\n/**\n  * Created by roman on 21.03.2016.\n  */\nobject Task1 {\n  def main(args: Array[String]) {\n    val sc = new Scanner(System.in)\n\n    val n = sc.nextInt()\n    val a = sc.nextInt()\n\n    println(if (a%2==0) (n-a)/2+1 else (a+1)/2)\n  }\n}\n", "src_uid": "aa62dcdc47d0abbba7956284c1561de8"}
{"source_code": "import scala.collection.mutable.MutableList\n\nobject GameWithSticks {\n\tdef main (args: Array[String]) {\n\t\tval scanner = new java.util.Scanner(System.in);\n\t\tvar width = scanner.nextInt();\n\t\tvar height = scanner.nextInt();\n\t\tval min = Math.min(width, height)\n\t\tif (min % 2 == 1) {\n\t\t\tprintln(\"Akshat\")\n\t\t}\n\t\telse {\n\t\t\tprintln(\"Malvika\")\n\t\t}\n\t}\n}", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4"}
{"source_code": "/**\n  * Created by MacDrive on 22.09.2017.\n  */\nobject ProblemA extends App{\n  val input = scala.io.StdIn.readLine()\n\n  val noZero  = input.reverse.dropWhile(x => x == '0')\n\n  val split = noZero.splitAt(noZero.length/2)\n\n  val ready = if (split._1.length != split._2.length) (split._1, split._2.tail) else split\n\n  if (ready._1 == ready._2.reverse) print(\"YES\") else print(\"NO\")\n\n}\n", "src_uid": "d82278932881e3aa997086c909f29051"}
{"source_code": "object A353 {\n\n  import IO._\n\n  def main(args: Array[String]): Unit = {\n    val Array(n) = readInts(1)\n    val in = Array.fill(n)(readInts(2))\n    if(in.map(_.sum).sum%2 == 0) {\n      val first = in.map(_(0)).sum % 2\n      val second = in.map(_(1)).sum % 2\n      if(first == 0 && second == 0) {\n        println(\"0\")\n      } else {\n        val index = in.exists{ arr =>\n          if(arr(0)%2 == 0)\n            arr(1)%2 == 1\n          else\n            arr(1)%2 == 0\n        }\n\n        if(index) {\n          println(\"1\")\n        } else {\n          println(\"-1\")\n        }\n      }\n    } else {\n      println(\"-1\")\n    }\n  }\n\n  object IO {\n    @inline def read: String = scala.io.StdIn.readLine\n\n    @inline def tokenizeLine = new java.util.StringTokenizer(read)\n\n    def readInts(n: Int): Array[Int] = {\n      val tl = tokenizeLine;\n      Array.fill(n)(tl.nextToken.toInt)\n    }\n\n    def readLongs(n: Int): Array[Long] = {\n      val tl = tokenizeLine;\n      Array.fill(n)(tl.nextToken.toLong)\n    }\n\n    def readBigs(n: Int): Array[BigInt] = {\n      val tl = tokenizeLine;\n      Array.fill(n)(BigInt(tl.nextToken))\n    }\n  }\n\n}\n", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43"}
{"source_code": "import scala.io.StdIn._\n\nobject Codeforces extends App {\n  val Array(n, m) = readLine split ' ' map(_.toInt)\n  val first = readLine split ' ' map(_.toInt) toSet\n  val second = readLine split ' ' map(_.toInt) toSet\n\n  val Array(minFirst, minSecond) = Array(first min, second min) sorted\n  val minIntersect = first intersect second match {\n    case s if s nonEmpty => s.min\n    case _ => Int.MaxValue\n  }\n\n  if (minIntersect < 10)\n    println(minIntersect)\n  else\n    println(s\"$minFirst$minSecond\")\n}", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee"}
{"source_code": "// cf 171A not done\n\nobject MysteryNumbers extends App {\n  val ln = (Console.readLine()).split(\" \") map (_.toInt)\n  val a = ln(0)\n  val b = ln(1)\n  \n  def invert(n:Int, acc:Int):Int = n match {\n    case 0 => acc\n    case _ => invert(n/10, acc*10 + (n%10))\n  }\n  \n  val bb = invert(b,0)\n  println(a + bb)\n}", "src_uid": "69b219054cad0844fc4f15df463e09c0"}
{"source_code": "object C519 {\n  @inline def read = scala.io.StdIn.readLine\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(read)\n\n  def readInts(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)\n  }\n\n  def readLongs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong)\n  }\n\n  def readBigs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken))\n  }\n\n  def main(args: Array[String]): Unit = {\n    var Array(n, m) = readLongs(2)\n    var res = 0\n    while(n != 0 && m != 0) {\n      if(n >= m && n >= 2 && m >= 1) {\n        n -= 2\n        m -= 1\n        res += 1\n      } else if(n < m && n >= 1 && m >= 2){\n        m -= 2\n        n -= 1\n        res += 1\n      } else {\n        n = 0; m = 0\n      }\n    }\n    println(res)\n  }\n}", "src_uid": "0718c6afe52cd232a5e942052527f31b"}
{"source_code": "//package c617.a\n\nobject Solution extends App {\n  import scala.io.StdIn\n  val x = StdIn.readInt()\n  val a = x / 5\n  val b = x % 5\n  println(if (b != 0) a + 1 else a)\n}\n", "src_uid": "4b3d65b1b593829e92c852be213922b6"}
{"source_code": "object main extends App with fastIO {\n  \n  var Array(a, b, s) = readLine split(\" \") map(_.toInt)\n  println(if (((s - a.abs - b.abs) & 1) == 0 && s >= a.abs + b.abs) \"Yes\" else \"No\") \n\n  flush  \n}\n\ntrait fastIO {\n  import java.io._\n  \n  val isFile = false\n  val input = \"io.in\"\n  val output = \"io.out\"\n  \n  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))\n  val in = new StreamTokenizer(bf)\n  val out = new PrintWriter(if(isFile) new FileWriter(output) else new OutputStreamWriter(System.out))\n\n  def next: String = {\n    in.ordinaryChars('0', '9')\n    in.wordChars('0', '9')\n    in.nextToken\n    in.sval\n  }\n  \n  def nextInt: Int = {\n    in.nextToken\n    in.nval.toInt\n  }\n  \n  def nextLong:Long ={\n    in.nextToken\n    in.nval.toLong\n  }\n  \n  def nextDouble: Double = {\n    in.nextToken\n    in.nval.toDouble\n  }\n    \n  def readLine: String = bf.readLine()\n  def println(o:Any) = out.println(o)\n  def print(o:Any) = out.print(o)\n  def printf(s:String,o:Any*) = out.printf(s,o)\n  def flush = out.flush\n}", "src_uid": "9a955ce0775018ff4e5825700c13ed36"}
{"source_code": "object P8B {\n    import io.StdIn._\n\n    def main(args:Array[String]) {\n        val m = collection.mutable.HashMap[(Int, Int), Int]()\n        val s = readLine\n        var k = 0\n        def f(i:Int, x:Int, y:Int) {\n            if (!m.contains((x, y))) {\n                m((x, y)) = k\n                k += 1\n            }\n            if (i < s.size) s(i) match {\n                case 'L' => f(i + 1, x, y - 1)\n                case 'R' => f(i + 1, x, y + 1)\n                case 'U' => f(i + 1, x - 1, y)\n                case 'D' => f(i + 1, x + 1, y)\n            }\n        }; f(0, 0, 0)\n        val e = Array.fill(k){collection.mutable.Buffer[Int]()}\n        for (((x, y), i) <- m) {\n            for (xyN <- Array((x + 1, y), (x, y + 1))) m.get(xyN) match {\n                case Some(j) => {e(i).+=(j); e(j).+=(i)}\n                case None => {}\n            }\n        }\n        val d = Array.fill(k){Int.MaxValue}; d(0) = 0\n        val q = collection.mutable.Queue[Int](0)\n        while (q.nonEmpty) {\n            val qH = q.dequeue\n            for (i <- e(qH)) if (d(i) > d(qH) + 1) {\n                d(i) = d(qH) + 1\n                q.enqueue(i)\n            }\n        }\n        println(if (d(k - 1) == s.size) \"OK\" else \"BUG\")\n    }\n}\n", "src_uid": "bb7805cc9d1cc907b64371b209c564b3"}
{"source_code": "object CF499B extends App {\n\n  import java.io.PrintWriter\n  import java.util.Scanner\n\n  val in = new Scanner(System.in)\n  val out = new PrintWriter(System.out)\n\n  def solve = {\n    val participants = in.nextInt\n    val food = new Array[Int](in.nextInt).map(_ => in.nextInt).groupBy(identity).mapValues(_.size).map(_._2).toArray.sorted.reverse\n\n    def tryNDays(days: Int): Boolean = {\n      if (days == 0) return true\n      return food.map(_/days).sum >= participants\n    }\n\n    out.println(Stream.from(0).takeWhile(tryNDays).last)\n  }\n\n  solve\n  out.flush\n  out.close\n}", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe"}
{"source_code": "object Main {\n\n  def main(args: Array[String]) {\n\n    val std = scala.io.StdIn\n    val n = std.readLine().toInt\n    \n    var divisors = std.readLine().split(\" \").map(_.toInt).sorted.reverse.toList\n    val first = divisors.head\n    \n    divisors = divisors.tail\n    var prev = first\n    while (divisors.length > 1 && divisors.head != prev && first % divisors.head == 0 ) {\n      prev = divisors.head\n      divisors = divisors.tail\n    }\n    \n    println(divisors.head + \" \" + first)\n\n  }\n}\n", "src_uid": "868407df0a93085057d06367aecaf9be"}
{"source_code": "import java.util.Scanner\n\n/**\n * Created by hama_du on 2014/03/12.\n */\nobject ProblemC extends App {\n  val in = new Scanner(System.in)\n  val recipe = in.next.toCharArray\n  val B = recipe.count(p => p == 'B')\n  val S = recipe.count(p => p == 'S')\n  val C = recipe.count(p => p == 'C')\n  val b,s,c = in.nextLong\n  val pb,ps,pc = in.nextLong\n  val P = in.nextLong\n\n  println(binSearch(-1, 1000000000000000L))\n\n\n  def binSearch(min: Long, max:Long): Long = {\n    if (max - min <= 1) {\n      min\n    } else {\n      val med = (min + max) / 2\n      if (isPossible(med)) {\n        binSearch(med, max)\n      } else {\n        binSearch(min, med)\n      }\n    }\n  }\n\n  def isPossible(med: Long): Boolean = {\n    val needB = (med * B - b) max 0\n    val needS = (med * S - s) max 0\n    val needC = (med * C - c) max 0\n    (needB * pb + needS * ps + needC * pc) <= P\n  }\n}\n", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e"}
{"source_code": "import scala.collection.mutable.ArraySeq\n\nobject Main {\n\n  def main(args: Array[String]) {\n    val Array(n, l, r) = scala.io.StdIn.readLine split ' ' filter (_.nonEmpty) map (_.toInt)\n    val numDiv3 = (l: Int, r: Int) => r / 3 - (l + 2) / 3 + 1\n    val (a, b, c) = (numDiv3(l, r), numDiv3(l - 1, r - 1), numDiv3(l + 1, r + 1))\n    println((Matrix(ArraySeq(ArraySeq(a, c, b), ArraySeq(b, a, c), ArraySeq(c, b, a))) ** n) (0)(0))\n  }\n\n  val MOD = 1000000007\n\n  class Matrix(val n: Int, val m: Int, val mat: ArraySeq[ArraySeq[Long]]) {\n    def apply(i: Int) = mat(i)\n    def *(oth: Matrix) = {\n      val res = Matrix(n, oth.m)\n      for (i <- 0 until n; k <- 0 until m; j <- 0 until oth.m) {\n        res(i)(j) = (res(i)(j) + mat(i)(k) * oth.mat(k)(j)) % MOD\n      }\n      res\n    }\n    def **(k: Int): Matrix =\n      if (k == 1)\n        this\n      else {\n        val hf = this ** (k / 2)\n        val res = hf * hf\n        if (k % 2 == 0) res\n        else res * this\n      }\n  }\n\n  object Matrix {\n    def apply(mat: ArraySeq[ArraySeq[Long]]) = new Matrix(mat.length, mat(0).length, mat)\n    def apply(n: Int, m: Int) = new Matrix(n, m, ArraySeq.fill(n, m)(0))\n  }\n}", "src_uid": "4c4852df62fccb0a19ad8bc41145de61"}
{"source_code": "object Main\n{\n  def main(args : Array[String]) = {\n    val Array(n,a,b,c) = readLine.split(\" \").map(_.toInt)\n    var res = 0\n    for (i <- 0 to n/a; j <- 0 to n/b)\n    {\n      val r = n-i*a-j*b\n      if (r>=0 && r % c == 0)\n\tres = res max (i + j + r/c)\n    }\n    println(res)\n  }\n}\n", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43"}
{"source_code": "import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._, java.awt._\n\nobject _669A extends CodeForcesApp {\n  override def apply(io: IO) = {\n    val n = io[Int]\n    val ans = 2*(n/3) + (if (n%3 > 0) 1 else 0)\n    io += ans\n  }\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n  lazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)\n  def apply(io: IO): io.type\n  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()\n}\nobject Utils {\n  import scala.collection.mutable, mutable.{Map => Dict}\n  implicit class GenericExtensions[A](val a: A) extends AnyVal {\n    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a\n  }\n  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {\n    def onlyElement: A = t.head.ensuring(t.size == 1)\n    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)\n    def duplicates(implicit b: C of A): C[A] = {\n      val elems = mutable.Set.empty[A]\n      (t collect {case i if !elems.add(i) => i}).to[C]\n    }\n    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}\n    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]\n    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap\n    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)\n    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}\n    def toMutableMultiSet: Dict[A, Int] = {\n      val c = map[A] to 0\n      t.foreach(i => c(i) += 1)\n      c\n    }\n    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap\n  }\n  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)\n  }\n  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)\n  }\n  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {\n    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t\n  }\n  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {\n    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_._1).mapValues(_._2)\n    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_._1).mapValues(_.map(_._2).to[C])\n    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]\n  }\n  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {\n    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap\n    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}\n    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m\n  }\n  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {\n    def notContains(x: A): Boolean = !(s contains x)\n    def toMutable = mutable.Set.empty[A] ++ s\n  }\n  implicit class LongExtensions(val x: Long) extends AnyVal {\n    def bitCount: Int = java.lang.Long.bitCount(x)\n  }\n  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {\n    import Numeric.Implicits._\n    def **(i: Int): A = if (i == 0) n.one else {\n      val h = x ** (i/2)\n      if (i%2 == 0) h * h else h * h * x\n    }\n    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)\n    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf \"Greg\" whenNegative Int.MaxValue\n  }\n  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {\n    import scala.collection.immutable.NumericRange, Integral.Implicits._\n    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x\n    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(n.min(x, y), n.max(x, y), n.one)\n  }\n  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))\n  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)\n  def  asc[A](implicit order: Ordering[A]): Ordering[A] = order\n  def map[K] = new {\n    def to[V](default: V): Dict[K, V] = Dict.empty[K, V] withDefaultValue default // also to(Dict.empty[K2, V])\n  }\n  def memoize[I] = new {\n    def apply[O](f: I => O): I => O = new mutable.HashMap[I, O]() {\n      override def apply(key: I) = getOrElseUpdate(key, f(key))\n    }\n  }\n  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None\n  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)\n  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]\n  val mod: Int = (1e9 + 7).toInt\n  val newLine: String = \"\\n\"\n}\n/***********************************[Scala I/O]*********************************************/\nimport Utils._, java.io._, java.util.StringTokenizer\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends PrintWriter(out, true) with Iterator[String] {\n  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n\n  @inline private[this] def tokenizer() = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    if (tokenizers.nonEmpty) Some(tokenizers.head) else None\n  }\n\n  def apply[A](implicit read: IO.Read[A]): A = read.apply(this)\n  def apply[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(apply).to[C]\n\n  def till(delim: String): String = tokenizer().get.nextToken(delim)\n  def tillEndOfLine(): String = till(\"\\n\\r\")\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n\n  var separator = \" \"\n  private[this] var isNewLine = true\n\n  def +=[A](x: A)(implicit write: IO.Write[A]): this.type = {\n    write(this)(x)\n    this\n  }\n  def ++=[A: IO.Write](xs: Traversable[A]): this.type = this.+=(xs.size).appendNewLine().+=(xs)\n\n  def appendNewLine(): this.type = {\n    println()\n    this\n  }\n\n  override def print(obj: String) = {\n    if (isNewLine) isNewLine = false else super.print(separator)\n    super.print(obj)\n  }\n  override def println() = if (!isNewLine) {\n    super.println()\n    isNewLine = true\n  }\n  override def close() = {\n    flush()\n    in.close()\n    super.close()\n  }\n}\nobject IO {\n  class Read[A](val apply: IO => A) {\n    def map[B](f: A => B): Read[B] = new Read(apply andThen f)\n  }\n  object Read {\n    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r[C, A](r[Int]))\n    implicit val string                                       : Read[String]       = new Read(_.next())\n    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)\n    implicit val boolean                                      : Read[Boolean]      = string.map(_.toBoolean)\n    implicit val int                                          : Read[Int]          = string.map(_.toInt)\n    implicit val long                                         : Read[Long]         = string.map(_.toLong)\n    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))\n    implicit val double                                       : Read[Double]       = string.map(_.toDouble)\n    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))\n    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r[A], r[B]))\n    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r[A], r[B], r[C]))\n    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r[A], r[B], r[C], r[D]))\n  }\n  trait Write[-A] {\n    def apply(out: PrintWriter)(x: A): Unit\n  }\n  trait DefaultWrite {\n    implicit def any[A]: Write[A] = Write(_.toString)\n  }\n  object Write extends DefaultWrite {\n    def apply[A](f: A => String) = new Write[A] {\n      override def apply(out: PrintWriter)(x: A) = out.print(f(x))\n    }\n    implicit val boolean: Write[Boolean] = Write(b => if (b) \"YES\" else \"NO\")\n    implicit def tuple2[A, B]: Write[(A, B)] = Write {case (a, b) => s\"$a $b\"}\n    implicit def iterable[A](implicit write: Write[A]): Write[Traversable[A]] = new Write[Traversable[A]] {\n      override def apply(out: PrintWriter)(xs: Traversable[A]) = {\n        xs foreach write(out)\n        out.println()\n      }\n    }\n  }\n}\n\n", "src_uid": "a993069e35b35ae158d35d6fe166aaef"}
{"source_code": "\n\nimport java.io.PrintWriter\nimport java.util.Scanner\n\n/**\n * Created by arseny on 19.07.14.\n */\nobject C extends App {\n  val home = true\n  val in = new Scanner(System.in)\n  val out = new PrintWriter(System.out)\n\n  def nextInt = in.nextInt\n  def nextLong = in.nextLong\n  def nextDouble = in.nextDouble\n  def nextString = in.next\n\n  def solve() = {\n    val n = nextLong\n    val m = nextLong\n    val k = nextLong\n    if (k > n + m - 2) {\n      out.println(-1)\n    } else {\n      def minSquare(t: Long) = {\n        (n / (t + 1)) * (m / (k - t + 1))\n      }\n      val l = math.max(0, k - m + 1)\n      val r = math.min(k, n - 1)\n      var max = l\n      if (minSquare(r) > minSquare(max)) {\n        max = r\n      }\n      if (r != 0 && minSquare(r - 1) > minSquare(max)) {\n        max = r - 1\n      }\n      if (l != k && minSquare(l + 1) > minSquare(max)) {\n        max = l + 1\n      }\n      out.println(minSquare(max))\n    }\n  }\n\n  try {\n    solve()\n  } catch {\n    case _: Exception => sys.exit(9999)\n  } finally {\n    out.flush()\n    out.close()\n  }\n}\n", "src_uid": "bb453bbe60769bcaea6a824c72120f73"}
{"source_code": "\n/**\n  * Created by octavian on 13/02/2016.\n  */\nobject Cards {\n\n  def main(args: Array[String]) = {\n\n    //System.setIn(new FileInputStream(\"./src/cards.in\"))\n    //System.setOut(new PrintStream(new FileOutputStream(\"./src/cards.out\")))\n\n    val n = readInt()\n    val a: Array[Char] = readLine().toCharArray\n    var count = Array(0, 0, 0)\n    var chars = Array('B', 'R', 'G')\n    for(i <- 0 until a.length) {\n\n      a(i) match {\n        case 'B' => count(0) += 1\n        case 'R' => count(1) += 1\n        case 'G' => count(2) += 1\n      }\n    }\n\n    println(computePos(count, chars).sorted.mkString)\n  }\n\n  def computePos(count: Array[Int], chars: Array[Char]): Array[Char] = {\n    for(i <- 0 until 3) {\n      for(j <- 0 until 3) {\n        for(k <- 0 until 3) {\n          if(i != j && i != k && j != k) {\n            if(count(i) > 0 && count(j) == 0 && count(k) == 0) {\n              //println(\"In 1: \" + i + \" \" + j + \" \" + k)\n              return Array(chars(i))\n            }\n            if(count(i) == 1 && count(j) == 1 && count(k) == 0) {\n              //println(\"In 1: \" + i + \" \" + j + \" \" + k)\n              return Array(chars(k))\n            }\n            if(count(i) > 1 && count(j) == 1 && count(k) == 0) {\n              //println(\"In 1: \" + i + \" \" + j + \" \" + k)\n              return Array(chars(j), chars(k))\n            }\n          }\n        }\n      }\n    }\n    return chars\n  }\n\n}\n", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f"}
{"source_code": "object Main {\n  def main(args: Array[String]) {\n    val Array(a, b) = readLine().split(\" \").map(_.toInt)\n    \n    var rest = a\n    var sum = a\n    while(rest >= b) {\n      sum += rest / b\n      rest = rest / b + rest % b\n    }\n    println(sum)\n  }\n}", "src_uid": "a349094584d3fdc6b61e39bffe96dece"}
{"source_code": "import scala.io._\nimport scala.collection.mutable._\nimport java.util.StringTokenizer\n\nobject HelloWorld {\n\n  def main(args: Array[String]): Unit = {\n    var Array(l, d, v, g, r) = readLine.split(\" \").map(_.toDouble);\n    var result: Double = 0;\n    var timeToTraffic = d / v;\n    var mod = timeToTraffic % (g + r);\n    var green = if (mod >= 0 && mod < g) true else false\n    if (green) {\n      result = l / v;\n    } else {\n      result = d / v + (r - (mod - g)) + (l - d) / v;\n    }\n    println(result);\n  }\n\n}", "src_uid": "e4a4affb439365c843c9f9828d81b42c"}
{"source_code": "import java.util.Scanner\n\nobject Main {\n\n  def sqr(x: Long) = x * x\n\n  def powmod(x: Long, n: Long, p: Long): Long = {\n    if (n == 1) x\n    else if (n % 2 == 1) (powmod(x, n - 1, p) * x) % p\n    else sqr(powmod(x, n / 2, p)) % p\n  }\n\n  def C(n: Int, k: Int) = {\n    var res = BigInt(1)\n    for (i <- n - k + 1 to n) {\n      res = res * i\n    }\n    for (i <- 1 to k.toInt) {\n      res = res / i\n    }\n    res\n  }\n\n  def fact(n: Int) = {\n    var res = BigInt(1)\n    for (i <- 1 to n) {\n      res = res * i\n    }\n    res\n  }\n\n  def gcd(a: Long, b: Long): Long = if (b == 0) a else gcd(b, a % b)\n\n  def lcm(a: Long, b: Long) = a / gcd(a, b) * b\n\n  def main(args: Array[String]): Unit = {\n    val in = new Scanner(System.in)\n\n    val primes = Array(2, 3, 5, 7)\n\n    val R = in.nextLong()\n\n    var res = 0L\n\n    for (mask <- 0 until (1 << primes.length)) {\n      var prod = 1L\n      var cnt = 0\n      for (i <- primes.indices) {\n        if ((mask & (1 << i)) != 0) {\n          prod = prod * primes(i)\n          cnt = cnt + 1\n        }\n      }\n      //System.err.println(prod)\n      res = res + (if (cnt % 2 == 0) 1 else -1) * (R / prod)\n    }\n\n    println(res)\n\n  }\n}\n", "src_uid": "e392be5411ffccc1df50e65ec1f5c589"}
{"source_code": "import java.util.Scanner\n\nobject Main {\n\n\tdef main(args: Array[String]): Unit = {\n\t\tval scanner = new Scanner (System.in)\n\t\tval s = scanner.next ()\n\t\tval t = s.sorted.reverse\n\t\tval ans = t.takeWhile(c => c == t.head)\n\t\tprintln (ans)\n\t}\n\n}\n", "src_uid": "9a40e9b122962a1f83b74ddee6246a40"}
{"source_code": "object Main {\n  def main(args: Array[String]) {\n    val op = readLine().split(\" \").map(_.toInt)\n    val a = readLine().split(\" \").map(_.toInt)\n    val n = op(0)\n    val m = op(1)\n    val k = op(2)\n    \n    val r = a.sorted.reverse.scanLeft(k)(_ + _ - 1)\n    val count = if(m < k) 0 else r.zipWithIndex.find(_._1 >= m).map(_._2).getOrElse(-1)\n    println(count)\n  }\n}", "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c"}
{"source_code": "import java.util.ArrayList\nimport java.util.StringTokenizer\n//import scala.reflect.io.File\nimport java.io.BufferedReader\nimport java.io.BufferedInputStream\nimport java.io.InputStreamReader\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\n\nobject A_425 {   var br = createBufferedReader(); var debugV = false \n    \n    //COMMENT ME !\n    runTest(Test.sa1)\n    debugV = true\n//    file = File(\"C:\\\\temp\\\\google cj\\\\2014q\\\\c-small.res\")\n  \n  def main(args: Array[String]): Unit = {\n    //---------------------------- parameters reading \n    val l1 = readLine\n    val n = l1.long\n    val k = l1.long\n    \n    val rr = n / k\n    val res = if (rr % 2 == 1) \"YES\" else \"NO\"\n    \n    //---------------------------- parameters reading :end \n    outLn(res)\n    finish\n  }\n  \n  \n  //============================ service code ======================\n\n//  var file:File = null\n  val resultStr = new StringBuilder\n  def outLn(str:String) = resultStr.append(str).append(\"\\n\")\n  def outLn(number:Integer) = resultStr.append(number+\"\").append(\"\\n\")\n  def finish() {\n//    if (file == null || !devEnv) {\n      println(resultStr.toString())\n//    } else {\n//      file.writeAll(resultStr.toString())\n//    }\n  }\n  \n  def readLine() = new Line  \n  class Line {\n    val fullLine = br.readLine()\n    val tok = new StringTokenizer(fullLine, \" \")\n    def int = tok.nextToken().toInt\n    def long = tok.nextToken().toLong\n    def double = tok.nextToken().toDouble\n    def string = tok.nextToken()\n  }\n  \n  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {\n    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);\n    new BufferedReader(new InputStreamReader(bis));\n  }\n  \n  def runTest(str:String) = if (devEnv) { \n    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes(\"ISO-8859-1\")))\n  }\n  \n  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function\n  \n  lazy val devEnv = this.getClass.getCanonicalName.contains(\".\")\n  \n//============================================================================================\nobject Test {\n  \nval sa1 = \"\"\"\n10 4\n\"\"\"\n\nval sa2 = \"\"\"\n1 1\n\"\"\"\n\nval sa3 = \"\"\"\n\"\"\"\n}\n\n}\n\n", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50"}
{"source_code": "object _937A extends CodeForcesApp {\n  import Utils._, annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._\n\n  override def apply(io: IO): io.type = {\n    val input = io.read[Vector[Int]]\n    val ans = input.filter(_ > 0).distinct.size\n    io.write(ans)\n  }\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n  lazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)\n  def apply(io: IO): io.type\n  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()\n}\nobject Utils {\n  import scala.collection.mutable, mutable.{Map => Dict}\n  type Point = java.awt.geom.Point2D.Double\n  implicit class GenericExtensions[A](val a: A) extends AnyVal {\n    def in(set: collection.Set[A]): Boolean = set(a)\n    def some: Option[A] = Some(a)\n    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a\n  }\n  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {\n    def onlyElement: A = assuming(t.size == 1)(t.head)\n    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)\n    def duplicates(implicit b: C of A): C[A] = {\n      val elems = mutable.Set.empty[A]\n      (t collect {case i if !elems.add(i) => i}).to[C]\n    }\n    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}\n    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)\n    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)\n    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]\n    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap\n    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)\n    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}\n    def toMutableMultiSet: Dict[A, Int] = {\n      val c = map[A] to 0\n      t.foreach(i => c(i) += 1)\n      c\n    }\n    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0\n    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)\n  }\n  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {\n    def sort(from: Int = 0, until: Int = a.length)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)\n  }\n  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {\n    def sort(from: Int = 0, until: Int = a.length)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)\n  }\n  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {\n    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t\n  }\n  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {\n    def key = p._1\n    def value = p._2\n    def toSeq(implicit ev: B =:= A): Seq[A] = Seq(p._1, ev(p._2))\n  }\n  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {\n    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)\n    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C]).withDefaultValue(b().result())\n    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]\n  }\n  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {\n    def lastKeyOption: Option[K] = m.lastOption.map(_.key)\n    def firstKeyOption: Option[K] = m.headOption.map(_.key)\n    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap\n    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}\n    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m\n    def mapValuesSafely[V2](f: V => V2): Map[K, V2] = m.mapValues(f).view.force //Hack to get around https://issues.scala-lang.org/browse/SI-4776\n  }\n  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {\n    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)\n    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)\n    private def removeNode(kv: (K, V)): (K, V) = {\n      m -= kv.key\n      kv\n    }\n  }\n  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {\n    def notContains(x: A): Boolean = !(s contains x)\n    def toMutable = mutable.Set.empty[A] ++ s\n  }\n  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {\n    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}\n    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)\n    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)\n    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}\n    //def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)\n  }\n  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {\n    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero\n    def toEnglish = if(x) \"Yes\" else \"No\"\n  }\n  implicit class IntExtensions(val x: Int) extends AnyVal {\n    import java.lang.{Integer => JInt}\n    def withHighestOneBit: Int = JInt.highestOneBit(x)\n    def withLowestOneBit: Int = JInt.lowestOneBit(x)\n    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)\n    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)\n    def bitCount: Int = JInt.bitCount(x)\n    def setLowestBits(n: Int): Int = x | (left(n) - 1)\n    def clearLowestBits(n: Int): Int = x & left(n, ~0)\n    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)\n    def setBit(i: Int): Int = x | left(i)\n    def clearBit(i: Int): Int = x & ~left(i)\n    def toggleBit(i: Int): Int = x ^ left(i)\n    def getBit(i: Int): Int = (x >> i) & 1\n    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)\n    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)\n  }\n  implicit class LongExtensions(val x: Long) extends AnyVal {\n    import java.lang.{Long => JLong}\n    def withHighestOneBitSet: Long = JLong.highestOneBit(x)\n    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)\n    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)\n    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)\n    def bitCount: Int = JLong.bitCount(x)\n    def setLowestBits(n: Int): Long = x | (left(n) - 1)\n    def clearLowestBits(n: Int): Long = x & left(n, ~0L)\n    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)\n    def setBit(i: Int): Long = x | left(i)\n    def clearBit(i: Int): Long = x & ~left(i)\n    def toggleBit(i: Int): Long = x ^ left(i)\n    def getBit(i: Int): Long = (x >> i) & 1\n    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)\n  }\n  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {\n    import Numeric.Implicits._\n    def **(i: Int): A = if (i == 0) n.one else {\n      val h = x ** (i/2)\n      if (i%2 == 0) h * h else h * h * x\n    }\n    def distance(y: A) = (x - y).abs()\n    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)\n    def whenNegative(f: => A): A = nonNegative.getOrElse(f)   //e.g. students.indexOf(\"Greg\").whenNegative(Int.MaxValue)\n  }\n  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {\n    import scala.collection.immutable.NumericRange, Integral.Implicits._\n    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x\n    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)\n    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)\n  }\n  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new Point(n.toDouble(p._1), n.toDouble(p._2))\n  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)\n  def asc[A](implicit order: Ordering[A]): Ordering[A] = order\n  def map[K] = new {\n    def to[V](default: => V): Dict[K, V] = using(_ => default)\n    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {\n      override def apply(key: K) = getOrElseUpdate(key, f(key))\n    }\n  }\n  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]\n  def memoize[A, B](f: A => B): A ==> B = map[A] using f\n  implicit class FuzzyDouble(val x: Double) extends AnyVal {\n    def  >~(y: Double) = x > y + eps\n    def >=~(y: Double) = x >= y + eps\n    def  ~<(y: Double) = y >=~ x\n    def ~=<(y: Double) = y >~ x\n    def  ~=(y: Double) = (x distance y) <= eps\n  }\n  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {\n    val (xs, ys) = points.unzip\n    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)\n  }\n  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {\n    val shape = new java.awt.geom.GeneralPath()\n    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}\n    points.tail foreach {case (x, y) => shape.lineTo(x, y)}\n    shape.closePath()\n    shape\n  }\n  def until(until: Int): Range = 0 until until\n  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}\n  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}\n  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None\n  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)\n  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]\n  type ==>[A, B] = collection.Map[A, B]\n  val mod: Int = (1e9 + 7).toInt\n  val eps: Double = 1e-9\n}\n/***********************************[Scala I/O]*********************************************/\nimport Utils._, java.io._, java.util.StringTokenizer\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {\n  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n  val printer = new PrintWriter(out, true)\n\n  @inline private[this] def tokenizer() = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    when(tokenizers.nonEmpty)(tokenizers.head)\n  }\n\n  def read[A](implicit read: IO.Read[A]): A = read.apply(this)\n  def read[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(read).to[C]\n\n  def readTill(delim: String): String = tokenizer().get.nextToken(delim)\n  def readTillEndOfLine(): String = readTill(\"\\n\\r\")\n\n  def readAll[A: IO.Read]: (Int, Vector[A]) = {\n    val data = read[Vector[A]]\n    (data.length, data)\n  }\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n\n  def write(obj: Any): this.type = {\n    printer.print(obj)\n    this\n  }\n  def writeLine(): this.type = {\n    printer.println()\n    this\n  }\n  def writeLine(obj: Any): this.type = {\n    printer.println(obj)\n    this\n  }\n  def writeAll(obj: Traversable[Any], separator: String = \" \"): this.type = write(obj mkString separator)\n  def query[A: IO.Read](question: Any): A = writeLine(question).read\n\n  override def flush() = printer.flush()\n  def close() = {\n    flush()\n    in.close()\n    printer.close()\n  }\n}\nobject IO {\n  class Read[A](val apply: IO => A) {\n    def map[B](f: A => B): Read[B] = new Read(apply andThen f)\n  }\n  object Read {\n    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))\n    implicit val string                                       : Read[String]       = new Read(_.next())\n    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)\n    implicit val int                                          : Read[Int]          = string.map(_.toInt)\n    implicit val long                                         : Read[Long]         = string.map(_.toLong)\n    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))\n    implicit val double                                       : Read[Double]       = string.map(_.toDouble)\n    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))\n    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))\n    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]))\n    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]))\n    implicit val boolean                                      : Read[Boolean]      = string map {s =>\n      s.toLowerCase match {\n        case \"yes\" | \"true\" | \"1\" => true\n        case \"no\" | \"false\" | \"0\" => false\n        case _ => s.toBoolean\n      }\n    }\n  }\n}\n\n", "src_uid": "3b520c15ea9a11b16129da30dcfb5161"}
{"source_code": "import java.util.Scanner\n\nobject DashaAndFriends extends App {\n  def parseInts(str: String, numIterations: Integer) = {\n    val scanner = new Scanner(str)\n    val res = (0 until numIterations) map (_ => scanner.nextInt())\n    scanner.close()\n    res\n  }\n\n  val trackInfo = parseInts(Console.readLine(), 2);\n\n  val numObstacles = trackInfo(0)\n\n  val trackLen = trackInfo(1)\n\n  val kefaStats = parseInts(Console.readLine(), numObstacles)\n\n  val sashaStats = parseInts(Console.readLine(), numObstacles)\n\n  def tailRecurse(stats1: Seq[Int], stats2: Seq[Int], tail1: Int, trackLen: Int, distToNextNode1: Int, distToNextNode2: Int, jumps: Int): Int = {\n    val statLen = stats1.size\n    if (jumps >= statLen || distToNextNode1 != distToNextNode2) statLen - jumps\n    else {\n      val head1 = tail1 + jumps\n      val nextNode = stats1((head1) % statLen)\n      val thisNode = (if ((head1) % statLen != 0) stats1((head1 - 1) % statLen) else stats1((head1 - 1) % statLen) - trackLen)\n      tailRecurse(\n        stats1,\n        stats2,\n        tail1,\n        trackLen,\n        distToNextNode1 + nextNode - thisNode,\n        distToNextNode2 + stats2(jumps) - stats2(jumps - 1),\n        jumps + 1)\n    }\n  }\n\n  def checkRotation(stats1: Seq[Int], stats2: Seq[Int], tail1: Int, tail2: Int, distToNextNode1: Int, distToNextNode2: Int, counter: Int): String = {\n    val statLen = stats1.size\n    // TODO mdaniel Remove the counter and replace with better solution for tail\n    if (counter >= statLen) \"NO\" // should this be statlen - 1???\n    else {\n      // TODO mdaniel Improve the logic for passing in tail1 to be for current tail. Now it's more like next tail\n      val allEqualDistance = tailRecurse(stats1, stats2, (tail1 + 1) % statLen, trackLen, distToNextNode1, distToNextNode2, 1)\n      if (allEqualDistance == 0) \"YES\"\n      else {\n        val newTail1 = (tail1 + 1) % statLen\n        checkRotation(stats1, stats2, newTail1, tail2,\n          stats1((newTail1 + 1) % statLen) - stats1(newTail1),\n          distToNextNode2, counter + 1\n        )\n      }\n    }\n  }\n\n  def isSameTrack(stats1: Seq[Int], stats2: Seq[Int], trackLen: Int): String = {\n    val statLen = stats1.size\n\n    val start = statLen - 1\n\n    val distToNextNode1 = trackLen - stats1(start) + stats1(0)\n    val distToNextNode2 = trackLen - stats2(start) + stats2(0)\n\n    checkRotation(stats1, stats2, start, start, distToNextNode1, distToNextNode2, 0)\n\n//    (0 until statLen).filter(x => tailRecurse(stats1, stats2, i, trackLen, distToNextNode1, distToNextNode2, 1) == 0)\n//    for (i <- 0 until statLen) {\n//      val allEqualDistance = tailRecurse(stats1, stats2, i, trackLen, distToNextNode1, distToNextNode2, 1)\n//\n//      if (allEqualDistance == 0) {\n//        return \"YES\"\n//      }\n//\n//      // update head1\n//      head1 = (head1 + 1) % statLen\n//      distToNextNode1 = stats1((i + 1) % statLen) - stats1(head1)\n//      // Start this one at a constant spot\n//      distToNextNode2 = trackLen - stats2(head2) + stats2(0)\n//    }\n//\n//    \"NO\"\n  }\n\n  println(isSameTrack(kefaStats, sashaStats, trackLen))\n}\n", "src_uid": "3d931684ca11fe6141c6461e85d91d63"}
{"source_code": "object Main {\n  def main(args: Array[String]) {\n    val n = readInt()\n    val sq = Math.sqrt(n).ceil.toInt\n    val a = for {\n      i <- 1 to sq\n      j <- i + 1 to sq\n      k <- 1 to n / (i * i + j * j)\n      a = k * (j * j - i * i)\n      b = k * 2 * i * j\n      c = k * (i * i + j * j)\n      if a <= n\n      if b <= n\n      if c <= n\n    } yield(a.min(b), a.max(b), c)\n    println(a.toSet.size)\n  } \n}", "src_uid": "36a211f7814e77339eb81dc132e115e1"}
{"source_code": "object A373 {\n\n  import IO._\n  import collection.{mutable => cu}\n\n  def main(args: Array[String]): Unit = {\n    val Array(k) = readInts(1)\n    val in = Array.fill(4)(read)\n      .flatMap(_.toCharArray.filter(_!='.').map(_-'0'))\n      .groupBy(identity)\n      .mapValues(_.length)\n      .values\n    if(in.exists(_ > 2*k))\n      println(\"NO\")\n    else\n      println(\"YES\")\n  }\n\n  object IO {\n    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n\n    @inline def read: String = input.readLine()\n\n    @inline def tokenizeLine = new java.util.StringTokenizer(read)\n\n    def readInt: Int = tokenizeLine.nextToken.toInt\n\n    def readInts(n: Int): Array[Int] = {\n      val tl = tokenizeLine\n      Array.fill(n)(tl.nextToken.toInt)\n    }\n\n    def readLongs(n: Int): Array[Long] = {\n      val tl = tokenizeLine\n      Array.fill(n)(tl.nextToken.toLong)\n    }\n\n    def readBigs(n: Int): Array[BigInt] = {\n      val tl = tokenizeLine\n      Array.fill(n)(BigInt(tl.nextToken))\n    }\n  }\n\n}\n", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16"}
{"source_code": "/**\n  * @author ShankarShastri\n  *         Algorithm: ProblemA(http://codeforces.com/contest/999/problem/A)\n  */\n\nimport scala.io.StdIn._\n\n\nobject ProblemA {\n  def solveContestForMiska(list: List[Int], k: Int) = {\n    val leftList =  list.takeWhile(_ <= k)\n    leftList.length + list.splitAt(leftList.length)._2.reverse.takeWhile(_ <= k).length\n  }\n  def readLineToList[Int]() = readLine.split(\" \").map(_.toInt).toList\n  def main(args: Array[String]): Unit = {\n   val Array(n,k) = readLine.split(\" \").map(_.toInt)\n    val list = readLineToList()\n    println(solveContestForMiska(list, k))\n  }\n}\n", "src_uid": "ecf0ead308d8a581dd233160a7e38173"}
{"source_code": "object Solution133A extends App {\n\n  def solution() {\n    val s = _string\n    if (s.contains(\"H\") || s.contains(\"Q\") || s.contains(\"9\")) {\n      println(\"YES\")\n    } else {\n      println(\"NO\")\n    }\n  }\n\n  //////////////////////////////////////////////////\n  import java.util.Scanner\n  val SC: Scanner = new Scanner(System.in)\n  def _line: String = SC.nextLine\n  def _int: Int = SC.nextInt\n  def _long: Long = SC.nextLong\n  def _string: String = SC.next\n  solution()\n}", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12"}
{"source_code": "object Main {\n  def main(args: Array[String]) = {\n    val a1 = readLine().split(\" \").map(_.toInt)\n    val a2 = readLine().split(\" \").map(_.toInt)\n    val a3 = readLine().split(\" \").map(_.toInt)\n    \n    val sum = a1.sum + a2.sum + a3.sum\n    a1(0) = sum / 2 - a1.sum\n    a2(1) = sum / 2 - a2.sum\n    a3(2) = sum / 2 - a3.sum\n    println(a1.mkString(\" \"))\n    println(a2.mkString(\" \"))\n    println(a3.mkString(\" \"))    \n  }\n}", "src_uid": "0c42eafb73d1e30f168958a06a0f9bca"}
{"source_code": "object Main extends App{\n  val in= readLine\n  val Array(d1, d2, d3)=in.split(' ').map(_.toInt)\n  println(Math.min(Math.min(Math.min(d1 + d2, d1 + d3), d2 + d3)*2, d1 + d2 + d3))}", "src_uid": "26cd7954a21866dbb2824d725473673e"}
{"source_code": "// http://codeforces.com/contest/394/problem/A\nobject A extends App {\n  val in = readLine()\n  val lr = in.split('=')\n  val ls = lr(0).split('+')\n  val ca = ls(0).count(_ == '|')\n  val cb = ls(1).count(_ == '|')\n  val cc = lr(1).count(_ == '|')\n  val l = ca + cb\n  val r = cc\n  if (l == r) println(in)\n  else if (l-r == 2) {\n    if (ca>1) println(\"|\"*(ca-1)+\"+\"+\"|\"*cb+\"=\"+\"|\"*(cc+1))\n    else  println(\"|\"*ca+\"+\"+\"|\"*(cb-1)+\"=\"+\"|\"*(cc+1))\n  }\n  else if (r-l == 2) {\n    if (cc == 1) println(\"Impossible\")\n    else println(\"|\"*(ca+1)+\"+\"+\"|\"*cb+\"=\"+\"|\"*(cc-1))\n  }\n  else println(\"Impossible\")\n}\n", "src_uid": "ee0aaa7acf127e9f3a9edafc58f4e2d6"}
{"source_code": "object B268 {\n  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)\n\n  def readInts(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)\n  }\n\n  def readLongs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong)\n  }\n\n  def readBigs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken))\n  }\n\n  def main(args: Array[String]): Unit = {\n    val Array(n) = readInts(1)\n    var res = n.toLong\n    for(i <- n-1 to 1 by -1) {\n      res += (n-i)*i\n    }\n    println(res)\n  }\n}", "src_uid": "6df251ac8bf27427a24bc23d64cb9884"}
{"source_code": "object Solution extends App {\n\n  val in = scala.io.Source.stdin.getLines()\n  val Array(n, a, b) = in.next().split(\" \").map(_.toInt)\n  println(n - Math.max(a, n - b - 1))\n}\n", "src_uid": "51a072916bff600922a77da0c4582180"}
{"source_code": "import java.util.Scanner\n\nobject Main {\n  def main(args: Array[String]): Unit = {\n    val is = new Scanner(System.in)\n    val n = is.nextInt()\n\n    var t = 0\n    var i = 1\n    while (t + i <= n) {\n      t += i\n      i += 1\n    }\n\n    i -= 1\n    println(i)\n    val res = (1 to i).updated(i - 1, i + n - t).mkString(\" \")\n    println(res)\n  }\n}", "src_uid": "356a7bcebbbd354c268cddbb5454d5fc"}
{"source_code": "object E extends App {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n\n  val Array(n) = readInts(1)\n  val as = readInts(n)\n  val sum = as.sum\n  var dp = Array.fill(1, sum + 1)(0L)\n  var maxSum = as.max\n\n  for (i <- 0 until n) {\n\n    val dp2 = Array.ofDim[Array[Long]](i + 2)\n    var dd = 0\n    while (dd < dp.length) {\n      dp2(dd) = dp(dd).clone()\n      dd += 1\n    }\n    dp2(dd) = Array.fill(sum + 1)(0L)\n\n    val a = as(i)\n    var j = 1\n    val maxSumCurrent = maxSum\n    while (j <= i) {\n      var s = 0\n      while (s <= maxSumCurrent) {\n        if (dp(j)(s) > 0) {\n          dp2(j + 1)(s + a) = dp2(j + 1)(s + a) + dp(j)(s)\n          if (s + a > maxSum) maxSum = s + a\n        }\n        s += 1\n      }\n      j += 1\n    }\n    dp2(1)(a) += 1\n    dp = dp2\n  }\n\n  val counted = as.groupBy(identity).map {\n    case (a, x) => a -> x.length\n  }\n\n  val pascal = Array.ofDim[Long](n + 1, n + 1)\n  for (i <- pascal.indices) pascal(i)(0) = 1L\n  for (i <- 1 until pascal.length) {\n    var j = 1\n    while (j < pascal(i).length) {\n      pascal(i)(j) = pascal(i - 1)(j - 1) + pascal(i - 1)(j)\n      j += 1\n    }\n  }\n\n  var res = 1\n  if (counted.size == 2) {\n    res = n\n  } else {\n    for ((a, count) <- counted) {\n      for (i <- 1 to count) {\n        if ((dp(i)(a * i) == pascal(count)(i) ||\n          dp(n - i)(sum - a * i) == 1)\n          && i > res) {\n          res = i\n        }\n      }\n    }\n  }\n\n  println(res)\n}\n", "src_uid": "ccc4b27889598266e8efe73b8aa3666c"}
{"source_code": "//package merofeev.contests.codeforces.rnd372\n\nimport java.util.Scanner\n\n/**\n  * @author erofeev \n  * @since 17.09.16\n  */\nobject BAlphabet {\n\n  def main(args: Array[String]): Unit = {\n    val str = new Scanner(System.in).nextLine\n    if (str.length < 26) {\n      println(-1)\n      return\n    }\n\n    val chars = new Array[Int](26)\n    var counter = 0\n\n    for (pos <- 0 until str.length) {\n      if (str(pos) == '?') {\n        counter += 1\n      } else {\n        chars(str(pos) - 'A') += 1\n        if (chars(str(pos) - 'A') == 1) {\n          counter += 1\n        }\n      }\n      if (pos > 25) {\n        if (str(pos - 26) == '?') {\n          counter -= 1\n        } else {\n          chars(str(pos - 26) - 'A') -= 1\n          if (chars(str(pos - 26) - 'A') == 0) {\n            counter -= 1\n          }\n        }\n      }\n      if (counter == 26) {\n        val preres: String = str.substring(pos - 25, pos + 1)\n        val sb = buildRes(str, chars, preres)\n        val left: String = str.substring(0, pos - 25).replaceAll(\"\\\\?\", \"A\")\n        val right: String = str.substring(pos + 1).replaceAll(\"\\\\?\", \"A\")\n        println(left + sb + right)\n        return\n      }\n    }\n    println(-1)\n  }\n\n  def buildRes(str: String, chars: Array[Int], preres: String): String = {\n    val sb = new StringBuilder(preres)\n    var curr = 0\n    while (chars.length > curr && chars(curr) > 0) curr += 1\n    for (elem <- 0 until 26) {\n      if (sb(elem) == '?') {\n        sb.setCharAt(elem, ('A' + curr).toChar)\n        curr += 1\n        while (chars.length > curr && chars(curr) > 0) {\n          curr += 1\n        }\n      }\n    }\n    sb.toString()\n  }\n}", "src_uid": "a249431a4b0b1ade652997fe0b82edf3"}
{"source_code": "object Main {\n  def gcd(a: Int, b: Int): Int =\n    if (a % b == 0) b\n    else gcd(b, a % b)\n    \n  def lcd(a: Int, b: Int): Int = (a.toLong * b.toLong / gcd(a, b)).toInt\n\n  def main(args: Array[String]) {\n    val xyab = readLine().split(\" \").map(_.toInt) \n    val x = xyab(0)\n    val y = xyab(1)\n    val a = xyab(2)\n    val b = xyab(3)\n    val lcd0 = lcd(x, y)\n    val upper = b / lcd0\n    val lower = (a + lcd0 - 1) / lcd0\n    val count = upper - lower + 1\n    println(count)\n  }\n}", "src_uid": "c7aa8a95d5f8832015853cffa1374c48"}
{"source_code": "import annotation.tailrec, collection.mutable, util._, control.Breaks._, math.Ordering.Implicits._\nimport CodeForcesApp._\nobject _588B extends CodeForcesApp[Long]({scanner => import scanner._\n  val n = nextLong\n  val divisors = bag[Long]\n\n  for {\n    i <- 1 to Math.sqrt(n.toDouble).ceil.toInt if n%i == 0\n  } {\n    divisors += i.toLong\n    divisors += n/i\n  }\n  val squares = divisors.map(i => i*i)\n  val lovely = divisors.filterNot(x => squares.exists(s => s > 1 && x%s == 0))\n  //debug(lovely)\n  lovely.max\n}) {\n  override def format(result: Result) = super.format(result)\n}\n/********************************************************************************************/\nimport java.util.Scanner\nabstract class CodeForcesApp[A](solver: Scanner => A) {\n  final type Result = A\n  final def apply(problem: String): String = apply(new Scanner(problem))\n  final def apply(scanner: Scanner): String = format(solver(scanner))\n  def format(result: Result): String = result.toString\n  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))\n}\nobject CodeForcesApp {\n  final val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)\n  final val mod: Int = 1000000007\n  final val eps: Double = 1e-9\n  @inline final def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None\n  @inline final def repeat[A](n: Int)(f: => A): Seq[A] = (1 to n).map(_ => f)\n  @inline final def desc[A: Ordering]: Ordering[A] = implicitly[Ordering[A]].reverse\n  import scala.collection.mutable.{Map => Dict, Set => Bag}\n  final def nil[A]: List[A] = List.empty[A]\n  final def bag[A]: Bag[A] = Bag.empty[A]\n  final def map[A] = new {\n    def to[B](default: B): Dict[A, B] = Dict.empty[A, B] withDefaultValue default\n  }\n}\n", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92"}
{"source_code": "import scala.annotation.tailrec\nimport scala.collection.mutable.ArrayBuffer\nimport scala.io.StdIn._\n\nobject C extends App {\n  val Max = 8e15.toLong + 1\n\n  val m = readLong()\n\n  def count(n: Long): Long = {\n//    print(s\"count($n)=\")\n    var result = 0L\n    var k = 2L\n    while (k * k * k <= n) {\n      result += n / (k.toLong * k * k)\n      k += 1\n    }\n\n//    println(result)\n    result\n  }\n\n  var left = 0L\n  var right = Max\n\n  def find: Long = {\n    while (left < right) {\n      val mid = (left + right) / 2L\n//      println(s\"$left & $right & $mid\")\n      val ans = count(mid)\n      if (ans < m) left = mid + 1\n      else right = mid\n    }\n\n    count(left)\n  }\n\n  val result = find\n  println(if (result == m) left else -1)\n}\n", "src_uid": "602deaad5c66e264997249457d555129"}
{"source_code": "import java.util.Scanner\n//remove if not needed\nimport scala.collection.JavaConversions._\n\nobject Power {\n\n  def main(args: Array[String]) {\n    val kbd = new Scanner(System.in)\n    val n = kbd.nextDouble()\n    val result = Math.pow(5, n).toInt\n    val resultAsString = java.lang.Integer.toString(result)\n    val length = resultAsString.length\n    if (n <= 13) println(resultAsString.substring((length - 2))) else println(\"25\")\n  }\n}\n", "src_uid": "dcaff75492eafaf61d598779d6202c9d"}
{"source_code": "object A extends App {\n  \n  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n\n  val Array(m) = readInts(1)\n  val Array(h1, a1) = readInts(2)\n  val Array(x1, y1) = readInts(2)\n  val Array(h2, a2) = readInts(2)\n  val Array(x2, y2) = readInts(2)\n  \n  def ring(h0: Int, a: Int, x: Long, y: Int) = {\n    val visited = Array.fill(m){ -1 }\n    var h = h0\n    var step = 0\n    while (visited(h) < 0) {\n      visited(h) = step\n      h = ((x.toLong * h + y) % m).toInt\n      step += 1\n    }\n    val cycleStart = visited(h)\n    val cycleSize = step - cycleStart\n    val extraSteps = visited(a)\n    (extraSteps, cycleSize, cycleStart)\n  }\n\n  val (steps1, cycle1, cycleStart1) = ring(h1, a1, x1, y1)\n  val (steps2, cycle2, cycleStart2) = ring(h2, a2, x2, y2)\n\n  if (steps1 < 0 || steps2 < 0) println(-1)\n  else {\n    var step1 = steps1.toLong\n    var step2 = steps2.toLong\n    var i = 0\n    while (i < 100000000) {\n      if (step1 == step2) {\n        println(step1)\n        System.exit(0)\n      } else if (step1 < step2 && steps1 >= cycleStart1) step1 += cycle1\n      else if (step2 < step1 && steps2 >= cycleStart2) step2 += cycle2\n      i += 1\n    }\n    println(-1)\n  }\n}\n", "src_uid": "7225266f663699ff7e16b726cadfe9ee"}
{"source_code": "import scala.io.Source\n\nobject a15 {\n  def main(args: Array[String]): Unit = {\n    val Array(_,s) = Source.stdin.getLines().take(2).toArray\n    println(if (s==\"0\")\n      0\n    else\n      s\"1${s.filter(_ == '0')}\"\n    )\n  }\n\n}\n", "src_uid": "ac244791f8b648d672ed3de32ce0074d"}
{"source_code": "object _982A extends CodeForcesApp {\n  import annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._, Math._\n\n  override def apply(io: IO): io.type = {\n    val _ = io.read[Int]\n    val seating = io.read[String]\n    val isMaximal = !seating.contains(\"11\") && !seating.startsWith(\"00\") && !seating.endsWith(\"00\") && !seating.contains(\"000\") && seating != \"0\"\n    io.write(if (isMaximal) \"Yes\" else \"No\")\n  }\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n  lazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)\n  def apply(io: IO): io.type\n  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()\n}\n/***********************************[Scala I/O]*********************************************/\nimport java.io._, java.util.StringTokenizer\nimport scala.collection.generic.CanBuild\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {\n  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n  val printer = new PrintWriter(out, true)\n\n  @inline private[this] def tokenizer() = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    tokenizers.headOption\n  }\n\n  def read[A](implicit read: IO.Read[A]): A = read.apply(this)\n  def read[C[_], A: IO.Read](n: Int)(implicit b: CanBuild[A, C[A]]): C[A] = Iterator.fill(n)(read).to[C]\n\n  def readTill(delim: String): String = tokenizer().get.nextToken(delim)\n  def readTillEndOfLine(): String = readTill(\"\\n\\r\")\n\n  def readAll[A: IO.Read]: (Int, Vector[A]) = {\n    val data = read[Vector[A]]\n    (data.length, data)\n  }\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n\n  def write(obj: Any): this.type = {\n    printer.print(obj)\n    this\n  }\n  def writeLine(): this.type = {\n    printer.println()\n    this\n  }\n  def writeLine(obj: Any): this.type = {\n    printer.println(obj)\n    this\n  }\n  def writeAll(obj: Traversable[Any], separator: String = \" \"): this.type = write(obj mkString separator)\n  def query[A: IO.Read](question: Any): A = writeLine(question).read\n\n  override def flush() = printer.flush()\n  def close() = {\n    flush()\n    in.close()\n    printer.close()\n  }\n}\nobject IO {\n  class Read[A](val apply: IO => A) {\n    def map[B](f: A => B): Read[B] = new Read(apply andThen f)\n  }\n\n  object Read {\n    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]))\n    implicit val string                                                   : Read[String]       = new Read(_.next())\n    implicit val int                                                      : Read[Int]          = string.map(_.toInt)\n    implicit val long                                                     : Read[Long]         = string.map(_.toLong)\n    implicit val bigInt                                                   : Read[BigInt]       = string.map(BigInt(_))\n    implicit val double                                                   : Read[Double]       = string.map(_.toDouble)\n    implicit val bigDecimal                                               : Read[BigDecimal]   = string.map(BigDecimal(_))\n    implicit def tuple2[A: Read, B: Read]                                 : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))\n    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]))\n    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]))\n    implicit val boolean                                                  : Read[Boolean]      = string map {s =>\n      s.toLowerCase match {\n        case \"yes\" | \"true\" | \"1\" => true\n        case \"no\" | \"false\" | \"0\" => false\n        case _ => s.toBoolean\n      }\n    }\n  }\n}\n\n", "src_uid": "c14d255785b1f668d04b0bf6dcadf32d"}
{"source_code": "import java.io.PrintWriter\nimport java.util.Scanner\n\n/**\n * Created by arseny on 07.02.15.\n */\nobject A extends App {\n\n  val in = new Scanner(System.in)\n  val out = new PrintWriter(System.out)\n\n  def nextInt = in.nextInt\n  def nextLong = in.nextLong\n  def nextDouble = in.nextDouble\n  def nextString = in.next\n\n  def solve() = {\n    val n1 = nextInt\n    val n2 = nextInt\n    val k1 = nextInt\n    val k2 = nextInt\n    println(if (n1 > n2) \"First\" else \"Second\")\n  }\n\n  try {\n    solve()\n  } catch {\n    case _: Exception => sys.exit(9999)\n  } finally {\n    out.flush()\n    out.close()\n  }\n}", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b"}
{"source_code": "import scala.io.StdIn._\nimport scala.collection.mutable.ArrayBuffer\n\nobject Main {\n  def main(args: Array[String]): Unit = {\n    // println(\"please enter:\")\n    val n = readInt()\n    val ps = readLine().split(\" \").map(_.toInt)\n\n    var ret = 0\n\n    var curParity, lastParity, lastState, zeroSeqLen, even, odd, diffParity = 0\n    var leadingZeros, trailingZeros = 0\n    var leadingParity, trailingParity = 0\n    var evenParity, oddParity = ArrayBuffer[Int]()\n    var hasNum = false\n    var prevNumParity = 0\n\n    (ps :+ -1).foreach(x => {\n      if (x == 0) { // zero\n        lastState = 0\n        zeroSeqLen += 1\n        prevNumParity = 0\n      } else if (x == -1) { // reach the end\n        if (lastState == 0) trailingZeros = zeroSeqLen\n        trailingParity = lastParity\n      } else { // num\n        if (x % 2 == 0) { // even\n          even += 1\n          curParity = 1\n        } else { // odd\n          odd += 1\n          curParity = -1\n        }\n        if (prevNumParity != 0 && prevNumParity != curParity) {\n          ret += 1\n        }\n        if (lastState == 0) {\n          if (lastParity == 0) {\n            leadingZeros = zeroSeqLen\n            leadingParity = curParity\n          } else if (lastParity == curParity) {\n            if (curParity == 1)\n              evenParity += zeroSeqLen\n            else\n              oddParity += zeroSeqLen\n          } else {\n            diffParity += 1\n          }\n          zeroSeqLen = 0\n        }\n        hasNum = true\n        lastState = 1\n        lastParity = curParity\n        prevNumParity = curParity\n      }\n    })\n\n    even = n / 2 - even\n    odd = (n + 1) / 2 - odd\n\n    // println(f\"$leadingZeros, $trailingZeros\")\n    // println(\"even:\")\n    // for (i <- evenParity)\n    //   println(i)\n    // println(\"odd:\")\n    // for (i <- oddParity)\n    //   println(i)\n    // println(f\"diff: $diffParity, even: $even, odd: $odd\")\n\n    if (n == 1) {\n      ret = 0\n    } else if (!hasNum) { // if all bulbs are removed\n      ret = 1\n    } else {\n      evenParity = evenParity.sorted\n      oddParity = oddParity.sorted\n      var (evenLeft, evenZeros) = takeSumLim(evenParity, 0, even)\n      var (oddLeft, oddZeros) = takeSumLim(oddParity, 0, odd)\n      // println(f\"even: $even, odd: $odd\")\n      // println(\n      //   f\"leading parity: $leadingParity, \" +\n      //     f\"trailing parity: $trailingParity\"\n      // )\n      ret += 1\n      if (leadingParity == 1 && leadingZeros <= evenLeft) {\n        evenLeft -= leadingZeros\n        ret -= 1\n      } else if (leadingParity == -1 && leadingZeros <= oddLeft) {\n        oddLeft -= leadingZeros\n        ret -= 1\n      }\n      ret += 1\n      if (trailingParity == 1 && trailingZeros <= evenLeft ||\n          trailingParity == -1 && trailingZeros <= oddLeft) {\n        ret -= 1\n      }\n      ret += diffParity\n      ret += 2 * evenZeros\n      ret += 2 * oddZeros\n    }\n\n    println(ret)\n  }\n\n  def takeSumLim(seq: ArrayBuffer[Int], z: Int, lim: Int): (Int, Int) =\n    if (seq.length == 0)\n      (lim - z, 0)\n    else if (z + seq(0) <= lim)\n      takeSumLim(seq.tail, z + seq(0), lim)\n    else\n      (lim - z, seq.length)\n\n}\n", "src_uid": "90db6b6548512acfc3da162144169dba"}
{"source_code": "object Lesha extends App {\n\n  case class State(val boundaries: List[Int], val hasNonZeros: Boolean, val sum: Int)\n\n  val n: Int = readLine.toInt\n  val aa: Seq[Int] = readLine.split(' ').map(_.toInt)\n\n  val sums: Seq[Int] = aa.scanLeft(0)(_ + _)\n  val r = (sums.zipWithIndex.toMap + (sums.head -> 0, sums.last -> (sums.size - 1))).values.toList.sorted\n  val results = r match {\n    case 0 :: x => x\n    case x: List[Int] => x\n  }\n\n  if (aa.forall(_ == 0)) {\n    println(\"NO\")\n  }\n  else {\n    println(\"YES\")\n    println(results.length)\n    (0 :: results).map(_ + 1) zip results foreach {\n      case (a, b) => println(a + \" \" + b)\n    }\n  }\n\n}\n", "src_uid": "3a9258070ff179daf33a4515def9897a"}
{"source_code": "object Solution extends App {\n  val in = io.Source.stdin.getLines()\n  val Array(x, y) = in.next().split(' ').map(_.toInt)\n  val d = Math.sqrt(x * x + y * y)\n  if (d == d.toInt)\n    println(\"black\")\n  else if ((x > 0 && y > 0) || (x < 0 && y < 0))\n    if (d.toInt % 2 == 0)\n      println(\"black\")\n    else\n      println(\"white\")\n  else\n  if (d.toInt % 2 == 0)\n    println(\"white\")\n  else\n    println(\"black\")\n}", "src_uid": "8c92aac1bef5822848a136a1328346c6"}
{"source_code": "import scala.annotation.tailrec, scala.collection.mutable\nimport CodeForcesApp._\nobject _557A extends CodeForcesApp[List[Int]]({ scanner => import scanner._\n  val n = nextInt\n  val rs = List.fill(3)((nextInt, nextInt))\n  val (mins, maxs) = (rs.map(_._1), rs.map(_._2))\n  var ans = mins\n  while(ans.sum < n) {\n    val diff = n - ans.sum\n    var found = false\n    ans = ans zip maxs map { case (c, m) =>\n      if(found) {\n        c\n      } else if(c == m) {\n        c\n      } else {\n        found = true\n        (c + diff) min m\n      }\n    }\n  }\n  ans\n}) {\n  override def format(result: List[Int]) = result mkString \" \"\n}\nimport java.util.Scanner\nabstract class CodeForcesApp[A](solver: Scanner => A) {\n  final def apply(problem: String): String = apply(new Scanner(problem))\n  final def apply(scanner: Scanner): String = format(solver(scanner))\n  def format(result: A): String = result.toString\n  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))\n}\nobject CodeForcesApp {\n  val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  val modulus: Int = 1000000007\n  def when[A](x: Boolean)(f: => A): Option[A] = if (x) Some(f) else None\n  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)\n}\n", "src_uid": "3cd092b6507079518cf206deab21cf97"}
{"source_code": "import scala.io.StdIn._\nobject Solution {\n  def main(args: Array[String]): Unit = {\n    val Array(k2, k3, k5, k6) = readLine.split(\" \").map(_.toInt)\n    val b = Math.min(k2, Math.min(k5, k6))\n    val s = Math.min(k3, k2 - b)\n    println(b * 256 + s * 32)\n  }\n}\n", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e"}
{"source_code": "object B{\n  def main(args: Array[String]){\n\n    //a~b\n    val(a,b)={\n      val sp=readLine.split(\" \")\n      val (p,d)=(sp(0).toLong, sp(1).toLong)\n      (p-d,p)\n    }\n\n    //i\u500b\u306e9\u3067max\u8abf\u3079\u308b\n    val ans=(1 to 18).filter{i=>\n      Math.pow(10, i)<=b\n    }.map{i=>\n      val n1=Math.pow(10, i).toLong\n      ((b+1)-(b+1)%n1-1)\n    }.filter{ans=>\n      a<=ans && ans<=b\n    }.lastOption.getOrElse(b.toLong)\n\n    println(ans)\n\n  }\n}\n", "src_uid": "c706cfcd4c37fbc1b1631aeeb2c02b6a"}
{"source_code": "object Main {\n  def main(args: Array[String]): Unit = {\n    val s = new Main()\n    s.solve()\n    s.out.flush()\n  }\n}\n\nclass Main {\n  import java.io._\n  import java.util.StringTokenizer\n\n  import scala.collection.mutable\n  import scala.util.Sorting\n  import math.{abs, max, min}\n  import mutable.{ArrayBuffer, ListBuffer}\n  import scala.reflect.ClassTag\n\n  val MOD = 1000000007\n  val out = new PrintWriter(System.out)\n\n  def solve(): Unit = {\n    val S = ns()\n\n    val evens = S.take((S.length - 1) / 2 + 1).reverse\n    val odds = S.drop(evens.length)\n    val T = Array.ofDim[Char](S.length)\n    REP(evens.length) { i =>\n      T(i * 2) = evens(i)\n    }\n    REP(odds.length) { i =>\n      T(i * 2 + 1) = odds(i)\n    }\n    out.println(T.mkString)\n  }\n\n  class InputReader(val stream: InputStream) {\n    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n    private var tokenizer: StringTokenizer = _\n\n    def next(): String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new StringTokenizer(reader.readLine)\n      tokenizer.nextToken\n    }\n\n    def nextInt(): Int = next().toInt\n    def nextLong(): Long = next().toLong\n    def nextChar(): Char = next().charAt(0)\n  }\n  val sc = new InputReader(System.in)\n  def ni(): Int = sc.nextInt()\n  def nl(): Long = sc.nextLong()\n  def nc(): Char = sc.nextChar()\n  def ns(): String = sc.next()\n  def ns(n: Int): Array[Char] = ns().toCharArray\n  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)\n  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {\n    val A1, A2 = Array.ofDim[Int](n)\n    REP(n) { i =>\n      A1(i) = ni() + offset\n      A2(i) = ni() + offset\n    }\n    (A1, A2)\n  }\n  def nm(n: Int, m: Int): Array[Array[Int]] = {\n    val A = Array.ofDim[Int](n, m)\n    REP(n) { i =>\n      REP(m) { j =>\n        A(i)(j) = ni()\n      }\n    }\n    A\n  }\n  def nal(n: Int): Array[Long] = map(n)(_ => nl())\n  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))\n  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = offset\n    val N = n + offset\n    while(i < N) { f(i); i += 1 }\n  }\n  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = n - 1 + offset\n    while(i >= offset) { f(i); i -= 1 }\n  }\n\n  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {\n    val res = Array.ofDim[A](n)\n    REP(n)(i => res(i) = f(i + offset))\n    res\n  }\n\n\n  def sumL(as: Array[Int]): Long = {\n    var s = 0L\n    REP(as.length)(i => s += as(i))\n    s\n  }\n\n  def cumSum(as: Array[Int]) = {\n    val cum = Array.ofDim[Long](as.length + 1)\n    REP(as.length) { i =>\n      cum(i + 1) = cum(i) + as(i)\n    }\n    cum\n  }\n}", "src_uid": "992ae43e66f1808f19c86b1def1f6b41"}
{"source_code": "object Main {\n  def main(args: Array[String]): Unit = {\n    val s = new Main()\n    s.solve()\n    s.out.flush()\n  }\n}\n\nclass Main {\n  import java.io._\n  import java.util.StringTokenizer\n\n  import scala.collection.mutable\n  import scala.util.Sorting\n  import math.{abs, max, min}\n  import mutable.{ArrayBuffer, ListBuffer}\n  import scala.reflect.ClassTag\n\n  val MOD = 1000000007\n  val out = new PrintWriter(System.out)\n\n  def solve(): Unit = {\n    val N, M = ni()\n    val A = na(N)\n    val mx = A.max\n\n    val vacant = (A map (mx - _)).sum\n    val needs = max(0, M - vacant)\n    val additional = needs / N + (if (needs % N != 0) 1 else 0)\n\n    out.println(s\"${additional + mx} ${mx+M}\")\n  }\n\n\n  class InputReader(val stream: InputStream) {\n    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n    private var tokenizer: StringTokenizer = _\n\n    def next(): String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new StringTokenizer(reader.readLine)\n      tokenizer.nextToken\n    }\n\n    def nextInt(): Int = next().toInt\n    def nextLong(): Long = next().toLong\n    def nextChar(): Char = next().charAt(0)\n  }\n  val sc = new InputReader(System.in)\n  def ni(): Int = sc.nextInt()\n  def nl(): Long = sc.nextLong()\n  def nc(): Char = sc.nextChar()\n  def ns(): String = sc.next()\n  def ns(n: Int): Array[Char] = ns().toCharArray\n  def na(n: Int): Array[Int] = map(n)(_ => ni())\n  def nal(n: Int): Array[Long] = map(n)(_ => nl())\n  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))\n  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = offset\n    val N = n + offset\n    while(i < N) { f(i); i += 1 }\n  }\n  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = n - 1 + offset\n    while(i >= offset) { f(i); i -= 1 }\n  }\n\n  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {\n    val res = Array.ofDim[A](n)\n    rep(n)(i => res(i) = f(i))\n    res\n  }\n\n  def sumL(as: Array[Int]): Long = {\n    var s = 0L\n    rep(as.length)(i => s += as(i))\n    s\n  }\n}", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d"}
{"source_code": "object B {\n  import InOut._\n  def main(args: Array[String]): Unit = {\n\n    val k = nextLong\n\n    val xs = Array.fill(10)(1L)\n    var cnt = 1L\n    while (cnt < k) {\n      var i = xs.indices.minBy(xs)\n      cnt /= xs(i)\n      xs(i) += 1\n      cnt *= xs(i)\n    }\n\n    val s = \"codeforces\".zip(xs).map { case (c, count) =>\n      c.toString * count.toInt\n    }.mkString\n\n    out.println(s)\n\n    out.flush()\n  }\n \n  final object InOut {\n    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n    val out = new java.io.PrintWriter(System.out, false)\n    private[this] var tokenizer: java.util.StringTokenizer = _\n    def nextToken: String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new java.util.StringTokenizer(in.readLine)\n      tokenizer.nextToken\n    }\n    def nextInt = Integer.parseInt(nextToken)\n    def nextLong = java.lang.Long.parseLong(nextToken)\n    def nextBig = BigInt(nextToken)\n    def nextInts(n: Int) = Array.fill(n) { nextInt }\n    def nextLongs(n: Int) = Array.fill(n) { nextLong }\n    def nextBigs(n: Int) = Array.fill(n) { nextBig }\n    def nextLine = in.readLine\n  }\n}\n", "src_uid": "8001a7570766cadcc538217e941b3031"}
{"source_code": "object Solution {\n    def sqr(n: Int) = n * n\n  \n    def solve(n: String): Int = {\n        if(n.head == '0')return -1\n        if(sqr(Math.sqrt(n.toInt).toInt).toString() == n)return 0\n        if(n.length == 1)return -1\n        var ans = -1\n        for(i <- 0 until n.length()){\n            val substr = n.substring(0, i) + n.substring(i + 1);\n            val answer = solve(substr)\n            if(answer != -1 && (ans == -1 || ans > answer + 1))ans = answer + 1\n        }\n        return ans\n    }\n    \n    def main(args: Array[String]) {\n        val n = readLine\n        println(solve(n))\n    }\n}\n", "src_uid": "fa4b1de79708329bb85437e1413e13df"}
{"source_code": "import scala.collection.mutable.ArrayBuffer\nimport scala.io.StdIn\n\nobject Codeforces1011A {\n\n  def getWeight(char: Char): Int = char - 'a' + 1\n\n  def getMinimumWeight(n: Int, k: Int, stages: String): Int = {\n    val stageSet = stages.toSet\n\n    val rocket = new ArrayBuffer[Char]()\n\n    var previousCharAdded = false\n    for (ch <- 'a' to 'z') {\n      if ((stageSet contains ch) && !previousCharAdded) {\n        rocket.append(ch)\n        previousCharAdded = true\n      } else {\n        previousCharAdded = false\n      }\n    }\n\n    if (rocket.size < k) -1\n    else rocket.take(k).map(getWeight).sum\n  }\n\n  def main(args: Array[String]): Unit = {\n    val Array(n, k) = StdIn.readLine.trim.split(\" \").map(_.toInt)\n    val stages = StdIn.readLine()\n    val weight = getMinimumWeight(n, k, stages)\n    println(weight)\n  }\n}\n", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313"}
{"source_code": "object _801A extends CodeForcesApp {\n  import Utils._, annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._\n\n  override def apply(io: IO) = {import io.{read, readAll, write, writeAll, writeLine}\n    val s = read[String]\n    val ans = s.indices\n      .flatMap(i => Seq(s.updated(i, 'V'), s.updated(i, 'K')))\n      .maxWith(count)\n      .get\n\n    write(ans max count(s))\n  }\n\n  def count(s: String) = s.sliding(2).count(_ == \"VK\")\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n  lazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)\n  def apply(io: IO): io.type\n  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()\n}\nobject Utils {\n  import scala.collection.mutable, mutable.{Map => Dict}\n  implicit class GenericExtensions[A](val a: A) extends AnyVal {\n    def in(set: collection.Set[A]): Boolean = set(a)\n    def some: Option[A] = Some(a)\n    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a\n  }\n  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {\n    def onlyElement: A = assuming(t.size == 1)(t.head)\n    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)\n    def duplicates(implicit b: C of A): C[A] = {\n      val elems = mutable.Set.empty[A]\n      (t collect {case i if !elems.add(i) => i}).to[C]\n    }\n    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}\n    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)\n    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)\n    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]\n    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap\n    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)\n    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}\n    def toMutableMultiSet: Dict[A, Int] = {\n      val c = map[A] to 0\n      t.foreach(i => c(i) += 1)\n      c\n    }\n    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0\n    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)\n  }\n  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)\n  }\n  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)\n  }\n  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {\n    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t\n  }\n  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {\n    def key = p._1\n    def value = p._2\n  }\n  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {\n    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)\n    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])\n    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]\n  }\n  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {\n    def lastKeyOption: Option[K] = m.lastOption.map(_.key)\n    def firstKeyOption: Option[K] = m.headOption.map(_.key)\n    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap\n    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}\n    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m\n    def mapValuesSafely[V2](f: V => V2): Map[K, V2] = m.mapValues(f).view.force //Hack to get around https://issues.scala-lang.org/browse/SI-4776\n  }\n  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {\n    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)\n    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)\n    private def removeNode(kv: (K, V)): (K, V) = {\n      m -= kv.key\n      kv\n    }\n  }\n  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {\n    def notContains(x: A): Boolean = !(s contains x)\n    def toMutable = mutable.Set.empty[A] ++ s\n  }\n  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {\n    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}\n    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)\n    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)\n    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}\n    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)\n  }\n  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {\n    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero\n    def toEnglish = if(x) \"YES\" else \"NO\"\n  }\n  implicit class IntExtensions(val x: Int) extends AnyVal {\n    import java.lang.{Integer => JInt}\n    def withHighestOneBit: Int = JInt.highestOneBit(x)\n    def withLowestOneBit: Int = JInt.lowestOneBit(x)\n    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)\n    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)\n    def bitCount: Int = JInt.bitCount(x)\n    def setLowestBits(n: Int): Int = x | (left(n) - 1)\n    def clearLowestBits(n: Int): Int = x & left(n, ~0)\n    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)\n    def setBit(i: Int): Int = x | left(i)\n    def clearBit(i: Int): Int = x & ~left(i)\n    def toggleBit(i: Int): Int = x ^ left(i)\n    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1\n    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)\n    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)\n  }\n  implicit class LongExtensions(val x: Long) extends AnyVal {\n    import java.lang.{Long => JLong}\n    def withHighestOneBitSet: Long = JLong.highestOneBit(x)\n    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)\n    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)\n    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)\n    def bitCount: Int = JLong.bitCount(x)\n    def setLowestBits(n: Int): Long = x | (left(n) - 1)\n    def clearLowestBits(n: Int): Long = x & left(n, ~0L)\n    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)\n    def setBit(i: Int): Long = x | left(i)\n    def clearBit(i: Int): Long = x & ~left(i)\n    def toggleBit(i: Int): Long = x ^ left(i)\n    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1\n    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)\n  }\n  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {\n    import Numeric.Implicits._\n    def **(i: Int): A = if (i == 0) n.one else {\n      val h = x ** (i/2)\n      if (i%2 == 0) h * h else h * h * x\n    }\n    def distance(y: A) = (x - y).abs()\n    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)\n    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf \"Greg\" whenNegative Int.MaxValue\n  }\n  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {\n    import scala.collection.immutable.NumericRange, Integral.Implicits._\n    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x\n    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)\n    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)\n  }\n  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))\n  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)\n  def asc[A](implicit order: Ordering[A]): Ordering[A] = order\n  def map[K] = new {\n    def to[V](default: => V): Dict[K, V] = using(_ => default)\n    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {\n      override def apply(key: K) = getOrElseUpdate(key, f(key))\n    }\n  }\n  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]\n  def memoize[A, B](f: A => B): A ==> B = map[A] using f\n  implicit class FuzzyDouble(val x: Double) extends AnyVal {\n    def  >~(y: Double) = x > y + eps\n    def >=~(y: Double) = x >= y + eps\n    def  ~<(y: Double) = y >=~ x\n    def ~=<(y: Double) = y >~ x\n    def  ~=(y: Double) = (x distance y) <= eps\n  }\n  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {\n    val (xs, ys) = points.unzip\n    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)\n  }\n  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {\n    val shape = new java.awt.geom.GeneralPath()\n    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}\n    points.tail foreach {case (x, y) => shape.lineTo(x, y)}\n    shape.closePath()\n    shape\n  }\n  def until(until: Int): Range = 0 until until\n  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}\n  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}\n  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None\n  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)\n  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]\n  type ==>[A, B] = collection.Map[A, B]\n  val mod: Int = (1e9 + 7).toInt\n  val eps: Double = 1e-9\n}\n/***********************************[Scala I/O]*********************************************/\nimport Utils._, java.io._, java.util.StringTokenizer\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {\n  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n  val printer = new PrintWriter(out, true)\n\n  @inline private[this] def tokenizer() = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    when(tokenizers.nonEmpty)(tokenizers.head)\n  }\n\n  def read[A](implicit read: IO.Read[A]): A = read.apply(this)\n  def read[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(read).to[C]\n\n  def readTill(delim: String): String = tokenizer().get.nextToken(delim)\n  def readTillEndOfLine(): String = readTill(\"\\n\\r\")\n\n  def readAll[A: IO.Read]: (Int, Vector[A]) = {\n    val data = read[Vector[A]]\n    (data.length, data)\n  }\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n\n  def write(obj: Any): this.type = {\n    printer.print(obj)\n    this\n  }\n  def writeLine(): this.type = {\n    printer.println()\n    this\n  }\n  def writeLine(obj: Any): this.type = {\n    printer.println(obj)\n    this\n  }\n  def writeAll(obj: Traversable[Any], separator: String = \" \"): this.type = write(obj mkString separator)\n  def query[A: IO.Read](question: Any): A = writeLine(question).read\n\n  override def flush() = printer.flush()\n  def close() = {\n    flush()\n    in.close()\n    printer.close()\n  }\n}\nobject IO {\n  class Read[A](val apply: IO => A) {\n    def map[B](f: A => B): Read[B] = new Read(apply andThen f)\n  }\n  object Read {\n    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))\n    implicit val string                                       : Read[String]       = new Read(_.next())\n    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)\n    implicit val int                                          : Read[Int]          = string.map(_.toInt)\n    implicit val long                                         : Read[Long]         = string.map(_.toLong)\n    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))\n    implicit val double                                       : Read[Double]       = string.map(_.toDouble)\n    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))\n    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))\n    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]))\n    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]))\n    implicit val boolean                                      : Read[Boolean]      = string map {s =>\n      s.toLowerCase match {\n        case \"yes\" | \"true\" | \"1\" => true\n        case \"no\" | \"false\" | \"0\" => false\n        case _ => s.toBoolean\n      }\n    }\n  }\n}\n\n", "src_uid": "578bae0fe6634882227ac371ebb38fc9"}
{"source_code": "object Main {\n  def main(args: Array[String]): Unit = {\n    val s = new Main()\n    s.solve()\n    s.out.flush()\n  }\n}\n\nclass Main {\n  import java.io._\n  import java.util.StringTokenizer\n\n  import scala.collection.mutable\n  import scala.util.Sorting\n  import math.{abs, max, min}\n  import mutable.{ArrayBuffer, ListBuffer}\n  import scala.reflect.ClassTag\n\n  val MOD = 1000000007\n  val out = new PrintWriter(System.out)\n\n  def solve(): Unit = {\n    val N, K = ni()\n    val d = divisors(N)\n\n    var ans = 1e18.toLong\n    REP(d.length) { i =>\n      if (d(i) < K) {\n        val b = d(i)\n        val a = N / b\n        val x = a.toLong * K + b\n        ans = min(ans, x)\n      }\n    }\n\n    out.println(ans)\n  }\n\n\n  /**\n    * O(\u221ax)\n    */\n  def divisors(x: Int): Array[Int] = {\n    val pre = ArrayBuffer[Int]()\n    val post = ArrayBuffer[Int]()\n    REP(math.sqrt(x).toInt, 1) { d =>\n      if (x % d == 0) {\n        pre += d\n        if (d * d != x) post += x / d\n      }\n    }\n\n    val res = Array.ofDim[Int](pre.length + post.length)\n    REP(pre.length)(i => res(i) = pre(i))\n    val preLen = pre.length\n    REP_r(post.length)(i => res(i + preLen) = post(i))\n    res\n  }\n\n  class InputReader(val stream: InputStream) {\n    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n    private var tokenizer: StringTokenizer = _\n\n    def next(): String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new StringTokenizer(reader.readLine)\n      tokenizer.nextToken\n    }\n\n    def nextInt(): Int = next().toInt\n    def nextLong(): Long = next().toLong\n    def nextChar(): Char = next().charAt(0)\n  }\n  val sc = new InputReader(System.in)\n  def ni(): Int = sc.nextInt()\n  def nl(): Long = sc.nextLong()\n  def nc(): Char = sc.nextChar()\n  def ns(): String = sc.next()\n  def ns(n: Int): Array[Char] = ns().toCharArray\n  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)\n  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {\n    val A1, A2 = Array.ofDim[Int](n)\n    REP(n) { i =>\n      A1(i) = ni() + offset\n      A2(i) = ni() + offset\n    }\n    (A1, A2)\n  }\n  def nm(n: Int, m: Int): Array[Array[Int]] = {\n    val A = Array.ofDim[Int](n, m)\n    REP(n) { i =>\n      REP(m) { j =>\n        A(i)(j) = ni()\n      }\n    }\n    A\n  }\n  def nal(n: Int): Array[Long] = map(n)(_ => nl())\n  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))\n  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = offset\n    val N = n + offset\n    while(i < N) { f(i); i += 1 }\n  }\n  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = n - 1 + offset\n    while(i >= offset) { f(i); i -= 1 }\n  }\n\n  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {\n    val res = Array.ofDim[A](n)\n    REP(n)(i => res(i) = f(i + offset))\n    res\n  }\n\n\n  def sumL(as: Array[Int]): Long = {\n    var s = 0L\n    REP(as.length)(i => s += as(i))\n    s\n  }\n\n  def cumSum(as: Array[Int]) = {\n    val cum = Array.ofDim[Long](as.length + 1)\n    REP(as.length) { i =>\n      cum(i + 1) = cum(i) + as(i)\n    }\n    cum\n  }\n}", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57"}
{"source_code": "import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._\n\nobject _658A extends CodeForcesApp {\n  override def apply(io: IO) = {\n    val n, c = io[Int]\n    val p, t = io[IndexedSeq, Int](n)\n    io += ((score(p, t, c) - score(p.reverse, t.reverse, c)).signum match {\n      case 0 => \"Tie\"\n      case 1 => \"Limak\"\n      case -1 => \"Radewoosh\"\n    })\n  }\n\n  def score(p: Seq[Int], t: Seq[Int], c: Int): Int = {\n    var time, score = 0\n    for {\n      i <- p.indices\n    }  {\n      time += t(i)\n      score += ((p(i) - c*time) max 0)\n    }\n    score\n  }\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n  lazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)\n  def apply(io: IO): io.type\n  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()\n}\nobject Utils {\n  import scala.collection.mutable, mutable.{Map => Dict}\n  implicit class GenericExtensions[A](val a: A) extends AnyVal {\n    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a\n  }\n  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {\n    def onlyElement: A = t.head.ensuring(t.size == 1)\n    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)\n    def duplicates(implicit b: C of A): C[A] = {\n      val elems = mutable.Set.empty[A]\n      (t collect {case i if !elems.add(i) => i}).to[C]\n    }\n    def sum[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}\n    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]\n    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap\n    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)\n    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}\n    def toMutableMultiSet: Dict[A, Int] = {\n      val c = map[A] to 0\n      t.foreach(i => c(i) += 1)\n      c\n    }\n    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap\n  }\n  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)\n  }\n  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)\n  }\n  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {\n    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t\n  }\n  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {\n    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_._1).mapValues(_._2)\n    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_._1).mapValues(_.map(_._2).to[C])\n    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]\n  }\n  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {\n    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap\n    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}\n    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m\n  }\n  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {\n    def notContains(x: A): Boolean = !(s contains x)\n  }\n  implicit class LongExtensions(val x: Long) extends AnyVal {\n    def bitCount: Int = java.lang.Long.bitCount(x)\n  }\n  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {\n    import Numeric.Implicits._\n    def **(i: Int): A = if (i == 0) n.one else {\n      val h = x ** (i/2)\n      if (i%2 == 0) h * h else h * h * x\n    }\n    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)\n    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf \"Greg\" whenNegative Int.MaxValue\n  }\n  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {\n    import scala.collection.immutable.NumericRange, Integral.Implicits._\n    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x\n    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(n.min(x, y), n.max(x, y), n.one)\n  }\n  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)\n  def  asc[A](implicit order: Ordering[A]): Ordering[A] = order\n  def map[K] = new {\n    def to[V](default: V): Dict[K, V] = Dict.empty[K, V] withDefaultValue default\n  }\n  def memoize[I] = new {\n    def apply[O](f: I => O): I => O = new mutable.HashMap[I, O]() {\n      override def apply(key: I) = getOrElseUpdate(key, f(key))\n    }\n  }\n  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None\n  def repeat(n: Int)(f: => Unit): Unit = (1 to n).foreach(_ => f)\n  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]\n  val mod: Int = (1e9 + 7).toInt\n}\n/***********************************[Scala I/O]*********************************************/\nimport Utils._, java.io._, java.util.StringTokenizer\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends PrintWriter(out, true) with Iterator[String] {\n  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n\n  @inline private[this] def tokenizer() = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    if (tokenizers.nonEmpty) Some(tokenizers.head) else None\n  }\n\n  def apply[A](implicit read: IO.Read[A]): A = read.apply(this)\n  def apply[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(apply).to[C]\n\n  def till(delim: String): String = tokenizer().get.nextToken(delim)\n  def tillEndOfLine(): String = till(\"\\n\\r\")\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n\n  var separator = \" \"\n  private[this] var isNewLine = true\n\n  def +=[A](x: A)(implicit write: IO.Write[A]): this.type = {\n    write(this)(x)\n    this\n  }\n  def appendNewLine(): this.type = {\n    println()\n    this\n  }\n\n  override def print(obj: String) = {\n    if (isNewLine) isNewLine = false else super.print(separator)\n    super.print(obj)\n  }\n  override def println() = if (!isNewLine) {\n    super.println()\n    isNewLine = true\n  }\n  override def close() = {\n    flush()\n    in.close()\n    super.close()\n  }\n}\nobject IO {\n  class Read[A](val apply: IO => A) {\n    def map[B](f: A => B): Read[B] = new Read(apply andThen f)\n  }\n  object Read {\n    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r[C, A](r[Int]))\n    implicit val string                                       : Read[String]       = new Read(_.next())\n    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)\n    implicit val boolean                                      : Read[Boolean]      = string.map(_.toBoolean)\n    implicit val int                                          : Read[Int]          = string.map(_.toInt)\n    implicit val long                                         : Read[Long]         = string.map(_.toLong)\n    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))\n    implicit val double                                       : Read[Double]       = string.map(_.toDouble)\n    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))\n    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r[A], r[B]))\n    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r[A], r[B], r[C]))\n    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r[A], r[B], r[C], r[D]))\n  }\n  trait Write[-A] {\n    def apply(out: PrintWriter)(x: A): Unit\n  }\n  trait DefaultWrite {\n    implicit def any[A]: Write[A] = Write(_.toString)\n  }\n  object Write extends DefaultWrite {\n    def apply[A](f: A => String) = new Write[A] {\n      override def apply(out: PrintWriter)(x: A) = out.print(f(x))\n    }\n    implicit val boolean: Write[Boolean] = Write(b => if (b) \"YES\" else \"NO\")\n    implicit def iterable[A](implicit write: Write[A]): Write[Traversable[A]] = new Write[Traversable[A]] {\n      override def apply(out: PrintWriter)(xs: Traversable[A]) = {\n        xs foreach write(out)\n        out.println()\n      }\n    }\n  }\n}\n\n", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a"}
{"source_code": "import scala.io.StdIn\n\n/**\n  * Created by a.kosarev1 on 23.01.2017.\n  */\nobject Solution extends App {\n\n  val stdIn = StdIn.readLine();\n  val input = stdIn.split(\" \").map(_.toInt)\n\n  println(calculateWeeks(input(0), input(1)))\n\n  def calculateWeeks(month: Int, dow: Int): Int = {\n    val daysCount = 28 + (month + month / 8) % 2 + 2 % month + 2 * (1 / month)\n\n    def calcWeeks(weekCount: Int, dow: Int, acc: Int): Int = {\n      if (acc == daysCount) weekCount\n      else if (dow % 7 == 0) calcWeeks(weekCount + 1, 1, acc + 1)\n      else calcWeeks(weekCount, dow + 1, acc + 1)\n    }\n    calcWeeks(1, dow, 1)\n  }\n\n}", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74"}
{"source_code": "object Main extends App {\n  val mapping = Map(\"0\"->2,\"1\"->7,\"2\"->2,\"3\"->3,\"4\"->3,\"5\"->4,\"6\"->2,\"7\"->5, \"8\"->1,\"9\"->2)\n  val ns = readLine.split(\"\").filterNot(_ == \"\")\n  println(ns.map(mapping(_)).foldLeft(1)({_ * _}))  \n}", "src_uid": "76c8bfa6789db8364a8ece0574cd31f5"}
{"source_code": "object Main {\n  def main(args: Array[String]) {\n    val n = readInt()\n    val a = (1 to 4).map(_ => readLine().split(\" \").map(_.toInt))\n    val mapped = a.map(row => row(0).min(row(1)) + row(2).min(row(3)))\n    val min = mapped.zipWithIndex.minBy(_._1)\n    if (min._1 > n) println(\"-1\")\n    else {\n      val row = a(min._2)\n      val v1 = row(0).min(row(1))\n      val v2 = n - v1\n      println((min._2 + 1) + \" \" + v1 + \" \" + v2)\n    }\n  }\n}", "src_uid": "6e7ee0da980beb99ca49a5ddd04089a5"}
{"source_code": "import scala.math._, scala.io.StdIn._\n\nobject B extends App {\n  val n = readLong\n\n  var r = digits(n).product\n  var k = 10L\n  while (k <= n) {\n    val r1 = digits((n / k) * k - 1).product\n    if (r1 > r)\n      r = r1\n    k *= 10\n  }\n  println(r)\n\n  def digits(n: Long) = n.toString.map(_.asDigit)  \n\n  def readInts() = readLine.split(\" \").map(_.toInt)\n}\n", "src_uid": "38690bd32e7d0b314f701f138ce19dfb"}
{"source_code": "import scala.io.StdIn._\n\nobject Main extends App {\n    var line = readLine();\n    val n = line.toInt;\n    def solve (n : Int ) = (0 to 9).\n    map( i => math.pow(10,i) ).\n    filter( i => i<= n ).\n    foldLeft[Double](0)((acc,i) => acc + n - i + 1);\n    println((solve(n) / 1).asInstanceOf[Long]);\n}", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9"}
{"source_code": "object B extends App {\n  def check(y: Int, p: Int): Boolean = {\n    val t = p min (math.sqrt(y).toInt + 1)\n    for (x <- 2 to t)\n      if (y % x == 0) return false\n    true\n  }\n\n  def branch(y: Int, p: Int): Int =\n    if (y == p) -1\n    else if (check(y, p)) y\n    else branch(y - 1, p)\n\n  val Array(p, y) = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n\n  println(branch(y, p))\n}", "src_uid": "b533203f488fa4caf105f3f46dd5844d"}
{"source_code": "import java.util.Scanner\n\nobject C extends App {\n\n  val sc = new Scanner(System.in)\n\n  val n = sc.nextLong()\n  val m = sc.nextLong()\n\n  if (n < m) println(n)\n  else {\n    val d = 1 + 8 * (n - m)\n    val root = ((-1.0 + math.sqrt(d)) / 2.0).ceil.toLong\n    // fix for floating point precision\n    if (n - m - (root * (root + 1)) / 2 <= 0) println(root + m)\n    else println(root + m + 1)\n  }\n}\n", "src_uid": "3b585ea852ffc41034ef6804b6aebbd8"}
{"source_code": "import scala.io.StdIn.readLine\n\n/**\n * @author slie742\n */\nobject NearlyLucky {\n  \n  def main(args: Array[String]) {\n    val lucky = readLine.count { c => c == '4' || c == '7'}\n    if (lucky == 4 || lucky == 7)\n      println(\"YES\")\n    else\n      println(\"NO\")\n  }\n  \n}", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1"}
{"source_code": "object A732 {\n  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)\n\n  def readInts(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)\n  }\n\n  def readLongs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong)\n  }\n\n  def readBigs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken))\n  }\n\n  def main(args: Array[String]): Unit = {\n    val Array(k, r) = readInts(2)\n    var num = 1\n    var break = false\n    while(!break && num <= 10) {\n      if(num*k % 10 == 0) {\n        println(num)\n        break = true\n      } else if ((num*k - r)%10 == 0) {\n        println(num)\n        break = true\n      }\n      num += 1\n    }\n  }\n}", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3"}
{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n  val in = Source.stdin.getLines()\n  val Array(n, k) = in.next().split(' ').map(_.toInt)\n  val mod = (1e9 + 7).toInt\n  val dp = Array.ofDim[Int](k + 1, n + 1)\n\n  (0 to n).foreach { i => dp(0)(i) = 1}\n\n  (1 to k).foreach { i =>\n    var j = 1\n    while (j <= n) {\n      (j to n by j).foreach { el =>\n        dp(i)(j) += dp(i - 1)(el)\n        dp(i)(j) %= mod\n      }\n      j += 1\n    }\n  }\n\n  println(dp(k)(1))\n}\n", "src_uid": "c8cbd155d9f20563d37537ef68dde5aa"}
{"source_code": "import scala.collection.mutable\n\nobject B extends App {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }\n\n  val Array(n) = readInts(1)\n\n  val rByL = Array.fill(n){ mutable.Queue.empty[Int] }\n\n  for {\n    r <- 0 to n - 1\n    l <- r + 1 to n\n  } rByL(r) += l\n\n  var res = 0\n  var done = false\n\n  while (!done) {\n    var r = 0\n    while (r < n && rByL(r).isEmpty) r += 1\n    if (r == n) done = true\n    else {\n      res += 1\n      while (r < n) {\n        val l = rByL(r).dequeue()\n        r = l\n        while (r < n && rByL(r).isEmpty) r += 1\n      }\n    }\n  }\n\n  println(res)\n}\n", "src_uid": "f8af5dfcf841a7f105ac4c144eb51319"}
{"source_code": "import java.util._\nimport java.io._\nimport java.util\nimport scala.annotation.tailrec\n\nobject C {\n\n  var out: PrintWriter = null\n  var br: BufferedReader = null\n  var st: StringTokenizer = null\n\n  def next: String = {\n    while (st == null || !st.hasMoreTokens) {\n      st = new StringTokenizer(br.readLine)\n    }\n    return st.nextToken\n  }\n\n  def nextInt: Int = {\n    return Integer.parseInt(next)\n  }\n\n  def nextLong: Long = {\n    return java.lang.Long.parseLong(next)\n  }\n\n  def baseHouse(n: Long): Long = {\n    return (3L * n * n + n) / 2L\n  }\n\n  def solve: Int = {\n    val n = nextLong\n    var ans = 0\n    for (i <- 1 to 1e6.toInt) {\n      if (n - baseHouse(i) >= 0 && (n - baseHouse(i)) % 3 == 0) {\n        ans += 1\n      }\n    }\n    out.println(ans)\n    return 1\n  }\n\n  def main(args: Array[String]): Unit = {\n    br = new BufferedReader(new InputStreamReader(System.in))\n    out = new PrintWriter(new BufferedOutputStream(System.out))\n    solve\n    out.close\n  }\n}\n", "src_uid": "ab4f9cb3bb0df6389a4128e9ff1207de"}
{"source_code": "import java.io._\nimport scala.io.Source\n\nimport scala.annotation.tailrec\n\nobject ProblemA {\n  def main(args: Array[String]): Unit = processStdInOut()\n\n  def processStdInOut(): Unit = {\n    val src = Source.fromInputStream(System.in)\n    processFromSource(src)\n  }\n\n  def processFromSource(src: Source): Unit = {\n    try {\n      val bw = new BufferedWriter(new OutputStreamWriter(System.out));\n      try {\n        val lines = src.getLines()\n        processLines(lines, bw)\n      } finally {\n        bw.flush()\n      }\n    } finally {\n      src.close();\n    }\n  }\n\n  // Standard code above, custom code below\n  def processLines(lines: Iterator[String], bw: BufferedWriter): Unit = {\n    val n = lines.next().toInt\n    val soln = solve(n)\n    bw.write(soln.toString)\n    bw.newLine()\n  }\n\n  def solve(n: Int): Int = {\n    def isComposite(i: Int): Boolean = {\n      val maxDiv = (math.sqrt(i) + 0.5).toInt\n      2.to(maxDiv).exists(i % _ == 0)\n    }\n\n    val mOpt = (1 to 1000).find(m => isComposite(m * n + 1))\n    mOpt.get\n  }\n}\n", "src_uid": "5c68e20ac6ecb7c289601ce8351f4e97"}
{"source_code": "import java.util.Scanner\n\nimport scala.language.postfixOps\n\nobject TaskA extends App {\n  val sc = new Scanner(System.in)\n  val s = sc.next\n  val lampsCnt = new Array[Int](100)\n  0 until 4 map { d =>\n    val lamps = d until s.length by 4 map s\n    lampsCnt(lamps.filterNot(_ == '!').head) = lamps.count(_ == '!')\n  }\n  println(\"RBYG\" map (_.toInt) map lampsCnt mkString \" \")\n}\n", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33"}
{"source_code": "//rextester.com:2.11.7--codeforces.com:2.11.8\nobject myClass extends App{\n    val a=scala.io.StdIn.readInt()*2;var b=false\n    for(i<-1 to math.sqrt(a).toInt-1){\n        val c=a-i*i-i;val d=math.sqrt(c).toInt\n        if(d*(d+1)==c)b=true\n    }\n    print({if(b)\"YES\"else\"NO\"})\n }", "src_uid": "245ec0831cd817714a4e5c531bffd099"}
{"source_code": "object B extends App\n{\n    val Array(n, k) = readLine.split(\" \").map(_.toInt)\n    val m = 1000000007\n    var ans:Long = 1\n    for (i <- 0 until n-k)\n        ans = (ans*(n-k)) % m\n    for (i <- 0 until k-1)\n        ans = (ans*k) % m\n    println(ans)\n}", "src_uid": "cc838bc14408f14f984a349fea9e9694"}
{"source_code": "import java.util.Scanner\n\n\nimport scala.collection.mutable.SortedSet\nobject main extends App with fastIO {\n//  def main(args: Array[String]) : Unit = {\n//    val n = readLine().toInt\n//    val input = new Scanner(System.in);\n    val n = next\n    val s = next\n    var st = SortedSet[Char]();\n    for (ch <- s) {\n      if (!st.contains(ch.toLower)) {\n        st += ch.toLower\n      }\n\n    }\n    println( if (st.size >= 26) \"YES\" else \"NO\")\n    flush\n\n//  }\n}\n\n\ntrait fastIO {\n  import java.io._\n\n  val isFile = false\n  val input = \"io.in\"\n  val output = \"io.out\"\n\n  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))\n  val in = new StreamTokenizer(bf)\n  val out = new PrintWriter(if(isFile) new FileWriter(output) else new OutputStreamWriter(System.out))\n\n  def next: String = {\n    in.ordinaryChars('0', '9')\n    in.wordChars('0', '9')\n    in.nextToken\n    in.sval\n  }\n\n  def nextInt: Int = {\n    in.nextToken\n    in.nval.toInt\n  }\n\n  def nextLong:Long ={\n    in.nextToken\n    in.nval.toLong\n  }\n\n  def nextDouble: Double = {\n    in.nextToken\n    in.nval.toDouble\n  }\n\n  def readLine: String = bf.readLine()\n  def println(o:Any) = out.println(o)\n  def print(o:Any) = out.print(o)\n  def printf(s:String,o:Any*) = out.printf(s,o)\n  def flush = out.flush\n}", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d"}
{"source_code": "object Main {\n  def gcd(a: Int, b: Int): Int = {\n    if (a % b == 0) b\n    else gcd(b, a % b)\n  }\n  \n  def main(args: Array[String]) {\n    val Array(a, b, c, d) = readLine().split(\" \").map(_.toInt)\n    if (a * d > b * c) {\n      val num = a * d - b * c \n      val den = a * d\n      val div = gcd(num, den)\n      println((num /  div) + \"/\" + (den / div))\n    } else {\n      val num = b * c - a * d\n      val den = b * c\n      val div = gcd(num, den)\n      println((num /  div) + \"/\" + (den / div))\n    }\n  }\n}", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e"}
{"source_code": "\nimport java.io.FileReader\nimport java.util.Comparator\n\nimport collection.Searching._\nimport scala.collection.mutable\n\nobject Solution {\n  //Console.setIn(new FileReader(new java.io.File(\"input\")))\n  //Console.setOut(new PrintStream(new java.io.File(\"output\")))\n  var caseNo = 1\n\n  def doCase() : Unit = {\n    val str = readLine()\n    println(subsr(str, 0, \"QAQ\", 0, Array.fill(str.length, 3){-1}))\n  }\n\n  def subsr(str : String, strIdx : Int, pat : String, patIdx : Int, cache : Array[Array[Long]]) : Long = {\n    if (patIdx == pat.length) {\n       return 1\n    } else if (strIdx == str.length) {\n      return 0\n    }\n\n    if (cache(strIdx)(patIdx) == -1) {\n      var result = 0L\n      result += subsr(str, strIdx + 1, pat, patIdx, cache)\n      if (str.charAt(strIdx).equals(pat.charAt(patIdx))) {\n        result += subsr(str, strIdx + 1, pat, patIdx + 1, cache)\n      }\n      cache(strIdx)(patIdx) = result\n    }\n    cache(strIdx)(patIdx)\n  }\n\n  def main(args: Array[String]) {\n    var tests = 1\n    for (test <- 0 until tests) {\n      doCase()\n      caseNo += 1\n    }\n  }\n\n  def readIntLine(): Array[Int] = {\n    readLine().split(\" \").map(_.toInt)\n  }\n\n  def readLongLine(): Array[Long] = {\n    readLine().split(\" \").map(_.toLong)\n  }\n\n  def readBigIntLine(): Array[BigInt] = {\n    readLine().split(\" \").map(BigInt.apply)\n  }\n}", "src_uid": "8aef4947322438664bd8610632fe0947"}
{"source_code": "\r\nimport scala.io.StdIn\r\n\r\nobject Main extends App {\r\n  def main() = {\r\n    val n = StdIn.readLine().toInt\r\n    val X = 998244353\r\n    val result = Range(2, n+1).foldLeft((1, 1)) { (state, x) =>\r\n      val (totalSum, prev) = state\r\n      val m = multiples(x) - 1\r\n      val cur = (prev + totalSum + m) % X\r\n      ((totalSum + prev) % X, cur)\r\n    }\r\n    println(result._2)\r\n  }\r\n\r\n  def multiples(n: Int): Int = {\r\n    if (n == 1)\r\n      1\r\n    else {\r\n      val p = primeMultiple(n)\r\n      var result = 1;\r\n      var x = n\r\n      while (x % p == 0) {\r\n        result += 1\r\n        x /= p\r\n      }\r\n      result * multiples(x)\r\n    }\r\n  }\r\n\r\n  val primes = {\r\n    def sieve(stream: Stream[Int]): Stream[Int] = {\r\n      stream.head #:: stream.tail.filter(_ % stream.head != 0)\r\n    }\r\n    sieve(Stream.from(2))\r\n  }\r\n\r\n  var primeMultipleArr = Array.fill(1000001)(-1)\r\n  primes.takeWhile(_ < 1000).foreach { x =>\r\n    var y = x * x\r\n    while (y < primeMultipleArr.size) {\r\n      if (primeMultipleArr(y) == -1)\r\n        primeMultipleArr(y) = x\r\n      y += x\r\n    }\r\n  }\r\n\r\n  def primeMultiple(i: Int) = {\r\n    primeMultipleArr(i) match {\r\n      case -1 => i\r\n      case x => x\r\n    }\r\n  }\r\n\r\n  main()\r\n}\r\n", "src_uid": "09be46206a151c237dc9912df7e0f057"}
{"source_code": "object Try1 {\n  def main(args: Array[String]) {\n    var ans,m,x,c,k, n, i: Int = 0\n    var z = new Array[Int](26)\n    n = readInt()\n    var line = readLine()\n    i=0\n    ans=0\n    while (i<n)\n      {\n        while(i<n && line(i)>='A' && line(i)<='Z') i+=1\n        m=0\n        for (k <- 0 to 25) z(k)=0\n        while(i<n && line(i)>='a' && line(i)<='z')\n          {\n            z(line(i)-'a')+=1\n            i+=1\n          }\n        for (k <- 0 to 25) if (z(k)>0) m+=1\n        if (m>ans) ans=m\n      }\n    println(ans)\n  }\n}", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3"}
{"source_code": "\nimport scala.collection.mutable.Stack\nimport scala.collection.mutable.Queue\nimport java.io.FileInputStream\n\n\n\nobject Main {\n    def mktuple(c : Char, t :Tuple2[Int, Int]) : Tuple2[Int, Int] = {\n            val (x, y) = t\n                    c match {\n                    case 'U' => (x, y +1)\n                    case 'D' => (x, y-1)\n                    case 'R' => (x +1, y)\n                    case 'L' => (x-1, y)\n            }\n    }\n\n    def main(args: Array[String]): Unit = {\n         \n            val s = new java.util.Scanner(System.in)\n            val (a, b, move) = (s.nextInt, s.nextInt, s.next)\n            var locs = new Array[Tuple2[Int, Int]](move.length + 1)\n            locs(0) = (0, 0)\n            for (i <- 1 to move.length)\n                locs(i) = mktuple(move.charAt(i-1), locs(i-1))\n                val (fullx, fully) = (locs(move.length)._1, locs(move.length)._2)\n                for (i <- 0 to move.length){\n                    if (fullx == 0 && fully == 0) {\n                        if ( locs(i) == (a,b)){\n                            println(\"Yes\")\n                            return                  \n                        }\n                    }\n                    else if (fullx == 0){ \n                        if (a == locs(i)._1 && \n                                (b - (locs(i)._2)) % fully == 0 &&\n                                (b - (locs(i)._2)) / fully >= 0){\n                            println(\"Yes\")\n                            return\n                        }\n                    }\n                    else if (fully == 0) { \n                        if (b == locs(i)._2 &&\n                                (a - (locs(i)._1)) % fullx == 0 &&\n                                (a - (locs(i)._1)) / fullx >= 0) {\n                            println(\"Yes\")\n                            return\n                        }}\n                    else {    \n\n                        val (t1, t2) = ( (a - locs(i)._1) /fullx, (b - locs(i)._2) / fully)\n                                if (t1 == t2 && t1 >= 0 && \n                                (a - (locs(i)._1)) % fullx == 0 &&\n                                (b - (locs(i)._2)) % fully == 0) {\n                                    println(\"Yes\")\n                                    return\n                                }\n                    }\n                }\n            println(\"No\")\n    }\n}", "src_uid": "5d6212e28c7942e9ff4d096938b782bf"}
{"source_code": "import java.util.Scanner\n\nobject P388A {\n    def main(args: Array[String]) {\n        val scanner = new Scanner(System.in)\n        val n = scanner.nextInt()\n        val boxes = for (i <- 1 to n) yield scanner.nextInt()\n        val piles = construct(boxes.toList.sorted)\n        println(piles.length)\n    }\n\n    def construct(boxes: List[Int]): List[Int] = {\n        val piles = new scala.collection.mutable.ListBuffer[Int]()\n        for (box <- boxes) {\n            val index = piles.indexWhere(_ <= box)\n            if (index == -1) piles += 1\n            else piles(index) += 1\n        }\n        piles.toList\n    }\n}\n", "src_uid": "7c710ae68f27f140e7e03564492f7214"}
{"source_code": "object Main {\n  def main(args: Array[String]): Unit = {\n    val s = new Main()\n    s.solve()\n    s.out.flush()\n  }\n}\n\nclass Main {\n  import java.io._\n  import java.util.StringTokenizer\n\n  import scala.collection.mutable\n  import scala.util.Sorting\n  import math.{abs, max, min}\n  import mutable.{ArrayBuffer, ListBuffer}\n  import scala.reflect.ClassTag\n\n  val MOD = 1000000007\n  val out = new PrintWriter(System.out)\n\n  def solve(): Unit = {\n    val N = ni()\n    val S = ns(N)\n    val eight = S count (_ == '8')\n    val ans = min(S.length / 11, eight)\n    out.println(ans)\n  }\n\n\n  class InputReader(val stream: InputStream) {\n    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n    private var tokenizer: StringTokenizer = _\n\n    def next(): String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new StringTokenizer(reader.readLine)\n      tokenizer.nextToken\n    }\n\n    def nextInt(): Int = next().toInt\n    def nextLong(): Long = next().toLong\n    def nextChar(): Char = next().charAt(0)\n  }\n  val sc = new InputReader(System.in)\n  def ni(): Int = sc.nextInt()\n  def nl(): Long = sc.nextLong()\n  def nc(): Char = sc.nextChar()\n  def ns(): String = sc.next()\n  def ns(n: Int): Array[Char] = ns().toCharArray\n  def na(n: Int): Array[Int] = map(n)(_ => ni())\n  def nal(n: Int): Array[Long] = map(n)(_ => nl())\n  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))\n  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = offset\n    val N = n + offset\n    while(i < N) { f(i); i += 1 }\n  }\n  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = n - 1 + offset\n    while(i >= offset) { f(i); i -= 1 }\n  }\n\n  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {\n    val res = Array.ofDim[A](n)\n    rep(n)(i => res(i) = f(i))\n    res\n  }\n\n  def sumL(as: Array[Int]): Long = {\n    var s = 0L\n    rep(as.length)(i => s += as(i))\n    s\n  }\n}", "src_uid": "259d01b81bef5536b969247ff2c2d776"}
{"source_code": "/**\n  * Created by Permagate on 29-Jan-17.\n  */\nimport java.io.PrintWriter\nimport java.util.Scanner\n\nobject A extends App {\n  object Solver {\n    def run(algoToRun: (Scanner, PrintWriter) => Unit): Unit = {\n      val in = new Scanner(System.in)\n      val out = new PrintWriter(System.out)\n\n      try {\n        algoToRun(in, out)\n      } catch {\n        case ex: Exception => ex.printStackTrace(out)\n      } finally {\n        out.flush()\n        out.close()\n      }\n    }\n  }\n\n  Solver.run(algoToRun = (in, out) => {\n    val n: Long = in.nextLong()\n    val k: Int = in.nextInt()\n\n    val divisors: List[Long] =\n      (for (i <- 1L to math.sqrt(n).toLong if n % i == 0) yield i).toList\n        .filter(num => n % num == 0)\n        .flatMap(divisor => divisor match {\n          case divi if divi == n / divi => List(divi)\n          case divi => List(divi, n / divi)\n        })\n        .sorted\n\n    val answer: Long = if (k > divisors.length) -1 else divisors(k - 1)\n    out.println(answer)\n  })\n}\n", "src_uid": "6ba39b428a2d47b7d199879185797ffb"}
{"source_code": "object Codeforces460A extends App{\n\n  def DayCount(firsthave:Int,every:Int):Int={\n    var have:Int=firsthave\n    var plus:Int=firsthave/every\n    have+=plus\n    var remainder:Int= firsthave%every\n    remainder+=plus\n    while (remainder >= every){\n      plus=remainder/every\n      have+=plus\n      remainder=remainder%every+plus\n    }\n    return have\n  }\n\n  val initval=scala.io.StdIn.readLine.split(\" \").map(_.toInt)\n  println(DayCount(initval(0),initval(1)))\n\n}\n", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0"}
{"source_code": "object B extends App {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }\n\n  val Array(n) = readInts(1)\n  val as = Array.fill(n){ readLine.toInt }\n  val ds = (0 until n).toSet\n\n  var res = \"NO\"\n  for {\n    d <- ds.subsets\n  } {\n    val (l, r) = as.indices.partition(d)\n    val pos = l.map(as).sum - r.map(as).sum\n    if (pos % 360 == 0) res = \"YES\"\n  }\n\n  println(res)\n\n  Console.flush\n}\n", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10"}
{"source_code": "import scala.collection.mutable\n\nobject C extends App {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }\n\n  val Array(n, l) = readLongs(2)\n  val cs = readLongs(n.toInt)\n  val mem = mutable.Map.empty[(Long, Int), Long]\n\n  def calc(ll: Long, from: Int): Long = {\n    if (ll == 0L) 0L\n    else if (from == 0L) ll * cs(0)\n    else if (mem.contains((ll, from))) mem((ll, from))\n    else {\n      val v = 1L << from\n      val full = cs(from) * ((ll + v - 1) / v)\n      //println(ll, from , v, full)\n      val c = if (ll >= v) {\n        Math.min(\n          Math.min(\n            calc(ll % v, from - 1) + cs(from) * (ll / v),\n            calc(ll, from - 1)),\n          full)\n      } else {\n        Math.min(calc(ll, from - 1), full)\n      }\n      mem.put((ll, from), c)\n      c\n    }\n  }\n\n  val res = calc(l, n.toInt - 1)\n\n  println(res)\n}\n", "src_uid": "04ca137d0383c03944e3ce1c502c635b"}
{"source_code": "object Sishik_49A extends App {\n  val str = readLine()\n  val splitted = str.split(\" \").toList\n  var splt = \"\"\n  for (i <- splitted) {\n    splt = splt + i\n  }\n  val lastSymbol = splt.substring(splt.length - 2, splt.length - 1).toUpperCase\n  val listGLAS = List(\"A\", \"E\", \"I\", \"O\", \"U\", \"Y\")\n  val listSOGLAS = List(\"B\", \"C\", \"D\", \"F\", \"G\", \"H\", \"J\", \"K\", \"L\", \"M\", \"N\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"V\", \"W\", \"X\", \"Z\")\n  def identify(char: String): Unit = char match {\n    case charac if listGLAS.contains(charac) => println(\"YES\")\n    case charac if listSOGLAS.contains(charac) => println(\"NO\")\n  }\n  identify(lastSymbol)\n}\n", "src_uid": "dea7eb04e086a4c1b3924eff255b9648"}
{"source_code": "\n\n/**\n  *\n  */\nobject P868B {\n  def main(args: Array[String]): Unit = {\n    val sc = new java.util.Scanner(System.in)\n    val h = sc.nextInt // 1\u2009\u2264\u2009h\u2009\u2264\u200912\n    val m = sc.nextInt // 0\u2009\u2264\u2009m\n    val s = sc.nextInt // s\u2009\u2264\u200959\n    val t1 = sc.nextInt // 1\u2009\u2264\u2009t1,\u2009t2\u2009\u2264\u200912, t1\u2009\u2260\u2009t2\n    val t2 = sc.nextInt\n    // Misha's position and the target time do not coincide with the position of any hand.\n\n    //    Output\n    //    Print \"YES\" (quotes for clarity), if Misha can prepare the contest on time, and \"NO\" otherwise.\n    //    You can print each character either upper- or lowercase (\"YeS\" and \"yes\" are valid when the answer is \"YES\").\n\n    //    Last time Misha talked with the coordinator at t1 o'clock, so now he stands on the number t1 on the clock face.\n    //    The contest should be ready by t2 o'clock. In the terms of paradox it means that Misha has to go to number t2 somehow.\n    //    Note that he doesn't have to move forward only: in these circumstances time has no direction.\n\n    //    if hour clock points 12 and Misha stands at 11 then he cannot move to 1 along the top arc.\n    //    He has to follow all the way round the clock center (of course, if there are no other hands on his way).\n\n    val clock = 0 to 600\n    val ns = s % 60 * 10\n    val nm = m % 60 * 10 + { if (ns > 0) 1 else 0 }\n    val nh = (h % 12) * 50 + { if (nm > 0) 1 else 0 }\n    val wall = Seq(ns, nm, nh).toSet\n\n    val a = (t1 % 12) * 50\n    val b = (t2 % 12) * 50\n\n    val cw = Iterator.continually(clock).flatten.dropWhile(_ != a).takeWhile(_ != b)\n    val acw = Iterator.continually(clock.reverse).flatten.dropWhile(_ != a).takeWhile(_ != b)\n\n    val canMoveClockwize = cw.forall(n => !wall.contains(n))\n    val canMoveAntiClockwize = acw.forall(n => !wall.contains(n))\n\n    if (canMoveAntiClockwize || canMoveClockwize) println(\"YES\")\n    else println(\"NO\")\n  }\n}\n", "src_uid": "912c8f557a976bdedda728ba9f916c95"}
{"source_code": "object aTask {\n  import scala.io.StdIn.{readInt, readLine}\n\n  def func(str: List[Char], acc: List[Char]): List[Char] = {\n    str match {\n      case Nil => acc\n      case x::Nil => x::acc\n      case x::y::xs if x == 'U' && y == 'R' => func(xs, 'D'::acc)\n      case x::y::xs if x == 'R' && y == 'U' => func(xs, 'D'::acc)\n      case x::xs => func(xs, x::acc)\n\n    }\n\n  }\n\n  def main(args: Array[String]): Unit ={\n    val n = readInt\n    val s = readLine.toCharArray.toList\n    println(func(s, List()).length)\n  }\n}\n", "src_uid": "986ae418ce82435badadb0bd5588f45b"}
{"source_code": "object Main {\n\n  def parseInput: (String, String, String) = {\n    val lr = (readLine + \"|_\").split('|')\n    val remain = readLine\n    (lr(0), lr(1), remain)\n  }\n\n  def solve(left: String, right: String, remain: String): String = {\n    val diff = math.abs(left.length - right.length)\n    if (remain.length >= diff && (remain.length - diff) % 2 == 0) {\n      val k = (remain.length - diff) / 2 + (if (left.length < right.length) diff else 0)\n      (left + remain.substring(0, k)) + '|' + (right + remain.substring(k))\n    } else {\n      null\n    }\n  }\n\n  def main(args: Array[String]) {\n    val (left, right, remain) = parseInput\n    val result = solve(left, right, remain)\n    println(if (result == null) \"Impossible\" else result)\n  }\n}\n", "src_uid": "917f173b8523ddd38925238e5d2089b9"}
{"source_code": "\nobject SantaClausAndAPlaceInAClass extends App{\n  val Array(n, m, k) = io.StdIn.readLine.split(\"\\\\s+\").map(_.toInt)\n  val lane = Math.ceil(k / (2.0 * m)).toInt\n  val desk = Math.ceil((k - (lane - 1) * 2 * m) / 2.0).toInt\n  println(s\"\"\"$lane $desk ${if(k % 2 == 0) \"R\" else \"L\"}\"\"\")\n}\n", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb"}
{"source_code": "object A extends App {\n  val sc = new java.util.Scanner(System.in)\n  val n, s = sc.nextInt()\n  val t = Array.fill(n)(sc.nextInt()).sortWith(_ > _)\n  println(if (t.tail.sum <= s) \"YES\" else \"NO\")\n}\n", "src_uid": "496baae594b32c5ffda35b896ebde629"}
{"source_code": "\nimport scala.math._\n\nobject Main extends App {\n  val Array(l1, r1, l2, r2, k) = readLine.split(\" \").map(_.toLong)\n  val l = max(l1, l2)\n  val r = min(r1, r2)\n  val res = if (l <= r) {r - l + 1 - (if (k >= l && k <= r) 1 else 0)} else 0\n  println(res)  \n}", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82"}
{"source_code": "object Main\n{\n\tdef min (a : Int, b : Int) : Int = \n\t\tif (a < b) return a\n\t\telse return b\n\tdef main (args : Array[String]) = \n\t{\n\t\tval n_v = readLine.split(' ').map(_.toInt)\n\t\tval n = n_v(0)\n\t\tval v = n_v(1)\n\n\t\tvar grad = 2\n\t\tvar kolku_imam = min(n-1, v) - 1\n\t\tvar rez = kolku_imam + 1\n\n\t\twhile (grad != n)\n\t\t{\n\t\t\t//println(\"vleguva za grad = \" + grad + \" kolku_imam = \" + kolku_imam + \" rez = \" + rez)\n\t\t\tvar kolku = n - grad\n\t\t\tif (kolku_imam >= kolku)\n\t\t\t{\n\t\t\t\tgrad += 1\n\t\t\t\tkolku_imam -= 1\n\t\t\t}\n\t\t\telse \n\t\t\t{\n\t\t\t\t//staj si od ovaa stanica\n\t\t\t\tkolku_imam -= 1\n\t\t\t\tkolku_imam += 1\n\t\t\t\trez += grad\n\t\t\t\tgrad += 1\n\t\t\t}\n\t\t}\n\n\t\tprintln(rez)\n\t}\n}", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7"}
{"source_code": "\n/**\n  * Created by reynaldo on 2/17/16.\n  */\nobject B {\n\n  def main(args: Array[String]) {\n    val in = scala.io.StdIn\n\n    val line = in.readLine()\n    val h = line.substring(0, 2).toInt\n    val m = line.substring(3, 5).toInt\n    val a = in.readInt()\n\n    solve(h, m + a)\n\n    @annotation.tailrec\n    def solve(h: Int, m: Int): Unit = {\n      if (m < 60 && h < 24)\n        println(f\"$h%02d:$m%02d\")\n      else if (m >= 60)\n        solve(h + m / 60, m %  60)\n      else\n        solve(h % 24, m)\n    }\n  }\n}\n", "src_uid": "20c2d9da12d6b88f300977d74287a15d"}
{"source_code": "\n/**\n  * Created by octavian on 06/02/2016.\n  */\nobject Luke {\n\n  def main(args: Array[String]) {\n\n    //System.setIn(new FileInputStream(\"./src/luke.in\"))\n    //System.setOut(new PrintStream(new FileOutputStream(\"./src/luke.out\")))\n\n    val Array(d, l, v1, v2):Array[Double] = readLine().split(\" \").map(_.toDouble)\n    println((l - d)/(v1 + v2))\n  }\n\n}\n", "src_uid": "f34f3f974a21144b9f6e8615c41830f5"}
{"source_code": "import scala.collection._\n\nobject A extends App {\n  \n  val as = readLine\n  val bs = readLine\n  \n  val res = (for (i <- 0 until as.length by 2) yield (as(i), bs(i)) match {\n    case ('[', '8') => 1\n    case ('(', '[') => 1\n    case ('8', '(') => 1\n    case (a, b) if a == b => 0\n    case _ => -1\n  }) sum\n  \n  if (res > 0) println(\"TEAM 2 WINS\")\n  else if (res < 0) println(\"TEAM 1 WINS\")\n  else println(\"TIE\")\n}", "src_uid": "bdf2e78c47d078b4ba61741b6fbb23cf"}
{"source_code": "object JuanDavidRobles112A {\n  def main(args: Array[String]): Unit = {\n\n    import scala.io.StdIn\n    var str1 : String = StdIn.readLine()\n    var str2 : String = StdIn.readLine()\n\n    if (str1.equalsIgnoreCase(str2)){\n      println(\"0\")\n      return\n    }\n\n    str1 = str1.toUpperCase()\n    str2 = str2.toUpperCase()\n\n    if (str1.compareTo(str2) > 0){\n      println(\"1\")\n    } else {\n      println(\"-1\")\n    }\n\n    /*for (i <- 0 until str1.length) {\n      if (str1.charAt(i).toInt != str2.charAt(i).toInt) {\n        if (str1.charAt(i).toInt > str2.charAt(i).toInt) {\n          println(\"1\")\n        } else {\n          println(\"-1\")\n        }\n        return\n      }\n    }*/\n  }\n}\n", "src_uid": "ffeae332696a901813677bd1033cf01e"}
{"source_code": "object Main {\n  class Card(val value: Int, val suit: Char) {\n  }\n  \n  object Card {\n    def apply(s: String) = {\n      val v = s(0) match {\n        case '6' => 6\n        case '7' => 7\n        case '8' => 8\n        case '9' => 9\n        case 'T' => 10\n        case 'J' => 11\n        case 'Q' => 12\n        case 'K' => 13\n        case 'A' => 14\n      }\n      new Card(v, s(1))\n    }\n    \n    def compare(c1: Card, c2: Card, s: Char) = {\n      if (c1.suit == s && c2.suit == s) c1.value > c2.value\n      else if (c1.suit == s) true\n      else (c1.suit == c2.suit && c1.value > c2.value)\n    }\n  }\n  \n  def main(args: Array[String]) {\n    val s = readChar()\n    val cs = readLine().split(\" \")\n    val c1 = Card(cs(0))\n    val c2 = Card(cs(1))\n    if (Card.compare(c1, c2, s)) println(\"YES\")\n    else println(\"NO\")\n  }\n}", "src_uid": "da13bd5a335c7f81c5a963b030655c26"}
{"source_code": "import scala.math._, scala.io.StdIn._\n\nobject D extends App {\n  val Array(n, k) = readLongs\n  val Array(a, b) = readLongs\n\n  val d1 = k + a - b\n  val d2 = a + b\n  println(s\"${min(minStops(d1), minStops(d2))} ${max(maxStops(d1), maxStops(d2))}\")\n\n  def minStops(d: Long) = {\n    val d1 = d / gcd(d, k)\n    val k1 = k / gcd(d, k)\n    val k2 = gcd(k1, n)\n    k1 * (0L until n / k2).map(i => n / gcd(n, d1 + k2 * i)).min\n  }\n\n  def maxStops(d: Long) = n * k / gcd(d, k)\n\n  def gcd(x: Long, y: Long): Long = if (y == 0) x else gcd(y, x % y)\n  def lcm(x: Long, y: Long): Long = x * y / gcd(x, y)\n\n  def readLongs() = readLine.split(\" \").map(_.toLong)\n}\n", "src_uid": "5bb4adff1b332f43144047955eefba0c"}
{"source_code": "object A extends App {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }\n\n  val Array(n) = readInts(1)\n\n  if (n == 1) {\n    println(\"1 1\")\n    println(1)\n  } else {\n    val x = (n - 1) * 2\n    println(s\"$x 2\")\n    println(\"1 2\")\n  }\n}\n", "src_uid": "5c000b4c82a8ecef764f53fda8cee541"}
{"source_code": "object A extends App {\n  val Array(n, m, a, b) = scala.io.StdIn.readLine().split(\" \").map(_.toLong)\n\n  val t = n / m\n\n  val r =\n    if (t == 0) ((m - n) * a) min (n * b)\n    else ((n - t * m) * b) min (((t + 1) * m - n) * a)\n\n  println(r)\n}\n", "src_uid": "c05d753b35545176ad468b99ff13aa39"}
{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n  val in = Source.stdin.getLines()\n  val n = in.next().toLong\n  if (n == 1)\n    println(1)\n  else if (n == 2)\n    println(2)\n  else if (n == 3)\n    println(6)\n  else if (n % 2 == 0 && n % 3 == 0)\n    println((n - 1) * (n - 2) * (n - 3))\n  else if (n % 2 == 0)\n    println(n * (n - 1) * (n - 3))\n  else\n    println(n * (n - 1) * (n - 2))\n}\n", "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e"}
{"source_code": "import java.util.Scanner\n\nobject Rounding {\n  def main(args: Array[String]): Unit = {\n    val sc = new Scanner(System.in)\n    val X = sc.nextInt()\n    println(if (X % 10 <= 5) X - (X % 10) else X + 10 - (X % 10))\n  }\n}\n", "src_uid": "29c4d5fdf1328bbc943fa16d54d97aa9"}
{"source_code": "import collection.mutable.Map\n\nobject test6 extends App {\n    val y=readInt\n    for(i<- y+1 to 9999 if i.toString.distinct.size>=4) {println(i); exit(0)}\n}   \n\n\n", "src_uid": "d62dabfbec52675b7ed7b582ad133acd"}
{"source_code": "import java.util.Scanner\n\nobject ZeroProblem extends App {\n\n  val s = new Scanner(System.in)\n  val n = s.nextInt()\n  val k = s.nextInt()\n  var primes = Array.fill[Boolean](n + 1)(true)\n  findPrimes()\n  val sl = (2 to n).filter(primes).sliding(2).filter(_.size > 1).count(x => (x(0) + x(1) + 1) <= n && primes(x(0) + x(1) + 1))\n  if (sl >= k) println(\"YES\") else println(\"NO\")\n\n  def findPrimes(): Unit = {\n    var i = 2\n    while (i < n + 1) {\n      if (primes(i)) {\n        var j = i + i\n        while (j < n) {\n          primes(j) = false\n          j += i\n        }\n      }\n      i += 1\n    }\n  }\n\n}", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d"}
{"source_code": "object Main extends App {\n  def luckyDigit(c : Char) = c == '4' || c == '7'\n  def luckyNum(s : String) = s.foldLeft(true)(_ & luckyDigit(_))\n  def sumChar(s : String) = s.foldLeft(0)(_ + _ -'0')\n  def sumEqual(s : String, l : Int) = sumChar(s.take(l)) == sumChar(s.drop(l))\n  def lucky(n : Int, s : String) = luckyNum(s) && sumEqual(s, n/2)\n\n  println(if (lucky(readLine.toInt, readLine)) \"YES\" else \"NO\")\n}\n", "src_uid": "435b6d48f99d90caab828049a2c9e2a7"}
{"source_code": "object Solution extends App {\n  val in = scala.io.Source.stdin.getLines()\n  def sim(x: Long, y: Long, m: Long, sum: Long = 0l): Long = {\n    val min = Math.min(x, y)\n    val max = Math.max(x, y)\n    if (max >= m)\n      sum\n    else\n      sim(max, min + max, m, sum + 1)\n  }\n  \n  val Array(x, y, m) = in.next().split(' ').map(_.toLong)\n  if (x >= m || y >= m)\n    println(0)\n  else if (x <= 0 && y <= 0)\n    println(-1)\n  else if (x >= 0 && y >= 0) {\n    println (sim(x, y, m))\n  }\n  else\n  {\n    val max = Math.max(x, y)\n    val min = Math.min(x, y)\n    val toPlus = -(min + max - 1) / max\n    val nMin = toPlus * max + min\n    println (sim(max, nMin, m) + toPlus)\n  }\n}\n", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821"}
{"source_code": "object CF1076b extends App {\n  val in = new java.util.Scanner(System.in)\n  val out = new java.io.PrintWriter(System.out)\n\n  import scala.math._\n\n  def findPrime(n: Long) : Long = {\n    if (n % 2 == 0) { 2 }\n    else {\n      (3 to Int.MaxValue by 2).view.map(_.toLong).takeWhile((x: Long) => x*x <= n).filter(n % _ == 0).headOption getOrElse n\n    }\n  }\n\n  def solve(n: Long) : Long = {\n    if (n % 2 == 0) { n/2 }\n    else {\n      solve(n-findPrime(n)) + 1\n    }\n  }\n\n  val n = in.nextLong\n  out.println(solve(n))\n  out.flush;out.close;\n}\n", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6"}
{"source_code": "object Two63A extends App {\n\timport java.io.PrintWriter\n\timport java.util.Scanner\n\n\tval in = new Scanner(System.in)\n\tval out = new PrintWriter(System.out)\n\tval m = for {\n\t\ti <- 0 until 5\n\t\tj <- 0 until 5\n\t\tk = in.nextInt()\n\t\tif k == 1\n\t} yield (i, j)\n\tval abs = math.abs(m(0)._1 - 2) + math.abs(m(0)._2 - 2)\n\tout.println(abs)\n\tin.close()\n\tout.close()\n}", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9"}
{"source_code": "import scala.io.StdIn._\n\nobject CF577A extends App {\n  val Array(n, x) = readLine().split(\" \").map(_.toInt)\n  var c = 0\n  (1 to n).foreach(i => if (x % i == 0 && x / i <= n) c = c + 1)\n  println(c)\n}\n", "src_uid": "c4b139eadca94201596f1305b2f76496"}
{"source_code": "object A {\n  def main(args: Array[String]): Unit = {\n\n    val Array(n, a, b, c) = scala.io.StdIn.readLine.split(\" \").map(_.toLong)\n    val ans = n % 4 match {\n      case 0 => 0\n      case 1 => Array(c, 3 * a, a + b).min\n      case 2 => Array(b, 2 * a, 2 * c).min\n      case 3 => Array(a, b + c, 3 * c).min\n    }\n    println(ans)\n  }\n}\n", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8"}
{"source_code": "import scala.io.StdIn\n\nobject Codeforces114A {\n  def isHappy(x: Int, y: Int, z: Int, a: Int, b: Int, c: Int): Boolean =\n    x <= a && x + y <= a + b && x + y + z <= a + b + c\n\n  def main(args: Array[String]): Unit = {\n    val Array(x, y, z) = StdIn.readLine().trim.split(\" \").map(_.toInt)\n    val Array(a, b, c) = StdIn.readLine().trim.split(\" \").map(_.toInt)\n\n    val happy = isHappy(x, y, z, a, b, c)\n\n    val output = if (happy) \"YES\" else \"NO\"\n    println(output)\n  }\n}\n", "src_uid": "d54201591f7284da5e9ce18984439f4e"}
{"source_code": "import scala.annotation.tailrec\nobject X extends App {\n  case class Point(x: Double, y: Double)\n  case class Line(u: Point, v: Point) {\n    lazy val slope = (v.y - u.y) / (v.x - u.x)\n    lazy val midPoint = Point((u.x + v.x) / 2, (u.y + v.y) / 2)\n  }\n\n  val perpBisector = (l: Line) => {\n    val mid = l.midPoint\n    val otherPoint = Point(mid.x + l.u.y - l.v.y, mid.y + l.v.x - l.u.x)\n    Line(mid, otherPoint)\n  }\n\n  val intersectLine = (l1: Line, l2: Line) => {\n    val numer =\n      (l1.u.x - l2.u.x) * (l2.u.y - l2.v.y) - (l1.u.y - l2.u.y) * (l2.u.x - l2.v.x)\n\n    val denom =\n      (l1.u.x - l1.v.x) * (l2.u.y - l2.v.y) - (l1.u.y - l1.v.y) * (l2.u.x - l2.v.x)\n\n    val t = numer / denom\n\n    val x = l1.u.x + t * (l1.v.x - l1.u.x)\n    val y = l1.u.y + t * (l1.v.y - l1.u.y)\n\n    Point(x, y)\n  }\n\n  val calculateCircleCentre = (A: Point, B: Point, C: Point) => {\n    val l1 = Line(B, C)\n    val l2 = Line(A, B)\n\n    intersectLine(perpBisector(l1), perpBisector(l2))\n  }\n\n  val getAngle = (p1: Point, p2: Point, p3: Point) => {\n    val r1Square =\n      (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)\n    val r2Square =\n      (p2.x - p3.x) * (p2.x - p3.x) + (p2.y - p3.y) * (p2.y - p3.y)\n    val r3Square =\n      (p3.x - p1.x) * (p3.x - p1.x) + (p3.y - p1.y) * (p3.y - p1.y)\n\n    val denom = 2 * Math.sqrt(r1Square * r2Square)\n    val numer = r1Square + r2Square - r3Square\n\n    val cosTheta = numer / denom\n\n    Math.acos(cosTheta)\n  }\n\n  @tailrec\n  def findDenom(\n      dec: Double,\n      closeEnough: (Double, Int) => Boolean,\n      i: Int = 1,\n      bestCase: Int = 1,\n      closestDiff: Double = 1\n  ): Int = {\n    val mult = i * dec\n    val diff = mult - Math.floor(mult)\n    val actualDiff = if (diff < 0.5) diff else 1 - diff\n    val nextClosestDiff =\n      if (actualDiff < closestDiff) actualDiff else closestDiff\n    val nextBestCase = if (actualDiff == nextClosestDiff) i else bestCase\n\n    if (closeEnough(closestDiff, i)) bestCase\n    else findDenom(dec, closeEnough, i + 1, nextBestCase, nextClosestDiff)\n  }\n  @tailrec\n  def gcd(a: Int, b: Int): Int = {\n    if (b == 0) a else gcd(b, a % b)\n  }\n\n  val lcm = (a: Int, b: Int) => a * b / gcd(a, b)\n\n  val computeArea = (p1: Point, p2: Point, p3: Point) => {\n    val closeEnough = (closestDiff: Double, i: Int) => {\n      closestDiff < 0.000001 || i > 100\n    }\n    val centre = calculateCircleCentre(p1, p2, p3)\n\n    val angle1 = getAngle(p1, centre, p2) / (2 * Math.PI)\n    val angle2 = getAngle(p2, centre, p3) / (2 * Math.PI)\n    val angle3 = getAngle(p3, centre, p1) / (2 * Math.PI)\n\n    val denom1 = findDenom(angle1, closeEnough)\n    val denom2 = findDenom(angle2, closeEnough)\n    val denom3 = findDenom(angle3, closeEnough)\n\n    val lcmAngle = lcm(lcm(denom1, denom2), denom3)\n\n    val area =\n      0.5 * ((centre.x - p1.x) * (centre.x - p1.x) + (centre.y - p1.y) * (centre.y - p1.y)) * Math\n        .sin((2 * Math.PI) / lcmAngle) * lcmAngle\n\n    area\n  }\n\n  val lineToPoint = (line: String) => {\n    val coords = line.split(\" \").map(s => s.toDouble)\n    Point(coords(0), coords(1))\n  }\n\n  val t1 = scala.io.StdIn.readLine()\n  val t2 = scala.io.StdIn.readLine()\n  val t3 = scala.io.StdIn.readLine()\n\n  val p1 = lineToPoint(t1)\n  val p2 = lineToPoint(t2)\n  val p3 = lineToPoint(t3)\n\n  val area = computeArea(p1, p2, p3)\n\n  println(area)\n}\n", "src_uid": "980f4094b3cfc647d6f74e840b1bfb62"}
{"source_code": "object Main  extends App {\n    val n = readLine.split(' ').map(_.toInt)\n    val arr = readLine.split(' ').map(_.toInt).toList\n    arr.sorted.map{x=>print(x+\" \")}\n}", "src_uid": "ae20712265d4adf293e75d016b4b82d8"}
{"source_code": "import scala.io.StdIn\nimport scala.util.control.Breaks._\n\n\nobject Vitya_in_the_Countryside_719A {\n  def main(args: Array[String]): Unit = {\n    val c = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)\n    val cal = c ++ c ++ c ++ c ++ c\n    val n = StdIn.readInt()\n    val observ = StdIn.readLine().split(\" \").map( _.toInt )\n    var up = 0\n    var down = 0\n    for (i <- cal.indices.dropRight(observ.length)) {\n      breakable {\n        for (j <- observ.indices) {\n          if (cal(i + j) != observ(j)) break\n          if (j == observ.length - 1 && i + j != cal.length - 1) {\n            if (cal(i + j + 1) > cal(i + j)) up += 1\n            else down += 1\n          }\n        }\n      }\n    }\n    if (up == 0 && down > 0) println(\"DOWN\")\n    else if (down == 0 && up > 0) println(\"UP\")\n    else println(-1)\n  }\n}", "src_uid": "8330d9fea8d50a79741507b878da0a75"}
{"source_code": "import scala.io._\nimport java.io._\n\nobject ProblemA {\n  def main(args: Array[String]): Unit = processStdInOut()\n\n  def processStdInOut(): Unit = {\n    val src = io.Source.fromInputStream(System.in)\n    try {\n      val bw = new BufferedWriter(new OutputStreamWriter(System.out));\n      try {\n        val lines = src.getLines()\n        processLines(lines, bw)\n      } finally {\n        bw.flush()\n        bw.close()\n      }\n    } finally {\n      src.close();\n    }\n  }\n\n  // Standard code above, custom code below\n\n  case class Solution(runCount: Int, runs: List[Int])\n\n  def processLines(lines: Iterator[String], bw: BufferedWriter): Unit = {\n\n    val size = lines.next().toInt\n    val chars = lines.next() + 'W' // Ensure last run isn't missed by appending dummy character\n    val soln = solve(size, chars.toList)\n    bw.write(s\"${soln.runCount}\")\n    bw.newLine()\n    if (soln.runCount > 0) {\n      bw.write(soln.runs.mkString(\" \"))\n      bw.newLine()\n    }\n  }\n\n  case class Accumulator(wasLastCharB: Boolean, blackCount: Int, runsInReverse: List[Int], runCount: Int)\n\n  def solve(size: Int, chars: List[Char]): Solution = {\n    val accumulator = chars.foldLeft(Accumulator(false, 0, List.empty, 0)) { (acc: Accumulator, ch: Char) =>\n        if (ch == 'B') {\n          acc.copy(wasLastCharB = true, blackCount = acc.blackCount + 1)\n        } else {\n          if (acc.wasLastCharB) {\n            acc.copy(wasLastCharB = false, blackCount = 0,\n              runsInReverse = acc.blackCount :: acc.runsInReverse,\n              runCount = acc.runCount + 1)\n          } else {\n            acc\n          }\n        }\n    }\n    Solution(accumulator.runCount, accumulator.runsInReverse.reverse)\n  }\n}\n", "src_uid": "e4b3a2707ba080b93a152f4e6e983973"}
{"source_code": "object A313 {\n  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)\n\n  def readInts(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)\n  }\n\n  def readLongs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong)\n  }\n\n  def readBigs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken))\n  }\n\n  def main(args: Array[String]): Unit = {\n    val Array(n) = readInts(1)\n    if(n > 0) {\n      println(n)\n    } else {\n      val s = n.toString.drop(1)\n      if(s.length == 1) {\n        println(\"0\")\n      } else {\n        if (-s.dropRight(1).toInt > -(s.dropRight(2) + s.last).toInt) {\n          println(- s.dropRight(1).toInt)\n        } else {\n          println(- (s.dropRight(2) + s.last).toInt)\n        }\n      }\n    }\n  }\n}", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e"}
{"source_code": "import scala.io._\nimport scala.collection.mutable._\nimport java.util.StringTokenizer\n\nobject HelloWorld {\n\n  def main(args: Array[String]): Unit = {\n    var s = readLine + readLine + readLine;\n    if (s.substring(0, 4) == s.substring(5, 9).reverse) {\n      println(\"YES\");\n    } else {\n      println(\"NO\");\n    }\n  }\n\n}", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9"}
{"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.collection.mutable.ListBuffer\nimport scala.collection.immutable.Queue\nimport scala.util.Random\n\nobject P104A extends App {\n  val sc = new Scanner(System.in)\n  val out = new PrintWriter(System.out)\n\n  val N = sc.nextInt\n  val stack = 0 :: 4 :: List.fill(8)(4) ::: (15 :: 4 :: Nil)\n\n  def solve(): Int = {\n    val rest = N - 10\n    if (rest < 1 || 11 < rest) 0\n    else stack(rest)\n  }\n\n  out.println(solve)\n  out.close\n}\n", "src_uid": "5802f52caff6015f21b80872274ab16c"}
{"source_code": "object B extends App {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }\n\n  val Array(k, p) = readInts(2)\n\n  var sum = 0L\n\n  var x = 1L\n  var mul = 10L\n  while (x <= k) {\n    if (x >= mul) mul *= 10\n    val y = x.toString.reverse.toLong\n    val xy = x * mul + y\n    sum = (sum + xy) % p\n    x += 1\n  }\n\n  println(sum)\n}\n", "src_uid": "00e90909a77ce9e22bb7cbf1285b0609"}
{"source_code": "\n\nobject objecta {\n    import java.io.{BufferedReader, FileInputStream, InputStreamReader}\n    import scala.collection.mutable\n    import scala.util.control.Breaks._\n    import scala.util.Random\n\n    val source = System.in\n    //new FileInputStream(\"D://in.txt\")\n    implicit val reader = new BufferedReader(new InputStreamReader(source))\n\n    def read()(implicit reader: BufferedReader): String = reader.readLine().split(\" \")(0)\n    def readArray()(implicit reader: BufferedReader): Array[String] = reader.readLine().split(\" \")\n    def readString()(implicit reader: BufferedReader): String = reader.readLine()\n\n    def main(args: Array[String]): Unit = {\n        val n = read().toInt\n        print(n % 2)\n    }\n}\n", "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795"}
{"source_code": "object Contest extends App {\n  \n  val Array(a, b) = readLine().split(\" \").map(_.toInt)\n  val p2 = math.min(a, b)\n  println((a + b - 1 - p2) + \" \" + p2)  \n}\n", "src_uid": "c8378e6fcaab30d15469a55419f38b39"}
{"source_code": "/**\n  * @author tdx\n  */\nobject Solution {\n  import scala.io.StdIn._\n\n  def main(args: Array[String]): Unit = {\n    val parts = readLine().split(\" \").map(_.toInt)\n    val n = parts(0)\n    val k = parts(1)\n    val grades = readLine().split(\" \").map(_.toInt)\n    var cur = grades.sum\n    var total = n\n    while (math.round(cur*1.0/total) < k) {\n      total += 1\n      cur += k\n    }\n    println(total - n)\n  }\n}\n", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900"}
{"source_code": "object _849A extends CodeForcesApp {\n  import Utils._, annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._\n\n  override def apply(io: IO): io.type = {\n    val v = io.read[Vector[Int]]\n    def isOdd(x: Int) = x%2 == 1\n    val ans = Iterator(v.head, v.last, v.length).forall(isOdd)\n    io.write(ans.toEnglish)\n    io\n  }\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n  lazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)\n  def apply(io: IO): io.type\n  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()\n}\nobject Utils {\n  import scala.collection.mutable, mutable.{Map => Dict}\n  implicit class GenericExtensions[A](val a: A) extends AnyVal {\n    def in(set: collection.Set[A]): Boolean = set(a)\n    def some: Option[A] = Some(a)\n    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a\n  }\n  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {\n    def onlyElement: A = assuming(t.size == 1)(t.head)\n    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)\n    def duplicates(implicit b: C of A): C[A] = {\n      val elems = mutable.Set.empty[A]\n      (t collect {case i if !elems.add(i) => i}).to[C]\n    }\n    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}\n    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)\n    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)\n    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]\n    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap\n    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)\n    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}\n    def toMutableMultiSet: Dict[A, Int] = {\n      val c = map[A] to 0\n      t.foreach(i => c(i) += 1)\n      c\n    }\n    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0\n    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)\n  }\n  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)\n  }\n  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)\n  }\n  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {\n    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t\n  }\n  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {\n    def key = p._1\n    def value = p._2\n    def toSeq(implicit ev: A =:= B): Seq[A] = Seq(p._1, p._2.asInstanceOf[A])\n  }\n  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {\n    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)\n    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])\n    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]\n  }\n  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {\n    def lastKeyOption: Option[K] = m.lastOption.map(_.key)\n    def firstKeyOption: Option[K] = m.headOption.map(_.key)\n    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap\n    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}\n    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m\n    def mapValuesSafely[V2](f: V => V2): Map[K, V2] = m.mapValues(f).view.force //Hack to get around https://issues.scala-lang.org/browse/SI-4776\n  }\n  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {\n    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)\n    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)\n    private def removeNode(kv: (K, V)): (K, V) = {\n      m -= kv.key\n      kv\n    }\n  }\n  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {\n    def notContains(x: A): Boolean = !(s contains x)\n    def toMutable = mutable.Set.empty[A] ++ s\n  }\n  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {\n    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}\n    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)\n    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)\n    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}\n    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)\n  }\n  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {\n    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero\n    def toEnglish = if(x) \"Yes\" else \"No\"\n  }\n  implicit class IntExtensions(val x: Int) extends AnyVal {\n    import java.lang.{Integer => JInt}\n    def withHighestOneBit: Int = JInt.highestOneBit(x)\n    def withLowestOneBit: Int = JInt.lowestOneBit(x)\n    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)\n    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)\n    def bitCount: Int = JInt.bitCount(x)\n    def setLowestBits(n: Int): Int = x | (left(n) - 1)\n    def clearLowestBits(n: Int): Int = x & left(n, ~0)\n    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)\n    def setBit(i: Int): Int = x | left(i)\n    def clearBit(i: Int): Int = x & ~left(i)\n    def toggleBit(i: Int): Int = x ^ left(i)\n    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1\n    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)\n    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)\n  }\n  implicit class LongExtensions(val x: Long) extends AnyVal {\n    import java.lang.{Long => JLong}\n    def withHighestOneBitSet: Long = JLong.highestOneBit(x)\n    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)\n    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)\n    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)\n    def bitCount: Int = JLong.bitCount(x)\n    def setLowestBits(n: Int): Long = x | (left(n) - 1)\n    def clearLowestBits(n: Int): Long = x & left(n, ~0L)\n    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)\n    def setBit(i: Int): Long = x | left(i)\n    def clearBit(i: Int): Long = x & ~left(i)\n    def toggleBit(i: Int): Long = x ^ left(i)\n    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1\n    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)\n  }\n  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {\n    import Numeric.Implicits._\n    def **(i: Int): A = if (i == 0) n.one else {\n      val h = x ** (i/2)\n      if (i%2 == 0) h * h else h * h * x\n    }\n    def distance(y: A) = (x - y).abs()\n    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)\n    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf \"Greg\" whenNegative Int.MaxValue\n  }\n  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {\n    import scala.collection.immutable.NumericRange, Integral.Implicits._\n    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x\n    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)\n    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)\n  }\n  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))\n  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)\n  def asc[A](implicit order: Ordering[A]): Ordering[A] = order\n  def map[K] = new {\n    def to[V](default: => V): Dict[K, V] = using(_ => default)\n    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {\n      override def apply(key: K) = getOrElseUpdate(key, f(key))\n    }\n  }\n  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]\n  def memoize[A, B](f: A => B): A ==> B = map[A] using f\n  implicit class FuzzyDouble(val x: Double) extends AnyVal {\n    def  >~(y: Double) = x > y + eps\n    def >=~(y: Double) = x >= y + eps\n    def  ~<(y: Double) = y >=~ x\n    def ~=<(y: Double) = y >~ x\n    def  ~=(y: Double) = (x distance y) <= eps\n  }\n  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {\n    val (xs, ys) = points.unzip\n    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)\n  }\n  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {\n    val shape = new java.awt.geom.GeneralPath()\n    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}\n    points.tail foreach {case (x, y) => shape.lineTo(x, y)}\n    shape.closePath()\n    shape\n  }\n  def until(until: Int): Range = 0 until until\n  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}\n  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}\n  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None\n  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)\n  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]\n  type ==>[A, B] = collection.Map[A, B]\n  val mod: Int = (1e9 + 7).toInt\n  val eps: Double = 1e-9\n}\n/***********************************[Scala I/O]*********************************************/\nimport Utils._, java.io._, java.util.StringTokenizer\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {\n  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n  val printer = new PrintWriter(out, true)\n\n  @inline private[this] def tokenizer() = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    when(tokenizers.nonEmpty)(tokenizers.head)\n  }\n\n  def read[A](implicit read: IO.Read[A]): A = read.apply(this)\n  def read[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(read).to[C]\n\n  def readTill(delim: String): String = tokenizer().get.nextToken(delim)\n  def readTillEndOfLine(): String = readTill(\"\\n\\r\")\n\n  def readAll[A: IO.Read]: (Int, Vector[A]) = {\n    val data = read[Vector[A]]\n    (data.length, data)\n  }\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n\n  def write(obj: Any): this.type = {\n    printer.print(obj)\n    this\n  }\n  def writeLine(): this.type = {\n    printer.println()\n    this\n  }\n  def writeLine(obj: Any): this.type = {\n    printer.println(obj)\n    this\n  }\n  def writeAll(obj: Traversable[Any], separator: String = \" \"): this.type = write(obj mkString separator)\n  def query[A: IO.Read](question: Any): A = writeLine(question).read\n\n  override def flush() = printer.flush()\n  def close() = {\n    flush()\n    in.close()\n    printer.close()\n  }\n}\nobject IO {\n  class Read[A](val apply: IO => A) {\n    def map[B](f: A => B): Read[B] = new Read(apply andThen f)\n  }\n  object Read {\n    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))\n    implicit val string                                       : Read[String]       = new Read(_.next())\n    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)\n    implicit val int                                          : Read[Int]          = string.map(_.toInt)\n    implicit val long                                         : Read[Long]         = string.map(_.toLong)\n    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))\n    implicit val double                                       : Read[Double]       = string.map(_.toDouble)\n    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))\n    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))\n    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]))\n    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]))\n    implicit val boolean                                      : Read[Boolean]      = string map {s =>\n      s.toLowerCase match {\n        case \"yes\" | \"true\" | \"1\" => true\n        case \"no\" | \"false\" | \"0\" => false\n        case _ => s.toBoolean\n      }\n    }\n  }\n}\n\n", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db"}
{"source_code": "import scala.io.StdIn\n\nobject Solution {\n\n  def solve(s: String): Int = {\n    var cnt = 0\n    var ans = 0\n    for (i <- s.length - 1 to 0 by -2) {\n      if (i != 0) {\n        ans += 1\n      } else {\n        ans += cnt\n      }\n      if (s.charAt(i) == '1' || i > 0 && s.charAt(i - 1) == '1') {\n        cnt = 1\n      }\n    }\n    ans\n  }\n\n  def main(args: Array[String]): Unit = {\n    val s = StdIn.readLine\n    print(solve(s))\n  }\n}", "src_uid": "d8ca1c83b431466eff6054d3b422ab47"}
{"source_code": "object C {\n\n  def main(args: Array[String]): Unit = {}\n \n  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n \n  val Array(la, ra, ta) = readLongs(3)\n  val Array(lb, rb, tb) = readLongs(3)\n \n  val lenA = ra - la + 1\n  val lenB = rb - lb + 1\n \n  def gcd(x: Long, y: Long): Long = if (y == 0) x else gcd(y, x % y)\n \n  val g = gcd(ta, tb)\n \n  if (g == 1) {\n    println(lenA min lenB)\n  } else if (ta == tb) {\n    println(((ra min rb) - (la max lb) + 1) max 0)\n  } else {\n \n    val x1 = if (la <= lb) {\n      val d = (lb - la) % g\n      Math.max(\n        Math.min(lenA - d, lenB),\n        Math.min(lenA, lenB - (g - d)))\n    } else {\n      val d = (la - lb) % g\n      Math.max(\n        Math.min(lenA, lenB - d),\n        Math.min(lenA - (g - d), lenB))\n    }\n \n    val x2 = if (ra <= rb) {\n      val d = (rb - ra) % g\n      Math.max(\n        Math.min(lenA - d, lenB),\n        Math.min(lenA, lenB - (g - d)))\n    } else {\n      val d = (ra - rb) % g\n      Math.max(\n        Math.min(lenA, lenB - d),\n        Math.min(lenA - (g - d), lenB))\n    }\n    //println(g, x1, x2)\n    val res = 0L max x1 //max x2\n \n    println(res)\n  }\n}", "src_uid": "faa75751c05c3ff919ddd148c6784910"}
{"source_code": "import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._\n\nobject _645A extends CodeForcesApp {\n  override def apply(io: IO) = {\n    val p1, p2 = (io[String] + io[String].reverse).replace(\"X\", \"\").toIndexedSeq\n    io += p1 isRotationOf p2\n  }\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n  lazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)\n  def apply(io: IO): io.type\n  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()\n}\nobject Utils {\n  import scala.collection.mutable, mutable.{Map => Dict}\n  implicit class GenericExtensions[A](val a: A) extends AnyVal {\n    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a\n  }\n  implicit class TraversableExtensions[A](val t: Traversable[A]) extends AnyVal {\n    def onlyElement: A = t.head.ensuring(t.size == 1)\n    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)\n    def duplicates: Traversable[A] = {\n      val elems = mutable.Set.empty[A]\n      t collect {case i if !elems.add(i) => i}\n    }\n    def zipWith[B](f: A => B): Traversable[(A, B)] = t map {i => i -> f(i)}\n    def mapTo[B](f: A => B): Map[A, B] = zipWith(f).toUniqueMap\n    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)\n    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}\n    def toMutableMultiSet: Dict[A, Int] = {\n      val c = map[A] to 0\n      t.foreach(i => c(i) += 1)\n      c\n    }\n    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap\n  }\n  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)\n  }\n  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)\n  }\n  implicit class IndexedSeqExtensions[A](val s: IndexedSeq[A]) extends AnyVal {\n    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t\n    def withOffset(offset: Int): IndexedSeq[A] = Iterator.fill(offset)(null.asInstanceOf[A]) ++: s\n  }\n  implicit class PairsExtensions[A, B](val t: Traversable[(A, B)]) extends AnyVal {\n    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_._1).mapValues(_._2)\n    def toMultiMap: Map[A, Traversable[B]] = t.groupBy(_._1).mapValues(_.map(_._2))\n    def swap: Traversable[(B, A)] = t.map(_.swap)\n  }\n  implicit class MapExtensions[K, V](val m: Map[K, V]) extends AnyVal {\n    def invert: Map[V, Set[K]] = m.swap.toMultiMap.mapValues(_.toSet)\n    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}\n  }\n  implicit class LongExtensions(val x: Long) extends AnyVal {\n    def bitCount: Int = java.lang.Long.bitCount(x)\n  }\n  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {\n    import Numeric.Implicits._\n    def ^^(i: Int): A = if (i == 0) n.one else {\n      val h = x ^^ (i/2)\n      if (i%2 == 0) h * h else h * h * x\n    }\n    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)\n    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students.indexOf(\"Greg\").whenNegative Int.MaxValue\n  }\n  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {\n    import scala.collection.immutable.NumericRange, Integral.Implicits._\n    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x\n    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(n.min(x, y), n.max(x, y), n.one)\n  }\n  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)\n  def  asc[A](implicit order: Ordering[A]): Ordering[A] = order\n  def map[K] = new {\n    def to[V](default: V): Dict[K, V] = Dict.empty[K, V] withDefaultValue default\n  }\n  def memoize[I] = new {\n    def apply[O](f: I => O): I => O = new mutable.HashMap[I, O]() {\n      override def apply(key: I) = getOrElseUpdate(key, f(key))\n    }\n  }\n  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None\n  def repeat(n: Int)(f: => Unit): Unit = (1 to n).foreach(_ => f)\n  val mod: Int = (1e9 + 7).toInt\n}\n/***********************************[Scala I/O]*********************************************/\nimport Utils._, java.io._, java.util.StringTokenizer, scala.collection.generic.CanBuild\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends PrintWriter(out, true) with Iterator[String] {\n  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n\n  @inline private[this] def tokenizer() = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    if (tokenizers.nonEmpty) Some(tokenizers.head) else None\n  }\n\n  def apply[A](implicit read: IO.Read[A]): A = read.apply(this)\n  def apply[C[_], A: IO.Read](n: Int)(implicit builder: CanBuild[A, C[A]]): C[A] = (builder() ++= Iterator.fill(n)(apply)).result()\n\n  def till(delim: String): String = tokenizer().get.nextToken(delim)\n  def tillEndOfLine(): String = till(\"\\n\\r\")\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n\n  var separator = \" \"\n  private[this] var isNewLine = true\n\n  def +=[A](x: A)(implicit write: IO.Write[A]): this.type = {\n    write(this)(x)\n    this\n  }\n  def appendNewLine(): this.type = {\n    println()\n    this\n  }\n\n  override def print(obj: Any) = {\n    if (isNewLine) isNewLine = false else super.print(separator)\n    super.print(obj)\n  }\n  override def println() = if (!isNewLine) {\n    super.println()\n    isNewLine = true\n  }\n  override def close() = {\n    flush()\n    in.close()\n    super.close()\n  }\n}\nobject IO {\n  class Read[A](val apply: IO => A) {\n    def map[B](f: A => B): Read[B] = new Read(apply andThen f)\n  }\n  object Read {\n    implicit def collection[C[_], A: Read](implicit b: CanBuild[A, C[A]]): Read[C[A]]            = new Read(r => r[C, A](r[Int]))\n    implicit val string                                                  : Read[String]          = new Read(_.next())\n    implicit val char                                                    : Read[Char]            = string.map(_.toTraversable.onlyElement)\n    implicit val boolean                                                 : Read[Boolean]         = string.map(_.toBoolean)\n    implicit val int                                                     : Read[Int]             = string.map(_.toInt)\n    implicit val long                                                    : Read[Long]            = string.map(_.toLong)\n    implicit val bigInt                                                  : Read[BigInt]          = string.map(BigInt(_))\n    implicit val double                                                  : Read[Double]          = string.map(_.toDouble)\n    implicit val bigDecimal                                              : Read[BigDecimal]      = string.map(BigDecimal(_))\n    implicit def tuple2[A: Read, B: Read]                                : Read[(A, B)]          = new Read(r => (r[A], r[B]))\n    implicit def tuple3[A: Read, B: Read, C: Read]                       : Read[(A, B, C)]       = new Read(r => (r[A], r[B], r[C]))\n    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]              : Read[(A, B, C, D)]    = new Read(r => (r[A], r[B], r[C], r[D]))\n    implicit def tuple5[A: Read, B: Read, C: Read, D: Read, E: Read]     : Read[(A, B, C, D, E)] = new Read(r => (r[A], r[B], r[C], r[D], r[E]))\n  }\n  class Write[-A] {\n    def apply(out: PrintWriter)(x: A): Unit = out.print(x)\n  }\n  trait DefaultWrite {\n    implicit def any[A]: Write[A] = new Write[A]\n  }\n  object Write extends DefaultWrite {\n    def apply[A](f: A => String) = new Write[A] {\n      override def apply(out: PrintWriter)(x: A) = out.print(f(x))\n    }\n    implicit val boolean: Write[Boolean] = Write(b => if (b) \"YES\" else \"NO\")\n    implicit def iterable[A](implicit write: Write[A]): Write[Traversable[A]] = new Write[Traversable[A]] {\n      override def apply(out: PrintWriter)(xs: Traversable[A]) = {\n        xs foreach write(out)\n        out.println()\n      }\n    }\n  }\n}\n\n", "src_uid": "46f051f58d626587a5ec449c27407771"}
{"source_code": "object Main\n{\n\tdef cmp (s1 : Array[Char], s2 : Array[Char]) : Boolean =\n\t{\n\t\tfor (i <- 0 until s1.size)\n\t\t\tif (s1(i) != s2(i)) return false\n\t\treturn true\n\t}\n\n\tdef add (s : String, a : Char) : String =\n\t{\n\t\tvar s2 = new Array[Char](s.size+2)\n\t\tfor (i <- 0 until s.size)\n\t\t\ts2(i) = s(i)\n\t\ts2(s.size) = a\n\n\t\tprintln(\"\")\n\t\tprint (\"Ja izgradi nizata: \")\n\t\tfor (i <- 0 until s2.size)\n\t\t\tprint(s2(i))\n\t\tprintln(\"\")\n\n\t\ts2.toString\n\t}\n\n\tdef main (args : Array[String]) =\n\t{\n\t\tvar str = scala.io.StdIn.readLine.toArray\n\n\t\tvar arr = new Array[Array[Char]](12)\n\t\tfor (i <- 0 to 9)\n\t\t{\n\t\t\tvar s = scala.io.StdIn.readLine.toArray\n\t\t\tarr(i) = s\n\t\t}\n\n\t\tvar i = 0\n\t\twhile (i <= 70)\n\t\t{\n\t\t\t//println(\"vleguva tuka za i = \" + i)\n\t\t\tvar str2 = new Array[Char](12)\n\t\t\tfor (j <- i until i+10)\n\t\t\t\tstr2(j-i) = str(j)\n\n\t\t\t//for (j <- 0 until str2.size)\n\t\t\t\t//print(str2(j))\n\t\t\t//println(\"\")\n\n\t\t\tvar which = -1\n\t\t\tfor (j <- 0 to 9)\n\t\t\t\tif (cmp(arr(j), str2))\n\t\t\t\t{\n\t\t\t\t\twhich = j\n\t\t\t\t}\n\t\t\tprint(which)\n\t\t\ti += 10\n\t\t}\n\t}\n}", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9"}
{"source_code": "object Solution extends App {\n  val in = scala.io.Source.stdin.getLines()\n  var Array(m, s) = in.next().split(\" \").map(_.toInt)\n  if (s == 0 && m == 1)\n    println(\"0 0\")\n  else if (9 * m < s || s == 0)\n    println(\"-1 -1\")\n  else {\n    val i = s / 9\n    val left = s % 9\n    val answer = Array.ofDim[Int](m)\n    Range(0, i).foreach { j => answer(j) = 9}\n    if (left > 0)\n      answer(i) = left\n    val answer2 = answer.reverse\n    if (answer2(0) == 0) {\n      answer2(0) = 1\n      var j = 1\n      while (j < answer2.length && answer2(j) == 0) j += 1\n      answer2(j) = answer2(j) - 1\n    }\n    println(answer2.mkString + \" \" + answer.mkString)\n\n\n  }\n\n}", "src_uid": "75d062cece5a2402920d6706c655cad7"}
{"source_code": "object Solution extends CodeForcesApp {\n\timport Utils._, annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._, Math._\n\n\toverride def apply(io: IO): io.type = {\n\t\tvar n = io.read[Int]\n\t\tvar t = io.read[Int]\n\t\tvar k = io.read[Int]\n\t\tvar d = io.read[Int]\n\t\tn = (n + k - 1) / k\n\t\tio.writeLine(if(d + t < t * n) {\"YES\"} else {\"NO\"})\n\t}\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n\tlazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n\tdef debug(x: => Any): Unit = if (!isOnlineJudge) println(x)\n\tdef apply(io: IO): io.type\n\tdef main(args: Array[String]): Unit = apply(new IO(System.in, System.out)).close()\n}\n/****************************[Scala Collection Utils]****************************************/\nobject Utils {\n\timport scala.collection.mutable\n\n\ttype of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]\n\n\tdef when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None\n\n\tdef repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)\n\n\timplicit class GenericExtensions[A](a: A) {\n\t\tdef partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a\n\t}\n\n\timplicit class TraversableExtensions[A, C[X] <: Traversable[X]](t: C[A]) {\n\t\tdef zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]\n\n\t\tdef whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)\n\n\t\tdef toMultiSet: Map[A, Int] = t.groupBy(identity).mapValues(_.size)\n\t}\n\n\timplicit class PairExtensions[A, B](p: (A, B)) {\n\t\tdef key = p._1\n\t\tdef value = p._2\n\t\tdef toSeq(implicit ev: B =:= A): Seq[A] = Seq(p.key, ev(p.value))\n\t}\n\n\timplicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {\n\t\tdef toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C]).withDefaultValue(b().result())\n\t}\n\n\timplicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](m: C[K, V]) {\n\t\tdef toMutable: mutable.Map[K, V] = mutable.Map.empty[K, V] ++ m\n\t}\n\n\timplicit class SetExtensions[A, C[A] <: Set[A]](s: C[A]) {\n\t\tdef notContains(x: A): Boolean = !(s contains x)\n\t\tdef toMutable = mutable.Set.empty[A] ++ s\n\t}\n\n\timplicit class IterableExtensions[A, C[A] <: Seq[A]](s: C[A]) {\n\t\tdef indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}\n\t\tdef deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)\n\t\tdef insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)\n\t\tdef findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}\n\t}\n\n\timplicit class BooleanExtensions(x: Boolean) {\n\t\tdef to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero\n\t\tdef toEnglish = if(x) \"Yes\" else \"No\"\n\t}\n\n\tdef desc[A](implicit order: Ordering[A]): Ordering[A] = order.reverse  //e.g. students.sortBy(_.height)(desc)\n\n\tdef map[K] = new {\n\t\tdef to[V](default: => V): mutable.Map[K, V] = using(_ => default)\n\t\tdef using[V](f: K => V): mutable.Map[K, V] = new mutable.HashMap[K, V]() {\n\t\t\toverride def apply(key: K) = getOrElseUpdate(key, f(key))\n\t\t}\n\t}\n\n\tdef newMultiMap[K, V] = map[K] to mutable.Set.empty[V]\n\n\tdef memoize[A, B](f: A => B): A => B = map[A] using f\n}\n/***********************************[Scala I/O]*********************************************/\nimport java.io._, java.util.StringTokenizer\nimport scala.collection.generic.CanBuild\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {\n\tdef this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n\tdef this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n\tprivate[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n\tval printer = new PrintWriter(out, true)\n\n\t@inline private[this] def tokenizer() = {\n\t\twhile(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n\t\ttokenizers.headOption\n\t}\n\n\tdef read[A](implicit read: IO.Read[A]): A = read.apply(this)\n\tdef read[C[_], A: IO.Read](n: Int)(implicit b: CanBuild[A, C[A]]): C[A] = Iterator.fill(n)(read).to[C]\n\n\tdef readTill(delim: String): String = tokenizer().get.nextToken(delim)\n\tdef readTillEndOfLine(): String = readTill(\"\\n\\r\")\n\n\tdef readAll[A: IO.Read]: (Int, Vector[A]) = {\n\t\tval data = read[Vector[A]]\n\t\t(data.length, data)\n\t}\n\n\toverride def next() = tokenizer().get.nextToken()\n\toverride def hasNext = tokenizer().nonEmpty\n\n\tdef write(obj: Any): this.type = {\n\t\tprinter.print(obj)\n\t\tthis\n\t}\n\tdef writeLine(): this.type = {\n\t\tprinter.println()\n\t\tthis\n\t}\n\tdef writeLine(obj: Any): this.type = {\n\t\tprinter.println(obj)\n\t\tthis\n\t}\n\tdef writeLines(obj: Traversable[Any]): this.type = writeAll(obj, separator = \"\\n\")\n\tdef writeAll(obj: Traversable[Any], separator: String = \" \"): this.type = write(obj mkString separator)\n\tdef query[A: IO.Read](question: Any): A = writeLine(question).read\n\n\toverride def flush() = printer.flush()\n\tdef close() = {\n\t\tflush()\n\t\tin.close()\n\t\tprinter.close()\n\t}\n}\nobject IO {\n\tclass Read[A](val apply: IO => A) {\n\t\tdef map[B](f: A => B): Read[B] = new Read(apply andThen f)\n\t}\n\n\tobject Read {\n\t\timplicit def collection[C[_], A: Read](implicit b: CanBuild[A, C[A]]) : Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))\n\t\timplicit val string                                                   : Read[String]       = new Read(_.next())\n\t\timplicit val int                                                      : Read[Int]          = string.map(_.toInt)\n\t\timplicit val long                                                     : Read[Long]         = string.map(_.toLong)\n\t\timplicit val bigInt                                                   : Read[BigInt]       = string.map(BigInt(_))\n\t\timplicit val double                                                   : Read[Double]       = string.map(_.toDouble)\n\t\timplicit val bigDecimal                                               : Read[BigDecimal]   = string.map(BigDecimal(_))\n\t\timplicit def tuple2[A: Read, B: Read]                                 : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))\n\t\timplicit def tuple3[A: Read, B: Read, C: Read]                        : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))\n\t\timplicit 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]))\n\t\timplicit val boolean                                                  : Read[Boolean]      = string map {s =>\n\t\t\ts.toLowerCase match {\n\t\t\t\tcase \"yes\" | \"true\" | \"1\" => true\n\t\t\t\tcase \"no\" | \"false\" | \"0\" => false\n\t\t\t\tcase _ => s.toBoolean\n\t\t\t}\n\t\t}\n\t}\n}\n", "src_uid": "32c866d3d394e269724b4930df5e4407"}
{"source_code": "//package codeforces.contests._1433\n\nobject BoringApartments {\n  def main(args: Array[String]): Unit = {\n    for (_ <- 1 to io.StdIn.readInt()) {\n      val n = io.StdIn.readInt()\n\n      val digit = n % 10\n      val size = n.toString.length\n\n      println {\n        ((digit - 1) max 0) * 10 + (1 to size).sum\n      }\n    }\n  }\n}\n", "src_uid": "289a55128be89bb86a002d218d31b57f"}
{"source_code": "object Main extends App {\n  var Array(n, m) = readLine.split(\" \").map(_.toInt)\n\n  def getResult(n: Int, m: Int) = {\n    if (m == 0)\n      1\n    else if (m <= (n / 2)) {\n      m\n    } else {\n      n - m\n    }\n  }\n\n  println(getResult(n, m))\n}", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648"}
{"source_code": "object Main {\n  def main(args: Array[String]) {\n    val Array(a, b) = readLine().split(\" \").map(_.toInt)\n    val r = Array(0, 0, 0)\n    for(i <- 1 to 6) {\n      if ((a - i).abs < (b - i).abs) r(0) += 1\n      else if ((a - i).abs == (b - i).abs) r(1) += 1\n      else r(2) += 1\n    }\n    println(r.mkString(\" \"))\n  }\n}", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8"}
{"source_code": "import scala.io.StdIn;\n\nobject TaskB extends App {\n\n  def sumNumb(numb: Long) :Long = { // \u0441\u0443\u043c\u043c\u0430 \u0446\u0438\u0444\u0440 \u0432 \u0447\u0438\u0441\u043b\u0435\n    if(numb == 0) 0\n    else numb % 10 + sumNumb(numb / 10)\n  }\n\n  def digitInNumber(numb: Long): Long = { // \u043a\u043e\u043b-\u0432\u043e \u0446\u0438\u0444\u0440 \u0432 \u0447\u0438\u0441\u043b\u0435\n    if(numb == 0) 0\n    else digitInNumber(numb / 10) + 1\n  }\n\n  def generateNumberFromDigit(digit: Long, amt_digit: Long):Long = { // \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u0438\u0437 \u0446\u0438\u0444\u0440 digit, \u0434\u043b\u0438\u043d\u043d\u043e\u0439 amt_digit\n    if(amt_digit == 0) 0\n    else generateNumberFromDigit(digit, amt_digit - 1) * 10 + digit\n  }\n\n  def generateNumberFrom9 = generateNumberFromDigit(9, _:Long)\n\n  val numb = StdIn.readLong()\n  val delta = generateNumberFrom9(digitInNumber(numb) - 1)\n\n  println(sumNumb(delta) + sumNumb(numb - delta))\n}", "src_uid": "5c61b4a4728070b9de49d72831cd2329"}
{"source_code": "object A extends App {\n  val n = scala.io.StdIn.readLine().toInt\n  val a = scala.io.StdIn.readLine().toInt\n  val b = scala.io.StdIn.readLine().toInt\n  val c = scala.io.StdIn.readLine().toInt\n\n  val d = a min b\n  val e = d min c\n  if (n == 1) println(0)\n  else if (n == 2) println(d)\n  else println(d + (n - 2) * e)\n}", "src_uid": "6058529f0144c853e9e17ed7c661fc50"}
{"source_code": "object A extends App {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }\n\n  val Array(l, r) = readInts(2)\n\n  var res = l\n  var max = 1\n\n  var x = 2\n  while (x * x <= r) {\n    val cnt = r / x - l / x + (if (l % x == 0) 1 else 0)\n    if (cnt > max) {\n      max = cnt\n      res = x\n    }\n    x += 1\n  }\n\n  println(res)\n}\n", "src_uid": "a8d992ab26a528f0be327c93fb499c15"}
{"source_code": "object P1A {\n  def main(args : Array[String]) {\n    val a = readInt;\n    val b = readInt;\n    val c: Long = readInt;\n    System.out.println((((a - 1) / c) + 1) * (((b - 1) / c) + 1));\n  }\n\n  ///********************************************************************\n  ///                    for read integers\n  ///\n  def readInt : Int = {\n    var result = 0\n    var read = 0\n    var sign = false\n\n    do {\n      read = System.in.read()\n    } while (read != -1 && (read != '-' && read < '0' || read > '9'))\n\n    if (read == -1) return Integer.MIN_VALUE;\n    if (read == '-') { sign = true; read = System.in.read() }\n\n    do {\n      result = (result << 3) + (result << 1) + read - '0';\n      read = System.in.read();\n    } while (read != -1 && read >= '0' && read <= '9');\n    if (read == 13) System.in.read(); // skip 10\n\n    if (sign) -result else result\n  }\n}", "src_uid": "ef971874d8c4da37581336284b688517"}
{"source_code": "import scala.io.StdIn\n\nobject p1 {\n  def main(args: Array[String]): Unit = {\n    val in = StdIn.readLine()\n\n    val res = if (in.contains(\"ABC\") || in.contains(\"ACB\") || in.contains(\"BAC\") || in.contains(\"BCA\") || in.contains(\"CAB\") || in.contains(\"CBA\")) \"Yes\" else \"No\"\n\n    println(res)\n  }\n}", "src_uid": "ba6ff507384570152118e2ab322dd11f"}
{"source_code": "object Main {\n  import java.io._\n  import java.util.StringTokenizer\n\n  import scala.collection.mutable\n  import scala.util.Sorting\n  import math.{abs, max, min}\n  import mutable.{ArrayBuffer, ListBuffer}\n  import scala.reflect.ClassTag\n\n  val MOD = 1000000007\n  val out = new PrintWriter(System.out)\n\n  def solve(): Unit = {\n    val N, W, B = ni()\n    val A = na(N)\n    var ok = true\n    var ans = 0\n\n    rep(N / 2) { i =>\n      val j = N - 1 - i\n      if (A(i) == A(j)) {\n        if (A(i) == 2) {\n          ans += min(W, B) * 2\n        }\n      } else if (Set(A(i), A(j)) == Set(0, 1)){\n        ok = false\n      } else {\n        val a = (Set(A(i), A(j)) - 2).head\n        if (a == 0) ans += W\n        else ans += B\n      }\n    }\n    if (N % 2 == 1) {\n      if (A(N / 2) == 2) ans += min(B, W)\n    }\n\n    if (!ok) ans = -1\n    out.println(ans)\n  }\n\n  def main(args: Array[String]): Unit = {\n    solve()\n    out.flush()\n  }\n\n\n  class InputReader(val stream: InputStream) {\n    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n    private var tokenizer: StringTokenizer = _\n\n    def next(): String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new StringTokenizer(reader.readLine)\n      tokenizer.nextToken\n    }\n\n    def nextInt(): Int = next().toInt\n    def nextLong(): Long = next().toLong\n    def nextChar(): Char = next().charAt(0)\n  }\n  val sc = new InputReader(System.in)\n  def ni(): Int = sc.nextInt()\n  def nl(): Long = sc.nextLong()\n  def nc(): Char = sc.nextChar()\n  def ns(): String = sc.next()\n  def ns(n: Int): Array[Char] = ns().toCharArray\n  def na(n: Int): Array[Int] = map(n)(_ => ni())\n  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))\n  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = offset\n    val N = n + offset\n    while(i < N) { f(i); i += 1 }\n  }\n  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = n - 1 + offset\n    while(i >= offset) { f(i); i -= 1 }\n  }\n\n  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {\n    val res = Array.ofDim[A](n)\n    rep(n)(i => res(i) = f(i))\n    res\n  }\n}", "src_uid": "af07223819aeb5bd6ded4340c472b2b6"}
{"source_code": "object Main\n{\n  def main(args : Array[String])\n  {\n    val Array(w,h) = readLine split \" \" map (_.toInt)\n    var c : BigInt = 0\n    for(x <- 0 to w/2; y <- 0 to h/2)\n    {\n      val xx = (w-x) min x\n      val yy = (h-y) min y\n      var mn = 4\n      val mx = x == w/2 && w%2==0\n      val my = y == h/2 && h%2==0\n      if (mx && my)\n\tmn = 1\n      else if (mx || my)\n\tmn = 2\n      c += mn*xx*yy\n    }\n    println(c)\n  }\n}\n", "src_uid": "42454dcf7d073bf12030367eb094eb8c"}
{"source_code": "object Main {\n  def main(args: Array[String]): Unit = {\n    val s = new Main()\n    s.solve()\n    s.out.flush()\n  }\n}\n\nclass Main {\n  import java.io._\n  import java.util.StringTokenizer\n\n  import scala.collection.mutable\n  import scala.util.Sorting\n  import math.{abs, max, min}\n  import mutable.{ArrayBuffer, ListBuffer}\n  import scala.reflect.ClassTag\n\n  val MOD = 1000000007\n  val out = new PrintWriter(System.out)\n\n  def solve(): Unit = {\n    val N, K = nl()\n    val l = max(1, K - N)\n    val r = min(K - 1, N)\n    val len = r - l + 1\n    val ans =\n      if (2 * N - 1 < K) 0\n      else if (len % 2 == 0) {\n        len / 2\n      } else {\n        len / 2\n      }\n\n    out.println(ans)\n  }\n\n\n  class InputReader(val stream: InputStream) {\n    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n    private var tokenizer: StringTokenizer = _\n\n    def next(): String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new StringTokenizer(reader.readLine)\n      tokenizer.nextToken\n    }\n\n    def nextInt(): Int = next().toInt\n    def nextLong(): Long = next().toLong\n    def nextChar(): Char = next().charAt(0)\n  }\n  val sc = new InputReader(System.in)\n  def ni(): Int = sc.nextInt()\n  def nl(): Long = sc.nextLong()\n  def nc(): Char = sc.nextChar()\n  def ns(): String = sc.next()\n  def ns(n: Int): Array[Char] = ns().toCharArray\n  def na(n: Int): Array[Int] = map(n)(_ => ni())\n  def nal(n: Int): Array[Long] = map(n)(_ => nl())\n  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))\n  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = offset\n    val N = n + offset\n    while(i < N) { f(i); i += 1 }\n  }\n  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = n - 1 + offset\n    while(i >= offset) { f(i); i -= 1 }\n  }\n\n  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {\n    val res = Array.ofDim[A](n)\n    rep(n)(i => res(i) = f(i))\n    res\n  }\n\n  def sumL(as: Array[Int]): Long = {\n    var s = 0L\n    rep(as.length)(i => s += as(i))\n    s\n  }\n}", "src_uid": "98624ab2fcd2a50a75788a29e04999ad"}
{"source_code": "object Main {\n  def main(args: Array[String]): Unit = {\n    val s = new Main()\n    s.solve()\n    s.out.flush()\n  }\n}\n\nclass Main {\n  import java.io._\n  import java.util.StringTokenizer\n\n  import scala.collection.mutable\n  import scala.util.Sorting\n  import math.{abs, max, min}\n  import mutable.{ArrayBuffer, ListBuffer}\n  import scala.reflect.ClassTag\n\n  val MOD = 1000000007\n  val out = new PrintWriter(System.out)\n\n  def solve(): Unit = {\n    val N = ni()\n    val even = N.toLong * (N + 1) / 2 % 2 == 0\n    if (even) out.println(0)\n    else out.println(1)\n  }\n\n\n  def debug(as: Array[Boolean]): Unit = {\n    System.err.println(as.map(x => if(x) \"1\" else \"0\").mkString)\n  }\n\n  def debug(as: Array[Int]): Unit = {\n    System.err.println(as.mkString(\" \"))\n  }\n\n  def debug(as: Array[Long]): Unit = {\n    System.err.println(as.mkString(\" \"))\n  }\n\n  def debug(s: String): Unit = {\n    System.err.println(s)\n  }\n\n  class InputReader(val stream: InputStream) {\n    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n    private var tokenizer: StringTokenizer = _\n\n    def next(): String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new StringTokenizer(reader.readLine)\n      tokenizer.nextToken\n    }\n\n    def nextInt(): Int = next().toInt\n    def nextLong(): Long = next().toLong\n    def nextChar(): Char = next().charAt(0)\n  }\n  val sc = new InputReader(System.in)\n  def ni(): Int = sc.nextInt()\n  def nl(): Long = sc.nextLong()\n  def nc(): Char = sc.nextChar()\n  def ns(): String = sc.next()\n  def ns(n: Int): Array[Char] = ns().toCharArray\n  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)\n  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {\n    val A1, A2 = Array.ofDim[Int](n)\n    REP(n) { i =>\n      A1(i) = ni() + offset\n      A2(i) = ni() + offset\n    }\n    (A1, A2)\n  }\n  def nm(n: Int, m: Int): Array[Array[Int]] = {\n    val A = Array.ofDim[Int](n, m)\n    REP(n) { i =>\n      REP(m) { j =>\n        A(i)(j) = ni()\n      }\n    }\n    A\n  }\n  def nal(n: Int): Array[Long] = map(n)(_ => nl())\n  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))\n  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = offset\n    val N = n + offset\n    while(i < N) { f(i); i += 1 }\n  }\n  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = n - 1 + offset\n    while(i >= offset) { f(i); i -= 1 }\n  }\n\n  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {\n    val res = Array.ofDim[A](n)\n    REP(n)(i => res(i) = f(i + offset))\n    res\n  }\n\n\n  def sumL(as: Array[Int]): Long = {\n    var s = 0L\n    REP(as.length)(i => s += as(i))\n    s\n  }\n\n  def cumSum(as: Array[Int]) = {\n    val cum = Array.ofDim[Long](as.length + 1)\n    REP(as.length) { i =>\n      cum(i + 1) = cum(i) + as(i)\n    }\n    cum\n  }\n}", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9"}
{"source_code": "import java.util._\n\nobject Main{\n  def main(args: Array[String]) {\n    val sc = new Scanner(System.in);\n    val n = sc.nextInt();\n    val x = sc.nextInt();\n    val a = for (i <- 0 until n) yield sc.nextInt();\n\n    val ret = 0.until(x).map(i => if (a.contains(i)) 0 else 1).sum + (if (a.contains(x)) 1 else 0)\n\n    println(ret);\n  }\n}", "src_uid": "21f579ba807face432a7664091581cd8"}
{"source_code": "import java.util.Scanner\n\nobject R273_InitialBet {\n  def main(args:Array[String]) = {\n    val in = new Scanner(System.in).nextLine().split(\" \").map(_.toInt)\n    if (in.sum % in.length == 0 && in.sum != 0) {\n      println(in.sum / in.length)\n    }\n    else{\n      println(-1)\n    }\n  }\n}\n", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20"}
{"source_code": "object c402A {\n    def main(args: Array[String]) {\n        val l = Console.readLine().split(\" \").map(i => Integer.parseInt(i))\n        val max_sections = l(0)\n        var nuts = l(1)\n        var divisors = l(2)\n        val section_capacity = l(3)\n        var nsections = (nuts-1)/section_capacity + 1\n\n        //Complete boxes\n        //println(\"nsections:\" + nsections)\n        val complete_boxes = divisors/max_sections\n        //println(\"complete_boxes:\" + complete_boxes)\n        var boxes = 0\n        if (complete_boxes > 0) {\n            boxes += math.min(nsections/max_sections, complete_boxes)\n            divisors -= boxes*(max_sections - 1)\n            nsections -= boxes*max_sections\n        }\n        //println(\"nsections 2:\" + nsections)\n        //Partial box\n        if (nsections > 0 && divisors > 0) {\n            boxes += 1\n            nsections -= divisors + 1\n        }\n        //println(\"nsections 3:\" + nsections)\n        if (nsections > 0) boxes += nsections\n        println(boxes)\n    }\n}", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652"}
{"source_code": "import java.util.Scanner\n\nobject Main {\n\n   def main(args: Array[String]): Unit = {\n       val scanner = new Scanner (System.in)\n\t\t val a, b, c = scanner.nextInt()\n\t\t val ans = (a * c + b - 1) / b - c\n\t\t println (ans)\n   }\n\n}\n", "src_uid": "7dd098ec3ad5b29ad681787173eba341"}
{"source_code": "object Main extends App {\n  val in = readLine.toInt\n  println(Range(1, 17).find(t => (in + t).toString.contains('8')).get)\n}", "src_uid": "4e57740be015963c190e0bfe1ab74cb9"}
{"source_code": "object Solution extends App {\n  val in = scala.io.Source.stdin.getLines()\n  val n = in.next().toInt\n  val data = in.next().split(\" \").map(_.toInt)\n  val sum = data.sum\n  var left = if (n % sum == 0) n - sum * (n / sum - 1) else n % sum\n  println(data.indices.find { i =>\n    left -= data(i)\n    left <= 0\n  }.get + 1)\n}", "src_uid": "007a779d966e2e9219789d6d9da7002c"}
{"source_code": "import scala.io.StdIn\n\n\n\nobject Main {\n  def abs(x: BigInt): BigInt = {\n    if(x >= 0) x\n    else -x\n  }\n\n  def getStepsCount(x: BigInt, y: BigInt, destX: BigInt, destY: BigInt): BigInt = {\n    abs(destX - x) >= abs(destY - y) match {\n      case true => abs(destX - x)\n      case false => abs(destY - y)\n    }\n  }\n\n  def main(args: Array[String]): Unit = {\n    val n = BigInt(StdIn.readLine())\n    val input = StdIn.readLine().split(\" \").map(BigInt(_))\n    val (destX, destY) = (input(0), input(1))\n    if(getStepsCount(1, 1, destX, destY) <= getStepsCount(n, n, destX, destY)) println(\"White\")\n    else println(\"Black\")\n  }\n}", "src_uid": "b8ece086b35a36ca873e2edecc674557"}
{"source_code": "\nobject CF_522_2_A {\n  def solve(n: Int, k: Int, as: Seq[Int]): Int = {\n    val counts = as.groupBy(identity).mapValues(_.size)\n    val maxCount = counts.values.max\n    val numSetsEach = Utility.intCeil(maxCount, k)\n    val numUtensilsInSet = counts.size\n    val totalUtensils = k * numSetsEach * numUtensilsInSet\n    val numStolen = totalUtensils - n\n    numStolen\n  }\n  \n\n  def solution(i: Input) = solve(i.int, i.int, {i.nextLine; i.intSeq()})\n\n//     ~~~ Boilerplate ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n  val out = new java.io.PrintWriter(System.out)\n  def main(args: Array[String]) = {\n    val sol = solution(new Input(System.in))\n    out.println(sol)\n    out.close()\n  }\n\n//     ~~~ Utility methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n  import java.util.Scanner\n  class Input(sc: Scanner) {\n    def this(i: java.io.InputStream) = this(new Scanner(i))\n    def this(s: String) = this(new Scanner(s))\n    def nextLine = sc.nextLine() // do this if still on previous line before collecting line of data\n    def collect[T](f: String => T) = {sc.nextLine().split(\" \").toVector.map(f)}\n    def intSeq() = collect(_.toInt)\n    def doubleSeq() = collect(_.toDouble)\n    def int() = sc.nextInt()\n    def long() = sc.nextLong()\n    def double() = sc.nextDouble()\n  }\n\n  object Utility {\n    def intCeil(a: Int, b: Int) = (a - 1) / b + 1\n    def longCeil(a: Long, b: Long) = (a - 1) / b + 1\n  }\n}", "src_uid": "c03ff0bc6a8c4ce5372194e8ea18527f"}
{"source_code": "import scala.io.Source\n\nobject Hello extends App {\n\n  val v = Source.stdin.getLines().next().toLong\n\n  val result = if (v == 0)\n    1 else\n    v % 4 match {\n      case 1 => 8\n      case 2 => 4\n      case 3 => 2\n      case _ => 6\n    }\n  print(result)\n}\n", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f"}
{"source_code": "object Main {\n    def main(args: Array[String]): Unit = {\n        val n = readInt\n        val (l, r) = readLine.toList.take(n).foldLeft((0, 0)){\n            case ((l, r), 'L') => (l - 1, r)\n            case ((l, r), 'R') => (l, r + 1)\n        }\n        println(r - l + 1)\n    }\n}", "src_uid": "098ade88ed90664da279fe8a5a54b5ba"}
{"source_code": "import scala.collection.mutable.ArrayBuffer\nimport scala.io.StdIn._\nimport scala.util.Sorting._\nimport scala.math._\nimport scala.collection._\nimport java.util._\n\nobject HelloWorld {\n\n  def main(args: Array[String]) {\n\n    val n: BigInt = BigInt(readLine.trim)\n    print(if(n % 2 != 0) \"-\" else \"\")\n\n    val even = (n/2)*((n/2)+1)\n    val odd = n*(n+1)/2 - even\n    val ans = odd - even\n\n    println(ans.abs)\n  }\n}", "src_uid": "689e7876048ee4eb7479e838c981f068"}
{"source_code": "import java.util.Scanner\nobject Cifera {\n\n  val scanner = new Scanner(System.in)\n  val a = scanner.nextInt()\n  var b = scanner.nextInt();\n  \n  def main(args: Array[String]) {\n    var i = 0\n    while (b%a == 0) {\n        b /= a\n        i +=1\n    }\n    println(if (b==1) \"YES\" else \"NO\" )\n    if (b==1){\n      println(i-1)\n    }\n  }\n}", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46"}
{"source_code": "object RepeatingCipher1095A//  extends TSolver {\n                     extends App {\n    import java.io.{InputStream, PrintStream}\n    import java.util.Scanner\n    solve(System.in,System.out)\n    def solve(in: InputStream, out: PrintStream): Unit = {\n        val scanner = new Scanner(in)\n      val szT = scanner.nextInt\n      val t = scanner.next\n      val n: Int = Math.floor(Math.sqrt(szT*2.0)).toInt\n\n      val result = (1 to n).map{ i =>\n        //position of the i th element?\n        val pos = (i*(i+1))/2 - 1\n\n        t(pos).toString\n      }.mkString\n      out.println(result)\n    }\n}", "src_uid": "08e8c0c37b223f6aae01d5609facdeaf"}
{"source_code": "object A extends App {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }\n\n  val n = readLine\n  val s = readLine\n\n  val res = new StringBuilder\n  var prev = 'x'\n  val isWovel = Set('a', 'e', 'i', 'o', 'u', 'y')\n\n  for (c <- s) {\n    if (!isWovel(prev) || !isWovel(c)) res += c\n    prev = c\n  }\n\n  println(res.result())\n\n  Console.flush\n}\n", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690"}
{"source_code": "import java.util.StringTokenizer\n\nobject _513B extends App {\n  var token = new StringTokenizer(\"\")\n  def next = {\n    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)\n    token.nextToken()\n  }\n\n  def calc(cand: Vector[Int], m: Long): Vector[Int] =\n    if (cand.size == 1) cand\n    else {\n      val half = 1L << (cand.size - 2)\n      if (m <= half) cand.head +: calc(cand.tail, m)\n      else calc(cand.tail, m - half) :+ cand.head\n    }\n  val n = next.toInt\n  val m = next.toLong\n  println(calc((1 to n).toVector, m).mkString(\" \"))\n}\n", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2"}
{"source_code": "object Main {\n  def solution_exists(a: Int, b: Int, c: Int, d: Int): Boolean = {\n    def gcd(a: Int, b: Int): Int = {\n      if (b > 0) gcd(b, a % b)\n      else a\n    }\n    val x = b % a\n    val y = d % c\n    val g = gcd(a, c)\n    (x - y) % g == 0\n  }\n  def main(args: Array[String]) {\n    var Array(a, b): Array[Int] = Console.in.readLine().split(\" \").map(_.toInt)\n    var Array(c, d): Array[Int] = Console.in.readLine().split(\" \").map(_.toInt)\n    if (solution_exists(a, b, c, d)) {\n      var q = b\n      while (q < d)\n        q += a\n      var t = d\n      while (t < b)\n        t += c\n      var delta = c\n      if (q > t) {\n        t = q\n        delta = a\n      }\n      while ((t - d) % c != 0 || (t - b) % a != 0)\n        t += delta\n      println(t)\n    }\n    else\n      println(-1)\n  }\n}", "src_uid": "158cb12d45f4ee3368b94b2b622693e7"}
{"source_code": "import scala.io.Source\n\nobject a10 {\n  def main(args: Array[String]): Unit = {\n    val lines = Source.stdin.getLines().map(_.split(' ').map(_.toInt))toArray\n    val k = lines(0)(1)\n    val a = lines(1).sortWith((a,b)=>b<a).find(k % _ == 0).get\n    println(k/a)\n  }\n\n}\n", "src_uid": "80520be9916045aca3a7de7bc925af1f"}
{"source_code": "object Main {\n  def main(args: Array[String]) = {\n    val n = readInt()\n    val a = readLine().split(\" \").map(_.toInt)\n    val xy = readLine().split(\" \").map(_.toInt)\n    val x = xy(0)\n    val y = xy(1)\n    \n    val sc = a.scanLeft(0)(_ + _)\n    val f = sc.zipWithIndex.filter(_._1 >= x).filter(_._1 <= y)\n    val sum = sc.last\n    f.find(t => sum - t._1 >= x && sum - t._1 <= y) match {\n      case None => println(\"0\")\n      case Some(t) => println(t._2 + 1)\n    }\n  }\n}", "src_uid": "e595a1d0c0e4bbcc99454d3148b4557b"}
{"source_code": "import io.StdIn._\n\nimport scala.collection.mutable._\n\nobject Solution {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }\n\n\n  def main(args: Array[String]) {\n    val Array(n, m) = readInts(2)\n\n    var l = 2\n    var r = Int.MaxValue\n\n    while (l <= r) {\n      val mid = (l + r) / 2\n      val a = mid / 2\n      val b = mid / 3\n      val x = mid / 6\n\n      if (n <= a && m <= b && n + m <= a + b - x) r = mid - 1\n      else l = mid + 1\n    }\n\n    println(l)\n\n\n\n//    Console.withOut(new java.io.BufferedOutputStream(Console.out))\n//    println(res.mkString(\"\\n\"))\n//    Console.flush\n  }\n}", "src_uid": "23f2c8cac07403899199abdcfd947a5a"}
{"source_code": "import scala.io.StdIn\nobject Main extends App {\n\n  class Board(val data: Seq[String], lastMove: (Int, Int)) {\n\n    val X: Char = 'x'\n    val O: Char  = 'o'\n    val Empty : Char = '.'\n    val Available : Char  = '!'\n    val Valid = Set(X, O, Empty)\n\n    lazy val availableMoves: String = {\n      val newBoard = if (subgame.map(tiles(_)).contains(Empty)) {\n        tiles.zipWithIndex.map(t => {\n          if (subgame.contains(t._2) && t._1 == Empty) Available\n          else t._1\n        })\n      } else {\n        tiles.map(t => if (t == Empty) Available else t)\n      }\n      newBoard.grouped(9).map(a => a.grouped(3).map(String.valueOf).mkString(\" \")).grouped(3).map(_.mkString(\"\\n\")).mkString(\"\\n\\n\")\n    }\n\n    lazy val tiles: Array[Char] = data.map(_.toCharArray.filter(Valid.contains)).filter(!_.isEmpty).flatten.toArray\n\n    lazy val subgame: Set[Int] = {\n      val gY = (lastMove._1 - 1) / 3\n      val gX = (lastMove._2 - 1) / 3\n      val pY = (lastMove._1 - 1) % 3\n      val pX = (lastMove._2 - 1) % 3\n      (for (\n        x <- 0 to 2;\n        y <- 0 to 2\n      ) yield ((y + pY * 3) * 9) + pX * 3 + x).toSet[Int]\n    }\n\n  }\n  val data = for (_ <- 1 to 11) yield StdIn.readLine()\n  val coords = StdIn.readLine().split(\" \").map(_.toInt)\n  println(new Board(data, (coords.head, coords.tail.head)).availableMoves)\n}\n", "src_uid": "8f0fad22f629332868c39969492264d3"}
{"source_code": "import scala.util.Sorting\n\nobject A347 {\n  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)\n\n  def readInts(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)\n  }\n\n  def readLongs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong)\n  }\n\n  def readBigs(n: Int) = {\n    val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken))\n  }\n\n  def main(args: Array[String]): Unit = {\n    val Array(n) = readInts(1)\n    val input = readInts(n).sortBy(-1*identity(_))\n\n    println((Array(input(0)) ++ input.dropRight(1).drop(1).sortBy(identity) ++ Array(input(n-1))).mkString(\" \"))\n\n  }\n}", "src_uid": "4408eba2c5c0693e6b70bdcbe2dda2f4"}
{"source_code": "object B743 {\n\n  import IO._\n  import collection.{mutable => cu}\n\n  def main(args: Array[String]): Unit = {\n    val Array(n, k) = readLongs(2)\n\n    println(find(n, k))\n  }\n\n  def find(n: Long, k: Long): Long = {\n    val pow = math.pow(2, n-1).toLong\n    if(k == math.pow(2, n-1)) {\n      n\n    } else if(k < math.pow(2, n-1)){\n      find(n-1, k)\n    } else {\n      find(n-1, k-pow)\n    }\n  }\n\n  object IO {\n    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n\n    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(\"src/input\")))\n    @inline def read: String = input.readLine()\n\n    @inline def tokenizeLine = new java.util.StringTokenizer(read)\n\n    def readInt: Int = tokenizeLine.nextToken.toInt\n\n    def readInts(n: Int): Array[Int] = {\n      val tl = tokenizeLine\n      Array.fill(n)(tl.nextToken.toInt)\n    }\n\n    def readLongs(n: Int): Array[Long] = {\n      val tl = tokenizeLine\n      Array.fill(n)(tl.nextToken.toLong)\n    }\n\n    def readBigs(n: Int): Array[BigInt] = {\n      val tl = tokenizeLine\n      Array.fill(n)(BigInt(tl.nextToken))\n    }\n  }\n\n}\n", "src_uid": "0af400ea8e25b1a36adec4cc08912b71"}
{"source_code": "import scala.io.StdIn\n\nobject Main {\n  def main(args: Array[String]): Unit = {\n    val nk = StdIn.readLine().split(\" \").map(item => item.toInt)\n    val (n, k) = (nk(0), nk(1))\n    val a = StdIn.readLine().split(\" \").map(item => item.toInt)\n    val b = a.distinct\n    if (b.length < k) {\n      println(\"NO\")\n    } else {\n      println(\"YES\")\n      val c = (0 until k).map(i => a.indexOf(b(i)) + 1)\n      c.foreach(item => print(item + \" \"))\n    }\n  }\n}\n", "src_uid": "5de6574d57ab04ca195143e08d28d0ad"}
{"source_code": "import java.util.Scanner\n\nobject Main{\n  def main (args: Array[String]){\n    val sc = new Scanner(System.in)\n    val n = sc.nextInt()\n\n    var choko = new Array[Int](n)\n    var flagz = true\n    for(i <- 0 until n){\n      val tmp = sc.nextInt()\n      if(tmp == 1)\n        flagz = false\n      choko(i) = tmp\n    }\n\n    //\n    if(flagz)\n      println(0)\n    else{\n      var ind = -1\n      var iii = 0\n\n      while(ind == -1){\n        if(choko(iii) == 1)\n          ind = iii\n\n        iii += 1\n      }\n\n      if(ind == n-1)\n        println(1)\n      else{\n        var ans = 1L\n        var zero = 0\n        for(i <- ind+1 until n){\n          choko(i) match{\n            case 0 => zero += 1\n            case 1 =>\n              ans *= zero + 1\n              zero = 0\n            case _ => ()\n          }\n        }\n        println(ans)\n      }      \n    }\n  }\n}\n", "src_uid": "58242665476f1c4fa723848ff0ecda98"}
{"source_code": "object Solution extends App {\n  val in = scala.io.Source.stdin.getLines()\n  val n = in.next().toInt\n  val str = in.next()\n  val part1 = str.take(n).sorted\n  val part2 = str.drop(n).sorted\n  if (part1.zip(part2).forall(x => x._1 < x._2) || part1.zip(part2).forall(x => x._1 > x._2))\n    println(\"YES\")\n  else\n    println(\"NO\")\n}\n", "src_uid": "e4419bca9d605dbd63f7884377e28769"}
{"source_code": "import java.util.StringTokenizer\n\nimport scala.io.StdIn\n\nobject A extends App with Reader {\n  read()\n  val n = int()\n  val k = (0 until 31).filter(i => n >= (1 << i)).last\n  println(k+1)\n}\n\ntrait Reader {\n  var st: StringTokenizer = _\n  def read() = { st = new StringTokenizer(StdIn.readLine()) }\n  def int() = st.nextToken().toInt\n  def long() = st.nextToken().toLong\n}\n", "src_uid": "95cb79597443461085e62d974d67a9a0"}
{"source_code": "object Solution extends App {\n  val lines = io.Source.stdin.getLines()\n  val n = lines.next().toInt\n  val str = lines.next()\n  val (curr, max, inside, _) = str.foldLeft((0, 0, 0, false)) {\n    case ((currentLength, maxLength, inside, false), '_') => (0, Math.max(maxLength, currentLength), inside, false)\n    case ((currentLength, maxLength, inside, true), '_') if currentLength > 0 => (0, maxLength, inside + 1, true)\n    case ((currentLength, maxLength, inside, true), '_') => (0, maxLength, inside, true)\n    case ((currentLength, maxLength, inside, false), '(') => (0, Math.max(maxLength, currentLength), inside, true)\n    case ((currentLength, maxLength, inside, true), ')') if currentLength > 0 => (0, maxLength, inside + 1, false)\n    case ((currentLength, maxLength, inside, true), ')') => (0, maxLength, inside, false)\n    case ((currentLength, maxLength, inside, state), el) => (currentLength + 1, maxLength, inside, state)\n  }\n  println(s\"${Math.max(max, curr)} $inside\")\n}\n", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92"}
{"source_code": "import java.util.Scanner\n\nimport scala.io.StdIn\n\nobject AtaskGlobal extends App {\n  var line = new Scanner(StdIn.readLine())\n  val a = BigInt(line.nextInt())\n  val b = BigInt(line.nextInt())\n  val c = BigInt(line.nextInt())\n\n  var diff = BigInt(0)\n  var greater = BigInt(0)\n  if (a >= b) {\n    diff = a - b\n  } else {\n    diff = b - a\n    greater = 1\n  }\n  var realA = a\n  var realB = b\n\n  if (diff == 2) {\n    if (greater == 1) {\n      realB = b - 1\n    } else {\n      realA = a - 1\n    }\n  }\n  if (diff >= 3) {\n    if (greater == 1) {\n      realB = a + 1\n    } else {\n      realA = b + 1\n    }\n  }\n\n  var result = c*2 + realA + realB\n  println(result)\n}\n", "src_uid": "609f131325c13213aedcf8d55fc3ed77"}
{"source_code": "/**\n  * Created by Nikolay on 23/06/16.\n  */\n\nimport scala.io.StdIn.readInt\nobject ApplicationA extends App {\n  val a = scala.io.StdIn.readLine().split(\"\\\\s+\")\n  val n = a(0).toInt\n  val k = a(1).toInt\n  val ans = n / k * k +  k\n  print(ans)\n}\n", "src_uid": "75f3835c969c871a609b978e04476542"}
{"source_code": "import scala.io.StdIn\nimport scala.util.Sorting\n\nobject DrazilFactorial {\n  \n  def getMaxF(input:Array[Char]):String = {\n    val output:Array[Int] = input flatMap ((c:Char) => {\n        val x:Int = c-'0'\n        if (x==9) Array(7,3,3,2)\n        else if (x==8) Array(7,2,2,2)\n        else if (x==7) Array(7)\n        else if (x==6) Array(5, 3)\n        else if (x==5) Array(5)\n        else if (x==4) Array(3, 2, 2)\n        else if (x==3) Array(3)\n        else if (x==2) Array(2)\n        else Array.emptyIntArray\n      })\n    output.sorted(Ordering[Int].reverse).mkString(\"\")\n  }\n  \n  def main(args: Array[String]) {\n    val cnt:Int = StdIn.readLine().toInt\n    val ln:String = StdIn.readLine()\n    val ca:Array[Char] = ln.toCharArray()\n    val fca:Array[Char] = ca filter (c=>c>'0' && c<='9')\n    println(getMaxF(fca))\n  }\n\n}", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398"}
{"source_code": "object Solution extends App {\n\n  def sumPair(data: Array[Array[Int]], permutation: Array[Int], a: Int, b: Int) = {\n    data(permutation(a))(permutation(b)) + data(permutation(b))(permutation(a))\n  }\n\n  def sum(data: Array[Array[Int]], permutations: Array[Int]) = {\n    sumPair(data, permutations, 0, 1) +\n    sumPair(data, permutations, 2, 3) +\n    sumPair(data, permutations, 1, 2) +\n    sumPair(data, permutations, 3, 4) +\n    sumPair(data, permutations, 2, 3) +\n    sumPair(data, permutations, 3, 4)\n  }\n\n  val in = scala.io.Source.stdin.getLines()\n  val t = Array.fill(5){in.next().split(\" \").map(_.toInt)}\n  println(Array(0, 1, 2, 3, 4).permutations.map(i => sum(t, i)).max)\n}", "src_uid": "be6d4df20e9a48d183dd8f34531df246"}
{"source_code": "object _869A extends CodeForcesApp {\n  import Utils._, annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._\n\n  override def apply(io: IO): io.type = {\n    val n = io.read[Int]\n    val x, y = io.read[Vector, Int](n)\n    val all = x.toSet ++ y\n    var c = 0\n    for {\n      i <- x\n      j <- y\n      xor = i ^ j\n      if all.contains(xor)\n    } c += 1\n\n    val ans = if (c%2 == 0) \"Karen\" else \"Koyomi\"\n    io.write(ans)\n  }\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n  lazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)\n  def apply(io: IO): io.type\n  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()\n}\nobject Utils {\n  import scala.collection.mutable, mutable.{Map => Dict}\n  implicit class GenericExtensions[A](val a: A) extends AnyVal {\n    def in(set: collection.Set[A]): Boolean = set(a)\n    def some: Option[A] = Some(a)\n    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a\n  }\n  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {\n    def onlyElement: A = assuming(t.size == 1)(t.head)\n    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)\n    def duplicates(implicit b: C of A): C[A] = {\n      val elems = mutable.Set.empty[A]\n      (t collect {case i if !elems.add(i) => i}).to[C]\n    }\n    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}\n    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)\n    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)\n    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]\n    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap\n    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)\n    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}\n    def toMutableMultiSet: Dict[A, Int] = {\n      val c = map[A] to 0\n      t.foreach(i => c(i) += 1)\n      c\n    }\n    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0\n    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)\n  }\n  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)\n  }\n  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)\n  }\n  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {\n    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t\n  }\n  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {\n    def key = p._1\n    def value = p._2\n    def toSeq(implicit ev: A =:= B): Seq[A] = Seq(p._1, p._2.asInstanceOf[A])\n  }\n  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {\n    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)\n    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])\n    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]\n  }\n  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {\n    def lastKeyOption: Option[K] = m.lastOption.map(_.key)\n    def firstKeyOption: Option[K] = m.headOption.map(_.key)\n    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap\n    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}\n    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m\n    def mapValuesSafely[V2](f: V => V2): Map[K, V2] = m.mapValues(f).view.force //Hack to get around https://issues.scala-lang.org/browse/SI-4776\n  }\n  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {\n    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)\n    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)\n    private def removeNode(kv: (K, V)): (K, V) = {\n      m -= kv.key\n      kv\n    }\n  }\n  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {\n    def notContains(x: A): Boolean = !(s contains x)\n    def toMutable = mutable.Set.empty[A] ++ s\n  }\n  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {\n    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}\n    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)\n    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)\n    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}\n    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)\n  }\n  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {\n    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero\n    def toEnglish = if(x) \"Yes\" else \"No\"\n  }\n  implicit class IntExtensions(val x: Int) extends AnyVal {\n    import java.lang.{Integer => JInt}\n    def withHighestOneBit: Int = JInt.highestOneBit(x)\n    def withLowestOneBit: Int = JInt.lowestOneBit(x)\n    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)\n    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)\n    def bitCount: Int = JInt.bitCount(x)\n    def setLowestBits(n: Int): Int = x | (left(n) - 1)\n    def clearLowestBits(n: Int): Int = x & left(n, ~0)\n    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)\n    def setBit(i: Int): Int = x | left(i)\n    def clearBit(i: Int): Int = x & ~left(i)\n    def toggleBit(i: Int): Int = x ^ left(i)\n    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1\n    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)\n    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)\n  }\n  implicit class LongExtensions(val x: Long) extends AnyVal {\n    import java.lang.{Long => JLong}\n    def withHighestOneBitSet: Long = JLong.highestOneBit(x)\n    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)\n    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)\n    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)\n    def bitCount: Int = JLong.bitCount(x)\n    def setLowestBits(n: Int): Long = x | (left(n) - 1)\n    def clearLowestBits(n: Int): Long = x & left(n, ~0L)\n    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)\n    def setBit(i: Int): Long = x | left(i)\n    def clearBit(i: Int): Long = x & ~left(i)\n    def toggleBit(i: Int): Long = x ^ left(i)\n    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1\n    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)\n  }\n  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {\n    import Numeric.Implicits._\n    def **(i: Int): A = if (i == 0) n.one else {\n      val h = x ** (i/2)\n      if (i%2 == 0) h * h else h * h * x\n    }\n    def distance(y: A) = (x - y).abs()\n    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)\n    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf \"Greg\" whenNegative Int.MaxValue\n  }\n  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {\n    import scala.collection.immutable.NumericRange, Integral.Implicits._\n    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x\n    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)\n    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)\n  }\n  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))\n  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)\n  def asc[A](implicit order: Ordering[A]): Ordering[A] = order\n  def map[K] = new {\n    def to[V](default: => V): Dict[K, V] = using(_ => default)\n    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {\n      override def apply(key: K) = getOrElseUpdate(key, f(key))\n    }\n  }\n  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]\n  def memoize[A, B](f: A => B): A ==> B = map[A] using f\n  implicit class FuzzyDouble(val x: Double) extends AnyVal {\n    def  >~(y: Double) = x > y + eps\n    def >=~(y: Double) = x >= y + eps\n    def  ~<(y: Double) = y >=~ x\n    def ~=<(y: Double) = y >~ x\n    def  ~=(y: Double) = (x distance y) <= eps\n  }\n  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {\n    val (xs, ys) = points.unzip\n    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)\n  }\n  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {\n    val shape = new java.awt.geom.GeneralPath()\n    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}\n    points.tail foreach {case (x, y) => shape.lineTo(x, y)}\n    shape.closePath()\n    shape\n  }\n  def until(until: Int): Range = 0 until until\n  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}\n  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}\n  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None\n  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)\n  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]\n  type ==>[A, B] = collection.Map[A, B]\n  val mod: Int = (1e9 + 7).toInt\n  val eps: Double = 1e-9\n}\n/***********************************[Scala I/O]*********************************************/\nimport Utils._, java.io._, java.util.StringTokenizer\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {\n  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n  val printer = new PrintWriter(out, true)\n\n  @inline private[this] def tokenizer() = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    when(tokenizers.nonEmpty)(tokenizers.head)\n  }\n\n  def read[A](implicit read: IO.Read[A]): A = read.apply(this)\n  def read[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(read).to[C]\n\n  def readTill(delim: String): String = tokenizer().get.nextToken(delim)\n  def readTillEndOfLine(): String = readTill(\"\\n\\r\")\n\n  def readAll[A: IO.Read]: (Int, Vector[A]) = {\n    val data = read[Vector[A]]\n    (data.length, data)\n  }\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n\n  def write(obj: Any): this.type = {\n    printer.print(obj)\n    this\n  }\n  def writeLine(): this.type = {\n    printer.println()\n    this\n  }\n  def writeLine(obj: Any): this.type = {\n    printer.println(obj)\n    this\n  }\n  def writeAll(obj: Traversable[Any], separator: String = \" \"): this.type = write(obj mkString separator)\n  def query[A: IO.Read](question: Any): A = writeLine(question).read\n\n  override def flush() = printer.flush()\n  def close() = {\n    flush()\n    in.close()\n    printer.close()\n  }\n}\nobject IO {\n  class Read[A](val apply: IO => A) {\n    def map[B](f: A => B): Read[B] = new Read(apply andThen f)\n  }\n  object Read {\n    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))\n    implicit val string                                       : Read[String]       = new Read(_.next())\n    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)\n    implicit val int                                          : Read[Int]          = string.map(_.toInt)\n    implicit val long                                         : Read[Long]         = string.map(_.toLong)\n    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))\n    implicit val double                                       : Read[Double]       = string.map(_.toDouble)\n    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))\n    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))\n    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]))\n    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]))\n    implicit val boolean                                      : Read[Boolean]      = string map {s =>\n      s.toLowerCase match {\n        case \"yes\" | \"true\" | \"1\" => true\n        case \"no\" | \"false\" | \"0\" => false\n        case _ => s.toBoolean\n      }\n    }\n  }\n}\n\n", "src_uid": "1649d2592eadaa8f8d076eae2866cffc"}
{"source_code": "object _869C extends CodeForcesApp {\n  import Utils._, annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._\n\n  val arithmetic = new ModularArithmetic(998244353L) {\n    override def modularInverse(n: Long): Mod = BigInt(n).modPow(mod - 2, mod).toLong\n  }\n  import arithmetic._\n\n  override def apply(io: IO): io.type = {\n    val a, b, c = io.read[Int]\n    var ans: Mod = possibleBridges(a, b) * possibleBridges(b, c)\n    ans = ans * possibleBridges(c, a)\n    io.write(ans)\n  }\n\n  def possibleBridges(island1: Int, island2: Int): Mod = {\n    val a = island1 min island2\n    val b = island1 max island2\n    (0 to a)\n      .map(possibleBridges(a, b, _))\n      .foldLeft(0L)({case (i, j) => toMod(i + j)})\n  }\n  \n  def possibleBridges(a: Int, b: Int, k: Int): Mod = combinations(a, k) * permutations(b, k)\n}\n\nclass ModularArithmetic(val mod: Long) {\n  class Mod(val value: Long) {\n    override val toString = value.toString\n  }\n  implicit def fromMod(mod: Mod): Long = mod.value\n  implicit def toMod(x: Long): Mod = new Mod(x%mod)\n\n  val factorial: IndexedSeq[Mod] = {\n    val N = 5500\n    val f = Array.ofDim[Mod](N)\n    f(0) = 1L\n    (1 until N).foreach(i => f(i) = f(i-1) * i)\n    f\n  }\n\n  def modularInverse(n: Long): Mod = BigInt(n).modInverse(mod).toLong //If mod is prime override this with BigInt(n).modPow(mod - 2, mod).toLong\n\n  def modDiv(a: Long, b: Long): Mod = a * modularInverse(b)\n\n  def permutations(n: Int, k: Int): Mod = modDiv(factorial(n), factorial(n - k))\n\n  def combinations(n: Int, k: Int): Mod = modDiv(permutations(n, k), factorial(k))\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n  lazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)\n  def apply(io: IO): io.type\n  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()\n}\nobject Utils {\n  import scala.collection.mutable, mutable.{Map => Dict}\n  implicit class GenericExtensions[A](val a: A) extends AnyVal {\n    def in(set: collection.Set[A]): Boolean = set(a)\n    def some: Option[A] = Some(a)\n    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a\n  }\n  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {\n    def onlyElement: A = assuming(t.size == 1)(t.head)\n    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)\n    def duplicates(implicit b: C of A): C[A] = {\n      val elems = mutable.Set.empty[A]\n      (t collect {case i if !elems.add(i) => i}).to[C]\n    }\n    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}\n    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)\n    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)\n    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]\n    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap\n    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)\n    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}\n    def toMutableMultiSet: Dict[A, Int] = {\n      val c = map[A] to 0\n      t.foreach(i => c(i) += 1)\n      c\n    }\n    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0\n    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)\n  }\n  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)\n  }\n  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)\n  }\n  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {\n    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t\n  }\n  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {\n    def key = p._1\n    def value = p._2\n    def toSeq(implicit ev: A =:= B): Seq[A] = Seq(p._1, p._2.asInstanceOf[A])\n  }\n  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {\n    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)\n    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])\n    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]\n  }\n  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {\n    def lastKeyOption: Option[K] = m.lastOption.map(_.key)\n    def firstKeyOption: Option[K] = m.headOption.map(_.key)\n    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap\n    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}\n    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m\n    def mapValuesSafely[V2](f: V => V2): Map[K, V2] = m.mapValues(f).view.force //Hack to get around https://issues.scala-lang.org/browse/SI-4776\n  }\n  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {\n    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)\n    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)\n    private def removeNode(kv: (K, V)): (K, V) = {\n      m -= kv.key\n      kv\n    }\n  }\n  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {\n    def notContains(x: A): Boolean = !(s contains x)\n    def toMutable = mutable.Set.empty[A] ++ s\n  }\n  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {\n    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}\n    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)\n    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)\n    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}\n    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)\n  }\n  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {\n    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero\n    def toEnglish = if(x) \"Yes\" else \"No\"\n  }\n  implicit class IntExtensions(val x: Int) extends AnyVal {\n    import java.lang.{Integer => JInt}\n    def withHighestOneBit: Int = JInt.highestOneBit(x)\n    def withLowestOneBit: Int = JInt.lowestOneBit(x)\n    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)\n    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)\n    def bitCount: Int = JInt.bitCount(x)\n    def setLowestBits(n: Int): Int = x | (left(n) - 1)\n    def clearLowestBits(n: Int): Int = x & left(n, ~0)\n    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)\n    def setBit(i: Int): Int = x | left(i)\n    def clearBit(i: Int): Int = x & ~left(i)\n    def toggleBit(i: Int): Int = x ^ left(i)\n    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1\n    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)\n    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)\n  }\n  implicit class LongExtensions(val x: Long) extends AnyVal {\n    import java.lang.{Long => JLong}\n    def withHighestOneBitSet: Long = JLong.highestOneBit(x)\n    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)\n    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)\n    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)\n    def bitCount: Int = JLong.bitCount(x)\n    def setLowestBits(n: Int): Long = x | (left(n) - 1)\n    def clearLowestBits(n: Int): Long = x & left(n, ~0L)\n    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)\n    def setBit(i: Int): Long = x | left(i)\n    def clearBit(i: Int): Long = x & ~left(i)\n    def toggleBit(i: Int): Long = x ^ left(i)\n    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1\n    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)\n  }\n  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {\n    import Numeric.Implicits._\n    def **(i: Int): A = if (i == 0) n.one else {\n      val h = x ** (i/2)\n      if (i%2 == 0) h * h else h * h * x\n    }\n    def distance(y: A) = (x - y).abs()\n    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)\n    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf \"Greg\" whenNegative Int.MaxValue\n  }\n  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {\n    import scala.collection.immutable.NumericRange, Integral.Implicits._\n    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x\n    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)\n    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)\n  }\n  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))\n  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)\n  def asc[A](implicit order: Ordering[A]): Ordering[A] = order\n  def map[K] = new {\n    def to[V](default: => V): Dict[K, V] = using(_ => default)\n    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {\n      override def apply(key: K) = getOrElseUpdate(key, f(key))\n    }\n  }\n  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]\n  def memoize[A, B](f: A => B): A ==> B = map[A] using f\n  implicit class FuzzyDouble(val x: Double) extends AnyVal {\n    def  >~(y: Double) = x > y + eps\n    def >=~(y: Double) = x >= y + eps\n    def  ~<(y: Double) = y >=~ x\n    def ~=<(y: Double) = y >~ x\n    def  ~=(y: Double) = (x distance y) <= eps\n  }\n  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {\n    val (xs, ys) = points.unzip\n    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)\n  }\n  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {\n    val shape = new java.awt.geom.GeneralPath()\n    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}\n    points.tail foreach {case (x, y) => shape.lineTo(x, y)}\n    shape.closePath()\n    shape\n  }\n  def until(until: Int): Range = 0 until until\n  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}\n  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}\n  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None\n  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)\n  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]\n  type ==>[A, B] = collection.Map[A, B]\n  val mod: Int = (1e9 + 7).toInt\n  val eps: Double = 1e-9\n}\n/***********************************[Scala I/O]*********************************************/\nimport Utils._, java.io._, java.util.StringTokenizer\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {\n  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n  val printer = new PrintWriter(out, true)\n\n  @inline private[this] def tokenizer() = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    when(tokenizers.nonEmpty)(tokenizers.head)\n  }\n\n  def read[A](implicit read: IO.Read[A]): A = read.apply(this)\n  def read[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(read).to[C]\n\n  def readTill(delim: String): String = tokenizer().get.nextToken(delim)\n  def readTillEndOfLine(): String = readTill(\"\\n\\r\")\n\n  def readAll[A: IO.Read]: (Int, Vector[A]) = {\n    val data = read[Vector[A]]\n    (data.length, data)\n  }\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n\n  def write(obj: Any): this.type = {\n    printer.print(obj)\n    this\n  }\n  def writeLine(): this.type = {\n    printer.println()\n    this\n  }\n  def writeLine(obj: Any): this.type = {\n    printer.println(obj)\n    this\n  }\n  def writeAll(obj: Traversable[Any], separator: String = \" \"): this.type = write(obj mkString separator)\n  def query[A: IO.Read](question: Any): A = writeLine(question).read\n\n  override def flush() = printer.flush()\n  def close() = {\n    flush()\n    in.close()\n    printer.close()\n  }\n}\nobject IO {\n  class Read[A](val apply: IO => A) {\n    def map[B](f: A => B): Read[B] = new Read(apply andThen f)\n  }\n  object Read {\n    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))\n    implicit val string                                       : Read[String]       = new Read(_.next())\n    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)\n    implicit val int                                          : Read[Int]          = string.map(_.toInt)\n    implicit val long                                         : Read[Long]         = string.map(_.toLong)\n    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))\n    implicit val double                                       : Read[Double]       = string.map(_.toDouble)\n    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))\n    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))\n    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]))\n    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]))\n    implicit val boolean                                      : Read[Boolean]      = string map {s =>\n      s.toLowerCase match {\n        case \"yes\" | \"true\" | \"1\" => true\n        case \"no\" | \"false\" | \"0\" => false\n        case _ => s.toBoolean\n      }\n    }\n  }\n}\n\n", "src_uid": "b6dc5533fbf285d5ef4cf60ef6300383"}
{"source_code": "object Main extends AlgoApp {\n  type Mat = (Long, Long, Long, Long)\n  def multiply(a: Mat, b: Mat, modNum: Long): Mat = {\n    ((a._1 * b._1 + a._2 * b._3) % modNum,\n      (a._1 * b._2 + a._2 * b._4) % modNum,\n      (a._3 * b._1 + a._4 * b._3) % modNum,\n      (a._3 * b._2 + a._4 * b._4) % modNum)\n  }\n  def power(a: Mat, b: Long, modNum: Long): Mat = {\n    var tmp = a\n    var ans: Mat = (1L, 0L, 0L, 1L)\n    var p = b\n    while (p > 0) {\n      if (p % 2 == 1) {\n        ans = multiply(ans, tmp, modNum)\n      }\n      tmp = multiply(tmp, tmp, modNum)\n      p >>= 1\n    }\n    ans\n  }\n\n  def solve(n: Long, res: Long, modNum: Long): Long = {\n    val mat = power((1L, 1L, 1L, 0L), n, modNum)\n    val ans = (mat._1 + mat._2) % modNum\n    if (res == 0) {\n      ans\n    } else {\n      var (x, y, z) = (2L, n, 1L)\n      while (y > 0) {\n        if (y % 2 == 1)\n          z = z * x % modNum\n        x = x * x % modNum\n        y >>= 1\n      }\n      (z - ans + modNum) % modNum\n    }\n  }\n\n  val n = nextLong\n  var k = nextLong\n  val l = nextInt\n  val modNum = nextLong\n  var ans = 1L % modNum\n  for (i <- 1 to l) {\n    val tmp = solve(n, k & 1, modNum)\n    ans = ans * tmp % modNum\n    k >>= 1\n  }\n  if (k > 0) ans = 0\n  println(ans)\n}\n\nabstract class AlgoApp extends App {\n  import java.util.StringTokenizer\n\n  var token = new StringTokenizer(\"\")\n  def next = {\n    while (!token.hasMoreTokens())\n      token = new StringTokenizer(readLine)\n    token.nextToken()\n  }\n  def nextInt = next.toInt\n  def nextLong = next.toLong\n}", "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e"}
{"source_code": "object Main {\n  import java.io.{BufferedReader, InputStream, InputStreamReader}\n  import java.util.StringTokenizer\n  import scala.reflect.ClassTag\n\n  def main(args: Array[String]): Unit = {\n    val out = new java.io.PrintWriter(System.out)\n    new Main(out, new InputReader(System.in)).solve()\n    out.flush()\n  }\n\n  private val oj = System.getenv(\"ATCODER_DEBUG\") == null\n  def DEBUG(f: => Unit): Unit = {\n    if (!oj){ f }\n  }\n  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) \"1\" else \"0\").mkString) }\n  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(\" \")) }\n  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(\" \")) }\n  def debugDim(m: Array[Array[Long]]): Unit = if (!oj){\n    REP(m.length) { i =>\n      debug(m(i))\n    }\n  }\n  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){\n    REP(m(0).length) { j =>\n      REP(m.length) { i =>\n        System.err.print(m(i)(j))\n        System.err.print(\" \")\n      }\n      System.err.println()\n    }\n  }\n  def debug(s: => String): Unit = DEBUG {\n    System.err.println(s)\n  }\n  def debugL(num: => Long): Unit = DEBUG {\n    System.err.println(num)\n  }\n\n  class InputReader(val stream: InputStream) {\n    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n    private var tokenizer: StringTokenizer = _\n\n    def next(): String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new StringTokenizer(reader.readLine)\n      tokenizer.nextToken\n    }\n\n    def nextInt(): Int = Integer.parseInt(next())\n    def nextLong(): Long = java.lang.Long.parseLong(next())\n    def nextChar(): Char = next().charAt(0)\n\n    def ni(): Int = nextInt()\n    def nl(): Long = nextLong()\n    def nc(): Char = nextChar()\n    def ns(): String = next()\n    def ns(n: Int): Array[Char] = ns().toCharArray\n    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)\n    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {\n      val A1, A2 = Array.ofDim[Int](n)\n      REP(n) { i =>\n        A1(i) = ni() + offset\n        A2(i) = ni() + offset\n      }\n      (A1, A2)\n    }\n    def nm(n: Int, m: Int): Array[Array[Int]] = {\n      val A = Array.ofDim[Int](n, m)\n      REP(n) { i =>\n        REP(m) { j =>\n          A(i)(j) = ni()\n        }\n      }\n      A\n    }\n    def nal(n: Int): Array[Long] = map(n)(_ => nl())\n    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))\n  }\n\n  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = offset\n    val N = n + offset\n    while(i < N) { f(i); i += 1 }\n  }\n  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = n - 1 + offset\n    while(i >= offset) { f(i); i -= 1 }\n  }\n  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {\n    REP(to - from + 1, from) { i =>\n      f(i)\n    }\n  }\n  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {\n    val res = Array.ofDim[A](n)\n    REP(n)(i => res(i) = f(i + offset))\n    res\n  }\n\n  def sumL(as: Array[Int]): Long = {\n    var s = 0L\n    REP(as.length)(i => s += as(i))\n    s\n  }\n  def cumSum(as: Array[Int]): Array[Long] = {\n    val cum = Array.ofDim[Long](as.length + 1)\n    REP(as.length) { i =>\n      cum(i + 1) = cum(i) + as(i)\n    }\n    cum\n  }\n}\n\nclass Main(out: java.io.PrintWriter, sc: Main.InputReader) {\n  import sc._\n  import Main._\n  import java.util.Arrays.sort\n\n  import scala.collection.mutable\n  import math.{abs, max, min}\n  import mutable.ArrayBuffer\n\n  // toInt\u3068\u304b+7\u3068\u304b\u3059\u308b\u306a\u3089val\u306b\u3057\u308d\n  @inline private def MOD = 1000000007\n\n  def solve(): Unit = {\n    val X, Y, Z = ni()\n\n    if (abs(X - Y) > 0 && Z >= abs(X - Y) || abs(X - Y) == 0 && Z > 0) {\n      out.println(\"?\")\n    } else {\n      if (X > Y) {\n        out.println(\"+\")\n      } else if (X < Y ) {\n        out.println(\"-\")\n      } else {\n        out.println(0)\n      }\n    }\n  }\n}", "src_uid": "66398694a4a142b4a4e709d059aca0fa"}
{"source_code": "object Main extends App{\n  val s = readLine()\n  var s1, s2 = \"\"\n  if (s.startsWith(\"ftp\")){\n    s1 = \"ftp\"\n    s2 = s.substring(3)\n  }\n  else{\n    s1 = \"http\"\n    s2 = s.substring(4)\n  }\n  var p = s2.indexOf(\"ru\")\n  if (p == 0)\n    p = 2 + s2.substring(2).indexOf(\"ru\")\n  val s3 = s2.substring(p + 2)\n  s2 = s2.substring(0, p)\n  if (s3.length == 0)\n    println(s1 + \"://\" + s2 + \".ru\")\n  else\n    println(s1 + \"://\" + s2 + \".ru/\" + s3)\n}\n", "src_uid": "4c999b7854a8a08960b6501a90b3bba3"}
{"source_code": "import scala.io.StdIn.readLine\nobject Triangle extends App{\n  readLine\n  println(if (readLine.split(' ').map(_.toInt).sorted.sliding(3).exists { case Array(x, y, z) \u21d2 x + y > z }) \"YES\" else \"NO\")\n}\n", "src_uid": "897bd80b79df7b1143b652655b9a6790"}
{"source_code": "import java.util.StringTokenizer\n\nobject _415A extends App {\n  var token = new StringTokenizer(\"\")\n  def next = {\n    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)\n    token.nextToken()\n  }\n  val n = next.toInt\n  val m = next.toInt\n  val a = (1 to m).map(i => next.toInt)\n  val ans = (0 to n).toArray\n\n  var right = n + 1\n  for (index <- a) {\n    if (index < right) {\n      for (i <- index until right) ans(i) = index\n      right = index\n    }\n  }\n  println((1 to n).map(i => ans(i)).mkString(\" \"))\n}\n", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863"}
{"source_code": "import scala.io.StdIn\n\nobject Codeforces1099C {\n\n  def increaseLength(postCardLine: String, lengthToIncrease: Int): String = {\n    val formingLine = new StringBuilder\n    var alreadyIncreased = false\n    for (i <- postCardLine.indices) {\n      if (postCardLine(i) == '*') {\n        if (!alreadyIncreased) {\n          for (_ <- 1 to lengthToIncrease) {\n            formingLine.append(postCardLine(i - 1))\n          }\n          alreadyIncreased = true\n        }\n      }\n      else if (postCardLine(i) != '?') {\n        formingLine.append(postCardLine(i))\n      }\n    }\n\n    formingLine.toString\n  }\n\n  def decreaseLength(postCardLine: String, lengthToDecrease: Int): String = {\n    val formingLine = new StringBuilder\n    var totalDecreased = 0\n    for (i <- postCardLine.indices) {\n      if (i + 1 < postCardLine.length\n        && (postCardLine(i + 1) == '*' || postCardLine(i + 1) == '?')\n        && totalDecreased < lengthToDecrease) {\n        totalDecreased += 1\n      }\n      else if (postCardLine(i) != '*' && postCardLine(i) != '?') {\n        formingLine.append(postCardLine(i))\n      }\n    }\n\n    formingLine.toString\n  }\n\n  def convertToLength(postCardLine: String, k: Int): Option[String] = {\n    val initialLength = postCardLine.count(ch => ch != '*' && ch != '?')\n    val canBeIncreased = postCardLine.contains('*')\n    val canBeDecreaseUpTo = postCardLine.count(ch => ch == '*' || ch == '?')\n\n    if (initialLength < k && canBeIncreased)\n      Some(increaseLength(postCardLine, k - initialLength))\n    else if (initialLength >= k && canBeDecreaseUpTo >= initialLength - k)\n      Some(decreaseLength(postCardLine, initialLength - k))\n    else None\n  }\n\n  def main(args: Array[String]): Unit = {\n    val postCardLine = StdIn.readLine().trim\n    val k = StdIn.readLine().trim.toInt\n\n    val convertedLine = convertToLength(postCardLine, k)\n\n    println(convertedLine.getOrElse(\"Impossible\"))\n  }\n}", "src_uid": "90ad5e6bb5839f9b99a125ccb118a276"}
{"source_code": "//package codeforces.contest1097\n\nobject GennadyAndACardGame {\n  def main(args: Array[String]): Unit = {\n    val Array(rank, suit) = io.StdIn.readLine().split(\"\")\n    val inHand = io.StdIn.readLine.split(\" \").map(s => (s(0), s(1)))\n\n    if(inHand.exists { case (r, s) => r == rank(0) || s == suit(0) })\n      println(\"YES\")\n    else\n      println(\"NO\")\n  }\n}\n", "src_uid": "699444eb6366ad12bc77e7ac2602d74b"}
{"source_code": "object A535 {\n\n  import IO._\n  val alpha = Array(\n    \"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\",\n    \"ten\",  \"eleven\",\"twelve\", \"thirteen\", \"fourteen\", \"fifteen\", \"sixteen\", \"seventeen\", \"eighteen\", \"nineteen\",\n    \"twenty\")\n  val tens = Array(\"twenty\", \"thirty\", \"forty\", \"fifty\", \"sixty\", \"seventy\", \"eighty\", \"ninety\")\n  def main(args: Array[String]): Unit = {\n    val Array(n) = readInts(1)\n    if(n <= 20) {\n      println(alpha(n))\n    } else {\n      if(n%10 == 0) {\n        println(tens(n/10 - 2))\n      } else {\n        println(tens(n/10 - 2) + \"-\" + alpha(n%10))\n      }\n    }\n  }\n\n  object IO {\n    @inline def read: String = scala.io.StdIn.readLine\n\n    @inline def tokenizeLine = new java.util.StringTokenizer(read)\n\n    def readInts(n: Int): Array[Int] = {\n      val tl = tokenizeLine;\n      Array.fill(n)(tl.nextToken.toInt)\n    }\n\n    def readLongs(n: Int): Array[Long] = {\n      val tl = tokenizeLine;\n      Array.fill(n)(tl.nextToken.toLong)\n    }\n\n    def readBigs(n: Int): Array[BigInt] = {\n      val tl = tokenizeLine;\n      Array.fill(n)(BigInt(tl.nextToken))\n    }\n  }\n\n}\n", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7"}
{"source_code": "import scala.collection.mutable.ArrayBuffer                                                 \nimport scala.io.StdIn                                                                       \n                                                                                            \nobject Solution extends App {                                                               \n  val arr = StdIn.readLine().split(\" \").map(_.toInt)                                        \n  var a = arr(0)                                                                            \n  var b = arr(1)                                                                            \n  var x = arr(2)                                                                            \n                                                                                            \n  val ans = ArrayBuffer.empty[Int]                                                          \n  if (a > b) {                                                                              \n    ans.append(0)                                                                           \n    a = a - 1                                                                               \n  }else                                                                                     \n  {                                                                                         \n    ans.append(1)                                                                           \n    b = b - 1                                                                               \n  }                                                                                         \n  while(a + b > 0) {                                                                        \n    if (x > 1) {                                                                            \n      if (ans.last == 0) {                                                                  \n        ans.append(1)                                                                       \n        b = b - 1                                                                           \n      } else {                                                                              \n        ans.append(0)                                                                       \n        a = a - 1                                                                           \n      }                                                                                     \n    }                                                                                       \n    else                                                                                    \n      {                                                                                     \n        if (x == 1)                                                                         \n          {                                                                                 \n            if (ans.last == 0) while(a > 0){ans.append(0);a = a - 1}                        \n            else while(b > 0){ans.append(1);b = b - 1}                                      \n          } else                                                                            \n          {                                                                                 \n            while(a > 0){ans.append(0);a = a - 1}                                           \n            while(b > 0){ans.append(1);b = b - 1}                                           \n          }                                                                                 \n                                                                                            \n      }                                                                                     \n       x = x - 1                                                                            \n                                                                                            \n  }                                                                                         \n                                                                                            \n  println(ans.map(_.toString).reduce((a,b) => a + b))                                       \n                                                                                            \n}                                                                                           ", "src_uid": "ef4123b8f3f3b511fde8b79ea9a6b20c"}
{"source_code": "object B extends App {\n  val Array(x, y) = scala.io.StdIn.readLine().split(\" \").map(_.toLong)\n\n  def compare(x: Long, y: Long): Int =\n    if (x == y) 0\n    else {\n      val n: Double = scala.math.log10(x) * y\n      val d: Double = scala.math.log10(y) * x\n\n      if (n == d) 0\n      else if (n > d) 1\n      else -1\n    }\n\n  val r = compare(x, y)\n\n  if (r == 0) println(\"=\")\n  else if (r < 0) println(\"<\")\n  else println(\">\")\n}\n", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6"}
{"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport java.util.Arrays.binarySearch\nimport scala.annotation.tailrec\nimport scala.annotation.switch\nimport scala.annotation.unchecked\nimport scala.collection.mutable\nimport scala.collection.mutable.ListBuffer\nimport scala.collection.mutable.ArrayBuffer\nimport scala.collection.immutable.TreeSet\nimport scala.util.Random\nimport scala.util.control.Breaks._\n\n\nobject P203A extends App {\n  val sc = new Scanner(System.in)\n  val out = new PrintWriter(System.out)\n\n  // T minutes ... 0, 1, ...\n  // a points(ini), - d_a / min\n  // b points(ini), - d_b / min\n  \n  def solve(): String = {\n    val X, T, A, B, Da, Db = sc.nextInt\n\n    val points = {\n      for {\n        i <- 0 to T\n        j <- 0 to T\n      }\n      yield {\n        val a = if (i == T) 0\n                else A - Da * i\n        val b = if (j == T) 0\n                else B - Db * j\n        a + b\n      }\n    }\n    points.find(_ == X) match {\n      case Some(x) => \"YES\"\n      case None    => \"NO\"\n    }\n  }\n\n  out.println(solve)\n  out.close\n}\n", "src_uid": "f98168cdd72369303b82b5a7ac45c3af"}
{"source_code": "import java.util._\nobject GCD\n{\n    def gcd(a: Int,b: Int): Int = {\n       if(b ==0) a else gcd(b, a%b)\n    }\n     \n    def main(args: Array[String]) {\n        val in = new Scanner(System.in)\n        val a = in.nextInt\n        val b = in.nextInt\n        \n        var res = 1\n        for(i <- 1 to Math.min(a,b)){\n            res *= i\n        }\n        print(res)\n    }\n}", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6"}
{"source_code": "object MikeAndPalindrome {\n  def isPossibleToConvert(testString: String): Boolean = {\n    if (testString.length != 0) {\n      val charChangeRequired = (0 to ((testString.length - 1) / 2)).count(p => testString(p) != testString(testString.length - p - 1))\n      charChangeRequired == 1 || (charChangeRequired == 0 && testString.length % 2 == 1)\n    }\n    else {\n      false\n    }\n  }\n\n  def main(args: Array[String]): Unit = {\n    val input = readLine().toString\n    if (isPossibleToConvert(input)) println(\"YES\") else println(\"NO\")\n  }\n}\n", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52"}
{"source_code": "object Main extends App {\n\tval Array(n, k) = scala.io.StdIn.readLine split ' ' map(_.toInt)\n\tprintln((2*n+k-1)/k+(5*n+k-1)/k+(8*n+k-1)/k)\n}", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39"}
{"source_code": "object Solution extends App {\n  val in = scala.io.Source.stdin.getLines()\n  val n = in.next().toInt\n  val data = List(\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\").filter(_.length == n)\n  val str = in.next()\n\n  println(data.find(e => e.zip(str).forall(el => el._2 == '.' || el._1 == el._2)).get)\n\n}\n", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0"}
{"source_code": "import scala.collection._\n\nobject C extends App {\n\n  def readString = Console.readLine\n  def tokenizeLine = new java.util.StringTokenizer(readString)\n  def readInts(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toInt) }\n\n  val Array(n, m) = readInts(2)\n  val as = readInts(n)\n  val bs = readInts(n)\n  \n  val maxSize = 2 * n + 1\n\n  var paint = Array.fill(maxSize, maxSize)(Long.MaxValue / 2)\n  for (i <- 0 until maxSize) paint(i)(i) = 0\n  var paint0 = Array.ofDim[Long](maxSize)\n\n  for (j <- 0 until maxSize) {\n    for (step <- 0 until n) {\n      val tmp = paint(j)\n      paint(j) = paint0\n      paint0 = tmp\n      paint(j)(0) = paint0(1) + bs(step)\n      paint(j)(2 * n - 1) = paint0(2 * n - 2) + as(step)\n      for (i <- 1 until maxSize - 2) {\n        paint(j)(i) = math.min(paint0(i + 1) + bs(step), paint0(i - 1) + as(step))\n      }\n    }\n  }\n  \n  def mult(x: Array[Array[Long]], y: Array[Array[Long]]) = {\n    val z = Array.fill(maxSize, maxSize)(0L)\n    for (i <- 0 until maxSize; j <- 0 until maxSize) {\n      var min = Long.MaxValue\n      for (k <- 0 until maxSize) if (x(i)(k) < Long.MaxValue / 2 && y(k)(j) < Long.MaxValue / 2) min = math.min(min, x(i)(k) + y(k)(j))\n      z(i)(j) = min\n    }\n    z\n  }\n  \n  def pow(x: Array[Array[Long]], deg: Int) = {\n    var res: Array[Array[Long]] = null\n    var y = x\n    var step = 1\n    while (step <= deg) {\n      if ((deg & step) > 0) res = if (res == null) y else mult(res, y)\n      //if (res != null) for (p <- res) println(p.mkString(\" \"))\n      y = mult(y, y)\n      step *= 2\n    }\n    res\n  }\n  //for (p <- paint) println(p.mkString(\" \"))\n  val full = pow(paint, m)\n\n  println(full(0)(0))\n}", "src_uid": "f40900973f4ebeb6fdafd75ebe4e9601"}
{"source_code": "object C extends App {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }\n\n  val s = readLine\n  val t = \"abcdefghijklmnopqrstuvwxyz\"\n  val res = new StringBuilder\n\n  var i, j = 0\n  while (i < s.length && j < t.length) {\n    if (s(i) <= t(j)) {\n      res += t(j)\n      i += 1\n      j += 1\n    } else {\n      res += s(i)\n      i += 1\n    }\n  }\n\n  while (i < s.length) {\n    res += s(i)\n    i += 1\n  }\n\n  if (j == t.length) println(res.result())\n  else println(-1)\n}\n", "src_uid": "f8ad543d499bcc0da0121a71a26db854"}
{"source_code": "import scala.collection.mutable\nobject BurningMidnightOil extends App {\n  val input = io.Source.stdin.getLines.next\n  val (n :: k :: Nil) = input.split(\" \").map(_.toInt).toList\n\n  val (nd, kd) = (n.toDouble, k.toDouble)\n  val mini = ((nd * (1.0 - 1.0 / kd)) + 1.0).toInt\n  val maxi = n\n\n  def testV(v: Int): Boolean = {\n    var acc = 0\n    var next = v\n    while(next != 0) {\n      acc = acc + next\n      next = next / k\n    }\n    acc >= n\n  }\n\n  def binarySearch(min: Int, max: Int, trial: Int, test: (Int => Boolean)): Int = {\n    if(min == max)        trial\n    else if(test(trial))  binarySearch(min, trial, (min + trial)/2, test)\n    else                  binarySearch(trial + 1, max, (trial + max + 1)/2, test)\n  }\n\n  println(binarySearch(mini, maxi, (mini + maxi)/2, testV))\n\n}", "src_uid": "41dfc86d341082dd96e089ac5433dc04"}
{"source_code": "object Solution extends App {\n  val lines = io.Source.stdin.getLines()\n  val Array(n, m) = lines.next().split(' ').map(_.toLong)\n  def f(n: Long, el: Int) = {\n    if (n % 10 >= el) 1 else 0\n  }\n\n  val result = (1 to 10).map(i => (1 to 10).filter(j => (i + j) % 5 == 0).map(j => (n / 10 + f(n, i)) * (m / 10 + f(m, j))).sum).sum\n  println(result)\n}\n\n", "src_uid": "df0879635b59e141c839d9599abd77d2"}
{"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport java.util.Arrays.binarySearch\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.collection.mutable.ListBuffer\nimport scala.collection.mutable.ArrayBuffer\nimport scala.util.Random\nimport scala.util.control.Breaks._\n\n\nobject P047A extends App {\n  val sc = new Scanner(System.in)\n  val out = new PrintWriter(System.out)\n\n  def solve(): String = {\n\n    val N = sc.nextInt\n\n    @inline\n    def triangular(n: Int): Int = n * (n + 1) / 2\n\n    @tailrec\n    def loop(n: Int): String = if (N == triangular(n)) \"YES\"\n                               else if (N < triangular(n)) \"NO\"\n                               else loop(n + 1)\n\n    loop(0)\n  }\n\n  out.println(solve)\n  out.close\n}\n\n\n\n\n\n", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301"}
{"source_code": "import java.util.Scanner\n\nobject Main{\n  def log7(n: Int): String = {\n    def func(b: Int, res: String): String = {\n      b match{\n        case 0 => res\n        case x => func(b / 7, (b % 7).toString + res)\n      }\n    }\n\n    val a = func(n, \"\")\n    if(a == \"\") \"0\"\n    else a\n  }\n\n  def main (args: Array[String]){\n    val sc = new Scanner(System.in)\n    val n = sc.nextInt()\n    val m = sc.nextInt()\n\n    //\n    val ns = log7(n-1)\n    val ms = log7(m-1)\n\n    val nl = ns.length\n    val ml = ms.length\n\n    if(nl + ml > 7){\n      println(0)\n    }\n    else{\n      val dp = new Array[Boolean](6543211)\n      var ans = 0\n\n      for(s <- \"0123456\".permutations){\n        val nows = s.substring(0, nl+ml)\n        if(!dp(nows.toInt)){\n          dp(nows.toInt) = true\n          val a = nows.substring(0, nl).toInt\n          val b = nows.substring(nl, nl+ml).toInt\n          if(a <= ns.toInt && b <= ms.toInt)\n            ans += 1\n        }\n      }\n      println(ans)\n    }\n  }\n}\n", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c"}
{"source_code": "import scala.annotation.tailrec\nimport scala.collection.mutable.ListBuffer\nimport scala.io.StdIn._\n\nobject B_QuasiBin extends App {\n  val n = readInt()\n//    val n = 9\n\n  val bin: Seq[Int] = Vector(1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000, 10001, 10010, 10011, 10100, 10101, 10110, 10111, 11000, 11001, 11010, 11011, 11100, 11101, 11110, 11111, 100000, 100001, 100010, 100011, 100100, 100101, 100110, 100111, 101000, 101001, 101010, 101011, 101100, 101101, 101110, 101111, 110000, 110001, 110010, 110011, 110100, 110101, 110110, 110111, 111000, 111001, 111010, 111011, 111100, 111101, 111110, 111111, 1000000, 1000001)\n\n  def solve(n: Int): List[Int] = {\n    if (n == 0) Nil\n    else if (bin.contains(n)) List(n)\n    else {\n      var i = 0\n      var max = Integer.MIN_VALUE\n      var maxElement = 0\n      while (bin(i) <= n) {\n        if (max < quality(n, bin(i))) {\n          max = quality(n, bin(i))\n          maxElement = i\n        }\n        i += 1\n      }\n\n      bin(maxElement) :: solve(n - bin(maxElement))\n    }\n\n  }\n\n  val answer = solve(n)\n  println(answer.length)\n  println(answer.mkString(\" \"))\n\n  def quality(a: Int, b: Int): Int = {\n    var counter = 0\n    var aa = a\n    var bb = b\n    while (aa > 0) {\n      if (aa % 10 > 0 && bb % 10 > 0) {\n        counter += 1\n      }\n\n      aa /= 10\n      bb /= 10\n    }\n\n    counter\n  }\n\n}\n", "src_uid": "033068c5e16d25f09039e29c88474275"}
{"source_code": "object B {\n    def main(args: Array[String]) = {\n        val a = readInt;\n        val a_str = a toString;\n        val ac2 = math.ceil(math.sqrt(a)) toInt;\n        val af2 = math.floor(math.sqrt(a)) toInt;\n\n        def good(x: Int): Boolean = x.toString exists {a_str contains _};\n\n        val appropriateSmall = for (x <- (1 to af2)\n            if a % x == 0 && good(x)) yield x;\n        val appropriateBig = for (x <- (1 to (ac2 - 1))\n            if a % x == 0 && good(a / x)) yield a / x;\n\n        println((appropriateSmall length) + (appropriateBig length))\n    }\n}\n", "src_uid": "ada94770281765f54ab264b4a1ef766e"}
{"source_code": "object Main extends App {\n  val in = readLine\n  println(in.split(\"WUB\").filter(_.nonEmpty).mkString(\" \"))\n}", "src_uid": "edede580da1395fe459a480f6a0a548d"}
{"source_code": "import java.util.Scanner\n\n/**\n * Created by hama_du on 2014/07/19.\n */\nobject ProblemB extends App {\n  val in = new Scanner(System.in)\n  val s = in.nextLine().toCharArray\n  val t = in.nextLine().toCharArray\n\n  val solve = canSolve(s, t)\n  val automaton = canAutomaton(s, t)\n  val array = canArray(s, t)\n\n  if (automaton) {\n    println(\"automaton\")\n  } else if (array) {\n    println(\"array\")\n  } else if (solve) {\n    println(\"both\")\n  } else {\n    println(\"need tree\")\n  }\n\n\n  def canSolve(s: Array[Char], t: Array[Char]) = {\n    countFrequency(s).zip(countFrequency(t)).filter(p => (p._1 < p._2)).size == 0\n  }\n\n  def canAutomaton(s: Array[Char], t: Array[Char]): Boolean = {\n    var t_idx = 0\n    var s_idx = 0\n    while (t_idx < t.length) {\n      while (s_idx < s.length && s(s_idx) != t(t_idx)) {\n        s_idx += 1\n      }\n      if (s_idx < s.length) {\n        s_idx += 1\n        t_idx += 1\n      } else {\n        return false;\n      }\n    }\n    true\n  }\n\n  def canArray(s: Array[Char], t: Array[Char]) = {\n    countFrequency(s).zip(countFrequency(t)).filter(p => (p._1 == p._2)).size == 26\n  }\n\n  def countFrequency(s: Array[Char]) = {\n    val cnt = Array.ofDim[Int](26)\n    s.foreach(c => {\n      cnt(c - 'a') += 1\n    })\n    cnt\n  }\n}\n", "src_uid": "edb9d51e009a59a340d7d589bb335c14"}
{"source_code": "object Candies306A  extends App {\n    import java.io.{InputStream, PrintStream}\n    import java.util.Scanner\n    solve(System.in,System.out)\n    def solve(in: InputStream, out: PrintStream): Unit = {\n        val scanner = new Scanner(in)\n      val n = scanner.nextInt()\n      val m = scanner.nextInt()\n      val minK = n/m\n      val b = n-minK*m\n      val a = m - b\n      val result = Seq((a,minK),(b,minK+1)).flatMap{case (people,numCandies) => (1 to people).map{_ => numCandies}}.mkString(\" \")\n      out.println(result)\n    }\n}", "src_uid": "0b2c1650979a9931e00ffe32a70e3c23"}
{"source_code": "import java.util.StringTokenizer\n\nimport scala.collection.mutable\n\nobject A extends App {\n  val INF = 1 << 30\n\n  var st: StringTokenizer = _\n  def read() = { st = new StringTokenizer(readLine()) }\n  def int() = st.nextToken().toInt\n  def long() = st.nextToken().toLong\n\n  var q = INF\n\n  read()\n  val a = int()\n  q = Math.min(q, a)\n  read()\n  val b = int()\n  q = Math.min(q, b / 2)\n  read()\n  val c = int()\n  q = Math.min(q, c / 4)\n\n  println(7 * q)\n\n}\n", "src_uid": "82a4a60eac90765fb62f2a77d2305c01"}
{"source_code": "import java.util.Scanner\nimport scala.language.implicitConversions\n\nobject evenodd {\n  class Lazy[A](x: => A) {\n    lazy val value = x\n    override def toString(): String = value.toString()\n  }\n  object Lazy {\n    def apply[A](x: => A) = new Lazy(x)\n    implicit def fromLazy[A](z: Lazy[A]): A = z.value\n    implicit def toLazy[A](x: => A): Lazy[A] = Lazy(x)\n  }\n  def memoize[I, O](f: I => O): I => O = new collection.mutable.HashMap[I, O]() {\n    override def apply(key: I) = getOrElseUpdate(key, f(key))\n  }\n\n  def main(args: Array[String]): Unit = {\n    val sc = new Scanner(System.in)\n\n    val N = sc.nextInt();\n\n    if (N % 2 == 0) println(\"Mahmoud\");\n    else println(\"Ehab\");\n  }\n}", "src_uid": "5e74750f44142624e6da41d4b35beb9a"}
{"source_code": "import scala.io.StdIn._\n\nobject Solution {\n  def main(args: Array[String]): Unit = {\n    val Array(n, m) = readLine.split(\" \").map(_.toInt)\n    val list = readLine.toList.dropWhile(c => c != 'G' && c != 'T').reverse.dropWhile(c => c != 'G' && c != 'T').grouped(m).toList\n    if (\"GT\".contains(list.head.head) && \"GT\".contains(list.last.head) && list.size > 1 && list.forall(seq => seq.head != '#')) {\n      println(\"YES\")\n    } else {\n      println(\"NO\")\n    }\n  }\n}\n", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41"}
{"source_code": "object CF0058A extends App {\n\n  val str = readLine()\n\n  if (str.matches(\".*h{1,}.*e{1,}.*l{1,}.*l{1,}.*o{1,}.*\")) {\n    println(\"YES\")\n  } else {\n    println(\"NO\")\n  }\n\n}\n", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838"}
{"source_code": "object Main {\n  def main(args: Array[String]) {\n    val s = readLine\n    if (s.count(_.isLower) >= (s.size + 1) / 2) println(s.toLowerCase)\n    else println(s.toUpperCase)\n  }\n}", "src_uid": "b432dfa66bae2b542342f0b42c0a2598"}
{"source_code": "object Try1 {\n  def main(args: Array[String]) {\n    var n, i, m: Int = 0\n    n = readInt()\n    val line = Console.readLine()\n    for (i <- 1 to n - 1) {\n      if (line {\n        i\n      } != line {\n        i - 1\n      })\n        m += 1\n    }\n    m %= 2\n    if (line {\n      0\n    } == 'S' && m == 1)\n      println(\"YES\")\n    else println(\"NO\")\n  }\n}\n", "src_uid": "ab8a2070ea758d118b3c09ee165d9517"}
{"source_code": "\nobject Main{\n  def main(args: Array[String]) {\n    val n = readInt()\n    val a = readLine().split(\" \").map(_.toInt)\n\n    var c = new Array[Int](101)\n\n    for(x <- a){\n      c(x) += 1\n    }\n\n    println(c.max)\n  }\n}", "src_uid": "f30329023e84b4c50b1b118dc98ae73c"}
{"source_code": "import scala.collection.mutable._\nimport scala.math._\nimport scala.util.control.Breaks.break\nimport scala.util.control.Breaks.breakable\nimport java.util._\nobject Main extends App {\n  val sc = new Scanner(System.in)\n  val s = readLine\n  val t = readLine\n  val n = max(abs(s(0)-t(0)), abs(s(1)-t(1)))\n  val dx = Array[Int](0,1,1,1,0,-1,-1,-1)\n  val dy = Array[Int](1,1,0,-1,-1,-1,0,1)\n  val d = Array[String](\"U\", \"RU\", \"R\", \"RD\", \"D\", \"LD\", \"L\", \"LU\")\n  def go(s: String, t: String) {\n    if(s == t) return\n    val xx = (t(0)-s(0)) / (if(t(0)-s(0)!=0) abs(t(0)-s(0)) else 1)\n    val yy = (t(1)-s(1)) / (if(t(1)-s(1)!=0) abs(t(1)-s(1)) else 1)\n    val ss = (s(0) + xx).toChar +\"\"+ (s(1) + yy).toChar\n    for(i <- 0 until 8) {\n      if(dx(i) == xx && dy(i) == yy) {\n        println(d(i))\n        go(ss, t)\n      }\n    }\n  }\n  println(n)\n  go(s,t)\n}\n", "src_uid": "d25d454702b7755297a7a8e1f6f36ab9"}
{"source_code": "object B extends App {\n  val n = scala.io.StdIn.readInt()\n\n  var t = 0\n  for (a <- 1 to n)\n    for (b <- a to n) {\n      val c = a ^ b\n      if (c >= b && c <= n && a + b > c && a + c > b && c + b > a) t = t + 1\n    }\n\n  println(t)\n}\n", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d"}
{"source_code": "\nimport scala.io.StdIn.readLine\nimport scala.io.StdIn.readInt\n\n\nobject DreamoonStairs {\n  \n   def readInts() : Array[Int] =\n     readLine.split(' ').map(_.toInt)\n   \n   def readLongs() : Array[Long] = \n      readLine.split(' ').map(_.toLong)\n   \n   def readTuple() : (Int,Int) = {\n     val line = readInts\n     (line(0),line(1))\n   }\n   def readTupleLong() : (Long,Long) = {\n     val line = readLongs\n     (line(0),line(1))\n   }\n   \n   def readTriple() : (Int,Int,Int) = {\n     val line = readInts\n     (line(0),line(1),line(2))\n   }\n   def readQuad() : (Int,Int,Int,Int) = {\n     val line = readInts\n     (line(0),line(1),line(2),line(3))\n   }\n   \n   \n   def solve(twos: Int, ones: Int, m: Int) : Int = {\n     if (twos < 0) -1 \n     else {\n       if ((twos+ones)%m == 0) twos + ones\n       else solve(twos-1,ones+2,m)\n     }\n   }\n   \n                         \n   def main(args: Array[String]) {\n     val (n,m) = readTuple\n     println(solve(n/2, if (n%2==0) 0 else 1,m))              \n   }\n  \n}", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f"}
{"source_code": "import java.io._\nimport java.util.ArrayList\nimport java.util.StringTokenizer\n\nobject B_328s {\n\n  def main(args: Array[String]): Unit = {\n    var debugV = false\n    def db(x: => String) = if (debugV)  println(x) // nullary function\n    \n    val is = System.in\n    \n    //COMMENT ME !\n//    val is = new ByteArrayInputStream(sa1.trim.getBytes(\"ISO-8859-1\"))\n//    debugV = true\n\n    val bis = new BufferedInputStream(is);\n    val br = new BufferedReader(new InputStreamReader(bis));\n    \n    //---------------------------- parameters reading ------------------------------------\n    val line1 = new StringTokenizer(br.readLine())\n    val n = line1.nextToken().toInt\n    \n    //---------------------------- parameters reading end --------------------------------\n    \n    var res = 1l\n    var counter = 1l\n    if (n == 3) {\n    } else {\n      while (counter <= n) {\n        if (counter == 1 || counter == 2 || counter == 3) {\n          res += n-3\n        } else {\n          res += n-4\n        }\n        counter += 1\n      }\n    }\n     \n    println(res)\n    \n    \n  }\n\n}", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b"}
{"source_code": "// codeforces problem 55 B Sma\n\nobject SmallNums extends App {\n\n  def readNums(): List[Long] = {\n    val line = Console.readLine()\n    val ss = line.split(\" \")\n    val ls: List[String] = ss toList;\n    ls map (s => s.toLong)\n  }\n\n  def str2op(s: String): Op = s match {\n    case \"+\" => new Add\n    case \"*\" => new Mul\n    case _ => throw new Error(\"Illegal operation \" + s)\n  }\n\n  def readOps(): List[Op] = {\n    val ss = Console.readLine().split(\" \")\n    val ls: List[String] = ss toList;\n    ls map str2op\n  }\n\n  def allPairs(n: Int): List[(Int, Int)] = {\n    val sq = for {\n      i <- Range(1, n)\n      j <- Range(0, i)\n    } yield (j, i)\n    sq toList\n  }\n\n  def removeA[T](l: List[T], a: Int): List[T] =\n    (l take a) ::: (l drop (a + 1))\n\n  def removeAB[T](l: List[T], a: Int, b: Int): List[T] =\n    removeA(removeA(l, a), (b - 1))\n\n  def minNum(nms: List[Long], ops: List[Op], pairs: List[(Int, Int)], mmin: Long): Long = pairs match {\n    case Nil => mmin\n    case (a, b) :: tl => {\n      val r = ops.head.apply(nms(a), nms(b))\n      val n1 = (nms length) - 1\n      if (n1 == 1) {\n        r\n      } else {\n        val mn = minNum(r :: removeAB(nms, a, b), ops.tail, allPairs(n1), Long.MaxValue)\n        val min1 = if (mn < mmin) mn else mmin\n        minNum(nms, ops, tl, min1)\n      }\n    }\n  }\n\n  val nums = readNums()\n  val ops = readOps\n  val n = 4\n  val minv = minNum(nums, ops, allPairs(n), Long.MaxValue)\n  Console.println(minv)\n}\n\nabstract class Op {\n  def apply(a: Long, b: Long): Long\n}\ncase class Add extends Op {\n  def apply(a: Long, b: Long) = a + b\n}\ncase class Mul extends Op {\n  def apply(a: Long, b: Long) = a * b\n}", "src_uid": "7a66fae63d9b27e444d84447012e484c"}
{"source_code": "import java.io._\nimport java.util.StringTokenizer\n\nobject A {\n\n  var out: PrintWriter = null\n  var br: BufferedReader = null\n  var st: StringTokenizer = null\n\n  def main(args: Array[String]): Unit = {\n    br = new BufferedReader(new InputStreamReader(System.in))\n    out = new PrintWriter(new BufferedOutputStream(System.out))\n    solve\n    out.close\n  }\n\n  def next: String = {\n    while (st == null || !st.hasMoreTokens) {\n      st = new StringTokenizer(br.readLine)\n    }\n    return st.nextToken\n  }\n\n  def nextInt: Int = return Integer.parseInt(next)\n\n  def nextLong: Long = return java.lang.Long.parseLong(next)\n\n  def nextDouble: Double = return java.lang.Double.parseDouble(next)\n\n  def solve: Int = {\n    val n = nextInt\n    val t = nextInt\n    if (t == 10) {\n      if (n == 1) {\n        out.println(-1)\n      } else {\n        for (i <- 0 until n - 1) {\n          out.print(1)\n        }\n        out.println(0)\n      }\n    } else {\n      for (i <- 0 until n) {\n        out.print(t)\n      }\n    }\n    return 0\n  }\n}\n", "src_uid": "77ffc1e38c32087f98ab5b3cb11cd2ed"}
{"source_code": "object Main {\n  def main(args: Array[String]): Unit = {\n    val s = new Main()\n    s.solve()\n    s.out.flush()\n  }\n}\n\nclass Main {\n  import java.io._\n  import java.util.StringTokenizer\n  import java.util.Arrays\n\n  import scala.collection.mutable\n  import scala.util.Sorting\n  import math.{abs, max, min}\n  import mutable.{ArrayBuffer, ListBuffer}\n  import scala.reflect.ClassTag\n\n  val MOD = 1000000007\n  val out = new PrintWriter(System.out)\n\n  def solve(): Unit = {\n    val N = ni()\n    var ans = 0L\n    REP(N - 2) { i =>\n      ans += (i + 2) * (i + 3)\n    }\n    out.println(ans)\n  }\n\n  private val oj = System.getenv(\"ATCODER_DEBUG\") == null\n\n  def DEBUG(f: => Unit): Unit = {\n    if (!oj){ f }\n  }\n\n  def debug(as: Array[Boolean]): Unit = DEBUG {\n    debug(as.map(x => if(x) \"1\" else \"0\").mkString)\n  }\n\n  def debug(as: Array[Int]): Unit = DEBUG {\n    debug(as.mkString(\" \"))\n  }\n\n  def debug(as: Array[Long]): Unit = DEBUG {\n    debug(as.mkString(\" \"))\n  }\n\n  def debug(s: => String): Unit = DEBUG {\n    System.err.println(s)\n  }\n\n  def debugL(num: => Long): Unit = DEBUG {\n    System.err.println(num)\n  }\n\n  class InputReader(val stream: InputStream) {\n    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n    private var tokenizer: StringTokenizer = _\n\n    def next(): String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new StringTokenizer(reader.readLine)\n      tokenizer.nextToken\n    }\n\n    def nextInt(): Int = next().toInt\n    def nextLong(): Long = next().toLong\n    def nextChar(): Char = next().charAt(0)\n  }\n  val sc = new InputReader(System.in)\n  def ni(): Int = sc.nextInt()\n  def nl(): Long = sc.nextLong()\n  def nc(): Char = sc.nextChar()\n  def ns(): String = sc.next()\n  def ns(n: Int): Array[Char] = ns().toCharArray\n  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)\n  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {\n    val A1, A2 = Array.ofDim[Int](n)\n    REP(n) { i =>\n      A1(i) = ni() + offset\n      A2(i) = ni() + offset\n    }\n    (A1, A2)\n  }\n  def nm(n: Int, m: Int): Array[Array[Int]] = {\n    val A = Array.ofDim[Int](n, m)\n    REP(n) { i =>\n      REP(m) { j =>\n        A(i)(j) = ni()\n      }\n    }\n    A\n  }\n  def nal(n: Int): Array[Long] = map(n)(_ => nl())\n  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))\n  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = offset\n    val N = n + offset\n    while(i < N) { f(i); i += 1 }\n  }\n  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = n - 1 + offset\n    while(i >= offset) { f(i); i -= 1 }\n  }\n  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {\n    REP(to - from + 1, from) { i =>\n      f(i)\n    }\n  }\n\n  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {\n    val res = Array.ofDim[A](n)\n    REP(n)(i => res(i) = f(i + offset))\n    res\n  }\n\n\n  def sumL(as: Array[Int]): Long = {\n    var s = 0L\n    REP(as.length)(i => s += as(i))\n    s\n  }\n\n  def cumSum(as: Array[Int]) = {\n    val cum = Array.ofDim[Long](as.length + 1)\n    REP(as.length) { i =>\n      cum(i + 1) = cum(i) + as(i)\n    }\n    cum\n  }\n}\n", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a"}
{"source_code": "import scala.io.StdIn\nimport scala.math.pow\n\nobject Main {\n  def main(args: Array[String]): Unit = {\n    println(rec(readLong, 1000000000, 9))\n  }\n\n  @annotation.tailrec\n  final def rec(n: Long, x: Long, power: Int, sum: Int = 0): Int = {\n    if(power == -1) return sum\n\n    var newSum = sum\n    var newN = n\n\n    if(n == x) newSum += 1\n    if(n > x) {\n      newN -= x\n      newSum += pow(2, power).toInt\n    }\n\n    rec(newN, x / 10, power - 1, newSum)\n  }\n}\n", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb"}
{"source_code": "import java.util.Scanner\n\nobject Main{\n  def main (args: Array[String]){\n    val sc = new Scanner(System.in)\n    val n = sc.nextInt()\n\n    var a = n / 2\n\n    if (a % 2 == 0)\n      a -= 1\n\n    if (n % 2 == 1)\n      println(0)\n    else println(a / 2)\n  }\n}\n", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37"}
{"source_code": "object Solution extends App {\n  val in = scala.io.Source.stdin.getLines()\n  val Array(d, sumTime) = in.next().split(\" \").map(_.toInt)\n  val data = (1 to d).map(_ => in.next().split(\" \").map(_.toInt))\n  val min = data.map(_.head)\n  val max = data.map(_.last)\n  var leftTime = sumTime - min.sum\n  if (sumTime < min.sum || sumTime > max.sum)\n    println(\"NO\")\n  else {\n    val r = data.map{ t =>\n      val q = t.head + Math.min(leftTime, t.last - t.head)\n      leftTime += t.head - q\n      q\n    }\n    println(\"YES\")\n    println(r.mkString(\" \"))\n  }\n}", "src_uid": "f48ff06e65b70f49eee3d7cba5a6aed0"}
{"source_code": "object A extends App {\n\n  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }\n  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }\n\n  val a = readLine\n  val s = readLine\n\n  val x = s.groupBy(identity)\n  val max = x.values.exists(_.size > 1)\n\n  println(if (max || s.length == 1) \"Yes\" else \"No\")\n}\n", "src_uid": "6b22e93f7e429693dcfe3c099346dcda"}
{"source_code": "import java.util.Scanner\n\nobject Solution {\n  def main(args: Array[String]): Unit = {\n\n    val scanner = new Scanner(System.in)\n    val n = scanner.nextInt()\n\n    var result = false\n    for (number <- 0 to n / 2 if !result) {\n      if (isCorrect(number) && isCorrect(n - number))\n        result = true\n    }\n\n    println(if (result) \"YES\" else \"NO\")\n\n    def isCorrect(number: Int): Boolean = number match {\n      case n: Int if n <= 0 => false;\n      case n: Int => n % 2 == 0\n    }\n  }\n}", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2"}
{"source_code": "import java.util.Scanner\n\nobject A2 {\n\n  def solution (x:Int, y:Int) : Int = {\n    val a = (1 to x).scan(0)(_ + _)\n    var c = y\n    if (c>=a.last) c%=a.last\n    if (c > 0)\n      c - (a.takeWhile(_ <= c).last)\n    else\n      0\n  }\n\n  def main(args: Array[String]): Unit = {\n    val reader = new Scanner(System.in)\n    println(solution(reader.nextInt(),reader.nextInt()))\n  }\n}\n", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb"}
{"source_code": "\n\nimport java.io._\nimport java.util.ArrayList\nimport java.util.StringTokenizer\n//import java.math.BigDecimal\n\nobject Bitz_D {  \n  \n  def main(args: Array[String]): Unit = {\n\n    //COMMENT ME !\n//    is = new ByteArrayInputStream(Test.sa1.trim.getBytes(\"ISO-8859-1\"))\n//    debugV = true\n\n\n    //---------------------------- parameters reading --------------------------\n    br = setupInputOutput(); \n    val line1 = readLine\n    val n = line1.long\n\n    var res = (n*(n+1)) /2 \n    res = res * 6 + 1\n    println(res)\n    \n  \n    \n    //---------------------------- parameters reading end ----------------------\n\n  }\n\n  \n  //---------------------------- service code ----------------------------------\n\n  \n  def readLine() = new Line  \n  class Line {\n    val tok = new StringTokenizer(br.readLine(), \" \")\n    def int = tok.nextToken().toInt\n    def long = tok.nextToken().toLong\n    def double = tok.nextToken().toDouble\n    def string = tok.nextToken()\n  }\n  \n  var debugV = false\n  var is = System.in\n  var br = setupInputOutput();  \n  def db(x: => String) = if (debugV) println(x) // nullary function\n  def setupInputOutput(): BufferedReader = {\n    val devEnv = this.getClass.getCanonicalName.contains(\".\")\n    if (!devEnv) {\n      is = System.in\n      debugV = false\n    }\n    val bis = new BufferedInputStream(is);\n    new BufferedReader(new InputStreamReader(bis));\n  }\n  \n//============================================================================================\nobject Test {\n  \nval sa1 = \"\"\"\n1000 1000000\n\"\"\"\n\n}\n\n}\n", "src_uid": "c046895a90f2e1381a7c1867020453bd"}
{"source_code": "object A670 {\n\n  import IO._\n\n  def main(args: Array[String]): Unit = {\n    val Array(n) = readInts(1)\n    if(n%7 == 1) {\n      println(s\"${2*(n/7)} ${2*(n/7) + 1}\")\n    } else if(n%7 == 6) {\n      println(s\"${2*(n/7) + 1} ${2*(n/7) + 2}\")\n    } else if(n%7 == 0) {\n      println(s\"${2 * (n/7)} ${2*(n/7)}\")\n    } else {\n      println(s\"${2 * (n/7)} ${2 * (n/7) + 2}\")\n    }\n  }\n\n  object IO {\n    @inline def read: String = scala.io.StdIn.readLine\n\n    @inline def tokenizeLine = new java.util.StringTokenizer(read)\n\n    def readInts(n: Int): Array[Int] = {\n      val tl = tokenizeLine;\n      Array.fill(n)(tl.nextToken.toInt)\n    }\n\n    def readLongs(n: Int): Array[Long] = {\n      val tl = tokenizeLine;\n      Array.fill(n)(tl.nextToken.toLong)\n    }\n\n    def readBigs(n: Int): Array[BigInt] = {\n      val tl = tokenizeLine;\n      Array.fill(n)(BigInt(tl.nextToken))\n    }\n  }\n\n}\n", "src_uid": "8152daefb04dfa3e1a53f0a501544c35"}
{"source_code": "object A {\n  def main(args: Array[String]){\n    val line1 = readLine().split(\":\")\n    val line2 = readLine().split(\":\")\n    val h1 = line1(0).toInt\n    val m1 = line1(1).toInt\n    val h2 = line2(0).toInt\n    val m2 = line2(1).toInt\n\n    val difHour = h2 - h1\n    val difMin = m2 - m1 + (difHour * 60)\n    val halfMin = difMin / 2\n    val addHour = halfMin / 60\n    val addMin = halfMin % 60\n\n    var resHour = h1 + addHour\n    var resMin = m1 + addMin\n    if (resMin >= 60) {\n      resHour += 1\n      resMin -= 60\n    }\n\n    println(\"%02d:%02d\".format(resHour, resMin))\n  }\n}\n", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50"}
{"source_code": "//package eduround61\n\nimport scala.io.StdIn\n\nobject TaskF extends App {\n  val n = StdIn.readInt()\n  val s = StdIn.readLine()\n  var dp = Array.ofDim[Int](n, n)\n  for {\n    i <- 0 until n\n    j <- 0 until n\n  } dp(i)(j) = -1\n\n  println(rec(0, n-1))\n\n  def rec(l: Int, r: Int): Int = {\n    if (dp(l)(r) != -1)\n      return dp(l)(r)\n    if (l > r) {\n      return 0\n    }\n    if (l == r) {\n      return 1\n    }\n    var res = 1 + rec(l+1, r)\n    for (i <- l+1 to r if s(i) == s(l)) {\n      res = Math.min(res, rec(l+1, i-1) + rec(i, r))\n    }\n    dp(l)(r) = res\n    res\n  }\n\n}\n", "src_uid": "516a89f4d1ae867fc1151becd92471e6"}
{"source_code": "//package solutions\n\nimport java.io.PrintWriter\nimport java.util.Scanner\n\nimport scala.util.control.Breaks\n\n/**\n  * @author traff\n  */\n\n\nobject SolTaskA extends App {\n  override def main(args: Array[String]): Unit = {\n    val out = new PrintWriter(System.out)\n\n    run(new Scanner(System.in), out)\n\n    out.close()\n  }\n\n  def run(s: Scanner, out: PrintWriter): Unit = {\n\n    val n = s.nextLine().toInt\n\n    val a = s.nextLine().split(\" \").map(_.toInt)\n    val b = s.nextLine().split(\" \").map(_.toInt)\n\n    var cnt1 = a.foldLeft(Array.fill(5)(0))((a, x) => {\n      a(x - 1) += 1\n      a\n    })\n\n\n    var cnt2 = b.foldLeft(Array.fill(5)(0))((a, x) => {\n      a(x - 1) += 1\n      a\n    })\n\n\n    Breaks.breakable {\n      val d = cnt1.zip(cnt2).foldLeft(0)((c, t) => {\n        val d = math.abs(t._1 - t._2)\n        if (d % 2 != 0) {\n          out.println(-1)\n          Breaks.break()\n        }\n        c + d / 2\n      })\n\n      out.println(if (d % 2 == 0) d / 2 else -1)\n    }\n  }\n\n}\n", "src_uid": "47da1dd95cd015acb8c7fd6ae5ec22a3"}
{"source_code": "object Main\n{\n\tdef cmp (s1 : Array[Char], s2 : Array[Char]) : Boolean =\n\t{\n\t\tfor (i <- 0 until s1.size)\n\t\t\tif (s1(i) != s2(i)) return false\n\t\treturn true\n\t}\n\n\tdef add (s : String, a : Char) : String =\n\t{\n\t\tvar s2 = new Array[Char](s.size+2)\n\t\tfor (i <- 0 until s.size)\n\t\t\ts2(i) = s(i)\n\t\ts2(s.size) = a\n\n\t\tprintln(\"\")\n\t\tprint (\"Ja izgradi nizata: \")\n\t\tfor (i <- 0 until s2.size)\n\t\t\tprint(s2(i))\n\t\tprintln(\"\")\n\n\t\ts2.toString\n\t}\n\n\tdef main (args : Array[String]) =\n\t{\n\t\tval m = scala.io.StdIn.readInt\n\n\t\tval mat = Array.ofDim[Int](10,10)\n\t\tfor (i <- 0 to 6)\n\t\t\tfor (j <- 0 to 6)\n\t\t\t\tmat(i)(j) = 0\n\n\t\t//println(\"pomina\")\n\n\t\tfor (i <- 0 until m)\n\t\t{\n\t\t\tvar a_b = scala.io.StdIn.readLine.split(' ').map(_.toInt)\n\t\t\tvar a = a_b(0)\n\t\t\tvar b = a_b(1)\n\t\t\tmat(a)(b) = 1\n\t\t\tmat(b)(a) = 1\n\t\t}\n\n\t\tvar flag = false\n\n\t\tfor (i <- 1 to 5)\n\t\t\tfor (j <- 1 to 5)\n\t\t\t\tfor (k <- 1 to 5)\n\t\t\t\t\tif (i != j && i != k && j != k)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (mat(i)(j) == 1 && mat(i)(k) == 1 && mat(j)(k) == 1)\n\t\t\t\t\t\t\tflag = true\n\t\t\t\t\t\tif (mat(i)(j) == 0 && mat(i)(k) == 0 && mat(j)(k) == 0)\n\t\t\t\t\t\t\tflag = true\n\t\t\t\t\t}\n\n\t\tif (flag == true)\n\t\t\tprintln(\"WIN\")\n\t\telse\n\t\t\tprintln(\"FAIL\")\n\n\t}\n}", "src_uid": "2bc18799c85ecaba87564a86a94e0322"}
{"source_code": "object Solution {\n\n  def main(args: Array[String]): Unit = {\n\n    val in: Iterator[String] = io.Source.stdin.getLines()\n    val n = in.next().toInt\n    val s = in.next()\n\n    var res = Int.MaxValue\n\n    val q = s.sliding(4).toList\n      q.foreach { current =>\n      val Array (a, b, c, d) = current.toArray.map(_ - 'A')\n      val aa = changes(a, 'A' - 'A')\n      val bb = changes(b, 'C' - 'A')\n      val cc = changes(c, 'T' - 'A')\n      val dd = changes(d, 'G' - 'A')\n      res = Math.min(res, aa + bb + cc + dd)\n    }\n\n    println(res)\n  }\n\n  def changes(source: Int, target: Int) = {\n    Math.min(Math.min(Math.abs(target - source), target + 26 - source), source + 26 - target)\n  }\n\n\n\n}", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543"}
{"source_code": "\n/**\n  * Created by MZKL7315 on 4/18/2016.\n  */\nobject Main {\n\n  def main(args: Array[String]) = {\n    val in = scala.io.Source.stdin.getLines()\n    val l = in.next().split(' ').toList\n    if (l(0).equals(l(1))) println(l(0))\n    else println(1)\n  }\n}\n", "src_uid": "9c5b6d8a20414d160069010b2965b896"}
{"source_code": "object P75A extends App{\n    val (a,b) = (readLine,readLine)\n    def r(s:String) = s.replace(\"0\",\"\").toInt\n    println(if(Array(a,b).map(r).sum == r((a.toInt + b.toInt).toString())) \"YES\" else \"NO\")\n}\n", "src_uid": "ac6971f4feea0662d82da8e0862031ad"}
{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n  val in = Source.stdin.getLines()\n  val Array(a, b) = in.next().split(' ').map(_.toInt)\n  println(a + b - (if ((a - b) % 3 == 0 && a * b != 1) 3 else 2))\n}\n", "src_uid": "ba0f9f5f0ad4786b9274c829be587961"}
{"source_code": "import java.io._\nimport java.util\nimport java.util._\n\nobject A {\n\n  var out: PrintWriter = null\n  var br: BufferedReader = null\n  var st: StringTokenizer = null\n\n  def next: String = {\n    while (st == null || !st.hasMoreTokens) {\n      st = new StringTokenizer(br.readLine)\n    }\n    return st.nextToken\n  }\n\n  def nextInt: Int = {\n    return Integer.parseInt(next)\n  }\n\n  def nextLong: Long = {\n    return java.lang.Long.parseLong(next)\n  }\n\n  def solve: Int = {\n    val s = next\n    val t = next\n    val len = s.size\n    val s1 = s.toCharArray\n    var i = len - 1\n    while (i >= 0 && s(i) == 'z') {\n      s1(i) = 'a'\n      i -= 1\n    }\n    s1(i) = (s1(i) + 1).toChar\n    val res = new String(s1)\n    if (res > s && res < t) {\n      out.println(res)\n      return 1\n    }\n    out.println(\"No such string\")\n    return 1\n  }\n\n  def main(args: Array[String]): Unit = {\n    br = new BufferedReader(new InputStreamReader(System.in))\n    out = new PrintWriter(new BufferedOutputStream(System.out))\n    solve\n    out.close\n  }\n}\n", "src_uid": "47618510d2a17b1cc1e6a688201d51a3"}
{"source_code": "object A extends App {\n  val vs = List('a', 'e', 'u', 'i', 'o', '1', '3', '5', '7', '9')\n  val s = scala.io.StdIn.readLine()\n  println(s.filter(vs.contains).length)\n}\n", "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223"}
{"source_code": "object Main {\n    def main(args: Array[String]): Unit = {\n        val n = readLong\n        if (n == 1) println(\"1 1\")\n        else {\n        val plist = f1(n)\n        //println(plist)\n        val compV = plist.foldLeft(Vector[(Long, Long)]((1L, 1L))){\n            case (l, x) => l.map{case (i, j) => (i * x, j)} ++ l.map{case (i, j) => (i, j * x)}\n        }\n        //println(compV)\n        val (am, bm) = compV match {\n            case (a, b) +: rest => rest.foldLeft((a, b)){\n                case ((am, bm), (x, y)) => if (math.max(am, bm) > math.max(x, y)) (x, y) else (am, bm)\n            }\n        }\n        println(am.toString + \" \" + bm.toString)\n       }\n    }\n\n    def f1(n: Long): List[Long] = {\n        val (ps, np) = (2 to (math.sqrt(n.toDouble) + 1).toInt).foldLeft((List[Long](), n)){\n            case ((ls, n), i) => if (n % i == 0) {\n                val (is, ni) = f2(n, i)\n                (ls :+ is, ni)\n            } else (ls, n)\n        }\n        if (np == 1L) ps else ps :+ np\n    }\n\n    def f2(n: Long, i: Long): (Long, Long) = {\n        def aux(n: Long, i: Long, t: Long): (Long, Long) = if (n % i != 0) (t, n) else aux(n / i, i, t * i)\n        aux(n, i, 1L)\n    }\n}", "src_uid": "e504a04cefef3da093573f9df711bcea"}
{"source_code": "import java.util.Scanner\n\nobject MainB extends App {\n  val sc = new Scanner(System.in)\n\n  def conv(n: Int): List[Int] = {\n    def inner(n: Int): List[Int] = {\n      if (n < 3) n :: Nil\n      else (n % 3) :: inner(n / 3)\n    }\n\n    inner(n).reverse\n  }\n\n  def sum(a: List[Int], b: List[Int]): List[Int] = {\n    val la = List.make(a.size.max(b.size) - a.size, 0) ++ a\n    val lb = List.make(a.size.max(b.size) - b.size, 0) ++ b\n\n    val res = for (d <- la zip lb) yield (d._1 + d._2) % 3\n    res\n  }\n\n  def diff(a: List[Int], c: List[Int]): List[Int] = {\n    val la = List.make(a.size.max(c.size) - a.size, 0) ++ a\n    val lc = List.make(a.size.max(c.size) - c.size, 0) ++ c\n\n    for(d <- la zip lc) yield (d._2 - d._1 + 3) % 3\n  }\n\n  def rest(l: List[Int]): String = {\n    val s = for (i <- l.reverse zip Stream.from(0)) yield i._1 * (Math.pow(3, i._2)).toInt\n    s.sum.toString()\n  }\n\n  val a = sc.nextInt()\n  val c = sc.nextInt()\n  val ca = conv(a)\n  val cc = conv(c)\n\n  println(rest(diff(ca, cc)))\n}", "src_uid": "5fb635d52ddccf6a4d5103805da02a88"}
{"source_code": "object Round213_Div2_Task4 {\n  /**\n   * <a href=\"http://codeforces.com/contest/365/problem/C\">Contest 213, Div 2, problem C</a>\n   *\n   * John Doe has recently found a \"Free Market\" in his city \u2014 that is the\n   * place where you can exchange some of your possessions for other things\n   * for free.\n   *\n   * John knows that his city has n items in total (each item is\n   * unique). You can bring any number of items to the market and exchange\n   * them for any other one. Note that each item is one of a kind and that\n   * means that you cannot exchange set {a,\u2009b} for set {v,\u2009a}. However, you\n   * can always exchange set x for any set y, unless there is item p, such\n   * that p occurs in x and p occurs in y.\n   *\n   * For each item, John knows its value ci. John's sense of justice\n   * doesn't let him exchange a set of items x for a set of items y, if\n   * s(x)\u2009+\u2009d\u2009<\u2009s(y) (s(x) is the total price of items in the set x).\n   *\n   * During one day John can exchange only one set of items for something\n   * else. Initially, he has no items. John wants to get a set of items\n   * with the maximum total price. Find the cost of such set and the\n   * minimum number of days John can get it in.\n   *\n   * Input The first line contains two space-separated integers n, d\n   * (1\u2009\u2264\u2009n\u2009\u2264\u200950, 1\u2009\u2264\u2009d\u2009\u2264\u2009104) \u2014 the number of items on the market and\n   * John's sense of justice value, correspondingly. The second line\n   * contains n space-separated integers ci (1\u2009\u2264\u2009ci\u2009\u2264\u2009104).\n   *\n   * Output Print two space-separated integers: the maximum possible price\n   * in the set of items John can get and the minimum number of days needed\n   * to get such set.\n   */\n\n  val inputStreamReader = {\n    import java.net.InetAddress\n    import java.security.MessageDigest\n    import java.io.{ FileInputStream, InputStreamReader, BufferedReader }\n\n    val md = MessageDigest.getInstance(\"SHA-1\")\n    val userName = System.getProperty(\"user.name\")\n    val hostName = InetAddress.getLocalHost.getHostName\n\n    val bytes = md.digest((userName + hostName).getBytes)\n    val sb = new StringBuilder\n    for (i \u2190 0 until bytes.length)\n      sb.append(Integer.toString((bytes(i) & 0xff) + 0x100, 16).substring(1))\n\n    val inputStream =\n      if (sb.result == \"51a302f8ba1abe181e33fe86c0ab4c7bedfb6c91\") new FileInputStream(\"tmp/0.txt\")\n      else System.in\n    new BufferedReader(new InputStreamReader(inputStream))\n  }\n\n  def main(args: Array[String]): Unit = {\n    import java.util.StringTokenizer\n\n    val (n, d) = {\n      val st = new StringTokenizer(inputStreamReader.readLine)\n      (st.nextToken.toInt, st.nextToken.toInt)\n    }\n\n    val costs = {\n      val r = Array.fill(n)(0)\n      val st = new StringTokenizer(inputStreamReader.readLine)\n      for (i \u2190 0 until n) r(i) = st.nextToken().toInt\n      r\n    }\n    val sum = costs.sum\n    val dp = Array.fill(n + 1)(Array.fill(sum + 1)(false))\n    for (i \u2190 0 until n) dp(i)(0) = true\n\n    for {\n      n_i \u2190 1 to n\n      sum_i \u2190 1 to sum\n    } {\n      dp(n_i)(sum_i) = dp(n_i - 1)(sum_i)\n      if (costs(n_i - 1) <= sum_i) dp(n_i)(sum_i) |= dp(n_i - 1)(sum_i - costs(n_i - 1))\n    }\n\n    var cur = 0\n    var steps = 0\n    var found = true\n    while (found) {\n      found = false\n      for {\n        i \u2190 Math.min(cur + d, sum) until cur by -1\n        j \u2190 1 to n\n        if !found && dp(j)(i)\n      } {\n        found = true\n        cur = i\n        steps += 1\n      }\n    }\n    println(s\"$cur $steps\")\n  }\n}", "src_uid": "65699ddec8d0db2f58b83a0f64de6f6f"}
{"source_code": "import java.io._\nimport java.util._\n\nobject D {\n\n  var out: PrintWriter = null\n  var br: BufferedReader = null\n  var st: StringTokenizer = null\n\n  def next: String = {\n    while (st == null || !st.hasMoreTokens) {\n      st = new StringTokenizer(br.readLine)\n    }\n    return st.nextToken\n  }\n\n  def nextInt: Int = {\n    return Integer.parseInt(next)\n  }\n\n  def nextLong: Long = {\n    return java.lang.Long.parseLong(next)\n  }\n\n  def nextDouble: Double = {\n    return java.lang.Double.parseDouble(next)\n  }\n\n  def solve: Int = {\n    val n = nextInt\n    val p = nextDouble\n    val t = nextInt\n    val dp = new Array[Array[Double]](n + 1)\n    for (i <- 0 to n) {\n      dp(i) = new Array[Double](t + 1)\n    }\n    dp(0)(0) = 1.0d\n    for (i <- 1 to t) {\n      dp(0)(i) = dp(0)(i - 1) * (1.0d - p)\n    }\n    for (i <- 1 to n) {\n      for (j <- 1 to t) {\n        dp(i)(j) += dp(i - 1)(j - 1) * p\n        if (i == n) {\n          dp(i)(j) += dp(i)(j - 1)\n        } else {\n          dp(i)(j) += dp(i)(j - 1) * (1.0d - p)\n        }\n      }\n    }\n    var ans = 0.0d\n    for (j <- 1 to n) {\n      ans += dp(j)(t) * j\n    }\n    out.println(ans)\n    return 1\n  }\n\n  def main(args: Array[String]): Unit = {\n    br = new BufferedReader(new InputStreamReader(System.in))\n    out = new PrintWriter(new BufferedOutputStream(System.out))\n    solve\n    out.close\n  }\n}\n", "src_uid": "20873b1e802c7aa0e409d9f430516c1e"}
{"source_code": "import scala.util.control.Breaks\n\nobject Main extends App {\n\n  val Array(a, b) = scala.io.StdIn.readLine.split(\" \").map(_.toInt)\n\n  //println(a);\n  var sum: Long = a;\n  var sum2: Long = b;\n  var loop = new Breaks;\n  loop.breakable {\n    for (i <- 1 to 100005) {\n      if (i % 2 == 1)\n        sum -= i;\n      else\n        sum2 -= i;\n      if (sum < 0) {\n        println(\"Vladik\");\n        loop.break();\n      }\n      if (sum2 < 0) {\n        println(\"Valera\");\n        loop.break();\n      }\n    }\n  }\n\n}\n", "src_uid": "87e37a82be7e39e433060fd8cdb03270"}
{"source_code": "object Solution82A extends App {\n\n  def aaa(n: Int): Int = {\n    def seq(n: Int, sum: Int = 0): Stream[(Int, Int)] = (n, sum) #:: seq(n * 2, sum + n)\n    val qqq = seq(5)\n    val idx = qqq.indexWhere(_._2 > n)\n    val last = qqq(idx - 1)\n    val count = last._1 / 5\n    val offset = n - last._2\n    offset / count\n  }\n\n  def solution() {\n    val names = Map(\n      0 -> \"Sheldon\",\n      1 -> \"Leonard\",\n      2 -> \"Penny\",\n      3 -> \"Rajesh\",\n      4 -> \"Howard\"\n    )\n    println(names(aaa(_int - 1)))\n  }\n\n  //////////////////////////////////////////////////\n  import java.util.Scanner\n  val SC: Scanner = new Scanner(System.in)\n  def _line: String = SC.nextLine\n  def _int: Int = SC.nextInt\n  def _long: Long = SC.nextLong\n  def _string: String = SC.next\n  solution()\n}", "src_uid": "023b169765e81d896cdc1184e5a82b22"}
{"source_code": "import scala.collection.mutable.ArrayBuffer\n\nobject Flask {\n  def check(data:ArrayBuffer[ArrayBuffer[Char]], i:Int, j: Int, n: Int, m: Int): Boolean = {\n    (data(i)(j) == 'W' && (\n    (j + 1 < m  && data(i)(j + 1) == 'P') ||\n    (j - 1 >= 0  && data(i)(j - 1) == 'P') ||\n    (i + 1 < n  && data(i + 1)(j) == 'P') ||\n    (i - 1 >= 0  && data(i - 1)(j) == 'P')))\n  }\n  \n  def main(args: Array[String]): Unit = {\n    var input = readLine.split(\" \").map(_.toInt)\n    var n = input(0); var m = input(1)\n    var data:ArrayBuffer[ArrayBuffer[Char]] = new ArrayBuffer[ArrayBuffer[Char]]()\n\n    (0 until n).foreach(i => {\n      data += new ArrayBuffer[Char]()\n      readLine.foreach(ch => data(i) += ch)\n    })\n    \n    var total = 0\n    for (i <- 0 to n - 1; j <- 0 to m - 1)\n      if (check(data, i, j, n, m))\n        total += 1\n\n    println(total)\n  }\n}\n", "src_uid": "969b24ed98d916184821b2b2f8fd3aac"}
{"source_code": "import java.util.Scanner\n\n/**\n  * Created by dr0ff on 04/03/16.\n  */\nobject InsomniaCure {\n\n  def main(args: Array[String]): Unit = {\n    val in = new Scanner(System.in)\n    val k = in.nextInt()\n    val l = in.nextInt()\n    val m = in.nextInt()\n    val n = in.nextInt()\n    val dragons = in.nextInt()\n\n    print(countPunchedDragons(dragons, k, l, m, n))\n  }\n\n  def countPunchedDragons(dragons: Int, k: Int, l: Int, m: Int, n: Int): Int = {\n    val lcmKL = lcm(k, l);\n    val lcmKM = lcm(k, m);\n    val lcmKN = lcm(k, n);\n    val lcmLM = lcm(l, m);\n    val lcmLN = lcm(l, n);\n    val lcmMN = lcm(m, n);\n\n    dragons / k +\n    dragons / l - dragons / lcmKL +\n    dragons / m - dragons / lcmKM - dragons / lcmLM +\n      dragons / lcm(lcmKM, lcmLM) +\n    dragons / n - dragons / lcmKN - dragons / lcmLN - dragons / lcmMN +\n      dragons / lcm(lcmKN, lcmLN) + dragons / lcm(lcmKN, lcmMN) + dragons / lcm(lcmLN, lcmMN) -\n      dragons / lcm(lcm(lcmKN, lcmLN), lcmMN)\n  }\n\n  /**\n    * Return greatest common divisor using Euclid's Algorithm.\n    * @param a\n    * @param b\n    * @return greates common divisor of a and b\n    */\n  def gcd(a: Int, b: Int): Int =\n    if (b > 0)\n      gcd(b, a % b)\n    else\n      a\n\n  /**\n    * Return lowest common multiple.\n    * @param a\n    * @param b\n    * @return lowest common multiple of a and b\n    */\n  def lcm(a: Int, b: Int): Int =\n    a * b / gcd(a, b)\n}\n", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7"}
{"source_code": "object A {\n  def gcd(a: Int, b: Int): Int = { if (a<b) gcd(b, a) else if (b==0) a else gcd(b,a%b) }\n  def main(args: Array[String]) {\n    val sc = new java.util.Scanner(System.in)\n    val n = sc.nextInt();\n    val in = Array.fill(n)(sc.nextInt())\n    \n    println(in.foldLeft(0)(gcd(_, _)) * n)\n  }\n}\n", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4"}
{"source_code": "\nobject A {\n  def main(args: Array[String]) = {\n    solve\n  }\n  def solve = {\n    var n = readLine().toInt\n    var ans = 0\n    for (e <- (1 to n).map(i => i * (i + 1) / 2)) {\n      if (e <= n) {\n        n -= e\n        ans += 1\n      }\n    }\n    println(ans)\n  }\n}\n", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0"}
{"source_code": "object E extends App {\n    def test(a: Double, h: Double) = a * h / 2 / math.sqrt(h * h + a * a / 4)\n    val input = readLine().toDouble\n    val tests = for {\n        i <- 1 to 10\n        j <- 1 to 10\n        if math.abs(test(i, j) - input) < 1e-6\n    } yield (i, j)\n    println(tests(0)._1 + \" \" + tests(0)._2)\n}\n", "src_uid": "879ac20ae5d3e7f1002afe907d9887df"}
{"source_code": "object C\n{\n  val mod = 1000000007L\n  \n  def main(args: Array[String])\n  {\n    val n = readLong\n    val powN = pow(2,n)\n    println(powN*(powN+1)/2%mod)\n  }\n  def pow(a: Long, b: Long): Long =\n  {\n    if(b==0) 1L\n    else if(b%2==1) (a*pow(a,b-1))%mod\n    else\n    {\n      val sqrt = pow(a,b/2)\n      (sqrt*sqrt)%mod\n    }\n  }\n}\n", "src_uid": "782b819eb0bfc86d6f96f15ac09d5085"}
{"source_code": "import scala.io.StdIn\n\nobject Test {\n  def main(args: Array[String]): Unit = {\n    StdIn.readLine\n    println(StdIn.readLine.split(' ').map(_.toInt).sorted.toList.grouped(2).toList.map{_.reduce{_ - _}}.sum.abs)\n  }\n}\n", "src_uid": "55485fe203a114374f0aae93006278d3"}
{"source_code": "import java.util.StringTokenizer\n\nimport scala.Ordering\nimport scala.collection.mutable\n\nobject C extends App {\n  val INF = 1 << 30\n  var st: StringTokenizer = _\n  def read() = { st = new StringTokenizer(readLine()) }\n  def int() = st.nextToken().toInt\n\n  read()\n  val n = int()\n\n  case class Card(id: Int, red: Boolean, rCost: Int, bCost: Int)\n  val cards: Array[Card] = (0 until n).map { k =>\n    read()\n    Card(k, st.nextToken() == \"R\", int(), int())\n  }.toArray\n\n  case class State(redCost: Int, blueCost: Int)\n  val ord = new Ordering[State] {\n    override def compare(x: State, y: State): Int = x.redCost - y.redCost\n  }\n  var states = new Array[List[State]](1 << n)\n\n  states(0) = List(State(0, 0))\n\n  (1 until (1 << n)).foreach { stateId =>\n    val intCards = cards.filter(card => ((1 << card.id) & stateId) != 0)\n    val rCards = intCards.count(_.red)\n    val bCards = intCards.length - rCards\n    val arr = mutable.ArrayBuilder.make[State]\n    intCards.foreach { card =>\n      val preState = stateId ^ (1 << card.id)\n      val redCost = Math.max(0, card.rCost - rCards + (if (card.red) 1 else 0) )\n      val blueCost = Math.max(0, card.bCost - bCards + (if (card.red) 0 else 1) )\n      states(preState).foreach { pre =>\n        arr += State(pre.redCost + redCost, pre.blueCost + blueCost)\n      }\n    }\n    val newStates = arr.result()\n    java.util.Arrays.sort(newStates, ord)\n\n    var list = List.empty[State]\n    list = newStates.reduceLeft { (last, cur) =>\n      if (last.redCost <= cur.redCost && last.blueCost <= cur.blueCost) last\n      else if (last.redCost >= cur.redCost && last.blueCost >= cur.blueCost) cur\n      else { list = last :: list; cur }\n    } :: list\n    states(stateId) = list\n  }\n\n  val finalStates = states((1<<n)-1)\n  val ans = n + finalStates.map(s => Math.max(s.redCost, s.blueCost)).min\n  println(ans)\n\n}\n", "src_uid": "25a77f2b7cb281ff3c7800a20b3e5969"}
{"source_code": "\n/**\n  * Created by octavian on 07/02/2016.\n  */\nobject Kefir {\n\n  def main(args: Array[String]) = {\n\n    //System.setIn(new FileInputStream(\"./src/kefir.in\"))\n    //System.setOut(new PrintStream(new FileOutputStream(\"./src/kefir.out\")))\n\n    val n: Long = readLong()\n    val a: Long = readLong()\n    val b: Long = readLong()\n    val c: Long = readLong()\n\n    if(a <= (b - c)) {\n      println(n/a)\n    }\n    else {\n      var used: Long = (n - b)/(b - c)\n      while(n - used*(b - c) >= b) {\n        used += 1\n      }\n      used = Math.max(used, 0)\n      used += (n - used*(b - c))/a\n      println(used)\n    }\n\n  }\n\n}\n", "src_uid": "0ee9abec69230eab25de51aef0984f8f"}
{"source_code": "object A{\n  def main(args: Array[String]){\n\n    val n =readLine.toInt\n    val a =readLine.split(\" \").toList.map(_.toInt)\n\n    val name =Array[String](\"chest\", \"biceps\", \"back\")\n    val sum =Array[Int](0,0,0)\n\n    var max=0\n    var midx=0\n    for((aa,i) <- a.zipWithIndex){\n      val ii=i%3\n      sum(ii)+=aa\n      if(max<sum(ii)){\n        max=sum(ii)\n        midx=ii;\n      }\n    }\n    \n    println(name(midx))\n  }\n}\n", "src_uid": "579021de624c072f5e0393aae762117e"}
{"source_code": "import scala.io.StdIn._\nimport scala.math._\n\nobject Incident {\n  \n  def main(args : Array[String]){\n  \n  var in=readLine.split(' ')\n  var  t=in(0).toLong\n  var  s=in(1).toLong\n  var  x=in(2).toLong\n  if(x>=t+s)\n\t{\n\tif((x-t)%s==0 || (x-1-t)%s==0)  printf(\"YES\\n\")\n\telse printf(\"NO\\n\")\n\t}\n\telse \n\t{\n\t\tif(x==t) printf(\"YES\\n\")\n\t\telse printf(\"NO\\n\")\n\t}\n}\n}", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952"}
{"source_code": "object Solution extends App {\n  val in = io.Source.stdin.getLines()\n  val n = in.next().toInt\n  val (m, s) = in.next().split(' ').map(_.toInt).foldLeft((0, 0)) {\n      case ((max, state), 0) =>\n        (max, 0)\n      case ((max, 0), 3) =>\n        (max + 1, 0)\n      case ((max, 0), el) =>\n        (max + 1, el)\n      case ((max, 1), 3) =>\n        (max + 1, 2)\n      case ((max, 2), 3) =>\n        (max + 1, 1)\n      case ((max, 2), 0) =>\n        (max + 1, 0)\n      case ((max, state), el) if state == el =>\n        (max, 0)\n      case ((max, state), el) =>\n        (max + 1, el)\n  }\n  println(n - m)\n}\n", "src_uid": "08f1ba79ced688958695a7cfcfdda035"}
{"source_code": "object Main {\n  //import java.io.{BufferedReader, InputStreamReader}\n\n  val out = new java.io.PrintWriter(System.out, false)\n  //val in = new BufferedReader(new InputStreamReader(System.in))\n\n  def nextInt(): Int = Integer.parseInt(scala.io.StdIn.readLine)\n  def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)\n  def readInts(n: Int) = { val tl = tokenizeLine; val a = new Array[Int](n); for (i <- a.indices) a(i) = Integer.parseInt(tl.nextToken); a }\n\n  def main(args: Array[String]): Unit = {\n    val n = nextInt()\n    //val Array(n) = readInts(1)\n    val (a, b) = n % 4 match {\n      case 0 => (1, 'A')\n      case 1 => (0, 'A')\n      case 2 => (1, 'B')\n      case 3 => (2, 'A')\n    }\n    out.println(s\"$a $b\")\n    out.flush()\n  }\n\n}\n", "src_uid": "488e809bd0c55531b0b47f577996627e"}
{"source_code": "object Solution extends App {\n  val in = scala.io.Source.stdin.getLines()\n\n  val data = in.next().split(' ').map(_.toLong).sorted\n  if (data.last > 2 * (data(0) + data(1)))\n    println(data(0) + data(1))\n  else {\n    println(data.sum / 3)\n\n  }\n\n}\n", "src_uid": "bae7cbcde19114451b8712d6361d2b01"}
{"source_code": "import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._\n\nobject _659A extends CodeForcesApp {\n  override def apply(io: IO) = {\n    val n, a, b = io[Int]\n    val m = (a + b) % n\n    io += (if (m <= 0) n + m else m)\n  }\n}\n/****************************[Ignore Template Below]****************************************/\ntrait CodeForcesApp {\n  lazy val isOnlineJudge: Boolean = sys.props.get(\"ONLINE_JUDGE\").exists(_.toBoolean)\n  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)\n  def apply(io: IO): io.type\n  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()\n}\nobject Utils {\n  import scala.collection.mutable, mutable.{Map => Dict}\n  implicit class GenericExtensions[A](val a: A) extends AnyVal {\n    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a\n  }\n  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {\n    def onlyElement: A = t.head.ensuring(t.size == 1)\n    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)\n    def duplicates(implicit b: C of A): C[A] = {\n      val elems = mutable.Set.empty[A]\n      (t collect {case i if !elems.add(i) => i}).to[C]\n    }\n    def sum[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}\n    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]\n    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap\n    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)\n    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}\n    def toMutableMultiSet: Dict[A, Int] = {\n      val c = map[A] to 0\n      t.foreach(i => c(i) += 1)\n      c\n    }\n    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap\n  }\n  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)\n  }\n  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {\n    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)\n  }\n  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {\n    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t\n  }\n  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {\n    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_._1).mapValues(_._2)\n    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_._1).mapValues(_.map(_._2).to[C])\n    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]\n  }\n  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {\n    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap\n    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}\n    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m\n  }\n  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {\n    def notContains(x: A): Boolean = !(s contains x)\n  }\n  implicit class LongExtensions(val x: Long) extends AnyVal {\n    def bitCount: Int = java.lang.Long.bitCount(x)\n  }\n  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {\n    import Numeric.Implicits._\n    def **(i: Int): A = if (i == 0) n.one else {\n      val h = x ** (i/2)\n      if (i%2 == 0) h * h else h * h * x\n    }\n    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)\n    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf \"Greg\" whenNegative Int.MaxValue\n  }\n  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {\n    import scala.collection.immutable.NumericRange, Integral.Implicits._\n    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x\n    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(n.min(x, y), n.max(x, y), n.one)\n  }\n  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)\n  def  asc[A](implicit order: Ordering[A]): Ordering[A] = order\n  def map[K] = new {\n    def to[V](default: V): Dict[K, V] = Dict.empty[K, V] withDefaultValue default\n  }\n  def memoize[I] = new {\n    def apply[O](f: I => O): I => O = new mutable.HashMap[I, O]() {\n      override def apply(key: I) = getOrElseUpdate(key, f(key))\n    }\n  }\n  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None\n  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)\n  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]\n  val mod: Int = (1e9 + 7).toInt\n  val newLine: String = \"\\n\"\n}\n/***********************************[Scala I/O]*********************************************/\nimport Utils._, java.io._, java.util.StringTokenizer\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends PrintWriter(out, true) with Iterator[String] {\n  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))\n  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))\n\n  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered\n\n  @inline private[this] def tokenizer() = {\n    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()\n    if (tokenizers.nonEmpty) Some(tokenizers.head) else None\n  }\n\n  def apply[A](implicit read: IO.Read[A]): A = read.apply(this)\n  def apply[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(apply).to[C]\n\n  def till(delim: String): String = tokenizer().get.nextToken(delim)\n  def tillEndOfLine(): String = till(\"\\n\\r\")\n\n  override def next() = tokenizer().get.nextToken()\n  override def hasNext = tokenizer().nonEmpty\n\n  var separator = \" \"\n  private[this] var isNewLine = true\n\n  def +=[A](x: A)(implicit write: IO.Write[A]): this.type = {\n    write(this)(x)\n    this\n  }\n  def appendNewLine(): this.type = {\n    println()\n    this\n  }\n\n  override def print(obj: String) = {\n    if (isNewLine) isNewLine = false else super.print(separator)\n    super.print(obj)\n  }\n  override def println() = if (!isNewLine) {\n    super.println()\n    isNewLine = true\n  }\n  override def close() = {\n    flush()\n    in.close()\n    super.close()\n  }\n}\nobject IO {\n  class Read[A](val apply: IO => A) {\n    def map[B](f: A => B): Read[B] = new Read(apply andThen f)\n  }\n  object Read {\n    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r[C, A](r[Int]))\n    implicit val string                                       : Read[String]       = new Read(_.next())\n    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)\n    implicit val boolean                                      : Read[Boolean]      = string.map(_.toBoolean)\n    implicit val int                                          : Read[Int]          = string.map(_.toInt)\n    implicit val long                                         : Read[Long]         = string.map(_.toLong)\n    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))\n    implicit val double                                       : Read[Double]       = string.map(_.toDouble)\n    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))\n    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r[A], r[B]))\n    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r[A], r[B], r[C]))\n    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r[A], r[B], r[C], r[D]))\n  }\n  trait Write[-A] {\n    def apply(out: PrintWriter)(x: A): Unit\n  }\n  trait DefaultWrite {\n    implicit def any[A]: Write[A] = Write(_.toString)\n  }\n  object Write extends DefaultWrite {\n    def apply[A](f: A => String) = new Write[A] {\n      override def apply(out: PrintWriter)(x: A) = out.print(f(x))\n    }\n    implicit val boolean: Write[Boolean] = Write(b => if (b) \"YES\" else \"NO\")\n    implicit def tuple2[A, B]: Write[(A, B)] = Write {case (a, b) => s\"$a $b\"}\n    implicit def iterable[A](implicit write: Write[A]): Write[Traversable[A]] = new Write[Traversable[A]] {\n      override def apply(out: PrintWriter)(xs: Traversable[A]) = {\n        xs foreach write(out)\n        out.println()\n      }\n    }\n  }\n}\n\n", "src_uid": "cd0e90042a6aca647465f1d51e6dffc4"}
{"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P118D extends App {\n  def solve(n1: Int, n2: Int, k1: Int, k2: Int): Long = {\n    val cache = mutable.Map.empty[(Int, Int), Long]\n\n    def dp(a: Int, b: Int): Long =\n      if (a < 0 || b < 0) 0\n      else if (a == 0) { if (b == 0) 1 else 0 }\n      else if (b == 0) { if (a <= k1) 1 else 0 }\n      else {\n        val pair = (a, b)\n        if (cache.contains(pair)) cache(pair)\n        else {\n          @tailrec\n          def loop(acc: Long, i: Int, j: Int): Long =\n            if (i == a) acc\n            else if (j == b) loop(acc, i + 1, b - k2)\n            else loop(acc + dp(i, j), i, j + 1)\n          val x = loop(0, a - k1, b - k2) % 100000000L\n          cache += (pair -> x)\n          x\n        }\n      }\n    dp(n1, n2)\n  }\n\n  val sc = new Scanner(System.in)\n  val out = new PrintWriter(System.out)\n\n  val n1, n2, k1, k2 = sc.nextInt\n  val answer = (solve(n1, n2, k1, k2) + solve(n2, n1, k2, k1)) % 100000000L\n  out.println(answer)\n  out.close\n}\n", "src_uid": "63aabef26fe008e4c6fc9336eb038289"}
{"source_code": "object Main {\n  def main(args: Array[String]): Unit = {\n    val s = new Main()\n    s.solve()\n    s.out.flush()\n  }\n}\n\nclass Main {\n  import java.io._\n  import java.util.StringTokenizer\n\n  import scala.collection.mutable\n  import scala.util.Sorting\n  import math.{abs, max, min}\n  import mutable.{ArrayBuffer, ListBuffer}\n  import scala.reflect.ClassTag\n\n  val MOD = 1000000007\n  val out = new PrintWriter(System.out)\n\n  case class Rect(x1: Int, y1: Int, x2: Int, y2: Int) {\n    def area = (x2 - x1).toLong * (y2 - y1)\n  }\n\n  def solve(): Unit = {\n    val N = ni()\n    val R = map(N){ _ =>\n      val x1, y1, x2, y2 = ni()\n      Rect(x1, y1, x2, y2)\n    }\n\n    val l = R.map(_.x1).min\n    val r = R.map(_.x2).max\n    val b = R.map(_.y1).min\n    val t = R.map(_.y2).max\n\n    val w = r - l\n    val h = t - b\n\n    val sqr = Rect(l, b, r, t)\n    val isSqr = w > 0 && w == h &&\n      R.map(_.area).sum == sqr.area\n\n    if (isSqr) out.println(\"YES\")\n    else out.println(\"NO\")\n  }\n\n\n  def debug(as: Array[Boolean]): Unit = {\n    System.err.println(as.map(x => if(x) \"1\" else \"0\").mkString)\n  }\n\n  def debug(as: Array[Int]): Unit = {\n    System.err.println(as.mkString(\" \"))\n  }\n\n  def debug(as: Array[Long]): Unit = {\n    System.err.println(as.mkString(\" \"))\n  }\n\n  def debug(s: String): Unit = {\n    System.err.println(s)\n  }\n\n  class InputReader(val stream: InputStream) {\n    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n    private var tokenizer: StringTokenizer = _\n\n    def next(): String = {\n      while (tokenizer == null || !tokenizer.hasMoreTokens)\n        tokenizer = new StringTokenizer(reader.readLine)\n      tokenizer.nextToken\n    }\n\n    def nextInt(): Int = next().toInt\n    def nextLong(): Long = next().toLong\n    def nextChar(): Char = next().charAt(0)\n  }\n  val sc = new InputReader(System.in)\n  def ni(): Int = sc.nextInt()\n  def nl(): Long = sc.nextLong()\n  def nc(): Char = sc.nextChar()\n  def ns(): String = sc.next()\n  def ns(n: Int): Array[Char] = ns().toCharArray\n  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)\n  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {\n    val A1, A2 = Array.ofDim[Int](n)\n    REP(n) { i =>\n      A1(i) = ni() + offset\n      A2(i) = ni() + offset\n    }\n    (A1, A2)\n  }\n  def nm(n: Int, m: Int): Array[Array[Int]] = {\n    val A = Array.ofDim[Int](n, m)\n    REP(n) { i =>\n      REP(m) { j =>\n        A(i)(j) = ni()\n      }\n    }\n    A\n  }\n  def nal(n: Int): Array[Long] = map(n)(_ => nl())\n  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))\n  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = offset\n    val N = n + offset\n    while(i < N) { f(i); i += 1 }\n  }\n  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {\n    var i = n - 1 + offset\n    while(i >= offset) { f(i); i -= 1 }\n  }\n\n  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {\n    val res = Array.ofDim[A](n)\n    REP(n)(i => res(i) = f(i + offset))\n    res\n  }\n\n\n  def sumL(as: Array[Int]): Long = {\n    var s = 0L\n    REP(as.length)(i => s += as(i))\n    s\n  }\n\n  def cumSum(as: Array[Int]) = {\n    val cum = Array.ofDim[Long](as.length + 1)\n    REP(as.length) { i =>\n      cum(i + 1) = cum(i) + as(i)\n    }\n    cum\n  }\n}", "src_uid": "f63fc2d97fd88273241fce206cc217f2"}
{"source_code": "\nimport scala.math._\n\nobject FlippingGame extends App {\n  import Scanner._\n\n  val n = readInt\n  val seq = Array.fill(n)(readInt)\n\n  var max = -1\n  for(i <- 0 until n) {\n    var total = 0\n    for(j <- i until n; v = seq(j)) {\n      if(v == 0) {\n        total += 1\n        if(total > max)\n          max = total\n      } else\n        total -= 1\n    }\n  }\n  println(seq.sum + max)\n}\n\n\nobject Scanner {\n  def readInt() = {\n    var acc = 0\n    readWith {\n      case c if c >= '0' && c <= '9' && (Int.MaxValue - acc) >= (c - '0') =>\n        acc = (acc * 10) + (c - '0')\n    }\n    acc\n  }\n  def readLong() = {\n    var acc = 0L\n    readWith {\n      case c if c >= '0' && c <= '9' && (Long.MaxValue - acc) >= (c - '0') =>\n        acc = (acc * 10L) + (c - '0')\n    }\n    acc\n  }\n  def readDouble() = {\n    var (acc, frac, fracPow, readFrac) = (0L, 0L, 1L, false)\n    readWith {\n      case c if c >= '0' && c <= '9' && !readFrac && (Long.MaxValue - acc) >= (c - '0') =>\n        acc = (acc * 10) + (c - '0')\n      case c if c >= '0' && c <= '9' && readFrac && (Long.MaxValue - frac) >= (c - '0') =>\n        frac = (frac * 10) + (c - '0')\n        fracPow *= 10\n      case c if c == '.' && !readFrac =>\n        readFrac = true\n    }\n    acc + (frac.toDouble / fracPow)\n  }\n  def readString() = {\n    var string = new StringBuilder\n    readWith { case c => string += c }\n    string\n  }\n  def readLine() = Console.in.readLine()\n  def readChar() = Console.in.read().toChar\n  def readWith(func: PartialFunction[Char, Unit]) {\n    val handler = func orElse[Char, Unit] {\n      case _ => throw new java.io.IOException(\"unexpected token\")\n    }\n\n    var c = readChar\n    while(c.isWhitespace)\n      c = readChar\n\n    while(!c.isWhitespace) {\n      handler(c)\n\n      c = readChar\n    }\n  }\n}\n\n", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99"}
{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n  val in = Source.stdin.getLines()\n  val n = in.next().toInt\n  val data = in.next().split(' ').map(_.toInt).distinct.sorted\n  if (data.length > 2 && data.sliding(3).exists{case Array(a, b, c) => c == a + 2})\n    println(\"YES\")\n  else\n    println(\"NO\")\n}", "src_uid": "d6c876a84c7b92141710be5d76536eab"}
{"source_code": "object A471 extends App {\n    // val sticks = scala.io.StdIn.readLine.split(' ').map(_.toInt)\n    val sticks = new Array[Int](6)\n    val cnt = new Array[Int](10)\n    \n    val cin = new java.util.Scanner(System.in)\n    \n    for (i <- 0 until 6)\n        sticks(i) = cin.nextInt\n\n    for (i <- sticks) cnt(i) += 1\n\n    if (cnt.max < 4) println(\"Alien\")\n    else {\n        val criteria = cnt.filter(x => x != 0 && x != 4)(0) % 2\n        println(\n            criteria match {\n                case 0 => \"Elephant\"\n                case 1 => \"Bear\"\n            })\n    }\n}", "src_uid": "43308fa25e8578fd9f25328e715d4dd6"}
{"source_code": "object Solution extends App {\n  val in = scala.io.Source.stdin.getLines()\n  val n = in.next().toInt\n  val data = (1 to n).map(_ => in.next().split(' ').map(_.toInt))\n  if (n == 1)\n    println(-1)\n  else if (n == 3 || n == 4) {\n    val min = data.map(_.head).min\n    val max = data.map(_.head).max\n    val miny = data.map(_.last).min\n    val maxy = data.map(_.last).max\n    println((maxy - miny) * (max - min))\n  } else {\n    val min = data.map(_.head).min\n    val max = data.map(_.head).max\n    val miny = data.map(_.last).min\n    val maxy = data.map(_.last).max\n    if (min != max && miny != maxy)\n      println((maxy - miny) * (max - min))\n    else\n      println(-1)\n  }\n}\n", "src_uid": "ba49b6c001bb472635f14ec62233210e"}