{"nl": {"description": "You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.", "input_spec": "The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive ( > 0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.", "output_spec": "Print a single number — the sum of all edges of the parallelepiped.", "sample_inputs": ["1 1 1", "4 6 6"], "sample_outputs": ["12", "28"], "notes": "NoteIn the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3."}, "positive_code": [{"source_code": "import collection.mutable.ArrayBuffer\nimport java.io.InputStreamReader\nimport java.io.BufferedReader\nimport scala.collection.JavaConversions._\n\n\nobject CodeForces138_1 {\n\n val in = System.in\n val out = System.out\n\n def grabData {\n val reader = new BufferedReader(new InputStreamReader(in))\n //val array = new ArrayBuffer[]()\n var line = reader.readLine()\n while(line != null) {\n\n line = reader.readLine()\n }\n //array\n }\n\n def grabData2 = {\n val reader = new BufferedReader(new InputStreamReader(in))\n val line = reader.readLine()\n line.split(' ').toSeq.map(_.toInt)\n }\n\n\n\n def main(args: Array[String]) {\n val sses = grabData2\n val s1:Double = sses(0)\n val s2:Double = sses(1)\n val s3:Double = sses(2)\n val c = Math.sqrt(s2*s3/s1)\n val a = s3/c\n val b = s2/c\n out.print(((c+a+b)*4).toInt)\n }\n\n}\n"}, {"source_code": "object A {\n def main(args : Array[String]) : Unit = {\n val Array(x, y, z) = readLine.split(\" \").map(s => s toInt);\n\n def side(x : Int, y : Int, z : Int) : Double = {\n scala.math.sqrt(x * y / z)\n }\n\n val sm = side(x, y, z) + side(y, z, x) + side(z, x, y)\n\n println((4 * sm) toInt)\n }\n}\n"}, {"source_code": "import java.util.StringTokenizer\n\nobject _224A extends App {\n var token = new StringTokenizer(\"\")\n\n def next = {\n while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)\n token.nextToken()\n }\n\n val a = next.toInt\n val b = next.toInt\n val c = next.toInt\n val cb = a.toLong * b * c\n val wb = Math.sqrt(cb).round\n val zb = (for {\n i <- (wb - 10) to (wb + 10)\n if (i > 0)\n if (i * i == cb)\n } yield i).head\n\n val t = zb / a\n val tt = zb / b\n val ttt = zb / c\n println(4 * (t + tt + ttt))\n}\n"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val Array(x1, x2, x3) = in.next().split(' ').map(_.toInt)\n\n def findSolution(x1: Int, x2: Int, x3: Int) = {\n (1 to x1).collectFirst {\n case a if x3 == x2 / a * x1 / a =>\n (a, x2 / a, x1 / a)\n case a if x2 == x3 / a * x1 / a =>\n (a, x3 / a, x1 / a)\n }\n }\n\n println(findSolution(x1, x2, x3).map(i => 4 * (i._1 + i._2 + i._3)).get)\n\n}\n"}, {"source_code": "object A224 {\n\n import IO._\n import collection.{mutable => cu}\n def gcd(a: Long, b: Long): Long = {\n if(b == 0) a else gcd(b, a%b)\n }\n def main(args: Array[String]): Unit = {\n val in = readLongs(3).sorted\n var break = false\n for(i <- 1 to in.min.toInt if !break) {\n val a = i\n val b = in(0)/a\n val c = in(2)/a\n if(b*c == in(1)) {\n println(4 * (a + b + c))\n break = true\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"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P224A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val X, Y, Z = sc.nextLong\n\n val xyz = math.sqrt(X * Y * Z).round\n\n val a = xyz / X\n val b = xyz / Y\n val c = xyz / Z\n\n val answer = 4 * (a + b + c)\n\n out.println(answer)\n out.close\n}\n"}, {"source_code": "// codeforces 224A\nobject Parallelipiped extends App {\n val ss = (Console.readLine.split(\" \")) map (_.toInt)\n val sxy = ss(0)\n val syz = ss(1)\n val sxz = ss(2)\n \n def lxyz():Int = {\n val vars = for {\n x <- 1 to 10000\n if sxy % x == 0\n val y = sxy / x\n if syz % y == 0\n val z = syz / y\n if x*z == sxz \n } yield (x + y + z)\n vars(0) * 4\n }\n \n println(lxyz())\n}"}, {"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(ab, bc, ac) = readInts\n def intStream(i: Int): Stream[Int] = i #:: intStream(i + 1)\n def a = intStream(1).filter(ab % _ == 0).filter(ac % _ == 0)\n def ans = a.filter(a => ab / a * ac / a == bc).head\n\n def main(a: Array[String]) {\n println(4 * (ans + ab / ans + ac / ans))\n }\n}\n"}, {"source_code": "object test5 extends App {\n val Array(x,y,z)=readLine.split(\" \").map(_.toInt)\n for(a<-1 to x if x%a==0)\n {\n\t\tval b=x/a\n\t\tif(y%a==0)\n\t\t{\n\t\t\tval c=y/a\n\t\t\tif(b*c==z)\n\t\t\t{\n\t\t\t\tprintln((a+b+c)*4)\n\t\t\t\texit\n\t\t\t}\n\t\t}\n }\n} \n\n/*\na*b=x\n\na*c=y && b*c=z ||\nb*c=y && a*c=z\n*/"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val ss = readLine().split(\" \").map(_.toInt).sorted\n val s1 = ss(0)\n val s2 = ss(1)\n val s3 = ss(2)\n \n val ls0 = for {\n i <- 1 to s1\n j = (s1 / i).toInt\n if i * j == s1\n } yield(i, j)\n val ls = for {\n (i, j) <- ls0\n k = (ss(1) / i).toInt\n if i * k == s2\n if j * k == s3\n } yield(i, j, k)\n println((ls(0)._1 + ls(0)._2 + ls(0)._3) * 4)\n }\n}"}], "negative_code": [{"source_code": "object A224 {\n\n import IO._\n import collection.{mutable => cu}\n def gcd(a: Long, b: Long): Long = {\n if(b == 0) a else gcd(b, a%b)\n }\n def main(args: Array[String]): Unit = {\n val in = readLongs(3)\n var break = false\n for(i <- 1 to in.min.toInt if !break) {\n val a = i\n val b = in(0)/a\n val c = in(2)/a\n if(b*c == in(1)) {\n println(4 * (a + b + c))\n break = true\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": "c0a3290be3b87f3a232ec19d4639fefc"} {"nl": {"description": "Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given a, b and n who wins the game.", "input_spec": "The only string contains space-separated integers a, b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.", "output_spec": "If Simon wins, print \"0\" (without the quotes), otherwise print \"1\" (without the quotes).", "sample_inputs": ["3 5 9", "1 1 100"], "sample_outputs": ["0", "1"], "notes": "NoteThe greatest common divisor of two non-negative integers a and b is such maximum positive integer k, that a is divisible by k without remainder and similarly, b is divisible by k without remainder. Let gcd(a, b) represent the operation of calculating the greatest common divisor of numbers a and b. Specifically, gcd(x, 0) = gcd(0, x) = x.In the first sample the game will go like that: Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left. Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left. Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left. Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left. Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left. Antisimon should take gcd(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.In the second sample each player during each move takes one stone from the heap. As n is even, Antisimon takes the last stone and Simon can't make a move after that."}, "positive_code": [{"source_code": "import scala.io.StdIn.readLine\n\n/**\n * @author slie742\n */\nobject EpicGame {\n \n def gcd(a: Int,b:Int) : Int = {\n b match {\n case 0 => a\n case _ => gcd(b,a%b)\n }\n }\n \n def solve(a: Int, b: Int, n:Int) : Int = {\n def go(rem: Int, turn: Int) : Int = turn match {\n case 0 => if (rem < gcd(a,rem)) 1\n else go(rem - gcd(a,rem),1)\n case _ => if (rem < gcd(b,rem)) 0\n else go(rem - gcd(b,rem),0) \n } \n go(n,0)\n }\n \n def main(args: Array[String]) {\n val line = readLine.split(' ').map(_.toInt)\n println(solve(line(0),line(1),line(2)))\n }\n \n}"}, {"source_code": "import scala.util.Sorting\nimport scala.io.StdIn\n\nobject App {\n\n\n def main(args: Array[String]) {\n\n val Array(a, b, n) = StdIn.readLine().split(\" \").map(_.toInt)\n\n val A:Array[Int] = Array(a,b)\n var cur = 0\n var curn = n\n while(gcd(curn,A(cur)) <= curn) {\n curn-=gcd(curn,A(cur));\n if(cur == 0) {\n cur = 1\n } else {\n cur = 0\n }\n }\n if(cur == 0) {\n cur = 1\n } else {\n cur = 0\n }\n print(cur)\n\n\n def gcd(x:Int, y:Int):Int = {\n if(x % y == 0)\n y\n else\n gcd( y % x, x)\n }\n\n }\n\n\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject TEST extends App {\n val a : Array[Int] = readLine.split(\" \").map(_.toInt)\n\n def gcd(x: Int, y: Int): Int = if(y==0) x else gcd(y,x%y)\n\n def play(state :Int,n: Int):Int =if(n==0) state^1 else play(state^1,n-gcd(n,a(state)))\n\n print(play(0,a(2)))\n}"}, {"source_code": "import scala.annotation.tailrec\nobject Main {\n\n def main(args: Array[String]): Unit = {\n @tailrec\n def gcd(x:Int,y:Int):Int= y match{\n case 0 => return x;\n case _ => return gcd(y,x%y);\n }\n var fix = readLine().split(\" \").map(_.toInt)\n @tailrec\n def rec(t:Int,n:Int):Int= n match{\n case _ if gcd(fix(t),n)>n => return 1-t;\n case _ => return rec(1-t,n-gcd(fix(t),n))\n }\n println(rec(0,fix(2)))\n }\n\n}"}, {"source_code": "import scala.annotation.tailrec\nobject Main {\n\n def main(args: Array[String]): Unit = {\n @tailrec\n def gcd(x:Int,y:Int):Int={\n if(y==0)return x;\n return gcd(y,x%y);\n }\n var fix = readLine().split(\" \").map(_.toInt)\n @tailrec\n def rec(t:Int,n:Int):Int={\n val req = gcd(fix(t),n)\n if(req>n)return 1-t;\n return rec(1-t,n-req)\n }\n println(rec(0,fix(2)))\n }\n\n}"}, {"source_code": "import scala.collection.immutable.Nil\n\nobject A00119 extends App {\n def parseInt(str: String, count: Int): Seq[Int] = {\n val scanner = new java.util.Scanner(str)\n val res = (1 to count) map (_ => scanner.nextInt())\n scanner.close()\n res\n }\n def scanInts(count: Int): Seq[Int] = parseInt(Console.readLine, count)\n def readMatrix(row: Int, col: Int) = (1 to row) map (x => scanInts(col))\n\n def oneIntLine = {\n val Seq(count) = parseInt(Console.readLine(), 1);\n count\n }\n \n def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)\n \n def nextVals(x: (Int, Int, Int)): (Int, Int, Int) =\n if (x._3 == 0) null\n else (x._2, x._1, x._3 - gcd(x._1, x._3))\n \n def valStream(x: (Int, Int, Int)): Stream[(Int, Int, Int)] = {\n val n = nextVals(x)\n if (n == null) Stream.Empty\n else x #:: valStream(n)\n }\n\n val Seq(a, b, n) = readMatrix(1, 3).head\n\n println((valStream((a, b, n)).length - 1) % 2)\n \n \n \n}"}, {"source_code": "object Main {\n\n def gcd(x: Int, y: Int): Int = {\n var a = x; var b = y\n while (b > 0) {\n a %= b\n val k = a\n a = b\n b = k\n }\n return a\n } \n\n def main(args: Array[String]): Unit = {\n var Array(a, b, n) = readLine split \" \" map(_.toInt)\n var cur = 1\n while (n > 0) {\n val k = if (cur == 1) a else b\n n -= gcd(k, n)\n cur += 1;\n cur %= 2 \n }\n\n println (cur)\n }\n}"}, {"source_code": "\nobject One19A extends App {\n\n\tval Array(a, b, n) = readLine.split(' ').map(_.toInt)\n\n\tdef recursive(tog: Boolean, left: Int): Boolean = if (tog) {\n\t\tval cal = left - gcd(a, left)\n\t\tif (cal >= 0) recursive(!tog, cal) else tog\n\t} else {\n\t\tval cal = left - gcd(b, left)\n\t\tif (cal >= 0) recursive(!tog, cal) else tog\n\t}\n\n\tdef gcd(a: Int, b: Int): Int = if (a == 0) b else gcd(b % a, a)\n\n\tif (recursive(true, n)) {\n\t\tprintln(1)\n\t} else {\n\t\tprintln(0)\n\t}\n}"}, {"source_code": "import scala.io.StdIn\n\nobject Main extends App {\n val str = StdIn.readLine().split(\" \").map(_.toInt)\n val a = str(0)\n val b = str(1)\n var n = str(2)\n var moveCount = 0\n\n def gcd(a: Int, b: Int): Int =\n if (b == 0) a else gcd(b, a % b)\n\n while(n >= 0) {\n if (moveCount == 0) {\n val move = gcd(a, n)\n n = n - move\n moveCount = 1\n } else {\n val move = gcd(b, n)\n n = n - move\n moveCount = 0\n }\n }\n\n if (moveCount == 1) println(1)\n else println(0)\n}"}, {"source_code": "object Solutuin119A extends App {\n\n\n def norm(a: Int, b: Int): (Int, Int) = (scala.math.min(a,b), scala.math.max(a, b))\n\n def gcd(a: Int, b: Int): Int = {\n val n = norm(a, b)\n n._2 % n._1 match {\n case 0 => n._1\n case m => gcd(m, n._1)\n }\n }\n\n def solution() {\n val a = _int\n val b = _int\n val n = _int\n val qqq = Map(0 -> a, 1 -> b)\n\n def wins(n: Int, turn: Int): Int = n match {\n case 0 => (turn + 1) % 2\n case _ => wins(n - gcd(n, qqq(turn)), (turn + 1) % 2)\n }\n\n println(wins(n, 0))\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}"}, {"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 def gcd(a: Int, b: Int): Int = if(b == 0) a else gcd(b, a%b)\n var t = Array[Int](sc.nextInt,sc.nextInt)\n var n = sc.nextInt\n def sim(s: Int): Int = {\n val g = gcd(n,t(s))\n val ns = (s+1)%2\n if(n < g) ns\n else { n-=g; sim(ns) }\n }\n println(sim(0))\n}\n"}, {"source_code": "object Solution extends App{\n def gcd(a: Int, b: Int): Int = {\n if(b == 0) a else gcd(b, a % b)\n }\n\n val in = scala.io.Source.stdin.getLines()\n var Array(a, b, n) = in.next().split(\" \").map(_.toInt)\n var count = 0\n var take = gcd(a, n)\n while (n > take) {\n n -= take\n count += 1\n if (count % 2 == 1)\n take = gcd(b, n)\n else\n take = gcd(a, n)\n }\n println(count % 2)\n}"}, {"source_code": "import scala.collection.JavaConversions._\nimport scala.collection.mutable.ArraySeq\n\nobject Codeforces119A {\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 arr: ArraySeq[Int] = scala.io.StdIn.readLine().split(\" \").map(Integer.parseInt)\n var currentPlayer = 0 // Simon\n var g: Int = 0\n while (arr(2) >= 0) {\n g = gcd(arr(currentPlayer), arr(2))\n if (arr(2) < g) {\n println(1-currentPlayer)\n return\n }\n else {\n arr(2) -= g\n currentPlayer = 1 - currentPlayer\n }\n }\n }\n}"}, {"source_code": "object A119 {\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 gcd(a: Int, b: Int): Int = if(b==0) a else gcd(b, a%b)\n def main(args: Array[String]): Unit = {\n var Array(a, b, n) = readInts(3)\n val arr = Array(a, b)\n var player = 0\n while(n > 0) {\n val gc = gcd(arr(player), n)\n n -= gc\n player = 1-player\n }\n println(1-player)\n }\n}"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P119A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val A, B, N = sc.nextInt\n\n @tailrec\n def euclid(a: Int, b: Int): Int =\n if (b == 0) a\n else euclid(b, a % b)\n\n def gcd(a: Int, b: Int): Int =\n if (a > b) euclid(a, b)\n else euclid(b, a)\n\n def antisimon(x: Int): Int = {\n val r = gcd(x, B)\n if (x < r) 0\n else simon(x - r)\n }\n\n def simon(x: Int): Int = {\n val r = gcd(x, A)\n if (x < r) 1\n else antisimon(x - r)\n }\n\n val solve: Int = simon(N)\n\n out.println(solve)\n out.close\n}\n"}, {"source_code": "\n\nobject EpicGame {\n\tdef main (args: Array[String]) {\n\t\tval scanner = new java.util.Scanner(System.in);\n\t\tval a = scanner.nextInt();\n\t\tval b = scanner.nextInt();\n\t\tvar n = scanner.nextInt();\n\t\tvar turn = 0 // 0 for Simon's turn\n\t\twhile (n > 0) {\n\t\t n -= gcd(n, if (turn == 0) a else b)\n\t\t turn = 1 - turn\n\t\t}\n\t\tprint(1 - turn)\n\t}\n\t\n\tdef gcd (x: Int, y: Int) : Int = {\n\t if (x > y) {\n\t gcd(x - y, y)\n\t }\n\t else {\n\t if (x == y) {\n\t x\n\t }\n\t else {\n\t gcd (x, y - x)\n\t }\n\t }\n\t \n\t}\n}"}, {"source_code": "object Codeforces119A extends App{\n\n def GCDFind(first:Int,second:Int):Int={\n var a:Int=first\n var b:Int=second\n var temp:Int=0\n if (b>a){\n temp=a\n a=b\n b=temp\n }\n temp=b\n while((a%temp!=0)||(b%temp!=0)){\n temp=a-(a/b)*b\n a=b\n b=temp\n }\n return temp\n }\n\n def EpicGame(simon:Int,antisimon:Int,totalstone:Int):Int={\n var currentstone:Int=totalstone\n var temp:Int=0\n while(currentstone!=0){\n temp=GCDFind(simon,currentstone)\n currentstone = currentstone-temp\n if (currentstone==0){\n return 0\n }\n temp=GCDFind(antisimon,currentstone)\n currentstone = currentstone-temp\n if (currentstone==0){\n return 1\n }\n }\n return 1\n }\n val oldgroup=scala.io.StdIn.readLine.split(\" \")\n var ingroup=oldgroup.map(_.toInt)\n println(EpicGame(ingroup(0),ingroup(1),ingroup(2)))\n\n}\n"}, {"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 @tailrec\n def gcd(a: Int, b: Int): Int = if(b == 0) a else gcd(b, a % b)\n\n @tailrec\n def ans(a: Array[Int], i: Int, n: Int): Int = if(n == 0) 1 - i else ans(a, (i + 1) % 2, n - gcd(n, a(i)))\n\n def main(a: Array[String]) {\n val a = readInts\n println(ans(a, 0, a(2)))\n }\n}\n"}, {"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 main(args: Array[String]) {\n val arr = readLine().split(\" \").map(_.toInt)\n val a = arr(0)\n val b = arr(1)\n var n = arr(2)\n var turn = 1\n while (n != 0) { \n if (turn == 1) {\n n -= gcd(n, a)\n turn = 0\n } else {\n n -= gcd(n, b)\n turn = 1\n }\n }\n println(turn)\n }\n}"}, {"source_code": "import java.util.Scanner\n\nobject CF119A {\n def gcd(a:Int,b:Int):Int = b match{\n case 0=> a\n case b=> gcd(b,a%b)\n }\n \n def main(args: Array[String]){\n val sc:Scanner = new Scanner(System.in)\n val a = sc.nextInt; val b = sc.nextInt; var s = sc.nextInt\n var turn = 0\n while(gcd(if (turn==0) a else b,s) <= s){\n s -= gcd(if (turn==0) a else b,s)\n turn = (turn+1)%2\n }\n turn = (turn+1)%2\n println(turn);\n }\n}"}], "negative_code": [{"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 def gcd(a: Int, b: Int): Int = if(b == 0) a else gcd(b, a%b)\n var t = Array[Int](sc.nextInt,sc.nextInt)\n var n = sc.nextInt\n def sim(s: Int): Int = {\n val g = gcd(n,t(s))\n if(n > g) return (s+1)%2\n else { n-=g; sim((s+1)%2) }\n }\n println(sim(0))\n}\n"}], "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2"} {"nl": {"description": "Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least x blue, y violet and z orange spheres. Can he get them (possible, in multiple actions)?", "input_spec": "The first line of the input contains three integers a, b and c (0 ≤ a, b, c ≤ 1 000 000) — the number of blue, violet and orange spheres that are in the magician's disposal. The second line of the input contains three integers, x, y and z (0 ≤ x, y, z ≤ 1 000 000) — the number of blue, violet and orange spheres that he needs to get.", "output_spec": "If the wizard is able to obtain the required numbers of spheres, print \"Yes\". Otherwise, print \"No\".", "sample_inputs": ["4 4 0\n2 1 2", "5 6 1\n2 7 2", "3 3 3\n2 2 2"], "sample_outputs": ["Yes", "No", "Yes"], "notes": "NoteIn the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs."}, "positive_code": [{"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val r = in.next().split(' ').map(_.toInt).zip(in.next().split(' ').map(_.toInt)).foldLeft(0, 0) {\n case((minus, plus), (have, need)) if need <= have => (minus, plus + (have - need) / 2)\n case((minus, plus), (have, need)) => (minus + need - have, plus)\n }\n if (r._1 > r._2)\n println(\"No\")\n else\n println(\"Yes\")\n}\n"}, {"source_code": "object A606 {\n\n import IO._\n import collection.{mutable => cu}\n\n def main(args: Array[String]): Unit = {\n val Array(a,b,c) = readInts(3)\n val Array(x,y,z) = readInts(3)\n if(solve(a,b,c,x,y,z)) {\n println(\"Yes\")\n } else {\n println(\"No\")\n }\n }\n\n def solve(a: Int, b: Int, c: Int, x: Int, y: Int, z: Int): Boolean = {\n if(x == 0 && y == 0 && z == 0)\n true\n else {\n if (a >= x) {\n solve(b, c, a - x, y, z, 0)\n } else {\n val short = x-a\n if((c-z)/2 > 0) {\n val extra = math.min(short, (c-z)/2)\n solve(a+extra, b, c - extra*2, x, y, z)\n } else if((b-y)/2 > 0) {\n val extra = math.min(short, (b-y)/2)\n solve(a+extra, b - extra*2, c, x, y, z)\n } else {\n false\n }\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"}, {"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 val as = readInts(3)\n val bs = readInts(3)\n \n val have = (0 to 2).map(i => ((as(i) - bs(i)) / 2) max 0).sum\n val need = (0 to 2).map(i => (bs(i) - as(i)) max 0).sum\n\n println(if (have >= need) \"Yes\" else \"No\")\n}"}, {"source_code": "import io.StdIn._\n\nobject Main{\n def main (args: Array[String]){\n val yes = \"Yes\"\n val no = \"No\"\n\n val Array(a, b, c) = readLine.split(' ').map(_.toInt)\n val Array(x, y, z) = readLine.split(' ').map(_.toInt)\n\n var dif = new Array[Int](3)\n dif(0) = a - x\n dif(1) = b - y\n dif(2) = c - z\n\n var over = 0\n var husoku = 0\n for(i <- 0 to 2){\n if (dif(i) >= 0) over += dif(i) / 2\n else husoku += Math.abs(dif(i))\n }\n\n if(over >= husoku) println(yes)\n else println(no)\n }\n}\n"}, {"source_code": "object A{\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 has=for(i<-0 until 3) yield nextInt\n val want=for(i<-0 until 3) yield nextInt\n var sum=0\n for(i<-0 until 3){\n if(has(i)>want(i)){\n sum+=(has(i)-want(i))/2\n }else{\n sum+=has(i)-want(i)\n }\n\n }\n if(sum>=0){\n out.print(\"Yes\")\n }else{\n out.print(\"No\")\n }\n\n //code ends here\n out.flush\n out.close\n }\n}\n\n"}], "negative_code": [{"source_code": "object A606 {\n\n import IO._\n import collection.{mutable => cu}\n\n def main(args: Array[String]): Unit = {\n val Array(a,b,c) = readInts(3)\n val Array(x,y,z) = readInts(3)\n if(solve(a,b,c,x,y,z)) {\n println(\"Yes\")\n } else {\n println(\"No\")\n }\n }\n\n def solve(a: Int, b: Int, c: Int, x: Int, y: Int, z: Int): Boolean = {\n if(x == 0 && y == 0 && z == 0)\n true\n else {\n if (a >= x) {\n solve(b, c, a - x, y, z, 0)\n } else {\n val short = x-a\n if((b-y)/2 > 0) {\n val extra = (b-y)/2\n solve(a+extra, b - extra*2, c, x, y, z)\n } else if((c-z)/2 > 0) {\n val extra = (c-z)/2\n solve(a+extra, b, c - extra*2, x, y, z)\n } else {\n false\n }\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"}, {"source_code": "import scala.collection._\n\nobject 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 \n case class X(a: Int, b: Int, c: Int)\n\n val Array(a, b, c) = readInts(3)\n val start = X(a, b, c)\n\n val Array(x, y, z) = readInts(3)\n val goal = X(x, y, z)\n\n val end = System.currentTimeMillis() + 1500\n val visited = mutable.Set.empty[X]\n\n def check(q: X): Unit = {\n //println(q)\n if (!visited(q) && System.currentTimeMillis < end) {\n visited += q\n if (q == goal) {\n println(\"Yes\")\n System.exit(0)\n } else {\n if (q.a > goal.a) {\n check(X(q.a - 2, q.b + 1, q.c))\n check(X(q.a - 2, q.b, q.c + 1))\n }\n if (q.b > goal.b) {\n check(X(q.a + 1, q.b - 2, q.c))\n check(X(q.a, q.b - 2, q.c + 1))\n }\n if (q.c > goal.c) {\n check(X(q.a + 1, q.b, q.c - 2))\n check(X(q.a, q.b + 1, q.c - 2))\n }\n }\n }\n }\n\n check(start)\n \n println(\"No\")\n}\n"}, {"source_code": "import scala.collection._\n\nobject 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 \n case class X(a: Int, b: Int, c: Int)\n\n val Array(a, b, c) = readInts(3)\n val start = X(a, b, c)\n\n val Array(x, y, z) = readInts(3)\n val goal = X(x, y, z)\n\n val end = System.currentTimeMillis() + 1500\n val visited = mutable.Set.empty[X]\n\n def check(q: X): Unit = {\n //println(q)\n if (!visited(q) && System.currentTimeMillis < end) {\n visited += q\n if (q.a >= goal.a && q.b >= goal.b && q.c >= goal.c) {\n println(\"Yes\")\n System.exit(0)\n } else {\n if (q.a > goal.a + 2000) {\n check(X(q.a - 1000, q.b + 500, q.c))\n check(X(q.a - 1000, q.b, q.c + 500))\n }\n if (q.b > goal.b + 2000) {\n check(X(q.a + 500, q.b - 1000, q.c))\n check(X(q.a, q.b - 1000, q.c + 500))\n }\n if (q.c > goal.c + 2000) {\n check(X(q.a + 500, q.b, q.c - 1000))\n check(X(q.a, q.b + 500, q.c - 1000))\n }\n if (q.a > goal.a) {\n check(X(q.a - 2, q.b + 1, q.c))\n check(X(q.a - 2, q.b, q.c + 1))\n }\n if (q.b > goal.b) {\n check(X(q.a + 1, q.b - 2, q.c))\n check(X(q.a, q.b - 2, q.c + 1))\n }\n if (q.c > goal.c) {\n check(X(q.a + 1, q.b, q.c - 2))\n check(X(q.a, q.b + 1, q.c - 2))\n }\n }\n }\n }\n\n check(start)\n \n println(\"No\")\n}\n"}, {"source_code": "import scala.collection._\n\nobject 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 \n case class X(a: Int, b: Int, c: Int)\n\n val Array(a, b, c) = readInts(3)\n val start = X(a, b, c)\n\n val Array(x, y, z) = readInts(3)\n val goal = X(x, y, z)\n\n val end = System.currentTimeMillis() + 1500\n val visited = mutable.Set.empty[X]\n\n def check(q: X): Unit = {\n //println(q)\n if (!visited(q) && System.currentTimeMillis < end) {\n visited += q\n if (q.a >= goal.a && q.b >= goal.b && q.c >= goal.c) {\n println(\"Yes\")\n System.exit(0)\n } else {\n if (q.a > goal.a + 4000) {\n check(X(q.a - 1000, q.b + 500, q.c))\n check(X(q.a - 1000, q.b, q.c + 500))\n }\n if (q.b > goal.b + 4000) {\n check(X(q.a + 500, q.b - 1000, q.c))\n check(X(q.a, q.b - 1000, q.c + 500))\n }\n if (q.c > goal.c + 4000) {\n check(X(q.a + 500, q.b, q.c - 1000))\n check(X(q.a, q.b + 500, q.c - 1000))\n }\n if (q.a > goal.a) {\n check(X(q.a - 2, q.b + 1, q.c))\n check(X(q.a - 2, q.b, q.c + 1))\n }\n if (q.b > goal.b) {\n check(X(q.a + 1, q.b - 2, q.c))\n check(X(q.a, q.b - 2, q.c + 1))\n }\n if (q.c > goal.c) {\n check(X(q.a + 1, q.b, q.c - 2))\n check(X(q.a, q.b + 1, q.c - 2))\n }\n }\n }\n }\n\n check(start)\n \n println(\"No\")\n}\n"}], "src_uid": "1db4ba9dc1000e26532bb73336cf12c3"} {"nl": {"description": "There are n students who have taken part in an olympiad. Now it's time to award the students.Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners.You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.", "input_spec": "The first (and the only) line of input contains two integers n and k (1 ≤ n, k ≤ 1012), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas.", "output_spec": "Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.", "sample_inputs": ["18 2", "9 10", "1000000000000 5", "1000000000000 499999999999"], "sample_outputs": ["3 6 9", "0 0 9", "83333333333 416666666665 500000000002", "1 499999999999 500000000000"], "notes": null}, "positive_code": [{"source_code": "import scala.io.StdIn\n\nobject A extends App {\n\n var Array(n, k) = StdIn.readLine().split(\" \").map(_.toLong)\n val x = n/(2*(k+1))\n println(x + \" \" + x*k + \" \" + (n - x*k -x))\n}\n"}], "negative_code": [], "src_uid": "405a70c3b3f1561a9546910ab3fb5c80"} {"nl": {"description": "You are given a square board, consisting of $$$n$$$ rows and $$$n$$$ columns. Each tile in it should be colored either white or black.Let's call some coloring beautiful if each pair of adjacent rows are either the same or different in every position. The same condition should be held for the columns as well.Let's call some coloring suitable if it is beautiful and there is no rectangle of the single color, consisting of at least $$$k$$$ tiles.Your task is to count the number of suitable colorings of the board of the given size.Since the answer can be very large, print it modulo $$$998244353$$$.", "input_spec": "A single line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 500$$$, $$$1 \\le k \\le n^2$$$) — the number of rows and columns of the board and the maximum number of tiles inside the rectangle of the single color, respectively.", "output_spec": "Print a single integer — the number of suitable colorings of the board of the given size modulo $$$998244353$$$.", "sample_inputs": ["1 1", "2 3", "49 1808"], "sample_outputs": ["0", "6", "359087121"], "notes": "NoteBoard of size $$$1 \\times 1$$$ is either a single black tile or a single white tile. Both of them include a rectangle of a single color, consisting of $$$1$$$ tile.Here are the beautiful colorings of a board of size $$$2 \\times 2$$$ that don't include rectangles of a single color, consisting of at least $$$3$$$ tiles: The rest of beautiful colorings of a board of size $$$2 \\times 2$$$ are the following: "}, "positive_code": [{"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 = 998244353\n val out = new PrintWriter(System.out)\n\n def solve(): Unit = {\n val sc = new InputReader(System.in)\n val N, K = sc.nextInt()\n val s = System.nanoTime()\n var dp, ndp = Array.ofDim[Int](N + 2, N + 2)\n dp(0)(0) = 1\n rep(N) { i =>\n import java.util\n rep(ndp.length)(i => util.Arrays.fill(ndp(i), 0))\n rep(i + 1) { j =>\n rep(i + 1) { k =>\n ndp(j + 1)(max(k, j + 1)) = (ndp(j + 1)(max(k, j + 1)) + dp(j)(k)) % MOD\n ndp(1)(max(k, 1)) = (ndp(1)(max(k, 1)) + dp(j)(k)) % MOD\n }\n }\n val tmp = dp\n dp = ndp\n ndp = tmp\n }\n\n val cnt = Array.ofDim[Long](N + 1)\n rep(N + 1) { j =>\n rep(N + 1) { k =>\n cnt(k) = (cnt(k) + dp(j)(k)) % MOD\n }\n }\n val cum = Array.ofDim[Long](N + 1)\n cum(0) = cnt(0)\n rep(N){ k =>\n cum(k + 1) = (cum(k + 1) + cum(k) + cnt(k + 1)) % MOD\n }\n\n var ans = 0L\n rep(N, 1) { i =>\n val j = min(N, (K - 1) / i)\n ans = (ans + cnt(i) * cum(j)) % MOD\n }\n\n ans = ans * (MOD + 1) / 2 % MOD\n\n out.println(ans)\n\n val e = System.nanoTime()\n System.err.println(s\"${(e-s)/1000000}\")\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 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 implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {\n // todo Orderingだとboxing発生するので自作Orderを用意したい\n def maxByOpt[B: Ordering](f: A => B): Option[A] = {\n if (as.nonEmpty) Some(as.maxBy(f)) else None\n }\n\n def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {\n val map = mutable.Map.empty[K, ArrayBuffer[A]]\n rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))\n map\n }\n\n def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {\n var sum = num.zero\n rep(as.length)(i => sum = num.plus(sum, f(as(i))))\n sum\n }\n\n def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {\n limit(f, ixRange)(cmp.lt)\n }\n\n def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {\n limit(f, ixRange)(cmp.gt)\n }\n\n private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {\n var limA = as(ixRange.head)\n var limB = f(limA)\n\n for (i <- ixRange.tail) {\n val a = as(i)\n val b = f(a)\n if (cmp(b, limB)) {\n limA = a\n limB = b\n }\n }\n (limA, limB)\n }\n }\n\n implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {\n def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {\n as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))\n }\n }\n}"}, {"source_code": "object E 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, k) = readInts(2)\n val MOD = 998244353L\n val MODB = BigInt(MOD)\n val TWO = BigInt(2)\n\n val counts = Array.fill(n + 1)(0L)\n var prev = 0L\n for (kh <- 1 to (k min n)) {\n val dp = Array.fill(n + 1, 2)(0L)\n for (i <- 1 to n) {\n if (i <= kh) {\n val pp = TWO.modPow((i min kh) - 1, MODB).toLong\n dp(i)(0) = pp\n dp(i)(1) = pp\n } else {\n var p = 1L\n for (j <- 1 to (i min kh)) {\n dp(i)(0) = (dp(i)(0) + dp(i - j)(1)) % MOD\n dp(i)(1) = (dp(i)(1) + dp(i - j)(0)) % MOD\n p = 2 * p % MOD\n }\n }\n }\n val total = (dp(n)(0) + dp(n)(1)) % MOD\n counts(kh) = (total - prev + MOD) % MOD\n prev = total\n }\n\n var res = 0L\n for (kh <- 1 to n) {\n for (kv <- 1 to n) {\n if (kh * kv < k) res = (res + counts(kh) * counts(kv)) % MOD\n }\n }\n\n println(res * TWO.modInverse(MODB) % MOD)\n}\n"}], "negative_code": [{"source_code": "object E 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, k) = readInts(2)\n val MOD = 998244353L\n val MODB = BigInt(MOD)\n val TWO = BigInt(2)\n\n val counts = Array.fill(n + 1)(0L)\n for (kh <- 1 to (k min n)) {\n val dp = Array.fill(n + 1, 2)(0L)\n for (i <- 1 to n) {\n if (i <= kh) {\n val pp = TWO.modPow((i min kh) - 1, MODB).toLong\n dp(i)(0) = pp\n dp(i)(1) = pp\n } else {\n var p = 1L\n for (j <- 1 to (i min kh)) {\n dp(i)(0) = (dp(i)(0) + dp(i - j)(1)) % MOD\n dp(i)(1) = (dp(i)(1) + dp(i - j)(0)) % MOD\n p = 2 * p % MOD\n }\n }\n// val p = TWO.modPow((i min kh) - 1, MODB).toLong\n// if (i <= kh) {\n// dp(i)(0) = p\n// dp(i)(1) = p\n// } else {\n// dp(i)(0) = p * dp(i - kh)(1) % MOD\n// dp(i)(1) = p * dp(i - kh)(0) % MOD\n// }\n }\n //println(kh, dp.map(_.sum).mkString(\" \"))\n counts(kh) = (dp(n)(0) + dp(n)(1) + MOD - counts(kh - 1)) % MOD\n }\n//println(counts.mkString(\" \"))\n var res = 0L\n for (kh <- 1 to n) {\n for (kv <- 1 to n) {\n //println(res, counts(kh), counts(kv))\n if (kh * kv < k) res = (res + counts(kh) * counts(kv)) % MOD\n }\n }\n\n println(res * TWO.modInverse(MODB) % MOD)\n}\n"}], "src_uid": "77177b1a2faf0ba4ca1f4d77632b635b"} {"nl": {"description": "Pasha has a positive integer a without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer.Help Pasha count the maximum number he can get if he has the time to make at most k swaps.", "input_spec": "The single line contains two integers a and k (1 ≤ a ≤ 1018; 0 ≤ k ≤ 100).", "output_spec": "Print the maximum number that Pasha can get if he makes at most k swaps.", "sample_inputs": ["1990 1", "300 0", "1034 2", "9090000078001234 6"], "sample_outputs": ["9190", "300", "3104", "9907000008001234"], "notes": null}, "positive_code": [{"source_code": "import java.util.Scanner\n\nobject Main {\n def main(args: Array[String]) {\n val in = new Scanner(System.in)\n val s = in.next\n var k = in.nextInt\n\n val arr = s.toCharArray()\n\n for (i <- 0 to arr.length - 2) {\n var maxPos = -1\n for (j <- i to Math.min(i + k, arr.length - 1))\n if (maxPos == -1 || arr(j) > arr(maxPos))\n maxPos = j\n if (maxPos != 0) {\n while (maxPos > i) {\n var t = arr(maxPos)\n arr(maxPos) = arr(maxPos - 1)\n arr(maxPos - 1) = t\n k = k - 1\n maxPos = maxPos - 1\n }\n }\n }\n\n println(arr.mkString)\n }\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val Array(az, kz) = in.next().split(' ')\n val k = kz.toInt\n val a = az.toCharArray\n\n def solve(data: Array[Char], index: Int, k: Int, ch: Char): Array[Char] =\n if (k == 0 || index == data.length - 1)\n a\n else if (ch <= data(index))\n solve(data, index + 1, k, '9')\n else {\n ((index + 1) to Math.min(data.length - 1, index + k)).find(i => data(i) == ch) match {\n case None => solve(data, index, k, (ch - 1).toChar)\n case Some(i) =>\n val tmp = data(i)\n (i until index by - 1).foreach {\n j => data(j) = data(j - 1)\n }\n data(index) = tmp\n solve(data, index + 1, k + index - i, '9')\n }\n }\n\n def sol(data: Array[Char], k: Int) = {\n solve(data, 0, k, '9')\n }\n\n println(sol(a, k).mkString)\n\n}"}, {"source_code": "import scala.collection.JavaConversions._\nimport scala.collection.mutable.ArraySeq\n\nobject Codeforces435B {\n def main(args: Array[String]) {\n var Array(num, swaps) = scala.io.StdIn.readLine().split(\" \").map(_.toLong)\n val numSeq = ArraySeq(num.toString.toList: _*)\n var i = 0\n while (i < numSeq.length-1 && swaps > 0) {\n var temp = 1\n var maxIndex = 0\n while (temp <= swaps && (i+temp) <= (numSeq.length-1)) {\n if (Integer.parseInt(numSeq(i+maxIndex).toString) < Integer.parseInt(numSeq(i+temp).toString))\n maxIndex = temp\n temp += 1\n }\n swaps -= maxIndex\n while (maxIndex > 0) {\n val t = numSeq(i+maxIndex)\n numSeq(i+maxIndex) = numSeq(i+maxIndex-1)\n numSeq(i+maxIndex-1) = t\n maxIndex -= 1\n }\n i += 1\n }\n println(numSeq.mkString(\"\"))\n }\n}"}, {"source_code": "/**\n * Created by ashione on 14-6-19.\n */\nimport java.util.Scanner\nobject swapNum {\n def main(Arg:Array[String]): Unit= {\n val s = new Scanner(System.in)\n val sl:String = s.next\n val dist = s.nextInt\n val (ans,_,_)=findNum(sl.toList,1,dist)\n ans foreach print\n }\n def findNum(sl:List[Char],start:Int,dist:Int):(List[Char],Int,Int) = {\n if(dist<=0 || start>=sl.length) return (sl,0,0)\n var localtion = start-1\n for(i <- start to start + dist-1 if isl(localtion)) localtion = i\n if(localtion!=start-1) {\n val (sl1, sl2) = sl.splitAt(localtion)\n val (d, e) = sl2.splitAt(1)\n val (a, sl1t) = sl1.splitAt(start - 1)\n val (b, c) = sl1t.splitAt(1)\n findNum(a ::: d ::: b ::: c ::: e, start + 1, dist-(localtion - start+1))\n }\n else findNum(sl,start+1,dist)\n\n }\n\n}\n"}], "negative_code": [{"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val Array(as, ks) = in.next().split(' ')\n val k = ks.toInt\n val a = as.toCharArray\n val r = (1 to k).foreach { _ =>\n val i = (1 until a.length).find(i => a(i) > a(i - 1))\n if (i.nonEmpty) {\n val tmp = a(i.get)\n a(i.get) = a(i.get - 1)\n a(i.get - 1) = tmp\n }\n\n }\n println(a.mkString)\n}\n"}, {"source_code": "/**\n * Created by ashione on 14-6-19.\n */\nimport java.util.Scanner\nobject swapNum {\n def main(Arg:Array[String]): Unit= {\n val s = new Scanner(System.in)\n val sl:String = s.next\n val dist = s.nextInt\n val (ans,_,_)=findNum(sl.toList,1,dist)\n ans foreach print\n }\n def findNum(sl:List[Char],start:Int,dist:Int):(List[Char],Int,Int) = {\n if(dist<=0 || start>=sl.length) return (sl,0,0)\n var localtion = start-1\n for(i <- start to start + dist-1 if isl(localtion)) localtion = i\n if(localtion!=start-1) {\n val (sl1, sl2) = sl.splitAt(localtion)\n val (d, e) = sl2.splitAt(1)\n val (a, sl1t) = sl1.splitAt(start - 1)\n val (b, c) = sl1t.splitAt(1)\n findNum(a ::: d ::: c ::: b ::: e, start + 1, localtion - start)\n }\n else findNum(sl,start+1,dist)\n\n }\n\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject Main {\n def main(args: Array[String]) {\n val in = new Scanner(System.in)\n val s = in.next\n var k = in.nextInt\n\n val arr = s.toCharArray()\n\n while (k > 0) {\n k = k - 1\n def loop(i: Int): Unit =\n if (i < arr.length - 1) {\n if (arr(i) < arr(i + 1)) {\n val t = arr(i)\n arr(i) = arr(i + 1)\n arr(i + 1) = t\n } else loop(i + 1)\n }\n loop(0)\n }\n\n println(arr.mkString)\n }\n}"}, {"source_code": "import java.util.Scanner\n\nobject Main {\n def main(args: Array[String]) {\n val in = new Scanner(System.in)\n val s = in.next\n var k = in.nextInt\n\n val arr = s.toCharArray()\n\n for (i <- 0 to arr.length - 2) {\n var maxPos = 0\n for (j <- i to Math.min(i + k, arr.length - 1))\n if (arr(j) > arr(maxPos) || maxPos == 0)\n maxPos = j\n if (maxPos != 0) {\n while (maxPos > i) {\n var t = arr(maxPos)\n arr(maxPos) = arr(maxPos - 1)\n arr(maxPos - 1) = t\n k = k - 1\n maxPos = maxPos - 1\n }\n }\n }\n\n println(arr.mkString)\n }\n}"}], "src_uid": "e56f6c343167745821f0b18dcf0d0cde"} {"nl": {"description": "Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?", "input_spec": "The first and the only line of the input contains two distinct integers n and m (1 ≤ n, m ≤ 104), separated by a space .", "output_spec": "Print a single number — the minimum number of times one needs to push the button required to get the number m out of number n.", "sample_inputs": ["4 6", "10 1"], "sample_outputs": ["2", "9"], "notes": "NoteIn the first example you need to push the blue button once, and then push the red button once.In the second example, doubling the number is unnecessary, so we need to push the blue button nine times."}, "positive_code": [{"source_code": "import java.io._\nimport java.util.StringTokenizer\n\nobject TwoButtons {\n def main(args: Array[String]): Unit = {\n val in = new InputReader(System.in)\n val out = new PrintWriter(new BufferedOutputStream(System.out))\n val solver = new Task()\n solver.solve(in, out)\n out.close()\n }\n\n class Task {\n private val INF = 1e6.asInstanceOf[Int]\n\n def solve(in: InputReader, out: PrintWriter): Unit = {\n val n = in.nextInt()\n val m = in.nextInt()\n val ans = dfs(n, m, Array.ofDim[Int](math.max(n, m) + 1))\n out.println(ans)\n }\n\n private def dfs(n: Int, m: Int, memo: Array[Int]): Int = {\n if (n >= m) n - m\n else if (n <= 0) INF\n else if (memo(n) > 0) memo(n)\n else {\n memo(n) = INF\n memo(n) = math.min(dfs(n * 2, m, memo), dfs(n - 1, m, memo)) + 1\n memo(n)\n }\n }\n }\n\n class InputReader(val stream: InputStream) {\n private val reader = new BufferedReader(new InputStreamReader(stream))\n private var tokenizer: StringTokenizer = _\n\n def next(): String = {\n while (tokenizer == null || !tokenizer.hasMoreTokens) {\n try {\n tokenizer = new StringTokenizer(reader.readLine())\n } catch {\n case _: IOException => throw new RuntimeException\n }\n }\n tokenizer.nextToken()\n }\n\n def nextInt(): Int = {\n Integer.parseInt(next())\n }\n }\n\n}\n"}, {"source_code": "import java.io._\nimport java.util.StringTokenizer\n\nobject TwoButtons {\n def main(args: Array[String]): Unit = {\n val inputStream = System.in\n val outputStream = System.out\n val in = new InputReader(inputStream)\n val out = new PrintWriter(outputStream)\n val solver = new Task()\n solver.solve(in, out)\n out.close()\n }\n\n class Task {\n private val INF = 1e6.asInstanceOf[Int]\n\n def solve(in: InputReader, out: PrintWriter): Unit = {\n val n = in.nextInt()\n val m = in.nextInt()\n val ans = dfs(n, m, Array.ofDim[Int](math.max(n, m) + 1))\n out.println(ans)\n }\n\n private def dfs(n: Int, m: Int, memo: Array[Int]): Int = {\n if (n >= m) n - m\n else if (n <= 0) INF\n else if (memo(n) > 0) memo(n)\n else {\n memo(n) = INF\n memo(n) = math.min(dfs(n * 2, m, memo), dfs(n - 1, m, memo)) + 1\n memo(n)\n }\n }\n }\n\n class InputReader(val stream: InputStream) {\n private val reader = new BufferedReader(new InputStreamReader(stream))\n private var tokenizer: StringTokenizer = _\n\n def next(): String = {\n while (tokenizer == null || !tokenizer.hasMoreTokens) {\n try {\n tokenizer = new StringTokenizer(reader.readLine())\n } catch {\n case _: IOException => throw new RuntimeException\n }\n }\n tokenizer.nextToken()\n }\n\n def nextInt(): Int = {\n Integer.parseInt(next())\n }\n }\n\n}\n"}, {"source_code": "object TwoButtons {\n case class Pair(e:Int,stp:Int)\n def main(args: Array[String]): Unit = {\n val in =scala.io.StdIn\n var line=in.readLine()\n var n=line.split(\" \")(0).toInt\n var m=line.split(\" \")(1).toInt\n //val n=4 ; val m=6\n //val n=10 ; val m=1\n //Applying BSF and in level order search the first occurrence of m is the minimum step\n var click=0\n\twhile (m!=n){\n\t click+=1\n\t if(m>n) {\n\t\tif (m % 2 == 0) {\n\t\t m /= 2\n\t\t} else {\n\t\t m = (m + 1) / 2\n\t\t click+=1\n\t\t}\n\t }else{\n\t\tm+=1\n\t }\n\t}\n\tprintln(click)\n }\n}"}, {"source_code": "import scala.collection.mutable\n\nobject B520 {\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 val MAX = 2*10000\n val graph = Array.fill(MAX+1)(List.empty[Int])\n graph(1) = List(2)\n for(i <- 2 to MAX) {\n graph(i) = List(2*i, i-1)\n }\n def bfs(src: Int, des: Int): Int = {\n val vis = Array.fill(MAX+1)(false)\n val q = mutable.Queue.empty[(Int, Int)]\n q.enqueue((0, src))\n vis(src) = true\n while(q.nonEmpty) {\n val (dist, ele) = q.dequeue()\n if(des == ele) {\n return dist\n }\n if(ele <= MAX) {\n for (i <- graph(ele) if i <= MAX && !vis(i)) {\n q.enqueue((dist + 1, i))\n vis(i) = true\n }\n }\n }\n -1\n }\n def main(args: Array[String]): Unit = {\n var Array(n, m) = readInts(2)\n println(bfs(n, m))\n }\n\n}"}, {"source_code": "\n/**\n * Created by yangchaozhong on 3/16/15.\n */\nobject CF520B extends App {\n import scala.collection.mutable.HashSet\n import java.util.{Scanner}\n import java.io.{PrintWriter}\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 def nextLine = in.nextLine\n\n def solve = {\n val n = nextInt\n val m = nextInt\n\n if (n >= m) {\n out.println(n - m)\n } else {\n\n def dfs(x: Int): Int = {\n if (x == n) 0\n else if (x < n) {\n n - x\n } else {\n if (x % 2 == 0) {\n dfs(x / 2) + 1\n } else {\n dfs(x + 1) + 1\n }\n }\n }\n\n out.println(dfs(m))\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"}, {"source_code": "import java.io._\nimport java.util.StringTokenizer\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 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 f(n: Int, m: Int, dp: Array[Int]): Int = {\n if (n >= m) {\n return n - m\n }\n if (n <= 0) {\n return 1e6.toInt\n }\n if (dp(n) > 0) {\n return dp(n)\n }\n dp(n) = 1e6.toInt\n dp(n) = Math.min(f(2 * n, m, dp), f(n - 1, m, dp)) + 1\n return dp(n)\n }\n\n def solve: Int = {\n val n = nextInt\n val m = nextInt\n val sz = Math.max(n, m)\n val dp = new Array[Int](sz + 1)\n out.println(f(n, m, dp))\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}"}, {"source_code": "import scala.collection.mutable\nimport scala.collection.mutable.ArrayBuffer\nimport scala.io.StdIn._\n\nobject Main2 extends App {\n val Array(initialNumber, desiredNumber) = readLine().split(\" \").map(_.toInt)\n val queue = mutable.Queue((initialNumber, 0))\n var answers = ArrayBuffer.fill(20001)(-1)\n while (queue.nonEmpty) {\n val (value, actionCount) = queue.dequeue()\n if (value - 1 > 0 && answers(value - 1) == -1) {\n answers(value - 1) = actionCount + 1\n queue.enqueue((value - 1, actionCount + 1))\n }\n if (value * 2 < 20001 && answers(value * 2) == -1) {\n answers(value * 2) = actionCount + 1\n queue.enqueue((value * 2, actionCount + 1))\n }\n }\n println(answers(desiredNumber))\n}\n"}], "negative_code": [{"source_code": "object TwoButtons {\n case class Pair(e:Int,stp:Int)\n def main(args: Array[String]): Unit = {\n val in =scala.io.StdIn\n var line=in.readLine()\n var n=line.split(\" \")(0).toInt\n var m=line.split(\" \")(1).toInt\n //val n=4 ; val m=6\n //val n=10 ; val m=1\n //Applying BSF and in level order search the first occurrence of m is the minimum step\n var click=0\n\twhile (m!=n){\n\t click+=1\n\t if(m>n) {\n\t\tif (m % 2 == 0) {\n\t\t m /= 2\n\t\t} else {\n\t\t m = (m + 1) / 2\n\t\t}\n\t }else{\n\t\tm+=1\n\t }\n\t}\n\tprintln(click)\n }\n}"}, {"source_code": "object B520 {\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) = readInts(2)\n if(n > m) {\n println(n-m)\n } else {\n if (m % 2 == 0) {\n var res = 0\n while(m % 2 == 0 && n < m) {\n m /= 2\n res += 1\n }\n println(res + (n-m))\n } else {\n var res = 0\n while(n < m) {\n n *= 2\n res += 1\n }\n println(res + n-m)\n }\n }\n }\n\n}"}, {"source_code": "/**\n * Created by yangchaozhong on 3/16/15.\n */\nobject CF520B extends App {\n import java.util.{Scanner}\n import java.io.{PrintWriter}\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 def nextLine = in.nextLine\n\n def solve = {\n val n = nextInt\n val m = nextInt\n\n if (n >= m) {\n out.println(n - m)\n } else {\n def dfs(x: Int): Int = {\n if (x == m) 0\n else if (x > m) {\n x - m\n } else {\n if (x > m / 2 && x > 2)\n Math.min(dfs(x * 2) + 1, dfs(x - 1) + 1)\n else\n dfs(x * 2) + 1\n }\n }\n\n out.println(dfs(n))\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"}, {"source_code": "import java.io._\nimport java.util\nimport java.util._\n\nobject B {\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 n = nextInt\n val m = nextInt\n if (m < n) {\n out.println(n - m)\n return 1\n }\n if (m == n) {\n out.println(0)\n return 1\n }\n var y = m\n var ans = 0\n while (y % 2 == 0) {\n y /= 2\n ans += 1\n }\n val sz = Math.max(n, y)\n val dp = new Array[Array[Int]](sz + 1)\n for (i <- 0 until sz + 1) {\n dp(i) = new Array[Int](sz + 1)\n }\n\n for (i <- 0 to sz) {\n for (j <- i + 1 until sz) {\n dp(i)(j) = j - i\n }\n }\n for (i <- 1 to sz) {\n for (j <- 1 to sz) {\n if (i * 2 <= sz) {\n dp(i)(j) = Math.min(dp(i - 1)(j), dp(i * 2)(j)) + 1\n }\n else {\n dp(i)(j) = dp(i - 1)(j) + 1\n }\n }\n }\n out.println(dp(y - 1)(y - 1) + 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"}, {"source_code": "import java.io._\nimport java.util\nimport java.util._\n\nobject B {\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 n = nextInt\n val m = nextInt\n if (m < n) {\n out.println(n - m)\n return 1\n }\n if (m == n) {\n out.println(0)\n return 1\n }\n var x = n\n var y = m\n var ans = 0\n while (y > n && y % 2 == 0) {\n y /= 2\n ans += 1\n }\n while (x < y) {\n x *= 2\n ans += 1\n }\n if (y < x) {\n out.println(ans + x - y)\n return 1\n }\n if (y == x) {\n out.println(ans)\n return 1\n }\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"}, {"source_code": "import java.io._\nimport java.util\nimport java.util._\n\nobject B {\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 n = nextInt\n val m = nextInt\n if (m < n) {\n out.println(n - m)\n return 1\n }\n if (m == n) {\n out.println(0)\n return 1\n }\n var x = n\n var ans = 0\n while (x < m) {\n x *= 2\n ans += 1\n }\n if (m % 2 == 0 && n > m / 2) {\n out.println(Math.min(n - m / 2 + 1, ans + x - m))\n } else {\n out.println(ans + x - m)\n }\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": "861f8edd2813d6d3a5ff7193a804486f"} {"nl": {"description": "Two beavers, Timur and Marsel, play the following game.There are n logs, each of exactly m meters in length. The beavers move in turns. For each move a beaver chooses a log and gnaws it into some number (more than one) of equal parts, the length of each one is expressed by an integer and is no less than k meters. Each resulting part is also a log which can be gnawed in future by any beaver. The beaver that can't make a move loses. Thus, the other beaver wins.Timur makes the first move. The players play in the optimal way. Determine the winner.", "input_spec": "The first line contains three integers n, m, k (1 ≤ n, m, k ≤ 109).", "output_spec": "Print \"Timur\", if Timur wins, or \"Marsel\", if Marsel wins. You should print everything without the quotes. ", "sample_inputs": ["1 15 4", "4 9 5"], "sample_outputs": ["Timur", "Marsel"], "notes": "NoteIn the first sample the beavers only have one log, of 15 meters in length. Timur moves first. The only move he can do is to split the log into 3 parts each 5 meters in length. Then Marsel moves but he can't split any of the resulting logs, as k = 4. Thus, the winner is Timur.In the second example the beavers have 4 logs 9 meters in length. Timur can't split any of them, so that the resulting parts possessed the length of not less than 5 meters, that's why he loses instantly."}, "positive_code": [{"source_code": "import java.io.ByteArrayInputStream\n\nobject Main {\n\n def main(args: Array[String]) = {\n /** setup **/\n var debug: Object => Unit = null\n if (!args.isEmpty && args.head == \"test\") {\n debug = println\n val TEST = \"2 100000 569\\n605 986\"\n System.setIn(new ByteArrayInputStream(TEST.getBytes))\n } else {\n debug = a => Unit\n }\n val input = scala.io.Source.stdin.getLines()\n\n /** parse **/\n\n val line = input.next().split(\" \").map(_.toInt)\n val (n, m, k) = (line(0), line(1), line(2))\n\n var sol = \"\"\n val p1 = \"Timur\"\n val p2 = \"Marsel\"\n /** algorithm **/\n\n if (n % 2 == 0) sol = p2\n else if (k == m) sol = p2\n else if (k != 0 && k != 1 && (2 to (Math.ceil(Math.sqrt(m)).toInt)).find(i => m % i == 0 && m / i >= k).isEmpty) sol = p2\n else sol = p1\n /** print **/\n println(sol)\n }\n}"}], "negative_code": [{"source_code": "\nobject Main {\n\n def main(args: Array[String]) = {\n val input = scala.io.Source.stdin.getLines()\n\n val a = input.next().split(\" \").map(_.toInt).toList.toArray\n\n val sum = a.sum\n\n var cu = 0\n var p = 0\n\n var l = List.empty[Char]\n while (cu < sum) {\n if (a(p) == 0) {\n l = 'R' :: l\n p += 1\n } else if (p == a.length - 1) {\n l = 'R' :: 'L' :: 'P' :: l\n a(p) -= 1\n cu += 1\n } else if (p+1 < a.size && a(p+1) > 0 && a(p) > 1) {\n l = 'L' :: 'P' :: 'R' :: 'P' :: l\n cu += 2\n a(p) -= 1\n a(p+1) -= 1\n } else if (a(p) > 1) {\n l = 'L' :: 'R' :: 'P' :: l\n a(p) -= 1\n cu += 1\n } else {\n l = 'R' :: 'P' :: l\n a(p) -= 1\n cu += 1\n p += 1\n }\n }\n while (l.head != 'P') l = l.tail\n print(l.reverse.mkString)\n }\n}"}, {"source_code": "import java.io.ByteArrayInputStream\n\nobject Main {\n\n def main(args: Array[String]) = {\n /** setup **/\n var debug: Object => Unit = null\n if (!args.isEmpty && args.head == \"test\") {\n debug = println\n val TEST = \"2 100000 569\\n605 986\"\n System.setIn(new ByteArrayInputStream(TEST.getBytes))\n } else {\n debug = a => Unit\n }\n val input = scala.io.Source.stdin.getLines()\n\n /** parse **/\n\n val line = input.next().split(\" \").map(_.toInt)\n val (n, m, k) = (line(0), line(1), line(2))\n\n var sol = \"\"\n val p1 = \"Timur\"\n val p2 = \"Marsel\"\n /** algorithm **/\n\n if (n % 2 == 0) sol = p2\n else if (m % k != 0) sol = p2\n else sol = p1\n /** print **/\n println(sol)\n }\n}"}, {"source_code": "import java.io.ByteArrayInputStream\n\nobject Main {\n\n def main(args: Array[String]) = {\n /** setup **/\n var debug: Object => Unit = null\n if (!args.isEmpty && args.head == \"test\") {\n debug = println\n val TEST = \"2 100000 569\\n605 986\"\n System.setIn(new ByteArrayInputStream(TEST.getBytes))\n } else {\n debug = a => Unit\n }\n val input = scala.io.Source.stdin.getLines()\n\n /** parse **/\n\n val line = input.next().split(\" \").map(_.toInt)\n val (n, m, k) = (line(0), line(1), line(2))\n\n var sol = \"\"\n val p1 = \"Timur\"\n val p2 = \"Marsel\"\n /** algorithm **/\n\n if (n % 2 == 0) sol = p2\n else if ((k until m).find(i => m % i == 0).nonEmpty) sol = p2\n else sol = p1\n /** print **/\n println(sol)\n }\n}"}, {"source_code": "import java.io.ByteArrayInputStream\n\nobject Main {\n\n def main(args: Array[String]) = {\n /** setup **/\n var debug: Object => Unit = null\n if (!args.isEmpty && args.head == \"test\") {\n debug = println\n val TEST = \"2 100000 569\\n605 986\"\n System.setIn(new ByteArrayInputStream(TEST.getBytes))\n } else {\n debug = a => Unit\n }\n val input = scala.io.Source.stdin.getLines()\n\n /** parse **/\n\n val line = input.next().split(\" \").map(_.toInt)\n val (n, m, k) = (line(0), line(1), line(2))\n\n var sol = \"\"\n val p1 = \"Timur\"\n val p2 = \"Marsel\"\n /** algorithm **/\n\n if (n % 2 == 0) sol = p2\n else if (k != 0 && k != 1 && (2 to (Math.ceil(Math.sqrt(m)).toInt)).find(i => m % i == 0 && m / i >= k).isEmpty) sol = p2\n else sol = p1\n /** print **/\n println(sol)\n }\n}"}, {"source_code": "import java.io.ByteArrayInputStream\n\nobject Main {\n\n def main(args: Array[String]) = {\n /** setup **/\n var debug: Object => Unit = null\n if (!args.isEmpty && args.head == \"test\") {\n debug = println\n val TEST = \"2 100000 569\\n605 986\"\n System.setIn(new ByteArrayInputStream(TEST.getBytes))\n } else {\n debug = a => Unit\n }\n val input = scala.io.Source.stdin.getLines()\n\n /** parse **/\n\n val line = input.next().split(\" \").map(_.toInt)\n val (n, m, k) = (line(0), line(1), line(2))\n\n var sol = \"\"\n val p1 = \"Timur\"\n val p2 = \"Marsel\"\n /** algorithm **/\n\n if (n % 2 == 0) sol = p2\n else if ((k until (Math.sqrt(m).toInt + 1)).find(i => m % i == 0).isEmpty) sol = p2\n else sol = p1\n /** print **/\n println(sol)\n }\n}"}, {"source_code": "import java.io.ByteArrayInputStream\n\nobject Main {\n\n def main(args: Array[String]) = {\n /** setup **/\n var debug: Object => Unit = null\n if (!args.isEmpty && args.head == \"test\") {\n debug = println\n val TEST = \"2 100000 569\\n605 986\"\n System.setIn(new ByteArrayInputStream(TEST.getBytes))\n } else {\n debug = a => Unit\n }\n val input = scala.io.Source.stdin.getLines()\n\n /** parse **/\n\n val line = input.next().split(\" \").map(_.toInt)\n val (n, m, k) = (line(0), line(1), line(2))\n\n var sol = \"\"\n val p1 = \"Timur\"\n val p2 = \"Marsel\"\n /** algorithm **/\n\n if (n % 2 == 0) sol = p2\n else if ((k to (Math.sqrt(m).toInt + 1)).find(i => m % i == 0).isEmpty) sol = p2\n else sol = p1\n /** print **/\n println(sol)\n }\n}"}], "src_uid": "4a3767011ddac874efa021fff7c94432"} {"nl": {"description": "Let's define a split of $$$n$$$ as a nonincreasing sequence of positive integers, the sum of which is $$$n$$$. For example, the following sequences are splits of $$$8$$$: $$$[4, 4]$$$, $$$[3, 3, 2]$$$, $$$[2, 2, 1, 1, 1, 1]$$$, $$$[5, 2, 1]$$$.The following sequences aren't splits of $$$8$$$: $$$[1, 7]$$$, $$$[5, 4]$$$, $$$[11, -3]$$$, $$$[1, 1, 4, 1, 1]$$$.The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $$$[1, 1, 1, 1, 1]$$$ is $$$5$$$, the weight of the split $$$[5, 5, 3, 3, 3]$$$ is $$$2$$$ and the weight of the split $$$[9]$$$ equals $$$1$$$.For a given $$$n$$$, find out the number of different weights of its splits.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\leq n \\leq 10^9$$$).", "output_spec": "Output one integer — the answer to the problem.", "sample_inputs": ["7", "8", "9"], "sample_outputs": ["4", "5", "5"], "notes": "NoteIn the first sample, there are following possible weights of splits of $$$7$$$:Weight 1: [$$$\\textbf 7$$$] Weight 2: [$$$\\textbf 3$$$, $$$\\textbf 3$$$, 1] Weight 3: [$$$\\textbf 2$$$, $$$\\textbf 2$$$, $$$\\textbf 2$$$, 1] Weight 7: [$$$\\textbf 1$$$, $$$\\textbf 1$$$, $$$\\textbf 1$$$, $$$\\textbf 1$$$, $$$\\textbf 1$$$, $$$\\textbf 1$$$, $$$\\textbf 1$$$]"}, "positive_code": [{"source_code": "\n\nobject CF964A extends App {\n import scala.io.Source\n\n //val src = Source.fromFile(\"data.txt\")\n val src = Source.stdin\n val lines = src.getLines\n \n def readInts(): Array[Int] = {\n val line = if (lines.hasNext) lines.next else null\n if (line == null) throw new RuntimeException(\"Premature end of source encountered\")\n line.split(\" \").map(x => x.toInt)\n }\n val ints = readInts()\n println(ints(0)/2 + 1)\n \n}"}, {"source_code": "object _964A 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]\n io.write(n/2 + 1)\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\n\nclass IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {\n import IO._\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: 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 private[IO] type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]\n\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.head)\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"}], "negative_code": [], "src_uid": "5551742f6ab39fdac3930d866f439e3e"} {"nl": {"description": "Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.", "input_spec": "The only line of the input contains a single integer n (2 ≤ n ≤ 1018) — the number of players to participate in the tournament.", "output_spec": "Print the maximum number of games in which the winner of the tournament can take part.", "sample_inputs": ["2", "3", "4", "10"], "sample_outputs": ["1", "2", "2", "4"], "notes": "NoteIn all samples we consider that player number 1 is the winner.In the first sample, there would be only one game so the answer is 1.In the second sample, player 1 can consequently beat players 2 and 3. In the third sample, player 1 can't play with each other player as after he plays with players 2 and 3 he can't play against player 4, as he has 0 games played, while player 1 already played 2. Thus, the answer is 2 and to achieve we make pairs (1, 2) and (3, 4) and then clash the winners."}, "positive_code": [{"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val n = in.next().toLong\n var i = 0\n var a = 1l\n var b = 1l\n while (b <= n) {\n val tmp = a + b\n a = b\n b = tmp\n i += 1\n }\n println(i - 1)\n}\n"}, {"source_code": "import java.io._\nimport scala.io.Source\n\nimport scala.annotation.tailrec\n\nobject ProblemCFib {\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().toLong\n val soln = solve(n)\n bw.write(soln.toString)\n bw.newLine()\n }\n\n // Cache the Fibonacci lookup for good performance:\n var minPlayersByChampionsWinsLookup = Map[Long, Long](\n 0L -> 1L, // A single player is champion without playing a single match\n 1L -> 2L // With 2 players the champion wins after a single match\n )\n\n // The following function is equivalent to fib(wins + 2) where fib is the Fibonacci sequence\n def minPlayersForChampionWithWins(wins: Long): Long = {\n if (minPlayersByChampionsWinsLookup.contains(wins)) {\n minPlayersByChampionsWinsLookup(wins)\n } else {\n val result = minPlayersForChampionWithWins(wins - 1) + minPlayersForChampionWithWins(wins - 2)\n minPlayersByChampionsWinsLookup += wins -> result\n result\n }\n }\n\n def solve(n: Long): Long = {\n @tailrec\n def search(candidateWins: Long): Long = {\n val minTournamentSize = minPlayersForChampionWithWins(candidateWins)\n\n if (minTournamentSize == n) candidateWins\n else if (minTournamentSize > n) (candidateWins - 1) // overshot the target, so use previous value\n else search(candidateWins + 1)\n }\n\n search(0)\n }\n}\n"}, {"source_code": "import scala.collection.mutable\n\nobject A extends App {\n def readLongs = scala.io.StdIn.readLine().split(\" \").map(_.toLong)\n\n val Array(n) = readLongs\n\n case class E(prev: Long, cur: Long, games : Int) {\n def next = E(cur, prev+cur, games+1)\n }\n\n var e = E(1, 1, 0)\n while (e.cur <= n) {\n e = e.next\n // println(e)\n }\n\n println(e.games-1)\n}\n"}, {"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) = readLongs(1)\n\n var res = 1\n val memo = Array.fill(100000){ -1L }\n\n memo(1) = 2\n memo(2) = 3\n\n def minPlayers(moves: Int): Long = {\n if (memo(moves) < 0) memo(moves) = minPlayers(moves - 1) + minPlayers(moves - 2)\n memo(moves)\n }\n\n while (minPlayers(res) <= n) res += 1\n\n println(res - 1)\n}\n"}], "negative_code": [{"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val n = in.next().toLong\n var i = 0\n var a = 1l\n var b = 1l\n while (b < n) {\n val tmp = a + b\n a = b\n b = tmp\n i += 1\n }\n println(i - 1)\n}\n"}, {"source_code": "import java.io._\nimport scala.io.Source\n\nimport scala.annotation.tailrec\n\nobject ProblemC {\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().toLong\n val log2 = math.log(2)\n val rounds = math.ceil(math.log(n) / log2) + 0.1\n // note: bump it slightly in case of round errors like a ?.999999 \"integer\"\n bw.write(rounds.toLong.toString)\n bw.newLine()\n }\n}\n"}, {"source_code": "import java.io._\nimport scala.io.Source\n\nimport scala.annotation.tailrec\n\nobject ProblemC {\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().toLong\n val soln = solve(n)\n bw.write(soln.toString)\n bw.newLine()\n }\n\n def solve(n: Long): Long = {\n @tailrec\n def loop(minGames: Long, counts: List[Long]): Long = counts match {\n case 0 :: tl => loop(minGames + 1, tl)\n case 1 :: Nil => minGames\n case a :: Nil => loop(minGames, List(a - 2, 1))\n case 1 :: 1 :: Nil => minGames + 2\n case 1 :: 1 :: c :: tl => loop(minGames + 2, (c + 1) :: tl)\n case 2 :: 1 :: tl => loop(minGames + 1, 2 :: tl) // Don't leave an \"orphaned\" player\n case a :: 0 :: tl => loop(minGames, (a - 2) :: 1l :: tl)\n case a :: b :: Nil => loop(minGames, List(a - 1, b - 1, 1))\n case a :: b :: c :: tl => loop(minGames, (a - 1) :: (b - 1) :: (c + 1) :: tl)\n case Nil => 0\n }\n\n val maxGamesPlayed = loop(0, List(n))\n maxGamesPlayed\n }\n}\n"}, {"source_code": "import java.io._\nimport scala.io.Source\n\nimport scala.annotation.tailrec\n\nobject ProblemC {\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().toDouble\n val log2 = math.log(2)\n val rounds = math.ceil(math.log(n) / log2).toLong\n val adjRounds = if (math.pow(2, rounds) < n) rounds + 1\n else if (math.pow(2, rounds - 1) >= n) rounds - 1\n else rounds\n bw.write(adjRounds.toString)\n bw.newLine()\n }\n}\n"}], "src_uid": "3d3432b4f7c6a3b901161fa24b415b14"} {"nl": {"description": "A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total.If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.", "input_spec": "The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements. The third line contains k space-separated integers b1, b2, ..., bk (1 ≤ bi ≤ 200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in a and b more than once in total.", "output_spec": "Output \"Yes\" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and \"No\" otherwise.", "sample_inputs": ["4 2\n11 0 0 14\n5 4", "6 1\n2 3 0 8 9 10\n5", "4 1\n8 94 0 4\n89", "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7"], "sample_outputs": ["Yes", "No", "Yes", "Yes"], "notes": "NoteIn the first sample: Sequence a is 11, 0, 0, 14. Two of the elements are lost, and the candidates in b are 5 and 4. There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is \"Yes\". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid."}, "positive_code": [{"source_code": "import scala.io.Source\n\n/** A. An abandoned sentiment from past\n * time limit per test1 second\n * memory limit per test256 megabytes\n *\n * A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight.\n * Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.\n *\n * To get rid of the oddity and recover her weight, a special integer sequence is needed.\n * Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.\n *\n * Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b,\n * whose length k equals the number of lost elements in a (i.e. the number of zeros).\n *\n * Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once.\n * Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total.\n * If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity.\n * You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words,\n * you should detect whether it is possible to replace each zero in a with an integer from b so that each integer\n * from b is used exactly once, and the resulting sequence is not increasing.\n */\nobject P814A {\n /** get integer seqence `a`. the length of sequence is n\n *\n * @param args\n */\n def main(args: Array[String]): Unit = {\n val lines = Source.stdin.getLines()\n\n val Array(n, k) = lines.next().split(\" \")\n\n /** n-length arr with k zero values */\n val a = lines.next().split(\" \").map(_.toInt).toList\n\n /** k-length arr */\n val b = lines.next().split(\" \").map(_.toInt)\n\n /** Input guarantees that apart from 0, no integer occurs in a and b more than once in total.\n *\n * Detect whether it is possible to replace each zero in a with an integer from b so that each integer\n * from b is used exactly once, and the resulting sequence is not increasing */\n\n def test(a: List[Int], b: Int): Boolean = {\n a match {\n case a0 :: a1 :: tail =>\n if (a1 == 0) test(a0 :: b :: tail, b)\n else {\n if (a0 > a1) true\n else test(a1 :: tail, b)\n }\n case _ => false\n }\n }\n\n val result =\n if (b.length > 1) true\n else if (a.head == 0) test(b.head :: a.tail, b.head)\n else test(a, b.head)\n\n if (result) println(\"Yes\")\n else println(\"No\")\n }\n}\n\n"}, {"source_code": "\nimport java.io._\nimport java.util._\n\nimport scala.collection.mutable\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 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 sorted(a: Array[Int]): Boolean = {\n for (i <- 1 until a.length) {\n if (a(i) < a(i - 1)) {\n return false\n }\n }\n true\n }\n\n def solve: Int = {\n val n = nextInt\n val k = nextInt\n val a = new Array[Int](n)\n val b = new Array[Int](k)\n for (i <- 0 until n) {\n a(i) = nextInt\n }\n for (i <- 0 until k) {\n b(i) = nextInt\n }\n if (k > 1) {\n out.println(\"Yes\")\n return 0\n }\n val pos = a.indexOf(0)\n a(pos) = b(0)\n if (sorted(a)) {\n out.println(\"No\")\n } else {\n out.println(\"Yes\")\n }\n return 0\n }\n}\n"}, {"source_code": "object EightOneFourA {\n def checkIfSeqAsc(seq: Seq[Int]): Boolean = {\n val startValue = Int.MinValue\n seq.foldLeft((true, startValue)) {\n case ((isSorted, previousValue), currentValue) => {\n (isSorted && (currentValue >= previousValue), currentValue)\n }\n }._1\n }\n\n def main(args: Array[String]): Unit = {\n val input = readLine().toString.split(\" \")\n val stringA = readLine().toString.split(\" \")\n val stringB = readLine().toString.split(\" \")\n\n if (input(1).toInt > 1) {\n println(\"YES\")\n } else {\n val finalArray = stringA.map(_.toInt).map(p => {\n if (p == 0) {\n stringB(0).toInt\n } else {\n p\n }\n })\n\n if (checkIfSeqAsc(finalArray)) {\n println(\"NO\")\n } else {\n println(\"YES\")\n }\n }\n }\n}\n"}, {"source_code": "/**\n * Created by Hyper on 22.06.2017.\n */\nimport scala.io.StdIn\nobject cf extends App{\n def checkNonAscending(l: List[Int]):String ={\n l match {\n case head::tail::Nil => if(head > tail) \"Yes\" else \"No\"\n case head::tail => if(head > tail.head) \"Yes\" else checkNonAscending(tail)\n }\n }\n def replace(a: List[Int], b: Int): List[Int] ={\n a match{\n case Nil => Nil\n case 0 :: tail => b :: tail\n case u :: tail => u :: replace(tail,b)\n }\n }\n val v = StdIn.readLine().split(\" \").toList\n val n = v.head.toInt\n val k = v.tail.head.toInt\n val A = StdIn.readLine().split(\" \").toList.map(s => s.toInt)\n val B = StdIn.readLine().split(\" \").toList.map(s => s.toInt)\n if (k > 2) println(\"Yes\")\n else println(checkNonAscending(replace(A,B.head)))\n}\n\n"}, {"source_code": "object Hitagi extends App {\n\n def replaceZeros(seq: List[Int], replacement: List[Int]): List[Int] = seq match {\n case Nil => List[Int]()\n case 0 :: xs => replacement.head :: replaceZeros(xs, replacement.tail)\n case x :: xs => x :: replaceZeros(xs, replacement)\n }\n\n val Array(n: Int, k: Int) = readLine.split(' ').map(_.toInt)\n val a: List[Int] = readLine.split(' ').map(_.toInt).toList\n val b: List[Int] = readLine.split(' ').map(_.toInt).toList\n\n val initialSequence = replaceZeros(a, b.sortBy(x => -x))\n val result: Boolean = initialSequence.zip(initialSequence.tail).map {\n case (a, b) => b <= a\n }.exists(x => x)\n\n if (result) println(\"Yes\") else println(\"No\")\n\n}\n"}], "negative_code": [{"source_code": "import scala.io.Source\n\n/** A. An abandoned sentiment from past\n * time limit per test1 second\n * memory limit per test256 megabytes\n *\n * A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight.\n * Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.\n *\n * To get rid of the oddity and recover her weight, a special integer sequence is needed.\n * Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.\n *\n * Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b,\n * whose length k equals the number of lost elements in a (i.e. the number of zeros).\n *\n * Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once.\n * Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total.\n * If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity.\n * You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words,\n * you should detect whether it is possible to replace each zero in a with an integer from b so that each integer\n * from b is used exactly once, and the resulting sequence is not increasing.\n */\nobject P814A {\n /** get integer seqence `a`. the length of sequence is n\n *\n * @param args\n */\n def main(args: Array[String]): Unit = {\n val lines = Source.stdin.getLines()\n\n val Array(n, k) = lines.next().split(\" \")\n\n /** n-length arr with k zero values */\n val a = lines.next().split(\" \").map(_.toInt).toList\n\n /** k-length arr */\n val b = lines.next().split(\" \").map(_.toInt)\n\n /** Input guarantees that apart from 0, no integer occurs in a and b more than once in total.\n *\n * Detect whether it is possible to replace each zero in a with an integer from b so that each integer\n * from b is used exactly once, and the resulting sequence is not increasing */\n\n def test(a: List[Int], b: Int): Boolean = {\n a match {\n case a0 :: a1 :: tail =>\n if (a1 == 0) test(a0 :: b :: tail, b)\n else {\n if (a0 > a1) true\n else test(a1 :: tail, b)\n }\n case _ => false\n }\n }\n\n val result =\n if (b.length > 1) true\n else test(a, b.head)\n\n if (result) println(\"Yes\")\n else println(\"No\")\n }\n}\n\n"}, {"source_code": "\nimport java.io._\nimport java.util._\n\nimport scala.collection.mutable\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 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 sorted(l: Array[Int]): Boolean = l == l.sorted\n\n def solve: Int = {\n val n = nextInt\n val k = nextInt\n val a = new Array[Int](n)\n val b = new Array[Int](k)\n for (i <- 0 until n) {\n a(i) = nextInt\n }\n for (i <- 0 until k) {\n b(i) = nextInt\n }\n if (k > 1) {\n out.println(\"Yes\")\n return 0\n }\n val pos = a.indexOf(0)\n a(pos) = b(0)\n if (sorted(a)) {\n out.println(\"No\")\n } else {\n out.println(\"Yes\")\n }\n return 0\n }\n}\n"}, {"source_code": "\nimport java.io._\nimport java.util._\n\nimport scala.collection.mutable\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 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 solve: Int = {\n val n = nextInt\n val k = nextInt\n val a = new Array[Int](n)\n val b = new Array[Int](k)\n for (i <- 0 until n) {\n a(i) = nextInt\n }\n for (i <- 0 until k) {\n b(i) = nextInt\n }\n if (n == k) {\n out.println(\"Yes\")\n return 0\n }\n for (i <- 1 until n) {\n if (a(i) == 0 && a(i - 1) == 0) {\n out.println(\"Yes\")\n return 0\n }\n }\n for (i <- 0 until n) {\n if (a(i) == 0) {\n if (i - 1 >= 0 && a(i - 1) != 0) {\n for (j <- 0 until k) {\n if (b(j) < a(i - 1)) {\n out.println(\"Yes\")\n return 0\n }\n }\n } else if (i + 1 < n && a(i + 1) != 0) {\n for (j <- 0 until k) {\n if (a(i + 1) != 0 && b(j) > a(i + 1)) {\n out.println(\"Yes\")\n return 0\n }\n }\n }\n }\n }\n out.println(\"No\")\n return 0\n }\n}\n"}, {"source_code": "\nimport java.io._\nimport java.util._\n\nimport scala.collection.mutable\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 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 solve: Int = {\n val n = nextInt\n val k = nextInt\n val a = new Array[Int](n)\n val b = new Array[Int](k)\n for (i <- 0 until n) {\n a(i) = nextInt\n }\n for (i <- 0 until k) {\n b(i) = nextInt\n }\n for (i <- 1 until n) {\n if (a(i) == 0 && a(i - 1) == 0) {\n out.println(\"Yes\")\n return 0\n }\n }\n for (i <- 0 until n) {\n if (a(i) == 0) {\n if (i - 1 >= 0 && a(i - 1) != 0) {\n for (j <- 0 until k) {\n if (b(j) < a(i - 1)) {\n out.println(\"Yes\")\n return 0\n }\n }\n }\n if (i + 1 < n && a(i + 1) != 0) {\n for (j <- 0 until k) {\n if (a(i + 1) != 0 && b(j) > a(i + 1)) {\n out.println(\"Yes\")\n return 0\n }\n }\n }\n }\n }\n out.println(\"No\")\n return 0\n }\n}\n"}, {"source_code": "import java.io._\nimport java.util._\n\nimport scala.collection.mutable\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 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 solve: Int = {\n val n = nextInt\n val k = nextInt\n val a = new Array[Int](n)\n val b = new Array[Int](k)\n for (i <- 0 until n) {\n a(i) = nextInt\n }\n for (i <- 0 until k) {\n b(i) = nextInt\n }\n if (n == k) {\n out.println(\"Yes\")\n return 0\n }\n for (i <- 0 until n) {\n if (a(i) == 0) {\n if (i > 0) {\n for (j <- 0 until k) {\n if (a(i - 1) != 0 && b(j) < a(i - 1)) {\n out.println(\"Yes\")\n return 0\n }\n }\n } else {\n for (j <- 0 until k) {\n if (a(i + 1) != 0 && b(j) > a(i + 1)) {\n out.println(\"Yes\")\n return 0\n }\n }\n }\n }\n }\n out.println(\"No\")\n return 0\n }\n}\n"}, {"source_code": "\nimport java.io._\nimport java.util._\n\nimport scala.collection.mutable\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 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 sorted(l: Array[Int]): Boolean = l == l.sorted\n\n def solve: Int = {\n val n = nextInt\n val k = nextInt\n val a = new Array[Int](n)\n val b = new Array[Int](k)\n for (i <- 0 until n) {\n a(i) = nextInt\n }\n for (i <- 0 until k) {\n b(i) = nextInt\n }\n if (k > 1) {\n out.println(\"Yes\")\n return 0\n }\n val pos = a.indexOf(0)\n a(pos) = b(0)\n if (!sorted(a)) {\n out.println(\"Yes\")\n } else {\n out.println(\"No\")\n }\n return 0\n }\n}\n"}, {"source_code": "\nimport java.io._\nimport java.util._\n\nimport scala.collection.mutable\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 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 solve: Int = {\n val n = nextInt\n val k = nextInt\n val a = new Array[Int](n)\n val b = new Array[Int](k)\n for (i <- 0 until n) {\n a(i) = nextInt\n }\n val set = new mutable.HashSet[Int]()\n for (i <- 0 until k) {\n b(i) = nextInt\n set += b(i)\n }\n for (i <- 1 until n) {\n if (a(i) == 0 && a(i - 1) == 0) {\n out.println(\"Yes\")\n return 0\n }\n }\n for (i <- 0 until n) {\n if (a(i) == 0) {\n if (i - 1 >= 0 && i + 1 < n) {\n for (j <- 0 until k) {\n if (b(j) < a(i - 1) && b(j) > a(i + 1)) {\n out.println(\"Yes\")\n return 0\n }\n }\n } else if (i - 1 >= 0) {\n for (j <- 0 until k) {\n if (b(j) < a(i - 1)) {\n out.println(\"Yes\")\n return 0\n }\n }\n } else if (i + 1 < n) {\n for (j <- 0 until k) {\n if (b(j) > a(i + 1)) {\n out.println(\"Yes\")\n return 0\n }\n }\n }\n }\n }\n out.println(\"No\")\n return 0\n }\n}\n"}, {"source_code": "\nimport java.io._\nimport java.util._\n\nimport scala.collection.mutable\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 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 solve: Int = {\n val n = nextInt\n val k = nextInt\n val a = new Array[Int](n)\n val b = new Array[Int](k)\n for (i <- 0 until n) {\n a(i) = nextInt\n }\n for (i <- 0 until k) {\n b(i) = nextInt\n }\n for (i <- 1 until n) {\n if (a(i) == 0 && a(i - 1) == 0) {\n out.println(\"Yes\")\n return 0\n }\n }\n for (i <- 0 until n) {\n if (a(i) == 0) {\n if (i - 1 >= 0) {\n for (j <- 0 until k) {\n if (b(j) < a(i - 1)) {\n out.println(\"Yes\")\n return 0\n }\n }\n }\n if (i + 1 < n) {\n for (j <- 0 until k) {\n if (b(j) > a(i + 1)) {\n out.println(\"Yes\")\n return 0\n }\n }\n }\n }\n }\n out.println(\"No\")\n return 0\n }\n}\n"}, {"source_code": "\nimport java.io._\nimport java.util._\n\nimport scala.collection.mutable\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 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 solve: Int = {\n val n = nextInt\n val k = nextInt\n val a = new Array[Int](n)\n val b = new Array[Int](k)\n for (i <- 0 until n) {\n a(i) = nextInt\n }\n val set = new mutable.HashSet[Int]()\n for (i <- 0 until k) {\n b(i) = nextInt\n set += b(i)\n }\n for (i <- 1 until n) {\n if (a(i) == 0 && a(i - 1) == 0) {\n out.println(\"Yes\")\n return 0\n }\n }\n for (i <- 0 until n) {\n if (a(i) == 0) {\n if (i - 1 >= 0 && i + 1 < n) {\n for (j <- 0 until k) {\n if (b(j) < a(i - 1) && b(j) > a(i + 1)) {\n out.println(\"Yes\")\n return 0\n }\n }\n }\n }\n }\n out.println(\"No\")\n return 0\n }\n}\n"}], "src_uid": "40264e84c041fcfb4f8c0af784df102a"} {"nl": {"description": "As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark n distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.", "input_spec": "The first line contains two lowercase English letters — the password on the phone. The second line contains single integer n (1 ≤ n ≤ 100) — the number of words Kashtanka knows. The next n lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.", "output_spec": "Print \"YES\" if Kashtanka can bark several words in a line forming a string containing the password, and \"NO\" otherwise. You can print each letter in arbitrary case (upper or lower).", "sample_inputs": ["ya\n4\nah\noy\nto\nha", "hp\n2\nht\ntp", "ah\n1\nha"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteIn the first example the password is \"ya\", and Kashtanka can bark \"oy\" and then \"ah\", and then \"ha\" to form the string \"oyahha\" which contains the password. So, the answer is \"YES\".In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark \"ht\" and then \"tp\" producing \"http\", but it doesn't contain the password \"hp\" as a substring.In the third example the string \"hahahaha\" contains \"ah\" as a substring."}, "positive_code": [{"source_code": "import java.util.Scanner\n\nobject BarkUnlock {\n\tdef main(args: Array[String]) = {\n\t\tval sc: Scanner = new Scanner(System.in)\n\t\tval password: String = sc.next()\n\t\tval n: Int = sc.nextInt()\n\t\tval words: List[String] = (1 to n).map(_ => sc.next()).toList\n\n\t\tif(words.exists(_.equals(password))) println(\"YES\")\n\t\telse if(words.exists(_.charAt(1) == password.charAt(0)) && \n\t\t\twords.exists(_.charAt(0) == password.charAt(1))) println(\"YES\")\n\t\telse println(\"NO\")\n\t}\n}"}, {"source_code": "import scala.io.StdIn\n\nobject Atdroch {\n def main(args: Array[String]) {\n val actualPwd = StdIn.readLine()\n\n val numSubstrings = StdIn.readInt()\n val substrings = (0 until numSubstrings).map(i => StdIn.readLine())\n\n println(if (bruteforcePossible(actualPwd, substrings)) \"YES\" else \"NO\")\n }\n\n def bruteforcePossible(actualPwd: String, substrings: Seq[String]): Boolean = {\n if(substrings.contains(actualPwd)) {\n true\n }\n else {\n (for (x <- substrings; y <- substrings) yield (x, y)).foldLeft(false)((possible, xy) => {\n if(possible) true\n else {\n val (x, y) = xy\n\n x(1) == actualPwd(0) && y(0) == actualPwd(1)\n }\n })\n }\n }\n\n}\n"}], "negative_code": [], "src_uid": "cad8283914da16bc41680857bd20fe9f"} {"nl": {"description": "Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyramid is n. The top level consists of only 1 glass, that stands on 2 glasses on the second level (counting from the top), then 3 glasses on the third level and so on.The bottom level consists of n glasses.Vlad has seen in the movies many times how the champagne beautifully flows from top levels to bottom ones, filling all the glasses simultaneously. So he took a bottle and started to pour it in the glass located at the top of the pyramid.Each second, Vlad pours to the top glass the amount of champagne equal to the size of exactly one glass. If the glass is already full, but there is some champagne flowing in it, then it pours over the edge of the glass and is equally distributed over two glasses standing under. If the overflowed glass is at the bottom level, then the champagne pours on the table. For the purpose of this problem we consider that champagne is distributed among pyramid glasses immediately. Vlad is interested in the number of completely full glasses if he stops pouring champagne in t seconds.Pictures below illustrate the pyramid consisting of three levels. ", "input_spec": "The only line of the input contains two integers n and t (1 ≤ n ≤ 10, 0 ≤ t ≤ 10 000) — the height of the pyramid and the number of seconds Vlad will be pouring champagne from the bottle.", "output_spec": "Print the single integer — the number of completely full glasses after t seconds.", "sample_inputs": ["3 5", "4 8"], "sample_outputs": ["4", "6"], "notes": "NoteIn the first sample, the glasses full after 5 seconds are: the top glass, both glasses on the second level and the middle glass at the bottom level. Left and right glasses of the bottom level will be half-empty."}, "positive_code": [{"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val Array(n, t) = in.next().split(' ').map(_.toInt)\n val data = (1 to n).map(i => Array.fill[(Int, Int)](i){(0, 1)}).toArray\n\n def norm(a: (Int, Int)): (Int, Int) = {\n (2 to Math.min(a._1, a._2)).find(j => a._1 % j == 0 && a._2 % j == 0) match {\n case None => a\n case Some(i) => norm((a._1 / i, a._2 / i))\n }\n }\n\n def sum(a: (Int, Int), b: (Int, Int)): (Int, Int) = {\n if (a._2 == b._2)\n norm((a._1 + b._1, b._2))\n else\n norm((a._1 * b._2 + b._1 * a._2, a._2 * b._2))\n }\n\n data(0)(0) = sum(data(0)(0), (t, 1))\n data.indices.foreach(i =>\n data(i).indices.foreach { j =>\n val el = data(i)(j)\n if (el._1 >= el._2 && el != (1, 1)) {\n val temp = (data(i)(j)._1 - data(i)(j)._2, data(i)(j)._2)\n data(i)(j) = (1, 1)\n if (i != data.length - 1) {\n data(i + 1)(j) = sum(data(i + 1)(j), (temp._1, temp._2 * 2))\n data(i + 1)(j + 1) = sum(data(i + 1)(j + 1), (temp._1, temp._2 * 2))\n }\n }\n })\n println(data.map(_.count(_ == (1, 1))).sum)\n}\n"}, {"source_code": "import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._\n\nobject _676B extends CodeForcesApp {\n override def apply(io: IO) = {\n val n, t = io[Int]\n val tower = Array.ofDim[Double]((n * (n + 1))/2)\n\n def pour(glass: Int, amount: Double): Unit = if (glass < tower.length) {\n val capacity = 1 - tower(glass)\n val fill = amount min capacity\n tower(glass) += fill\n val next = amount - fill\n if(next >~ 0) {\n val level = ((Math.sqrt(1 + 8.0*glass) - 1)/2).toInt\n pour(glass + level + 1, next/2)\n pour(glass + level + 2, next/2)\n } else {\n //debug(glass, amount, fill, tower.toList)\n }\n }\n\n repeat(t) {\n pour(glass = 0, amount = 1)\n }\n\n val ans = tower.count(_ ~= 1)\n io += ans\n }\n}\n\n// ((sqrt(1+8*n)-1)/2)\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 def prefixSum(implicit n: Numeric[A]) = t.scanLeft(n.zero) {case (acc, i) => n.plus(acc, i)}\n def suffixSum(implicit n: Numeric[A]) = t.scanRight(n.zero) {case (i, acc) => n.plus(acc, i)}\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 SortedExtensions[A, C[A] <: collection.SortedSet[A]](val s: C[A]) extends AnyVal {\n def greaterThanOrEqualTo(a: A): Option[A] = s.from(a).headOption\n def lessThan(a: A): Option[A] = s.until(a).lastOption\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 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[A, B](f: A => B): collection.Map[A, B] = new mutable.HashMap[A, B]() {\n override def apply(key: A) = getOrElseUpdate(key, f(key))\n }\n implicit class FuzzyDouble(x: Double)(implicit eps: Double = 1e-9) {\n def >~(y: Double) = x > y+eps\n def >=~(y: Double) = x >= y-eps\n def ~<(y: Double) = x < y-eps\n def ~=<(y: Double) = x <= y+eps\n def ~=(y: Double) = ~=<(y) && >=~(y)\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}\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[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"}], "negative_code": [{"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val Array(n, t) = in.next().split(' ').map(_.toInt)\n val data = (1 to n).map(i => Array.fill[(Int, Int)](i){(0, 1)}).toArray\n\n def norm(a: (Int, Int)): (Int, Int) = {\n (2 to Math.min(a._1, a._2)).find(j => a._1 % j == 0 && a._2 % j == 0) match {\n case None => a\n case Some(i) => norm((a._1 / i, a._2 / i))\n }\n }\n\n def sum(a: (Int, Int), b: (Int, Int)): (Int, Int) = {\n if (a._2 == b._2)\n norm((a._1 + b._1, b._2))\n else\n norm((a._1 * b._2 + b._1 * a._2, a._2 * b._2))\n }\n\n data.indices.foreach(i =>\n data(i).indices.foreach { j =>\n val el = data(i)(j)\n if (el._1 >= el._2 && el != (1, 1)) {\n val temp = (data(i)(j)._1 - data(i)(j)._2, data(i)(j)._2)\n data(i)(j) = (1, 1)\n if (i != data.length - 1) {\n data(i + 1)(j) = sum(data(i + 1)(j), (temp._1, temp._2 * 2))\n data(i + 1)(j + 1) = sum(data(i + 1)(j + 1), (temp._1, temp._2 * 2))\n }\n }\n })\n println(data.map(_.count(_ == (1, 1))).sum)\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val Array(n, t) = in.next().split(' ').map(_.toInt)\n val data = (1 to n).map(i => Array.fill[(Int, Int)](i){(0, 1)}).toArray\n\n def norm(a: (Int, Int)): (Int, Int) = {\n (2 to Math.min(a._1, a._2)).find(j => a._1 % j == 0 && a._2 % j == 0) match {\n case None => a\n case Some(i) => norm((a._1 / i, a._2 / i))\n }\n }\n\n def sum(a: (Int, Int), b: (Int, Int)): (Int, Int) = {\n if (a._2 == b._2)\n norm((a._1 + b._1, b._2))\n else\n norm((a._1 * b._2 + b._1 * a._2, a._2 * b._2))\n }\n\n (1 to t).foreach { _ =>\n data(0)(0) = sum(data(0)(0), (1, 1))\n data.indices.foreach(i =>\n data(i).indices.foreach { j =>\n val el = data(i)(j)\n if (el._1 >= el._2 && el != (1, 1)) {\n val temp = (data(i)(j)._1 - data(i)(j)._2, data(i)(j)._2)\n data(i)(j) = (1, 1)\n if (i != data.length - 1) {\n data(i + 1)(j) = sum(data(i + 1)(j), (temp._1, temp._2 * 2))\n data(i + 1)(j + 1) = sum(data(i + 1)(j + 1), (temp._1, temp._2 * 2))\n }\n }\n })\n println(data.map(_.toList).toList)\n\n }\n println(data.map(_.toList).toList)\n println(data.map(_.count(_ == (1, 1))).sum)\n}\n"}], "src_uid": "b2b49b7f6e3279d435766085958fb69d"} {"nl": {"description": "Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, \"AZ\", \"AA\", \"ZA\" — three distinct two-grams.You are given a string $$$s$$$ consisting of $$$n$$$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string $$$s$$$ = \"BBAABBBA\" the answer is two-gram \"BB\", which contained in $$$s$$$ three times. In other words, find any most frequent two-gram.Note that occurrences of the two-gram can overlap with each other.", "input_spec": "The first line of the input contains integer number $$$n$$$ ($$$2 \\le n \\le 100$$$) — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ capital Latin letters.", "output_spec": "Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string $$$s$$$ as a substring (i.e. two consecutive characters of the string) maximal number of times.", "sample_inputs": ["7\nABACABA", "5\nZZZAA"], "sample_outputs": ["AB", "ZZ"], "notes": "NoteIn the first example \"BA\" is also valid answer.In the second example the only two-gram \"ZZ\" can be printed because it contained in the string \"ZZZAA\" two times."}, "positive_code": [{"source_code": "object Problem_977B {\n // Two-gram\n\n def main(args: Array[String]) {\n val scan = scala.io.StdIn\n val len: Int = scan.readLine.toInt\n val targetStr: String = scan.readLine()\n\n val occurenceMap = targetStr.foldLeft(Map.empty[String, Int], ' ') {\n case ((map: Map[String, Int], prevChar: Char), elem: Char) =>\n if (prevChar != ' ') {\n (map + (f\"$prevChar$elem\" -> (map.getOrElse(s\"$prevChar$elem\", 0) + 1)), elem)\n }\n else {\n (map, elem)\n }\n }._1\n\n println(occurenceMap.maxBy(_._2)._1)\n }\n\n}\n"}, {"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 = ni()\n val s = ns(N)\n val cnt = Array.ofDim[Int](26, 26)\n rep(N - 1) { i =>\n val a = s(i) - 'A'\n val b = s(i + 1) - 'A'\n cnt(a)(b) += 1\n }\n\n val ms = cnt.map(_.max).max\n var a, b = 0\n rep(26) { i =>\n rep(26) { j =>\n if (cnt(i)(j) == ms) {\n a = i\n b = j\n }\n }\n }\n\n out.println(s\"${('A'+a).toChar}${('A'+b).toChar}\")\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\n implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {\n // todo Orderingだとboxing発生するので自作Orderを用意したい\n def maxByOpt[B: Ordering](f: A => B): Option[A] = {\n if (as.nonEmpty) Some(as.maxBy(f)) else None\n }\n\n def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {\n val map = mutable.Map.empty[K, ArrayBuffer[A]]\n rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))\n map\n }\n\n def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {\n var sum = num.zero\n rep(as.length)(i => sum = num.plus(sum, f(as(i))))\n sum\n }\n\n def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {\n limit(f, ixRange)(cmp.lt)\n }\n\n def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {\n limit(f, ixRange)(cmp.gt)\n }\n\n private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {\n var limA = as(ixRange.head)\n var limB = f(limA)\n\n for (i <- ixRange.tail) {\n val a = as(i)\n val b = f(a)\n if (cmp(b, limB)) {\n limA = a\n limB = b\n }\n }\n (limA, limB)\n }\n }\n\n implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {\n def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {\n as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))\n }\n }\n}"}, {"source_code": "import scala.collection.mutable\n\nobject CE976B extends App {\n readInt();\n val string = readLine();\n val charArray = string.toCharArray();\n val map = mutable.Map[String, Int]()\n for (i <- 0 to string.length - 2) {\n val subString = string.substring(i, i + 2);\n if (map.contains(subString)) {\n val currentTime = map(subString) + 1\n map += (subString -> currentTime)\n }\n else\n map += (subString -> 1)\n }\n val maxTime = map.reduceLeft((a, b) => if (a._2 > b._2) a else b)\n println(maxTime._1)\n\n def sub(n: Int) = if (n % 10 == 0) n / 10 else n - 1;\n}\n"}, {"source_code": "\nimport scala.io.StdIn\n\nobject TwoGram extends App {\n\n val l1 = StdIn.readLine()\n val l2 = StdIn.readLine()\n print(impl(l2))\n\n def impl(st: String): String = {\n val m = collection.mutable.Map[String, Int]().withDefaultValue(0)\n\n for (i <- Range(0, st.length - 1)) {\n m(st.charAt(i).toString + st.charAt(i + 1)) += 1\n }\n\n m.maxBy(_._2)._1\n }\n}"}, {"source_code": "object B977 extends App {\n type Base = String\n type Pair = (Char, Char)\n type Splitted = List[Pair]\n\n val s: String = { readLine(); readLine() }\n\n def answer0 = (s head, (s tail) head)\n def splitted: Splitted = ((s tail) tail).foldLeft(List[(Char, Char)](answer0)) { (answer: List[(Char, Char)], i: Char) => \n val (_, previous) = (answer).head\n (previous, i) :: (answer)\n }\n\n def iterate(result: Map[Pair, Int], over: Splitted): Pair = {\n over match {\n case Nil =>\n result\n .toList\n .maxBy{ p => p._2 }\n ._1\n \n case h :: t =>\n if (result.contains(h)) iterate(result + (h -> (result(h) + 1)), over tail)\n else iterate(result + (h -> 1), over tail)\n }\n }\n\n val r = iterate(Map.empty, splitted)\n print(r._1 + \"\" + r._2)\n}"}, {"source_code": "object CF_379_Two_Gram extends App {\n\n def createListGroup[T](\n list: List[T],\n accumList: List[(T, T)] = List[(T, T)]()): List[(T, T)] = {\n list match {\n case head :: tail if tail != Nil =>\n createListGroup(tail, accumList :+ (head, tail.head))\n case _ :: tail if tail == Nil => accumList\n case Nil => accumList\n }\n }\n\n val numOfChar = scala.io.StdIn.readLine\n val string = createListGroup(scala.io.StdIn.readLine.toList)\n println(\n string\n .map(x => x._1.toString + x._2.toString)\n .groupBy(identity)\n .mapValues(_.size)\n .toSeq\n .sortWith(_._2 > _._2)\n .head\n ._1)\n}"}, {"source_code": "object B extends App {\n val n = scala.io.StdIn.readInt()\n val s = scala.io.StdIn.readLine()\n\n val a = Array.fill(65535)(0)\n var m = -1\n var j = -1\n\n var p = s.head\n for (c <- s.tail) {\n val i = ((p.toByte - 65) << 8) + c.toByte - 65\n a(i) += 1\n if (a(i) > m) {\n j = i\n m = a(i)\n }\n p = c\n }\n\n println(s\"${((j >> 8) + 65).toChar}${((j & 0xFF) + 65).toChar}\")\n}\n"}, {"source_code": "object _977B 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 _, s = io.read[String]\n val (ans, _) = s.sliding(2).toSeq.groupBy(identity).mapValues(_.size).maxBy(_._2)\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"}, {"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 n = read().toInt\n val s = readString()\n\n val f = new mutable.HashMap[String, Int]()\n\n for (i <- 0 until s.length - 1) {\n val key = s.substring(i, i + 2)\n val value = f.getOrElse(key, 0)\n f.put(key, value + 1)\n }\n\n var rs = \"\"\n var max = 0\n f.foreach{case (k, v) => {\n if (max < v) {\n max = v\n rs = k\n }\n }}\n println(rs)\n }\n}\n"}, {"source_code": "\nobject CF977A extends App {\n\n import java.io.{PrintWriter}\n import java.util.{Locale, Scanner}\n\n val in = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n def nextInt = in.nextInt\n def nextDouble = in.nextDouble\n def nextString = in.next\n\n def substract(n: Int, k: Int): Int = {\n if (k == 0) n\n else {\n val updatedN = if (n % 10 == 0) n / 10 else n - 1\n substract(updatedN, k - 1)\n }\n }\n\n def sub(text: String, s: Int): Unit = {\n text.substring(s, s + 1)\n }\n\n def solve: Unit = {\n val n = nextInt\n val input = nextString\n\n val res = for (i <- (0 until n - 1)) yield input.substring(i, i + 2)\n val m = res.groupBy(x => x).mapValues(_.size).maxBy(_._2)._1\n out.println(m)\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"}], "negative_code": [], "src_uid": "e78005d4be93dbaa518f3b40cca84ab1"} {"nl": {"description": "What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. \"Wait a second!\" — thought Petya. He know for a fact that if he fulfills the parents' task in the i-th (1 ≤ i ≤ 12) month of the year, then the flower will grow by ai centimeters, and if he doesn't water the flower in the i-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by k centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by k centimeters.", "input_spec": "The first line contains exactly one integer k (0 ≤ k ≤ 100). The next line contains twelve space-separated integers: the i-th (1 ≤ i ≤ 12) number in the line represents ai (0 ≤ ai ≤ 100). ", "output_spec": "Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by k centimeters. If the flower can't grow by k centimeters in a year, print -1.", "sample_inputs": ["5\n1 1 1 1 2 2 3 2 2 1 1 1", "0\n0 0 0 0 0 0 0 1 1 2 3 0", "11\n1 1 4 1 1 5 1 1 4 1 1 1"], "sample_outputs": ["2", "0", "3"], "notes": "NoteLet's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.In the second sample Petya's parents will believe him even if the flower doesn't grow at all (k = 0). So, it is possible for Petya not to water the flower at all."}, "positive_code": [{"source_code": "/*input\n45\n0 0 0 0 0 0 0 1 1 2 3 0\n*/\n\nimport java.util.Scanner\nimport scala.io.StdIn\n\nobject Solution {\n\tdef main(args: Array[String]): Unit = {\n\n\t\tval k = StdIn.readInt();\n\t\tval arr = StdIn.readLine().split(\" \").map( _.toInt ).sortWith( _ > _);\n\t\tif(arr.sum < k) println(-1)\n\t\telse{\n\t\t\tval out = arr.foldLeft(List(0,0)){(x: List[Int], y: Int) => {\n\n\t\t\t\t\tif(x(0) >= k) x else List(x(0)+y, x(1)+1)\n\t\t\t\t}\n\t\t\t}(1);\n\t\t\tprintln(out);\n\t\t}\n\n\t}\n\n}"}, {"source_code": "object Main extends App {\n\tdef findMinMonth(array: Array[Int], poitner: Int, neededLength: Int, currentLength: Int): Int = {\n\t\tif (neededLength == 0) 0\n\t\telse if (poitner == array.size) -1\n\t\telse if (currentLength + array(poitner) >= neededLength) poitner + 1\n\t\telse findMinMonth(array, poitner + 1, neededLength, currentLength + array(poitner))\n\t}\n\n\tval neededLength = readLine.toInt\n\tval growPerMonthList = readLine.split(\" \").map(_.toInt).sortWith((a: Int, b: Int) => a > b)\n\tprintln(findMinMonth(growPerMonthList, 0, neededLength, 0))\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer;\nimport java.util.Arrays\n\nobject Solver {\n\n var st : StringTokenizer = null;\n var in : BufferedReader = null;\n var out : PrintWriter = null;\n\n def main(args: Array[String]){\n open();\n solve();\n close();\n }\n\n def open() {\n in = new BufferedReader(new InputStreamReader(System.in));\n out = new PrintWriter(System.out);\n }\n\n def nextToken() : String = {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine());\n }\n st.nextToken();\n }\n\n def nextInt() : Int = {\n Integer.parseInt(nextToken());\n }\n\n// def nextLong() {\n// return Long.parseLong(nextToken());\n// }\n//\n// def nextDouble() : Double = {\n// Double.parseDouble(nextToken());\n// }\n\n def solve(){\n var k:Int = nextInt;\n var ar: Array[Int] = new Array[Int](12);\n var sum: Int = 0;\n for (i <- 0 to 11){\n ar(i) = nextInt;\n sum += ar(i);\n }\n \n if (sum0){\n i-=1;\n k -= ar(i);\n }\n \n out.println(12-i);\n return\n }\n\n def close() {\n out.flush();\n out.close();\n }\n\n}"}, {"source_code": "object P149A extends App {\n var k = readLine.toInt\n val months = readLine.split(\" \").map(_.toInt).toList.sortWith(_ > _)\n print(if (months.sum < k) -1\n else months.takeWhile({(e) => if (k>0) {k -= e; true} else false }).length)\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val k = in.next().toInt\n val data = in.next().split(\" \").map(_.toInt).sorted.reverse\n var i = 0\n var soFar = 0\n if (data.sum < k)\n println(-1)\n else {\n while (soFar < k) {\n soFar += data(i)\n i += 1\n }\n println(i)\n }\n\n}\n"}, {"source_code": "object A149 {\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) = readInts(1)\n val months = readInts(12).sortBy(x => -x)\n var size = 0\n var i = 0\n while(size < k && i < 12) {\n size += months(i)\n i += 1\n }\n if(size < k) {\n println(\"-1\")\n } else {\n println(i)\n }\n }\n}"}, {"source_code": "\nobject tmp extends App {\n\n import java.io._\n import java.util.StringTokenizer\n\n class MyScanner(br: BufferedReader) {\n var st = new StringTokenizer(\"\")\n\n def this(is: InputStream) = this(new BufferedReader(new InputStreamReader(is)))\n\n private def next() = {\n\n while (!st.hasMoreElements) {\n st = new StringTokenizer(br.readLine())\n }\n st.nextToken()\n }\n\n def nextInt() = java.lang.Integer.parseInt(next())\n\n def nextLong() = java.lang.Long.parseLong(next())\n\n def nextLine() = br.readLine()\n }\n\n val sc = new MyScanner(System.in)\n val n = sc.nextInt()\n val a = (for (_ <- 0 until 12) yield sc.nextInt()).sorted.reverse\n if (n == 0) {\n println(0)\n System.exit(0)\n }\n if (a.sum < n) {\n println(-1)\n System.exit(0)\n }\n var count = 0\n val part = a.takeWhile(v => {val cond = count < n; count += v; cond})\n println(part.length)\n\n}\n"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P149A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val K = sc.nextInt\n val g = List.fill(12)(sc.nextInt).sorted.reverse\n\n def solve: Int = {\n @tailrec\n def loop(acc: Int, m: Int, gs: List[Int]): Int =\n if (acc >= K) m\n else gs match {\n case Nil => -1\n case x :: xs => loop(acc + x, m + 1, xs)\n }\n loop(0, 0, g)\n }\n\n out.println(solve)\n out.close\n}\n"}, {"source_code": "import annotation.tailrec\nimport java.io._\n\nobject Easy {\n val reader = new BufferedReader(new InputStreamReader(System.in))\n def readInts = reader.readLine().split(\" \").map(_.toInt)\n def readInt = reader.readLine().toInt\n\n val k = readInt\n def ans = readInts.sortWith(_ > _).foldLeft(List(0)) {\n case (l @ head :: _, x) => head + x :: l\n }.filter(_ < k).size\n\n def main(args: Array[String]) {\n println((ans + 1) % 14 - 1)\n }\n}\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val k = readInt()\n val a = readLine().split(\" \").map(_.toInt)\n val r = a.sortWith(_ > _).foldLeft((0, 0)) { (t, a) => \n if (t._1 >= k) t\n else (t._1 + a, t._2 + 1)\n }\n if (r._1 < k) println(\"-1\")\n else println(r._2)\n }\n}"}, {"source_code": "import java.util.Scanner\n\nobject Amain {\n def main(args: Array[String]) {\n val sc = new Scanner(System.in)\n val N = sc.nextInt\n val cal = (for(i <- 1 to 12) yield sc.nextInt).sortWith(_ > _)\n \n // println(cal)\n \n val ret = for(i <- 0 to 12) yield {\n (cal.take(i).sum, i)\n }\n \n if(cal.sum < N) println(-1)\n else println(ret.filter(_._1 >= N).head._2)\n }\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject Main {\n def main(args: Array[String]): Unit = {\n val k = StdIn.readInt()\n val a = StdIn.readLine().split(\" \").toList.map(_.toInt).sorted.reverse\n println(a.inits.toList.reverse.find(_.sum >= k).map(_.length).getOrElse(-1))\n }\n}\n"}], "negative_code": [{"source_code": "object Main extends App {\n\tdef findMinMonth(array: Array[Int], poitner: Int, neededLength: Int, currentLength: Int): Int = {\n\t\tval newLength = currentLength + array(poitner)\n\t\tif (newLength >= neededLength) poitner + 1\n\t\telse if (poitner == array.size) 0\n\t\telse findMinMonth(array, poitner + 1, neededLength, newLength)\n\t}\n\n\tval neededLength = readLine.toInt\n\tval growPerMonthList = readLine.split(\" \").map(_.toInt).sortWith((a: Int, b: Int) => a > b)\n\tprintln(findMinMonth(growPerMonthList, 0, neededLength, 0))\n}"}, {"source_code": "object Main extends App {\n\tdef findMinMonth(array: Array[Int], poitner: Int, neededLength: Int, currentLength: Int): Int = {\n\t\tif (neededLength == 0) 0\n\t\telse if (poitner == array.size) currentLength\n\t\telse if (currentLength + array(poitner) >= neededLength) poitner + 1\n\t\telse findMinMonth(array, poitner + 1, neededLength, currentLength + array(poitner))\n\t}\n\n\tval neededLength = readLine.toInt\n\tval growPerMonthList = readLine.split(\" \").map(_.toInt).sortWith((a: Int, b: Int) => a > b)\n\tprintln(findMinMonth(growPerMonthList, 0, neededLength, 0))\n}"}, {"source_code": "object P149A extends App {\n var k = readLine.toInt\n val months = readLine.split(\" \").map(_.toInt).toList.sortWith(_ > _)\n print(months.takeWhile({(e) => if (k>=0) {k -= e; true} else false }).length)\n}"}, {"source_code": "object P149A extends App {\n var k = readLine.toInt\n val months = readLine.split(\" \").map(_.toInt).toList.sortWith(_ > _)\n print(months.takeWhile({(e) => if (k>0) {k -= e; true} else false }).length)\n}"}, {"source_code": "object P149A extends App {\n var k = readLine.toInt\n val months = readLine.split(\" \").map(_.toInt).toList.sortWith(_ > _)\n print(if (months.sum > k) -1\n else months.takeWhile({(e) => if (k>0) {k -= e; true} else false }).length)\n}"}, {"source_code": "\nobject tmp extends App {\n\n import java.io._\n import java.util.StringTokenizer\n\n class MyScanner(br: BufferedReader) {\n var st = new StringTokenizer(\"\")\n\n def this(is: InputStream) = this(new BufferedReader(new InputStreamReader(is)))\n\n private def next() = {\n\n while (!st.hasMoreElements) {\n st = new StringTokenizer(br.readLine())\n }\n st.nextToken()\n }\n\n def nextInt() = java.lang.Integer.parseInt(next())\n\n def nextLong() = java.lang.Long.parseLong(next())\n\n def nextLine() = br.readLine()\n }\n\n val sc = new MyScanner(System.in)\n val n = sc.nextInt()\n val a = (for (_ <- 0 until 12) yield sc.nextInt()).sorted.reverse\n if (n == 0) {\n println(0)\n System.exit(0)\n }\n if (a.sum < n) {\n println(-1)\n System.exit(0)\n }\n var count = 0\n val part = a.takeWhile(v => {val cond = count < n; count += v; cond})\n println(part)\n println(part.length)\n\n}\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val k = readInt()\n val a = readLine().split(\" \").map(_.toInt)\n val r = a.sortWith(_ > _).foldLeft((0, 0)) { (t, a) => \n if (t._1 >= k) t\n else (t._1 + a, t._2 + 1)\n }\n println(r._2)\n }\n}"}, {"source_code": "import scala.io.StdIn\n\nobject Main {\n def main(args: Array[String]): Unit = {\n val k = StdIn.readInt()\n val a = StdIn.readLine().split(\" \").toList.map(_.toInt).sorted.reverse\n println(a.inits.toList.reverse.find(_.sum >= k).getOrElse(List.empty).length)\n }\n}\n"}], "src_uid": "59dfa7a4988375febc5dccc27aca90a8"} {"nl": {"description": "Stepan has n pens. Every day he uses them, and on the i-th day he uses the pen number i. On the (n + 1)-th day again he uses the pen number 1, on the (n + 2)-th — he uses the pen number 2 and so on.On every working day (from Monday to Saturday, inclusive) Stepan spends exactly 1 milliliter of ink of the pen he uses that day. On Sunday Stepan has a day of rest, he does not stend the ink of the pen he uses that day. Stepan knows the current volume of ink in each of his pens. Now it's the Monday morning and Stepan is going to use the pen number 1 today. Your task is to determine which pen will run out of ink before all the rest (that is, there will be no ink left in it), if Stepan will use the pens according to the conditions described above.", "input_spec": "The first line contains the integer n (1 ≤ n ≤ 50 000) — the number of pens Stepan has. The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is equal to the number of milliliters of ink which the pen number i currently has.", "output_spec": "Print the index of the pen which will run out of ink before all (it means that there will be no ink left in it), if Stepan will use pens according to the conditions described above. Pens are numbered in the order they are given in input data. The numeration begins from one. Note that the answer is always unambiguous, since several pens can not end at the same time.", "sample_inputs": ["3\n3 3 3", "5\n5 4 5 4 4"], "sample_outputs": ["2", "5"], "notes": "NoteIn the first test Stepan uses ink of pens as follows: on the day number 1 (Monday) Stepan will use the pen number 1, after that there will be 2 milliliters of ink in it; on the day number 2 (Tuesday) Stepan will use the pen number 2, after that there will be 2 milliliters of ink in it; on the day number 3 (Wednesday) Stepan will use the pen number 3, after that there will be 2 milliliters of ink in it; on the day number 4 (Thursday) Stepan will use the pen number 1, after that there will be 1 milliliters of ink in it; on the day number 5 (Friday) Stepan will use the pen number 2, after that there will be 1 milliliters of ink in it; on the day number 6 (Saturday) Stepan will use the pen number 3, after that there will be 1 milliliters of ink in it; on the day number 7 (Sunday) Stepan will use the pen number 1, but it is a day of rest so he will not waste ink of this pen in it; on the day number 8 (Monday) Stepan will use the pen number 2, after that this pen will run out of ink. So, the first pen which will not have ink is the pen number 2."}, "positive_code": [{"source_code": "import scala.io.StdIn._\n\nobject F extends App {\n val n = readInt()\n val xs = readLine().split(\" \").map(_.toInt)\n if (n % 7 == 0) {\n var mi = -1\n xs.zipWithIndex.foreach({ case (x, i) =>\n if ((i + 1) % 7 != 0 && (mi == -1 || xs(mi) > x)) mi = i else ()\n })\n println(mi + 1)\n } else {\n val mx = (xs.min - 1) / 6 * 6\n var ys = xs.map(_ - mx)\n var (i, d) = (0, 1)\n while (d != 8) {\n if (d == 7) d = 0 else {\n ys(i) = ys(i) - 1\n if (ys(i) == 0) d = 7 else ()\n }\n d += 1\n i = (i + 1) % n\n }\n println(if (i == 0) n else i)\n }\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject F extends App {\n val n = readInt()\n val xs = readLine().split(\" \").map(_.toInt)\n if (n % 7 == 0) {\n var mi = -1\n xs.zipWithIndex.foreach({ case (x, i) =>\n if ((i + 1) % 7 != 0 && (mi == -1 || xs(mi) > x)) mi = i else ()\n })\n println(mi + 1)\n } else {\n val mx = (xs.min - 1) / 6 * 6\n var ys = xs.map(_ - mx)\n var (i, d) = (0, 1)\n while (d != 8) {\n if (d == 7) d = 0 else {\n ys(i) = ys(i) - 1\n if (ys(i) == 0) d = 7 else ()\n }\n d += 1\n i = (i + 1) % n\n }\n println(if (i == 0) n else i)\n }\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject F extends App {\n val n = readInt()\n val xs = readLine().split(\" \").map(_.toInt)\n if (n % 7 == 0) {\n var mi = -1\n xs.zipWithIndex.foreach({ case (x, i) =>\n if ((i + 1) % 7 != 0 && (mi == -1 || xs(mi) > x)) mi = i else ()\n })\n println(mi + 1)\n } else {\n val mx = (xs.min - 1) / 6 * 6\n var ys = xs.map(_ - mx)\n var (i, d) = (0, 1)\n while (d != 8) {\n if (d == 7) d = 0 else {\n ys(i) = ys(i) - 1\n if (ys(i) == 0) d = 7 else ()\n }\n d += 1\n i = (i + 1) % n\n }\n println(if (i == 0) n else i)\n }\n}"}], "negative_code": [{"source_code": "import scala.io.StdIn._\n\nobject F extends App {\n val n = readInt()\n val a = readLine().split(\" \").map(_.toInt)\nvar mn = 0;\n var i = 0;\n\t\twhile(i 0) {\n \t\tnxt = j;\n j = 25;\n\t\t} else {\n\t\t pv = j;\n }\n\t }\n j += 1;\n\t}\n\twhile (l != r) {\n\t var m = ((l + r) / 2).toInt;\n\t var emptyC = 0;\n\t if (m >= pv && pv > 0) {\n\t\temptyC = (m - pv) / (nxt - pv);\n\t\temptyC += 1;\n \t }\n\t if (m - emptyC > x) {\n\t\tr = m.toLong;\n \t }\n else {\n\t\tl = (m + 1).toLong;\n\t }\n\t}\n\tif (l - 1 < mx) {\n \t mx = (l - 1).toInt;\n\t d = i + 1;\n\t}\n i+=1;\n }\n println(d)\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject F extends App {\n val n = readInt()\n val a = readLine().split(\" \").map(_.toInt)\n var mx = 4e9.toLong;\n var d = 1;\n var i = 0;\n while(i 0) {\n \t\tnxt = j;\n j = 25;\n\t\t} else {\n\t\t pv = j;\n }\n\t }\n j += 1;\n\t}\n\twhile (l != r) {\n\t var m = ((l + r) / 2+1e-5).toLong;\n\t var emptyC = 0.toLong;\n\t if (m >= pv && pv > 0) {\n\t\temptyC = ((m - pv) / (nxt - pv) + 1e-5).toLong;\n\t\temptyC += 1;\n \t }\n\t if (m - emptyC > x) {\n\t\tr = m.toLong;\n \t }\n else {\n\t\tl = (m + 1).toLong;\n\t }\n\t}\n\tif (l - 1 < mx) {\n \t mx = (l - 1).toInt;\n\t d = i + 1;\n\t}\n i+=1;\n }\n println(d)\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject F extends App {\n val n = readInt()\n val a = readLine().split(\" \").map(_.toInt)\n var mx = 4e9.toLong;\n var d = 1;\n var i = 0;\n while(i 0) {\n \t\tnxt = j;\n j = 25;\n\t\t} else {\n\t\t pv = j;\n }\n\t }\n j += 1;\n\t}\n\twhile (l != r) {\n\t var m = ((l + r) / 2).toLong;\n\t var emptyC = 0.toLong;\n\t if (m >= pv && pv > 0) {\n\t\temptyC = (m - pv) / (nxt - pv);\n\t\temptyC += 1;\n \t }\n\t if (m - emptyC > x) {\n\t\tr = m.toLong;\n \t }\n else {\n\t\tl = (m + 1).toLong;\n\t }\n\t}\n\tif (l - 1 < mx) {\n \t mx = (l - 1).toInt;\n\t d = i + 1;\n\t}\n i+=1;\n }\n println(d)\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject F extends App {\n val n = readInt()\n val a = readLine().split(\" \").map(_.toInt)\n var mx = 2e9;\n var d = 1;\n var i = 0;\n while(i 0) {\n \t\tnxt = j;\n j = 25;\n\t\t} else {\n\t\t pv = j;\n }\n\t }\n j += 1;\n\t}\n\twhile (l != r) {\n\t var m = ((l + r) / 2).toInt;\n\t var emptyC = 0;\n\t if (m >= pv && pv > 0) {\n\t\temptyC = (m - pv) / (nxt - pv);\n\t\temptyC += 1;\n \t }\n\t if (m - emptyC > x) {\n\t\tr = m;\n \t }\n else {\n\t\tl = m + 1;\n\t }\n\t}\n\tif (l - 1 < mx) {\n \t mx = l - 1;\n\t d = i + 1;\n\t}\n i+=1;\n }\n println(d)\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject F extends App {\n val n = readInt()\n val a = readLine().split(\" \").map(_.toInt)\n \tif (n % 7 == 0) {\n\t\tvar mn = 0;\n var i = 0;\n\t\twhile(i 0) {\n \t\tnxt = j;\n j = 25;\n\t\t} else {\n\t\t pv = j;\n }\n\t }\n j += 1;\n\t}\n\twhile (l != r) {\n\t var m = ((l + r) / 2).toInt;\n\t var emptyC = 0;\n\t if (m >= pv && pv > 0) {\n\t\temptyC = (m - pv) / (nxt - pv);\n\t\temptyC += 1;\n \t }\n\t if (m - emptyC > x) {\n\t\tr = m;\n \t }\n else {\n\t\tl = m + 1;\n\t }\n\t}\n\tif (l - 1 < mx) {\n \t mx = l - 1;\n\t d = i + 1;\n\t}\n i+=1;\n }\n println(d)\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject F extends App {\n val n = readInt()\n val a = readLine().split(\" \").map(_.toInt)\n var mx = 4e9.toLong;\n var d = 1;\n var i = 0;\n while(i 0) {\n \t\tnxt = j;\n j = 25;\n\t\t} else {\n\t\t pv = j;\n }\n\t }\n j += 1;\n\t}\n\twhile (l != r) {\n\t var m = ((l + r) / 2).toLong;\n\t var emptyC = 0.toLong;\n\t if (m >= pv && pv > 0) {\n\t\temptyC = ((m - pv) / (nxt - pv)).toLong;\n\t\temptyC += 1;\n \t }\n\t if (m - emptyC > x) {\n\t\tr = m.toLong;\n \t }\n else {\n\t\tl = (m + 1).toLong;\n\t }\n\t}\n\tif (l - 1 < mx) {\n \t mx = (l - 1).toInt;\n\t d = i + 1;\n\t}\n i+=1;\n }\n println(d)\n}"}], "src_uid": "8054dc5dd09d600d7fb8d9f5db4dcaca"} {"nl": {"description": "There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n. The i-th child wants to get at least ai candies.Jzzhu asks children to line up. Initially, the i-th child stands at the i-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm: Give m candies to the first child of the line. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. Repeat the first two steps while the line is not empty. Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?", "input_spec": "The first line contains two integers n, m (1 ≤ n ≤ 100; 1 ≤ m ≤ 100). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100).", "output_spec": "Output a single integer, representing the number of the last child.", "sample_inputs": ["5 2\n1 3 1 4 2", "6 4\n1 1 2 2 3 3"], "sample_outputs": ["4", "6"], "notes": "NoteLet's consider the first sample. Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.Child 4 is the last one who goes home."}, "positive_code": [{"source_code": "\n\nimport java.io.PrintWriter\nimport java.util.Scanner\n\n/**\n * Created by arseny on 19.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 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 = nextInt\n val m = nextInt\n val a = new Array[Int](n)\n for (i <- 0 until n) {\n val t = nextInt\n a(i) = t / m\n if (t % m != 0) {\n a(i) = a(i) + 1\n }\n }\n //println(a.toList)\n var max = 0\n for (i <- 0 until n) {\n if (a(i) >= a(max)) {\n max = i\n }\n }\n out.println(max + 1)\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\n"}, {"source_code": "import java.util.StringTokenizer\n\nimport scala.collection.mutable.Queue\n\nobject _450A 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 n).map(i => next.toInt).toArray\n\n def f(q: Queue[Int]): Int = {\n if (q.tail == Nil) q.head + 1\n else {\n val i = q.head\n if (a(i) <= m) f(q.tail)\n else {\n a(i) = a(i) - m\n f(q.tail :+ i)\n }\n }\n }\n println(f(Queue[Int]() ++ (0 until n)))\n}\n"}, {"source_code": "import java.util.Scanner\n\n/**\n * Created by kshim on 25/07/2014.\n */\nobject CF257A extends App {\n def Process(m:Int, a:Seq[Int]):Int = {\n val dvd = a.map(v => math.ceil(v / m.toDouble).toInt)\n var maxi = -1\n var max = -1\n for(i <- 0 until dvd.length){\n if(dvd(i) >= max){\n max = dvd(i)\n maxi = i\n }\n }\n maxi + 1\n }\n val in = new Scanner(System.in)\n val n = in.nextInt()\n val m = in.nextInt()\n val ai = (1 to n).map(_=>in.nextInt())\n println(Process(m,ai.toArray))\n}\n"}, {"source_code": "object A450 {\n\n import IO._\n\n def main(args: Array[String]): Unit = {\n val Array(n, m) = readInts(2)\n val in = readInts(n).zipWithIndex\n val q = collection.mutable.Queue[(Int, Int)]()\n in.foreach(q.enqueue(_))\n while(q.size > 1) {\n var (cand, pos) = q.dequeue()\n cand -= m\n if(cand > 0)\n q.enqueue((cand, pos))\n }\n println(q.dequeue._2 + 1)\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"}, {"source_code": "object Children {\n\n def splitter(as: String) = as.split(\"\\\\s+\") match {\n case Array(n, m) => List(n.toInt, m.toInt)\n case arr: Array[String] => arr.map(_.toInt).toList\n }\n\n def solve(l: List[(Int, Int)], m: Int): Int = l match {\n case h :: Nil => h._2\n case h :: t if (h._1 <= m) => solve(t, m)\n case h :: t => solve(t :+ (h._1 - m, h._2), m)\n }\n\n def main(args: Array[String]) {\n val List(nmStr, asStr) = io.Source.stdin.getLines.take(2).toList\n val List(n, m) = splitter(nmStr)\n val as = splitter(asStr).zipWithIndex\n println(solve(as, m) + 1)\n }\n}\n\n"}, {"source_code": "/**\n * @author Oleg Arshinsky\n */\nobject A extends App {{\n\n val Array(_, m) = readLine()\n .split(\" \")\n .map(_.toInt)\n\n val as: Array[Int] = readLine()\n .split(\" \")\n .map(_.toInt)\n\n val max: Int = as.max\n\n val res: Int =\n if (max > m) {val bs = as.map(a => (a.toDouble / m).ceil.toInt); bs.lastIndexOf(bs.max)+1}\n\n else\n as.length\n\n println(res)\n\n}}\n\n"}, {"source_code": "object Main {\n def main(args: Array[String]): Unit = {\n val nm = io.StdIn.readLine().split(\" \").map(x => Integer.parseInt(x))\n val nums = io.StdIn.readLine().split(\" \").map { x=>\n val i = Integer.parseInt(x)\n if (i % nm(1) != 0) i/nm(1) + 1 else i/nm(1)\n }\n \n def indexOfMax( maxIndex: Int, index: Int): Int = {\n if (index < 0) maxIndex\n else indexOfMax(if (nums(index) > nums(maxIndex)) index else maxIndex, index - 1)\n }\n \n println(indexOfMax(nm(0)-1, nm(0)-1) + 1)\n }\n}"}, {"source_code": "import scala.annotation.tailrec\n\nobject Main extends App {\n val sc = new java.util.Scanner(System.in)\n val n,m = sc.nextInt\n val input = List.fill(n)(sc.nextInt)\n\n def solve( m: Int, input: List[Int] ): Int = {\n\n @tailrec\n def dist(children: List[(Int, Int)]): Int = {\n children match {\n\n case List(x) => // size == 1\n x._2 + 1\n\n case x :: xs =>\n val diff = x._1 - m\n if (diff <= 0)\n dist(xs)\n else\n dist( ( (diff, x._2) :: xs.reverse ).reverse )\n }\n }\n\n dist( input.zipWithIndex )\n }\n\n println( solve( m, input ) )\n}\n"}, {"source_code": "import scala.annotation.tailrec\nimport scala.collection.mutable.ListBuffer\n\nobject Main extends App {\n val sc = new java.util.Scanner(System.in)\n val n,m = sc.nextInt\n val children = List.fill(n)(sc.nextInt).zipWithIndex\n\n @tailrec\n def dist(children: List[(Int,Int)]): Unit = {\n children match {\n case Nil =>\n case List(x) => println(x._2 + 1)\n case x::xs =>\n val diff = x._1 - m\n if( diff <= 0 )\n dist(xs)\n else\n dist( xs :+ (diff, x._2) )\n }\n }\n\n dist(children)\n}\n"}, {"source_code": "object HelloWorld{\n def giveCandies(xs: List[(Int, Int)], m:Int, lastSatisfied:Int):Int = xs match {\n case Nil => lastSatisfied\n case x::xs => if (x._1<=m) giveCandies(xs, m, x._2) else giveCandies(xs++List((x._1-m, x._2)), m, lastSatisfied)\n }\n def main(args: Array[String]){\n val in = new java.util.Scanner(System.in)\n val n = in.nextInt\n val m = in.nextInt\n in.nextLine\n val q = in.nextLine.split(\" \").map(_.toInt).zipWithIndex.toList\n print(giveCandies(q, m, -1)+1)\n }\n}"}], "negative_code": [{"source_code": "\n\nimport java.io.PrintWriter\nimport java.util.Scanner\n\n/**\n * Created by arseny on 19.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 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 = nextInt\n val m = nextInt\n val a = new Array[Int](n)\n for (i <- 0 until n) {\n a(i) = Math.max(nextInt / m, 1)\n }\n var max = 0\n for (i <- 0 until n) {\n if (a(i) >= a(max)) {\n max = i\n }\n }\n out.println(max + 1)\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\n"}, {"source_code": "\n\nimport java.io.PrintWriter\nimport java.util.Scanner\n\n/**\n * Created by arseny on 19.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 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 = nextInt\n val m = nextInt\n val a = new Array[Int](n)\n for (i <- 0 until n) {\n a(i) = (nextInt) / m\n }\n var max = 0\n for (i <- 0 until n) {\n if (a(i) >= a(max)) {\n max = i\n }\n }\n out.println(max + 1)\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\n"}, {"source_code": "import java.util.Scanner\n\n/**\n * Created by kshim on 25/07/2014.\n */\nobject CF257A extends App {\n def Process(m:Int, a:Seq[Int]):Int = {\n val dvd = a.map(_ / m)\n var maxi = -1\n var max = -1\n for(i <- 0 until dvd.length){\n if(dvd(i) >= max){\n max = dvd(i)\n maxi = i\n }\n }\n maxi + 1\n }\n val in = new Scanner(System.in)\n val n = in.nextInt()\n val m = in.nextInt()\n val ai = (1 to n).map(_=>in.nextInt())\n println(Process(m,ai))\n}\n"}, {"source_code": "/**\n * @author Oleg Arshinsky\n */\nobject A extends App {{\n\n val Array(_, m) = readLine()\n .split(\" \")\n .map(_.toInt)\n\n val as: Array[Int] = readLine()\n .split(\" \")\n .map(_.toInt)\n\n val max: Int = as.max\n\n val res: Int =\n if (max > m) {val bs = as.map(_ / m); bs.lastIndexOf(bs.max)+1}\n\n else\n as.length\n\n println(res)\n\n}}\n\n"}, {"source_code": "/**\n * @author Oleg Arshinsky\n */\nobject A extends App {{\n\n val line: String = readLine()\n\n val asString: String = readLine()\n val as: Array[Int] = asString.split(\" \")\n .map(_.toInt)\n\n val of: Int = as.lastIndexOf(as.max)\n\n println(of+1)\n\n}}\n\n"}, {"source_code": "/**\n * @author Oleg Arshinsky\n */\nobject A extends App {{\n\n val line: String = readLine()\n\n val asString: String = readLine()\n val as: Array[Int] = asString.split(\" \")\n .map(_.toInt)\n\n val of: Int = as.lastIndexOf(as.max)\n\n println(of)\n\n}}\n\n"}, {"source_code": "/**\n * @author Oleg Arshinsky\n */\nobject A extends App {{\n\n val line: String = readLine()\n val Array(n, m) = line.split(\" \").map(_.toInt)\n\n val asString: String = readLine()\n val as: Array[Int] = asString.split(\" \")\n .map(_.toInt)\n\n val max: Int = as.max\n val of: Int =\n if (max > m)\n as.lastIndexOf(max)\n else\n as.length-1\n\n println(of+1)\n\n}}\n\n"}, {"source_code": "object Main {\n def main(args: Array[String]): Unit = {\n val nm = io.StdIn.readLine().split(\" \").map(x => Integer.parseInt(x))\n val nums = io.StdIn.readLine().split(\" \")\n def indexOfMax( maxIndex: Int, index: Int): Int = {\n if (index < 0) maxIndex\n else indexOfMax(if (nums(index) > nums(maxIndex)) index else maxIndex, index - 1)\n }\n println(indexOfMax(nm(0)-1, nm(0)-1) + 1)\n }\n}"}, {"source_code": "import scala.annotation.tailrec\n\nobject Main extends App {\n val sc = new java.util.Scanner(System.in)\n val n,m = sc.nextInt\n val children = List.fill(n)(sc.nextInt).zipWithIndex\n\n @tailrec\n def dist(children: List[(Int,Int)]): Unit = {\n children match {\n case Nil =>\n case List(x) => println(x._2 + 1)\n case x::xs =>\n val diff = x._1 - m\n if( diff < 0 )\n dist(xs)\n else\n dist( ( (diff, x._2) :: xs).reverse )\n }\n }\n\n dist(children)\n}\n"}], "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c"} {"nl": {"description": "There are n boys and m girls attending a theatre club. To set a play \"The Big Bang Theory\", they need to choose a group containing exactly t actors containing no less than 4 boys and no less than one girl. How many ways are there to choose a group? Of course, the variants that only differ in the composition of the troupe are considered different.Perform all calculations in the 64-bit type: long long for С/С++, int64 for Delphi and long for Java.", "input_spec": "The only line of the input data contains three integers n, m, t (4 ≤ n ≤ 30, 1 ≤ m ≤ 30, 5 ≤ t ≤ n + m).", "output_spec": "Find the required number of ways. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.", "sample_inputs": ["5 2 5", "4 3 5"], "sample_outputs": ["10", "3"], "notes": null}, "positive_code": [{"source_code": "object P131C extends App {\n val Array(n,m,t) = readLine.split(\" \").map(_.toInt)\n def f(a:BigInt, n:Int):BigInt = if (n<=2) a*math.max(n,1) else f(a*n, n-1)\n def m(m:Int, n:Int) = f(1,n)/f(1,n-m)/f(1,m)\n val c = (for(b <- 4 to n; g <- 1 to m) yield((b,g))) filter ((x)=>x._1+x._2==t)\n println(c.map((x) => m(x._1,n) * m(x._2,m)).sum)\n}"}, {"source_code": "object P131C extends App {\n \n val Array(n,m,t) = readLine.split(\" \").map(_.toInt)\n \n def fac(a:BigInt,n:Int):BigInt = if (n<=2) a*math.max(n,1) else fac(a*n,n-1)\n def mofn(m:Int,n:Int) = fac(1,n) / fac(1,n-m) / fac(1,m)\n \n val combs = (for(boys <- 4 to n; girls <- 1 to m) yield((boys,girls))) filter ((x) => x._1 + x._2 == t)\n \n println(combs.map((x) => mofn(x._1,n) * mofn(x._2,m)).sum)\n \n\n}"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val arr@Array(n, m, t) = in.next().split(' ').map(_.toInt)\n val max = arr.max\n val binom = Array.ofDim[Long](max + 1, max + 1)\n (0 to max).foreach { i =>\n binom(i)(0) = 1\n (1 to i).foreach {j =>\n binom(i)(j) = binom(i - 1)(j) + binom(i - 1)(j - 1)\n }\n }\n// println(binom.map(_.mkString(\" \")).mkString(\"\\n\"))\n\n println((1 to t - 4).foldLeft(0l) {\n case(sum, i) =>\n sum + binom(m)(i) * binom(n)(t - i)\n })\n}\n"}, {"source_code": "\nobject Main {\n\n def mkComb(n:Int) = {\n val a = Array.ofDim[Long](n, n)\n for (i <- 0 until n) {\n a(i)(0) = 1L\n a(i)(i) = 1L\n for (j <- 1 until i)\n a(i)(j) = a(i-1)(j) + a(i-1)(j-1)\n }\n a\n }\n\n def main(args: Array[String]) {\n val comb = mkComb(31)\n val n = nextInt()\n val m = nextInt()\n val actors = nextInt()\n val ans = for ( boys <- 0 to actors;\n girls = actors - boys\n if boys >= 4 && boys <= n\n if girls >= 1 && girls <= m\n ) yield (comb(n)(boys) * comb(m)(girls))\n println(ans.sum)\n }\n\n val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));\n var st = new java.util.StringTokenizer(\"\");\n\n def next() = {\n while (!st.hasMoreTokens())\n st = new java.util.StringTokenizer(in.readLine());\n st.nextToken();\n }\n\n def nextInt() = java.lang.Integer.parseInt(next());\n def nextDouble() = java.lang.Double.parseDouble(next());\n def nextLong() = java.lang.Long.parseLong(next());\n}\n"}, {"source_code": "object C131 {\n\tdef fact(t: Int): BigInt = if (t <= 1) BigInt(1) else t * fact(t - 1)\n\timplicit def implfact(t: Int) = new { def ! = fact(t)}\n\n\tdef c(n: Int, k: Int): BigInt = (n!)/((k!) * ((n - k)!))\n\n\tdef main(args: Array[String]) {\n\t\tval s = readLine.split(\" \")\n\t\tval n = Integer.parseInt(s(0))\n\t\tval m = Integer.parseInt(s(1))\n\t\tval t = Integer.parseInt(s(2))\n\t\tvar res = BigInt(0)\n\t\tfor (i <- 4 to n)\n\t\t\tfor (j <- 1 to m)\n\t\t\t\tif (i + j == t)\n\t\t\t\t\tres += c(n, i) * c(m, j)\n\t\tprintln(res)\n\t}\n}"}, {"source_code": "object Main {\n val cache: Array[Array[Long]] = (1 to 61).map(_ => (1L to 61L).toArray).toArray\n for{\n i <- 0 to 60\n j <- 0 to 60\n } {\n (i, j) match {\n case (n, 0) => cache(n)(0) = 1\n case (0, k) => cache(0)(k) = 0\n case (n, k) => cache(n)(k) = cache(n - 1)(k - 1) + cache(n - 1)(k)\n }\n }\n\n def main(args: Array[String]) {\n val Array(n, m, k) = readLine().split(\" \").map(_.toInt)\n val sum = (4 to n.min(k - 1)).map(i => cache(n)(i) * cache(m)(k - i)).sum\n println(sum)\n }\n}"}], "negative_code": [{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n\n def factorial(n: Int) = (1 to n).foldLeft(1l) { case(acc, i) => acc * i }\n\n def combinations(k: Int, n: Int) = factorial(n) / (factorial(k) * factorial(n - k))\n\n\n val in = Source.stdin.getLines()\n val Array(n, m, t) = in.next().split(' ').map(_.toInt)\n println((1 to t - 4).foldLeft(0l) {\n case(sum, i) => sum + combinations(i, m) * combinations(t - i, n)\n })\n}\n"}], "src_uid": "489e69c7a2fba5fac34e89d7388ed4b8"} {"nl": {"description": "It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board of the size n × m centimeters (each cell is 1 × 1 centimeters). She can jump as she wishes for an arbitrary number of times, she can even visit a cell more than once. The only restriction is that she cannot jump out of the board.The flea can count the amount of cells that she can reach from the starting position (x, y). Let's denote this amount by dx, y. Your task is to find the number of such starting positions (x, y), which have the maximum possible value of dx, y.", "input_spec": "The first line contains three integers n, m, s (1 ≤ n, m, s ≤ 106) — length of the board, width of the board and length of the flea's jump.", "output_spec": "Output the only integer — the number of the required starting positions of the flea.", "sample_inputs": ["2 3 1000000", "3 3 2"], "sample_outputs": ["6", "4"], "notes": null}, "positive_code": [{"source_code": "object P032C extends App {\n val a = readLine.split(' ').map(_.toLong)\n val f = (n: Long, s: Long) => ((n-1)%s+1) * ((n-1)/s+1)\n println(f(a(0), a(2)) * f(a(1), a(2)))\n}\n"}], "negative_code": [{"source_code": "object P032C extends App {\n val a = readLine.split(' ').map(_.toInt)\n val f = (n: Int, s: Int) => ((n-1)%s+1) * ((n-1)/s+1)\n println(f(a(0), a(2)) * f(a(1), a(2)))\n}\n"}], "src_uid": "e853733fb2ed87c56623ff9a5ac09c36"} {"nl": {"description": "Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle.More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied. Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i (0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways).", "input_spec": "A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three.", "output_spec": "Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7.", "sample_inputs": ["1", "2"], "sample_outputs": ["20", "680"], "notes": "Note20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): "}, "positive_code": [{"source_code": "/**\n * @author netman\n */\n\n\nimport java.io._\nimport scala._\nimport scala.Array._\nimport java.util.ArrayList\nimport scala.collection.mutable._\nimport java.util.StringTokenizer\n\n\nobject HelloWorld {\n\n class InputReader(reader: BufferedReader) {\n \n var tokenizer: StringTokenizer = null;\n \n def this(stream: InputStream) = {\n this(new BufferedReader(new InputStreamReader(stream), (1 << 20)));\n }\n \n def this(f: File) = {\n this(new BufferedReader(new FileReader(f), (1 << 20)));\n }\n \n def next(): String = {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n \n def nextInt(): Int = next().toInt\n \n def nextDouble(): Double = next().toDouble\n \n def close() = reader.close();\n }\n \n class OutputWriter(writer: PrintWriter) {\n def this(stream: OutputStream) {\n this(new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream))));\n }\n \n def this(f: File) = {\n this(new PrintWriter(new BufferedWriter(new FileWriter(f))));\n }\n \n def print(x: Any) = writer.print(x);\n \n def println(x: Any) = writer.println(x);\n \n def close() = writer.close();\n }\n \n \n val in = new InputReader(System.in)\n val out = new OutputWriter(System.out)\n \n val P = 1000 * 1000 * 1000L + 7\n \n def main(args: Array[String]): Unit = { \n val n = in.nextInt\n \n var f = new Array[Long](2)\n var fn = new Array[Long](2)\n \n f(0) = 1\n \n val coef = 7L\n val all = 3 * 3 * 3L\n \n for (i <- 0 until n) {\n fn(0) = f(0) * coef\n fn(1) = f(1) * all + f(0) * (all - coef)\n fn(0) %= P\n fn(1) %= P\n var tmp = f\n f = fn\n fn = tmp\n }\n \n out.println(f(1))\n \n out.close\n }\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n\n val n = in.next().toInt\n var ans = (BigInt(3).pow(3 * n) - BigInt(7).pow(n)) % 1000000007\n println(ans.toLong)\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject B extends App {\n val Array(n) = readLine().split(\" \").map(_.toInt)\n\n val M = 1000000007\n\n def countMod(base: Int, power: Int): Long = {\n var curr: Long = base\n for (i <- 2 to power) {\n curr *= base\n if (curr > M) curr %= M\n }\n curr\n }\n\n// def countMod2(base: Int, power: Int): Long = {\n// BigInt(base).modPow(power, M).toLong\n// }\n\n val answer = countMod(27, n) - countMod(7, n)\n println(if (answer < 0) M + answer else answer)\n\n}\n"}], "negative_code": [{"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n\n val n = in.next().toLong\n println((Math.pow(3, 3 * n) - Math.pow(7, n)).toLong % 1000000007)\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject B extends App {\n val Array(n) = readLine().split(\" \").map(_.toInt)\n\n val M = 1000000007\n\n def countMod(base: Int, power: Int): Long = {\n var curr: Long = base\n for (i <- 2 to power) {\n curr *= base\n if (curr > M) curr %= M\n }\n curr\n }\n\n println(countMod(27, n) - countMod(7, n))\n\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject B extends App {\n val Array(n) = readLine().split(\" \").map(_.toInt)\n\n val M = 1000000007\n\n def countMod(base: Int, power: Int): Long = {\n var curr: Long = base\n for (i <- 2 to power) {\n curr *= base\n if (curr > M) curr %= M\n }\n curr\n }\n\n val answer = countMod(27, n) - countMod(7, n)\n println(if (answer < 0) M - answer else answer)\n\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject B extends App {\n val Array(n) = readLine().split(\" \").map(_.toInt)\n\n val M = 1000000007\n\n def countMod(base: Int, power: Int): Long = {\n var curr: Long = base\n for (i <- 2 to power) {\n curr *= base\n if (curr > M) curr %= M\n }\n curr\n }\n\n def countMod2(base: Int, power: Int): Long = {\n BigInt(base).modPow(power, M).toLong\n }\n\n\n val answer = countMod2(27, n) - countMod2(7, n)\n println(if (answer < 0) M - answer else answer)\n\n}\n"}], "src_uid": "eae87ec16c284f324d86b7e65fda093c"} {"nl": {"description": "Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). Digits are written one by one in order corresponding to number and separated by single '0' character. Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.", "input_spec": "The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s. The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.", "output_spec": "Print the decoded number.", "sample_inputs": ["3\n111", "9\n110011101"], "sample_outputs": ["3", "2031"], "notes": null}, "positive_code": [{"source_code": "import scala.collection.mutable.ArrayBuffer\nimport scala.io.StdIn._\n\nobject Main extends App {\n readLine()\n val a = readLine().split(\"0\", -1)\n var res = \"\"\n a.foreach(x => res += x.length)\n println(res)\n}\n"}, {"source_code": "object Main extends App {\n val n = io.StdIn.readInt()\n var s: String = io.StdIn.readLine()\n\n var result = \"\"\n while(!s.isEmpty){\n if (s.head == '0') s = s.tail\n val (head, tail) = s.span(_ == '1')\n result += head.length.toString\n s = tail\n }\n println(result)\n}"}, {"source_code": "object Main extends App {\n scala.io.StdIn.readLine()\n print(scala.io.StdIn.readLine().split(\"0\", -1).map(_.length).mkString(\"\"))\n}"}], "negative_code": [{"source_code": "import scala.collection.mutable.ArrayBuffer\nimport scala.io.StdIn._\n\nobject Main extends App {\n readLine()\n val a = readLine().split('0')\n var res = \"\"\n a.foreach(x => res += x.length)\n println(res)\n}\n"}, {"source_code": "object Main extends App {\n scala.io.StdIn.readLine()\n print(scala.io.StdIn.readLine().split(\"0\").map(_.length).mkString(\"\"))\n}"}], "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa"} {"nl": {"description": "Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).The University works in such a way that every day it holds exactly n lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks).The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the n pairs she knows if there will be a class at that time or not.Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university.Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home.Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.", "input_spec": "The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of lessons at the university. The second line contains n numbers ai (0 ≤ ai ≤ 1). Number ai equals 0, if Alena doesn't have the i-th pairs, otherwise it is equal to 1. Numbers a1, a2, ..., an are separated by spaces.", "output_spec": "Print a single number — the number of pairs during which Alena stays at the university.", "sample_inputs": ["5\n0 1 0 1 1", "7\n1 0 1 0 0 1 0", "1\n0"], "sample_outputs": ["4", "4", "0"], "notes": "NoteIn the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair. In the last sample Alena doesn't have a single pair, so she spends all the time at home."}, "positive_code": [{"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).dropWhile(_ == 0).reverse.dropWhile(_ == 0).reverse\n val res = data.foldLeft((0, 0)){\n case((soFar, zeros), 1) if zeros < 2 => (soFar + zeros + 1, 0)\n case((soFar, zeros), 1) => (soFar + 1, 0)\n case((soFar, zeros), 0) => (soFar, zeros + 1)\n }\n\n println(res._1)\n\n}"}, {"source_code": "object A586 {\n\n import IO._\n\n def main(args: Array[String]): Unit = {\n val Array(n) = readInts(1)\n val in = readInts(n).dropWhile(_ == 0).reverse.dropWhile(_ == 0).reverse\n var res = 0\n var curr = 0\n for(i <- in.indices) {\n if(in(i) == 0) {\n curr += 1\n res += 1\n } else {\n res += 1\n if(curr > 1)\n res -= curr\n curr = 0\n }\n }\n println(res)\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"}, {"source_code": "import scala.io.StdIn._\n\nobject A extends App {\n readInt()\n\n val pairs = readLine().split(\" \").map(_.toInt).dropWhile(_ == 0).reverse.dropWhile(_ == 0)\n\n var lastlast = 1\n var last = 1\n var zeros = 0\n for (p <- pairs) {\n if (p == 0) {\n if (last == 0 && lastlast == 0) zeros += 1\n else if (last == 0) zeros += 2\n }\n\n lastlast = last\n last = p\n }\n\n println(pairs.length - zeros)\n}\n"}, {"source_code": "\nimport java.io._\n\n//32A, 586A\nobject A_AlenaSchedule {\n \n def main(args: Array[String]): Unit = {\n val bis = new BufferedInputStream(System.in);\n val br = new BufferedReader(new InputStreamReader(bis));\n\n val number = br.readLine().trim().toInt\n val pairsSrc = br.readLine().trim().split(\" \")\n \n// val number = 5\n// val pairsSrc = \"0 1 0 1 1\".split(\" \")\n \n// val number = 7\n// val pairsSrc = \"1 0 1 0 0 1 0\".split(\" \")\n \n \n var pairs = List[Int]()\n var break = true\n var breakCandidate = false;\n \n for (i <- 0 until number) {\n val value = pairsSrc(i).toInt \n if (breakCandidate && value == 0) {\n break = true\n breakCandidate = false\n } else if (break && value == 0) {\n //skip\n } else if (value == 1) {\n break = false\n if (breakCandidate) {\n pairs = 0 :: pairs\n breakCandidate = false\n }\n pairs = value :: pairs\n } else if (!break && value == 0) {\n if(!breakCandidate) {\n breakCandidate = true\n } \n } \n }\n \n println(pairs.size)\n\n }\n}\n"}], "negative_code": [], "src_uid": "2896aadda9e7a317d33315f91d1ca64d"} {"nl": {"description": "It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through n, are arranged so that the i-th cow occupies the i-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his k minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute.Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the k minutes that they have. We denote as pi the label of the cow in the i-th stall. The messiness of an arrangement of cows is defined as the number of pairs (i, j) such that i < j and pi > pj.", "input_spec": "The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100 000) — the number of cows and the length of Farmer John's nap, respectively.", "output_spec": "Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than k swaps. ", "sample_inputs": ["5 2", "1 10"], "sample_outputs": ["10", "0"], "notes": "NoteIn the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.In the second sample, there is only one cow, so the maximum possible messiness is 0."}, "positive_code": [{"source_code": "import scala.collection._\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, k) = readInts(2)\n\n var res = 0L\n\n val lim = math.min(k, n / 2)\n for (i <- 1 to lim) {\n val x = n - 2 * i\n res += 2 * x + 1\n }\n\n println(res)\n}\n"}, {"source_code": "import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._\n\nobject _645B extends CodeForcesApp {\n override def apply(io: IO) = {\n val n, k = io[Long]\n io += solve(n, k, 0)\n }\n\n @tailrec\n def solve(n: Long, k: Long, acc: Long): Long = {\n //debug(n, k)\n (n, k) match {\n case (_, 0) => acc\n case (1, _) | (0, _) => acc\n case _ => solve(n - 2, k - 1, acc + (n - 2) + (n - 1))\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}\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 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 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"}], "negative_code": [], "src_uid": "ea36ca0a3c336424d5b7e1b4c56947b0"} {"nl": {"description": "Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number n is almost lucky.", "input_spec": "The single line contains an integer n (1 ≤ n ≤ 1000) — the number that needs to be checked.", "output_spec": "In the only line print \"YES\" (without the quotes), if number n is almost lucky. Otherwise, print \"NO\" (without the quotes).", "sample_inputs": ["47", "16", "78"], "sample_outputs": ["YES", "YES", "NO"], "notes": "NoteNote that all lucky numbers are almost lucky as any number is evenly divisible by itself.In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4."}, "positive_code": [{"source_code": "object a {\n\tdef main(args: Array[String]) {\n\t val a = scala.io.StdIn.readInt()\n var ans = List(4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777).\n map(arg => a%arg).\n\t exists(arg => arg == 0)\n\n print(if (ans) \"YES\" else \"NO\")\n\t}\n}"}, {"source_code": "import scala.io.StdIn\nimport scala.util.control.Breaks\n\n/**\n * @author traff\n */\n\nobject Main extends App {\n val n = StdIn.readLine().toInt\n\n Breaks.breakable {\n for (i <- 2 to n) {\n if (n % i == 0 && !i.toString.exists(!\"47\".contains(_))) {\n println(\"YES\")\n Breaks.break()\n }\n }\n println(\"NO\")\n }\n}\n\n"}, {"source_code": "object Solution extends App{\n val in = scala.io.Source.stdin.getLines()\n val n = in.next().toInt\n if (List(4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777).exists(t => n % t == 0)) \n println(\"YES\") else println(\"NO\")\n}"}, {"source_code": "import scala.collection.mutable.ArrayBuffer\n\nobject Main {\n\n\n def generateLuckyMumbers(buf: ArrayBuffer[Int], maxValue: Int, currentValue: Int): Unit = {\n if (currentValue <= maxValue) {\n buf.append(currentValue)\n generateLuckyMumbers(buf, maxValue, currentValue * 10 + 4)\n generateLuckyMumbers(buf, maxValue, currentValue * 10 + 7)\n }\n }\n\n\n def main(args: Array[String]) {\n val std = scala.io.StdIn\n val number = std.readLine().toInt\n\n val luckyNumbers = ArrayBuffer.empty[Int]\n generateLuckyMumbers(luckyNumbers, number, 4)\n generateLuckyMumbers(luckyNumbers, number, 7)\n val result = luckyNumbers.exists(x => number % x == 0)\n if (result) {\n println(\"YES\")\n }\n else {\n println(\"NO\")\n }\n }\n}"}, {"source_code": "import scala.io.StdIn\n\n/**\n * Created by richard on 2015/6/10.\n */\nobject cf112a {\n def main(args: Array[String]): Unit = {\n val num = Array(4,7,47,74,447,474,477,744,747,774,777)\n val n = StdIn.readInt()\n println(if (num.exists(n%_==0)) \"YES\" else \"NO\")\n }\n}\n"}, {"source_code": "object A122 {\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(num) = readBigs(1)\n val lucky = Array(\"4\", \"7\", \"44\", \"47\", \"74\", \"77\", \"444\", \"447\", \"474\", \"477\", \"744\", \"747\", \"774\", \"777\").map(BigInt.apply)\n if(lucky.exists{n => (num % n) == 0}) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n }\n}"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P122A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val luckyNumbers = (1 to 1000).filter { n =>\n n.toString.forall(c => c == '4' || c == '7')\n }\n\n def isAlmostLucky(i: Int): Boolean =\n luckyNumbers.find(i % _ == 0) match {\n case None => false\n case Some(_) => true\n }\n\n def solve: String =\n if (isAlmostLucky(sc.nextInt)) \"YES\"\n else \"NO\"\n\n out.println(solve)\n out.close\n}\n"}, {"source_code": "\n\nobject LuckyDivision {\n\tdef main (args: Array[String]) {\n\t\tval scanner = new java.util.Scanner(System.in);\n\t\tval input = scanner.nextInt();\n\t\tif (isLucky(input)) {\n\t\t\tprintln(\"YES\")\n\t\t\tSystem.exit(0)\n\t\t}\n\t\tfor (i <- 1 to input / 2) {\n\t\t\tif (input % i == 0 && isLucky(i)) {\n\t\t\t\tprintln(\"YES\")\n\t\t\t\tSystem.exit(0)\n\t\t\t}\n\t\t}\n\t\tprintln(\"NO\")\n\t}\n\n\tdef isLucky(in: Int) : Boolean = {\n\t\t\tvar lucky = true;\n\t\t\tvar tmp = in;\n\t\t\twhile (lucky && tmp > 0) {\n\t\t\t\tval rem = tmp % 10;\n\t\t\t\tif (rem != 4 && rem != 7) {\n\t\t\t\t\tlucky = false\n\t\t\t\t}\n\t\t\t\ttmp /= 10\n\t\t\t}\n\t\t\tlucky\n\t}\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject LuckyDivision extends App {\n\n def isLucky(i: Int): Boolean = i match {\n case 0 => true\n case _ => (i%10 == 4 || i%10 == 7) && isLucky(i / 10)\n }\n\n def isAlmostLucky(i: Int, d: Int): Boolean = d match {\n case 0 => false\n case _ => (i%d == 0 && isLucky(d)) || isAlmostLucky(i, d-1)\n }\n\n val s = readInt\n println(if(isAlmostLucky(s, s)) \"YES\" else \"NO\")\n}\n"}, {"source_code": "object Codeforces122A extends App{\n\n def CreateLuckyNumberSet:List[Int] = {\n var luckyset:List[Int] = List()\n luckyset = List(4,7,44,47,74,77,444,447,474,477,744,747,774,777)\n return luckyset\n }\n def TestAlmostLuckyNumber(query:Int):Boolean={\n val luckyset:List[Int] = CreateLuckyNumberSet\n for (i <- luckyset){\n if (query%i == 0){\n return true\n }\n }\n return false\n }\n var query:Int=scala.io.StdIn.readInt\n var ans:Boolean = TestAlmostLuckyNumber(query)\n if (ans == true){\n println(\"YES\")\n }\n else {\n println(\"NO\")\n }\n}\n"}, {"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 limitedStream(cur: Int, sqr: Int): Stream[Int] = if(cur * cur > sqr) Stream.Empty else cur #:: limitedStream(cur + 1, sqr)\n def dividersStream(n: Int) = limitedStream(1, n).filter(n % _ == 0)\n def allDividersStream(n: Int) = dividersStream(n).flatMap { x =>\n Stream(x, n / x)\n }\n def beautifulInt(x: Int) = x.toString.forall(\"47\".contains(_))\n def beautifulDividersStream(n: Int) = allDividersStream(n).filter(beautifulInt)\n\n def main(a: Array[String]) {\n println(if(beautifulDividersStream(readInt).isEmpty) \"NO\" else \"YES\")\n }\n}\n"}, {"source_code": "object Main {\n val happy: Stream[Int] = {\n def nextGen(ls: List[Int], gen: Int): Stream[Int] = {\n val nextLs = List(4, 7).flatMap(e => ls.map(e * gen +))\n nextLs.toStream #::: nextGen(nextLs, gen * 10) \n }\n nextGen(List(0), 1)\n }\n\n def main(args: Array[String]) {\n val num = readInt()\n var isHappy = false\n for(h <- happy.takeWhile(_ <= num)) {\n if (num % h == 0) isHappy |= true\n }\n if (isHappy) println(\"YES\")\n else println(\"NO\")\n }\n}"}, {"source_code": "// Codeforces 122A\n\nobject _122A extends App {\n val scanner = new java.util.Scanner(System.in)\n val lucky_numbers = List(4, 7, 47, 74, 447, 474, 477, 747)\n val n = scanner.nextInt\n println(\n if (lucky_numbers.exists(n%_ == 0)) \"YES\" else \"NO\"\n )\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject A_122 extends App {\n val n = readInt()\n\n def isLucky(x: Int) = x.toString.toCharArray.toSet.forall(x => x == '4' || x == '7')\n\n val L = 1 to 1000 filter isLucky\n\n if (L.contains(n) || L.exists(l => n % l == 0)) println(\"YES\")\n else println(\"NO\")\n}\n"}, {"source_code": "import scala.io.StdIn.readLine\nobject problem {\n def main(args: Array[String]) {\n val s = readLine.toInt\n println(if(List(4,7,47,74,447,477,744,747).exists(s%_ == 0)) \"YES\" else \"NO\")\n }\n}"}, {"source_code": "object JuanDavidRobles122A {\n def main(args: Array[String]): Unit = {\n\n import scala.io.StdIn\n \n var number: Int = Integer.parseInt(StdIn.readLine())\n var string: String = \"\"\n var out: String = \"NO\"\n \n string = String.valueOf(number)\n string = string.replace(\"4\",\"\")\n string = string.replace(\"7\",\"\")\n if (string.equals(\"\")){\n out = \"YES\"\n }\n \n for (i <- 4 to number){\n \n string = String.valueOf(i)\n string = string.replace(\"4\",\"\")\n string = string.replace(\"7\",\"\")\n if (string.equals(\"\") && number%i == 0){\n out = \"YES\"\n }\n }\n \n println(out)\n\n }\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject HelloWorldMain {\n\n def main(args: Array[String]): Unit = {\n\n\n val luckOrNot = readInt()\n\n val allLuckies = for( i <- 1 to 1000 if i.toString.matches(\"(4|7)*\") ) yield i\n\n var result = \"NO\"\n allLuckies.foreach(i => if(luckOrNot % i == 0 ) result = \"YES\" )\n\n\n println(result)\n\n\n\n }\n}\n\n\n"}, {"source_code": "import scala.io.StdIn.readInt\n\n\nobject LuckyNumbers {\n \n def main(args: Array[String]) { \n val n = readInt\n if (Range(1,n).inclusive.\n filter { p => p.toString().toSet subsetOf Set('4','7') }.\n exists(n%_ == 0))\n println(\"YES\")\n else\n println(\"NO\")\n }\n \n}"}, {"source_code": "object Main extends App{\n val in= readLine\n val n =in.toInt\n if(List(4,7,44,47,74,77,444,447,474,477,744,747,774,777).exists(t => n % t ==0)) \n println(\"YES\")else println(\"NO\")\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject cf extends App\n{\n val v = readInt\n print(if(List(4,7,44,47,74,77,444,447,474,477,744,747,774,777).exists(kuy => v%kuy==0)) \"YES\" else \"NO\")\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject Task extends App{\n\tval N = readLine.split(\" \").map{_.toInt}.head\n\t\n\tdef isLucky(n:Int):Boolean = {\n def aux(n:Int, div:String):Boolean = {\n val d = div.toInt\n \n if(n < d)\n false\n else if(n % d == 0)\n true\n else {\n aux(n, div + \"4\") || aux(n, div + \"7\")\n }\n }\n \n aux(n, \"4\") || aux(n, \"7\")\n\t}\n\t\n\tif(isLucky(N))\n\t println(\"YES\")\n\telse\n\t println(\"NO\")\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject Solution {\n\n\tvar n = readInt\n\n\tdef isLucky(n:Int):Boolean = {\n\t\tvar nst = n.toString\n\t\tvar ret = true\n\t\tfor(i <- 0 until nst.size) {\n\t\t\tif(nst(i) != '4' && nst(i) != '7') ret = false\n\t\t}\n\t\tret\n\t}\n\n\tdef main(args:Array[String]):Unit = {\n\t\tvar almostLucky = false\n\t\tfor(i <- 1 to n) {\n\t\t\tif(isLucky(i) && !almostLucky && n%i == 0) {\n\t\t\t\tprintln(\"YES\")\n\t\t\t\talmostLucky = true\n\t\t\t}\n\t\t}\n\t\tif(!almostLucky) println(\"NO\")\n\t}\n\n}\n"}, {"source_code": "object Divider{\n\n def main(args: Array[String]): Unit = {\n val n = readInt()\n\n val list = List(4,7,47,74,444,447,474,477,744,774,747,777)\n\n if(list.contains(n) || list.exists(x => n % x == 0) ) println(\"YES\") else print(\"NO\")\n }\n}"}, {"source_code": "object One22A extends App {\n\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\n\tval n = in.nextInt\n\n\tlucky(n) match {\n\t\tcase true => yes\n\t\tcase false =>\n\t\t\t(4 to n - 1).exists(lucky) match {\n\t\t\t\tcase true => yes\n\t\t\t\tcase false => no\n\t\t\t}\n\t}\n\n\tin.close()\n\tout.close()\n\n\tdef yes = out.println(\"YES\")\n\tdef no = out.println(\"NO\")\n\tdef lucky(str: Int) = n % str == 0 && str.toString.forall(x => x == '4' || x == '7')\n\n}"}, {"source_code": "object CF0122A extends App {\n\n val l = List(4, 7, 47, 74, 444, 447, 474, 744, 774, 747, 777)\n\n def del(v: Int): Boolean = {\n\n var t = false\n\n l.foreach(n => {\n if (v%n == 0) {\n t = true\n }\n })\n\n t\n }\n\n val str = readLine()\n val value = str.toInt\n if (value % 4 == 0 || value % 7 == 0 || del(value)) {\n println(\"YES\")\n } else {\n val status = str.getBytes.forall(b => {\n b == '4' || b == '7'\n })\n\n if (status) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n }\n\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject Task {\n\n def main(args: Array[String]): Unit = {\n\n val x: Int = StdIn.readInt()\n if (solve(x)) {\n println(\"YES\")\n }\n else {\n println(\"NO\")\n }\n\n }\n\n private def solve(x: Int): Boolean = {\n\n val lucky: Array[Int] = Array(4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777)\n for (l <- lucky) {\n if (x % l == 0) {\n return true\n }\n }\n return false\n\n }\n\n}\n"}, {"source_code": "import scala.collection.immutable\n\nobject Hello extends App {\n\n import scala.io.StdIn._\n\n val k = readInt()\n\n def countNums(n: Int): Int = n.toString.length\n\n def permutationsWithRepetitions[T](input : List[T], n : Int) : List[List[T]] = {\n require(input.nonEmpty && n > 0)\n n match {\n case 1 => for (el <- input) yield List(el)\n case _ => for (el <- input; perm <- permutationsWithRepetitions(input, n - 1)) yield el :: perm\n }\n }\n\n def allPermutationsWithRepetitions[T](input : List[T], n : Int, result: List[List[List[T]]]): List[List[List[T]]] =\n if (n == 0) result\n else allPermutationsWithRepetitions(input, n - 1, result :+ permutationsWithRepetitions(input, n))\n\n val nums: immutable.Seq[Int] = allPermutationsWithRepetitions(List(4, 7), countNums(k), List()).flatten.map(_.mkString(\"\")).map(Integer.parseInt)\n\n if (nums.exists(k % _ == 0) || nums.contains(k)) println(\"YES\") else println(\"NO\")\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject HappyNum extends App {\n val num = readInt\n var ok = false\n\n val list = List(4, 7, 44, 47, 74, 77, 444, 447, 477, 474, 744, 747, 774, 777)\n\n if (list.contains(num)) {\n ok = true\n }else {\n for(i <- list){\n if (num % i == 0) ok = true\n }\n }\n\n if (ok) print(\"YES\")\n else print(\"NO\")\n\n}\n"}], "negative_code": [{"source_code": "object HappyNum extends App {\n val num = readLine()\n val numnum = num.toInt\n val listNum = num.toList\n var ok = true\n\n for(i <- listNum){\n if (i != '4' && i != '7'){\n ok = false\n }\n }\n if (!ok && numnum % 7 == 0 || numnum % 4 == 0){\n ok = true\n }\n if (ok) print(\"YES\")\n else print(\"NO\")\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject HappyNum extends App {\n val num = readInt\n var ok = false\n\n val list = List(4, 7, 44, 47, 74, 77, 444, 447, 474, 744, 747, 774, 777)\n\n if (list.contains(num)) {\n ok = true\n }else {\n for(i <- list){\n if (num % i == 0) ok = true\n }\n }\n\n if (ok) print(\"YES\")\n else print(\"NO\")\n\n}"}, {"source_code": "\n\nobject LuckyDivision {\n\tdef main (args: Array[String]) {\n\t\tval scanner = new java.util.Scanner(System.in);\n\t\tval input = scanner.nextInt();\n\t\tif (isLucky(input)) {\n\t\t\tprintln(\"YES\")\n\t\t\tSystem.exit(0)\n\t\t}\n\t\tval sqrtInput = Math.round (Math.sqrt(input))\n\t\t\t\tfor (i <- 1 to sqrtInput.toInt) {\n\t\t\t\t\tif (isLucky(i) && input % i == 0) {\n\t\t\t\t\t\tprintln(\"YES\")\n\t\t\t\t\t\tSystem.exit(0)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\tprintln(\"NO\")\n\t}\n\n\tdef isLucky(in: Int) : Boolean = {\n\t\t\tvar lucky = true\n\t\t\t\t\tvar tmp = in\n\t\t\t\t\twhile (lucky && tmp > 0) {\n\t\t\t\t\t\tval rem = tmp % 10\n\t\t\t\t\t\t\t\tif (rem != 4 && rem != 7) {\n\t\t\t\t\t\t\t\t\tlucky = false\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\ttmp = tmp / 10\n\t\t\t\t\t}\n\t\t\tlucky\n\t}\n}"}, {"source_code": "\n\nobject LuckyDivision {\n\tdef main (args: Array[String]) {\n\t\tval scanner = new java.util.Scanner(System.in);\n\t\tval input = scanner.nextInt();\n\t\tif (isLucky(input)) {\n\t\t\tprintln(\"YES\")\n\t\t\tSystem.exit(0)\n\t\t}\n\t\tval sqrtInput = Math.round (Math.sqrt(input))\n\t\t\t\tfor (i <- 1 to sqrtInput.toInt + 1) {\n\t\t\t\t\tif (isLucky(i) && input % i == 0) {\n\t\t\t\t\t\tprintln(\"YES\")\n\t\t\t\t\t\tSystem.exit(0)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\tprintln(\"NO\")\n\t}\n\n\tdef isLucky(in: Int) : Boolean = {\n\t\t\tvar lucky = true\n\t\t\t\t\tvar tmp = in\n\t\t\t\t\twhile (lucky && tmp > 0) {\n\t\t\t\t\t\tval rem = tmp % 10\n\t\t\t\t\t\t\t\tif (rem != 4 && rem != 7) {\n\t\t\t\t\t\t\t\t\tlucky = false\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\ttmp = tmp / 10\n\t\t\t\t\t}\n\t\t\tlucky\n\t}\n}"}, {"source_code": "object CF0122A extends App {\n\n val str = readLine()\n val value = str.toInt\n if (value % 4 == 0 || value % 7 == 0) {\n println(\"YES\")\n } else {\n val status = str.getBytes.forall(b => {\n b == '4' || b == '7'\n })\n\n if (status) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n }\n\n}\n"}], "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d"} {"nl": {"description": "Let's assume that we have a pair of numbers (a, b). We can get a new pair (a + b, b) or (a, a + b) from the given pair in a single step.Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of steps needed to transform (1,1) into the pair where at least one number equals n.", "input_spec": "The input contains the only integer n (1 ≤ n ≤ 106).", "output_spec": "Print the only integer k.", "sample_inputs": ["5", "1"], "sample_outputs": ["3", "0"], "notes": "NoteThe pair (1,1) can be transformed into a pair containing 5 in three moves: (1,1)  →  (1,2)  →  (3,2)  →  (5,2)."}, "positive_code": [{"source_code": "\nobject Main {\n \n val inf = 1000000000\n\n def gcdCount(a: Int, b: Int, sum: Int):Int =\n if (b != 0) gcdCount(b, a % b, sum + a / b)\n else if (a == 1) (sum - 1)\n else inf\n\n def main(args: Array[String]) {\n val n = nextInt\n val ans = (1 to n).map(gcdCount(n, _, 0))\n println(ans.min)\n }\n\n val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));\n var st = new java.util.StringTokenizer(\"\");\n\n def next() = {\n while (!st.hasMoreTokens())\n st = new java.util.StringTokenizer(in.readLine());\n st.nextToken();\n }\n\n def nextInt() = java.lang.Integer.parseInt(next());\n def nextDouble() = java.lang.Double.parseDouble(next());\n def nextLong() = java.lang.Long.parseLong(next());\n}\n"}], "negative_code": [], "src_uid": "75739f77378b21c331b46b1427226fa1"} {"nl": {"description": "Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into n consecutive segments, each segment needs to be painted in one of the colours.Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them.", "input_spec": "The first line contains a single positive integer n (1 ≤ n ≤ 100) — the length of the canvas. The second line contains a string s of n characters, the i-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one).", "output_spec": "If there are at least two different ways of painting, output \"Yes\"; otherwise output \"No\" (both without quotes). You can print each character in any case (upper or lower).", "sample_inputs": ["5\nCY??Y", "5\nC?C?Y", "5\n?CYC?", "5\nC??MM", "3\nMMY"], "sample_outputs": ["Yes", "Yes", "Yes", "No", "No"], "notes": "NoteFor the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example."}, "positive_code": [{"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 val s = readLine\n\n val ok = (!(s.contains(\"CC\") || s.contains(\"YY\") || s.contains(\"MM\"))) &&\n (s.startsWith(\"?\") || s.endsWith(\"?\") || s.contains(\"??\") ||\n s.contains(\"C?C\") || s.contains(\"Y?Y\") || s.contains(\"M?M\"))\n\n println(if (ok) \"Yes\" else \"No\")\n}\n"}, {"source_code": "object objecta {\n import java.io.{BufferedReader, FileInputStream, InputStreamReader}\n import scala.collection.mutable\n import scala.util.control.Breaks._\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 val s = readString\n\n for (i <- 0 until n - 1)\n if (s(i) != '?' && s(i) == s(i + 1)){\n print(\"NO\")\n return\n }\n\n if (s(0) == '?' || s(n - 1) == '?') {\n print(\"YES\")\n return\n }\n\n for (i <- 1 until n - 2)\n if (s(i) == '?') {\n if (s(i + 1) == '?') {\n print(\"YES\")\n return\n } else if (s(i - 1) == s(i + 1)) {\n print(\"YES\")\n return\n }\n }\n print(\"NO\")\n }\n}\n"}], "negative_code": [{"source_code": "object objecta {\n import java.io.{BufferedReader, FileInputStream, InputStreamReader}\n import scala.collection.mutable\n import scala.util.control.Breaks._\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 val s = readString\n\n for (i <- 0 until n - 1)\n if (s(i) == '?') {\n if (s(i + 1) == '?') {\n print(\"YES\")\n return\n } else if (i > 0 && s(i - 1) == s(i + 1)) {\n print(\"YES\")\n return\n }\n } else if (s(i) == s(i + 1)){\n print(\"NO\")\n return\n }\n print(\"NO\")\n }\n}\n"}, {"source_code": "object objecta {\n import java.io.{BufferedReader, FileInputStream, InputStreamReader}\n import scala.collection.mutable\n import scala.util.control.Breaks._\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 val s = readString\n\n for (i <- 0 until n - 1)\n if (s(i) != '?' && s(i) == s(i + 1)){\n print(\"NO\")\n return\n }\n for (i <- 0 until n - 1)\n if (s(i) == '?') {\n if (s(i + 1) == '?') {\n print(\"YES\")\n return\n } else if (i ==0) {\n print(\"YES\")\n return\n } else if (s(i - 1) == s(i + 1)) {\n print(\"YES\")\n return\n }\n }\n print(\"NO\")\n }\n}\n"}, {"source_code": "object objecta {\n import java.io.{BufferedReader, FileInputStream, InputStreamReader}\n import scala.collection.mutable\n import scala.util.control.Breaks._\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 val s = readString\n\n if (n == 1)\n if (s(0) == '?') {\n print(\"YES\")\n return\n } else {\n print(\"NO\")\n return\n }\n\n for (i <- 0 until n - 1)\n if (s(i) != '?' && s(i) == s(i + 1)){\n print(\"NO\")\n return\n }\n for (i <- 0 until n - 1)\n if (s(i) == '?') {\n if (s(i + 1) == '?') {\n print(\"YES\")\n return\n } else if (i ==0) {\n print(\"YES\")\n return\n } else if (s(i - 1) == s(i + 1)) {\n print(\"YES\")\n return\n }\n }\n print(\"NO\")\n }\n}\n"}, {"source_code": "object objecta {\n import java.io.{BufferedReader, FileInputStream, InputStreamReader}\n import scala.collection.mutable\n import scala.util.control.Breaks._\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 val s = readString\n\n for (i <- 0 until n - 1)\n if (s(i) == s(i + 1)){\n print(\"NO\")\n return\n }\n for (i <- 0 until n - 1)\n if (s(i) == '?') {\n if (s(i + 1) == '?') {\n print(\"YES\")\n return\n } else if (i ==0) {\n print(\"YES\")\n return\n } else if (s(i - 1) == s(i + 1)) {\n print(\"YES\")\n return\n }\n }\n print(\"NO\")\n }\n}\n"}, {"source_code": "object objecta {\n import java.io.{BufferedReader, FileInputStream, InputStreamReader}\n import scala.collection.mutable\n import scala.util.control.Breaks._\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 val s = readString\n\n for (i <- 0 until n - 1)\n if (s(i + 1) != '?' && s(i) == s(i + 1)) {\n print(\"NO\")\n return\n }\n print(\"YES\")\n }\n}\n"}, {"source_code": "object objecta {\n import java.io.{BufferedReader, FileInputStream, InputStreamReader}\n import scala.collection.mutable\n import scala.util.control.Breaks._\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 val s = readString\n\n for (i <- 0 until n - 1)\n if (s(i) == '?') {\n if (s(i + 1) == '?') {\n print(\"YES\")\n return\n } else if (i ==0) {\n print(\"YES\")\n return\n } else if (s(i - 1) == s(i + 1)) {\n print(\"YES\")\n return\n }\n } else if (s(i) == s(i + 1)){\n print(\"NO\")\n return\n }\n print(\"NO\")\n }\n}\n"}], "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3"} {"nl": {"description": "Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an a1 × b1 rectangle, the paintings have shape of a a2 × b2 and a3 × b3 rectangles.Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be parallel to the floor. The paintings can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it is possible to place the paintings on the board, or is the board he bought not large enough?", "input_spec": "The first line contains two space-separated numbers a1 and b1 — the sides of the board. Next two lines contain numbers a2, b2, a3 and b3 — the sides of the paintings. All numbers ai, bi in the input are integers and fit into the range from 1 to 1000.", "output_spec": "If the paintings can be placed on the wall, print \"YES\" (without the quotes), and if they cannot, print \"NO\" (without the quotes).", "sample_inputs": ["3 2\n1 3\n2 1", "5 5\n3 3\n3 3", "4 2\n2 3\n1 2"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteThat's how we can place the pictures in the first test:And that's how we can do it in the third one."}, "positive_code": [{"source_code": "import io.StdIn._\n\nobject Solution {\n def main(args: Array[String]) {\n val p = readLine().split(\" \").map(_.toInt).sortBy(-_)\n val a = readLine().split(\" \").map(_.toInt).sortBy(-_)\n val b = readLine().split(\" \").map(_.toInt).sortBy(-_)\n\n var found = false\n if (p(0)-a(0)>=0 && p(1)-a(1)>=0) {\n val r1 = Array(p(0)-a(0), p(1)).sortBy(-_)\n if (r1(0)>=b(0) && r1(1)>=b(1)) found = true\n else {\n val r2 = Array(p(0), p(1)-a(1)).sortBy(-_)\n if (r2(0)>=b(0) && r2(1)>=b(1)) found = true\n }\n }\n if (p(0)-a(1)>=0 && p(1)-a(0)>=0) {\n val r1 = Array(p(0)-a(1), p(1)).sortBy(-_)\n if (r1(0)>=b(0) && r1(1)>=b(1)) found = true\n else {\n val r2 = Array(p(0), p(1)-a(0)).sortBy(-_)\n if (r2(0)>=b(0) && r2(1)>=b(1)) found = true\n }\n }\n\n if (found) println(\"YES\") else println(\"NO\")\n }\n}\n"}, {"source_code": "import annotation.tailrec, collection.mutable, util.control.Breaks._, math.Ordering.Implicits._\nimport CodeForcesApp._\nobject _560B extends CodeForcesApp[Boolean]({scanner => import scanner._\n val List(a1, b1, a2, b2, a3, b3) = List.fill(6)(nextInt)\n def fit(r: R) = {\n val (x, y) = r\n //debug(x, y, a1, b1)\n (x <= a1 && y <= b1) || (x <= b1 && y <= a1)\n }\n type R = (Int, Int)\n def join(r1: R, r2: R): R = (r1._1 + r2._1, r1._2 max r2._2)\n def allSwapJoin(r1: R, r2: R): List[R] = join(r1, r2) :: join(r1, r2.swap) :: join(r1.swap, r2) :: join(r1.swap, r2.swap) :: Nil\n def allJoin(r1: R, r2: R): List[R] = allSwapJoin(r1, r2) ::: allSwapJoin(r2, r1)\n allJoin((a2, b2), (a3, b3)) exists fit\n}) {\n override def format(result: Boolean) = if (result) \"YES\" else \"NO\"\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}"}], "negative_code": [{"source_code": "import annotation.tailrec, collection.mutable, util.control.Breaks._, math.Ordering.Implicits._\nimport CodeForcesApp._\nobject _560B extends CodeForcesApp[Boolean]({scanner => import scanner._\n val List(a1, b1, a2, b2, a3, b3) = List.fill(6)(nextInt)\n def fit(r: R) = {\n val (x, y) = r\n //debug(x, y, a1, b1)\n (x <= a1 && y <= b1) || (x <= b1 && y <= a1)\n }\n type R = (Int, Int)\n def join(r1: R, r2: R): R = (r1._1 + r2._1, r1._2 min r2._2)\n def allSwapJoin(r1: R, r2: R): List[R] = join(r1, r2) :: join(r1, r2.swap) :: join(r1.swap, r2) :: join(r1.swap, r2.swap) :: Nil\n def allJoin(r1: R, r2: R): List[R] = allSwapJoin(r1, r2) ::: allSwapJoin(r2, r1)\n allJoin((a2, b2), (a3, b3)) exists fit\n}) {\n override def format(result: Boolean) = if (result) \"YES\" else \"NO\"\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}\n"}], "src_uid": "2ff30d9c4288390fd7b5b37715638ad9"} {"nl": {"description": "The year 2015 is almost over.Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510 = 111110111112. Note that he doesn't care about the number of zeros in the decimal representation.Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster?Assume that all positive integers are always written without leading zeros.", "input_spec": "The only line of the input contains two integers a and b (1 ≤ a ≤ b ≤ 1018) — the first year and the last year in Limak's interval respectively.", "output_spec": "Print one integer – the number of years Limak will count in his chosen interval.", "sample_inputs": ["5 10", "2015 2015", "100 105", "72057594000000000 72057595000000000"], "sample_outputs": ["2", "1", "0", "26"], "notes": "NoteIn the first sample Limak's interval contains numbers 510 = 1012, 610 = 1102, 710 = 1112, 810 = 10002, 910 = 10012 and 1010 = 10102. Two of them (1012 and 1102) have the described property."}, "positive_code": [{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n\n def ceil(a: Long): String = {\n val str = a.toBinaryString\n val zeroCount = str.count(_ == '0')\n if (zeroCount == 1) str\n else if (zeroCount == 0) \"10\" + \"1\" * (str.length - 1)\n else {\n val ones = str.takeWhile(_ == '1').length\n \"1\" * ones + \"0\" + \"1\" * (str.length - ones - 1)\n }\n }\n\n def floor(a: Long): String = {\n val str = a.toBinaryString\n val zeroCount = str.count(_ == '0')\n if (zeroCount == 1) str\n else if (zeroCount == 0) str.dropRight(1) + '0'\n else {\n val ones = str.takeWhile(_ == '1').length\n if (ones == 1)\n \"1\" * (str.length - 2) + \"0\"\n else\n \"1\" * (ones - 1) + \"0\" + \"1\" * (str.length - ones)\n }\n }\n\n def count(aSize: Int, aZeroPosition: Int, bSize: Int, bZeroPosition: Int): Int = {\n if (aSize > bSize || (aZeroPosition > bZeroPosition && aSize == bSize)) 0\n else if (aSize == bSize && aZeroPosition == bZeroPosition) 1\n else if (aZeroPosition == aSize) count(aSize + 1, 1, bSize, bZeroPosition)\n else 1 + count(aSize, aZeroPosition + 1, bSize, bZeroPosition)\n }\n\n val in = Source.stdin.getLines()\n val Array(a, b) = in.next().split(' ').map(_.toLong)\n val c = ceil(a)\n val f = floor(b)\n// println(a.toBinaryString)\n// println(c)\n// println(b.toBinaryString)\n// println(f)\n println(count(c.length, c.indexOf('0'), f.length, f.indexOf('0')))\n}"}, {"source_code": "import scala.collection._\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(a, b) = readLongs(2)\n var res = 0L\n\n for (l <- 1 to 62) {\n val x = (1L << l) - 1\n for (j <- 0 until l - 1) {\n val y = x ^ (1L << j)\n if (a <= y && y <= b) {\n res += 1\n }\n }\n }\n println(res)\n}\n"}, {"source_code": "import io.StdIn._\nimport scala.collection.mutable._\n\nobject Solution {\n\n def main(args: Array[String]) {\n val Array(n, m) = readLine().split(\" \").map(_.toLong)\n\n var num = 0\n\n for (i <- 2 to 63) {\n for (j <- 0 to i-2) {\n val y = ((1.toLong<= n && y <= m) {\n num += 1\n// println(i+\"..\"+j+\"..\"+y)\n }\n }\n }\n\n println(num)\n\n }\n}"}, {"source_code": "import java.util.Scanner\nimport java.lang.Long.parseLong\n\nobject Main{\n def main (args: Array[String]){\n val sc = new Scanner(System.in)\n val a = sc.nextLong()\n val b = sc.nextLong()\n\n //\n val a_2 = a.toBinaryString\n val b_2 = b.toBinaryString\n\n val a_2l = a_2.length\n var shaku = \"10\"\n var flag = true\n var ans = 0L\n var digi_cnt = 1\n while(flag){\n val tn = parseLong(shaku, 2)\n\n if(a <= tn){\n if(b >= tn)\n ans += 1\n else\n flag = false\n }\n\n digi_cnt += 1\n val sl = shaku.length\n if(sl == digi_cnt){\n shaku = shaku.updated(digi_cnt - 1, '1')\n shaku = shaku ++ \"1\"\n shaku = shaku.updated(1, '0')\n digi_cnt = 1\n }\n else{\n shaku = shaku.updated(digi_cnt - 1, '1')\n shaku = shaku.updated(digi_cnt, '0')\n }\n }\n\n println(ans)\n }\n}\n\n \n"}], "negative_code": [{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n\n def ceil(a: Long): String = {\n val str = a.toBinaryString\n val zeroCount = str.count(_ == '0')\n if (zeroCount == 1) str\n else if (zeroCount == 0) str + '0'\n else {\n val ones = str.takeWhile(_ == '1').length\n \"1\" * ones + \"0\" + \"1\" * (str.length - ones - 1)\n }\n }\n\n def floor(a: Long): String = {\n val str = a.toBinaryString\n val zeroCount = str.count(_ == '0')\n if (zeroCount == 1) str\n else if (zeroCount == 0) str.dropRight(1) + '0'\n else {\n val ones = str.takeWhile(_ == '1').length\n if (ones == 1)\n \"1\" * (str.length - 2) + \"0\"\n else\n \"1\" * (ones - 1) + \"0\" + \"1\" * (str.length - ones)\n }\n }\n\n def count(aSize: Int, aZeroPosition: Int, bSize: Int, bZeroPosition: Int): Int = {\n if (aSize > bSize || (aZeroPosition > bZeroPosition && aSize == bSize)) 0\n else if (aSize == bSize && aZeroPosition == bZeroPosition) 1\n else if (aZeroPosition == aSize) count(aSize + 1, 0, bSize, bZeroPosition)\n else 1 + count(aSize, aZeroPosition + 1, bSize, bZeroPosition)\n }\n\n val in = Source.stdin.getLines()\n val Array(a, b) = in.next().split(' ').map(_.toLong)\n val c = ceil(a)\n val f = floor(b)\n println(count(c.length, c.indexOf('0'), f.length, f.indexOf('0')))\n}"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n\n def ceil(a: Long): String = {\n val str = a.toBinaryString\n val zeroCount = str.count(_ == '0')\n if (zeroCount == 1) str\n else if (zeroCount == 0) str + '0'\n else {\n val ones = str.takeWhile(_ == '1').length\n \"1\" * ones + \"0\" + \"1\" * (str.length - ones - 1)\n }\n }\n\n def floor(a: Long): String = {\n val str = a.toBinaryString\n val zeroCount = str.count(_ == '0')\n if (zeroCount == 1) str\n else if (zeroCount == 0) str.dropRight(1) + '0'\n else {\n val ones = str.takeWhile(_ == '1').length\n if (ones == 1)\n \"1\" * (str.length - 2) + \"0\"\n else\n \"1\" * (ones - 1) + \"0\" + \"1\" * (str.length - ones)\n }\n }\n\n def count(aSize: Int, aZeroPosition: Int, bSize: Int, bZeroPosition: Int): Int = {\n if (aSize > bSize) 0\n else if (aSize == bSize && aZeroPosition == bZeroPosition) 1\n else if (aZeroPosition == aSize) count(aSize + 1, 1, bSize, bZeroPosition)\n else 1 + count(aSize, aZeroPosition + 1, bSize, bZeroPosition)\n }\n\n val in = Source.stdin.getLines()\n val Array(a, b) = in.next().split(' ').map(_.toLong)\n val c = ceil(a)\n val f = floor(b)\n println(count(c.length, c.indexOf('0'), f.length, f.indexOf('0')))\n}"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n\n def ceil(a: Long): String = {\n val str = a.toBinaryString\n val zeroCount = str.count(_ == '0')\n if (zeroCount == 1) str\n else if (zeroCount == 0) str + '0'\n else {\n val ones = str.takeWhile(_ == '1').length\n \"1\" * ones + \"0\" + \"1\" * (str.length - ones - 1)\n }\n }\n\n def floor(a: Long): String = {\n val str = a.toBinaryString\n val zeroCount = str.count(_ == '0')\n if (zeroCount == 1) str\n else if (zeroCount == 0) str.dropRight(1) + '0'\n else {\n val ones = str.takeWhile(_ == '1').length\n if (ones == 1)\n \"1\" * (str.length - 2) + \"0\"\n else\n \"1\" * (ones - 1) + \"0\" + \"1\" * (str.length - ones)\n }\n }\n\n def count(aSize: Int, aZeroPosition: Int, bSize: Int, bZeroPosition: Int): Int = {\n if (aSize > bSize || (aZeroPosition > bZeroPosition && aSize == bSize)) 0\n else if (aSize == bSize && aZeroPosition == bZeroPosition) 1\n else if (aZeroPosition == aSize) count(aSize + 1, 1, bSize, bZeroPosition)\n else 1 + count(aSize, aZeroPosition + 1, bSize, bZeroPosition)\n }\n\n val in = Source.stdin.getLines()\n val Array(a, b) = in.next().split(' ').map(_.toLong)\n val c = ceil(a)\n val f = floor(b)\n println(count(c.length, c.indexOf('0'), f.length, f.indexOf('0')))\n}"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n\n def ceil(a: Long): String = {\n val str = a.toBinaryString\n val zeroCount = str.count(_ == '0')\n if (zeroCount == 1) str\n else if (zeroCount == 0) str + '0'\n else {\n val ones = str.takeWhile(_ == '1').length\n \"1\" * ones + \"0\" + \"1\" * (str.length - ones - 1)\n }\n }\n\n def floor(a: Long): String = {\n val str = a.toBinaryString\n val zeroCount = str.count(_ == '0')\n if (zeroCount == 1) str\n else if (zeroCount == 0) str.dropRight(1) + '0'\n else {\n val ones = str.takeWhile(_ == '1').length\n if (ones == 1)\n \"1\" * (str.length - 2) + \"0\"\n else\n \"1\" * (ones - 1) + \"0\" + \"1\" * (str.length - ones)\n }\n }\n\n def count(aSize: Int, aZeroPosition: Int, bSize: Int, bZeroPosition: Int): Int = {\n if (aSize > bSize || (aZeroPosition < bZeroPosition && aSize == bSize)) 0\n else if (aSize == bSize && aZeroPosition == bZeroPosition) 1\n else if (aZeroPosition == aSize) count(aSize + 1, 1, bSize, bZeroPosition)\n else 1 + count(aSize, aZeroPosition + 1, bSize, bZeroPosition)\n }\n\n val in = Source.stdin.getLines()\n val Array(a, b) = in.next().split(' ').map(_.toLong)\n val c = ceil(a)\n val f = floor(b)\n println(count(c.length, c.indexOf('0'), f.length, f.indexOf('0')))\n}"}], "src_uid": "581f61b1f50313bf4c75833cefd4d022"} {"nl": {"description": "In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.After practice competition, participant number i got a score of ai. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.", "input_spec": "The single line contains six integers a1, ..., a6 (0 ≤ ai ≤ 1000) — scores of the participants", "output_spec": "Print \"YES\" (quotes for clarity), if it is possible to build teams with equal score, and \"NO\" otherwise. You can print each character either upper- or lowercase (\"YeS\" and \"yes\" are valid when the answer is \"YES\").", "sample_inputs": ["1 3 2 1 2 1", "1 1 1 1 1 99"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.In the second sample, score of participant number 6 is too high: his team score will be definitely greater."}, "positive_code": [{"source_code": "import java.io._\nimport java.util.Scanner\nimport scala.language.implicitConversions\n\nobject AcmICPC {\n\n class Lazy[A](x: => A) {\n lazy val value = x\n override def toString(): String = value.toString()\n }\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\n import Lazy._\n\n def main(args: Array[String]): Unit = {\n val sc = new Scanner(System.in)\n\n val A = sc.nextLine().split(\" \").map(str => str.toInt)\n val sum = A.sum\n val answer = A.combinations(3).exists(combination => combination.sum * 2 == sum)\n\n println(if(answer) \"YES\" else \"NO\")\n\n }\n}"}, {"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 as = readInts(6)\n\n var can = false\n for (bs <- as.permutations) {\n if (bs.take(3).sum == bs.drop(3).sum) can = true\n }\n\n println(if (can) \"YES\" else \"NO\")\n\n Console.flush\n}\n"}, {"source_code": "/**\n * @see http://codeforces.com/contest/890/problem/A\n */\n\nobject AACM extends App {\n val a = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n val s = a sum\n val n = 6\n\n val vs = for {\n i <- 0 to 5\n j <- i to 5\n k <- j to 5\n if i != j && j != k && i != k && s - a(i) - a(j) - a(k) == a(i) + a(j) + a(k)\n } yield (i, j, k)\n\n if (vs.isEmpty) println(\"NO\")\n else println(\"YES\")\n}\n"}], "negative_code": [{"source_code": "import scala.annotation.tailrec\n\nobject A extends App {\n val a = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n val n = 6\n val s = a.sum\n\n @tailrec\n def check(i: Int = 0, j: Int = 0, k: Int = 0): Boolean =\n if (i == n || j == n || k == n) false\n else if (s - a(i) - a(j) - a(k) == a(i) + a(j) + a(k)) true\n else check(i + (j + (k + 1) / n) / n, (j + (k + 1) / n) % n, (k + 1) % n)\n\n if (check()) println(\"YES\")\n else println(\"NO\")\n}\n"}], "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11"} {"nl": {"description": "Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for her studies, and she wants to close all the tabs that don't belong to this segment as fast as possible.Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab i, then she can move it to the tab max(i - 1, a) or to the tab min(i + 1, b)) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab i, she can close all the tabs with indices from segment [a, i - 1] or from segment [i + 1, b]). In the aforementioned expressions a and b denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 7 tabs initially and tabs 1, 2 and 7 are closed, then a = 3, b = 6.What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from l to r inclusive opened?", "input_spec": "The only line of input contains four integer numbers n, pos, l, r (1 ≤ n ≤ 100, 1 ≤ pos ≤ n, 1 ≤ l ≤ r ≤ n) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened.", "output_spec": "Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [l, r].", "sample_inputs": ["6 3 2 4", "6 3 1 3", "5 2 1 5"], "sample_outputs": ["5", "1", "0"], "notes": "NoteIn the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it.In the second test she only needs to close all the tabs to the right of the current position of the cursor.In the third test Luba doesn't need to do anything."}, "positive_code": [{"source_code": "\nobject B extends App {\n val Array(n, pos, l, r) = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n\n def seconds(i: Int, a: Int, b: Int, t: Int = 0): Int =\n if (a == l && b == r) t\n else if (a == l) seconds(r, a, r, t + (r - i).abs + 1)\n else if (b == r) seconds(l, l, b, t + (i - l).abs + 1)\n else {\n if (i <= l) seconds(l, l, b, t + l - i + 1)\n else if (i >= r) seconds(r, a, r, t + i - r + 1)\n else {\n if (r - i < i - l) seconds(r, a, b, t + r - i)\n else seconds(l, a, b, t + i - l)\n }\n }\n\n println(seconds(pos, 1, n))\n}\n"}, {"source_code": "object CF915B extends App{\n val sc = new java.util.Scanner(System.in)\n val n, pos, l, r = sc.nextInt\n val move = if (l == 1) {\n if (r == n) 0 else (r-pos abs) + 1\n } else {\n if (r == n) (pos-l abs) + 1 else ((pos-l min r-pos) abs) + (r - l) + 2\n }\n println(move)\n}"}, {"source_code": "object CF915B extends App{\n val sc = new java.util.Scanner(System.in)\n val n, pos, l, r = sc.nextInt\n val move = if (l == 1) {\n if (r == n) 0 else (r-pos abs) + 1\n } else {\n if (r == n) (pos-l abs) + 1 else ((pos-l min r-pos) abs) + (r - l) + 2\n }\n println(move)\n}\n"}], "negative_code": [{"source_code": "\nobject B extends App {\n val Array(n, pos, l, r) = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n\n def seconds(i: Int, a: Int, b: Int, t: Int = 0): Int =\n if (a == l && b == r) t\n else if (a == l) seconds(r, a, r, t + r - i + 1)\n else if (b == r) seconds(l, l, b, t + i - l + 1)\n else {\n if (i <= l) seconds(l, l, b, t + l - i + 1)\n else if (i >= r) seconds(r, a, r, t + i - r + 1)\n else {\n if (r - i < i - l) seconds(r, a, b, t + r - i)\n else seconds(l, a, b, t + i - l)\n }\n }\n\n println(seconds(pos, 1, n))\n}\n"}, {"source_code": "object CF915B extends App{\n val sc = new java.util.Scanner(System.in)\n val n, pos, l, r = sc.nextInt\n val move = if (l == 1) {\n if (r == n) 0 else r-pos + 1\n } else {\n if (r == n) pos-l + 1 else (pos-l min r-pos) + (r - l) + 2\n }\n println(move)\n}"}], "src_uid": "5deaac7bd3afedee9b10e61997940f78"} {"nl": {"description": "There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor.The game is played on a square field consisting of n × n cells. Initially all cells are empty. On each turn a player chooses and paint an empty cell that has no common sides with previously painted cells. Adjacent corner of painted cells is allowed. On the next turn another player does the same, then the first one and so on. The player with no cells to paint on his turn loses.The professor have chosen the field size n and allowed the student to choose to be the first or the second player in the game. What should the student choose to win the game? Both players play optimally.", "input_spec": "The only line of the input contains one integer n (1 ≤ n ≤ 1018) — the size of the field.", "output_spec": "Output number 1, if the player making the first turn wins when both players play optimally, otherwise print number 2.", "sample_inputs": ["1", "2"], "sample_outputs": ["1", "2"], "notes": null}, "positive_code": [{"source_code": "\n/**\n * Created by octavian on 18/02/2016.\n */\nobject Game {\n\n def main(args: Array[String]) {\n // System.setIn(new FileInputStream(\"src/game.in\"))\n //System.setOut(new PrintStream(new FileOutputStream(\"src/game.out\")))\n\n var n = readLong()\n if(n % 2 == 0) {\n println(2)\n }\n else {\n println(1)\n }\n\n }\n\n}\n"}, {"source_code": "import java.util.Scanner\n\nimport scala.collection.mutable.ArrayBuffer\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 n = in.nextLong()\n\n println((n + 1) % 2 + 1)\n }\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n println(2 - in.next().last.asDigit % 2)\n}"}, {"source_code": "import scala.io.StdIn\n\nobject Game {\n\n def main(args: Array[String]) {\n val n = StdIn.readLong()\n print(2 - (n % 2))\n }\n \n}\n"}], "negative_code": [], "src_uid": "816ec4cd9736f3113333ef05405b8e81"} {"nl": {"description": "Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see \"her\" in the real world and found out \"she\" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.", "input_spec": "The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.", "output_spec": "If it is a female by our hero's method, print \"CHAT WITH HER!\" (without the quotes), otherwise, print \"IGNORE HIM!\" (without the quotes).", "sample_inputs": ["wjmzbmr", "xiaodao", "sevenkplus"], "sample_outputs": ["CHAT WITH HER!", "IGNORE HIM!", "CHAT WITH HER!"], "notes": "NoteFor the first example. There are 6 distinct characters in \"wjmzbmr\". These characters are: \"w\", \"j\", \"m\", \"z\", \"b\", \"r\". So wjmzbmr is a female and you should print \"CHAT WITH HER!\"."}, "positive_code": [{"source_code": "object Main {\n def main(args: Array[String]): Unit = {\n val str = readLine()\n if (str.distinct.length % 2 == 0) println(\"CHAT WITH HER!\") else println(\"IGNORE HIM!\")\n }\n}"}, {"source_code": "object Two36A extends App {\n\tval str = readLine\n\tval a = 'a'\n\tval arr = new Array[Int](26)\n\tstr.foreach { x =>\n\t\tarr(x - a) += 1\n\t}\n\tval size = arr.filter(_ > 0).size\n\tif (size % 2 != 0) {\n\t\tprintln(\"IGNORE HIM!\")\n\t} else {\n\t\tprintln(\"CHAT WITH HER!\")\n\t}\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject BoyorGirl {\n def main(args: Array[String]): Unit = {\n val name = readLine().toSet\n val ans = if (name.size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\"\n println(ans)\n }\n}"}, {"source_code": "object Main extends App{\n if(readLine.distinct.size %2==0)\n println(\"CHAT WITH HER!\")else\n println(\"IGNORE HIM!\")\n}"}, {"source_code": "object BoyGirl extends App {\n\n\tval uniqueCharacters = \n\t\tscala.io.StdIn.readLine()\n\t\t.toSet.size\n\n\tif (uniqueCharacters % 2 != 0) println(\"IGNORE HIM!\")\n\t\telse println(\"CHAT WITH HER!\")\n\n}"}, {"source_code": "object Main extends App {\n val str = readLine()\n\n val r = str.toLowerCase().groupBy(_.toChar).map { case (k, v) => (k, v.size) }\n\n if (r.size % 2 == 0) println(\"CHAT WITH HER!\")\n else println(\"IGNORE HIM!\")\n}\n"}, {"source_code": "object Task236A {\n def main(args: Array[String]): Unit = {\n println(if (scala.io.StdIn.readLine().foldLeft(Set[Char]())((x, y) => x + y).size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n }\n}"}, {"source_code": "object CF0236A extends App {\n\n var str = readLine().toList\n\n val size = str.toSet.size\n\n if(size % 2 == 0) {\n println(\"CHAT WITH HER!\")\n } else {\n println(\"IGNORE HIM!\")\n }\n}\n"}, {"source_code": "object Solution236A extends App {\n\n val ans = Map(0 -> \"CHAT WITH HER!\", 1 -> \"IGNORE HIM!\")\n\n def solution() {\n println(ans(_string.groupBy(c => c).size % 2))\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}"}, {"source_code": "import scala.io.StdIn\n\nobject BoyAndGirlMain {\n def main(args: Array[String]): Unit = {\n val userName = StdIn.readLine().toArray\n val lol = userName.groupBy(_.charValue())\n\n if (lol.size % 2 == 0 )\n print (\"CHAT WITH HER!\")\n else print(\"IGNORE HIM!\")\n }\n\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject Main {\n def main(args: Array[String]): Unit = {\n val s = readLine\n if (s.toSeq.distinct.size % 2 == 0) println(\"CHAT WITH HER!\") else println(\"IGNORE HIM!\")\n }\n}\n"}, {"source_code": "object Solution extends App {\n if (readLine().distinct.size % 2 == 0)\n println(\"CHAT WITH HER!\")\n else\n println(\"IGNORE HIM!\")\n}"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val std = scala.io.StdIn\n val userName = std.readLine()\n val result = if (userName.distinct.length % 2 == 0) {\n \"CHAT WITH HER!\"\n }\n else {\n \"IGNORE HIM!\"\n }\n println(result)\n }\n}"}, {"source_code": "import scala.io.StdIn\n\nobject BoyOrGirl extends App {\n\n val name = StdIn.readLine()\n\n if (impl(name))\n print(\"CHAT WITH HER!\")\n else\n print(\"IGNORE HIM!\")\n\n def impl(name: String): Boolean = {\n name.distinct.length % 2 == 0\n }\n\n}\n"}, {"source_code": "import scala.io.StdIn.readLine\nobject BoyOrGirl extends App\n{\n val input = readLine()\n val sort = input.distinct.length\n if(sort % 2 == 0)\n {\n println(\"CHAT WITH HER!\")\n } else println(\"IGNORE HIM!\")\n}"}, {"source_code": "object a{def main(args:Array[String]){if(readLine.distinct.size%2==0)print(\"CHAT WITH HER!\")else print(\"IGNORE HIM!\")}}"}, {"source_code": "//2.12 | CodeForces.Com\nobject Solution {\n def main(args: Array[String]) {\n if(readLine.distinct.size % 2 == 0)\n print(\"CHAT WITH HER!\")\n else\n print(\"IGNORE HIM!\")\n }\n}"}, {"source_code": "//rextester.com:2.11.7--codeforces.com:2.11.8\nobject a extends App{\n if(readLine.distinct.size%2==0)print(\"CHAT WITH HER!\")else print(\"IGNORE HIM!\")\n}"}, {"source_code": "/**\n * Created by richard on 2015/6/10.\n */\nimport scala.io.StdIn\nobject cf236a {\n def main(args: Array[String]): Unit = {\n val name = StdIn.readLine()\n println(if (name.distinct.size%2==1) \"IGNORE HIM!\" else \"CHAT WITH HER!\")\n }\n}\n"}, {"source_code": "object I {\n \n def main(args : Array[String]): Unit = {\n var s = readLine\n var used=false\n var cnt = 1\n for (i <- 1 to s.length()-1; j <- i-1 to 0 by -1){\n \tif (s.charAt(i)==s.charAt(j))used = true\n \tif (j==0){\n \t if (!used)cnt += 1\n \t used = false \t \n \t}\n }\n// println(cnt)\n if (cnt % 2 == 0)\n println(\"CHAT WITH HER!\")\n else println(\"IGNORE HIM!\")\n }\n\n}"}, {"source_code": "object A236 extends App {\n var name: String = readLine\n var count = 0;\n while (!name.isEmpty()) {\n name = name.filterNot((a: Char) => a == name.charAt(0))\n count += 1;\n }\n if (count % 2 == 0)\n println(\"CHAT WITH HER!\")\n else println(\"IGNORE HIM!\")\n}"}, {"source_code": "object Main {\n def main(args: Array[String]): Unit = {\n val s = readLine\n if (s.toList.distinct.length % 2 == 0) {\n println(\"CHAT WITH HER!\")\n } else {\n println(\"IGNORE HIM!\")\n }\n }\n}\n"}, {"source_code": "\nobject Main extends App {\n val sc = new java.util.Scanner(System.in)\n val name = sc.next()\n\n println(if (name.toSet.size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}\n"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P236A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val name = sc.nextLine\n\n def solve: String =\n if (name.groupBy(identity[Char]).size % 2 == 0) \"CHAT WITH HER!\"\n else \"IGNORE HIM!\"\n\n out.println(solve)\n out.close\n}\n"}, {"source_code": "\n\nobject BoyOrGirl {\n\tdef main (args: Array[String]) {\n\t\tval scanner = new java.util.Scanner(System.in);\n\t\tval input = scanner.nextLine;\n\t\tvar theList: List[Char] = Nil\n\t\tfor (c <- input) {\n\t\t if (!theList.contains(c)) {\n\t\t theList = c::theList;\n\t\t }\n\t\t}\n\t\tif (theList.size % 2 == 0) {\n\t\t println(\"CHAT WITH HER!\")\n\t\t}\n\t\telse {\n\t\t println(\"IGNORE HIM!\")\n\t\t}\n\t}\n}"}, {"source_code": "object A {\n def main(args: Array[String]) {\n val input = readLine()\n val chars = input.iterator.toSet\n print(\n if ((chars.iterator.length % 2) == 0)\n \"CHAT WITH HER!\"\n else\n \"IGNORE HIM!\")\n }\n\n}\n"}, {"source_code": "// codeforces 236A\n\nobject DevYun extends App {\n val nm = Console.readLine()\n val sch: Set[Char] = nm toSet\n val devush = (sch.size % 2) == 0\n val answer = if (devush) \"CHAT WITH HER!\" else \"IGNORE HIM!\"\n println(answer)\n}"}, {"source_code": "import java.util.Scanner\n\nobject Try1 {\n def main(args: Array[String]) {\n val in = new Scanner(System.in)\n var a,b,len,x, m, k, n, j, i: Int = 0\n\n// val lb = \"abcdefghijklmnopqrstuvwxyz\"\n// val lc = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n var v = new Array[Int](26)\n i=0\n while (i<26){\n v(i)=0\n i+=1\n }\n// n = in.nextInt()\n// k = in.nextInt()\n// x=0\n val la = in.nextLine()\n a=0\n b=0\n m = la.length()\n i=0\n while (i=b)\n// {\n// i=0\n// while (i='a' && la(i)<='z') print(la(i))\n// else print(lb(la(i)-'A'))\n// i+=1\n// }\n// }\n// else\n// {\n// i=0\n// while (i='a' && la(i)<='z') print(lc(la(i)-'a'))\n// else print(la(i))\n// i+=1\n// }\n// }\n// m = la.compareToIgnoreCase(lb) //不区分大小写判断字符串是否相等\n\n\n// i=0\n// n=line.length()\n// while (i2 && line(n-3)=='W' && line(n-2)=='U' && line(n-1)=='B') n-=3\n// while (i x).size % 2)\n\n def main(a: Array[String]) {\n println(ans)\n }\n}\n"}, {"source_code": "object test5 extends App {\n val name=readLine\n if(name.distinct.size%2==0)\n \tprintln(\"CHAT WITH HER!\")\n else\n \tprintln(\"IGNORE HIM!\")\n \n} \n\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val s = readLine().toSet\n if (s.size % 2 == 0) println(\"CHAT WITH HER!\")\n else println(\"IGNORE HIM!\")\n }\n}"}, {"source_code": "// Codeforces 236A\n\nobject _236A extends App {\n val scanner = new java.util.Scanner(System.in)\n val user_name = scanner.next\n println(\n if (user_name.distinct.size % 2 == 0) \"CHAT WITH HER!\"\n else \"IGNORE HIM!\"\n )\n}\n\n"}, {"source_code": "import scala.io.StdIn._\n\nobject A_236 extends App {\n println(if (readLine().toCharArray.toSet.size % 2 == 1) \"IGNORE HIM!\" else \"CHAT WITH HER!\")\n}\n"}, {"source_code": "import scala.io.StdIn.readLine\nobject problem {\n def main(args: Array[String]) {\n val s = readLine\n println(if(s.distinct.size%2 ==0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n }\n}"}, {"source_code": "object JuanDavidRobles236A {\n\n def main(args: Array[String]): Unit = {\n\n import scala.io.StdIn\n import java.util\n\n var string: String = StdIn.readLine()\n var words: Array[Char] = new Array[Char](30)\n var count: Int = 0\n\n for (i <- 0 until string.length){\n if (!arrayContains(words, string.charAt(i))){\n words(count) = string.charAt(i)\n count += 1\n }\n }\n\n if (count%2 == 0){\n println(\"CHAT WITH HER!\")\n } else {\n println(\"IGNORE HIM!\")\n }\n\n }\n\n def arrayContains(myString: Array[Char], char: Char): Boolean ={\n var boolean: Boolean = false\n for (i <- 0 until myString.length){\n\n if (myString.charAt(i) == char){\n boolean = true\n }\n }\n\n boolean\n }\n}"}, {"source_code": "\nimport scala.io.StdIn.readLine\n\nobject BoyOrGirl {\n def main(args: Array[String]) { \n if (readLine.toSet.size % 2 == 0)\n println(\"CHAT WITH HER!\")\n else \n println(\"IGNORE HIM!\")\n }\n \n}"}, {"source_code": "object Main extends App{\n if(readLine.distinct.size %2==0)\n println(\"CHAT WITH HER!\")else\n println(\"IGNORE HIM!\")\n}"}, {"source_code": "import scala.collection.immutable.Set\nobject TEST extends App{\n var al = Set[Char]()\n readLine.foreach(i => al += i)\n print (if(al.size%2==0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}"}, {"source_code": "object Main {\n\n def distinct(x: List[Char]): List[Char] = {\n x.foldLeft(List.empty[Char])((acc, c) => if (acc.contains(c)) acc else c :: acc)\n }\n \n def gender(nick: String): String = {\n val chars = distinct(nick.toList)\n if (chars.size % 2 == 0) \"CHAT WITH HER!\"\n else \"IGNORE HIM!\"\n }\n \n def main(args: Array[String]) = {\n print (gender(readLine))\n }\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject Task extends App{\n\tval name = readLine.toSet\n\t\n\tif(name.size % 2 == 0)\n\t println(\"CHAT WITH HER!\")\n\telse\n\t println(\"IGNORE HIM!\")\n}"}, {"source_code": "object A00236 extends App {\n val str = Console.readLine()\n val message = if (str.distinct.length % 2 == 1) \"IGNORE HIM!\" else \"CHAT WITH HER!\"\n println(message)\n}\n"}], "negative_code": [{"source_code": "object Main {\n def main(args: Array[String]): Unit = {\n val str = readLine()\n println(str.distinct.length)\n }\n}"}, {"source_code": "object BoyGirl extends App {\n\n\tval uniqueCharacters = \n\t\tscala.io.StdIn.readLine()\n\t\t.toSet.size\n\n\tif (uniqueCharacters % 2 == 0) println(\"IGNORE HIM!\")\n\t\telse println(\"CHAT WITH HER!\")\n\n}"}, {"source_code": "object Main extends App {\n val str = readLine()\n\n val r = str.toLowerCase().groupBy(_.toChar).map { case (k, v) => (k, v.size) }.\n filter { case (k, v) => v == 1 }.filterNot { case (k, v) => k == ' ' }.size\n\n if (r % 2 == 0) println(\"IGNORE HIM!\")\n else println(\"CHAT WITH HER!\")\n}"}, {"source_code": "import scala.io.StdIn\n\nobject BoyAndGirlMain {\n def main(args: Array[String]): Unit = {\n val userName = StdIn.readLine().toArray\n val lol = userName.groupBy(_.charValue())\n\n println(lol .size)\n if (lol.size % 2 == 0 )\n print (\"CHAT WITH HER!\")\n else print(\"IGNORE HIM!\")\n }\n\n}\n"}, {"source_code": "/**\n * Created by richard on 2015/6/10.\n */\nimport scala.io.StdIn\nobject cf236a {\n def main(args: Array[String]): Unit = {\n val name = StdIn.readLine()\n println(if (name.size%2==1) \"IGNORE HIM!\" else \"CHAT WITH HER!\")\n }\n}\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val s = readLine().toSet\n println(s)\n if (s.size % 2 == 0) println(\"CHAT WITH HER!\")\n else println(\"IGNORE HIM!\")\n }\n}"}, {"source_code": "// Codeforces 236A\n\nobject _236A extends App {\n val scanner = new java.util.Scanner(System.in)\n val user_name = scanner.next\n println(\n if (user_name.distinct.size % 2 == 0) \"CHAT WITH HER\"\n else \"IGNORE HIM\"\n )\n}\n\n"}, {"source_code": "object JuanDavidRobles236A {\n def main(args: Array[String]): Unit = {\n\n import scala.io.StdIn\n\n var string: String = StdIn.readLine()\n var words: Array[Char] = new Array[Char](30)\n\n var count: Int = 0\n\n for (i <- 0 until string.length; j <- 0 until words.length()){\n\n if (words(j).equals(string.charAt(i))){\n words(count) = string.charAt(i)\n count = count + 1\n }\n }\n\n if (count%2 == 0){\n println(\"CHAT WITH HER!\")\n } else {\n println(\"IGNORE HIM!\")\n }\n\n }\n}"}], "src_uid": "a8c14667b94b40da087501fd4bdd7818"} {"nl": {"description": "You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences. Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?", "input_spec": "The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a. The second line contains n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100) — the elements of sequence a.", "output_spec": "Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.", "sample_inputs": ["3\n1 -2 0", "6\n16 23 16 15 42 8"], "sample_outputs": ["3", "120"], "notes": "NoteIn the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C =  - 2, B - C = 3.In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120."}, "positive_code": [{"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 val xs = readInts(n)\n val sum = xs.sum\n var max = Int.MinValue\n\n for (d <- -101 to 101) {\n max = Math.max(max, Math.abs(xs.filter(_ <= d).sum - xs.filter(_ > d).sum))\n }\n\n println(max)\n\n Console.flush\n}\n"}, {"source_code": "object APartition extends App {\n val n = scala.io.StdIn.readInt()\n val a = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n\n val t = a.foldLeft(0)(_ + _.abs)\n\n println(t)\n}\n"}, {"source_code": "object A extends App {\n val n = scala.io.StdIn.readInt()\n val a = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n val t = a.foldLeft((0, 0))((t, i) => {\n if (i < 0 ) (t._1, t._2 + i)\n else if (i > 0) (t._1 + i, t._2)\n else t\n })\n\n println(t._1 - t._2)\n}\n"}, {"source_code": "object _946A extends CodeForcesApp {\n import Utils._, annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._, Math._\n\n override def apply(io: IO): io.type = {\n val a = io.read[Seq[Int]]\n val (b, c) = a.partition(_ > 0)\n io.write(b.sum - c.sum)\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 isPrime(n: Int): Boolean = BigInt(n).isProbablePrime(31)\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"}, {"source_code": "object CF946A extends App {\n import scala.io.StdIn._\n readLine()\n\n val nums: List[Int] = readLine().split(\" \").map(Integer.parseInt(_)).toList\n\n val (pos, neg) = nums.partition(_ > 0)\n\n val res = pos.sum - neg.sum\n\n println(res)\n\n}\n"}], "negative_code": [{"source_code": "object A extends App {\n val n = scala.io.StdIn.readInt()\n val a = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n\n val t = a.reduce(_.abs + _.abs)\n\n println(t)\n}\n"}], "src_uid": "4b5d14833f9b51bfd336cc0e661243a5"} {"nl": {"description": "Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from $$$1$$$ to $$$9$$$). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, $$$\\ldots$$$, 9m, 1p, 2p, $$$\\ldots$$$, 9p, 1s, 2s, $$$\\ldots$$$, 9s.In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.Do you know the minimum number of extra suited tiles she needs to draw so that she can win?Here are some useful definitions in this game: A mentsu, also known as meld, is formed by a koutsu or a shuntsu; A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu. Some examples: [2m, 3p, 2s, 4m, 1s, 2s, 4s] — it contains no koutsu or shuntsu, so it includes no mentsu; [4s, 3m, 3p, 4s, 5p, 4s, 5p] — it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] — it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu. Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.", "input_spec": "The only line contains three strings — the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from $$$1$$$ to $$$9$$$ and the second character is m, p or s.", "output_spec": "Print a single integer — the minimum number of extra suited tiles she needs to draw.", "sample_inputs": ["1s 2s 3s", "9m 9m 9m", "3p 9m 2p"], "sample_outputs": ["0", "0", "1"], "notes": "NoteIn the first example, Tokitsukaze already has a shuntsu.In the second example, Tokitsukaze already has a koutsu.In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile — 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p]."}, "positive_code": [{"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とか+7とかするならvalにしろ\n @inline private def MOD = 1000000007\n\n def solve(): Unit = {\n val A = map(3)(_ => ns())\n val C = Array.ofDim[Int](3, 9)\n A.foreach { s =>\n val c = s.last match {\n case 's' => 0\n case 'm' => 1\n case 'p' => 2\n }\n val n = s.head - '1'\n C(c)(n) += 1\n }\n var ans = 3\n // koutsu\n REP(3) { i =>\n REP(9) { j =>\n ans = min(ans, 3 - C(i)(j))\n }\n }\n\n // shuntsu\n REP(3) { i =>\n REP(7) { j =>\n var c = 0\n if (C(i)(j) > 0) c += 1\n if (C(i)(j + 1) > 0) c += 1\n if (C(i)(j + 2) > 0) c += 1\n ans = min(ans, 3 - c)\n }\n }\n\n out.println(ans)\n }\n}"}], "negative_code": [], "src_uid": "7e42cebc670e76ace967e01021f752d3"} {"nl": {"description": "A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.The next prime number after x is the smallest prime number greater than x. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly x Roman soldiers, where x is a prime number, and next day they beat exactly y Roman soldiers, where y is the next prime number after x, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.Yesterday the Gauls beat n Roman soldiers and it turned out that the number n was prime! Today their victims were a troop of m Romans (m > n). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?", "input_spec": "The first and only input line contains two positive integers — n and m (2 ≤ n < m ≤ 50). It is guaranteed that n is prime. Pretests contain all the cases with restrictions 2 ≤ n < m ≤ 4.", "output_spec": "Print YES, if m is the next prime number after n, or NO otherwise.", "sample_inputs": ["3 5", "7 11", "7 9"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "positive_code": [{"source_code": "object Flask {\n \n def isPrime(n: Int): Boolean = List.range(2, n / 2 + 1).forall(n % _ != 0)\n\n def main(args: Array[String]): Unit = {\n var input = Console.readLine.split(\" \").map(_.toInt)\n var n = input(0); var m = input(1)\n var result = isPrime(m) && List.range(n + 1, m).forall(x => !isPrime(x))\n println(if (result) \"YES\" else \"NO\")\n }\n}"}, {"source_code": "import scala.io.Source\n\nobject a11 {\n def main(args: Array[String]): Unit = {\n val a = Seq.iterate((List[Int](),(2 to 50).toArray),5)(a=>(((a._2.head)::a._1), a._2.filter(b => b % (a._2.head) != 0))).last\n val primes = a._1.reverse.toArray ++ a._2\n val line = Source.stdin.getLines().take(1).map(_.split(' ').map(_.toInt)).toArray.head\n val (b,c) = (line(0), line(1))\n println(if (!primes.contains(c) || primes(primes.indexOf(b)+1) != c)\n \"NO\"\n else\n \"YES\")\n }\n}"}, {"source_code": "object Solution extends App {\n def simple(a: Int) =\n a % 2 != 0 && (3 to Math.sqrt(a).toInt by 2).forall(a % _ != 0) || a == 2\n\n val in = scala.io.Source.stdin.getLines()\n val Array(n, m) = in.next().split(\" \").map(_.toInt)\n if (simple(m) && (n + 1 until m).forall(t => !simple(t)))\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "object A80 {\n\n import IO._\n import collection.{mutable => cu}\n\n def main(args: Array[String]): Unit = {\n val Array(n, m) = readInts(2)\n val primes = genPrimes(100)\n if(primes.contains(n) && primes.contains(m)) {\n val nPos = primes.indexOf(n)\n val mPos = primes.indexOf(m)\n if(mPos == nPos+1) {\n out.println(\"YES\")\n } else {\n out.println(\"NO\")\n }\n } else {\n out.println(\"NO\")\n }\n out.close()\n }\n\n def genPrimes(till: Int): Array[Int] = {\n val isPrime = Array.fill[Boolean](till+1)(true)\n isPrime(0) = false\n isPrime(1) = true // not composite\n for(i <- 4 to till by 2) {\n isPrime(i) = false\n }\n for(i <- 3 to till by 2 if isPrime(i)) {\n for(j <- i+i to till by i) isPrime(j) = false\n }\n isPrime.zipWithIndex.filter(_._1).map(_._2)\n }\n\n object IO {\n private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n // private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(\"src/input\")))\n val out = new java.io.PrintWriter(System.out)\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"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P80A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n def nextPrime(n: Int): Int = {\n def isPrime(x: Int): Boolean = (2 until x).forall(x % _ > 0)\n\n @tailrec\n def loop(i: Int): Int =\n if (isPrime(i)) i\n else loop(i + 1)\n\n loop(n + 1)\n }\n\n val N, M = sc.nextInt\n val answer = if (M == nextPrime(N)) \"YES\" else \"NO\"\n\n out.println(answer)\n out.close\n}\n"}, {"source_code": "object APanoramixsPrediction extends App {\n import scala.io.StdIn._\n\n lazy val primes: Stream[Int] =\n 2 #:: Stream.iterate(3)(_ + 2).filter(isPrime)\n\n def isPrime(number: Int): Boolean =\n primes.takeWhile(prime => prime * prime <= number).forall(number % _ != 0)\n\n val Array(n, m) = readLine().split(\" \").map(_.toInt)\n\n val ans = isPrime(m) && primes.indexOf(n) + 1 == primes.indexOf(m) match {\n case true => \"YES\"\n case _ => \"NO\"\n }\n\n println(ans)\n}\n"}, {"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 def sqStream(current: Int, ceil: Int): Stream[Int] = if(current * current > ceil) Stream.Empty else current #:: sqStream(current + 1, ceil)\n def isPrime(x: Int) = sqStream(2, x).filter(x % _ == 0).isEmpty\n @tailrec\n def nextPrime(n: Int): Int = if(isPrime(n)) n else nextPrime(n + 1)\n val Array(m, n) = readInts\n def ans = nextPrime(m + 1) == n\n val yesNoAns = Map(true -> \"YES\", false -> \"NO\")\n\n def main(a: Array[String]) {\n println(yesNoAns(ans))\n }\n}\n"}, {"source_code": "object Main {\n def sieve(n: Int) = {\n val primes = scala.collection.mutable.BitSet.empty ++ (2 to n)\n for {\n candidate <- 2 until Math.sqrt(n).ceil.toInt\n if primes contains candidate\n } primes --= candidate * candidate to n by candidate\n primes \n } \n \n val primes = sieve(51).zipWithIndex\n\n def main(args: Array[String]) {\n val nm = readLine().split(\" \").map(_.toInt)\n val n = nm(0)\n val m = nm(1)\n val i = primes.find(_._1 == n).get._2\n val j = primes.find(_._1 == m).map(_._2)\n if (j.map(_ - i).getOrElse(0) == 1) println(\"YES\")\n else println(\"NO\")\n }\n}"}, {"source_code": "object Panoramix extends App {\n\n val Array(n, m) = readLine.split(' ').map(_.toInt)\n\n val primes: Array[Int] = Array(\n 2, 3, 5, 7, 11, 13,\n 17, 19, 23, 29, 31,\n 37, 41, 43, 47\n )\n\n val result: Boolean = \n primes.contains(n) && primes.contains(m) &&\n primes.indexOf(m) - primes.indexOf(n) == 1\n println(if (result) \"YES\" else \"NO\")\n\n}\n"}], "negative_code": [{"source_code": "object Solution extends App {\n def simple(a: Int) = {\n a % 2 == 0 && (a == 2 || (3 to Math.sqrt(a).toInt).forall(a % _ != 0))\n }\n\n val in = scala.io.Source.stdin.getLines()\n val Array(n, m) = in.next().split(\" \").map(_.toInt)\n if (simple(m) && (n + 1 until m).forall(t => !simple(t)))\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "object Main {\n def sieve(n: Int) = {\n val primes = scala.collection.mutable.BitSet.empty ++ (2 to n)\n for {\n candidate <- 2 until Math.sqrt(n).toInt\n if primes contains candidate\n } primes --= candidate * candidate to n by candidate\n primes \n } \n \n val primes = sieve(50).zipWithIndex\n\n def main(args: Array[String]) {\n val nm = readLine().split(\" \").map(_.toInt)\n val n = nm(0)\n val m = nm(1)\n val i = primes.find(_._1 == n).get._2\n val j = primes.find(_._1 == m).map(_._2)\n if (j.map(_ - i).getOrElse(0) == 1) println(\"YES\")\n else println(\"NO\")\n }\n}"}, {"source_code": "object Main {\n def sieve(n: Int) = {\n val primes = scala.collection.mutable.BitSet.empty ++ (2 to n)\n for {\n candidate <- 2 until Math.sqrt(n).ceil.toInt\n if primes contains candidate\n } primes --= candidate * candidate to n by candidate\n primes \n } \n \n val primes = sieve(51).zipWithIndex\n\n def main(args: Array[String]) {\n val nm = readLine().split(\" \").map(_.toInt)\n val n = nm(0)\n val m = nm(1)\n val i = primes.find(_._1 == n).get._2\n val j = primes.find(_._1 == m).map(_._2)\n println(\"i = \" + i)\n println(\"j = \" + j)\n if (j.map(_ - i).getOrElse(0) == 1) println(\"YES\")\n else println(\"NO\")\n }\n}"}], "src_uid": "9d52ff51d747bb59aa463b6358258865"} {"nl": {"description": "n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.", "input_spec": "The only line of input contains two integers n and m, separated by a single space (1 ≤ m ≤ n ≤ 109) — the number of participants and the number of teams respectively. ", "output_spec": "The only line of the output should contain two integers kmin and kmax — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.", "sample_inputs": ["5 1", "3 2", "6 3"], "sample_outputs": ["10 10", "1 1", "3 6"], "notes": "NoteIn the first sample all the participants get into one team, so there will be exactly ten pairs of friends.In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people."}, "positive_code": [{"source_code": "import java.util.StringTokenizer\n\nobject _478B 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.toLong\n val m = next.toLong\n def choose(a: Long) = a * (a - 1) / 2\n val max = choose(n - (m - 1))\n val min = (m - n % m) * choose(n / m) + (n % m) * choose(n / m + 1)\n println(min + \" \" + max)\n}\n"}, {"source_code": "object Solution extends App {\n def f(n: Long) = n * (n - 1) / 2\n\n\n val in = scala.io.Source.stdin.getLines()\n val Array(n, m) = in.next().split(\" \").map(_.toLong)\n val c = n / m\n val min = (n % m) * f(c + 1) + (m - n % m) * f(c)\n val max = f(n - m + 1)\n println(min + \" \" + max)\n}"}, {"source_code": "object B478 {\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(n, m) = readLongs(2)\n val min = {\n val mod = n%m\n mod * ((n/m + 1) *(n/m)) /2 + (m-mod) * ((n/m) * (n/m -1 )) / 2\n }\n val max = ((n-m+1) * (n-m))/2\n println(s\"$min $max\")\n }\n}"}, {"source_code": "import java.util.Scanner\n\nobject R273_RandomTeams {\n def main(args: Array[String]) = {\n val in = new Scanner(System.in).nextLine().split(\" \").map(_.toInt)\n val (n, m) = (in(0), in(1))\n val (p, q) = (n / m, n % m)\n\n val min = combination2(p) * (m - q) + combination2(p + 1) * q\n val max = combination2(n - m + 1)\n println(min + \" \" + max)\n }\n\n def combination2(n: Long): Long = {\n (n * (n - 1)) / 2\n }\n}\n"}, {"source_code": "object P478B {\n\tdef edges(n: Int) : BigInt = ((BigInt(n) * n) - n) / 2\n\n\tdef main(args: Array[String]) {\n\t\tval Array(n, m) = scala.io.StdIn.readLine.split(\" \").map(_.toInt)\n\t\tval min = (n % m) * edges((n / m) + 1) + (m - (n % m)) * edges(n / m)\n\t\tval max = edges(n - m + 1)\n\t\tprintln(List(min, max).mkString(\" \"))\n\t}\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject Solution {\n def countPairs(n: Long): Long = n * (n - 1) / 2\n \n def main(args: Array[String]) = {\n\tval in = new Scanner(System.in)\n\tval people = in.nextLong()\n\tval teams = in.nextLong()\n\tval max = countPairs(people - teams + 1)\n\tval size = people / teams\n\tval bigCount = people - size * teams \n\tval smallCount = teams - bigCount\n\tval min = countPairs(size + 1) * bigCount + countPairs(size) * smallCount\n\tprintln(min + \" \" + max)\n }\n}"}, {"source_code": "import java.util.Scanner\n\nobject Main extends App {\n val in = (new Scanner(System.in)).nextLine().split(\" \").map(_.toInt)\n val n = in(0)\n val m = in(1)\n\n def nC2(n: Int): Long = {\n if(n == 1) 0\n else\n n.toLong * (n-1) / 2\n }\n\n val mi = n/m\n val mi2_count = if( mi*m != n ) n - mi*m else 0\n val mi_count = m - mi2_count\n val ans1 = (nC2(mi)*mi_count + nC2(mi+1)*mi2_count)\n\n val mx = n - (m-1)\n val ans2 = nC2(mx)\n\n println(ans1.toString + \" \" + ans2.toString)\n}\n"}], "negative_code": [{"source_code": "import java.util.StringTokenizer\n\nobject _478B 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.toLong\n val m = next.toLong\n def choose(a: Long) = a * (a - 1) / 2\n val max = choose(n - (m - 1))\n val min = {\n if (n % m == 0) m * choose(n / m)\n else (m - 1) * choose(n / m) + choose(n - n / m * (m - 1))\n }\n println(min + \" \" + max)\n}\n"}, {"source_code": "object Solution extends App {\n def f(n: Int) = n * (n - 1) / 2\n\n\n val in = scala.io.Source.stdin.getLines()\n val Array(n, m) = in.next().split(\" \").map(_.toInt)\n val c = n / m\n val min = (n % m) * f(c + 1) + (m - n % m) * f(c)\n val max = f(n - m + 1)\n println(max + \" \" + min)\n}"}, {"source_code": "object Solution extends App {\n def f(n: Int) = n * (n - 1) / 2\n\n val in = scala.io.Source.stdin.getLines()\n val Array(n, m) = in.next().split(\" \").map(_.toInt)\n val c = n / m\n val min = (n % m) * f(c + 1) + (m - n % m) * f(c)\n val max = f(n - m + 1)\n println(min + \" \" + max)\n}"}, {"source_code": "object Solution extends App {\n def f(n: Int) = n * (n + 1) / 2\n \n\n val in = scala.io.Source.stdin.getLines()\n val Array(n, m) = in.next().split(\" \").map(_.toInt)\n val c = n / m\n val min = (n % m) * f(c + 1) + (m - n % m) * f(c)\n val max = f(n - m)\n println(max + \" \" + min)\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject R273_RandomTeams {\n def main(args: Array[String]) = {\n val in = new Scanner(System.in).nextLine().split(\" \").map(_.toInt)\n val (n, m) = (in(0), in(1))\n val (p, q) = (n / m, n % m)\n\n val min = combination2(p) * (m - q) + (combination2(p) + 1) * q\n val max = combination2(n - m + 1)\n println(min + \" \" + max)\n }\n\n def combination2(n: Long): Long = {\n (n * (n - 1)) / 2\n }\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject R273_RandomTeams {\n def main(args: Array[String]) = {\n val in = new Scanner(System.in).nextLine().split(\" \").map(_.toInt)\n val n = in(0)\n val m = in(1)\n val p = n / m\n val q = n % m\n\n val min = combination2(p) * (m - q) + (combination2(p) + 1) * q\n val max = combination2(n - m + 1)\n println(min + \" \" + max)\n }\n\n def combination2(n: Int): Int = {\n (n / 2) * (n - 1)\n }\n\n def fact(n: Int): Int = {\n Range(1, n + 1).toList.product\n }\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject R273_RandomTeams {\n def main(args: Array[String]) = {\n val in = new Scanner(System.in).nextLine().split(\" \").map(_.toInt)\n val n = in(0)\n val m = in(1)\n val p = n / m\n val q = n % m\n\n val min = combination2(p) * (m - q) + (combination2(p) + 1) * q\n val max = combination2(n - m + 1)\n println(min + \" \" + max)\n }\n\n def combination2(n: Int): Int = {\n (n * (n - 1)) / 2\n }\n\n def fact(n: Int): Int = {\n Range(1, n + 1).toList.product\n }\n}\n"}, {"source_code": "object P478B {\n\tdef edges(n: Int) : BigInt = ((BigInt(n) * n) - n) / 2\n\n\tdef main(args: Array[String]) {\n\t\tval Array(n, m) = scala.io.StdIn.readLine.split(\" \").map(_.toInt)\n\t\tval min = (n % m) * edges((n / m) + 1) + (m - (n % m)) * edges(n / m)\n\t\tval max = edges(n - m + 1)\n\t\tprintln(min, max)\n\t}\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject Solution {\n def countPairs(n: Long): Long = n * (n - 1) / 2\n \n def main(args: Array[String]) = {\n\tval in = new Scanner(System.in)\n\tval people = in.nextLong()\n\tval teams = in.nextLong()\n\tval max = countPairs(people - teams + 1) + teams - 1\n\tval size = people / teams\n\tval bigCount = people - size * teams \n\tval smallCount = teams - bigCount\n\tval min = countPairs(size + 1) * bigCount + countPairs(size) * smallCount\n\tprintln(min + \" \" + max)\n }\n}"}, {"source_code": "import java.util.Scanner\n\nobject Main extends App {\n val in = (new Scanner(System.in)).nextLine().split(\" \").map(_.toInt)\n val n = in(0)\n val m = in(1)\n\n def nCm(n: Int, m: Int): Long = {\n if(n == 1) 0\n else {\n val nt = (1 to n).reverse.take(m).product\n val mt = (1 to m).reverse.product\n (nt / mt).toLong\n }\n }\n\n val mi = n/m\n val mi2_count = if( mi*m != n ) n - mi*m else 0\n val mi_count = m - mi2_count\n val ans1 = (nCm(mi,2)*mi_count + nCm(mi+1,2)*mi2_count)\n\n val mx = n - (m-1)\n val ans2 = nCm(mx,2)\n\n print(Math.min(ans1, ans2))\n print(\" \")\n println(Math.max(ans1, ans2))\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject Main extends App {\n val in = (new Scanner(System.in)).nextLine().split(\" \").map(_.toInt)\n val n = in(0)\n val m = in(1)\n\n def nCm(n: Int, m: Int): Long = {\n if(n == 1) 1\n else {\n val nt = (1 to n).reverse.take(m).product\n val mt = (1 to m).reverse.product\n (nt / mt).toLong\n }\n }\n\n val mi = n/m\n val mi2_count = if( mi*m != n ) n - mi*m else 0\n val mi_count = m - mi2_count\n val ans1 = (nCm(mi,2)*mi_count + nCm(mi+1,2)*mi2_count)\n\n val mx = n - (m-1)\n val ans2 = nCm(mx,2)\n\n print(Math.min(ans1, ans2))\n print(\" \")\n println(Math.max(ans1, ans2))\n}\n"}], "src_uid": "a081d400a5ce22899b91df38ba98eecc"} {"nl": {"description": "You are given names of two days of the week.Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year.In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.Names of the days of the week are given with lowercase English letters: \"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\".", "input_spec": "The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set \"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\".", "output_spec": "Print \"YES\" (without quotes) if such situation is possible during some non-leap year. Otherwise, print \"NO\" (without quotes).", "sample_inputs": ["monday\ntuesday", "sunday\nsunday", "saturday\ntuesday"], "sample_outputs": ["NO", "YES", "YES"], "notes": "NoteIn the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday."}, "positive_code": [{"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val first = in.next() match {\n case \"monday\" => 0\n case \"tuesday\" => 1\n case \"wednesday\" => 2\n case \"thursday\" => 3\n case \"friday\" => 4\n case \"saturday\" => 5\n case \"sunday\" => 6\n }\n val second = in.next() match {\n case \"monday\" => 0\n case \"tuesday\" => 1\n case \"wednesday\" => 2\n case \"thursday\" => 3\n case \"friday\" => 4\n case \"saturday\" => 5\n case \"sunday\" => 6\n }\n val candidates = List(first + 28, first + 30, first + 31).map(_ % 7)\n if (candidates.contains(second))\n println(\"YES\")\n else\n println(\"NO\")\n}\n"}, {"source_code": "import 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 def processLines(lines: Iterator[String], bw: BufferedWriter): Unit = {\n val day1 = lines.next()\n val day2 = lines.next()\n val hasSolution = solve(day1, day2)\n if (hasSolution) { bw.write(\"YES\") } else {bw.write(\"NO\") };\n bw.newLine()\n }\n\n def solve(day1: String, day2: String): Boolean = {\n val dayNames = List(\"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\")\n def getDayIndex(dayName: String): Int = dayNames.indexOf(dayName)\n val day1Index = getDayIndex(day1)\n val day2Index = getDayIndex(day2)\n val dayOffset = (7 + day2Index - day1Index) % 7 // Add 7 to prevent negative remainders\n val monthLengths = List(28, 30, 31)\n monthLengths.exists(dayOffset == _ % 7)\n }\n}\n"}, {"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\n val dows = Array(\"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\")\n val ms = Array(28, 30, 31)\n\n val s1, s2 = readLine\n\n val d1 = dows.indexWhere(_ == s1)\n val d2 = dows.indexWhere(_ == s2)\n\n val can = ms.exists(d => (d1 + d) % 7 == d2)\n\n println(if (can) \"YES\" else \"NO\")\n}\n"}, {"source_code": "import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._, collection.Searching._\n\nobject _724A extends CodeForcesApp {\n override def apply(io: IO) = {import io.{read, write, writeAll, writeLine}\n val d1, d2 = read[String]\n\n val months = Seq(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)\n val firstDayOfMonth = months.init.scanLeft(0)(_ + _)\n\n val days = IndexedSeq(\"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\")\n\n val ans = days.zipWithIndex exists {case (start, k) =>\n val calendar = Seq.tabulate(365)(i => days((i + k)%days.length))\n firstDayOfMonth.sliding(2) exists {\n case Seq(m1, m2) => calendar(m1) == d1 && calendar(m2) == d2\n }\n }\n\n write(ans.toEnglish)\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 }\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 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 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 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 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 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 = \"\\n\"): 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"}, {"source_code": "//package me.code4fun\n\nimport scala.io.StdIn\n\nobject A {\n\n def dayOfWeek(dayStr: String): Int =\n dayStr match {\n case \"monday\" => 0\n case \"tuesday\" => 1\n case \"wednesday\" => 2\n case \"thursday\" => 3\n case \"friday\" => 4\n case \"saturday\" => 5\n case \"sunday\" => 6\n case _ => throw new IllegalArgumentException(s\"$dayStr is not a day of week\")\n }\n\n val nbDaysInWeek = 7\n\n val possibleOffsets = Seq(28, 30, 31).map(_ % nbDaysInWeek)\n\n def posMod(a: Int, b: Int): Int = {\n val mod = a % b\n if (mod >= 0) mod else (mod + b)\n }\n\n def areConsecutiveDays(firstDay: String, secondDay: String): Boolean = {\n val fst = dayOfWeek(firstDay)\n val snd = dayOfWeek(secondDay)\n val diff = posMod(snd - fst, nbDaysInWeek)\n possibleOffsets.contains(diff)\n }\n\n def main(args: Array[String]): Unit = {\n val fst = StdIn.readLine()\n val snd = StdIn.readLine()\n if (areConsecutiveDays(fst, snd))\n Console.out.println(\"YES\")\n else\n Console.out.println(\"NO\")\n }\n}\n"}], "negative_code": [], "src_uid": "2a75f68a7374b90b80bb362c6ead9a35"} {"nl": {"description": "In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong — the oldest among the inhabitants of Mainframe. But still he managed to get some information from there. For example, he managed to learn that User launches games for pleasure — and then terrible Game Cubes fall down on the city, bringing death to those modules, who cannot win the game...For sure, as guard Bob appeared in Mainframe many modules stopped fearing Game Cubes. Because Bob (as he is alive yet) has never been defeated by User, and he always meddles with Game Cubes, because he is programmed to this.However, unpleasant situations can happen, when a Game Cube falls down on Lost Angles. Because there lives a nasty virus — Hexadecimal, who is... mmm... very strange. And she likes to play very much. So, willy-nilly, Bob has to play with her first, and then with User.This time Hexadecimal invented the following entertainment: Bob has to leap over binary search trees with n nodes. We should remind you that a binary search tree is a binary tree, each node has a distinct key, for each node the following is true: the left sub-tree of a node contains only nodes with keys less than the node's key, the right sub-tree of a node contains only nodes with keys greater than the node's key. All the keys are different positive integer numbers from 1 to n. Each node of such a tree can have up to two children, or have no children at all (in the case when a node is a leaf).In Hexadecimal's game all the trees are different, but the height of each is not lower than h. In this problem «height» stands for the maximum amount of nodes on the way from the root to the remotest leaf, the root node and the leaf itself included. When Bob leaps over a tree, it disappears. Bob gets the access to a Cube, when there are no trees left. He knows how many trees he will have to leap over in the worst case. And you?", "input_spec": "The input data contains two space-separated positive integer numbers n and h (n ≤ 35, h ≤ n).", "output_spec": "Output one number — the answer to the problem. It is guaranteed that it does not exceed 9·1018.", "sample_inputs": ["3 2", "3 3"], "sample_outputs": ["5", "4"], "notes": null}, "positive_code": [{"source_code": "//package me.jetblack.cf\n\nimport java.util.Scanner\n\nobject TreesCount extends App {\n\n val s = new Scanner(System.in)\n\n val maxn = s.nextInt()\n val maxh = s.nextInt()\n\n val dp = Array.ofDim[Long](maxn + 1, maxn + 1)\n dp(0)(0) = 1\n for {\n h <- (1 until maxn + 1)\n i <- (1 until maxn + 1)\n j <- (1 to i)\n } yield {\n val left1 = dp(h - 1)(j - 1)\n val right1 = (0 until h).map(h1 => dp(h1)(i - j)).sum\n val left2 = (0 until h - 1).map(h1 => dp(h1)(j - 1)).sum\n val right2 = dp(h - 1)(i - j)\n dp(h)(i) += (left1 * right1) + left2 * right2\n }\n\n val result = (maxh to maxn).map(dp(_)(maxn)).sum\n println(result)\n\n}\n"}, {"source_code": "import java.util._\nimport java.io._\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 sumOfTrees(dp: Array[Array[Long]], h: Int, n: Int): Long = {\n var temp: Long = 0\n for (i <- 0 to h) {\n temp += dp(i)(n)\n }\n temp\n }\n\n def solve = {\n val n = nextInt\n val h = nextInt\n val dp = new Array[Array[scala.Long]](36)\n for (i <- 0 to 35) {\n dp(i) = new Array[scala.Long](36)\n Arrays.fill(dp(i), 0)\n }\n dp(0)(0) = 1L\n for (i <- 1 to h) {\n dp(i)(0) = 0L\n }\n for (i <- 1 to n) {\n dp(0)(i) = 0L\n }\n for (i <- 1 to 35) {\n for (j <- 1 to 35) {\n var temp: Long = 0\n for (m <- 1 to j) {\n temp += dp(i - 1)(m - 1) * sumOfTrees(dp, i - 1, j - m) + dp(i - 1)(j - m) * sumOfTrees(dp, i - 2, m - 1)\n }\n dp(i)(j) = temp\n }\n }\n var ans: Long = 0\n for (i <- h to n) {\n ans += dp(i)(n)\n }\n out.println(ans)\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"}], "negative_code": [{"source_code": "//package me.jetblack.cf\n\nimport java.util.Scanner\n\nobject TreesCount extends App {\n\n val s = new Scanner(System.in)\n\n val maxn = s.nextInt()\n val maxh = s.nextInt()\n\n val dp = Array.ofDim[Int](maxn + 1, maxn + 1)\n dp(0)(0) = 1\n for {\n h <- (1 until maxn + 1)\n i <- (1 until maxn + 1)\n j <- (1 to i)\n } yield {\n val left1 = dp(h - 1)(j - 1)\n val right1 = (0 until h).map(h1 => dp(h1)(i - j)).sum\n val left2 = (0 until h - 1).map(h1 => dp(h1)(j - 1)).sum\n val right2 = dp(h - 1)(i - j)\n dp(h)(i) += (left1 * right1) + left2 * right2\n }\n\n val result = (maxh to maxn).map(dp(_)(maxn)).sum\n println(result)\n\n}\n"}], "src_uid": "faf12a603d0c27f8be6bf6b02531a931"} {"nl": {"description": "Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately.Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal.", "input_spec": "You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell. It is guaranteed that in the current arrangement nobody has still won.", "output_spec": "Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.", "sample_inputs": ["XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........", "XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n.........."], "sample_outputs": ["YES", "NO"], "notes": null}, "positive_code": [{"source_code": "import scala.io.StdIn._\n\nobject Main extends App {\n val a =\n (for (_ <- 0 until 10)\n yield readLine()).toArray\n\n if (check((0, 1)) || check((1, 0)) || check((1, 1)) || check((1, -1)))\n println(\"YES\")\n else\n println(\"NO\")\n\n def good(x: Int): Boolean = x >= 0 && x < 10\n\n def check(diff: (Int, Int)): Boolean = {\n for (i <- 0 until 10; j <- 0 until 10) {\n var (x, y, cnt, free) = (j, i, 0, 0)\n for (z <- 0 until 5) {\n if (good(x) && good(y))\n if (a(y)(x) == 'X')\n cnt += 1\n else if (a(y)(x) == '.')\n free += 1\n y += diff._1\n x += diff._2\n }\n if (cnt == 4 && free == 1)\n return true\n }\n false\n }\n}\n"}, {"source_code": "import scala.collection.mutable.ArrayBuffer\nimport scala.io.StdIn._\n\nobject Main extends App {\n val a = ArrayBuffer[ArrayBuffer[Char]]()\n for (i <- 0 until 10) {\n a.append(readLine().toCharArray.to[ArrayBuffer])\n }\n\n if (check(a, (0, 1)) || check(a, (1, 0)) || check(a, (1, 1)) || check(a, (1, -1)))\n println(\"YES\")\n else\n println(\"NO\")\n\n def good(x: Int): Boolean = x >= 0 && x < 10\n\n def check(a: ArrayBuffer[ArrayBuffer[Char]], diff: (Int, Int)): Boolean = {\n for (i <- 0 until 10) {\n for (j <- 0 until 10) {\n var x = j\n var y = i\n var cnt = 0\n var free = 0\n for (z <- 0 until 5) {\n if (good(x) && good(y))\n if (a(y)(x) == 'X')\n cnt += 1\n else if (a(y)(x) == '.')\n free += 1\n y += diff._1\n x += diff._2\n }\n if (cnt == 4 && free == 1)\n return true\n }\n }\n false\n }\n}\n"}], "negative_code": [{"source_code": "import scala.collection.mutable.ArrayBuffer\nimport scala.io.StdIn._\n\nobject Main extends App {\n val a = ArrayBuffer[ArrayBuffer[Char]]()\n for (i <- 0 until 10) {\n a.append(readLine().toCharArray.to[ArrayBuffer])\n }\n\n if (check(a) || check(a.transpose) || check2(a, (1, 1)) || check2(a, (1, -1)))\n println(\"YES\")\n else\n println(\"NO\")\n\n\n def check(a: ArrayBuffer[ArrayBuffer[Char]]): Boolean = {\n for (i <- 0 until 10) {\n for (j <- 0 to 5) {\n var cnt = 0\n for (z <- j until j + 5) {\n if (a(i)(z) == 'X')\n cnt += 1\n else if (a(i)(z) == 'O')\n cnt = -5\n }\n if (cnt == 4)\n return true\n }\n }\n false\n }\n\n def good(x: Int): Boolean = x >= 0 && x < 10\n\n def check2(a: ArrayBuffer[ArrayBuffer[Char]], diff: (Int, Int)): Boolean = {\n for (i <- 0 until 10) {\n for (j <- 0 until 10) {\n var x = j\n var y = i\n var cnt = 0\n for (z <- 0 until 5) {\n y += diff._1\n x += diff._2\n if (good(x) && good(y))\n if (a(y)(x) == 'X')\n cnt += 1\n else if (a(y)(x) == 'O')\n cnt = -5\n }\n if (cnt == 4)\n return true\n }\n }\n false\n }\n}\n"}, {"source_code": "import scala.collection.mutable.ArrayBuffer\nimport scala.io.StdIn._\n\nobject Main extends App {\n val a = ArrayBuffer[ArrayBuffer[Char]]()\n for (i <- 0 until 10) {\n a.append(readLine().toCharArray.to[ArrayBuffer])\n }\n\n if (check(a, (0, 1)) || check(a, (1, 0)) || check(a, (1, 1)) || check(a, (1, -1)))\n println(\"YES\")\n else\n println(\"NO\")\n\n def good(x: Int): Boolean = x >= 0 && x < 10\n\n def check(a: ArrayBuffer[ArrayBuffer[Char]], diff: (Int, Int)): Boolean = {\n for (i <- 0 until 10) {\n for (j <- 0 until 10) {\n var x = j\n var y = i\n var cnt = 0\n var free = 0\n for (z <- 0 until 5) {\n y += diff._1\n x += diff._2\n if (good(x) && good(y))\n if (a(y)(x) == 'X')\n cnt += 1\n else if (a(y)(x) == '.')\n free += 1\n }\n if (cnt == 4 && free == 1)\n return true\n }\n }\n false\n }\n}\n"}], "src_uid": "d5541028a2753c758322c440bdbf9ec6"} {"nl": {"description": "An n × n table a is defined as follows: The first row and the first column contain ones, that is: ai, 1 = a1, i = 1 for all i = 1, 2, ..., n. Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula ai, j = ai - 1, j + ai, j - 1. These conditions define all the values in the table.You are given a number n. You need to determine the maximum value in the n × n table defined by the rules above.", "input_spec": "The only line of input contains a positive integer n (1 ≤ n ≤ 10) — the number of rows and columns of the table.", "output_spec": "Print a single line containing a positive integer m — the maximum value in the table.", "sample_inputs": ["1", "5"], "sample_outputs": ["1", "70"], "notes": "NoteIn the second test the rows of the table look as follows: {1, 1, 1, 1, 1},  {1, 2, 3, 4, 5},  {1, 3, 6, 10, 15},  {1, 4, 10, 20, 35},  {1, 5, 15, 35, 70}."}, "positive_code": [{"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n var n = in.next().toInt\n var previous = Array.fill(n){1}\n Range(0, n - 1).foreach { i =>\n val current = Array.ofDim[Int](n)\n current(0) = 1\n Range(1, n).foreach {\n i => current(i) = current(i - 1) + previous(i)\n }\n previous = current\n }\n print(previous.max)\n}\n"}, {"source_code": "object S509A {\n def main(args: Array[String]) {\n var i: Int = 0\n var j: Int = 0\n var n = readInt()\n val a = Array.ofDim[Int](n, n)\n for (i <- 0 until n) {\n a(i)(0) = 1\n a(0)(i) = 1\n }\n for (i <- 1 until n) {\n for (j <- 1 until n)\n a(i)(j) = a(i - 1)(j) + a(i)(j - 1)\n }\n println(a(n - 1)(n - 1))\n }\n}\n\n"}, {"source_code": "object A509 {\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 res = Array.ofDim[Int](n, n)\n for(i <- 0 until n; j <- 0 until n) {\n if(i == 0 || j == 0) {\n res(i)(j) = 1\n } else {\n res(i)(j) = res(i-1)(j) + res(i)(j-1)\n }\n }\n println(res(n-1)(n-1))\n }\n}"}, {"source_code": "import Array._\nimport scala.io.StdIn.readLine\nobject problem {\n def main(args: Array[String]) {\n val n = readLine.toInt\n var A = ofDim[Int](n + 1, n + 1)\n for(i <- 1 to n) A(1)(i) = 1\n for(i <- 2 to n){\n for(j <- 1 to n) A(i)(j) = A(i - 1)(j) + A(i)(j - 1)\n }\n// for(i <- 1 to n){\n// for(j <- 1 to n) print(A(i)(j) + \" \"); println()\n// }\n for(i <- n to n){\n for(j <- n to n) print(A(i)(j) + \" \"); println()\n }\n }\n}"}, {"source_code": "\nimport scala.io.StdIn.readLine\nimport scala.io.StdIn.readInt\n\n\nobject MaximumInTable {\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 def solve(n : Int) : Int = {\n def go(r: Int, c: Int) : Int = {\n if (r == 1 || c == 1) 1 \n else go(r-1,c)+go(r,c-1)\n }\n go(n,n)\n }\n \n \n def main(args: Array[String]) {\n val n = readInt\n println(solve(n))\n }\n \n}"}, {"source_code": "object main extends App with fastIO {\n \n def C(n: Int, m: Int): Int = {\n (n, m) match {\n case (1, m) => 1\n case (n, 1) => 1\n case (n, m) => C(n - 1, m) + C(n, m - 1)\n }\n }\n \n val n = nextInt \n \n println(C(n, 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\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}"}, {"source_code": "import scala.util.Sorting\nimport scala.io.StdIn\n\nobject App {\n\n\n def main(args: Array[String]) {\n\n\n val n = StdIn.readInt()\n val A = Array.ofDim[Array[Int]](n)\n for (i <- 0 to n - 1) {\n A(i) = new Array[Int](n)\n A(i)(0) = 1\n A(0)(i) = 1\n }\n\n for (i <- 1 to n - 1) {\n for (j <- 1 to n - 1) {\n A(i)(j) = A(i-1)(j) + A(i)(j-1)\n }\n }\n\n println(A(n-1)(n-1))\n }\n\n\n\n\n}\n"}], "negative_code": [], "src_uid": "2f650aae9dfeb02533149ced402b60dc"} {"nl": {"description": "Gerald has been selling state secrets at leisure. All the secrets cost the same: n marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on. There are no coins of other denominations. Of course, Gerald likes it when he gets money without the change. And all buyers respect him and try to give the desired sum without change, if possible. But this does not always happen.One day an unlucky buyer came. He did not have the desired sum without change. Then he took out all his coins and tried to give Gerald a larger than necessary sum with as few coins as possible. What is the maximum number of coins he could get?The formal explanation of the previous paragraph: we consider all the possible combinations of coins for which the buyer can not give Gerald the sum of n marks without change. For each such combination calculate the minimum number of coins that can bring the buyer at least n marks. Among all combinations choose the maximum of the minimum number of coins. This is the number we want.", "input_spec": "The single line contains a single integer n (1 ≤ n ≤ 1017). Please, do not use the %lld specifier to read or write 64 bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.", "output_spec": "In a single line print an integer: the maximum number of coins the unlucky buyer could have paid with.", "sample_inputs": ["1", "4"], "sample_outputs": ["1", "2"], "notes": "NoteIn the first test case, if a buyer has exactly one coin of at least 3 marks, then, to give Gerald one mark, he will have to give this coin. In this sample, the customer can not have a coin of one mark, as in this case, he will be able to give the money to Gerald without any change.In the second test case, if the buyer had exactly three coins of 3 marks, then, to give Gerald 4 marks, he will have to give two of these coins. The buyer cannot give three coins as he wants to minimize the number of coins that he gives."}, "positive_code": [{"source_code": "object CF333A {\n def main(argv: Array[String]) {\n def calc(n: Long): Long = {\n if (n % 3 == 0) calc(n / 3)\n else (n + 2) / 3\n }\n println(calc(readLine.toLong))\n }\n}"}, {"source_code": "import scala.collection.mutable._\nimport scala.math._\nimport scala.util._\nimport scala.util.control.Breaks.break\nimport scala.util.control.Breaks.breakable\nimport java.util._\nimport java.math.BigInteger\nobject Main extends App {\n val sc = new Scanner(System.in)\n def count3(n: BigInt): BigInt = {\n if(n % 3 != 0) return 0\n return 1 + count3(n / 3)\n }\n def pow(a: BigInt, b: BigInt): BigInt = {\n if(b == 0) return 1\n else return a * pow(a, b-1)\n }\n val n = new BigInt(sc.nextBigInteger)\n val m = pow(3, count3(n)+1)\n println(n / m + (if((n % m) == 0) 0 else 1))\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val n = in.next().toLong\n\n def findK(n: Long): Long = {\n var k = 3l\n while (n % k == 0) {\n k *= 3\n }\n k\n }\n\n val k = findK(n)\n println( n / k + (if (n % k != 0) 1 else 0))\n\n\n}\n"}, {"source_code": "/**\n * Created by Notebook on 14.02.2015.\n */\nobject AplusB extends App{\n var a =readLong()\n while(a%3==0) a /= 3\n println(a/3+1)\n}\n"}, {"source_code": "object A extends App {\n\n def readString = Console.readLine\n\n val n = BigInt(readString)\n\n var i = BigInt(3)\n \n while (i <= n && n % i == 0) i *= 3\n \n println(n / i + 1)\n}"}, {"source_code": "object Main extends App {\n\n def calc(n: Long): Long = {\n if (n % 3 == 0) calc(n / 3)\n else (n + 2) / 3\n }\n println(calc(readLine.toLong))\n }\n\n"}, {"source_code": "/**\n * User: Oleg Nizhnik\n * Date: 29.07.13\n * Time: 1:49\n */\nobject C_Secrets extends App {\n def find(n: Long, k: Long = 1): Long = if (n % k == 0) find(n, k * 3) else (n + k - 1) / k\n println(find(readLine().toLong))\n\n}\n"}, {"source_code": "/**\n * User: Oleg Nizhnik\n * Date: 29.07.13\n * Time: 1:49\n */\nobject C_Secrets {\n def find(n: Long, k: Long = 1): Long = if (n % k == 0) find(n, k * 3) else (n + k - 1) / k\n def main(args: Array[String]) = println(find(readLine().toLong))\n}\n"}], "negative_code": [{"source_code": "import scala.collection.mutable._\nimport scala.math._\nimport scala.util._\nimport scala.util.control.Breaks.break\nimport scala.util.control.Breaks.breakable\nimport java.util._\nimport java.math.BigInteger\nobject Main extends App {\n val sc = new Scanner(System.in)\n val v = new BigInt(sc.nextBigInteger)\n println(v / 3 + (if((v % 3) == 0) 0 else 1))\n}\n"}, {"source_code": "import scala.collection.mutable._\nimport scala.math._\nimport scala.util._\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 println(ceil(readLong/3.0).toLong)\n}\n"}, {"source_code": "import scala.collection.mutable._\nimport scala.math._\nimport scala.util._\nimport scala.util.control.Breaks.break\nimport scala.util.control.Breaks.breakable\nimport java.util._\nimport java.math.BigInteger\nobject Main extends App {\n val sc = new Scanner(System.in)\n val v = new BigInt(sc.nextBigInteger)\n println(v / 3 + ceil((v % 3).toInt * 0.1).toInt)\n}\n"}, {"source_code": "/**\n * Author: Odomontois\n * Date: 29.07.13\n * Time: 9:53\n * To change this template use File | Settings | File Templates.\n */\nobject C_Secrets extends App {\n val in = java.lang.Long.toString(readLine().toLong, 3).reverse\n println((in(0) match {\n case '1' => in.drop(1).dropWhile(_ == '2')\n case '0' | '2' => in.dropWhile(_ == '0').dropWhile(_ == '2')\n }).map(Map('0' -> 0, '1' -> 1, '2' -> 2)).sum + 1)\n}\n"}, {"source_code": "/**\n * Author: Odomontois\n * Date: 29.07.13\n * Time: 9:53\n * To change this template use File | Settings | File Templates.\n */\nobject C_Secrets extends App {\n val in = java.lang.Long.toString(readLine().toLong, 3).reverse.dropWhile(_ == '0')\n println((in(0) match {\n case '1' => in.drop(1)\n case '2' => in\n }).dropWhile(_ == '2').map(Map('0' -> 0, '1' -> 1, '2' -> 2)).sum + 1)\n}\n"}], "src_uid": "7e7b59f2112fd200ee03255c0c230ebd"} {"nl": {"description": "The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1 ≤ i ≤ n) day, the price for one barrel of honey is going to is xi kilos of raspberry.Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for c kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day d (1 ≤ d < n), lent a barrel of honey and immediately (on day d) sell it according to a daily exchange rate. The next day (d + 1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day d + 1) give his friend the borrowed barrel of honey as well as c kilograms of raspberry for renting the barrel.The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.", "input_spec": "The first line contains two space-separated integers, n and c (2 ≤ n ≤ 100, 0 ≤ c ≤ 100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel. The second line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100), the price of a honey barrel on day i.", "output_spec": "Print a single integer — the answer to the problem.", "sample_inputs": ["5 1\n5 10 7 3 20", "6 2\n100 1 10 40 10 40", "3 0\n1 2 3"], "sample_outputs": ["3", "97", "0"], "notes": "NoteIn the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97."}, "positive_code": [{"source_code": "\nimport scala.io.StdIn\n\nobject BearAndRaspberryMain {\n def main(args: Array[String]): Unit ={\n val nc = StdIn.readLine().split(\" \").map(_.toInt)\n val n = nc(0)\n val c = nc(1)\n val elements = StdIn.readLine().split(\" \").map(_.toInt)\n var LOL = 0\n for(i <- 0 to n-2){\n val d = elements(i) - c - elements(i+1)\n if( LOL < d)\n LOL = d\n }\n print(LOL)\n }\n}"}, {"source_code": "import java.util.StringTokenizer\n\nobject _385A 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 c = next.toInt\n val a = (1 to n).map(i => next.toInt)\n val b = (1 until n).map(i => a(i - 1) - a(i)).max\n val ans = (b - c) max 0\n println(ans)\n}\n"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val Array(n, c) = in.next().split(\" \").map(_.toInt)\n val ans = Math.max(0, in.next().split(\" \").map(_.toInt).sliding(2).map(t => t.head - t.last - c).max)\n println(ans)\n}"}, {"source_code": "import java.util.Scanner\n\nobject P385A {\n def main(args: Array[String]) {\n val scanner = new Scanner(System.in)\n val n = scanner.nextInt()\n val c = scanner.nextInt()\n val prices = for (i <- 1 to n) yield scanner.nextInt()\n val gains = for ((prev, next) <- prices.init zip prices.tail) yield prev - next - c\n val ans = if (gains.max > 0) gains.max else 0\n println(ans)\n }\n}\n"}, {"source_code": "object A385 {\n\n import IO._\n\n def main(args: Array[String]): Unit = {\n val Array(n, c) = readInts(2)\n val in = readInts(n)\n var res = 0\n for(i <- 0 until n-1) {\n val cal = in(i) - in(i+1) - c\n res = math.max(res, cal)\n }\n println(res)\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"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P385A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n val N, C = sc.nextInt\n val X = List.fill(N)(sc.nextInt)\n \n val gain = (X, X.tail).zipped.map(_ - _).max - C\n val answer = if (gain > 0) gain\n else 0\n \n out.println(answer)\n out.close\n}\n"}, {"source_code": "//package codeforces\n\n/**\n * TODO: describe\n *\n * @author keks\n */\nobject T385A {\n def main(args: Array[String]) {\n val rent = readArray.last\n print(getRasp(readArray, rent))\n }\n\n def getRasp(a: Array[Int], rent: Int) = {\n val total = ((0, a.head) /: a.tail)(\n (acc, prev) => (if (acc._1 < acc._2 - prev) acc._2 - prev else acc._1, prev)\n )._1\n if (total > rent) total - rent else 0\n }\n\n def readArray = readLine().split(' ').map(_.toInt)\n}\n"}, {"source_code": "object A extends App {\n val sc = new java.util.Scanner(System.in)\n val n, c = sc.nextInt()\n val x = Array.fill(n)(sc.nextInt())\n var ans = 0\n for (i <- 0 until n-1) {\n ans = ans.max(x(i)-x(i+1)-c)\n }\n println(ans)\n}\n"}], "negative_code": [], "src_uid": "411539a86f2e94eb6386bb65c9eb9557"} {"nl": {"description": "The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.", "input_spec": "The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.", "output_spec": "If the word t is a word s, written reversely, print YES, otherwise print NO.", "sample_inputs": ["code\nedoc", "abb\naba", "code\ncode"], "sample_outputs": ["YES", "NO", "NO"], "notes": null}, "positive_code": [{"source_code": "object P041A extends App {\n val t = readLine()\n val s = readLine()\n println(if (t.reverse == s) \"YES\" else \"NO\")\n}\n"}, {"source_code": "object Translation extends App{\n val berlandish = scala.io.StdIn.readLine()\n val birlandish = scala.io.StdIn.readLine()\n\n if (birlandish.reverse == berlandish) println(\"YES\")\n else println(\"NO\")\n \n}\n"}, {"source_code": "object Main extends App {\n val str1 = readLine()\n val str2 = readLine()\n\n if (str1 == str2.reverse) println(\"YES\")\n else println(\"NO\")\n}"}, {"source_code": "object CF0041A extends App {\n\n val f = readLine()\n val s = readLine()\n\n if( f == s.reverse) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n\n}\n"}, {"source_code": "object Solver {\n def main(args: Array[String]) {\n val (first, second) = (Console.readLine, Console.readLine)\n val success = first.length == second.length && List.range(0, first.length).forall(i => first(i) == second(first.length - i - 1))\n\n println(if (success) \"YES\" else \"NO\")\n }\n}\n"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n var str = in.next()\n var str2 = in.next()\n if (str.length != str2.length || str.zip(str2.reverse).exists(t => t._1 != t._2))\n println(\"NO\")\n else\n println(\"YES\")\n}"}, {"source_code": "object Main {\n\n def main(args: Array[String]) {\n val std = scala.io.StdIn\n\n val areTheSame = std.readLine().equals(std.readLine().reverse)\n if (areTheSame) {\n println(\"YES\")\n }\n else {\n println(\"NO\")\n }\n }\n}"}, {"source_code": "object A41 {\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 if(input1.reverse.compareTo(input2) == 0) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n }\n}"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P41A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val S, T = sc.nextLine\n val answer = if (S == T.reverse) \"YES\" else \"NO\"\n\n out.println(answer)\n out.close\n}\n"}, {"source_code": "\n\nobject Translation {\n\tdef main (args: Array[String]) {\n\t\tval scanner = new java.util.Scanner(System.in);\n\t\tval word1 = scanner.nextLine;\n\t\tval word2 = scanner.nextLine;\n\t\tvar leftIndex = 0;\n\t\tvar rightIndex = word2.length - 1;\n\t\tvar equal = true;\n\t\twhile (equal && leftIndex < word1.length() && rightIndex >= 0) {\n\t\t\tequal = word1(leftIndex) == word2(rightIndex)\n\t\t\tleftIndex += 1; rightIndex-=1\n\t\t}\n\t\tif (equal) {\n\t\t\tprintln(\"YES\")\n\t\t}\n\t\telse\n\t\t\tprintln(\"NO\")\n\t}\n}"}, {"source_code": "import scala.io._\nimport scala.collection.mutable._\nimport java.io.FileWriter\nimport java.io.PrintWriter\n\nobject HelloWorld {\n\n def main(args: Array[String]): Unit = {\n var t = readLine;\n var s = readLine;\n if (t == s.reverse) {\n println(\"YES\");\n } else {\n println(\"NO\");\n }\n } \n}"}, {"source_code": "import annotation.tailrec\nimport java.io._\n\nobject Easy {\n val reader = new BufferedReader(new InputStreamReader(System.in))\n def readInts = reader.readLine().split(\" \").map(_.toInt)\n def readInt = reader.readLine().toInt\n\n def ans = if(reader.readLine() == reader.readLine().reverse) \"YES\" else \"NO\"\n\n def main(args: Array[String]) {\n println(ans)\n }\n}\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val s1 = readLine()\n val s2 = readLine()\n if (s1.reverse == s2) println(\"YES\")\n else println(\"NO\")\n }\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject A_41 extends App {\n val a = readLine()\n val b = readLine()\n\n println(\n if (a == b.reverse) \"YES\" else \"NO\"\n )\n}\n"}, {"source_code": "import scala.io.StdIn.readLine\nobject problem {\n def main(args: Array[String]) {\n val s = readLine\n val t = readLine\n if(t == s.reverse) println(\"YES\") else println(\"NO\")\n }\n}"}, {"source_code": "import java.util.Scanner\n\n\nobject HelloWorldMain {\n\n def main(args: Array[String]): Unit = {\n val sc = new Scanner(System.in)\n\n val str = sc.next()\n\n val strShouldBeReverse = sc.next()\n\n if(str.reverse equalsIgnoreCase strShouldBeReverse )println(\"YES\")\n else println(\"NO\")\n\n\n }\n}\n\n\n\n"}, {"source_code": "import scala.io.StdIn.readLine\nimport scala.io.StdIn.readInt\n\n\nobject Translation {\n \n def readInts() : Array[Int] =\n readLine.split(' ').map(_.toInt)\n \n def main(args: Array[String]) {\n val s = readLine\n val t = readLine\n if (s == t.reverse) println(\"YES\") else println(\"NO\")\n }\n \n}"}, {"source_code": "import java.util.Scanner\n\nobject TEST extends App{\n val sc = new Scanner(System.in)\n print (if(readLine.reverse == readLine)\"YES\" else \"NO\")\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject Task extends App{\n val w1 = readLine\n val w2 = readLine\n \n if(w1.reverse == w2)\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "import scala.io.StdIn\n\nobject Main {\n def main(args: Array[String]): Unit = {\n if (StdIn.readLine() == StdIn.readLine().reverse) println(\"YES\") else println(\"NO\")\n }\n}\n"}], "negative_code": [{"source_code": "object P041A extends App {\n val t = readLine()\n val s = readLine()\n println(if (t.reverse == s) \"YES\" else \"No\")\n}\n"}], "src_uid": "35a4be326690b58bf9add547fb63a5a5"} {"nl": {"description": "A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.You're given a number. Determine if it is a magic number or not.", "input_spec": "The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.", "output_spec": "Print \"YES\" if n is a magic number or print \"NO\" if it's not.", "sample_inputs": ["114114", "1111", "441231"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "positive_code": [{"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val str = in.next()\n if (str.forall(ch => ch == '1' || ch == '4') &&\n str.head != '4' && !str.contains(\"444\"))\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "object A320 {\n\n import IO._\n\n def main(args: Array[String]): Unit = {\n val num = read\n val dummy = Array.fill[Char](num.length)('x').mkString(\"\")\n val res = num.replaceAll(\"144\", \"xxx\").replaceAll(\"14\", \"xx\").replaceAll(\"1\", \"x\")\n if(res.equals(dummy)) {\n println(\"YES\")\n } else {\n println(\"NO\")\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"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P320A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n \n\n def solve(): String = {\n\n @tailrec\n def loop(cs: List[Char]): String = cs match {\n case Nil => \"YES\"\n case '1' :: '4' :: '4' :: rest => loop(rest)\n case '1' :: '4' :: rest => loop(rest)\n case '1' :: rest => loop(rest)\n case _ => \"NO\"\n }\n\n loop(sc.nextLine.toList)\n }\n\n out.println(solve)\n out.close\n}\n"}, {"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 ans = reader.readLine().matches(\"(14{0,2})+\")\n val yesNoAns = Map(true -> \"YES\", false -> \"NO\")\n\n def main(a: Array[String]) {\n println(yesNoAns(ans))\n }\n}\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val s = readLine()\n val r = s.replaceAll(\"144\", \"a\").replaceAll(\"14\", \"a\").replaceAll(\"1\", \"a\")\n if (r.matches(\"a*\")) println(\"YES\")\n else println(\"NO\")\n }\n}"}, {"source_code": "object CF320A extends App {\n override def main(args: Array[String]) {\n val s:String = readLine()\n var i = 0\n while (i < s.length()) {\n if (i+3 <= s.length() && s.substring(i, i+3) == \"144\")\n i += 3 \n else if (i + 2 <= s.length() && s.substring(i, i+2) == \"14\") i += 2\n else if (s.charAt(i) == '1') i += 1\n else {\n println(\"NO\")\n return\n } \n }\n println(\"YES\")\n } \n}"}, {"source_code": "object MagicNumbers {\n def main(args:Array[String]):Unit={\n val str=readLine\n println(solve(str))\n }\n def solve(str:String):String={\n// str.toCharArray.toList match {\n// case(\"144\"::string)=> solve(string)\n// case (\"14\"::string)=>solve(string)\n// case(\"1\"::string)=>solve(string)\n// case(str.length==0)=>\"YES\"\n// case(_)=>\"NO\"\n// }\n if(str.startsWith(\"144\")) solve(str.substring(3))\n else if(str.startsWith(\"14\")) solve(str.substring(2))\n else if(str.startsWith(\"1\")) solve(str.substring(1))\n else if(str.length==0) \"YES\"\n else \"NO\"\n }\n}"}, {"source_code": "import scala.io.StdIn\n\nobject Main {\n def main(args: Array[String]): Unit = {\n val string = StdIn.readLine()\n val valuesOtherThanOneOrFour = string.exists(char => char != '1' && char != '4')\n val startsWithValueOtherThanOne = !string.startsWith(\"1\")\n val containsThreeConsecutiveFours = string.indexOf(\"444\") != -1\n if (valuesOtherThanOneOrFour || startsWithValueOtherThanOne || containsThreeConsecutiveFours) println(\"NO\") else println(\"YES\")\n }\n}\n"}], "negative_code": [{"source_code": "object A320 {\n\n import IO._\n\n def main(args: Array[String]): Unit = {\n val num = read\n if(num.replaceAll(\"144\", \"\").replaceAll(\"14\", \"\").replaceAll(\"1\", \"\").isEmpty) {\n println(\"YES\")\n } else {\n println(\"NO\")\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"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val s = readLine()\n val r = s.replaceAll(\"144\", \"\").replaceAll(\"14\", \"\").replaceAll(\"1\", \"\")\n if (r.size == 0) println(\"YES\")\n else println(\"NO\")\n }\n}"}, {"source_code": "import scala.io.StdIn\n\nobject Main {\n def main(args: Array[String]): Unit = {\n if (StdIn.readLine.forall(char => char == '4' || char == '1')) print(\"YES\") else print(\"NO\")\n }\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject Main {\n def main(args: Array[String]): Unit = {\n var string = StdIn.readLine()\n while (string.contains(\"144\")) {\n string = string.replace(\"144\", \"\")\n }\n while (string.contains(\"14\")) {\n string = string.replace(\"14\", \"\")\n }\n if (string.forall(_ == '1')) println(\"YES\") else println(\"NO\")\n }\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject Main {\n def main(args: Array[String]): Unit = {\n val string = StdIn.readLine()\n if (string.exists(char => char != '4' && char != '1') || !string.startsWith(\"1\")) print(\"NO\") else print(\"YES\")\n }\n}\n"}], "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5"} {"nl": {"description": "The math faculty of Berland State University has suffered the sudden drop in the math skills of enrolling students. This year the highest grade on the entrance math test was 8. Out of 100! Thus, the decision was made to make the test easier.Future students will be asked just a single question. They are given a sequence of integer numbers $$$a_1, a_2, \\dots, a_n$$$, each number is from $$$1$$$ to $$$3$$$ and $$$a_i \\ne a_{i + 1}$$$ for each valid $$$i$$$. The $$$i$$$-th number represents a type of the $$$i$$$-th figure: circle; isosceles triangle with the length of height equal to the length of base; square. The figures of the given sequence are placed somewhere on a Cartesian plane in such a way that: $$$(i + 1)$$$-th figure is inscribed into the $$$i$$$-th one; each triangle base is parallel to OX; the triangle is oriented in such a way that the vertex opposite to its base is at the top; each square sides are parallel to the axes; for each $$$i$$$ from $$$2$$$ to $$$n$$$ figure $$$i$$$ has the maximum possible length of side for triangle and square and maximum radius for circle. Note that the construction is unique for some fixed position and size of just the first figure.The task is to calculate the number of distinct points (not necessarily with integer coordinates) where figures touch. The trick is, however, that the number is sometimes infinite. But that won't make the task difficult for you, will it?So can you pass the math test and enroll into Berland State University?", "input_spec": "The first line contains a single integer $$$n$$$ ($$$2 \\le n \\le 100$$$) — the number of figures. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 3$$$, $$$a_i \\ne a_{i + 1}$$$) — types of the figures.", "output_spec": "The first line should contain either the word \"Infinite\" if the number of distinct points where figures touch is infinite or \"Finite\" otherwise. If the number is finite than print it in the second line. It's guaranteed that the number fits into 32-bit integer type.", "sample_inputs": ["3\n2 1 3", "3\n1 2 3"], "sample_outputs": ["Finite\n7", "Infinite"], "notes": "NoteHere are the glorious pictures for the examples. Note that the triangle is not equilateral but just isosceles with the length of height equal to the length of base. Thus it fits into a square in a unique way.The distinct points where figures touch are marked red.In the second example the triangle and the square touch each other for the whole segment, it contains infinite number of points. "}, "positive_code": [{"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とか+7とかするならvalにしろ\n @inline private def MOD = 1000000007\n\n def solve(): Unit = {\n val N = ni()\n val A = na(N)\n\n val Inf = 1e9.toInt\n var ans = sumL(map(N - 1) { i =>\n (A(i), A(i + 1)) match {\n case (1, 2) => 3\n case (1, 3) => 4\n case (2, 1) => 3\n case (2, 3) => Inf\n case (3, 1) => 4\n case (3, 2) => Inf\n }\n })\n\n ans += sumL(map(N - 2) { i =>\n (A(i), A(i + 1), A(i + 2)) match {\n case (3, 1, 2) => -1\n case _ => 0\n }\n })\n\n if (ans >= Inf) out.println(\"Infinite\")\n else {\n out.println(\"Finite\")\n out.println(ans)\n }\n }\n}"}, {"source_code": "object Main extends App {\n val n = readInt \n val a = readLine.split(\" \").map(_.toInt)\n val result = a.foldLeft((0, 0, 0))((acc, next) => {\n if (acc._3 == -1) (0, 0, -1)\n else {\n (acc._1, acc._2, next) match {\n case (3, 1, 2) => (acc._2, next, acc._3 + 2)\n case (_, 1, 2) => (acc._2, next, acc._3 + 3)\n case (_, 1, 3) => (acc._2, next, acc._3 + 4)\n case (_, 2, 1) => (acc._2, next, acc._3 + 3)\n case (_, 3, 1) => (acc._2, next, acc._3 + 4)\n case (_, 0, _) => (acc._2, next, 0)\n case _ => (0, 0, -1)\n }\n }\n })\n\n if (result._3 < 0) {\n println(\"Infinite\")\n } else {\n println(\"Finite\")\n println(result._3)\n }\n}"}, {"source_code": "import java.util.Scanner\n\nimport scala.io.StdIn\n\nobject Figures extends App {\n val line = new Scanner(StdIn.readLine())\n val n = line.nextInt()\n val a = StdIn.readLine().split(' ').map(_.toInt)\n var points = 0\n for(i <- 0 until n-1) {\n if (a(i) == 1) {\n if (a(i+1) == 2) {\n points += 3\n }\n if (a(i+1) == 3) {\n points += 4\n }\n }\n if (a(i) == 2) {\n if (a(i+1) == 1) {\n points += 3\n }\n if (a(i+1) == 3) {\n println(\"Infinite\")\n System.exit(0)\n }\n }\n if (a(i) == 3) {\n if (a(i+1) == 1) {\n points += 4\n if (i+2 < n && a(i+2) == 2) {\n points -= 1\n }\n }\n if (a(i+1) == 2) {\n println(\"Infinite\")\n System.exit(0)\n }\n }\n }\n println(\"Finite\")\n println(points)\n\n}\n"}], "negative_code": [{"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とか+7とかするならvalにしろ\n @inline private def MOD = 1000000007\n\n def solve(): Unit = {\n val N = ni()\n val A = na(N)\n\n val Inf = 1e9.toInt\n val ans = sumL(map(N - 1) { i =>\n (A(i), A(i + 1)) match {\n case (1, 2) => 3\n case (1, 3) => 4\n case (2, 1) => 3\n case (2, 3) => Inf\n case (3, 1) => 4\n case (3, 2) => Inf\n }\n })\n\n if (ans >= Inf) out.println(\"Infinite\")\n else {\n out.println(\"Finite\")\n out.println(ans)\n }\n }\n}"}, {"source_code": "object Main extends App {\n val n = readInt \n val a = readLine.split(\" \").map(_.toInt)\n val result = a.foldLeft((0, 0, 0))((acc, next) => {\n if (acc._3 == -1) (0, 0, -1)\n else {\n (acc._1, acc._2, next) match {\n case (2, 1, 3) => (acc._2, next, acc._3 + 3)\n case (_, 1, 2) => (acc._2, next, acc._3 + 3)\n case (_, 1, 3) => (acc._2, next, acc._3 + 4)\n case (_, 2, 1) => (acc._2, next, acc._3 + 3)\n case (_, 3, 1) => (acc._2, next, acc._3 + 4)\n case (_, 0, _) => (acc._2, next, 0)\n case _ => (0, 0, -1)\n }\n }\n })\n\n if (result._3 < 0) {\n println(\"Infinite\")\n } else {\n println(\"Finite\")\n println(result._3)\n }\n}"}, {"source_code": "object Main extends App {\n val n = readInt \n val a = readLine.split(\" \").map(_.toInt)\n val result = a.foldLeft((0, 0))((acc, next) => {\n if (acc._2 == -1) (0, -1)\n else {\n (acc._1, next) match {\n case (1, 2) => (next, acc._2 + 3)\n case (2, 1) => (next, acc._2 + 3)\n case (1, 3) => (next, acc._2 + 4)\n case (3, 1) => (next, acc._2 + 4)\n case (0, _) => (next, 0)\n case (_, _) => (0, -1)\n }\n }\n })\n\n if (result._2 < 0) {\n println(\"Infinite\")\n } else {\n println(\"Finite\")\n println(result._2)\n }\n}"}], "src_uid": "6c8f028f655cc77b05ed89a668273702"} {"nl": {"description": "JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer $$$n$$$, you can perform the following operations zero or more times: mul $$$x$$$: multiplies $$$n$$$ by $$$x$$$ (where $$$x$$$ is an arbitrary positive integer). sqrt: replaces $$$n$$$ with $$$\\sqrt{n}$$$ (to apply this operation, $$$\\sqrt{n}$$$ must be an integer). You can perform these operations as many times as you like. What is the minimum value of $$$n$$$, that can be achieved and what is the minimum number of operations, to achieve that minimum value?Apparently, no one in the class knows the answer to this problem, maybe you can help them?", "input_spec": "The only line of the input contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^6$$$) — the initial number.", "output_spec": "Print two integers: the minimum integer $$$n$$$ that can be achieved using the described operations and the minimum number of operations required.", "sample_inputs": ["20", "5184"], "sample_outputs": ["10 2", "6 4"], "notes": "NoteIn the first example, you can apply the operation mul $$$5$$$ to get $$$100$$$ and then sqrt to get $$$10$$$.In the second example, you can first apply sqrt to get $$$72$$$, then mul $$$18$$$ to get $$$1296$$$ and finally two more sqrt and you get $$$6$$$.Note, that even if the initial value of $$$n$$$ is less or equal $$$10^6$$$, it can still become greater than $$$10^6$$$ after applying one or more operations."}, "positive_code": [{"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 if (N == 1) {\n out.println(s\"1 0\")\n } else {\n val f = factorize(N)\n val mul = f.keys.product\n val maxPow = f.values.max\n val minPow = f.values.min\n val lg = if (maxPow == 1 ) 0 else log2(maxPow - 1) + 1\n val cnt = lg + (if (minPow == maxPow && isPow2(maxPow)) 0 else 1)\n out.println(s\"$mul $cnt\")\n }\n }\n\n def isPow2(n: Int): Boolean = {\n Integer.highestOneBit(n) == n\n }\n\n /**\n * *注意* IntをLongにして使わないこと\n */\n def factorize(n: Int): mutable.Map[Int, Int] = {\n import scala.collection.mutable\n val res = mutable.Map[Int, Int]() withDefaultValue 0\n\n def minFactor(n0: Int, rt: Int, i: Int): Int = {\n if (i > rt) n0 // √n まで見つからなかったら n0は素数か1\n else if (n0 % i == 0) i\n else minFactor(n0, rt, i + 1)\n }\n\n def step(n0: Int): 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 /**\n * log2して小数点切り捨てたもの\n */\n def log2(x: Int): Int = {\n var a = Integer.highestOneBit(x)\n var i = 0\n while(a > 1) {\n i += 1\n a >>>= 1\n }\n i\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}"}, {"source_code": "//package codeforce520\n\nimport scala.collection.mutable.ArrayBuffer\n\nobject B {\n def main(args: Array[String]): Unit = {\n val reader = scala.io.StdIn\n\n val n = reader.readInt()\n\n val sieve = ArrayBuffer.fill(n + 1)(1)\n sieve(0) = 0\n sieve(1) = 0\n\n (2 until sieve.size) foreach {i =>\n if (sieve(i) == 1) {\n val j = i\n var c = 2\n while (j * c < sieve.size) {\n sieve(j * c) = 0\n c += 1\n }\n }\n }\n\n val prime = sieve.zipWithIndex.filter(_._1 == 1).map(_._2)\n\n val factor = prime.map{p =>\n var c = 0\n var t = n\n\n while (t % p == 0 && t > 0) {\n c += 1\n t = t / p\n }\n\n (p , c)\n }.filter(_._2 > 0)\n //println(factor.mkString(\" \"))\n\n val minValue = factor.map(_._1).foldLeft(1)(_ * _)\n val need1Operation = factor.map(_._2).toSet.size == 1\n var mult = true\n\n var maxP = if (factor.size > 0) factor.map(_._2).max else 0\n var minO = 0\n var pick = 1\n while(pick < maxP) {\n minO += 1\n pick *= 2\n }\n\n if (pick > maxP) {\n minO += 1\n mult = false\n }\n\n if (!need1Operation && mult == true) minO += 1\n\n if (n <= 3) {\n println(s\"$n 0\")\n }\n else {\n println(s\"$minValue $minO\")\n }\n\n }\n}\n"}, {"source_code": "import scala.collection.mutable\nimport scala.io.StdIn\n\nobject Codeforces1062B {\n\n def getMinimumOperation(n: Int): (Int, Int) = {\n val primeFactors = getPrimeFactorization(n)\n\n if (isUniquePrimeFactors(primeFactors))\n return (multiply(primeFactors.keys), 0)\n\n var totalSteps = 0\n\n val maxPower = primeFactors.values.max\n if (!isPowerOfTwo(maxPower) || !primeFactors.values.forall(_ == maxPower)) {\n totalSteps += 1\n }\n val powerOfTwo = getNextPowerOfTwo(maxPower)\n totalSteps += powerOfTwo\n\n (multiply(primeFactors.keys), totalSteps)\n }\n\n def isPowerOfTwo(n: Int): Boolean = (n & (n - 1)) == 0\n\n def getNextPowerOfTwo(n: Int): Int = {\n var poweredNumber = 2L\n var power = 1\n while (poweredNumber < n) {\n poweredNumber *= 2\n power += 1\n }\n power\n }\n\n def multiply(numbers: Iterable[Int]): Int = {\n var result = 1\n for (number <- numbers) result *= number\n result\n }\n\n\n def isUniquePrimeFactors(primeFactors: mutable.Map[Int, Int]): Boolean =\n primeFactors.values.forall(_ == 1)\n\n def getPrimeFactorization(n: Int): mutable.Map[Int, Int] = {\n val primeFactors = new mutable.HashMap[Int, Int]()\n var remainingNumber = n\n val sqrtN = math.sqrt(n).toInt\n for (primeCandidate <- 2 to sqrtN) {\n if (remainingNumber % primeCandidate == 0) {\n primeFactors(primeCandidate) = 0\n while (remainingNumber % primeCandidate == 0) {\n primeFactors(primeCandidate) += 1\n remainingNumber /= primeCandidate\n }\n }\n }\n\n if (remainingNumber != 1) {\n primeFactors(remainingNumber) = 1\n }\n\n primeFactors\n }\n\n def main(args: Array[String]): Unit = {\n val n = StdIn.readLine.trim.toInt\n\n val result = getMinimumOperation(n)\n\n println(s\"${result._1} ${result._2}\")\n }\n}\n"}], "negative_code": [{"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 if (N == 1) {\n out.println(s\"1 0\")\n } else {\n val f = factorize(N)\n val mul = f.keys.product\n val maxPow = f.values.max\n val minPow = f.values.min\n val lg = if (maxPow == 1 ) 0 else log2(maxPow - 1) + 1\n val cnt = lg + (if (minPow == maxPow) 0 else 1)\n out.println(s\"$mul $cnt\")\n }\n }\n\n /**\n * *注意* IntをLongにして使わないこと\n */\n def factorize(n: Int): mutable.Map[Int, Int] = {\n import scala.collection.mutable\n val res = mutable.Map[Int, Int]() withDefaultValue 0\n\n def minFactor(n0: Int, rt: Int, i: Int): Int = {\n if (i > rt) n0 // √n まで見つからなかったら n0は素数か1\n else if (n0 % i == 0) i\n else minFactor(n0, rt, i + 1)\n }\n\n def step(n0: Int): 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 /**\n * log2して小数点切り捨てたもの\n */\n def log2(x: Int): Int = {\n var a = Integer.highestOneBit(x)\n var i = 0\n while(a > 1) {\n i += 1\n a >>>= 1\n }\n i\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}"}, {"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 if (N == 1) {\n out.println(s\"1 0\")\n } else {\n val f = factorize(N)\n val mul = f.keys.product\n val maxPow = f.values.max\n val minPow = f.values.min\n val cnt = log2(maxPow - 1) + 1 + (if (minPow == maxPow) 0 else 1)\n out.println(s\"$mul $cnt\")\n }\n }\n\n /**\n * *注意* IntをLongにして使わないこと\n */\n def factorize(n: Int): mutable.Map[Int, Int] = {\n import scala.collection.mutable\n val res = mutable.Map[Int, Int]() withDefaultValue 0\n\n def minFactor(n0: Int, rt: Int, i: Int): Int = {\n if (i > rt) n0 // √n まで見つからなかったら n0は素数か1\n else if (n0 % i == 0) i\n else minFactor(n0, rt, i + 1)\n }\n\n def step(n0: Int): 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 /**\n * log2して小数点切り捨てたもの\n */\n def log2(x: Int): Int = {\n var a = Integer.highestOneBit(x)\n var i = 0\n while(a > 1) {\n i += 1\n a >>>= 1\n }\n i\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}"}, {"source_code": "//package codeforce520\n\nimport scala.collection.mutable.ArrayBuffer\n\nobject B {\n def main(args: Array[String]): Unit = {\n val reader = scala.io.StdIn\n\n val n = reader.readInt()\n\n val sieve = ArrayBuffer.fill(n + 1)(1)\n sieve(0) = 0\n sieve(1) = 0\n\n (2 until sieve.size) foreach {i =>\n if (sieve(i) == 1) {\n val j = i\n var c = 2\n while (j * c < sieve.size) {\n sieve(j * c) = 0\n c += 1\n }\n }\n }\n\n val prime = sieve.zipWithIndex.filter(_._1 == 1).map(_._2)\n\n val factor = prime.map{p =>\n var c = 0\n var t = n\n\n while (t % p == 0 && t > 0) {\n c += 1\n t = t / p\n }\n\n (p , c)\n }.filter(_._2 > 0)\n //println(factor.mkString(\" \"))\n\n val minValue = factor.map(_._1).foldLeft(1)(_ * _)\n val need1Operation = factor.map(_._2).toSet.size == 1\n var mult = false\n\n var maxP = if (factor.size > 0) factor.map(_._2).max else 0\n var minO = 0\n var pick = 1\n while(pick < maxP) {\n minO += 1\n pick *= 2\n }\n\n if (pick > maxP) minO += 1\n\n if (!need1Operation || mult == true) minO += 1\n\n if (n <= 3) {\n println(s\"$n 0\")\n }\n else {\n println(s\"$minValue $minO\")\n }\n\n }\n}\n"}, {"source_code": "//package codeforce520\n\nimport scala.collection.mutable.ArrayBuffer\n\nobject B {\n def main(args: Array[String]): Unit = {\n val reader = scala.io.StdIn\n\n val n = reader.readInt()\n val length = (n + 1) / 2\n\n val sieve = ArrayBuffer.fill(length + 1)(1)\n sieve(0) = 0\n sieve(1) = 0\n\n (2 until sieve.size) foreach {i =>\n if (sieve(i) == 1) {\n val j = i\n var c = 2\n while (j * c < sieve.size) {\n sieve(j * c) = 0\n c += 1\n }\n }\n }\n\n val prime = sieve.zipWithIndex.filter(_._1 == 1).map(_._2)\n\n val factor = prime.map{p =>\n var c = 0\n var t = n\n while (t % p == 0 && t > 0) {\n c += 1\n t = t / p\n }\n\n (p , c)\n }.filter(_._2 > 0)\n\n val minValue = factor.map(_._1).foldLeft(1)(_ * _)\n val need1Operation = factor.map(_._2).toSet.size == 1\n var minOperation = (factor.map(_._2).max / 2)\n if (!need1Operation) minOperation += 1\n println(s\"$minValue $minOperation\")\n }\n}\n"}, {"source_code": "//package codeforce520\n\nimport scala.collection.mutable.ArrayBuffer\n\nobject B {\n def main(args: Array[String]): Unit = {\n val reader = scala.io.StdIn\n\n val n = reader.readInt()\n\n val sieve = ArrayBuffer.fill(n + 1)(1)\n sieve(0) = 0\n sieve(1) = 0\n\n (2 until sieve.size) foreach {i =>\n if (sieve(i) == 1) {\n val j = i\n var c = 2\n while (j * c < sieve.size) {\n sieve(j * c) = 0\n c += 1\n }\n }\n }\n\n val prime = sieve.zipWithIndex.filter(_._1 == 1).map(_._2)\n\n val factor = prime.map{p =>\n var c = 0\n var t = n\n\n while (t % p == 0 && t > 0) {\n c += 1\n t = t / p\n }\n\n (p , c)\n }.filter(_._2 > 0)\n //println(factor.mkString(\" \"))\n\n val minValue = factor.map(_._1).foldLeft(1)(_ * _)\n val need1Operation = factor.map(_._2).toSet.size == 1\n var mult = false\n\n var maxP = if (factor.size > 0) factor.map(_._2).max else 0\n var minO = 0\n while(maxP > 1) {\n if (maxP % 2 == 0) {\n maxP = maxP / 2\n }\n else {\n maxP = maxP - 1\n mult = true\n }\n minO += 1\n }\n\n if (!need1Operation || mult == true) minO += 1\n\n if (n <= 3) {\n println(s\"$n 0\")\n }\n else {\n println(s\"$minValue $minO\")\n }\n\n }\n}\n"}, {"source_code": "//package codeforce520\n\nimport scala.collection.mutable.ArrayBuffer\n\nobject B {\n def main(args: Array[String]): Unit = {\n val reader = scala.io.StdIn\n\n val n = reader.readInt()\n\n val sieve = ArrayBuffer.fill(n + 1)(1)\n sieve(0) = 0\n sieve(1) = 0\n\n (2 until sieve.size) foreach {i =>\n if (sieve(i) == 1) {\n val j = i\n var c = 2\n while (j * c < sieve.size) {\n sieve(j * c) = 0\n c += 1\n }\n }\n }\n\n val prime = sieve.zipWithIndex.filter(_._1 == 1).map(_._2)\n\n val factor = prime.map{p =>\n var c = 0\n var t = n\n\n while (t % p == 0 && t > 0) {\n c += 1\n t = t / p\n }\n\n (p , c)\n }.filter(_._2 > 0)\n //println(factor.mkString(\" \"))\n\n val minValue = factor.map(_._1).foldLeft(1)(_ * _)\n val need1Operation = factor.map(_._2).toSet.size == 1\n var mult = false\n\n var maxP = if (factor.size > 0) factor.map(_._2).max else 0\n var minO = 0\n while(maxP > 1) {\n if (maxP % 2 == 0) {\n maxP = maxP / 2\n }\n else {\n maxP = maxP - 1\n mult = true\n }\n minO += 1\n }\n\n if (!need1Operation || mult == true) minO += 1\n\n println(s\"$minValue $minO\")\n }\n}\n"}, {"source_code": "import scala.collection.mutable\nimport scala.io.StdIn\n\nobject Codeforces1062B {\n\n def getMinimumOperation(n: Int): (Int, Int) = {\n val primeFactors = getPrimeFactorization(n)\n\n var totalSteps = 0\n\n val maxPower = primeFactors.values.max\n if (!isPowerOfTwo(maxPower) || !primeFactors.values.forall(_ == maxPower)) {\n totalSteps += 1\n }\n val powerOfTwo = getNextPowerOfTwo(maxPower)\n totalSteps += powerOfTwo\n\n (multiply(primeFactors.keys), totalSteps)\n }\n\n def isPowerOfTwo(n: Int): Boolean = (n & (n - 1)) == 0\n\n def getNextPowerOfTwo(n: Int): Int = {\n var poweredNumber = 2L\n var power = 1\n while (poweredNumber < n) {\n poweredNumber *= 2\n power += 1\n }\n power\n }\n\n def multiply(numbers: Iterable[Int]): Int = {\n var result = 1\n for (number <- numbers) result *= number\n result\n }\n\n\n def isUniquePrimeFactors(primeFactors: mutable.Map[Int, Int]): Boolean =\n primeFactors.values.forall(_ == 1)\n\n def getPrimeFactorization(n: Int): mutable.Map[Int, Int] = {\n val primeFactors = new mutable.HashMap[Int, Int]()\n var remainingNumber = n\n val sqrtN = math.sqrt(n).toInt\n for (primeCandidate <- 2 to sqrtN) {\n if (remainingNumber % primeCandidate == 0) {\n primeFactors(primeCandidate) = 0\n while (remainingNumber % primeCandidate == 0) {\n primeFactors(primeCandidate) += 1\n remainingNumber /= primeCandidate\n }\n }\n }\n\n if (remainingNumber != 1) {\n primeFactors(remainingNumber) = 1\n }\n\n primeFactors\n }\n\n def main(args: Array[String]): Unit = {\n val n = StdIn.readLine.trim.toInt\n\n val result = getMinimumOperation(n)\n\n println(s\"${result._1} ${result._2}\")\n }\n}\n"}], "src_uid": "212cda3d9d611cd45332bb10b80f0b56"} {"nl": {"description": "One day the Codeforces round author sat exams. He had n exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to make the sum of his marks strictly more than k. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than k, the author's mum won't be pleased at all. The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams. Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all n exams equal exactly k.", "input_spec": "The single input line contains space-separated integers n and k (1 ≤ n ≤ 50, 1 ≤ k ≤ 250) — the number of exams and the required sum of marks. It is guaranteed that there exists a way to pass n exams in the way that makes the sum of marks equal exactly k.", "output_spec": "Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal k.", "sample_inputs": ["4 8", "4 10", "1 3"], "sample_outputs": ["4", "2", "0"], "notes": "NoteIn the first sample the author has to get a 2 for all his exams.In the second sample he should get a 3 for two exams and a 2 for two more.In the third sample he should get a 3 for one exam."}, "positive_code": [{"source_code": "import java.util.Scanner\nimport math.min\nimport math.max\n\nobject Main {\n\n def main(args:Array[String]) {\n val scanner = new Scanner(System.in)\n val n, k = scanner.nextInt()\n val ans = max (0, min (n, 3 * n - k))\n println (ans)\n }\n\n}\n\n// vim: set ts=4 sw=4 et:\n"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val Array(n, k) = in.next().split(' ').map(_.toInt)\n val count = n - Math.min(n, k - 2 * n)\n println(count)\n}\n"}, {"source_code": "object A194 {\n\n import IO._\n import collection.{mutable => cu}\n\n def main(args: Array[String]): Unit = {\n var Array(n, k) = readInts(2)\n k -= 2*n\n if(k <= n) {\n println(n-k)\n } else {\n println(\"0\")\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"}, {"source_code": "object Main {\n\tdef main(args: Array[String]) {\n\t\tval result = {\n\t\t\tval (n, k) = {\n\t\t\t\tval line = readLine()\n\t\t\t\tval sp = line.split(' ')\n\t\t\t\tval p = sp.map(Integer.parseInt(_))\n\t\t\t\t(p(0), p(1))\n\t\t\t}\n\t\t\tval lowest = k / n\n\t\t\tif (lowest > 2) 0\n\t\t\telse n*3 - k\n\t\t}\n\t\tprint(result)\n\t}\n}"}, {"source_code": "import java.util._\n\nobject Main {\n\n def main(args: Array[String]) {\n val in = new Scanner(System.in)\n val n = in.nextInt\n val s = in.nextInt - 2 * n\n if (s >= n) {\n println(0)\n } else {\n println(n - s)\n }\n }\n\n}"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val Array(n, k) = readLine().split(\" \").map(_.toInt)\n if (k / 3 >= n) println(\"0\")\n else println(n - (k - (k / n) * n))\n }\n}"}, {"source_code": "object Main extends App{\n val in = readLine\n val Array(n, k)=in.split(' ').map(_.toInt)\n val count = n -Math.min(n, k -2* n)\n println(count)\n}"}], "negative_code": [{"source_code": "object Main {\n def main(args: Array[String]) {\n val Array(n, k) = readLine().split(\" \").map(_.toInt)\n if (k / 3 >= n) println(\"0\")\n else println(n - (k - (k / 2) * 2))\n }\n}"}], "src_uid": "5a5e46042c3f18529a03cb5c868df7e8"} {"nl": {"description": "When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked $$$n$$$ people about their opinions. Each person answered whether this problem is easy or hard.If at least one of these $$$n$$$ people has answered that the problem is hard, the coordinator decides to change the problem. For the given responses, check if the problem is easy enough.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$) — the number of people who were asked to give their opinions. The second line contains $$$n$$$ integers, each integer is either $$$0$$$ or $$$1$$$. If $$$i$$$-th integer is $$$0$$$, then $$$i$$$-th person thinks that the problem is easy; if it is $$$1$$$, then $$$i$$$-th person thinks that the problem is hard.", "output_spec": "Print one word: \"EASY\" if the problem is easy according to all responses, or \"HARD\" if there is at least one person who thinks the problem is hard. You may print every letter in any register: \"EASY\", \"easy\", \"EaSY\" and \"eAsY\" all will be processed correctly.", "sample_inputs": ["3\n0 0 1", "1\n0"], "sample_outputs": ["HARD", "EASY"], "notes": "NoteIn the first example the third person says it's a hard problem, so it should be replaced.In the second example the problem easy for the only person, so it doesn't have to be replaced."}, "positive_code": [{"source_code": "import scala.io.StdIn\nobject EasyProblem extends App\n{\n val numOfPersons = StdIn.readInt()\n val input = StdIn.readLine().split(' ').map(_.toInt)\n var hard = 0\n for(i <- input.indices)\n {\n if(input(i) == 1)\n {\n hard += 1\n }\n }\n if(hard > 0)\n {\n println(\"HARD\")\n } else println(\"EASY\")\n}"}, {"source_code": "import scala.io.StdIn\n\nobject cf1030a {\n def main(args: Array[String]): Unit = {\n val _ = StdIn.readInt()\n val in = StdIn.readLine().split(' ').map(_.toInt)\n\n if (in.sum > 0) {\n println(\"HARD\")\n } else {\n println(\"EASY\")\n }\n }\n}\n"}, {"source_code": "import scala.io.StdIn.readLine\n\nobject A1030 {\n def main(args: Array[String]): Unit = {\n val _ = readLine\n val answer = if (Helper.readToListInts.contains(1)) \"HARD\" else \"EASY\"\n println(answer)\n }\n}\n\nobject Helper {\n def readInt: Int = readLine.toInt\n def readToListInts: List[Int] = readLine.split(\" \").map(_.toInt).toList\n def readToVectorInts: Vector[Int] = readLine.split(\" \").map(_.toInt).toVector\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject Main {\n def main(args: Array[String]): Unit = {\n val n = StdIn.readLine()\n val s = StdIn.readLine()\n if(solve(s)) println(\"HARD\")\n else println(\"EASY\")\n }\n\n def solve(s: String): Boolean = {\n s.contains('1')\n }\n}"}, {"source_code": "import io.StdIn._\nobject InSearchOfEasyproblem {\n\n def main(args: Array[String]): Unit = {\n var number = readInt()\n var inputs: Array[Int] = readLine().split(\" \").map(t => s\"$t\".toInt)\n val answer = inputs.sum match {\n case 0 => \"EASY\"\n case _ => \"HARD\"\n }\n println(answer)\n }\n\n}"}, {"source_code": "object InSearchofanEasyProblem1030A 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 isHard = (1 to n).foldLeft(0){case (current,_) => current + scanner.nextInt()} > 0\n out.println(s\"${if(isHard) \"HARD\" else \"EASY\"}\")\n\n }\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject Codeforces1030A extends App {\n val n = StdIn.readLine().toInt\n val hard = StdIn.readLine().split(\"\\\\s\").map(n => n == \"1\")\n\n val allEasy = !hard.contains(true)\n\n printf(if (allEasy) \"EASY\" else \"HARD\")\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject Main2 extends App {\n val personNumber = StdIn.readInt()\n val difficulties = StdIn.readLine()\n println(if (difficulties.contains(\"1\")) \"hard\" else \"easy\")\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject TaskA extends App {\n readInt\n println(if (readLine.split(\" \").contains(\"1\")) \"HARD\" else \"EASY\")\n}\n"}, {"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 A = na(N)\n val ok = A.forall(_ == 0)\n val ans = if(ok) \"EASY\" else \"HARD\"\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}\n"}, {"source_code": "object A {\n def main(args: Array[String]) = {\n val n = scala.io.StdIn.readInt()\n if (scala.io.StdIn.readLine().split(\" \").map(_.toInt).sum > 0) {\n System.out.println(\"HARD\")\n } else {\n System.out.println(\"EASY\")\n }\n }\n}\n"}, {"source_code": "import java.util.Scanner\nimport scala.io.StdIn\nobject Toto extends App {\n val n = StdIn.readInt()\n val data = new Scanner (StdIn.readLine())\n val hard =\n (1 to n).foldLeft(false) {\n (acc, _) =>\n val x = data.nextInt()\n acc || (x == 1)\n }\n if (hard){println(\"HARD\")} else {println(\"EASY\")}\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject Solution {\n\tval n = readLine.toInt\n\tvar r = readLine.split(\" \").map(_.toInt)\n\n\tdef main(args:Array[String]):Unit = {\n\t\tvar response = \"EASY\"\n\t\tfor(i <- 0 until n) {\n\t\t\tif(r(i) == 1) response = \"HARD\"\n\t\t}\n\t\tprintln(response)\n\t}\n}\n"}], "negative_code": [{"source_code": "object Toto extends App {\n println(\"HARD\")\n}\n"}], "src_uid": "060406cd57739d929f54b4518a7ba83e"} {"nl": {"description": "Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: deletes all the vowels, inserts a character \".\" before each consonant, replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters \"A\", \"O\", \"Y\", \"E\", \"U\", \"I\", and the rest are consonants. The program's input is exactly one string, it should return the output as a single string, resulting after the program's processing the initial string.Help Petya cope with this easy task.", "input_spec": "The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.", "output_spec": "Print the resulting string. It is guaranteed that this string is not empty.", "sample_inputs": ["tour", "Codeforces", "aBAcAba"], "sample_outputs": [".t.r", ".c.d.f.r.c.s", ".b.c.b"], "notes": null}, "positive_code": [{"source_code": "object Main extends App{\n \n var t = readLine().toLowerCase().replaceAll(\"[aeyuio]\",\"\")\n t.foreach( (c) => print(\".\" + c ) )\n \n} "}, {"source_code": "object JuanDavidRobles {\n def main(args: Array[String]): Unit = {\n\n import scala.io.StdIn\n\n var line : String = StdIn.readLine()\n\n var string : String = \"\"\n\n var char : Char = 'a'\n\n for (i <- 0 until line.length){\n char = line.charAt(i)\n if (!char.equals('a') && !char.equals('e') &&\n !char.equals('i') && !char.equals('o') &&\n !char.equals('u') && !char.equals('y') &&\n !char.equals('A') && !char.equals('E') &&\n !char.equals('I') && !char.equals('O') &&\n !char.equals('U') && !char.equals('Y')){\n\n if (char.toInt >= 65 && char <= 90){\n char = (char.toInt+32).toChar\n }\n string = string + \".\" + char.toString\n }\n }\n println(string)\n }\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject Main {\n\n val vowels = Array('A', 'I', 'U', 'E', 'O', 'Y')\n\n def isVowel(char: Char) : Boolean = {\n vowels contains char\n }\n\n def main(args: Array[String]): Unit = {\n val s = StdIn.readLine()\n\n println(s.map(_.toUpper).filter(!isVowel(_)).map(\".\"+ _.toLower).mkString)\n }\n}\n"}, {"source_code": "import scala.io.StdIn.readLine\n\n\nobject StringTask {\n \n def main(args: Array[String]) {\n val line = readLine\n println(line.toLowerCase()\n .filterNot { List('a','o','y','e','u','i').contains(_) }\n .flatMap { x => \".\" + x }\n )\n \n }\n \n}"}, {"source_code": "object Main extends App {\nval vovels = List('a', 'i', 'u', 'e', 'o', 'y')\nval s = readLine()\nval res = s.toLowerCase.filter(!vovels.contains(_)).flatMap(x=>\".\" + x)\nprintln(res)\n}"}, {"source_code": "object Main extends App {\n val help =List('a','e','o','u','i','y')\n println(readLine().toLowerCase.filterNot(help.contains).mkString(\".\",\".\",\"\"))\n}"}, {"source_code": "object Main extends App {\n val vowels = List('A', 'O', 'Y', 'E', 'U', 'I') ++ List('a', 'o', 'y', 'e', 'u', 'i')\n def isVowel(c: Char): Boolean = vowels exists { _ == c }\n def isConsonant(c: Char): Boolean = !isVowel(c)\n def insertDot(c: Char): String = \".\"+ c\n def solve(s: String): String = s filterNot isVowel flatMap insertDot toLowerCase\n\n println(solve(readLine()))\n}\n"}, {"source_code": "object StringTask {\n val vowels = Array('a', 'e', 'i', 'o', 'u', 'y')\n\n def main(args: Array[String]) {\n val sb = new StringBuilder\n\n Console.readLine.foreach { ch =>\n val lower = ch.toLower\n if (!vowels.contains(lower)) {\n sb.append(\".\").append(lower)\n }\n }\n\n println(sb.toString)\n }\n}\n"}, {"source_code": "object test\n{\n def main(args : Array[String])\n {\n print(readLine.toLowerCase.replaceAll(\"[aeiouy]\",\"\").map(\".\"+_).mkString)\n }\n}\n"}, {"source_code": "object Main {\n\n def main(args: Array[String]): Unit = {\n println(readLine().map(_.toUpperCase).filter(!\"AOYEUI\".contains(_)).map(\".\"+_.toLowerCase).reduce(_+_))\n }\n\n}"}, {"source_code": "object test {\n\tdef main(args: Array[String]){\n\t\tprint(readLine.toLowerCase.replaceAll(\"[aeiouy]\",\"\").map(\".\"+_).mkString)\n\t}\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject StringTask_118A extends App{\n\tval str = readLine\n\tval vowels = Set('a', 'e', 'i', 'o', 'u', 'y')\n\t\n\tprintln(str.map(_.toLower).filter(!vowels.contains(_)).flatMap(\".\" + _))\n}"}, {"source_code": "import java.util.Scanner\n\n/**\n * Created by Orhan on 3/7/2017.\n */\nobject StringTask extends App{\n val line = new Scanner(System.in)\n var word = line.next().toLowerCase()\n val vowels = Array(\"a\", \"o\", \"y\", \"e\", \"u\", \"i\")\n print(word.split(\"\").filter( w => !vowels.contains(w)).map(w => \".\" + w).mkString(\"\"))\n}\n"}, {"source_code": "object StringTask {\n import io.StdIn.{readLine => rl}\n def rnum() = rl().split(\" \").map(_.toLong)\n def main(args : Array[String]) {\n val iscons = (c:Char) => !\"aoyeui\".contains(c)\n println (rl.toLowerCase.filter(iscons).fold(\"\")((h,t) => h + \".\" + t))\n }\n}\n"}, {"source_code": "object main extends App{\n var s = readLine.toLowerCase().replaceAll(\"[aeyuio]\",\"\")\n s.foreach((c) => print(\".\" + c))\n}"}, {"source_code": "import java.util.Scanner\n\nobject A00118 extends App {\n println(Console.readLine().filterNot(\"aeiouyAEIOUY\".contains(_)).map(x => \".\" + x).map(x => x.toLowerCase()).mkString)\n}\n"}, {"source_code": "object Main {\n def main(args: Array[String]): Unit = {\n val isVowel = Set('a', 'e', 'i', 'o', 'u', 'y')\n\n val line = readLine.toLowerCase\n\n val out1 = line.filterNot(isVowel)\n val out = out1 map {x => \".\"+x}\n println(out.mkString)\n }\n}\n"}, {"source_code": "object A {\n\n def main(args: Array[String]): Unit = {\n println(readLine().toLowerCase().replaceAll(\"[aoyeui]\", \"\").map(s => \".\" + s).mkString(\"\"))\n }\n\n}"}, {"source_code": "import scala.io.StdIn\n\nobject Test {\n val vovels = \"AOUYIE\".toLowerCase.toCharArray\n def main(args1: Array[String]) {\n// val args = Console.readLine().split(\" \")\n// val (v: Long, y: Long, z: Long) = (args(0).toLong, args(1).toLong, args(2).toLong)\n\n\n val line = StdIn.readLine\n val chars = line.toCharArray\n val res = chars.map(s => s.toLower).filter(s => !isVovel(s)).map(s => s\".$s\")\n\n\n// val res = balls.size\n res.foreach(print)\n }\n\n def isVovel(char: Char): Boolean = {\n return vovels.contains(char)\n }\n}"}, {"source_code": "object OneOneEightA {\n\n\tdef main(args : Array[String]) : Unit = {\n\t\tvar vovels=Array('a', 'o', 'y', 'e', 'u', 'i','A', 'O', 'Y', 'E', 'U', 'I')\n\t\tvar input=readLine.toCharArray\n\t\tvar strBuff=new StringBuilder\n\t\tfor(i<-input){\n\t\t\tif(!vovels.contains(i)){\n\t\t\t\tstrBuff.append(\".\"+i.toLower)\n\t\t\t}\n\t\t}\n\t\tprintln(strBuff.toString)\n\t}\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject StringTask {\n def main(args: Array[String]): Unit = {\n val vowels = Set('a', 'o', 'y', 'e', 'u', 'i')\n val s = readLine().toLowerCase().filter(x => !vowels.contains(x))\n val ans = s.map(x => \".\" + x).foldLeft(\"\")((acc, x) => acc + x)\n println(ans)\n }\n}"}, {"source_code": "/*input\nxnhcigytnqcmy\n*/\n\nimport java.util.Scanner\nimport scala.io.StdIn\n\nobject Solution {\n\tdef main(args: Array[String]): Unit = {\n\n\t\tval str = StdIn.readLine().map(_.toLower);\n\t\tstr.foreach((x: Char) => {\n\t\t\tif(!(\"aeiouy\".contains(x))) {\n\t\t\t\tprint('.');\n\t\t\t\tprint(x);\n\t\t\t}\n\t\t})\n\n\t}\n\n}"}, {"source_code": "object main extends App {\n var s = readLine().toLowerCase().replaceAll(\"([aoyeui])\", \"\")\n s.foreach((c) => print(\".\" + c))\n}"}, {"source_code": "object CF118A extends App {\n import scala.io.StdIn.readLine\n import scala.collection.immutable.HashSet\n val s = readLine.toLowerCase.toCharArray\n val vowels:HashSet[Char] = HashSet('a','e','i','o','u','y')\n s.filter(!vowels(_)).foreach(x => print(\".\"+x.toString))\n}"}, {"source_code": "object StringTask extends App {\n\n\t\n\tval input = scala.io.StdIn.readLine().toLowerCase()\n\n val noVowel = input.replaceAll(\"([aeiouy])+\", \"\")\n val output = noVowel.map(x => s\".$x\").mkString\n \n\tprintln(output)\n\n}"}, {"source_code": "object Main extends App {\n val inputString = readLine.toList\n\n def replaceLiterals(list: List[Char]): List[Char] = list match {\n case List() => List()\n case e :: rest => \n e match {\n case 'a' | 'e' | 'i' | 'o' | 'u' |'y' | 'A' | 'E' | 'I' | 'O' | 'U' | 'Y' => replaceLiterals(rest)\n case _ => '.' :: e.toLower :: replaceLiterals(rest)\n } \n }\n\n println(replaceLiterals(inputString).mkString)\n}\n"}, {"source_code": "object Main extends App {\n val str = readLine().toList\n val vovels = \"AOYEUIaoyeui\"\n\n def helper(xs: List[Char]): List[Char] = xs match {\n case (x :: ys) if vovels.contains(x) => helper(ys)\n case (x :: ys) => '.' :: x.toLower :: helper(ys)\n case _ => Nil\n }\n\n println(helper(str).mkString)\n}"}, {"source_code": "object CF0118A extends App {\n\n val gl = List(\"a\", \"o\", \"y\", \"e\", \"u\", \"i\")\n\n val str = readLine()\n\n var result = new StringBuilder\n\n for (ch <- str) {\n if (!(gl contains(ch.toString.toLowerCase))) {\n result ++= \".\" + ch.toString.toLowerCase\n }\n }\n\n println(result)\n\n}\n"}, {"source_code": "import scala.io.StdIn\n\n/** A. String Task\n *\n * @author Yuichiroh Matsubayashi\n * Created on 15/01/19.\n */\nobject P118A extends App {\n val vowels = Seq('a', 'o', 'y', 'e', 'u', 'i')\n val word = StdIn.readLine().toLowerCase\n\n def solution = word.filterNot(vowels.contains(_)).map(c => \".\" + c).mkString\n\n println(solution)\n}"}, {"source_code": "import java.io._\n\nobject Main {\n\n val in = new BufferedReader(new InputStreamReader(System.in))\n val out = new PrintWriter(System.out)\n sys.addShutdownHook(out.close())\n\n @inline def nextInt = in.readLine().toInt\n @inline def nextInts = in.readLine().split(\" +\").map(_.toInt)\n @inline def println[T](x: T) = out.println(x)\n\n def main(args: Array[String]): Unit = {\n val s = in.readLine()\n val ans = s.\n toLowerCase.\n replace(\"a\",\"\").\n replace(\"e\",\"\").\n replace(\"i\",\"\").\n replace(\"o\",\"\").\n replace(\"u\",\"\").\n replace(\"y\",\"\").\n mkString(\".\", \".\", \"\")\n\n println(ans)\n\n }\n}"}, {"source_code": "object HelloWorld {\n def main(args: Array[String]): Unit = {\n \tvar s = readLine()\n \ts = s.map(c => c.toLower)\n \ts = s.replaceAll( \"[eyuioa]\", \"\") \n \tvar str = \"\"\n \tfor(i <-0 until s.length())\n \t\tstr = str + \".\" + s(i)\n \tprintln(str)\n }\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject task1 {\n def main(args: Array[String]): Unit = {\n val input = readLine()\n val letters = List('A', 'O', 'Y', 'E', 'U', 'I').map(_.toLower)\n val result = input.filterNot(el2 => letters.contains(el2.toLower)).map{ el =>\n s\".$el\"\n }.mkString(\"\").toLowerCase\n println(result)\n }\n\n}\n"}, {"source_code": "object task158A {\n def stripChars(s:String, ch:String)= s filterNot (ch contains _)\n def main(args:Array[String]) {\n for (c<-stripChars(io.Source.stdin.getLines.toList(0).toLowerCase,\"aoyeui\")) {\n print(\".\"+c)\n }\n println\n }\n}"}, {"source_code": "object pratise {\n def main(args : Array[String]) {\n val str = readLine().toLowerCase().replaceAll(\"([aoyeui])\",\"\")\n str.foreach(c => print(\".\"+c))\n }\n}\n"}, {"source_code": "object cf extends App{\n val vowels = Set('a', 'e', 'i', 'o', 'u', 'y')\n var s = readLine().toLowerCase()\n var res = \"\"\n for (i <- 0 to s.length()-1) {\n if (!vowels(s(i))) {\n res += \".\" + s(i)\n }\n }\n println(res)\n}"}, {"source_code": "object StringTask extends App {\n val str = readLine().toLowerCase\n val vowels = List('a', 'e', 'o', 'u', 'y', 'i')\n val consonants = List('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'z')\n\n def filterVowels(c: Char) = if (!vowels.contains(c)) true else false\n\n def mapConsonants(c: Char) = if (consonants.contains(c)) \".\" + c else c\n\n println(str.toList.filter(c => filterVowels(c)).map(c => mapConsonants(c)).mkString(\"\"))\n}\n"}, {"source_code": "object Solution {\n val vowels = Array(\"A\", \"O\", \"Y\", \"E\", \"U\", \"I\")\n def split(line: String) = line.grouped(1).toList\n def consonants(chars: List[String]) = chars filter (c => ! (vowels contains (c toUpperCase)))\n def withDots(chars: List[String]) = chars flatMap (c => Array(\".\", c))\n def solve(line: String) = withDots (consonants (split(line toLowerCase))) mkString\n def main(args: Array[String]) = println(solve(readLine))\n}"}, {"source_code": "object Solution {\n val vowels = Array(\"A\", \"O\", \"Y\", \"E\", \"U\", \"I\")\n def split(line: String) = line grouped 1\n def consonants(chars: Iterator[String]) = chars filter (c => ! (vowels contains (c toUpperCase)))\n def withDots(chars: Iterator[String]) = chars flatMap (c => List(\".\", c))\n def solve(line: String) = withDots (consonants (split(line toLowerCase))) mkString\n def main(args: Array[String]) = println(solve(readLine))\n}"}, {"source_code": "object Solution {\n val vowels = Array(\"A\", \"O\", \"Y\", \"E\", \"U\", \"I\") map (_ charAt 0)\n def isVowel(c: Char) = ! (vowels contains (Character.toUpperCase(c)))\n def consonants(chars: Seq[Char]) = chars filter isVowel\n def withDots(chars: Seq[Char]) = chars flatMap (c => List('.', c))\n def solve(line: String) = withDots(consonants(line.toLowerCase)).mkString\n def main(args: Array[String]) = println(solve(readLine))\n}"}, {"source_code": "object Solution {\n val vowels = Array(\"A\", \"O\", \"Y\", \"E\", \"U\", \"I\") map (_ charAt 0)\n def isVowel(c: Char) = ! (vowels contains (Character.toUpperCase(c)))\n def consonants(chars: Seq[Char]) = chars filter isVowel\n def withDots(chars: Seq[Char]) = chars flatMap (c => List('.', c))\n def solve(line: String) = withDots (consonants (line toLowerCase)) mkString\n def main(args: Array[String]) = println(solve(readLine))\n}"}, {"source_code": "object Solution118A extends Application {\n\n def solution() {\n println(_string.toLowerCase.replaceAll(\"[aoyeui]\", \"\").map(c => \".\" + c).mkString)\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}"}, {"source_code": "object Cf118A extends App {\n val s = readLine()\n println(s.toLowerCase.replaceAll(\"[ayeoiu]\", \"\").map(\".\" + _).mkString)\n}"}, {"source_code": "\nobject Main {\n def main(args: Array[String]): Unit = {\n print(readLine().split(\"\")\n .map(el => if (!\"AOYEUI\".contains(el.toUpperCase())) \".\" + el.toLowerCase() else \"\")\n .mkString(\"\"))\n }\n}"}, {"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 for(i <- readLine.replaceAll(\"[AOYEUIaoyeui]\", \"\").toLowerCase) print(\".\"+i)\n println\n}\n"}, {"source_code": "// http://codeforces.com/problemset/problem/118/A\n\nimport scala.io.StdIn.readLine\n\nobject StringTask {\n def main(args: Array[String]): Unit = {\n val vowels: Set[Char] = \"aeiouy\".toSet\n\n var line: String = readLine().toLowerCase()\n line = line.filterNot(vowels.contains(_))\n val dotted: String = line.mkString(\".\")\n println(f\".${dotted}%s\")\n }\n}"}, {"source_code": "object Solution extends App {\n val vowel = List('a', 'e', 'o', 'u', 'i', 'y')\n println(readLine().toLowerCase.filterNot(vowel.contains).mkString(\".\", \".\", \"\"))\n}"}, {"source_code": "import scala.collection.immutable.IndexedSeq\n\nobject Problem118A {\n def main(a: Array[String]) = {\n val vowels = Set('A', 'O', 'Y', 'E', 'U', 'I', 'a', 'o', 'y', 'e', 'u', 'i')\n\n val vowelsDeleted: String = readLine().filter(c => ! vowels.contains(c))\n val pointsToLowerCase: IndexedSeq[String] = vowelsDeleted.map(c => \".\" + c.toLower.toString())\n val result: String = pointsToLowerCase.foldLeft(\"\")((s: String, t: String) => s + t)\n\n println(result)\n }\n}\n"}, {"source_code": "object Cf118a extends App {\n val vowels = List('a', 'o', 'y', 'e', 'u', 'i')\n val word = readLine\n val result = word.toLowerCase.filterNot(vowels.contains).mkString(\".\", \".\", \"\")\n println(result)\n}\n"}, {"source_code": "object Main {\n\timport java.{util=>ju}\n\timport scala.annotation._\n\timport scala.collection._\n\timport scala.collection.{mutable => mu}\n\timport scala.collection.JavaConverters._\n\timport scala.math._\n\n\tdef main(args:Array[String])\n\t{\n\t\tval sc = new ju.Scanner(System.in)\n\t\tval input = sc.next();\n\n\t\tinput.map{\n\t\t\tcase n if n == 'A' => \"\"\n\t\t\tcase n if n == 'O' => \"\"\n\t\t\tcase n if n == 'Y' => \"\"\n\t\t\tcase n if n == 'E' => \"\"\n\t\t\tcase n if n == 'U' => \"\"\n\t\t\tcase n if n == 'I' => \"\"\n\t\t\tcase n if n == 'a' => \"\"\n\t\t\tcase n if n == 'o' => \"\"\n\t\t\tcase n if n == 'y' => \"\"\n\t\t\tcase n if n == 'e' => \"\"\n\t\t\tcase n if n == 'u' => \"\"\n\t\t\tcase n if n == 'i' => \"\"\n\t\t\tcase n if n.isLowerCase => \".\"+n\n\t\t\tcase n if n.isUpperCase => \".\"+n.toLowerCase\n\t\t\tcase n => n\n\t\t}.foreach{\n\t\t\tprint(_)\n\t\t}\n\n\n\t}\n}\n"}, {"source_code": "/**\n * Created by mikhailvarnavskikh on 04.04.15.\n */\nobject Main {\n\n def main(args: Array[String]) {\n val std = scala.io.StdIn\n val n = std.readLine()\n val vowels = \"aoiuey\"\n val res = n.toLowerCase.filter( x => !vowels.contains( x ) ).foldLeft( \"\" )( (r, c) => r + \".\" + c )\n println( res )\n }\n\n}\n"}, {"source_code": "\nimport scala.io.StdIn\n\nobject StringTask extends App {\n\n val input = StdIn.readLine()\n print(impl(input))\n\n def impl(word: String) = {\n val wordReform = new StringBuilder\n for (char <- word) {\n val lower = char.toLower\n if (isConsonant(lower)) {\n wordReform.append(\".\").append(lower)\n }\n }\n wordReform.toString()\n }\n\n private\n def isConsonant(char: Char): Boolean = {\n char match {\n case 'a' | 'e' | 'i' | 'o' | 'u' | 'y' => false\n case _ => true\n }\n }\n}"}, {"source_code": "import scala.io.StdIn\nobject solution extends App{\n \n val text = StdIn.readLine\n val vowels = \"aeiouy\"\n \n \n val output = text.foldLeft(\"\")((a,b) => {\n val lower = b.toString.toLowerCase\n if(vowels.contains(lower)) a+\"\"\n else a +\".\"+ lower\n } )\n println(output)\n}"}, {"source_code": "\n\nobject CF118A extends App {\n import scala.io.Source\n //val src = Source.fromFile(\"data.txt\")\n val src = Source.stdin\n val lines = src.getLines\n \n def readString(): String = {\n val line = if (lines.hasNext) lines.next else null\n if (line == null) throw new RuntimeException(\"Premature end of source encountered\")\n line\n }\n \n val st = readString().toLowerCase().\n filterNot(x => x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u' || x == 'y').\n toList.map(x => s\".$x\").mkString\n \n println(st)\n \n}"}, {"source_code": "object A118 {\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 input = scala.io.StdIn.readLine\n def isVowel(char: Char) = {\n Array('A', 'E', 'I', 'O', 'U', 'Y').contains(char) || Array('A', 'E', 'I', 'O', 'U', 'Y').map(_.toLower).contains(char)\n }\n println(input\n .filter(!isVowel(_))\n .toCharArray\n .map(x => if (x.isUpper) x.toLower else x)\n .flatMap{x => Array('.', x)}.mkString(\"\"))\n }\n}"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P118A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val Vowels = List('a', 'o', 'y', 'e', 'u', 'i')\n def solve: String = \".\" + sc.nextLine.toLowerCase.filterNot(Vowels.contains(_)).mkString(\".\")\n\n out.println(solve)\n out.close\n}\n"}, {"source_code": "import java.util.Scanner\nimport scala.collection.mutable.StringBuilder\n\nobject R118_A extends App {\n val sc = new Scanner(System.in)\n\n val w = sc.nextLine()\n println(process(w))\n def process(w:String):String = {\n val nw = w.toLowerCase().replaceAll(\"[aiueoy]\", \"\")\n val b = new StringBuilder\n nw.foreach(c=>{\n b.append('.')\n b.append(c)\n })\n b.result\n }\n}"}, {"source_code": "object StringTask {\n \tdef main (args: Array[String]) {\n\t\tval scanner = new java.util.Scanner(System.in)\n\t\t\t\tval word = scanner.nextLine().toLowerCase()\n\t\t\t\tword.toCharArray()\n\t\t\t\tvar output : String = \"\"\n\t\t\t\tfor (i <- 0 to word.length()-1) {\n\t\t\t\t val current =\n\t\t\t\t word(i) match {\n\t\t\t\t case 'a' | 'e' | 'y' | 'u' | 'i' | 'o' => \"\"\n\t\t\t\t case whatever => \".\"+whatever\n\t\t\t\t }\n\t\t\t\t output = output + current\n\t\t\t\t}\n\t\t\t\tprintln(output)\n\t}\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject ScalaTest{\n def main(args: Array[String]): Unit = {\n\n val list = List('a','e','i','o','u','y')\n val input = readLine().toLowerCase.filterNot{ch =>\n list.contains(ch)\n }.mkString(\".\")\n println(\".\" + input)\n }\n}"}, {"source_code": "object A118 {\n\tdef main(args: Array[String]) = {\n\t\tval vow = List('a', 'e', 'i', 'u', 'y', 'o')\n\t\tfor (c <- readLine.toLowerCase.toCharArray)\n\t\t\tif (!vow.exists(c == _))\n\t\t\t\tprint(\".\" + c)\n\t}\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject test {\n def main(args: Array[String]): Unit = {\n val input = readLine()\n\n println(codeForees(input))\n\n }\n\n def codeForees(text: String) = {\n text.toLowerCase.filterNot (a => a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o' ||a == 'y').map(a => s\".$a\" ).mkString\n }\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject Try1 {\n def main(args: Array[String]) {\n val in = new Scanner(System.in)\n var len,x, m, k, n, j, i: Int = 0\n// var a = new Array[Int](51)\n// n = in.nextInt()\n// k = in.nextInt()\n// x=0\n var line = in.nextLine()\n val al = \"AOYEUIaeiouy\"\n val b = \"abcdefghijklmnopqrstuvwxyz\"\n n=line.length()\n for (i <- 0 until n) {\n j=0\n while (j<12 && al(j)!=line(i)) j+=1\n if (j==12) {\n print('.')\n if (line(i)>='A' && line(i)<='Z') print(b(line(i)-'A'))\n else print(line(i))\n }\n }\n }\n}"}, {"source_code": "import java.io._\n\nobject Main {\n val in = new BufferedReader(new InputStreamReader(System.in))\n def main(args: Array[String]) {\n println(in.readLine().toLowerCase().filterNot(c => \"aeiuyo\".contains(c)).map(\".\" + _).mkString)\n }\n}"}, {"source_code": "object StringTask {\n val vowels = Set('A', 'O', 'Y', 'E', 'U', 'I')\n def isVowel(c:Char) = vowels.contains(c.toUpper)\n def main(args: Array[String]): Unit = {\n val s = io.StdIn.readLine()\n var rs = \"\"\n\n for {c <- s} {\n c match {\n case _ if isVowel(c) =>\n case _ => rs += \".\" + c.toLower\n }\n }\n Console.println(rs)\n }\n}\n"}, {"source_code": "object Codeforces118A extends App{\n\n def WordConvert(word:String):String={\n val restrictedlist:String=\"aAeEiIoOuUyY\"\n var ans:Array[Char]=new Array[Char](0)\n for (i<-word){\n if (!restrictedlist.contains(i)){\n ans=ans:+'.'\n ans=ans:+i.toLower\n }\n }\n return String.valueOf(ans)\n }\n\n val s:String=scala.io.StdIn.readLine\n println(WordConvert(s))\n\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject H {\n def main(args: Array[String]): Unit = {\n// var Array(n) = StdIn.readLine().split(\" \").map(_.toInt)\n\n val pp = (s: Char) => {\n if (s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u' || s == 'y') {\n\n }\n else {\n print('.')\n print(s)\n }\n }\n\n var s = StdIn.readLine()\n for (c <- s.toLowerCase().toCharArray)\n pp(c)\n }\n}\n"}, {"source_code": "import java.io._\n\nobject Easy {\n val reader = new BufferedReader(new InputStreamReader(System.in))\n def main(args: Array[String]) {\n println(reader.readLine().toLowerCase().filterNot(c => \"aeiuyo\".contains(c)).map(\".\" + _).mkString)\n }\n}\n"}, {"source_code": "/**\n * Created by vol on 9/16/14.\n */\nobject A118 extends App{\n val vowels = List('A', 'O', 'Y', 'E', 'U', 'I')\n val str:String = readLine()\n val noVowels = str.filter((e:Char) => !vowels.contains(e.toUpper))\n\n\n println(noVowels.map((e:Char) => \".\" + e.toLower).mkString)\n\n\n}\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val str = readLine()\n val replaced = str.toLowerCase.replaceAll(\"[aoyeui]\", \"\").replaceAll(\"([^aoyeiu])\", \".$1\")\n println(replaced)\n }\n}"}, {"source_code": "object _118A extends App {\n def is_vowel(c: Char): Boolean =\n c == 'a' || c == 'o' || c == 'y' || c == 'e' || c == 'u' || c == 'i'\n\n val string = readLine()\n println(\n string.map(c => c.toLower).\n filterNot(c => is_vowel(c)).\n foldLeft(\"\")((accm, c) => accm + '.' + c))\n}\n\n\n\n"}, {"source_code": "object _118A_StringTask extends App {\n import scala.io.StdIn._\n\n val s = readLine()\n\n def solve = {\n s filterNot { c =>\n Array('a', 'o', 'y', 'e', 'u', 'i').contains(c.toLower)\n } flatMap { c =>\n \".\" + c.toLower.toString\n }\n }\n\n println(solve)\n\n}\n"}, {"source_code": "object Main extends App{\n var t = readLine().toLowerCase().replaceAll(\"[aeyuio]\",\"\")\n t.foreach( (c) => print(\".\" + c ) )\n} "}], "negative_code": [{"source_code": "import scala.io.StdIn\n\nobject Main {\n\n val vowels = Array('A', 'I', 'U', 'E', 'O', 'I')\n\n def isVowel(char: Char) : Boolean = {\n vowels contains char\n }\n\n def main(args: Array[String]): Unit = {\n val s = StdIn.readLine()\n\n println(s.map(_.toUpper).filter(!isVowel(_)).map(\".\"+ _.toLower).mkString)\n }\n}\n"}, {"source_code": "object Main extends App {\n val vowels = List('A', 'O', 'Y', 'E', 'U', 'I') ++ List('a', 'o', 'y', 'e', 'u', 'i')\n def isVowel(c: Char): Boolean = vowels exists { _ == c }\n def isConsonant(c: Char): Boolean = !isVowel(c)\n def insertDot(c: Char): String = \".\"+ c\n def solve(s: String): String = s filterNot isVowel flatMap insertDot toLowerCase\n\n assert(solve(\"tour\") == \".t.r\")\n assert(solve(\"Codeforces\") == \".c.d.f.r.c.s\")\n assert(solve(\"aBAcAba\") == \".b.c.b\")\n}\n"}, {"source_code": "object StringTask {\n val vowels = Array('a', 'e', 'i', 'o', 'u')\n\n def main(args: Array[String]) {\n val sb = new StringBuilder\n\n Console.readLine.foreach { ch =>\n val lower = ch.toLower\n if (!vowels.contains(lower)) {\n sb.append(\".\").append(lower)\n }\n }\n\n println(sb.toString)\n }\n}\n"}, {"source_code": "object test\n{\n def main(args : Array[String])\n {\n print(readLine.toLowerCase.replaceAll(\"[aeiou]\",\"\").map(\".\"+_).mkString)\n }\n}\n"}, {"source_code": "object A00118 extends App {\n println(Console.readLine().filterNot(\"aeiouAEIOU\".contains(_)).map(x => \".\" + x).map(x => x.toLowerCase()).mkString)\n}\n"}, {"source_code": "/*input\nTata\n*/\n\nimport java.util.Scanner\nimport scala.io.StdIn\n\nobject Solution {\n\tdef main(args: Array[String]): Unit = {\n\n\t\tval str = StdIn.readLine().map(_.toLower);\n\t\tstr.foreach((x: Char) => {\n\t\t\tif(!(\"aeiou\".contains(x))) {\n\t\t\t\tprint('.');\n\t\t\t\tprint(x);\n\t\t\t}\n\t\t})\n\n\t}\n\n}"}, {"source_code": "object CF118A extends App {\n import scala.io.StdIn.readLine\n import scala.collection.immutable.HashSet\n val s = readLine.toLowerCase.toCharArray\n val vowels:HashSet[Char] = HashSet('a','e','i','o','u')\n s.filter(!vowels(_)).foreach(x => print(\".\"+x.toString))\n}\n"}, {"source_code": "object StringTask extends App {\n\n\tval vowels = List(\"a\", \"o\", \"y\", \"e\", \"u\", \"i\")\n\tval input = scala.io.StdIn.readLine().toLowerCase()\n\n\tval output = input.foreach(x =>\n\t\tif (vowels.contains(x)) input.replaceAll(x.toString(), \"\")\n\t\telse input.replaceAll(x.toString(), s\"\\\\.$x\")\n\t)\n\n\tprintln(output)\n\n}"}, {"source_code": "object StringTask extends App {\n\n\t\n\tval input = scala.io.StdIn.readLine().toLowerCase()\n\n val noVowel = input.replaceAll(\"([aeiou])+\", \"\")\n val output = noVowel.map(x => s\".$x\").mkString\n \n\tprintln(output)\n\n}"}, {"source_code": "object Main extends App {\n val inputString = readLine.toList\n\n def replaceLiterals(list: List[Char]): List[Char] = list match {\n case List() => List()\n case e :: rest => \n e match {\n case 'a' | 'e' | 'i' | 'o' | 'u' | 'A' | 'E' | 'I' | 'O' | 'U' => replaceLiterals(rest)\n case _ => '.' :: e.toLower :: replaceLiterals(rest)\n } \n }\n\n println(replaceLiterals(inputString).mkString)\n}\n"}, {"source_code": "object Main extends App {\n val inputString = readLine.toList\n\n def replaceLiterals(list: List[Char]): List[Char] = list match {\n case List() => List()\n case e :: rest => \n e match {\n case 'a' | 'e' | 'i' | 'o' | 'u' | 'A' | 'E' | 'I' | 'O' | 'U' => '.' :: replaceLiterals(rest)\n case _ => e.toLower :: replaceLiterals(rest)\n } \n }\n\n println(replaceLiterals(inputString).mkString)\n}\n"}, {"source_code": "object CF0118A extends App {\n\n val gl = List(\"a\", \"o\", \"y\", \"e\", \"u\", \"i\")\n\n val str = readLine()\n\n var result = new StringBuilder\n\n for (ch <- str) {\n if (!(gl contains(ch.toString))) {\n result ++= \".\" + ch.toString.toLowerCase\n }\n }\n\n println(result)\n\n}\n"}, {"source_code": "object HelloWorld {\n def main(args: Array[String]): Unit = {\n \tvar s = readLine()\n \ts = s.replaceAll( \"[eyuioa]\", \"\") \n \tvar str = \"\"\n \tfor(i <-0 until s.length())\n \t\tstr = str + \".\" + s(i)\n \tstr = str.map(c => c.toLower)\n \tprintln(str)\n }\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject task1 {\n def main(args: Array[String]): Unit = {\n val input = readLine()\n val letters = List('A', 'O', 'Y', 'E', 'U', 'I').map(_.toLower)\n val result = input.filterNot(el2 => letters.contains(el2)).map{ el =>\n s\".$el\"\n }.mkString(\"\").toLowerCase\n println(result)\n }\n\n}\n"}, {"source_code": "object cf extends App{\n val vowels = Set('a', 'e', 'i', 'o', 'u', 'y')\n var s = readLine().toLowerCase()\n var res = \"\"\n for (i <- 0 to s.length()-1) {\n if (!vowels(s(i))) {\n res += \".\" + s(i)\n }\n }\n}"}, {"source_code": "object Solution {\n val vowels = Array(\"A\", \"O\", \"Y\", \"E\", \"U\", \"I\") map (_ charAt 0)\n def isVowel(c: Char) = vowels contains (Character.toUpperCase(c))\n def consonants(chars: Seq[Char]) = chars filter isVowel\n def withDots(chars: Seq[Char]) = chars flatMap (c => List('.', c))\n def solve(line: String) = withDots (consonants (line toLowerCase)) mkString\n def main(args: Array[String]) = println(solve(readLine))\n}"}, {"source_code": "object Solution extends App {\n val vowel = List('a', 'e', 'o', 'u', 'i')\n println(readLine().toLowerCase.filterNot(vowel.contains).mkString(\".\"))\n}"}, {"source_code": "object Solution extends App {\n val vowel = List('a', 'e', 'o', 'u', 'i')\n println(readLine().toLowerCase.filterNot(vowel.contains).mkString(\".\", \".\", \"\"))\n}"}, {"source_code": "object Main {\n\timport java.{util=>ju}\n\timport scala.annotation._\n\timport scala.collection._\n\timport scala.collection.{mutable => mu}\n\timport scala.collection.JavaConverters._\n\timport scala.math._\n\n\tdef main(args:Array[String])\n\t{\n\t\tval sc = new ju.Scanner(System.in)\n\t\tval input = sc.next();\n\n\t\tinput.map{\n\t\t\tcase n if n == 'A' => \"\"\n\t\t\tcase n if n == 'O' => \"\"\n\t\t\tcase n if n == 'Y' => \"\"\n\t\t\tcase n if n == 'E' => \"\"\n\t\t\tcase n if n == 'I' => \"\"\n\t\t\tcase n if n == 'a' => \"\"\n\t\t\tcase n if n == 'o' => \"\"\n\t\t\tcase n if n == 'y' => \"\"\n\t\t\tcase n if n == 'e' => \"\"\n\t\t\tcase n if n == 'u' => \"\"\n\t\t\tcase n if n == 'i' => \"\"\n\t\t\tcase n if n.isLowerCase => \".\"+n\n\t\t\tcase n if n.isUpperCase => \".\"+n.toLowerCase\n\t\t\tcase n => n\n\t\t}.foreach{\n\t\t\tprint(_)\n\t\t}\n\n\n\t}\n}\n"}, {"source_code": "import scala.io.StdIn\nobject solution extends App{\n \n val text = StdIn.readLine\n val vowels = \"aeiouy\"\n \n \n text.foldLeft(\"\")((a,b) => {\n val lower = b.toString.toLowerCase\n if(vowels.contains(lower)) a\n else a +\".\"+ b\n } )\n \n}"}, {"source_code": "import scala.io.StdIn\nobject solution extends App{\n \n val text = StdIn.readLine\n val vowels = \"aeiouy\"\n \n \n text.foldLeft(\"\")((a,b) => {\n val lower = b.toString.toLowerCase\n if(vowels.contains(lower)) a+\"\"\n else a +\".\"+ b\n } )\n \n}"}, {"source_code": "import scala.io.StdIn\nobject solution extends App{\n \n val text = StdIn.readLine\n val vowels = \"aeiou\"\n \n \n text.foldLeft(\"\")((a,b) => {\n val lower = b.toString.toLowerCase\n if(vowels.contains(lower)) a+\"\"\n else a +\".\"+ b\n } )\n \n}"}, {"source_code": "import scala.io.StdIn\nobject solution extends App{\n \n val text = StdIn.readLine\n val vowels = \"aeiouy\"\n \n \n val output = text.foldLeft(\"\")((a,b) => {\n val lower = b.toString.toLowerCase\n if(vowels.contains(lower)) a+\"\"\n else a +\".\"+ b\n } )\n \n println(output)\n \n}"}, {"source_code": "import scala.io.StdIn\nobject solution extends App{\n \n val text = StdIn.readLine\n val vowels = \"aeiouy\"\n \n \n text.foldLeft(\"\")((a,b) => {\n val lower = b.toString.toLowerCase\n if(vowels.contains(lower)) a+\"\"\n else a +\".\"+ lower\n } )\n \n}"}, {"source_code": "import scala.io.StdIn._\n\nobject ScalaTest{\n def main(args: Array[String]): Unit = {\n\n val list = List('a','e','i','o','u')\n val input = readLine().toLowerCase.filterNot{ch =>\n list.contains(ch)\n }.mkString(\".\")\n println(\".\" + input)\n }\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject ScalaTest{\n def main(args: Array[String]): Unit = {\n\n val list = List('A','a','E','e','I','i','O','o','U','u')\n val input = readLine().filterNot{ch =>\n list.contains(ch)\n }.mkString(\".\")\n println(\".\" + input)\n }\n}"}, {"source_code": "import scala.io.StdIn\n\nobject H {\n def main(args: Array[String]): Unit = {\n// var Array(n) = StdIn.readLine().split(\" \").map(_.toInt)\n\n val pp = (s: Char) => {\n if (s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u') {\n\n }\n else {\n print('.')\n print(s)\n }\n }\n\n var s = StdIn.readLine()\n for (c <- s.toLowerCase().toCharArray)\n pp(c)\n }\n}\n"}], "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b"} {"nl": {"description": "Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators (https://en.wikipedia.org/wiki/Seven-segment_display). Max starts to type all the values from a to b. After typing each number Max resets the calculator. Find the total number of segments printed on the calculator.For example if a = 1 and b = 3 then at first the calculator will print 2 segments, then — 5 segments and at last it will print 5 segments. So the total number of printed segments is 12.", "input_spec": "The only line contains two integers a, b (1 ≤ a ≤ b ≤ 106) — the first and the last number typed by Max.", "output_spec": "Print the only integer a — the total number of printed segments.", "sample_inputs": ["1 3", "10 15"], "sample_outputs": ["12", "39"], "notes": null}, "positive_code": [{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val map = Map('0' -> 6, '1' -> 2, '2' -> 5, '3' -> 5, '4' -> 4, '5' -> 5, '6' -> 6, '7' -> 3, '8' -> 7, '9' -> 6)\n\n val in = Source.stdin.getLines()\n val Array(a, b) = in.next().split(' ').map(_.toInt)\n println((a to b).foldLeft(0l) {\n case (acc, i) => acc + i.toString.map(map).sum\n })\n}"}, {"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 @inline def segments(a: Int): Int = {\n val s = Array(6, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n var n = a\n var res = 0\n while (n > 0) {\n res += s(n%10)\n n /= 10\n }\n res\n }\n def main(args: Array[String]) {\n val Array(a, b) = readInts(2)\n\n println((a to b).foldLeft(0)( _ + segments(_)))\n\n\n// Console.withOut(new java.io.BufferedOutputStream(Console.out))\n// println(res.mkString(\"\\n\"))\n// Console.flush\n }\n}"}, {"source_code": "import scala.math._\nimport scala.Console\nobject Object {\n \n def main(args : Array[String]){\n \n val Array(a, b) = readLine.split(\" \").map{_.toInt }\n var tl = 0\n \n for(i <- a to b){\n val li = i.toString.map(_.asDigit)\n li.map { i => i match{\n case 1 => tl += 2\n case 2|3|5 => tl += 5\n case 6|9|0 => tl += 6\n case 4 => tl += 4\n case 7 => tl += 3\n case 8 => tl += 7\n }\n }\n }\n println(tl)\n }\n}"}, {"source_code": "import io.StdIn._\nimport scala.collection.mutable._\n\nobject Solution extends App {\n val nks = readLine().split(\" \")\n val nk = nks.map(_.toInt)\n val TempArr = Array( 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ) \n \n val a = nk(0)\n val b = nk(1)\n var ans = 0\n \n for ( i <- a to b ) {\n \n var temp = i\n \n while ( temp != 0 ) {\n ans = ans + TempArr( temp % 10 ) \n temp = temp / 10\n }\n \n }\n \n \n \n println ( ans ) \n \n \n}"}], "negative_code": [{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val map = Map('0' -> 6, '1' -> 2, '2' -> 5, '3' -> 5, '4' -> 4, '5' -> 5, '6' -> 6, '7' -> 3, '8' -> 7, '9' -> 6)\n\n val in = Source.stdin.getLines()\n val Array(a, b) = in.next().split(' ').map(_.toInt)\n (a to b).foldLeft(0l) {\n case (acc, i) => acc + i.toString.map(map).sum\n }\n}"}], "src_uid": "1193de6f80a9feee8522a404d16425b9"} {"nl": {"description": "Jzzhu has invented a kind of sequences, they meet the following property:You are given x and y, please calculate fn modulo 1000000007 (109 + 7).", "input_spec": "The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).", "output_spec": "Output a single integer representing fn modulo 1000000007 (109 + 7).", "sample_inputs": ["2 3\n3", "0 -1\n2"], "sample_outputs": ["1", "1000000006"], "notes": "NoteIn the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.In the second sample, f2 =  - 1;  - 1 modulo (109 + 7) equals (109 + 6)."}, "positive_code": [{"source_code": "\n\nimport java.io.PrintWriter\nimport java.util.Scanner\n\n/**\n * Created by arseny on 19.07.14.\n */\nobject B 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 x = nextLong\n val y = nextLong\n val p: Long = 1000 * 1000 * 1000 + 7\n val n = nextLong % 6\n val ans: Long = n match {\n case 0 => x - y\n case 1 => x\n case 2 => y\n case 3 => y - x\n case 4 => -x\n case 5 => - y\n }\n out.println((ans + 3 * p) % p)\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"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val Array(x, y) = in.next().split(\" \").map(_.toInt)\n val mod = 1000000007\n val n = (in.next().toInt - 1) % 6\n val k = n % 3\n val res = k match {\n case 0 => x\n case 1 => y\n case 2 => y - x\n }\n\n if (n < 3) println((res % mod + mod) % mod) else {\n println((-res % mod + mod) % mod)\n }\n}"}, {"source_code": "import java.util.Scanner\n\n/**\n * Created by kshim on 25/07/2014.\n */\nobject CF257B extends App {\n def Process(x:Long, y:Long, n:Long):Long = {\n val fn:Long = (n-1) % 6 match {\n case 0 => x\n case 1 => y\n case 2 => y - x\n case 3 => -x\n case 4 => -y\n case 5 => -y + x\n }\n val r = fn % (1000000000L + 7L)\n if(r < 0) {\n r + (1000000000L + 7L)\n } else {\n r\n }\n }\n val in = new Scanner(System.in)\n val x = in.nextInt()\n val y = in.nextInt()\n val n = in.nextInt()\n println(Process(x, y, n))\n}\n"}, {"source_code": "object B450 {\n\n import IO._\n import collection.{mutable => cu}\n val MOD = 1000000007L\n def main(args: Array[String]): Unit = {\n val Array(x, y) = readLongs(2)\n val a = Array(x, y, y-x,-x,-y,x-y).map(x => (x + 2*MOD)% MOD)\n val Array(n) = readInts(1)\n println(a((n-1)%6))\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"}, {"source_code": "object Sequences {\n\n def splitter(as: String) = as.split(\"\\\\s+\") match {\n case Array(n, m) => List(n.toLong, m.toLong)\n }\n\n def solve(x: Long, y: Long, n: Long): Long = (n % 6) match {\n case 1 => x\n case 2 => y\n case 3 => y-x\n case 4 => -x\n case 5 => -y\n case 0 => x-y\n }\n\n def main(args: Array[String]) {\n val N = 1e9.toLong + 7\n val List(xyStr, nStr) = io.Source.stdin.getLines.take(2).toList\n val List(x, y) = splitter(xyStr)\n val n = nStr.toLong\n val f = solve(x, y, n)\n val fModN = f % N\n val res: Long = if (fModN>=0) fModN else fModN + N\n println(res)\n }\n}\n\n"}, {"source_code": "/**\n * @author Oleg Arshinsky\n */\nobject B extends App {{\n\n val Array(x, y) = readLine().split(\" \").map(_.toInt)\n val n = readLine().toInt\n\n def _1 = x\n def _2 = y\n def _3 = y-x\n def _4 = -x\n def _5 = -y\n def _6 = x-y\n\n val functions = Array(_1, _2, _3, _4, _5, _6)\n\n val intermediate = n % 6\n\n val function_n = if (intermediate == 0) 6-1 else intermediate-1\n\n val f_n = functions(function_n)\n\n val a = f_n\n val b = 1000000007\n\n println((a - (a.toDouble/b).floor * b).toInt)\n\n\n\n}}\n"}, {"source_code": "object Main {\n def main(args: Array[String]): Unit = {\n val N = 1000000007\n val halfN = 500000003\n val xy = io.StdIn.readLine().split(\" \").map { s =>\n val i = Integer.parseInt(s)\n if (i < 0 ) i + N else i\n }\n val n = (io.StdIn.readInt() -1) % 6\n def compute(k: Int): Long = {\n if (k > 2) -1 * compute(k - 3)\n else if (k ==2) xy(1) - xy(0)\n else xy(k)\n }\n val fn = compute(n) % N\n println(if (fn < 0) fn + N else fn)\n }\n}"}, {"source_code": "import scala.math.BigInt\n\nobject Main extends App {\n val sc = new java.util.Scanner(System.in)\n val x, y, n = sc.nextInt\n\n def solve( x: Int, y: Int, n: Int ): Int = {\n val M: Int = 1e9.toInt + 7\n\n val newN = (n-1) % 6\n\n def tail(a: BigInt, b: BigInt): Stream[BigInt] = a #:: tail(b, b - a)\n val res = tail(x, y)(newN)\n ( ( ( res % M ) + M ) mod M ).toInt\n }\n\n println( solve( x, y, n ) )\n}\n"}, {"source_code": "import scala.math.BigInt\n\nobject Main extends App {\n val sc = new java.util.Scanner(System.in)\n val x, y, n = sc.nextInt\n\n def solve2( x: Int, y: Int, n: Int ): Int = {\n val M: Int = 1e9.toInt + 7\n\n val newN = (n-1) % 6\n\n def tail(a: BigInt, b: BigInt): Stream[BigInt] = a #:: tail(b, b - a)\n val res = tail(x, y)(newN)\n ( ( ( res % M ) + M ) mod M ).toInt\n }\n\n def solve( x: Int, y: Int, n: Int ): Int = {\n val M: Int = 1e9.toInt + 7\n\n val newN = (n-1) % 6\n\n var memo = new Array[Int](6)\n memo(0) = x\n memo(1) = y\n for( i <- (2 until 6) ) {\n memo(i) = ( memo(i-1) - memo(i-2) ) % M\n }\n\n ( ( memo(newN) % M ) + M ) % M\n }\n\n println( solve( x, y, n ) )\n}\n"}, {"source_code": "object HelloWorld{\n def computeSeq(x: Int, y:Int, l:Int):List[Int] = l match {\n case 0 => List()\n case _ => (y-x)::computeSeq(y, y-x, l-1)\n }\n def main(args: Array[String]){\n val in = new java.util.Scanner(System.in)\n val x = in.nextInt\n val y = in.nextInt\n val n = in.nextInt-1\n val seq = x::y::computeSeq(x, y, 4)\n println(floorMod(1000*1000*1000+7)(seq(n%6)))\n }\n def floorMod(m: Int)(n: Int) = (((n % m) + m) % m)\n}"}], "negative_code": [{"source_code": "import java.util.Scanner\n\n/**\n * Created by kshim on 25/07/2014.\n */\nobject CF257B extends App {\n def Process(x:Long, y:Long, n:Long):Long = {\n val fn:Long = (n-1) % 6 match {\n case 0 => x\n case 1 => y\n case 2 => y - x\n case 3 => -x\n case 4 => -y\n case 5 => -y + x\n }\n if(fn < 0) {\n (fn % (1000000000L + 7L)) + (1000000000L + 7L)\n } else {\n fn % (1000000000L + 7L)\n }\n }\n val in = new Scanner(System.in)\n val x = in.nextInt()\n val y = in.nextInt()\n val n = in.nextInt()\n println(Process(x, y, n))\n}\n"}, {"source_code": "object B450 {\n\n import IO._\n import collection.{mutable => cu}\n val MOD = 100000007L\n def main(args: Array[String]): Unit = {\n val Array(x, y) = readLongs(2)\n val a = Array(x, y, y-x,-x,-y,x-y).map(x => (x + 2*MOD)% MOD)\n val Array(n) = readInts(1)\n println(a((n-1)%6))\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"}, {"source_code": "object Sequences {\n\n def splitter(as: String) = as.split(\"\\\\s+\") match {\n case Array(n, m) => List(n.toLong, m.toLong)\n }\n\n def solve(x: Long, y: Long, n: Long): Long = (n % 6) match {\n case 1 => x\n case 2 => y\n case 3 => y-x\n case 4 => -x\n case 5 => -y\n case 0 => x-y\n }\n\n def main(args: Array[String]) {\n val N = 1e9.toLong + 7\n val List(xyStr, nStr) = io.Source.stdin.getLines.take(2).toList\n val List(x, y) = splitter(xyStr)\n val n = nStr.toLong\n val f = solve(x, y, n)\n val res: Long = if (f>=0) f % N else (f + N) % N\n println(res)\n }\n}\n\n"}, {"source_code": "object Sequences {\n\n def splitter(as: String) = as.split(\"\\\\s+\") match {\n case Array(n, m) => List(n.toLong, m.toLong)\n }\n\n def solve(x: Long, y: Long, n: Long): Long = (n % 6) match {\n case 1 => x\n case 2 => y\n case 3 => y-x\n case 4 => -x\n case 5 => -y\n case 0 => x-y\n }\n\n def main(args: Array[String]) {\n val N = 1e9.toLong + 7\n val List(xyStr, nStr) = io.Source.stdin.getLines.take(2).toList\n val List(x, y) = splitter(xyStr)\n val n = nStr.toLong\n val f = solve(x, y, n)\n val res: Long = if (f>=0) f % N else (f % N) + N\n println(res)\n }\n}\n\n"}, {"source_code": "object Main {\n def main(args: Array[String]): Unit = {\n val N = 1000000007\n val halfN = 500000003\n val xy = io.StdIn.readLine().split(\" \").map { s =>\n val i = Integer.parseInt(s)\n if (i > halfN) i - N else i\n }\n val n = (io.StdIn.readInt() -1) % 6\n def compute(k: Int): Long = {\n if (k > 2) -1 * compute(5 - k)\n else if (k == 0) xy(0)\n else if (k == 1) xy(1)\n else xy(1) - xy(0)\n }\n val fn = compute(n) % N\n println(if (fn < 0) fn + N else fn)\n }\n}"}, {"source_code": "object Main {\n def main(args: Array[String]): Unit = {\n val N = 1000000007\n val halfN = 500000003\n val xy = io.StdIn.readLine().split(\" \").map { s =>\n val i = Integer.parseInt(s)\n if (i > halfN) i - N else i\n }\n val n = io.StdIn.readLong()\n val fn = (xy(1) - ((n - 2) % N) * xy(0)) % N\n println(if (fn < 0) fn + N else fn)\n }\n}"}, {"source_code": "import scala.math.BigInt\n\nobject Main extends App {\n val sc = new java.util.Scanner(System.in)\n val x, y, n = sc.nextInt\n\n def solve( x: Int, y: Int, n: Int ): Int = {\n val M: Int = 1e9.toInt + 7\n\n val newN = (n-1) % 6\n\n def tail(a: BigInt, b: BigInt): Stream[BigInt] = a #:: tail(b, b - a)\n val res = tail(x, y)(newN-1)\n ( ( ( res % M ) + M ) mod M ).toInt\n }\n\n println( solve( x, y, n ) )\n}\n"}, {"source_code": "import scala.math.BigInt\n\nobject Main extends App {\n val sc = new java.util.Scanner(System.in)\n val x, y, n = sc.nextInt\n\n def solve( x: Int, y: Int, n: Int ): Int = {\n val M: Int = 1e9.toInt + 7\n\n val newN = (n-1) % 6\n\n def tail(a: BigInt, b: BigInt): Stream[BigInt] = a #:: tail(b, b - a)\n val res = tail(x, y)(newN)\n ( ( ( res % M ) + M ) mod M ).toInt\n }\n\n def solve2( x: Int, y: Int, n: Int ): Int = {\n val M: Int = 1e9.toInt + 7\n\n val newN = (n-1) % 6\n\n var memo = new Array[Int](6)\n memo(0) = x\n memo(1) = y\n for( i <- (2 until 6) ) {\n memo(i) = ( ( ( memo(i-1) + memo(i-2) ) % M ) + M ) % M\n }\n\n memo(newN)\n }\n\n println( solve2( x, y, n ) )\n}\n"}, {"source_code": "import scala.math.BigInt\n\nobject Main extends App {\n val sc = new java.util.Scanner(System.in)\n val x, y, n = sc.nextInt\n\n def solve( x: Int, y: Int, n: Int ): Int = {\n val M: Int = 1e9.toInt + 7\n\n val newN = (n-1) % 6\n\n def tail(a: BigInt, b: BigInt): Stream[BigInt] = a #:: tail(b, b - a)\n val res = tail(x, y)(newN)\n ( ( ( res % M ) + M ) mod M ).toInt\n }\n\n def solve2( x: Int, y: Int, n: Int ): Int = {\n val M: Int = 1e9.toInt + 7\n\n val newN = (n-1) % 6\n\n var memo = new Array[Int](6)\n memo(0) = x\n memo(1) = y\n for( i <- (2 until 6) ) {\n memo(i) = ( ( ( memo(i-1) - memo(i-2) ) % M ) + M ) % M\n }\n\n memo(newN)\n }\n\n println( solve2( x, y, n ) )\n}\n"}], "src_uid": "2ff85140e3f19c90e587ce459d64338b"} {"nl": {"description": "Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.", "input_spec": "The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.", "output_spec": "Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». ", "sample_inputs": ["4 2"], "sample_outputs": ["1/2"], "notes": "NoteDot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points."}, "positive_code": [{"source_code": "import java.util.StringTokenizer\n\nobject _9A extends App {\n var token = new StringTokenizer(\"\")\n def next = {\n while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)\n token.nextToken()\n }\n val cb = 7 - (next.toInt max next.toInt)\n if (cb == 0) println(\"0/1\")\n else if (cb == 1) println(\"1/6\")\n else if (cb == 2) println(\"1/3\")\n else if (cb == 3) println(\"1/2\")\n else if (cb == 4) println(\"2/3\")\n else if (cb == 5) println(\"5/6\")\n else println(\"1/1\")\n}\n"}, {"source_code": "//package me.jetblack.cf\n\nimport java.util.Scanner\n\nobject DiceRoll extends App {\n\n val s = new Scanner(System.in)\n\n val y = s.nextInt()\n val w = s.nextInt()\n\n val t = 6 - (math.max(y, w) - 1)\n if (t == 4) {\n println(\"2/3\")\n } else if (t == 3) {\n println(\"1/2\")\n } else if (t == 2) {\n println(\"1/3\")\n } else if (t == 6) {\n println(\"1/1\")\n } else {\n println(s\"$t/6\")\n }\n\n}\n"}, {"source_code": "object A9 {\n\n import IO._\n\n def main(args: Array[String]): Unit = {\n val score = readInts(2)\n val max = score.max\n val ans = Array(\"0/1\", \"1/1\", \"5/6\", \"2/3\", \"1/2\", \"1/3\", \"1/6\")\n println(ans(max))\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"}, {"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\n\nobject P009A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n def solve(): String = {\n val target: Int = List.fill(2)(sc.nextInt).max\n List(\"dummy\", \"1/1\", \"5/6\", \"2/3\", \"1/2\", \"1/3\", \"1/6\")(target)\n }\n \n out.println(solve)\n out.close\n}\n"}, {"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 solve = {\n val y = nextInt\n val w = nextInt\n val x = 6 - Math.max(y, w) + 1\n if (x % 6 == 0) {\n out.println(x / 6 + \"/\" + 1)\n } else if (x % 3 == 0) {\n out.println(x / 3 + \"/\" + 2)\n } else if (x % 2 == 0) {\n out.println(x / 2 + \"/\" + 3)\n } else {\n out.println(x + \"/\" + 6)\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}"}, {"source_code": "//package me.jetblack.cf\n\nimport java.util.Scanner\n\nobject DiceRoll extends App {\n\n val s = new Scanner(System.in)\n\n val y = s.nextInt()\n val w = s.nextInt()\n\n val t = 6 - (math.max(y, w) - 1)\n if (t == 4) {\n println(\"2/3\")\n } else if (t == 3) {\n println(\"1/2\")\n } else if (t == 2) {\n println(\"1/3\")\n } else if (t == 6) {\n println(\"1/1\")\n } else {\n println(s\"$t/6\")\n }\n\n}"}, {"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(y, w) = readLine.split(\" \").map(_.toInt);\n var max = math.max(y, w);\n if (max == 1) {\n println(\"1/1\");\n } else if (max == 2) {\n println(\"5/6\");\n } else if (max == 3) {\n println(\"2/3\");\n } else if (max == 4) {\n println(\"1/2\");\n } else if (max == 5) {\n println(\"1/3\");\n } else {\n println(\"1/6\");\n }\n }\n\n}"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val max = readLine.split(\" \").map(_.toInt).max\n max match {\n case 1 => println(\"1/1\")\n case 2 => println(\"5/6\")\n case 3 => println(\"2/3\")\n case 4 => println(\"1/2\")\n case 5 => println(\"1/3\")\n case 6 => println(\"1/6\")\n case _ => // to make scalac happy\n }\n }\n}"}, {"source_code": "object P9A {\n import io.StdIn._\n\n def main(args:Array[String]) {\n println(readLine.split(' ').map{_.toInt}.max match {\n case 1 => \"1/1\"\n case 2 => \"5/6\"\n case 3 => \"2/3\"\n case 4 => \"1/2\"\n case 5 => \"1/3\"\n case 6 => \"1/6\"\n })\n }\n}\n"}, {"source_code": "//package me.jetblack.cf\n\nimport java.util.Scanner\n\nobject DiceRoll extends App {\n\n val s = new Scanner(System.in)\n\n val y = s.nextInt()\n val w = s.nextInt()\n\n val t = 6 - (math.max(y, w) - 1)\n if (t == 4) {\n println(\"2/3\")\n } else if (t == 3) {\n println(\"1/2\")\n } else if (t == 2) {\n println(\"1/3\")\n } else if (t == 6) {\n println(\"1/1\")\n } else {\n println(s\"$t/6\")\n }\n\n}"}, {"source_code": "object dieroll extends App {\n val Array(a, b) = readLine split ' ' map (_.toInt)\n\n @scala.annotation.tailrec def gcd(a: Int, b: Int): Int = b match {\n case 0 => a\n case _ => gcd(b, a % b)\n }\n\n val total = 7 - math.max(a, b)\n val g = gcd(total, 6)\n\n println(s\"${total/g}/${6/g}\")\n}\n"}], "negative_code": [{"source_code": "import java.util.StringTokenizer\n\nobject _9A extends App {\n var token = new StringTokenizer(\"\")\n def next = {\n while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)\n token.nextToken()\n }\n val cb = 6 - next.toInt max next.toInt + 1\n if (cb == 0) println(\"0/1\")\n else if (cb == 1) println(\"1/6\")\n else if (cb == 2) println(\"1/3\")\n else if (cb == 3) println(\"1/2\")\n else if (cb == 4) println(\"2/3\")\n else if (cb == 5) println(\"5/6\")\n else println(\"1/1\")\n}\n"}, {"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 solve = {\n val y = nextInt\n val w = nextInt\n val x = 6 - Math.max(y, w) + 1\n if (x % 2 == 0) {\n out.println(x / 2 + \"/\" + 3)\n } else if (x % 3 == 0) {\n out.println(x / 3 + \"/\" + 2)\n } else if (x % 6 == 0) {\n out.println(x / 6 + \"/\" + 1)\n } else {\n out.println(x / 6)\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"}, {"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 solve = {\n val y = nextInt\n val w = nextInt\n val x = 6 - Math.max(y, w) + 1\n if (x % 2 == 0) {\n out.println(x / 2 + \"/\" + 3)\n } else if (x % 3 == 0) {\n out.println(x / 3 + \"/\" + 2)\n } else if (x % 6 == 0) {\n out.println(x / 6 + \"/\" + 1)\n } else {\n out.println(x + \"/\" + 6)\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"}, {"source_code": "object P9A {\n import io.StdIn._\n\n def main(args:Array[String]) {\n println(readLine.split(' ').map{_.toInt}.max match {\n case 1 => \"1/0\"\n case 2 => \"5/6\"\n case 3 => \"2/3\"\n case 4 => \"1/2\"\n case 5 => \"1/3\"\n case 6 => \"1/6\"\n })\n }\n}\n"}], "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414"} {"nl": {"description": "Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allowed to break the sticks or use their partial length. Anne has perfectly solved this task, now she is asking Johnny to do the same.The boy answered that he would cope with it without any difficulty. However, after a while he found out that different tricky things can occur. It can happen that it is impossible to construct a triangle of a positive area, but it is possible to construct a degenerate triangle. It can be so, that it is impossible to construct a degenerate triangle even. As Johnny is very lazy, he does not want to consider such a big amount of cases, he asks you to help him.", "input_spec": "The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.", "output_spec": "Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the sticks or use their partial length.", "sample_inputs": ["4 2 1 3", "7 2 2 4", "3 5 9 1"], "sample_outputs": ["TRIANGLE", "SEGMENT", "IMPOSSIBLE"], "notes": null}, "positive_code": [{"source_code": "object P6A {\n def main(args : Array[String]) {\n val a = readLine split ' ' map {_.toInt}\n val answer = () match {\n case _ if (a combinations 3) exists {\n case Array(u, v, w) => u + v > w && v + w > u && w + u > v\n } => \"TRIANGLE\"\n case _ if (a combinations 3) exists {\n case Array(u, v, w) => u + v >= w && v + w >= u && w + u >= v\n } => \"SEGMENT\"\n case _ => \"IMPOSSIBLE\"\n }\n println(answer)\n }\n}"}, {"source_code": "object Solution6A extends Application {\n\n def isTriangle(a: Int, b: Int, c: Int): Boolean = a + b > c && a + c > b && b + c > a\n\n def isSegment(a: Int, b: Int, c: Int): Boolean = a + b == c || a + c == b || b + c == a\n\n def solution() {\n val a1 = _int\n val a2 = _int\n val a3 = _int\n val a4 = _int\n\n if (isTriangle(a1, a2, a3)) {\n println(\"TRIANGLE\")\n return\n }\n if (isTriangle(a1, a2, a4)) {\n println(\"TRIANGLE\")\n return\n }\n if (isTriangle(a1, a4, a3)) {\n println(\"TRIANGLE\")\n return\n }\n if (isTriangle(a4, a2, a3)) {\n println(\"TRIANGLE\")\n return\n }\n\n\n if (isSegment(a1, a2, a3)) {\n println(\"SEGMENT\")\n return\n }\n if (isSegment(a1, a2, a4)) {\n println(\"SEGMENT\")\n return\n }\n if (isSegment(a1, a4, a3)) {\n println(\"SEGMENT\")\n return\n }\n if (isSegment(a4, a2, a3)) {\n println(\"SEGMENT\")\n return\n }\n\n println(\"IMPOSSIBLE\")\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}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n var data = in.next().split(\" \").map(_.toInt).toList.sorted\n\n def triangle(list: Seq[Int]): Int = {\n val sorted = list.sorted\n if (sorted(0) + sorted(1) == sorted(2)) 1\n else if (sorted(0) + sorted(1) > sorted(2)) 2\n else 0\n }\n\n val max = data.combinations(3).map(triangle).max\n if (max == 2)\n println(\"TRIANGLE\")\n else if (max == 1)\n println(\"SEGMENT\")\n else\n println(\"IMPOSSIBLE\")\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject ATriangle extends App {\n\n val scanner = new Scanner(System.in)\n\n val in = (0 until 4).map(i => scanner.nextInt().toDouble)\n\n val res = (0 until 4).foldLeft(\"IMPOSSIBLE\")((r: String, c: Int) =>\n r match {\n case \"TRIANGLE\" => \"TRIANGLE\"\n case t if t ==\"IMPOSSIBLE\" || t == \"SEGMENT\" =>\n val s = co(in.remove(c).toList)\n if (math.abs(s) == 1.0) \"SEGMENT\"\n else if (t == \"SEGMENT\" && math.abs(s) > 1.0) \"SEGMENT\"\n else if (math.abs(s) < 1.0) \"TRIANGLE\"\n else \"IMPOSSIBLE\"\n\n }\n )\n\n println(res)\n\n implicit class ListExt[T](src: Seq[T]) {\n def remove(idx: Int): Seq[T] = src.take(idx) ++ src.drop(idx + 1)\n }\n\n\n def co(a:List[Double]): Double = (math.pow(a(0), 2) + math.pow(a(1), 2) - math.pow(a(2), 2)) / (2 * a(0) * a(1))\n\n\n}\n"}, {"source_code": "object A6 {\n\n import IO._\n import collection.{mutable => cu}\n\n def main(args: Array[String]): Unit = {\n val in = readInts(4)\n val tri = in.permutations.exists{ arr =>\n val t = arr.take(3)\n arr(0)+arr(1) > arr(2) && arr(1)+arr(2) > arr(0) && arr(0)+arr(2) > arr(1)\n }\n if(tri) {\n println(\"TRIANGLE\")\n } else {\n val deg = in.permutations.exists{ arr =>\n val t = arr.take(3)\n arr(0)+arr(1) >= arr(2) && arr(1)+arr(2) >= arr(0) && arr(0)+arr(2) >= arr(1)\n }\n if(deg) {\n println(\"SEGMENT\")\n } else {\n println(\"IMPOSSIBLE\")\n }\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"}, {"source_code": "import java.util.Scanner\nimport scala.util.Sorting.quickSort\nimport scala.math.max;\n\nobject Main {\n\n val TRIANGLE = 2\n val SEGMENT = 1\n val IMPOSSIBLE = 0\n val map = Array(\"IMPOSSIBLE\", \"SEGMENT\", \"TRIANGLE\")\n\n def main(args: Array[String]) {\n val in = new Scanner(System.in)\n def next = in.next.toInt\n\n println(map(canMakeTriangle(Array(next, next, next, next))))\n }\n\n def canMakeTriangle(sides: Array[Int]): Int = {\n quickSort(sides)\n max(classifyTriangle(sides(0), sides(1), sides(2)), classifyTriangle(sides(1), sides(2), sides(3)))\n }\n\n def classifyTriangle(s0: Int, s1: Int, s2: Int) = {\n val s = s0 + s1;\n if (s < s2) IMPOSSIBLE\n else if (s == s2) SEGMENT\n else TRIANGLE\n }\n}\n"}, {"source_code": "\n/**\n * Created by yangchaozhong on 3/10/15.\n */\nobject CF6A extends App {\n import java.util.{Scanner}\n import java.io.{PrintWriter}\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 def nextLine = in.nextLine\n\n def solve = {\n val lines = Array.ofDim[Int](4)\n\n (0 until 4).foreach { i =>\n lines(i) = nextInt\n }\n\n val combinations = lines.combinations(3)\n var c1 = 0\n var c2 = 0\n combinations.foreach { arr =>\n val sortedArr = arr.sortWith(_ > _)\n if (sortedArr(1) + sortedArr(2) > sortedArr(0)) {\n c1 += 1\n } else if (sortedArr(1) + sortedArr(2) == sortedArr(0)) {\n c2 += 1\n }\n }\n\n if (c1 > 0) {\n out.println(\"TRIANGLE\")\n } else if (c2 > 0) {\n out.println(\"SEGMENT\")\n } else {\n out.println(\"IMPOSSIBLE\")\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"}, {"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 P006A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val f: PartialFunction[List[Int], String] = {\n case List(p, q, r, s) if p + q > r || q + r > s => \"TRIANGLE\"\n case List(p, q, r, s) if p + q == r || q + r == s => \"SEGMENT\"\n case _ => \"IMPOSSIBLE\"\n }\n val res: String = f(List.fill(4)(sc.nextInt).sorted)\n \n out.println(res)\n out.close\n}\n\n\n\n\n\n"}, {"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 solve = {\n val len = new Array[Int](4)\n for (i <- 0 until 4) {\n len(i) = nextInt\n }\n var flag = false\n for (i <- 0 until 4) {\n for (j <- 0 until 4) {\n for (k <- 0 until 4) {\n if (i != j && j != k && i != k) {\n if (len(i) < len(j) + len(k) &&\n len(j) < len(i) + len(k) &&\n len(k) < len(j) + len(i) && !flag) {\n out.println(\"TRIANGLE\")\n flag = true\n }\n }\n }\n }\n }\n if (!flag) {\n for (i <- 0 until 4) {\n for (j <- 0 until 4) {\n for (k <- 0 until 4) {\n if (i != j && j != k && i != k) {\n if ((len(i) <= len(j) + len(k) &&\n len(j) <= len(i) + len(k) &&\n len(k) <= len(j) + len(i)) && !flag) {\n out.println(\"SEGMENT\")\n flag = true\n }\n }\n }\n }\n }\n }\n if (!flag) {\n out.println(\"IMPOSSIBLE\")\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"}, {"source_code": "object P6A {\n def main(args : Array[String]) {\n val a = readLine split ' ' map {_.toInt}\n val answer = () match {\n case _ if (a combinations 3) exists {\n case Array(u, v, w) => u + v > w && v + w > u && w + u > v\n } => \"TRIANGLE\"\n case _ if (a combinations 3) exists {\n case Array(u, v, w) => u + v >= w && v + w >= u && w + u >= v\n } => \"SEGMENT\"\n case _ => \"IMPOSSIBLE\"\n }\n println(answer)\n }\n}"}, {"source_code": "import scala.io._\nimport scala.collection.mutable._\n\nobject HelloWorld {\n def main(args: Array[String]) = {\n var arr = readLine.split(\" \").map(_.toInt);\n var result = 0;\n val buffer = ArrayBuffer[Int](arr(0), arr(1), arr(2), arr(3)).sorted;\n for (i <- 0 until buffer.length) {\n val temp = buffer.clone;\n temp.remove(i);\n if (temp(0) + temp(1) > temp(2)) {\n result = math.max(result, 2);\n } else if (temp(0) + temp(1) == temp(2)) {\n result = math.max(result, 1);\n } else {\n result = math.max(result, 0);\n }\n }\n if (result == 0) {\n println(\"IMPOSSIBLE\");\n } else if (result ==1) {\n println(\"SEGMENT\");\n } else {\n println(\"TRIANGLE\");\n }\n }\n\n}"}, {"source_code": "import scala.io._\nimport scala.collection.mutable._\n\nobject HelloWorld {\n def main(args: Array[String]) = {\n var arr = readLine.split(\" \").map(_.toInt);\n val list = List(arr(0), arr(1), arr(2), arr(3)).sorted;\n var result = 0;\n val buffer = ArrayBuffer[Int](arr(0), arr(1), arr(2), arr(3)).sorted;\n for (i <- 0 until buffer.length) {\n val temp = buffer.clone;\n temp.remove(i);\n// println(\"LIST_LENGTH = \" + buffer.length);\n// println(\"TEMP = \" + temp.toString);\n// println(\"LIST = \" + buffer.toString);\n if (temp(0) + temp(1) > temp(2)) {\n result = math.max(result, 2);\n } else if (temp(0) + temp(1) == temp(2)) {\n \tresult = math.max(result, 1);\n } else {\n result = math.max(result, 0);\n }\n }\n if (result == 0) {\n println(\"IMPOSSIBLE\");\n } else if (result ==1) {\n println(\"SEGMENT\");\n } else {\n println(\"TRIANGLE\");\n }\n }\n\n}"}, {"source_code": "object Main { \n def main(args: Array[String]) {\n val a = readLine().split(\" \").map(_.toInt).sorted\n \n var traingle = false\n var segment = false\n for{\n i <- 0 to 3\n j <- i + 1 to 3\n k <- j + 1 to 3 \n } {\n if (a(i) + a(j) > a(k)) traingle = true\n else if (a(i) + a(j) == a(k)) segment = true\n }\n if (traingle ) println(\"TRIANGLE\")\n else if (segment) println(\"SEGMENT\")\n else println(\"IMPOSSIBLE\")\n }\n}"}, {"source_code": "object Main{\n def main(args: Array[String]) {\n def solve(list: List[Int]): String ={\n\n (list(0), list(1), list(2), list(3)) match {\n case _ if list(0) + list(1) > list(2) => \"TRIANGLE\"\n case _ if list(0) + list(1) > list(3) => \"TRIANGLE\"\n case _ if list(0) + list(2) > list(3) => \"TRIANGLE\"\n case _ if list(1) + list(2) > list(3) => \"TRIANGLE\"\n\n case _ if list(0) + list(1) == list(2) => \"SEGMENT\"\n case _ if list(0) + list(1) == list(3) => \"SEGMENT\"\n case _ if list(0) + list(2) == list(3) => \"SEGMENT\"\n case _ if list(1) + list(2) == list(3) => \"SEGMENT\"\n\n case _ => \"IMPOSSIBLE\"\n }\n }\n\n val line = scala.io.StdIn.readLine()\n val nums = line.split(\" \").map(x => x.toInt).toList.sorted\n\n println(solve(nums))\n }\n}"}, {"source_code": "object P6A {\n def main(args : Array[String]) {\n val a = readLine split ' ' map {_.toInt}\n val answer = () match {\n case _ if (a combinations 3) exists {\n case Array(u, v, w) => u + v > w && v + w > u && w + u > v\n } => \"TRIANGLE\"\n case _ if (a combinations 3) exists {\n case Array(u, v, w) => u + v >= w && v + w >= u && w + u >= v\n } => \"SEGMENT\"\n case _ => \"IMPOSSIBLE\"\n }\n println(answer)\n }\n}\n"}], "negative_code": [{"source_code": "object Solution6A extends Application {\n\n def isTriangle(a: Int, b: Int, c: Int): Boolean = a + b > c && a + c > b && b + c > a\n\n def isSegment(a: Int, b: Int, c: Int): Boolean = !isTriangle(a, b, c) && a + b == c && a + c == b && b + c == a\n\n def solution() {\n val a1 = _int\n val a2 = _int\n val a3 = _int\n val a4 = _int\n\n if (isTriangle(a1, a2, a3)) {\n println(\"TRIANGLE\")\n return\n }\n if (isTriangle(a1, a2, a4)) {\n println(\"TRIANGLE\")\n return\n }\n if (isTriangle(a1, a4, a3)) {\n println(\"TRIANGLE\")\n return\n }\n if (isTriangle(a4, a2, a3)) {\n println(\"TRIANGLE\")\n return\n }\n\n\n if (isSegment(a1, a2, a3)) {\n println(\"SEGMENT\")\n return\n }\n if (isSegment(a1, a2, a4)) {\n println(\"SEGMENT\")\n return\n }\n if (isSegment(a1, a4, a3)) {\n println(\"SEGMENT\")\n return\n }\n if (isSegment(a4, a2, a3)) {\n println(\"SEGMENT\")\n return\n }\n\n println(\"IMPOSSIBLE\")\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}"}, {"source_code": "\n/**\n * Created by yangchaozhong on 3/10/15.\n */\nobject CF6A extends App {\n import java.util.{Scanner}\n import java.io.{PrintWriter}\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 def nextLine = in.nextLine\n\n def solve = {\n val lines = Array.ofDim[Int](4)\n\n (0 until 4).foreach { i =>\n lines(i) = nextInt\n }\n\n val combinations = lines.combinations(3)\n var c1 = 0\n var c2 = 0\n combinations.foreach { x =>\n x.permutations.foreach { y =>\n if (y(0) + y(1) > y(2) && y(0) + y(1) < y(2)) {\n c1 += 1\n } else if (y(0) + y(1) == y(2)) {\n c2 += 1\n }\n }\n }\n\n if (c1 > 0) {\n out.println(\"TRIANGLE\")\n } else if (c2 > 0) {\n out.println(\"SEGMENT\")\n } else {\n out.println(\"IMPOSSIBLE\")\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"}, {"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 P006A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val isTriangle: PartialFunction[List[Int], Boolean] = {\n case List(x, y, z) => x + y > z\n }\n\n val res = List.fill(4)(sc.nextInt).sorted.sliding(3).find(isTriangle) match {\n case Some(x) => \"TRIANGLE\"\n case None => \"SEGMENT\"\n }\n\n out.println(res)\n out.close\n}\n\n\n\n\n\n"}, {"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 solve = {\n val len = new Array[Int](4)\n for (i <- 0 until 4) {\n len(i) = nextInt\n }\n var flag = false\n for (i <- 0 until 4) {\n for (j <- 0 until 4) {\n for (k <- 0 until 4) {\n if (i != j && j != k && i != k) {\n if (len(i) < len(j) + len(k) &&\n len(j) < len(i) + len(k) &&\n len(k) < len(j) + len(i) && !flag) {\n out.println(\"TRIANGLE\")\n flag = true\n }\n }\n }\n }\n }\n if (!flag) {\n for (i <- 0 until 4) {\n for (j <- 0 until 4) {\n for (k <- 0 until 4) {\n if (i != j && j != k && i != k) {\n if ((len(i) <= len(j) + len(k) &&\n len(j) <= len(i) + len(k) ||\n len(k) <= len(j) + len(i)) && !flag) {\n out.println(\"SEGMENT\")\n flag = true\n }\n }\n }\n }\n }\n }\n if (!flag) {\n out.println(\"IMPOSSIBLE\")\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": "8f5df9a41e6e100aa65b9fc1d26e447a"} {"nl": {"description": "Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3 × 3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is announced.You are given a 3 × 3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below: illegal — if the given board layout can't appear during a valid game; the first player won — if in the given board layout the first player has just won; the second player won — if in the given board layout the second player has just won; draw — if the given board layout has just let to a draw. ", "input_spec": "The input consists of three lines, each of the lines contains characters \".\", \"X\" or \"0\" (a period, a capital letter X, or a digit zero).", "output_spec": "Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.", "sample_inputs": ["X0X\n.0.\n.X."], "sample_outputs": ["second"], "notes": null}, "positive_code": [{"source_code": "import java.util.Scanner\n\nobject ZeroCross extends App {\n\n /*val a = b.map(a => a.zipWithIndex).flatten.groupBy(_._2).values.map(_.map(_._1)).map(_.mkString)\n println(a.mkString(\" \"))\n*/\n\n\n val b = Array.ofDim[Int](3, 3)\n\n val scanner = new Scanner(System.in)\n (0 until 3).foreach {\n i =>\n b(i) = scanner.next.toCharArray.map(convert)\n }\n\n def convert(ch: Char): Int = {\n if (ch == '.') 0\n else if (ch == '0') 1\n else 2\n }\n\n\n val board = Board(b)\n\n if (board.xWon && board.zeroWon) {\n println(\"illegal\")\n } else if (board.count(2) < board.count(1)) {\n println(\"illegal\")\n } else if (board.count(2) - board.count(1) > 1) {\n println(\"illegal\")\n } else if (board.zeroWon && board.count(2) > board.count(1)) {\n println(\"illegal\")\n } else if (board.xWon && board.count(2) == board.count(1)) {\n println(\"illegal\")\n } else if (board.xWon) {\n println(\"the first player won\")\n } else if (board.zeroWon) {\n println(\"the second player won\")\n } else if (board.draw) {\n println(\"draw\")\n } else if (board.count(1) == board.count(2)) {\n println(\"first\")\n } else if (board.count(2) - board.count(1) == 1) {\n println(\"second\")\n } else {\n println(\"illegal\")\n }\n\n\n case class Board(arr: Array[Array[Int]]) {\n\n def xWon: Boolean = won(2)\n\n def zeroWon: Boolean = won(1)\n\n def won(item: Int): Boolean = {\n wonHorizontal(item) || wonVertical(item) || wonDiagonal(item)\n }\n\n def count(item: Int): Int = arr.flatten.count(_ == item)\n\n def draw: Boolean = count(1) == 4 && count(2) == 5\n\n def wonDiagonal(item: Int) = {\n val diag = for {x <- 0 until 3\n st = arr(x)(x)\n rev = arr(x)(2 - x)} yield (st, rev)\n val res = diag.foldLeft((\"\", \"\"))((acc, t) => (acc._1 + t._1, acc._2 + t._2))\n List(res._1, res._2).contains(item.toString * 3)\n }\n\n def wonHorizontal(item: Int): Boolean = arr.map(a => a.mkString).contains(item.toString * 3)\n\n def wonVertical(item: Int): Boolean = b.map(a => a.zipWithIndex).flatten.groupBy(_._2).values.map(_.map(_._1)).map(_.mkString).toList.contains(item.toString * 3)\n\n }\n\n\n}\n"}, {"source_code": "object C3 {\n\n import IO._\n import collection.{mutable => cu}\n\n def wins(b: Array[Array[Char]], char: Char): Boolean = {\n b.exists(_.forall(_==char)) || {\n (0 until 3).exists(j => Array(b(0)(j), b(1)(j), b(2)(j)).forall(_==char))\n } || {\n Array(b(0)(0), b(1)(1), b(2)(2)).forall(_==char)\n } || {\n Array(b(0)(2), b(1)(1), b(2)(0)).forall(_==char)\n }\n }\n\n def main(args: Array[String]): Unit = {\n val b = Array.fill(3)(read.toCharArray)\n val x = b.flatten.count(_ == 'X')\n val zero = b.flatten.count(_ == '0')\n if(x != zero && x != zero+1) {\n println(\"illegal\") //also both can't win\n } else {\n if (wins(b, 'X') && wins(b, '0')) {\n println(\"illegal\")\n } else if (wins(b, 'X')){\n if(x == zero+1)\n println(\"the first player won\")\n else\n println(\"illegal\")\n } else if (wins(b, '0')){\n if(x == zero)\n println(\"the second player won\")\n else\n println(\"illegal\")\n } else {\n if(b.flatten.contains('.')) {\n if(x == zero) {\n println(\"first\")\n } else {\n println(\"second\")\n }\n } else {\n println(\"draw\")\n }\n }\n }\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"}, {"source_code": "object cf3C extends App {\n val s = readLine + readLine + readLine\n val numX = s count {_ == 'X'}\n val num0 = s count {_ == '0'}\n val toX = numX== num0\n val to0 = numX== num0+1\n val filled = s forall {_!='.'}\n val lines = Array(\n Array(0, 1, 2), Array(3, 4, 5), Array(6, 7, 8),\n Array(0, 3, 6), Array(1, 4, 7), Array(2, 5, 8),\n Array(0, 4, 8), Array(2, 4, 6))\n val winX = lines exists {_ forall {s(_) == 'X'}}\n val win0 = lines exists {_ forall {s(_) == '0'}}\n val answer = () match {\n case _ if !toX && !to0 || toX && winX || to0 && win0 => \"illegal\"\n case _ if winX => \"the first player won\"\n case _ if win0 => \"the second player won\"\n case _ if filled => \"draw\"\n case _ if toX => \"first\"\n case _ if to0 => \"second\"\n }\n println(answer)\n}"}, {"source_code": "object P3C {\n def main(args : Array[String]) {\n val s = readLine + readLine + readLine\n val numX = s count {_ == 'X'}\n val num0 = s count {_ == '0'}\n val toX = numX == num0\n val to0 = numX == num0 + 1\n val filled = s forall {_ != '.'}\n val lines = Array(\n Array(0, 1, 2), Array(3, 4, 5), Array(6, 7, 8),\n Array(0, 3, 6), Array(1, 4, 7), Array(2, 5, 8),\n Array(0, 4, 8), Array(2, 4, 6))\n val winX = lines exists {_ forall {s(_) == 'X'}}\n val win0 = lines exists {_ forall {s(_) == '0'}}\n val answer = () match {\n case _ if !toX && !to0 || toX && winX || to0 && win0 => \"illegal\"\n case _ if winX => \"the first player won\"\n case _ if win0 => \"the second player won\"\n case _ if filled => \"draw\"\n case _ if toX => \"first\"\n case _ if to0 => \"second\"\n }\n println(answer)\n }\n}\n"}], "negative_code": [{"source_code": "import java.util.Scanner\n\nobject ZeroCross extends App {\n\n /*val a = b.map(a => a.zipWithIndex).flatten.groupBy(_._2).values.map(_.map(_._1)).map(_.mkString)\n println(a.mkString(\" \"))\n*/\n\n\n val b = Array.ofDim[Int](3, 3)\n\n val scanner = new Scanner(System.in)\n (0 until 3).foreach {\n i =>\n b(i) = scanner.next.toCharArray.map(convert)\n }\n\n def convert(ch: Char): Int = {\n if (ch == '.') 0\n else if (ch == '0') 1\n else 2\n }\n\n\n val board = Board(b)\n\n if (board.xWon && board.zeroWon) {\n println(\"illegal\")\n } else if (board.count(2) < board.count(1)) {\n println(\"illegal\")\n } else if (board.count(2) - board.count(1) > 1) {\n println(\"illegal\")\n } else if (board.zeroWon && board.count(2) > board.count(1)) {\n println(\"illegal\")\n } else if (board.xWon && board.count(2) == board.count(1)) {\n println(\"illegal\")\n } else if (board.xWon) {\n println(\"the first player won\")\n } else if (board.zeroWon) {\n println(\"the second player won\")\n } else if (board.draw) {\n println(\"draw\")\n } else if (board.count(1) == board.count(2)) {\n println(\"first\")\n } else if (board.count(2) - board.count(1) == 1) {\n println(\"second\")\n } else {\n println(\"illegal\")\n }\n\n\n case class Board(arr: Array[Array[Int]]) {\n\n def xWon: Boolean = won(2)\n\n def zeroWon: Boolean = won(1)\n\n def won(item: Int): Boolean = {\n wonHorizontal(item) || wonVertical(item) || wonDiagonal(item)\n }\n\n def count(item: Int): Int = arr.flatten.count(_ == item)\n\n def draw: Boolean = count(1) == 4 && count(2) == 5\n\n def wonDiagonal(item: Int) = {\n val diag = for {x <- 0 until 3\n st = arr(x)(x)\n rev = arr(2 - x)(2 - x)} yield (st, rev)\n val res = diag.foldLeft((\"\", \"\"))((acc, t) => (acc._1 + t._1, acc._2 + t._1))\n List(res._1, res._2).contains(item.toString * 3)\n }\n\n def wonHorizontal(item: Int): Boolean = arr.map(a => a.mkString).contains(item.toString * 3)\n\n def wonVertical(item: Int): Boolean = b.map(a => a.zipWithIndex).flatten.groupBy(_._2).values.map(_.map(_._1)).map(_.mkString).toList.contains(item.toString * 3)\n\n }\n\n\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject ZeroCross extends App {\n\n /*val a = b.map(a => a.zipWithIndex).flatten.groupBy(_._2).values.map(_.map(_._1)).map(_.mkString)\n println(a.mkString(\" \"))\n*/\n\n\n val b = Array.ofDim[Int](3, 3)\n\n val scanner = new Scanner(System.in)\n (0 until 3).foreach {\n i =>\n b(i) = scanner.next.toCharArray.map(convert)\n }\n\n def convert(ch: Char): Int = {\n if (ch == '.') 0\n else if (ch == '0') 1\n else 2\n }\n\n\n val board = Board(b)\n\n if (board.xWon && board.zeroWon) {\n println(\"illegal\")\n } else if (board.count(2) < board.count(1)) {\n println(\"illegal\")\n } else if (board.count(2) - board.count(1) > 1) {\n println(\"illegal\")\n } else if (board.zeroWon && board.count(2) > board.count(1)) {\n println(\"illegal\")\n } else if (board.xWon && board.count(2) == board.count(1)) {\n println(\"illegal\")\n } else if (board.xWon) {\n println(\"the first player won\")\n } else if (board.zeroWon) {\n println(\"the second player won\")\n } else if (board.draw) {\n println(\"draw\")\n } else if (board.count(1) == board.count(2)) {\n println(\"first\")\n } else if (board.count(2) - board.count(1) == 1) {\n println(\"second\")\n } else {\n println(\"illegal\")\n }\n\n\n case class Board(arr: Array[Array[Int]]) {\n\n def xWon: Boolean = won(2)\n\n def zeroWon: Boolean = won(1)\n\n def won(item: Int): Boolean = {\n wonHorizontal(item) || wonVertical(item) || wonDiagonal(item)\n }\n\n def count(item: Int): Int = arr.flatten.count(_ == item)\n\n def draw: Boolean = count(1) == 4 && count(2) == 5\n\n def wonDiagonal(item: Int) = {\n val diag = for {x <- 0 until 3\n st = arr(x)(2 - x)\n rev = arr(2 - x)(2)} yield (st, rev)\n val res = diag.foldLeft((\"\", \"\"))((acc, t) => (acc._1 + t._1, acc._2 + t._1))\n List(res._1, res._2).contains(item.toString * 3)\n }\n\n def wonHorizontal(item: Int): Boolean = arr.map(a => a.mkString).contains(item.toString * 3)\n\n def wonVertical(item: Int): Boolean = b.map(a => a.zipWithIndex).flatten.groupBy(_._2).values.map(_.map(_._1)).map(_.mkString).toList.contains(item.toString * 3)\n\n }\n\n\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject ZeroCross extends App {\n\n /*val a = b.map(a => a.zipWithIndex).flatten.groupBy(_._2).values.map(_.map(_._1)).map(_.mkString)\n println(a.mkString(\" \"))\n*/\n\n\n val b = Array.ofDim[Int](3, 3)\n\n val scanner = new Scanner(System.in)\n (0 until 3).foreach {\n i =>\n b(i) = scanner.next.toCharArray.map(convert)\n }\n\n def convert(ch: Char): Int = {\n if (ch == '.') 0\n else if (ch == '0') 1\n else 2\n }\n\n\n val board = Board(b)\n\n if (board.xWon && board.zeroWon) {\n println(\"illegal\")\n } else if (board.count(2) < board.count(1)) {\n println(\"illegal\")\n } else if (board.count(2) - board.count(1) > 1) {\n println(\"illegal\")\n } else if (board.zeroWon && board.count(2) > board.count(1)) {\n println(\"illegal\")\n } else if (board.xWon) {\n println(\"the first player won\")\n } else if (board.zeroWon) {\n println(\"the second player won\")\n } else if (board.draw) {\n println(\"draw\")\n } else if (board.count(1) == board.count(2)) {\n println(\"first\")\n } else if (board.count(2) - board.count(1) == 1) {\n println(\"second\")\n } else {\n println(\"illegal\")\n }\n\n\n case class Board(arr: Array[Array[Int]]) {\n\n def xWon: Boolean = won(2)\n\n def zeroWon: Boolean = won(1)\n\n def won(item: Int): Boolean = {\n wonHorizontal(item) || wonVertical(item) || wonDiagonal(item)\n }\n\n def count(item: Int): Int = arr.flatten.count(_ == item)\n\n def draw: Boolean = count(1) == 4 && count(2) == 5\n\n def wonDiagonal(item: Int) = {\n val diag = for {x <- 0 until 3\n st = arr(x)(x)\n rev = arr(2 - x)(2 - x)} yield (st, rev)\n val res = diag.foldLeft((\"\", \"\"))((acc, t) => (acc._1 + t._1, acc._2 + t._1))\n List(res._1, res._2).contains(item.toString * 3)\n }\n\n def wonHorizontal(item: Int): Boolean = arr.map(a => a.mkString).contains(item.toString * 3)\n\n def wonVertical(item: Int): Boolean = b.map(a => a.zipWithIndex).flatten.groupBy(_._2).values.map(_.map(_._1)).map(_.mkString).toList.contains(item.toString * 3)\n\n }\n\n\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject ZeroCross extends App {\n\n /*val a = b.map(a => a.zipWithIndex).flatten.groupBy(_._2).values.map(_.map(_._1)).map(_.mkString)\n println(a.mkString(\" \"))\n*/\n\n\n val b = Array.ofDim[Int](3, 3)\n\n val scanner = new Scanner(System.in)\n (0 until 3).foreach { i =>\n b(i) = scanner.next.toCharArray.map(convert)\n }\n\n def convert(ch: Char):Int = {\n if (ch == '.') 0\n else if (ch == '0') 1\n else 2\n }\n\n\n val board = Board(b)\n\n if (board.xWon && board.zeroWon) {\n println(\"illegal\")\n } else if (board.count(2) < board.count(1)) {\n println(\"illegal\")\n } else if (board.count(2) - board.count(1) > 1) {\n println(\"illegal\")\n } else if (board.xWon) {\n println(\"the first player won\")\n } else if (board.zeroWon) {\n println(\"the second player won\")\n } else if (board.draw) {\n println(\"draw\")\n } else if (board.count(1) == board.count(2)) {\n println(\"first\")\n } else if (board.count(2) - board.count(1) == 1) {\n println(\"second\")\n } else {\n println(\"illegal\")\n }\n\n\n\n case class Board(arr: Array[Array[Int]]) {\n\n def xWon: Boolean = won(2)\n\n def zeroWon: Boolean = won(1)\n\n def won(item: Int): Boolean = {\n wonHorizontal(item) || wonVertical(item) || wonDiagonal(item)\n }\n\n def count(item: Int):Int = arr.flatten.count(_ == item)\n\n def draw:Boolean = count(1) == 4 && count(2) == 5\n\n def wonDiagonal(item: Int) = {\n val diag = for {x <- 0 until 3\n st = arr(x)(x)\n rev = arr(2 - x)(2 - x)} yield (st, rev)\n val res = diag.foldLeft((\"\",\"\"))((acc, t) => (acc._1 + t._1, acc._2 + t._1))\n List(res._1, res._2).contains(item.toString * 3)\n }\n\n def wonHorizontal(item: Int): Boolean = arr.map(a => a.mkString).contains(item.toString * 3)\n\n def wonVertical(item: Int): Boolean = b.map(a => a.zipWithIndex).flatten.groupBy(_._2).values.map(_.map(_._1)).map(_.mkString).toList.contains(item.toString * 3)\n\n }\n\n\n}\n"}, {"source_code": "object C3 {\n\n import IO._\n import collection.{mutable => cu}\n\n def wins(b: Array[Array[Char]], char: Char): Boolean = {\n b.exists(_.forall(_==char)) || {\n (0 until 3).exists(j => Array(b(0)(j), b(1)(j), b(2)(j)).forall(_==char))\n } || {\n Array(b(0)(0), b(1)(1), b(2)(2)).forall(_==char)\n } || {\n Array(b(0)(2), b(1)(1), b(2)(0)).forall(_==char)\n }\n }\n\n def main(args: Array[String]): Unit = {\n val b = Array.fill(3)(read.toCharArray)\n val x = b.flatten.count(_ == 'X')\n val zero = b.flatten.count(_ == '0')\n if(x != zero || x != zero+1) {\n println(\"illegal\") //also both can't win\n } else {\n if (wins(b, 'X') && wins(b, '0')) {\n println(\"illegal\")\n } else if (wins(b, 'X')){\n if(x == zero+1)\n println(\"the first player won\")\n else\n println(\"illegal\")\n } else if (wins(b, '0')){\n if(x == zero)\n println(\"the second player won\")\n else\n println(\"illegal\")\n } else {\n if(b.flatten.contains('.')) {\n if(x == zero) {\n println(\"first\")\n } else {\n println(\"second\")\n }\n } else {\n println(\"draw\")\n }\n }\n }\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"}, {"source_code": "object C3 {\n\n import IO._\n import collection.{mutable => cu}\n\n def wins(b: Array[Array[Char]], char: Char): Boolean = {\n b.exists(_.forall(_==char)) || {\n (0 until 3).exists(j => Array(b(0)(j), b(1)(j), b(2)(j)).forall(_==char))\n } || {\n Array(b(0)(0), b(1)(1), b(2)(2)).forall(_==char)\n } || {\n Array(b(0)(2), b(1)(1), b(2)(0)).forall(_==char)\n }\n }\n\n def main(args: Array[String]): Unit = {\n val b = Array.fill(3)(read.toCharArray)\n val x = b.flatten.count(_ == 'X')\n val zero = b.flatten.count(_ == '0')\n if(x < zero) {\n println(\"illegal\") //also both can't win\n } else {\n if (wins(b, 'X') && wins(b, '0')) {\n println(\"illegal\")\n } else if (wins(b, 'X')){\n if(x == zero+1)\n println(\"the first player won\")\n else\n println(\"illegal\")\n } else if (wins(b, '0')){\n if(x == zero)\n println(\"the second player won\")\n else\n println(\"illegal\")\n } else {\n if(b.flatten.contains('.')) {\n if(x == zero) {\n println(\"first\")\n } else {\n println(\"second\")\n }\n } else {\n println(\"draw\")\n }\n }\n }\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"}, {"source_code": "object C3 {\n\n import IO._\n import collection.{mutable => cu}\n\n def wins(b: Array[Array[Char]], char: Char): Boolean = {\n b.exists(_.forall(_==char)) || {\n (0 until 3).exists(j => Array(b(0)(j), b(1)(j), b(2)(j)).forall(_==char))\n } || {\n Array(b(0)(0), b(1)(1), b(2)(2)).forall(_==char)\n } || {\n Array(b(0)(2), b(1)(1), b(2)(0)).forall(_==char)\n }\n }\n\n def main(args: Array[String]): Unit = {\n val b = Array.fill(3)(read.toCharArray)\n if(b.flatten.count(_ == 'X') < b.flatten.count(_ == '0') || (wins(b, 'X') && wins(b, '0')) ) {\n println(\"illegal\") //also both can't win\n } else if (wins(b, 'X')){\n println(\"the first player won\")\n } else if (wins(b, 'X')){\n println(\"the second player won\")\n } else {\n if(b.flatten.contains('.')) {\n if(b.flatten.count(_ == 'X') == b.flatten.count(_ == '0')) {\n println(\"first\")\n } else {\n println(\"second\")\n }\n } else {\n println(\"draw\")\n }\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"}, {"source_code": "object P3C {\n def main(args : Array[String]) {\n val s = readLine + readLine + readLine\n val numX = s count {_ == 'X'}\n val num0 = s count {_ == '0'}\n val filled = s forall {_ != '.'}\n val lines = Array(\n Array(0, 1, 2), Array(3, 4, 5), Array(6, 7, 8),\n Array(0, 3, 6), Array(1, 4, 7), Array(2, 5, 8),\n Array(0, 4, 8), Array(2, 4, 6))\n val winX = lines exists {_ forall {s(_) == 'X'}}\n val win0 = lines exists {_ forall {s(_) == '0'}}\n val answer = () match {\n case _ if numX < num0 || num0 + 1 < numX => \"Illegal\"\n case _ if winX && win0 => \"Illegal\"\n case _ if winX => \"the first player won\"\n case _ if win0 => \"the second player won\"\n case _ if filled => \"draw\"\n case _ if numX == num0 => \"first\"\n case _ => \"second\"\n }\n println(answer)\n }\n}\n"}, {"source_code": "object P3C {\n def main(args : Array[String]) {\n val s = readLine + readLine + readLine\n val numX = s count {_ == 'X'}\n val num0 = s count {_ == '0'}\n val filled = s forall {_ != '.'}\n val lines = Array(\n Array(0, 1, 2), Array(3, 4, 5), Array(6, 7, 8),\n Array(0, 3, 6), Array(1, 4, 7), Array(2, 5, 8),\n Array(0, 4, 8), Array(2, 4, 6))\n val winX = lines exists {_ forall {s(_) == 'X'}}\n val win0 = lines exists {_ forall {s(_) == '0'}}\n val answer = () match {\n case _ if numX < num0 || num0 + 1 < numX => \"illegal\"\n case _ if winX && win0 => \"illegal\"\n case _ if winX => \"the first player won\"\n case _ if win0 => \"the second player won\"\n case _ if filled => \"draw\"\n case _ if numX == num0 => \"first\"\n case _ => \"second\"\n }\n println(answer)\n }\n}\n"}], "src_uid": "892680e26369325fb00d15543a96192c"} {"nl": {"description": "The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows. The event coordinator has a list of k participants who should be picked up at the airport. When a participant gets on the bus, he will sit in the last row with an empty seat. If there is more than one empty seat in that row, he will take the leftmost one. In order to keep track of the people who are on the bus, the event coordinator needs a figure showing which seats are going to be taken by k participants. Your task is to draw the figure representing occupied seats.", "input_spec": "The only line of input contains integer k, (0 ≤ k ≤ 34), denoting the number of participants.", "output_spec": "Print the figure of a bus with k passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six lines. Do not output extra space or other characters.", "sample_inputs": ["9", "20"], "sample_outputs": ["+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+", "+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|)\n+------------------------+"], "notes": null}, "positive_code": [{"source_code": "import java.io.PrintWriter\nimport java.util.Scanner\n\n/**\n * Created by arseny on 05.10.14.\n */\nobject A extends App {\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 k = nextInt\n var r1 = \"+------------------------+\"\n var r2 = \"|#.#.#.#.#.#.#.#.#.#.#.|D|)\"\n var r3 = \"|#.#.#.#.#.#.#.#.#.#.#.|.|\"\n var r4 = \"|#.......................|\"\n var r5 = \"|#.#.#.#.#.#.#.#.#.#.#.|.|)\"\n var r6 = \"+------------------------+\"\n\n if (k >= 1) {\n r2 = r2.updated(1, 'O')\n }\n if (k >= 2) {\n r3 = r3.updated(1, 'O')\n }\n if (k >= 3) {\n r4 = r4.updated(1, 'O')\n }\n if (k >= 4) {\n r5 = r5.updated(1, 'O')\n }\n if (k >= 5) {\n val m = (k - 4) / 3\n for (i <- 0 until m) {\n r2 = r2.updated((i + 1) * 2 + 1, 'O')\n r3 = r3.updated((i + 1) * 2 + 1, 'O')\n r5 = r5.updated((i + 1) * 2 + 1, 'O')\n }\n val t = (k - 4) % 3\n if (t >= 1) {\n r2 = r2.updated(2 * m + 3, 'O')\n }\n if (t >= 2) {\n r3 = r3.updated(2 * m + 3, 'O')\n }\n }\n\n out.println(r1)\n out.println(r2)\n out.println(r3)\n out.println(r4)\n out.println(r5)\n out.println(r6)\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}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n var n = in.next().toInt\n val left = if (n == 0) 0\n else if (n < 5) 1\n else 1 + ((n - 5) / 3 + 1)\n val middleleft = if (n < 2) 0\n else if (n < 6) 1\n else 1 + ((n - 6) / 3 + 1)\n val middleright = if (n < 3) 0 else 1\n val right = if (n < 4) 0\n else if (n < 7) 1\n else 1 + ((n - 7) / 3 + 1)\n println(\"+------------------------+\")\n println(\"|\" + (\"O.\" * left) + (\"#.\" * (11 - left)) + \"|D|)\")\n println(\"|\" + (\"O.\" * middleleft) + (\"#.\" * (11 - middleleft)) + \"|.|\")\n println(\"|\" + (if (middleright == 0) \"#.\" else \"O.\") + (\"..\" * 10) + \"..|\")\n println(\"|\" + (\"O.\" * right) + (\"#.\" * (11 - right)) + \"|.|)\")\n println(\"+------------------------+\")\n\n}"}, {"source_code": "object BY2015_1 extends App {\n @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n def readInts(n: Int) = {\n val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)\n }\n\n val Array(n) = readInts(1)\n val arr = Array.ofDim[String](34)\n for(i <- 0 until n) {\n arr(i) = \"O\"\n }\n for(i <- n until 34){\n arr(i) = \"#\"\n }\n println(\"+------------------------+\\n\" +\n s\"|${arr(0)}.${arr(4)}.${arr(7)}.${arr(10)}.${arr(13)}.${arr(16)}.${arr(19)}.${arr(22)}.${arr(25)}.${arr(28)}.${arr(31)}.|D|)\\n\" +\n s\"|${arr(1)}.${arr(5)}.${arr(8)}.${arr(11)}.${arr(14)}.${arr(17)}.${arr(20)}.${arr(23)}.${arr(26)}.${arr(29)}.${arr(32)}.|.|\\n\" +\n s\"|${arr(2)}.......................|\\n\" +\n s\"|${arr(3)}.${arr(6)}.${arr(9)}.${arr(12)}.${arr(15)}.${arr(18)}.${arr(21)}.${arr(24)}.${arr(27)}.${arr(30)}.${arr(33)}.|.|)\\n+------------------------+\")\n}\n"}, {"source_code": "import scala.collection._\n\nobject 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 val seats = Array.fill(4, 11)(false)\n var used = 0\n \n for (r <- 0 until 11) {\n for (c <- 0 until 4 if r == 0 || c != 2) {\n if (used < n) {\n seats(c)(r) = true\n used += 1\n }\n }\n }\n \n \n println(\"+------------------------+\")\n \n print(\"|\")\n for (s <- seats(0)) print(if (s) \"O.\" else \"#.\")\n println(\"|D|)\")\n\n print(\"|\")\n for (s <- seats(1)) print(if (s) \"O.\" else \"#.\")\n println(\"|.|\")\n \n print(\"|\")\n if (seats(2)(0)) print(\"O\") else print(\"#\")\n println(\".......................|\")\n \n print(\"|\")\n for (s <- seats(3)) print(if (s) \"O.\" else \"#.\")\n println(\"|.|)\")\n\n println(\"+------------------------+\")\n \n//|O.O.O.#.#.#.#.#.#.#.#.|D|)\n//|O.O.O.#.#.#.#.#.#.#.#.|.|\n//|O.......................|\n//|O.O.#.#.#.#.#.#.#.#.#.|.|)\n//+------------------------+\n}"}, {"source_code": "import java.util._\nimport java.io._\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 var k = nextInt\n out.println(\"+------------------------+\")\n val ans = new Array[util.ArrayList[Char]](4)\n for (i <- 0 until 4) {\n ans(i) = new util.ArrayList[Char]()\n ans(i).add('|')\n }\n for (j <- 0 until 11) {\n for (i <- 0 until 4) {\n if (k > 0) {\n if (i == 2) {\n if (j == 0) {\n ans(i).add('O')\n ans(i).add('.')\n k -= 1\n } else {\n ans(i).add('.')\n ans(i).add('.')\n }\n }\n else {\n ans(i).add('O')\n ans(i).add('.')\n k -= 1\n }\n }\n else {\n if (i == 2 && j > 0) {\n ans(i).add('.')\n ans(i).add('.')\n } else {\n ans(i).add('#')\n ans(i).add('.')\n }\n }\n }\n }\n ans(0).add('|')\n ans(0).add('D')\n ans(0).add('|')\n ans(0).add(')')\n ans(1).add('|')\n ans(1).add('.')\n ans(1).add('|')\n ans(2).add('.')\n ans(2).add('.')\n ans(2).add('|')\n ans(3).add('|')\n ans(3).add('.')\n ans(3).add('|')\n ans(3).add(')')\n for (i <- 0 until 4) {\n for (j <- 0 until ans(i).size()) {\n out.print(ans(i).get(j))\n }\n out.println\n }\n out.println(\"+------------------------+\")\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"}, {"source_code": "object main{\n\n\n def work(n:Int): Unit ={\n var s = \"+------------------------+\\n|#.#.#.#.#.#.#.#.#.#.#.|D|)\\n|#.#.#.#.#.#.#.#.#.#.#.|.|\\n|#.......................|\\n|#.#.#.#.#.#.#.#.#.#.#.|.|)\\n+------------------------+\"\n var x = n\n\n var arr = s.split('\\n').map( _.toList.toIndexedSeq)\n for {\n column <- 0 until arr(0).length\n row <- 0 until 6\n } {\n val ch = arr(row)(column)\n if ('#' == ch && x >0){\n arr = arr.updated(row, arr(row).updated(column,'O'))\n x -= 1\n }\n }\n val s2 = (arr map (_.mkString)).mkString(\"\\n\")\n\n println(s2)\n }\n\n def main(args:Array[String]) = {\n val n = readInt()\n work(n)\n }\n\n\n\n}\n"}], "negative_code": [{"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n var n = in.next().toInt\n val left = if (n == 0) 0\n else if (n < 5) 1\n else 1 + ((n - 5) / 3 + 1)\n val middleleft = if (n < 2) 0\n else if (n < 6) 1\n else 1 + ((n - 6) / 3 + 1)\n val middleright = if (n < 3) 0 else 1\n val right = if (n < 4) 0\n else if (n < 7) 1\n else 1 + ((n - 7) / 3 + 1)\n println(\"|+------------------------+\")\n println(\"||\" + (\"0.\" * left) + (\"#.\" * (11 - left)) + \"|D|)\")\n println(\"||\" + (\"0.\" * middleleft) + (\"#.\" * (11 - middleleft)) + \"|.|)\")\n println(\"||\" + (\"0.\" * middleright) + (\"..\" * (11 - middleright)) + \"..|\")\n println(\"||\" + (\"0.\" * right) + (\"#.\" * (11 - right)) + \"|.|)\")\n println(\"|+------------------------+\")\n\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n var n = in.next().toInt\n val left = if (n == 0) 0\n else if (n < 5) 1\n else 1 + ((n - 5) / 3 + 1)\n val middleleft = if (n < 2) 0\n else if (n < 6) 1\n else 1 + ((n - 6) / 3 + 1)\n val middleright = if (n < 3) 0 else 1\n val right = if (n < 4) 0\n else if (n < 7) 1\n else 1 + ((n - 7) / 3 + 1)\n println(\"|+------------------------+\")\n println(\"||\" + (\"O.\" * left) + (\"#.\" * (11 - left)) + \"|D|)\")\n println(\"||\" + (\"O.\" * middleleft) + (\"#.\" * (11 - middleleft)) + \"|.|)\")\n println(\"||\" + (\"O.\" * middleright) + (\"..\" * (11 - middleright)) + \"..|\")\n println(\"||\" + (\"O.\" * right) + (\"#.\" * (11 - right)) + \"|.|)\")\n println(\"|+------------------------+\")\n\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n var n = in.next().toInt\n val left = if (n == 0) 0\n else if (n < 5) 1\n else 1 + ((n - 5) / 3 + 1)\n val middleleft = if (n < 2) 0\n else if (n < 6) 1\n else 1 + ((n - 6) / 3 + 1)\n val middleright = if (n < 3) 0 else 1\n val right = if (n < 4) 0\n else if (n < 7) 1\n else 1 + ((n - 7) / 3 + 1)\n println(\"|+------------------------+\")\n println(\"||\" + (\"O.\" * left) + (\"#.\" * (11 - left)) + \"|D|)\")\n println(\"||\" + (\"O.\" * middleleft) + (\"#.\" * (11 - middleleft)) + \"|.|\")\n println(\"||\" + (\"O.\" * middleright) + (\"..\" * (11 - middleright)) + \"..|\")\n println(\"||\" + (\"O.\" * right) + (\"#.\" * (11 - right)) + \"|.|)\")\n println(\"|+------------------------+\")\n\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n var n = in.next().toInt\n val left = if (n == 0) 0\n else if (n < 5) 1\n else 1 + ((n - 5) / 3 + 1)\n val middleleft = if (n < 2) 0\n else if (n < 6) 1\n else 1 + ((n - 6) / 3 + 1)\n val middleright = if (n < 3) 0 else 1\n val right = if (n < 4) 0\n else if (n < 7) 1\n else 1 + ((n - 7) / 3 + 1)\n println(\"+------------------------+\")\n println(\"|\" + (\"O.\" * left) + (\"#.\" * (11 - left)) + \"|D|)\")\n println(\"|\" + (\"O.\" * middleleft) + (\"#.\" * (11 - middleleft)) + \"|.|\")\n println(\"|\" + (if (middleright == 0) \"#.\" else \"O.\") + (\"..\" * (11 - middleright)) + \"..|\")\n println(\"|\" + (\"O.\" * right) + (\"#.\" * (11 - right)) + \"|.|)\")\n println(\"+------------------------+\")\n\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n var n = in.next().toInt\n val left = if (n == 0) 0\n else if (n < 5) 1\n else 1 + ((n - 5) / 3 + 1)\n val middleleft = if (n < 2) 0\n else if (n < 6) 1\n else 1 + ((n - 6) / 3 + 1)\n val middleright = if (n < 3) 0 else 1\n val right = if (n < 4) 0\n else if (n < 7) 1\n else 1 + ((n - 7) / 3 + 1)\n println(\"+------------------------+\")\n println(\"|\" + (\"O.\" * left) + (\"#.\" * (11 - left)) + \"|D|)\")\n println(\"|\" + (\"O.\" * middleleft) + (\"#.\" * (11 - middleleft)) + \"|.|\")\n println(\"|\" + (if (middleright == 0) \"#.\" else \"O.\") + (\"..\" * (10 - middleright)) + \"..|\")\n println(\"|\" + (\"O.\" * right) + (\"#.\" * (11 - right)) + \"|.|)\")\n println(\"+------------------------+\")\n\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n var n = in.next().toInt\n val left = if (n == 0) 0\n else if (n < 5) 1\n else 1 + ((n - 5) / 3 + 1)\n val middleleft = if (n < 2) 0\n else if (n < 6) 1\n else 1 + ((n - 6) / 3 + 1)\n val middleright = if (n < 3) 0 else 1\n val right = if (n < 4) 0\n else if (n < 7) 1\n else 1 + ((n - 7) / 3 + 1)\n println(\"+------------------------+\")\n println(\"|\" + (\"O.\" * left) + (\"#.\" * (11 - left)) + \"|D|)\")\n println(\"|\" + (\"O.\" * middleleft) + (\"#.\" * (11 - middleleft)) + \"|.|\")\n println(\"|\" + (\"O.\" * middleright) + (\"..\" * (11 - middleright)) + \"..|\")\n println(\"|\" + (\"O.\" * right) + (\"#.\" * (11 - right)) + \"|.|)\")\n println(\"+------------------------+\")\n\n}"}], "src_uid": "075f83248f6d4d012e0ca1547fc67993"} {"nl": {"description": "Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.Each command is one of the following two types: Go 1 unit towards the positive direction, denoted as '+' Go 1 unit towards the negative direction, denoted as '-' But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5). You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands?", "input_spec": "The first line contains a string s1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}. The second line contains a string s2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command. Lengths of two strings are equal and do not exceed 10.", "output_spec": "Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9.", "sample_inputs": ["++-+-\n+-+-+", "+-+-\n+-??", "+++\n??-"], "sample_outputs": ["1.000000000000", "0.500000000000", "0.000000000000"], "notes": "NoteFor the first sample, both s1 and s2 will lead Dreamoon to finish at the same position  + 1. For the second sample, s1 will lead Dreamoon to finish at position 0, while there are four possibilites for s2: {\"+-++\", \"+-+-\", \"+--+\", \"+---\"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5. For the third sample, s2 could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position  + 3 is 0."}, "positive_code": [{"source_code": "import scala.io.StdIn\n\nobject DW extends App {\n\n val required = StdIn.readLine().toCharArray.map {\n case '+' => 1\n case '-' => -1\n }.sum\n val (actual, uncertain) = StdIn.readLine().toCharArray.map {\n case '+' => (1, 0)\n case '-' => (-1, 0)\n case '?' => (0, 1)\n }.fold(0,0) {\n case ((a1, b1), (a2, b2)) => (a1 + a2, b1 + b2)\n }\n val miss = math.abs(required - actual)\n if (\n required > (actual + uncertain) ||\n required < (actual - uncertain) ||\n miss == 0 && uncertain % 2 != 0\n ) println(0.0d)\n else {\n\n val pluses = miss + (uncertain - miss) / 2\n println(\n math.pow(0.5f, uncertain) * factorial(uncertain) / (factorial(pluses) * factorial(math.abs(uncertain - pluses)))\n )\n }\n\n def factorial(n: Int): Int = {\n var res = 1\n for (i <- 1 to n) {\n res *= i\n }\n res\n }\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject Wifi\n{\n\tvar original, total, correct: Int = 0\n\t\n\tdef main(args: Array[String])\n\t{\n\t\tval a, b = readLine\n\t\t\n\t\tfor (c <- a) c match\n\t\t{\n\t\t\tcase '+' => original += 1\n\t\t\tcase '-' => original -= 1\n\t\t}\n\t\t\n\t\tparse(b, 0)\n\t\tprintf(\"%1$.12f\", correct.toDouble / total)\n\t}\n\t\n\tdef parse(str: String, _pos: Int)\n\t{\n\t\tif (str isEmpty)\n\t\t{\n\t\t\tif (_pos == original) correct += 1\n\t\t\ttotal += 1\n\t\t\treturn\n\t\t}\n\t\tvar pos = _pos\n\t\t\n\t\tfor (i <- 0 until str.size) str(i) match\n\t\t{\n\t\t\tcase '+' => pos += 1\n\t\t\tcase '-' => pos -= 1\n\t\t\tcase '?' => {\n\t\t\t\t\t\t\tparse(str.substring(i + 1), pos + 1)\n\t\t\t\t\t\t\tparse(str.substring(i + 1), pos - 1)\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t}\n\t\t\n\t\tif (pos == original) correct += 1\n\t\ttotal += 1\n\t}\n}"}, {"source_code": "object B476 {\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 s1 = scala.io.StdIn.readLine\n val s2 = scala.io.StdIn.readLine\n val total = math.pow(2.0, s2.count(_ == '?'))\n val count = gen(0, s2.toCharArray, calc(s1.toCharArray))\n println(count.toDouble/total)\n }\n\n def calc(str: Array[Char]): Int = {\n val ret = str.foldLeft(0) { case (sum, ch) =>\n if(ch == '+') {\n sum + 1\n } else {\n sum - 1\n }\n }\n ret\n }\n\n def gen(ind: Int, str: Array[Char], finalPos: Int): Int = {\n if(ind == str.length) {\n if(calc(str) == finalPos) 1 else 0\n } else if (str(ind) != '?'){\n gen(ind + 1, str, finalPos)\n } else {\n var score = 0\n\n str(ind) = '+'\n score = gen(ind + 1, str, finalPos)\n\n str(ind) = '-'\n score += gen(ind + 1, str, finalPos)\n\n str(ind) = '?'\n\n score\n }\n }\n}"}, {"source_code": "object Main extends App {\n def step(acc: Array[Int], op: Char): Array[Int] = \n if (op == '+') acc.map(_ + 1)\n else if (op == '-') acc.map(_ - 1)\n else acc.flatMap(x => Array(x - 1, x + 1))\n \n val orig = readLine\n val endPos = orig.foldLeft(Array(0))(step)(0)\n \n val recieved = readLine\n val sampleSpace = recieved.foldLeft(Array(0))(step)\n \n println(sampleSpace.count(_ == endPos) / sampleSpace.size.toDouble)\n}"}], "negative_code": [{"source_code": "object B476 {\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 s1 = scala.io.StdIn.readLine\n val s2 = scala.io.StdIn.readLine\n val total = s2.count(_ == '?').toDouble\n if(total == 0) {\n println(1.0d)\n } else {\n val count = gen(0, s2.toCharArray, calc(s1.toCharArray))\n println(count.toDouble/total)\n }\n }\n\n def calc(str: Array[Char]): Int = {\n str.foldLeft(0) { case (sum, ch) =>\n if(ch == '+') {\n sum + 1\n } else {\n sum - 1\n }\n }\n }\n\n def gen(ind: Int, str: Array[Char], finalPos: Int): Int = {\n if(ind == str.length) {\n if(calc(str) == finalPos) 1 else 0\n } else if (str(ind) != '?'){\n gen(ind + 1, str, finalPos)\n } else {\n var score = 0\n\n str(ind) = '+'\n score = gen(ind + 1, str, finalPos)\n\n str(ind) = '-'\n score += gen(ind + 1, str, finalPos)\n\n score\n }\n }\n}"}, {"source_code": "object B476 {\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 s1 = scala.io.StdIn.readLine\n val s2 = scala.io.StdIn.readLine\n val total = math.pow(2.0, s2.count(_ == '?'))\n val count = gen(0, s2.toCharArray, calc(s1.toCharArray))\n println(count.toDouble/total)\n }\n\n def calc(str: Array[Char]): Int = {\n str.foldLeft(0) { case (sum, ch) =>\n if(ch == '+') {\n sum + 1\n } else {\n sum - 1\n }\n }\n }\n\n def gen(ind: Int, str: Array[Char], finalPos: Int): Int = {\n if(ind == str.length) {\n if(calc(str) == finalPos) 1 else 0\n } else if (str(ind) != '?'){\n gen(ind + 1, str, finalPos)\n } else {\n var score = 0\n\n str(ind) = '+'\n score = gen(ind + 1, str, finalPos)\n\n str(ind) = '-'\n score += gen(ind + 1, str, finalPos)\n\n score\n }\n }\n}"}], "src_uid": "f7f68a15cfd33f641132fac265bc5299"} {"nl": {"description": "Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.Limak wants to prove how responsible a bear he is. He is going to regularly save candies for the entire year 2016! He considers various saving plans. He can save one candy either on some fixed day of the week or on some fixed day of the month.Limak chose one particular plan. He isn't sure how many candies he will save in the 2016 with his plan. Please, calculate it and tell him.", "input_spec": "The only line of the input is in one of the following two formats: \"x of week\" where x (1 ≤ x ≤ 7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. \"x of month\" where x (1 ≤ x ≤ 31) denotes the day of the month. ", "output_spec": "Print one integer — the number of candies Limak will save in the year 2016.", "sample_inputs": ["4 of week", "30 of month"], "sample_outputs": ["52", "11"], "notes": "NotePolar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – https://en.wikipedia.org/wiki/Gregorian_calendar. The week starts with Monday.In the first sample Limak wants to save one candy on each Thursday (the 4-th day of the week). There are 52 Thursdays in the 2016. Thus, he will save 52 candies in total.In the second sample Limak wants to save one candy on the 30-th day of each month. There is the 30-th day in exactly 11 months in the 2016 — all months but February. It means that Limak will save 11 candies in total."}, "positive_code": [{"source_code": "import scala.math._\nimport scala.collection.immutable.Range\nimport scala.io.Source\n\nobject a8 {\n def main(args: Array[String]): Unit = {\n val a = Array.iterate(4,366)(a=>(a + 1)%7).map(_+1)\n val b = Array(31,29,31,30,31,30,31,31,30,31,30,31).map(a=>(1 to a ).toArray)\n val line = Source.stdin.getLines().toArray.head.split(' ')\n val x = line(0).toInt\n println(line(2) match {\n case \"week\" => a.count(_ == x)\n case \"month\" => b.map(_.count(_ == x)).sum\n })\n //a.foreach(println)\n }\n\n}\n"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val Array(day, of, period) = in.next().split(' ')\n val d = day.toInt\n if (period == \"week\") {\n d match {\n case 6 => println(53)\n case 5 => println(53)\n case _ => println(52)\n }\n } else {\n d match {\n case 31 => println(7)\n case 30 => println(11)\n case _ => println(12)\n }\n }\n}"}, {"source_code": "object A611 {\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 t1 = tokenizeLine\n val input = Array.fill(3)(t1.nextToken)\n if(input.contains(\"week\")) {\n val day = input(0).toInt\n if(Array(1,2,3,4,7).contains(day))\n println(\"52\")\n else\n println(\"53\")\n } else {\n val day = input(0).toInt\n if(day <= 29) {\n println(\"12\")\n } else if (day == 30) {\n println(\"11\")\n } else {\n println(\"7\")\n }\n }\n }\n}"}, {"source_code": "import scala.collection._\n\nobject 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 ss = readLine.split(\" \")\n\n val n = ss(0).toInt\n if (ss(2) == \"week\") {\n val w = Seq(0, 52, 52, 52, 52, 53, 53, 52)\n println(w(n))\n } else {\n val x = if (n <= 29) 12 \n else if (n <= 30) 11\n else 7\n println(x)\n }\n}\n"}, {"source_code": "\n/**\n * @author pvasilyev\n * @since 05 May 2016\n */\nobject A611 extends App {\n\n val Array(x, y, z) = scala.io.StdIn.readLine().split(\" \")\n val n = x.toInt\n var answer = 0\n if (\"month\".equals(z)) {\n if (n < 30) {\n answer = 12\n } else if (n == 30) {\n answer = 11\n } else {\n answer = 7\n }\n } else {\n if (n == 5 || n == 6) {\n answer = 53\n } else {\n answer = 52\n }\n }\n\n println(answer)\n\n}\n"}, {"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 val of = sc.next()\n val span = sc.next()\n\n if(span == \"week\"){\n if(n == 7)\n println(52)\n else if(n >= 5)\n println(53)\n else\n println(52)\n }\n else if(span == \"month\"){\n if(n <= 29)\n println(12)\n else if(n == 30)\n println(11)\n else // n == 31\n println(7)\n }\n }\n}\n"}], "negative_code": [{"source_code": "import scala.math._\nimport scala.collection.immutable.Range\nimport scala.io.Source\n\nobject a8 {\n def main(args: Array[String]): Unit = {\n val a = Array.iterate(4,365)(a=>(a + 1)%7).map(_+1)\n val b = Array(31,28,31,30,31,30,31,31,30,31,30,31).map(a=>(1 to a ).toArray)\n val line = Source.stdin.getLines().toArray.head.split(' ')\n val x = line(0).toInt\n println(line(2) match {\n case \"week\" => a.count(_ == x)\n case \"month\" => b.map(_.count(_ == x)).sum\n })\n //b.foreach(println)\n }\n\n}\n"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val Array(day, of, period) = in.next().split(' ')\n val d = day.toInt\n if (period == \"week\") {\n d match {\n case 6 => println(53)\n case 5 => println(53)\n case _ => println(52)\n }\n } else {\n d match {\n case 31 => println(7)\n case 30 => println(11)\n case 29 => println(11)\n case _ => println(12)\n }\n }\n}"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val Array(day, of, period) = in.next().split(' ')\n val d = day.toInt\n if (period == \"week\") {\n d match {\n case 7 => println(53)\n case 6 => println(53)\n case _ => println(52)\n }\n } else {\n d match {\n case 31 => println(7)\n case 30 => println(11)\n case 29 => println(11)\n case _ => println(12)\n }\n }\n}"}, {"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 val of = sc.next()\n val span = sc.next()\n\n if(span == \"week\"){\n if(n >= 5)\n println(53)\n else\n println(52)\n }\n else if(span == \"month\"){\n if(n <= 29)\n println(12)\n else if(n == 30)\n println(11)\n else // n == 31\n println(7)\n }\n }\n}\n"}], "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b"} {"nl": {"description": "One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n. Let's assume that Misha chose number m, and Andrew chose number a.Then, by using a random generator they choose a random integer c in the range between 1 and n (any integer from 1 to n is chosen with the same probability), after which the winner is the player, whose number was closer to c. The boys agreed that if m and a are located on the same distance from c, Misha wins.Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and number n. You need to determine which value of a Andrew must choose, so that the probability of his victory is the highest possible.More formally, you need to find such integer a (1 ≤ a ≤ n), that the probability that is maximal, where c is the equiprobably chosen integer from 1 to n (inclusive).", "input_spec": "The first line contains two integers n and m (1 ≤ m ≤ n ≤ 109) — the range of numbers in the game, and the number selected by Misha respectively.", "output_spec": "Print a single number — such value a, that probability that Andrew wins is the highest. If there are multiple such values, print the minimum of them.", "sample_inputs": ["3 1", "4 3"], "sample_outputs": ["2", "2"], "notes": "NoteIn the first sample test: Andrew wins if c is equal to 2 or 3. The probability that Andrew wins is 2 / 3. If Andrew chooses a = 3, the probability of winning will be 1 / 3. If a = 1, the probability of winning is 0.In the second sample test: Andrew wins if c is equal to 1 and 2. The probability that Andrew wins is 1 / 2. For other choices of a the probability of winning is less."}, "positive_code": [{"source_code": "import scala.io.StdIn._\nobject B extends App{\n val Array(n,m) = readLine().split(\" \").map(_.toLong)\n if (2*m-1 >= n){\n println(Math.max(m-1,1))\n }else{\n println(Math.min(n,m+1))\n }\n}\n"}, {"source_code": "object B570 {\n\n import IO._\n\n def main(args: Array[String]): Unit = {\n val Array(n, m) = readInts(2)\n var maxAndrew = 0\n var res = n-m+1\n Array(m+1, m-1).foreach{\n case a if a > 0 && a <= n =>\n var andrew = 0\n if(a == m+1) {\n andrew = n - m - 1\n } else {\n andrew = m-1\n }\n if(andrew > maxAndrew) {\n maxAndrew = andrew\n res = a\n }\n case _ =>\n }\n println(res)\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"}, {"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 n = nextInt\n val m = nextInt\n if (n == 1) {\n out.println(1)\n return 0\n }\n val abs = n - m\n if (abs > m) {\n out.println(m + 1)\n } else if (abs < m){\n out.println(m - 1)\n } else {\n out.println(m + 1)\n }\n return 0\n }\n}\n"}, {"source_code": "import io.StdIn._\nimport scala.collection.mutable\nimport scala.collection.mutable._\n\nobject Solution {\n\n def main(args: Array[String]) {\n val Array(n, m) = readLine().split(\" \").map(_.toInt)\n\n println (if (m <= n/2) Math.min(n,m+1) else Math.max(1,m-1))\n }\n}\n"}, {"source_code": "import annotation.tailrec, collection.mutable, util._, control.Breaks._, math.Ordering.Implicits._\nimport CodeForcesApp._\nobject _570B extends CodeForcesApp[Int]({scanner => import scanner._\n val (n, m) = (nextInt, nextInt)\n (n, m) match {\n case (1, _) => 1\n case (_, 1) => 2\n case (_, `n`) => n-1\n case _ => m + (if (m <= n / 2) 1 else -1)\n }\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 import scala.collection.mutable.{Map => Dict}\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 modulus: Int = 1000000007\n final val eps: Double = 1e-9\n final def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None\n final def repeat[A](n: Int)(f: => A): Seq[A] = 1 to n map {_ => f}\n final def newCounter[A]: Dict[A, Int] = Dict.empty[A, Int] withDefaultValue 0\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject SomeTest extends App {\n val Array(n, m) = readLine().split(\" \").map(_.toLong)\n\n if (n == 1) println(1)\n else if (n - m > m - 1) {\n println(m + 1)\n } else {\n println(m - 1)\n }\n}"}, {"source_code": "\nimport scala.io.StdIn.readLine\nimport scala.io.StdIn.readInt\n\n\nobject SimpleGame {\n \n def readInts() : Array[Int] =\n readLine.split(' ').map(_.toInt)\n \n def readTuple() : (Int,Int) = {\n val line = readInts\n (line(0),line(1))\n }\n def readTriple() : (Int,Int,Int) = {\n val line = readInts\n (line(0),line(1),line(2))\n }\n \n \n def main(args: Array[String]) {\n val (n,m) = readTuple()\n if (m <= n/2) println(Math.min(m+1,n)) else println(Math.max(m-1,1))\n }\n \n}"}], "negative_code": [{"source_code": "import scala.io.StdIn._\nobject B extends App{\n val Array(n,m) = readLine().split(\" \").map(_.toInt)\n if (2*m-1 >= n){\n println(m-1)\n }else{\n println(m+1)\n }\n}\n"}, {"source_code": "import scala.io.StdIn._\nobject B extends App{\n val Array(n,m) = readLine().split(\" \").map(_.toLong)\n if (2*m-1 >= n){\n println(m-1)\n }else{\n println(m+1)\n }\n}\n"}, {"source_code": "import scala.io.StdIn._\nobject B extends App{\n val Array(n,m) = readLine().split(\" \").map(_.toLong)\n if (2*m-1 >= n){\n println(Math.max(m-1,0))\n }else{\n println(Math.min(n,m+1))\n }\n}\n"}, {"source_code": "import scala.io.StdIn._\nobject B extends App{\n val Array(n,m) = readLine().split(\" \").map(_.toInt)\n if (2*m-1 <= n){\n println(m+1)\n }else{\n println(m-1)\n }\n}\n"}, {"source_code": "object B570 {\n\n import IO._\n\n def main(args: Array[String]): Unit = {\n val Array(n, m) = readInts(2)\n var maxAndrew = 0\n var res = 0\n Array(m+1, m-1).foreach{\n case a if a > 1 && a <= n =>\n var andrew = 0\n if(a == m+1) {\n andrew = n - (m+1)\n } else {\n andrew = m-1\n }\n if(andrew > maxAndrew) {\n maxAndrew = andrew\n res = a\n }\n case _ =>\n }\n println(res)\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"}, {"source_code": "object B570 {\n\n import IO._\n\n def main(args: Array[String]): Unit = {\n val Array(n, m) = readInts(2)\n var maxAndrew = 0\n var res = 1\n Array(m+1, m-1).foreach{\n case a if a > 0 && a <= n =>\n var andrew = 0\n if(a == m+1) {\n andrew = n - m\n } else {\n andrew = a\n }\n if(andrew > maxAndrew) {\n maxAndrew = andrew\n res = a\n }\n case _ =>\n }\n println(res)\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"}, {"source_code": "object B570 {\n\n import IO._\n\n def main(args: Array[String]): Unit = {\n val Array(n, m) = readInts(2)\n var maxAndrew = 0\n var res = 1\n Array(m+1, m-1).foreach{\n case a if a > 1 && a <= n =>\n var andrew = 0\n if(a == m+1) {\n andrew = n - (m+1)\n } else {\n andrew = m-1\n }\n if(andrew > maxAndrew) {\n maxAndrew = andrew\n res = a\n }\n case _ =>\n }\n println(res)\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"}, {"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 n = nextInt\n val m = nextInt\n if (n == 1) {\n out.println(1)\n return 0\n }\n val abs: Int = Math.abs(n - m)\n if (abs > m) {\n out.println(m + 1)\n } else if (abs < m){\n out.println(m - 1)\n } else {\n out.println(m - 1)\n }\n return 0\n }\n}\n"}, {"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 n = nextInt\n val m = nextInt\n if (n == 1) {\n out.println(1)\n return 0\n }\n val mid = n / 2 + n % 2\n if (m > mid) {\n out.println(mid)\n } else if (m < mid) {\n out.println(m + 1)\n } else {\n out.println(m - 1)\n }\n return 0\n }\n}\n"}, {"source_code": "import io.StdIn._\nimport scala.collection.mutable\nimport scala.collection.mutable._\n\nobject Solution {\n\n def main(args: Array[String]) {\n val Array(n, m) = readLine().split(\" \").map(_.toInt)\n\n println (if (m < (n+1)/2) m+1 else m-1)\n }\n}\n"}, {"source_code": "import io.StdIn._\nimport scala.collection.mutable\nimport scala.collection.mutable._\n\nobject Solution {\n\n def main(args: Array[String]) {\n val Array(n, m) = readLine().split(\" \").map(_.toInt)\n\n println (if (m <= n/2) m+1 else m-1)\n }\n}\n"}, {"source_code": "import annotation.tailrec, collection.mutable, util._, control.Breaks._, math.Ordering.Implicits._\nimport CodeForcesApp._\nobject _570B extends CodeForcesApp[Int]({scanner => import scanner._\n val (n, m) = (nextInt, nextInt)\n if (m < n/2) {\n m+1\n } else if (m > n/2) {\n m-1\n } else {\n if (n%2 == 1) m+1 else m-1\n }\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 import scala.collection.mutable.{Map => Dict}\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 modulus: Int = 1000000007\n final val eps: Double = 1e-9\n final def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None\n final def repeat[A](n: Int)(f: => A): Seq[A] = 1 to n map {_ => f}\n final def newCounter[A]: Dict[A, Int] = Dict.empty[A, Int] withDefaultValue 0\n}\n"}, {"source_code": "import annotation.tailrec, collection.mutable, util._, control.Breaks._, math.Ordering.Implicits._\nimport CodeForcesApp._\nobject _570B extends CodeForcesApp[Int]({scanner => import scanner._\n val (n, m) = (nextInt, nextInt)\n (n, m) match {\n case (1, _) => 1\n case (2, 1) => 2\n case (2, 2) => 1\n case (3, 1) => 2\n case (3, 2) => 1\n case (3, 3) => 1\n case _ if m <= n/2 => m+1\n case _ if m > n/2 => m-1\n }\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 import scala.collection.mutable.{Map => Dict}\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 modulus: Int = 1000000007\n final val eps: Double = 1e-9\n final def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None\n final def repeat[A](n: Int)(f: => A): Seq[A] = 1 to n map {_ => f}\n final def newCounter[A]: Dict[A, Int] = Dict.empty[A, Int] withDefaultValue 0\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject B extends App {\n val Array(n, m) = readLine().split(\" \").map(_.toLong)\n val Half = Math.ceil(n / 2.0).toLong\n\n if (m >= Half) {\n println(m - 1)\n } else {\n println(m + 1)\n }\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject B extends App {\n val Array(n, m) = readLine().split(\" \").map(_.toLong)\n val Half = Math.ceil(n / 2.0)\n\n if (m >= Half) {\n println(m - 1)\n } else if (m < Half) {\n println(m + 1)\n }\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject B extends App {\n val Array(n, m) = readLine().split(\" \").map(_.toLong)\n val Half = Math.ceil(n / 2.0)\n\n if (n == 1) println(1)\n else if (m >= Half) {\n println(m - 1)\n } else if (m < Half) {\n println(m + 1)\n }\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject B extends App {\n val Array(n, m) = readLine().split(\" \").map(_.toLong)\n val Half = Math.ceil(n / 2.0).toInt\n\n if (m >= Half) {\n println(m - 1)\n } else {\n println(m + 1)\n }\n}\n"}, {"source_code": "\nimport scala.io.StdIn.readLine\nimport scala.io.StdIn.readInt\n\n\nobject SimpleGame {\n \n def readInts() : Array[Int] =\n readLine.split(' ').map(_.toInt)\n \n def readTuple() : (Int,Int) = {\n val line = readInts\n (line(0),line(1))\n }\n def readTriple() : (Int,Int,Int) = {\n val line = readInts\n (line(0),line(1),line(2))\n }\n \n \n def main(args: Array[String]) {\n val (n,m) = readTuple()\n if (m <= n/2) println(m+1) else println(m-1)\n }\n \n}"}], "src_uid": "f6a80c0f474cae1e201032e1df10e9f7"} {"nl": {"description": "Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?", "input_spec": "The single line contains four space-separated integers n, m, a, b (1 ≤ n, m, a, b ≤ 1000) — the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket. ", "output_spec": "Print a single integer — the minimum sum in rubles that Ann will need to spend.", "sample_inputs": ["6 2 1 2", "5 2 2 3"], "sample_outputs": ["6", "8"], "notes": "NoteIn the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets."}, "positive_code": [{"source_code": "object Main extends App {\n val in = readLine\n val Array(n, m, a, b) = in.split(\" \").map(_.toInt)\n if (m * a <= b)\n println(a * n)\n else \n println((n / m) * b + (if (n % m > 0) Math.min(b, n % m * a) else 0))\n}"}, {"source_code": "object Main {\n def main(args: Array[String]): Unit = {\nval Array(n,m,a,b) = scala.io.StdIn.readLine().split(' ').map(_.toInt)\nprintln(scala.math.min(n/m*b+scala.math.min(n%m*a, b), n*a))\n }\n }"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val Array(n, m, a, b) = in.next().split(\" \").map(_.toInt)\n if (m * a <= b)\n println(a * n)\n else {\n println((n / m) * b + (if (n % m > 0) Math.min(b, n % m * a) else 0))\n }\n\n}\n"}, {"source_code": "import scala.collection.JavaConversions._\n\n\nobject Codeforces466A {\n def main(args: Array[String]) {\n val Array(n, m, a, b) = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n if (b.toFloat/m > a) {\n println(n*a)\n }\n else {\n val x = n / m\n val y = n % m\n if (y > 0) {\n if (y*a < b)\n println(x*b + y*a)\n else\n println(x*b + b)\n }\n else\n println(x*b)\n }\n }\n}"}, {"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 def main(args: Array[String]): Unit = {\n val Array(n, m, a, b) = readLine.split(\" \").map(_.toInt)\n\n var ans = Int.MaxValue\n for(i <- 0 to n){\n var by_one = i\n var by_one_price = by_one * a\n\n var remained_tickets = n - i\n if(remained_tickets >= 0){\n var by_m = (remained_tickets + (m - 1)) / m\n var by_m_price = by_m * b\n\n ans = Array(ans, by_one_price + by_m_price).min\n }\n }\n\n println(ans)\n }\n}"}, {"source_code": "object A466 {\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, m, a, b) = readInts(4)\n\n var res = n * a\n res = math.min(res, b*(if(n%m == 0) n/m else n/m + 1) )\n res = math.min(res, if(n%m == 0) b*(n/m) else b*(n/m) + a*(n%m))\n println(res)\n }\n}"}, {"source_code": "\nimport java.util._\nimport java.io._\nimport java.util\nimport scala.annotation.tailrec\n\nobject A {\n\n var out: PrintWriter = null\n var br: BufferedReader = null\n var st: StringTokenizer = null\n var ans = 0\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 n = nextInt\n val m = nextInt\n val a = nextInt\n val b = nextInt\n var min = Int.MaxValue\n for (i <- 0 to n / m + 1) {\n var temp = i * b\n val x: Int = n - (i * m)\n if ( x > 0) {\n temp += x * a\n }\n min = Math.min(min, temp)\n }\n out.println(min)\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"}, {"source_code": "\n\nobject CheapTravel {\n\tdef main (args: Array[String]) {\n\t\t//Parsing the input\n\t\tval scanner = new java.util.Scanner(System.in);\n\t\tval n = scanner.nextInt();\n\t\tval m = scanner.nextInt();\n\t\tval a = scanner.nextInt();\n\t\tval b = scanner.nextInt();\n\t\t// Check whether it is cheaper to buy m-rides tickets\n\t\tif (a*m >= b) {\n\t\t val lastTicket = if ((n%m * a) < b) n%m*a else b\n\t\t\tprintln(n / m * b + lastTicket)\n\t\t}\n\t\telse\n\t\t\tprintln(n * a)\n\t}\n}"}, {"source_code": "object Main {\n def main(args: Array[String]) = {\n val cin = new java.util.Scanner(System.in)\n val n = cin.nextInt()\n val m = cin.nextInt()\n val a = cin.nextInt()\n val b = cin.nextInt()\n println(Math.min(Math.min(n * a, (n / m) * b + (n % m) * a), ((n + m - 1) / m) * b))\n }\n}\n"}, {"source_code": "//package xubiker.archive\n \nimport java.util.Scanner\n\nobject Task_466A extends App {\n\n val sc = new Scanner(System.in)\n\n val n = sc.nextInt()\n val m = sc.nextInt()\n val a = sc.nextInt()\n val b = sc.nextInt()\n\n sc.close()\n\n val price1 = (Math.ceil(n.toDouble / m) * b).toInt\n val price2 = a * n\n val price3 = (n / m) * b + (n % m) * a\n\n val price = price1.min(price2.min(price3))\n println(price)\n\n}\n"}, {"source_code": "\nimport scala.io.StdIn.readLine\nimport scala.io.StdIn.readInt\n\n\nobject CheapTravel {\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 \n def main(args: Array[String]) {\n val (n,m,a,b) = readQuad()\n val pricePerRide = b.toDouble/m\n if (pricePerRide >= a) println(a*n) // always by single tickets\n else { \n val priceRem = if ( (n%m)*a <= b) (n%m)*a else b\n println( (n/m)*b + priceRem)\n }\n }\n \n}"}, {"source_code": "object Main extends App {\n val in = readLine\n val Array(n, m, a, b) = in.split(\" \").map(_.toInt)\n if (m * a <= b)\n println(a * n)\n else \n println((n / m) * b + (if (n % m > 0) Math.min(b, n % m * a) else 0))\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject Main2 extends App {\n val Array(ridesNumber, subscriptionRidesNumber, ridePrice, subscriptionPrice) = readLine().split(\" \").map(_.toInt)\n val ans = if (subscriptionRidesNumber * ridePrice > subscriptionPrice) {\n val priceWithGreedySubscriptions = (ridesNumber/subscriptionRidesNumber) * subscriptionPrice\n val remainingRides = ridesNumber%subscriptionRidesNumber\n if (remainingRides * ridePrice < subscriptionPrice) {\n priceWithGreedySubscriptions + remainingRides * ridePrice\n } else {\n priceWithGreedySubscriptions + subscriptionPrice\n }\n } else {\n ridesNumber * ridePrice\n }\n println(ans)\n}\n"}, {"source_code": "import scala.util.Sorting\nimport scala.io.StdIn\n\nobject App {\n\n\n def main(args: Array[String]) {\n\n val Array(n,m,a,b) = StdIn.readLine().split(\" \").map(_.toInt)\n\n\n\n var ans = 10000000;\n for(i <- 0 to 1000) {\n ans = math.min(ans, b * i + math.max(n - m * i,0) * a)\n }\n\n println(ans)\n\n\n }\n\n\n}\n"}], "negative_code": [{"source_code": "object Main {\n def main(args: Array[String]): Unit = {\nval Array(n,m,a,b) = scala.io.StdIn.readLine().split(' ').map(_.toInt)\nprintln(n/m*b+n%m*a)\n }\n }\n"}, {"source_code": "import scala.io.StdIn\n\nobject Task466A {\n\tdef main(args: Array[String]) {\n\t\tval nmab = StdIn.readLine().split(\" \").map(_.toInt)\n\t\tif (nmab(3).toDouble / nmab(1) < nmab(2))\n\t\t\tprintln(nmab(0) / nmab(1) * nmab(3) + Math.min(nmab(2), nmab(3)))\n\t\telse println(nmab(0) * nmab(2))\n\t}\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject Task466A {\n\tdef main(args: Array[String]) {\n\t\tval nmab = StdIn.readLine().split(\" \").map(_.toInt)\n\t\tif (nmab(3).toDouble / nmab(1) < nmab(2))\n\t\t\tprintln(nmab(0) / nmab(1) * nmab(3) + nmab(0) % nmab(1) * Math.min(nmab(2), nmab(3)))\n\t\telse println(nmab(0) * nmab(2))\n\t}\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject Task466A {\n\tdef main(args: Array[String]) {\n\t\tval nmab = StdIn.readLine().split(\" \").map(_.toInt)\n\t\tprintln(if (nmab(3).toDouble / nmab(1) < nmab(2))\n\t\t\tif (nmab(0).toDouble / nmab(1) < 1) nmab(3)\n\t\t\telse nmab(0) / nmab(1) * nmab(3) + nmab(0) % nmab(1) * Math.min(nmab(2), nmab(3))\n\t\telse nmab(0) * nmab(2))\n\t}\n}\n"}, {"source_code": "import scala.collection.JavaConversions._\n\n\nobject Codeforces468A {\n def main(args: Array[String]) {\n val Array(n, m, a, b) = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n if (m.toFloat/b > a) {\n println(n*a)\n }\n else {\n println((n/m)*b + (n%m)*a)\n }\n }\n}"}, {"source_code": "import scala.collection.JavaConversions._\n\n\nobject Codeforces466A {\n def main(args: Array[String]) {\n val Array(n, m, a, b) = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n if (m.toFloat/b > a) {\n println(n*a)\n }\n else {\n val x = n / m\n val y = n % m\n if (y*a < b)\n println((n/m)*b + (n%m)*a)\n else\n println((n/m)*b + b)\n }\n }\n}"}, {"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 def main(args: Array[String]): Unit = {\n val Array(n, m, a, b) = readLine.split(\" \").map(_.toInt)\n\n var ans = Int.MaxValue\n for(i <- 0 to n){\n var by_one = i\n var by_one_price = by_one * a\n\n var remained_tickets = n - i\n if(remained_tickets > 0){\n var by_m = (remained_tickets + (m - 1)) / m\n var by_m_price = by_m * b\n\n ans = Array(ans, by_one_price + by_m_price).min\n }\n }\n\n println(ans)\n }\n}"}, {"source_code": "import java.util._\nimport java.io._\nimport java.util\nimport scala.annotation.tailrec\n\nobject A {\n\n var out: PrintWriter = null\n var br: BufferedReader = null\n var st: StringTokenizer = null\n var ans = 0\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 n = nextInt\n val m = nextInt\n val a = nextInt\n val b = nextInt\n var min = Int.MaxValue\n for (i <- 0 to n / m) {\n min = Math.min(min, i * b + (n - (i * m)) * a)\n }\n out.println(min)\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"}, {"source_code": "\nimport java.util._\nimport java.io._\nimport java.util\nimport scala.annotation.tailrec\n\nobject A {\n\n var out: PrintWriter = null\n var br: BufferedReader = null\n var st: StringTokenizer = null\n var ans = 0\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 n = nextInt\n val m = nextInt\n val a = nextInt\n val b = nextInt\n out.println(Math.min(n * a, (n / m) * b + (n % m) * a))\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"}, {"source_code": "\n\nobject CheapTravel {\n\tdef main (args: Array[String]) {\n\t\t//Parsing the input\n\t\tval scanner = new java.util.Scanner(System.in);\n\t\tval n = scanner.nextInt();\n\t\tval m = scanner.nextInt();\n\t\tval a = scanner.nextInt();\n\t\tval b = scanner.nextInt();\n\t\t// Check whether it is cheaper to buy m-rides tickets\n\t\tif (a*m >= b) \n\t\t\tprintln(n / m * b + n%m * a)\n\t\t\telse\n\t\t\t\tprintln(n * a)\n\t}\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject Main2 extends App {\n val Array(ridesNumber, subscriptionRidesNumber, ridePrice, subscriptionPrice) = readLine().split(\" \").map(_.toInt)\n val ans = if (subscriptionRidesNumber * ridePrice > subscriptionPrice) {\n val subscriptionsPrice = (ridesNumber/subscriptionRidesNumber) * subscriptionPrice\n val remainingRides = (ridesNumber%subscriptionRidesNumber)\n if (remainingRides * ridePrice < subscriptionsPrice) {\n subscriptionsPrice + remainingRides * ridePrice\n } else {\n subscriptionsPrice + subscriptionPrice\n }\n } else {\n ridesNumber * ridePrice\n }\n println(ans)\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject Main2 extends App {\n val Array(ridesNumber, subscriptionRidesNumber, ridePrice, subscriptionPrice) = readLine().split(\" \").map(_.toInt)\n val ans = if (subscriptionRidesNumber * ridePrice > subscriptionPrice) {\n (ridesNumber/subscriptionRidesNumber) * subscriptionPrice + (ridesNumber%subscriptionRidesNumber) * ridePrice\n } else {\n ridesNumber * ridePrice\n }\n println(ans)\n}\n"}, {"source_code": "import scala.util.Sorting\nimport scala.io.StdIn\n\nobject App {\n\n\n def main(args: Array[String]) {\n\n val Array(n,m,a,b) = StdIn.readLine().split(\" \").map(_.toInt)\n\n\n\n var ans = 10000;\n for(i <- 0 to 1000) {\n ans = math.min(ans, b * i + math.max(n - m * i,0) * a)\n }\n\n println(ans)\n\n\n }\n\n\n}\n"}], "src_uid": "faa343ad6028c5a069857a38fa19bb24"} {"nl": {"description": "Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements: one resistor; an element and one resistor plugged in sequence; an element and one resistor plugged in parallel. With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals . In this case Re equals the resistance of the element being connected.Mike needs to assemble an element with a resistance equal to the fraction . Determine the smallest possible number of resistors he needs to make such an element.", "input_spec": "The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction is irreducible. It is guaranteed that a solution always exists.", "output_spec": "Print a single number — the answer to the problem. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.", "sample_inputs": ["1 1", "3 2", "199 200"], "sample_outputs": ["1", "3", "200"], "notes": "NoteIn the first sample, one resistor is enough.In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance . We cannot make this element using two resistors."}, "positive_code": [{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val data = in.next().split(' ').map(_.toLong)\n var (a, b) = if (data.head % data.last == 0) (data.head /data.last, 1l) else (data.head, data.last)\n var r = 0l\n while (b > 0) {\n r += a / b\n val newB = a % b\n a = b\n b = newB\n }\n println(r)\n}"}, {"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 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 def cnt(a: Long, b: Long): Long = {\n //println(a, b)\n if (a == 0L || b == 0L) 0L\n else if (a == 1L) b\n else if (b == a) 1L\n else if (b == 1L) a\n else if (a > b) a / b + cnt(a % b, b)\n else b / a + cnt(b % a, a)\n }\n\n val Array(a, b) = readLongs(2)\n\n println(cnt(a, b))\n}"}, {"source_code": "object C344 {\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(a, b) = readLongs(2)\n println(rec(a, b))\n }\n def rec(a: Long, b: Long): Long = {\n if(a == 1 || b == 1) {\n a+b-1\n } else {\n if (a > b) {\n (a / b) + rec(b, a%b)\n } else {\n rec(b, a)\n }\n }\n }\n}"}, {"source_code": "object C extends App {\n\n def readString = Console.readLine\n def tokenizeLine = new java.util.StringTokenizer(readString)\n def readLongs(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toLong) }\n \n def cnt(a: Long, b: Long): Long = {\n if (a == 1L) b\n else if (a > b) a / b + cnt(a % b, b)\n else cnt(b, a)\n }\n\n val Array(a, b) = readLongs(2)\n\n println(cnt(a, b))\n}"}], "negative_code": [{"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 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 def cnt(a: Long, b: Long): Long = {\n //println(a, b)\n if (a == 0L || b == 0L) 0L\n //else if (a == 1L) b\n else if (b == a) 1L\n else if (b == 1L) a\n else if (a > b) (a - b) + cnt(a % b, b)\n else (b - a) + cnt(b % a, a)\n }\n\n val Array(a, b) = readLongs(2)\n\n println(cnt(a, b))\n}"}, {"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 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 def cnt(a: Long, b: Long): Long = {\n //println(a, b)\n if (a == 0L || b == 0L) 0L\n else if (a == 1L) b\n else if (b == a) 1L\n else if (b == 1L) a\n else if (a > b) (a - b) + cnt(a % b, b)\n else (b - a) + cnt(b % a, a)\n }\n\n val Array(a, b) = readLongs(2)\n\n println(cnt(a, b))\n}"}, {"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 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 def cnt(a: Long, b: Long): Long = {\n //println(a, b)\n if (a == 0L || b == 0L) 0L\n else if (a == 1L) b\n else if (b == a) 1L\n else if (a > b) (a - b) + cnt(a % b, b)\n else (b - a) + cnt(b % a, a)\n }\n\n val Array(a, b) = readLongs(2)\n\n println(cnt(a, b))\n}"}, {"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 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 def cnt(a: Long, b: Long): Long = {\n //println(a, b)\n /*if (a == 1L) b\n else*/ if (b == 1L) 1L\n else if (a > b) (a - b) + cnt(a % b, b)\n else (b - a) + cnt(b % a, a)\n }\n\n val Array(a, b) = readLongs(2)\n\n println(cnt(a, b))\n}"}, {"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 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 def cnt(a: Long, b: Long): Long = {\n //println(a, b)\n if (a == 1L) b\n else if (b == 1L) 1L\n else if (a > b) (a - b) + cnt(a % b, b)\n else cnt(b, a)\n }\n\n val Array(a, b) = readLongs(2)\n\n println(cnt(a, b))\n}"}], "src_uid": "792efb147f3668a84c866048361970f8"} {"nl": {"description": "Some country is populated by wizards. They want to organize a demonstration.There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least y percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only n people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than y percent of the city people.", "input_spec": "The first line contains three space-separated integers, n, x, y (1 ≤ n, x, y ≤ 104, x ≤ n) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city ( > n).", "output_spec": "Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than y percent of n (the real total city population). ", "sample_inputs": ["10 1 14", "20 10 50", "1000 352 146"], "sample_outputs": ["1", "0", "1108"], "notes": "NoteIn the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones."}, "positive_code": [{"source_code": "object Solver {\n def main(args: Array[String]) {\n var input = Console.readLine.split(\" \").map(x => x.toInt)\n var n = input(0); var x = input(1); var y = input(2);\n\n var required = Math.ceil(n * y / 100.0).toInt\n var clones = if (required > x) required - x else 0\n println(clones)\n }\n}\n"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val Array(n, x, y) = in.next().split(\" \").map(_.toInt)\n println(Range(0, 1000 * 1000 + 1).find(i => (i + x) * 100 / n >= y).get)\n}"}, {"source_code": "import scala.math\nobject Main\n{\n\tdef up(a:Double):Int = \n\t{\n\t\tif(a.floor == a)\n\t\t\treturn a.floor.toInt\n\t\treturn (a.floor.toInt + 1)\n\t}\n\n\tdef main(args:Array[String])\n\t{\n\t\tval rd = readLine.split(\" \").map(i => i.toInt);\n\t\tval n = rd(0)\n\t\tval x = rd(1)\n\t\tval y = rd(2)\n\t\t\n\t\tval cl = up((n / 100.0) * y - x)\n\t\tif (cl < 0)\n\t\t\tprintln(0)\n\t\telse \n\t\t\tprintln(cl)\n\t}\n}"}, {"source_code": "import java.util.Scanner\n\nobject A {\n def main(args: Array[String]) {\n val sc = new java.util.Scanner(System.in)\n val n, x, y = sc.nextInt()\n println(math.max(0, (n*y+99)/100-x))\n }\n}\n\n"}, {"source_code": "import java.util.Scanner\nobject A {\n def main(args: Array[String]) {\n val sc = new java.util.Scanner(System.in)\n val n, x, y = sc.nextInt()\n val s = n * y - x * 100\n if (s <= 0) println(0)\n else if(s % 100 == 0) println(s / 100)\n else println((s + 100) / 100)\n }\n}\n\n"}, {"source_code": "import java.util.Scanner\n\nobject A extends App {\n val sc = new java.util.Scanner(System.in)\n val n, x, y = sc.nextInt()\n println(math.max(0, (n*y+99)/100-x))\n}\n\n"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P168A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val N, X, Y = sc.nextInt\n\n val p = math.ceil(N * Y / 100.0).toInt - X\n\n out.println(if (p < 0) 0 else p)\n out.close\n}\n"}, {"source_code": "import annotation.tailrec\nimport java.io._\n\nobject Easy {\n val reader = new BufferedReader(new InputStreamReader(System.in))\n def readInts = reader.readLine().split(\" \").map(_.toInt)\n def readInt = reader.readLine().toInt\n\n val Array(n, x, y) = readInts\n def ceil(a: Int, b: Int) = a / b + (if(a % b == 0) 0 else 1)\n// def ans = ceil(n * y - 100 * x, 100) max 0\n def ans = (0.01 * n * y - 0.000001 - x).ceil.toInt max 0\n\n\n def main(args: Array[String]) {\n println(ans)\n }\n}\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val nxy = readLine().split(\" \").map(_.toInt)\n val n = nxy(0)\n val x = nxy(1)\n val y = nxy(2)\n println((((n * y + 99) / 100) - x).max(0))\n }\n}"}], "negative_code": [{"source_code": "import java.util.Scanner\nobject A {\n def main(args: Array[String]) {\n val sc = new java.util.Scanner(System.in)\n val n, x, y = sc.nextInt()\n if ((n * y - x * 100) <= 0) println(0)\n else println(((n * y - x * 100) / 100).ceil)\n }\n}\n\n"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P168A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val N, X, Y = sc.nextInt\n\n val answer = math.ceil(N * Y / 100.0).toInt - X\n\n out.println(answer)\n out.close\n}\n"}, {"source_code": "import annotation.tailrec\nimport java.io._\n\nobject Easy {\n val reader = new BufferedReader(new InputStreamReader(System.in))\n def readInts = reader.readLine().split(\" \").map(_.toInt)\n def readInt = reader.readLine().toInt\n\n val Array(n, x, y) = readInts\n def ceil(a: Int, b: Int) = a / b + (if(a % b == 0) 0 else 1)\n// def ans = ceil(n * y - 100 * x, 100) max 0\n def ans = (0.01 * n * y - 0.1 - x).ceil.toInt max 0\n\n\n def main(args: Array[String]) {\n println(ans)\n }\n}\n"}, {"source_code": "import annotation.tailrec\nimport java.io._\n\nobject Easy {\n val reader = new BufferedReader(new InputStreamReader(System.in))\n def readInts = reader.readLine().split(\" \").map(_.toInt)\n def readInt = reader.readLine().toInt\n\n val Array(n, x, y) = readInts\n def ceil(a: Int, b: Int) = a / b + (if(a % b == 0) 0 else 1)\n// def ans = ceil(n * y - 100 * x, 100) max 0\n def ans = (0.01 * n * y - x).ceil.toInt max 0\n\n\n def main(args: Array[String]) {\n println(ans)\n }\n}\n"}, {"source_code": "import annotation.tailrec\nimport java.io._\n\nobject Easy {\n val reader = new BufferedReader(new InputStreamReader(System.in))\n def readInts = reader.readLine().split(\" \").map(_.toInt)\n def readInt = reader.readLine().toInt\n\n val Array(n, x, y) = readInts\n def ceil(a: Int, b: Int) = a / b + (if(a % b == 0) 0 else 1)\n// def ans = ceil(n * y - 100 * x, 100) max 0\n def ans = (1.0 * n * y - x).ceil.toInt max 0\n\n\n def main(args: Array[String]) {\n println(ans)\n }\n}\n"}, {"source_code": "import annotation.tailrec\nimport java.io._\n\nobject Easy {\n val reader = new BufferedReader(new InputStreamReader(System.in))\n def readInts = reader.readLine().split(\" \").map(_.toInt)\n def readInt = reader.readLine().toInt\n\n val Array(n, x, y) = readInts\n def ceil(a: Int, b: Int) = a / b + (if(a % b == 0) 0 else 1)\n def ans = ceil(n * y - 100 * x, 100) max 0\n\n\n def main(args: Array[String]) {\n println(ans)\n }\n}\n"}], "src_uid": "7038d7b31e1900588da8b61b325e4299"} {"nl": {"description": "You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length.The output of the function f is another string of the same length. The i-th character of the output is equal to the minimum of the i-th character of s1 and the i-th character of s2.For example, f(\"ab\", \"ba\") = \"aa\", and f(\"nzwzl\", \"zizez\") = \"niwel\".You found two strings x and y of the same length and consisting of only lowercase English letters. Find any string z such that f(x, z) = y, or print -1 if no such string z exists.", "input_spec": "The first line of input contains the string x. The second line of input contains the string y. Both x and y consist only of lowercase English letters, x and y have same length and this length is between 1 and 100.", "output_spec": "If there is no string z such that f(x, z) = y, print -1. Otherwise, print a string z such that f(x, z) = y. If there are multiple possible answers, print any of them. The string z should be the same length as x and y and consist only of lowercase English letters.", "sample_inputs": ["ab\naa", "nzwzl\nniwel", "ab\nba"], "sample_outputs": ["ba", "xiyez", "-1"], "notes": "NoteThe first case is from the statement.Another solution for the second case is \"zizez\"There is no solution for the third case. That is, there is no z such that f(\"ab\", z) =  \"ba\"."}, "positive_code": [{"source_code": "/**\n * Created by moiseev on 21.04.2017.\n */\nobject Task2 extends App {\n\n import java.util.{Scanner}\n\n val in = new Scanner(System.in)\n\n val X = in.next\n val Y = in.next\n\n def middleChar( charLeft: Char, charRes: Char ): (Boolean,Char) = {\n if ( charLeft < charRes ) (false,' ')\n else {\n // a - 92 z - 122\n // charLeft - between 92 and 122\n // result should be between charLeft and 122 inclusive\n (\n true,if ( charLeft == charRes ) {\n val randRandge: Int = 122 - charLeft\n (charLeft.toInt + (if (randRandge > 0)scala.util.Random.nextInt(randRandge) else 0) ).toChar\n }\n else charRes\n )\n }\n }\n\n def findSecondString( strLeft:String, strRes: String ): (Boolean, String) = {\n if ( strLeft.size == 0 ) (true,\"\") // Finishing the recursion\n else if (strLeft.size != strRes.size )\n (false,\"\") // Strings are of different size - false definetly\n else {\n val (res, ch) = middleChar(strLeft.head, strRes.head)\n\n if (!res)\n (false, \"\") // Some i chars says they are not from our F()\n else {\n val (recRes, strRec) = findSecondString(strLeft.tail, strRes.tail)\n\n if (!recRes)\n (false, \"\") // Just to recursevly inform about failure\n else (true, ch + strRec)\n }\n }\n }\n\n val (resBool,resStr) = findSecondString(X,Y)\n if (resBool) {\n println(resStr)\n } else {\n println(-1)\n }\n}\n"}, {"source_code": "object _801B 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 x, z = read[String]\n\n val ans = Try{x.zip(z).map({case (a, b) => b.ensuring(b <= a)})}\n\n write(ans.map(_.mkString).getOrElse(\"-1\"))\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 }\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"}], "negative_code": [], "src_uid": "ce0cb995e18501f73e34c76713aec182"} {"nl": {"description": "You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 10$$$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $$$n$$$ distinct space-separated integers $$$x_1, x_2, \\ldots, x_n$$$ ($$$0 \\le x_i \\le 9$$$) representing the sequence. The next line contains $$$m$$$ distinct space-separated integers $$$y_1, y_2, \\ldots, y_m$$$ ($$$0 \\le y_i \\le 9$$$) — the keys with fingerprints.", "output_spec": "In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.", "sample_inputs": ["7 3\n3 5 7 1 6 2 8\n1 2 7", "4 4\n3 4 1 0\n0 1 7 9"], "sample_outputs": ["7 1 2", "1 0"], "notes": "NoteIn the first example, the only digits with fingerprints are $$$1$$$, $$$2$$$ and $$$7$$$. All three of them appear in the sequence you know, $$$7$$$ first, then $$$1$$$ and then $$$2$$$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.In the second example digits $$$0$$$, $$$1$$$, $$$7$$$ and $$$9$$$ have fingerprints, however only $$$0$$$ and $$$1$$$ appear in the original sequence. $$$1$$$ appears earlier, so the output is 1 0. Again, the order is important."}, "positive_code": [{"source_code": "import scala.collection.mutable._\nimport scala.io.StdIn\n\nobject Main {\n def main(arg: Array[String]) {\n var z = readLine().split(\" \")\n var n = z(0).toInt\n var m = z(1).toInt\n\n \n\n var x = readLine.split(\" \").map(_.toInt).toArray\n var y = readLine.split(\" \").map(_.toInt).toArray\n \n\n for(ele <- x){\n if(y contains ele) {\n print(ele + \" \")\n }\n }\n }\n}"}, {"source_code": "/**\n * @author ShankarShastri\n * Algorithm: ProblemA (http://codeforces.com/contest/994/problem/A)\n */\n\nimport scala.io.StdIn._\nimport scala.annotation.tailrec\n\nobject ProblemA {\n def main(args: Array[String]): Unit = {\n readLine\n val list = readLine.split(\" \").map(_.toInt).toList\n val keys = readLine.split(\" \").map(_.toInt).toList\n val res = keys.map(x => (x, list.indexOf(x))).filter(_._2 != -1).sortBy(_._2).map(_._1)\n println(res.mkString(\" \"))\n }\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject Main {\n def main(args: Array[String]): Unit = {\n StdIn.readLine()\n val a = StdIn.readLine().split(\" \")\n val b = StdIn.readLine().split(\" \")\n val c = a.filter(item => b.contains(item))\n c.foreach(item => print(item + \" \"))\n }\n}"}], "negative_code": [], "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72"} {"nl": {"description": "Vasily has a number a, which he wants to turn into a number b. For this purpose, he can do two types of operations: multiply the current number by 2 (that is, replace the number x by 2·x); append the digit 1 to the right of current number (that is, replace the number x by 10·x + 1). You need to help Vasily to transform the number a into the number b using only the operations described above, or find that it is impossible.Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform a into b.", "input_spec": "The first line contains two positive integers a and b (1 ≤ a < b ≤ 109) — the number which Vasily has and the number he wants to have.", "output_spec": "If there is no way to get b from a, print \"NO\" (without quotes). Otherwise print three lines. On the first line print \"YES\" (without quotes). The second line should contain single integer k — the length of the transformation sequence. On the third line print the sequence of transformations x1, x2, ..., xk, where: x1 should be equal to a, xk should be equal to b, xi should be obtained from xi - 1 using any of two described operations (1 < i ≤ k). If there are multiple answers, print any of them.", "sample_inputs": ["2 162", "4 42", "100 40021"], "sample_outputs": ["YES\n5\n2 4 8 81 162", "NO", "YES\n5\n100 200 2001 4002 40021"], "notes": null}, "positive_code": [{"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val Array(a, b) = in.next().split(' ').map(_.toLong)\n\n def solution(current: Long): List[Long] = {\n if (current == b)\n List(current)\n else if (current > b)\n List.empty\n else {\n val candidate = solution(current * 2)\n if (candidate.nonEmpty)\n current :: candidate\n else {\n val candidate2 = solution(current * 10 + 1)\n if (candidate2.isEmpty)\n List.empty\n else\n current :: candidate2\n }\n }\n }\n\n solution(a) match {\n case Nil => println(\"NO\")\n case list =>\n println(\"YES\")\n println(list.length)\n println(list.mkString(\" \"))\n }\n}"}], "negative_code": [], "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3"} {"nl": {"description": "Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, \"noon\", \"testset\" and \"a\" are all palindromes, while \"test\" and \"kitayuta\" are not.You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print \"NA\" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.", "input_spec": "The only line of the input contains a string s (1 ≤ |s| ≤ 10). Each character in s is a lowercase English letter.", "output_spec": "If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print \"NA\" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted. ", "sample_inputs": ["revive", "ee", "kitayuta"], "sample_outputs": ["reviver", "eye", "NA"], "notes": "NoteFor the first sample, insert 'r' to the end of \"revive\" to obtain a palindrome \"reviver\".For the second sample, there is more than one solution. For example, \"eve\" will also be accepted.For the third sample, it is not possible to turn \"kitayuta\" into a palindrome by just inserting one letter."}, "positive_code": [{"source_code": "import scala.io.StdIn\n\n/** A. Mr. Kitayuta's Gift\n * http://codeforces.com/contest/505/problem/A\n * @author Yuichiroh Matsubayashi\n * Created on 15/01/19.\n */\nobject P505A extends App {\n val letters = StdIn.readLine().toList\n val size = letters.size\n\n def solution = {\n def valid(size: Int, short: List[Char], long: List[Char], skipped: Int = -1, char: String = \"\"): (Int, String) = {\n if (long == Nil) (skipped, char)\n else if (short == Nil) (size - 1, long.mkString)\n else if (short.head == long.head) valid(size, short.tail, long.tail, skipped, char)\n else if (skipped < 0) valid(size, short, long.tail, size - long.size, long.head.toString)\n else (-1, \"\")\n }\n\n if (size % 2 == 0) {\n val (pre, post) = letters.splitAt(size / 2)\n if (pre == post) pre.mkString + post.head.toString + post.mkString\n else {\n val (skippedPre, cPre) = valid(pre.size, pre.reverse.tail, post)\n if (skippedPre >= 0) {\n val (ppre, ppost) = pre.splitAt(pre.size - skippedPre-1)\n ppre.mkString + cPre + ppost.mkString + post.mkString\n }\n else {\n val (skippedPost, cPost) = valid(post.size, post.tail, pre.reverse)\n if (skippedPost >= 0) {\n val (ppre, ppost) = post.splitAt(skippedPost+1)\n pre.mkString + ppre.mkString + cPost + ppost.mkString\n }\n else \"NA\"\n }\n }\n }\n else {\n val (pre, b) = letters.splitAt(size / 2)\n val (mid, post) = (b.head, b.tail)\n\n if (pre == post.reverse) pre.mkString + mid + mid + post.mkString\n else {\n val (skippedPre, cPre) = valid(pre.size + 1, pre.reverse, mid :: post)\n if (skippedPre >= 0) {\n val (ppre, ppost) = pre.splitAt(pre.size - skippedPre)\n ppre.mkString + cPre + ppost.mkString + mid + post.mkString\n }\n else {\n val (skippedPost, cPost) = valid(post.size + 1, post, mid :: pre.reverse)\n if (skippedPost >= 0) {\n val (ppre, ppost) = post.splitAt(skippedPost)\n pre.mkString + mid + ppre.mkString + cPost + ppost.mkString\n }\n else \"NA\"\n }\n }\n }\n }\n\n println(solution)\n}"}, {"source_code": "import scala.io.StdIn\n\n/** A. Mr. Kitayuta's Gift\n * http://codeforces.com/contest/505/problem/A\n * @author Yuichiroh Matsubayashi\n * Created on 15/01/19.\n */\nobject P505A extends App {\n val letters = StdIn.readLine().toList\n val size = letters.size\n\n def solution = {\n def valid(size: Int, short: List[Char], long: List[Char], skipped: Int = -1, char: String = \"\"): (Int, String) = {\n if (long == Nil) (skipped, char)\n else if (short == Nil) {\n if (skipped < 0) (size - 1, long.mkString)\n else {\n new NoSuchElementException\n (size, \"\")\n }\n }\n else if (short.head == long.head) valid(size, short.tail, long.tail, skipped, char)\n else if (skipped < 0) valid(size, short, long.tail, size - long.size, long.head.toString)\n else (-1, \"\")\n }\n\n if (size % 2 == 0) {\n val (pre, post) = letters.splitAt(size / 2)\n if (pre == post) pre.mkString + post.head.toString + post.mkString\n else {\n val (skippedPre, cPre) = valid(pre.size, pre.reverse.tail, post)\n if (skippedPre >= 0) {\n val (ppre, ppost) = pre.splitAt(pre.size - skippedPre-1)\n ppre.mkString + cPre + ppost.mkString + post.mkString\n }\n else {\n val (skippedPost, cPost) = valid(post.size, post.tail, pre.reverse)\n if (skippedPost >= 0) {\n val (ppre, ppost) = post.splitAt(skippedPost+1)\n pre.mkString + ppre.mkString + cPost + ppost.mkString\n }\n else \"NA\"\n }\n }\n }\n else {\n val (a, b) = letters.splitAt(size / 2)\n val (pre, mid, post) = (a.toList, b.head, b.tail)\n\n if (pre == post.reverse) pre.mkString + mid + mid + post.mkString\n else {\n\n val (skippedPre, cPre) = valid(pre.size + 1, pre.reverse, mid :: post)\n if (skippedPre >= 0) {\n val (ppre, ppost) = pre.splitAt(pre.size - skippedPre)\n ppre.mkString + cPre + ppost.mkString + mid + post.mkString\n }\n else {\n val (skippedPost, cPost) = valid(post.size + 1, post, mid :: pre.reverse)\n if (skippedPost >= 0) {\n val (ppre, ppost) = post.splitAt(skippedPost)\n pre.mkString + mid + ppre.mkString + cPost + ppost.mkString\n }\n else \"NA\"\n }\n }\n }\n }\n\n println(solution)\n}\n"}, {"source_code": "object A505 {\n\n import IO._\n import collection.{mutable => cu}\n def isPalin(str: String): Boolean = {\n (0 until str.length/2).forall(i => str(i) == str(str.length-i-1))\n }\n def main(args: Array[String]): Unit = {\n var str = read\n val n = str.length\n var break = false\n for(i <- 0 to n if !break) {\n for(j <- 'a' to 'z' if !break) {\n val (f, s) = str.splitAt(i)\n if(isPalin(f+j+s)) {\n str = f + j + s\n break = true\n }\n }\n }\n if(!break) {\n out.println(\"NA\")\n } else {\n out.println(str)\n }\n out.close()\n }\n\n object IO {\n private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n // private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(\"src/input\")))\n val out = new java.io.PrintWriter(System.out)\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"}, {"source_code": "\n/**\n * @author pvasilyev\n * @since 01 Aug 2016\n */\nobject A505 extends App {\n\n def palindrome(stringToCheck: String): Boolean = {\n for (i <- 0 until stringToCheck.length / 2 + 1) {\n if (stringToCheck.charAt(i) != stringToCheck.charAt(stringToCheck.length() - 1 - i)) {\n return false\n }\n }\n true\n }\n\n def solve() = {\n var pal: String = null\n val s: String = scala.io.StdIn.readLine()\n for (c <- 0 until 26 ) {\n val ch: Char = ('a'.toInt + c).toChar\n for (i <- 0 until s.length) {\n val stringToCheck = s.substring(0, i) + ch + s.substring(i)\n if (palindrome(stringToCheck)) {\n pal = stringToCheck\n }\n }\n if (palindrome(s + ch)) {\n pal = s + ch\n }\n }\n if (pal != null) {\n println(pal)\n } else {\n println(\"NA\")\n }\n }\n\n solve()\n\n}\n"}, {"source_code": "\nobject Main {\n def main(args: Array[String]) {\n val s:String=io.StdIn.readLine()\n println(solve(s))\n }\n def solve(s:String):String = {\n if (s.length==1)\n return s+s\n if (isPal(s))\n if (s.length%2==0) insert(s,'a',s.length/2) else insert(s,s(s.length/2),s.length/2)\n else {\n var i=0\n while (i h => acc\n case (l, h) => {\n if (str.charAt(l) == str.charAt(h))\n findInsertionPoints(str, l + 1, h - 1, acc)\n else {\n val loResult = findInsertionPoints(str, l, h - 1, acc :+ (l, str.charAt(h)))\n val hiResult = findInsertionPoints(str, l + 1, h, acc :+ (h + 1, str.charAt(l)))\n\n if (loResult.size < hiResult.size)\n loResult\n else\n hiResult\n }\n }\n }\n }\n\n val insertionPoints = findInsertionPoints(str, 0, str.length - 1)\n\n if (insertionPoints.size == 1) {\n val point = insertionPoints.head\n val newStr = str.substring(0, point._1) + point._2 + str.substring(point._1)\n out.println(newStr)\n } else if (insertionPoints.size == 0) {\n if (str.size % 2 == 0) {\n val newStr = str.substring(0, str.size / 2) + 'a' + str.substring(str.size / 2)\n out.println(newStr)\n } else {\n val newStr = str.substring(0, str.size / 2) + str.charAt(str.size / 2) + str.charAt(str.size / 2) + str.substring(str.size / 2 + 1)\n out.println(newStr)\n }\n } else {\n out.println(\"NA\")\n }\n }\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject Main {\n\n val chars = 'a' to 'z'\n\n def main(args: Array[String]): Unit = {\n val s = StdIn.readLine()\n for (c <- chars) {\n for (pos <- Range(0, s.length + 1)) {\n val splitted = s.splitAt(pos)\n val newS = splitted._1 + c + splitted._2\n if(newS == newS.reverse) {\n println(newS)\n return\n }\n }\n }\n println(\"NA\")\n return\n }\n}"}, {"source_code": "object Main extends App {\n val word = readLine\n def morph(s: String): Option[Char] = {\n val d = s.size / 2\n val dir = s take d\n val back = s.reverse take d\n (dir zip back).foldLeft[Option[Char]](Some('*'))({\n case (None, _) => None\n case (_, ('*', c2)) => Some(c2)\n case (_, (c1, '*')) => Some(c1)\n case (acc, (c1, c2)) if c1==c2 => acc\n case _ => None\n })\n }\n\n (word.inits.toList.zip(word.tails.toList.reverse)).map({\n case (start, end) => {\n val v = List(start, \"*\", end).mkString\n (v, morph(v))\n }\n }).filter({ case (_, None) => false; case _ => true }).headOption match {\n case None => println(\"NA\")\n case Some((v, Some(r))) => println(v.replace(\"*\", if(r == '*') \"a\" else r.toString))\n }\n}"}, {"source_code": "import scala.io.StdIn._\n\nobject Main extends App {\n val s = readLine\n val n = s.length\n\n def ans: String = {\n var mp = 0\n while (mp < n && s(mp) == s(n - 1 - mp)) {\n mp += 1\n }\n\n val anyChar = \"a\"\n val noAns = \"NA\"\n\n def getForEven: String = {\n def getLeft: Option[Int] = {\n var mid = n / 2 - 1\n var i = 1\n while (mid - i >= 0 && s(mid - i) == s(mid + i)) {\n i += 1\n }\n mid -= i - 1\n\n (0 to n / 2 - 1).find(i => i <= mp && i >= mid)\n }\n\n def getRight: Option[Int] = {\n var mid = n / 2\n var i = 1\n while (mid + i < n && s(mid - i) == s(mid + i)) {\n i += 1\n }\n mid += i - 1\n\n (n / 2 + 1 to n).find(i => n - i <= mp && i - 1 <= mid)\n }\n\n val fromLeft = getLeft\n if (fromLeft.isDefined) {\n val pos = fromLeft.get\n return s.substring(0, pos) + s(n - 1 - pos) + s.substring(pos)\n }\n\n val fromRight = getRight\n if (fromRight.isDefined) {\n val pos = fromRight.get\n return s.substring(0, pos) + s(n - pos) + s.substring(pos)\n }\n\n if (mp >= n / 2)\n s.substring(0, n / 2) + anyChar + s.substring(n / 2)\n else\n noAns\n }\n\n def getForOdd: String = {\n def getLeft: Option[Int] = {\n var mid = n / 2 - 1\n if (s(mid) != s(mid + 1)) {\n return Option.empty\n }\n\n var i = 1\n while (mid - i >= 0 && s(mid - i) == s(mid + 1 + i)) {\n i += 1\n }\n mid -= i - 1\n\n (0 to n / 2 - 1).find(i => i <= mp && i >= mid)\n }\n\n def getRight: Option[Int] = {\n var mid = n / 2 + 1\n if (s(mid - 1) != s(mid)) {\n return Option.empty\n }\n\n var i = 1\n while (mid + i < n && s(mid - 1 - i) == s(mid + i)) {\n i += 1\n }\n mid += i - 1\n\n (n / 2 + 2 to n).find(i => n - i <= mp && i - 1 <= mid)\n }\n\n val fromLeft = getLeft\n if (fromLeft.isDefined) {\n val pos = fromLeft.get\n return s.substring(0, pos) + s(n - 1 - pos) + s.substring(pos)\n }\n\n val fromRight = getRight\n if (fromRight.isDefined) {\n val pos = fromRight.get\n return s.substring(0, pos) + s(n - pos) + s.substring(pos)\n }\n\n if (mp >= n / 2)\n s.substring(0, n / 2) + s(n / 2) + s.substring(n / 2)\n else\n noAns\n }\n\n if (n == 1)\n s * 2\n else if (n % 2 == 0)\n getForEven\n else\n getForOdd\n }\n\n println(ans)\n}\n"}], "negative_code": [{"source_code": "import scala.io.StdIn\n\n/** A. Mr. Kitayuta's Gift\n * http://codeforces.com/contest/505/problem/A\n * @author Yuichiroh Matsubayashi\n * Created on 15/01/19.\n */\nobject P505A extends App {\n val letters = StdIn.readLine().toList\n val size = letters.size\n\n// println(letters, size)\n\n def valid(s1: List[Char], s2: List[Char], skippedA: Int = -1, skippedB: Int = -1, skippedLetter: Char = ' '): String = {\n// println(s1, s2, skippedLetter)\n if (s1 == Nil || s2 == Nil) {\n// println(skippedA, skippedB)\n if (skippedA >= 0) {\n val (pre, post) = letters.splitAt(size - skippedA)\n pre.mkString + skippedLetter + post.mkString\n }\n else if (skippedB >= 0) {\n val (pre, post) = letters.splitAt(skippedB)\n pre.mkString + skippedLetter + post.mkString\n }\n else if (size % 2 == 0) {\n val (pre, post) = letters.splitAt(size / 2)\n pre.mkString + \"a\" + post.mkString\n }\n else {\n val (pre, post) = letters.splitAt(size / 2)\n pre.mkString + post.head + post.mkString\n }\n }\n else if (s1.head == s2.head) valid(s1.tail, s2.tail, skippedA, skippedB, skippedLetter)\n else {\n val a = if (skippedA < 0) valid(s1.tail, s2, skippedA = size / 2 - s1.size, skippedB, s1.head) else \"NA\"\n if (a != \"NA\") a\n else if (skippedB < 0) valid(s1, s2.tail, skippedA, skippedB = size / 2 - s2.size, s2.head)\n else \"NA\"\n }\n }\n\n def solution = valid(letters.slice(0, size / 2), letters.reverse.slice(0, size / 2))\n\n println(solution)\n}\n"}, {"source_code": "\n\nimport scala.io.StdIn\n\n/** A. Mr. Kitayuta's Gift\n * http://codeforces.com/contest/505/problem/A\n * @author Yuichiroh Matsubayashi\n * Created on 15/01/19.\n */\nobject P505A extends App {\n val letters = StdIn.readLine().toList\n val size = letters.size\n\n def solution = {\n if (size % 2 == 0) {\n val (pre, post) = letters.splitAt(size / 2)\n if (pre.toList == post.reverse) pre.mkString + post.head.toString + post.mkString\n else {\n if (pre.toList == pre.head :: post.tail.reverse) (letters.head :: letters.reverse).reverse.mkString\n else if ((post.last :: pre).reverse.tail == post.toList) (post.last :: letters).mkString\n else \"NA\"\n }\n }\n else {\n val (a, b) = letters.splitAt(size / 2)\n val (pre, mid, post) = (a.toList, b.head, b.tail)\n\n if (pre == post.reverse) pre.mkString + mid + mid + post.mkString\n else {\n def valid(size: Int, short: List[Char], long: List[Char], skipped: Int = -1, char: String = \"\"): (Int, String) = {\n if (long == Nil) (skipped, char)\n else if (short == Nil) {\n if (skipped < 0) (size - 1, long.mkString)\n else {\n new NoSuchElementException\n (size, \"\")\n }\n }\n else if (short.head == long.head) valid(size, short.tail, long.tail, skipped, char)\n else if (skipped < 0) valid(size, short, long.tail, size - long.size, long.head.toString)\n else (-1, \"\")\n }\n\n val (skippedPre, cPre) = valid(pre.size + 1, pre.reverse, mid :: post)\n if (skippedPre >= 0) {\n val (ppre, ppost) = pre.splitAt(pre.size - skippedPre)\n ppre.mkString + cPre + ppost.mkString + mid + post.mkString\n }\n else {\n val (skippedPost, cPost) = valid(post.size + 1, post, mid :: pre.reverse)\n if (skippedPost >= 0) {\n val (ppre, ppost) = post.splitAt(skippedPost)\n pre.mkString + mid + ppre.mkString + cPost + ppost.mkString\n }\n else \"NA\"\n }\n }\n }\n }\n\n println(solution)\n}\n"}, {"source_code": "\nimport scala.io.StdIn\n\n/** A. Mr. Kitayuta's Gift\n * http://codeforces.com/contest/505/problem/A\n * @author Yuichiroh Matsubayashi\n * Created on 15/01/19.\n */\nobject P505A extends App {\n val letters = StdIn.readLine().toList\n val size = letters.size\n\n println(letters, size)\n\n def valid(s1: List[Char], s2: List[Char], size: Int, skippedA: Int = -1, skippedB: Int = -1, skippedLetter: Char = ' '): String = {\n println(s1, s2, size, skippedA, skippedB, skippedLetter)\n if (s1 == Nil || s2 == Nil) {\n println(skippedA, skippedB)\n if (skippedA >= 0) {\n val (pre, post) = letters.splitAt(size - skippedA)\n pre.mkString + skippedLetter + post.mkString\n }\n else if (skippedB >= 0) {\n val (pre, post) = letters.splitAt(skippedB)\n pre.mkString + skippedLetter + post.mkString\n }\n else if (size % 2 == 0) {\n val (pre, post) = letters.splitAt(size / 2)\n pre.mkString + \"a\" + post.mkString\n }\n else {\n val (pre, post) = letters.splitAt(size / 2)\n pre.mkString + post.head + post.mkString\n }\n }\n else if (s1.head == s2.head) valid(s1.tail, s2.tail, size, skippedA, skippedB, skippedLetter)\n else {\n val a = if (skippedA < 0) valid(s1.tail, s2, size, size - s1.size, skippedB, s1.head) else \"NA\"\n if (a != \"NA\") a\n else if (skippedA < 0 && skippedB < 0) valid(s1, s2.tail, size, skippedA, size - s2.size, s2.head)\n else \"NA\"\n }\n }\n\n def solution = valid(letters.slice(0, (size / 2.0).ceil.toInt), letters.reverse.slice(0, (size / 2.0).ceil.toInt), (size / 2.0).ceil.toInt)\n\n println(solution)\n}\n"}, {"source_code": "\n\nimport scala.io.StdIn\n\n/** A. Mr. Kitayuta's Gift\n * http://codeforces.com/contest/505/problem/A\n * @author Yuichiroh Matsubayashi\n * Created on 15/01/19.\n */\nobject P505A extends App {\n val letters = StdIn.readLine().toList\n val size = letters.size\n\n def solution = {\n if (size % 2 == 0) {\n val (pre, post) = letters.splitAt(size / 2)\n if (pre.toList == post.reverse) pre + post.head.toString + post\n else {\n if (pre.toList == pre.head :: post.tail.reverse) (letters.head :: letters.reverse).reverse.mkString\n else if ((post.last :: pre).reverse.tail == post.toList) (post.last :: letters).mkString\n else \"NA\"\n }\n }\n else {\n val (a, b) = letters.splitAt(size / 2)\n val (pre, mid, post) = (a.toList, b.head, b.tail)\n\n if (pre == post.reverse) pre.mkString + mid + mid + post.mkString\n else {\n def valid(size: Int, short: List[Char], long: List[Char], skipped: Int = -1, char: String = \"\"): (Int, String) = {\n if (long == Nil) (skipped, char)\n else if (short == Nil) {\n if (skipped < 0) (size - 1, long.mkString)\n else {\n new NoSuchElementException\n (size, \"\")\n }\n }\n else if (short.head == long.head) valid(size, short.tail, long.tail, skipped, char)\n else if (skipped < 0) valid(size, short, long.tail, size - long.size, long.head.toString)\n else (-1, \"\")\n }\n\n val (skippedPre, cPre) = valid(pre.size + 1, pre.reverse, mid :: post)\n if (skippedPre >= 0) {\n val (ppre, ppost) = pre.splitAt(pre.size - skippedPre)\n ppre.mkString + cPre + ppost.mkString + mid + post.mkString\n }\n else {\n val (skippedPost, cPost) = valid(post.size + 1, post, mid :: pre.reverse)\n if (skippedPost >= 0) {\n val (ppre, ppost) = post.splitAt(skippedPost)\n pre.mkString + mid + ppre.mkString + cPost + ppost.mkString\n }\n else \"NA\"\n }\n }\n }\n }\n\n println(solution)\n}\n"}, {"source_code": "\nobject Main {\n def main(args: Array[String]) {\n val s:String=io.StdIn.readLine()\n println(solve(s))\n }\n def solve(s:String):String = {\n if (isPal(s))\n if (s.length%2==0) insert(s,'a',s.length/2) else \"NA\"\n else {\n var i=0\n while (i h => acc\n case (l, h) => {\n if (str.charAt(l) == str.charAt(h))\n findInsertionPoints(str, l + 1, h - 1, acc)\n else {\n val loResult = findInsertionPoints(str, l, h - 1, acc :+ (l, str.charAt(h)))\n val hiResult = findInsertionPoints(str, l + 1, h, acc :+ (h + 1, str.charAt(l)))\n\n if (loResult.size < hiResult.size)\n loResult\n else\n hiResult\n }\n }\n }\n }\n\n val insertionPoints = findInsertionPoints(str, 0, str.length - 1)\n\n if (insertionPoints.size == 1) {\n val point = insertionPoints.head\n val newStr = str.substring(0, point._1) + point._2 + str.substring(point._1)\n out.println(newStr)\n } else if (insertionPoints.size == 0) {\n if (str.size % 2 == 0) {\n val newStr = str.substring(0, str.size / 2) + 'a' + str.substring(str.size / 2)\n out.println(newStr)\n } else if (str.size == 1) {\n out.println(str + str)\n } else {\n out.println(\"NA\")\n }\n } else {\n out.println(\"NA\")\n }\n }\n}\n"}, {"source_code": "\n\nimport java.io.InputStream\nimport java.io.PrintStream\nimport java.util.Scanner\n\nobject A_Mr_Kitayutas_Gift {\n\n def main(args: Array[String]) {\n parseSolveAndPrint(System.in, System.out)\n }\n\n def parseSolveAndPrint(in: InputStream, out: PrintStream): Unit = {\n val scanner = new Scanner(in)\n val str = scanner.next()\n\n def findInsertionPoints(str : String, l : Int, h: Int, acc : Seq[(Int, Char)] = Nil) : Seq[(Int, Char)] = {\n (l, h) match {\n case (l, h) if l > h => acc\n case (l, h) => {\n if (str.charAt(l) == str.charAt(h))\n findInsertionPoints(str, l + 1, h - 1, acc)\n else {\n val loResult = findInsertionPoints(str, l, h - 1, acc :+ (l, str.charAt(h)))\n val hiResult = findInsertionPoints(str, l + 1, h, acc :+ (h + 1, str.charAt(l)))\n\n if (loResult.size < hiResult.size)\n loResult\n else\n hiResult\n }\n }\n }\n }\n\n val insertionPoints = findInsertionPoints(str, 0, str.length - 1)\n\n if (insertionPoints.size == 1) {\n val point = insertionPoints.head\n val newStr = str.substring(0, point._1) + point._2 + str.substring(point._1)\n out.println(newStr)\n } else if (insertionPoints.size == 0) {\n if (str.size % 2 == 0) {\n val newStr = str.substring(0, str.size / 2) + 'a' + str.substring(str.size / 2)\n out.println(newStr)\n } else {\n out.println(\"NA\")\n }\n } else {\n out.println(\"NA\")\n }\n }\n}\n"}, {"source_code": "\n\nimport java.io.InputStream\nimport java.io.PrintStream\nimport java.util.Scanner\n\nobject A_Mr_Kitayutas_Gift {\n\n def main(args: Array[String]) {\n parseSolveAndPrint(System.in, System.out)\n }\n\n def parseSolveAndPrint(in: InputStream, out: PrintStream): Unit = {\n val scanner = new Scanner(in)\n val str = scanner.next()\n\n def findInsertionPoints(str : String, l : Int, h: Int, acc : Seq[(Int, Char)] = Nil) : Seq[(Int, Char)] = {\n (l, h) match {\n case (l, h) if l > h => acc\n case (l, h) => {\n if (str.charAt(l) == str.charAt(h))\n findInsertionPoints(str, l + 1, h - 1, acc)\n else {\n val loResult = findInsertionPoints(str, l, h - 1, acc :+ (l, str.charAt(h)))\n val hiResult = findInsertionPoints(str, l + 1, h, acc :+ (h + 1, str.charAt(l)))\n\n if (loResult.size < hiResult.size)\n loResult\n else\n hiResult\n }\n }\n }\n }\n\n val insertionPoints = findInsertionPoints(str, 0, str.length - 1)\n\n if (insertionPoints.size == 1) {\n val point = insertionPoints.head\n val newStr = str.substring(0, point._1) + point._2 + str.substring(point._1)\n out.println(newStr)\n } else if (insertionPoints.size == 0) {\n if (str.size % 2 == 0) {\n val newStr = str.substring(0, str.size / 2) + 'a' + str.substring(str.size / 2)\n out.println(newStr)\n } else {\n out.println(\"NA\")\n }\n } else {\n out.println(\"NA\")\n }\n\n println(insertionPoints.toString())\n }\n}\n"}], "src_uid": "24e8aaa7e3e1776adf342ffa1baad06b"} {"nl": {"description": "A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that . In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0.The expression means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as \"^\", in Pascal — as \"xor\".In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9).", "input_spec": "The only line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105).", "output_spec": "Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output.", "sample_inputs": ["3 2"], "sample_outputs": ["6"], "notes": "NoteSequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3)."}, "positive_code": [{"source_code": "object A {\n val mod = 1000000009L\n\n def main(args: Array[String]) {\n val (n, m) = {\n val sp = readLine.split(\" \")\n (sp(0).toInt, sp(1).toInt)\n }\n\n if (m < 60 && (1L << m) - n < 0) {\n println(0)\n return\n }\n\n val m2 = (1 to m).foldLeft(1L) { (v: Long, i) =>\n v * 2 % mod\n }\n\n val ans = (1 to n).foldLeft(1L) { (v: Long, i) =>\n v * (m2 - i + mod) % mod\n }\n println(ans)\n }\n}"}, {"source_code": "import java.util._\n\nobject Main extends App {\n val sc = new Scanner(System.in)\n val mod = 1000000009L\n\n val n, m = sc.nextInt()\n\n def power(x: Long, p: Long, res: Long = 1L): Long =\n if (p == 0) res else power(x, p - 1, res * x % mod)\n\n def solve(p: Long, n: Long, res: Long = 1L): Long =\n if (n == 0) res else solve(p - 1, n - 1, res * p % mod)\n\n println(solve(power(2, m) - 1, n))\n}\n"}], "negative_code": [], "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8"} {"nl": {"description": "One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.", "input_spec": "The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends. Next line contains string s — colors of baloons.", "output_spec": "Answer to the task — «YES» or «NO» in a single line. You can choose the case (lower or upper) for each letter arbitrary.", "sample_inputs": ["4 2\naabb", "6 3\naacaab"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO»."}, "positive_code": [{"source_code": "/**\n * Created by mettu.r on 20/08/17.\n */\nobject Demo extends App {\n override def main(args: Array[String]): Unit = {\n var a = readLine().split(\" \").map(x => x.toInt);\n var n = a(0);\n var k = a(1);\n var s = readLine();\n var map = scala.collection.mutable.Map[Char,Int]();\n s.foreach(x => {\n map.put(x , map.getOrElse(x,0) + 1 );\n });\n var ans = true;\n map.foreach( x => if( x._2 > k ) ans = false );\n if( ans )\n printf(\"Yes\\n\");\n else\n printf(\"No\\n\");\n }\n}"}, {"source_code": "import java.util.Scanner\n\nobject Try1 {\n def main(args: Array[String]) {\n val in = new Scanner(System.in)\n var len, m, k, n, j, i: Int = 0\n var a = new Array[Int](26)\n n = in.nextInt()\n m = in.nextInt()\n k=0\n var line = in.nextLine()\n line = in.nextLine()\n for (i <- 0 to 25) a(i)=0\n for (i <- 0 until n)\n a(line(i)-'a')+=1\n// len = line.length()\n for (i <- 0 to 25)\n if (a(i)>m) k=1\n if (k==0) println(\"YES\")\n else println(\"NO\")\n }\n}"}], "negative_code": [{"source_code": "import java.util.Scanner\n\nobject Try1 {\n def main(args: Array[String]) {\n val in = new Scanner(System.in)\n var len, w, ans, m, x, c, k, n, j, i: Int = 0\n var a = new Array[Int](26)\n n = in.nextInt()\n m = in.nextInt()\n k=0\n var line = in.nextLine()\n line = in.nextLine()\n for (i <- 0 to 25) a(i)=0\n for (i <- 0 until n)\n a(line(i)-'a')+=1\n// len = line.length()\n if (nm) k=1\n if (k==0) println(\"YES\")\n else println(\"NO\")\n }\n}"}, {"source_code": "import java.util.Scanner\n\nobject Try1 {\n def main(args: Array[String]) {\n val in = new Scanner(System.in)\n var len, w, ans, m, x, c, k, n, j, i: Int = 0\n var a = new Array[Int](26)\n n = in.nextInt()\n m = in.nextInt()\n k=0\n var line = in.nextLine()\n line = in.nextLine()\n for (i <- 0 to 25) a(i)=0\n for (i <- 0 until n)\n a(line(i)-'a')+=1\n// len = line.length()\n if (n 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 writeLines(obj: Traversable[Any]): this.type = writeAll(obj, separator = \"\\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"}], "negative_code": [], "src_uid": "8b2a9ae21740c89079a6011a30cd6aee"} {"nl": {"description": "Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer x was given. The task was to add x to the sum of the digits of the number x written in decimal numeral system.Since the number n on the board was small, Vova quickly guessed which x could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number n for all suitable values of x or determine that such x does not exist. Write such a program for Vova.", "input_spec": "The first line contains integer n (1 ≤ n ≤ 109).", "output_spec": "In the first line print one integer k — number of different values of x satisfying the condition. In next k lines print these values in ascending order.", "sample_inputs": ["21", "20"], "sample_outputs": ["1\n15", "0"], "notes": "NoteIn the first test case x = 15 there is only one variant: 15 + 1 + 5 = 21.In the second test case there are no such x."}, "positive_code": [{"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 C_441 { 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 n = readLine.int\n \n //---------------------------- parameters reading :end\n \n var continue = true\n var variants = List[Int]()\n var x = n\n val maxDif = n.toString().length() * 9\n while (continue) {\n val sum = sumDig(x) + x\n continue = x > 0 && x + maxDif >= n\n if (sum == n) variants ::= x\n x -= 1\n }\n \n def sumDig(x: Int) = {\n x.toString.map(c => (c+\"\").toInt).sum\n }\n \n val res = if (variants.size > 0) {\n variants.size + \"\\n\" + variants.sorted.mkString(\" \")\n } else {\n \"0\"\n }\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 = \"\"\"\n21\n\"\"\"\n\nval sa2 = \"\"\"\n20\n\"\"\"\n\nval sa3 = \"\"\"\n100 \n\"\"\"\n}\n\n}\n\n"}, {"source_code": "import scala.collection.mutable.ListBuffer\n\nobject test {\n def digits(a: Int): Int =\n if (a == 0) 0\n else 1 + digits(a/10)\n def sumDigits(a: Int): Int =\n if (a == 0) 0\n else (a % 10) + sumDigits(a/10)\n def main(args: Array[String]) {\n val a = scala.io.StdIn.readInt\n var l = ListBuffer[Int]()\n for(x <- math.max(a-9*digits(a)-5, 0) to a) {\n if(sumDigits(x)+x == a) l += x\n }\n println(l.length)\n for(x <- l) {\n println(x)\n }\n }\n}"}], "negative_code": [{"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 C_441 { 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 n = readLine.int\n \n var continue = true\n var variants = List[Int]()\n var x = n\n while (continue) {\n val sum = sumDig(x) + x\n continue = sum > n\n if (sum == n) variants ::= x\n x -= 1\n }\n \n def sumDig(x: Int) = {\n x.toString.map(c => (c+\"\").toInt).sum\n }\n \n// val max = groups.values.reduce((a,b) => if (a.size > b.size) a else b) \n// debug(\"max = \" + max.mkString(\" \"))\n \n //---------------------------- parameters reading :end\n \n val res = if (variants.size > 0) {\n variants.size + \"\\n\" + variants.sorted.mkString(\" \")\n } else {\n \"0\"\n }\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 = \"\"\"\n21\n\"\"\"\n\nval sa2 = \"\"\"\n20\n\"\"\"\n\nval sa3 = \"\"\"\n100 \n\"\"\"\n}\n\n}\n\n"}], "src_uid": "ae20ae2a16273a0d379932d6e973f878"} {"nl": {"description": "In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly n Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be divisible by the denomination of any cheaper coin. It is known that among all the possible variants the variant with the largest number of new coins will be chosen. Find this variant. Print in the order of decreasing of the coins' denominations.", "input_spec": "The first and only line contains an integer n (1 ≤ n ≤ 106) which represents the denomination of the most expensive coin. ", "output_spec": "Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination n of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coins should be different. If there are several solutins to that problem, print any of them.", "sample_inputs": ["10", "4", "3"], "sample_outputs": ["10 5 1", "4 2 1", "3 1"], "notes": null}, "positive_code": [{"source_code": "import scala.collection.mutable.ListBuffer\nobject P58B extends App {\n\n val n = readLine.toInt\n val cache = new Array[List[Int]](n)\n cache(0) = List(1)\n\n def f(n: Int): List[Int] = {\n if (cache(n - 1) != null) cache(n - 1)\n else {\n var factors = ListBuffer[Int](1)\n for (e <- 2 to math.sqrt(n).toInt) if (n % e == 0) factors ++= Set(e, n / e)\n cache(n - 1) = List(n) ++ factors.map(f(_)).maxBy(_.size)\n cache(n - 1)\n }\n }\n\n for (e <- f(n)) print(e+\" \")\n}"}, {"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 res = (2 to n).foldLeft(List(1)) {\n case(list, el) if n % el == 0 && el % list.head == 0 => el :: list\n case(list, el) => list\n }\n\n println(res.mkString(\" \"))\n}"}, {"source_code": "object Main {\n val primes: Stream[Int] = 2 #:: 3 #:: \n Stream.from(5, 2).filter(i => primes.takeWhile(_ < Math.sqrt(i)).forall(i % _ != 0))\n\n def split(n: Int): List[Int] = {\n primes.takeWhile(_ <= Math.sqrt(n)).find(n % _ == 0) match {\n case Some(div) => div :: split(n / div)\n case None => List(n)\n }\n }\n\n def main(args: Array[String]) {\n val n = readInt()\n val divs = split(n)\n if (n == 1) println(\"1\")\n else println(divs.scanLeft(1)(_ * _).reverse.mkString(\" \"))\n }\n}"}], "negative_code": [{"source_code": "import scala.collection.mutable.ListBuffer\nobject P58B extends App {\n\n val n = readLine.toInt\n var factors = ListBuffer[Int]()\n for (e <- 2 to math.sqrt(n).toInt) if (n % e == 0) factors ++= Set(e, n / e)\n\n val evens = factors.filter(_ % 2 == 0)\n val odds = factors.filter(_ % 2 == 1)\n factors = List(evens, odds).maxBy(_.size) + n + 1\n\n for (e <- factors.toSet.toList.sortWith(_ > _)) print(e+\" \")\n\n}"}, {"source_code": "import scala.collection.mutable.ListBuffer\nobject P58B extends App {\n\n val n = readLine.toInt\n var factors = ListBuffer[Int]()\n for (e <- 2 to math.sqrt(n).toInt) if (n % e == 0) factors ++= Set(e, n / e)\n\n val evens = factors.filter(_ % 2 == 0)\n val odds = factors.filter(_ % 2 == 1)\n factors = List(evens, odds).maxBy(_.size) + n + 1\n\n for (e <- factors.toList.sortWith(_ > _)) print(e+\" \")\n\n}"}, {"source_code": "object Main {\n val primes: Stream[Int] = 2 #:: 3 #:: \n Stream.from(5, 2).filter(i => primes.takeWhile(_ < Math.sqrt(i)).forall(i % _ != 0))\n\n def split(n: Int): List[Int] = {\n primes.takeWhile(_ <= Math.sqrt(n)).find(n % _ == 0) match {\n case Some(div) => div :: split(n / div)\n case None => List(n)\n }\n }\n\n def main(args: Array[String]) {\n val n = readInt()\n val divs = split(n)\n println(divs.scanLeft(1)(_ * _).reverse.mkString(\" \"))\n }\n}"}], "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63"} {"nl": {"description": "Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime. You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l ≤ a < b < c ≤ r. More specifically, you need to find three numbers (a, b, c), such that l ≤ a < b < c ≤ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.", "input_spec": "The single line contains two positive space-separated integers l, r (1 ≤ l ≤ r ≤ 1018; r - l ≤ 50).", "output_spec": "Print three positive space-separated integers a, b, c — three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order. If the counterexample does not exist, print the single number -1.", "sample_inputs": ["2 4", "10 11", "900000000000000009 900000000000000029"], "sample_outputs": ["2 3 4", "-1", "900000000000000009 900000000000000010 900000000000000021"], "notes": "NoteIn the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. "}, "positive_code": [{"source_code": "import java.util.StringTokenizer\n\nobject _483A extends App {\n var token = new StringTokenizer(\"\")\n\n def next = {\n while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)\n token.nextToken()\n }\n\n val l = next.toLong\n val r = next.toLong\n\n def gcd(a: Long, b: Long): Long = if (b == 0) a else gcd(b, a % b)\n val ans = for {\n a <- l to r\n b <- a + 1 to r\n c <- b +1 to r\n if (gcd(a, b) == 1 && gcd(b, c) == 1 && gcd(a, c) > 1)\n } yield (a, b, c)\n\n if (ans.size == 0) println(-1)\n else println(ans.head._1 + \" \" + ans.head._2 + \" \" + ans.head._3)\n}\n"}, {"source_code": "object Solution extends App {\n def simple(a: Long, b: Long): Boolean = {\n if (b == 0) a == 1\n else simple(b, a % b)\n }\n\n val in = scala.io.Source.stdin.getLines()\n val Array(a, b) = in.next().split(\" \").map(_.toLong)\n val options = (a to b - 2).flatMap(a1 => (a1 + 1 to b - 1).flatMap(b1 => (b1 + 1 to b).map(c1 => (a1, b1, c1))))\n println(options.find{\n case(a, b, c) => simple(a, b) && simple(b, c) && !simple(a, c)\n }.map(t => s\"${t._1} ${t._2} ${t._3}\").getOrElse(\"-1\"))\n\n\n}"}, {"source_code": "object A483 {\n\n import IO._\n def gcd(a: Long, b: Long): Long = {\n if(b == 0) a else gcd(b, a%b)\n }\n def main(args: Array[String]): Unit = {\n val Array(l, r) = readLongs(2)\n var break = false\n for(a <- l to r-2; b <- a+1 to r-1; c <- b+1 to r if !break) {\n if(gcd(a, b) == 1 && gcd(b, c) == 1 && gcd(a, c) != 1) {\n println(s\"$a $b $c\")\n break = true\n }\n }\n if(!break) {\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"}, {"source_code": " /**\n * Created by SchmAn4 on 26.10.2014.\n */\n object Counterexample {\n def main(s: Array[String]): Unit = {\n val start = System.currentTimeMillis\n val scanner = new java.util.Scanner(System.in)\n val x = scanner.nextLong()\n val y = scanner.nextLong()\n val list = (x to y)\n\n/*\n val triples = for(x <- list; y <- list; z <- list) yield (x,y,z)\n println(triples.filter {\n case (x, y, z) => x < y && y < z && x != y && y != z && x != z && ggT(x, y) == 1 && ggT(y, z) == 1 && ggT(x, z) != 1\n })\n */\n // 380ms\n\n\n /*\n val seven = (for (\n x <- list; y <- list; z <- list\n if x < y && y < z && x != y && y != z && x != z && ggT(x, y) == 1 && ggT(y, z) == 1 && ggT(x, z) != 1\n ) yield (x,y,z)).headOption\n // 340ms\n*/\n val iter = (for {\n x <- list.toIterator; y <- list.toIterator; z <- list.toIterator\n if x < y && y < z && x != y && y != z && x != z && ggT(x, y) == 1 && ggT(y, z) == 1 && ggT(x, z) != 1\n } yield (x,y,z))\n\n if (iter.hasNext) {\n val triple = iter.next\n println(triple._1+\" \"+triple._2+\" \"+triple._3)\n } else\n println(-1)\n // 300ms\n\n// println((System.currentTimeMillis-start)+\"ms\")\n }\n\n /*\n def perform(a: Long, b: Long): String = (a,b) match {\n //case (p,q) if ggT(p,q) == 1 => \"-1\"\n case (p,q) => perform2(p,q,p+1,p+1)\n }\n\n def perform2(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {\n case (a,b,c,d) if b >= c && ggT(a,c) == 1 => perform3(a,b,c,d+1) //a+\" \"+c+\" \"+b\n case (_,b,c,d) if b <= c => \"-1\"\n case (a,b,c,d) => perform2(a,b,c+1,d+1)\n }\n\n def perform3(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {\n case (a,b,c,d) if b >= d && ggT(c,d) == 1 && ggT(a,d) != 1 => a+\" \"+c+\" \"+d\n case (_,b,c,d) if b <= d => \"-1\"\n case (a,b,c,d) => perform2(a,b,c,d+1)\n }\n */\n\n def ggT(a: Long, b: Long): Long = (a,b) match {\n case (_,0) => a\n case (p,q) if p == q => a\n case (p,q) => ggT(b,a%b)\n }\n\n /*\n Input\n 900000000000000009 900000000000000029\n Output\n 900000000000000009 900000000000000010 900000000000000029\n Answer\n 900000000000000009 900000000000000010 900000000000000021\n */\n\n\n }\n"}, {"source_code": "object main {\nimport scala.io.StdIn._\nimport scala.collection.mutable.{HashMap,HashSet}\n\ndef gcd(a: Long, b: Long): Long = {\n\tif (a == 0) b else gcd(b % a, a)\n}\n\n\ndef main(args: Array[String]) {\n\n\nval input = readLine.trim.split(\" +\")\nval left = input(0).toLong\nval right = input(1).toLong\nval coprimes = HashMap[Long, HashSet[Long]]()\nfor (x <- left to right) {\n\tval temp = HashSet[Long]()\n\tfor (y <- left to right) {\n\t\tif (x != y && gcd(x,y) == 1) temp += y\n\t}\n\tcoprimes += x -> temp\n}\ndef findIt: (Long, Long, Long) = {\n\tfor (a <- coprimes.keys) {\n\t\tfor (b <- coprimes(a)) {\n\t\t\tif (b > a) {\n\t\t\t\tfor (c <- coprimes(b)) {\n\t\t\t\t\tif (c > a && c > b && !coprimes(a).contains(c)) return (a,b,c)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn null\n}\nval res = findIt\nprintln(if (res != null) { res._1 + \" \" + res._2 + \" \" + res._3 } else -1)\n\n\n\n\n}\n\n}"}], "negative_code": [{"source_code": " /**\n * Created by SchmAn4 on 26.10.2014.\n */\n object Counterexample {\n def main(s: Array[String]): Unit = {\n val scanner = new java.util.Scanner(System.in)\n val x = scanner.nextLong()\n val y = scanner.nextLong()\n println(perform(x,y))\n }\n\n def perform(a: Long, b: Long): String = (a,b) match {\n //case (p,q) if ggT(p,q) == 1 => \"-1\"\n case (p,q) => perform2(p,q,p+1)\n }\n\n def perform2(a: Long, b: Long, c: Long): String = (a,b,c) match {\n case (_,b,c) if b == c => \"-1\"\n case (a,b,c) if ggT(a,c) == 1 && ggT(b,c) == 1 => a+\" \"+c+\" \"+b\n case (a,b,c) => perform2(a,b,c+1)\n }\n\n def ggT(a: Long, b: Long): Long = (a,b) match {\n case (_,0) => a\n case (p,q) if p == q => a\n case (p,q) => ggT(b,a%b)\n }\n\n\n }\n"}, {"source_code": " /**\n * Created by SchmAn4 on 26.10.2014.\n */\n object Counterexample {\n def main(s: Array[String]): Unit = {\n val scanner = new java.util.Scanner(System.in)\n val x = scanner.nextLong()\n val y = scanner.nextLong()\n println(perform(x,y))\n }\n\n def perform(a: Long, b: Long): String = (a,b) match {\n case (p,q) if ggT(p,q) == 1 => \"-1\"\n case (p,q) => perform2(p,q,p+1)\n }\n\n def perform2(a: Long, b: Long, c: Long): String = (a,b,c) match {\n case (_,b,c) if b == c => \"-1\"\n case (a,b,c) if ggT(a,c) == 1 && ggT(b,c) == 1 => a+\" \"+c+\" \"+b\n case (a,b,c) => perform2(a,b,c+1)\n }\n\n def ggT(a: Long, b: Long): Long = (a,b) match {\n case (_,0) => a\n case (p,q) if p == q => a\n case (p,q) => ggT(b,a%b)\n }\n\n\n }\n"}, {"source_code": " /**\n * Created by SchmAn4 on 26.10.2014.\n */\n object Counterexample {\n def main(s: Array[String]): Unit = {\n val scanner = new java.util.Scanner(System.in)\n val x = scanner.nextLong()\n val y = scanner.nextLong()\n println(perform(x,y))\n }\n\n def perform(a: Long, b: Long): String = (a,b) match {\n //case (p,q) if ggT(p,q) == 1 => \"-1\"\n case (p,q) => perform2(p,q,p+1,p+1)\n }\n\n def perform2(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {\n case (a,b,c,d) if ggT(a,c) == 1 => perform3(a,b,c,d+1) //a+\" \"+c+\" \"+b\n case (_,b,c,d) if b <= c => \"-1\"\n case (a,b,c,d) => perform2(a,b,c+1,d+1)\n }\n\n def perform3(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {\n case (a,b,c,d) if ggT(c,d) == 1 && ggT(a,d) != 1 => a+\" \"+c+\" \"+d\n case (_,b,c,d) if b <= d => \"-1\"\n case (a,b,c,d) => perform2(a,b,c,d+1)\n }\n\n def ggT(a: Long, b: Long): Long = (a,b) match {\n case (_,0) => a\n case (p,q) if p == q => a\n case (p,q) => ggT(b,a%b)\n }\n\n /*\n Input\n 900000000000000009 900000000000000029\n Output\n 900000000000000009 900000000000000010 900000000000000029\n Answer\n 900000000000000009 900000000000000010 900000000000000021\n */\n\n\n }\n"}, {"source_code": " /**\n * Created by SchmAn4 on 26.10.2014.\n */\n object Counterexample {\n def main(s: Array[String]): Unit = {\n val scanner = new java.util.Scanner(System.in)\n val x = scanner.nextLong()\n val y = scanner.nextLong()\n println(perform(x,y))\n }\n\n def perform(a: Long, b: Long): String = (a,b) match {\n //case (p,q) if ggT(p,q) == 1 => \"-1\"\n case (p,q) => perform2(p,q,p+1,p+1)\n }\n\n def perform2(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {\n case (a,b,c,d) if b >= c && ggT(a,c) == 1 => perform3(a,b,c,d+1) //a+\" \"+c+\" \"+b\n case (_,b,c,d) if b <= c => \"-1\"\n case (a,b,c,d) => perform2(a,b,c+1,d+1)\n }\n\n def perform3(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {\n case (a,b,c,d) if b >= d && ggT(c,d) == 1 && ggT(a,d) != 1 => a+\" \"+c+\" \"+d\n case (_,b,c,d) if b <= d => \"-1\"\n case (a,b,c,d) => perform2(a,b,c,d+1)\n }\n\n def ggT(a: Long, b: Long): Long = (a,b) match {\n case (_,0) => a\n case (p,q) if p == q => a\n case (p,q) => ggT(b,a%b)\n }\n\n /*\n Input\n 900000000000000009 900000000000000029\n Output\n 900000000000000009 900000000000000010 900000000000000029\n Answer\n 900000000000000009 900000000000000010 900000000000000021\n */\n\n\n }\n"}, {"source_code": " /**\n * Created by SchmAn4 on 26.10.2014.\n */\n object Counterexample {\n def main(s: Array[String]): Unit = {\n val scanner = new java.util.Scanner(System.in)\n val x = scanner.nextLong()\n val y = scanner.nextLong()\n println(perform(x,y))\n }\n\n def perform(a: Long, b: Long): String = (a,b) match {\n //case (p,q) if ggT(p,q) == 1 => \"-1\"\n case (p,q) => perform2(p,q,p+1,p+1)\n }\n\n def perform2(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {\n case (a,b,c,d) if ggT(a,c) == 1 => perform3(a,b,c,d+1) //a+\" \"+c+\" \"+b\n case (_,b,c,d) if b == c => \"-1\"\n case (a,b,c,d) => perform2(a,b,c+1,d+1)\n }\n\n def perform3(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {\n case (a,b,c,d) if ggT(c,d) == 1 && ggT(a,d) != 1 => a+\" \"+c+\" \"+d\n case (_,b,c,d) if b == d => \"-1\"\n case (a,b,c,d) => perform2(a,b,c,d+1)\n }\n\n def ggT(a: Long, b: Long): Long = (a,b) match {\n case (_,0) => a\n case (p,q) if p == q => a\n case (p,q) => ggT(b,a%b)\n }\n\n /*\n Input\n 900000000000000009 900000000000000029\n Output\n 900000000000000009 900000000000000010 900000000000000029\n Answer\n 900000000000000009 900000000000000010 900000000000000021\n */\n\n\n }\n"}], "src_uid": "6c1ad1cc1fbecff69be37b1709a5236d"} {"nl": {"description": "A monster is attacking the Cyberland!Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF).During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases by max(0, ATKM - DEFY), where index Y denotes Master Yang and index M denotes monster. Both decreases happen simultaneously Once monster's HP ≤ 0 and the same time Master Yang's HP > 0, Master Yang wins.Master Yang can buy attributes from the magic shop of Cyberland: h bitcoins per HP, a bitcoins per ATK, and d bitcoins per DEF.Now Master Yang wants to know the minimum number of bitcoins he can spend in order to win.", "input_spec": "The first line contains three integers HPY, ATKY, DEFY, separated by a space, denoting the initial HP, ATK and DEF of Master Yang. The second line contains three integers HPM, ATKM, DEFM, separated by a space, denoting the HP, ATK and DEF of the monster. The third line contains three integers h, a, d, separated by a space, denoting the price of 1 HP, 1 ATK and 1 DEF. All numbers in input are integer and lie between 1 and 100 inclusively.", "output_spec": "The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win.", "sample_inputs": ["1 2 1\n1 100 1\n1 100 100", "100 100 100\n1 1 1\n1 1 1"], "sample_outputs": ["99", "0"], "notes": "NoteFor the first sample, prices for ATK and DEF are extremely high. Master Yang can buy 99 HP, then he can beat the monster with 1 HP left.For the second sample, Master Yang is strong enough to beat the monster, so he doesn't need to buy anything."}, "positive_code": [{"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val Array(hpy, atky, defy) = in.next().split(\" \").map(_.toLong)\n val Array(hpm, atkm, defm) = in.next().split(\" \").map(_.toLong)\n val Array(hpcost, atkcost, defcost) = in.next().split(\" \").map(_.toLong)\n var atkmin = if (atky > defm) atky else defm + 1\n var cost = -1l\n (atkmin to (hpm + defm)).foreach { atk =>\n if (cost == -1l || (atk - atky) * atkcost < cost)\n if (atkm > defy)\n (defy to atkm).foreach { defend =>\n if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost < cost)) {\n val win = hpm / (atk - defm) + (if (hpm % (atk - defm) > 0) 1 else 0)\n val damage = win * (atkm - defend)\n val hp = if (damage >= hpy) damage - hpy + 1 else 0\n if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost < cost))\n cost = (atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost\n }\n }\n else {\n cost = (atk - atky) * atkcost\n }\n }\n if (cost == -1l)\n println(0)\n else\n println(cost)\n\n\n}"}, {"source_code": "import scala.collection._\n\nobject 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(hy, ay, dy) = readLongs(3)\n val Array(hm, am, dm) = readLongs(3)\n val Array(ch, ca, cd) = readLongs(3)\n\n var min = Long.MaxValue\n\n for (a <- 0 to 1000) {\n for (d <- 0 to 100) {\n\n def can(h: Long) = {\n //(hy + h) * (ay + a - dm) > hm * (am - dy - d)\n val x = (ay + a - dm)\n if (am - dy - d <= 0 && x > 0) true\n else {\n if (x <= 0) false\n else {\n val steps = (hm + x - 1) / x\n if ((am - dy - d) * steps < hy + h) true\n else false\n }\n }\n }\n\n @annotation.tailrec\n def binSearch(low: Long, hi: Long): Long = {\n if (hi < low) low\n else {\n val mid = (low + hi) >>> 1\n if (can(mid)) binSearch(low, mid - 1)\n else binSearch(mid + 1, hi)\n }\n }\n\n val h = binSearch(0, 100000000L)\n \n //if (d == 0 && a == 0) println(h)\n \n val cost = a * ca + d * cd + h * ch \n \n min = Math.min(min, cost)\n }\n }\n\n println(min)\n}"}], "negative_code": [{"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val Array(hpy, atky, defy) = in.next().split(\" \").map(_.toLong)\n val Array(hpm, atkm, defm) = in.next().split(\" \").map(_.toLong)\n val Array(hpcost, atkcost, defcost) = in.next().split(\" \").map(_.toLong)\n var atkmin = if (atky > defm) atky else defm + 1\n var cost = -1l\n (atkmin to (hpm + defm)).foreach { atk =>\n if (cost == -1l || (atk - atky) * atkcost < cost)\n if (atkm > defm)\n (defy to atkm).foreach { defend =>\n println(\"andhere\")\n if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost < cost)) {\n val win = hpm / (atk - defm) + (if (hpm % (atk - defm) > 0) 1 else 0)\n val damage = win * (atkm - defend)\n val hp = if (damage >= hpy) damage - hpy + 1 else 0\n if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost < cost))\n cost = (atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost\n }\n }\n else cost = (atk - atky) * atkcost\n }\n if (cost == -1l)\n println(0)\n else\n println(cost)\n\n\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val Array(hpy, atky, defy) = in.next().split(\" \").map(_.toLong)\n val Array(hpm, atkm, defm) = in.next().split(\" \").map(_.toLong)\n val Array(hpcost, atkcost, defcost) = in.next().split(\" \").map(_.toLong)\n var atkmin = if (atky > defm) atky else defm + 1\n var cost = -1l\n (atkmin to (hpm + defm)).foreach { atk =>\n if (cost == -1l || (atk - atky) * atkcost < cost)\n if (atkm > defm)\n (defy to atkm).foreach { defend =>\n if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost < cost)) {\n val win = hpm / (atk - defm) + (if (hpm % (atk - defm) > 0) 1 else 0)\n val damage = win * (atkm - defend)\n val hp = if (damage >= hpy) damage - hpy + 1 else 0\n if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost < cost))\n cost = (atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost\n }\n }\n else cost = (atk - atky) * atkcost\n }\n if (cost == -1l)\n println(0)\n else\n println(cost)\n\n\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val Array(hpy, atky, defy) = in.next().split(\" \").map(_.toLong)\n val Array(hpm, atkm, defm) = in.next().split(\" \").map(_.toLong)\n val Array(hpcost, atkcost, defcost) = in.next().split(\" \").map(_.toLong)\n var atkmin = if (atky > defm) atky else defm + 1\n var cost = -1l\n (atkmin to (hpm + defm)).foreach { atk =>\n if (cost == -1l || (atk - atky) * atkcost < cost)\n (defy to atkm).foreach { defend =>\n if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost < cost)) {\n val win = hpm / (atk - defm) + (if (hpm % (atk - defm) > 0) 1 else 0)\n val damage = win * (atkm - defend)\n val hp = if (damage >= hpy) damage - hpy + 1 else 0\n if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost < cost))\n cost = (atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost\n }\n }\n }\n if (cost == -1l)\n println(0)\n else\n println(cost)\n\n\n}"}, {"source_code": "import scala.collection._\n\nobject 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(hy, ay, dy) = readLongs(3)\n val Array(hm, am, dm) = readLongs(3)\n val Array(ch, ca, cd) = readLongs(3)\n\n var min = Long.MaxValue\n\n for (a <- 0 to 100) {\n for (d <- 0 to 100) {\n\n def can(h: Long) = {\n (hy + h) * (ay + a - dm) > hm * (am - dy - d)\n }\n\n @annotation.tailrec\n def binSearch(low: Long, hi: Long): Long = {\n if (hi < low) low\n else {\n val mid = (low + hi) >>> 1\n if (can(mid)) binSearch(low, mid - 1)\n else binSearch(mid + 1, hi)\n }\n }\n\n val h = binSearch(0, 100000000L)\n \n val cost = a * ca + d * cd + h * ch \n \n min = Math.min(min, cost)\n }\n }\n\n println(min)\n}"}, {"source_code": "import scala.collection._\n\nobject 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(hy, ay, dy) = readLongs(3)\n val Array(hm, am, dm) = readLongs(3)\n val Array(ch, ca, cd) = readLongs(3)\n\n var min = Long.MaxValue\n\n for (a <- 0 to 1000) {\n for (d <- 0 to 100) {\n\n def can(h: Long) = {\n //(hy + h) * (ay + a - dm) > hm * (am - dy - d)\n if (am - dy - d <= 0) true\n else {\n val x = (ay + a - dm)\n if (x <= 0) false\n else {\n val steps = (hm + x - 1) / x\n if ((am - dy - d) * steps < hy + h) true\n else false\n }\n }\n }\n\n @annotation.tailrec\n def binSearch(low: Long, hi: Long): Long = {\n if (hi < low) low\n else {\n val mid = (low + hi) >>> 1\n if (can(mid)) binSearch(low, mid - 1)\n else binSearch(mid + 1, hi)\n }\n }\n\n val h = binSearch(0, 100000000L)\n \n //if (d == 0 && a == 0) println(h)\n \n val cost = a * ca + d * cd + h * ch \n \n min = Math.min(min, cost)\n }\n }\n\n println(min)\n}"}, {"source_code": "import scala.collection._\n\nobject 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(hy, ay, dy) = readLongs(3)\n val Array(hm, am, dm) = readLongs(3)\n val Array(ch, ca, cd) = readLongs(3)\n\n var min = Long.MaxValue\n\n for (a <- 0 to 100) {\n for (d <- 0 to 100) {\n\n def can(h: Long) = {\n //(hy + h) * (ay + a - dm) > hm * (am - dy - d)\n if (am - dy - d <= 0) true\n else {\n val x = (ay + a - dm)\n if (x <= 0) false\n else {\n val steps = (hm + x - 1) / x\n if ((am - dy - d) * steps < hy + h) true\n else false\n }\n }\n }\n\n @annotation.tailrec\n def binSearch(low: Long, hi: Long): Long = {\n if (hi < low) low\n else {\n val mid = (low + hi) >>> 1\n if (can(mid)) binSearch(low, mid - 1)\n else binSearch(mid + 1, hi)\n }\n }\n\n val h = binSearch(0, 100000000L)\n \n //if (d == 0 && a == 0) println(h)\n \n val cost = a * ca + d * cd + h * ch \n \n min = Math.min(min, cost)\n }\n }\n\n println(min)\n}"}, {"source_code": "import scala.collection._\n\nobject 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(hy, ay, dy) = readLongs(3)\n val Array(hm, am, dm) = readLongs(3)\n val Array(ch, ca, cd) = readLongs(3)\n\n var min = Long.MaxValue\n\n for (a <- 0 to 1000) {\n for (d <- 0 to 100) {\n\n def can(h: Long) = {\n //(hy + h) * (ay + a - dm) > hm * (am - dy - d)\n if (am - dy - d <= 0) true\n else {\n val x = (ay + a - dm)\n if (x <= 0) false\n else {\n (hy + h) * (ay + a - dm) > hm * (am - dy - d)\n /*val steps = (hm + x) * 1f / x\n if ((am - dy - d) * steps < hy + h) true\n else false*/\n }\n }\n }\n\n @annotation.tailrec\n def binSearch(low: Long, hi: Long): Long = {\n if (hi < low) low\n else {\n val mid = (low + hi) >>> 1\n if (can(mid)) binSearch(low, mid - 1)\n else binSearch(mid + 1, hi)\n }\n }\n\n val h = binSearch(0, 100000000L)\n \n //if (d == 0 && a == 0) println(h)\n \n val cost = a * ca + d * cd + h * ch \n \n min = Math.min(min, cost)\n }\n }\n\n println(min)\n}"}, {"source_code": "import scala.collection._\n\nobject 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(hy, ay, dy) = readLongs(3)\n val Array(hm, am, dm) = readLongs(3)\n val Array(ch, ca, cd) = readLongs(3)\n\n var min = Long.MaxValue\n\n for (a <- 0 to 1000) {\n for (d <- 0 to 100) {\n\n def can(h: Long) = {\n //(hy + h) * (ay + a - dm) > hm * (am - dy - d)\n if (am - dy - d <= 0) true\n else {\n val x = (ay + a - dm)\n if (x <= 0) false\n else {\n val steps = 1d * hm / x\n if ((am - dy - d) * steps < hy + h) true\n else false\n }\n }\n }\n\n @annotation.tailrec\n def binSearch(low: Long, hi: Long): Long = {\n if (hi < low) low\n else {\n val mid = (low + hi) >>> 1\n if (can(mid)) binSearch(low, mid - 1)\n else binSearch(mid + 1, hi)\n }\n }\n\n val h = binSearch(0, 100000000L)\n \n //if (d == 0 && a == 0) println(h)\n \n val cost = a * ca + d * cd + h * ch \n \n min = Math.min(min, cost)\n }\n }\n\n println(min)\n}"}], "src_uid": "bf8a133154745e64a547de6f31ddc884"} {"nl": {"description": "Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.More formally, you are given an odd numer n. Find a set of numbers pi (1 ≤ i ≤ k), such that 1 ≤ k ≤ 3 pi is a prime The numbers pi do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.", "input_spec": "The single line contains an odd number n (3 ≤ n < 109).", "output_spec": "In the first line print k (1 ≤ k ≤ 3), showing how many numbers are in the representation you found. In the second line print numbers pi in any order. If there are multiple possible solutions, you can print any of them.", "sample_inputs": ["27"], "sample_outputs": ["3\n5 11 11"], "notes": "NoteA prime is an integer strictly larger than one that is divisible only by one and by itself."}, "positive_code": [{"source_code": "/**\n * @author netman\n */\n\n\nimport java.io._\nimport scala._\nimport scala.Array._\nimport java.util.ArrayList\nimport scala.collection.mutable._\nimport java.util.StringTokenizer\n\n\nobject HelloWorld {\n\n class InputReader(reader: BufferedReader) {\n \n var tokenizer: StringTokenizer = null;\n \n def this(stream: InputStream) = {\n this(new BufferedReader(new InputStreamReader(stream), (1 << 20)));\n }\n \n def this(f: File) = {\n this(new BufferedReader(new FileReader(f), (1 << 20)));\n }\n \n def next(): String = {\n while (tokenizer == null || !tokenizer.hasMoreTokens()) {\n tokenizer = new StringTokenizer(reader.readLine());\n }\n return tokenizer.nextToken();\n }\n \n def nextInt(): Int = next().toInt\n \n def nextDouble(): Double = next().toDouble\n \n def close() = reader.close();\n }\n \n class OutputWriter(writer: PrintWriter) {\n def this(stream: OutputStream) {\n this(new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream))));\n }\n \n def this(f: File) = {\n this(new PrintWriter(new BufferedWriter(new FileWriter(f))));\n }\n \n def print(x: Any) = writer.print(x);\n \n def println(x: Any) = writer.println(x);\n \n def close() = writer.close();\n }\n \n \n val in = new InputReader(System.in)\n val out = new OutputWriter(System.out)\n \n def sieve = {\n val MAX_P = 2000\n var _isPrime = Array.fill[Boolean](MAX_P)(true)\n _isPrime(1) = false\n for (i <- 2 until MAX_P) {\n if (_isPrime(i)) {\n for (j <- i + i until MAX_P by i) {\n _isPrime(j) = false\n }\n }\n }\n \n var primes = ArrayBuffer.empty[Int]\n \n primes += 0\n \n for (i <- 1 until MAX_P) {\n if (_isPrime(i)) primes += i\n }\n \n primes\n }\n \n def isPrime(x: Int): Boolean = {\n if (x == 0) return true\n if (x == 1) return false\n val sqrtX = math.ceil(math.sqrt(x)).toInt\n for (i <- 2 to sqrtX) {\n if (x % i == 0) return false\n }\n return true\n }\n \n def main(args: Array[String]): Unit = { \n val primes = sieve\n \n val x = in.nextInt\n \n var i = 0\n while (primes(i) <= 1000 && primes(i) <= x) {\n var j = 0\n while (primes(j) <= 1000 && primes(i) + primes(j) <= x) {\n if (isPrime(x - primes(i) - primes(j))) {\n var res = ArrayBuffer.empty[Int]\n res += primes(i)\n res += primes(j)\n res += x - primes(i) - primes(j)\n \n while (res.indexOf(0) != -1) res.remove(res.indexOf(0))\n \n out.println(res.length)\n for (x <- res) {\n out.print(x + \" \")\n }\n out.println(\"\")\n \n out.close\n \n return\n }\n j += 1\n }\n i += 1\n }\n \n out.close\n }\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val n1 = in.next().toInt\n val first = 3\n val n = n1 - first\n\n def isPrime(n: Int) =\n if (n == 1) false\n else if (n == 2) true\n else if (n % 2 == 0) false\n else !(3 to Math.sqrt(n).toInt + 1 by 2).exists(i => n % i == 0)\n\n\n if (n == 0) {\n println(1)\n println(3)\n } else if (isPrime(n)) {\n println(2)\n println(\"3 \" + n)\n } else {\n val second = (2 until n).find(i => isPrime(i) && isPrime(n - i)).get\n println(3)\n println(s\"3 $second ${n - second}\")\n }\n}"}, {"source_code": "\nimport java.io._\nimport java.util.StringTokenizer\n\nobject D {\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 checkPrime(n: Int): Boolean = {\n if (n == 1)\n return false\n var ind = 2\n var flag = false\n while (!flag && ind <= Math.sqrt(n).toInt) {\n if (n % ind == 0) {\n flag = true\n }\n ind += 1\n }\n !flag\n }\n\n def solve: Int = {\n val n = nextInt\n var ind = 2\n var flag = false\n if (n == 4) {\n out.println(2)\n out.println(\"2 2\")\n return 0\n }\n while (!flag && ind <= Math.sqrt(n).toInt) {\n if (n % ind == 0) {\n flag = true\n }\n ind += 1\n }\n if (flag) {\n if (checkPrime(n - 3)) {\n out.println(2)\n out.println(\"3 \" + (n - 3))\n return 0\n }\n out.println(3)\n out.print(\"3 \")\n for (i <- 2 to 1e6.toInt) {\n if (checkPrime(i) && checkPrime(n - i - 3) && n - i - 3 > 0) {\n out.println(i + \" \" + (n - i - 3))\n return 0\n }\n }\n } else {\n out.println(1)\n out.println(n)\n }\n return 0\n }\n}\n"}], "negative_code": [{"source_code": "import scala.collection.mutable\n\nobject Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val n1 = in.next().toInt\n val first = 3\n val n = n1 - first\n\n def isPrime(n: Int) =\n if (n == 1) false\n else if (n == 2) true\n else !(3 to Math.sqrt(n).toInt + 1 by 2).exists(i => n % i == 0)\n\n\n if (n == 0) {\n println(1)\n println(3)\n } else {\n val set = mutable.Set(2)\n val notPrime = Array.ofDim[Boolean](n + 1)\n notPrime(1) = true\n notPrime(0) = true\n\n (4 to n by 2).foreach { i => notPrime(i) = true }\n (3 to n by 2).foreach { i =>\n if (!notPrime(i)) {\n set += i\n (2 * i to n by i).foreach { j => notPrime(j) = true }\n }\n }\n\n if (set.contains(n)) {\n println(2)\n println(\"3 \" + n)\n } else {\n val second = set.find(i => isPrime(i) && isPrime(n - i)).get\n println(3)\n println(s\"3 $second ${n - second}\")\n }\n }\n}"}], "src_uid": "f2aaa149ce81bf332d0b5d80b2a13bc3"} {"nl": {"description": "You have two variables a and b. Consider the following sequence of actions performed with these variables: If a = 0 or b = 0, end the process. Otherwise, go to step 2; If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3; If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process.Initially the values of a and b are positive integers, and so the process will be finite.You have to determine the values of a and b after the process ends.", "input_spec": "The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1018). n is the initial value of variable a, and m is the initial value of variable b.", "output_spec": "Print two integers — the values of a and b after the end of the process.", "sample_inputs": ["12 5", "31 12"], "sample_outputs": ["0 1", "7 12"], "notes": "NoteExplanations to the samples: a = 12, b = 5 a = 2, b = 5 a = 2, b = 1 a = 0, b = 1; a = 31, b = 12 a = 7, b = 12."}, "positive_code": [{"source_code": "object B extends App {\n\n @inline def tokenizeLine = new java.util.StringTokenizer(readLine)\n def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }\n\n var Array(a, b) = readLongs(2)\n\n var changed = true\n while (a != 0 && b != 0 && changed) {\n if (a >= 2 * b) {\n var bb = b\n while (2 * bb <= a) bb *= 2\n a -= bb\n } else if (b >= 2 * a) {\n var aa = a\n while (2 * aa <= b) aa *= 2\n b -= aa\n } else changed = false\n }\n\n println(s\"$a $b\")\n}\n"}, {"source_code": "object B extends App {\n val Array(n, m) = scala.io.StdIn.readLine().split(\" \").map(_.toLong)\n\n def weird(a: Long, b: Long): (Long, Long) =\n if (a == 0 || b == 0) (a, b)\n else {\n val ra = a % (2 * b)\n if (ra != a) weird(ra, b)\n else {\n val rb = b % (2 * a)\n if (rb != b) weird(a, rb)\n else (a, b)\n }\n }\n\n val (a, b) = weird(n, m)\n println(a + \" \" + b)\n}\n"}, {"source_code": "object BWeirdSubtractionProcess extends App {\n val Array(n, m) = scala.io.StdIn.readLine().split(\" \").map(_.toLong)\n\n def weird(a: Long, b: Long): (Long, Long) =\n if (a == 0 || b == 0) (a, b)\n else {\n val _b = 2 * b\n if (a >= _b) weird(a % _b, b)\n else {\n val _a = 2 * a\n if (b >= _a) weird(a, b % _a)\n else (a, b)\n }\n }\n\n val (a, b) = weird(n, m)\n println(a + \" \" + b)\n}\n"}, {"source_code": "object _946B extends CodeForcesApp {\n import Utils._, annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._, Math._\n\n override def apply(io: IO): io.type = {\n var a, b = io.read[Long]\n\n while(a > 0 && b > 0 && (a >= 2*b || b >= 2*a)) {\n if (a >= 2*b) {\n val ka = (a - 2*b)/(2*b) max 1L\n a -= ka*(2*b)\n } else {\n val kb = (b - 2*a)/(2*a) max 1L\n b -= kb*(2*a)\n }\n }\n\n io.writeAll(Seq(a, b))\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 isPrime(n: Int): Boolean = BigInt(n).isProbablePrime(31)\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"}], "negative_code": [{"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 var Array(a, b) = readLongs(2)\n\n var changed = true\n while (a * b != 0 && changed) {\n if (a >= 2 * b) {\n changed = true\n var bb = b\n while (2 * bb <= a) bb *= 2\n a -= bb\n } else if (b >= 2 * a) {\n changed = true\n var aa = a\n while (2 * aa <= b) aa *= 2\n b -= aa\n } else changed = false\n }\n\n println(s\"$a $b\")\n}\n"}], "src_uid": "1f505e430eb930ea2b495ab531274114"} {"nl": {"description": "Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.", "input_spec": "The first line contains integer n (1 ≤ n ≤ 100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains n positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show. The numbers in the lines are separated by a single space.", "output_spec": "In a single line print the answer to the problem.", "sample_inputs": ["1\n1", "1\n2", "2\n3 5"], "sample_outputs": ["3", "2", "3"], "notes": "NoteIn the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.In the second sample Dima can show 2 or 4 fingers."}, "positive_code": [{"source_code": "object CF272A {\n def main(argv: Array[String]) {\n val n = readInt\n val str = readLine.split(\" \")\n def readSum(i: Int, acc: Int): Int = {\n if (i == n) acc\n else readSum(i + 1, acc + str(i).toInt)\n }\n val sum = readSum(0, 0)\n def findAns(i: Int, acc: Int): Int = {\n if (i == 6) acc\n else {\n if ((sum + i) % (n + 1) != 1) findAns(i + 1, acc + 1)\n else findAns(i + 1, acc)\n }\n }\n println(findAns(1, 0))\n }\n}"}, {"source_code": "import java.util.StringTokenizer\n\nobject _272A 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 sum = (1 to n).map(i => next.toInt).sum\n val cb = (1 to 5).filter(i => (i + sum) % (n + 1) != 1)\n println(cb.size)\n}\n"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val n = in.next().toInt\n val sum = in.next().split(\" \").map(_.toInt).sum\n println((1 to 5).count(i => (i + sum - 1) % (n + 1) != 0))\n}"}, {"source_code": "object A272 {\n\n import IO._\n import collection.{mutable => cu}\n\n def solve(arr: Array[Int], fing: Int): Boolean = {\n (arr.sum + fing)%(arr.length+1) != 1\n }\n\n def main(args: Array[String]): Unit = {\n val Array(n) = readInts(1)\n val in = readInts(n)\n out.println((1 to 5).count(fing => solve(in, fing)))\n out.close()\n }\n\n object IO {\n private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n // private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(\"src/input\")))\n val out = new java.io.PrintWriter(System.out)\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"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P272A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val N = sc.nextInt\n val fs = List.fill(N)(sc.nextInt).sum\n\n val answer: Int = {\n for {\n i <- 1 to 5\n if ((fs + i - 1) % (N + 1) > 0)\n }\n yield 1\n }.sum\n\n out.println(answer)\n out.close\n}\n"}, {"source_code": "import java.util._\n\nobject Main {\n def main(args: Array[String]) {\n val in = new Scanner(System.in)\n val n = in.nextInt\n var s = 0\n for (i <- 0 to n - 1) {\n s += in.nextInt\n }\n \n var cnt = 0\n for (i <- 1 to 5) {\n if ((s + i) % (n + 1) != 1) {\n cnt += 1\n }\n }\n println(cnt)\n }\n}"}, {"source_code": "object Fuck {\n def main(args: Array[String]) {\n var n = readInt()+1\n var a = readLine().split(\" \").toList map (_.toInt) sum;\n println(Range(1,6) count (x => (x+a) % n != 1))\n }\n}\n"}, {"source_code": "import annotation.tailrec\nimport java.io._\n\nobject Easy {\n val reader = new BufferedReader(new InputStreamReader(System.in))\n def readInts = reader.readLine().split(\" \").map(_.toInt)\n def readInt = reader.readLine().toInt\n\n val n = readInt\n val fingers = readInts.sum\n def ans = (1 to 5).count(x => (x + fingers) % (n + 1) != 1)\n\n def main(args: Array[String]) {\n println(ans)\n }\n}\n"}, {"source_code": "object A\n{\n def main(args: Array[String])\n {\n val n = readLine.toInt\n val fingers= readLine.split(\" \").map(_.toInt).sum\n println((1 to 5) map(_+fingers) filter(_%(n+1)!=1) length)\n }\n}"}, {"source_code": "object A\n{\n def main(args: Array[String])\n {\n val n = readLine.toInt\n val fingers= readLine.split(\" \").map(_.toInt).sum\n println((1 to 5) filter{x=>(x+fingers)%(n+1)!=1} length)\n }\n}\n"}, {"source_code": "import java.util._\n\nobject Main {\n def main(args: Array[String]) {\n val in = new Scanner(System.in)\n val n = in.nextInt\n var s = 0\n for (i <- 0 to n - 1) {\n s += in.nextInt\n }\n \n var cnt = 0\n for (i <- 1 to 5) {\n if ((s + i) % (n + 1) != 1) {\n cnt += 1\n }\n }\n println(cnt)\n }\n}"}, {"source_code": "import collection.mutable.Map\nimport collection.mutable.ArrayBuffer\n\nobject test6 extends App {\n val n=readInt\n val total=readLine.split(\" \").map(_.toInt).sum\n \n val ans=(for(i<-1 to 5) yield {\n if((total+i)%(n+1)==1) 0 else 1 \n }) sum\n \n println(ans)\n} \n\n\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val n = readInt\n val sum = readLine().split(\" \").map(_.toInt).sum\n val r = (1 to 5).foldLeft(0) { (acc, i) => \n if ((sum + i) % (n + 1) == 1) acc\n else acc + 1\n }\n println(r)\n }\n}"}], "negative_code": [{"source_code": "object A272 {\n\n import IO._\n import collection.{mutable => cu}\n\n def solve(arr: Array[Int], fing: Int): Boolean = {\n (arr.sum + fing)%(arr.length+1) != 1\n }\n\n def main(args: Array[String]): Unit = {\n val Array(n) = readInts(1)\n val in = readInts(n)\n var break = false\n for(fing <- 2 to 5 if !break) {\n if(solve(in, fing)) {\n out.println(fing)\n break = true\n }\n }\n out.close()\n }\n\n object IO {\n private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n // private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(\"src/input\")))\n val out = new java.io.PrintWriter(System.out)\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"}, {"source_code": "object A272 {\n\n import IO._\n import collection.{mutable => cu}\n\n def solve(arr: Array[Int], fing: Int): Boolean = {\n (arr.sum + fing)%(arr.length+1) == 0\n }\n\n def main(args: Array[String]): Unit = {\n val Array(n) = readInts(1)\n val in = readInts(n)\n var break = false\n for(fing <- 1 to 5 if !break) {\n if(solve(in, fing)) {\n out.println(fing)\n break = true\n }\n }\n out.close()\n }\n\n object IO {\n private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n // private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(\"src/input\")))\n val out = new java.io.PrintWriter(System.out)\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"}, {"source_code": "object A272 {\n\n import IO._\n import collection.{mutable => cu}\n\n def solve(arr: Array[Int], fing: Int): Boolean = {\n (arr.sum + fing)%(arr.length+1) == 0\n }\n\n def main(args: Array[String]): Unit = {\n val Array(n) = readInts(1)\n val in = readInts(n)\n var break = false\n for(fing <- 2 to 5 if !break) {\n if(solve(in, fing)) {\n out.println(fing)\n break = true\n }\n }\n out.close()\n }\n\n object IO {\n private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n // private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(\"src/input\")))\n val out = new java.io.PrintWriter(System.out)\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": "ff6b3fd358c758324c19a26283ab96a4"} {"nl": {"description": "Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?You are given a system of equations: You should count, how many there are pairs of integers (a, b) (0 ≤ a, b) which satisfy the system.", "input_spec": "A single line contains two integers n, m (1 ≤ n, m ≤ 1000) — the parameters of the system. The numbers on the line are separated by a space.", "output_spec": "On a single line print the answer to the problem.", "sample_inputs": ["9 3", "14 28", "4 20"], "sample_outputs": ["1", "1", "0"], "notes": "NoteIn the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair."}, "positive_code": [{"source_code": "object Round131A2 {\n\n def main(args: Array[String]): Unit = {\n val Array(n, m) = readLine().split(\" \").map(_.toInt)\n var res = 0\n for (a <- 0 to 1000)\n for (b <- 0 to 1000)\n if (a * a + b == n && a + b * b == m)\n res = res + 1\n println(res)\n }\n\n}"}, {"source_code": "import java.util.StringTokenizer\n\nobject _214A 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 ans = for {\n a <- 0 to m\n val b = n - a * a\n if (b >= 0 && a + b * b == m)\n } yield 1\n println(ans.sum)\n}\n"}, {"source_code": "object Solution extends App {\n val Array(n, m) = readLine().split(\" \").map(_.toInt)\n println(Range(0, 1000).flatMap(i => Range(0, 1000).map(t => (i, t))).count{\n case(a, b) => a * a + b == n && a + b * b == m\n })\n\n}"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P214A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n val N, M = sc.nextInt\n\n val answer = {\n for {\n i <- 0 until 32\n j <- 0 until 32\n if i * i + j == N && i + j * j == M\n } yield 1\n }.sum\n\n out.println(answer)\n out.close\n}\n"}, {"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 Array(n, m) = readInts\n def sqr(x: Int) = x * x\n def ans = (0 to n).filter(n - sqr(_) >= 0).count(a => a + sqr(n - sqr(a)) == m)\n\n def main(a: Array[String]) {\n println(ans)\n }\n}\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val mn = readLine().split(\" \").map(_.toInt)\n val m = mn(0)\n val n = mn(1)\n var count = 0\n val s = for {\n a <- 0 to (Math.sqrt(m).toInt + 1)\n b <- 0 to (Math.sqrt(n).toInt + 1) \n if a * a + b == m && a + b * b == n\n } yield (1)\n println(s.size)\n }\n}"}, {"source_code": "object A{\n def main(args: Array[String]){\n\n val (n,m)={\n val sp=readLine.split(\" \")\n (sp(0).toInt, sp(1).toInt)\n }\n \n println(\n 0 to 1000 count{a=>\n val b= n-a*a\n b>=0 && a+b*b==m\n }\n )\n }\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject Main {\n def main(args: Array[String]): Unit = {\n val Array(n, m) = StdIn.readLine().split(\" \").map(_.toInt)\n println(f(n, m))\n }\n\n def f(n: Int, m: Int): Int = {\n var r = 0\n for {\n a <- 0 to 100\n b <- 0 to 100\n if a * a + b == n && a + b * b == m\n } yield {\n r += 1\n }\n r\n }\n}\n"}], "negative_code": [{"source_code": "object Round131A2 {\n\n def main(args: Array[String]): Unit = {\n val Array(n, m) = readLine().split(\" \").map(_.toInt)\n var res = 0\n for (a <- 1 to 1000)\n for (b <- 1 to 1000)\n if (a * a + b == n && a + b * b == m)\n res = res + 1\n println(res)\n }\n\n}"}, {"source_code": "object Solution extends App {\n val Array(n, m) = readLine().split(\" \").map(_.toInt)\n println(Range(0, 1000).flatMap(i => Range(0, i).map(t => (i, t))).count{\n case(a, b) => a * a + b == n && a + b * b == m\n })\n\n}"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P214A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val N, M = sc.nextInt\n\n out.println(List(N, M).mkString(\" \"))\n\n val answer = {\n for {\n a <- 0 to math.sqrt(N).floor.toInt\n b = math.sqrt(M - a).floor.toInt\n if a + b * b == M && a * a + b == N\n } yield 1\n }.size\n\n out.println(answer)\n out.close\n}\n"}, {"source_code": "object A{\n def main(args: Array[String]){\n\n val (n,m)={\n val sp=readLine.split(\" \")\n (sp(0).toInt, sp(1).toInt)\n }\n \n println(\n 0 to 1000 count{a=>\n val b= n-a*a\n a+b*b==m\n }\n )\n }\n}\n"}], "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd"} {"nl": {"description": "George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t. Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second test sample). ", "input_spec": "The first line contains current time s as a string in the format \"hh:mm\". The second line contains time t in the format \"hh:mm\" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59.", "output_spec": "In the single line print time p — the time George went to bed in the format similar to the format of the time in the input.", "sample_inputs": ["05:50\n05:44", "00:00\n01:00", "00:01\n00:00"], "sample_outputs": ["00:06", "23:00", "00:01"], "notes": "NoteIn the first sample George went to bed at \"00:06\". Note that you should print the time only in the format \"00:06\". That's why answers \"0:06\", \"00:6\" and others will be considered incorrect. In the second sample, George went to bed yesterday.In the third sample, George didn't do to bed at all."}, "positive_code": [{"source_code": "\nobject ThreeEightSevenA {\n\n\tdef main(args: Array[String]): Unit = {\n\t\tvar to=readLine.split(':').map(_.toInt)\n\t\tvar from=readLine.split(':').map(_.toInt)\n\t\t\n\t\tif(to(0)==from(0) && to(1)==from(1)){\n\t\t\tprintln(\"00:00\")\n\t\t\treturn\n\t\t}\n\t\t\n\t\tif(to(0)==0 && to(1)==0){\n\t\t\tto(0)=24\n\t\t}\n\t\t\n\t\t\n\t\tvar h=to(0)-from(0)\n\t\tvar min=to(1)-from(1)\n\t\t\n\t\tif(min<0)\n\t\t{\n\t\t\th=h-1\n\t\t\tmin+=60\n\t\t}\n\t\tif(h<0){\n\t\t\th+=24\n\t\t}\n\t\tif(h<10)\n\t\t\tprint(\"0\"+h)\n\t\telse\n\t\t\tprint(h)\n\t\t\n\t\tprint(\":\")\n\t\t\n\t\tif(min<10)\n\t\t\tprintln(\"0\"+min)\n\t\telse\n\t\t\tprintln(min)\n\t\t\n\t}\n}"}, {"source_code": "import java.util.StringTokenizer\n\nobject _387A extends App {\n var token = new StringTokenizer(\"\")\n\n def next = {\n while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)\n token.nextToken()\n }\n\n val cb = next.split(\":\").map(s => s.toInt)\n val wb = next.split(\":\").map(s => s.toInt)\n\n var h = cb(0)\n var m = cb(1)\n val h1 = wb(0)\n val m1 = wb(1)\n\n if (h < h1 || h == h1 && m < m1) h += 24\n\n if (m < m1) {\n m += 60\n h -= 1\n }\n\n println(\"%02d:%02d\".format(h - h1, m - m1))\n}\n"}, {"source_code": "object Solution extends App {\n\n val in = scala.io.Source.stdin.getLines()\n val k = in.next()\n val t = in.next()\n var hourNow = k.take(2).toInt\n var minutesNow = k.drop(3).toInt\n val hours = t.take(2).toInt\n val minutes = t.drop(3).toInt\n if (minutesNow < minutes) {\n minutesNow += 60\n hourNow -= 1\n }\n if (hourNow < hours)\n hourNow += 24\n hourNow -= hours\n minutesNow -= minutes\n println(f\"$hourNow%02d:$minutesNow%02d\")\n\n\n}"}, {"source_code": "import java.util.Scanner\n\nobject P387A {\n class Time(timeString: String) {\n val splitTime = timeString.split(\":\")\n val hour = splitTime(0).toInt\n val minute = splitTime(1).toInt\n val totalMinute = hour * 60 + minute\n def -(that: Time): Time = {\n val t = (this.totalMinute - that.totalMinute + 60 * 24) % (60 * 24)\n new Time(t / 60 + \":\" + t % 60)\n }\n override def toString =\n \"0\" * (2 - hour.toString.length) + hour + \":\" + \"0\" * (2 - minute.toString.length) + minute\n }\n\n def main(args: Array[String]) {\n val scanner = new Scanner(System.in)\n val wakeUpTime = new Time(scanner.next())\n val sleepTime = new Time(scanner.next())\n val bedInTime = wakeUpTime - sleepTime\n println(bedInTime)\n }\n}\n"}, {"source_code": "object A387 {\n\n import IO._\n import collection.{mutable => cu}\n\n def main(args: Array[String]): Unit = {\n val curr = read.split(\":\").map(_.toInt)\n val time = read.split(\":\").map(_.toInt)\n\n val start = Array(((if(curr(1)-time(1) < 0) -1 else 0) + 24+curr(0)-time(0))%24, (60+curr(1)-time(1))%60)\n\n out.println(s\"${\"%02d\".format(start(0))}:${\"%02d\".format(start(1))}\")\n out.close()\n }\n\n object IO {\n private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n // private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(\"src/input\")))\n val out = new java.io.PrintWriter(System.out)\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"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P387A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n \n object Clock {\n def apply(m: Int): String = {\n val hour = m / 60\n val min = m % 60\n f\"$hour%02d:$min%02d\"\n }\n\n def unapply(s: String): Option[Int] = {\n val parts = s split \":\"\n if (parts.length == 2) Some(parts(0).toInt * 60 + parts(1).toInt)\n else None\n }\n }\n\n def solve(): String = {\n val Clock(t0) = sc.nextLine\n val Clock(t1) = sc.nextLine\n if (t0 >= t1) Clock(t0 - t1)\n else Clock(t0 - t1 + 1440)\n }\n\n out.println(solve)\n out.close\n}\n"}, {"source_code": "import java.util.Scanner\n\n/**\n * Created by Kuang.Ru on 14-10-10.\n */\nobject A387 {\n def main(args: Array[String]) {\n val sc = new Scanner(System.in)\n val s, t = sc.next()\n var st = s.split(\":\").map(_.toInt)\n val tt = t.split(\":\").map(_.toInt)\n var goBedMin = st(1) - tt(1)\n\n if (goBedMin < 0) {\n st(0) -= 1\n goBedMin = 60 + goBedMin\n }\n\n var goBedHour = st(0) - tt(0)\n\n if (goBedHour < 0) {\n goBedHour = 24 + goBedHour\n }\n\n printf(\"%02d:%02d\", goBedHour, goBedMin)\n }\n}\n"}, {"source_code": "import scala.util.matching.Regex\n\nobject A extends App {\n def ms2s(ms: (Int, Int)) = { ms._1*60 + ms._2 }\n def s2ms(s: Int) = { (s/60, s%60) }\n def str2ms(s: String): (Int, Int) = {\n val p: Regex = \"\"\"([0-9][0-9]):([0-9][0-9])\"\"\".r\n val m: Regex.Match = p.findFirstMatchIn(s).get\n return (m.group(1).toInt, m.group(2).toInt)\n }\n \n val a = readLine()\n val b = readLine()\n \n var ta = ms2s(str2ms(a))\n val tb = ms2s(str2ms(b))\n \n if (ta < tb) ta += 24*60\n val ans = s2ms(ta - tb)\n println(\"%02d:%02d\".format(ans._1, ans._2))\n}\n"}, {"source_code": "import scala.util.matching.Regex\n\nobject A extends App {\n def ms2s(ms: (Int, Int)) = { ms._1*60 + ms._2 }\n def s2ms(s: Int) = { (s/60, s%60) }\n def str2ms(s: String): (Int, Int) = {\n val p: Regex = \"\"\"([0-9][0-9]):([0-9][0-9])\"\"\".r\n val m: Regex.Match = p.findFirstMatchIn(s).get\n return (m.group(1).toInt, m.group(2).toInt)\n }\n \n var ta, tb = ms2s(str2ms(readLine()))\n val ans = s2ms(ta+(if (ta < tb) 24*60 else 0) - tb)\n println(\"%02d:%02d\".format(ans._1, ans._2))\n}\n"}], "negative_code": [{"source_code": "\nobject ThreeEightSevenA {\n\n\tdef main(args: Array[String]): Unit = {\n\t\tvar to=readLine.split(':').map(_.toInt)\n\t\tvar from=readLine.split(':').map(_.toInt)\n\t\tif(to(0)==from(0) && to(1)==from(1)){\n\t\t\tprintln(\"00:00\")\n\t\t\treturn\n\t\t}\n\t\tif(to(0)==0 && to(1)==0){\n\t\t\tto(0)=24\n\t\t}\n\t\tvar h=to(0)-from(0)\n\t\tvar min=to(1)-from(1)\n\t\t\n\t\tif(min<0)\n\t\t{\n\t\t\th=h-1\n\t\t\tmin=min+60\n\t\t}\n\t\t\n\t\tif(h<10)\n\t\t\tprint(\"0\"+h)\n\t\telse\n\t\t\tprint(h)\n\t\tprint(\":\")\n\t\tif(min<10)\n\t\t\tprintln(\"0\"+min)\n\t\telse\n\t\t\tprintln(min)\n\t\t\n\t}\n}"}, {"source_code": "\nobject ThreeEightSevenA {\n\n\tdef main(args: Array[String]): Unit = {\n\t\tvar to=readLine.split(':').map(_.toInt)\n\t\tvar from=readLine.split(':').map(_.toInt)\n\t\tif(to(0)==0 && to(1)==0){\n\t\t\tto(0)=24\n\t\t}\n\t\tvar h=to(0)-from(0)\n\t\tvar min=to(1)-from(1)\n\t\tif(min<0)\n\t\t{\n\t\t\th=h-1\n\t\t\tmin=min+60\n\t\t}\n\t\tif(h<10)\n\t\t\tprint(\"0\"+h)\n\t\telse\n\t\t\tprint(h)\n\t\tprint(\":\")\n\t\tif(min<10)\n\t\t\tprintln(\"0\"+min)\n\t\telse\n\t\t\tprintln(min)\n\t}\n\n}"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P387A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n \n object Clock {\n def apply(m: Int): String = {\n val hour = m / 60\n val min = m % 60\n f\"$hour%02d:$min%02d\"\n }\n\n def unapply(s: String): Option[Int] = {\n val parts = s split \":\"\n if (parts.length == 2) Some(parts(0).toInt * 60 + parts(1).toInt)\n else None\n }\n }\n\n def solve(): String = {\n val Clock(t0) = sc.nextLine\n val Clock(t1) = sc.nextLine\n if (t0 > t1) Clock(t0 - t1)\n else Clock(t0 - t1 + 1440)\n }\n\n out.println(solve)\n out.close\n}\n"}], "src_uid": "595c4a628c261104c8eedad767e85775"} {"nl": {"description": "Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.", "input_spec": "The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).", "output_spec": "Output the decoded ternary number. It can have leading zeroes.", "sample_inputs": [".-.--", "--.", "-..-.--"], "sample_outputs": ["012", "20", "1012"], "notes": null}, "positive_code": [{"source_code": "object P032B extends App {\n def f(a: List[Char]):Unit = a match {\n case '.'::tail => print(0); f(tail)\n case '-'::'.'::tail => print(1); f(tail)\n case '-'::'-'::tail => print(2); f(tail)\n case Nil =>\n }\n f(readLine.toList)\n}\n\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val text = in.next().foldLeft(None: Option[Char], List.empty[Int]) {\n case((None, list), '.') => (None, 0 :: list)\n case((None, list), '-') => (Some('-'), list)\n case((Some('-'), list), '-') => (None, 2 :: list)\n case((Some('-'), list), '.') => (None, 1 :: list)\n }\n\n println(text._2.reverse.mkString)\n\n}\n\n\n"}, {"source_code": "object BBorze extends App {\n import scala.io.StdIn._\n\n val ans = readLine()\n .foldLeft((List.empty[Int], \"\")) {\n case ((codes, code), part) =>\n code + part match {\n case \".\" => (0 :: codes, \"\")\n case \"-.\" => (1 :: codes, \"\")\n case \"--\" => (2 :: codes, \"\")\n case _ => (codes, part.toString)\n }\n }\n ._1\n .reverse\n\n println(ans.mkString(\"\"))\n}\n"}, {"source_code": "object BBorze extends App {\n import scala.io.StdIn._\n\n val ans = readLine().replace(\"--\", \"2\").replace(\"-.\", \"1\").replace(\".\", \"0\")\n\n println(ans.mkString(\"\"))\n}\n"}, {"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;\n var result = \"\";\n while (s.length > 0) {\n if (s.startsWith(\".\")) {\n result += \"0\";\n s = s.replaceFirst(\".\", \"\");\n } else if (s.startsWith(\"-.\")) {\n result += \"1\";\n s = s.replaceFirst(\"-.\", \"\");\n } else if (s.startsWith(\"--\")) {\n result += \"2\";\n s = s.replaceFirst(\"--\", \"\");\n }\n }\n println(result);\n }\n\n}"}, {"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;\n var result = \"\";\n var ind = 0;\n while (ind < s.length) {\n if (s.startsWith(\".\", ind)) {\n result += \"0\";\n ind += 1;\n } else if (s.startsWith(\"-.\", ind)) {\n result += \"1\";\n ind += 2;\n } else if (s.startsWith(\"--\", ind)) {\n result += \"2\";\n ind += 2;\n }\n }\n println(result);\n }\n\n}"}], "negative_code": [], "src_uid": "46b5a1cd1bd2985f2752662b7dbb1869"} {"nl": {"description": "In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed. Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.", "input_spec": "Four lines contain four characters each: the j-th character of the i-th line equals \".\" if the cell in the i-th row and the j-th column of the square is painted white, and \"#\", if the cell is black.", "output_spec": "Print \"YES\" (without the quotes), if the test can be passed and \"NO\" (without the quotes) otherwise.", "sample_inputs": ["####\n.#..\n####\n....", "####\n....\n####\n...."], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column."}, "positive_code": [{"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val data = (1 to 4).map(_ => in.next().map{t => if (t == '#') 1 else 0}).toArray\n val r = (1 to 3).map(i =>\n (1 to 3).map{\n j =>\n val sum = data(i)(j) + data(i - 1)(j) + data(i)(j - 1) + data(i - 1)(j - 1)\n Math.max(sum, 4 - sum)\n }.max\n ).max\n if (r < 3)\n println(\"NO\")\n else\n println(\"YES\")\n}"}, {"source_code": "object IQ {\n \n def main (args : Array[String]){\n var a = new Array[String](4)\n for (i <- 0 to 3)\n a(i) = readLine\n for (i <- 1 to 3; j <- 1 to 3){\n var ans = 0\n if (a(i).charAt(j)=='.')ans +=1\n if (a(i-1).charAt(j-1)=='.')ans +=1\n if (a(i).charAt(j-1)=='.')ans +=1\n if (a(i-1).charAt(j)=='.')ans +=1\n if (ans!=2){\n \t println(\"YES\");return\n \t }\n }\n println(\"NO\") \n }\n\n}"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P287A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n type Grid = Array[Array[Char]]\n val grid: Grid = Array.fill(4)(sc.nextLine.toArray)\n \n def solve(): String = {\n def test(i: Int, j: Int): Boolean = {\n val cells = List(List(i, j), List(i + 1, j), List(i, j + 1), List(i + 1, j + 1))\n cells.count {\n case List(x, y) => grid(x)(y) == '#'\n } != 2\n }\n\n if ((for (i <- 0 until 3; j <- 0 until 3) yield test(i, j)).exists(_ == true)) \"YES\"\n else \"NO\"\n }\n\n out.println(solve)\n out.close\n}\n"}, {"source_code": "\nobject A {\n def R = readLine().split(\" \") map(_.toInt)\n\n def main(args: Array[String]) {\n var a = Array.ofDim[Boolean](4,4)\n def check(b:Boolean):Boolean = {\n for (x <- 0 until 3; y <- 0 until 3 if (a(x)(y) == b &&a(x+1)(y) ==b &&a(x)(y+1) == b &&a(x+1)(y+1) == b)) return true;\n return false;\n }\n for (i <- 0 until 4)\n a(i) = readLine().toCharArray() map(x => if (x == '#') true else false)\n\n if (check(true) || check(false)) {\n println(\"YES\")\n return;\n }\n for (b <- List(false, true); i <- 0 until 4; j <- 0 until 4 if (a(i)(j) != b)) {\n a(i)(j) = b;\n if (check(b)) {\n println(\"YES\")\n return;\n }\n a(i)(j) = !b;\n }\n println(\"NO\")\n \n }\n\n}"}, {"source_code": "import annotation.tailrec\nimport java.io._\n\nobject Easy {\n val reader = new BufferedReader(new InputStreamReader(System.in))\n def readInts = reader.readLine().split(\" \").map(_.toInt)\n def readInt = reader.readLine().toInt\n\n val board = for(_ <- 1 to 4) yield reader.readLine().map {\n case '.' => 0\n case _ => 1\n }\n def ans = (for(i <- 0 to 2) yield (for(j <- 0 to 2) yield {\n val sum = board(i)(j) + board(i + 1)(j) + board(i)(j + 1) + board(i + 1)(j + 1)\n sum != 2\n }).contains(true)).contains(true)\n def yesNoAns = Map(true -> \"YES\", false -> \"NO\")\n\n def main(args: Array[String]) {\n println(yesNoAns(ans))\n }\n}\n"}, {"source_code": "object A\n{\n\tdef main(args: Array[String]) {\n\t\tval sz = 4\n\t\tval maze = Array.ofDim[Int](sz, sz)\n\t\tfor (i <- 0 until sz) {\n\t\t\tmaze(i) = readLine.split(\"\").tail.map( x => if(x == \"#\") 1 else 0 )\n\t\t}\n\t\tval result = (for (i <- 0 until sz - 1; j <- 0 until sz - 1) yield(i, j)).map( pos => {\n\t\t\t\t\t\t\tval (x, y) = pos\n\t\t\t\t\t\t\tval ss = maze(x)(y) + maze(x+1)(y) + maze(x)(y+1) + maze(x+1)(y+1)\n\t\t\t\t\t\t\tif(ss >= 3 || ss<=1) true else false\n\t\t\t\t\t\t}) reduceLeft(_ || _)\n\t\tprintln(if(result) \"YES\" else \"NO\")\n\t}\n}\n\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val al = new Array[String](4)\n al(0) = readLine()\n al(1) = readLine()\n al(2) = readLine()\n al(3) = readLine()\n \n val sqs = for {\n i <- 0 to 2\n j <- 0 to 2\n } yield(Seq(al(i)(j), al(i)(j + 1), al(i + 1)(j), al(i + 1)(j + 1)))\n if (sqs.count{ s => \n val bl = s.count(_ == '#')\n bl <= 1 || bl >= 3\n } >= 1) println(\"YES\")\n else println(\"NO\")\n }\n}"}, {"source_code": "object CFContest176Div2A {\n def main(args: Array[String]){\n var inp = new Array[Array[Char]](4);\n inp = inp.map(_ => readLine().toCharArray())\n var result = false;\n var i =0; var j = 0;\n for(i <- 0 to 2; j <- 0 to 2){\n var b=0;\n for(k<- 0 to 1; l<- 0 to 1){\n if(inp(i+k)(j+l) == '#') b+=1;\n \n }\n result = result || (b<=1 || b>=3)\n }\n if(result) println(\"YES\") else println(\"NO\")\n \n }\n}"}], "negative_code": [{"source_code": "object CFContest176Div2A {\n def main(args: Array[String]){\n var inp = new Array[Array[Char]](4);\n inp = inp.map(_ => readLine().toCharArray())\n var result = false;\n var i =0; var j = 0;\n for(i <- 0 to 2; j <- 0 to 2){\n var b=0;\n for(k<- 0 to 1; l<- 0 to 1){\n if(inp(i+k)(j+l) == '#') b+=1;\n \n }\n result = result || (b==1 || b==3)\n }\n if(result) println(\"YES\") else println(\"NO\")\n \n }\n}"}, {"source_code": "object IQ {\n \n def main (args : Array[String]){\n var a = new Array[String](4)\n for (i <- 0 until 4)\n a(i) = readLine\n var ans = 0\n for (i <- 1 to 3; j <- 1 to 3){\n if (a(i).charAt(j)=='.')ans +=1\n if (a(i-1).charAt(j-1)=='.')ans +=1\n if (a(i-1).charAt(j+1)=='.')ans +=1\n if (a(i+1).charAt(j-1)=='.')ans +=1\n if (ans!=2){\n \t println(\"YES\");return}\n }\n println(\"No\") \n }\n\n}"}, {"source_code": "object IQ {\n \n def main (args : Array[String]){\n var a = new Array[String](4)\n for (i <- 0 until 4)\n a(i) = readLine\n var ans = 0\n for (i <- 0 to 1)\n for (j <- 0 to 1)\n if (a(i).charAt(j)=='.')ans +=1\n if (ans==3 || ans==1){\n println(\"YES\");return}\n ans = 0\n for (i <- 2 to 3)\n for (j <- 0 to 1)\n if (a(i).charAt(j)=='.')ans +=1\n if (ans==3 || ans==1){\n println(\"YES\");return}\n ans = 0\n for (i <- 2 to 3)\n for (j <- 2 to 3)\n if (a(i).charAt(j)=='.')ans +=1\n if (ans==3 || ans==1){\n println(\"YES\");return}\n ans = 0\n for (i <- 0 to 1)\n for (j <- 2 to 3)\n if (a(i).charAt(j)=='.')ans +=1\n if (ans==3 || ans==1){\n println(\"YES\");return}\n println(\"NO\") \n \n }\n\n}"}, {"source_code": "\nobject A {\n def R = readLine().split(\" \") map(_.toInt)\n\n def main(args: Array[String]) {\n var a = Array.ofDim[Boolean](4,4)\n def check:Boolean = {\n for (x <- 0 until 3; y <- 0 until 3 if (a(x)(y)&&a(x+1)(y)&&a(x)(y+1)&&a(x+1)(y+1))) return true;\n return false;\n }\n for (i <- 0 until 4)\n a(i) = readLine().toCharArray() map(x => if (x == '#') true else false)\n\n for (i <- 0 until 4; j <- 0 until 4 if (!a(i)(j))) {\n a(i)(j) = true;\n if (check) {\n println(\"YES\")\n return;\n }\n a(i)(j) = false;\n }\n println(\"NO\")\n \n }\n\n}"}, {"source_code": "\nobject A {\n def R = readLine().split(\" \") map(_.toInt)\n\n def main(args: Array[String]) {\n var a = Array.ofDim[Boolean](4,4)\n def check(b:Boolean):Boolean = {\n for (x <- 0 until 3; y <- 0 until 3 if (a(x)(y) == b &&a(x+1)(y) ==b &&a(x)(y+1) == b &&a(x+1)(y+1) == b)) return true;\n return false;\n }\n for (i <- 0 until 4)\n a(i) = readLine().toCharArray() map(x => if (x == '#') true else false)\n\n \n for (b <- List(false, true); i <- 0 until 4; j <- 0 until 4 if (a(i)(j) != b)) {\n a(i)(j) = b;\n if (check(b)) {\n println(\"YES\")\n return;\n }\n a(i)(j) = !b;\n }\n println(\"NO\")\n \n }\n\n}"}, {"source_code": "object CFContest176Div2A {\n def main(args: Array[String]){\n var inp = new Array[Array[Char]](4);\n inp = inp.map(_ => readLine().toCharArray())\n var result = false;\n var i =0; var j = 0;\n for(i <- 0 to 2; j <- 0 to 2){\n var b=0;\n for(k<- 0 to 1; l<- 0 to 1){\n if(inp(i+k)(j+l) == '#') b+=1;\n \n }\n result = result || (b<1 || b>3)\n }\n if(result) println(\"YES\") else println(\"NO\")\n \n }\n}"}], "src_uid": "01b145e798bbdf0ca2ecc383676d79f3"} {"nl": {"description": "Alice and Bob are decorating a Christmas Tree. Alice wants only $$$3$$$ types of ornaments to be used on the Christmas Tree: yellow, blue and red. They have $$$y$$$ yellow ornaments, $$$b$$$ blue ornaments and $$$r$$$ red ornaments.In Bob's opinion, a Christmas Tree will be beautiful if: the number of blue ornaments used is greater by exactly $$$1$$$ than the number of yellow ornaments, and the number of red ornaments used is greater by exactly $$$1$$$ than the number of blue ornaments. That is, if they have $$$8$$$ yellow ornaments, $$$13$$$ blue ornaments and $$$9$$$ red ornaments, we can choose $$$4$$$ yellow, $$$5$$$ blue and $$$6$$$ red ornaments ($$$5=4+1$$$ and $$$6=5+1$$$).Alice wants to choose as many ornaments as possible, but she also wants the Christmas Tree to be beautiful according to Bob's opinion.In the example two paragraphs above, we would choose $$$7$$$ yellow, $$$8$$$ blue and $$$9$$$ red ornaments. If we do it, we will use $$$7+8+9=24$$$ ornaments. That is the maximum number.Since Alice and Bob are busy with preparing food to the New Year's Eve, they are asking you to find out the maximum number of ornaments that can be used in their beautiful Christmas Tree! It is guaranteed that it is possible to choose at least $$$6$$$ ($$$1+2+3=6$$$) ornaments.", "input_spec": "The only line contains three integers $$$y$$$, $$$b$$$, $$$r$$$ ($$$1 \\leq y \\leq 100$$$, $$$2 \\leq b \\leq 100$$$, $$$3 \\leq r \\leq 100$$$) — the number of yellow, blue and red ornaments. It is guaranteed that it is possible to choose at least $$$6$$$ ($$$1+2+3=6$$$) ornaments.", "output_spec": "Print one number — the maximum number of ornaments that can be used. ", "sample_inputs": ["8 13 9", "13 3 6"], "sample_outputs": ["24", "9"], "notes": "NoteIn the first example, the answer is $$$7+8+9=24$$$.In the second example, the answer is $$$2+3+4=9$$$."}, "positive_code": [{"source_code": "//package codeforces.contest1091\n\nobject NewYearAndTheChristmasOrnament {\n def main(args: Array[String]): Unit = {\n val Array(y, b, r) = io.StdIn.readLine.split(\" \").map(_.toInt)\n println(sumOfMaxPossibleIncrementalSequence(y, b, r))\n }\n\n def sumOfMaxPossibleIncrementalSequence(y: Int, b: Int, r: Int): Int = {\n if (!requiresFix(y, b) && !requiresFix(b, r)) y + b + r\n else {\n if (requiresFix(b, r)) {\n val f = fix(b, r)\n sumOfMaxPossibleIncrementalSequence(y, f._1, f._2)\n } else {\n val f = fix(y, b)\n sumOfMaxPossibleIncrementalSequence(f._1, f._2, r)\n }\n }\n }\n\n def requiresFix(x: Int, y: Int): Boolean = x + 1 != y\n\n def fix(x: Int, y: Int): (Int, Int) = {\n if (x < y) (x, x + 1)\n else (y - 1, y)\n }\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject A1091 {\n def main(args: Array[String]): Unit = {\n val Array (y_, b_, r_) = StdIn.readLine().split(' ').map{_.toInt}\n println(\n (for { y <- y_ to 1 by -1\n b <- b_ to 2 by -1\n r <- r_ to 3 by -1\n if r == b+1 && b == y+1 }\n yield y+b+r).take(1).head\n )\n }\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject NewYearAndTheChristmasOrnament extends App {\n\n val line = StdIn.readLine().split(\" \").map(_.toInt)\n\n val (y, b, r) = (line(0), line(1), line(2))\n\n val resY = Iterator\n .iterate(y)(_ - 1)\n .takeWhile(_ >= 1)\n .find(y1 => {\n val b1 = y1 + 1\n val r1 = b1 + 1\n\n b1 <= b && r1 <= r\n })\n .get\n\n println(resY + resY + 1 + resY + 2)\n}\n"}, {"source_code": "object A 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(y, b, r) = readInts(3)\n\n val y2 = y min (b - 1) min (r - 2)\n val b2 = y2 + 1\n val r2 = b2 + 1\n\n println(y2 + b2 + r2)\n\n Console.flush\n}\n"}], "negative_code": [], "src_uid": "03ac8efe10de17590e1ae151a7bae1a5"} {"nl": {"description": "Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically  — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $$$4.5$$$ would be rounded up to $$$5$$$ (as in example 3), but $$$4.4$$$ would be rounded down to $$$4$$$.This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $$$5$$$ (maybe even the dreaded $$$2$$$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $$$5$$$ for the course. Of course, Vasya will get $$$5$$$ for the lab works he chooses to redo.Help Vasya — calculate the minimum amount of lab works Vasya has to redo.", "input_spec": "The first line contains a single integer $$$n$$$ — the number of Vasya's grades ($$$1 \\leq n \\leq 100$$$). The second line contains $$$n$$$ integers from $$$2$$$ to $$$5$$$ — Vasya's grades for his lab works.", "output_spec": "Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $$$5$$$.", "sample_inputs": ["3\n4 4 4", "4\n5 4 5 5", "4\n5 3 3 5"], "sample_outputs": ["2", "0", "1"], "notes": "NoteIn the first sample, it is enough to redo two lab works to make two $$$4$$$s into $$$5$$$s.In the second sample, Vasya's average is already $$$4.75$$$ so he doesn't have to redo anything to get a $$$5$$$.In the second sample Vasya has to redo one lab work to get rid of one of the $$$3$$$s, that will make the average exactly $$$4.5$$$ so the final grade would be $$$5$$$."}, "positive_code": [{"source_code": "import scala.annotation.tailrec\nimport scala.io.StdIn.readLine\n\nobject Task2 extends App {\n val n = readLine().split(' ').map(_.toInt).head\n\n val marks = readLine().split(' ').map(_.toInt).toList.sorted\n\n @tailrec\n def sol(n: Int, marks: List[Int], index: Int = 0, res: Int = 0): Int =\n if (marks.sum.toDouble / n >= 4.5) res else sol(n, marks.updated(index, 5), index + 1, res + 1)\n\n println(sol(n, marks))\n\n}"}, {"source_code": "object Main{\n def main(arr: Array[String]): Unit ={\n val n = readInt()\n val a = readLine.split(\" \").map(_.toInt).map(_ * 10)\n\n val totReq = n * 45\n\n val as = a.sorted\n var ctot = as.sum\n var changes = 0\n var i = 0\n while(totReq > ctot && i < n){\n ctot += (50 - as(i))\n changes += 1\n i += 1\n }\n\n println(changes)\n }\n}"}, {"source_code": "import scala.annotation.tailrec\nimport scala.io.StdIn.readLine\nimport scala.math.ceil\n\nobject Main extends App {\n def read(): List[Int] = readLine().split(' ').map(_.toInt).toList\n @tailrec def f(marks: List[Int], need: Int, ans: Int = 0): Int = {\n if (need > 0) marks match {\n case _ :: Nil => ans + 1\n case x :: xs => f(xs, need - 5 + x, ans + 1)\n } else ans\n }\n val List(n) = read()\n val marks = read().sorted\n val need = ceil(n * 4.5).toInt - marks.sum\n println(f(marks, need))\n}\n"}, {"source_code": "import math._\nobject Main extends App {\n val n = readInt\n val m = ceil(4.5 * n).toInt\n val array = readLine.split(\" \").map(_.toInt).sorted\n val dif = m - array.sum\n if (dif <= 0) println(0)\n else {\n val a_2 = array.count(_ == 2)\n if (dif <= a_2 * 3) {\n println(ceil(dif / 3.0).toInt)\n } else {\n val r = dif - 3 * a_2\n val a_3 = array.count(_ == 3)\n if (r <= a_3 * 2) {\n println(ceil(r / 2.0).toInt + a_2)\n } else {\n println(dif - 2 * a_2 - a_3)\n }\n }\n }\n}"}], "negative_code": [{"source_code": "import math._\nobject Main extends App {\n val n = readInt\n val m = 5 * n - n / 2\n val array = readLine.split(\" \").map(_.toInt).sorted\n val dif = m - array.sum\n if (dif <= 0) println(0)\n else {\n val a_3 = array.count(_ == 3)\n if (dif <= a_3 * 2){\n println(ceil(dif / 2))\n } else {\n println(dif - a_3)\n }\n }\n}"}, {"source_code": "import math._\nobject Main extends App {\n val n = readInt\n val m = 5 * n - n / 2\n val array = readLine.split(\" \").map(_.toInt).sorted\n val dif = m - array.sum\n if (dif <= 0) println(0)\n else {\n val a_3 = array.count(_ == 3)\n if (dif <= a_3 * 2){\n println(ceil(dif / 2).toInt)\n } else {\n println(dif - a_3)\n }\n }\n}"}, {"source_code": "import math._\nobject Main extends App {\n val n = readInt\n val m = ceil(4.5 * n).toInt\n val array = readLine.split(\" \").map(_.toInt).sorted\n val dif = m - array.sum\n if (dif <= 0) println(0)\n else {\n val a_3 = array.count(_ == 3)\n if (dif <= a_3 * 2){\n println(ceil(dif / 2).toInt)\n } else {\n println(dif - a_3)\n }\n }\n}"}, {"source_code": "import math._\nobject Main extends App {\n val n = readInt\n val m = ceil(4.5 * n).toInt\n val array = readLine.split(\" \").map(_.toInt).sorted\n val dif = m - array.sum\n if (dif <= 0) println(0)\n else {\n val a_3 = array.count(_ == 3)\n if (dif <= a_3 * 2){\n println(ceil(dif / 2.0).toInt)\n } else {\n println(dif - a_3)\n }\n }\n}"}, {"source_code": "import math._\nobject Main extends App {\n val n = readInt\n val m = 5 * n - n / 2\n val array = readLine.split(\" \").map(_.toInt).sorted\n val dif = m - array.sum\n if (dif <= 0) println(0)\n else {\n val a_3 = array.count(_ == 3)\n if (dif <= a_3 * 2){\n println(dif / 2)\n } else {\n println(dif - a_3)\n }\n }\n}"}], "src_uid": "715608282b27a0a25b66f08574a6d5bd"} {"nl": {"description": "Imagine that you are in a building that has exactly n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to n. Now you're on the floor number a. You are very bored, so you want to take the lift. Floor number b has a secret lab, the entry is forbidden. However, you already are in the mood and decide to make k consecutive trips in the lift.Let us suppose that at the moment you are on the floor number x (initially, you were on floor a). For another trip between floors you choose some floor with number y (y ≠ x) and the lift travels to this floor. As you cannot visit floor b with the secret lab, you decided that the distance from the current floor x to the chosen y must be strictly less than the distance from the current floor x to floor b with the secret lab. Formally, it means that the following inequation must fulfill: |x - y| < |x - b|. After the lift successfully transports you to floor y, you write down number y in your notepad.Your task is to find the number of distinct number sequences that you could have written in the notebook as the result of k trips in the lift. As the sought number of trips can be rather large, find the remainder after dividing the number by 1000000007 (109 + 7).", "input_spec": "The first line of the input contains four space-separated integers n, a, b, k (2 ≤ n ≤ 5000, 1 ≤ k ≤ 5000, 1 ≤ a, b ≤ n, a ≠ b).", "output_spec": "Print a single integer — the remainder after dividing the sought number of sequences by 1000000007 (109 + 7).", "sample_inputs": ["5 2 4 1", "5 2 4 2", "5 3 4 1"], "sample_outputs": ["2", "2", "0"], "notes": "NoteTwo sequences p1, p2, ..., pk and q1, q2, ..., qk are distinct, if there is such integer j (1 ≤ j ≤ k), that pj ≠ qj.Notes to the samples: In the first sample after the first trip you are either on floor 1, or on floor 3, because |1 - 2| < |2 - 4| and |3 - 2| < |2 - 4|. In the second sample there are two possible sequences: (1, 2); (1, 3). You cannot choose floor 3 for the first trip because in this case no floor can be the floor for the second trip. In the third sample there are no sought sequences, because you cannot choose the floor for the first trip. "}, "positive_code": [{"source_code": "import scala.collection._\n\nobject C extends App {\n\n val M = 1000000007 \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, a, _b, k) = readInts(4)\n val b = _b - 1\n\n val counts = Array.fill(n){ 1L }\n val pSums = Array.ofDim[Long](n + 1)\n \n for (step <- 0 until k) {\n var s = 0L\n for (i <- 0 until n) {\n pSums(i) = s\n s += counts(i)\n }\n pSums(n) = s\n \n for (i <- 0 until n) if (i != b) {\n val delta = math.abs(b - i) - 1\n val l = if (i < b) 0 max (i - delta) else (b + 1) max (i - delta) \n val r = if (i > b) (n - 1) min (i + delta) else (b - 1) min (i + delta)\n counts(i) = (pSums(r + 1) - pSums(l) - counts(i)) % M\n }\n }\n \n println(counts(a - 1))\n}\n\n"}], "negative_code": [], "src_uid": "142b06ed43b3473513995de995e19fc3"} {"nl": {"description": "Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li, Ri] with the same probability. Determine the expected value that the winner will have to pay in a second-price auction.", "input_spec": "The first line of input contains an integer number n (2 ≤ n ≤ 5). n lines follow, the i-th of them containing two numbers Li and Ri (1 ≤ Li ≤ Ri ≤ 10000) describing the i-th company's bid preferences. This problem doesn't have subproblems. You will get 8 points for the correct submission.", "output_spec": "Output the answer with absolute or relative error no more than 1e - 9.", "sample_inputs": ["3\n4 7\n8 10\n5 5", "3\n2 5\n3 4\n1 6"], "sample_outputs": ["5.7500000000", "3.5000000000"], "notes": "NoteConsider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5·5 + 0.25·6 + 0.25·7 = 5.75."}, "positive_code": [{"source_code": "import java.util.StringTokenizer\n\nobject _513C extends App {\n var token = new StringTokenizer(\"\")\n def next = {\n while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)\n token.nextToken()\n }\n\n val n = next.toInt\n val l = Array.fill(n)(0)\n val r = Array.fill(n)(0)\n for (i <- 0 until n) {\n l(i) = next.toInt\n r(i) = next.toInt\n }\n val mask = (1 to n).toArray\n val denominator = (l zip r).map(p => 1.0 * (p._2 - p._1 + 1)).reduce(_ * _)\n\n def calc(l: Int, r: Int, ll: Int, rr: Int): Double = {\n val lll = l max ll\n val rrr = r min rr\n if (lll <= rrr) rrr - lll + 1 else 0\n }\n\n var second = 1\n var numerator = 0.0\n def dfs(t: Int) {\n if (t >= n) {\n val sorted = mask.sorted\n if (sorted(n - 2) == 0) {\n var tmp = 1.0\n for (i <- 0 until n) {\n if (mask(i) == 1) tmp *= calc(l(i), r(i), second + 1, Int.MaxValue)\n else if (mask(i) == 0) tmp *= calc(l(i), r(i), second, second)\n else tmp *= calc(l(i), r(i), 0, second - 1)\n }\n numerator += second * tmp\n }\n } else {\n for (i <- -1 to 1) {\n mask(t) = i; dfs(t + 1)\n }\n }\n }\n while (second <= 10000) {\n dfs(0)\n second += 1\n }\n println(\"%.10f\".format(numerator / denominator))\n}\n"}, {"source_code": "import scala.collection._\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) = readInts(1)\n var ls, rs = Array.ofDim[Int](n)\n\n for (i <- 0 until n) {\n val Array(l, r) = readInts(2)\n ls(i) = l\n rs(i) = r\n }\n\n var ev1, ev2 = 0d\n\n def probWin(x: Int, l: Int, r: Int): Double = {\n if (x < l) 0d\n else if (x > r) 1d\n else (x - l + 0d) / (r - l + 1d)\n }\n\n def probLose(x: Int, l: Int, r: Int): Double = {\n if (x < l) 1d\n else if (x > r) 0d\n else (r - x + 0d) / (r - l + 1d)\n }\n\n def probEq(x: Int, l: Int, r: Int): Double = {\n if (x < l) 0d\n else if (x > r) 0d\n else 1d / (r - l + 1d)\n }\n\n val maxMask = (1 << (n - 2)) - 1\n\n for (p1 <- 0 until n) {\n for (p2 <- 0 until n) if (p2 != p1) {\n var sumProb1 = 0d\n var sumProb2 = 0d\n for (x2 <- ls(p2) to rs(p2)) {\n for (mask <- 0 to maxMask) {\n var prob = 1d\n var i = 1\n var eqCnt = 2\n for (px <- 0 until n) if (px != p2 && px != p1) {\n if ((mask & i) == 0) prob *= probWin(x2, ls(px), rs(px))\n else {\n prob *= probEq(x2, ls(px), rs(px))\n eqCnt += 1\n }\n i *= 2\n }\n // println(p1, p2, x2, mask, prob, probLose(x2, ls(p1), rs(p1)), probEq(x2, ls(p1), rs(p1)))\n sumProb1 += x2 * prob * probLose(x2, ls(p1), rs(p1)) / (eqCnt - 1d)\n sumProb2 += x2 * prob * probEq(x2, ls(p1), rs(p1)) / (eqCnt - 1d) / eqCnt\n //sumProb2 += x2 * 0.5d * prob * probEq(x2, ls(p1), rs(p1))\n }\n }\n ev1 += sumProb1 / (rs(p2) - ls(p2) + 1d)\n ev2 += sumProb2 / (rs(p2) - ls(p2) + 1d)\n }\n }\n //println(ev1, ev2)\n println(ev1 + ev2)\n}\n"}, {"source_code": "import java.util.Scanner\nimport java.io.FileInputStream\n\nobject DoubleSolution {\n\n def main(args: Array[String]) {\n val sc = new Scanner(if (args.length > 0) new FileInputStream(args(0)) else System.in)\n val n = sc.nextInt\n val arr = Array.tabulate(n)(_ => (sc.nextInt(), sc.nextInt()))\n //val start = System.nanoTime()\n println(new DoubleAuction(n, arr).expectationOfSecond())\n //val end = System.nanoTime()\n //println(\"Time = \" + (end - start) / 1000000L)\n }\n}\n\nclass DoubleAuction(n: Int, r: Array[(Int, Int)]) {\n def low(i: Int): Int = r(i)._1\n def hi(i: Int): Int = r(i)._2\n def length(i: Int): Int = r(i)._2 - r(i)._1 + 1\n\n val ZERO = BigInt(0)\n val ONE = BigInt(0)\n def gcd(a: BigInt, b: BigInt): BigInt = if (b == ZERO) a else gcd(b, a % b)\n\n def simplify(a: BigInt, b: BigInt): (BigInt, BigInt) = {\n val g = gcd(a, b)\n if (g == ONE) (a, b) else (a / g, b / g)\n }\n\n def expectationOfSecond(): Double = {\n val secondFrom = (0 until n).map(low).sortWith(_ > _)(1)\n val secondTo = (0 until n).map(hi).sortWith(_ > _)(1)\n var value = 0.0\n var second = secondFrom\n while (second<=secondTo) {\n var si = 0\n while (si < n) {\n if (low(si) <= second && second <= hi(si)) {\n var fi = 0\n while (fi (if (i < si) second else second - 1)) {\n a0 *= ((if (i < si) second else second - 1) - low(i) + 1)\n a0 /= length(i)\n }\n i += 1\n }\n value = value + a0\n }\n }\n fi += 1\n }\n }\n si += 1\n }\n second += 1\n }\n value\n }\n}\n"}, {"source_code": "import java.util.Scanner\nimport java.io.FileInputStream\n\nobject DoubleSolution {\n\n def main(args: Array[String]) {\n val sc = new Scanner(if (args.length > 0) new FileInputStream(args(0)) else System.in)\n val n = sc.nextInt\n val arr = Array.tabulate(n)(_ => (sc.nextInt(), sc.nextInt()))\n println(new DoubleAuction(n, arr).expectationOfSecond())\n }\n}\n\nclass DoubleAuction(n: Int, r: Array[(Int, Int)]) {\n def low(i: Int): Int = r(i)._1\n def hi(i: Int): Int = r(i)._2\n def length(i: Int): Int = r(i)._2 - r(i)._1 + 1\n\n val ZERO = BigInt(0)\n val ONE = BigInt(0)\n def gcd(a: BigInt, b: BigInt): BigInt = if (b == ZERO) a else gcd(b, a % b)\n\n def simplify(a: BigInt, b: BigInt): (BigInt, BigInt) = {\n val g = gcd(a, b)\n if (g == ONE) (a, b) else (a / g, b / g)\n }\n\n def expectationOfSecond(): Double = {\n val secondFrom = (0 until n).map(low).sortWith(_ > _)(1)\n val secondTo = (0 until n).map(hi).sortWith(_ > _)(1)\n //val summands =\n (for {\n second <- secondFrom to secondTo\n si <- 0 until n if low(si) <= second && second <= hi(si)\n fi <- 0 until n if fi != si && (if (fi < si) second + 1 else second) <= hi(fi)\n if (0 until n).filter(i => i != si && i != fi).forall(i => low(i) <= (if (i < si) second + 1 else second))\n\n } yield {\n val a0: Double = second * (hi(fi) - math.max(if (fi < si) second + 1 else second, low(fi)) + 1) / length(si).toDouble / length(fi)\n (0 until n).filter(i => i != si && i != fi && hi(i) > (if (i < si) second else second - 1)).\n foldLeft(a0) ((p, i) => p * ((if (i < si) second else second - 1) - low(i) + 1) / length(i))\n }).sum\n }\n}"}, {"source_code": "import java.io.FileInputStream\nimport java.util.Scanner\nimport scala.collection.mutable\n\nobject Solution {\n def main(args: Array[String]) {\n val sc = new Scanner(if (args.length > 0) new FileInputStream(args(0)) else System.in)\n val n = sc.nextInt\n\n val arr = Array.tabulate(n)(_ => (sc.nextInt(), sc.nextInt()))\n //val start = System.nanoTime()\n println(new Auction(n, arr).expectationOfSecond())\n //val end = System.nanoTime()\n //println(\"Time = \" + (end - start) / 1000000L)\n }\n}\n\nclass Auction(n: Int, r: Array[(Int, Int)]) {\n def low(i: Int): Int = r(i)._1\n def hi(i: Int): Int = r(i)._2\n def length(i: Int): Int = r(i)._2 - r(i)._1 + 1\n\n val ZERO = BigInt(0)\n val ONE = BigInt(0)\n def gcd(a: BigInt, b: BigInt): BigInt = if (b == ZERO) a else gcd(b, a % b)\n\n def simplify(a: BigInt, b: BigInt): (BigInt, BigInt) = {\n val g = gcd(a, b)\n if (g == ONE) (a, b) else (a / g, b / g)\n }\n\n def expectationOfSecond(): Double = {\n val secondFrom = (0 until n).map(low).sortWith(_ > _)(1)\n val secondTo = (0 until n).map(hi).sortWith(_ > _)(1)\n val map = new mutable.OpenHashMap[BigInt, BigInt](200000)\n //val summands =\n for {\n second <- secondFrom to secondTo\n si <- 0 until n if low(si) <= second && second <= hi(si)\n fi <- 0 until n if fi != si && (if (fi < si) second + 1 else second) <= hi(fi)\n if (0 until n).filter(i => i != si && i != fi).forall(i => low(i) <= (if (i < si) second + 1 else second))\n } {\n val a0: BigInt = second * (hi(fi) - math.max(if (fi < si) second + 1 else second, low(fi)) + 1)\n val b0: BigInt = length(si) * length(fi)\n val is = (0 until n).filter(i => i != si && i != fi && hi(i) > (if (i < si) second else second - 1))\n val a = is.map(i => (if (i < si) second else second - 1) - low(i) + 1).foldLeft(a0)(_ * _)\n val b = is.map(i => length(i)).foldLeft(b0)(_ * _)\n val x = simplify(a, b)\n map += (x._2 -> (map.getOrElse(x._2, ZERO) + x._1))\n }\n val grouped = map.toIterator.map(p => simplify(p._2, p._1))\n// val grouped = summands.foldLeft(Map[BigInt, BigInt]())((m, x) => m + (x._2 -> (m.getOrElse(x._2, ZERO) + x._1))).\n// toList.map(p => simplify(p._2, p._1))\n\n //println( summands.foldLeft(Map[BigInt, BigInt]()) ( (m, x) => m + (x._2 -> (m.getOrElse(x._2, ZERO) + x._1)) ) )\n\n //val grouped = summands.groupBy(_._2).mapValues(_.map(_._1).sum).toList.map(p=>simplify(p._2,p._1))\n //val grouped = summands.agroupBy(_._2).map(p => (p._1,p._2.map(_._1).sum)).map(p=>simplify(p._2,p._1))\n grouped.map(p => BigDecimal(p._1) / BigDecimal(p._2)).sum.toDouble\n }\n}\n"}], "negative_code": [{"source_code": "import java.util.StringTokenizer\n\nobject _513C extends App {\n var token = new StringTokenizer(\"\")\n def next = {\n while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)\n token.nextToken()\n }\n\n val n = next.toInt\n val l = Array.fill(n)(0)\n val r = Array.fill(n)(0)\n for (i <- 0 until n) {\n l(i) = next.toInt\n r(i) = next.toInt\n }\n val mask = (1 to n).toArray\n val denominator = (l zip r).map(p => 1.0 * (p._2 - p._1 + 1)).reduce(_ * _)\n\n def calc(l: Int, r: Int, ll: Int, rr: Int): Double = {\n val lll = l max ll\n val rrr = r min rr\n if (lll <= rrr) rrr - lll + 1 else 0\n }\n\n val numerators = for (second <- 1 to 50) yield {\n def dfs(t: Int): Double =\n if (t >= n) {\n val sorted = mask.sorted\n if (sorted(n - 2) == 0) {\n val cand = for (i <- 0 until n) yield {\n if (mask(i) == 1) calc(l(i), r(i), second + 1, Int.MaxValue)\n else if (mask(i) == 0) calc(l(i), r(i), second, second)\n else calc(l(i), r(i), 0, second - 1)\n }\n cand.reduce(_ * _) * second\n } else 0\n } else {\n val hehe = for (i <- -1 to 1) yield { mask(t) = i; dfs(t + 1) }\n hehe.sum\n }\n dfs(0)\n }\n val numerator = numerators.sum\n println(\"%.10f\".format(numerator / denominator))\n}\n"}, {"source_code": "import scala.collection._\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) = readInts(1)\n var ls, rs = Array.ofDim[Int](n)\n\n for (i <- 0 until n) {\n val Array(l, r) = readInts(2)\n ls(i) = l\n rs(i) = r\n }\n\n var ev1, ev2 = 0d\n\n def probWin(x: Int, l: Int, r: Int): Double = {\n if (x < l) 0d\n else if (x > r) 1d\n else (x - l + 0d) / (r - l + 1d)\n }\n\n def probLose(x: Int, l: Int, r: Int): Double = {\n if (x < l) 1d\n else if (x > r) 0d\n else (r - x + 0d) / (r - l + 1d)\n }\n\n def probEq(x: Int, l: Int, r: Int): Double = {\n if (x < l) 0d\n else if (x > r) 0d\n else 1d / (r - l + 1d)\n }\n\n val maxMask = (1 << (n - 2)) - 1\n\n for (p1 <- 0 until n) {\n for (p2 <- 0 until n) if (p2 != p1) {\n var sumProb1 = 0d\n var sumProb2 = 0d\n for (x2 <- ls(p2) to rs(p2)) {\n for (mask <- 0 to maxMask) {\n var prob = 1d\n var i = 1\n var eqCnt = 2\n for (px <- 0 until n) if (px != p2 && px != p1) {\n if ((mask & i) == 0) prob *= probWin(x2, ls(px), rs(px))\n else {\n prob *= probEq(x2, ls(px), rs(px))\n eqCnt += 1\n }\n i *= 2\n }\n // println(p1, p2, x2, mask, prob, probLose(x2, ls(p1), rs(p1)), probEq(x2, ls(p1), rs(p1)))\n sumProb1 += x2 * prob * probLose(x2, ls(p1), rs(p1)) / (eqCnt - 1d)\n sumProb2 += x2 * prob * probEq(x2, ls(p1), rs(p1)) / (eqCnt - 1d) / eqCnt\n //sumProb2 += x2 * 0.5d * prob * probEq(x2, ls(p1), rs(p1))\n }\n }\n ev1 += sumProb1 / (rs(p2) - ls(p2) + 1d)\n ev2 += sumProb2 / (rs(p2) - ls(p2) + 1d)\n }\n }\n println(ev1, ev2)\n println(ev1 + ev2)\n}\n"}, {"source_code": "import java.util.Scanner\nimport java.io.FileInputStream\n\nobject DoubleSolution {\n\n def main(args: Array[String]) {\n val sc = new Scanner(if (args.length > 0) new FileInputStream(args(0)) else System.in)\n val n = sc.nextInt\n val arr = Array.tabulate(n)(_ => (sc.nextInt(), sc.nextInt()))\n println(new DoubleAuction(n, arr).expectationOfSecond())\n }\n}\n\nclass DoubleAuction(n: Int, r: Array[(Int, Int)]) {\n def low(i: Int): Int = r(i)._1\n def hi(i: Int): Int = r(i)._2\n def length(i: Int): Int = r(i)._2 - r(i)._1 + 1\n\n val ZERO = BigInt(0)\n val ONE = BigInt(0)\n def gcd(a: BigInt, b: BigInt): BigInt = if (b == ZERO) a else gcd(b, a % b)\n\n def simplify(a: BigInt, b: BigInt): (BigInt, BigInt) = {\n val g = gcd(a, b)\n if (g == ONE) (a, b) else (a / g, b / g)\n }\n\n def expectationOfSecond(): Double = {\n val secondFrom = (0 until n).map(low).sortWith(_ > _)(1)\n val secondTo = (0 until n).map(hi).sortWith(_ > _)(1)\n var value = 0.0\n var second = secondFrom\n while (second<=secondTo) {\n var si = 0\n while (si < n) {\n if (low(si) <= second && second <= hi(si)) {\n var fi = 0\n while (fi < n) {\n if (fi != si && (if (fi < si) second + 1 else second) <= hi(fi)) {\n var v = second * (hi(fi) - math.max(if (fi < si) second + 1 else second, low(fi)) + 1) / length(si).toDouble / length(fi)\n var i = 0\n while (i < n) {\n if (i != si && i != fi && hi(i) > (if (i < si) second else second - 1)) {\n v *= ((if (i < si) second else second - 1) - low(i) + 1) / length(i).toDouble\n }\n i += 1\n }\n value += v\n }\n fi += 1\n }\n }\n si += 1\n }\n second += 1\n }\n value\n }\n}\n"}, {"source_code": "import Fraction._\nimport java.io.FileInputStream\nimport java.util.Scanner\n\nobject Solution {\n def main(args: Array[String]) {\n // assert(new Auction(3, Array((4, 7), (8, 10), (5, 5))).expectationOfSecond().toDouble == 5.75)\n // assert(new Auction(3, Array((2,5), (3,4), (1,6))).expectationOfSecond().toDouble == 3.5)\n val sc = new Scanner(if (args.length > 0) new FileInputStream(args(0)) else System.in)\n val n = sc.nextInt\n val arr = Array.tabulate(n)(_ => (sc.nextInt(), sc.nextInt()))\n val expectation = new Auction(3, arr).expectationOfSecond().toDouble\n println(expectation)\n }\n}\n\nclass Fraction(val a:Long, val b:Long) {\n def toDouble: Double = if (a == 0) 0.0 else a.toDouble / b\n\n def *(that: Fraction): Fraction = mul(this, that)\n\n override def toString: String =\n if (a == 0) \"0\"\n else if (b == 1) a.toString\n else a + \"/\" + b\n}\n\nobject Fraction {\n val ZERO = new Fraction(0L, 1L)\n val ONE = new Fraction(1L, 1L)\n def gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\n def fract(a: Long, b: Long): Fraction =\n if (a == 0L) ZERO\n else if (a == b) ONE\n else {\n val d = gcd(a, b)\n new Fraction(a / d, b / d)\n }\n\n def mul(x: Fraction, y: Fraction): Fraction =\n if (x == ZERO || y == ZERO) ZERO\n else if (x == ONE) y\n else if (y == ONE) x\n else fract(x.a * y.a, x.b * y.b)\n\n def mul(x: Long, y: Fraction): Fraction =\n if (x == 0 || y == ZERO) ZERO\n else if (x == 1) y\n else if (y == ONE) new Fraction(x, 1L)\n else fract(x * y.a, y.b)\n\n def sum(x: Fraction, y: Fraction): Fraction =\n if (x == ZERO) y\n else if (y == ZERO) x\n else if (x.b == y.b) fract(x.a + y.a, x.b)\n else fract(x.a * y.b + y.a * x.b, x.b * y.b)\n}\n\nclass Auction(n: Int, r: Array[(Int, Int)]) {\n @inline def low(i: Int): Int = r(i)._1\n @inline def hi(i: Int): Int = r(i)._2\n @inline def length(i: Int): Int = r(i)._2 - r(i)._1 + 1\n\n def pFirst(firstFrom: Int, excluded: Int): Fraction = {\n @inline def from(i: Int) = if (i < excluded) firstFrom + 1 else firstFrom\n @inline def till(i: Int) = if (i < excluded) firstFrom else firstFrom - 1\n val fs = (0 until n).filter(i => i != excluded && from(i) <= hi(i))\n if (fs.isEmpty) ZERO\n else\n fs.map(f =>\n (0 until n).filter(i => i != excluded && i != f).\n map(i => if (hi(i) <= till(i)) ONE\n else if (till(i) < low(i)) ZERO\n else fract(till(i) - low(i) + 1, length(i))).\n foldLeft(fract(hi(f) - math.max(from(f), low(f)) + 1, length(f)))(mul)\n ).reduce(sum)\n }\n\n def expectationOfSecond(): Fraction = {\n val secondFrom = (0 until n).map(low).sortWith(_ > _)(1)\n val secondTo = (0 until n).map(hi).sortWith(_ > _)(1)\n (for {\n second <- secondFrom to secondTo\n i <- 0 until n if low(i) <= second && second <= hi(i)\n } yield fract(second, length(i)) * pFirst(second, i)) reduce sum\n }\n\n}\n\n"}, {"source_code": "import java.io.FileInputStream\nimport java.util.Scanner\n\nobject Solution {\n def main(args: Array[String]) {\n val sc = new Scanner(if (args.length > 0) new FileInputStream(args(0)) else System.in)\n val n = sc.nextInt\n val arr = Array.tabulate(n)(_ => (sc.nextInt(), sc.nextInt()))\n println(new Auction(n, arr).expectationOfSecond())\n }\n}\nclass Auction(n: Int, r: Array[(Int, Int)]) {\n def low(i: Int): Int = r(i)._1\n def hi(i: Int): Int = r(i)._2\n def length(i: Int): Int = r(i)._2 - r(i)._1 + 1\n\n val ZERO = BigInt(0)\n val ONE = BigInt(0)\n def gcd(a: BigInt, b: BigInt): BigInt = if (b == ZERO) a else gcd(b, a % b)\n\n def simplify(a: BigInt, b: BigInt): (BigInt, BigInt) = {\n val g = gcd(a, b)\n if (g == ONE) (a, b) else (a / g, b / g)\n }\n\n def expectationOfSecond(): Double = {\n val secondFrom = (0 until n).map(low).sortWith(_ > _)(1)\n val secondTo = (0 until n).map(hi).sortWith(_ > _)(1)\n val summands =\n for {\n second <- secondFrom to secondTo\n si <- 0 until n if low(si) <= second && second <= hi(si)\n fi <- 0 until n if fi != si && (if (fi < si) second + 1 else second) <= hi(fi)\n if (0 until n).filter(i => i != si && i != fi).forall(i => low(i) <= (if (i < si) second + 1 else second))\n } yield {\n val a0: BigInt = second * (hi(fi) - math.max(if (fi < si) second + 1 else second, low(fi)) + 1)\n val b0: BigInt = length(si) * length(fi)\n val is = (0 until n).filter(i => i != si && i != fi && hi(i) > (if (i < si) second else second - 1))\n val a = is.map(i => (if (i < si) second else second - 1) - low(i) + 1).foldLeft(a0)(_ * _)\n val b = is.map(i => length(i)).foldLeft(b0)(_ * _)\n simplify(a, b)\n }\n //val optimized = summands\n val grouped = summands.groupBy(_._2).mapValues(_.map(_._1).sum).map(p => simplify(p._2, p._1))\n grouped.map(p => BigDecimal(p._1) / BigDecimal(p._2)).sum.toDouble\n }\n}\n"}, {"source_code": "import Fraction._\nimport java.io.FileInputStream\nimport java.util.Scanner\n\nobject Solution {\n def main(args: Array[String]) {\n val sc = new Scanner(if (args.length > 0) new FileInputStream(args(0)) else System.in)\n val n = sc.nextInt\n val arr = Array.tabulate(n)(_ => (sc.nextInt(), sc.nextInt()))\n val expectation = new Auction(n, arr).expectationOfSecond().toDouble\n println(expectation)\n }\n}\n\nclass Fraction(val a:Long, val b:Long) {\n def toDouble: Double = if (a == 0) 0.0 else a.toDouble / b\n\n def *(that: Fraction): Fraction = mul(this, that)\n\n override def toString: String =\n if (a == 0) \"0\"\n else if (b == 1) a.toString\n else a + \"/\" + b\n}\n\nobject Fraction {\n val ZERO = new Fraction(0L, 1L)\n val ONE = new Fraction(1L, 1L)\n def gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\n def fract(a: Long, b: Long): Fraction =\n if (a == 0L) ZERO\n else if (a == b) ONE\n else {\n val d = gcd(a, b)\n new Fraction(a / d, b / d)\n }\n\n def mul(x: Fraction, y: Fraction): Fraction =\n if (x == ZERO || y == ZERO) ZERO\n else if (x == ONE) y\n else if (y == ONE) x\n else fract(x.a * y.a, x.b * y.b)\n\n def mul(x: Long, y: Fraction): Fraction =\n if (x == 0 || y == ZERO) ZERO\n else if (x == 1) y\n else if (y == ONE) new Fraction(x, 1L)\n else fract(x * y.a, y.b)\n\n def sum(x: Fraction, y: Fraction): Fraction =\n if (x == ZERO) y\n else if (y == ZERO) x\n else if (x.b == y.b) fract(x.a + y.a, x.b)\n else fract(x.a * y.b + y.a * x.b, x.b * y.b)\n}\n\nclass Auction(n: Int, r: Array[(Int, Int)]) {\n @inline def low(i: Int): Int = r(i)._1\n @inline def hi(i: Int): Int = r(i)._2\n @inline def length(i: Int): Int = r(i)._2 - r(i)._1 + 1\n\n def pFirst(firstFrom: Int, excluded: Int): Fraction = {\n @inline def from(i: Int) = if (i < excluded) firstFrom + 1 else firstFrom\n @inline def till(i: Int) = if (i < excluded) firstFrom else firstFrom - 1\n val fs = (0 until n).filter(i => i != excluded && from(i) <= hi(i))\n if (fs.isEmpty) ZERO\n else\n fs.map(f =>\n (0 until n).filter(i => i != excluded && i != f).\n map(i => if (hi(i) <= till(i)) ONE\n else if (till(i) < low(i)) ZERO\n else fract(till(i) - low(i) + 1, length(i))).\n foldLeft(fract(hi(f) - math.max(from(f), low(f)) + 1, length(f)))(mul)\n ).reduce(sum)\n }\n\n def expectationOfSecond(): Fraction = {\n val secondFrom = (0 until n).map(low).sortWith(_ > _)(1)\n val secondTo = (0 until n).map(hi).sortWith(_ > _)(1)\n (for {\n second <- secondFrom to secondTo\n i <- 0 until n if low(i) <= second && second <= hi(i)\n } yield fract(second, length(i)) * pFirst(second, i)) reduce sum\n }\n\n}\n\n"}, {"source_code": "import Fraction._\nimport java.io.FileInputStream\nimport java.util.Scanner\n\nobject Solution {\n def main(args: Array[String]) {\n // assert(new Auction(3, Array((4, 7), (8, 10), (5, 5))).expectationOfSecond().toDouble == 5.75)\n // assert(new Auction(3, Array((2,5), (3,4), (1,6))).expectationOfSecond().toDouble == 3.5)\n val sc = new Scanner(if (args.length > 0) new FileInputStream(args(0)) else System.in)\n val n = sc.nextInt\n val arr = Array.tabulate(n)(_ => (sc.nextInt(), sc.nextInt()))\n val start = System.nanoTime()\n val expectation = new Auction(n, arr).expectationOfSecond().toDouble\n val end = System.nanoTime()\n println(expectation)\n println(\"Time = \" + (end - start) / 1000000L)\n }\n}\n\nclass Fraction(val a:Long, val b:Long) {\n def toDouble: Double = if (a == 0) 0.0 else a.toDouble / b\n\n def *(that: Fraction): Fraction = mul(this, that)\n\n override def toString: String =\n if (a == 0) \"0\"\n else if (b == 1) a.toString\n else a + \"/\" + b\n}\n\nobject Fraction {\n val ZERO = new Fraction(0L, 1L)\n val ONE = new Fraction(1L, 1L)\n def gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\n def fract(a: Long, b: Long): Fraction =\n if (a == 0L) ZERO\n else if (a == b) ONE\n else {\n val d = gcd(a, b)\n new Fraction(a / d, b / d)\n }\n\n// def mul(x: Fraction, y: Fraction): Fraction =\n// if (x == ZERO || y == ZERO) ZERO\n// else if (x == ONE) y\n// else if (y == ONE) x\n// else {\n// val gcd1 = gcd(x.a, y.b)\n// val gcd2 = gcd(x.b, y.a)\n// fract((x.a / gcd1) * (y.a / gcd2), (x.b / gcd2) * (y.b / gcd1))\n// if (x.a * y.a < x.a || x.a * y.a < y.a) println(x.a, y.a, x.a * y.a)\n// fract( x.a * y.a, x.b * y.b)\n// }\n\n def mul(x: Fraction, y: Fraction): Fraction = mulUnsafe(reduce(x), reduce(y))\n def mulUnsafe(x: Fraction, y: Fraction): Fraction =\n if (x == ZERO || y == ZERO) ZERO\n else if (x == ONE) y\n else if (y == ONE) x\n else {\n val gcd1 = gcd(x.a, y.b)\n val gcd2 = gcd(x.b, y.a)\n fract((x.a / gcd1) * (y.a / gcd2), (x.b / gcd2) * (y.b / gcd1))\n if (x.a * y.a < x.a || x.a * y.a < y.a) println(x.a, y.a, x.a * y.a)\n fract( x.a * y.a, x.b * y.b)\n }\n\n\n def mul(x: Long, y: Fraction): Fraction =\n if (x == 0 || y == ZERO) ZERO\n else if (x == 1) y\n else if (y == ONE) new Fraction(x, 1L)\n else fract(x * y.a, y.b)\n\n// def sum(x: Fraction, y: Fraction): Fraction =\n// if (x == ZERO) y\n// else if (y == ZERO) x\n// else if (x.b == y.b) fract(x.a + y.a, x.b)\n// else {\n// val g = gcd(x.b, y.b)\n// if (g == 1) fract(x.a * y.b + y.a * x.b, x.b * y.b)\n// else fract(x.a * (y.b / g) + y.a * (x.b / g), x.b / g * y.b)\n// }\n\n def sumUnsafe(x: Fraction, y: Fraction): Fraction =\n if (x == ZERO) y\n else if (y == ZERO) x\n else if (x.b == y.b) fract(x.a + y.a, x.b)\n else {\n val g = gcd(x.b, y.b)\n if (g == 1) fract(x.a * y.b + y.a * x.b, x.b * y.b)\n else fract(x.a * (y.b / g) + y.a * (x.b / g), x.b / g * y.b)\n }\n\n def sum(x: Fraction, y: Fraction): Fraction = sumUnsafe(reduce(x),reduce(y))\n\n val MAX: Long = Integer.MAX_VALUE\n def reduce(x: Fraction): Fraction =\n if (x.a < MAX && x.b < MAX) x\n else {\n var a = x.a\n var b = x.b\n while (a > MAX || b > MAX) {\n a >>= 1\n b >>= 1\n }\n fract(a, b)\n }\n}\n\n//class BigFraction(val a:BigInt, val b:BigInt) {\n//\n//}\n//\n//object BigFraction {\n// def sum(x: BigFraction, y: Fraction): BigFraction = {\n//\n// }\n//}\n\nclass Auction(n: Int, r: Array[(Int, Int)]) {\n @inline def low(i: Int): Int = r(i)._1\n @inline def hi(i: Int): Int = r(i)._2\n @inline def length(i: Int): Int = r(i)._2 - r(i)._1 + 1\n\n def pFirst(firstFrom: Int, excluded: Int): Fraction = {\n @inline def from(i: Int) = if (i < excluded) firstFrom + 1 else firstFrom\n @inline def till(i: Int) = if (i < excluded) firstFrom else firstFrom - 1\n val fs = (0 until n).filter(i => i != excluded && from(i) <= hi(i))\n if (fs.isEmpty) ZERO\n else\n fs.map(f =>\n (0 until n).filter(i => i != excluded && i != f).\n map(i => if (hi(i) <= till(i)) ONE\n else if (till(i) < low(i)) ZERO\n else fract(till(i) - low(i) + 1, length(i))).\n foldLeft(fract(hi(f) - math.max(from(f), low(f)) + 1, length(f)))(mul)\n ).reduce(sum)\n }\n\n def expectationOfSecond(): Fraction = {\n val secondFrom = (0 until n).map(low).sortWith(_ > _)(1)\n val secondTo = (0 until n).map(hi).sortWith(_ > _)(1)\n val summands =\n for {\n second <- secondFrom to secondTo\n i <- 0 until n if low(i) <= second && second <= hi(i)\n } yield fract(second, length(i)) * pFirst(second, i)\n val optimized = summands.groupBy(_.b).mapValues(_.map(_.a).sum).map(p => fract(p._2, p._1))\n optimized.reduce(sum)\n }\n\n}\n"}, {"source_code": "import Fraction._\nimport java.io.FileInputStream\nimport java.util.Scanner\n\nobject Solution {\n def main(args: Array[String]) {\n // assert(new Auction(3, Array((4, 7), (8, 10), (5, 5))).expectationOfSecond().toDouble == 5.75)\n // assert(new Auction(3, Array((2,5), (3,4), (1,6))).expectationOfSecond().toDouble == 3.5)\n val sc = new Scanner(if (args.length > 0) new FileInputStream(args(0)) else System.in)\n val n = sc.nextInt\n val arr = Array.tabulate(n)(_ => (sc.nextInt(), sc.nextInt()))\n// val start = System.nanoTime()\n val expectation = new Auction(n, arr).expectationOfSecond().toDouble\n// val end = System.nanoTime()\n println(expectation)\n// println(\"Time = \" + (end - start) / 1000000L)\n }\n}\n\nclass Fraction(val a:Long, val b:Long) {\n def toDouble: Double = if (a == 0) 0.0 else a.toDouble / b\n\n def *(that: Fraction): Fraction = mul(this, that)\n\n override def toString: String =\n if (a == 0) \"0\"\n else if (b == 1) a.toString\n else a + \"/\" + b\n}\n\nobject Fraction {\n val ZERO = new Fraction(0L, 1L)\n val ONE = new Fraction(1L, 1L)\n def gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\n def fract(a: Long, b: Long): Fraction =\n if (a == 0L) ZERO\n else if (a == b) ONE\n else {\n val d = gcd(a, b)\n new Fraction(a / d, b / d)\n }\n\n// def mul(x: Fraction, y: Fraction): Fraction =\n// if (x == ZERO || y == ZERO) ZERO\n// else if (x == ONE) y\n// else if (y == ONE) x\n// else {\n// val gcd1 = gcd(x.a, y.b)\n// val gcd2 = gcd(x.b, y.a)\n// fract((x.a / gcd1) * (y.a / gcd2), (x.b / gcd2) * (y.b / gcd1))\n// if (x.a * y.a < x.a || x.a * y.a < y.a) println(x.a, y.a, x.a * y.a)\n// fract( x.a * y.a, x.b * y.b)\n// }\n\n def mul(x: Fraction, y: Fraction): Fraction = mulUnsafe(reduce(x), reduce(y))\n def mulUnsafe(x: Fraction, y: Fraction): Fraction =\n if (x == ZERO || y == ZERO) ZERO\n else if (x == ONE) y\n else if (y == ONE) x\n else {\n //val gcd1 = gcd(x.a, y.b)\n //val gcd2 = gcd(x.b, y.a)\n // fract((x.a / gcd1) * (y.a / gcd2), (x.b / gcd2) * (y.b / gcd1))\n // if (x.a * y.a < x.a || x.a * y.a < y.a) println(x.a, y.a, x.a * y.a)\n fract( x.a * y.a, x.b * y.b)\n }\n\n\n def mul(x: Long, y: Fraction): Fraction =\n if (x == 0 || y == ZERO) ZERO\n else if (x == 1) y\n else if (y == ONE) new Fraction(x, 1L)\n else fract(x * y.a, y.b)\n\n// def sum(x: Fraction, y: Fraction): Fraction =\n// if (x == ZERO) y\n// else if (y == ZERO) x\n// else if (x.b == y.b) fract(x.a + y.a, x.b)\n// else {\n// val g = gcd(x.b, y.b)\n// if (g == 1) fract(x.a * y.b + y.a * x.b, x.b * y.b)\n// else fract(x.a * (y.b / g) + y.a * (x.b / g), x.b / g * y.b)\n// }\n\n def sumUnsafe(x: Fraction, y: Fraction): Fraction =\n if (x == ZERO) y\n else if (y == ZERO) x\n else if (x.b == y.b) fract(x.a + y.a, x.b)\n else {\n val g = gcd(x.b, y.b)\n if (g == 1) fract(x.a * y.b + y.a * x.b, x.b * y.b)\n else fract(x.a * (y.b / g) + y.a * (x.b / g), x.b / g * y.b)\n }\n\n def sum(x: Fraction, y: Fraction): Fraction = sumUnsafe(reduce(x),reduce(y))\n\n val MAX: Long = Integer.MAX_VALUE\n def reduce(x: Fraction): Fraction =\n if (x.a < MAX && x.b < MAX) x\n else {\n var a = x.a\n var b = x.b\n while (a > MAX || b > MAX) {\n a >>= 1\n b >>= 1\n }\n fract(a, b)\n }\n}\n\n//class BigFraction(val a:BigInt, val b:BigInt) {\n//\n//}\n//\n//object BigFraction {\n// def sum(x: BigFraction, y: Fraction): BigFraction = {\n//\n// }\n//}\n\nclass Auction(n: Int, r: Array[(Int, Int)]) {\n @inline def low(i: Int): Int = r(i)._1\n @inline def hi(i: Int): Int = r(i)._2\n @inline def length(i: Int): Int = r(i)._2 - r(i)._1 + 1\n\n def pFirst(firstFrom: Int, excluded: Int): Fraction = {\n @inline def from(i: Int) = if (i < excluded) firstFrom + 1 else firstFrom\n @inline def till(i: Int) = if (i < excluded) firstFrom else firstFrom - 1\n val fs = (0 until n).filter(i => i != excluded && from(i) <= hi(i))\n if (fs.isEmpty) ZERO\n else\n fs.map(f =>\n (0 until n).filter(i => i != excluded && i != f).\n map(i => if (hi(i) <= till(i)) ONE\n else if (till(i) < low(i)) ZERO\n else fract(till(i) - low(i) + 1, length(i))).\n foldLeft(fract(hi(f) - math.max(from(f), low(f)) + 1, length(f)))(mul)\n ).reduce(sum)\n }\n\n def expectationOfSecond(): Fraction = {\n val secondFrom = (0 until n).map(low).sortWith(_ > _)(1)\n val secondTo = (0 until n).map(hi).sortWith(_ > _)(1)\n val summands =\n for {\n second <- secondFrom to secondTo\n i <- 0 until n if low(i) <= second && second <= hi(i)\n } yield fract(second, length(i)) * pFirst(second, i)\n val optimized = summands.groupBy(_.b).mapValues(_.map(_.a).sum).map(p => fract(p._2, p._1))\n optimized.reduce(sum)\n }\n\n}\n\n"}], "src_uid": "5258ce738eb268b9750cfef309d265ef"} {"nl": {"description": " Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one): After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.", "input_spec": "There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space. In the second strings, a single number n is given (0 ≤ n ≤ 109) – the duration of the rotation. It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.", "output_spec": "Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.", "sample_inputs": ["^ >\n1", "< ^\n3", "^ v\n6"], "sample_outputs": ["cw", "ccw", "undefined"], "notes": null}, "positive_code": [{"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 s = readLine\n val Array(n) = readInts(1)\n\n val dir = Map('v' -> 0, '<' -> 1, '^' -> 2, '>' -> 3)\n\n val rot = (dir(s(2)) - dir(s(0)) + 4) % 4\n\n val res = if (rot == 2 || rot == 0) \"undefined\" else\n if (n % 4 == rot) \"cw\"\n else \"ccw\"\n\n println(res)\n}\n"}], "negative_code": [], "src_uid": "fb99ef80fd21f98674fe85d80a2e5298"} {"nl": {"description": "Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown.", "input_spec": "The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture. ", "output_spec": "Print \"F\" (without quotes) if Uncle Fyodor wins. Print \"M\" if Matroskin wins and \"S\" if Sharic wins. If it is impossible to find the winner, print \"?\".", "sample_inputs": ["rock\nrock\nrock", "paper\nrock\nrock", "scissors\nrock\nrock", "scissors\npaper\nrock"], "sample_outputs": ["?", "F", "?", "?"], "notes": null}, "positive_code": [{"source_code": "object RockPaperScissors48A extends App {\n import java.io.{InputStream, PrintStream}\n import java.util.Scanner\n solve(System.in,System.out)\n\n trait Gesture {\n val user: String\n def against(gesture: Gesture): Gesture\n }\n case class Rock(user: String) extends Gesture {\n override def against(gesture: Gesture): Gesture = gesture match {\n case Rock(other) => if(other.equals(user)) this else Rock(\"?\")\n case s: Scissors => this\n case p: Paper => p\n }\n }\n case class Scissors(user: String) extends Gesture {\n override def against(gesture: Gesture): Gesture = gesture match {\n case r: Rock => r\n case Scissors(other) =>if(other.equals(user)) this else Scissors(\"?\")\n case p: Paper => this\n }\n }\n case class Paper(user: String) extends Gesture {\n override def against(gesture: Gesture): Gesture = gesture match {\n case r: Rock => this\n case s: Scissors => s\n case Paper(other) => if(other.equals(user)) this else Paper(\"?\")\n }\n }\n def build(s: String,user: String): Gesture = {\n s match {\n case \"rock\" => Rock(user)\n case \"paper\" => Paper(user)\n case _ => Scissors(user)\n }\n }\n def solve(in: InputStream, out: PrintStream): Unit = {\n val scanner = new Scanner(in)\n val a = build(scanner.next(),\"F\")\n val b = build(scanner.next(),\"M\")\n val c = build(scanner.next(),\"S\")\n val winner1 = a against b against c\n val winner2 = a against c against b\n if(winner1 == winner2)\n out.println(winner1.user)\n else\n out.println(\"?\")\n }\n}"}], "negative_code": [], "src_uid": "072c7d29a1b338609a72ab6b73988282"} {"nl": {"description": "The Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 × 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all).For example, if the first line of the board looks like that \"BBBBBBWW\" (the white cells of the line are marked with character \"W\", the black cells are marked with character \"B\"), then after one cyclic shift it will look like that \"WBBBBBBW\".Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard.", "input_spec": "The input consists of exactly eight lines. Each line contains exactly eight characters \"W\" or \"B\" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character \"W\" stands for the white color, character \"B\" stands for the black color. Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns — from 1 to 8 from left to right. The given board can initially be a proper chessboard.", "output_spec": "In a single line print \"YES\" (without the quotes), if we can make the board a proper chessboard and \"NO\" (without the quotes) otherwise.", "sample_inputs": ["WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB", "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th.In the second sample there is no way you can achieve the goal."}, "positive_code": [{"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val d = (1 to 8).map(_ => in.next())\n if (d.forall(t => t == \"WBWBWBWB\" || t == \"BWBWBWBW\"))\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "object Main{\n\n def different(a: String, b: String, pos: Int = 0): Boolean = {\n if (pos >= a.length) true else{\n if (a(pos) == b(pos)) false else different(a, b, pos+1)\n }\n } //> different: (a: String, b: String, pos: Int)Boolean\n \n def validPair(a: String, b: String, remainTry: Int = 0): Boolean = {\n if (remainTry == a.length) false else{\n if (different(a, b)) true else{\n val nextA = a.substring(1) + a(0)\n validPair(nextA, b, remainTry+1)\n }\n }\n } //> validPair: (a: String, b: String, remainTry: Int)Boolean\n \n def alterChar(s: String, pos: Int = 1): Boolean = {\n if (pos == s.length) true else{\n if (s(pos) == s(pos-1)) false else alterChar(s, pos+1)\n }\n } //> alterChar: (s: String, pos: Int)Boolean\n \n def validRow(s: String, remainTry: Int = 0): Boolean = {\n if (remainTry == s.length) false else{\n if (alterChar(s)) true else{\n val nextS = s.substring(1) + s(0)\n validRow(nextS, remainTry + 1)\n }\n }\n } //> validRow: (s: String, remainTry: Int)Boolean\n \n def validBoard(board: Array[String])={\n var ret = true\n if (!validRow(board(0))) ret = false\n for (i <- 1 until board.length){\n if (!validPair(board(i-1), board(i))) ret = false\n }\n ret\n } //> validBoard: (board: Array[String])Boolean\n\n def main(args: Array[String]) = {\n val board = new Array[String](8)\n for (i <- 0 until 8){\n board(i) = readLine()\n }\n if (validBoard(board)) println(\"YES\") else println(\"NO\")\n \n } //> main: (args: Array[String])Unit\n}"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P259A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val B = List.fill(8)(sc.nextLine)\n \n def solve(): String = if (B forall (s => s == \"WBWBWBWB\" || s == \"BWBWBWBW\")) \"YES\"\n else \"NO\"\n\n out.println(solve)\n out.close\n}\n"}, {"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 bw = \"(BW)*\"\n val wb = \"(WB)*\"\n val ans = (for(_ <- 1 to 8) yield reader.readLine()).forall(s => s.matches(bw) || s.matches(wb))\n val yesNoAns = Map(true -> \"YES\", false -> \"NO\")\n\n def main(a: Array[String]) {\n println(yesNoAns(ans))\n }\n}\n"}, {"source_code": "object Main {\n def correct(row: String): Boolean = {\n val sum = row.zipWithIndex.map{ t => \n if (t._1 == 'W') 1 << t._2\n else 0\n }.sum\n if (sum == 0x55 || sum == 0xAA) true\n else false\n }\n\n def main(args: Array[String]) {\n val cor = (1 to 8).map(_ => readLine()).map(correct(_)).foldLeft(true)(_ & _)\n if (cor) println(\"YES\")\n else println(\"NO\")\n }\n}"}, {"source_code": "object B{\n def main(args: Array[String]){\n\n val s1=\"WBWBWBWB\"\n val s2=\"BWBWBWBW\"\n (1 to 8).foreach{i=>\n val str=readLine\n if(str!=s1 && str!=s2){\n println(\"NO\")\n return\n }\n }\n println(\"YES\")\n }\n}"}, {"source_code": "object Ches {\n def main(args:Array[String]):Unit={\n var list=List[String]()\n for(i<-0 until 8){\n list=list:+readLine()\n }\n if(solve(list)) println(\"YES\")\n else println(\"NO\")\n }\n def solve(list:List[String]):Boolean={\n def isNormal(str:String):Boolean={\n def strIter(str:String, c:Char):Boolean={\n if(str.length==0) true\n else if(c==str.head) false\n else strIter(str.tail, str.head)\n }\n strIter(str, str.last)\n }\n if(list.length==0) true\n else if(!isNormal(list.head)) false\n else solve(list.tail)\n }\n}\n"}], "negative_code": [{"source_code": "object Main{\n\n def different(a: String, b: String, pos: Int = 0): Boolean = {\n if (pos >= a.length) true else{\n if (a(pos) == b(pos)) false else different(a, b, pos+1)\n }\n } //> different: (a: String, b: String, pos: Int)Boolean\n \n def validPair(a: String, b: String, remainTry: Int = 0): Boolean = {\n if (remainTry == a.length) false else{\n if (different(a, b)) true else{\n val nextA = a.substring(1) + a(0)\n validPair(nextA, b, remainTry+1)\n }\n }\n } //> validPair: (a: String, b: String, remainTry: Int)Boolean\n \n def validBoard(board: Array[String])={\n var ret = true\n for (i <- 1 until board.length){\n if (!validPair(board(i-1), board(i))) ret = false\n }\n ret\n } //> validBoard: (board: Array[String])Boolean\n\n def main(args: Array[String]) = {\n val board = new Array[String](8)\n for (i <- 0 until 8){\n board(i) = readLine()\n }\n if (validBoard(board)) println(\"YES\") else println(\"NO\")\n \n } //> main: (args: Array[String])Unit\n}"}], "src_uid": "ca65e023be092b2ce25599f52acc1a67"} {"nl": {"description": "n hobbits are planning to spend the night at Frodo's house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit gets hurt if he has at least two pillows less than some of his neighbors have. Frodo will sleep on the k-th bed in the row. What is the maximum number of pillows he can have so that every hobbit has at least one pillow, every pillow is given to some hobbit and no one is hurt?", "input_spec": "The only line contain three integers n, m and k (1 ≤ n ≤ m ≤ 109, 1 ≤ k ≤ n) — the number of hobbits, the number of pillows and the number of Frodo's bed.", "output_spec": "Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.", "sample_inputs": ["4 6 2", "3 10 3", "3 6 1"], "sample_outputs": ["2", "4", "3"], "notes": "NoteIn the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds.In the second example Frodo can take at most four pillows, giving three pillows to each of the others.In the third example Frodo can take three pillows, giving two pillows to the hobbit in the middle and one pillow to the hobbit on the third bed."}, "positive_code": [{"source_code": "object Solution extends App {\n\n val arr = io.StdIn.readLine().split(\" \").map(_.toLong);\n val n = arr(0)\n var m = arr(1)\n val k = arr(2)\n \n def calcPillows(x: Long, y: Long) = {\n def maxBed(x: Long, y: Long) = (x - 1) * x / 2 + y - (x - 1)\n\n def maxPillow(x: Long, y: Long) = (x - 1 + x - y) * y / 2\n\n if (y >= x - 1) maxBed(x, y) else maxPillow(x, y)\n }\n\n def binSearch(start: Long, end: Long): Long = {\n val mid = (end + start) / 2\n val calc = calcPillows(mid, k - 1)\n val calcAnother = calcPillows(mid, n - k)\n if (end - start <= 1) mid\n else if (calc + calcAnother + mid <= m) binSearch(mid, end) else binSearch(start, mid)\n }\n\n print(binSearch(1, m + 1))\n\n}"}], "negative_code": [{"source_code": "object Solution extends App {\n\n val arr = io.StdIn.readLine().split(\" \").map(_.toLong);\n val n = arr(0)\n val m = arr(1)\n val k = arr(2)\n\n def calcPillows(x: Long, y: Long) = {\n def maxBed(x: Long, y: Long) = (x - 1) * x / 2 + y - x + 1\n\n def maxPillow(x: Long, y: Long) = (x - 1 + x - y) * y / 2\n\n if (y > x - 1) maxBed(x, y) else maxPillow(x, y)\n }\n\n def binSearch(start: Long, end: Long): Long = {\n val mid = (end + start) / 2\n val calc = calcPillows(mid, k - 1)\n val calcAnother = calcPillows(mid, n - k - 1)\n if (end - start <= 1) mid\n else if (calc + calcAnother + mid <= m) binSearch(mid, end) else binSearch(start, mid)\n }\n\n print(binSearch(1, m + 1))\n\n}"}, {"source_code": "object Solution extends App {\n\n val arr = io.StdIn.readLine().split(\" \").map(_.toLong);\n val n = arr(0)\n val m = arr(1)\n val k = arr(2)\n\n def calcPillows(x: Long, y: Long) = {\n def maxBed(x: Long, y: Long) = (x - 1) * x / 2 + y - x + 1\n\n def maxPillow(x: Long, y: Long) = (x - 1 + x - y) * y / 2\n\n if (y > x - 1) maxBed(x, y) else maxPillow(x, y)\n }\n\n def binSearch(start: Long, end: Long): Long = {\n val mid = (end + start) / 2\n val calc = calcPillows(mid, k)\n val calcAnother = calcPillows(mid, n - k + 1)\n if (end - start <= 1) mid\n else if (calc + calcAnother <= m) binSearch(mid, end) else binSearch(start, mid)\n }\n\n print(binSearch(1, m + 1))\n\n}\n"}], "src_uid": "da9ddd00f46021e8ee9db4a8deed017c"} {"nl": {"description": "Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad.The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions $$$a$$$, $$$b$$$ and $$$c$$$ respectively. At the end of the performance, the distance between each pair of ropewalkers was at least $$$d$$$.Ropewalkers can walk on the rope. In one second, only one ropewalker can change his position. Every ropewalker can change his position exactly by $$$1$$$ (i. e. shift by $$$1$$$ to the left or right direction on the rope). Agafon, Boniface and Konrad can not move at the same time (Only one of them can move at each moment). Ropewalkers can be at the same positions at the same time and can \"walk past each other\".You should find the minimum duration (in seconds) of the performance. In other words, find the minimum number of seconds needed so that the distance between each pair of ropewalkers can be greater or equal to $$$d$$$.Ropewalkers can walk to negative coordinates, due to the rope is infinite to both sides.", "input_spec": "The only line of the input contains four integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$1 \\le a, b, c, d \\le 10^9$$$). It is possible that any two (or all three) ropewalkers are in the same position at the beginning of the performance.", "output_spec": "Output one integer — the minimum duration (in seconds) of the performance.", "sample_inputs": ["5 2 6 3", "3 1 5 6", "8 3 3 2", "2 3 10 4"], "sample_outputs": ["2", "8", "2", "3"], "notes": "NoteIn the first example: in the first two seconds Konrad moves for 2 positions to the right (to the position $$$8$$$), while Agafon and Boniface stay at their positions. Thus, the distance between Agafon and Boniface will be $$$|5 - 2| = 3$$$, the distance between Boniface and Konrad will be $$$|2 - 8| = 6$$$ and the distance between Agafon and Konrad will be $$$|5 - 8| = 3$$$. Therefore, all three pairwise distances will be at least $$$d=3$$$, so the performance could be finished within 2 seconds."}, "positive_code": [{"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[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とか+7とかするならvalにしろ\n @inline private def MOD = 1000000007\n\n def solve(): Unit = {\n val A, B, C, D = ni()\n val V = Array(A, B, C)\n sort(V)\n val ans = max(0, D - (V(1) - V(0))) + max(0, D - (V(2) - V(1)))\n out.println(ans)\n }\n}"}, {"source_code": "object _1185A 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 Seq(a, b, c) = io.read[Seq, Int](3).sorted\n val d = io.read[Int]\n val ans = ((d - b + a) max 0) + ((d - c + b) max 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}\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 writeLines(obj: Traversable[Any]): this.type = writeAll(obj, separator = \"\\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"}, {"source_code": "\n\nobject Main {\n\n import java.io.{PrintWriter, _}\n import java.util._\n\n\n def main(args: Array[String]): Unit = {\n val inputStream = System.in\n val outputStream = System.out\n val in = new InputReader(inputStream)\n val out = new PrintWriter(outputStream)\n val solver = new Task\n solver.solve(1, in, out)\n out.close()\n }\n\n def ?(item: Boolean, first: Any, second: Any): Any = if (item) first else second\n\n class Task {\n def solve(testNumber: Int, in: InputReader, out: PrintWriter): Unit = {\n var arr = new Array[Int](3)\n arr(0) = in.nextInt\n arr(1) = in.nextInt\n arr(2) = in.nextInt\n arr = arr.sorted\n val d = in.nextInt\n val a = math.max(arr(1) + d - arr(2), 0)\n val b = math.min(arr(1) - d - arr(0), 0)\n out.println(a - b)\n }\n\n }\n\n\n class InputReader(val stream: InputStream) extends AutoCloseable {\n //reader = new BufferedReader(new FileReader(stream), 32768);\n private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n private var tokenizer = new StringTokenizer(\"\")\n\n\n def next: String = {\n while ( {\n tokenizer == null || !tokenizer.hasMoreTokens\n }) try\n tokenizer = new StringTokenizer(reader.readLine)\n catch {\n case e: IOException =>\n throw new RuntimeException(e)\n }\n tokenizer.nextToken\n }\n\n def nextLine: String = {\n try\n return reader.readLine\n catch {\n case e: IOException =>\n e.printStackTrace()\n }\n \"\"\n }\n\n def nextInt: Int = next.toInt\n\n def nextLong: Long = next.toLong\n\n override def close(): Unit = {\n }\n }\n\n}\n"}], "negative_code": [{"source_code": "\n\nobject Main {\n\n import java.io.{PrintWriter, _}\n import java.util._\n\n\n def main(args: Array[String]): Unit = {\n val inputStream = System.in\n val outputStream = System.out\n val in = new InputReader(inputStream)\n val out = new PrintWriter(outputStream)\n val solver = new Task\n solver.solve(1, in, out)\n out.close()\n }\n\n def ?(item: Boolean, first: Any, second: Any): Any = if (item) first else second\n\n class Task {\n def solve(testNumber: Int, in: InputReader, out: PrintWriter): Unit = {\n var arr = new Array[Int](3)\n arr(0) = in.nextInt\n arr(1) = in.nextInt\n arr(2) = in.nextInt\n arr = arr.sorted\n val d = in.nextInt\n val a = math.max(arr(1) + d - arr(2), 0)\n val b = math.max(math.abs(arr(1) - d - arr(0)), 0)\n out.println(a + b)\n }\n\n }\n\n\n class InputReader(val stream: InputStream) extends AutoCloseable {\n //reader = new BufferedReader(new FileReader(stream), 32768);\n private val reader = new BufferedReader(new InputStreamReader(stream), 32768)\n private var tokenizer = new StringTokenizer(\"\")\n\n\n def next: String = {\n while ( {\n tokenizer == null || !tokenizer.hasMoreTokens\n }) try\n tokenizer = new StringTokenizer(reader.readLine)\n catch {\n case e: IOException =>\n throw new RuntimeException(e)\n }\n tokenizer.nextToken\n }\n\n def nextLine: String = {\n try\n return reader.readLine\n catch {\n case e: IOException =>\n e.printStackTrace()\n }\n \"\"\n }\n\n def nextInt: Int = next.toInt\n\n def nextLong: Long = next.toLong\n\n override def close(): Unit = {\n }\n }\n\n}\n"}], "src_uid": "47c07e46517dbc937e2e779ec0d74eb3"} {"nl": {"description": "The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the \"middle\" row — the row which has exactly rows above it and the same number of rows below it. Elements of the \"middle\" column — the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5 × 5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix.", "input_spec": "The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: 1 ≤ n ≤ 5 The input limitations for getting 100 points are: 1 ≤ n ≤ 101 ", "output_spec": "Print a single integer — the sum of good matrix elements.", "sample_inputs": ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"], "sample_outputs": ["45", "17"], "notes": "NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure."}, "positive_code": [{"source_code": "import scala.io.Source\n\nobject Cf177a1 extends App {\n val a = Source.stdin.getLines.drop(1).map(_.split(\" \").map(_.toInt)).toArray\n var rez = 0\n val n = a.length\n for (i <- 0 until n) {\n for (j <- 0 until n) {\n if (i == j || i == n - j - 1 || i == n / 2 || j == n / 2) rez = rez + a(i)(j)\n }\n }\n println(rez)\n}"}, {"source_code": "import scala.io.Source\n\nobject Cf177a1 extends App {\n val a = Source.stdin.getLines.drop(1).map(_.split(\" \").map(_.toInt)).toArray\n var rez = 0\n val n = a.length\n for (i <- 0 until n) {\n for (j <- 0 until n) {\n if (i == j || i == n - j - 1 || i == n / 2 || j == n / 2) rez = rez + a(i)(j)\n }\n }\n println(rez)\n}"}], "negative_code": [], "src_uid": "5ebfad36e56d30c58945c5800139b880"} {"nl": {"description": "Alice is the leader of the State Refactoring Party, and she is about to become the prime minister. The elections have just taken place. There are $$$n$$$ parties, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th party has received $$$a_i$$$ seats in the parliament.Alice's party has number $$$1$$$. In order to become the prime minister, she needs to build a coalition, consisting of her party and possibly some other parties. There are two conditions she needs to fulfil: The total number of seats of all parties in the coalition must be a strict majority of all the seats, i.e. it must have strictly more than half of the seats. For example, if the parliament has $$$200$$$ (or $$$201$$$) seats, then the majority is $$$101$$$ or more seats. Alice's party must have at least $$$2$$$ times more seats than any other party in the coalition. For example, to invite a party with $$$50$$$ seats, Alice's party must have at least $$$100$$$ seats. For example, if $$$n=4$$$ and $$$a=[51, 25, 99, 25]$$$ (note that Alice'a party has $$$51$$$ seats), then the following set $$$[a_1=51, a_2=25, a_4=25]$$$ can create a coalition since both conditions will be satisfied. However, the following sets will not create a coalition: $$$[a_2=25, a_3=99, a_4=25]$$$ since Alice's party is not there; $$$[a_1=51, a_2=25]$$$ since coalition should have a strict majority; $$$[a_1=51, a_2=25, a_3=99]$$$ since Alice's party should have at least $$$2$$$ times more seats than any other party in the coalition. Alice does not have to minimise the number of parties in a coalition. If she wants, she can invite as many parties as she wants (as long as the conditions are satisfied). If Alice's party has enough people to create a coalition on her own, she can invite no parties.Note that Alice can either invite a party as a whole or not at all. It is not possible to invite only some of the deputies (seats) from another party. In other words, if Alice invites a party, she invites all its deputies.Find and print any suitable coalition.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$2 \\leq n \\leq 100$$$) — the number of parties. The second line contains $$$n$$$ space separated integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\leq a_i \\leq 100$$$) — the number of seats the $$$i$$$-th party has.", "output_spec": "If no coalition satisfying both conditions is possible, output a single line with an integer $$$0$$$. Otherwise, suppose there are $$$k$$$ ($$$1 \\leq k \\leq n$$$) parties in the coalition (Alice does not have to minimise the number of parties in a coalition), and their indices are $$$c_1, c_2, \\dots, c_k$$$ ($$$1 \\leq c_i \\leq n$$$). Output two lines, first containing the integer $$$k$$$, and the second the space-separated indices $$$c_1, c_2, \\dots, c_k$$$. You may print the parties in any order. Alice's party (number $$$1$$$) must be on that list. If there are multiple solutions, you may print any of them.", "sample_inputs": ["3\n100 50 50", "3\n80 60 60", "2\n6 5", "4\n51 25 99 25"], "sample_outputs": ["2\n1 2", "0", "1\n1", "3\n1 2 4"], "notes": "NoteIn the first example, Alice picks the second party. Note that she can also pick the third party or both of them. However, she cannot become prime minister without any of them, because $$$100$$$ is not a strict majority out of $$$200$$$.In the second example, there is no way of building a majority, as both other parties are too large to become a coalition partner.In the third example, Alice already has the majority. The fourth example is described in the problem statement."}, "positive_code": [{"source_code": "object A 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 = readInts(n).zipWithIndex\n val a0 = as(0)._1\n\n val cs = as.filter(_._1 * 2 <= a0)\n\n val sum = a0 + cs.map(_._1).sum\n\n if (sum * 2 > as.map(_._1).sum) {\n println(cs.size + 1)\n println((1 +: cs.map(_._2 + 1)).mkString(\" \"))\n } else {\n println(0)\n }\n\n Console.flush\n}\n"}, {"source_code": "object _1178A 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 votes = io.read[Vector[Int]]\n val majority = 0 +: votes.indicesWhere(v => 2*v <= votes.head)\n val ans = if (2*majority.map(votes).sum > votes.sum) {\n majority\n } else {\n Nil\n }\n io.writeLine(ans.length).writeAll(ans.map(_ + 1))\n }\n\n implicit class IterableExtensions[A, C[A] <: Seq[A]](s: C[A]) {\n def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}\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 writeLines(obj: Traversable[Any]): this.type = writeAll(obj, separator = \"\\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"}], "negative_code": [{"source_code": "object _1178A 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 votes = io.read[Vector[Int]]\n val majority = 0 +: votes.indicesWhere(v => 2*v <= votes.head)\n val ans = if (2*majority.map(votes).sum >= votes.sum) {\n majority\n } else {\n Nil\n }\n io.writeLine(ans.length).writeAll(ans.map(_ + 1))\n }\n\n implicit class IterableExtensions[A, C[A] <: Seq[A]](s: C[A]) {\n def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}\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 writeLines(obj: Traversable[Any]): this.type = writeAll(obj, separator = \"\\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": "0a71fdaaf08c18396324ad762b7379d7"} {"nl": {"description": "The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy \"GAGA: Go And Go Again\". The gameplay is as follows. There are two armies on the playing field each of which consists of n men (n is always even). The current player specifies for each of her soldiers an enemy's soldier he will shoot (a target) and then all the player's soldiers shot simultaneously. This is a game world, and so each soldier shoots perfectly, that is he absolutely always hits the specified target. If an enemy soldier is hit, he will surely die. It may happen that several soldiers had been indicated the same target. Killed soldiers do not participate in the game anymore. The game \"GAGA\" consists of three steps: first Valera makes a move, then Arcady, then Valera again and the game ends. You are asked to calculate the maximum total number of soldiers that may be killed during the game. ", "input_spec": "The input data consist of a single integer n (2 ≤ n ≤ 108, n is even). Please note that before the game starts there are 2n soldiers on the fields. ", "output_spec": "Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns.", "sample_inputs": ["2", "4"], "sample_outputs": ["3", "6"], "notes": "NoteThe first sample test:1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1.2) Arcady's soldier 2 shoots at Valera's soldier 1.3) Valera's soldier 1 shoots at Arcady's soldier 2.There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2."}, "positive_code": [{"source_code": "import java.util.Scanner\nobject GAGA {\n def main(args: Array[String]) {\n val scanner = new Scanner(System.in)\n val n = scanner.nextInt()\n println(n/2*3);\n }\n}"}, {"source_code": "import java.util.StringTokenizer\n\nobject _84A 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 println(n / 2 * 3)\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n println(3 * in.next().toInt / 2)\n}"}, {"source_code": "import scala.math\nobject Main\n{\n\tdef main(args:Array[String])\n\t{\n\t\tprintln(readInt / 2 * 3)\n\t}\n}"}, {"source_code": "object A84 {\n\n import IO._\n import collection.{mutable => cu}\n\n def main(args: Array[String]): Unit = {\n val Array(n) = readInts(1)\n println(3*(n/2))\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"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P84A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val N = sc.nextInt\n\n val answer = 2 * N - (N / 2)\n\n out.println(answer)\n out.close\n}\n"}, {"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 def ans = readInt / 2 * 3\n\n def main(a: Array[String]) {\n println(ans)\n }\n}\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val n = readInt()\n println(3 * n / 2)\n }\n}"}], "negative_code": [], "src_uid": "031e53952e76cff8fdc0988bb0d3239c"} {"nl": {"description": "While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number \"586\" are the same as finger movements for number \"253\": Mike has already put in a number by his \"finger memory\" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?", "input_spec": "The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.", "output_spec": "If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print \"YES\" (without quotes) in the only line. Otherwise print \"NO\" (without quotes) in the first line.", "sample_inputs": ["3\n586", "2\n09", "9\n123456789", "3\n911"], "sample_outputs": ["NO", "NO", "YES", "YES"], "notes": "NoteYou can find the picture clarifying the first sample case in the statement above."}, "positive_code": [{"source_code": "import scala.io.StdIn._\n\nobject _361A extends App {\n readInt\n val s = readLine.toCharArray.map(_.asDigit).toSet\n val unique =\n List(\n Set(1, 4, 7, 0),\n Set(1, 2, 3),\n Set(3, 6, 9, 0),\n Set(7, 0, 9))\n val ans = unique.forall(x => x.intersect(s).nonEmpty)\n println(if (ans) \"YES\" else \"NO\")\n}"}, {"source_code": "import scala.io.StdIn._ \nimport scala.util.control._\n\nobject cf689A {\n def main (args: Array[String]) {\n val n = readInt();\n val s = readLine();\n\n if (judge(s, up) || judge(s, down) || judge(s, left) || judge(s, right)) {\n println(\"NO\");\n } else {\n println(\"YES\");\n }\n }\n\n def judge (s:String, f: Char => Boolean) : Boolean = {\n var res:Boolean = true;\n for (i <- 0 until s.length()) {\n if (f(s(i)) == false) {\n res = false\n }\n }\n return res;\n }\n\n def up (c:Char) : Boolean = {\n if (c == '0' || c > '3') return true;\n else return false;\n }\n\n\n def down (c:Char) : Boolean = {\n if (c == '8' || (c < '7' && c > '0')) return true;\n else return false;\n }\n\n def left (c:Char) : Boolean = {\n if ((c - '0') % 3 == 1 || c == '0') return false;\n else return true;\n }\n\n def right (c:Char) : Boolean = {\n if ((c - '0') % 3 == 0 || c == '0') return false;\n else return true;\n }\n}"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val n = in.next().toInt\n val line = in.next()\n val up = Set('1', '2', '3')\n val down = Set('7', '0', '9')\n val right = Set('3', '6', '9', '0')\n val left = Set('1', '4', '7', '0')\n List(left, right, down, up).exists(set => line.forall(i => !set.contains(i))) match {\n case false => println(\"YES\")\n case true => println(\"NO\")\n }\n}\n"}, {"source_code": "import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._\n\nobject _689A extends CodeForcesApp {\n\n val moves = Map(\n 1 -> \"DR\",\n 2 -> \"DLR\",\n 3 -> \"DL\",\n 4 -> \"UDR\",\n 5 -> \"UDLR\",\n 6 -> \"UDL\",\n 7 -> \"UR\",\n 8 -> \"UDLR\",\n 9 -> \"UL\",\n 0 -> \"U\"\n ).mapValues(_.toSet)\n\n override def apply(io: IO) = {import io.{read, write}\n val (_, d) = read[(Int, String)]\n val ans = \"UDLR\" find {c => d.forall(i => moves(i - '0').contains(c))}\n write(ans.isEmpty.toYesNo)\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 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 toYesNo = if(x) \"YES\" else \"NO\"\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] = 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 @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 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 override def next() = tokenizer().get.nextToken()\n override def hasNext = tokenizer().nonEmpty\n\n def write(obj: Any, more: Any*): this.type = {\n printer.print(obj)\n more foreach {i =>\n printer.print(' ')\n printer.print(i)\n }\n this\n }\n def writeLine(obj: Any*): this.type = {\n if (obj.isEmpty) printer.println() else obj foreach printer.println\n this\n }\n def writeAll(obj: Traversable[Any], separator: String = \" \"): this.type = write(obj mkString separator)\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"}, {"source_code": "import java.util.Scanner\n\nobject Main{\n def ctoi(c: Char) = c.toInt - '0'.toInt\n\n def main (args: Array[String]){\n val sc = new Scanner(System.in)\n val n = sc.nextInt()\n sc.nextLine()\n val s = sc.nextLine()\n\n val dp = new Array[Boolean](10)\n\n val key = Array((1, 3),\n (0,0), (1,0), (2,0),\n (0,1), (1,1), (2,1),\n (0,2), (1,2), (2,2)\n )\n\n var xl = 9\n var xr = -1\n var yl = 9\n var yr = -1\n\n for(i <- 0 until n){\n val now = ctoi(s(i))\n dp(now) = true\n val (nx, ny) = key(now)\n\n xl = Math.min(xl, nx)\n xr = Math.max(xr, nx)\n yl = Math.min(yl, ny)\n yr = Math.max(yr, ny)\n }\n\n val xz = xr - xl + 1\n val yz = yr - yl + 1\n\n val yes = \"YES\"\n val no = \"NO\"\n\n if(yz == 4)\n println(yes)\n else if(xz == 3 && yz == 3){\n if(dp(0) || (dp(8) && !dp(7) && !dp(9)))\n println(no)\n else\n println(yes)\n }\n else\n println(no)\n }\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject A extends App {\n readInt()\n val M = readLine().toCharArray.map(_.asDigit)\n\n def delta(a: Int, b: Int): (Int, Int) = {\n val (y1, x1) = pos(a)\n val (y2, x2) = pos(b)\n (y2 - y1, x2 - x1)\n }\n\n def pos(a: Int) = {\n if (List(1, 2, 3).contains(a)) (0, a - 1)\n else if (List(4, 5, 6).contains(a)) (1, a % 4)\n else if (List(7, 8, 9).contains(a)) (2, a % 7)\n else (3, 1)\n }\n\n var prev = M.head\n val Deltas = M.tail.map { curr =>\n val d = delta(prev, curr)\n prev = curr\n d\n }\n\n def canMoveFromThisPoint(startY: Int, startX: Int): Boolean = {\n var y = startY\n var x = startX\n\n Deltas.foreach { case (dy, dx) =>\n y += dy\n x += dx\n\n if (y < 0 || x < 0 || y > 3 || x >= 3) return false\n else if (y == 3 && x != 1) return false\n }\n\n true\n }\n\n def existDifferentPath: Boolean = {\n val (startY, startX) = pos(M.head)\n for {\n y <- 0 to 3\n x <- 0 to 2\n } {\n val isIllegal = (y == 3 && x != 1) || (y == startY && x == startX)\n if (!isIllegal && canMoveFromThisPoint(y, x)) return true\n }\n\n false\n }\n\n val unique = !existDifferentPath\n println(if (unique) \"YES\" else \"NO\")\n}\n"}, {"source_code": "object main\n{\n\tdef main(args : Array[String] )\n\t{\n\t\tvar n = Console.readLine.toInt;\n\t\tvar str = Console.readLine;\n\n\t\tvar pos = Array(Array(4,2),Array(1,1),Array(1,2),Array(1,3),Array(2,1),Array(2,2),Array(2,3),Array(3,1),Array(3,2),Array(3,3));\n\n\t\tvar cnt = 0;\n\t\tvar a = 0;\n\t\tfor (a <- 0 to 9 )\n\t\t{\n\t\t\tvar nowx = pos(a)(0);\n\t\t\tvar nowy = pos(a)(1);\n\t\t\tvar able = true;\n\t\t\tvar b = 0;\n\t\t\tfor (b <- 0 to n-2)\n\t\t\t{\n\t\t\t\tvar dx = pos(str.charAt(b+1)-'0')(0)-pos(str.charAt(b)-'0')(0);\n\t\t\t\tvar dy = pos(str.charAt(b+1)-'0')(1)-pos(str.charAt(b)-'0')(1);\n\t\t\t\tnowx += dx;\n\t\t\t\tnowy += dy;\n\t\t\t\tif (nowx < 1 || nowy < 1 || nowy>3) able=false;\n\t\t\t\tif (nowx>3 && (nowx!=4 || nowy!=2)) able=false;\n\t\t\t}\n\t\t\tif (able) cnt+=1;\n\t\t}\n\t\tif (cnt==1) println(\"YES\");\n\t\telse println(\"NO\");\n}\n}"}], "negative_code": [{"source_code": "import scala.io.StdIn._ \nimport scala.util.control._\n\nobject cf689A {\n def main (args: Array[String]) {\n val n = readInt();\n val s = readLine();\n\n if (judge(s, up) || judge(s, down) || judge(s, left) || judge(s, right)) {\n println(\"NO\");\n } else {\n println(\"YES\");\n }\n }\n\n def judge (s:String, f: Char => Boolean) : Boolean = {\n var res:Boolean = true;\n for (i <- 0 until s.length()) {\n if (f(s(i)) == false) {\n res = false\n }\n }\n return res;\n }\n\n def up (c:Char) : Boolean = {\n if (c == '0' || c > '3') return true;\n else return false;\n }\n\n\n def down (c:Char) : Boolean = {\n if (c == '8' || c < '7') return true;\n else return false;\n }\n\n def left (c:Char) : Boolean = {\n if ((c - '0') % 3 == 1 || c == '0') return false;\n else return true;\n }\n\n def right (c:Char) : Boolean = {\n if ((c - '0') % 3 == 0 || c == '0') return false;\n else return true;\n }\n}"}, {"source_code": "import scala.io.StdIn._ \nimport scala.util.control._\n\nobject cf689A {\n def main (args: Array[String]) {\n val n = readInt();\n val s = readLine();\n\n if (judge(s, up) || judge(s, down) || judge(s, left) || judge(s, right)) {\n println(\"NO\");\n } else {\n println(\"YES\");\n }\n }\n\n def judge (s:String, f: Char => Boolean) : Boolean = {\n var res:Boolean = true;\n for (i <- 0 until s.length()) {\n if (f(s(i)) == false) {\n res = false\n }\n }\n return res;\n }\n\n def up (c:Char) : Boolean = {\n if (c == '0' || c > '3') return true;\n else return false;\n }\n\n\n def down (c:Char) : Boolean = {\n if (c == '8' || c < '7') return true;\n else return false;\n }\n\n def left (c:Char) : Boolean = {\n if ((c - '0') % 3 == 1) return true;\n else return false;\n }\n\n def right (c:Char) : Boolean = {\n if ((c - '0') % 3 == 0 && c != '0') return true;\n else return false;\n }\n}"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val n = in.next().toInt\n val line = in.next()\n val up = Set('1', '2', '3')\n val down = Set('7', '0', '9')\n val right = Set('3', '6', '9', '0')\n val left = Set('1', '4', '7', '0')\n List(left, up, down, up).exists(set => line.forall(i => !set.contains(i))) match {\n case false => println(\"YES\")\n case true => println(\"NO\")\n }\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject Main{\n def ctoi(c: Char) = c.toInt - '0'.toInt\n\n def main (args: Array[String]){\n val sc = new Scanner(System.in)\n val n = sc.nextInt()\n sc.nextLine()\n val s = sc.nextLine()\n\n val key = Array((1, 3),\n (0,0), (1,0), (2,0),\n (0,1), (1,1), (2,1),\n (0,2), (1,2), (2,2)\n )\n\n var xl = 9\n var xr = -1\n var yl = 9\n var yr = -1\n\n for(i <- 0 until n){\n val (nx, ny) = key(ctoi(s(i)))\n xl = Math.min(xl, nx)\n xr = Math.max(xr, nx)\n yl = Math.min(yl, ny)\n yr = Math.max(yr, ny)\n }\n\n val xz = xr - xl + 1\n val yz = yr - yl + 1\n\n val yes = \"YES\"\n val no = \"NO\"\n\n if(yz == 4)\n println(yes)\n else if(xz == 3 && yz == 3)\n println(yes)\n else\n println(no)\n }\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject A extends App {\n readInt()\n val M = readLine().toCharArray.map(_.asDigit)\n\n def delta(a: Int, b: Int): (Int, Int) = {\n val (y1, x1) = pos(a)\n val (y2, x2) = pos(b)\n (y2 - y1, x2 - x1)\n }\n\n def pos(a: Int) = {\n if (List(1, 2, 3).contains(a)) (0, a - 1)\n else if (List(4, 5, 6).contains(a)) (1, a % 4)\n else if (List(7, 8, 9).contains(a)) (2, a % 7)\n else (3, 1)\n }\n\n var prev = M.head\n val Deltas = M.tail.map { curr =>\n val d = delta(prev, curr)\n prev = curr\n d\n }\n\n def canMoveFromThisPoint(startY: Int, startX: Int): Boolean = {\n var y = startY\n var x = startX\n\n Deltas.foreach { case (dy, dx) =>\n y += dy\n x += dx\n\n if (y < 0 || x < 0 || y > 3 || x >= 3) return false\n else if (y == 3 && x != 1) return false\n }\n\n true\n }\n\n def existDifferentPath: Boolean = {\n val (startY, startX) = pos(M.head)\n for {\n y <- 0 to 3\n x <- 0 to 2\n if y != startY && x != startX\n } {\n if (canMoveFromThisPoint(y, x)) return true\n }\n\n false\n }\n\n val unique = !existDifferentPath\n println(if (unique) \"YES\" else \"NO\")\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject A extends App {\n readInt()\n val M = readLine().toCharArray.map(_.asDigit)\n\n def delta(a: Int, b: Int): (Int, Int) = {\n val (y1, x1) = pos(a)\n val (y2, x2) = pos(b)\n (y2 - y1, x2 - x1)\n }\n\n def pos(a: Int) = {\n if (List(1, 2, 3).contains(a)) (0, a - 1)\n else if (List(4, 5, 6).contains(a)) (1, a % 4)\n else if (List(7, 8, 9).contains(a)) (2, a % 7)\n else (3, 1)\n }\n\n var prev = M.head\n val Deltas = M.tail.map { curr =>\n val d = delta(prev, curr)\n prev = curr\n d\n }\n\n def canMoveFromThisPoint(startY: Int, startX: Int): Boolean = {\n var y = startY\n var x = startX\n\n Deltas.foreach { case (dy, dx) =>\n y += dy\n x += dx\n\n if (y < 0 || x < 0 || y > 3 || x >= 3) return false\n else if (y == 3 && x != 1) return false\n }\n\n true\n }\n\n def existDifferentPath: Boolean = {\n val (startY, startX) = pos(M.head)\n for {\n y <- 0 to 3\n x <- 0 to 2\n if y != startY && x != startX\n } {\n val isIllegal = y == 3 && x != 1\n if (!isIllegal && canMoveFromThisPoint(y, x)) return true\n }\n\n false\n }\n\n val unique = !existDifferentPath\n println(if (unique) \"YES\" else \"NO\")\n}\n"}, {"source_code": "object main\n{\n\tdef main(args : Array[String] )\n\t{\n\t\tvar n = Console.readLine.toInt;\n\t\tvar str = Console.readLine;\n\n\t\tvar a = 0;\n\n\t\tvar minx = 3;\n\t\tvar miny = 3;\n\t\tvar maxx = 1;\n\t\tvar maxy = 1;\n\n\t\tfor ( a <- 0 to n-1 )\n\t\t{\n\t\t\tif (str.charAt(a)<='3') \n\t\t\t{\n\t\t\t\tminx=1;\n\t\t\t}\n\t\t\tif (str.charAt(a)<='6' && minx==3)\n\t\t\t{\n\t\t\t\tminx=2;\n\t\t\t}\n\t\t\tif (str.charAt(a)>='7')\n\t\t\t{\n\t\t\t\tmaxx=3;\n\t\t\t}\n\t\t\tif (str.charAt(a)>='4' && maxx==1)\n\t\t\t{\n\t\t\t\tmaxx=2;\n\t\t\t}\n\t\t\tif (str.charAt(a)=='1' || str.charAt(a)=='4' || str.charAt(a)=='7')\n\t\t\t{\n\t\t\t\tminy=1;\n\t\t\t}\n\t\t\tif ((str.charAt(a)=='2' || str.charAt(a)=='5' || str.charAt(a)=='8'))\n\t\t\t{\n\t\t\t\tif (miny==3) \n\t\t\t\t{\n\t\t\t\t\tminy=2;\n\t\t\t\t}\n\t\t\t\tif (maxy==1)\n\t\t\t\t{\n\t\t\t\t\tmaxy=2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (str.charAt(a)=='3' || str.charAt(a)=='6' || str.charAt(a)=='9')\n\t\t\t{\n\t\t\t\tmaxy=3;\n\t\t\t}\n\t\t}\n\t\tif (minx==1 && maxx==3 && miny==1 && maxy==3)\n\t\t{\n\t\t\tprintln(\"YES\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprintln(\"NO\");\n\t\t}\n\t}\n}"}, {"source_code": "object main\n{\n\tdef main(args : Array[String] )\n\t{\n\t\tvar n = Console.readLine.toInt;\n\t\tvar str = Console.readLine;\n\n\t\tvar a = 0;\n\n\t\tvar minx = 3;\n\t\tvar miny = 3;\n\t\tvar maxx = 1;\n\t\tvar maxy = 1;\n\n\t\tfor ( a <- 0 to n-1 )\n\t\t{\n\t\t\tif (str.charAt(a)<='3') \n\t\t\t{\n\t\t\t\tminx=1;\n\t\t\t}\n\t\t\tif (str.charAt(a)<='6' && minx==3)\n\t\t\t{\n\t\t\t\tminx=2;\n\t\t\t}\n\t\t\tif (str.charAt(a)>='7')\n\t\t\t{\n\t\t\t\tmaxx=3;\n\t\t\t}\n\t\t\tif (str.charAt(a)>='4' && maxx==1)\n\t\t\t{\n\t\t\t\tmaxx=2;\n\t\t\t}\n\t\t\tif (str.charAt(a)=='1' || str.charAt(a)=='4' || str.charAt(a)=='7')\n\t\t\t{\n\t\t\t\tminy=1;\n\t\t\t}\n\t\t\tif ((str.charAt(a)=='2' || str.charAt(a)=='5' || str.charAt(a)=='8'))\n\t\t\t{\n\t\t\t\tif (miny==3) \n\t\t\t\t{\n\t\t\t\t\tminy=2;\n\t\t\t\t}\n\t\t\t\tif (maxy==1)\n\t\t\t\t{\n\t\t\t\t\tmaxy=2;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (str.charAt(a)=='3' || str.charAt(a)=='6' || str.charAt(a)=='9')\n\t\t\t{\n\t\t\t\tmaxx=3;\n\t\t\t}\n\t\t}\n\t\tif (minx==1 && maxx==3 && miny==1 && maxy==3)\n\t\t{\n\t\t\tprintln(\"YES\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprintln(\"NO\");\n\t\t}\n\t}\n}"}], "src_uid": "d0f5174bb0bcca5a486db327b492bf33"} {"nl": {"description": "The only difference between easy and hard versions is the number of elements in the array.You are given an array $$$a$$$ consisting of $$$n$$$ integers. In one move you can choose any $$$a_i$$$ and divide it by $$$2$$$ rounding down (in other words, in one move you can set $$$a_i := \\lfloor\\frac{a_i}{2}\\rfloor$$$).You can perform such an operation any (possibly, zero) number of times with any $$$a_i$$$.Your task is to calculate the minimum possible number of operations required to obtain at least $$$k$$$ equal numbers in the array.Don't forget that it is possible to have $$$a_i = 0$$$ after some operations, thus the answer always exists.", "input_spec": "The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le k \\le n \\le 50$$$) — the number of elements in the array and the number of equal numbers required. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 2 \\cdot 10^5$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.", "output_spec": "Print one integer — the minimum possible number of operations required to obtain at least $$$k$$$ equal numbers in the array.", "sample_inputs": ["5 3\n1 2 2 4 5", "5 3\n1 2 3 4 5", "5 3\n1 2 3 3 3"], "sample_outputs": ["1", "2", "0"], "notes": null}, "positive_code": [{"source_code": "//package codeforces.contest1213\n\nobject EqualizingByDivision {\n\n def main(args: Array[String]): Unit = {\n val Array(_, k) = io.StdIn.readLine().split(\" \").map(_.toInt)\n val elements = io.StdIn.readLine().split(\" \").map(_.toInt)\n\n val maxElement = elements.max\n\n val frequency = Array.ofDim[Int](maxElement + 1, 20) // frequency with steps\n\n for (e <- elements) {\n var temp = e\n var i = 0\n while (temp > 0) {\n frequency(temp)(i) += 1\n\n i += 1\n temp = temp / 2\n }\n }\n\n println {\n (1 to maxElement).foldLeft(Int.MaxValue) {\n case (acc, e) =>\n val (steps, count) = frequency(e).indices\n .foldLeft((0, 0)) {\n case ((steps, count), i) =>\n val c = frequency(e)(i)\n if (c != 0 && count < k)\n if (count + c <= k) (steps + i * c, count + c)\n else (steps + i * (k - count), k)\n else\n (steps, count)\n }\n\n if (count == k) acc min steps else acc\n }\n }\n }\n}\n"}, {"source_code": "//package codeforces.contest1213\n\nobject EqualizingByDivision {\n\n def main(args: Array[String]): Unit = {\n val Array(_, k) = io.StdIn.readLine().split(\" \").map(_.toInt)\n val elements = io.StdIn.readLine().split(\" \").map(_.toInt)\n\n val maxElement = elements.max\n\n val frequency = Array.ofDim[Int](maxElement + 1, 20) // frequency with steps\n\n for (e <- elements) {\n var temp = e\n var i = 0\n while (temp > 0) {\n frequency(temp)(i) += 1\n\n i += 1\n temp = temp / 2\n }\n }\n\n println {\n (1 to maxElement).foldLeft(Int.MaxValue) {\n case (acc, e) =>\n val (steps, count) = frequency(e).indices\n .foldLeft((0, 0)) {\n case ((steps, count), i) =>\n val c = frequency(e)(i)\n if (c != 0 && count < k)\n if (count + c <= k) (steps + i * c, count + c)\n else (steps + i * (k - count), k)\n else\n (steps, count)\n }\n\n if (count == k) acc min steps else acc\n }\n }\n }\n}\n"}], "negative_code": [{"source_code": "//package codeforces.contest1213\n\nobject EqualizingByDivision {\n\n def main(args: Array[String]): Unit = {\n val Array(_, k) = io.StdIn.readLine().split(\" \").map(_.toInt)\n val elements = io.StdIn.readLine().split(\" \").map(_.toInt)\n\n val maxElement = elements.max\n\n val frequency = Array.ofDim[Int](maxElement + 1, 20) // frequency with steps\n\n for (e <- elements) {\n var temp = e\n var i = 0\n while (temp > 0) {\n frequency(temp)(i) += 1\n\n i += 1\n temp = temp / 2\n }\n }\n\n println {\n (1 to maxElement).foldLeft(Int.MaxValue) {\n case (acc, e) =>\n val (steps, count) = frequency(e).indices\n .foldLeft((0, 0)) {\n case ((steps, count), i) =>\n val c = frequency(e)(i)\n if (c != 0 && count < k)\n if (count + c <= k) (steps + i * c, count + c)\n else (steps + i * (count + c - k), k)\n else\n (steps, count)\n }\n\n if (count == k) acc min steps else acc\n }\n }\n }\n}\n"}], "src_uid": "ed1a2ae733121af6486568e528fe2d84"} {"nl": {"description": "Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1 + 2 + 3 = 6.The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.", "input_spec": "The first line contains a single integer a (1 ≤ a ≤ 1000) — the initial position of the first friend. The second line contains a single integer b (1 ≤ b ≤ 1000) — the initial position of the second friend. It is guaranteed that a ≠ b.", "output_spec": "Print the minimum possible total tiredness if the friends meet in the same point.", "sample_inputs": ["3\n4", "101\n99", "5\n10"], "sample_outputs": ["1", "2", "9"], "notes": "NoteIn the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2.In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9."}, "positive_code": [{"source_code": "import scala.io._\nimport scala.math._\n\nobject a7 {\n def main(args: Array[String]): Unit = {\n def apsum(n:Int) = n*(n+1)/2\n val pos = Source.stdin.getLines().toArray.map(_.toInt)\n val (a,b)=(pos(0), pos(1))\n val diff = abs(a-b)\n println(apsum(diff/2)+apsum(diff-diff/2))\n }\n}\n"}, {"source_code": "object A extends App {\n def l(n: Int): Int = n * (n + 1) / 2\n\n val a = scala.io.StdIn.readInt()\n val b = scala.io.StdIn.readInt()\n val n = (a - b).abs\n val m = n / 2\n\n val t = if (n == 1) 1\n else if (n % 2 == 0) 2 * l(m)\n else 2 * l(m) + (m + 1)\n\n println(t)\n}\n"}], "negative_code": [], "src_uid": "d3f2c6886ed104d7baba8dd7b70058da"} {"nl": {"description": "One day Vasya heard a story: \"In the city of High Bertown a bus number 62 left from the bus station. It had n grown-ups and m kids...\"The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride.The bus fare equals one berland ruble in High Bertown. However, not everything is that easy — no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with his k (k > 0) children, pays overall k rubles: a ticket for himself and (k - 1) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble.We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups.Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total.", "input_spec": "The input file consists of a single line containing two space-separated numbers n and m (0 ≤ n, m ≤ 105) — the number of the grown-ups and the number of the children in the bus, correspondingly.", "output_spec": "If n grown-ups and m children could have ridden in the bus, then print on a single line two space-separated integers — the minimum and the maximum possible total bus fare, correspondingly. Otherwise, print \"Impossible\" (without the quotes).", "sample_inputs": ["1 2", "0 5", "2 2"], "sample_outputs": ["2 2", "Impossible", "2 3"], "notes": "NoteIn the first sample a grown-up rides with two children and pays two rubles.In the second sample there are only children in the bus, so the situation is impossible. In the third sample there are two cases: Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passengers pay two rubles in total. One of the grown-ups ride with two children's and pays two rubles, the another one rides alone and pays one ruble for himself. So, they pay three rubles in total. "}, "positive_code": [{"source_code": "object Solution {\n def main(args: Array[String]) {\n val tokens = readLine().split(\" \").map(_.toInt)\n val grownups = tokens(0)\n val kids = tokens(1)\n if (grownups == 0 && kids > 0) {\n println(\"Impossible\")\n } else {\n printf(\"%d %d\\n\",\n grownups + (0 max (kids-grownups)),\n grownups + (0 max (kids-1)))\n }\n }\n}\n"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val Array(n, m) = in.next().split(' ').map(_.toInt)\n println((n, m) match {\n case(x, 0) => s\"$x $x\"\n case(0, x) => \"Impossible\"\n case(y, x) if y >= x => s\"$y ${y + x - 1}\"\n case(y, x) => s\"$x ${y + x - 1}\"\n })\n\n}"}, {"source_code": "//http://rextester.com scala 2.11.7\nimport scala.io.Source\nobject Rextester extends App{\n val a=Source.stdin.getLines();val Array(b,c)=a.next().split(' ').map(_.toInt)\n if(b<1&c>0)print(\"Impossible\")\n else{\n var d=b+c-1\n if(c==0)d=b\n print(math.max(b,c)+\" \"+d)\n }\n}"}, {"source_code": "import scala.io.Source;object a{def main(args:Array[String]){val z=Source.stdin.getLines();val Array(a,b)=z.next().split(' ').map(_.toInt);if(a<1&b>0)print(\"Impossible\")else print(math.max(a,b)+\" \"+{if(b>0)a+b-1 else a})}}"}, {"source_code": "//rextester.com:2.11.7--codeforces.com:2.11.8\nimport scala.io.Source\nobject Rextester extends App{\n val z=Source.stdin.getLines();val Array(a,b)=z.next().split(' ').map(_.toInt)\n if(a<1&b>0)print(\"Impossible\")\n else print(math.max(a,b)+\" \"+{if(b>0)a+b-1 else a})\n}"}, {"source_code": "//rextester.com:2.11.7--codeforces.com:2.11.8\nimport scala.io.Source\nobject a extends App{\n val z=Source.stdin.getLines();val Array(a,b)=z.next().split(' ').map(_.toInt)\n if(a<1&b>0)print(\"Impossible\")\n else print(math.max(a,b)+\" \"+{if(b>0)a+b-1 else a})\n}"}, {"source_code": "//2.12.5 | JDoodle.Com & 2.12 | CodeForces.Com\nimport scala.io.Source\n\nobject Solution {\n def main(args: Array[String]) {\n val input = Source.stdin.getLines()\n \n val Array(grown_ups, children) = input.next().split(' ').map(_.toInt)\n \n if (grown_ups < 1 & children > 0)\n print(\"Impossible\")\n else\n print(math.max(grown_ups, children) + \" \" + {if (children > 0) grown_ups + children - 1 else grown_ups})\n }\n}"}, {"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 P190A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val N, M = sc.nextInt\n\n val res = (N, M) match {\n case (0, 0) => \"0 0\"\n case (0, _) => \"Impossible\"\n case (x, 0) => List(x, x).mkString(\" \")\n case (x, y) => List(x max y, x + y - 1).mkString(\" \")\n }\n\n out.println(res)\n out.close\n}\n\n\n\n\n\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val Array(n, m) = readLine().split(\" \").map(_.toInt)\n val min = n + (m - n).max(0)\n val max = n + (m - 1).max(0)\n if (n == 0 && m == 0) println(\"0 0\")\n else if (n == 0) println(\"Impossible\")\n else println(min + \" \" + max)\n }\n}"}], "negative_code": [{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val Array(n, m) = in.next().split(' ').map(_.toInt)\n println((n, m) match {\n case(0, x) => \"Impossible\"\n case(x, 0) => s\"$x $x\"\n case(y, x) if y >= x => s\"$y ${y + x - 1}\"\n case(y, x) => s\"$x ${y + x - 1}\"\n })\n\n}"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val Array(n, m) = in.next().split(' ').map(_.toInt)\n println((n, m) match {\n case(0, x) => \"Impossible\"\n case(y, x) if y >= x => s\"$y ${y + x - 1}\"\n case(y, x) => s\"$x ${y + x - 1}\"\n })\n\n}"}, {"source_code": "//http://rextester.com scala 2.11.7\nimport scala.io.Source\nobject Rextester extends App{\n val in=Source.stdin.getLines();val Array(a,b)=in.next().split(' ').map(_.toInt)\n if(a>0&b>=0){\n var c=a+b-1\n if(b==0)c=a\n print(math.max(a,b)+\" \"+c)\n }\n else print(\"Impossible\")\n}"}, {"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 P190A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val N, M = sc.nextInt\n\n val res = (N, M) match {\n case (0, _) => \"Impossible\"\n case (x, 0) => List(x, x).mkString(\" \")\n case (x, y) => List(x max y, x + y - 1).mkString(\" \")\n }\n\n out.println(res)\n out.close\n}\n\n\n\n\n\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val Array(n, m) = readLine().split(\" \").map(_.toInt)\n val min = n + (m - n).max(0)\n val max = n + (m - 1).max(0)\n if (n == 0) println(\"Impossible\")\n else println(min + \" \" + max)\n }\n}"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val Array(n, m) = readLine().split(\" \").map(_.toInt)\n val min = n + (m - n).max(0)\n val max = n + m - 1\n if (n == 0) println(\"Impossible\")\n else println(min + \" \" + max)\n }\n}"}], "src_uid": "1e865eda33afe09302bda9077d613763"} {"nl": {"description": "A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.As before, the chessboard is a square-checkered board with the squares arranged in a 8 × 8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke.Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements.It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task.", "input_spec": "The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black. It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row).", "output_spec": "Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.", "sample_inputs": ["WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW", "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW"], "sample_outputs": ["3", "1"], "notes": null}, "positive_code": [{"source_code": "object P7A {\n def main(args : Array[String]) {\n val a = Array.fill(8){readLine}\n val af = a filter {_ != \"BBBBBBBB\"}\n val c = 0 until 8 count {n => af exists {_(n) == 'B'}}\n println(8 - af.size + c)\n }\n}"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val data = (1 to 8).map(_ => in.next())\n val lines = data.count(_.forall(_ == 'B'))\n val rows = data.find(_.exists(_ == 'W')).map(_.count(_ == 'B')).getOrElse(0)\n println(lines + rows)\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject A7Chess extends App {\n\n val scanner = new Scanner(System.in)\n\n val in = Array.ofDim[Cell](8, 8)\n\n var result = 0\n\n for (x <- 0 until 8) yield {\n val str = scanner.next()\n in(x) = str.map({\n case 'W' => Cell(color = false)\n case 'B' => Cell(color = true)\n }).toArray\n }\n\n (0 until 8) foreach(i => solve(in(_)(i)))\n (0 until 8) foreach(i => solve(in(i)(_)))\n\n println(result)\n\n def solve(function: (Int) => Cell): Unit = {\n if (paintedWithBlack(function)) {\n visit(function)\n result += 1\n }\n }\n\n def visit(function: (Int) => Cell): Unit = {\n (0 until 8).foreach(function(_).visited = true)\n }\n\n def paintedWithBlack(function: (Int) => Cell): Boolean = {\n (0 until 8).forall(function(_).color) && (0 until 8).exists(!function(_).visited)\n }\n\n case class Cell(color: Boolean, var visited: Boolean = false)\n\n}\n"}, {"source_code": "object A7 {\n\n import IO._\n import collection.{mutable => cu}\n\n def main(args: Array[String]): Unit = {\n val in = Array.fill(8)(read.toCharArray)\n val res = {\n (0 until 8).map{j => (0 until 8).map(i=>in(i)(j))}.count(_.forall(_ == 'B')) +\n in.count(_.forall(_ == 'B'))\n }\n if(res == 16)\n println(\"8\")\n else\n println(res)\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"}, {"source_code": "object P7A {\n def main(args : Array[String]) {\n val a = Array.fill(8){readLine}\n val af = a filter {_ != \"BBBBBBBB\"}\n val c = 0 until 8 count {n => af exists {_(n) == 'B'}}\n println(8 - af.size + c)\n }\n}"}, {"source_code": "object P7A {\n def main(args : Array[String]) {\n val a = Array.fill(8){readLine}\n val af = a filter {_ != \"BBBBBBBB\"}\n val c = 0 until 8 count {n => af exists {_(n) == 'B'}}\n println(8 - af.size + c)\n }\n}\n"}, {"source_code": "object P7A {\n def main(args : Array[String]) {\n val a = Array.fill(8){readLine} filter {_ != \"BBBBBBBB\"}\n val c = 0 until 8 count {n => a exists {_(n) == 'B'}}\n println(8 - a.size + c)\n }\n}\n"}], "negative_code": [{"source_code": "object P7A {\n def main(args : Array[String]) {\n val a = Array.fill(8){readLine}\n val af = a filter {_ != \"BBBBBBBB\"}\n val c = 0 until 8 count {n => af exists {_(n) == 'W'}}\n println(8 - af.size + c)\n }\n}"}, {"source_code": "object P7A {\n def main(args : Array[String]) {\n val a = Array.fill(8){readLine}\n val af = a filter {_ != \"BBBBBBBB\"}\n val c = 0 until 8 count {\n n : Int => af forall {_(n) == 'B'}\n }\n println(8 - af.size + c)\n }\n}\n"}, {"source_code": "object P7A {\n def main(args : Array[String]) {\n val a = Array.fill(8){readLine}\n val af = a filter {_ != \"BBBBBBBB\"}\n val c = 0 until 8 count {n => af exists {_(n) == 'W'}}\n println(8 - af.size + c)\n }\n}\n"}], "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0"} {"nl": {"description": "Count the number of distinct sequences a1, a2, ..., an (1 ≤ ai) consisting of positive integers such that gcd(a1, a2, ..., an) = x and . As this number could be large, print the answer modulo 109 + 7.gcd here means the greatest common divisor.", "input_spec": "The only line contains two positive integers x and y (1 ≤ x, y ≤ 109).", "output_spec": "Print the number of such sequences modulo 109 + 7.", "sample_inputs": ["3 9", "5 8"], "sample_outputs": ["3", "0"], "notes": "NoteThere are three suitable sequences in the first test: (3, 3, 3), (3, 6), (6, 3).There are no suitable sequences in the second test."}, "positive_code": [{"source_code": "object Main extends App {\n\n import scala.io.StdIn\n val MOD: Integer = 1000000007\n\n val Array(x, y) = StdIn.readLine().split(\" \").map(_.toInt)\n var mem = collection.mutable.Map[Integer, Integer]()\n\n if (y % x > 0) {\n println(0)\n }\n else {\n println(f(y/x))\n }\n\n\n\n def f(n: Integer): Integer = {\n\n if (n == 1) return 1\n\n if (mem contains(n))\n return mem(n)\n\n var res = pow2(n-1)\n\n for (d <- 2 to Math.round(Math.sqrt(1*n)).toInt)\n if (n % d == 0) {\n res = ((res - f(n / d))%MOD+MOD)%MOD\n if (d != n / d) res = ((res - f(d))%MOD+MOD)%MOD\n }\n res -= 1\n mem += n -> (res%MOD+MOD)%MOD\n mem(n)\n }\n\n def pow2(x: Integer): Integer = {\n x%2 match {\n case 0 if x > 0 => {\n val res = pow2(x/2)%MOD\n ((1l*res*res)%MOD).toInt\n }\n case 0 if x == 0 => 1\n case _ => {\n (2 * pow2(x-1) % MOD) % MOD\n }\n }\n }\n\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject UnusualSequencesJudgeSolution {\n class Lazy[A](x: => A) {\n lazy val value = x\n override def toString(): String = value.toString()\n }\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 val MOD: Long = 1000000007\n\n def main(args: Array[String]): Unit = {\n val sc = new Scanner(System.in)\n val (x, y) = (sc.nextInt, sc.nextInt)\n\n def count(L: Int): Long = {\n if (L <= 2) 1\n else {\n def pow(b: Long, p: Long): Long = {\n if (p == 0) 1L\n else if (p % 2 == 0) {\n val result = pow(b, p / 2);\n (result * result) % MOD\n }\n else (b * pow(b, p - 1)) % MOD\n }\n def divisors(x: Int): List[Int] = {\n def divisorsRec(d: Int): List[Int] = {\n if (1L * d * d > x) List.empty\n else if (x % d == 0) {\n if (d * d == x) d :: divisorsRec(d + 1)\n else d :: x / d :: divisorsRec(d + 1)\n }\n else divisorsRec(d + 1)\n }\n divisorsRec(1)\n }\n\n lazy val D: Int => Long = memoize (l => (pow(2, l - 1) - divisors(l).filter(_ != l).map(d => D(d)).foldLeft(0L)((x, sum) => (x + sum) % MOD) + MOD) % MOD)\n\n D(L)\n }\n }\n def solve(): Long = {\n if (y % x != 0) 0\n else {\n count(y / x)\n }\n }\n println(solve())\n }\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject UnusualSequencesJudgeSolution {\n val MOD: Long = 1000000007\n\n def main(args: Array[String]): Unit = {\n val sc = new Scanner(System.in)\n val (x, y) = (sc.nextInt, sc.nextInt)\n\n def count(L: Int): Long = {\n if (L <= 2) 1\n else {\n def pow(b: Long, p: Long): Long = {\n if (p == 0) 1L\n else if (p % 2 == 0) {\n val result = pow(b, p / 2);\n (result * result) % MOD\n }\n else (b * pow(b, p - 1)) % MOD\n }\n def divisors(x: Int): List[Int] = {\n def divisorsRec(d: Int): List[Int] = {\n if (1L * d * d > x) List.empty\n else if (x % d == 0) {\n if (d * d == x) d :: divisorsRec(d + 1)\n else d :: x / d :: divisorsRec(d + 1)\n }\n else divisorsRec(d + 1)\n }\n divisorsRec(1)\n }\n\n val DP = collection.mutable.Map[Int, Long]()\n def D(l: Int): Long = {\n if (DP.contains(l)) DP(l)\n else {\n val result = (pow(2, l - 1) - divisors(l).filter(_ != l).map(d => D(d)).foldLeft(0L)((x, sum) => (x + sum) % MOD) + MOD) % MOD\n DP.update(l, result)\n result\n }\n }\n\n D(L)\n }\n }\n def solve(): Long = {\n if (y % x != 0) 0\n else {\n count(y / x)\n }\n }\n println(solve())\n }\n}\n"}], "negative_code": [{"source_code": "object Main extends App {\n\n import scala.io.StdIn\n val MOD: Integer = 1000000007\n\n val Array(x, y) = StdIn.readLine().split(\" \").map(_.toInt)\n var mem = collection.mutable.Map[Integer, Integer]()\n\n if (y % x > 0) {\n println(0)\n }\n else {\n println(f(y/x))\n }\n\n\n\n def f(n: Integer): Integer = {\n\n if (mem contains(n))\n return mem(n)\n\n var res = pow2(n-1)\n\n for (d <- 2 to Math.round(Math.sqrt(1*n)).toInt)\n if (n % d == 0) {\n res = ((res - f(n / d))%MOD+MOD)%MOD\n if (d != n / d) res = ((res - f(d))%MOD+MOD)%MOD\n }\n res -= 1\n mem += n -> (res%MOD+MOD)%MOD\n mem(n)\n }\n\n def pow2(x: Integer): Integer = {\n x%2 match {\n case 0 if x > 0 => {\n val res = pow2(x/2)%MOD\n ((1l*res*res)%MOD).toInt\n }\n case 0 if x == 0 => 1\n case _ => {\n (2 * pow2(x-1) % MOD) % MOD\n }\n }\n }\n\n}\n"}, {"source_code": "\nimport java.util.Scanner\n\n\nobject UnusualSequences {\n val MOD: Long = 1000000007\n\n class Matrix (val M: Array[Array[Long]]) {\n val R = M.size\n val C = M(0).size\n def *(other: Matrix): Matrix = {\n val result = Array.tabulate(R, other.C)((r, c) => 0.until(C).map(x => M(r)(x) * other.M(x)(c)).sum)\n new Matrix(result)\n }\n def power(pow: Long): Matrix = {\n if (pow == 0) Matrix.getIdentity(R, C)\n else if (pow % 2 != 0) this * power(pow - 1)\n else {\n val result = power(pow / 2)\n result * result\n }\n }\n }\n object Matrix {\n def apply(M: Array[Array[Long]]) = new Matrix(M)\n def getIdentity(r: Int, c: Int) = {\n new Matrix(Array.tabulate(r, c)((i, j) => if (i == j) 1 else 0))\n }\n }\n\n def main(args: Array[String]): Unit = {\n val sc = new Scanner(System.in)\n val (x, y) = (sc.nextInt, sc.nextInt)\n\n def count(L: Int): Long = {\n if (L <= 2) 1\n else {\n val base = Matrix(Array(Array(1), Array(0), Array(1)))\n val matrix = Matrix(Array(Array(0, 1, 1), Array(1, 1, 0), Array(0, 0, 2)))\n\n val result = matrix.power(L - 1) * base\n result.M(0)(0)\n }\n }\n def solve(): Long = {\n if (y % x != 0) 0\n else {\n count(y / x)\n }\n }\n println(solve())\n }\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject UnusualSequencesJudgeSolution {\n val MOD: Long = 1000000007\n\n def main(args: Array[String]): Unit = {\n val sc = new Scanner(System.in)\n val (x, y) = (sc.nextInt, sc.nextInt)\n\n def count(L: Int): Long = {\n if (L <= 2) 1\n else {\n def pow(b: Long, p: Long): Long = {\n if (p == 0) 1\n else if (p % 2 == 0) {\n val result = pow(b, p / 2);\n (result * result) % MOD\n }\n else (b * pow(b, p - 1)) % MOD\n }\n def divisors(x: Int): List[Int] = {\n def divisorsRec(d: Int): List[Int] = {\n if (1L * d * d > x) List.empty\n else if (x % d == 0) {\n if (d * d == x) d :: divisorsRec(d + 1)\n else d :: x / d :: divisorsRec(d + 1)\n }\n else divisorsRec(d + 1)\n }\n divisorsRec(1)\n }\n\n val DP = collection.mutable.Map[Int, Long]()\n def D(l: Int): Long = {\n if (DP.contains(l)) DP(l)\n else {\n val result = pow(2, l - 1) - divisors(l).filter(_ != l).map(d => D(d)).foldLeft(0L)((x, sum) => (x + sum) % MOD)\n DP.update(l, result)\n result\n }\n }\n\n D(L)\n }\n }\n def solve(): Long = {\n if (y % x != 0) 0\n else {\n count(y / x)\n }\n }\n println(solve())\n }\n}\n"}], "src_uid": "de7731ce03735b962ee033613192f7bc"} {"nl": {"description": "There are three doors in front of you, numbered from $$$1$$$ to $$$3$$$ from left to right. Each door has a lock on it, which can only be opened with a key with the same number on it as the number on the door.There are three keys — one for each door. Two of them are hidden behind the doors, so that there is no more than one key behind each door. So two doors have one key behind them, one door doesn't have a key behind it. To obtain a key hidden behind a door, you should first unlock that door. The remaining key is in your hands.Can you open all the doors?", "input_spec": "The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 18$$$) — the number of testcases. The first line of each testcase contains a single integer $$$x$$$ ($$$1 \\le x \\le 3$$$) — the number on the key in your hands. The second line contains three integers $$$a, b$$$ and $$$c$$$ ($$$0 \\le a, b, c \\le 3$$$) — the number on the key behind each of the doors. If there is no key behind the door, the number is equal to $$$0$$$. Values $$$1, 2$$$ and $$$3$$$ appear exactly once among $$$x, a, b$$$ and $$$c$$$.", "output_spec": "For each testcase, print \"YES\" if you can open all the doors. Otherwise, print \"NO\".", "sample_inputs": ["4\n\n3\n\n0 1 2\n\n1\n\n0 3 2\n\n2\n\n3 1 0\n\n2\n\n1 3 0"], "sample_outputs": ["YES\nNO\nYES\nNO"], "notes": null}, "positive_code": [{"source_code": "import scala.io.StdIn._\r\nimport scala.util.control.Breaks._\r\n\r\nobject Main {\r\n def main(args: Array[String]): Unit = {\r\n val t: Int = readInt()\r\n for (_ <- 1 to t) {\r\n var curr_door: Int = readInt()\r\n val A: Array[Int] = readLine().split(\" \").map(_.toInt)\r\n var a: Boolean = true\r\n breakable {for (_ <- 1 to 3) {\r\n if (curr_door == 0) {\r\n a = false\r\n break\r\n }\r\n curr_door = A(curr_door-1)\r\n }}\r\n if (a) println(\"YES\") else println(\"NO\")\r\n }\r\n }\r\n}"}, {"source_code": "\r\n\r\nobject prob2 {\r\n def main(args: Array[String]) = {\r\n new Resolver3(Console.in, Console.out).run()\r\n }\r\n}\r\n\r\nclass Resolver3(input: java.io.BufferedReader, output: java.io.PrintStream) {\r\n\r\n import java.util.StringTokenizer\r\n import scala.collection.mutable\r\n import scala.collection.mutable._\r\n import scala.math.{abs,pow,min,max}\r\n import scala.collection.mutable.ListBuffer\r\n\r\n def run() {\r\n var tokenizer = new StringTokenizer(input.readLine())\r\n val q = tokenizer.nextToken().toInt\r\n for (sss <- 0 until q) {\r\n tokenizer = new StringTokenizer(input.readLine())\r\n val n = tokenizer.nextToken().toInt\r\n val A = new Array[Int](3)\r\n tokenizer = new StringTokenizer(input.readLine())\r\n A(0) = tokenizer.nextToken().toInt\r\n A(1) = tokenizer.nextToken().toInt\r\n A(2) = tokenizer.nextToken().toInt\r\n var t = false\r\n val a = A(n-1)\r\n if (a != 0) {\r\n val b = A(a-1)\r\n if (b!=0) {\r\n t = true\r\n }\r\n }\r\n if (t) {\r\n println(\"YES\")\r\n }\r\n else {\r\n println(\"NO\")\r\n }\r\n }\r\n }\r\n}"}], "negative_code": [], "src_uid": "5cd113a30bbbb93d8620a483d4da0349"} {"nl": {"description": "You are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and a ambidexters, who can play with left or right hand.The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.", "input_spec": "The only line contains three integers l, r and a (0 ≤ l, r, a ≤ 100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. ", "output_spec": "Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.", "sample_inputs": ["1 4 2", "5 5 5", "0 2 0"], "sample_outputs": ["6", "14", "0"], "notes": "NoteIn the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand."}, "positive_code": [{"source_code": "object aTask1 {\n import scala.io.StdIn.{readLine, readInt}\n def main(args: Array[String]):Unit = {\n val l::r::a::Nil = readLine.split(\" \").map(_.toInt).toList\n val p1 = math.min(l,r)\n val p2 = math.min(math.abs(l - r), a)\n val p3 = if (a - p2 >0) (a-p2)/2 else 0\n println((p1+p2+p3) * 2)\n }\n}"}, {"source_code": "object Solution {\n def main(args: Array[String]) {\n val sc = new java.util.Scanner(System.in)\n val l, r, a = sc.nextInt\n val u = a.min((r - l).abs)\n \n println(2 * (l.min(r) + u + (a - u)/2))\n }\n}"}, {"source_code": "object A extends App {\n val Array(l, r, a) = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n val d = (l max r) - (l min r)\n val t = a min d\n val s = (l min r) + t + (0 max (a - t)) / 2\n\n println(2 * s)\n}\n"}, {"source_code": "import java.io._\nimport java.util\nimport java.util.StringTokenizer\n\n\nobject Solution {\n // VM options: -Xmx1024m -Xss1024m\n private val inputFilename = \"input.txt\"\n private val outputFilename = \"output.txt\"\n\n def main(args: Array[String]): Unit = {\n new Solution(args.contains(\"DEBUG_MODE\")).run(args)\n }\n}\n\ncase class Solution(isDebug: Boolean) {\n def solve(): Unit = {\n var l = nextInt\n var r = nextInt\n var a = nextInt\n val addL = Math.max(0, Math.min(r - l, a))\n l += addL\n a -= addL\n val addR = Math.max(0, Math.min(l - r, a))\n r += addR\n a -= addR\n l += a / 2\n r += a / 2\n println(s\"${Math.min(l, r) * 2}\")\n }\n\n def run(args: Array[String]): Unit = {\n if (isDebug) {\n in = new BufferedReader(new InputStreamReader(new FileInputStream(Solution.inputFilename)))\n // in = new BufferedReader(new InputStreamReader(System.in))\n } else {\n in = new BufferedReader(new InputStreamReader(System.in))\n }\n out = new PrintWriter(System.out)\n // out = new PrintWriter(outputFilename)\n\n // val t = nextInt\n val t = 1\n (0 until t).foreach { i =>\n // out.print(s\"Case #${i + 1}: \")\n solve()\n }\n in.close()\n out.flush()\n out.close()\n }\n\n private var in: BufferedReader = _\n private var line: StringTokenizer = _\n private var out: PrintWriter = _\n\n private[this] def println(s: String = \"\"): Unit = out.println(s)\n\n private[this] def nextIntArray(n: Int) = (0 until n).map(_ => nextInt).toArray\n\n private[this] def nextLongArray(n: Int) = (0 until n).map(_ => nextLong).toArray\n\n private[this] def nextInt = nextToken.toInt\n\n private[this] def nextLong = nextToken.toLong\n\n private[this] def nextDouble = nextToken.toDouble\n\n private[this] def nextToken = {\n while (line == null || !line.hasMoreTokens) {\n line = new StringTokenizer(in.readLine)\n }\n line.nextToken\n }\n}"}], "negative_code": [], "src_uid": "e8148140e61baffd0878376ac5f3857c"} {"nl": {"description": "The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation code arrives.A young hacker Vasya disassembled the program and found the algorithm that transforms the shown number into the activation code. Note: it is clear that Vasya is a law-abiding hacker, and made it for a noble purpose — to show the developer the imperfection of their protection.The found algorithm looks the following way. At first the digits of the number are shuffled in the following order <first digit><third digit><fifth digit><fourth digit><second digit>. For example the shuffle of 12345 should lead to 13542. On the second stage the number is raised to the fifth power. The result of the shuffle and exponentiation of the number 12345 is 455 422 043 125 550 171 232. The answer is the 5 last digits of this result. For the number 12345 the answer should be 71232.Vasya is going to write a keygen program implementing this algorithm. Can you do the same?", "input_spec": "The only line of the input contains a positive integer five digit number for which the activation code should be found.", "output_spec": "Output exactly 5 digits without spaces between them — the found activation code of the program.", "sample_inputs": ["12345"], "sample_outputs": ["71232"], "notes": null}, "positive_code": [{"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 s = in.nextLine()\n\n val t = \"\" + s(0) + s(2) + s(4) + s(3) + s(1)\n\n val x = BigInt(t)\n val y = (x * x * x * x * x).toString()\n\n println(y.substring(y.length() - 5))\n }\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject CrackingTheCode {\n\n def main(args: Array[String]) {\n val MOD = 100000\n val n = StdIn.readLong()\n val res = Array(n / 10000, (n / 100) % 10, n % 10, (n / 10) % 10, (n / 1000) % 10)\n val k = res(0) * 10000 + res(1) * 1000 + res(2) * 100 + res(3) * 10 + res(4)\n def pow(n : Int) : Long = {\n if (n == 0) 1\n else (k * pow(n - 1)) % MOD\n }\n println(\"%05d\".format(pow(5)))\n }\n\n}\n"}], "negative_code": [{"source_code": "import scala.io.StdIn\n\nobject CrackingTheCode {\n\n def main(args: Array[String]) {\n val MOD = 100000\n val n = StdIn.readLong()\n val res = Array(n / 10000, (n / 100) % 10, n % 10, (n / 10) % 10, (n / 1000) % 10)\n val k = res(0) * 10000 + res(1) * 1000 + res(2) * 100 + res(3) * 10 + res(4)\n def pow(n : Int) : Long = {\n if (n == 0) 1\n else (k * pow(n - 1)) % MOD\n }\n println(pow(5))\n }\n\n}\n"}], "src_uid": "51b1c216948663fff721c28d131bf18f"} {"nl": {"description": "Polycarpus has postcards and photos hung in a row on the wall. He decided to put them away to the closet and hang on the wall a famous painter's picture. Polycarpus does it like that: he goes from the left to the right and removes the objects consecutively. As Polycarpus doesn't want any mix-ups to happen, he will not carry in his hands objects of two different types. In other words, Polycarpus can't carry both postcards and photos simultaneously. Sometimes he goes to the closet and puts the objects there, thus leaving his hands free. Polycarpus must put all the postcards and photos to the closet. He cannot skip objects. What minimum number of times he should visit the closet if he cannot carry more than 5 items?", "input_spec": "The only line of the input data contains a non-empty string consisting of letters \"С\" and \"P\" whose length does not exceed 100 characters. If the i-th character in the string is the letter \"С\", that means that the i-th object (the numbering goes from the left to the right) on Polycarpus' wall is a postcard. And if the i-th character is the letter \"P\", than the i-th object on the wall is a photo.", "output_spec": "Print the only number — the minimum number of times Polycarpus has to visit the closet.", "sample_inputs": ["CPCPCPC", "CCCCCCPPPPPP", "CCCCCCPPCPPPPPPPPPP", "CCCCCCCCCC"], "sample_outputs": ["7", "4", "6", "2"], "notes": "NoteIn the first sample Polycarpus needs to take one item to the closet 7 times.In the second sample Polycarpus can first take 3 postcards to the closet; then 3 more. He can take the 6 photos that are left in the similar way, going to the closet twice.In the third sample Polycarpus can visit the closet twice, both times carrying 3 postcards. Then he can take there 2 photos at once, then one postcard and finally, he can carry the last 10 photos if he visits the closet twice.In the fourth sample Polycarpus can visit the closet twice and take there all 10 postcards (5 items during each go)."}, "positive_code": [{"source_code": "import scala.collection.mutable.ArrayBuffer\n\nobject Flask {\n def main(args: Array[String]): Unit = {\n var s = readLine\n var total = 0\n var symbol = s(0); var count = 1\n \n (1 until s.size).foreach(i => {\n if (s(i) == symbol && count < 5) count += 1\n else { count = 1; symbol = s(i); total += 1 }\n })\n println(total + 1)\n }\n}\n"}, {"source_code": "object main {\n def main(args: Array[String]) = {\n val str = readLine()\n \n var last:Char = str apply 0\n var n = 0\n var res = 0\n \n \n str foreach ((x:Char) => {\n if (last == x) {\n if (n == 5) {\n n = 1\n res += 1\n } else {\n n += 1\n }\n } else {\n if (n != 0) {\n res += 1\n } \n n = 1\n last = x\n \n }\n })\n \n println(res + 1)\n }\n}"}, {"source_code": "object P137A extends App {\n \n println(readLine.foldLeft((0,0,'x'))((t,c) => if (t._3 != c) (t._1+1,1,c) else (if(t._2 == 5) (t._1+1,1,c) else (t._1,t._2+1,c))) _1)\n\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val str = in.next()\n val res = str.tail.foldLeft((0, 1, str.head)) {\n case ((count, soFar, prev), el) if soFar == 5 => (count + 1, 1, el)\n case ((count, soFar, prev), el) if el == prev => (count, soFar + 1, el)\n case ((count, soFar, prev), el) => (count + 1, 1, el)\n }\n println(res._1 + (if (res._2 != 0) 1 else 0))\n}"}, {"source_code": "object A137 {\n\n import IO._\n import collection.{mutable => cu}\n\n def main(args: Array[String]): Unit = {\n val str = read\n var res = 0\n var curr = 1\n for(i <- 1 to str.length) {\n if(i == str.length || str(i) != str(i-1)) {\n res += (curr+4)/5\n curr = 1\n } else {\n curr += 1\n }\n }\n out.println(res)\n out.close()\n }\n\n object IO {\n private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n // private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(\"src/input\")))\n val out = new java.io.PrintWriter(System.out)\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"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P137A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n val CP = sc.nextLine.toList\n\n def solve(): Int = {\n\n @tailrec\n def loop(n: Int, carry: List[Char], wall: List[Char]): Int = (carry, wall) match {\n case (_, Nil) => n\n case (Nil, y :: ys) => loop(n, y :: Nil, ys)\n case (xs, ys) if xs.size == 5 => loop(n + 1, Nil, ys)\n case (x :: xs, y :: ys) if x == y => loop(n, y :: x :: xs, ys)\n case (x :: xs, y :: ys) if x != y => loop(n + 1, y :: Nil, ys)\n }\n\n loop(0, Nil, CP) + 1\n }\n\n out.println(solve)\n out.close\n}\n"}, {"source_code": "object A137 {\n\tdef main(args: Array[String]) {\n\t\tval s: String = readLine\n\t\tvar res: Int = 0\n\t\tvar curc: Char = '?'\n\t\tvar curval: Int = 5\n\t\tfor (c <- s)\n\t\t\tif (c == curc && curval < 5)\n\t\t\t\tcurval += 1\n\t\t\telse {\n\t\t\t\tres += 1\n\t\t\t\tcurval = 1\n\t\t\t\tcurc = c\n\t\t\t}\n\t\tprintln(res)\n\t}\n}"}, {"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 def readLine = reader.readLine\n\n def calc(str: String): Double = {\n if(str.length == 0) 0\n else {\n val ch = str.head\n Math.ceil(0.2 * str.takeWhile(_ == ch).length) + calc(str.dropWhile(_ == ch))\n }\n }\n def ans = calc(readLine)\n\n def main(a: Array[String]) {\n println(ans.round)\n }\n}\n"}, {"source_code": "object Main {\n def main(args: Array[String]) = {\n val s = readLine()\n \n var cur = ' '\n var inHands = 0\n var count = 0\n s.foreach{ c => \n if (c != cur) {\n inHands = 0\n count += 1\n cur = c\n } else if (inHands == 5) {\n count += 1\n inHands = 0\n }\n inHands += 1\n }\n println(count)\n }\n}"}], "negative_code": [{"source_code": "object main {\n\tdef main(args: Array[String]) = {\n\t\tval str = readLine()\n\t\t\n\t\tvar last:Char = str apply 0\n\t\tvar n = 0\n\t\tvar res = 1\n\t\t\n\t\t\n\t\tstr foreach ((x:Char) => {\n\t\t\tif (last == x) {\n\t\t\t\tif (n == 5) {\n\t\t\t\t\tn = 0\n\t\t\t\t\tres += 1\n\t\t\t\t} else {\n\t\t\t\t\tn += 1\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (n != 0) {\n\t\t\t\t\tres += 1\n\t\t\t\t}\n\t\t\t\tn += 1\n\t\t\t\tlast = x\n\t\t\t \n\t\t\t}\n\t\t})\n\t\t\n\t\tprintln(res)\n\t}\n}"}, {"source_code": "object main {\n def main(args: Array[String]) = {\n val str = readLine()\n \n var last:Char = str apply 0\n var n = 0\n var res = 0\n \n \n str foreach ((x:Char) => {\n if (last == x) {\n if (n == 5) {\n n = 1\n res += 1\n } else {\n n += 1\n }\n } else {\n if (n != 0) {\n res += 1\n }\n n += 1\n last = x\n \n }\n })\n \n println(res + 1)\n }\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val str = in.next()\n val res = str.tail.foldLeft((0, 0, str.head)) {\n case ((count, soFar, prev), el) if soFar == 5 => (count + 1, 1, el)\n case ((count, soFar, prev), el) if el == prev => (count, 1, el)\n case ((count, soFar, prev), el) => (count + 1, 1, el)\n }\n println(res._1 + (if (res._2 != 0) 1 else 0))\n}"}], "src_uid": "5257f6b50f5a610a17c35a47b3a0da11"} {"nl": {"description": "Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.", "input_spec": "The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces into which the delivered pizza was cut. The second line contains n integers ai (1 ≤ ai ≤ 360)  — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.", "output_spec": "Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.", "sample_inputs": ["4\n90 90 90 90", "3\n100 100 160", "1\n360", "4\n170 30 150 10"], "sample_outputs": ["0", "40", "360", "0"], "notes": "NoteIn first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.Picture explaning fourth sample:Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector."}, "positive_code": [{"source_code": "\nimport java.util.Scanner\nimport scala.language.implicitConversions\n\nobject PizzaSeparation {\n\n class Lazy[A](x: => A) {\n lazy val value = x\n override def toString(): String = value.toString()\n }\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\n def main(args: Array[String]): Unit = {\n val sc = new Scanner(System.in)\n\n val N = sc.nextInt()\n val A = for (i <- 0.until(N)) yield sc.nextInt()\n\n def bestPrefix(xs: List[Int], s: Int): Int = xs match {\n case Nil => 360\n case x :: rest => val ns = s + x; Math.min(Math.abs(360 - 2 * ns), bestPrefix(rest, ns))\n }\n\n def solve(xs: List[Int]): Int = xs match {\n case Nil => 360\n case x :: rest => Math.min(bestPrefix(xs, 0), solve(rest))\n }\n\n println(solve(A.toList))\n }\n}"}, {"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) = readIntLine()\n val widths = readIntLine()\n\n val sum = Array.ofDim[Int](widths.length, widths.length + 1)\n\n for (i <- widths.indices) {\n for (j <- i + 1 to widths.length) {\n sum(i)(j) = sum(i)(j - 1) + widths(j - 1)\n }\n }\n\n val minDiff = widths.indices.map{\n i =>\n (i + 1 to widths.length).map{\n j =>\n Math.abs(180 - sum(i)(j)) * 2\n }.min\n }.min\n\n println(minDiff)\n }\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}"}, {"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 val as = readInts(n)\n\n var min = 360\n\n for {\n i <- 0 until n\n j <- i to n\n } {\n val s1 = as.view(i, j).sum\n val s2 = 360 - s1\n val d = Math.abs(s1 - s2)\n if (d < min) min = d\n }\n\n println(min)\n}\n"}, {"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(n) = readInts(1)\n val as = readInts(n)\n\n var min = 360\n var s1 = 0\n var l, r = 0\n\n def check(s1: Int) = {\n val s2 = 360 - s1\n val d = Math.abs(s1 - s2)\n if (d < min) min = d\n }\n\n while (r < n) {\n while (s1 < 180 && r < n) {\n s1 += as(r)\n r += 1\n check(s1)\n }\n while (s1 >= 180) {\n s1 -= as(l)\n l += 1\n check(s1)\n }\n }\n\n println(min)\n}\n"}], "negative_code": [{"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(n) = readInts(1)\n val as = readInts(n)\n\n var min = 360\n var s1 = 0\n var l, r = 0\n\n def check(s1: Int) = {\n val s2 = 360 - s1\n val d = Math.abs(s1 - s2)\n if (d < min) min = d\n }\n\n while (r < n) {\n while (s1 < 180 && r < n) {\n s1 += as(r)\n r += 1\n }\n check(s1)\n while (s1 >= 180) {\n s1 -= as(l)\n l += 1\n }\n check(s1)\n }\n\n println(min)\n}\n"}], "src_uid": "1b6a6aff81911865356ec7cbf6883e82"} {"nl": {"description": "Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 and 16, inclusive. <hostname> — is a sequence of word separated by periods (characters «.»), where each word should contain only characters allowed for <username>, the length of each word is between 1 and 16, inclusive. The length of <hostname> is between 1 and 32, inclusive. <resource> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <resource> is between 1 and 16, inclusive. The content of square brackets is optional — it can be present or can be absent.There are the samples of correct Jabber IDs: mike@codeforces.com, 007@en.codeforces.com/contest.Your task is to write program which checks if given string is a correct Jabber ID.", "input_spec": "The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive.", "output_spec": "Print YES or NO.", "sample_inputs": ["mike@codeforces.com", "john.smith@codeforces.ru/contest.icpc/12"], "sample_outputs": ["YES", "NO"], "notes": null}, "positive_code": [{"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n\n def isGood(str: String) = {\n str.length >= 1 && str.length <= 16 && str.forall(ch => (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9') || ch == '_')\n }\n\n if (line.split(\"@\", -1) match {\n case Array(first, second) if isGood(first) =>\n second.split(\"/\", -1) match {\n case Array(hostname, resource) =>\n hostname.split(\"\\\\.\", -1).forall(isGood) && isGood(resource) && hostname.length <= 32\n case Array(hostname) =>\n hostname.split(\"\\\\.\", -1).forall(isGood)\n case _ => false\n }\n case _ => false\n })\n println(\"YES\")\n else\n println(\"NO\")\n}\n"}, {"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 user = next\n if (user.split(\"@\").length != 2 || user.endsWith(\"@\")) {\n out.println(\"NO\")\n return 1\n }\n val name = user.split(\"@\")(0)\n if (name.length <= 0 || name.length > 16) {\n out.println(\"NO\")\n return 1\n }\n val part2 = user.split(\"@\")(1)\n val allow = \"QWERTYUIOPASDFGHJKLZXCVBNMabcdefghijklmnopqrstuvwxyz1234567890_\".toCharArray\n if (name.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (part2.split(\"/\")(0).length <= 0 || part2.split(\"/\")(0).length > 32) {\n out.println(\"NO\")\n return 1\n }\n\n val hosts = part2.split(\"/\")(0).split(\"\\\\.\")\n if (part2.split(\"/\")(0).startsWith(\".\") || part2.split(\"/\")(0).endsWith(\".\")) {\n out.println(\"NO\")\n return 1\n }\n if (part2.split(\"/\")(0).contains(\".\") && hosts.length == 0) {\n out.println(\"NO\")\n return 1\n }\n for (i <- 0 until hosts.length) {\n if (hosts(i).filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (hosts(i).length <= 0 || hosts(i).length > 16) {\n out.println(\"NO\")\n return 1\n }\n }\n\n if (part2.split(\"/\").length > 1) {\n val res = part2.split(\"/\")(1)\n if (res.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n }\n if (user.endsWith(\"/\")) {\n out.println(\"NO\")\n return 1\n }\n out.println(\"YES\")\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}"}], "negative_code": [{"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n\n def isGood(str: String) = {\n str.length >= 1 && str.length <= 16 && str.forall(ch => (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9') || ch == '_')\n }\n\n if (line.split('@') match {\n case Array(first, second) if isGood(first) =>\n second.split(\"/\", -1) match {\n case Array(hostname, resource) =>\n hostname.split(\"\\\\.\", -1).forall(isGood) && isGood(resource) && hostname.length <= 32\n case Array(hostname) =>\n hostname.split(\"\\\\.\", -1).forall(isGood)\n case _ => false\n }\n case _ => false\n })\n println(\"YES\")\n else\n println(\"NO\")\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n\n def isGood(str: String) = {\n str.length >= 1 && str.length <= 16 && str.forall(ch => (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9') || ch == '_')\n }\n\n if (line.split('@') match {\n case Array(first, second) if isGood(first) =>\n second.split('/') match {\n case Array(hostname, resource) =>\n hostname.split('.').forall(isGood) && isGood(resource) && hostname.length <= 32\n case Array(hostname) =>\n hostname.split('.').forall(isGood)\n case _ => false\n }\n case _ => false\n })\n println(\"YES\")\n else\n println(\"NO\")\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n\n def isGood(str: String) = {\n str.length >= 1 && str.length <= 16 && str.forall(ch => (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9') || ch == '_')\n }\n\n if (line.split('@') match {\n case Array(first, second) if isGood(first) =>\n second.split('/') match {\n case Array(hostname, resource) =>\n hostname.split(\"\\\\.\", -1).forall(isGood) && isGood(resource) && hostname.length <= 32\n case Array(hostname) =>\n hostname.split(\"\\\\.\", -1).forall(isGood)\n case _ => false\n }\n case _ => false\n })\n println(\"YES\")\n else\n println(\"NO\")\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n\n def isGood(str: String) = {\n str.length >= 1 && str.length <= 16 && str.forall(ch => (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9') || ch == '_')\n }\n\n if (line.split('@') match {\n case Array(first, second) =>\n second.split('/') match {\n case Array(hostname, resource) =>\n hostname.split('.').forall(isGood) && isGood(resource) && hostname.length <= 32\n case Array(hostname) =>\n hostname.split('.').forall(isGood)\n case _ => false\n }\n case _ => false\n })\n println(\"YES\")\n else\n println(\"NO\")\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n\n def isGood(str: String) = {\n str.length >= 1 && str.length <= 16 && str.forall(ch => (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9') || ch == '_')\n }\n\n if (line.split('@') match {\n case Array(first, second) =>\n second.split('/') match {\n case Array(hostname, resource) =>\n hostname.split('.').forall(isGood) && isGood(resource) && hostname.length <= 32\n case Array(hostname) =>\n println(\"HERE\")\n hostname.split('.').forall(isGood)\n case _ => false\n }\n case _ => false\n })\n println(\"YES\")\n else\n println(\"NO\")\n}\n"}, {"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 user = next\n if (user.split(\"@\").length != 2) {\n out.println(\"NO\")\n return 1\n }\n\n val name = user.split(\"@\")(0)\n if (name.length <= 0 || name.length > 16) {\n out.println(\"NO\")\n return 1\n }\n val part2 = user.split(\"@\")(1)\n val allow = \"abcdefghijklmnopqrstuvwxyz1234567890_\".toCharArray\n if (name.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (part2.split(\"\\\\\\\\\")(0).length <= 0 || part2.split(\"\\\\\\\\\")(0).length > 32) {\n out.println(\"NO\")\n return 1\n }\n\n val hosts = part2.split(\"\\\\\\\\\")(0).split(\".\")\n for (i <- 0 until hosts.length) {\n if (hosts(i).filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (hosts(i).length <= 0 || hosts(i).length > 16) {\n out.println(\"NO\")\n return 1\n }\n }\n\n if (part2.split(\"\\\\\\\\\").length > 1) {\n val res = part2.split(\"\\\\\\\\\")(1)\n if (res.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n }\n out.println(\"YES\")\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"}, {"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 user = next\n if (user.split(\"@\").length != 2) {\n out.println(\"NO\")\n return 1\n }\n val name = user.split(\"@\")(0)\n if (name.length <= 0 || name.length > 16) {\n out.println(\"NO\")\n return 1\n }\n val part2 = user.split(\"@\")(1)\n val allow = \"QWERTYUIOPASDFGHJKLZXCVBNMabcdefghijklmnopqrstuvwxyz1234567890_\".toCharArray\n if (name.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (part2.split(\"/\")(0).length <= 0 || part2.split(\"/\")(0).length > 32) {\n out.println(\"NO\")\n return 1\n }\n\n val hosts = part2.split(\"/\")(0).split(\"\\\\.\")\n if (part2.startsWith(\".\") || (part2.endsWith(\".\"))) {\n out.println(\"NO\")\n return 1\n }\n if (part2.split(\"/\")(0).contains(\".\") && hosts.length == 0) {\n out.println(\"NO\")\n return 1\n }\n for (i <- 0 until hosts.length) {\n if (hosts(i).filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (hosts(i).length <= 0 || hosts(i).length > 16) {\n out.println(\"NO\")\n return 1\n }\n }\n\n if (part2.split(\"/\").length > 1) {\n val res = part2.split(\"/\")(1)\n if (res.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n }\n if (user.endsWith(\"/\")) {\n out.println(\"NO\")\n return 1\n }\n out.println(\"YES\")\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}"}, {"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 user = next\n if (user.split(\"@\").length != 2) {\n out.println(\"NO\")\n return 1\n }\n val name = user.split(\"@\")(0)\n if (name.length <= 0 || name.length > 16) {\n out.println(\"NO\")\n return 1\n }\n val part2 = user.split(\"@\")(1)\n val allow = \"QWERTYUIOPASDFGHJKLZXCVBNMabcdefghijklmnopqrstuvwxyz1234567890_\".toCharArray\n if (name.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (part2.split(\"/\")(0).length <= 0 || part2.split(\"/\")(0).length > 32) {\n out.println(\"NO\")\n return 1\n }\n\n val hosts = part2.split(\"/\")(0).split(\"\\\\.\")\n if (part2.split(\"/\")(0).startsWith(\".\") || part2.split(\"/\")(0).endsWith(\".\")) {\n out.println(\"NO\")\n return 1\n }\n if (part2.split(\"/\")(0).contains(\".\") && hosts.length == 0) {\n out.println(\"NO\")\n return 1\n }\n for (i <- 0 until hosts.length) {\n if (hosts(i).filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (hosts(i).length <= 0 || hosts(i).length > 16) {\n out.println(\"NO\")\n return 1\n }\n }\n\n if (part2.split(\"/\").length > 1) {\n val res = part2.split(\"/\")(1)\n if (res.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n }\n if (user.endsWith(\"/\")) {\n out.println(\"NO\")\n return 1\n }\n out.println(\"YES\")\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}"}, {"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 user = next\n if (user.split(\"@\").length != 2) {\n out.println(\"NO\")\n return 1\n }\n val name = user.split(\"@\")(0)\n if (name.length <= 0 || name.length > 16) {\n out.println(\"NO\")\n return 1\n }\n val part2 = user.split(\"@\")(1)\n val allow = \"QWERTYUIOPASDFGHJKLZXCVBNMabcdefghijklmnopqrstuvwxyz1234567890_\".toCharArray\n if (name.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (part2.split(\"/\")(0).length <= 0 || part2.split(\"/\")(0).length > 32) {\n out.println(\"NO\")\n return 1\n }\n\n val hosts = part2.split(\"/\")(0).split(\".\")\n for (i <- 0 until hosts.length) {\n if (hosts(i).filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (hosts(i).length <= 0 || hosts(i).length > 16) {\n out.println(\"NO\")\n return 1\n }\n }\n\n if (part2.split(\"/\").length > 1) {\n val res = part2.split(\"/\")(1)\n if (res.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n }\n if (user.endsWith(\"/\")) {\n out.println(\"NO\")\n return 1\n }\n out.println(\"YES\")\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}"}, {"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 user = next\n if (user.split(\"@\").length != 2) {\n out.println(\"NO\")\n return 1\n }\n val name = user.split(\"@\")(0)\n if (name.length <= 0 || name.length > 16) {\n out.println(\"NO\")\n return 1\n }\n val part2 = user.split(\"@\")(1)\n val allow = \"QWERTYUIOPASDFGHJKLZXCVBNMabcdefghijklmnopqrstuvwxyz1234567890_\".toCharArray\n if (name.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (part2.split(\"/\")(0).length <= 0 || part2.split(\"/\")(0).length > 32) {\n out.println(\"NO\")\n return 1\n }\n\n val hosts = part2.split(\"/\")(0).split(\".\")\n if (part2.startsWith(\".\") || (part2.endsWith(\".\"))) {\n out.println(\"NO\")\n return 1\n }\n if (part2.split(\"/\")(0).contains(\".\") && hosts.length == 0) {\n out.println(\"NO\")\n return 1\n }\n for (i <- 0 until hosts.length) {\n if (hosts(i).filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (hosts(i).length <= 0 || hosts(i).length > 16) {\n out.println(\"NO\")\n return 1\n }\n }\n\n if (part2.split(\"/\").length > 1) {\n val res = part2.split(\"/\")(1)\n if (res.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n }\n if (user.endsWith(\"/\")) {\n out.println(\"NO\")\n return 1\n }\n out.println(\"YES\")\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}"}, {"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 user = next\n if (user.split(\"@\").length != 2) {\n out.println(\"NO\")\n return 1\n }\n val name = user.split(\"@\")(0)\n if (name.length <= 0 || name.length > 16) {\n out.println(\"NO\")\n return 1\n }\n val part2 = user.split(\"@\")(1)\n val allow = \"QWERTYUIOPASDFGHJKLZXCVBNMabcdefghijklmnopqrstuvwxyz1234567890_\".toCharArray\n if (name.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (part2.split(\"/\")(0).length <= 0 || part2.split(\"/\")(0).length > 32) {\n out.println(\"NO\")\n return 1\n }\n\n val hosts = part2.split(\"/\")(0).split(\".\")\n if (part2.startsWith(\".\") || (part2.endsWith(\".\"))) {\n out.println(\"NO\")\n return 1\n }\n for (i <- 0 until hosts.length) {\n if (hosts(i).filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (hosts(i).length <= 0 || hosts(i).length > 16) {\n out.println(\"NO\")\n return 1\n }\n }\n\n if (part2.split(\"/\").length > 1) {\n val res = part2.split(\"/\")(1)\n if (res.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n }\n if (user.endsWith(\"/\")) {\n out.println(\"NO\")\n return 1\n }\n out.println(\"YES\")\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}"}, {"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 user = next\n if (user.split(\"@\").length != 2) {\n out.println(\"NO\")\n return 1\n }\n val name = user.split(\"@\")(0)\n if (name.length <= 0 || name.length > 16) {\n out.println(\"NO\")\n return 1\n }\n val part2 = user.split(\"@\")(1)\n val allow = \"QWERTYUIOPASDFGHJKLZXCVBNMabcdefghijklmnopqrstuvwxyz1234567890_\".toCharArray\n if (name.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (part2.split(\"/\")(0).length <= 0 || part2.split(\"/\")(0).length > 32) {\n out.println(\"NO\")\n return 1\n }\n\n val hosts = part2.split(\"/\")(0).split(\".\")\n if (part2.startsWith(\".\")) {\n out.println(\"NO\")\n return 1\n }\n for (i <- 0 until hosts.length) {\n if (hosts(i).filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (hosts(i).length <= 0 || hosts(i).length > 16) {\n out.println(\"NO\")\n return 1\n }\n }\n\n if (part2.split(\"/\").length > 1) {\n val res = part2.split(\"/\")(1)\n if (res.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n }\n if (user.endsWith(\"/\")) {\n out.println(\"NO\")\n return 1\n }\n out.println(\"YES\")\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}"}, {"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 user = next\n if (user.split(\"@\").length != 2) {\n out.println(\"NO\")\n return 1\n }\n val name = user.split(\"@\")(0)\n if (name.length <= 0 || name.length > 16) {\n out.println(\"NO\")\n return 1\n }\n val part2 = user.split(\"@\")(1)\n val allow = \"abcdefghijklmnopqrstuvwxyz1234567890_\".toCharArray\n if (name.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (part2.split(\"/\")(0).length <= 0 || part2.split(\"/\")(0).length > 32) {\n out.println(\"NO\")\n return 1\n }\n\n val hosts = part2.split(\"/\")(0).split(\".\")\n for (i <- 0 until hosts.length) {\n if (hosts(i).filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (hosts(i).length <= 0 || hosts(i).length > 16) {\n out.println(\"NO\")\n return 1\n }\n }\n\n if (part2.split(\"/\").length > 1) {\n val res = part2.split(\"/\")(1)\n if (res.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n }\n if (user.endsWith(\"/\")) {\n out.println(\"NO\")\n return 1\n }\n out.println(\"YES\")\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}"}, {"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 user = next\n if (user.split(\"@\").length != 2) {\n out.println(\"NO\")\n return 1\n }\n\n val name = user.split(\"@\")(0)\n if (name.length <= 0 || name.length > 16) {\n out.println(\"NO\")\n return 1\n }\n val part2 = user.split(\"@\")(1)\n val allow = \"QWERTYUIOPASDFGHJKLZXCVBNMabcdefghijklmnopqrstuvwxyz1234567890_\".toCharArray\n val filter: String = name.filter(x => allow.contains(x))\n if (filter.length != name.length) {\n out.println(\"NO\")\n return 1\n }\n if (part2.split(\"\\\\\\\\\")(0).length <= 0 || part2.split(\"\\\\\\\\\")(0).length > 32) {\n out.println(\"NO\")\n return 1\n }\n\n val hosts = part2.split(\"\\\\\\\\\")(0).split(\".\")\n for (i <- 0 until hosts.length) {\n val filter1: String = hosts(i).filter(x => allow.contains(x))\n if (filter1.length != hosts(i).length) {\n out.println(\"NO\")\n return 1\n }\n if (hosts(i).length <= 0 || hosts(i).length > 16) {\n out.println(\"NO\")\n return 1\n }\n }\n\n if (part2.split(\"\\\\\\\\\").length > 1) {\n val res = part2.split(\"\\\\\\\\\")(1)\n val filter1: String = res.filter(x => allow.contains(x))\n if (filter1.length != res.length) {\n out.println(\"NO\")\n return 1\n }\n }\n out.println(\"YES\")\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"}, {"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 user = next\n if (user.split(\"@\").length != 2) {\n out.println(\"NO\")\n return 1\n }\n\n val name = user.split(\"@\")(0)\n if (name.length <= 0 || name.length > 16) {\n out.println(\"NO\")\n return 1\n }\n val part2 = user.split(\"@\")(1)\n val allow = \"QWERTYUIOPASDFGHJKLZXCVBNMabcdefghijklmnopqrstuvwxyz1234567890_\".toCharArray\n if (name.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (part2.split(\"\\\\\\\\\")(0).length <= 0 || part2.split(\"\\\\\\\\\")(0).length > 32) {\n out.println(\"NO\")\n return 1\n }\n\n val hosts = part2.split(\"\\\\\\\\\")(0).split(\".\")\n for (i <- 0 until hosts.length) {\n if (hosts(i).filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n if (hosts(i).length <= 0 || hosts(i).length > 16) {\n out.println(\"NO\")\n return 1\n }\n }\n\n if (part2.split(\"\\\\\\\\\").length > 1) {\n val res = part2.split(\"\\\\\\\\\")(1)\n if (res.filter(x => !allow.contains(x)).length > 0) {\n out.println(\"NO\")\n return 1\n }\n }\n out.println(\"YES\")\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": "2a68157e327f92415067f127feb31e24"} {"nl": {"description": "Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.", "input_spec": "The first and only line of input contains a single string in the format hh:mm (00 ≤  hh  ≤ 23, 00 ≤  mm  ≤ 59).", "output_spec": "Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.", "sample_inputs": ["05:39", "13:31", "23:59"], "sample_outputs": ["11", "0", "1"], "notes": "NoteIn the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome."}, "positive_code": [{"source_code": "import java.util.Scanner\n\n/**\n * Created by pinguinson on 6/17/2017.\n */\nobject A extends App {\n val sc = new Scanner(System.in)\n val palindromes = Seq(\n ( 0, 0),\n ( 1,10),\n ( 2,20),\n ( 3,30),\n ( 4,40),\n ( 5,50),\n //6\n //7\n //8\n //9\n (10, 1),\n (11,11),\n (12,21),\n (13,31),\n (14,41),\n (15,51),\n //16\n //17\n //18\n //19\n (20, 2),\n (21,12),\n (22,22),\n (23,32))\n val s = sc.next()\n val h = s.substring(0, 2).toInt\n val m = s.substring(3, 5).toInt\n val togo = palindromes.find {\n case (hour, minute) =>\n (hour > h) ||\n ((hour == h) && (minute >= m))\n } match {\n case Some((hr, min)) => (hr - h) * 60 + (min - m)\n case None => (23 - h) + (60 - m)\n }\n println(togo)\n}\n"}, {"source_code": "object _816A 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 var Array(hh, mm) = read[String].split(':').map(_.toInt)\n var ans = 0\n while(!isPalindrome(hh, mm)) {\n val (nh, nm) = next(hh, mm)\n hh = nh\n mm = nm\n ans += 1\n }\n write(ans)\n }\n\n def pad(x: Int) = if (x < 10) s\"0$x\" else x.toString\n\n def isPalindrome(hh: Int, mm: Int) = {\n val t = s\"${pad(hh)}:${pad(mm)}\"\n t == t.reverse\n }\n\n def next(hh: Int, mm: Int) = {\n if (mm == 59) {\n ((hh + 1)%24, 0)\n } else {\n (hh, mm + 1)\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}\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"}], "negative_code": [{"source_code": "import java.util.Scanner\n\n/**\n * Created by pinguinson on 6/17/2017.\n */\nobject A extends App {\n val sc = new Scanner(System.in)\n val palindromes = Seq((0,0),(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (10, 1), (11, 11), (12,21),(13,31), (14,41),(15,51),(20,2), (21,12), (22,22),(23,32))\n val s = sc.next()\n val h = s.substring(0, 2).toInt\n val m = s.substring(3, 5).toInt\n val togo = palindromes.find {\n case (hour, minute) => hour >= h && minute >= m\n } match {\n case Some((hr, min)) => (hr - h) * 60 + (min - m)\n case None => (23 - h) + (60 - m)\n }\n println(togo)\n}\n"}], "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5"} {"nl": {"description": "A string $$$s$$$ of length $$$n$$$ can be encrypted by the following algorithm: iterate over all divisors of $$$n$$$ in decreasing order (i.e. from $$$n$$$ to $$$1$$$), for each divisor $$$d$$$, reverse the substring $$$s[1 \\dots d]$$$ (i.e. the substring which starts at position $$$1$$$ and ends at position $$$d$$$). For example, the above algorithm applied to the string $$$s$$$=\"codeforces\" leads to the following changes: \"codeforces\" $$$\\to$$$ \"secrofedoc\" $$$\\to$$$ \"orcesfedoc\" $$$\\to$$$ \"rocesfedoc\" $$$\\to$$$ \"rocesfedoc\" (obviously, the last reverse operation doesn't change the string because $$$d=1$$$).You are given the encrypted string $$$t$$$. Your task is to decrypt this string, i.e., to find a string $$$s$$$ such that the above algorithm results in string $$$t$$$. It can be proven that this string $$$s$$$ always exists and is unique.", "input_spec": "The first line of input consists of a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$) — the length of the string $$$t$$$. The second line of input consists of the string $$$t$$$. The length of $$$t$$$ is $$$n$$$, and it consists only of lowercase Latin letters.", "output_spec": "Print a string $$$s$$$ such that the above algorithm results in $$$t$$$.", "sample_inputs": ["10\nrocesfedoc", "16\nplmaetwoxesisiht", "1\nz"], "sample_outputs": ["codeforces", "thisisexampletwo", "z"], "notes": "NoteThe first example is described in the problem statement."}, "positive_code": [{"source_code": "object CF_490_3_B {\n\n type In = (Int, String)\n type Out = String\n \n def solve(in: In): Out = {\n val (n, s) = in\n\n var ms = s\n for {\n i <- 1 to n\n if n % i == 0\n } {\n val (a, b) = ms.splitAt(i)\n ms = a.reverse + b\n }\n\n ms\n }\n\n// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n// Specify Input and Output formats on RHS here:\n\n def formatIn(i: Input): In = (i.int, {i.nextLine; i.nextLine})\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"}, {"source_code": "object B999 {\n\n import IO._\n import collection.{mutable => cu}\n\n def main(args: Array[String]): Unit = {\n val Array(n) = readInts(1)\n var str = read\n for(fact <- 1 to n) {\n if(n % fact == 0) {\n str = (str.take(fact).reverse) ++ str.drop(fact)\n }\n }\n out.println(str)\n\n out.close()\n }\n\n object IO {\n private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n // private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(\"src/input\")))\n val out = new java.io.PrintWriter(System.out)\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}"}, {"source_code": "import scala.io.StdIn\n\nobject ReversingEncryption {\n def decrypt(length: Int, line: String): String = {\n var newString = line\n for (i <- 1 to length) {\n if (length % i == 0) {\n newString = newString.replaceFirst(newString.substring(0, i), newString.substring(0, i).reverse)\n }\n }\n newString\n }\n\n def main(args: Array[String]): Unit = {\n val length = StdIn.readInt()\n var line = StdIn.readLine()\n println(decrypt(length, line))\n }\n}"}, {"source_code": "import scala.io.StdIn._\nimport scala.annotation.tailrec\n\nobject ProblemB {\n def readLineToList = readLine.split(\" \").map(_.toInt).toList\n\n def main(args: Array[String]): Unit = {\n val max = readLine.toInt\n val encryptedStr = readLine\n val divisors = (1 to max).filter(max % _ == 0)\n\n val result = divisors.foldLeft(encryptedStr)((a,b) => {\n a.substring(0, b).reverse + a.splitAt(b)._2\n })\n println(result)\n }\n}"}, {"source_code": "object Main2 extends App {\n\n import java.io._\n import java.util.{StringTokenizer}\n\n val in = new Reader()\n val out: PrintWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))\n\n val n = in.nextInt\n var s = in.next\n (2 to n) filter(n % _ == 0) foreach { d =>\n s = s.substring(0, d).reverse + s.substring(d, n)\n }\n out.print(s)\n out.flush()\n out.close()\n\n class Reader @throws[IOException]\n () {\n var br: BufferedReader = new BufferedReader(new InputStreamReader(System.in))\n var tok: StringTokenizer = null\n\n def this(file: String) {\n this()\n br = new BufferedReader(new FileReader(file))\n }\n\n def next: String = {\n while (tok == null || !tok.hasMoreElements) tok = new StringTokenizer(br.readLine)\n tok.nextToken\n }\n\n def nextInt: Int = next.toInt\n\n def nextLong: Long = next.toLong\n\n def nextDouble: Double = next.toDouble\n\n def nextLine: String = br.readLine\n }\n\n}"}, {"source_code": "import scala.io.StdIn\n\nobject ReverseEncryption {\n def main(args: Array[String]): Unit = {\n StdIn.readLine()\n val string = StdIn.readLine()\n println(solve(string))\n }\n\n def solve(input: String) = {\n var result = input\n divisor(input.length).foreach(n => result = flip(result, n))\n result\n }\n\n private def divisor(n: Int): Seq[Int] = {\n for {\n i <- 2 to n\n if n % i == 0\n }\n yield i\n }\n\n private def flip(input: String, n: Int): String = {\n input.substring(0, n).reverse + input.substring(n)\n }\n}"}, {"source_code": "import math._\nobject Main extends App {\n val n = readInt\n val s = readLine\n val d = (1 to sqrt(n).toInt).filter(n % _ == 0)\n val all_d = (d ++ d.map(n / _).reverse).distinct\n val b = StringBuilder.newBuilder\n b.append(s)\n all_d.foreach(i => b.replace(0, i, b.substring(0, i).reverse))\n println(b)\n}"}], "negative_code": [{"source_code": "import math._\nobject Main extends App {\n val n = readInt\n val s = readLine\n val d = (1 to sqrt(n).toInt).filter(n % _ == 0)\n val all_d = d ++ d.map(n / _).reverse\n val b = StringBuilder.newBuilder\n b.append(s)\n all_d.foreach(i => b.replace(0, i, b.substring(0, i).reverse))\n println(b)\n}"}], "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3"} {"nl": {"description": "Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome.In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment.However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him.", "input_spec": "The first and only line of the input starts with a string with the format \"HH:MM\" where \"HH\" is from \"00\" to \"23\" and \"MM\" is from \"00\" to \"59\". Both \"HH\" and \"MM\" have exactly two digits.", "output_spec": "Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.", "sample_inputs": ["12:21", "23:59"], "sample_outputs": ["13:31", "00:00"], "notes": null}, "positive_code": [{"source_code": "object P108A extends App {\n \n val Array(hh,mm) = readLine.split(\":\").map(_.toInt)\n \n def inc(t:(Int,Int)) = ((t._1 + (if (t._2==59) 1 else 0)) % 24,(t._2+1) % 60)\n def f(s:Int) = \"%02d\".format(s)\n def isPal(t:Int,s:Int) = (f(t) == f(s).reverse)\n \n var time = (hh,mm)\n do time = inc(time) while(!isPal(time._1,time._2))\n print(f(time._1) + \":\" + f(time._2))\n\n}"}, {"source_code": "object P108A extends App {\n val Array(h,m)=readLine.split(\":\").map(_.toInt)\n def i(t:(Int,Int))=((t._1+(if(t._2==59)1 else 0))%24,(t._2+1)%60)\n def f(s:Int)=\"%02d\".format(s)\n var t = (h,m)\n do t = i(t) while(f(t._1) != f(t._2).reverse)\n print(f(t._1) + \":\" + f(t._2))\n}"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n def pol(time: Int) = {\n val minutes = time % 60\n val hours = time / 60 % 24\n minutes % 10 == hours / 10 && minutes / 10 == hours % 10\n }\n\n val in = Source.stdin.getLines()\n val Array(hh, mm) = in.next().split(\":\").map(_.toInt)\n var time = hh * 60 + mm + 1\n while (!pol(time)) time += 1\n val minutes = time % 60\n val hours = time / 60 % 24\n println(f\"$hours%02d:$minutes%02d\")\n}"}, {"source_code": "object A108 {\n\n import IO._\n import collection.{mutable => cu}\n\n def main(args: Array[String]): Unit = {\n val in = {\n val str = read\n Array(str.take(2).toInt, str.takeRight(2).toInt)\n }\n var break = false\n while(!break) {\n if(in(0) == 23 && in(1) == 59) {\n in(0) = 0\n in(1) = 0\n } else if(in(1) == 59){\n in(0) += 1\n in(1) = 0\n } else {\n in(1) += 1\n }\n val str = \"%02d\".format(in(0)) + \":\" + \"%02d\".format(in(1))\n if(str == str.reverse) {\n println(str)\n break = true\n }\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"}, {"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 P108A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val List(hh, mm): List[String] = sc.nextLine.split(\":\").toList\n\n def nextPalindromicTime(n: Int): String = {\n val h = (n + 1) % 24\n val m = f\"$h%02d\".reverse.toInt\n if (m < 60) f\"$h%02d:$m%02d\"\n else nextPalindromicTime(h)\n }\n\n val res = {\n val rh = hh.reverse.toInt\n if (rh < 60 && rh > mm.toInt) hh + \":\" + hh.reverse\n else nextPalindromicTime(hh.toInt)\n }\n\n out.println(res)\n out.close\n}\n\n\n\n\n\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val Array(hh, mm) = readLine().split(\":\")\n val h1 = \n if (hh.reverse.toInt <= mm.toInt) hh.toInt + 1\n else hh.toInt\n val h2 = h1 match {\n case 24 => \"00\"\n case i if i < 6 => \"0\" + i\n case i if i >= 6 && i <= 9 => \"10\"\n case i if i >= 16 && i <= 19 => \"20\"\n case i => i.toString\n }\n println(h2 + \":\" + h2.reverse)\n }\n}"}], "negative_code": [{"source_code": "object P108A extends App {\n \n val Array(hh,mm) = readLine.split(\":\").map(_.toInt)\n \n def inc(t:(Int,Int)) = ((t._1 + (if (t._2==59) 1 else 0)) % 24,(t._2+1) % 60)\n def isPal(t:(Int,Int)) = (t._1 == t._2.toString.reverse.toInt)\n \n var time = (hh,mm)\n do time = inc(time) while(!isPal(time))\n printf(\"%02d:%02d\", time._1, time._2)\n\n}"}, {"source_code": "object P108A extends App {\n val Array(h,m)=readLine.split(\":\").map(_.toInt)\n def i(t:(Int,Int))=((t._1+(if(t._2==59)1 else 0))%24,(t._2+1)%60)\n def f(s:Int)=\"%02d\".format(s)\n var t = (h,m)\n do t = i(t) while(f(t._1) != f(t._2))\n print(f(t._1) + \":\" + f(t._2))\n}"}, {"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 P108A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val List(h, m) = sc.nextLine.split(\":\").toList\n\n val res = if (h.reverse.toInt > m.toInt) out.println(h + \":\" + h.reverse)\n else nextPalindromicTIme(h.toInt)\n\n def nextPalindromicTIme(x: Int): String = {\n val y = (x + 1) % 24\n val z = f\"$y%02d\".reverse.toInt\n if (z < 60) f\"$y%02d:$z%02d\"\n else (nextPalindromicTIme(x + 1))\n }\n\n out.println(res)\n out.close\n}\n\n\n\n\n\n"}, {"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 P108A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val List(h, m) = sc.nextLine.split(\":\").toList\n\n if (h.reverse.toInt >= m.toInt) out.println(h + \":\" + h.reverse)\n else nextPalindromicTIme(h.toInt)\n\n def nextPalindromicTIme(x: Int): String = {\n val y = (x + 1) % 24\n val z = f\"$y%02d\".reverse.toInt\n if (z < 60) f\"$y%02d:$z%02d\"\n else (nextPalindromicTIme(x + 1))\n }\n\n out.close\n}\n\n\n\n\n\n"}, {"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 P108A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val List(h, m) = sc.nextLine.split(\":\").toList\n\n if (h.reverse.toInt > m.toInt) out.println(h + \":\" + h.reverse)\n else nextPalindromicTIme(h.toInt)\n\n def nextPalindromicTIme(x: Int): String = {\n val y = (x + 1) % 24\n val z = f\"$y%02d\".reverse.toInt\n if (z < 60) f\"$y%02d:$z%02d\"\n else (nextPalindromicTIme(x + 1))\n }\n\n out.close\n}\n\n\n\n\n\n"}, {"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 P108A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val List(h, m) = sc.nextLine.split(\":\").toList\n\n val res = if (h.reverse.toInt > m.toInt) h + \":\" + h.reverse\n else nextPalindromicTIme(h.toInt)\n\n def nextPalindromicTIme(x: Int): String = {\n val y = (x + 1) % 24\n val z = f\"$y%02d\".reverse.toInt\n if (z < 60) f\"$y%02d:$z%02d\"\n else nextPalindromicTIme(x + 1)\n }\n\n out.println(res)\n out.close\n}\n\n\n\n\n\n"}, {"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 P108A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val n = sc.nextLine.split(\":\")(0).toInt\n\n def nextPalindromicTIme(x: Int): String = {\n val y = (x + 1) % 24\n val z = f\"$y%02d\".reverse.toInt\n if (z < 60) f\"$y%02d:$z%02d\"\n else (nextPalindromicTIme(x + 1))\n }\n\n out.println(nextPalindromicTIme(n))\n out.close\n}\n\n\n\n\n\n"}], "src_uid": "158eae916daa3e0162d4eac0426fa87f"} {"nl": {"description": "Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.Let's remember how Fibonacci numbers can be calculated. F0 = 0, F1 = 1, and all the next numbers are Fi = Fi - 2 + Fi - 1.So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ...If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number n by three not necessary different Fibonacci numbers or say that it is impossible.", "input_spec": "The input contains of a single integer n (0 ≤ n < 109) — the number that should be represented by the rules described above. It is guaranteed that n is a Fibonacci number.", "output_spec": "Output three required numbers: a, b and c. If there is no answer for the test you have to print \"I'm too stupid to solve this problem\" without the quotes. If there are multiple answers, print any of them.", "sample_inputs": ["3", "13"], "sample_outputs": ["1 1 1", "2 3 8"], "notes": null}, "positive_code": [{"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 n = scanner nextInt ()\n\t\tprint (\"0 0 \")\n\t\tprintln (n)\n\t}\n\n}\n"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val n = in.next().toInt\n println(s\"$n 0 0\")\n}\n"}, {"source_code": "object A199 {\n\n import IO._\n import collection.{mutable => cu}\n def main(args: Array[String]): Unit = {\n val Array(n) = readLongs(1)\n println(s\"0 0 $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"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P199A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val N = sc.nextInt\n\n def solve(): List[Int] = {\n\n @tailrec\n def loop(a: Int, b: Int, c: Int, d: Int, x: Int): List[Int] = {\n if (x == N) List(a, b, d)\n else loop(b, c, d, x, d + x)\n }\n\n N match {\n case 0 => List(0, 0, 0)\n case 1 => List(0, 0, 1)\n case 2 => List(0, 1, 1)\n case _ => loop(0, 1, 1, 2, 3)\n }\n }\n\n out.println(solve.mkString(\" \"))\n out.close\n}\n"}, {"source_code": "\nimport java.util\n\nimport scala.annotation.tailrec\n\n/**\n * @author pvasilyev\n * @since 16 Jun 2016\n */\nobject A199 extends App {\n\n @tailrec\n // fibs[from] <= f\n def binarySearch(fibs: util.ArrayList[Int], f: Int, from: Int, to: Int): Int = {\n if (to - from < 2) {\n from\n } else {\n val mid: Int = (from + to) / 2\n if (fibs.get(mid) <= f) {\n binarySearch(fibs, f, mid, to)\n } else {\n binarySearch(fibs, f, from, mid)\n }\n }\n }\n\n def solve() = {\n val f: Int = scala.io.StdIn.readInt()\n if (f == 0) {\n println(\"0 0 0\")\n } else if (f == 1) {\n println(\"0 0 1\")\n } else {\n val fibs = new util.ArrayList[Int]()\n fibs.add(0)\n fibs.add(1)\n var k = 2\n while (fibs.get(k - 1) + fibs.get(k - 2) < 1000000000) {\n fibs.add(fibs.get(k - 1) + fibs.get(k - 2))\n k += 1\n }\n val i: Int = binarySearch(fibs, f, 0, fibs.size())\n println(\"0 \" + fibs.get(i-2) + \" \" + fibs.get(i-1))\n }\n }\n\n solve()\n\n}\n"}, {"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 def readLine = reader.readLine\n\n def ans = Array(0, 0, readInt).mkString(\" \")\n\n def main(a: Array[String]) {\n println(ans)\n }\n}\n"}, {"source_code": "object Main {\n val fib: Stream[Int] = {\n def fibf(a: Int, b: Int): Stream[Int] = {\n a #:: fibf(b, a + b)\n }\n fibf(0, 1)\n }\n\n def main(args: Array[String]) = {\n val n = readLine()\n val i = fib.takeWhile(_ < 1000000000).indexOf(n)\n if (i <= 3) println(\"0 0 \" + n) \n else println(fib(i - 4) + \" \" + fib(i - 3) + \" \" + fib(i - 1))\n }\n}"}, {"source_code": "object Solution extends App{\n \n val in = scala.io.Source.stdin.getLines()\n val n = in.next().toInt\n println(s\"$n 0 0\")\n}"}], "negative_code": [{"source_code": "object A199 {\n\n import IO._\n import collection.{mutable => cu}\n def generateFib(till: Long): Array[Long] = {\n var num1 = 1L\n var num2 = 2L\n var res = Array(1L, 2L)\n while(num2 <= till) {\n val temp = num1 + num2\n num1 = num2\n num2 = temp\n res ++= Array(num2)\n }\n res\n }\n def main(args: Array[String]): Unit = {\n val Array(n) = readLongs(1)\n val fibs = generateFib(1000000000L)\n var break = false\n for(i <- fibs; j <- fibs; k <- fibs if !break) {\n if(i+j+k == n) {\n println(s\"$i $j $k\")\n break = true\n }\n }\n if(!break)\n println(\"I'm too stupid to solve this problem\")\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": "db46a6b0380df047aa34ea6a8f0f93c1"} {"nl": {"description": "Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than $$$a$$$ and screen height not greater than $$$b$$$. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is $$$w$$$, and the height of the screen is $$$h$$$, then the following condition should be met: $$$\\frac{w}{h} = \\frac{x}{y}$$$.There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers $$$w$$$ and $$$h$$$ there is a TV set with screen width $$$w$$$ and height $$$h$$$ in the shop.Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers $$$w$$$ and $$$h$$$, beforehand, such that $$$(w \\le a)$$$, $$$(h \\le b)$$$ and $$$(\\frac{w}{h} = \\frac{x}{y})$$$.In other words, Monocarp wants to determine the number of TV sets having aspect ratio $$$\\frac{x}{y}$$$, screen width not exceeding $$$a$$$, and screen height not exceeding $$$b$$$. Two TV sets are considered different if they have different screen width or different screen height.", "input_spec": "The first line contains four integers $$$a$$$, $$$b$$$, $$$x$$$, $$$y$$$ ($$$1 \\le a, b, x, y \\le 10^{18}$$$) — the constraints on the screen width and height, and on the aspect ratio.", "output_spec": "Print one integer — the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.", "sample_inputs": ["17 15 5 3", "14 16 7 22", "4 2 6 4", "1000000000000000000 1000000000000000000 999999866000004473 999999822000007597"], "sample_outputs": ["3", "0", "1", "1000000063"], "notes": "NoteIn the first example, there are $$$3$$$ possible variants: $$$(5, 3)$$$, $$$(10, 6)$$$, $$$(15, 9)$$$.In the second example, there is no TV set meeting the constraints.In the third example, there is only one variant: $$$(3, 2)$$$."}, "positive_code": [{"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 a, b = nl()\n var x, y = nl()\n val d = gcd(x, y)\n x /= d\n y /= d\n\n val ans = min(a / x, b / y)\n\n out.println(ans)\n }\n\n\n def gcd(a: Long, b: Long): Long = {\n if (b == 0) a\n else gcd(b, a % b)\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}"}], "negative_code": [], "src_uid": "907ac56260e84dbb6d98a271bcb2d62d"} {"nl": {"description": "A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case English letters.There is very little time to correct the mistake. All that we can manage to do is to cut out some substring from the banner, i.e. several consecutive letters. After that all the resulting parts of the banner will be glued into a single piece (if the beginning or the end of the original banner was cut out, only one part remains); it is not allowed change the relative order of parts of the banner (i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters). Thus, for example, for example, you can cut a substring out from string 'TEMPLATE' and get string 'TEMPLE' (if you cut out string AT), 'PLATE' (if you cut out TEM), 'T' (if you cut out EMPLATE), etc.Help the organizers of the round determine whether it is possible to cut out of the banner some substring in such a way that the remaining parts formed word CODEFORCES.", "input_spec": "The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES.", "output_spec": "Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes).", "sample_inputs": ["CODEWAITFORITFORCES", "BOTTOMCODER", "DECODEFORCES", "DOGEFORCES"], "sample_outputs": ["YES", "NO", "YES", "NO"], "notes": null}, "positive_code": [{"source_code": "object Main extends App with fastIO{\n val s = readLine\n val st = \"CODEFORCES\"\n var bo = false\n //if(s.contains(st)) bo = true\n for(a <- 0 until s.length; b <- a to s.length){\n if(s.substring(0,a)++s.substring(b,s.length)==st) bo = true\n }\n println(if(bo)\"YES\" else \"NO\")\n flush\n}\n\ntrait fastIO {\n import java.io._\n val isFile = false\n val input = \"file.in\"\n val output = \"file.out\"\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 def nextInt: Int = {\n in.nextToken()\n in.nval.toInt\n }\n def nextLong:Long ={\n in.nextToken()\n in.nval.toLong\n }\n def nextDouble: Double = {\n in.nextToken()\n in.nval\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}"}, {"source_code": "import scala.io.Source\n\nobject A extends App {\n val str = Source.stdin.getLines().next()\n val a = (0 until str.length).exists(s => (s to str.length).exists(e => str.substring(0, s) + str.substring(e) == \"CODEFORCES\"))\n println(if (a) \"YES\" else \"NO\")\n}\n"}, {"source_code": "import scala.collection._\n\nobject 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 b = \"CODEFORCES\"\n var canCut = true\n var hasCut = false\n var ok = true\n \n var i = 0\n while (i < a.length && i < b.length && a(i) == b(i)) {\n i += 1\n }\n \n var j = 0\n while (j < a.length && j < b.length && a(a.length - j - 1) == b(b.length - j - 1)) {\n j += 1\n }\n//println(i, j)\n println(if (i == b.length || j == b.length || i + j >= b.length) \"YES\" else \"NO\")\n}\n"}, {"source_code": "import java.io._\nimport java.util._\n\nimport scala.collection.mutable\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 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 def solve: Int = {\n val banner = next\n val n = banner.length\n for (i <- 0 until n) {\n for (j <- i - 1 until n) {\n if ((banner.substring(0, i) + banner.substring(j + 1)).equalsIgnoreCase(\"codeforces\")) {\n out.println(\"YES\")\n return 0\n }\n }\n }\n out.println(\"NO\")\n return 0\n }\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject A_CuttingBanner extends App {\n val banner = readLine()\n val Code = \"CODEFORCES\"\n\n private def isPossible: Boolean = {\n if (banner.length > Code.length) {\n val sizeToCut = banner.length - Code.length\n for {\n left <- 0 to banner.length\n } {\n val L = banner.take(left)\n val R = banner.drop(left + sizeToCut)\n// println(L + \"|\" + R)\n if (L + R == Code) return true\n }\n }\n\n false\n }\n\n println(if (isPossible) \"YES\" else \"NO\")\n}\n"}], "negative_code": [{"source_code": "object Main extends App with fastIO{\n val s = readLine\n val st = \"CODEFORCES\"\n var bo = false\n if(s.contains(st)) bo = true\n else for(a <- 0 until s.length; b <- a until s.length){\n if(s.substring(0,a)++s.substring(b,s.length)==st) bo = true\n }\n println(if(bo)\"YES\" else \"NO\")\n flush\n}\n\ntrait fastIO {\n import java.io._\n val isFile = false\n val input = \"file.in\"\n val output = \"file.out\"\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 def nextInt: Int = {\n in.nextToken()\n in.nval.toInt\n }\n def nextLong:Long ={\n in.nextToken()\n in.nval.toLong\n }\n def nextDouble: Double = {\n in.nextToken()\n in.nval\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}"}, {"source_code": "\nobject Main extends App with fastIO{\n val s = readLine\n val st = \"CODEFORCES\"\n var bo = false\n //if(s.contains(st)) bo = true\n for(a <- 0 until s.length; b <- a until s.length){\n if(s.substring(0,a)++s.substring(b,s.length)==st) bo = true\n }\n println(if(bo)\"YES\" else \"NO\")\n flush\n}\n\ntrait fastIO {\n import java.io._\n val isFile = false\n val input = \"file.in\"\n val output = \"file.out\"\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 def nextInt: Int = {\n in.nextToken()\n in.nval.toInt\n }\n def nextLong:Long ={\n in.nextToken()\n in.nval.toLong\n }\n def nextDouble: Double = {\n in.nextToken()\n in.nval\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}"}, {"source_code": "import scala.collection._\n\nobject 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 b = \"CODEFORCES\"\n var canCut = true\n var hasCut = false\n var ok = true\n \n var i = 0\n while (i < a.length && i < b.length && a(i) == b(i)) {\n i += 1\n }\n \n var j = 0\n while (j < a.length && j < b.length && a(a.length - j - 1) == b(b.length - j - 1)) {\n j += 1\n }\n//println(i, j)\n println(if (i == b.length || j == b.length || i + j == b.length) \"YES\" else \"NO\")\n}\n"}, {"source_code": "import scala.collection._\n\nobject 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 b = \"CODEFORCES\"\n var canCut = true\n var hasCut = false\n var ok = true\n \n var i = 0\n while (i < a.length && i < b.length && a(i) == b(i)) {\n i += 1\n }\n \n var j = 0\n while (j < a.length && j < b.length && a(a.length - j - 1) == b(b.length - j - 1)) {\n j += 1\n }\n//println(i, j)\n println(if (a == b || (i + j == b.length && (i > 0 || j > 0))) \"YES\" else \"NO\")\n}\n"}, {"source_code": "import java.io._\nimport java.util._\n\nimport scala.collection.mutable\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 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 def solve: Int = {\n val banner = next\n val n = banner.length\n for (i <- 0 until n) {\n for (j <- i + 1 until n) {\n if ((banner.substring(0, i) + banner.substring(j)).equalsIgnoreCase(\"codeforces\")) {\n out.println(\"YES\")\n return 0\n }\n }\n }\n out.println(\"NO\")\n return 0\n }\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject A_CuttingBanner extends App {\n val banner = readLine()\n val Code = \"CODEFORCES\"\n\n private def isPossible: Boolean = {\n if (banner.length > Code.length) {\n val sizeToCut = banner.length - Code.length\n for {\n left <- 0 to (banner.length - Code.length)\n } {\n val L = banner.take(left)\n val R = banner.drop(left + banner.length - Code.length)\n if (L + R == Code) return true\n }\n }\n\n false\n }\n\n println(if (isPossible) \"YES\" else \"NO\")\n}\n"}], "src_uid": "bda4b15827c94b526643dfefc4bc36e7"} {"nl": {"description": "Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.", "input_spec": "The first line of the input contains a single integer n (2 ≤ n ≤ 100) — the size of the permutation. The second line of the input contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n), where ai is equal to the element at the i-th position.", "output_spec": "Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.", "sample_inputs": ["5\n4 5 1 3 2", "7\n1 6 5 3 4 7 2", "6\n6 5 4 3 2 1"], "sample_outputs": ["3", "6", "5"], "notes": "NoteIn the first sample, one may obtain the optimal answer by swapping elements 1 and 2.In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2."}, "positive_code": [{"source_code": "object Solution extends App {\n val lines = io.Source.stdin.getLines()\n lines.next()\n val data = lines.next().split(' ').map(_.toInt)\n if (data.head == 1 || data.last == 1 || data.last == data.length || data.last == data.length) {\n println(data.length - 1)\n } else {\n val indexOne = data.indexOf(1) + 1\n val indexN = data.indexOf(data.length) + 1\n var first = Math.max(indexOne - 1, indexN - 1)\n var last = Math.max(data.length - indexOne, data.length - indexN)\n println(Math.max(first, last))\n }\n\n}\n"}, {"source_code": "import io.StdIn._\nimport scala.math._\n\nobject Permutation extends App {\n val n = readInt()\n val arr = readLine().split(\" \").map(_.toInt)\n\n val pos1 = arr.indexOf(1)\n val posMax = arr.indexOf(n)\n val diff = abs(pos1-posMax)\n\n if(diff == n){\n println(n-1)\n }else{\n if(pos1>posMax){\n if((n-1)-pos1>= posMax){\n println((n-1)-posMax)\n }else{\n println(pos1)\n }\n }else{\n if((n-1)-posMax>= pos1){\n println((n-1)-pos1)\n }else{\n println(posMax)\n }\n }\n\n }\n}"}, {"source_code": "object A676 {\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 idx1 = in.indexOf(1)\n val idxN = in.indexOf(n)\n var max = math.abs(idxN - idx1)\n for(i <- 0 until n if i != idxN) {\n max = math.max(max, math.abs(idxN - i))\n }\n for(i <- 0 until n if i != idx1) {\n max = math.max(max, math.abs(idx1 - i))\n }\n println(max)\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"}, {"source_code": "import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._\n\nobject _676A extends CodeForcesApp {\n override def apply(io: IO) = {\n val a = io[Vector[Int]]\n val n = a.length\n val (p, q) = (a.indexOf(1) + 1, a.indexOf(n) + 1)\n //debug(n, p, q)\n val ans = (p - 1).abs max (n - p) max (q - 1).abs max (n - q)\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 def prefixSum(implicit n: Numeric[A]) = t.scanLeft(n.zero) {case (acc, i) => n.plus(acc, i)}\n def suffixSum(implicit n: Numeric[A]) = t.scanRight(n.zero) {case (i, acc) => n.plus(acc, i)}\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 SortedExtensions[A, C[A] <: collection.SortedSet[A]](val s: C[A]) extends AnyVal {\n def greaterThanOrEqualTo(a: A): Option[A] = s.from(a).headOption\n def lessThan(a: A): Option[A] = s.until(a).lastOption\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 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[A, B](f: A => B): collection.Map[A, B] = new mutable.HashMap[A, B]() {\n override def apply(key: A) = getOrElseUpdate(key, f(key))\n }\n implicit class FuzzyDouble(x: Double)(implicit eps: Double = 1e-9) {\n def >~(y: Double) = x > y+eps\n def >=~(y: Double) = x >= y-eps\n def ~<(y: Double) = x < y-eps\n def ~=<(y: Double) = x <= y+eps\n def ~=(y: Double) = ~=<(y) && >=~(y)\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}\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[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"}], "negative_code": [{"source_code": "import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._\n\nobject _676A extends CodeForcesApp {\n override def apply(io: IO) = {\n val a = io[Vector[Int]]\n val n = a.length\n val (p, q) = (a.indexOf(1), a.indexOf(n))\n val ans = p max (n - p) max q max (n - q)\n io += (ans - 1)\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 def prefixSum(implicit n: Numeric[A]) = t.scanLeft(n.zero) {case (acc, i) => n.plus(acc, i)}\n def suffixSum(implicit n: Numeric[A]) = t.scanRight(n.zero) {case (i, acc) => n.plus(acc, i)}\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 SortedExtensions[A, C[A] <: collection.SortedSet[A]](val s: C[A]) extends AnyVal {\n def greaterThanOrEqualTo(a: A): Option[A] = s.from(a).headOption\n def lessThan(a: A): Option[A] = s.until(a).lastOption\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 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[A, B](f: A => B): collection.Map[A, B] = new mutable.HashMap[A, B]() {\n override def apply(key: A) = getOrElseUpdate(key, f(key))\n }\n implicit class FuzzyDouble(x: Double)(implicit eps: Double = 1e-9) {\n def >~(y: Double) = x > y+eps\n def >=~(y: Double) = x >= y-eps\n def ~<(y: Double) = x < y-eps\n def ~=<(y: Double) = x <= y+eps\n def ~=(y: Double) = ~=<(y) && >=~(y)\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}\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[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": "1d2b81ce842f8c97656d96bddff4e8b4"} {"nl": {"description": "This winter is so cold in Nvodsk! A group of n friends decided to buy k bottles of a soft drink called \"Take-It-Light\" to warm up a bit. Each bottle has l milliliters of the drink. Also they bought c limes and cut each of them into d slices. After that they found p grams of salt.To make a toast, each friend needs nl milliliters of the drink, a slice of lime and np grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?", "input_spec": "The first and only line contains positive integers n, k, l, c, d, p, nl, np, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.", "output_spec": "Print a single integer — the number of toasts each friend can make.", "sample_inputs": ["3 4 5 10 8 100 3 1", "5 100 10 1 19 90 4 3", "10 1000 1000 25 23 1 50 1"], "sample_outputs": ["2", "3", "0"], "notes": "NoteA comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is min(6, 80, 100) / 3 = 2."}, "positive_code": [{"source_code": "import java.util.Scanner\nobject Cola {\n\n def main(args: Array[String] ) {\n val scanner = new Scanner(System.in)\n val n, k, l, c, d, p, nl, np = scanner.nextInt();\n val limes = c*d/n\n val cola = k*l/(n*nl)\n val salt = p/(n*np)\n \n println(Math.min(Math.min(limes,cola),salt))\n \n }\n}"}, {"source_code": "/**\n * Created by IntelliJ IDEA.\n * User: cm\n * Date: 17.02.12\n * Time: 23:06\n * To change this template use File | Settings | File Templates.\n */\n\nobject P151A extends App {\n val Array(n, k, l, c, d, p, nl, np) = readLine().split(\" \").map(_.toInt)\n print(List(k*l/nl,c*d,p/np).min / n)\n}\n"}, {"source_code": "import java.util.StringTokenizer\n\nobject _151A extends App {\n var token = new StringTokenizer(\"\")\n def next = {\n while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)\n token.nextToken()\n }\n val Array(n, k, l, c, d, p, nl, np) = (1 to 8).map(i => next.toInt).toArray\n val ans = (k * l / nl) min (c * d) min (p / np)\n println(ans / n)\n}\n"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val Array(n, k, l, c, d, p, nl, np) = in.next().split(\" \").map(_.toInt)\n println(Math.min(c * d, Math.min((k * l) / nl, p / np)) / n)\n}\n"}, {"source_code": " object Main\n {\n def min(a:Int, b:Int, c:Int):Int = \n {\n var aorb = 0;\n if (a < b)\n {\n aorb = a\n }\n else\n {\n aorb = b\n }\n \n if (c < aorb)\n return c;\n return aorb;\n }\n def main(args:Array[String])\n {\n val a = readLine().split(\" \").map(i => i.toInt);\n val n = a(0);\n val k = a(1);\n val l = a(2);\n val c = a(3);\n val d = a(4);\n val p = a(5);\n val nl = a(6);\n val np = a(7);\n \n println(min(k * l / nl, c * d, p / np) / n);\n }\n }"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P151A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val n, k, l, c, d, p, nl, np = sc.nextInt\n\n val drink = (k * l) / nl\n val lime = c * d\n val salt = p / np\n\n val answer = List(drink, lime, salt).min / n\n\n out.println(answer)\n out.close\n}\n"}, {"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 Array(n, k, l, c, d, p, nl, np) = readInts\n def ans = ((k * l) / nl min c * d min p / np) / n\n\n def main(a: Array[String]) {\n println(ans)\n }\n}\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val nklcdpnlnp = readLine().split(\" \").map(_.toInt)\n val n = nklcdpnlnp(0)\n val k = nklcdpnlnp(1)\n val l = nklcdpnlnp(2)\n val c = nklcdpnlnp(3)\n val d = nklcdpnlnp(4)\n val p = nklcdpnlnp(5)\n val nl = nklcdpnlnp(6)\n val np = nklcdpnlnp(7)\n \n val tests = Seq(k * l / nl) ++ Seq(c * d) ++ Seq(p / np)\n println(tests.min / n)\n }\n}"}, {"source_code": "import java.util.Scanner\n\nobject SoftDrinking { \n def main(args: Array[String]) { \n val sc = new Scanner(System.in)\n val n = sc.nextInt\n val k = sc.nextInt\n val l = sc.nextInt\n val c = sc.nextInt\n val d = sc.nextInt\n val p = sc.nextInt\n val nl = sc.nextInt\n val np = sc.nextInt\n println(List(k * l / nl, c * d, p / np).min / n)\n }\n}\n"}], "negative_code": [{"source_code": "import java.util.StringTokenizer\n\nobject _151A extends App {\n var token = new StringTokenizer(\"\")\n def next = {\n while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)\n token.nextToken()\n }\n val Array(n, k, l, c, d, p, nl, np) = (1 to 8).map(i => next.toInt).toArray\n val ans = (n * k / nl) min (c * d) min (p / np)\n println(ans / n)\n}\n"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val Array(n, k, l, c, d, p, nl, np) = in.next().split(\" \").map(_.toInt)\n println(Math.min(c * d, Math.min(n / nl, p / np)) / n)\n}\n"}], "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1"} {"nl": {"description": "Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.", "input_spec": "The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.", "output_spec": "Output the least super lucky number that is more than or equal to n.", "sample_inputs": ["4500", "47"], "sample_outputs": ["4747", "47"], "notes": null}, "positive_code": [{"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next().toInt\n\n def next(a: Int): Option[Long] = {\n if (a.toBinaryString.length < 3)\n None\n else {\n val candidate = a.toBinaryString.tail\n if (candidate.length % 2 == 0 && candidate.count(_ == '0') == candidate.count(_ == '1'))\n Some(candidate.map(ch => if (ch == '0') '4' else '7').toLong)\n else\n None\n }\n }\n\n var a = 0\n while (next(a).getOrElse(0l) < line) {\n a += 1\n }\n println(next(a).get)\n}"}], "negative_code": [], "src_uid": "77b5f83cdadf4b0743618a46b646a849"} {"nl": {"description": "Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this counter increases by 1. If the player answers a question incorrectly, the counter is reset, that is, the number on it reduces to 0. If after an answer the counter reaches the number k, then it is reset, and the player's score is doubled. Note that in this case, first 1 point is added to the player's score, and then the total score is doubled. At the beginning of the game, both the player's score and the counter of consecutive correct answers are set to zero.Manao remembers that he has answered exactly m questions correctly. But he does not remember the order in which the questions came. He's trying to figure out what his minimum score may be. Help him and compute the remainder of the corresponding number after division by 1000000009 (109 + 9).", "input_spec": "The single line contains three space-separated integers n, m and k (2 ≤ k ≤ n ≤ 109; 0 ≤ m ≤ n).", "output_spec": "Print a single integer — the remainder from division of Manao's minimum possible score in the quiz by 1000000009 (109 + 9).", "sample_inputs": ["5 3 2", "5 4 2"], "sample_outputs": ["3", "6"], "notes": "NoteSample 1. Manao answered 3 questions out of 5, and his score would double for each two consecutive correct answers. If Manao had answered the first, third and fifth questions, he would have scored as much as 3 points.Sample 2. Now Manao answered 4 questions. The minimum possible score is obtained when the only wrong answer is to the question 4.Also note that you are asked to minimize the score and not the remainder of the score modulo 1000000009. For example, if Manao could obtain either 2000000000 or 2000000020 points, the answer is 2000000000 mod 1000000009, even though 2000000020 mod 1000000009 is a smaller number."}, "positive_code": [{"source_code": "import scala.collection._\n\nobject A extends App {\n \n val MOD = 1000000009 \n \n def readString = Console.readLine\n def readBigs = readString.split(\" \").map(s => BigInt(s))\n\n val Array(n, m, k) = readBigs\n\n val plain = ((n - m) * (k - 1) + m.min(n % k)).min(m)\n val doubling = m - plain\n val groups = doubling / k\n val doubled = k * (BigInt(2).modPow(groups + 1, MOD) - 2 + MOD)\n \n val result = (plain + doubled) % MOD\n \n println(result)\n}"}], "negative_code": [], "src_uid": "9cc1aecd70ed54400821c290e2c8018e"} {"nl": {"description": "Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.She precisely remembers she had n buyers and each of them bought exactly half of the apples she had at the moment of the purchase and also she gave a half of an apple to some of them as a gift (if the number of apples at the moment of purchase was odd), until she sold all the apples she had.So each buyer took some integral positive number of apples, but maybe he didn't pay for a half of an apple (if the number of apples at the moment of the purchase was odd).For each buyer grandma remembers if she gave a half of an apple as a gift or not. The cost of an apple is p (the number p is even).Print the total money grandma should have at the end of the day to check if some buyers cheated her.", "input_spec": "The first line contains two integers n and p (1 ≤ n ≤ 40, 2 ≤ p ≤ 1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number p is even. The next n lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of the apples and with the string halfplus if grandma also gave him a half of an apple as a gift. It is guaranteed that grandma has at least one apple at the start of the day and she has no apples at the end of the day.", "output_spec": "Print the only integer a — the total money grandma should have at the end of the day. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.", "sample_inputs": ["2 10\nhalf\nhalfplus", "3 10\nhalfplus\nhalfplus\nhalfplus"], "sample_outputs": ["15", "55"], "notes": "NoteIn the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer."}, "positive_code": [{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val Array(n, p) = in.next().split(' ').map(_.toInt)\n println((1 to n).map(_ => in.next()).reverse.tail.foldLeft((1l, p.toLong / 2)) {\n case ((mayBuy, money), \"halfplus\") => (mayBuy * 2 + 1, money + p * mayBuy + p / 2)\n case ((mayBuy, money), _) => (mayBuy * 2, money + p * mayBuy)\n }._2)\n}"}, {"source_code": "/**\n * Created by aborisenko on 21.02.16.\n */\n\nimport io.StdIn._\n\nobject Main extends App {\n def a632 (){\n\n val Array(n, p) = readLine().split(\" \").map(_.toInt)\n\n var result: Long = 0\n var nn: Long = 0\n\n val a: Array[Int] = Array.fill[Int](n)(0)\n for( i <- 0 to n-1)\n if( readLine() == \"half\" )\n a(i) = 1\n\n for( i <- 1 to n) {\n if (a(n-i) == 1) {\n result += nn * p\n nn *= 2\n } else {\n result += nn * p + p / 2\n nn = nn * 2 + 1\n }\n }\n\n println(result)\n }\n\n a632()\n}\n"}], "negative_code": [{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val Array(n, p) = in.next().split(' ').map(_.toInt)\n println((1 to n).map(_ => in.next()).reverse.tail.foldLeft((1, p / 2)) {\n case ((mayBuy, money), \"halfplus\") => (mayBuy * 2 + 1, money + p * mayBuy + p / 2)\n case ((mayBuy, money), _) => (mayBuy * 2, money + p * mayBuy)\n }._2)\n}"}, {"source_code": "/**\n * Created by aborisenko on 21.02.16.\n */\n\nimport io.StdIn._\n\nobject Main extends App {\n def a632 (){\n\n val Array(n, p) = readLine().split(\" \").map(_.toInt)\n\n var result: Long = 0\n var nn: Long = 0\n\n val a: Array[Int] = Array.fill[Int](n)(0)\n for( i <- 0 to n-1)\n if( readLine() == \"half\" )\n a(i) = 1\n\n for( i <- 0 to n-1) {\n if (a(i) == 1) {\n result += nn * p\n nn *= 2\n } else {\n result += nn * p + p / 2\n nn = nn * 2 + 1\n }\n }\n\n println(result)\n }\n\n a632()\n}\n"}], "src_uid": "6330891dd05bb70241e2a052f5bf5a58"} {"nl": {"description": "Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule.A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number — the number of bonds the atom must form with other atoms. An atom can form one or multiple bonds with any other atom, but it cannot form a bond with itself. The number of bonds of an atom in the molecule must be equal to its valence number. Mike knows valence numbers of the three atoms. Find a molecule that can be built from these atoms according to the stated rules, or determine that it is impossible.", "input_spec": "The single line of the input contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 106) — the valence numbers of the given atoms.", "output_spec": "If such a molecule can be built, print three space-separated integers — the number of bonds between the 1-st and the 2-nd, the 2-nd and the 3-rd, the 3-rd and the 1-st atoms, correspondingly. If there are multiple solutions, output any of them. If there is no solution, print \"Impossible\" (without the quotes).", "sample_inputs": ["1 1 2", "3 4 5", "4 1 1"], "sample_outputs": ["0 1 1", "1 3 2", "Impossible"], "notes": "NoteThe first sample corresponds to the first figure. There are no bonds between atoms 1 and 2 in this case.The second sample corresponds to the second figure. There is one or more bonds between each pair of atoms.The third sample corresponds to the third figure. There is no solution, because an atom cannot form bonds with itself.The configuration in the fourth figure is impossible as each atom must have at least one atomic bond."}, "positive_code": [{"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val Array(a, b, c) = in.next().split(' ').map(_.toInt)\n val r = (0 to a).find{ i =>\n val ab = i\n val ac = a - i\n b - ab >= 0 && (b - ab) == (c - ac)\n }\n println(r.map{\n i => s\"$i ${b - i} ${a - i}\"\n }.getOrElse(\"Impossible\"))\n}"}, {"source_code": "object B344 {\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(a, b, c) = readInts(3)\n var i = 0\n var break = false\n while(!break && i <= a) {\n if(c-(a-i) >= 0 && c-a+2*i == b) {\n println(s\"$i ${c-a+i} ${a-i}\")\n break = true\n }\n i += 1\n }\n\n if(!break) {\n println(\"Impossible\")\n }\n }\n}"}, {"source_code": "import scala.collection._\n\nobject B 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 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 as = readInts(3)\n val sort = as.zipWithIndex.sortBy(_._1)\n \n val d = math.abs(sort(1)._1 - sort(2)._1)\n \n def idx(a: Int, b: Int) = (a, b) match {\n case (0, 1) | (1, 0) => 0\n case (1, 2) | (2, 1) => 1\n case (0, 2) | (2, 0) => 2\n }\n \n if ((sort(0)._1 - d) % 2 == 1 || sort(0)._1 < d) {\n println(\"Impossible\")\n } else {\n val dd = (sort(0)._1 - d) / 2\n val bs = Array(dd, dd + d, sort(1)._1 - dd)\n val cs = Array.ofDim[Int](3)\n \n cs(idx(sort(0)._2, sort(1)._2)) = bs(0)\n cs(idx(sort(1)._2, sort(2)._2)) = bs(2)\n cs(idx(sort(0)._2, sort(2)._2)) = bs(1)\n\n println(cs.mkString(\" \"))\n }\n\n}"}, {"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.collection.immutable.TreeSet\nimport scala.util.Random\nimport scala.util.control.Breaks._\n\n\nobject P344B extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n def solve(): String = {\n val A, B, C = sc.nextInt\n\n val xyz2 = List(A + B - C, - A + B + C, A - B + C)\n\n if (xyz2.forall { x => x >= 0 && x % 2 == 0 } ) {\n xyz2.map(_ / 2).mkString(\" \")\n }\n else {\n \"Impossible\"\n }\n }\n \n out.println(solve)\n out.close\n}\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val a = readLine().split(\" \").map(_.toInt)\n val s = a.map(_ => 0)\n \n s(0) = (a(0) + a(1) - a(2)) / 2\n s(1) = (a(1) + a(2) - a(0)) / 2\n s(2) = (a(2) + a(0) - a(1)) / 2\n \n if (s.min < 0 || a.sum % 2 != 0) println(\"Impossible\")\n else println(s.mkString(\" \"))\n }\n}"}], "negative_code": [{"source_code": "object B344 {\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(a, b, c) = readInts(3)\n var i = 0\n var break = true\n while(break && i <= a) {\n if(c-(a-i) > 0 && c-a+2*i > 0 && c-a+2*i == b) {\n println(s\"$i ${c-(a-i)} ${a-i}\")\n break = false\n }\n i += 1\n }\n\n if(break) {\n println(\"Impossible\")\n }\n }\n}"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val a = readLine().split(\" \").map(_.toInt)\n val s = a.map(_ => 0)\n s(0) = (a(0) + a(1) - a(2)) / 2\n s(1) = (a(1) + a(2) - a(0)) / 2\n s(2) = (a(2) + a(0) - a(1)) / 2\n \n if (s.min < 0) println(\"Impossible\")\n else println(s.mkString(\" \"))\n }\n}"}], "src_uid": "b3b986fddc3770fed64b878fa42ab1bc"} {"nl": {"description": "Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house m of a village. There are n houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house n. The village is also well-structured: house i and house i + 1 (1 ≤ i < n) are exactly 10 meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased.You will be given n integers a1, a2, ..., an that denote the availability and the prices of the houses. If house i is occupied, and therefore cannot be bought, then ai equals 0. Otherwise, house i can be bought, and ai represents the money required to buy it, in dollars.As Zane has only k dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love.", "input_spec": "The first line contains three integers n, m, and k (2 ≤ n ≤ 100, 1 ≤ m ≤ n, 1 ≤ k ≤ 100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 100) — denoting the availability and the prices of the houses. It is guaranteed that am = 0 and that it is possible to purchase some house with no more than k dollars.", "output_spec": "Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy.", "sample_inputs": ["5 1 20\n0 27 32 21 19", "7 3 50\n62 0 0 0 99 33 22", "10 5 100\n1 0 1 0 0 0 0 0 1 1"], "sample_outputs": ["40", "30", "20"], "notes": "NoteIn the first sample, with k = 20 dollars, Zane can buy only house 5. The distance from house m = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters.In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house m = 3 and house 6 are only 30 meters away, while house m = 3 and house 7 are 40 meters away."}, "positive_code": [{"source_code": "import scala.io.Source\nimport scala.math._\n\nobject a12 {\n def main(args: Array[String]): Unit = {\n val lines = Source.stdin.getLines().take(2).map(_.split(' ').map(_.toInt)).toArray\n val Array(n,kk,l) = lines(0)\n val k = kk-1\n val (bb,cc) = lines(1).zipWithIndex.splitAt(k)\n val (b,c) = (bb.filter(_._1!=0).reverse.dropWhile(_._1 > l).headOption,\n cc.tail.filter( _._1!=0).dropWhile(_._1 > l).headOption)\n println(\n (b,c) match {\n case (Some(a), Some(b)) => min(k-a._2, b._2-k)*10\n case (Some(d),None) => (k - d._2)*10\n case (None, Some(d)) => (d._2 - k)*10\n case (None,None) => -1\n }\n )\n }\n}\n"}, {"source_code": "//package com.obarros.hackerrank.codechallenges.daysofcode.codeforces.Round_408\n\n\nobject ProblemA {\n def main(args: Array[String]): Unit = {\n val input = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n val n = input(0)\n val m = input(1)\n val k = input(2)\n val houses = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n System.out.println(solution(n, m, k, houses))\n }\n\n def solution(n: Int, m: Int, k: Int, houses: Array[Int]): Int = {\n\n var result = Int.MaxValue\n for (i <- houses.indices) {\n if (houses(i) != 0 && houses(i) <= k)\n result = math.min(result, 10*math.abs(m -1 - i))\n }\n result\n }\n}\n\n"}, {"source_code": "\n/**\n * Created by ruslan on 3/29/17.\n */\nobject ProblemA extends App {\n import java.io.{BufferedReader, IOException, InputStreamReader, PrintWriter}\nimport java.util.StringTokenizer\n\n val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))\n val out = new PrintWriter(System.out)\n\n class FastScanner(val in: BufferedReader) {\n var st: StringTokenizer = _;\n\n def nextToken(): String = {\n while (st == null || !st.hasMoreTokens()) {\n st = new StringTokenizer(in.readLine);\n }\n return st.nextToken();\n }\n\n def nextInt(): Integer = {\n Integer.parseInt(nextToken());\n }\n\n def nextLong(): Long = {\n nextToken().toLong;\n }\n\n def nextDouble(): Double = {\n nextToken().toDouble;\n }\n }\n\n val n = in.nextInt()\n val m = in.nextInt()\n\n val k = in.nextInt()\n\n var res = n + 1\n\n for (i <- 1 to n) {\n val emount = in.nextInt()\n if (emount != 0 && emount <= k && Math.abs(i - m) < res) {\n res = Math.abs(i - m)\n }\n }\n\n println(res * 10)\n\n}\n"}], "negative_code": [{"source_code": "import scala.io.Source\nimport scala.math._\n\nobject a12 {\n def main(args: Array[String]): Unit = {\n val lines = Source.stdin.getLines().take(2).map(_.split(' ').map(_.toInt)).toArray\n val Array(n,k,l) = lines(0)\n val (bb,cc) = lines(1).zipWithIndex.splitAt(k-1)\n val (b,c) = (bb.filter(_._1!=0).reverse.dropWhile(_._1 > l).headOption,\n cc.tail.filter( _._1!=0).dropWhile(_._1 > l).headOption)\n println(\n (b,c) match {\n case (Some(a), Some(b)) => min(k-a._2, b._2-k)*10\n case (Some(d),None) => (k-1 - d._2)*10\n case (None, Some(d)) => (d._2 - k+1)*10\n case (None,None) => -1\n }\n )\n }\n}\n"}, {"source_code": "//package com.obarros.hackerrank.codechallenges.daysofcode.codeforces.Round_408\n\n\nobject ProblemA {\n def main(args: Array[String]): Unit = {\n val input = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n val m = input(0)\n val n = input(1)\n val k = input(2)\n val houses = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n var cond: Array[Int] = Array[Int]()\n var res: Array[Int] = Array[Int]()\n\n for (i <- houses.indices) {\n if (houses(i) <= k && i != n && i != 0)\n cond :+= 1\n else\n cond :+= 0\n }\n\n for (j <- houses.indices) {\n res :+= cond(j) * (j + 1) * 10\n }\n\n val reset = n * 10\n val result = {\n res.filter(x => x != 0).map(x => math.abs(x - reset)).min\n }\n\n\n System.out.println(result)\n }\n\n}"}, {"source_code": "//package com.obarros.hackerrank.codechallenges.daysofcode.codeforces.Round_408\n\n\nobject ProblemA {\n def main(args: Array[String]): Unit = {\n val input = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n val m = input(0)\n val n = input(1)\n val k = input(2)\n val houses = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n var cond: Array[Int] = Array[Int]()\n var res: Array[Int] = Array[Int]()\n\n for (i <- houses.indices) {\n if (houses(i) <= k && i != n && i != 0)\n cond :+= 1\n else\n cond :+= 0\n }\n\n for (j <- houses.indices) {\n res :+= cond(j) * (j + 1) * 10\n }\n\n val reset = n * 10\n val result = {\n res.map(x => x - reset).filter(x => x != 0).map(x => math.abs(x)).min\n }\n\n\n System.out.println(result)\n }\n\n}"}, {"source_code": "//package com.obarros.hackerrank.codechallenges.daysofcode.codeforces.Round_408\n\n\nobject ProblemA {\n def main(args: Array[String]): Unit = {\n val input = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n val m = input(0)\n val n = input(1)\n val k = input(2)\n val houses = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n var cond: Array[Int] = Array[Int]()\n var res: Array[Int] = Array[Int]()\n\n for (i <- houses.indices) {\n if (houses(i) <= k && i != n && houses(i) != 0)\n cond :+= 1\n else\n cond :+= 0\n }\n\n for (j <- houses.indices) {\n res :+= cond(j) * (j + 1) * 10\n }\n\n// System.out.println(\"cond: \")\n// cond.foreach(x => print(x + \" \"))\n// System.out.println()\n// System.out.println(\"res: \")\n// res.foreach(x => print(x + \" \"))\n// System.out.println()\n\n val reset = n * 10\n val result = {\n res.filter(x => x != 0 ).map(x => math.abs(x - reset)).filter(x => x != 0 ).min\n }\n\n\n System.out.println(result)\n }\n\n}"}, {"source_code": "//package Round_408\n\n/**\n * Created by OMVB on 10/04/2017.\n */\nobject Problem_A {\n def main(args: Array[String]): Unit = {\n val input = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n val m = input(0)\n val n = input(1)\n val k = input(2)\n val houses = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n var cond: Array[Int] = Array[Int]()\n var res: Array[Int] = Array[Int]()\n\n for (i <- houses.indices) {\n if (houses(i) <= k && i != n && i != 0)\n cond :+= 1\n else\n cond :+= 0\n }\n\n for (j <- houses.indices) {\n res :+= cond(j) * (j + 1) * 10\n }\n\n val reset = n * 10\n val result = {\n res.map(x => x - reset).filter(x => x > 0 && x != 0 && x != m).min\n }\n\n System.out.println(result)\n }\n\n}\n"}], "src_uid": "57860e9a5342a29257ce506063d37624"} {"nl": {"description": "One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing x by m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory. The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by m). Given the number of details a on the first day and number m check if the production stops at some moment.", "input_spec": "The first line contains two integers a and m (1 ≤ a, m ≤ 105).", "output_spec": "Print \"Yes\" (without quotes) if the production will eventually stop, otherwise print \"No\".", "sample_inputs": ["1 5", "3 6"], "sample_outputs": ["No", "Yes"], "notes": null}, "positive_code": [{"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n var Array(a, m) = in.next().split(\" \").map(_.toInt)\n var visited = Set.empty[Int]\n while (!visited(a) && a != 0) {\n visited += a\n a = 2 * a % m\n }\n if (a == 0)\n println(\"Yes\")\n else\n println(\"No\")\n}"}], "negative_code": [{"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n var Array(a, m) = in.next().split(\" \").map(_.toInt)\n var visited = Set.empty[Int]\n while (!visited(a) && a != 0) {\n visited += a\n a = 2 * a % m\n }\n if (a == 0)\n println(\"YES\")\n else\n println(\"NO\")\n}"}], "src_uid": "f726133018e2149ec57e113860ec498a"} {"nl": {"description": "Polycarp plays \"Game 23\". Initially he has a number $$$n$$$ and his goal is to transform it to $$$m$$$. In one move, he can multiply $$$n$$$ by $$$2$$$ or multiply $$$n$$$ by $$$3$$$. He can perform any number of moves.Print the number of moves needed to transform $$$n$$$ to $$$m$$$. Print -1 if it is impossible to do so.It is easy to prove that any way to transform $$$n$$$ to $$$m$$$ contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation).", "input_spec": "The only line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le m \\le 5\\cdot10^8$$$).", "output_spec": "Print the number of moves to transform $$$n$$$ to $$$m$$$, or -1 if there is no solution.", "sample_inputs": ["120 51840", "42 42", "48 72"], "sample_outputs": ["7", "0", "-1"], "notes": "NoteIn the first example, the possible sequence of moves is: $$$120 \\rightarrow 240 \\rightarrow 720 \\rightarrow 1440 \\rightarrow 4320 \\rightarrow 12960 \\rightarrow 25920 \\rightarrow 51840.$$$ The are $$$7$$$ steps in total.In the second example, no moves are needed. Thus, the answer is $$$0$$$.In the third example, it is impossible to transform $$$48$$$ to $$$72$$$."}, "positive_code": [{"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 REP(30) { two =>\n REP(18) { three =>\n val a = math.round(math.pow(2, two))\n val b = math.round(math.pow(3, three))\n debug(s\"$a $b\")\n if (M % a == 0 && M % b == 0 && M / a / b == N) {\n out.println(s\"${two + three}\")\n return\n }\n }\n }\n\n out.println(-1)\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"}, {"source_code": "import java.util.Scanner\n\nobject Main {\n\n def main(args: Array[String]): Unit = {\n val sc = new Scanner(System.in)\n val n = sc.nextInt()\n val m = sc.nextInt()\n if(n == m)\n println(0)\n\n else if(n % 2 == 0 && m % 2 == 1)\n println(-1)\n\n else if(m % n == 0){\n var division = m / n\n var res = 0;\n while(division % 3 == 0){\n division = division / 3\n res += 1\n }\n while (division % 2 == 0){\n division = division / 2\n res += 1\n }\n if(division == 1)\n println(res)\n else\n println(-1)\n }\n else\n println(-1)\n }\n}\n"}, {"source_code": "object _1141A 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, m = io.read[Int]\n val ans = if (m%n == 0) {\n var r = m/n\n var c = 0\n while(r%3 == 0) {\n r /= 3\n c += 1\n }\n while(r%2 == 0) {\n r /= 2\n c += 1\n }\n if (r == 1) Some(c) else None\n } else {\n None\n }\n \n io.write(ans.getOrElse(-1))\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 writeLines(obj: Traversable[Any]): this.type = writeAll(obj, separator = \"\\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"}, {"source_code": "object Competitive extends App {\n val Array(x,y) = readLine.split(\" \").map(_.toInt)\n if(x==y) println(0)\n else if(y%x!=0) println(-1)\n else {\n var z = y / x\n var count = 0\n var stat = 1\n while(z>1) {\n if(z%2!=0 && z%3!=0) {\n stat = 0\n z = 1\n }\n else {\n if(z%2==0) z/=2\n else if(z%3==0) z/=3\n count+=1\n }\n }\n if(stat==0) println(-1)\n else println(count)\n }\n\n}\n"}, {"source_code": "\nimport scala.annotation.tailrec\n\nobject Main extends App {\n\n val inputs = io.StdIn.readLine().split(\" \").map(x => x.toInt)\n\n def solve(i: Int, i1: Int): Int = {\n @tailrec\n def solve(a: Int, acc: Int = 0): Int = {\n if (a == 1) acc\n else if (a == -1) -1\n else solve(if (a % 3 == 0) a / 3 else if (a % 2 == 0) a / 2 else -1, acc + 1)\n\n }\n\n if (i1 % i != 0) -1\n else solve(i1 / i)\n }\n\n println(solve(inputs(0), inputs(1)))\n\n\n}\n"}, {"source_code": "\nobject Main extends App {\n\n val inputs = io.StdIn.readLine().split(\" \").map(x => x.toInt)\n\n def solve(i: Int, i1: Int): Int = {\n def solve(a: Int, acc: Int = 0): Int = {\n if (a == 1) acc\n else if (a == -1) -1\n else solve(if (a % 3 == 0) a / 3 else if (a % 2 == 0) a / 2 else -1, acc + 1)\n\n }\n\n if (i1 % i != 0) -1\n else solve(i1 / i)\n }\n\n println(solve(inputs(0), inputs(1)))\n\n\n}"}], "negative_code": [{"source_code": "object Main extends App {\n\n val inputs = io.StdIn.readLine().split(\" \").map(x => x.toInt)\n\n def solve(i: Int, i1: Int) : Int = {\n def solve(a: Int, acc: Int = 0): Int = {\n if (a == 1) acc\n else solve(if (a % 3 == 0) a / 3 else a / 2, acc + 1)\n\n }\n if (i1 % i != 0) -1\n else solve(i1 / i)\n }\n\n println(solve(inputs(0),inputs(1)))\n\n\n}\n"}, {"source_code": "object Main extends App {\n\n val inputs = io.StdIn.readLine().split(\" \").map(x => x.toInt)\n\n def solve(i: Int, i1: Int): Int = {\n def solve(a: Int, acc: Int = 0): Int = {\n if (a == 1) acc\n else solve(if (a % 3 == 0) a / 3 else a / 2, acc + 1)\n\n }\n\n if (i1 % i != 0) -1\n else if (i == i1) 0\n else if (i1 % 2 != 0 && i1 % 3 != 0) -1\n else solve(i1 / i)\n }\n\n println(solve(inputs(0), inputs(1)))\n\n\n}"}], "src_uid": "3f9980ad292185f63a80bce10705e806"} {"nl": {"description": "Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food: on Mondays, Thursdays and Sundays he eats fish food; on Tuesdays and Saturdays he eats rabbit stew; on other days of week he eats chicken stake. Polycarp plans to go on a trip and already packed his backpack. His backpack contains: $$$a$$$ daily rations of fish food; $$$b$$$ daily rations of rabbit stew; $$$c$$$ daily rations of chicken stakes. Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.", "input_spec": "The first line of the input contains three positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \\le a, b, c \\le 7\\cdot10^8$$$) — the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly.", "output_spec": "Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.", "sample_inputs": ["2 1 1", "3 2 2", "1 100 1", "30 20 10"], "sample_outputs": ["4", "7", "3", "39"], "notes": "NoteIn the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday — rabbit stew and during Wednesday — chicken stake. So, after four days of the trip all food will be eaten.In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack.In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be $$$99$$$ portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip."}, "positive_code": [{"source_code": "import scala.annotation.tailrec\nimport scala.io.StdIn._\n\nobject GourmetCat {\n \n @tailrec\n def gormetCat(m: Map[Int, Int], mToWeekD: Map[Int, Int], index: Int = 0, result: Int = 0): Int = {\n val i = mToWeekD.getOrElse(index % 7, 0)\n if(m.getOrElse(i, 0) == 0) {\n result\n } else {\n gormetCat(m.updated(i, m.getOrElse(i, 0) - 1), mToWeekD, index+1, result+1)\n }\n }\n \n @tailrec\n def reduceCatFood(fishFood: Int, rabbitStew: Int, chickenStake: Int, result: Int = 0): (Int, Int, Int, Int) = {\n if(fishFood > 3 && rabbitStew > 3 && chickenStake > 3) {\n reduceCatFood(fishFood - 3, rabbitStew - 2, chickenStake - 2, result + 7)\n } else (fishFood, rabbitStew, chickenStake, result)\n }\n \n \n def main(args: Array[String]): Unit = {\n val Array(fishFood, rabbitStew, chickenStake) = readLine.split(\" \").map(_.toInt)\n \n \n val (reducedFishFood, reducedRabbitStew, reducedChickenStake, prelimResult) =\n reduceCatFood(fishFood, rabbitStew, chickenStake)\n val m = Map[Int, Int]().updated(0, reducedFishFood).\n updated(1, reducedRabbitStew).updated(2, reducedChickenStake)\n val mToWeekD = Map[Int, Int]((0, 0), (1, 1), (2, 2),\n (3, 0), (4,2), (5,1),(6,0))\n \n \n println((0 to 6).map(gormetCat(m, mToWeekD, _, prelimResult)).max)\n }\n}\n"}], "negative_code": [], "src_uid": "e17df52cc0615585e4f8f2d31d2daafb"} {"nl": {"description": "Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate. Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number x is the notation of form AeB, where A is a real number and B is an integer and x = A × 10B is true. In our case A is between 0 and 9 and B is non-negative.Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding.", "input_spec": "The first and only line of input contains a single string of form a.deb where a, d and b are integers and e is usual character 'e' (0 ≤ a ≤ 9, 0 ≤ d < 10100, 0 ≤ b ≤ 100) — the scientific notation of the desired distance value. a and b contain no leading zeros and d contains no trailing zeros (but may be equal to 0). Also, b can not be non-zero if a is zero.", "output_spec": "Print the only real number x (the desired distance value) in the only line in its decimal notation. Thus if x is an integer, print it's integer value without decimal part and decimal point and without leading zeroes. Otherwise print x in a form of p.q such that p is an integer that have no leading zeroes (but may be equal to zero), and q is an integer that have no trailing zeroes (and may not be equal to zero).", "sample_inputs": ["8.549e2", "8.549e3", "0.33e0"], "sample_outputs": ["854.9", "8549", "0.33"], "notes": null}, "positive_code": [{"source_code": "object Solution {\n def main(args : Array[String]) {\n val line = readLine()\n val r = \"^(.*)\\\\.(.*)e(.*)$\"r;\n val r(a, d, e) = line\n var n = a + d\n val i = e.toInt\n if (n.size < 1 + i) n = n + (\"0\" * (i + 1 - n.size))\n n = n.substring(0, i + 1) + \".\" + n.substring(i + 1);\n println(post(n));\n }\n def post(s:String) :String = {\n if (s.startsWith(\"0\") && !s.startsWith(\"0.\"))\n post(s.substring(1))\n else if (s.matches(\".*\\\\.0*\")) s.substring(0,s.indexOf('.'))\n else s\n }\n}"}, {"source_code": "import scala.io.StdIn._ \nimport scala.util.control._\n\nobject cf697B {\n def main (args: Array[String]) {\n val line = readLine()\n\n var b:Int = 0;\n var ex_e = false\n\n for (i <- 0 until line.length()) {\n if (ex_e == true) {\n b = b * 10 + line(i) - '0'\n }\n if (line(i) == 'e') ex_e = true\n }\n\n // println(b) \n var ex_point = false\n var buf = new StringBuilder()\n\n var loop = new Breaks\n loop.breakable {\n for (i <- 0 until line.length()) {\n if (line(i) == 'e') {\n if (b > 0) {\n while (b > 0) {\n buf += '0'\n b = b - 1\n }\n buf += '.' \n }\n loop.break\n }\n\n if (ex_point == true) {\n if (b == 0) {\n buf += '.'\n }\n buf += line(i)\n b = b - 1\n } else {\n if (line(i) == '.') {\n ex_point = true\n } else {\n buf += line(i)\n }\n }\n }\n }\n \n var pos: Int = 0\n // println(buf)\n loop.breakable {\n for (i <- 0 until buf.length()) {\n var j = buf.length() - i - 1;\n if (buf(j) == '.') {\n pos = j\n loop.break\n }\n if (buf(j) != '0') {\n pos = j + 1\n loop.break\n }\n }\n }\n // println(\"pos \" + pos) \n var flag = false\n\n for (i <- 0 until pos) {\n if (flag == true) {\n if (buf(i) == '.' && i == buf.length()-1) {\n } else {\n print(buf(i))\n }\n } else {\n if (buf(i) != '0') {\n print(buf(i))\n flag = true\n } else if (buf(i + 1) == '.' ) {\n print(buf(i));\n flag = true\n } \n }\n }\n println() \n }\n}"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n val Array(ns, es) = line.split('e')\n val (ne, ee) = ns.split('.') match {\n case Array(before, after) =>\n val afterDrop = after.reverse.dropWhile(_ == '0').reverse\n (before + afterDrop, -afterDrop.length)\n case Array(before) => (before, 0)\n }\n val e = ee + es.toInt\n\n if (e == 0)\n println(ne)\n else if (e < 0)\n println(ne.take(ne.length + e) + '.' + ne.drop(ne.length + e))\n else\n println(ne + \"0\" * e)\n}\n"}], "negative_code": [{"source_code": "import scala.io.StdIn._ \nimport scala.util.control._\n\nobject cf697B {\n def main (args: Array[String]) {\n val line = readLine()\n\n var b:Int = 0;\n var ex_e = false\n\n for (i <- 0 until line.length()) {\n if (ex_e == true) {\n b = b * 10 + line(i) - '0'\n }\n if (line(i) == 'e') ex_e = true\n }\n\n // println(b) \n var ex_point = false\n var buf = new StringBuilder()\n\n var loop = new Breaks\n loop.breakable {\n for (i <- 0 until line.length()) {\n if (line(i) == 'e') {\n while (b > 0) {\n buf += '0'\n b = b - 1\n }\n buf += '.'\n loop.break\n }\n\n if (ex_point == true) {\n if (b == 0) {\n buf += '.'\n }\n buf += line(i)\n b = b - 1\n } else {\n if (line(i) == '.') {\n ex_point = true\n } else {\n buf += line(i)\n }\n }\n }\n }\n \n var pos: Int = 0\n // println(buf)\n loop.breakable {\n for (i <- 0 until buf.length()) {\n var j = buf.length() - i - 1;\n if (buf(j) == '.') {\n pos = j\n loop.break\n }\n if (buf(j) != '0') {\n pos = j + 1\n loop.break\n }\n }\n }\n // println(\"pos \" + pos) \n var flag = false\n\n for (i <- 0 until pos) {\n if (flag == true) {\n if (buf(i) == '.' && i == buf.length()-1) {\n } else {\n print(buf(i))\n }\n } else {\n if (buf(i) != '0') {\n print(buf(i))\n flag = true\n } else if (buf(i + 1) == '.' ) {\n print(buf(i));\n flag = true\n } \n }\n }\n println() \n }\n}"}, {"source_code": "import scala.io.StdIn._ \nimport scala.util.control._\n\nobject cf697B {\n def main (args: Array[String]) {\n val line = readLine()\n\n var b:Int = 0;\n var ex_e = false\n\n for (i <- 0 until line.length()) {\n if (ex_e == true) {\n b = b * 10 + line(i) - '0'\n }\n if (line(i) == 'e') ex_e = true\n }\n\n // println(b) \n var ex_point = false\n var buf = new StringBuilder()\n\n var loop = new Breaks\n loop.breakable {\n for (i <- 0 until line.length()) {\n if (line(i) == 'e') {\n while (b > 0) {\n buf += '0'\n b = b - 1\n }\n loop.break\n }\n\n if (ex_point == true) {\n if (b == 0) {\n buf += '.'\n }\n buf += line(i)\n b = b - 1\n } else {\n if (line(i) == '.') {\n ex_point = true\n } else {\n buf += line(i)\n }\n }\n }\n }\n \n var pos: Int = 0\n // println(buf)\n loop.breakable {\n for (i <- 0 until buf.length()) {\n var j = buf.length() - i - 1;\n if (buf(j) != '0') {\n pos = j\n loop.break;\n }\n }\n }\n // println(\"pos \" + pos) \n var flag = false\n\n for (i <- 0 until pos) {\n if (flag == true) {\n if (buf(i) == '.' && i == buf.length()-1) {\n } else {\n print(buf(i))\n }\n } else {\n if (buf(i) != '0') {\n print(buf(i))\n flag = true\n } else if (buf(i + 1) == '.' ) {\n print(buf(i));\n flag = true\n } \n }\n }\n println()\n/*\n val loop = new Breaks;\n loop.breakable {\n for (i <- 0 until buf.length()) {\n if (buf(i) == 'e') loop.break\n print(buf(i))\n }\n println()\n }\n*/\n \n }\n}"}, {"source_code": "import scala.io.StdIn._ \nimport scala.util.control._\n\nobject cf697B {\n def main (args: Array[String]) {\n val line = readLine()\n\n var b:Int = 0;\n var ex_e = false\n\n for (i <- 0 until line.length()) {\n if (ex_e == true) {\n b = b * 10 + line(i) - '0'\n }\n if (line(i) == 'e') ex_e = true\n }\n\n // println(b) \n var ex_point = false\n var buf = new StringBuilder()\n\n var loop = new Breaks\n loop.breakable {\n for (i <- 0 until line.length()) {\n if (line(i) == 'e') {\n while (b > 0) {\n buf += '0'\n b = b - 1\n }\n loop.break\n }\n\n if (ex_point == true) {\n if (b == 0) {\n buf += '.'\n }\n buf += line(i)\n b = b - 1\n } else {\n if (line(i) == '.') {\n ex_point = true\n } else {\n buf += line(i)\n }\n }\n }\n }\n \n // println(buf)\n\n var flag = false\n\n for (i <- 0 until buf.length()) {\n if (flag == true) {\n if (buf(i) == '.' && i == buf.length()-1) {\n } else {\n print(buf(i))\n }\n } else {\n if (buf(i) != '0') {\n print(buf(i))\n flag = true\n } else if (buf(i + 1) == '.' ) {\n print(buf(i));\n flag = true\n } \n }\n }\n println()\n/*\n val loop = new Breaks;\n loop.breakable {\n for (i <- 0 until buf.length()) {\n if (buf(i) == 'e') loop.break\n print(buf(i))\n }\n println()\n }\n*/\n \n }\n}"}, {"source_code": "import scala.io.StdIn._ \nimport scala.util.control._\n\nobject cf697B {\n def main (args: Array[String]) {\n val line = readLine()\n\n var b:Int = 0;\n var ex_e = false\n\n for (i <- 0 until line.length()) {\n if (ex_e == true) {\n b = b * 10 + line(i) - '0'\n }\n if (line(i) == 'e') ex_e = true\n }\n\n // println(b) \n var ex_point = false\n var buf = new StringBuilder()\n\n var loop = new Breaks\n loop.breakable {\n for (i <- 0 until line.length()) {\n if (line(i) == 'e') {\n while (b > 0) {\n buf += '0'\n b = b - 1\n }\n loop.break\n }\n\n if (ex_point == true) {\n if (b == 0) {\n buf += '.'\n }\n buf += line(i)\n b = b - 1\n } else {\n if (line(i) == '.') {\n ex_point = true\n } else {\n buf += line(i)\n }\n }\n }\n }\n \n var pos: Int = 0\n // println(buf)\n loop.breakable {\n for (i <- 0 until buf.length()) {\n var j = buf.length() - i - 1;\n if (buf(j) == '.') {\n pos = j\n loop.break\n }\n if (buf(j) != '0') {\n pos = j + 1\n loop.break\n }\n }\n }\n // println(\"pos \" + pos) \n var flag = false\n\n for (i <- 0 until pos) {\n if (flag == true) {\n if (buf(i) == '.' && i == buf.length()-1) {\n } else {\n print(buf(i))\n }\n } else {\n if (buf(i) != '0') {\n print(buf(i))\n flag = true\n } else if (buf(i + 1) == '.' ) {\n print(buf(i));\n flag = true\n } \n }\n }\n println() \n }\n}"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n val Array(ns, es) = line.split('e')\n val n = ns.toDouble\n val e = es.toInt\n val ans = n * Math.pow(10, e)\n if (ans == ans.toInt)\n println(ans.toInt)\n else\n println(ans)\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n val Array(ns, es) = line.split('e')\n val n = ns.toDouble\n val e = es.toInt\n println(n * Math.pow(10, e))\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n val Array(ns, es) = line.split('e')\n val n = ns.filter(_ != '.')\n val eee = ns.indexOf('.')\n val ee = if (eee == -1) 0 else eee\n val e = es.toInt + ee + n.reverse.takeWhile(_ == '0').length\n val ne = n.reverse.dropWhile(_ == '0').reverse\n\n\n if (e == ne.length)\n println(ne)\n else if (e < ne.length)\n println(ne.take(e) + '.' + n.drop(e))\n else\n println(ne + \"0\" * (e - ne.length))\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n val Array(ns, es) = line.split('e')\n val (ne, ee) = ns.split('.') match {\n case Array(before, after) =>\n val afterDrop = after.reverse.dropWhile(_ == 0).reverse\n (before + afterDrop, -afterDrop.length)\n case Array(before) => (before, 0)\n }\n val e = ee + es.toInt\n\n if (e == 0)\n println(ne)\n else if (e < ne.length)\n println(ne.take(ne.length + e) + '.' + ne.drop(ne.length + e))\n else\n println(ne + \"0\" * (e - ne.length))\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n val Array(ns, es) = line.split('e')\n val (ne, ee) = ns.split('.') match {\n case Array(before, after) =>\n val afterDrop = after.reverse.dropWhile(_ == 0).reverse\n (before + afterDrop, -afterDrop.length)\n case Array(before) => (before, 0)\n }\n val e = ee + es.toInt\n\n println(e)\n\n if (e == 0)\n println(ne)\n else if (e < 0)\n println(ne.take(ne.length + e) + '.' + ne.drop(ne.length + e))\n else\n println(ne + \"0\" * e)\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n val Array(ns, es) = line.split('e')\n val (ne, ee) = ns.split('.') match {\n case Array(before, after) =>\n val afterDrop = after.reverse.dropWhile(_ == 0).reverse\n (before + afterDrop, -afterDrop.length)\n case Array(before) => (before, 0)\n }\n val e = ee + es.toInt\n if (e == ne.length)\n println(ne)\n else if (e < ne.length)\n println(ne.take(ne.length + e) + '.' + ne.drop(ne.length + e))\n else\n println(ne + \"0\" * (e - ne.length))\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n val Array(ns, es) = line.split('e')\n val (ne, ee) = ns.split('.') match {\n case Array(before, after) =>\n val afterDrop = after.reverse.dropWhile(_ == 0).reverse\n (before + afterDrop, -afterDrop.length)\n case Array(before) => (before, 0)\n }\n val e = ee + es.toInt\n\n println(e)\n\n if (e == ne.length)\n println(ne)\n else if (e < ne.length)\n println(ne.take(ne.length + e) + '.' + ne.drop(ne.length + e))\n else\n println(ne + \"0\" * (e - ne.length))\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n val Array(ns, es) = line.split('e')\n val n = ns.filter(_ != '.')\n val eee = ns.indexOf('.')\n val ee = if (eee == -1) 0 else eee\n val e = es.toInt + ee\n println(n.take(e) + '.' + n.drop(e))\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n val Array(ns, es) = line.split('e')\n val n = ns.filter(_ != '.')\n val eee = ns.indexOf('.')\n val ee = if (eee == -1) 0 else eee\n val e = es.toInt - ee + n.reverse.takeWhile(_ == '0').length\n val ne = n.reverse.dropWhile(_ == '0').reverse\n\n\n if (e == ne.length)\n println(ne)\n else if (e < ne.length)\n println(ne.take(e) + '.' + n.drop(e))\n else\n println(ne + \"0\" * (e - ne.length))\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n val Array(ns, es) = line.split('e')\n val (ne, ee) = ns.split('.') match {\n case Array(before, after) =>\n val afterDrop = after.reverse.dropWhile(_ == 0).reverse\n (before + afterDrop, -afterDrop.length)\n case Array(before) => (before, 0)\n }\n val e = ee + es.toInt\n\n if (e == 0)\n println(ne)\n else if (e < 0)\n println(ne.take(ne.length + e) + '.' + ne.drop(ne.length + e))\n else\n println(ne + \"0\" * e)\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n val Array(ns, es) = line.split('e')\n val (ne, ee) = ns.split('.') match {\n case Array(before, after) =>\n val afterDrop = after.reverse.dropWhile(_ == 0).reverse\n (before + afterDrop, -afterDrop.length)\n case Array(before) => (before, 0)\n }\n val e = ee + es.toInt\n\n println(e)\n\n if (e == 0)\n println(ne)\n else if (e < ne.length)\n println(ne.take(ne.length + e) + '.' + ne.drop(ne.length + e))\n else\n println(ne + \"0\" * (e - ne.length))\n}\n"}, {"source_code": "object Solution extends App {\n val in = io.Source.stdin.getLines()\n val line = in.next()\n val Array(ns, es) = line.split('e')\n val n = ns.filter(_ != '.')\n val eee = ns.indexOf('.')\n val ee = if (eee == -1) 0 else eee\n val e = es.toInt + ee + n.reverse.takeWhile(_ == '0').length\n val ne = n.reverse.dropWhile(_ == '0').reverse\n\n\n if (e == ne.length)\n println(ne)\n else if (e < ne.length)\n println(ne.take(e) + '.' + n.drop(e))\n else\n println(ne + \"0\" * (e - ne.length + 1))\n}\n"}], "src_uid": "a79358099f08f3ec50c013d47d910eef"} {"nl": {"description": "Little Petya was given this problem for homework:You are given function (here represents the operation of taking the remainder). His task is to count the number of integers x in range [a;b] with property f(x) = x.It is a pity that Petya forgot the order in which the remainders should be taken and wrote down only 4 numbers. Each of 24 possible orders of taking the remainder has equal probability of being chosen. For example, if Petya has numbers 1, 2, 3, 4 then he can take remainders in that order or first take remainder modulo 4, then modulo 2, 3, 1. There also are 22 other permutations of these numbers that represent orders in which remainder can be taken. In this problem 4 numbers wrote down by Petya will be pairwise distinct.Now it is impossible for Petya to complete the task given by teacher but just for fun he decided to find the number of integers with property that probability that f(x) = x is not less than 31.4159265352718281828459045%. In other words, Petya will pick up the number x if there exist at least 7 permutations of numbers p1, p2, p3, p4, for which f(x) = x.", "input_spec": "First line of the input will contain 6 integers, separated by spaces: p1, p2, p3, p4, a, b (1 ≤ p1, p2, p3, p4 ≤ 1000, 0 ≤ a ≤ b ≤ 31415). It is guaranteed that numbers p1, p2, p3, p4 will be pairwise distinct.", "output_spec": "Output the number of integers in the given range that have the given property.", "sample_inputs": ["2 7 1 8 2 8", "20 30 40 50 0 100", "31 41 59 26 17 43"], "sample_outputs": ["0", "20", "9"], "notes": null}, "positive_code": [{"source_code": "object Main {\n def main(args: Array[String]) {\n val Array(p1, p2, p3, p4, a, b) = readLine().split(\" \").map(_.toInt)\n val p = Array(p1, p2, p3, p4).min\n println((p - a).min(b - a + 1).max(0))\n }\n}"}], "negative_code": [{"source_code": "object Main {\n def main(args: Array[String]) {\n val Array(p1, p2, p3, p4, a, b) = readLine().split(\" \").map(_.toInt)\n val p = Array(p1, p2, p3, p4).min\n println((p - a).max(0))\n }\n}"}], "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a"} {"nl": {"description": "There are n cards (n is even) in the deck. Each card has a positive integer written on it. n / 2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player. Find the way to distribute cards such that the sum of values written of the cards will be equal for each player. It is guaranteed that it is always possible.", "input_spec": "The first line of the input contains integer n (2 ≤ n ≤ 100) — the number of cards in the deck. It is guaranteed that n is even. The second line contains the sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is equal to the number written on the i-th card.", "output_spec": "Print n / 2 pairs of integers, the i-th pair denote the cards that should be given to the i-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input. It is guaranteed that solution exists. If there are several correct answers, you are allowed to print any of them.", "sample_inputs": ["6\n1 5 7 4 4 3", "4\n10 10 10 10"], "sample_outputs": ["1 3\n6 2\n4 5", "1 2\n3 4"], "notes": "NoteIn the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8. In the second sample, all values ai are equal. Thus, any distribution is acceptable."}, "positive_code": [{"source_code": "import scala.io.StdIn._\n\nobject Main extends App {\n val n = readInt()\n val a = readLine().split(\" \").map(_.toInt).zipWithIndex.sorted\n val (f, s) = a.splitAt(n / 2)\n val ans = f.zip(s.reverse)\n for (((_, a), (_, b)) <- ans) println((a + 1) + \" \" + (b + 1))\n}"}, {"source_code": "object Solution extends App {\n val lines = io.Source.stdin.getLines()\n val n = lines.next().toInt\n val data = lines.next().split(' ').map(_.toInt).zipWithIndex.sorted\n println(data.take(n / 2).zip(data.drop(n / 2).reverse).map(a => s\"${a._1._2 + 1} ${a._2._2 + 1}\").mkString(\"\\n\"))\n}\n"}, {"source_code": "object A701 {\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).zipWithIndex.sortBy(_._1)\n for(i <- 1 to n/2) {\n println(s\"${input(i-1)._2 + 1} ${input(n-i)._2 + 1}\")\n }\n }\n}"}, {"source_code": "object main {\n def main (args: Array[String]) {\n val n = scala.io.StdIn.readInt()\n val input = (scala.io.StdIn.readLine().split(\" \") map (x => x.toInt)).toVector\n val inputWithIndex = input zip (1 to n)\n val sortedInputWithIndex = inputWithIndex.sortBy(pair => pair._1)\n (0 until n/2) map (\n i => println(sortedInputWithIndex(i)._2.toString + \" \" + sortedInputWithIndex(n - i - 1)._2).toString)\n }\n}"}, {"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 val xs = readInts(n).zipWithIndex.sortBy(_._1).map(_._2 + 1)\n\n for (i <- 0 until n / 2) println(s\"${xs(i)} ${xs(n - i - 1)}\")\n}"}, {"source_code": "import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._\n\nobject _701A extends CodeForcesApp {\n override def apply(io: IO) = {import io.{read, write, writeAll}\n val cards = read[Vector[Int]]\n val n = cards.length\n val used = mutable.Set.empty[Int]\n val sum = 2*cards.sum/n\n\n val cz = cards.zipWithIndex\n\n val ans = Vector.fill(n/2) {\n val Some((c1, i1)) = cz find {case (c, i) => !used(i)}\n used += i1\n val Some((c2, i2)) = cz find {case (c, i) => !used(i) && c + c1 == sum}\n used += i2\n //debug(i1, i2, c1, c2, sum)\n s\"${i1 + 1} ${i2 + 1}\"\n }\n\n writeAll(ans, \"\\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}\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 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 }\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 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 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 override def next() = tokenizer().get.nextToken()\n override def hasNext = tokenizer().nonEmpty\n\n def write(obj: Any, more: Any*): this.type = {\n printer.print(obj)\n more foreach {i =>\n printer.print(' ')\n printer.print(i)\n }\n this\n }\n def writeOnNextLine(obj: Any, more: Any*): this.type = {\n printer.println()\n write(obj, more: _*)\n this\n }\n def writeAll(obj: Traversable[Any], separator: String = \" \"): this.type = write(obj mkString separator)\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"}, {"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 dp = new Array[(Int, Int)](n)\n for(i <- 0 until n){\n val tmp = sc.nextInt()\n dp(i) = (tmp, i+1)\n }\n\n val ans = dp.sorted\n\n for(i <- 0 until n / 2){\n println(ans(i)._2 + \" \" + ans(n-1-i)._2)\n }\n }\n}\n"}, {"source_code": "object main extends App {\n import java.io.{InputStream, PrintStream}\n import java.util.Scanner\n// override\n def solve(input: InputStream, output: PrintStream): Unit = {\n val sc = new Scanner(input)\n val n = sc.nextInt()\n val cardsSorted = (1 to n).map(_ => sc.nextInt()).zipWithIndex.sortBy{case (v,_) => v}.toArray\n (1 to n/2).foreach{\n i => {\n val (_,firstIndex) = cardsSorted(i-1)\n val (_,secondIndex) = cardsSorted(n-i)\n output.println((firstIndex+1)+\" \"+(secondIndex+1))\n }\n }\n }\n solve(System.in,System.out)\n}"}], "negative_code": [{"source_code": "object Solution extends App {\n val lines = io.Source.stdin.getLines()\n val n = lines.next().toInt\n val data = lines.next().split(' ').map(_.toInt).zipWithIndex.sorted\n println(data.take(n / 2).zip(data.drop(n / 2)).map(a => s\"${a._1._2 + 1} ${a._2._2 + 1}\").mkString(\"\\n\"))\n}\n"}, {"source_code": "object Solution extends App {\n val lines = io.Source.stdin.getLines()\n val n = lines.next().toInt\n val data = lines.next().split(' ').map(_.toInt).sorted\n println(data.take(n / 2).zip(data.drop(n / 2)).map(a => s\"${a._1} ${a._2}\").mkString(\"\\n\"))\n}\n"}], "src_uid": "6e5011801ceff9d76e33e0908b695132"} {"nl": {"description": "Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of n commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the same square he starts in? Two substrings are considered different if they have different starting or ending indices.", "input_spec": "The first line of the input contains a single positive integer, n (1 ≤ n ≤ 200) — the number of commands. The next line contains n characters, each either 'U', 'R', 'D', or 'L' — Calvin's source code.", "output_spec": "Print a single integer — the number of contiguous substrings that Calvin can execute and return to his starting square.", "sample_inputs": ["6\nURLLDR", "4\nDLUU", "7\nRLRLRLR"], "sample_outputs": ["2", "0", "12"], "notes": "NoteIn the first case, the entire source code works, as well as the \"RL\" substring in the second and third characters.Note that, in the third case, the substring \"LR\" appears three times, and is therefore counted three times to the total result."}, "positive_code": [{"source_code": "\n/**\n * Created by octavian on 13/02/2016.\n */\nobject Calvin {\n\n def main(args: Array[String]) = {\n\n //System.setIn(new FileInputStream(\"./src/calvin.in\"))\n //System.setOut(new PrintStream(new FileOutputStream(\"./src/calvin.out\")))\n\n val n = readInt()\n val a: Array[Char] = readLine().toCharArray\n var res = 0\n for(i <- 0 until n - 1) {\n var x = 0\n var y = 0\n for(j <- i until n) {\n a(j) match {\n case 'R' => x = x + 1\n case 'L' => x = x - 1\n case 'D' => y = y + 1\n case 'U' => y = y - 1\n }\n if(x == 0 && y == 0) {\n res += 1\n }\n }\n }\n\n println(res)\n\n }\n\n}\n"}, {"source_code": "import scala.io.Source\n\nobject Main {\n def isOk(s: Seq[(Int, Int)]): Boolean = {\n var x = 0\n var y = 0\n s.foreach{t =>\n x += t._1\n y += t._2\n }\n x == 0 && y == 0\n }\n\n def run(in: Source): String = {\n val tuples = in.getLines().toSeq(1).map{\n case 'U' => (0, 1)\n case 'R' => (1, 0)\n case 'D' => (0, -1)\n case 'L' => (-1, 0)\n }\n val result = (1 to tuples.size).map{ size =>\n tuples.sliding(size).map(isOk).map {\n case false => 0\n case true => 1\n }.sum\n }.sum\n\n result.toString\n }\n\n //\n\n def readAll: String = {\n Source.fromInputStream(System.in).mkString\n }\n\n def main(args: Array[String]): Unit = {\n val in: Source = Source.fromString(readAll)\n print(run(in))\n }\n\n def test(string: String): String = {\n val in: Source = Source.fromString(string)\n run(in)\n }\n}"}, {"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 str = in.next()\n val lU = Array.ofDim[Int](str.length)\n val lD = Array.ofDim[Int](str.length)\n val lR = Array.ofDim[Int](str.length)\n val lL = Array.ofDim[Int](str.length)\n str.indices.foreach { i =>\n if (i != 0) {\n lU(i) = lU(i - 1)\n lD(i) = lD(i - 1)\n lR(i) = lR(i - 1)\n lL(i) = lL(i - 1)\n }\n if (str(i) == 'L') lL(i) += 1\n else if (str(i) == 'U') lU(i) += 1\n else if (str(i) == 'D') lD(i) += 1\n else lR(i) += 1\n }\n println(str.indices.foldLeft(0) { case (acc, start) =>\n (start + 1 until str.length by 2).foldLeft(acc) {\n case (a, end) =>\n val lCount = if (start == 0) lL(end) else lL(end) - lL(start - 1)\n val rCount = if (start == 0) lR(end) else lR(end) - lR(start - 1)\n val dCount = if (start == 0) lD(end) else lD(end) - lD(start - 1)\n val uCount = if (start == 0) lU(end) else lU(end) - lU(start - 1)\n\n if (lCount == rCount && dCount == uCount) a + 1 else a\n }\n })\n\n}"}, {"source_code": "import scala.collection._\n\nobject 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 var res = 0\n val Array(n) = readInts(1)\n val s = readLine\n\n for (i <- 0 until n) {\n for (j <- i + 1 to n) {\n val ss = s.substring(i, j)\n if (ss.count(_ == 'L') == ss.count(_ == 'R') && ss.count(_ == 'U') == ss.count(_ == 'D')) res += 1\n }\n }\n\n //FIXME Console.setOut(new java.io.BufferedOutputStream(Console.out))\n\n println(res)\n\n Console.flush\n}"}, {"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 def main(args: Array[String]) {\n val n = readLine().toInt\n val s = readLine()\n\n var res = 0\n\n for (i <- 0 to n-1) {\n var h = 0\n var v = 0\n for (j <- i to n-1) {\n if (s(j) == 'R') v += 1\n if (s(j) == 'L') v -= 1\n if (s(j) == 'U') h += 1\n if (s(j) == 'D') h -= 1\n\n if (v == 0 && h == 0) res += 1\n }\n }\n\n println(res)\n\n\n\n// Console.withOut(new java.io.BufferedOutputStream(Console.out))\n// println(res.mkString(\"\\n\"))\n// Console.flush\n }\n}"}, {"source_code": "import scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util._, control._\nimport scala.math.Ordering.Implicits._\n\nobject _626A extends CodeForcesApp {\n override type Result = Int\n\n override def solve(read: InputReader) = {\n val n = read[Int]\n val instr = read[String].toList\n var ans = 0\n for {\n i <- 0 until n\n j <- i+1 to n\n s = instr.slice(i, j)\n if isOkay(s)\n } ans += 1\n ans\n }\n\n @tailrec\n def isOkay(instr: List[Char], x: Int = 0, y: Int = 0): Boolean = instr match {\n case 'U' :: rest => isOkay(rest, x, y + 1)\n case 'D' :: rest => isOkay(rest, x, y - 1)\n case 'L' :: rest => isOkay(rest, x - 1, y)\n case 'R' :: rest => isOkay(rest, x + 1, y)\n case _ => x == 0 && y == 0\n }\n\n override def format(result: Result) = result.toString\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 {i <- 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[T1: Parser, T2: Parser] : Parser[(T1, T2)] = new Parser(r => (r[T1], r[T2]))\n implicit def tuple3[T1: Parser, T2: Parser, T3: Parser] : Parser[(T1, T2, T3)] = new Parser(r => (r[T1], r[T2], r[T3]))\n implicit def tuple4[T1: Parser, T2: Parser, T3: Parser, T4: Parser] : Parser[(T1, T2, T3, T4)] = new Parser(r => (r[T1], r[T2], r[T3], r[T4]))\n implicit def tuple5[T1: Parser, T2: Parser, T3: Parser, T4: Parser, T5: Parser] : Parser[(T1, T2, T3, T4, T5)] = new Parser(r => (r[T1], r[T2], r[T3], r[T4], r[T5]))\n}\n"}], "negative_code": [], "src_uid": "7bd5521531950e2de9a7b0904353184d"} {"nl": {"description": "Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.", "input_spec": "The first line contains four space-separated integers s1, s2, s3, s4 (1 ≤ s1, s2, s3, s4 ≤ 109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.", "output_spec": "Print a single integer — the minimum number of horseshoes Valera needs to buy.", "sample_inputs": ["1 7 3 3", "7 7 7 7"], "sample_outputs": ["1", "3"], "notes": null}, "positive_code": [{"source_code": "object Two28A extends App {\n\tval Array(s1, s2, s3, s4) = readLine.split(' ').map(_.toInt)\n\tval set = Set(s1, s2, s3, s4)\n\tprintln(4 - set.size)\n}"}, {"source_code": "import scala.io.StdIn\n\nobject Main extends App {\n val colors = StdIn.readLine().split(\" \").toList\n println(colors.size - colors.distinct.size)\n}"}, {"source_code": "object A {\n def main(args: Array[String]) {\n println(4 - readLine.split(\" \").distinct.size)\n }\n}\n"}, {"source_code": "object Solution228A extends App {\n\n def solution() {\n println(4 - 1.to(4).map(_ => _int).groupBy(i => i).size)\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}"}, {"source_code": "import scala.collection.mutable._\nimport scala.math._\nimport scala.util._\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 t = (for(i <- 1 to 4) yield sc.nextInt).toSet\n println(4 - t.size)\n}\n"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val data = in.next().split(\" \")\n println(data.length - data.distinct.length)\n}"}, {"source_code": "//package cf228\n\nobject A {\n\n def main(args: Array[String]) {\n val cs = readLine.split(' ').map(_.toInt)\n println((cs.map((_,1)).groupBy(_._1).toSeq.map(_._2.size) /:\\ 0){_+_-1})\n }\n\n}\n"}, {"source_code": "object A228 {\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 input = readInts(4).toSet\n println(4 - input.size)\n }\n}"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P228A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val shoes = Array.fill(4)(sc.nextInt)\n\n val answer: Int = 4 - shoes.groupBy(identity[Int]).size\n\n out.println(answer)\n out.close\n}\n"}, {"source_code": "\n\nobject Horseshoe {\n\tdef main (args: Array[String]) {\n\t\tval scanner = new java.util.Scanner(System.in);\n\t\tval set = Set(scanner.nextInt(),scanner.nextInt(),scanner.nextInt(),scanner.nextInt())\n\t\tprintln(4-set.size)\n\t}\n}"}, {"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 = 4 - readInts.groupBy(x => x).size\n\n def main(a: Array[String]) {\n println(ans)\n }\n}\n"}, {"source_code": "object test5 extends App {\n val s=readLine.split(\" \").map(_.toInt)\n println(4-s.groupBy(v=>v).size)\n} \n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val s = readLine().split(\" \").map(_.toInt).toSet\n println(4 - s.size)\n }\n}"}, {"source_code": "// Codeforces 228A\n\nobject _228A extends App {\n val scanner = new java.util.Scanner(System.in)\n val horseshoes = Array.fill(4)(scanner.nextInt)\n println(4-horseshoes.distinct.size)\n}\n\n"}, {"source_code": "\nimport scala.io.StdIn.readLine\nimport scala.io.StdIn.readInt\n\n\nobject HorseShoe {\n \n def readInts() : Array[Int] =\n readLine.split(' ').map(_.toInt)\n \n def main(args: Array[String]) {\n println(4 - readInts.toSet.size)\n }\n \n}"}, {"source_code": "\nobject Solution extends App {\n val hh = readLine.split(\" \").map(_.toInt)\n \n println(4 - hh.distinct.size)\n}"}, {"source_code": "\nobject A00228 extends App {\n def frequency[T](seq: Seq[T]) = seq.groupBy(identity).mapValues(_.size).withDefaultValue(0)\n def parseInt(str: String, count: Int): Seq[Long] = {\n val scanner = new java.util.Scanner(str)\n val res = (1 to count) map (_ => scanner.nextLong())\n scanner.close()\n res\n }\n def scanInts(count: Int): Seq[Long] = parseInt(Console.readLine, count)\n def readMatrix(row: Int, col: Int) = (1 to row) map (x => scanInts(col))\n\n val hooves = readMatrix(1, 4).head.toList\n println(4 - frequency(hooves).size)\n}"}], "negative_code": [{"source_code": "object A00228 extends App {\n def frequencyList[T](lst: List[T]) = {\n def iter(remLst: List[T], acc: List[(T, Int)]): List[(T, Int)] = (remLst, acc) match {\n case (Nil, l) => l.reverse\n case (x :: xs, Nil) => iter(xs, (x, 1) :: Nil)\n case (x :: xs, (last, count) :: ys) if x == last => iter(xs, (last, count + 1) :: ys)\n case (x :: xs, ys) => iter(xs, (x, 1) :: ys)\n }\n iter(lst, Nil)\n }\n\n def parseInt(str: String, count: Int): Seq[Long] = {\n val scanner = new java.util.Scanner(str)\n val res = (1 to count) map (_ => scanner.nextLong())\n scanner.close()\n res\n }\n def scanInts(count: Int): Seq[Long] = parseInt(Console.readLine, count)\n def readMatrix(row: Int, col: Int) = (1 to row) map (x => scanInts(col))\n\n println(4 - frequencyList(readMatrix(1, 4).head.toList).size)\n}\n"}], "src_uid": "38c4864937e57b35d3cce272f655e20f"} {"nl": {"description": "Mike is trying rock climbing but he is awful at it. There are n holds on the wall, i-th hold is at height ai off the ground. Besides, let the sequence ai increase, that is, ai < ai + 1 for all i from 1 to n - 1; we will call such sequence a track. Mike thinks that the track a1, ..., an has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height.Today Mike decided to cover the track with holds hanging on heights a1, ..., an. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1, 2, 3, 4, 5) and remove the third element from it, we obtain the sequence (1, 2, 4, 5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions.Help Mike determine the minimum difficulty of the track after removing one hold.", "input_spec": "The first line contains a single integer n (3 ≤ n ≤ 100) — the number of holds. The next line contains n space-separated integers ai (1 ≤ ai ≤ 1000), where ai is the height where the hold number i hangs. The sequence ai is increasing (i.e. each element except for the first one is strictly larger than the previous one).", "output_spec": "Print a single number — the minimum difficulty of the track after removing a single hold.", "sample_inputs": ["3\n1 4 6", "5\n1 2 3 4 5", "5\n1 2 3 7 8"], "sample_outputs": ["5", "2", "4"], "notes": "NoteIn the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.In the second test after removing every hold the difficulty equals 2.In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for which the difficulty is 4, 5 and 5, respectively. Thus, after removing the second element we obtain the optimal answer — 4."}, "positive_code": [{"source_code": "import java.util.StringTokenizer\n\nobject _496A 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 a = (1 to n).map(i => next.toInt)\n val d = (1 until n).map(i => a(i) - a(i - 1))\n var ans = d.max\n val dd = (1 until d.length).map(i => d(i) + d(i - 1))\n ans = ans max dd.min\n println(ans)\n}\n"}, {"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 var min = data.sliding(2).map{t => t.last - t.head}.max\n println(Math.max(data.sliding(3).map{t => t.last - t.head}.min, min))\n}"}, {"source_code": "object A496 {\n\n import IO._\n def drop(a: Int, arr: Array[Int]) = arr.take(a) ++ arr.drop(a+1)\n def main(args: Array[String]): Unit = {\n val Array(n) = readInts(1)\n val in = readInts(n)\n var res = Int.MaxValue\n for(i <- 1 to n-2) {\n val arr = drop(i, in.clone())\n var inter = 0\n for(j <- 1 until n-1) {\n //i+1 is removed\n inter = math.max(inter, arr(j)-arr(j-1))\n }\n res = math.min(res, inter)\n }\n\n println(res)\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"}, {"source_code": "object P496A {\n\tdef zipSub(a: List[Int], b: List[Int]) : List[Int] = {\n\t\treturn (a, b).zipped.map(_ - _)\n\t}\n\n\tdef main(args: Array[String]) {\n\t\tval n = scala.io.StdIn.readInt()\n\t\tval a = scala.io.StdIn.readLine.split(\" \").map(_.toInt).toList\n\t\tprintln(math.max(zipSub(a.drop(1), a).max, zipSub(a.drop(2), a).min))\n\t}\n}\n"}, {"source_code": "object Main extends App {\n\n val n = readInt\n val a = readLine.split(\" \").map(_.toInt)\n val pairs = (a zip a.tail) map { case (a1,a2) => a2 - a1 }\n val cur = pairs.max\n val dropped = (pairs zip pairs.tail) map { case (a1, a2) => List(a1+a2, cur).max }\n println(dropped.min)\n\n}"}, {"source_code": "object Main extends App {\n\n val n = readInt\n \n val a = readLine.split(\" \").map(_.toInt).toList\n \n def trackDiff(a: List[Int], maxDiff: Int): Int = \n if (a.tail.isEmpty) maxDiff else trackDiff(a.tail, maxDiff.max(a.tail.head - a.head))\n \n def trackDiffWithout(i: Int) = trackDiff(a.take(i) ::: a.drop(i + 1), -1)\n \n println((1 to n - 2).map(trackDiffWithout(_)).min)\n}"}], "negative_code": [], "src_uid": "8a8013f960814040ac4bf229a0bd5437"} {"nl": {"description": "Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1.You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right.", "input_spec": "The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000).", "output_spec": "Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left.", "sample_inputs": ["1", "2", "3", "8"], "sample_outputs": ["1", "2", "2 1", "4"], "notes": "NoteIn the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.In the second sample, we perform the following steps:Initially we place a single slime in a row by itself. Thus, row is initially 1.Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.In the last sample, the steps look as follows: 1 2 2 1 3 3 1 3 2 3 2 1 4 "}, "positive_code": [{"source_code": "import scala.collection.mutable.ArrayBuffer\n\n/**\n * Created by octavian on 30/01/2016.\n */\nobject Slime {\n\n def main(args: Array[String]) = {\n\n //System.setIn(new FileInputStream(\"./src/slime.in\"))\n //System.setOut(new PrintStream(new FileOutputStream(\"./src/slime.out\")))\n\n val n = readInt()\n var slimes = ArrayBuffer.empty[Int]\n for(i <- 1 to n) {\n slimes :+= 1\n while(slimes.size > 1 && slimes(slimes.length - 1) == slimes(slimes.length - 2)) {\n //println(\"condition holds\")\n slimes(slimes.length - 2) += 1\n slimes = slimes.dropRight(1)\n }\n //println(\"slimes is \" + slimes)\n }\n println(slimes.mkString(\" \"))\n }\n}\n"}, {"source_code": "import scala.collection.mutable.ListBuffer\n\nobject A341{\n def main(args: Array[String]){\n def log2(x: Double) = scala.math.log(x)/scala.math.log(2)\n var x=scala.io.StdIn.readDouble\n val res = scala.collection.mutable.ArrayBuffer.empty[Int]\n while (x > 1){\n val p = log2(x)\n x -= math.pow(2, p.toInt)\n res+=(p.toInt+1)\n }\n if (x == 1){\n res+=1\n }\n println(res.mkString(\" \"))\n }\n}\n"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val string = in.next().toInt.toBinaryString.reverse\n println(string.zipWithIndex.map{\n case ('1', n) => n + 1\n case _ => 0\n }.filter(_ != 0).reverse.mkString(\" \"))\n}"}, {"source_code": "object A618 {\n\n import IO._\n import collection.{mutable => cu}\n\n def main(args: Array[String]): Unit = {\n val Array(n) = readInts(1)\n var res = Array.empty[Int]\n for(i <- 0 to 30) {\n if ((n & (1 << i)) != 0)\n res ++= Array(i+1)\n }\n println(res.sorted.reverse.mkString(\" \"))\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"}, {"source_code": "import scala.collection._\nimport scala.collection.mutable.ArrayStack\n\nobject 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 val s = ArrayStack.empty[Int]\n \n for (_ <- 1 to n) {\n var x = 1\n while (s.nonEmpty && s.head == x) {\n x += 1\n s.pop()\n }\n s.push(x)\n }\n\n Console.setOut(new java.io.BufferedOutputStream(Console.out))\n\n println(s.toArray.reverse.mkString(\" \"))\n\n Console.flush\n}\n"}, {"source_code": "\nimport scala.collection.mutable\n\n/**\n * \n *\n * @author pvasilyev\n * @since 25 Apr 2016\n */\nobject Problem156 extends App {\n\n val n = scala.io.StdIn.readInt()\n\n def solve(n: Int, binaryRepresentation: mutable.MutableList[Int], factor: Int): Unit = {\n if (n > 0) {\n if (n % factor == 0) {\n binaryRepresentation += 0\n } else {\n binaryRepresentation += 1\n }\n\n solve(n / factor, binaryRepresentation, factor)\n }\n }\n\n val binaryRepresentation: mutable.MutableList[Int] = mutable.MutableList.empty\n solve(n, binaryRepresentation, 2)\n val answer: mutable.MutableList[Int] = mutable.MutableList.empty\n for (i <- binaryRepresentation.indices) {\n if (binaryRepresentation.get(i).get == 1) {\n answer += (i+1)\n }\n }\n println(answer.reverse.mkString(\" \"))\n\n}\n"}, {"source_code": "\nimport scala.collection.mutable\n\n/**\n * \n *\n * @author pvasilyev\n * @since 25 Apr 2016\n */\nobject Problem156 extends App {\n\n val n = scala.io.StdIn.readInt()\n\n def solve(n: Int, bits: mutable.MutableList[Int]): Unit = {\n if (n > 0) {\n bits += (n % 2)\n solve(n / 2, bits)\n }\n }\n\n val bits: mutable.MutableList[Int] = mutable.MutableList.empty\n solve(n, bits)\n val answer = bits.zipWithIndex.collect({case (1, i) => i + 1})\n println(answer.reverse.mkString(\" \"))\n\n}\n"}, {"source_code": "import scala.io.Source\n\nobject Main {\n val count = Source.stdin.getLines().mkString.toInt\n val stack = scala.collection.mutable.Stack[Int]()\n\n def foldStack(): Unit = {\n while (stack.length > 1 && stack.elems.head == stack.elems.tail.head) {\n val a = stack.pop()\n val b = stack.pop()\n stack.push(a + 1)\n }\n }\n\n def main(args: Array[String]) {\n for (i <- 0 until count) {\n foldStack()\n stack.push(1)\n }\n foldStack()\n println(stack.reverse.mkString(\" \"))\n }\n}\n"}, {"source_code": "import scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util._, control._\nimport scala.math.Ordering.Implicits._\n\nobject _618A extends CodeForcesApp {\n override type Result = Seq[Int]\n\n override def solve(scanner: Scanner) = {\n import scanner._\n val n = nextInt()\n val bits = java.lang.Integer.toBinaryString(n).reverse.zipWithIndex\n bits collect { case ('1', i) => i + 1}\n }\n\n override def format(result: Seq[Int]) = result.reverse mkString \" \"\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 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)\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"}, {"source_code": "import java.util.Scanner\n\nobject Main{\n def main (args: Array[String]){\n val sc = new Scanner(System.in)\n var n = sc.nextInt()\n\n // var ans = new List[Int]()\n\n if(n == 1){\n println(1)\n }\n else{\n val a = (Math.log(n)/Math.log(2)).toInt\n print(a + 1)\n n -= Math.pow(2, a).toInt\n\n def check(n: Int): Unit = {\n n match{\n case 0 =>\n println()\n case 1 =>\n println(\" 1\")\n case x =>\n val b = (Math.log(n)/Math.log(2)).toInt\n print(' ')\n print(b + 1)\n val c = x - Math.pow(2, b).toInt\n check(c)\n }\n }\n\n check(n)\n }\n }\n}\n"}, {"source_code": "object Runner {\n\n def main(args: Array[String]) = {\n val n = readInt()\n\n val binaryStr = Integer.toBinaryString(n)\n var res = List[Int]()\n for (i <- 0 until binaryStr.length()) {\n if (binaryStr.charAt(i).equals('1')) {\n res = res :+ (binaryStr.length() - i)\n }\n }\n var str = \"\"\n for (i <- 0 until res.size) {\n str += res(i)\n if (i != res.size - 1) {\n str += \" \"\n }\n }\n println(str)\n }\n}"}, {"source_code": "\nimport java.io._\nimport java.util.ArrayList\nimport java.util.StringTokenizer\nimport javax.print.attribute.standard.Sides\n\nobject CF2016_A { \n \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.int\n \n val arr = new ArrayList[Int]\n for (i<- 1 to n) {\n arr.add(1)\n while (arr.size() > 1 && arr.get(arr.size()-1) == arr.get(arr.size()-2)) {\n val vv = arr.remove(arr.size()-1) + 1 \n arr.remove(arr.size()-1)\n arr.add(vv)\n }\n }\n for (i <- 0 until arr.size()) print(arr.get(i)+\" \")\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 = \"\"\"\n\n\"\"\"\n\n}\n\n}\n\n"}], "negative_code": [{"source_code": "\n\nimport scala.collection.mutable.ArrayBuffer\n\n/**\n * Created by octavian on 30/01/2016.\n */\nobject Slime {\n\n def main(args: Array[String]) = {\n\n //System.setIn(new FileInputStream(\"./src/slime.in\"))\n //System.setOut(new PrintStream(new FileOutputStream(\"./src/slime.out\")))\n\n val n = readInt()\n var slimes = ArrayBuffer.empty[Int]\n for(i <- 1 to n) {\n slimes :+= 1;\n //println(\"slimes is \" + slimes)\n while(slimes.size > 1 && slimes(slimes.length - 1) == slimes(slimes.length - 2)) {\n //println(\"condition holds\")\n slimes(slimes.length - 2) += 1\n slimes = slimes.dropRight(1)\n }\n }\n println(slimes.mkString)\n }\n}\n"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val string = in.next().toInt.toBinaryString\n println(string.zip(string.indices.map(i => 1 << i)).map{\n case ('1', n) => n\n case _ => 0\n }.filter(_ != 0).mkString(\" \"))\n}"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val string = in.next().toInt.toBinaryString.reverse\n println(string.zip(string.indices.map(i => 1 << i)).map{\n case ('1', n) => n\n case _ => 0\n }.filter(_ != 0).reverse.mkString(\" \"))\n}"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val string = in.next().toInt.toBinaryString.reverse\n println(string.zip(string.indices.map(i => 1 << i)).map{\n case ('1', n) => n\n case _ => 0\n }.filter(_ != 0).mkString(\" \"))\n}"}, {"source_code": "import java.util.Scanner\n\nobject Main{\n def main (args: Array[String]){\n val sc = new Scanner(System.in)\n var n = sc.nextInt()\n\n // var ans = new List[Int]()\n\n if(n == 1){\n println(1)\n }\n else{\n val a = (Math.log(n)/Math.log(2)).toInt\n print(a + 1)\n n -= Math.pow(2, a).toInt\n\n def check(n: Int): Unit = {\n n match{\n case 0 =>\n println()\n case 1 =>\n println(\" 1\")\n case x =>\n val b = (Math.log(n)/Math.log(2)).toInt\n print(b + 1)\n val c = x - Math.pow(2, b).toInt\n check(c)\n }\n }\n\n check(n)\n }\n }\n}\n"}], "src_uid": "757cd804aba01dc4bc108cb0722f68dc"} {"nl": {"description": "Vasya plays Robot Bicorn Attack.The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string s. Vasya decided to brag about his achievement to the friends. However, he has forgotten how many points he got for each round. The only thing he remembers is the string s.Help Vasya to find out what is the maximum amount of points he could get. Take into account that Vasya played Robot Bicorn Attack for the first time, so he could not get more than 1000000 (106) points for one round.", "input_spec": "The only line of input contains non-empty string s obtained by Vasya. The string consists of digits only. The string length does not exceed 30 characters.", "output_spec": "Print the only number — the maximum amount of points Vasya could get. If Vasya is wrong and the string could not be obtained according to the rules then output number -1.", "sample_inputs": ["1234", "9000", "0009"], "sample_outputs": ["37", "90", "-1"], "notes": "NoteIn the first example the string must be split into numbers 1, 2 and 34.In the second example the string must be split into numbers 90, 0 and 0. In the third example the string is incorrect, because after splitting the string into 3 numbers number 00 or 09 will be obtained, but numbers cannot have leading zeroes."}, "positive_code": [{"source_code": "import scala.math.max\n\nobject CF105A {\n\n def parseScore(string: String): Option[Int] = {\n if (string.length == 0) None\n else if (string.length >= 2 && string.charAt(0) == '0') None\n else if (string.length >= 8) None\n else if (string.toInt > 1000000) None\n else Some(string.toInt)\n }\n\n def main(args: Array[String]): Unit = {\n val input = readLine()\n var maxSum = -1\n for (i <- 0 until input.length) {\n for (j <- i until input.length) {\n val string1 = input.substring(0, i)\n val string2 = input.substring(i, j)\n val string3 = input.substring(j)\n (parseScore(string1), parseScore(string2), parseScore(string3)) match {\n case (Some(value1), Some(value2), Some(value3)) => {\n maxSum = max(value1 + value2 + value3, maxSum)\n }\n case _ => Unit\n }\n }\n }\n println(maxSum)\n }\n}\n"}, {"source_code": "/**\n * Created by IntelliJ IDEA.\n * User: ymatsux\n * Date: 12/05/06\n * Time: 2:02\n * To change this template use File | Settings | File Templates.\n */\n\nobject CF115A {\n def main(args: Array[String]): Unit = {\n val input = readLine()\n var ans = -1\n for (i <- 0 until input.length) {\n for (j <- i + 1 until input.length) {\n val s1 = input.substring(0, i)\n val s2 = input.substring(i, j)\n val s3 = input.substring(j)\n if (isValid(s1) && isValid(s2) && isValid(s3)) {\n ans = math.max(s1.toInt + s2.toInt + s3.toInt, ans)\n }\n }\n }\n println(ans)\n }\n\n def isValid(string: String): Boolean = {\n if (string.length == 0) false\n else if (string.length >= 2 && string.charAt(0) == '0') false\n else {\n val value = BigInt(string)\n value <= 1000000\n }\n }\n}\n"}], "negative_code": [], "src_uid": "bf4e72636bd1998ad3d034ad72e63097"} {"nl": {"description": "One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are \"Danil\", \"Olya\", \"Slava\", \"Ann\" and \"Nikita\".Names are case sensitive.", "input_spec": "The only line contains string from lowercase and uppercase letters and \"_\" symbols of length, not more than 100 — the name of the problem.", "output_spec": "Print \"YES\", if problem is from this contest, and \"NO\" otherwise.", "sample_inputs": ["Alex_and_broken_contest", "NikitaAndString", "Danil_and_Olya"], "sample_outputs": ["NO", "YES", "NO"], "notes": null}, "positive_code": [{"source_code": "import scala.io.StdIn._\n\nobject Codeforces extends App {\n val contest = readLine()\n val friends = List(\"Danil\", \"Olya\", \"Slava\", \"Ann\", \"Nikita\")\n var count: Int = 0\n friends.foreach(count += _.r.findAllIn(contest).length)\n println(if (count == 1) \"YES\" else \"NO\")\n}\n"}, {"source_code": "object A extends App {\n def countSubstring(str1: String, str2: String): Int = {\n def count(pos: Int, c: Int): Int = {\n val idx = str1 indexOf(str2, pos)\n if (idx == -1) c else count(idx + str2.length, c+1)\n }\n count(0, 0)\n }\n\n val friends = List(\"Danil\", \"Olya\", \"Slava\", \"Ann\", \"Nikita\")\n val str1 = scala.io.StdIn.readLine()\n\n if (friends.foldLeft(0)((acc, str2) => acc + countSubstring(str1, str2)) == 1) println(\"YES\")\n else println(\"NO\")\n}\n"}, {"source_code": "object _877A 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 friends = List(\"Danil\", \"Olya\", \"Slava\", \"Ann\", \"Nikita\")\n val input = io.read[String]\n val result = friends.sumWith {f =>\n if (input.contains(f)) {\n if (input.indexOf(f) == input.lastIndexOf(f)) {\n 1\n } else {\n 2\n }\n } else {\n 0\n }\n }\n\n\n io.write((result == 1).toEnglish.toUpperCase())\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"}, {"source_code": "import java.util.Scanner\n\nobject Try1 {\n def main(args: Array[String]) {\n val in = new Scanner(System.in)\n var a,b,len,x, m, k, n, j, i: Int = 0\n// val lb = \"abcdefghijklmnopqrstuvwxyz\"\n// val lc = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n// var a = new Array[Int](51)\n// n = in.nextInt()\n// k = in.nextInt()\n// x=0\n val la = in.nextLine()\n a=0\n b=0\n m = la.length()\n i=0\n while (i='a' && la(i)<='z') a+=1\n// else b+=1\n i+=1\n }\n if (a==1) println(\"YES\")\n else println(\"NO\")\n// if (a>=b)\n// {\n// i=0\n// while (i='a' && la(i)<='z') print(la(i))\n// else print(lb(la(i)-'A'))\n// i+=1\n// }\n// }\n// else\n// {\n// i=0\n// while (i='a' && la(i)<='z') print(lc(la(i)-'a'))\n// else print(la(i))\n// i+=1\n// }\n// }\n// m = la.compareToIgnoreCase(lb) //不区分大小写判断字符串是否相等\n\n\n// i=0\n// n=line.length()\n// while (i2 && line(n-3)=='W' && line(n-2)=='U' && line(n-1)=='B') n-=3\n// while (i n / 2) {\n println(str.map{\n case ('x') if change > 0 =>\n change -= 1\n 'X'\n case t => t\n })\n } else {\n println(str.map{\n case ('X') if change > 0 =>\n change -= 1\n 'x'\n case t => t\n })\n }\n}"}, {"source_code": "\nobject A {\n def main(args: Array[String]): Unit = {\n val n = Console.readInt\n val s = new StringBuilder(Console readLine)\n var c = 0\n for (x <- s) c += (if (x == 'X') 1 else 0)\n if (c < n/2) {\n var q = n/2-c\n for (x <- 0 until n) {\n if (s(x) == 'x' && q > 0) {\n s(x) = 'X'\n q -= 1;\n }\n }\n } else {\n var q = c-n/2\n for (x <- 0 until n) {\n if (s(x) == 'X' && q > 0) {\n s(x) = 'x'\n q -= 1;\n }\n }\n }\n println(Math.abs(c-n/2))\n println(s)\n }\n}\n"}], "negative_code": [], "src_uid": "fa6311c72d90d8363d97854b903f849d"} {"nl": {"description": "Two boys decided to compete in text typing on the site \"Key races\". During the competition, they have to type a text consisting of s characters. The first participant types one character in v1 milliseconds and has ping t1 milliseconds. The second participant types one character in v2 milliseconds and has ping t2 milliseconds.If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. Right after that he starts to type it. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw.Given the length of the text and the information about participants, determine the result of the game.", "input_spec": "The first line contains five integers s, v1, v2, t1, t2 (1 ≤ s, v1, v2, t1, t2 ≤ 1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant.", "output_spec": "If the first participant wins, print \"First\". If the second participant wins, print \"Second\". In case of a draw print \"Friendship\".", "sample_inputs": ["5 1 2 1 2", "3 3 1 1 1", "4 5 3 1 5"], "sample_outputs": ["First", "Second", "Friendship"], "notes": "NoteIn the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins.In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw."}, "positive_code": [{"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(s, v1, v2, t1, t2) = readInts(5)\n\n val x1 = s * v1 + 2 * t1\n val x2 = s * v2 + 2 * t2\n\n val r = if (x1 < x2) \"First\"\n else if (x2 < x1) \"Second\"\n else \"Friendship\"\n\n println(r)\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject Main extends App {\n\n val Array(s, v1, v2, t1, t2) = StdIn.readLine().split(\" \").map(_.toInt)\n\n val first = 2*t1 + v1*s\n val second = 2*t2 + v2*s\n if(first < second) println(\"First\")\n else if(first > second) println(\"Second\")\n else if(first == second) println(\"Friendship\")\n\n}\n"}, {"source_code": "object AKeyRaces extends App {\n def result: (Int, Int, Int, Int, Int) => Int = (s: Int, v1: Int, v2: Int, t1: Int, t2: Int) => {\n val r1 = 2 * t1 + s * v1\n val r2 = 2 * t2 + s * v2\n if (r1 == r2) 0\n else if (r1 < r2) 1\n else -1\n }\n\n val Array(s, v1, v2, t1, t2) = scala.io.StdIn.readLine.split(\" \").map(_.toInt)\n val r = result(s, v1, v2, t1, t2)\n if (r == 0) print(\"Friendship\")\n else if (r == 1) print(\"First\")\n else print(\"Second\")\n}\n"}], "negative_code": [], "src_uid": "10226b8efe9e3c473239d747b911a1ef"} {"nl": {"description": "Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable professor of all times, a three times Soviet Union Hero, a Noble Prize laureate in student expulsion, venerable Petr Palych.The poor student couldn't answer a single question. Thus, instead of a large spacious office he is going to apply for a job to thorium mines. But wait a minute! Petr Palych decided to give the student the last chance! Yes, that is possible only in dreams. So the professor began: \"Once a Venusian girl and a Marsian boy met on the Earth and decided to take a walk holding hands. But the problem is the girl has al fingers on her left hand and ar fingers on the right one. The boy correspondingly has bl and br fingers. They can only feel comfortable when holding hands, when no pair of the girl's fingers will touch each other. That is, they are comfortable when between any two girl's fingers there is a boy's finger. And in addition, no three fingers of the boy should touch each other. Determine if they can hold hands so that the both were comfortable.\"The boy any the girl don't care who goes to the left and who goes to the right. The difference is only that if the boy goes to the left of the girl, he will take her left hand with his right one, and if he goes to the right of the girl, then it is vice versa.", "input_spec": "The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly. The second line contains two integers not exceeding 100. They are the number of fingers on the Marsian boy's left and right hands correspondingly.", "output_spec": "Print YES or NO, that is, the answer to Petr Palych's question.", "sample_inputs": ["5 1\n10 5", "4 5\n3 3", "1 2\n11 6"], "sample_outputs": ["YES", "YES", "NO"], "notes": "NoteThe boy and the girl don't really care who goes to the left."}, "positive_code": [{"source_code": "import scala.io.StdIn\n\n/**\n * @author chengyi\n */\nobject StudentDream {\n \n def tryHold(g:Int, b:Int):Boolean = {\n \n if (b>=(g-1) && b<=(2*(g-1)+4) ) true else false\n }\n \n def canHold(g:String, b:String):String = {\n val gi = g.split(\" \")\n val gl = gi(0).toInt\n val gr = gi(1).toInt\n \n val bi = b.split(\" \")\n val bl = bi(0).toInt\n val br = bi(1).toInt\n \n if (tryHold(gl, br) || tryHold(gr, bl)){\n \"YES\"\n }else{\n \"NO\"\n }\n }\n \n def main(args:Array[String]){\n val g = StdIn.readLine();\n val b = StdIn.readLine()\n println(canHold(g,b))\n }\n \n}"}], "negative_code": [{"source_code": "import scala.io.StdIn\n\n/**\n * @author chengyi\n */\nobject StudentDream {\n \n def tryHold(g:Int, b:Int):Boolean = {\n val del = b-g\n if (del>= -1 && del<=3) true else false\n }\n \n def canHold(g:String, b:String):String = {\n val gi = g.split(\" \")\n val gl = gi(0).toInt\n val gr = gi(1).toInt\n \n val bi = b.split(\" \")\n val bl = bi(0).toInt\n val br = bi(1).toInt\n \n if (tryHold(gl, br) || tryHold(gr, bl)){\n \"YES\"\n }else{\n \"NO\"\n }\n }\n \n def main(args:Array[String]){\n val g = StdIn.readLine();\n val b = StdIn.readLine()\n println(canHold(g,b))\n }\n \n}"}, {"source_code": "import scala.io.StdIn\n\n/**\n * @author chengyi\n */\nobject StudentDream {\n \n def tryHold(g:Int, b:Int):Boolean = {\n val del = g -b\n if (del>= -1 && del<=3) true else false\n }\n \n def canHold(g:String, b:String):String = {\n val gi = g.split(\" \")\n val gl = gi(0).toInt\n val gr = gi(1).toInt\n \n val bi = b.split(\" \")\n val bl = bi(0).toInt\n val br = bi(1).toInt\n \n if (tryHold(gl, br) || tryHold(gr, bl)){\n \"YES\"\n }else{\n \"NO\"\n }\n }\n \n def main(args:Array[String]){\n val g = StdIn.readLine();\n val b = StdIn.readLine()\n println(canHold(g,b))\n }\n \n}"}], "src_uid": "36b7478e162be6e985613b2dad0974dd"} {"nl": {"description": "Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.After how many full years will Limak become strictly larger (strictly heavier) than Bob?", "input_spec": "The only line of the input contains two integers a and b (1 ≤ a ≤ b ≤ 10) — the weight of Limak and the weight of Bob respectively.", "output_spec": "Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.", "sample_inputs": ["4 7", "4 9", "1 1"], "sample_outputs": ["2", "3", "1"], "notes": "NoteIn the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then."}, "positive_code": [{"source_code": "object Problem extends App{\n val ln = readLine\n val vals = ln.split(\" \")\n var a = vals(0).toInt\n var b = vals(1).toInt\n var counter = 0\n do{\n a *= 3\n b *= 2\n counter += 1\n } while (a <= b)\n println(counter)\n}"}, {"source_code": "object BearAndBigBrother extends App {\n\n val inputs = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n val liak = inputs(0)\n val bob = inputs(1)\n\n def solution(x: Int, y: Int): Int = {\n def helper(a: Int, b:Int, c: Int):Int = {\n \n if (a > b) c\n else {\n helper(a*3, b*2, c+1)\n }\n \n }\n helper(x,y,0)\n}\n\n println(solution(liak,bob))\n}"}, {"source_code": "object tanya extends App{\nvar twoNum = readLine().split(\" \")\nvar a = twoNum(0).toInt\nvar b = twoNum(1).toInt\nvar c = 0\n\nwhile(a <= b){\n c += 1\n a = a * 3\n b = b * 2\n}\nprintln(c)\n}\n"}, {"source_code": "//package solutions\n\nimport java.io.PrintWriter\nimport java.util.Scanner\n\nimport scala.math\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 val a = s.nextInt()\n val b = s.nextInt()\n\n val n = (math.log(b) - math.log(a)) / (math.log(3) - math.log(2))\n var res = math.ceil(n).toInt\n if (res < n + 0.0000001) {\n res += 1\n }\n out.print(res)\n }\n}\n"}, {"source_code": "import scala.io.StdIn\n\nobject BearAndBigBrother extends App {\n\n val l1 = StdIn.readLine().split(\" \")\n val a = l1(0).toInt\n val b = l1(1).toInt\n print(impl(a, b))\n\n def impl(a: Int, b: Int): Int = {\n var years = 0\n var currA = a\n var currB = b\n while (currA <= currB) {\n currA = 3 * currA\n currB = 2 * currB\n years += 1\n }\n years\n }\n}\n"}, {"source_code": "import scala.io.StdIn.readLine\nobject BearBrother extends App\n{\n val input = readLine().split(' ').map(_.toInt)\n var sum = 0\n var a: Int = input(0)\n var b: Int = input(1)\n while(!(a > b))\n {\n a *= 3\n b *= 2\n sum += 1\n }\n println(sum)\n}"}, {"source_code": "import scala.io.StdIn.readLine\n\nobject A791 {\n def main(args: Array[String]): Unit = {\n val List(limak, bob) = readToListInts\n println(solve(limak, bob))\n }\n\n def solve(limak: Int, bob: Int): Int = {\n def aux(a: Int, b: Int, count: Int): Int = {\n if (a > b) {\n count\n } else {\n aux(a*3, b*2, count + 1)\n }\n }\n aux(limak, bob, 0)\n }\n\n def readToListInts: List[Int] = readLine.split(\" \").map(_.toInt).toList\n}\n\n"}, {"source_code": "import io.StdIn._\nobject BearAndBigBrother {\n\n def main(args: Array[String]): Unit = {\n var inputs:Array[Int] = readLine().split(\" \").map(t=> s\"$t\".toInt)\n var i = 0\n while(inputs(0) <= inputs(1)){\n inputs(0) *= 3\n inputs(1) *= 2\n i += 1\n }\n println(i)\n }\n\n}"}, {"source_code": "object _791A 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 a, b = read[Long]\n write(solve(a, b))\n }\n\n def solve(a: Long, b: Long): Int = if (a > b) 0 else 1 + solve(3*a, 2*b)\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"}, {"source_code": "import java.util.Scanner\n\nobject Main{\n def main (args: Array[String]){\n val sc = new Scanner(System.in)\n\n var a = sc.nextInt()\n var b = sc.nextInt()\n\n var flag = true\n\n var ans = 0\n while(flag){\n ans += 1\n a = a*3\n b = b*2\n\n if(a > b)\n flag = false\n }\n\n println(ans)\n }\n}\n"}, {"source_code": "object BearandBigBrother791A // 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 a = scanner.nextInt()\n val b = scanner.nextInt()\n\n val numYears = (1 to 10).\n scanLeft((a,b,0: Int)){case ((ap,bp,_),year) => (ap*3,bp*2,year)}.\n filter{case (at,bt,_) => at>bt}.\n head._3\n\n out.println(numYears)\n\n }\n}"}, {"source_code": "import scala.io.StdIn\n\nobject Codeforces791a extends App {\n var Array(a, b) = StdIn.readLine().split(\"\\\\s\").map(s => s.toInt)\n var years = 0\n while (a <= b) {\n a *= 3\n b *= 2\n years += 1\n }\n println(years)\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject Main2 {\n def main(args: Array[String]): Unit = {\n val scanner = new Scanner(System.in)\n val limakWeight = scanner.nextInt()\n val bobWeight = scanner.nextInt()\n println(Math.ceil(Math.log(bobWeight.toDouble / limakWeight + 0.00001)/Math.log(1.5)).toInt)\n }\n}\n"}, {"source_code": "/**\n * Created by ruslan on 3/18/17.\n */\nobject ProblemA extends App {\n\n import java.io.{BufferedReader, InputStreamReader, PrintWriter}\n import java.util.StringTokenizer\n\n\n override def main(args: Array[String]): Unit = {\n\n val br = new BufferedReader(new InputStreamReader(System.in))\n var st: StringTokenizer = null\n val out = new PrintWriter(System.out)\n\n def next: String = {\n while (st == null || !st.hasMoreTokens) st =\n new StringTokenizer(br.readLine)\n st.nextToken\n }\n\n def nextInt: Int = next.toInt\n\n var massLimak: Long = nextInt\n var massBoba: Long = nextInt\n var res = 0\n\n while (massLimak <= massBoba) {\n res += 1\n massLimak *= 3\n massBoba *= 2\n }\n\n println(res)\n\n }\n}"}, {"source_code": "import scala.io.StdIn._\nimport scala.math.pow\n\nobject TaskA extends App {\n var a :: b :: Nil = readLine().split(\" \").map(_.toInt).toList\n var year = 1\n while (a * pow(3, year) <= b * pow(2, year)) year += 1\n print(year)\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject Solution {\n\tvar Array(a, b) = readLine.split(\" \").map(_.toInt)\n\n\tdef main(args:Array[String]):Unit = {\n\n\t\tvar n = 0\n\t\twhile(a <= b) {\n\t\t\ta *= 3\n\t\t\tb *= 2\n\t\t\tn += 1\n\t\t}\n\t\tprintln(n)\n\t\n\t}\n}\n"}], "negative_code": [{"source_code": "object BearAndBigBrother extends App {\n\n val inputs = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n val liak = inputs(0)\n val bob = inputs(1)\n\n def solution(x: Int, y: Int): Int = {\n def helper(a: Int, b:Int, c: Int):Int = {\n if (a == b) 1\n else if (a > b) c\n else {\n helper(a*3, b*2, c+1)\n }\n \n }\n helper(x,y,2)\n}\n\n println(solution(liak,bob))\n}"}, {"source_code": "object BearAndBigBrother extends App {\n\n /*val weights = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n var iLiak = weights(0)\n var iBob = weights(1)\n var years = 1\n while(iLiak <= iBob){\n iLiak*=3\n iBob*=2\n years +=1\n }\n println(years)\n\n */\n val inputs = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n val liak = inputs(0)\n val bob = inputs(1)\n\n def solution(x: Int, y: Int): Int = {\n def helper(a: Int, b:Int, c: Int):Int = {\n if (a == b) 1\n else if (a > b) c\n else {\n helper(a*3, b*2, c+1)\n }\n \n }\n helper(x,y,0)\n}\n\n println(solution(liak,bob))\n}"}, {"source_code": "object BearAndBigBrother extends App {\n def solution(x: Int, y: Int): Int = {\n def helper(a: Int, b:Int, c: Int):Int = {\n if (a == b) 1\n else if (a > b) c\n else {\n helper(a*3, b*2, c+1)\n }\n }\n helper(x,y,1)\n }\n println(solution(4,7))\n}"}, {"source_code": "object BearAndBigBrother extends App {\n\n val inputs = scala.io.StdIn.readLine().split(\" \").map(_.toInt)\n val liak = inputs(0)\n val bob = inputs(1)\n\n def solution(x: Int, y: Int): Int = {\n def helper(a: Int, b:Int, c: Int):Int = {\n if (a == b) 1\n else if (a > b) c\n else {\n helper(a*3, b*2, c+1)\n }\n \n }\n helper(x,y,1)\n}\n\n println(solution(liak,bob))\n}"}, {"source_code": "object tanya extends App{\nvar twoNum = readLine().split(\" \")\nvar a = twoNum(0).toInt\nvar b = twoNum(1).toInt\n\n\nfor (n <- 1 to b){\nif(a % 10 == 0){\n a = a/10\n}else{\n a = a - 1\n}\n}\nprintln(a)\n}\n"}, {"source_code": "object tanya extends App{\nvar twoNum = readLine().split(\" \")\nvar a = twoNum(0).toInt\nvar b = twoNum(1).toInt\nvar c = 0\n\nwhile(a < b){\n c += 1\n a = a * 3\n b = b * 2\n}\nprintln(c)\n}"}, {"source_code": "import scala.io.StdIn.readLine\n\nobject A791 {\n def main(args: Array[String]): Unit = {\n val List(limak, bob) = readToListInts\n println(solve(limak, bob))\n }\n\n def solve(limak: Int, bob: Int): Int = {\n def aux(a: Int, b: Int, count: Int): Int = {\n if (a >= b) {\n count\n } else {\n aux(a*3, b*2, count + 1)\n }\n }\n aux(limak, bob, 0)\n }\n\n def readToListInts: List[Int] = readLine.split(\" \").map(_.toInt).toList\n}\n\n"}, {"source_code": "import scala.io.StdIn\n\nobject Codeforces971A extends App {\n val Array(a, b) = StdIn.readLine().split(\"\\\\s\").map(a => a.toDouble)\n\n if (a == b) {\n println(\"1\")\n } else {\n val r = Math.log(b/a) / (Math.log(3) - Math.log(2))\n println(Math.ceil(r).toInt.toString)\n }\n}\n"}, {"source_code": "import java.util.Scanner\n\nobject Main2 {\n def main(args: Array[String]): Unit = {\n val scanner = new Scanner(System.in)\n val limakWeight = scanner.nextInt()\n val bobWeight = scanner.nextInt()\n println(Math.ceil(Math.log(((bobWeight + 0000.1) / limakWeight))/Math.log(1.5)).toInt)\n }\n}\n"}], "src_uid": "a1583b07a9d093e887f73cc5c29e444a"} {"nl": {"description": "Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.There are n teams taking part in the national championship. The championship consists of n·(n - 1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.", "input_spec": "The first line contains an integer n (2 ≤ n ≤ 30). Each of the following n lines contains a pair of distinct space-separated integers hi, ai (1 ≤ hi, ai ≤ 100) — the colors of the i-th team's home and guest uniforms, respectively.", "output_spec": "In a single line print the number of games where the host team is going to play in the guest uniform.", "sample_inputs": ["3\n1 2\n2 4\n3 4", "4\n100 42\n42 100\n5 42\n100 5", "2\n1 2\n1 2"], "sample_outputs": ["1", "5", "0"], "notes": "NoteIn the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first)."}, "positive_code": [{"source_code": "object Two68A extends App {\n\n\timport java.io.PrintWriter\n\timport java.util.Scanner\n\tval in = new Scanner(System.in)\n\tval out = new PrintWriter(System.out)\n\timport in._\n\timport out._\n\n\tval n = nextInt\n\tval arr = new Array[(Int, Int)](n)\n\tfor (i <- 0 until n) {\n\t\tarr(i) = (nextInt, nextInt)\n\t}\n\tvar sum = 0\n\tfor (i <- 0 until n; j <- i + 1 until n) {\n\t\tval x1 = arr(i)\n\t\tval x2 = arr(j)\n\t\tif (x1._1 == x2._2) sum += 1\n\t\tif (x2._1 == x1._2) sum += 1\n\t}\n\tprintln(sum)\n\tin.close\n\tout.close\n}"}, {"source_code": "import scala.annotation.tailrec\nimport scala.io.StdIn.readInt\nimport scala.io.StdIn.readLine\n\nobject Main extends App {\n case class Team(homeColor: Int, guestColor: Int)\n\n val n = readInt()\n val teams = (for {\n _ <- 0 until n\n Array(hColor, gColor) = readLine().split(\" \").map(_.toInt)\n } yield Team(hColor, gColor)).toList\n\n val ans = teams.foldLeft(0)((sum, host) => sum + count(host, teams, 0))\n println(ans)\n\n @tailrec\n def count(host: Team, others: List[Team], acc: Int): Int = others match {\n case Nil => acc\n case x :: xs =>\n if (x.guestColor == host.homeColor) count(host, xs, acc + 1)\n else count(host, xs, acc)\n }\n}"}, {"source_code": "import scala.io.StdIn\nimport scala.collection.mutable.ArrayBuffer\n\nobject Main extends App {\n val n = StdIn.readInt()\n val array = ArrayBuffer[(Int, Int)]()\n\n for (_ <- 1 to n) {\n val str = StdIn.readLine().split(\" \").map(_.toInt)\n array += ((str(0), str(1)))\n }\n\n var count = 0\n\n for (i <- 1 to n) {\n for (j <- (i + 1) to n) {\n if (array(i - 1)._1 == array(j - 1)._2) count += 1\n if (array(i - 1)._2 == array(j - 1)._1) count += 1\n }\n }\n\n println(count)\n}"}, {"source_code": "import scala.collection.mutable._\nimport scala.math._\nimport scala.util._\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 n = sc.nextInt\n val t = for(i <- 1 to n) yield (sc.nextInt, sc.nextInt)\n var cnt = 0\n for(i <- t) for(j <- t) if(i._1 == j._2) cnt += 1\n println(cnt)\n}\n"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val n = in.next().toInt\n val data = Range(0, n).map{ i => in.next().split(\" \")}\n println(data.map(el => data.count{t => t.last == el.head}).sum)\n}"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val n = readLine().toInt\n val h = new Array[Int](n)\n val a = new Array[Int](n)\n for (i <- 0 to n-1) {\n val Array(vh, va) = readLine().split(\" \").map(_.toInt)\n h(i) = vh\n a(i) = va\n }\n \n println((for (x <- h.iterator; y <- a.iterator) yield (x, y)).filter(x => x._1 == x._2).length)\n }\n}"}, {"source_code": "object A268 {\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 = Array.fill(n)(readInts(2))\n\n var res = 0\n for(i <- 0 until n) {\n for(j <- 0 until n if i != j) {\n if(input(i)(0) == input(j)(1)) res += 1\n }\n }\n\n println(res)\n }\n}"}, {"source_code": "import java.util.Scanner\nimport java.io.PrintWriter\nimport scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util.Random\n\nobject P268A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val N = sc.nextInt\n val hs = new Array[Int](N)\n val as = new Array[Int](N)\n for (i <- 0 until N) {\n hs(i) = sc.nextInt\n as(i) = sc.nextInt\n }\n\n val answer: Int = {\n for {\n h <- hs\n a <- as\n if h == a\n } yield 1\n } sum\n\n out.println(answer)\n out.close\n}\n"}, {"source_code": "\n\nobject Games {\n\tdef main (args: Array[String]) {\n\t\tval scanner = new java.util.Scanner(System.in);\n\t\tval n = scanner.nextInt();\n\t\t// Parsing input\n\t\tvar teams = new Array[(Int,Int)](n);\n\t\tfor (i <- 0 to n-1) {\n\t\t teams(i) = (scanner.nextInt(), scanner.nextInt());\n\t\t}\n\t\t// Computation\n\t\tvar output = 0\n\t\tfor (i <- 0 to n-1) {\n\t\t for (j <- 0 to n-1) {\n\t\t if (i!=j) {\n\t\t val (home,_) = teams(i)\n\t\t val (_, guest) = teams(j)\n\t\t if (home == guest)\n\t\t output += 1\n\t\t }\n\t\t }\n\t\t}\n\t\tprintln(output)\n\t}\n}"}, {"source_code": "object Matchi extends App {\n var ss = (Console.readLine.split(\" \")) map (_.toInt)\n val n = ss(0)\n \n def readMatches(nn:Int):List[(Int,Int)] = \n if (nn == 0) List()\n else {\n val sss = (Console.readLine.split(\" \")) map (_.toInt)\n (sss(0), sss(1)) :: readMatches(nn-1)\n }\n \n \n def cntMatch(pl:List[(Int,Int)], ac:Int, bc:Int):Int =\n \tpl match {\n \tcase Nil => 0\n \tcase (a,b) :: tl => ((if (b==ac) 1 else 0) +\n \t\t(if (a==bc) 1 else 0) +\n \t\tcntMatch(tl, ac,bc))\n \t} //> cntMatch: (pl: List[(Int, Int)], ac: Int, bc: Int)Int\n \t\n def cntSame(pl:List[(Int,Int)]):Int =\n \tpl match {\n \tcase Nil => 0\n \tcase (a,b) :: tl => cntMatch(tl, a,b) + cntSame(tl)\n \t} \n \n val pl = readMatches(n)\n println(cntSame(pl))\n}"}, {"source_code": "object A\n{\n def main(args: Array[String])\n {\n val n = readLine().toInt\n val colors=Array.ofDim[Int](n,2)\n for (i <- 0 until n)\n {\n colors(i)=readLine.split(\" \").map(_.toInt)\n }\n println((for(x<- colors.iterator; y<-colors.iterator) yield(x,y)).filter(x => x._1(0) == x._2(1)).length)\n }\n}\n"}, {"source_code": "import java.util._\n\nobject CF268A {\n\n def main(args: Array[String]) {\n var list1 = Array[Int]()\n var list2 = Array[Int]()\n val in = new Scanner(System.in)\n \n val n = in.nextInt\n \n for (i <- 0 to n - 1) {\n list1 = list1 :+ in.nextInt\n list2 = list2 :+ in.nextInt\n }\n \n var count = 0\n for (i <- 0 to n - 1) {\n for (j <- 0 to n - 1) {\n if (i != j && list2(j) == list1(i)) {\n count += 1\n }\n }\n }\n \n println(count)\n }\n \n}"}, {"source_code": "import java.io.PrintWriter\nimport java.io.File\nimport java.util.Scanner\n\nobject test5 extends App {\n val n=readLine.toInt\n val colors=Array.ofDim[Int](n,2)\n for(i<-0 until n){\n colors(i)=readLine.split(\" \").map(_.toInt)\n }\n \n val list=for(i<-0 until n; j<-0 until n if i!=j) yield\n if(colors(i)(0)==colors(j)(1)) 1 else 0\n \n println(list.sum)\n} \n\n"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val num = readInt()\n var s = List[(Int, Int)]()\n for (i <- 0 until num) {\n val a = readLine().split(\" \").map(_.toInt)\n s = (a(0), a(1)) :: s\n }\n val r = s.foldLeft(0) { (acc, t) => \n acc + s.foldLeft(0) { (acc, tt) => if (t._1 == tt._2) acc + 1 else acc }\n }\n println(r)\n }\n}"}, {"source_code": "import scala.collection.mutable._\nimport scala.math._\nimport scala.util._\nimport scala.util.control.Breaks.break\nimport scala.util.control.Breaks.breakable\nimport java.util._\nobject problem extends App {\n val cin = new Scanner(System.in)\n val n = cin.nextInt()\n var cnt = 0\n val t = for(i <- 1 to n) yield (cin.nextInt(), cin.nextInt())\n for(i <- t) for(j <- t) if(i._1 == j._2) cnt += 1\n println(cnt)\n}"}, {"source_code": "\nimport scala.io.StdIn.readLine\nimport scala.io.StdIn.readInt\n\n\nobject Games {\n \n def readInts() : Array[Int] =\n readLine.split(' ').map(_.toInt)\n \n def main(args: Array[String]) {\n val n = readInt\n val colors = for {\n i <- 1 to n \n line = readInts\n } yield(line(0),line(1))\n val games = \n for {\n i <- 0 to n-1\n j <- 0 to n-1\n if (i != j)\n } yield (i,j)\n println(games.count(p => colors(p._1)._1 == colors(p._2)._2))\n }\n \n}"}, {"source_code": "import scala.Math.pow;\nimport scala.collection.mutable.LinkedList\n\nobject App {\n\tdef readInts:Array[Int] = (readLine split \" \") map (_.toInt)\n //> readInts: => Array[Int] //> solve: (n: Int, m: Int, prev: Int, a: Int, b: Int)(Int, Int)\n\t\n\tdef f1_io() = {\n\t\tval Array(n) = readInts\n\t\tval homeColor = new Array[Int](n)\n\t\tval outColor = new Array[Int](n)\n\t\tfor (i <- 1 to n) {\n\t\t val a = readInts\n\t\t homeColor(i - 1) = a(0)\n\t\t outColor(i - 1) = a(1)\n\t\t}\n\t\t\n\t\tprint ((homeColor map (x => (outColor filter (y => x == y)).length)).sum)\n\t} \n def main(args: Array[String]): Unit = {\n\tf1_io\n }\n\n}"}, {"source_code": " object Games extends App {\n \tdef resolve(): Int = {\n \t\tvar hs = Map[Int, Int]()\n \t\tvar as = Map[Int, Int]()\n \t\t\n \t\tval lines = io.Source.stdin.getLines.toList.tail\n \t\t\n \t\tfor (elem <- lines) {\n \t\t\tval (homekit: Int, awaykit: Int) = {\n \t\t\t\tval tokens = elem.split(\" \")\n \t\t\t\t(tokens(0).toInt, tokens(1).toInt)\n \t\t\t}\n \t\t\t\n \t\t\ths = hs + (homekit -> (hs.getOrElse(homekit, 0) + 1))\n \t\t\tas = as + (awaykit -> (as.getOrElse(awaykit, 0) + 1))\n \t\t}\n \t\t\n \t\tvar sum = 0\n \t\tfor ((k, v) <- hs) {\n \t\t\tsum += v * as.getOrElse(k, 0)\n \t\t}\n \t\t\n \t\tsum\n \t}\n\t\n\tprint(resolve())\n }"}, {"source_code": "object A00268 extends App {\n def parseInt(str: String, count: Int): Seq[Int] = {\n val scanner = new java.util.Scanner(str)\n val res = (1 to count) map (_ => scanner.nextInt())\n scanner.close()\n res\n }\n def scanInts(count: Int): Seq[Int] = parseInt(Console.readLine, count)\n def readMatrix(row: Int, col: Int) = (1 to row) map (x => scanInts(col))\n\n def oneIntLine = {\n val Seq(count) = parseInt(Console.readLine(), 1);\n count\n }\n\n def frequency[T](seq: Seq[T]) = seq.groupBy(identity).mapValues(_.size).withDefaultValue(0)\n \n val nTeams = oneIntLine\n val colors = readMatrix(nTeams, 2)\n val guestColorFreq = frequency(colors.map(_(1)))\n val result = colors.map(x => guestColorFreq(x(0))).sum\n println(result)\n}\n"}], "negative_code": [{"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val n = in.next().toInt\n println(in.next().split(\"WUB\").filter(_.nonEmpty).mkString(\" \"))\n}"}, {"source_code": " object Games extends App {\n \tdef resolve(): Int = {\n \t\tvar hs = Map[Int, Int]()\n \t\tvar as = Map[Int, Int]()\n \t\t\n \t\tval lines = io.Source.stdin.getLines.toList.tail\n \t\t\n \t\tfor (elem <- lines) {\n \t\t\tval (homekit: Int, awaykit: Int) = {\n \t\t\t\tval tokens = elem.split(\" \")\n \t\t\t\t(tokens(0).toInt, tokens(1).toInt)\n \t\t\t}\n \t\t\t\n \t\t\ths = hs + (homekit -> (hs.getOrElse(homekit, 0) + 1))\n \t\t\tas = as + (awaykit -> (as.getOrElse(awaykit, 0) + 1))\n \t\t}\n \t\t\n \t\tvar sum = 0\n \t\tfor ((k, v) <- hs) {\n \t\t\tsum += v * as.getOrElse(k, 0)\n \t\t}\n \t\t\n \t\tsum\n \t}\n }"}], "src_uid": "745f81dcb4f23254bf6602f9f389771b"} {"nl": {"description": "You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: the i-th letter occurs in the string no more than ai times; the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once. ", "input_spec": "The first line of the input contains a single integer n (2  ≤  n  ≤  26) — the number of letters in the alphabet. The next line contains n integers ai (1 ≤ ai ≤ 109) — i-th of these integers gives the limitation on the number of occurrences of the i-th character in the string.", "output_spec": "Print a single integer — the maximum length of the string that meets all the requirements.", "sample_inputs": ["3\n2 5 5", "3\n1 1 2"], "sample_outputs": ["11", "3"], "notes": "NoteFor convenience let's consider an alphabet consisting of three letters: \"a\", \"b\", \"c\". In the first sample, some of the optimal strings are: \"cccaabbccbb\", \"aabcbcbcbcb\". In the second sample some of the optimal strings are: \"acc\", \"cbc\"."}, "positive_code": [{"source_code": "\n/**\n * Created by octavian on 06/02/2016.\n */\nobject MakeClass {\n\n val INF = 1000000005\n\n def main(args: Array[String]) = {\n\n //System.setIn(new FileInputStream(\"./src/makeClass.in\"))\n //System.setOut(new PrintStream(new FileOutputStream(\"./src/makeClass.out\")))\n\n val N = readInt()\n val vals = readLine().split(\" \").map(_.toInt).sorted\n\n var res: BigInt = 0\n var last = INF\n for(i <- vals.length - 1 to 0 by -1) {\n val toAdd = Math.min(vals(i), last - 1)\n last = toAdd\n if(toAdd > 0) {\n res += toAdd\n }\n }\n\n println(res)\n\n }\n\n}\n"}, {"source_code": "import scala.io.Source\n\nobject Solution extends App {\n val in = Source.stdin.getLines()\n val n = in.next().toInt\n var used = Set.empty[Int]\n println(in.next().split(' ').map(_.toInt).zipWithIndex.foldLeft(0l) {\n case (acc, (count, index)) =>\n var nc = count\n while (nc > 0 && used.contains(nc)) nc -= 1\n if (nc != 0) {\n used += nc\n }\n acc + nc\n })\n}"}, {"source_code": "\n\nimport java.io._\nimport java.util\nimport java.util.StringTokenizer\n\nimport scala.annotation.implicitNotFound\nimport scala.collection.mutable\nimport scala.reflect.ClassTag\n\n/**\n * Created by nimas on 2/4/16.\n */\nobject MakingAString extends App{\n\n class Template(val delim: String = \" \") {\n\n val in = new BufferedReader(new InputStreamReader(System.in))\n val out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))\n val it = Iterator.iterate(new StringTokenizer(\"\"))(tok => if (tok.hasMoreTokens) tok else new StringTokenizer(in.readLine(), delim))\n\n\n def nextTs[T: ParseAble](n: Int)(delim: String = \" \")(implicit ev: ClassTag[T]) = (Array fill n) {\n nextT[T](delim)\n }\n\n def nextT[T: ParseAble](delim: String = \" \") = {\n val x = it.find(_.hasMoreTokens)\n implicitly[ParseAble[T]].parse(x get)\n }\n\n def close(): Unit = {\n in.close()\n out.close()\n }\n\n @implicitNotFound(\"No member of type class ParseAble in scope for ${T}\")\n trait ParseAble[T] {\n def parse(strTok: StringTokenizer): T\n }\n\n object ParseAble {\n\n implicit object ParseAbleInt extends ParseAble[Int] {\n override def parse(strTok: StringTokenizer): Int = strTok nextToken() toInt\n }\n\n implicit object ParseAbleLong extends ParseAble[Long] {\n override def parse(strTok: StringTokenizer): Long = strTok nextToken() toLong\n }\n\n implicit object ParseAbleDouble extends ParseAble[Double] {\n override def parse(strTok: StringTokenizer): Double = strTok nextToken() toDouble\n }\n\n implicit object ParseAbleBigInt extends ParseAble[BigInt] {\n override def parse(strTok: StringTokenizer): BigInt = BigInt(strTok nextToken())\n }\n\n }\n\n }\n\n val io = new Template()\n\n import io._\n\n val n = nextT[Int]()\n val a = nextTs[Long](n)() sorted Ordering.Long\n\n val map = new mutable.HashMap[Long, Boolean]()\n\n out.println((a.iterator map {\n x => {\n if (map getOrElse(x, true)) {\n map put(x, false)\n x\n } else {\n val find = x - 1 to(1, -1) find {\n !map.contains(_)\n } getOrElse 0l\n if (find != 0) map put(find, false)\n find\n }\n }\n }).sum)\n\n close()\n\n}\n"}, {"source_code": "import scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util._, control._\nimport scala.math.Ordering.Implicits._\n\nobject _624B extends CodeForcesApp {\n override type Result = Long\n\n override def solve(read: Scanner) = {\n val n = read[Int]\n val seen = mutable.Set.empty[Long]\n @tailrec def add(i: Long): Unit = if (seen(i)) add(i-1) else if (i > 0) {val _ = seen += i}\n repeat(n)(add(read[Long]))\n seen.sum\n }\n\n def repeat(n: Int)(f: => Unit): Unit = (1 to n).foreach(_ => f)\n\n override def format(result: Result) = result.toString\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: Scanner): Result\n def format(result: Result): String\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.{BufferedReader, Reader, InputStreamReader, StringReader, InputStream}\nimport java.util.StringTokenizer\n\nclass Scanner(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)\n .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 def apply[A: Parser]: A = implicitly[Parser[A]].apply(next())\n\n def nextLine(): String = tokenizer().get.nextToken(\"\\n\\r\")\n override def next() = tokenizer().get.nextToken()\n override def hasNext = tokenizer().nonEmpty\n override def close() = reader.close()\n}\n\ntrait Parser[A] {\n def apply(s: String): A\n}\nobject Parser {\n def apply[A](f: String => A) = new Parser[A] {\n override def apply(s: String) = f(s)\n }\n implicit val tokenString: Parser[String] = Parser(identity)\n implicit val tokenChar: Parser[Char] = Parser(s => s.ensuring(_.length == 1, s\"Expected Char; found $s\").head)\n implicit val tokenBool: Parser[Boolean] = Parser(_.toBoolean)\n implicit val tokenInt: Parser[Int] = Parser(_.toInt)\n implicit val tokenLong: Parser[Long] = Parser(_.toLong)\n implicit val tokenBigInt: Parser[BigInt] = Parser(BigInt(_))\n implicit val tokenDouble: Parser[Double] = Parser(_.toDouble)\n implicit val tokenBigDecimal: Parser[BigDecimal] = Parser(BigDecimal(_))\n}\n"}, {"source_code": "import scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util._, control._\nimport scala.math.Ordering.Implicits._\n\nobject _624B extends CodeForcesApp {\n override type Result = Long\n\n override def solve(read: InputReader) = {\n val n = read[Int]\n val seen = mutable.Set.empty[Long]\n @tailrec def add(i: Long): Unit = if (seen(i)) add(i-1) else if (i > 0) {val _ = seen += i}\n repeat(n)(add(read[Long]))\n seen.sum\n }\n\n def repeat(n: Int)(f: => Unit): Unit = (1 to n).foreach(_ => f)\n\n override def format(result: Result) = result.toString\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 {i <- 1 to n} builder += apply[A]\n builder.result()\n }\n\n def tillEndOfLine(): String = tokenizer().get.nextToken(\"\\n\\r\")\n\n override def next() = tokenizer().get.nextToken()\n override def hasNext = tokenizer().nonEmpty\n override def close() = reader.close()\n}\n\ntrait Parser[A] {\n def apply(reader: InputReader): A\n}\nobject Parser {\n def apply[A](f: String => A) = new Parser[A] {\n override def apply(reader: InputReader) = f(reader.next())\n }\n type Collection[C[_], A] = scala.collection.generic.CanBuildFrom[C[A], A, C[A]]\n implicit def collectionParser[C[_], A: Parser](implicit cbf: Collection[C, A]): Parser[C[A]] = new Parser[C[A]] {\n override def apply(reader: InputReader) = reader[C, A](reader[Int])\n }\n implicit val stringParser: Parser[String] = Parser(identity)\n implicit val charParser: Parser[Char] = Parser(s => s.ensuring(_.length == 1, s\"Expected Char; found $s\").head)\n implicit val booleanParser: Parser[Boolean] = Parser(_.toBoolean)\n implicit val intParser: Parser[Int] = Parser(_.toInt)\n implicit val longParser: Parser[Long] = Parser(_.toLong)\n implicit val bigIntParser: Parser[BigInt] = Parser(BigInt(_))\n implicit val doubleParser: Parser[Double] = Parser(_.toDouble)\n implicit val bigDecimalParser: Parser[BigDecimal] = Parser(BigDecimal(_))\n}\n"}, {"source_code": "import scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util._, control._\nimport scala.math.Ordering.Implicits._\n\nobject _624B extends CodeForcesApp {\n override type Result = Long\n\n override def solve(read: InputReader) = {\n val n = read[Int]\n val seen = mutable.Set.empty[Long]\n @tailrec def add(i: Long): Unit = if (seen(i)) add(i-1) else if (i > 0) {val _ = seen += i}\n repeat(n)(add(read[Long]))\n seen.sum\n }\n\n def repeat(n: Int)(f: => Unit): Unit = (1 to n).foreach(_ => f)\n\n override def format(result: Result) = result.toString\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(next())\n\n def tillEndOfLine(): String = tokenizer().get.nextToken(\"\\n\\r\")\n override def next() = tokenizer().get.nextToken()\n override def hasNext = tokenizer().nonEmpty\n override def close() = reader.close()\n}\n\ntrait Parser[A] {\n def apply(s: String): A\n}\nobject Parser {\n def apply[A](f: String => A) = new Parser[A] {\n override def apply(s: String) = f(s)\n }\n implicit val stringParser: Parser[String] = Parser(identity)\n implicit val charParser: Parser[Char] = Parser(s => s.ensuring(_.length == 1, s\"Expected Char; found $s\").head)\n implicit val booleanParser: Parser[Boolean] = Parser(_.toBoolean)\n implicit val intParser: Parser[Int] = Parser(_.toInt)\n implicit val longParser: Parser[Long] = Parser(_.toLong)\n implicit val bigIntParser: Parser[BigInt] = Parser(BigInt(_))\n implicit val doubleParser: Parser[Double] = Parser(_.toDouble)\n implicit val bigDecimalParser: Parser[BigDecimal] = Parser(BigDecimal(_))\n}\n"}, {"source_code": "import scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util._, control._\nimport scala.math.Ordering.Implicits._\n\nobject _624B extends CodeForcesApp {\n override type Result = Long\n\n override def solve(scanner: Scanner) = {\n import scanner._\n val seen = mutable.Set.empty[Long]\n @tailrec def add(i: Long): Unit = if (seen(i)) add(i-1) else if (i > 0) seen += i\n repeat(nextInt())(add(nextLong()))\n seen.sum\n }\n\n def repeat(n: Int)(f: => Unit): Unit = (1 to n).foreach(_ => f)\n\n override def format(result: Result) = result.toString\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 val mod: Int = 1000000007\n type Result\n def solve(scanner: Scanner): Result\n def format(result: Result): String\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)\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"}, {"source_code": "/**\n * Created by Andrew Tsibin https://github.com/Evilnef.\n */\nobject Problemset624 {\n def main(args: Array[String]): Unit = {\n val problem = new ProblemB\n problem.solve()\n }\n\n private abstract class Problem {\n def solve()\n }\n\n private class ProblemA extends Problem {\n override def solve(): Unit = {\n val Array(d, l, v1, v2) = scala.io.StdIn.readLine().split(\" \").map(_.toDouble)\n val result = (l - d) / (v1 + v2)\n println(result)\n }\n }\n\n private class ProblemB extends Problem {\n override def solve(): Unit = {\n var maxStringLengths: BigInt = 0\n val n = scala.io.StdIn.readInt()\n val a = scala.io.StdIn.readLine().split(\" \").map(BigInt(_)).sortWith(_ > _)\n for (i <- a.indices) {\n if (i == 0) maxStringLengths += a(i)\n else maxStringLengths += {\n if (a(i) >= a(i - 1))\n a(i) = a(i - 1) - 1\n if (a(i) < 0) 0 else a(i)\n }\n }\n println(maxStringLengths)\n }\n }\n\n}\n"}, {"source_code": "import scala.util.Sorting\nimport scala.io.StdIn\nobject App {\n def main(args: Array[String]) {\n\n\n\n val n = scala.io.StdIn.readInt()\n val A:Array[Long] = StdIn.readLine().split(\" \").map(_.toLong)\n Sorting.quickSort(A)\n\n\n print(A.reverse.zipWithIndex.foldLeft((0L,0L))({\n case(b,(a,i)) =>\n if(i == 0) {\n (a,a)\n } else {\n val k = math.max(0, math.min(b._2 - 1, a))\n (b._1 + k, k)\n }\n })._1)\n }\n\n\n}\n"}, {"source_code": "import scala.util.Sorting\nimport scala.io.StdIn\nobject App {\n def main(args: Array[String]) {\n\n\n\n val n = scala.io.StdIn.readInt()\n val A:Array[Long] = StdIn.readLine().split(\" \").map(_.toLong)\n Sorting.quickSort(A)\n\n\n var acc:Long = 0\n A.reverse.zipWithIndex.foldLeft(0L)({\n case(b,(a,i)) =>\n if(i == 0) {\n acc+=a\n a\n } else {\n acc += math.max(math.min(b - 1, a),0)\n math.max(math.min(b - 1, a),0)\n }\n })\n\n print(acc)\n\n }\n\n\n}\n"}, {"source_code": "import scala.util.Sorting\nimport scala.io.StdIn\nobject App {\n def main(args: Array[String]) {\n\n\n\n val n = scala.io.StdIn.readInt()\n val A:Array[Long] = StdIn.readLine().split(\" \").map(_.toLong).sortWith( _ > _)\n\n\n print(A.zipWithIndex.foldLeft((0L,0L))({\n case(b,(a,i)) =>\n if(i == 0) {\n (a,a)\n } else {\n val k = math.max(0, math.min(b._2 - 1, a))\n (b._1 + k, k)\n }\n })._1)\n }\n\n\n}\n"}, {"source_code": "import scala.util.Sorting\nimport scala.io.StdIn\nobject App {\n def main(args: Array[String]) {\n\n\n\n val n = scala.io.StdIn.readInt()\n val A:Array[Long] = StdIn.readLine().split(\" \").map(_.toLong).sorted.reverse\n\n\n print(A.zipWithIndex.foldLeft((0L,0L))({\n case(b,(a,i)) =>\n if(i == 0) {\n (a,a)\n } else {\n val k = math.max(0, math.min(b._2 - 1, a))\n (b._1 + k, k)\n }\n })._1)\n }\n\n\n}\n"}], "negative_code": [{"source_code": "\n/**\n * Created by octavian on 06/02/2016.\n */\nobject MakeClass {\n\n val INF = 1000000005\n\n def main(args: Array[String]) = {\n\n //System.setIn(new FileInputStream(\"./src/makeClass.in\"))\n //System.setOut(new PrintStream(new FileOutputStream(\"./src/makeClass.out\")))\n\n val N = readInt()\n var vals = readLine().split(\" \").map(_.toInt)\n\n var res = 0\n var last = INF\n for(i <- vals.length - 1 to 0 by -1) {\n val toAdd = Math.min(vals(i), last - 1)\n last = toAdd\n if(toAdd > 0) {\n res += toAdd\n }\n }\n\n println(res)\n\n }\n\n}\n"}, {"source_code": "\n/**\n * Created by octavian on 06/02/2016.\n */\nobject MakeClass {\n\n val INF = 1000000005\n\n def main(args: Array[String]) = {\n\n //System.setIn(new FileInputStream(\"./src/makeClass.in\"))\n //System.setOut(new PrintStream(new FileOutputStream(\"./src/makeClass.out\")))\n\n val N = readInt()\n val vals = readLine().split(\" \").map(_.toInt).sorted\n\n var res = 0\n var last = INF\n for(i <- vals.length - 1 to 0 by -1) {\n val toAdd = Math.min(vals(i), last - 1)\n last = toAdd\n if(toAdd > 0) {\n res += toAdd\n }\n }\n\n println(res)\n\n }\n\n}\n"}, {"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 arr = Array.ofDim[Int](26)\n var used = Set.empty[Int]\n in.next().split(' ').map(_.toInt).zipWithIndex.foreach {\n case (count, index) =>\n var nc = count\n while (nc > 0 && used.contains(nc)) nc -= 1\n if (nc != 0) {\n arr(index) = nc\n used += nc\n }\n }\n println(arr.sum)\n\n\n}"}, {"source_code": "\nimport java.io._\nimport java.util\nimport java.util.StringTokenizer\n\nimport scala.annotation.implicitNotFound\nimport scala.collection.mutable\nimport scala.reflect.ClassTag\n\n/**\n * Created by nimas on 2/4/16.\n */\nobject MakingAString extends App{\n\n class Template(val delim: String = \" \") {\n\n val in = new BufferedReader(new InputStreamReader(System.in))\n val out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))\n val it = Iterator.iterate(new StringTokenizer(\"\"))(tok => if (tok.hasMoreTokens) tok else new StringTokenizer(in.readLine(), delim))\n\n\n def nextTs[T: ParseAble](n: Int)(delim: String = \" \")(implicit ev: ClassTag[T]) = (Array fill n) {\n nextT[T](delim)\n }\n\n def nextT[T: ParseAble](delim: String = \" \") = {\n val x = it.find(_.hasMoreTokens)\n implicitly[ParseAble[T]].parse(x get)\n }\n\n def close(): Unit = {\n in.close()\n out.close()\n }\n\n @implicitNotFound(\"No member of type class ParseAble in scope for ${T}\")\n trait ParseAble[T] {\n def parse(strTok: StringTokenizer): T\n }\n\n object ParseAble {\n\n implicit object ParseAbleInt extends ParseAble[Int] {\n override def parse(strTok: StringTokenizer): Int = strTok nextToken() toInt\n }\n\n implicit object ParseAbleLong extends ParseAble[Long] {\n override def parse(strTok: StringTokenizer): Long = strTok nextToken() toLong\n }\n\n implicit object ParseAbleDouble extends ParseAble[Double] {\n override def parse(strTok: StringTokenizer): Double = strTok nextToken() toDouble\n }\n\n implicit object ParseAbleBigInt extends ParseAble[BigInt] {\n override def parse(strTok: StringTokenizer): BigInt = BigInt(strTok nextToken())\n }\n\n }\n\n }\n\n val io = new Template()\n\n import io._\n\n val n = nextT[Int]()\n val a = nextTs[Int](n)() sorted Ordering.Int\n\n val map = new mutable.HashMap[Int, Boolean]()\n\n\n out.println((a.iterator map {\n x => {\n if (map getOrElse(x, true)) {\n map put(x, false)\n x\n } else {\n x - 1 to(1, -1) find {\n !map.contains(_)\n } getOrElse 0\n }\n }\n }).sum)\n\n close()\n\n}\n"}, {"source_code": "\n\nimport java.io._\nimport java.util\nimport java.util.StringTokenizer\n\nimport scala.annotation.implicitNotFound\nimport scala.collection.mutable\nimport scala.reflect.ClassTag\n\n/**\n * Created by nimas on 2/4/16.\n */\nobject MakingAString extends App{\n\n class Template(val delim: String = \" \") {\n\n val in = new BufferedReader(new InputStreamReader(System.in))\n val out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))\n val it = Iterator.iterate(new StringTokenizer(\"\"))(tok => if (tok.hasMoreTokens) tok else new StringTokenizer(in.readLine(), delim))\n\n\n def nextTs[T: ParseAble](n: Int)(delim: String = \" \")(implicit ev: ClassTag[T]) = (Array fill n) {\n nextT[T](delim)\n }\n\n def nextT[T: ParseAble](delim: String = \" \") = {\n val x = it.find(_.hasMoreTokens)\n implicitly[ParseAble[T]].parse(x get)\n }\n\n def close(): Unit = {\n in.close()\n out.close()\n }\n\n @implicitNotFound(\"No member of type class ParseAble in scope for ${T}\")\n trait ParseAble[T] {\n def parse(strTok: StringTokenizer): T\n }\n\n object ParseAble {\n\n implicit object ParseAbleInt extends ParseAble[Int] {\n override def parse(strTok: StringTokenizer): Int = strTok nextToken() toInt\n }\n\n implicit object ParseAbleLong extends ParseAble[Long] {\n override def parse(strTok: StringTokenizer): Long = strTok nextToken() toLong\n }\n\n implicit object ParseAbleDouble extends ParseAble[Double] {\n override def parse(strTok: StringTokenizer): Double = strTok nextToken() toDouble\n }\n\n implicit object ParseAbleBigInt extends ParseAble[BigInt] {\n override def parse(strTok: StringTokenizer): BigInt = BigInt(strTok nextToken())\n }\n\n }\n\n }\n\n val io = new Template()\n\n import io._\n\n val n = nextT[Int]()\n val a = nextTs[Int](n)() sorted Ordering.Int\n\n val map = new mutable.HashMap[Int, Boolean]()\n\n\n out.println((a.iterator map {\n x => {\n if (map getOrElse(x, true)) {\n map put(x, false)\n x\n } else {\n val find = x - 1 to(1, -1) find {\n !map.contains(_)\n } getOrElse 0\n if (find != 0) map put(find, false)\n find\n }\n }\n }).sum)\n\n close()\n\n}\n"}, {"source_code": "import scala.annotation.tailrec\nimport scala.collection.mutable\nimport scala.util._, control._\nimport scala.math.Ordering.Implicits._\n\nobject _624B extends CodeForcesApp {\n override type Result = Int\n\n override def solve(scanner: Scanner) = {\n import scanner._\n val n = nextInt()\n val seen = mutable.Set.empty[Int]\n @tailrec def add(i: Int): Unit = if (seen(i)) add(i-1) else if (i > 0) seen += i\n repeat(n)(add(nextInt()))\n seen.sum\n }\n\n def repeat(n: Int)(f: => Unit): Unit = (1 to n).foreach(_ => f)\n\n override def format(result: Result) = result.toString\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 val mod: Int = 1000000007\n type Result\n def solve(scanner: Scanner): Result\n def format(result: Result): String\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)\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"}, {"source_code": "/**\n * Created by Andrew Tsibin https://github.com/Evilnef.\n */\nobject Problemset624 {\n def main(args: Array[String]): Unit = {\n val problem = new ProblemB\n problem.solve()\n }\n\n private abstract class Problem {\n def solve()\n }\n\n private class ProblemA extends Problem {\n override def solve(): Unit = {\n val Array(d, l, v1, v2) = scala.io.StdIn.readLine().split(\" \").map(_.toDouble)\n val result = (l - d) / (v1 + v2)\n println(result)\n }\n }\n\n private class ProblemB extends Problem {\n override def solve(): Unit = {\n var maxStringLengths = 0\n val n = scala.io.StdIn.readInt()\n val a = scala.io.StdIn.readLine().split(\" \").map(_.toInt).sortWith(_ > _)\n for (i <- a.indices) {\n if (i == 0) maxStringLengths += a(i)\n else maxStringLengths += {\n if (a(i) >= a(i - 1))\n a(i) = a(i - 1) - 1\n if (a(i) < 0) 0 else a(i)\n }\n }\n println(maxStringLengths)\n }\n }\n\n}\n"}, {"source_code": "import scala.util.Sorting\nimport scala.io.StdIn\nobject App {\n def main(args: Array[String]) {\n\n\n\n val n = scala.io.StdIn.readInt()\n val A:Array[Int] = StdIn.readLine().split(\" \").map(_.toInt)\n Sorting.quickSort(A)\n\n\n var acc = 0\n A.reverse.zipWithIndex.foldLeft(0)({\n case(b,(a,i)) =>\n if(i == 0) {\n acc+=a\n a\n } else {\n acc += math.max(math.min(b - 1, a),0)\n math.max(math.min(b - 1, a),0)\n }\n })\n\n print(acc)\n\n }\n\n\n}\n"}], "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f"} {"nl": {"description": "Unary is a minimalistic Brainfuck dialect in which programs are written using only one token. Brainfuck programs use 8 commands: \"+\", \"-\", \"[\", \"]\", \"<\", \">\", \".\" and \",\" (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm. First, replace each command with a corresponding binary code, using the following conversion table: \">\"  →  1000, \"<\"  →  1001, \"+\"  →  1010, \"-\"  →  1011, \".\"  →  1100, \",\"  →  1101, \"[\"  →  1110, \"]\"  →  1111. Next, concatenate the resulting binary codes into one binary number in the same order as in the program. Finally, write this number using unary numeral system — this is the Unary program equivalent to the original Brainfuck one.You are given a Brainfuck program. Your task is to calculate the size of the equivalent Unary program, and print it modulo 1000003 (106 + 3).", "input_spec": "The input will consist of a single line p which gives a Brainfuck program. String p will contain between 1 and 100 characters, inclusive. Each character of p will be \"+\", \"-\", \"[\", \"]\", \"<\", \">\", \".\" or \",\".", "output_spec": "Output the size of the equivalent Unary program modulo 1000003 (106 + 3).", "sample_inputs": [",.", "++++[>,.<-]"], "sample_outputs": ["220", "61425"], "notes": "NoteTo write a number n in unary numeral system, one simply has to write 1 n times. For example, 5 written in unary system will be 11111.In the first example replacing Brainfuck commands with binary code will give us 1101 1100. After we concatenate the codes, we'll get 11011100 in binary system, or 220 in decimal. That's exactly the number of tokens in the equivalent Unary program."}, "positive_code": [{"source_code": "\nobject Main {\n def main(args : Array[String]) =\n println (readLine.foldLeft (0) (\n (ans, x) => ((ans << 4) | ((\"><+-.,[]\" indexOf x) + 8)) % 1000003\n ))\n}\n"}, {"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 P133B extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n // \">\"  →  1000,\n // \"<\"  →  1001,\n // \"+\"  →  1010,\n // \"-\"  →  1011,\n // \".\"  →  1100,\n // \",\"  →  1101,\n // \"[\"  →  1110,\n // \"]\"  →  1111. \n\n \n val M = Map('>' -> 8,\n '<' -> 9,\n '+' -> 10,\n '-' -> 11,\n '.' -> 12,\n ',' -> 13,\n '[' -> 14,\n ']' -> 15)\n\n val P = 1000003\n\n def solve(): Int = {\n val BF = sc.nextLine\n\n BF.foldLeft(0) { (b, a) =>\n ((b << 4) | M(a)) % P\n }\n }\n\n out.println(solve)\n out.close\n}\n"}, {"source_code": "object Main {\n def main(args : Array[String]) =\n println (readLine.foldLeft (0) (\n (ans, x) => ((ans << 4) | ((\"><+-.,[]\" indexOf x) + 8)) % 1000003\n ))\n}"}, {"source_code": "object Main {\n def main(args : Array[String]) =\n println (readLine.foldLeft (0) (\n (ans, x) => ((ans << 4) | ((\"><+-.,[]\" indexOf x) + 8)) % 1000003\n ))\n}"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val s = readLine()\n val tr = s.map{\n case '>' => 8\n case '<' => 9\n case '+' => 10\n case '-' => 11\n case '.' => 12\n case ',' => 13\n case '[' => 14\n case ']' => 15\n }\n println(tr.foldLeft(0){ (acc, i) => (acc * 16 + i) % 1000003} )\n }\n}"}, {"source_code": "object Main {\n def main(args : Array[String]) =\n println (readLine.foldLeft (0) (\n (ans, x) => ((ans << 4) | ((\"><+-.,[]\" indexOf x) + 8)) % 1000003\n ))\n}"}, {"source_code": "object Main {\n def main(args : Array[String]) =\n println (readLine.foldLeft (0) (\n (ans, x) => ((ans << 4) | ((\"><+-.,[]\" indexOf x) + 8)) % 1000003\n ))\n}"}, {"source_code": "import java.util.Scanner\nobject P133B extends App {\n \n val map = Map('>' -> \"1000\", '<' -> \"1001\", '+' -> \"1010\", '-' -> \"1011\", \n '.' -> \"1100\", ',' -> \"1101\", '[' -> \"1110\", ']' -> \"1111\")\n val s = new Scanner(System.in).next()\n\n var res = \"\"\n for(c <- s) res += map(c) \n\n println(BigInt(res,2) % 1000003)\n \n}"}, {"source_code": "import java.util.Scanner\nobject P133B extends App {\n val m = Map('>'->\"1000\",'<'->\"1001\",'+'->\"1010\",'-'->\"1011\",'.'->\"1100\",','->\"1101\",'['->\"1110\",']'->\"1111\")\n val s = new Scanner(System.in).next()\n println(BigInt(s.map(m).mkString,2) % 1000003)\n}"}, {"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val str = in.next()\n\n val map = Map(\n '>' -> 8,\n '<' -> 9,\n '+' -> 10,\n '-' -> 11,\n '.' -> 12,\n ',' -> 13,\n '[' -> 14,\n ']' -> 15)\n\n println(str.foldLeft(0l) {\n case (acc, ch) => ((acc << 4) | map(ch)) % 1000003\n } % 1000003)\n\n}"}], "negative_code": [{"source_code": "object Solution extends App {\n val in = scala.io.Source.stdin.getLines()\n val str = in.next()\n\n val map = Map(\n '>' -> 8,\n '<' -> 9,\n '+' -> 10,\n '-' -> 11,\n '.' -> 12,\n ',' -> 13,\n '[' -> 14,\n ']' -> 15)\n\n println(str.foldLeft(0l) {\n case (acc, ch) => Math.abs(acc << 4) + map(ch)\n } % 1000003)\n\n}"}], "src_uid": "04fc8dfb856056f35d296402ad1b2da1"} {"nl": {"description": "Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is T seconds. Lesha downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For q seconds of real time the Internet allows you to download q - 1 seconds of the track.Tell Lesha, for how many times he will start the song, including the very first start.", "input_spec": "The single line contains three integers T, S, q (2 ≤ q ≤ 104, 1 ≤ S < T ≤ 105).", "output_spec": "Print a single integer — the number of times the song will be restarted.", "sample_inputs": ["5 2 2", "5 4 7", "6 2 3"], "sample_outputs": ["2", "1", "1"], "notes": "NoteIn the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.In the second test, the song is almost downloaded, and Lesha will start it only once.In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case."}, "positive_code": [{"source_code": "object A569 {\n\n import IO._\n import collection.{mutable => cu}\n\n def main(args: Array[String]): Unit = {\n var Array(t, s, q) = readInts(3)\n var res = 0\n while(s < t) {\n s *= q\n res += 1\n }\n out.println(res)\n out.close()\n }\n\n object IO {\n private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))\n // private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(\"src/input\")))\n val out = new java.io.PrintWriter(System.out)\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"}, {"source_code": "import java.io._\nimport java.util._\n\nimport scala.collection.mutable\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 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 t = nextInt\n var s = nextInt\n val q = nextInt\n var count = 0\n while (s < t) {\n s *= q\n count += 1\n }\n out.println(count)\n return 0\n }\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject A extends App {\n val Array(t, s, q) = readLine().split(\" \").map(_.toInt)\n\n var played = 0\n var started = 1\n var current = 0\n\n while (s + (current * ((q - 1.0) / q)) < t) {\n if (played + 1 <= s + ((current + 1) * ((q - 1.0) / q))) {\n played += 1\n } else {\n played = 1\n started += 1\n }\n\n current += 1\n }\n\n println(started)\n}\n"}, {"source_code": "\nimport java.util.Scanner\n\nobject PA extends App {\n var in = new Scanner(System.in)\n val Vector(t, s, q) = (1 to 3).map(_ => in.nextInt())\n def sol(ns:Int):Int = if(ns >= t) 0 else sol(ns*q) + 1\n println(sol(s).toString)\n}\n\n\n"}, {"source_code": "object Solution extends App{\n val in = scala.io.Source.stdin.getLines()\n var Array(t, s, q) = in.next().split(\" \").map(_.toInt)\n var count = 0\n while (s < t) {\n s *= q\n count += 1\n }\n println(count)\n\n}\n"}], "negative_code": [{"source_code": "import scala.io.StdIn._\n\nobject A extends App {\n val Array(t, s, q) = readLine().split(\" \").map(_.toInt)\n\n var downloaded = s.toDouble\n var played = 0\n var started = 1\n\n var speed = (q - 1.0) / q\n\n while (downloaded < t) {\n downloaded += speed\n\n if (played + 1 <= downloaded) {\n played += 1\n } else {\n played = 0\n started += 1\n }\n }\n\n println(started)\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject A extends App {\n val Array(t, s, q) = readLine().split(\" \").map(_.toInt)\n\n var downloaded = s.toDouble\n var played = 0\n var started = 1\n\n var speed = (q - 1.0) / q\n\n while (downloaded < t) {\n downloaded += speed\n\n if (played + 1 <= downloaded) {\n played += 1\n } else {\n played = 1\n started += 1\n }\n }\n\n println(started)\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject A extends App {\n val Array(t, s, q) = readLine().split(\" \").map(_.toInt)\n\n var downloaded = s.toDouble\n var played = 0\n var started = 1\n\n var speed = (q - 1.0) / q\n\n downloaded += speed\n\n while (downloaded < t) {\n\n if (played + 1 <= downloaded) {\n played += 1\n } else {\n played = 1\n started += 1\n }\n\n downloaded += speed\n }\n\n println(started)\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject A extends App {\n val Array(t, s, q) = readLine().split(\" \").map(_.toInt)\n\n var downloaded = s.toDouble\n var played = 0\n var started = 1\n\n var speed = (q - 1.0) / q\n\n downloaded += speed\n\n while (downloaded < t) {\n\n if (played + 1 <= downloaded) {\n played += 1\n } else {\n played = 0\n started += 1\n }\n\n downloaded += speed\n }\n\n println(started)\n}\n"}, {"source_code": "import scala.io.StdIn._\n\nobject A extends App {\n val Array(t, s, q) = readLine().split(\" \").map(_.toInt)\n\n var downloaded = s.toDouble\n var played = 0\n var started = 1\n\n var speed = (q - 1.0) / q\n\n while (downloaded < t) {\n downloaded += speed\n\n if (downloaded < t && played + 1 <= downloaded) {\n played += 1\n } else if (downloaded < t) {\n played = 0\n started += 1\n }\n }\n\n println(started)\n}\n"}, {"source_code": "object Solution extends App{\n val in = scala.io.Source.stdin.getLines()\n val Array(t, s, q) = in.next().split(\" \").map(_.toInt)\n var downloaded = 2 * s * (q - 1)\n var count = 1\n while (downloaded < t) {\n downloaded += downloaded * (q - 1)\n count += 1\n }\n println(count)\n\n}\n"}], "src_uid": "0d01bf286fb2c7950ce5d5fa59a17dd9"} {"nl": {"description": "Gerald is setting the New Year table. The table has the form of a circle; its radius equals R. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider all plates to be round and have the same radii that equal r. Each plate must be completely inside the table and must touch the edge of the table. Of course, the plates must not intersect, but they can touch each other. Help Gerald determine whether the table is large enough for n plates.", "input_spec": "The first line contains three integers n, R and r (1 ≤ n ≤ 100, 1 ≤ r, R ≤ 1000) — the number of plates, the radius of the table and the plates' radius.", "output_spec": "Print \"YES\" (without the quotes) if it is possible to place n plates on the table by the rules given above. If it is impossible, print \"NO\". Remember, that each plate must touch the edge of the table. ", "sample_inputs": ["4 10 4", "5 10 4", "1 10 10"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteThe possible arrangement of the plates for the first sample is: "}, "positive_code": [{"source_code": "object main {\n \n \n \n def main(args: Array[String]) = {\n \n val tokens = (readLine()) split \" \" map Integer.parseInt\n val n = tokens apply 0\n val R = tokens apply 1\n val r = tokens apply 2\n if (n == 1) {if (R >= r) println (\"YES\") else println(\"NO\")}\n else if ((R-r)*math.sin(math.Pi/n)>=r-0.00000001) println (\"YES\") else println(\"NO\")\n }\n}"}, {"source_code": "object P140A extends App {\n\n val Array(n, bigR, r) = readLine.split(\" \").map(_.toInt)\n\n def findSide(angle: Double, a: Double) = a / math.sin(math.toRadians(angle))\n\n val condition = if (n < 3) bigR >= n * r else math.abs(findSide(180.0 / n, r)) + r <= bigR\n\n print(if (condition) \"YES\" else \"NO\")\n\n}\n"}, {"source_code": "import scala.io.Source\nobject A {\n\n def main(arg: Array[String]) = {\n val in = Source.stdin.getLine(0).split(\" \").map(_.toInt)\n val n = in(0)\n val R = in(1).toDouble\n val r = in(2).toDouble\n\n if (n == 1) {\n if (r <= R)\n println(\"YES\")\n else\n println(\"NO\")\n } else if (r*2.0 > R)\n println(\"NO\")\n else {\n val a = Math.asin(r / (R - r))\n val fit = Math.floor(2 * Math.Pi / a + 1E-7).toInt / 2\n\n if (n <= fit)\n println(\"YES\")\n else\n println(\"NO\")\n }\n }\n}"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val Array(n, r1, r0) = readLine().split(\" \").map(_.toInt)\n if (n == 1 && r1 >= r0) println(\"YES\")\n else if (r1 > r0) {\n val angle = math.Pi / n\n if (r0.toDouble / (r1 - r0).toDouble - math.sin(angle) <= 0.000000001) println(\"YES\")\n else (println(\"NO\"))\n } else println(\"NO\")\n }\n}"}], "negative_code": [{"source_code": "import scala.io.Source\nobject A {\n\n def main(arg: Array[String]) = {\n val in = Source.stdin.getLine(0).split(\" \").map(_.toInt)\n val n = in(0)\n val R = in(1).toDouble\n val r = in(2).toDouble\n\n if (n == 1) {\n if (r <= R)\n println(\"YES\")\n else\n println(\"NO\")\n } else if (r*2.0 > R)\n println(\"NO\")\n else {\n val a = Math.asin(r / (R - r))\n val fit = Math.floor(2 * Math.Pi / (a-(1E-7))).toInt / 2\n\n if (n <= fit)\n println(\"YES\")\n else\n println(\"NO\")\n }\n }\n}"}, {"source_code": "import scala.io.Source\nobject A {\n\n def main(arg: Array[String]) = {\n val in = Source.stdin.getLine(0).split(\" \").map(_.toInt)\n val n = in(0)\n val R = in(1).toDouble\n val r = in(2).toDouble\n\n if (n == 1) {\n if (r <= R)\n println(\"YES\")\n else\n println(\"NO\")\n } else if (r*2.0 > R)\n println(\"NO\")\n else {\n val a = Math.asin(r / (R - r))\n val fit = Math.floor(2 * Math.Pi / (a-0.001)).toInt / 2\n\n if (n <= fit)\n println(\"YES\")\n else\n println(\"NO\")\n }\n }\n}"}, {"source_code": "import scala.io.Source\nobject A {\n\n def main(arg: Array[String]) = {\n val in = Source.stdin.getLine(0).split(\" \").map(_.toInt)\n val n = in(0)\n val R = in(1).toDouble\n val r = in(2).toDouble\n\n if (n == 1) {\n if (r <= R)\n println(\"YES\")\n else\n println(\"NO\")\n } else if (r*2.0 > R)\n println(\"NO\")\n else {\n val a = Math.asin(r / (R - r))\n val fit = Math.floor(2 * Math.Pi / a).toInt / 2\n\n if (n <= fit)\n println(\"YES\")\n else\n println(\"NO\")\n }\n }\n}"}, {"source_code": "import scala.io.Source\nobject A {\n\n def main(arg: Array[String]) = {\n val in = Source.stdin.getLine(0).split(\" \").map(_.toInt)\n val n = in(0)\n val R = in(1).toDouble\n val r = in(2).toDouble\n\n if (n == 1) {\n if (r <= R)\n println(\"YES\")\n else\n println(\"NO\")\n } else if (r*2.0 > R)\n println(\"NO\")\n else {\n val a = Math.asin(r / (R - r))\n val fit = Math.floor(2 * Math.Pi / a + Math.EPS_DOUBLE).toInt / 2\n\n if (n <= fit)\n println(\"YES\")\n else\n println(\"NO\")\n }\n }\n}"}, {"source_code": "import scala.io.Source\nobject A {\n\n def main(arg: Array[String]) = {\n val in = Source.stdin.getLine(0).split(\" \").map(_.toInt)\n val n = in(0)\n val R = in(1).toDouble\n val r = in(2).toDouble\n\n if (n == 1) {\n if (r <= R)\n println(\"YES\")\n else\n println(\"NO\")\n } else if (r*2.0 > R)\n println(\"NO\")\n else {\n val a = Math.asin(r / (R - r))\n val fit = Math.floor(2 * Math.Pi / (a-(Math.EPS_DOUBLE))).toInt / 2\n\n if (n <= fit)\n println(\"YES\")\n else\n println(\"NO\")\n }\n }\n}"}, {"source_code": "import scala.io.Source\nobject A {\n\n def main(arg: Array[String]) = {\n val in = Source.stdin.getLine(0).split(\" \").map(_.toInt)\n val n = in(0)\n val R = in(1).toDouble\n val r = in(2).toDouble\n\n if (n == 1) {\n if (r <= R)\n println(\"YES\")\n else\n println(\"NO\")\n } else if (r*2.0 > R)\n println(\"NO\")\n else {\n val a = Math.asin(r / (R - r))\n val fit = Math.floor(2 * Math.Pi / (a+(Math.EPS_DOUBLE))).toInt / 2\n\n if (n <= fit)\n println(\"YES\")\n else\n println(\"NO\")\n }\n }\n}"}, {"source_code": "import scala.io.Source\nobject A {\n\n def main(arg: Array[String]) = {\n val in = Source.stdin.getLine(0).split(\" \").map(_.toInt)\n val n = in(0)\n val R = in(1).toDouble\n val r = in(2).toDouble\n\n if (n == 1) {\n if (r <= R)\n println(\"YES\")\n else\n println(\"NO\")\n } else if (r*2.0 > R)\n println(\"NO\")\n else {\n val a = Math.asin(r / (R - r))\n \n println (a)\n val fit = Math.floor(2 * Math.Pi / a + Math.EPS_DOUBLE).toInt / 2\n\n \n println (fit)\n if (n <= fit)\n println(\"YES\")\n else\n println(\"NO\")\n }\n }\n}"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val Array(n, r1, r0) = readLine().split(\" \").map(_.toInt)\n if (n == 1 && r1 >= r0) println(\"YES\")\n else if (r1 > r0) {\n val angle = math.Pi / n\n if (r0.toDouble / (r1 - r0).toDouble <= math.sin(angle)) println(\"YES\")\n else (println(\"NO\"))\n } else println(\"NO\")\n }\n}"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val Array(n, r1, r0) = readLine().split(\" \").map(_.toInt)\n if (n == 1 && r1 >= r0) println(\"YES\")\n else if (r1 > r0) {\n val angle = math.Pi / n\n if (r0.toDouble / (r1 - r0).toDouble - math.sin(angle) <= 0.0000001) println(\"YES\")\n else (println(\"NO\"))\n } else println(\"NO\")\n }\n}"}, {"source_code": "object Main {\n def main(args: Array[String]) {\n val Array(n, r1, r0) = readLine().split(\" \").map(_.toInt)\n if (n == 1 && r1 >= r0) println(\"YES\")\n else if (r1 > r0) {\n val angle = math.Pi / n\n if (r0.toDouble / (r1 - r0).toDouble - math.sin(angle) <= 0.001) println(\"YES\")\n else (println(\"NO\"))\n } else println(\"NO\")\n }\n}"}], "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6"} {"nl": {"description": "Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any). Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.", "input_spec": "The first line contains a single integer n (1 ≤ n ≤ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 ≤ xi ≤ 106) — the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.", "output_spec": "In the single line print \"yes\" (without the quotes), if the line has self-intersections. Otherwise, print \"no\" (without the quotes).", "sample_inputs": ["4\n0 10 5 15", "4\n0 15 5 10"], "sample_outputs": ["yes", "no"], "notes": "NoteThe first test from the statement is on the picture to the left, the second test is on the picture to the right."}, "positive_code": [{"source_code": "object Main {\n def main(args: Array[String]) {\n val n=readLine().toInt\n val a=readLine().split(\" \").map(_ toInt)\n val b=(0 until n-1).map(i=>(math.min(a(i),a(i+1)),math.max(a(i),a(i+1))))\n println( if (b.exists(e1=>b.exists(e2=>(e1._1 _int)\n val intervals = coords.zip(coords.tail)\n\n def norm(a: (Int, Int)): (Int, Int) = (scala.math.min(a._1, a._2), scala.math.max(a._1, a._2))\n\n def inside(a: (Int, Int), x: Int): Boolean = a._1 < x && x < a._2\n def oneInside(a: (Int, Int), b: (Int, Int)): Boolean = inside(a, b._1) ^ inside(a, b._2)\n\n def intersects(a: (Int,Int), b: (Int, Int)): Boolean = {\n val x = norm(a)\n val y = norm(b)\n val res = oneInside(x, y) && oneInside(y, x)\n if (res) {\n //println(a)\n //println(b)\n }\n res\n }\n\n val hasInt = intervals.find(a => {\n intervals.find(b => intersects(a, b)).isDefined\n }).isDefined\n\n if (hasInt) {\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}"}, {"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).sliding(2).toList\n val r = data.forall{i => data.forall { j =>\n val minFirst = Math.min(i.head, i.last)\n val maxFirst = Math.max(i.head, i.last)\n val minSecond = Math.min(j.head, j.last)\n val maxSecond = Math.max(j.head, j.last)\n if (i == j)\n true\n else {\n val r = maxFirst <= minSecond || minFirst >= maxSecond || (maxFirst <= maxSecond && minFirst >= minSecond) ||\n (maxSecond <= maxFirst && minSecond >= minFirst)\n r\n }}}\n if (!r)\n println(\"yes\")\n else\n println(\"no\")\n}"}, {"source_code": "object A358 {\n\n import IO._\n import collection.{mutable => cu}\n\n def main(args: Array[String]): Unit = {\n val Array(n) = readInts(1)\n val in = readInts(n)\n val x = cu.ArrayBuffer.empty[(Int, Int)]\n for(i <- 1 until n)\n x.append((math.min(in(i-1), in(i)), math.max(in(i-1), in(i))))\n val res = x.sorted\n var break = false\n for(i <- res.indices; j <- res.indices if i!=j && !break) {\n if(res(i)._1 < res(j)._1 && res(i)._2 > res(j)._1 && res(j)._2 > res(i)._2) {\n println(\"yes\")\n break = true\n }\n }\n if(!break){\n println(\"no\")\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"}, {"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 n = readInt\n val xs = readInts(n)\n \n for (i <- 1 until n) {\n val l1 = math.min(xs(i - 1), xs(i))\n val r1 = math.max(xs(i - 1), xs(i)) \n for (j <- 1 until n) {\n val l2 = math.min(xs(j - 1), xs(j))\n val r2 = math.max(xs(j - 1), xs(j))\n if ((l1 < l2 && r1 > l2 && r1 < r2) || (r1 > r2 && l1 > l2 && l1 < r2) ||\n (l2 < l1 && r2 > l1 && r2 < r1) || (r2 > r1 && l2 > l1 && l2 < r1)) {\n println(\"yes\")\n //println(i, j)\n exit\n }\n } \n }\n\n println(\"no\")\n}"}, {"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 P358A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val N = sc.nextInt\n val P = Array.fill(N)(sc.nextInt)\n\n var flag = false\n breakable {\n for (i <- 0 until N - 2; j <- (i + 2) until N - 1) {\n val a = P(i)\n val b = P(i + 1)\n val c = P(j)\n val d = P(j + 1)\n if ((c - a).signum * (c - b).signum * (d - a).signum * (d - b).signum < 0) {\n flag = true\n break\n }\n }\n }\n\n val res = if (flag) \"yes\" else \"no\"\n\n out.println(res)\n out.close\n}\n\n\n\n\n\n"}, {"source_code": "import java.util.Scanner\nimport scala.collection.mutable.ArrayBuffer\n\nobject Solver extends App {\n val cin = new Scanner(System.in)\n \n val n = cin.nextInt\n cin.nextLine\n val points = cin.nextLine.split(\" \").map(_.toInt).toSeq\n\n val connections = for (i <- 0 until n - 1) yield (points(i), points(i + 1))\n \n var intersection = \"no\"\n connections.foreach { case (a, d) =>\n val p1 = Seq(a, d)\n val A = p1.min\n val D = p1.max\n \n connections.foreach { case (b, c) =>\n val p2 = Seq(b, c)\n val B = p2.min\n val C = p2.max\n \n if (B < D && D < C && A < B)\n intersection = \"yes\"\n }\n }\n \n println(intersection)\n}"}], "negative_code": [{"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).sliding(2)\n val r = data.forall{i => data.forall { j =>\n val minFirst = Math.min(i.head, i.last)\n val maxFirst = Math.max(i.head, i.last)\n val minSecond = Math.min(j.head, j.last)\n val maxSecond = Math.max(j.head, j.last)\n if (i == j)\n true\n else {\n maxFirst <= minSecond || minFirst >= maxSecond || (maxFirst <= maxSecond && minFirst >= minSecond) ||\n (maxSecond <= maxFirst && minSecond >= minFirst)\n }}}\n if (!r)\n println(\"yes\")\n else\n println(\"no\")\n}"}, {"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 n = readInt\n val xs = readInts(n)\n \n for (i <- 1 until n) {\n val l1 = xs(i - 1)\n val r1 = xs(i) \n for (j <- 1 until n) {\n val l2 = xs(j - 1)\n val r2 = xs(j)\n if ((l1 < l2 && r1 > l2 && r1 < r2) || (r1 > r2 && l1 > l2 && l1 < r2) ||\n (l2 < l1 && r2 > l1 && r2 < r1) || (r2 > r1 && l2 > l1 && l2 < r1)) {\n println(\"yes\")\n //println(i, j)\n exit\n }\n } \n }\n\n println(\"no\")\n}"}, {"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\n\nobject P358A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val N = sc.nextInt\n val ps = List.fill(N / 2, 2)(sc.nextInt)\n val res = if (ps(0) == ps(0).sorted && ps(1) == ps(1).sorted.reverse) \"no\"\n else \"yes\"\n\n out.println(res)\n out.close\n}\n\n\n\n"}, {"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 P358A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val N = sc.nextInt\n val P = Array.fill(N)(sc.nextLong)\n\n var flag = false\n breakable {\n for (i <- 0 until N - 2; j <- (i + 1) until N - 1) {\n val a = P(i)\n val b = P(i + 1)\n val c = P(j)\n val d = P(j + 1)\n if ((c - a) * (c - b) * (d - a) * (d - b) < 0) {\n flag = true\n break\n }\n }\n }\n\n val res = if (flag) \"YES\" else \"NO\"\n\n out.println(res)\n out.close\n}\n\n\n\n\n\n"}, {"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 P358A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val N = sc.nextInt\n val P = Array.fill(N)(sc.nextLong)\n\n var flag = false\n breakable {\n for (i <- 0 until N - 2; j <- (i + 1) until N - 1) {\n val a = P(i)\n val b = P(i + 1)\n val c = P(j)\n val d = P(j + 1)\n if ((c - a) * (c - b) * (d - a) * (d - b) < 0) {\n flag = true\n break\n }\n }\n }\n\n val res = if (flag) \"yes\" else \"no\"\n\n out.println(res)\n out.close\n}\n\n\n\n\n\n"}, {"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\n\nobject P358A extends App {\n val sc = new Scanner(System.in)\n val out = new PrintWriter(System.out)\n\n val N = sc.nextInt\n val ps = List.fill(N / 2, 2)(sc.nextInt).transpose\n val res = if (ps(0) == ps(0).sorted && ps(1) == ps(1).sorted.reverse) \"no\"\n else \"yes\"\n\n out.println(res)\n out.close\n}\n\n\n\n"}], "src_uid": "f1b6b81ebd49f31428fe57913dfc604d"} {"nl": {"description": "Any resemblance to any real championship and sport is accidental.The Berland National team takes part in the local Football championship which now has a group stage. Let's describe the formal rules of the local championship: the team that kicked most balls in the enemy's goal area wins the game; the victory gives 3 point to the team, the draw gives 1 point and the defeat gives 0 points; a group consists of four teams, the teams are ranked by the results of six games: each team plays exactly once with each other team; the teams that get places 1 and 2 in the group stage results, go to the next stage of the championship. In the group stage the team's place is defined by the total number of scored points: the more points, the higher the place is. If two or more teams have the same number of points, then the following criteria are used (the criteria are listed in the order of falling priority, starting from the most important one): the difference between the total number of scored goals and the total number of missed goals in the championship: the team with a higher value gets a higher place; the total number of scored goals in the championship: the team with a higher value gets a higher place; the lexicographical order of the name of the teams' countries: the country with the lexicographically smaller name gets a higher place. The Berland team plays in the group where the results of 5 out of 6 games are already known. To be exact, there is the last game left. There the Berand national team plays with some other team. The coach asks you to find such score X:Y (where X is the number of goals Berland scored and Y is the number of goals the opponent scored in the game), that fulfills the following conditions: X > Y, that is, Berland is going to win this game; after the game Berland gets the 1st or the 2nd place in the group; if there are multiple variants, you should choose such score X:Y, where value X - Y is minimum; if it is still impossible to come up with one score, you should choose the score where value Y (the number of goals Berland misses) is minimum. ", "input_spec": "The input has five lines. Each line describes a game as \"team1 team2 goals1:goals2\" (without the quotes), what means that team team1 played a game with team team2, besides, team1 scored goals1 goals and team2 scored goals2 goals. The names of teams team1 and team2 are non-empty strings, consisting of uppercase English letters, with length of no more than 20 characters; goals1, goals2 are integers from 0 to 9. The Berland team is called \"BERLAND\". It is guaranteed that the Berland team and one more team played exactly 2 games and the the other teams played exactly 3 games.", "output_spec": "Print the required score in the last game as X:Y, where X is the number of goals Berland scored and Y is the number of goals the opponent scored. If the Berland team does not get the first or the second place in the group, whatever this game's score is, then print on a single line \"IMPOSSIBLE\" (without the quotes). Note, that the result score can be very huge, 10:0 for example.", "sample_inputs": ["AERLAND DERLAND 2:1\nDERLAND CERLAND 0:3\nCERLAND AERLAND 0:1\nAERLAND BERLAND 2:0\nDERLAND BERLAND 4:0", "AERLAND DERLAND 2:2\nDERLAND CERLAND 2:3\nCERLAND AERLAND 1:3\nAERLAND BERLAND 2:1\nDERLAND BERLAND 4:1"], "sample_outputs": ["6:0", "IMPOSSIBLE"], "notes": "NoteIn the first sample \"BERLAND\" plays the last game with team \"CERLAND\". If Berland wins with score 6:0, the results' table looks like that in the end: AERLAND (points: 9, the difference between scored and missed goals: 4, scored goals: 5) BERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 6) DERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 5) CERLAND (points: 3, the difference between scored and missed goals: -4, scored goals: 3) In the second sample teams \"AERLAND\" and \"DERLAND\" have already won 7 and 4 points, respectively. The Berland team wins only 3 points, which is not enough to advance to the next championship stage."}, "positive_code": [{"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\tfor (i <- 1 to 5) read (scanner)\n\t\tfor (team <- teams.values) {\n\t\t\tval (n, p, d, g, name) = team\n\t\t\tif (n < 3 && name != \"BERLAND\") enemy = name\n\t\t}\n\n\t\tval berland = teams(\"BERLAND\")\n\t\tval ans_ix = scores.indexWhere (score => rank (score) <= 2)\n\n\t\tif (ans_ix == -1) {\n\t\t\tprintln (\"IMPOSSIBLE\")\n\t\t} else {\n\t\t\tval (x, y) = scores(ans_ix)\n\t\t\tprintln (x + \":\" + y)\n\t\t}\n\t}\n\n\tval teams = scala.collection.mutable.Map.empty[String, (Int, Int, Int, Int, String)]\n\tval scores = (List.tabulate (30)(i => List.tabulate (30-i)(j => (i+j+1, j)))).flatten\n\tvar enemy = \"\"\n\n\tdef update(team: (Int, Int, Int, Int, String), score: (Int, Int)): (Int, Int, Int, Int, String) = {\n\t\tval (n, p, d, g, name) = team\n\t\tval (x, y) = score\n\t\tval pp = if (x > y) 3 else if (x < y) 0 else 1\n\t\t(n + 1, p + pp, d + x - y, g + x, name)\n\t}\n\n\tdef read(scanner: Scanner): Unit = {\n\t\tval a, b = scanner.next ()\n\t\tval xy = scanner.next ()\n\t\tval x = xy(0) - '0'\n\t\tval y = xy(2) - '0'\n\t\tteams(a) = update(teams.getOrElse(a, (0, 0, 0, 0, a)), (x, y))\n\t\tteams(b) = update(teams.getOrElse(b, (0, 0, 0, 0, b)), (y, x))\n\t}\n\n\tdef compare(a: (Int, Int, Int, Int, String), b: (Int, Int, Int, Int, String)): Int = {\n\t\tval (n_a, p_a, d_a, g_a, name_a) = a\n\t\tval (n_b, p_b, d_b, g_b, name_b) = b\n\t\tif (p_a > p_b) 1\n\t\telse if (p_a < p_b) -1\n\t\telse if (d_a > d_b) 1\n\t\telse if (d_a < d_b) -1\n\t\telse if (g_a > g_b) 1\n\t\telse if (g_a < g_b) -1\n\t\telse if (name_a < name_b) 1\n\t\telse if (name_a > name_b) -1\n\t\telse 0\n\t}\n\n\tdef rank(score: (Int, Int)): Int = {\n\t\tval (x, y) = score\n\t\tdef my_score(): (Int, Int, Int, Int, String) = {\n\t\t\tupdate(teams(\"BERLAND\"), score)\n\t\t}\n\t\tdef enemy_score(s: (Int, Int, Int, Int, String)): (Int, Int, Int, Int, String) = {\n\t\t\tval (n, p, d, g, name) = s\n\t\t\tif (name == enemy) update(s, (y, x)) else s\n\t\t}\n\n\t\t(teams.values.count (x => compare(my_score(), enemy_score(x)) < 0)) + 1\n\t}\n\n}\n"}], "negative_code": [], "src_uid": "5033d51c67b7ae0b1a2d9fd292fdced1"} {"nl": {"description": "Reforms have started in Berland again! At this time, the Parliament is discussing the reform of the calendar. To make the lives of citizens of Berland more varied, it was decided to change the calendar. As more and more people are complaining that \"the years fly by...\", it was decided that starting from the next year the number of days per year will begin to grow. So the coming year will have exactly a days, the next after coming year will have a + 1 days, the next one will have a + 2 days and so on. This schedule is planned for the coming n years (in the n-th year the length of the year will be equal a + n - 1 day).No one has yet decided what will become of months. An MP Palevny made the following proposal. The calendar for each month is comfortable to be printed on a square sheet of paper. We are proposed to make the number of days in each month be the square of some integer. The number of days per month should be the same for each month of any year, but may be different for different years. The number of days in each year must be divisible by the number of days per month in this year. This rule ensures that the number of months in each year is an integer. The number of days per month for each year must be chosen so as to save the maximum amount of paper to print the calendars. In other words, the number of days per month should be as much as possible. These rules provide an unambiguous method for choosing the number of days in each month for any given year length. For example, according to Palevny's proposition, a year that consists of 108 days will have three months, 36 days each. The year that consists of 99 days will have 11 months, 9 days each, and a year of 365 days will have 365 months, one day each.The proposal provoked heated discussion in the community, the famous mathematician Perelmanov quickly calculated that if the proposal is supported, then in a period of n years, beginning with the year that has a days, the country will spend p sheets of paper to print a set of calendars for these years. Perelmanov's calculations take into account the fact that the set will contain one calendar for each year and each month will be printed on a separate sheet.Repeat Perelmanov's achievement and print the required number p. You are given positive integers a and n. Perelmanov warns you that your program should not work longer than four seconds at the maximum test.", "input_spec": "The only input line contains a pair of integers a, n (1 ≤ a, n ≤ 107; a + n - 1 ≤ 107).", "output_spec": "Print the required number p. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use cin, cout streams or the %I64d specifier.", "sample_inputs": ["25 3", "50 5"], "sample_outputs": ["30", "125"], "notes": "NoteA note to the first sample test. A year of 25 days will consist of one month containing 25 days. A year of 26 days will consist of 26 months, one day each. A year of 27 days will have three months, 9 days each."}, "positive_code": [{"source_code": "import java.io._\n\nobject Solution {\n def main(args: Array[String]) {\n val in = new BufferedReader(new InputStreamReader(System.in))\n val a :: n :: _ = in.readLine.split(\" \").map(_.toInt).toList\n val max = a + n\n val d = new Array[Int](max + 1)\n for(i <- 0 to max) {\n d(i) = i\n }\n var i = 2\n while(i * i <= max) {\n if(d(i) == i) {\n var j = i * i\n while(j <= max) {\n if(d(j) == j) {\n d(j) = i\n }\n j += i\n }\n }\n i += 1\n }\n var ans = 0L\n for(i <- a until a + n) {\n var x = i\n var add = x\n while(x != 1) {\n val dd = d(x).toLong * d(x)\n if(x % dd == 0) {\n x /= dd.toInt\n add /= dd.toInt\n }\n else {\n x /= d(x)\n }\n }\n ans += add\n }\n println(ans)\n }\n}"}], "negative_code": [], "src_uid": "915081861e391958dce6ee2a117abd4e"} {"nl": {"description": "Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is \"123456789101112131415...\". Your task is to print the n-th digit of this string (digits are numbered starting with 1.", "input_spec": "The only line of the input contains a single integer n (1 ≤ n ≤ 1000) — the position of the digit you need to print.", "output_spec": "Print the n-th digit of the line.", "sample_inputs": ["3", "11"], "sample_outputs": ["3", "0"], "notes": "NoteIn the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.In the second sample, the digit at position 11 is '0', it belongs to the integer 10."}, "positive_code": [{"source_code": "object Solution extends App {\n val lines = io.Source.stdin.getLines()\n val n = lines.next().toInt\n val str = (0 to 1000).mkString\n println(str(n))\n}\n"}, {"source_code": "object A672 {\n\n import IO._\n\n def main(args: Array[String]): Unit = {\n val Array(n) = readInts(1)\n val ret = (1 to 500).flatMap(x => x.toString.toCharArray)\n println(ret(n-1))\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"}, {"source_code": "import scala.collection.mutable.ArrayBuffer\nimport scala.io.StdIn\n\n/**\n * Created by whimsy on 16/7/11.\n */\n\n\n\nobject P672A extends App {\n def work() : Int = {\n// val n : Int = StdIn.readInt()\n val n = 3\n var cnt: Int = 0\n\n\n for (i <- 1 to n) {\n var t = i\n var ab = ArrayBuffer[Int]()\n while (t > 0) {\n ab += t % 10\n t = t / 10\n// println(t)\n }\n\n for (j <- 0 to ab.length) {\n println(cnt)\n cnt = cnt + 1\n if (cnt == n) {\n println(ab(j))\n return 1\n }\n }\n }\n return 0\n }\n\n def work2() : Int = {\n val n = StdIn.readInt()\n\n var content = \"\"\n var cnt = 0\n while (true) {\n cnt = cnt + 1\n content += cnt\n\n if (content.length >= n) {\n println(content.charAt(n - 1))\n return 1\n }\n }\n return 0\n }\n\n work2()\n}"}], "negative_code": [], "src_uid": "2d46e34839261eda822f0c23c6e19121"} {"nl": {"description": "Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher.Neko has two integers $$$a$$$ and $$$b$$$. His goal is to find a non-negative integer $$$k$$$ such that the least common multiple of $$$a+k$$$ and $$$b+k$$$ is the smallest possible. If there are multiple optimal integers $$$k$$$, he needs to choose the smallest one.Given his mathematical talent, Neko had no trouble getting Wrong Answer on this problem. Can you help him solve it?", "input_spec": "The only line contains two integers $$$a$$$ and $$$b$$$ ($$$1 \\le a, b \\le 10^9$$$).", "output_spec": "Print the smallest non-negative integer $$$k$$$ ($$$k \\ge 0$$$) such that the lowest common multiple of $$$a+k$$$ and $$$b+k$$$ is the smallest possible. If there are many possible integers $$$k$$$ giving the same value of the least common multiple, print the smallest one.", "sample_inputs": ["6 10", "21 31", "5 10"], "sample_outputs": ["2", "9", "0"], "notes": "NoteIn the first test, one should choose $$$k = 2$$$, as the least common multiple of $$$6 + 2$$$ and $$$10 + 2$$$ is $$$24$$$, which is the smallest least common multiple possible."}, "positive_code": [{"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.sort\n\n import scala.collection.mutable\n import math.{abs, max, min}\n import mutable.ArrayBuffer\n import scala.reflect.ClassTag\n\n val MOD = 1000000007\n val out = new PrintWriter(System.out)\n\n def solve(): Unit = {\n val A, B = nl()\n val D = divisors(abs(B - A).toInt)\n var ans = (A * B / gcd(A, B), 0) // (lcm, k)\n REP(D.length) { i =>\n val d = D(i)\n val k = (d - A % d).toInt\n val a = A + k\n val b = B + k\n val lcm = a * b / gcd(a, b)\n if (ans._1 > lcm) {\n ans = (lcm, k)\n }\n }\n\n out.println(ans._2)\n }\n\n def gcd(a: Long, b: Long): Long = {\n if (b == 0) a\n else gcd(b, a % b)\n }\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 val postLen = post.length\n REP(postLen)(i => res(i + preLen) = post(postLen - 1 - i))\n res\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 debugDim(m: Array[Array[Long]]): Unit = DEBUG {\n REP(m.length) { i =>\n debug(m(i))\n }\n }\n\n def debugDimFlip(m: Array[Array[Long]]): Unit = DEBUG {\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\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}"}], "negative_code": [], "src_uid": "414149fadebe25ab6097fc67663177c3"} {"nl": {"description": "Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.Note that the game consisted of several complete sets.", "input_spec": "The first line contains three space-separated integers k, a and b (1 ≤ k ≤ 109, 0 ≤ a, b ≤ 109, a + b > 0).", "output_spec": "If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.", "sample_inputs": ["11 11 5", "11 2 3"], "sample_outputs": ["1", "-1"], "notes": "NoteNote that the rules of the game in this problem differ from the real table tennis game, for example, the rule of \"balance\" (the winning player has to be at least two points ahead to win a set) has no power within the present problem."}, "positive_code": [{"source_code": "import scala.io.StdIn\n\n/**\n * @author traff\n */\n\nobject Main extends App {\n val Array(k, a, b) = StdIn.readLine().split(\" \").map(_.toInt)\n\n val d = a/k + b /k\n if (d>0 && (a>=k || b>=k) && !(a0) && !(b0) ) {\n println(d)\n } else {\n println(\"-1\")\n }\n}\n\n"}], "negative_code": [{"source_code": "import scala.io.StdIn\n\n/**\n * @author traff\n */\n\nobject Main extends App {\n val Array(k, a, b) = StdIn.readLine().split(\" \").map(_.toInt)\n\n val d = (a + b) /k\n if (d>0) {\n println(d)\n } else {\n println(\"-1\")\n }\n}\n\n"}, {"source_code": "import scala.io.StdIn\n\n/**\n * @author traff\n */\n\nobject Main extends App {\n val Array(k, a, b) = StdIn.readLine().split(\" \").map(_.toInt)\n\n val d = (a + b) /k\n if (d>0 && (a>=k || b>=k) && !(a0) && !(b0) ) {\n println(d)\n } else {\n println(\"-1\")\n }\n}\n\n"}, {"source_code": "import scala.io.StdIn\n\n/**\n * @author traff\n */\n\nobject Main extends App {\n val Array(k, a, b) = StdIn.readLine().split(\" \").map(_.toInt)\n\n val d = (a + b) /k\n if (d>0 && (a>=k || b>=k)) {\n println(d)\n } else {\n println(\"-1\")\n }\n}\n\n"}, {"source_code": "import scala.io.StdIn\n\n/**\n * @author traff\n */\n\nobject Main extends App {\n val Array(k, a, b) = StdIn.readLine().split(\" \").map(_.toInt)\n\n val d = (a + b) /k\n if (d>0) {\n println(\"1\")\n } else {\n println(\"-1\")\n }\n}\n\n"}], "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2"} {"nl": {"description": "The cows have just learned what a primitive root is! Given a prime p, a primitive root is an integer x (1 ≤ x < p) such that none of integers x - 1, x2 - 1, ..., xp - 2 - 1 are divisible by p, but xp - 1 - 1 is. Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime p, help the cows find the number of primitive roots .", "input_spec": "The input contains a single line containing an integer p (2 ≤ p < 2000). It is guaranteed that p is a prime.", "output_spec": "Output on a single line the number of primitive roots .", "sample_inputs": ["3", "5"], "sample_outputs": ["1", "2"], "notes": "NoteThe only primitive root is 2.The primitive roots are 2 and 3."}, "positive_code": [{"source_code": "import scala.io._\n\nobject Main {\n\n\tdef main(args: Array[String]) = {\n\t\t\n\t\tvar P = nextInt\n\t\t\n\t\tdef isPrimitiveRoot(x: Int, P: Int): Boolean = {\n\n\t\t\tdef rec(n: Int, powX: Int): Boolean =\n\t\t\t\tif (n == P - 1)\n\t\t\t\t\tpowX == 1\n\t\t\t\telse\n\t\t\t\t\tpowX != 1 && rec(n + 1, powX * x % P)\n\t\t\t\t\n\t\t\trec(1, x)\n\t\t}\n\n\t\tval roots = (1 until P) filter (isPrimitiveRoot(_, P))\n\t\t\n\t\tprintln(roots.size)\n\t}\n\n\tval in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));\n\tvar st = new java.util.StringTokenizer(\"\");\n\n\tdef next() = {\n\t\twhile (!st.hasMoreTokens())\n\t\t\tst = new java.util.StringTokenizer(in.readLine());\n\t\tst.nextToken();\n\t}\n\n\tdef nextInt() = java.lang.Integer.parseInt(next());\n\tdef nextDouble() = java.lang.Double.parseDouble(next());\n\tdef nextLong() = java.lang.Long.parseLong(next());\n}"}, {"source_code": "import scala.io._\nimport java.util.StringTokenizer\nimport java.io.BufferedReader\n\nobject Main {\n \n def main(args: Array[String]): Unit = {\n val P = nextInt\n \n def isPrimitiveRoot(x: Int, p: Int, acc: Int): Boolean =\n if (p == P - 1)\n acc == 1\n else\n acc != 1 &&\n isPrimitiveRoot(x, p + 1, acc * x % P)\n \n val answer = 1 until P count (x => isPrimitiveRoot(x, 1, x)) \n \n println (answer)\n }\n \n class Tokenizer(in: BufferedReader, splitOn: String = \" \\n\\t\\r\\f\")\n {\n private var tokenizer = new StringTokenizer(\"\")\n def readLine() = in.readLine() \n def nextToken(): String = {\n while (!tokenizer.hasMoreTokens) {\n val line = readLine\n if (line == null) return null\n tokenizer = new StringTokenizer(line, splitOn)\n }\n tokenizer.nextToken\n } \n def next[A](f: String => A) = f(nextToken)\n def nextSeq[A](f: () => A, count: Int) = (for (i <- 0 until count) yield f())\n }\n \n implicit val tokenizer = new Tokenizer(Console.in)\n \n def nextInt()(implicit t: Tokenizer) = t.next(_.toInt)\n def nextLong()(implicit t: Tokenizer) = t.next(_.toLong)\n def nextDouble()(implicit t: Tokenizer) = t.next(_.toDouble)\n def nextBigInt()(implicit t: Tokenizer) = t.next(BigInt(_))\n def nextSeq[A](f: () => A, count: Int = nextInt())(implicit t: Tokenizer) =\n (for (i <- 0 until count) yield f())\n}\n"}], "negative_code": [], "src_uid": "3bed682b6813f1ddb54410218c233cff"}