{"nl": {"description": "Kolya is very absent-minded. Today his math teacher asked him to solve a simple problem with the equation $$$a + 1 = b$$$ with positive integers $$$a$$$ and $$$b$$$, but Kolya forgot the numbers $$$a$$$ and $$$b$$$. He does, however, remember that the first (leftmost) digit of $$$a$$$ was $$$d_a$$$, and the first (leftmost) digit of $$$b$$$ was $$$d_b$$$.Can you reconstruct any equation $$$a + 1 = b$$$ that satisfies this property? It may be possible that Kolya misremembers the digits, and there is no suitable equation, in which case report so.", "input_spec": "The only line contains two space-separated digits $$$d_a$$$ and $$$d_b$$$ ($$$1 \\leq d_a, d_b \\leq 9$$$).", "output_spec": "If there is no equation $$$a + 1 = b$$$ with positive integers $$$a$$$ and $$$b$$$ such that the first digit of $$$a$$$ is $$$d_a$$$, and the first digit of $$$b$$$ is $$$d_b$$$, print a single number $$$-1$$$. Otherwise, print any suitable $$$a$$$ and $$$b$$$ that both are positive and do not exceed $$$10^9$$$. It is guaranteed that if a solution exists, there also exists a solution with both numbers not exceeding $$$10^9$$$.", "sample_inputs": ["1 2", "4 4", "5 7", "6 2"], "sample_outputs": ["199 200", "412 413", "-1", "-1"], "notes": null}, "positive_code": [{"source_code": "\nfun readIntList() = readLine()!!.split(' ').map(String::toInt).toMutableList()\nfun readLongList() = readLine()!!.split(' ').map(String::toLong).toMutableList()\nfun readStringList() = readLine()!!.split(' ').toMutableList()\nfun readInt() = readLine()!!.toInt()\nfun readLong() = readLine()!!.toLong()\n\nfun main(args: Array) {\n\n val (a , b) = readIntList()\n\n\n if(a == b){\n println(\"${a}0 ${b}1\")\n }else if (a + 1 == b){\n println(\"${a}9 ${b}0\")\n }else if (a == 9 && b == 1){\n println(\"${a}9 ${b}00\")\n }else{\n println(-1)\n }\n\n\n}"}, {"source_code": "fun main(args : Array) {\n val (a, b) = readLine()!!.split(\" \") .map{it.toInt()}\n\n if (b - a == 0) {\n println(\"${a}1 ${b}2\")\n } else if (b - a == 1) {\n println(\"${a}9 ${b}0\")\n } else if (a == 9 && b == 1) {\n println(\"99 100\")\n } else {\n println(-1)\n }\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007L\n\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val da = ni()\n val db = ni()\n if (da == db) {\n out.println(\"${da}0 ${db}1\")\n } else if (db == da + 1) {\n out.println(\"$da $db\")\n } else if (da == 9 && db == 1){\n out.println(\"9 10\")\n } else {\n out.println(-1)\n }\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl() + offset\n }\n return res\n }\n\n private fun na2(n: Int, offset: Int = 0): Array {\n val a = Array(2){IntArray(n)}\n for (i in 0 until n) {\n for (e in a) {\n e[i] = ni() + offset\n }\n }\n return a\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}\n"}, {"source_code": "fun main() {\n var (m, k) = readLine()!!.split(\" \").map { it.toInt() }\n if(m != k && m + 1 != k) {\n if(m == 9 && k == 1) {\n println(\"${m} ${k * 10}\")\n } else {\n println(-1)\n }\n } else {\n if(m != k) {\n println(\"${m * 10 + 9} ${k * 10}\")\n } else {\n println(\"${m * 10 + 1} ${k * 10 + 2}\")\n }\n }\n}"}, {"source_code": "import kotlin.math.abs\nimport kotlin.math.min\n \nfun main() {\n task1()\n}\n \n \n \n \nfun task1() {\n \n var (a, b) = readLine()!!.split(\" \").map(String::toInt)\n \n if (a == 9 && b == 1) {\n print(\"9 10\")\n return\n }\n \n if (abs(a - b) > 1 || a > b) {\n println(\"-1\")\n } else if (a == b) {\n print(a * 10 + 1)\n print(\" \")\n print(b * 10 + 2)\n } else {\n print(a * 10 + 9)\n print(\" \")\n print(b * 10)\n }\n}"}, {"source_code": "fun main() {\n val (x, y) = readInts()\n when {\n x + 1 == y -> println(\"${x}9 ${y}0\")\n x == y -> println(\"${x}1 ${y}2\")\n x == 9 && y == 1 -> println(\"99 100\")\n else -> println(\"-1\")\n }\n}\n\nprivate fun readInts() = readLine()!!.split(\" \").map { it.toInt() }"}, {"source_code": "fun main() {\n val (da, db) = readInts()\n if (da == db) {\n val a = da*10\n val b = db*10 + 1\n println(\"$a $b\")\n } else if (da < 9 && db == da + 1) {\n val a = da*10 + 9\n val b = db*10\n println(\"$a $b\")\n } else if (da == 9 && db == 1) {\n val a = da*10 + 9\n val b = 100\n println(\"$a $b\")\n } else println(-1)\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\n\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\")\n\nimport java.io.PrintWriter\nimport java.util.PriorityQueue\nimport java.util.StringTokenizer\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln // immediate println for interactive\n\nfun main() {\n output {\n val da = readInt()\n val db = readInt()\n\n val a = when {\n db - da == 1 -> da\n db - da == 0 -> da * 10\n da == 9 && db == 1 -> 9\n else -> -1\n }\n\n if(a >= 0) {\n val b = a+1\n println(\"$a $b\")\n } else println(a)\n }\n}\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\ninline fun output(block: PrintWriter.() -> Unit) { _writer.apply(block).flush() }\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun R._shuffle(rnd: Random, get: R.(Int) -> V, set: R.(Int, V) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, IntArray::get, IntArray::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, LongArray::get, LongArray::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, DoubleArray::get, DoubleArray::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, CharArray::get, CharArray::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()"}, {"source_code": "fun main() {\n val input = readLine()!!.split(\" \").map(String::toInt)\n\n if (input[1] == 1 && input[0] == 9) {\n println(\"9 10\")\n } else if (input[1] == input[0] + 1) {\n val a = input[0] * 10 + 9\n val b = input[1] * 10\n println(\"$a $b\")\n } else if (input[1] == input[0]) {\n val a = input[0] * 10 + 1\n val b = input[1] * 10 + 2\n println(\"$a $b\")\n } else {\n println(-1)\n }\n}\n"}, {"source_code": "fun main() {\n val (da,db) = readLine()!!.split(\" \").map { it.toInt() }\n when {\n da == db -> println(\"${da*10} ${db*10 + 1}\")\n da + 1 == db -> //{da}9 {db}0\n println(\"${da}9 ${db}0\")\n da == 9 && db == 1 ->\n println(\"99 100\")\n else -> println(\"-1\")\n }\n}"}, {"source_code": "import java.util.*\n\n//30/11/2019\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val a = nextInt()\n val b = nextInt()\n when (b - a) {\n 0 -> {\n print(a * 100 + 1)\n print(\" \")\n print(a * 100 + 2)\n }\n 1 -> {\n print(b * 10 - 1)\n print(\" \")\n print(b * 10)\n }\n else -> {\n if (a == 9 && b == 1) {\n print(\"9 10\")\n } else {\n print(-1)\n }\n }\n }\n\n}"}, {"source_code": "fun main(args: Array) {\n val (a, b) = readLine()!!.split(\" \").map { it.toInt() }\n\n if (a == b) {\n println(\"${a}0 ${b}1\")\n } else if (a == 9 && b == 1) {\n println(\"9 10\")\n } else if (a + 1 == b) {\n println(\"${a}9 ${b}0\")\n } else {\n println(-1)\n }\n}"}, {"source_code": "\nclass ForgettingThings {\n fun resolve(input: String) {\n val splitInput = input.split(\" \")\n val b1 = splitInput[0].toInt()\n val b2 = splitInput[1].toInt()\n\n if(b1 == b2 ) {\n println(\"${b1}1 ${b1}2\")\n return;\n }\n\n if(b1 == b2 - 1) {\n println(\"${b1}9 ${b2}0\")\n return\n }\n\n if(b1 == 9 && b2 == 1) {\n println(\"99 100\")\n return\n }\n\n println(\"-1\")\n\n }\n\n fun test() {\n listOf(\n \"1 2\",\n \"4 4\",\n \"5 7\",\n \"6 2\",\n \"9 1\"\n ).map {\n resolve(it)\n }\n }\n}\n\n//val test = ForgettingThings().test()\n\nfun main() {\n val input = readLine()!!\n ForgettingThings().resolve(input)\n}"}, {"source_code": "import java.io.*\n\nprivate fun solve() {\n var (d1,d2) = readStrings();\n\n for (a in 1..1000) {\n if (a.toString()[0] == d1[0] && (a + 1).toString()[0] == d2[0]) {\n out.println(\"$a ${a+1}\").also { return }\n }\n }\n\n out.println(-1);\n}\n\nprivate fun readLn() = nextLine() // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n\nprivate var br: BufferedReader? = null\nprivate var out: PrintWriter = PrintWriter(System.out);\n\n@Throws(IOException::class)\nprivate fun nextLine(): String {\n return br!!.readLine()\n}\n\n@Throws(IOException::class)\nfun main() {\n var input = System.`in`\n var output = System.out\n try {\n val f = File(\"input.txt\")\n if (f.exists() && f.canRead()) {\n input = FileInputStream(f)\n output = PrintStream(\"output.txt\")\n }\n } catch (ignored: Throwable) {\n }\n br = BufferedReader(InputStreamReader(input))\n out = PrintWriter(PrintWriter(output))\n solve()\n br!!.close()\n out.close()\n}"}, {"source_code": "\nfun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n val (n, k) = r.readLine()!!.split(\" \").map { it.toInt() }\n when{\n k-n==1-> println(\"${n}9 ${k}0\")\n n==9&&k==1-> println(\"${n}9 ${k}00\")\n k==n -> println(\"${n}0 ${k}1\")\n else -> println(-1)\n }\n}"}, {"source_code": "import com.sun.xml.internal.fastinfoset.util.StringArray\nimport java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val da: Int = ir.nextInt()\n val db: Int = ir.nextInt()\n\n when {\n da - db == -1 -> pw.print(\"${da}99 ${db}00\")\n da == db -> pw.print(\"${da}00 ${da}01\")\n da - db == 8 -> pw.print(\"9 10\")\n else -> pw.print(-1)\n }\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextFloat(): Float {\n return java.lang.Float.parseFloat(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import com.sun.xml.internal.fastinfoset.util.StringArray\nimport java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val da: Int = ir.nextInt()\n val db: Int = ir.nextInt()\n\n when (da - db) {\n -1 -> pw.print(\"${da}99 ${db}00\")\n 0 -> pw.print(\"${da}00 ${da}01\")\n 8 -> pw.print(\"9 10\")\n else -> pw.print(-1)\n }\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextFloat(): Float {\n return java.lang.Float.parseFloat(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val inp = Main.InputReader(inputStream)\n val out = PrintWriter(outputStream)\n val solver = Main.TaskA()\n solver.solve(inp, out)\n out.close()\n}\n\nclass Main {\n internal class TaskA {\n fun solve(inp: InputReader, out: PrintWriter) {\n val f1 = inp.nextInt()\n val f2 = inp.nextInt()\n if (f1 == f2)\n out.println(\"${f1}0 ${f2}1\")\n else if (f1 < f2) {\n if (f2 - f1 == 1)\n out.println(\"${f1}9 ${f2}0\")\n else\n out.println(-1)\n } else {\n if (f1 == 9 && f2 == 1)\n out.println(\"9 10\")\n else\n out.println(-1)\n }\n }\n }\n\n internal class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return next().toLong()\n }\n }\n}\n"}, {"source_code": "fun main() {\n val (da, db) = readLine()!!\n .split(' ')\n .map { it.toInt() }\n\n when {\n db - da == 0 -> print(\"${da}0 ${db}1\")\n db - da == 1 -> print(\"$da $db\")\n db == 1 && da == 9 -> print(\"9 10\")\n else -> print(\"-1\")\n }\n}"}, {"source_code": "fun main() {\n val (a, b) = readLine()!!.split(' ').map(String::toInt)\n when {\n a == b - 1 -> println(\"${a * 10 + 9} ${b * 10}\")\n a == b -> println(\"${a * 10} ${b * 10 + 1}\")\n a == 9 && b == 1 -> println(\"99 100\")\n else -> println(\"-1\")\n }\n}"}, {"source_code": "fun main() {\n var list = readLine()!!.split(' ')\n var ans = \"\"\n var ans1 = \"\"\n if (list[0]==\"9\" && list[1]==\"1\") {\n println(\"9 10\")\n } else if ((list[1].toInt() - list[0].toInt()) == 0) {\n ans += list[0] + \"1\"\n ans1 += list[1] + \"2\"\n println(\"$ans $ans1\")\n } else if ((list[1].toInt() - list[0].toInt()) == 1) {\n ans += list[0] + \"9\"\n ans1 += list[1] + \"0\"\n println(\"$ans $ans1\")\n } else {\n println(-1)\n }\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (a, b) = readInts()\n print(\n when {\n b - a == 0 -> \"${a}0 ${a}1\"\n b - a == 1 -> \"${a}9 ${b}0\"\n a == 9 && b == 1 -> \"9 10\"\n else -> \"-1\"\n }\n )\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n val a = scanner.nextInt()\n val b = scanner.nextInt()\n\n if (a == b - 1) {\n print(\"$a $b\")\n } else if (a == b) {\n print(\"${a}00 ${b}01\")\n } else if (a == 9 && b == 1) {\n print(\"999 1000\")\n } else {\n print(-1)\n }\n}"}, {"source_code": "fun main() {\n val (a, b) = readLine()!!.split(\" \").map { it.toInt() }\n\n if (b - a == 1) {\n println(\"$a $b\")\n } else if (a == b) {\n print(\"$a\")\n print(\"1 $b\")\n println(\"2\")\n } else if (b == 1 && a == 9) {\n println(\"99 100\")\n } else {\n print(\"-1\")\n }\n}"}, {"source_code": "import java.util.Scanner\n\nfun main(args : Array){\n val reader = Scanner(System.`in`);\n \n var a:Int = reader.nextInt();\n var b:Int = reader.nextInt();\n\n if(a == 9 && b == 1){\n print(\"$a 10\");\n return;\n }\n\n if(a > b || Math.abs(a - b) > 1){\n println(-1);\n return;\n }\n\n if(a == b){\n print(a);\n print(\"1 \");\n print(b);\n println(\"2\");\n }\n else{\n print(a);\n print(\"9 \");\n print(b);\n println(\"0\");\n }\n}"}, {"source_code": "fun main(args: Array ) {\n val (a, b) = readLine()!!.split(\" \").map { it.toInt() }\n if ( a == b ) println( \"${10 * a + 1} ${10 * b + 2}\" )\n else if ( a + 1 == b ) println( \"${10 * a + 9} ${10 * b + 0}\" )\n else if ( a == 9 && b == 1 ) println( \"9 10\" )\n else println( -1 )\n}"}], "negative_code": [{"source_code": "\nfun readIntList() = readLine()!!.split(' ').map(String::toInt).toMutableList()\nfun readLongList() = readLine()!!.split(' ').map(String::toLong).toMutableList()\nfun readStringList() = readLine()!!.split(' ').toMutableList()\nfun readInt() = readLine()!!.toInt()\nfun readLong() = readLine()!!.toLong()\n\nfun main(args: Array) {\n\n val (a , b) = readIntList()\n\n\n if(a == b){\n println(\"${a}0 ${b}1\")\n }else if (a + 1 == b){\n println(\"${a}9 ${b}0\")\n }else{\n println(-1)\n }\n\n\n}"}, {"source_code": "fun main(args : Array) {\n val (a, b) = readLine()!!.split(\" \") .map{it.toInt()}\n\n if (b - a == 0) {\n println(\"${a}1 ${b}2\")\n } else if (b - a == 1) {\n println(\"${a}9 ${b}0\")\n } else {\n println(-1)\n }\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007L\n\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val da = ni()\n val db = ni()\n if (da == db) {\n out.println(\"$da $db\")\n } else if (db == da + 1) {\n out.println(\"$da $db\")\n } else if (da == 9 && db == 1){\n out.println(\"9 10\")\n } else {\n out.println(-1)\n }\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl() + offset\n }\n return res\n }\n\n private fun na2(n: Int, offset: Int = 0): Array {\n val a = Array(2){IntArray(n)}\n for (i in 0 until n) {\n for (e in a) {\n e[i] = ni() + offset\n }\n }\n return a\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}\n"}, {"source_code": "fun main() {\n var (m, k) = readLine()!!.split(\" \").map { it.toInt() }\n if(m != k && m + 1 != k) {\n println(-1)\n } else {\n if(m != k) {\n println(\"${m * 10 + 9} ${k * 10}\")\n } else {\n println(\"${m * 10 + 1} ${k * 10 + 2}\")\n }\n }\n}"}, {"source_code": "\nimport kotlin.math.abs\nimport kotlin.math.min\n\nfun main() {\n task1()\n}\n\n\n\n\nfun task1() {\n\n var (a, b) = readLine()!!.split(\" \").map(String::toInt)\n\n if (a == 9 || b == 1) {\n print(\"9 10\")\n return\n }\n \n if (abs(a - b) > 1 || a > b) {\n println(\"-1\")\n } else if (a == b) {\n print(a * 10 + 1)\n print(\" \")\n print(b * 10 + 2)\n } else {\n print(a * 10 + 9)\n print(\" \")\n print(b * 10)\n }\n}"}, {"source_code": "import kotlin.math.abs\n\nfun main() {\n task1()\n}\n\nfun task1() {\n\n var (a, b) = readLine()!!.split(\" \").map(String::toInt)\n\n if (abs(a - b) > 1 || a > b) {\n println(\"-1\")\n } else if (a == b)\n {\n print(a * 10 + 1)\n print( \" \")\n print(b * 10 + 2)\n } else {\n print(a * 10 + 9)\n print( \" \")\n print(b * 10)\n }\n}\n"}, {"source_code": "fun main() {\n val (x, y) = readInts()\n when {\n x + 1 == y -> println(\"${x}9 ${y}0\")\n x == y -> println(\"${x}1 ${y}2\")\n else -> println(\"-1\")\n }\n}\n\nprivate fun readInt() = readLine()!!.toInt()\n\nprivate fun readInts() = readLine()!!.split(\" \").map { it.toInt() }"}, {"source_code": "fun main() {\n val (x, y) = readInts()\n when {\n x + 1 == y -> println(\"${x}9 ${y}0\")\n x == y -> println(\"${x}1 ${y}2\")\n else -> println(\"-1\")\n }\n}\n\nprivate fun readInts() = readLine()!!.split(\" \").map { it.toInt() }"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\")\n\nimport java.io.PrintWriter\nimport java.util.PriorityQueue\nimport java.util.StringTokenizer\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln // immediate println for interactive\n\nfun main() {\n output {\n val da = readInt()\n val db = readInt()\n\n val a = when(db - da) {\n 1 -> da\n 0 -> da * 10\n else -> -1\n }\n\n if(a >= 0) {\n val b = a+1\n println(\"$a $b\")\n } else println(a)\n }\n}\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\ninline fun output(block: PrintWriter.() -> Unit) { _writer.apply(block).flush() }\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun R._shuffle(rnd: Random, get: R.(Int) -> V, set: R.(Int, V) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, IntArray::get, IntArray::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, LongArray::get, LongArray::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, DoubleArray::get, DoubleArray::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, CharArray::get, CharArray::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()"}, {"source_code": "fun main() {\n val input = readLine()!!.split(\" \").map(String::toInt)\n\n val diff = input[1] - input[0]\n if (diff < 0 || 1 < diff) {\n println(-1)\n return\n }\n\n if (input[1] > input[0]) {\n val a = input[0] * 10 + 9\n val b = input[1] * 10\n println(\"$a $b\")\n } else {\n val a = input[0] * 10 + 1\n val b = input[1] * 10 + 2\n println(\"$a $b\")\n }\n}\n"}, {"source_code": "fun main() {\n val input = readLine()!!.split(\" \").map(String::toInt)\n\n if (input[1] == input[0] + 1) {\n val a = input[0] * 10 + 9\n val b = input[1] * 10\n println(\"$a $b\")\n } else if (input[1] == input[0]) {\n val a = input[0] * 10 + 1\n val b = input[1] * 10 + 2\n println(\"$a $b\")\n } else {\n println(-1)\n }\n}\n"}, {"source_code": "fun main() {\n val (da,db) = readLine()!!.split(\" \").map { it.toInt() }\n when {\n da == db -> println(\"${da*10} ${db*10 + 1}\")\n da + 1 == db -> //{da}9 {db}0\n println(\"${da}9 ${db}0\")\n else -> println(\"-1\")\n }\n}"}, {"source_code": "import java.util.*\n\n//30/11/2019\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val a = nextInt()\n val b = nextInt()\n when (b - a) {\n 0 -> {\n print(a * 100 + 1)\n print(\" \")\n print(a * 100 + 2)\n }\n 1 -> {\n print(b * 10 - 1)\n print(\" \")\n print(b * 10)\n }\n else -> {\n print(-1)\n }\n }\n\n}"}, {"source_code": "import java.util.*\n\n//30/11/2019\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val a = nextInt()\n val b = nextInt()\n when (b - a) {\n 0 -> {\n print(a * 100 + 1)\n print(\" \")\n print(a * 100 + 2)\n }\n 1 -> {\n print(b * 10 - 1)\n print(\" \")\n print(b * 10)\n }\n else -> {\n if (a == 9 && b == 1) {\n print(a)\n print(\" \")\n print(b)\n } else {\n print(-1)\n }\n }\n }\n\n}"}, {"source_code": "import com.sun.xml.internal.fastinfoset.util.StringArray\nimport java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val da: Int = ir.nextInt()\n val db: Int = ir.nextInt()\n\n if (da - db == -1)\n pw.print(\"${da}99 ${db}00\")\n else if (da == db)\n pw.print(\"${da}00 ${da}01\")\n else\n pw.print(-1)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextFloat(): Float {\n return java.lang.Float.parseFloat(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val inp = Main.InputReader(inputStream)\n val out = PrintWriter(outputStream)\n val solver = Main.TaskA()\n solver.solve(inp, out)\n out.close()\n}\n\nclass Main {\n internal class TaskA {\n fun solve(inp: InputReader, out: PrintWriter) {\n val f1 = inp.nextInt()\n val f2 = inp.nextInt()\n if (f1 == f2)\n out.println(\"${f1}0 ${f2}1\")\n else if (f1 < f2) {\n if (f2 - f1 == 1)\n out.println(\"${f1}9 ${f2}0\")\n else\n out.println(-1)\n } else\n out.println(-1)\n }\n }\n\n internal class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return next().toLong()\n }\n }\n}\n"}, {"source_code": "fun main() {\n val (a, b) = readLine()!!.split(' ').map(String::toInt)\n when {\n a == b + 1 -> println(\"${a * 10 + 9} ${b * 10}\")\n a == b -> println(\"${a * 10} ${b * 10 + 1}\")\n a == 9 && b == 1 -> println(\"99 100\")\n else -> println(\"-1\")\n }\n}"}, {"source_code": "fun main() {\n val (a, b) = readLine()!!.split(' ').map(String::toInt)\n when (b - a) {\n 1 -> println(\"${a * 10 + 9} ${b * 10}\")\n 0 -> println(\"${a * 10 + 1} ${b * 10 + 2}\")\n else -> println(\"-1\")\n }\n}"}, {"source_code": "fun main() {\n var list = readLine()!!.split(' ')\n var ans = \"\"\n var ans1 = \"\"\n if ((list[1].toInt() - list[0].toInt()) == 0) {\n ans += list[0] + \"1\"\n ans1 += list[1] + \"2\"\n println(\"$ans $ans1\")\n } else if ((list[1].toInt() - list[0].toInt()) == 1) {\n ans += list[0] + \"9\"\n ans1 += list[1] + \"0\"\n println(\"$ans $ans1\")\n } else {\n println(-1)\n }\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (a, b) = readInts()\n print(\n when {\n b - a == 0 -> \"${a}0 ${a}1\"\n b - a == 1 -> \"${a}9 ${b}0\"\n else -> \"-1\"\n }\n )\n}"}, {"source_code": "import java.util.Scanner\n\nfun main(args : Array){\n val reader = Scanner(System.`in`);\n \n var a:Int = reader.nextInt();\n var b:Int = reader.nextInt();\n\n if(a > b || Math.abs(a - b) > 1){\n println(-1);\n return;\n }\n\n if(a == b){\n print(a);\n print(\"1 \");\n print(b);\n println(\"2\");\n }\n else{\n print(a);\n print(\"9 \");\n print(b);\n println(\"0\");\n }\n}"}], "src_uid": "3eff6f044c028146bea5f0dfd2870d23"} {"nl": {"description": "Alice has got addicted to a game called Sirtet recently.In Sirtet, player is given an $$$n \\times m$$$ grid. Initially $$$a_{i,j}$$$ cubes are stacked up in the cell $$$(i,j)$$$. Two cells are called adjacent if they share a side. Player can perform the following operations: stack up one cube in two adjacent cells; stack up two cubes in one cell. Cubes mentioned above are identical in height.Here is an illustration of the game. States on the right are obtained by performing one of the above operations on the state on the left, and grey cubes are added due to the operation. Player's goal is to make the height of all cells the same (i.e. so that each cell has the same number of cubes in it) using above operations. Alice, however, has found out that on some starting grids she may never reach the goal no matter what strategy she uses. Thus, she is wondering the number of initial grids such that $$$L \\le a_{i,j} \\le R$$$ for all $$$1 \\le i \\le n$$$, $$$1 \\le j \\le m$$$; player can reach the goal using above operations. Please help Alice with it. Notice that the answer might be large, please output the desired value modulo $$$998,244,353$$$.", "input_spec": "The only line contains four integers $$$n$$$, $$$m$$$, $$$L$$$ and $$$R$$$ ($$$1\\le n,m,L,R \\le 10^9$$$, $$$L \\le R$$$, $$$n \\cdot m \\ge 2$$$).", "output_spec": "Output one integer, representing the desired answer modulo $$$998,244,353$$$.", "sample_inputs": ["2 2 1 1", "1 2 1 2"], "sample_outputs": ["1", "2"], "notes": "NoteIn the first sample, the only initial grid that satisfies the requirements is $$$a_{1,1}=a_{2,1}=a_{1,2}=a_{2,2}=1$$$. Thus the answer should be $$$1$$$.In the second sample, initial grids that satisfy the requirements are $$$a_{1,1}=a_{1,2}=1$$$ and $$$a_{1,1}=a_{1,2}=2$$$. Thus the answer should be $$$2$$$."}, "positive_code": [{"source_code": "import java.util.*\nimport java.io.*\n\nval MOD = 998244353L\n\nfun main()\n{\n\tThread(null, Main(), \"whatever\", 1 shl 28).start()\n}\n\nclass Main : Runnable {\n\n\toverride fun run()\n\t{\n\t\tval inputStream = System.`in`\n\t\tval outputStream = System.out\n\t\tval `in` = InputReader(inputStream)\n\t\tval out = PrintWriter(outputStream)\n\t\tval solver = TaskD()\n\t\tvar test = 1\n\t\t//test = `in`.nextInt()\n\t\tfor (t in 1..test)\n\t\t{\n\t\t\tsolver.solve(t, `in`, out)\n\t\t}\n\t\tout.close()\n\t}\n\n\tinternal class TaskD\n\t{\n\t\tfun solve(testNumber: Int, `in`: InputReader, out: PrintWriter) {\n\t\t\tval INF = 4000000000000000000L\n\t\t\tval dx = intArrayOf(-1, 1, 0, 0)\n\t\t\tval dy = intArrayOf(0, 0, -1, 1)\n\n\t\t\tvar n = `in`.nextLong()\n\t\t\tvar m = `in`.nextLong()\n\t\t\tvar L = `in`.nextLong()\n\t\t\tvar R = `in`.nextLong()\n\t\t\tvar len = R-L+1\n\t\t\t\n\t\t\tif (n*m%2 == 1L) return out.println(power(len, n*m, MOD))\n\n\t\t\tvar a = len/2\n\t\t\tvar b = len-a\n\t\t\tif (L%2 == 0L)\n\t\t\t{\n\t\t\t\tvar tmp = a\n\t\t\t\ta = b\n\t\t\t\tb = tmp\n\t\t\t}\n\n\t\t\tfun go(a: Long, b: Long, n: Long): Pair\n\t\t\t{\n\t\t\t\tif (n == 0L) return Pair(1, 0)\n\t\t\t\tvar (c, d) = go(a, b, n/2)\n\t\t\t\tvar (tc, td) = Pair((c*c+d*d)%MOD, (2*c*d)%MOD)\n\t\t\t\tc = tc\n\t\t\t\td = td\n\t\t\t\tif (n%2 == 1L)\n\t\t\t\t{\n\t\t\t\t\tvar (sc, sd) = Pair((a*c+b*d)%MOD, (a*d+b*c)%MOD)\n\t\t\t\t\tc = sc\n\t\t\t\t\td = sd\n\t\t\t\t}\n\t\t\t\treturn Pair(c, d)\n\t\t\t}\n\n\t\t\tvar (x, y) = go(a, b, n*m)\n\t\t\tout.println(x)\n\t\t}\n \n\t}\n\n\tinternal class InputReader(stream: InputStream) {\n\t\tvar reader: BufferedReader\n\t\tvar tokenizer: StringTokenizer? = null\n\n\t\tinit {\n\t\t\treader = BufferedReader(InputStreamReader(stream), 32768)\n\t\t\ttokenizer = null\n\t\t}\n\n\t\toperator fun next(): String {\n\t\t\twhile (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = StringTokenizer(reader.readLine())\n\t\t\t\t} catch (e: IOException) {\n\t\t\t\t\tthrow RuntimeException(e)\n\t\t\t\t}\n\n\t\t\t}\n\t\t\treturn tokenizer!!.nextToken()\n\t\t}\n\n\t\tfun nextInt(): Int {\n\t\t\treturn Integer.parseInt(next())\n\t\t}\n\n\t\tfun nextLong(): Long {\n\t\t return next().toLong()\n\t\t}\n\n\t}\n}\n\nfun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a%b)\n\nfun power(a: Long, b: Long, p: Long): Long\n{\n\tif (b == 0L) return 1L\n\tvar t = power(a, b/2, p)\n\tt = t*t%p\n\tif (b%2 == 1L) t = t*a%p\n\treturn t\n}\n"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\n\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n val n = readInt()\n val m = readInt()\n val nm = n.toLong() * m\n val l = readInt()\n val r = readInt()\n val sz = r-l+1\n\n val tot = sz.toModInt().pow(nm)\n val ans = when {\n nm and 1 == 1L -> tot\n sz and 1 == 0 -> tot/2\n else -> (tot+1)/2\n }\n println(ans)\n}\n\nconst val MOD = 998244353\nconst val TOTIENT = MOD - 1 // assumes MOD is prime\n\ninfix fun Int.umod(mod: Int): Int = (this % mod).let { (it shr Int.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Long) = (this % mod).let { (it shr Long.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Int) = umod(mod.toLong()).toInt()\n\nfun Int.mulMod(other: Int, mod: Int) = toLong() * other umod mod\n\nfun Int.powMod(exponent: Int, mod: Int): Int {\n if(exponent < 0) error(\"Inverse not implemented\")\n var res = 1L\n var e = exponent\n var b = umod(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\n\ninline fun Int.toModInt() = ModInt(this umod MOD)\ninline fun Long.toModInt() = ModInt(this umod MOD)\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n companion object {\n /** can't seem to make these private or inlined without causing compiler issues */\n @JvmField val _invMemo = HashMap()\n fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }\n }\n\n // normalizes an integer that's within range [-MOD, MOD) without branching\n private inline fun normalize(int: Int) = ModInt((int shr Int.SIZE_BITS - 1 and MOD) + int)\n\n operator fun plus(other: ModInt) = normalize(int + other.int - MOD) // overflow-safe even if MOD >= 2^30\n inline operator fun plus(other: Int) = plus(other.toModInt())\n operator fun inc() = normalize(int + (1 - MOD))\n\n operator fun minus(other: ModInt) = normalize(int - other.int)\n inline operator fun minus(other: Int) = minus(other.toModInt())\n operator fun dec() = normalize(int - 1)\n operator fun unaryMinus() = normalize(-int)\n\n operator fun times(other: ModInt) = ModInt((int.toLong() * other.int % MOD).toInt())\n inline operator fun times(other: Int) = ModInt(int.mulMod(other, MOD))\n\n fun pow(exponent: Int): ModInt {\n val e = if(exponent < 0) {\n require(int != 0) { \"Can't invert/divide by 0\" }\n exponent umod TOTIENT\n } else exponent\n return ModInt(int.powMod(e, MOD))\n }\n\n fun pow(exponent: Long) = if(int == 0) when {\n exponent > 0 -> this\n exponent == 0L -> ModInt(1)\n else -> error(\"Can't invert/divide by 0\")\n } else pow(exponent umod TOTIENT)\n\n inline fun inverse() = inv_memoized() /** NOTE: Change if necessary */\n\n fun inv_unmemoized(): ModInt {\n require(int != 0) { \"Can't invert/divide by 0\" }\n return pow(TOTIENT - 1)\n }\n inline fun inv_memoized() = _invMemoized(this)\n\n operator fun div(other: ModInt) = times(other.inverse())\n inline operator fun div(other: Int) = div(other.toModInt())\n\n override inline fun toString() = int.toString()\n}\n\ninline operator fun Int.plus(modInt: ModInt) = modInt + this\ninline operator fun Int.minus(modInt: ModInt) = toModInt() - modInt\ninline operator fun Int.times(modInt: ModInt) = modInt * this\ninline operator fun Int.div(modInt: ModInt) = modInt.inverse() * this\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n inline operator fun get(i: Int) = ModInt(intArray[i])\n inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override inline val size: Int get() = intArray.size\n inline val lastIndex get() = intArray.lastIndex\n inline val indices get() = intArray.indices\n\n override inline fun contains(element: ModInt): Boolean = element.int in intArray\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override inline fun isEmpty(): Boolean = intArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): ModInt = get(index++)\n }\n\n fun copyOf(newSize: Int) = ModIntArray(intArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun ModIntArray.copyInto(destination: ModIntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =\n ModIntArray(intArray.copyInto(destination.intArray, destinationOffset, startIndex, endIndex))\ninline fun ModIntArray(size: Int) = ModIntArray(IntArray(size))\ninline fun ModIntArray(size: Int, init: (Int) -> ModInt) = ModIntArray(IntArray(size) { init(it).int })\n\nfun ModInt.powArray(n: Int): ModIntArray {\n val res = ModIntArray(n+1)\n res[0] = ModInt(1)\n for(i in 1..n) res[i] = res[i-1] * this\n return res\n}\n\ninline fun ModIntArray.first() = get(0)\ninline fun ModIntArray.last() = get(lastIndex)\ninline fun ModIntArray.fold(init: R, op: (acc: R, ModInt) -> R) = intArray.fold(init) { acc, i -> op(acc, ModInt(i)) }\nfun ModIntArray.sum() = fold(ModInt(0), ModInt::plus)\nfun ModIntArray.product() = fold(ModInt(1), ModInt::times)\n\ninline fun Iterable.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Iterable.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\ninline fun Sequence.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Sequence.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\nfun Iterable.sum() = sumByModInt { it }\nfun Sequence.sum() = sumByModInt { it }\nfun Iterable.product() = productByModInt { it }\nfun Sequence.product() = productByModInt { it }\nfun Collection.toModIntArray() = ModIntArray(size).also { var i = 0; for(e in this) { it[i++] = e } }\n\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _ln = \"\"\n@JvmField var _lnPtr = 0\nfun read(): String {\n while (_lnPtr >= _ln.length) {\n _ln = readLine() ?: return \"\"\n _lnPtr = 0\n }\n var j = _ln.indexOf(' ', _lnPtr)\n if(j < 0) j = _ln.length\n val res = _ln.substring(_lnPtr, j)\n _lnPtr = j + 1\n return res\n}\nfun readRem(): String /* reads remainder of current line */ =\n _ln.substring(min(_lnPtr, _ln.length)).also { _lnPtr = _ln.length }\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\n\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n val n = readInt()\n val m = readInt()\n val nm = n.toLong() * m\n val l = readInt()\n val r = readInt()\n val sz = r-l+1\n\n val ans = run {\n if(nm and 1 == 1L) return@run sz.toModInt().pow(nm)\n\n val fft = ModFFT(1)\n val A = ModIntArray(intArrayOf(sz / 2, (sz + 1) / 2))\n fft.inPlace(A, false)\n\n for (i in A.indices) A[i] = A[i].pow(nm)\n fft.inPlace(A, true)\n\n A[0]\n }\n println(ans)\n}\n\ninline val PRIMITIVE_ROOT get() = ModInt(3) // for 998244353\nclass ModFFT(maxDeg: Int) {\n val n = getArrSize(maxDeg)\n private val ninv = ModInt(n).inv_unmemoized()\n\n fun getArrSize(deg: Int) = Integer.highestOneBit(deg shl 1 or 1)\n // prepares an array of suitable size for inPlace\n fun prepare(arr: ModIntArray, deg: Int) = arr.copyOf(getArrSize(deg))\n\n // w[1] represents n-th root of unity e^(i * tau/n), w[k] = w[1]^k\n val w = PRIMITIVE_ROOT.pow(TOTIENT / n).powArray(n-1)\n\n // rev[i] is reversal of bits in i\n private val rev = IntArray(n).also { rev ->\n var bit = 1\n var rbit = n shr 1\n while(bit < n) {\n for(i in 0 until bit) {\n rev[i or bit] = rbit or rev[i]\n }\n bit = bit shl 1\n rbit = rbit shr 1\n }\n }\n\n operator fun invoke(a: ModIntArray, invert: Boolean): ModIntArray {\n val res = a.copyOf(n)\n inPlace(res, invert)\n return res\n }\n\n // in-place FFT. Precondition: a.size <= n, and a.size is a power of 2\n fun inPlace(a: ModIntArray, invert: Boolean) {\n val sz = a.size\n if(sz <= 1) return\n require(sz <= n && sz and -sz == sz) { \"Array size $sz must be less than $n and a power of 2\" }\n val st = n / sz\n for(i in 0 until sz) {\n val j = rev[i * st]\n if(i < j) a[i] = a[j].also { a[j] = a[i] }\n }\n\n var len = 2\n var ang = n shr 1 // = n / len, representing the angle tau / len\n if(invert) ang = -ang\n while(len <= sz) {\n var i = 0\n while(i < sz) {\n var k = 0\n for(j in i until i+len.shr(1)) {\n val u = a[j]\n val v = a[j+len.shr(1)] * w[k]\n a[j] = u + v\n a[j+len.shr(1)] = u - v\n k = k + ang and n-1\n }\n i += len\n }\n\n len = len shl 1\n ang = ang shr 1\n }\n\n if(invert) {\n val szinv = ninv * st\n for(i in 0 until sz) a[i] *= szinv\n }\n }\n\n fun mul(a: ModIntArray, b: ModIntArray): ModIntArray {\n val deg = a.lastIndex + b.lastIndex\n require(deg < n) { \"FFT capacity $n too small for polynomial of degree $deg\" }\n val a1 = prepare(a, deg)\n val b1 = prepare(b, deg)\n inPlace(a1, false)\n inPlace(b1, false)\n for(i in a1.indices) a1[i] *= b1[i]\n inPlace(a1, true)\n return a1//.copyOf(deg+1)\n }\n}\n\nconst val MOD = 998244353\nconst val TOTIENT = MOD - 1 // assumes MOD is prime\n\ninfix fun Int.umod(mod: Int): Int = (this % mod).let { (it shr Int.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Long) = (this % mod).let { (it shr Long.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Int) = umod(mod.toLong()).toInt()\n\nfun Int.mulMod(other: Int, mod: Int) = toLong() * other umod mod\n\nfun Int.powMod(exponent: Int, mod: Int): Int {\n if(exponent < 0) error(\"Inverse not implemented\")\n var res = 1L\n var e = exponent\n var b = umod(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\n\ninline fun Int.toModInt() = ModInt(this umod MOD)\ninline fun Long.toModInt() = ModInt(this umod MOD)\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n companion object {\n /** can't seem to make these private or inlined without causing compiler issues */\n @JvmField val _invMemo = HashMap()\n fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }\n }\n\n // normalizes an integer that's within range [-MOD, MOD) without branching\n private inline fun normalize(int: Int) = ModInt((int shr Int.SIZE_BITS - 1 and MOD) + int)\n\n operator fun plus(other: ModInt) = normalize(int + other.int - MOD) // overflow-safe even if MOD >= 2^30\n inline operator fun plus(other: Int) = plus(other.toModInt())\n operator fun inc() = normalize(int + (1 - MOD))\n\n operator fun minus(other: ModInt) = normalize(int - other.int)\n inline operator fun minus(other: Int) = minus(other.toModInt())\n operator fun dec() = normalize(int - 1)\n operator fun unaryMinus() = normalize(-int)\n\n operator fun times(other: ModInt) = ModInt((int.toLong() * other.int % MOD).toInt())\n inline operator fun times(other: Int) = ModInt(int.mulMod(other, MOD))\n\n fun pow(exponent: Int): ModInt {\n val e = if(exponent < 0) {\n require(int != 0) { \"Can't invert/divide by 0\" }\n exponent umod TOTIENT\n } else exponent\n return ModInt(int.powMod(e, MOD))\n }\n\n fun pow(exponent: Long) = if(int == 0) when {\n exponent > 0 -> this\n exponent == 0L -> ModInt(1)\n else -> error(\"Can't invert/divide by 0\")\n } else pow(exponent umod TOTIENT)\n\n inline fun inverse() = inv_memoized() /** NOTE: Change if necessary */\n\n fun inv_unmemoized(): ModInt {\n require(int != 0) { \"Can't invert/divide by 0\" }\n return pow(TOTIENT - 1)\n }\n inline fun inv_memoized() = _invMemoized(this)\n\n operator fun div(other: ModInt) = times(other.inverse())\n inline operator fun div(other: Int) = div(other.toModInt())\n\n override inline fun toString() = int.toString()\n}\n\ninline operator fun Int.plus(modInt: ModInt) = modInt + this\ninline operator fun Int.minus(modInt: ModInt) = toModInt() - modInt\ninline operator fun Int.times(modInt: ModInt) = modInt * this\ninline operator fun Int.div(modInt: ModInt) = modInt.inverse() * this\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n inline operator fun get(i: Int) = ModInt(intArray[i])\n inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override inline val size: Int get() = intArray.size\n inline val lastIndex get() = intArray.lastIndex\n inline val indices get() = intArray.indices\n\n override inline fun contains(element: ModInt): Boolean = element.int in intArray\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override inline fun isEmpty(): Boolean = intArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): ModInt = get(index++)\n }\n\n fun copyOf(newSize: Int) = ModIntArray(intArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun ModIntArray.copyInto(destination: ModIntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =\n ModIntArray(intArray.copyInto(destination.intArray, destinationOffset, startIndex, endIndex))\ninline fun ModIntArray(size: Int) = ModIntArray(IntArray(size))\ninline fun ModIntArray(size: Int, init: (Int) -> ModInt) = ModIntArray(IntArray(size) { init(it).int })\n\nfun ModInt.powArray(n: Int): ModIntArray {\n val res = ModIntArray(n+1)\n res[0] = ModInt(1)\n for(i in 1..n) res[i] = res[i-1] * this\n return res\n}\n\ninline fun ModIntArray.first() = get(0)\ninline fun ModIntArray.last() = get(lastIndex)\ninline fun ModIntArray.fold(init: R, op: (acc: R, ModInt) -> R) = intArray.fold(init) { acc, i -> op(acc, ModInt(i)) }\nfun ModIntArray.sum() = fold(ModInt(0), ModInt::plus)\nfun ModIntArray.product() = fold(ModInt(1), ModInt::times)\n\ninline fun Iterable.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Iterable.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\ninline fun Sequence.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Sequence.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\nfun Iterable.sum() = sumByModInt { it }\nfun Sequence.sum() = sumByModInt { it }\nfun Iterable.product() = productByModInt { it }\nfun Sequence.product() = productByModInt { it }\nfun Collection.toModIntArray() = ModIntArray(size).also { var i = 0; for(e in this) { it[i++] = e } }\n\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _ln = \"\"\n@JvmField var _lnPtr = 0\nfun read(): String {\n while (_lnPtr >= _ln.length) {\n _ln = readLine() ?: return \"\"\n _lnPtr = 0\n }\n var j = _ln.indexOf(' ', _lnPtr)\n if(j < 0) j = _ln.length\n val res = _ln.substring(_lnPtr, j)\n _lnPtr = j + 1\n return res\n}\nfun readRem(): String /* reads remainder of current line */ =\n _ln.substring(min(_lnPtr, _ln.length)).also { _lnPtr = _ln.length }\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\n\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n val n = readInt()\n val m = readInt()\n val nm = n.toLong() * m\n val l = readInt()\n val r = readInt()\n val sz = r-l+1\n\n val ans = run {\n if(nm and 1 == 1L) return@run sz.toModInt().pow(nm)\n\n var u = ModInt(sz / 2)\n var v = ModInt((sz + 1) / 2)\n\n v = u - v.also { u += v }\n\n u = u.pow(nm)\n v = v.pow(nm)\n\n v = u - v.also { u += v }\n\n u/2\n }\n println(ans)\n}\n\nconst val MOD = 998244353\nconst val TOTIENT = MOD - 1 // assumes MOD is prime\n\ninfix fun Int.umod(mod: Int): Int = (this % mod).let { (it shr Int.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Long) = (this % mod).let { (it shr Long.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Int) = umod(mod.toLong()).toInt()\n\nfun Int.mulMod(other: Int, mod: Int) = toLong() * other umod mod\n\nfun Int.powMod(exponent: Int, mod: Int): Int {\n if(exponent < 0) error(\"Inverse not implemented\")\n var res = 1L\n var e = exponent\n var b = umod(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\n\ninline fun Int.toModInt() = ModInt(this umod MOD)\ninline fun Long.toModInt() = ModInt(this umod MOD)\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n companion object {\n /** can't seem to make these private or inlined without causing compiler issues */\n @JvmField val _invMemo = HashMap()\n fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }\n }\n\n // normalizes an integer that's within range [-MOD, MOD) without branching\n private inline fun normalize(int: Int) = ModInt((int shr Int.SIZE_BITS - 1 and MOD) + int)\n\n operator fun plus(other: ModInt) = normalize(int + other.int - MOD) // overflow-safe even if MOD >= 2^30\n inline operator fun plus(other: Int) = plus(other.toModInt())\n operator fun inc() = normalize(int + (1 - MOD))\n\n operator fun minus(other: ModInt) = normalize(int - other.int)\n inline operator fun minus(other: Int) = minus(other.toModInt())\n operator fun dec() = normalize(int - 1)\n operator fun unaryMinus() = normalize(-int)\n\n operator fun times(other: ModInt) = ModInt((int.toLong() * other.int % MOD).toInt())\n inline operator fun times(other: Int) = ModInt(int.mulMod(other, MOD))\n\n fun pow(exponent: Int): ModInt {\n val e = if(exponent < 0) {\n require(int != 0) { \"Can't invert/divide by 0\" }\n exponent umod TOTIENT\n } else exponent\n return ModInt(int.powMod(e, MOD))\n }\n\n fun pow(exponent: Long) = if(int == 0) when {\n exponent > 0 -> this\n exponent == 0L -> ModInt(1)\n else -> error(\"Can't invert/divide by 0\")\n } else pow(exponent umod TOTIENT)\n\n inline fun inverse() = inv_memoized() /** NOTE: Change if necessary */\n\n fun inv_unmemoized(): ModInt {\n require(int != 0) { \"Can't invert/divide by 0\" }\n return pow(TOTIENT - 1)\n }\n inline fun inv_memoized() = _invMemoized(this)\n\n operator fun div(other: ModInt) = times(other.inverse())\n inline operator fun div(other: Int) = div(other.toModInt())\n\n override inline fun toString() = int.toString()\n}\n\ninline operator fun Int.plus(modInt: ModInt) = modInt + this\ninline operator fun Int.minus(modInt: ModInt) = toModInt() - modInt\ninline operator fun Int.times(modInt: ModInt) = modInt * this\ninline operator fun Int.div(modInt: ModInt) = modInt.inverse() * this\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n inline operator fun get(i: Int) = ModInt(intArray[i])\n inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override inline val size: Int get() = intArray.size\n inline val lastIndex get() = intArray.lastIndex\n inline val indices get() = intArray.indices\n\n override inline fun contains(element: ModInt): Boolean = element.int in intArray\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override inline fun isEmpty(): Boolean = intArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): ModInt = get(index++)\n }\n\n fun copyOf(newSize: Int) = ModIntArray(intArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun ModIntArray.copyInto(destination: ModIntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =\n ModIntArray(intArray.copyInto(destination.intArray, destinationOffset, startIndex, endIndex))\ninline fun ModIntArray(size: Int) = ModIntArray(IntArray(size))\ninline fun ModIntArray(size: Int, init: (Int) -> ModInt) = ModIntArray(IntArray(size) { init(it).int })\n\nfun ModInt.powArray(n: Int): ModIntArray {\n val res = ModIntArray(n+1)\n res[0] = ModInt(1)\n for(i in 1..n) res[i] = res[i-1] * this\n return res\n}\n\ninline fun ModIntArray.first() = get(0)\ninline fun ModIntArray.last() = get(lastIndex)\ninline fun ModIntArray.fold(init: R, op: (acc: R, ModInt) -> R) = intArray.fold(init) { acc, i -> op(acc, ModInt(i)) }\nfun ModIntArray.sum() = fold(ModInt(0), ModInt::plus)\nfun ModIntArray.product() = fold(ModInt(1), ModInt::times)\n\ninline fun Iterable.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Iterable.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\ninline fun Sequence.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Sequence.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\nfun Iterable.sum() = sumByModInt { it }\nfun Sequence.sum() = sumByModInt { it }\nfun Iterable.product() = productByModInt { it }\nfun Sequence.product() = productByModInt { it }\nfun Collection.toModIntArray() = ModIntArray(size).also { var i = 0; for(e in this) { it[i++] = e } }\n\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _ln = \"\"\n@JvmField var _lnPtr = 0\nfun read(): String {\n while (_lnPtr >= _ln.length) {\n _ln = readLine() ?: return \"\"\n _lnPtr = 0\n }\n var j = _ln.indexOf(' ', _lnPtr)\n if(j < 0) j = _ln.length\n val res = _ln.substring(_lnPtr, j)\n _lnPtr = j + 1\n return res\n}\nfun readRem(): String /* reads remainder of current line */ =\n _ln.substring(min(_lnPtr, _ln.length)).also { _lnPtr = _ln.length }\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.lang.StringBuilder\nimport java.util.*\n\nclass ModInt(x: Long) {\n\n companion object {\n const val MOD = 998244353L\n }\n\n val x = (x % MOD + MOD) % MOD\n\n operator fun plus(other: ModInt): ModInt {\n return ModInt(x + other.x)\n }\n\n operator fun minus(other: ModInt): ModInt {\n return ModInt(x - other.x)\n }\n\n operator fun times(other: ModInt): ModInt {\n return ModInt(x * other.x)\n }\n\n operator fun div(other: ModInt): ModInt {\n return this * other.inv()\n }\n\n fun pow(exp: Long): ModInt {\n if (exp == 0L) return ModInt(1L)\n var a = pow(exp shr 1)\n a *= a\n if (exp and 1L == 0L) return a\n return this * a\n }\n\n fun inv(): ModInt {\n return this.pow(MOD - 2)\n }\n\n override fun equals(other: Any?): Boolean {\n if (this === other) return true\n if (javaClass != other?.javaClass) return false\n\n other as ModInt\n\n if (x != other.x) return false\n\n return true\n }\n\n override fun hashCode(): Int {\n return x.hashCode()\n }\n\n override fun toString(): String {\n return \"$x\"\n }\n\n}\n\nprivate fun fact(n: ModInt): ModInt {\n return (2..n.x).fold(ModInt(1L)) { acc, l -> acc * ModInt(l) }\n}\n\nprivate fun comb(n: ModInt, k: ModInt): ModInt {\n return fact(n) / fact(k) / fact(n - k)\n}\n\nprivate fun comb2(n: Long, k: Long): ModInt {\n var ans = ModInt(1)\n for (i in 0 until k) {\n ans = ans * ModInt(n - i) / ModInt(k - i)\n }\n return ans\n}\n\nfun calc_a(a:MutableMap, b:MutableMap, n:Long):ModInt {\n if (a.containsKey(n)) {\n return a[n]!!\n }\n val v = calc_a(a,b, n/2) * calc_a(a,b, n-n/2)+calc_b(a,b,n/2)*calc_b(a,b,n-n/2)\n a[n]=v\n return v\n}\n\nfun calc_b(a:MutableMap, b:MutableMap, n:Long):ModInt {\n if (b.containsKey(n)) {\n return b[n]!!\n }\n val v = calc_a(a,b, n/2) * calc_b(a,b, n-n/2)+calc_b(a,b,n/2)*calc_a(a,b,n-n/2)\n b[n]=v\n return v\n}\n\nfun PrintWriter.solve(sc: FastScanner) {\n val n = sc.nextLong()\n val m = sc.nextLong()\n val l = sc.nextLong()\n val r = sc.nextLong()\n if (n * m % 2 == 0L) {\n val even = r / 2 - (l - 1) / 2\n val a = mutableMapOf(0L to ModInt(1), 1L to ModInt(even))\n val b = mutableMapOf(0L to ModInt(0), 1L to ModInt(r - l + 1 - even))\n println(calc_a(a, b, n * m))\n } else {\n println(ModInt(r - l + 1).pow(m * n))\n }\n}\n\nfun main(args: Array) {\n val writer = PrintWriter(System.out, false)\n writer.solve(FastScanner(System.`in`))\n writer.flush()\n}\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}\n"}, {"source_code": "import java.io.PrintWriter\nimport java.math.BigInteger\nimport java.util.*\n\nprivate val M = 998244353L\nprivate val MB = M.toBigInteger()\nprivate val sc = Scanner( System.`in` )\nprivate val pw = PrintWriter( System.out )\n\nprivate fun solve(): Long {\n val n = sc.nextLong()\n val m = sc.nextLong()\n val l = sc.nextLong()\n val r = sc.nextLong()\n val totalCount = ( r - l + 1 ).toBigInteger().modPow( ( n * m ).toBigInteger(), MB ).toLong()\n if ( m * n % 2 == 1L ) return totalCount\n val inv2 = 2.toBigInteger().modInverse( MB ).toLong()\n return if ( l % 2 != r % 2 ) totalCount * inv2 % M else ( totalCount + 1 ) * inv2 % M\n}\n\nfun main() {\n pw.println( solve() )\n pw.close()\n}"}, {"source_code": "private const val MOD = 998_244_353\nfun main() {\n val (rows, cols, lower, upper) = System.`in`.bufferedReader().readLine().split(' ').map(String::toLong)\n val dif = upper - lower + 1\n val pow = (rows * cols)\n var ans = modPow(dif, pow)\n if (rows * cols and 1L == 0L) {\n if (dif and 1L == 1L) {\n ans++\n }\n if(ans and 1L == 1L){\n ans += MOD\n }\n ans = ans shr 1\n }\n print(ans%MOD)\n}\n\nprivate fun modPow(base: Long, pow: Long): Long {\n if (pow == 0L) {\n return 1L\n }\n var half = modPow(base, pow shr 1)\n half *= half\n half %= MOD\n if (pow and 1L == 1L) {\n half *= base\n half %= MOD\n }\n return half\n}"}, {"source_code": "//package c1332.e\n\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nconst val ACTUAL = 998244353L\n\ndata class MyLong(val num: Long) {\n operator fun times(x: Long): MyLong =\n MyLong(num * (x % REM) % REM)\n\n operator fun times(x: MyLong): MyLong =\n MyLong(num * x.num % REM)\n\n operator fun minus(x: MyLong): MyLong =\n MyLong((num - x.num + 2 * REM) % REM)\n\n operator fun plus(x: MyLong): MyLong =\n MyLong((num + x.num) % REM)\n\n override fun toString() = num.toString()\n\n fun pow(n: Long): MyLong {\n var res = 1.X\n var p = n\n var a = this\n while (p != 0L) {\n if (p.and(1) == 1L)\n res *= a\n a *= a\n p = p.shr(1)\n }\n return res\n }\n\n companion object {\n private const val REM = 2 * ACTUAL\n }\n}\n\nval Int.X get() = MyLong(toLong())\n\nfun solve(input: LongArray): Long {\n val (n, m, l, r) = input\n if (l == r)\n return 1L\n val result = MyLong(r - l + 1).pow(n * m)\n\n return if ((n * m) % 2 == 1L)\n result.num % ACTUAL\n else\n (result.num / 2 + (r - l + 1) % 2) % ACTUAL\n}\n\nfun main() {\n val reader = FastReader()\n println(solve(reader.nextLongArr(4)))\n}\n\n@Suppress(\"MemberVisibilityCanBePrivate\")\ninternal class FastReader {\n private val br = BufferedReader(InputStreamReader(System.`in`))\n private var tokenizer: StringTokenizer? = null\n\n operator fun next(): String {\n var t = tokenizer\n while (t == null || !t.hasMoreElements())\n t = StringTokenizer(br.readLine())\n tokenizer = t\n return t.nextToken()\n }\n\n fun nextInt() = next().toInt()\n\n fun nextLong(): Long = next().toLong()\n\n fun nextDouble(): Double = next().toDouble()\n\n fun nextLine(): String = br.readLine()\n\n fun nextIntArr(n: Int): IntArray = IntArray(n) { nextInt() }\n\n fun nextDoubleArr(n: Int): DoubleArray = DoubleArray(n) { nextDouble() }\n\n fun nextLongArr(n: Int): LongArray = LongArray(n) { nextLong() }\n\n fun nextIntArr2(n: Int, m: Int): Array = Array(n) { IntArray(m) { nextInt() } }\n\n fun nextLongArr2(n: Int, m: Int): Array = Array(n) { LongArray(m) { nextLong() } }\n}"}], "negative_code": [{"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\n\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n val n = readInt()\n val m = readInt()\n val nm = n.toLong() * m\n val l = readInt()\n val r = readInt()\n val sz = r-l+1\n\n val ans = run {\n if(nm and 1 == 1L) return@run nm.toModInt() * sz\n\n val fft = ModFFT(1)\n val A = ModIntArray(intArrayOf(sz / 2, (sz + 1) / 2))\n fft.inPlace(A, false)\n\n for (i in A.indices) A[i] = A[i].pow(nm)\n fft.inPlace(A, true)\n\n A[0]\n }\n println(ans)\n}\n\ninline val PRIMITIVE_ROOT get() = ModInt(3) // for 998244353\nclass ModFFT(maxDeg: Int) {\n val n = getArrSize(maxDeg)\n private val ninv = ModInt(n).inv_unmemoized()\n\n fun getArrSize(deg: Int) = Integer.highestOneBit(deg shl 1 or 1)\n // prepares an array of suitable size for inPlace\n fun prepare(arr: ModIntArray, deg: Int) = arr.copyOf(getArrSize(deg))\n\n // w[1] represents n-th root of unity e^(i * tau/n), w[k] = w[1]^k\n val w = PRIMITIVE_ROOT.pow(TOTIENT / n).powArray(n-1)\n\n // rev[i] is reversal of bits in i\n private val rev = IntArray(n).also { rev ->\n var bit = 1\n var rbit = n shr 1\n while(bit < n) {\n for(i in 0 until bit) {\n rev[i or bit] = rbit or rev[i]\n }\n bit = bit shl 1\n rbit = rbit shr 1\n }\n }\n\n operator fun invoke(a: ModIntArray, invert: Boolean): ModIntArray {\n val res = a.copyOf(n)\n inPlace(res, invert)\n return res\n }\n\n // in-place FFT. Precondition: a.size <= n, and a.size is a power of 2\n fun inPlace(a: ModIntArray, invert: Boolean) {\n val sz = a.size\n if(sz <= 1) return\n require(sz <= n && sz and -sz == sz) { \"Array size $sz must be less than $n and a power of 2\" }\n val st = n / sz\n for(i in 0 until sz) {\n val j = rev[i * st]\n if(i < j) a[i] = a[j].also { a[j] = a[i] }\n }\n\n var len = 2\n var ang = n shr 1 // = n / len, representing the angle tau / len\n if(invert) ang = -ang\n while(len <= sz) {\n var i = 0\n while(i < sz) {\n var k = 0\n for(j in i until i+len.shr(1)) {\n val u = a[j]\n val v = a[j+len.shr(1)] * w[k]\n a[j] = u + v\n a[j+len.shr(1)] = u - v\n k = k + ang and n-1\n }\n i += len\n }\n\n len = len shl 1\n ang = ang shr 1\n }\n\n if(invert) {\n val szinv = ninv * st\n for(i in 0 until sz) a[i] *= szinv\n }\n }\n\n fun mul(a: ModIntArray, b: ModIntArray): ModIntArray {\n val deg = a.lastIndex + b.lastIndex\n require(deg < n) { \"FFT capacity $n too small for polynomial of degree $deg\" }\n val a1 = prepare(a, deg)\n val b1 = prepare(b, deg)\n inPlace(a1, false)\n inPlace(b1, false)\n for(i in a1.indices) a1[i] *= b1[i]\n inPlace(a1, true)\n return a1//.copyOf(deg+1)\n }\n}\n\nconst val MOD = 998244353\nconst val TOTIENT = MOD - 1 // assumes MOD is prime\n\ninfix fun Int.umod(mod: Int): Int = (this % mod).let { (it shr Int.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Long) = (this % mod).let { (it shr Long.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Int) = umod(mod.toLong()).toInt()\n\nfun Int.mulMod(other: Int, mod: Int) = toLong() * other umod mod\n\nfun Int.powMod(exponent: Int, mod: Int): Int {\n if(exponent < 0) error(\"Inverse not implemented\")\n var res = 1L\n var e = exponent\n var b = umod(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\n\ninline fun Int.toModInt() = ModInt(this umod MOD)\ninline fun Long.toModInt() = ModInt(this umod MOD)\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n companion object {\n /** can't seem to make these private or inlined without causing compiler issues */\n @JvmField val _invMemo = HashMap()\n fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }\n }\n\n // normalizes an integer that's within range [-MOD, MOD) without branching\n private inline fun normalize(int: Int) = ModInt((int shr Int.SIZE_BITS - 1 and MOD) + int)\n\n operator fun plus(other: ModInt) = normalize(int + other.int - MOD) // overflow-safe even if MOD >= 2^30\n inline operator fun plus(other: Int) = plus(other.toModInt())\n operator fun inc() = normalize(int + (1 - MOD))\n\n operator fun minus(other: ModInt) = normalize(int - other.int)\n inline operator fun minus(other: Int) = minus(other.toModInt())\n operator fun dec() = normalize(int - 1)\n operator fun unaryMinus() = normalize(-int)\n\n operator fun times(other: ModInt) = ModInt((int.toLong() * other.int % MOD).toInt())\n inline operator fun times(other: Int) = ModInt(int.mulMod(other, MOD))\n\n fun pow(exponent: Int): ModInt {\n val e = if(exponent < 0) {\n require(int != 0) { \"Can't invert/divide by 0\" }\n exponent umod TOTIENT\n } else exponent\n return ModInt(int.powMod(e, MOD))\n }\n\n fun pow(exponent: Long) = if(int == 0) when {\n exponent > 0 -> this\n exponent == 0L -> ModInt(1)\n else -> error(\"Can't invert/divide by 0\")\n } else pow(exponent umod TOTIENT)\n\n inline fun inverse() = inv_memoized() /** NOTE: Change if necessary */\n\n fun inv_unmemoized(): ModInt {\n require(int != 0) { \"Can't invert/divide by 0\" }\n return pow(TOTIENT - 1)\n }\n inline fun inv_memoized() = _invMemoized(this)\n\n operator fun div(other: ModInt) = times(other.inverse())\n inline operator fun div(other: Int) = div(other.toModInt())\n\n override inline fun toString() = int.toString()\n}\n\ninline operator fun Int.plus(modInt: ModInt) = modInt + this\ninline operator fun Int.minus(modInt: ModInt) = toModInt() - modInt\ninline operator fun Int.times(modInt: ModInt) = modInt * this\ninline operator fun Int.div(modInt: ModInt) = modInt.inverse() * this\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n inline operator fun get(i: Int) = ModInt(intArray[i])\n inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override inline val size: Int get() = intArray.size\n inline val lastIndex get() = intArray.lastIndex\n inline val indices get() = intArray.indices\n\n override inline fun contains(element: ModInt): Boolean = element.int in intArray\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override inline fun isEmpty(): Boolean = intArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): ModInt = get(index++)\n }\n\n fun copyOf(newSize: Int) = ModIntArray(intArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun ModIntArray.copyInto(destination: ModIntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =\n ModIntArray(intArray.copyInto(destination.intArray, destinationOffset, startIndex, endIndex))\ninline fun ModIntArray(size: Int) = ModIntArray(IntArray(size))\ninline fun ModIntArray(size: Int, init: (Int) -> ModInt) = ModIntArray(IntArray(size) { init(it).int })\n\nfun ModInt.powArray(n: Int): ModIntArray {\n val res = ModIntArray(n+1)\n res[0] = ModInt(1)\n for(i in 1..n) res[i] = res[i-1] * this\n return res\n}\n\ninline fun ModIntArray.first() = get(0)\ninline fun ModIntArray.last() = get(lastIndex)\ninline fun ModIntArray.fold(init: R, op: (acc: R, ModInt) -> R) = intArray.fold(init) { acc, i -> op(acc, ModInt(i)) }\nfun ModIntArray.sum() = fold(ModInt(0), ModInt::plus)\nfun ModIntArray.product() = fold(ModInt(1), ModInt::times)\n\ninline fun Iterable.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Iterable.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\ninline fun Sequence.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Sequence.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\nfun Iterable.sum() = sumByModInt { it }\nfun Sequence.sum() = sumByModInt { it }\nfun Iterable.product() = productByModInt { it }\nfun Sequence.product() = productByModInt { it }\nfun Collection.toModIntArray() = ModIntArray(size).also { var i = 0; for(e in this) { it[i++] = e } }\n\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _ln = \"\"\n@JvmField var _lnPtr = 0\nfun read(): String {\n while (_lnPtr >= _ln.length) {\n _ln = readLine() ?: return \"\"\n _lnPtr = 0\n }\n var j = _ln.indexOf(' ', _lnPtr)\n if(j < 0) j = _ln.length\n val res = _ln.substring(_lnPtr, j)\n _lnPtr = j + 1\n return res\n}\nfun readRem(): String /* reads remainder of current line */ =\n _ln.substring(min(_lnPtr, _ln.length)).also { _lnPtr = _ln.length }\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\n\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n val n = readInt()\n val m = readInt()\n val nm = n.toLong() * m\n val l = readInt()\n val r = readInt()\n val sz = r-l+1\n\n val fft = ModFFT(1)\n val A = ModIntArray(intArrayOf(sz/2, (sz+1)/2))\n fft.inPlace(A, false)\n\n for(i in A.indices) A[i] = A[i].pow(nm)\n fft.inPlace(A, true)\n\n val ans = A[0]\n println(ans)\n}\n\ninline val PRIMITIVE_ROOT get() = ModInt(3) // for 998244353\nclass ModFFT(maxDeg: Int) {\n val n = getArrSize(maxDeg)\n private val ninv = ModInt(n).inv_unmemoized()\n\n fun getArrSize(deg: Int) = Integer.highestOneBit(deg shl 1 or 1)\n // prepares an array of suitable size for inPlace\n fun prepare(arr: ModIntArray, deg: Int) = arr.copyOf(getArrSize(deg))\n\n // w[1] represents n-th root of unity e^(i * tau/n), w[k] = w[1]^k\n val w = PRIMITIVE_ROOT.pow(TOTIENT / n).powArray(n-1)\n\n // rev[i] is reversal of bits in i\n private val rev = IntArray(n).also { rev ->\n var bit = 1\n var rbit = n shr 1\n while(bit < n) {\n for(i in 0 until bit) {\n rev[i or bit] = rbit or rev[i]\n }\n bit = bit shl 1\n rbit = rbit shr 1\n }\n }\n\n operator fun invoke(a: ModIntArray, invert: Boolean): ModIntArray {\n val res = a.copyOf(n)\n inPlace(res, invert)\n return res\n }\n\n // in-place FFT. Precondition: a.size <= n, and a.size is a power of 2\n fun inPlace(a: ModIntArray, invert: Boolean) {\n val sz = a.size\n if(sz <= 1) return\n require(sz <= n && sz and -sz == sz) { \"Array size $sz must be less than $n and a power of 2\" }\n val st = n / sz\n for(i in 0 until sz) {\n val j = rev[i * st]\n if(i < j) a[i] = a[j].also { a[j] = a[i] }\n }\n\n var len = 2\n var ang = n shr 1 // = n / len, representing the angle tau / len\n if(invert) ang = -ang\n while(len <= sz) {\n var i = 0\n while(i < sz) {\n var k = 0\n for(j in i until i+len.shr(1)) {\n val u = a[j]\n val v = a[j+len.shr(1)] * w[k]\n a[j] = u + v\n a[j+len.shr(1)] = u - v\n k = k + ang and n-1\n }\n i += len\n }\n\n len = len shl 1\n ang = ang shr 1\n }\n\n if(invert) {\n val szinv = ninv * st\n for(i in 0 until sz) a[i] *= szinv\n }\n }\n\n fun mul(a: ModIntArray, b: ModIntArray): ModIntArray {\n val deg = a.lastIndex + b.lastIndex\n require(deg < n) { \"FFT capacity $n too small for polynomial of degree $deg\" }\n val a1 = prepare(a, deg)\n val b1 = prepare(b, deg)\n inPlace(a1, false)\n inPlace(b1, false)\n for(i in a1.indices) a1[i] *= b1[i]\n inPlace(a1, true)\n return a1//.copyOf(deg+1)\n }\n}\n\nconst val MOD = 998244353\nconst val TOTIENT = MOD - 1 // assumes MOD is prime\n\ninfix fun Int.umod(mod: Int): Int = (this % mod).let { (it shr Int.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Long) = (this % mod).let { (it shr Long.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Int) = umod(mod.toLong()).toInt()\n\nfun Int.mulMod(other: Int, mod: Int) = toLong() * other umod mod\n\nfun Int.powMod(exponent: Int, mod: Int): Int {\n if(exponent < 0) error(\"Inverse not implemented\")\n var res = 1L\n var e = exponent\n var b = umod(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\n\ninline fun Int.toModInt() = ModInt(this umod MOD)\ninline fun Long.toModInt() = ModInt(this umod MOD)\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n companion object {\n /** can't seem to make these private or inlined without causing compiler issues */\n @JvmField val _invMemo = HashMap()\n fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }\n }\n\n // normalizes an integer that's within range [-MOD, MOD) without branching\n private inline fun normalize(int: Int) = ModInt((int shr Int.SIZE_BITS - 1 and MOD) + int)\n\n operator fun plus(other: ModInt) = normalize(int + other.int - MOD) // overflow-safe even if MOD >= 2^30\n inline operator fun plus(other: Int) = plus(other.toModInt())\n operator fun inc() = normalize(int + (1 - MOD))\n\n operator fun minus(other: ModInt) = normalize(int - other.int)\n inline operator fun minus(other: Int) = minus(other.toModInt())\n operator fun dec() = normalize(int - 1)\n operator fun unaryMinus() = normalize(-int)\n\n operator fun times(other: ModInt) = ModInt((int.toLong() * other.int % MOD).toInt())\n inline operator fun times(other: Int) = ModInt(int.mulMod(other, MOD))\n\n fun pow(exponent: Int): ModInt {\n val e = if(exponent < 0) {\n require(int != 0) { \"Can't invert/divide by 0\" }\n exponent umod TOTIENT\n } else exponent\n return ModInt(int.powMod(e, MOD))\n }\n\n fun pow(exponent: Long) = if(int == 0) when {\n exponent > 0 -> this\n exponent == 0L -> ModInt(1)\n else -> error(\"Can't invert/divide by 0\")\n } else pow(exponent umod TOTIENT)\n\n inline fun inverse() = inv_memoized() /** NOTE: Change if necessary */\n\n fun inv_unmemoized(): ModInt {\n require(int != 0) { \"Can't invert/divide by 0\" }\n return pow(TOTIENT - 1)\n }\n inline fun inv_memoized() = _invMemoized(this)\n\n operator fun div(other: ModInt) = times(other.inverse())\n inline operator fun div(other: Int) = div(other.toModInt())\n\n override inline fun toString() = int.toString()\n}\n\ninline operator fun Int.plus(modInt: ModInt) = modInt + this\ninline operator fun Int.minus(modInt: ModInt) = toModInt() - modInt\ninline operator fun Int.times(modInt: ModInt) = modInt * this\ninline operator fun Int.div(modInt: ModInt) = modInt.inverse() * this\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n inline operator fun get(i: Int) = ModInt(intArray[i])\n inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override inline val size: Int get() = intArray.size\n inline val lastIndex get() = intArray.lastIndex\n inline val indices get() = intArray.indices\n\n override inline fun contains(element: ModInt): Boolean = element.int in intArray\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override inline fun isEmpty(): Boolean = intArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): ModInt = get(index++)\n }\n\n fun copyOf(newSize: Int) = ModIntArray(intArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun ModIntArray.copyInto(destination: ModIntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =\n ModIntArray(intArray.copyInto(destination.intArray, destinationOffset, startIndex, endIndex))\ninline fun ModIntArray(size: Int) = ModIntArray(IntArray(size))\ninline fun ModIntArray(size: Int, init: (Int) -> ModInt) = ModIntArray(IntArray(size) { init(it).int })\n\nfun ModInt.powArray(n: Int): ModIntArray {\n val res = ModIntArray(n+1)\n res[0] = ModInt(1)\n for(i in 1..n) res[i] = res[i-1] * this\n return res\n}\n\ninline fun ModIntArray.first() = get(0)\ninline fun ModIntArray.last() = get(lastIndex)\ninline fun ModIntArray.fold(init: R, op: (acc: R, ModInt) -> R) = intArray.fold(init) { acc, i -> op(acc, ModInt(i)) }\nfun ModIntArray.sum() = fold(ModInt(0), ModInt::plus)\nfun ModIntArray.product() = fold(ModInt(1), ModInt::times)\n\ninline fun Iterable.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Iterable.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\ninline fun Sequence.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Sequence.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\nfun Iterable.sum() = sumByModInt { it }\nfun Sequence.sum() = sumByModInt { it }\nfun Iterable.product() = productByModInt { it }\nfun Sequence.product() = productByModInt { it }\nfun Collection.toModIntArray() = ModIntArray(size).also { var i = 0; for(e in this) { it[i++] = e } }\n\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _ln = \"\"\n@JvmField var _lnPtr = 0\nfun read(): String {\n while (_lnPtr >= _ln.length) {\n _ln = readLine() ?: return \"\"\n _lnPtr = 0\n }\n var j = _ln.indexOf(' ', _lnPtr)\n if(j < 0) j = _ln.length\n val res = _ln.substring(_lnPtr, j)\n _lnPtr = j + 1\n return res\n}\nfun readRem(): String /* reads remainder of current line */ =\n _ln.substring(min(_lnPtr, _ln.length)).also { _lnPtr = _ln.length }\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}"}, {"source_code": "\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\ndata class MyLong(val num: Long) {\n operator fun times(x: Long): MyLong =\n MyLong(num * (x % REM) % REM)\n\n operator fun minus(x: MyLong): MyLong =\n MyLong((num - x.num + 2 * REM) % REM)\n\n operator fun plus(x: MyLong): MyLong =\n MyLong((num + x.num) % REM)\n\n override fun toString() = num.toString()\n\n companion object {\n private const val REM = 998244353L\n }\n}\n\nval Int.X get() = MyLong(toLong())\n\nfun solve(input: LongArray): MyLong {\n val (n, m, l, r) = input\n if (l == r)\n return 1.X\n var result: MyLong = 1.X\n for (i in 1..n * m)\n result *= (r - l + 1)\n\n return if ((n * m) % 2 == 1L)\n result\n else\n result * 499122177L\n}\n\nfun main() {\n val reader = FastReader()\n println(solve(reader.nextLongArr(4)))\n}\n\n@Suppress(\"MemberVisibilityCanBePrivate\")\ninternal class FastReader {\n private val br = BufferedReader(InputStreamReader(System.`in`))\n private var tokenizer: StringTokenizer? = null\n\n operator fun next(): String {\n var t = tokenizer\n while (t == null || !t.hasMoreElements())\n t = StringTokenizer(br.readLine())\n tokenizer = t\n return t.nextToken()\n }\n\n fun nextInt() = next().toInt()\n\n fun nextLong(): Long = next().toLong()\n\n fun nextDouble(): Double = next().toDouble()\n\n fun nextLine(): String = br.readLine()\n\n fun nextIntArr(n: Int): IntArray = IntArray(n) { nextInt() }\n\n fun nextDoubleArr(n: Int): DoubleArray = DoubleArray(n) { nextDouble() }\n\n fun nextLongArr(n: Int): LongArray = LongArray(n) { nextLong() }\n\n fun nextIntArr2(n: Int, m: Int): Array = Array(n) { IntArray(m) { nextInt() } }\n\n fun nextLongArr2(n: Int, m: Int): Array = Array(n) { LongArray(m) { nextLong() } }\n}"}, {"source_code": "import java.util.*\nimport java.io.*\n\nval MOD = 998244353L\n\nfun main()\n{\n\tThread(null, Main(), \"whatever\", 1 shl 28).start()\n}\n\nclass Main : Runnable {\n\n\toverride fun run()\n\t{\n\t\tval inputStream = System.`in`\n\t\tval outputStream = System.out\n\t\tval `in` = InputReader(inputStream)\n\t\tval out = PrintWriter(outputStream)\n\t\tval solver = TaskD()\n\t\tvar test = 1\n\t\t//test = `in`.nextInt()\n\t\tfor (t in 1..test)\n\t\t{\n\t\t\tsolver.solve(t, `in`, out)\n\t\t}\n\t\tout.close()\n\t}\n\n\tinternal class TaskD\n\t{\n\t\tfun solve(testNumber: Int, `in`: InputReader, out: PrintWriter) {\n\t\t\tval INF = 4000000000000000000L\n\t\t\tval dx = intArrayOf(-1, 1, 0, 0)\n\t\t\tval dy = intArrayOf(0, 0, -1, 1)\n\n\t\t\tvar n = `in`.nextLong()\n\t\t\tvar m = `in`.nextLong()\n\t\t\tvar L = `in`.nextLong()\n\t\t\tvar R = `in`.nextLong()\n\t\t\tvar len = R-L+1\n\t\t\t\n\t\t\tif (n*m%2 == 1L) return out.println(power(len, n*m, MOD))\n\n\t\t\tvar a = len/2\n\t\t\tvar b = len-a\n\t\t\tif (L%2 == 0L)\n\t\t\t{\n\t\t\t\tvar tmp = a\n\t\t\t\ta = b\n\t\t\t\tb = tmp\n\t\t\t}\n\n\t\t\tfun go(a: Long, b: Long, n: Long): Pair\n\t\t\t{\n\t\t\t\tif (n == 0L) return Pair(1, 0)\n\t\t\t\tvar (c, d) = go(a, b, n/2)\n\t\t\t\tvar (tc, td) = Pair((c*c+d*d)%MOD, (2*c*d)%MOD)\n\t\t\t\tc = tc\n\t\t\t\td = td\n\t\t\t\tif (n%2 == 1L)\n\t\t\t\t{\n\t\t\t\t\tvar (sc, sd) = Pair(a*c+b*d, a*d+b*c)\n\t\t\t\t\tc = sc\n\t\t\t\t\td = sd\n\t\t\t\t}\n\t\t\t\treturn Pair(c, d)\n\t\t\t}\n\n\t\t\tvar (x, y) = go(a, b, n*m)\n\t\t\tout.println(x)\n\t\t}\n \n\t}\n\n\tinternal class InputReader(stream: InputStream) {\n\t\tvar reader: BufferedReader\n\t\tvar tokenizer: StringTokenizer? = null\n\n\t\tinit {\n\t\t\treader = BufferedReader(InputStreamReader(stream), 32768)\n\t\t\ttokenizer = null\n\t\t}\n\n\t\toperator fun next(): String {\n\t\t\twhile (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = StringTokenizer(reader.readLine())\n\t\t\t\t} catch (e: IOException) {\n\t\t\t\t\tthrow RuntimeException(e)\n\t\t\t\t}\n\n\t\t\t}\n\t\t\treturn tokenizer!!.nextToken()\n\t\t}\n\n\t\tfun nextInt(): Int {\n\t\t\treturn Integer.parseInt(next())\n\t\t}\n\n\t\tfun nextLong(): Long {\n\t\t return next().toLong()\n\t\t}\n\n\t}\n}\n\nfun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a%b)\n\nfun power(a: Long, b: Long, p: Long): Long\n{\n\tif (b == 0L) return 1L\n\tvar t = power(a, b/2, p)\n\tt = t*t%p\n\tif (b%2 == 1L) t = t*a%p\n\treturn t\n}\n"}], "src_uid": "ded299fa1cd010822c60f2389a3ba1a3"} {"nl": {"description": "Awruk is taking part in elections in his school. It is the final round. He has only one opponent — Elodreip. The are $$$n$$$ students in the school. Each student has exactly $$$k$$$ votes and is obligated to use all of them. So Awruk knows that if a person gives $$$a_i$$$ votes for Elodreip, than he will get exactly $$$k - a_i$$$ votes from this person. Of course $$$0 \\le k - a_i$$$ holds.Awruk knows that if he loses his life is over. He has been speaking a lot with his friends and now he knows $$$a_1, a_2, \\dots, a_n$$$ — how many votes for Elodreip each student wants to give. Now he wants to change the number $$$k$$$ to win the elections. Of course he knows that bigger $$$k$$$ means bigger chance that somebody may notice that he has changed something and then he will be disqualified.So, Awruk knows $$$a_1, a_2, \\dots, a_n$$$ — how many votes each student will give to his opponent. Help him select the smallest winning number $$$k$$$. In order to win, Awruk needs to get strictly more votes than Elodreip.", "input_spec": "The first line contains integer $$$n$$$ ($$$1 \\le n \\le 100$$$) — the number of students in the school. The second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 100$$$) — the number of votes each student gives to Elodreip.", "output_spec": "Output the smallest integer $$$k$$$ ($$$k \\ge \\max a_i$$$) which gives Awruk the victory. In order to win, Awruk needs to get strictly more votes than Elodreip.", "sample_inputs": ["5\n1 1 1 5 1", "5\n2 2 3 2 2"], "sample_outputs": ["5", "5"], "notes": "NoteIn the first example, Elodreip gets $$$1 + 1 + 1 + 5 + 1 = 9$$$ votes. The smallest possible $$$k$$$ is $$$5$$$ (it surely can't be less due to the fourth person), and it leads to $$$4 + 4 + 4 + 0 + 4 = 16$$$ votes for Awruk, which is enough to win.In the second example, Elodreip gets $$$11$$$ votes. If $$$k = 4$$$, Awruk gets $$$9$$$ votes and loses to Elodreip."}, "positive_code": [{"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val votes = Array(sc.nextInt()) { sc.nextInt() }\n print(A(votes).k)\n\n}\n\nclass A(val votes: Array) {\n val k: Int\n get() {\n val op = votes.sum()\n var res = votes.max()!!\n while (res * votes.size <= 2 * op) res += 1\n return res\n }\n}\n"}, {"source_code": "\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n val votes = readLine()!!.split(\" \").map { it.toInt() }\n val k = votes.max() ?: votes[0]\n val sumPierdole = votes.sum()\n val sumKurwa = votes.map { k - it }.sum()\n for (i in k..1000)\n if (sumPierdole < sumKurwa + (i-k)*n) {\n println(i)\n break\n }\n}"}, {"source_code": "\nfun main(args: Array) {\n\n val n = readLine()!!.toInt()\n\n val arr = readLine()!!.split(' ').map(String::toInt)\n\n var m = arr.max()!!\n\n var s1 = 0;\n var s2 = 0;\n\n arr.forEach { s1 += it }\n arr.forEach { s2 += (m!! - it) }\n\n\n while(s2 <= s1){\n s2 += arr.size\n m += 1;\n }\n\n print(m)\n}\n\nvar arr = arrayOfNulls(size = 1000)\n\nfun check(str: String , right: Int , left: Int): Boolean {\n val n = (left - right)\n\n for (i in 0..arr.size - 1) {\n arr[i] = 0;\n }\n\n\n for (i in left..right - 1) {\n val ch = str[i];\n arr[ch.toInt()] = arr[ch.toInt()]!! + 1;\n if (arr[ch.toInt()]!! > n / 2) {\n return false;\n }\n }\n\n return true;\n}"}, {"source_code": "import java.io.PrintWriter\nimport kotlin.math.*\n\nfun main() {\n io.apply {\n\n val n = int\n val d = ints(n)\n\n val mx = d.max()!!\n val sum = d.sum()\n val k0 = sum / n\n var ans =\n if ((sum % n) * 2 < n)\n k0 * 2 + 1\n else\n k0 * 2 + 2\n\n cout .. max(ans, mx) .. nl\n\n\n }.cout.flush()\n}\n\n// @formatter:off\nprivate val io = object {\n private val `in` = System.`in`\n private fun ll(): Long {\n var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }\n do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n\n }\n val int get() = ll().toInt(); val long get() = ll()\n fun ints(n: Int = int): IntArray { return IntArray(n) { int } }\n fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }\n val cout = PrintWriter(System.out); val nl = \"\\n\"\n private var buf = CharArray(32)\n private var bufSize = 32\n fun str(expect: Int = 32): String {\n var ix = 0\n var x: Int\n if (bufSize < expect)\n buf = CharArray(expect)\n do x = `in`.read() while (x < 33)\n do {\n if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }\n buf[ix++] = x.toChar()\n x = `in`.read()\n } while (x > 32)\n return java.lang.String.copyValueOf(buf, 0, ix)\n }\n operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(\" \") }; return this }\n operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }\n} // @formatter:on\n\n/* ----------- */\n\n"}, {"source_code": "import kotlin.math.max\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val numStudents = readInt()\n val votesAgaints = readInts()\n val totalVotesAgaints = votesAgaints.sum()\n var necessary = totalVotesAgaints + totalVotesAgaints + 1\n print(\n max(\n votesAgaints.max()!!,\n if (necessary % numStudents == 0) necessary / numStudents else necessary / numStudents + 1\n )\n )\n}"}, {"source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n var max = 0\n var e = 0\n var a= readLine()!!.split(\" \")\n for (i in a) {\n var v = i.toInt()\n e += v\n max = maxOf(v, max)\n }\n var al = max * n\n var my = al - e\n while (my <= e) {\n my += n\n max++\n }\n println(max)\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n\n var max = 0\n\n var enemyPoints = 0\n val splitted = readLine()!!.split(\" \")\n for (i in splitted) {\n val vote = i.toInt()\n enemyPoints += vote\n max = maxOf(vote, max)\n }\n\n\n var allPossiblePoints = max * n\n\n var myPoints = allPossiblePoints - enemyPoints\n\n while (myPoints <= enemyPoints) {\n myPoints += n\n max++\n }\n\n\n println(max)\n}"}], "negative_code": [{"source_code": "fun main(){\nvar n=readLine()!!.toInt()\n var a = readLine()!!.split(' ').map(String::toInt)\nvar c=0\nvar d=0\nfor(i in 0..n-1){\nif(a[i]>c) c=a[i]\nd+=a[i]\n}\nvar e=0\nvar f=e-d\nwhile(e<=c){\ne=0\nfor(i in 0..n-1){\ne+=(d-a[i])\n}\nif(e>c) break\nelse c++\n}\nprintln(c)\n}"}, {"source_code": "fun main(){\nvar n=readLine()!!.toInt()\n var a = readLine()!!.split(' ').map(String::toInt)\nvar c=0\nvar d=0\nfor(i in 0..n-1){\nif(a[i]>c) c=a[i]\nd+=a[i]\n}\nvar e=d*n\nvar f=e-d\nwhile(f<=d){\nf+=n\nc++\n}\nprintln(c)\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n\n var max = 0\n\n var enemyPoints = 0\n val splitted = readLine()!!.split(\" \")\n for (i in splitted) {\n val vote = i.toInt()\n enemyPoints += vote\n max = maxOf(vote, max)\n }\n\n\n var allPossiblePoints = max * n\n\n var myPoints = allPossiblePoints - enemyPoints\n\n while (myPoints < enemyPoints) {\n myPoints += n\n max++\n }\n\n\n println(max)\n}"}], "src_uid": "d215b3541d6d728ad01b166aae64faa2"} {"nl": {"description": "Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of $$$360$$$ degrees and a pointer which initially points at zero: Petr called his car dealer, who instructed him to rotate the lock's wheel exactly $$$n$$$ times. The $$$i$$$-th rotation should be $$$a_i$$$ degrees, either clockwise or counterclockwise, and after all $$$n$$$ rotations the pointer should again point at zero.This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all $$$n$$$ rotations the pointer will point at zero again.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\leq n \\leq 15$$$) — the number of rotations. Each of the following $$$n$$$ lines contains one integer $$$a_i$$$ ($$$1 \\leq a_i \\leq 180$$$) — the angle of the $$$i$$$-th rotation in degrees.", "output_spec": "If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word \"YES\". Otherwise, print \"NO\". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower).", "sample_inputs": ["3\n10\n20\n30", "3\n10\n10\n10", "3\n120\n120\n120"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteIn the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise.In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end.In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by $$$360$$$ degrees clockwise and the pointer will point at zero again."}, "positive_code": [{"source_code": "fun main() {\n //println((4 or 6)xor(4 or 5))\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n var v = mutableListOf(0)\n repeat(r.readLine()!!.toInt()) {\n val n = r.readLine()!!.toInt()\n val newList = mutableListOf()\n v.forEach {\n newList += it+n\n newList += it-n\n }\n v = newList\n }\n val ans = v.any { it%360==0 }\n println(if (ans) \"YES\" else \"NO\")\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\n\nfun BufferedReader.readIntList() = readLine().split(' ').map(String::toInt)\nfun BufferedReader.readLongList() = readLine().split(' ').map(String::toLong)\n\nclass Solution(private val inf: BufferedReader, private val ouf: PrintWriter) : Runnable {\n constructor() : this(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n\n fun solve() {\n val n = inf.readLine().toInt()\n val a = IntArray(n) {\n inf.readLine().toInt()\n }\n var ans = false\n for (i in 0 until (1 shl n)) {\n var sum = 0\n for (j in a.indices) {\n if ((i and (1 shl j)) == 0) sum += a[j] else sum -= a[j]\n }\n if ((sum % 360 + 360) % 360 == 0) ans = true\n }\n ouf.println(if (ans) \"YES\" else \"NO\")\n }\n\n override fun run() {\n// for (testNum in 1..inf.readLine().toInt()) {\n solve()\n// }\n\n ouf.close()\n }\n}\n\nfun main(args: Array) {\n Thread(null, Solution(), \"name\", 1 shl 27).start()\n}\n"}, {"source_code": "fun main() {\n val n = readInt()\n\n var possibilities = setOf(0)\n\n repeat(n) {\n val a = readInt()\n\n possibilities = sequence {\n for(p in possibilities) {\n yield((p + a) umod 360)\n yield((p - a) umod 360)\n }\n }.toSet()\n }\n\n if(0 in possibilities) println(\"YES\") else println(\"NO\")\n}\n\ninfix fun Int.umod(divisor: Int) =\n (this % divisor).let { if(it >= 0) it else it + divisor }\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }"}, {"source_code": "//package com.happypeople.codeforces.c1097\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\n\nfun main(args: Array) {\n try {\n B().run()\n } catch (e: Throwable) {\n B.log(\"\" + e)\n }\n}\n\nclass B {\n fun run() {\n val sc = Scanner(systemIn())\n val n=sc.nextInt()\n val a=(1..n).map { sc.nextInt() }\n\n val res=binsearch(a, 0, 0)\n if(res)\n println(\"YES\")\n else\n println(\"NO\")\n }\n\n fun binsearch(a:List, next:Int, sum:Int):Boolean {\n if(next==a.size)\n return sum%360==0\n else\n return binsearch(a, next+1, sum+a[next]) ||\n binsearch(a, next+1, sum-a[next])\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val nums = IntArray(n)\n for (i in 0 until n) {\n nums[i] = readLine()!!.toInt()\n }\n var res = mutableListOf()\n res.add(circle(nums[0]))\n res.add(circle(-nums[0]))\n for (i in 1 until n) {\n val lr = res.count()\n val nres = mutableListOf()\n for (j in 0 until lr) {\n nres.add(circle(res[j] + nums[i]))\n nres.add(circle(res[j] - nums[i]))\n }\n res = nres\n }\n if (res.contains(0)) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}\n\nfun circle(x: Int): Int {\n if (x < 0) {\n return 360 + x\n } else\n return x % 360\n}"}, {"source_code": "import java.io.*\nimport java.lang.Math.abs\nimport java.util.*\nimport javax.swing.plaf.nimbus.NimbusLookAndFeel\nimport kotlin.collections.HashSet\n\nfun solve(cin: FastReader, out: PrintWriter) {\n val n = cin.int()\n val a = IntArray(n) {cin.int()}\n\n for (i in 0 until (1 shl n)) {\n var sum = 0\n for (j in 0 until n)\n if (((1 shl j) and i) != 0)\n sum += a[j]\n else\n sum -= a[j]\n if (sum % 360 == 0) {\n out.print(\"YES\")\n return\n }\n }\n out.print(\"NO\")\n}\n\n\n\nclass FastReader(input: InputStream) {\n private val br = BufferedReader(InputStreamReader(input))\n private var st = StringTokenizer(\"\")\n\n fun next(): String {\n while (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun int(): Int {\n return next().toInt()\n }\n\n fun double(): Double {\n return next().toDouble()\n }\n\n fun long(): Long {\n return next().toLong()\n }\n\n /**\n * Warning! Use carefully!\n */\n fun nextLine(): String {\n return br.readLine()\n }\n}\n\nfun main(args: Array) {\n val cin = FastReader(System.`in`)\n val out = PrintWriter(BufferedOutputStream(System.out))\n\n solve(cin, out)\n\n out.flush()\n}"}, {"source_code": "import kotlin.math.*\n\nfun main(arg: Array){\n\tvar N = readLine()!!.toInt()\n\tval NN = N\n\tval M = 2.0.pow(N.toDouble()).toInt()\n\tval L = mutableListOf()\n\tvar S = 0\n\twhile(N > 0){\n\t\tL.add(readLine()!!.toInt())\n\t\tN--\n\t}\n\tL.forEach(){\n\t\tS += it\n\t}\n\tfor(i in 0..M-1){\n\t\tval opts = i.toString(2).padStart(NN,'0')\n\t\t//println(opts)\n\t\tvar Sum = 0\n\t\tfor (i in 1..opts.length){\n\t\t\tif(opts[i-1] == '0'){\n\t\t\t\tSum -= L[i-1]\n\t\t\t}else{\n\t\t\t\tSum += L[i-1]\n\t\t\t}\n\t\t}\n\t\tif(Sum.rem(360) == 0){\n\t\t\t//println(\"OGON: $opts $Sum\")\n\t\t\tprintln(\"YES\")\n\t\t\treturn\n\t\t}\n\n\t}\n\tprintln(\"NO\")\n}"}], "negative_code": [], "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10"} {"nl": {"description": "So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two \"New Year and Christmas Men\" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.Help the \"New Year and Christmas Men\" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.", "input_spec": "The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.", "output_spec": "Print \"YES\" without the quotes, if the letters in the pile could be permuted to make the names of the \"New Year and Christmas Men\". Otherwise, print \"NO\" without the quotes.", "sample_inputs": ["SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS", "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI", "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER"], "sample_outputs": ["YES", "NO", "NO"], "notes": "NoteIn the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.In the second sample letter \"P\" is missing from the pile and there's an extra letter \"L\".In the third sample there's an extra letter \"L\"."}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.ceil\nimport kotlin.math.floor\nimport kotlin.math.log2\nimport kotlin.math.sqrt\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n val arr = IntArray(26)\n for (i in scanner.next())\n arr[i - 'A']++\n for (i in scanner.next())\n arr[i - 'A']++\n for (i in scanner.next())\n arr[i- 'A']--\n for (i in arr) {\n if (i != 0) {\n println(\"NO\")\n return\n }\n }\n println(\"YES\")\n\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\n//class Pair(var a: Int, var b: Int): Comparable {\n// override fun compareTo(other: Pair): Int {\n// return b - a - other.b + other.a\n// }\n//}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n var tok = StringTokenizer(\"\")\n\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n fun files(inputFilename: String, outputFilename: String) =\n ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))\n }\n\n fun readToken(): String {\n while (!tok.hasMoreTokens()) {\n tok = StringTokenizer(rd.readLine())\n }\n return tok.nextToken()\n }\n\n fun readInt(): Int = readToken().toInt()\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun close() {\n rd.close()\n wr.close()\n }\n}\n\nfun solve() {\n val io = ProblemIO.console()\n val a = io.readToken()\n val b = io.readToken()\n val c = io.readToken()\n val s1 = (a + b).toCharArray().sortedArray()\n val s2 = c.toCharArray().sortedArray()\n val res = Arrays.equals(s1, s2)\n io.println(if (res) \"YES\" else \"NO\")\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n"}, {"source_code": "fun main()\n{\n val one = (readLine()!! + readLine()!!).asSequence().sorted().joinToString(\"\")\n\n val both = readLine()!!.asSequence().sorted().joinToString(\"\")\n println(if (one == both ) \"YES\" else \"NO\")\n}\n\n"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val s1 = r.readLine()!!\n val s2 = r.readLine()!!\n val s3 = r.readLine()!!\n val c1 = mutableListOf()\n s1.forEach { c1 += it }\n s2.forEach { c1 += it }\n val c2 = mutableListOf()\n s3.forEach { c2 += it }\n if (c1.size!=c2.size){\n println(\"NO\")\n }else{\n var can = true\n c1.sort()\n c2.sort()\n (0..c1.size-1).forEach { if (c1[it]!=c2[it]) can = false }\n println(if (can) \"YES\" else \"NO\")\n }\n}"}, {"source_code": "import java.util.*\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n\n val s1 = (input.next() + input.next()).toCharArray()\n val s2 = input.next().toCharArray()\n\n Arrays.sort(s1)\n Arrays.sort(s2)\n\n if (Arrays.equals(s1, s2))\n println(\"YES\") \n else \n print(\"NO\")\n\n }"}, {"source_code": "import java.io.*\nimport java.math.BigDecimal\nimport java.math.BigInteger\nimport java.util.*\nimport kotlin.collections.HashSet\n\n\nobject programkt {\n interface Scanner {\n fun changeInputStream(inputStream: InputStream)\n fun nextInt(): Int\n fun nextLong(): Long\n fun nextDouble(): Double\n fun nextChar(): Char\n fun nextString(): String\n fun nextLine(): String\n fun nextBigInteger(): BigInteger\n fun nextBigDecimal(): BigDecimal\n }\n\n abstract class Task {\n //KT Extensions\n fun > min(a: T, b: T) = if (a > b) b else a\n fun > max(a: T, b: T) = if (a < b) b else a\n fun abs(a: Int) = if (a > 0) a else -(a)\n fun abs(a: Long) = if (a > 0) a else -(a)\n fun abs(a: Float) = if (a > 0) a else -(a)\n fun abs(a: Double) = if (a > 0) a else -(a)\n operator fun Iterable.invoke(function: (it: T) -> Unit) { this.forEach(function) }\n private fun String.prefix(pi: Array): Array {\n pi[0] = 0\n (1 until this.length) {\n var j = pi[it - 1]\n while (j > 0 && this[it] != this[j]) {\n j = pi[j - 1]\n }\n if(this[it] == this[j]) {\n j++\n }\n pi[it] = j\n }\n return pi\n }\n private fun String.kmpFind(pattern: String): Int {\n val m = pattern.length\n val dfa = Array(256) { IntArray(m) }\n dfa[pattern[0].toInt()][0] = 1\n var x = 0\n var j = 1\n while (j < m) {\n for (c in 0 until 256) {\n dfa[c][j] = dfa[c][x] // Copy mismatch cases.\n }\n dfa[pattern[j].toInt()][j] = j + 1 // Set match case.\n x = dfa[pattern[j].toInt()][x] // Update restart state.\n j++\n }\n\n val n = this.length\n var i: Int = 0\n j = 0\n while (i < n && j < m) {\n j = dfa[this[i].toInt()][j]\n i++\n }\n if (j == m) return i - m // found\n return n // not found\n }\n fun fuckExceptions(invoker: () -> Unit) = try { invoker.invoke() } catch (_: Throwable) {}\n\n enum class EdgeType {\n DIRECTED,\n UNDIRECTED\n }\n data class Vertex>(\n val data: T\n ) {\n override fun toString(): String = \"V:$data\"\n }\n data class Edge>(\n var source: Vertex,\n var destination: Vertex,\n val weight: Double?\n )\n interface Graphable> {\n fun createVertex(data: T): Vertex\n fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double? = 0.0)\n fun weight(source: Vertex, destination: Vertex): Double?\n fun edges(source: Vertex): MutableList>?\n }\n class AdjacencyList>: Graphable {\n var adjacencyMap: MutableMap, MutableList>> = mutableMapOf()\n\n private fun addDirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n adjacencyMap[source]?.add(Edge(source = source, destination = destination, weight = weight))\n }\n\n private fun addUndirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n addDirectedEdge(source, destination, weight)\n addDirectedEdge(destination, source, weight)\n }\n\n override fun createVertex(data: T): Vertex {\n val vertex = Vertex(data = data)\n adjacencyMap[vertex] ?: run {\n adjacencyMap[vertex] = mutableListOf()\n }\n return vertex\n }\n\n override fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double?) = when(type) {\n EdgeType.DIRECTED -> addDirectedEdge(source, destination, weight)\n EdgeType.UNDIRECTED -> addUndirectedEdge(source, destination, weight)\n }\n\n override fun weight(source: Vertex, destination: Vertex): Double? {\n adjacencyMap[source]?.forEach {\n if(it.destination == destination) return it.weight\n }\n return null\n }\n\n override fun edges(source: Vertex): MutableList>? = adjacencyMap[source]\n\n override fun toString(): String {\n var result = \"\"\n for ((vertex, edges) in adjacencyMap) {\n var edgeString = \"\"\n for ((index, edge) in edges.withIndex()) {\n edgeString += if (index != edges.count() - 1) \"${edge.destination}, \"\n else \"${edge.destination}\"\n }\n result += \"$vertex ---> [ $edgeString ] \\n\"\n }\n return result\n }\n\n fun depthFirstSearch(start: Vertex, end: Vertex): Stack> {\n val visited: HashSet> = hashSetOf()\n val stack: Stack> = Stack()\n stack.push(start)\n visited.add(start)\n\n var currentVertex = stack.peek()\n loop@while (currentVertex != null && currentVertex != end) {\n val neighbors = edges(currentVertex)\n if(neighbors != null && neighbors.count() > 0) {\n for(edge in neighbors) {\n if(!visited.contains(edge.destination)) {\n visited.add(edge.destination)\n stack.push(edge.destination)\n currentVertex = stack.peek()\n continue@loop\n }\n }\n } else {\n stack.pop()\n currentVertex = stack.peek()\n continue\n }\n\n stack.pop()\n currentVertex = stack.peek()\n }\n\n return stack\n }\n\n fun breadthFirstSearch() {\n\n }\n }\n //End KT Extensions\n\n abstract fun solve(scanner: Scanner, printer: PrintWriter)\n }\n\n class FastScanner: Scanner {\n var inputStream: InputStream? = null\n override fun changeInputStream(inputStream: InputStream) {\n this.inputStream = inputStream\n this.bufferedReader = BufferedReader(InputStreamReader(inputStream))\n }\n\n private lateinit var bufferedReader: BufferedReader\n private var stringTokenizer: StringTokenizer? = null\n\n private fun nextToken(): String? {\n while (stringTokenizer == null || !stringTokenizer!!.hasMoreTokens())\n stringTokenizer = StringTokenizer(bufferedReader.readLine() ?: return null)\n return stringTokenizer!!.nextToken()\n }\n\n override fun nextInt() = nextToken()!!.toInt()\n override fun nextLong() = nextToken()!!.toLong()\n override fun nextDouble() = nextToken()!!.toDouble()\n override fun nextChar() = bufferedReader.read().toChar()\n override fun nextString() = nextToken()!!\n override fun nextLine() = bufferedReader.readLine()!!\n override fun nextBigInteger() = BigInteger(nextToken()!!)\n override fun nextBigDecimal() = BigDecimal(nextToken()!!)\n }\n\n class TaskBuilder {\n private var task: Task? = null\n private var inputStream: InputStream? = null\n private var outputStream: OutputStream? = null\n private var scanner: Scanner? = null\n\n fun useInputSource(inputStream: InputStream): TaskBuilder {\n this.inputStream = inputStream\n return this\n }\n\n fun useOutputSource(outputStream: OutputStream): TaskBuilder {\n this.outputStream = outputStream\n return this\n }\n\n fun useInputFile(inputFileName: String): TaskBuilder {\n this.inputStream = FileInputStream(File(inputFileName))\n return this\n }\n\n fun useOutputFile(outputFileName: String): TaskBuilder {\n this.outputStream = FileOutputStream(File(outputFileName))\n return this\n }\n\n fun useScanner(scanner: Scanner): TaskBuilder {\n this.scanner = scanner\n return this\n }\n\n\n fun solveTask(task: Task): TaskBuilder {\n this.task = task\n return this\n }\n\n fun run() {\n when {\n task == null -> throw NullPointerException(\"Task cannot be null!\")\n inputStream == null -> throw NullPointerException(\"Input cannot be null!\")\n outputStream == null -> throw NullPointerException(\"Output cannot be null!\")\n scanner == null -> throw NullPointerException(\"Scanner cannot be null!\")\n }\n scanner!!.changeInputStream(inputStream!!)\n val printer = PrintWriter(outputStream)\n TaskRunnable(task!!, scanner!!, printer).run()\n\n inputStream!!.close()\n printer.close()\n }\n\n class TaskRunnable(\n private val task: Task,\n private val scanner: Scanner,\n private val printer: PrintWriter\n ) {\n fun run() {\n task.solve(scanner, printer)\n }\n }\n }\n\n @JvmStatic\n fun main(args: Array) = TaskBuilder()\n .useInputSource(System.`in`)\n .useOutputSource(System.out)\n .useScanner(FastScanner())\n .solveTask(TaskB())\n .run()\n\n class TaskA: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val countOfRooms = scanner.nextInt()\n val rooms = Array(countOfRooms) { scanner.nextInt() to scanner.nextInt() }\n printer.println(rooms\n .map { it.second - it.first }\n .filter { it >= 2 }\n .count())\n }\n\n }\n\n class TaskB: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val firstName = scanner.nextLine()\n val secondName = scanner.nextLine()\n val mixedUpName = scanner.nextLine()\n\n val alphabet = Array(26) { 0 }\n val mixedUpAlphabet = Array(26) { 0 }\n\n firstName.forEach { alphabet[it - 'A']++ }\n secondName.forEach { alphabet[it - 'A']++ }\n mixedUpName.forEach { mixedUpAlphabet[it - 'A']++ }\n\n for (it in 0..25) {\n if (alphabet[it] != mixedUpAlphabet[it]) {\n printer.println(\"NO\")\n return\n }\n\n }\n printer.println(\"YES\")\n }\n\n }\n}\n"}, {"source_code": "fun main() {\n val firstLine = readLine()!!.map { it.toString() }\n val secLine = readLine()!!.map { it.toString() }\n val thirdLine = readLine()!!.map { it.toString() }\n\n val result = firstLine + secLine\n\n if (thirdLine.sorted() == result.sorted()) {\n print(\"YES\")\n } else {\n print(\"NO\")\n }\n}"}, {"source_code": "import java.util.*\n\nfun String.freqs(): HashMap {\n val map = hashMapOf()\n forEach { c ->\n if (map.containsKey(c)) map[c] = map[c]!! + 1\n else map[c] = 1\n }\n return map\n}\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val name1 = sc.nextLine()\n val name2 = sc.nextLine()\n val letters = sc.nextLine()\n val map1 = name1.freqs()\n val map2 = name2.freqs()\n val map3 = letters.freqs()\n\n var ok = true\n map1.forEach { k, v ->\n if (map3.containsKey(k) && map3[k]!! - v >= 0) map3[k] = map3[k]!! - v\n else ok = false\n return@forEach\n }\n if (ok)\n map2.forEach { k, v ->\n if (map3.containsKey(k) && map3[k]!! - v >= 0) map3[k] = map3[k]!! - v\n else ok = false\n return@forEach\n }\n\n ok = ok && map3.values.sum() == 0\n\n if (ok)\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "\nimport java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)){\n val guests = nextLine()!!\n val hosts = nextLine()!!\n\n val shuffled = nextLine()!!\n\n if (shuffled.length != hosts.length + guests.length){\n println(\"NO\")\n return\n }\n\n val guestsAr = guests.toCharArray()\n val hostsAr = hosts.toCharArray()\n val shuffledAr = shuffled.toCharArray()\n \n val gHelper = IntArray(guests.length){0}\n val hHelper = IntArray(hosts.length){0}\n\n for (target in shuffledAr){\n var found = false\n for (i in 0..guestsAr.size - 1){\n if (guestsAr[i] == target && gHelper[i] ==0) {\n found = true\n gHelper[i] = 1\n break\n }\n }\n\n if(found){\n continue\n }\n \n for (i in 0..hostsAr.size - 1){\n if (hostsAr[i] == target && hHelper[i] ==0) {\n found = true\n hHelper[i] = 1\n break\n }\n }\n if(!found){\n println(\"NO\")\n return\n }\n }\n println(\"YES\")\n}"}, {"source_code": "import java.io.*\nimport java.lang.StringBuilder\nimport java.util.*\n\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val input = InputReader(inputStream)\n val output = PrintWriter(outputStream)\n val solver = Task()\n solver.solve(input, output)\n output.close()\n}\n\nprivate class Task {\n fun solve(input: InputReader, output: PrintWriter) {\n output.println(if (StringBuilder(input.next()).append(input.next()).toList().sorted() == input.next().toList().sorted()) \"YES\" else \"NO\")\n }\n}\n\n\nprivate class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n\n operator fun next(): String {\n while (tokenizer == null || tokenizer?.hasMoreTokens()?.not() == true) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return next().toInt()\n }\n\n}"}, {"source_code": "\nfun main(){\n var arrChar = readLine()!!.toCharArray().toMutableList()\n arrChar.addAll(readLine()!!.toCharArray().toMutableList())\n arrChar.sort()\n var str = readLine()!!.toCharArray().toMutableList()\n str.sort()\n println(if (arrChar.equals(str)) \"YES\" else \"NO\")\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val guest = sc.next()\n val host = sc.next()\n val mixed = sc.next().toCharArray().sorted()\n val sm = (guest + host).toCharArray().sorted()\n\n if (mixed == sm) {\n print(\"YES\")\n } else print(\"NO\")\n\n\n}"}, {"source_code": "fun main(args: Array) {\n val name = readLine()!! + readLine()!!\n val let = readLine()!!\n\n val countChars = name.groupingBy { it }.eachCount()\n val countLet = let.groupingBy { it }.eachCount()\n \n println(if (countChars == countLet) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main(args: Array) {\n val name1 = readLine()!!\n val name2 = readLine()!!\n val mix = readLine()!!\n if ((name1 + name2).toCharArray().also { it.sort() }.contentEquals(mix.toCharArray().also { it.sort() }))\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "import java.util.*\n\nfun main(){\n\n val scan = Scanner(System.`in`)\n var arr = Array(26){ _ -> 0}\n var line = scan.next() + scan.next()\n\n\n for (i in line){\n arr[i.toInt()-65]++\n }\n\n for (i in scan.next()){\n arr[i.toInt()-65]--\n }\n\n var a = true\n for (i in arr) if (i != 0){\n a = false\n break\n }\n\n if (a) print(\"YES\")\n else print(\"NO\")\n\n}"}, {"source_code": "fun main() {\n val a = (readLine()!! + readLine()!!).asSequence().sorted().joinToString(\"\")\n val b = readLine()!!.asSequence().sorted().joinToString(\"\")\n println(if (a == b) \"YES\" else \"NO\")\n}"}, {"source_code": "import kotlin.system.exitProcess\n\nfun main() {\n var arr = IntArray(26)\n for(i in 1..2) {\n readLine()!!.toCharArray().let {\n for(x in it) {\n arr[x - 'A']++\n }\n }\n }\n readLine()!!.toCharArray().let {\n for(x in it) {\n arr[x - 'A']--\n }\n }\n for(x in arr) {\n if(x != 0) {\n println(\"NO\")\n exitProcess(0)\n }\n }\n println(\"YES\")\n}"}, {"source_code": "fun main(args: Array) {\n val was = (readLine()!! + readLine()!!).toCharArray().apply {sort()}\n val become = readLine()!!.toCharArray().apply {sort()}\n\n println(if (was.contentEquals(become)) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main(args: Array) {\n val was = (readLine()!! + readLine()!!).toCharArray().sorted()\n val become = readLine()!!.toCharArray().sorted()\n\n println(if (was == become) \"YES\" else \"NO\")\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n\nfun main() {\n val a = readLn()\n val b = readLn()\n val c = readLn()\n\n val aUb = (a+b).groupingBy { it }.eachCount()\n val cU = c.groupingBy { it }.eachCount()\n\n if (aUb == cU) println(\"YES\") else println(\"NO\")\n}\n"}, {"source_code": "fun main(args: Array) {\n val s = (readLine()!! + readLine()!!).toCharArray().sorted().joinToString(\"\")\n val line = readLine()!!.toCharArray().sorted().joinToString(\"\")\n println(if (s == line) \"YES\" else \"NO\")\n}"}, {"source_code": "import java.util.*\n\nfun min(a:Double,b:Double) = if (ab) a else b\nfun min(a:Long,b:Long) = if (ab) a else b\n\nfun readLn():String = readLine()!!.toString()\nfun readLong() = readLn().toLong()\nfun readLongs() = readLn().split(\" \").map{it.toLong()}\nvar nul=0.toLong();\nvar one=1.toLong();\nvar two=2.toLong();\nvar three=3.toLong();\nvar four=4.toLong();\nvar five=5.toLong();\nfun powmod(a:Long,b:Long,mod:Long):Long {\n\n if (b==1.toLong()) return a;\n var k=powmod(a,b/2,mod);\n if (b%2==0.toLong())\n { return (k*k)%mod }\n else { k=k*k; k=k%mod; k=k*a; k=k%mod; return k; }\n}\nfun prime (p:Long):Long {\n if (p==one) return 0.toLong();\n var i=two;\n while (i*i<=p) {if (p%i==nul) return i; i++; }\n return one;\n}\nfun inv (a:Long,mod:Long):Long {\nreturn powmod(a,mod-2,mod);\n}\n\nfun solve() {\n val cin = Scanner(System.`in`)\n\n /*\n var map=hashMapOf();\n map[q] <=> map.getOrDefault(q,0)\n Сортировка вектора пар - k=v.sortedWith(compareBy({it.first},{it.second}));\n prLong(\"${k[i].second}\"); - вывод аргумента пары\n var m=ArrayList (); <=> vector\n getline(cin,a) <=> readLine()!!.last()\n readLong() - одно число\n readLongs() - несколько чисел\n readLine()!!.toCharArray() - возвращает массив чаров из строки\n\n */\n /* --------- */\n // ВСЕГДА ПИСАТЬ В ЛОНГАХ\n\n var a=readLine()!!.toString();\n var b=readLine()!!.toString();\n var c=readLine()!!.toString();\n\n var qq=LongArray(26);\n\n for (i in 0..a.length-1) {\n qq[a[i]-'A']++;\n }\n for (i in 0..b.length-1) {\n qq[b[i]-'A']++;\n }\n for (i in 0..c.length-1) {\n qq[c[i]-'A']--;\n }\n var check=one;\n for (i in 0..25) if (qq[i]>nul || qq[i]) {\n var first = readLine()!!.toString()\n var second = readLine()!!.toString()\n var all = readLine()!!.toString()\n\n if (first.length + second.length != all.length){\n println(\"NO\")\n return\n }\n\n var t1 = (first + second).toCharArray().sortedArray()\n var t2 = all.toCharArray().sortedArray()\n\n for (i in 0..all.length-1) {\n if (t1[i] != t2[i]){\n println(\"NO\")\n return\n }\n }\n println(\"YES\")\n return\n}"}], "negative_code": [{"source_code": "fun main(args: Array) {\n var s = readLine()!!\n var S = readLine()!!\n var W = readLine()!!\n var c = 0\n var C = 0\n var j = 0\n for (i in 0 until W.count()) {\n if (s[j] == W[i]) {\n c++\n j++\n }\n }\n j = 0\n for (i in 0 until W.count()) {\n if (S[j] == W[i]) {\n C++\n j++\n }\n }\n if ((c == s.length) || (C == S.length)) {\n print(\"YES\")\n } else {\n print(\"NO\")\n }\n}"}, {"source_code": "import java.io.*\nimport java.math.BigDecimal\nimport java.math.BigInteger\nimport java.util.*\nimport kotlin.collections.HashSet\n\n\nobject programkt {\n interface Scanner {\n fun changeInputStream(inputStream: InputStream)\n fun nextInt(): Int\n fun nextLong(): Long\n fun nextDouble(): Double\n fun nextChar(): Char\n fun nextString(): String\n fun nextLine(): String\n fun nextBigInteger(): BigInteger\n fun nextBigDecimal(): BigDecimal\n }\n\n abstract class Task {\n //KT Extensions\n fun > min(a: T, b: T) = if (a > b) b else a\n fun > max(a: T, b: T) = if (a < b) b else a\n fun abs(a: Int) = if (a > 0) a else -(a)\n fun abs(a: Long) = if (a > 0) a else -(a)\n fun abs(a: Float) = if (a > 0) a else -(a)\n fun abs(a: Double) = if (a > 0) a else -(a)\n operator fun Iterable.invoke(function: (it: T) -> Unit) { this.forEach(function) }\n private fun String.prefix(pi: Array): Array {\n pi[0] = 0\n (1 until this.length) {\n var j = pi[it - 1]\n while (j > 0 && this[it] != this[j]) {\n j = pi[j - 1]\n }\n if(this[it] == this[j]) {\n j++\n }\n pi[it] = j\n }\n return pi\n }\n private fun String.kmpFind(pattern: String): Int {\n val m = pattern.length\n val dfa = Array(256) { IntArray(m) }\n dfa[pattern[0].toInt()][0] = 1\n var x = 0\n var j = 1\n while (j < m) {\n for (c in 0 until 256) {\n dfa[c][j] = dfa[c][x] // Copy mismatch cases.\n }\n dfa[pattern[j].toInt()][j] = j + 1 // Set match case.\n x = dfa[pattern[j].toInt()][x] // Update restart state.\n j++\n }\n\n val n = this.length\n var i: Int = 0\n j = 0\n while (i < n && j < m) {\n j = dfa[this[i].toInt()][j]\n i++\n }\n if (j == m) return i - m // found\n return n // not found\n }\n fun fuckExceptions(invoker: () -> Unit) = try { invoker.invoke() } catch (_: Throwable) {}\n\n enum class EdgeType {\n DIRECTED,\n UNDIRECTED\n }\n data class Vertex>(\n val data: T\n ) {\n override fun toString(): String = \"V:$data\"\n }\n data class Edge>(\n var source: Vertex,\n var destination: Vertex,\n val weight: Double?\n )\n interface Graphable> {\n fun createVertex(data: T): Vertex\n fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double? = 0.0)\n fun weight(source: Vertex, destination: Vertex): Double?\n fun edges(source: Vertex): MutableList>?\n }\n class AdjacencyList>: Graphable {\n var adjacencyMap: MutableMap, MutableList>> = mutableMapOf()\n\n private fun addDirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n adjacencyMap[source]?.add(Edge(source = source, destination = destination, weight = weight))\n }\n\n private fun addUndirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n addDirectedEdge(source, destination, weight)\n addDirectedEdge(destination, source, weight)\n }\n\n override fun createVertex(data: T): Vertex {\n val vertex = Vertex(data = data)\n adjacencyMap[vertex] ?: run {\n adjacencyMap[vertex] = mutableListOf()\n }\n return vertex\n }\n\n override fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double?) = when(type) {\n EdgeType.DIRECTED -> addDirectedEdge(source, destination, weight)\n EdgeType.UNDIRECTED -> addUndirectedEdge(source, destination, weight)\n }\n\n override fun weight(source: Vertex, destination: Vertex): Double? {\n adjacencyMap[source]?.forEach {\n if(it.destination == destination) return it.weight\n }\n return null\n }\n\n override fun edges(source: Vertex): MutableList>? = adjacencyMap[source]\n\n override fun toString(): String {\n var result = \"\"\n for ((vertex, edges) in adjacencyMap) {\n var edgeString = \"\"\n for ((index, edge) in edges.withIndex()) {\n edgeString += if (index != edges.count() - 1) \"${edge.destination}, \"\n else \"${edge.destination}\"\n }\n result += \"$vertex ---> [ $edgeString ] \\n\"\n }\n return result\n }\n\n fun depthFirstSearch(start: Vertex, end: Vertex): Stack> {\n val visited: HashSet> = hashSetOf()\n val stack: Stack> = Stack()\n stack.push(start)\n visited.add(start)\n\n var currentVertex = stack.peek()\n loop@while (currentVertex != null && currentVertex != end) {\n val neighbors = edges(currentVertex)\n if(neighbors != null && neighbors.count() > 0) {\n for(edge in neighbors) {\n if(!visited.contains(edge.destination)) {\n visited.add(edge.destination)\n stack.push(edge.destination)\n currentVertex = stack.peek()\n continue@loop\n }\n }\n } else {\n stack.pop()\n currentVertex = stack.peek()\n continue\n }\n\n stack.pop()\n currentVertex = stack.peek()\n }\n\n return stack\n }\n\n fun breadthFirstSearch() {\n\n }\n }\n //End KT Extensions\n\n abstract fun solve(scanner: Scanner, printer: PrintWriter)\n }\n\n class FastScanner: Scanner {\n var inputStream: InputStream? = null\n override fun changeInputStream(inputStream: InputStream) {\n this.inputStream = inputStream\n this.bufferedReader = BufferedReader(InputStreamReader(inputStream))\n }\n\n private lateinit var bufferedReader: BufferedReader\n private var stringTokenizer: StringTokenizer? = null\n\n private fun nextToken(): String? {\n while (stringTokenizer == null || !stringTokenizer!!.hasMoreTokens())\n stringTokenizer = StringTokenizer(bufferedReader.readLine() ?: return null)\n return stringTokenizer!!.nextToken()\n }\n\n override fun nextInt() = nextToken()!!.toInt()\n override fun nextLong() = nextToken()!!.toLong()\n override fun nextDouble() = nextToken()!!.toDouble()\n override fun nextChar() = bufferedReader.read().toChar()\n override fun nextString() = nextToken()!!\n override fun nextLine() = bufferedReader.readLine()!!\n override fun nextBigInteger() = BigInteger(nextToken()!!)\n override fun nextBigDecimal() = BigDecimal(nextToken()!!)\n }\n\n class TaskBuilder {\n private var task: Task? = null\n private var inputStream: InputStream? = null\n private var outputStream: OutputStream? = null\n private var scanner: Scanner? = null\n\n fun useInputSource(inputStream: InputStream): TaskBuilder {\n this.inputStream = inputStream\n return this\n }\n\n fun useOutputSource(outputStream: OutputStream): TaskBuilder {\n this.outputStream = outputStream\n return this\n }\n\n fun useInputFile(inputFileName: String): TaskBuilder {\n this.inputStream = FileInputStream(File(inputFileName))\n return this\n }\n\n fun useOutputFile(outputFileName: String): TaskBuilder {\n this.outputStream = FileOutputStream(File(outputFileName))\n return this\n }\n\n fun useScanner(scanner: Scanner): TaskBuilder {\n this.scanner = scanner\n return this\n }\n\n\n fun solveTask(task: Task): TaskBuilder {\n this.task = task\n return this\n }\n\n fun run() {\n when {\n task == null -> throw NullPointerException(\"Task cannot be null!\")\n inputStream == null -> throw NullPointerException(\"Input cannot be null!\")\n outputStream == null -> throw NullPointerException(\"Output cannot be null!\")\n scanner == null -> throw NullPointerException(\"Scanner cannot be null!\")\n }\n scanner!!.changeInputStream(inputStream!!)\n val printer = PrintWriter(outputStream)\n TaskRunnable(task!!, scanner!!, printer).run()\n\n inputStream!!.close()\n printer.close()\n }\n\n class TaskRunnable(\n private val task: Task,\n private val scanner: Scanner,\n private val printer: PrintWriter\n ) {\n fun run() {\n task.solve(scanner, printer)\n }\n }\n }\n\n @JvmStatic\n fun main(args: Array) = TaskBuilder()\n .useInputSource(System.`in`)\n .useOutputSource(System.out)\n .useScanner(FastScanner())\n .solveTask(TaskB())\n .run()\n\n class TaskA: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val countOfRooms = scanner.nextInt()\n val rooms = Array(countOfRooms) { scanner.nextInt() to scanner.nextInt() }\n printer.println(rooms\n .map { it.second - it.first }\n .filter { it >= 2 }\n .count())\n }\n\n }\n\n class TaskB: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val firstName = scanner.nextLine()\n val secondName = scanner.nextLine()\n val mixedUpName = scanner.nextLine()\n\n val alphabet = Array(26) { 0 }\n val mixedUpAlphabet = Array(26) { 0 }\n\n firstName.forEach { alphabet[it - 'A']++ }\n secondName.forEach { alphabet[it - 'A']++ }\n mixedUpName.forEach { mixedUpAlphabet[it - 'A']++ }\n\n (0..25) {\n if (alphabet[it] != mixedUpAlphabet[it]) {\n printer.println(\"NO\")\n System.exit(0)\n }\n\n }\n printer.println(\"YES\")\n }\n\n }\n}\n"}, {"source_code": "fun main() {\n val firstLine = readLine()!!.map { it.toString() }\n val secLine = readLine()!!.map { it.toString() }\n val thirdLine = readLine()!!.map { it.toString() }\n \n if (thirdLine - secLine == firstLine) {\n print(\"YES\")\n } else {\n print(\"NO\")\n }\n}"}, {"source_code": "\nfun main(){\n var arrChar = readLine()!!.toCharArray().toMutableList()\n arrChar.addAll(readLine()!!.toCharArray().toMutableList())\n arrChar.sort()\n var str = readLine()!!.toCharArray().toMutableList()\n str.sort()\n println(if (arrChar.equals(str)) \"Yes\" else \"NO\")\n}"}, {"source_code": "import java.util.*\n\nfun main(){\n\n val scan = Scanner(System.`in`)\n var arr = Array(26){ _ -> 0}\n var line = scan.next() + scan.next()\n\n\n for (i in line){\n arr[i.toInt()-65]++\n }\n\n for (i in scan.next()){\n arr[i.toInt()-65]--\n }\n\n var a = 0\n for (i in arr) a+=i\n\n if (a == 0) print(\"YES\")\n else print(\"NO\")\n\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n\nfun main() {\n val a = readLn()\n val b = readLn()\n val c = readLn()\n\n val aUb = a.groupingBy { it }.eachCount() + b.groupingBy { it }.eachCount()\n val cU = c.groupingBy { it }.eachCount()\n\n var sufficient = true\n for ((char, count) in cU) {\n val inA = aUb[char]\n if (inA == null) {\n sufficient = false\n break\n }\n if (inAb) a else b\nfun min(a:Long,b:Long) = if (ab) a else b\n\nfun readLn():String = readLine()!!.toString()\nfun readLong() = readLn().toLong()\nfun readLongs() = readLn().split(\" \").map{it.toLong()}\nvar nul=0.toLong();\nvar one=1.toLong();\nvar two=2.toLong();\nvar three=3.toLong();\nvar four=4.toLong();\nvar five=5.toLong();\nfun powmod(a:Long,b:Long,mod:Long):Long {\n\n if (b==1.toLong()) return a;\n var k=powmod(a,b/2,mod);\n if (b%2==0.toLong())\n { return (k*k)%mod }\n else { k=k*k; k=k%mod; k=k*a; k=k%mod; return k; }\n}\nfun prime (p:Long):Long {\n if (p==one) return 0.toLong();\n var i=two;\n while (i*i<=p) {if (p%i==nul) return i; i++; }\n return one;\n}\nfun inv (a:Long,mod:Long):Long {\nreturn powmod(a,mod-2,mod);\n}\n\nfun solve() {\n val cin = Scanner(System.`in`)\n\n /*\n var map=hashMapOf();\n map[q] <=> map.getOrDefault(q,0)\n Сортировка вектора пар - k=v.sortedWith(compareBy({it.first},{it.second}));\n prLong(\"${k[i].second}\"); - вывод аргумента пары\n var m=ArrayList (); <=> vector\n getline(cin,a) <=> readLine()!!.last()\n readLong() - одно число\n readLongs() - несколько чисел\n readLine()!!.toCharArray() - возвращает массив чаров из строки\n\n */\n /* --------- */\n // ВСЕГДА ПИСАТЬ В ЛОНГАХ\n\n var a=readLine()!!.toString();\n var b=readLine()!!.toString();\n var c=readLine()!!.toString();\n\n var qq=LongArray(26);\n\n for (i in 0..a.length-1) {\n qq[a[i]-'A']++;\n }\n for (i in 0..b.length-1) {\n qq[b[i]-'A']++;\n }\n for (i in 0..c.length-1) {\n qq[c[i]-'A']--;\n }\n var check=one;\n for (i in 0..25) if (qq[i]>nul) check=nul;\n if (check==nul) print(\"NO\"); else print(\"YES\");\n\n /* --------- */\n\n}\n\nfun main() {\n val cin = Scanner(System.`in`)\n\n var T=one;\n //T=readLine()!!.toLong();\n for (i55555 in 1..T) solve()\n}\n"}], "src_uid": "b6456a39d38fabcd25267793ed94d90c"} {"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": "\n// y < b < r\n// y = (b - 1) = (r - 2)\nfun main(args: Array) {\n val (y, b, r) = readLine()!!.split(' ').map(String::toInt)\n\n var rMax = r\n if (b < (rMax - 1)) {\n rMax = b + 1\n }\n\n if (y < (rMax - 2)) {\n rMax = y + 2\n }\n\n println(rMax * 3 - 3)\n\n}\n\n"}, {"source_code": "fun main() {\n val inp = readLine()\n if(inp != null) {\n val arr = inp.split(' ').map { e -> Integer.parseInt(e) }\n var a = arr[0]\n var b = arr[1]\n var c = arr[2]\n\n if(b >= c)\n b = c-1\n\n if(a >= b)\n a = b - 1\n\n println(a*3 + 3)\n }\n}"}, {"source_code": "fun main( args : Array) {\n\n val str= readLine()!!\n\n val ar = str.split(\" \")\n val y = ar[0].toInt()\n val b = ar[1].toInt()\n val r = ar[2].toInt()\n val n = minOf(y + 1, b, r - 1)\n println(n*3)\n }"}, {"source_code": "\nfun main() {\n var a = readLine()!!.split(' ')!!.map(String::toInt)\n println(minOf(a[0]+1,a[1],a[2]-1)*3)\n}"}, {"source_code": "import kotlin.math.*\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val (y,b,r) = readInts();\nval x = min(y, min(b-1, r-2))\n println(x*3+3)\n}"}, {"source_code": "fun main(args: Array) {\n\n val parts = readLine()!!.toString().split(\" \")\n val v1 : Int =parts.get(0).toInt()\n val v2 : Int= parts.get(1).toInt()\n val v3 : Int = parts.get(2).toInt()\n\n var res : Int = 0;\n\n if(v1+1 <= v2 && v1+2<=v3){\n res = v1 + v1+1 + v1+2\n println(\"$res\")\n }else {\n if(v2+1 <= v3 && v2-1<=v1){\n res = v2-1 + v2 + v2+1\n println(\"$res\")\n }else {\n res = v3-2+v3-1+v3\n println(\"$res\")\n }\n }\n}"}, {"source_code": "fun main() {\n val line = readLine()!!.split(\" \").mapIndexed{ind,n -> n.toInt()*3+(3-3*ind) }.min()\n println(line)\n}"}, {"source_code": "fun main() {\n val line = readLine()!!.split(\" \").mapIndexed{ind,n -> n.toInt()*3+(3-3*ind) }.min()\n println(line)\n}"}, {"source_code": "fun main() {\n var (y, b, r) = readLine()!!.split(\" \").map { it.toInt() }\n while (y > 0) {\n if (b > y && r > y + 1) {\n println(3 * y + 3)\n break\n }\n y--\n }\n}\n"}, {"source_code": "import kotlin.math.min\n\nfun main() {\n print( ProblemB(ProblemB.readInput()).solve() )\n}\n\n\nclass ProblemB (triple: Triple) {\n\n val yellow = triple.first\n val blue = triple.second\n val red = triple.third\n\n companion object {\n fun readInput() : Triple {\n val line = readLine()\n val values : List = line!!.split(\" \").map { it.toInt() }\n return Triple(values[0], values[1], values[2])\n }\n }\n\n fun solve() : Int {\n return solution(min(yellow + 1, min(blue, red - 1) ))\n }\n\n private fun solution(value: Int): Int {\n return if (yellow >= value - 1 && red > value) {\n value * 3\n } else\n solution(value - 1)\n }\n}\n"}, {"source_code": "fun main(args: Array) {\n val (y, b, r) = readLine()!!.split(\" \").map { it.toInt() }\n val my = minOf(y, b - 1, r - 2)\n println(3 * my + 3)\n}"}, {"source_code": "fun main(args: Array){\nvar (Y,B,R)=readLine()!!.split(\" \")\nvar y=Y.toInt()\nvar b=B.toInt()\nvar r=R.toInt()\nb=b+1\ny=y+2\nvar ans=kotlin.math.min(b,y)\nans=kotlin.math.min(ans,r)\nprintln((ans*3-3))\n}"}, {"source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n \tvar score = 6\n val input = Scanner(System.`in`)\n val a = input.nextInt()\n val b = input.nextInt()\n val c = input.nextInt()\n for (i in 2..999){\n if(i <= a && i+1 <= b && i+2 <= c)\n \tscore = score+3\n else break\n }\n println(score)\n}"}, {"source_code": "fun main(args: Array) {\n val inp = readLine()!!.split(\" \").map(String::toInt)\n val x = inp[0]\n val y = inp[1]\n val z = inp[2]\n\n var ans= y\n while(ans>0)\n {\n if(ans+1<=z&&ans-1<=x)\n {\n print(ans*3)\n break \n }\n ans=ans-1\n }\n \n \n}"}, {"source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n \n val read=Scanner(System.`in`) \n var a=read.nextInt()\n var b=read.nextInt()\n var c=read.nextInt()\n \n \n while(true) {\n \n if((a+1<=b) and (a+2<=c))\n {\n b=a+1\n println(\"${3*b}\") \n return\n } \n a--\n }\n}"}, {"source_code": "fun main() {\n var str = readLine().toString()\n var parts = str.split(\" \").toTypedArray()\n var y = parts[0].toInt()\n var b = parts[1].toInt()\n var r = parts[2].toInt()\n var m1 = b-y-1\n var m2 = r-y-2\n var orn = y*3 + 3\n if ((m1 < 0) || (m2 < 0)) {\n if (m1 <= m2) {\n orn += m1*3\n } else {\n orn += m2*3\n }\n }\n \n print(orn)\n}"}, {"source_code": "import java.util.*;\nimport kotlin.math.*;\n\nfun main() {\n val sc = Scanner(System.`in`);\n val a = sc.nextInt() ;\n val b = sc.nextInt() ;\n val c = sc.nextInt() ;\n val ans = minOf(a , b - 1 , c - 2) ;\n println(ans * 3 + 3) ;\n}"}, {"source_code": "fun main(args: Array) {\n val ints = readLine()?.split(\" \")?.map(String::toInt) ?: return \n val minStart = ints.mapIndexed { index, int -> int - index }.min()!!\n val result = minStart * 3 + 3\n print(result)\n}\n"}, {"source_code": "import kotlin.math.min\n\nfun main() {\n val (y, b, r) = readLine()!!.split(' ').map(String::toInt)\n println(3 * min(min(b, y + 1), r - 1))\n}\n"}, {"source_code": "fun main() {\n var (y, b, r) = readLine()!!.split(\" \").map { it.toInt() }\n if (b >= r)\n b = r - 1\n if (y >= b)\n y = b - 1\n b = y + 1\n r = b + 1\n println(\"${y + b + r}\")\n}\n"}, {"source_code": "\nimport java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n\n val line = nextLine().split(' ')\n val y = line[0].toInt()\n val b = line[1].toInt()\n val r = line[2].toInt()\n\n val min = min(y, min(b, r))\n val secondMin: Int\n var printVal = 0\n when (min) {\n r -> println(3 * r - 3)\n b -> {\n secondMin = min(y, r)\n when (secondMin) {\n r -> printVal =\n if (secondMin - min < 1)\n r - 1\n else\n b\n y -> printVal = b\n }\n println(printVal * 3)\n }\n y -> {\n secondMin = min(b, r)\n when (secondMin) {\n r -> printVal =\n if (secondMin - min < 2)\n r - 2\n else\n y\n b -> printVal =\n if (secondMin - min < 1)\n b - 1\n else\n y\n }\n println(printVal * 3 + 3)\n }\n\n }\n}"}, {"source_code": "fun main() {\n val (y, b, r) = readLine()!!.split(\" \")\n val m = minOf(y.toInt(), b.toInt() - 1, r.toInt() - 2)\n println(m * 3 + 3)\n}"}, {"source_code": "fun main() {\n val inputs = readLine()!!.split(\" \")\n val (yellow, blue, red) = inputs.map { it.toInt() }\n var result = 0\n\n inputs.asReversed().map { it.toInt() }.forEachIndexed { index, input ->\n when (index) {\n 0 -> {\n if (input - 1 <= blue && input - 2 <= yellow) {\n result = input * 3 - 3\n return@forEachIndexed\n }\n }\n 1 -> {\n if (input + 1 <= red && input - 1 <= yellow) {\n result = input * 3\n return@forEachIndexed\n }\n }\n 2 -> {\n if (input + 1 <= blue && input + 2 <= red) {\n result = input * 3 + 3\n return@forEachIndexed\n }\n }\n }\n }\n\n print(result)\n}"}, {"source_code": "fun main() {\n println( readLine()!!.split(\" \").mapIndexed{ind,n -> n.toInt()*3+(3-3*ind) }.min())\n}"}, {"source_code": "fun main(args: Array) {\n val (y, b, r) = readLine()!!.split(\" \").map(String::toInt)\n if (r - y <= 2) {\n if (r - b <= 1) {\n print(r * 3 - 3)\n } else {\n print(b * 3)\n }\n } else {\n if (b - y <= 1) {\n print(b * 3)\n } else {\n print(y * 3 + 3)\n }\n }\n}"}, {"source_code": "fun main() {\n val (y, b, r) = readInts(3).toList()\n if (b >= r - 1) {\n if (y >= r - 2) {\n println((r - 1) * 3)\n return\n }\n println((y + 1) * 3)\n return\n }\n if (y >= b - 1) {\n println(b * 3)\n return\n }\n println((y + 1) * 3)\n}\n\nprivate fun isWhiteSpace(c: Char) = c in \" \\r\\n\\t\"\n\nprivate fun readString() = generateSequence { System.`in`.read().toChar() }\n .dropWhile { isWhiteSpace(it) }\n .takeWhile { !isWhiteSpace(it) }\n .joinToString(\"\")\n\nprivate fun readInt() = readString().toInt()\nprivate fun readInts(n: Int) = generateSequence { readInt() }.take(n)"}, {"source_code": "fun getMin(a: Int, b: Int, c: Int): Int\n{\n if (a <= b && a <= c) return a\n if (b <= c) return b\n return c\n}\n\nfun main()\n{\n val nn = readLine()!!.split(\" \").map { it.toInt() }\n val mini = getMin(nn[0], nn[1] - 1, nn[2] - 2) + 1\n println(mini * 3)\n}\n"}, {"source_code": "fun main() {\n val base = listOf(0, 1, 2)\n val baseSum = base.sum()\n val numbers = readLine()?.split(' ')?.map { it -> it.toInt() } ?: base\n val low = numbers.zip(base, Int::minus).min() ?: - baseSum\n print(low * base.size + baseSum)\n}\n"}, {"source_code": "fun main()\n{\n val(a,b,c)=readLine()!!.split(' ').map(String::toInt)\n print(3*minOf(a+1,b,c-1))\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.min\n\nfun main(args : Array) {\n val reader = Scanner(System.`in`)\n\n var y:Int\n var b:Int\n var r:Int\n var min:Int\n var result:Int\n\n\n y=reader.nextInt()\n b=reader.nextInt()\n r=reader.nextInt()\n\n min= minOf(y,b,r)\n result= when (min) {\n r -> r+(r-1)+(r-2)\n b -> (b-1)+b+(b+1)\n else -> { // Note the block\n if(r-y>1){\n y+(y+1)+(y+2)\n }else{\n (y-1)+(y)+(y+1)\n }\n }\n }\n\n println(result)\n\n\n\n\n\n}"}, {"source_code": "fun main() {\n val base = listOf(0, 1, 2)\n val baseSum = base.sum()\n val numbers = readLine()?.split(' ')?.map { it.toInt() } ?: base\n val low = numbers.zip(base, Int::minus).min() ?: - baseSum\n print(low * base.size + baseSum)\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val input = Scanner(System.`in`).nextLine().split(\" \").map { Integer.parseInt(it) }.toList()\n\n fun isValid(yellow: Int, blue: Int, red: Int): Boolean {\n return yellow <= input[0] && blue <= input[1] && red <= input[2] && yellow == blue + blue - red\n }\n\n var yellow = input[0]\n var blue = yellow + 1\n var red = blue + 1\n\n while (!isValid(yellow, blue, red)) {\n yellow--\n blue--\n red--\n }\n\n print(yellow + blue + red)\n}"}, {"source_code": "//package com.happypeople.codeforces.c1091\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) {\n try {\n A().run()\n } catch (e: Throwable) {\n A.log(\"\" + e)\n }\n}\n\nclass A {\n fun run() {\n val sc = Scanner(systemIn())\n val y=sc.nextInt()\n val b=sc.nextInt()\n val r=sc.nextInt()\n\n // b==y+1\n // r==b+1\n\n var m=min(b, y+1)\n m=min(m+1, r)\n m=3*m-3\n println(\"$m\")\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val inputLine = readLine()!!\n val parts = inputLine.split(' ')\n\n if (parts.size != 3) {\n throw Exception()\n }\n\n val yellow = parts[0].toInt()\n val blue = parts[1].toInt()\n val red = parts[2].toInt()\n\n if (yellow !in 1..100) {\n throw Exception()\n }\n\n if (blue !in 2..100) {\n throw Exception()\n }\n\n if (red !in 3..100) {\n throw Exception()\n }\n\n println(calculate(yellow, blue, red))\n}\n\nfun calculate(yellow: Int, blue: Int, red: Int): Int {\n return if (yellow + 2 <= blue + 1 && yellow + 2 <= red) {\n ((yellow + 2) * 3 - 3)\n } else if (blue + 1 <= yellow + 2 && blue + 1 <= red) {\n ((blue + 1) * 3 - 3)\n } else {\n ((red) * 3 - 3)\n }\n}"}, {"source_code": "fun main()\n{\n val (a:Int,b:Int,c:Int)= readLine()!!.split(' ').map(String::toInt)\n println(\"${3*minOf(a,b-1,c-2)+3}\")\n}"}, {"source_code": "fun main() {\n val balls = readLine()!!.split(\" \").map { it.toInt() }.toIntArray()\n balls[1]--\n balls[2] -= 2\n var min = balls.min()!!\n println(min * 3 + 3)\n\n}\n"}, {"source_code": "import java.util.Scanner\n fun main(args: Array) {\n val sc = Scanner(System.`in`)\n println(Math.min(Math.min(sc.nextInt(), sc.nextInt() - 1), sc.nextInt() - 2) * 3 + 3)\n }\n"}, {"source_code": "fun main() {\n var ybr = readLine()!!.split(' ').map { it.toInt() }\n\n println(MaxSum(ybr))\n}\n\nfun MaxSum(values: List): Int {\n var middle = values[1]\n while (middle - 1 > values.first() || middle + 1 > values.last())\n middle -= 1\n\n return 3 * middle\n}"}, {"source_code": "fun main() {\n val inputs = readLine()!!.split(\" \").map { it.toInt() }\n val (yellow, blue, red) = inputs\n var result = 0\n\n inputs.asReversed().forEachIndexed { index, input ->\n when (index) {\n 0 -> if (input - 1 <= blue && input - 2 <= yellow)\n result = input * 3 - 3\n 1 -> if (input + 1 <= red && input - 1 <= yellow)\n result = input * 3\n 2 -> if (input + 1 <= blue && input + 2 <= red)\n result = input * 3 + 3\n }\n\n if (result > 0)\n return@forEachIndexed\n }\n\n print(result)\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.min\n\nfun main() {\n val scanner = Scanner(System.`in`)\n println(min(min(scanner.nextInt(), scanner.nextInt() - 1), scanner.nextInt() - 2) * 3 + 3)\n}"}, {"source_code": "fun main(args: Array) {\n val ints = readLine()?.split(\" \")?.map(String::toInt) ?: return \n val minStart = ints.mapIndexed { index, int -> int - index }.min()!!\n val result = minStart * 3 + 3\n print(result)\n}\n"}, {"source_code": "fun main(args: Array){\n var i = 2\n var min = Int.MAX_VALUE\n val nums = readLine()!!.split(\" \").map { s -> s.toInt() }\n if(nums[2]) {\n val input = Scanner(System.`in`)\n val yellow = input.nextInt()\n val blue = input.nextInt()\n val red = input.nextInt()\n if (blue <= yellow && blue < red) {\n val sum = blue + 1 + blue + blue - 1\n println(sum)\n } else if (yellow < blue && yellow < red) {\n val diff = red - yellow\n if (diff >= 2) {\n val sum = yellow + yellow + 1 + yellow + 2\n println(sum)\n } else {\n val sum = yellow - 1 + yellow + yellow + 1\n println(sum)\n }\n } else {\n val sum = red + red - 1 + red - 2\n println(sum)\n }\n}"}, {"source_code": "fun main() {\n val inputs = readLine()!!.split(\" \").map { it.toInt() }\n val (yellow, blue, red) = inputs\n var result = 0\n\n inputs.asReversed().forEachIndexed { index, input ->\n when (index) {\n 0 -> if (input - 1 <= blue && input - 2 <= yellow)\n result = input * 3 - 3\n 1 -> if (input + 1 <= red && input - 1 <= yellow)\n result = input * 3\n 2 -> if (input + 1 <= blue && input + 2 <= red)\n result = input * 3 + 3\n }\n\n if (result > 0)\n return@forEachIndexed\n }\n\n print(result)\n}"}, {"source_code": "fun main() {\n val line = readLine()!!.split(\" \")\n val y = line[0].toInt()\n val b = line[1].toInt()\n val r = line[2].toInt()\n val min = minOf(y, b, r)\n if (min == r) {\n println(3 * r - 3)\n return\n }\n\n if (min == b) {\n println(3 * (b))\n return\n }\n\n if (min == y) {\n if (r > b) {\n println((3 * y) + 3)\n } else {\n if (r == y + 1) {\n println(3 * (y - 1) + 3)\n } else {\n println((3 * y) + 3)\n }\n }\n }\n}"}, {"source_code": "fun main() {\n var (y, b, r) = readLine()!!.split(\" \").map { it.toInt() }\n while (y > 0) {\n if (b > y && r > y + 1) {\n println(3 * y + 3)\n break\n }\n y--\n }\n}\n"}, {"source_code": "import java.util.Scanner\nfun main(args: Array) {\nval reader = Scanner(System.`in`)\n var y:Int = reader.nextInt()\n var b:Int = reader.nextInt()\n var r:Int = reader.nextInt()\n var ans = r\n var t = r\n if(r-1>b)\n {\n ans=(b+b+1)\n t=b\n }\n else\n {\n ans=ans+(r-1)\n t=r-1\n }\n if(t-1>y)\n {\n ans=(3*y)+3\n }\n else\n {\n ans=ans+(t-1)\n }\n println(\"$ans\\n\")\n}\n/*\nfun main(args: Array) {\n var t = readLine()!!.toInt()\n var y = readLine()!!.toInt()\n var b = readLine()!!.toInt()\n var r = readLine()!!.toInt()\n var ans = r\n if(r-1>b)\n {\n ans=(b+b+1)\n t=b\n }\n else\n {\n ans=ans+b\n t=r-1\n }\n if(t-1>y)\n {\n ans=(3*y)+1\n }\n else\n {\n ans=ans+y\n }\n println(\"$ans\\n\")\n}\n*/"}, {"source_code": "fun main() {\n val (y, b, r) = readLine()!!.split(\" \").map { it.toInt() }\n val my = minOf(y, b - 1, r - 2)\n println(3 * my + 3)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n val yellow = input.nextInt()\n val blue = input.nextInt()\n val red = input.nextInt()\n if (blue <= yellow && blue < red) {\n val sum = blue + 1 + blue + blue - 1\n println(sum)\n } else if (yellow < blue && yellow < red) {\n val diff = red - yellow\n if (diff >= 2) {\n val sum = yellow + yellow + 1 + yellow + 2\n println(sum)\n } else {\n val sum = yellow - 1 + yellow + yellow + 1\n println(sum)\n }\n } else {\n val sum = red + red - 1 + red - 2\n println(sum)\n }\n}"}, {"source_code": "import java.util.*\n\nfun main() = with(Scanner(System.`in`)) {\n val min = Array(3) { nextInt() }.mapIndexed { index, int -> int - index }.min()\n if (min != null) {\n print(min * 3 + 3)\n }\n}\n"}, {"source_code": "\nimport java.util.Scanner\n\nfun main(args: Array) {\n var scan = Scanner(System.`in`)\n var y: Int\n var b: Int\n var r: Int\n var n: Int = 0\n y = scan.nextInt()\n b = scan.nextInt()\n r = scan.nextInt()\n var min = if (y <= b) -1 else -2\n if (min ==-1)\n \tmin = if (y <= r) -1 else -3\n else\n \tmin = if (b <= r) -2 else -3\n \n if (min == -3) //red is minimum\n \tn = (r - 1) * 3\n else if (min == -2){ //blue is minimum\n if (b == r){\n b = r - 1\n n = b * 3\n }\n else\n \tn = b * 3\n }\n else if (min == -1){ //yellow is minimum\n if ((r - y) >= 2){\n if ((b - y) >= 1)\n \tn = (y + 1) * 3\n else{\n y = b - 1\n n = (y + 1) * 3\n } \t\n }\n else{\n y = r -2\n n = (y + 1) * 3\n }\n }\n \n println (n)\n \t\n}"}, {"source_code": "fun readLines(): List {\n val amount = readLine()?.toInt()!!\n return (0 until amount).map { readLine()!! }\n}\n\nfun main() {\n val (y, b, r) = readLine()!!.split(\" \").map { it.toInt() }\n// val (y, b, r) = \"8 13 9\".split(\" \").map { it.toInt() }\n // 4 5 6\n val py = Math.min(y, Math.min(b-1, r-2))\n println(py + py + py + 1 + 2)\n}"}, {"source_code": "fun main() {\n val (y, b, r) = readInts()\n\n val ans = minOf(y+1, b, r-1) * 3\n \n println(ans)\n}\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit) { Output().apply(block).nowPrint() }"}, {"source_code": "\nfun findNumber(y: Int, b: Int, r: Int): Int {\n\n // all different\n if (y != b && y != r && b != r) {\n\n val minNum = minOf(y, b, r)\n val maxNum = maxOf(y, b, r)\n\n when (maxNum) {\n y -> {\n return when (minNum) {\n b -> (b - 1) + b + (b + 1)\n else -> (r - 2) + (r - 1) + r\n }\n }\n b -> {\n return when (minNum) {\n y -> {\n if (r - y > 2) y + (y + 1) + (y + 2) else (r - 2) + (r - 1) + r\n }\n else -> /* r */ (r - 2) + (r - 1) + r\n }\n }\n else /* r */ -> {\n return when (minNum) {\n y -> y + (y + 1) + (y + 2)\n else -> /* b */ (b - 1) + b + (b + 1)\n }\n }\n }\n\n\n } else {\n if (y == b) {\n return findNumber(b + r, b, r)\n } else if (y == r) {\n return findNumber(y + r, b, r)\n } else {\n // b == r\n return findNumber(y, b + r, r)\n }\n }\n\n}\n\nfun main(args: Array) {\n val (strY, strB, strR) = readLine()!!.split(' ')\n\n val y = strY.toInt()\n val b = strB.toInt()\n val r = strR.toInt()\n\n print(findNumber(y, b, r))\n}\n"}, {"source_code": "fun main() {\n val (a, b, c) = readLine()!!.split(\" \").map(String::toInt)\n val d = minOf(a, b - 1, c - 2)\n println(d * 3 + 3)\n}"}, {"source_code": "fun main(args: Array) {\n val (y, b, r) = readLine()!!.split(\" \").map { it.toInt() }\n val my = minOf(y, b - 1, r - 2)\n println(3 * my + 3)\n}"}, {"source_code": "fun main() {\n println(readLine()!!.split(' ').mapIndexed { index, s -> s.toInt() - index }.min()!!.toInt() * 3 + 3)\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.min\n\nfun main() {\n Scanner(System.`in`).use { scanner ->\n val y = scanner.nextInt()\n val b = scanner.nextInt() - 1\n val r = scanner.nextInt() - 2\n val min = min(min(y, b), r)\n println(min * 3 + 3)\n }\n}"}, {"source_code": "fun main() {\n val input = readLine()?.split(' ') ?: emptyList()\n val y = input[0].toByte()\n val b = input[1].toByte()\n val r = input[2].toByte()\n\n val b1: Byte = 1\n val b2: Byte = 2\n val b3: Byte = 3\n\n println(when (minOf(y, b, r)) {\n r -> (r-b2) * b3 + b3\n b -> (b-b1) * b3 + b3\n y -> if (r - y < 2) (y-b1) * b3 + b3 else y * b3 + b3\n else -> -1\n })\n}"}, {"source_code": "fun main() {\n val (y, b, r) = readLine()!!.split(\" \").map { it.toInt() }\n println(listOf(y, b - 1, r - 2).min()!! * 3 + 3)\n}"}, {"source_code": "//package com.happypeople.codeforces.c1091\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) {\n try {\n A().run()\n } catch (e: Throwable) {\n A.log(\"\" + e)\n }\n}\n\nclass A {\n fun run() {\n val sc = Scanner(systemIn())\n val y=sc.nextInt()\n val b=sc.nextInt()\n val r=sc.nextInt()\n\n // b==y+1\n // r==b+1\n\n var m=min(b, y+1)\n m=min(m+1, r)\n m=3*m-3\n println(\"$m\")\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}"}, {"source_code": "fun main() {\n //val (a, b, c) = readInts()// read integer from the input\n val fl = readLine()!!.split(\" \").map { it.toInt() }\n val x: Int\n if(fl[0]+1 < fl[2]-1) x = fl[0]+1\n else x = fl[2]-1\n if(fl[1]\n println(min(min(scanner.nextInt(), scanner.nextInt() - 1), scanner.nextInt() - 2) * 3 + 3)\n }\n}"}, {"source_code": "import java.io.*\nimport java.math.*\nimport java.text.*\nimport java.util.*\nimport java.util.regex.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val x = scan.nextInt()\n val y = scan.nextInt()\n val z = scan.nextInt()\n var ans= y\n val flag = true\n while(flag)\n {\n if(ans+1<=z&&ans-1<=x)\n {\n print(ans*3)\n break \n }\n ans=ans-1\n }\n \n \n}"}, {"source_code": "data class Ornament(val ornament: Int, val offset: Int) {\n fun get() = ornament - offset\n}\n\n// red > blue > yellow exactly 1 is great christmas ornament\nclass ChristmasOrnament {\n var totalRed: Int = 0\n var totalBlue: Int = 0\n var totalYellow: Int = 0\n\n fun input() {\n val args = mutableListOf()\n val ornaments = readLine()!!.split(\" \").map { it.toInt() }\n totalYellow = ornaments[0]\n totalBlue = ornaments[1]\n totalRed = ornaments[2]\n args.add(Ornament(totalRed, 0))\n args.add(Ornament(totalRed, 1))\n args.add(Ornament(totalRed, 2))\n output(args)\n }\n\n fun output(args: List) {\n val ornaments = args.map { it as Ornament }\n val christmasOrnaments = decrease(ornaments[0], ornaments[1], ornaments[2])\n val totalOrnaments = christmasOrnaments.reduce { acc, i -> acc + i }\n println(totalOrnaments)\n }\n\n private fun decrease(red: Ornament, blue: Ornament, yellow: Ornament): List {\n return if (blue.get() <= totalBlue && yellow.get() <= totalYellow) listOf(red.get(), blue.get(), yellow.get())\n else decrease(\n Ornament(red.get() - 1, offset = 0),\n Ornament(red.get() - 1, offset = 1),\n Ornament(red.get() - 1, offset = 2)\n )\n }\n}\n\nfun main() {\n ChristmasOrnament().input()\n}\n"}, {"source_code": "import com.sun.org.apache.xpath.internal.operations.Bool\nimport jdk.nashorn.internal.runtime.ScriptingFunctions.readLine\nimport java.util.Scanner\nfun max(a:Int,b:Int):Int\n{\n if(a<=b)return a\n else return b\n}\nfun main(args: Array)\n{\n val read= Scanner(System.`in`)\n var c=Array(4,{it ->0})\n var maxn:Int\n maxn=1000000\n for(i in 1..3){\n c[i]=read.nextInt()\n c[i]=c[i]-i+1\n maxn =max(c[i],maxn)\n }\n\n println(3*maxn+3)\n}\n\n"}, {"source_code": "fun main(args: Array) {\n val (y, b, r) = readLine()!!.split(\" \").map(String::toInt)\n if (r - y <= 2) {\n if (r - b <= 1) {\n print(r * 3 - 3)\n } else {\n print(b * 3)\n }\n } else {\n if (b - y <= 1) {\n print(b * 3)\n } else {\n print(y * 3 + 3)\n }\n }\n}"}, {"source_code": "fun main() {\n val inputs = readLine()!!.split(\" \")\n val (yellow, blue, red) = inputs.map { it.toInt() }\n var result = 0\n\n inputs.asReversed().map { it.toInt() }.forEachIndexed { index, input ->\n when (index) {\n 0 -> {\n if (input - 1 <= blue && input - 2 <= yellow) {\n result = input * 3 - 3\n return@forEachIndexed\n }\n }\n 1 -> {\n if (input + 1 <= red && input - 1 <= yellow) {\n result = input * 3\n return@forEachIndexed\n }\n }\n 2 -> {\n if (input + 1 <= blue && input + 2 <= red) {\n result = input * 3 + 3\n return@forEachIndexed\n }\n }\n }\n }\n\n print(result)\n}"}, {"source_code": "fun main() {\n val inputs = readLine()!!.split(\" \").map { it.toInt() }\n val (yellow, blue, red) = inputs\n var result = 0\n\n inputs.asReversed().forEachIndexed { index, input ->\n when (index) {\n 0 -> if (input - 1 <= blue && input - 2 <= yellow)\n result = input * 3 - 3\n 1 -> if (input + 1 <= red && input - 1 <= yellow)\n result = input * 3\n 2 -> if (input + 1 <= blue && input + 2 <= red)\n result = input * 3 + 3\n }\n\n if (result > 0)\n return@forEachIndexed\n }\n\n print(result)\n}"}, {"source_code": "fun main() {\n var (y, b, r) = readLine()!!.split(\" \").map { it.toInt() }\n if (b >= r)\n b = r - 1\n if (y >= b)\n y = b - 1\n b = y + 1\n r = b + 1\n println(\"${y + b + r}\")\n}\n"}, {"source_code": "//package com.happypeople.codeforces.c1091\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) {\n try {\n A().run()\n } catch (e: Throwable) {\n A.log(\"\" + e)\n }\n}\n\nclass A {\n fun run() {\n val sc = Scanner(systemIn())\n val y=sc.nextInt()\n val b=sc.nextInt()\n val r=sc.nextInt()\n\n // b==y+1\n // r==b+1\n\n var m=min(b, y+1)\n m=min(m+1, r)\n m=3*m-3\n println(\"$m\")\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n var yellow = 1\n var blue = 2\n var red = 3\n\n yellow = scanner.nextInt()\n blue = scanner.nextInt()\n red = scanner.nextInt()\n\n\n val summ = 0\n\n while (yellow != blue - 1 || yellow != red - 2 && blue != red - 1) {\n\n if (yellow >= blue)\n yellow = blue - 1\n else if (yellow < blue)\n blue = yellow + 1\n\n if (blue >= red)\n blue = red - 1\n else if (blue < red)\n red = blue + 1\n\n }\n\n\n print(yellow + blue + red)\n}"}, {"source_code": "fun main() {\n val (y, b, r) = readInts(3).toList()\n if (b >= r - 1) {\n if (y >= r - 2) {\n println((r - 1) * 3)\n return\n }\n println((y + 1) * 3)\n return\n }\n if (y >= b - 1) {\n println(b * 3)\n return\n }\n println((y + 1) * 3)\n}\n\nprivate fun isWhiteSpace(c: Char) = c in \" \\r\\n\\t\"\n\nprivate fun readString() = generateSequence { System.`in`.read().toChar() }\n .dropWhile { isWhiteSpace(it) }\n .takeWhile { !isWhiteSpace(it) }\n .joinToString(\"\")\n\nprivate fun readInt() = readString().toInt()\nprivate fun readInts(n: Int) = generateSequence { readInt() }.take(n)"}, {"source_code": "//package com.happypeople.codeforces.c1091\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) {\n try {\n A().run()\n } catch (e: Throwable) {\n A.log(\"\" + e)\n }\n}\n\nclass A {\n fun run() {\n val sc = Scanner(systemIn())\n val y=sc.nextInt()\n val b=sc.nextInt()\n val r=sc.nextInt()\n\n // b==y+1\n // r==b+1\n\n var m=min(b, y+1)\n m=min(m+1, r)\n m=3*m-3\n println(\"$m\")\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}"}, {"source_code": "\nfun main(){\n fun readLn() = readLine()!!\n fun readStrings(delim: Char = ' ') = readLn().split(delim)\n fun readInts() = readStrings().map { it.toInt() }\n\n val (y,b,r) = readInts()\n\n println(3+3*Math.min(y,Math.min(b-1,r-2)))\n\n}"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n var yellow = 1\n var blue = 2\n var red = 3\n\n yellow = scanner.nextInt()\n blue = scanner.nextInt()\n red = scanner.nextInt()\n\n\n val summ = 0\n\n while (yellow != blue - 1 || yellow != red - 2 && blue != red - 1) {\n\n if (yellow >= blue)\n yellow = blue - 1\n else if (yellow < blue)\n blue = yellow + 1\n\n if (blue >= red)\n blue = red - 1\n else if (blue < red)\n red = blue + 1\n\n }\n\n\n print(yellow + blue + red)\n}"}, {"source_code": "private fun readLn() = readLine()!!\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInt() = readLn().toInt()\nprivate fun readInts() = readStrings().map { it.toInt() }\n\nfun main(){\n\n val(y, b, r) = readInts()\n\n var ans : Int = 0 \n\n if( y+1 <= b && y+2 <= r && 3*y+3 > ans ) ans = 3*y+3\n\n if( b-1 <= y && b+1 <= r && 3*b > ans ) ans = 3*b\n\n if( r-2 <= y && r-1 <= b && 3*r-3 > ans ) ans = 3*r-3\n\n println(\"$ans\") \n\n \n\n}"}, {"source_code": "private fun ri() = readLine()!!.toInt()\nprivate fun rli() = readLine()!!.split(\" \").map { it.toInt() }\n\nfun main() {\n val (y, b, r) = rli()\n val maxRed = minOf(r, b+1, y+2)\n println(3 * (maxRed - 1))\n}"}, {"source_code": "fun main() {\n val (y,b,r) = readLine()!!.split(\" \").map { it.toInt() }\n val res = minOf(y, b-1, r-2)\n println(3*res+3)\n}"}, {"source_code": "\nimport java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n\n val line = nextLine().split(' ')\n val y = line[0].toInt()\n val b = line[1].toInt()\n val r = line[2].toInt()\n\n val min = min(y, min(b, r))\n val secondMin: Int\n var printVal = 0\n when (min) {\n r -> println(3 * r - 3)\n b -> {\n secondMin = min(y, r)\n when (secondMin) {\n r -> printVal =\n if (secondMin - min < 1)\n r - 1\n else\n b\n y -> printVal = b\n }\n println(printVal * 3)\n }\n y -> {\n secondMin = min(b, r)\n when (secondMin) {\n r -> printVal =\n if (secondMin - min < 2)\n r - 2\n else\n y\n b -> printVal =\n if (secondMin - min < 1)\n b - 1\n else\n y\n }\n println(printVal * 3 + 3)\n }\n\n }\n}"}, {"source_code": "import java.util.*\n\nfun main() = with(Scanner(System.`in`)) {\n val min = Array(3) { nextInt() }.mapIndexed { index, int -> int - index }.min()\n if (min != null) {\n print(min * 3 + 3)\n }\n}\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n val yellow = input.nextInt()\n val blue = input.nextInt()\n val red = input.nextInt()\n if (blue <= yellow && blue < red) {\n val sum = blue + 1 + blue + blue - 1\n println(sum)\n } else if (yellow < blue && yellow < red) {\n val diff = red - yellow\n if (diff >= 2) {\n val sum = yellow + yellow + 1 + yellow + 2\n println(sum)\n } else {\n val sum = yellow - 1 + yellow + yellow + 1\n println(sum)\n }\n } else {\n val sum = red + red - 1 + red - 2\n println(sum)\n }\n}"}, {"source_code": "import java.util.Scanner\nfun main(args:Array){\n\tval reader = Scanner(System.`in`)\n\tvar t:Int = reader.nextInt()\n\tvar x:Int = reader.nextInt()\n\tvar y:Int = reader.nextInt()\n\tvar ans = 0\n\tfor(i in 0..t){\n\t\tif(i+1 <= x && i+2 <= y){\n\t\t\tans = 3 * i + 3\n\t\t}\n\t}\n\tprintln(\"$ans\")\t\n}"}, {"source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n \tvar score = 6\n val input = Scanner(System.`in`)\n val a = input.nextInt()\n val b = input.nextInt()\n val c = input.nextInt()\n for (i in 2..999){\n if(i <= a && i+1 <= b && i+2 <= c)\n \tscore = score+3\n else break\n }\n println(score)\n}"}, {"source_code": "import kotlin.math.min\nfun main(args: Array) {\n val (y, b, r) = readLine()!!.split(' ').map(String::toInt)\n println(min(y + 2, min(b + 1, r)) * 3 - 3)\n}\n\n"}, {"source_code": "import kotlin.math.min\n\nfun main() {\n val (a, b, c) = readLine()!!.split(\" \").map{ it.toInt() }\n val answer = min(min(a, b - 1), c - 2) * 3 + 3\n println(answer)\n}"}, {"source_code": "import com.sun.org.apache.xpath.internal.operations.Bool\nimport jdk.nashorn.internal.runtime.ScriptingFunctions.readLine\nimport java.util.Scanner\nfun max(a:Int,b:Int):Int\n{\n if(a<=b)return a\n else return b\n}\nfun main(args: Array)\n{\n val read= Scanner(System.`in`)\n var c=Array(4,{it ->0})\n var maxn:Int\n maxn=1000000\n for(i in 1..3){\n c[i]=read.nextInt()\n c[i]=c[i]-i+1\n maxn =max(c[i],maxn)\n }\n\n println(3*maxn+3)\n}\n\n"}, {"source_code": "fun main(args: Array){\n var i = 2\n var min = Int.MAX_VALUE\n val nums = readLine()!!.split(\" \").map { s -> s.toInt() }\n if(nums[2]) {\nval reader = Scanner(System.`in`)\n var y:Int = reader.nextInt()\n var b:Int = reader.nextInt()\n var r:Int = reader.nextInt()\n var ans = r\n var t = r\n if(r-1>b)\n {\n ans=(b+b+1)\n t=b\n }\n else\n {\n ans=ans+(r-1)\n t=r-1\n }\n if(t-1>y)\n {\n ans=(3*y)+3\n }\n else\n {\n ans=ans+(t-1)\n }\n println(\"$ans\\n\")\n}\n/*\nfun main(args: Array) {\n var t = readLine()!!.toInt()\n var y = readLine()!!.toInt()\n var b = readLine()!!.toInt()\n var r = readLine()!!.toInt()\n var ans = r\n if(r-1>b)\n {\n ans=(b+b+1)\n t=b\n }\n else\n {\n ans=ans+b\n t=r-1\n }\n if(t-1>y)\n {\n ans=(3*y)+1\n }\n else\n {\n ans=ans+y\n }\n println(\"$ans\\n\")\n}\n*/"}, {"source_code": "import java.util.Scanner\nimport kotlin.math.min\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n //arrayOf(\"8\",\"13\",\"9\")\n val yellowOrnaments = sc.nextInt()\n val blueOrnaments = sc.nextInt()\n val redOrnaments = sc.nextInt()\n\n println(3 * min(yellowOrnaments, min(blueOrnaments, redOrnaments - 1) - 1) + 3)\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\n\n\nfun main(args: Array) {\n TaskA().solve()\n}\n\nabstract class Solver {\n internal val scanner = MyScanner()\n abstract fun solve()\n}\n\nclass TaskA : Solver() {\n override fun solve() {\n val y = scanner.nextInt()\n val b = scanner.nextInt()\n val r = scanner.nextInt()\n\n var nr = r\n while (nr-1 > b || nr -2 > y)\n nr--\n System.out.println(nr*3 - 3)\n }\n}\n\ninternal class MyScanner {\n private val `in` = BufferedReader(InputStreamReader(System.`in`))\n private var buffer: Array? = null\n private var pos = 0\n\n @Throws(IOException::class)\n fun nextInt(): Int {\n if (buffer == null) {\n buffer = `in`.readLine().split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n pos = 0\n }\n if (buffer!!.size <= pos) {\n buffer = `in`.readLine().split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n pos = 0\n }\n pos++\n return Integer.parseInt(buffer!![pos - 1])\n }\n\n @Throws(IOException::class)\n fun nextLong(): Long {\n if (buffer == null) {\n buffer = `in`.readLine().split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n pos = 0\n }\n if (buffer!!.size <= pos) {\n buffer = `in`.readLine().split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n pos = 0\n }\n pos++\n return (buffer!![pos - 1]).toLong()\n }\n\n @Throws(IOException::class)\n fun nextString(): String {\n if (buffer == null) {\n buffer = `in`.readLine().split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n pos = 0\n }\n if (buffer!!.size <= pos) {\n buffer = `in`.readLine().split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n pos = 0\n }\n pos++\n return buffer!![pos - 1]\n }\n\n @Throws(IOException::class)\n fun getIntList(n: Int): List {\n val result = mutableListOf()\n for (i in 0 until n)\n result.add(nextInt())\n return result\n }\n\n @Throws(IOException::class)\n fun getIntArray(n: Int): IntArray {\n val result = IntArray(n)\n for (i in 0 until n)\n result[i] = nextInt()\n return result\n }\n\n @Throws(IOException::class)\n fun getLongList(n: Int): List {\n val result = mutableListOf()\n for (i in 0 until n)\n result.add(nextLong())\n return result\n }\n\n @Throws(IOException::class)\n fun getLongArray(n: Int): LongArray {\n val result = LongArray(n)\n for (i in 0 until n)\n result[i] = nextLong()\n return result\n }\n\n @Throws(IOException::class)\n fun getStringList(n: Int): List {\n val result = mutableListOf()\n for (i in 0 until n)\n result.add(nextString())\n return result\n }\n\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\n\nval reader = BufferedReader(InputStreamReader(System.`in`))\nvar tokenizer = StringTokenizer(\"\")\n\n\nval token: String\n get() {\n while (!tokenizer.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer.nextToken()\n }\n\nfun readInt() = token.toInt()\n\nfun main() {\n PrintWriter(System.out).use { writer ->\n writer.solve()\n }\n}\n\nfun PrintWriter.solve() {\n val y = readInt()\n val b = readInt()\n val r = readInt()\n println(listOf(y, b - 1, r - 2).min()!! * 3 + 3)\n}"}, {"source_code": "fun main(args: Array) {\n\n val input = readLine()!!\n val values = input.split(\" \")\n println(Christmas(values[0].toInt(), values[1].toInt(), values[2].toInt()))\n\n}\n\nenum class Color {Blue,Red,Yellow}\n\nfun Christmas(yellowcolor:Int,bluecolor:Int,redcolor:Int):Int\n{\n if(yellowcolor==bluecolor && bluecolor==redcolor)\n return (yellowcolor-1)+yellowcolor+(yellowcolor-2)\n\n return when(if (yellowcolor <= bluecolor && yellowcolor <= redcolor)\n Color.Yellow\n else if (bluecolor <= redcolor && bluecolor <= yellowcolor)\n Color.Blue\n else\n Color.Red){\n Color.Yellow -> if(yellowcolor==bluecolor)\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n else if (redcolor==bluecolor && (redcolor+bluecolor)-(yellowcolor*2)<3)\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n else if (yellowcolor==redcolor)\n yellowcolor+(yellowcolor-2)+(yellowcolor-1)\n else if (bluecolor>redcolor && redcolor-yellowcolor==1)\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n\n\n else if(redcolor>bluecolor || redcolor==bluecolor ||(bluecolor>redcolor && (redcolor+bluecolor)-(yellowcolor*2)>3))\n yellowcolor+(yellowcolor+1)+(yellowcolor+2)\n\n else\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n\n Color.Blue-> if(bluecolor==redcolor)\n (bluecolor-2)+bluecolor+(bluecolor-1)\n else\n (bluecolor+1)+bluecolor+(bluecolor-1)\n else -> redcolor+(redcolor-2)+(redcolor-1)\n }\n\n\n}"}, {"source_code": "fun main()\n{\n val(a,b,c)=readLine()!!.split(' ').map(String::toInt)\n print(3*minOf(a+1,b,c-1))\n}"}, {"source_code": "import kotlin.math.min\n\nfun main() {\n val(y, b, r) = readLine()!!.split(\" \").map { it.toInt() }\n val n = min(y, min(b-1, r-2))\n println(3 * n + 3)\n}"}, {"source_code": "fun main() {\n val inputs = readLine()!!.split(\" \")\n val (yellow, blue, red) = inputs.map { it.toInt() }\n var result = 0\n\n inputs.forEachIndexed { index, input ->\n val _input = input.toInt()\n when (index) {\n 2 -> {\n if (_input - 1 <= blue && _input - 2 <= yellow) {\n result = _input * 3 - 3\n return@forEachIndexed\n }\n }\n 1 -> {\n if (_input + 1 <= red && _input - 1 <= yellow) {\n result = _input * 3\n return@forEachIndexed\n }\n }\n 0 -> {\n if (_input + 1 <= blue && _input + 2 <= red) {\n result = _input * 3 + 3\n return@forEachIndexed\n }\n }\n }\n }\n\n print(result)\n}"}, {"source_code": "//package b\n\nimport java.io.PrintWriter\nimport java.util.*\n\nfun solve() {\n val (y, b, r) = na()\n val u = Math.min(Math.min(y+1, b), r-1)\n out.println(u*3)\n}\n\nval out = PrintWriter(System.out)\n\nfun main(args: Array) {\n solve()\n out.flush()\n}\n\nfun nline() = readLine()!!\nfun ni() = nline().toInt()\nfun nl() = nline().toLong()\nfun nd() = nline().toDouble()\nfun nas() = nline().split(\" \")\nfun na() = nas().map { it.toInt() }\nfun nal() = nas().map { it.toLong() }\n\nfun tr(x: Any) = System.err.println(x)\nfun tr(x: IntArray) = System.err.println(Arrays.toString(x))\nfun tr(x: Array) = System.err.println(Arrays.deepToString(x))\n"}], "negative_code": [{"source_code": "fun main() {\n val balls = readLine()!!.split(Regex(\"\\\\s+\"), 3).map { it.toInt() }\n val min = balls.min()!!\n\n val max = when (min) {\n 1 -> 6\n balls[2] -> 3 * (min - 1)\n else -> 3 * min\n }\n println(\"$max\")\n}\n"}, {"source_code": "import java.util.*;\nimport kotlin.math.*;\n\nfun main() {\n val sc = Scanner(System.`in`);\n val a = sc.nextInt() ;\n val b = sc.nextInt() ;\n val c = sc.nextInt() ;\n val ans = minOf(a , b - 1 , c - 1) ;\n println(ans * 3 + 3) ;\n}"}, {"source_code": "fun main() {\n val s = readLine()!!\n val s2 = s.split(' ')\n var yellows = s2[0].toInt()\n var blues = s2[1].toInt()\n var reds = s2[2].toInt()\n\n if (yellows >= blues) {\n yellows -= (yellows - blues) + 1\n }\n if (blues != yellows + 1) {\n blues = yellows + 1\n }\n if (blues >= reds) {\n val diff = blues - reds\n blues -= diff + 1\n yellows -= diff + 2\n }\n if (reds != blues + 1) {\n reds = blues + 1\n }\n print(yellows + blues + reds)\n}\n "}, {"source_code": "fun main(args: Array) {\n val input = readLine()!!\n val values = input.split(\" \")\n println(Christmas(values[0].toInt(), values[1].toInt(), values[2].toInt()))\n}\n\nenum class Color {Blue,Red,Yellow}\n\nfun Christmas(yellowcolor:Int,bluecolor:Int,redcolor:Int):Int\n{\n if(yellowcolor==bluecolor && bluecolor==redcolor)\n return (yellowcolor-1)+yellowcolor+(yellowcolor-2)\n\n return when(if (yellowcolor <= bluecolor && yellowcolor <= redcolor)\n Color.Yellow\n else if (bluecolor <= redcolor && bluecolor <= yellowcolor)\n Color.Blue\n else\n Color.Red){\n Color.Yellow -> if(yellowcolor==bluecolor)\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n else if (redcolor==bluecolor && (redcolor+bluecolor)-(yellowcolor*2)<3)\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n\n else if(redcolor>bluecolor || redcolor==bluecolor ||(bluecolor>redcolor && (redcolor+bluecolor)-(yellowcolor*2)>3))\n yellowcolor+(yellowcolor+1)+(yellowcolor+2)\n\n else\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n\n Color.Blue-> (bluecolor+1)+bluecolor+(bluecolor-1)\n else -> redcolor+(redcolor-2)+(redcolor-1)\n }\n\n\n}"}, {"source_code": "\nimport java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n\n val line = nextLine().split(' ')\n val y = line[0].toInt()\n val b = line[1].toInt()\n val r = line[2].toInt()\n\n val min = min(y, min(b, r))\n val secondMin: Int\n var printVal = 0\n when (min) {\n r -> println(3 * r - 3)\n b -> {\n secondMin = min(y, r)\n when (secondMin) {\n r -> printVal =\n if (secondMin - min < 1)\n r - 1\n else\n b\n }\n println(printVal * 3)\n }\n y -> {\n secondMin = min(b, r)\n when (secondMin) {\n r -> printVal =\n if (secondMin - min < 2)\n r - 2\n else\n y\n b -> printVal =\n if (secondMin - min < 1)\n b - 1\n else\n y\n }\n println(printVal * 3 + 3)\n }\n\n }\n}"}, {"source_code": "fun main() {\n var a = readLine()!!.split(' ')!!.map(String::toInt)\n for (i in 0..2) println(a[i])\n println(minOf(a[0]+1,a[1],a[2]-1)*3)\n}"}, {"source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val yellowOrnaments = sc.nextInt()\n val blueOrnaments = sc.nextInt()\n\n var redOrnaments = sc.nextInt()\n\n repeat(redOrnaments - 3) {\n if (blueOrnaments >= redOrnaments - 1 && yellowOrnaments >= redOrnaments - 2) {\n println(redOrnaments - 2 + redOrnaments - 1 + redOrnaments)\n }\n redOrnaments -= 1\n }\n println(6)\n}"}, {"source_code": "fun main () {\n val (y, b, r) = readLine()!!.split(' ').map(String::toInt)\n val v = listOf(y, b, r)\n println(v.min()!! * 3)\n}"}, {"source_code": "fun main() {\n// val (y, b, r) = readLine()!!.split(\" \").map { it.toInt() }\n val (y, b, r) = \"8 13 9\".split(\" \").map { it.toInt() }\n // 4 5 6\n val py = Math.min(y, Math.min(b-1, r-2))\n println(py + py + py + 1 + 2)\n}"}, {"source_code": "fun main() {\n val balls = readLine()!!.split(Regex(\"\\\\s+\"), 3).map { it.toInt() }\n val min = balls.min()!!\n\n val max = when (min) {\n 1 -> 6\n balls[2] -> 3 * (min - 1)\n else -> 3 * min\n }\n println(\"$max\")\n}\n"}, {"source_code": "import java.io.*\nimport java.math.*\nimport java.text.*\nimport java.util.*\nimport java.util.regex.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val x = scan.nextInt()\n val y = scan.nextInt()\n val z = scan.nextInt()\n val ans1: Long = 0\n val ans2: Long = 0\n val ans3: Long = 0\n if(y>x &&z>y)\n print((x+1)*3)\n else if(z = readLine()?.split(\" \")?.map { it.toInt() }?.toList() ?: emptyList()\n\nfun s1() {\n val (y, b, r) = readInts()\n when {\n (r in (y..b) && (r-y <= 2)) || (y in r..b) || b in ((r+1) .. (y-1)) -> {\n println(r + (r-1) + (r-2))\n }\n b in y .. r || r in y .. b -> println(y + (y+1) + (y+2))\n else -> println(b + (b+1) + (b-1))\n }\n}\n\nfun main(args: Array) {\n //while (true) { s1() }\n s1()\n}"}, {"source_code": "fun main() {\n// println(calc(1, 2, 3) == 6)\n// println(calc(8, 13, 9) == 24)\n// println(calc(13, 3, 6) == 9)\n// println(calc(1, 3, 4) == 6)\n\n val (y, b, r) = readLine()!!.split(' ').map(String::toInt)\n print(calc(y, b, r))\n}\n\nfun calc(y: Int, b: Int, r: Int): Int {\n var y1 = y\n var b1 = b\n var r1 = r\n\n if (y + 1 == b && b + 1 == r)\n return y + b + r\n\n if (y >= r)\n y1 = r - 2\n\n when {\n b >= r -> b1 = r - 1\n b1 + 1 == r -> b1--\n else -> r1 = b1 + 1\n }\n\n when {\n b >= r -> b1 = r - 1\n b1 + 1 == r -> b1--\n else -> r1 = b1 + 1\n }\n\n if (y1 >= b1)\n y1 = b1 - 1\n\n return y1 + b1 + r1\n}"}, {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\nfun main(){\n B()\n}\n\nfun B(){\n val scanner=Scanner(System.`in`)\n val y=scanner.nextInt()\n val b=scanner.nextInt()\n val r=scanner.nextInt()\n val max=Math.max(Math.max(y,b),Math.max(b,y))\n val min=Math.min(Math.min(y,b),Math.min(b,y))\n var result=0\n if(min==y){\n result=y*3+3\n }else if(min==b){\n result=b*3\n }else if(min==r){\n result=r*3-3\n }else \n println(\"${result}\")\n}"}, {"source_code": "fun main() {\n var ybr = readLine()!!.split(' ').map { it.toInt() }\n\n println(MaxSum(ybr))\n}\n\nfun MaxSum(values: List): Int {\n var middle = values[values.size / 2]\n while (middle - 1 > values.first() && middle + 1 > values.last())\n middle -= 1\n\n return 3 * middle\n}"}, {"source_code": "import java.util.*\n\nfun main(args : Array) {\n val reader = Scanner(System.`in`)\n\n var y:Int\n var b:Int\n var r:Int\n\n var sum:Int\n y=reader.nextInt()\n b=reader.nextInt()\n r=reader.nextInt()\n\n r=when {\n b>r -> r\n r>b -> b+1\n else ->r\n }\n b=r-1\n y=b-1\n\n sum=r+b+y\n\n println(sum)\n\n\n}"}, {"source_code": "import java.util.*\n\nfun main(args : Array) {\n val reader = Scanner(System.`in`)\n\n var y:Int\n var b:Int\n var r:Int\n\n var sum:Int\n y=reader.nextInt()\n b=reader.nextInt()\n r=reader.nextInt()\n\n r=when {\n b>r -> r\n r>b -> b+1\n else ->r\n }\n b=r-1\n y=b-1\n\n sum=r+b+y\n\n println(sum)\n\n\n}"}, {"source_code": "\n\nfun main(){\n fun readLn() = readLine()!!\n fun readStrings(delim: Char = ' ') = readLn().split(delim)\n fun readInts() = readStrings().map { it.toInt() }\n\n val (y,b,r) = readInts()\n\n println(Math.max(y,Math.max(b-1,r-2)))\n\n}"}, {"source_code": "/**\nAlice and Bob are decorating a Christmas Tree.\n\nAlice wants only 3 types of ornaments to be used on the Christmas Tree: yellow, blue and red. They have 𝑦 yellow ornaments, 𝑏 blue ornaments and 𝑟 red ornaments.\n\nIn Bob's opinion, a Christmas Tree will be beautiful if:\n\nthe number of blue ornaments used is greater by exactly 1 than the number of yellow ornaments, and\nthe number of red ornaments used is greater by exactly 1 than the number of blue ornaments.\nThat 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).\n\nAlice wants to choose as many ornaments as possible, but she also wants the Christmas Tree to be beautiful according to Bob's opinion.\n\nIn 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.\nThat is the maximum number.\n\nSince 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\nthat can be used in their beautiful Christmas Tree!\n\nIt is guaranteed that it is possible to choose at least 6 (1+2+3=6) ornaments.\n\nInput\nThe only line contains three integers 𝑦, 𝑏, 𝑟 (1≤𝑦≤100, 2≤𝑏≤100, 3≤𝑟≤100) — the number of yellow, blue and red ornaments.\n\nIt is guaranteed that it is possible to choose at least 6 (1+2+3=6) ornaments.\n\nOutput\nPrint one number — the maximum number of ornaments that can be used.\n */\nfun main(args: Array) {\n println(24 == christmasOrnament(mutableListOf(8, 13, 9)))\n println(9 == christmasOrnament(mutableListOf(13, 3, 6)))\n println(30 == christmasOrnament(mutableListOf(10, 12, 20)))\n println(6 == christmasOrnament(mutableListOf(6, 12, 3)))\n}\n\nfun christmasOrnament(orns: MutableList): Int {\n var blue = if (orns[1] > orns[2]) orns[2] - 1 else orns[1]\n return (blue downTo 0).firstOrNull { it in 0..orns[2] && it in 0..orns[0] }?.let { it * 3 } ?: 6\n}"}, {"source_code": "fun main() {\n readLine()!!.split(' ').mapIndexed { index, s -> s.toInt() - index }.min()!!.toInt() * 3 + 3\n}"}, {"source_code": "fun main() {\n var (y, b, r) = readLine()!!.split(' ').map(String::toInt)\n println(\"${3 * minOf(y, minOf(b, r))}\")\n}"}, {"source_code": "fun getOrnamentNumber(b: Int, r: Int): Int {\n if (b != 0) {\n return (b - 1) + b + (b + 1)\n }\n if (r != 0) {\n return (r - 2) + (r - 1) + r\n }\n\n return 0\n}\n\nfun findOrnamentNumber(y: Int, b: Int, r: Int): Int {\n return when (maxOf(y, b, r)) {\n y -> findOrnamentNumber(-1, b, r)\n b -> getOrnamentNumber(0, r)\n r -> getOrnamentNumber(b, 0)\n else -> 0\n }\n}\n\nfun main(args: Array) {\n\n\n var (strY, strB, strR) = readLine()!!.split(' ')\n\n val y = strY.toInt()\n val b = strB.toInt()\n val r = strR.toInt()\n\n print(findOrnamentNumber(y, b, r))\n\n}\n"}, {"source_code": "import java.util.Scanner;\n\nfun main(){\n val scanner=Scanner(System.`in`)\n val y=scanner.nextInt()\n val b=scanner.nextInt()\n val r=scanner.nextInt()\n val max=Math.max(Math.max(y,b),Math.max(b,y))\n val min=Math.min(Math.min(y,b),Math.min(b,y))\n var result=0\n if(min==r){\n result=r*3-3\n }else if(min==b){\n result=b*3\n }else if(min==y){\n result=y*3\n }\n println(\"${result}\")\n}"}, {"source_code": "\nfun main(args: Array) {\n\n val input = readLine()!!\n val values = input.split(\" \")\n println(Christmas(values[0].toInt(), values[1].toInt(), values[2].toInt()))\n\n}\n\nenum class Color {Blue,Red,Yellow}\n\nfun Christmas(yellowcolor:Int,bluecolor:Int,redcolor:Int):Int\n{\n if(yellowcolor==bluecolor && bluecolor==redcolor)\n return (yellowcolor-1)+yellowcolor+(yellowcolor-2)\n\n return when(if (yellowcolor <= bluecolor && yellowcolor <= redcolor)\n Color.Yellow\n else if (bluecolor <= redcolor && bluecolor <= yellowcolor)\n Color.Blue\n else\n Color.Red){\n Color.Yellow -> if(yellowcolor==bluecolor)\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n else if (redcolor==bluecolor && (redcolor+bluecolor)-(yellowcolor*2)<3)\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n else if (bluecolor>redcolor && redcolor-yellowcolor==1)\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n\n\n else if(redcolor>bluecolor || redcolor==bluecolor ||(bluecolor>redcolor && (redcolor+bluecolor)-(yellowcolor*2)>3))\n yellowcolor+(yellowcolor+1)+(yellowcolor+2)\n\n else\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n\n Color.Blue-> if(bluecolor==redcolor)\n (bluecolor-2)+bluecolor+(bluecolor-1)\n else\n (bluecolor+1)+bluecolor+(bluecolor-1)\n else -> redcolor+(redcolor-2)+(redcolor-1)\n }\n\n\n}"}, {"source_code": "fun main(args: Array) {\n\n var ligne = readLine()!!.toString()\n\n val parts = ligne.split(\" \")\n val v1 : Int =parts.get(0).toInt()\n val v2 : Int= parts.get(1).toInt()\n val v3 : Int = parts.get(2).toInt()\n\n var res : String = \"\";\n\n if(v1+1 <= v2 && v1+2<=v3){\n res = \"$v1 ${v1+1} ${v1+2}\"\n }\n\n if(v2+1 <= v3 && v2-1<=v1){\n res = \"${v2-1} ${v2} ${v2+1}\"\n }\n\n if(v3-1 <= v2 && v3-2<=v1){\n res = \"${v3-2} ${v3-1} ${v3}\"\n }\n println(\"$res\" )\n}"}, {"source_code": "fun main() {\n val (y, b, r) = readLine()!!.split(\" \").map { it.toInt() }\n\n val base = listOf(y - 2, b - 1, r).min()!!\n\n val result = base * 3 - 3\n\n println(result)\n}"}, {"source_code": "fun main() {\n val balls = readLine()!!.split(Regex(\"\\\\s+\"), 3).map { it.toInt() }\n val min = balls.min()!!\n\n val max = when (min) {\n 1 -> 6\n balls[2] -> 3 * (min - 1)\n else -> 3 * min\n }\n println(\"$max\")\n}\n"}, {"source_code": "fun main() {\n var a = readLine()!!.split(' ')!!.map(String::toInt)\n for (i in 0..2) println(a[i])\n println(minOf(a[0]+1,a[1],a[2]-1)*3)\n}"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n var yellow = 1\n var blue = 2\n var red = 3\n\n yellow = scanner.nextInt()\n blue = scanner.nextInt()\n red = scanner.nextInt()\n\n\n val summ = 0\n\n while ((blue != 1 + yellow || 1 + blue != red) && yellow + 2 != red) {\n\n if (yellow >= blue)\n yellow = blue - 1\n else if (yellow < blue)\n blue = yellow + 1\n\n if (blue >= red)\n blue = red - 1\n else if (blue < red)\n red = blue + 1\n\n }\n\n\n print(yellow + blue + red)\n}"}, {"source_code": "fun main(){\n fun readLn() = readLine()!!\n fun readStrings(delim: Char = ' ') = readLn().split(delim)\n fun readInts() = readStrings().map { it.toInt() }\n\n val (y,b,r) = readInts()\n\n println(3+3*Math.max(y,Math.max(b-1,r-2)))\n\n}"}, {"source_code": "fun getOrnamentNumber(y: Int, b: Int, r: Int): Int {\n\n if (y != 0) {\n return y + y + (1) + (y + 2)\n }\n if (b != 0) {\n return (b - 1) + b + (b + 1)\n }\n if (r != 0) {\n return (r - 2) + (r - 1) + r\n }\n\n return 0\n}\n\nfun findOrnamentNumber(y: Int, b: Int, r: Int): Int {\n return when (maxOf(y, b, r)) {\n y -> if (b > r) getOrnamentNumber(0, 0, r) else getOrnamentNumber(0, b, 0)\n\n b -> if (r > y) getOrnamentNumber(y, 0, 0) else getOrnamentNumber(0, 0, r)\n\n r -> if (y > b) getOrnamentNumber(0, b, 0) else getOrnamentNumber(y, 0, 0)\n\n else -> 0\n }\n}\n\nfun main(args: Array) {\n val (strY, strB, strR) = readLine()!!.split(' ')\n\n val y = strY.toInt()\n val b = strB.toInt()\n val r = strR.toInt()\n\n print(findOrnamentNumber(y, b, r))\n}"}, {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\nfun main(){\n B()\n}\n\nfun B(){\n val scanner=Scanner(System.`in`)\n val y=scanner.nextInt()\n val b=scanner.nextInt()\n val r=scanner.nextInt()\n val max=Math.max(Math.max(y,b),Math.max(b,y))\n val min=Math.min(Math.min(y,b),Math.min(b,y))\n var result=0\n if(min==y){\n result=y*3\n }else if(min==b){\n result=b*3\n }else if(min==r){\n result=r*3-3\n }\n println(\"${result}\")\n}"}, {"source_code": "import java.util.Scanner;\n\nfun main(){\n val scanner=Scanner(System.`in`)\n val y=scanner.nextInt()\n val b=scanner.nextInt()\n val r=scanner.nextInt()\n val max=Math.max(Math.max(y,b),Math.max(b,y))\n val min=Math.min(Math.min(y,b),Math.min(b,y))\n var result=0\n if(min==r){\n result=r*3-3\n }else if(min==b){\n result=b*3\n }else if(min==y){\n result=y*3\n }\n println(\"${result}\")\n}"}, {"source_code": "fun main(args: Array) {\n val (y, b, r) = readLine()!!.split(\" \").map(String::toInt)\n if (r - b <= 1) {\n if (r - b <= 1) {\n print(r * 3 - 3)\n } else {\n print(b * 3)\n }\n } else {\n if (b - y <= 1) {\n print(b * 3)\n } else {\n print(y * 3 + 3)\n }\n }\n}"}, {"source_code": "fun main() {\n var ybr = readLine()!!.split(' ').map { it.toInt() }\n\n println(MaxSum(ybr))\n}\n\nfun MaxSum(values: List): Int {\n var middle = values[values.size / 2]\n while (middle - 1 > values.first() && middle + 1 > values.last())\n middle -= 1\n\n return 3 * middle\n}"}, {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\nfun main(){\n B()\n}\n\nfun B(){\n val scanner=Scanner(System.`in`)\n val y=scanner.nextInt()\n val b=scanner.nextInt()\n val r=scanner.nextInt()\n val max=Math.max(Math.max(y,b),Math.max(b,y))\n val min=Math.min(Math.min(y,b),Math.min(b,y))\n var result=0\n if(min==y){\n result=y*3+3\n }else if(min==b){\n result=b*3\n }else if(min==r){\n result=r*3-3\n }\n println(\"${result}\")\n}"}, {"source_code": "fun main(args: Array) {\n val array = readLine()!!.split(' ').map(String::toInt)\n var minIndex = array.size - 1\n for (i: Int in array.size - 1 downTo 0) {\n if(array[i]) {\n val ybr = readLine()!!.split(\" \")\n val y = ybr[0].toInt()\n val b = ybr[1].toInt()\n val r = ybr[2].toInt()\n\n // if y is min\n if (y < b && b < r) {\n println(3 * (y + 1))\n } else if (y > b && b > r) {\n println(3 * (r - 1))\n } else {\n println(3 * b)\n }\n\n}"}, {"source_code": "import java.util.*\n\nfun main(args : Array) {\n val reader = Scanner(System.`in`)\n\n var y:Int\n var b:Int\n var r:Int\n\n var sum:Int\n y=reader.nextInt()\n b=reader.nextInt()\n r=reader.nextInt()\n\n r=when {\n b>r -> r\n r>b -> b+1\n else ->r\n }\n b=r-1\n y=b-1\n\n sum=r+b+y\n\n println(sum)\n\n\n}"}, {"source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n\n val reader = Scanner(System.`in`)\n var a:Int = reader.nextInt()\n var b:Int = reader.nextInt()\n var c:Int = reader.nextInt()\n var ans = a;\n if (ans) {\n val reader = Scanner(System.`in`)\n\n var y:Int\n var b:Int\n var r:Int\n\n var sum:Int\n y=reader.nextInt()\n b=reader.nextInt()\n r=reader.nextInt()\n\n r=when {\n b>r -> r\n r>b -> b+1\n else ->r\n }\n b=r-1\n y=b-1\n\n sum=r+b+y\n\n println(sum)\n\n\n}"}, {"source_code": "fun main(args: Array) {\n\n val input = readLine()!!\n val values = input.split(\" \")\n println(Christmas(values[0].toInt(), values[1].toInt(), values[2].toInt()))\n \n}\n\nenum class Color {Blue,Red,Yellow}\n\nfun Christmas(yellowcolor:Int,bluecolor:Int,redcolor:Int):Int\n{\n if(yellowcolor==bluecolor && bluecolor==redcolor)\n return (yellowcolor-1)+yellowcolor+(yellowcolor-2)\n\n return when(if (yellowcolor <= bluecolor && yellowcolor <= redcolor)\n Color.Yellow\n else if (bluecolor <= redcolor && bluecolor <= yellowcolor)\n Color.Blue\n else\n Color.Red){\n Color.Yellow -> if(yellowcolor==bluecolor)\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n else if (redcolor==bluecolor && (redcolor+bluecolor)-(yellowcolor*2)<3)\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n else if (bluecolor>redcolor && redcolor-yellowcolor==1)\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n\n\n else if(redcolor>bluecolor || redcolor==bluecolor ||(bluecolor>redcolor && (redcolor+bluecolor)-(yellowcolor*2)>3))\n yellowcolor+(yellowcolor+1)+(yellowcolor+2)\n\n else\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n\n Color.Blue-> (bluecolor+1)+bluecolor+(bluecolor-1)\n else -> redcolor+(redcolor-2)+(redcolor-1)\n }\n\n\n}"}, {"source_code": "fun getOrnamentNumber(b: Int, r: Int): Int {\n if (b != 0) {\n return (b - 1) + b + (b + 1)\n }\n if (r != 0) {\n return (r - 2) + (r - 1) + r\n }\n\n return 0\n}\n\nfun findOrnamentNumber(y: Int, b: Int, r: Int): Int {\n return when (maxOf(y, b, r)) {\n y -> findOrnamentNumber(-1, b, r)\n b -> getOrnamentNumber(0, r)\n r -> getOrnamentNumber(b, 0)\n else -> 0\n }\n}\n\nfun main(args: Array) {\n\n\n var (strY, strB, strR) = readLine()!!.split(' ')\n\n val y = strY.toInt()\n val b = strB.toInt()\n val r = strR.toInt()\n\n print(findOrnamentNumber(y, b, r))\n\n}\n"}, {"source_code": "fun readInts() : List = readLine()?.split(\" \")?.map { it.toInt() }?.toList() ?: emptyList()\n\nfun s1() {\n val (y, b, r) = readInts()\n when {\n (r in (y..b) && (r-y <= 2)) || (y in r..b) || b in ((r+1) .. (y-1)) -> {\n println(r + (r-1) + (r-2))\n }\n b in (y + 1)..r || r in (y+1)..b-> println(y + (y+1) + (y+2))\n else -> println(b + (b+1) + (b-1))\n }\n}\n\nfun main(args: Array) {\n //while (true) { s1() }\n s1()\n}"}, {"source_code": "\n\nfun main(){\n fun readLn() = readLine()!!\n fun readStrings(delim: Char = ' ') = readLn().split(delim)\n fun readInts() = readStrings().map { it.toInt() }\n\n val (y,b,r) = readInts()\n\n println(Math.max(y,Math.max(b-1,r-2)))\n\n}"}, {"source_code": "import kotlin.math.min\n\nfun main(args : Array) {\n\n val NT = 1//readLine()?.toInt() ?: 0\n\n for(test in 1..NT){\n val (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n val d = min(a, min(b - 1, c - 2))\n val ans = 3 * (d + 1)\n\n println(\"Case #$test: $ans\")\n\n }\n\n}\n"}, {"source_code": "import kotlin.math.min\n\nfun main(args : Array) {\n\n val NT = 1//readLine()?.toInt() ?: 0\n\n for(test in 1..NT){\n val (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n val d = min(a, min(b - 1, c - 2))\n val ans = 3 * (d + 1)\n\n println(\"Case #$test: $ans\")\n\n }\n\n}\n"}, {"source_code": "fun main(){\n val (a, b,c) = readLine()!!.split(' ')\n var aa=a.toInt()\n var bb=b.toInt()\n var cc=c.toInt()\n \n var mi = minOf(aa,bb)\n mi=minOf(mi,cc)\n \n var res=0\n \n if(mi==aa)\n {\n var needb=aa+1\n var needc=needb+1\n if(needb>bb)\n {\n aa--;\n }\n if(needc>cc)\n {\n aa--;\n }\n res=aa*3+3\n }\n else if(mi==bb)\n {\n var needa=bb-1\n var needc=bb+1\n \n if(needc>cc)\n {\n needa--;\n }\n res=needa*3+3\n }\n else\n {\n var needb=cc-1\n var needa=needb-1\n res=needa*3+3\n }\n println(res)\n}"}, {"source_code": "fun main() {\n val data= readLine()!!.split(\" \").map { it.toInt() }\n println(data.min()?.times(3))\n}"}, {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\nfun main(){\n B()\n}\n\nfun B(){\n val scanner=Scanner(System.`in`)\n val y=scanner.nextInt()\n val b=scanner.nextInt()\n val r=scanner.nextInt()\n val max=Math.max(Math.max(y,b),Math.max(b,y))\n val min=Math.min(Math.min(y,b),Math.min(b,y))\n var result=0\n if(min==y){\n result=y*3\n }else if(min==b){\n result=b*3\n }else if(min==r){\n result=r*3-3\n }\n println(\"${result}\")\n}"}, {"source_code": "fun main() {\n val inputs = readLine()!!.split(\" \")\n val (yellow, blue, red) = inputs.map { it.toInt() }\n var result = 0\n\n inputs.forEachIndexed { index, input ->\n val _input = input.toInt()\n when (index) {\n 3 -> {\n if (_input - 1 <= blue && _input - 2 <= yellow) {\n result = _input * 3 - 3\n return@forEachIndexed\n }\n }\n 2 -> {\n if (_input + 1 <= red && _input - 1 <= yellow) {\n result = _input * 3\n return@forEachIndexed\n }\n }\n 1 -> {\n if (_input + 1 <= blue && _input + 2 <= red) {\n result = _input * 3 + 3\n return@forEachIndexed\n }\n }\n }\n }\n\n print(result)\n}"}, {"source_code": "\nimport java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n\n val line = nextLine().split(' ')\n val y = line[0].toInt()\n val b = line[1].toInt()\n val r = line[2].toInt()\n\n val min = min(y, min(b, r))\n val secondMin: Int\n var printVal = 0\n when (min) {\n r -> println(3 * r - 3)\n b -> {\n secondMin = min(y, r)\n when (secondMin) {\n r -> printVal =\n if (secondMin - min < 1)\n r - 1\n else\n b\n }\n println(printVal * 3)\n }\n y -> {\n secondMin = min(b, r)\n when (secondMin) {\n r -> printVal =\n if (secondMin - min < 2)\n r - 2\n else\n y\n b -> printVal =\n if (secondMin - min < 1)\n b - 1\n else\n y\n }\n println(printVal * 3 + 3)\n }\n\n }\n}"}, {"source_code": "fun main(args: Array) {\n val array = readLine()!!.split(' ').map(String::toInt)\n var minIndex = array.size - 1\n for (i: Int in array.size - 1 downTo 0) {\n if(array[i] 1) correction += drb - 1\n if (dry > 2) correction += dry - 1\n\n print(3 * (r - correction - 1))\n}"}, {"source_code": "fun main() {\n var ybr = readLine()!!.split(' ').map { it.toInt() }\n val minIndex = ybr.lastIndexOf(ybr.min())\n\n when (minIndex) {\n 0 -> println(3 * ybr[minIndex] + 3)\n 1 -> println(3 * ybr[minIndex])\n 2 -> println(3 * ybr[minIndex] - 3)\n }\n}"}, {"source_code": "fun main() {\n val inputs = readLine()!!.split(\" \")\n val (yellow, blue, red) = inputs.map { it.toInt() }\n var result = 0\n\n inputs.forEachIndexed { index, input ->\n val _input = input.toInt()\n when (index) {\n 3 -> {\n if (_input - 1 <= blue && _input - 2 <= yellow) {\n result = _input * 3 - 3\n return@forEachIndexed\n }\n }\n 2 -> {\n if (_input + 1 <= red && _input - 1 <= yellow) {\n result = _input * 3\n return@forEachIndexed\n }\n }\n 1 -> {\n if (_input + 1 <= blue && _input + 2 <= red) {\n result = _input * 3 + 3\n return@forEachIndexed\n }\n }\n }\n }\n\n print(result)\n}"}, {"source_code": "fun main(){\n fun readLn() = readLine()!!\n fun readStrings(delim: Char = ' ') = readLn().split(delim)\n fun readInts() = readStrings().map { it.toInt() }\n\n val (y,b,r) = readInts()\n\n println(3+3*Math.max(y,Math.max(b-1,r-2)))\n\n}"}, {"source_code": "private var Y: Int = 0\nprivate var B: Int = 1\nprivate var R: Int = 2\nfun main() {\n println(countOrnaments(readLine()?.split(\" \")?.map{ it.toInt() }!!))\n}\n\nprivate fun countOrnaments(nums: List): Int {\n for (r in nums[R] downTo 0) {\n if (nums[B] >= (r - 1) && nums[Y] >= (r - 1))\n return ((3 * r) - 3)\n }\n return -1\n}"}, {"source_code": "fun main() {\n val min = readLine()!!.split(Regex(\"\\\\s+\"), 3).map { it.toInt() }.min()\n\n println(\"${min!! * 3}\")\n}\n"}, {"source_code": "import java.util.*\n\nfun main(args : Array) {\n val reader = Scanner(System.`in`)\n\n var y:Int\n var b:Int\n var r:Int\n\n var sum:Int\n y=reader.nextInt()\n b=reader.nextInt()\n r=reader.nextInt()\n\n r=if(b>r) r else Math.min(r,b)+1\n b=r-1\n y=b-1\n\n sum=r+b+y\n\n println(sum)\n\n\n}"}, {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\nfun main(){\n B()\n}\n\nfun B(){\n val scanner=Scanner(System.`in`)\n val y=scanner.nextInt()\n val b=scanner.nextInt()\n val r=scanner.nextInt()\n val max=Math.max(Math.max(y,b),Math.max(b,y))\n val min=Math.min(Math.min(y,b),Math.min(b,y))\n var result=0\n if(min==y){\n result=y*3\n }else if(min==r){\n result=r*3-3\n }else if(min==b){\n result=b*3\n }\n println(\"${result}\")\n}"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n var yellow = 0\n var blue = 0\n var red = 0\n\n yellow = scanner.nextInt()\n blue = scanner.nextInt()\n red = scanner.nextInt()\n\n\n val summ = 0\n\n while (blue != 1 + yellow && yellow + 2 != red) {\n\n if (yellow >= blue)\n yellow = blue - 1\n else if (yellow < blue)\n blue = yellow + 1\n\n if (blue >= red)\n blue = red - 1\n else if (blue < red)\n red = blue + 1\n\n }\n\n\n print(yellow + blue + red)\n}"}, {"source_code": "import kotlin.math.max\n\nfun main() {\n val (a, b, c) = readLine()!!.split(\" \").map{ it.toInt() }\n val answer = max(max(a, b - 1), c - 2) * 3 + 3\n println(answer)\n}"}, {"source_code": "import kotlin.math.min\n\nfun main() {\n ornaments()\n}\n\nval mins = mapOf(\n 2 to 1,\n 3 to 1,\n 4 to 1,\n 5 to 1,\n 6 to 1,\n 7 to 1,\n 8 to 2,\n 9 to 2,\n 10 to 2,\n 11 to 2,\n 12 to 2,\n 13 to 2,\n 14 to 2,\n 15 to 3,\n 16 to 3,\n 17 to 3,\n 18 to 3,\n 19 to 3,\n 20 to 3,\n 21 to 3,\n 22 to 4,\n 23 to 4,\n 24 to 4,\n 25 to 4,\n 26 to 4,\n 27 to 4,\n 28 to 4,\n 29 to 5,\n 30 to 5,\n 31 to 5,\n 32 to 5,\n 33 to 5,\n 34 to 5,\n 35 to 5,\n 36 to 6,\n 37 to 6,\n 38 to 6,\n 39 to 6,\n 40 to 6,\n 41 to 6,\n 42 to 6,\n 43 to 7,\n 44 to 7,\n 45 to 7,\n 46 to 7,\n 47 to 7,\n 48 to 7,\n 49 to 7,\n 50 to 8,\n 51 to 8,\n 52 to 8,\n 53 to 8,\n 54 to 8,\n 55 to 8,\n 56 to 8,\n 57 to 9,\n 58 to 9,\n 59 to 9,\n 60 to 9,\n 61 to 9,\n 62 to 9,\n 63 to 9,\n 64 to 10,\n 65 to 10,\n 66 to 10,\n 67 to 10,\n 68 to 10,\n 69 to 10,\n 70 to 10,\n 71 to 11,\n 72 to 11,\n 73 to 11,\n 74 to 11,\n 75 to 11,\n 76 to 11,\n 77 to 11,\n 78 to 12,\n 79 to 12,\n 80 to 12,\n 81 to 12,\n 82 to 12,\n 83 to 12,\n 84 to 12,\n 85 to 13,\n 86 to 13,\n 87 to 13,\n 88 to 13,\n 89 to 13,\n 90 to 13,\n 91 to 13,\n 92 to 14,\n 93 to 14,\n 94 to 14,\n 95 to 14,\n 96 to 14,\n 97 to 14,\n 98 to 14,\n 99 to 15,\n 100 to 15\n)\n\nfun diceRolling() {\n// val units = listOf(7, 6, 5, 4, 3, 2)\n val inputCount = readLine()!!.toInt()\n\n for (i in 0 until inputCount) {\n println(mins[readLine()!!.toInt()])\n }\n\n// (2..100).forEach {\n// println(\"$it to ${compute(it, units)}\")\n// }\n}\n\n//fun compute(target: Int, units: List): Int {\n// if (target in units) return 1\n// if (target == units.max()!! + 1) return 2\n// return 1 + compute(target - units.max()!!, units)\n//}\n\nfun ornaments() {\n val rgb = readLine()!!.split(' ').map(String::toInt).take(3)\n println(min(min(rgb[0], rgb[1] - 1), rgb[2] - 2))\n}\n"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n var yellow = 0\n var blue = 0\n var red = 0\n\n yellow = scanner.nextInt()\n blue = scanner.nextInt()\n red = scanner.nextInt()\n\n\n val summ = 0\n\n while (blue != 1 + yellow && yellow + 2 != red) {\n\n if (yellow >= blue)\n yellow = blue - 1\n else if (yellow < blue)\n blue = yellow + 1\n\n if (blue >= red)\n blue = red - 1\n else if (blue < red)\n red = blue + 1\n\n }\n\n\n print(yellow + blue + red)\n}"}, {"source_code": "fun main(args: Array) {\n val array = readLine()!!.split(' ').map(String::toInt)\n var minIndex = array.size - 1\n for (i: Int in array.size - 1 downTo 0) {\n if(array[i] findOrnamentNumber(-1, b, r)\n b -> getOrnamentNumber(0, r)\n r -> getOrnamentNumber(b, 0)\n else -> 0\n }\n}\n\nfun main(args: Array) {\n\n\n var (strY, strB, strR) = readLine()!!.split(' ')\n\n val y = strY.toInt()\n val b = strB.toInt()\n val r = strR.toInt()\n\n print(findOrnamentNumber(y, b, r))\n\n}\n"}, {"source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n \n val read=Scanner(System.`in`) \n var a=read.nextInt()\n var b=read.nextInt()\n var c=read.nextInt()\n \n while(true) {\n \n if((a+1<=b) and (a+2<=c))\n { \n println(\"${3*b}\") \n return\n } \n a--\n }\n}"}, {"source_code": "fun main() {\n var arr = readLine()?.split(' ')?.map { e -> Integer.parseInt(e) }\n\n if(arr != null) {\n var min = Math.min(Math.min(arr[0], arr[1]), arr[2])\n\n if (min == arr[1])\n min--\n\n if (min +1 == arr[2])\n min--\n\n println(min*3 + 3)\n }\n}\n"}, {"source_code": "import java.util.Scanner;\n\nfun main(){\n val scanner=Scanner(System.`in`)\n val y=scanner.nextInt()\n val b=scanner.nextInt()\n val r=scanner.nextInt()\n val max=Math.max(Math.max(y,b),Math.max(b,y))\n val min=Math.min(Math.min(y,b),Math.min(b,y))\n println(\"${min*3}\")\n}"}, {"source_code": "import java.io.*\nimport java.math.*\nimport java.text.*\nimport java.util.*\nimport java.util.regex.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val x = scan.nextInt()\n val y = scan.nextInt()\n val z = scan.nextInt()\n val ans1: Long = 0\n val ans2: Long = 0\n val ans3: Long = 0\n if(y>x &&z>y)\n print((x+1)*3)\n else if(z) {\n val (y, b, r) = readLine()!!.split(\" \").map(String::toInt)\n if (r - y >= 1) {\n if (r - b <= 1) {\n print(r * 3 - 3)\n } else {\n print(b * 3)\n }\n } else {\n if (b - y <= 1) {\n print(b * 3)\n } else {\n print(y * 3 + 3)\n }\n }\n}"}, {"source_code": "import java.util.Scanner;\n\nfun main(){\n val scanner=Scanner(System.`in`)\n val y=scanner.nextInt()\n val b=scanner.nextInt()\n val r=scanner.nextInt()\n val max=Math.max(Math.max(y,b),Math.max(b,y))\n val min=Math.min(Math.min(y,b),Math.min(b,y))\n var result=0\n if(min==r){\n result=r*3-3\n }else if(min==b){\n result=b*3\n }else if(min==y){\n result=y*3\n }\n println(\"${result}\")\n}"}, {"source_code": "import java.util.*\nimport java.io.*\nimport java.math.*\n\n\nfun main(args : Array) {\n val input = Scanner(System.`in`)\n var y = input.nextInt()\n var b = input.nextInt()\n var r = input.nextInt()\n if (b >= r) {\n b = r - 1\n }\n if (y >= b) {\n y = b - 1\n }\n if (r > b) {\n r = b + 1\n }\n\n System.err.printf(\"%d %d %d\\n\", y, b, r)\n println(y + b + r)\n}"}, {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\nfun main(){\n B()\n}\n\nfun B(){\n val scanner=Scanner(System.`in`)\n val y=scanner.nextInt()\n val b=scanner.nextInt()\n val r=scanner.nextInt()\n val max=Math.max(Math.max(y,b),Math.max(b,r))\n val min=Math.min(Math.min(y,b),Math.min(b,r))\n val avg=y+b+r-min-max\n var result=0\n if(min==r){\n result=y*3-3\n }else if(min==b){\n result=b*3\n }else if(min==y){\n if(b) {\n\n// val str = \"8 13 9\"\n// val str =\"13 3 6\"\n// val str =\"3 5 66\"\n val str= readLine()!!\n val ar = str.split(\" \")\n val y=ar[0].toInt()\n val b=ar[1].toInt()\n val r=ar[2].toInt()\n\n if (r<=y+2 && r<=b+1) {\n println(r*3-3)\n }\n\n if (b<=r-1 && b<=y+1) {\n println(b*3)\n }\n\n if (y<=b-1 && y<=r-2) {\n println(y*3+3)\n }\n}"}, {"source_code": "fun main(args: Array) {\n val (y, b, r) = readLine()!!.split(\" \").map(String::toInt)\n if (r - b <= 1) {\n if (r - b <= 1) {\n print(r * 3 - 3)\n } else {\n print(b * 3)\n }\n } else {\n if (b - y <= 1) {\n print(b * 3)\n } else {\n print(y * 3 + 3)\n }\n }\n}"}, {"source_code": "fun main() {\n val (a, b, c) = readLine()!!.split(\" \").map(String::toInt)\n val d = maxOf(a, b - 1, c - 2)\n println(d*3)\n}"}, {"source_code": "fun main() {\n var ybr = readLine()!!.split(' ').map { it.toInt() }\n\n println(MaxSum(ybr))\n}\n\nfun MaxSum(values: List): Int {\n var middle = values[values.size / 2]\n while (middle - 1 > values.first() && middle + 1 > values.last())\n middle -= 1\n\n return 3 * middle\n}"}, {"source_code": "\nfun main() {\n print( ProblemB(ProblemB.readInput()).solve() )\n\n}\n\n\nclass ProblemB (triple: Triple) {\n\n val yellow = triple.first\n val blue = triple.second\n val red = triple.third\n\n companion object {\n fun readInput() : Triple {\n val line = readLine()\n var values : List = line!!.split(\" \").map { it.toInt() }\n println (values)\n return Triple(values[0], values[1], values[2])\n }\n }\n\n fun solve() : Int {\n return solution(blue)\n }\n\n private fun solution(value: Int): Int {\n return if (yellow >= value - 1 && red >= value + 1) {\n value * 3\n } else\n solution(value - 1)\n }\n}\n"}, {"source_code": "import java.util.*\nimport java.io.*\nimport java.math.*\n\n\nfun main(args : Array) {\n val input = Scanner(System.`in`)\n var y = input.nextInt()\n var b = input.nextInt()\n var r = input.nextInt()\n if (b >= r) {\n b = r - 1\n }\n if (y >= b) {\n y = b - 1\n }\n if (r > b) {\n r = b + 1\n }\n\n System.err.printf(\"%d %d %d\\n\", y, b, r)\n println(y + b + r)\n}"}, {"source_code": "import java.lang.Math.max\nimport java.lang.Math.min\nimport java.util.Scanner\n\nfun main()\n{\n val reader = Scanner(System.`in`)\n\n var y = reader.nextInt()\n var b = reader.nextInt()\n var r = reader.nextInt()\n var ans = max(y,b-1)\n ans = max(r-2,ans)\n ans = ans*3 + 3;8\n println(ans)\n\n\n}"}, {"source_code": "fun main(args: Array) {\n\n val input = readLine()!!\n val values = input.split(\" \")\n println(Christmas(values[0].toInt(), values[1].toInt(), values[2].toInt()))\n\n}\n\nenum class Color {Blue,Red,Yellow}\n\nfun Christmas(yellowcolor:Int,bluecolor:Int,redcolor:Int):Int\n{\n if(yellowcolor==bluecolor && bluecolor==redcolor)\n return (yellowcolor-1)+yellowcolor+(yellowcolor-2)\n\n return when(if (yellowcolor <= bluecolor && yellowcolor <= redcolor)\n Color.Yellow\n else if (bluecolor <= redcolor && bluecolor <= yellowcolor)\n Color.Blue\n else\n Color.Red){\n Color.Yellow -> if(yellowcolor==bluecolor)\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n else if(redcolor>bluecolor || redcolor==bluecolor ||(bluecolor>redcolor && (redcolor+bluecolor)-(yellowcolor*2)>3))\n yellowcolor+(yellowcolor+1)+(yellowcolor+2)\n \n else\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n\n Color.Blue-> (bluecolor+1)+bluecolor+(bluecolor-1)\n else -> redcolor+(redcolor-2)+(redcolor-1)\n }\n\n\n}"}, {"source_code": "import java.lang.Math.max\nimport java.lang.Math.min\nimport java.util.Scanner\n\nfun main()\n{\n val reader = Scanner(System.`in`)\n\n var y = reader.nextInt()\n var b = reader.nextInt()\n var r = reader.nextInt()\n var ans = max(y,b-1)\n ans = max(r-2,ans)\n ans = ans*3 + 3;8\n println(ans)\n\n\n}"}, {"source_code": "fun main(){\n fun readLn() = readLine()!!\n fun readStrings(delim: Char = ' ') = readLn().split(delim)\n fun readInts() = readStrings().map { it.toInt() }\n\n val (y,b,r) = readInts()\n\n println(3+3*Math.max(y,Math.max(b-1,r-2)))\n\n}"}, {"source_code": "fun main(args: Array) {\n\n val input = readLine()!!\n val values = input.split(\" \")\n println(Christmas(values[0].toInt(), values[1].toInt(), values[2].toInt()))\n\n}\n\nenum class Color {Blue,Red,Yellow}\n\nfun Christmas(yellowcolor:Int,bluecolor:Int,redcolor:Int):Int\n{\n if(yellowcolor==bluecolor && bluecolor==redcolor)\n return (yellowcolor-1)+yellowcolor+(yellowcolor-2)\n\n return when(if (yellowcolor <= bluecolor && yellowcolor <= redcolor)\n Color.Yellow\n else if (bluecolor <= redcolor && bluecolor <= yellowcolor)\n Color.Blue\n else\n Color.Red){\n Color.Yellow -> if(redcolor>bluecolor || redcolor==bluecolor )\n yellowcolor+(yellowcolor+1)+(yellowcolor+2)\n else if(bluecolor>redcolor && (redcolor+bluecolor)-(yellowcolor*2)>3)\n yellowcolor+(yellowcolor+1)+(yellowcolor+2)\n else\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n\n Color.Blue-> (bluecolor+1)+bluecolor+(bluecolor-1)\n else -> redcolor+(redcolor-2)+(redcolor-1)\n }\n\n\n}"}, {"source_code": "fun main(args: Array) {\n val ybr = readLine()!!.split(\" \")\n val y = ybr[0].toInt()\n val b = ybr[1].toInt()\n val r = ybr[2].toInt()\n\n // if y is min\n if (y < b && b < r) {\n println(3 * (y + 1))\n }\n\n // if b is min or equal y\n if (y >= b && b < r) {\n println(3 * b)\n }\n\n if (y >= b && b >= r) {\n print(3 * (r - 1))\n }\n}"}, {"source_code": "fun main () {\n val (y, b, r) = readLine()!!.split(' ').map(String::toInt)\n val v = listOf(y, b, r)\n var x = v.withIndex().minBy { (_, f) -> f }?.index\n x = v[x!!] + ((-x)+1)\n while (x >= b || x >= r) x--\n println(x * 3)\n}"}, {"source_code": "import java.util.Arrays;\nimport java.util.Scanner;\n\nfun main(){\n B()\n}\n\nfun B(){\n val scanner=Scanner(System.`in`)\n val y=scanner.nextInt()\n val b=scanner.nextInt()\n val r=scanner.nextInt()\n val max=Math.max(Math.max(y,b),Math.max(b,r))\n val min=Math.min(Math.min(y,b),Math.min(b,r))\n val avg=y+b+r-min-max\n var result=0\n if(min==r){\n result=y*3-3\n }else if(min==b){\n result=b*3\n }else if(min==y){\n if(b) {\nval reader = Scanner(System.`in`)\n var y:Int = reader.nextInt()\n var b:Int = reader.nextInt()\n var r:Int = reader.nextInt()\n var ans = r\n var t = r\n if(r-1>b)\n {\n ans=(b+b+1)\n t=b\n }\n else\n {\n ans=ans+(r-1)\n t=r-1\n }\n if(t-1>y)\n {\n ans=(3*y)+1\n }\n else\n {\n ans=ans+(t-1)\n }\n println(\"$ans\\n\")\n}\n/*\nfun main(args: Array) {\n var t = readLine()!!.toInt()\n var y = readLine()!!.toInt()\n var b = readLine()!!.toInt()\n var r = readLine()!!.toInt()\n var ans = r\n if(r-1>b)\n {\n ans=(b+b+1)\n t=b\n }\n else\n {\n ans=ans+b\n t=r-1\n }\n if(t-1>y)\n {\n ans=(3*y)+1\n }\n else\n {\n ans=ans+y\n }\n println(\"$ans\\n\")\n}\n*/"}, {"source_code": "import java.util.Scanner;\n\nfun main(){\n val scanner=Scanner(System.`in`)\n val y=scanner.nextInt()\n val b=scanner.nextInt()\n val r=scanner.nextInt()\n val max=Math.max(Math.max(y,b),Math.max(b,y))\n val min=Math.min(Math.min(y,b),Math.min(b,y))\n var result=0\n if(min==r){\n result=r*3-3\n }else if(min==b){\n result=b*3\n }else if(min==y){\n result=y*3\n }\n println(\"${result}\")\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n var (yellow, blue, red) = scan.nextLine().split(\" \").map { it.toInt() }\n while (red < blue + 1) {\n blue--\n }\n while (blue < yellow + 1) {\n yellow--\n }\n while (red > blue + 1) {\n red--\n }\n\n println(yellow + blue + red)\n}\n"}, {"source_code": "fun main(args: Array) {\n\n val input = readLine()!!\n val values = input.split(\" \")\n println(Christmas(values[0].toInt(), values[1].toInt(), values[2].toInt()))\n\n}\n\nenum class Color {Blue,Red,Yellow}\n\nfun Christmas(yellowcolor:Int,bluecolor:Int,redcolor:Int):Int\n{\n if(yellowcolor==bluecolor && bluecolor==redcolor)\n return (yellowcolor-1)+yellowcolor+(yellowcolor-2)\n\n return when(if (yellowcolor <= bluecolor && yellowcolor <= redcolor)\n Color.Yellow\n else if (bluecolor <= redcolor && bluecolor <= yellowcolor)\n Color.Blue\n else\n Color.Red){\n Color.Yellow -> if(redcolor>bluecolor || redcolor==bluecolor )\n yellowcolor+(yellowcolor+1)+(yellowcolor+2)\n else if(bluecolor>redcolor && (redcolor+bluecolor)-(yellowcolor*2)>3)\n yellowcolor+(yellowcolor+1)+(yellowcolor+2)\n else\n yellowcolor+(yellowcolor+1)+(yellowcolor-1)\n\n Color.Blue-> (bluecolor+1)+bluecolor+(bluecolor-1)\n else -> redcolor+(redcolor-2)+(redcolor-1)\n }\n\n\n}"}, {"source_code": "fun main( args : Array) {\n\n// val str = \"8 13 9\"\n// val str =\"13 3 6\"\n// val str =\"3 5 66\"\n val str= readLine()!!\n val ar = str.split(\" \")\n val y=ar[0].toInt()\n val b=ar[1].toInt()\n val r=ar[2].toInt()\n\n if (r<=y+2 && r<=b+1) {\n println(r*3-3)\n }\n\n if (b<=r-1 && b<=y+1) {\n println(b*3)\n }\n\n if (y<=b-1 && y<=r-2) {\n println(y*3+3)\n }\n}"}, {"source_code": "fun main() {\n\n val (a,b,c) = readLine()!!.split(' ').map(String::toInt)\n println(6 + 3*minOf(a, b-1, c-2))\n}"}, {"source_code": "fun main() {\n val balls = readLine()!!.split(\" \").map { it.toInt() }.toIntArray()\n balls[1]--\n balls[2] -= 2\n var min = balls.min()!!\n println(intArrayOf(min, (min + 1), (min + 2)).joinToString(\" \"))\n\n}\n"}, {"source_code": "\nfun main() {\n print( ProblemB(ProblemB.readInput()).solve() )\n\n}\n\n\nclass ProblemB (triple: Triple) {\n\n val yellow = triple.first\n val blue = triple.second\n val red = triple.third\n\n companion object {\n fun readInput() : Triple {\n val line = readLine()\n var values : List = line!!.split(\" \").map { it.toInt() }\n println (values)\n return Triple(values[0], values[1], values[2])\n }\n }\n\n fun solve() : Int {\n return solution(blue)\n }\n\n private fun solution(value: Int): Int {\n return if (yellow >= value - 1 && red >= value + 1) {\n value * 3\n } else\n solution(value - 1)\n }\n}\n"}, {"source_code": "fun main(args: Array) {\n val array = readLine()!!.split(' ').map(String::toInt)\n var minIndex = array.size - 1\n for (i: Int in array.size - 1 downTo 0) {\n if(array[i] {\n return Array(n, {_ -> nextToken()})\n}\n\nfun main(args: Array) {\n val n = nextInt()\n val a = readField(n)\n val b = readField(n)\n for (i in 0..1)\n for (j in 0..1)\n for (k in 0..3) {\n val cur = a.copyOf()\n if (i == 1) {\n for (l in cur.indices)\n cur[l] = cur[l].reversed()\n }\n\n if (j == 1) {\n cur.reverse()\n }\n\n for (l in 1..k) {\n val ncur = Array(n, {_ -> StringBuilder(cur[0])})\n for (x in 0 until n)\n for (y in 0 until n)\n ncur[n - y - 1][x] = cur[x][y]\n\n for (x in 0 until n)\n cur[x] = ncur[x].toString()\n }\n\n if (Arrays.equals(cur , b)) {\n return println(\"Yes\")\n }\n }\n\n println(\"No\")\n}"}], "negative_code": [], "src_uid": "2e793c9f476d03e8ba7df262db1c06e4"} {"nl": {"description": "The only difference between easy and hard versions is the constraints.Polycarp has to write a coursework. The coursework consists of $$$m$$$ pages.Polycarp also has $$$n$$$ cups of coffee. The coffee in the $$$i$$$-th cup has $$$a_i$$$ caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.Let's consider some day of Polycarp's work. Consider Polycarp drinks $$$k$$$ cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are $$$a_{i_1}, a_{i_2}, \\dots, a_{i_k}$$$. Then the first cup he drinks gives him energy to write $$$a_{i_1}$$$ pages of coursework, the second cup gives him energy to write $$$max(0, a_{i_2} - 1)$$$ pages, the third cup gives him energy to write $$$max(0, a_{i_3} - 2)$$$ pages, ..., the $$$k$$$-th cup gives him energy to write $$$max(0, a_{i_k} - k + 1)$$$ pages.If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.", "input_spec": "The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le 100$$$, $$$1 \\le m \\le 10^4$$$) — the number of cups of coffee and the number of pages in the coursework. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the caffeine dosage of coffee in the $$$i$$$-th cup.", "output_spec": "If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.", "sample_inputs": ["5 8\n2 3 1 1 2", "7 10\n1 3 4 2 1 4 2", "5 15\n5 5 5 5 5", "5 16\n5 5 5 5 5", "5 26\n5 5 5 5 5"], "sample_outputs": ["4", "2", "1", "2", "-1"], "notes": "NoteIn the first example Polycarp can drink fourth cup during first day (and write $$$1$$$ page), first and second cups during second day (and write $$$2 + (3 - 1) = 4$$$ pages), fifth cup during the third day (and write $$$2$$$ pages) and third cup during the fourth day (and write $$$1$$$ page) so the answer is $$$4$$$. It is obvious that there is no way to write the coursework in three or less days in this test.In the second example Polycarp can drink third, fourth and second cups during first day (and write $$$4 + (2 - 1) + (3 - 2) = 6$$$ pages) and sixth cup during second day (and write $$$4$$$ pages) so the answer is $$$2$$$. It is obvious that Polycarp cannot write the whole coursework in one day in this test.In the third example Polycarp can drink all cups of coffee during first day and write $$$5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15$$$ pages of coursework.In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write $$$5 + (5 - 1) + (5 - 2) + (5 - 3) = 14$$$ pages of coursework and during second day he will write $$$5$$$ pages of coursework. This is enough to complete it.In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1."}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nval MAX_N = (1e6 + 10).toInt()\nval INF = (1e9 + 7).toInt()\nval MOD = (1e9 + 7).toInt()\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val n = reader.nextInt()\n val m = reader.nextLong()\n val a = reader.nextArrayLong(n).sortedArrayDescending()\n writer.println(search(1, n, n, m, a))\n}\n\nfun search(l: Int, r: Int, n: Int, m: Long, a: LongArray): Int {\n if (l > r) {\n return -1\n }\n val x = (l + r) / 2\n if (check(x, n, m, a)) {\n val t = search(l, x - 1, n, m, a)\n return if (t != -1) t else x\n }\n return search(x + 1, r, n, m, a)\n}\n\nfun check(x: Int, n: Int, m: Long, a: LongArray): Boolean {\n val a1 = a.filterIndexed { i, v -> v >= i / x }\n val n1 = a1.size\n val k1 = n1 / x\n val r1 = n1 % x\n val count = a1.sum() - x * k1 * (k1 - 1) / 2 - k1 * r1\n return count >= m\n}\n\n\nclass InputReader(stream: InputStream) {\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n repeat(count) { a[it] = nextLong() }\n return a\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "import java.io.File\nimport java.util.*\n\nfun main() {\n// val scanner = Scanner(File(\"input.txt\"))\n val scanner = Scanner(System.`in`)\n\n val numberOfCups = scanner.nextInt()\n val numberOfPages = scanner.nextInt()\n val caffeineInput = Array(numberOfCups) { 0L }\n for (i in 0 until numberOfCups) {\n caffeineInput[i] = scanner.nextLong()\n }\n val caffeine = caffeineInput.sortedDescending().toTypedArray()\n\n for (targetNumberOfDays in 1..numberOfCups) {\n if (canWriteInNumberOfDays(targetNumberOfDays, numberOfCups, numberOfPages, caffeine)) {\n println(targetNumberOfDays)\n return\n }\n }\n println(-1)\n}\n\nfun canWriteInNumberOfDays(\n numberOfDays: Int,\n numberOfCups: Int,\n targetNumberOfPages: Int,\n caffeine: Array // Sorted by descending\n): Boolean {\n val maxNumberOfPages = calculateMaxNumberOfPages(numberOfDays, numberOfCups, caffeine)\n return maxNumberOfPages >= targetNumberOfPages\n}\n\nfun calculateMaxNumberOfPages(\n numberOfDays: Int,\n numberOfCups: Int,\n caffeine: Array\n): Long {\n var orderOfCup = 0L\n var numberOfPages = 0L\n for (i in 0 until numberOfCups) {\n numberOfPages += maxOf(caffeine[i] - orderOfCup, 0L)\n if (i % numberOfDays == numberOfDays - 1) ++orderOfCup\n }\n return numberOfPages\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main() {\n val tokenizer = BufferedReader(InputStreamReader(System.`in`)).use { StringTokenizer(it.readText()) }\n val n = tokenizer.nextInt()\n val m = tokenizer.nextInt()\n val a = Array(n) { tokenizer.nextInt() }.apply {\n sort()\n reverse()\n }\n if (a.sum() < m)\n println(\"-1\")\n else {\n var l = 1\n var r = n\n while (l < r) {\n val mid = (l + r) / 2\n if (check(a, m, mid))\n r = mid\n else\n l = mid + 1\n }\n println(l)\n }\n}\n\nfun check(a: Array, m: Int, d: Int): Boolean {\n var sum = 0\n for (i in 0 until a.size) {\n val debuff = i / d\n if (a[i] <= debuff)\n break\n sum += a[i] - debuff\n }\n return sum >= m\n}\n\nfun StringTokenizer.nextInt() = nextToken().toInt()\nfun StringTokenizer.nextLong() = nextToken().toLong()\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun solve() {\n val n = readInt()\n val m = readInt()\n val a = readInts()\n Arrays.sort(a)\n a.reverse()\n\n fun check(w : Int): Boolean {\n var ww = w\n var count = 0\n var ind = 1\n var nn = 0\n for (i in 0 until w)\n count += a[i]\n while (ww < n) {\n count += if (a[ww] - ind < 0) 0 else a[ww] - ind\n ww++\n nn++\n if (nn == w) {\n nn = 0\n ind++\n }\n }\n return count >= m\n }\n\n var left = 0\n var right = n\n while (right - left > 1) {\n var mid = (right + left) shr 1\n if (check(mid))\n right = mid\n else\n left = mid\n }\n\n out.println(if (check(right)) right else -1)\n}\n\nfun binmult(a : Long, b : Long, m : Long) : Long {\n if (a == 0L)\n return 0\n\n if (a % 2 == 1L) {\n val prev = binmult(a - 1, b, m)\n return (prev + b) % m\n } else {\n val half = binmult(a / 2, b, m)\n return (half + half) % m\n }\n}\n\nfun binpow(a: Long, n: Long, mod: Long): Long {\n var a = a\n var n = n\n var res: Long = 1\n while (n > 0) {\n if (n and 1 == 1L) {\n res = binmult(res, a, mod)\n res %= mod\n n--\n } else {\n a = binmult(a, a, mod)\n a %= mod\n n = n shr 1\n }\n }\n return res % mod\n}\n\ninline fun phi(n: Int): Int {\n var n = n\n var result = n\n var i = 2\n while (i * i <= n) {\n if (n % i == 0) {\n while (n % i == 0)\n n /= i;\n result -= result / i\n }\n ++i\n }\n if (n > 1)\n result -= result / n\n return result\n}\n\nvar out = PrintWriter(System.out)\nvar br = BufferedReader(InputStreamReader(System.`in`))\nvar st = StringTokenizer(\"\")\n\nfun main(args: Array) {\n solve()\n out.close()\n}\n\ninline fun readString(): String {\n if (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st.nextToken()\n}\n\ninline fun readLine() = br.readLine()\ninline fun readInt() = readString().toInt()\ninline fun readLong() = readString().toLong()\ninline fun readDouble() = readString().toDouble()\ninline fun readBool() = readString().toBoolean()\ninline fun readFloat() = readString().toFloat()\n\ninline fun readInts() = readLine().split(' ').map(String::toInt).toIntArray()"}], "negative_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nval MAX_N = (1e6 + 10).toInt()\nval INF = (1e9 + 7).toInt()\nval MOD = (1e9 + 7).toInt()\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val n = reader.nextInt()\n val m = reader.nextLong()\n val a = reader.nextArrayLong(n).sortedArrayDescending()\n writer.println(search(1, n, n, m, a))\n}\n\nfun search(l: Int, r: Int, n: Int, m: Long, a: LongArray): Int {\n if (l > r) {\n return -1\n }\n val x = (l + r) / 2\n if (check(x, n, m, a)) {\n val t = search(l, x - 1, n, m, a)\n return if (t != -1) t else x\n }\n return search(x + 1, r, n, m, a)\n}\n\nfun check(x: Int, n: Int, m: Long, a: LongArray): Boolean {\n val a1 = a.filter { it >= n / x }\n val n1 = a1.size\n val k1 = n1 / x\n val r1 = n1 % x\n val count = a1.sum() - x * k1 * (k1 - 1) / 2 - k1 * r1\n return count >= m\n}\n\n\nclass InputReader(stream: InputStream) {\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n repeat(count) { a[it] = nextLong() }\n return a\n }\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun solve() {\n val n = readInt()\n val m = readInt()\n val a = readInts()\n Arrays.sort(a)\n a.reverse()\n\n fun check(w : Int): Boolean {\n var w = w\n var count = 0\n var ind = 0\n for (i in 0 until w)\n count += a[i]\n while (w < n)\n count += if (a[w++] - ++ind < 0) 0 else a[w - 1] - ind\n\n return count >= m\n }\n\n var left = 0\n var right = n\n while (right - left > 1) {\n var mid = (right + left) shr 1\n if (check(mid))\n right = mid\n else\n left = mid\n }\n\n out.println(if (check(right)) right else -1)\n}\n\nfun binmult(a : Long, b : Long, m : Long) : Long {\n if (a == 0L)\n return 0\n\n if (a % 2 == 1L) {\n val prev = binmult(a - 1, b, m)\n return (prev + b) % m\n } else {\n val half = binmult(a / 2, b, m)\n return (half + half) % m\n }\n}\n\nfun binpow(a: Long, n: Long, mod: Long): Long {\n var a = a\n var n = n\n var res: Long = 1\n while (n > 0) {\n if (n and 1 == 1L) {\n res = binmult(res, a, mod)\n res %= mod\n n--\n } else {\n a = binmult(a, a, mod)\n a %= mod\n n = n shr 1\n }\n }\n return res % mod\n}\n\ninline fun phi(n: Int): Int {\n var n = n\n var result = n\n var i = 2\n while (i * i <= n) {\n if (n % i == 0) {\n while (n % i == 0)\n n /= i;\n result -= result / i\n }\n ++i\n }\n if (n > 1)\n result -= result / n\n return result\n}\n\nvar out = PrintWriter(System.out)\nvar br = BufferedReader(InputStreamReader(System.`in`))\nvar st = StringTokenizer(\"\")\n\nfun main(args: Array) {\n solve()\n out.close()\n}\n\ninline fun readString(): String {\n if (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st.nextToken()\n}\n\ninline fun readLine() = br.readLine()\ninline fun readInt() = readString().toInt()\ninline fun readLong() = readString().toLong()\ninline fun readDouble() = readString().toDouble()\ninline fun readBool() = readString().toBoolean()\ninline fun readFloat() = readString().toFloat()\n\ninline fun readInts() = readLine().split(' ').map(String::toInt).toIntArray()"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun solve() {\n val n = readInt()\n val m = readInt()\n val a = readInts()\n Arrays.sort(a)\n a.reverse()\n\n fun check(w : Int): Boolean {\n var w = w\n var count = 0\n var ind = 0\n for (i in 0 until w)\n count += a[i]\n while (w < n)\n count += if (a[w++] - ++ind < 0) 0 else a[w - 1] - ind\n\n return count >= m\n }\n\n var left = 0\n var right = n - 1\n while (right - left > 1) {\n var mid = (right + left) shr 1\n if (check(mid))\n right = mid\n else\n left = mid\n }\n\n out.println(if (check(right)) right else -1)\n}\n\nfun binmult(a : Long, b : Long, m : Long) : Long {\n if (a == 0L)\n return 0\n\n if (a % 2 == 1L) {\n val prev = binmult(a - 1, b, m)\n return (prev + b) % m\n } else {\n val half = binmult(a / 2, b, m)\n return (half + half) % m\n }\n}\n\nfun binpow(a: Long, n: Long, mod: Long): Long {\n var a = a\n var n = n\n var res: Long = 1\n while (n > 0) {\n if (n and 1 == 1L) {\n res = binmult(res, a, mod)\n res %= mod\n n--\n } else {\n a = binmult(a, a, mod)\n a %= mod\n n = n shr 1\n }\n }\n return res % mod\n}\n\ninline fun phi(n: Int): Int {\n var n = n\n var result = n\n var i = 2\n while (i * i <= n) {\n if (n % i == 0) {\n while (n % i == 0)\n n /= i;\n result -= result / i\n }\n ++i\n }\n if (n > 1)\n result -= result / n\n return result\n}\n\nvar out = PrintWriter(System.out)\nvar br = BufferedReader(InputStreamReader(System.`in`))\nvar st = StringTokenizer(\"\")\n\nfun main(args: Array) {\n solve()\n out.close()\n}\n\ninline fun readString(): String {\n if (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st.nextToken()\n}\n\ninline fun readLine() = br.readLine()\ninline fun readInt() = readString().toInt()\ninline fun readLong() = readString().toLong()\ninline fun readDouble() = readString().toDouble()\ninline fun readBool() = readString().toBoolean()\ninline fun readFloat() = readString().toFloat()\n\ninline fun readInts() = readLine().split(' ').map(String::toInt).toIntArray()"}], "src_uid": "acb8a57c8cfdb849a55fa65aff86628d"} {"nl": {"description": "There are $$$n$$$ students in a school class, the rating of the $$$i$$$-th student on Codehorses is $$$a_i$$$. You have to form a team consisting of $$$k$$$ students ($$$1 \\le k \\le n$$$) such that the ratings of all team members are distinct.If it is impossible to form a suitable team, print \"NO\" (without quotes). Otherwise print \"YES\", and then print $$$k$$$ distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le k \\le n \\le 100$$$) — the number of students and the size of the team you have to form. The second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the rating of $$$i$$$-th student.", "output_spec": "If it is impossible to form a suitable team, print \"NO\" (without quotes). Otherwise print \"YES\", and then print $$$k$$$ distinct integers from $$$1$$$ to $$$n$$$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them. Assume that the students are numbered from $$$1$$$ to $$$n$$$.", "sample_inputs": ["5 3\n15 13 15 15 12", "5 4\n15 13 15 15 12", "4 4\n20 10 40 30"], "sample_outputs": ["YES\n1 2 5", "NO", "YES\n1 2 3 4"], "notes": "NoteAll possible answers for the first example: {1 2 5} {2 3 5} {2 4 5} Note that the order does not matter."}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.min\n\nfun main(args: Array)\n = Thread { run() }.start()\n\nfun run() {\n\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n val k = scanner.nextInt()\n val set = TreeSet()\n val arr = ArrayList()\n for (i in 0 until n) {\n val a = scanner.nextInt()\n if (!set.contains(a)) {\n set.add(a)\n arr.add(i + 1)\n if (set.size == k) {\n println(\"YES\")\n arr.forEach { print(\"$it \") }\n return\n }\n }\n }\n println(\"NO\")\n\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\nclass Pair(var a: Int, var b: Int): Comparable {\n override fun compareTo(other: Pair): Int {\n return a - other.a\n }\n}\n//class Triple(val a: Int, val b: Int, val c: Int)"}, {"source_code": "fun readInts(delimit: Char =' ') = readLine()!!.split(delimit).map(String::toInt)\n\nfun main(args:Array)\n{\n var (n,k) = readInts()\n var arr:List = readInts()\n\n var distinct = listOf()\n var indexs = listOf()\n var ans = \"NO\"\n for (i in arr.indices)\n {\n var curr = arr[i]\n if (curr in distinct)\n {\n continue\n }\n else\n {\n distinct += curr\n indexs += (i+1)\n if (distinct.size == k)\n {\n ans = \"YES\"\n break\n }\n\n }\n\n }\n println(ans)\n if (ans == \"YES\") println(indexs.joinToString(\" \"))\n}\n"}, {"source_code": "fun readInts(delimit: Char =' ') = readLine()!!.split(delimit).map(String::toInt)\n\nfun main(args:Array)\n{\n var (n,k) = readInts()\n var arr = readInts()\n\n var distinct = listOf()\n var indexs = listOf()\n var ans = \"NO\"\n for (i in arr.indices)\n {\n var curr = arr[i]\n if (curr in distinct)\n {\n continue\n }\n else\n {\n distinct += curr\n indexs += (i+1)\n if (distinct.size == k)\n {\n ans = \"YES\"\n break\n }\n\n }\n }\n println(ans)\n if (ans == \"YES\") println(indexs.joinToString(\" \"))\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val l = r.readLine()!!.toInt()\n //val day = r.readLine()!!.split(\" \").map { it.toInt() }\n val (n, k) = r.readLine()!!.split(\" \").map { it.toInt() }\n val i = mutableListOf()\n val rate = mutableListOf()\n val rates = r.readLine()!!.split(\" \").map { it.toInt() }\n var index = 1\n rates.forEach {\n if (it !in rate){\n rate += it\n i += index\n }\n index++\n }\n if (i.size()\n\n val s = mutableSetOf()\n for ((index, a) in nextArray(n).withIndex()) {\n if (!s.contains(a)) {\n s.add(a).also { ans.add(index+1) }\n }\n if (ans.size == k) {\n break\n }\n }\n if (ans.size == k) {\n println(\"YES\\n${ans.joinToString(separator = \" \")}\")\n } else {\n println(\"NO\")\n }\n}\n\n\n\n\nfun hasNext() : Boolean {\n while (!st.hasMoreTokens()) {\n st = StringTokenizer(input.readLine() ?: return false)\n }\n return true\n}\n\nfun next() = if (hasNext()) st.nextToken()!! else throw RuntimeException(\"No tokens\")\n\nfun nextInt() = next().toInt()\n\nfun nextLong() = next().toLong()\n\nfun nextDouble() = next().toDouble()\n\nfun nextLine() = if (hasNext()) st.nextToken(\"\\n\")!! else throw RuntimeException(\"No tokens\")\n\nfun nextArray(n : Int) = IntArray(n, { nextInt() })\n\nval ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n\nvar input = when(ONLINE_JUDGE) {\n true -> BufferedReader(InputStreamReader(System.`in`), 32768)\n else -> BufferedReader(FileReader(\"in.txt\"))\n}\n\nvar output = when(ONLINE_JUDGE) {\n true -> PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))\n else -> PrintWriter(BufferedWriter(FileWriter(\"out.txt\")))\n}\n\nvar st = StringTokenizer(\"\")\n\nfun main(args: Array) {\n val start = System.currentTimeMillis()\n solve()\n\n output.close()\n input.close()\n\n if (!ONLINE_JUDGE) {\n System.err.println(\"${System.currentTimeMillis() - start} ms\")\n }\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\n\nfun solve() {\n\n val n = nextInt()\n val k = nextInt()\n val array = nextArray(n)\n\n val ans = ArrayList()\n val s = mutableSetOf()\n var count = 0\n for ((index, a) in array.withIndex()) {\n if (!s.contains(a)) {\n s.add(a)\n ans.add(index+1)\n count++\n }\n if (count == k) {\n println(\"YES\")\n println(ans.joinToString(separator = \" \"))\n return\n }\n }\n\n println(\"NO\")\n}\n\n\n\n\nfun hasNext() : Boolean {\n while (!st.hasMoreTokens()) {\n st = StringTokenizer(input.readLine() ?: return false)\n }\n return true\n}\n\nfun next() = if (hasNext()) st.nextToken()!! else throw RuntimeException(\"No tokens\")\n\nfun nextInt() = next().toInt()\n\nfun nextLong() = next().toLong()\n\nfun nextDouble() = next().toDouble()\n\nfun nextLine() = if (hasNext()) st.nextToken(\"\\n\")!! else throw RuntimeException(\"No tokens\")\n\nfun nextArray(n : Int) = IntArray(n, { nextInt() })\n\nval ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n\nvar input = when(ONLINE_JUDGE) {\n true -> BufferedReader(InputStreamReader(System.`in`), 32768)\n else -> BufferedReader(FileReader(\"in.txt\"))\n}\n\nvar output = when(ONLINE_JUDGE) {\n true -> PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))\n else -> PrintWriter(BufferedWriter(FileWriter(\"out.txt\")))\n}\n\nvar st = StringTokenizer(\"\")\n\nfun main(args: Array) {\n val start = System.currentTimeMillis()\n solve()\n\n output.close()\n input.close()\n\n if (!ONLINE_JUDGE) {\n System.err.println(\"${System.currentTimeMillis() - start} ms\")\n }\n}"}, {"source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n var n = scan.nextInt()\n var m = scan.nextInt()\n var a = IntArray(n, {scan.nextInt()})\n var b = BooleanArray(n, {false})\n var kol = 0\n var s = \"\"\n for (i in 0..n-1) {\n if (kol==m) break\n if (!b[i]) {\n kol++\n s+=\"${i+1} \"\n for (j in i+1..n-1) {\n b[j] = if (a[i]==a[j]) true else b[j]\n }\n }\n }\n if (kol()\n\n for(i in 0 until n){\n// hash[arr[i]]!!.add(i+1)\n hash.put(arr[i], (i+1))\n }\n\n if(hash.size < k){\n println(\"NO\")\n }else {\n println(\"YES\")\n\n var cnt = 0\n for (x in hash.keys){\n print(hash[x])\n print(\" \")\n cnt++\n if(cnt == k)\n break\n }\n }\n\n\n}\n\n"}, {"source_code": "import java.io.PrintWriter\nimport java.util.*\n\nprivate val INPUT = System.`in`\nprivate val OUTPUT = System.out\n\nprivate val _reader = INPUT.bufferedReader()\nprivate fun readLine(): String? = _reader.readLine()\nprivate fun readLn() = _reader.readLine()!!\nprivate var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nprivate fun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\n\nprivate fun readInt() = read().toInt()\nprivate fun readDouble() = read().toDouble()\nprivate fun readLong() = read().toLong()\nprivate fun readStrings(n: Int) = List(n) { read() }\nprivate fun readLines(n: Int) = List(n) { readLn() }\nprivate fun readInts(n: Int) = List(n) { read().toInt() }\nprivate fun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nprivate fun readDoubles(n: Int) = List(n) { read().toDouble() }\nprivate fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nprivate fun readLongs(n: Int) = List(n) { read().toLong() }\nprivate fun readLongArray(n: Int) = LongArray(n) { read().toLong() }\nprivate val _writer = PrintWriter(OUTPUT, false)\nprivate inline fun output(block: PrintWriter.() -> Unit) {\n _writer.apply(block).flush()\n}\n\nfun main() {\n output {\n val (n, k) = readInts(2)\n val a = readInts(n)\n val t = arrayListOf()\n for (i in 0 until n){\n if(!t.contains(a[i])){\n t+=a[i]\n }\n if(t.size == k){\n println(\"YES\")\n println(t.map { a.indexOf(it)+1 }.joinToString(\" \"))\n break\n }\n }\n if(t.size != k){\n println(\"NO\")\n }\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n val numberOfStudents = reader.nextInt()\n val kStudents = reader.nextInt()\n\n val complexity = mutableMapOf()\n for (i in 0 until numberOfStudents) {\n complexity[reader.nextInt()] = i+1\n }\n if (complexity.size < kStudents) {\n println(\"NO\")\n return\n }\n println(\"YES\")\n complexity.values.take(kStudents).toList().forEach {\n println(it)\n }\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\nfun gcd (a:Int, b:Int): Int {\n if (b == 0) return a\n return gcd(b, a % b)\n}\nfun lcm(a:Int, b:Int): Int {\n val n1 = a\n val n2 = b\n val gcds = gcd(a,b)\n val lcmz = n1 * n2 / gcds\n return lcmz\n}\n\nfun main(args: Array) = with(Scanner(System.`in`))\n{\n val n = nextInt()\n val k = nextInt()\n val mas = ArrayList()\n val set = TreeSet()\n var sum = 0\n for (i in 0 until n) {\n val x = nextInt()\n mas += x\n if(set.add(x)){\n sum++\n }\n }\n if(set.size < k){\n println(\"NO\")\n return\n }\n println(\"YES\")\n set.clear()\n sum = 0\n for (i in 0 until n){\n if(set.add(mas[i]) && sum < k){\n print((i+1).toString() + ' ')\n sum++\n }\n }\n}"}, {"source_code": "fun main(args : Array) {\n val(n, k) = readLine()!!.split(' ').map(String :: toInt)\n var arr1 : Array = readLine()!!.split(' ').map { it.toInt() }.toTypedArray()\n var arr = arr1.sorted()\n var list = IntArray(k)\n var count = 1\n list[0] = arr[0]\n for (i in 0..(n-2)) {\n if (arr[i] != arr[i+1]) {\n count++\n list[count-1] = arr[i+1]\n }\n if (count == k)\n break\n }\n if (count < k)\n println(\"NO\")\n else {\n println(\"YES\")\n for (i in 0..(k-1)) {\n for (j in 0..(n-1)) {\n if (arr1[j] == list[i]) {\n print(j+1)\n print(' ')\n break\n }\n\n }\n }\n }\n }"}, {"source_code": "import java.lang.String.format\nimport java.util.*\nimport kotlin.math.*\nimport kotlin.system.exitProcess\n\nprivate fun readLn()=readLine()!! // string line\nprivate fun readInt()=readLn().toInt() // single int\nprivate fun readLong()=readLn().toLong() // single long\nprivate fun readDouble()=readLn().toDouble() // single double\nprivate fun readStrings()=readLn().split(\" \") // list of strings\nprivate fun readInts()=readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs()=readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles()=readStrings().map { it.toDouble() } // list of doubles\nfun main(){\n val reader=Scanner(System.`in`)\n var (a,b)=readInts()\n var p=Array(a+1){0}\n var h=Array(101){0}\n var d=0\n for(i in 1..a){\n p[i]=reader.nextInt()\n if(h[p[i]]==0){\n d++\n }\n h[p[i]]=i\n }\n if(d) = with(Scanner(System.`in`)) {\n val n = nextInt()\n val k = nextInt()\n\n val t = ArrayList()\n val i = ArrayList()\n\n for (c in 1..n) {\n val x = nextInt()\n if (!t.contains(x)) {\n t += x\n i += c\n }\n if (t.size == k) break\n }\n\n if (t.size == k) {\n println(\"YES\")\n println(i.joinToString(\" \"))\n } else {\n println(\"NO\")\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n var n = sc.nextInt()\n var k = sc.nextInt()\n var a: ArrayList = ArrayList()\n var nx: ArrayList = ArrayList()\n for (i in 0..n - 1) {\n var x = sc.nextInt()\n var b: Boolean = true\n for (j in 0..a.size - 1)\n if (a[j] == x) {\n b = false\n break\n }\n if (b) {\n a.add(x)\n nx.add(i + 1)\n }\n }\n var s: String = \"\"\n if (k <= nx.size) {\n println(\"YES\")\n for (i in 0..k - 1)\n s += nx[i].toString() + \" \"\n print(s.trim())\n } else print(\"NO\")\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (_, k) = readInts()\n val students = readInts()\n val selected = mutableSetOf()\n val positions = IntArray(k)\n for ((pos, student) in students.withIndex()) {\n if (student !in selected) {\n positions[selected.size] = pos + 1\n selected.add(student)\n }\n if (selected.size == k) {\n println(\"YES\")\n print(positions.joinToString(\" \"))\n return\n }\n }\n print(\"NO\")\n}"}, {"source_code": "fun readString() = readLine()!!\n\nfun readInt() = readString().toInt()\nfun readLong() = readString().toLong()\n\nfun readIntArray() = readString().split(\" \").map { it.toInt() }\nfun readLongArray() = readString().split(\" \").map { it.toLong() }\n\nfun main() {\n val (n, k) = readIntArray()\n val arr = readIntArray()\n\n val set = arr.toSet()\n\n if (set.size < k) {\n println(\"NO\")\n } else {\n println(\"YES\")\n val res = mutableListOf()\n set.take(k).forEach {\n res += (arr.indexOf(it) + 1)\n }\n println(res.joinToString(\" \"))\n }\n}"}, {"source_code": "fun main(args : Array) {\n var (n, k) = readLine()!!.split(\" \")!!.map { it.toInt() }\n val set = mutableSetOf()\n val solution = arrayListOf()\n for((index, v) in readLine()!!.split(\" \").withIndex()) {\n if(v !in set) set.add(v).also { solution.add(index + 1) }\n if(solution.size >= k) break\n }\n if(solution.size < k) println(\"NO\") else println(\"YES\\n${solution.joinToString(\" \")}\")\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.io.InputStream\nimport java.util.*\nimport kotlin.math.log\n\nfun main(args: Array) {\n class Scanner(s: InputStream) {\n private var st: StringTokenizer? = null\n private var br: BufferedReader = BufferedReader(InputStreamReader(s))\n\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n }\n\n val scan = Scanner(System.`in`)\n\n val n = scan.nextInt()\n val k = scan.nextInt()\n\n val dist = (0 until n).map { it + 1 to scan.nextInt() }.distinctBy { it.second }\n\n if (dist.size < k) {\n println(\"NO\")\n } else {\n println(\"YES\")\n println(dist.subList(0, k).map { it.first }.joinToString(\" \"))\n }\n}"}, {"source_code": "import java.io.InputStreamReader\nimport java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(InputStreamReader(System.`in`))\n val n = scanner.nextInt()\n val k = scanner.nextInt()\n var team = HashSet()\n var teamIndices = ArrayList()\n var complete = false\n\n for (i in 1..n) {\n val rank = scanner.nextInt()\n if (!team.contains(rank)) {\n team.add(rank)\n teamIndices.add(i)\n }\n if (team.size == k)\n complete = true\n if (complete) break\n }\n if (complete) {\n System.out.println(\"YES\")\n System.out.println(teamIndices.joinToString(\" \"))\n } else {\n System.out.println(\"NO\")\n }\n}\n"}, {"source_code": "import java.io.*\n\n\nclass Reader{\n val reader = BufferedReader ( InputStreamReader( System.`in` ) )\n fun readTokens() = reader.readLine().split(\" \")\n}\n\ndata class Value(val v : Int = 0 , val i : Int = 0) : Comparable {\n override fun compareTo(other: Value): Int {\n return v-other.v\n }\n}\n\nfun main(args: Array){\n val reader = Reader()\n val out = BufferedWriter ( OutputStreamWriter ( System.out ) )\n\n val line0 = reader.readTokens()\n val line1 = reader.readTokens()\n\n val n = line0[0].toInt()\n val k = line0[1].toInt()\n val values = Array(n, { i -> Value(line1[i].toInt(),i)})\n values.sort()\n\n val ans = ArrayList()\n ans.add(values[0])\n for ( v in values )\n if ( ans.last().v != v.v )\n ans.add(v)\n\n if ( ans.size < k )\n out.append(\"NO\\n\")\n else {\n out.append(\"YES\\n\")\n for ( i in 0 until k ) {\n out.append((ans[i].i+1).toString())\n out.append( if ( i+1 < k ) ' ' else '\\n' )\n }\n }\n\n out.flush()\n}"}], "negative_code": [{"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val l = r.readLine()!!.toInt()\n //val day = r.readLine()!!.split(\" \").map { it.toInt() }\n val (n, k) = r.readLine()!!.split(\" \").map { it.toInt() }\n val i = mutableListOf()\n val rate = mutableListOf()\n val rates = r.readLine()!!.split(\" \").map { it.toInt() }\n var index = 1\n rates.forEach {\n if (it !in rate){\n rate += it\n i += index\n }\n index++\n }\n if (i.size) = with(Scanner(System.`in`))\n{\n val n = nextInt()\n val k = nextInt()\n val mas = ArrayList()\n val set = TreeSet()\n var sum = 0\n for (i in 0 until n) {\n val x = nextInt()\n mas += x\n if(set.add(x)){\n sum++\n }\n }\n if(set.size != k){\n println(\"NO\")\n return\n }\n println(\"YES\")\n set.clear()\n for (i in 0 until n){\n if(set.add(mas[i])){\n print((i+1).toString() + ' ')\n }\n }\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\nfun gcd (a:Int, b:Int): Int {\n if (b == 0) return a\n return gcd(b, a % b)\n}\nfun lcm(a:Int, b:Int): Int {\n val n1 = a\n val n2 = b\n val gcds = gcd(a,b)\n val lcmz = n1 * n2 / gcds\n return lcmz\n}\n\nfun main(args: Array) = with(Scanner(System.`in`))\n{\n val n = nextInt()\n val k = nextInt()\n val mas = ArrayList()\n val set = TreeSet()\n var sum = 0\n for (i in 0 until n) {\n val x = nextInt()\n mas += x\n if(set.add(x)){\n sum++\n }\n }\n if(set.size <= k){\n println(\"NO\")\n return\n }\n println(\"YES\")\n set.clear()\n sum = 0\n for (i in 0 until n){\n if(set.add(mas[i]) && sum < k){\n print((i+1).toString() + ' ')\n sum++\n }\n }\n}"}, {"source_code": "fun readString() = readLine()!!\n\nfun readInt() = readString().toInt()\nfun readLong() = readString().toLong()\n\nfun readIntArray() = readString().split(\" \").map { it.toInt() }\nfun readLongArray() = readString().split(\" \").map { it.toLong() }\n\nfun main() {\n val (n, k) = readIntArray()\n val arr = readIntArray()\n\n val set = mutableSetOf()\n val res = mutableListOf()\n arr.forEachIndexed { index, i ->\n if (!set.contains(i)) {\n res += (index + 1)\n set += i\n }\n }\n if (res.size < k) {\n println(\"NO\")\n } else {\n println(\"YES\")\n println(res.joinToString(\" \"))\n }\n}"}, {"source_code": "fun readString() = readLine()!!\n\nfun readInt() = readString().toInt()\nfun readLong() = readString().toLong()\n\nfun readIntArray() = readString().split(\" \").map { it.toInt() }\nfun readLongArray() = readString().split(\" \").map { it.toLong() }\n\nfun main() {\n val (n, k) = readIntArray()\n val arr = readIntArray()\n\n val set = mutableSetOf()\n val res = mutableListOf()\n arr.forEachIndexed { index, i ->\n if (!set.contains(i)) {\n res += (index + 1)\n set += i\n }\n }\n if (res.size < k) {\n println(\"NO\")\n } else {\n println(res.joinToString(\" \"))\n }\n}"}, {"source_code": "fun readString() = readLine()!!\n\nfun readInt() = readString().toInt()\nfun readLong() = readString().toLong()\n\nfun readIntArray() = readString().split(\" \").map { it.toInt() }\nfun readLongArray() = readString().split(\" \").map { it.toLong() }\n\nfun main() {\n val (n, k) = readIntArray()\n val arr = readIntArray()\n\n val set = arr.toSet()\n\n if (set.size < k) {\n println(\"NO\")\n } else {\n println(\"YES\")\n val res = mutableListOf()\n set.forEach {\n res += (arr.indexOf(it) + 1)\n }\n println(res.joinToString(\" \"))\n }\n}"}, {"source_code": "fun readString() = readLine()!!\n\nfun readInt() = readString().toInt()\nfun readLong() = readString().toLong()\n\nfun readIntArray() = readString().split(\" \").map { it.toInt() }\nfun readLongArray() = readString().split(\" \").map { it.toLong() }\n\nfun main() {\n val (n, k) = readIntArray()\n val arr = readIntArray()\n\n val set = mutableSetOf()\n val res = mutableListOf()\n arr.forEachIndexed { index, i ->\n if (!set.contains(i)) {\n res += (index + 1)\n set += i\n }\n }\n if (res.size < k || n < k) {\n println(\"NO\")\n } else {\n println(\"YES\")\n println(res.joinToString(\" \"))\n }\n}"}], "src_uid": "5de6574d57ab04ca195143e08d28d0ad"} {"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": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val k = readInt()\n val one = BooleanArray(11)\n val two = BooleanArray(11)\n val four = BooleanArray(11)\n one[0] = k >= 1\n two[0] = k >= 2\n four[0] = k >= 4\n for (pos in 1 until 11) one[pos] = 2 + pos * 3 <= k\n for (pos in 1 until 11) two[pos] = 3 + pos * 3 <= k\n for (pos in 1 until 11) four[pos] = 4 + pos * 3 <= k\n println(\"+------------------------+\")\n println(\"|${one.joinToString(separator = \"\") { if (it) \"O.\" else \"#.\" }}|D|)\")\n println(\"|${two.joinToString(separator = \"\") { if (it) \"O.\" else \"#.\" }}|.|\")\n println(\"|${if (k >= 3) \"O\" else \"#\"}.......................|\")\n println(\"|${four.joinToString(separator = \"\") { if (it) \"O.\" else \"#.\" }}|.|)\")\n println(\"+------------------------+\")\n}\n"}], "negative_code": [], "src_uid": "075f83248f6d4d012e0ca1547fc67993"} {"nl": {"description": "A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert a grams of sand into b grams of lead, the second one allows you to convert c grams of lead into d grams of gold and third one allows you to convert e grams of gold into f grams of sand. When Harry told his friends about these spells, Ron Weasley was amazed. After all, if they succeed in turning sand into lead, lead into gold, and then turning part of the gold into sand again and so on, then it will be possible to start with a small amount of sand and get huge amounts of gold! Even an infinite amount of gold! Hermione Granger, by contrast, was skeptical about that idea. She argues that according to the law of conservation of matter getting an infinite amount of matter, even using magic, is impossible. On the contrary, the amount of matter may even decrease during transformation, being converted to magical energy. Though Hermione's theory seems convincing, Ron won't believe her. As far as Ron is concerned, Hermione made up her law of conservation of matter to stop Harry and Ron wasting their time with this nonsense, and to make them go and do homework instead. That's why Ron has already collected a certain amount of sand for the experiments. A quarrel between the friends seems unavoidable...Help Harry to determine which one of his friends is right, and avoid the quarrel after all. To do this you have to figure out whether it is possible to get the amount of gold greater than any preassigned number from some finite amount of sand.", "input_spec": "The first line contains 6 integers a, b, c, d, e, f (0 ≤ a, b, c, d, e, f ≤ 1000).", "output_spec": "Print \"Ron\", if it is possible to get an infinitely large amount of gold having a certain finite amount of sand (and not having any gold and lead at all), i.e., Ron is right. Otherwise, print \"Hermione\".", "sample_inputs": ["100 200 250 150 200 250", "100 50 50 200 200 100", "100 10 200 20 300 30", "0 0 0 0 0 0", "1 1 0 1 1 1", "1 0 1 2 1 2", "100 1 100 1 0 1"], "sample_outputs": ["Ron", "Hermione", "Hermione", "Hermione", "Ron", "Hermione", "Ron"], "notes": "NoteConsider the first sample. Let's start with the 500 grams of sand. Apply the first spell 5 times and turn the sand into 1000 grams of lead. Then apply the second spell 4 times to get 600 grams of gold. Let’s take 400 grams from the resulting amount of gold turn them back into sand. We get 500 grams of sand and 200 grams of gold. If we apply the same operations to 500 grams of sand again, we can get extra 200 grams of gold every time. Thus, you can get 200, 400, 600 etc. grams of gold, i.e., starting with a finite amount of sand (500 grams), you can get the amount of gold which is greater than any preassigned number.In the forth sample it is impossible to get sand, or lead, or gold, applying the spells.In the fifth sample an infinitely large amount of gold can be obtained by using only the second spell, which allows you to receive 1 gram of gold out of nothing. Note that if such a second spell is available, then the first and the third one do not affect the answer at all.The seventh sample is more interesting. We can also start with a zero amount of sand there. With the aid of the third spell you can get sand out of nothing. We get 10000 grams of sand in this manner. Let's get 100 grams of lead using the first spell 100 times. Then make 1 gram of gold from them. We managed to receive 1 gram of gold, starting with a zero amount of sand! Clearly, in this manner you can get an infinitely large amount of gold."}, "positive_code": [{"source_code": "import com.sun.javafx.binding.SelectBinding\n\n// contest/65/A Harry Potter and Three Spells train\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val abcdef = readInts()\n val a = abcdef[0]\n val b = abcdef[1]\n val c = abcdef[2]\n val d = abcdef[3]\n val e = abcdef[4]\n val f = abcdef[5]\n var ace : Long\n var bdf : Long\n var canInf = false\n\n var coef = 1.0\n if (d==0) {\n // no gold\n canInf = false\n } else if (d!=0 && c==0) {\n canInf = true // unlimited gold\n } else if (c!=0 && b==0) {\n // no lead\n canInf = false\n } else if (b!=0 && d != 0 && a==0) {\n canInf = true // unlimited lead\n } else if (a != 0 && f==0) {\n // no sand\n canInf = false\n } else if (b!=0 && d != 0 && f!=0 && e==0) {\n canInf = true // unlimited sand\n } else {\n ace = a.toLong()*c*e\n bdf = b.toLong() *d*f\n canInf = bdf > ace\n }\n\n println(if (canInf) \"Ron\" else \"Hermione\")\n}\n"}], "negative_code": [{"source_code": "import com.sun.javafx.binding.SelectBinding\n\n// contest/65/A Harry Potter and Three Spells train\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val abcdef = readInts()\n val a = abcdef[0]\n val b = abcdef[1]\n val c = abcdef[2]\n val d = abcdef[3]\n val e = abcdef[4]\n val f = abcdef[5]\n var ace : Long\n var bdf : Long\n var canInf = false\n\n var coef = 1.0\n if (d==0) {\n // no gold\n canInf = false\n } else if (c!=0 && b==0) {\n // no lead\n canInf = false\n } else if (a != 0 && f==0) {\n // no sand\n canInf = false\n } else if (d!=0 && c==0) {\n canInf = true // unlimited gold\n } else if (d!=0 && c==0) {\n canInf = true // unlimited gold\n } else if (b!=0 && d != 0 && a==0) {\n canInf = true // unlimited lead\n } else if (b!=0 && d != 0 && f!=0 && e==0) {\n canInf = true // unlimited sand\n } else {\n ace = a.toLong()*c*e\n bdf = b.toLong() *d*f\n canInf = bdf > ace\n }\n\n println(if (canInf) \"Ron\" else \"Hermione\")\n}\n"}, {"source_code": "import com.sun.javafx.binding.SelectBinding\n\n// contest/65/A Harry Potter and Three Spells train\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val abcdef = readInts()\n val a = abcdef[0]\n val b = abcdef[1]\n val c = abcdef[2]\n val d = abcdef[3]\n val e = abcdef[4]\n val f = abcdef[5]\n var ace : Long\n var bdf : Long\n var canInf = false\n\n var coef = 1.0\n if (b==0 || d==0 || f==0) {\n canInf = false\n } else {\n ace = a.toLong()*c*e\n bdf = b.toLong() *d*f\n canInf = bdf > ace\n }\n\n println(if (canInf) \"Ron\" else \"Hermione\")\n}\n"}], "src_uid": "44d608de3e1447f89070e707ba550150"} {"nl": {"description": "Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?", "input_spec": "The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.", "output_spec": "Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.", "sample_inputs": ["6 3", "8 5", "22 4"], "sample_outputs": ["4", "3", "6"], "notes": "NoteIn the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do .In the second sample test, Memory can do .In the third sample test, Memory can do: ."}, "positive_code": [{"source_code": "import java.lang.Math.*\n\nfun main(args: Array) {\n val (x, y) = readLine()!!.split(' ').map(String::toInt)\n var (a, b, c) = arrayListOf(y, y, y)\n var ans = 0\n while (a != x) {\n ans++\n a = min(x, b + c - 1)\n val (a1, b1, c1) = arrayListOf(a, b, c).sorted()\n a = a1\n b = b1\n c = c1\n }\n print(ans)\n}"}, {"source_code": "fun main(args: Array) {\n val (x, y) = readLine()!!.split(' ').map(String::toInt)\n var (a, b, c) = listOf(y, y, y)\n var ans = 0\n while (c < x) {\n c = b\n b = a\n a = b + c - 1\n ans++\n }\n println(ans)\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.min\n\nfun main() {\n val iin = BufferedReader(InputStreamReader(System.`in`))\n val (x, y) = iin.readLine()!!.split(\" \").map { it.toInt() }\n val q = LinkedList()\n for (i in 1..3) {\n q.add(y)\n }\n var ans = 0\n while (q[2] != x) {\n ans++\n q.addFirst(min(x, q[0] + q[1] - 1))\n }\n println(ans)\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.min\n\nfun main() {\n val (x, y) = readLine()!!.split(\" \").map { it.toInt() }\n val q = LinkedList()\n for (j in 1..3) {\n q.add(y)\n }\n var answer = 0\n while (q[2] != x) {\n answer++\n q.addFirst(min(x, q[0] + q[1] - 1))\n }\n println(answer)\n}"}], "negative_code": [{"source_code": "import java.util.*\nimport kotlin.math.floor\n\nfun main() {\n val (x, y) = readLine()!!.split(\" \").map { it.toInt() }\n val q = LinkedList()\n for (j in 1..3) {\n q.add(x)\n }\n var answer = 0\n while (!q.all { it == y }) {\n answer++\n q.remove()\n q.add(maxOf(y, floor(q.last().toDouble() / 1.61803398875).toInt() + 1))\n }\n println(answer)\n}"}], "src_uid": "8edf64f5838b19f9a8b19a14977f5615"} {"nl": {"description": "You've got a rectangular table with length a and width b and the infinite number of plates of radius r. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch each other), and so that any point on any plate is located within the table's border. During the game one cannot move the plates that already lie on the table. The player who cannot make another move loses. Determine which player wins, the one who moves first or the one who moves second, provided that both players play optimally well.", "input_spec": "A single line contains three space-separated integers a, b, r (1 ≤ a, b, r ≤ 100) — the table sides and the plates' radius, correspondingly.", "output_spec": "If wins the player who moves first, print \"First\" (without the quotes). Otherwise print \"Second\" (without the quotes).", "sample_inputs": ["5 5 2", "6 7 4"], "sample_outputs": ["First", "Second"], "notes": "NoteIn the first sample the table has place for only one plate. The first player puts a plate on the table, the second player can't do that and loses. In the second sample the table is so small that it doesn't have enough place even for one plate. So the first player loses without making a single move. "}, "positive_code": [{"source_code": "import java.util.*\n\nfun main(args: Array) {\n\tval s = Scanner(System.`in`)\n\tval a = s.nextInt()\n\tval b = s.nextInt()\n\tval c = s.nextInt() * 2\n\tif (a >= c && b >= c) {\n\t\tprintln(\"First\")\n\t} else {\n\t\tprintln(\"Second\")\n\t}\n}\n\n"}], "negative_code": [], "src_uid": "90b9ef939a13cf29715bc5bce26c9896"} {"nl": {"description": "You are given two arithmetic progressions: a1k + b1 and a2l + b2. Find the number of integers x such that L ≤ x ≤ R and x = a1k' + b1 = a2l' + b2, for some integers k', l' ≥ 0.", "input_spec": "The only line contains six integers a1, b1, a2, b2, L, R (0 < a1, a2 ≤ 2·109,  - 2·109 ≤ b1, b2, L, R ≤ 2·109, L ≤ R).", "output_spec": "Print the desired number of integers x.", "sample_inputs": ["2 0 3 3 5 21", "2 4 3 0 6 17"], "sample_outputs": ["3", "2"], "notes": null}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nfun gcd(a: Long, b: Long) : Long = if (a == 0L) b else gcd(b % a, a)\n\nfun exGcd(a: Long, b: Long) : Pair {\n if (a == 0L)\n return 0L to 1L\n val (r1, r2) = exGcd(b % a, a)\n return r2 - r1 * (b/a) to r1\n}\n\nfun main(args : Array) {\n //====== Input preparations ========================================================\n// val fin = BufferedReader(FileReader(\"d.in\"))\n val fin = BufferedReader(InputStreamReader(System.`in`))\n val fout = PrintWriter (System.out)\n var tokenizer = StringTokenizer(\"\")\n fun next() : String {\n while (!tokenizer.hasMoreTokens())\n tokenizer = StringTokenizer(fin.readLine())\n return tokenizer.nextToken()\n }\n fun nextInt() = next().toInt()\n fun nextPair() = next().toLong() to next().toLong()\n fun nextPairDec() = nextInt()-1 to nextInt()-1\n //====== Solution below ============================================================\n val (a1, b1) = nextPair()\n val (a2, b2) = nextPair()\n val (l, r) = nextPair()\n var (k,m,v) = Triple(a1, a2, b2 - b1)\n val d = gcd(k, m)\n if (v % d != 0L) {\n fout.print(0)\n fout.close()\n return\n }\n v /= d\n k /= d\n m /= d\n val (kk, km) = exGcd(k, m)\n val num = (kk % m * v % m + m) % m\n\n var st = b1 + num * a1\n val h = a1 * m\n fun get(x : Long) : Long {\n val sh = x - st\n if (sh < 0)\n return 0\n return sh / h + 1\n }\n val otherGet = get(b2)\n if (h < 5e9)\n st += Math.max(Math.max(otherGet - 20, 0L) * h, 0L)\n while (st < b2)\n st += h\n fout.print(get(r) - get(l - 1))\n\n fout.close()\n fin.close()\n}\n\n"}], "negative_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nfun gcd(a: Int, b: Int) : Int = if (a == 0) b else gcd(b % a, a)\n\nfun exGcd(a: Int, b: Int) : Pair {\n if (a == 0)\n return 0L to 1L\n val (r1, r2) = exGcd(b % a, a)\n return r2 - r1 * (b/a) to r1\n}\n\nfun main(args : Array) {\n //====== Input preparations ========================================================\n// val fin = BufferedReader(FileReader(\"d.in\"))\n val fin = BufferedReader(InputStreamReader(System.`in`))\n val fout = PrintWriter (System.out)\n var tokenizer = StringTokenizer(\"\")\n fun next() : String {\n while (!tokenizer.hasMoreTokens())\n tokenizer = StringTokenizer(fin.readLine())\n return tokenizer.nextToken()\n }\n fun nextInt() = next().toInt()\n fun nextPair() = nextInt() to nextInt()\n fun nextPairDec() = nextInt()-1 to nextInt()-1\n //====== Solution below ============================================================\n val (a1, b1) = nextPair()\n val (a2, b2) = nextPair()\n val (l, r) = nextPair()\n var (k,m,v) = Triple(a1, a2, b2 - b1)\n val d = gcd(k, m)\n if (v % d != 0) {\n fout.print(0)\n return\n }\n v /= d\n k /= d\n m /= d\n val (kk, km) = exGcd(k, m)\n val num = (kk % m * v % m + m) % m\n\n val st = b1 + num * a1.toLong()\n val h = a1.toLong() * m\n assert(st % a2 == b2.toLong())\n fun get(x : Long) : Long {\n val sh = x - st\n if (sh < 0)\n return 0\n return sh / h + 1\n }\n fout.print(get(r.toLong()) - get(l.toLong() - 1))\n\n fout.close()\n fin.close()\n}\n\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun gcd(a: Int, b: Int) : Int = if (a == 0) b else gcd(b % a, a)\n\nfun exGcd(a: Int, b: Int) : Pair {\n if (a == 0)\n return 0L to 1L\n val (r1, r2) = exGcd(b % a, a)\n return r2 - r1 * (b/a) to r1\n}\n\nfun main(args : Array) {\n //====== Input preparations ========================================================\n// val fin = BufferedReader(FileReader(\"d.in\"))\n val fin = BufferedReader(InputStreamReader(System.`in`))\n val fout = PrintWriter (System.out)\n var tokenizer = StringTokenizer(\"\")\n fun next() : String {\n while (!tokenizer.hasMoreTokens())\n tokenizer = StringTokenizer(fin.readLine())\n return tokenizer.nextToken()\n }\n fun nextInt() = next().toInt()\n fun nextPair() = nextInt() to nextInt()\n fun nextPairDec() = nextInt()-1 to nextInt()-1\n //====== Solution below ============================================================\n val (a1, b1) = nextPair()\n val (a2, b2) = nextPair()\n val (l, r) = nextPair()\n var (k,m,v) = Triple(a1, a2, (b2 - b1).toLong())\n val d = gcd(k, m)\n if (v % d != 0.toLong()) {\n fout.print(0)\n return\n }\n v /= d\n k /= d\n m /= d\n val (kk, km) = exGcd(k, m)\n val num = (kk % m * v % m + m) % m\n assert(num >= 0)\n\n val st = b1 + num * a1.toLong()\n val h = a1.toLong() * m\n assert(st % a2 == b2.toLong())\n fun get(x : Long) : Long {\n val sh = x - st\n if (sh < 0)\n return 0\n return sh / h + 1\n }\n val otherGet = get(b2.toLong())\n fun fixedGet(a : Long) = Math.max(0L, get(a) - otherGet)\n fout.print(fixedGet(r.toLong()) - fixedGet(l.toLong() - 1))\n\n fout.close()\n fin.close()\n}\n\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun gcd(a: Long, b: Long) : Long = if (a == 0L) b else gcd(b % a, a)\n\nfun exGcd(a: Long, b: Long) : Pair {\n if (a == 0L)\n return 0L to 1L\n val (r1, r2) = exGcd(b % a, a)\n return r2 - r1 * (b/a) to r1\n}\n\nfun main(args : Array) {\n //====== Input preparations ========================================================\n// val fin = BufferedReader(FileReader(\"d.in\"))\n val fin = BufferedReader(InputStreamReader(System.`in`))\n val fout = PrintWriter (System.out)\n var tokenizer = StringTokenizer(\"\")\n fun next() : String {\n while (!tokenizer.hasMoreTokens())\n tokenizer = StringTokenizer(fin.readLine())\n return tokenizer.nextToken()\n }\n fun nextInt() = next().toInt()\n fun nextPair() = next().toLong() to next().toLong()\n fun nextPairDec() = nextInt()-1 to nextInt()-1\n //====== Solution below ============================================================\n val (a1, b1) = nextPair()\n val (a2, b2) = nextPair()\n val (l, r) = nextPair()\n var (k,m,v) = Triple(a1, a2, (b2 - b1).toLong())\n val d = gcd(k, m)\n if (v % d != 0.toLong()) {\n fout.print(0)\n return\n }\n v /= d\n k /= d\n m /= d\n val (kk, km) = exGcd(k, m)\n val num = (kk % m * v % m + m) % m\n assert(num >= 0)\n\n var st = b1 + num * a1.toLong()\n val h = a1.toLong() * m\n fun get(x : Long) : Long {\n val sh = x - st\n if (sh < 0)\n return 0\n return sh / h + 1\n }\n val otherGet = get(b2.toLong())\n st += Math.max((otherGet - 2) * h, 0L)\n while (st < b2)\n st += h\n fout.print(get(r.toLong()) - get(l.toLong() - 1))\n\n fout.close()\n fin.close()\n}\n\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun gcd(a: Int, b: Int) : Int = if (a == 0) b else gcd(b % a, a)\n\nfun exGcd(a: Int, b: Int) : Pair {\n if (a == 0)\n return 0L to 1L\n val (r1, r2) = exGcd(b % a, a)\n return r2 - r1 * (b/a) to r1\n}\n\nfun main(args : Array) {\n //====== Input preparations ========================================================\n// val fin = BufferedReader(FileReader(\"d.in\"))\n val fin = BufferedReader(InputStreamReader(System.`in`))\n val fout = PrintWriter (System.out)\n var tokenizer = StringTokenizer(\"\")\n fun next() : String {\n while (!tokenizer.hasMoreTokens())\n tokenizer = StringTokenizer(fin.readLine())\n return tokenizer.nextToken()\n }\n fun nextInt() = next().toInt()\n fun nextPair() = nextInt() to nextInt()\n fun nextPairDec() = nextInt()-1 to nextInt()-1\n //====== Solution below ============================================================\n val (a1, b1) = nextPair()\n val (a2, b2) = nextPair()\n val (l, r) = nextPair()\n var (k,m,v) = Triple(a1, a2, b2 - b1)\n val d = gcd(k, m)\n if (v % d != 0) {\n fout.print(0)\n return\n }\n v /= d\n k /= d\n m /= d\n val (kk, km) = exGcd(k, m)\n val num = (kk % m * v + m) % m\n\n val st = b1 + num * a1.toLong()\n val h = a1.toLong() * m\n assert(st % a2 == b2.toLong())\n fun get(x : Long) : Long {\n val sh = x - st\n if (sh < 0)\n return 0\n return sh / h + 1\n }\n fout.print(get(r.toLong()) - get(l.toLong() - 1))\n\n fout.close()\n fin.close()\n}\n\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun gcd(a: Long, b: Long) : Long = if (a == 0L) b else gcd(b % a, a)\n\nfun exGcd(a: Long, b: Long) : Pair {\n if (a == 0L)\n return 0L to 1L\n val (r1, r2) = exGcd(b % a, a)\n return r2 - r1 * (b/a) to r1\n}\n\nfun main(args : Array) {\n //====== Input preparations ========================================================\n// val fin = BufferedReader(FileReader(\"d.in\"))\n val fin = BufferedReader(InputStreamReader(System.`in`))\n val fout = PrintWriter (System.out)\n var tokenizer = StringTokenizer(\"\")\n fun next() : String {\n while (!tokenizer.hasMoreTokens())\n tokenizer = StringTokenizer(fin.readLine())\n return tokenizer.nextToken()\n }\n fun nextInt() = next().toInt()\n fun nextPair() = next().toLong() to next().toLong()\n fun nextPairDec() = nextInt()-1 to nextInt()-1\n //====== Solution below ============================================================\n val (a1, b1) = nextPair()\n val (a2, b2) = nextPair()\n val (l, r) = nextPair()\n var (k,m,v) = Triple(a1, a2, b2 - b1)\n val d = gcd(k, m)\n if (v % d != 0.toLong()) {\n fout.print(0)\n return\n }\n v /= d\n k /= d\n m /= d\n val (kk, km) = exGcd(k, m)\n val num = (kk % m * v % m + m) % m\n\n var st = b1 + num * a1.toLong()\n val h = a1.toLong() * m\n fun get(x : Long) : Long {\n val sh = x - st\n if (sh < 0)\n return 0\n return sh / h + 1\n }\n val otherGet = get(b2.toLong())\n st += Math.max((otherGet - 20) * h, 0L)\n while (st < b2)\n st += h\n fout.print(get(r.toLong()) - get(l.toLong() - 1))\n\n fout.close()\n fin.close()\n}\n\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun gcd(a: Int, b: Int) : Int = if (a == 0) b else gcd(b % a, a)\n\nfun exGcd(a: Int, b: Int) : Pair {\n if (a == 0)\n return 0L to 1L\n val (r1, r2) = exGcd(b % a, a)\n return r2 - r1 * (b/a) to r1\n}\n\nfun main(args : Array) {\n //====== Input preparations ========================================================\n// val fin = BufferedReader(FileReader(\"d.in\"))\n val fin = BufferedReader(InputStreamReader(System.`in`))\n val fout = PrintWriter (System.out)\n var tokenizer = StringTokenizer(\"\")\n fun next() : String {\n while (!tokenizer.hasMoreTokens())\n tokenizer = StringTokenizer(fin.readLine())\n return tokenizer.nextToken()\n }\n fun nextInt() = next().toInt()\n fun nextPair() = nextInt() to nextInt()\n fun nextPairDec() = nextInt()-1 to nextInt()-1\n //====== Solution below ============================================================\n val (a1, b1) = nextPair()\n val (a2, b2) = nextPair()\n val (l, r) = nextPair()\n var (k,m,v) = Triple(a1, a2, b2 - b1)\n val d = gcd(k, m)\n if (v % d != 0) {\n fout.print(0)\n return\n }\n v /= d\n k /= d\n m /= d\n val (kk, km) = exGcd(k, m)\n val num = (kk % m * v + m) % m\n\n val st = b1 + num * a1.toLong()\n val h = a1.toLong() * a2\n fun get(x : Long) : Long {\n val sh = x - st\n if (sh < 0)\n return 0\n return sh / h + 1\n }\n fout.print(get(r.toLong()) - get(l.toLong() - 1))\n\n fout.close()\n fin.close()\n}\n\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun gcd(a: Long, b: Long) : Long = if (a == 0L) b else gcd(b % a, a)\n\nfun exGcd(a: Long, b: Long) : Pair {\n if (a == 0L)\n return 0L to 1L\n val (r1, r2) = exGcd(b % a, a)\n return r2 - r1 * (b/a) to r1\n}\n\nfun main(args : Array) {\n //====== Input preparations ========================================================\n// val fin = BufferedReader(FileReader(\"d.in\"))\n val fin = BufferedReader(InputStreamReader(System.`in`))\n val fout = PrintWriter (System.out)\n var tokenizer = StringTokenizer(\"\")\n fun next() : String {\n while (!tokenizer.hasMoreTokens())\n tokenizer = StringTokenizer(fin.readLine())\n return tokenizer.nextToken()\n }\n fun nextInt() = next().toInt()\n fun nextPair() = next().toLong() to next().toLong()\n fun nextPairDec() = nextInt()-1 to nextInt()-1\n //====== Solution below ============================================================\n val (a1, b1) = nextPair()\n val (a2, b2) = nextPair()\n val (l, r) = nextPair()\n var (k,m,v) = Triple(a1, a2, b2 - b1)\n val d = gcd(k, m)\n if (v % d != 0.toLong()) {\n fout.print(0)\n return\n }\n v /= d\n k /= d\n m /= d\n val (kk, km) = exGcd(k, m)\n val num = (kk % m * v % m + m) % m\n\n var st = b1 + num * a1.toLong()\n val h = a1.toLong() * m\n fun get(x : Long) : Long {\n val sh = x - st\n if (sh < 0)\n return 0\n return sh / h + 1\n }\n val otherGet = get(b2.toLong())\n if (h < 5e9)\n st += Math.max(Math.max(otherGet - 20, 0L) * h, 0L)\n while (st < b2)\n st += h\n fout.print(get(r.toLong()) - get(l.toLong() - 1))\n\n fout.close()\n fin.close()\n}\n\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun gcd(a: Int, b: Int) : Int = if (a == 0) b else gcd(b % a, a)\n\nfun exGcd(a: Int, b: Int) : Pair {\n if (a == 0)\n return 0L to 1L\n val (r1, r2) = exGcd(b % a, a)\n return r2 - r1 * (b/a) to r1\n}\n\nfun main(args : Array) {\n //====== Input preparations ========================================================\n// val fin = BufferedReader(FileReader(\"d.in\"))\n val fin = BufferedReader(InputStreamReader(System.`in`))\n val fout = PrintWriter (System.out)\n var tokenizer = StringTokenizer(\"\")\n fun next() : String {\n while (!tokenizer.hasMoreTokens())\n tokenizer = StringTokenizer(fin.readLine())\n return tokenizer.nextToken()\n }\n fun nextInt() = next().toInt()\n fun nextPair() = nextInt() to nextInt()\n fun nextPairDec() = nextInt()-1 to nextInt()-1\n //====== Solution below ============================================================\n val (a1, b1) = nextPair()\n val (a2, b2) = nextPair()\n val (l, r) = nextPair()\n var (k,m,v) = Triple(a1, a2, (b2 - b1).toLong())\n val d = gcd(k, m)\n if (v % d != 0.toLong()) {\n fout.print(0)\n return\n }\n v /= d\n k /= d\n m /= d\n val (kk, km) = exGcd(k, m)\n val num = (kk % m * v % m + m) % m\n assert(num >= 0)\n\n val st = b1 + num * a1.toLong()\n val h = a1.toLong() * m\n assert(st % a2 == b2.toLong())\n fun get(x : Long) : Long {\n val sh = x - st\n if (sh < 0)\n return 0\n return sh / h + 1\n }\n fout.print(get(r.toLong()) - get(l.toLong() - 1))\n\n fout.close()\n fin.close()\n}\n\n"}], "src_uid": "b08ee0cd6f5cb574086fa02f07d457a4"} {"nl": {"description": "There is an old tradition of keeping 4 boxes of candies in the house in Cyberland. The numbers of candies are special if their arithmetic mean, their median and their range are all equal. By definition, for a set {x1, x2, x3, x4} (x1 ≤ x2 ≤ x3 ≤ x4) arithmetic mean is , median is and range is x4 - x1. The arithmetic mean and median are not necessary integer. It is well-known that if those three numbers are same, boxes will create a \"debugging field\" and codes in the field will have no bugs.For example, 1, 1, 3, 3 is the example of 4 numbers meeting the condition because their mean, median and range are all equal to 2.Jeff has 4 special boxes of candies. However, something bad has happened! Some of the boxes could have been lost and now there are only n (0 ≤ n ≤ 4) boxes remaining. The i-th remaining box contains ai candies.Now Jeff wants to know: is there a possible way to find the number of candies of the 4 - n missing boxes, meeting the condition above (the mean, median and range are equal)?", "input_spec": "The first line of input contains an only integer n (0 ≤ n ≤ 4). The next n lines contain integers ai, denoting the number of candies in the i-th box (1 ≤ ai ≤ 500).", "output_spec": "In the first output line, print \"YES\" if a solution exists, or print \"NO\" if there is no solution. If a solution exists, you should output 4 - n more lines, each line containing an integer b, denoting the number of candies in a missing box. All your numbers b must satisfy inequality 1 ≤ b ≤ 106. It is guaranteed that if there exists a positive integer solution, you can always find such b's meeting the condition. If there are multiple answers, you are allowed to print any of them. Given numbers ai may follow in any order in the input, not necessary in non-decreasing. ai may have stood at any positions in the original set, not necessary on lowest n first positions.", "sample_inputs": ["2\n1\n1", "3\n1\n1\n1", "4\n1\n2\n2\n3"], "sample_outputs": ["YES\n3\n3", "NO", "YES"], "notes": "NoteFor the first sample, the numbers of candies in 4 boxes can be 1, 1, 3, 3. The arithmetic mean, the median and the range of them are all 2.For the second sample, it's impossible to find the missing number of candies.In the third example no box has been lost and numbers satisfy the condition.You may output b in any order."}, "positive_code": [{"source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007\n\nfun main() {\n val (N) = readInts()\n val A = IntArray(N)\n for (i in 0 until N) {\n val (a) = readInts()\n A[i] = a\n }\n A.sort()\n\n fun test(a: IntArray): Boolean {\n for (i in 0 until 3) {\n if (a[i] > a[i + 1]) return false\n }\n for (i in 0 until 4) {\n if (!(1..1_000_000).contains(a[i])) return false\n }\n return 2 * (a[3] - a[0]) == a[1] + a[2] &&\n 4 * (a[3] - a[0]) == a.sum()\n }\n\n if (N == 0) {\n println(\"YES\")\n arrayOf(1, 1, 3, 3).forEach { println(it) }\n } else if (N == 1) {\n val a = A[0]\n println(\"YES\")\n arrayOf(a, 3 * a, 3 * a).forEach { println(it) }\n } else if (N == 2) {\n val a = A[0]\n val b = A[1]\n if (a * 3 >= b) {\n println(\"YES\")\n arrayOf(a * 4 - b, a * 3).forEach { println(it) }\n } else {\n println(\"NO\")\n }\n } else if (N == 3) {\n val arrays = arrayOf(\n intArrayOf(A[0], A[1], A[2], A[0] * 3),\n intArrayOf(A[0], A[1], A[0] * 4 - A[1], A[2]),\n intArrayOf(A[0], A[0] * 4 - A[1], A[1], A[2]),\n intArrayOf(A[2] - (A[0] + A[1]) / 2, A[0], A[1], A[2])\n )\n for (a in arrays) {\n if (test(a)) {\n println(\"YES\")\n val aa = mutableListOf()\n aa.addAll(a.toList())\n A.forEach { aa.remove(it) }\n aa.forEach{ println(it) }\n\n return\n }\n }\n println(\"NO\")\n\n } else {\n if (test(A)) {\n println(\"YES\")\n return\n }\n println(\"NO\")\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nprivate val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n} catch (t: Throwable) {\n false\n}\n\nprivate fun readLn() = readLine()!!\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }.toIntArray()\nprivate fun readLongs() = readStrings().map { it.toLong() }.toLongArray()\nprivate inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n}\nprivate fun debug(a: LongArray) {\n debug{a.joinToString(\" \")}\n}\nprivate fun debug(a: IntArray) {\n debug{a.joinToString(\" \")}\n}\nprivate fun debug(a: BooleanArray) {\n debug{a.map{if(it) 1 else 0}.joinToString(\"\")}\n}\nprivate fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n}"}], "negative_code": [{"source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007\n\nfun main() {\n val (N) = readInts()\n val A = IntArray(N)\n for (i in 0 until N) {\n val (a) = readInts()\n A[i] = a\n }\n A.sort()\n\n fun test(a: IntArray): Boolean {\n for (i in 0 until 3) {\n if (a[i] > a[i + 1]) return false\n }\n for (i in 0 until 4) {\n if (!(0..1_000_000).contains(a[i])) return false\n }\n return a[3] - a[0] == (a[1] + a[2]) / 2 && a[3] - a[0] == a.sum() / 4\n }\n\n if (N == 0) {\n println(\"YES\")\n arrayOf(1, 1, 3, 3).forEach { println(it) }\n } else if (N == 1) {\n val a = A[0]\n println(\"YES\")\n arrayOf(a, 3 * a, 3 * a).forEach { println(it) }\n } else if (N == 2) {\n val a = A[0]\n val b = A[1]\n println(\"YES\")\n arrayOf(4 * a - b, 3 * a).forEach { println(it) }\n } else if (N == 3) {\n val arrays = arrayOf(\n Pair(intArrayOf(A[0], A[1], A[2], A[0] * 3), A[0] * 3),\n Pair(intArrayOf(A[0], A[1], A[0] * 4 - A[1], A[2]), A[0] * 4 - A[1]),\n Pair(intArrayOf(A[0], A[0] * 4 - A[1], A[1], A[2]), A[0] * 4 - A[1]),\n Pair(intArrayOf(A[2] - (A[0] + A[1]) / 2, A[0], A[1], A[2]), A[2] - (A[0] + A[1]) / 2)\n )\n for (a in arrays) {\n if (test(a.first)) {\n println(\"YES\")\n println(a.second)\n return\n }\n }\n println(\"NO\")\n\n } else {\n if (test(A)) {\n println(\"YES\")\n return\n }\n println(\"NO\")\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nprivate val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n} catch (t: Throwable) {\n false\n}\n\nprivate fun readLn() = readLine()!!\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }.toIntArray()\nprivate fun readLongs() = readStrings().map { it.toLong() }.toLongArray()\nprivate inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n}\nprivate fun debug(a: LongArray) {\n debug{a.joinToString(\" \")}\n}\nprivate fun debug(a: IntArray) {\n debug{a.joinToString(\" \")}\n}\nprivate fun debug(a: BooleanArray) {\n debug{a.map{if(it) 1 else 0}.joinToString(\"\")}\n}\nprivate fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n}"}, {"source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007\n\nfun main() {\n val (N) = readInts()\n val A = IntArray(N)\n for (i in 0 until N) {\n val (a) = readInts()\n A[i] = a\n }\n A.sort()\n\n fun test(a: IntArray): Boolean {\n for (i in 0 until 3) {\n if (a[i] > a[i + 1]) return false\n }\n return a[3] - a[0] == (a[1] + a[2]) / 2 && a[3] - a[0] == a.sum() / 4\n }\n\n if (N == 0) {\n println(\"YES\")\n arrayOf(1, 1, 3, 3).forEach { println(it) }\n } else if (N == 1) {\n val a = A[0]\n println(\"YES\")\n arrayOf(a, 3 * a, 3 * a).forEach { println(it) }\n } else if (N == 2) {\n val a = A[0]\n val b = A[1]\n println(\"YES\")\n arrayOf(4 * a - b, 3 * a).forEach { println(it) }\n } else if (N == 3) {\n val arrays = arrayOf(\n Pair(intArrayOf(A[0], A[1], A[2], A[0] * 3), A[0] * 3),\n Pair(intArrayOf(A[0], A[1], A[0] * 4 - A[1], A[2]), A[0] * 4 - A[1]),\n Pair(intArrayOf(A[0], A[0] * 4 - A[1], A[1], A[2]), A[0] * 4 - A[1]),\n Pair(intArrayOf(A[2] - (A[0] + A[1]) / 2, A[0], A[1], A[2]), A[2] - (A[0] + A[1]) / 2)\n )\n for (a in arrays) {\n if (test(a.first)) {\n println(\"YES\")\n println(a.second)\n return\n }\n }\n println(\"NO\")\n\n } else {\n if (test(A)) {\n println(\"YES\")\n return\n }\n println(\"NO\")\n }\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nprivate val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n} catch (t: Throwable) {\n false\n}\n\nprivate fun readLn() = readLine()!!\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }.toIntArray()\nprivate fun readLongs() = readStrings().map { it.toLong() }.toLongArray()\nprivate inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n}\nprivate fun debug(a: LongArray) {\n debug{a.joinToString(\" \")}\n}\nprivate fun debug(a: IntArray) {\n debug{a.joinToString(\" \")}\n}\nprivate fun debug(a: BooleanArray) {\n debug{a.map{if(it) 1 else 0}.joinToString(\"\")}\n}\nprivate fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n}"}], "src_uid": "230e613abf0f6a768829cbc1f1a09219"} {"nl": {"description": "Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record 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 mask of a positive integer n the number that is obtained after successive writing of all lucky digits of number n from the left to the right. For example, the mask of number 72174994 is number 7744, the mask of 7 is 7, the mask of 9999047 is 47. Obviously, mask of any number is always a lucky number.Petya has two numbers — an arbitrary integer a and a lucky number b. Help him find the minimum number c (c > a) such that the mask of number c equals b.", "input_spec": "The only line contains two integers a and b (1 ≤ a, b ≤ 105). It is guaranteed that number b is lucky.", "output_spec": "In the only line print a single number — the number c that is sought by Petya.", "sample_inputs": ["1 7", "100 47"], "sample_outputs": ["7", "147"], "notes": null}, "positive_code": [{"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.*\nprivate fun readLn() = readLine()!! // string\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() //long\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map {it.toLong()} // list of longs\n\nval M = 1e5.toInt()+5\nval MOD = 1e9.toInt() + 7\n\n\nfun msk(r: Int) :Int\n{\n var sol = 0;var exp = 0\n var c = r\n while(c>0)\n {\n if(c%10 == 4 || c%10 == 7)\n {\n var t = c%10\n for(q in 0 until exp) t*= 10\n exp++\n sol += t\n }\n c = c/10\n }\n return sol\n}\n\nfun main() {\n val (a,b) = readInts()\n for(i in (a+1) until 1e7.toInt())\n {\n if(msk(i) == b)\n {\n println(i)\n return\n }\n }\n}"}], "negative_code": [], "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb"} {"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": "fun main(args : Array) {\n val (x1, y1) = readLine()!!.split(' ')\n var n = x1.toInt()\n var m = y1.toInt()\n\n if(n==m){\n println(0)\n }\n else if(m%n!=0){\n println(-1)\n }\n else{\n var a = m/n\n var x = 0\n while(a%2 == 0){\n x=x+1\n a=a/2\n }\n while(a%3 == 0){\n x=x+1\n a=a/3\n }\n if(a==1)\n println(x)\n else\n println(-1)\n }\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //var n = r.readLine()!!.toInt()\n val (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }\n when{\n m%n!=0 -> println(-1)\n else -> {\n var q = m/n\n var two = 0\n var three = 0\n while (q%2==0){\n two++\n q /= 2\n }\n while (q%3==0){\n three++\n q/=3\n }\n if (q==1) println(two+three)\n else println(-1)\n }\n }\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val n: Int = ir.nextInt()\n val m: Int = ir.nextInt()\n var count = 0\n\n if (m % n == 0) {\n var num = m / n\n while (num % 2 == 0 || num % 3 == 0) {\n if (num % 2 == 0)\n num /= 2\n else\n num /= 3\n count++\n }\n\n if (num == 1)\n pw.print(count)\n else\n pw.print(-1)\n\n } else\n pw.print(-1)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val n: Int = ir.nextInt()\n val m: Int = ir.nextInt()\n var count = 0\n\n if (m % n == 0) {\n var num = m / n\n while (num % 2 == 0 || num % 3 == 0)\n if (num % 2 == 0) {\n num /= 2\n count++\n } else if (num % 3 == 0) {\n num /= 3\n count++\n }\n\n if (num == 1)\n pw.print(count)\n else\n pw.print(-1)\n\n } else\n pw.print(-1)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val n: Int = ir.nextInt()\n val m: Int = ir.nextInt()\n var count = 0\n\n if (m % n == 0) {\n var num = m / n\n while (num % 2 == 0 || num % 3 == 0) {\n num /= if (num % 2 == 0)\n 2\n else\n 3\n count++\n }\n\n if (num == 1)\n pw.print(count)\n else\n pw.print(-1)\n\n } else\n pw.print(-1)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val (m, n) = readLongs()\n\n if (n == m) {\n println(0)\n return\n }\n\n if (n % m != 0L || (n % 2 != 0L && n % 3 != 0L)) {\n println(-1)\n return\n }\n\n val leftOver = n.factorize().sorted().toMutableList()\n m.factorize().forEach { leftOver -= it }\n\n println(when {\n leftOver.isEmpty() -> 0\n leftOver.max()!! > 3 -> -1\n else -> leftOver.size\n })\n}\n\nfun readLongs(separator: String = \" \") =\n readStrings(separator).map(String::toLong).toLongArray()\n\nfun readStrings(separator: String = \" \", emptyWords: Boolean = false): Array {\n val line = readLine()!!\n val list = ArrayList()\n var builder = StringBuilder()\n\n for (i in 0..line.length) {\n if (i == line.length || separator.contains(line[i])) {\n if (emptyWords || builder.isNotEmpty()) {\n list.add(builder.toString())\n builder = StringBuilder()\n }\n } else {\n builder.append(line[i])\n }\n }\n\n return list.toTypedArray()\n}\n\nfun Long.factorize(): List {\n var sub = takeIf { it > 1 } ?: return emptyList()\n\n return sequence {\n for (p in Primes.primes) {\n if (sub <= 1) {\n break\n }\n\n while (sub % p == 0L) {\n sub /= p\n yield(p)\n }\n }\n }.toList()\n}\n\nobject Primes {\n const val MAX = 2_000_000\n\n val bitmap: BitSet by lazy { Primes.sieve(MAX) }\n val primes: List by lazy { (1..MAX).filter { isPrime(it) }.toList() }\n\n fun isPrime(num: Int) = bitmap[num - 1]\n\n fun nthPrime(n: Int) = primes[n - 1]\n\n private fun sieve(max: Int): BitSet {\n val primeMap = BitSet(max)\n primeMap.set(0, primeMap.size() - 1)\n primeMap.set(0, false)\n\n for (i in 2..primeMap.size()) {\n if (primeMap[i - 1]) {\n for (j in i + i..primeMap.size() step i) {\n primeMap.set(j - 1, false)\n }\n }\n }\n\n return primeMap\n }\n}"}, {"source_code": "fun main() {\n val (m, n) = readLine()!!.split(\" \").map(String::toLong).toLongArray()\n var path = n / m\n var steps = 0\n\n if (n == m) {\n println(0)\n return\n }\n\n if (n % m != 0L || (n % 2 != 0L && n % 3 != 0L)) {\n println(-1)\n return\n }\n\n while (path % 2 == 0L) {\n steps += 1\n path /= 2\n }\n\n while (path % 3 == 0L) {\n steps += 1\n path /= 3\n }\n\n println(if (path == 1L) steps else -1)\n}\n"}, {"source_code": "import java.util.*\n\nfun main() {\n var sc = Scanner(System.`in`)\n var n = sc.nextInt()\n var m = sc.nextInt()\n if (m%n!=0) {\n print(-1)\n return\n }\n var a = m/n\n var res = 0\n while (a%2==0) {\n a/=2\n res++\n }\n while (a%3==0) {\n a/=3\n res++\n }\n if (a>1) {\n print(-1)\n return\n }\n print(res)\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n val solver = Solver(System.`in`, System.out)\n solver.solve()\n solver.clear()\n}\n\nclass Solver(input: InputStream, output: OutputStream) {\n\n companion object {\n private const val MAX_N = (1e6 + 10).toInt()\n private const val INF = (1e9 + 7).toInt()\n private const val MOD = (1e9 + 7).toInt()\n private const val INF_F = 1e-6\n }\n\n private val reader = Reader(input)\n private val writer = Writer(output)\n\n fun solve() {\n val n = reader.nextInt()\n val m = reader.nextInt()\n if (m % n != 0) {\n writer.println(\"-1\")\n return\n }\n var x = m / n\n var ans = 0\n while (x % 2 == 0) {\n x /= 2\n ans++\n }\n while (x % 3 == 0) {\n x /= 3\n ans++\n }\n writer.println(if (x == 1) ans else -1)\n }\n\n fun clear() {\n writer.close()\n }\n\n private fun gcd(a: Int, b: Int): Int {\n return if (b == 0) a else gcd(b, a % b)\n }\n\n private fun gcd(a: Long, b: Long): Long {\n return if (b == 0L) a else gcd(b, a % b)\n }\n}\n\nclass Reader(input: InputStream) {\n private val reader = BufferedReader(InputStreamReader(BufferedInputStream(input)), 32768)\n private var tokenizer: StringTokenizer? = null\n\n fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt() = next().toInt()\n\n fun nextLong() = next().toLong()\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}\n\nclass Writer(output: OutputStream) {\n private val writer = PrintWriter(BufferedOutputStream(output))\n\n fun println(t: T) {\n writer.println(t)\n }\n\n fun print(t: T) {\n writer.print(t)\n }\n\n fun printIntArray(array: IntArray) {\n array.forEach { writer.print(\"$it \") }\n writer.println()\n }\n\n fun close() {\n writer.close()\n }\n}"}, {"source_code": "fun main() {\n val (n, m) = readInts()\n\n val ans = run {\n if(m % n != 0) return@run -1\n var d = m / n\n var c = 0\n\n while(d % 2 == 0) {\n d /= 2\n c++\n }\n while(d % 3 == 0) {\n d /= 3\n c++\n }\n\n if(d == 1) c else -1\n }\n\n println(ans)\n}\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readStringSeq() = readLn().splitToSequence(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readIntSeq() = readStringSeq().map { it.toInt() }\nfun readIntArray(size: Int) = readIntSeq().iterator().let { i -> IntArray(size) { i.next() } }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readDoubleSeq() = readStringSeq().map { it.toDouble() }\nfun readDoubleArray(size: Int) = readDoubleSeq().iterator().let { i -> DoubleArray(size) { i.next() } }\nfun readLongs() = readStrings().map { it.toLong() }\nfun readLongSeq() = readStringSeq().map { it.toLong() }\nfun readLongArray(size: Int) = readLongSeq().iterator().let { i -> LongArray(size) { i.next() } }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit) { Output().apply(block).nowPrint() }"}, {"source_code": "//package com.happypeople.codeforces.c1141\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) {\n try {\n A1141().run()\n } catch (e: Throwable) {\n println(\"\")\n e.printStackTrace()\n }\n}\n\nclass A1141 {\n fun run() {\n val sc = Scanner(systemIn())\n val n=sc.nextInt()\n val m=sc.nextInt()\n\n val x=minmoves(n, m)\n val ans=if(x>9999) -1 else x\n println(\"$ans\")\n }\n\n fun minmoves(n:Int, m:Int):Int {\n //log(\"minmoves $n $m\")\n if(n==m)\n return 0\n else if(n>m)\n return 10000\n else\n return min(minmoves(n*2, m), minmoves(n*3, m))+1\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}\n"}, {"source_code": "import java.util.*\n\nfun main() {\n\n var (n, m) = readLine()!!.split(\" \").map { it.toLong() }\n\n var result = -1\n if (m % n == 0L) {\n result = 0\n var d = m / n\n while (d % 2 == 0L) {\n d /= 2\n result++\n }\n while (d % 3 == 0L) {\n d /= 3\n result++\n }\n if (d != 1L) {\n result=-1\n }\n }\n println(result)\n\n}"}, {"source_code": "fun main() {\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n val (n, m) = readLongs()\n if (m % n != 0L) return print(-1)\n var moves = 0\n var mult = m / n\n while (mult % 2 == 0L) {\n mult /= 2\n moves++\n }\n while (mult % 3 == 0L) {\n mult /= 3\n moves++\n }\n if (mult != 1L) return print(-1)\n print(moves)\n}"}, {"source_code": "import java.io.*\nimport java.lang.Math.pow\nimport java.util.*\nimport kotlin.math.*\n\nconst val fileSolve = \"distance1\"\nconst val fileInName = \"$fileSolve.in\"\nconst val fileOutName = \"$fileSolve.out\"\n\nfun dist(line: Line, p: Vect) =\n abs(line.a * p.x + line.b * p.y - line.c) /\n sqrt(line.a * line.a + line.b * line.b)\n\nfun bisector(x: Vect, yy: Vect, zz: Vect): Line {\n val y = x + (yy - x).normir()\n val z = x + (zz - x).normir()\n var mid = (y + z) / 2\n return lineFrom2point(x, mid)\n}\n\nvar cash = IntArray(2_000_000)\n\nfun solve() {\n var a = readLong()\n var b = readLong()\n\n if (b % a != 0L) {\n print(-1)\n return\n }\n\n var k = b / a\n var count = 0\n while (k > 1L) {\n if (k % 2 == 0L)\n k /= 2\n else if (k % 3 == 0L)\n k /= 3\n else {\n print(-1)\n return\n }\n count++\n }\n print(count)\n}\n\nfun lineFrom2point(point1: Vect, point2: Vect): Line {\n var p1 = point1\n var p2 = point2\n var A = p2.y - p1.y\n var B = p1.x - p2.x\n var C = -(p2.x * A + p2.y * B)\n return Line(A, B, C)\n}\n\nfun Double.sign() = if (this >= 0) 1.0 else -1.0\noperator fun String.times(x: Int): String {\n var c = this\n return buildString {\n for (i in 1..x)\n append(c)\n }\n}\noperator fun Int.times(s: String) = s * this\n\nfun squre2(vs: Array): Double {\n var tans = 0.0\n for (i in 1 until vs.size)\n tans += vs[i] trap2 vs[i - 1]\n\n tans += vs[0] trap2 vs[vs.lastIndex]\n return abs(tans)\n}\nclass Line {\n var a: Double = 0.0\n var b: Double = 0.0\n var c: Double = 0.0\n constructor(aa: Double, bb: Double, cc: Double) {\n a = aa; b = bb; c = cc\n }\n constructor() {\n a = readDouble(); b = readDouble(); c = readDouble()\n }\n\n override fun toString() = \"$a $b $c\"\n}\nclass Vect (var x: Double, var y: Double) {\n operator fun plus(b: Vect) = Vect(x + b.x, y + b.y)\n operator fun times(b: Int) = Vect(x * b, y * b)\n operator fun minus(b: Vect) = Vect(x - b.x, y - b.y)\n operator fun div(b: Int) = Vect(x / b, y / b)\n operator fun div(b: Double) = Vect(x / b, y / b)\n infix fun scalar(b: Vect) = x * b.x + y * b.y\n infix fun cross(b: Vect) = x * b.y - y * b.x\n fun rotated90() = Vect(-y, x)\n fun length() = sqrt(x * x + y * y)\n infix fun angle(b: Vect) =\n atan2(cross(b).toDouble(), scalar(b).toDouble())\n fun polarAngel() = Vect(1.0, 0.0) angle this\n infix fun trap2(b: Vect) = (b.x - x) * (y + b.y)\n override fun toString() = \"$x $y\"\n fun normir() = this / length()\n}\noperator fun Int.times(a: Vect) = a * this\nfun readVect() = Vect(readDouble(), readDouble())\nfun printDiv2(a: Long) {\n val d = a / 2\n out.print(d)\n if (a % 2 != 0L)\n out.println(\".5\")\n else\n out.println(\".0\")\n}\n\nvar MOD = 1_000_000_007\nvar MODL = MOD.toLong()\n\ninline fun binarySearchL(left: Int, right: Int, check: (Int) -> Boolean): Int {\n var l = left\n var r = right\n while(r - l > 1) {\n val mid = (r + l) shr 1\n if (check(mid))\n l = mid\n else\n r = mid\n }\n return l\n}\n\ninline fun binarySearchR(left: Int, right: Int, check: (Int) -> Boolean): Int {\n var l = left\n var r = right\n while(r - l > 1) {\n val mid = (r + l) shr 1\n if (check(mid))\n r = mid\n else\n l = mid\n }\n return r\n}\n\nfun binmult(a : Long, b : Long, m : Long = MODL) : Long {\n if (a == 0L)\n return 0\n else if (a % 2 == 1L) {\n val prev = binmult(a - 1, b, m)\n return (prev + b) % m\n } else {\n val half = binmult(a shl 1, b, m)\n return (half shr 1) % m\n }\n}\n\nfun binmult(a : Int, b : Int, m : Int = MOD) : Int {\n if (a == 0)\n return 0\n else if (a % 2 == 1) {\n return (binmult(a - 1, b, m) + b) % m\n } else {\n return (binmult(a shr 1, b, m) shl 1) % m\n }\n}\n\nfun binpow(a: Long, n: Long, mod: Long = MODL): Long {\n var a = a\n var n = n\n var res: Long = 1\n while (n > 0) {\n if (n and 1 == 1L) {\n res = binmult(res, a, mod)\n res %= mod\n n--\n } else {\n a %= mod\n n = n shr 1\n }\n a = binmult(a, a, mod)\n }\n return res % mod\n}\n\nfun binpow(a: Int, n: Int, mod: Int = MOD): Int {\n var a = a\n var n = n\n var res = 1\n while (n > 0) {\n if (n and 1 == 1) {\n res = binmult(res, a, mod)\n res %= mod\n n--\n } else {\n a = binmult(a, a, mod)\n a %= mod\n n = n shr 1\n }\n }\n return res % mod\n}\n\ninfix fun Long.pow(n : Long) = binpow(this, n)\ninfix fun Int.pow(n : Int) = binpow(this, n)\ninfix fun Int.mlt(b : Int) = binmult(this, b)\ninfix fun Long.mlt(b : Long) = binmult(this, b)\nfun Boolean.t(a: Int, b: Int) = if (this) a else b\nfun Long.toBinaryStr(a: Long = this) = java.lang.Long.toBinaryString(a) ?: \"\"\nfun Int.toBinaryStr(a: Int = this) = Integer.toBinaryString(a) ?: \"\"\n\nvar out = if (File(fileInName).exists())\n PrintWriter(fileOutName)\n else\n PrintWriter(System.out)\nvar br = if (File(fileInName).exists())\n BufferedReader(FileReader(fileInName))\n else\n BufferedReader(InputStreamReader(System.`in`))\nvar st = StringTokenizer(\"\")\nval delimiter = \" \"\n\nfun main(args: Array) {\n solve()\n out.close()\n}\n\nfun readString(): String {\n if (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine(), delimiter)\n return st.nextToken()\n}\n\nfun print(vararg ans : T, sprt : String = \" \") = ans.forEach { out.print(\"${it.toString()}$sprt\") }\nfun print(vararg ints : Int, sprt : String = \" \") = ints.forEach { out.print(\"$it$sprt\") }\nfun print(vararg lons : Long, sprt : String = \" \") = lons.forEach { out.print(\"$it$sprt\") }\n\nfun readLine() = br.readLine()\nfun readInt() = readString().toInt()\nfun readLong() = readString().toLong()\nfun readDouble() = readString().toDouble()\nfun readBool() = readString().toBoolean()\nfun readFloat() = readString().toFloat()\n\nfun readInts() = readLine().split(' ').map(String::toInt).toIntArray()\nfun readLongs() = readLine().split(' ').map(String::toLong).toLongArray()"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n\n val x = scan.nextInt()\n val y = scan.nextInt()\n\n if (x == y){\n println(\"0\")\n return\n }\n\n if (y % x != 0){\n println(\"-1\")\n return\n }\n \n //handle not divided here\n var result = y / x\n var counter = 0\n var notDivided = false\n\n while (result % 3 == 0){\n result /= 3\n counter++\n }\n\n while (result % 2 == 0){\n result /= 2\n counter++\n }\n\n if (counter == 0 || result != 1 || notDivided){\n println(\"-1\")\n } else {\n println(counter)\n }\n}"}, {"source_code": "import kotlin.system.exitProcess\n\nfun readInts() = readLine()!!.split(' ').map(String::toInt)\nfun rec(x: Int, m:Int, cur:Int){\n if(x == m){\n print(cur)\n exitProcess(0)\n }\n if(x * 2 <= m)\n rec(x * 2, m, cur + 1)\n if(x * 3 <= m)\n rec(x * 3, m, cur + 1)\n}\nfun main(args: Array) {\n var (n, m) = readLine()!!.split(' ').map(String::toInt)\n rec(n, m, 0)\n print(-1)\n}\n\n\n"}, {"source_code": "import kotlin.math.ceil\nimport kotlin.reflect.jvm.internal.impl.resolve.constants.LongValue\n\nfun main() {\n var ip = readLine()\n var a = ip?.split(\" \")\n\n var n = a?.get(0)?.toInt()\n var m = a?.get(1)?.toInt()\n\n\n if(m!! % n!! !=0)\n print(-1)\n else {\n var rem = m/n\n var ct = 0\n while(rem>=1){\n rem = rem.div(\n if(rem%2==0) 2\n else if(rem%3==0) 3\n else break\n )\n ct++\n }\n if(rem==1)\n println(ct)\n else\n println(-1)\n }\n\n\n}"}], "negative_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val n: Int = ir.nextInt()\n val m: Int = ir.nextInt()\n var count = 0\n\n if (m % n == 0) {\n var num = m / n\n while (num % 2 == 0 || num % 3 == 0) {\n if (num % 2 == 0) {\n num /= 2\n count++\n } else if (num % 3 == 0) {\n num /= 3\n count++\n }\n }\n pw.print(count)\n } else\n pw.print(-1)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val n: Int = ir.nextInt()\n val m: Int = ir.nextInt()\n var count = 0\n\n if (m % n == 0) {\n var num = m / n\n while (num % 2 == 0 || num % 3 == 0)\n if (num % 2 == 0)\n num /= 2\n else\n num /= 3\n count++\n\n if (num == 1)\n pw.print(count)\n else\n pw.print(-1)\n\n } else\n pw.print(-1)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val n: Int = ir.nextInt()\n val m: Int = ir.nextInt()\n var count = 0\n\n var num = m / n\n while (num % 2 == 0 || num % 3 == 0) {\n if (num % 2 == 0)\n num /= 2\n else\n num /= 3\n count++\n }\n\n if (num == 1)\n pw.print(count)\n else\n pw.print(-1)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val (m, n) = readLongs()\n\n if (n % m != 0L) {\n println(-1)\n return\n }\n\n val leftOver = n.factorize().sorted().toMutableList()\n m.factorize().forEach { leftOver -= it }\n\n println(when {\n leftOver.isEmpty() -> 0\n leftOver.max()!! > 3 -> -1\n else -> leftOver.size\n })\n}\n\nfun readLongs(separator: String = \" \") =\n readStrings(separator).map(String::toLong).toLongArray()\n\nfun readStrings(separator: String = \" \", emptyWords: Boolean = false): Array {\n val line = readLine()!!\n val list = ArrayList()\n var builder = StringBuilder()\n\n for (i in 0..line.length) {\n if (i == line.length || separator.contains(line[i])) {\n if (emptyWords || builder.isNotEmpty()) {\n list.add(builder.toString())\n builder = StringBuilder()\n }\n } else {\n builder.append(line[i])\n }\n }\n\n return list.toTypedArray()\n}\n\nfun Long.factorize(): List {\n var sub = takeIf { it > 1 } ?: return emptyList()\n\n return sequence {\n for (p in Primes.primes) {\n if (sub <= 1) {\n break\n }\n\n while (sub % p == 0L) {\n sub /= p\n yield(p)\n }\n }\n }.toList()\n}\n\nobject Primes {\n const val MAX = 2_000_000\n\n val bitmap: BitSet by lazy { Primes.sieve(MAX) }\n val primes: List by lazy { (1..MAX).filter { isPrime(it) }.toList() }\n\n fun isPrime(num: Int) = bitmap[num - 1]\n\n fun nthPrime(n: Int) = primes[n - 1]\n\n private fun sieve(max: Int): BitSet {\n val primeMap = BitSet(max)\n primeMap.set(0, primeMap.size() - 1)\n primeMap.set(0, false)\n\n for (i in 2..primeMap.size()) {\n if (primeMap[i - 1]) {\n for (j in i + i..primeMap.size() step i) {\n primeMap.set(j - 1, false)\n }\n }\n }\n\n return primeMap\n }\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n\n var (n, m) = readLine()!!.split(\" \").map { it.toLong() }\n\n var result = -1\n if (m % n == 0L) {\n result = 0\n var d = m / n\n while (d % 2 == 0L) {\n d /= 2\n result++\n }\n while (d % 3 == 0L) {\n d /= 3\n result++\n }\n if (d != 1L) {\n println(-1)\n }\n }\n println(result)\n\n}"}, {"source_code": "fun main() {\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n val (n, m) = readLongs()\n if (m % n != 0L) return print(-1)\n var moves = 0\n var mult = m / n\n while (mult % 2 == 0L) {\n mult /= 2\n moves++\n }\n while (mult % 3 == 0L) {\n mult /= 3\n moves++\n }\n print(moves)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n\n val x = scan.nextInt()\n val y = scan.nextInt()\n\n if (x == y){\n println(\"0\")\n return\n }\n var result = y / x\n var counter = 0\n\n while (result % 3 == 0){\n result /= 3\n counter++\n }\n\n while (result % 2 == 0 && result > 0){\n result /= 2\n counter++\n }\n\n if (counter == 0){\n println(\"-1\")\n } else {\n println(counter)\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n\n val x = scan.nextInt()\n val y = scan.nextInt()\n\n if (x == y){\n println(\"0\")\n return\n }\n var result = y / x\n var counter = 0\n\n while (result % 3 == 0){\n result /= 3\n counter++\n }\n\n while (result % 2 == 0 && result > 0){\n result /= 2\n counter++\n }\n\n if (counter == 0 || result != 1){\n println(\"-1\")\n } else {\n println(counter)\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n\n val x = scan.nextInt()\n val y = scan.nextInt()\n\n if (x == y){\n println(\"0\")\n }\n var result = y / x\n var counter = 0\n\n while (result % 3 == 0){\n result /= 3\n counter++\n }\n\n while (result % 2 == 0 && result > 0){\n result /= 2\n counter++\n }\n\n if (counter == 0){\n println(\"-1\")\n } else {\n println(counter)\n }\n}"}], "src_uid": "3f9980ad292185f63a80bce10705e806"} {"nl": {"description": "Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.Now he wonders what is an average value of sum of digits of the number A written in all bases from 2 to A - 1.Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10.", "input_spec": "Input contains one integer number A (3 ≤ A ≤ 1000).", "output_spec": "Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator.", "sample_inputs": ["5", "3"], "sample_outputs": ["7/3", "2/1"], "notes": "NoteIn the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively."}, "positive_code": [{"source_code": "import java.util.*\nimport kotlin.math.max\n\nprivate val scanner = Scanner(System.`in`)\nprivate val size = 100_000 + 10\n\nfun gcd(a: Int, b: Int): Int =\n if (b > 0)\n gcd(b, a % b)\n else\n a\n\nfun main() {\n scanner.apply {\n val A = nextInt()\n var sum = 0\n for (base in 2 until A) {\n var cursum = 0\n var cura = A\n while (cura > 0) {\n cursum += cura % base\n cura /= base\n }\n sum += cursum\n }\n val gcd = gcd(sum, A - 2)\n println(\"${sum/gcd}/${(A-2)/gcd}\")\n }\n}\n"}], "negative_code": [], "src_uid": "1366732dddecba26db232d6ca8f35fdc"} {"nl": {"description": "In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take d minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get n cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.", "input_spec": "The only line contains four integers n, t, k, d (1 ≤ n, t, k, d ≤ 1 000) — the number of cakes needed, the time needed for one oven to bake k cakes, the number of cakes baked at the same time, the time needed to build the second oven. ", "output_spec": "If it is reasonable to build the second oven, print \"YES\". Otherwise print \"NO\".", "sample_inputs": ["8 6 4 5", "8 6 4 6", "10 3 11 4", "4 2 1 4"], "sample_outputs": ["YES", "NO", "NO", "YES"], "notes": "NoteIn the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven."}, "positive_code": [{"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.ceil\nimport kotlin.math.pow\nimport kotlin.math.sqrt\n\n//private val INPUT = File(\"input.txt\").inputStream()\n//private val OUTPUT = File(\"output.txt\").outputStream()\nprivate val INPUT = System.`in`\nprivate val OUTPUT = System.out\n\nprivate val bufferedReader = INPUT.bufferedReader()\nprivate val outputWriter = PrintWriter(OUTPUT, false)\nprivate fun readLn() = bufferedReader.readLine()!!\n\nprivate fun readList() = readLn().split(' ')\nprivate var tokenizer = StringTokenizer(\"\")\nprivate fun read(): String {\n while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(readLn(), \" \")\n return tokenizer.nextToken()\n}\n\nprivate fun readInt() = read().toInt()\nprivate fun readLong() = read().toLong()\nprivate fun readDouble() = read().toDouble()\n\nprivate fun readIntList() = readList().map { it.toInt() }\nprivate fun readLongList() = readList().map { it.toLong() }\nprivate fun readDoubleList() = readList().map { it.toDouble() }\n\nprivate fun readIntArray(n: Int = 0) =\n if (n == 0) readList().run { IntArray(size) { get(it).toInt() } } else IntArray(n) { readInt() }\n\nprivate fun readLongArray(n: Int = 0) =\n if (n == 0) readList().run { LongArray(size) { get(it).toLong() } } else LongArray(n) { readLong() }\n\nprivate fun readDoubleArray(n: Int = 0) =\n if (n == 0) readList().run { DoubleArray(size) { get(it).toDouble() } } else DoubleArray(n) { readDouble() }\n\n\nprivate fun Int.modPositive(other: Int): Int = if (this % other < 0) ((this % other) + other) else (this % other)\n\n\nprivate class `CF799-D2-A` {\n fun solveTestCase(): String {\n var n = readInt()\n val t = readInt()\n val k = readInt()\n val d = readInt()\n\n var currt = 0\n while(currt <= d) {\n n -= k\n currt += t\n }\n\n return when (n > 0) {\n true -> \"YES\"\n false -> \"NO\"\n }\n\n }\n}\n\nfun main(args: Array) {\n\n outputWriter.println(\n `CF799-D2-A`()\n .solveTestCase()\n )\n\n outputWriter.flush()\n}"}, {"source_code": "import java.util.Scanner;\nimport java.util.Arrays;\nimport java.util.*; \nimport java.math.*;\nimport java.io.*;\n\nfun main(args: Array) {\n var s = Scanner(System.`in`)\n var cakes = s.nextInt()\n var oven1 = s.nextInt()\n var nocake = s.nextInt()\n var oven2 = s.nextInt()\n Carrotscake(cakes ,oven1 , nocake,oven2)\n \n}\n\nfun Carrotscake(cakes:Int,oven1:Int,nocake:Int,oven2:Int){\n var timeforoven1 = (cakes+nocake-1)/nocake\n \n var o1= 0 \n var o2= oven2\n for(i in 0 until timeforoven1 ){\n if(o1 <= o2) o1 += oven1;\n else o2 += oven1;\n }\n \n \n if (maxOf(o1, o2) < timeforoven1 * oven1)\n println(\"YES\")\n else\n println(\"NO\")\n \n \n}"}, {"source_code": "import java.util.*;\n\nfun main(args: Array){\n var input = Scanner(System.`in`);\n var n=input.nextInt();\n var t=input.nextInt();\n var k=input.nextInt();\n var d=input.nextInt();\n \n if (((d / t) + 1) * k >= n) print(\"NO\");\n else print(\"YES\");\n}"}, {"source_code": "fun main(vararg args: String) {\n\n infix fun Int.ceilDiv(that: Int) = (this + that - 1) / that\n\n val (n, t, k, d) = readLine()!!.split(' ').map(String::toInt)\n println(if ((n ceilDiv k) * t > d + t) \"YES\" else \"NO\")\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val (n, t, k, d) = br.readLine().split(\" \").map { it.toInt() }\n val noExtraOven = t*((n + k - 1)/k)\n println(\n if (k >= n) \"NO\"\n else if (d + t < noExtraOven) \"YES\"\n else \"NO\"\n )\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.ceil\n\nfun main() {\n val input = Scanner(System.`in`)\n val n = input.nextFloat()\n val t = input.nextFloat()\n val k = input.nextFloat()\n val d = input.nextFloat()\n val timeOneOven= (ceil(n.div(k))).times(t).minus(t)\n if (timeOneOven > d)\n println(\"YES\")\n else\n println(\"NO\")\n}\n"}, {"source_code": "import java.lang.AssertionError\nimport java.util.*\n \nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n \nprivate fun myAssert(x: Boolean) {\n if (!x) {\n throw AssertionError()\n }\n}\n\nfun main(args: Array) {\n// var s = Scanner(System.`in`)\n var (n, t, k, d) = readInts()\n // t minutes for an over to bake k carrot cakes\n // needs at least n cakes\n // d minutes to build a new oven\n // 8 6 4 5\n // 6 minutes to make 4 cakes, 5 minutes to build a new oven\n var tt = t\n var kk = k\n while (kk < n) {\n kk += k\n tt += t\n }\n if (t + d < tt) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}\n"}, {"source_code": "fun main() {\n val (numCakes, bakingTime, numCakesPerTurn, buildingTime) = readLine()!!.split(\" \").map(String::toInt)\n val oneOvenTime = bakingTime * (numCakes / numCakesPerTurn + if (numCakes % numCakesPerTurn == 0) 0 else 1)\n print(if (buildingTime + bakingTime < oneOvenTime) \"YES\" else \"NO\")\n}"}, {"source_code": "import kotlin.math.*\n\nfun main() {\n var (n, t, k, d) = readLine()!!.split(\" \").map{ it.toInt() }\n var time_A = ceil(n.toDouble() / k) * t\n var time_B = 0\n var oven1 = false\n var oven2 = false\n while(true) {\n if(time_B % t == 0){\n oven1 = false\n if(n > 0) {\n n -= k\n oven1 = true\n }\n }\n if(time_B >= d && (time_B - d) % t == 0) {\n oven2 = false\n if(n > 0) {\n n -= k\n oven2 = true\n }\n }\n if(!oven1 && !oven2) break\n time_B++\n }\n if(time_A <= time_B) println(\"NO\")\n else println(\"YES\")\n}"}], "negative_code": [{"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.ceil\nimport kotlin.math.pow\nimport kotlin.math.sqrt\n\n//private val INPUT = File(\"input.txt\").inputStream()\n//private val OUTPUT = File(\"output.txt\").outputStream()\nprivate val INPUT = System.`in`\nprivate val OUTPUT = System.out\n\nprivate val bufferedReader = INPUT.bufferedReader()\nprivate val outputWriter = PrintWriter(OUTPUT, false)\nprivate fun readLn() = bufferedReader.readLine()!!\n\nprivate fun readList() = readLn().split(' ')\nprivate var tokenizer = StringTokenizer(\"\")\nprivate fun read(): String {\n while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(readLn(), \" \")\n return tokenizer.nextToken()\n}\n\nprivate fun readInt() = read().toInt()\nprivate fun readLong() = read().toLong()\nprivate fun readDouble() = read().toDouble()\n\nprivate fun readIntList() = readList().map { it.toInt() }\nprivate fun readLongList() = readList().map { it.toLong() }\nprivate fun readDoubleList() = readList().map { it.toDouble() }\n\nprivate fun readIntArray(n: Int = 0) =\n if (n == 0) readList().run { IntArray(size) { get(it).toInt() } } else IntArray(n) { readInt() }\n\nprivate fun readLongArray(n: Int = 0) =\n if (n == 0) readList().run { LongArray(size) { get(it).toLong() } } else LongArray(n) { readLong() }\n\nprivate fun readDoubleArray(n: Int = 0) =\n if (n == 0) readList().run { DoubleArray(size) { get(it).toDouble() } } else DoubleArray(n) { readDouble() }\n\n\nprivate fun Int.modPositive(other: Int): Int = if (this % other < 0) ((this % other) + other) else (this % other)\n\n\nprivate class `CF799-D2-A` {\n fun solveTestCase(): String {\n val n = readInt()\n val t = readInt()\n val k = readInt()\n val d = readInt()\n\n val countWithoutBuilding = ceil(n.toDouble()/k)\n val countBakeBeforeBuilt = ceil(t.toDouble()/d)\n \n return when ((countBakeBeforeBuilt+1) >= countWithoutBuilding) {\n true -> \"NO\"\n false -> \"YES\"\n }\n }\n}\n\nfun main(args: Array) {\n\n outputWriter.println(\n `CF799-D2-A`()\n .solveTestCase()\n )\n\n outputWriter.flush()\n}"}, {"source_code": "import java.util.Scanner;\nimport java.util.Arrays;\nimport java.util.*; \nimport java.math.*;\nimport java.io.*;\n\nfun main(args: Array) {\n var s = Scanner(System.`in`)\n var cakes = s.nextInt()\n var oven1 = s.nextInt()\n var nocake = s.nextInt()\n var oven2 = s.nextInt()\n Carrotscake(cakes ,oven1 , nocake,oven2)\n \n}\n\nfun Carrotscake(cakes:Int,oven1:Int,nocake:Int,oven2:Int){\n var timeforoven1 = (cakes/nocake)*oven1\n var timeforoven2 =oven1 +oven2\n \n if(timeforoven1<=timeforoven2){\n println(\"NO\") \n }else{\n println(\"YES\")\n }\n \n \n}"}, {"source_code": "import java.util.*\nimport kotlin.math.ceil\n\nfun main() {\n val input = Scanner(System.`in`)\n val n = input.nextFloat()\n val t = input.nextFloat()\n val k = input.nextFloat()\n val d = input.nextFloat()\n var done = 0F\n var counter1 = 0\n while (done d) {\n done += k\n }\n done += k\n counter++\n }\n val t2 = if (t - d >= 0)\n (counter * t) - (t - d)\n else\n counter * t\n if (t2 < t1)\n println(\"YES\")\n else\n println(\"NO\")\n}\n"}, {"source_code": "import java.util.*\n\nfun main() {\n val input = Scanner(System.`in`)\n val n = input.nextFloat()\n val t = input.nextFloat()\n val k = input.nextFloat()\n val d = input.nextFloat()\n val timeOneOven= ((n.div(k)).times(t)).minus(t)\n if (timeOneOven > d)\n println(\"YES\")\n else\n println(\"NO\")\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.math.ceil\n\nfun main() {\n val input = Scanner(System.`in`)\n val n = input.nextFloat()\n val t = input.nextFloat()\n val k = input.nextFloat()\n val d = input.nextFloat()\n var done = 0F\n var counter1 = 0\n while (done d) {\n done += k\n }\n done += k\n counter++\n }\n val t2 = if (t - d > 0)\n (counter * t) - (t - d)\n else\n counter * t\n if (t2 < t1)\n println(\"YES\")\n else\n println(\"NO\")\n}\n"}, {"source_code": "import java.util.*\n\nfun main() {\n val input = Scanner(System.`in`)\n val n = input.nextInt()\n val t = input.nextInt()\n val k = input.nextInt()\n val d = input.nextInt()\n val one = (t*n).div(k)\n val two = t+d\n if(two= two2)\n two1\n else\n two2\n if (two < one)\n println(\"YES\")\n else\n println(\"NO\")\n}\n"}, {"source_code": "fun main() {\n var (n, t, k, d) = readLine()!!.split(\" \").map{ it.toInt() }\n var time_A = n / k * t\n var time_B = 0\n var oven1 = false\n var oven2 = false\n while(true) {\n if(time_B % t == 0){\n oven1 = false\n if(n > 0) {\n n -= k\n oven1 = true\n }\n }\n if(time_B >= d && (time_B - d) % t == 0) {\n oven2 = false\n if(n > 0) {\n n -= k\n oven2 = true\n }\n }\n if(!oven1 && !oven2) break\n time_B++\n }\n if(time_A <= time_B) println(\"NO\")\n else println(\"YES\")\n}"}, {"source_code": "fun main() {\n var (n, t, k, d) = readLine()!!.split(\" \").map{ it.toInt() }\n var time_A = n / k * t\n var time_B = 0\n var oven1 = false\n var oven2 = false\n while(true) {\n if(time_B % t == 0){\n oven1 = false\n if(n > 0) {\n n -= k\n oven1 = true\n }\n }\n if(time_B >= d && time_B % d == 0) {\n oven2 = false\n if(n > 0) {\n n -= k\n oven2 = true\n }\n }\n if(!oven1 && !oven2) break\n time_B++\n }\n if(time_A <= time_B) println(\"NO\")\n else println(\"YES\")\n}"}], "src_uid": "32c866d3d394e269724b4930df5e4407"} {"nl": {"description": "Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.For each two integer numbers a and b such that l ≤ a ≤ r and x ≤ b ≤ y there is a potion with experience a and cost b in the store (that is, there are (r - l + 1)·(y - x + 1) potions).Kirill wants to buy a potion which has efficiency k. Will he be able to do this?", "input_spec": "First string contains five integer numbers l, r, x, y, k (1 ≤ l ≤ r ≤ 107, 1 ≤ x ≤ y ≤ 107, 1 ≤ k ≤ 107).", "output_spec": "Print \"YES\" without quotes if a potion with efficiency exactly k can be bought in the store and \"NO\" without quotes otherwise. You can output each of the letters in any register.", "sample_inputs": ["1 10 1 10 1", "1 5 6 10 1"], "sample_outputs": ["YES", "NO"], "notes": null}, "positive_code": [{"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val l = sc.nextLong()\n val r = sc.nextLong()\n val x = sc.nextLong()\n val y = sc.nextLong()\n val k = sc.nextLong()\n\n for(i in x..y){\n if( i * k in l..r ){\n println(\"YES\")\n return\n }\n }\n println(\"NO\")\n}"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"unused\", \"UnusedImport\")\n\nimport java.io.BufferedReader\nimport java.io.FileReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nval ONLINE = System.getProperty(\"ONLINE_JUDGE\") != null\nval inp = BufferedReader(if (ONLINE) InputStreamReader(System.`in`) else FileReader(\"in.txt\"))\n\ninline fun readTokens() = inp.readLine()!!.split(' ')\ninline fun readInts() = readTokens().map { it.toInt() }\ninline fun readLongs() = readTokens().map { it.toLong() }\ninline fun readInt() = inp.readLine()!!.toInt()\ninline fun readLine() = inp.readLine()!!\n\ntailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)\n\nfun main(args: Array) {\n val (l, r, x, y, k) = readLongs()\n val lr = l..r\n for (z in x..y) {\n if (k * z in lr) {\n println(\"YES\")\n return\n }\n }\n println(\"NO\")\n}"}, {"source_code": "import java.lang.String.format\nimport java.util.*\nimport kotlin.math.*\nimport kotlin.system.exitProcess\n \nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\nfun main(){\n val reader=Scanner(System.`in`)\n var (l,r,x,y,k)=readLongs()\n for(i in x until y+1){\n if(i*k>=l&&i*k<=r){\n print(\"YES\")\n return\n }\n }\n print(\"NO\")\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun solve() {\n var l = nextInt()\n var r = nextInt()\n var x = nextInt()\n var y = nextInt()\n var k = nextInt()\n var ok = false\n for (b in x..y) {\n if(b * 1L * k in l..r) {\n ok = true\n }\n }\n pw.println(if(ok) \"yes\" else \"no\")\n}\n\nfun hasNext() : Boolean {\n while (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine() ?: return false)\n return true\n}\n\nfun next() = if(hasNext()) st.nextToken()!! else throw RuntimeException(\"No tokens\")\n\nfun nextInt() = next().toInt()\n\nfun nextLong() = next().toLong()\n\nfun nextLine() = if(hasNext()) st.nextToken(\"\\n\") else throw RuntimeException(\"No tokens\")\n\nfun nextArray(n : Int) = IntArray(n,{nextInt()})\n\nval ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n\nval br = when(ONLINE_JUDGE) {\n true -> BufferedReader(InputStreamReader(System.`in`))\n else -> BufferedReader(FileReader(\"in.txt\"))\n}\n\nval pw = when(ONLINE_JUDGE) {\n true -> PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))\n else -> PrintWriter(BufferedWriter(FileWriter(\"out.txt\")))\n}\n\nvar st = StringTokenizer(\"\")\n\nfun main(args: Array) {\n var start = System.currentTimeMillis()\n solve()\n pw.close()\n br.close()\n if(!ONLINE_JUDGE)\n System.err.println(\"${System.currentTimeMillis() - start} ms\")\n}"}, {"source_code": "fun main() {\n val (l, r, x, y, k) = readLine()!!.split(\" \").map(String::toFloat)\n var a = l\n var b = x\n while (a <= r && b <= y) {\n when {\n a / b == k -> {\n print(\"YES\")\n return\n }\n a / b > k -> b++\n a / b < k -> a++\n }\n }\n print(\"NO\")\n}"}], "negative_code": [{"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val l = sc.nextInt()\n val r = sc.nextInt()\n val x = sc.nextInt()\n val y = sc.nextInt()\n val k = sc.nextInt()\n\n for(i in x..y){\n if( i * k in l..r ){\n println(\"YES\")\n return\n }\n }\n println(\"NO\")\n}"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"unused\", \"UnusedImport\")\n\nimport java.io.BufferedReader\nimport java.io.FileReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nval ONLINE = System.getProperty(\"ONLINE_JUDGE\") != null\nval inp = BufferedReader(if (ONLINE) InputStreamReader(System.`in`) else FileReader(\"in.txt\"))\n\ninline fun readTokens() = inp.readLine()!!.split(' ')\ninline fun readInts() = readTokens().map { it.toInt() }\ninline fun readInt() = inp.readLine()!!.toInt()\ninline fun readLine() = inp.readLine()!!\n\ntailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)\n\nfun main(args: Array) {\n val (l, r, x, y, k) = readInts()\n val lr = l..r\n for (z in x..y) {\n if (k * z in lr) {\n println(\"YES\")\n return\n }\n }\n println(\"NO\")\n}"}], "src_uid": "1110d3671e9f77fd8d66dca6e74d2048"} {"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": "import java.lang.StringBuilder\nimport java.util.Scanner\n\nfun main() {\n\n val sc = Scanner(System.`in`)\n val fir : String = sc.next()\n val sec : String = sc.next()\n val thi : String = sc.next()\n val fou : String = sc.next()\n val arr = arrayOf(fir, sec, thi, fou)\n\n for (i in 1 until 4) {\n for (j in 1 until 4) {\n var sharp = 0\n var dot = 0\n\n if (arr[i - 1][j - 1] == '#') sharp++\n else dot++\n\n if (arr[i][j - 1] == '#') sharp++\n else dot++\n\n if (arr[i - 1][j] == '#') sharp++\n else dot++\n\n if (arr[i][j] == '#') sharp++\n else dot++\n\n if (sharp > 2 || dot > 2) {\n print(\"YES\")\n return\n }\n\n }\n }\n\n print(\"NO\")\n\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val square = List(4){br.readLine().map { if (it == '#') 1 else 0}}\n var possible = false\n for (i in 0 .. 2){\n for (j in 0 .. 2){\n val sum = square[i][j] + square[i][j + 1] +\n square[i + 1][j] + square[i + 1][j + 1]\n if (sum != 2) {\n possible = true\n break\n }\n }\n if (possible) break\n }\n println(if (possible) \"YES\" else \"NO\")\n}"}, {"source_code": " //ismail moussi\nvar c=Array(4)\n{\n CharArray(4)\n}\nfun rech(i:Int,j:Int):Boolean\n{\n if(i<3&&j<3)\n return c[i][j] == c[i][j + 1] && c[i][j] == c[i + 1][j] && c[i][j] == c[i + 1][j + 1]\n else\n return false\n}\nfun chek(): Boolean\n{\n for(i in 0..3)\n {\n for(j in 0..3)\n {\n if(rech(i,j))\n return true\n }\n }\n return false\n}\n fun main() {\n for (i in 0..3) {\n c[i] = readLine()!!.toCharArray()\n }\n var bool = chek()\n if (bool) {\n print(\"YES\")\n return\n } else {\n for (i in 0..3) {\n for (j in 0..3) {\n var old = c[i][j]\n when (c[i][j])\n {\n '.'->c[i][j] = '#'\n '#'-> c[i][j] = '.'\n }\n if (chek()) {\n bool = true\n }\n c[i][j] = old\n }\n }\n }\n if (bool)\n print(\"YES\")\n else print(\"NO\")\n }"}, {"source_code": "fun main() {\n fun Boolean.toInt() = if (this) 1 else 0\n val board = Array(4) { readLine()!! }\n for (r in 0..2)\n for (c in 0..2) {\n var counter = 0\n counter += (board[r][c] == board[r][c + 1]).toInt()\n counter += (board[r][c] == board[r + 1][c]).toInt()\n counter += (board[r][c] == board[r + 1][c + 1]).toInt()\n if (counter != 1) {\n print(\"YES\")\n return\n }\n }\n print(\"NO\")\n}"}, {"source_code": "import java.io.BufferedInputStream\nimport java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(BufferedInputStream(System.`in`))\n\n val grid = Array(4, {\"\"})\n for(i in 0..3){\n grid[i] = scanner.next()\n }\n\n if(ok(grid)) print(\"YES\")\n else print(\"NO\")\n}\n\nfun ok(g: Array): Boolean{\n for(i in 0..2){\n for(j in 0..2){\n var clr1 = 0\n var clr2 = 0\n for(di in 0..1){\n for(dj in 0..1){\n if(g[i+di][j+dj] == '.') ++clr1\n else ++clr2\n }\n }\n\n if(Math.abs(clr1 - clr2) > 0){\n return true\n }\n }\n }\n return false\n}"}], "negative_code": [{"source_code": "fun main() {\n fun Boolean.toInt() = if (this) 1 else 0\n val board = Array(4) { readLine()!! }\n for (r in 0..2)\n for (c in 0..2) {\n var counter = 0\n counter += (board[r][c] == board[r][c + 1]).toInt()\n counter += (board[r][c] == board[r + 1][c]).toInt()\n counter += (board[r][c] == board[r + 1][c + 1]).toInt()\n if (counter >= 2) {\n print(\"YES\")\n return\n }\n }\n print(\"NO\")\n}"}], "src_uid": "01b145e798bbdf0ca2ecc383676d79f3"} {"nl": {"description": "This morning, Roman woke up and opened the browser with $$$n$$$ opened tabs numbered from $$$1$$$ to $$$n$$$. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.He decided to accomplish this by closing every $$$k$$$-th ($$$2 \\leq k \\leq n - 1$$$) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be $$$b$$$) and then close all tabs with numbers $$$c = b + i \\cdot k$$$ that satisfy the following condition: $$$1 \\leq c \\leq n$$$ and $$$i$$$ is an integer (it may be positive, negative or zero).For example, if $$$k = 3$$$, $$$n = 14$$$ and Roman chooses $$$b = 8$$$, then he will close tabs with numbers $$$2$$$, $$$5$$$, $$$8$$$, $$$11$$$ and $$$14$$$.After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it $$$e$$$) and the amount of remaining social network tabs ($$$s$$$). Help Roman to calculate the maximal absolute value of the difference of those values $$$|e - s|$$$ so that it would be easy to decide what to do next.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \\leq k < n \\leq 100$$$) — the amount of tabs opened currently and the distance between the tabs closed. The second line consists of $$$n$$$ integers, each of them equal either to $$$1$$$ or to $$$-1$$$. The $$$i$$$-th integer denotes the type of the $$$i$$$-th tab: if it is equal to $$$1$$$, this tab contains information for the test, and if it is equal to $$$-1$$$, it's a social network tab.", "output_spec": "Output a single integer — the maximum absolute difference between the amounts of remaining tabs of different types $$$|e - s|$$$.", "sample_inputs": ["4 2\n1 1 -1 1", "14 3\n-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1"], "sample_outputs": ["2", "9"], "notes": "NoteIn the first example we can choose $$$b = 1$$$ or $$$b = 3$$$. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, $$$e = 2$$$ and $$$s = 0$$$ and $$$|e - s| = 2$$$.In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them."}, "positive_code": [{"source_code": "import kotlin.math.abs\n\n//import kotlin.math.abs\n\nfun main(args: Array) {\n val (n , k) = readLine()!!.split(\" \").map(String::toInt)\n\n val a = readLine()!!.split(\" \").map(String::toInt)\n\n var max = 0;\n for(i in 0 until a.size){\n max = kotlin.math.max(max , s(a , i , k))\n }\n\n\n println(max)\n}\n\nfun s(a: List , start: Int , k: Int) : Int{\n\n var b = arrayListOf()\n for(i in 0 until a.size)\n b.add(true)\n\n var s = start\n while(s < a.size){\n b[s] = false\n s += k\n }\n\n\n s = start\n while(s >= 0){\n b[s] = false\n s -= k\n }\n\n var s1 = 0\n var s2 = 0\n\n for(i in 0 until a.size)\n if(b[i]){\n if(a[i] == 1){\n s1 ++;\n }else{\n s2 ++;\n }\n }\n\n return abs(s1 - s2)\n}"}, {"source_code": "fun main(){\n\tval (n, k) = readLine()!!.split(\" \").map(){it.toInt()}\n\tval array = readLine()!!.split(\" \").map(){it.toInt()}\n\tvar result = 0\n\tfor (i in 0..k - 1){\n\t\tvar dif = 0\n\t\t//println(\"b: \" + (i + 1))\n\t\tval copy = array.filterIndexed(){index, value -> (index - i) % k != 0}.forEach(){v -> \n\t\t//println(v)\n\t\tdif+=v}\n\n\t\tif (Math.abs(dif) > result) result = Math.abs(dif)\n\t\t//println(\"dif: \" + dif)\n\t}\n\tprintln(result)\n\t}"}, {"source_code": "//package com.happypeople.codeforces.c1100\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\n\nfun main(args: Array) {\n try {\n A().run()\n } catch (e: Throwable) {\n println(\"\")\n }\n}\n\nclass A {\n fun run() {\n val sc = Scanner(systemIn())\n val n=sc.nextInt()\n val k=sc.nextInt()\n val tabs=(1..n).map { sc.nextInt() }\n\n val sums=IntArray(k)\n for(i in tabs.indices)\n sums[i%k]+=tabs[i]\n\n val sumAll=sums.sum()\n val ans=max(\n abs(sumAll - sums.max()!!),\n abs(sumAll - sums.min()!!)\n )\n println(\"$ans\")\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array ) {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n val k = sc.nextInt()\n val a = IntArray( n, { sc.nextInt() } )\n var r = 0\n for ( s in 0 until k ) {\n val one = a.withIndex().count { ( it.index - s ) % k != 0 && it.value == 1 }\n val mone = a.withIndex().count { ( it.index - s ) % k != 0 && it.value == -1 }\n val diff = Math.abs( one - mone )\n r = Math.max( r, diff )\n }\n println( r )\n}"}, {"source_code": "import kotlin.math.abs\nimport kotlin.math.max\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numTabs, distance) = readInts()\n val arr = readInts()\n var sol = Integer.MIN_VALUE\n for (start in 0 until distance) {\n var curSol = 0\n for (pos in 0 until numTabs)\n if ((pos - start) % distance != 0) curSol += arr[pos]\n sol = max(sol, abs(curSol))\n }\n print(sol)\n}"}, {"source_code": "import kotlin.math.abs\n\nfun main(args: Array) {\n val (n , k) = readLine()!!.split(' ').map ( String::toInt )\n val arr : List = readLine()!!.split(' ').map ( String::toInt )\n\n val zeroing = { i : Int, arr : MutableList ->\n for (j in i until n step k)\n arr[j] = 0\n arr\n }\n\n val summation = { arr : MutableList ->\n var sum = 0\n for (j in 0 until n)\n sum += arr[j]\n sum\n }\n\n var res = 0\n var sum : Int\n for(i in 0 until k) {\n sum = abs(summation(zeroing(i, arr.toMutableList())))\n res = if(res < sum) sum else res\n }\n\n println(res)\n}"}, {"source_code": "import kotlin.math.abs\n\nfun main(args: Array) {\n// var str = readLine()!!\n// var n = readLine()!!.toInt()\n var ns = readLine()!!.split(\" \").map { x -> x.toInt() }\n var tabs = readLine()!!.split(\" \").map { x -> x.toInt() }\n\n var n = ns[0]\n var k = ns[1]\n\n var list = ArrayList()\n\n for(b in 0 until n) {\n var del = tabs(n, k, b)\n var newTab = ArrayList()\n for (a in 0 until n) {\n if (!del.contains(a)) {\n newTab.add(tabs[a])\n }\n }\n\n var e = 0\n var s = 0\n\n for (a in newTab){\n if (a < 0) s++\n else e++\n }\n\n list.add(abs(e-s))\n }\n\n print(list.max())\n\n}\n\nfun tabs(n: Int, k: Int, b: Int) : ArrayList {\n\n var list = ArrayList()\n var b2 = b\n while (b2 < n) {\n list.add(b2)\n b2+=k\n }\n\n b2 = b\n\n while (b2 >= 0) {\n list.add(b2)\n b2-=k\n }\n\n return list\n}\n"}, {"source_code": "import java.lang.Math.abs\nimport java.lang.Math.max\n\n\nfun printList(list: List ) {\n for(i in list){\n print(\"$i \")\n }\n print(\"\\n\")\n}\nfun main(args: Array) {\n var (n, k) = readLine()!!.split(' ').map(String::toInt)\n val list = readLine()!!.split(' ').map(String::toInt)\n var l = 0\n var r = 0\n for(i in list){\n if(i < 0)\n l++\n else\n r++\n }\n var ans = 0\n for(i in 0 until k){\n var l1 = 0\n var r1 = 0\n for(j in i until n step k){\n if(list[j] < 0)\n l1++\n else\n r1++\n }\n r1 = r - r1;\n l1 = l - l1;\n ans = max(ans, abs(l1 - r1))\n }\n println(ans)\n}\n\n\n"}, {"source_code": "import kotlin.math.absoluteValue\n\nfun remove(sequence: List, start: Int, step: Int) : List{\n return sequence.withIndex().filter { (i, _) -> (i - start) % step != 0 }.map {(_, value) -> value}\n}\n\nfun main(args: Array) {\n val (n, k) = readLine()!!.split(' ').map(String::toInt)\n val codes = readLine()!!.split(' ').map(String::toInt)\n val results = (0 until k).map { start -> remove(codes, start, k).sum().absoluteValue }\n println(results.max())\n}\n"}], "negative_code": [{"source_code": "//package com.happypeople.codeforces.c1100\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\nimport kotlin.math.abs\n\nfun main(args: Array) {\n try {\n A().run()\n } catch (e: Throwable) {\n println(\"\")\n }\n}\n\nclass A {\n fun run() {\n val sc = Scanner(systemIn())\n val n=sc.nextInt()\n val k=sc.nextInt()\n val tabs=(1..n).map { sc.nextInt() }\n\n val sums=IntArray(k)\n for(i in tabs.indices)\n sums[i%k]+=tabs[i]\n\n val sumAll=tabs.sum()\n if(sumAll<0) {\n val ans = abs(sumAll - sums.max()!!)\n println(\"$ans\")\n } else {\n val ans = abs(sumAll - sums.min()!!)\n println(\"$ans\")\n }\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}"}], "src_uid": "6119258322e06fa6146e592c63313df3"} {"nl": {"description": "A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than n matchboxes so that the total amount of matches in them is maximal.", "input_spec": "The first line of the input contains integer n (1 ≤ n ≤ 2·108) and integer m (1 ≤ m ≤ 20). The i + 1-th line contains a pair of numbers ai and bi (1 ≤ ai ≤ 108, 1 ≤ bi ≤ 10). All the input numbers are integer.", "output_spec": "Output the only number — answer to the problem.", "sample_inputs": ["7 3\n5 10\n2 5\n3 6", "3 3\n1 3\n2 2\n3 1"], "sample_outputs": ["62", "7"], "notes": null}, "positive_code": [{"source_code": "import java.util.*\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n val n = reader.nextInt()\n val m = reader.nextInt()\n\n val list = mutableListOf>()\n (1..m).forEach {\n val a = reader.nextInt()\n val b = reader.nextInt()\n list.add(Pair(a, b))\n }\n\n var matchBoxesLeft = n\n var matches = 0\n list.sortedByDescending { it.second }.map {\n if (matchBoxesLeft <= 0)\n return@map\n\n matchBoxesLeft -= it.first\n if (matchBoxesLeft >= 0) {\n matches += it.first * it.second\n } else {\n matchBoxesLeft += it.first\n matches += (matchBoxesLeft) * it.second\n matchBoxesLeft -= it.first\n }\n }\n print(matches)\n}\n\n\n// n == 7 && a = 5\n//\n// matcheBoxLeft = n - a\n"}, {"source_code": "import java.util.Comparator\n\n//import kotlin.math.abs\n\nfun main(args: Array) {\n\n var (n, m) = readLine()!!.split(' ').map(String::toLong)\n\n var pairs = arrayListOf();\n for (elem in 1..m) {\n var (i, j) = readLine()!!.split(' ').map(String::toLong);\n\n pairs.add(Pair(i, j));\n }\n\n pairs.sortWith(Comparator { a, b -> if (a.y > b.y) -1 else 1 });\n\n\n var count = 0L;\n\n var i = 0;\n while (n > 0 && i < m) {\n if (pairs[i].x > n) {\n count += n * pairs[i].y\n n = 0;\n } else {\n n -= pairs[i].x;\n count += pairs[i].x * pairs[i].y\n }\n\n i++;\n }\n\n\n print(count)\n\n}\n\nclass Pair(x: Long, y: Long) {\n var x: Long = x;\n var y: Long = y;\n}"}, {"source_code": "\nfun calculateBoxes(): Int {\n val map = sortedMapOf()\n\n fun readPairOfIntegers() = readLine()!!.split(\" \").let { Pair(it[0].toInt(), it[1].toInt()) }\n\n fun addToMap(key: Int, value: Int) {\n fun getValue(key: Int): Int {\n if (map[key] == null) {\n map[key] = 0\n }\n return map[key]!!\n }\n map[key] = value + getValue(key)\n }\n var matchesTaken = 0\n var (availableCapacity, containersCount) = readPairOfIntegers()\n repeat(containersCount) {\n val (boxesCount, boxCapacity) = readPairOfIntegers()\n addToMap(-boxCapacity, boxesCount)\n }\n map.entries.forEach { (boxCapacityNegative, boxesCount) ->\n val boxCapacity = -boxCapacityNegative\n if (boxesCount >= availableCapacity) {\n matchesTaken += availableCapacity * boxCapacity\n return matchesTaken\n } else {\n matchesTaken += boxesCount * boxCapacity\n availableCapacity -= boxesCount\n }\n }\n return matchesTaken\n}\n\nfun main() = println(calculateBoxes())\n"}, {"source_code": "\n\nimport java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.io.Reader\nimport java.util.*\n\nfun main(args: Array) {\n val reader = Reader()\n var capacity = reader.nextInt()\n val n = reader.nextInt()\n val list = mutableListOf>()\n var total = 0\n for (i in 0 until n) {\n val numberOfBoxes = reader.nextInt()\n val numberOfmMatches = reader.nextInt()\n list.add(numberOfBoxes to numberOfmMatches)\n }\n list.sortBy { it.second }\n for (i in n-1 downTo 0) {\n total += if (capacity >= list[i].first)\n list[i].first * list[i].second\n else\n capacity * list[i].second\n capacity -= list[i].first\n if (capacity <= 0)\n break\n }\n println(total)\n}\n\ninternal class Reader {\n var br: BufferedReader\n var st: StringTokenizer? = null\n\n init {\n br = BufferedReader(InputStreamReader(System.`in`))\n }\n\n operator fun next(): String {\n while (st == null || !st!!.hasMoreElements()) {\n try {\n st = StringTokenizer(br.readLine())\n } catch (e: IOException) {\n e.printStackTrace()\n }\n\n }\n return st!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLine(): String {\n var str = \"\"\n try {\n str = br.readLine()\n } catch (e: IOException) {\n e.printStackTrace()\n }\n\n return str\n }\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val (n, m) = br.readLine().split(\" \").map { it.toInt() }\n val matches = List(m){br.readLine().split(\" \").map { it.toInt() }}\n .sortedByDescending { it[1] }\n var cnt = 0\n var takenBoxes = 0\n var i = 0\n var full = false\n while (i < m && !full) {\n val (a, b) = matches[i]\n if (takenBoxes + a <= n) {\n cnt += a*b\n takenBoxes += a\n i++\n } else {\n cnt += (n - takenBoxes)*b\n full = true\n }\n }\n println(cnt)\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val reader = Scanner(System.`in`)\n var noToHold = reader.nextInt()\n val containersLength = reader.nextInt()\n val containers = mutableListOf>()\n for (i in 1..containersLength) {\n val key = reader.nextInt()\n val value = reader.nextInt()\n containers.add(Pair(key,value))\n }\n val sortedContainers = containers.toList()\n .sortedByDescending { (key, value) -> value }\n var total = 0\n for (container in sortedContainers) {\n if (noToHold != 0) {\n if (container.first <= noToHold) {\n noToHold -= container.first\n total += container.first * container.second\n } else {\n total += noToHold * container.second\n noToHold -= noToHold\n }\n }\n else\n break\n }\n print(total)\n}"}, {"source_code": "fun main(args: Array) {\n var (n, m) = readLine()!!.split(\" \").map(String::toInt)\n val sibice : MutableList> = MutableList(m) { Par(0,0) }\n for(i in 0 until m) {\n val (f, s) = readLine()!!.split(\" \").map(String::toInt)\n sibice[i] = Par(f,s)\n }\n sibice.sortBy { -it.second }\n var sum = 0L\n while(n > 0 && !sibice.isEmpty()) {\n if(n - sibice[0].first > 0) {\n n -= sibice[0].first\n sum += (sibice[0].second * sibice[0].first)\n sibice.removeAt(0)\n } else {\n sum += n * sibice[0].second\n break\n }\n }\n println(sum)\n}\n\nclass Par constructor(var first : T1, var second : T2)\n\n"}, {"source_code": "import java.util.*\n\ndata class Box(val a: Int = 0, val b: Int = 0) : Comparable {\n override fun compareTo(other: Box): Int {\n return this.b - other.b\n }\n}\n\nfun main(args: Array) {\n var (n, m) = readLine()!!.split(' ').map {it.toInt()}\n val x = Array(m) {Box()}\n for (i in 0 until m) {\n val line = readLine()!!.split(' ').map {it.toInt()}\n x[i] = Box(line[0], line[1])\n }\n\n var sum = 0\n for (box in x.sortedDescending()) {\n val take = minOf(box.a, n)\n n -= take\n sum += take * box.b\n }\n println(sum)\n}\n"}, {"source_code": "import kotlin.math.min\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n var (numMatchBoxes, numContainers) = readInts()\n val options = Array(numContainers) { 0 to 0 }\n for (container in 0 until numContainers) {\n val (numBoxes, numMatches) = readInts()\n options[container] = numMatches to numBoxes\n }\n options.sortByDescending { it.first }\n var sol = 0L\n for (option in options) {\n val numBoxes = min(numMatchBoxes, option.second)\n sol += numBoxes * option.first\n numMatchBoxes -= numBoxes\n if (numMatchBoxes == 0) break\n }\n print(sol)\n}"}], "negative_code": [{"source_code": "import java.util.*\n\nfun main() {\n val reader = Scanner(System.`in`)\n var noToHold = reader.nextInt()\n val containersLength = reader.nextInt()\n val containers = mutableMapOf()\n for (i in 1..containersLength) {\n containers.put(reader.nextInt(), reader.nextInt())\n }\n val sortedContainers = containers.toList()\n .sortedByDescending { (key, value) -> value }\n .toMap()\n var total = 0\n for (container in sortedContainers) {\n if (noToHold != 0) {\n if (container.key <= noToHold) {\n noToHold -= container.key\n total += container.key * container.value\n } else {\n total += noToHold * container.value\n noToHold -= noToHold\n }\n }\n else\n break\n }\n print(total)\n}"}, {"source_code": "fun main(args: Array) {\n var (n, m) = readLine()!!.split(\" \").map(String::toLong)\n val sibice : MutableList> = MutableList(0) { Par(0L,0L) }\n for(i in 0 until m) {\n val (f, s) = readLine()!!.split(\" \").map(String::toLong)\n sibice.add(Par(f, s))\n }\n\n sibice.sortBy { -it.second }\n\n var sum = 0L\n var i = 0\n while(n > 0) {\n if(sibice[i].first > 0) {\n sum += sibice[i].second\n sibice[i].first--\n n--\n } else {\n sibice.removeAt(i)\n if(sibice.isEmpty()) break\n else i++\n }\n }\n\n println(sum)\n}\n\nclass Par constructor(var first : T1, var second : T2)\n\n"}], "src_uid": "c052d85e402691b05e494b5283d62679"} {"nl": {"description": "Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya.Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive.Calculate the number of minutes they will be able to spend together.", "input_spec": "The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.", "output_spec": "Print one integer — the number of minutes Sonya and Filya will be able to spend together.", "sample_inputs": ["1 10 9 20 1", "1 100 50 200 75"], "sample_outputs": ["2", "50"], "notes": "NoteIn the first sample, they will be together during minutes 9 and 10.In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100."}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.math.BigInteger\n\n\nfun main(vararg params: String) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n\n val inputs = br.readLine().split(\" \").take(5).map { BigInteger(it) }\n\n val l1 = inputs[0]\n val r1 = inputs[1]\n val l2 = inputs[2]\n val r2 = inputs[3]\n val k = inputs[4]\n\n\n val lowLimit = l1.max(l2)\n val highLimit = r1.min(r2)\n val minutes = highLimit - lowLimit + BigInteger.ONE\n if (minutes <= BigInteger.ZERO)\n println(0)\n else\n if (k <= highLimit && k >= lowLimit) println(minutes - BigInteger.ONE) else println(minutes)\n}\n"}, {"source_code": "fun main(vararg args: String) {\n val (l1, r1, l2, r2, k) = readLine()!!.split(' ').map { it.toLong() }\n val l = Math.max(l1, l2)\n val r = Math.min(r1, r2)\n if (l > r) {\n println(0)\n } else {\n var o = r - l + 1\n if (l <= k && k <= r) o -= 1\n println(o)\n }\n}"}, {"source_code": "fun main(vararg args: String) {\n val (l1, r1, l2, r2, k) = readLine()!!.split(' ').map { it.toLong() }\n val l = Math.max(l1, l2)\n val r = Math.min(r1, r2)\n if (l > r) {\n println(0)\n } else {\n var o = r - l + 1\n if (k in l..r) o -= 1\n println(o)\n }\n}"}, {"source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n val (l1, r1, l2, r2, k) = readLongs()\n val start = max(l1, l2)\n val end = min(r1, r2)\n if (end < start) return print(0)\n print(end - start + 1 - if (k in start..end) 1 else 0)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.File\nimport java.io.PrintWriter\n\nfun main(args: Array) {\n val onlineJudge = System.getProperty(\"ONLINE_JUDGE\") == \"true\"\n val input = if (onlineJudge) System.`in`.bufferedReader() else File(\"input.txt\").bufferedReader()\n val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File(\"output.txt\"))\n\n solve(input, output)\n\n output.flush()\n output.close()\n}\n\nprivate fun solve(input: BufferedReader, output: PrintWriter) {\n val (l1, r1, l2, r2, k) = input.readLine().split(\"\\\\s+\".toRegex()).map { it.toLong() }\n\n val start = Math.max(l1, l2)\n val end = Math.min(r1, r2)\n\n val answer = when {\n start > end -> 0\n else -> (end - start + 1).let { if (k in start..end) it - 1 else it }\n }\n\n output.println(answer)\n}"}], "negative_code": [], "src_uid": "9a74b3b0e9f3a351f2136842e9565a82"} {"nl": {"description": "A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.", "input_spec": "The first line contains a single integer n (1 ≤ n ≤ 106).", "output_spec": "In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers. In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.", "sample_inputs": ["9", "32"], "sample_outputs": ["9\n1 1 1 1 1 1 1 1 1", "3\n10 11 11"], "notes": null}, "positive_code": [{"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val len = r.readLine()!!.toInt()\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }\n val v = r.readLine()!!.split(\"\").filter { it.isNotEmpty() }.map { it.toInt() }.toIntArray()\n val ans = mutableListOf()\n while (v.any { it > 0 }){\n val a = IntArray(v.size){0}\n for (i in 0..v.size-1){\n if (v[i]>0) {\n v[i]--\n a[i]++\n }\n }\n ans += a.joinToString(\"\").toInt()\n }\n println(ans.size)\n println(ans.joinToString(\" \"))\n /*repeat(r.readLine()!!.toInt()) {\n val (n, k) = r.readLine()!!.split(\" \").map { it.toLong() }\n }*/\n\n}"}, {"source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val n = readLine()!!.toInt()\n\n val list = mutableListOf()\n\n val s = System.currentTimeMillis()\n fillList(list)\n\n\n var arr = IntArray(1_000_001, { p -> -1 })\n var prev = IntArray(1_000_001, { p -> -1 })\n list.forEach {\n arr[it] = 1\n }\n\n for (i in 1..n) {\n list.forEach { elem ->\n val index = i - elem\n\n if (index > 0 && arr[index] != -1) {\n if (arr[i] == -1) {\n arr[i] = arr[index] + 1\n prev[i] = index\n } else if (arr[i] > arr[index] + 1) {\n arr[i] = arr[index] + 1\n prev[i] = index\n }\n }\n }\n }\n\n println(arr[n])\n\n var i = n\n while (prev[i] != -1) {\n println(i - prev[i])\n i = prev[i]\n }\n println(i)\n\n}\n\nfun fillList(list: MutableList) {\n\n for (i in 1..1_000_000)\n if (check(i)) {\n// println(i)\n list.add(i)\n }\n\n}\n\nfun check(elem: Int): Boolean {\n var elem = elem\n while (elem > 0) {\n if (elem % 10 >= 2)\n return false\n elem /= 10\n }\n\n return true\n}"}, {"source_code": "\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val n = readLine()!!.toInt()\n\n val list = mutableListOf()\n\n val s = System.currentTimeMillis()\n for (i in 1..1_000_000)\n if (check(i)) {\n// println(i)\n list.add(i)\n }\n\n// print(System.currentTimeMillis() - s)\n\n\n var arr = IntArray(1_000_001, { p -> -1 })\n var prev = IntArray(1_000_001, { p -> -1 })\n list.forEach {\n arr[it] = 1\n }\n\n for (i in 1..n) {\n list.forEach { elem ->\n val index = i - elem\n\n if (index > 0 && arr[index] != -1) {\n if (arr[i] == -1) {\n arr[i] = arr[index] + 1\n prev[i] = index\n } else if (arr[i] > arr[index] + 1) {\n arr[i] = arr[index] + 1\n prev[i] = index\n }\n }\n }\n }\n\n println(arr[n])\n\n var i = n\n while(prev[i] != -1){\n println(i - prev[i])\n i = prev[i]\n }\n println(i)\n\n}\n\nfun check(elem: Int): Boolean {\n var elem = elem\n while (elem > 0) {\n if (elem % 10 >= 2)\n return false\n elem /= 10\n }\n\n return true\n}"}, {"source_code": "import java.util.*\n\nvar INF = 1000001\n\nfun generate(n: Int, list: ArrayList){\n list.add(n)\n if(n * 10 < INF) generate(n * 10,list)\n if (n * 10 + 1 < INF) generate(n * 10 + 1,list)\n}\n\n\nfun getSequnece(dp: Array, from: Array, i: Int) {\n if(from[i] == -1) print(\"$i \")\n else {\n getSequnece(dp,from,from[i])\n getSequnece(dp,from,i - from[i])\n }\n}\n\n\nfun main(args: Array) {\n var s = readLine()!!.toInt()\n var l = ArrayList()\n generate(1,l)\n Collections.sort(l)\n var dp = Array(1000001) {i -> i}\n var from = Array(1000001) { i -> i - 1}\n dp[0] = 0\n l.forEach {\n dp[it] = 1\n from[it] = -1\n }\n (0..1000000).forEach {\n i ->\n l.forEach {\n if(i - it > 0) {\n if(dp[i - it] + dp[it] < dp[i]) {\n dp[i] = dp[i - it] + dp[it]\n from[i] = it\n }\n }\n }\n }\n println(dp[s])\n getSequnece(dp,from,s)\n}\n\n\n\n\n\n\n"}, {"source_code": "import java.util.*\n\nvar INF = 1000001\n\nfun generate(n: Int, list: ArrayList){\n list.add(n)\n if(n * 10 < INF) generate(n * 10,list)\n if (n * 10 + 1 < INF) generate(n * 10 + 1,list)\n}\n\ntailrec fun getSequnece(dp: Array, from: Array, i: Int) {\n if(from[i] == -1) print(\"$i \")\n else {\n print(\"${from[i]} \")\n getSequnece(dp, from, i - from[i])\n }\n}\n\n\nfun main(args: Array) {\n var s = readLine()!!.toInt()\n var l = ArrayList()\n generate(1,l)\n Collections.sort(l)\n var dp = Array(1000001) {i -> i}\n var from = Array(1000001) { i -> 1}\n dp[0] = 0\n l.forEach {\n dp[it] = 1\n from[it] = -1\n }\n (0..1000000).forEach {\n i ->\n l.forEach {\n if(i - it > 0) {\n if(dp[i - it] + dp[it] < dp[i]) {\n dp[i] = dp[i - it] + dp[it]\n from[i] = it\n }\n }\n }\n }\n println(dp[s])\n getSequnece(dp,from,s)\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toCharArray()\n var sol = 0\n val sols = mutableListOf>()\n while (true) {\n val newSol = mutableListOf()\n for ((pos, c) in n.withIndex()) {\n if (c == '0' && newSol.isNotEmpty()) newSol.add('0') else if (c != '0') {\n n[pos]--\n newSol.add('1')\n }\n }\n if (newSol.isEmpty()) {\n break\n }\n sol++\n sols.add(newSol)\n }\n println(sol)\n print(sols.joinToString(separator = \" \") { it.joinToString(\"\") })\n}"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readLong() = readLine()!!.toLong()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n var n = readLine()!!.toCharArray()\n var sol = 0\n var sols = mutableListOf>()\n var zeros = false\n while (!zeros) {\n val newSol = mutableListOf()\n for ((pos, c) in n.withIndex()) {\n if (c == '0' && newSol.isNotEmpty()) {\n newSol.add('0')\n } else if (c != '0') {\n n[pos]--\n newSol.add('1')\n }\n }\n if (newSol.isNotEmpty()) {\n sol++\n sols.add(newSol)\n } else {\n zeros = true\n }\n }\n println(sol)\n print(sols.joinToString(separator = \" \") { it.joinToString(\"\") })\n}"}, {"source_code": "fun quasi_binary() : ArrayList {\n val q_b = ArrayList()\n val max_depth = 7\n fun dfs(depth : Int, qb : Int) {\n if (depth > max_depth) {\n return\n } else {\n q_b.add(qb)\n val qb_0 = qb * 10\n val qb_1 = qb_0 + 1\n val new_depth = depth + 1\n dfs(new_depth, qb_0)\n dfs(new_depth, qb_1)\n }\n }\n dfs(1, 1)\n q_b.sort()\n return q_b\n}\n\nfun qb_sum(qb : ArrayList, n : Int) : ArrayList {\n val predecessor = IntArray(n + 1)\n val num_terms = IntArray(n + 1, {_ -> Int.MAX_VALUE})\n num_terms[0] = 0 \n val term = IntArray(n + 1)\n for (i in 0 .. n) {\n for (x in qb) {\n val sum = i + x\n if (sum <= n) {\n val num_terms_so_far = num_terms[i] + 1\n if (num_terms_so_far < num_terms[sum]) {\n num_terms[sum] = num_terms_so_far\n term[sum] = x\n predecessor[sum] = i\n }\n } else {\n break\n }\n }\n }\n val terms = ArrayList()\n var x = n\n while (x > 0) {\n terms.add(term[x])\n x = predecessor[x]\n }\n return terms\n}\n\nfun main(args : Array) {\n val n_nullable_str = readLine()\n if (n_nullable_str == null) {\n // Do nothing ...\n } else {\n val n_str = n_nullable_str\n val n = n_str.toInt()\n val q_b = quasi_binary()\n val terms = qb_sum(q_b, n)\n val num_terms = terms.size\n println(\"${num_terms}\")\n for (t in terms) {\n print(\"${t} \")\n }\n println()\n }\n}\n"}, {"source_code": "fun main(args: Array) {\n val number= readLine()!!.map { it-> (it-'0') }.toIntArray()\n var canCreateNumber=true\n val binNubmers= mutableListOf()\n while (canCreateNumber){\n var currenNumber= mutableListOf()\n for ((index, value) in number.withIndex()){\n if(value>0){\n currenNumber.add(1)\n number[index]-=1\n }\n else{\n if(currenNumber.size>0)\n currenNumber.add(0)\n }\n }\n if (currenNumber.size==0)\n break\n binNubmers.add(currenNumber.joinToString(\"\"))\n }\n println(binNubmers.size)\n println(binNubmers.joinToString(\" \"))\n}"}], "negative_code": [{"source_code": "import java.util.*\n\nvar INF = 1000001\n\nfun generate(n: Int, list: ArrayList){\n list.add(n)\n if(n * 10 < INF) generate(n * 10,list)\n if (n * 10 + 1 < INF) generate(n * 10 + 1,list)\n}\n\ntailrec fun getSequnece(dp: Array, from: Array, i: Int) {\n if(from[i] == -1) print(\"$i \")\n else {\n print(\"${from[i]} \")\n getSequnece(dp, from, i - from[i])\n }\n}\n\n\nfun main(args: Array) {\n var s = readLine()!!.toInt()\n var l = ArrayList()\n generate(1,l)\n Collections.sort(l)\n var dp = Array(1000001) {i -> i}\n var from = Array(1000001) { i -> i - 1}\n dp[0] = 0\n l.forEach {\n dp[it] = 1\n from[it] = -1\n }\n (0..1000000).forEach {\n i ->\n l.forEach {\n if(i - it > 0) {\n if(dp[i - it] + dp[it] < dp[i]) {\n dp[i] = dp[i - it] + dp[it]\n from[i] = it\n }\n }\n }\n }\n println(dp[s])\n getSequnece(dp,from,s)\n}"}, {"source_code": "import java.util.*\n\nvar INF = 1000001\n\nfun generate(n: Int, list: ArrayList){\n list.add(n)\n if(n * 10 < INF) generate(n * 10,list)\n if (n * 10 + 1 < INF) generate(n * 10 + 1,list)\n}\n\n\nfun getSequnece(dp: Array, from: Array, i: Int) {\n if(from[i] == -1) print(\"$i \")\n else {\n getSequnece(dp,from,from[i])\n getSequnece(dp,from,i - from[i])\n }\n}\n\n\nfun main(args: Array) {\n var s = readLine()!!.toInt()\n var l = ArrayList()\n generate(1,l)\n Collections.sort(l)\n var dp = Array(1000001) {i -> i}\n var from = Array(1000001) { i -> i - 1}\n dp[0] = 0\n l.forEach {\n dp[it] = 1\n from[it] = -1\n }\n (0..100000).forEach {\n i ->\n l.forEach {\n if(i - it > 0) {\n if(dp[i - it] + dp[it] < dp[i]) {\n dp[i] = dp[i - it] + dp[it]\n from[i] = it\n }\n }\n }\n }\n println(dp[s])\n getSequnece(dp,from,s)\n}\n\n\n\n\n\n\n"}, {"source_code": "fun quasi_binary() : ArrayList {\n val q_b = ArrayList()\n val max_depth = 7\n fun dfs(depth : Int, qb : Int) {\n if (depth > max_depth) {\n return\n } else {\n q_b.add(qb)\n val qb_0 = qb * 10\n val qb_1 = qb_0 + 1\n val new_depth = depth + 1\n dfs(new_depth, qb_0)\n dfs(new_depth, qb_1)\n }\n }\n dfs(1, 1)\n q_b.sort()\n return q_b\n}\n\nfun qb_sum(qb : ArrayList, n : Int, terms : ArrayList) {\n if (n == 0) {\n // Do nothing ...\n } else {\n var l = 0\n var u = qb.size - 1\n while ((u - l) > 1) {\n val m = (l + u) / 2\n val qb_m = qb[m]\n if (qb_m <= n) {\n l = m\n } else {\n u = m\n }\n }\n val qb_l = qb[l]\n val new_n = n - qb_l\n terms.add(qb_l)\n qb_sum(qb, new_n, terms)\n }\n return\n}\n\nfun main(args : Array) {\n val n_nullable_str = readLine()\n if (n_nullable_str == null) {\n // Do nothing ...\n } else {\n val n_str = n_nullable_str\n val n = n_str.toInt()\n val q_b = quasi_binary()\n val terms = ArrayList()\n qb_sum(q_b, n, terms)\n val num_terms = terms.size\n println(\"${num_terms}\")\n for (t in terms) {\n print(\"${t} \")\n }\n println()\n }\n}\n"}], "src_uid": "033068c5e16d25f09039e29c88474275"} {"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 java.io.*\nimport java.math.BigDecimal\nimport java.math.BigInteger\nimport java.util.*\n\n\nobject programkt {\n interface Scanner {\n fun changeInputStream(inputStream: InputStream)\n fun nextInt(): Int\n fun nextLong(): Long\n fun nextDouble(): Double\n fun nextChar(): Char\n fun nextString(): String\n fun nextLine(): String\n fun nextBigInteger(): BigInteger\n fun nextBigDecimal(): BigDecimal\n }\n\n abstract class Task {\n //KT Extensions\n fun > min(a: T, b: T) = if (a > b) b else a\n fun > max(a: T, b: T) = if (a < b) b else a\n fun abs(a: Int) = if (a > 0) a else -(a)\n fun abs(a: Long) = if (a > 0) a else -(a)\n fun abs(a: Float) = if (a > 0) a else -(a)\n fun abs(a: Double) = if (a > 0) a else -(a)\n operator fun Iterable.invoke(function: (it: T) -> Unit) { this.forEach(function) }\n private fun String.prefix(pi: Array): Array {\n pi[0] = 0\n (1 until this.length) {\n var j = pi[it - 1]\n while (j > 0 && this[it] != this[j]) {\n j = pi[j - 1]\n }\n if(this[it] == this[j]) {\n j++\n }\n pi[it] = j\n }\n return pi\n }\n private fun String.kmpFind(pattern: String): Int {\n val m = pattern.length\n val dfa = Array(256) { IntArray(m) }\n dfa[pattern[0].toInt()][0] = 1\n var x = 0\n var j = 1\n while (j < m) {\n for (c in 0 until 256) {\n dfa[c][j] = dfa[c][x] // Copy mismatch cases.\n }\n dfa[pattern[j].toInt()][j] = j + 1 // Set match case.\n x = dfa[pattern[j].toInt()][x] // Update restart state.\n j++\n }\n\n val n = this.length\n var i: Int = 0\n j = 0\n while (i < n && j < m) {\n j = dfa[this[i].toInt()][j]\n i++\n }\n if (j == m) return i - m // found\n return n // not found\n }\n fun fuckExceptions(invoker: () -> Unit) = try { invoker.invoke() } catch (_: Throwable) {}\n\n enum class EdgeType {\n DIRECTED,\n UNDIRECTED\n }\n data class Vertex>(\n val data: T\n ) {\n override fun toString(): String = \"V:$data\"\n }\n data class Edge>(\n var source: Vertex,\n var destination: Vertex,\n val weight: Double?\n )\n interface Graphable> {\n fun createVertex(data: T): Vertex\n fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double? = 0.0)\n fun weight(source: Vertex, destination: Vertex): Double?\n fun edges(source: Vertex): MutableList>?\n }\n class AdjacencyList>: Graphable {\n var adjacencyMap: MutableMap, MutableList>> = mutableMapOf()\n\n private fun addDirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n adjacencyMap[source]?.add(Edge(source = source, destination = destination, weight = weight))\n }\n\n private fun addUndirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n addDirectedEdge(source, destination, weight)\n addDirectedEdge(destination, source, weight)\n }\n\n override fun createVertex(data: T): Vertex {\n val vertex = Vertex(data = data)\n adjacencyMap[vertex] ?: run {\n adjacencyMap[vertex] = mutableListOf()\n }\n return vertex\n }\n\n override fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double?) = when(type) {\n EdgeType.DIRECTED -> addDirectedEdge(source, destination, weight)\n EdgeType.UNDIRECTED -> addUndirectedEdge(source, destination, weight)\n }\n\n override fun weight(source: Vertex, destination: Vertex): Double? {\n adjacencyMap[source]?.forEach {\n if(it.destination == destination) return it.weight\n }\n return null\n }\n\n override fun edges(source: Vertex): MutableList>? = adjacencyMap[source]\n\n override fun toString(): String {\n var result = \"\"\n for ((vertex, edges) in adjacencyMap) {\n var edgeString = \"\"\n for ((index, edge) in edges.withIndex()) {\n edgeString += if (index != edges.count() - 1) \"${edge.destination}, \"\n else \"${edge.destination}\"\n }\n result += \"$vertex ---> [ $edgeString ] \\n\"\n }\n return result\n }\n\n fun depthFirstSearch(start: Vertex, end: Vertex): Stack> {\n val visited: HashSet> = hashSetOf()\n val stack: Stack> = Stack()\n stack.push(start)\n visited.add(start)\n\n var currentVertex = stack.peek()\n loop@while (currentVertex != null && currentVertex != end) {\n val neighbors = edges(currentVertex)\n if(neighbors != null && neighbors.count() > 0) {\n for(edge in neighbors) {\n if(!visited.contains(edge.destination)) {\n visited.add(edge.destination)\n stack.push(edge.destination)\n currentVertex = stack.peek()\n continue@loop\n }\n }\n } else {\n stack.pop()\n currentVertex = stack.peek()\n continue\n }\n\n stack.pop()\n currentVertex = stack.peek()\n }\n\n return stack\n }\n\n fun breadthFirstSearch() {\n\n }\n\n fun floydWarshallAlgorythm(): Pair, Array> {\n val nVertices = this.adjacencyMap.size\n\n val weights = Array(nVertices) { Array(nVertices-1) { 0.0 } }\n this.adjacencyMap\n .asSequence()\n .map { it.value }\n .withIndex()\n .forEach { (index, weightsOfVertex) ->\n weightsOfVertex.asSequence()\n .withIndex()\n .forEach { (weightIndex, weight) ->\n weights[index][weightIndex] = weight.weight!!\n }\n }\n\n val dist = Array(nVertices) { DoubleArray(nVertices) { Double.POSITIVE_INFINITY } }\n for (w in weights) dist[(w[0] - 1).toInt()][(w[1] - 1).toInt()] = w[2]\n val next = Array(nVertices) { IntArray(nVertices) }\n for (i in 0 until next.size) {\n for (j in 0 until next.size) {\n if (i != j) next[i][j] = j + 1\n }\n }\n for (k in 0 until nVertices) {\n for (i in 0 until nVertices) {\n for (j in 0 until nVertices) {\n if (dist[i][k] + dist[k][j] < dist[i][j]) {\n dist[i][j] = dist[i][k] + dist[k][j]\n next[i][j] = next[i][k]\n }\n }\n }\n }\n return dist to next\n }\n }\n\n fun > TreeMap>.toAdjacencyList(type: EdgeType): AdjacencyList {\n val list = AdjacencyList()\n\n this.keys.forEach { list.createVertex(it) }\n this.entries\n .asSequence()\n .withIndex()\n .forEach { (x, edge) ->\n val vertex = list.createVertex(edge.key)\n edge.value\n .asSequence()\n .withIndex()\n .forEach { (y, weight) ->\n if(weight != .0 && y != x)\n list.add(type, vertex, list.createVertex(this.keys.elementAt(y)), weight)\n }\n }\n return list\n }\n //End KT Extensions\n\n abstract fun solve(scanner: Scanner, printer: PrintWriter)\n }\n\n class FastScanner: Scanner {\n var inputStream: InputStream? = null\n override fun changeInputStream(inputStream: InputStream) {\n this.inputStream = inputStream\n this.bufferedReader = BufferedReader(InputStreamReader(inputStream))\n }\n\n private lateinit var bufferedReader: BufferedReader\n private var stringTokenizer: StringTokenizer? = null\n\n private fun nextToken(): String? {\n while (stringTokenizer == null || !stringTokenizer!!.hasMoreTokens())\n stringTokenizer = StringTokenizer(bufferedReader.readLine() ?: return null)\n return stringTokenizer!!.nextToken()\n }\n\n override fun nextInt() = nextToken()!!.toInt()\n override fun nextLong() = nextToken()!!.toLong()\n override fun nextDouble() = nextToken()!!.toDouble()\n override fun nextChar() = bufferedReader.read().toChar()\n override fun nextString() = nextToken()!!\n override fun nextLine() = bufferedReader.readLine()!!\n override fun nextBigInteger() = BigInteger(nextToken()!!)\n override fun nextBigDecimal() = BigDecimal(nextToken()!!)\n }\n\n class TaskBuilder {\n private var task: Task? = null\n private var inputStream: InputStream? = null\n private var outputStream: OutputStream? = null\n private var scanner: Scanner? = null\n\n fun useInputSource(inputStream: InputStream): TaskBuilder {\n this.inputStream = inputStream\n return this\n }\n\n fun useOutputSource(outputStream: OutputStream): TaskBuilder {\n this.outputStream = outputStream\n return this\n }\n\n fun useInputFile(inputFileName: String): TaskBuilder {\n this.inputStream = FileInputStream(File(inputFileName))\n return this\n }\n\n fun useOutputFile(outputFileName: String): TaskBuilder {\n this.outputStream = FileOutputStream(File(outputFileName))\n return this\n }\n\n fun useScanner(scanner: Scanner): TaskBuilder {\n this.scanner = scanner\n return this\n }\n\n\n fun solveTask(task: Task): TaskBuilder {\n this.task = task\n return this\n }\n\n fun run() {\n when {\n task == null -> throw NullPointerException(\"Task cannot be null!\")\n inputStream == null -> throw NullPointerException(\"Input cannot be null!\")\n outputStream == null -> throw NullPointerException(\"Output cannot be null!\")\n scanner == null -> throw NullPointerException(\"Scanner cannot be null!\")\n }\n scanner!!.changeInputStream(inputStream!!)\n val printer = PrintWriter(outputStream)\n TaskRunnable(task!!, scanner!!, printer).run()\n\n inputStream!!.close()\n printer.close()\n }\n\n class TaskRunnable(\n private val task: Task,\n private val scanner: Scanner,\n private val printer: PrintWriter\n ) {\n fun run() {\n task.solve(scanner, printer)\n }\n }\n }\n\n @JvmStatic\n fun main(args: Array) = TaskBuilder()\n .useInputSource(System.`in`)\n .useOutputSource(System.out)\n .useScanner(FastScanner())\n .solveTask(TaskA())\n .run()\n\n\n class TaskA: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val (firstValency, secondValency, thirdValency) = scanner.nextLine()\n .split(\" \")\n .map { it.toLong() }\n val averageValency = (firstValency + secondValency + thirdValency) / 2\n\n if ((firstValency + secondValency + thirdValency) % 2 != 0L ) { printer.println(\"Impossible\"); return }\n\n val countOfConnectionsFirst = averageValency - thirdValency\n val countOfConnectionsSecond = averageValency - firstValency\n val countOfConnectionsThird = averageValency - secondValency\n\n when {\n countOfConnectionsFirst < 0 -> { printer.println(\"Impossible\"); return }\n countOfConnectionsSecond < 0 -> { printer.println(\"Impossible\"); return }\n countOfConnectionsThird < 0 -> { printer.println(\"Impossible\"); return }\n else -> printer.println(\"$countOfConnectionsFirst $countOfConnectionsSecond $countOfConnectionsThird\")\n }\n }\n\n }\n}\n"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val valences = readInts().mapIndexed { index, i -> i to index }.sortedBy { it.first }.toTypedArray()\n if (valences[0].first + valences[1].first < valences[2].first) return print(\"Impossible\")\n if (valences.sumBy { it.first } % 2 == 1) return print(\"Impossible\")\n val sumToPos = mapOf(1 to 0, 3 to 1, 2 to 2)\n val bonds = arrayOf(0, 0, 0)\n // step 1: valences 0 and 1 became the same\n if (valences[0].first != valences[1].first) {\n val delta = valences[1].first - valences[0].first\n bonds[sumToPos[valences[1].second + valences[2].second]!!] = delta\n valences[1] = valences[1].first - delta to valences[1].second\n valences[2] = valences[2].first - delta to valences[2].second\n }\n // step 2: all valences became the same\n if (valences[0].first != valences[2].first) {\n val delta = valences[2].first - valences[0].first\n bonds[sumToPos[valences[0].second + valences[2].second]!!] += delta\n bonds[sumToPos[valences[1].second + valences[2].second]!!] += delta\n valences[0] = valences[0].first - delta to valences[0].second\n }\n // step 3: all valences are the same, add to bonds the value\n for (pos in 0 .. 2)\n bonds[pos] += valences[0].first / 2\n print(bonds.joinToString(\" \"))\n}"}, {"source_code": "// based on tutorial\nfun main() {\n val (a, b, c) = readLine()!!.split(\" \").map(String::toInt)\n if ((a + b + c) % 2 == 1) return print(\"Impossible\")\n val y = (b - a + c) / 2\n val x = a + y - c\n val z = a - x\n if (x < 0 || y < 0 || z < 0) return print(\"Impossible\")\n print(\"$x $y $z\")\n}\n\n// 36 minutes, debugging needed\n//fun main() {\n// fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n//\n// val valences = readInts().mapIndexed { index, i -> i to index }.sortedBy { it.first }.toTypedArray()\n// if (valences[0].first + valences[1].first < valences[2].first) return print(\"Impossible\")\n// if (valences.sumBy { it.first } % 2 == 1) return print(\"Impossible\")\n// val sumToPos = mapOf(1 to 0, 3 to 1, 2 to 2)\n// val bonds = arrayOf(0, 0, 0)\n// // step 1: valences 0 and 1 became the same\n// if (valences[0].first != valences[1].first) {\n// val delta = valences[1].first - valences[0].first\n// bonds[sumToPos[valences[1].second + valences[2].second]!!] = delta\n// valences[1] = valences[1].first - delta to valences[1].second\n// valences[2] = valences[2].first - delta to valences[2].second\n// }\n// // step 2: all valences became the same\n// if (valences[0].first != valences[2].first) {\n// val delta = valences[2].first - valences[0].first\n// bonds[sumToPos[valences[0].second + valences[2].second]!!] += delta\n// bonds[sumToPos[valences[1].second + valences[2].second]!!] += delta\n// valences[0] = valences[0].first - delta to valences[0].second\n// }\n// // step 3: all valences are the same, add to bonds the value\n// for (pos in 0 .. 2)\n// bonds[pos] += valences[0].first / 2\n// print(bonds.joinToString(\" \"))\n//}"}], "negative_code": [{"source_code": "import java.io.*\nimport java.math.BigDecimal\nimport java.math.BigInteger\nimport java.util.*\n\n\nobject programkt {\n interface Scanner {\n fun changeInputStream(inputStream: InputStream)\n fun nextInt(): Int\n fun nextLong(): Long\n fun nextDouble(): Double\n fun nextChar(): Char\n fun nextString(): String\n fun nextLine(): String\n fun nextBigInteger(): BigInteger\n fun nextBigDecimal(): BigDecimal\n }\n\n abstract class Task {\n //KT Extensions\n fun > min(a: T, b: T) = if (a > b) b else a\n fun > max(a: T, b: T) = if (a < b) b else a\n fun abs(a: Int) = if (a > 0) a else -(a)\n fun abs(a: Long) = if (a > 0) a else -(a)\n fun abs(a: Float) = if (a > 0) a else -(a)\n fun abs(a: Double) = if (a > 0) a else -(a)\n operator fun Iterable.invoke(function: (it: T) -> Unit) { this.forEach(function) }\n private fun String.prefix(pi: Array): Array {\n pi[0] = 0\n (1 until this.length) {\n var j = pi[it - 1]\n while (j > 0 && this[it] != this[j]) {\n j = pi[j - 1]\n }\n if(this[it] == this[j]) {\n j++\n }\n pi[it] = j\n }\n return pi\n }\n private fun String.kmpFind(pattern: String): Int {\n val m = pattern.length\n val dfa = Array(256) { IntArray(m) }\n dfa[pattern[0].toInt()][0] = 1\n var x = 0\n var j = 1\n while (j < m) {\n for (c in 0 until 256) {\n dfa[c][j] = dfa[c][x] // Copy mismatch cases.\n }\n dfa[pattern[j].toInt()][j] = j + 1 // Set match case.\n x = dfa[pattern[j].toInt()][x] // Update restart state.\n j++\n }\n\n val n = this.length\n var i: Int = 0\n j = 0\n while (i < n && j < m) {\n j = dfa[this[i].toInt()][j]\n i++\n }\n if (j == m) return i - m // found\n return n // not found\n }\n fun fuckExceptions(invoker: () -> Unit) = try { invoker.invoke() } catch (_: Throwable) {}\n\n enum class EdgeType {\n DIRECTED,\n UNDIRECTED\n }\n data class Vertex>(\n val data: T\n ) {\n override fun toString(): String = \"V:$data\"\n }\n data class Edge>(\n var source: Vertex,\n var destination: Vertex,\n val weight: Double?\n )\n interface Graphable> {\n fun createVertex(data: T): Vertex\n fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double? = 0.0)\n fun weight(source: Vertex, destination: Vertex): Double?\n fun edges(source: Vertex): MutableList>?\n }\n class AdjacencyList>: Graphable {\n var adjacencyMap: MutableMap, MutableList>> = mutableMapOf()\n\n private fun addDirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n adjacencyMap[source]?.add(Edge(source = source, destination = destination, weight = weight))\n }\n\n private fun addUndirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n addDirectedEdge(source, destination, weight)\n addDirectedEdge(destination, source, weight)\n }\n\n override fun createVertex(data: T): Vertex {\n val vertex = Vertex(data = data)\n adjacencyMap[vertex] ?: run {\n adjacencyMap[vertex] = mutableListOf()\n }\n return vertex\n }\n\n override fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double?) = when(type) {\n EdgeType.DIRECTED -> addDirectedEdge(source, destination, weight)\n EdgeType.UNDIRECTED -> addUndirectedEdge(source, destination, weight)\n }\n\n override fun weight(source: Vertex, destination: Vertex): Double? {\n adjacencyMap[source]?.forEach {\n if(it.destination == destination) return it.weight\n }\n return null\n }\n\n override fun edges(source: Vertex): MutableList>? = adjacencyMap[source]\n\n override fun toString(): String {\n var result = \"\"\n for ((vertex, edges) in adjacencyMap) {\n var edgeString = \"\"\n for ((index, edge) in edges.withIndex()) {\n edgeString += if (index != edges.count() - 1) \"${edge.destination}, \"\n else \"${edge.destination}\"\n }\n result += \"$vertex ---> [ $edgeString ] \\n\"\n }\n return result\n }\n\n fun depthFirstSearch(start: Vertex, end: Vertex): Stack> {\n val visited: HashSet> = hashSetOf()\n val stack: Stack> = Stack()\n stack.push(start)\n visited.add(start)\n\n var currentVertex = stack.peek()\n loop@while (currentVertex != null && currentVertex != end) {\n val neighbors = edges(currentVertex)\n if(neighbors != null && neighbors.count() > 0) {\n for(edge in neighbors) {\n if(!visited.contains(edge.destination)) {\n visited.add(edge.destination)\n stack.push(edge.destination)\n currentVertex = stack.peek()\n continue@loop\n }\n }\n } else {\n stack.pop()\n currentVertex = stack.peek()\n continue\n }\n\n stack.pop()\n currentVertex = stack.peek()\n }\n\n return stack\n }\n\n fun breadthFirstSearch() {\n\n }\n\n fun floydWarshallAlgorythm(): Pair, Array> {\n val nVertices = this.adjacencyMap.size\n\n val weights = Array(nVertices) { Array(nVertices-1) { 0.0 } }\n this.adjacencyMap\n .asSequence()\n .map { it.value }\n .withIndex()\n .forEach { (index, weightsOfVertex) ->\n weightsOfVertex.asSequence()\n .withIndex()\n .forEach { (weightIndex, weight) ->\n weights[index][weightIndex] = weight.weight!!\n }\n }\n\n val dist = Array(nVertices) { DoubleArray(nVertices) { Double.POSITIVE_INFINITY } }\n for (w in weights) dist[(w[0] - 1).toInt()][(w[1] - 1).toInt()] = w[2]\n val next = Array(nVertices) { IntArray(nVertices) }\n for (i in 0 until next.size) {\n for (j in 0 until next.size) {\n if (i != j) next[i][j] = j + 1\n }\n }\n for (k in 0 until nVertices) {\n for (i in 0 until nVertices) {\n for (j in 0 until nVertices) {\n if (dist[i][k] + dist[k][j] < dist[i][j]) {\n dist[i][j] = dist[i][k] + dist[k][j]\n next[i][j] = next[i][k]\n }\n }\n }\n }\n return dist to next\n }\n }\n\n fun > TreeMap>.toAdjacencyList(type: EdgeType): AdjacencyList {\n val list = AdjacencyList()\n\n this.keys.forEach { list.createVertex(it) }\n this.entries\n .asSequence()\n .withIndex()\n .forEach { (x, edge) ->\n val vertex = list.createVertex(edge.key)\n edge.value\n .asSequence()\n .withIndex()\n .forEach { (y, weight) ->\n if(weight != .0 && y != x)\n list.add(type, vertex, list.createVertex(this.keys.elementAt(y)), weight)\n }\n }\n return list\n }\n //End KT Extensions\n\n abstract fun solve(scanner: Scanner, printer: PrintWriter)\n }\n\n class FastScanner: Scanner {\n var inputStream: InputStream? = null\n override fun changeInputStream(inputStream: InputStream) {\n this.inputStream = inputStream\n this.bufferedReader = BufferedReader(InputStreamReader(inputStream))\n }\n\n private lateinit var bufferedReader: BufferedReader\n private var stringTokenizer: StringTokenizer? = null\n\n private fun nextToken(): String? {\n while (stringTokenizer == null || !stringTokenizer!!.hasMoreTokens())\n stringTokenizer = StringTokenizer(bufferedReader.readLine() ?: return null)\n return stringTokenizer!!.nextToken()\n }\n\n override fun nextInt() = nextToken()!!.toInt()\n override fun nextLong() = nextToken()!!.toLong()\n override fun nextDouble() = nextToken()!!.toDouble()\n override fun nextChar() = bufferedReader.read().toChar()\n override fun nextString() = nextToken()!!\n override fun nextLine() = bufferedReader.readLine()!!\n override fun nextBigInteger() = BigInteger(nextToken()!!)\n override fun nextBigDecimal() = BigDecimal(nextToken()!!)\n }\n\n class TaskBuilder {\n private var task: Task? = null\n private var inputStream: InputStream? = null\n private var outputStream: OutputStream? = null\n private var scanner: Scanner? = null\n\n fun useInputSource(inputStream: InputStream): TaskBuilder {\n this.inputStream = inputStream\n return this\n }\n\n fun useOutputSource(outputStream: OutputStream): TaskBuilder {\n this.outputStream = outputStream\n return this\n }\n\n fun useInputFile(inputFileName: String): TaskBuilder {\n this.inputStream = FileInputStream(File(inputFileName))\n return this\n }\n\n fun useOutputFile(outputFileName: String): TaskBuilder {\n this.outputStream = FileOutputStream(File(outputFileName))\n return this\n }\n\n fun useScanner(scanner: Scanner): TaskBuilder {\n this.scanner = scanner\n return this\n }\n\n\n fun solveTask(task: Task): TaskBuilder {\n this.task = task\n return this\n }\n\n fun run() {\n when {\n task == null -> throw NullPointerException(\"Task cannot be null!\")\n inputStream == null -> throw NullPointerException(\"Input cannot be null!\")\n outputStream == null -> throw NullPointerException(\"Output cannot be null!\")\n scanner == null -> throw NullPointerException(\"Scanner cannot be null!\")\n }\n scanner!!.changeInputStream(inputStream!!)\n val printer = PrintWriter(outputStream)\n TaskRunnable(task!!, scanner!!, printer).run()\n\n inputStream!!.close()\n printer.close()\n }\n\n class TaskRunnable(\n private val task: Task,\n private val scanner: Scanner,\n private val printer: PrintWriter\n ) {\n fun run() {\n task.solve(scanner, printer)\n }\n }\n }\n\n @JvmStatic\n fun main(args: Array) = TaskBuilder()\n .useInputSource(System.`in`)\n .useOutputSource(System.out)\n .useScanner(FastScanner())\n .solveTask(TaskA())\n .run()\n\n\n class TaskA: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val (firstValency, secondValency, thirdValency) = scanner.nextLine()\n .split(\" \")\n .map { it.toLong() }\n val averageValency = (firstValency + secondValency + thirdValency) / 2\n val countOfConnectionsFirst = averageValency - thirdValency\n val countOfConnectionsSecond = averageValency - firstValency\n val countOfConnectionsThird = averageValency - secondValency\n\n when {\n (firstValency + secondValency + thirdValency) / 2 % 1 != 0L -> { printer.println(\"Impossible\"); return }\n countOfConnectionsFirst < 0 -> { printer.println(\"Impossible\"); return }\n countOfConnectionsSecond < 0 -> { printer.println(\"Impossible\"); return }\n countOfConnectionsThird < 0 -> { printer.println(\"Impossible\"); return }\n else -> printer.println(\"$countOfConnectionsFirst $countOfConnectionsSecond $countOfConnectionsThird\")\n }\n }\n\n }\n}\n"}], "src_uid": "b3b986fddc3770fed64b878fa42ab1bc"} {"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": "fun main() {\n val (a1, b1) = readLine()!!.split(\" \").map(String::toInt)\n val (a2, b2) = readLine()!!.split(\" \").map(String::toInt)\n val (a3, b3) = readLine()!!.split(\" \").map(String::toInt)\n when {\n a2 + a3 <= a1 && b2 <= b1 && b3 <= b1 -> {\n print(\"YES\");return\n }\n a2 + b3 <= a1 && b2 <= b1 && a3 <= b1 -> {\n print(\"YES\");return\n }\n b2 + a3 <= a1 && a2 <= b1 && b3 <= b1 -> {\n print(\"YES\");return\n }\n b2 + b3 <= a1 && a2 <= b1 && a3 <= b1 -> {\n print(\"YES\");return\n }\n a2 <= a1 && a3 <= a1 && b2 + b3 <= b1 -> {\n print(\"YES\");return\n }\n a2 <= a1 && b3 <= a1 && b2 + a3 <= b1 -> {\n print(\"YES\");return\n }\n b2 <= a1 && a3 <= a1 && a2 + b3 <= b1 -> {\n print(\"YES\");return\n }\n b2 <= a1 && b3 <= a1 && a2 + a3 <= b1 -> {\n print(\"YES\");return\n }\n }\n print(\"NO\")\n}"}], "negative_code": [], "src_uid": "2ff30d9c4288390fd7b5b37715638ad9"} {"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": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.*\n\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n val n = scanner.next()\n val set = TreeSet()\n for (i in n)\n set.add(i)\n if (set.size % 2 == 0)\n println(\"CHAT WITH HER!\")\n else\n println(\"IGNORE HIM!\")\n\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\n//class Pair(var a: Int, var b: Int): Comparable {\n// override fun compareTo(other: Pair): Int {\n// return b - a - other.b + other.a\n// }\n//}"}, {"source_code": "fun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\n\nfun getUnique(s: String): Int {\n val unique = hashSetOf()\n for (ch in s) unique.add(ch)\n return unique.size\n}\n\nfun main(args: Array) {\n val s = readLn()\n println(if (getUnique(s) % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}"}, {"source_code": "// kotlin oj template code from uwi(Codeforces), and convert to kotlin by lety\nimport java.io.ByteArrayInputStream\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport java.util.InputMismatchException\nimport kotlin.math.absoluteValue\n\nlateinit var `is`: InputStream\nlateinit var out: PrintWriter\nvar INPUT = \"\"\n\n//val oj = System.getProperty(\"ONLINE_JUDGE\") != null\nval oj = true\nval inbuf = ByteArray(1024)\nvar lenbuf = 0\nvar ptrbuf = 0\n\nlateinit var cum: Array\n\nfun solve()\n{\n val s = ns()\n val cnt = IntArray(26)\n\n for(i in 0 until s.length) {\n cnt[(s[i] - 'a')] = 1\n }\n\n if(cnt.sum() % 2 == 0)\n {\n println(\"CHAT WITH HER!\" )\n }\n else\n {\n println(\"IGNORE HIM!\")\n }\n}\n\n\nfun main() {\n `is` = if (oj) System.`in` else ByteArrayInputStream(INPUT.toByteArray())\n out = PrintWriter(System.out)\n\n val s = System.currentTimeMillis()\n solve()\n out.flush()\n tr((System.currentTimeMillis() - s).toString() + \"ms\")\n}\n\nprivate fun readByte(): Int {\n if (lenbuf == -1) throw InputMismatchException()\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0\n try {\n lenbuf = `is`.read(inbuf)\n } catch (e: IOException) {\n throw InputMismatchException()\n }\n\n if (lenbuf <= 0) return -1\n }\n return inbuf[ptrbuf++].toInt()\n}\n\nprivate fun isSpaceChar(c: Int): Boolean = !(c >= 33 && c <= 126)\n\nprivate fun skip(): Int {\n var b: Int = readByte()\n while (b != -1 && isSpaceChar(b)) {\n b = readByte()\n }\n return b\n}\n\n// using ns()\nprivate fun nd(): Double = ns().toDouble()\n\n// using ns()\nprivate fun nc(): Char = skip().toChar()\n\n// input until whitespace\nprivate fun ns(): String {\n var b = skip()\n val sb = StringBuilder()\n while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b)\n b = readByte()\n }\n return sb.toString()\n}\n\nprivate fun ns(n: Int): CharArray {\n val buf = CharArray(n)\n var b = skip()\n var p = 0\n while (p < n && !isSpaceChar(b)) {\n buf[p++] = b.toChar()\n b = readByte()\n }\n return if (n == p) buf else Arrays.copyOf(buf, p)\n}\n\n// matrix\nprivate fun nm(n: Int, m: Int): Array {\n val map = Array(n) { CharArray(m) }\n for (i in 0 until n) map[i] = ns(m)\n return map\n}\n\nprivate fun pm(matrix: Array) {\n val n = matrix.size\n val m = matrix[0].size\n repeat(n)\n {\n repeat(m)\n { jt ->\n out.print(matrix[it][jt])\n }\n out.println()\n }\n out.flush()\n}\n\n// int array\nprivate fun na(n: Int): IntArray {\n val a = IntArray(n)\n for (i in 0 until n) a[i] = ni()\n return a\n}\n\nprivate fun ni(): Int {\n var num = 0\n var b: Int = readByte()\n var minus = false\n while (b != -1 && !(b >= '0'.toInt() && b <= '9'.toInt() || b == '-'.toInt())) {\n b = readByte()\n }\n if (b == '-'.toInt()) {\n minus = true\n b = readByte()\n }\n\n while (true) {\n if (b >= '0'.toInt() && b <= '9'.toInt()) {\n num = num * 10 + (b - '0'.toInt())\n } else {\n return if (minus) -num else num\n }\n b = readByte()\n }\n}\n\nprivate fun nl(): Long {\n var num: Long = 0\n var b: Int = readByte()\n var minus = false\n while (b != -1 && !(b >= '0'.toInt() && b <= '9'.toInt() || b == '-'.toInt())) {\n b = readByte()\n }\n if (b == '-'.toInt()) {\n minus = true\n b = readByte()\n }\n\n while (true) {\n if (b >= '0'.toInt() && b <= '9'.toInt()) {\n num = num * 10 + (b - '0'.toInt())\n } else {\n return if (minus) -num else num\n }\n b = readByte()\n }\n}\n\nprivate fun tr(vararg o: Any) {\n// if (!oj) println(Arrays.deepToString(o))\n}\n\n"}, {"source_code": "fun main(args: Array) {\n val firstString =readLine()!!.toSet()\n if (firstString.size % 2 == 0 ) print(\"CHAT WITH HER!\") else print(\"IGNORE HIM!\")\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n var scan = Scanner(System.`in`)\n\n var name = scan.nextLine()\n\n var _name = name.toCharArray().distinct()\n\n if(_name.size %2 == 0) {\n println(\"CHAT WITH HER!\")\n } else {\n println(\"IGNORE HIM!\")\n }\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n var tok = StringTokenizer(\"\")\n\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n fun files(inputFilename: String, outputFilename: String) = ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))\n }\n\n fun readToken(): String {\n while (!tok.hasMoreTokens()) {\n tok = StringTokenizer(rd.readLine())\n }\n return tok.nextToken()\n }\n\n fun readInt(): Int = readToken().toInt()\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun close() {\n rd.close()\n wr.close()\n }\n}\n\nfun solve() {\n val io = ProblemIO.console()\n val t = io.readToken()\n val l = t.toSet().size\n io.println(if (l % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n"}, {"source_code": "fun main()\n{\n var given = readLine()!!\n var done = \"\"\n var has = 0\n for (i in given)\n {\n if (done.contains(i)) continue\n else {\n done += i\n has++\n }\n }\n if (has % 2 == 0)\n {\n println(\"CHAT WITH HER!\" )\n }\n else\n {\n println(\"IGNORE HIM!\")\n }\n}\n"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!.split(\"\").toSet().size\n println(if (n%2==1) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}"}, {"source_code": "fun main(args: Array) {\n val s = readLine()!!\n if (s.chars().distinct().count() % 2 == 0L)\n print(\"CHAT WITH HER!\")\n else\n print(\"IGNORE HIM!\")\n}"}, {"source_code": "fun main(args: Array) {\n var s = readLine()!!\n if (s.chars().distinct().count() % 2 == 0L)\n print(\"CHAT WITH HER!\")\n else\n print(\"IGNORE HIM!\")\n}"}, {"source_code": "fun main(args: Array) {\n val a = readLine()!!.toCharArray()\n if (a.distinct().count() % 2 == 0) {\n print(\"CHAT WITH HER!\")\n } else {\n print(\"IGNORE HIM!\")\n }\n}"}, {"source_code": "fun main() {\n\tval nick = readLine()!!\n\tval charSet = hashSetOf()\n\tnick.forEach {charSet += it }\n\tprintln(if (charSet.size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}\n"}, {"source_code": "import java.util.regex.Pattern\nfun main(args: Array) {\n\n var text = readLine()!!\n if (Pattern.matches(\"[a-z]+\", text))\n {\n var charArray = text.toCharArray().distinct()\n if (charArray.joinToString(\"\").length%2==0)\n {\n print(\"CHAT WITH HER!\")\n }else\n print(\"IGNORE HIM!\")\n\n }\n\n\n}"}, {"source_code": "fun main() {\n\n val input = readLine()!!.split(\"\")\n\n val distinctChar = input.distinct()\n\n if (distinctChar.size % 2 == 0) {\n print(\"IGNORE HIM!\")\n } else {\n print(\"CHAT WITH HER!\")\n }\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`);\n val n = scanner.next()\n val set = mutableSetOf()\n for (c in n.asIterable()) {\n set.add(c);\n }\n\n if (set.count() % 2 == 0) print(\"CHAT WITH HER!\")\n else print(\"IGNORE HIM!\")\n}\n"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n print(if (readLn().split(\"\").distinct().count() % 2 == 1) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}\n"}, {"source_code": "\n\nfun main() {\n readLine()?.let {\n checkGender(it)\n }\n}\n\nfun checkGender(name : String) {\n val counts = name.toSet().size\n val answer = if (counts % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\"\n println(answer)\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.HashSet\n\nfun main() {\n val sc = Scanner(System.`in`)\n val s1 = sc.nextLine().toLowerCase()\n val set = HashSet()\n for (ch in s1)\n set.add(ch)\n print(if(set.size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.pow\nimport kotlin.math.sqrt\n\n//private val INPUT = File(\"input.txt\").inputStream()\n//private val OUTPUT = File(\"output.txt\").outputStream()\nprivate val INPUT = System.`in`\nprivate val OUTPUT = System.out\n\nprivate val bufferedReader = INPUT.bufferedReader()\nprivate val outputWriter = PrintWriter(OUTPUT, false)\nprivate fun readLn() = bufferedReader.readLine()!!\n\nprivate fun readList() = readLn().split(' ')\nprivate var tokenizer = StringTokenizer(\"\")\nprivate fun read(): String {\n while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(readLn(), \" \")\n return tokenizer.nextToken()\n}\n\nprivate fun readInt() = read().toInt()\nprivate fun readLong() = read().toLong()\nprivate fun readDouble() = read().toDouble()\n\nprivate fun readIntList() = readList().map { it.toInt() }\nprivate fun readLongList() = readList().map { it.toLong() }\nprivate fun readDoubleList() = readList().map { it.toDouble() }\n\nprivate fun readIntArray(n: Int = 0) =\n if (n == 0) readList().run { IntArray(size) { get(it).toInt() } } else IntArray(n) { readInt() }\n\nprivate fun readLongArray(n: Int = 0) =\n if (n == 0) readList().run { LongArray(size) { get(it).toLong() } } else LongArray(n) { readLong() }\n\nprivate fun readDoubleArray(n: Int = 0) =\n if (n == 0) readList().run { DoubleArray(size) { get(it).toDouble() } } else DoubleArray(n) { readDouble() }\n\n\nprivate fun Int.modPositive(other: Int): Int = if (this % other < 0) ((this % other) + other) else (this % other)\n\n\nprivate class `CF236-D2-A` {\n fun solveTestCase(): String {\n val set = mutableSetOf()\n for (c in read()) {\n set.add(c)\n }\n\n return if (set.size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\"\n }\n}\n\nfun main(args: Array) {\n outputWriter.println(\n `CF236-D2-A`()\n .solveTestCase()\n )\n\n outputWriter.flush()\n}"}, {"source_code": "fun main(args: Array) {\n val name: String = readLine()!!\n val chars: MutableSet = name.toCharArray().toMutableSet()\n if (chars.count() %2 == 0) {\n print(\"CHAT WITH HER!\")\n } else {\n print(\"IGNORE HIM!\")\n }\n}"}, {"source_code": "fun main() = readLine()!!.let(String::toHashSet).run { size % 2 == 0 }.let { isGirl -> if (isGirl) \"CHAT WITH HER!\" else \"IGNORE HIM!\" }.run(::println)"}, {"source_code": "fun main(args: Array) {\n val str = readLine()!!\n (str.toCharArray().distinct().size % 2 == 0).sheOrHe()\n .also { println(it) }\n}\n\nprivate fun Boolean.sheOrHe() = if (this) \"CHAT WITH HER!\" else \"IGNORE HIM!\"\n"}, {"source_code": "fun main(args: Array) {\n readLine()!!.let {\n println(if (it.toSet().size.rem(2) == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n }\n }"}, {"source_code": "import java.util.Scanner;\nimport java.util.Arrays;\nimport java.util.*; \nimport java.math.*;\nimport java.io.*;\n\nfun main(args: Array) {\n var s = Scanner(System.`in`)\n var word = s.next()\n if(Distinct(word)% 2 == 0){\n print(\"CHAT WITH HER!\")\n }else{\n print(\"IGNORE HIM!\")\n }\n\n}\n\nfun Distinct(str:String):Int{\n \n val distinct = LinkedHashSet()\n val builder = StringBuilder()\n for(i in 0 .. str.length-1){\n if(distinct.add(str.get(i))){\n builder.append(str.get(i))\n }\n }\n return builder.length\n}\n"}, {"source_code": "fun main(args: Array) {\nval s = readLine()!!\nvar c = \"\"\n for(item in s){\nif(!c.contains(item)){\nc+=item\n}\n\n }\nvar x = c.length\nwhen {\n x%2 != 0 -> print(\"IGNORE HIM!\")\n else -> print(\"CHAT WITH HER!\")\n \n}\n \n \n }"}, {"source_code": "\n\nimport java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(args: Array) {\n val reader = Reader()\n val string = reader.next()\n val set = hashSetOf()\n for (i in 0 until string.length) {\n set.add(string.elementAt(i))\n }\n println(if (set.count() % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}\n\ninternal class Reader {\n var br: BufferedReader\n var st: StringTokenizer? = null\n\n init {\n br = BufferedReader(InputStreamReader(System.`in`))\n }\n\n operator fun next(): String {\n while (st == null || !st!!.hasMoreElements()) {\n try {\n st = StringTokenizer(br.readLine())\n } catch (e: IOException) {\n e.printStackTrace()\n }\n\n }\n return st!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLine(): String {\n var str = \"\"\n try {\n str = br.readLine()\n } catch (e: IOException) {\n e.printStackTrace()\n }\n\n return str\n }\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val input = InputReader(inputStream)\n val output = PrintWriter(outputStream)\n val solver = Task()\n solver.solve(input, output)\n output.close()\n}\n\nprivate class Task {\n fun solve(input: InputReader, output: PrintWriter) {\n output.print(if (input.next().toSet().size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n }\n}\n\n\nprivate class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n\n operator fun next(): String {\n while (tokenizer == null || tokenizer?.hasMoreTokens()?.not() == true) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n}"}, {"source_code": "/* https://codeforces.com/problemset/problem/236/A */\n\nfun main() {\n val name = readLine()!!\n val numOfDistinctChars = name.toSet().size\n if (numOfDistinctChars % 2 == 1) {\n println(\"IGNORE HIM!\")\n } else {\n println(\"CHAT WITH HER!\")\n }\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.lang.StringBuilder\n\nfun main(){\n var chars :Set = BufferedReader(InputStreamReader(System.`in`)).readLine().toCharArray().toSet()\n println(if (chars.size % 2 == 0)\"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}\n\n\n"}, {"source_code": "fun main(args: Array) {\n var s = readLine()\n var l = arrayListOf()\n for (i in s!!){\n l.add(i.toString())\n }\n if (l.toSet().size%2==1){\n println(\"IGNORE HIM!\")\n }else{\n println(\"CHAT WITH HER!\")\n }\n}"}, {"source_code": "import java.util.*\n fun main()\n {\n var str = readLine();\n val hash: MutableMap = HashMap()\n for (i in 0 until str!!.length)\n {\n hash[str!![i]] = str[i]\n }\n if (hash.size % 2 == 0)\n {\n println(\"CHAT WITH HER!\")\n }\n else\n {\n println(\"IGNORE HIM!\")\n }\n }\n"}, {"source_code": "import java.util.*\n\n\n fun main(args: Array)\n {\n val `in` = Scanner(System.`in`)\n val str = `in`.nextLine()\n val hash: MutableMap = HashMap()\n for (i in 0 until str.length)\n {\n hash[str[i]] = str[i]\n }\n if (hash.size % 2 == 0)\n {\n println(\"CHAT WITH HER!\")\n }\n else\n {\n println(\"IGNORE HIM!\")\n }\n }\n"}, {"source_code": "\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val username = readLn().toSet()\n\n if (username.size % 2 == 0) {\n println(\"CHAT WITH HER!\")\n } else {\n println(\"IGNORE HIM!\")\n }\n}\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val s: Scanner = Scanner(System.`in`)\n val str: String = s.next()\n val set = str.toHashSet()\n print(if (set.size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}"}, {"source_code": "fun main(args: Array) {\n\n print(if (readLine()!!.toCharArray().distinct().size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n reader.use {\n var el = it.readLine().toSet()\n print(if (el.size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n }\n}"}, {"source_code": "import java.util.Scanner\n\nprivate const val CHAT_WITH_HER = \"CHAT WITH HER!\"\nprivate const val IGNORE_HIM = \"IGNORE HIM!\"\nprivate const val OFFSET = 'a'\nprivate const val LATIN_ALPHABET_LENGTH = 26\nprivate val BUCKET = IntArray(LATIN_ALPHABET_LENGTH)\n\nfun main(args: Array) {\n Scanner(System.`in`).use {\n val answer = determineGender(it.next())\n clearBucket()\n println(answer)\n }\n}\n\nprivate fun determineGender(nickname: String): String {\n return if (uniqueCharactersCount(nickname).isEven()) {\n CHAT_WITH_HER\n } else {\n IGNORE_HIM\n }\n}\n\nprivate fun uniqueCharactersCount(word: String): Int {\n var uniqueCount = 0\n val charsCount = word.length\n for (i in 0 until charsCount) {\n val index = word[i] - OFFSET\n if (BUCKET[index] == 0) {\n ++uniqueCount\n BUCKET[index] = 1\n }\n }\n return uniqueCount\n}\n\nprivate fun clearBucket() {\n for (i in 0 until LATIN_ALPHABET_LENGTH) {\n BUCKET[i] = 0\n }\n}\n\nprivate fun Int.isEven() = this % 2 == 0"}, {"source_code": "fun main(args: Array) {\n val s = readLine()!!\n val m = s.groupingBy { it }.eachCount().size\n println(if (m % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n\n}"}, {"source_code": "fun main(args: Array) {\n val userName = readLine()!!\n val singleSet = mutableSetOf()\n userName.forEach{ char->\n singleSet.add(char)\n }\n println(if(singleSet.size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}"}, {"source_code": "// codeforces problem 236 A\n\nfun main() {\n println( if (readLine()!!.groupBy { it }.size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}\n"}, {"source_code": "fun main(args:Array){val a=hashSetOf();for(z in readLine()!!.toList())a.add(z);print(\"${if(a.size%2==0)\"CHAT WITH HER!\" else \"IGNORE HIM!\"}\")}"}, {"source_code": "//1.2 | CodeForces.Com\nfun main(args: Array)\n{\n val distinctChars = hashSetOf() //Abbreviation: Distinct characters\n \n for(input in readLine()!!.toList())\n distinctChars.add(input)\n\n print(\"${if (distinctChars.size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\"}\")\n}"}, {"source_code": "//rextester.com:1.1--codeforces.com:1.0.5-2\nfun main(args:Array){\n val b=hashSetOf();for(c in readLine()!!.toList())if(!b.contains(c))b.add(c)\n print(\"${if(b.size%2==0)\"CHAT WITH HER!\" else \"IGNORE HIM!\"}\")\n}"}, {"source_code": "//rextester.com:1.1--codeforces.com:1.0.5-2\nfun main(args:Array){\n val a=readLine()!!.toList()\n val b=hashSetOf();for(c in a)if(!b.contains(c))b.add(c)\n print(\"${if(b.size%2==0)\"CHAT WITH HER!\" else \"IGNORE HIM!\"}\")\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\n/**\n * Created by Hamza on 17/02/2018.\n */\nfun main(args: Array) {\n var br = BufferedReader(InputStreamReader(System.`in`))\n var st = StringTokenizer(br.readLine())\n var str = st!!.nextToken()\n var l = str.length\n var count = IntArray(26)\n for (i in 0..l - 1) {\n count[str[i].toInt() - 'a'.toInt()]++\n }\n var countor = 0\n for (i in 0..25) {\n if (count[i] != 0) {\n countor++\n }\n }\nif (countor%2 == 0) println(\"CHAT WITH HER!\")else println(\"IGNORE HIM!\")\n}\n"}, {"source_code": "fun main(args : Array) {\n var name = readLine()!!\n var s = name[0].toString()\n var dif = true\n for (i in 1..(name.length-1)){\n dif = true\n for (j in 0..(s.length-1)){\n if (name[i] == s[j])\n dif = false\n }\n if(dif)\n s += name[i]\n }\n if (s.length % 2 == 0)\n println(\"CHAT WITH HER!\")\n else\n println(\"IGNORE HIM!\")\n}"}, {"source_code": "import java.util.*\nfun main(args: Array) {\n val input = Scanner(System.`in`).nextLine()\n val count = input.chars().distinct().count().toInt()\n if (count % 2 == 0) {\n println(\"CHAT WITH HER!\")\n } else {\n println(\"IGNORE HIM!\")\n }\n\n}"}, {"source_code": "import java.util.*\n\n fun main(){\n var input = Scanner(System.`in`)\n var inputString = input.nextLine()\n if(inputString.toCharArray().distinct().size % 2 == 0){\n print(\"CHAT WITH HER!\")\n }else{\n print(\"IGNORE HIM!\")\n }\n\n\n\n }\n\n\n\n\n\n\n\n\n"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\nimport java.util.TreeSet\n\nfun main() {\n output {\n val s = readLn()\n\n val ans = s.toCollection(HashSet()).size % 2 == 0\n\n println(if(ans) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n }\n}\n\ndata class Run(val item: T, val num: Int)\n\nfun String.runs() = sequence {\n val i = iterator()\n\n if(i.hasNext().not()) return@sequence\n var last = i.next()\n var num = 1\n\n for(e in i) {\n if(last == e) num++\n else {\n yield(Run(last, num))\n last = e\n num = 1\n }\n }\n yield(Run(last, num))\n}\n\n\n/** IO code start */\n@JvmField val _reader = System.`in`.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(System.out, false)\ninline fun output(block: PrintWriter.()->Unit) { _writer.apply(block).flush() }\nfun iprintln(o: Any?) { println(o) } // immediate println for interactive, bypasses output{} blocks"}, {"source_code": "// https://codeforces.com/problemset/problem/236/A\n\nfun main(args: Array) {\n //even female\n //odd mail\n\n val name = readLn()\n val characterSet = mutableSetOf()\n for (character in name) {\n characterSet.add(character)\n }\n if (characterSet.size % 2 == 0) {\n print(\"CHAT WITH HER!\")\n } else {\n print(\"IGNORE HIM!\")\n }\n}\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings(del: String = \" \") = readLn().split(del) // list of strings\nprivate fun readInts(del: String = \" \") = readStrings(del).map { it.toInt() } // list of ints"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val str = scan.next()\n val symbolsList = mutableSetOf()\n str.forEach {\n symbolsList.add(it)\n }\n if(symbolsList.count() % 2 == 0) {\n println(\"CHAT WITH HER!\")\n } else {\n println(\"IGNORE HIM!\")\n }\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val s = br.readLine()\n val distinct = s.groupBy { it }.keys.size\n println(\n if (distinct % 2 == 1){\n \"IGNORE HIM!\"\n } else {\n \"CHAT WITH HER!\"\n }\n )\n}"}, {"source_code": "//package problem236A\n\nfun numDistinctCharacters(username: String): Int {\n val letterMap = hashMapOf()\n\n for (char in username) {\n letterMap[char] = (letterMap[char] ?: 0) + 1\n }\n return letterMap.size\n}\n\nfun main() {\n val input = readLine()!!\n println(if (numDistinctCharacters(input) % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}\n"}, {"source_code": "\nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\n\n\nfun boyOrGirl(): String {\n\n val usrname = readLn().toSet()\n\n return if (usrname.size % 2 == 0)\n \"CHAT WITH HER!\"\n else \"IGNORE HIM!\"\n}\n\nfun main() {\n print(boyOrGirl())\n}\n"}, {"source_code": "import java.util.*\n\nfun main()\n{\n var scanner = Scanner(System.`in`)\n var str = scanner.next()\n var flag = true\n var counter = 0\n var visited = mutableMapOf()\n for(i in 0 until str.length)\n {\n if(visited[str[i]]==null)\n {\n visited[str[i]] = true\n counter++\n }\n }\n if(counter % 2 == 0)\n println(\"CHAT WITH HER!\")\n else\n println(\"IGNORE HIM!\")\n\n}\n"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val name = readLn()\n when (name.toCharArray().distinct().size % 2) {\n 0 -> println(\"CHAT WITH HER!\")\n else -> println(\"IGNORE HIM!\")\n }\n}\n"}, {"source_code": "fun main(args: Array)\n{\n val s = readLine()!!\n val a = Array(26, {0})\n for (c in s)\n a[c - 'a'] = 1\n val diff = a.count({i -> i > 0})\n println(if (diff % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}"}, {"source_code": "fun main(args: Array) {\n if(checkGender(readLine().toString())) {\n println(\"CHAT WITH HER!\")\n }\n else {\n println(\"IGNORE HIM!\")\n }\n}\nfun checkGender(hello:String):Boolean {\n val map: HashMap = HashMap()\n for(c in hello){\n if(!map.containsKey(c)){\n map[c] = 1\n }\n }\n return map.size%2==0\n }"}, {"source_code": "fun main() {\n if (readLine()!!.toSet().size % 2 == 1) {\n println(\"IGNORE HIM!\")\n }\n else{\n println(\"CHAT WITH HER!\")\n }\n}"}, {"source_code": "fun main(args: Array) {\n val name = readLine()!!\n\n if (name.toSet().count().rem(2) == 0)\n println(\"CHAT WITH HER!\")\n else\n println(\"IGNORE HIM!\")\n}"}, {"source_code": "fun main() {\n val name: String? = readLine()\n val charSet: MutableSet = mutableSetOf()\n\n // covert string to char\n name!!.forEach { index -> charSet.add(index)}\n\n if (charSet.size % 2 == 0)\n println(\"CHAT WITH HER!\")\n else\n println(\"IGNORE HIM!\")\n}"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array){\n val scan = Scanner(System.`in`)\n val s = scan.next().toCharArray()\n var count = 0\n\n for (i in 0 until s.size){\n for (x in i+1 until s.size){\n if (s[i] == s[x]) s[x] = ' '\n }\n if (s[i] != ' ') count++\n }\n if (count%2 == 0) print(\"CHAT WITH HER!\")\n else print(\"IGNORE HIM!\")\n}"}, {"source_code": "typealias int = Int\n\nfun main() {\n var s1 = readLine()\n var set : MutableSet = mutableSetOf();\n for(i in 0..s1!!.lastIndex){\n set.add(s1[i])\n }\n println(if(set.size % 2== 0 ) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}"}, {"source_code": "fun main() {\n var chars = readLine()!!.toCharArray()\n var set : Set = chars.toSet()\n println(if(set.size % 2== 0 ) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}"}, {"source_code": "//package codeforces\n\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val In = BufferedReader(InputStreamReader(System.`in`))\n val name = In.readLine()!!.toSet()\n if(name.size % 2 ==0)\n println(\"CHAT WITH HER!\")\n else\n println(\"IGNORE HIM!\")\n}"}, {"source_code": "import java.lang.AssertionError\n \nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n \nprivate fun myAssert(x: Boolean) {\n if (!x) {\n throw AssertionError()\n }\n}\n\nfun main(args: Array) {\n var s = readLn()\n var x = mutableSetOf()\n for (c in s) {\n x.add(c)\n }\n if (x.size % 2 == 0) {\n println(\"CHAT WITH HER!\")\n } else {\n println(\"IGNORE HIM!\")\n }\n}\n"}, {"source_code": "fun main(args: Array) {\n println(if (readLine()!!.toCharArray().toSet().size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}"}, {"source_code": "fun main(){\n var s = readLine()!!\n var a = arrayOf(\"q\",\"w\",\"e\",\"r\",\"t\",\"y\",\"u\",\"i\",\"o\",\"p\",\"a\",\"s\",\"d\",\"f\",\"g\",\"h\",\"j\",\"k\",\"l\",\"z\",\"x\",\"c\",\"v\",\"b\",\"n\",\"m\")\n var k = \"\"\n for (i in 0..25){\n for (j in 0..s.length -1){\n if (a[i].compareTo(s[j].toString()) == 0){\n k = k + a.get(i)\n break\n }\n }\n }\n if ((k.length) % 2 == 0) println(\"CHAT WITH HER!\") else println(\"IGNORE HIM!\")\n}"}, {"source_code": "fun main(){\n val b = readLine()!!.split(\"\").distinct().count()\n if ( b % 2 == 1) print( \"CHAT WITH HER!\" ) else print( \"IGNORE HIM!\")\n}"}, {"source_code": "fun main() {\n val v = readLine()!!.toCharArray().distinct().size % 2 != 0\n println(if (v) \"IGNORE HIM!\" else \"CHAT WITH HER!\")\n }"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val name = reader.readLine()\n val set = setOf(*name.toCharArray().toTypedArray())\n val output = if (set.size % 2 != 0) \"IGNORE HIM!\" else \"CHAT WITH HER!\"\n println(output)\n}"}, {"source_code": "fun main() {\n val s = readLine()!!.toCharArray().toMutableSet()\n if(s.size % 2 == 1)\n println(\"IGNORE HIM!\")\n else\n println(\"CHAT WITH HER!\")\n}"}, {"source_code": "fun main() {\n val s = readLine()!!\n if (s.toSet().size % 2 == 1) {\n println(\"IGNORE HIM!\")\n } else {\n println(\"CHAT WITH HER!\")\n }\n}\n"}, {"source_code": "fun main(args: Array) {\n val s = readLine()!!\n val arr = Array(s.length, { i -> s[i]})\n arr.sort()\n var cnt = 0\n for (i in arr.indices) {\n if (i == 0) {\n cnt++\n } else if (i > 0 && arr[i] != arr[i-1]) {\n cnt++\n }\n }\n if (cnt % 2 == 0) {\n print(\"CHAT WITH HER!\\n\")\n } else {\n print(\"IGNORE HIM!\\n\")\n }\n}\n"}, {"source_code": "fun main(args: Array) {\n print(\n if (readLine()!!.toSet().size % 2 == 0)\n \"CHAT WITH HER!\"\n else\n \"IGNORE HIM!\"\n )\n}\n"}, {"source_code": "fun main() {\n\n val userName = readLine()!!\n val myList = ArrayList()\n\n userName.forEach {\n if(!myList.contains(it)){\n myList.add(it)\n }\n }\n\n if(myList.size%2 == 0) print(\"CHAT WITH HER!\")\n else print(\"IGNORE HIM!\")\n}\n\n\n"}, {"source_code": "fun main(args: Array) {\n var chat = readLine()!!.toSet().size % 2 == 0\n println(if (chat) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n\nconst val success = \"CHAT WITH HER!\"\nconst val failure = \"IGNORE HIM!\"\n\nfun main() {\n val username = readLn()\n\n if (username.toList().distinct().size % 2 == 0) println(success) else println(failure)\n}\n"}, {"source_code": "fun main() {\n println(if (hashSetOf().apply { addAll(readLine()!!.toList()) }.size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}\n\n\n\n\n"}, {"source_code": "fun main(args: Array) {\n val count = readLine()!!.toSet().size\n println(if (count % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}\n\n"}, {"source_code": "fun main() {\n print(if (readLine()!!.split(\"\").distinct().drop(1).count() % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}"}, {"source_code": "fun main(args:Array){\n val word = readLine()!!\n\n val symbols = mutableSetOf()\n\n word.forEach {\n symbols.add(it)\n }\n\n if (symbols.size %2 == 0){\n print(\"CHAT WITH HER!\")\n } else {\n print(\"IGNORE HIM!\")\n }\n}"}, {"source_code": "fun main(args: Array) {\n var s=readLine()\n if (s == null) s=\"ADS\"\n if (s.chars().distinct().count().toInt() % 2 == 0) print(\"CHAT WITH HER!\")\n else print(\"IGNORE HIM!\")\n}"}, {"source_code": "import java.util.Scanner\n\nfun main(){\n var input = Scanner(System.`in`)\n var s = input.next()\n var length = removeDistincts(s).length\n if(length % 2 == 0)\n println(\"CHAT WITH HER!\")\n else\n println(\"IGNORE HIM!\")\n}\nfun removeDistincts(str : String) : String {\n\n var charArr = str.toCharArray()\n var arr = arrayListOf()\n for (i in 0..charArr.size-1){\n arr.add(charArr.get(i))\n }\n var i = 0\n var j = 1\n while (i < arr.size-1){\n j = i +1\n while (j < arr.size) {\n if (arr.get(i) == arr.get(j)) {\n arr.removeAt(j)\n } else\n j++\n }\n i++\n }\n return arr.toString()\n\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n\nfun main() {\n\tval str = readLn()\n\n\tif (str.toSet().size % 2 == 0)\n\t\tprintln(\"CHAT WITH HER!\")\n\telse\n\t\tprintln(\"IGNORE HIM!\")\n}\n"}, {"source_code": "import java.util.*\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val username = scanner.next().toSet()\n\n if (username.size % 2 == 0) {\n println(\"CHAT WITH HER!\")\n } else {\n println(\"IGNORE HIM!\")\n }\n}"}, {"source_code": "fun main() {\n val data = readLine()!!.map { it.toString() }.sorted()\n\n val unique = data.reduce { acc, s ->\n if (acc.last().toString() == s) acc else acc + s\n }.length\n if (unique % 2 == 0) {\n println(\"CHAT WITH HER!\")\n } else {\n println(\"IGNORE HIM!\")\n }\n}"}, {"source_code": "fun main(args: Array) {\n\tval userInput: String? = readLine()\n\tval user = userInput!!\n\tprintln(checkIfMale(user))\n}\n\nfun checkIfMale(user: String): String {\n\tval listOfChars = user.toList();\n\tval set = hashSetOf()\n\tfor(char in listOfChars){\n\t\tif(!set.contains(char)){\n\t\t\tset.add(char)\n\t\t}\n\t}\n\t\n\treturn if(set.size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\"\n}"}, {"source_code": "/**\n *\n * Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a\n * user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so).\n * After that they talked very often and eventually they became a couple in the network.\n *\n * But yesterday, he came to see \"her\" in the real world and found out \"she\" is actually a very strong man! Our hero is\n * 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.\n *\n * This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she\n * 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.\n *\n * Input\n * The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.\n *\n * Output\n * If it is a female by our hero's method, print \"CHAT WITH HER!\" (without the quotes), otherwise, print \"IGNORE HIM!\" (without the quotes).\n */\nfun main(){\n val input = readLine()\n val listChar = mutableListOf()\n input!!.forEach {\n if(!listChar.contains(it.toString())){\n listChar += it.toString()\n }\n }\n if(listChar.size and 1 == 0){\n // the number of distinct chars is even\n println(\"CHAT WITH HER!\")\n }\n else{\n // the number of distinct chars is odd\n println(\"IGNORE HIM!\")\n }\n}"}, {"source_code": "fun main() {\n val username = readLine()!!.toCharArray()\n val distinctChars = username.distinct()\n print(if(distinctChars.size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}"}], "negative_code": [{"source_code": "fun main(args: Array) {\n if(checkGender(readLine().toString())) {\n println(\"CHAT WITH HER\")\n }\n else {\n println(\"IGNORE HIM\")\n }\n}\nfun checkGender(hello:String):Boolean {\n val map: HashMap = HashMap()\n for(c in hello){\n if(!map.containsKey(c)){\n map[c] = 1\n }\n }\n return map.size%2==0\n }"}, {"source_code": "//package codeforces\n\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val In = BufferedReader(InputStreamReader(System.`in`))\n val name = In.readLine()!!.toSet()\n if(name.size % 2 ==0)\n println(\"IGNORE HIM!\")\n else\n println(\"CHAT WITH HER!\")\n}"}, {"source_code": "fun main(){\n val s = readLine()!!\n var repeat = 0\n for (i in 0..s.length-1){\n for (j in (i+1)..s.length -1) {\n if (s[i].compareTo(s[j]) == 0) repeat++\n }\n }\n if ((s.length - repeat) % 2 == 0) println(\"CHAT WITH HER!\") else println(\"IGNORE HIM!\")\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val result = reader.readLine().length % 2 == 0\n println(if (result) \"IGNORE HIM!\" else \"CHAT WITH HER!\")\n}"}, {"source_code": "fun main(args: Array) {\n val count = readLine()!!.toSet().size\n println(if (count % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM\")\n}\n\n"}, {"source_code": "\nfun main(){\n val input = readLine()\n val listChar = mutableListOf()\n input!!.forEach {\n if(!listChar.contains(it.toString())){\n listChar += it.toString()\n }\n }\n if(listChar.size and 1 == 0){\n // the number of distinct chars is even\n println(\"IGNORE HIM!\")\n }\n else{\n // the number of distinct chars is odd\n println(\"CHAT WITH HER!\")\n }\n}"}], "src_uid": "a8c14667b94b40da087501fd4bdd7818"} {"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": "import java.util.*\n\nval reader = Scanner(System.`in`)\nvar c = 0\nvar ans = 0\nfun main(args: Array) {\n val n = reader.nextInt()\n for (i in 1..n)\n c+=reader.nextInt()\n for (i in 1..5)\n {\n if ((i+c)%(n+1) !=1)\n ans++\n }\n /*if ((c+1)%(n+1)==1)\n println(2)\n else\n println(3)*/\n println(ans)\n}"}, {"source_code": "fun main() {\n var n = readLine()!!.toInt()\n var list = readLine()!!.split(' ').map { it.toInt() }.sum()\n var ans = 0\n for (i in 1..5) {\n if ((list + i) % (n + 1) != 1) {\n ans++\n }\n }\n println(ans)\n}"}, {"source_code": "fun main(args: Array) {\n\n var n = readLine()!!.toLong()\n n++\n\n var sum = 0L\n var res = 0L\n\n readLine()!!.split(' ').map { sum += it.toLong() }\n\n sum--;\n\n for (i in 1..5) {\n if ((sum + i) % n != 0L) res++\n }\n\n print(res)\n\n\n\n}\n"}, {"source_code": "fun main() {\n var n = readLine()!!.toInt() + 1\n val total = readLine()!!.split(\" \").map{ it.toInt() }.reduce{ sum, e -> sum + e }\n var count = 0\n for(i in 1..5) {\n if((i + total) % n != 1)\n count++\n }\n println(count)\n}"}], "negative_code": [{"source_code": "import java.util.*\n\nval reader = Scanner(System.`in`)\nvar c = 0\nfun main(args: Array) {\n val n = reader.nextInt()\n for (i in 1..n)\n c+=reader.nextInt()\n if ((c+1)%(n+1)==1)\n println(2)\n else\n println(3)\n}"}, {"source_code": "fun main() {\n var n = readLine()!!.toInt()\n var list = readLine()!!.split(' ').map { it.toInt() }.sum()\n var ans = 0\n for (i in 1..5) {\n if ((list + i) % (n + 1) != 1) {\n ans = i\n break\n }\n }\n println(ans)\n}"}], "src_uid": "ff6b3fd358c758324c19a26283ab96a4"} {"nl": {"description": "Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a1, a2, ..., an. His teapot stores w milliliters of tea (w ≤ a1 + a2 + ... + an). Polycarp wants to pour tea in cups in such a way that: Every cup will contain tea for at least half of its volume Every cup will contain integer number of milliliters of tea All the tea from the teapot will be poured into cups All friends will be satisfied. Friend with cup i won't be satisfied, if there exists such cup j that cup i contains less tea than cup j but ai > aj.For each cup output how many milliliters of tea should be poured in it. If it's impossible to pour all the tea and satisfy all conditions then output -1.", "input_spec": "The first line contains two integer numbers n and w (1 ≤ n ≤ 100, ). The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 100).", "output_spec": "Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them. If it's impossible to pour all the tea and satisfy all conditions then output -1.", "sample_inputs": ["2 10\n8 7", "4 4\n1 1 1 1", "3 10\n9 8 10"], "sample_outputs": ["6 4", "1 1 1 1", "-1"], "notes": "NoteIn the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available."}, "positive_code": [{"source_code": "import java.lang.*\nimport java.util.*\nimport kotlin.collections.*\nimport kotlin.math.*\n\nval read = Scanner(System.`in`)\n\nfun main(){\n var n = read.nextInt()\n var w = read.nextInt()\n var a = Array>(n){Pair(30, 5)}\n for (i in a.indices){\n var t = read.nextInt()\n a[i] = Pair(t, i)\n }\n a.sortByDescending { it.first }\n var b = Array>(n){Pair(30, 5)}\n var Sum = 0\n for (i in a.indices){\n var t = ceil(a[i].first.toDouble() / 2).toInt()\n b[i] = Pair(t, a[i].second)\n Sum += t\n }\n\n if (Sum > w){\n print(-1)\n }\n else{\n var cont = w - Sum\n for (i in a.indices){\n //println(\"${b[i].first} $cont\")\n if (b[i].first + cont > a[i].first){\n cont -= (a[i].first - b[i].first)\n b[i] = b[i].copy(first = a[i].first)\n }\n else{\n b[i] = b[i].copy(first = b[i].first + cont)\n cont = 0\n }\n }\n b.sortBy { it.second }\n for (i in b) print(\"${i.first} \")\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(vararg args: String) {\n\n data class Cup(val p: Int, val a: Int, var f: Int = 0)\n\n fun Int.halfUp() = (this + 1) shr 1\n\n with(Scanner(System.`in`)) {\n val n = nextInt()\n val w = nextInt()\n val cups = Array(n) { i -> Cup(i, nextInt()) }\n val halfSum = cups.sumBy { it.a.halfUp() }\n if (halfSum > w) println(-1)\n else {\n var extra = w - halfSum\n val s = cups.sortedBy { -it.a }\n var c = 0\n s.forEach {\n it.f = it.a.halfUp()\n val e = extra.coerceAtMost(it.a - it.f)\n it.f += e\n extra -= e\n }\n println(cups.joinToString(\" \") { it.f.toString() })\n }\n }\n}\n"}, {"source_code": "\nfun debug(x: Any) {\n System.err.println(x)\n}\n\nfun main(args: Array) {\n val (n, w) = readLine()!!.split(\" \").map { it.toInt() }\n val a = readLine()!!.split(\" \").map { it.toInt() }.toMutableList()\n val indexes = a.mapIndexed { index, x -> x to index }.sortedBy { it.first }.map { it.second }\n val sa = a.sorted()\n val b = IntArray(a.size)\n var rem = w\n for ((index, x) in sa.withIndex()) {\n val min = (x + 1) / 2\n if (rem < min) {\n println(-1)\n return\n }\n b[index] = min\n rem -= min\n }\n require(b.toList() == b.sorted())\n for (i in sa.size - 1 downTo 0) {\n val add = Math.min(sa[i] - b[i], rem)\n b[i] += add\n rem -= add\n if (rem == 0) {\n break\n }\n }\n val answer = b.mapIndexed { index, x -> indexes[index] to x }.sortedBy { it.first }.map { it.second }\n println(answer.joinToString(\" \"))\n}"}, {"source_code": "fun main(args: Array) {\n val reg = Regex(\" \")\n var s = readLine()!!.split(reg)\n val n = s[0].toInt()\n var w = s[1].toLong()\n s = readLine()!!.split(reg)\n var a: List = (0..n - 1).map { s[it].toLong() }\n //a = a.sorted().reversed()\n val b: List = (0..n - 1).map { if (a[it] % 2 == 1L) (a[it] + 1) / 2 else a[it] / 2 }\n if (b.sum() > w)\n println(-1)\n else{\n w -= b.sum()\n var c: List> = (0..n - 1).map { Pair(a[it], it) }\n c = c.sortedBy { it.first }.reversed()\n val ans = Array(n, {i -> 0L})\n var i = 0\n while (w > 0 && i < n){\n val pos = c[i].second\n ans[pos] = if (a[pos] < b[pos] + w) a[pos] else b[pos] + w\n w -= (ans[pos] - b[pos])\n ++i\n }\n if (w > 0)\n println(-1)\n else {\n for (j in 0..n - 1)\n print(\"${if (ans[j] == 0L) b[j] else ans[j]} \")\n }\n }\n}"}], "negative_code": [{"source_code": "import java.lang.*\nimport java.util.*\nimport kotlin.collections.*\nimport kotlin.math.*\n\nval read = Scanner(System.`in`)\n\nfun main(){\n var n = read.nextInt()\n var w = read.nextInt()\n var a = Array>(n){Pair(30, 5)}\n for (i in a.indices){\n var t = read.nextInt()\n a[i] = Pair(t, i)\n }\n a.sortByDescending { it.first }\n var b = Array>(n){Pair(30, 5)}\n var Sum = 0\n for (i in a.indices){\n var t = ceil(a[i].first.toDouble() / 2).toInt()\n b[i] = Pair(t, a[i].second)\n Sum += t\n }\n\n if (Sum > w){\n print(-1)\n }\n else{\n var cont = w - Sum\n for (i in a.indices){\n //println(\"${b[i].first} $cont\")\n if (b[i].first + cont >= a[i].first){\n cont = a[i].first - b[i].first\n b[i] = b[i].copy(first = a[i].first)\n }\n else{\n b[i] = b[i].copy(first = b[i].first + cont)\n cont = 0\n }\n }\n b.sortBy { it.second }\n for (i in b) print(\"${i.first} \")\n }\n}"}, {"source_code": "import java.lang.*\nimport java.util.*\nimport kotlin.collections.*\nimport kotlin.math.*\n\nval read = Scanner(System.`in`)\n\nfun main(){\n var n = read.nextInt()\n var w = read.nextInt()\n var a = Array(n){0}\n for (i in a.indices) a[i] = read.nextInt()\n a.sort()\n var b = Array(n){0}\n for (i in a.indices) b[i] = ceil(a[i].toDouble() / 2).toInt()\n\n //println(b.sum())\n if (b.sum() > w){\n print(-1)\n }\n else{\n var cont = w - b.sum()\n for (i in a.indices){\n if (b[i] + cont > a[i]){\n cont = a[i] - b[i]\n b[i] = a[i]\n }\n else{\n b[i] += cont\n cont = 0\n }\n }\n print(b.joinToString(\" \"))\n }\n}"}, {"source_code": "import java.lang.*\nimport java.util.*\nimport kotlin.collections.*\nimport kotlin.math.*\n\nval read = Scanner(System.`in`)\n\nfun main(){\n var n = read.nextInt()\n var w = read.nextInt()\n var a = Array>(n){Pair(30, 5)}\n for (i in a.indices){\n var t = read.nextInt()\n a[i] = Pair(t, i)\n }\n a.sortBy { it.first }\n var b = Array>(n){Pair(30, 5)}\n var Sum = 0\n for (i in a.indices){\n var t = ceil(a[i].first.toDouble() / 2).toInt()\n b[i] = Pair(t, a[i].second)\n Sum += t\n }\n\n //println(b.sum())\n if (Sum > w){\n print(-1)\n }\n else{\n var cont = w - Sum\n for (i in a.indices){\n if (b[i].first + cont > a[i].first){\n cont = a[i].first - b[i].first\n b[i] = b[i].copy(first = a[i].first)\n //b[i].first = a[i].first\n }\n else{\n b[i] = b[i].copy(first = b[i].first + cont)\n //b[i].first += cont\n cont = 0\n }\n }\n b.sortBy { it.second }\n for (i in b) print(\"${i.first} \")\n }\n}"}, {"source_code": "import java.lang.*\nimport java.util.*\nimport kotlin.collections.*\nimport kotlin.math.*\n\nval read = Scanner(System.`in`)\n\nfun main(){\n var n = read.nextInt()\n var w = read.nextInt()\n var a = Array>(n){Pair(30, 5)}\n for (i in a.indices){\n var t = read.nextInt()\n a[i] = Pair(t, i)\n }\n a.sortByDescending { it.first }\n var b = Array>(n){Pair(30, 5)}\n var Sum = 0\n for (i in a.indices){\n var t = ceil(a[i].first.toDouble() / 2).toInt()\n b[i] = Pair(t, a[i].second)\n Sum += t\n }\n\n //println(b.sum())\n if (Sum > w){\n print(-1)\n }\n else{\n var cont = w - Sum\n for (i in a.indices){\n if (b[i].first + cont > a[i].first){\n cont = a[i].first - b[i].first\n b[i] = b[i].copy(first = a[i].first)\n //b[i].first = a[i].first\n }\n else{\n b[i] = b[i].copy(first = b[i].first + cont)\n //b[i].first += cont\n cont = 0\n }\n }\n b.sortBy { it.second }\n for (i in b) print(\"${i.first} \")\n }\n}"}, {"source_code": "fun main(args: Array) {\n val reg = Regex(\" \")\n var s = readLine()!!.split(reg)\n val n = s[0].toInt()\n var w = s[1].toLong()\n s = readLine()!!.split(reg)\n var a: List = (0..n - 1).map { s[it].toLong() }\n //a = a.sorted().reversed()\n val b: List = (0..n - 1).map { if (a[it] % 2 == 1L) (a[it] + 1) / 2 else a[it] / 2 }\n if (b.sum() > w)\n println(-1)\n else{\n w -= b.sum()\n var c: List> = (0..n - 1).map { Pair(a[it], it) }\n c = c.sortedBy { it.first }.reversed()\n val ans = Array(n, {i -> 0L})\n var i = 0\n while (w > 0 && i < n){\n val pos = c[i].second\n ans[pos] = if (a[pos] < b[pos] + w) a[pos] else b[pos] + w\n w -= (ans[pos] - b[pos])\n ++i\n }\n if (i == n)\n println(-1)\n else {\n for (j in 0..n - 1)\n print(\"${if (ans[j] == 0L) b[j] else ans[j]} \")\n }\n }\n}"}], "src_uid": "5d3bb9e03f4c5c8ecb6233bd5f90f3a3"} {"nl": {"description": "Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.In order to pass through a guardpost, one needs to bribe both guards.The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!", "input_spec": "The first line of the input contains integer n (1 ≤ n ≤ 105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 ≤ a, b, c, d ≤ 105) — the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.", "output_spec": "In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line. The guardposts are numbered from 1 to 4 according to the order given in the input. If there are multiple solutions, you can print any of them.", "sample_inputs": ["10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9", "10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8", "5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3"], "sample_outputs": ["1 5 5", "3 4 6", "-1"], "notes": "NoteExplanation of the first example.The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.Explanation of the second example.Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard."}, "positive_code": [{"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val money = readInt()\n val guardPosts = mutableListOf>()\n for (i in 1..4) guardPosts.add(readInts())\n for (pos in 0 until 4)\n for (index1 in 0..1)\n for (index2 in 2..3)\n if (guardPosts[pos][index1] + guardPosts[pos][index2] <= money)\n return print(\"${pos + 1} ${guardPosts[pos][index1]} ${money - guardPosts[pos][index1]}\")\n print(-1)\n}"}], "negative_code": [], "src_uid": "6e7ee0da980beb99ca49a5ddd04089a5"} {"nl": {"description": "Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a \"Double Cola\" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.Write a program that will print the name of a man who will drink the n-th can.Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.", "input_spec": "The input data consist of a single integer n (1 ≤ n ≤ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.", "output_spec": "Print the single line — the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: \"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\" (without the quotes). In that order precisely the friends are in the queue initially.", "sample_inputs": ["1", "6", "1802"], "sample_outputs": ["Sheldon", "Sheldon", "Penny"], "notes": null}, "positive_code": [{"source_code": "\nfun main(args: Array) {\n\n\n fun who(n : Int) = when(n) {\n 1 -> \"Sheldon\"\n 2 -> \"Leonard\"\n 3 -> \"Penny\"\n 4 -> \"Rajesh\"\n else -> \"Howard\"\n }\n\n\n val n = readLine()!!.toInt()\n\n\n fun solve(n : Int) {\n var cnt = 1\n\n while (5 * (2 * cnt - 1) < n) {\n cnt *= 2\n }\n\n var N = 5 * (cnt - 1) + 1\n\n for (i in 1..5) {\n if ( (n >= N) && n < (cnt + N))\n println(who(i))\n N += cnt\n }\n\n }\n\n solve(n)\n\n}\n"}, {"source_code": "fun main(args: Array) {\n DoubleCola()\n}\n\nfun DoubleCola() {\n val names = arrayOf(\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\")\n var n = readLine()!!.toInt()\n var min: Int = 1\n var max: Int = 0\n for (k in 0..Int.MAX_VALUE) {\n var t = (Math.pow(2.0, k.toDouble())).toInt()\n min += 5 * (t / 2)\n max += 5 * t\n if (n <= max) {\n n = (n - min) / t\n println(names[n])\n break\n }\n }\n}\n"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!.toInt()\n //val l = r.readLine()!!.split(\" \").map { it.toInt() }\n var width = 5\n var num = 0L\n while (num + width < n) {\n num += width\n width *= 2\n }\n when{\n (n-num)/width.toDouble()<=0.2 -> println(\"Sheldon\")\n (n-num)/width.toDouble()<=0.4 -> println(\"Leonard\")\n (n-num)/width.toDouble()<=0.6 -> println(\"Penny\")\n (n-num)/width.toDouble()<=0.8 -> println(\"Rajesh\")\n (n-num)/width.toDouble()<=1.0 -> println(\"Howard\")\n }\n}\n"}, {"source_code": "import java.util.*\nimport java.math.*\nimport kotlin.math.*\n\nfun readLn()=readLine()!!\nfun readInt()=readLn().toInt()\nfun readInts()=readLn().split(\" \").map{it.toInt()}\nfun readLong()=readLn().toLong()\nfun readLongs()=readLn().split(\" \").map{it.toLong()}\n\nval out=mutableListOf()\nfun printLine(s:String){out.add(s)}\nfun output(){println(out.joinToString(\"\\n\"))}\n\nfun main(){\n var n=readInt();n--\n var names=arrayOf(\"Sheldon\",\"Leonard\",\"Penny\",\"Rajesh\",\"Howard\")\n var sz=1\n while(sz*5<=n){\n n-=sz*5\n sz*=2\n }\n printLine(names[n/sz])\n output()\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.math.BigDecimal\nimport java.util.*\nimport kotlin.collections.HashMap\n\nobject programkt {\n internal class FastScanner(inpStr: InputStream, private var br: BufferedReader = BufferedReader(InputStreamReader(inpStr)), private var stok: StringTokenizer? = null) {\n private fun nextToken(): String? {\n while (stok == null || !stok!!.hasMoreTokens())\n stok = StringTokenizer(br.readLine() ?: return null)\n return stok!!.nextToken()\n }\n\n fun nextInt() = nextToken()!!.toInt()\n fun nextLong() = nextToken()!!.toLong()\n fun nextDouble() = nextToken()!!.toDouble()\n fun nextChar() = br.read().toChar()\n fun nextLine() = br.readLine()\n fun nextBigInteger() = nextToken()!!.toBigInteger()\n fun nextBigDecimal() = nextToken()!!.toBigDecimal()\n }\n\n @JvmStatic fun main(args: Array) {\n val scanner = FastScanner(System.`in`)\n val n = scanner.nextInt()\n val set = arrayListOf(\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\")\n var s = 5\n var r = 1\n var k = 0\n while(n - s > 0) {\n k = s\n r *= 2\n s += r * 5\n }\n println(set[(n-k-1)/r])\n }\n}"}, {"source_code": "import java.io.*\nimport java.math.BigInteger\nimport java.util.*\nimport kotlin.Comparator\nimport kotlin.math.ceil\nimport kotlin.math.max\nimport kotlin.math.min\n\nval reader = BufferedReader(InputStreamReader(System.`in`))\n\nfun readIntList() = reader.readLine().split(' ').map(String::toInt)\nfun readLongList() = reader.readLine().split(' ').map(String::toLong)\nfun readStringList() = reader.readLine().split(' ')\nfun readInt() = reader.readLine().toInt()\nfun readLong() = reader.readLine().toLong()\nfun readDouble() = reader.readLine().toDouble()\n\nfun main(args: Array) {\n val list = listOf(\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\")\n val n = readInt()\n\n var i = 0\n var d = 1\n while (i < n){\n i += d\n if(n <= i){\n println(list[0])\n return\n }\n\n i += d\n if(n <= i){\n println(list[1])\n return\n }\n\n i += d\n if(n <= i){\n println(list[2])\n return\n }\n\n i += d\n if(n <= i){\n println(list[3])\n return\n }\n\n i += d\n if(n <= i){\n println(list[4])\n return\n }\n\n d *= 2\n }\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val input = InputReader(inputStream)\n val output = PrintWriter(outputStream)\n val solver = Task()\n solver.solve(input, output)\n output.close()\n}\n\nprivate class Task {\n fun solve(input: InputReader, output: PrintWriter) {\n val n = input.nextLong()\n\n var index = 1\n var length = 5\n var multiplier = 1\n\n while (true) {\n val newIndex = index + length\n\n if (n in index..(newIndex - 1)) {\n break\n } else {\n length *= 2\n index = newIndex\n multiplier *= 2\n }\n }\n\n val diff = n - index\n\n val res = when (diff) {\n in 0 until multiplier -> \"Sheldon\"\n in multiplier until 2 * multiplier -> \"Leonard\"\n in 2 * multiplier until 3 * multiplier -> \"Penny\"\n in 3 * multiplier until 4 * multiplier -> \"Rajesh\"\n in 4 * multiplier until 5 * multiplier -> \"Howard\"\n\n else -> throw IllegalArgumentException()\n }\n\n output.println(res)\n }\n}\n\n\nprivate class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n\n operator fun next(): String {\n while (tokenizer == null || tokenizer?.hasMoreTokens()?.not() == true) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextLong(): Long {\n return next().toLong()\n }\n}\n"}, {"source_code": "fun main(args: Array) {\n var n= readLine()!!.toInt()\n val arr=ArrayList()\n arr.add(\"Sheldon\")\n arr.add(\"Leonard\")\n arr.add(\"Penny\")\n arr.add(\"Rajesh\")\n arr.add(\"Howard\")\n while (n>5)\n n=n/2-2\n println(arr[n-1])\n\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val n = br.readLine().toInt()\n val (w, sum) = findWindow(n)\n val segmentSize = pow(2, w.toLong())\n val i = if (n <= 5) 1 else sum - 5*segmentSize\n val j = n - i\n println(\n when (j / segmentSize){\n 0L -> \"Sheldon\"\n 1L -> \"Leonard\"\n 2L -> \"Penny\"\n 3L -> \"Rajesh\"\n else -> \"Howard\"\n }\n )\n\n}\n\nfun pow(a: Long, n: Long): Long {\n tailrec fun go(a: Long, n: Long, acc: Long): Long =\n if (a == 0L) 0\n else if (n == 0L) 1\n else if (n == 1L) a * acc\n else if (n % 2 == 0L) go(a * a, n/2, acc)\n else go(a * a, (n - 1)/2, a * acc)\n\n return go(a, n, 1)\n}\n\nfun findWindow (n: Int): Pair{\n tailrec fun go (i: Int, sum: Int, exp: Int): Pair =\n if (n <= sum) i to sum\n else go(i + 1, sum + 5*exp, exp*2)\n\n return go(0, 5, 2)\n}"}, {"source_code": "import kotlin.math.pow\nfun main(args: Array) {\n doubleCola(Integer.parseInt(readLine()))\n}\n\nfun doubleCola(nthCola:Int){\n\n var elements = 5*(2.0.pow(0))\n var nthEbene = 1\n var range = 0.0\n\n while(elements println(\"Sheldon\")\n nthCola <= range+((elements-range)/5)*2 -> println(\"Leonard\")\n nthCola <= range+((elements-range)/5)*3 -> println(\"Penny\")\n nthCola <= range+((elements-range)/5)*4 -> println(\"Rajesh\")\n nthCola <= range+((elements-range)/5)*5 -> println(\"Howard\")\n }\n}"}, {"source_code": "import kotlin.math.sign\n\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n var m = 0\n var c = 1\n while (n > m + c * 5) {\n m += c * 5\n c *= 2\n }\n println(arrayOf(\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\")[(n - m - 1) / c])\n}"}, {"source_code": "fun main() {\n var n = readLine()!!.toInt()\n var k = 1\n while (k * 5 < n) {\n n -= k * 5\n k *= 2\n }\n\n n = (n - 1) / k\n println(arrayOf(\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\")[n])\n}"}, {"source_code": "fun main() {\n fun readLong() = readLine()!!.toLong()\n\n val people = arrayOf(\"\", \"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\")\n val n = readLong()\n var current = 0L\n var multiplier = 1L\n while (current + multiplier * 5 < n) {\n current += multiplier * 5\n multiplier *= 2\n }\n val pos = (n - current) / multiplier + (if ((n - current) % multiplier == 0L) 0 else 1)\n print(people[pos.toInt()])\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport kotlin.math.ceil\n\nval names = listOf(\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\")\n\nval size = names.count()\n\nfun f(n: Int): Int {\n if (n <= size) {\n return n - 1\n }\n var sum: Int = size\n var prevSum: Int = size\n var perLevel = 2\n var prevPerLevel = 2\n var height = 1\n while (sum < n) {\n prevSum = sum\n prevPerLevel = perLevel\n sum += perLevel * 5\n perLevel *= 2\n height++\n }\n val offset: Int = n - prevSum\n val result = ceil(offset / prevPerLevel.toDouble()).toInt()\n return result - 1\n}\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val n: Int = reader.readLine().toInt()\n val result = f(n)\n println(names[result])\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toLong()\n var s = 1L\n var l = 1L\n var p = 1L\n var r = 1L\n var h = 1L\n var sum = 0L\n while (true) {\n sum += s\n if (sum >= n) {\n println(\"Sheldon\")\n return\n }\n s *= 2\n\n sum += l\n if (sum >= n) {\n println(\"Leonard\")\n return\n }\n l *= 2\n\n sum += p\n if (sum >= n) {\n println(\"Penny\")\n return\n }\n p *= 2\n\n sum += r\n if (sum >= n) {\n println(\"Rajesh\")\n return\n }\n r *= 2\n\n sum += h\n if (sum >= n) {\n println(\"Howard\")\n return\n }\n h *= 2\n }\n}\n"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val a = arrayOf(\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\")\n\n val map = IntArray(5, { 1 })\n\n var step = 0\n var i = 0\n\n while (step < n) {\n step += map[i]\n if (step >= n) println(a[i])\n\n map[i]*=2\n i++\n if (i >= 5) i = 0\n }\n\n\n}"}, {"source_code": "fun printAnswer(number: Int) {\n val names = arrayOf(\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\")\n println(names[number - 1])\n}\n\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n\n if (n <= 5) {\n printAnswer(n)\n return\n }\n\n var doubles = 1\n var c = 5\n \n while (c < n) {\n doubles *= 2\n c += doubles * 5\n }\n var bottom = c - doubles * 5\n var answer = 0\n while (bottom < n) {\n answer ++\n bottom += doubles\n }\n printAnswer(answer)\n}"}, {"source_code": "import java.io.InputStreamReader\nimport java.util.Scanner\n\nfun main(args: Array) {\n val reader = Scanner(InputStreamReader(System.`in`))\n val n = reader.nextInt()\n val names = listOf(\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\")\n var queueSize = 5\n var queueStart = 0\n while (queueStart + queueSize < n) {\n queueStart += queueSize\n queueSize *= 2\n }\n println(names[(n - queueStart - 1) / (queueSize / 5)])\n}"}, {"source_code": "fun main(args: Array) {\n\tvar nums = mutableListOf(5)\n\tvar index: Double = 0.0\n\twhile(true) {\n\t\tnums.add(nums[index.toInt()] + 5*Math.pow(2.0, (index + 1.0)).toInt())\n\t\tindex++\n\t\tif(nums[index.toInt()] > 1000000000) {\n\t\t\tbreak\n\t\t}\n\t}\n\tvar n = readLine()!!.toInt()\n\tvar result: Double = 0.0\n\tfor(i in 0..nums.size - 1) {\n\t\tif(nums[i] >= n) {\n\t\t\tif(i == 0)\n\t\t\t\tresult = n.toDouble()\n\t\t\telse\n\t\t\t\tresult = ((n - nums[i-1]).toDouble())/Math.pow(2.0, i.toDouble())\n\t\t\tresult = Math.ceil(result)\n\t\t\tbreak\n\t\t}\n\t}\n\twhen(result.toInt()) {\n\t\t1 -> println(\"Sheldon\")\n\t\t2 -> println(\"Leonard\")\n\t\t3 -> println(\"Penny\")\n\t\t4 -> println(\"Rajesh\")\n\t\t5 -> println(\"Howard\")\n\t}\n}"}], "negative_code": [{"source_code": "import java.io.*\nimport java.util.*\n\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val input = InputReader(inputStream)\n val output = PrintWriter(outputStream)\n val solver = Task()\n solver.solve(input, output)\n output.close()\n}\n\nprivate class Task {\n fun solve(input: InputReader, output: PrintWriter) {\n val n = input.nextLong()\n\n var index = 1\n var length = 5\n var multiplier = 1\n\n while (true) {\n val newIndex = index + length\n\n if (n in index..(newIndex - 1)) {\n break\n } else {\n length *= 2\n index = newIndex\n multiplier *= 2\n }\n }\n\n val diff = n - index\n\n val res = when (diff) {\n in 0..multiplier -> \"Sheldon\"\n in multiplier..2 * multiplier -> \"Leonard\"\n in 2 * multiplier..3 * multiplier -> \"Penny\"\n in 3 * multiplier..4 * multiplier -> \"Rajesh\"\n in 4 * multiplier..5 * multiplier -> \"Howard\"\n\n else -> throw IllegalArgumentException()\n }\n\n output.println(res)\n }\n}\n\n\nprivate class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n\n operator fun next(): String {\n while (tokenizer == null || tokenizer?.hasMoreTokens()?.not() == true) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextLong(): Long {\n return next().toLong()\n }\n}"}, {"source_code": "fun main() {\n var n = readLine()!!.toInt()\n var k = 1\n while (5 * k * (k + 1) / 2 < n) k++\n n -= 5 * k * (k - 1) / 2\n n = (n - 1) / k\n println(arrayOf(\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\")[n])\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nval names = listOf(\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\")\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val n = reader.readLine().toInt()\n var nodesCount = 5\n var sum = 5\n var offset = n\n while (sum < n) {\n offset -= nodesCount\n nodesCount *= 2\n sum += nodesCount\n }\n val width = nodesCount / 5\n val index = if (offset / width - 1 <= 0) 0 else offset / width\n println(names[index])\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nval names = listOf(\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\")\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val n = reader.readLine().toInt()\n var nodesCount = 5\n var sum = 5\n var offset = n\n while (sum < n) {\n offset -= nodesCount\n nodesCount *= 2\n sum += nodesCount\n }\n val width = nodesCount / 5\n val index = if (offset / width - 1 < 0) 0 else offset / width\n println(names[index])\n}"}, {"source_code": "fun main(args: Array) {\n\tvar nums = mutableListOf(5)\n\tvar index: Double = 0.0\n\twhile(true) {\n\t\tnums.add(nums[index.toInt()] + 5*Math.pow(2.0, (index + 1.0)).toInt())\n\t\tindex++\n\t\tif(nums[index.toInt()] > 1000000000) {\n\t\t\tbreak\n\t\t}\n\t}\n\t\n\tprintln(nums)\n\tvar n = readLine()!!.toInt()\n\tvar result: Double = 0.0\n\tfor(i in 0..nums.size - 1) {\n\t\tif(nums[i] >= n) {\n\t\t\tif(i == 0)\n\t\t\t\tresult = n.toDouble()\n\t\t\telse\n\t\t\t\tresult = ((n - nums[i-1]).toDouble())/Math.pow(2.0, i.toDouble())\n\t\t\tresult = Math.ceil(result)\n\t\t\tbreak\n\t\t}\n\t}\n\twhen(result.toInt()) {\n\t\t1 -> println(\"Sheldon\")\n\t\t2 -> println(\"Leonard\")\n\t\t3 -> println(\"Penny\")\n\t\t4 -> println(\"Rajesh\")\n\t\t5 -> println(\"Howard\")\n\t}\n}"}], "src_uid": "023b169765e81d896cdc1184e5a82b22"} {"nl": {"description": "Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number.For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7).A number's length is the number of digits in its decimal representation without leading zeroes.", "input_spec": "The first line contains three integers: a, b, n (1 ≤ a < b ≤ 9, 1 ≤ n ≤ 106).", "output_spec": "Print a single integer — the answer to the problem modulo 1000000007 (109 + 7).", "sample_inputs": ["1 3 3", "2 3 10"], "sample_outputs": ["1", "165"], "notes": null}, "positive_code": [{"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n val a = readInt()\n val b = readInt()\n val n = readInt()\n\n val mc = ArrayModCombinatorics(n)\n\n var ans = ModInt(0)\n for(i in 0..n) {\n val sum = a * i + b * (n-i)\n if(sum.toString().all { (it - '0').let { it == a || it == b } }) ans += mc.C(n, i)\n }\n println(ans.int)\n}\n\nclass ArrayModCombinatorics(val maxn: Int) {\n val factorial = ModIntArray(maxn + 1).also {\n it[0] = ModInt(1)\n for(i in 1 .. maxn) {\n it[i] = it[i-1] * i\n }\n }\n\n val invf = ModIntArray(maxn + 1).also {\n it[maxn] = factorial[maxn].inv_unmemoized()\n for(i in maxn downTo 1) {\n it[i-1] = it[i] * i\n }\n }\n\n fun P(n: Int, k: Int) = if(k > n) ModInt(0) else factorial[n] * invf[n-k]\n fun C(n: Int, k: Int) = if(k > n) ModInt(0) else factorial[n] * invf[k] * invf[n-k]\n}\n\nconst val BILLION7 = 1e9.toInt() + 7\nconst val MOD = BILLION7\nconst val TOTIENT = MOD - 1 // assumes MOD is prime\n\ninfix fun Int.umod(mod: Int): Int = (this % mod).let { (it shr Int.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Long) = (this % mod).let { (it shr Long.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Int) = umod(mod.toLong()).toInt()\n\nfun Int.mulMod(other: Int, mod: Int) = toLong() * other umod mod\n\nfun Int.powMod(exponent: Int, mod: Int): Int {\n if(exponent < 0) error(\"Inverse not implemented\")\n var res = 1L\n var e = exponent\n var b = umod(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\n\ninline fun Int.toModInt() = ModInt(this umod MOD)\ninline fun Long.toModInt() = ModInt(this umod MOD)\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n companion object {\n /** can't seem to make these private or inlined without causing compiler issues */\n @JvmField val _invMemo = HashMap()\n fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }\n }\n\n // normalizes an integer that's within range [-MOD, MOD) without branching\n private inline fun normalize(int: Int) = ModInt((int shr Int.SIZE_BITS - 1 and MOD) + int)\n\n operator fun plus(other: ModInt) = normalize(int + other.int - MOD) // overflow-safe even if MOD >= 2^30\n inline operator fun plus(other: Int) = plus(other.toModInt())\n operator fun inc() = normalize(int + (1 - MOD))\n\n operator fun minus(other: ModInt) = normalize(int - other.int)\n inline operator fun minus(other: Int) = minus(other.toModInt())\n operator fun dec() = normalize(int - 1)\n operator fun unaryMinus() = normalize(-int)\n\n operator fun times(other: ModInt) = ModInt((int.toLong() * other.int % MOD).toInt())\n inline operator fun times(other: Int) = ModInt(int.mulMod(other, MOD))\n\n fun pow(exponent: Int): ModInt {\n val e = if(exponent < 0) {\n require(int != 0) { \"Can't invert/divide by 0\" }\n exponent umod TOTIENT\n } else exponent\n return ModInt(int.powMod(e, MOD))\n }\n\n fun pow(exponent: Long) = if(int == 0) when {\n exponent > 0 -> this\n exponent == 0L -> ModInt(1)\n else -> error(\"Can't invert/divide by 0\")\n } else pow(exponent umod TOTIENT)\n\n inline fun inverse() = inv_memoized() /** NOTE: Change if necessary */\n\n fun inv_unmemoized(): ModInt {\n require(int != 0) { \"Can't invert/divide by 0\" }\n return pow(TOTIENT - 1)\n }\n inline fun inv_memoized() = _invMemoized(this)\n\n operator fun div(other: ModInt) = times(other.inverse())\n inline operator fun div(other: Int) = div(other.toModInt())\n\n override inline fun toString() = int.toString()\n}\n\ninline operator fun Int.plus(modInt: ModInt) = modInt + this\ninline operator fun Int.minus(modInt: ModInt) = toModInt() - modInt\ninline operator fun Int.times(modInt: ModInt) = modInt * this\ninline operator fun Int.div(modInt: ModInt) = modInt.inverse() * this\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n inline operator fun get(i: Int) = ModInt(intArray[i])\n inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override inline val size: Int get() = intArray.size\n inline val lastIndex get() = intArray.lastIndex\n inline val indices get() = intArray.indices\n\n override inline fun contains(element: ModInt): Boolean = element.int in intArray\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override inline fun isEmpty(): Boolean = intArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): ModInt = get(index++)\n }\n\n fun copyOf(newSize: Int) = ModIntArray(intArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun ModIntArray.copyInto(destination: ModIntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =\n ModIntArray(intArray.copyInto(destination.intArray, destinationOffset, startIndex, endIndex))\ninline fun ModIntArray(size: Int) = ModIntArray(IntArray(size))\ninline fun ModIntArray(size: Int, init: (Int) -> ModInt) = ModIntArray(IntArray(size) { init(it).int })\n\nfun ModInt.powArray(n: Int): ModIntArray {\n val res = ModIntArray(n+1)\n res[0] = ModInt(1)\n for(i in 1..n) res[i] = res[i-1] * this\n return res\n}\n\ninline fun ModIntArray.first() = get(0)\ninline fun ModIntArray.last() = get(lastIndex)\ninline fun ModIntArray.fold(init: R, op: (acc: R, ModInt) -> R) = intArray.fold(init) { acc, i -> op(acc, ModInt(i)) }\nfun ModIntArray.sum() = fold(ModInt(0), ModInt::plus)\nfun ModIntArray.product() = fold(ModInt(1), ModInt::times)\n\ninline fun Iterable.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Iterable.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\ninline fun Sequence.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Sequence.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\ninline fun Array.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Array.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\nfun Iterable.sum() = sumByModInt { it }\nfun Sequence.sum() = sumByModInt { it }\nfun Iterable.product() = productByModInt { it }\nfun Sequence.product() = productByModInt { it }\nfun Collection.toModIntArray() = ModIntArray(size).also { var i = 0; for(e in this) { it[i++] = e } }\n\ninline fun Iterable.sumByLong(func: (T) -> Long) = fold(0L) { acc, t -> acc + func(t) }\ninline fun Sequence.sumByLong(func: (T) -> Long) = fold(0L) { acc, t -> acc + func(t) }\ninline fun Array.sumByLong(func: (T) -> Long) = fold(0L) { acc, t -> acc + func(t) }\nfun IntArray.sumLong() = fold(0L, Long::plus)\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _ln = \"\"\n@JvmField var _lnPtr = 0\nfun read(): String {\n while (_lnPtr >= _ln.length) {\n _ln = readLine() ?: return \"\"\n _lnPtr = 0\n }\n var j = _ln.indexOf(' ', _lnPtr)\n if(j < 0) j = _ln.length\n val res = _ln.substring(_lnPtr, j)\n _lnPtr = j + 1\n return res\n}\nfun readRem(): String /* reads remainder of current line */ =\n _ln.substring(min(_lnPtr, _ln.length)).also { _lnPtr = _ln.length }\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nval m = (1e9 + 7).toLong()\nval maxN = (1e6 + 300).toInt()\nval fact by lazy { precFact() }\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val abn = br.readLine().split(\" \").map { it.toInt() }\n val a = abn[0]\n val b = abn[1]\n val n = abn[2]\n\n println(numWays(a, b, n))\n\n}\n\nfun numWays(a: Int, b: Int, n: Int): Long{\n tailrec fun go(i: Int, acc: Long): Long =\n if (i == n + 1) acc % m\n else if (isGood(a*i + b*(n-i), a, b)){\n go(i + 1, combination(n, i) + acc)\n }\n else\n go(i + 1, acc)\n return go(0, 0)\n}\n\n\nfun combination(n: Int, i: Int): Long {\n val inv = binExp(fact[i]*fact[n - i], m - 2, m)\n return (fact[n] * inv) % m\n}\n\nfun isGood(num: Int, a: Int, b: Int): Boolean{\n tailrec fun go(digit: Int, rest: Int, a: Int, b: Int): Boolean =\n if (rest == 0) digit == a || digit == b\n else{\n if (digit != a && digit != b) false\n else go(rest % 10, rest / 10, a, b)\n }\n val ans = go(num % 10, num / 10, a, b)\n return go(num % 10, num / 10, a, b)\n}\n\nfun binExp(a: Long, x: Long, m: Long): Long{\n tailrec fun go(a: Long, x: Long, acc: Long): Long =\n if (x == 0L) 1\n else {\n if (x == 1L) (a * acc) % m\n else if (x % 2 == 0L) go((a * a) % m, x/2, acc)\n else go((a * a) % m, (x - 1)/2, (a * acc) % m)\n }\n return go(a % m, x ,1)\n}\n\n\nfun precFact(): Array{\n val fact = Array(maxN){_ -> 0L}\n fact[0] = 1\n for (i in 1 until maxN){\n fact[i] = (i % m * fact[i - 1] % m ) % m\n }\n return fact\n}"}], "negative_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nval m = 1000000007L\nval maxN = 1000000\nval fact by lazy { precFact() }\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val abn = br.readLine().split(\" \").map { it.toInt() }\n val a = abn[0]\n val b = abn[1]\n val n = abn[2]\n\n println(numWays(a, b, n))\n\n}\n\nfun numWays(a: Int, b: Int, n: Int): Long{\n tailrec fun go(i: Int, acc: Long): Long =\n if (i == n + 1) acc % m\n else if (isGood(a*i + b*(n-i), a, b)){\n go(i + 1, combination(n, i) + acc % m)\n }\n else\n go(i + 1, acc)\n return go(0, 0)\n}\n\n\nfun combination(n: Int, i: Int): Long {\n val inv = binExp(fact[i]*fact[n - i], m - 2, m)\n return (fact[n] * inv) % m\n}\n\nfun isGood(num: Int, a: Int, b: Int): Boolean{\n tailrec fun go(digit: Int, rest: Int, a: Int, b: Int): Boolean =\n if (rest == 0) digit == a || digit == b\n else{\n if (digit != a && digit != b) false\n else go(rest % 10, rest / 10, a, b)\n }\n val ans = go(num % 10, num / 10, a, b)\n return go(num % 10, num / 10, a, b)\n}\n\nfun binExp(a: Long, x: Long, m: Long): Long{\n tailrec fun go(a: Long, x: Long, acc: Long): Long =\n if (x == 0L) 1\n else {\n if (x == 1L) (a % m * acc % m) % m\n else if (x % 2 == 0L) go((a % m * a % m) % m, x/2, acc)\n else go((a % m * a % m) % m, (x - 1)/2, (a % m * acc % m) % m)\n }\n return go(a, x ,1)\n}\n\nfun precFact(): Array{\n val fact = Array(maxN){_ -> 0L}\n fact[0] = 1\n for (i in 1 until maxN){\n fact[i] = (i % m * fact[i - 1] % m ) % m\n }\n return fact\n}"}], "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81"} {"nl": {"description": "You are given a string s consisting of |s| small english letters.In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.Your target is to make some number of moves (not necessary minimal) to get string abcdefghijklmnopqrstuvwxyz (english alphabet) as a subsequence. Subsequence of the string is the string that is obtained by deleting characters at some positions. You need to print the string that will be obtained from the given string and will be contain english alphabet as a subsequence or say that it is impossible.", "input_spec": "The only one line of the input consisting of the string s consisting of |s| (1 ≤ |s| ≤ 105) small english letters.", "output_spec": "If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes).", "sample_inputs": ["aacceeggiikkmmooqqssuuwwyy", "thereisnoanswer"], "sample_outputs": ["abcdefghijklmnopqrstuvwxyz", "-1"], "notes": null}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val s = reader.next().toCharArray()\n var i = 0\n var t = 0\n while (i < s.size && t != 26) {\n val c = 'a' + t\n if (c < s[i]) {\n i++\n continue\n }\n\n s[i] = c\n i++\n t++\n }\n if (t != 26) {\n writer.print(\"-1\")\n } else {\n writer.print(StringBuilder().append(s))\n }\n}\n\nclass InputReader(stream: InputStream) {\n val reader: BufferedReader\n var tokenizer: StringTokenizer? = null\n\n init {\n reader = BufferedReader(InputStreamReader(stream), 32768)\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}\n\n"}, {"source_code": "\nfun main(args: Array) {\n System.`in`.bufferedReader().use {\n val s = it.readLine()\n\n // Find 'a'.\n var i = 0\n while (i < s.length && s[i] != 'a')\n ++i\n\n if (i >= s.length) {\n println(-1)\n return\n }\n\n val start = i\n ++i\n var ok = true\n for (ch in 'b' .. 'z') {\n while (i < s.length && s[i] > ch)\n ++i\n if (i >= s.length) {\n ok = false\n break\n }\n ++i\n }\n\n if (!ok) {\n println(-1)\n return\n }\n\n for (j in 0 .. start)\n print(s[j])\n\n i = start + 1\n for (ch in 'b' .. 'z') {\n while (i < s.length && s[i] > ch) {\n print(s[i])\n ++i\n }\n assert(i < s.length)\n print(ch)\n ++i\n }\n while (i < s.length)\n print(s[i++])\n println()\n }\n}\n"}, {"source_code": "fun main() {\n val text = readLine()!!.toCharArray()\n var expected = 'a'\n for (pos in 0 until text.size) {\n if (text[pos] <= expected) {\n text[pos] = expected\n expected++\n if (expected > 'z') {\n break\n }\n }\n }\n print(if (expected > 'z') text.joinToString(\"\") else -1)\n}\n"}, {"source_code": "class C {\n fun run() {\n val sourceLine = readLine()!!\n val alphabet = \"abcdefghijklmnopqrstuvwxyz\"\n var alphabetIndex = 0\n val result = StringBuilder()\n for (letter in sourceLine) {\n if(alphabetIndex < alphabet.length) {\n result.append(if (letter <= alphabet[alphabetIndex]) {\n alphabet[alphabetIndex++]\n } else letter)\n } else result.append(letter)\n }\n println(if(alphabetIndex < alphabet.length) \"-1\" else result.toString())\n }\n}\n\nfun main(args: Array) {\n C().run()\n}"}], "negative_code": [{"source_code": "fun main() {\n val text = readLine()\n var found = false\n var start = 0\n var pos = start\n var expected = 'a'\n while (pos < text!!.length && !found) {\n if(text[pos] <= expected) {\n expected++\n if (expected > 'z') {\n found = true\n }\n } else {\n start = pos + 1\n expected = 'a'\n }\n pos++\n }\n if (!found) {\n print(-1)\n } else {\n if(start > 0) {\n print(text.substring(0, start))\n }\n print(\"abcdefghijklmnopqrstuvwxyz\")\n if(start + 26 < text.length) {\n print(text.substring(start + 26 - 1))\n }\n }\n}"}, {"source_code": "fun main() {\n val text = readLine()\n if (text!!.startsWith(\"kilxjakqdnsopqjyylldfwahknloaiqyhulluazaiacxsthvpsyvsaxwjjeukaqkndvnnamjdoygfxweyarcvxfxgjbqgusleydluvixsvgyaojqfaheitonqtnng\")) {\n print(text.substring(500))\n }\n var found = false\n var start = 0\n var pos = start\n var expected = 'a'\n while (pos < text!!.length && !found) {\n if(text[pos] <= expected) {\n expected++\n if (expected > 'z') {\n found = true\n }\n } else {\n start = pos + 1\n expected = 'a'\n }\n pos++\n }\n if (!found) {\n print(-1)\n } else {\n if(start > 0) {\n print(text.substring(0, start))\n }\n print(\"abcdefghijklmnopqrstuvwxyz\")\n if(start + 26 < text.length) {\n print(text.substring(start + 26 - 1))\n }\n }\n}"}, {"source_code": "fun main() {\n val text = readLine()\n var found = false\n var start = 0\n var pos = start\n var expected = 'a'\n while (start < text!!.length && !found) {\n if(text[pos] <= expected) {\n expected++\n if (expected > 'z') {\n found = true\n }\n } else {\n start = pos + 1\n expected = 'a'\n }\n pos++\n }\n if (!found) {\n print(-1)\n } else {\n if(start > 0) {\n print(text.substring(0, start))\n }\n print(\"abcdefghijklmnopqrstuvwxyz\")\n if(start + 26 < text.length) {\n print(text.substring(start + 26 - 1))\n }\n }\n}"}], "src_uid": "f8ad543d499bcc0da0121a71a26db854"} {"nl": {"description": "Arpa is taking a geometry exam. Here is the last problem of the exam.You are given three points a, b, c.Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.", "input_spec": "The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| ≤ 109). It's guaranteed that the points are distinct.", "output_spec": "Print \"Yes\" if the problem has a solution, \"No\" otherwise. You can print each letter in any case (upper or lower).", "sample_inputs": ["0 1 1 1 1 0", "1 1 0 0 1000 1000"], "sample_outputs": ["Yes", "No"], "notes": "NoteIn the first sample test, rotate the page around (0.5, 0.5) by .In the second sample test, you can't find any solution."}, "positive_code": [{"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val ax = sc.nextLong()\n val ay = sc.nextLong()\n val bx = sc.nextLong()\n val by = sc.nextLong()\n val cx = sc.nextLong()\n val cy = sc.nextLong()\n\n val d1 = (bx - ax) * (bx - ax) + (by - ay) * (by - ay)\n val d2 = (cx - bx) * (cx - bx) + (cy - by) * (cy - by)\n\n when {\n Math.abs((bx - ax) * (cy - ay)) == Math.abs((by - ay) * (cx - ax)) -> println(\"No\")\n d1 != d2 -> println(\"No\")\n else -> println(\"Yes\")\n }\n\n}\n"}], "negative_code": [], "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab"} {"nl": {"description": "A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).Consider a permutation $$$p$$$ of length $$$n$$$, we build a graph of size $$$n$$$ using it as follows: For every $$$1 \\leq i \\leq n$$$, find the largest $$$j$$$ such that $$$1 \\leq j < i$$$ and $$$p_j > p_i$$$, and add an undirected edge between node $$$i$$$ and node $$$j$$$ For every $$$1 \\leq i \\leq n$$$, find the smallest $$$j$$$ such that $$$i < j \\leq n$$$ and $$$p_j > p_i$$$, and add an undirected edge between node $$$i$$$ and node $$$j$$$ In cases where no such $$$j$$$ exists, we make no edges. Also, note that we make edges between the corresponding indices, not the values at those indices.For clarity, consider as an example $$$n = 4$$$, and $$$p = [3,1,4,2]$$$; here, the edges of the graph are $$$(1,3),(2,1),(2,3),(4,3)$$$.A permutation $$$p$$$ is cyclic if the graph built using $$$p$$$ has at least one simple cycle. Given $$$n$$$, find the number of cyclic permutations of length $$$n$$$. Since the number may be very large, output it modulo $$$10^9+7$$$.Please refer to the Notes section for the formal definition of a simple cycle", "input_spec": "The first and only line contains a single integer $$$n$$$ ($$$3 \\le n \\le 10^6$$$).", "output_spec": "Output a single integer $$$0 \\leq x < 10^9+7$$$, the number of cyclic permutations of length $$$n$$$ modulo $$$10^9+7$$$.", "sample_inputs": ["4", "583291"], "sample_outputs": ["16", "135712853"], "notes": "NoteThere are $$$16$$$ cyclic permutations for $$$n = 4$$$. $$$[4,2,1,3]$$$ is one such permutation, having a cycle of length four: $$$4 \\rightarrow 3 \\rightarrow 2 \\rightarrow 1 \\rightarrow 4$$$.Nodes $$$v_1$$$, $$$v_2$$$, $$$\\ldots$$$, $$$v_k$$$ form a simple cycle if the following conditions hold: $$$k \\geq 3$$$. $$$v_i \\neq v_j$$$ for any pair of indices $$$i$$$ and $$$j$$$. ($$$1 \\leq i < j \\leq k$$$) $$$v_i$$$ and $$$v_{i+1}$$$ share an edge for all $$$i$$$ ($$$1 \\leq i < k$$$), and $$$v_1$$$ and $$$v_k$$$ share an edge. "}, "positive_code": [{"source_code": "import java.math.BigInteger\n\ntailrec fun fac(n: BigInteger, acc: BigInteger): BigInteger =\n if (n == BigInteger.ONE) acc else fac(\n n - BigInteger.ONE,\n acc * n % BigInteger.valueOf(1000000007)\n )\n\nfun pow(a: Int):Long{\n var n = a\n var base = 2L\n var num = 1L\n while (n> 0){\n if (n% 2== 1){\n num = num* base%1000000007L\n }\n n /= 2\n base = base*base%1000000007L\n }\n return num\n}\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val len = r.readLine()!!.toInt()\n //val (n, m, k) = r.readLine()!!.split(\" \").map { it.toInt() }\n val n = r.readLine()!!.toLong()\n var ans = fac(BigInteger.valueOf(n), BigInteger.ONE) - pow((n-1).toInt()).toBigInteger()\n if (ans< BigInteger.ZERO) ans += BigInteger.valueOf(1000000007)\n println(ans)\n}"}, {"source_code": "import javafx.scene.layout.Priority\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\nimport kotlin.math.*\nimport kotlin.system.exitProcess\n\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\nconst val _BUFFER_SIZE = 1 shl 16\n@JvmField val _buffer = ByteArray(_BUFFER_SIZE)\n@JvmField var _bufferPt = 0\n@JvmField var _bytesRead = 0\n\ntailrec fun readChar(): Char {\n if(_bufferPt == _bytesRead) {\n _bufferPt = 0\n _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)\n }\n return if(_bytesRead < 0) Char.MIN_VALUE\n else {\n val c = _buffer[_bufferPt++].toChar()\n if (c == '\\r') readChar()\n else c\n }\n}\n\nfun readLine(): String? {\n var c = readChar()\n return if(c == Char.MIN_VALUE) null\n else buildString {\n while(true) {\n when(c) {\n '\\n', Char.MIN_VALUE -> return@buildString\n else -> {\n append(c)\n c = readChar()\n }\n }\n }\n }\n}\nfun readLn() = readLine()!!\n\nfun read() = buildString {\n var c = readChar()\n while(c <= ' ') {\n if(c == Char.MIN_VALUE) return@buildString\n c = readChar()\n }\n do {\n append(c)\n c = readChar()\n } while(c > ' ')\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\nfun main() {\n val MOD = 1_000_000_000 + 7\n val n = readInt()\n\n var result = 1L\n\n for (i in 1..n) {\n result = result * i % MOD\n }\n\n var x = 1L\n for (i in 1..n-1) {\n x = (2 * x) % MOD\n }\n\n result = (result - x) % MOD\n if (result < 0) {\n result += MOD\n }\n\n println(result)\n}"}, {"source_code": "fun main() {\n val n = readInt()\n\n val mod = 1000000007L\n val factorial = (1L..n).reduce { acc, num -> (acc * num) % mod }\n val pow2 = (1 until n).fold(1L) { acc, _ -> (acc * 2) % mod }\n\n println(((factorial + mod) - pow2) % mod)\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\n\nprivate fun readInt() = readLn().toInt()"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n//@file:OptIn(ExperimentalStdlibApi::class)\n\nimport java.io.File\nimport java.io.PrintWriter\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n// val startTime = System.nanoTime()\n\n val numCases = 1//readInt()\n case@ for(case in 1..numCases) {\n// print(\"Case #$case: \")\n\n val n = readInt()\n\n val ans = (1..n).productByModInt { ModInt(it) } - ModInt(2).pow(n-1)\n\n println(ans)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nconst val BILLION7 = 1e9.toInt() + 7\nconst val MOD = BILLION7\nconst val TOTIENT = MOD - 1 // assumes MOD is prime\n\ninfix fun Int.modulo(mod: Int): Int = (this % mod).let { (it shr Int.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.modulo(mod: Long) = (this % mod).let { (it shr Long.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.modulo(mod: Int) = modulo(mod.toLong()).toInt()\n\nfun Int.mulMod(other: Int, mod: Int) = toLong() * other modulo mod\n\nfun Int.powMod(exponent: Long, mod: Int): Int {\n if(exponent < 0) error(\"Inverse not implemented\")\n var res = 1L\n var e = exponent\n var b = modulo(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1L) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\nfun Int.powMod(exponent: Int, mod: Int) = powMod(exponent.toLong(), mod)\nfun Int.modPowArray(n: Int, mod: Int): IntArray {\n val res = IntArray(n+1)\n res[0] = 1\n for(i in 1..n) res[i] = mulMod(res[i-1], mod)\n return res\n}\n\ninline fun Int.toModInt() = ModInt(this modulo MOD)\ninline fun Long.toModInt() = ModInt(this modulo MOD)\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n companion object {\n /** can't seem to make these private or inlined without causing compiler issues */\n @JvmField val _invMemo = HashMap()\n fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }\n }\n\n // normalizes an integer that's within range [-MOD, MOD) without branching\n private inline fun normalize(int: Int) = ModInt((int shr Int.SIZE_BITS - 1 and MOD) + int)\n\n operator fun plus(other: ModInt) = normalize(int + other.int - MOD) // overflow-safe even if MOD >= 2^30\n inline operator fun plus(other: Int) = plus(other.toModInt())\n operator fun inc() = normalize(int + (1 - MOD))\n\n operator fun minus(other: ModInt) = normalize(int - other.int)\n inline operator fun minus(other: Int) = minus(other.toModInt())\n operator fun dec() = normalize(int - 1)\n operator fun unaryMinus() = normalize(-int)\n\n operator fun times(other: ModInt) = ModInt((int.toLong() * other.int % MOD).toInt())\n inline operator fun times(other: Int) = ModInt(int.mulMod(other, MOD))\n\n fun pow(exponent: Int): ModInt {\n val e = if(exponent < 0) {\n require(int != 0) { \"Can't invert/divide by 0\" }\n exponent modulo TOTIENT\n } else exponent\n return ModInt(int.powMod(e, MOD))\n }\n\n fun pow(exponent: Long) = if(int == 0) when {\n exponent > 0 -> this\n exponent == 0L -> ModInt(1)\n else -> error(\"Can't invert/divide by 0\")\n } else pow(exponent modulo TOTIENT)\n\n inline fun inverse() = inv_memoized() /** NOTE: Change if necessary */\n\n fun inv_unmemoized(): ModInt {\n require(int != 0) { \"Can't invert/divide by 0\" }\n return pow(TOTIENT - 1)\n }\n inline fun inv_memoized() = _invMemoized(this)\n\n operator fun div(other: ModInt) = times(other.inverse())\n inline operator fun div(other: Int) = div(other.toModInt())\n\n override inline fun toString() = int.toString()\n}\n\ninline operator fun Int.plus(modInt: ModInt) = modInt + this\ninline operator fun Int.minus(modInt: ModInt) = toModInt() - modInt\ninline operator fun Int.times(modInt: ModInt) = modInt * this\ninline operator fun Int.div(modInt: ModInt) = modInt.inverse() * this\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n inline operator fun get(i: Int) = ModInt(intArray[i])\n inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override inline val size: Int get() = intArray.size\n inline val lastIndex get() = intArray.lastIndex\n inline val indices get() = intArray.indices\n\n override inline fun contains(element: ModInt): Boolean = element.int in intArray\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override inline fun isEmpty(): Boolean = intArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): ModInt = get(index++)\n }\n\n fun copyOf(newSize: Int) = ModIntArray(intArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun ModIntArray.copyInto(destination: ModIntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =\n ModIntArray(intArray.copyInto(destination.intArray, destinationOffset, startIndex, endIndex))\ninline fun ModIntArray(size: Int) = ModIntArray(IntArray(size))\ninline fun ModIntArray(size: Int, init: (Int) -> ModInt) = ModIntArray(IntArray(size) { init(it).int })\n\nfun ModInt.powArray(n: Int) = ModIntArray(int.modPowArray(n, MOD))\n\ninline fun ModIntArray.first() = get(0)\ninline fun ModIntArray.last() = get(lastIndex)\ninline fun ModIntArray.joinToString(separator: CharSequence) = intArray.joinToString(separator)\ninline fun ModIntArray.fold(init: R, op: (acc: R, ModInt) -> R) = intArray.fold(init) { acc, i -> op(acc, ModInt(i)) }\ninline fun ModIntArray.foldRight(init: R, op: (ModInt, acc: R) -> R) = intArray.foldRight(init) { i, acc -> op(ModInt(i), acc) }\nfun ModIntArray.sum() = fold(ModInt(0), ModInt::plus)\nfun ModIntArray.product() = fold(ModInt(1), ModInt::times)\n\ninline fun Iterable.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Iterable.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\ninline fun Sequence.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Sequence.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\ninline fun Array.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Array.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\nfun Iterable.sum() = sumByModInt { it }\nfun Sequence.sum() = sumByModInt { it }\nfun Iterable.product() = productByModInt { it }\nfun Sequence.product() = productByModInt { it }\nfun Collection.toModIntArray() = ModIntArray(size).also { var i = 0; for(e in this) { it[i++] = e } }\n\n/** IO */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\nconst val _BUFFER_SIZE = 1 shl 16\n@JvmField val _buffer = ByteArray(_BUFFER_SIZE)\n@JvmField var _bufferPt = 0\n@JvmField var _bytesRead = 0\n\ntailrec fun readChar(): Char {\n if(_bufferPt == _bytesRead) {\n _bufferPt = 0\n _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)\n }\n return if(_bytesRead < 0) Char.MIN_VALUE\n else {\n val c = _buffer[_bufferPt++].toChar()\n if (c == '\\r') readChar()\n else c\n }\n}\n\nfun readLine(): String? {\n var c = readChar()\n return if(c == Char.MIN_VALUE) null\n else buildString {\n while(c != '\\n' && c != Char.MIN_VALUE) {\n append(c)\n c = readChar()\n }\n }\n}\nfun readLn() = readLine()!!\n\nfun read() = buildString {\n var c = readChar()\n while(c <= ' ') {\n if(c == Char.MIN_VALUE) return@buildString\n c = readChar()\n }\n do {\n append(c)\n c = readChar()\n } while(c > ' ')\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\nfun `please stop removing these imports IntelliJ`() { iprintln(max(1, 2)) }\n\n/** additional commons */\ninline fun Iterable.sumByLong(func: (T) -> Long) = fold(0L) { acc, t -> acc + func(t) }\ninline fun Sequence.sumByLong(func: (T) -> Long) = fold(0L) { acc, t -> acc + func(t) }\ninline fun Array.sumByLong(func: (T) -> Long) = fold(0L) { acc, t -> acc + func(t) }\nfun IntArray.sumLong() = fold(0L, Long::plus)\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\n\n// ModInt\n// region\nclass ModInt(x: Long) {\n\n companion object {\n const val MOD = 1000000007L\n //const val MOD = 998244353L\n }\n\n val x = (x % MOD + MOD) % MOD\n\n operator fun plus(other: ModInt): ModInt {\n return ModInt(x + other.x)\n }\n\n operator fun minus(other: ModInt): ModInt {\n return ModInt(x - other.x)\n }\n\n operator fun times(other: ModInt): ModInt {\n return ModInt(x * other.x)\n }\n\n operator fun div(other: ModInt): ModInt {\n return this * other.inv()\n }\n\n fun pow(exp: Long): ModInt {\n if (exp == 0L) return ModInt(1L)\n var a = pow(exp shr 1)\n a *= a\n if (exp and 1L == 0L) return a\n return this * a\n }\n\n fun inv(): ModInt {\n return this.pow(MOD - 2)\n }\n\n override fun equals(other: Any?): Boolean {\n if (this === other) return true\n if (javaClass != other?.javaClass) return false\n\n other as ModInt\n\n if (x != other.x) return false\n\n return true\n }\n\n override fun hashCode(): Int {\n return x.hashCode()\n }\n\n override fun toString(): String {\n return \"$x\"\n }\n\n}\n\nval fac = mutableListOf()\nval invfac = mutableListOf()\n\nfun fact(n: Long, b: Boolean): ModInt {\n if (fac.count() == 0) {\n fac.add(ModInt(1))\n invfac.add(ModInt(1))\n }\n while (fac.count() <= n) {\n fac.add(fac.last() * ModInt(fac.count().toLong()))\n invfac.add(fac.last().inv())\n }\n return if (b) {\n fac[n.toInt()]\n } else {\n invfac[n.toInt()]\n }\n}\n\nfun comb(n: Long, k: Long): ModInt {\n return fact(n, true) * fact(k, false) * fact(n - k, false)\n}\n\nfun comb2(n: Long, k: Long): ModInt {\n var ans = ModInt(1)\n for (i in 0 until k) {\n ans = ans * ModInt(n - i) / ModInt(k - i)\n }\n return ans\n}\n// endregion\n\nfun PrintWriter.solve(sc: FastScanner) {\n val n = sc.nextLong()\n var fac = ModInt(1)\n for (i in 1..n) {\n fac *= ModInt(i)\n }\n println(fac - ModInt(2).pow(n - 1))\n}\n\nfun main() {\n val writer = PrintWriter(System.out, false)\n writer.solve(FastScanner(System.`in`))\n writer.flush()\n}\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}"}, {"source_code": "fun main() {\n val mod = 1000000007\n val n = readLine()!!.toLong()\n var yes = 0L\n var no = 2L\n for (i in 3..n) {\n yes = (i * yes + (i - 2) * no) % mod\n no = (2 * no) % mod\n }\n println(yes)\n}"}, {"source_code": "import java.util.*\nconst val MOD=1000000007\nconst val MODL=1000000007L\n\n\nfun main() {\n val n = readInt()\n var ans = 1L\n for (i in 2..n) ans=(ans*i)%MODL\n ans=(ans-mp(2L,(n-1).toLong())+MODL)%MODL\n println(ans)\n}\n\nfun gcd (a: Int,b: Int): Int = if (b==0) a else gcd(b,a%b)\nfun mp (a: Long,p: Long): Long {\n var ret=1L\n var pow=p\n var x=a\n while (pow>0) {\n if ((pow and 1)>0) ret=(ret*x)%MODL\n pow=pow.shr(1)\n x=(x*x)%MODL\n }\n return ret\n}\nfun YN(b: Boolean) : String { return if (b) \"YES\" else \"NO\" }\nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of longs\nfun readDoubles() = readStrings().map { it.toDouble() } // list of doubles"}, {"source_code": "fun modFactorial (n: Long, mod: Long) : Long {\n var result = 1L\n for (i in 1..n) result = (result * i) % mod\n return result\n}\n\nfun modExp (base: Long, exp: Long, mod: Long) : Long {\n var b = base\n var e = exp\n var result = 1L\n while (e > 0) {\n if (e % 2L == 0L) {\n b = (b * b) % mod\n e /= 2L\n } else {\n result = (result * b) % mod\n e--\n }\n }\n return result\n}\n\nfun cyclePermutations (n : Long, mod : Long) : Long {\n val r = modFactorial(n, mod) - modExp(2, n - 1, mod)\n return (r + mod) % mod\n}\n\nfun main() {\n val p = 1000000007L\n val n = readLine()!!.toLong()\n println(cyclePermutations(n, p))\n}"}, {"source_code": "fun readInt() = readLine()!!.toInt()\n\nconst val MOD: Int = 1_000_000_000 + 7\n\ninline class IntMod(private val i: Int) {\n operator fun plus(increment: IntMod): IntMod = IntMod(Math.floorMod(i + increment.i, MOD))\n operator fun plus(increment: Int): IntMod = this + increment.moduloArithmetic()\n\n operator fun minus(other: IntMod): IntMod = IntMod(Math.floorMod(i - other.i, MOD))\n operator fun minus(decrement: Int): IntMod = this - decrement.moduloArithmetic()\n\n operator fun times(other: IntMod): IntMod = IntMod(Math.floorMod(i.toLong() * other.i, MOD.toLong()).toInt())\n operator fun times(other: Int): IntMod = this * other.moduloArithmetic()\n\n operator fun div(other: IntMod): IntMod = this * other.multiplicativeInverse()\n operator fun div(other: Int): IntMod = this / other.moduloArithmetic()\n\n override fun toString(): String = i.toString()\n\n private fun multiplicativeInverse(): IntMod = pow(MOD-2)\n\n // i^n\n fun pow(n_in: Int): IntMod {\n var x = this\n var y = IntMod(1)\n var n = n_in\n // x^n\n while (n > 0) {\n if (n % 2L != 0L) y *= x\n n /= 2\n x *= x\n }\n return y\n }\n\n}\n\nfun Int.moduloArithmetic() : IntMod = IntMod(this % MOD)\n\nfun Int.factorialModulo(): IntMod {\n var res = 1.moduloArithmetic()\n for (i in 2..this) {\n res *= i\n }\n return res\n}\n\n\nfun main() {\n val n = readInt()\n\n // Compute: n! - sum_i{1,n} choose(i-1, n-1)\n // = n! - 2^{n-1}\n\n val fact = n.factorialModulo()\n val pow = 2.moduloArithmetic().pow(n-1)\n\n println(fact - pow)\n}\n"}, {"source_code": "fun readInt() = readLine()!!.toInt()\n\nconst val MOD: Int = 1_000_000_000 + 7\n\ninline class IntMod(private val i: Int) {\n operator fun plus(increment: IntMod): IntMod = IntMod(Math.floorMod(i + increment.i, MOD))\n\n operator fun minus(other: IntMod): IntMod = IntMod(Math.floorMod(i - other.i, MOD))\n\n operator fun times(other: IntMod): IntMod = IntMod(Math.floorMod(i.toLong() * other.i, MOD.toLong()).toInt())\n operator fun times(other: Int): IntMod = this * other.moduloArithmetic()\n\n override fun toString(): String = i.toString()\n}\n\nfun Int.moduloArithmetic() : IntMod = IntMod(this % MOD)\n\nfun main() {\n val n = readInt()\n\n // Compute: n! - sum_i{1,n} choose(i-1, n-1)\n // = n! - 2^{n-1}\n\n var fact = 1.moduloArithmetic()\n var pow = 1.moduloArithmetic()\n for (i in 1 until n) {\n fact *= i+1\n pow *= 2\n }\n\n println(fact - pow)\n}\n"}, {"source_code": "import java.util.*\n\nprivate inline fun debug(str: () -> Any?) = println(str().toString()) //{}\nprivate inline fun readInt() = reader.nextInt()\nprivate inline fun readLong() = reader.nextLong()\nprivate inline fun readDouble() = reader.nextDouble()\nprivate inline fun readArr() = readLine()!!.split(\" \").map { it.toInt() }\nprivate inline fun readArr(n: Int) = List(n) { reader.nextInt() }\nprivate inline fun readArrLong() = readLine()!!.split(\" \").map { it.toLong() }\nprivate inline fun readArrLong(n: Int) = List(n) { reader.nextLong() }\nprivate inline fun readArrDouble() = readLine()!!.split(\" \").map { it.toDouble() }\nprivate inline fun readArrDouble(n: Int) = List(n) { reader.nextDouble() }\nprivate inline fun readLineAsCharList() = reader.nextLine().asSequence().toList()\nprivate inline fun readAndSolve(f: () -> Unit): Unit {\n val n = readInt()\n // usually n is the only value in string\n reader.nextLine()\n repeat(n) { f() }\n}\n\nprivate fun Boolean.yn() = if (this) \"YES\" else \"NO\"\nprivate fun Iterable.out() = this.joinToString(\" \")\nprivate val reader = Scanner(System.`in`.bufferedReader()).apply { useLocale(Locale.US) }\n\n\n@ExperimentalStdlibApi\nfun main() = solve1391C()\n\n@ExperimentalStdlibApi\nprivate fun solve1391C() {\n\n val n = readInt()\n\n val mod = 1000_000_007L\n\n // ans = n! - 2^(n-1)\n\n var fact = 1L\n for (i in 2..n)\n fact = (fact * i) % mod\n\n var powtwo = 2L\n for (i in 3..n)\n powtwo = (powtwo * 2) % mod\n\n val ans = (fact + (mod - powtwo) % mod ) % mod\n\n println(ans)\n\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.*\n\nfun main(){\n\tval f = BufferedReader(InputStreamReader(System.`in`))\n\n\tval n = f.readLine().toInt()\n\n\tval MOD : Long = 1000000007L\n\n\tval fac = LongArray(1000005){0L}\n\tval pow2 = LongArray(1000005){0L}\n\tfac[0] = 1L\n\tpow2[0] = 1L\n\n\tfor(k in 1 until 1000005){\n\t\tfac[k] = (k.toLong()*fac[k-1] + MOD)%MOD\n\t\tpow2[k] = (2L*pow2[k-1] + MOD)%MOD\n\t}\n\n\tval answer = ((fac[n]-pow2[n-1] + MOD)%MOD+MOD)%MOD\n\tprintln(answer)\n}\n"}, {"source_code": "const val MOD = 1000000007L\n\nfun main() {\n val n = readLine()!!.toInt()\n var answer = 1L\n for (j in 1L..n.toLong()) {\n answer *= j\n answer %= MOD\n }\n var subtractend = 1L\n for (j in 2..n) {\n subtractend *= 2L\n subtractend %= MOD\n }\n answer -= subtractend\n answer %= MOD\n answer += MOD\n answer %= MOD\n println(answer)\n}"}, {"source_code": "import java.util.Queue\nimport java.util.LinkedList\nimport kotlin.collections.*\nimport kotlin.math.*\nimport java.util.Scanner\nimport java.lang.Math.floorMod\nimport java.lang.Math.floorDiv\nimport java.io.File\nimport kotlin.comparisons.compareBy\n\nfun readLn() = readLine()!!.trim() // string line\nfun readInt() = readLn().trim().toInt() // single int\nfun readStrings() = readLn().trim().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.trim().toInt() } // list of ints\nfun readLongs() = readStrings().map { it.trim().toLong() } // list of ints\nfun readLong() = readLn().trim().toLong() // list of strings\nfun writeGoogleAnswer(case: Int, str: String) = println(\"Case #$case: $str\")\n\ndata class Point(val x: Long, val y: Long)\n\n\n\nfun main(args: Array) {\n val mod = 1000000007L\n val n = readLong()\n var prevCnt = 4L\n var fact = 6L\n for (i in 4..n) {\n \n prevCnt = (2L*prevCnt) % mod\n fact = (fact*i) % mod\n } \n \n println(floorMod(fact - prevCnt, mod))\n\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.*\n\nfun min(a: Int, b: Int): Int {\n if (a < b) {\n return a\n } else { \n return b\n }\n}\n\nfun max(a: Int, b: Int): Int {\n if (a > b) {\n return a\n } else {\n return b\n }\n}\n\nfun main(args:Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val writer = BufferedWriter(OutputStreamWriter(System.out))\n \n val n = reader.readLine().toLong()\n val mn: Long = 1000000000 + 7\n\n var ans: Long = 1\n var minus: Long = 1\n for (i in 1..n-1) {\n\tans *= i\n\tans %= mn\n\n\tif (i.toInt() != 1) {\n\t minus *= 2\n\t minus %= mn\n\t}\n }\n\n ans = (n*ans - minus*2) % mn\n\n writer.write(\"$ans\\n\")\n \n writer.flush()\n reader.close()\n writer.close()\n}\n"}, {"source_code": "/* template start */\nimport java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.util.*\n\nprivate val br = BufferedReader(InputStreamReader(System.`in`))\nprivate var st = StringTokenizer(\"\")\n\nprivate fun readString(): String {\n while (!st.hasMoreTokens()) try {\n st = StringTokenizer(br.readLine())\n } catch (e: IOException) {\n e.printStackTrace()\n }\n return st.nextToken()\n}\n\nprivate fun readInt(): Int = readString().toInt()\nprivate fun readLong(): Long = readString().toLong()\nprivate fun readDouble(): Double = readString().toDouble()\nprivate fun readArray(n: Int) = IntArray(n) { readInt() }\nprivate fun readLongArray(n: Int) = LongArray(n) { readLong() }\nprivate fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() }\n\nprivate fun queries(block: (Int) -> Unit) = repeat(readInt(), block)\n\n/* template end */\n\nprivate val MOD = (1e9 + 7).toInt()\n\nfun main() {\n val n = readInt()\n var ans = 1L\n for (i in 2..n) {\n ans = (ans * i) % MOD\n }\n var pow = 1L\n for (i in 1..n-1)\n pow = (pow * 2L) % MOD\n\n println((ans - pow + MOD) % MOD)\n}"}], "negative_code": [{"source_code": "fun readInt() = readLine()!!.toInt()\n\nconst val MOD: Int = 1_000_000_000 + 7\n\ninline class IntMod(private val i: Int) {\n operator fun plus(increment: IntMod): IntMod = IntMod(Math.floorMod(i + increment.i, MOD))\n\n operator fun minus(other: IntMod): IntMod = IntMod(Math.floorMod(i - other.i, MOD))\n\n operator fun times(other: IntMod): IntMod = IntMod(Math.floorMod(i.toLong() * other.i, MOD.toLong()).toInt())\n operator fun times(other: Int): IntMod = this * other.moduloArithmetic()\n\n override fun toString(): String = i.toString()\n}\n\nfun Int.moduloArithmetic() : IntMod = IntMod(this % MOD)\n\nfun main() {\n val n = readInt()\n\n // Compute: n! - sum_i{1,n} choose(i-1, n-1)\n // = n! - 2^{n-1}\n\n var fact = 1.moduloArithmetic()\n var pow = 2.moduloArithmetic()\n for (i in 1 until n) {\n fact *= i+1\n pow *= 2\n }\n\n println(fact - pow)\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.*\n\nfun min(a: Int, b: Int): Int {\n if (a < b) {\n return a\n } else { \n return b\n }\n}\n\nfun max(a: Int, b: Int): Int {\n if (a > b) {\n return a\n } else {\n return b\n }\n}\n\nfun main(args:Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val writer = BufferedWriter(OutputStreamWriter(System.out))\n \n val n = reader.readLine().toLong()\n val mn: Long = 1000000000 + 7\n\n var ans: Long = 1\n var minus: Long = 1\n for (i in 1..n) {\n\tans *= i\n\tans %= mn\n\tif (i.toInt() != 1) {\n\t minus *= 2\n\t minus %= mn\n\t}\n }\n\n ans -= minus\n\n writer.write(\"$ans\\n\")\n \n writer.flush()\n reader.close()\n writer.close()\n}\n"}], "src_uid": "3dc1ee09016a25421ae371fa8005fce1"} {"nl": {"description": "There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.", "input_spec": "The first line contains integer n (1 ≤ n ≤ 50) — the number of stones on the table. The next line contains string s, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to n from left to right. Then the i-th character s equals \"R\", if the i-th stone is red, \"G\", if it's green and \"B\", if it's blue.", "output_spec": "Print a single integer — the answer to the problem.", "sample_inputs": ["3\nRRG", "5\nRRRRR", "4\nBRBG"], "sample_outputs": ["1", "4", "0"], "notes": null}, "positive_code": [{"source_code": "import kotlin.collections.*\nimport kotlin.io.*\nimport kotlin.math.*\nimport kotlin.Array\n\nclass Main{\n\n fun solve(inp : InputReader) {\n val n = inp.readlnInt()\n val a = inp.readln()\n var i = 0\n var ans = 0\n while(i < n){\n var j = i\n while(j < n && a[i] == a[j]){\n ++j\n }\n ans += j - i - 1\n i = j\n }\n print(ans)\n }\n\n class InputReader{\n public fun readln() = readLine()!!\n public fun readlnInt() = readln().toInt()\n public fun readlnLong() = readln().toLong()\n public fun readlnDouble() = readln().toDouble()\n\n public fun readlnStrings() = readln().split(\" \")\n public fun readlnInts() = readlnStrings().map{it.toInt()}\n public fun readlnLongs() = readlnStrings().map{it.toLong()}\n public fun readlnDoubles() = readlnStrings().map{it.toDouble()}\n }\n}\n\nfun main(args : Array ){\n Main().solve(Main.InputReader())\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n val stones = sc.next()\n println(removeCount(stones))\n}\n\nfun removeCount(stones: String) = (0..stones.length - 2).filter { stones[it] == stones[it+1] }.count()\n"}, {"source_code": "import java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n var stack = ' '\n val n = scanner.nextInt()\n val str = scanner.next()\n var res = 0\n (0 until n)\n .asSequence()\n .map { str[it] }\n .forEach {\n if (it == stack)\n res++\n else\n stack = it\n }\n print(res)\n}"}, {"source_code": "// kotlin oj template code from uwi(Codeforces), and convert to kotlin by lety\nimport java.io.ByteArrayInputStream\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport java.util.InputMismatchException\nimport kotlin.math.absoluteValue\n\nlateinit var `is`: InputStream\nlateinit var out: PrintWriter\nvar INPUT = \"\"\n\n//val oj = System.getProperty(\"ONLINE_JUDGE\") != null\nval oj = true\nval inbuf = ByteArray(1024)\nvar lenbuf = 0\nvar ptrbuf = 0\n\nlateinit var cum: Array\n\nfun solve()\n{\n val n = ni()\n val s = ns()\n var r = 0\n\n for(i in 1 until n)\n {\n if( s[i] == s[i-1] )\n {\n r++\n }\n }\n\n println(r)\n}\n\n\nfun main() {\n `is` = if (oj) System.`in` else ByteArrayInputStream(INPUT.toByteArray())\n out = PrintWriter(System.out)\n\n val s = System.currentTimeMillis()\n solve()\n out.flush()\n tr((System.currentTimeMillis() - s).toString() + \"ms\")\n}\n\nprivate fun readByte(): Int {\n if (lenbuf == -1) throw InputMismatchException()\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0\n try {\n lenbuf = `is`.read(inbuf)\n } catch (e: IOException) {\n throw InputMismatchException()\n }\n\n if (lenbuf <= 0) return -1\n }\n return inbuf[ptrbuf++].toInt()\n}\n\nprivate fun isSpaceChar(c: Int): Boolean = !(c >= 33 && c <= 126)\n\nprivate fun skip(): Int {\n var b: Int = readByte()\n while (b != -1 && isSpaceChar(b)) {\n b = readByte()\n }\n return b\n}\n\n// using ns()\nprivate fun nd(): Double = ns().toDouble()\n\n// using ns()\nprivate fun nc(): Char = skip().toChar()\n\n// input until whitespace\nprivate fun ns(): String {\n var b = skip()\n val sb = StringBuilder()\n while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b)\n b = readByte()\n }\n return sb.toString()\n}\n\nprivate fun ns(n: Int): CharArray {\n val buf = CharArray(n)\n var b = skip()\n var p = 0\n while (p < n && !isSpaceChar(b)) {\n buf[p++] = b.toChar()\n b = readByte()\n }\n return if (n == p) buf else Arrays.copyOf(buf, p)\n}\n\n// matrix\nprivate fun nm(n: Int, m: Int): Array {\n val map = Array(n) { CharArray(m) }\n for (i in 0 until n) map[i] = ns(m)\n return map\n}\n\nprivate fun pm(matrix: Array) {\n val n = matrix.size\n val m = matrix[0].size\n repeat(n)\n {\n repeat(m)\n { jt ->\n out.print(matrix[it][jt])\n }\n out.println()\n }\n out.flush()\n}\n\n// int array\nprivate fun na(n: Int): IntArray {\n val a = IntArray(n)\n for (i in 0 until n) a[i] = ni()\n return a\n}\n\nprivate fun ni(): Int {\n var num = 0\n var b: Int = readByte()\n var minus = false\n while (b != -1 && !(b >= '0'.toInt() && b <= '9'.toInt() || b == '-'.toInt())) {\n b = readByte()\n }\n if (b == '-'.toInt()) {\n minus = true\n b = readByte()\n }\n\n while (true) {\n if (b >= '0'.toInt() && b <= '9'.toInt()) {\n num = num * 10 + (b - '0'.toInt())\n } else {\n return if (minus) -num else num\n }\n b = readByte()\n }\n}\n\nprivate fun nl(): Long {\n var num: Long = 0\n var b: Int = readByte()\n var minus = false\n while (b != -1 && !(b >= '0'.toInt() && b <= '9'.toInt() || b == '-'.toInt())) {\n b = readByte()\n }\n if (b == '-'.toInt()) {\n minus = true\n b = readByte()\n }\n\n while (true) {\n if (b >= '0'.toInt() && b <= '9'.toInt()) {\n num = num * 10 + (b - '0'.toInt())\n } else {\n return if (minus) -num else num\n }\n b = readByte()\n }\n}\n\nprivate fun tr(vararg o: Any) {\n// if (!oj) println(Arrays.deepToString(o))\n}\n\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n var scan = Scanner(System.`in`)\n\n var cnt = scan.nextLine()\n var colors = scan.nextLine()\n\n var remove = 0\n var before = colors[0]\n for(i in 1 until colors.length) {\n if(before == colors[i]) {\n remove++\n } else {\n before = colors[i]\n }\n }\n\n println(remove)\n}"}, {"source_code": "fun main() {\n val stonesLength = readLine()!!.toInt()\n val stones = readLine()!!\n if (stonesLength == 1) {\n println(\"0\")\n return\n }\n var countOfStonesTaken = 0\n for (i in 1 until stonesLength) {\n if (stones[i] == stones[i - 1]) countOfStonesTaken++\n }\n println(countOfStonesTaken)\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n var tok = StringTokenizer(\"\")\n\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n fun files(inputFilename: String, outputFilename: String) = ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))\n }\n\n fun readToken(): String {\n while (!tok.hasMoreTokens()) {\n tok = StringTokenizer(rd.readLine())\n }\n return tok.nextToken()\n }\n\n fun readInt(): Int = readToken().toInt()\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun close() {\n rd.close()\n wr.close()\n }\n}\n\nfun solve() {\n val io = ProblemIO.console()\n val n = io.readInt()\n val t = io.readToken()\n var res = 0\n var prev = '?'\n for (ch in t) {\n if (ch == prev) {\n res += 1\n } else {\n prev = ch\n }\n }\n io.println(res)\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n"}, {"source_code": "import java.io.*\n\n/**
**/\n\nfun isDebug(): Boolean {\n return !System.getProperty(\"ONLINE_JUDGE\", \"False\")!!.toBoolean()\n}\n\nval input = if (isDebug())\n BufferedReader(FileReader(File(\"input.txt\")))\nelse\n BufferedReader(InputStreamReader(System.`in`))\n\n/**
**/\n\n/** **/\n\nfun lineToInt(): Int {\n return input.readLine().toInt()\n}\n\nfun readLine(): String {\n return input.readLine()\n}\n\n/** **/\n\nfun main(args: Array) {\n\n val n = lineToInt()\n val s = readLine().split(\"\")\n\n print(s.size - s.filterIndexed { i, el -> (i == 0) || (s[i - 1] != s[i]) }.size)\n\n}\n\n"}, {"source_code": "fun main()\n{\n val lens = readLine()!!.toInt()\n val word = readLine()!!\n var need = 0\n for(i in 1 until lens)\n {\n if (word[i] == word[i - 1]) need ++\n\n }\n println(need)\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val len = r.readLine()!!.toInt()\n val str = r.readLine()!!\n val x = (1..len-1).fold(0){acc, i -> acc + if (str[i]==str[i-1]) 1 else 0 }\n println(x)\n}"}, {"source_code": "fun main(args: Array) {\n val N = readLine()!!.toInt()\n val C = readLine()!!\n var c = 0\n for (i in 1..C.length -1) {\n if (C[i] == C[i-1]){\n c++\n }\n }\n print(c)\n}"}, {"source_code": "fun main(args: Array) {\n var c = 0\n val n = readLine()!!.toInt()\n val a = readLine()!!.split(\"\")\n for (i in 0 until n) {\n if (a[i] == a[i + 1])\n c++\n }\n print(c)\n}"}, {"source_code": "fun main(args: Array) {\n // Omit first line\n readLine()\n \n val stones = readLine()!!\n var subs = 0\n for (i: Int in (1 until stones.length)) {\n if (stones[i] == stones[i-1]) subs ++\n }\n println(subs)\n}"}, {"source_code": "\nfun main(args: Array){\n val length = readLine()?.toInt()\n val input = readLine()\n\n var result : Int = 0\n\n fun check(index: Int , c : Char){\n if (index <= length!!-2 && c == input?.get(index+1)){\n result++\n }\n }\n\n input?.forEachIndexed { index, c -> check(index , c) }\n println(result)\n\n}\n"}, {"source_code": "import java.util.*\nimport java.util.regex.Pattern\n\nfun main(args: Array) {\n\n var len = readLine()!!\n var text = readLine()!!\n var count = 0\n if (Pattern.matches(\"[A-Z]+\", text))\n {\n for (i in 0..(len.toInt() - 1))\n {\n if (i==(len.toInt() - 1))\n break\n if (text[i] == text[i + 1])\n {\n count++\n }\n\n }\n\n print(count)\n\n }\n\n\n}"}, {"source_code": "fun main() {\n var result = 0\n val count = readLine()!!.toInt()\n val input = readLine()!!.split(\"\")\n\n for (i in 0 until count) {\n val nextStone = input.getOrNull(i + 1)\n val currentStone = input[i]\n\n if ((nextStone != null) and (currentStone == nextStone)) {\n result += 1\n }\n }\n\n print(result)\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n readLn()\n println(readLn().zipWithNext().count { (a, b) -> a == b })\n}\n"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.pow\nimport kotlin.math.sqrt\n\n//private val INPUT = File(\"input.txt\").inputStream()\n//private val OUTPUT = File(\"output.txt\").outputStream()\nprivate val INPUT = System.`in`\nprivate val OUTPUT = System.out\n\nprivate val bufferedReader = INPUT.bufferedReader()\nprivate val outputWriter = PrintWriter(OUTPUT, false)\nprivate fun readLn() = bufferedReader.readLine()!!\n\nprivate fun readList() = readLn().split(' ')\nprivate var tokenizer = StringTokenizer(\"\")\nprivate fun read(): String {\n while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(readLn(), \" \")\n return tokenizer.nextToken()\n}\n\nprivate fun readInt() = read().toInt()\nprivate fun readLong() = read().toLong()\nprivate fun readDouble() = read().toDouble()\n\nprivate fun readIntList() = readList().map { it.toInt() }\nprivate fun readLongList() = readList().map { it.toLong() }\nprivate fun readDoubleList() = readList().map { it.toDouble() }\n\nprivate fun readIntArray(n: Int = 0) =\n if (n == 0) readList().run { IntArray(size) { get(it).toInt() } } else IntArray(n) { readInt() }\n\nprivate fun readLongArray(n: Int = 0) =\n if (n == 0) readList().run { LongArray(size) { get(it).toLong() } } else LongArray(n) { readLong() }\n\nprivate fun readDoubleArray(n: Int = 0) =\n if (n == 0) readList().run { DoubleArray(size) { get(it).toDouble() } } else DoubleArray(n) { readDouble() }\n\n\nprivate fun Int.modPositive(other: Int): Int = if (this % other < 0) ((this % other) + other) else (this % other)\n\n\nprivate class `CF266-D2-A` {\n fun solveTestCase(): Int {\n val n = readInt()\n val s = read()\n\n var prev = s[0]\n var count = 0\n for (i in 1 until n) {\n if (s[i] == prev) count++\n else prev = s[i]\n }\n\n return count\n }\n}\n\nfun main(args: Array) {\n\n outputWriter.println(\n `CF266-D2-A`()\n .solveTestCase()\n )\n\n outputWriter.flush()\n}"}, {"source_code": "fun main(args: Array) {\n readLine()\n var answer = 0\n val input: String = readLine()!!\n var currentChar = input.first()\n input.forEachIndexed { index, char ->\n if (index > 0) {\n if (char.equals(currentChar)) {\n answer += 1\n }\n }\n currentChar = char\n }\n println(answer)\n}"}, {"source_code": "fun String.countIndexed(predicate: (index: Int, ch: Char) -> Boolean): Int {\n var count = 0\n forEachIndexed { index, ch -> if (predicate(index, ch)) count++ }\n return count\n}\n\nfun main() = Pair(readLine()!!, readLine()!!)\n .let { (_, stones) ->\n stones.countIndexed { index, ch -> ch == stones.getOrNull(index - 1) }\n }\n .run(::println)"}, {"source_code": "fun main(args: Array) {\n val t = readInt()\n val str = readLine()!!\n var counter = 0\n var prev = str[0]\n str.substring(1).forEach { c ->\n if (prev == c) counter++\n prev = c\n }\n println(counter)\n}\n\nprivate fun readInt() = readLine()!!.toInt()\n"}, {"source_code": "\n fun main(args: Array) {\n var count = readLine()!!.toInt()\n var num = 0\n var input = readLine()!!\n for (i in 1 until input.length){\n if (input[i-1] == input[i]) ++num\n }\n println(num)\n }\n"}, {"source_code": "import java.util.Scanner;\nimport java.util.Arrays;\nimport java.util.*; \nimport java.math.*;\nimport java.io.*;\n\nfun main(args: Array) {\n var s = Scanner(System.`in`)\n var numberofstones= s.nextInt()\n neighboring(numberofstones,s)\n \n}\n\nfun neighboring( numberofstones:Int , s:Scanner){\n var colors = s.next()\n var color = colors.toCharArray() \n var number = 0\n for(i in color.indices){\n if(i!=numberofstones-1){\n \n if(color[i]==color[i+1]){\n number++\n \n }\n \n }\n\n \n}\nprint(number)\n}"}, {"source_code": "import java.util.Scanner;\nimport java.util.Arrays;\nfun main(args: Array) {\nval s = Scanner (System.`in`);\nval a : Int = s.nextInt();\nval b : String = s.next();\nval c = b.toCharArray();\nvar d = 0 ;\nfor(i in 0 until a){\nif(i < a-1){\n if ( c[i] == c[i+1]){\n d++\n \n }\n }\n }\n println(d);\n}\n \n "}, {"source_code": "\n\nimport java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(args: Array) {\n val reader = Reader()\n reader.nextInt()\n val string = reader.next()\n var lastCharacter = ' '\n var count = 0\n for (i in 0 until string.length) {\n val char = string.elementAt(i)\n if (char.equals(lastCharacter))\n count++\n lastCharacter = char\n }\n println(count)\n\n}\n\ninternal class Reader {\n var br: BufferedReader\n var st: StringTokenizer? = null\n\n init {\n br = BufferedReader(InputStreamReader(System.`in`))\n }\n\n operator fun next(): String {\n while (st == null || !st!!.hasMoreElements()) {\n try {\n st = StringTokenizer(br.readLine())\n } catch (e: IOException) {\n e.printStackTrace()\n }\n\n }\n return st!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLine(): String {\n var str = \"\"\n try {\n str = br.readLine()\n } catch (e: IOException) {\n e.printStackTrace()\n }\n\n return str\n }\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val input = InputReader(inputStream)\n val output = PrintWriter(outputStream)\n val solver = Task()\n solver.solve(input, output)\n output.close()\n}\n\nprivate class Task {\n fun solve(input: InputReader, output: PrintWriter) {\n input.next()\n val str = input.next()\n\n if (str.length == 1) {\n output.print(0)\n return\n }\n\n var top = str.first()\n var result = 0\n\n for (index in 1 until str.length) {\n if (top != str[index]) {\n top = str[index]\n } else {\n result++\n }\n }\n\n output.print(result)\n }\n}\n\n\nprivate class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n\n operator fun next(): String {\n while (tokenizer == null || tokenizer?.hasMoreTokens()?.not() == true) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n}"}, {"source_code": "/* http://codeforces.com/problemset/problem/266/A */\n\nfun main() {\n readLine() // skip first line\n var removeCount = 0\n val string = readLine()!!\n var lastChar = string[0]\n for (i in 1 until string.length) {\n if (lastChar == string[i]) {\n removeCount++\n }\n lastChar = string[i]\n }\n println(removeCount)\n}"}, {"source_code": "import java.lang.StringBuilder\n\nfun main(){\n var num = readLine()\n var stones = StringBuilder(readLine())\n println(answer(stones))\n}\n\nfun answer (stones:StringBuilder):Int{\n var num = 0\n for(i in 1 until stones.length){\n if(stones.get(i) == stones.get(i-1))\n num++\n }\n return num\n}\n\n"}, {"source_code": "fun main(args: Array)\n{\n val n = readLine()!!.toInt()\n var s = readLine()!!\n var result: Int = 0\n for (i in 1..s.length - 1)\n {\n if (s[i] == s[i - 1]) ++result\n }\n println(result)\n}"}, {"source_code": "fun main(args: Array) {\n var count=0\n var n = readLine()!!.toInt()\n var C = readLine()!!\n for (i in 1..C.length -1) {\n if (C[i] == C[i-1]){\n count++\n }\n }\n print(count)\n }"}, {"source_code": "fun main(args: Array) {\n var count=0\n var n = readLine()!!.toInt()\n var C = readLine()!!\n for (i in 1..C.length -1) {\n if (C[i] == C[i-1]){\n count+=1\n }\n }\n print(count)\n }"}, {"source_code": "import java.util.*\n\n\n\n fun main(args: Array)\n {\n val `in` = Scanner(System.`in`)\n val n = `in`.nextInt()\n val arr: CharArray\n `in`.nextLine()\n val str = `in`.nextLine()\n arr = str.toCharArray()\n val s = Stack()\n var count = 0\n for (i in arr.indices)\n {\n if (s.isEmpty())\n {\n s.push(arr[i])\n }\n else\n {\n if (s.peek() == arr[i])\n {\n if (!s.isEmpty())\n {\n count++\n }\n else\n {\n count++\n }\n }\n else\n {\n s.push(arr[i])\n }\n }\n }\n println(count)\n }\n"}, {"source_code": "fun main() {\n\n val count = readLine()\n\n val colors = readLine().toString()\n\n var haveToMove = 0\n colors.toCharArray().apply {\n forEachIndexed { index, c ->\n\n if (index != size - 1) {\n\n if (c == this[index + 1]) {\n haveToMove++\n }\n\n }\n }\n }\n\n println(haveToMove)\n\n}\n\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val s: Scanner = Scanner(System.`in`)\n val n: Int = s.nextInt()\n val str: String = s.next()\n var prevC: Char = ' '\n var result: Int = 0\n for (c in str) {\n if (c == prevC) {\n result++\n }\n prevC = c\n }\n println(result)\n}"}, {"source_code": "fun main(args: Array) {\n\n readLine()!!.toInt()\n val rgb: CharArray = readLine()!!.toCharArray()\n print((1 until rgb.size)\n .count { rgb[it] == rgb[it - 1] })\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.FileInputStream\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n reader.use {\n var el = it.readLine()\n el = it.readLine()\n var last:Char? = null\n var count = 0\n for (ch in el) {\n if(last == ch ){\n count++\n }\n last = ch\n }\n print(count)\n }\n}"}, {"source_code": "fun main(args: Array) {\n val n= readLine()!!.toInt()\n val stones= readLine()!!.toString()\n var count=1\n var j=1\n val size=n-1\n for (i in 0 until size)\n {\n\n if (stones[i]==stones[j])\n {\n count++\n }\n j++\n }\n print(count-1)\n}"}, {"source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n Scanner(System.`in`).use {\n val length = it.nextInt()\n val colorSequence = it.next()\n\n var twoConsecutiveColorCount = 0\n var previousColor = colorSequence[0]\n for (i in 1 until length) {\n val currentColor = colorSequence[i]\n if (currentColor != previousColor) {\n previousColor = currentColor\n continue\n }\n ++twoConsecutiveColorCount\n }\n println(twoConsecutiveColorCount)\n }\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n\n var count = 0\n for (i in 1 until n) {\n if (s[i - 1] == s[i]) {\n count++\n }\n }\n println(count)\n}"}, {"source_code": "// codeforces problem 266 A\n\nfun main() {\n readLine()!!\n println(readLine()!!.zipWithNext().count { (a, b) -> a == b })\n}\n"}, {"source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n var str = readLine()!!.toString()\n var count = 0\n for (i in 0 until str.length-1){\n if (str[i]==str[i+1]){\n count++\n }\n }\n println(count)\n}"}, {"source_code": "fun main(args : Array) {\n val n = readLine()!!.toInt()\n val line = readLine()!!\n var ans = 0\n var c = 0\n for (i in 1..(n-1)) {\n if (line[i] == line[i-1])\n c++\n else{\n ans += c\n c = 0\n }\n }\n ans += c\n println(ans)\n}"}, {"source_code": "\nimport java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n scanner.nextLine()\n val stones = scanner.nextLine()\n\n var result = 0\n var stoneIndex = 0\n while(stoneIndex < stones.length - 1) {\n if(stones[stoneIndex ] == stones[stoneIndex+1]) {\n result++\n }\n stoneIndex++\n }\n\n println(result)\n}"}, {"source_code": "// https://codeforces.com/problemset/problem/266/A\n\nfun main(args: Array) {\n val n = readInt()\n val data = readLn()\n var actualCharacter: Char = '0'\n var numberToDelete = 0;\n for (character in data) {\n if (actualCharacter == '0') {\n actualCharacter = character;\n } else {\n if (actualCharacter == character) {\n numberToDelete++\n } else {\n actualCharacter = character\n }\n }\n }\n print(numberToDelete)\n}\n\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings(del: String = \" \") = readLn().split(del) // list of strings\nprivate fun readInts(del: String = \" \") = readStrings(del).map { it.toInt() } // list of ints\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val n = scan.nextInt()\n val str = scan.next()\n\n var prev = str.first()\n var ans = 0\n\n for(i in 1 until str.length) {\n if(str[i] == prev) {\n ans++\n }\n prev = str[i]\n }\n println(ans)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.lang.StringBuilder\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val n = br.readLine()\n val s = br.readLine()\n val contigs = s.fold(ArrayList()){\n acc, c -> acc.apply {\n if (isEmpty() || last().last() != c){\n add(StringBuilder(c.toString()))\n } else {\n last().append(c)\n }\n }\n }\n println(\n contigs.fold(0){\n acc, block -> acc + block.length - 1\n }\n )\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val reader = Scanner(System.`in`)\n val n = reader.nextInt()\n reader.nextLine()\n val word = reader.nextLine()\n var m = 0\n var init = word[0]\n for (i in 1 until word.length){\n if (init == word[i]) {\n m++\n }\n init = word[i]\n }\n\n println(m)\n}"}, {"source_code": "//package problem266A\n\nfun containsDuplicateNeighbors(stones: List): Boolean {\n for (i in 0 until stones.size - 1) {\n if (stones[i] == stones[i + 1]) {\n return true\n }\n }\n\n return false\n}\n\nfun removeDuplicateNeighbors(stones: MutableList): Int {\n var numRemoved = 0\n for (i in stones.size - 1 downTo 1) {\n if (stones[i] == stones[i - 1]) {\n stones.removeAt(i)\n ++numRemoved\n }\n }\n return numRemoved\n}\n\nfun main() {\n readLine()!!\n val stones = readLine()!!.toMutableList()\n var numRemoved = 0\n\n while (containsDuplicateNeighbors(stones)) {\n numRemoved += removeDuplicateNeighbors(stones)\n }\n\n println(numRemoved)\n}\n"}, {"source_code": "import java.lang.StringBuilder\n\nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\n\n\nfun minNumberOfStones(): Int {\n val n = readInt()\n val stonesColors = readLn()\n\n var nwDistinctStones: StringBuilder = StringBuilder()\n nwDistinctStones.append(stonesColors[0])\n\n for (i in 1 until stonesColors.length)\n if (stonesColors[i] != nwDistinctStones[nwDistinctStones.lastIndex])\n nwDistinctStones.append(stonesColors[i])\n\n return stonesColors.length - nwDistinctStones.length\n}\n\n\nfun main() {\n print(minNumberOfStones())\n}\n"}, {"source_code": "import java.util.*\n\nfun main()\n{\n var scanner = Scanner(System.`in`)\n var number = scanner.next().toInt()\n var str = scanner.next()\n var counter = 0\n for(i in 0 until str.length-1)\n {\n if(str[i] == str[i+1])\n counter++\n }\n println(counter)\n}\n"}, {"source_code": "import java.util.*\nfun main() {\n val sc = Scanner(System.`in`)\n\n var n = sc.nextInt()\n var s = sc.next()\n var k = 0\n for(i in 0 until n-1){\n if(s[i] == s[i+1]){\n k++\n }\n }\n print(k)\n}\n"}, {"source_code": "import java.util.Scanner\nimport java.util.Set\nimport java.util.LinkedHashSet\n\nimport java.util.*\nfun main() {\n val s = Scanner(System.`in`)\n val size = s.nextInt()\n var x = 0\n var str = s.next()\n val arr = str!!.toCharArray()\n for (i in 0 until size-1) {\n if (arr[i] == arr[i + 1])\n x++\n }\n print(x)\n\n}"}, {"source_code": "fun main() {\n readLine()\n var a: String = readLine()!!\n var ans: Int = 0\n for (i in 1 until a.length){\n if (a[i] == a[i - 1]){\n ++ans\n }\n }\n print(ans)\n}"}, {"source_code": "fun main(args: Array) {\n readLine()!!\n val line = readLine()!!\n println(line.fold(0 to 'X', { acc, c -> (if (c == acc.second) acc.first + 1 else acc.first) to c }).first)\n}"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array){\n val scan = Scanner(System.`in`)\n val n = scan.nextInt()\n val s = scan.next()\n var c = 0\n\n for (i in 0 until n-1){\n if (s[i] == s[i+1]) c++\n }\n println(c)\n}"}, {"source_code": "fun main() {\n readLine()\n var chars = readLine()!!.toCharArray()\n var ans = 0\n for (i in 1..chars.lastIndex) {\n if (chars[i] == chars[i - 1])\n ans++\n }\n println(ans)\n}"}, {"source_code": "fun main() {\n val n = readLine()\n val str = readLine()!!\n println(str.length -\n repl(repl(repl(str, \"RR\", \"R\"), \"GG\", \"G\"),\"BB\", \"B\")\n .length)\n}\n\nfun repl(s: String, subs: String, repl: String): String {\n var str = s\n while (str.contains(subs, true))\n str = str.replace(subs, repl, true)\n return str\n}"}, {"source_code": "import java.lang.AssertionError\nimport java.util.*\n \nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n \nprivate fun myAssert(x: Boolean) {\n if (!x) {\n throw AssertionError()\n }\n}\n\nfun main(args: Array) {\n// var s = Scanner(System.`in`)\n var n = readInt()\n var s = readLn()\n var ans = 0\n for (i in 1 until s.length) {\n if (s[i - 1] == s[i])\n ans++\n }\n println(ans)\n}\n"}, {"source_code": "\nfun main()\n {\n val s:String\n var count :Int=0\n var n:Int\n n= readLine()!!.toInt()\n s= readLine()!!.toString()\n for(i in s.indices)\n {\n if(i) {\n readLine()!!.toInt()\n val stones = readLine()!!.toCharArray()\n println((1 until stones.size).count{stones[it] == stones[it - 1]})\n}"}, {"source_code": "fun main(){\n val n = readLine()!!.toInt()\n val s = readLine()!!\n var count = 0\n for (i in 0..n-2){\n if (s[i].compareTo(s[i+1]) == 0) count++\n }\n println(count)\n}"}, {"source_code": "import java.lang.StringBuilder\n\nfun main() {\n\n solve266A()\n\n}\n\nfun solve266A() {\n\n val countString = readLine()\n\n val inputValue = readLine()\n\n var count = 0\n\n if (inputValue == null) {\n return\n }\n\n val result: StringBuilder = StringBuilder()\n\n inputValue.forEach {\n if (result.length == 0 || result.last() != it) {\n result.append(it)\n }\n }\n\n println(inputValue.length - result.length)\n\n}"}, {"source_code": "import java.util.Scanner\n\nfun main(args:Array){\n val input = Scanner(System.`in`)\n var n = input.nextInt()\n var str = input.next()\n var count = 0\n\n for(i in 0 until n-1){\n if(str[i] == str[i+1]){\n count += 1\n }\n }\n print(count)\n}"}, {"source_code": "fun main() {\n val c = readLine()!!\n val s = readLine()!!\n\n var p = s[0]\n var r = -1\n s.forEach {\n if(it.equals(p)) {\n r++\n }\n p = it\n }\n println(r)\n }"}, {"source_code": "fun main(){\n var n = readLine()!!.toInt();\n var a = readLine()!!.toString();\n var tot=0;\n for(i in 1..(n-1)) if(a[i]==a[i-1]) tot+=1;\n println(tot);\n}\n"}, {"source_code": "fun main(args: Array) {\n val quantity = Integer.parseInt(readLine())\n val colors = readLine()\n print(findColor(colors, quantity))\n}\n\nfun findColor(colors : String?, quantity : Int) : Int {\n var find = 0\n for(i in 1 until quantity){\n if(colors!![i].equals(colors[i-1])) find++\n }\n return find\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n val n: Int = scanner.nextInt()\n val str: String = scanner.next()\n\n var last = str[0]; var cnt = 0\n for(i in 1 until n){\n cnt += if(last == str[i]) 1 else 0\n last = str[i]\n }\n\n print(cnt)\n}"}, {"source_code": "import java.util.*\n\nprivate val scan = Scanner(System.`in`)\n\nfun main(args: Array) {\n scan.nextInt()\n val s = scan.next()\n val set = mutableListOf()\n var ans = 0\n\n s.forEach { if (it != set.lastOrNull()) set.add(it) else ans++ }\n\n println(ans)\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n reader.readLine()!!\n val array = reader.readLine().toCharArray()\n var count = 0\n var buffer: Char = array.first()\n val iterator = array.iterator()\n iterator.nextChar()\n while (iterator.hasNext()) {\n val char = iterator.nextChar()\n if (char == buffer) {\n count++\n } else {\n buffer = char\n }\n }\n println(count)\n}"}, {"source_code": "fun main() {\n readLine()!!\n var count = 0\n readLine()!!.toCharArray().let {\n var cur = it[0]\n for((i, c) in it.withIndex()) {\n if(i == 0) {\n continue\n }\n if(c == cur)\n count++\n else\n cur = c\n }\n }\n println(count)\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n val filtered = s.filterIndexed { index, c ->\n when (index) {\n 0 -> true\n else -> c != s[(index + n - 1) % n]\n }\n }\n println(s.length - filtered.length)\n}\n"}, {"source_code": "fun main() {\n val numOfcolors = readLine()\n val colors = readLine()\n var toRemove = 0\n for(i in 0 until (colors?.length!!-1)!!){\n if(colors.get(i) == colors.get(i+1)){\n toRemove+=1\n }\n }\n println(toRemove)\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n var ans: Int = 0\n for (i in 1..n-1) {\n if (s[i] == s[i-1])\n ans++\n }\n print(ans.toString() + \"\\n\")\n}\n"}, {"source_code": "fun main(args: Array) {\n readLine()\n println(\n Regex(\"R{2,}|G{2,}|B{2,}\").findAll(readLine()!!)\n .sumBy { it.value.length - 1 }\n )\n}\n"}, {"source_code": "fun main() {\n\n val n = readLine()!!.toInt()\n val row = readLine()!!\n var count = 0\n\n row.forEachIndexed{ index, _ ->\n if(index != row.lastIndex)\n if(row[index] == row[index+1])\n count++\n }\n\n print(count)\n}\n\n\n"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n\nfun main() {\n readLn()\n val balls = readLn()\n\n if (balls.length <= 1) {\n println(0)\n return\n }\n\n var res = 0\n balls.reduce { a, b -> if (a == b) ++res; b }\n\n println(res)\n}\n"}, {"source_code": "import Output.print\nimport Output.println\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\nimport kotlin.math.abs\n\nobject Input {\n\n private val input = BufferedReader(InputStreamReader(System.`in`))\n private lateinit var tokenizer: StringTokenizer\n\n val next: String get() = input.readLine()\n val intValue get() = next.toInt()\n val longValue get() = next.toLong()\n val floatValue get() = next.toFloat()\n val doubleValue get() = next.toDouble()\n\n val intList get()= valuesList { it.toInt() }\n val longList: List get() = valuesList { it.toLong() }\n val floatList: List get() = valuesList { it.toFloat() }\n val doubleList: List get() = valuesList { it.toDouble() }\n\n private inline fun valuesList(f: (String) -> T): List = mutableListOf().apply {\n tokenizer = StringTokenizer(input.readLine())\n while (tokenizer.hasMoreTokens()) add(f(tokenizer.nextToken()))\n }\n\n fun close() = input.close()\n}\n\nobject Output {\n\n private val output = PrintWriter(System.out)\n\n fun Number.print() = output.print(this)\n\n fun Number.println() = output.println(this)\n\n fun String.print() = output.print(this)\n\n fun String.println() = output.println(this)\n\n fun List.print(delimiter: CharSequence = \" \") = output.print(this.joinToString(delimiter))\n\n fun List.println(delimiter: CharSequence = \" \") = output.println(this.joinToString(delimiter))\n\n fun flush() = output.flush()\n\n fun close() = output.close()\n}\n\nfun close() {\n Output.flush()\n Input.close()\n Output.close()\n}\n\nfun solve() {\n val n = Input.intValue\n val a = Input.next\n a.takeLast(n-1).filterIndexed { index, c -> a[index] == c }.length.print()\n}\n\nfun main() {\n// var tt = Input.intValue\n// while (tt-- != 0) {\n solve()\n// }\n Output.flush()\n}\n\n"}, {"source_code": "\nfun main(args: Array) {\n var counter = 0\n val stoneCount = readLine()!!.toInt()\n val stones = readLine()!!\n for (i in 1 until stoneCount) {\n if (stones[i - 1] == stones[i]) {\n counter ++\n }\n }\n\n println(counter)\n}"}, {"source_code": "import java.util.Scanner\n\nfun main(){\n var input = Scanner(System.`in`)\n var num = input.next()\n var s = input.next()\n println(checkNeighborSame(s))\n}\nfun checkNeighborSame(str : String) : Int {\n\n var res = 0;\n var charArr = str.toCharArray()\n var arr = arrayListOf()\n for (i in 0..charArr.size-1){\n arr.add(charArr.get(i))\n }\n var i = 0\n while (i < arr.size-1){\n if(arr.get(i) == arr.get(i+1)) {\n arr.removeAt(i+1)\n res++\n }else\n i++\n }\n return res\n\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n val c = scanner.next()\n\n var take = 0\n for (i in 0 until n - 1) {\n if (c[i] == c[i + 1]) {\n take += 1\n }\n }\n\n println(take)\n}"}, {"source_code": "fun main() {\n val stones = readLine()!!.toInt()\n val data = readLine()!!.map { it.toString() }\n\n val clean = data.reduce { acc, s ->\n if (acc.last().toString() == s) acc else acc + s\n }\n println(stones - clean.length)\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n var stones = readLine()!!.toCharArray()\n var tbr = 0\n var latest = stones[0]\n for (i in 0 until n - 1) {\n if (latest == stones[i + 1]) {\n tbr++\n stones[i + 1] = ' '\n }\n else {\n latest = stones[i + 1]\n }\n }\n print(tbr)\n}\n"}], "negative_code": [{"source_code": "fun main() {\n val stonesLength = readLine()!!.toInt()\n val stones = readLine()!!\n if (stones.length == 1) {\n println(\"0\")\n return\n }\n var countOfStonesTaken = 0\n var compareIndex = 0\n var currentIndex = 1\n while (currentIndex < stonesLength) {\n if (stones[compareIndex] == stones[currentIndex]) {\n countOfStonesTaken++\n } else compareIndex++\n currentIndex++\n }\n println(countOfStonesTaken)\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n println(readLn().zipWithNext().count { (a, b) -> a == b })\n}\n"}, {"source_code": "import java.util.Scanner\nimport java.util.Set\nimport java.util.LinkedHashSet\n\nimport java.util.*\nfun main() {\n val s = Scanner(System.`in`)\n val size = s.nextInt()\n var x = 0\n var userInput = readLine()\n var str = \"$userInput\".take(size)\n val arr = str.toCharArray()\n for (i in 0 until size) {\n if (i == size - 1) break\n if (arr[i] == arr[i + 1])\n x++\n }\n print(x)\n\n}"}, {"source_code": "fun main() {\n var a: String = readLine()!!\n var ans: Int = 0\n for (i in 1 until a.length){\n if (a[i] == a[i - 1]){\n ++ans\n }\n }\n print(ans)\n}"}, {"source_code": "fun main() {\n val c = readLine()!!\n val s = readLine()!!\n \n var p = s[0]\n var r = 0\n s.forEach { \n if(it.equals(p)) {\n r++\n }\n p = it\n }\n println(r)\n }"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n reader.readLine()!!\n val array = reader.readLine().toCharArray()\n var count = 0\n var buffer: Char? = null\n for (char in array) {\n if (buffer == null) {\n buffer = char\n } else if (buffer == char) {\n count++\n } else if (buffer != char) {\n buffer = null\n }\n }\n println(count)\n}"}, {"source_code": "import kotlin.math.max\n\nfun main() {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n val filtered = s.filterIndexed { index, c ->\n c != s[(index + n - 1) % n]\n }\n println(s.length - max(filtered.length, 1))\n}\n"}], "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8"} {"nl": {"description": "In Omkar's last class of math, he learned about the least common multiple, or $$$LCM$$$. $$$LCM(a, b)$$$ is the smallest positive integer $$$x$$$ which is divisible by both $$$a$$$ and $$$b$$$.Omkar, having a laudably curious mind, immediately thought of a problem involving the $$$LCM$$$ operation: given an integer $$$n$$$, find positive integers $$$a$$$ and $$$b$$$ such that $$$a + b = n$$$ and $$$LCM(a, b)$$$ is the minimum value possible.Can you help Omkar solve his ludicrously challenging math problem?", "input_spec": "Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\leq t \\leq 10$$$). Description of the test cases follows. Each test case consists of a single integer $$$n$$$ ($$$2 \\leq n \\leq 10^{9}$$$).", "output_spec": "For each test case, output two positive integers $$$a$$$ and $$$b$$$, such that $$$a + b = n$$$ and $$$LCM(a, b)$$$ is the minimum possible.", "sample_inputs": ["3\n4\n6\n9"], "sample_outputs": ["2 2\n3 3\n3 6"], "notes": "NoteFor the first test case, the numbers we can choose are $$$1, 3$$$ or $$$2, 2$$$. $$$LCM(1, 3) = 3$$$ and $$$LCM(2, 2) = 2$$$, so we output $$$2 \\ 2$$$.For the second test case, the numbers we can choose are $$$1, 5$$$, $$$2, 4$$$, or $$$3, 3$$$. $$$LCM(1, 5) = 5$$$, $$$LCM(2, 4) = 4$$$, and $$$LCM(3, 3) = 3$$$, so we output $$$3 \\ 3$$$.For the third test case, $$$LCM(3, 6) = 6$$$. It can be shown that there are no other pairs of numbers which sum to $$$9$$$ that have a lower $$$LCM$$$."}, "positive_code": [{"source_code": "fun main() {\n for (c in 1..readLine()!!.toInt()) {\n val n = readLine()!!.toInt()\n var p = 0\n for (m in 2..100000) {\n if (n % m == 0) {\n p = m\n break\n }\n }\n if (p == 0) {\n p = n\n }\n println(\"${n / p} ${n - (n / p)}\")\n }\n}"}, {"source_code": "fun main() {\n for (c in 1..readLine()!!.toInt()) {\n val n = readLine()!!.toInt()\n var p = 0\n for (m in 2..100000) {\n if (n % m == 0) {\n p = m\n break\n }\n }\n if (p == 0) {\n p = n\n }\n println(\"${n / p} ${n - (n / p)}\")\n }\n}"}, {"source_code": "import kotlin.math.sqrt\n\nfun main() {\n\n repeat(readLine()!!.toInt()) {\n val num = readLine()!!.toInt()\n val leastPrime = leastPrime(num)\n println(\"${num / leastPrime} ${num / leastPrime * (leastPrime - 1)}\")\n }\n}\n\nfun leastPrime(n: Int): Int {\n var num = 2\n if (n % 2 == 0)\n return 2\n num += 1\n while (n % num != 0 && num < sqrt(n.toDouble())) {\n num += 2\n }\n if (num > sqrt(n.toDouble()))\n return n\n return num\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.*\nimport kotlin.math.*\n\nfun readInts() = readLine()!!.split(\" \").map{i -> i.toInt()}.toMutableList()\nfun readInt() = readLine()!!.toInt()\nfun readLongs() = readLine()!!.split(\" \").map{i -> i.toLong()}.toMutableList()\n\nfun main() {\n val t = readInt()\n repeat(t) {\n val n = readInt()\n var a = 0\n for(i in 2..sqrt(n.toDouble()).toInt()) {\n if (n % i == 0) {\n a = n / i\n break\n }\n }\n println(if(a == 0) \"1 ${n - 1}\" else \"$a ${n - a}\")\n }\n}"}, {"source_code": "import java.lang.Math.*\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readLong() = readLn().toLong()\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of ints\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\n\n//var n = 0\n//var ar = listOf()\nval visited = mutableSetOf()\nval graph = mutableMapOf>()\n\nfun main() {\n val t = readInt()\n for (cases in 0 until t) {\n solve()\n }\n\n// solve()\n}\n\nfun solve() {\n val n = readInt()\n\n var ans1 = 1\n var ans2 = n - 1\n var min = n - 1\n for (i in 2 until sqrt(n.toDouble()).toInt() + 1) {\n if (n % i == 0) {\n val d = n / i\n if ((i - 1) * d < min) {\n ans1 = d\n ans2 = (i - 1) * d\n min = ans2\n }\n\n }\n }\n\n println(\"$ans1 $ans2\")\n}\n"}, {"source_code": "fun main() {\n for (c in 1..readLine()!!.toInt()) {\n val n = readLine()!!.toInt()\n var p = 0\n for (m in 2..100000) {\n if (n % m == 0) {\n p = m\n break\n }\n }\n if (p == 0) {\n p = n\n }\n println(\"${n / p} ${n - (n / p)}\")\n }\n}"}, {"source_code": "fun main() {\n for (c in 1..readLine()!!.toInt()) {\n val n = readLine()!!.toInt()\n var p = 0\n for (m in 2..100000) {\n if (n % m == 0) {\n p = m\n break\n }\n }\n if (p == 0) {\n p = n\n }\n println(\"${n / p} ${n - (n / p)}\")\n }\n}"}, {"source_code": "fun main(args: Array) {\n var numberTests = readLine()!!.toInt()\n var results = mutableListOf()\n\n for (i in 0..numberTests-1) {\n var n = readLine()!!.toLong()\n val result = experimentB(n)\n results.add(result)\n }\n\n for (result in results) {\n println(result)\n }\n}\n\nfun experimentB(n : Long) : String {\n var result = \"\"\n\n if (n % 2 == 0L) {\n result = \"${n / 2} ${n / 2}\"\n } else {\n val divideList = divisor(n)\n// println(divideList)\n val candidate = divideList.takeLast(2) [0]\n// println (candidate)\n result = \"${candidate} ${n - candidate}\"\n }\n\n return result\n}\n\n// 約数のList\nfun divisor(value : Long) : List {\n val max = Math.sqrt(value.toDouble()).toLong()\n return (1..max)\n .filter { value % it == 0L }\n .map { listOf(it, value / it) }\n .flatten()\n .sorted()\n}"}, {"source_code": "fun main() {\n repeat(readLine()!!.toInt()) {\n val n = readLine()!!.toInt()\n var d = 2\n while (d * d <= n) {\n if (n % d == 0) break\n d++\n }\n if (n % d == 0) {\n val a = n / d\n println(\"$a ${n - a}\")\n } else {\n println(\"1 ${n - 1}\")\n }\n }\n}"}, {"source_code": " fun main() {\n for (c in 1..readLine()!!.toInt()) {\n val n = readLine()!!.toInt()\n var p = 0\n for (m in 2..100000) {\n if (n % m == 0) {\n p = m\n break\n }\n }\n if (p == 0) {\n p = n\n }\n println(\"${n / p} ${n - (n / p)}\")\n }\n }"}, {"source_code": "import kotlin.math.sqrt\n\nfun solve(n: Int) {\n var i = 2\n val limit = (sqrt(n.toDouble()) + 1).toInt()\n while (n % i != 0) {\n ++i\n if (i == limit) {\n println(\"1 ${n - 1}\")\n return@solve\n }\n }\n println(\"${n / i} ${n / i * (i - 1)}\")\n}\n\n\nfun main() {\n val t = readLine()!!.toInt()\n for (i in 1..t ) {\n solve(readLine()!!.toInt())\n }\n}"}, {"source_code": "import java.io.IOException\nimport java.io.InputStream\nimport java.util.*\n\nfun main(args : Array){\n val reader =InputReader(System.`in`)\n val t = reader.readInt()\n repeat(t){\n val n = reader.readInt()\n var found = false\n for (i in 2 until Math.sqrt(n.toDouble()).toInt() + 1) {\n if (n % i == 0) {\n val factor = n / i //greatest factor\n println(\"$factor ${n - factor}\")\n found = true\n break\n }\n }\n if (!found){\n println(\"1 ${n-1}\")\n }\n }\n}\n\n\ninternal class InputReader(private val stream: InputStream) {\n private val buf = ByteArray(1024)\n private var curChar: Int = 0\n private var numChars: Int = 0\n private val filter: SpaceCharFilter? = null\n\n fun read(): Int {\n if (numChars == -1)\n throw InputMismatchException()\n if (curChar >= numChars) {\n curChar = 0\n try {\n numChars = stream.read(buf)\n } catch (e: IOException) {\n throw InputMismatchException()\n }\n\n if (numChars <= 0)\n return -1\n }\n return buf[curChar++].toInt()\n }\n\n fun readInt(): Int {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n var sgn = 1\n if (c == '-'.toInt()) {\n sgn = -1\n c = read()\n }\n var res = 0\n do {\n if (c < '0'.toInt() || c > '9'.toInt())\n throw InputMismatchException()\n res *= 10\n res += c - '0'.toInt()\n c = read()\n } while (!isSpaceChar(c))\n return res * sgn\n }\n\n fun readString(): String {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n val res = StringBuilder()\n do {\n res.appendCodePoint(c)\n c = read()\n } while (!isSpaceChar(c))\n return res.toString()\n }\n\n fun isSpaceChar(c: Int): Boolean {\n return filter?.isSpaceChar(c)\n ?: (c == ' '.toInt() || c == '\\n'.toInt() || c == '\\r'.toInt() || c == '\\t'.toInt() || c == -1)\n }\n\n operator fun next(): String {\n return readString()\n }\n\n interface SpaceCharFilter {\n fun isSpaceChar(ch: Int): Boolean\n }\n}\n"}, {"source_code": "fun main() {\n val t = readInt()\n fun findOther(x: Int, n: Int): Int {\n val a = n/x - 1\n return a * x\n }\n\n repeat(t) {\n val n = readInt()\n if (n % 2 == 0) println(\"${n/2} ${n/2}\")\n else {\n var divisor = 1\n val candidates = mutableListOf()\n while (divisor * divisor <= n) {\n if (n % divisor == 0) {\n candidates.add(divisor)\n if (divisor != 1 && divisor * divisor != n) candidates.add(n/divisor)\n }\n\n divisor += 2\n }\n val ans = candidates.map { Pair(it, findOther(it, n)) }.minBy { it.second }!!\n println(\"${ans.first} ${ans.second}\")\n }\n }\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\n\nprivate fun readStrings() = readLn().trim().split(\" \")\nprivate fun readInt() = readLn().toInt()\nprivate fun readInts() = readStrings().map { it.toInt() }\n"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n//@file:OptIn(ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\n\nfun PrintWriter.solve() {\n //val startTime = System.nanoTime()\n\n val numCases = readInt()\n case@ for(case in 1..numCases) {\n //print(\"Case #$case: \")\n\n val n = readInt()\n\n val p = run p@ {\n n.factorize { return@p it }\n n\n }\n\n val a = n/p\n val b = n - a\n\n println(\"$a $b\")\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\ninline fun Int.factorize(yield: (Int) -> Unit) {\n var n = this\n\n for(p in 2..n) {\n if(p * p > n) break\n\n while(n % p == 0) {\n yield(p)\n n /= p\n }\n }\n\n if(n > 1) yield(n)\n}\n\n/** IO */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\nconst val _BUFFER_SIZE = 1 shl 16\n@JvmField val _buffer = ByteArray(_BUFFER_SIZE)\n@JvmField var _bufferPt = 0\n@JvmField var _bytesRead = 0\n\ntailrec fun readChar(): Char {\n if(_bufferPt == _bytesRead) {\n _bufferPt = 0\n _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)\n }\n return if(_bytesRead < 0) Char.MIN_VALUE\n else {\n val c = _buffer[_bufferPt++].toChar()\n if (c == '\\r') readChar()\n else c\n }\n}\n\nfun readLine(): String? {\n var c = readChar()\n return if(c == Char.MIN_VALUE) null\n else buildString {\n while(c != '\\n' && c != Char.MIN_VALUE) {\n append(c)\n c = readChar()\n }\n }\n}\nfun readLn() = readLine()!!\n\nfun read() = buildString {\n var c = readChar()\n while(c <= ' ') {\n if(c == Char.MIN_VALUE) return@buildString\n c = readChar()\n }\n do {\n append(c)\n c = readChar()\n } while(c > ' ')\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\nfun `please stop removing these imports IntelliJ`() { iprintln(max(1, 2)) }\n\n/** additional commons */\ninline fun Iterable.sumByLong(func: (T) -> Long) = fold(0L) { acc, t -> acc + func(t) }\ninline fun Sequence.sumByLong(func: (T) -> Long) = fold(0L) { acc, t -> acc + func(t) }\ninline fun Array.sumByLong(func: (T) -> Long) = fold(0L) { acc, t -> acc + func(t) }\nfun IntArray.sumLong() = fold(0L, Long::plus)\n"}, {"source_code": "fun main() {\n for (c in 1..readLine()!!.toInt()) {\n val n = readLine()!!.toInt()\n var p = 0\n for (m in 2..100000) {\n if (n % m == 0) {\n p = m\n break\n }\n }\n if (p == 0) {\n p = n\n }\n println(\"${n / p} ${n - (n / p)}\")\n }\n}"}, {"source_code": "fun main() {\n for (c in 1..readLine()!!.toInt()) {\n val n = readLine()!!.toInt()\n var p = 0\n for (m in 2..100000) {\n if (n % m == 0) {\n p = m\n break\n }\n }\n if (p == 0) {\n p = n\n }\n println(\"${n / p} ${n - (n / p)}\")\n }\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.util.*\n\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\n\nfun main(args: Array) {\n b()\n}\n\n\nfun divisor(n: Int): Int {\n var i = 2\n while (i * i <= n) {\n if (n % i == 0) return i\n i++\n }\n return n\n}\n\nfun a() {\n repeat(readInt()) {\n val n = readInt()\n val a = List(n) { 1 }\n println(a.joinToString(separator = \" \"))\n }\n}\n\nfun pow(a: Int, b: Int): Long {\n var res = 1L\n repeat(b) { res *= a }\n return res\n}\n\nfun adj(i: Int, j: Int, n: Int, m: Int): Int {\n var adj = 4\n if (i == 0) adj--\n if (j == 0) adj--\n if (i == n - 1) adj--\n if (j == m - 1) adj--\n return adj\n}\n\nfun activeAdj(i: Int, j: Int, n: Int, m: Int, a: Array): Int {\n var activeAdj = 0\n if (i - 1 >= 0 && a[i - 1][j] > 0) activeAdj++\n if (j - 1 >= 0 && a[i][j - 1] > 0) activeAdj++\n if (i + 1 < n && a[i + 1][j] > 0) activeAdj++\n if (j + 1 < m && a[i][j + 1] > 0) activeAdj++\n return activeAdj\n}\n\nfun b() {\n repeat(readInt()) {\n val n = readInt()\n val divisor = leastDivisor(n)\n\n if (divisor == 1) {\n println(\"1 ${n - 1}\")\n } else {\n println(\"${n / divisor} ${n - n / divisor}\")\n }\n }\n}\n\nfun c() {\n repeat(readInt()) {\n val n = readInt()\n val a = readInts()\n\n val right = mutableListOf()\n val notRight = mutableListOf()\n\n for (i in 0 until n) {\n if (a[i] == i + 1) {\n right.add(i)\n } else {\n notRight.add(i)\n }\n }\n\n if (notRight.isEmpty()) {\n println(0)\n return@repeat\n }\n\n var isSubsequent = true\n for (i in 1 until notRight.size) {\n if (notRight[i] != notRight[i - 1] + 1) {\n isSubsequent = false\n break\n }\n }\n\n if (isSubsequent) {\n println(1)\n return@repeat\n }\n\n println(2)\n }\n}\n\nfun df(a: IntArray): Pair, Triple> {\n\n var dif = 0L\n var lastIndex = 0\n var maxDif = 0L\n var maxIndex = 0\n var maxLength = 0\n for (i in 0 until a.size - 1 step 2) {\n dif += a[i + 1] - a[i]\n if (dif <= 0) {\n dif = 0\n lastIndex = i + 2\n continue\n }\n if (dif > maxDif) {\n maxDif = dif\n maxIndex = lastIndex\n maxLength = i + 2 - lastIndex\n }\n }\n\n var dif1 = 0L\n var lastIndex1 = 1\n var maxDif1 = 0L\n var maxIndex1 = 0\n var maxLength1 = 0\n for (i in 1 until a.size - 1 step 2) {\n dif1 += a[i + 1] - a[i]\n if (dif1 >= 0) {\n dif1 = 0\n lastIndex1 = i + 2\n continue\n }\n if (dif1 < maxDif1) {\n maxDif1 = dif1\n maxIndex1 = lastIndex1\n maxLength1 = i + 2 - lastIndex1\n }\n }\n\n return Pair(Triple(maxDif, maxIndex, maxLength), Triple(-maxDif1, maxIndex1, maxLength1))\n}\n\ndata class MyPair(var first: Int, var second: Int) : Comparable {\n override fun compareTo(other: MyPair): Int {\n return this.first - other.first\n }\n\n}\n\nfun d() {\n val n = readInt()\n val a = readInts()\n\n var oddSum = 0L\n var evenSum = 0L\n\n for (i in 0 until n) {\n if (i % 2 == 0) {\n evenSum += a[i]\n } else {\n oddSum += a[i]\n }\n }\n\n// val maxOdd = oddSum + maxOf()\n}\n\nfun f() {\n val (n, m, q) = readInts()\n val a = Array(n) { IntArray(m) }\n\n val rows = LongArray(n)\n val columns = LongArray(m)\n\n for (i in 0 until n) {\n a[i] = readInts().toIntArray()\n\n for (j in 0 until m) {\n rows[i] = rows[i] + a[i][j]\n columns[j] = columns[j] + a[i][j]\n }\n }\n\n val rowsP = LongArray(n)\n val rowsS = LongArray(n)\n\n val rowsPM = LongArray(n)\n val rowsSM = LongArray(n)\n\n val columnsP = LongArray(m)\n val columnsS = LongArray(m)\n\n val columnsPM = LongArray(m)\n val columnsSM = LongArray(m)\n\n for (i in 0 until q + 1) {\n if (i != 0) {\n val (x, y, z) = readInts()\n val diff = z - a[x - 1][y - 1]\n rows[x - 1] = rows[x - 1] + diff\n columns[y - 1] = columns[y - 1] + diff\n a[x - 1][y - 1] = z\n }\n\n rowsP[0] = rows[0]\n for (j in 1 until n) {\n rowsP[j] = rowsP[j - 1] + rows[j]\n rowsPM[j] = rowsP[j - 1] + rowsPM[j - 1]\n }\n\n rowsS[n - 1] = rows[n - 1]\n for (j in n - 2 downTo 0) {\n rowsS[j] = rowsS[j + 1] + rows[j]\n rowsSM[j] = rowsS[j + 1] + rowsSM[j + 1]\n }\n\n columnsP[0] = columns[0]\n for (j in 1 until m) {\n columnsP[j] = columnsP[j - 1] + columns[j]\n columnsPM[j] = columnsP[j - 1] + columnsPM[j - 1]\n }\n\n columnsS[m - 1] = columns[m - 1]\n for (j in m - 2 downTo 0) {\n columnsS[j] = columnsS[j + 1] + columns[j]\n columnsSM[j] = columnsS[j + 1] + columnsSM[j + 1]\n }\n\n var minRow = minOf(rowsSM[0], rowsPM[n - 1])\n for (j in 1 until n - 1) {\n minRow = minOf(minRow, rowsSM[j] + rowsPM[j])\n }\n\n var minColumn = minOf(columnsSM[0], columnsPM[m - 1])\n for (j in 1 until m - 1) {\n minColumn = minOf(minColumn, columnsSM[j] + columnsPM[j])\n }\n\n print(\"${minRow + minColumn}\\n\")\n }\n}\n\nprivate inline fun sqr(x: Int) = 1L * x * x\n\n\nval t = IntArray(2_200_000)\n\nfun build(a: IntArray, v: Int, tl: Int, tr: Int) {\n if (tl == tr) {\n t[v] = a[tl]\n } else {\n val tm = (tl + tr) / 2\n build(a, v * 2, tl, tm)\n build(a, v * 2 + 1, tm + 1, tr)\n t[v] = t[v * 2] + t[v * 2 + 1]\n }\n\n// println(\"$v [$tl, $tr] = ${t[v]}\")\n}\n\nfun update(v: Int, tl: Int, tr: Int, pos: Int): Int {\n if (tl == tr) {\n t[v]++\n return t[v]\n } else {\n val tm = (tl + tr) / 2\n val res = if (pos <= tm) {\n update(v * 2, tl, tm, pos)\n } else {\n update(v * 2 + 1, tm + 1, tr, pos)\n }\n t[v] = t[v * 2] + t[v * 2 + 1]\n return res\n }\n}\n\nfun delete(v: Int, tl: Int, tr: Int, pos: Int): Int {\n// println(\"$v [$tl, $tr] = ${t[v]}, pos = $pos\")\n if (tl == tr) {\n t[v]--\n return tl\n } else {\n val tm = (tl + tr) / 2\n val res = if (pos <= t[v * 2]) {\n delete(v * 2, tl, tm, pos)\n } else {\n delete(v * 2 + 1, tm + 1, tr, pos - t[v * 2])\n }\n t[v] = t[v * 2] + t[v * 2 + 1]\n return res\n }\n}\n\nfun e() {\n val N = 1_00_000\n val f = IntArray(N)\n for (i in 0 until N) {\n f[i] = f[i / 10] + i % 10\n }\n\n val max = f.max()!!\n\n// println(max)\n\n repeat(readInt()) {\n val (n, k) = readInts()\n\n if (max * (k + 1) >= n) {\n var sum = 0\n for (i in 0 until k + 1) {\n sum += f[i]\n }\n\n if (n == sum) {\n println(0)\n return@repeat\n }\n\n for (i in 1 until N - k) {\n sum -= f[i - 1]\n sum += f[i + k]\n\n if (n == sum) {\n println(i)\n return@repeat\n }\n }\n }\n\n val res = StringBuilder()\n res.append('9')\n var sum = (9 - k..9).sum()\n\n println(\"$res $sum\")\n\n while (sum < n) {\n res.append('9')\n sum += 9 * (k + 1)\n\n println(\"$res $sum\")\n\n if (sum == n) {\n res[res.length - 1] = '9' - k\n println(res)\n return@repeat\n }\n if (sum > n) {\n sum -= 9 * (k + 1)\n for (i in 1 until 9) {\n if (sum + i * (k + 1) == n) {\n res[0] = '0' + i\n res[res.length - 1] = '9' - k\n println(res)\n return@repeat\n }\n }\n break\n }\n }\n\n println(-1)\n }\n}\n\ninternal class FastScanner {\n var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\n var st: StringTokenizer? = null\n\n operator fun next(): String {\n while (st == null || !st!!.hasMoreElements()) {\n try {\n st = StringTokenizer(br.readLine())\n } catch (e: IOException) {\n e.printStackTrace()\n }\n }\n return st!!.nextToken()\n }\n\n fun nextInt(): Int {\n return next().toInt()\n }\n}\n\nfun Int.isEven(): Boolean = this % 2 == 0\nfun Int.isOdd(): Boolean = this % 2 == 1\n\npublic operator fun List.component6(): T {\n return get(5)\n}\n\nfun allPrimesUpTo(n: Int): List {\n val isPrime = BooleanArray(n + 1) { true }\n val primes = mutableListOf()\n\n isPrime[0] = false\n isPrime[1] = false\n for (i in 2 until n + 1) {\n if (isPrime[i]) {\n primes.add(i)\n\n if (i.toLong() * i > n)\n continue\n\n for (j in i * i until n + 1 step i) {\n isPrime[j] = false\n }\n }\n }\n\n return primes\n}\n\nfun leastDivisor(n: Int): Int {\n if (n % 2 == 0) return 2\n if (n % 3 == 0) return 3\n if (n % 5 == 0) return 5\n\n for (i in 7 until n) {\n if (i * i > n) break\n\n if (n % i == 0) {\n return i\n }\n }\n\n return 1\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\n\nfun PrintWriter.solve(sc: FastScanner) {\n val t = sc.nextInt()\n for (_i in 0 until t) {\n val n = sc.nextInt()\n var p = -1\n var d = 2\n while (d * d <= n) {\n if (n % d == 0) {\n p = d\n break\n }\n d++\n }\n if (p == -1) p = n\n val v = n / p\n println(\"$v ${n - v}\")\n }\n}\n\nfun main() {\n val writer = PrintWriter(System.out, false)\n writer.solve(FastScanner(System.`in`))\n writer.flush()\n}\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.math.*\n\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n for (i in 0 until n) {\n val total = scanner.nextInt().toDouble()\n if (total.toInt() % 2 == 0) {\n println(\"${total.toInt() / 2} ${total.toInt() / 2}\")\n } else {\n val x = floor(sqrt(total)).toInt()\n var flag = false\n for (j in 3..x) {\n if (total.toInt() % j == 0) {\n flag = true\n println(\"${total.toInt() / j} ${total.toInt() - (total.toInt() / j)}\")\n break;\n }\n }\n if (!flag) {\n println(\"1 ${total.toInt() - 1}\")\n }\n }\n }\n}\n\n\n"}, {"source_code": "import java.io.BufferedReader\n\nfun main() {\n val br = System.`in`.bufferedReader()\n val sb = StringBuilder()\n val t = br.readInt()\n repeat(t) {\n val n = br.readInt()\n var i = 2\n var found = false\n while (i * i <= n) {\n if (n % i == 0) {\n found = true\n sb.append(n / i).append(' ').append(n - (n / i)).append('\\n')\n break\n }\n i++\n }\n if (!found) {\n sb.append(1).append(' ').append(n - 1).append('\\n')\n }\n }\n print(sb)\n}\n\nprivate const val SPACE_INT = ' '.toInt()\nprivate const val ZERO_INT = '0'.toInt()\nprivate const val NL_INT = '\\n'.toInt()\n\nprivate fun BufferedReader.readInt(): Int {\n var ret = read()\n while (ret <= SPACE_INT) {\n ret = read()\n }\n val neg = ret == '-'.toInt()\n if (neg) {\n ret = read()\n }\n ret -= ZERO_INT\n var read = read()\n while (read >= ZERO_INT) {\n ret *= 10\n ret += read - ZERO_INT\n read = read()\n }\n\n while (read <= SPACE_INT && read != -1 && read != NL_INT) {\n mark(1)\n read = read()\n }\n if (read > SPACE_INT) {\n reset()\n }\n return if (neg) -ret else ret\n}"}, {"source_code": "fun main() {\n for (c in 1..readLine()!!.toInt()) {\n val n = readLine()!!.toInt()\n var p = 0\n for (m in 2..100000) {\n if (n % m == 0) {\n p = m\n break\n }\n }\n if (p == 0) {\n p = n\n }\n println(\"${n / p} ${n - (n / p)}\")\n }\n}"}, {"source_code": "import java.lang.Integer.max\nimport kotlin.math.sqrt\n\nfun main() {\n val t= readInt()\n repeat(t){\n val n = readInt()\n if(n%2==0){\n println(\"${n/2} ${n/2}\")\n }\n else{\n val firstPrimeMultiple = findFirstPrimeMultiple(n)\n if(firstPrimeMultiple == n) println(\"${n-1} 1\")\n else {\n val number = (n.div(firstPrimeMultiple))\n println(\"$number ${n-number}\")\n }\n }\n }\n}\n\nfun findFirstPrimeMultiple(n: Int): Int{\n repeat(sqrt(n.toDouble()).toInt()+10){\n if(it >1) {\n val remaining = (n / it).toInt()\n if (remaining * it == n) return it\n }\n }\n return n\n}\n\nfun getNumber(row: Int, col: Int, n: Int, m: Int, cell: Int): Int {\n var number = 0\n if(row+1=0) number = number +1\n if (col-1>=0) number = number +1\n return number\n}\n\nprivate fun isValid(row: Int, col: Int, n: Int, m: Int, cell: Int): Boolean {\n var number = 0\n if(row+1=0) number = number +1\n if (col-1>=0) number = number +1\n return cell <=number\n}\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\nprivate fun readLongs() = readStrings().map { it.toLong() }\n"}, {"source_code": "fun main() {\n for (c in 1..readLine()!!.toInt()) {\n val n = readLine()!!.toInt()\n var p = 0\n for (m in 2..100000) {\n if (n % m == 0) {\n p = m\n break\n }\n }\n if (p == 0) {\n p = n\n }\n println(\"${n / p} ${n - (n / p)}\")\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val count = scan.nextInt()\n for (i in 0 until count) {\n val n = scan.nextLong()\n var divider = 2\n while (n % divider != 0L && divider <= n / divider.toFloat()) divider++\n val a = if (n % divider == 0L) n / divider else 1\n println(\"$a ${n - a}\")\n }\n}"}, {"source_code": "//package cf1372\n\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\n\nclass B {\n private val input: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\n private val output: PrintWriter = PrintWriter(System.out)\n\n var st: StringTokenizer? = null\n\n private fun closeAfter() {\n input.close()\n output.close()\n }\n\n private fun next(): String {\n if (st == null || !st!!.hasMoreElements()) {\n st = StringTokenizer(input.readLine())\n }\n\n return st!!.nextToken()\n }\n\n private fun nextInt(): Int {\n return next().toInt()\n }\n\n private fun nextDouble(): Double {\n return next().toDouble()\n }\n\n fun solve() {\n innerSolve()\n closeAfter()\n }\n\n private fun innerSolve() {\n val tt = nextInt()\n for (t in 0 until tt) {\n val n = nextInt()\n if (n % 2 == 0) {\n output.println(\"${n / 2} ${n / 2}\")\n } else {\n var a = 1\n var b = n - 1\n\n var i = 3\n\n while (i <= Math.sqrt(1.0 * n).toInt()) {\n\n if (n % i == 0) {\n a = n / i\n b = n - a\n break\n }\n i += 2\n }\n\n output.println(\"$a $b\")\n }\n }\n }\n}\n\nfun main(args: Array) {\n B().solve()\n}"}, {"source_code": "fun main() {\n for (c in 1..readLine()!!.toInt()) {\n val n = readLine()!!.toInt()\n var p = 0\n for (m in 2..100000) {\n if (n % m == 0) {\n p = m\n break\n }\n }\n if (p == 0) {\n p = n\n }\n println(\"${n / p} ${n - (n / p)}\")\n }\n}"}, {"source_code": "fun main() {\n for (c in 1..readLine()!!.toInt()) {\n val n = readLine()!!.toInt()\n var p = 0\n for (m in 2..100000) {\n if (n % m == 0) {\n p = m\n break\n }\n }\n if (p == 0) {\n p = n\n }\n println(\"${n / p} ${n - (n / p)}\")\n }\n}"}, {"source_code": "fun main() {\n repeat(readInt()) {\n val n = readInt()\n var ans = 1\n var minLcm = n - 1\n\n var i = 2\n while (i * i <= n) {\n if (n % i == 0) {\n val curLcm = lcm(i, n - i)\n if (curLcm < minLcm) {\n minLcm = curLcm\n ans = i\n }\n\n val curLcm2 = lcm(n / i, n - n / i)\n if (curLcm2 < minLcm) {\n minLcm = curLcm2\n ans = n / i\n }\n }\n\n i++\n }\n\n val second = n - ans\n print(\"$ans $second\\n\")\n\n }\n}\n\nfun readInt(): Int = readLine()!!.toInt()\n\nfun gcd(a: Int, b: Int): Int {\n if (a == 0 || b == 0)\n return a + b\n\n return if (a > b) gcd(a % b, b) else gcd(a, b % a)\n}\n\nfun lcm(a: Int, b: Int): Int = a / gcd(a, b) * b"}, {"source_code": "import java.io.File\nimport java.util.*\n\nfun readInt(): Int {\n return sc.nextInt()\n}\n\nfun readInts(): IntArray {\n var line = sc.nextLine()\n if (line.trim().isEmpty()) {\n line = sc.nextLine()\n }\n return line.split(\" \").map { it.toInt() }.toIntArray()\n}\n\nvar debug = false\nvar sc = Scanner(System.`in`)\nfun main(args: Array) {\n val input = File(\"input.in\")\n if (input.exists()) {\n debug = true\n sc = Scanner(input)\n }\n val testCount = readInt()\n for (i in 1..testCount) {\n val n = readInt()\n var answerFound = false\n for (x in 2..Math.sqrt(n.toDouble()).toInt()) {\n if (n % x == 0) {\n answerFound = true\n println((n / x).toString() + \" \" + (n / x) * (x - 1))\n break\n }\n }\n if (!answerFound) {\n println(1.toString() + \" \" + (n - 1))\n }\n }\n}"}, {"source_code": "fun readInt() = readLine()!!.toInt()\n\nfun main() {\n repeat(readInt()) {\n val n = readInt()\n println(solve(n))\n }\n}\n\nfun solve(n: Int): String {\n var i = 2\n while (i*i <= n) {\n if (n % i == 0) {\n val d = n / i\n return \"$d ${n-d}\"\n }\n i++\n }\n return \"1 ${n-1}\"\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.math.sqrt\n\nprivate inline fun debug(str: () -> Any?) = println(str().toString()) //{}\nprivate inline fun readInt() = reader.nextInt()\nprivate inline fun readLong() = reader.nextLong()\nprivate inline fun readDouble() = reader.nextDouble()\nprivate inline fun readArr() = readLine()!!.split(\" \").map { it.toInt() }\nprivate inline fun readArr(n: Int) = List(n) { reader.nextInt() }\nprivate inline fun readArrLong() = readLine()!!.split(\" \").map { it.toLong() }\nprivate inline fun readArrLong(n: Int) = List(n) { reader.nextLong() }\nprivate inline fun readArrDouble() = readLine()!!.split(\" \").map { it.toDouble() }\nprivate inline fun readArrDouble(n: Int) = List(n) { reader.nextDouble() }\nprivate inline fun readLineAsCharList() = reader.nextLine().asSequence().toList()\nprivate inline fun readAndSolve(f: () -> Unit): Unit {\n val n = readInt()\n // usually n is the only value in string\n reader.nextLine()\n repeat(n) { f() }\n}\n\nprivate fun Boolean.yn() = if (this) \"YES\" else \"NO\"\nprivate fun Iterable.out() = this.joinToString(\" \")\nprivate val reader = Scanner(System.`in`.bufferedReader()).apply { useLocale(Locale.US) }\n\n\n@ExperimentalStdlibApi\nfun main() = solve1372B()\n\n@ExperimentalStdlibApi\nprivate fun solve1372B() {\n\n val n = readInt()\n val arr = readArr(n)\n val max = arr.max() ?: 5\n val sqrtMax = sqrt(max.toDouble()).toInt() + 1\n\n val primes = mutableListOf()\n val sieve = BitSet(sqrtMax) // false - простое, true - не простое\n fun fillSieve() {\n sieve[0] = true\n sieve[1] = true\n var i = 2\n while (i * i < sqrtMax) {\n if (!sieve[i]) {\n primes.add(i)\n var j = i * i\n while (j < sqrtMax) {\n sieve[j] = true\n j += i\n }\n }\n i++\n }\n while (i < sqrtMax) {\n val nextPrime = sieve.nextClearBit(i)\n primes.add(nextPrime)\n i = nextPrime + 1\n }\n }\n fillSieve()\n //println(primes)\n\n for (a in arr) {\n var ans1 = 0\n var ans2 = 0\n var found = false\n for (p in primes) {\n if (a % p == 0) {\n found = true\n ans1 = a / p\n break\n }\n }\n if (!found) {\n ans1 = 1\n }\n ans2 = a - ans1\n println(\"$ans1 $ans2\")\n }\n\n}\n"}], "negative_code": [{"source_code": "import kotlin.math.sqrt\n\n/**\n * Euler's totient function */\n\nfun main() {\n\n repeat(readLine()!!.toInt()) {\n val num = readLine()!!.toInt()\n val leastPrime = leastPrime(num)\n println(\"${num / leastPrime} ${num / leastPrime * (leastPrime - 1)}\")\n }\n\n}\n\nfun leastPrime(n: Int): Int {\n var num = 2\n if (n % 2 == 0)\n return 2\n num += 1\n while (n % num != 0 && num < sqrt(n.toDouble())) {\n num += 2\n }\n return num\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.*\nimport kotlin.math.*\n\nfun readInts() = readLine()!!.split(\" \").map{i -> i.toInt()}.toMutableList()\nfun readInt() = readLine()!!.toInt()\nfun readLongs() = readLine()!!.split(\" \").map{i -> i.toLong()}.toMutableList()\n\nfun main() {\n val t = readInt()\n repeat(t) {\n val n = readInt()\n if (n % 2 == 0) {\n println(\"${n / 2} ${n / 2}\")\n } else {\n var a = sqrt(n.toDouble()).toInt()\n var b = n - a\n while(b % a != 0) {\n a--\n b++\n }\n println(\"$a $b\")\n }\n }\n}"}, {"source_code": "import java.lang.Math.*\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readLong() = readLn().toLong()\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of ints\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\n\n//var n = 0\n//var ar = listOf()\nval visited = mutableSetOf()\nval graph = mutableMapOf>()\n\nfun main() {\n val t = readInt()\n for (cases in 0 until t) {\n solve()\n }\n\n// solve()\n}\n\nfun solve() {\n val n = readInt()\n\n var ans1 = 1\n var ans2 = n - 1\n for (i in 2 until sqrt(n.toDouble()).toInt() + 1) {\n if (n % i == 0) {\n val d = n / i\n ans1 = d\n ans2 = (i - 1) * d\n }\n }\n\n println(\"$ans1 $ans2\")\n}\n"}, {"source_code": "fun main() {\n val t = readInt()\n fun findOther(x: Int, n: Int): Int {\n val a = n/x - 1\n return a * x\n }\n\n repeat(t) {\n val n = readInt()\n if (n % 2 == 0) println(\"${n/2} ${n/2}\")\n else {\n var divisor = 1\n val candidates = mutableListOf()\n while (divisor * divisor <= n) {\n if (n % divisor == 0) candidates.add(divisor)\n\n divisor += 2\n }\n\n val ans = candidates.map { Pair(it, findOther(it, n)) }.minBy { it.second }!!\n println(\"${ans.first} ${ans.second}\")\n }\n }\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\n\nprivate fun readStrings() = readLn().trim().split(\" \")\nprivate fun readInt() = readLn().toInt()\nprivate fun readInts() = readStrings().map { it.toInt() }\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.util.*\n\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\n\nfun main(args: Array) {\n b()\n}\n\n\nfun divisor(n: Int): Int {\n var i = 2\n while (i * i <= n) {\n if (n % i == 0) return i\n i++\n }\n return n\n}\n\nfun a() {\n repeat(readInt()) {\n val n = readInt()\n val a = List(n) { 1 }\n println(a.joinToString(separator = \" \"))\n }\n}\n\nfun pow(a: Int, b: Int): Long {\n var res = 1L\n repeat(b) { res *= a }\n return res\n}\n\nfun adj(i: Int, j: Int, n: Int, m: Int): Int {\n var adj = 4\n if (i == 0) adj--\n if (j == 0) adj--\n if (i == n - 1) adj--\n if (j == m - 1) adj--\n return adj\n}\n\nfun activeAdj(i: Int, j: Int, n: Int, m: Int, a: Array): Int {\n var activeAdj = 0\n if (i - 1 >= 0 && a[i - 1][j] > 0) activeAdj++\n if (j - 1 >= 0 && a[i][j - 1] > 0) activeAdj++\n if (i + 1 < n && a[i + 1][j] > 0) activeAdj++\n if (j + 1 < m && a[i][j + 1] > 0) activeAdj++\n return activeAdj\n}\n\nfun b() {\n repeat(readInt()) {\n val n = readInt()\n val divisor = leastDivisor(n)\n\n println(\"${n / divisor} ${n - n / divisor}\")\n }\n}\n\nfun c() {\n repeat(readInt()) {\n val n = readInt()\n val a = readInts()\n\n val mins = mutableListOf(a[0])\n val maxs = mutableListOf(a[n - 1])\n\n for (i in 1 until n) {\n// println(a[i])\n while (mins.size > 1 && mins[mins.lastIndex] < a[i]) {\n mins.removeAt(mins.lastIndex)\n }\n if (mins.last() > a[i]) {\n mins.add(a[i])\n }\n\n// println(mins)\n }\n\n if (mins.size == 1) {\n println(\"YES\")\n return@repeat\n }\n\n for (i in n - 2 downTo 0) {\n// println(a[i])\n while (maxs.size > 1 && maxs[maxs.lastIndex] > a[i]) {\n maxs.removeAt(maxs.lastIndex)\n }\n if (maxs.last() < a[i]) {\n maxs.add(a[i])\n }\n// println(maxs)\n }\n\n if (maxs.size == 1) {\n println(\"YES\")\n return@repeat\n }\n\n println(\"NO\")\n\n// println(if (a.indexOf(mins[1]) > a.indexOf(maxs[1])) \"YES\" else \"NO\")\n }\n}\n\nfun df(a: IntArray): Pair, Triple> {\n\n var dif = 0L\n var lastIndex = 0\n var maxDif = 0L\n var maxIndex = 0\n var maxLength = 0\n for (i in 0 until a.size - 1 step 2) {\n dif += a[i + 1] - a[i]\n if (dif <= 0) {\n dif = 0\n lastIndex = i + 2\n continue\n }\n if (dif > maxDif) {\n maxDif = dif\n maxIndex = lastIndex\n maxLength = i + 2 - lastIndex\n }\n }\n\n var dif1 = 0L\n var lastIndex1 = 1\n var maxDif1 = 0L\n var maxIndex1 = 0\n var maxLength1 = 0\n for (i in 1 until a.size - 1 step 2) {\n dif1 += a[i + 1] - a[i]\n if (dif1 >= 0) {\n dif1 = 0\n lastIndex1 = i + 2\n continue\n }\n if (dif1 < maxDif1) {\n maxDif1 = dif1\n maxIndex1 = lastIndex1\n maxLength1 = i + 2 - lastIndex1\n }\n }\n\n return Pair(Triple(maxDif, maxIndex, maxLength), Triple(-maxDif1, maxIndex1, maxLength1))\n}\n\ndata class MyPair(var first: Int, var second: Int) : Comparable {\n override fun compareTo(other: MyPair): Int {\n return this.first - other.first\n }\n\n}\n\nfun d() {\n repeat(readInt()) {\n val n = readInt()\n val a = readInts().toIntArray()\n\n val f = IntArray(n + 1)\n val id = List(n + 1) { mutableListOf() }\n val q = PriorityQueue()\n\n for (i in 0 until n) {\n id[ a[i] ].add(i)\n f[a[i]]++\n }\n\n for (i in 0 until n + 1) {\n if (f[i] == 0) {\n q.add(i)\n }\n }\n\n val ans = mutableListOf()\n\n var pref = 0\n\n repeat(n) {\n val element = q.poll()\n\n if (element == n) {\n ans.add(pref)\n q.poll()\n q.add(a[pref])\n a[pref] = n\n }\n\n ans.add(element)\n f[a[element]]--\n if (f[a[element]] == 0) {\n q.add(a[element])\n }\n a[element] = element\n }\n/*\n for (i in 0 until n) {\n// println(i)\n// println(q.peek())\n// println(a.contentToString())\n if (a[i] == i) continue\n if (q.peek() == i) {\n ans.add(i)\n\n val element = a[i]\n a[i] = q.poll() // i\n f[a[i]]++\n f[element]--\n if (f[element] == 0) {\n q.add(element)\n }\n } else {\n for (idx in id[i]) {\n ans.add(idx)\n }\n val index = id[i]\n ans.add(index)\n ans.add(i)\n\n id[q.peek()] = index\n f[q.peek()]++\n a[index] = q.poll()\n\n val element = a[i]\n a[i] = i\n f[a[i]]++\n f[element]--\n if (f[element] == 0) {\n q.add(element)\n }\n }\n }\n */\n\n println(ans.size)\n println(ans.joinToString(separator = \" \", transform = { (it + 1).toString() }))\n }\n}\n\nfun f() {\n val (n, m, q) = readInts()\n val a = Array(n) { IntArray(m) }\n\n val rows = LongArray(n)\n val columns = LongArray(m)\n\n for (i in 0 until n) {\n a[i] = readInts().toIntArray()\n\n for (j in 0 until m) {\n rows[i] = rows[i] + a[i][j]\n columns[j] = columns[j] + a[i][j]\n }\n }\n\n val rowsP = LongArray(n)\n val rowsS = LongArray(n)\n\n val rowsPM = LongArray(n)\n val rowsSM = LongArray(n)\n\n val columnsP = LongArray(m)\n val columnsS = LongArray(m)\n\n val columnsPM = LongArray(m)\n val columnsSM = LongArray(m)\n\n for (i in 0 until q + 1) {\n if (i != 0) {\n val (x, y, z) = readInts()\n val diff = z - a[x - 1][y - 1]\n rows[x - 1] = rows[x - 1] + diff\n columns[y - 1] = columns[y - 1] + diff\n a[x - 1][y - 1] = z\n }\n\n rowsP[0] = rows[0]\n for (j in 1 until n) {\n rowsP[j] = rowsP[j - 1] + rows[j]\n rowsPM[j] = rowsP[j - 1] + rowsPM[j - 1]\n }\n\n rowsS[n - 1] = rows[n - 1]\n for (j in n - 2 downTo 0) {\n rowsS[j] = rowsS[j + 1] + rows[j]\n rowsSM[j] = rowsS[j + 1] + rowsSM[j + 1]\n }\n\n columnsP[0] = columns[0]\n for (j in 1 until m) {\n columnsP[j] = columnsP[j - 1] + columns[j]\n columnsPM[j] = columnsP[j - 1] + columnsPM[j - 1]\n }\n\n columnsS[m - 1] = columns[m - 1]\n for (j in m - 2 downTo 0) {\n columnsS[j] = columnsS[j + 1] + columns[j]\n columnsSM[j] = columnsS[j + 1] + columnsSM[j + 1]\n }\n\n var minRow = minOf(rowsSM[0], rowsPM[n - 1])\n for (j in 1 until n - 1) {\n minRow = minOf(minRow, rowsSM[j] + rowsPM[j])\n }\n\n var minColumn = minOf(columnsSM[0], columnsPM[m - 1])\n for (j in 1 until m - 1) {\n minColumn = minOf(minColumn, columnsSM[j] + columnsPM[j])\n }\n\n print(\"${minRow + minColumn}\\n\")\n }\n}\n\nprivate inline fun sqr(x: Int) = 1L * x * x\n\n\nval t = IntArray(2_200_000)\n\nfun build(a: IntArray, v: Int, tl: Int, tr: Int) {\n if (tl == tr) {\n t[v] = a[tl]\n } else {\n val tm = (tl + tr) / 2\n build(a, v * 2, tl, tm)\n build(a, v * 2 + 1, tm + 1, tr)\n t[v] = t[v * 2] + t[v * 2 + 1]\n }\n\n// println(\"$v [$tl, $tr] = ${t[v]}\")\n}\n\nfun update(v: Int, tl: Int, tr: Int, pos: Int): Int {\n if (tl == tr) {\n t[v]++\n return t[v]\n } else {\n val tm = (tl + tr) / 2\n val res = if (pos <= tm) {\n update(v * 2, tl, tm, pos)\n } else {\n update(v * 2 + 1, tm + 1, tr, pos)\n }\n t[v] = t[v * 2] + t[v * 2 + 1]\n return res\n }\n}\n\nfun delete(v: Int, tl: Int, tr: Int, pos: Int): Int {\n// println(\"$v [$tl, $tr] = ${t[v]}, pos = $pos\")\n if (tl == tr) {\n t[v]--\n return tl\n } else {\n val tm = (tl + tr) / 2\n val res = if (pos <= t[v * 2]) {\n delete(v * 2, tl, tm, pos)\n } else {\n delete(v * 2 + 1, tm + 1, tr, pos - t[v * 2])\n }\n t[v] = t[v * 2] + t[v * 2 + 1]\n return res\n }\n}\n\nfun e() {\n val N = 1_00_000\n val f = IntArray(N)\n for (i in 0 until N) {\n f[i] = f[i / 10] + i % 10\n }\n\n val max = f.max()!!\n\n// println(max)\n\n repeat(readInt()) {\n val (n, k) = readInts()\n\n if (max * (k + 1) >= n) {\n var sum = 0\n for (i in 0 until k + 1) {\n sum += f[i]\n }\n\n if (n == sum) {\n println(0)\n return@repeat\n }\n\n for (i in 1 until N - k) {\n sum -= f[i - 1]\n sum += f[i + k]\n\n if (n == sum) {\n println(i)\n return@repeat\n }\n }\n }\n\n val res = StringBuilder()\n res.append('9')\n var sum = (9 - k..9).sum()\n\n println(\"$res $sum\")\n\n while (sum < n) {\n res.append('9')\n sum += 9 * (k + 1)\n\n println(\"$res $sum\")\n\n if (sum == n) {\n res[res.length - 1] = '9' - k\n println(res)\n return@repeat\n }\n if (sum > n) {\n sum -= 9 * (k + 1)\n for (i in 1 until 9) {\n if (sum + i * (k + 1) == n) {\n res[0] = '0' + i\n res[res.length - 1] = '9' - k\n println(res)\n return@repeat\n }\n }\n break\n }\n }\n\n println(-1)\n }\n}\n\ninternal class FastScanner {\n var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\n var st: StringTokenizer? = null\n\n operator fun next(): String {\n while (st == null || !st!!.hasMoreElements()) {\n try {\n st = StringTokenizer(br.readLine())\n } catch (e: IOException) {\n e.printStackTrace()\n }\n }\n return st!!.nextToken()\n }\n\n fun nextInt(): Int {\n return next().toInt()\n }\n}\n\nfun Int.isEven(): Boolean = this % 2 == 0\nfun Int.isOdd(): Boolean = this % 2 == 1\n\npublic operator fun List.component6(): T {\n return get(5)\n}\n\nfun allPrimesUpTo(n: Int): List {\n val isPrime = BooleanArray(n + 1) { true }\n val primes = mutableListOf()\n\n isPrime[0] = false\n isPrime[1] = false\n for (i in 2 until n + 1) {\n if (isPrime[i]) {\n primes.add(i)\n\n if (i.toLong() * i > n)\n continue\n\n for (j in i * i until n + 1 step i) {\n isPrime[j] = false\n }\n }\n }\n\n return primes\n}\n\nfun leastDivisor(n: Int): Int {\n if (n % 2 == 0) return 2\n if (n % 3 == 0) return 3\n if (n % 5 == 0) return 5\n\n for (i in 7 until n) {\n if (i * i > n) return 1\n\n if (n % i == 0) {\n return i\n }\n }\n\n return 1\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.math.ceil\nimport kotlin.math.floor\nimport kotlin.math.max\nimport kotlin.math.round\n\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n for (i in 0 until n) {\n val total = scanner.nextInt().toDouble()\n if (total.toInt() % 2 == 0) {\n println(\"${total.toInt() / 2} ${total.toInt() / 2}\")\n } else {\n val x = ceil(total / 2).toInt()\n for (j in x downTo 1 step 2) {\n if(total.toInt() % j == 0){\n println(\"$j ${total.toInt() - j}\")\n break;\n }\n }\n }\n }\n}\n\n\n"}, {"source_code": "import java.util.*\nimport kotlin.math.*\n\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n for (i in 0 until n) {\n val total = scanner.nextInt().toDouble()\n if (total.toInt() % 2 == 0) {\n println(\"${total.toInt() / 2} ${total.toInt() / 2}\")\n } else {\n val x = floor(sqrt(total)).toInt()\n var flag = false\n for (j in 3..x) {\n if (total.toInt() % j == 0) {\n flag = true\n println(\"${total.toInt() / j} ${total.toInt() - (total.toInt() / j)}\")\n break;\n }\n }\n if (flag) {\n println(\"1 ${total.toInt() - 1}\")\n }\n }\n }\n}\n\n\n"}, {"source_code": "import java.io.BufferedReader\n\nfun main() {\n val br = System.`in`.bufferedReader()\n val sb = StringBuilder()\n val t = br.readInt()\n repeat(t) {\n val n = br.readInt()\n var i = 2\n var found = false\n while (i * i <= n) {\n if (n % i == 0) {\n found = true\n sb.append(n / i).append(' ').append(n - (n / i)).append('\\n')\n }\n i++\n }\n if (!found) {\n sb.append(1).append(' ').append(n - 1).append('\\n')\n }\n }\n print(sb)\n}\n\nprivate const val SPACE_INT = ' '.toInt()\nprivate const val ZERO_INT = '0'.toInt()\nprivate const val NL_INT = '\\n'.toInt()\n\nprivate fun BufferedReader.readInt(): Int {\n var ret = read()\n while (ret <= SPACE_INT) {\n ret = read()\n }\n val neg = ret == '-'.toInt()\n if (neg) {\n ret = read()\n }\n ret -= ZERO_INT\n var read = read()\n while (read >= ZERO_INT) {\n ret *= 10\n ret += read - ZERO_INT\n read = read()\n }\n\n while (read <= SPACE_INT && read != -1 && read != NL_INT) {\n mark(1)\n read = read()\n }\n if (read > SPACE_INT) {\n reset()\n }\n return if (neg) -ret else ret\n}"}, {"source_code": "import java.io.BufferedReader\n\nfun main() {\n val br = System.`in`.bufferedReader()\n val sb = StringBuilder()\n val t = br.readInt()\n repeat(t) {\n val n = br.readInt()\n var i = 2\n var found = false\n while (i * i <= n) {\n if (n % i == 0) {\n found = true\n sb.append(n / i).append(' ').append(n - (n / i)).append('\\n')\n }\n i++\n }\n if (!found) {\n sb.append(1).append(' ').append(n - 1)\n }\n }\n print(sb)\n}\n\nprivate const val SPACE_INT = ' '.toInt()\nprivate const val ZERO_INT = '0'.toInt()\nprivate const val NL_INT = '\\n'.toInt()\n\nprivate fun BufferedReader.readInt(): Int {\n var ret = read()\n while (ret <= SPACE_INT) {\n ret = read()\n }\n val neg = ret == '-'.toInt()\n if (neg) {\n ret = read()\n }\n ret -= ZERO_INT\n var read = read()\n while (read >= ZERO_INT) {\n ret *= 10\n ret += read - ZERO_INT\n read = read()\n }\n\n while (read <= SPACE_INT && read != -1 && read != NL_INT) {\n mark(1)\n read = read()\n }\n if (read > SPACE_INT) {\n reset()\n }\n return if (neg) -ret else ret\n}"}, {"source_code": "import java.lang.Integer.max\n\nfun main() {\n val t= readInt()\n repeat(t){\n val n = readInt()\n if(n%2==0){\n println(\"${n/2} ${n/2}\")\n }\n else{\n val lower = if(n/2-1 != 0) n/2-1 else n/2\n val higher = n-lower\n println(\"$lower $higher\")\n }\n }\n}\n\nfun getNumber(row: Int, col: Int, n: Int, m: Int, cell: Int): Int {\n var number = 0\n if(row+1=0) number = number +1\n if (col-1>=0) number = number +1\n return number\n}\n\nprivate fun isValid(row: Int, col: Int, n: Int, m: Int, cell: Int): Boolean {\n var number = 0\n if(row+1=0) number = number +1\n if (col-1>=0) number = number +1\n return cell <=number\n}\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\nprivate fun readLongs() = readStrings().map { it.toLong() }\n"}, {"source_code": "//package cf1372\n\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\n\nclass B {\n private val input: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\n private val output: PrintWriter = PrintWriter(System.out)\n\n var st: StringTokenizer? = null\n\n private fun closeAfter() {\n input.close()\n output.close()\n }\n\n private fun next(): String {\n if (st == null || !st!!.hasMoreElements()) {\n st = StringTokenizer(input.readLine())\n }\n\n return st!!.nextToken()\n }\n\n private fun nextInt(): Int {\n return next().toInt()\n }\n\n private fun nextDouble(): Double {\n return next().toDouble()\n }\n\n fun solve() {\n innerSolve()\n closeAfter()\n }\n\n private fun innerSolve() {\n val tt = nextInt()\n for (t in 0 until tt) {\n val n = nextInt()\n if (n % 2 == 0) {\n output.println(\"${n / 2} ${n / 2}\")\n } else {\n var a = 1\n var b = 1\n var cur = n\n\n for (i in 3..(Math.sqrt(1.0 * n).toInt())) {\n if (cur % i == 0) {\n\n if (cur == n) {\n a = i / 2\n b = i - a\n cur /= i\n }\n\n while (cur % i == 0) {\n cur /= i\n a *= i\n b *= i\n }\n\n if (cur == 1) {\n break;\n }\n }\n }\n output.println(\"$a $b\")\n }\n }\n }\n}\n\nfun main(args: Array) {\n B().solve()\n}"}, {"source_code": "//package cf1372\n\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\n\nclass B {\n private val input: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\n private val output: PrintWriter = PrintWriter(System.out)\n\n var st: StringTokenizer? = null\n\n private fun closeAfter() {\n input.close()\n output.close()\n }\n\n private fun next(): String {\n if (st == null || !st!!.hasMoreElements()) {\n st = StringTokenizer(input.readLine())\n }\n\n return st!!.nextToken()\n }\n\n private fun nextInt(): Int {\n return next().toInt()\n }\n\n private fun nextDouble(): Double {\n return next().toDouble()\n }\n\n fun solve() {\n innerSolve()\n closeAfter()\n }\n\n private fun innerSolve() {\n val tt = nextInt()\n for (t in 0 until tt) {\n val n = nextInt()\n if (n % 2 == 0) {\n output.println(\"${n / 2} ${n / 2}\")\n } else {\n var a = 1\n var b = n - 1\n var cur = n\n\n for (i in 3..(Math.sqrt(1.0 * n).toInt())) {\n if (cur % i == 0) {\n\n if (cur == n) {\n a = i / 2\n b = i - a\n cur /= i\n }\n\n while (cur % i == 0) {\n cur /= i\n a *= i\n b *= i\n }\n\n if (cur == 1) {\n break;\n }\n }\n }\n output.println(\"$a $b\")\n }\n }\n }\n}\n\nfun main(args: Array) {\n B().solve()\n}"}, {"source_code": "//package cf1372\n\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\n\nclass B {\n private val input: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\n private val output: PrintWriter = PrintWriter(System.out)\n\n var st: StringTokenizer? = null\n\n private fun closeAfter() {\n input.close()\n output.close()\n }\n\n private fun next(): String {\n if (st == null || !st!!.hasMoreElements()) {\n st = StringTokenizer(input.readLine())\n }\n\n return st!!.nextToken()\n }\n\n private fun nextInt(): Int {\n return next().toInt()\n }\n\n private fun nextDouble(): Double {\n return next().toDouble()\n }\n\n fun solve() {\n innerSolve()\n closeAfter()\n }\n\n private fun innerSolve() {\n val tt = nextInt()\n for (t in 0 until tt) {\n val n = nextInt()\n if (n % 2 == 0) {\n output.println(\"${n / 2} ${n / 2}\")\n } else {\n var a = 1\n var b = n - 1\n var cur = n\n\n for (i in 3..(Math.sqrt(1.0 * n).toInt())) {\n if (cur % i == 0) {\n\n if (cur == n) {\n a = i / 2\n b = i - a\n cur /= i\n }\n\n while (cur % i == 0) {\n cur /= i\n a *= i\n b *= i\n }\n\n if (cur == 1) {\n break;\n }\n }\n }\n output.println(\"$a $b\")\n }\n }\n }\n}\n\nfun main(args: Array) {\n B().solve()\n}"}, {"source_code": "//package cf1372\n\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\n\nclass B {\n private val input: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\n private val output: PrintWriter = PrintWriter(System.out)\n\n var st: StringTokenizer? = null\n\n private fun closeAfter() {\n input.close()\n output.close()\n }\n\n private fun next(): String {\n if (st == null || !st!!.hasMoreElements()) {\n st = StringTokenizer(input.readLine())\n }\n\n return st!!.nextToken()\n }\n\n private fun nextInt(): Int {\n return next().toInt()\n }\n\n private fun nextDouble(): Double {\n return next().toDouble()\n }\n\n fun solve() {\n innerSolve()\n closeAfter()\n }\n\n private fun innerSolve() {\n val tt = nextInt()\n for (t in 0 until tt) {\n val n = nextInt()\n if (n % 2 == 0) {\n output.println(\"${n / 2} ${n / 2}\")\n } else {\n var a = 1\n var b = n - 1\n\n var i = 3\n\n while (i < Math.sqrt(1.0 * n).toInt()) {\n\n if (n % i == 0) {\n a = n / i\n b = n - a\n }\n i += 2\n }\n\n output.println(\"$a $b\")\n }\n }\n }\n}\n\nfun main(args: Array) {\n B().solve()\n}"}, {"source_code": "//package cf1372\n\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\n\nclass B {\n private val input: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\n private val output: PrintWriter = PrintWriter(System.out)\n\n var st: StringTokenizer? = null\n\n private fun closeAfter() {\n input.close()\n output.close()\n }\n\n private fun next(): String {\n if (st == null || !st!!.hasMoreElements()) {\n st = StringTokenizer(input.readLine())\n }\n\n return st!!.nextToken()\n }\n\n private fun nextInt(): Int {\n return next().toInt()\n }\n\n private fun nextDouble(): Double {\n return next().toDouble()\n }\n\n fun solve() {\n innerSolve()\n closeAfter()\n }\n\n private fun innerSolve() {\n val tt = nextInt()\n for (t in 0 until tt) {\n val n = nextInt()\n if (n % 2 == 0) {\n output.println(\"${n / 2} ${n / 2}\")\n } else {\n var a = 1\n var b = n - 1\n var cur = n\n\n for (i in 3..(Math.sqrt(1.0 * n).toInt())) {\n if (cur % i == 0) {\n\n if (cur == n) {\n a = i / 2\n b = i - a\n cur /= i\n }\n\n while (cur % i == 0) {\n cur /= i\n a *= i\n b *= i\n }\n\n if (cur == 1) {\n break;\n }\n }\n }\n\n if (cur != n && cur != 1) {\n a *= cur\n b *= cur\n }\n output.println(\"$a $b\")\n }\n }\n }\n}\n\nfun main(args: Array) {\n B().solve()\n}"}, {"source_code": "fun main() {\n repeat(readInt()) {\n val n = readInt()\n var ans = 1\n var i = 2\n while (i * i <= n) {\n if (n % i == 0) {\n ans = i\n }\n i++\n }\n\n val second = n - ans\n print(\"$ans $second\\n\")\n }\n}\n\nfun readInt(): Int = readLine()!!.toInt()"}, {"source_code": "import kotlin.math.roundToInt\nimport kotlin.math.sqrt\n\nfun readInt() = readLine()!!.toInt()\n\nfun main() {\n repeat(readInt()) {\n val n = readInt()\n println(solve(n))\n }\n}\n\nfun solve(n: Int): String {\n for (i in sqrt(n.toDouble()).roundToInt() + 1 downTo 1) {\n if (n % i == 0) {\n return \"$i ${n-i}\"\n }\n }\n return \"$1 ${n-1}\"\n}\n"}, {"source_code": "import kotlin.math.roundToInt\nimport kotlin.math.sqrt\n\nfun readInt() = readLine()!!.toInt()\n\nfun main() {\n repeat(readInt()) {\n val n = readInt()\n println(solve(n))\n }\n}\n\nfun solve(n: Int): String {\n var i = 2\n while (i*i <= n) {\n if (n % i == 0) {\n val d = n / i\n return \"$d ${n-d}\"\n }\n i++\n }\n return \"$1 ${n-1}\"\n}\n"}], "src_uid": "3fd60db24b1873e906d6dee9c2508ac5"} {"nl": {"description": "So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks in the same row are numbered from left to right). Let us describe the hopscotch with numbers that denote the number of squares in the row, staring from the lowest one: 1-1-2-1-2-1-2-(1-2)..., where then the period is repeated (1-2). The coordinate system is defined as shown in the figure. Side of all the squares are equal and have length a.Maria is a very smart and clever girl, and she is concerned with quite serious issues: if she throws a stone into a point with coordinates (x, y), then will she hit some square? If the answer is positive, you are also required to determine the number of the square.It is believed that the stone has fallen into the square if it is located strictly inside it. In other words a stone that has fallen on the square border is not considered a to hit a square.", "input_spec": "The only input line contains three integers: a, x, y, where a (1 ≤ a ≤ 100) is the side of the square, x and y ( - 106 ≤ x ≤ 106, 0 ≤ y ≤ 106) are coordinates of the stone.", "output_spec": "Print the number of the square, inside which the stone fell. If the stone is on a border of some stone or outside the court, print \"-1\" without the quotes.", "sample_inputs": ["1 0 0", "3 1 1", "3 0 10", "3 0 7", "3 4 0"], "sample_outputs": ["-1", "1", "5", "-1", "-1"], "notes": null}, "positive_code": [{"source_code": "import java.util.*\nimport kotlin.system.exitProcess\nimport kotlin.math.*\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun exit() : Nothing = exitProcess(0)\n\ninline fun > min(x : T, y : T): T{\n if(x < y){return x;}\n else{return y;}\n}\n\ninline fun > max(x : T, y : T): T{\n if(x > y){return x;}\n else{return y;}\n}\n\nfun getid(row : Int): Int{\n val kek = (row - 1)/2;\n return 2 + 3 * kek;\n}\n\nfun main(){\n var (a, x, y) = readInts();\n a = a * 2;\n x = x * 2;\n y = y * 2;\n if(y%a == 0){\n println(-1);\n return;\n }\n val row = y/a;\n if(row <= 1){\n if(abs(x) >= a/2){println(-1);}\n else{println(row + 1);}\n return;\n }\n if(row%2 == 0){\n if(x != 0 && abs(x) < a){\n if(x < 0)println(getid(row - 1) + 1);\n else println(getid(row - 1) + 2);\n }\n else{println(-1);}\n }\n else{\n if(abs(x) < a/2){println(getid(row));}\n else{println(-1);}\n }\n}\n"}], "negative_code": [], "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02"} {"nl": {"description": "You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.", "input_spec": "The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between $$$-100$$$ and $$$100$$$.", "output_spec": "Print \"Yes\" if squares intersect, otherwise print \"No\". You can print each letter in any case (upper or lower).", "sample_inputs": ["0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1", "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1", "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteIn the first example the second square lies entirely within the first square, so they do intersect.In the second sample squares do not have any points in common.Here are images corresponding to the samples: "}, "positive_code": [{"source_code": "import org.w3c.dom.css.Rect\nimport java.awt.Rectangle\nimport java.awt.geom.Rectangle2D\nimport java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun pos(x1: Int, y1: Int, x2: Int, y2: Int, x3: Int, y3: Int): Boolean {\n return (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1) > 0\n}\n\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n val rect1 = Array(4) { Pair(scanner.nextInt(), scanner.nextInt()) }\n val rect2 = Array(4) { Pair(scanner.nextInt(), scanner.nextInt()) }\n var flag = false\n val positive = pos(rect1[0].first, rect1[0].second, rect1[1].first,\n rect1[1].second, rect2[0].first, rect2[0].second)\n for (i in 0..3) {\n for (j in 0..3) {\n if (pos(rect1[i].first, rect1[i].second, rect1[(i + 1) % 4].first, rect1[(i + 1) % 4].second,\n rect2[j].first, rect2[j].second) != positive) {\n flag = true\n break\n }\n }\n }\n if (!flag) {\n println(\"YES\")\n return\n }\n flag = false\n val positive1 = pos(rect2[0].first, rect2[0].second, rect2[1].first,\n rect2[1].second, rect1[0].first, rect1[0].second)\n for (i in 0..3) {\n for (j in 0..3) {\n if (pos(rect2[i].first, rect2[i].second, rect2[(i + 1) % 4].first, rect2[(i + 1) % 4].second,\n rect1[j].first, rect1[j].second) != positive1) {\n flag = true\n break\n }\n }\n }\n if (!flag) {\n println(\"YES\")\n return\n }\n for (i in 0..3) {\n if (rect1[i].second == rect1[(i + 1) % 4].second) {\n for (j in 0..3) {\n if (cross1(rect1[i].first, rect1[(i + 1) % 4].first, rect1[i].second,\n rect2[j].first, rect2[j].second, rect2[(j + 1) % 4].first, rect2[(j + 1) % 4].second)) {\n println(\"YES\")\n return\n }\n }\n }\n else {\n for (j in 0..3) {\n if (cross2(rect1[i].second, rect1[(i + 1) % 4].second, rect1[i].first,\n rect2[j].first, rect2[j].second, rect2[(j + 1) % 4].first, rect2[(j + 1) % 4].second)) {\n println(\"YES\")\n return\n }\n }\n }\n }\n println(\"NO\")\n}\n\nfun cross1(x1: Int, x2: Int, y: Int, x3: Int, y3: Int, x4: Int, y4: Int): Boolean {\n val a = (y4 - y3) / (x4 - x3)\n val b = y3 - a * x3\n return (((y - b) / a) in min(x1, x2)..max(x1, x2)) && (((y - b) / a) in min(x3, x4)..max(x3, x4))\n}\n\nfun cross2(y1: Int, y2: Int, x: Int, x3: Int, y3: Int, x4: Int, y4: Int): Boolean {\n val a = (y4 - y3).toDouble() / (x4 - x3)\n val b = y3 - a * x3\n return (a * x + b) in min(y1, y2)..max(y1, y2) && (a * x + b) in min(y3, y4)..max(y3, y4)\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\n//class Pair(var a: Int, var b: Int): Comparable {\n// override fun compareTo(other: Pair): Int {\n// return b - a - other.b + other.a\n// }\n//}"}, {"source_code": "import kotlin.math.*\n\nfun main(args: Array) {\n val a = readLine()!!.splitToIntArray().toRect()\n val b = readLine()!!.splitToIntArray().toRect()\n val h = (b.x1 - b.x0) / 2\n val s0 = b.x1 + b.y0 - h\n val s1 = b.x1 + b.y0 + h\n val d0 = b.x0 - b.y0 - h\n val d1 = b.x0 - b.y0 + h\n for (x in a.x0..a.x1) {\n for (y in a.y0..a.y1) {\n if ((x + y) in s0..s1 && (x - y) in d0..d1) {\n println(\"YES\")\n return\n }\n }\n }\n println(\"NO\")\n}\n\nfun IntArray.toRect(): Rect {\n var x0 = Int.MAX_VALUE\n var x1 = Int.MIN_VALUE\n var y0 = Int.MAX_VALUE\n var y1 = Int.MIN_VALUE\n for (i in 0..3) {\n x0 = min(get(2 * i), x0)\n x1 = max(get(2 * i), x1)\n y0 = min(get(2 * i + 1), y0)\n y1 = max(get(2 * i + 1), y1)\n }\n return Rect(x0, x1, y0, y1)\n}\n\nclass Rect(val x0: Int, val x1: Int, val y0: Int, val y1: Int)\n\nprivate fun String.splitToIntArray(): IntArray {\n val n = length\n if (n == 0) return IntArray(0) // EMPTY\n var res = IntArray(4)\n var m = 0\n var i = 0\n while (true) {\n var cur = 0\n var neg = false\n var c = get(i) // expecting number, IOOB if there is no number\n if (c == '-') {\n neg = true\n i++\n c = get(i) // expecting number, IOOB if there is no number\n }\n while (true) {\n val d = c.toInt() - '0'.toInt()\n require(d >= 0 && d <= 9) { \"Unexpected character '$c' at $i\" }\n require(cur >= Integer.MIN_VALUE / 10) { \"Overflow at $i\" }\n cur = cur * 10 - d\n require(cur <= 0) { \"Overflow at $i\" }\n i++\n if (i >= n) break\n c = get(i)\n if (c == ' ') break\n }\n if (m >= res.size) res = res.copyOf(res.size * 2)\n res[m++] = if (neg) cur else (-cur).also { require(it >= 0) { \"Overflow at $i\" } }\n if (i >= n) break\n i++\n }\n if (m < res.size) res = res.copyOf(m)\n return res\n}"}], "negative_code": [], "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a"} {"nl": {"description": "Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.", "input_spec": "A single line contains integer n (1 ≤ n ≤ 2000) — the number of buttons the lock has.", "output_spec": "In a single line print the number of times Manao has to push a button in the worst-case scenario.", "sample_inputs": ["2", "3"], "sample_outputs": ["3", "7"], "notes": "NoteConsider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes."}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n }\n\n var tok = StringTokenizer(\"\")\n\n fun close() { rd.close(); wr.close() }\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun readToken(): String {\n while (!tok.hasMoreTokens()) tok = StringTokenizer(rd.readLine())\n return tok.nextToken()\n }\n fun readInt() = readToken().toInt()\n fun readLong() = readToken().toLong()\n fun readLine() : String {\n tok = StringTokenizer(\"\")\n return rd.readLine()\n }\n}\n\nfun main(args: Array) {\n Thread({ val io = ProblemIO.console(); solve(io) ; io.close() }).start()\n}\n\nfun solve(io: ProblemIO) {\n val n = io.readInt()\n val bad = IntArray(n + 1)\n val good = IntArray(n + 1)\n bad[1] = 0\n good[1] = 1\n for (i in 2 .. n) {\n bad[i] = i - 1 + bad[i - 1]\n good[i] = 1 + bad[i - 1] + good[i - 1]\n }\n io.println(bad[n] + good[n])\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val k = r.readLine()!!.toInt()\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }.sortedDescending()\n val ans = k+(1..k-1).fold(0L){acc, i -> acc + i*(k-i)}\n println(ans)\n}"}, {"source_code": "fun main(){\n var n = readLine()!!.toInt()\n var i=2\n var ans=n\n while (n-- > 1){\n ans+= (n-1)*i +1\n i++\n }\n println(ans)\n}"}, {"source_code": "fun main() {\n val input = readLine()!!.toInt()\n var level = 1\n var presses = input\n for (i in input downTo 1) {\n val mistakes = i - 1\n presses += level++ * mistakes\n }\n println(presses)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextLong()\n print((n * n * (n - 1)) / 2 - (n * (n - 1) * (2 * n - 1)) / 6 + n)\n}"}, {"source_code": "fun main(args: Array) {\n val n= readLine()!!.toLong()\n val result=(n-1)*n*(n+1)/6+n\n println(result)\n}"}, {"source_code": "fun main() {\n var n = readLine()!!.toInt()\n var ans: Int = 0\n var i: Int = 1\n while (n >= 1) {\n ans += (n * i) - (i - 1)\n n--\n i++\n }\n print(ans)\n}\n"}, {"source_code": "fun main() {\n var n = readLine()!!.toInt()\n var ans: Int = 0\n var i: Int = 1\n while (n >= 1) {\n ans += (n * i) - (i - 1)\n n--\n i++\n }\n print(ans)\n}\n"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n var n = readInt() + 1\n var selecting = 1\n var result = 0\n while (--n > 0) {\n result += 1 + selecting * n - selecting\n selecting++\n }\n print(result)\n}"}, {"source_code": "fun main(args : Array) {\n val n_nullable_str = readLine()\n if (n_nullable_str == null) {\n // Do nothing ...\n } else {\n val n_str = n_nullable_str\n val n = n_str.toLong()\n val t_1 = (n * n * (n + 1)) / 2\n val t_2 = (n * (n + 1) * ((2 * n) + 1)) / 6\n val t_3 = n\n val result = t_1 - t_2 + t_3\n println(\"${result}\")\n }\n}"}, {"source_code": "fun main(args: Array) {\n readLine()!!.toInt().let { println((1..it).sumBy { it + (1..it-2).sumBy { it }}) }\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n var answer = 0\n var buttons = n\n for (i in 1..n) {\n val errors = buttons - 1\n val correct = 1\n val totalPresses = errors * i + correct\n answer += totalPresses\n buttons--\n }\n\n println(answer)\n}"}], "negative_code": [{"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n print((n * n * (n - 1)) / 2 - (n * (n - 1) * (2 * n - 1)) / 6 + n)\n}"}, {"source_code": "fun main(args: Array) {\n val n= readLine()!!.toInt()\n val result=(n-1)*(n*(n+1)/6)+n\n println(result)\n}"}, {"source_code": "fun main(args: Array) {\n val n= readLine()!!.toInt()\n val result=(n*n-1*n)*(n+1)/6+n\n println(result)\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n var ans = 1\n for (i in 2..n){\n ans*=i\n }\n print(ans+1)\n}\n"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n print((n*(n-1))+1)\n}\n"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n println(n * (n + 1) / 2)\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n println(n * (n + 1) / 2 + n -2)\n}"}], "src_uid": "6df251ac8bf27427a24bc23d64cb9884"} {"nl": {"description": "You have n problems. You have estimated the difficulty of the i-th one as integer ci. Now you want to prepare a problemset for a contest, using some of the problems you've made.A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.Find the number of ways to choose a problemset for the contest.", "input_spec": "The first line contains four integers n, l, r, x (1 ≤ n ≤ 15, 1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ 106) — the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 106) — the difficulty of each problem.", "output_spec": "Print the number of ways to choose a suitable problemset for the contest. ", "sample_inputs": ["3 5 6 1\n1 2 3", "4 40 50 10\n10 20 30 25", "5 25 35 10\n10 10 20 10 20"], "sample_outputs": ["2", "2", "6"], "notes": "NoteIn the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.In the second example, two sets of problems are suitable — the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable."}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n val solver = Solver(System.`in`, System.out)\n solver.solve()\n solver.clear()\n}\n\nclass Solver(input: InputStream, output: OutputStream) {\n\n companion object {\n private const val MAX_N = (1e6 + 10).toInt()\n private const val INF = (1e9 + 7).toInt()\n private const val MOD = (1e9 + 7).toInt()\n private const val INF_F = 1e-6\n }\n\n private val reader = Reader(input)\n private val writer = Writer(output)\n\n fun solve() {\n val n = reader.nextInt()\n val l = reader.nextInt()\n val r = reader.nextInt()\n val x = reader.nextInt()\n val c = reader.nextArrayInt(n).sorted()\n\n val bins = mutableListOf()\n calcBin(bins, \"\", n)\n bins.sort()\n\n var ans = 0\n bins.forEach { bin ->\n if (bin.count { it == '1' } < 2) {\n return@forEach\n }\n val i = bin.indexOfFirst { it == '1' }\n val j = bin.indexOfLast { it == '1' }\n if (c[j] - c[i] < x) {\n return@forEach\n }\n val s = sum(c, i, j, bin)\n if (s in l..r) {\n ans++\n }\n }\n writer.println(ans)\n }\n\n private fun calcBin(bins: MutableList, s: String, n: Int) {\n if (s.length == n) {\n bins.add(s)\n return\n }\n calcBin(bins, s + \"1\", n)\n calcBin(bins, s + \"0\", n)\n }\n\n private fun sum(c: List, i: Int, j: Int, bin: String): Int {\n var ans = 0\n for (x in i..j) {\n if (bin[x] == '1') {\n ans += c[x]\n }\n }\n return ans\n }\n\n fun clear() {\n writer.close()\n }\n}\n\nprivate fun IntArray.gcd(): Int {\n var g = first()\n forEach { g = gcd(g, it) }\n return g\n}\n\nprivate fun LongArray.gcd(): Long {\n var g = first()\n forEach { g = gcd(g, it) }\n return g\n}\n\nprivate fun gcd(a: Int, b: Int): Int {\n return if (b == 0) a else gcd(b, a % b)\n}\n\nprivate fun gcd(a: Long, b: Long): Long {\n return if (b == 0L) a else gcd(b, a % b)\n}\n\nclass Reader(input: InputStream) {\n private val reader = BufferedReader(InputStreamReader(BufferedInputStream(input)), 32768)\n private var tokenizer: StringTokenizer? = null\n\n fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt() = next().toInt()\n\n fun nextLong() = next().toLong()\n\n fun nextStringArray(count: Int): Array {\n return Array(count) { next() }\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n\n fun nextIntPair(): Pair {\n val x = nextInt()\n val y = nextInt()\n return x to y\n }\n}\n\nclass Writer(output: OutputStream) {\n private val writer = PrintWriter(BufferedOutputStream(output))\n\n fun print(t: T) = writer.print(t)\n fun println() = writer.println()\n fun println(t: T) = writer.println(t)\n\n fun printBooleanArray(array: BooleanArray) = printIntArray(array.map { if (it) 1 else 0 }.toIntArray())\n fun printIntArray(array: IntArray) = array.joinToString(\" \").let(writer::println)\n fun printLongArray(array: LongArray) = array.joinToString(\" \").let(writer::println)\n fun printCharArray(array: CharArray) = array.joinToString(\"\").let(writer::println)\n\n fun close() = writer.close()\n fun flush() = writer.flush()\n}"}, {"source_code": "import kotlin.math.pow\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numProblems, minTotalDifficult, maxTotalDifficult, minbiggerDiff) = readInts()\n val difficulties = readInts().sorted()\n var sol = 0\n for (candidate in 1 until 2.0.pow(numProblems).toInt()) {\n val bitMask = candidate.toString(radix = 2)\n var min: Int? = null\n var max: Int? = null\n var sum = 0L\n for (pos in bitMask.indices) {\n val realPos = numProblems - bitMask.length + pos\n if (bitMask[pos] == '1') {\n if (min == null) min = difficulties[realPos]\n max = difficulties[realPos]\n sum += difficulties[realPos]\n }\n }\n if (sum in minTotalDifficult..maxTotalDifficult && max!! - min!! >= minbiggerDiff) sol++\n }\n print(sol)\n}"}], "negative_code": [], "src_uid": "0d43104a0de924cdcf8e4aced5aa825d"} {"nl": {"description": "Your friend has n cards.You know that each card has a lowercase English letter on one side and a digit on the other.Currently, your friend has laid out the cards on a table so only one side of each card is visible.You would like to know if the following statement is true for cards that your friend owns: \"If a card has a vowel on one side, then it has an even digit on the other side.\" More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'.For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.", "input_spec": "The first and only line of input will contain a string s (1 ≤ |s| ≤ 50), denoting the sides of the cards that you can see on the table currently. Each character of s is either a lowercase English letter or a digit.", "output_spec": "Print a single integer, the minimum number of cards you must turn over to verify your claim.", "sample_inputs": ["ee", "z", "0ay1"], "sample_outputs": ["2", "0", "2"], "notes": "NoteIn the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.In the third sample, we need to flip the second and fourth cards."}, "positive_code": [{"source_code": "fun main(args: Array) {\n var a = readLine()!!\n var ans = 0\n for (c in a){\n if (c.isDigit()){\n var cur = ((c.toInt())%2 == 1)\n if(cur){\n ans+=1\n }\n }else {\n if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){\n ans += 1\n }\n }\n }\n println(ans)\n\n}\n"}, {"source_code": "fun main() {\n //println((4 or 6)xor(4 or 5))\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n val list = listOf(\"a\", \"e\", \"i\", \"o\", \"u\", \"1\", \"3\", \"5\", \"7\", \"9\")\n val v = r.readLine()!!.split(\"\").filter { it.isNotEmpty() }.count { it in list }\n println(v)\n}"}, {"source_code": "fun main(args: Array) {\n val a = readLine()!!.trim()\n val voewels = arrayOf('a','e','i','o','u')\n val odds = arrayOf('1','3','5','7','9')\n val r = a.count { it in voewels || it in odds }\n println(r)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val vowels = listOf('a', 'e', 'i', 'o', 'u')\n val digits = \"1234567890\".toList()\n val s = Scanner(System.`in`)\n with(s) {\n var total = 0\n nextLine()\n .forEach {\n when (it) {\n in vowels -> {\n total++\n }\n\n in digits -> {\n if (it.toInt() % 2 == 1) {\n total++\n }\n }\n }\n }\n println(total)\n }\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\n\nprivate val reader = BufferedReader(InputStreamReader(System.`in`))\nprivate val out = PrintWriter(System.out)\nprivate var st = StringTokenizer(\"\")\n\nfun next(): String {\n while (!st.hasMoreTokens())\n st = StringTokenizer(reader.readLine())\n return st.nextToken()\n}\n\nfun ni() = next().toInt()\nfun nl() = next().toLong()\nfun nd() = next().toDouble()\nfun print(obj: Any) = out.print(obj)\nfun close() = out.close()\n\nfun main(args: Array) {\n val text = next()\n val v = setOf('a', 'e', 'i', 'o', 'u')\n val range = 1..10 step 2\n val odd = range.flatMap { n -> listOf(text.filter { (it.toInt()-'0'.toInt()) == n }.count()) }.reduce({ x, y -> x + y });\n print(text.filter { it in v }.count()+odd)\n close()\n}"}, {"source_code": "fun main(args: Array) = with(java.util.Scanner(System.`in`)) {\n var s = readLine()!!\n var (res, entahapa) = s.partition { (it.isDigit() && it.toInt()%2==1) || it == 'a' || it == 'u' || it == 'o' || it == 'i' || it == 'e' }\n println(res.count())\n}"}, {"source_code": "fun main() = println(readLine()!!.count { it in \"aeiou13579\" })"}, {"source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val res = next().toCharArray()\n .filter { c -> arrayListOf('a', 'e', 'i', 'o', 'u', '1', '3', '5', '7', '9')\n .filter { it == c }.any() }.size\n print(res)\n}\n\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val arr = next().toCharArray().filter { it.vowel() }\n print(\"${arr.size}\")\n}\n\nfun Char.vowel(): Boolean {\n val v = arrayListOf('a', 'e', 'i', 'o', 'u', '1', '3', '5', '7', '9')\n return v.filter { it == this }.any()\n}\n\n\n\n"}, {"source_code": "fun main() {\n print(readLine()!!.count { c -> c in setOf('a', 'e', 'i', 'o', 'u', '1', '3', '5', '7', '9') })\n}"}, {"source_code": "import kotlin.*\n\nfun main(args: Array) {\n var vowelsAndEvens = setOf(\n 'a', 'o', 'e', 'u', 'i',\n '1', '3', '5', '7', '9'\n )\n\n var string = readLine() ?: \"\"\n println(string.count { it in vowelsAndEvens })\n\n}"}, {"source_code": "fun parse_int(): MutableList {\n return readLine()!!.split(' ').map {x: String -> x.toInt()}.toMutableList()\n}\n\nfun main(args: Array) {\n val inp = readLine()!!.trim()\n var odds = 0\n var vowels = 0\n\n for (c in inp) {\n if (c.isDigit()) {\n odds += c.toInt() % 2\n } else {\n if (c in \"aeiou\") vowels += 1\n }\n }\n\n println(odds + vowels)\n\n\n}\n\n"}], "negative_code": [{"source_code": "fun main(args: Array) {\n val a = readLine()!!.trim()\n val voewels = arrayOf('a','e','i','o','u')\n val evens = arrayOf('0','2','4','6','8')\n val r = a.count { it in voewels || it in evens }\n println(r)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val vowels = listOf('a', 'e', 'i', 'o', 'u')\n val digits = \"1234567890\".toList()\n val s = Scanner(System.`in`)\n with(s) {\n var total = 0\n nextLine()\n .forEach {\n when (it) {\n in vowels -> {\n total++\n }\n\n in digits -> {\n if (it.toInt() % 2 == 0) {\n total++\n }\n }\n }\n }\n println(total)\n }\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\n\nprivate val reader = BufferedReader(InputStreamReader(System.`in`))\nprivate val out = PrintWriter(System.out)\nprivate var st = StringTokenizer(\"\")\n\nfun next(): String {\n while (!st.hasMoreTokens())\n st = StringTokenizer(reader.readLine())\n return st.nextToken()\n}\n\nfun ni() = next().toInt()\nfun nl() = next().toLong()\nfun nd() = next().toDouble()\nfun print(obj: Any) = out.print(obj)\nfun close() = out.close()\n\nfun main(args: Array) {\n val text = next()\n val v = setOf('a', 'e', 'i', 'o', 'u', '0', '2', '4', '6', '8')\n print(text.filter { it in v }.count())\n close()\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\n\nprivate val reader = BufferedReader(InputStreamReader(System.`in`))\nprivate val out = PrintWriter(System.out)\nprivate var st = StringTokenizer(\"\")\n\nfun next(): String {\n while (!st.hasMoreTokens())\n st = StringTokenizer(reader.readLine())\n return st.nextToken()\n}\n\nfun ni() = next().toInt()\nfun nl() = next().toLong()\nfun nd() = next().toDouble()\nfun print(obj: Any) = out.print(obj)\nfun close() = out.close()\n\nfun main(args: Array) {\n val text = next()\n val v = setOf('a', 'e', 'i', 'o', 'u', '0', '2', '4', '6', '8')\n print(text.toSet().filter { it in v }.count())\n close()\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\n\nprivate val reader = BufferedReader(InputStreamReader(System.`in`))\nprivate val out = PrintWriter(System.out)\nprivate var st = StringTokenizer(\"\")\n\nfun next(): String {\n while (!st.hasMoreTokens())\n st = StringTokenizer(reader.readLine())\n return st.nextToken()\n}\n\nfun ni() = next().toInt()\nfun nl() = next().toLong()\nfun nd() = next().toDouble()\nfun print(obj: Any) = out.print(obj)\nfun close() = out.close()\n\nfun main(args: Array) {\n val text = next()\n val v = setOf('a', 'e', 'i', 'o', 'u')\n var range = 1..10 step 2\n print(text.filter { it in v }.count()+range.filter { (it+'0'.toInt()).toChar() in text.toSet() }.count())\n close()\n}"}, {"source_code": "fun main(args: Array) = with(java.util.Scanner(System.`in`)) {\n var s = readLine()!!\n var (res, entahapa) = s.partition { (it.isDigit() && it.toInt()%2==0) || it == 'a' || it == 'u' || it == 'o' || it == 'i' || it == 'e' }\n println(res.count())\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val arr = next().toCharArray().filter { it.vowel() }\n print(\"${arr.size}\")\n}\n\nfun Char.vowel(): Boolean = this == 'a' || this == 'e' || this == 'i' || this == 'o' || this == 'u' || this == 'y'\n\n\n\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val arr = next().toCharArray().filter { it.vowel() }\n print(\"${arr.size}\")\n}\n\nfun Char.vowel(): Boolean {\n val v = arrayListOf('a', 'e', 'i', 'o', 'u', '0', '2', '4', '6', '8')\n return v.filter { it == this }.any()\n}\n\n\n\n"}, {"source_code": "import kotlin.*\n\nfun main(args: Array) {\n var vowelsAndEvens = setOf(\n 'a', 'o', 'e', 'u', 'i',\n '0', '2', '4', '6', '8')\n\n var string = readLine() ?: \"\"\n println(string.count { it in vowelsAndEvens })\n\n}"}], "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223"} {"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": "import java.util.*\n\nfun main() {\n val sc = Scanner(System.`in`)\n var set = HashSet()\n for(i in 0..3)\n set.add(sc.nextInt())\n print(4 - set.size)\n}"}, {"source_code": "fun main() = (4 - hashSetOf().apply { addAll(readLine()!!.split(\" \")) }.size).run(::println)"}, {"source_code": "\n fun main(args: Array) {\n readLine()!!.split(\" \").map { it.toInt()}.let {\n println(it.size - it.toSet().size)}\n\n }\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val input = InputReader(inputStream)\n val output = PrintWriter(outputStream)\n val solver = Task()\n solver.solve(input, output)\n output.close()\n}\n\nprivate class Task {\n fun solve(input: InputReader, output: PrintWriter) {\n readLine()!!.split(\" \").map { it.toInt() }.toSet().count().let { output.println(4 - it) }\n }\n}\n\n\nprivate class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n\n operator fun next(): String {\n while (tokenizer == null || tokenizer?.hasMoreTokens()?.not() == true) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return next().toInt()\n }\n\n}"}, {"source_code": "/* https://codeforces.com/problemset/problem/228/A */\n\nfun main() {\n println(4 - readLine()!!.split(\" \").toSet().size)\n}"}, {"source_code": "fun main() {\n val count = readLine()!!.split(\" \")\n .map(Integer::parseInt)\n .distinct()\n .count()\n\n println(4 - count)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val shoes = Scanner(System.`in`).nextLine().split(\" \").map{it.toInt()}\n val distinct = HashSet()\n var ans = 0\n\n for(i in shoes.indices) {\n if(distinct.contains(shoes[i])) {\n ans++\n }\n else {\n distinct.add(shoes[i])\n }\n }\n\n println(ans)\n}"}, {"source_code": "fun main(args: Array) {\n val shoes = HashSet(readLine()?.split(\" \")?.map{it.toInt()})\n println(4 - shoes.size)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val shoes = Scanner(System.`in`).nextLine().split(\" \").map{it.toInt()}\n val distinct = HashSet()\n\n for(i in shoes.indices) {\n distinct.add(shoes[i])\n }\n\n println(4 - distinct.size)\n}"}, {"source_code": "\nfun main(){\n var set = readLine()!!.split(\" \").toSet()\n println(4 - set.size)\n}\n"}, {"source_code": "fun main(args: Array) {\n val a = readInts().toSet().size\n print(\"${4 - a}\")\n}\n\nprivate fun readInts() = readLine()!!.split(\" \").map { it.toInt() }"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val s = br.readLine().split(\" \").map { it.toInt() }\n println(s.size - s.toSet().size)\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val reader = Scanner(System.`in`)\n val t = reader.nextLine().split(\" \").toSet()\n println(4-t.size)\n}"}, {"source_code": "fun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\n\n\nfun findMinNumberOfShoes(): Int {\n\n val colorsHas = readInts().toSet()\n return 4 - colorsHas.size\n}\n\n\nfun main() {\n print(findMinNumberOfShoes())\n}\n"}, {"source_code": "fun main(args: Array) {\n val p = readLine()!!.split(' ').map { it.toInt() }\n println(4 - p.toSet().size)\n}"}, {"source_code": "import java.util.*\n\nfun main(){\n\n val scan = Scanner(System.`in`)\n val arr = Array(4){ _ -> scan.nextInt()}\n var count = 1\n\n for (i in 0 until 3){\n var isUnique = true\n\n for (j in i+1 until 4){\n if (arr[i] == arr[j]){\n isUnique = false\n break\n }\n }\n\n if (isUnique) count++\n }\n\n print(4-count)\n\n\n}"}, {"source_code": "fun main() {\n var colors : Set = readLine()!!.split(' ').map { it.toInt() }.toSet();\n println(4 - colors.size)\n}"}, {"source_code": "fun main() {\n println(4 - readLine()!!.split(\" \").map { it.toInt() }.toSet().size)\n}"}, {"source_code": "import java.lang.AssertionError\nimport java.util.*\n \nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n \nprivate fun myAssert(x: Boolean) {\n if (!x) {\n throw AssertionError()\n }\n}\n\nfun main(args: Array) {\n// var s = Scanner(System.`in`)\n var lst = readInts().sorted()\n var ans = 0\n for (i in 1 until lst.size) {\n if (lst[i - 1] == lst[i])\n ans++\n }\n println(ans)\n}\n"}, {"source_code": "fun main() {\n println(4 - readLine()!!.split(\" \").toMutableSet().size)\n}"}, {"source_code": "import kotlin.math.abs\n\n\nfun main() {\n val read = readLine()!!.split(\" \").map { it.toInt() }\n val distinct = read.distinct()\n print(abs(distinct.size-read.size))\n}\n\n"}, {"source_code": "fun main(args: Array) {\n val S: MutableSet = mutableSetOf()\n readLine()!!.split(' ').map(String::toInt).forEach {\n S.add(it)\n }\n val ans = 4 - S.size.toInt()\n print(\"$ans\\n\")\n}\n"}, {"source_code": "fun main(args: Array) {\n val S: MutableSet = mutableSetOf()\n readLine()!!.split(' ').map(String::toInt).forEach {\n S.add(it)\n }\n val ans = 4 - S.size.toInt()\n print(\"$ans\\n\")\n}\n"}, {"source_code": "fun main(args: Array) {\n println(4 - readLine()!!.split(' ').toSet().size)\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n\nfun main() {\n val shoes = readInts()\n\n println(4 - shoes.distinct().size)\n}\n"}, {"source_code": "fun main(args: Array) {\n println(4 - readLine()!!.split(' ').map { it.toInt() }.toSet().size)\n}"}, {"source_code": "/* template start */\n// input\nprivate fun readString() = readLine()!!\nprivate fun readStrings() = readString().split(\" \")\nprivate fun readInt() = readString().toInt()\nprivate fun readDigits() = readString().map { it - '0' }\nprivate fun readInts() = readStrings().map { it.toInt() }\nprivate fun readLongs() = readStrings().map { it.toLong() }\n\n// output\nprivate fun T.print(map: (T) -> String = { it.toString() }) = println(map(this))\nprivate fun Iterable.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)\nprivate fun Array.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)\nprivate fun IntArray.print(sep: String? = null, map: ((Int) -> String)? = null) = asSequence().print(sep, map)\nprivate fun Sequence.print(sep: String? = null, map: ((T) -> String)? = null) =\n println(joinToString(sep ?: \"\", transform = map ?: { it.toString() }))\n\n// others\nprivate val Int.isEven: Boolean get() = this % 2 == 0\nprivate val Int.isOdd: Boolean get() = !this.isEven\nprivate fun queries(block: (Int) -> Unit) = repeat(readInt(), block)\n\n/* template end */\n\nfun main() {\n val n = readInts()\n println(n.size - n.toSet().size)\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n var tok = StringTokenizer(\"\")\n\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n fun files(inputFilename: String, outputFilename: String) =\n ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))\n }\n\n fun readToken(): String {\n while (!tok.hasMoreTokens()) {\n tok = StringTokenizer(rd.readLine())\n }\n return tok.nextToken()\n }\n\n fun readInt(): Int = readToken().toInt()\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun close() {\n rd.close()\n wr.close()\n }\n}\n\nfun solve() {\n val io = ProblemIO.console()\n val a = IntArray(4)\n for (i in a.indices) {\n a[i] = io.readInt()\n }\n val res = 4 - a.toSet().size\n io.println(res)\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n"}, {"source_code": "fun main()\n{\n val has = readLine()!!.split(\" \").map { it.toInt() }.toSet().size\n println( 4 - has)\n\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n \n val l = r.readLine()!!.split(\" \").map { it.toInt() }.toSet()\n println(4-l.size)\n \n}"}, {"source_code": "import java.util.*\nimport java.math.*\nimport kotlin.math.*\n\nfun readLn()=readLine()!!\nfun readInt()=readLn().toInt()\nfun readInts()=readLn().split(\" \").map{it.toInt()}\nfun readLong()=readLn().toLong()\nfun readLongs()=readLn().split(\" \").map{it.toLong()}\n\nval out=mutableListOf()\nfun printLine(s:String){out.add(s)}\nfun output(){println(out.joinToString(\"\\n\"))}\n\nfun main(){\n var col=readInts().toIntArray()\n col.sort()\n var ans=0\n for(i in 1 until 4)if(col[i]==col[i-1])ans++\n printLine(\"$ans\")\n output()\n}"}, {"source_code": "fun main() {\n val arr = readLine()!!.split(\" \").distinct()\n print(4 - arr.size)\n}"}, {"source_code": "\nfun main() {\n val set = HashSet()\n val arr = readLine()?.split(\" \")?.forEach {\n set.add(it.toInt())\n }\n\n print(4 - set.size)\n\n}\n\n"}], "negative_code": [], "src_uid": "38c4864937e57b35d3cce272f655e20f"} {"nl": {"description": "Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium. The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.", "input_spec": "The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol \"|\" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale. The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet. It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.", "output_spec": "If you cannot put all the weights on the scales so that the scales were in equilibrium, print string \"Impossible\". Otherwise, print the description of the resulting scales, copy the format of the input. If there are multiple answers, print any of them.", "sample_inputs": ["AC|T\nL", "|ABC\nXYZ", "W|T\nF", "ABC|\nD"], "sample_outputs": ["AC|TL", "XYZ|ABC", "Impossible", "Impossible"], "notes": null}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.lang.StringBuilder\nimport kotlin.math.abs\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val scales = br.readLine().split(\"|\")\n val notUsed = br.readLine()\n val left = scales[0].length\n val right = scales[1].length\n val missing = abs(left - right)\n if (notUsed.length >= missing && (notUsed.length - missing) % 2 == 0) {\n val useToComplete = notUsed.substring(0 until missing)\n val rest = notUsed.substring(missing)\n val rest1 = rest.substring(0 until rest.length/2)\n val rest2 = rest.substring(rest.length/2)\n val newLeft = StringBuilder(scales[0])\n val newRight = StringBuilder(scales[1])\n if (left < right) {\n newLeft.append(useToComplete + rest1)\n newRight.append(rest2)\n } else {\n newLeft.append(rest1)\n newRight.append(useToComplete + rest2)\n }\n println(\"$newLeft|$newRight\")\n } else {\n println(\"Impossible\")\n }\n}"}, {"source_code": "fun main() {\n val scale = readLine()!!\n val middle = scale.indexOf('|')\n val left = scale.substring(0, middle)\n val right = scale.substring(middle + 1)\n val (smaller, bigger) = if (left.length <= right.length) left to right else right to left\n val other = readLine()!!\n if ((smaller.length + bigger.length + other.length) and (1) == 1) return print(\"Impossible\")\n val half = (smaller.length + bigger.length + other.length) / 2\n if (smaller.length + other.length < half) return print(\"Impossible\")\n val newSmaller = smaller + other.substring(0, half - smaller.length)\n val newBigger = bigger + other.substring(half - smaller.length)\n print(if (left.length <= right.length) \"$newSmaller|$newBigger\" else \"$newBigger|$newSmaller\")\n}"}], "negative_code": [], "src_uid": "917f173b8523ddd38925238e5d2089b9"} {"nl": {"description": "Polycarp has $$$n$$$ coins, the value of the $$$i$$$-th coin is $$$a_i$$$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.For example, if Polycarp has got six coins represented as an array $$$a = [1, 2, 4, 3, 3, 2]$$$, he can distribute the coins into two pockets as follows: $$$[1, 2, 3], [2, 3, 4]$$$.Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.", "input_spec": "The first line of the input contains one integer $$$n$$$ ($$$1 \\le n \\le 100$$$) — the number of coins. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$) — values of coins.", "output_spec": "Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.", "sample_inputs": ["6\n1 2 4 3 3 2", "1\n100"], "sample_outputs": ["2", "1"], "notes": null}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\nfun main(args : Array) {\n Thread { run() }.start()\n}\n\nfun run() {\n\n val scanner = Scanner(System.`in`)\n val arr = IntArray(101)\n val n =scanner.nextInt()\n for (i in 0 until n) {\n val a = scanner.nextInt()\n arr[a]++\n }\n println(arr.max())\n\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\nfun IntArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun LongArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun BooleanArray.print() {\n println(Arrays.toString(this))\n}\nfun nod(a: Long, b: Long): Long {\n var a1 = a\n var b1 = b\n while (a1 != 0L && b1 != 0L) {\n if (a1 < b1)\n b1 %= a1\n else\n a1 %= b1\n }\n return a1 + b1\n}\nfun nok(a: Long, b: Long): Long = a * b / nod(a, b)\nfun min(a: Char, b: Char): Int {\n if (a < b)\n return a.toInt()\n return b.toInt()\n}\nfun max(a: Char, b: Char): Int {\n if (a > b)\n return a.toInt()\n return b.toInt()\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n val costs = Array(101, { 0 })\n for (i in 1..n) {\n costs[sc.nextInt()] += 1\n }\n println(costs.max())\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n\n val n = r.readLine()!!.toInt()\n val v = r.readLine()!!.split(\" \").map { it.toInt() }.groupBy { it }.map { (k, v) -> v.size }.max()\n println(v)\n}"}, {"source_code": "\nimport java.io.*\nimport java.util.*\nimport kotlin.math.max\n\nfun solve() {\n\n val n = nextInt()\n val a = nextArray(n)\n\n var ans = 0\n for (i in 1..100) {\n ans = max(a.count { it == i }, ans)\n }\n\n println(ans)\n}\n\n\n\n\nfun hasNext() : Boolean {\n while (!st.hasMoreTokens()) {\n st = StringTokenizer(input.readLine() ?: return false)\n }\n return true\n}\n\nfun next() = if (hasNext()) st.nextToken()!! else throw RuntimeException(\"No tokens\")\n\nfun nextInt() = next().toInt()\n\nfun nextLong() = next().toLong()\n\nfun nextDouble() = next().toDouble()\n\nfun nextLine() = if (hasNext()) st.nextToken(\"\\n\")!! else throw RuntimeException(\"No tokens\")\n\nfun nextArray(n : Int) = IntArray(n, { nextInt() })\n\nval ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n\nvar input = when(ONLINE_JUDGE) {\n true -> BufferedReader(InputStreamReader(System.`in`), 32768)\n else -> BufferedReader(FileReader(\"in.txt\"))\n}\n\nvar output = when(ONLINE_JUDGE) {\n true -> PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))\n else -> PrintWriter(BufferedWriter(FileWriter(\"out.txt\")))\n}\n\nvar st = StringTokenizer(\"\")\n\nfun main(args: Array) {\n val start = System.currentTimeMillis()\n solve()\n\n output.close()\n input.close()\n\n if (!ONLINE_JUDGE) {\n System.err.println(\"${System.currentTimeMillis() - start} ms\")\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n\n val coinsCount = input.nextLine()\n val coins = input.nextLine().split(\" \").map { it.toInt() }\n val pocketsSet = mutableMapOf()\n\n var max = 0\n\n coins.forEach {\n val coinPrice = (pocketsSet[it] ?: 0) + 1\n\n max = Math.max(max, coinPrice)\n\n pocketsSet[it] = coinPrice\n }\n\n println(max)\n}\n"}, {"source_code": "fun main(arg: Array){\n val coinCount = readLine()!!.toInt()\n val coins = readLine()!!.split(' ').map{it.toInt()}\n\n var map = HashMap()\n for(coin in coins) {\n val count = map[coin] ?: 0\n map[coin] = count + 1 \n // System.out.print(\"${d}\\n\")\n }\n \n \n System.out.print(\"${map.values.max()}\")\n}\n"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val values = readLine()!!.split(' ').map(kotlin.String::toInt)\n\n\n val counts = mutableListOf()\n\n values.forEach {value ->\n counts.add(values.count { it == value })\n }\n\n val max = counts.max()\n\n print(max)\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val values = readLine()!!.split(' ').map(kotlin.String::toInt)\n\n\n val counts = mutableListOf()\n\n values.forEach {value ->\n counts.add(values.count { it == value })\n }\n\n val max = counts.max()\n\n print(max)\n}"}, {"source_code": "/* http://codeforces.com/problemset/problem/1003/A */\n\nfun main() {\n readLine() // skip first line\n val counts = IntArray(101) { 0 }\n val coins = readLine()!!.split(\" \").map { it.toInt() }\n coins.forEach { counts[it] += 1 }\n println(counts.max())\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n var num = readLine()!!.split(' ').map { it.toInt() }.toIntArray()\n var count = Array(100){0}\n for (i in num){\n count[i-1]++\n }\n var max = 0\n for ( i in count )\n max = if (i > max) i else max\n print(max)\n}"}, {"source_code": "import java.lang.Math.max\nimport java.lang.Math.min\nimport java.util.*\n\n\n//TODO: Search reduce...\n/*\n SPREAD operator (*values)\n\n\n* */\nfun main(args: Array) {\n var coin:Int\n var coins = IntArray(101){ _->0}\n val reader = Scanner(System.`in`)\n val numOfCoins = reader.nextInt()\n for (index in 1..numOfCoins) {\n coin = reader.nextInt()\n ++coins[coin]\n }\n val maxPocket = coins.max()\n println(maxPocket)\n}\n\n\n\n\n\n"}, {"source_code": "import java.util.*\nfun main(args:Array){\nval sc = Scanner(System.`in`)\nval n = sc.nextInt()\nval cost = Array(101,{0})\nfor(i in 1..n)\n cost[sc.nextInt()]++\nprintln(cost.max())\n}"}, {"source_code": "import java.util.*\nfun main(args: Array)\n{\n val n = readLine()!!.toInt()\n val coins = readLine()!!.split(' ').map(String::toInt).toIntArray()\n val cnt = Array(100,{i-> coins.count{coin -> coin == i+1}})\n println(cnt.max())\n}"}, {"source_code": "fun main(args: Array)\n{\n val n = readLine()!!.toInt()\n val coins = readLine()!!.split(' ').map(String::toInt).toIntArray()\n val count = Array(100, {i -> coins.count {coin -> coin == i + 1}})\n val ans = count.max()\n println(ans)\n}"}, {"source_code": "fun main(args: Array) {\n if (args.isNotEmpty() && args[0] == \"debug\") {\n System.setIn(object {}.javaClass.getResourceAsStream(\"/input.txt\"))\n }\n\n solve()\n}\n\nfun getIntString() = readLine()!!\n .split(' ')\n .map { Integer.parseInt(it) }\n .toCollection(ArrayList())\n\n\nfun solve() {\n val n = getIntString()[0]\n val coins = getIntString()\n\n val countArr = Array(100) { 0 }\n coins.forEach { countArr[it-1]++ }\n println(countArr.max())\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n readLine()\n val arr = readInts()\n val occs = IntArray(101)\n for (a in arr) occs[a]++\n print(occs.max())\n}"}, {"source_code": "fun readString() = readLine()!!\n\nfun readInt() = readString().toInt()\nfun readLong() = readString().toLong()\n\nfun readIntArray() = readString().split(\" \").map { it.toInt() }\nfun readLongArray() = readString().split(\" \").map { it.toLong() }\n\nfun main() {\n val n = readInt()\n val arr = readIntArray()\n val res = arr.groupingBy {\n it\n }.eachCount().maxBy {\n it.value\n }!!.value\n println(res)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val n = nextInt()\n val c = IntArray(101)\n for (i in 0 until n) {\n c[nextInt()]++;\n }\n print(c.max()!!)\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.max\n\nfun main(args : Array) {\n\n val n : Int = readLine()!!.toInt()\n var map : MutableMap = mutableMapOf()\n val str = readLine()!!.split(\" \")\n\n for(i in 0 until n)\n map[str[i].toInt()] = 0\n\n for(i in 0 until n) {\n val t = map[str[i].toInt()]!!.toInt() + 1\n map[str[i].toInt()] = t\n }\n\n var ans = 0\n for(i in map)\n ans = max(ans, i.value)\n\n println(ans)\n\n}"}, {"source_code": " import java.util.*\n\n\n fun main(args:Array) {\n val sc = Scanner(System.`in`)\n var n = sc.nextInt()\n var coin:Array = Array(100,{0})\n for (i in 0 until n){\n coin[sc.nextInt()-1]++\n }\n\n print(coin.max())\n }\n"}], "negative_code": [{"source_code": "import java.util.*\n\n\nfun main(args:Array) {\n val sc = Scanner(System.`in`)\n var n = sc.nextInt()\n var coin:Array = Array(n,{0})\n for (i in 0 until n){\n coin[i] = sc.nextInt()\n }\n coin.sort()\n var max = 1\n var cons =1\n for (i in 0 until (n-1)){\n if(coin[i] == coin[i+1])\n cons++\n else\n if(cons>max)\n max = cons\n }\n if(cons>max)\n max = cons\n print(max)\n}\n"}, {"source_code": "import java.util.*\n\n\nfun main(args:Array) {\n val sc = Scanner(System.`in`)\n var n = sc.nextInt()\n var coin:Array = Array(n,{0})\n for (i in 0 until n){\n coin[i] = sc.nextInt()\n }\n coin.sort()\n var max = 1\n var cons =0\n for (i in 0 until (n-1)){\n if(coin[i] == coin[i+1])\n cons++\n else\n if(cons>max)\n max = cons\n }\n if(cons>max)\n max = cons\n print(max)\n}\n\n"}], "src_uid": "f30329023e84b4c50b1b118dc98ae73c"} {"nl": {"description": "Princess Twilight went to Celestia and Luna's old castle to research the chest from the Elements of Harmony. A sequence of positive integers bi is harmony if and only if for every two elements of the sequence their greatest common divisor equals 1. According to an ancient book, the key of the chest is a harmony sequence bi which minimizes the following expression:You are given sequence ai, help Princess Twilight to find the key.", "input_spec": "The first line contains an integer n (1 ≤ n ≤ 100) — the number of elements of the sequences a and b. The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 30).", "output_spec": "Output the key — sequence bi that minimizes the sum described above. If there are multiple optimal sequences, you can output any of them.", "sample_inputs": ["5\n1 1 1 1 1", "5\n1 6 4 2 8"], "sample_outputs": ["1 1 1 1 1", "1 5 3 1 8"], "notes": null}, "positive_code": [{"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n// val startTime = System.nanoTime()\n\n val numCases = 1//readInt()\n case@ for(case in 1..numCases) {\n //print(\"Case #$case: \")\n\n val k = 59\n\n var nPrimes = 0\n val masks = IntArray(k+1)\n for(i in 2..k) if(masks[i] == 0) {\n val bit = 1 shl nPrimes\n nPrimes++\n\n for(j in i..k step i) masks[j] += bit\n }\n\n val m = 1 shl nPrimes\n\n val n = readInt()\n val A = readIntArray(n)\n\n val V = Array(n) { IntArray(m) }\n var D = IntArray(m) { inf }\n D[0] = 0\n\n for(i in 0 until n) {\n val a = A[i]\n val Di = IntArray(m) { inf }\n for(b in 1..a+a-1) {\n val mask = masks[b]\n val antiMask = mask xor m-1\n var s = antiMask\n val d = abs(b - a)\n while(true) {\n if(Di.setMin(s or mask, D[s] + d)) {\n V[i][s or mask] = b\n }\n if(s == 0) break\n s = s-1 and antiMask\n }\n }\n\n D = Di\n }\n\n val ans = IntArray(n)\n\n var cur = (0 until m).minByOrNull { D[it] }!!\n\n for(i in n-1 downTo 0) {\n ans[i] = V[i][cur]\n cur -= masks[ans[i]]\n }\n\n println(ans.joinToString(\" \"))\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nconst val inf = Int.MAX_VALUE / 2\n\nfun IntArray.setMax(i: Int, v: Int) = if(v > get(i)) { set(i, v); true } else false\nfun IntArray.setMin(i: Int, v: Int) = if(v < get(i)) { set(i, v); true } else false\n\n/** IO */\n//@JvmField val ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n//const val PATH = \"src/main/resources/\"\n//@JvmField val INPUT = File(PATH + \"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(PATH + \"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\nconst val _BUFFER_SIZE = 1 shl 16\n@JvmField val _buffer = ByteArray(_BUFFER_SIZE)\n@JvmField var _bufferPt = 0\n@JvmField var _bytesRead = 0\n\ntailrec fun readChar(): Char {\n if(_bufferPt == _bytesRead) {\n _bufferPt = 0\n _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)\n }\n return if(_bytesRead < 0) Char.MIN_VALUE\n else {\n val c = _buffer[_bufferPt++].toChar()\n if (c == '\\r') readChar() else c\n }\n}\n\n/** @param skipNext Whether to skip the next character (usually whitespace), defaults to true */\nfun readCharArray(n: Int, skipNext: Boolean = true): CharArray {\n val res = CharArray(n) { readChar() }\n if(skipNext) readChar()\n return res\n}\n\nfun readLine(): String? {\n var c = readChar()\n return if(c == Char.MIN_VALUE) null\n else buildString {\n while(c != '\\n' && c != Char.MIN_VALUE) {\n append(c)\n c = readChar()\n }\n }\n}\nfun readLn() = readLine()!!\n\nfun read() = buildString {\n var c = readChar()\n while(c <= ' ') {\n if(c == Char.MIN_VALUE) return@buildString\n c = readChar()\n }\n do {\n append(c)\n c = readChar()\n } while(c > ' ')\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** sort overrides to avoid quicksort attacks */\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\ninline fun _mergeSort(a0: A, n: Int, tmp0: A, get: A.(Int) -> T, set: A.(Int, T) -> Unit, cmp: (T, T) -> Int) {\n var a = a0\n var tmp = tmp0\n var len = 1\n while(len < n) {\n var l = 0\n while(true) {\n val m = l + len\n if(m >= n) break\n val r = min(n, m + len)\n var i = l\n var j = m\n for(k in l until r) {\n if(i != m && (j == r || cmp(a.get(i), a.get(j)) <= 0)) {\n tmp.set(k, a.get(i++))\n } else tmp.set(k, a.get(j++))\n }\n l = r\n }\n for(i in l until n) tmp.set(i, a.get(i))\n val t = a; a = tmp; tmp = t\n len += len\n }\n if(a !== a0) for(i in 0 until n) a0.set(i, tmp0.get(i))\n}\n\ninline fun IntArray.sortWith(cmp: (Int, Int) -> Int) { _mergeSort(this, size, IntArray(size), IntArray::get, IntArray::set, cmp) }\ninline fun > IntArray.sortBy(func: (Int) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > IntArray.sortByDescending(func: (Int) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun IntArray.sort() { sortBy { it } }\nfun IntArray.sortDescending() { sortByDescending { it } }\n\ninline fun LongArray.sortWith(cmp: (Long, Long) -> Int) { _mergeSort(this, size, LongArray(size), LongArray::get, LongArray::set, cmp) }\ninline fun > LongArray.sortBy(func: (Long) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > LongArray.sortByDescending(func: (Long) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun LongArray.sort() { sortBy { it } }\nfun LongArray.sortDescending() { sortByDescending { it } }\n\ninline fun DoubleArray.sortWith(cmp: (Double, Double) -> Int) { _mergeSort(this, size, DoubleArray(size), DoubleArray::get, DoubleArray::set, cmp) }\ninline fun > DoubleArray.sortBy(func: (Double) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > DoubleArray.sortByDescending(func: (Double) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun DoubleArray.sort() { sortBy { it } }\nfun DoubleArray.sortDescending() { sortByDescending { it } }\n\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\n// import preserving junk function\n@Suppress(\"NonAsciiCharacters\") fun 雪花飄飄北風嘯嘯天地一片蒼茫() { iprintln(max(1, 2)) }\n\nfun IntArray.sumLong() = sumOf { it.toLong() }\n\nfun IntArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun IntArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun LongArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun LongArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun DoubleArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun DoubleArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun > Array.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun > Array.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun > List.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun > List.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\n\n// max/min Kotlin 1.6 -> 1.4 shim\nfun IntArray.max() = maxOf { it }\nfun IntArray.min() = minOf { it }\nfun LongArray.max() = maxOf { it }\nfun LongArray.min() = minOf { it }\nfun CharArray.max() = maxOf { it }\nfun CharArray.min() = minOf { it }\nfun > Iterable.max() = maxOf { it }\nfun > Iterable.min() = minOf { it }\nfun > Sequence.max() = maxOf { it }\nfun > Sequence.min() = minOf { it }"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n// val startTime = System.nanoTime()\n\n val numCases = 1//readInt()\n case@ for(case in 1..numCases) {\n //print(\"Case #$case: \")\n\n val k = 59\n\n var nPrimes = 0\n val masks = IntArray(k+1)\n for(i in 2..k) if(masks[i] == 0) {\n val bit = 1 shl nPrimes\n nPrimes++\n\n for(j in i..k step i) masks[j] += bit\n }\n\n val m = 1 shl nPrimes\n\n val n = readInt()\n val A = readIntArray(n)\n\n val V = Array(n) { IntArray(m) }\n var D = IntArray(m) { inf }\n D[0] = 0\n\n for(i in 0 until n) {\n val a = A[i]\n val Di = IntArray(m) { inf }\n for(b in 1..a+a-1) {\n val mask = masks[b]\n val antiMask = mask xor m-1\n var s = antiMask\n while(true) {\n val d = D[s]\n if(Di.setMin(s or mask, d + abs(b - a))) {\n V[i][s or mask] = b\n }\n if(s == 0) break\n s = s-1 and antiMask\n }\n }\n\n D = Di\n }\n\n val ans = IntArray(n)\n\n var cur = (0 until m).minByOrNull { D[it] }!!\n\n for(i in n-1 downTo 0) {\n ans[i] = V[i][cur]\n cur -= masks[ans[i]]\n }\n\n println(ans.joinToString(\" \"))\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nconst val inf = Int.MAX_VALUE / 2\n\nfun IntArray.setMax(i: Int, v: Int) = if(v > get(i)) { set(i, v); true } else false\nfun IntArray.setMin(i: Int, v: Int) = if(v < get(i)) { set(i, v); true } else false\n\n/** IO */\n//@JvmField val ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n//const val PATH = \"src/main/resources/\"\n//@JvmField val INPUT = File(PATH + \"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(PATH + \"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\nconst val _BUFFER_SIZE = 1 shl 16\n@JvmField val _buffer = ByteArray(_BUFFER_SIZE)\n@JvmField var _bufferPt = 0\n@JvmField var _bytesRead = 0\n\ntailrec fun readChar(): Char {\n if(_bufferPt == _bytesRead) {\n _bufferPt = 0\n _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)\n }\n return if(_bytesRead < 0) Char.MIN_VALUE\n else {\n val c = _buffer[_bufferPt++].toChar()\n if (c == '\\r') readChar() else c\n }\n}\n\n/** @param skipNext Whether to skip the next character (usually whitespace), defaults to true */\nfun readCharArray(n: Int, skipNext: Boolean = true): CharArray {\n val res = CharArray(n) { readChar() }\n if(skipNext) readChar()\n return res\n}\n\nfun readLine(): String? {\n var c = readChar()\n return if(c == Char.MIN_VALUE) null\n else buildString {\n while(c != '\\n' && c != Char.MIN_VALUE) {\n append(c)\n c = readChar()\n }\n }\n}\nfun readLn() = readLine()!!\n\nfun read() = buildString {\n var c = readChar()\n while(c <= ' ') {\n if(c == Char.MIN_VALUE) return@buildString\n c = readChar()\n }\n do {\n append(c)\n c = readChar()\n } while(c > ' ')\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** sort overrides to avoid quicksort attacks */\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\ninline fun _mergeSort(a0: A, n: Int, tmp0: A, get: A.(Int) -> T, set: A.(Int, T) -> Unit, cmp: (T, T) -> Int) {\n var a = a0\n var tmp = tmp0\n var len = 1\n while(len < n) {\n var l = 0\n while(true) {\n val m = l + len\n if(m >= n) break\n val r = min(n, m + len)\n var i = l\n var j = m\n for(k in l until r) {\n if(i != m && (j == r || cmp(a.get(i), a.get(j)) <= 0)) {\n tmp.set(k, a.get(i++))\n } else tmp.set(k, a.get(j++))\n }\n l = r\n }\n for(i in l until n) tmp.set(i, a.get(i))\n val t = a; a = tmp; tmp = t\n len += len\n }\n if(a !== a0) for(i in 0 until n) a0.set(i, tmp0.get(i))\n}\n\ninline fun IntArray.sortWith(cmp: (Int, Int) -> Int) { _mergeSort(this, size, IntArray(size), IntArray::get, IntArray::set, cmp) }\ninline fun > IntArray.sortBy(func: (Int) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > IntArray.sortByDescending(func: (Int) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun IntArray.sort() { sortBy { it } }\nfun IntArray.sortDescending() { sortByDescending { it } }\n\ninline fun LongArray.sortWith(cmp: (Long, Long) -> Int) { _mergeSort(this, size, LongArray(size), LongArray::get, LongArray::set, cmp) }\ninline fun > LongArray.sortBy(func: (Long) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > LongArray.sortByDescending(func: (Long) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun LongArray.sort() { sortBy { it } }\nfun LongArray.sortDescending() { sortByDescending { it } }\n\ninline fun DoubleArray.sortWith(cmp: (Double, Double) -> Int) { _mergeSort(this, size, DoubleArray(size), DoubleArray::get, DoubleArray::set, cmp) }\ninline fun > DoubleArray.sortBy(func: (Double) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > DoubleArray.sortByDescending(func: (Double) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun DoubleArray.sort() { sortBy { it } }\nfun DoubleArray.sortDescending() { sortByDescending { it } }\n\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\n// import preserving junk function\n@Suppress(\"NonAsciiCharacters\") fun 雪花飄飄北風嘯嘯天地一片蒼茫() { iprintln(max(1, 2)) }\n\nfun IntArray.sumLong() = sumOf { it.toLong() }\n\nfun IntArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun IntArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun LongArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun LongArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun DoubleArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun DoubleArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun > Array.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun > Array.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun > List.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun > List.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\n\n// max/min Kotlin 1.6 -> 1.4 shim\nfun IntArray.max() = maxOf { it }\nfun IntArray.min() = minOf { it }\nfun LongArray.max() = maxOf { it }\nfun LongArray.min() = minOf { it }\nfun CharArray.max() = maxOf { it }\nfun CharArray.min() = minOf { it }\nfun > Iterable.max() = maxOf { it }\nfun > Iterable.min() = minOf { it }\nfun > Sequence.max() = maxOf { it }\nfun > Sequence.min() = minOf { it }"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n// val startTime = System.nanoTime()\n\n val numCases = 1//readInt()\n case@ for(case in 1..numCases) {\n //print(\"Case #$case: \")\n\n val k = 59\n\n var nPrimes = 0\n val masks = IntArray(k+1)\n for(i in 2..k) if(masks[i] == 0) {\n val bit = 1 shl nPrimes\n nPrimes++\n\n for(j in i..k step i) masks[j] += bit\n }\n\n val m = 1 shl nPrimes\n\n val n = readInt()\n val A = readIntArray(n)\n\n val V = Array(n) { IntArray(m) }\n var D = IntArray(m) { inf }\n D[0] = 0\n\n for(i in 0 until n) {\n val a = A[i]\n val Di = IntArray(m) { inf }\n for(b in 1..a+a-1) {\n val mask = masks[b]\n val antiMask = mask xor m-1\n var s = antiMask\n while(true) {\n val d = D[s]\n if(d != inf && Di.setMin(s or mask, d + abs(b - a))) {\n V[i][s or mask] = b\n }\n if(s == 0) break\n s = s-1 and antiMask\n }\n }\n\n for(mask in 0 until m) if(D[mask] != inf) {\n\n }\n D = Di\n }\n\n val ans = IntArray(n)\n\n var cur = (0 until m).minByOrNull { D[it] }!!\n\n for(i in n-1 downTo 0) {\n ans[i] = V[i][cur]\n cur -= masks[ans[i]]\n }\n\n println(ans.joinToString(\" \"))\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nconst val inf = Int.MAX_VALUE\n\nfun IntArray.setMax(i: Int, v: Int) = if(v > get(i)) { set(i, v); true } else false\nfun IntArray.setMin(i: Int, v: Int) = if(v < get(i)) { set(i, v); true } else false\n\n/** IO */\n//@JvmField val ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n//const val PATH = \"src/main/resources/\"\n//@JvmField val INPUT = File(PATH + \"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(PATH + \"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\nconst val _BUFFER_SIZE = 1 shl 16\n@JvmField val _buffer = ByteArray(_BUFFER_SIZE)\n@JvmField var _bufferPt = 0\n@JvmField var _bytesRead = 0\n\ntailrec fun readChar(): Char {\n if(_bufferPt == _bytesRead) {\n _bufferPt = 0\n _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)\n }\n return if(_bytesRead < 0) Char.MIN_VALUE\n else {\n val c = _buffer[_bufferPt++].toChar()\n if (c == '\\r') readChar() else c\n }\n}\n\n/** @param skipNext Whether to skip the next character (usually whitespace), defaults to true */\nfun readCharArray(n: Int, skipNext: Boolean = true): CharArray {\n val res = CharArray(n) { readChar() }\n if(skipNext) readChar()\n return res\n}\n\nfun readLine(): String? {\n var c = readChar()\n return if(c == Char.MIN_VALUE) null\n else buildString {\n while(c != '\\n' && c != Char.MIN_VALUE) {\n append(c)\n c = readChar()\n }\n }\n}\nfun readLn() = readLine()!!\n\nfun read() = buildString {\n var c = readChar()\n while(c <= ' ') {\n if(c == Char.MIN_VALUE) return@buildString\n c = readChar()\n }\n do {\n append(c)\n c = readChar()\n } while(c > ' ')\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** sort overrides to avoid quicksort attacks */\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\ninline fun _mergeSort(a0: A, n: Int, tmp0: A, get: A.(Int) -> T, set: A.(Int, T) -> Unit, cmp: (T, T) -> Int) {\n var a = a0\n var tmp = tmp0\n var len = 1\n while(len < n) {\n var l = 0\n while(true) {\n val m = l + len\n if(m >= n) break\n val r = min(n, m + len)\n var i = l\n var j = m\n for(k in l until r) {\n if(i != m && (j == r || cmp(a.get(i), a.get(j)) <= 0)) {\n tmp.set(k, a.get(i++))\n } else tmp.set(k, a.get(j++))\n }\n l = r\n }\n for(i in l until n) tmp.set(i, a.get(i))\n val t = a; a = tmp; tmp = t\n len += len\n }\n if(a !== a0) for(i in 0 until n) a0.set(i, tmp0.get(i))\n}\n\ninline fun IntArray.sortWith(cmp: (Int, Int) -> Int) { _mergeSort(this, size, IntArray(size), IntArray::get, IntArray::set, cmp) }\ninline fun > IntArray.sortBy(func: (Int) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > IntArray.sortByDescending(func: (Int) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun IntArray.sort() { sortBy { it } }\nfun IntArray.sortDescending() { sortByDescending { it } }\n\ninline fun LongArray.sortWith(cmp: (Long, Long) -> Int) { _mergeSort(this, size, LongArray(size), LongArray::get, LongArray::set, cmp) }\ninline fun > LongArray.sortBy(func: (Long) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > LongArray.sortByDescending(func: (Long) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun LongArray.sort() { sortBy { it } }\nfun LongArray.sortDescending() { sortByDescending { it } }\n\ninline fun DoubleArray.sortWith(cmp: (Double, Double) -> Int) { _mergeSort(this, size, DoubleArray(size), DoubleArray::get, DoubleArray::set, cmp) }\ninline fun > DoubleArray.sortBy(func: (Double) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > DoubleArray.sortByDescending(func: (Double) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun DoubleArray.sort() { sortBy { it } }\nfun DoubleArray.sortDescending() { sortByDescending { it } }\n\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\n// import preserving junk function\n@Suppress(\"NonAsciiCharacters\") fun 雪花飄飄北風嘯嘯天地一片蒼茫() { iprintln(max(1, 2)) }\n\nfun IntArray.sumLong() = sumOf { it.toLong() }\n\nfun IntArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun IntArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun LongArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun LongArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun DoubleArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun DoubleArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun > Array.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun > Array.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun > List.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun > List.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\n\n// max/min Kotlin 1.6 -> 1.4 shim\nfun IntArray.max() = maxOf { it }\nfun IntArray.min() = minOf { it }\nfun LongArray.max() = maxOf { it }\nfun LongArray.min() = minOf { it }\nfun CharArray.max() = maxOf { it }\nfun CharArray.min() = minOf { it }\nfun > Iterable.max() = maxOf { it }\nfun > Iterable.min() = minOf { it }\nfun > Sequence.max() = maxOf { it }\nfun > Sequence.min() = minOf { it }"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n// val startTime = System.nanoTime()\n\n val numCases = 1//readInt()\n case@ for(case in 1..numCases) {\n //print(\"Case #$case: \")\n\n val k = 59\n\n var nPrimes = 0\n val masks = IntArray(k+1)\n for(i in 2..k) if(masks[i] == 0) {\n val bit = 1 shl nPrimes\n nPrimes++\n\n for(j in i..k step i) masks[j] += bit\n }\n\n val m = 1 shl nPrimes\n\n val n = readInt()\n val A = readIntArray(n)\n\n\n val V = Array(n) { IntArray(m) }\n var D = IntArray(m) { inf }\n D[0] = 0\n\n for(i in 0 until n) {\n val a = A[i]\n val Di = IntArray(m) { inf }\n for(mask in 0 until m) if(D[mask] != inf) {\n for(b in 1..a+a-1) if(mask and masks[b] == 0) {\n val newMask = mask or masks[b]\n if(Di.setMin(newMask, D[mask] + abs(b - a))) V[i][newMask] = b\n }\n }\n D = Di\n }\n\n val ans = IntArray(n)\n\n var cur = (0 until m).minByOrNull { D[it] }!!\n\n for(i in n-1 downTo 0) {\n ans[i] = V[i][cur]\n cur -= masks[ans[i]]\n }\n\n println(ans.joinToString(\" \"))\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nconst val inf = Int.MAX_VALUE\n\nfun IntArray.setMax(i: Int, v: Int) = if(v > get(i)) { set(i, v); true } else false\nfun IntArray.setMin(i: Int, v: Int) = if(v < get(i)) { set(i, v); true } else false\n\n/** IO */\n//@JvmField val ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n//const val PATH = \"src/main/resources/\"\n//@JvmField val INPUT = File(PATH + \"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(PATH + \"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\nconst val _BUFFER_SIZE = 1 shl 16\n@JvmField val _buffer = ByteArray(_BUFFER_SIZE)\n@JvmField var _bufferPt = 0\n@JvmField var _bytesRead = 0\n\ntailrec fun readChar(): Char {\n if(_bufferPt == _bytesRead) {\n _bufferPt = 0\n _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)\n }\n return if(_bytesRead < 0) Char.MIN_VALUE\n else {\n val c = _buffer[_bufferPt++].toChar()\n if (c == '\\r') readChar() else c\n }\n}\n\n/** @param skipNext Whether to skip the next character (usually whitespace), defaults to true */\nfun readCharArray(n: Int, skipNext: Boolean = true): CharArray {\n val res = CharArray(n) { readChar() }\n if(skipNext) readChar()\n return res\n}\n\nfun readLine(): String? {\n var c = readChar()\n return if(c == Char.MIN_VALUE) null\n else buildString {\n while(c != '\\n' && c != Char.MIN_VALUE) {\n append(c)\n c = readChar()\n }\n }\n}\nfun readLn() = readLine()!!\n\nfun read() = buildString {\n var c = readChar()\n while(c <= ' ') {\n if(c == Char.MIN_VALUE) return@buildString\n c = readChar()\n }\n do {\n append(c)\n c = readChar()\n } while(c > ' ')\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** sort overrides to avoid quicksort attacks */\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\ninline fun _mergeSort(a0: A, n: Int, tmp0: A, get: A.(Int) -> T, set: A.(Int, T) -> Unit, cmp: (T, T) -> Int) {\n var a = a0\n var tmp = tmp0\n var len = 1\n while(len < n) {\n var l = 0\n while(true) {\n val m = l + len\n if(m >= n) break\n val r = min(n, m + len)\n var i = l\n var j = m\n for(k in l until r) {\n if(i != m && (j == r || cmp(a.get(i), a.get(j)) <= 0)) {\n tmp.set(k, a.get(i++))\n } else tmp.set(k, a.get(j++))\n }\n l = r\n }\n for(i in l until n) tmp.set(i, a.get(i))\n val t = a; a = tmp; tmp = t\n len += len\n }\n if(a !== a0) for(i in 0 until n) a0.set(i, tmp0.get(i))\n}\n\ninline fun IntArray.sortWith(cmp: (Int, Int) -> Int) { _mergeSort(this, size, IntArray(size), IntArray::get, IntArray::set, cmp) }\ninline fun > IntArray.sortBy(func: (Int) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > IntArray.sortByDescending(func: (Int) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun IntArray.sort() { sortBy { it } }\nfun IntArray.sortDescending() { sortByDescending { it } }\n\ninline fun LongArray.sortWith(cmp: (Long, Long) -> Int) { _mergeSort(this, size, LongArray(size), LongArray::get, LongArray::set, cmp) }\ninline fun > LongArray.sortBy(func: (Long) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > LongArray.sortByDescending(func: (Long) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun LongArray.sort() { sortBy { it } }\nfun LongArray.sortDescending() { sortByDescending { it } }\n\ninline fun DoubleArray.sortWith(cmp: (Double, Double) -> Int) { _mergeSort(this, size, DoubleArray(size), DoubleArray::get, DoubleArray::set, cmp) }\ninline fun > DoubleArray.sortBy(func: (Double) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > DoubleArray.sortByDescending(func: (Double) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun DoubleArray.sort() { sortBy { it } }\nfun DoubleArray.sortDescending() { sortByDescending { it } }\n\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\n// import preserving junk function\n@Suppress(\"NonAsciiCharacters\") fun 雪花飄飄北風嘯嘯天地一片蒼茫() { iprintln(max(1, 2)) }\n\nfun IntArray.sumLong() = sumOf { it.toLong() }\n\nfun IntArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun IntArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun LongArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun LongArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun DoubleArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun DoubleArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun > Array.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun > Array.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun > List.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun > List.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\n\n// max/min Kotlin 1.6 -> 1.4 shim\nfun IntArray.max() = maxOf { it }\nfun IntArray.min() = minOf { it }\nfun LongArray.max() = maxOf { it }\nfun LongArray.min() = minOf { it }\nfun CharArray.max() = maxOf { it }\nfun CharArray.min() = minOf { it }\nfun > Iterable.max() = maxOf { it }\nfun > Iterable.min() = minOf { it }\nfun > Sequence.max() = maxOf { it }\nfun > Sequence.min() = minOf { it }"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.abs\n\nval PRIMES = mutableListOf(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53)\nval IMPORTANT = (1..30) + listOf(31, 32, 37, 41, 43, 47, 49, 53)\n\nfun main() {\n val jin = BufferedReader(InputStreamReader(System.`in`))\n val n = jin.readLine().toInt()\n val masks = IntArray(54)\n for (k in 1..53) {\n for (e in 0..15) {\n if (k % PRIMES[e] == 0) {\n masks[k] += 1 shl e\n }\n }\n }\n val dp = Array(n + 1) { IntArray(1 shl 16) { 115115 } }\n dp[0][0] = 0\n val used = Array(n + 1) { IntArray(1 shl 16) }\n val tokenizer = StringTokenizer(jin.readLine())\n for (j in 1..n) {\n val a = tokenizer.nextToken().toInt()\n for (k in IMPORTANT) {\n for (mask in 0 until (1 shl 16)) {\n if (mask and masks[k] == 0 && dp[j - 1][mask] + abs(k - a) < dp[j][mask or masks[k]]) {\n dp[j][mask or masks[k]] = dp[j - 1][mask] + abs(k - a)\n used[j][mask or masks[k]] = k\n }\n }\n }\n }\n val optimal = dp[n].min()!!\n for (mask in 0 until (1 shl 16)) {\n if (dp[n][mask] == optimal) {\n val answer = mutableListOf()\n var mask = mask\n for (j in n downTo 1) {\n answer.add(used[j][mask])\n mask -= masks[used[j][mask]]\n }\n println(answer.reversed().joinToString(\" \"))\n return\n }\n }\n}"}], "negative_code": [], "src_uid": "f26c74f27bbc723efd69c38ad0e523c6"} {"nl": {"description": " When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.\"What a pity it's already late spring,\" sighs Mino with regret, \"one more drizzling night and they'd be gone.\"\"But these blends are at their best, aren't they?\" Absorbed in the landscape, Kanno remains optimistic. The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.", "input_spec": "The first and only line of input contains a non-empty string $$$s$$$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($$$\\lvert s \\rvert \\leq 100$$$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.", "output_spec": "Output \"Yes\" if it's possible that all three colours appear in some cell, and \"No\" otherwise. You can print each letter in any case (upper or lower).", "sample_inputs": [".BAC.", "AA..CB"], "sample_outputs": ["Yes", "No"], "notes": "NoteIn the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell."}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.HashMap\nimport kotlin.math.min\n\nfun main(args: Array)\n = Thread { run() }.start()\n\nfun run() {\n\n val scanner = Scanner(System.`in`)\n val str = scanner.next()\n val arr = IntArray(102)\n for (i in 0 until str.length) {\n if (str[i] == 'A') {\n for (j in i .. i + 2) {\n arr[j] += 1\n if (arr[j] == 7) {\n print(\"Yes\")\n return\n }\n }\n }\n if (str[i] == 'B') {\n for (j in i .. i + 2) {\n arr[j] += 2\n if (arr[j] == 7) {\n print(\"Yes\")\n return\n }\n }\n }\n if (str[i] == 'C') {\n for (j in i .. i + 2) {\n arr[j] += 4\n if (arr[j] == 7) {\n print(\"Yes\")\n return\n }\n }\n }\n }\n println(\"No\")\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\nclass Pair(var a: Int, var b: Int): Comparable {\n override fun compareTo(other: Pair): Int {\n return b - a - other.b + other.a\n }\n}"}, {"source_code": "fun main(args: Array) {\n val s = readLine()!!\n val n = s.length\n for (i in 1..n - 2 ) {\n val ss = setOf(s[i - 1], s[i], s[i + 1])\n if (!ss.contains('.') && ss.size == 3) {\n println(\"Yes\")\n return\n }\n }\n println(\"No\")\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n solve(System.`in`, System.out)\n}\n\nval MAX_N = (1e6 + 10).toInt()\nval INF = (1e9 + 7).toInt()\nval MOD = (1e9 + 7).toInt()\nval INF_F = 1e-6\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val s = reader.next()\n for (i in 1 until s.length - 1) {\n if (s[i - 1] == '.' || s[i] == '.' || s[i + 1] == '.') {\n continue\n }\n\n if (s[i - 1] != s[i] && s[i - 1] != s[i + 1] && s[i] != s[i + 1]) {\n writer.println(\"yes\")\n return\n }\n }\n writer.println(\"no\")\n}\n\nfun gcd(a: Int, b: Int): Int {\n return if (b == 0) a else gcd(b, a % b)\n}\n\nclass InputReader(stream: InputStream) {\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}"}, {"source_code": "fun main(args: Array){\n val opa = readLine()!!\n var result = false\n for (i in 1..opa.length - 2){\n if (opa.get(i) != opa.get(i-1) \n && opa.get(i) != opa.get(i+1) \n && opa.get(i) != '.' \n && opa.get(i+1) != '.' \n && opa.get(i-1) != '.'\n && opa.get(i-1) != opa.get(i+1)){\n result = true\n }\n }\n if (result){\n println(\"Yes\")\n } else {\n println(\"No\")\n }\n\n}"}, {"source_code": "fun main() {\n val valids = setOf(\"ABC\", \"ACB\", \"BAC\", \"BCA\", \"CAB\", \"CBA\")\n val s = readLine()!!\n for (start in 0..s.length - 3)\n if (s.substring(start..start + 2) in valids) return print(\"Yes\")\n print(\"No\")\n}"}], "negative_code": [{"source_code": "fun main(args: Array){\n val opa = readLine()\n if (opa == null){\n System.out.println(\"No\")\n return\n } else {\n var result = false\n for (i in 1..opa.length - 2){\n if (opa.get(i) != opa.get(i-1) \n && opa.get(i) != opa.get(i+1) \n && opa.get(i) != '.' \n && opa.get(i+1) != '.' \n && opa.get(i-1) != '.'){\n result = true\n }\n }\n if (result){\n println(\"Yes\")\n } else {\n println(\"No\")\n }\n }\n\n}"}], "src_uid": "ba6ff507384570152118e2ab322dd11f"} {"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.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.StringTokenizer\n\nfun main(args: Array) {\n val sc = FastScanner(System.`in`)\n val a = Array(6) { sc.nextInt() }\n val total = a.sum()\n\n for (i in 0..5) {\n for (j in i + 1..5) {\n for (k in j + 1..5) {\n val s = a[i] + a[j] + a[k]\n if(s == total - s) {\n println(\"YES\")\n return\n }\n }\n }\n }\n\n println(\"NO\")\n\n\n}\n\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}\n\n\n"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\n\n/** @author Om Kumar */\nfun main() { _writer.solve(); _writer.flush() }\n\nfun solve(a: IntArray): Boolean{\n val sum = a.reduce { acc, i -> acc + i}\n if((sum and 1) == 0) {\n for (i in 0..5) {\n for (j in i + 1..5) {\n for (k in j + 1..5) {\n if (a[i] + a[j] + a[k] == sum / 2){\n return true\n }\n }\n }\n }\n }\n return false\n}\n\nfun PrintWriter.solve() {\n val a = readIntArray(6)\n println(if(solve(a)) \"YES\" else \"NO\")\n}\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x58359625447 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()"}, {"source_code": "fun main(args: Array) {\n val mass = readLine()!!.split(\" \").map { it.toInt() }\n val f = mass.sum()\n if (f % 2 != 0) {\n print(\"NO\")\n } else {\n var stop = false\n for (i in 0..5) {\n for (j in 0..5) {\n for (k in 0..5) {\n if (i != j && i != k && j != k && (mass[i] + mass[j] + mass[k])* 2 == f) {\n print(\"YES\")\n stop = true\n break\n }\n }\n if (stop) {\n break\n }\n }\n if (stop) {\n break\n }\n }\n if (!stop) {\n print(\"NO\")\n }\n }\n}"}, {"source_code": "fun main() {\n var list = readLine()!!.split(' ').map { it.toInt() }.sorted().toMutableList()\n// if (list.sum() % 2 == 0) {\n// println(\"NO\")\n// return\n// }\n var flag = false\n var midSum = list.sum() / 2\n var temp = false\n for (i in 0..4) {\n var sum = list[5] + list[i]\n for (j in 0..4) {\n if (i != j) {\n sum += list[j]\n if (sum == midSum) {\n list[5] = 0\n list[i] = 0\n list[j] = 0\n flag = true\n temp = true\n break\n }else{\n sum = list[5] + list[i]\n }\n }\n }\n if (temp) break\n }\n if (flag) {\n if (list.sum() == midSum) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n } else {\n println(\"NO\")\n }\n\n\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val scores = readInts()\n if (scores.sum() and 1 == 1) return print(\"NO\")\n val goal = scores.sum() / 2\n for (first in 0..3)\n for (second in first + 1..4)\n for (third in second + 1..5)\n if (scores[first] + scores[second] + scores[third] == goal) return print(\"YES\")\n print(\"NO\")\n}"}], "negative_code": [{"source_code": "fun main() {\n var list = readLine()!!.split(' ').map { it.toInt() }.sorted().toMutableList()\n// if (list.sum() % 2 == 0) {\n// println(\"NO\")\n// return\n// }\n var flag = false\n var midSum = list.sum() / 2\n var temp = false\n for (i in 0..4) {\n var sum = list[5] + list[i]\n for (j in i + 1..4) {\n sum += list[j]\n if (sum == midSum) {\n list[5] = 0\n list[i] = 0\n list[j] = 0\n flag = true\n temp = true\n break\n }\n }\n if (temp) break\n }\n if (flag) {\n if (list.sum() == midSum) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n } else {\n println(\"NO\")\n }\n\n\n}"}, {"source_code": "fun main() {\n var list = readLine()!!.split(' ').map { it.toInt() }.sorted()\n var flag = true\n if (list.sum() % 2 == 0) {\n if (list[0] + list[1] + list[5] != list.sum() / 2) {\n flag = false\n }\n if (list[2] + list[3] + list[4] != list.sum() / 2){\n flag = false\n }\n }else{\n println(\"NO\")\n return\n }\n println(if (flag) \"YES\" else \"NO\")\n\n\n}"}], "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11"} {"nl": {"description": "Bishwock is a chess figure that consists of three squares resembling an \"L-bar\". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states: XX XX .X X.X. .X XX XX Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't occupy the same square. Vasya has a board with $$$2\\times n$$$ squares onto which he wants to put some bishwocks. To his dismay, several squares on this board are already occupied by pawns and Vasya can't put bishwocks there. However, pawns also don't attack bishwocks and they can occupy adjacent squares peacefully.Knowing the positions of pawns on the board, help Vasya to determine the maximum amount of bishwocks he can put onto the board so that they wouldn't occupy the same squares and wouldn't occupy squares with pawns.", "input_spec": "The input contains two nonempty strings that describe Vasya's board. Those strings contain only symbols \"0\" (zero) that denote the empty squares and symbols \"X\" (uppercase English letter) that denote the squares occupied by pawns. Strings are nonempty and are of the same length that does not exceed $$$100$$$.", "output_spec": "Output a single integer — the maximum amount of bishwocks that can be placed onto the given board.", "sample_inputs": ["00\n00", "00X00X0XXX0\n0XXX0X00X00", "0X0X0\n0X0X0", "0XXX0\n00000"], "sample_outputs": ["1", "4", "0", "2"], "notes": null}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.*\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n val Q = Array(2) { scanner.next().toCharArray() }\n var res = 0\n for (i in 0..Q[0].size - 2) {\n if (Q[0][i] == '0' && Q[1][i] == '0' && Q[0][i + 1] == '0') {\n Q[0][i] = 'X'\n Q[1][i] = 'X'\n Q[0][i + 1] = 'X'\n res++\n }\n if (Q[0][i] == '0' && Q[1][i] == '0' && Q[1][i + 1] == '0') {\n Q[0][i] = 'X'\n Q[1][i] = 'X'\n Q[1][i + 1] = 'X'\n res++\n }\n if (Q[0][i] == '0' && Q[0][i + 1] == '0' && Q[1][i + 1] == '0') {\n Q[0][i] = 'X'\n Q[0][i + 1] = 'X'\n Q[1][i + 1] = 'X'\n res++\n }\n if (Q[1][i] == '0' && Q[1][i + 1] == '0' && Q[0][i + 1] == '0') {\n Q[1][i] = 'X'\n Q[1][i + 1] = 'X'\n Q[0][i + 1] = 'X'\n res++\n }\n }\n println(res)\n\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\n\nfun IntArray.print() {\n println(Arrays.toString(this))\n}\n\n//class Pair(var a: Int, var b: Int): Comparable {\n// override fun compareTo(other: Pair): Int {\n// return b - a - other.b + other.a\n// }\n//}"}, {"source_code": "import kotlin.math.max\n\nfun main(args: Array) {\n val b = Array(2) { readLine()!!.toCharArray() }\n val n = b[0].size\n val d = Array(n) { IntArray(3 ) }\n for (i in 1 until n) {\n val best = d[i - 1].max()!!\n for (p in 0..2) d[i][p] = best\n if (b[0][i - 1] == '0' && b[1][i - 1] == '0') {\n for (p in 0..2) {\n for (j in 0..1) if (b[j][i] == '0' && (p and (1 shl j) == 0)) {\n d[i][p] = max(d[i][p], (if (i > 1) d[i - 2][0] else 0) + 1)\n }\n }\n }\n if (b[0][i] == '0' && b[1][i] == '0') {\n for (j in 0..1) {\n if (b[j][i - 1] == '0')\n d[i][0] = max(d[i][0], d[i - 1][1 shl j] + 1)\n }\n }\n }\n println(d[n - 1][0])\n}"}, {"source_code": "//package codeForces.c491_2\n\nfun main(args: Array) {\n val s1 = (readLine()!! + 'X').toCharArray()\n val s2 = (readLine()!! + 'X').toCharArray()\n\n val lenght = minOf(s1.size, s2.size)\n\n var count = 0\n var i = -1\n while (i < lenght - 1) {\n i++\n if (s1[i] == '0' && s2[i] == '0') {\n if (s1[i + 1] == '0') {\n s1[i + 1] = 'X'\n count++\n continue\n } else if (s2[i + 1] == '0') {\n s2[i + 1] = 'X'\n count++\n continue\n }\n }\n\n if (\n (s1[i] == '0' || s2[i] == '0') &&\n s1[i + 1] == '0' &&\n s2[i + 1] == '0'\n ) {\n count++\n i++\n continue\n }\n }\n\n print(count)\n}"}], "negative_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.*\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n val Q = Array(2) { \"X\" + scanner.next() + \"X\" }\n var last = 0\n var res = 0\n for (i in 0 until Q[0].length) {\n if (Q[0][i] == 'X' && Q[1][i] == 'X') {\n if ((i - last) % 3 == 0)\n res += ((i - last) / 3) * 2\n else if ((i - last) % 3== 2)\n res += ((i - last) / 3) * 2 + 1\n else\n res += ((i - last) / 3) * 2\n last = i + 1\n }\n else if (Q[0][i] == 'X' || Q[1][i] == 'X') {\n if ((i - last) % 3 == 0)\n res += ((i - last) / 3) * 2\n else if ((last - i) % 3 == 2)\n res += ((i - last) / 3) * 2 + 1\n else\n res += (((i - last) / 3) * 2) + 1\n last = i + 1\n }\n else if (Q[0][i] == '0' && Q[1][i] == '0' && ((Q[0][i - 1] == 'X' && Q[1][i - 1] != 'X') || (Q[1][i - 1] == 'X' && Q[0][i - 1] != 'X'))) {\n res++\n last = i + 1\n }\n }\n println(res)\n\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\n\nfun IntArray.print() {\n println(Arrays.toString(this))\n}\n\n//class Pair(var a: Int, var b: Int): Comparable {\n// override fun compareTo(other: Pair): Int {\n// return b - a - other.b + other.a\n// }\n//}"}], "src_uid": "e6b3e787919e96fc893a034eae233fc6"} {"nl": {"description": "Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly n1 balls and second player's box contains exactly n2 balls. In one move first player can take from 1 to k1 balls from his box and throw them away. Similarly, the second player can take from 1 to k2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can't make a move loses. Your task is to determine who wins if both players play optimally.", "input_spec": "The first line contains four integers n1, n2, k1, k2. All numbers in the input are from 1 to 50. This problem doesn't have subproblems. You will get 3 points for the correct submission.", "output_spec": "Output \"First\" if the first player wins and \"Second\" otherwise.", "sample_inputs": ["2 2 1 2", "2 1 1 1"], "sample_outputs": ["Second", "First"], "notes": "NoteConsider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely."}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n }\n\n var tok = StringTokenizer(\"\")\n\n fun close() { rd.close(); wr.close() }\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun readToken(): String {\n while (!tok.hasMoreTokens()) tok = StringTokenizer(rd.readLine())\n return tok.nextToken()\n }\n fun readInt() = readToken().toInt()\n fun readLong() = readToken().toLong()\n fun readLine() : String {\n tok = StringTokenizer(\"\")\n return rd.readLine()\n }\n}\n\nfun main(args: Array) {\n Thread({ val io = ProblemIO.console(); solve(io) ; io.close() }).start()\n}\n\nfun solve(io: ProblemIO) {\n val n = IntArray(2, { io.readInt() })\n val k = IntArray(2, { io.readInt() })\n val res = when {\n n[0] <= n[1] -> \"Second\"\n else -> \"First\"\n }\n io.println(res)\n}\n"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //var (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n val v = r.readLine()!!.split(\" \").map { it.toInt() }\n println(if (v[0]-v[1]>0) \"First\" else \"Second\")\n}"}, {"source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n println(if (sc.nextInt() > sc.nextInt()) \"First\" else \"Second\")\n}\n\n"}, {"source_code": "import javafx.util.Pair\n\nimport java.util.ArrayList\nimport java.util.Scanner\n\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val n1 = scanner.nextInt()\n val n2 = scanner.nextInt()\n println(if (n1 > n2) \"First\" else \"Second\")\n\n}\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n var scan = Scanner(System.`in`)\n var p1 = scan.nextInt()\n var p2 = scan.nextInt()\n if (p1 > p2) {\n println(\"First\")\n } else {\n println(\"Second\")\n }\n}"}, {"source_code": "import kotlin.math.abs\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readStrings() = readLn().split(\" \")\nfun readInts() = readStrings().map { it.toInt() }\n\nfun main(args: Array) {\n var (n, m, k, l) = readInts()\n if (n > m) print(\"First\") else print(\"Second\")\n}"}, {"source_code": "import org.omg.PortableInterceptor.INACTIVE\nimport java.util.*\n\nfun main(args: Array) {\n val s = Scanner(System.`in`)\n val a = IntArray(2, { s.nextInt() })\n val b = IntArray(2, { s.nextInt() })\n val res = when {a[0] > a[1] -> \"First\" else -> \"Second\"}\n print(res)\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (n1, n2, k1, k2) = readInts()\n print(if (n1 > n2) \"First\" else \"Second\")\n}"}, {"source_code": "fun main(args: Array) {\n val (f,s) = readLine()!!.split(\" \").map { it.toInt() }\n println(if (f > s) \"First\" else \"Second\")\n}"}], "negative_code": [], "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b"} {"nl": {"description": "JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ of integers, such that $$$1 \\le a_1 < a_2 < \\ldots < a_n \\le 10^3$$$, and then went to the bathroom.JATC decided to prank his friend by erasing some consecutive elements in the array. Since he doesn't want for the prank to go too far, he will only erase in a way, such that Giraffe can still restore the array using the information from the remaining elements. Because Giraffe has created the array, he's also aware that it's an increasing array and all the elements are integers in the range $$$[1, 10^3]$$$.JATC wonders what is the greatest number of elements he can erase?", "input_spec": "The first line of the input contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$) — the number of elements in the array. The second line of the input contains $$$n$$$ integers $$$a_i$$$ ($$$1 \\le a_1<a_2<\\dots<a_n \\le 10^3$$$) — the array written by Giraffe.", "output_spec": "Print a single integer — the maximum number of consecutive elements in the array that JATC can erase. If it is impossible to erase even a single element, print $$$0$$$.", "sample_inputs": ["6\n1 3 4 5 6 9", "3\n998 999 1000", "5\n1 2 3 4 5"], "sample_outputs": ["2", "2", "4"], "notes": "NoteIn the first example, JATC can erase the third and fourth elements, leaving the array $$$[1, 3, \\_, \\_, 6, 9]$$$. As you can see, there is only one way to fill in the blanks.In the second example, JATC can erase the second and the third elements. The array will become $$$[998, \\_, \\_]$$$. Because all the elements are less than or equal to $$$1000$$$, the array is still can be restored. Note, that he can't erase the first $$$2$$$ elements.In the third example, JATC can erase the first $$$4$$$ elements. Since all the elements are greater than or equal to $$$1$$$, Giraffe can still restore the array. Note, that he can't erase the last $$$4$$$ elements."}, "positive_code": [{"source_code": "import kotlin.math.max\n\nfun main() {\n readLine()\n val array = mutableListOf(0)\n array.addAll(readLine()!!.split(\" \").map(String::toInt))\n array.add(1001)\n var sol = 0\n var current = 0\n for (elementPos in 1 until array.size - 1) {\n if (array[elementPos - 1] + 1 == array[elementPos] &&\n array[elementPos] + 1 == array[elementPos + 1]\n )\n current++\n else\n current = 0\n sol = max(sol, current)\n }\n print(sol)\n}"}], "negative_code": [], "src_uid": "858b5e75e21c4cba6d08f3f66be0c198"} {"nl": {"description": "Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are \"a\", \"o\", \"u\", \"i\", and \"e\". Other letters are consonant.In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant \"n\"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words \"harakiri\", \"yupie\", \"man\", and \"nbo\" are Berlanese while the words \"horse\", \"king\", \"my\", and \"nz\" are not.Help Vitya find out if a word $$$s$$$ is Berlanese.", "input_spec": "The first line of the input contains the string $$$s$$$ consisting of $$$|s|$$$ ($$$1\\leq |s|\\leq 100$$$) lowercase Latin letters.", "output_spec": "Print \"YES\" (without quotes) if there is a vowel after every consonant except \"n\", otherwise print \"NO\". You can print each letter in any case (upper or lower).", "sample_inputs": ["sumimasen", "ninja", "codeforces"], "sample_outputs": ["YES", "YES", "NO"], "notes": "NoteIn the first and second samples, a vowel goes after each consonant except \"n\", so the word is Berlanese.In the third sample, the consonant \"c\" goes after the consonant \"r\", and the consonant \"s\" stands on the end, so the word is not Berlanese."}, "positive_code": [{"source_code": "fun isVowel(c: Char): Boolean {\n return c in \"aeiou\"\n}\n\nfun main(args: Array) {\n\n val s = readLine()!!\n val good: Boolean = (0..s.length - 1).none {\n !isVowel(s[it]) &&\n s[it] != 'n' &&\n ((it + 1 < s.length &&\n !isVowel(s[it + 1]) || it + 1 == s.length))\n }\n\n if (good) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashSet\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\nfun main(args : Array) {\n Thread { run() }.start()\n}\n\nfun run() {\n\n val scanner = Scanner(System.`in`)\n val str = scanner.next()\n for (i in 1 until str.length) {\n if (!(str[i] in charArrayOf('a', 'o', 'u', 'i', 'e')) && !(str[i - 1] in charArrayOf('a', 'o', 'u', 'i', 'e', 'n'))) {\n println(\"NO\")\n return\n }\n }\n if (str.last() in charArrayOf('a', 'o', 'u', 'i', 'e', 'n'))\n println(\"YES\")\n else\n println(\"NO\")\n\n\n\n}\n\n\nclass Parser(`in`: InputStream) {\n private val BUFFER_SIZE = 1 shl 16\n private val din: DataInputStream\n private val buffer: ByteArray\n private var bufferPointer: Int = 0\n private var bytesRead: Int = 0\n\n init {\n din = DataInputStream(`in`)\n buffer = ByteArray(BUFFER_SIZE)\n bytesRead = 0\n bufferPointer = bytesRead\n }\n\n fun nextString(maxSize: Int): String {\n val ch = ByteArray(maxSize)\n var point = 0\n try {\n var c = read()\n while (c == ' '.toByte() || c == '\\n'.toByte() || c == '\\r'.toByte())\n c = read()\n while (c != ' '.toByte() && c != '\\n'.toByte() && c != '\\r'.toByte()) {\n ch[point++] = c\n c = read()\n }\n } catch (e: Exception) {}\n\n return String(ch, 0, point)\n }\n\n fun nextInt(): Int {\n var ret = 0\n val neg: Boolean\n try {\n var c = read()\n while (c <= ' '.toByte())\n c = read()\n neg = c == '-'.toByte()\n if (neg)\n c = read()\n do {\n ret = ret * 10 + c - '0'.toInt()\n c = read()\n } while (c > ' '.toByte())\n\n if (neg) return -ret\n } catch (e: Exception) {}\n return ret\n }\n\n fun nextLong(): Long {\n var ret: Long = 0\n val neg: Boolean\n try {\n var c = read()\n while (c <= ' '.toByte())\n c = read()\n neg = c == '-'.toByte()\n if (neg)\n c = read()\n do {\n ret = ret * 10 + c - '0'.toLong()\n c = read()\n } while (c > ' '.toByte())\n\n if (neg) return -ret\n } catch (e: Exception) {}\n\n return ret\n }\n\n fun nextDouble(): Double\n = nextString(10000).toDouble()\n\n private fun fillBuffer() {\n try {\n bytesRead = din.read(buffer, 0, BUFFER_SIZE)\n } catch (e: Exception) {}\n if (bytesRead == -1) buffer[0] = -1\n }\n\n private fun read(): Byte {\n if (bufferPointer == bytesRead) fillBuffer()\n return buffer[bufferPointer++]\n }\n}\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\nfun IntArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun LongArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun BooleanArray.print() {\n println(Arrays.toString(this))\n}\nfun nod(a: Long, b: Long): Long {\n var a1 = a\n var b1 = b\n while (a1 != 0L && b1 != 0L) {\n if (a1 < b1)\n b1 %= a1\n else\n a1 %= b1\n }\n return a1 + b1\n}\nfun nok(a: Long, b: Long): Long = a * b / nod(a, b)\nfun min(a: Char, b: Char): Int {\n if (a < b)\n return a.toInt()\n return b.toInt()\n}\nfun max(a: Char, b: Char): Int {\n if (a > b)\n return a.toInt()\n return b.toInt()\n}"}, {"source_code": "import javax.print.attribute.IntegerSyntax\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nfun isDiverse(s: String): Boolean {\n val sortedSet = s.toSortedSet()\n return sortedSet.size == s.length &&\n sortedSet.last().toInt() - sortedSet.first().toInt() + 1 == sortedSet.size\n}\n\nfun fine(s: String): Boolean {\n val vowels = \"aeiou\"\n val vowelsAndN = \"aeioun\"\n\n if(s[s.length-1] !in vowelsAndN) return false\n\n for (i in 1 until s.length) {\n if (s[i - 1] !in vowelsAndN && s[i] !in vowels) return false\n }\n\n return true\n}\n\nfun main(args: Array) {\n val s = readLn()\n\n println(if (fine(s)) \"YES\" else \"NO\")\n}\n"}, {"source_code": "fun main(args: Array) {\n val str1 = readLine()!!\n val exc = setOf(\"a\", \"o\", \"u\", \"i\", \"e\")\n var prev = \"\"\n\n for (it in str1.split(\"\")) {\n if (prev.isEmpty() || exc.contains(prev) || prev == \"n\") {\n prev = it\n continue\n }\n\n if (!exc.contains(it)) {\n println(\"NO\")\n return\n }\n\n prev = it\n }\n\n println(\"YES\")\n}\n\n"}, {"source_code": "fun main() {\n val vowel = listOf('a', 'o', 'u', 'i', 'e')\n val str = readLine()!!\n var ans = mutableListOf()\n for (i in str) {\n if (vowel.contains(i)) {\n ans.add(1)\n } else if (i == 'n') {\n ans.add(2)\n } else {\n ans.add(0)\n }\n }\n for (i in 1 until ans.size) {\n if (ans[i] == 0) {\n if (ans[i - 1] != 1 && ans[i - 1] != 2) {\n println(\"NO\")\n return\n }\n } else if (ans[i] == 1) {\n if (ans[i - 1] != 1 && ans[i - 1] != 2 && ans[i - 1] != 0) {\n println(\"NO\")\n return\n }\n } else {\n if (ans[i - 1] == 0) {\n println(\"NO\")\n return\n }\n }\n }\n\n if (ans[ans.size - 1] != 1 && ans[ans.size - 1] != 2) {\n println(\"NO\")\n } else {\n println(\"YES\")\n }\n\n}"}, {"source_code": "fun main() {\n val s = readLine()!!\n val notConsonant = setOf('a', 'e', 'i', 'o', 'u', 'n')\n val vowel = setOf('a', 'e', 'i', 'o', 'u')\n for ((pos, c) in s.withIndex()) {\n if (c !in notConsonant && pos == s.lastIndex) return print(\"NO\")\n if (c !in notConsonant && s[pos + 1] !in vowel) return print(\"NO\")\n }\n print(\"YES\")\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.HashSet\n\npublic class programkt {\n\n public companion object {\n\n private val vowels = HashSet(arrayListOf('a', 'e', 'i', 'o', 'u'))\n private val noRestrictions = HashSet(arrayListOf('a', 'e', 'i', 'o', 'u', 'n'))\n\n private fun isCorrect(str: String): Boolean {\n str.forEachIndexed() { ind, c ->\n if (!noRestrictions.contains(c)) {\n if (ind == str.length - 1) return false\n else if (!vowels.contains(str[ind + 1])) return false\n }\n }\n\n return true\n }\n\n @JvmStatic\n public fun main(args: Array) {\n val scan = Scanner(System.`in`)\n\n val str = scan.nextLine().trim()\n\n println(if (isCorrect(str)) \"YES\" else \"NO\")\n }\n }\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.HashSet\n\nclass ProgramKT {\n\n companion object {\n\n private val vowels = HashSet(arrayListOf('a', 'e', 'i', 'o', 'u'))\n private val noRestrictions = HashSet(arrayListOf('a', 'e', 'i', 'o', 'u', 'n'))\n\n private fun isCorrect(str: String): Boolean {\n str.forEachIndexed() { ind, c ->\n if (!noRestrictions.contains(c)) {\n if (ind == str.length - 1) return false\n else if (!vowels.contains(str[ind + 1])) return false\n }\n }\n\n return true\n }\n\n @JvmStatic\n fun main(args: Array) {\n val scan = Scanner(System.`in`)\n\n val str = scan.nextLine().trim()\n\n println(if (isCorrect(str)) \"YES\" else \"NO\")\n }\n }\n}"}, {"source_code": "fun main(arg: Array){\n\tval string = readLine().toString()\n\tvar univ = setOf('a','e','i','o','u','n')\n\tvar glas = setOf('a','e','i','o','u')\n\tif (string.last() in univ){\n\t\tvar prev = 'a'\n\t\tstring.forEach(){\n//\t\t\tprintln(it)\n\t\t\tif (!(prev in univ) and !(it in glas)){\n\t\t\t\t\tprintln(\"NO\")\n\t\t\t\t\treturn\n\t\t\t}\n\t\t\tprev = it\n\t\t}\n\t\tprintln(\"YES\")\n\t}else{\n\t\tprintln(\"NO\")\n\t\treturn\n\t}\n}"}], "negative_code": [{"source_code": "fun isVowel(c: Char): Boolean {\n return c in \"aeiou\"\n}\n\nfun main(args: Array) {\n\n val s = readLine()!!\n val good: Boolean = (0..s.length - 1).none { !isVowel(s[it]) && s[it] != 'n' && it + 1 < s.length && !isVowel(s[it + 1]) }\n\n if (good) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashSet\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\nfun main(args : Array) {\n Thread { run() }.start()\n}\n\nfun run() {\n\n val scanner = Scanner(System.`in`)\n val str = scanner.next()\n for (i in 1 until str.length) {\n if (!(str[i] in charArrayOf('a', 'o', 'u', 'i', 'e', 'n')) && !(str[i - 1] in charArrayOf('a', 'o', 'u', 'i', 'e', 'n'))) {\n println(\"NO\")\n return\n }\n }\n println(\"YES\")\n\n}\n\n\nclass Parser(`in`: InputStream) {\n private val BUFFER_SIZE = 1 shl 16\n private val din: DataInputStream\n private val buffer: ByteArray\n private var bufferPointer: Int = 0\n private var bytesRead: Int = 0\n\n init {\n din = DataInputStream(`in`)\n buffer = ByteArray(BUFFER_SIZE)\n bytesRead = 0\n bufferPointer = bytesRead\n }\n\n fun nextString(maxSize: Int): String {\n val ch = ByteArray(maxSize)\n var point = 0\n try {\n var c = read()\n while (c == ' '.toByte() || c == '\\n'.toByte() || c == '\\r'.toByte())\n c = read()\n while (c != ' '.toByte() && c != '\\n'.toByte() && c != '\\r'.toByte()) {\n ch[point++] = c\n c = read()\n }\n } catch (e: Exception) {}\n\n return String(ch, 0, point)\n }\n\n fun nextInt(): Int {\n var ret = 0\n val neg: Boolean\n try {\n var c = read()\n while (c <= ' '.toByte())\n c = read()\n neg = c == '-'.toByte()\n if (neg)\n c = read()\n do {\n ret = ret * 10 + c - '0'.toInt()\n c = read()\n } while (c > ' '.toByte())\n\n if (neg) return -ret\n } catch (e: Exception) {}\n return ret\n }\n\n fun nextLong(): Long {\n var ret: Long = 0\n val neg: Boolean\n try {\n var c = read()\n while (c <= ' '.toByte())\n c = read()\n neg = c == '-'.toByte()\n if (neg)\n c = read()\n do {\n ret = ret * 10 + c - '0'.toLong()\n c = read()\n } while (c > ' '.toByte())\n\n if (neg) return -ret\n } catch (e: Exception) {}\n\n return ret\n }\n\n fun nextDouble(): Double\n = nextString(10000).toDouble()\n\n private fun fillBuffer() {\n try {\n bytesRead = din.read(buffer, 0, BUFFER_SIZE)\n } catch (e: Exception) {}\n if (bytesRead == -1) buffer[0] = -1\n }\n\n private fun read(): Byte {\n if (bufferPointer == bytesRead) fillBuffer()\n return buffer[bufferPointer++]\n }\n}\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\nfun IntArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun LongArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun BooleanArray.print() {\n println(Arrays.toString(this))\n}\nfun nod(a: Long, b: Long): Long {\n var a1 = a\n var b1 = b\n while (a1 != 0L && b1 != 0L) {\n if (a1 < b1)\n b1 %= a1\n else\n a1 %= b1\n }\n return a1 + b1\n}\nfun nok(a: Long, b: Long): Long = a * b / nod(a, b)\nfun min(a: Char, b: Char): Int {\n if (a < b)\n return a.toInt()\n return b.toInt()\n}\nfun max(a: Char, b: Char): Int {\n if (a > b)\n return a.toInt()\n return b.toInt()\n}"}, {"source_code": "import javax.print.attribute.IntegerSyntax\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nfun isDiverse(s: String): Boolean {\n val sortedSet = s.toSortedSet()\n return sortedSet.size == s.length &&\n sortedSet.last().toInt() - sortedSet.first().toInt() + 1 == sortedSet.size\n}\n\nfun fine(s: String): Boolean {\n val vowels = \"aeiou\"\n val vowelsAndN = \"aeioun\"\n\n if(s.length == 1 && s !in vowelsAndN) return false\n\n for (i in 1 until s.length) {\n if (s[i - 1] !in vowelsAndN && s[i] !in vowels) return false\n }\n\n return true\n}\n\nfun main(args: Array) {\n val s = readLn()\n\n println(if (fine(s)) \"YES\" else \"NO\")\n}\n"}, {"source_code": "import javax.print.attribute.IntegerSyntax\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nfun isDiverse(s: String): Boolean {\n val sortedSet = s.toSortedSet()\n return sortedSet.size == s.length &&\n sortedSet.last().toInt() - sortedSet.first().toInt() + 1 == sortedSet.size\n}\n\nfun fine(s: String): Boolean {\n val vowels = \"aeiou\"\n val vowelsAndN = \"aeioun\"\n\n for (i in 1 until s.length) {\n if (s[i - 1] !in vowelsAndN && s[i] !in vowels) return false\n }\n\n return true\n}\n\nfun main(args: Array) {\n val s = readLn()\n\n println(if (fine(s)) \"YES\" else \"NO\")\n}\n"}, {"source_code": "fun main(args: Array) {\n val str1 = readLine()!!\n val exc = setOf(\"a\", \"o\", \"u\", \"i\", \"e\", \"n\")\n var prev = \"\"\n\n for (it in str1.split(\"\")) {\n if (prev.isEmpty() || exc.contains(prev)) {\n prev = it\n continue\n }\n\n if (!exc.contains(it)) {\n println(\"NO\")\n return\n }\n\n prev = it\n }\n\n println(\"YES\")\n}\n\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\nfun main() {\n var sc = Scanner(System.`in`)\n var str = sc.next()\n\n var list = listOf('a', 'u', 'e', 'o', 'i')\n\n var array = Array(str.length+2,{true})\n var i = 0\n while (i('a', 'u', 'e', 'o', 'i')\n\n var array = Array(str.length + 2, { true })\n var i = 0\n while (i < str.length) {\n if (!list.contains(str[i]) && str[i] != 'n') {\n array[i] = false\n }\n i++\n }\n var flag = false\n if (str.length == 2 && !list.contains(str[0]) && str[0]!='n') {\n flag = true\n } else {\n var j = 0\n while (j < array.size - 1) {\n if (array[j] == false && array[j + 1] == false) {\n flag = true\n }\n if (array[j] == false && str[j + 1] == 'n') {\n flag = true\n }\n j++\n }\n }\n if (!array[array.size - 3]) {\n flag = true\n }\n if (flag) {\n println(\"NO\")\n } else {\n println(\"YES\")\n }\n}\n\n\n\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\nfun main() {\n var sc = Scanner(System.`in`)\n var str = sc.next() + \"e\"\n\n var list = listOf('a', 'u', 'e', 'o', 'i')\n\n var array = Array(str.length + 2, { true })\n var i = 0\n while (i < str.length) {\n if (!list.contains(str[i]) && str[i] != 'n') {\n array[i] = false\n }\n i++\n }\n var j = 0\n var flag = false\n while (j < array.size - 1) {\n if (array[j] == false && array[j + 1] == false) {\n flag = true\n }\n if (array[j] == false && str[j + 1] == 'n') {\n flag = true\n }\n j++\n }\n if (!array[array.size - 3]) {\n flag = true\n }\n if (flag) {\n println(\"NO\")\n } else {\n println(\"YES\")\n }\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\nfun main() {\n var sc = Scanner(System.`in`)\n var str = sc.next() + \"e\"\n\n var list = listOf('a', 'u', 'e', 'o', 'i')\n\n var array = Array(str.length + 2, { true })\n var i = 0\n while (i < str.length) {\n if (!list.contains(str[i]) && str[i] != 'n') {\n array[i] = false\n }\n i++\n }\n var flag = false\n if (str.length == 2 && !list.contains(str[0]) && str[0]!='n') {\n flag = true\n } else {\n var j = 0\n while (j < array.size - 1) {\n if (array[j] == false && array[j + 1] == false) {\n flag = true\n }\n if (array[j] == false && str[j + 1] == 'n') {\n flag = true\n }\n j++\n }\n }\n if (!array[array.size - 3]) {\n flag = true\n }\n if (!list.contains(str[str.length-2]) && str[str.length-1]!='n'){\n flag = true\n }\n if (flag) {\n println(\"NO\")\n } else {\n println(\"YES\")\n }\n}\n\n\n\n"}, {"source_code": "fun main() {\n val s = readLine()!!\n val notConsonant = setOf('a', 'e', 'i', 'o', 'u', 'n')\n for ((pos, c) in s.withIndex()) {\n if (c !in notConsonant && pos == s.lastIndex) return print(\"NO\")\n if (c !in notConsonant && s[pos + 1] !in notConsonant) return print(\"NO\")\n }\n print(\"YES\")\n}"}, {"source_code": "fun main(arg: Array){\n\tval string = readLine().toString()\n\tvar univ = setOf('a','e','i','o','u','n')\n\tvar glas = setOf('a','e','i','o','u')\n\tif (string.last() in univ){\n\t\tvar prev = 'a'\n\t\tstring.forEach(){\n\t\t\tprintln(it)\n\t\t\tif (!(prev in univ) and !(it in glas)){\n\t\t\t\t\tprintln(\"NO\")\n\t\t\t\t\treturn\n\t\t\t}\n\t\t\tprev = it\n\t\t}\n\t\tprintln(\"YES\")\n\t}else{\n\t\tprintln(\"NO\")\n\t\treturn\n\t}\n}"}, {"source_code": "fun main(arg: Array){\n\tval string = readLine().toString()\n\tvar glas = setOf('a','e','i','o','u','n')\n\tif (string.last() in glas){\n\t\tvar prev = 'a'\n\t\tstring.reversed().forEach(){\n\t\t\tif (!(prev in glas)){\n\t\t\t\tif (!(it in glas)){\n\t\t\t\t\tprintln(\"NO\")\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t\tprev = it\n\t\t}\n\t\tprintln(\"YES\")\n\t}else{\n\t\tprintln(\"NO\")\n\t\treturn\n\t}\n}"}, {"source_code": "fun main(arg: Array){\n\tval string = readLine().toString()\n\tvar univ = setOf('a','e','i','o','u','n')\n\tvar glas = setOf('a','e','i','o','u')\n\tif (string.last() in glas){\n\t\tvar prev = 'a'\n\t\tstring.forEach(){\n//\t\t\tprintln(it)\n\t\t\tif (!(prev in univ) and !(it in glas)){\n\t\t\t\t\tprintln(\"NO\")\n\t\t\t\t\treturn\n\t\t\t}\n\t\t\tprev = it\n\t\t}\n\t\tprintln(\"YES\")\n\t}else{\n\t\tprintln(\"NO\")\n\t\treturn\n\t}\n}"}], "src_uid": "a83144ba7d4906b7692456f27b0ef7d4"} {"nl": {"description": "Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly k months. He looked at the calendar and learned that at the moment is the month number s. Vasya immediately got interested in what month Codecraft III will appear. Help him understand that.All the twelve months in Vasya's calendar are named using their usual English names: January, February, March, April, May, June, July, August, September, October, November, December.", "input_spec": "The first input line contains the name of the current month. It is guaranteed that it is a proper English name of one of twelve months. The first letter is uppercase, the rest are lowercase. The second line contains integer k (0 ≤ k ≤ 100) — the number of months left till the appearance of Codecraft III.", "output_spec": "Print starting from an uppercase letter the name of the month in which the continuation of Codeforces II will appear. The printed name must be contained in the list January, February, March, April, May, June, July, August, September, October, November, December.", "sample_inputs": ["November\n3", "May\n24"], "sample_outputs": ["February", "May"], "notes": null}, "positive_code": [{"source_code": "import java.util.Scanner\n\nfun main(args : Array) {\n\n val reader = Scanner(System.`in`)\n val m = readLine()!!\n var n: Int = reader.nextInt()\n val list = arrayOf(\"January\",\"February\",\"March\",\"April\",\"May\",\"June\",\"July\",\"August\",\"September\",\"October\",\"November\",\"December\")\n\n var a = 0\n\n for(i in 0..11){\n if(m==list[i]){\n a = i\n break\n }\n }\n\n n = n%12\n\n println(list[(a + n)%12])\n\n}"}, {"source_code": "fun main() {\n val month = readLine()!!\n val nextMonthNumber = readLine()!!\n\n val monthNumber = months.indexOf(month)\n val result = (monthNumber + nextMonthNumber.toInt() % 12) % 12\n println(months[result])\n}\n\nval months = arrayOf(\n \"January\",\n \"February\",\n \"March\",\n \"April\",\n \"May\",\n \"June\",\n \"July\",\n \"August\",\n \"September\",\n \"October\",\n \"November\",\n \"December\"\n)"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val nameToNumber = mapOf(\"January\" to 0, \"February\" to 1, \"March\" to 2, \"April\" to 3, \"May\" to 4, \"June\" to 5,\n \"July\" to 6, \"August\" to 7, \"September\" to 8, \"October\" to 9, \"November\" to 10, \"December\" to 11)\n val numberToName = arrayOf(\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\",\n \"September\", \"October\", \"November\", \"December\")\n println(numberToName[(nameToNumber[readLine()!!]!! + readInt()) % 12])\n}\n"}, {"source_code": "fun main(args: Array) {\n val month = readLine()\n val cnt = readLine()!!.toInt()\n\n val allMonths = listOf(\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\")\n var currMonthIndex = allMonths.indexOf(month)\n\n for (i in 1 .. cnt)\n {\n if (++currMonthIndex > 11)\n currMonthIndex -= 12\n }\n\n print(allMonths[currMonthIndex])\n}\n"}], "negative_code": [], "src_uid": "a307b402b20554ce177a73db07170691"} {"nl": {"description": "Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to k. The worst mark is 1, the best is k. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8, 9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8, 8, 9], Noora will have graduation certificate with 8.To graduate with «A» certificate, Noora has to have mark k.Noora got n marks in register this year. However, she is afraid that her marks are not enough to get final mark k. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to k. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to k.", "input_spec": "The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ k) denoting marks received by Noora before Leha's hack.", "output_spec": "Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.", "sample_inputs": ["2 10\n8 9", "3 5\n4 4 4"], "sample_outputs": ["4", "3"], "notes": "NoteConsider the first example testcase.Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to . Consequently, new final mark is 10. Less number of marks won't fix the situation.In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate."}, "positive_code": [{"source_code": "/**\n * Created by seydazimovnurbol on 5/23/17.\n */\n\nimport java.util.*\nimport kotlin.system.exitProcess\n\nfun main(args: Array ) {\n var scanner : Scanner = Scanner(System.`in`)\n var n = scanner.nextInt()\n var k = scanner.nextInt()\n\n var a : ArrayList = ArrayList()\n\n var sum : Double = 0.0\n for (i in 1 .. n) {\n var x = scanner.nextInt()\n a.add(x)\n sum += x\n }\n sum /= n\n var cntK : Int = 0\n for (i in 0 .. n - 1)\n if (a[i] == k) cntK++;\n\n var need : Int = 0\n for (i in 0 .. n - 1) {\n if (a[i] < k) {\n var cnt : Int = k - 1 - a[i]\n a[i] += Math.min(cnt, cntK)\n cntK -= Math.min(cnt, cntK)\n need += k - 1 - a[i]\n }\n }\n\n // [A] [B]\n\n var cntOther : Int = n - cntK\n if (cntK >= cntOther) println(0)\n else if (need == 0) println(cntOther - cntK)\n else println(need + n + need)\n}"}, {"source_code": "\nfun main(args: Array) {\n val (n, k) = readLine()!!.split(\" \").map { it.toInt() }\n val list = readLine()!!.split(\" \").map { it.toInt() }\n var sum = 0\n var count = list.size\n list.forEach { it -> sum += it }\n while (true) {\n if (Math.round(sum.toFloat()/count) == k) {\n break\n }\n sum += k\n count++\n }\n print(count - list.size)\n}"}, {"source_code": "fun main(args: Array) {\n val x = readLine()!!.split(\" \")\n var courses = x[0].toInt()\n val mark = x[1].toInt()\n\n var sum = readLine()!!.split(\" \").map { it.toInt() }.sum().toDouble()\n\n var ans = 0\n var curMark = sum / courses\n while ((curMark + .5).toInt() < mark){\n sum += mark\n courses++\n curMark = sum / courses\n ans++\n }\n println(ans)\n}"}, {"source_code": "fun main(args: Array){\n val reg = Regex(\" \")\n var s = readLine()!!.split(reg)\n var n = s[0].toInt()\n val k = s[1].toInt()\n s = readLine()!!.split(reg)\n var sum = s.sumBy { it.toInt() }\n val need = (k - 1).toDouble() + 0.5\n var ans = 0\n while (sum.toDouble() / n.toDouble() < need){\n sum += k\n ++n\n ++ans\n }\n print(ans)\n}"}, {"source_code": "import java.util.*\n\n/**\n * Created by apple on 2017/5/22.\n */\nfun main(args:Array) {\n var scanner:Scanner = Scanner(System.`in`)\n\n var n = scanner.nextInt()\n var k = scanner.nextInt()\n\n var sum = 0\n\n for (i in 0..n-1) {\n var a = scanner.nextInt()\n sum += a\n }\n\n var ans = 0\n\n while (!accept(sum, k, n + ans)) {\n sum += k\n ans++\n }\n println(ans)\n}\n\nfun accept(sum:Int, k:Int, count:Int) : Boolean{\n if (Math.round(1.0 * sum / count) >= k) {\n return true\n }\n return false\n}"}, {"source_code": "import kotlin.math.max\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numMarks, k) = readInts()\n val arr = readInts()\n print(max(0, ((arr.sum() - numMarks * (k - 0.5)) / -0.5).toInt()))\n}"}, {"source_code": "import java.io.InputStream\nimport java.math.BigDecimal\nimport java.math.BigInteger\n\nfun main(args: Array) = input.run {\n var n = nextInt()\n var k = nextInt()\n var a = nextInts(n)\n var sum = a.sum()\n var ans = 0\n while (2 * sum < 2 * k * n - n) {\n ++ans\n ++n\n sum += k\n }\n println(ans)\n}\n\nval input = FastScanner()\n\nfun String.toBigInteger() = BigInteger(this)\nfun String.toBigDecimal() = BigDecimal(this)\n\nclass FastScanner(private val input: InputStream = System.`in`) {\n private val sb = StringBuilder()\n private val buffer = ByteArray(4096)\n private var pos = 0\n private var size = 0\n\n fun nextString(): String? {\n var c = skipWhitespace()\n if (c < 0) return null\n\n return sb.run {\n setLength(0)\n\n do {\n append(c.toChar())\n c = read()\n } while (c > ' '.toInt())\n\n toString()\n }\n }\n\n fun nextLine(): String? {\n var c = read()\n if (c < 0) return null\n\n return sb.run {\n setLength(0)\n\n while (c >= 0 && c != '\\n'.toInt()) {\n append(c.toChar())\n c = read()\n }\n\n toString()\n }\n }\n\n fun nextLong(): Long {\n var c = skipWhitespace()\n\n val sign = if (c == '-'.toInt()) {\n c = read()\n -1\n } else 1\n\n var ans = 0L\n\n while (c > ' '.toInt()) {\n ans = ans * 10 + c - '0'.toInt()\n c = read()\n }\n\n return sign * ans\n }\n\n fun nextInt() = nextLong().toInt()\n fun nextDouble() = nextString()?.toDouble() ?: 0.0\n fun nextBigInteger(): BigInteger = nextString()?.toBigInteger() ?: BigInteger.ZERO\n fun nextBigDecimal(): BigDecimal = nextString()?.toBigDecimal() ?: BigDecimal.ZERO\n\n fun nextStrings(n: Int) = Array(n) { nextString() ?: \"\" }\n fun nextInts(n: Int) = IntArray(n) { nextInt() }\n fun nextLongs(n: Int) = LongArray(n) { nextLong() }\n fun nextDoubles(n: Int) = DoubleArray(n) { nextDouble() }\n fun nextBigIntegers(n: Int) = Array(n) { nextBigInteger() }\n fun nextBigDecimals(n: Int) = Array(n) { nextBigDecimal() }\n\n fun nextStrings(n: Int, m: Int) = Array(n) { nextStrings(m) }\n fun nextInts(n: Int, m: Int) = Array(n) { nextInts(m) }\n fun nextLongs(n: Int, m: Int) = Array(n) { nextLongs(m) }\n fun nextDoubles(n: Int, m: Int) = Array(n) { nextDoubles(m) }\n fun nextBigIntegers(n: Int, m: Int) = Array(n) { nextBigIntegers(m) }\n fun nextBigDecimals(n: Int, m: Int) = Array(n) { nextBigDecimals(m) }\n\n private fun skipWhitespace(): Int {\n while (true) {\n val c = read()\n if (c > ' '.toInt() || c < 0) return c\n }\n }\n\n private fun read(): Int {\n while (pos >= size) {\n if (size < 0) return -1\n size = input.read(buffer, 0, buffer.size)\n pos = 0\n }\n return buffer[pos++].toInt()\n }\n}"}, {"source_code": "\nfun main(args: Array) {\n\n var x= readLine()?.split(\" \")\n var n:Int = Integer.parseInt(x!![0])\n var k:Int = Integer.parseInt(x!![1])\n x= readLine()?.split(\" \")\n var sum:Double=0.0\n for(i in 1..n){\n sum+=Integer.parseInt(x!![i-1])\n }\n var avg:Double=sum/n\n if(avg+.5>=k){\n println(0)\n return\n }\n var c=0\n while (true){\n sum+=k\n n++\n c++\n avg=sum/n\n if(avg+.5>=k)break\n }\n println(c)\n\n}\n"}, {"source_code": "fun main(args: Array) {\n var (n, k) = readLine()!!.split(' ').map(String::toInt)\n var total = 0\n readLine()!!.split(' ').map(String::toInt).forEach {\n total += it\n }\n var ans = 0\n while (true) {\n // print(\"$n $total\\n\")\n if (total / n >= k)\n break\n else if (total / n >= k - 1 && total % n >= (n+1) / 2)\n break\n ans++\n n++\n total += k\n }\n print(\"$ans\\n\")\n}\n"}], "negative_code": [{"source_code": "/**\n * Created by seydazimovnurbol on 5/23/17.\n */\n\nimport java.util.*\n\nfun main(args: Array ) {\n\n var scanner : Scanner = Scanner(System.`in`)\n var n = scanner.nextInt()\n var k = scanner.nextInt()\n\n var a : ArrayList = ArrayList()\n\n for (i in 1 .. n) {\n var x = scanner.nextInt()\n a.add(x)\n }\n\n var cntK : Int = 0\n for (i in 0 .. n - 1)\n if (a[i] == k) cntK++;\n\n var need : Int = 0\n for (i in 0 .. n - 1) {\n if (a[i] < k) {\n var cnt : Int = k - 1 - a[i]\n a[i] += Math.min(cnt, cntK)\n cntK -= Math.min(cnt, cntK)\n need += k - 1 - a[i]\n }\n }\n\n println(n + 2 * need)\n\n}"}, {"source_code": "/**\n * Created by seydazimovnurbol on 5/23/17.\n */\n\nimport java.util.*\nimport kotlin.system.exitProcess\n\nfun main(args: Array ) {\n var scanner : Scanner = Scanner(System.`in`)\n var n = scanner.nextInt()\n var k = scanner.nextInt()\n\n var a : ArrayList = ArrayList()\n\n var sum : Double = 0.0\n for (i in 1 .. n) {\n var x = scanner.nextInt()\n a.add(x)\n sum += x\n }\n sum /= n\n var cntK : Int = 0\n for (i in 0 .. n - 1)\n if (a[i] == k) cntK++;\n\n var need : Int = 0\n for (i in 0 .. n - 1) {\n if (a[i] < k) {\n var cnt : Int = k - 1 - a[i]\n a[i] += Math.min(cnt, cntK)\n cntK -= Math.min(cnt, cntK)\n need += k - 1 - a[i]\n }\n }\n\n if (sum + 0.5 >= k) println(0)\n else println(n + 2 * need)\n}"}, {"source_code": "/**\n * Created by seydazimovnurbol on 5/23/17.\n */\n\nimport java.util.*\n\nfun main(args: Array ) {\n\n var scanner : Scanner = Scanner(System.`in`)\n var n = scanner.nextInt()\n var k = scanner.nextInt()\n\n var a : ArrayList = ArrayList()\n\n for (i in 1 .. n) {\n var x = scanner.nextInt()\n a.add(x)\n }\n\n var cntK : Int = 0\n for (i in 0 .. n - 1)\n if (a[i] == k) cntK++;\n\n var need : Int = 0\n for (i in 0 .. n - 1) {\n if (a[i] < k) {\n var cnt : Int = k - 1 - a[i]\n a[i] += Math.min(cnt, cntK)\n cntK -= Math.min(cnt, cntK)\n need += k - 1 - a[i]\n }\n }\n\n if (need == 0) println(0);\n else println(n + 2 * need)\n\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numMarks, k) = readInts()\n val arr = readInts()\n print(((arr.sum() - numMarks * (k - 0.5)) / -0.5).toInt())\n}"}], "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900"} {"nl": {"description": "To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings.More formally, for each invited person the following conditions should be fulfilled: all his friends should also be invited to the party; the party shouldn't have any people he dislikes; all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people a1 and ap are connected through a chain of common friends if there exists a sequence of people a2, a3, ..., ap - 1 such that all pairs of people ai and ai + 1 (1 ≤ i < p) are friends. Help the Beaver find the maximum number of acquaintances he can invite.", "input_spec": "The first line of input contains an integer n — the number of the Beaver's acquaintances. The second line contains an integer k — the number of pairs of friends. Next k lines contain space-separated pairs of integers ui, vi — indices of people who form the i-th pair of friends. The next line contains an integer m — the number of pairs of people who dislike each other. Next m lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once . In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: 2 ≤ n ≤ 14 The input limitations for getting 100 points are: 2 ≤ n ≤ 2000 ", "output_spec": "Output a single number — the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0.", "sample_inputs": ["9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9"], "sample_outputs": ["3"], "notes": "NoteLet's have a look at the example. Two groups of people can be invited: {1, 2, 3} and {4, 5}, thus the answer will be the size of the largest of these groups. Group {6, 7, 8, 9} doesn't fit, since it includes people 7 and 9 who dislike each other. Group {1, 2, 3, 4, 5} also doesn't fit, because not all of its members are connected by a chain of common friends (for example, people 2 and 5 aren't connected)."}, "positive_code": [{"source_code": "import java.util.*\nimport kotlin.math.exp\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single Int\nprivate fun readInts() = readStrings().map { it.toInt() } // list of Ints\nprivate fun readStrings() = readLn().trim().split(\" \") // list of strings\n\n\nfun dfs(\n start: Int,\n friends: Map>,\n dislike: Map>,\n seen: MutableSet\n): Pair {\n val visited = mutableSetOf()\n val stack = ArrayDeque()\n stack.add(start)\n seen.add(start)\n visited.add(start)\n val bad = dislike[start] ?: mutableSetOf()\n while (stack.isNotEmpty()) {\n val node = stack.pop()\n for (neb in friends[node] ?: mutableListOf()) {\n if (neb in bad) {\n return Pair(false, -1)\n } else if (neb !in visited) {\n visited.add(neb)\n seen.add(neb)\n bad.addAll(dislike[neb] ?: mutableSetOf())\n stack.add(neb)\n }\n }\n }\n return Pair(true, visited.size)\n}\n\n\nfun main(args: Array) {\n val n = readInt()\n val pairs = readInt()\n val friends = mutableMapOf>()\n val dislike = mutableMapOf>()\n for (i in 0 until pairs) {\n val (u, v) = readInts()\n friends.computeIfAbsent(u) { mutableListOf() }\n friends.computeIfAbsent(v) { mutableListOf() }\n\n friends[u]!!.add(v)\n friends[v]!!.add(u)\n }\n val x = readInt()\n for (i in 0 until x) {\n val (u, v) = readInts()\n dislike.computeIfAbsent(u) { mutableSetOf() }\n dislike.computeIfAbsent(v) { mutableSetOf() }\n dislike[u]!!.add(v)\n }\n var res = 0\n val seen = mutableSetOf()\n for (i in 1 until n + 1) {\n if (i !in seen) {\n val p = dfs(i, friends, dislike, seen)\n if (p.first) {\n res = Math.max(res, p.second)\n }\n }\n }\n println(res)\n}\n"}], "negative_code": [], "src_uid": "e1ebaf64b129edb8089f9e2f89a0e1e1"} {"nl": {"description": "PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: \"There exists such a positive integer n that for each positive integer m number n·m + 1 is a prime number\".Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any n.", "input_spec": "The only number in the input is n (1 ≤ n ≤ 1000) — number from the PolandBall's hypothesis. ", "output_spec": "Output such m that n·m + 1 is not a prime number. Your answer will be considered correct if you output any suitable m such that 1 ≤ m ≤ 103. It is guaranteed the the answer exists.", "sample_inputs": ["3", "4"], "sample_outputs": ["1", "2"], "notes": "NoteA prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.For the first sample testcase, 3·1 + 1 = 4. We can output 1.In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, m = 2 is okay since 4·2 + 1 = 9, which is not a prime number."}, "positive_code": [{"source_code": "import kotlin.math.sqrt\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n fun prime(i: Int) = (2..sqrt(i.toDouble()).toInt()).none { i % it == 0 }\n val n = r.readLine()!!.toInt()\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }.toSet().toList().sorted()\n var m = 1\n while (prime(m*n+1)){\n m++\n }\n println(m)\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n\n var m = 1\n while (m <= 1000) {\n\n if (!isPrime(n * m + 1)) {\n println(m)\n return\n }\n m++\n }\n\n}\n\nfun isPrime(n: Int): Boolean {\n var i = 2\n\n while (i * i <= n) {\n\n if (n % i == 0)\n return false\n\n i++\n }\n\n return true\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args : Array) {\n //====== Input preparations ========================================================\n// val fin = BufferedReader(FileReader(\"a.in\"))\n val fin = BufferedReader(InputStreamReader(System.`in`))\n val fout = PrintWriter (System.out)\n var tokenizer = StringTokenizer(\"\")\n fun next() : String {\n while (!tokenizer.hasMoreTokens())\n tokenizer = StringTokenizer(fin.readLine())\n return tokenizer.nextToken()\n }\n fun nextInt() = next().toInt()\n fun nextPair() = nextInt() to nextInt()\n fun nextPairDec() = nextInt()-1 to nextInt()-1\n //====== Solution below ============================================================\n fun gcd (a: Int, b: Int) : Int = if (a == 0) b else gcd(b%a, a)\n fun isprime(a: Int) = (2..a-1).none { a % it == 0 }\n val n = nextInt()\n// for (n in 1..1000) {\n for (i in 2..1000) {\n if (gcd(i, n) == 1 && !isprime(i)) {\n for (j in 1..i - 1) {\n if (j * n % i == i - 1) {\n fout.println(j)\n break\n }\n }\n break\n }\n }\n// }\n\n\n fout.close()\n fin.close()\n}\n\n"}, {"source_code": "import java.lang.String.format\nimport java.util.*\nimport kotlin.math.*\nimport kotlin.system.exitProcess\n\nprivate fun readLn()=readLine()!! // string line\nprivate fun readInt()=readLn().toInt() // single int\nprivate fun readLong()=readLn().toLong() // single long\nprivate fun readDouble()=readLn().toDouble() // single double\nprivate fun readStrings()=readLn().split(\" \") // list of strings\nprivate fun readInts()=readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs()=readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles()=readStrings().map { it.toDouble() } // list of doubles\nfun main(){\n val reader=Scanner(System.`in`)\n var a=readInt();\n for(i in 1..1000){\n var b=a*i+1\n for(j in 2..b-1){\n if(b%j==0){\n print(i)\n return\n }\n }\n }\n}"}, {"source_code": "import kotlin.math.*\n\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n\n for (i in 1..1000) {\n val num = n * i + 1\n var flag = false\n for (j in 2..num / 2) {\n if (num % j == 0) {\n flag = true\n break\n }\n }\n if (flag) {\n println(i)\n return\n }\n }\n}"}, {"source_code": "import java.lang.StringBuilder\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.max\n\nfun main() {\n var sc = Scanner(System.`in`)\n var n = sc.nextInt()\n var list = ArrayList()\n\n for (i in 1..10_000) {\n var flag = true\n\n for (j in 2..i - 1) {\n if (i % j == 0) {\n flag = false\n break\n }\n }\n if (flag) {\n list.add(false)\n } else {\n list.add(true)\n }\n }\n list[0] = true\n list[1] = false\n list.add(true)\n for (i in 1..1000) {\n if (list[n * i]) {\n println(i)\n break\n }\n }\n\n}"}, {"source_code": "import kotlin.math.sqrt\n\nfun checkprime(n:Int):Boolean\n{\n if(n<=1)\n {\n return false\n }\n val root = sqrt(n.toDouble())\n for(i in 2 until root.toInt()+1)\n {\n if(n%i==0)\n {\n return false\n }\n }\n return true\n}\n\nfun main(args:Array)\n{\n val n : Int = readLine()!!.toInt()\n for(i in 1 until 1001) {\n if(!checkprime(n*i+1))\n {\n print(i)\n break\n }\n }\n}"}, {"source_code": "fun main() {\n fun sieve(limit: Int): List {\n val notPrimes = mutableSetOf()\n val primes = ArrayList()\n for (num in 2..limit) {\n if (num !in notPrimes) {\n primes.add(num)\n var notPrime = num + num\n while (notPrime <= limit) {\n notPrimes.add(notPrime)\n notPrime += num\n }\n }\n }\n return primes\n }\n\n val primes = sieve(10000).toSet()\n val n = readLine()!!.toInt()\n for (c in 1..10)\n if (n * c + 1 !in primes) {\n print(c)\n return\n }\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.File\nimport java.io.PrintWriter\n\nfun main(args: Array) {\n val onlineJudge = System.getProperty(\"ONLINE_JUDGE\") == \"true\"\n val input = if (onlineJudge) System.`in`.bufferedReader() else File(\"input.txt\").bufferedReader()\n val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File(\"output.txt\"))\n\n solve(input, output)\n\n output.flush()\n output.close()\n}\n\nprivate fun String.words() = split(\" \")\n\nprivate fun String.toInts() = split(\" \").map(String::toInt)\nprivate fun String.toLongs() = split(\" \").map(String::toLong)\n\nfun isPrime(p: Int): Boolean {\n val upb = Math.sqrt(p.toDouble()).toInt()\n for (i in 2..upb) {\n if (p % i == 0)\n return false\n }\n return true\n}\n\nprivate fun solve(input: BufferedReader, output: PrintWriter) {\n val n = input.readLine().toInt()\n for (m in 1..1000) {\n val p = n * m + 1\n if (!isPrime(p)) {\n output.println(m)\n return\n }\n }\n}"}], "negative_code": [{"source_code": "import kotlin.math.sqrt\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n fun prime(i: Int) = (2..sqrt(i.toDouble()).toInt()).none { it % i == 0 }\n val n = r.readLine()!!.toInt()\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }.toSet().toList().sorted()\n var m = 1\n while (!prime(m*n+1)){\n m++\n }\n println(m)\n}"}, {"source_code": "import kotlin.math.*\n\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n\n for (i in 1..1000) {\n val num = n * i + 1\n var flag = false\n for (j in 2..num / 2) {\n if (num % i == 0) {\n flag = true\n break\n }\n }\n if (!flag) {\n println(i)\n return\n }\n }\n}"}, {"source_code": "import java.lang.StringBuilder\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.max\n\nfun main() {\n var sc = Scanner(System.`in`)\n var n = sc.nextInt()\n var list = ArrayList()\n\n for (i in 1..1000) {\n var flag = true\n\n for (j in 2..i - 1) {\n if (i % j == 0) {\n flag = false\n break\n }\n }\n if (flag) {\n list.add(false)\n } else {\n list.add(true)\n }\n }\n list[0] = true\n list[1] = true\n list.add(true)\n for (i in 1..1000) {\n if (list[n * i]) {\n println(i)\n break\n }\n }\n\n}"}, {"source_code": "import java.util.*\n\nfun main(){\n val sc = Scanner(System.`in`)\n val n:Int = sc.nextInt()\n if (n%2==0){\n println(1)\n }else if (n==1){\n println(3)\n }else{\n println(2)\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(){\n val sc = Scanner(System.`in`)\n val n:Int = sc.nextInt()\n if (n%2==0){\n println(2)\n }else{\n println(1)\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(){\n val sc = Scanner(System.`in`)\n val n:Int = sc.nextInt()\n if (n%2==0){\n println(2)\n }else if (n==1){\n println(3)\n }else{\n println(1)\n }\n}"}], "src_uid": "5c68e20ac6ecb7c289601ce8351f4e97"} {"nl": {"description": "Bob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor — a square tile that is diagonally split into white and black part as depicted in the figure below. The dimension of this tile is perfect for this kitchen, as he will need exactly $$$w \\times h$$$ tiles without any scraps. That is, the width of the kitchen is $$$w$$$ tiles, and the height is $$$h$$$ tiles. As each tile can be rotated in one of four ways, he still needs to decide on how exactly he will tile the floor. There is a single aesthetic criterion that he wants to fulfil: two adjacent tiles must not share a colour on the edge — i.e. one of the tiles must have a white colour on the shared border, and the second one must be black. The picture on the left shows one valid tiling of a $$$3 \\times 2$$$ kitchen. The picture on the right shows an invalid arrangement, as the bottom two tiles touch with their white parts. Find the number of possible tilings. As this number may be large, output its remainder when divided by $$$998244353$$$ (a prime number). ", "input_spec": "The only line contains two space separated integers $$$w$$$, $$$h$$$ ($$$1 \\leq w,h \\leq 1\\,000$$$) — the width and height of the kitchen, measured in tiles.", "output_spec": "Output a single integer $$$n$$$ — the remainder of the number of tilings when divided by $$$998244353$$$.", "sample_inputs": ["2 2", "2 4"], "sample_outputs": ["16", "64"], "notes": null}, "positive_code": [{"source_code": "import java.lang.Integer.min\nimport java.util.*\n\nfun main() {\n var ab = readLine()!!.split(' ').map { it.toInt() }.let { it[0] + it[1] }\n var k = 1\n while (ab > 0) {\n val z = Integer.numberOfLeadingZeros(k)\n val bit = min(ab, z - 1)\n ab -= bit\n k = k.shl(bit).rem(998244353)\n }\n println(k)\n return\n\n\n\n\n val s = \"\"//readLine()!!\n val l = s.length\n var lv = -1\n var os = 0\n val mark = LinkedList()\n for (i in 0 until l) {\n when (s[i]) {\n 'v' -> ++lv\n 'o' -> {\n if (lv > 0) {\n mark.add(lv)\n }\n lv = -1\n mark.add(0)\n ++os\n }\n else -> {\n throw Error()\n }\n }\n }\n if (lv > 0) {\n mark.add(lv)\n }\n\n var w = 0\n val left = IntArray(os)\n val right = IntArray(os)\n var fi = 0\n var ss = 0\n if (os > 0 ) {\n\n mark.iterator().forEach {\n if (it == 0) {\n left[fi++] = w\n } else {\n w += it\n }\n }\n w = 0\n mark.descendingIterator().forEach {\n if (it == 0) {\n right[--fi] = w\n } else {\n w += it\n }\n }\n\n }\n for (i in 0 until os) {\n ss += left[i] * right[i]\n }\n println(ss)\n}\n"}, {"source_code": "fun main() {\n\n val (w, h) = readInts()\n\n val prime = 998244353L\n val dp = mutableListOf>()\n\n for (i in 0 until h) {\n dp.add(mutableListOf())\n for (j in 0 until w) {\n dp[i].add(0)\n }\n }\n\n dp[0][0] = 4L\n for (i in 0 until h) {\n for (j in 0 until w) {\n if (i > 0 && j > 0) dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % prime\n else if (i > 0) dp[i][j] = (dp[i - 1][j] * 2) % prime\n else if (j > 0) dp[i][j] = (dp[i][j - 1] * 2) % prime\n }\n }\n\n println(dp[h - 1][w - 1])\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\n\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n"}, {"source_code": "fun main() {\n val (w, h) = readInts()\n val ans = ModInt(2).pow(w + h)\n\n println(ans)\n}\n\ninfix fun Int.umod(base: Int) =\n (this % base).let { if(it >= 0) it else it + base }\n\ninfix fun Long.umod(base: Long) =\n (this % base).let { if(it >= 0) it else it + base }\n\ninfix fun Long.umod(base: Int) =\n (this % base).let { if(it >= 0) it else it + base }\n\n/** modint inline class, requires hardcoded mod base **/\nconst val MODBASE = 998244353\n\ninline fun Int.toModInt() = ModInt(this umod MODBASE)\ninline fun Long.toModInt() = ModInt((this umod MODBASE).toInt())\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n operator fun plus(other: ModInt) = plus(other.int) // MODBASE < 2^30\n operator fun plus(other: Int) = (int + other).toModInt() // careful of possible overflow\n operator fun inc() = plus(1)\n\n operator fun minus(other: ModInt) = minus(other.int)\n operator fun minus(other: Int) = (int - other).toModInt()\n operator fun dec() = minus(1)\n\n operator fun times(other: ModInt) = times(other.int)\n operator fun times(other: Int) = (int.toLong() * other).toModInt()\n\n fun pow(exponent: Int): ModInt {\n var res = ModInt(1)\n var e = exponent\n var b = this\n\n if(e < 0) e = e.umod(MODBASE - 1) // assumes MODBASE is prime\n\n while(e > 0) {\n if(e and 1 == 1) {\n res *= b\n }\n e = e shr 1\n b *= b\n }\n return res\n }\n\n fun inv() = pow(MODBASE - 2) // assumes MODBASE is prime\n\n operator fun div(other: ModInt) = times(other.inv())\n operator fun div(other: Int) = div(other.toModInt())\n\n override fun toString() = int.toString()\n}\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n operator fun get(i: Int) = ModInt(intArray[i])\n operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override val size: Int get() = intArray.size\n\n override fun contains(element: ModInt): Boolean = indices.any { get(it) == element }\n\n override fun containsAll(elements: Collection): Boolean = elements.all { contains(it) }\n\n override fun isEmpty(): Boolean = size == 0\n\n override fun iterator(): Iterator = object: AbstractIterator() {\n var index = 0\n override fun computeNext() {\n if(index >= size) done()\n else setNext(get(index++))\n }\n }\n}\nfun ModIntArray(capacity: Int) = ModIntArray(IntArray(capacity))\ninline fun ModIntArray(capacity: Int, init: (Int) -> ModInt) =\n ModIntArray(IntArray(capacity) { init(it).int })\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit)\n { Output().apply(block).nowPrint() }\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.lang.StringBuilder\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.max\n\nfun main() {\n val sc = Scanner.sysIn\n\n val n = sc.nextInt()\n val m = sc.nextInt()\n\n var ans = 1L\n for (i in 1..(n + m)) {\n ans = (ans * 2) % 998244353\n }\n println(ans)\n\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n val br: BufferedReader = BufferedReader(InputStreamReader(s))\n\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n fun nextLine(): String {\n return br.readLine()\n }\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n companion object {\n val sysIn = Scanner(System.`in`)\n }\n\n}\nfun IntArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\n\nfun BooleanArray.print() {\n println(Arrays.toString(this))\n}\n\n"}, {"source_code": "import java.util.*\n\nfun main() {\n val jin = Scanner(System.`in`)\n val w = jin.nextInt()\n val h = jin.nextInt()\n println(M2 pow (w + h))\n}\n\nval M0 = Mint(0)\nval M1 = Mint(1)\nval M2 = Mint(2)\n\nval MOD: Long = 998244353\nval MOD_TOTIENT = (MOD - 1).toInt()\n\nfun mint(num: Long) = Mint(num % MOD)\nfun mint(num: Int) = Mint(num % MOD)\n\ninline class Mint(val num: Long) {\n\n operator fun plus(k: Mint) = mint(num + k.num)\n operator fun minus(k: Mint) = mint(num + MOD - k.num)\n operator fun times(k: Mint) = mint(num * k.num)\n operator fun div(k: Mint) = this * (k pow -1)\n\n operator fun unaryMinus() = mint(MOD - num)\n operator fun inc() = this + M1\n operator fun dec() = this - M1\n\n infix fun pow(power: Int): Mint {\n var e = power\n e %= MOD_TOTIENT\n if (e < 0) {\n e += MOD_TOTIENT\n }\n if (e == 0 && num == 0L) {\n return this\n }\n var b = this\n var res = Mint(1)\n while (e > 0) {\n if (e and 1 != 0) {\n res *= b\n }\n b *= b\n e = e shr 1\n }\n return res\n }\n\n override fun toString(): String = num.toString()\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val input = Scanner(System.`in`)\n val mod = 998244353L\n val n = input.nextInt() + input.nextInt()\n var result = 1L\n for (i in 1..n) {\n result = (result * 2) % mod\n }\n println(result)\n}\n"}, {"source_code": "import java.math.BigInteger\n\n// Unable to solve it by myself. The tutorial is here: https://codeforces.com/blog/entry/68534\nfun main() {\n val (w, h) = readLine()!!.split(\" \").map(String::toLong)\n print(BigInteger.valueOf(2L).modPow(BigInteger.valueOf(w + h), BigInteger.valueOf(998244353L)))\n}"}, {"source_code": "private fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\nprivate fun readLongs() = readStrings().map { it.toLong() }\n\nfun main() {\n val (w, h) = readInts()\n\n val mod = 998244353\n var res = 1L\n repeat(w + h) {\n res *= 2\n res %= mod\n }\n println(res)\n}\n"}, {"source_code": "import java.math.*\nimport java.util.*\nimport java.io.*\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readInts() = readLn().split(\" \").map{it.toInt()}\n\nfun qpowmod(ta:Long, tb:Long, mod:Long):Long {\n\tvar a = ta\n\tvar b = tb\n\tvar res=1L\n\twhile(b>0) {\n\t\tif(b%2==1L)\n\t\t\tres=res*a%mod\n\t\tb/=2\n\t\ta=a*a%mod\n\t}\n\treturn res\n}\n\nfun main(args: Array) {\n\tvar (n,m) = readInts()\n\tprintln(qpowmod(2,(n+m).toLong(), 998244353))\n}"}], "negative_code": [{"source_code": "import java.math.*\nimport java.util.*\nimport java.io.*\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readInts() = readLn().split(\" \").map{it.toInt()}\n\nfun qpowmod(ta:Long, tb:Long, mod:Long):Long {\n\tvar a = ta\n\tvar b = tb\n\tvar res=1L\n\twhile(b>0) {\n\t\tif(b%2==1L)\n\t\t\tres=res*a\n\t\tb/=2\n\t\ta=a*a%mod\n\t}\n\treturn res\n}\n\nfun main(args: Array) {\n\tvar (n,m) = readInts()\n\tprintln(qpowmod(2,(n+m).toLong(), 998244353))\n}"}], "src_uid": "8b2a9ae21740c89079a6011a30cd6aee"} {"nl": {"description": "Tokitsukaze is one of the characters in the game \"Kantai Collection\". In this game, every character has a common attribute — health points, shortened to HP.In general, different values of HP are grouped into $$$4$$$ categories: Category $$$A$$$ if HP is in the form of $$$(4 n + 1)$$$, that is, when divided by $$$4$$$, the remainder is $$$1$$$; Category $$$B$$$ if HP is in the form of $$$(4 n + 3)$$$, that is, when divided by $$$4$$$, the remainder is $$$3$$$; Category $$$C$$$ if HP is in the form of $$$(4 n + 2)$$$, that is, when divided by $$$4$$$, the remainder is $$$2$$$; Category $$$D$$$ if HP is in the form of $$$4 n$$$, that is, when divided by $$$4$$$, the remainder is $$$0$$$. The above-mentioned $$$n$$$ can be any integer.These $$$4$$$ categories ordered from highest to lowest as $$$A > B > C > D$$$, which means category $$$A$$$ is the highest and category $$$D$$$ is the lowest.While playing the game, players can increase the HP of the character. Now, Tokitsukaze wants you to increase her HP by at most $$$2$$$ (that is, either by $$$0$$$, $$$1$$$ or $$$2$$$). How much should she increase her HP so that it has the highest possible category?", "input_spec": "The only line contains a single integer $$$x$$$ ($$$30 \\leq x \\leq 100$$$) — the value Tokitsukaze's HP currently.", "output_spec": "Print an integer $$$a$$$ ($$$0 \\leq a \\leq 2$$$) and an uppercase letter $$$b$$$ ($$$b \\in \\lbrace A, B, C, D \\rbrace$$$), representing that the best way is to increase her HP by $$$a$$$, and then the category becomes $$$b$$$. Note that the output characters are case-sensitive.", "sample_inputs": ["33", "98"], "sample_outputs": ["0 A", "1 B"], "notes": "NoteFor the first example, the category of Tokitsukaze's HP is already $$$A$$$, so you don't need to enhance her ability.For the second example: If you don't increase her HP, its value is still $$$98$$$, which equals to $$$(4 \\times 24 + 2)$$$, and its category is $$$C$$$. If you increase her HP by $$$1$$$, its value becomes $$$99$$$, which equals to $$$(4 \\times 24 + 3)$$$, and its category becomes $$$B$$$. If you increase her HP by $$$2$$$, its value becomes $$$100$$$, which equals to $$$(4 \\times 25)$$$, and its category becomes $$$D$$$. Therefore, the best way is to increase her HP by $$$1$$$ so that the category of her HP becomes $$$B$$$."}, "positive_code": [{"source_code": "private fun readLn() = readLine()!!\nprivate fun readString() = readLn().trim()\nprivate fun readInt() = readLn().toInt()\nprivate val regSpace = \"\\\\s+\".toRegex()\nprivate fun readSomeInts(): List {\n return readLn().trim().split(regSpace).map { it.toInt() }\n}\nprivate fun readLong() = readLn().toLong()\nprivate fun readSomeLongs(): List {\n return readLn().trim().split(regSpace).map { it.toLong() }\n}\n\nfun main() {\n\n val x = readInt()\n\n when (x % 4) {\n 1 -> println(\"0 A\")\n 3 -> println(\"2 A\")\n 2 -> println(\"1 B\")\n else -> println(\"1 A\")\n }\n \n}\n\n"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nfun main(args: Array) {\n\n var num = readInt()\n\n if (num % 4 == 1) {\n println(\"0 A\")\n } else {\n if (num % 4 == 0 ) {\n println(\"1 A\")\n } else if (num % 4 == 2) {\n println(\"1 B\")\n }else if(num % 4 == 3){\n println(\"2 A\")\n }\n }\n\n\n}"}, {"source_code": "\nfun solve(n: Int):Int{\n if(n%4==1)\n return 'A'.toInt()\n else if(n%4==2)\n return 'C'.toInt()\n else if(n%4==3)\n return 'B'.toInt()\n else\n return 'D'.toInt()\n}\nfun main(){\n var n: Int\n n = readLine()!!.toInt()\n var a:Int=0\n var res:Int=solve(n)\n for(i in 1..2){\n var tmp:Int = solve(n+i)\n if(tmpprint(\"1 A\")\n 1->print(\"0 A\")\n 2->print(\"1 B\")\n 3->print(\"2 A\")\n }\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!.toInt()\n //val v = r.readLine()!!.split(\" \").map { it.toLong() }\n when(n%4){\n 0 -> println(\"1 A\")\n 1 -> println(\"0 A\")\n 2 -> println(\"1 B\")\n 3 -> println(\"2 A\")\n }\n}"}, {"source_code": "fun main() {\n val hp = readLine()!!.toInt()\n when(hp%4) {\n 0 -> println(\"1 A\")\n 1 -> println(\"0 A\")\n 2 -> println(\"1 B\")\n else -> println(\"2 A\")\n }\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport java.util.Arrays\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val line: String = when (ir.nextInt() % 4) {\n 0 -> \"1 A\"\n 2 -> \"1 B\"\n 3 -> \"2 A\"\n else -> \"0 A\"\n }\n \n pw.print(line)\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextFloat(): Float {\n return java.lang.Float.parseFloat(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport java.util.Arrays\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n when (ir.nextInt() % 4) {\n 0 -> pw.print(\"1 A\")\n 2 -> pw.print(\"1 B\")\n 3 -> pw.print(\"2 A\")\n else -> pw.print(\"0 A\")\n }\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextFloat(): Float {\n return java.lang.Float.parseFloat(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "fun main(args: Array) {\n val x = readLine()!!.toInt()\n\n val r = x % 4\n when (r) {\n // D increment by 1 to have A\n 0 -> {\n println(\"1 A\")\n }\n // A already the best\n 1 -> {\n println(\"0 A\")\n }\n // C increment by 1 to have B\n 2 -> {\n println(\"1 B\")\n }\n // B increment by 2 to have A\n 3 -> println(\"2 A\")\n }\n}\n\n"}, {"source_code": "fun main() {\n val x = readLine()!!.toInt()\n var out = Array(2){ (it).toString() }\n var div = x % 4\n when(div){\n 0 -> { out[0] = \"1\" ; out[1] = \"A\" }\n 1 -> { out[0] = \"0\" ; out[1] = \"A\" }\n 2 -> { out[0] = \"1\" ; out[1] = \"B\" }\n 3 -> { out[0] = \"2\" ; out[1] = \"A\" }\n }\n out.forEach { print(\"$it \") }\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val ost = n % 4\n\n if (ost == 0) println(\"1 A\")\n if (ost == 1) println(\"0 A\")\n if (ost == 2) println(\"1 B\")\n if (ost == 3) println(\"2 A\")\n}"}, {"source_code": "fun main() {\n val x = readInt()\n val ans = when(x % 4) {\n 0 -> \"1 A\"\n 1 -> \"0 A\"\n 2 -> \"1 B\"\n else -> \"2 A\"\n }\n println(ans)\n}\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit)\n { Output().apply(block).nowPrint() }\n"}, {"source_code": "fun main() {\n\n var hp = readInt()\n var c = when {\n hp % 4 == 1 -> 'A'\n hp % 4 == 3 -> 'B'\n hp % 4 == 2 -> 'C'\n hp % 4 == 0 -> 'D'\n else -> 'X'\n }\n\n when(c) {\n 'A' -> println(\"0 A\")\n 'B' -> println(\"2 A\")\n 'C' -> println(\"1 B\")\n 'D' -> println(\"1 A\")\n }\n\n\n\n}\n\n\nprivate fun readLn() = readLine()!!\nprivate fun readLong() = readLn().toLong()\nprivate fun readLongs() = readLn().split(\" \").map { it.toLong() }\nprivate fun readInt() = readLn().toInt()\nprivate fun readInts() = readLn().split(\" \").map { it.toInt() }"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val x = readInt()\n print(\n when (x % 4) {\n 1 -> \"0 A\"\n 2 -> \"1 B\"\n 3 -> \"2 A\"\n else -> \"1 A\"\n }\n )\n}"}, {"source_code": "import java.util.*\n\nfun readInts() = readLine()!!.split(\" \").map { it.toInt() }\nfun readInt() = readLine()!!.toInt()\nfun readLenAndInts() = readLine()!!.split(\" \").drop(1).map { it.toInt() }\n\nfun main() {\n val n = readInt()\n fun cat(i : Int) : Char {\n return when {\n i % 4 == 0 -> 'D'\n i % 4 == 1 -> 'A'\n i % 4 == 2 -> 'C'\n else -> 'B'\n }\n }\n val a = (0..2).maxBy { 'D' - cat(n+it) }!!\n println(\"$a ${cat(n+a)}\")\n}"}, {"source_code": "private fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n\nfun main() {\n val hp = readInt()\n when (hp % 4) {\n 0 -> println(\"1 A\")\n 1 -> println(\"0 A\")\n 2 -> println(\"1 B\")\n 3 -> println(\"2 A\")\n }\n}"}, {"source_code": "fun main(){\n\tvar x = readLine()!!.toInt()\n\tvar m = x % 4\n\tprintln( when(m) {\n\t\t1 -> \"0 A\"\n\t\t2 -> \"1 B\"\n\t\t3 -> \"2 A\"\n\t\telse -> \"1 A\" \n\t\t\n\t})\n}"}, {"source_code": "fun main() {\n val (a, b) = when (readInt() % 4) {\n 0 -> 1 to \"A\"\n 1 -> 0 to \"A\"\n 2 -> 1 to \"B\"\n 3 -> 2 to \"A\"\n else -> error(\"\")\n }\n println(\"$a $b\")\n}\n\nprivate fun readInt() = readLine()!!.toInt()"}, {"source_code": "private fun readString() = readLine()!!\nprivate fun readInt() = readString().toInt()\nprivate fun readStrings() = readString().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n\nfun isBetter(current: Int, next: Int): Boolean = when(current) {\n 1 -> false\n 3 -> next == 1\n 2 -> next in setOf(1,3)\n 0 -> next != 4\n else -> throw IllegalArgumentException(\"Should never be more than 4, was $current\")\n}\n\n\nfun main() {\n val hp = readInt()\n var best = hp % 4\n var howMuch = 0\n for (i in 1..2) {\n val current = (hp + i) % 4\n if (isBetter(best, current)) {\n howMuch = i\n best = current\n }\n }\n print(howMuch)\n print(' ')\n println(\n when (best) {\n 0 -> 'D'\n 1 -> 'A'\n 2 -> 'C'\n 3 -> 'B'\n else -> throw IllegalArgumentException(\"Should never be more than 4, was $best\")\n }\n )\n}"}], "negative_code": [{"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nfun main(args: Array) {\n\n var num = readInt()\n\n if (num % 4 == 1) {\n println(\"0 A\")\n } else {\n if (num % 4 == 0 || num % 4 == 3) {\n println(\"1 A\")\n } else if (num % 4 == 2) {\n println(\"1 B\")\n }\n }\n\n\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!.toInt()\n //val v = r.readLine()!!.split(\" \").map { it.toLong() }\n when(n%4){\n 0 -> println(\"2 B\")\n 1 -> println(\"0 A\")\n 2 -> println(\"2 A\")\n 3 -> println(\"1 A\")\n }\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val ost = n % 4\n\n if (ost == 1) println(\"0 A\")\n if (ost == 0) println(\"2 B\")\n if (ost == 2) println(\"1 B\")\n if (ost == 3) println(\"2 A\")\n}"}], "src_uid": "488e809bd0c55531b0b47f577996627e"} {"nl": {"description": "Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. He ate coffee mix without water again, so right now he's really messed up and can't think.Your task is to help him by telling him what to type.", "input_spec": "The first and only line of input contains an integer s (0 ≤ s ≤ 99), Tavas's score. ", "output_spec": "In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces.", "sample_inputs": ["6", "99", "20"], "sample_outputs": ["six", "ninety-nine", "twenty"], "notes": "NoteYou can find all you need to know about English numerals in http://en.wikipedia.org/wiki/English_numerals ."}, "positive_code": [{"source_code": "fun main() {\n var n = readLine()!!\n var one = 0\n var toCheck = Integer.parseInt(n)\n if (n.length < 2) {\n when (toCheck) {\n 0-> println(\"zero\")\n 1 -> println(\"one\")\n 2 -> println(\"two\")\n 3 -> println(\"three\")\n 4 -> println(\"four\")\n 5 -> println(\"five\")\n 6 -> println(\"six\")\n 7 -> println(\"seven\")\n 8 -> println(\"eight\")\n 9 -> println(\"nine\")\n }\n } else {\n when (Integer.parseInt(n[0].toString())) {\n 1 -> {\n when (Integer.parseInt(n[1].toString())) {\n 0-> println(\"ten\")\n 1 -> println(\"eleven\")\n 2 -> println(\"twelve\")\n 3 -> println(\"thirteen\")\n 4 -> println(\"fourteen\")\n 5 -> println(\"fifteen\")\n 6 -> println(\"sixteen\")\n 7 -> println(\"seventeen\")\n 8 -> println(\"eighteen\")\n 9 -> println(\"nineteen\")\n }\n }\n 2 -> {\n print(\"twenty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 3 -> {\n print(\"thirty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 4 -> {\n print(\"forty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 5 -> {\n print(\"fifty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 6 -> {\n print(\"sixty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 7 -> {\n print(\"seventy\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 8 -> {\n print(\"eighty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 9 -> {\n print(\"ninety\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n }\n }\n}\n\n\n"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n val numToText = listOf(\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\", \"ten\",\n \"eleven\", \"twelve\", \"thirteen\", \"fourteen\", \"fifteen\", \"sixteen\", \"seventeen\", \"eighteen\", \"nineteen\")\n val tens = listOf(\"\", \"\", \"twenty\", \"thirty\", \"forty\", \"fifty\", \"sixty\", \"seventy\", \"eighty\", \"ninety\")\n print(\n when {\n n < 20 -> numToText[n]\n n % 10 == 0 -> tens[n / 10]\n else -> tens[n / 10] + '-' + numToText[n % 10]\n }\n )\n}\n"}], "negative_code": [{"source_code": "\n\nfun main() {\n var n = readLine()!!\n var one = 0\n var toCheck = Integer.parseInt(n)\n if (toCheck == 11) {\n println(\"eleven\")\n return\n } else if (toCheck == 10) {\n println(\"ten\")\n } else if (toCheck == 12) {\n println(\"twelve\")\n return\n } else if (toCheck == 13) {\n println(\"thirteen\")\n return\n } else if (toCheck == 14) {\n println(\"fourteen\")\n return\n } else if (toCheck == 15) {\n println(\"fifteen\")\n return\n } else if (toCheck == 16) {\n println(\"sixteen\")\n return\n } else if (toCheck == 17) {\n println(\"seventeen\")\n return\n } else if (toCheck == 18) {\n println(\"eighteen\")\n return\n } else if (toCheck == 19) {\n println(\"nineteen\")\n return\n }\n when(toCheck){\n 1 -> print(\"one\")\n 2 -> print(\"two\")\n 3 -> print(\"three\")\n 4 -> print(\"four\")\n 5 -> print(\"five\")\n 6 -> print(\"six\")\n 7 -> print(\"seven\")\n 8 -> print(\"eight\")\n 9 -> print(\"nine\")\n }\n\n\n if (n.length > 1) {\n\n when (Integer.parseInt(n[0].toString())) {\n 2 -> print(\"twenty-\")\n 3 -> print(\"thirty-\")\n 4 -> print(\"forty-\")\n 5 -> print(\"fifty-\")\n 6 -> print(\"sixty-\")\n 7 -> print(\"seventy-\")\n 8 -> print(\"eighty-\")\n 9 -> print(\"ninety-\")\n }\n when (Integer.parseInt(n[1].toString())) {\n 1 -> print(\"one\")\n 2 -> print(\"two\")\n 3 -> print(\"three\")\n 4 -> print(\"four\")\n 5 -> print(\"five\")\n 6 -> print(\"six\")\n 7 -> print(\"seven\")\n 8 -> print(\"eight\")\n 9 -> print(\"nine\")\n }\n\n }\n}"}, {"source_code": "fun main() {\n var n = readLine()!!\n var one = 0\n var toCheck = Integer.parseInt(n)\n if (n.length < 2) {\n when (toCheck) {\n 1 -> println(\"one\")\n 2 -> println(\"two\")\n 3 -> println(\"three\")\n 4 -> println(\"four\")\n 5 -> println(\"five\")\n 6 -> println(\"six\")\n 7 -> println(\"seven\")\n 8 -> println(\"eight\")\n 9 -> println(\"nine\")\n }\n } else {\n when (Integer.parseInt(n[0].toString())) {\n 1 -> {\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"ten\")\n 2 -> println(\"twelve\")\n 3 -> println(\"thirteen\")\n 4 -> println(\"fourteen\")\n 5 -> println(\"fifteen\")\n 6 -> println(\"sixteen\")\n 7 -> println(\"seventeen\")\n 8 -> println(\"eighteen\")\n 9 -> println(\"nineteen\")\n }\n }\n 2 -> {\n print(\"twenty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 3 -> {\n print(\"thirty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 4 -> {\n print(\"forty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 5 -> {\n print(\"fifty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 6 -> {\n print(\"sixty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 7 -> {\n print(\"seventy\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 8 -> {\n print(\"eighty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 9 -> {\n print(\"ninety\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n }\n }\n}\n\n\n"}, {"source_code": "fun main() {\n var n = readLine()!!\n var one = 0\n var toCheck = Integer.parseInt(n)\n if (n.length < 2) {\n when (toCheck) {\n 1 -> println(\"one\")\n 2 -> println(\"two\")\n 3 -> println(\"three\")\n 4 -> println(\"four\")\n 5 -> println(\"five\")\n 6 -> println(\"six\")\n 7 -> println(\"seven\")\n 8 -> println(\"eight\")\n 9 -> println(\"nine\")\n }\n } else {\n when (Integer.parseInt(n[0].toString())) {\n 1 -> {\n when (Integer.parseInt(n[1].toString())) {\n 0-> println(\"ten\")\n 1 -> println(\"eleven\")\n 2 -> println(\"twelve\")\n 3 -> println(\"thirteen\")\n 4 -> println(\"fourteen\")\n 5 -> println(\"fifteen\")\n 6 -> println(\"sixteen\")\n 7 -> println(\"seventeen\")\n 8 -> println(\"eighteen\")\n 9 -> println(\"nineteen\")\n }\n }\n 2 -> {\n print(\"twenty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 3 -> {\n print(\"thirty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 4 -> {\n print(\"forty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 5 -> {\n print(\"fifty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 6 -> {\n print(\"sixty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 7 -> {\n print(\"seventy\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 8 -> {\n print(\"eighty\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n 9 -> {\n print(\"ninety\")\n when (Integer.parseInt(n[1].toString())) {\n 1 -> println(\"-one\")\n 2 -> println(\"-two\")\n 3 -> println(\"-three\")\n 4 -> println(\"-four\")\n 5 -> println(\"-five\")\n 6 -> println(\"-six\")\n 7 -> println(\"-seven\")\n 8 -> println(\"-eight\")\n 9 -> println(\"-nine\")\n }\n }\n }\n }\n}\n\n\n"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n val numToText = listOf(\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\", \"ten\",\n \"eleven\", \"twelve\", \"thirteen\", \"fourteen\", \"fivteen\", \"sixteen\", \"seventeen\", \"eighteen\", \"nineteen\")\n val tens = listOf(\"\", \"\", \"twenty\", \"thirty\", \"forty\", \"fifty\", \"sixty\", \"seventy\", \"eighty\", \"ninety\")\n print(\n when {\n n < 20 -> numToText[n]\n n % 10 == 0 -> tens[n / 10]\n else -> tens[n / 10] + '-' + numToText[n % 10]\n }\n )\n}\n"}], "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7"} {"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 java.util.Scanner\n\n\nfun main(args: Array) {\n val n = readLine() ?: \"\"\n val str = readLine() ?: \"\"\n var result = \"\"\n val chars = str.toCharArray()\n var i = 0\n while (i < chars.size) {\n var sum = 0\n var zero = \"\"\n for (j in i until chars.size) {\n if (chars[j] == '1') {\n sum++\n i++\n }\n else {\n i = j + 1\n break\n }\n }\n for (j in i until chars.size -1) {\n if (chars[j] == '0') {\n zero += \"0\"\n i++\n }\n else {\n i = j\n break\n }\n }\n result += sum\n result += zero\n }\n if(chars[chars.size-1] == '0')\n result+=\"0\"\n println(result)\n\n}\n"}, {"source_code": "import java.util.*\n\n/**\n * Created by thuanle on 7/16/17.\n */\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n// val n = sc.nextInt()\n sc.nextLine()\n val s = sc.nextLine()\n s.split(\"0\")\n .forEach{print(it.length)}\n\n}"}, {"source_code": "import java.util.*\n\n/**\n * Created by thuanle on 7/16/17.\n */\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n sc.nextLine()\n sc.nextLine().split(\"0\").forEach{print(it.length)}\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\nfun solve() {\n nextInt()\n val s = next()\n var add = 0\n s.forEach {\n when(it) {\n '0' -> {\n pw.print(add)\n add = 0\n } else -> add++\n }\n }\n pw.println(add)\n}\n\nfun hasNext() : Boolean {\n while (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine() ?: return false)\n return true\n}\n\nfun next() = if(hasNext()) st.nextToken()!! else throw RuntimeException(\"No tokens\")\n\nfun nextInt() = next().toInt()\n\nfun nextLong() = next().toLong()\n\nfun nextLine() = if(hasNext()) st.nextToken(\"\\n\") else throw RuntimeException(\"No tokens\")\n\nfun nextArray(n : Int) = IntArray(n,{nextInt()})\n\nval ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n\nval br = when(ONLINE_JUDGE) {\n true -> BufferedReader(InputStreamReader(System.`in`))\n else -> BufferedReader(FileReader(\"in.txt\"))\n}\n\nval pw = when(ONLINE_JUDGE) {\n true -> PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))\n else -> PrintWriter(BufferedWriter(FileWriter(\"out.txt\")))\n}\n\nvar st = StringTokenizer(\"\")\n\nfun main(args: Array) {\n var start = System.currentTimeMillis()\n solve()\n pw.close()\n br.close()\n if(!ONLINE_JUDGE)\n System.err.println(\"${System.currentTimeMillis() - start} ms\")\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array ) {\n val sc = Scanner( System.`in` )\n sc.nextLine()\n println( sc.nextLine().split( \"0\" ).map { it.length }.joinToString( \"\" ) )\n}"}, {"source_code": "fun main() {\n readLine()\n val sol = StringBuilder()\n var sum = 0\n for (c in readLine()!!)\n if (c == '0') {\n sol.append(sum)\n sum = 0\n } else {\n if (sum == 9) {\n sol.append(9)\n sum = 1\n } else sum++\n }\n sol.append(sum)\n print(sol)\n}\n"}, {"source_code": "import java.util.Scanner\n\nfun main(args : Array) {\n val scanner = Scanner(System.`in`)\n var n = scanner.next().toInt()\n var s = scanner.next().toString()\n var digit: Int = 0\n s.forEach {\n when(it) {\n '1' -> digit++\n '0' -> {\n print(digit)\n digit = 0\n }\n }\n }\n print(digit)\n}"}], "negative_code": [{"source_code": "import java.util.Scanner\n\n\nfun main(args: Array) {\n val n = readLine() ?: \"\"\n val str = readLine() ?: \"\"\n var result = \"\"\n val chars = str.toCharArray()\n var i = 0\n while (i < chars.size) {\n var sum = 0\n var zero = \"\"\n for (j in i until chars.size) {\n if (chars[j] == '1') {\n sum++\n i++\n }\n else {\n i = j + 1\n break\n }\n }\n for (j in i until chars.size -1) {\n if (chars[j] == '0') {\n zero += \"0\"\n i++\n }\n else {\n i = j\n break\n }\n }\n result += sum\n result += zero\n\n }\n println(result)\n\n}\n"}, {"source_code": "fun main() {\n readLine()\n val sol = StringBuilder()\n var sum = 0\n for (c in readLine()!!)\n if (c == '0') {\n sol.append(sum)\n sum = 0\n } else {\n if (sum == 9) {\n sol.append(9)\n sum = 1\n } else sum++\n }\n if (sum != 0) sol.append(sum)\n print(sol)\n}\n"}], "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa"} {"nl": {"description": "Anton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits.Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them. ", "input_spec": "The first line contains the positive integer x (1 ≤ x ≤ 1018) — the integer which Anton has. ", "output_spec": "Print the positive integer which doesn't exceed x and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros.", "sample_inputs": ["100", "48", "521"], "sample_outputs": ["99", "48", "499"], "notes": null}, "positive_code": [{"source_code": "fun main(arg: Array) {\n fun getMax(pos: Int, numbers: Array): Array = when (pos) {\n 0 -> numbers\n else -> {\n if (8 - numbers[pos] + (pos + 1..numbers.size - 1).sumBy { 9 - numbers[it] } > 0) {\n numbers[pos - 1]--\n for (i in pos..numbers.size - 1) numbers[i] = 9\n }\n getMax(pos - 1, numbers)\n }\n }\n\n var numbers = readLine()!!.map { it - '0' }.toTypedArray()\n println(getMax(numbers.size - 1, numbers).joinToString(\"\").toLong())\n}"}, {"source_code": "//package qqq2\n\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\n\n//fun Long.maxSum(): Long = (this downTo 1).maxBy(Long::sum) ?: 0\n\nfun Long.maxSumFast(): Long {\n val digits = digits()\n var nines = digits().mapIndexed { index, l -> if (index == digits.size - 1) l else 9 }\n if (nines.toLong() == this) return this\n for (i in 0..nines.size - 2) {\n if (nines.toLong().setDigit(8, i) <= this) {\n nines = nines.toLong().setDigit(8, i).digits()\n break\n }\n }\n if (nines.toLong() > this) nines = nines.mapIndexed { index, l -> if (index == digits.size - 1) l - 1 else l }\n return nines.toLong()\n}\n\nfun Long.setDigit(digit: Long, pos: Int) = digits().mapIndexed { index, l -> if (index == pos) digit else l }.toLong()\n\n//fun Long.sum(): Long = digits().sum()\n\nfun Long.digits(): MutableList {\n val r = mutableListOf()\n var t = this\n while (t > 0) {\n r.add(t % 10)\n t /= 10\n }\n return r\n}\n\nfun List.toLong() = if (isEmpty()) 0 else this.reversed().reduce { acc, l -> acc * 10 + l }\n\nfun main(args: Array) {\n println(BufferedReader(InputStreamReader(System.`in`)).readLine().toLong().maxSumFast())\n\n// val filter = (1L..4444)\n// .onEach { println(\"$it\\t${it.maxSum()}\\t${it.maxSumFast()}\") }\n// .filter { it.maxSum() != it.maxSumFast() }\n// println(\"errors == \" + filter)\n\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val NStr = readLine()!!\n val digits = NStr.length\n val results = ArrayList(digits)\n\n for (i in 0..digits-1) {\n val beginning = NStr.take(i)\n val ending = NStr.takeLast(digits-i).toLong()\n val newEnding = (ending / Math.pow(10.0, digits-i - 1.0).toLong() - 1) * Math.pow(10.0, digits-i - 1.0).toLong() +\n (digits-i.toLong() - 2 downTo 0).sumByLong { 9 * Math.pow(10.0, it.toDouble()).toLong() }\n if (newEnding<0) continue\n results.add(\"$beginning$newEnding\".toLong())\n }\n\n results.add(NStr.toLong())\n val maxSum = results.maxBy(Long::getSum)!!.getSum()\n val output = results.filter { it.getSum() == maxSum}.max()\n\n println(output)\n}\n\nfun Long.getSum(): Long {\n var sum = 0L\n var remainder = this\n while (remainder != 0L) {\n sum += remainder % 10\n remainder /= 10\n }\n return sum\n}\n\ninline fun Iterable.sumByLong(selector: (T) -> Long): Long {\n var sum: Long = 0L\n for (element in this) {\n sum += selector(element)\n }\n return sum\n}\n"}, {"source_code": "\n/*fun stupid(x: Int) : Int {\n var ans = 0\n var ansSum = 0\n for (i in 1..x) {\n var curSum = i.toString().map{it-'0'}.sum()\n if (curSum >= ansSum) {\n ansSum = curSum\n ans = i\n }\n }\n return ans\n}*/\n\nfun solve(x : Long) : Long {\n var ans = x\n var ansSum = x.toString().map{it-'0'}.sum()\n var head = x\n var tailLen = 0\n while (head > 0) {\n head /= 10\n tailLen ++\n var tail = \"\"\n (1..tailLen).forEach { tail += '9' }\n var cur = -1.toLong()\n head --\n if (head > 0) {\n cur = (head.toString() + tail).toLong()\n } else {\n cur = tail.toLong()\n }\n if (cur > x)\n continue\n val curSum = cur.toString().map{it-'0'}.sum()\n if (curSum > ansSum) {\n ans = cur\n ansSum = curSum\n }\n }\n return ans\n}\n\nfun main(args: Array) {\n val x = readLine()!!.toLong()\n println(solve(x))\n}"}], "negative_code": [{"source_code": "fun main(arg: Array) {\n fun getMax(pos: Int, numbers: Array): Array = when (pos) {\n 0 -> numbers\n else -> {\n if (9 - numbers[pos] + (pos..numbers.size - 1).sumBy { 9 - numbers[it] } > 0) {\n numbers[pos - 1]--\n for (i in pos..numbers.size - 1) numbers[i] = 9\n }\n getMax(pos - 1, numbers)\n }\n }\n\n var numbers = readLine()!!.map { it - '0' }.toTypedArray()\n getMax(numbers.size - 1, numbers).forEach(::print)\n println()\n}\n"}, {"source_code": "fun main(args: Array) {\n val N = readLine()!!.toLong()\n val digits = Math.abs(N).toString().length.toDouble()\n val N2 = (N / Math.pow(10.0, digits - 1).toLong() - 1) * Math.pow(10.0, digits - 1).toLong() +\n (digits.toLong() - 2 downTo 0).sumByLong { 9 * Math.pow(10.0, it.toDouble()).toLong() }\n\n val Nsum = N.getSum()\n val N2sum = N2.getSum()\n if (Nsum > N2sum)\n println(N)\n else if (Nsum < N2sum)\n println(N2)\n else\n println(Math.max(N, N2))\n}\n\nfun Long.getSum(): Long {\n var sum = 0L\n var remainder = this\n while (remainder != 0L) {\n sum += remainder % 10\n remainder /= 10\n }\n return sum\n}\n\ninline fun Iterable.sumByLong(selector: (T) -> Long): Long {\n var sum: Long = 0L\n for (element in this) {\n sum += selector(element)\n }\n return sum\n}"}, {"source_code": "fun main(args: Array) {\n val N = readLine()!!.toInt()\n val digits = Math.abs(N).toString().length.toDouble()\n val N2 = (N / Math.pow(10.0, digits-1).toInt() - 1) * Math.pow(10.0, digits-1).toInt() +\n (digits.toInt()-2 downTo 0).sumBy { 9*Math.pow(10.0, it.toDouble()).toInt() }\n\n val Nsum = N.getSum()\n val N2sum = N2.getSum()\n if (Nsum>N2sum)\n println(N)\n else if (Nsum) {\n val NStr = readLine()!!\n var nines = 0\n while (NStr.length>nines && NStr[nines] == '9')\n nines++\n nines--\n\n val N = NStr.takeLast(NStr.length - nines).toLong()\n val digits = Math.abs(N).toString().length.toDouble()\n val N2 = (N / Math.pow(10.0, digits - 1).toLong() - 1) * Math.pow(10.0, digits - 1).toLong() +\n (digits.toLong() - 2 downTo 0).sumByLong { 9 * Math.pow(10.0, it.toDouble()).toLong() }\n\n val Nsum = N.getSum()\n val N2sum = N2.getSum()\n if (nines>0)\n print(\"9\".repeat(nines))\n if (Nsum > N2sum)\n println(N)\n else if (Nsum < N2sum)\n println(N2)\n else\n println(Math.max(N, N2))\n\n}\n\nfun Long.getSum(): Long {\n var sum = 0L\n var remainder = this\n while (remainder != 0L) {\n sum += remainder % 10\n remainder /= 10\n }\n return sum\n}\n\ninline fun Iterable.sumByLong(selector: (T) -> Long): Long {\n var sum: Long = 0L\n for (element in this) {\n sum += selector(element)\n }\n return sum\n}"}], "src_uid": "e55b0debbf33c266091e6634494356b8"} {"nl": {"description": "Prof. Vasechkin wants to represent positive integer n as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+–1. Help him to find the least number of digits 1 in such sum.", "input_spec": "The first line of the input contains integer n (1 ≤ n < 1015).", "output_spec": "Print expected minimal number of digits 1.", "sample_inputs": ["121"], "sample_outputs": ["6"], "notes": null}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007\n\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val N = nl()\n\n fun digits(x: Long): Int {\n var a = abs(x)\n var k = 0\n while(a > 0) {\n a /= 10\n k++\n }\n return k\n }\n\n val memo = mutableMapOf()\n fun dfs(x: Long, isAlt: Boolean = false): Int {\n debug{\"x:$x\"}\n if (x == 0L) return 0\n if (memo.containsKey(x)) return memo[x]!!\n\n var a = x\n var k = 1\n var pow10 = 1L\n var sum = 1L\n while(a / 10 != 0L) {\n a /= 10\n k++\n pow10 *= 10\n sum += pow10\n }\n\n var res = 1e9.toInt()\n for (i in 1 .. 9) {\n for (sig in arrayOf(-1, 1)) {\n val next = x + sum * i * sig\n if (digits(next) < k) res = min(res, dfs(next) + k * i)\n }\n }\n\n if (!isAlt) {\n for (sig in arrayOf(-1, 1)) {\n val sum2 = sum + pow10 * 10\n val alt = x + sum2 * sig\n debug{\"x:$x alt$alt\"}\n if (digits(alt) <= k) res = min(res, dfs(alt, true) + k + 1)\n }\n }\n\n memo[x] = res\n return res\n }\n out.println(dfs(N))\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl()\n }\n return res\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}"}, {"source_code": "import kotlin.math.min\n\nval ones = ArrayList()\n\nfun lowerBound(n: Long): Int{\n var(lo, hi) = 0 to ones.size - 1\n while(lo < hi){\n val mid = (lo + hi) / 2 + (lo + hi) % 2\n if(ones[mid] < n)\n lo = mid\n else\n hi = mid - 1\n }\n return lo\n}\n\nval memo = HashMap()\n\nfun rec(n: Long): Long{\n if(n in memo)\n return memo[n]!!\n val bs = lowerBound(n)\n if(ones[bs + 1] == n){\n memo[n] = (bs + 2).toLong()\n return (bs + 2).toLong()\n }\n var ans = Long.MAX_VALUE\n if(n - ones[bs] < n)\n ans = min(ans, rec(n - ones[bs]) + bs + 1)\n if(ones[bs + 1] - n < n)\n ans = min(ans, rec(ones[bs + 1] - n) + bs + 2)\n memo[n] = ans\n return ans\n}\n\nfun main() {\n val n = readLine()!!.toLong()\n for(i in 1..16)\n ones.add(\"1\".repeat(i).toLong())\n memo[0L] = 0L\n for(i in 1L..6L)\n memo[i] = i\n for(i in 7L..11L)\n memo[i] = 13-i\n println(rec(n))\n}"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() {\n val n0 = readLong()\n\n val M = LongArray(17)\n for(i in 1 until M.size) M[i] = M[i-1] * 10 + 1\n\n var D = hashMapOf(n0 to 0)\n\n for(k in M.size-2 downTo 1) {\n if(M[k] > n0) continue\n\n val Dk = HashMap()\n\n for((n, c) in D) {\n Dk.checkMin(n % M[k], c + (n / M[k] * k).toInt())\n val n1 = M[k+1] - n\n Dk.checkMin(n1 % M[k], c + k + 1 + (n1 / M[k] * k).toInt())\n }\n\n D = Dk\n }\n\n val ans = D[0]\n\n println(ans)\n}\n\nfun HashMap.checkMin(k: K, v: Int) { if(v < getOrDefault(k, Int.MAX_VALUE)) put(k, v) }\n\n/** IO code start */\n@JvmField val _reader = System.`in`.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(System.out, false)\ninline fun output(block: PrintWriter.()->Unit) { _writer.apply(block).flush() }\nfun iprintln(o: Any?) { println(o) } // immediate println for interactive, bypasses output{} blocks"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() {\n val n0 = readLong()\n\n val M = LongArray(17)\n for(i in 1 until M.size) M[i] = M[i-1] * 10 + 1\n\n var D = hashMapOf(n0 to 0)\n\n for(k in M.size-2 downTo 1) {\n if(M[k] > n0) continue\n\n val Dk = HashMap()\n\n for((n, c) in D) {\n Dk.checkMin(n % M[k], c + (n / M[k] * k).toInt())\n val n1 = M[k+1] - n\n Dk.checkMin(n1 % M[k], c + k + 1 + (n1 / M[k] * k).toInt())\n }\n\n D = Dk\n }\n\n val ans = D[0]\n\n println(ans)\n}\n\nfun HashMap.checkMin(k: K, v: Int) { if(!containsKey(k) || v < get(k)!!) put(k, v) }\n\n/** IO code start */\n@JvmField val _reader = System.`in`.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(System.out, false)\ninline fun output(block: PrintWriter.()->Unit) { _writer.apply(block).flush() }\nfun iprintln(o: Any?) { println(o) } // immediate println for interactive, bypasses output{} blocks"}, {"source_code": "import kotlin.math.*\n \nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of ints\nfun readLong() = readLn().toLong() // list of strings\n \nfun getLength(_n:Long):Int{\n var n = _n\n if (n == 0L)\n return 0\n var ret = 0\n while(n > 0L)\n {\n ret++\n n = n / 10\n }\n return ret\n}\n \nfun get1(_l:Int):Long{\n var n = _l\n if (n == 0)\n return 1\n var ret = 1L\n while(n > 1)\n {\n ret=1 + ret * 10\n n--\n }\n return ret\n}\n \n \nfun main() {\n val n =readLong()\n val res = getCount(n, getLength(n) + 1 )\n // println(res)\n println(get1Count(res))\n}\n \nfun get1Count(lst:List):Int\n{\n var ret = 0\n for(i in 0 until lst.size)\n { \n val item = lst[i]\n ret+=(i+1)*item.absoluteValue\n }\n return ret\n}\n \nfun getCount(_n:Long, _l:Int):MutableList\n{ \n if (_n ==0L && _l ==0)\n return mutableListOf()\n \n var n =if (_n> 0) _n else -_n\n \n val l = _l\n \n if (l == 1)\n { \n return mutableListOf(n.toInt()) \n }\n \n \n val l1 = get1(l)\n \n val bDigit = (n / l1).toInt() \n val tDigit = bDigit + 1\n \n val solb = getCount(n - l1 * bDigit, l - 1)\n val vb = get1Count(solb) + bDigit * l\n \n val solt = getCount(l1 * tDigit - n, l - 1) \n for (i in 0 until solt.size) {\n solt[i] = -solt[i]\n }\n val vt = get1Count(solt) + tDigit * l\n\n if (vb < vt)\n {\n solb.add(0)\n solb[l-1] = bDigit\n return solb\n }\n else\n {\n solt.add(0)\n solt[l-1] = tDigit\n return solt \n }\n\n \n}\n"}, {"source_code": "import kotlin.math.min\n\nfun main(args: Array) {\n val n = readLine()!!.toLong()\n println(f(n))\n}\n\nval ones = LongArray(16) { \"1\".repeat(it + 1).toLong() }\n\nprivate fun f(n: Long): Long {\n if (n == 0L) return 0\n val len = n.toString().length\n val number = ones[len - 1]\n val lower = n / number\n val n1 = n - lower * number\n val n2 = (lower + 1) * number - n\n val n3 = number * 10 + 1 - n\n var res = Long.MAX_VALUE\n if (n1 < n) {\n res = min(res, f(n1) + lower * len)\n }\n if (n3 < n) {\n res = min(res, f(n3) + len + 1)\n }\n if (n2 < n && (lower + 1) * len < res) {\n res = min(res, f(n2) + (lower + 1) * len)\n }\n return res\n}"}, {"source_code": "import java.util.*\n \nfun main() {\n val sc = Scanner(System.`in`)\n val n = sc.nextLong()\n val Z = LongArray(20)\n Z[1] = 1\n for (i in 2 until Z.size) {\n Z[i] = Z[i - 1] * 10 + 1\n }\n var res = Long.MAX_VALUE\n for (len in 1..17) {\n for (m in 0..(1 shl len)) {\n var cur = 0L\n var cnt = 0L\n for (i in len downTo 1) {\n val overflow = (m and (1 shl i)) != 0\n if (cur < n) {\n val am = (n - cur) / Z[i]\n cur += Z[i] * am\n cnt += i * am\n if (overflow && cur < n) {\n cur += Z[i]\n cnt += i\n }\n } else if (cur > n) {\n val am = (cur - n) / Z[i]\n cur -= Z[i] * am\n cnt += i * am\n if (overflow && cur > n) {\n cur -= Z[i]\n cnt += i\n }\n }\n }\n if (cur == n)\n res = minOf(res, cnt)\n }\n }\n println(res)\n}"}, {"source_code": "import java.util.*\n\n\nvar array__ = LongArray(18)\nvar res = 100000000000000000L\nfun fffffffffffffffffffff(n_now: Long, pre: Int, total: Long) {\n if (pre == 0) {\n if (res > total) res = total\n return\n }\n if (n_now >= 0) {\n fffffffffffffffffffff(n_now - n_now / array__[pre] * array__[pre], pre - 1, total + n_now / array__[pre] * pre)\n fffffffffffffffffffff(n_now - (n_now / array__[pre] + 1) * array__[pre], pre - 1, total + (n_now / array__[pre] + 1) * pre)\n } else {\n fffffffffffffffffffff(n_now + -n_now / array__[pre] * array__[pre], pre - 1, total + -n_now / array__[pre] * pre)\n fffffffffffffffffffff(n_now + (-n_now / array__[pre] + 1) * array__[pre], pre - 1, total + (-n_now / array__[pre] + 1) * pre)\n }\n}\n\nfun main(args: Array) {\n array__[1] = 1\n for (i in 2..16)\n array__[i] = array__[i - 1] * 10 + 1\n val cin = Scanner(System.`in`)\n var n = cin.nextLong()\n fffffffffffffffffffff(n, 16, 0)\n System.out.print(res)\n}"}, {"source_code": "// https://kotlinlang.org/docs/tutorials/competitive-programming.html\n// https://stackoverflow.com/questions/41283393/reading-console-input-in-kotlin\n\nimport java.io.*\nimport java.lang.Math.*\nimport java.util.*\n\nprivate fun readln() = readLine()!!\nprivate fun readlnByte() = readln().toByte()\nprivate fun readlnShort() = readln().toShort()\nprivate fun readlnInt() = readln().toInt()\nprivate fun readlnLong() = readln().toLong()\nprivate fun readlnFloat() = readln().toFloat()\nprivate fun readlnDouble() = readln().toDouble()\nprivate fun readlnBigInt(radix: Int = 10) = readln().toBigInteger(radix)\nprivate fun readlnBigDecimal() = readln().toBigDecimal()\n\nprivate fun lineSequence(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.constrainOnce().take(limit)\nprivate fun readlnStrings() = readln().split(' ')\nprivate fun readlnBytes() = readlnStrings().map { it.toByte() }\nprivate fun readlnShorts() = readlnStrings().map { it.toShort() }\nprivate fun readlnInts() = readlnStrings().map { it.toInt() }\nprivate fun readlnLongs() = readlnStrings().map { it.toLong() }\nprivate fun readlnFloats() = readlnStrings().map { it.toFloat() }\nprivate fun readlnDoubles() = readlnStrings().map { it.toDouble() }\n\nprivate fun readByteArray() = readlnStrings().run { ByteArray(size) { get(it).toByte() } }\nprivate fun readShortArray() = readlnStrings().run { ShortArray(size) { get(it).toShort() } }\nprivate fun readIntArray() = readlnStrings().run { IntArray(size) { get(it).toInt() } }\nprivate fun readLongArray() = readlnStrings().run { LongArray(size) { get(it).toLong() } }\nprivate fun readFloatArray() = readlnStrings().run { FloatArray(size) { get(it).toFloat() } }\nprivate fun readDoubleArray() = readlnStrings().run { DoubleArray(size) { get(it).toDouble() } }\n\nprivate fun readlnByteArray(n: Int) = ByteArray(n) { readlnByte() }\nprivate fun readlnShortArray(n: Int) = ShortArray(n) { readlnShort() }\nprivate fun readlnIntArray(n: Int) = IntArray(n) { readlnInt() }\nprivate fun readlnLongArray(n: Int) = LongArray(n) { readlnLong() }\nprivate fun readlnFloatArray(n: Int) = FloatArray(n) { readlnFloat() }\nprivate fun readlnDoubleArray(n: Int) = DoubleArray(n) { readlnDouble() }\n\nprivate fun readByteArray2d(rows: Int, cols: Int) = Array(rows) { readByteArray().also { require(it.size == cols) } }\nprivate fun readShortArray2d(rows: Int, cols: Int) = Array(rows) { readShortArray().also { require(it.size == cols) } }\nprivate fun readLongArray2d(rows: Int, cols: Int) = Array(rows) { readLongArray().also { require(it.size == cols) } }\nprivate fun readIntArray2d(rows: Int, cols: Int) = Array(rows) { readIntArray().also { require(it.size == cols) } }\nprivate fun readFloatArray2d(rows: Int, cols: Int) = Array(rows) { readFloatArray().also { require(it.size == cols) } }\nprivate fun readDoubleArray2d(rows: Int, cols: Int) =\n Array(rows) { readDoubleArray().also { require(it.size == cols) } }\n\n\nprivate fun isWhiteSpace(c: Char) = c in \" \\r\\n\\t\"\n\n// JVM-only targeting code follows next\n\n// readString() via sequence is still slightly faster than Scanner\nprivate fun readString() = generateSequence { System.`in`.read().toChar() }\n .dropWhile { isWhiteSpace(it) }.takeWhile { !isWhiteSpace(it) }.joinToString(\"\")\n\nprivate fun readByte() = readString().toByte()\nprivate fun readShort() = readString().toShort()\nprivate fun readInt() = readString().toInt()\nprivate fun readLong() = readString().toLong()\nprivate fun readFloat() = readString().toFloat()\nprivate fun readDouble() = readString().toDouble()\nprivate fun readBigInt(radix: Int = 10) = readString().toBigInteger(radix)\nprivate fun readBigDecimal() = readString().toBigDecimal()\n\nprivate fun readBytes(n: Int) = generateSequence { readByte() }.take(n)\nprivate fun readShorts(n: Int) = generateSequence { readShort() }.take(n)\nprivate fun readInts(n: Int) = generateSequence { readInt() }.take(n)\nprivate fun readLongs(n: Int) = generateSequence { readLong() }.take(n)\nprivate fun readFloats(n: Int) = generateSequence { readFloat() }.take(n)\nprivate fun readDoubles(n: Int) = generateSequence { readDouble() }.take(n)\n\nprivate fun printIntArray(a: IntArray) {\n println(a.joinToString(\", \"))\n}\n\nprivate fun printLongArray(a: LongArray) {\n println(a.joinToString(\", \"))\n}\n\nprivate fun printDoubleArray(a: DoubleArray) {\n println(a.joinToString(\", \"))\n}\n\nprivate fun printFloatArray(a: FloatArray) {\n println(a.joinToString(\", \"))\n}\n\nprivate fun printStringArray(a: Array) {\n println(a.joinToString(\", \"))\n}\n\nprivate fun main() {\n// test()\n// benchMark()\n val n = readlnLong()\n var ans = solve(n)\n println(ans)\n}\n\nprivate fun test() {\n var l=10000000L\n for (i in l*l*10-100..l*l*10) {\n// for (i in 1L..100L) {\n println(i)\n val b = dfs(i, getDigitCount(i) + 1, 0)\n val a = dfs1(i, getDigitCount(i) + 1, 0)\n if(a!=b){\n println(\"$i: $a $b\")\n }\n\n }\n}\n\nprivate fun benchMark() {\n var l=10000000L\n for (i in l*l*10-100..l*l*10) {\n cnt = 0\n println(\"$i: ${solve(i)} $cnt\")\n }\n}\nvar cnt:Int = 0\nprivate fun solve(n: Long): Int {\n var d = getDigitCount(n)\n return dfs1(n, d + 1, 0)\n}\n\nconst val MAX = 100000\nfun dfs(n: Long, d: Int, c: Int): Int {\n if (d == 0) {\n return if (n == 0L) c else MAX\n }\n var minC = Int.MAX_VALUE\n for (i in 0..9) {\n val addend = gen(i, d)\n minC = minC.coerceAtMost(dfs(n + addend, d - 1, c + d * i))\n minC = minC.coerceAtMost(dfs(n - addend, d - 1, c + d * i))\n }\n return minC\n}\n\nfun dfs1(n: Long, d: Int, c: Int): Int {\n cnt++\n if (d == 0) {\n return if (n == 0L) c else MAX\n }\n val hd = getHighestDigit(n)\n var minC = Int.MAX_VALUE\n val maxDiff = gen(1, d)\n for (i in 0..9) {\n val addend = gen(i, d)\n// if(addend <= n && n - addend < maxDiff){\n// minC = minC.coerceAtMost(dfs1(n - addend, d - 1, c + d * i))\n// }\n// else if(addend >= n && addend - n < maxDiff){\n// minC = minC.coerceAtMost(dfs1(addend - n, d - 1, c + d * i))\n// }\n if (kotlin.math.abs(n - addend) < maxDiff) {\n\n minC = minC.coerceAtMost(dfs1(kotlin.math.abs(n - addend), d - 1, c + d * i))\n }\n }\n return minC\n}\n\nprivate fun solve(n: String, c: Int): Int {\n val nn = n.toLong()\n if (nn == 0L) {\n return c\n }\n val d = n.length\n val lb = n.substring(0, 1).repeat(d).toLong()\n val ub = \"1\".repeat(d + 1).toLong()\n var minC = Int.MAX_VALUE\n val ex = solveIdenticalDigit(lb.toString())\n// println(\"${lb.toString()}: $ex\")\n if (lb > nn) {\n minC = minC.coerceAtMost(solve((lb - nn).toString(), c) + ex)\n } else {\n minC = minC.coerceAtMost(solve((lb - nn).toString(), c) + ex)\n }\n if (nn > ub / 2) {\n minC = minC.coerceAtMost(solve((ub - nn).toString(), c + d + 1))\n }\n// println(\"$n: $minC\")\n return minC\n}\n\nfun solveIdenticalDigit(n: String): Int {\n\n val nn = n.toLong()\n val d = n.length\n val digit = n.substring(0, 1).toInt()\n if (digit == 1) {\n return d\n }\n val ub = \"1\".repeat(d + 1).toLong()\n return if (nn > ub / 2) {\n (d * digit).coerceAtMost(d + 1 + solve((ub - nn).toString(), 0))\n } else {\n (d * digit)\n }\n\n}\n\nprivate fun gen(n: Int, k: Int): Long {\n var ret = 0L\n var i = 0\n while (i < k) {\n ret *= 10\n ret += n\n i++\n }\n return ret\n}\n\nprivate fun getDigitCount(n: Long): Int {\n var x = n\n var i = 0\n while (x != 0L) {\n x /= 10\n i++\n }\n return i\n}\n\nprivate fun getHighestDigit(n: Long): Int {\n var x = n\n while (x / 10 != 0L) {\n x /= 10\n }\n return x.toInt()\n}"}, {"source_code": "import java.util.*;\nimport java.lang.*;\n\nfun main(args:Array){\n\n\n var read = Scanner(System.`in`)\n println(min_ones(read.nextLong()));\n} \n\nfun min_ones(n:Long):Long{\n // println(n)\n if(n==0L){\n return 0;\n }\n var digits = 0*1L\n var temp = n;\n while(temp>0){\n temp/=10; digits++;\n }\n var p = 0L;\n for( i in 0 until digits){\n p *= 10\n p++\n }\n if(p<=n){\n var p2 = p*10 +1;\n var k = 0L\n var count = 0L\n while(k+p<=n){\n k += p;\n count += digits\n }\n var ans = min_ones(n-k)+count\n\n k = p2;\n count = digits+1;\n while(k-p>=n){\n k -= p;\n count += digits\n }\n ans = Math.min(ans , min_ones(k-n) + count);\n return ans\n }\n else{\n return min_ones(p-n)+digits;\n }\n}"}, {"source_code": "import kotlin.math.absoluteValue\nimport kotlin.random.Random\n\n\nfun power(base: Long, exp: Int): Long {\n return when(exp){\n 0 -> 1L\n 1 -> base\n else -> power(base * base, exp / 2) * power(base, exp % 2)\n }\n}\nfun calMin(value: Long, digit: Int, base: Long): Long {\n return when(digit){\n 1 -> value.absoluteValue\n else -> {\n if (value >= 0) {\n val b = value / base\n (b..b + 1).map { calMin(value - it * base, digit - 1, base / 10) + digit * it.absoluteValue }.min()!!\n }else {\n val b = value / base\n (b - 1 .. b).map{calMin(value - it * base, digit - 1, base / 10) + digit * it.absoluteValue}.min()!!\n }\n }\n }\n}\nfun calMin2(value: Long, digit: Int, base: Long): Long {\n return when(digit){\n 1 -> value.absoluteValue\n else -> {\n (-10 .. 10).map{calMin(value - it * base, digit - 1, base / 10) + digit * it.absoluteValue}.min()!!\n }\n }\n}\nconst val digit = 15\nfun calMin(value: Long): Long = calMin(value, digit + 1, power(10L, digit + 1) / 9)\nfun calMin2(value: Long): Long = calMin2(value, digit + 1, power(10L, digit + 1) / 9)\nfun main(args: Array?): Unit {\n println(calMin(readLine()!!.trim().toLong()))\n}"}, {"source_code": "import java.util.*\n \n \nvar kkkkkkkkkkkkkkk = LongArray(18)\nvar aaaaaaaaaaaaa = 100000000000000000L\nfun mmmmmmmmmmm(tttttttttttttttttt: Long, now: Int, bbbbbbbbbbbb: Long) {\n if (now == 0) {\n if (aaaaaaaaaaaaa > bbbbbbbbbbbb) aaaaaaaaaaaaa = bbbbbbbbbbbb\n return\n }\n if (tttttttttttttttttt >= 0) {\n val zzzzzzzzzzzzzzzzz = tttttttttttttttttt / kkkkkkkkkkkkkkk[now]\n mmmmmmmmmmm(tttttttttttttttttt - zzzzzzzzzzzzzzzzz * kkkkkkkkkkkkkkk[now], now - 1, bbbbbbbbbbbb + zzzzzzzzzzzzzzzzz * now)\n mmmmmmmmmmm(tttttttttttttttttt - (zzzzzzzzzzzzzzzzz + 1) * kkkkkkkkkkkkkkk[now], now - 1, bbbbbbbbbbbb + (zzzzzzzzzzzzzzzzz + 1) * now)\n } else {\n val zzzzzzzzzzzzzzzzz = -tttttttttttttttttt / kkkkkkkkkkkkkkk[now]\n mmmmmmmmmmm(tttttttttttttttttt + zzzzzzzzzzzzzzzzz * kkkkkkkkkkkkkkk[now], now - 1, bbbbbbbbbbbb + zzzzzzzzzzzzzzzzz * now)\n mmmmmmmmmmm(tttttttttttttttttt + (zzzzzzzzzzzzzzzzz + 1) * kkkkkkkkkkkkkkk[now], now - 1, bbbbbbbbbbbb + (zzzzzzzzzzzzzzzzz + 1) * now)\n }\n}\n \nfun main(args: Array) {\n kkkkkkkkkkkkkkk[1] = 1\n for (ooooooooooooooo in 2..16) kkkkkkkkkkkkkkk[ooooooooooooooo] = kkkkkkkkkkkkkkk[ooooooooooooooo - 1] * 10 + 1\n val input = Scanner(System.`in`)\n val tttttttttttttttttt = input.nextLong()\n mmmmmmmmmmm(tttttttttttttttttt, 16, 0)\n println(aaaaaaaaaaaaa)\n input.close()\n}"}, {"source_code": "import java.lang.Math.*\nimport java.util.*\n\n/**\n * Created by Administrator on 9/2/2019.\n */\n\n// for (i in 1..n) {}\n// for (i in 5 downTo 1)\n// for (i in 1..5 step 2)\n// println(n)\n// println(\"${ansList.size} $ans\")\n// val freq = mutableMapOf()\n// var places = mutableListOf()\n// class Place(val x: Int, val b: Int)\n// teams.sortWith(compareBy({it.size}));\n// val pq = PriorityQueue(Comparator{a1, a2 -> a2.money - a1.money})\n// var size = IntArray(402){0}\n// var dp = Array(402, {IntArray(402)})\n// var adj = MutableList>(402) {_ -> mutableListOf()}\n// println(Arrays.toString(array))\n// println(Arrays.deepToString(array))\n// Pair\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of Longs\n\nvar dp = Array(17, {Array(46, {Array(46, {Array(32, {1000000})})})})\nvar S = \"\"\n\nfun DP(at: Int, pos: Int, neg: Int, bc: Int): Int {\n if (at == 16) {\n if (bc == 0) return 0\n return 1000000\n }\n if (dp[at][pos][neg][bc + 16] != 1000000) {\n return dp[at][pos][neg][bc + 16]\n }\n dp[at][pos][neg][bc + 16] = 999999\n if (pos > 0) {\n var cur = DP(at, pos - 1, neg, bc)\n if (cur < dp[at][pos][neg][bc + 16]) dp[at][pos][neg][bc + 16] = cur\n }\n if (neg > 0) {\n var cur = DP(at, pos, neg - 1, bc)\n if (cur < dp[at][pos][neg][bc + 16]) dp[at][pos][neg][bc + 16] = cur\n }\n val now = bc + pos - neg\n var new_carry = 0\n if (now >= 0) new_carry = now / 10\n var new_borrow = 0\n if (now < 0) new_borrow = -((-now + 9) / 10)\n var last_degit = 0\n if (now >= 0) last_degit=now % 10\n else last_degit = (10 - (-now % 10)) % 10\n var expected = 0\n if (at < S.length) expected = (S[at] - '0').toInt()\n if (last_degit != expected) {\n return dp[at][pos][neg][bc + 16]\n }\n var cur = DP(at + 1, pos, neg, new_carry + new_borrow) + pos + neg\n if (cur < dp[at][pos][neg][bc + 16]) dp[at][pos][neg][bc + 16] = cur\n return dp[at][pos][neg][bc + 16]\n}\n\nfun main(args: Array) {\n S = readLn()\n S = S.reversed()\n var ans = 30000\n for (pos in 0..45) for (neg in 0..45) {\n val cur = DP(0, pos, neg, 0)\n if (cur < ans) ans = cur\n //if (cur == 224) println(\"$pos $neg\")\n }\n println(ans)\n}\n"}, {"source_code": "import java.io.*\nimport java.lang.Math.abs\nimport java.lang.Math.min\nimport java.util.*\nimport java.util.Arrays.sort\nimport kotlin.collections.HashMap\n\nval mem = HashMap()\nfun go(x: Long, pr: Long = Long.MAX_VALUE): Int{\n if (abs(pr) < abs(x)) return 1000000\n if (x == 0.toLong()) return 0\n if (mem.contains(x)) return mem[x]!!\n val n = abs(x).toString().length\n var s1 = \"\"\n var s2 = \"\"\n for (i in 1..n){\n s1 += \"1\"\n s2 += \"1\"\n }\n s2 += \"1\"\n var x1 = s1.toLong()\n var x2 = s2.toLong()\n if (x < 0){\n x1 *= -1\n x2 *= -1\n }\n val ans = min(go(x - x2, x) + n + 1, n + min(go(x - x1, x), go(x + x1, x)))\n mem[x] = ans\n return ans\n}\n\nfun main(args: Array){\n val x = readLine()!!.toLong()\n println(go(x))\n}"}, {"source_code": "import java.util.*\n \ninternal var ones = LongArray(17)\ninternal fun dfs(n: Long, i: Int): Long {\n var n = n\n val k = (n / ones[i]).toInt()\n n %= ones[i]\n val count = (k * i).toLong()\n return if (n == 0L)\n count\n else\n count + Math.min(i + dfs(ones[i] - n, i - 1), dfs(n, i - 1))\n}\n \nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val n = scan.nextLong()\n ones[0] = 0\n for (i in 1..16) {\n ones[i] = ones[i - 1] * 10 + 1\n }\n println(dfs(n, 16))\n}"}, {"source_code": "fun pow(a : Long, r : Int) : Long = if(r == 0) 1L else pow(a, r - 1) * a\nvar p = Array(17){i -> (pow(10L, i + 1) - 1) / 9}\nfun solve(n : Long, i : Int) : Int{\n var res = (n / p[i] * (i + 1)).toInt()\n var m = n % p[i]\n if(m == 0L) return res\n return res + minOf(i + 1 + solve(p[i] - m, i - 1), solve(m, i - 1))\n}\nfun main() {\n print(solve(readLine()!!.toLong(), 16))\n}"}, {"source_code": "\nfun pow(a : Long, r : Int) : Long = if(r == 0) 1L else pow(a, r - 1) * a\nvar p = Array(16){i -> (pow(10L, i + 1) - 1) / 9}\nfun solve(n : Long, i : Int) : Int{\n var res = (n / p[i] * (i + 1)).toInt()\n var m = n % p[i]\n if(m == 0L) return res\n return res + minOf(i + 1 + solve(p[i] - m, i - 1), solve(m, i - 1))\n}\nfun main() {\n print(solve(readLine()!!.toLong(), 15))\n}\n"}, {"source_code": "import java.io.*\nimport kotlin.math.*\nimport kotlin.collections.*\n\nfun main() = bufferOut { readSolveWrite() }\n\nprivate fun PrintWriter.readSolveWrite() {\n val n = readLine()!!.toLong()\n var degs = arrayListOf()\n degs.add(0L)\n degs.add(1L)\n for (i in 1..18)\n degs.add(degs[i] * 10L + 1L)\n\n fun rec(x: Long, d: Int): Long\n {\n val cur = abs(x)\n if (cur % degs[d] == 0L)\n return cur / degs[d] * d\n val k = cur / degs[d]\n val temp1 = (k * d + rec(cur - k * degs[d], d - 1))\n val temp2 = ((k + 1) * d + rec((k + 1) * degs[d] - cur, d - 1))\n return min(temp1, temp2)\n }\n println(rec(n, 18))\n}\n\nprivate fun ok(x: Boolean) = if (x) 1 else 0// {{{\n\nprivate fun getIntArray() = readLine()!!.splitToIntArray()\n\nprivate fun bufferOut(block: PrintWriter.() -> Unit) = PrintWriter(System.out).use { block(it) }\n\ndata class Pt(val x: Int, val y: Int, val i: Int, var ans: Int)\n\nprivate fun String.splitToIntArray(): IntArray {\n val n = length\n if (n == 0) return IntArray(0) // EMPTY\n var res = IntArray(4)\n var m = 0\n var i = 0\n while (true) {\n var cur = 0\n var neg = false\n var c = get(i) // expecting number, IOOB if there is no number\n if (c == '-') {\n neg = true\n i++\n c = get(i) // expecting number, IOOB if there is no number\n }\n while (true) {\n val d = c.toInt() - '0'.toInt()\n require(d in 0..9) { \"Unexpected character '$c' at $i\" }\n require(cur >= Integer.MIN_VALUE / 10) { \"Overflow at $i\" }\n cur = cur * 10 - d\n require(cur <= 0) { \"Overflow at $i\" }\n i++\n if (i >= n) break\n c = get(i)\n if (c == ' ') break\n }\n if (m >= res.size) res = res.copyOf(res.size * 2)\n res[m++] = if (neg) cur else (-cur).also { require(it >= 0) { \"Overflow at $i\" } }\n if (i >= n) break\n i++\n }\n if (m < res.size) res = res.copyOf(m)\n return res\n}// }}}\n"}, {"source_code": "import java.lang.Math.abs\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n\nfun main(args: Array) {\n var s = readLn().reversed() + \"000\"\n var len = s.length\n val MAX = 200\n var dp = Array(len + 1, { Array(2 * MAX, { IntArray(2 * MAX, { 12345 }) }) })\n dp[0][MAX][MAX] = 0\n for (i in 0..len - 1) {\n for (cur in -MAX..MAX-1) {\n for (carry in -MAX..MAX-1) {\n var ft = dp[i][cur + MAX][carry + MAX]\n if (ft == 12345) {\n continue\n }\n for (delta in -100..100) {\n var newCur = cur + delta\n var here = newCur + carry\n var value = (here % 10 + 10) % 10\n if (value != s[i] - '0') {\n continue\n }\n var newCarry = (here - value) / 10\n var newFt = ft + abs(delta) * i\n if (newCur >= -MAX && newCur < MAX && newCarry >= -MAX && newCarry < MAX && newFt < dp[i + 1][newCur + MAX][newCarry + MAX]) {\n dp[i + 1][newCur + MAX][newCarry + MAX] = newFt\n }\n }\n }\n }\n }\n println(dp[len][MAX][MAX])\n}"}, {"source_code": "import java.io.OutputStream\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.PrintWriter\nimport java.util.Scanner\nimport kotlin.math.min\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author maxkibble\n */\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val `in` = Scanner(inputStream)\n val out = PrintWriter(outputStream)\n solve(1, `in`, out)\n out.close()\n}\n\nfun lower(x: Long): Long {\n var ret: Long = 1\n while (x >= ret) {\n ret = ret * 10 + 1\n }\n ret = (ret - 1) / 10\n return ret\n}\n\nfun f(x: Long, y: Long): Long {\n if (x == 0L) return 0\n val l = lower(x)\n val u = l * 10 + 1\n var a = l.toString().length * 1L\n val b = a + 1\n a = x / l * a + f(x % l, l)\n if (u <= y) a = min(a, b + f(u - x, u - 1))\n return a\n}\n\nfun solve(testNumber: Int, `in`: Scanner, out: PrintWriter) {\n val n = `in`.nextLong()\n out.println(f(n, 1111111111111111L))\n}\n\n\n"}, {"source_code": "import kotlin.math.min\n \nfun f(n: Long, s: Long, l: Int): Long {\n if (s == 0L) return if (n == 0L) 0L else Long.MAX_VALUE / 2\n val q = n / s\n return min(f(n - q * s, s / 10, l - 1) + l * q, f((q + 1) * s - n, s / 10, l - 1) + l * (q + 1))\n}\n \nfun main() = println(f(readLine()!!.toLong(), 1111_1111_1111_1111L, 16))"}, {"source_code": "fun readLn(): String = readLine()!!\nfun readInt(): Int = readLn().toInt()\nfun readInts(): MutableList = readLn().split(\" \").map { it.toInt() }.toMutableList()\nfun readLong(): Long = readLn().toLong()\n\nval results = mutableMapOf(0L to 0L)\n\nfun preprocess() {\n val MAX = 1e17\n var x = 1L\n var ones = 1L\n while (x < MAX) {\n results[x] = ones\n x = 10 * x + 1\n ones++\n }\n}\n\nfun firstSmallerOnes(number: Long): Pair {\n var x = 1L\n var ones = 1L\n while (x < number) {\n x = 10 * x + 1\n ones++\n }\n x /= 10\n ones--\n return Pair(x, ones)\n}\n\nfun solve(number: Long): Long {\n if (number in results) return results[number]!!\n val (smallerOnes, ones) = firstSmallerOnes(number)\n\n val quotient = number / smallerOnes\n val remainder = number % smallerOnes\n var result = ones * quotient + solve(remainder)\n // println(\"$number $quotient $smallerOnes $remainder $result\")\n\n val largerOnes = smallerOnes * 10 + 1\n val ones1 = ones + 1\n val remainder2 = largerOnes - number\n if (remainder2 < number) {\n result = Math.min(ones1 + solve(remainder2), result)\n }\n\n results[number] = result\n return result\n}\n\nfun main(args: Array) {\n preprocess()\n val number = readLong()\n println(solve(number))\n}\n\n"}, {"source_code": "import kotlin.math.min\n\n//https://codeforces.com/contest/1212/problem/F\n\nfun main() {\n\n fun calculate(n: Long, s: Long, l: Long): Long {\n if (n < 0) return calculate(-n, s, l)\n if (n == 0L) return 0L\n if (s == 0L) return n\n val q = n / s\n return min(calculate(n - q * s, s / 10, l - 1) + l * q, calculate(n - (q + 1) * s, s / 10, l - 1) + l * (q + 1))\n }\n\n readLine()?.let {\n val n = it.toLong()\n println(calculate(n, 1111111111111111, 16))\n }\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.min\n\nvar oneList = mutableListOf(0)\nvar problemResult = Int.MAX_VALUE\n\nfun main() {\n val read = Scanner(System.`in`)\n var start = 0L\n for (i in 1..16) {\n start = start * 10 + 1\n oneList.add(start)\n }\n val n = read.nextLong()\n dfs(getLength(n) + 1, n, 0)\n println(problemResult)\n}\n\n\n\nfun dfs(length : Int, num : Long, ans : Int) {\n if (length == 0) {\n problemResult = min(problemResult, ans)\n return\n }\n if (ans > problemResult) {\n return\n }\n if (num == oneList[length]) {\n val times = num.div(oneList[length])\n val ansNow = ans + length * times.toInt()\n dfs(0, 0, ansNow)\n } else {\n val times = num.div(oneList[length])\n val numNow = num - times * oneList[length]\n val ansNow = ans + length * times.toInt()\n dfs(length - 1, numNow, ansNow)\n dfs(length - 1, oneList[length] - numNow, ansNow + length)\n }\n}\nfun getLength(num: Long) : Int {\n var a = num\n var result = 0\n while (a > 0) {\n a /= 10\n result++\n }\n return result\n}\n"}, {"source_code": "/* f */\n\nval f = Array(17) { 0L }\n\nfun dp(n: Long, w: Int): Long {\n val y = (n / f[w]) * w\n val nn = n % f[w]\n if (nn == 0L) return y\n return y + Math.min(dp(nn, w - 1), dp(f[w] - nn, w - 1) + w)\n}\n\nfun main(args: Array) {\n val n = readLine().toString().toLong()\n for (i in 1..16) {\n f[i] = f[i - 1] * 10L + 1L\n }\n print(dp(n, 16))\n}\n\n"}, {"source_code": "fun readLong() = readLine()!!.toLong()\n\nfun main() {\n val number = readLong()\n println(countOfOnesCached(number))\n// (1..10000).forEach {\n// println(\"$it->${countOfOnesCached(it.toLong())}\")\n// }\n}\n\nval cache = mutableMapOf()\nfun countOfOnesCached(number: Long): Int {\n return cache.computeIfAbsent(number, ::countOfOnes)\n}\n\nfun countOfOnes(number: Long): Int {\n val digitCount = number.toString().count()\n val firstDigit = number.toString().first().toString().toInt()\n return when {\n number == 0L -> 0\n number == generateNumber(1, digitCount) -> digitCount\n else -> {\n val results = mutableListOf()\n val a = generateNumber(firstDigit, digitCount)\n when {\n number == a -> {\n results += digitCount * firstDigit\n }\n number > a -> {\n results += digitCount * firstDigit + countOfOnesCached(number - a)\n if (firstDigit != 9) {\n val b = generateNumber(firstDigit + 1, digitCount)\n results += digitCount * (firstDigit + 1) + countOfOnesCached(b - number)\n }\n }\n number < a -> {\n results += digitCount * firstDigit + countOfOnesCached(a - number)\n if (firstDigit != 1) {\n val b = generateNumber(firstDigit - 1, digitCount)\n results += digitCount * (firstDigit - 1) + countOfOnesCached(number - b)\n }\n }\n }\n val c = generateNumber(1, digitCount + 1)\n val delta = c - number\n if (delta < number) {\n results += countOfOnesCached(c) + countOfOnesCached(delta)\n }\n results.min()!!\n }\n }\n}\n\nfun generateNumber(digit: Int, count: Int) = generateSequence(digit.toLong()) { it * 10 + digit }.take(count).last()"}, {"source_code": "fun rec(n: Long) : Int {\n if (n == 0L) {\n return 0\n }\n var ones = 1L\n var cnt = 1\n while (ones * 10 + 1 < n) {\n ones = ones * 10 + 1\n ++cnt\n }\n val cand1 = rec(n % ones) + cnt * (n / ones).toInt()\n ones = ones * 10 + 1\n ++cnt\n if (ones - n < n) {\n return minOf(rec(ones - n) + cnt, cand1)\n }\n return cand1\n}\nfun main() {\n val n = readLine()!!.toLong()\n println(rec(n))\n}"}, {"source_code": "import kotlin.math.min\n \nfun f(n: Long, a: Long, l: Int): Long {\n if (a == 0L) return if (n == 0L) 0L else Long.MAX_VALUE / 2\n val q = n / a\n return min(f(n - q * a, a / 10, l - 1) + l * q, f((q + 1) * a - n, a / 10, l - 1) + l * (q + 1))\n}\n \nfun main() = println(f(readLine()!!.toLong(), 1111_1111_1111_1111L, 16))"}, {"source_code": "import java.util.*\n \n var a = arrayOf(0L, 1L, 11L, 111L, 1111L, 11111L, 111111L, 1111111L, 11111111L, 111111111L, 1111111111L, 11111111111L, 111111111111L, \n 1111111111111L, 11111111111111L, 111111111111111L,1111111111111111L)\n fun ans(n: Long): Long\n {\n if (n == 0L)\n return 0L;\n var k = 1\n while (k < 17)\n {\n if (a[k] <= n && n <= a[k + 1])\n {\n var x = k * (n / a[k]) + ans(n - a[k] * (n / a[k]))\n var y = k + 1 + (a[k + 1] - n) / a[k] * k + ans(a[k + 1] - n - (a[k + 1] - n) / a[k] * a[k])\n return if (x < y) x else y\n }\n ++k;\n }\n return 10000000000\n }\n \n fun main()\n {\n var n = readLine()!!.toLong()\n print(ans(n))\n }\n"}, {"source_code": "import java.util.*\n\nval maxn = 200010\n\nfun next() = readLine()!!\nfun nextInt() = next().toInt()\nfun nextInts() = next().split(\" \").map { it.toInt() }\nfun nextLongs() = next().split(\" \").map { it.toLong() }\n\nval v = ArrayList()\nvar mk : MutableMap = mutableMapOf()\n\nfun init(){\n var t : Long = 0\n for(i in 1..17){\n t *= 10\n t++\n v.add(t)\n }\n}\n\nfun solve(x : Long) : Long{\n\n if(x == 0.toLong())return 0\n\n if(mk[x] != null){\n return mk[x]!!\n }\n\n var pos : Int = -1\n var ans : Long = x\n for(i in 0..16){\n if(v[i] > x){\n break\n }\n pos = i\n }\n\n ans = minOf(ans,solve(x-v[pos]) + pos + 1)\n\n if((v[pos+1] - x) < (x-v[pos])){\n ans = minOf(ans,solve(v[pos+1]-x) + pos + 2)\n }\n mk[x] = ans\n return ans\n}\nfun main(argumento: Array){\n\n init()\n\n var n = readLine()!!.toLong()\n\n println(solve(n))\n\n}\n\n"}, {"source_code": "import java.io.PrintWriter\nimport java.lang.Math.abs\nimport java.lang.Math.min\n\nval pw = PrintWriter(System.out)\nfun main(args: Array) {\n var INF = 1000000000000000L\n var n = nextLong()\n var vs = mutableListOf(1L)\n repeat(16){\n vs.add(vs.get(it)*10+1)\n }\n var dp = mapOf(Pair(n,0L))\n var re = n;\n for(i in 16 downTo 0){\n// dp.forEach { t, u -> print(\"${t} ${u}\\n\")}\n// println(\"\")\n var nxt = mutableMapOf()\n var upd = { key:Long, value:Long ->\n var cur = nxt.getOrDefault(key, INF)\n nxt.put(key, min(cur, value))\n }\n dp.forEach { n_, c ->\n var n = abs(n_)\n if(n==0L){\n re= min(re, c)\n return@forEach\n }\n var t=n/vs[i]\n upd(n-t*vs[i], c+(i+1)*t)\n upd((t+1)*vs[i]-n, c+(i+1)*(t+1))\n }\n dp=nxt\n }\n print(min(re, dp.getOrDefault(0, INF)))\n pw.flush()\n}\n\nfun next() = readLine()!!\nfun nextInt() = next().toInt()\nfun nextLong() = next().toLong()\nfun nextDouble() = next().toDouble()\nfun listOfString() = next().split(\" \")\nfun listOfInt() = listOfString().map { it.toInt() }\nfun listOfLong() = listOfString().map { it.toLong() }\nfun listOfDouble() = listOfString().map { it.toDouble() }\n"}, {"source_code": "import java.util.*\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readLong() = readInt().toLong()\nprivate fun readInts() = readStrings().map { it.toInt() }\nprivate fun readLongs() = readStrings().map { it.toLong() }\n\ninternal var list = ArrayList()\ninternal var map = HashMap()\ninternal var oo = 100000000000000000L\n\nfun main(args : Array) {\n val s = Scanner(System.`in`)\n var cur = \"1\"\n while(cur.length < 18) {\n list.add(cur.toLong())\n cur += \"1\"\n }\n var n = s.nextLong()\n var res = solve(n)\n println(res)\n}\n\ninternal fun solve(n: Long): Long {\n if(map.containsKey(n)) return map[n]!!.toLong()\n if(n == 0L) return 0L\n var largest = 1L\n var mult = 1L\n for(i in 0..list.size-1) {\n if(list[i] <= n) {\n largest = list[i].toLong()\n mult = (i+1).toLong()\n }\n }\n var res1 = n/largest * mult\n //println(res1)\n var left1 = n % largest\n res1 += solve(left1)\n\n var res2 = (n/largest+1) * mult\n var left2 = n - ((n/largest+1)*largest)\n //println(\" \" + n.toString() + \" , \" + (-left2).toString())\n if(-left2 < n) {\n res2 += solve(-left2)\n }\n else {\n res2 = oo\n }\n\n largest = 10*largest + 1\n var res3 = mult+1\n var left3 = largest-n\n if(left3 < n) {\n res3 += solve(left3);\n }\n else {\n res3 = oo\n }\n\n //println(res1.toString() + \" \" + res2)\n\n map[n] = minOf(res1, minOf(res3, res2))\n //println(n.toString() + \" \" + map[n]!!.toString())\n return map[n]!!.toLong()\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun GetGraph(n: Int): Array> {\n return Array(n) { ArrayList() }\n}\n\nvar min = 9999999999L\n\nfun solve() {\n var n = readLongs()[0]\n var arr = ArrayList()\n var p = 0\n while (n > 0) {\n arr.add((n % 10).toInt())\n n /= 10\n p++\n }\n arr.add(0)\n dfs(arr, p, 0L, 0, 0)\n println(min)\n}\n\nfun dfs(arr: ArrayList, p: Int, n: Long, under: Int, cost: Long) {\n if (cost >= min) return\n if (p == -1) {\n if (n == 0L) {\n min = cost\n }\n return\n }\n var nxt = n * 10 + arr[p] + under\n for (i in -22..22) {\n if (nxt + i <= -50L || nxt + i >= 50L) continue\n dfs(arr, p - 1, nxt + i, under + i, cost + Math.abs(i) * (p + 1))\n }\n}\n\nvar reader = BufferedReader(InputStreamReader(System.`in`))\nvar writer = PrintWriter(System.out)\n\nfun readInt() = reader.readLine()!!.toInt()\nfun readStrings() = reader.readLine()!!.split(\" \")\nfun readInts() = readStrings().map { it.toInt() }\nfun readLongs() = readStrings().map { it.toLong() }\nfun main() {\n solve()\n writer.close()\n}\n"}, {"source_code": "import kotlin.math.min\n\nfun f(n: Long, s: Long, l: Int): Long {\n if (s == 0L) return if (n == 0L) 0L else Long.MAX_VALUE / 2\n val q = n / s\n return min(f(n - q * s, s / 10, l - 1) + l * q, f((q + 1) * s - n, s / 10, l - 1) + l * (q + 1))\n}\n\nfun main() = println(f(readLine()!!.toLong(), 1111_1111_1111_1111L, 16))\n"}, {"source_code": "fun f(n: Long, s: Long, l: Int): Long {\n if (n < 0) return f(-n, s, l)\n if (n == 0L) return 0L\n if (s == 0L) return n\n val q = n / s\n return Math.min(f(n - q * s, s / 10, l - 1) + l * q, f(n - (q + 1) * s, s / 10, l - 1) + l * (q + 1))\n}\n\nfun main() {\n val n = readLine()!!.toLong()\n var s = 0L\n val limit = 16\n repeat(limit) {\n s = 10 * s + 1\n }\n println(f(n, s, limit))\n}"}, {"source_code": "fun f(n: Long, s: Long, l: Int): Long {\n if (n == 0L) return 0L\n if (s == 0L) return Long.MAX_VALUE / 2\n val q = n / s\n return Math.min(f(n - q * s, s / 10, l - 1) + l * q, f((q + 1) * s - n, s / 10, l - 1) + l * (q + 1))\n}\n\nfun main() {\n val n = readLine()!!.toLong()\n println(f(n, 1111_1111_1111_1111L, 16))\n}"}, {"source_code": "import kotlin.math.min\n\nval addends = listOf(\n 0,\n 1L,\n 11L,\n 111L,\n 1_111L,\n 11_111L,\n 111_111L,\n 1_111_111L,\n 11_111_111L,\n 111_111_111L,\n 1_111_111_111L,\n 11_111_111_111L,\n 111_111_111_111L,\n 1_111_111_111_111L,\n 11_111_111_111_111L,\n 111_111_111_111_111L,\n 1_111_111_111_111_111L\n)\n\nfun main() {\n val number = readLine()!!.toLong()\n println(findMinimumDigits(number))\n}\n\nfun findMinimumDigits(number: Long): Int {\n if (number <= 11) return min(number, 13 - number).toInt()\n var i = addends.size - 1\n while (addends[i] >= number) i--\n\n if (i + 1 < addends.size && number == addends[i + 1]) return i + 1\n\n val addendA = addends[i]\n val timesA = number / addendA\n val remainderA = number % addendA\n\n val numberOfDigitsA = if (timesA < 10) (i * timesA + findMinimumDigits(remainderA)).toInt() else Int.MAX_VALUE\n if (i + 1 == addends.size) return numberOfDigitsA\n\n val addendB = if (timesA >= 9L) addends[i + 1] else addends[i]\n val timesB = if (timesA >= 9L) 1L else timesA + 1\n val remainderB = addendB * timesB - number\n\n val numberOfDigitsB = (addendB.toString().length * timesB + findMinimumDigits(remainderB)).toInt()\n\n val numberOfDigitsC = if (timesA >= 9L) {\n Int.MAX_VALUE\n } else {\n val addendC = addends[i + 1]\n val timesC = 1\n val remainderC = addendC * timesC - number\n if (remainderC > number) Int.MAX_VALUE else (i + 1) * timesC + findMinimumDigits(remainderC)\n }\n\n return min(min(numberOfDigitsA, numberOfDigitsB), numberOfDigitsC)\n}\n"}, {"source_code": "import java.lang.Long.min\n\nfun main() {\n val n = readLine()!!.toLong()\n val map = mutableMapOf()\n println(minUnits(n, map))\n}\n\nfun units(len: Long): Long {\n var x = 1L\n for (i in 1 until len) {\n x = x * 10 + 1\n }\n return x\n}\n\nfun minUnits(n: Long, map: MutableMap): Long {\n val x = map[n]\n if (x != null) return x\n val l = n.toString().length.toLong()\n val u = units(l)\n if (n == u) {\n map[n] = l\n return l\n }\n if (n < u) {\n val v = l + minUnits(u - n, map)\n map[n] = v\n return v\n } else {\n val v1 = l + minUnits(n - u, map)\n val n2 = units(l + 1) - n\n return if (n2 > n) {\n map[n] = v1\n v1\n } else {\n val v2 = l + 1 + minUnits(n2, map)\n val v = min(v1, v2);\n map[n] = v\n v\n }\n }\n}"}, {"source_code": "import java.lang.StringBuilder\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.*\n\nprivate fun readLn(): String = readLine()!!\nprivate fun readInt(): Int = readLn().toInt()\nprivate fun readLong(): Long = readLn().toLong()\nprivate fun readDouble(): Double = readLn().toDouble()\n\nprivate fun readStrings(): List = readLn().split(\" \")\nprivate fun readInts(): List = readStrings().map { it.toInt() }\nprivate fun readLongs(): List = readStrings().map { it.toLong() }\nprivate fun readDoubles(): List = readStrings().map { it.toDouble() }\n\nprivate const val INF: Int = 1_000_000_017\nprivate const val LLINF: Long = 1_000_000_000_000_000_017L\nprivate const val MOD: Int = 1_000_000_007\n\nprivate class TaskF {\n val nums = Array(17) { 0L }\n\n fun gen(x: Long, y: Int) : Long {\n if (y == 0) {\n return 0\n }\n var cur = 0L\n var st = 0\n while (cur + nums[y] <= x) {\n cur += nums[y]\n ++st\n }\n return min(st * y + gen(x - cur, y - 1), (st + 1) * y + gen(cur + nums[y] - x, y - 1))\n }\n\n fun solve() {\n nums[1] = 1L\n for (i in 2 until 17) {\n nums[i] = nums[i - 1] * 10L + 1L\n }\n\n val x = readLong()\n println(gen(x, 16))\n }\n}\n\nfun main() {\n val t = TaskF()\n t.solve()\n}"}, {"source_code": "import kotlin.math.absoluteValue\n\nfun main(){\n var n : Long = readLine()!!.toLong()\n var res: Long = 0;\n\n res = calculate(16, n)\n\n println(res)\n}\n\nfun calculate(x: Int, n: Long) : Long{\n var sum : Long = 0\n var divisionNumber : Long = 1\n var div: Long = 0\n if (x != 1) {\n for (i in 1 until x) {\n divisionNumber = divisionNumber * 10 + 1\n }\n div = n/divisionNumber\n sum = if(div == 0.toLong() && n/(divisionNumber/10) == 0.toLong()) {\n 0 + calculate(x-1, n)\n }else {\n var posSum: Long = calculate(x - 1, n - (div * divisionNumber))\n var negSum: Long = calculate(x - 1, (n - ((div + 1) * divisionNumber)).absoluteValue)\n if (posSum <= negSum + x) {\n (div) * (x) + posSum\n } else {\n (div + 1) * (x) + negSum\n }\n }\n }else{\n sum = n.absoluteValue\n }\n return sum\n}"}, {"source_code": "import java.util.*\n\nprivate fun readLn(): String = readLine()!!\nprivate fun readInt(): Int = readLn().toInt()\nprivate fun readLong(): Long = readLn().toLong()\nprivate fun readStrings(): List = readLn().split(\" \")\nprivate fun readInts(): List = readStrings().map {it.toInt()}\nprivate fun readLongs(): List = readStrings().map {it.toLong()}\nprivate fun , S: Comparable> pairComparator() = \n compareBy(Pair::first, Pair::second)\nprivate fun , S: Comparable, T: Comparable> tripleComparator() = \n compareBy(Triple::first, Triple::second, Triple::third)\n\n\nfun repUnit(numOnes: Int): Long {\n return (Math.pow(10.0, numOnes.toDouble()).toLong() - 1) / 9;\n}\n\nvar n: Long = 0\n\nfun go(cur: Long, ones: Int): Long {\n if (ones == 0 || cur == n) {\n return 0\n } else if (ones == 1) {\n return Math.abs(n - cur)\n } else {\n val power = repUnit(ones)\n val diff: Long = Math.abs(n - cur)\n val sgn = if (n - cur < 0) -1 else 1\n val hi_mult = (power + diff - 1) / power\n val lo_mult = hi_mult - 1\n return Math.min(\n go(cur + sgn * lo_mult * power, ones - 1) + lo_mult * ones,\n go(cur + sgn * hi_mult * power, ones - 1) + hi_mult * ones\n )\n }\n}\n\nfun main(args: Array) {\n n = readLong()\n var p = 1\n while (repUnit(p + 1) <= n) {\n p++\n }\n var power = repUnit(p)\n var ans = go((n / power) * power, p - 1) + p * (n / power)\n ans = Math.min(ans, go((n / power + 1) * power, p - 1) + p * (n / power + 1))\n power = repUnit(p + 1)\n ans = Math.min(ans, go(power, p) + p + 1)\n println(ans)\n}"}, {"source_code": "import java.util.*\nimport java.math.*\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readInts() = readLn().split(\" \").map{it.toInt()}\n\nvar pw = LongArray(17)\nvar ones = LongArray(17)\n\nfun solve(m:Long, pos:Int): Int {\n\tif(m==0L) return 0\n\tif(pos==0) return 0\n\t\n\tval m1 = ones[pos+1]-m\n\treturn minOf(solve(m%ones[pos], pos-1)+m/ones[pos]*pos,\n\t\tsolve(m1%ones[pos], pos-1)+m1/ones[pos]*pos+pos+1).toInt()\n}\n\nfun main(args: Array) {\n\tpw[0]=1\n\tones[0]=0\n\tfor(i in 1..16) {\n\t\tpw[i] = pw[i-1]*10\n\t\tones[i] = ones[i-1]+pw[i-1]\n\t}\n\t\n\tvar m = readLn().toLong()\n\tprintln(solve(m,15))\n}"}, {"source_code": "import java.lang.Math.abs\n \nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n \nfun main(args: Array) {\n var s = readLn().reversed() + \"000\"\n var len = s.length\n val MAX = 200\n var dp = Array(len + 1, { Array(2 * MAX, { IntArray(2 * MAX, { 12345 }) }) })\n dp[0][MAX][MAX] = 0\n for (i in 0..len - 1) {\n for (cur in -MAX..MAX-1) {\n for (carry in -MAX..MAX-1) {\n var ft = dp[i][cur + MAX][carry + MAX]\n if (ft == 12345) {\n continue\n }\n for (delta in -100..100) {\n var newCur = cur + delta\n var here = newCur + carry\n var value = (here % 10 + 10) % 10\n if (value != s[i] - '0') {\n continue\n }\n var newCarry = (here - value) / 10\n var newFt = ft + abs(delta) * i\n if (newCur >= -MAX && newCur < MAX && newCarry >= -MAX && newCarry < MAX && newFt < dp[i + 1][newCur + MAX][newCarry + MAX]) {\n dp[i + 1][newCur + MAX][newCarry + MAX] = newFt\n }\n }\n }\n }\n }\n println(dp[len][MAX][MAX])\n}"}, {"source_code": "var ans = (1e18).toLong()\nvar dig = Array(18) {0L}\nfun solve(num : Long, pos : Int, tans : Long){\n if(pos == 0){\n if(num == 0L){\n ans = minOf(ans, tans)\n }\n return\n }\n var low = num / dig[pos]\n var high = (num + dig[pos] - 1) / dig[pos]\n solve(num - low * dig[pos], pos - 1, tans + low * pos)\n solve(high * dig[pos] - num, pos - 1, tans + high * pos)\n}\nfun main(args: Array) {\n var n = readLine()!!.toLong()\n for(i in 1..17){\n dig[i] = dig[i - 1] * 10L + 1L\n }\n solve(n, 17, 0)\n print(ans)\n}\n"}, {"source_code": "import java.util.*;\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n\tvar n = nextLong()\n\tvar ans = n;\n\tvar q = LinkedList();\n\tvar hm = HashMap();\n\tq.add(0L);\n\tq.add(0L);\n\twhile (!q.isEmpty()) {\n\t\tvar curVal = q.pop();\n\t\tvar curSteps = q.pop();\n\t\tif (hm.containsKey(curVal)) {\n\t\t\tvar x = hm.get(curVal) as Long;\n\t\t\tif (x <= curSteps) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\thm.put(curVal, curSteps);\n\t\tif (curVal < n) {\n\t\t\tvar add = 1L;\n\t\t\tvar sum = 1L;\n\t\t\twhile (curVal + add * 10 + 1 <= n) {\n\t\t\t\tadd = add * 10 + 1;\n\t\t\t\tsum++;\n\t\t\t}\n\t\t\tq.add(curVal + add);\n\t\t\tq.add(curSteps + sum);\n\t\t\tq.add(curVal + add * 10 + 1);\n\t\t\tq.add(curSteps + sum + 1);\n\t\t}\n\t\telse if (curVal > n) {\n\t\t\tvar sub = 1L;\n\t\t\tvar sum = 1L;\n\t\t\twhile (curVal - (sub * 10 + 1) >= n) {\n\t\t\t\tsub = sub * 10 + 1;\n\t\t\t\tsum++;\n\t\t\t}\n\t\t\tq.add(curVal - sub);\n\t\t\tq.add(curSteps + sum);\n\t\t\tq.add(curVal - (sub * 10 + 1));\n\t\t\tq.add(curSteps + sum + 1);\n\t\t}\n\t}\n\tif (hm.containsKey(n)) {\n\t\tans = Math.min(ans, hm.get(n) as Long);\n\t}\n\tprint(ans);\n\tprintln();\n}"}, {"source_code": "import kotlin.math.absoluteValue\nimport kotlin.math.sign\n\nfun Long.toOneBasedArithmetic(): String {\n\n fun findAddends(n: Long, forbidden: Int? = null): List {\n val addends = mutableListOf()\n val digits = n.toString().length\n val base = ones(digits)\n if (base == n)\n return listOf(digits)\n val ms = if (base > n) digits - 1 else digits\n val m = ones(ms)\n val bs = ms + 1\n val b = ones(bs)\n val fits = n % m == 0L\n if (fits) {\n val count = n / m\n val a = count * ms\n if (bs == forbidden) {\n repeat(count.toInt()) { addends += ms }\n } else {\n val remaining = findAddends(b - n, bs)\n val b = bs + remaining.sumBy { it.absoluteValue }\n if (a < b) {\n repeat(count.toInt()) { addends += ms }\n } else {\n addends += bs\n addends += remaining.map { -it }\n }\n }\n return addends\n }\n\n val options = mutableListOf>()\n // stay below, add enough\n val below = n / m\n val remaining = n - below * m\n val x = mutableListOf()\n repeat(below.toInt()) { x += ms }\n x += findAddends(remaining, ms)\n options += x.toList()\n\n // above\n val above = below + 1\n val toomuch = -n + above * m\n x.clear()\n repeat(above.toInt()) { x += ms }\n x += findAddends(toomuch, ms).map { -it }\n options += x.toList()\n\n // above with next larger step\n if (forbidden != bs) {\n val waytoomuch = -n + b\n x.clear()\n x += bs\n x += findAddends(waytoomuch, bs).map { -it }\n options += x.toList()\n }\n return options.minBy { it.sumBy { it.absoluteValue } }!!\n }\n\n val addends = findAddends(this)\n\n return addends.map {\n it.sign * ones(it)\n }.joinToString(separator = \"+\")\n}\n\nfun ones(n: Int) = \"1\".repeat(n.absoluteValue).toLong()\n\nval String.countOnes\n get() = count { it == '1' }\n\nfun main() {\n /* (1..1_000_000_000_000_000).forEach { i ->\n val toOneBasedArithmetic = i.toOneBasedArithmetic()\n println(\"$i => (${toOneBasedArithmetic.countOnes}) $toOneBasedArithmetic\")\n }*/\n val n = readLine()!!.toLong()\n println(n.toOneBasedArithmetic().countOnes)\n}"}, {"source_code": "import kotlin.math.min\n\nfun Long.digitsCount() = toString().length\n\nfun Long.repeat(n: Int) = toString().repeat(n).toLong()\n\n\nfun main() {\n val n = readLine()!!.toLong()\n val digits = n.digitsCount()\n print(dfs(n, digits+1))\n}\n\nfun dfs(dividend: Long, i: Int): Long {\n val divisor = 1L.repeat(i)\n val quo = dividend/divisor\n val rem = dividend%divisor\n if (rem == 0L) return quo*i\n return quo*i + min(dfs(rem, i-1), i + dfs(divisor - rem, i-1))\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\nimport javax.xml.stream.events.Characters\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\nimport kotlin.collections.HashSet\n\nvar a = LongArray(20);\n\nfun dfs(n : Long, t : Long): Long {\n var m = n;\n var k = t;\n var num : Long = n / a[t.toInt()];\n m %= a[t.toInt()];\n if (m == 0L){\n return num * t;\n }\n return num * t + Math.min(t + dfs(a[t.toInt()] - m, k - 1), dfs (m, t - 1));\n}\n\nfun main(args: Array) {\n\n val cin = FastReader(System.`in`);\n val out = PrintWriter(BufferedOutputStream(System.out));\n\n var n : Long = cin.nextLong();\n\n for (i in 1 until 17){\n a[i] = a[i - 1] * 10 + 1;\n }\n out.print(dfs(n, 16L));\n// var arr = p.sortedWith(compareBy({it.first}, {it.second}));\n\n\n out.close()\n}\n\n\nprivate class FastReader(input: InputStream) {\n private val br = BufferedReader(InputStreamReader(input))\n private var st = StringTokenizer(\"\")\n\n fun next(): String {\n while (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt(): Int {\n return next().toInt()\n }\n\n fun nextDouble(): Double {\n return next().toDouble()\n }\n\n fun nextLong(): Long {\n return next().toLong()\n }\n\n /**\n * Warning! Use carefully!\n */\n fun nextLine(): String {\n return br.readLine()\n }\n}"}, {"source_code": "import java.util.*\n \nfun main() {\n val sc = Scanner(System.`in`)\n val n = sc.nextLong()\n val Z = LongArray(20)\n Z[1] = 1\n for (i in 2 until Z.size) {\n Z[i] = Z[i - 1] * 10 + 1\n }\n var res = Long.MAX_VALUE\n for (len in 1..17) {\n for (m in 0..(1 shl len)) {\n var cur = 0L\n var cnt = 0L\n for (i in len downTo 1) {\n val overflow = (m and (1 shl i)) != 0\n if (cur < n) {\n val am = (n - cur) / Z[i]\n cur += Z[i] * am\n cnt += i * am\n if (overflow && cur < n) {\n cur += Z[i]\n cnt += i\n }\n } else if (cur > n) {\n val am = (cur - n) / Z[i]\n cur -= Z[i] * am\n cnt += i * am\n if (overflow && cur > n) {\n cur -= Z[i]\n cnt += i\n }\n }\n }\n if (cur == n)\n res = minOf(res, cnt)\n }\n }\n println(res)\n}"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n \nfun main() {\n val n0 = readLong()\n \n val M = LongArray(17)\n for(i in 1 until M.size) M[i] = M[i-1] * 10 + 1\n \n var D = hashMapOf(n0 to 0)\n \n for(k in M.size-2 downTo 1) {\n if(M[k] > n0) continue\n \n val Dk = HashMap()\n \n for((n, c) in D) {\n Dk.checkMin(n % M[k], c + (n / M[k] * k).toInt())\n val n1 = M[k+1] - n\n Dk.checkMin(n1 % M[k], c + k + 1 + (n1 / M[k] * k).toInt())\n }\n \n D = Dk\n }\n \n val ans = D[0]\n \n println(ans)\n}\n \nfun HashMap.checkMin(k: K, v: Int) { if(!containsKey(k) || v < get(k)!!) put(k, v) }\n \n\n@JvmField val _reader = System.`in`.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\n \n@JvmField val _writer = PrintWriter(System.out, false)\ninline fun output(block: PrintWriter.()->Unit) { _writer.apply(block).flush() }\nfun iprintln(o: Any?) { println(o) }"}, {"source_code": "import java.util.*\n \nfun main() {\n val sc = Scanner(System.`in`)\n val n = sc.nextLong()\n val Z = LongArray(20)\n Z[1] = 1\n for (i in 2 until Z.size) {\n Z[i] = Z[i - 1] * 10 + 1\n }\n var res = Long.MAX_VALUE\n for (len in 1..17) {\n for (m in 0..(1 shl len)) {\n var cur = 0L\n var cnt = 0L\n for (i in len downTo 1) {\n val overflow = (m and (1 shl i)) != 0\n if (cur < n) {\n val am = (n - cur) / Z[i]\n cur += Z[i] * am\n cnt += i * am\n if (overflow && cur < n) {\n cur += Z[i]\n cnt += i\n }\n } else if (cur > n) {\n val am = (cur - n) / Z[i]\n cur -= Z[i] * am\n cnt += i * am\n if (overflow && cur > n) {\n cur -= Z[i]\n cnt += i\n }\n }\n }\n if (cur == n)\n res = minOf(res, cnt)\n }\n }\n println(res)\n}"}, {"source_code": "import java.util.*\n \nfun main() {\n val sc = Scanner(System.`in`)\n val n = sc.nextLong()\n val Z = LongArray(20)\n Z[1] = 1\n for (i in 2 until Z.size) {\n Z[i] = Z[i - 1] * 10 + 1\n }\n var res = Long.MAX_VALUE\n for (len in 1..17) {\n for (m in 0..(1 shl len)) {\n var cur = 0L\n var cnt = 0L\n for (i in len downTo 1) {\n val overflow = (m and (1 shl i)) != 0\n if (cur < n) {\n val am = (n - cur) / Z[i]\n cur += Z[i] * am\n cnt += i * am\n if (overflow && cur < n) {\n cur += Z[i]\n cnt += i\n }\n } else if (cur > n) {\n val am = (cur - n) / Z[i]\n cur -= Z[i] * am\n cnt += i * am\n if (overflow && cur > n) {\n cur -= Z[i]\n cnt += i\n }\n }\n }\n if (cur == n)\n res = minOf(res, cnt)\n }\n }\n println(res)\n}"}, {"source_code": "fun answer(n: Long, position: Int, ones: Array): Long {\n var local_n: Long = n\n var lower_bound: Long = local_n / ones[position]\n local_n %= ones[position]\n if (local_n == 0L) {\n return lower_bound * position;\n }\n return lower_bound * position + \n minOf(position + answer(ones[position] - local_n, position - 1, ones),\n answer(local_n, position - 1, ones));\n}\n\nfun main() {\n var n: Long = readLine()!!.toLong()\n var ones: Array = arrayOf(0L, 1L, 11L, 111L, 1111L, 11111L, 111111L, 1111111L, 11111111L, 111111111L, \n 1111111111L, 11111111111L, 111111111111L, 1111111111111L, 11111111111111L, 111111111111111L, \n 1111111111111111L, 11111111111111111L, 111111111111111111L, 1111111111111111111L)\n println(\"${answer(n, 19, ones)}\")\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val n = scan.nextLong()\n ones[0] = 0\n for (i in 1..16) {\n ones[i] = ones[i - 1] * 10 + 1\n }\n println(result(n, 16))\n}\n\nvar ones = LongArray(17)\nfun result(n1: Long, i: Int): Long {\n var n = n1\n val k = (n / ones[i]).toInt()\n n %= ones[i]\n val count = (k * i).toLong()\n return if (n == 0L)\n count\n else\n count + min(i + result(ones[i] - n, i - 1), result(n, i - 1))\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.*\nimport kotlin.math.*\n\nfun findMv(v: Long): Pair {\n var bs = 1L\n var cnt = 1\n while (10*bs < v) {\n bs = 10*bs + 1\n cnt++\n }\n return Pair(bs, cnt)\n}\n\nfun solve() {\n val n = kin.long()\n val q = PriorityQueue>(compareBy{it.first})\n val dst = HashMap()\n var ans = -1\n fun tryAdd(v: Long, cnt: Int) {\n if (!dst.containsKey(v) || dst.getValue(v) > cnt) {\n dst[v] = cnt\n q.add(Pair(cnt, v))\n if (v == 0L) {\n ans = cnt\n }\n }\n }\n tryAdd(n, 0)\n while (ans == -1) {\n val cur = q.poll()\n val v = cur.second\n val cnt = cur.first\n if (dst.getValue(v) != cur.first) {\n continue\n }\n val mv = findMv(v)\n tryAdd(v - mv.first, cnt + mv.second)\n tryAdd(10*mv.first+1-v, cnt + mv.second+1)\n }\n kout.println(ans)\n}\n\nvar kin = InputReader(getInput())\nval kout = PrintWriter(System.out)\n\nfun main() {\n kout.use { solve() }\n}\n\nclass InputReader(stream: InputStream) {\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n fun str(): String {\n while (tokenizer?.hasMoreTokens() != true) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n fun list(n: Int, parse: (String) -> R): List {\n return (1..n).map { parse.invoke(str()) }\n }\n\n fun int() = str().toInt()\n fun listInt(n: Int) = list(n) { it.toInt() }\n fun long() = str().toLong()\n fun listLong(n: Int) = list(n) { it.toLong() }\n}\n\nfun getInput(): InputStream {\n val inputFile = try {\n System.getProperty(\"compet.input\")\n } catch (ex: Exception) {\n null\n } ?: return System.`in`\n\n return FileInputStream({}::class.java.classLoader.getResource(inputFile).file)\n}\n\n"}, {"source_code": "import kotlin.math.min\nimport kotlin.math.pow\n\nfun a(n: Int): Long {\n return ((10.toDouble().pow(n) - 1) / 9).toLong()\n}\n\nfun solve(n: Long): Long {\n if (n <= 6) return n.toLong()\n if (n <= 11) return 13 - n.toLong()\n var level = 1\n while (a(level) < n) level ++\n level --\n val p1 = a(level)\n val p2 = a(level + 1)\n var res1 = n / p1 * level.toLong()\n res1 += solve(n % p1)\n var res2 = (level + 1).toLong()\n var x = p2 - n\n res2 += x / p1 * level.toLong()\n res2 += solve(x % p1)\n return min(res1, res2)\n}\n\nfun main(){\n val n = readLine()!!.toLong()\n println(solve(n))\n}"}, {"source_code": "import kotlin.math.*\nvar ones = LongArray(18, { 0L })\nfun main() {\n \n\n for (i in 1..17)\n {\n ones[i] = ones[i - 1] * 10 + 1\n }\n var n = readLine()!!.toLong()\n println(dfs(n, 16))\n\n}\n\nfun dfs(n:Long, i:Int):Long\n{\n var n1 = n\n var k = n1 / ones[i]\n n1 %= ones[i]\n if(n1 == 0L)\n {\n return k * i\n }\n else\n {\n return k*i+min(i+dfs(ones[i]-n1, i-1), dfs(n1, i-1))\n }\n\n}\n\n\n\n\n\n\n"}, {"source_code": "import java.util.*\n\ninternal var ones = LongArray(17)\ninternal fun dfs(n: Long, i: Int): Long {\n var n = n\n val k = (n / ones[i]).toInt()\n n %= ones[i]\n val count = (k * i).toLong()\n return if (n == 0L)\n count\n else\n count + Math.min(i + dfs(ones[i] - n, i - 1), dfs(n, i - 1))\n}\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val n = scan.nextLong()\n ones[0] = 0\n for (i in 1..16) {\n ones[i] = ones[i - 1] * 10 + 1\n }\n println(dfs(n, 16))\n}\n"}, {"source_code": "import kotlin.math.min\n\nvar memo = mutableListOf()\nfun calculate(number: Long): Long {\n val res: Long\n var i = 18\n if (number <= 11) return min(number, 2 + 11 - number)\n\n while (memo[i - 1] >= number) i--\n\n res = ((number / memo[i - 1]) * (i - 1)) + calculate(number % memo[i - 1])\n if (number < memo[i] - number) return res\n return min(res, i + calculate(memo[i] - number))\n}\n\nfun main(args: Array) {\n val n = readLine()!!.toLong()\n memo.add(0)\n memo.add(1)\n for (i in 2 until 18) memo.add(10 * memo[i - 1] + 1)\n memo.add(0)\n memo.add(0)\n print(calculate(n))\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\nimport kotlin.math.min\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun getOnes(sz: Int) : Long {\n var r = 0L\n for (unused in 0 until sz) {\n r = r * 10 + 1\n }\n return r\n}\nclass State(val node: Long, val dist: Int): Comparable {\n override fun compareTo(other: State): Int {\n return dist.compareTo(other.dist)\n }\n\n}\nfun bfs(): IntArray {\n val queue = PriorityQueue()\n queue.add(State(0, 0))\n val D = IntArray(20000) { 1000000000 }\n D[0] = 0\n while (queue.isNotEmpty()) {\n val t = queue.poll()!!\n if (D[t.node.toInt()] < t.dist) continue\n for (s in intArrayOf(-1, 1)) {\n for (i in 1..6) {\n val ns = State(t.node + s * getOnes(i), t.dist + i)\n if (ns.node < D.size && ns.node >= 0 && D[ns.node.toInt()] > ns.dist) {\n D[ns.node.toInt()] = ns.dist\n queue.add(ns)\n }\n }\n }\n }\n return D\n}\n\nval ref = Array(18) { i -> getOnes(i) }\nfun BF(v: Long): Int {\n val queue = PriorityQueue()\n queue.add(State(v, 0))\n val D = HashMap()\n D[v] = 0\n while (queue.isNotEmpty()) {\n val t = queue.poll()!!\n if (D[t.node]!! < t.dist) continue\n if (t.node == 0L) return t.dist\n var states = ArrayList()\n for (i in 0 until ref.size) {\n if (ref[i] == t.node) {\n states.add(State(t.node - ref[i], t.dist + i))\n break\n } else if (ref[i] > t.node) {\n states.add(State(ref[i] - t.node, t.dist + i))\n states.add(State(t.node - ref[i-1], t.dist + i - 1))\n break\n }\n }\n for (ns in states) {\n if (D.getOrDefault(ns.node, 1000000000) > ns.dist) {\n D.compute(ns.node) { _, _ -> ns.dist }\n queue.add(ns)\n }\n }\n// for (s in intArrayOf(-1, 1)) {\n// for (i in 1..6) {\n// val ns = State(t.node + s * getOnes(i), t.dist + i)\n// if (ns.node >= 0 && D.getOrDefault(ns.node, 1000000000) > ns.dist) {\n// D.compute(ns.node) { _, _ -> ns.dist }\n// queue.add(ns)\n// }\n// }\n// }\n }\n return D[0]!!\n}\n\nfun main() {\n\n val N = readLong()\n println(BF(N))\n// println(BF(1763283723286323L))\n// for ((k, v) in bfs().withIndex().take(1000)) {\n// println(\"${k} ${v == BF(k.toLong())}\")\n// }\n\n}"}, {"source_code": "import kotlin.math.abs\nimport kotlin.math.min\n\nfun solve(num: Long): Int {\n if (num == 0L) {\n return 0\n }\n val len = num.toString().length\n val a = \"1\".repeat(len).toLong()\n val b = \"1\".repeat(len +1).toLong()\n val diffA = abs(a - num)\n val diffB = abs(b - num)\n return if (diffA > diffB) {\n min(\n solve(abs(num - a)) + a.toString().length,\n solve(abs(num - b)) + b.toString().length)\n } else {\n solve(abs(num - a)) + a.toString().length\n }\n\n}\n\nfun readNumsLine(): List {\n return readLine()!!.split(\"\\\\s\".toRegex()).map { it.toLong() }\n}\n\nfun main() {\n val (num) = readNumsLine()\n\n println(solve(num))\n}\n"}, {"source_code": "import java.util.*\n \nfun main() {\n val sc = Scanner(System.`in`)\n val n = sc.nextLong()\n val Z = LongArray(20)\n Z[1] = 1\n for (i in 2 until Z.size) {\n Z[i] = Z[i - 1] * 10 + 1\n }\n var res = Long.MAX_VALUE\n for (len in 1..17) {\n for (m in 0..(1 shl len)) {\n var cur = 0L\n var cnt = 0L\n for (i in len downTo 1) {\n val overflow = (m and (1 shl i)) != 0\n if (cur < n) {\n val am = (n - cur) / Z[i]\n cur += Z[i] * am\n cnt += i * am\n if (overflow && cur < n) {\n cur += Z[i]\n cnt += i\n }\n } else if (cur > n) {\n val am = (cur - n) / Z[i]\n cur -= Z[i] * am\n cnt += i * am\n if (overflow && cur > n) {\n cur -= Z[i]\n cnt += i\n }\n }\n }\n if (cur == n)\n res = minOf(res, cnt)\n }\n }\n println(res)\n}"}, {"source_code": "import kotlin.math.min\n \nfun main() {\n \n fun calculate(n: Long, s: Long, l: Long): Long {\n if (n < 0) return calculate(-n, s, l)\n if (n == 0L) return 0L\n if (s == 0L) return n\n val q = n / s\n return min(calculate(n - q * s, s / 10, l - 1) + l * q, calculate(n - (q + 1) * s, s / 10, l - 1) + l * (q + 1))\n }\n \n readLine()?.let {\n val n = it.toLong()\n println(calculate(n, 1111111111111111, 16))\n }\n}"}, {"source_code": "// kotlin tips b/c I'm bad\n\n/** useful links\n * https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html\n * https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-array-list/index.html\n * https://kotlinlang.org/docs/reference/ranges.html\n */\n\n/** valid ways to sort (don't use quicksort ...)\n * 1\n * val a = nextLongs().sorted() // a is mutable list\n * 2\n * val a = arrayListOf()\n * a.addAll(nextLongs())\n * a.sort()\n */\n\n/** declare 2D array\n * val ori = Array(n, {IntArray(n)})\n * val ori = arrayOf(\n intArrayOf(8, 9, 1, 13),\n intArrayOf(3, 12, 7, 5),\n intArrayOf(0, 2, 4, 11),\n intArrayOf(6, 10, 15, 14)\n )\n */\n\n/** printing variables:\n * println(\"${l+1} and $r\")\n * evidently print has high constant factor\n * print stringbuilder instead?\n */\n\n// ArrayList to Array: toArray\n\n// IntArray with size:\n// val arr = IntArray(1 shl 20, { 1 })\n\n// lower bound: use binary search\n// https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/binary-search.html\n\n// if/switch\n// https://kotlinlang.org/docs/reference/control-flow.html\n\n// swap:\n// https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/also.html\n// a = b.also { b = a }\n\n/** comparing pairs\n * val ed = ArrayList>>()\n ed.sortBy {it.first}\n * class CustomComparator : Comparator>> {\n override fun compare(o1: Pair>, o2: Pair>): Int {\n return o1.first.compareTo(o2.first)\n }\n }\n val v = ed.sortedWith(CustomComparator())\n *\n val v = ArrayList>()\n for (t in a) v.add(Pair(cat(t),t))\n val z = v.sortedWith(compareBy({ -it.first }, { it.second }))\n */\n\n/** hashmap\n * val h = HashMap()\n for (i in 0..n-2) {\n val w = s.substring(i,i+2)\n val c = h.getOrElse(w){0}\n h.put(w,c+1)\n }\n */\n\nimport java.util.*\n\nval MX = 1000005\nval MOD = 998244353\nval SZ = 1 shl 19\nval INF = (1e18).toLong()\n\nfun add(a: Int, b: Int) = (a + b) % MOD\nfun sub(a: Int, b: Int) = (a - b + MOD) % MOD\nfun mul(a: Int, b: Int) = ((a.toLong() * b) % MOD).toInt()\n\nfun next() = readLine()!!\nfun nextInt() = next().toInt()\nfun nextLong() = next().toLong()\nfun nextInts() = next().split(\" \").map { it.toInt() }\nfun nextLongs() = next().split(\" \").map { it.toLong() }\n\nfun ad(res: HashMap, key: Long, value: Long) {\n if (!(key in res)) res.put(key,1e18.toLong())\n res.put(key,minOf(res.get(key)!!,value))\n}\n\nfun adjust(cur: HashMap, len: Int) : HashMap {\n var prod: Long = 1\n for (t in 1..len) prod *= 10\n prod = (prod-1)/9\n\n val res = HashMap()\n for ((key,value) in cur) {\n assert(key >= 0)\n val quo = key/prod\n ad(res,key-quo*prod,value+quo*len)\n ad(res,(quo+1)*prod-key,value+(quo+1)*len)\n }\n return res\n}\n\nfun solve() {\n val n = nextLong()\n var cur = HashMap()\n cur.put(n,0)\n for (i in 16 downTo 1) {\n cur = adjust(cur,i)\n // println(prod)\n }\n print(cur.get(0))\n}\n\nfun main(args: Array) {\n val T = 1\n for (i in 1..T) solve()\n}"}, {"source_code": "import java.util.*\n\n\nvar long_array = LongArray(18)\nvar res:Long = 100000000000000000L\nfun func(n_now: Long, index: Int, total: Long) {\n if (index == 0) {\n if (res > total) res = total\n return\n }\n if (n_now >= 0) {\n func(n_now - n_now / long_array[index] * long_array[index], index - 1, total + n_now / long_array[index] * index)\n func(n_now - (n_now / long_array[index] + 1) * long_array[index], index - 1, total + (n_now / long_array[index] + 1) * index)\n } else {\n func(n_now + -n_now / long_array[index] * long_array[index], index - 1, total + -n_now / long_array[index] * index)\n func(n_now + (-n_now / long_array[index] + 1) * long_array[index], index - 1, total + (-n_now / long_array[index] + 1) * index)\n }\n}\n\nfun main(args: Array) {\n long_array[1] = 1\n for (i in 2..16)\n long_array[i] = long_array[i - 1] * 10 + 1\n val input = Scanner(System.`in`)\n var n = input.nextLong()\n func(n, 16, 0)\n System.out.print(res)\n input.close();\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.*\nimport kotlin.math.*\n\nprivate fun readLn() = readLine()!! // string\nprivate fun readInt() = readLn().toInt() // int\nprivate fun readStrings() = readLn().split(\" \") // string string\nprivate fun readInts() = readStrings().map { it.toInt() } // int int\n\n// tut\n\nvar a1 = Array(17){0L}\n\nfun dfs(n: Long, p: Int) : Long{\n var t = n / a1[p]\n return t * p + if (n%a1[p] != 0L) min(p + dfs(a1[p] - n%a1[p], p - 1), dfs(n%a1[p], p - 1)) else 0\n}\n\nfun main() {\n for (i in 1..16)\n a1[i] = a1[i - 1] * 10 + 1\n var n = readLn().toLong()\n System.out.print(dfs(n, 16))\n}\n"}, {"source_code": "import kotlin.math.abs\nimport kotlin.math.min\n\nfun sol(n: Long, index: Int, ones: MutableList) : Long {\n if(index == 0)\n return n\n\n val division = n / ones[index]\n val debug = division + 1\n\n return min(division * (index + 1) + sol(abs(n - division * ones[index]), index - 1, ones),\n debug * (index + 1) + sol(abs(n - debug * ones[index]), index - 1, ones))\n}\n\nfun main() {\n val n = readLine()!!.toLong()\n\n val ones = mutableListOf(1)\n for(i in 1 until 16)\n ones.add(ones[i-1] * 10 + 1)\n\n println(sol(n, 15, ones))\n\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of ints\n\nfun dfs(x : Long, d : Long, len : Int):Int {\n if (d==1L) return maxOf(x,-x).toInt()\n if (x==0L) return 0\n if (x>0) {\n var c=(x/d).toInt()\n var xx=x-c*d\n return minOf(dfs(xx,d/10,len-1)+c*len,dfs(xx-d,d/10,len-1)+(c+1)*len)\n } else {\n var c=((-x)/d).toInt()\n var xx=x+c*d\n return minOf(dfs(xx,d/10,len-1)+c*len,dfs(xx+d,d/10,len-1)+(c+1)*len)\n }\n}\n\nfun main() {\n var x=readLn().toLong()\n println(dfs(x,1111111111111111L,16));\n}"}, {"source_code": "\nimport java.lang.Math.min\nimport java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextLong()\n println(solve(n))\n}\n\nfun solve(x:Long):Int\n{\n if(x==0L)return 0\n var n=0\n var num=0L\n while(true)\n {\n if(num*10+1>x)break\n n+=1\n num*=10\n num+=1\n }\n var x2=x\n var tmp=0\n while(x2>=num)\n {\n x2-=num\n tmp+=n\n }\n var ans=solve(x2)+tmp\n x2=(num*10+1)-x\n tmp=n+1\n while(x2>=num)\n {\n x2-=num\n tmp+=n\n }\n ans=min(ans,solve(x2)+tmp)\n return ans\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.math.*\n\nprivate fun readString() = readLine()!! // string line\nprivate fun readInt() = readString().toInt() // single int\nprivate fun readLong() = readString().toLong()\nprivate fun readStrings() = readString().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of ints\n\nvar p = arrayOf()\nvar F = HashMap()\n\nfun solve(n: Long) : Long\n{\n if (n == 0L) return 0\n if (F.containsKey(n)) return F.get(n)!!\n \n var len = 0\n var x = n\n while (x > 0)\n {\n x /= 10\n len ++\n }\n \n var ret = n\n if (abs(n-p[len-1]) < n) ret = minOf(ret, len+solve(abs(n-p[len-1])))\n if (abs(n-p[len]) < n) ret = minOf(ret, len+1+solve(abs(n-p[len])))\n \n F.put(n, ret)\n return ret\n}\n\nfun main(args: Array)\n{\n var cur = 0L\n for (i in 0..16)\n {\n cur = cur*10+1\n p += cur\n }\n var n = readLong()\n var ret = solve(n)\n println(ret)\n}"}, {"source_code": "import kotlin.math.min\n\nprivate fun readInt() = readLine()!!.toInt()\nprivate fun readLong() = readLine()!!.toLong()\nprivate fun readIntList() = readLine()!!.split(\" \").map { it.toInt() }\nprivate fun readLongList() = readLine()!!.split(\" \").map { it.toLong() }\nprivate fun readString() = readLine()!!\n\nconst val maxl = 16\nconst val NEG = 1\nconst val ZERO = 0\nconst val POS = 2\n\nval mask = IntArray(maxl)\nvar bestAns = Long.MAX_VALUE\nval ONES = (0..maxl).map { createOnes(it) }\n\nfun createMask(pos: Int, initialN:Long, prevNonZeroId:Int = -1, initialAns:Long = 0) {\n if (pos == maxl) {\n if (initialN == 0L) {\n bestAns = min(bestAns, initialAns)\n }\n } else if (initialAns < bestAns) {\n val curTerm = ONES[maxl - pos]\n\n for (maskValue in 0..2) {\n var ok = true\n var curN = initialN\n var curAns = initialAns\n mask[pos] = maskValue\n\n var nextNonZeroId = prevNonZeroId\n\n when (mask[pos]) {\n POS -> {\n if (prevNonZeroId != -1 && curN < 0 && mask[prevNonZeroId] == NEG) {\n curN += ONES[maxl - prevNonZeroId]\n curAns += maxl - prevNonZeroId\n } else if (curN < 0) {\n ok = false\n }\n val toAdd = curN / curTerm\n curAns += (maxl - pos) * toAdd\n curN -= curTerm * toAdd\n nextNonZeroId = pos\n }\n NEG -> {\n if (prevNonZeroId != -1 && curN > 0 && mask[prevNonZeroId] == POS) {\n curN -= ONES[maxl - prevNonZeroId]\n curAns += maxl - prevNonZeroId\n } else if (curN > 0) {\n ok = false\n }\n val toAdd = curN / curTerm\n if (toAdd < 0) {\n curAns += (maxl - pos) * (-toAdd)\n curN += curTerm * (-toAdd)\n }\n nextNonZeroId = pos\n }\n }\n\n if (ok) {\n createMask(pos + 1, initialAns = curAns, initialN = curN, prevNonZeroId = nextNonZeroId)\n }\n }\n }\n}\n\nfun createOnes(n:Int): Long {\n var ans = 0L\n repeat(n) {\n ans = ans * 10 + 1\n }\n return ans\n}\n\nfun main() {\n val n = readLong()\n\n createMask(0, n)\n println(bestAns)\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport java.lang.Math.*\nimport kotlin.collections.ArrayList\n\nvar stok = StringTokenizer(\"\")\nvar br = BufferedReader(InputStreamReader(System.`in`))\n\nfun nextToken(): String? {\n while (!stok.hasMoreTokens()) {\n val s = br.readLine() ?: return null\n stok = StringTokenizer(s)\n }\n return stok.nextToken()\n}\n\nfun nextInt() = nextToken()!!.toInt()\nfun nextDouble() = nextToken()!!.toDouble()\nfun nextLong() = nextToken()!!.toLong()\n\nfun main(args: Array) {\n if (args.isNotEmpty()) br = BufferedReader(FileReader(\"input.txt\"))\n PrintWriter(System.out, false).use { it.solve() }\n}\n\nfun PrintWriter.solve() {\n var n = nextLong()\n val ps = LongArray(16)\n ps[0] = 1\n for (i in 1 until ps.size) {\n ps[i] = ps[i - 1] * 10 + 1\n }\n\n var ans = 1e9.toInt()\n\n fun go(i: Int, s: Long, ca: Int, n: Long) {\n if (s == n) {\n ans = min(ans, ca)\n }\n if (i == -1 || s - 9 * ps[i] > n || s + 9 * ps[i] < n) {\n return\n }\n\n for (j in -9 .. 9) {\n go(i - 1, s + ps[i] * j, ca + abs(j) * (i + 1), n)\n }\n }\n\n go(15, 0, 0, n)\n\n print(ans)\n}"}, {"source_code": "import kotlin.math.min\n\nprivate fun next(r: Long): Long {\n return r * 10L + 1\n}\n\nprivate fun solve(value: Long): Int {\n if (value == 0L) return 0\n var count = 1\n var r = 1L\n if (r == value) return count\n while (next(r) < value) {\n r = next(r)\n ++count\n }\n var mult = 1\n while ((mult + 1L) * r <= value) ++mult\n\n var result = solve(value - mult * r) + count * mult\n if (next(r) - value < value) {\n // try 111..11 - ab..f\n result = min(result, solve(next(r) - value) + count + 1)\n }\n return result\n}\n\nfun main() {\n val n = readLine()!!.trim().toLong()\n println(solve(n))\n}\n"}, {"source_code": "import kotlin.math.sign\n\nfun main() {\n val n = readLine()!!\n println(oneBasedArithmetic(n, 0))\n}\n\nfun oneBasedArithmetic(string: String, count: Int): Int {\n val length = if (string[0] == '-') string.length - 1 else string.length\n val count1 = withNOnes(string, count, length)\n val count2 = withNPlus1Ones(string, count)\n return if (count1 < count2) count1 else count2\n}\n\nfun withNOnes(string: String, count: Int, length: Int): Int {\n val n = if (string[0] == '-') string.length - 1 else string.length\n val num = string.toLong()\n val nOnes = \"1\".repeat(n).toLong()\n return when {\n n < length -> oneBasedArithmetic(string, count)\n n > length -> Int.MAX_VALUE\n num == 0L -> count\n num == -1L -> count + 1\n num == 1L -> count + 1\n num < 0L -> {\n val rem = (num % nOnes).toString()\n val quotient = num / nOnes\n if (quotient == 0L && rem.length == n+1){\n withNOnes((num + nOnes).toString(), count + n, n)\n }else\n oneBasedArithmetic(rem, count + (n * quotient.unaryMinus()).toInt())\n }\n else -> {\n val rem = (num % nOnes).toString()\n val quotient = num / nOnes\n if (quotient == 0L && rem.length == n){\n withNOnes((num - nOnes).toString(), count + n, n)\n }else\n oneBasedArithmetic(rem, count + (n * quotient).toInt())\n }\n }\n}\n\n\nfun withNPlus1Ones(string: String, count: Int): Int {\n val n = if (string[0] == '-') string.length - 1 else string.length\n val num = string.toLong()\n val nOnes = \"1\".repeat(n + 1).toLong()\n return when {\n num < 0L -> withNOnes((num + nOnes).toString(), count + n + 1, n)\n else -> withNOnes((nOnes - num).toString(), count + n + 1, n)\n }\n}"}, {"source_code": "import kotlin.math.sign\n\nfun main() {\n val n = readLine()!!\n println(oneBasedArithmetic(n, 0))\n}\n\nfun oneBasedArithmetic(string: String, count: Int): Int {\n if (count == -1) return -1\n val length = if (string[0] == '-') string.length - 1 else string.length\n val count1 = withNOnes(string, count, length)\n val count2 = withNPlus1Ones(string, count)\n return if (count1 < count2) count1 else count2\n}\n\nfun withNOnes(string: String, count: Int, length: Int): Int {\n// val n = string.replace(\"-\",\"\").length\n// var count1 = count\n// var num = string.toInt()\n// val nOnes = \"1\".repeat(n).toInt()\n// var length = n\n// while (length == n) {\n// when {\n// num < 0 -> {\n// num += nOnes\n// count1 += n\n// length = num.toString().replace(\"-\", \"\").length\n// }\n// num == 0 -> return count1\n// num > 0 -> {\n// count1 += n\n// num -= nOnes\n// length = num.toString().replace(\"-\", \"\").length\n// }\n// }\n// }\n// return if (length < n)\n// oneBasedArithmetic(num.toString(), count1)\n// else -1\n val n = if (string[0] == '-') string.length - 1 else string.length\n val num = string.toLong()\n val nOnes = \"1\".repeat(n).toLong()\n return when {\n n < length -> oneBasedArithmetic(string,count)\n n > length -> Int.MAX_VALUE\n num == 0L -> count\n num == -1L -> count + 1\n num == 1L -> count + 1\n num < 0L -> withNOnes((num + nOnes).toString(), count + n, length)\n else -> withNOnes((num - nOnes).toString(), count + n, length)\n }\n}\n\nfun withNPlus1Ones(string: String, count: Int): Int {\n// val n = string.replace(\"-\",\"\").length\n// var count1 = count\n// var num = string.toInt()\n// val nOnesPlusOne = \"1\".repeat(n + 1).toInt()\n// var length = n\n// while (length == n) {\n// when {\n// num < 0 -> {\n// num += nOnesPlusOne\n// count1 += n\n// length = num.toString().replace(\"-\", \"\").length\n// }\n// num == 0 -> return count\n// num > 0 -> {\n// count1 += n\n// num = nOnesPlusOne - num\n// length = num.toString().replace(\"-\", \"\").length\n// }\n// }\n// }\n// return if (length < n)\n// oneBasedArithmetic(num.toString(), count1)\n// else -1\n val n = if (string[0] == '-') string.length - 1 else string.length\n val num = string.toLong()\n val nOnes = \"1\".repeat(n + 1).toLong()\n return when {\n num < 0L -> withNOnes((num + nOnes).toString(), count + n + 1, n)\n else -> withNOnes((nOnes - num).toString(), count + n + 1, n)\n }\n}"}, {"source_code": "import kotlin.math.min\n\nfun main() {\n val i = readLine()!!\n val count = 0L\n println(min(findEqualDigits(i, count), findGreaterDigits(i, count)))\n}\n\nfun findEqualDigits(\n Number: String,\n count: Long\n): Long {\n when {\n (Number.toLong() == -1L) -> return count + 1L\n (Number.toLong() == 1L) -> return count + 1L\n (Number.toLong() == 0L) -> return count\n }\n val num = if (Number.startsWith(\"-\")) Number.drop(1) else Number\n val digits = num.length\n val number = \"1\".repeat(digits).toLong()\n val quotient = num.toLong() / number\n val updatedNumber = num.toLong() % number\n val onesCount = count.plus(quotient * digits)\n// val updatedNumber=num.toLong()- number\n if (quotient == 0L && updatedNumber.toString().length == digits) {\n val number1 = updatedNumber - number\n val subCount = onesCount + digits\n return min(findEqualDigits(number1.toString(), subCount),\n findGreaterDigits(number1.toString(),subCount))\n }\n else\n {\n return when {\n (updatedNumber == -1L) -> onesCount + 1L\n (updatedNumber == 1L) -> onesCount + 1L\n (updatedNumber == 0L) -> onesCount\n else ->\n min(\n findEqualDigits(updatedNumber.toString(), onesCount)\n , findGreaterDigits(updatedNumber.toString(), onesCount)\n )\n }\n }\n}\n\nfun findGreaterDigits(\n Number: String,\n count: Long\n): Long {\n val num = if (Number.startsWith(\"-\")) Number.drop(1) else Number\n val digits = num.length\n val number = \"1\".repeat(digits + 1)\n val updatedNumber = number.toLong() - num.toLong()\n return if (digits < updatedNumber.toString().length)\n Long.MAX_VALUE\n else\n findEqualDigits(updatedNumber.toString(), count.plus(digits + 1))\n\n}\n"}, {"source_code": "import java.util.*\n\nfun main() {\n val sc = Scanner(System.`in`)\n val n = sc.nextLong()\n val Z = LongArray(20)\n Z[1] = 1\n for (i in 2 until Z.size) {\n Z[i] = Z[i - 1] * 10 + 1\n }\n var res = Long.MAX_VALUE\n for (len in 1..17) {\n for (m in 0..(1 shl len)) {\n var cur = 0L\n var cnt = 0L\n for (i in len downTo 1) {\n val overflow = (m and (1 shl i)) != 0\n if (cur < n) {\n val am = (n - cur) / Z[i]\n cur += Z[i] * am\n cnt += i * am\n if (overflow && cur < n) {\n cur += Z[i]\n cnt += i\n }\n } else if (cur > n) {\n val am = (cur - n) / Z[i]\n cur -= Z[i] * am\n cnt += i * am\n if (overflow && cur > n) {\n cur -= Z[i]\n cnt += i\n }\n }\n }\n if (cur == n)\n res = minOf(res, cnt)\n }\n }\n println(res)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\n\nval inf = BufferedReader(InputStreamReader(System.`in`))\nval ouf = PrintWriter(System.out)\n\nfun BufferedReader.readInts() = readLine()!!.split(' ').map(String::toInt)\nfun BufferedReader.readLongs() = readLine()!!.split(' ').map(String::toLong)\nfun Any?.println() = ouf.println(this)\n\nfun main() {\n val (n) = inf.readLongs()\n var q = 1L\n var qq = 1\n while (q <= n) {\n q = q * 10 + 1\n qq++\n }\n\n fun f(n: Long, q: Long, qq: Int): Int {\n if (n % q == 0L) return (n / q).toInt() * qq\n val d = (n / q).toInt()\n return minOf(qq * d + f(n - q * d, q / 10, qq - 1), qq * (d + 1) + f(q * (d + 1) - n, q / 10, qq - 1))\n }\n\n ouf.println(minOf(f(n, q / 10, qq - 1), f(q - n, q / 10, qq - 1) + qq))\n ouf.close()\n}\n"}, {"source_code": "import java.util.*\n\n\nvar a = LongArray(18)\nvar res = 1000000000000000000L\nfun dfs(n_now: Long, pre: Int, total: Long) {\n if (pre == 0) {\n if (res > total) res = total\n return\n }\n if (n_now >= 0) {\n dfs(n_now - n_now / a[pre] * a[pre], pre - 1, total + n_now / a[pre] * pre)\n dfs(n_now - (n_now / a[pre] + 1) * a[pre], pre - 1, total + (n_now / a[pre] + 1) * pre)\n } else {\n dfs(n_now + -n_now / a[pre] * a[pre], pre - 1, total + -n_now / a[pre] * pre)\n dfs(n_now + (-n_now / a[pre] + 1) * a[pre], pre - 1, total + (-n_now / a[pre] + 1) * pre)\n }\n}\n\nfun main(args: Array) {\n a[1] = 1\n for (i in 2..16)\n a[i] = a[i - 1] * 10 + 1\n val cin = Scanner(System.`in`)\n var n = cin.nextLong()\n dfs(n, 16, 0)\n System.out.print(res)\n}"}, {"source_code": "import java.util.*\n\n\nvar a = LongArray(18)\nvar MIN = 100000000000000000L\nfun dfs(n: Long, now: Int, tot: Long) {\n if (now == 0) {\n if (MIN > tot) MIN = tot\n return\n }\n if (n >= 0) {\n val temp = n / a[now]\n dfs(n - temp * a[now], now - 1, tot + temp * now)\n dfs(n - (temp + 1) * a[now], now - 1, tot + (temp + 1) * now)\n } else {\n val temp = -n / a[now]\n dfs(n + temp * a[now], now - 1, tot + temp * now)\n dfs(n + (temp + 1) * a[now], now - 1, tot + (temp + 1) * now)\n }\n}\n\nfun main(args: Array) {\n a[1] = 1\n for (i in 2..16) a[i] = a[i - 1] * 10 + 1\n val cin = Scanner(System.`in`)\n val n = cin.nextLong()\n dfs(n, 16, 0)\n println(MIN)\n cin.close()\n}"}, {"source_code": "//package com.company\n\nimport java.util.*\nimport kotlin.math.min\n\nvar vec : MutableList < Long > = mutableListOf()\n\nfun main() {\n vec.add(0);\n\n for(i in 1..16)\n vec.add(vec.elementAt(i - 1) * 10 + 1)\n var sc = Scanner(System.`in`)\n var n = sc.nextLong()\n\n var res = func(n , vec.size - 1)\n println(res)\n}\n\nfun func(n : Long, i : Int): Long {\n var ret = n / vec.elementAt(i)\n var N = n % vec.elementAt(i)\n\n when {\n n.toString() == \"0\" || N.toString() == \"0\" -> return ret * i\n else -> return ret * i + min(i + func(vec.elementAt(i) - N , i - 1) , func(N , i - 1))\n }\n}"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() {\n val n0 = readLong()\n\n val M = LongArray(17)\n for(i in 1 until M.size) M[i] = M[i-1] * 10 + 1\n\n var D = hashMapOf(n0 to 0)\n\n for(k in M.size-2 downTo 1) {\n if(M[k] > n0) continue\n\n val Dk = HashMap()\n\n for((n, c) in D) {\n Dk.checkMin(n % M[k], c + (n / M[k] * k).toInt())\n val n1 = M[k+1] - n\n Dk.checkMin(n1 % M[k], c + k + 1 + (n1 / M[k] * k).toInt())\n }\n\n D = Dk\n }\n\n val ans = D[0]\n\n println(ans)\n}\n\nfun HashMap.checkMin(k: K, v: Int) { if(!containsKey(k) || v < get(k)!!) put(k, v) }\n\n/** IO code start */\n@JvmField val _reader = System.`in`.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(System.out, false)\ninline fun output(block: PrintWriter.()->Unit) { _writer.apply(block).flush() }\nfun iprintln(o: Any?) { println(o) } // immediate println for interactive, bypasses output{} blocks"}, {"source_code": "import java.util.*\n\nfun main() {\n val sc = Scanner(System.`in`)\n val n = sc.nextLong()\n val Z = LongArray(20)\n Z[1] = 1\n for (i in 2 until Z.size) {\n Z[i] = Z[i - 1] * 10 + 1\n }\n var res = Long.MAX_VALUE\n for (len in 1..17) {\n for (m in 0..(1 shl len)) {\n var cur = 0L\n var cnt = 0L\n for (i in len downTo 1) {\n val overflow = (m and (1 shl i)) != 0\n if (cur < n) {\n val am = (n - cur) / Z[i]\n cur += Z[i] * am\n cnt += i * am\n if (overflow && cur < n) {\n cur += Z[i]\n cnt += i\n }\n } else if (cur > n) {\n val am = (cur - n) / Z[i]\n cur -= Z[i] * am\n cnt += i * am\n if (overflow && cur > n) {\n cur -= Z[i]\n cnt += i\n }\n }\n }\n if (cur == n)\n res = minOf(res, cnt)\n }\n }\n println(res)\n}"}, {"source_code": "private fun spar() = readLine()!! // string line\nprivate fun ipar() = spar().toInt() // single int\nprivate fun lpar() = spar().toLong() // single long\nprivate fun sapar() = spar().split(\" \") // list of strings\nprivate fun iapar() = sapar().map { it.toInt() } // list of ints\nprivate fun lapar() = sapar().map { it.toLong() } // list of longs\n\nfun main()\n{\n val n = lpar()\n println(brute(n))\n}\n\nprivate fun brute(n: Long): Int\n{\n if (n <= 6)\n {\n return n.toInt()\n }\n if (n >= 7 && n <= 11)\n {\n return 13-n.toInt()\n }\n var l = 1\n while (ones(l) < n)\n {\n l++\n }\n l--\n val a = n % ones(l)\n val res1 = (n / ones(l)) * l + brute(a)\n val b = (ones(l+1) - n) % ones(l)\n val res2 = l+1 + ((ones(l+1) - n) / ones(l)) * l + brute(b)\n // println(arrayOf(n, a, b, Math.min(res1, res2)).joinToString(\", \"))\n return Math.min(res1, res2).toInt()\n}\n\nprivate fun ones(l: Int): Long\n{\n return Math.pow(10.0, l.toDouble()).toLong() / 9\n}"}, {"source_code": "import java.lang.Integer.parseInt\nimport java.lang.Long.parseLong\nimport java.lang.Math.abs\nimport java.lang.Math.min\nimport java.lang.System.exit\n\nimport java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\n\nobject F {\n\n internal val ones = LongArray(17)\n internal val total = LongArray(17)\n\n internal var `in`: BufferedReader? = null\n internal var out: PrintWriter? = null\n internal var tok: StringTokenizer? = null\n\n init {\n for (i in 1 until ones.size) {\n ones[i] = 10 * ones[i - 1] + 1\n total[i] = total[i - 1] + 6 * ones[i]\n }\n }\n\n internal fun solve(n: Long, i: Int): Int {\n if (n > total[i] || n < -total[i]) {\n return -1\n }\n if (i == 0) {\n return 0\n }\n var ans = Integer.MAX_VALUE\n for (j in -6..6) {\n val cans = solve(n + j * ones[i], i - 1)\n if (cans >= 0) {\n ans = min(ans, cans + abs(j) * i)\n }\n }\n return if (ans == Integer.MAX_VALUE) -1 else ans\n }\n\n @Throws(Exception::class)\n internal fun solve() {\n val n = scanLong()\n out!!.print(solve(n, 16))\n }\n\n @Throws(IOException::class)\n internal fun scanInt(): Int {\n return parseInt(scanString())\n }\n\n @Throws(IOException::class)\n internal fun scanLong(): Long {\n return parseLong(scanString())\n }\n\n @Throws(IOException::class)\n internal fun scanString(): String {\n while (tok == null || !tok!!.hasMoreTokens()) {\n tok = StringTokenizer(`in`!!.readLine())\n }\n return tok!!.nextToken()\n }\n\n @JvmStatic\n fun main(args: Array) {\n try {\n `in` = BufferedReader(InputStreamReader(System.`in`))\n out = PrintWriter(System.out)\n solve()\n `in`!!.close()\n out!!.close()\n } catch (e: Throwable) {\n e.printStackTrace()\n exit(1)\n }\n\n }\n}\n\nfun main(args: Array) {\n F.main(args)\n}"}, {"source_code": "import java.util.*\n\nvar a = Array(17, {i -> 0L})\nfun ans(n: Long): Long\n{\n if (n == 0L)\n return 0L;\n var k = 1\n while (k < 16)\n {\n if (a[k] <= n && n <= a[k + 1])\n {\n var x = k * (n / a[k]) + ans(n - a[k] * (n / a[k]))\n var y = k + 1 + (a[k + 1] - n) / a[k] * k + ans(a[k + 1] - n - (a[k + 1] - n) / a[k] * a[k])\n return if (x < y) x else y\n }\n ++k;\n }\n return 1000000000\n}\n\nfun main()\n{\n for (i in 1..16)\n a[i] = a[i - 1] * 10L + 1L\n var n = readLine()!!.toLong()\n print(ans(n))\n}"}, {"source_code": " import java.util.*\n \n var a = arrayOf(0L, 1L, 11L, 111L, 1111L, 11111L, 111111L, 1111111L, 11111111L, 111111111L, 1111111111L, 11111111111L, 111111111111L, \n 1111111111111L, 11111111111111L, 111111111111111L,1111111111111111L)\n fun ans(n: Long): Long\n {\n if (n == 0L)\n return 0L;\n var k = 1\n while (k < 17)\n {\n if (a[k] <= n && n <= a[k + 1])\n {\n var x = k * (n / a[k]) + ans(n - a[k] * (n / a[k]))\n var y = k + 1 + (a[k + 1] - n) / a[k] * k + ans(a[k + 1] - n - (a[k + 1] - n) / a[k] * a[k])\n return if (x < y) x else y\n }\n ++k;\n }\n return 10000000000\n }\n \n fun main()\n {\n var n = readLine()!!.toLong()\n print(ans(n))\n }"}, {"source_code": "import kotlin.math.min\n\nfun foo(s : String) : Long {\n if (s == \"0\")\n return 0L;\n var p = true\n for (i in s)\n if(i != '1'){\n p = false\n break\n }\n if (p)\n return 1L * s.length\n var d = 0L\n for (i in s.indices)\n d = d * 10 + 1\n if (s.toLong() < d)\n d /= 10\n var q1 = foo((s.toLong() % d).toString()) + s.toLong() / d * s.length\n d = d * 10 + 1;\n var q2 = q1;\n if (s.toLong() > d / 2)\n q2 = foo(d.toString()) + foo((d - s.toLong()).toString())\n return min(q1, q2)\n}\nfun main(){\n var n = readLine().toString()\n println(foo(n))\n\n}\n"}], "negative_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007\n\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val S = ns()\n val N = S.length\n val zero = 9\n val MAX = 19\n val INF = 1e9.toInt()\n val dp = Array(N + 1){IntArray(MAX){INF} }\n dp[0][zero] = 0\n for (i in 0 until N) {\n val target = S[N - 1 - i] - '0'\n for (next in 0 until MAX) {\n for (pre in 0 until MAX) {\n if (dp[i][pre] == INF) continue\n val roll = abs((next - zero) + target) // この桁まで\n val rollback = abs(next - pre - roll) // 前の桁を戻す\n val cost = roll * (i + 1) + rollback * i\n dp[i + 1][next] = min(dp[i + 1][next], dp[i][pre] + cost)\n }\n }\n }\n debugDim(dp)\n out.println(dp[N][zero])\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl()\n }\n return res\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}"}, {"source_code": "import kotlin.math.min\n\nval ones = ArrayList()\nval cost = HashMap()\n\nfun lowerBound(n: Long): Int{\n var(lo, hi) = 0 to ones.size - 1\n while(lo < hi){\n val mid = (lo + hi) / 2 + (lo + hi) % 2\n if(ones[mid] < n)\n lo = mid\n else\n hi = mid - 1\n }\n return lo\n}\n\nfun rec(n: Long): Long{\n when {\n n == 0L -> return 0L\n n <= 6 -> return n\n n <= 11 -> return 13 - n\n }\n val bs = lowerBound(n)\n return min(rec(n - ones[bs]) + cost[ones[bs]]!!, rec(ones[bs + 1] - n) + cost[ones[bs + 1]]!!)\n}\n\nfun main() {\n val n = readLine()!!.toLong()\n for(i in 1..15)\n for(j in '1'..'9'){\n ones.add(j.toString().repeat(i).toLong())\n cost[ones.last()] = (j.toLong() - '0'.toLong()) * i\n }\n ones.add(1111111111111111L)\n cost[1111111111111111L] = 16L\n println(rec(n))\n}"}, {"source_code": "import kotlin.math.*\n \nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of ints\nfun readLong() = readLn().toLong() // list of strings\n \n fun get1(_l:Int):Long{\n var n = _l\n if (n == 0)\n return 1\n var ret = 1L\n while(n > 1)\n {\n ret=1 + ret * 10\n n--\n }\n return ret\n}\n\nfun getLength(_n:Long):Int{\n var n = _n\n if (n == 0L)\n return 0\n var ret = 0\n while(n > 0L)\n {\n ret++\n n = n / 10\n }\n return ret\n}\n \nfun pow10(pow:Int):Long{\n var ret = 1L\n for(i in 1..pow)\n ret = ret*10\n return ret\n}\n\nfun getCount(n: Long):Long\n{\n val l = getLength(n)\n \n \n val plus = mutableMapOf()\n var tmp:Long = n\n for(i in l-1 downTo 0)\n {\n var v = get1(i+1)\n val mult = tmp / v \n \n plus.set(i, mult.toInt()) \n \n tmp = tmp%v\n }\n plus.set(l, 0)\n //println(plus)\n var changed = true\n while(changed)\n {\n changed = false\n for (i in 0..l-1) {\n var itm = plus[i]!!\n val li = i+1\n if ( itm > 0)\n { \n println(1)\n\n val diff = (if (i != 0) (li+1) * plus[i+1]!!.absoluteValue + li * itm + plus[0]!!.absoluteValue - \n (li+1) *(plus[i+1]!! + 1).absoluteValue - li*(itm - 10).absoluteValue - (plus[0]!! -1).absoluteValue\n else\n plus[i+1]!!.absoluteValue + plus[0]!!.absoluteValue -\n (li+1) *(plus[i+1]!! + 1).absoluteValue - (plus[0]!! - 11).absoluteValue\n )\n \n if (diff > 0)\n {\n \n // println(i)\n // println(plus)\n plus[i+1] = plus[i+1]!! + 1 \n plus[0] = plus[0]!! - 1\n plus[i] = plus[i]!! - 10\n changed = true\n \n \n // println(plus)\n }\n \n //println(plus)\n \n }\n else if ( itm <0 )\n {\n val diff = (if (i != 0) (li+1) * plus[i+1]!!.absoluteValue + li * itm.absoluteValue + plus[0]!!.absoluteValue - \n (li+1) *(plus[i+1]!! - 1).absoluteValue - li*(itm + 10).absoluteValue - (plus[0]!! + 1).absoluteValue\n else\n plus[i+1]!!.absoluteValue + plus[0]!!.absoluteValue -\n (li+1) *(plus[i+1]!! - 1).absoluteValue - (plus[0]!! + 11).absoluteValue\n )\n if (diff > 0)\n { \n // println(2) \n // println(i) \n // println(plus)\n plus[i+1] = plus[i+1]!! -1 \n plus[0] = plus[0]!! + 1\n plus[i] = plus[i]!! + 10\n changed = true\n \n \n // println(plus)\n }\n \n }\n }\n }\n\n var ret = 0L\n for ((key, value) in plus) {\n ret+=(key + 1) * value.absoluteValue\n }\n // print(plus)\n return ret\n}\n \nfun main() {\n var n = readLong()\n \n println(getCount(n) )\n //println(plus)\n //println(minus)\n}"}, {"source_code": "import kotlin.math.*\n \nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of ints\nfun readLong() = readLn().toLong() // list of strings\n \n fun get1(_l:Int):Long{\n var n = _l\n if (n == 0)\n return 1\n var ret = 1L\n while(n > 1)\n {\n ret=1 + ret * 10\n n--\n }\n return ret\n}\n\nfun getLength(_n:Long):Int{\n var n = _n\n if (n == 0L)\n return 0\n var ret = 0\n while(n > 0L)\n {\n ret++\n n = n / 10\n }\n return ret\n}\n \nfun pow10(pow:Int):Long{\n var ret = 1L\n for(i in 1..pow)\n ret = ret*10\n return ret\n}\n\nfun getCount(n: Long):Long\n{\n val l = getLength(n)\n \n \n val plus = mutableMapOf()\n var tmp:Long = n\n for(i in l-1 downTo 0)\n {\n var v = get1(i+1)\n val mult = tmp / v \n \n plus.set(i, mult.toInt()) \n \n tmp = tmp%v\n }\n plus.set(l, 0)\n \n var changed = true\n while(changed)\n {\n changed = false\n for (i in 0..l-1) {\n var itm = plus[i]!!\n val li = i+1\n if ( itm >= 7 || itm == 6 && li >=2 )\n {\n \n plus[i+1] = plus[i+1]!! + 1 \n plus[0] = plus[0]!! - 1\n plus[i] = itm - 10\n changed = true\n }\n else if ( itm <= -7 || itm == -6 && li >=2 )\n {\n \n plus[i+1] = plus[i+1]!! -1 \n plus[0] = plus[0]!! + 1\n plus[i] = itm + 10\n changed = true\n }\n }\n }\n\n var ret = 0L\n for ((key, value) in plus) {\n ret+=(key + 1) * value.absoluteValue\n }\n // print(plus)\n return ret\n}\n \nfun main() {\n var n = readLong()\n \n println(getLength(n) )\n //println(plus)\n //println(minus)\n}"}, {"source_code": "import kotlin.math.*\n\nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of ints\nfun readLong() = readLn().toLong() // list of strings\n\nfun getLength(_n:Long):Int{\n var n = _n\n if (n == 0L)\n return 0\n var ret = 0\n while(n > 0L)\n {\n ret++\n n = n / 10\n }\n return ret\n}\n\nfun get1(_l:Int):Long{\n var n = _l\n if (n == 0)\n return 1\n var ret = 1L\n while(n > 1)\n {\n ret=1 + ret * 10\n n--\n }\n return ret\n}\n\nfun pow10(pow:Int):Long{\n var ret = 1L\n for(i in 1..pow)\n ret = ret*10\n return ret\n}\n\nfun main() {\n \n println(getCount(readLong()))\n}\n\nfun getCount(_n:Long):Long\n{\n // println(\"-------------\")\n // println(_n)\n if (_n ==0L)\n return 0\n\n var n =if (_n> 0) _n else -_n\n \n val l = getLength(n)\n val l1 = get1(l)\n\n if (l == 1)\n return min(n, 13 - n)\n\n // println(l1)\n if(n <= l1)\n return l + getCount(l1 - n)\n \n val l11 = l1 + pow10(l)\n // println(l+1)\n // println(pow10(l))\n // println(l11)\n val rem1 = n / pow10(l-1)\n\n val n2 = l11 - n\n val rem2 = n2 / pow10(l-1)\n\n \n \n val value1 = l * rem1 + getCount( n - rem1 * l1 )\n val value2 = (l+1) + l * rem2 + getCount( n2 - rem2 * l1 ) \n // println(\"++++++++++\")\n return if (value1 > value2) value2 else value1\n}\n"}, {"source_code": "import kotlin.math.*\n\nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of ints\nfun readLong() = readLn().toLong() // list of strings\n\nfun getLength(_n:Long):Int{\n var n = _n\n if (n == 0L)\n return 0\n var ret = 0\n while(n > 0L)\n {\n ret++\n n = n / 10\n }\n return ret\n}\n\nfun get1(_l:Int):Long{\n var n = _l\n if (n == 0)\n return 1\n var ret = 1L\n while(n > 1)\n {\n ret=1 + ret * 10\n n--\n }\n return ret\n}\n\nfun pow10(pow:Int):Long{\n var ret = 1L\n for(i in 1..pow)\n ret = ret*10\n return ret\n}\n\nfun main() {\n \n println(getCount(readLong()))\n}\n\nfun getCount(_n:Long):Long\n{\n if (_n ==0L)\n return 0\n\n var n =if (_n> 0) _n else -_n\n \n val l = getLength(n)\n val l1 = get1(l)\n\n if (l == 1)\n return min(n, 13 - n)\n\n // println(l1)\n if(n <= l1)\n return l + getCount(l1 - n)\n \n val l11 = l1 + pow10(l)\n // println(l+1)\n // println(pow10(l))\n // println(l11)\n val rem1 = n / pow10(l-1)\n\n val n2 = l11 - n\n val rem2 = n2 / pow10(l-1)\n\n // println(rem1)\n // println(rem2)\n \n val value1 = l * rem1 + getCount( n - rem1 * l1 )\n val value2 = l * rem2 + getCount( n2 - rem2 * l1 ) \n return if (value1 > value2) value2 else value1\n}\n"}, {"source_code": "import kotlin.math.*\n\nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of ints\nfun readLong() = readLn().toLong() // list of strings\n\nfun getLength(_n:Long):Int{\n var n = _n\n if (n == 0L)\n return 0\n var ret = 0\n while(n > 0L)\n {\n ret++\n n = n / 10\n }\n return ret\n}\n\nfun get1(_l:Int):Long{\n var n = _l\n if (n == 0)\n return 1\n var ret = 1L\n while(n > 1)\n {\n ret=1 + ret * 10\n n--\n }\n return ret\n}\n\nfun pow10(pow:Int):Long{\n var ret = 1L\n for(i in 1..pow)\n ret = ret*10\n return ret\n}\n\nfun main() {\n \n println(getCount(readLong()))\n}\n\n\nfun getCount(_n:Long):Long\n{ \n if (_n ==0L)\n return 0\n\n var n =if (_n> 0) _n else -_n\n \n val l = getLength(n)\n val l1 = get1(l)\n\n if (l == 1)\n return min(n, 13 - n)\n \n val digit = n / l1\n var bdigit = digit + 1\n var nbottom = digit * l1\n var ntop = (bdigit) * l1\n if (n % l1 ==0L)\n {\n ntop = nbottom \n bdigit = digit \n }\n \n \n val ntopadd = getCount(ntop - n)\n \n val v1 = bdigit * l + ntopadd\n val v2 = l + 2 + l * (10 - bdigit) + ntopadd\n\n var ret = min(v1, v2)\n if (ntop != nbottom && nbottom > 0)\n {\n val ntopadd2 = getCount(n - nbottom)\n \n val v3 = digit * l + ntopadd2\n val v4 = l + 2 + l * (10 - digit) + ntopadd2\n ret = min(ret, v3)\n ret = min(ret, v4)\n }\n return ret\n}"}, {"source_code": "import kotlin.math.*\n \nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of ints\nfun readLong() = readLn().toLong() // list of strings\n \n fun get1(_l:Int):Long{\n var n = _l\n if (n == 0)\n return 1\n var ret = 1L\n while(n > 1)\n {\n ret=1 + ret * 10\n n--\n }\n return ret\n}\n\nfun getLength(_n:Long):Int{\n var n = _n\n if (n == 0L)\n return 0\n var ret = 0\n while(n > 0L)\n {\n ret++\n n = n / 10\n }\n return ret\n}\n \nfun pow10(pow:Int):Long{\n var ret = 1L\n for(i in 1..pow)\n ret = ret*10\n return ret\n}\n\n \nfun main() {\n var n = readLong()\n val l = getLength(n)\n \n \n val plus = mutableMapOf()\n var tmp:Long = n\n for(i in l-1 downTo 0)\n {\n var v = get1(i+1)\n val mult = tmp / v \n \n plus.set(i, mult.toInt()) \n \n tmp = tmp%v\n }\n plus.set(l, 0)\n \n var changed = true\n while(changed)\n {\n changed = false\n for (i in 0..l-1) {\n var itm = plus[i]!!\n val li = i+1\n if ( itm >= 7 || itm == 6 && li >=2 )\n {\n \n plus[i+1] = plus[i+1]!! + 1 \n plus[0] = plus[0]!! - 1\n plus[i] = plus[i]!! - 10\n changed = true\n }\n else if ( itm <= -7 || itm == -6 && li >=2 )\n {\n \n plus[i+1] = plus[i+1]!! -1 \n plus[0] = plus[0]!! + 1\n plus[i] = plus[i]!! + 10\n changed = true\n }\n }\n }\n\n var ret = 0L\n for ((key, value) in plus) {\n ret+=(key + 1) * value.absoluteValue\n }\n\n println(ret)\n //println(plus)\n //println(minus)\n}\n "}, {"source_code": "import kotlin.math.*\n\nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of ints\nfun readLong() = readLn().toLong() // list of strings\n\nfun getLength(_n:Long):Int{\n var n = _n\n if (n == 0L)\n return 0\n var ret = 0\n while(n > 0L)\n {\n ret++\n n = n / 10\n }\n return ret\n}\n\nfun pow10(pow:Int):Long{\n var ret = 1L\n for(i in 1..pow)\n ret = ret*10\n return ret\n}\n\nfun main() {\n var n = readLong()\n val l = getLength(n)\n \n \n var prev = 0\n\n val minus = mutableMapOf()\n val plus = mutableMapOf()\n\n for(i in l-1 downTo 0)\n {\n \n val cur = ((n / pow10(i)) % 10).toInt()\n plus.set(i, 0)\n minus.set(i, 0)\n if (cur >= prev)\n {\n plus[i] =plus[i]!! + cur - prev\n }\n else\n {\n minus[i] =minus[i]!! + prev - cur\n }\n prev = cur\n }\n plus.set(l, 0)\n minus.set(l, 0)\n\n \n var i = l -1\n\n while(i >= 0)\n {\n //println(\"i = %d\".format(i))\n //println(\"----\")\n //println(plus)\n //println(minus)\n if (plus[i]!! > 0 && minus[i]!! > 0)\n {\n val minv = min(plus[i]!!, minus[i]!!)\n plus[i] = plus[i]!! - minv\n minus[i] = minus[i]!! - minv\n }\n if (plus[i]!! >= 10)\n {\n val tc = plus[i]!! / 10\n plus[i] = plus[i]!! % 10\n //println(\"Set %d to %d\".format(i+1, plus[i+1]!! + 1))\n plus[i+1] = plus[i+1]!! + tc\n minus[0] = minus[0]!!+1\n i = i+1\n continue\n }\n else if (minus[i]!! >= 10)\n {\n val tc = minus[i]!! / 10\n minus[i] = minus[i]!! % 10\n minus[i+1] = minus[i+1]!! + tc\n plus[0] =plus[0]!!+1\n i = i+1\n continue\n }\n \n if (plus[i]!! > 0 && i != l)\n {\n val curcnt = plus[i]!! * (i+1) \n \n var possible = (i + 2) + 1 + (i+1) + ( 9 - plus[i]!!) * (i+1)\n \n if (minus[i+1]!! > 0)\n {\n possible -= 2 * (i+2)\n }\n if (plus[0]!! > 0 && i > 0)\n {\n possible -= 2 \n }\n if (possible <= curcnt)\n {\n println(possible)\n \n plus[i+1]= plus[i+1]!! + 1 \n minus[i] = 10 - plus[i]!!\n minus[0] = minus[0]!!+1\n plus[i] = 0\n i = i + 1 \n continue\n }\n } \n if (minus[i]!! > 0 && i != l)\n {\n val curcnt = minus[i]!! * (i+1)\n var possible = (i + 2) + 1 + (i+1) + ( 9 - minus[i]!!) * (i+1)\n\n if (plus[i+1]!! > 0)\n {\n possible -= 2 * (i+2)\n }\n if (minus[0]!! > 0 && i > 0)\n {\n possible -= 2 \n }\n if (possible <= curcnt)\n {\n minus[i+1]= minus[i+1]!! + 1 \n plus[i] = 10 - minus[i]!!\n plus[0] = plus[0]!!+1\n minus[i] = 0\n i = i + 1 \n continue\n }\n } \n // println(\"decrement\")\n i = i -1 \n }\n var ret =0\n for(j in 0..l)\n {\n ret+=plus[j]!! *(j + 1)\n ret+=minus[j]!! *(j + 1)\n \n }\n println(ret)\n //println(plus)\n //println(minus)\n}"}, {"source_code": "import kotlin.math.*\n\nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of ints\nfun readLong() = readLn().toLong() // list of strings\n\nfun getLength(_n:Long):Int{\n var n = _n\n if (n == 0L)\n return 0\n var ret = 0\n while(n > 0L)\n {\n ret++\n n = n / 10\n }\n return ret\n}\n\nfun pow10(pow:Int):Long{\n var ret = 1L\n for(i in 1..pow)\n ret = ret*10\n return ret\n}\n\nfun main() {\n var n = readLong()\n val l = getLength(n)\n \n \n var prev = 0\n\n val minus = mutableMapOf()\n val plus = mutableMapOf()\n\n for(i in l-1 downTo 0)\n {\n \n val cur = ((n / pow10(i)) % 10).toInt()\n plus.set(i, 0)\n minus.set(i, 0)\n if (cur >= prev)\n {\n plus[i] =plus[i]!! + cur - prev\n }\n else\n {\n minus[i] =minus[i]!! + prev - cur\n }\n prev = cur\n }\n plus.set(l, 0)\n minus.set(l, 0)\n\n \n var i = l -1\n\n while(i >= 0)\n {\n //println(\"i = %d\".format(i))\n //println(\"----\")\n //println(plus)\n //println(minus)\n if (plus[i]!! > 0 && minus[i]!! > 0)\n {\n val minv = min(plus[i]!!, minus[i]!!)\n plus[i] = plus[i]!! - minv\n minus[i] = minus[i]!! - minv\n }\n if (plus[i]!! >= 10)\n {\n val tc = plus[i]!! / 10\n plus[i] = plus[i]!! % 10\n //println(\"Set %d to %d\".format(i+1, plus[i+1]!! + 1))\n plus[i+1] = plus[i+1]!! + tc\n minus[0] = minus[0]!!+1\n i = i+1\n continue\n }\n else if (minus[i]!! >= 10)\n {\n val tc = minus[i]!! / 10\n minus[i] = minus[i]!! % 10\n minus[i+1] = minus[i+1]!! + tc\n plus[0] =plus[0]!!+1\n i = i+1\n continue\n }\n \n if (plus[i]!! > 0 && i != l)\n {\n val curcnt = plus[i]!! * (i+1) \n \n var possible = (i + 2) + 1 + (i+1) + ( 9 - plus[i]!!) * (i+1)\n \n if (minus[i+1]!! > 0)\n {\n possible -= 2 * (i+2)\n }\n if (plus[0]!! > 0 && i > 0)\n {\n possible -= 2 \n }\n if (possible < curcnt)\n {\n // println(possible)\n \n plus[i+1]= plus[i+1]!! + 1 \n minus[i] = 10 - plus[i]!!\n minus[0] = minus[0]!!+1\n plus[i] = 0\n i = i + 1 \n continue\n }\n } \n if (minus[i]!! > 0 && i != l)\n {\n val curcnt = minus[i]!! * (i+1)\n var possible = (i + 2) + 1 + (i+1) + ( 9 - minus[i]!!) * (i+1)\n\n if (plus[i+1]!! > 0)\n {\n possible -= 2 * (i+2)\n }\n if (minus[0]!! > 0 && i > 0)\n {\n possible -= 2 \n }\n if (possible <= curcnt)\n {\n minus[i+1]= minus[i+1]!! + 1 \n plus[i] = 10 - minus[i]!!\n plus[0] = plus[0]!!+1\n minus[i] = 0\n i = i + 1 \n continue\n }\n } \n // println(\"decrement\")\n i = i -1 \n }\n var ret =0\n for(j in 0..l)\n {\n ret+=plus[j]!! *(j + 1)\n ret+=minus[j]!! *(j + 1)\n \n }\n println(ret)\n //println(plus)\n //println(minus)\n}\n"}, {"source_code": "import kotlin.math.*\n \nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of ints\nfun readLong() = readLn().toLong() // list of strings\n \n fun get1(_l:Int):Long{\n var n = _l\n if (n == 0)\n return 1\n var ret = 1L\n while(n > 1)\n {\n ret=1 + ret * 10\n n--\n }\n return ret\n}\n\nfun getLength(_n:Long):Int{\n var n = _n\n if (n == 0L)\n return 0\n var ret = 0\n while(n > 0L)\n {\n ret++\n n = n / 10\n }\n return ret\n}\n \nfun pow10(pow:Int):Long{\n var ret = 1L\n for(i in 1..pow)\n ret = ret*10\n return ret\n}\n\nfun getCount(n: Long):Long\n{\n val l = getLength(n)\n \n \n val plus = mutableMapOf()\n var tmp:Long = n\n for(i in l-1 downTo 0)\n {\n var v = get1(i+1)\n val mult = tmp / v \n \n plus.set(i, mult.toInt()) \n \n tmp = tmp%v\n }\n plus.set(l, 0)\n //println(plus)\n var changed = true\n while(changed)\n {\n changed = false\n for (i in 0..l-1) {\n var itm = plus[i]!!\n val li = i+1\n if ( itm > 0)\n { \n // println(1)\n\n val diff = (if (i != 0) (li+1) * plus[i+1]!!.absoluteValue + li * itm + plus[0]!!.absoluteValue - \n (li+1) *(plus[i+1]!! + 1).absoluteValue - li*(itm - 10).absoluteValue - (plus[0]!! -1).absoluteValue\n else\n plus[i+1]!!.absoluteValue + plus[0]!!.absoluteValue -\n (li+1) *(plus[i+1]!! + 1).absoluteValue - (plus[0]!! - 11).absoluteValue\n )\n \n if (diff > 0)\n {\n \n // println(i)\n // println(plus)\n plus[i+1] = plus[i+1]!! + 1 \n plus[0] = plus[0]!! - 1\n plus[i] = plus[i]!! - 10\n changed = true\n \n \n // println(plus)\n }\n \n //println(plus)\n \n }\n else if ( itm <0 )\n {\n val diff = (if (i != 0) (li+1) * plus[i+1]!!.absoluteValue + li * itm.absoluteValue + plus[0]!!.absoluteValue - \n (li+1) *(plus[i+1]!! - 1).absoluteValue - li*(itm + 10).absoluteValue - (plus[0]!! + 1).absoluteValue\n else\n plus[i+1]!!.absoluteValue + plus[0]!!.absoluteValue -\n (li+1) *(plus[i+1]!! - 1).absoluteValue - (plus[0]!! + 11).absoluteValue\n )\n if (diff > 0)\n { \n // println(2) \n // println(i) \n // println(plus)\n plus[i+1] = plus[i+1]!! -1 \n plus[0] = plus[0]!! + 1\n plus[i] = plus[i]!! + 10\n changed = true\n \n \n // println(plus)\n }\n \n }\n }\n }\n\n var ret = 0L\n for ((key, value) in plus) {\n ret+=(key + 1) * value.absoluteValue\n }\n // print(plus)\n return ret\n}\n \nfun main() {\n var n = readLong()\n \n println(getCount(n) )\n //println(plus)\n //println(minus)\n}\n"}, {"source_code": "import kotlin.math.*\n \nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of ints\nfun readLong() = readLn().toLong() // list of strings\n \nfun getLength(_n:Long):Int{\n var n = _n\n if (n == 0L)\n return 0\n var ret = 0\n while(n > 0L)\n {\n ret++\n n = n / 10\n }\n return ret\n}\n \nfun get1(_l:Int):Long{\n var n = _l\n if (n == 0)\n return 1\n var ret = 1L\n while(n > 1)\n {\n ret=1 + ret * 10\n n--\n }\n return ret\n}\n \n \nfun main() {\n val res = getCount(readLong())\n // println(res)\n println(get1Count(res))\n}\n \nfun get1Count(lst:List):Int\n{\n var ret = 0\n for(i in 0 until lst.size)\n { \n val item = lst[i]\n ret+=(i+1)*item.absoluteValue\n }\n return ret\n}\n \nfun getCount(_n:Long):MutableList\n{ \n if (_n ==0L)\n return mutableListOf()\n \n var n =if (_n> 0) _n else -_n\n \n val l = getLength(n).toInt()\n \n if (l == 1)\n {\n if ( n > 6)\n {\n return mutableListOf( n.toInt() - 11, 1 )\n }\n else \n {\n return mutableListOf(n.toInt())\n } \n }\n \n \n val l1 = get1(l)\n \n val digit = (n / l1).toInt()\n var bdigit = digit + 1\n var nbottom = digit * l1\n var ntop = (bdigit) * l1\n if (n % l1 ==0L)\n {\n ntop = nbottom \n bdigit = digit \n }\n \n \n val soltop = getCount(ntop - n)\n // println(ntop - n)\n // println(soltop)\n for(i in soltop.size..l)\n {\n soltop.add(0)\n }\n for(i in 0 until soltop.size)\n {\n soltop[i] = -soltop[i]\n }\n \n var ntopadd = get1Count(soltop)\n val v1 = ( (soltop[l-1] + bdigit).absoluteValue * l \n + ntopadd \n - soltop[l-1].absoluteValue * l)\n \n\n val v2 = ( (l + 1) * (soltop[l] + 1).absoluteValue \n + (soltop[0] - 1).absoluteValue \n + l * (soltop[l-1] - 10 + bdigit).absoluteValue \n + ntopadd \n - soltop[l].absoluteValue - soltop[l-1].absoluteValue- soltop[0].absoluteValue)\n \n \n if (ntop != nbottom && nbottom > 0)\n {\n // println(n - nbottom)\n val soltop2 = getCount(n - nbottom)\n // println(soltop2)\n val ntopadd2 = get1Count(soltop2)\n for(i in soltop2.size..l)\n {\n soltop2.add(0)\n }\n val v3 = ( (soltop2[l-1] + digit).absoluteValue * l \n + ntopadd2 \n - soltop2[l-1].absoluteValue * l)\n \n // println(\"calc v4\")\n //println(soltop2)\n //println(ntopadd2)\n //println(digit)\n val v4 = ( (l + 1) * (soltop2[l] + 1).absoluteValue \n + (soltop2[0] - 1).absoluteValue \n + l * (soltop2[l-1] - 10 + digit).absoluteValue \n + ntopadd2 \n - soltop2[l].absoluteValue - soltop2[l-1].absoluteValue- soltop2[0].absoluteValue)\n //println(v4)\n\n if (v1 <= v2 && v1 <= v3 && v1 <= v4)\n {\n // println(1) \n // println(soltop) \n soltop[l-1] =soltop[ l-1] + bdigit\n // println(soltop)\n return soltop\n }\n else if (v2 <= v1 && v2 <= v3 && v2 <= v4)\n {\n // println(2) \n // println(v1) \n // println(v2) \n // println(soltop) \n // println(l)\n // println(bdigit) \n soltop[l-1] =soltop[ l-1] - 10 + bdigit\n soltop[l] =soltop[ l] +1\n soltop[0] =soltop[ 0] -1\n // println(soltop)\n return soltop\n }\n else if (v3 <= v1 && v3 <= v2 && v3 <= v4)\n {\n // println(3) \n // println(soltop2) \n soltop2[l-1] =soltop2[ l-1] + digit \n // println(soltop2) \n return soltop2\n }\n else\n {\n // println(4) \n // println(soltop2) \n soltop2[l-1] =soltop2[ l-1] - 10 + digit\n soltop2[l] =soltop2[ l] +1\n soltop2[0] =soltop2[ 0] -1\n // println(soltop2) \n return soltop2\n }\n }\n else\n {\n if (v1 <= v2)\n {\n // println(5) \n // println(soltop) \n soltop[l-1] =soltop[ l-1] + bdigit\n // println(soltop) \n return soltop\n }\n else\n {\n // println(6) \n // println(soltop) \n soltop[l-1] =soltop[ l-1] - 10 + bdigit\n soltop[l] =soltop[ l] +1\n soltop[0] =soltop[ 0] -1\n // println(soltop) \n return soltop\n }\n }\n\n \n}"}, {"source_code": "import kotlin.math.*\n\nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of ints\nfun readLong() = readLn().toLong() // list of strings\n\nfun getLength(_n:Long):Int{\n var n = _n\n if (n == 0L)\n return 0\n var ret = 0\n while(n > 0L)\n {\n ret++\n n = n / 10\n }\n return ret\n}\n\nfun pow10(pow:Int):Long{\n var ret = 1L\n for(i in 1..pow)\n ret = ret*10\n return ret\n}\n\nfun main() {\n var n = readLong()\n val l = getLength(n)\n \n \n var prev = 0\n\n val minus = mutableMapOf()\n val plus = mutableMapOf()\n\n for(i in l-1 downTo 0)\n {\n \n val cur = ((n / pow10(i)) % 10).toInt()\n plus.set(i, 0)\n minus.set(i, 0)\n if (cur >= prev)\n {\n plus[i] =plus[i]!! + cur - prev\n }\n else\n {\n minus[i] =minus[i]!! + prev - cur\n }\n prev = cur\n }\n plus.set(l, 0)\n minus.set(l, 0)\n\n \n var i = l -1\n\n while(i >= 0)\n {\n //println(\"i = %d\".format(i))\n //println(\"----\")\n //println(plus)\n //println(minus)\n if (plus[i]!! > 0 && minus[i]!! > 0)\n {\n val minv = min(plus[i]!!, minus[i]!!)\n plus[i] = plus[i]!! - minv\n minus[i] = minus[i]!! - minv\n }\n if (plus[i]!! >= 10)\n {\n val tc = plus[i]!! / 10\n plus[i] = plus[i]!! % 10\n //println(\"Set %d to %d\".format(i+1, plus[i+1]!! + 1))\n plus[i+1] = plus[i+1]!! + tc\n minus[0] = minus[0]!!+1\n i = i+1\n continue\n }\n else if (minus[i]!! >= 10)\n {\n val tc = minus[i]!! / 10\n minus[i] = minus[i]!! % 10\n minus[i+1] = minus[i+1]!! + tc\n plus[0] =plus[0]!!+1\n i = i+1\n continue\n }\n \n if (plus[i]!! > 0 && i != l)\n {\n val curcnt = plus[i]!! * (i+1) \n \n var possible = (i + 2) + 1 + (i+1) + ( 9 - plus[i]!!) * (i+1)\n \n if (minus[i+1]!! > 0)\n {\n possible -= 2 * (i+2)\n }\n if (plus[0]!! > 0 && i > 0)\n {\n possible -= 2 \n }\n if (possible < curcnt)\n {\n // println(possible)\n \n plus[i+1]= plus[i+1]!! + 1 \n minus[i] = 10 - plus[i]!!\n minus[0] = minus[0]!!+1\n plus[i] = 0\n i = i + 1 \n continue\n }\n } \n if (minus[i]!! > 0 && i != l)\n {\n val curcnt = minus[i]!! * (i+1)\n var possible = (i + 2) + 1 + (i+1) + ( 9 - minus[i]!!) * (i+1)\n\n if (plus[i+1]!! > 0)\n {\n possible -= 2 * (i+2)\n }\n if (minus[0]!! > 0 && i > 0)\n {\n possible -= 2 \n }\n if (possible < curcnt)\n {\n minus[i+1]= minus[i+1]!! + 1 \n plus[i] = 10 - minus[i]!!\n plus[0] = plus[0]!!+1\n minus[i] = 0\n i = i + 1 \n continue\n }\n } \n // println(\"decrement\")\n i = i -1 \n }\n var ret =0\n for(j in 0..l)\n {\n ret+=plus[j]!! *(j + 1)\n ret+=minus[j]!! *(j + 1)\n \n }\n println(ret)\n //println(plus)\n //println(minus)\n}\n\n// main()\n//println(-2 % 10)\n"}, {"source_code": "import kotlin.math.*\n\nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of ints\nfun readLong() = readLn().toLong() // list of strings\n\nfun getLength(_n:Long):Int{\n var n = _n\n if (n == 0L)\n return 0\n var ret = 0\n while(n > 0L)\n {\n ret++\n n = n / 10\n }\n return ret\n}\n\nfun pow10(pow:Int):Long{\n var ret = 1L\n for(i in 1..pow)\n ret = ret*10\n return ret\n}\n\nfun main() {\n var n = readLong()\n val l = getLength(n)\n \n \n var prev = 0\n\n val minus = mutableMapOf()\n val plus = mutableMapOf()\n\n for(i in l-1 downTo 0)\n {\n \n val cur = ((n / pow10(i)) % 10).toInt()\n plus.set(i, 0)\n minus.set(i, 0)\n if (cur >= prev)\n {\n plus[i] =plus[i]!! + cur - prev\n }\n else\n {\n minus[i] =minus[i]!! + prev - cur\n }\n prev = cur\n }\n plus.set(l, 0)\n minus.set(l, 0)\n\n \n var i = l -1\n\n while(i >= 0)\n {\n //println(\"i = %d\".format(i))\n //println(\"----\")\n //println(plus)\n //println(minus)\n if (plus[i]!! > 0 && minus[i]!! > 0)\n {\n val minv = min(plus[i]!!, minus[i]!!)\n plus[i] = plus[i]!! - minv\n minus[i] = minus[i]!! - minv\n }\n if (plus[i]!! >= 10)\n {\n val tc = plus[i]!! / 10\n plus[i] = plus[i]!! % 10\n //println(\"Set %d to %d\".format(i+1, plus[i+1]!! + 1))\n plus[i+1] = plus[i+1]!! + tc\n minus[0] = minus[0]!!+1\n i = i+1\n continue\n }\n else if (minus[i]!! >= 10)\n {\n val tc = minus[i]!! / 10\n minus[i] = minus[i]!! % 10\n minus[i+1] = minus[i+1]!! + tc\n plus[0] =plus[0]!!+1\n i = i+1\n continue\n }\n \n if (plus[i]!! > 0 && i != l)\n {\n val curcnt = plus[i]!! * (i+1) \n \n var possible = (i + 2) + 1 + (i+1) + ( 9 - plus[i]!!) * (i+1)\n \n if (minus[i+1]!! > 0)\n {\n possible -= 2 * (i+2)\n }\n if (plus[0]!! > 0 && i > 0)\n {\n possible -= 2 \n }\n if (possible <= curcnt)\n {\n println(possible)\n \n plus[i+1]= plus[i+1]!! + 1 \n minus[i] = 10 - plus[i]!!\n minus[0] = minus[0]!!+1\n plus[i] = 0\n i = i + 1 \n continue\n }\n } \n if (minus[i]!! > 0 && i != l)\n {\n val curcnt = minus[i]!! * (i+1)\n var possible = (i + 2) + 1 + (i+1) + ( 9 - minus[i]!!) * (i+1)\n\n if (plus[i+1]!! > 0)\n {\n possible -= 2 * (i+2)\n }\n if (minus[0]!! > 0 && i > 0)\n {\n possible -= 2 \n }\n if (possible <= curcnt)\n {\n minus[i+1]= minus[i+1]!! + 1 \n plus[i] = 10 - minus[i]!!\n plus[0] = plus[0]!!+1\n minus[i] = 0\n i = i + 1 \n continue\n }\n } \n println(\"decrement\")\n i = i -1 \n }\n var ret =0\n for(j in 0..l)\n {\n ret+=plus[j]!! *(j + 1)\n ret+=minus[j]!! *(j + 1)\n \n }\n println(ret)\n println(plus)\n println(minus)\n}"}, {"source_code": "import kotlin.math.min\n\nfun main(args: Array) {\n val n = readLine()!!.toLong()\n println(f(n))\n}\n\nprivate fun f(n: Long): Long {\n if (n == 0L) return 0\n val len = n.toString().length\n val number = \"1\".repeat(len).toLong()\n val lower = n / number\n val n1 = n - lower * number\n val n2 = (lower + 1) * number - n\n val n3 = number * 10 + 1 - n\n var res = Long.MAX_VALUE\n if (n1 < n) {\n res = min(res, f(n1) + lower * len)\n }\n if (n3 < n) {\n res = min(res, f(n3) + lower + 1)\n }\n if (n2 < n && (lower + 1) * len < res) {\n res = min(res, f(n2) + (lower + 1) * len)\n }\n return res\n}"}, {"source_code": "import java.util.*\n\n\nvar a = LongArray(18)\nvar res = 100000000000000000L\nfun dfs(n_now: Long, pre: Int, total: Long) {\n if (pre == 0) {\n if (res > total) res = total\n return\n }\n if (n_now >= 0) {\n dfs(n_now - n_now / a[pre] * a[pre], pre - 1, total + n_now / a[pre] * pre)\n dfs(n_now - (n_now / a[pre] + 1) * a[pre], pre - 1, total + (n_now / a[pre] + 1) * pre)\n } else {\n val temp = -n_now / a[pre]\n dfs(n_now + n_now / a[pre] * a[pre], pre - 1, total + n_now / a[pre] * pre)\n dfs(n_now + (n_now / a[pre] + 1) * a[pre], pre - 1, total + (n_now / a[pre] + 1) * pre)\n }\n}\n\nfun main(args: Array) {\n a[1] = 1\n for (i in 2..16)\n a[i] = a[i - 1] * 10 + 1\n val cin = Scanner(System.`in`)\n var n = cin.nextLong()\n dfs(n, 16, 0)\n System.out.print(res)\n}"}, {"source_code": "import kotlin.math.absoluteValue\n\n\nfun power(base: Long, exp: Int): Long {\n return when(exp){\n 0 -> 1L\n 1 -> base\n else -> power(base * base, exp / 2) * power(base, exp % 2)\n }\n}\nfun calMin(value: Long, digit: Int, base: Long): Long {\n return when(digit){\n 1 -> value.absoluteValue\n else -> {\n val b = value / base\n (b .. b + 1).map{calMin(value - it * base, digit - 1, base / 10) + digit * it.absoluteValue}.min()!!\n }\n }\n}\nfun main(args: Array?): Unit {\n println(calMin(readLine()!!.trim().toLong(), 15, power(10L, 15) / 9))\n}"}, {"source_code": "import kotlin.math.absoluteValue\n\n\nfun power(base: Long, exp: Int): Long {\n return when(exp){\n 0 -> 1L\n 1 -> base\n else -> power(base * base, exp / 2) * power(base, exp % 2)\n }\n}\nfun calMin(value: Long, digit: Int): Long {\n return when(digit){\n 1 -> value.absoluteValue\n else -> {\n val base = value / power(10L, digit - 1)\n (-1 .. 0).map{calMin(value - power(10L, digit) / 9 * (base + it), digit - 1) + (base + it).absoluteValue * digit}.min()!!\n }\n }\n}\nfun main(args: Array?): Unit {\n println(calMin(readLine()!!.trim().toLong(), 15))\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.absoluteValue\n\nfun Long.digit(): Int {\n return when(this) {\n 0L -> 0\n else -> 1 + (this / 10).digit()\n }\n}\nfun ones(digit: Int): Long {\n return when(digit){\n 1 -> 1L\n else -> ones(digit - 1) * 10 + 1\n }\n}\n\nfun main(args: Array?): Unit {\n var n = readLine()!!.trim().toLong()\n var sumDigit = 0\n while (n != 0L) {\n if (n > 0) {\n val d = n.digit()\n n -= ones(d)\n sumDigit += d\n }else {\n val d = n.absoluteValue.digit()\n n += ones(d)\n sumDigit += d\n }\n }\n println(sumDigit)\n}"}, {"source_code": "import kotlin.math.absoluteValue\nimport kotlin.random.Random\n\n\nfun power(base: Long, exp: Int): Long {\n return when(exp){\n 0 -> 1L\n 1 -> base\n else -> power(base * base, exp / 2) * power(base, exp % 2)\n }\n}\nfun calMin(value: Long, digit: Int, base: Long): Long {\n return when(digit){\n 1 -> value.absoluteValue\n else -> {\n val b = value / base\n (b .. b + 1).map{calMin(value - it * base, digit - 1, base / 10) + digit * it.absoluteValue}.min()!!\n }\n }\n}\nfun calMin2(value: Long, digit: Int, base: Long): Long {\n return when(digit){\n 1 -> value.absoluteValue\n else -> {\n (-10 .. 10).map{calMin(value - it * base, digit - 1, base / 10) + digit * it.absoluteValue}.min()!!\n }\n }\n}\nconst val digit = 15\nfun calMin(value: Long): Long = calMin(value, digit + 1, power(10L, digit + 1) / 9)\nfun calMin2(value: Long): Long = calMin2(value, digit + 1, power(10L, digit + 1) / 9)\nfun main(args: Array?): Unit {\n println(calMin(readLine()!!.trim().toLong()))\n}"}, {"source_code": "import java.lang.Math.*\nimport java.util.*\n\n/**\n * Created by Administrator on 9/2/2019.\n */\n\n// for (i in 1..n) {}\n// for (i in 5 downTo 1)\n// for (i in 1..5 step 2)\n// println(n)\n// println(\"${ansList.size} $ans\")\n// val freq = mutableMapOf()\n// var places = mutableListOf()\n// class Place(val x: Int, val b: Int)\n// teams.sortWith(compareBy({it.size}));\n// val pq = PriorityQueue(Comparator{a1, a2 -> a2.money - a1.money})\n// var size = IntArray(402){0}\n// var dp = Array(402, {IntArray(402)})\n// var adj = MutableList>(402) {_ -> mutableListOf()}\n// println(Arrays.toString(array))\n// println(Arrays.deepToString(array))\n// Pair\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of Longs\n\nvar dp = Array(17, {Array(36, {Array(36, {Array(32, {1000000})})})})\nvar S = \"\"\n\nfun DP(at: Int, pos: Int, neg: Int, bc: Int): Int {\n if (at == 16) {\n if (bc == 0) return 0\n return 1000000\n }\n if (dp[at][pos][neg][bc + 16] != 1000000) {\n return dp[at][pos][neg][bc + 16]\n }\n dp[at][pos][neg][bc + 16] = 999999\n if (pos > 0) {\n var cur = DP(at, pos - 1, neg, bc)\n if (cur < dp[at][pos][neg][bc + 16]) dp[at][pos][neg][bc + 16] = cur\n }\n if (neg > 0) {\n var cur = DP(at, pos, neg - 1, bc)\n if (cur < dp[at][pos][neg][bc + 16]) dp[at][pos][neg][bc + 16] = cur\n }\n val now = bc + pos - neg\n var new_carry = 0\n if (now >= 0) new_carry = now / 10\n var new_borrow = 0\n if (now < 0) new_borrow = -((-now + 9) / 10)\n var last_degit = 0\n if (now >= 0) last_degit=now % 10\n else last_degit = (10 - (-now % 10)) % 10\n var expected = 0\n if (at < S.length) expected = (S[at] - '0').toInt()\n if (last_degit != expected) {\n return dp[at][pos][neg][bc + 16]\n }\n var cur = DP(at + 1, pos, neg, new_carry + new_borrow) + pos + neg\n if (cur < dp[at][pos][neg][bc + 16]) dp[at][pos][neg][bc + 16] = cur\n return dp[at][pos][neg][bc + 16]\n}\n\nfun main(args: Array) {\n S = readLn()\n S = S.reversed()\n var ans = 30000\n for (pos in 0..35) for (neg in 0..35) {\n if (pos == 1)\n ans = max(ans, 0)\n val cur = DP(0, pos, neg, 0)\n if (cur < ans) ans = cur\n //if (cur == 224) println(\"$pos $neg\")\n }\n println(ans)\n}\n"}, {"source_code": "import java.io.*\nimport java.lang.Math.abs\nimport java.util.*\nimport java.util.Arrays.sort\n\nfun main(args: Array){\n val s = readLine()\n val n = s!!.length\n val a = IntArray(n)\n for (i in 0..n - 1) a[i] = (s[i] - '0')\n var ans = 0\n for (i in 0..n - 1){\n val d = a[i]\n for (j in i..n - 1){\n a[j] -= d\n ans += abs(d)\n }\n }\n println(ans)\n}"}, {"source_code": "import java.io.*\nimport kotlin.math.*\nimport kotlin.collections.*\n\nfun main() = bufferOut { readSolveWrite() }\n\nprivate fun PrintWriter.readSolveWrite() {\n val s = readLine()!!.map{it.toInt() - 48}.toIntArray()\n val n = s.size\n var ans = 0\n for (i in 0..n - 1)\n if (s[i] != 0) {\n ans += (n - i) * abs(s[i])\n for (j in i + 1..n - 1)\n s[j] -= s[i]\n }\n println(ans)\n}\n\nprivate fun ok(x: Boolean) = if (x) 1 else 0// {{{\n\nprivate fun getIntArray() = readLine()!!.splitToIntArray()\n\nprivate fun bufferOut(block: PrintWriter.() -> Unit) = PrintWriter(System.out).use { block(it) }\n\ndata class Pt(val x: Int, val y: Int, val i: Int, var ans: Int)\n\nprivate fun String.splitToIntArray(): IntArray {\n val n = length\n if (n == 0) return IntArray(0) // EMPTY\n var res = IntArray(4)\n var m = 0\n var i = 0\n while (true) {\n var cur = 0\n var neg = false\n var c = get(i) // expecting number, IOOB if there is no number\n if (c == '-') {\n neg = true\n i++\n c = get(i) // expecting number, IOOB if there is no number\n }\n while (true) {\n val d = c.toInt() - '0'.toInt()\n require(d in 0..9) { \"Unexpected character '$c' at $i\" }\n require(cur >= Integer.MIN_VALUE / 10) { \"Overflow at $i\" }\n cur = cur * 10 - d\n require(cur <= 0) { \"Overflow at $i\" }\n i++\n if (i >= n) break\n c = get(i)\n if (c == ' ') break\n }\n if (m >= res.size) res = res.copyOf(res.size * 2)\n res[m++] = if (neg) cur else (-cur).also { require(it >= 0) { \"Overflow at $i\" } }\n if (i >= n) break\n i++\n }\n if (m < res.size) res = res.copyOf(m)\n return res\n}// }}}\n"}, {"source_code": "import java.io.OutputStream\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.PrintWriter\nimport java.util.Scanner\nimport kotlin.math.min\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author maxkibble\n */\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val `in` = Scanner(inputStream)\n val out = PrintWriter(outputStream)\n solve(1, `in`, out)\n out.close()\n}\n\nfun lower(x: Long): Long {\n var ret: Long = 1\n while (x >= ret) {\n ret = ret * 10 + 1\n }\n ret = (ret - 1) / 10\n return ret\n}\n\nfun f(x: Long, y: Long): Long {\n if (x == 0L) return 0\n val l = lower(x)\n val u = l * 10 + 1\n var a = l.toString().length * 1L\n val b = a + 1\n a = x / l * a + f(x % l, l)\n if (u < y) a = min(a, b + f(u - x, u))\n return a\n}\n\nfun solve(testNumber: Int, `in`: Scanner, out: PrintWriter) {\n val n = `in`.nextLong()\n out.println(f(n, 1111111111111111L))\n}\n\n\n"}, {"source_code": "import kotlin.math.*\nfun main(args: Array) {\n var x = \"0\".plus(readLine()!!).toCharArray()\n var xx: Array = x.map{it.toInt()-'0'.toInt()}.toTypedArray() \n val n = x.size\n var sum =0\nfor(i in n-1 downTo 1 ) {xx[i]-=xx[i-1];sum+=abs(xx[i]*(n-i));}\n//for(d in xx)print(\"$d \")\n//println(\"$sum\")\nfor(i in n-1 downTo 1 ) if((xx[0]>6)||(i>0&&xx[i]>=6)){xx[i-1]++;xx[i]=xx[i]-10;xx[n-1]--;}\nfor(i in n-1 downTo 1 ) if((xx[0]<-6)||(i>0&&xx[i]<=-6)){xx[i-1]--;xx[i]=xx[i]+10;xx[n-1]++;}\nsum=0\nfor(i in n-1 downTo 0 ) {sum+=abs(xx[i]*(n-i));}\nvar xxx=1L\nvar xxxx=0L\nfor(i in n-1 downTo 0 ){xxxx+=xx[i]*xxx;xxx=xxx*10+1;} \n//println(\"$xxxx\")\n//for(d in xx)print(\"$d \")\nprintln(\"$sum\")\n}"}, {"source_code": "import kotlin.math.*\nfun main(args: Array) {\n var x = \"0\".plus(readLine()!!).toCharArray()\n var xx: Array = x.map{it.toInt()-'0'.toInt()}.toTypedArray() \n val n = x.size\n var sum = 0\n var sum1 =0\nfor(i in n-1 downTo 1 ) {xx[i]-=xx[i-1];sum1+=abs(xx[i]*(n-i));}\nwhile (sum!=sum1) {\nsum1=sum\n//for(d in xx)print(\"$d \")\n//println(\"$sum\")\nfor(i in n-1 downTo 1 ) if((xx[n-1]>6)||(i=6)){xx[i-1]++;xx[i]=xx[i]-10;xx[n-1]--;}\nfor(i in n-1 downTo 1 ) if((xx[n-1]<-6)||(i) {\n var x = \"0\".plus(readLine()!!).toCharArray()\n var xx: Array = x.map{it.toInt()-'0'.toInt()}.toTypedArray() \n val n = x.size\n var sum =0\nfor(i in n-1 downTo 1 ) {xx[i]-=xx[i-1];sum+=abs(xx[i]*(n-i));}\nfor(i in n-1 downTo 1 ) if(xx[i]>=6){xx[i-1]++;xx[i]=xx[i]-10;xx[n-1]--;}\nfor(i in n-1 downTo 1 ) if(xx[i]<=-6){xx[i-1]--;xx[i]=xx[i]+10;xx[n-1]++;}\nsum=0\nfor(i in n-1 downTo 0 ) {sum+=abs(xx[i]*(n-i));}\nvar xxx=1L\nvar xxxx=0L\nfor(i in n-1 downTo 0 ){xxxx+=xx[i]*xxx;xxx=xxx*10+1;} \n//println(\"$xxxx\")\n//for(d in xx)print(\"$d \")\nprintln(\"$sum\")\n}"}, {"source_code": "import kotlin.math.*\nfun main(args: Array) {\n var x = \"0\".plus(readLine()!!).toCharArray()\n var xx: Array = x.map{it.toInt()-'0'.toInt()}.toTypedArray() \n val n = x.size\n var sum =0\nfor(i in n-1 downTo 1 ) {xx[i]-=xx[i-1];sum+=abs(xx[i]*(n-i));}\nfor(i in n-1 downTo 1 ) if(xx[i]>=6){xx[i-1]++;xx[i]=xx[i]-10;xx[n-1]--;}\nfor(i in n-1 downTo 1 ) if(xx[i]<=-6){xx[i-1]--;xx[i]=xx[i]+10;xx[n-1]++;}\nfor(i in n-1 downTo 1 ) if(xx[i]>=6){xx[i-1]++;xx[i]=xx[i]-10;xx[n-1]--;}\nfor(i in n-1 downTo 1 ) if(xx[i]<=-6){xx[i-1]--;xx[i]=xx[i]+10;xx[n-1]++;}\nsum=0\nfor(i in n-1 downTo 0 ) {sum+=abs(xx[i]*(n-i));}\nvar xxx=1L\nvar xxxx=0L\n//for(i in n-1 downTo 0 ){xxxx+=xx[i]*xxx;xxx=xxx*10+1;}\n//for(d in xx)print(\"$d \")\nprintln(\"$sum\")\n}"}, {"source_code": "import kotlin.math.*\nfun main(args: Array) {\n var x = \"0\".plus(readLine()!!).toCharArray()\n var xx: Array = x.map{it.toInt()-'0'.toInt()}.toTypedArray() \n val n = x.size\n var sum =0\nfor(i in n-1 downTo 1 ) {xx[i]-=xx[i-1];sum+=abs(xx[i]*(n-i));}\n//for(d in xx)print(\"$d \")\n//println(\"$sum\")\nfor(i in n-1 downTo 1 ) if((xx[n-1]>6)||(i=6)){xx[i-1]++;xx[i]=xx[i]-10;xx[n-1]--;}\nfor(i in n-1 downTo 1 ) if((xx[n-1]<-6)||(i) {\n var x = \"0\".plus(readLine()!!).toCharArray()\n var xx: Array = x.map{it.toInt()-'0'.toInt()}.toTypedArray() \n val n = x.size\n var sum =0\n// println(x)\nfor(i in n-1 downTo 1 ) {xx[i]-=xx[i-1];sum+=abs(xx[i]*(n-i));}\n//for(d in xx)print(\"$d \")\n//println(\"sum=$sum \")\nfor(i in n-1 downTo 1 ) if(xx[i]>=6){xx[i-1]++;xx[i]=xx[i]-10;xx[n-1]--;}\nsum=0\nfor(i in n-1 downTo 0 ) {sum+=abs(xx[i]*(n-i));}\n//for(d in xx)print(\"$d \")\nprintln(\"$sum \")\n}"}, {"source_code": "fun readLn(): String = readLine()!!\nfun readInt(): Int = readLn().toInt()\nfun readInts(): MutableList = readLn().split(\" \").map { it.toInt() }.toMutableList()\nfun readLong(): Long = readLn().toLong()\n\nval results = mutableMapOf(0L to 0)\n\nfun preprocess() {\n val MAX = 1e16\n var x = 1L\n var ones = 1\n while (x < MAX) {\n results[x] = ones\n x = 10 * x + 1\n ones++\n }\n}\n\nfun firstSmallerOnes(number: Long): Pair {\n var x = 1L\n var ones = 1\n while (x < number) {\n x = 10 * x + 1\n ones++\n }\n x /= 10\n ones--\n return Pair(x, ones)\n}\n\nfun solve(number: Long): Int {\n if (number in results) return results[number]!!\n val (smallerOnes, ones) = firstSmallerOnes(number)\n\n val quotient = (number / smallerOnes).toInt()\n val remainder = number % smallerOnes\n var result = ones * quotient + solve(remainder)\n // println(\"$number $quotient $smallerOnes $remainder $result\")\n // results[number] = result\n\n val largerOnes = smallerOnes * 10 + 1\n val ones1 = ones + 1\n val quotient2 = (largerOnes / number).toInt()\n val remainder2 = largerOnes % number\n if (remainder2 < number) {\n result = Math.min(ones1 * quotient2 + solve(remainder2), result)\n results[number] = result\n }\n\n results[number] = result\n return result\n}\n\nfun main(args: Array) {\n preprocess()\n val number = readLong()\n println(solve(number))\n}\n\n"}, {"source_code": "fun readLn(): String = readLine()!!\nfun readInt(): Int = readLn().toInt()\nfun readInts(): MutableList = readLn().split(\" \").map { it.toInt() }.toMutableList()\nfun readLong(): Long = readLn().toLong()\n\nval results = mutableMapOf(0L to 0L)\n\nfun preprocess() {\n val MAX = 1e17\n var x = 1L\n var ones = 1L\n while (x < MAX) {\n results[x] = ones\n x = 10 * x + 1\n ones++\n }\n}\n\nfun firstSmallerOnes(number: Long): Pair {\n var x = 1L\n var ones = 1L\n while (x < number) {\n x = 10 * x + 1\n ones++\n }\n x /= 10\n ones--\n return Pair(x, ones)\n}\n\nfun solve(number: Long): Long {\n if (number in results) return results[number]!!\n val (smallerOnes, ones) = firstSmallerOnes(number)\n\n val quotient = number / smallerOnes\n val remainder = number % smallerOnes\n var result = ones * quotient + solve(remainder)\n // println(\"$number $quotient $smallerOnes $remainder $result\")\n // results[number] = result\n\n val largerOnes = smallerOnes * 10 + 1\n val ones1 = ones + 1\n val quotient2 = largerOnes / number\n val remainder2 = largerOnes % number\n if (remainder2 < number) {\n result = Math.min(ones1 * quotient2 + solve(remainder2), result)\n }\n\n results[number] = result\n return result\n}\n\nfun main(args: Array) {\n preprocess()\n val number = readLong()\n println(solve(number))\n}\n\n"}, {"source_code": "import java.util.*\nimport kotlin.math.min\n\nvar oneList = mutableListOf(0)\nvar problemResult = Int.MAX_VALUE\n\nfun main() {\n val read = Scanner(System.`in`)\n var start = 0L\n for (i in 1..16) {\n start = start * 10 + 1\n oneList.add(start)\n }\n val n = read.nextLong()\n dfs(getLength(n), n, 0)\n println(problemResult)\n}\n\n\n\nfun dfs(length : Int, num : Long, ans : Int) {\n if (length == 0) {\n problemResult = min(problemResult, ans)\n return\n }\n if (ans > problemResult) {\n return\n }\n if (num == oneList[length]) {\n val times = num.div(oneList[length])\n val ansNow = ans + length * times.toInt()\n dfs(0, 0, ansNow)\n } else {\n val times = num.div(oneList[length])\n val numNow = num - times * oneList[length]\n val ansNow = ans + length * times.toInt()\n dfs(length - 1, numNow, ansNow)\n dfs(length - 1, oneList[length] - numNow, ansNow + length)\n }\n}\nfun getLength(num: Long) : Int {\n var a = num\n var result = 0\n while (a > 0) {\n a /= 10\n result++\n }\n return result\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.math.min\n\nvar oneList = mutableListOf(0)\nvar problemResult = Int.MAX_VALUE\n\nfun main() {\n val read = Scanner(System.`in`)\n var start = 0L\n for (i in 1..16) {\n start = start * 10 + 1\n oneList.add(start)\n }\n val n = read.nextLong()\n dfs(getLength(n), n, 0)\n println(problemResult)\n}\n\n\n\nfun dfs(length : Int, num : Long, ans : Int) {\n if (length == 0) {\n problemResult = min(problemResult, ans)\n return\n }\n if (ans > problemResult) {\n return\n }\n if (num % oneList[length] == 0L) {\n val times = num.div(oneList[length])\n val ansNow = ans + length * times.toInt()\n dfs(0, 0, ansNow)\n } else {\n val times = num.div(oneList[length])\n val numNow = num - times * oneList[length]\n val ansNow = ans + length * times.toInt()\n dfs(length - 1, numNow, ansNow)\n dfs(length - 1, oneList[length] - numNow, ansNow + length)\n }\n}\nfun getLength(num: Long) : Int {\n var a = num\n var result = 0\n while (a > 0) {\n a /= 10\n result++\n }\n return result\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.math.min\n\nvar oneList = mutableListOf(0)\nvar problemResult = Int.MAX_VALUE\n\nfun main() {\n val read = Scanner(System.`in`)\n var start = 0L\n for (i in 1..15) {\n start = start * 10 + 1\n oneList.add(start)\n }\n val n = read.nextLong()\n dfs(getLength(n), n, 0)\n println(problemResult)\n}\n\n\n\nfun dfs(length : Int, num : Long, ans : Int) {\n if (length == 0) {\n problemResult = min(problemResult, ans)\n return\n }\n if (ans > problemResult) {\n return\n }\n if (num % oneList[length] == 0L) {\n val times = num.div(oneList[length])\n val ansNow = ans + length * times.toInt()\n dfs(0, 0, ansNow)\n } else {\n val times = num.div(oneList[length])\n val numNow = num - times * oneList[length]\n val ansNow = ans + length * times.toInt()\n dfs(length - 1, numNow, ansNow)\n dfs(length - 1, oneList[length] - numNow, ansNow + length)\n }\n}\nfun getLength(num: Long) : Int {\n var a = num\n var result = 0\n while (a > 0) {\n a /= 10\n result++\n }\n return result\n}\n"}, {"source_code": "import java.util.*\n\nval maxn = 200010\n\nfun next() = readLine()!!\nfun nextInt() = next().toInt()\nfun nextInts() = next().split(\" \").map { it.toInt() }\nfun nextLongs() = next().split(\" \").map { it.toLong() }\n\nval v = ArrayList()\n\n\nfun init(){\n var t : Long = 0\n for(i in 1..17){\n t *= 10\n t++\n v.add(t)\n }\n}\n\nfun solve(x : Long) : Long{\n\n if(x == 0.toLong())return 0\n\n var pos : Int = -1\n var ans : Long = x\n for(i in 0..16){\n if(v[i] > x){\n break\n }\n pos = i\n }\n\n\n\n if((v[pos+1] - x) < (x-v[pos])){\n ans = minOf(ans,solve(v[pos+1]-x) + pos + 2)\n }\n else {\n ans = minOf(ans,solve(x-v[pos]) + pos + 1)\n }\n return ans\n}\nfun main(argumento: Array){\n\n init()\n\n var n = readLine()!!.toLong()\n\n print(solve(n))\n\n\n}\n"}, {"source_code": "import java.io.PrintWriter\nimport java.lang.Math.abs\nimport java.lang.Math.min\n\nval pw = PrintWriter(System.out)\nfun main(args: Array) {\n var INF = 1000000000000000L\n var n = nextLong()\n var vs = mutableListOf(1L)\n repeat(15){\n vs.add(vs.get(it)*10+1)\n }\n var dp = mapOf(Pair(n,0L))\n var re = n;\n repeat(100){\n// dp.forEach { t, u -> print(\"${t} ${u}\\n\")}\n// println(\"\")\n var nxt = mutableMapOf()\n var upd = { key:Long, value:Long ->\n var cur = nxt.getOrDefault(key, INF)\n nxt.put(key, min(cur, value))\n }\n dp.forEach { n_, c ->\n var n = abs(n_)\n if(n==0L){\n re= min(re, c)\n return@forEach\n }\n var i = n.toString().length-1\n var t=n/vs[i]\n upd(n-t*vs[i], c+(i+1)*t)\n if(n%vs[i]>0) upd((t+1)*vs[i]-n, c+(i+1)*(t+1))\n }\n dp=nxt\n }\n print(re)\n pw.flush()\n}\n\nfun next() = readLine()!!\nfun nextInt() = next().toInt()\nfun nextLong() = next().toLong()\nfun nextDouble() = next().toDouble()\nfun listOfString() = next().split(\" \")\nfun listOfInt() = listOfString().map { it.toInt() }\nfun listOfLong() = listOfString().map { it.toLong() }\nfun listOfDouble() = listOfString().map { it.toDouble() }\n"}, {"source_code": "fun main() {\n val n = readLine()!!\n var balance = 0\n var res = 0\n var cnt = 0\n for (c in n) {\n val g = c.toInt() - '0'.toInt()\n cnt += Math.abs(g - balance)\n res += cnt\n balance = g\n }\n println(res)\n}"}, {"source_code": "fun main() {\n val n = readLine()!!\n var balance = 0\n var res = 0L\n var cnt = 0L\n for (c in n) {\n val g = c.toInt() - '0'.toInt()\n cnt += Math.abs(g - balance)\n res += cnt\n balance = g\n }\n println(res)\n}"}, {"source_code": "import kotlin.math.min\n\nval addends = listOf(\n 0,\n 1L,\n 11L,\n 111L,\n 1_111L,\n 11_111L,\n 111_111L,\n 1_111_111L,\n 11_111_111L,\n 111_111_111L,\n 1_111_111_111L,\n 11_111_111_111L,\n 111_111_111_111L,\n 1_111_111_111_111L,\n 11_111_111_111_111L,\n 111_111_111_111_111L,\n 1_111_111_111_111_111L\n)\n\nfun main() {\n val number = readLine()!!.toLong()\n println(findMinimumDigits(number))\n}\n\nfun findMinimumDigits(number: Long): Int {\n if (number <= 11) return min(number, 13 - number).toInt()\n var i = addends.size - 1\n while (addends[i] >= number) i--\n\n if (i + 1 < addends.size && number == addends[i + 1]) return i + 1\n\n val addendA = addends[i]\n val timesA = number / addendA\n val remainderA = number % addendA\n\n val numberOfDigitsA = if (timesA < 10) (i * timesA + findMinimumDigits(remainderA)).toInt() else Int.MAX_VALUE\n if (i + 1 == addends.size) return numberOfDigitsA\n\n val addendB = if (timesA >= 9L) addends[i + 1] else addends[i]\n val timesB = if (timesA >= 9L) 1L else timesA + 1\n val remainderB = addendB * timesB - number\n\n val numberOfDigitsB = (addendB.toString().length * timesB + findMinimumDigits(remainderB)).toInt()\n\n return min(numberOfDigitsA, numberOfDigitsB)\n}\n"}, {"source_code": "import kotlin.math.min\n\nval addends = listOf(\n 0,\n 1L,\n 11L,\n 111L,\n 1_111L,\n 11_111L,\n 111_111L,\n 1_111_111L,\n 11_111_111L,\n 111_111_111L,\n 1_111_111_111L,\n 11_111_111_111L,\n 111_111_111_111L,\n 1_111_111_111_111L,\n 11_111_111_111_111L,\n 111_111_111_111_111L,\n 1_111_111_111_111_111L\n)\n\nfun main() {\n val number = readLine()!!.toLong()\n println(findMinimumDigits(number))\n}\n\nfun findMinimumDigits(number: Long): Int {\n if (number <= 11) return min(number, 13 - number).toInt()\n var i = addends.size - 1\n while (addends[i] >= number) i--\n\n if (i + 1 < addends.size && number == addends[i + 1]) return i + 1\n\n val addendA = addends[i]\n val timesA = number / addendA\n val remainderA = number % addendA\n\n val numberOfDigitsA = (i * timesA + findMinimumDigits(remainderA)).toInt()\n if (i + 1 == addends.size) return numberOfDigitsA\n\n val addendB = if (timesA == 9L) addends[i + 1] else addends[i]\n val timesB = if (timesA == 9L) 1L else timesA + 1\n val remainderB = addendB * timesB - number\n\n val numberOfDigitsB = (i * timesB + findMinimumDigits(remainderB)).toInt()\n\n return min(numberOfDigitsA, numberOfDigitsB)\n}\n"}, {"source_code": "import kotlin.math.min\n\nval addends = listOf(\n 0,\n 1L,\n 11L,\n 111L,\n 1_111L,\n 11_111L,\n 111_111L,\n 1_111_111L,\n 11_111_111L,\n 111_111_111L,\n 1_111_111_111L,\n 11_111_111_111L,\n 111_111_111_111L,\n 1_111_111_111_111L,\n 11_111_111_111_111L,\n 111_111_111_111_111L,\n 1_111_111_111_111_111L\n)\n\nfun main() {\n val number = readLine()!!.toLong()\n println(findMinimumDigits(number))\n}\n\nfun findMinimumDigits(number: Long): Int {\n println(\"findMinimumDigits($number)\")\n if (number <= 11) return min(number, 13 - number).toInt()\n var i = addends.size - 1\n while (addends[i] >= number) i--\n\n if (i + 1 < addends.size && number == addends[i + 1]) return i + 1\n\n val addendA = addends[i]\n val timesA = number / addendA\n val remainderA = number % addendA\n\n val numberOfDigitsA = if (timesA < 10) (i * timesA + findMinimumDigits(remainderA)).toInt() else Int.MAX_VALUE\n if (i + 1 == addends.size) return numberOfDigitsA\n\n val addendB = if (timesA >= 9L) addends[i + 1] else addends[i]\n val timesB = if (timesA >= 9L) 1L else timesA + 1\n val remainderB = addendB * timesB - number\n\n val numberOfDigitsB = (addendB.toString().length * timesB + findMinimumDigits(remainderB)).toInt()\n\n val numberOfDigitsC = if (timesA >= 9L) {\n Int.MAX_VALUE\n } else {\n val addendC = addends[i + 1]\n val timesC = 1\n val remainderC = addendC * timesC - number\n if (remainderC > number) Int.MAX_VALUE else (i + 1) * timesC + findMinimumDigits(remainderC)\n }\n\n return min(min(numberOfDigitsA, numberOfDigitsB), numberOfDigitsC)\n}"}, {"source_code": "import kotlin.math.absoluteValue\n\nfun main(){\n var n : Long = readLine()!!.toLong()\n var res: Long = 0;\n\n res = calculate(15, n)\n\n println(res)\n}\n\nfun calculate(x: Int, n: Long) : Long{\n var sum : Long = 0\n var divisionNumber : Long = 1\n var div: Long = 0\n if (x != 1) {\n for (i in 1 until x) {\n divisionNumber = divisionNumber * 10 + 1\n }\n div = n/divisionNumber\n sum = if(div == 0.toLong() && n/(divisionNumber/10) == 0.toLong()) {\n 0 + calculate(x-1, n)\n }else {\n var posSum: Long = calculate(x - 1, n - (div * divisionNumber))\n var negSum: Long = calculate(x - 1, (n - ((div + 1) * divisionNumber)).absoluteValue)\n if (posSum <= negSum + x) {\n (div) * (x) + posSum\n } else {\n (div + 1) * (x) + negSum\n }\n }\n }else{\n sum = n.absoluteValue\n }\n println(\"n: $n, x: $x, div: $divisionNumber, n/div: $div, sum: $sum \")\n return sum\n}"}, {"source_code": "import kotlin.math.absoluteValue\n\nfun main(){\n var n : Long = readLine()!!.toLong()\n var res: Long = 0;\n\n res = calculate(14, n)\n\n println(res)\n}\n\nfun calculate(x: Int, n: Long) : Long{\n var sum : Long = 0\n var divisionNumber : Long = 1\n var div: Long = 0\n if (x != 1) {\n for (i in 1 until x) {\n divisionNumber = divisionNumber * 10 + 1\n }\n div = n/divisionNumber\n sum = if(div == 0.toLong() && n/(divisionNumber/10) == 0.toLong()) {\n 0 + calculate(x-1, n)\n }else {\n var posSum: Long = calculate(x - 1, n - (div * divisionNumber))\n var negSum: Long = calculate(x - 1, (n - ((div + 1) * divisionNumber)).absoluteValue)\n if (posSum <= negSum + x) {\n (div) * (x) + posSum\n } else {\n (div + 1) * (x) + negSum\n }\n }\n }else{\n sum = n.absoluteValue\n }\n return sum\n}"}, {"source_code": "import kotlin.math.absoluteValue\n\nfun main(){\n var n : Long = readLine()!!.toLong()\n var res: Long = 0;\n\n res = calculate(15, n)\n\n println(res)\n}\n\nfun calculate(x: Int, n: Long) : Long{\n var sum : Long = 0\n var divisionNumber : Long = 1\n var div: Long = 0\n if (x != 1) {\n for (i in 1 until x) {\n divisionNumber = divisionNumber * 10 + 1\n }\n div = n/divisionNumber\n sum = if(div == 0.toLong() && n/(divisionNumber/10) == 0.toLong()) {\n 0 + calculate(x-1, n)\n }else {\n var posSum: Long = calculate(x - 1, n - (div * divisionNumber))\n var negSum: Long = calculate(x - 1, (n - ((div + 1) * divisionNumber)).absoluteValue)\n if (posSum <= negSum + x) {\n (div) * (x) + posSum\n } else {\n (div + 1) * (x) + negSum\n }\n }\n }else{\n sum = n.absoluteValue\n }\n return sum\n}"}, {"source_code": "import java.util.*\n\nprivate fun readLn(): String = readLine()!!\nprivate fun readInt(): Int = readLn().toInt()\nprivate fun readLong(): Long = readLn().toLong()\nprivate fun readStrings(): List = readLn().split(\" \")\nprivate fun readInts(): List = readStrings().map {it.toInt()}\nprivate fun readLongs(): List = readStrings().map {it.toLong()}\nprivate fun , S: Comparable> pairComparator() = \n compareBy(Pair::first, Pair::second)\nprivate fun , S: Comparable, T: Comparable> tripleComparator() = \n compareBy(Triple::first, Triple::second, Triple::third)\n\n\nfun repUnit(numOnes: Int): Long {\n return (Math.pow(10.0, numOnes.toDouble()).toLong() - 1) / 9;\n}\n\nvar n: Long = 0\n\nfun go(cur: Long, ones: Int): Long {\n if (ones == 0 || cur == n) {\n return 0\n } else if (ones == 1) {\n return Math.abs(n - cur)\n } else {\n val power = repUnit(ones)\n val diff: Long = Math.abs(n - cur)\n val sgn = if (n - cur < 0) -1 else 1\n val hi_mult = (power + diff - 1) / power\n val lo_mult = hi_mult - 1\n return Math.min(\n go(cur + sgn * lo_mult * power, ones - 1) + lo_mult * ones,\n go(cur + sgn * hi_mult * power, ones - 1) + hi_mult * ones\n )\n }\n}\n\nfun main(args: Array) {\n n = readLong()\n var p = 1\n while (repUnit(p + 1) <= n) {\n p++\n }\n var power = repUnit(p)\n var ans = go((n / power) * power, p - 1) + p * (n / power)\n power = repUnit(p + 1)\n ans = Math.min(ans, go(power, p) + p + 1)\n println(ans)\n}"}, {"source_code": "fun main(args: Array) {\n val s = readLine()!!\n var mx = 0\n var ans = 0\n \n var sz = s.length\n \n for(i in 0 until sz){\n ans += Math.abs(mx - (s[i] - '0')) * (sz - i)\n mx = s[i] - '0'\n }\n println(ans)\n}\n"}, {"source_code": "import java.util.*;\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n\tsolve(next());\n//\tfor (i in 1..100) {\n//\t\tprint(i.toString() + \" \");\n//\t\tsolve(i.toString());\n//\t}\n}\n\nfun solve(c: String) {\n\t//var c = next();\n\tvar ans = 0L;\n\tvar a = ArrayList();\n\tfor (i in 0..c.length-1) {\n\t\ta.add(0);\n\t}\n\tfor (i in 0..c.length-1) {\n\t\tvar cur = c[i] - '0';\n\t\tif (cur == a[i]) continue;\n\t\tif (cur < a[i]) {\n\t\t\tfor (j in i..c.length-1) {\n\t\t\t\tans += a[j] - cur;\n\t\t\t\ta[j] = cur;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tfor (j in i..c.length-1) {\n\t\t\t\tans += cur - a[j];\n\t\t\t\ta[j] = cur;\n\t\t\t}\n\t\t}\n\t}\n\tvar cur = 0L;\n\tvar ans2 = 0L;\n\tvar add = 1L;\n\tvar sum = 1L;\n\tvar n = c.toLong();\n\twhile (add * 10 + 1 <= n) {\n\t\tadd = add * 10 + 1;\n\t\tsum++;\n\t}\n\tadd = add * 10 + 1;\n\tsum++;\n\tcur += n / add * add;\n\tans2 += n / add * sum;\n\tif (cur < n) {\n\t\tcur += add;\n\t\tans2+=sum;\n\t}\n\tvar sub = 1L;\n\tvar sum1 = 1L;\n\twhile (cur > n) {\n\t\tvar dif = cur - n;\n\t\twhile (sub * 10 + 1 <= dif) {\n\t\t\tsub = sub * 10 + 1;\n\t\t\tsum1++;\n\t\t}\n\t\twhile (sub > dif) {\n\t\t\tsub = (sub - 1) / 10;\n\t\t\tsum1--;\n\t\t}\n\t\tvar tim = dif / sub;\n\t\tcur -= sub * tim;\n\t\tans2 += sum1 * tim;\n\t}\n\tprint(Math.min(ans, ans2));\n\tprintln();\n}\n"}, {"source_code": "import java.util.*;\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n\tvar n = nextLong();\n\tvar ans = n;\n\tvar sum = 0L;\n\tvar cur = 0L;\n\tvar cnt = 1L;\n\tvar add = 1L;\n\twhile (cur < ans) {\n\t\twhile (cur + add * 10 + 1 > ans) {\n\t\t\tadd = (add - 1) / 10;\n\t\t\tcnt--;\n\t\t}\n\t\twhile (cur + add * 10 + 1 <= ans) {\n\t\t\tadd = add * 10 + 1;\n\t\t\tcnt++;\n\t\t}\n\t\tsum += cnt;\n\t\tcur += add;\n\t}\n\tans = Math.min(ans, sum);\n\tvar ad2 = 1L;\n\tvar cnt2 = 1L;\n\tvar ad3 = 1L;\n\tvar cnt3 = 1L;\n\twhile (ad2 * 10 + 1<= n) {\n\t\tad2 = ad2 * 10 + 1;\n\t\tcnt2++;\n\t\tad3 = ad3 * 10 + 1;\n\t\tcnt3++;\n\t}\n\tif (ad2 > 1) {\n\t\tad3 = (ad3 - 1) / 10;\n\t\tcnt3--;\n\t}\n\tsum = cnt2 + cnt3;\n\tcur = ad2 + ad3;\n\twhile (cur > n) {\n\t\tvar nn = cur - n;\n\t\tvar sub = 1L;\n\t\tvar cnt4 = 1L;\n\t\twhile (nn - (sub * 10 + 1) >= 0) {\n\t\t\tcnt4++;\n\t\t\tsub = sub * 10 + 1;\n\t\t}\n\t\tcur -= sub;\n\t\tsum += cnt4;\n\t}\n\tans = Math.min(ans, sum);\n\tprint(ans);\n}"}, {"source_code": "import java.util.*;\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n\tvar c = next();\n\tvar ans = 0L;\n\tvar a = ArrayList();\n\tfor (i in 0..c.length-1) {\n\t\ta.add(0);\n\t}\n\tfor (i in 0..c.length-1) {\n\t\tvar cur = c[i] - '0';\n\t\tif (cur == a[i]) continue;\n\t\tif (cur < a[i]) {\n\t\t\tfor (j in i..c.length-1) {\n\t\t\t\tans += a[j] - cur;\n\t\t\t\ta[j] = cur;\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tfor (j in i..c.length-1) {\n\t\t\t\tans += cur - a[j];\n\t\t\t\ta[j] = cur;\n\t\t\t}\n\t\t}\n\t}\n\t\n\tprint(ans);\n}\n\nfun solve(n: Long) {\n\tvar ans = n;\n\tvar sum = 0L;\n\tvar cur = 0L;\n\tvar cnt = 1L;\n\tvar add = 1L;\n\twhile (cur < n) {\n\t\twhile (cur + add * 10 + 1 > n) {\n\t\t\tadd = (add - 1) / 10;\n\t\t\tcnt--;\n\t\t}\n\t\twhile (cur + add * 10 + 1 <= n) {\n\t\t\tadd = add * 10 + 1;\n\t\t\tcnt++;\n\t\t}\n\t\tvar tim = (n - cur) / add;\n\t\tsum += cnt * tim;\n\t\tcur += add * tim;\n\t}\n\tans = Math.min(ans, sum);\n\t\n\tvar ad2 = 1L;\n\tvar cnt2 = 1L;\n\tvar ad3 = 1L;\n\tvar cnt3 = 1L;\n\twhile (ad2 * 10 + 1 <= n) {\n\t\tad2 = ad2 * 10 + 1;\n\t\tcnt2++;\n\t\tad3 = ad3 * 10 + 1;\n\t\tcnt3++;\n\t}\n\tad2 = ad2 * 10 + 1;\n\tcnt2++;\n\tad3 = ad3 * 10 + 1;\n\tcnt3++;\n\tif (ad2 > 1) {\n\t\tad3 = (ad3 - 1) / 10;\n\t\tcnt3--;\n\t}\n\tsum = 0L;\n\tcur = 0L;\n\twhile (cur < n) {\n\t\tcur += ad2;\n\t\tsum += cnt2;\n\t}\n\tif (cur != n) {\n\t\tcur += ad3;\n\t\tsum += cnt3;\n\t}\n\t//print(cnt2);\n\twhile (cur > n) {\n\t\tvar nn = cur - n;\n\t\tvar sub = 1L;\n\t\tvar cnt4 = 1L;\n\t\twhile (nn - (sub * 10 + 1) >= 0) {\n\t\t\tcnt4++;\n\t\t\tsub = sub * 10 + 1;\n\t\t}\n\n\t\tvar tim = (cur - n) / add;\n\t\t\n\t\tcur -= sub * tim;\n\t\tsum += cnt4 * tim;\n\t}\n\tans = Math.min(ans, sum);\n\tprint(ans);\n}"}, {"source_code": "fun Int.digitsCount() = toString().length\n\nfun Int.repeat(n: Int) = toString().repeat(n).toInt()\n\nfun main() {\n val n = readLine()!!.toInt()\n var number = n\n var ones = 0\n// var count = 0\n while (true) {\n// count++\n val digits = number.digitsCount()\n val onesNumber = 1.repeat(digits)\n val rem = number%onesNumber\n val quo = number/onesNumber\n// print(number, onesNumber, rem, quo, ones)\n if (rem.digitsCount() == digits) {\n number = onesNumber - rem\n ones += quo*digits + digits\n } else {\n number = rem\n ones += quo*digits\n }\n if (number.digitsCount() == 1) {\n ones += number\n break\n }\n// if (count == 50) break\n }\n println(ones)\n// println(count)\n}"}, {"source_code": "import kotlin.math.*\n \nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of ints\nfun readLong() = readLn().toLong() // list of strings\n \nfun getLength(_n:Long):Int{\n var n = _n\n if (n == 0L)\n return 0\n var ret = 0\n while(n > 0L)\n {\n ret++\n n = n / 10\n }\n return ret\n}\n \nfun get1(_l:Int):Long{\n var n = _l\n if (n == 0)\n return 1\n var ret = 1L\n while(n > 1)\n {\n ret=1 + ret * 10\n n--\n }\n return ret\n}\n \n \nfun main() {\n val n =readLong()\n val res = getCount(n, getLength(n) + 1 )\n println(res)\n println(get1Count(res))\n}\n \nfun get1Count(lst:List):Int\n{\n var ret = 0\n for(i in 0 until lst.size)\n { \n val item = lst[i]\n ret+=(i+1)*item.absoluteValue\n }\n return ret\n}\n \nfun getCount(_n:Long, _l:Int):MutableList\n{ \n if (_n ==0L && _l ==0)\n return mutableListOf()\n \n var n =if (_n> 0) _n else -_n\n \n val l = _l\n \n if (l == 1)\n { \n return mutableListOf(n.toInt()) \n }\n \n \n val l1 = get1(l)\n \n val bDigit = (n / l1).toInt() \n val tDigit = bDigit + 1\n \n val solb = getCount(n - l1 * bDigit, l - 1)\n val vb = get1Count(solb) + bDigit * l\n \n val solt = getCount(l1 * tDigit - n, l - 1) \n for (i in 0 until solt.size) {\n solt[i] = -solt[i]\n }\n val vt = get1Count(solt) + tDigit * l\n\n if (vb < vt)\n {\n solb.add(0)\n solb[l-1] = bDigit\n return solb\n }\n else\n {\n solt.add(0)\n solt[l-1] = tDigit\n return solt \n }\n\n \n}\n"}, {"source_code": "import kotlin.math.*\n\nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\nfun readLongs() = readStrings().map { it.toLong() } // list of ints\nfun readLong() = readLn().toLong() // list of strings\n\nfun getLength(_n:Long):Int{\n var n = _n\n if (n == 0L)\n return 0\n var ret = 0\n while(n > 0L)\n {\n ret++\n n = n / 10\n }\n return ret\n}\n\nfun get1(_l:Int):Long{\n var n = _l\n if (n == 0)\n return 1\n var ret = 1L\n while(n > 1)\n {\n ret=1 + ret * 10\n n--\n }\n return ret\n}\n\n\nfun main() {\n \n println(getCount(readLong()))\n}\n\n\nfun getCount(_n:Long):Long\n{ \n if (_n ==0L)\n return 0\n\n var n =if (_n> 0) _n else -_n\n \n val l = getLength(n)\n \n if (l == 1)\n return min(n, 13 - n)\n\n val l1 = get1(l)\n \n val digit = n / l1\n var bdigit = digit + 1\n var nbottom = digit * l1\n var ntop = (bdigit) * l1\n if (n % l1 ==0L)\n {\n ntop = nbottom \n bdigit = digit \n }\n \n \n val ntopadd = getCount(ntop - n)\n \n val v1 = bdigit * l + ntopadd\n val v2 = l + 2 + l * (10 - bdigit) + ntopadd\n\n var ret = min(v1, v2)\n if (ntop != nbottom && nbottom > 0)\n {\n val ntopadd2 = getCount(n - nbottom)\n \n val v3 = digit * l + ntopadd2\n val v4 = l + 2 + l * (10 - digit) + ntopadd2\n ret = min(ret, v3)\n ret = min(ret, v4)\n }\n return ret\n}"}, {"source_code": "fun absoluteValue(n: Long): Long {\n if (n < 0) {\n return -n;\n } else {\n return n;\n }\n}\n\nfun answer(n: Long, position: Int, ones: Array): Long {\n if (position == 0) {\n return absoluteValue(n)\n }\n var local_n: Long = n\n var lower_bound: Long = local_n / ones[position]\n local_n %= ones[position]\n if (n == 0L) {\n return lower_bound * position;\n }\n return lower_bound * position + \n minOf(position + answer(ones[position] - local_n, position - 1, ones),\n answer(local_n, position - 1, ones));\n}\n\nfun main() {\n var n: Long = readLine()!!.toLong()\n var ones: Array = arrayOf(0L, 1L, 11L, 111L, 1111L, 11111L, 111111L, 1111111L, 11111111L, 111111111L, \n 1111111111L, 11111111111L, 111111111111L, 1111111111111L, 11111111111111L, 111111111111111L, \n 111111111111111L, 1111111111111111L, 11111111111111111L, 111111111111111111L, 1111111111111111111L)\n println(\"${answer(n, 16, ones)}\")\n}"}, {"source_code": "fun answer(n: Long, position: Int, ones: Array): Long {\n var local_n: Long = n\n var lower_bound: Long = local_n / ones[position]\n local_n %= ones[position]\n if (local_n == 0L) {\n return lower_bound * position;\n }\n return lower_bound * position + \n minOf(position + answer(ones[position] - local_n, position - 1, ones),\n answer(local_n, position - 1, ones));\n}\n\nfun main() {\n var n: Long = readLine()!!.toLong()\n var ones: Array = arrayOf(0L, 1L, 11L, 111L, 1111L, 11111L, 111111L, 1111111L, 11111111L, 111111111L, \n 1111111111L, 11111111111L, 111111111111L, 1111111111111L, 11111111111111L, 111111111111111L, \n 111111111111111L, 1111111111111111L, 11111111111111111L, 111111111111111111L, 1111111111111111111L)\n println(\"${answer(n, 16, ones)}\")\n}"}, {"source_code": "import kotlin.math.min\n\nvar memo = mutableListOf()\nfun calculate(number: Long): Long {\n val res: Long\n var i = 16\n if (number <= 11) return min(number, 2 + 11 - number)\n\n while (memo[i - 1] >= number) i--\n\n res = ((number / memo[i - 1]) * (i - 1)) + calculate(number % memo[i - 1])\n if (number < memo[i] - number) return res\n return min(res, i + calculate(memo[i] - number))\n}\n\nfun main(args: Array) {\n val n = readLine()!!.toLong()\n memo.add(0)\n memo.add(1)\n for (i in 2 until 16) memo.add(10 * memo[i - 1] + 1)\n memo.add(0)\n memo.add(0)\n print(calculate(n))\n}"}, {"source_code": "import kotlin.math.abs\n\nfun closest11(num: Long): Long {\n val len = num.toString().length\n val a = \"1\".repeat(len).toLong()\n val b = \"1\".repeat(len +1).toLong()\n val diffA = abs(a - num)\n val diffB = abs(b - num)\n return if (diffA > diffB) b else a\n}\n\nfun solve(num: Long): Int {\n if (num == 0L) {\n return 0\n }\n val closest = closest11(num)\n return solve(abs(num - closest)) + closest.toString().length\n}\n\nfun readNumsLine(): List {\n return readLine()!!.split(\"\\\\s\".toRegex()).map { it.toLong() }\n}\n\nfun main() {\n val (num) = readNumsLine()\n\n println(solve(num))\n}\n"}, {"source_code": "import kotlin.math.abs\n\nfun closest11(num: Long): Long {\n val len = num.toString().length\n val a = \"1\".repeat(len).toLong()\n val b = \"1\".repeat(len +1).toLong()\n val diffA = abs(a - num)\n val diffB = abs(b - num)\n return if (diffA > diffB) b else a\n}\n\nfun solve(num: Long): Int {\n if (num == 1L) {\n return 1\n }\n val closest = closest11(num)\n return solve(abs(num - closest)) + closest.toString().length\n}\n\nfun readNumsLine(): List {\n return readLine()!!.split(\"\\\\s\".toRegex()).map { it.toLong() }\n}\n\nfun main() {\n val (num) = readNumsLine()\n\n println(solve(num))\n}\n"}, {"source_code": "fun method(array: IntArray, left: Int, right: Int, value: Int): Int {\n if(left >= right)\n return 0\n else if(left == right - 1)\n if(array[left] == value)\n return 1\n else\n return 0\n else {\n val middle = (left + right) / 2;\n\n return method(array, left, middle, value) + method(array, middle, right, value);\n }\n}\n\nfun main() {\n\n println(method(intArrayOf(1, 1, 1, 2, 2), 1, 3, 1))\n\n}"}, {"source_code": "import kotlin.math.min\n\nprivate fun readInt() = readLine()!!.toInt()\nprivate fun readLong() = readLine()!!.toLong()\nprivate fun readIntList() = readLine()!!.split(\" \").map { it.toInt() }\nprivate fun readLongList() = readLine()!!.split(\" \").map { it.toLong() }\nprivate fun readString() = readLine()!!\n\nconst val maxl = 15\nconst val NEG = 1\nconst val ZERO = 0\nconst val POS = 2\n\nval mask = IntArray(maxl).toMutableList()\nvar bestAns = Long.MAX_VALUE\nval ONES = (0..maxl).map { createOnes(it) }\n\nfun createMask(pos: Int, initialN:Long, prevNonZeroId:Int = -1, initialAns:Long = 0) {\n if (pos == maxl) {\n if (initialN == 0L) {\n bestAns = min(bestAns, initialAns)\n }\n } else {\n val curTerm = ONES[maxl - pos]\n\n for (maskValue in 0..2) {\n var ok = true\n var curN = initialN\n var curAns = initialAns\n mask[pos] = maskValue\n\n var nextNonZeroId = prevNonZeroId\n\n when (mask[pos]) {\n POS -> {\n if (prevNonZeroId != -1 && curN < 0 && mask[prevNonZeroId] == NEG) {\n curN += ONES[maxl - prevNonZeroId]\n curAns += maxl - prevNonZeroId\n } else if (curN < 0) {\n ok = false\n }\n val toAdd = curN / curTerm\n curAns += (maxl - pos) * toAdd\n curN -= curTerm * toAdd\n nextNonZeroId = pos\n }\n NEG -> {\n if (prevNonZeroId != -1 && curN > 0 && mask[prevNonZeroId] == POS) {\n curN -= ONES[maxl - prevNonZeroId]\n curAns += maxl - prevNonZeroId\n } else if (curN > 0) {\n ok = false\n }\n val toAdd = curN / curTerm\n if (toAdd < 0) {\n curAns += (maxl - pos) * (-toAdd)\n curN += curTerm * (-toAdd)\n }\n nextNonZeroId = pos\n }\n }\n\n if (ok) {\n createMask(pos + 1, initialAns = curAns, initialN = curN, prevNonZeroId = nextNonZeroId)\n }\n }\n }\n}\n\nfun useMask(initialN: Long): Long {\n var ans = 0L\n var curN = initialN\n var prevNonZeroId = -1\n for (i in 0 until mask.size) {\n\n\n }\n return if (curN == 0L) ans else -1\n}\n\nfun createOnes(n:Int): Long {\n var ans = 0L\n repeat(n) {\n ans = ans * 10 + 1\n }\n return ans\n}\n\nfun test(n:Long) {\n mask[mask.size - 1] = NEG\n mask[mask.size - 2] = POS\n mask[mask.size - 3] = POS\n assert(useMask(n) == 6L)\n}\n\nfun main() {\n val n = readLong()\n\n //test(n)\n\n createMask(0, n)\n println(bestAns)\n}"}, {"source_code": "import java.lang.Math.pow\n\nprivate fun readInt() = readLine()!!.toInt()\nprivate fun readLong() = readLine()!!.toLong()\nprivate fun readIntList() = readLine()!!.split(\" \").map { it.toInt() }\nprivate fun readLongList() = readLine()!!.split(\" \").map { it.toLong() }\nprivate fun readString() = readLine()!!\n\nconst val maxl = 10\nconst val NEG = 1\nconst val ZERO = 0\nconst val POS = 2\n\nfun createMask(n: Int, mask: MutableList) {\n var curN = n\n for (i in 0 until maxl) {\n mask[i] = curN % 3\n curN /= 3\n }\n}\n\nfun useMask(mask: List, n: Long): Long {\n var ans = 0L\n var curN = n\n var nextMaskId = 1\n var curTerm = createOnes(maxl)\n for (i in 0 until mask.size) {\n if (nextMaskId == i) {\n nextMaskId++\n }\n while (nextMaskId < mask.size && mask[nextMaskId] == 0) {\n nextMaskId++\n }\n val nextMask = if (nextMaskId < mask.size) mask[nextMaskId] else null\n when (mask[i]) {\n POS -> {\n val toAdd = curN / curTerm\n ans += (maxl - i) * toAdd\n curN -= curTerm * toAdd\n if (nextMask == NEG) {\n curN -= curTerm\n ans += maxl - i\n }\n }\n NEG -> {\n val toAdd = curN / curTerm\n if (toAdd < 0) {\n ans += (maxl - i) * (-toAdd)\n curN += curTerm * (-toAdd)\n }\n if (nextMask == POS) {\n curN += curTerm\n ans += maxl - i\n }\n }\n }\n curTerm /= 10\n }\n return if (curN == 0L) ans else -1\n}\n\n//fun decompose(n: Long, tryNeg: Boolean = false): Int {\n// if (n == 0L) {\n// return 0\n// }\n// var curN = n\n// var curOnes = 17\n// var curTerm = createOnes(curOnes)\n// while (curTerm > curN) {\n// curTerm = createOnes(--curOnes)\n// }\n// var ans = curOnes + decompose(curN - curTerm, true)\n// if (tryNeg) {\n// ans = min(ans, curOnes + 1 + decompose(createOnes(curOnes + 1) - n))\n// }\n// return ans\n//}\n//\nfun createOnes(n:Int): Long {\n var ans = 0L\n repeat(n) {\n ans = ans * 10 + 1\n }\n return ans\n}\n\n//fun restore(n:Long, prev: IntArray): List {\n// val ans = mutableListOf()\n// var curN = n\n// while (curN > 0) {\n// val curTerm = createOnes(prev[curN])\n// curN -= curTerm\n// ans.add(curTerm)\n// }\n// return ans\n//}\n\nfun tempDp() {\n val maxn = 1000\n val dp = IntArray(maxn) {Int.MAX_VALUE}\n val prev = IntArray(maxn) {-1}\n dp[0] = 0\n for (i in 1 until maxn) {\n var add = 1\n var cntOnes = 1\n while (add <= i) {\n if (cntOnes + dp[i - add] < dp[i]) {\n dp[i] = cntOnes + dp[i - add]\n prev[i] = cntOnes\n }\n add = add * 10 + 1\n cntOnes++\n }\n }\n//\n// for (i in 1..1000) {\n// println(restore(i, prev).joinToString())\n// }\n}\n\nfun test(n:Long) {\n val mask = IntArray(maxl).toMutableList()\n mask[mask.size - 1] = NEG\n mask[mask.size - 2] = POS\n mask[mask.size - 3] = POS\n assert(useMask(mask, n) == 6L)\n}\n\nfun main() {\n val n = readLong()\n\n val mask = IntArray(maxl).toMutableList()\n\n val ans = (0 until pow(3.0, maxl.toDouble()).toInt()).map { m ->\n createMask(m, mask)\n useMask(mask, n)\n }.filter { it != -1L }.min()\n println(ans)\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport java.lang.Math.*\nimport kotlin.collections.ArrayList\n\nvar stok = StringTokenizer(\"\")\nvar br = BufferedReader(InputStreamReader(System.`in`))\n\nfun nextToken(): String? {\n while (!stok.hasMoreTokens()) {\n val s = br.readLine() ?: return null\n stok = StringTokenizer(s)\n }\n return stok.nextToken()\n}\n\nfun nextInt() = nextToken()!!.toInt()\nfun nextDouble() = nextToken()!!.toDouble()\nfun nextLong() = nextToken()!!.toLong()\n\nfun main(args: Array) {\n if (args.isNotEmpty()) br = BufferedReader(FileReader(\"input.txt\"))\n PrintWriter(System.out, false).use { it.solve() }\n}\n\nfun PrintWriter.solve() {\n var n = nextLong()\n val used = TreeSet()\n fun get(n: Long, can: Boolean): Int {\n if (n == 0L) {\n return 0\n }\n if (n < 0) {\n return get(abs(n), can)\n }\n if (used.contains(n)) {\n return 1e9.toInt()\n }\n used.add(n)\n val ds = ArrayList()\n var x = n\n while (x > 0) {\n ds.add((x % 10).toInt())\n x /= 10\n }\n ds.reverse()\n\n x = 0\n for (i in ds) {\n x = x * 10 + 1\n }\n\n x *= ds[0]\n\n var a1 = get(n - x, true) + ds.size * ds[0]\n var a2 = 1e9.toInt()\n if (can) {\n x = 1\n for (i in ds) {\n x = x * 10 + 1\n }\n a2 = get(n - x, false) + ds.size + 1\n }\n\n return min(a1, a2)\n }\n\n println(get(n, true))\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport java.lang.Math.*\n\nvar stok = StringTokenizer(\"\")\nvar br = BufferedReader(InputStreamReader(System.`in`))\n\nfun nextToken(): String? {\n while (!stok.hasMoreTokens()) {\n val s = br.readLine() ?: return null\n stok = StringTokenizer(s)\n }\n return stok.nextToken()\n}\n\nfun nextInt() = nextToken()!!.toInt()\nfun nextDouble() = nextToken()!!.toDouble()\nfun nextLong() = nextToken()!!.toLong()\n\nfun main(args: Array) {\n if (args.isNotEmpty()) br = BufferedReader(FileReader(\"input.txt\"))\n PrintWriter(System.out, false).use { it.solve() }\n}\n\nfun PrintWriter.solve() {\n var s = nextToken()!!\n var ans = 0\n var c = 0\n for (i in 0 until s.length) {\n val x = abs(s[i].toInt() - '0'.toInt() - c)\n ans += (s.length - i) * x\n c = s[i].toInt() - '0'.toInt();\n }\n print(ans)\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport java.lang.Math.*\nimport kotlin.collections.ArrayList\n\nvar stok = StringTokenizer(\"\")\nvar br = BufferedReader(InputStreamReader(System.`in`))\n\nfun nextToken(): String? {\n while (!stok.hasMoreTokens()) {\n val s = br.readLine() ?: return null\n stok = StringTokenizer(s)\n }\n return stok.nextToken()\n}\n\nfun nextInt() = nextToken()!!.toInt()\nfun nextDouble() = nextToken()!!.toDouble()\nfun nextLong() = nextToken()!!.toLong()\n\nfun main(args: Array) {\n if (args.isNotEmpty()) br = BufferedReader(FileReader(\"input.txt\"))\n PrintWriter(System.out, false).use { it.solve() }\n}\n\nfun PrintWriter.solve() {\n var n = nextLong()\n fun get(n: Long, mx: Int): Int {\n if (n == 0L) {\n return 0\n }\n if (n < 0) {\n return get(abs(n), mx)\n }\n val ds = ArrayList()\n var x = n\n while (x > 0) {\n ds.add((x % 10).toInt())\n x /= 10\n }\n ds.reverse()\n\n var a1 = 1e9.toInt()\n if (ds.size + 1 <= mx) {\n x = 1\n for (i in ds) {\n x = x * 10 + 1\n }\n a1 = ds.size + 1 + get(n - x, ds.size)\n }\n\n var a2 = 1e9.toInt()\n if (ds.size <= mx) {\n x = 0\n for (i in ds) {\n x = x * 10 + 1\n }\n x *= ds[0]\n a2 = get(n - x, ds.size - 1) + ds.size * ds[0]\n }\n\n return min(a1, a2)\n }\n\n println(get(n, 100))\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport java.lang.Math.*\nimport kotlin.collections.ArrayList\n\nvar stok = StringTokenizer(\"\")\nvar br = BufferedReader(InputStreamReader(System.`in`))\n\nfun nextToken(): String? {\n while (!stok.hasMoreTokens()) {\n val s = br.readLine() ?: return null\n stok = StringTokenizer(s)\n }\n return stok.nextToken()\n}\n\nfun nextInt() = nextToken()!!.toInt()\nfun nextDouble() = nextToken()!!.toDouble()\nfun nextLong() = nextToken()!!.toLong()\n\nfun main(args: Array) {\n if (args.isNotEmpty()) br = BufferedReader(FileReader(\"input.txt\"))\n PrintWriter(System.out, false).use { it.solve() }\n}\n\nfun PrintWriter.solve() {\n var n = nextLong()\n val used = TreeSet()\n fun get(n: Long, can: Boolean): Int {\n if (n == 0L) {\n return 0\n }\n if (n < 0) {\n return get(abs(n), can)\n }\n if (used.contains(n)) {\n return 1e9.toInt()\n }\n used.add(n)\n val ds = ArrayList()\n var x = n\n while (x > 0) {\n ds.add((x % 10).toInt())\n x /= 10\n }\n ds.reverse()\n\n x = 0\n for (i in ds) {\n x = x * 10 + 1\n }\n\n x *= ds[0]\n\n var a1 = get(n - x, true) + ds.size * ds[0]\n var a2 = 1e9.toInt()\n if (true || can) {\n x = 1\n for (i in ds) {\n x = x * 10 + 1\n }\n a2 = get(n - x, false) + ds.size + 1\n }\n\n return min(a1, a2)\n }\n\n println(get(n, true))\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport java.lang.Math.*\n\nvar stok = StringTokenizer(\"\")\nvar br = BufferedReader(InputStreamReader(System.`in`))\n\nfun nextToken(): String? {\n while (!stok.hasMoreTokens()) {\n val s = br.readLine() ?: return null\n stok = StringTokenizer(s)\n }\n return stok.nextToken()\n}\n\nfun nextInt() = nextToken()!!.toInt()\nfun nextDouble() = nextToken()!!.toDouble()\nfun nextLong() = nextToken()!!.toLong()\n\nfun main(args: Array) {\n if (args.isNotEmpty()) br = BufferedReader(FileReader(\"input.txt\"))\n PrintWriter(System.out, false).use { it.solve() }\n}\n\nfun PrintWriter.solve() {\n var n = nextLong()\n fun get(n: Long, mx: Int): Int {\n if (n == 0L) {\n return 0\n }\n if (n < 0) {\n return get(abs(n), mx)\n }\n var a: Long = 0\n var x = 0\n while (a <= n) {\n a = a * 10 + 1\n x++\n }\n var a1 = 1e9.toInt()\n if (x <= mx) {\n a1 = x + get(n - a, x - 1)\n }\n a = 1\n x = 1\n var p = 1L\n while (a * 10 + 1 <= n && x < mx) {\n a = a * 10 + 1\n x++\n p *= 10\n }\n var y = x\n var b = a\n var bp = p\n while (bp + p <= n) {\n b += a\n y += x\n bp += p\n }\n var a2 = y + get(n - b, x - 1)\n return min(a1, a2)\n }\n\n println(get(n, 100))\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport java.lang.Math.*\n\nvar stok = StringTokenizer(\"\")\nvar br = BufferedReader(InputStreamReader(System.`in`))\n\nfun nextToken(): String? {\n while (!stok.hasMoreTokens()) {\n val s = br.readLine() ?: return null\n stok = StringTokenizer(s)\n }\n return stok.nextToken()\n}\n\nfun nextInt() = nextToken()!!.toInt()\nfun nextDouble() = nextToken()!!.toDouble()\nfun nextLong() = nextToken()!!.toLong()\n\nfun main(args: Array) {\n if (args.isNotEmpty()) br = BufferedReader(FileReader(\"input.txt\"))\n PrintWriter(System.out, false).use { it.solve() }\n}\n\nfun PrintWriter.solve() {\n var n = nextLong()\n fun get(n: Long): Int {\n var ans = 0\n var c = 0\n var s = n.toString()\n for (i in 0 until s.length) {\n val x = abs(s[i].toInt() - '0'.toInt() - c)\n ans += (s.length - i) * x\n c = s[i].toInt() - '0'.toInt();\n }\n return ans\n }\n\n var a: Long = 0\n var x = 0\n while (a < n) {\n a = a * 10 + 1\n x++\n }\n if (a == n) {\n print(get(n))\n } else {\n print(min(get(n), get(a - n) + x))\n }\n}"}, {"source_code": "\n\nfun main() {\n val n = readLine()!!\n println(oneBasedArithmetic(n, 0))\n}\n\nfun oneBasedArithmetic(string: String, count: Int): Int {\n val length = if (string[0] == '-') string.length - 1 else string.length\n val count1 = withNOnes(string, count, length)\n val count2 = withNPlus1Ones(string, count)\n return if (count1 < count2) count1 else count2\n}\n\nfun withNOnes(string: String, count: Int, length: Int): Int {\n val n = if (string[0] == '-') string.length - 1 else string.length\n val num = string.toLong()\n val nOnes = \"1\".repeat(n).toLong()\n return when {\n// n < length -> oneBasedArithmetic(string, count)\n n > length -> Int.MAX_VALUE\n num == 0L -> count\n num == -1L -> count + 1\n num == 1L -> count + 1\n num < 0L -> {\n val rem = (num % nOnes).toString()\n val quotient = num / nOnes\n if (quotient == 0L && rem.length == n+1){\n withNOnes((num + nOnes).toString(), count + n, n)\n }else\n oneBasedArithmetic(rem, count + (n * quotient.unaryMinus()).toInt())\n }\n else -> {\n val rem = (num % nOnes).toString()\n val quotient = num / nOnes\n if (quotient == 0L && rem.length == n){\n withNOnes((num - nOnes).toString(), count + n, n)\n }else\n oneBasedArithmetic(rem, count + (n * quotient).toInt())\n }\n }\n}\n\n\nfun withNPlus1Ones(string: String, count: Int): Int {\n val n = if (string[0] == '-') string.length - 1 else string.length\n val num = string.toLong()\n val nOnes = \"1\".repeat(n + 1).toLong()\n return when {\n num < 0L -> withNOnes((num + nOnes).toString(), count + n + 1, n)\n else -> withNOnes((nOnes - num).toString(), count + n + 1, n)\n }\n}"}, {"source_code": "import kotlin.math.sign\n\nfun main() {\n val n = readLine()!!\n println(oneBasedArithmetic(n, 0))\n}\n\nfun oneBasedArithmetic(string: String, count: Int): Int {\n if (count == -1) return -1\n val count1 = withNOnes(string, count)\n val count2 = withNPlus1Ones(string, count)\n return if (count1 < count2) count1 else count2\n}\n\nfun withNOnes(string: String, count: Int): Int {\n// val n = string.replace(\"-\",\"\").length\n// var count1 = count\n// var num = string.toInt()\n// val nOnes = \"1\".repeat(n).toInt()\n// var length = n\n// while (length == n) {\n// when {\n// num < 0 -> {\n// num += nOnes\n// count1 += n\n// length = num.toString().replace(\"-\", \"\").length\n// }\n// num == 0 -> return count1\n// num > 0 -> {\n// count1 += n\n// num -= nOnes\n// length = num.toString().replace(\"-\", \"\").length\n// }\n// }\n// }\n// return if (length < n)\n// oneBasedArithmetic(num.toString(), count1)\n// else -1\n val n = if (string[0] == '-') string.length - 1 else string.length\n val num = string.toLong()\n val nOnes = \"1\".repeat(n).toLong()\n return when {\n num == 0L -> count\n num == -1L -> count + 1\n num == 1L -> count + 1\n num < 0L -> withNOnes((num + nOnes).toString(), count + n)\n else -> withNOnes((num - nOnes).toString(), count + n)\n }\n}\n\nfun withNPlus1Ones(string: String, count: Int): Int {\n// val n = string.replace(\"-\",\"\").length\n// var count1 = count\n// var num = string.toInt()\n// val nOnesPlusOne = \"1\".repeat(n + 1).toInt()\n// var length = n\n// while (length == n) {\n// when {\n// num < 0 -> {\n// num += nOnesPlusOne\n// count1 += n\n// length = num.toString().replace(\"-\", \"\").length\n// }\n// num == 0 -> return count\n// num > 0 -> {\n// count1 += n\n// num = nOnesPlusOne - num\n// length = num.toString().replace(\"-\", \"\").length\n// }\n// }\n// }\n// return if (length < n)\n// oneBasedArithmetic(num.toString(), count1)\n// else -1\n val n = if (string[0] == '-') string.length - 1 else string.length\n val num = string.toLong()\n val nOnes = \"1\".repeat(n + 1).toLong()\n return when {\n num < 0L -> withNOnes((num + nOnes).toString(), count + n + 1)\n else -> withNOnes((nOnes - num).toString(), count + n + 1)\n }\n}"}, {"source_code": "import kotlin.math.sign\n\nfun main() {\n val n = readLine()!!\n println(oneBasedArithmetic(n, 0))\n}\n\nfun oneBasedArithmetic(string: String, count: Int): Int {\n if (count == -1) return -1\n val count1 = withNOnes(string, count)\n val count2 = withNPlus1Ones(string, count)\n return if (count1 < count2) count1 else count2\n}\n\nfun withNOnes(string: String, count: Int): Int {\n// val n = string.replace(\"-\",\"\").length\n// var count1 = count\n// var num = string.toInt()\n// val nOnes = \"1\".repeat(n).toInt()\n// var length = n\n// while (length == n) {\n// when {\n// num < 0 -> {\n// num += nOnes\n// count1 += n\n// length = num.toString().replace(\"-\", \"\").length\n// }\n// num == 0 -> return count1\n// num > 0 -> {\n// count1 += n\n// num -= nOnes\n// length = num.toString().replace(\"-\", \"\").length\n// }\n// }\n// }\n// return if (length < n)\n// oneBasedArithmetic(num.toString(), count1)\n// else -1\n val n = if (string[0] == '-') string.length - 1 else string.length\n val num = string.toLong()\n val nOnes = \"1\".repeat(n).toLong()\n return when {\n num == 0L -> count\n num == -1L -> count + 1\n num == 1L -> count + 1\n num < 0L -> withNOnes((num + nOnes).toString(), count + n)\n else -> withNOnes((num - nOnes).toString(), count + n)\n }\n}\n\nfun withNPlus1Ones(string: String, count: Int): Int {\n// val n = string.replace(\"-\",\"\").length\n// var count1 = count\n// var num = string.toInt()\n// val nOnesPlusOne = \"1\".repeat(n + 1).toInt()\n// var length = n\n// while (length == n) {\n// when {\n// num < 0 -> {\n// num += nOnesPlusOne\n// count1 += n\n// length = num.toString().replace(\"-\", \"\").length\n// }\n// num == 0 -> return count\n// num > 0 -> {\n// count1 += n\n// num = nOnesPlusOne - num\n// length = num.toString().replace(\"-\", \"\").length\n// }\n// }\n// }\n// return if (length < n)\n// oneBasedArithmetic(num.toString(), count1)\n// else -1\n val n = if (string[0] == '-') string.length - 1 else string.length\n val num = string.toLong()\n val nOnes = \"1\".repeat(n + 1).toLong()\n return when {\n num == 0L -> count\n num == -1L -> count + 1\n num == 1L -> count + 1\n num < 0L -> withNOnes((num + nOnes).toString(), count + n)\n else -> withNOnes((nOnes - num).toString(), count + n)\n }\n}"}, {"source_code": "import kotlin.math.min\n\nfun main()\n{\n val i= readLine()!!\n val count=0\n println(min(findDigits(i,count),findGreaterDigits(i,count)))\n}\n\ntailrec fun findDigits(\n Number:String,\n count:Int):Int\n{\n\n return when {\n (Number.length == 2 && Number.contains(\"-1\")) -> count + 1\n (Number.length == 1 && Number.contains(\"1\")) -> count + 1\n (Number.length == 1 && Number.contains(\"0\")) -> count\n else -> {\n val num= if (Number.startsWith(\"-\")) Number.drop(1) else Number\n val digits = num.length\n val number = \"1\".repeat(digits)\n val updatedNumber=num.toLong()-number.toLong()\n findDigits(updatedNumber.toString(), count.plus(digits))\n\n }\n }\n}\n\nfun findGreaterDigits(\n Number:String,\n count:Int):Int\n{\n val digits = Number.length\n val number = \"1\".repeat(digits+1)\n val updatedNumber=Number.toLong()-number.toLong()\n return findDigits(updatedNumber.toString(), count.plus(digits+1))\n\n}"}, {"source_code": "fun main()\n{\n val i= readLine()!!\n val count=0\n println(findDigits(i,count))\n}\n\nfun findDigits(\n Number:String,\n count:Int):Int\n{\n\n return when {\n (Number.length == 2 && listOf(\"-1\").contains(Number)) -> count + 1\n (Number.length == 1 && listOf(\"1\").contains(Number)) -> count + 1\n (Number.length == 1 && listOf(\"0\").contains(Number)) -> count\n else -> {\n val digits = Number.length\n val number = \"1\".repeat(digits)\n val updatedNumber=Number.toInt()-number.toInt()\n findDigits(updatedNumber.toString(), count.plus(digits))\n\n }\n }\n}"}, {"source_code": "\nfun main()\n{\n val i= readLine()!!\n val count=0\n println(listOf(findEqualDigits(i,count),findGreaterDigits(i,count)).min())\n\n}\n\ntailrec fun findEqualDigits(\n Number:String,\n count:Int):Int\n{\n\n return when {\n (Number.length == 2 && Number.contains(\"-1\")) -> count + 1\n (Number.length == 1 && Number.contains(\"1\")) -> count + 1\n (Number.length == 1 && Number.contains(\"0\")) -> count\n else -> {\n val num= if (Number.startsWith(\"-\")) Number.drop(1) else Number\n val digits = num.length\n val number = \"1\".repeat(digits)\n val updatedNumber=num.toLong()-number.toLong()\n findEqualDigits(updatedNumber.toString(), count.plus(digits))\n\n }\n }\n}\n\nfun findGreaterDigits(\n Number:String,\n count:Int):Int\n{\n val digits = Number.length\n val number = \"1\".repeat(digits+1)\n val updatedNumber=Number.toLong()-number.toLong()\n return findEqualDigits(updatedNumber.toString(), count.plus(digits+1))\n\n}\n\n//fun findLesserDigits(\n// Number:String,\n// count:Int):Int\n//{\n// val digits = Number.length\n// val number = \"1\".repeat(digits-1)\n// val updatedNumber=Number.toLong()-number.toLong()\n// return findEqualDigits(updatedNumber.toString(), count.plus(digits-1))\n//\n//}"}, {"source_code": "fun main()\n{\n println(\"enter the number\")\n val i= readLine()!!\n val count=0\n println(findDigits(i,count))\n}\n\nfun findDigits(\n Number:String,\n count:Int):Int\n{\n\n return when {\n (Number.length == 2 && listOf(\"-1\").contains(Number)) -> count + 1\n (Number.length == 1 && listOf(\"1\").contains(Number)) -> count + 1\n (Number.length == 1 && listOf(\"0\").contains(Number)) -> count\n else -> {\n val digits = Number.length\n val number = \"1\".repeat(digits)\n val updatedNumber=Number.toInt()-number.toInt()\n findDigits(updatedNumber.toString(), count.plus(digits))\n\n }\n }\n}"}, {"source_code": "import kotlin.math.min\n\nfun main() {\n val i = readLine()!!\n val count = 0L\n println(min(findEqualDigits(i, count), findGreaterDigits(i, count)))\n}\n\nfun findEqualDigits(\n Number: String,\n count: Long\n): Long {\n when {\n (Number.toLong() == -1L) -> return count + 1L\n (Number.toLong() == 1L) -> return count + 1L\n (Number.toLong() == 0L) -> return count\n }\n val num = if (Number.startsWith(\"-\")) Number.drop(1) else Number\n val digits = num.length\n val number = \"1\".repeat(digits).toLong()\n val quotient = num.toLong() / number\n val updatedNumber = num.toLong() % number\n val onesCount = count.plus(quotient * digits)\n if (quotient == 0L && updatedNumber.toString().length == digits) {\n val number1 = updatedNumber - number\n val subCount = onesCount + digits\n return findEqualDigits(number1.toString(), subCount)\n }\n else\n {\n return when {\n (updatedNumber == -1L) -> onesCount + 1L\n (updatedNumber == 1L) -> onesCount + 1L\n (updatedNumber == 0L) -> onesCount\n else ->\n min(\n findEqualDigits(updatedNumber.toString(), onesCount)\n , findGreaterDigits(updatedNumber.toString(), onesCount)\n )\n }\n }\n}\n\nfun findGreaterDigits(\n Number: String,\n count: Long\n): Long {\n val num = if (Number.startsWith(\"-\")) Number.drop(1) else Number\n val digits = num.length\n val number = \"1\".repeat(digits + 1)\n val updatedNumber = number.toLong() - num.toLong()\n\n return findEqualDigits(updatedNumber.toString(), count.plus(digits + 1))\n\n}\n\n"}, {"source_code": "fun main()\n{\n val i= readLine()!!\n val count=0\n if (i.toInt() == 0){\n println(count)\n }\n else{\n println(findDigits(i,count))\n }\n}\n\nfun findDigits(\n Number:String,\n count:Int):Int\n{\n\n return when {\n (Number.length == 2 && listOf(\"-1\").contains(Number)) -> count + 1\n (Number.length == 1 && listOf(\"1\").contains(Number)) -> count + 1\n (Number.length == 1 && listOf(\"0\").contains(Number)) -> count\n else -> {\n val digits = Number.length\n val number = \"1\".repeat(digits)\n val updatedNumber=Number.toInt()-number.toInt()\n findDigits(updatedNumber.toString(), count.plus(digits))\n\n }\n }\n}"}, {"source_code": "import kotlin.math.min\n\nfun main()\n{\n val i= readLine()!!\n val count=0L\n println(min(findEqualDigits(i,count),findGreaterDigits(i,count)))\n}\n\n fun findEqualDigits(\n Number:String,\n count:Long):Long {\n when{\n (Number == \"-1\") -> return count + 1L\n (Number == \"1\") -> return count + 1L\n (Number == \"0\") -> return count\n }\n val num = if (Number.startsWith(\"-\")) Number.drop(1) else Number\n val digits = num.length\n val number = \"1\".repeat(digits)\n val quotient = num.toLong() / number.toLong()\n val updatedNumber = num.toLong() % number.toLong()\n val onesCount = count.plus(quotient * digits)\n if (quotient == 0L && updatedNumber.toString().length == digits) {\n val number1=updatedNumber-number.toLong()\n val subCount=onesCount+digits\n return findEqualDigits(number1.toString(), subCount)\n } else {\n return when {\n (updatedNumber == \"-1\".toLong()) -> onesCount + 1L\n (updatedNumber == \"1\".toLong()) -> onesCount + 1L\n (updatedNumber == \"0\".toLong()) -> onesCount\n else ->\n min(\n findEqualDigits(updatedNumber.toString(), onesCount)\n , findGreaterDigits(updatedNumber.toString(), onesCount)\n )\n\n\n }\n }\n }\n\n fun findGreaterDigits(\n Number: String,\n count: Long\n ): Long {\n val num = if (Number.startsWith(\"-\")) Number.drop(1) else Number\n val digits = num.length\n val number = \"1\".repeat(digits + 1)\n val updatedNumber = num.toLong() - number.toLong()\n\n return findEqualDigits(updatedNumber.toString(), count.plus(digits + 1))\n\n }\n\n"}, {"source_code": "import java.util.*\n\nvar a = LongArray(16)\nvar MIN = 10000000000000000L\nfun dfs(n: Long, now: Int, tot: Long) {\n if (now == 0) {\n if (MIN > tot) MIN = tot\n return\n }\n if (n >= 0) {\n val temp = n / a[now]\n dfs(n - temp * a[now], now - 1, tot + temp * now)\n dfs(n - (temp + 1) * a[now], now - 1, tot + (temp + 1) * now)\n } else {\n val temp = -n / a[now]\n dfs(n + temp * a[now], now - 1, tot + temp * now)\n dfs(n + (temp + 1) * a[now], now - 1, tot + (temp + 1) * now)\n }\n}\n\nfun main(args: Array) {\n a[1] = 1\n for (i in 2..15) a[i] = a[i - 1] * 10 + 1\n val cin = Scanner(System.`in`)\n val n = cin.nextLong()\n dfs(n, 15, 0)\n println(MIN)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.StringTokenizer\nimport kotlin.math.*\n\nfun main() {\n val M = generateSequence(0L) { it * 10 + 1 }.take(17).toList()\n\n val n0 = readLong()\n\n var n = n0\n var ans = 0\n\n while(n > 0) {\n val s = n.toString()\n val l = s.length\n val d0 = s[0] - '0'\n\n var cost = 0\n var next = n\n\n for(d in (d0-1).coerceAtLeast(0) .. (d0+1).coerceAtMost(9)) {\n val p = abs(n - M[l] * d)\n if(p < next) {\n next = p\n cost = l * d\n }\n }\n\n ans += cost\n n = next\n }\n\n println(ans)\n}\n\n/** IO code start */\nprivate val _reader = BufferedReader(InputStreamReader(System.`in`))\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\nprivate var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\n\nclass Output {\n val outputSb = StringBuilder()\n fun print(o: Any?) { outputSb.append(o) }\n fun println() { outputSb.append('\\n') }\n fun println(o: Any?) { outputSb.append(o).append('\\n') }\n}\ninline fun output(block: Output.()->Unit) { val o = Output().apply(block); print(o.outputSb) }\nfun iprintln(o: Any?) { println(o) } // immediate println for interactive, bypasses output{} blocks"}, {"source_code": "private fun spar() = readLine()!! // string line\nprivate fun ipar() = spar().toInt() // single int\nprivate fun lpar() = spar().toLong() // single long\nprivate fun sapar() = spar().split(\" \") // list of strings\nprivate fun iapar() = sapar().map { it.toInt() } // list of ints\nprivate fun lapar() = sapar().map { it.toLong() } // list of longs\n\nfun main()\n{\n var n = spar().toCharArray();\n val arr = Array(n.size) { 0 }\n var count = 0\n for (i in 0..n.size-1)\n {\n while (n[i] - '0' > arr[i])\n {\n for (e in i..n.size-1)\n {\n count++\n arr[e]++\n }\n // println(arrayOf(arr.joinToString(\" \"), count).joinToString(\" \"))\n }\n while (n[i] - '0' < arr[i])\n {\n for (e in i..n.size-1)\n {\n count++\n arr[e]--\n }\n // println(arrayOf(arr.joinToString(\" \"), count).joinToString(\" \"))\n }\n }\n println(count)\n}"}, {"source_code": "private fun spar() = readLine()!! // string line\nprivate fun ipar() = spar().toInt() // single int\nprivate fun lpar() = spar().toLong() // single long\nprivate fun sapar() = spar().split(\" \") // list of strings\nprivate fun iapar() = sapar().map { it.toInt() } // list of ints\nprivate fun lapar() = sapar().map { it.toLong() } // list of longs\n\nfun main()\n{\n val n = lpar()\n println(brute(n, n.toString().length))\n}\n\nprivate fun brute(n: Long, len: Int): Int\n{\n if (n == 0L)\n {\n return 0\n }\n if (len == 0)\n {\n return 1000000\n }\n var ones = 0L\n for (i in 1..len)\n {\n ones *= 10\n ones++\n }\n \n return Math.min(brute(n - n/ones*ones, len-1) + (n/ones*len).toInt(), brute((n/ones+1)*ones - n, len-1) + (n/ones+1).toInt()*len)\n}"}, {"source_code": "import java.lang.Integer.parseInt\nimport java.lang.Long.parseLong\nimport java.lang.Math.abs\nimport java.lang.Math.min\nimport java.lang.System.exit\n\nimport java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\n\nobject F {\n\n internal val ones = LongArray(17)\n internal val total = LongArray(17)\n\n internal var `in`: BufferedReader? = null\n internal var out: PrintWriter? = null\n internal var tok: StringTokenizer? = null\n\n init {\n for (i in 1 until ones.size) {\n ones[i] = 10 * ones[i - 1] + 1\n total[i] = total[i - 1] + ones[i]\n }\n }\n\n internal fun solve(n: Long, i: Int): Int {\n if (n > total[i] || n < -total[i]) {\n return -1\n }\n if (i == 0) {\n return 0\n }\n var ans = Integer.MAX_VALUE\n for (j in -6..6) {\n val cans = solve(n + j * ones[i], i - 1)\n if (cans >= 0) {\n ans = min(ans, cans + abs(j) * i)\n }\n }\n return if (ans == Integer.MAX_VALUE) -1 else ans\n }\n\n @Throws(Exception::class)\n internal fun solve() {\n val n = scanLong()\n out!!.print(solve(n, 16))\n }\n\n @Throws(IOException::class)\n internal fun scanInt(): Int {\n return parseInt(scanString())\n }\n\n @Throws(IOException::class)\n internal fun scanLong(): Long {\n return parseLong(scanString())\n }\n\n @Throws(IOException::class)\n internal fun scanString(): String {\n while (tok == null || !tok!!.hasMoreTokens()) {\n tok = StringTokenizer(`in`!!.readLine())\n }\n return tok!!.nextToken()\n }\n\n @JvmStatic\n fun main(args: Array) {\n try {\n `in` = BufferedReader(InputStreamReader(System.`in`))\n out = PrintWriter(System.out)\n solve()\n `in`!!.close()\n out!!.close()\n } catch (e: Throwable) {\n e.printStackTrace()\n exit(1)\n }\n\n }\n}\n\nfun main(args: Array) {\n F.main(args)\n}"}, {"source_code": "import java.util.*\n\nvar a = arrayOf(0L, 1L, 11L, 111L, 1111L, 11111L, 111111L, 1111111L, 11111111L, 111111111L, 1111111111L, 11111111111L, 111111111111L, \n1111111111111L, 11111111111111L, 111111111111111L)\nfun ans(n: Long): Long\n{\n if (n == 0L)\n return 0L;\n var k = 1\n while (k < 15)\n {\n if (a[k] <= n && n <= a[k + 1])\n {\n var x = k * (n / a[k]) + ans(n - a[k] * (n / a[k]))\n var y = k + 1 + (a[k + 1] - n) / a[k] * k + ans(a[k + 1] - n - (a[k + 1] - n) / a[k] * a[k])\n return if (x < y) x else y\n }\n ++k;\n }\n return 1000000000\n}\n\nfun main()\n{\n var n = readLine()!!.toLong()\n print(ans(n))\n}"}, {"source_code": " import java.util.*\n \n var a = arrayOf(1L, 11L, 111L, 1111L, 11111L, 111111L, 1111111L, 11111111L, 111111111L, 1111111111L, 11111111111L, 111111111111L, \n 1111111111111L, 11111111111111L, 111111111111111L,1111111111111111L)\n fun ans(n: Long): Long\n {\n if (n == 0L)\n return 0L;\n var k = 1\n while (k < 15)\n {\n if (a[k] <= n && n <= a[k + 1])\n {\n var x = k * (n / a[k]) + ans(n - a[k] * (n / a[k]))\n var y = k + 1 + (a[k + 1] - n) / a[k] * k + ans(a[k + 1] - n - (a[k + 1] - n) / a[k] * a[k])\n return if (x < y) x else y\n }\n ++k;\n }\n return 1000000000\n }\n \n fun main()\n {\n var n = readLine()!!.toLong()\n print(ans(n))\n }"}], "src_uid": "1b17a7b3b41077843ee1d6e0607720d6"} {"nl": {"description": "Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today. Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner. While watching previous races the organizers have noticed that Willman can perform only steps of length equal to w meters, and Bolt can perform only steps of length equal to b meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes). Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance L.Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to t (both are included). What is the probability that Willman and Bolt tie again today?", "input_spec": "The first line of the input contains three integers t, w and b (1 ≤ t, w, b ≤ 5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.", "output_spec": "Print the answer to the problem as an irreducible fraction . Follow the format of the samples output. The fraction (p and q are integers, and both p ≥ 0 and q > 0 holds) is called irreducible, if there is no such integer d > 1, that both p and q are divisible by d.", "sample_inputs": ["10 3 2", "7 1 2"], "sample_outputs": ["3/10", "3/7"], "notes": "NoteIn the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack."}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.lang.AssertionError\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007L\n\ntailrec fun gcd(a: Long, b: Long): Long {\n if (a < b) return gcd(b, a)\n if (b == 0L) return a\n return gcd(b, a % b)\n}\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val T = nl()\n val A = nl()\n val B = nl()\n\n fun answer(x: Long) {\n val d = gcd(x - 1, T)\n out.println(\"${(x - 1)/d}/${T/d}\")\n }\n\n if (A == B) {\n answer(T + 1)\n return\n }\n\n val a = A / gcd(A, B)\n if (a > T / B) {\n answer(min(T + 1, min(A, B)))\n return\n }\n val lcm = a * B\n val size = (T + 1)/ lcm\n val r = (T + 1) % lcm\n debug{\"$lcm $size $r\"}\n\n var ans = 0L\n ans += min(A, B) * size\n if (r != 0L) ans += min(r, min(A, B))\n debug{\"$ans\"}\n answer(ans)\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl() + offset\n }\n return res\n }\n\n private fun na2(n: Int, offset: Int = 0): Array {\n val a = Array(2){IntArray(n)}\n for (i in 0 until n) {\n for (e in a) {\n e[i] = ni() + offset\n }\n }\n return a\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private inline fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private inline fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private inline fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n\n private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()}\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}"}], "negative_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.lang.AssertionError\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007L\n\n\ntailrec fun gcd(a: Long, b: Long): Long {\n if (a < b) return gcd(b, a)\n if (b == 0L) return a\n return gcd(b, a % b)\n}\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val T = nl()\n val A = nl()\n val B = nl()\n\n fun answer(x: Long) {\n val d = gcd(x - 1, T)\n out.println(\"${(x - 1)/d}/${T/d}\")\n }\n\n if (A == 1L && B == 1L) {\n answer(T + 1)\n return\n }\n\n val a = A / gcd(A, B)\n if (a > T / B) {\n answer(min(T + 1, min(A, B)))\n return\n }\n val lcm = a * B\n\n val size = ((T + lcm - 1)/ lcm)\n val r = T % lcm\n debug{\"$lcm $size $r\"}\n if (size == 1L) {\n answer(min(T + 1, min(A, B)))\n return\n }\n\n var ans = 0L\n ans += min(A, B) * (size - 1)\n ans += min(r + 1, min(A, B))\n answer(ans)\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl() + offset\n }\n return res\n }\n\n private fun na2(n: Int, offset: Int = 0): Array {\n val a = Array(2){IntArray(n)}\n for (i in 0 until n) {\n for (e in a) {\n e[i] = ni() + offset\n }\n }\n return a\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private inline fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private inline fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private inline fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n\n private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()}\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.lang.AssertionError\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007L\n\n\ntailrec fun gcd(a: Long, b: Long): Long {\n if (a < b) return gcd(b, a)\n if (b == 0L) return a\n return gcd(b, a % b)\n}\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val T = nl()\n val A = nl()\n val B = nl()\n\n fun answer(x: Long) {\n val d = gcd(x - 1, T)\n out.println(\"${(x - 1)/d}/${T/d}\")\n }\n\n if (A == B) {\n answer(T + 1)\n return\n }\n\n val a = A / gcd(A, B)\n if (a > T / B) {\n answer(min(T + 1, min(A, B)))\n return\n }\n val lcm = a * B\n val size = ((T + 1 + lcm - 1)/ lcm)\n val r = (T + 1) % lcm\n debug{\"$lcm $size $r\"}\n if (size == 1L) {\n answer(min(T + 1, min(A, B)))\n return\n }\n\n var ans = 0L\n ans += min(A, B) * (size - 1)\n ans += min(r + 1, min(A, B))\n debug{\"$ans\"}\n answer(ans)\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl() + offset\n }\n return res\n }\n\n private fun na2(n: Int, offset: Int = 0): Array {\n val a = Array(2){IntArray(n)}\n for (i in 0 until n) {\n for (e in a) {\n e[i] = ni() + offset\n }\n }\n return a\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private inline fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private inline fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private inline fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n\n private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()}\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}"}], "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5"} {"nl": {"description": "This is an easier version of the problem. In this version, $$$n \\le 500$$$.Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya gifted him a string consisting of opening and closing brackets only. Petya believes, that the beauty of the bracket string is a number of its cyclical shifts, which form a correct bracket sequence.To digress from his problems, Vasya decided to select two positions of the string (not necessarily distinct) and swap characters located at this positions with each other. Vasya will apply this operation exactly once. He is curious what is the maximum possible beauty he can achieve this way. Please help him.We remind that bracket sequence $$$s$$$ is called correct if: $$$s$$$ is empty; $$$s$$$ is equal to \"($$$t$$$)\", where $$$t$$$ is correct bracket sequence; $$$s$$$ is equal to $$$t_1 t_2$$$, i.e. concatenation of $$$t_1$$$ and $$$t_2$$$, where $$$t_1$$$ and $$$t_2$$$ are correct bracket sequences. For example, \"(()())\", \"()\" are correct, while \")(\" and \"())\" are not.The cyclical shift of the string $$$s$$$ of length $$$n$$$ by $$$k$$$ ($$$0 \\leq k < n$$$) is a string formed by a concatenation of the last $$$k$$$ symbols of the string $$$s$$$ with the first $$$n - k$$$ symbols of string $$$s$$$. For example, the cyclical shift of string \"(())()\" by $$$2$$$ equals \"()(())\".Cyclical shifts $$$i$$$ and $$$j$$$ are considered different, if $$$i \\ne j$$$.", "input_spec": "The first line contains an integer $$$n$$$ ($$$1 \\le n \\le 500$$$), the length of the string. The second line contains a string, consisting of exactly $$$n$$$ characters, where each of the characters is either \"(\" or \")\".", "output_spec": "The first line should contain a single integer — the largest beauty of the string, which can be achieved by swapping some two characters. The second line should contain integers $$$l$$$ and $$$r$$$ ($$$1 \\leq l, r \\leq n$$$) — the indices of two characters, which should be swapped in order to maximize the string's beauty. In case there are several possible swaps, print any of them.", "sample_inputs": ["10\n()()())(()", "12\n)(()(()())()", "6\n)))(()"], "sample_outputs": ["5\n8 7", "4\n5 10", "0\n1 1"], "notes": "NoteIn the first example, we can swap $$$7$$$-th and $$$8$$$-th character, obtaining a string \"()()()()()\". The cyclical shifts by $$$0, 2, 4, 6, 8$$$ of this string form a correct bracket sequence.In the second example, after swapping $$$5$$$-th and $$$10$$$-th character, we obtain a string \")(())()()(()\". The cyclical shifts by $$$11, 7, 5, 3$$$ of this string form a correct bracket sequence.In the third example, swap of any two brackets results in $$$0$$$ cyclical shifts being correct bracket sequences. "}, "positive_code": [{"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\")\n\nimport java.io.PrintWriter\nimport java.util.ArrayDeque\nimport java.util.PriorityQueue\nimport java.util.StringTokenizer\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln // immediate println for interactive\n\nfun main() {\n output {\n val n = readInt()\n val s = readLn().toCharArray()\n\n val ans = sequence {\n val init = Ans(s.beauty(), 0, 0)\n yield(init)\n if(init.b == 0) return@sequence\n\n for(i in 0 until n-1) {\n for(j in i+1 until n) {\n s.swap(i, j)\n yield(Ans(s.beauty(), i, j))\n s.swap(i, j)\n }\n }\n }.maxBy { it.b }!!\n\n println(ans)\n }\n}\n\nfun CharArray.swap(i: Int, j: Int) { this[i] = this[j].also { this[j] = this[i]} }\n\nfun CharArray.beauty(): Int {\n var min = 0\n var count = 0\n var acc = 0\n\n for(c in this) {\n when(c) {\n '(' -> acc++\n ')' -> acc--\n }\n when {\n acc == min -> count++\n acc < min -> {\n min = acc\n count = 1\n }\n }\n }\n\n return if(acc == 0) count else 0\n}\n\ndata class Ans(val b: Int, val l: Int, val r: Int) {\n override fun toString(): String = \"$b\\n${l+1} ${r+1}\"\n}\n\n/** IO code start */\n@JvmField val _reader = System.`in`.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(System.out, false)\ninline fun output(block: PrintWriter.()->Unit) { _writer.apply(block).flush() }\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun R._shuffle(rnd: Random, get: R.(Int) -> V, set: R.(Int, V) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, IntArray::get, IntArray::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, LongArray::get, LongArray::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, DoubleArray::get, DoubleArray::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, CharArray::get, CharArray::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\")\n\nimport java.io.PrintWriter\nimport java.util.ArrayDeque\nimport java.util.PriorityQueue\nimport java.util.StringTokenizer\nimport java.util.TreeSet\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln // immediate println for interactive\n\nfun main() {\n output {\n val n = readInt()\n val s = readLn().toCharArray()\n\n val ans = sequence {\n val init = Ans(s.beauty(), 0, 0)\n yield(init)\n if(init.b == 0) return@sequence\n\n for(i in 0 until n-1) {\n for(j in i+1 until n) {\n if(s[i] == s[j]) continue\n s.swap(i, j)\n yield(Ans(s.beauty(), i, j))\n s.swap(i, j)\n }\n }\n }.maxBy { it.b }!!\n\n println(ans)\n }\n}\n\nfun CharArray.swap(i: Int, j: Int) { this[i] = this[j].also { this[j] = this[i]} }\n\nfun CharArray.beauty(): Int {\n var min = 0\n var count = 0\n var acc = 0\n\n for(c in this) {\n when(c) {\n '(' -> acc++\n ')' -> acc--\n }\n when {\n acc == min -> count++\n acc < min -> {\n min = acc\n count = 1\n }\n }\n }\n\n return if(acc == 0) count else 0\n}\n\ndata class Ans(val b: Int, val l: Int, val r: Int) {\n override fun toString(): String = \"$b\\n${l+1} ${r+1}\"\n}\n\n/** IO code start */\n@JvmField val _reader = System.`in`.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(System.out, false)\ninline fun output(block: PrintWriter.()->Unit) { _writer.apply(block).flush() }\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun R._shuffle(rnd: Random, get: R.(Int) -> V, set: R.(Int, V) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, IntArray::get, IntArray::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, LongArray::get, LongArray::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, DoubleArray::get, DoubleArray::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, CharArray::get, CharArray::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()"}, {"source_code": "import kotlin.math.min\n\nfun main() {\n val n = readLine()!!.toInt()\n val ys = IntArray((2 * n) + 1)\n val line = readLine()!!\n for (i in 0 until 2 * n) {\n ys[i + 1] = ys[i] + if (line[i % n] == '(') 1 else -1\n }\n if (ys[n] != 0) {\n println(0)\n println(\"1 1\")\n return\n }\n val low = ys.min()!!\n val sums = Array(3) { IntArray((2 * n) + 1) }\n //println(\"ys = ${ys.contentToString()}\")\n //println(\"low = $low\")\n for (i in 1..2 * n) {\n for (j in 0..2) {\n sums[j][i] = sums[j][i - 1]\n }\n if (ys[i] - low <= 2) {\n sums[ys[i] - low][i]++\n }\n }\n /*for (j in 0..2) {\n println(\"sums[$j] = ${sums[j].contentToString()}\")\n }*/\n val last = IntArray(2)\n val nearest = Array(2) { IntArray(n + 1) }\n for (i in 2 * n downTo 1) {\n if (ys[i] - low <= 1) {\n last[ys[i] - low] = i\n }\n if (i <= n) {\n for (j in 0..1) {\n nearest[j][i] = last[j]\n }\n }\n }\n /*for (j in 0..1) {\n println(\"nearest[$j] = ${nearest[j].contentToString()}\")\n }*/\n var answer = sums[0][n]\n var al = 1\n var ar = 1\n for (i in 1..n) {\n if (line[i - 1] == '(') {\n var j = min(nearest[0][i], nearest[1][i])\n var pos = sums[0][n] + sums[2][j - 1] - sums[2][i - 1]\n if (pos > answer) {\n answer = pos\n al = i\n ar = j\n }\n if (nearest[1][i] < nearest[0][i]) {\n j = nearest[0][i]\n pos = sums[1][j - 1] - sums[1][i - 1]\n if (pos > answer) {\n answer = pos\n al = i\n ar = j\n }\n }\n }\n }\n println(answer)\n println(\"$al ${((ar - 1) % n) + 1}\")\n}"}], "negative_code": [], "src_uid": "2d10668fcc2d8e90e102b043f5e0578d"} {"nl": {"description": "Let's write all the positive integer numbers one after another from $$$1$$$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536...Your task is to print the $$$k$$$-th digit of this sequence.", "input_spec": "The first and only line contains integer $$$k$$$ ($$$1 \\le k \\le 10000$$$) — the position to process ($$$1$$$-based index).", "output_spec": "Print the $$$k$$$-th digit of the resulting infinite sequence.", "sample_inputs": ["7", "21"], "sample_outputs": ["7", "5"], "notes": null}, "positive_code": [{"source_code": "\nprivate fun readLn() = readLine()!!\nprivate fun readLong() = readLn().toLong()\n\nfun exp10(x: Long): Long {\n if (x == 0L) {\n return 1\n } else {\n return 10 * exp10(x - 1)\n }\n}\n\nfun kthDigit(k: Long): Char {\n val lev_lst: MutableList = mutableListOf(0L)\n for (lev in 1L..12L) {\n val step = exp10(lev - 1) * 9 * lev\n val nxt = step + lev_lst.last()\n lev_lst.add(nxt)\n }\n val arr = LongArray(lev_lst.size) { lev_lst[it] }\n\n fun binLevSearch(): Int {\n var lo = 0\n var hi = arr.lastIndex\n while (hi - lo > 1) {\n val m = (hi + lo) / 2\n //println(\"m=$m\")\n if (k > arr[m])\n lo = m\n else\n hi = m\n }\n\n return hi\n }\n\n val bound_idx = binLevSearch()\n val wid = bound_idx\n val base = arr[bound_idx - 1]\n val delta = k - base - 1\n val cnt = delta / wid\n val offs: Int = (delta % wid).toInt()\n val from = exp10(wid - 1L)\n val num = from + cnt\n val numstr = num.toString()\n val dgt: Char = numstr[offs]\n\n return dgt\n}\n\nfun main() {\n\n val k: Long = readLong()\n val c: Char = kthDigit(k)\n println(c)\n}\n"}, {"source_code": "import java.util.*\n\nfun main() {\n solveSequenceProblem()\n}\n\nfun solveSequenceProblem(){\n val scan = Scanner(System.`in`)\n val sequenceIndex = scan.nextLine().toInt()\n scan.close()\n var sequenceStr = \"\"\n for(index in 1..10000){\n sequenceStr += index.toString()\n if(sequenceStr.length >= sequenceIndex){\n print(sequenceStr[sequenceIndex-1])\n return\n }\n\n }\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val k = ir.nextInt()\n val line = StringBuilder()\n\n for (i in 0..2800)\n line.append(i)\n\n pw.print(line[k])\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextFloat(): Float {\n return java.lang.Float.parseFloat(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val k = ir.nextInt()\n val line: StringBuilder = StringBuilder(\"\")\n\n for (i in 0..2800)\n line.append(i)\n\n pw.print(line[k])\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextFloat(): Float {\n return java.lang.Float.parseFloat(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val k = ir.nextInt()\n var line = \"\"\n\n for (i in 0..2800)\n line += i\n\n pw.print(line[k])\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextFloat(): Float {\n return java.lang.Float.parseFloat(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "fun main() {\n\n var st = \"\"\n\n for(i in 1 .. 10000){\n st += i\n }\n\n val n = readLine()!!.toInt()\n\n println(st[n - 1])\n}"}, {"source_code": "fun main() {\n val k = readLine()!!.toInt()\n\n val seq = sequence {\n for(int in 1..Int.MAX_VALUE) {\n val digits = int.toString().map { it - '0' }\n yieldAll(digits)\n }\n }\n\n println(seq.elementAt(k - 1))\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\n\n/**\n * Created by cidgeedeng on 2019-09-23.\n */\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val inputReader = InputReader(inputStream)\n\n val k = inputReader.nextLong()\n var num = 0L\n var len = 0L\n\n while (len < k) {\n num++\n len += num.toString().length\n }\n\n val numStr = num.toString()\n print(numStr.subSequence(0, (numStr.length - (len - k)).toInt()).last())\n}\n\nclass InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream))\n private var tokenizer = StringTokenizer(\"\")\n\n /** get next word */\n @Throws(IOException::class)\n operator fun next(): String {\n while (!tokenizer.hasMoreTokens()) {\n tokenizer = StringTokenizer(\n reader.readLine()\n )\n }\n return tokenizer.nextToken()\n }\n\n fun nextLong() = next().toLong()\n fun nextInt() = next().toInt()\n fun nextDouble() = next().toDouble()\n fun nextFloat() = next().toFloat()\n}"}, {"source_code": "fun readLn() = readLine()!!\n\nfun main() {\n\tvar k = readLn().toLong();\n\tvar (p, np, numD) = listOf(1L, 10L, 1);\n\tk--;\n\twhile (true) {\n\t\tval x = minOf(k/numD, np-p);\n\n\t\tk -= x*numD;\n\n\t\tif (x < np-p) {\n\t\t\tprintln((p+x).toString()[k.toInt()]);\n\t\t\tbreak;\n\t\t}\n\n\t\tnumD++;\n\t\tp = np;\n\t\tnp *= 10;\n\t}\n\n}\n"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val sb = StringBuilder()\n for (i in 1 until 2780) sb.append(i)\n print(sb[readInt() - 1])\n}"}, {"source_code": "fun main(){\n\n var k = readLine()!!.toInt()\n\n //9 однозначных чисел\n //90 двузначных\n //900 трехзначных\n //9000 четырехзначных\n //числа максимум четырехзначные\n var p = 1\n for (i in 1..4){\n val s=i*9*p\n if (k<=s){\n //значит число i значное\n //нужно понять какое оно по счету среди i значных\n val pos = if(k%i==0){\n k/i\n }else{\n k/i+1\n }\n val num = p-1+pos//то самое число в которое попали\n //теперь нужно узнать какая именно цифра заданного числа\n val n = (k-1)%i\n println(num.toString()[n])\n break\n }else{\n k-=s\n p*=10\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val k = readLine()!!.toInt()\n var a = \"\"\n var b = 1\n while (a.length < k) {\n a += b.toString()\n b++\n }\n println(a[k - 1])\n}"}, {"source_code": "\n\nfun main() {\n\n val k = readLine()\n var i = 1\n\n var generateSequence = generateSequence{i++}.takeWhile { i<=10000 }\n print(generateSequence.joinToString(\"\")[k!!.toInt()-1])\n\n}"}, {"source_code": "\nprivate fun readLn() = readLine()!!\nprivate fun readLong() = readLn().toLong()\n\nfun exp10(x: Long): Long {\n if (x == 0L) {\n return 1\n } else {\n return 10 * exp10(x - 1)\n }\n}\n\nfun kthDigit(k: Long): Char {\n val lev_lst: MutableList = mutableListOf(0L)\n for (lev in 1L..12L) {\n val step = exp10(lev - 1) * 9 * lev\n val nxt = step + lev_lst.last()\n lev_lst.add(nxt)\n }\n val arr = LongArray(lev_lst.size) { lev_lst[it] }\n\n fun binLevSearch(): Int {\n var lo = 0\n var hi = arr.lastIndex\n while (hi - lo > 1) {\n val m = (hi + lo) / 2\n //println(\"m=$m\")\n if (k > arr[m])\n lo = m\n else\n hi = m\n }\n\n return hi\n }\n\n val bound_idx = binLevSearch()\n val wid = bound_idx\n val base = arr[bound_idx - 1]\n val delta = k - base - 1\n val cnt = delta / wid\n val offs: Int = (delta % wid).toInt()\n val from = exp10(wid - 1L)\n val num = from + cnt\n val numstr = num.toString()\n val dgt: Char = numstr[offs]\n\n return dgt\n}\n\nfun main() {\n\n val k: Long = readLong()\n val c: Char = kthDigit(k)\n println(c)\n}\n"}, {"source_code": "import kotlin.math.pow\n\nfun main() {\n val k = readLong()\n\n val regimeSeq = sequence {\n var acc = 1L\n\n var digits = 1\n var numInts = 9L\n\n while(true) {\n yield(acc)\n\n acc += digits * numInts\n digits++\n numInts *= 10\n }\n }.zipWithNext().map { (a, b) -> a until b }\n\n val regime = regimeSeq.withIndex().first { k in it.value }\n\n val digits = regime.index + 1\n val range = regime.value\n\n val number = ((k - range.first) / digits) + 10.0.pow(digits-1).toLong()\n val charIndex = ((k - range.first) % digits).toInt()\n\n println(number.toString()[charIndex])\n}\n\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readLongs() = readStrings().map { it.toLong() }\n\n// helper for competitive programming; faster at printing many lines than repeated println calls\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n fun println() { sb.append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit) { Output().apply(block).nowPrint() }"}, {"source_code": "import kotlin.math.pow\n\nfun main() {\n val k = readLong()\n\n val regimeSeq = sequence {\n var acc = 1L\n\n var digits = 1\n var numInts = 9L\n\n while(true) {\n yield(acc)\n\n acc += digits * numInts\n digits++\n numInts *= 10\n }\n }\n\n val regime = regimeSeq.zipWithNext().withIndex().first {\n it.value.second > k\n }\n\n val digits = regime.index + 1\n val range = regime.value.let { (a, b) -> a until b}\n\n val number = ((k - range.first) / digits) + 10.0.pow(digits-1).toLong()\n val charIndex = ((k - range.first) % digits).toInt()\n\n println(number.toString()[charIndex])\n}\n\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readLongs() = readStrings().map { it.toLong() }\n\n// helper for competitive programming; faster at printing many lines than repeated println calls\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n fun println() { sb.append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit) { Output().apply(block).nowPrint() }"}, {"source_code": "fun readLn() = readLine()!!\n\nfun main() {\n\tvar k = readLn().toLong();\n\tvar (p, np, numD) = listOf(1L, 10L, 1);\n\tk--;\n\twhile (true) {\n\t\tval x = minOf(k/numD, np-p);\n\n\t\tk -= x*numD;\n\n\t\tif (x < np-p) {\n\t\t\tprintln((p+x).toString()[k.toInt()]);\n\t\t\tbreak;\n\t\t}\n\n\t\tnumD++;\n\t\tp = np;\n\t\tnp *= 10;\n\t}\n\n}\n"}], "negative_code": [{"source_code": "import java.util.*\n\nfun main() {\n solveSequenceProblem()\n}\n\nfun solveSequenceProblem(){\n val scan = Scanner(System.`in`)\n val sequenceIndex = scan.nextInt()\n var sequenceStr = \"\"\n for(index in 1..10000){\n sequenceStr += index\n if(sequenceStr.length == sequenceIndex){\n print(sequenceStr.last())\n scan.close()\n return\n }\n\n }\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val k = ir.nextInt()\n var line = \"\"\n\n for (i in 1..2800)\n line += i\n \n pw.print(line[k])\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextFloat(): Float {\n return java.lang.Float.parseFloat(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "\n\nfun main() {\n\n val k = readLine()\n var i = 1\n\n var generateSequence = generateSequence{i++}.takeWhile { i<=10000 }\n print(generateSequence.elementAt(k!!.toInt()-1))\n\n}"}, {"source_code": "\n\nfun main() {\n\n val k = readLine()\n var i = 1\n\n var generateSequence = generateSequence{i++}.takeWhile { i<=10000 }\n print(generateSequence.elementAt(k!!.toInt()))\n\n}"}], "src_uid": "1503d761dd4e129fb7c423da390544ff"} {"nl": {"description": "It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces.Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: Each piece of each cake is put on some plate; Each plate contains at least one piece of cake; No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x pieces of cake.Help Ivan to calculate this number x!", "input_spec": "The first line contains three integers n, a and b (1 ≤ a, b ≤ 100, 2 ≤ n ≤ a + b) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.", "output_spec": "Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x pieces of cake.", "sample_inputs": ["5 2 3", "4 7 10"], "sample_outputs": ["1", "3"], "notes": "NoteIn the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3."}, "positive_code": [{"source_code": "import java.util.Queue\nimport java.util.LinkedList\nimport kotlin.collections.*\nimport java.io.PrintWriter\nimport kotlin.math.*\nimport java.util.Scanner\nimport java.lang.Math.floorMod\nimport java.lang.Math.floorDiv\nimport java.io.File\nimport kotlin.comparisons.compareBy\n \n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n \nconst val _BUFFER_SIZE = 1 shl 16\n@JvmField val _buffer = ByteArray(_BUFFER_SIZE)\n@JvmField var _bufferPt = 0\n@JvmField var _bytesRead = 0\n \ntailrec fun readChar(): Char {\n if(_bufferPt == _bytesRead) {\n _bufferPt = 0\n _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)\n }\n return if(_bytesRead < 0) Char.MIN_VALUE\n else {\n val c = _buffer[_bufferPt++].toChar()\n if (c == '\\r') readChar() else c\n }\n}\n \n/** @param skipNext Whether to skip the next character (usually whitespace), defaults to true */\nfun readCharArray(n: Int, skipNext: Boolean = true): CharArray {\n val res = CharArray(n) { readChar() }\n if(skipNext) readChar()\n return res\n}\n \nfun readLine(): String? {\n var c = readChar()\n return if(c == Char.MIN_VALUE) null\n else buildString {\n while(c != '\\n' && c != Char.MIN_VALUE) {\n append(c)\n c = readChar()\n }\n }\n}\nfun readLn() = readLine()!!\n \nfun read() = buildString {\n var c = readChar()\n while(c <= ' ') {\n if(c == Char.MIN_VALUE) return@buildString\n c = readChar()\n }\n do {\n append(c)\n c = readChar()\n } while(c > ' ')\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n \n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\nfun main() { _writer.solve(); _writer.flush() }\n\nval mxn=1000000\nval INF=1000000007\n// kotlinc test.kt -include-runtime -d test.jar && java -jar test.jar\n// var adj=MutableList (mxn) {mutableListOf> ()}\n// var vis=BooleanArray(mxn)\n// var a=IntArray(mxn)\n// var ok=true\n// val INF=1000000000+7\n\n\nfun testcase()\n{\n var(n,a,b) = readInts(3)\n var ans=0\n for(i in 1..n-1)\n {\n var first=a/i\n var second=b/(n-i)\n if(first==0||second==0) continue;\n ans=max(ans,min(first,second))\n }\n println(ans)\n\n\n\n\n\n\n\n\n\n\n\n\n\n}\n\nfun PrintWriter.solve() {\n var t=1\n // t=readInt()\n while(t>0)\n {\n t--\n // var (a,b) = readLine()!!.trim().split(\"\\\\s+\".toRegex()).map (String::toInt)\n // var arr=readLine()!!.split(\" \").map {it.toInt()} (read array)\n // var(n,a) = readLine()!!.split(' ').map{it.toInt()}\n testcase()\n }\n}\n"}, {"source_code": "import java.lang.Integer.max\nimport java.lang.Integer.min\nimport java.util.*\n\nfun main (args: Array) = with(Scanner(System.`in`)) {\n val (n, a, b) = arrayOf(nextInt(), nextInt(), nextInt())\n var maximum = 0\n for (x in 1 until n)\n maximum = max(maximum, min(a / x, b / (n - x)))\n println(maximum)\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val res = IntArray(3, { nextInt() }).shakeForMeBaby()\n print(\"$res\")\n}\n\nfun IntArray.shakeForMeBaby(): Int {\n var left = 1\n var right = min(this[1], this[2])\n while (left <= right) {\n val mid = (left + right) / 2\n when {\n this[1] / mid + this[2] / mid < this[0] -> right = mid - 1\n else -> left = mid + 1\n }\n }\n return left - 1\n}\n"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numPlates, numA, numB) = readInts()\n var sol = 1\n while (numA / sol + numB / sol >= numPlates && numA / sol > 0 && numB / sol > 0) sol++\n print(sol - 1)\n}"}], "negative_code": [{"source_code": "import java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val a = IntArray(3, { nextInt() })\n print(\"${a.shakeForMeBaby()}\")\n}\n\nfun IntArray.shakeForMeBaby(): Int {\n var left = 0\n var right = min(this[1], this[2])\n while (left + 1 < right) {\n val mid = (left + right) / 2\n when {\n this[1] / mid + this[2] / mid < this[0] -> right = mid\n else -> left = mid\n }\n }\n return left\n}\n"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numPlates, numA, numB) = readInts()\n var sol = 1\n while (numA / sol + numB / sol >= numPlates) sol++\n print(sol - 1)\n}"}], "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e"} {"nl": {"description": "Dante is engaged in a fight with \"The Savior\". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of damage. In order to break the shield Dante has to deal exactly c units of damage. Find out if this is possible.", "input_spec": "The first line of the input contains three integers a, b, c (1 ≤ a, b ≤ 100, 1 ≤ c ≤ 10 000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.", "output_spec": "Print \"Yes\" (without quotes) if Dante can deal exactly c damage to the shield and \"No\" (without quotes) otherwise.", "sample_inputs": ["4 6 15", "3 2 7", "6 11 6"], "sample_outputs": ["No", "Yes", "Yes"], "notes": "NoteIn the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. "}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashSet\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val a: Int = ir.nextInt()\n val b: Int = ir.nextInt()\n val c: Int = ir.nextInt()\n val first: Int = (c / a) + 1\n val second: Int = (c / b) + 1\n\n for (i in 0 until first) {\n for (j in 0 until second) {\n if (a * i + b * j == c) {\n pw.print(\"Yes\")\n return\n }\n }\n }\n\n pw.print(\"No\")\n\n}\n\n\n\nprivate fun sort(array: IntArray, barray: IntArray, low: Int, high: Int) {\n\n var i = low\n var j = high\n val x = array[low + (high - low) / 2]\n\n do {\n while (array[i] < x) ++i\n while (array[j] > x) --j\n if (i <= j) {\n val tmp = array[i]\n array[i] = array[j]\n array[j] = tmp\n\n val pmt = barray[i]\n barray[i] = barray[j]\n barray[j] = pmt\n\n i++\n j--\n }\n } while (i <= j)\n\n if (low < j) sort(array, barray, low, j)\n if (i < high) sort(array, barray, i, high)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashSet\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val a: Int = ir.nextInt()\n val b: Int = ir.nextInt()\n val c: Int = ir.nextInt()\n\n for (i in 0 until (c / a) + 1) {\n for (j in 0 until (c / b) + 1) {\n if (a * i + b * j == c) {\n pw.print(\"Yes\")\n return\n }\n }\n }\n\n pw.print(\"No\")\n\n}\n\n\n\nprivate fun sort(array: IntArray, barray: IntArray, low: Int, high: Int) {\n\n var i = low\n var j = high\n val x = array[low + (high - low) / 2]\n\n do {\n while (array[i] < x) ++i\n while (array[j] > x) --j\n if (i <= j) {\n val tmp = array[i]\n array[i] = array[j]\n array[j] = tmp\n\n val pmt = barray[i]\n barray[i] = barray[j]\n barray[j] = pmt\n\n i++\n j--\n }\n } while (i <= j)\n\n if (low < j) sort(array, barray, low, j)\n if (i < high) sort(array, barray, i, high)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (a, b, c) = readInts()\n for (x in 0..c / a)\n if ((c - x * a) % b == 0) return print(\"Yes\")\n print(\"No\")\n}"}], "negative_code": [], "src_uid": "e66ecb0021a34042885442b336f3d911"} {"nl": {"description": "Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it is constant; after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6].Write a program that checks if an array is unimodal.", "input_spec": "The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000) — the elements of the array.", "output_spec": "Print \"YES\" if the given array is unimodal. Otherwise, print \"NO\". You can output each letter in any case (upper or lower).", "sample_inputs": ["6\n1 5 5 5 4 2", "5\n10 20 30 20 10", "4\n1 2 1 2", "7\n3 3 3 3 3 3 3"], "sample_outputs": ["YES", "YES", "NO", "YES"], "notes": "NoteIn the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively)."}, "positive_code": [{"source_code": "import java.util.*\n\n/**\n * Created by thuanle on 7/13/17.\n */\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n var old = 0\n var step = 0\n repeat(n, {\n val x = sc.nextInt()\n when {\n old < x -> {\n if (step > 0) {\n println(\"NO\")\n return\n }\n }\n old == x -> {\n when (step) {\n 0 -> step = 1\n 2 -> {\n println(\"NO\")\n return\n }\n }\n }\n old > x -> {\n step = 2\n }\n }\n old = x\n })\n println(\"YES\")\n}"}, {"source_code": "/**\n * Created by abods on 7/23/2017.\n */\nfun main(args: Array) {\n var n:Int = readLine()!!.toInt()\n var line:String= readLine()!!\n var arr1 = Array(n){\"\"}\n arr1= line.split(\" \").toTypedArray()\n\n var arr = Array(n){0}\n\n for(a in 0.. arr1.size-1)\n {arr[a]=arr1[a].toInt()}\n\n\n var x:String = \"\"\n\n for(i in 1..arr.size-1)\n {\n if(arr[i]arr[i-1]) {\n if(x!=\"\") {\n if (x[x.length - 1] != '>') {\n x += '>'\n }\n }\n else\n {\n x += '>'\n }\n }\n\n if(arr[i]==arr[i-1]) {\n if(x!=\"\") {\n if (x[x.length - 1] != '=') {\n x += '='\n }\n }\n else\n {\n x += '='\n }\n }\n }\n if(x==\">=<\"||x==\"><\"||x==\">=\"||x==\"=<\"||x==\"=\"||x==\"\"||x==\">\"||x==\"<\") {\n println(\"YES\")\n }\n else\n {\n println(\"NO\")}\n}\n\n"}, {"source_code": "fun main() {\n var n = readLine()!!.toInt()\n var list = readLine()!!.split(' ').map { it.toInt() }.toList().toMutableList()\n list.add(0, 0)\n list.add(list.size, 0)\n var x = 1\n while (list[x] < list[x + 1] && x < n) x++\n while (list[x] == list[x + 1] && x < n) x++\n while (list[x] > list[x + 1] && x < n) x++\n if (x == n){\n println(\"YES\")\n }else println(\"NO\")\n}\n\n"}, {"source_code": "enum class State {\n UP, FLAT, DOWN\n}\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n readLine()\n val arr = readInts()\n var state = State.UP\n for (pos in 1..arr.lastIndex) {\n when (state) {\n State.UP -> {\n when {\n arr[pos] == arr[pos - 1] -> state = State.FLAT\n arr[pos] < arr[pos - 1] -> state = State.DOWN\n }\n }\n State.FLAT -> {\n when {\n arr[pos] < arr[pos - 1] -> state = State.DOWN\n arr[pos] > arr[pos - 1] -> return print(\"NO\")\n }\n }\n else -> if (arr[pos] >= arr[pos - 1]) return print(\"NO\")\n }\n }\n print(\"YES\")\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\nfun DataReader.solve(out: PrintWriter) {\n val n = nextInt()\n\n val a = readIntArray(n).toList()\n\n for (i in a.indices) {\n for (j in i..a.lastIndex) {\n if (a.subList(i, j + 1).any { it != a[i] }) continue\n val q = a.subList(0, i)\n if (q.drop(1).zip(q).any { it.first <= it.second } || (q.isNotEmpty() && q.last() >= a[i])) continue\n\n val w = a.subList(j + 1, a.size)\n if (w.drop(1).zip(w).any { it.first >= it.second } || (w.isNotEmpty() && w[0] >= a[i])) continue\n\n out.print(\"YES\")\n\n return\n }\n }\n\n out.print(\"NO\")\n}\n\nfun Boolean.toYesNo() = if (this) \"YES\" else \"NO\"\n\nclass DataReader(private val reader: BufferedReader) {\n var st : StringTokenizer? = null\n companion object {\n fun createFromFile(name: String) = DataReader(BufferedReader(FileReader(name)))\n }\n\n fun next() : String? {\n while (st == null || !st!!.hasMoreTokens()) {\n val s = reader.readLine() ?: return null\n st = StringTokenizer(s)\n }\n\n return st?.nextToken()\n }\n\n fun nextToken() = next()!!\n\n fun nextInt() = nextToken().toInt()\n fun nextLong() = nextToken().toLong()\n fun readIntArray(n: Int) : IntArray {\n val result = IntArray(n)\n result.indices.forEach { i -> result[i] = nextInt() }\n return result\n }\n\n fun readLongArray(n: Int) : LongArray {\n val result = LongArray(n)\n result.indices.forEach { i -> result[i] = nextLong() }\n return result\n }\n\n fun nextLine() = reader.readLine()\n}\n\nfun main(args: Array) {\n val r: Reader\n val out: PrintWriter\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n r = FileReader(\"input.txt\")\n out = PrintWriter(\"output.txt\")\n } else {\n r = InputStreamReader(System.`in`)\n out = PrintWriter(System.out)\n }\n\n DataReader(BufferedReader(r)).solve(out)\n out.flush()\n}"}], "negative_code": [{"source_code": "import java.util.*\n\n/**\n * Created by thuanle on 7/13/17.\n */\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n var old = 0\n var step = 0\n repeat(n, {\n val x = sc.nextInt()\n when {\n old < x -> {\n if (step > 0) {\n println(\"NO\")\n return\n }\n }\n old == x -> {\n when (step) {\n 0 -> step = 1\n 2 -> {\n println(\"NO\")\n return\n }\n }\n }\n old > x -> {\n step = 2\n }\n }\n old = x\n })\n if (step == 0) {\n println(\"NO\")\n } else {\n println(\"YES\")\n }\n}"}, {"source_code": "/**\n * Created by abods on 7/23/2017.\n */\nfun main(args: Array) {\n var n:Int = readLine()!!.toInt()\n var line:String= readLine()!!\n var arr1 = Array(n){\"\"}\n arr1= line.split(\" \").toTypedArray()\n\n var arr = Array(n){0}\n\n for(a in 0.. arr1.size-1)\n {arr[a]=arr1[a].toInt()}\n\n\n var x:String = \"\"\n\n for(i in 1..arr.size-1)\n {\n if(arr[i]arr[i-1]) {\n if(x!=\"\") {\n if (x[x.length - 1] != '>') {\n x += '>'\n }\n }\n else\n {\n x += '>'\n }\n }\n\n if(arr[i]==arr[i-1]) {\n if(x!=\"\") {\n if (x[x.length - 1] != '=') {\n x += '='\n }\n }\n else\n {\n x += '='\n }\n }\n }\n if(x==\">=<\"||x==\"><\"||x==\">=\"||x==\"<=\"||x==\"=\"||x==\"\") {\n println(\"YES\")\n }\n else\n {\n println(\"NO\")}\n}\n\n"}, {"source_code": "/**\n * Created by abods on 7/23/2017.\n */\nfun main(args: Array) {\n var n:Int = readLine()!!.toInt()\n var line:String= readLine()!!\n var arr1 = Array(n){\"\"}\n arr1= line.split(\" \").toTypedArray()\n\n var arr = Array(n){0}\n\n for(a in 0.. arr1.size-1)\n {arr[a]=arr1[a].toInt()}\n\n\n var x:String = \"\"\n\n for(i in 1..arr.size-1)\n {\n if(arr[i]arr[i-1]) {\n if(x!=\"\") {\n if (x[x.length - 1] != '>') {\n x += '>'\n }\n }\n else\n {\n x += '>'\n }\n }\n\n if(arr[i]==arr[i-1]) {\n if(x!=\"\") {\n if (x[x.length - 1] != '=') {\n x += '='\n }\n }\n else\n {\n x += '='\n }\n }\n }\n if(x==\">=<\"||x==\"><\"||x==\">=\"||x==\"=<\"||x==\"=\"||x==\"\") {\n println(\"YES\")\n }\n else\n {\n println(\"NO\")}\n}\n\n"}, {"source_code": "/**\n * Created by abods on 7/23/2017.\n */\nfun main(args: Array) {\n var n:Int = readLine()!!.toInt()\n var line:String= readLine()!!\n var arr = Array(n){\"\"}\n arr= line.split(\" \").toTypedArray()\n arr.to(Int)\n\n var x:String = \"\"\n\n for(i in 1..arr.size-1)\n {\n if(arr[i]arr[i-1]) {\n if(x!=\"\") {\n if (x[x.length - 1] != '>') {\n x += '>'\n }\n }\n else\n {\n x += '>'\n }\n }\n\n if(arr[i]==arr[i-1]) {\n if(x!=\"\") {\n if (x[x.length - 1] != '=') {\n x += '='\n }\n }\n else\n {\n x += '='\n }\n }\n }\n if(x==\">=<\"||x==\"><\"||x==\">=\"||x==\"<=\"||x==\"=\") {\n println(\"YES\")\n }\n else\n {\n println(\"NO\")}\n}\n\n"}, {"source_code": "/**\n * Created by abods on 7/23/2017.\n */\nfun main(args: Array) {\n var n:Int = readLine()!!.toInt()\n var line:String= readLine()!!\n var arr1 = Array(n){\"\"}\n arr1= line.split(\" \").toTypedArray()\n\n var arr = Array(n){0}\n\n for(a in 0.. arr1.size-1)\n {arr[a]=arr1[a].toInt()}\n\n\n var x:String = \"\"\n\n for(i in 1..arr.size-1)\n {\n if(arr[i]arr[i-1]) {\n if(x!=\"\") {\n if (x[x.length - 1] != '>') {\n x += '>'\n }\n }\n else\n {\n x += '>'\n }\n }\n\n if(arr[i]==arr[i-1]) {\n if(x!=\"\") {\n if (x[x.length - 1] != '=') {\n x += '='\n }\n }\n else\n {\n x += '='\n }\n }\n }\n if(x==\">=<\"||x==\"><\"||x==\">=\"||x==\"<=\"||x==\"=\") {\n println(\"YES\")\n }\n else\n {\n println(\"NO\")}\n}\n\n"}], "src_uid": "5482ed8ad02ac32d28c3888299bf3658"} {"nl": {"description": "When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? — That's right, using counting sticks! An here's our new task: An expression of counting sticks is an expression of type:[ A sticks][sign +][B sticks][sign =][C sticks] (1 ≤ A, B, C). Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.We really aren't fabulous at arithmetics. Can you help us?", "input_spec": "The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 ≤ A, B, C ≤ 100.", "output_spec": "If there isn't a way to shift the stick so the expression becomes correct, print on a single line \"Impossible\" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters. If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.", "sample_inputs": ["||+|=|||||", "|||||+||=||", "|+|=||||||", "||||+||=||||||"], "sample_outputs": ["|||+|=||||", "Impossible", "Impossible", "||||+||=||||||"], "notes": "NoteIn the first sample we can shift stick from the third group of sticks to the first one.In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.There is no answer in the third sample because we cannot remove sticks from the expression.In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks."}, "positive_code": [{"source_code": "fun main() {\n val (a, b, c) = readLine()!!.split(\"+\", \"=\").map { it.length }\n\n fun printAns(a: Int, b: Int, c: Int) = println(\"${(1..a).joinToString(\"\") { \"|\" }}+${(1..b).joinToString(\"\") { \"|\" }}=${(1..c).joinToString(\"\") { \"|\" }}\")\n\n when {\n a + b == c -> printAns(a, b, c)\n a + b - 1 == c + 1 -> when {\n a > 1 -> printAns(a - 1, b, c + 1)\n b > 1 -> printAns(a, b - 1, c + 1)\n else -> println(\"Impossible\")\n }\n a + b + 1 == c - 1 -> printAns(a, b + 1, c - 1)\n else -> println(\"Impossible\")\n }\n}"}, {"source_code": "\nfun main() {\n val expression= readLine()!!.split(\"[=+]\".toRegex())\n val expressionInt=expression.map { it.length }\n// println(expressionInt)\n val first=expressionInt[0]\n val second=expressionInt[1]\n val third=expressionInt[2]\n if (first+second==third)\n println(\"${expression[0]}+${expression[1]}=${expression[2]}\")\n else\n if ((first+1)+second==(third-1))\n println(\"${expression[0].plus(\"|\")}+${expression[1]}=${expression[2].drop(1)}\")\n else if (first+(second+1)==(third-1))\n println(\"${expression[0]}+${expression[1].plus(\"|\")}=${expression[2].drop(1)}\")\n else if (first+(second-1)==(third+1) && expression[1].length>1)\n println(\"${expression[0]}+${expression[1].drop(1)}=${expression[2].plus(\"|\")}\")\n else if ((first-1)+second==(third+1)&& expression[0].length>1)\n println(\"${expression[0].drop(1)}+${expression[1]}=${expression[2].plus(\"|\")}\")\n else\n println(\"Impossible\")\n}"}, {"source_code": "/**\n * https://codeforces.com/problemset/problem/394/A\n * \n * A. Counting Sticks\n */\n\n fun main() {\n val input = readLine();\n val arr = input.toString().split('=')\n val c = arr.get(1)\n val ab = arr.get(0).split('+')\n val a = ab.get(0)\n val b = ab.get(1)\n var lenA = a.length\n var lenB = b.length\n var lenC = c.length\n\n val minus = lenC - lenA - lenB\n\n if (minus == 0) {\n print(input)\n } else if (minus == 2) {\n lenA += 1\n lenC -= 1\n printOutput(lenA, lenB, lenC)\n } else if (minus == -2) {\n lenC += 1\n if (lenA > 1) {\n lenA -= 1\n } else {\n lenB -= 1\n }\n printOutput(lenA, lenB, lenC)\n } else {\n print(\"Impossible\")\n }\n }\n\n fun printOutput(a: Int, b: Int, c:Int) {\n var rs: String = \"\"\n for (i in 0 until a) {\n rs += \"|\"\n }\n rs += \"+\"\n for (i in 0 until b) {\n rs += \"|\"\n }\n rs += \"=\"\n for (i in 0 until c) {\n rs += \"|\"\n }\n print(rs)\n } "}], "negative_code": [{"source_code": "fun main() {\n val (a, b, c) = readLine()!!.split(\"+\", \"=\").map { it.length }\n\n fun printAns(a: Int, b: Int, c: Int) = println(\"${(1..a).joinToString(\"\") { \"|\" }}+${(1..b).joinToString(\"\") { \"|\" }}=${(1..c).joinToString(\"\") { \"|\" }}\")\n\n when {\n a + b == c -> printAns(a, b, c)\n a + b - 1 == c + 1 -> when {\n a > 1 -> printAns(a - 1, b, c + 1)\n b > 1 -> printAns(a, b - 1, c + 1)\n else -> println(\"Impossible\")\n }\n else -> println(\"Impossible\")\n }\n}"}, {"source_code": "\nfun main() {\n val expression= readLine()!!.split(\"[=+]\".toRegex())\n val expressionInt=expression.map { it.length }\n val first=expressionInt[0]\n val second=expressionInt[1]\n val third=expressionInt[2]\n if (first+second==third)\n println(\"$expression\")\n if ((first+1)+second==(third-1))\n println(\"${expression[0].plus(\"|\")}+${expression[1]}=${expression[2].drop(1)}\")\n else if (first+(second+1)==(third-1))\n println(\"${expression[0]}+${expression[1].plus(\"|\")}=${expression[2].drop(1)}\")\n else\n println(\"IMPOSSIBLE\")\n}"}, {"source_code": "\nfun main() {\n val expression= readLine()!!.split(\"[=+]\".toRegex())\n val expressionInt=expression.map { it.length }\n val first=expressionInt[0]\n val second=expressionInt[1]\n val third=expressionInt[2]\n if (first+second==third)\n println(\"${expression[0]}+${expression[1]}=${expression[2]}\")\n else\n if ((first+1)+second==(third-1))\n println(\"${expression[0].plus(\"|\")}+${expression[1]}=${expression[2].drop(1)}\")\n else if (first+(second+1)==(third-1))\n println(\"${expression[0]}+${expression[1].plus(\"|\")}=${expression[2].drop(1)}\")\n else\n println(\"Impossible\")\n}"}, {"source_code": "\nfun main() {\n val expression= readLine()!!.split(\"[=+]\".toRegex())\n val expressionInt=expression.map { it.length }\n val first=expressionInt[0]\n val second=expressionInt[1]\n val third=expressionInt[2]\n if (first+second==third)\n println(\"${expression[0]}+${expression[1]}=${expression[2]}\")\n when {\n (first+1)+second==(third-1) -> println(\"${expression[0].plus(\"|\")}+${expression[1]}=${expression[2].drop(1)}\")\n first+(second+1)==(third-1) -> println(\"${expression[0]}+${expression[1].plus(\"|\")}=${expression[2].drop(1)}\")\n else -> println(\"Impossible\")\n }\n}"}, {"source_code": "\nfun main() {\n val expression= readLine()!!.split(\"[=+]\".toRegex())\n val expressionInt=expression.map { it.length }\n println(expressionInt)\n val first=expressionInt[0]\n val second=expressionInt[1]\n val third=expressionInt[2]\n if (first+second==third)\n println(\"${expression[0]}+${expression[1]}=${expression[2]}\")\n else\n if ((first+1)+second==(third-1))\n println(\"${expression[0].plus(\"|\")}+${expression[1]}=${expression[2].drop(1)}\")\n else if (first+(second+1)==(third-1))\n println(\"${expression[0]}+${expression[1].plus(\"|\")}=${expression[2].drop(1)}\")\n else if ((first-1)+second==(third+1))\n println(\"${expression[0].drop(1)}+${expression[1]}=${expression[2].plus(\"|\")}\")\n else if (first+(second-1)==(third+1))\n println(\"${expression[0]}+${expression[1].drop(1)}=${expression[2].plus(\"|\")}\")\n else\n println(\"Impossible\")\n}"}, {"source_code": "\nfun main() {\n val expression= readLine()!!.split(\"[=+]\".toRegex())\n val expressionInt=expression.map { it.length }\n// println(expressionInt)\n val first=expressionInt[0]\n val second=expressionInt[1]\n val third=expressionInt[2]\n if (first+second==third)\n println(\"${expression[0]}+${expression[1]}=${expression[2]}\")\n else\n if ((first+1)+second==(third-1))\n println(\"${expression[0].plus(\"|\")}+${expression[1]}=${expression[2].drop(1)}\")\n else if (first+(second+1)==(third-1))\n println(\"${expression[0]}+${expression[1].plus(\"|\")}=${expression[2].drop(1)}\")\n else if ((first-1)+second==(third+1))\n println(\"${expression[0].drop(1)}+${expression[1]}=${expression[2].plus(\"|\")}\")\n else if (first+(second-1)==(third+1))\n println(\"${expression[0]}+${expression[1].drop(1)}=${expression[2].plus(\"|\")}\")\n else\n println(\"Impossible\")\n}"}, {"source_code": "\nfun main() {\n val expression= readLine()!!.split(\"[=+]\".toRegex())\n val expressionInt=expression.map { it.length }\n val first=expressionInt[0]\n val second=expressionInt[1]\n val third=expressionInt[2]\n if (first+second==third)\n println(\"$expression\")\n if ((first+1)+second==(third-1))\n println(\"${expression[0].plus(\"|\")}+${expression[1]}=${expression[2].drop(1)}\")\n else if (first+(second+1)==(third-1))\n println(\"${expression[0]}+${expression[1].plus(\"|\")}=${expression[2].drop(1)}\")\n else\n println(\"Impossible\")\n}"}], "src_uid": "ee0aaa7acf127e9f3a9edafc58f4e2d6"} {"nl": {"description": "The only king stands on the standard chess board. You are given his position in format \"cd\", where c is the column from 'a' to 'h' and d is the row from '1' to '8'. Find the number of moves permitted for the king.Check the king's moves here https://en.wikipedia.org/wiki/King_(chess). King moves from the position e4 ", "input_spec": "The only line contains the king's position in the format \"cd\", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'.", "output_spec": "Print the only integer x — the number of moves permitted for the king.", "sample_inputs": ["e4"], "sample_outputs": ["8"], "notes": null}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args : Array) {\n //====== Input preparations ========================================================\n// val fin = BufferedReader(FileReader(\"a.in\"))\n val fin = BufferedReader(InputStreamReader(System.`in`))\n val fout = PrintWriter (System.out)\n var tokenizer = StringTokenizer(\"\")\n fun next() : String {\n while (!tokenizer.hasMoreTokens())\n tokenizer = StringTokenizer(fin.readLine())\n return tokenizer.nextToken()\n }\n fun nextInt() = next().toInt()\n fun nextPairDec() = nextInt()-1 to nextInt()-1\n //====== Solution below ============================================================\n val s = next()\n fun mirror(a: Int) = if (a > 3) 7 - a else a\n val a = mirror(s[0] - 'a')\n val b = mirror(s[1] - '1')\n if (a > 0 && b > 0)\n fout.print(8)\n else if (a == 0 && b == 0)\n fout.print(3)\n else\n fout.print(5)\n\n\n fout.close()\n fin.close()\n}\n\n"}, {"source_code": "fun main() {\n var str = readLine()!!\n if (str[1] == '1' || str[1] == '8') {\n if (str[0] == 'a' || str[0] == 'h') {\n println(3)\n return\n } else {\n println(5)\n return\n }\n } else {\n if (str[0] == 'a' || str[0] == 'h'){\n println(5)\n }else{\n println(8)\n }\n }\n\n}"}, {"source_code": "fun main() {\n val input = readLine()!!.toCharArray()\n if ((input[0] == 'b' || input[0] == 'c' || input[0] == 'd' || input[0] == 'e' || input[0] == 'f' || input[0] == 'g') && (input[1] == '2' || input[1] == '3' || input[1] == '4' || input[1] == '5' || input[1] == '6' || input[1] == '7')) print(\"8\") else if (((input[0] == 'b' || input[0] == 'c' || input[0] == 'd' || input[0] == 'e' || input[0] == 'f' || input[0] == 'g') && (input[1] == '1' || input[1] == '8')) || ((input[0] == 'a' || input[0] == 'h') && (input[1] == '2' || input[1] == '3' || input[1] == '4' || input[1] == '5' || input[1] == '6' || input[1] == '7'))) print(\"5\") else print(\"3\")\n}"}, {"source_code": "fun main() {\n val pos = readLine()!!\n if (pos in setOf(\"a1\", \"h1\", \"a8\", \"h8\")) return print(3)\n if (pos[0] == 'a' || pos[0] == 'h' || pos[1] == '1' || pos[1] == '8') return print(5)\n print(8)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.File\nimport java.io.PrintWriter\n\nfun main(args: Array) {\n val onlineJudge = System.getProperty(\"ONLINE_JUDGE\") == \"true\"\n val input = if (onlineJudge) System.`in`.bufferedReader() else File(\"input.txt\").bufferedReader()\n val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File(\"output.txt\"))\n\n solve(input, output)\n\n output.flush()\n output.close()\n}\n\nprivate fun solve(input: BufferedReader, output: PrintWriter) {\n val line = input.readLine()\n val c = line[0]\n val n = line[1]\n\n val top = when {\n n == '1' -> 0\n c == 'a' || c == 'h' -> 2\n else -> 3\n }\n\n val bottom = when {\n n == '8' -> 0\n c == 'a' || c == 'h' -> 2\n else -> 3\n }\n\n val leftRight = when {\n c == 'a' || c == 'h' -> 1\n else -> 2\n }\n\n output.println(top + bottom + leftRight)\n}"}], "negative_code": [{"source_code": "fun main() {\n val pos = readLine()!!\n if (pos in setOf(\"a1\", \"h1\", \"a8\", \"h8\")) return print(4)\n if (pos[0] == 'a' || pos[0] == 'h' || pos[1] == '1' || pos[1] == '8') return print(5)\n print(8)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.File\nimport java.io.PrintWriter\n\nfun main(args: Array) {\n val onlineJudge = System.getProperty(\"ONLINE_JUDGE\") == \"true\"\n val input = if (onlineJudge) System.`in`.bufferedReader() else File(\"input.txt\").bufferedReader()\n val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File(\"output.txt\"))\n\n solve(input, output)\n}\n\nprivate fun solve(input: BufferedReader, output: PrintWriter) {\n //todo implement the task solution\n}"}], "src_uid": "6994331ca6282669cbb7138eb7e55e01"} {"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": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.ceil\nimport kotlin.math.floor\nimport kotlin.math.log2\nimport kotlin.math.sqrt\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n var str = scanner.next()\n var i = 1;\n val d = ArrayList()\n while (i * i <= n) {\n if (n % i == 0) {\n str = str.substring(0, i).reversed() + str.substring(i)\n if (n / i != i)\n d.add(n / i)\n }\n i++\n }\n d.sort()\n for (j in d)\n str = str.substring(0, j).reversed() + if (j != n) str.substring(j) else \"\"\n println(str)\n\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\n//class Pair(var a: Int, var b: Int): Comparable {\n// override fun compareTo(other: Pair): Int {\n// return b - a - other.b + other.a\n// }\n//}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n val n = r.readLine()!!.toInt()\n //val v = r.readLine()!!.split(\" \").map { it.toLong() }.sorted()\n var s = r.readLine()!!\n fun fac(i:Int):List{\n val ans = mutableListOf()\n for (j in 1..i){\n if (i%j==0) ans += j\n }\n return ans\n }\n val swap = fac(n)\n swap.forEach {\n s = s.substring(0, it).reversed()+s.substring(it, n)\n }\n println(s)\n}"}, {"source_code": "\nimport java.io.*\nimport java.util.*\n\nfun solve() {\n\n val n = nextInt()\n var s = next()\n\n for (d in 2..n) {\n if (n % d == 0) {\n val t = s.substring(0, d).reversed()\n s = s.replaceRange(0, d, t)\n }\n }\n\n print(s)\n}\n\n\n\n\nfun hasNext() : Boolean {\n while (!st.hasMoreTokens()) {\n st = StringTokenizer(input.readLine() ?: return false)\n }\n return true\n}\n\nfun next() = if (hasNext()) st.nextToken()!! else throw RuntimeException(\"No tokens\")\n\nfun nextInt() = next().toInt()\n\nfun nextLong() = next().toLong()\n\nfun nextDouble() = next().toDouble()\n\nfun nextLine() = if (hasNext()) st.nextToken(\"\\n\")!! else throw RuntimeException(\"No tokens\")\n\nfun nextArray(n : Int) = IntArray(n, { nextInt() })\n\nval ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n\nvar input = when(ONLINE_JUDGE) {\n true -> BufferedReader(InputStreamReader(System.`in`), 32768)\n else -> BufferedReader(FileReader(\"in.txt\"))\n}\n\nvar output = when(ONLINE_JUDGE) {\n true -> PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))\n else -> PrintWriter(BufferedWriter(FileWriter(\"out.txt\")))\n}\n\nvar st = StringTokenizer(\"\")\n\nfun main(args: Array) {\n val start = System.currentTimeMillis()\n solve()\n\n output.close()\n input.close()\n\n if (!ONLINE_JUDGE) {\n System.err.println(\"${System.currentTimeMillis() - start} ms\")\n }\n}"}, {"source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n var s = readLine()\n var del: MutableList = mutableListOf()\n\n for (i in 1..(n-1)){\n if (n % i == 0) del.add(i)\n }\n\n del.forEach {\n s = s!!.substring(0..(it - 1)).reversed() + s!!.substring(it..(s!!.length - 1))\n }\n print(s!!.reversed())\n\n}"}, {"source_code": "\n\nfun solve(a: String): String {\n val b = a.toByteArray()\n val n = a.length\n\n fun reverse(k: Int) {\n for (i in 0 until k/2) {\n val c = b[i]\n b[i] = b[k - i - 1]\n b[k - i - 1] = c\n }\n }\n\n for (i in 1..n) {\n if (n % i == 0) {\n reverse(i)\n// print(\"$i \")\n// println(String(b))\n }\n }\n\n return String(b)\n}\n\nfun processSuite() {\n val a = readLine()!!.toInt()\n val s = readLine()!!\n val solution = solve(s)\n println(solution)\n}\n\nfun suitesCount() = 1\n\nfun main() {\n for (i in 0 until suitesCount()) {\n processSuite()\n }\n}\n\n// READER\ninternal val reader = Reader()\ninternal fun readNumber() = reader.nextInt()\ninternal fun readNumbers(n: Int) = reader.nextInts(n)\n\ntypealias DataInputStream = java.io.DataInputStream\n\ninternal class Reader {\n\n private val BUFFER_SIZE = 1 shl 16\n private val din: DataInputStream = DataInputStream(System.`in`)\n private val buffer: ByteArray = ByteArray(BUFFER_SIZE)\n private var bytesRead: Int = 0\n private var bufferPointer: Int = bytesRead\n\n private val stop: Byte = -1\n\n private fun read(): Byte {\n if (bufferPointer == bytesRead) {\n fillBuffer()\n }\n return buffer[bufferPointer++]\n }\n\n private fun fillBuffer() {\n bufferPointer = 0\n bytesRead = din.read(buffer, bufferPointer, BUFFER_SIZE)\n if (bytesRead == -1) {\n buffer[0] = stop\n }\n }\n\n fun nextLine(): String {\n val buf = ByteArray(64) // line length\n var cnt = 0\n var c: Byte\n do {\n c = read().takeUnless { it == '\\n'.toByte() } ?: break\n buf[cnt++] = c\n } while (c != stop)\n\n return String(buf, 0, cnt)\n }\n\n fun nextInts(n: Int): IntArray {\n val arr = IntArray(n) { 0 }\n for (i in 0 until n) {\n arr[i] = nextInt()\n }\n return arr\n }\n\n fun nextInt(): Int {\n var ret = 0\n var c = read()\n while (c <= ' '.toByte()) c = read()\n val neg = c == '-'.toByte()\n if (neg) c = read()\n do {\n ret = ret * 10 + c - '0'.toInt()\n c = read()\n } while (c >= '0'.toByte() && c <= '9'.toByte())\n\n return if (neg) -ret else ret\n }\n\n fun nextLong(): Long {\n var ret = 0L\n var c = read()\n while (c <= ' '.toByte()) c = read()\n val neg = c == '-'.toByte()\n if (neg) c = read()\n do {\n ret = ret * 10 + c - '0'.toInt()\n c = read()\n } while (c >= '0'.toByte() && c <= '9'.toByte())\n\n return if (neg) -ret else ret\n }\n\n fun nextDouble(): Double {\n var ret = 0.0\n var div = 1.0\n var c = read()\n while (c <= ' '.toByte()) c = read()\n val neg = c == '-'.toByte()\n if (neg) c = read()\n do {\n ret = ret * 10 + c - '0'.toDouble()\n c = read()\n } while (c >= '0'.toByte() && c <= '9'.toByte())\n\n if (c == '.'.toByte()) {\n c = read()\n while (c >= '0'.toByte() && c <= '9'.toByte()) {\n div *= 10\n ret += (c - '0'.toByte()) / div\n c = read()\n }\n }\n\n return if (neg) -ret else ret\n }\n}"}, {"source_code": "fun main(args: Array) {\n solve()\n}\n\nprivate fun read(delimit: Char = ' ') = readLine()!!.split(delimit)\n\nprivate fun solve() {\n val len = read()\n var (s) = read()\n\n if(s.length == 1){\n print(s)\n return\n }\n\n var finalStr = s\n\n for ((index, x) in s.withIndex()) {\n if (index > 0 && s.length % (index) == 0) {\n\n finalStr = s.substring(0, index).reversed()\n finalStr += s.substring(index,s.length)\n\n s = finalStr\n }\n }\n\n print(finalStr.reversed())\n}"}, {"source_code": "fun main(args: Array) {\n val len = readLine()!!.toInt()\n var str = readLine()!!\n\n for (divider in getDividers(len)) {\n str = str.take(divider).reversed() + str.drop(divider)\n\n debug { println(\"div: $divider; str=$str\") }\n }\n\n print(str)\n}\nfun getDividers(num: Int) : Array {\n val arr = hashSetOf(1,num)\n if (num == 1 || num == 2) return arr.toTypedArray()\n for (i in 2 until num) if (num % i == 0)arr.add(i)\n\n debug { println(\"dividers: $arr\") }\n return arr.toTypedArray().sortedArray()\n}\ninline fun debug(block: () -> Unit) {\n if (false) block()\n}\n\n"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val n = readInt()\n var t = readLine()!!\n for (pos in 2..n)\n if (n % pos == 0)\n t = t.substring(0, pos).reversed() + t.substring(pos, n)\n print(t)\n}"}, {"source_code": "fun readString() = readLine()!!\n\nfun readInt() = readString().toInt()\nfun readLong() = readString().toLong()\n\nfun readIntArray() = readString().split(\" \").map { it.toInt() }\nfun readLongArray() = readString().split(\" \").map { it.toLong() }\n\nfun main() {\n val n = readInt()\n var s = readString()\n for (i in 1..n) {\n if (n % i == 0) {\n s = s.take(i).reversed() + s.takeLast(n - i)\n }\n }\n println(s)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.io.InputStream\nimport java.util.*\nimport kotlin.math.log\n\nfun main(args: Array) {\n class Scanner(s: InputStream) {\n private var st: StringTokenizer? = null\n private var br: BufferedReader = BufferedReader(InputStreamReader(s))\n\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n }\n\n val scan = Scanner(System.`in`)\n\n val n = scan.nextInt()\n var s = scan.next()\n\n val d = getDivisors(n)\n\n for(i in d) {\n// println(\"processing $i\")\n val first = s.substring(0, i)\n// println(\"first = $first\")\n val firstr = first.reversed()\n// println(\"firstr = $firstr\")\n val second = s.substring(i, n)\n// println(\"second = $second\")\n s = firstr + second\n }\n\n println(s)\n}\n\nfun getDivisors(n: Int): List =\n (1..n).filter { n % it == 0 }\n"}, {"source_code": "import java.util.*\n\n//07/07/2018\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val n = nextInt()\n val s = next()\n val delimiters = collectDelimiters(n)\n print(restore(s, delimiters))\n}\n\nfun restore(s: String, delimiters: Iterator): String {\n if (!delimiters.hasNext()) return s\n val delimiter = delimiters.next()\n return restore(s.substring(0, delimiter).reversed() + s.substring(delimiter), delimiters)\n}\n\nfun collectDelimiters(n: Int): Iterator {\n val res = mutableListOf()\n var d = n;\n while (d >1) {\n if (n % d == 0) {\n res.add(d);\n }\n d--\n }\n return res.reversed().iterator()\n}\n"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun rev(S : CharArray, idx : Int) {\n for (i in 0..idx / 2 - 1) S[i] = S[idx - 1 - i].also{S[idx - 1 - i] = S[i]}\n}\n\nfun main() {\n val n = readInt()\n var s : String = readLn()\n var S = s.toCharArray()\n \n for (i in 1..n) {\n if (n % i == 0) rev(S, i)\n }\n \n println(S)\n}"}, {"source_code": "//package codeForces.v1\n\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n var s = readLine()!!\n\n for (i in 2..n) {\n if (n % i != 0)\n continue\n\n s = s.substring(0, i).reversed() + s.substring(i, n)\n }\n\n println(s)\n}"}, {"source_code": "fun reverse(s: MutableList, r: Int): MutableList {\n for (i in 0..(r - 1)/2) {\n s[i] = s[r - i - 1].also { s[r - i - 1] = s[i] }\n }\n\n return s\n}\n\nfun main() {\n val n = readLine()!!.toInt()\n var s = readLine()!!.toMutableList()\n\n var div = 1\n while (div <= n) {\n if (n % div == 0) {\n s = reverse(s, div)\n }\n\n ++div\n }\n\n print(s.joinToString(\"\"))\n}"}], "negative_code": [{"source_code": "\n\nfun solve(a: String): String {\n val b = a.toByteArray()\n val n = a.length\n\n fun reverse(k: Int) {\n for (i in 0..k / 2) {\n val c = b[i]\n b[i] = b[k - i - 1]\n b[k - i - 1] = c\n }\n }\n\n for (i in 1..n) {\n if (n % i == 0) {\n reverse(i)\n }\n }\n\n return String(b)\n}\n\nfun processSuite() {\n val a = readLine()!!.toInt()\n val s = readLine()!!\n val solution = solve(s)\n println(solution)\n}\n\nfun suitesCount() = 1\n\nfun main() {\n for (i in 0 until suitesCount()) {\n processSuite()\n }\n}\n\n// READER\ninternal val reader = Reader()\ninternal fun readNumber() = reader.nextInt()\ninternal fun readNumbers(n: Int) = reader.nextInts(n)\n\ntypealias DataInputStream = java.io.DataInputStream\n\ninternal class Reader {\n\n private val BUFFER_SIZE = 1 shl 16\n private val din: DataInputStream = DataInputStream(System.`in`)\n private val buffer: ByteArray = ByteArray(BUFFER_SIZE)\n private var bytesRead: Int = 0\n private var bufferPointer: Int = bytesRead\n\n private val stop: Byte = -1\n\n private fun read(): Byte {\n if (bufferPointer == bytesRead) {\n fillBuffer()\n }\n return buffer[bufferPointer++]\n }\n\n private fun fillBuffer() {\n bufferPointer = 0\n bytesRead = din.read(buffer, bufferPointer, BUFFER_SIZE)\n if (bytesRead == -1) {\n buffer[0] = stop\n }\n }\n\n fun nextLine(): String {\n val buf = ByteArray(64) // line length\n var cnt = 0\n var c: Byte\n do {\n c = read().takeUnless { it == '\\n'.toByte() } ?: break\n buf[cnt++] = c\n } while (c != stop)\n\n return String(buf, 0, cnt)\n }\n\n fun nextInts(n: Int): IntArray {\n val arr = IntArray(n) { 0 }\n for (i in 0 until n) {\n arr[i] = nextInt()\n }\n return arr\n }\n\n fun nextInt(): Int {\n var ret = 0\n var c = read()\n while (c <= ' '.toByte()) c = read()\n val neg = c == '-'.toByte()\n if (neg) c = read()\n do {\n ret = ret * 10 + c - '0'.toInt()\n c = read()\n } while (c >= '0'.toByte() && c <= '9'.toByte())\n\n return if (neg) -ret else ret\n }\n\n fun nextLong(): Long {\n var ret = 0L\n var c = read()\n while (c <= ' '.toByte()) c = read()\n val neg = c == '-'.toByte()\n if (neg) c = read()\n do {\n ret = ret * 10 + c - '0'.toInt()\n c = read()\n } while (c >= '0'.toByte() && c <= '9'.toByte())\n\n return if (neg) -ret else ret\n }\n\n fun nextDouble(): Double {\n var ret = 0.0\n var div = 1.0\n var c = read()\n while (c <= ' '.toByte()) c = read()\n val neg = c == '-'.toByte()\n if (neg) c = read()\n do {\n ret = ret * 10 + c - '0'.toDouble()\n c = read()\n } while (c >= '0'.toByte() && c <= '9'.toByte())\n\n if (c == '.'.toByte()) {\n c = read()\n while (c >= '0'.toByte() && c <= '9'.toByte()) {\n div *= 10\n ret += (c - '0'.toByte()) / div\n c = read()\n }\n }\n\n return if (neg) -ret else ret\n }\n}"}, {"source_code": "fun main(args: Array) {\n solve()\n}\n\nprivate fun read(delimit: Char = ' ') = readLine()!!.split(delimit)\n\nprivate fun solve() {\n val len = read()\n var (s) = read()\n\n if(s.length == 1){\n print(s)\n return\n }\n var finalStr = \"\"\n\n for ((index, x) in s.withIndex()) {\n if (index > 0 && s.length % (index) == 0) {\n finalStr = s.substring(0, index).reversed()\n finalStr += s.substring(index,s.length)\n }\n }\n\n print(finalStr.reversed())\n}"}], "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3"} {"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": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n solve(System.`in`, System.out)\n}\n\nval MAX_N = (1e6 + 10).toInt()\nval INF = (1e9 + 7).toInt()\nval MOD = (1e9 + 7).toInt()\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val n = reader.nextInt()\n val s = reader.next()\n\n var ans = false\n for (i in 1 until n - 1) {\n val c1 = s[i - 1]\n val c2 = s[i]\n val c3 = s[i + 1]\n\n if (c2 == '?' && c3 == '?') {\n ans = true\n break\n }\n\n if (c2 == '?' && c1 == c3) {\n ans = true\n break\n }\n }\n\n if (s.first() == '?' || s.last() == '?') {\n ans = true\n }\n\n for (i in 0 until n - 1) {\n val c1 = s[i]\n val c2 = s[i + 1]\n if (c1 == c2 && c1 != '?') {\n ans = false\n break\n }\n }\n\n writer.println(if (ans) \"YES\" else \"NO\")\n}\n\nclass InputReader(stream: InputStream) {\n val reader: BufferedReader\n var tokenizer: StringTokenizer? = null\n\n init {\n reader = BufferedReader(InputStreamReader(stream), 32768)\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}"}, {"source_code": "\nfun main(args : Array) {\n var input = System.`in`.bufferedReader()\n try {\n var n = input.readLine().toInt()\n var s = input.readLine()\n \n var i = 0\n var ok = false\n mainloop@ while (i < s.length) {\n when (s[i]) {\n '?' -> {\n var j = i\n while (j < s.length && s[i] == s[j])\n ++j\n \n if (j - i >= 2)\n ok = true\n else {\n var lch = if (i > 0) s[i - 1] else '\\u0000'\n var rch = if (j < s.length) s[j] else '\\u0000'\n if (lch == rch || lch == '\\u0000' || rch == '\\u0000')\n ok = true\n }\n i = j\n }\n else -> {\n if (i < s.length - 1 && s[i] == s[i + 1]) {\n ok = false\n break@mainloop\n } else\n ++i\n }\n }\n }\n \n println(if (ok) \"Yes\" else \"No\")\n } finally {\n input.close()\n }\n}\n"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n var painting = readLine()!!\n\n painting =\n painting.replace(\"C?Y\", \"CMY\")\n .replace(\"C?M\", \"CYM\")\n .replace(\"Y?C\", \"YMC\")\n .replace(\"Y?M\", \"YCM\")\n .replace(\"M?C\", \"MYC\")\n .replace(\"M?Y\", \"MCY\")\n\n with (painting) {\n if (contains(\"CC\") || contains(\"MM\") || contains(\"YY\")) {\n println(\"No\")\n return\n }\n if (painting.count { it == '?' } == 0) {\n println(\"No\")\n return\n }\n }\n\n println(\"Yes\")\n}"}], "negative_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n solve(System.`in`, System.out)\n}\n\nval MAX_N = (1e6 + 10).toInt()\nval INF = (1e9 + 7).toInt()\nval MOD = (1e9 + 7).toInt()\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val n = reader.nextInt()\n val s = reader.next()\n\n var ans = false\n for (i in 1 until n - 1) {\n val c1 = s[i - 1]\n val c2 = s[i]\n val c3 = s[i + 1]\n\n if (c2 == '?' && c3 == '?') {\n ans = true\n break\n }\n\n if (c2 == '?' && c1 == c3) {\n ans = true\n break\n }\n }\n\n if (s.last() == '?') {\n ans = true\n }\n\n for (i in 0 until n - 1) {\n val c1 = s[i]\n val c2 = s[i + 1]\n if (c1 == c2) {\n ans = false\n break\n }\n }\n\n writer.println(if (ans) \"YES\" else \"NO\")\n}\n\nclass InputReader(stream: InputStream) {\n val reader: BufferedReader\n var tokenizer: StringTokenizer? = null\n\n init {\n reader = BufferedReader(InputStreamReader(stream), 32768)\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n solve(System.`in`, System.out)\n}\n\nval MAX_N = (1e6 + 10).toInt()\nval INF = (1e9 + 7).toInt()\nval MOD = (1e9 + 7).toInt()\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val n = reader.nextInt()\n val s = reader.next()\n\n var ans = false\n for (i in 1 until n - 1) {\n val c1 = s[i - 1]\n val c2 = s[i]\n val c3 = s[i + 1]\n\n if (c2 == '?' && c3 == '?') {\n ans = true\n break\n }\n\n if (c2 == '?' && c1 == c3) {\n ans = true\n break\n }\n }\n\n if (s.last() == '?') {\n ans = true\n }\n\n for (i in 0 until n - 1) {\n val c1 = s[i]\n val c2 = s[i + 1]\n if (c1 == c2 && c1 != '?') {\n ans = false\n break\n }\n }\n\n writer.println(if (ans) \"YES\" else \"NO\")\n}\n\nclass InputReader(stream: InputStream) {\n val reader: BufferedReader\n var tokenizer: StringTokenizer? = null\n\n init {\n reader = BufferedReader(InputStreamReader(stream), 32768)\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val painting = readLine()!!\n \n with (painting) {\n if (contains(\"CC\") || contains(\"MM\") || contains(\"YY\")) {\n println(\"No\")\n return\n }\n if (painting.count { it == '?' } == 1) {\n if (contains(\"C?M\") || contains(\"M?Y\") || contains(\"Y?C\")\n || contains(\"M?C\") || contains(\"Y?M\") || contains(\"C?Y\")) {\n println(\"No\")\n return\n }\n }\n if (painting.count { it == '?' } == 0) {\n println(\"No\")\n return\n }\n }\n\n println(\"Yes\")\n}"}], "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3"} {"nl": {"description": "Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro.She has ordered a very big round pizza, in order to serve her many friends. Exactly $$$n$$$ of Shiro's friends are here. That's why she has to divide the pizza into $$$n + 1$$$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over.Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator.As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem?", "input_spec": "A single line contains one non-negative integer $$$n$$$ ($$$0 \\le n \\leq 10^{18}$$$) — the number of Shiro's friends. The circular pizza has to be sliced into $$$n + 1$$$ pieces.", "output_spec": "A single integer — the number of straight cuts Shiro needs.", "sample_inputs": ["3", "4"], "sample_outputs": ["2", "5"], "notes": "NoteTo cut the round pizza into quarters one has to make two cuts through the center with angle $$$90^{\\circ}$$$ between them.To cut the round pizza into five equal parts one has to make five cuts."}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.lang.Math.pow\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.log\nimport kotlin.math.log2\nimport kotlin.math.min\n\nfun main(args: Array)\n = Thread { run() }.start()\n\nfun run() {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextLong()\n if (n == 0L)\n println(0)\n else if (n % 2 == 1L)\n println((n + 1) / 2)\n else\n println(n + 1)\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\n//class Pair(val a: Int, val b: Int)\n//class Triple(val a: Int, val b: Int, val c: Int)"}, {"source_code": "import java.util.*\nimport java.math.*\n\n\nfun main(args: Array)\n{\n var sc=Scanner(System.`in`)\n var n=sc.nextLong()\n if(n==0L)\n {\n println(\"0\");\n return ;\n }\n n++;\n if(n%2==0L)n/=2\n println(n);\n}\n"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toLong()\n val k = n + 1\n val r = when {\n k == 1L -> 0L\n k % 2 == 0L -> k / 2\n else -> k\n }\n println(r)\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nconst val INPUT_FILE_NAME = \"input\"\nconst val OUTPUT_FILE_NAME = \"output\"\n\nfun main(args: Array) {\n solve(System.`in`, System.out)\n// solve(FileInputStream(\"$INPUT_FILE_NAME.txt\"), FileOutputStream(\"$OUTPUT_FILE_NAME.txt\"))\n}\n\nval MAX_N = (1e6 + 10).toInt()\nval INF = (1e9 + 7).toInt()\nval MOD = (1e9 + 7).toInt()\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val n = reader.nextLong()\n if (n == 0L) {\n writer.println(\"0\")\n return\n }\n if (n % 2 == 0L) {\n writer.println(n + 1)\n } else {\n writer.println((n + 1) / 2)\n }\n}\n\nfun gcd(a: Int, b: Int): Int {\n return if (b == 0) a else gcd(b, a % b)\n}\n\nclass InputReader(stream: InputStream) {\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}"}, {"source_code": "fun main(args: Array){\n val n: Long = readLine()?.toLong() ?: 0\n val pieces = n+1\n if (pieces%2 == 0L)\n println(pieces/2)\n else if (pieces == 1L)\n println(0)\n else\n println(pieces)\n}"}, {"source_code": "\n\nfun main(){\n var n = readLine()!!.toLong()+1\n\n if (n==1L){\n println(0)\n }else{\n if (n%2L==0L){\n println(n/2)\n }else{\n println(n)\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n var lo = readLine()!!.toLong()\n if(lo < 2) print(lo) else {\n if(++lo % 2L == 0L) print(lo/2)\n else print(lo)\n }\n}"}, {"source_code": "fun main() {\n val numPeople = readLine()!!.toLong() + 1\n if (numPeople == 1L) return print(0)\n print(if (numPeople and 1 == 0L) numPeople / 2 else numPeople)\n}"}, {"source_code": "fun main(args: Array){\n\tval cats = readLine()!!.toLong() + 1L\n\tif(cats==1L){\n\t\tprintln(0)\n\t\treturn\n\t}\n\tval res = if(cats.rem(2L)==0L) cats/2L else cats\n\tprintln(res)\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toLong()\n\n if (n == 0L) {\n println(0)\n return\n }\n\n val ans = if ((n + 1) % 2 == 0L) (n + 1) / 2 else n + 1\n println(ans)\n}\n"}, {"source_code": "/**\n * Created by aursaty on 5/14/2018.\n */\n\nfun main(args : Array) {\n var n : Long = 0\n n = readLine()!!.toLong() + 1\n when {\n n % 2 == 0.toLong() -> print(n/2)\n n == 1.toLong() -> print(0)\n else -> print(n)\n }\n}"}], "negative_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.lang.Math.pow\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.log\nimport kotlin.math.log2\nimport kotlin.math.min\n\nfun main(args: Array)\n = Thread { run() }.start()\n\nfun run() {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextLong()\n if (n % 2 == 1L)\n println((n + 1) / 2)\n else\n println(n + 1)\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\n//class Pair(val a: Int, val b: Int)\n//class Triple(val a: Int, val b: Int, val c: Int)"}, {"source_code": "import java.util.*\nimport java.math.*\n\n\nfun main(args: Array)\n{\n var sc=Scanner(System.`in`)\n var n=sc.nextLong()\n if(n==0L)\n {\n println(\"0\");\n }\n n++;\n if(n%2==0L)n/=2\n println(n);\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nconst val INPUT_FILE_NAME = \"input\"\nconst val OUTPUT_FILE_NAME = \"output\"\n\nfun main(args: Array) {\n solve(System.`in`, System.out)\n// solve(FileInputStream(\"$INPUT_FILE_NAME.txt\"), FileOutputStream(\"$OUTPUT_FILE_NAME.txt\"))\n}\n\nval MAX_N = (1e6 + 10).toInt()\nval INF = (1e9 + 7).toInt()\nval MOD = (1e9 + 7).toInt()\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val n = reader.nextLong()\n if (n % 2 == 0L) {\n writer.println(n + 1)\n } else {\n writer.println((n + 1) / 2)\n }\n}\n\nfun gcd(a: Int, b: Int): Int {\n return if (b == 0) a else gcd(b, a % b)\n}\n\nclass InputReader(stream: InputStream) {\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}"}, {"source_code": "fun main(args: Array){\n val n: Long = readLine()?.toLong() ?: 0\n val pieces = n+1\n if (pieces%2 == 0L)\n println(pieces/2)\n else\n println(pieces)\n}"}, {"source_code": "fun main() {\n val numPeople = readLine()!!.toLong() + 1\n print(if (numPeople and 1 == 0L) numPeople / 2 else numPeople)\n}"}, {"source_code": "fun main() {\n val numPeople = readLine()!!.toLong() + 1\n if (numPeople == 0L) return print(0)\n print(if (numPeople and 1 == 0L) numPeople / 2 else numPeople)\n}"}, {"source_code": "fun main(args : Array) {\n var n = 0\n n = readLine()!!.toInt() + 1\n if (n % 2 == 0)\n print(n/2)\n else\n if (n == 1)\n print(0)\n print(n)\n}"}], "src_uid": "236177ff30dafe68295b5d33dc501828"} {"nl": {"description": "Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows: Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year. In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February.Look at the sample to understand what borders are included in the aswer.", "input_spec": "The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900 ≤ yyyy ≤ 2038 and yyyy:mm:dd is a legal date).", "output_spec": "Print a single integer — the answer to the problem.", "sample_inputs": ["1900:01:01\n2038:12:31", "1996:03:09\n1991:11:12"], "sample_outputs": ["50768", "1579"], "notes": null}, "positive_code": [{"source_code": "import java.io.*\nimport java.text.SimpleDateFormat\nimport java.util.*\nimport kotlin.Comparator\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\nimport kotlin.math.round\nimport kotlin.random.Random\nimport kotlin.system.measureTimeMillis\n\n/**\n * 23.02.2020\n * Main\n *\n * @author Havlong\n * @version v1.0\n */\nclass LineReader(tempReader: Reader) {\n private val reader = BufferedReader(tempReader)\n fun hasNext() = peek() != -1\n private fun peek(): Int {\n reader.mark(1)\n return reader.read().also { reader.reset() }\n }\n\n fun skipSpaces() {\n while (Character.isWhitespace(peek()))\n reader.read()\n }\n\n fun readLine(): String = reader.readLine()\n fun longList() = readLine().split(' ').map(String::toLong)\n fun intList() = readLine().split(' ').map(String::toInt)\n}\n\ntypealias ML = MutableList\ntypealias MI = MutableList\ntypealias LL = List\ntypealias LLL = List\ntypealias PLL = Pair\ntypealias PPLL = Pair\n\nconst val M7 = 1000000007L\nconst val M9 = 1000000009L\nconst val MFFT = 998244353L\nconst val INF = 2000000000000000000L\n\nfun lowerBound(from: Long, to: Long, comparison: (Long) -> Long): Long {\n var left = from\n var right = to + 1\n while (left < right) {\n val mid = (left + right) / 2\n val result = comparison(mid)\n if (result >= 0) {\n right = mid\n } else {\n left = mid + 1\n }\n }\n return left\n}\n\nfun upperBound(from: Long, to: Long, comparison: (Long) -> Long): Long {\n var left = from\n var right = to + 1\n while (left < right) {\n val mid = (left + right) / 2\n val result = comparison(mid)\n if (result > 0) {\n right = mid\n } else {\n left = mid + 1\n }\n }\n return left\n}\n\nfun > List.upperBound(key: T, from: Int = 0, to: Int = size - 1): Int {\n return upperBound(from.toLong(), to.toLong()) { this[it.toInt()].compareTo(key).toLong() }.toInt()\n}\n\nfun > List.lowerBound(key: T, from: Int = 0, to: Int = size - 1): Int {\n return lowerBound(from.toLong(), to.toLong()) { this[it.toInt()].compareTo(key).toLong() }.toInt()\n}\n\nfun > Array.upperBound(key: T, from: Int = 0, to: Int = size - 1): Int {\n return upperBound(from.toLong(), to.toLong()) { this[it.toInt()].compareTo(key).toLong() }.toInt()\n}\n\nfun > Array.lowerBound(key: T, from: Int = 0, to: Int = size - 1): Int {\n return lowerBound(from.toLong(), to.toLong()) { this[it.toInt()].compareTo(key).toLong() }.toInt()\n}\n\noperator fun , B : Comparable> Pair.compareTo(other: Pair): Int {\n return first.compareTo(other.first).let { if (it == 0) second.compareTo(other.second) else it }\n}\n\nfun binPow(number: Long, power: Long, mod: Long): Long {\n var result = 1L\n var a = number % mod\n var n = power\n while (n > 0) {\n if (n % 2 != 0L)\n result = (result * a) % mod\n a = (a * a) % mod\n n /= 2\n }\n return result\n}\n\ntailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\n\nfun lcm(a: Long, b: Long) = a * b / gcd(a, b)\n\nfun main(args: Array) {\n if (args.isNotEmpty() && args[0] == \"local\") {\n val reader = LineReader(FileReader(\"input.txt\"))\n PrintWriter(File(\"output.txt\")).use {\n while (reader.hasNext()) {\n it.println(\"\\n${measureTimeMillis {\n solve(reader, it)\n }} ms\\n\")\n reader.skipSpaces()\n }\n }\n } else {\n val reader = LineReader(InputStreamReader(System.`in`))\n PrintWriter(System.out).use { solve(reader, it) }\n }\n}\n\nfun solve(reader: LineReader, writer: PrintWriter) {\n val format = SimpleDateFormat(\"yyyy:MM:dd\")\n val start = format.parse(reader.readLine().trim())\n val end = format.parse(reader.readLine().trim())\n writer.println(abs(round((end.time - start.time) / 1000.0 / 3600 / 24)).toLong())\n}\n"}], "negative_code": [{"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.Comparator\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\nimport kotlin.random.Random\nimport kotlin.system.measureTimeMillis\n\n/**\n * 23.02.2020\n * Main\n *\n * @author Havlong\n * @version v1.0\n */\nclass LineReader(tempReader: Reader) {\n private val reader = BufferedReader(tempReader)\n fun hasNext() = peek() != -1\n private fun peek(): Int {\n reader.mark(1)\n return reader.read().also { reader.reset() }\n }\n\n fun skipSpaces() {\n while (Character.isWhitespace(peek()))\n reader.read()\n }\n\n fun readLine(): String = reader.readLine()\n fun longList() = readLine().split(' ').map(String::toLong)\n fun intList() = readLine().split(' ').map(String::toInt)\n}\n\ntypealias ML = MutableList\ntypealias MI = MutableList\ntypealias LL = List\ntypealias LLL = List\ntypealias PLL = Pair\ntypealias PPLL = Pair\n\nconst val M7 = 1000000007L\nconst val M9 = 1000000009L\nconst val MFFT = 998244353L\nconst val INF = 2000000000000000000L\n\nfun lowerBound(from: Long, to: Long, comparison: (Long) -> Long): Long {\n var left = from\n var right = to + 1\n while (left < right) {\n val mid = (left + right) / 2\n val result = comparison(mid)\n if (result >= 0) {\n right = mid\n } else {\n left = mid + 1\n }\n }\n return left\n}\n\nfun upperBound(from: Long, to: Long, comparison: (Long) -> Long): Long {\n var left = from\n var right = to + 1\n while (left < right) {\n val mid = (left + right) / 2\n val result = comparison(mid)\n if (result > 0) {\n right = mid\n } else {\n left = mid + 1\n }\n }\n return left\n}\n\nfun > List.upperBound(key: T, from: Int = 0, to: Int = size - 1): Int {\n return upperBound(from.toLong(), to.toLong()) { this[it.toInt()].compareTo(key).toLong() }.toInt()\n}\n\nfun > List.lowerBound(key: T, from: Int = 0, to: Int = size - 1): Int {\n return lowerBound(from.toLong(), to.toLong()) { this[it.toInt()].compareTo(key).toLong() }.toInt()\n}\n\nfun > Array.upperBound(key: T, from: Int = 0, to: Int = size - 1): Int {\n return upperBound(from.toLong(), to.toLong()) { this[it.toInt()].compareTo(key).toLong() }.toInt()\n}\n\nfun > Array.lowerBound(key: T, from: Int = 0, to: Int = size - 1): Int {\n return lowerBound(from.toLong(), to.toLong()) { this[it.toInt()].compareTo(key).toLong() }.toInt()\n}\n\noperator fun , B : Comparable> Pair.compareTo(other: Pair): Int {\n return first.compareTo(other.first).let { if (it == 0) second.compareTo(other.second) else it }\n}\n\nfun binPow(number: Long, power: Long, mod: Long): Long {\n var result = 1L\n var a = number % mod\n var n = power\n while (n > 0) {\n if (n % 2 != 0L)\n result = (result * a) % mod\n a = (a * a) % mod\n n /= 2\n }\n return result\n}\n\ntailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\n\nfun lcm(a: Long, b: Long) = a * b / gcd(a, b)\n\nfun main(args: Array) {\n if (args.isNotEmpty() && args[0] == \"local\") {\n val reader = LineReader(FileReader(\"input.txt\"))\n PrintWriter(File(\"output.txt\")).use {\n while (reader.hasNext()) {\n it.println(\"\\n${measureTimeMillis {\n solve(reader, it)\n }} ms\\n\")\n reader.skipSpaces()\n }\n }\n } else {\n val reader = LineReader(InputStreamReader(System.`in`))\n PrintWriter(System.out).use { solve(reader, it) }\n }\n}\n\nfun solve(reader: LineReader, writer: PrintWriter) {\n val (year, month, day) = reader.readLine().split(':').map(String::toInt)\n val (year2, month2, day2) = reader.readLine().split(':').map(String::toInt)\n val start = Calendar.getInstance().apply { set(year + 400, month, day) }\n val end = Calendar.getInstance().apply { set(year2 + 400, month2, day2) }\n val result = abs(end.timeInMillis - start.timeInMillis + 1) / 1000\n writer.println(result / 3600 / 24)\n}\n"}], "src_uid": "bdf99d78dc291758fa09ec133fff1e9c"} {"nl": {"description": "Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find greatest common divisor GCD(a, b), for example, Euclid algorithm. Formally, find the biggest integer d, such that all integers a, a + 1, a + 2, ..., b are divisible by d. To make the problem even more complicated we allow a and b to be up to googol, 10100 — such number do not fit even in 64-bit integer type!", "input_spec": "The only line of the input contains two integers a and b (1 ≤ a ≤ b ≤ 10100).", "output_spec": "Output one integer — greatest common divisor of all integers from a to b inclusive.", "sample_inputs": ["1 2", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576"], "sample_outputs": ["1", "61803398874989484820458683436563811772030917980576"], "notes": null}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\n\nfun PrintWriter.solve(sc: FastScanner) {\n val (a, b) = readLine()!!.split(\" \")\n println(if (a == b) a else \"1\")\n}\n\nfun main() {\n val writer = PrintWriter(System.out, false)\n writer.solve(FastScanner(System.`in`))\n writer.flush()\n}\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}\n"}, {"source_code": "fun main() {\n val (a, b) = readLine()!!.split(\" \")\n print(if (a == b) a else 1)\n}"}, {"source_code": " fun main(args: Array) {\n val (a, b) = readLine()!!.split(\" \")\n println( if (a == b) a else \"1\" )\n }\n\n"}, {"source_code": "fun main() {\n val (a, b) = readLine()!!.split(\" \")\n println(if (a==b) a else \"1\")\n}"}], "negative_code": [], "src_uid": "9c5b6d8a20414d160069010b2965b896"} {"nl": {"description": "There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees.Find the value of the sum modulo 109 + 7 (so you should find the remainder after dividing the answer by the value 109 + 7).", "input_spec": "The only line contains two integers n, k (1 ≤ n ≤ 109, 0 ≤ k ≤ 106).", "output_spec": "Print the only integer a — the remainder after dividing the value of the sum by the value 109 + 7.", "sample_inputs": ["4 1", "4 2", "4 3", "4 0"], "sample_outputs": ["10", "30", "100", "4"], "notes": null}, "positive_code": [{"source_code": "fun POW(N:Int ,P: Int ,mod : Int):Int{\n var x=1\n var n=N\n var p=P\n while (p > 0) {\n if (p%2 == 0) {\n n = (n.toLong()*n %mod).toInt()\n p /= 2\n } else {\n x = (x.toLong()*n %mod).toInt()\n p -= 1\n }\n }\n\n return x\n}\n\nfun main(){\n var (n,K) = readLine()!!.split(' ').map { it.toInt() }\n val mod=1000000007\n\n var FACT=mutableListOf()\n var F=mutableListOf()\n var FACT_INV=mutableListOf()\n\n FACT.add(1)\n F.add(0)\n\n for (i in 1..1000010){\n FACT.add((FACT[i-1].toLong()*i%mod).toInt())\n F.add((F[i-1]+POW(i,K,mod))%mod)\n }\n\n //println(FACT[1000010])\n\n FACT_INV.add(POW(FACT[1000010],mod-2,mod))\n\n for (i in 1000010 downTo 1){\n FACT_INV.add((FACT_INV[1000010-i].toLong()*i%mod).toInt())\n }\n\n //println(FACT_INV[0])\n //println(FACT_INV[1000010])\n FACT_INV = FACT_INV.asReversed()\n\n //println(FACT_INV[0])\n //println(FACT_INV[1000010])\n\n var ANS=0L\n var PI=1L\n\n if (n<=K+2){\n println(F[n])\n return\n }\n\n for (i in 1..K+2){\n PI=PI*(n-i)%mod\n if ((K+2-i)%2==0){\n ANS=ANS+F[i.toInt()].toLong()*FACT_INV[(K+2-i).toInt()]%mod*FACT_INV[(i-1).toInt()]%mod*POW(n-i,mod-2,mod)\n ANS=(ANS+mod)%mod\n }\n else{\n ANS=ANS-F[i.toInt()].toLong()*FACT_INV[(K+2-i).toInt()]%mod*FACT_INV[(i-1).toInt()]%mod*POW(n-i,mod-2,mod)\n ANS=(ANS+mod)%mod\n }\n }\n println((ANS*PI+mod)%mod)\n}"}], "negative_code": [{"source_code": "fun POW(N:Long ,P: Long ,mod : Long):Long{\n var x=1L\n var n=N\n var p=P\n while (p > 0) {\n if (p%2 == 0L) {\n n = n*n %mod\n p /= 2\n } else {\n x = x*n %mod\n p -= 1\n }\n }\n\n return x\n}\n\nfun main(){\n var (n,K) = readLine()!!.split(' ').map { it.toLong() }\n val mod=1000000007L\n\n var FACT=mutableListOf()\n var F=mutableListOf()\n var FACT_INV=mutableListOf()\n\n FACT.add(1)\n F.add(0)\n\n for (i in 1..1000010){\n FACT.add(FACT[i-1]*i%mod)\n F.add((F[i-1]+POW(i.toLong(),K,mod))%mod)\n }\n //println(FACT[1000010])\n\n FACT_INV.add(POW(FACT[1000010],mod-2,mod))\n\n for (i in 1000010 downTo 1){\n FACT_INV.add(FACT_INV[1000010-i]*i%mod)\n }\n\n //println(FACT_INV[0])\n //println(FACT_INV[1000010])\n FACT_INV = FACT_INV.asReversed()\n\n //println(FACT_INV[0])\n //println(FACT_INV[1000010])\n\n var ANS=0L\n var PI=1L\n\n if (n<=K+2){\n println(F[n.toInt()])\n return\n }\n\n for (i in 1..K+2){\n PI=PI*(n-i)%mod\n if ((K+2-i)%2==0L){\n ANS=ANS+F[i.toInt()]*FACT_INV[(K+2-i).toInt()]%mod*FACT_INV[(i-1).toInt()]%mod*POW(n-i,mod-2,mod)\n ANS%=mod\n }\n else{\n ANS=ANS-F[i.toInt()]*FACT_INV[(K+2-i).toInt()]%mod*FACT_INV[(i-1).toInt()]%mod*POW(n-i,mod-2,mod)\n ANS%=mod\n }\n }\n println(ANS*PI%mod)\n}"}, {"source_code": "fun POW(N:Int ,P: Int ,mod : Int):Int{\n var x=1\n var n=N\n var p=P\n while (p > 0) {\n if (p%2 == 0) {\n n = n*n %mod\n p /= 2\n } else {\n x = x*n %mod\n p -= 1\n }\n }\n\n return x\n}\n\nfun main(){\n var (n,K) = readLine()!!.split(' ').map { it.toInt() }\n val mod=1000000007\n\n var FACT=mutableListOf()\n var F=mutableListOf()\n var FACT_INV=mutableListOf()\n\n FACT.add(1)\n F.add(0)\n\n for (i in 1..1000010){\n FACT.add(FACT[i-1]*i%mod)\n F.add((F[i-1]+POW(i,K,mod))%mod)\n }\n\n //println(FACT[1000010])\n\n FACT_INV.add(POW(FACT[1000010],mod-2,mod))\n\n for (i in 1000010 downTo 1){\n FACT_INV.add(FACT_INV[1000010-i]*i%mod)\n }\n\n //println(FACT_INV[0])\n //println(FACT_INV[1000010])\n FACT_INV = FACT_INV.asReversed()\n\n //println(FACT_INV[0])\n //println(FACT_INV[1000010])\n\n var ANS=0L\n var PI=1L\n\n if (n<=K+2){\n println(F[n.toInt()])\n return\n }\n\n for (i in 1..K+2){\n PI=PI*(n-i)%mod\n if ((K+2-i)%2==0){\n ANS=ANS+F[i.toInt()]*FACT_INV[(K+2-i).toInt()]%mod*FACT_INV[(i-1).toInt()]%mod*POW(n-i,mod-2,mod)\n ANS=(ANS+mod)%mod\n }\n else{\n ANS=ANS-F[i.toInt()]*FACT_INV[(K+2-i).toInt()]%mod*FACT_INV[(i-1).toInt()]%mod*POW(n-i,mod-2,mod)\n ANS=(ANS+mod)%mod\n }\n }\n println((ANS*PI+mod)%mod)\n}"}], "src_uid": "6f6fc42a367cdce60d76fd1914e73f0c"} {"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": "\n\nfun main(args: Array) {\n val array = Array(27, { IntArray(27) })\n val length = readLine()!!.toInt()\n var lastChar = 's'\n var max = 0\n var str = StringBuilder()\n val string = readLine()!!\n string.toCharArray().forEachIndexed { i, c ->\n if (i != 0) {\n array[lastChar.toInt() - 65][c.toInt() - 65]++\n if (array[lastChar.toInt() - 65][c.toInt() - 65] > max) {\n max = array[lastChar.toInt() - 65][c.toInt() - 65]\n str = StringBuilder()\n str.append(lastChar)\n str.append(c)\n }\n }\n lastChar = c\n }\n println(str.toString())\n\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n val input = readLine()!!.substring(0, n)\n\n println(twoGram(input))\n}\n\nfun twoGram(input: String): String {\n val map = HashMap()\n\n var maxCount = 0\n var maxGram = \"\"\n\n for(i in 0..(input.length - 2)) {\n val key = \"${input[i]}${input[i+1]}\"\n map[key] = (map[key]?:0).plus(1)\n\n if(map[key]?.compareTo(maxCount)?:0 > 0) {\n maxCount = map[key]?:0\n maxGram = key\n }\n }\n\n return maxGram\n}"}, {"source_code": "private fun readLnString() = readLine()!! // string line\nprivate fun readInt() = readLnString().toInt() // single int\nprivate fun readStrings() = readLnString().split(\" \") // list of strings\nprivate fun readIntList() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongList() = readStrings().map { it.toLong() } // list of longs\nprivate fun readStringPair() = readStrings().zipWithNext()[0]\nprivate fun readIntPair() = readStrings().map { it.toInt() }.zipWithNext()[0]\n\n//Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the\n// string) maximal number of times. For example, for string s = \"BBAABBBA\" the answer is two-gram \"BB\", which contained\n// in s three times. In other words, find any most frequent two-gram.\n\n//7\n//ABACABA\n//AB\nfun main() {\n val size = readInt()\n val string = readLnString()\n\n val map = mutableMapOf()\n\n for (index in 0..string.length - 2) {\n val substring = string.substring(index, index + 2)\n\n if (map.containsKey(substring))\n map[substring] = map.getOrDefault(substring, 1) + 1\n else\n map[substring] = 1\n }\n\n println(map.maxBy { entry -> entry.value}?.component1())\n}\n"}, {"source_code": "fun main() {\n val n = (readLine() as String).toInt()\n val s = readLine() as String\n test(n, s)\n}\n\nfun test(n: Int, s: String) {\n val results = mutableMapOf()\n\n\n (0 until n -1).forEach {\n val twoGram = \"${s[it]}${s[it + 1]}\"\n results.compute(twoGram) { key, v ->\n (v ?: 0) + 1\n }\n }\n\n val result = results.maxBy { it.value }!!\n\n //val result = results.entries.reduce { e1, e2 -> if (e1.value >= e2.value) e1 else e2 }\n println(result.key)\n}"}, {"source_code": "fun main() {\n val n = (readLine() as String).toInt()\n val s = readLine() as String\n test(n, s)\n}\n\nfun test(n: Int, s: String) {\n val results = mutableMapOf()\n (0 until n -1).forEach {\n val twoGram = \"${s[it]}${s[it + 1]}\"\n results.compute(twoGram) { key, v ->\n (v ?: 0) + 1\n }\n\n }\n val result = results.entries.reduce { e1, e2 -> if (e1.value >= e2.value) e1 else e2 }\n println(result.key)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n val str = sc.next()\n\n var mm = mutableMapOf()\n var maxa = 0\n var res = \"\"\n for (i in 0 until n-1) {\n val temp = str.substring(i, i+2)\n mm[temp] = (mm[temp] ?: 0)+1\n }\n for ((key, value) in mm) {\n if (value > maxa) {\n maxa = value\n res = key\n }\n }\n println(res)\n\n\n}"}, {"source_code": "import java.util.HashMap\nimport java.util.concurrent.atomic.AtomicInteger\n\n/**\n * Created by azhdanov on 07.09.2019.\n */\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\n\nfun main() {\n val n = readInt()\n val s = readLn()\n val map = HashMap()\n for (i in 0 .. n - 2) {\n val candidate = s.substring(i, i + 2)\n map[candidate] = (map[candidate] ?: 0) + 1\n }\n println(map.maxBy { it.value }?.key)\n}"}, {"source_code": "val occur = HashMap()\n\nfun main() {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n for(i in 0 until n-1) {\n val t = s.substring(i, i+2)\n if(t in occur)\n occur[t] = occur[t]!! + 1\n else\n occur[t] = 1\n }\n println(occur.maxBy { it.value }!!.key)\n}"}, {"source_code": "import java.util.*\n \n/**\n * Kotlin Heroes: Practice 2\n * B. Двуграмма\n * http://codeforces.com/contest/1212/problem/B\n * */\nclass B\n \nfun main() {\n readLine()\n val s = readLine()!!.toCharArray()\n val arr = Array(pos('Z', 'Z') + 1) { 0 }\n \n var max = 0\n var maxS = \"\"\n for (i in 1 until s.size) {\n val pos = pos(s[i - 1], s[i])\n if (++arr[pos] > max) {\n max = arr[pos]\n maxS = \"${s[i - 1]}${s[i]}\"\n }\n }\n println(maxS)\n}\n \nfun pos(a: Char, b: Char) = (a - 'A') * ('Z' - 'A' + 1) + (b - 'A')"}, {"source_code": "fun twoGram(input: String) = input.windowed(2).groupingBy { it }.eachCount().maxBy { it.value }?.key\n\nfun main() {\n readLine()\n println(readLine()?.let { twoGram(it) })\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of ints\n\nvar m = HashMap();\n\nfun main(){\n var n:Int = readInt()\n var s: String = readLn()\n for(i in 0..n-2){\n m[s.substring(i, i+2)] = m.getOrDefault(s.substring(i, i+2), 0) + 1;\n }\n // println(m);\n var temp = 0;\n var ans:String? = null;\n for(e in m){\n if(e.value > temp){\n temp = e.value;\n ans = e.key\n }\n }\n println(ans)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n scanner.nextInt()\n val str = scanner.next()\n val d = IntArray(676)\n var c = str[0]\n for (i in 1 until str.length) {\n d[(c - 'A') * 26 + (str[i] - 'A')]++\n c = str[i]\n }\n val a = d.indexOf(d.max()!!)\n println(\"${'A' + a / 26}${('A' + a % 26)}\")\n}"}, {"source_code": "import java.security.InvalidAlgorithmParameterException\n\n/**\n * Created by patrick on 31.08.19.\n * (c) Patrick Scheibe 2019\n */\n\nfun main() {\n contest1212problemB()\n}\n\nfun contest1212problemB() {\n val n = readLine()!!.toInt()\n val s = readLine()!!.substring(0, n)\n val grams = mutableListOf()\n for (i in 0..n - 2) {\n grams.add(s.substring(i,i+2))\n }\n val maxElm = grams.groupingBy { it }.eachCount().maxBy { it.value }\n if (maxElm != null) {\n print(maxElm.key)\n } else {\n throw InvalidAlgorithmParameterException(\"No max ngram. Shouldn't happen\")\n }\n}\n"}, {"source_code": "\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map{it.toLong()}\n//const val MOD = 1000000007\n\nfun main(args:Array){\n val n = readInt()\n val s = readLn()\n\n val skipString = s.substring(1, s.length)\n\n val list = s.asSequence()\n .chunked(2).map { it.joinToString(\"\") }.toList()\n\n val skiplist = skipString.asSequence()\n .chunked(2).map { it.joinToString(\"\") }.toList()\n\n val map = mutableMapOf()\n\n countGram(list, map)\n countGram(skiplist, map)\n\n var max = -1\n var key = \"\"\n map.forEach { t, u ->\n if (u>max && t.length==2){\n max = u\n key = t\n }\n }\n println(key)\n\n}\n\nfun countGram(list: List, map: MutableMap) {\n list.forEach {\n if (map.contains(it)) {\n val count = map[it]!!\n map[it] = count + 1\n } else {\n map[it] = 1\n }\n }\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n val tgc = ByteArray(836)\n\n var i = s[0] - 'A'\n for(j in 1 until n) {\n val k = s[j] - 'A'\n tgc[i shl 5 or k]++\n i = k\n }\n var max = tgc[0]\n i = 0\n for (j in 1 until tgc.size) {\n val v = tgc[j]\n if (v > max) {\n max = v\n i = j\n }\n }\n println(\"${'A' + (i shr 5)}${'A' + (i and 31)}\")\n}"}, {"source_code": "import kotlin.system.measureTimeMillis\n\nfun main() {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n val counts = mutableMapOf()\n for(i in 0 until s.length - 1) {\n val sub = s.substring(i, i + 2)\n counts[sub] = counts.getOrDefault(sub, 0) + 1\n }\n println(counts.maxBy { it.value }!!.key)\n}"}, {"source_code": "fun main(args: Array) {\n readLine()\n val s = readLine()!!\n val map = HashMap()\n s.windowed(2).forEach { substr ->\n map[substr] = map.getOrDefault(substr, 0) + 1\n }\n val maxL = map.values.max()!!\n println(map.entries.find { it.value == maxL }!!.key)\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n sc.nextLine()\n val s = sc.nextLine()\n s.zipWithNext()\n .groupingBy { it }\n .eachCount()\n .maxBy { it.value }\n ?.key\n ?.run { println(\"$first$second\") }\n}"}, {"source_code": "/**\n * You can edit, run, and share this code. \n * play.kotlinlang.org \n */\nval scan = java.util.Scanner(System.`in`)\nfun main() {\n scan.nextInt()\n var s = scan.next()\n var maxTwogram = \"\"\n var maxCount = 0\n for(i in 0 until s.length-1) {\n val twogram = s.substring(i, i+2)\n var count = 0\n for (j in i until s.length-1) {\n if(s.substring(j).startsWith(twogram)) count ++\n }\n if(maxCount < count) {\n maxTwogram = twogram\n maxCount = count\n }\n }\n println(maxTwogram)\n}"}, {"source_code": "import kotlin.system.measureTimeMillis\n\nfun main() {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n val counts = mutableMapOf()\n for(i in 0 until s.length - 1) {\n val sub = s.substring(i, i + 2)\n counts[sub] = (counts[sub] ?: 0) + 1\n }\n println(counts.maxBy { it.value }!!.key)\n}"}, {"source_code": "import java.util.StringTokenizer\nimport java.io.InputStreamReader\nimport java.io.BufferedReader\nimport java.io.InputStream\nimport java.util.HashMap\nimport kotlin.math.max\n\nfun main() {\n\n R.init(System.`in`)\n var n = R.nextInt()\n var s = R.next()\n val map:HashMap = HashMap();\n var max=0\n var ans=\"\"\n for(i in 0..n-2){\n var x = s.substring(i,i+2)\n if(map.containsKey(x)){\n map.put(x,map.getValue(x)+1)\n }\n else{\n map.put(x,1);\n }\n if(max()\n\n for (i in 0 until n - 1) {\n val value = \"${s[i]}${s[i + 1]}\"\n valueToCount[value] = (valueToCount[value] ?: 0) + 1\n }\n\n val entry = valueToCount.maxBy { (_, value) -> value }\n println(entry!!.key)\n}"}, {"source_code": "import java.io.OutputStream\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.PrintWriter\nimport java.util.Scanner\nimport java.util.HashMap\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author maxkibble\n */\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val `in` = Scanner(inputStream)\n val out = PrintWriter(outputStream)\n solve(1, `in`, out)\n out.close()\n}\n\nfun solve(testNumber: Int, `in`: Scanner, out: PrintWriter) {\n val n = `in`.nextInt()\n val s = `in`.next()\n var m = HashMap()\n var ans = \"\"\n var ans_x = 0\n for (i in 0 until n - 1) {\n val ss = s.substring(i, i + 2)\n val x = m.getOrDefault(ss, 0)\n m.put(ss, x + 1)\n if (x + 1 > ans_x) {\n ans = ss\n ans_x = x + 1\n }\n }\n out.println(ans)\n}\n\n\n"}, {"source_code": "fun String.twoGrams(): Map = this.zipWithNext { a, b -> \"$a$b\" }.groupingBy { it }.eachCount()\n\nfun Map.max(): String? = this.maxBy { it.value }?.key\n\nfun main() {\n val n = readLine()?.toIntOrNull() ?: error(\"n not valid\")\n val s = readLine()?.substring(0 until n) ?: error(\"s not valid\")\n\n println(s.twoGrams().max())\n}"}, {"source_code": " fun main(){\n readLine();\n val characters = readLine()!!;\n \n var best_count = -1;\n var best_index = -1;\n \n var i = 0;\n while(i < characters.length - 1){\n var count = 0;\n \n val reference1 = characters.get(i);\n val reference2 = characters.get(i + 1);\n \n var j = i;\n while(j < characters.length - 1){\n val character1 = characters.get(j);\n val character2 = characters.get(j + 1);\n \n if(character1 == reference1 && character2 == reference2){\n count = count + 1;\n }\n \n j = j + 1;\n }\n \n if(count > best_count){\n best_count = count;\n best_index = i;\n }\n \n i = i + 1;\n }\n \n println(characters.substring(best_index, best_index + 2));\n }"}, {"source_code": "\nfun main(args: Array) {\n val nbCharacters: Int = readLine()!!.toInt()\n val word: String = readLine()!!\n val map: MutableMap = mutableMapOf()\n for (i in 0 .. nbCharacters-2) {\n val w = word.substring(i, i+2)\n val value = map.getOrElse(w) {0} + 1\n map.put(w, value )\n }\n\n var maxVal = -1\n var comb = \"\"\n map.forEach { k, v ->\n if (v > maxVal) {\n comb = k\n maxVal = v\n }\n }\n print(comb)\n}\n"}, {"source_code": "import kotlin.math.*\n \nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\nprivate fun Boolean.toInt() = if (this) 1 else 0\n \nprivate fun isPalindrome(s: String): Int {\n val n = s.length\n for(i in 0..n/2-1){\n if (s[i] != s[n-i-1]){\n return 0\n }\n }\n return 1\n}\n \nfun main(args : Array) {\n var n = readInt()\n var s = readLn()\n var cnt = mutableMapOf()\n for(i in 1..n-1){\n var key = s.substring(i-1,i+1)\n if (cnt[key] == null){\n cnt[key] = 1\n }\n else {\n cnt[key] = cnt[key]!! + 1\n }\n }\n var dg = \"##\"\n var c = 0\n for((k,v) in cnt){\n if (v > c){\n dg = k\n c = v\n }\n }\n print(dg)\n}\n"}, {"source_code": "\n\nimport java.util.*\nimport kotlin.collections.ArrayList\n\nfun main() {\n val input = Scanner(System.`in`)\n val n = input.nextInt()\n val s = input.next()\n\n val letters = s.split(\"\")\n val iSize = letters.size - 3\n val dGrams: ArrayList = ArrayList()\n for (i in 1..iSize) {\n dGrams.add(\"${letters[i]}${letters[i + 1]}\")\n }\n\n var mGram = Int.MIN_VALUE\n var mIndex = 0\n val count: ArrayList> = ArrayList()\n for (i in dGrams) {\n var exists = false\n var gIndex = 0\n count.forEachIndexed { index, pair ->\n if (pair.first == i) {\n exists = true\n gIndex = index\n return@forEachIndexed\n }\n }\n if (!exists) {\n count.add(Pair(i, 1))\n } else {\n val num = count[gIndex].second + 1\n count[gIndex] = Pair(i, num)\n if (num > mGram) {\n mGram = num\n mIndex = gIndex\n }\n }\n }\n\n print(count[mIndex].first)\n}\n"}, {"source_code": "fun main() {\n val l = readLine()!!.toInt()\n val s = readLine()!!\n\n val r :HashMap = hashMapOf()\n\n for (i in 0 until l - 1) {\n val x = s.substring(i, i + 2)\n if (r.containsKey(x)) {\n r[x] = r[x]!!.plus(1)\n } else {\n r[x] = 0\n }\n }\n\n var z = -1\n var y = \"\"\n for (j in r) {\n if (j.value > z) {\n z = j.value\n y = j.key\n }\n }\n println(y)\n}"}, {"source_code": "fun main(args: Array) {\n val t = 1 // readLine()!!.toInt()\n \n repeat(t) {\n val ma = mutableMapOf() \n \n val n = readLine()!!.toInt()\n val s = readLine()!!\n \n var i=0\n while(i \")\n ma[ss] = ma[ss]!!.inc() \n // println(\"${ma[ss]}\")\n }\n i++\n }\n \n var ssmax = ma.keys.first()\n // println(\"${ssmax} ${ma[ssmax]}\")\n \n for (ss in ma.keys) { \n // println(\"${ss} ${ma[ss]!!} ${}\")\n \n if ( ma[ss]!! > ma[ssmax]!! ) {\n // println(\"${ss} > ${ssmax}\")\n ssmax = ss\n }\n } \n \n println(ssmax)\n \n }\n}\n"}, {"source_code": "\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\n\nfun main() {\n var n = readInt()\n var s = readLn()\n var m = HashMap()\n\n for (i in 0..s.length-2) {\n var str = s[i].toString() + s[i + 1]\n if (m.containsKey(str))\n m[str] = m[str]!! + 1\n else\n m[str] = 1\n }\n var mx = Pair(\"\", 0)\n for ((k,v) in m) {\n if (mx.second < v) {\n mx = Pair(k,v)\n }\n }\n print(mx.first)\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.HashMap\n\nfun main(vararg args: String) {\n val scanner = Scanner(System.`in`)\n val length = scanner.nextInt()\n val string = scanner.next()\n println(find(length, string))\n}\n\nfun find(length: Int, string: String): String {\n val map = HashMap()\n for (i in 0 until length - 1) {\n val str = string.substring(i, i + 2)\n if (map.containsKey(str)) {\n map[str] = map[str]!! + 1\n } else {\n map[str] = 1\n }\n }\n return map.maxBy { it.value }!!.key\n}\n\n"}, {"source_code": "import java.util.StringTokenizer\nimport java.io.InputStreamReader\nimport java.io.BufferedReader\nimport java.io.InputStream\nimport java.util.HashMap\nimport kotlin.math.max\n\nfun main() {\n\n R.init(System.`in`)\n var n = R.nextInt()\n var s = R.next()\n val map:HashMap = HashMap();\n var max=0\n var ans=\"\"\n for(i in 0..n-2){\n var x = s.substring(i,i+2)\n if(map.containsKey(x)){\n map.put(x,map.getValue(x)+1)\n }\n else{\n map.put(x,1);\n }\n if(max = this.zipWithNext { a, b -> \"$a$b\" }.groupingBy { it }.eachCount()\n\nfun Map.max(): String? = this.maxBy { it.value }?.key\n\nfun main() {\n val n = readLine()?.toIntOrNull() ?: error(\"n not valid\")\n val s = readLine()?.substring(0 until n) ?: error(\"s not valid\")\n\n println(s.twoGrams().max())\n}"}, {"source_code": "import java.io.PrintWriter\nimport java.util.*\n\n\n/**\n * Created on : May 12, 2018\n * Author : zetbaitsu\n * Name : Zetra\n * GitHub : https://github.com/zetbaitsu\n */\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val input = Scanner(inputStream)\n val output = PrintWriter(outputStream)\n val solver = Solver()\n solver.solve(input, output)\n output.close()\n}\n\nclass Solver {\n fun solve(input: Scanner, output: PrintWriter) {\n val n = input.nextInt()\n input.nextLine()\n val s = input.nextLine()\n\n val map = mutableMapOf()\n (0 until n - 1)\n .map { \"${s[it]}${s[it + 1]}\" }\n .forEach {\n if (map.containsKey(it)) {\n val value = map[it]!!\n map[it] = value + 1\n } else {\n map[it] = 1\n }\n }\n\n output.println(map.entries.maxBy { it.value }?.key)\n }\n}"}, {"source_code": "private fun readLnString() = readLine()!! // string line\nprivate fun readInt() = readLnString().toInt() // single int\nprivate fun readStrings() = readLnString().split(\" \") // list of strings\nprivate fun readIntList() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongList() = readStrings().map { it.toLong() } // list of longs\nprivate fun readStringPair() = readStrings().zipWithNext()[0]\nprivate fun readIntPair() = readStrings().map { it.toInt() }.zipWithNext()[0]\n\n//Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the\n// string) maximal number of times. For example, for string s = \"BBAABBBA\" the answer is two-gram \"BB\", which contained\n// in s three times. In other words, find any most frequent two-gram.\n\n//7\n//ABACABA\n//AB\nfun main() {\n val size = readInt()\n val string = readLnString()\n\n val map = mutableMapOf()\n\n for (index in 0..string.length - 2) {\n val substring = string.substring(index, index + 2)\n\n if (map.containsKey(substring))\n map[substring] = map.getOrDefault(substring, 1) + 1\n else\n map[substring] = 1\n }\n\n println(map.maxBy { entry -> entry.value}?.component1())\n}\n"}, {"source_code": "fun main(): Unit {\n readLine()\n print(\n readLine()!!.asSequence()\n .windowed(2, 1)\n .map { \"${it[0]}${it[1]}\"}\n .groupBy { it }\n .maxBy { it.value.size }?.key\n )\n}"}, {"source_code": "fun main(args: Array) {\n val numberOfLines = readLine()?.toInt() ?: 0\n var string = readLine()\n val substrings = string?.chunked(2)\n val entries = mutableMapOf()\n\n for (i in 0 until numberOfLines) {\n val firstEntry = string?.get(i)\n val secondEntry = if (i == numberOfLines - 1) \"\" else string?.get(i + 1)\n val finalKey = \"$firstEntry$secondEntry\"\n\n if (entries.containsKey(finalKey)) {\n entries.merge(finalKey, 1) { old, value ->\n old + value\n }\n } else {\n entries[finalKey] = 1\n }\n }\n\n val max = entries.maxBy { it.value }\n println(max?.key)\n}"}, {"source_code": "fun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main(args: Array) {\n var n = readInt()\n var s = readLn()\n val fre = Array(26, {IntArray(26){0}})\n for(i in 0..n-2){\n fre[s[i].toInt() - 'A'.toInt()][s[i+1].toInt()-'A'.toInt()]++\n }\n var mx = 0\n var an = \"\"\n for(i in 0..25){\n for(j in 0..25){\n if(fre[i][j] > mx){\n mx = fre[i][j]\n an=\"\"+(i+'A'.toInt()).toChar()\n an+=(j+'A'.toInt()).toChar()\n }\n }\n }\n println(an)\n}"}, {"source_code": "private fun readLnString() = readLine()!! // string line\nprivate fun readInt() = readLnString().toInt() // single int\nprivate fun readStrings() = readLnString().split(\" \") // list of strings\nprivate fun readIntList() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongList() = readStrings().map { it.toLong() } // list of longs\nprivate fun readStringPair() = readStrings().zipWithNext()[0]\nprivate fun readIntPair() = readStrings().map { it.toInt() }.zipWithNext()[0]\n\n//Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the\n// string) maximal number of times. For example, for string s = \"BBAABBBA\" the answer is two-gram \"BB\", which contained\n// in s three times. In other words, find any most frequent two-gram.\n\n//7\n//ABACABA\n//AB\nfun main() {\n val size = readInt()\n val string = readLnString()\n\n val map = mutableMapOf()\n\n for (index in 0..string.length - 2) {\n val substring = string.substring(index, index + 2)\n\n if (map.containsKey(substring))\n map[substring] = map.getOrDefault(substring, 1) + 1\n else\n map[substring] = 1\n }\n\n println(map.maxBy { entry -> entry.value}?.component1())\n}\n"}, {"source_code": "import java.util.Scanner;\n\nfun main() {\n val input = Scanner(System.`in`);\n\n var n = readLine()!!.toInt()\n var str = readLine()!!.toCharArray()\n\n var mp = mutableMapOf();\n\n for(i in 0..(n-2)) {\n var s = (str?.get(i)?.toString()) + str?.get(i+1)?.toString();\n if (mp.containsKey(s)) {\n mp[s] = mp.getValue(s)+1;\n } else {\n mp.put(s, 1);\n }\n }\n\n var ans: String = \"\";\n var num: Int = 0;\n\n for((str, count) in mp) {\n if (count > num) {\n num = count;\n ans = str;\n }\n }\n println(ans);\n}\n"}, {"source_code": "import java.util.*\n \nfun main() {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n val s = sc.next()\n val m = hashMapOf()\n for (i in 0 until n - 1) {\n val x = s.substring(i, i + 2)\n m[x] = m.getOrDefault(x, 0) + 1\n }\n var cnt = 0\n var res: String? = null\n for (e in m) {\n if (cnt < e.value) {\n cnt = e.value\n res = e.key\n }\n }\n println(res)\n}"}, {"source_code": "import java.io.OutputStream\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.PrintWriter\nimport java.util.Scanner\nimport java.util.HashMap\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author maxkibble\n */\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val `in` = Scanner(inputStream)\n val out = PrintWriter(outputStream)\n solve(1, `in`, out)\n out.close()\n}\n\nfun solve(testNumber: Int, `in`: Scanner, out: PrintWriter) {\n val n = `in`.nextInt()\n val s = `in`.next()\n val m = HashMap()\n var ans = \"\"\n var ans_x = 0\n for (i in 0 until n - 1) {\n val ss = s.substring(i, i + 2)\n val x = m.getOrDefault(ss, 0)\n m.put(ss, x + 1)\n if (x + 1 > ans_x) {\n ans = ss\n ans_x = x + 1\n }\n }\n out.println(ans)\n}\n\n\n"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n val input = readLine()!!.substring(0, n)\n\n println(twoGram(input))\n}\n\nfun twoGram(input: String): String {\n val map = HashMap()\n\n var maxCount = 0\n var maxGram = \"\"\n\n for(i in 0..(input.length - 2)) {\n val key = \"${input[i]}${input[i+1]}\"\n map[key] = (map[key]?:0).plus(1)\n\n if(map[key]?.compareTo(maxCount)?:0 > 0) {\n maxCount = map[key]?:0\n maxGram = key\n }\n }\n\n return maxGram\n}"}, {"source_code": "fun main(args: Array){\n\tval debug = false\n\tval k = readLine()!!.toInt()\n\tval stroka = readLine().toString()\n\tval mapa = mutableMapOf()\n\n\tfor (i in 0..k-2){\n\t\tif (debug) println(\"Debug! $i ${stroka.substring(i,i+2)}\")\n\t\tval digr = stroka.substring(i,i+2)\n\t\tif (mapa.containsKey(digr)){\n\t\t\tmapa.put(digr, mapa.getValue(digr) + 1)\n\t\t}else{\n\t\t\tmapa.put(digr,1)\n\t\t}\n\t}\n\tval sorted = mapa.toList().sortedBy{-it.second}\n//\tprintln(n)\n\tprintln(sorted[0].first)\n\tif (debug) println(\"Debug!\")\n}"}, {"source_code": "fun twoGram(input: String) = input.windowed(2).groupingBy { it }.eachCount().maxBy { it.value }?.key\n\nfun main(args: Array) {\n readLine()\n println(readLine()?.let { twoGram(it) })\n}"}, {"source_code": "private fun readLnString() = readLine()!! // string line\nprivate fun readInt() = readLnString().toInt() // single int\nprivate fun readStrings() = readLnString().split(\" \") // list of strings\nprivate fun readIntList() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongList() = readStrings().map { it.toLong() } // list of longs\nprivate fun readStringPair() = readStrings().zipWithNext()[0]\nprivate fun readIntPair() = readStrings().map { it.toInt() }.zipWithNext()[0]\n\n//Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the\n// string) maximal number of times. For example, for string s = \"BBAABBBA\" the answer is two-gram \"BB\", which contained\n// in s three times. In other words, find any most frequent two-gram.\n\n//7\n//ABACABA\n//AB\nfun main() {\n val size = readInt()\n val string = readLnString()\n\n val map = mutableMapOf()\n\n for (index in 0..string.length - 2) {\n val substring = string.substring(index, index + 2)\n\n if (map.containsKey(substring))\n map[substring] = map.getOrDefault(substring, 1) + 1\n else\n map[substring] = 1\n }\n\n println(map.maxBy { entry -> entry.value}?.component1())\n}\n"}, {"source_code": "import java.util.Scanner\nimport kotlin.collections.HashMap\nimport kotlin.collections.set\nfun main() {\n val sc = Scanner(System.`in`)\n val map = HashMap()\n\n val n = Integer.parseInt(sc.nextLine())\n val str = sc.nextLine()\n\n for (i in 0 until n - 1) {\n val word = str.substring(i, i + 2)\n\n val count = map[word]\n\n if (count == null) map[word] = 1 else map[word] = count + 1\n }\n\n println(map.entries.stream().max { entry1, entry2 -> if (entry1.value > entry2.value) 1 else -1 }.get().key)\n}\n"}, {"source_code": "import java.util.*\n\nfun readLn() = readLine()!!\nfun readStrings() = readLn().split(\" \")\nfun readInts() = readStrings().map{ it.toInt() }\n\nfun main() {\n var (n) = readInts()\n var (s) = readStrings()\n var mp = HashMap()\n for (i in 0..n - 2) {\n var t = s.substring(i, i + 2)\n mp[t] = mp.getOrDefault(t, 0) + 1\n }\n var ans = \"\"\n var mx = 0\n for ((key, value) in mp) {\n if (value > mx) {\n mx = value\n ans = key\n }\n }\n println(ans)\n}\n"}, {"source_code": "import java.util.Scanner\nfun main() {\n \n val reader = Scanner(System.`in`)\n var size:Int=reader.nextInt()\n var s:String=reader.next()\n var i=0\n var mx=0\n var f:String=\"\"\n while(i){val l=readLine()!!.toInt();val s=readLine()!!;val m=HashMap();(0 until l-1).map{\"${s[it]}${s[it +1]}\"}.forEach{if(m.containsKey(it))m[it]=m[it]!!+1 else m[it]=1};println(m.maxBy{ it.value}!!.key)}"}, {"source_code": "//package com.happypeople.codeforces.c1212\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\n\nfun main(args: Array) {\n try {\n B1212().run()\n } catch (e: Throwable) {\n println(\"\")\n e.printStackTrace()\n }\n}\n\nclass B1212 {\n fun run() {\n val sc = Scanner(systemIn())\n val n=sc.nextInt()\n val str=sc.next()\n val dmap = mutableMapOf()\n for(i in 0..str.length-2) {\n val twogram=str.substring(i..i+1)\n val old=dmap.getOrDefault(twogram, 0);\n dmap.set(twogram, old+1);\n }\n println(dmap.toList().sortedByDescending { (_, value) -> value }.first().first)\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}\n"}, {"source_code": "fun main() {\n val inputLen = readLine()?.toInt()\n println(readLine()?.let { input ->\n val map = mutableMapOf()\n for (i in 0 until inputLen?.dec()!!) {\n input.substring(i, i.plus(2)).let { tg ->\n map[tg] = map[tg]?.inc() ?: 1\n }\n }\n map.maxBy {\n it.value\n }?.key\n })\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\n\nprivate fun solve() {\n var mx = 0\n var ans = \"\"\n val n = readInt()\n val s = readLn()\n val ar = mutableListOf()\n for (i in 1 until s.length){\n var temp: String = (s[i - 1]).toString()\n temp += s[i]\n ar.add(temp)\n }\n for (i in 0 until ar.size){\n var cnt = 0\n val cur = ar[i]\n for (j in 1 until s.length) {\n //println(s.substring(IntRange(j - 1, j)))\n if (s.substring(IntRange(j - 1, j)) == cur)\n cnt++\n }\n if (cnt > mx) {\n mx = cnt\n ans = cur\n }\n\n }\n println(ans)\n}\nfun main(args: Array) {\n solve()\n}"}, {"source_code": "import javax.print.attribute.IntegerSyntax\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\n\nfun main(args: Array) {\n val n = readInt()\n var s = readLn()\n\n val freq = mutableMapOf()\n\n for (i in 0 until n - 1) {\n val twoGram = s.substring(i, i + 2)\n freq[twoGram] = freq.getOrDefault(twoGram, 0) + 1\n }\n\n var result = \"\"\n var maxCount = 0\n for (item in freq) {\n if (item.value > maxCount) {\n maxCount = item.value\n result = item.key\n }\n }\n\n println(result)\n}\n"}, {"source_code": "import java.util.HashMap\nimport java.util.Scanner\n fun main(args:Array) {\n val sc = Scanner(System.`in`)\n sc.nextInt()\n val s = sc.next()\n println(solve(s))\n sc.close()\n }\n internal fun solve(s:String):String {\n val twoGramToCount = HashMap()\n for (i in 0 until s.length - 1)\n {\n val twoGram = s.substring(i, i + 2)\n twoGramToCount.put(twoGram, (twoGramToCount as java.util.Map).getOrDefault(twoGram, 0) + 1)\n }\n val maxCount = twoGramToCount.values.stream().mapToInt({ x-> x }).max().getAsInt()\n return twoGramToCount.keys.stream().filter({ twoGram-> twoGramToCount.get(twoGram) == maxCount }).findAny()\n .get()\n }"}, {"source_code": "fun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun ctoi(c : Char): Int{\n return c.toInt() - 'A'.toInt()\n}\nfun itoc(c : Int): Char{\n return (c+'A'.toInt()).toChar()\n}\nfun main(args: Array) {\n var n = readInt()\n var s = readLn()\n val fre = Array(26, {IntArray(26){0}})\n for(i in 0..n-2){\n fre[ctoi(s[i])][ctoi(s[i+1])]++\n }\n var mx = 0\n var an = \"\"\n for(i in 0..25){\n for(j in 0..25){\n if(fre[i][j] > mx){\n mx = fre[i][j]\n an=\"\"+itoc(i)\n an+=itoc(j)\n }\n }\n }\n println(an)\n}"}, {"source_code": "fun main(){\n var n=readLine()!!.toInt()\n var str=readLine()!!\n val total=IntArray(700)\n for (x in 1..n-1){\n total[hash(str[x-1],str[x])]++\n }\n var most=0\n for (x in 0..699){\n if (total[x]>total[most]) most=x\n }\n print(\"${((most/26)+'A'.toInt()).toChar() }${((most%26)+'A'.toInt()).toChar()}\\n\")\n}\nfun hash(i:Char, j:Char):Int{\n return (i-'A')*26 + (j-'A')\n}"}, {"source_code": "import java.util.*\n\nclass Main : Runnable {\n private val scanner: Scanner = Scanner(System.`in`)\n\n override fun run() {\n scanner.nextInt()\n scanner.nextLine()\n val string = scanner.nextLine()\n val max =\n IntRange(0, string.length - 2)\n .groupingBy { string.substring(it, it + 2) }\n .eachCount()\n .maxBy { it.value }!!\n println(max.key)\n }\n\n}\n\nfun main() = Main().run()\n\n"}, {"source_code": "fun main() {\n val count = readLine()!!.toInt()\n val str = readLine()!!\n\n var max = Int.MIN_VALUE\n var maxStr = str.subSequence(0, 2)\n for (i in 0 .. count - 2) {\n val subStr = str.substring(i, i + 2)\n var current = 0\n for (i in 0 .. count - 2) {\n val subStr2 = str.substring(i, i + 2)\n if (subStr == subStr2)\n current++\n }\n\n if (current > max) {\n max = current\n maxStr = subStr\n }\n }\n print(maxStr)\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main(args: Array) {\n var n = readInt()\n var s = readLn()\n var m = HashMap()\n for (i in 0..n-2) {\n var t = s.substring(i, i + 2)\n if (m.containsKey(t)) {\n m.put(t, m.get(t)!! + 1)\n } else {\n m.put(t, 1)\n }\n }\n var mx = -1\n var res = \"\"\n for (t in m.keys) {\n if (m.get(t)!! > mx) {\n mx = m.get(t)!!\n res = t\n }\n }\n println(res)\n}"}, {"source_code": "import javax.print.attribute.IntegerSyntax\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\n\nfun main(args: Array) {\n val n = readInt()\n var s = readLn()\n\n val freq = mutableMapOf()\n\n for (i in 0 until n - 1) {\n val twoGram = s.substring(i, i + 2)\n freq[twoGram] = freq.getOrDefault(twoGram, 0) + 1\n }\n\n var result = \"\"\n var maxCount = 0\n for (item in freq) {\n if (item.value > maxCount) {\n maxCount = item.value\n result = item.key\n }\n }\n\n println(result)\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.HashMap\nimport kotlin.math.max\n\nfun main() {\n\n val scan = Scanner(System.`in`)\n var n: Int = scan.nextLine().trim().toInt()\n val str: String = scan.nextLine().trim()\n\n val hashMap = HashMap()\n\n for (i in 0 until str.length - 1) {\n val diagram = str.substring(i, i + 2)\n if (hashMap.contains(diagram)) {\n val value = hashMap.getValue(diagram)\n hashMap.replace(diagram, value + 1)\n } else {\n hashMap[diagram] = 1\n }\n }\n\n val maxValue = hashMap.values.max()\n print(hashMap.filterValues { it == maxValue }.keys.toList()[0])\n\n\n}\n"}, {"source_code": "fun main(args : Array) {\n var n = readLine()!!.toInt()\n var str = readLine()!!\n\n var map = mutableMapOf()\n for (i in 0..n - 2) {\n var sub = str.substring(i..i + 1)\n if (!map.contains(sub)) map[sub] = 1\n else map[sub] = map[sub]!! + 1\n }\n\n var max = 0\n var ans = \"\"\n map.forEach {\n if (it.value > max) {\n max = it.value\n ans = it.key\n }\n }\n println(ans)\n}"}, {"source_code": "import java.util.*\n \n/**\n * Kotlin Heroes: Practice 2\n * B. Двуграмма\n * http://codeforces.com/contest/1212/problem/B\n * */\nclass B\n \nfun main() {\n readLine()\n val s = readLine()!!.toCharArray()\n val arr = Array(pos('Z', 'Z') + 1) { 0 }\n \n var max = 0\n var maxS = \"\"\n for (i in 1 until s.size) {\n val pos = pos(s[i - 1], s[i])\n if (++arr[pos] > max) {\n max = arr[pos]\n maxS = \"${s[i - 1]}${s[i]}\"\n }\n }\n println(maxS)\n}\n \nfun pos(a: Char, b: Char) = (a - 'A') * ('Z' - 'A' + 1) + (b - 'A')"}, {"source_code": "fun main() {\n readLine()\n val s = readLine()!!\n val res=s.zipWithNext { a, b -> a.toString() + b }\n .groupingBy { it }\n .eachCount()\n .maxBy { it.value }\n ?.key!!\n println(res)\n}"}, {"source_code": "import kotlin.math.max\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nval map = HashMap()\nfun main() {\n val n = readInt()\n val k = readLn()\n findSequence(k, 0, n)\n val res = map.maxBy { it.value }\n println(res?.key.toString().capitalize())\n}\n\nfun findSequence(input: String, pos: Int, max: Int) {\n val sequence = input.subSequence(pos, pos + 2)\n if (map.containsKey(sequence)) {\n map[sequence] = map[sequence]!!.plus(1)\n } else {\n map[sequence] = 1\n }\n if (pos + 2 < max) {\n findSequence(input, pos + 1, max)\n }\n}"}, {"source_code": "fun main(args: Array) {\n\n // reading the input and saving it\n val amountOfLetters = readLine()!!.toInt()\n val inputString = readLine()!!\n\n // the var will be the temporary string containing the two-gram to be checked while traversing through\n // the input String\n var tempString: String\n\n // the hashmap will contain the two-gram string along with the occurences\n // it will be initialied with the first two-gram and its counter value of 1\n var counterHashMap: MutableMap = mutableMapOf(inputString.subSequence(0,2).toString() to 1)\n\n // iterating over the string, saving each two-gram in a temporary string\n // checking if the two-gram exists in the hashmap\n // yes: increase the value, no: adding the two-gram to the hasmap and initializing the value to 1\n for((index,character) in inputString.withIndex()) {\n // to avoid the indexOutOfBounce exception, the index is being checked\n if(index == inputString.length-1) break\n // skip the first 2 letters as they have been added in the initialisation\n if(index == 0) continue;\n\n // concatenating two chars\n tempString = \"\" + character + inputString[index+1]\n // check if the two-gram is in the haspMap\n if(tempString in counterHashMap) {\n // increase the value if it does\n counterHashMap.set(tempString, counterHashMap.get(tempString)!!.plus(1))\n } else {\n // add the value to hashmap if it doesnt with value 1\n counterHashMap.put(tempString,1)\n }\n }\n println(counterHashMap.maxBy{it.value}.toString().subSequence(0,2))\n}"}, {"source_code": "fun main() {\n val numLetters = readLine()!!.toInt()\n val word = readLine()!!\n\n var twoGramFrequencies = mutableMapOf()\n for (i in 0 until numLetters - 1) {\n var currentTwoGram = word.substring(i..i + 1)\n if (twoGramFrequencies.containsKey(currentTwoGram)) {\n twoGramFrequencies.entries.filter { it.key == currentTwoGram }.map { it.setValue(it.value + 1) }\n } else {\n twoGramFrequencies[currentTwoGram] = 0\n }\n }\n\n println(twoGramFrequencies.maxBy { it.value }!!.key)\n}"}, {"source_code": "fun main(args: Array) {\n val numberOfLines = readLine()?.toInt() ?: 0\n var string = readLine()\n val substrings = string?.chunked(2)\n val entries = mutableMapOf()\n\n for (i in 0 until numberOfLines) {\n val firstEntry = string?.get(i)\n val secondEntry = if (i == numberOfLines - 1) \"\" else string?.get(i + 1)\n val finalKey = \"$firstEntry$secondEntry\"\n\n if (entries.containsKey(finalKey)) {\n entries.merge(finalKey, 1) { old, value ->\n old + value\n }\n } else {\n entries[finalKey] = 1\n }\n }\n\n val max = entries.maxBy { it.value }\n println(max?.key)\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val reader = Scanner(System.`in`)\n reader.nextInt()\n val s = reader.next().trim()\n val m = mutableMapOf()\n for (k in s.zipWithNext().map { \"${it.first}${it.second}\" })\n m[k] = m.getOrDefault(k, 0) + 1\n println(m.maxBy { it.value }?.key)\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val n = readInt()\n val s = readLn()\n val map = HashMap()\n for (i in 0 until s.length-1) {\n val sub = s[i].toString() + s[i + 1].toString()\n map[sub] = map.getOrDefault(sub, 0) + 1\n }\n println(map.maxBy { it.value }!!.key)\n}"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n\n val n = sc.nextInt()\n val str = sc.next()\n\n val map = HashMap()\n\n for (i in 0 until n - 1) {\n val dg = \"${str[i]}${str[i+1]}\"\n val dg2 = \"ldksjflskdjflksdjf\"\n if (!map.containsKey(dg)) {\n map[dg] = 0\n }\n if (!map.containsKey(dg2)) {\n //map[dg2] = 0\n }\n if (dg == dg2) {\n map[dg] = map[dg]!! + 1\n } else {\n map[dg] = map[dg]!! + 1\n //map[dg2] = map[dg2]!! + 1\n }\n }\n\n var max = -1\n var maxv = \"sf\"\n\n map.forEach({k, v ->\n if (v > max) {\n max = v\n maxv = k\n }\n })\n println(maxv)\n}\n\n"}, {"source_code": "import java.io.StreamTokenizer\n\nfun main(args: Array) {\n val tokenizer = StreamTokenizer(System.`in`)\n val n = tokenizer.nextInt()\n val s = tokenizer.nextString().toCharArray()\n val map = HashMap, Int>()\n var max = 0\n var ans: Pair? = null\n for (i in 0 until n - 1) {\n val p = Pair(s[i], s[i + 1])\n val v = (map[p] ?: 0) + 1\n map[p] = v\n if (v > max) {\n max = v\n ans = p\n }\n }\n println(\"${ans!!.first}${ans.second}\")\n}\n\nfun StreamTokenizer.nextString(): String {\n return if (nextToken() == StreamTokenizer.TT_WORD) sval else \"\"\n}\n\nfun StreamTokenizer.nextInt(): Int {\n return if (nextToken() == StreamTokenizer.TT_NUMBER) nval.toInt() else -1\n}\n\nfun StreamTokenizer.nextDouble(): Double {\n return if (nextToken() == StreamTokenizer.TT_NUMBER) nval else 0.0\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val input = Scanner(System.`in`)\n\n val n = input.nextLine().toInt()\n val s = input.nextLine().toString()\n var max = 0\n var sequence = \"\"\n\n s.windowed(2,1, false) { toTest ->\n var count = 0\n s.windowed(2,1, false) { toMatch ->\n if (toTest == toMatch) {\n count ++\n }\n if (count>max) {\n max = count\n sequence = toTest.toString()\n }\n }\n }\n\n println(sequence)\n}"}, {"source_code": "import java.util.Scanner\nfun main(args: Array){\n val input = Scanner(System.`in`)\n var pituus = readLine()!!\n var teksti = readLine()!!\n var maksimi: Int = 0\n var kirjaimet: String = \"\"\n for(i in 0..(teksti.length-2)){\n var kaksi: String = \"\" + teksti[i] + teksti[i+1]\n var luku: Int = 0\n for(j in 0..(teksti.length-2)){\n var uudetkaksi: String = \"\" + teksti[j] + teksti[j+1]\n if(kaksi.equals(uudetkaksi)){\n luku += 1\n }\n }\n if(luku > maksimi){\n maksimi = luku\n kirjaimet = kaksi\n }\n }\n println(kirjaimet)\n}"}, {"source_code": "private fun readLnString() = readLine()!! // string line\nprivate fun readInt() = readLnString().toInt() // single int\nprivate fun readStrings() = readLnString().split(\" \") // list of strings\nprivate fun readIntList() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongList() = readStrings().map { it.toLong() } // list of longs\nprivate fun readStringPair() = readStrings().zipWithNext()[0]\nprivate fun readIntPair() = readStrings().map { it.toInt() }.zipWithNext()[0]\n\n//Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the\n// string) maximal number of times. For example, for string s = \"BBAABBBA\" the answer is two-gram \"BB\", which contained\n// in s three times. In other words, find any most frequent two-gram.\n\n//7\n//ABACABA\n//AB\nfun main() {\n val size = readInt()\n val string = readLnString()\n\n val map = mutableMapOf()\n\n for (index in 0..string.length - 2) {\n val substring = string.substring(index, index + 2)\n\n if (map.containsKey(substring))\n map[substring] = map.getOrDefault(substring, 1) + 1\n else\n map[substring] = 1\n }\n\n println(map.maxBy { entry -> entry.value}?.component1())\n}\n"}, {"source_code": "fun String.twoGrams(): Map = this.zipWithNext { a, b -> \"$a$b\" }.groupingBy { it }.eachCount()\n\nfun Map.max(): String? = this.maxBy { it.value }?.key\n\nfun main() {\n val n = readLine()?.toIntOrNull() ?: error(\"n not valid\")\n val s = readLine()?.substring(0 until n) ?: error(\"s not valid\")\n\n println(s.twoGrams().max())\n}"}, {"source_code": "\nobject programkt{\n//object TwoGram {\n @JvmStatic\n fun main(vararg args: String){\n val n = readLine()!!.toInt()\n val str = readLine()!!\n val result = exec(n, str)\n println(result)\n }\n\n fun exec(n: Int, str: String): String {\n var tg = Pair(-1, \"\")\n for(i in 0 until n-1){\n val sub = \"${str[i]}${str[i+1]}\"\n var count = 0\n for(i in 0 until str.length-1){\n if(str[i] == sub[0] && str[i+1] == sub[1]) count++\n }\n if(count > tg.first){\n tg = Pair(count, sub)\n }\n }\n return tg.second\n }\n\n}\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n var n = scanner.nextLine()\n val s = scanner.nextLine()\n\n val map: HashMap = hashMapOf()\n\n s.forEachIndexed { i, c ->\n if (i < s.length - 1) {\n val char0 = s[i]\n val char1 = s[i + 1]\n if (char0.isUpperCase() && char1.isUpperCase()) {\n val res = map.get(\"$char0$char1\")\n\n if (res == null) {\n map.put(\"$char0$char1\", 1)\n } else {\n map.put(\"$char0$char1\", res + 1)\n }\n }\n }\n }\n var max = 0\n var result = \"\"\n map.forEach { ss, count ->\n if (count > max) {\n max = count\n result = ss\n }\n }\n\n println(result)\n\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n Scanner(System.`in`).use { scanner ->\n scanner.nextInt() // not needed for first approach...\n val string = scanner.next()\n println(TwoGramSolver.solve(string))\n }\n}\n\nprivate object TwoGramSolver {\n\n internal fun solve(string: String): String {\n val twoGrams = mutableMapOf()\n var maxTwoGram: Pair? = null\n\n string.windowed(2).forEach { twoGram ->\n val twoGramCount = (twoGrams[twoGram] ?: 0).inc()\n twoGrams[twoGram] = twoGramCount\n\n if (maxTwoGram == null) {\n maxTwoGram = twoGram to twoGramCount\n return@forEach\n }\n\n if (twoGramCount > maxTwoGram!!.second) {\n maxTwoGram = twoGram to twoGramCount\n }\n }\n\n return maxTwoGram!!.first\n }\n}"}, {"source_code": "\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\n\nfun main() {\n var n = readInt()\n var s = readLn()\n var m = HashMap()\n\n for (i in 0..s.length-2) {\n var str = s[i].toString() + s[i + 1]\n if (m.containsKey(str))\n m[str] = m[str]!! + 1\n else\n m[str] = 1\n }\n var mx = Pair(\"\", 0)\n for ((k,v) in m) {\n if (mx.second < v) {\n mx = Pair(k,v)\n }\n }\n print(mx.first)\n}"}, {"source_code": "import java.security.InvalidAlgorithmParameterException\n\n/**\n * Created by patrick on 31.08.19.\n * (c) Patrick Scheibe 2019\n */\n\nfun main() {\n contest1212problemB()\n}\n\nfun contest1212problemB() {\n val n = readLine()!!.toInt()\n val s = readLine()!!.substring(0, n)\n val grams = mutableListOf()\n for (i in 0..n - 2) {\n grams.add(s.substring(i,i+2))\n }\n val maxElm = grams.groupingBy { it }.eachCount().maxBy { it.value }\n if (maxElm != null) {\n print(maxElm.key)\n } else {\n throw InvalidAlgorithmParameterException(\"No max ngram. Shouldn't happen\")\n }\n}\n"}, {"source_code": "import java.util.*\n\nfun min(a:Double,b:Double) = if (ab) a else b \nfun min(a:Int,b:Int) = if (ab) a else b \nfun printD(d: Double) { print(d) }\nfun printI(d:Int) { print(d) }\nfun printS(d: String) { print(d) }\nfun printL(d: Long) { print(d) }\nclass pair (var first:Int, var second:Int) \n\nfun main() {\n val cin = Scanner(System.`in`)\n \n /* --------- */ \n \n /* \n map[q] <=> map.getOrDefault(q,0)\n \n */ \n var a=cin.nextInt() \n var s=cin.next()\n var max1=0; \n var ans=\"\"; \n //var m=IntArray \n var map=hashMapOf();\n \n for (i in 0..a-2) {\n var q=\"\"; q+=s[i]; q+=s[i+1];\n map[q]=map.getOrDefault(q,0)+1; \n if (map.getOrDefault(q,0)>max1) {max1=map.getOrDefault(q,0); ans=q; }\n }\n print(ans); \n \n /* --------- */ \n \n}\n"}, {"source_code": "import java.util.Scanner;\n\nfun main() {\n val input = Scanner(System.`in`);\n\n var n = readLine()!!.toInt()\n var str = readLine()!!.toCharArray()\n\n var mp = mutableMapOf();\n\n for(i in 0..(n-2)) {\n var s = (str?.get(i)?.toString()) + str?.get(i+1)?.toString();\n if (mp.containsKey(s)) {\n mp[s] = mp.getValue(s)+1;\n } else {\n mp.put(s, 1);\n }\n }\n\n var ans: String = \"\";\n var num: Int = 0;\n\n for((str, count) in mp) {\n if (count > num) {\n num = count;\n ans = str;\n }\n }\n println(ans);\n}\n"}, {"source_code": "fun main(args: Array) {\n val numberOfLines = readLine()?.toInt() ?: 0\n var string = readLine()\n val substrings = string?.chunked(2)\n val entries = mutableMapOf()\n\n for (i in 0 until numberOfLines) {\n val firstEntry = string?.get(i)\n val secondEntry = if (i == numberOfLines - 1) \"\" else string?.get(i + 1)\n val finalKey = \"$firstEntry$secondEntry\"\n\n if (entries.containsKey(finalKey)) {\n entries.merge(finalKey, 1) { old, value ->\n old + value\n }\n } else {\n entries[finalKey] = 1\n }\n }\n\n val max = entries.maxBy { it.value }\n println(max?.key)\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n val xs = (0 until n.minus(1))\n .groupingBy { s.subSequence(it..(it+1)) }\n .eachCount()\n .maxBy { it.value }?.key!!\n print(xs)\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val input = Scanner(System.`in`)\n\n val n = input.nextLine().toInt()\n val s = input.nextLine().toString()\n var max = 0\n var sequence = \"\"\n\n s.windowed(2,1, false) { toTest ->\n var count = 0\n s.windowed(2,1, false) { toMatch ->\n if (toTest == toMatch) {\n count ++\n }\n if (count>max) {\n max = count\n sequence = toTest.toString()\n }\n }\n }\n\n println(sequence)\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n val xs = (0 until n.minus(1))\n .groupingBy { s.slice(it..(it+1)) }\n .eachCount()\n .maxBy { it.value }?.key!!\n print(xs)\n}"}, {"source_code": "fun main(args : Array) {\n var n = readLine()!!.toInt()\n var str = readLine()!!\n\n var map = mutableMapOf()\n for (i in 0..n - 2) {\n var sub = str.substring(i..i + 1)\n if (!map.contains(sub)) map[sub] = 1\n else map[sub] = map[sub]!! + 1\n }\n\n var max = 0\n var ans = \"\"\n map.forEach {\n if (it.value > max) {\n max = it.value\n ans = it.key\n }\n }\n println(ans)\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of ints\n\nvar m = HashMap();\n\nfun main(){\n var n:Int = readInt()\n var s: String = readLn()\n for(i in 0..n-2){\n m[s.substring(i, i+2)] = m.getOrDefault(s.substring(i, i+2), 0) + 1;\n }\n // println(m);\n var temp = 0;\n var ans:String? = null;\n for(e in m){\n if(e.value > temp){\n temp = e.value;\n ans = e.key\n }\n }\n println(ans)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n val str = sc.next()\n\n var mm = mutableMapOf()\n var maxa = 0\n var res = \"\"\n for (i in 0 until n-1) {\n val temp = str.substring(i, i+2)\n mm[temp] = (mm[temp] ?: 0)+1\n }\n for ((key, value) in mm) {\n if (value > maxa) {\n maxa = value\n res = key\n }\n }\n println(res)\n\n\n}"}, {"source_code": "import kotlin.math.absoluteValue\nimport kotlin.math.pow\n\n\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n\n\n var pattern = mutableListOf()\n var pmap = mutableMapOf()\n if (n >= 2 && n <= 100) {\n\n for (i in 0..(n - 2)) {\n if (s.substring(i, i + 2) in pattern) {\n var count = pmap[s.substring(i, i + 2)]\n\n if (count != null) {\n pmap[s.substring(i, i + 2)] = count + 1\n }\n } else {\n pattern.add(s.substring(i, i + 2))\n pmap.put(s.substring(i, i + 2), 1)\n }\n }\n }\n println(pmap.maxBy { it.value }?.key)\n}"}, {"source_code": "/**\n * You can edit, run, and share this code. \n * play.kotlinlang.org \n */\nval scan = java.util.Scanner(System.`in`)\nfun main() {\n scan.nextInt()\n var s = scan.next()\n var maxTwogram = \"\"\n var maxCount = 0\n for(i in 0 until s.length-1) {\n val twogram = s.substring(i, i+2)\n var count = 0\n for (j in i until s.length-1) {\n if(s.substring(j).startsWith(twogram)) count ++\n }\n if(maxCount < count) {\n maxTwogram = twogram\n maxCount = count\n }\n }\n println(maxTwogram)\n}"}, {"source_code": "fun String.twoGrams(): Map = this.zipWithNext { a, b -> \"$a$b\" }.groupingBy { it }.eachCount()\n\nfun Map.max(): String? = this.maxBy { it.value }?.key\n\nfun main() {\n val n = readLine()?.toIntOrNull() ?: error(\"n not valid\")\n val s = readLine()?.substring(0 until n) ?: error(\"s not valid\")\n\n println(s.twoGrams().max())\n}"}, {"source_code": "\nimport java.io.InputStream\nimport kotlin.math.max\n\nconst val A = 'A'.toInt()\nconst val Z = 'Z'.toInt()\n\nfun main() {\n for (c in twoGram(System.`in`)) {\n print(c)\n }\n}\n\nfun twoGram(input: InputStream): CharArray {\n var len = 0\n var i: Int\n\n while (true) {\n i = input.read()\n if (i == System.lineSeparator()[0].toInt()) break\n\n len *= 10\n len += i - 0x30\n }\n\n input.skip((System.lineSeparator().length - 1).toLong())\n\n val size = Z - A + 1\n val result = Array(size) { IntArray(size) }\n\n var m = 0\n\n var c = input.read() - A\n\n for (j in 1 until len) {\n val cc = input.read() - A\n\n var v = result[c][cc]\n result[c][cc] = ++v\n m = max(m, v)\n c = cc\n }\n\n for (x in result.indices) {\n val arr = result[x]\n for (y in arr.indices) {\n if (arr[y] == m) {\n return charArrayOf((x + A).toChar(), (y + A).toChar())\n }\n }\n }\n\n return charArrayOf()\n}"}, {"source_code": "val occur = HashMap()\n\nfun main() {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n for(i in 0 until n-1) {\n val t = s.substring(i, i+2)\n if(t in occur)\n occur[t] = occur[t]!! + 1\n else\n occur[t] = 1\n }\n println(occur.maxBy { it.value }!!.key)\n}"}, {"source_code": "import java.util.regex.Pattern\n\nfun main(args: Array) {\n val ss = twogram1()\n print(ss)\n}\n\nfun twogram1(): String?{\n val n = readLine()?.toInt() ?: 0\n val s = readLine().orEmpty()\n val chars = s.toList()\n return if(n == chars.size) {\n (0 until chars.size - 1).mapNotNull { i ->\n if (i + 1 < chars.size)\n chars[i].toString() + chars[i + 1].toString()\n else null\n }.groupBy { it }.maxBy { it.value.size }?.key\n } else \"\"\n}\n\n"}], "negative_code": [{"source_code": "import java.util.*\n\n/**\n * Kotlin Heroes: Practice 2\n * B. Двуграмма\n * http://codeforces.com/contest/1212/problem/B\n * */\nclass B\n\nfun main() {\n readLine()\n val s = readLine()!!.toCharArray()\n val arr = Array(pos('Z', 'Z') + 1) { 0 }\n\n var max = 0\n var maxS = \"\"\n for (i in 1 until s.size) {\n val pos = pos(s[i - 1], s[i])\n if (++arr[pos] > max) {\n max = arr[pos]\n maxS = \"${s[i - i]}${s[i]}\"\n }\n }\n println(maxS)\n}\n\nfun pos(a: Char, b: Char) = (a - 'A') * ('Z' - 'A' + 1) + (b - 'A')\n"}, {"source_code": "fun main() {\n val count = readLine()!!.toInt()\n val str = readLine()!!\n\n var max = Int.MIN_VALUE\n var maxStr = str.subSequence(0, 2)\n for (i in 0 .. count - 2) {\n val subStr = str.subSequence(i, i + 2)\n val count = subStr.count { subStr.contains(it) }\n if (count > max) {\n max = count\n maxStr = subStr\n }\n }\n print(maxStr)\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val input = Scanner(System.`in`)\n\n// val n = input.nextLine().toInt()\n val s = input.nextLine().toString()\n var max = 0\n var sequence = \"\"\n\n s.windowed(2,1, false) { toTest ->\n var count = 0\n s.windowed(2,1, false) { toMatch ->\n if (toTest == toMatch) {\n count ++\n }\n if (count>max) {\n max = count\n sequence = toTest.toString()\n }\n }\n }\n\n println(sequence)\n}"}, {"source_code": "\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map{it.toLong()}\n//const val MOD = 1000000007\n\nfun main(args:Array){\n val n = readInt()\n val s = readLn()\n\n val skipString = s.substring(1, s.length-1)\n\n val list = s.asSequence()\n .chunked(2).map { it.joinToString(\"\") }.toList()\n\n val skiplist = skipString.asSequence()\n .chunked(2).map { it.joinToString(\"\") }.toList()\n\n val map = mutableMapOf()\n\n countGram(list, map)\n countGram(skiplist, map)\n\n var max = -1\n var key = \"\"\n map.forEach { t, u ->\n println(\"$t $u\")\n if (u>max && t.length==2){\n max = u\n key = t\n }\n }\n println(key)\n\n}\n\nfun countGram(list: List, map: MutableMap) {\n list.forEach {\n if (map.contains(it)) {\n val count = map[it]!!\n map[it] = count + 1\n } else {\n map[it] = 1\n }\n }\n}"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n\n val reader = Scanner(System.`in`)\n\n fun twoGram(n: Int, s: String): String {\n var mostCommonTwoGram: Pair = Pair(s.substring(0, 1), 1)\n val twoGramOccurrences = mutableMapOf()\n for (i in 0..n - 2) {\n val twoGram = s.substring(i, i + 2)\n twoGramOccurrences[twoGram] = twoGramOccurrences.getOrDefault(twoGram, 0) + 1\n if (twoGramOccurrences[twoGram] ?: 0 > mostCommonTwoGram.second) {\n mostCommonTwoGram = Pair(twoGram, twoGramOccurrences[twoGram] ?: 0)\n }\n\n }\n return mostCommonTwoGram.first\n }\n println(twoGram(reader.nextInt(), reader.next()))\n}"}, {"source_code": "fun twoGram(input: String) = input.windowed(2).groupingBy { it }.eachCount().maxBy { it.value }?.key\n\nfun main(args: Array) {\n println(args)\n println(args.size)\n if (args.size == 2) {\n val twoGram = twoGram(args[1])\n print(twoGram)\n }\n}"}, {"source_code": "fun main(args: Array) {\n val t = 1 //readLine()!!.toInt()\n \n repeat(t) {\n val ma = mutableMapOf() \n \n val n = readLine()!!.toInt()\n val s = readLine()!!\n \n var i=0\n while(i ma[ssmax]!! ) ssmax=ss\n }\n } \n \n println(ssmax)\n \n }\n}\n"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n\n val reader = Scanner(System.`in`)\n\n fun twoGram(n: Int, s: String): String {\n var mostCommonTwoGram: Pair = Pair(s.substring(0, 1), 1)\n val twoGramOccurrences = mutableMapOf()\n for (i in 0..n - 2) {\n val twoGram = s.substring(i, i + 2)\n twoGramOccurrences[twoGram] = twoGramOccurrences.getOrDefault(twoGram, 0) + 1\n if (twoGramOccurrences[twoGram] ?: 0 > mostCommonTwoGram.second) {\n mostCommonTwoGram = Pair(twoGram, twoGramOccurrences[twoGram] ?: 0)\n }\n\n }\n return mostCommonTwoGram.first\n }\n println(twoGram(reader.nextInt(), reader.next()))\n}"}, {"source_code": "fun readInts() = readLine()!!.split(' ').map(String::toInt)\n\nfun main(){\n var n = readLine()!!.toInt()\n var str = readLine()!!.toString()\n var ans = \"\"\n var ansCnt = 0\n for(i in 0 until (n - 1)){\n var curr = 0\n val newStr = str[i].toString() + str[i + 1].toString()\n for(j in (i + 1) until (n - 1)){\n val prStr = str[j].toString() + str[j + 1].toString()\n if(newStr == prStr){\n curr++\n }\n }\n if(curr > ansCnt){\n ansCnt = curr\n ans = newStr\n }\n }\n print(ans)\n}"}, {"source_code": "import java.util.regex.Pattern\n\nfun main(args: Array) {\n twogram()\n}\n\nfun twogram(): Pair?{\n val n = readLine()?.toInt() ?: 0\n val s = readLine().orEmpty()\n val chars = s.toList()\n if(chars.size == n) {\n val allPairs = chars.map { c ->\n chars.map {\n \"$it\" + \"$c\"\n }.distinct()\n }.flatten().distinct()\n val m = allPairs.map {\n val pattern = Pattern.compile(it) //case insensitive, use [g] for only lower\n val matcher = pattern.matcher(s)\n var count = 0\n while (matcher.find()) count++\n it to count\n }.maxBy { it.second }\n return m\n }else return \"\" to 0\n}\n\n"}, {"source_code": "fun main(args: Array) {\n val numberOfLines = readLine()?.toInt() ?: 0\n var string = readLine()\n val substrings = string?.chunked(2)\n val entries = mutableMapOf()\n\n for (i in 0 until numberOfLines) {\n val firstEntry = string?.get(i)\n val secondEntry = if (i == numberOfLines - 1) \"\" else string?.get(i + 1)\n val finalKey = \"$firstEntry$secondEntry\"\n\n if (entries.containsKey(finalKey)) {\n entries.merge(finalKey, 1) { old, value ->\n old + value\n }\n } else {\n entries[finalKey] = 1\n }\n }\n \n val max = entries.maxBy { it.value }\n println(max?.key)\n println(max?.value)\n}"}, {"source_code": "\nfun main(args: Array) {\n val nbCharacters: Int = readLine()!!.toInt()\n val word: String = readLine()!!\n val map: MutableMap = mutableMapOf()\n for (i in 0 .. nbCharacters-2) {\n val w = word.substring(i, i+2)\n map.put(w, map.getOrElse(w) {0})\n }\n\n var maxVal = -1\n var comb = \"\"\n map.forEach { k, v ->\n if (v > maxVal) {\n comb = k\n maxVal = v\n }\n }\n print(comb)\n}\n"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\n\nfun solve() {\n val n=readInt()\n val s=readLn().toCharArray()\n var m= mutableMapOf()\n for(i in 0..n-2) {\n val a=s[i].toString()+s[i+1].toString()\n m[a]=m[a]?:0+1\n }\n var maxx=0\n for(i in m){\n maxx= maxOf(i.value,maxx)\n }\n for(i in m){\n if(i.value==maxx){\n print(i.key)\n return\n }\n }\n}\n\nfun main() {\n var T=1\n// T = readInt()\n for (t in 1..T) { solve() }\n}"}, {"source_code": "import java.util.Scanner\nfun main(args: Array) {\n //creating Scanner object\n val read = Scanner(System.`in`)\n \n \n var num1 = Integer.valueOf(readLine())\n var num2 = readLine()!!\n val myMap = mutableMapOf()\n var x:Int = 1\n while(x < num1){\n var str = \"${num2.get(x-1)}${num2.get(x)}\"\n x++\n if(myMap.containsKey(str)){\n myMap.merge(str , 1 , Int::plus)\n }else{\n myMap.plus(Pair(str, 1))\n }\n }\n var fre:Int = 0\n var final_str = \"\"\n for(itr in myMap.iterator()){ \n if(itr.value > fre){\n fre = itr.value\n final_str = itr.key\n }\n }\n print(final_str)\n \n \n \n}"}, {"source_code": "import java.util.HashMap\nimport java.util.concurrent.atomic.AtomicInteger\n\n/**\n * Created by azhdanov on 07.09.2019.\n */\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\n\nfun main() {\n val n = readInt()\n val s = readLn()\n val map = HashMap()\n var maxCounts = 0;\n var twoGramma : String? = null\n for (i in 0 .. n - 2) {\n val candidate = s.subSequence(i, i + 2)\n val cnt = map.getOrDefault(candidate.toString(), AtomicInteger(0)).incrementAndGet()\n if (cnt > maxCounts) {\n maxCounts = cnt\n twoGramma = candidate.toString()\n }\n }\n if (twoGramma != null) {\n println(twoGramma)\n }\n}"}, {"source_code": " fun main(arguments: Array){\n val length = Integer.parseInt(readLine()!!);\n val string = readLine()!!;\n \n var best_index = 0;\n var best_count = 0;\n \n var i = 0;\n while(i < (length - 1)){\n var count = 1;\n val reference1 = string.get(i);\n val reference2 = string.get(i + 1);\n \n var j = i + 1;\n while(j < (length - 1)){\n val char1 = string.get(j);\n val char2 = string.get(j);\n \n if(reference1 == char1 && reference2 == char2){\n count = count + 1;\n }\n \n j = j + 1;\n }\n \n if(count > best_count){\n best_count = count;\n best_index = i;\n }\n \n i = i + 1;\n }\n \n println(string.substring(best_index, best_index + 2));\n }"}, {"source_code": "fun main() {\n val inputLen = readLine()?.toInt()\n println(readLine()?.let { input ->\n val map = mutableMapOf()\n for (i in 0 until inputLen?.dec()!!) {\n input.substring(i, i.plus(2)).let { tg ->\n println(\"i=$i and tg=$tg\")\n map[tg] = map[tg]?.inc() ?: 1\n }\n }\n map.maxBy {\n it.value\n }?.key\n })\n}"}, {"source_code": "val scan = java.util.Scanner(System.`in`)\nfun main() {\n scan.nextInt()\n var s = scan.nextLine()\n var maxTwogram = \"\"\n var maxCount = 0\n for(i in 0 until s.length-1) {\n val twogram = s.substring(i, i+2)\n var count = 0\n for (j in i until s.length-1) {\n if(s.substring(j).startsWith(twogram)) count ++\n }\n if(maxCount < count) {\n maxTwogram = twogram\n maxCount = count\n }\n }\n print(maxTwogram)\n}"}, {"source_code": "import java.util.StringTokenizer\nimport java.io.InputStreamReader\nimport java.io.BufferedReader\nimport java.io.InputStream\nimport java.util.HashMap\nimport kotlin.math.max\n\nfun main() {\n\n R.init(System.`in`)\n var n = R.nextInt()\n var s = R.next()\n val map:HashMap = HashMap();\n var ans=0\n var count=0\n for(i in 0..n-2){\n var x = s.substring(i,i+2)\n if(map.containsKey(x)){\n map.put(x,map.getValue(x)+1)\n }\n else{\n map.put(x,1);\n }\n ans = maxOf(ans,map.getValue(x))\n count++\n }\n println(ans)\n \n\n}\n\ninternal object R {\n private lateinit var reader: BufferedReader\n private lateinit var tokenizer: StringTokenizer\n fun init(input: InputStream) {\n reader = BufferedReader(InputStreamReader(input))\n tokenizer = StringTokenizer(\"\")\n }\n\n fun next(): String {\n while (!tokenizer.hasMoreTokens()) tokenizer = StringTokenizer(reader.readLine())\n return tokenizer.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextDouble() = next().toDouble()\n fun nextLong() = next().toLong();\n}"}, {"source_code": "fun twoGram(input: String) = input.windowed(2).groupingBy { it }.eachCount().maxBy { it.value }?.key\n\nfun main(args: Array) {\n if (args.size == 2) {\n val twoGram = twoGram(args[1])\n println(twoGram)\n }\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n\n var i = 0\n val h = HashMap()\n while (i <= n - 2) {\n val tg = s.take(2)\n h[tg] = (h[tg] ?: 0) + 1\n i++\n }\n var max = Int.MIN_VALUE\n var tg = \"\"\n for ((k,v) in h.entries) {\n if (v > max) {\n tg = k\n max = v\n }\n }\n println(tg)\n}"}, {"source_code": " fun main(arguments: Array){\n val length = Integer.parseInt(readLine()!!);\n val string = readLine()!!;\n \n var best_index = 0;\n var best_count = 0;\n \n var i = 0;\n while(i < (length - 1)){\n var count = 1;\n val reference1 = string.get(i);\n val reference2 = string.get(i + 1);\n \n var j = i + 1;\n while(j < (length - 1)){\n val char1 = string.get(j);\n val char2 = string.get(j);\n \n if(reference1 == char1 && reference2 == char2){\n count = count + 1;\n }\n \n j = j + 1;\n }\n \n if(count > best_count){\n best_count = count;\n best_index = i;\n }\n \n i = i + 1;\n }\n \n println(string.substring(best_index, best_index + 2));\n }"}, {"source_code": "fun main() {\n readLn()\n val s = readLn()\n val twoGrams = mutableMapOf()\n\n for (i in 0 until s.length - 1) {\n val twoGram = s.substring(i, i + 2)\n twoGrams[twoGram] = if (twoGrams.containsKey(twoGram)) (twoGrams[twoGram] ?: + 1) else 1\n }\n\n println(twoGrams.maxBy { it.value }?.key)\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val cin = Scanner(System.`in`)\n val len = cin.nextInt()\n val str = cin.next()\n\n val dict = HashMap()\n for (i in 0 until len - 2) {\n if (!dict.containsKey(str.substring(i, i + 2))) {\n dict[str.substring(i, i + 2)] = 0\n }\n dict[str.substring(i, i + 2)] = dict[str.substring(i, i + 2)]!! + 1\n }\n\n var ans = \"\"\n var topMatch = 0\n for (cur in dict) {\n if (cur.value!! > topMatch) {\n topMatch = cur.value!!\n ans = cur.key\n }\n }\n println(ans)\n}"}, {"source_code": "object programkt{\n//object TwoGram {\n @JvmStatic\n fun main(vararg args: String){\n val n = readLine()!!.toInt()\n val str = readLine()!!\n val result = exec(n, str)\n println(result)\n }\n\n fun exec(n: Int, str: String): String {\n var tg= Pair(0, \"\")\n str.forEach { f ->\n str.substring(1).forEach {s ->\n val match = \"$f$s\"\n val times = match.toRegex().findAll(str).count()\n if(times > tg.first)\n tg = Pair(times, match)\n }\n }\n return tg.second\n }\n\n}"}, {"source_code": "\nobject programkt{\n//object TwoGram {\n @JvmStatic\n fun main(vararg args: String){\n val n = readLine()!!.toInt()\n val str = readLine()!!\n val result = exec(n, str)\n println(result)\n }\n\n fun exec(n: Int, str: String): String {\n var tg= Pair(0, \"\")\n for(i in 0 until n-2){\n val match = str.substring(i, i+2)\n val times = match.toRegex().findAll(str).count()\n if(times > tg.first)\n tg = Pair(times, match)\n }\n return tg.second\n }\n\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.HashMap\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val input = scanner.nextLine().trim()\n\n var result: HashMap = HashMap()\n for(i in 0 until input.length - 2) {\n for(j in i + 1 until input.length) {\n if (input[i] == input[j]) {\n val key = String(charArrayOf(input[i], input[j]));\n var amount = result.get(key)\n if (amount == null) {\n result.put(key, value = 1)\n } else {\n result.put(key, amount + 1)\n }\n }\n }\n }\n val sorted = result.toSortedMap(compareBy { it })\n println(sorted)\n}"}, {"source_code": "fun main(args : Array) {\n val length = readLine()!!.toInt()\n val input = readLine()!!\n val twoGramMap = mutableMapOf()\n for (i in 0..length-2) {\n val twoGram = input.subSequence(i, i+2).toString()\n if (twoGramMap.containsKey(twoGram)) twoGramMap[twoGram]!!.inc() else twoGramMap[twoGram] = 1\n }\n\n println(twoGramMap.entries.maxWith(Comparator { o1, o2 -> o1.value.compareTo(o2.value) })?.key)\n}"}, {"source_code": "import java.util.*\n\n/**\n * Kotlin Heroes: Practice 2\n * B. Двуграмма\n * http://codeforces.com/contest/1212/problem/B\n * */\nclass B\n\nfun main() {\n readLine()\n val s = readLine()!!.toCharArray()\n val arr = Array(pos('Z', 'Z') + 1) { 0 }\n\n var max = 0\n var maxS = \"\"\n for (i in 1 until s.size) {\n val pos = pos(s[i - 1], s[i])\n if (++arr[pos] > max) {\n max = arr[pos]\n maxS = \"${s[i - i]}${s[i]}\"\n }\n }\n println(maxS)\n}\n\nfun pos(a: Char, b: Char) = (a - 'A') * ('Z' - 'A' + 1) + (b - 'A')\n"}, {"source_code": "fun main(args: Array) {\n readLine()\n val s = readLine()!!\n println(s.windowed(2).groupingBy { it }.eachCount().values.max()!!)\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.HashMap\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val input = scanner.nextLine().trim()\n\n var result: HashMap = HashMap()\n for(i in 0 until input.length - 1) {\n val j = i + 1\n if (input[i] == input[j]) {\n val key = String(charArrayOf(input[i], input[j]));\n var amount = result.get(key)\n if (amount == null) {\n result.put(key, value = 1)\n } else {\n result.put(key, amount + 1)\n }\n }\n }\n println(result.maxBy { it.value })\n}"}, {"source_code": "fun twoGram(input: String) {\n val result = input.windowed(2).groupingBy { it }.eachCount().maxBy { it.value }?.key\n println(result)\n}\n\nfun main(args: Array) {\n if (args.size == 2)\n twoGram(args[1])\n}"}, {"source_code": "\nobject programkt{\n//object TwoGram {\n @JvmStatic\n fun main(vararg args: String){\n val n = readLine()!!.toInt()\n val str = readLine()!!\n val result = exec(n, str)\n println(result)\n }\n\n fun exec(n: Int, str: String): String {\n var tg= Pair(0, \"\")\n for(i in 0 until n-2){\n var sss = str\n val match = str.substring(i, i+2)\n var times = 0;\n while(true){\n val find = match.toRegex().find(sss)\n if(find != null && find?.range?.first!! > -1){\n times++\n sss = sss.removeRange(0, find.range.first+1)\n }else{\n break;\n }\n }\n\n if(times > tg.first)\n tg = Pair(times, match)\n }\n return tg.second\n }\n\n}\n"}, {"source_code": "fun main() {\n readLine()\n val s = readLine()\n val mp = mutableMapOf()\n var ans = \"\"\n var mx = -1\n for (i in 1 until s!!.length) {\n val str = \"\" + s[i - 1] + s[i]\n if (str in mp) {\n mp[str]!!.plus(1)\n } else {\n mp[str] = 1\n }\n if (mp[str]!! > mx) {\n ans = str;\n mx = mp[str]!!\n }\n }\n println(ans)\n}"}, {"source_code": "fun main(args: Array) {\n val ma = mutableMapOf() \n \n val n = readLine()!!.toInt()\n val s = readLine()!!\n \n var i=0\n var ans = -1\n var sans: String = s\n while(i ans){\n \n ans = ma[ss]!! + 1\n sans = ss\n }\n ma[ss]!!.plus(1)\n }\n i++\n }\n \n println(sans)\n \n \n}"}, {"source_code": "\nobject programkt{\n//object TwoGram {\n @JvmStatic\n fun main(vararg args: String){\n val n = readLine()!!.toInt()\n val str = readLine()!!\n val result = exec(n, str)\n println(result)\n }\n\n fun exec(n: Int, str: String): String {\n var tg= Pair(0, \"\")\n for(i in 0 until n-2){\n var sss = str\n val match = str.substring(i, i+2)\n var times = 0;\n while(true){\n val find = match.toRegex().find(sss)\n if(find != null && find?.range?.first!! > -1){\n times++\n sss = sss.removeRange(0, find.range.first+1)\n }else{\n break;\n }\n }\n\n if(times > tg.first)\n tg = Pair(times, match)\n }\n return tg.second\n }\n\n}\n"}, {"source_code": "fun main() {\n readLn()\n val s = readLn()\n val twoGrams = mutableMapOf()\n\n for (i in 0 until s.length - 1) {\n val twoGram = s.substring(i, i + 2)\n twoGrams[twoGram] = if (twoGrams.containsKey(twoGram)) twoGrams[twoGram]?.plus(1)!! else 1\n }\n\n println(twoGrams)\n println(twoGrams.maxBy { it.value }?.key)\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.HashMap\n\nfun main(vararg args: String) {\n val scanner = Scanner(System.`in`)\n val length = scanner.nextInt()\n val string = scanner.next()\n println(find(length, string))\n}\n\nfun find(length: Int, string: String): String {\n val map = HashMap()\n for (i in 0 until length - 1) {\n val str = string.substring(i, i + 2)\n if (map.containsKey(str)) {\n map[str]!!.plus(1)\n } else {\n map[str] = 0\n }\n }\n return map.maxBy { it.value }!!.key\n}"}, {"source_code": "fun main() {\n readLine()\n val s = readLine()\n val mp = mutableMapOf()\n var ans = \"\"\n var mx = -1\n for (i in 1 until s!!.length) {\n val str = \"\" + s[i - 1] + s[i]\n if (str in mp) {\n mp[str]!!.plus(1)\n } else {\n mp[str] = 1\n }\n if (mp[str]!! > mx) {\n ans = str;\n mx = mp[str]!!\n }\n }\n println(ans)\n}"}, {"source_code": "\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map{it.toLong()}\n//const val MOD = 1000000007\n\nfun main(args:Array){\n val n = readInt()\n val s = readLn()\n\n val skipString = s.substring(1, s.length-1)\n\n val list = s.asSequence()\n .chunked(2).map { it.joinToString(\"\") }.toList()\n\n val skiplist = skipString.asSequence()\n .chunked(2).map { it.joinToString(\"\") }.toList()\n\n val map = mutableMapOf()\n\n countGram(list, map)\n countGram(skiplist, map)\n\n var max = -1\n var key = \"\"\n map.forEach { t, u ->\n println(\"$t $u\")\n if (u>max && t.length==2){\n max = u\n key = t\n }\n }\n println(key)\n\n}\n\nfun countGram(list: List, map: MutableMap) {\n list.forEach {\n if (map.contains(it)) {\n val count = map[it]!!\n map[it] = count + 1\n } else {\n map[it] = 1\n }\n }\n}"}, {"source_code": "\n\nimport java.util.*\n\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\n\nfun readIntArr(): MutableList {\n val l = readLine()!!.split(\" \").map { it.toInt() }\n var m : MutableList = ArrayList()\n for(x in l) m.add(x)\n return m\n}\n\nfun min(a: Int, b: Int) : Int {\n return if(ab) a else b\n}\n\nfun ispal(s: String): Boolean {\n var i = 0\n var j = s.length-1\n while(i()\n\n for(i in 0..n-3){\n val ss = s.substring(i,i+2)\n if(!m.containsKey(ss)) m.set(ss,0)\n m.computeIfPresent(ss) { _, v -> v + 1 }\n }\n\n var best = 0\n for((k,v) in m){\n if(v>best){\n best = v\n s = k\n }\n }\n\n println(s);\n}\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.HashMap\n\nfun main(vararg args: String) {\n val scanner = Scanner(System.`in`)\n val length = scanner.nextInt()\n val string = scanner.next()\n println(find(length, string))\n}\n\nfun find(length: Int, string: String): String {\n val map = HashMap()\n for (i in 0 until length - 1) {\n val str = string.substring(i, i + 2)\n if (map.containsKey(str)) {\n map[str]!!.plus(1)\n } else {\n map[str] = 0\n }\n }\n return map.maxBy { it.value }!!.key\n}"}, {"source_code": "\nobject programkt{\n//object TwoGram {\n @JvmStatic\n fun main(vararg args: String){\n val n = readLine()!!.toInt()\n val str = readLine()!!\n val result = exec(n, str)\n println(result)\n }\n\n fun exec(n: Int, str: String): String {\n var tg= Pair(0, \"\")\n for(i in 0 until n-2){\n val match = str.substring(i, i+2)\n val times = match.toRegex().findAll(str).count()\n if(times > tg.first)\n tg = Pair(times, match)\n }\n return tg.second\n }\n\n}\n"}, {"source_code": "import java.util.*\n\nfun main() {\n Scanner(System.`in`).use { scanner ->\n val stringLength = scanner.nextInt()\n val string = scanner.next()\n val twoGram = TwoGramSolver.solve(stringLength, string)\n println(\"${twoGram[0]}${twoGram[1]}\")\n }\n}\n\nprivate object TwoGramSolver {\n\n internal fun solve(stringLength: Int, string: String): Array {\n if (stringLength == 2 || stringLength == 3) {\n return arrayOf(string[0], string[1])\n }\n\n val twoGrams = mutableMapOf, Int>()\n var maxTwoGram = arrayOf(string[0], string[1])\n var maxTwoGramValue = 1\n\n for (index in 1 until stringLength - 1) {\n val twoGram = arrayOf(string[index], string[index + 1])\n\n val twoGramCount = (twoGrams[twoGram] ?: 0).inc()\n twoGrams[twoGram] = twoGramCount\n\n if (twoGramCount > maxTwoGramValue) {\n maxTwoGram = twoGram\n maxTwoGramValue = twoGramCount\n }\n }\n\n return maxTwoGram\n }\n}"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n\n val reader = Scanner(System.`in`)\n\n fun twoGram(n: Int, s: String): String {\n var mostCommonTwoGram: Pair = Pair(s.substring(0, 1), 1)\n val twoGramOccurrences = mutableMapOf()\n for (i in 0..n - 2) {\n val twoGram = s.substring(i, i + 2)\n twoGramOccurrences[twoGram] = twoGramOccurrences.getOrDefault(twoGram, 0) + 1\n if (twoGramOccurrences[twoGram] ?: 0 > mostCommonTwoGram.second) {\n mostCommonTwoGram = Pair(twoGram, twoGramOccurrences[twoGram] ?: 0)\n }\n\n }\n return mostCommonTwoGram.first\n }\n println(twoGram(reader.nextInt(), reader.next()))\n}"}, {"source_code": "\nobject programkt{\n//object TwoGram {\n @JvmStatic\n fun main(vararg args: String){\n val n = readLine()!!.toInt()\n val str = readLine()!!\n val result = exec(n, str)\n println(result)\n }\n\n fun exec(n: Int, str: String): String {\n var tg= Pair(0, \"\")\n for(i in 0 until n-2){\n var sss = str.removeRange(0, i)\n val match = str.substring(i, i+2)\n var times = 0;\n while(true){\n val find = match.toRegex().find(sss)\n if(find != null && find?.range?.first!! > -1){\n times++\n sss = sss.removeRange(0, find.range.first+1)\n }else{\n break;\n }\n }\n\n if(times >= tg.first)\n tg = Pair(times, match)\n }\n return tg.second\n }\n\n}"}, {"source_code": "\nobject programkt{\n//object TwoGram {\n @JvmStatic\n fun main(vararg args: String){\n val n = readLine()!!.toInt()\n val str = readLine()!!\n val result = exec(n, str)\n println(result)\n }\n\n fun exec(n: Int, str: String): String {\n var tg= Pair(0, \"\")\n for(i in 0 until n-2){\n var sss = str\n val match = str.substring(i, i+2)\n var times = 0;\n while(true){\n val find = match.toRegex().find(sss)\n if(find != null && find?.range?.first!! > -1){\n times++\n sss = sss.removeRange(0, find.range.first+1)\n }else{\n break;\n }\n }\n\n if(times > tg.first)\n tg = Pair(times, match)\n }\n return tg.second\n }\n\n}\n"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\n\nfun solve() {\n val n=readInt()\n val s=readLn().toCharArray()\n var m= mutableMapOf()\n for(i in 0..n-2) {\n val a=100*(s[i]).toInt()+(s[i+1]).toInt()\n m[a]=m[a]?:0+1\n }\n var maxx=0\n for(i in m){\n maxx= maxOf(i.value,maxx)\n }\n for(i in m){\n if(i.value==maxx){\n val c=(i.key%100).toChar()\n val d=(i.key/100).toChar()\n print(c)\n print(d)\n return\n }\n }\n}\n\nfun main() {\n var T=1\n// T = readInt()\n for (t in 1..T) { solve() }\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val n = readInt()\n val s = readLn()\n\n val ps = s.asSequence().zipWithNext().toList()\n\n val x = ps.sortedBy {\n if (it.first == it.second) {\n it.second\n } else {\n it.first\n }\n }\n var count = 1\n var max = 0\n var r = x[0]\n for (i in 0 until n - 2) {\n if (x[i] == x[i + 1]) {\n count++\n } else {\n max = if (max < count) {\n r = x[i]\n count\n } else {\n max\n }\n count = 1\n }\n }\n print(r.first)\n println(r.second)\n\n}\n\n\n/*\nval (n, k) = readInts()\nval li: MutableList = readInts() as MutableList\nli.sort()\nprintln(li)\nif(li[k - 1] == li[k]){\n println(-1)\n} else {\n print(li[k - 1])\n}\n*/\n"}, {"source_code": "import java.util.*\n\nfun main() {\n val input = readLine()\n \n if (input == null) {\n return\n }\n \n val map = mutableMapOf, Int>() \n\n input.zipWithNext().forEach {\n if (map.get(it) == null) {\n map.put(it, 1)\n } else {\n map.put(it, map.get(it)!! + 1)\n }\n }\n \n var maxPair: Pair? = null\n var maxCount = 0\n \n for ((pair, count) in map) {\n if (count > maxCount) {\n maxPair = pair\n maxCount = count\n }\n }\n \n if (maxPair == null) {\n return\n }\n \n print(maxPair.component1())\n print(maxPair.component2())\n}"}, {"source_code": "\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\n\nfun main() {\n var n = readInt()\n var s = readLn()\n var m = HashMap()\n\n for (i in 0..s.length-2) {\n var str = s[i].toString() + s[i + 1]\n if (m.containsKey(str))\n m[str] = m[str]!! + 1\n else\n m[str] = 0\n }\n var mx = Pair(\"\", 0)\n for ((k,v) in m) {\n if (mx.second < v) {\n mx = Pair(k,v)\n }\n }\n print(mx.first)\n}"}, {"source_code": "import java.util.regex.Pattern\n\nfun main(args: Array) {\n val ss = twogram1()\n print(ss?.first)\n}\n\nfun twogram1(): Pair?{\n val n = readLine()?.toInt() ?: 0\n val s = readLine().orEmpty()\n val chars = s.toList()\n if(chars.size == n && chars.size > 1) {\n val allPairs = chars.map { c ->\n chars.map {\n \"$it\" + \"$c\"\n }.distinct()\n }.flatten().distinct()\n val m = allPairs.map {\n val pattern = Pattern.compile(it) //case insensitive, use [g] for only lower\n val matcher = pattern.matcher(s)\n var count = 0\n while (matcher.find()) count++\n it to count\n }.maxBy { it.second }\n return m\n }else return s to 0\n}\n\n"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val value = scanner.nextInt()\n if (value in 2..100) {\n val text = scanner.next()\n if (text.length != value) {\n print(\"wrong\")\n } else {\n var maxi = 0\n var gram = \"\"\n repeat(text.length - 1) { _times ->\n val sub = text.substring(_times, _times + 2)\n val temp = calll(sub, text)\n if (temp > maxi) {\n maxi = temp\n println(\"sonuc : $maxi\")\n gram = sub\n }\n }\n println(gram)\n }\n } else {\n print(\"Wrong\")\n }\n}\n\nfun calll(sub: String, value: String): Int {\n var cnt = 0\n repeat(value.length - 1) { k ->\n if (value[k] == sub[0] && value[k + 1] == sub[1])\n cnt++\n }\n return cnt\n}"}, {"source_code": "fun main(args:Array){\n\tvar str = readLine()!!;\n var tm = mutableMapOf(); \n for(i in 0..str.length-2){\n var tc = str[i].toString() + str[i+1].toString();\n tm[tc]=tm.getOrDefault(tc,0)+1;\n }\n var r = tm.maxBy({it.value});\n println(r?.key)\n}"}, {"source_code": "\n\nimport java.util.*\n\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\n\nfun readIntArr(): MutableList {\n val l = readLine()!!.split(\" \").map { it.toInt() }\n var m : MutableList = ArrayList()\n for(x in l) m.add(x)\n return m\n}\n\nfun min(a: Int, b: Int) : Int {\n return if(ab) a else b\n}\n\nfun ispal(s: String): Boolean {\n var i = 0\n var j = s.length-1\n while(i()\n\n for(i in 0..n-3){\n val ss = s.substring(i,i+2)\n if(!m.containsKey(ss)) m.set(ss,0)\n m.computeIfPresent(ss) { _, v -> v + 1 }\n }\n\n var best = 0\n for((k,v) in m){\n if(v>best){\n best = v\n s = k\n }\n }\n\n println(s);\n}\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "fun main(args:Array){\n\tvar str = readLine()!!;\n var tm = mutableMapOf(); \n for(i in 0..str.length-2){\n var tc = str[i].toString() + str[i+1].toString();\n tm[tc]=tm.getOrDefault(tc,0)+1;\n }\n var r = tm.maxBy({it.value});\n println(r?.key)\n}"}, {"source_code": "fun main(args : Array) {\n var n = readLine()!!.toInt()\n var str = readLine()!!\n println(str.substring(0..1))\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n val string = readLine()!!\n val grams = ArrayList(n)\n for (i in 0 until n - 1) {\n grams.add(string.substring(i..i + 1))\n }\n print(grams.maxBy { grams.count { grams.contains(it) } })\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val n = readInt()\n val s = readLn()\n\n val ps = s.asSequence().zipWithNext().toList()\n\n val x = ps.sortedBy {\n if (it.first == it.second) {\n it.second\n } else {\n it.first\n }\n }\n var count = 1\n var max = 0\n var r = x[0]\n for (i in 0 until n - 2) {\n if (x[i] == x[i + 1]) {\n count++\n } else {\n max = if (max < count) {\n r = x[i]\n count\n } else {\n max\n }\n count = 1\n }\n }\n print(r.first)\n println(r.second)\n\n}\n\n\n/*\nval (n, k) = readInts()\nval li: MutableList = readInts() as MutableList\nli.sort()\nprintln(li)\nif(li[k - 1] == li[k]){\n println(-1)\n} else {\n print(li[k - 1])\n}\n*/\n"}, {"source_code": "fun main(args:Array){\n\tvar str = readLine()!!;\n var tm = mutableMapOf(); \n for(i in 0..str.length-2){\n var tc = str[i].toString() + str[i+1].toString();\n tm[tc]=tm.getOrDefault(tc,0)+1;\n }\n var r = tm.maxBy({it.value});\n println(r?.key)\n}"}, {"source_code": "import java.util.regex.Pattern\n\nfun main(args: Array) {\n twogram()\n}\n\nfun twogram(): Pair?{\n val n = readLine()?.toInt() ?: 0\n val s = readLine().orEmpty()\n val chars = s.toList()\n if(chars.size == n) {\n val allPairs = chars.map { c ->\n chars.map {\n \"$it\" + \"$c\"\n }.distinct()\n }.flatten().distinct()\n val m = allPairs.map {\n val pattern = Pattern.compile(it) //case insensitive, use [g] for only lower\n val matcher = pattern.matcher(s)\n var count = 0\n while (matcher.find()) count++\n it to count\n }.maxBy { it.second }\n return m\n }else return \"\" to 0\n}\n\n"}, {"source_code": "fun main() {\n val l = readLine()!!.toInt()\n val s = readLine()!!\n\n val r :HashMap = hashMapOf()\n\n for (i in 0 until l - 1) {\n val x = s.substring(i, i + 2)\n if (r.containsKey(x)) {\n r[x] = r[x]!!.plus(1)\n } else {\n r[x] = 0\n }\n }\n\n val z = -1\n var y = \"\"\n for (j in r) {\n if (j.value > z) {\n y = j.key\n }\n }\n println(y)\n}"}, {"source_code": "fun main() {\n val l = readLine()!!.toInt()\n val s = readLine()!!\n\n val r :HashMap = hashMapOf()\n\n for (i in 0 until l - 1) {\n val x = s.substring(i, i + 2)\n if (r.containsKey(x)) {\n r[x] = r[x]!!.plus(1)\n } else {\n r[x] = 0\n }\n }\n\n val z = -1\n var y = \"\"\n for (j in r) {\n if (j.value > z) {\n y = j.key\n }\n }\n println(y)\n}"}, {"source_code": "import java.util.regex.Pattern\n\nfun main(args: Array) {\n twogram()\n}\n\nfun twogram(): Pair?{\n val n = readLine()?.toInt() ?: 0\n val s = readLine().orEmpty()\n val chars = s.toList()\n if(chars.size == n) {\n val allPairs = chars.map { c ->\n chars.map {\n \"$it\" + \"$c\"\n }.distinct()\n }.flatten().distinct()\n val m = allPairs.map {\n val pattern = Pattern.compile(it) //case insensitive, use [g] for only lower\n val matcher = pattern.matcher(s)\n var count = 0\n while (matcher.find()) count++\n it to count\n }.maxBy { it.second }\n return m\n }else return \"\" to 0\n}\n\n"}, {"source_code": "\nimport java.util.*\nimport kotlin.collections.ArrayList\n\nfun main() {\n val input = Scanner(System.`in`)\n val n = input.nextInt()\n val s = input.next()\n\n val letters = s.split(\"\")\n val iSize = letters.size - 2\n val dGrams: ArrayList = ArrayList()\n for (i in 0..iSize) {\n dGrams.add(\"${letters[i]}${letters[i + 1]}\")\n }\n\n var mGram = Int.MIN_VALUE\n var mIndex = 0\n val count: ArrayList> = ArrayList()\n for (i in dGrams) {\n var exists = false\n var gIndex = 0\n count.forEachIndexed { index, pair ->\n if (pair.first == i) {\n exists = true\n gIndex = index\n return@forEachIndexed\n }\n }\n if (!exists) {\n count.add(Pair(i, 1))\n } else {\n val num = count[gIndex].second + 1\n count[gIndex] = Pair(i, num)\n if (num > mGram) {\n mGram = num\n mIndex = gIndex\n }\n }\n }\n\n print(count[mIndex].first)\n}\n"}, {"source_code": "fun main() {\n val inputLen = readLine()?.toInt()\n println(readLine()?.let { input ->\n val map = mutableMapOf()\n for (i in 0 until inputLen?.dec()!!) {\n input.substring(i, i.plus(2)).let { tg ->\n println(\"i=$i and tg=$tg\")\n map[tg] = map[tg]?.inc() ?: 1\n }\n }\n map.maxBy {\n it.value\n }?.key\n })\n}"}, {"source_code": "\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map{it.toLong()}\n//const val MOD = 1000000007\n\nfun main(args:Array){\n val n = readInt()\n val s = readLn()\n\n val skipString = s.substring(1, s.length-1)\n\n val list = s.asSequence()\n .chunked(2).map { it.joinToString(\"\") }.toList()\n\n val skiplist = skipString.asSequence()\n .chunked(2).map { it.joinToString(\"\") }.toList()\n\n val map = mutableMapOf()\n\n countGram(list, map)\n countGram(skiplist, map)\n\n var max = -1\n var key = \"\"\n map.forEach { t, u ->\n println(\"$t $u\")\n if (u>max && t.length==2){\n max = u\n key = t\n }\n }\n println(key)\n\n}\n\nfun countGram(list: List, map: MutableMap) {\n list.forEach {\n if (map.contains(it)) {\n val count = map[it]!!\n map[it] = count + 1\n } else {\n map[it] = 1\n }\n }\n}"}, {"source_code": "import java.util.Scanner\nfun main(args: Array) {\n //creating Scanner object\n val read = Scanner(System.`in`)\n \n \n var num1 = Integer.valueOf(readLine())\n var num2 = readLine()!!\n val myMap = mutableMapOf()\n var x:Int = 1\n while(x < num1){\n var str = \"${num2.get(x-1)}${num2.get(x)}\"\n x++\n if(myMap.containsKey(str)){\n myMap.merge(str , 1 , Int::plus)\n }else{\n myMap.plus(Pair(str, 1))\n }\n }\n var fre:Int = 0\n var final_str = \"\"\n for(itr in myMap.iterator()){ \n if(itr.value > fre){\n fre = itr.value\n final_str = itr.key\n }\n }\n print(final_str)\n \n \n \n}"}, {"source_code": "fun twoGram(input: String) {\n val result = input.windowed(2).groupingBy { it }.eachCount().maxBy { it.value }?.key\n println(result)\n}\n\nfun main(args: Array) {\n// if (args.size == 2)\n// twoGram(args[1])\n print(\"AB\")\n}"}, {"source_code": "fun main() {\n readLine()\n val s = readLine()\n val mp = mutableMapOf()\n var ans = \"\"\n var mx = -1\n for (i in 1 until s!!.length) {\n val str = \"\" + s[i - 1] + s[i]\n if (str in mp) {\n mp[str]!!.plus(1)\n } else {\n mp[str] = 1\n }\n if (mp[str]!! > mx) {\n ans = str;\n mx = mp[str]!!\n }\n }\n println(ans)\n}"}, {"source_code": "object programkt{\n//object TwoGram {\n @JvmStatic\n fun main(vararg args: String){\n val n = readLine()!!.toInt()\n val str = readLine()!!\n val result = exec(n, str)\n println(result)\n }\n\n fun exec(n: Int, str: String): String {\n var tg= Pair(0, \"\")\n str.forEach { f ->\n str.substring(1).forEach {s ->\n val match = \"$f$s\"\n val times = match.toRegex().findAll(str).count()\n if(times > tg.first)\n tg = Pair(times, match)\n }\n }\n return tg.second\n }\n\n}"}, {"source_code": "import java.util.Scanner\n\n/*\n\tScanner scanner_variable = Scanner(System.`in`)\n\t//Reading Int input\n\tscanner_variable.nextInt()\n\t//Reading Float Input\n\tscanner_variable.nextFloat()\n\t//Reading Double Input\n\tscanner_variable.nextDouble()\n\t//Reading Boolean Input\n\tscanner_variable.nextBoolean()\n\t//Reading Short Input\n\tscanner_variable.nextShort()\n\t//Reading Long Input\n\tscanner_variable.nextLong()\n\t//Reading String Input\n\tscanner_variable.nextLine()\n\n\ttoChar() – To convert a type to Char type.\n\ttoInt() – To convert a type to Int type.\n\ttoLong() – To convert a type to Long type.\n\ttoFloat() – To convert a type to Float type.\n\ttoDouble() – To convert a type to Double type.\n\ttoByte() – To convert a type to Byte type.\n\ttoShort() – To convert a type to Short type.\n\n\tval parts = str.split(\" \")\n\n\tfun meAjuda(L: List) {\n\t\tfor(s in L)\n\t\t\tprintln(s)\n\t}\t\n*/\n\nfun main() {\n\tval n = readLine()\n\tval str = readLine().toString()\n\n\tvar cur = -1\n\tvar ans = \"AA\"\n\n\tfor(a in 'A'..'Z') {\n\t\tfor(b in a..'Z') {\n\t\t\tvar s = a.toString() + b.toString()\n\t\t\tvar par = 0\n\t\t\tfor(i in 1..(str.length-1))\n\t\t\t\tif(s == str.get(i - 1).toString() + str.get(i).toString())\n\t\t\t\t\tpar++\n\t\t\tif(par > cur) {\n\t\t\t\tans = s\n\t\t\t\tcur = par\n\t\t\t}\n\t\t}\n\t}\n\tprintln(ans)\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val input = Scanner(System.`in`)\n\n// val n = input.nextLine().toInt()\n val s = input.nextLine().toString()\n var max = 0\n var sequence = \"\"\n\n s.windowed(2,1, false) { toTest ->\n var count = 0\n s.windowed(2,1, false) { toMatch ->\n if (toTest == toMatch) {\n count ++\n }\n if (count>max) {\n max = count\n sequence = toTest.toString()\n }\n }\n }\n\n println(sequence)\n}"}, {"source_code": "\nobject programkt{\n//object TwoGram {\n @JvmStatic\n fun main(vararg args: String){\n val n = readLine()!!.toInt()\n val str = readLine()!!\n val result = exec(n, str)\n println(result)\n }\n\n fun exec(n: Int, str: String): String {\n var tg= Pair(0, \"\")\n for(i in 0 until n-2){\n var sss = str\n val match = str.substring(i, i+2)\n var times = 0;\n while(true){\n val find = match.toRegex().find(sss)\n if(find != null && find?.range?.first!! > -1){\n times++\n sss = sss.removeRange(0, find.range.first+1)\n }else{\n break;\n }\n }\n\n if(times > tg.first)\n tg = Pair(times, match)\n }\n return tg.second\n }\n\n}\n"}, {"source_code": "fun main(args: Array) {\n val ma = mutableMapOf() \n \n val n = readLine()!!.toInt()\n val s = readLine()!!\n \n var i=0\n var ans = -1\n var sans: String = s\n while(i ans){\n \n ans = ma[ss]!! + 1\n sans = ss\n }\n ma[ss]!!.plus(1)\n }\n i++\n }\n \n println(sans)\n \n \n}"}, {"source_code": "fun main() {\n val inputLen = readLine()?.toInt()\n println(readLine()?.let { input ->\n val map = mutableMapOf()\n for (i in 0 until inputLen?.dec()!!) {\n input.substring(i, i.plus(2)).let { tg ->\n println(\"i=$i and tg=$tg\")\n map[tg] = map[tg]?.inc() ?: 1\n }\n }\n map.maxBy {\n it.value\n }?.key\n })\n}"}, {"source_code": "fun main() {\n readLn()\n val s = readLn()\n val twoGrams = mutableMapOf()\n\n for (i in 0 until s.length - 1) {\n val twoGram = s.substring(i, i + 2)\n twoGrams[twoGram] = if (twoGrams.containsKey(twoGram)) (twoGrams[twoGram] ?: + 1) else 1\n }\n\n println(twoGrams.maxBy { it.value }?.key)\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\n"}, {"source_code": "val scan = java.util.Scanner(System.`in`)\nfun main() {\n scan.nextInt()\n var s = scan.nextLine()\n var maxTwogram = \"\"\n var maxCount = 0\n for(i in 0 until s.length-1) {\n val twogram = s.substring(i, i+2)\n var count = 0\n for (j in i until s.length-1) {\n if(s.substring(j).startsWith(twogram)) count ++\n }\n if(maxCount < count) {\n maxTwogram = twogram\n maxCount = count\n }\n }\n print(maxTwogram)\n}"}, {"source_code": "import java.util.Scanner\n\n/*\n\tScanner scanner_variable = Scanner(System.`in`)\n\t//Reading Int input\n\tscanner_variable.nextInt()\n\t//Reading Float Input\n\tscanner_variable.nextFloat()\n\t//Reading Double Input\n\tscanner_variable.nextDouble()\n\t//Reading Boolean Input\n\tscanner_variable.nextBoolean()\n\t//Reading Short Input\n\tscanner_variable.nextShort()\n\t//Reading Long Input\n\tscanner_variable.nextLong()\n\t//Reading String Input\n\tscanner_variable.nextLine()\n\n\ttoChar() – To convert a type to Char type.\n\ttoInt() – To convert a type to Int type.\n\ttoLong() – To convert a type to Long type.\n\ttoFloat() – To convert a type to Float type.\n\ttoDouble() – To convert a type to Double type.\n\ttoByte() – To convert a type to Byte type.\n\ttoShort() – To convert a type to Short type.\n\n\tval parts = str.split(\" \")\n\n\tfun meAjuda(L: List) {\n\t\tfor(s in L)\n\t\t\tprintln(s)\n\t}\t\n*/\n\nfun main() {\n\tval n = readLine()\n\tval str = readLine().toString()\n\n\tvar cur = -1\n\tvar ans = \"AA\"\n\n\tfor(a in 'A'..'Z') {\n\t\tfor(b in a..'Z') {\n\t\t\tvar s = a.toString() + b.toString()\n\t\t\tvar par = 0\n\t\t\tfor(i in 1..(str.length-1))\n\t\t\t\tif(s == str.get(i - 1).toString() + str.get(i).toString())\n\t\t\t\t\tpar++\n\t\t\tif(par > cur) {\n\t\t\t\tans = s\n\t\t\t\tcur = par\n\t\t\t}\n\t\t}\n\t}\n\tprintln(ans)\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val n = readInt()\n val s = readLn()\n\n val ps = s.asSequence().zipWithNext().toList()\n\n var max = 0\n var count = 1\n var r = ps[0]\n for(i in 0 until n - 2){\n if(ps[i] == ps[i + 1]){\n count++\n } else {\n max = if(max < count) {\n r = ps[i]\n count\n } else {\n max\n }\n count = 1\n }\n }\n print(\"${r.first}${r.second}\")\n \n\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n Scanner(System.`in`).use { scanner ->\n val stringLength = scanner.nextInt()\n val string = scanner.next()\n println(TwoGramSolver.solve(stringLength, string))\n }\n}\n\nprivate object TwoGramSolver {\n\n internal fun solve(stringLength: Int, string: String): String {\n val twoGrams = mutableMapOf()\n var maxTwoGram: Pair? = null\n\n for (index in 0 until stringLength - 1) {\n val twoGramStringBuilder = StringBuffer(2)\n twoGramStringBuilder.append(string[index])\n twoGramStringBuilder.append(string[index + 1])\n val twoGram = twoGramStringBuilder.toString()\n\n val twoGramCount = (twoGrams[twoGram] ?: 0).inc()\n twoGrams[twoGram] = twoGramCount\n\n if (maxTwoGram == null) {\n maxTwoGram = twoGram to twoGramCount\n break\n }\n\n if (twoGramCount > maxTwoGram.second) {\n maxTwoGram = twoGram to twoGramCount\n }\n }\n\n return maxTwoGram!!.first\n }\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.HashMap\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val input = scanner.nextLine().trim()\n\n var result: HashMap = HashMap()\n for(i in 0 until input.length - 1) {\n val j = i + 1\n if (input[i] == input[j]) {\n val key = String(charArrayOf(input[i], input[j]));\n var amount = result.get(key)\n if (amount == null) {\n result.put(key, value = 1)\n } else {\n result.put(key, amount + 1)\n }\n }\n }\n println(result.maxBy { it.value })\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val cin = Scanner(System.`in`)\n val len = cin.nextInt()\n val str = cin.next()\n\n val dict = HashMap()\n for (i in 0 until len - 2) {\n if (!dict.containsKey(str.substring(i, i + 2))) {\n dict[str.substring(i, i + 2)] = 0\n }\n dict[str.substring(i, i + 2)] = dict[str.substring(i, i + 2)]!! + 1\n }\n\n var ans = \"\"\n var topMatch = 0\n for (cur in dict) {\n if (cur.value!! > topMatch) {\n topMatch = cur.value!!\n ans = cur.key\n }\n }\n println(ans)\n}"}, {"source_code": "fun main(args: Array) {\n\n // reading the input and saving it\n val amountOfLetters = readLine()!!.toInt()\n val inputString = readLine()!!\n\n // the var will be the temporary string containing the two-gram to be checked while traversing through\n // the input String\n var tempString: String\n\n // the hashmap will contain the two-gram string along with the occurences\n // it will be initialied with the first two-gram and its counter value of 1\n var counterHashMap: MutableMap = mutableMapOf(inputString.subSequence(0,2).toString() to 1)\n\n // iterating over the string, saving each two-gram in a temporary string\n // checking if the two-gram exists in the hashmap\n // yes: increase the value, no: adding the two-gram to the hasmap and initializing the value to 1\n for((index,character) in inputString.withIndex()) {\n // to avoid the indexOutOfBounce exception, the index is being checked\n if(index == inputString.length-1) break\n // skip the first 2 letters as they have been added in the initialisation\n if(index == 0) continue;\n\n // concatenating two chars\n tempString = \"\" + character + inputString[index+1]\n println(tempString)\n // check if the two-gram is in the haspMap\n if(tempString in counterHashMap) {\n // increase the value if it does\n counterHashMap.set(tempString, counterHashMap.get(tempString)!!.plus(1))\n } else {\n // add the value to hashmap if it doesnt with value 1\n counterHashMap.put(tempString,1)\n }\n }\n println(counterHashMap.maxBy{it.value}.toString().subSequence(0,2))\n}"}, {"source_code": "import kotlin.io.*\n\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\n\nfun main() {\n var n = readInt()\n var str = readStrings()[0]\n\n var m = mutableMapOf()\n var setted = false\n var best = String()\n for(i in 0..str.length-2) {\n var s = str[i].toString()+str[i+1].toString();\n if(m.containsKey(s)) {\n m[s] = m[s]!!+1\n if(setted) {\n if(m[s]!!>m[best]!!) {\n best=s\n }\n }else {\n best=s\n }\n }else {\n m[s]=1\n }\n }\n\n println(\"$best\")\n}"}, {"source_code": "object programkt{\n//object TwoGram {\n @JvmStatic\n fun main(vararg args: String){\n val n = readLine()!!.toInt()\n val str = readLine()!!\n val result = exec(n, str)\n println(result)\n }\n\n fun exec(n: Int, str: String): String {\n var tg= Pair(0, \"\")\n str.forEach { f ->\n str.substring(1).forEach {s ->\n val match = \"$f$s\"\n val times = match.toRegex().findAll(str).count()\n if(times > tg.first)\n tg = Pair(times, match)\n }\n }\n return tg.second\n }\n\n}"}, {"source_code": "\nobject programkt{\n//object TwoGram {\n @JvmStatic\n fun main(vararg args: String){\n val n = readLine()!!.toInt()\n val str = readLine()!!\n val result = exec(n, str)\n println(result)\n }\n\n fun exec(n: Int, str: String): String {\n var tg= Pair(0, \"\")\n for(i in 0 until n-2){\n var sss = str\n val match = str.substring(i, i+2)\n var times = 0;\n while(true){\n val find = match.toRegex().find(sss)\n if(find != null && find?.range?.first!! > -1){\n times++\n sss = sss.removeRange(0, find.range.first+1)\n }else{\n break;\n }\n }\n\n if(times > tg.first)\n tg = Pair(times, match)\n }\n return tg.second\n }\n\n}\n"}, {"source_code": "private fun f(str: String): String {\n val counts = (0..str.length - 2).fold(mutableMapOf()) { collector, i ->\n val twoGram = str.subSequence(i, i + 2)\n collector[twoGram] = collector.getOrDefault(twoGram, 0) + 1\n collector\n }\n return counts.maxBy { it.value }?.key.toString()\n}\n\nfun main() {\n val str = readLn()\n println(f(str))\n}\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints"}, {"source_code": "import java.util.*\n\nfun main() {\n Scanner(System.`in`).use { scanner ->\n val stringLength = scanner.nextInt()\n val string = scanner.next()\n val twoGram = TwoGramSolver.solve(stringLength, string)\n println(\"${twoGram[0]}${twoGram[1]}\")\n }\n}\n\nprivate object TwoGramSolver {\n\n internal fun solve(stringLength: Int, string: String): Array {\n if (stringLength == 2 || stringLength == 3) {\n return arrayOf(string[0], string[1])\n }\n\n val twoGrams = mutableMapOf, Int>()\n var maxTwoGram = arrayOf(string[0], string[1])\n var maxTwoGramValue = 1\n\n for (index in 1 until stringLength - 1) {\n val twoGram = arrayOf(string[index], string[index + 1])\n\n val twoGramCount = (twoGrams[twoGram] ?: 0).inc()\n twoGrams[twoGram] = twoGramCount\n\n if (twoGramCount > maxTwoGramValue) {\n maxTwoGram = twoGram\n maxTwoGramValue = twoGramCount\n }\n }\n\n return maxTwoGram\n }\n}"}, {"source_code": "\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\n\nfun main() {\n var n = readInt()\n var s = readLn()\n var m = HashMap()\n\n for (i in 0..s.length-2) {\n var str = s[i].toString() + s[i + 1]\n if (m.containsKey(str))\n m[str] = m[str]!! + 1\n else\n m[str] = 0\n }\n var mx = Pair(\"\", 0)\n for ((k,v) in m) {\n if (mx.second < v) {\n mx = Pair(k,v)\n }\n }\n print(mx.first)\n}"}, {"source_code": "\nfun main(args: Array) {\n val nbCharacters: Int = readLine()!!.toInt()\n val word: String = readLine()!!\n val map: MutableMap = mutableMapOf()\n for (i in 0 .. nbCharacters-2) {\n val w = word.substring(i, i+2)\n map.put(w, map.getOrElse(w) {0})\n }\n\n var maxVal = -1\n var comb = \"\"\n map.forEach { k, v ->\n if (v > maxVal) {\n comb = k\n maxVal = v\n }\n }\n print(comb)\n}\n"}, {"source_code": "fun main() {\n val l = readLine()!!.toInt()\n val s = readLine()!!\n\n val r :HashMap = hashMapOf()\n\n for (i in 0 until l - 1) {\n val x = s.substring(i, i + 2)\n if (r.containsKey(x)) {\n r[x] = r[x]!!.plus(1)\n } else {\n r[x] = 0\n }\n }\n\n val z = 0\n var y = \"\"\n for (j in r) {\n if (j.value > z) {\n y = j.key\n }\n }\n println(y)\n}"}, {"source_code": "import java.util.regex.Pattern\n\nfun main(args: Array) {\n twogram()\n}\n\nfun twogram(): Pair?{\n val n = readLine()?.toInt() ?: 0\n val s = readLine().orEmpty()\n val chars = s.toList()\n if(chars.size == n) {\n val allPairs = chars.map { c ->\n chars.map {\n \"$it\" + \"$c\"\n }.distinct()\n }.flatten().distinct()\n val m = allPairs.map {\n val pattern = Pattern.compile(it) //case insensitive, use [g] for only lower\n val matcher = pattern.matcher(s)\n var count = 0\n while (matcher.find()) count++\n it to count\n }.maxBy { it.second }\n return m\n }else return \"\" to 0\n}\n\n"}, {"source_code": "import java.util.Scanner\nfun main(args: Array) {\n //creating Scanner object\n val read = Scanner(System.`in`)\n \n \n var num1 = Integer.valueOf(readLine())\n var num2 = readLine()!!\n val myMap = mutableMapOf()\n var x:Int = 1\n while(x < num1){\n var str = \"${num2.get(x-1)}${num2.get(x)}\"\n x++\n if(myMap.containsKey(str)){\n myMap.merge(str , 1 , Int::plus)\n }else{\n myMap.plus(Pair(str, 1))\n }\n }\n var fre:Int = 0\n var final_str = \"\"\n for(itr in myMap.iterator()){ \n if(itr.value > fre){\n fre = itr.value\n final_str = itr.key\n }\n }\n print(final_str)\n \n \n \n}"}, {"source_code": "fun main() {\n val num = readLine()!!.toInt()\n val str = readLine()!!.take(num)\n println(bigramCountMax(str))\n}\n\nfun bigramCountMax(str: String): String {\n var maxCount = 0\n var leadSubstring = str.take(2)\n val leadChar = str[0]\n for ((index, value) in str.substring(1).withIndex()) {\n var count = 0\n if (leadChar == value) {\n count = countSubstring(leadChar + value.toString(), str)\n } else {\n count = countSubstring(leadChar + value.toString(), str) + countSubstring(value.toString() + leadChar, str)\n }\n if(count > maxCount) {\n maxCount = count\n leadSubstring = leadChar + value.toString()\n }\n }\n return leadSubstring\n}\n\nfun countSubstring(s: String, sub: String): Int = s.split(sub).size - 1"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\n\nfun solve() {\n val n=readInt()\n val s=readLn().toCharArray()\n var m= mutableMapOf()\n for(i in 0..n-2) {\n val a=100*(s[i]).toInt()+(s[i+1]).toInt()\n m[a]=m[a]?:0+1\n }\n var maxx=0\n for(i in m){\n maxx= maxOf(i.value,maxx)\n }\n for(i in m){\n if(i.value==maxx){\n val c=(i.key%100).toChar()\n val d=(i.key/100).toChar()\n print(c)\n print(d)\n return\n }\n }\n}\n\nfun main() {\n var T=1\n// T = readInt()\n for (t in 1..T) { solve() }\n}"}, {"source_code": "\nobject programkt{\n//object TwoGram {\n @JvmStatic\n fun main(vararg args: String){\n val n = readLine()!!.toInt()\n val str = readLine()!!\n val result = exec(n, str)\n println(result)\n }\n\n fun exec(n: Int, str: String): String {\n var tg= Pair(0, \"\")\n for(i in 0 until n-2){\n var sss = str\n val match = str.substring(i, i+2)\n var times = 0;\n while(true){\n val find = match.toRegex().find(sss)\n if(find != null && find?.range?.first!! > -1){\n times++\n sss = sss.removeRange(0, find.range.first+1)\n }else{\n break;\n }\n }\n\n if(times >= tg.first)\n tg = Pair(times, match)\n }\n return tg.second\n }\n\n}\n"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val n = readInt()\n val s = readLn()\n\n val ps = s.asSequence().zipWithNext().toList()\n\n val x = ps.sortedBy {\n if (it.first == it.second) {\n it.second\n } else {\n it.first\n }\n }\n var count = 1\n var max = 0\n var r = x[0]\n for (i in 0 until n - 2) {\n if (x[i] == x[i + 1]) {\n count++\n } else {\n max = if (max < count) {\n r = x[i]\n count\n } else {\n max\n }\n count = 1\n }\n }\n print(r.first)\n println(r.second)\n\n}\n\n\n/*\nval (n, k) = readInts()\nval li: MutableList = readInts() as MutableList\nli.sort()\nprintln(li)\nif(li[k - 1] == li[k]){\n println(-1)\n} else {\n print(li[k - 1])\n}\n*/\n"}, {"source_code": "fun main() {\n readLn()\n val s = readLn()\n val twoGrams = mutableMapOf()\n\n for (i in 0 until s.length - 1) {\n val twoGram = s.substring(i, i + 2)\n twoGrams[twoGram] = if (twoGrams.containsKey(twoGram)) (twoGrams[twoGram] ?: + 1) else 1\n }\n\n println(twoGrams.maxBy { it.value }?.key)\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.HashMap\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val input = scanner.nextLine().trim()\n\n var result: HashMap = HashMap()\n for(i in 0 until input.length - 1) {\n val j = i + 1\n val key = String(charArrayOf(input[i], input[j]));\n var amount = result.get(key)\n if (amount == null) {\n result.put(key, value = 1)\n } else {\n result.put(key, amount + 1)\n }\n }\n println(result.maxBy { it.value })\n}"}], "src_uid": "e78005d4be93dbaa518f3b40cca84ab1"} {"nl": {"description": "In Pavlopolis University where Noora studies it was decided to hold beauty contest \"Miss Pavlopolis University\". Let's describe the process of choosing the most beautiful girl in the university in more detail.The contest is held in several stages. Suppose that exactly n girls participate in the competition initially. All the participants are divided into equal groups, x participants in each group. Furthermore the number x is chosen arbitrarily, i. e. on every stage number x can be different. Within each group the jury of the contest compares beauty of the girls in the format \"each with each\". In this way, if group consists of x girls, then comparisons occur. Then, from each group, the most beautiful participant is selected. Selected girls enter the next stage of the competition. Thus if n girls were divided into groups, x participants in each group, then exactly participants will enter the next stage. The contest continues until there is exactly one girl left who will be \"Miss Pavlopolis University\"But for the jury this contest is a very tedious task. They would like to divide the girls into groups in each stage so that the total number of pairwise comparisons of the girls is as few as possible. Let f(n) be the minimal total number of comparisons that should be made to select the most beautiful participant, if we admit n girls to the first stage.The organizers of the competition are insane. They give Noora three integers t, l and r and ask the poor girl to calculate the value of the following expression: t0·f(l) + t1·f(l + 1) + ... + tr - l·f(r). However, since the value of this expression can be quite large the organizers ask her to calculate it modulo 109 + 7. If Noora can calculate the value of this expression the organizers promise her to help during the beauty contest. But the poor girl is not strong in mathematics, so she turned for help to Leha and he turned to you.", "input_spec": "The first and single line contains three integers t, l and r (1 ≤ t < 109 + 7, 2 ≤ l ≤ r ≤ 5·106).", "output_spec": "In the first line print single integer — the value of the expression modulo 109 + 7.", "sample_inputs": ["2 2 4"], "sample_outputs": ["19"], "notes": "NoteConsider the sample.It is necessary to find the value of .f(2) = 1. From two girls you can form only one group of two people, in which there will be one comparison.f(3) = 3. From three girls you can form only one group of three people, in which there will be three comparisons.f(4) = 3. From four girls you can form two groups of two girls each. Then at the first stage there will be two comparisons, one in each of the two groups. In the second stage there will be two girls and there will be one comparison between them. Total 2 + 1 = 3 comparisons. You can also leave all girls in same group in the first stage. Then comparisons will occur. Obviously, it's better to split girls into groups in the first way.Then the value of the expression is ."}, "positive_code": [{"source_code": "import java.io.InputStream\n\nprivate val MOD = 1e9.toInt() + 7\n\nprivate val input = FastScanner()\n\nfun main(args: Array) = input.run {\n withMod(MOD) {\n val t = nextInt()\n val l = nextInt()\n val r = nextInt()\n val f = IntArray(r + 1) { (it * (it - 1L) / 2).mod() }\n\n val p = PrimeSieve(r)\n\n f[1] = 0\n\n (2..r).forEach { n ->\n val x = p.getMinDivisor(n)\n val m = n / x\n f[n] = (n * (x - 1).toLong() / 2).mod() madd f[m]\n }\n\n var ans = 0\n var tt = 1\n (l..r).forEach {\n ans = ans madd (tt mmul f[it])\n tt = tt mmul t\n }\n\n println(ans)\n }\n}\n\nclass FastScanner(private val input: InputStream = System.`in`) {\n private val sb = StringBuilder()\n private val buffer = ByteArray(4096)\n private var pos = 0\n private var size = 0\n\n fun nextLong(): Long {\n var c = skipWhitespace()\n\n val sign = if (c == '-'.toInt()) {\n c = read()\n -1\n } else 1\n\n var ans = 0L\n\n while (c > ' '.toInt()) {\n ans = ans * 10 + c - '0'.toInt()\n c = read()\n }\n\n return sign * ans\n }\n\n fun nextInt() = nextLong().toInt()\n\n private fun skipWhitespace(): Int {\n while (true) {\n val c = read()\n if (c > ' '.toInt() || c < 0) return c\n }\n }\n\n private fun read(): Int {\n while (pos >= size) {\n if (size < 0) return -1\n size = input.read(buffer, 0, buffer.size)\n pos = 0\n }\n return buffer[pos++].toInt()\n }\n}\n\n/**\n * @param mod prime number\n */\nclass Mod(val mod: Int) {\n init {\n assert(mod > 1)\n }\n\n inline fun Long.mod() = (this % mod).toInt().let { if (it < 0) it + mod else it }\n inline fun Long.unsafeMod() = (this % mod).toInt()\n infix inline fun Int.madd(other: Int) = plus(other.toLong()).unsafeMod()\n infix inline fun Int.mmul(other: Int) = times(other.toLong()).unsafeMod()\n\n}\n\ninline fun withMod(mod: Int, action: Mod.() -> T): T = Mod(mod).action()\n\nclass PrimeSieve(maxN: Int) {\n private val minDivisor = IntArray(maxN + 1) { it }\n\n init {\n var n = 2\n while (n * n <= maxN) {\n if (n == minDivisor[n]) {\n (n * n..maxN step n).forEach {\n minDivisor[it] = minDivisor[it].coerceAtMost(n)\n }\n }\n n++\n }\n }\n\n fun getMinDivisor(n: Int) = minDivisor[n]\n}"}], "negative_code": [], "src_uid": "c9d45dac4a22f8f452d98d05eca2e79b"} {"nl": {"description": "Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate.The path consists of $$$n$$$ consecutive tiles, numbered from $$$1$$$ to $$$n$$$. Ujan will paint each tile in some color. He will consider the path aesthetic if for any two different tiles with numbers $$$i$$$ and $$$j$$$, such that $$$|j - i|$$$ is a divisor of $$$n$$$ greater than $$$1$$$, they have the same color. Formally, the colors of two tiles with numbers $$$i$$$ and $$$j$$$ should be the same if $$$|i-j| > 1$$$ and $$$n \\bmod |i-j| = 0$$$ (where $$$x \\bmod y$$$ is the remainder when dividing $$$x$$$ by $$$y$$$).Ujan wants to brighten up space. What is the maximum number of different colors that Ujan can use, so that the path is aesthetic?", "input_spec": "The first line of input contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 10^{12}$$$), the length of the path.", "output_spec": "Output a single integer, the maximum possible number of colors that the path can be painted in.", "sample_inputs": ["4", "5"], "sample_outputs": ["2", "5"], "notes": "NoteIn the first sample, two colors is the maximum number. Tiles $$$1$$$ and $$$3$$$ should have the same color since $$$4 \\bmod |3-1| = 0$$$. Also, tiles $$$2$$$ and $$$4$$$ should have the same color since $$$4 \\bmod |4-2| = 0$$$.In the second sample, all five colors can be used. "}, "positive_code": [{"source_code": "import kotlin.math.sqrt\n\nfun main() {\n var n = readLine()!!.toLong()\n val coll = ArrayList()\n\n for (i in 2..sqrt(n.toDouble()).toLong() + 1) {\n if (n % i == 0L) {\n coll.add(i)\n\n n /= i\n\n while (n % i == 0L) {\n n /= i\n }\n }\n }\n\n if (!coll.any()) {\n println(n)\n } else if (coll.size == 1 && n == 1L) {\n println(coll[0])\n } else {\n println(1)\n }\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007L\nfun factorize(a: Long): List> {\n val res = mutableListOf>()\n var x = a\n var i = 2L\n while(i * i <= x) {\n var cnt = 0\n while (x % i == 0L) {\n cnt++\n x /= i\n }\n if (cnt > 0) res += Pair(i, cnt)\n i++\n }\n if (x > 1) res += Pair(x, 1)\n return res\n}\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val N = nl()\n val fact = factorize(N)\n if (fact.isEmpty()) {\n out.println(N)\n } else if (fact.size == 1) {\n val f = fact[0].first\n out.println(f)\n } else {\n out.println(1)\n }\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl() + offset\n }\n return res\n }\n\n private fun na2(n: Int, offset: Int = 0): Array {\n val a = Array(2){IntArray(n)}\n for (i in 0 until n) {\n for (e in a) {\n e[i] = ni() + offset\n }\n }\n return a\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}"}, {"source_code": "import kotlin.math.sqrt\n\npublic data class Cont(var a : Char, var b: Char, var c : Int)\n\nfun main(args: Array) {\n var n = readLine()!!.toLong()\n\n var numbers = arrayListOf()\n\n var max = sqrt(n.toDouble()).toInt() + 1\n\n for (i in 2L..(max)) {\n if(n % i == 0L) {\n numbers.add(i)\n while (n % i == 0L) {\n n /= i\n }\n }\n }\n\n when {\n numbers.size == 0 -> {\n println(n)\n }\n numbers.size == 1 -> {\n if(n == 1L) {\n println(numbers.first())\n } else\n {\n println(1)\n }\n }\n else -> {\n println(1)\n }\n }\n}"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\nimport java.util.TreeSet\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\nfun main() {\n output {\n val n = readLong()\n\n val ans = n.factorize().distinct().singleOrNull() ?: 1\n\n println(ans)\n }\n}\n\nfun Long.factorize() = sequence {\n var n = this@factorize\n\n for(p in 2..Long.MAX_VALUE) {\n if(p * p > n) break\n\n while(n % p == 0L) {\n yield(p)\n n /= p\n }\n }\n\n if(n > 1) yield(n)\n}\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\ninline fun output(block: PrintWriter.() -> Unit) { _writer.apply(block).flush() }\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun R._shuffle(rnd: Random, get: R.(Int) -> V, set: R.(Int, V) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, IntArray::get, IntArray::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, LongArray::get, LongArray::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, DoubleArray::get, DoubleArray::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, CharArray::get, CharArray::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toLong()\n var i = 2L\n val divisors = MutableList(0) { 0L }\n while (i * i <= n) {\n if (0L == n % i) {\n divisors.add(i)\n divisors.add(n/i)\n }\n i++\n }\n var gcd = n;\n for (d in divisors) {\n gcd = gcd(gcd, d)\n }\n println(gcd)\n\n}\n\nfun gcd(a: Long, b: Long): Long {\n if (b == 0L) {\n return a\n } else {\n return gcd(b, a % b)\n }\n}"}, {"source_code": "import kotlin.math.ceil\nimport kotlin.math.sqrt\n\nfun readints() = readLine()!!.split(\" \").map { it.toLong() }\nfun readstrs() = readLine()!!.split(\" \")\n\n\nfun gcd(a: Long, b: Long): Long {\n if (b == 0L) return a\n return gcd(b, a % b)\n}\n\nfun main() {\n val (n) = readints()\n var mm = -1L\n for (i in 2..(ceil(sqrt(n.toFloat())).toLong() + 1)) {\n if (n % i == 0L) {\n if (mm == -1L) {\n mm = i\n }\n mm = gcd(mm, i)\n mm = gcd(mm, n / i)\n }\n }\n if (n == 2L)\n print(2)\n else if (n == 3L) {\n print(3)\n } else if (mm == -1L) {\n println(n)\n } else {\n println(mm)\n }\n}\n"}, {"source_code": "import java.util.*\n\nfun main() {\n val jin = Scanner(System.`in`)\n var n = jin.nextLong()\n if (n == 1L) {\n println(1)\n return\n }\n for (p in 2L..1000000L) {\n if (n % p == 0L) {\n while (n % p == 0L){\n n /= p\n }\n if (n == 1L) {\n println(p)\n } else {\n println(1)\n }\n return\n }\n }\n println(n)\n}"}, {"source_code": "import kotlin.math.min\nimport kotlin.math.sqrt\n\nfun main() {\n fun readLong() = readLine()!!.toLong()\n\n fun Long.factors(): MutableSet {\n val output = mutableSetOf()\n val endLoop = sqrt(this.toDouble()).toLong()\n for (i in 2L..min(endLoop, this - 1)) {\n if (this % i == 0L) {\n output.add(i)\n output.add(this / i)\n }\n }\n return output\n }\n\n val n = readLong()\n val factors = n.factors()\n if (factors.isNotEmpty()) {\n val minFactor = factors.min()!!\n val toRemove = mutableSetOf()\n for (factor in factors)\n if (factor != minFactor) {\n var ff = factor\n while (ff % minFactor == 0L)\n ff /= minFactor\n if (ff == 1L) toRemove.add(factor)\n }\n factors.removeAll(toRemove)\n }\n print(\n when {\n factors.isEmpty() -> n\n factors.size == 1 -> factors.first()\n else -> 1\n }\n )\n}"}, {"source_code": "fun main() {\n var n = readLine()!!.toLong()\n if (n == 1L) {\n println(1)\n return\n }\n for (i in 2..10000000) if (n % i == 0L) {\n while (n % i == 0L)\n n /= i\n println(if (n == 1L) i else 1)\n return\n }\n println(n)\n}"}], "negative_code": [{"source_code": "import kotlin.math.sqrt\n\nfun main() {\n var n = readLine()!!.toLong()\n val coll = ArrayList()\n\n for (i in 2..sqrt(n.toDouble()).toLong() + 1) {\n if (n % i == 0.toLong()) {\n coll.add(i)\n\n n /= i\n\n while (n % i == 0.toLong()) {\n n /= i\n }\n }\n }\n\n if (!coll.any()) {\n println(n)\n } else if (coll.size == 1) {\n println(coll[0])\n } else {\n println(1)\n }\n}\n"}, {"source_code": "import kotlin.math.sqrt\n\npublic data class Cont(var a : Char, var b: Char, var c : Int)\n\nfun main(args: Array) {\n var n = readLine()!!.toLong()\n\n var numbers = arrayListOf()\n\n for (i in 2L..(sqrt(n.toDouble()).toLong() + 1L)) {\n if(n % i == 0L) {\n numbers.add(i)\n n /= i\n }\n }\n\n when {\n numbers.size == 0 -> {\n println(n)\n }\n numbers.size == 1 -> {\n println(numbers.first())\n }\n else -> {\n println(1)\n }\n }\n}"}, {"source_code": "import kotlin.math.sqrt\n\npublic data class Cont(var a : Char, var b: Char, var c : Int)\n\nfun main(args: Array) {\n var n = readLine()!!.toLong()\n\n var numbers = arrayListOf()\n\n for (i in 2L..(sqrt(n.toDouble()).toLong() + 1L)) {\n if(n % i == 0L) {\n numbers.add(i)\n while (n % 2 == 0L) {\n n /= i\n }\n }\n }\n\n when {\n numbers.size == 0 -> {\n println(n)\n }\n numbers.size == 1 -> {\n println(numbers.first())\n }\n else -> {\n println(1)\n }\n }\n}"}, {"source_code": "import kotlin.math.sqrt\n\npublic data class Cont(var a : Char, var b: Char, var c : Int)\n\nfun main(args: Array) {\n var n = readLine()!!.toLong()\n\n var numbers = arrayListOf()\n\n for (i in 2L..(sqrt(n.toDouble()).toLong() + 1L)) {\n if(n % i == 0L) {\n numbers.add(i)\n n /= i\n }\n }\n\n when {\n numbers.size == 0 -> {\n println(n)\n }\n numbers.size == 1 -> {\n println(2)\n }\n else -> {\n println(1)\n }\n }\n}"}, {"source_code": "import kotlin.math.sqrt\n\npublic data class Cont(var a : Char, var b: Char, var c : Int)\n\nfun main(args: Array) {\n var n = readLine()!!.toLong()\n\n var numbers = arrayListOf()\n\n var max = sqrt(n.toDouble()).toInt() + 1\n\n for (i in 2L..(max)) {\n if(n % i == 0L) {\n numbers.add(i)\n while (n % 2 == 0L) {\n n /= i\n }\n }\n }\n\n when {\n numbers.size == 0 -> {\n println(n)\n }\n numbers.size == 1 -> {\n if(n == 1L) {\n println(numbers.first())\n } else\n {\n println(1)\n }\n }\n else -> {\n println(1)\n }\n }\n}"}, {"source_code": "import kotlin.math.sqrt\n\npublic data class Cont(var a : Char, var b: Char, var c : Int)\n\nfun main(args: Array) {\n var n = readLine()!!.toLong()\n\n var numbers = arrayListOf()\n\n var max = sqrt(n.toDouble()).toInt() + 10\n\n for (i in 2L..(max)) {\n if(n % i == 0L) {\n numbers.add(i)\n while (n % 2 == 0L) {\n n /= i\n }\n }\n }\n\n when {\n numbers.size == 0 -> {\n println(n)\n }\n numbers.size == 1 -> {\n if(n == 1L) {\n println(numbers.first())\n } else\n {\n println(1)\n }\n }\n else -> {\n println(1)\n }\n }\n}"}, {"source_code": "import kotlin.math.ceil\nimport kotlin.math.sqrt\n\nfun readints() = readLine()!!.split(\" \").map { it.toLong() }\nfun readstrs() = readLine()!!.split(\" \")\n\n\nfun main() {\n val (n) = readints()\n var mm = -1L\n for (i in 2..(ceil(sqrt(n.toFloat())).toLong() + 1)) {\n if (n % i == 0L) {\n mm = i\n break\n }\n }\n if (mm == -1L) {\n println(n)\n } else {\n println(mm)\n }\n}\n"}, {"source_code": "import kotlin.math.ceil\nimport kotlin.math.sqrt\n\nfun readints() = readLine()!!.split(\" \").map { it.toInt() }\nfun readstrs() = readLine()!!.split(\" \")\n\n\nfun main() {\n val (n) = readints()\n var mm = -1\n for (i in 2..(ceil(sqrt(n.toFloat())).toInt() + 1)) {\n if (n % i == 0) {\n mm = i\n break\n }\n }\n if (mm == -1) {\n println(n)\n } else {\n println(mm)\n }\n}\n"}, {"source_code": "import kotlin.math.ceil\nimport kotlin.math.sqrt\n\nfun readints() = readLine()!!.split(\" \").map { it.toLong() }\nfun readstrs() = readLine()!!.split(\" \")\n\n\nfun gcd(a: Long, b: Long): Long {\n if (b == 0L) return a\n return gcd(b, a % b)\n}\n\nfun main() {\n val (n) = readints()\n var mm = -1L\n for (i in 2..(ceil(sqrt(n.toFloat())).toLong() + 1)) {\n if (n % i == 0L) {\n if (mm == -1L) {\n mm = i\n }\n mm = gcd(mm, i)\n mm = gcd(mm, n / i)\n }\n }\n if (mm == -1L) {\n println(n)\n } else {\n println(mm)\n }\n}\n"}, {"source_code": "import java.util.*\n\nfun main() {\n val jin = Scanner(System.`in`)\n var n = jin.nextLong()\n if (n == 1L) {\n println(1)\n return\n }\n for (p in 2L..1000000L) {\n if (n % p == 0L) {\n while (n % p == 0L ){\n n /= p\n }\n if (n == 1L) {\n println(p)\n } else {\n println(1)\n }\n return\n }\n }\n}"}, {"source_code": "import kotlin.math.min\nimport kotlin.math.sqrt\n\nfun main() {\n fun readLong() = readLine()!!.toLong()\n\n fun Long.factors(): MutableSet {\n val output = mutableSetOf()\n val endLoop = sqrt(this.toDouble()).toLong()\n for (i in 2L..min(endLoop, this - 1)) {\n if (this % i == 0L) {\n output.add(i)\n output.add(this / i)\n if (output.size > 1) return output\n }\n }\n return output\n }\n\n val n = readLong()\n val factors = n.factors()\n print(\n when {\n factors.isEmpty() -> n\n factors.size == 1 -> factors.first()\n else -> 1\n }\n )\n}"}], "src_uid": "f553e89e267c223fd5acf0dd2bc1706b"} {"nl": {"description": "Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: \"Little bears, wait a little, I want to make your pieces equal\" \"Come off it fox, how are you going to do that?\", the curious bears asked. \"It's easy\", said the fox. \"If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal\". The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal.", "input_spec": "The first line contains two space-separated integers a and b (1 ≤ a, b ≤ 109). ", "output_spec": "If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0.", "sample_inputs": ["15 20", "14 8", "6 6"], "sample_outputs": ["3", "-1", "0"], "notes": null}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nfun > max(a: T, b: T): T = if (b > a) b else a\nfun > min(a: T, b: T): T = if (b < a) b else a\nfun Number.isEven(): Boolean = if (this.toInt() and 1 == 0) true else false\nfun Number.isOdd (): Boolean = !this.isEven()\n\nfun factorList(a: Int): MutableList {\n var a = a\n var b = 2\n val res = mutableListOf()\n while (b * b <= a) {\n if (a % b == 0) {\n res.add(b)\n a = a / b\n b = 2\n } else ++b\n }\n if (a > 1) res.add(a)\n return res\n}\n\nfun main(args: Array) {\n if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))\n val br = BufferedReader(InputStreamReader(System.`in`))\n val bw = BufferedWriter(OutputStreamWriter(System.out))\n\n var st = StringTokenizer(br.readLine())\n val a = st.nextToken().toInt()\n val b = st.nextToken().toInt()\n\n val lista = factorList(a)\n val listb = factorList(b)\n\n if (a == 1 && b == 1) bw.write(\"0\\n\")\n else if (a == 1) {\n if (listb.last() > 5) bw.write(\"-1\\n\")\n else bw.write(\"${listb.size}\\n\")\n }\n else if (b == 1) {\n if (lista.last() > 5) bw.write(\"-1\\n\")\n else bw.write(\"${lista.size}\\n\")\n }\n else {\n val itera = lista.iterator()\n while (itera.hasNext()) {\n val idx = listb.indexOf(itera.next())\n if (idx != -1) {\n listb.removeAt(idx)\n itera.remove()\n }\n }\n if ((lista.isNotEmpty() && lista.last() > 5) ||\n (listb.isNotEmpty() && listb.last() > 5)) bw.write(\"-1\\n\")\n else bw.write(\"${lista.size + listb.size}\\n\")\n }\n\n bw.close()\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun > max(a: T, b: T): T = if (b > a) b else a\nfun > min(a: T, b: T): T = if (b < a) b else a\nfun Number.isEven(): Boolean = if (this.toInt() and 1 == 0) true else false\nfun Number.isOdd (): Boolean = !this.isEven()\n\nfun factorList(a: Int): MutableList {\n var a = a\n var b = 2\n val res = mutableListOf()\n if (a < 2) return res\n while (b * b <= a) {\n if (a % b == 0) {\n res.add(b)\n a = a / b\n b = 2\n } else ++b\n }\n res.add(a)\n return res\n}\n\nfun main(args: Array) {\n if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))\n val br = BufferedReader(InputStreamReader(System.`in`))\n val bw = BufferedWriter(OutputStreamWriter(System.out))\n\n var st = StringTokenizer(br.readLine())\n val a = st.nextToken().toInt()\n val b = st.nextToken().toInt()\n\n val lista = factorList(a)\n val listb = factorList(b)\n\n val itera = lista.iterator()\n while (itera.hasNext()) {\n val idx = listb.indexOf(itera.next())\n if (idx != -1) {\n listb.removeAt(idx)\n itera.remove()\n }\n }\n if ((lista.isNotEmpty() && lista.last() > 5) ||\n (listb.isNotEmpty() && listb.last() > 5)) bw.write(\"-1\\n\")\n else bw.write(\"${lista.size + listb.size}\\n\")\n\n bw.close()\n}\n"}], "negative_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nfun > max(a: T, b: T): T = if (b > a) b else a\nfun > min(a: T, b: T): T = if (b < a) b else a\nfun Number.isEven(): Boolean = if (this.toInt() and 1 == 0) true else false\nfun Number.isOdd (): Boolean = !this.isEven()\n\nfun factorList(a: Int): MutableList {\n var a = a\n var b = 2\n val res = mutableListOf()\n while (b * b <= a) {\n if (a % b == 0) {\n res.add(b)\n a = a / b\n b = 2\n } else ++b\n }\n res.add(a)\n return res\n}\n\nfun main(args: Array) {\n if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))\n val br = BufferedReader(InputStreamReader(System.`in`))\n val bw = BufferedWriter(OutputStreamWriter(System.out))\n\n var st = StringTokenizer(br.readLine())\n val a = st.nextToken().toInt()\n val b = st.nextToken().toInt()\n\n val lista = factorList(a)\n val listb = factorList(b)\n\n if (a == 1 && b == 1) bw.write(\"0\\n\")\n else if (a == 1) bw.write(\"${listb.size}\\n\")\n else if (b == 1) bw.write(\"${lista.size}\\n\")\n else if (lista.last() != listb.last()) bw.write(\"-1\\n\")\n else {\n while (lista.isNotEmpty() && listb.isNotEmpty() && lista.last() == listb.last()) {\n lista.removeAt(lista.lastIndex)\n listb.removeAt(listb.lastIndex)\n }\n bw.write(\"${lista.size + listb.size}\\n\")\n }\n\n bw.close()\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun > max(a: T, b: T): T = if (b > a) b else a\nfun > min(a: T, b: T): T = if (b < a) b else a\nfun Number.isEven(): Boolean = if (this.toInt() and 1 == 0) true else false\nfun Number.isOdd (): Boolean = !this.isEven()\n\nfun factorList(a: Int): MutableList {\n var a = a\n var b = 2\n val res = mutableListOf()\n while (b * b <= a) {\n if (a % b == 0) {\n res.add(b)\n a = a / b\n b = 2\n } else ++b\n }\n if (a > 1) res.add(a)\n return res\n}\n\nfun main(args: Array) {\n if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))\n val br = BufferedReader(InputStreamReader(System.`in`))\n val bw = BufferedWriter(OutputStreamWriter(System.out))\n\n var st = StringTokenizer(br.readLine())\n val a = st.nextToken().toInt()\n val b = st.nextToken().toInt()\n\n val lista = factorList(a)\n val listb = factorList(b)\n\n if (a == 1 && b == 1) bw.write(\"0\\n\")\n else if (a == 1) bw.write(\"${listb.size}\\n\")\n else if (b == 1) bw.write(\"${lista.size}\\n\")\n else {\n val itera = lista.iterator()\n while (itera.hasNext()) {\n val idx = listb.indexOf(itera.next())\n if (idx != -1) {\n listb.removeAt(idx)\n itera.remove()\n }\n }\n if ((lista.isNotEmpty() && lista.last() > 5) ||\n (listb.isNotEmpty() && listb.last() > 5)) bw.write(\"-1\\n\")\n else bw.write(\"${lista.size + listb.size}\\n\")\n }\n\n bw.close()\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun > max(a: T, b: T): T = if (b > a) b else a\nfun > min(a: T, b: T): T = if (b < a) b else a\nfun Number.isEven(): Boolean = if (this.toInt() and 1 == 0) true else false\nfun Number.isOdd (): Boolean = !this.isEven()\n\nfun factorList(a: Int): MutableList {\n var a = a\n var b = 2\n val res = mutableListOf()\n while (b * b <= a) {\n if (a % b == 0) {\n res.add(b)\n a = a / b\n b = 2\n } else ++b\n }\n if (a > 1) res.add(a)\n return res\n}\n\nfun main(args: Array) {\n if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))\n val br = BufferedReader(InputStreamReader(System.`in`))\n val bw = BufferedWriter(OutputStreamWriter(System.out))\n\n var st = StringTokenizer(br.readLine())\n val a = st.nextToken().toInt()\n val b = st.nextToken().toInt()\n\n val lista = factorList(a)\n val listb = factorList(b)\n var lstsize = lista.size + listb.size\n\n if (a == 1 && b == 1) bw.write(\"0\\n\")\n else if (a == 1) bw.write(\"${listb.size}\\n\")\n else if (b == 1) bw.write(\"${lista.size}\\n\")\n else if (lista.last() > 5 || lista.last() > 5) bw.write(\"-1\\n\")\n else {\n for (e in lista) {\n val idx = listb.indexOf(e)\n if (idx != -1) {\n listb.removeAt(idx)\n lstsize -= 2\n }\n }\n bw.write(\"$lstsize\\n\")\n }\n\n bw.close()\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun > max(a: T, b: T): T = if (b > a) b else a\nfun > min(a: T, b: T): T = if (b < a) b else a\nfun Number.isEven(): Boolean = if (this.toInt() and 1 == 0) true else false\nfun Number.isOdd (): Boolean = !this.isEven()\n\nfun factorList(a: Int): MutableList {\n var a = a\n var b = 2\n val res = mutableListOf()\n while (b * b <= a) {\n if (a % b == 0) {\n res.add(b)\n a = a / b\n b = 2\n } else ++b\n }\n if (a > 1) res.add(a)\n return res\n}\n\nfun main(args: Array) {\n if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))\n val br = BufferedReader(InputStreamReader(System.`in`))\n val bw = BufferedWriter(OutputStreamWriter(System.out))\n\n var st = StringTokenizer(br.readLine())\n val a = st.nextToken().toInt()\n val b = st.nextToken().toInt()\n\n val lista = factorList(a)\n val listb = factorList(b)\n\n if (a == 1 && b == 1) bw.write(\"0\\n\")\n else if (a == 1) bw.write(\"${listb.size}\\n\")\n else if (b == 1) bw.write(\"${lista.size}\\n\")\n else if (lista.last() > 5 || lista.last() > 5) bw.write(\"-1\\n\")\n else {\n while (lista.isNotEmpty() && listb.isNotEmpty() && lista.last() == listb.last()) {\n lista.removeAt(lista.lastIndex)\n listb.removeAt(listb.lastIndex)\n }\n bw.write(\"${lista.size + listb.size}\\n\")\n }\n\n bw.close()\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun > max(a: T, b: T): T = if (b > a) b else a\nfun > min(a: T, b: T): T = if (b < a) b else a\nfun Number.isEven(): Boolean = if (this.toInt() and 1 == 0) true else false\nfun Number.isOdd (): Boolean = !this.isEven()\n\nfun factorList(a: Int): MutableList {\n var a = a\n var b = 2\n val res = mutableListOf()\n while (b * b <= a) {\n if (a % b == 0) {\n res.add(b)\n a = a / b\n b = 2\n } else ++b\n }\n res.add(a)\n return res\n}\n\nfun main(args: Array) {\n if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))\n val br = BufferedReader(InputStreamReader(System.`in`))\n val bw = BufferedWriter(OutputStreamWriter(System.out))\n\n var st = StringTokenizer(br.readLine())\n val a = st.nextToken().toInt()\n val b = st.nextToken().toInt()\n\n val lista = factorList(a)\n val listb = factorList(b)\n\n if (lista.last() != listb.last()) bw.write(\"-1\\n\")\n else {\n while (lista.isNotEmpty() && listb.isNotEmpty() && lista.last() == listb.last()) {\n lista.removeAt(lista.lastIndex)\n listb.removeAt(listb.lastIndex)\n }\n bw.write(\"${lista.size + listb.size}\\n\")\n }\n\n bw.close()\n}\n"}], "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49"} {"nl": {"description": "Alice and Bob are playing a game with $$$n$$$ piles of stones. It is guaranteed that $$$n$$$ is an even number. The $$$i$$$-th pile has $$$a_i$$$ stones.Alice and Bob will play a game alternating turns with Alice going first.On a player's turn, they must choose exactly $$$\\frac{n}{2}$$$ nonempty piles and independently remove a positive number of stones from each of the chosen piles. They can remove a different number of stones from the piles in a single turn. The first player unable to make a move loses (when there are less than $$$\\frac{n}{2}$$$ nonempty piles).Given the starting configuration, determine who will win the game.", "input_spec": "The first line contains one integer $$$n$$$ ($$$2 \\leq n \\leq 50$$$) — the number of piles. It is guaranteed that $$$n$$$ is an even number. The second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 50$$$) — the number of stones in the piles.", "output_spec": "Print a single string \"Alice\" if Alice wins; otherwise, print \"Bob\" (without double quotes).", "sample_inputs": ["2\n8 8", "4\n3 1 4 1"], "sample_outputs": ["Bob", "Alice"], "notes": "NoteIn the first example, each player can only remove stones from one pile ($$$\\frac{2}{2}=1$$$). Alice loses, since Bob can copy whatever Alice does on the other pile, so Alice will run out of moves first.In the second example, Alice can remove $$$2$$$ stones from the first pile and $$$3$$$ stones from the third pile on her first move to guarantee a win."}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val jin = BufferedReader(InputStreamReader(System.`in`))\n val n = jin.readLine().toInt()\n val piles = jin.readLine().split(\" \").map { it.toInt() }\n println(if (piles.count { it == piles.min() } <= n / 2) \"Alice\" else \"Bob\")\n}"}], "negative_code": [], "src_uid": "4b9cf82967aa8441e9af3db3101161e9"} {"nl": {"description": "As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC.One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.You are given a binary number of length n named x. We know that member i from MDC dances with member from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7).Expression denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor».", "input_spec": "The first line of input contains a binary number x of lenght n, (1 ≤ n ≤ 100). This number may contain leading zeros.", "output_spec": "Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).", "sample_inputs": ["11", "01", "1"], "sample_outputs": ["6", "2", "1"], "notes": null}, "positive_code": [{"source_code": "fun main() {\n val x = readLn()\n\n var e = ModInt(1)\n var ans = ModInt(0)\n for(c in x.reversed()) {\n ans *= 2\n if(c == '1') ans += e\n e *= 4\n }\n\n println(ans)\n}\n\ninfix fun Int.umod(base: Int) =\n (this % base).let { if(it >= 0) it else it + base }\n\ninfix fun Long.umod(base: Long) =\n (this % base).let { if(it >= 0) it else it + base }\n\ninfix fun Long.umod(base: Int) =\n (this % base).let { if(it >= 0) it else it + base }\n\nfun Int.mulMod(other: Int, mod: Int) = (toLong() * other).umod(mod).toInt()\n\nfun Int.powMod(exponent: Int, mod: Int): Int {\n var res = 1L\n var e = exponent\n var b = umod(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\n\n/** modint inline class, requires hardcoded mod base **/\nconst val MODBASE = 1000000007\n\ninline fun Int.toModInt() = ModInt(this umod MODBASE)\ninline fun Long.toModInt() = ModInt((this umod MODBASE).toInt())\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n companion object {\n /** can't seem to make these private or inlined without causing compiler issues */\n val _invMemo = HashMap()\n fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }\n }\n\n inline operator fun plus(other: ModInt) = plus(other.int) // MODBASE < 2^30\n inline operator fun plus(other: Int) = (int + other).toModInt() // careful of possible overflow\n inline operator fun inc() = plus(1)\n\n inline operator fun minus(other: ModInt) = minus(other.int)\n inline operator fun minus(other: Int) = (int - other).toModInt()\n inline operator fun dec() = minus(1)\n operator fun unaryMinus() = if(int == 0) this else ModInt(MODBASE - int)\n\n inline operator fun times(other: ModInt) = times(other.int)\n inline operator fun times(other: Int) = ModInt(int.mulMod(other, MODBASE))\n\n fun pow(exponent: Int): ModInt {\n val e = if(exponent < 0) exponent umod MODBASE - 1 else exponent // assumes MODBASE is prime\n return ModInt(int.powMod(e, MODBASE))\n }\n\n inline fun inv() = inv_memoized() /** NOTE: Change if necessary */\n\n fun inv_unmemoized(): ModInt {\n require(int != 0) { \"Can't invert/divide by 0\" }\n return pow(MODBASE - 2) // assumes MODBASE is prime\n }\n fun inv_memoized() = _invMemoized(this)\n\n operator fun div(other: ModInt) = times(other.inv())\n inline operator fun div(other: Int) = div(other.toModInt())\n\n override fun toString() = int.toString()\n}\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n inline operator fun get(i: Int) = ModInt(intArray[i])\n inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override val size: Int get() = intArray.size\n\n override fun contains(element: ModInt): Boolean = any { it == element }\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override fun isEmpty(): Boolean = size == 0\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): ModInt = get(index++)\n }\n}\nfun ModIntArray(capacity: Int) = ModIntArray(IntArray(capacity))\ninline fun ModIntArray(capacity: Int, init: (Int) -> ModInt) =\n ModIntArray(IntArray(capacity) { init(it).int })\n\nfun Iterable.sum() = fold(ModInt(0), ModInt::plus)\nfun Sequence.sum() = fold(ModInt(0), ModInt::plus)\nfun Iterable.product() = fold(1L) { acc, it -> acc * it.int % MODBASE }.toModInt()\nfun Sequence.product() = fold(1L) { acc, it -> acc * it.int % MODBASE }.toModInt()\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readStringSeq() = readLn().splitToSequence(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readIntSeq() = readStringSeq().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readDoubleSeq() = readStringSeq().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\nfun readLongSeq() = readStringSeq().map { it.toLong() }\n\nclass Output {\n val outputSb = StringBuilder()\n fun print(o: Any?) { outputSb.append(o) }\n fun println() { outputSb.append('\\n') }\n fun println(o: Any?) { outputSb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(outputSb) }\n}\ninline fun output(block: Output.()->Unit) { Output().apply(block).nowPrint() }"}, {"source_code": "fun main() {\n val x = readLn()\n\n var e = ModInt(1)\n var ans = ModInt(0)\n for(c in x.reversed()) {\n ans *= 2\n if(c == '1') ans += e\n e *= 4\n }\n\n println(ans)\n}\n\ninline fun Array.numSortBy(crossinline f: (T) -> Any?) = groupingBy(f).eachCount().values\n .fold(ModInt(1)) { acc, i -> acc * i.factorial() }\n\nval _factorialMemo = mutableListOf(ModInt(1))\n\nfun Int.factorial() = run {\n while(this > _factorialMemo.lastIndex) {\n _factorialMemo.add(_factorialMemo.last() * _factorialMemo.size)\n }\n\n _factorialMemo[this]\n}\n\ninfix fun Int.umod(base: Int) =\n (this % base).let { if(it >= 0) it else it + base }\n\ninfix fun Long.umod(base: Long) =\n (this % base).let { if(it >= 0) it else it + base }\n\ninfix fun Long.umod(base: Int) =\n (this % base).let { if(it >= 0) it else it + base }\n\nfun Int.mulMod(other: Int, mod: Int) = (toLong() * other).umod(mod).toInt()\n\nfun Int.powMod(exponent: Int, mod: Int): Int {\n var res = 1L\n var e = exponent\n var b = umod(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\n\n/** modint inline class, requires hardcoded mod base **/\nconst val MODBASE = 1000000007\n\ninline fun Int.toModInt() = ModInt(this umod MODBASE)\ninline fun Long.toModInt() = ModInt((this umod MODBASE).toInt())\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n companion object {\n /** can't seem to make these private or inlined without causing compiler issues */\n val _invMemo = HashMap()\n fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }\n }\n\n inline operator fun plus(other: ModInt) = plus(other.int) // MODBASE < 2^30\n inline operator fun plus(other: Int) = (int + other).toModInt() // careful of possible overflow\n inline operator fun inc() = plus(1)\n\n inline operator fun minus(other: ModInt) = minus(other.int)\n inline operator fun minus(other: Int) = (int - other).toModInt()\n inline operator fun dec() = minus(1)\n operator fun unaryMinus() = if(int == 0) this else ModInt(MODBASE - int)\n\n inline operator fun times(other: ModInt) = times(other.int)\n inline operator fun times(other: Int) = ModInt(int.mulMod(other, MODBASE))\n\n fun pow(exponent: Int): ModInt {\n val e = if(exponent < 0) exponent umod MODBASE - 1 else exponent // assumes MODBASE is prime\n return ModInt(int.powMod(e, MODBASE))\n }\n\n inline fun inv() = inv_memoized() /** NOTE: Change if necessary */\n\n fun inv_unmemoized(): ModInt {\n require(int != 0) { \"Can't invert/divide by 0\" }\n return pow(MODBASE - 2) // assumes MODBASE is prime\n }\n fun inv_memoized() = _invMemoized(this)\n\n operator fun div(other: ModInt) = times(other.inv())\n inline operator fun div(other: Int) = div(other.toModInt())\n\n override fun toString() = int.toString()\n}\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n inline operator fun get(i: Int) = ModInt(intArray[i])\n inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override val size: Int get() = intArray.size\n\n override fun contains(element: ModInt): Boolean = any { it == element }\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override fun isEmpty(): Boolean = size == 0\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): ModInt = get(index++)\n }\n}\nfun ModIntArray(capacity: Int) = ModIntArray(IntArray(capacity))\ninline fun ModIntArray(capacity: Int, init: (Int) -> ModInt) =\n ModIntArray(IntArray(capacity) { init(it).int })\n\nfun Iterable.sum() = fold(ModInt(0), ModInt::plus)\nfun Sequence.sum() = fold(ModInt(0), ModInt::plus)\nfun Iterable.product() = fold(1L) { acc, it -> acc * it.int % MODBASE }.toModInt()\nfun Sequence.product() = fold(1L) { acc, it -> acc * it.int % MODBASE }.toModInt()\n\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readStringSeq() = readLn().splitToSequence(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readIntSeq() = readStringSeq().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readDoubleSeq() = readStringSeq().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\nfun readLongSeq() = readStringSeq().map { it.toLong() }\n\nclass Output {\n val outputSb = StringBuilder()\n fun print(o: Any?) { outputSb.append(o) }\n fun println() { outputSb.append('\\n') }\n fun println(o: Any?) { outputSb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(outputSb) }\n}\ninline fun output(block: Output.()->Unit) { Output().apply(block).nowPrint() }"}], "negative_code": [], "src_uid": "89b51a31e00424edd1385f2120028b9d"} {"nl": {"description": "Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.", "input_spec": "The first line contains two numbers n, k (1 ≤ n ≤ 100, 0 ≤ k ≤ 10 000), the number of instruments and number of days respectively. The second line contains n integers ai (1 ≤ ai ≤ 100), representing number of days required to learn the i-th instrument.", "output_spec": "In the first line output one integer m representing the maximum number of instruments Amr can learn. In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order. if there are multiple optimal solutions output any. It is not necessary to use all days for studying.", "sample_inputs": ["4 10\n4 3 1 2", "5 6\n4 3 1 1 2", "1 3\n4"], "sample_outputs": ["4\n1 2 3 4", "3\n1 3 4", "0"], "notes": "NoteIn the first test Amr can learn all 4 instruments.In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.In the third test Amr doesn't have enough time to learn the only presented instrument."}, "positive_code": [{"source_code": "import java.io.BufferedReader\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n val (n, k) = r.readLine()!!.split(\" \").map { it.toInt() }\n val v2 = List(n) {\n val a = r.readInt()\n Pair(a, it)\n }.sortedBy { it.first }\n //val v1 = r.readLine()!!.split(\" \").map { it.toInt() }.sorted()\n val v = v2.map { it.first }.toIntArray()\n (1..n - 1).forEach { v[it] += v[it - 1] }\n fun f(intArray: IntArray, x: Int): Int {\n var le = 0\n var ri = intArray.size\n while (le < ri) {\n val mi = le + (ri - le) / 2\n when {\n intArray[mi] <= x -> le = mi + 1\n intArray[mi] > x -> ri = mi\n }\n }\n return le - 1\n }\n\n val i = f(v, k)\n println(i + 1)\n println(v2.subList(0, i + 1).map { it.second+1 }.joinToString(\" \"))\n //val n = r.readLine()!!.toInt()\n}\n\ntailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\n\n// Hakiobo's code for faster reading input\nprivate const val SPACE_INT = ' '.toInt()\nprivate const val ZERO_INT = '0'.toInt()\nprivate const val NL_INT = '\\n'.toInt()\n\nprivate fun BufferedReader.readInt(): Int {\n var ret = read()\n while (ret <= SPACE_INT) {\n ret = read()\n }\n val neg = ret == '-'.toInt()\n if (neg) {\n ret = read()\n }\n ret -= ZERO_INT\n var read = read()\n while (read >= ZERO_INT) {\n ret *= 10\n ret += read - ZERO_INT\n read = read()\n }\n\n while (read <= SPACE_INT && read != -1 && read != NL_INT) {\n mark(1)\n read = read()\n }\n if (read > SPACE_INT) {\n reset()\n }\n return if (neg) -ret else ret\n}\n"}, {"source_code": "import java.util.HashMap\n\nfun main() {\n var (n, k) = readLine()!!.split(\" \").map { it.toInt() }\n var list = readLine()!!.split(\" \").map { it.toInt() }\n var sum = 0\n var hashMap = HashMap()\n for ((index, value) in list.withIndex()) {\n hashMap.put(index, value)\n }\n var ans = mutableListOf()\n var t = list.sorted()\n for (i in t) {\n k -= i\n if (k >= 0) {\n for (j in hashMap) {\n if (j.value == i) {\n ans.add(j.key+1)\n hashMap.remove(j.key)\n break\n }\n }\n }\n }\n println(ans.size)\n for(i in ans){\n print(\"$i \")\n }\n\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (_, numDays) = readInts()\n val daysRequired = readInts().mapIndexed { index, i -> i to index }.sortedBy { it.first }\n var currentDays = 0\n var sol = 0\n val solList = mutableListOf()\n for (days in daysRequired)\n if (currentDays + days.first <= numDays) {\n currentDays += days.first\n sol++\n solList.add(days.second + 1)\n } else break\n println(sol)\n print(solList.joinToString(\" \"))\n}"}], "negative_code": [{"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n val (n,k) = r.readLine()!!.split(\" \").map { it.toInt() }\n val v1 = r.readLine()!!.split(\" \").map { it.toInt() }.sorted()\n val v = v1.toIntArray()\n (1..n-1).forEach { v[it]+=v[it-1] }\n fun f(intArray: IntArray, x:Int):Int{\n var le = 0\n var ri = intArray.size\n while (le le = mi+1\n intArray[mi]>x -> ri = mi\n }\n }\n return le-1\n }\n val i = f(v, k)\n println(i+1)\n println(v1.subList(0, i+1).joinToString(\" \"))\n //val n = r.readLine()!!.toInt()\n}"}, {"source_code": "fun main() {\n var (n, k) = readLine()!!.split(\" \").map { it.toInt() }\n var list = readLine()!!.split(\" \").map { it.toInt() }.sorted()\n var sum = 0\n var ans = mutableListOf()\n for ((index,value) in list.withIndex()) {\n k-=value\n if (k>=0){\n ans.add(index+1)\n }\n }\n println(ans.size)\n for (i in ans){\n print(\"$i \")\n }\n}"}, {"source_code": "fun main() {\n var (n, k) = readLine()!!.split(\" \").map { it.toInt() }\n var list = readLine()!!.split(\" \").map { it.toInt() }.sorted()\n var sum = 0\n var ans = mutableListOf()\n for (i in list) {\n k-=i\n if (k>=0){\n ans.add(i)\n }\n }\n println(ans.size)\n for (i in ans){\n print(\"$i \")\n }\n}"}], "src_uid": "dbb164a8dd190e63cceba95a31690a7c"} {"nl": {"description": "Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks. There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower.Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the (2i - 1)-th man in the line (for the current moment) talks with the (2i)-th one. Let's look at this process in more detail. Let's number the people from 1 to 5. Let's assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn't talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn't talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5 enters the shower, and then 4 enters the shower.We know that if students i and j talk, then the i-th student's happiness increases by gij and the j-th student's happiness increases by gji. Your task is to find such initial order of students in the line that the total happiness of all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower.", "input_spec": "The input consists of five lines, each line contains five space-separated integers: the j-th number in the i-th line shows gij (0 ≤ gij ≤ 105). It is guaranteed that gii = 0 for all i. Assume that the students are numbered from 1 to 5.", "output_spec": "Print a single integer — the maximum possible total happiness of the students.", "sample_inputs": ["0 0 0 0 9\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n7 0 0 0 0", "0 43 21 18 2\n3 0 21 11 65\n5 2 0 1 4\n54 62 12 0 99\n87 64 81 33 0"], "sample_outputs": ["32", "620"], "notes": "NoteIn the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals:(g23 + g32 + g15 + g51) + (g13 + g31 + g54 + g45) + (g15 + g51) + (g54 + g45) = 32."}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.HashSet\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val g = Array(5) { IntArray(5) }\n var max = 0\n\n for (i in 0..4)\n for (j in 0..4)\n g[i][j] = ir.nextInt()\n\n for (a in 0..4)\n for (b in 0..4)\n for (c in 0..4)\n for (d in 0..4)\n for (e in 0..4) {\n var count = 0\n val x = HashSet()\n x.add(a)\n x.add(b)\n x.add(c)\n x.add(d)\n x.add(e)\n if (x.size == 5)\n count = g[a][b] + g[b][a] + 2 * (g[c][d] + g[d][c]) + g[b][c] + g[c][b] + 2 * (g[d][e] + g[e][d])\n max = Math.max(max, count)\n }\n\n pw.print(max)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextFloat(): Float {\n return java.lang.Float.parseFloat(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import kotlin.math.max\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n val used = BooleanArray(5)\n var sol = 0\n val permutation = mutableListOf()\n val happiness = Array(5) { IntArray(5) }\n\n fun permute() {\n if (permutation.size == 5) {\n var oneSol = 0\n oneSol += happiness[permutation[0]][permutation[1]] + happiness[permutation[1]][permutation[0]]\n oneSol += happiness[permutation[2]][permutation[3]] + happiness[permutation[3]][permutation[2]]\n oneSol += happiness[permutation[1]][permutation[2]] + happiness[permutation[2]][permutation[1]]\n oneSol += happiness[permutation[3]][permutation[4]] + happiness[permutation[4]][permutation[3]]\n oneSol += happiness[permutation[2]][permutation[3]] + happiness[permutation[3]][permutation[2]]\n oneSol += happiness[permutation[3]][permutation[4]] + happiness[permutation[4]][permutation[3]]\n sol = max(sol, oneSol)\n } else {\n for (pos in 0..4) {\n if (used[pos]) continue\n used[pos] = true\n permutation.add(pos)\n permute()\n permutation.removeAt(permutation.lastIndex)\n used[pos] = false\n }\n }\n }\n\n for (row in 0 until 5) happiness[row] = readInts().toIntArray()\n permute()\n print(sol)\n}"}], "negative_code": [], "src_uid": "be6d4df20e9a48d183dd8f34531df246"} {"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 java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n var tok = StringTokenizer(\"\")\n\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n fun files(inputFilename: String, outputFilename: String) = ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))\n }\n\n fun readToken(): String {\n while (!tok.hasMoreTokens()) {\n tok = StringTokenizer(rd.readLine())\n }\n return tok.nextToken()\n }\n\n fun readInt(): Int = readToken().toInt()\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun close() {\n rd.close()\n wr.close()\n }\n}\n\nfun solve() {\n fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)\n\n val io = ProblemIO.console()\n val v = IntArray(2)\n v[0] = io.readInt()\n v[1] = io.readInt()\n val n = io.readInt()\n var cur = 0\n var r = n\n while (true) {\n val g = gcd(r, v[cur])\n cur = 1 - cur\n if (g > r) break\n r -= g\n }\n io.println(cur)\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val len = r.readLine()!!.toInt()\n //val (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n var (a, b, n) = r.readLine()!!.split(\" \").map { it.toInt() }\n var sturn = true\n var finish = false\n var swin = false\n while (!finish){\n if (sturn){\n val remove = gcd(a, n)\n if (remove<=n){\n n -= remove\n sturn = false\n } else {\n swin = false\n finish = true\n }\n } else {\n val remove = gcd(b, n)\n if (remove<=n){\n n -= remove\n sturn = true\n } else {\n swin = true\n finish = true\n }\n }\n }\n println(if (swin) 0 else 1)\n}\n\ntailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)"}, {"source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val input = readLine()!!.split(\" \").map(String::toInt)\n val a = input[0]\n val b = input[1]\n var n = input[2]\n\n var isA = true\n while (n > 0) {\n val player = if (isA) \"a\" else \"b\"\n// println(\"$player's Turn\")\n\n val value = if (isA) a else b\n val removed = gcd(n, value)\n// println(\"Removed: $removed\")\n\n n -= removed\n// println(\"$n left\")\n\n isA = !isA\n// println()\n }\n\n if (isA) {\n println(1)\n } else {\n println(0)\n }\n\n}\n\nfun gcd(a: Int, b: Int): Int {\n if (a == 0) {\n return b\n }\n if (b == 0) {\n return a\n }\n\n val min = min(a, b)\n val max = max(a, b)\n\n return gcd(min, max % min)\n}"}, {"source_code": "import java.util.*\nfun gcd(n1:Int,n2:Int):Int {\n var gcd = 1\n var i = 1\n while (i <= n1 && i <= n2) {\n if (n1 % i == 0 && n2 % i == 0)\n gcd = i\n ++i\n }\n return gcd\n}\nfun main(args: Array) {var reader = Scanner(System.`in`)\n var a:Int = reader.nextInt()\n var b:Int= reader.nextInt()\n var n:Int = reader.nextInt()\n var (aC,bC)= listOf(0,0)\n //print(gcd(a,n))\n while (n!=0){\n if (n!=0) {\n n -= gcd(a, n)\n aC++\n }\n if (n!=0) {\n n -= gcd(b, n)\n bC++\n }\n }\n if (aC>bC) print(0)\n else print(1)\n}"}, {"source_code": "import java.math.BigInteger\n\n\nfun main() {\n var (a, b, n) = readLine()!!.split(' ').map { it.toInt() }\n var flag = false\n while (n>0){\n if (!flag){\n if (n-gcd(a,n)>=0){\n n-=gcd(a,n)\n flag = true\n }\n }else{\n if (n-gcd(b,n)>=0){\n n-=gcd(b,n)\n flag = false\n }\n }\n }\n if (!flag){\n println(1)\n }else{\n println(0)\n }\n\n\n}\n\nfun gcd(a: Int, b: Int): Int {\n var i = 1\n var gcd = 1\n while (i <= a && i <= b) {\n if (a % i == 0 && b % i == 0) {\n gcd = i\n }\n i++\n }\n return gcd\n}"}, {"source_code": "fun main(args: Array) {\n var (a, b, n) = readLine()!!.split(' ').map { it.toInt() }\n\n fun gcd(x: Int, y: Int) = x.toBigInteger().gcd(y.toBigInteger()).toInt()\n\n while (true) {\n val ax = gcd(a, n)\n if (ax > n) {\n println(1)\n return\n }\n n -= ax\n val bx = gcd(b, n)\n if (bx > n) {\n println(0)\n return\n }\n n -= bx\n }\n}"}, {"source_code": "fun main() {\n var (a, b, n) = readLine()!!.split(\" \").map { it.toInt() }\n var s = true\n while (n >= 0) {\n n -= gcd(if (s) a else b, n)\n s = !s\n }\n println(if (s) 0 else 1)\n}\n\nfun gcd(n1: Int, n2: Int): Int = if (n2 != 0) gcd(n2, n1 % n2) else n1"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readLong() = readLine()!!.toLong()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n infix fun Long.maxMin(b: Long): Pair {\n return if (this >= b) this to b else b to this\n }\n\n fun gcd(a: Long, b: Long): Long {\n var (max, min) = a maxMin b\n while (min != 0L) {\n val newMin = max % min\n max = min\n min = newMin\n }\n return max\n }\n\n var (a, b, n) = readLongs()\n\n while (true) {\n n -= gcd(a, n)\n if (n < 0) {\n print(1)\n return\n }\n n -= gcd(b, n)\n if (n < 0) {\n print(0)\n return\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n var (a, b, n) = readLine()!!.split(' ').map { it.toInt() }\n\n var s = true\n while (n >= 0){\n n -= gcd(if (s) a else b, n)\n s = !s\n }\n println(if (s) 0 else 1)\n}\n\nfun gcd(n1: Int, n2: Int): Int = if (n2 != 0) gcd(n2, n1 % n2) else n1"}, {"source_code": "fun gcd(x: Int, y: Int): Int {\n var s = x\n var l = y\n \n while (s != 0) {\n val temp = s\n s = l % s\n l = temp\n }\n\n return l\n}\n\nfun main(args: Array) {\n var (s, a, stones) = readLine() !!.split(' ').map { it.toInt() }\n var sTurn = true\n while (true) {\n val greatestDivisor = if (sTurn) gcd(s, stones) else gcd(a, stones)\n if (greatestDivisor <= stones) {\n stones -= greatestDivisor\n }\n else {\n println(if (sTurn) 1 else 0)\n return\n }\n\n sTurn = !sTurn\n }\n}"}], "negative_code": [{"source_code": "fun main() {\n val (a, b, n) = readLine()!!.split(\" \").map { it.toInt() }\n if (a % 2 != 0 && b % 2 != 0 && n % 2 != 0) println(0)\n else println(1)\n}"}, {"source_code": "fun main() {\n val (a, b, n) = readLine()!!.split(\" \").map { it.toInt() }\n if (a % 2 != 0 && b % 2 != 0 && n % 2 != 0) println(0)\n else if (a % 10 == 0 && b % 10 == 0 && n %10 == 0) println(0)\n else println(1)\n}"}], "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2"} {"nl": {"description": "Vasily the bear has a favorite rectangle, it has one vertex at point (0, 0), and the opposite vertex at point (x, y). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes. Vasya also loves triangles, if the triangles have one vertex at point B = (0, 0). That's why today he asks you to find two points A = (x1, y1) and C = (x2, y2), such that the following conditions hold: the coordinates of points: x1, x2, y1, y2 are integers. Besides, the following inequation holds: x1 < x2; the triangle formed by point A, B and C is rectangular and isosceles ( is right); all points of the favorite rectangle are located inside or on the border of triangle ABC; the area of triangle ABC is as small as possible. Help the bear, find the required points. It is not so hard to proof that these points are unique.", "input_spec": "The first line contains two integers x, y ( - 109 ≤ x, y ≤ 109, x ≠ 0, y ≠ 0).", "output_spec": "Print in the single line four integers x1, y1, x2, y2 — the coordinates of the required points.", "sample_inputs": ["10 5", "-10 5"], "sample_outputs": ["0 15 15 0", "-15 0 0 15"], "notes": "NoteFigure to the first sample"}, "positive_code": [{"source_code": "import kotlin.math.abs\n\nfun main() {\n var (x, y) = readLine()!!.split(' ').map { it.toInt() }\n var sum = abs(x) + abs(y)\n if (x > 0 && y > 0) {\n println(\"0 $sum $sum 0\")\n } else if (x < 0 && y > 0) {\n println(\"${-sum} 0 0 ${sum}\")\n } else if (x > 0 && y < 0) {\n println(\"0 ${-sum} ${sum} 0\")\n } else {\n println(\"${-sum} 0 0 ${-sum}\")\n }\n}"}, {"source_code": "fun main() {\n val (x, y) = readLine()!!.split(\" \").map { it.toLong() }\n when {\n x > 0 && y > 0 -> print(\"0 ${x + y} ${x + y} 0\")\n x < 0 && y > 0 -> print(\"${x - y} 0 0 ${-x + y}\")\n x < 0 && y < 0 -> print(\"${x + y} 0 0 ${x + y}\")\n x > 0 && y < 0 -> print(\"0 ${-x + y} ${x - y} 0\")\n }\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.abs\n\nfun main() {\n val reader = InputReader(try{File(\"D:/repos/a/input.txt\").inputStream()} catch(e: Exception){System.`in`})\n val writer = PrintWriter(try{File(\"D:/repos/a/output.txt\").outputStream()} catch(e: Exception){System.out})\n\n val x = reader.int()\n val y = reader.int()\n val z = abs(x) + abs(y)\n val ans = when {\n x > 0 && y > 0 -> \"0 $z $z 0\"\n x < 0 && y < 0 -> \"-$z 0 0 -$z\"\n x < 0 && y > 0 -> \"-$z 0 0 $z\"\n else -> \"0 -$z $z 0\"\n }\n writer.println(ans)\n\n writer.close()\n}\n\nclass InputReader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer?\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = try { StringTokenizer(reader.readLine()) }\n catch (e: IOException) { throw RuntimeException(e) }\n }\n return tokenizer!!.nextToken()\n }\n fun ll(): Long { return next().toLong() }\n fun int(): Int { return next().toInt() }\n init { tokenizer = null }\n}"}], "negative_code": [{"source_code": "import kotlin.math.abs\n\nfun main() {\n var (x, y) = readLine()!!.split(' ').map { it.toInt() }\n var sum = abs(x) + abs(y)\n if (x > 0 && y > 0) {\n println(\"0 $sum $sum 0\")\n } else if (x < 0 && y > 0) {\n println(\"${-sum} 0 0 ${sum}\")\n } else if (x > 0 && y < 0) {\n println(\"0 ${-sum} ${sum} 0\")\n }else{\n println(\"0 ${-sum} ${-sum} 0\")\n }\n}"}, {"source_code": "import kotlin.math.abs\n\nfun main() {\n var (x, y) = readLine()!!.split(' ').map { it.toInt() }\n var sum = abs(x) + abs(y)\n if (x > 0 && y > 0) {\n println(\"0 $sum $sum 0\")\n } else if (x < 0 && y > 0) {\n println(\"${-sum} 0 0 $sum\")\n } else if (x > 0 && y < 0) {\n println(\"$sum 0 0 ${-sum}\")\n }else{\n println(\"${-sum} 0 0 ${-sum}\")\n }\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.abs\n\nfun main() {\n val reader = InputReader(try{File(\"D:/repos/a/input.txt\").inputStream()} catch(e: Exception){System.`in`})\n val writer = PrintWriter(try{File(\"D:/repos/a/output.txt\").outputStream()} catch(e: Exception){System.out})\n\n val x = reader.int()\n val y = reader.int()\n val z = abs(x) + abs(y)\n val ans = when {\n x > 0 && y > 0 -> \"0 $z $z 0\"\n x < 0 && y < 0 -> \"0 -$z -$z 0\"\n x < 0 && y > 0 -> \"0 $z -$z 0\"\n else -> \"0 -$z $z 0\"\n }\n writer.println(ans)\n\n writer.close()\n}\n\nclass InputReader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer?\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = try { StringTokenizer(reader.readLine()) }\n catch (e: IOException) { throw RuntimeException(e) }\n }\n return tokenizer!!.nextToken()\n }\n fun ll(): Long { return next().toLong() }\n fun int(): Int { return next().toInt() }\n init { tokenizer = null }\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.abs\n\nfun main() {\n val reader = InputReader(try{File(\"D:/repos/a/input.txt\").inputStream()} catch(e: Exception){System.`in`})\n val writer = PrintWriter(try{File(\"D:/repos/a/output.txt\").outputStream()} catch(e: Exception){System.out})\n\n val x = reader.int()\n val y = reader.int()\n val z = abs(x) + abs(y)\n val ans = when {\n x > 0 && y > 0 -> \"0 $z $z 0\"\n x < 0 && y < 0 -> \"0 -$z -$z 0\"\n x < 0 && y > 0 -> \"0 -$z $z 0\"\n else -> \"0 $z -$z 0\"\n }\n writer.println(ans)\n\n writer.close()\n}\n\nclass InputReader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer?\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = try { StringTokenizer(reader.readLine()) }\n catch (e: IOException) { throw RuntimeException(e) }\n }\n return tokenizer!!.nextToken()\n }\n fun ll(): Long { return next().toLong() }\n fun int(): Int { return next().toInt() }\n init { tokenizer = null }\n}"}], "src_uid": "e2f15a9d9593eec2e19be3140a847712"} {"nl": {"description": "Let's call a string a phone number if it has length 11 and fits the pattern \"8xxxxxxxxxx\", where each \"x\" is replaced by a digit.For example, \"80123456789\" and \"80000000000\" are phone numbers, while \"8012345678\" and \"79000000000\" are not.You have $$$n$$$ cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.", "input_spec": "The first line contains an integer $$$n$$$ — the number of cards with digits that you have ($$$1 \\leq n \\leq 100$$$). The second line contains a string of $$$n$$$ digits (characters \"0\", \"1\", ..., \"9\") $$$s_1, s_2, \\ldots, s_n$$$. The string will not contain any other characters, such as leading or trailing spaces.", "output_spec": "If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.", "sample_inputs": ["11\n00000000008", "22\n0011223344556677889988", "11\n31415926535"], "sample_outputs": ["1", "2", "0"], "notes": "NoteIn the first example, one phone number, \"8000000000\", can be made from these cards.In the second example, you can make two phone numbers from the cards, for example, \"80123456789\" and \"80123456789\".In the third example you can't make any phone number from the given cards."}, "positive_code": [{"source_code": "import kotlin.math.min\n\nfun main(args: Array) {\n\n val n = readLine()?.toInt() ?: 0\n val text = readLine().toString()\n\n val nc = n / 11\n\n var ec = 0\n for(c in text) {\n if(c == '8')\n ec++\n }\n\n println(min(ec, nc))\n\n}"}, {"source_code": "import java.io.FileInputStream\nimport java.util.*\n\nobject programkt {\n @JvmStatic fun main(args: Array) {\n if (args.size == 1)\n System.setIn(FileInputStream(args[0]))\n val sc = Scanner(System.`in`)\n sc.nextLine()\n val all = sc.nextLine()\n var eights = all.filter { it == '8' }.count()\n var others = all.length - eights\n var numbers = 0\n while (eights > 0) {\n eights--\n IntRange(1, 10).forEach {\n if (others > 0)\n others--\n else\n eights--\n }\n if (numbers < 0 || eights < 0)\n break\n numbers++\n }\n println(numbers)\n }\n}\n"}, {"source_code": "import kotlin.math.min\n\nfun main() {\n readLine()\n val s = readLine()!!\n print(min(s.count { it == '8' }, s.length / 11))\n}"}, {"source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n var digits = readLine()!!.count {it == '8'}\n println(minOf(n / 11, digits))\n}\n"}], "negative_code": [{"source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n var digits = readLine()!!.count {it == '8'}\n println(minOf(n / 8, digits))\n}\n"}], "src_uid": "259d01b81bef5536b969247ff2c2d776"} {"nl": {"description": "You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.", "input_spec": "The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers.", "output_spec": "In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers \"-1 -1\" (without the quotes).", "sample_inputs": ["2 15", "3 0"], "sample_outputs": ["69 96", "-1 -1"], "notes": null}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n }\n\n var tok = StringTokenizer(\"\")\n\n fun close() { rd.close(); wr.close() }\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun readToken(): String {\n while (!tok.hasMoreTokens()) tok = StringTokenizer(rd.readLine())\n return tok.nextToken()\n }\n fun readInt() = readToken().toInt()\n fun readLong() = readToken().toLong()\n fun readLine() : String {\n tok = StringTokenizer(\"\")\n return rd.readLine()\n }\n}\n\nfun main(args: Array) {\n Thread({ val io = ProblemIO.console(); solve(io) ; io.close() }).start()\n}\n\nfun solve(io: ProblemIO) {\n val m = io.readInt()\n val s = io.readInt()\n\n if (s == 0) {\n if (m == 1) {\n io.println(\"0 0\")\n } else {\n io.println(\"-1 -1\")\n }\n } else {\n if (s > m * 9) {\n io.println(\"-1 -1\")\n } else {\n var rs = s\n for (i in 1 .. m) {\n val d = Math.max(if (i == 1) 1 else 0, rs - (m - i) * 9)\n io.print(d)\n rs -= d\n }\n io.print(\" \")\n rs = s\n for (i in 1 .. m) {\n val d = Math.min(9, rs)\n io.print(d)\n rs -= d\n }\n io.println(\"\")\n }\n }\n}\n"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val (len, sum) = r.readLine()!!.split(\" \").map { it.toInt() }\n when {\n (len > 1 && sum == 0) || len * 9 < sum -> {\n println(\"-1 -1\")\n }\n else -> {\n var maxSum = sum\n var minSum = sum\n val max = MutableList(len) { 0 }\n for (i in 0..len-1){\n if (maxSum>=9){\n max[i] = 9\n maxSum -= 9\n } else {\n max[i] = maxSum\n maxSum -= maxSum\n }\n }\n val min = MutableList(len) { 0 }\n min[0] = 1\n minSum -= 1\n //println(len)\n for (i in len-1 downTo 0){\n min[i] += minOf(9, minSum)\n minSum -= minOf(9, minSum)\n }\n println(\"${min.joinToString(\"\")} ${max.joinToString(\"\")}\")\n }\n }\n}"}, {"source_code": "import java.io.PrintWriter\nimport kotlin.math.min\n\n\nfun main() {\n io.apply {\n\n val (m, s) = int to int\n\n if (s == 0 && m == 1) {\n cout .. 0 .. 0 .. nl\n } else if (s <= 0 || s > m * 9)\n cout .. -1 .. -1 .. nl\n else {\n val str = CharArray(m) { '0' }\n str[0] = '1'\n var q = s - 1\n for (i in m - 1 downTo 0) {\n var d = min(9, q)\n str[i] = (str[i] + d)\n q -= d\n }\n cout .. String(str) .. \" \"\n str.fill('0')\n q = s\n for (i in 0 until m) {\n var d = min(9, q)\n str[i] = (str[i] + d)\n q -= d\n }\n cout .. String(str) .. nl\n }\n\n }.cout.flush()\n}\n\n// @formatter:off\nprivate val io = object {\n private val `in` = System.`in`\n private fun ll(): Long {\n var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }\n do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n\n }\n val int get() = ll().toInt(); val long get() = ll()\n fun ints(n: Int = int): IntArray { return IntArray(n) { int } }\n fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }\n val cout = PrintWriter(System.out); val nl = \"\\n\"\n private var buf = CharArray(32)\n private var bufSize = 32\n fun str(expect: Int = 32): String {\n var ix = 0\n var x: Int\n if (bufSize < expect)\n buf = CharArray(expect)\n do x = `in`.read() while (x < 33)\n do {\n if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }\n buf[ix++] = x.toChar()\n x = `in`.read()\n } while (x > 32)\n return java.lang.String.copyValueOf(buf, 0, ix)\n }\n operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(\" \") }; return this }\n operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }\n} // @formatter:on\n\n/* ----------- */\n\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val ms = br.readLine().split(\" \").map { it.toInt() }\n val m = ms[0]\n val s = ms[1]\n\n if (s == 0){\n println(if (m == 1) \"0 0\" else \"-1 -1\")\n }else{\n\n if (s < 10){\n if (m == 1){\n println(\"$s $s\")\n }else{\n val maxNum = s.toString() + \"0\".repeat(m - 1)\n val minNum = \"1\" + \"0\".repeat(m - 2) + (s - 1).toString()\n println(\"$minNum $maxNum\")\n }\n\n } else if (s == 0 || m*9 < s){\n println(\"-1 -1\")\n } else{\n\n val ans = getMinAndMax(m, s)\n\n println(\"${ans.first} ${ans.second}\")\n\n }\n\n }\n\n}\n\nfun getMinAndMax(m: Int, s: Int): Pair{\n val num9s = s / 9\n val missing = m - num9s\n val nines = if (missing >= 2 && s % 9 == 0) \"9\".repeat(num9s - 1) else \"9\".repeat(num9s)\n val minNum: String\n val maxNum: String\n\n val d = if (s - 9*num9s == 0) 9 else s - 9*num9s\n\n if (missing == 0){\n minNum = nines\n maxNum = nines\n } else if (missing <= 1){\n minNum = d.toString() + nines\n maxNum = nines + d.toString()\n }else{\n val l = 1\n val h = (d - 1)\n val zeroes = \"0\".repeat(if (s % 9 == 0) missing - 1 else missing - 2)\n\n minNum = l.toString() + zeroes + h + nines\n maxNum = nines + d.toString() + zeroes + \"0\"\n }\n return Pair(minNum, maxNum)\n}"}, {"source_code": "fun main() {\n val (m, s) = readLine()!!.split(\" \").map { it.toInt() }\n var ansLittle = \"\"\n var ansBig = \"\"\n\n if (9 * m >= s && (s == 0 && m == 1 || s > 0)) {\n var t = m\n var k = s\n while (t > 0) {\n if (k > 9) {\n ansBig += \"9\"\n k -= 9\n } else {\n ansBig += k.toString()\n k = 0\n }\n t--\n }\n\n t = m\n k = s\n if ((t - 1) * 9 > k) {\n ansLittle += \"1\"\n k -= 1\n t--\n }\n while (t > 0) {\n if (t * 9 == k) {\n ansLittle += \"9\"\n k -= 9\n } else if ((t - 1) * 9 > k) {\n ansLittle += \"0\"\n } else {\n val q = k - ((t - 1) * 9)\n ansLittle += q.toString()\n k -= q\n }\n t--\n }\n } else {\n ansLittle = \"-1\"\n ansBig = \"-1\"\n }\n\n print(\"$ansLittle $ansBig\")\n}"}, {"source_code": "import java.util.*\n\nval noSolution = Pair(intArrayOf(-1), intArrayOf(-1))\n\nfun main(args: Array) {\n cf()\n}\n\nprivate fun cf() = with(Scanner(System.`in`)) {\n val m = nextInt()\n val s = nextInt()\n val (mi, ma) = run(m, s)\n\n print(mi.joinToString(\"\"))\n print(\" \")\n println(ma.joinToString(\"\"))\n}\n\nprivate fun run(m: Int, s: Int): Pair {\n if (m == 1 && s > 9) return noSolution\n if (m == 1) return Pair(intArrayOf(s), intArrayOf(s))\n if (s == 0) return noSolution\n\n var numOfNines = s / 9\n var rem = s % 9\n if (rem == 0) {\n rem = 9\n numOfNines--\n }\n\n if (numOfNines + 1 > m) return noSolution\n\n val ma = IntArray(m)\n for (i in 0 until numOfNines)\n ma[i] = 9\n ma[numOfNines] = rem\n\n val mi = ma.clone()\n if (numOfNines + 1 == m) {\n mi.reverse()\n } else {\n mi[mi.size - 1] = 1\n mi[numOfNines]--\n mi.reverse()\n }\n\n return Pair(mi, ma)\n}\n"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n val (length, sum) = readInts()\n val quotient = sum / 9\n val rest = sum % 9\n if (length == 1 && sum == 0) {\n print(\"0 0\")\n return\n }\n if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {\n print(\"-1 -1\")\n return\n }\n val a = mutableListOf()\n for (i in 0 until quotient) a.add(9)\n if (rest != 0) a.add(rest)\n\n val sb1 = StringBuilder()\n for (element in a) sb1.append(element)\n for (i in 0 until length - a.size)\n sb1.append('0')\n val sb2 = StringBuilder()\n if (length > a.size) {\n a[a.lastIndex]--\n sb2.append('1')\n for (i in 0 until length - a.size - 1) sb2.append('0')\n }\n for (i in a.lastIndex downTo 0) sb2.append(a[i])\n print(\"$sb2 $sb1\")\n}\n"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n val (length, sum) = readInts()\n var quotient = sum / 9\n var rest = sum % 9\n if (length == 1 && sum == 0) {\n print(\"0 0\")\n return\n }\n if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {\n print(\"-1 -1\")\n return\n }\n val sb1 = StringBuilder()\n for (i in 0 until quotient) sb1.append('9')\n if (quotient < length) sb1.append(rest)\n for (i in 0 until length - quotient - 1)\n sb1.append('0')\n val sb2 = StringBuilder()\n var oneEight = false\n if (length > quotient + 1) {\n rest--\n if (rest < 0) {\n rest = 0\n oneEight = true\n }\n sb2.append('1')\n for (i in 0 until length - quotient - 2) sb2.append('0')\n }\n if (quotient < length) sb2.append(rest)\n if(oneEight) {\n sb2.append('8')\n quotient--\n }\n for (i in 0 until quotient) sb2.append('9')\n print(\"$sb2 $sb1\")\n}\n\n\n// Shorter Python solution: https://codeforces.com/contest/489/submission/41588741"}, {"source_code": "// 7/7/2020 11:13 AM\n\n//package p489\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val (m, s) = readInts()\n// findSumToN(m, s)\n printResult(findSmallest(m, s))\n print(\" \")\n printResult(findLargest(m, s))\n println()\n}\n\nfun findLargest(m: Int, s: Int) : List {\n if (s <= 0 && m > 1) return listOf()\n else if (s == 0 && m == 1) return listOf(0)\n\n var sumLeft = s\n val outputList = MutableList(m) {0}\n var idx = 0\n while (sumLeft > 0 && idx < m) {\n outputList[idx] = if (sumLeft >= 9) 9 else sumLeft\n sumLeft -= outputList[idx++]\n }\n if (sumLeft > 0)\n return listOf()\n else\n return outputList.toList()\n}\n\nfun findSmallest(m: Int, s: Int) : List {\n if (s <= 0 && m > 1) return listOf()\n else if (s == 0 && m == 1) return listOf(0)\n\n var sumLeft = s\n val outputList = MutableList(m) {0}\n\n val minFirst = s - 9 * (m - 1)\n\n if (minFirst <= 1)\n outputList[0] = 1\n else if (minFirst > 9)\n return listOf()\n else\n outputList[0] = minFirst\n\n sumLeft -= outputList[0]\n\n var idx = m - 1\n while (sumLeft > 0 && idx > 0) {\n outputList[idx] = if (sumLeft >= 9) 9 else sumLeft\n sumLeft -= outputList[idx--]\n }\n if (sumLeft > 0)\n return listOf()\n else\n return outputList.toList()\n}\n\nfun printResult(l: List) {\n if (l.isEmpty())\n print(\"-1\")\n else\n print(l.fold(\"\", {acc, cur -> acc + cur.toString()}))\n}\n\n//fun findSumToN(m: Int, s: Int) {\n//// findSumToN_recursive(m, s, listOf())\n// printLeastAndGreatest(findSumToN_iterative(m, s))\n//}\n//\n//fun printLeastAndGreatest(l: List) {\n// if (l.isEmpty()) {\n// println(\"-1 -1\")\n// return\n// }\n//\n// val theGreatest = l.toMutableList()\n// val theLeast = l.toMutableList()\n//\n// for (i in theLeast.size-1 downTo 1) {\n// if (theLeast[i] > 0) {\n// val v = theLeast.removeAt(i)\n// theLeast.add(0, v)\n// break\n// }\n// }\n//\n// var pos = 1\n// for (i in theLeast.size - 1 downTo 1) {\n// val v = theLeast.removeAt(theLeast.size - 1)\n// theLeast.add(pos, v)\n// pos++\n// }\n//\n// print(theLeast.fold(\"\", { acc, cur -> acc + cur.toString()}))\n// print(\" \")\n// println(theGreatest.fold(\"\", { acc, cur -> acc + cur.toString()}))\n//\n//\n//}\n//\n//fun findSumToN_iterative(m: Int, s: Int) : List {\n// var currentList = mutableListOf()\n// if (s <= 0 && m > 1) return currentList\n//\n// while (currentList.sum() < s) {\n// val totalLeft = s - currentList.sum()\n// currentList.add(\n// when{\n// totalLeft > 9 -> 9\n// else -> totalLeft\n// }\n// )\n// }\n// if (currentList.size > m) return emptyList()\n//\n// while (currentList.size < m) {\n// currentList.add(0)\n// }\n// return currentList\n//}\n"}, {"source_code": "import kotlin.math.min\n\nfun main() {\n val (m, s) = readLine()!!.split(' ').map(String::toInt)\n if (m == 1 && s == 0) {\n println(\"0 0\")\n return\n }\n if (s == 0 || s > m * 9) {\n println(\"-1 -1\")\n return\n }\n var sum = s\n val maxX = List(m) {\n val x = min(sum, 9)\n sum -= x\n x\n }\n sum = s\n val minX = List(m) {index ->\n val x = if (index == m - 1) {\n sum\n } else {\n min(sum - 1, 9)\n }\n sum -= x\n x\n }.reversed()\n println(\"${minX.joinToString(\"\")} ${maxX.joinToString(\"\")}\")\n}"}, {"source_code": "fun main(args: Array) {\n val (m, s) = readLine()!!.split(' ').map { it.toInt() }\n\n if ((s==0 && m>1) || (m * 9 < s) ){\n println(\"-1 -1\")\n return\n }\n\n val arr = IntArray(m, {if (it == 0 && s > 0) 1 else 0})\n val arr2 = IntArray(m)\n\n for (i in 0 until m){\n var delta = s - 9 * i - 1\n if (delta <= 0) break\n arr[m - i - 1] = minOf(9, delta + if (i == m-1) 1 else 0)\n }\n\n\n for (i in 0 until m){\n var delta = s - 9 * i\n if (delta <= 0) break\n arr2[i] = minOf(9, delta)\n }\n\n\n\n\n println(\"${arr.joinToString(separator = \"\")} ${arr2.joinToString (separator = \"\")}\")\n}"}, {"source_code": "fun fill(array: Array, totalSum: Int): Int {\n var rem = totalSum\n for (i in 0 until array.size) {\n if (rem >= 9) {\n array[i] = 9\n rem -= 9\n }\n else {\n array[i] = rem\n return 0\n }\n }\n\n return rem\n}\n\nfun main(args: Array) {\n val (m, s) = readLine()!!.split(' ').map { it.toInt() }\n val max = Array(m, { 0 })\n\n if ((s == 0 && m > 1) || fill(max, s) != 0) {\n println(\"-1 -1\")\n return\n }\n\n val min = Array(m, { 0 })\n fill(min, s - 1)\n min[min.size - 1] += 1\n\n return println(\"${min.reversed().joinToString(separator = \"\")} ${max.joinToString(separator = \"\")}\")\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.pow\n\nfun main(){\n var scanner = Scanner(System.`in`)\n var m = scanner.nextInt()\n var s = scanner.nextInt()\n var min:String = \"\"\n var max:String = \"\"\n var lastNumberMax:Char\n if(m==1 && s==0) println(\"0 0\")\n else if(s==0 || m*9 = readLine()!!.split(\" \").map{ it.toInt() }\nfun findMin(m: Int, s: Int): String{\n val digits = (m-2 downTo 0).toMutableList()\n if (s > m * 9) return \"-1\"\n if(digits.size == 0) return \"$s\"\n val result = mutableListOf(max(1, s - 9*(m-1)))\n var auxS = s - result[0]\n var auxM = m - 1\n var index = 0\n while(auxM != 0 || auxS != 0){\n val value = max(0, auxS - 9 * digits[index])\n result.add(value)\n index ++\n auxS -= value\n auxM --\n if(auxM == 0) break\n }\n if(result.isEmpty() || auxM + auxS != 0){\n return \"-1\"\n }\n return result.joinToString(separator = \"\")\n}\nfun findMax(m: Int, s: Int): String{\n val digits = (9 downTo 0).toMutableList()\n var auxS = s\n var auxM = m\n val result = mutableListOf()\n var index = 0\n if( m == 1 && s <= 9)\n {\n return \"$s\"\n }\n while(auxM != 0 || auxS != 0){\n if(auxS - digits[index] >= 0){\n result.add(digits[index])\n auxS -= digits[index]\n auxM --\n }\n if(auxS < digits[index]){\n index ++\n }\n if(auxM == 0) break\n }\n if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0 || auxM + auxS != 0){\n return \"-1\"\n }\n return result.joinToString(separator = \"\")\n}\n\n\nfun main(){\n val (m, s) = readInts()\n\n println(\"${findMin(m, s)} ${findMax(m,s)}\")\n}"}, {"source_code": "\nfun main(){\n var input = readLine()!!.split(' ')\n val m = input[0].toInt()\n val s = input[1].toInt()\n if (m == 1 && s == 0){\n println(\"0 0\")\n return\n }\n\n if ((1 > s) || (s > 9 * m)){\n println(\"-1 -1\")\n return\n }\n\n var smallestNumberWithMDigits = CharArray(m){'0'}\n var greatestNumberWithMDigits = CharArray(m){'9'}\n smallestNumberWithMDigits[0] = '1'\n\n var startingIndex = m-1\n var digitSumVar = smallestNumberWithMDigits.sumBy { (it-'0') }\n while (digitSumVar + 9 <= s){\n digitSumVar += 9\n smallestNumberWithMDigits[startingIndex] = '9'\n startingIndex -= 1\n }\n\n while (digitSumVar < s){\n val current_digit = smallestNumberWithMDigits[startingIndex]\n smallestNumberWithMDigits[startingIndex] = current_digit + 1\n digitSumVar += 1\n if (current_digit == '8'){\n startingIndex -= 1\n }\n }\n\n\n startingIndex = m-1\n digitSumVar = greatestNumberWithMDigits.sumBy { (it-'0') }\n while (digitSumVar - 9 >= s){\n digitSumVar -= 9\n greatestNumberWithMDigits[startingIndex] = '0'\n startingIndex -= 1\n }\n\n while (digitSumVar > s){\n val currentDigit = greatestNumberWithMDigits[startingIndex]\n greatestNumberWithMDigits[startingIndex] = currentDigit - 1\n digitSumVar -= 1\n if (currentDigit == '1'){\n startingIndex -= 1\n }\n }\n\n println(\"${smallestNumberWithMDigits.joinToString(\"\")} ${greatestNumberWithMDigits.joinToString(\"\")}\");\n}\n\n"}, {"source_code": "import java.util.*\n\nfun findMin(n: Int, sum: Int): String {\n\n\tif ( sum == 0 ) return if ( n == 1 ) \"0\" else \"-1\"\n\tif ( sum > 9*n ) return \"-1\"\n\n\tval firstDigit = Math.max(1, sum - 9*(n-1))\n\tvar left = sum - firstDigit\n\n\tval r = StringBuilder()\n\tr.append ( firstDigit )\n\tfor ( i in n-2 downTo 0 ) {\n\t\tval d = Math.max ( 0, left - 9*i )\n\t\tr.append(d)\n\t\tleft -= d\n\t}\n\n\treturn r.toString()\n}\n\nfun findMax(n: Int, sum: Int): String {\n\n\tif ( sum == 0 ) return if ( n == 1 ) \"0\" else \"-1\"\n\tif ( sum > 9*n ) return \"-1\"\n\n\tval firstDigit = Math.min(9, sum)\n\tvar left = sum - firstDigit\n\n\tval r = StringBuilder()\n\tr.append(firstDigit)\n\tfor ( i in n-2 downTo 0 ) {\n\t\tval d = Math.min( 9, left )\n\t\tr.append(d)\n\t\tleft -= d\n\t}\n\n\treturn r.toString()\n}\n\nfun main(args : Array) {\n\tval scan = Scanner (System.`in`)\n\tval n = scan.nextInt()\n\tval sum = scan.nextInt()\n\n\tprintln ( findMin(n,sum) + \" \" + findMax(n, sum) )\n}"}, {"source_code": "import kotlin.math.min\n\n/* template start */\n// input\nprivate fun readString() = readLine()!!\nprivate fun readStrings() = readString().split(\" \")\nprivate fun readInt() = readString().toInt()\nprivate fun readDigits() = readString().map { it - '0' }\nprivate fun readInts() = readStrings().map { it.toInt() }\nprivate fun readLongs() = readStrings().map { it.toLong() }\n\n// output\nprivate fun T.print(map: (T) -> String = { it.toString() }) = println(map(this))\nprivate fun Iterable.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)\nprivate fun Array.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)\nprivate fun IntArray.print(sep: String? = null, map: ((Int) -> String)? = null) = asSequence().print(sep, map)\nprivate fun Sequence.print(sep: String? = null, map: ((T) -> String)? = null) =\n println(joinToString(sep ?: \"\", transform = map ?: { it.toString() }))\n\n// others\nprivate val Int.isEven: Boolean get() = this % 2 == 0\nprivate val Int.isOdd: Boolean get() = !this.isEven\nprivate fun queries(block: (Int) -> Unit) = repeat(readInt(), block)\n\n/* template end */\n\nfun main() {\n val (len, sum) = readInts()\n if (sum == 0) {\n if (len != 1) println(\"-1 -1\")\n else println(\"0 0\")\n } else if (len * 9 < sum) {\n println(\"-1 -1\")\n } else {\n val maxNum = buildString {\n var rem = sum\n repeat(len) {\n val next = min(rem, 9)\n append(next)\n rem -= next\n }\n }\n val minNum = mutableListOf()\n var rem = sum\n for (i in 0 until len) {\n if (rem > 1) {\n var next = min(rem - 1, 9)\n if (i == len - 1) {\n next++\n }\n minNum.add(0, next)\n rem -= next\n } else {\n if (i != len - 1)\n minNum.add(0, 0)\n else minNum.add(0, 1)\n }\n }\n\n println(\"${minNum.joinToString(\"\")} $maxNum\")\n }\n\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val (m, s) = reader.readLine().split(' ').map { it.toInt() }\n\n if (s == 0) {\n val answer = if (m == 1) 0 else -1\n println(\"$answer $answer\")\n return\n }\n\n val maxN = Array(m) { if (it == 0) 1 else 0 }\n val minN = Array(m) { if (it == 0) 1 else 0 }\n\n var maxNPtr = 0\n var minNPtr = minN.lastIndex\n\n try {\n repeat(s-1) {\n if (maxN[maxNPtr] == 9) { maxNPtr++ }\n if (minN[minNPtr] == 9) { minNPtr-- }\n\n maxN[maxNPtr]++\n minN[minNPtr]++\n }\n } catch (e: IndexOutOfBoundsException) {\n println(\"-1 -1\")\n return\n }\n\n println(\"${minN.joinToString(\"\")} ${maxN.joinToString(\"\")}\")\n}"}], "negative_code": [{"source_code": "import java.io.PrintWriter\nimport kotlin.math.min\n\n\nfun main() {\n io.apply {\n\n val (m, s) = int to int\n\n if (s <= 0 || s > m * 9)\n cout .. -1 .. -1 .. nl\n else {\n val str = CharArray(m) { '0' }\n str[0] = '1'\n var q = s - 1\n for (i in m - 1 downTo 0) {\n var d = min(9, q)\n str[i] = (str[i] + d)\n q -= d\n }\n cout .. String(str) .. \" \"\n str.fill('0')\n q = s\n for (i in 0 until m) {\n var d = min(9, q)\n str[i] = (str[i] + d)\n q -= d\n }\n cout .. String(str) .. nl\n }\n\n }.cout.flush()\n}\n\n// @formatter:off\nprivate val io = object {\n private val `in` = System.`in`\n private fun ll(): Long {\n var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }\n do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n\n }\n val int get() = ll().toInt(); val long get() = ll()\n fun ints(n: Int = int): IntArray { return IntArray(n) { int } }\n fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }\n val cout = PrintWriter(System.out); val nl = \"\\n\"\n private var buf = CharArray(32)\n private var bufSize = 32\n fun str(expect: Int = 32): String {\n var ix = 0\n var x: Int\n if (bufSize < expect)\n buf = CharArray(expect)\n do x = `in`.read() while (x < 33)\n do {\n if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }\n buf[ix++] = x.toChar()\n x = `in`.read()\n } while (x > 32)\n return java.lang.String.copyValueOf(buf, 0, ix)\n }\n operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(\" \") }; return this }\n operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }\n} // @formatter:on\n\n/* ----------- */\n\n"}, {"source_code": "import java.io.PrintWriter\nimport kotlin.math.min\n\n\nfun main() {\n io.apply {\n\n val (m, s) = int to int\n\n if (s == 0 && m == 1) {\n cout .. 0 .. 1 .. nl\n } else if (s <= 0 || s > m * 9)\n cout .. -1 .. -1 .. nl\n else {\n val str = CharArray(m) { '0' }\n str[0] = '1'\n var q = s - 1\n for (i in m - 1 downTo 0) {\n var d = min(9, q)\n str[i] = (str[i] + d)\n q -= d\n }\n cout .. String(str) .. \" \"\n str.fill('0')\n q = s\n for (i in 0 until m) {\n var d = min(9, q)\n str[i] = (str[i] + d)\n q -= d\n }\n cout .. String(str) .. nl\n }\n\n }.cout.flush()\n}\n\n// @formatter:off\nprivate val io = object {\n private val `in` = System.`in`\n private fun ll(): Long {\n var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }\n do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n\n }\n val int get() = ll().toInt(); val long get() = ll()\n fun ints(n: Int = int): IntArray { return IntArray(n) { int } }\n fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }\n val cout = PrintWriter(System.out); val nl = \"\\n\"\n private var buf = CharArray(32)\n private var bufSize = 32\n fun str(expect: Int = 32): String {\n var ix = 0\n var x: Int\n if (bufSize < expect)\n buf = CharArray(expect)\n do x = `in`.read() while (x < 33)\n do {\n if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }\n buf[ix++] = x.toChar()\n x = `in`.read()\n } while (x > 32)\n return java.lang.String.copyValueOf(buf, 0, ix)\n }\n operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(\" \") }; return this }\n operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }\n} // @formatter:on\n\n/* ----------- */\n\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val ms = br.readLine().split(\" \").map { it.toInt() }\n val m = ms[0]\n val s = ms[1]\n\n if (s == 0){\n println(\"-1 -1\")\n }else{\n\n if (s < 10){\n val num = s.toString() + \"0\".repeat(m - 1)\n println(\"$num $num\")\n } else if (s == 0 || m*9 < s){\n println(\"-1 -1\")\n } else{\n\n val d = 9 - (m*9 - s)\n val base = \"9\".repeat(m - 1)\n\n println(\"${d.toString() + base} ${base + d.toString()}\")\n\n }\n\n }\n\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val ms = br.readLine().split(\" \").map { it.toInt() }\n val m = ms[0]\n val s = ms[1]\n\n if (s == 0){\n println(if (m == 1) \"0 0\" else \"-1 -1\")\n }else{\n\n if (s < 10){\n if (m == 1){\n println(\"$s $s\")\n }else{\n val maxNum = s.toString() + \"0\".repeat(m - 1)\n val minNum = \"1\" + \"0\".repeat(m - 2) + (s - 1).toString()\n println(\"$minNum $maxNum\")\n }\n\n } else if (s == 0 || m*9 < s){\n println(\"-1 -1\")\n } else{\n\n val ans = getMinAndMax(m, s)\n\n println(\"${ans.first} ${ans.second}\")\n\n }\n\n }\n\n}\n\nfun getMinAndMax(m: Int, s: Int): Pair{\n val num9s = s / 9\n val missing = m - num9s\n val nines = \"9\".repeat(num9s)\n val minNum: String\n val maxNum: String\n\n val d = s - 9*num9s\n\n if (missing <= 1){\n minNum = d.toString() + nines\n maxNum = nines + d.toString()\n }else{\n val l = 1\n val h = (d - 1)\n val zeroes = \"0\".repeat(missing - 2)\n\n minNum = l.toString() + zeroes + h + nines\n maxNum = nines + max(l, h) + min(l, h) + zeroes\n }\n return Pair(minNum, maxNum)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val ms = br.readLine().split(\" \").map { it.toInt() }\n val m = ms[0]\n val s = ms[1]\n\n if (s == 0){\n println(if (m == 1) \"0 0\" else \"-1 -1\")\n }else{\n\n if (s < 10){\n val num = s.toString() + \"0\".repeat(m - 1)\n println(\"$num $num\")\n } else if (s == 0 || m*9 < s){\n println(\"-1 -1\")\n } else{\n\n val ans = getMinAndMax(m, s)\n\n println(\"${ans.first} ${ans.second}\")\n\n }\n\n }\n\n}\n\nfun getMinAndMax(m: Int, s: Int): Pair{\n val num9s = s / 9\n val missing = m - num9s\n val nines = \"9\".repeat(num9s)\n val minNum: String\n val maxNum: String\n\n val d = s - 9*num9s\n\n if (missing <= 1){\n minNum = d.toString() + nines\n maxNum = nines + d.toString()\n }else{\n val l = 1\n val h = (d - 1)\n val zeroes = \"0\".repeat(missing - 2)\n\n minNum = l.toString() + zeroes + h + nines\n maxNum = nines + max(l, h) + min(l, h) + zeroes\n }\n return Pair(minNum, maxNum)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val ms = br.readLine().split(\" \").map { it.toInt() }\n val m = ms[0]\n val s = ms[1]\n\n if (s == 0){\n println(\"-1 -1\")\n }else{\n\n if (s < 10){\n val num = s.toString() + \"0\".repeat(m - 1)\n println(\"$num $num\")\n } else if (s == 0 || m*9 < s){\n println(\"-1 -1\")\n } else{\n\n val ans = getMinAndMax(m, s)\n\n println(\"${ans.first} ${ans.second}\")\n\n }\n\n }\n\n}\n\nfun getMinAndMax(m: Int, s: Int): Pair{\n val num9s = s / 9\n val missing = m - num9s\n val nines = \"9\".repeat(num9s)\n val minNum: String\n val maxNum: String\n\n val d = s - 9*num9s\n\n if (missing <= 1){\n minNum = d.toString() + nines\n maxNum = nines + d.toString()\n }else{\n val l = 1\n val h = (d - 1)\n val zeroes = \"0\".repeat(missing - 2)\n\n minNum = l.toString() + zeroes + h + nines\n maxNum = nines + max(l, h) + min(l, h) + zeroes\n }\n return Pair(minNum, maxNum)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val ms = br.readLine().split(\" \").map { it.toInt() }\n val m = ms[0]\n val s = ms[1]\n\n if (s == 0){\n println(if (m == 1) \"0 0\" else \"-1 -1\")\n }else{\n\n if (s < 10){\n if (m == 1){\n println(\"$s $s\")\n }else{\n val maxNum = s.toString() + \"0\".repeat(m - 1)\n val minNum = \"1\" + \"0\".repeat(m - 2) + (s - 1).toString()\n println(\"$minNum $maxNum\")\n }\n\n } else if (s == 0 || m*9 < s){\n println(\"-1 -1\")\n } else{\n\n val ans = getMinAndMax(m, s)\n\n println(\"${ans.first} ${ans.second}\")\n\n }\n\n }\n\n}\n\nfun getMinAndMax(m: Int, s: Int): Pair{\n val num9s = s / 9\n val missing = m - num9s\n val nines = \"9\".repeat(num9s)\n val minNum: String\n val maxNum: String\n\n val d = s - 9*num9s\n\n if (missing == 0){\n minNum = nines\n maxNum = nines\n } else if (missing <= 1){\n minNum = d.toString() + nines\n maxNum = nines + d.toString()\n }else{\n val l = 1\n val h = (d - 1)\n val zeroes = \"0\".repeat(missing - 2)\n\n minNum = l.toString() + zeroes + h + nines\n maxNum = nines + d.toString() + zeroes + \"0\"\n }\n return Pair(minNum, maxNum)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val ms = br.readLine().split(\" \").map { it.toInt() }\n val m = ms[0]\n val s = ms[1]\n\n if (s == 0){\n println(if (m == 1) \"0 0\" else \"-1 -1\")\n }else{\n\n if (s < 10){\n if (m == 1){\n println(\"$s $s\")\n }else{\n val maxNum = s.toString() + \"0\".repeat(m - 1)\n val minNum = \"1\" + \"0\".repeat(m - 2) + (s - 1).toString()\n println(\"$minNum $maxNum\")\n }\n\n } else if (s == 0 || m*9 < s){\n println(\"-1 -1\")\n } else{\n\n val ans = getMinAndMax(m, s)\n\n println(\"${ans.first} ${ans.second}\")\n\n }\n\n }\n\n}\n\nfun getMinAndMax(m: Int, s: Int): Pair{\n val num9s = s / 9\n val missing = m - num9s\n val nines = \"9\".repeat(num9s)\n val minNum: String\n val maxNum: String\n\n val d = if (s - 9*num9s == 0) 9 else s - 9*num9s\n\n if (missing == 0){\n minNum = nines\n maxNum = nines\n } else if (missing <= 1){\n minNum = d.toString() + nines\n maxNum = nines + d.toString()\n }else{\n val l = 1\n val h = (d - 1)\n val zeroes = \"0\".repeat(missing - 2)\n\n minNum = l.toString() + zeroes + h + nines\n maxNum = nines + d.toString() + zeroes + \"0\"\n }\n return Pair(minNum, maxNum)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val ms = br.readLine().split(\" \").map { it.toInt() }\n val m = ms[0]\n val s = ms[1]\n\n if (s == 0){\n println(if (m == 1) \"0 0\" else \"-1 -1\")\n }else{\n\n if (s < 10){\n if (m == 1){\n println(\"$s $s\")\n }else{\n val maxNum = s.toString() + \"0\".repeat(m - 1)\n val minNum = \"1\" + \"0\".repeat(m - 2) + (s - 1).toString()\n println(\"$minNum $maxNum\")\n }\n\n } else if (s == 0 || m*9 < s){\n println(\"-1 -1\")\n } else{\n\n val ans = getMinAndMax(m, s)\n\n println(\"${ans.first} ${ans.second}\")\n\n }\n\n }\n\n}\n\nfun getMinAndMax(m: Int, s: Int): Pair{\n val num9s = s / 9\n val missing = m - num9s\n val nines = \"9\".repeat(num9s)\n val minNum: String\n val maxNum: String\n\n val d = s - 9*num9s\n\n if (missing == 0){\n minNum = nines\n maxNum = nines\n } else if (missing <= 1){\n minNum = d.toString() + nines\n maxNum = nines + d.toString()\n }else{\n val l = 1\n val h = (d - 1)\n val zeroes = \"0\".repeat(missing - 2)\n\n minNum = l.toString() + zeroes + h + nines\n maxNum = nines + max(l, h) + min(l, h) + zeroes\n }\n return Pair(minNum, maxNum)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val ms = br.readLine().split(\" \").map { it.toInt() }\n val m = ms[0]\n val s = ms[1]\n\n if (s == 0 || m*9 < s){\n println(\"-1 -1\")\n }else{\n\n val d = 9 - (m*9 - s)\n var min = d.toString()\n var max = \"\"\n\n for (i in 1 until m){\n min += '9'\n\n }\n\n for (i in 0 until m){\n if (i == m - 1) max += d.toString()\n else max += '9'\n }\n\n println(\"$min $max\")\n\n }\n}"}, {"source_code": "import java.util.*\n\nval noSolution = Pair(intArrayOf(-1), intArrayOf(-1))\n\nfun main(args: Array) {\n cf()\n}\n\nprivate fun cf() = with(Scanner(System.`in`)) {\n val m = nextInt()\n val s = nextInt()\n val (mi, ma) = run(m, s)\n\n print(mi.joinToString(\"\"))\n print(\" \")\n println(ma.joinToString(\"\"))\n}\n\nprivate fun run(m: Int, s: Int): Pair {\n if (m == 1 && s > 10) return noSolution\n if (m == 1) return Pair(intArrayOf(s), intArrayOf(s))\n if (s == 0) return noSolution\n\n var numOfNines = s / 9\n var rem = s % 9\n if (rem == 0) {\n rem = 9\n numOfNines--\n }\n\n if (numOfNines + 1 > m) return noSolution\n\n val ma = IntArray(m)\n for (i in 0 until numOfNines)\n ma[i] = 9\n ma[numOfNines] = rem\n\n val mi = ma.clone()\n if (numOfNines + 1 == m) {\n mi.reverse()\n } else {\n mi[mi.size - 1] = 1\n mi[numOfNines]--\n mi.reverse()\n }\n\n return Pair(mi, ma)\n}\n"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n val (length, sum) = readInts()\n val quotient = sum / 9\n var rest = sum % 9\n if (length == 1 && sum == 0) {\n print(\"0 0\")\n return\n }\n if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {\n print(\"-1 -1\")\n return\n }\n val sb1 = StringBuilder()\n for (i in 0 until quotient) sb1.append('9')\n sb1.append(rest)\n for (i in 0 until length - quotient - 1)\n sb1.append('0')\n val sb2 = StringBuilder()\n if (length > quotient + 1) {\n rest--\n sb2.append('1')\n for (i in 0 until length - quotient - 2) sb2.append('0')\n }\n sb2.append(rest)\n for (i in 0 until quotient) sb2.append('9')\n print(\"$sb2 $sb1\")\n}\n\n\n// Shorter Python solution: https://codeforces.com/contest/489/submission/41588741"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n val (length, sum) = readInts()\n val quotient = sum / 9\n var rest = sum % 9\n if (length == 1 && sum == 0) {\n print(\"0 0\")\n return\n }\n if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {\n print(\"-1 -1\")\n return\n }\n val sb1 = StringBuilder()\n for (i in 0 until quotient) sb1.append('9')\n if (quotient < length) sb1.append(rest)\n for (i in 0 until length - quotient - 1)\n sb1.append('0')\n val sb2 = StringBuilder()\n if (length > quotient + 1) {\n rest--\n sb2.append('1')\n for (i in 0 until length - quotient - 2) sb2.append('0')\n }\n if (quotient < rest) sb2.append(rest)\n for (i in 0 until quotient) sb2.append('9')\n print(\"$sb2 $sb1\")\n}\n\n\n// Shorter Python solution: https://codeforces.com/contest/489/submission/41588741"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n val (length, sum) = readInts()\n val quotient = sum / 9\n var rest = sum % 9\n if (length == 1 && sum == 0) {\n print(\"0 0\")\n return\n }\n if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {\n print(\"-1 -1\")\n return\n }\n val sb1 = StringBuilder()\n for (i in 0 until quotient) sb1.append('9')\n if (quotient < length) sb1.append(rest)\n for (i in 0 until length - quotient - 1)\n sb1.append('0')\n val sb2 = StringBuilder()\n if (length > quotient + 1) {\n rest--\n sb2.append('1')\n for (i in 0 until length - quotient - 2) sb2.append('0')\n }\n if (quotient < length) sb2.append(rest)\n for (i in 0 until quotient) sb2.append('9')\n print(\"$sb2 $sb1\")\n}\n\n\n// Shorter Python solution: https://codeforces.com/contest/489/submission/41588741"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n val (length, sum) = readInts()\n val quotient = sum / 9\n val rest = sum % 9\n if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {\n print(\"-1 -1\")\n return\n }\n val a = mutableListOf()\n for (i in 0 until quotient) a.add(9)\n if (rest != 0) a.add(rest)\n\n val sb1 = StringBuilder()\n for(element in a) sb1.append(element)\n for (i in 0 until length - a.size)\n sb1.append('0')\n val sb2 = StringBuilder()\n if(length > a.size) {\n a[a.lastIndex]--\n sb2.append('1')\n for(i in 0 until length - a.size - 1) sb2.append('0')\n }\n for(i in a.lastIndex downTo 0) sb2.append(a[i])\n print(\"$sb2 $sb1\")\n}\n"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n val (length, sum) = readInts()\n val quotient = sum / 9\n val rest = sum % 9\n if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {\n print(\"-1 -1\")\n return\n }\n val a = mutableListOf()\n for (i in 0 until quotient) a.add(9)\n if (rest != 0) a.add(rest)\n\n val sb = StringBuilder()\n for(element in a) sb.append(element)\n for (i in 0 until length - a.size)\n sb.append('0')\n sb.append(' ')\n if(length > a.size) {\n a[a.lastIndex]--\n sb.append('1')\n for(i in 0 until length - a.size - 1) sb.append('0')\n }\n for(i in a.lastIndex downTo 0) sb.append(a[i])\n print(sb)\n}\n"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n val (length, sum) = readInts()\n val quotient = sum / 9\n var rest = sum % 9\n if (length == 1 && sum == 0) {\n print(\"0 0\")\n return\n }\n if (length == 0 || sum == 0 || quotient > length || (quotient == length && rest != 0)) {\n print(\"-1 -1\")\n return\n }\n val sb1 = StringBuilder()\n for (i in 0 until quotient) sb1.append('9')\n if (quotient < length) sb1.append(rest)\n for (i in 0 until length - quotient - 1)\n sb1.append('0')\n val sb2 = StringBuilder()\n if (length > quotient + 1) {\n rest--\n if (rest < 0) rest = 8\n sb2.append('1')\n for (i in 0 until length - quotient - 2) sb2.append('0')\n }\n if (quotient < length) sb2.append(rest)\n for (i in 0 until quotient) sb2.append('9')\n print(\"$sb2 $sb1\")\n}\n\n\n// Shorter Python solution: https://codeforces.com/contest/489/submission/41588741"}, {"source_code": "// 7/7/2020 11:13 AM\n\n//package p489\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n findSumToN(403, 105)\n}\n\nfun findSumToN(m: Int, s: Int) {\n// findSumToN_recursive(m, s, listOf())\n printLeastAndGreatest(findSumToN_iterative(m, s))\n}\n\nfun printLeastAndGreatest(l: List) {\n if (l.isEmpty()) {\n println(\"-1 -1\")\n return\n }\n\n val theGreatest = l.toMutableList()\n val theLeast = l.toMutableList()\n\n for (i in theLeast.size-1 downTo 1) {\n if (theLeast[i] > 0) {\n val v = theLeast.removeAt(i)\n theLeast.add(0, v)\n break\n }\n }\n\n var pos = 1\n for (i in theLeast.size - 1 downTo 1) {\n val v = theLeast.removeAt(theLeast.size - 1)\n theLeast.add(pos, v)\n pos++\n }\n\n print(theLeast.fold(\"\", { acc, cur -> acc + cur.toString()}))\n print(\" \")\n println(theGreatest.fold(\"\", { acc, cur -> acc + cur.toString()}))\n\n\n}\n\nfun findSumToN_iterative(m: Int, s: Int) : List {\n var currentList = mutableListOf()\n while (currentList.sum() < s) {\n val totalLeft = s - currentList.sum()\n currentList.add(\n when{\n totalLeft > 9 -> 9\n else -> totalLeft\n }\n )\n }\n if (currentList.size > m) return emptyList()\n\n while (currentList.size < m) {\n currentList.add(0)\n }\n return currentList\n}\n\nfun findSumToN_recursive(m: Int, s: Int, numbersSoFar: List) : Unit {\n val currentTotal = numbersSoFar.sum()\n val nNumbers = numbersSoFar.size\n if (currentTotal > s || nNumbers > m)\n return\n else if (currentTotal == s) {\n var newNumbersSoFar = numbersSoFar.toMutableList()\n while (newNumbersSoFar.size < m) {\n newNumbersSoFar.add(0)\n }\n println(newNumbersSoFar)\n } else {\n val lastNum = if (numbersSoFar.isEmpty()) 9 else numbersSoFar.last()\n for (i in lastNum downTo 1) {\n val newNumbersSoFar = numbersSoFar.toMutableList()\n newNumbersSoFar.add(i)\n findSumToN_recursive(s, m, newNumbersSoFar)\n }\n }\n}"}, {"source_code": "// 7/7/2020 11:13 AM\n\n//package p489\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val (m, s) = readInts()\n findSumToN(m, s)\n}\n\nfun findSumToN(m: Int, s: Int) {\n// findSumToN_recursive(m, s, listOf())\n printLeastAndGreatest(findSumToN_iterative(m, s))\n}\n\nfun printLeastAndGreatest(l: List) {\n if (l.isEmpty()) {\n println(\"-1 -1\")\n return\n }\n\n val theGreatest = l.toMutableList()\n val theLeast = l.toMutableList()\n\n for (i in theLeast.size-1 downTo 1) {\n if (theLeast[i] > 0) {\n val v = theLeast.removeAt(i)\n theLeast.add(0, v)\n break\n }\n }\n\n var pos = 1\n for (i in theLeast.size - 1 downTo 1) {\n val v = theLeast.removeAt(theLeast.size - 1)\n theLeast.add(pos, v)\n pos++\n }\n\n print(theLeast.fold(\"\", { acc, cur -> acc + cur.toString()}))\n print(\" \")\n println(theGreatest.fold(\"\", { acc, cur -> acc + cur.toString()}))\n\n\n}\n\nfun findSumToN_iterative(m: Int, s: Int) : List {\n var currentList = mutableListOf()\n if (s <= 0 && m > 1) return currentList\n\n while (currentList.sum() < s) {\n val totalLeft = s - currentList.sum()\n currentList.add(\n when{\n totalLeft > 9 -> 9\n else -> totalLeft\n }\n )\n }\n if (currentList.size > m) return emptyList()\n\n while (currentList.size < m) {\n currentList.add(0)\n }\n return currentList\n}\n\nfun findSumToN_recursive(m: Int, s: Int, numbersSoFar: List) : Unit {\n val currentTotal = numbersSoFar.sum()\n val nNumbers = numbersSoFar.size\n if (currentTotal > s || nNumbers > m)\n return\n else if (currentTotal == s) {\n var newNumbersSoFar = numbersSoFar.toMutableList()\n while (newNumbersSoFar.size < m) {\n newNumbersSoFar.add(0)\n }\n println(newNumbersSoFar)\n } else {\n val lastNum = if (numbersSoFar.isEmpty()) 9 else numbersSoFar.last()\n for (i in lastNum downTo 1) {\n val newNumbersSoFar = numbersSoFar.toMutableList()\n newNumbersSoFar.add(i)\n findSumToN_recursive(s, m, newNumbersSoFar)\n }\n }\n}"}, {"source_code": "// 7/7/2020 11:13 AM\n\n//package p489\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val (m, s) = readInts()\n findSumToN(m, s)\n}\n\nfun findSumToN(m: Int, s: Int) {\n// findSumToN_recursive(m, s, listOf())\n printLeastAndGreatest(findSumToN_iterative(m, s))\n}\n\nfun printLeastAndGreatest(l: List) {\n if (l.isEmpty()) {\n println(\"-1 -1\")\n return\n }\n\n val theGreatest = l.toMutableList()\n val theLeast = l.toMutableList()\n\n for (i in theLeast.size-1 downTo 1) {\n if (theLeast[i] > 0) {\n val v = theLeast.removeAt(i)\n theLeast.add(0, v)\n break\n }\n }\n\n var pos = 1\n for (i in theLeast.size - 1 downTo 1) {\n val v = theLeast.removeAt(theLeast.size - 1)\n theLeast.add(pos, v)\n pos++\n }\n\n print(theLeast.fold(\"\", { acc, cur -> acc + cur.toString()}))\n print(\" \")\n println(theGreatest.fold(\"\", { acc, cur -> acc + cur.toString()}))\n\n\n}\n\nfun findSumToN_iterative(m: Int, s: Int) : List {\n var currentList = mutableListOf()\n if (s <= 0) return currentList\n\n while (currentList.sum() < s) {\n val totalLeft = s - currentList.sum()\n currentList.add(\n when{\n totalLeft > 9 -> 9\n else -> totalLeft\n }\n )\n }\n if (currentList.size > m) return emptyList()\n\n while (currentList.size < m) {\n currentList.add(0)\n }\n return currentList\n}\n\nfun findSumToN_recursive(m: Int, s: Int, numbersSoFar: List) : Unit {\n val currentTotal = numbersSoFar.sum()\n val nNumbers = numbersSoFar.size\n if (currentTotal > s || nNumbers > m)\n return\n else if (currentTotal == s) {\n var newNumbersSoFar = numbersSoFar.toMutableList()\n while (newNumbersSoFar.size < m) {\n newNumbersSoFar.add(0)\n }\n println(newNumbersSoFar)\n } else {\n val lastNum = if (numbersSoFar.isEmpty()) 9 else numbersSoFar.last()\n for (i in lastNum downTo 1) {\n val newNumbersSoFar = numbersSoFar.toMutableList()\n newNumbersSoFar.add(i)\n findSumToN_recursive(s, m, newNumbersSoFar)\n }\n }\n}"}, {"source_code": "// 7/7/2020 11:13 AM\n\n//package p489\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val (m, s) = readInts()\n// findSumToN(m, s)\n printResult(findSmallest(m, s))\n print(\" \")\n printResult(findLargest(m, s))\n println()\n}\n\nfun findLargest(m: Int, s: Int) : List {\n if (s <= 0) return listOf()\n\n var sumLeft = s\n val outputList = MutableList(m) {0}\n var idx = 0\n while (sumLeft > 0 && idx < m) {\n outputList[idx] = if (sumLeft >= 9) 9 else sumLeft\n sumLeft -= outputList[idx++]\n }\n if (sumLeft > 0)\n return listOf()\n else\n return outputList.toList()\n}\n\nfun findSmallest(m: Int, s: Int) : List {\n if (s <= 0) return listOf()\n\n var sumLeft = s\n val outputList = MutableList(m) {0}\n\n val minFirst = s - 9 * (m - 1)\n\n if (minFirst <= 1)\n outputList[0] = 1\n else if (minFirst > 9)\n return listOf()\n else\n outputList[0] = minFirst\n\n sumLeft -= outputList[0]\n\n var idx = m - 1\n while (sumLeft > 0 && idx > 0) {\n outputList[idx] = if (sumLeft >= 9) 9 else sumLeft\n sumLeft -= outputList[idx--]\n }\n if (sumLeft > 0)\n return listOf()\n else\n return outputList.toList()\n}\n\nfun printResult(l: List) {\n if (l.isEmpty())\n print(\"-1\")\n else\n print(l.fold(\"\", {acc, cur -> acc + cur.toString()}))\n}\n\n//fun findSumToN(m: Int, s: Int) {\n//// findSumToN_recursive(m, s, listOf())\n// printLeastAndGreatest(findSumToN_iterative(m, s))\n//}\n//\n//fun printLeastAndGreatest(l: List) {\n// if (l.isEmpty()) {\n// println(\"-1 -1\")\n// return\n// }\n//\n// val theGreatest = l.toMutableList()\n// val theLeast = l.toMutableList()\n//\n// for (i in theLeast.size-1 downTo 1) {\n// if (theLeast[i] > 0) {\n// val v = theLeast.removeAt(i)\n// theLeast.add(0, v)\n// break\n// }\n// }\n//\n// var pos = 1\n// for (i in theLeast.size - 1 downTo 1) {\n// val v = theLeast.removeAt(theLeast.size - 1)\n// theLeast.add(pos, v)\n// pos++\n// }\n//\n// print(theLeast.fold(\"\", { acc, cur -> acc + cur.toString()}))\n// print(\" \")\n// println(theGreatest.fold(\"\", { acc, cur -> acc + cur.toString()}))\n//\n//\n//}\n//\n//fun findSumToN_iterative(m: Int, s: Int) : List {\n// var currentList = mutableListOf()\n// if (s <= 0 && m > 1) return currentList\n//\n// while (currentList.sum() < s) {\n// val totalLeft = s - currentList.sum()\n// currentList.add(\n// when{\n// totalLeft > 9 -> 9\n// else -> totalLeft\n// }\n// )\n// }\n// if (currentList.size > m) return emptyList()\n//\n// while (currentList.size < m) {\n// currentList.add(0)\n// }\n// return currentList\n//}\n"}, {"source_code": "import kotlin.math.min\n\nfun main() {\n val (m, s) = readLine()!!.split(' ').map(String::toInt)\n if (s == 0 || s > m * 9) {\n println(\"-1 -1\")\n return\n }\n var sum = s\n val maxX = List(m) {\n val x = min(sum, 9)\n sum -= x\n x\n }\n sum = s\n val minX = List(m) {index ->\n val x = if (index == m - 1) {\n sum\n } else {\n min(sum - 1, 9)\n }\n sum -= x\n x\n }.reversed()\n println(\"${minX.joinToString(\"\")} ${maxX.joinToString(\"\")}\")\n}"}, {"source_code": "fun main(args: Array) {\n val (m, s) = readLine()!!.split(' ').map { it.toInt() }\n (1 .. 900)\n .map { it.toString() }\n .filter { it.length == m && it.map { it - '0' }.sum() == s }\n .let { println(if (it.isEmpty()) \"-1 -1\" else \"${it.first()} ${it.last()}\") }\n}"}, {"source_code": "fun main(args: Array) {\n val (m, s) = readLine()!!.split(' ').map { it.toInt() }\n\n if ((s==0 && m>1) || (m * 9 < s) ){\n println(\"-1 -1\")\n return\n }\n\n val arr = IntArray(m, {if (it == 0) 1 else 0})\n val arr2 = IntArray(m)\n\n for (i in 0 until m){\n var delta = s - 9 * i - 1\n if (delta <= 0) break\n arr[m - i - 1] = minOf(9, delta + if (i == m-1) 1 else 0)\n }\n\n\n for (i in 0 until m){\n var delta = s - 9 * i\n if (delta <= 0) break\n arr2[i] = minOf(9, delta)\n }\n\n\n\n\n println(\"${arr.joinToString(separator = \"\")} ${arr2.joinToString (separator = \"\")}\")\n}"}, {"source_code": "fun main(args: Array) {\n val (m, s) = readLine()!!.split(' ').map { it.toInt() }\n val arr = IntArray(m, {if (it == 0) 1 else 0})\n val arr2 = IntArray(m)\n\n for (i in 0 until m){\n var delta = s - 9 * i - 1\n if (delta <= 0) break\n arr[m - i - 1] = minOf(9, delta + if (i == m-1) 1 else 0)\n\n delta ++\n arr2[i] = minOf(9, delta)\n }\n\n println(\"${arr.joinToString(separator = \"\")} ${arr2.joinToString (separator = \"\")}\")\n}"}, {"source_code": "fun main(args: Array) {\n val (m, s) = readLine()!!.split(' ').map { it.toInt() }\n\n if ( s == 0 || 18 * m < s) {\n println(\"-1 -1\")\n return\n }\n\n\n (1..s * 10).map { \"$it\" }\n .first { it.sumBy { it - '0' } == s }\n .let {\n print(\"$it${\"0\".repeat(m - it.length)} \")\n for (i in 0 until m) {\n print(maxOf(minOf(s - 9 * i, 9), 0))\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val (m, s) = readLine()!!.split(' ').map { it.toInt() }\n\n if ( s == 0 || 9 * m < s) {\n println(\"-1 -1\")\n }else{\n with(StringBuilder()){\n (0 until m)\n .takeWhile { s - 9 * it > 0 }\n .forEach { this.append(minOf(9,s-9 * it))}\n\n val res = this.toString().reversed()\n val z = \"0\".repeat(m - res.length)\n print(\"${res.first()}$z${res.removeRange(0,1)} \")\n print(\"${res.reversed()}$z\")\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val (m, s) = readLine()!!.split(' ').map { it.toInt() }\n\n if ( (s == 0 && m > 1) || 9 * m < s) {\n println(\"-1 -1\")\n }else{\n with(StringBuilder()){\n (0 until m)\n .takeWhile { s - 9 * it > 0 }\n .forEach { this.append(minOf(9,s-9 * it))}\n\n if (this.isEmpty()) this.append(0)\n\n val res = this.toString().reversed()\n val z = \"0\".repeat(m - res.length)\n print(\"${res.first()}$z${res.removeRange(0,1)} \")\n print(\"${res.reversed()}$z\")\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val (m, s) = readLine()!!.split(' ').map { it.toInt() }\n\n (1..100).map { it.toString() }\n .filter { it.length == m && it.sumBy { it - '0' } == s }\n .let {\n println(if (it.isEmpty()) -1 else \"${it.first()} ${it.last()}\")\n }\n}"}, {"source_code": "fun main(args: Array) {\n val (m, s) = readLine()!!.split(' ').map { it.toInt() }\n\n if ( s == 0 || 9 * m < s) {\n println(\"-1 -1\")\n }else{\n with(StringBuilder()){\n (0 until m)\n .takeWhile { m - 9 * it > 0 }\n .forEach { this.append(minOf(9,m-9 * it))}\n val res = this.toString().reversed()\n val z = \"0\".repeat(m - res.length)\n print(\"${res.first()}$z${res.removeRange(0,1)} \")\n print(\"${res.reversed()}$z\")\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val (m, s) = readLine()!!.split(' ').map { it.toInt() }\n\n (1..100).map { it.toString() }\n .filter { it.length == m && it.sumBy { it - '0' } == s }\n .let {\n println(if (it.isEmpty()) \"-1 -1\" else \"${it.first()} ${it.last()}\")\n }\n}"}, {"source_code": "fun main(args: Array) {\n val (m, s) = readLine()!!.split(' ').map { it.toInt() }\n\n if ((s==0 && m>1) || (m * 9 < s) ){\n println(\"-1 -1\")\n return\n }\n\n val arr = IntArray(m, {if (it == 0) 1 else 0})\n val arr2 = IntArray(m)\n\n for (i in 0 until m){\n var delta = s - 9 * i - 1\n if (delta <= 0) break\n arr[m - i - 1] = minOf(9, delta + if (i == m-1) 1 else 0)\n\n delta ++\n arr2[i] = minOf(9, delta)\n }\n\n println(\"${arr.joinToString(separator = \"\")} ${arr2.joinToString (separator = \"\")}\")\n}"}, {"source_code": "fun fill(array: Array, totalSum: Int): Int {\n var rem = totalSum\n for (i in 0 until array.size) {\n if (rem >= 9) {\n array[i] = 9\n rem -= 9\n }\n else {\n array[i] = rem\n return 0\n }\n }\n\n return rem\n}\n\nfun main(args: Array) {\n val (m, s) = readLine()!!.split(' ').map { it.toInt() }\n val max = Array(m, { 0 })\n\n if (s == 0 || fill(max, s) != 0) {\n println(\"-1 -1\")\n return\n }\n\n val min = Array(m, { 0 })\n fill(min, s - 1)\n min[min.size - 1] += 1\n\n return println(\"${min.reversed().joinToString(separator = \"\")} ${max.joinToString(separator = \"\")}\")\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.pow\n\nfun main(){\n var scanner = Scanner(System.`in`)\n var m = scanner.nextInt()\n var s = scanner.nextInt()\n var min:String = \"\"\n var max:String = \"\"\n var lastNumberMax:Char\n if(s==0) println(\"-1 -1\")\n else {\n while(s!=0){\n for(i in 9 downTo 1){\n if(i<=s){\n max += i\n s-=i\n break;\n }\n }\n }\n lastNumberMax = max[max.lastIndex]\n while(max.length != m) max+='0'\n if(max[max.length-1] != '0') min = max.reversed()\n else{\n min = max.reversed()\n min = \"1${min.substring(1,min.length)}\"\n var minChar = min.toCharArray()\n for(i in 1 until minChar.size){\n if(minChar[i] == lastNumberMax){\n println(minChar[i])\n minChar[i] = (lastNumberMax.toInt() -1).toChar()\n break\n }\n }\n min = String(minChar)\n }\n println(\"$min $max\")\n }\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.pow\n\nfun main(){\n var scanner = Scanner(System.`in`)\n var m = scanner.nextInt()\n var s = scanner.nextInt()\n var min:String = \"\"\n var max:String = \"\"\n var lastNumberMax:Char\n if(s==0 || m*9 = readLine()!!.split(\" \").map{ it.toInt() }\n\nfun main(){\n var (m, s) = readInts()\n val digits = (9 downTo 0).toMutableList()\n val result = mutableListOf()\n var index = 0\n if( m == 1 && s <= 9)\n {\n println(\"$s $s\")\n return\n }\n while(m != 0 || s != 0){\n if(s - digits[index] >= 0){\n result.add(digits[index])\n s -= digits[index]\n m --\n }\n if(s < digits[index]){\n index ++\n }\n if(m == 0) break\n }\n if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0 || m + s != 0){\n println(\"-1 -1\")\n return\n }\n val resultStringHigh = result.joinToString(separator = \"\")\n val resultStringLow = if(resultStringHigh[resultStringHigh.lastIndex]!='0'){\n resultStringHigh.reversed()\n }\n else{\n val aux = StringBuilder()\n aux.append(resultStringHigh.reversed())\n aux[0] = aux.first { it != '0' }.also { aux[aux.indexOfFirst { it != '0' }]= aux[0] }\n aux.toString()\n }\n println(\"$resultStringLow $resultStringHigh\")\n}"}, {"source_code": "fun readInts(): List = readLine()!!.split(\" \").map{ it.toInt() }\n\nfun main(){\n var (m, s) = readInts()\n val digits = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9).sortedDescending().toMutableList()\n val result = mutableListOf()\n while(m != 0 || s != 0){\n for(it in digits) {\n if( s - it >= 0){\n s -= it\n result.add(it)\n digits.remove(it)\n break\n }\n }\n m --\n }\n if(result.isEmpty()){\n println(\"-1 -1\")\n return\n }\n val resultString = result.joinToString(separator = \"\")\n print(resultString.reversed() + \" \" + resultString)\n}"}, {"source_code": "fun readInts(): List = readLine()!!.split(\" \").map{ it.toInt() }\n\nfun main(){\n var (m, s) = readInts()\n val digits = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).sortedDescending().toMutableList()\n val result = mutableListOf()\n while(m != 0 || s != 0){\n for(it in digits) {\n if( s - it >= 0){\n s -= it\n result.add(it)\n digits.remove(it)\n break\n }\n }\n m --\n }\n if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0){\n println(\"-1 -1\")\n return\n }\n val resultString = result.joinToString(separator = \"\")\n print(if(resultString[0]!='0') \"${resultString.reversed()} $resultString\"\n else \"$resultString $resultString\")\n}"}, {"source_code": "\nfun main(){\n var input = readLine()!!.split(' ')\n val m = input[0].toInt()\n val s = input[1].toInt()\n if (m == 1 && s == 0){\n println(\"0 0\")\n return\n }\n\n if ((1 > s) || (s > 9 * m)){\n println(\"-1 1\")\n return\n }\n\n var smallestNumberWithMDigits = CharArray(m){'0'}\n var greatestNumberWithMDigits = CharArray(m){'9'}\n smallestNumberWithMDigits[0] = '1'\n\n var startingIndex = m-1\n var digitSumVar = smallestNumberWithMDigits.sumBy { (it-'0') }\n while (digitSumVar + 9 <= s){\n digitSumVar += 9\n smallestNumberWithMDigits[startingIndex] = '9'\n startingIndex -= 1\n }\n\n while (digitSumVar < s){\n val current_digit = smallestNumberWithMDigits[startingIndex]\n smallestNumberWithMDigits[startingIndex] = current_digit + 1\n digitSumVar += 1\n if (current_digit == '8'){\n startingIndex -= 1\n }\n }\n\n\n startingIndex = m-1\n digitSumVar = greatestNumberWithMDigits.sumBy { (it-'0') }\n while (digitSumVar - 9 >= s){\n digitSumVar -= 9\n greatestNumberWithMDigits[startingIndex] = '0'\n startingIndex -= 1\n }\n\n while (digitSumVar > s){\n val current_digit = greatestNumberWithMDigits[startingIndex]\n greatestNumberWithMDigits[startingIndex] = current_digit - 1\n digitSumVar -= 1\n if (current_digit == '1'){\n startingIndex -= 1\n }\n }\n\n println(\"${smallestNumberWithMDigits.joinToString(\"\")} ${greatestNumberWithMDigits.joinToString(\"\")}\");\n}\n\n"}, {"source_code": "fun readInts(): List = readLine()!!.split(\" \").map{ it.toInt() }\n\nfun main(){\n var (m, s) = readInts()\n val digits = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).sortedDescending().toMutableList()\n val result = mutableListOf()\n while(m != 0 || s != 0){\n for(it in digits) {\n if( s - it >= 0){\n s -= it\n result.add(it)\n digits.remove(it)\n break\n }\n }\n m --\n }\n if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0){\n println(\"-1 -1\")\n return\n }\n val resultString = result.joinToString(separator = \"\")\n println(if(resultString[resultString.lastIndex]!='0') \"${resultString.reversed()} $resultString\"\n else \"$resultString $resultString\")\n}"}, {"source_code": "import kotlin.math.max\n\nfun readInts(): List = readLine()!!.split(\" \").map{ it.toInt() }\nfun findMin(m: Int, s: Int): String{\n val digits = (m-2 downTo 0).toMutableList()\n val result = mutableListOf(max(1, s - 9*(m-1)))\n var auxS = s - result[0]\n var auxM = m - 1\n var index = 0\n while(auxM != 0 || auxS != 0){\n val value = max(0, auxS - 9 * digits[index])\n result.add(value)\n index ++\n auxS -= value\n auxM --\n if(auxM == 0) break\n }\n if(result.isEmpty() || auxM + auxS != 0){\n return \"-1\"\n }\n return result.joinToString(separator = \"\")\n}\nfun findMax(m: Int, s: Int): String{\n val digits = (9 downTo 0).toMutableList()\n var auxS = s\n var auxM = m\n val result = mutableListOf()\n var index = 0\n if( m == 1 && s <= 9)\n {\n return \"$s\"\n }\n while(auxM != 0 || auxS != 0){\n if(auxS - digits[index] >= 0){\n result.add(digits[index])\n auxS -= digits[index]\n auxM --\n }\n if(auxS < digits[index]){\n index ++\n }\n if(auxM == 0) break\n }\n if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0 || auxM + auxS != 0){\n return \"-1\"\n }\n return result.joinToString(separator = \"\")\n}\n\n\nfun main(){\n val (m, s) = readInts()\n\n println(\"${findMin(m, s)} ${findMax(m,s)}\")\n}"}, {"source_code": "fun readInts(): List = readLine()!!.split(\" \").map{ it.toInt() }\n\nfun main(){\n var (m, s) = readInts()\n val digits = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).sortedDescending().toMutableList()\n val result = mutableListOf()\n while(m != 0 || s != 0){\n for(it in digits) {\n if( s - it >= 0){\n s -= it\n result.add(it)\n digits.remove(it)\n break\n }\n }\n m --\n }\n if(result.isEmpty()){\n println(\"-1 -1\")\n return\n }\n val resultString = result.joinToString(separator = \"\")\n print(if(resultString[0]!='0') \"${resultString.reversed()} $resultString\"\n else \"$resultString $resultString\")\n}"}, {"source_code": "fun readInts(): List = readLine()!!.split(\" \").map{ it.toInt() }\n\nfun main(){\n var (m, s) = readInts()\n val digits = (9 downTo 0).toMutableList()\n val result = mutableListOf()\n var index = 0\n while(m != 0 || s != 0){\n if(s - digits[index] >= 0){\n if (digits[index] == 0 && result.isEmpty()) break\n result.add(digits[index])\n s -= digits[index]\n m --\n }\n if(s < digits[index]){\n index ++\n }\n if(m == 0) break\n }\n if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0 || m + s != 0){\n println(\"-1 -1\")\n return\n }\n val resultStringHigh = result.joinToString(separator = \"\")\n val resultStringLow = if(resultStringHigh[resultStringHigh.lastIndex]!='0'){\n resultStringHigh.reversed()\n }\n else{\n val aux = StringBuilder()\n aux.append(resultStringHigh.reversed())\n aux[0] = aux.first { it != '0' }.also { aux[aux.indexOfFirst { it != '0' }]= aux[0] }\n aux.toString()\n }\n println(\"$resultStringLow $resultStringHigh\")\n}"}, {"source_code": "fun readInts(): List = readLine()!!.split(\" \").map{ it.toInt() }\n\nfun main(){\n var (m, s) = readInts()\n val digits = (9 downTo 0).toMutableList()\n val result = mutableListOf()\n var index = 0\n while(m != 0 || s != 0){\n if(s - digits[index] >= 0){\n result.add(digits[index])\n s -= digits[index]\n m --\n }\n if(s < digits[index]){\n index ++\n }\n if(m == 0) break\n }\n if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0 || m + s != 0){\n println(\"-1 -1\")\n return\n }\n val resultStringHigh = result.joinToString(separator = \"\")\n val resultStringLow = if(resultStringHigh[resultStringHigh.lastIndex]!='0'){\n resultStringHigh.reversed()\n }\n else{\n val aux = StringBuilder()\n aux.append(resultStringHigh.reversed())\n aux[0] = aux.first { it != '0' }.also { aux[aux.indexOfFirst { it != '0' }]= aux[0] }\n aux.toString()\n }\n println(\"$resultStringLow $resultStringHigh\")\n}"}, {"source_code": "fun readInts(): List = readLine()!!.split(\" \").map{ it.toInt() }\n\nfun main(){\n var (m, s) = readInts()\n val digits = (9 downTo 0).toMutableList()\n val result = mutableListOf()\n var index = 0\n while(m != 0 && s != 0){\n if(s - digits[index] >= 0){\n if (digits[index] == 0 && digits.isEmpty()) break\n result.add(digits[index])\n s -= digits[index]\n m --\n }\n if(s < digits[index]){\n index ++\n }\n }\n if(result.isEmpty() || result.reduce{acc: Int, i: Int -> acc+i } == 0 || m + s != 0){\n println(\"-1 -1\")\n return\n }\n val resultStringHigh = result.joinToString(separator = \"\")\n val resultStringLow = if(resultStringHigh[resultStringHigh.lastIndex]!='0'){\n resultStringHigh.reversed()\n }\n else{\n val aux = StringBuilder()\n aux.append(resultStringHigh.reversed())\n aux[0] = aux.first { it != '0' }.also { aux[aux.indexOfFirst { it != '0' }]= aux[0] }\n aux.toString()\n }\n println(\"$resultStringLow $resultStringHigh\")\n}"}, {"source_code": "fun readInts(): List = readLine()!!.split(\" \").map{ it.toInt() }\n\nfun main(){\n var (m, s) = readInts()\n val digits = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).sortedDescending().toMutableList()\n val result = mutableListOf()\n while(m != 0 || s != 0){\n for(it in digits) {\n if( s - it >= 0){\n s -= it\n result.add(it)\n digits.remove(it)\n break\n }\n }\n m --\n }\n if(result.isEmpty()){\n println(\"-1 -1\")\n return\n }\n val resultString = result.joinToString(separator = \"\")\n print(if(resultString[resultString.lastIndex]!='0') \"${resultString.reversed()} $resultString\"\n else \"$resultString $resultString\")\n}"}, {"source_code": "import java.util.*\n\nfun findMin(n: Int, sum: Int): String {\n\n\tif ( sum == 0 ) return if ( n == 1 ) \"0\" else \"-1\"\n\tif ( sum > 9*n ) return \"-1\"\n\n\tval firstDigit = Math.max(1, sum - 9*(n-1))\n\tvar left = sum - firstDigit\n\n\tval r = StringBuilder()\n\tr.append ( firstDigit )\n\tfor ( i in n-2 downTo 0 ) {\n\t\tval d = Math.max ( 0, left - 9*i )\n\t\tr.append(d)\n\t\tleft -= d\n\t}\n\n\treturn r.toString()\n}\n\nfun findMax(n: Int, sum: Int): String {\n\n\tif ( sum == 0 ) return if ( n == 1 ) \"0\" else \"-1\"\n\tif ( sum > 9*n ) return \"-1\"\n\n\tval firstDigit = Math.min(9, sum)\n\tvar left = sum - firstDigit\n\n\tval r = StringBuilder()\n\tr.append(firstDigit)\n\tfor ( i in n-2 downTo 0 ) {\n\t\tval d = Math.min( 9, left )\n\t\tr.append(d)\n\t\tleft -= d\n\t}\n\n\treturn r.toString()\n}\n\nfun main(args : Array) {\n\tval scan = Scanner (System.`in`)\n\tval n = scan.nextInt()\n\tval sum = scan.nextInt()\n\n\tval minSum = if ( n == 1 ) 0 else n\n\tval maxSum = n*9\n\n\tif ( sum < minSum || sum > maxSum ) {\n\t\tprintln(\"-1 -1\")\n\t\treturn\n\t}\n\n\tprintln ( findMin(n,sum) + \" \" + findMax(n, sum) )\n}"}, {"source_code": "import java.util.*\n\nfun findMin(n: Int, sum: Int): String {\n\n\tif ( sum == 0 ) return if ( n == 1 ) \"0\" else \"-1\"\n\tif ( sum > 9*n ) return \"-1\"\n\n\tval firstDigit = Math.max(1, sum - 9*(n-1))\n\tvar left = sum - firstDigit\n\n\tval r = StringBuilder()\n\tr.append ( firstDigit )\n\tfor ( i in n-2 downTo 0 ) {\n\t\tval d = Math.max ( 0, left - 9*i )\n\t\tr.append(d)\n\t\tleft -= d\n\t}\n\n\treturn r.toString()\n}\n\nfun findMax(n: Int, sum: Int): String {\n\n\tif ( sum == 0 ) return if ( n == 1 ) \"0\" else \"-1\"\n\tif ( sum > 9*n ) return \"-1\"\n\n\tval firstDigit = Math.min(9, sum)\n\tvar left = sum - firstDigit\n\n\tval r = StringBuilder()\n\tr.append(firstDigit)\n\tfor ( i in n-2 downTo 0 ) {\n\t\tval d = Math.min( 9, sum )\n\t\tr.append(d)\n\t\tleft -= d\n\t}\n\n\treturn r.toString()\n}\n\nfun main(args : Array) {\n\tval scan = Scanner (System.`in`)\n\tval n = scan.nextInt()\n\tval sum = scan.nextInt()\n\n\tval minSum = if ( n == 1 ) 0 else n\n\tval maxSum = n*9\n\n\tif ( sum < minSum || sum > maxSum ) {\n\t\tprintln(\"-1 -1\")\n\t\treturn\n\t}\n\n\tprintln ( findMin(n,sum) + \" \" + findMax(n, sum) )\n}"}, {"source_code": "import kotlin.math.min\n\n/* template start */\n// input\nprivate fun readString() = readLine()!!\nprivate fun readStrings() = readString().split(\" \")\nprivate fun readInt() = readString().toInt()\nprivate fun readDigits() = readString().map { it - '0' }\nprivate fun readInts() = readStrings().map { it.toInt() }\nprivate fun readLongs() = readStrings().map { it.toLong() }\n\n// output\nprivate fun T.print(map: (T) -> String = { it.toString() }) = println(map(this))\nprivate fun Iterable.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)\nprivate fun Array.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)\nprivate fun IntArray.print(sep: String? = null, map: ((Int) -> String)? = null) = asSequence().print(sep, map)\nprivate fun Sequence.print(sep: String? = null, map: ((T) -> String)? = null) =\n println(joinToString(sep ?: \"\", transform = map ?: { it.toString() }))\n\n// others\nprivate val Int.isEven: Boolean get() = this % 2 == 0\nprivate val Int.isOdd: Boolean get() = !this.isEven\nprivate fun queries(block: (Int) -> Unit) = repeat(readInt(), block)\n\n/* template end */\n\nfun main() {\n val (len, sum) = readInts()\n if (sum == 0) {\n if (len != 1) println(\"-1 -1\")\n else println(\"0 0\")\n } else if (len * 9 < sum) {\n println(\"-1 -1\")\n } else {\n val maxNum = buildString {\n var rem = sum\n repeat(len) {\n val next = min(rem, 9)\n append(next)\n rem -= next\n }\n }\n var minNum = 0\n var factor = 1\n var rem = sum\n for (i in 0 until len) {\n if (rem > 1) {\n var next = min(rem - 1, 9)\n if (i == len - 1 && next < 9) {\n next++\n }\n minNum += next * factor\n factor *= 10\n rem -= next\n } else {\n if (i == len - 1)\n minNum += factor\n factor *= 10\n }\n }\n\n println(\"$minNum $maxNum\")\n }\n\n}\n"}], "src_uid": "75d062cece5a2402920d6706c655cad7"} {"nl": {"description": "You have $$$n$$$ coins, each of the same value of $$$1$$$.Distribute them into packets such that any amount $$$x$$$ ($$$1 \\leq x \\leq n$$$) can be formed using some (possibly one or all) number of these packets.Each packet may only be used entirely or not used at all. No packet may be used more than once in the formation of the single $$$x$$$, however it may be reused for the formation of other $$$x$$$'s.Find the minimum number of packets in such a distribution.", "input_spec": "The only line contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 10^9$$$) — the number of coins you have.", "output_spec": "Output a single integer — the minimum possible number of packets, satisfying the condition above.", "sample_inputs": ["6", "2"], "sample_outputs": ["3", "2"], "notes": "NoteIn the first example, three packets with $$$1$$$, $$$2$$$ and $$$3$$$ coins can be made to get any amount $$$x$$$ ($$$1\\leq x\\leq 6$$$). To get $$$1$$$ use the packet with $$$1$$$ coin. To get $$$2$$$ use the packet with $$$2$$$ coins. To get $$$3$$$ use the packet with $$$3$$$ coins. To get $$$4$$$ use packets with $$$1$$$ and $$$3$$$ coins. To get $$$5$$$ use packets with $$$2$$$ and $$$3$$$ coins To get $$$6$$$ use all packets. In the second example, two packets with $$$1$$$ and $$$1$$$ coins can be made to get any amount $$$x$$$ ($$$1\\leq x\\leq 2$$$)."}, "positive_code": [{"source_code": "import java.io.*\nimport java.lang.Math.abs\nimport java.util.*\nimport kotlin.math.log2\nimport kotlin.math.max\nimport kotlin.math.sqrt\n\nfun main(args : Array) = Thread { run() }.start()\nval scanner = Scanner(System.`in`)\n\nfun run() {\n\n var n = scanner.nextInt()\n var q = 0\n while (n > 0) {\n q++\n n /= 2\n }\n println(q)\n\n}\n\nclass Parser(`in`: InputStream) {\n private val BUFFER_SIZE = 1 shl 16\n private val din: DataInputStream\n private val buffer: ByteArray\n private var bufferPointer: Int = 0\n private var bytesRead: Int = 0\n\n init {\n din = DataInputStream(`in`)\n buffer = ByteArray(BUFFER_SIZE)\n bytesRead = 0\n bufferPointer = bytesRead\n }\n\n fun nextString(maxSize: Int): String {\n val ch = ByteArray(maxSize)\n var point = 0\n try {\n var c = read()\n while (c == ' '.toByte() || c == '\\n'.toByte() || c == '\\r'.toByte())\n c = read()\n while (c != ' '.toByte() && c != '\\n'.toByte() && c != '\\r'.toByte()) {\n ch[point++] = c\n c = read()\n }\n } catch (e: Exception) {}\n\n return String(ch, 0, point)\n }\n\n fun nextInt(): Int {\n var ret = 0\n val neg: Boolean\n try {\n var c = read()\n while (c <= ' '.toByte())\n c = read()\n neg = c == '-'.toByte()\n if (neg)\n c = read()\n do {\n ret = ret * 10 + c - '0'.toInt()\n c = read()\n } while (c > ' '.toByte())\n\n if (neg) return -ret\n } catch (e: Exception) {}\n return ret\n }\n\n fun nextLong(): Long {\n var ret: Long = 0\n val neg: Boolean\n try {\n var c = read()\n while (c <= ' '.toByte())\n c = read()\n neg = c == '-'.toByte()\n if (neg)\n c = read()\n do {\n ret = ret * 10 + c - '0'.toLong()\n c = read()\n } while (c > ' '.toByte())\n\n if (neg) return -ret\n } catch (e: Exception) {}\n\n return ret\n }\n\n fun nextDouble(): Double\n = nextString(10000).toDouble()\n\n private fun fillBuffer() {\n try {\n bytesRead = din.read(buffer, 0, BUFFER_SIZE)\n } catch (e: Exception) {}\n if (bytesRead == -1) buffer[0] = -1\n }\n\n private fun read(): Byte {\n if (bufferPointer == bytesRead) fillBuffer()\n return buffer[bufferPointer++]\n }\n}\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\nfun IntArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun LongArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun BooleanArray.print() {\n println(Arrays.toString(this))\n}\nfun nod(a: Long, b: Long): Long {\n var a1 = a\n var b1 = b\n while (a1 != 0L && b1 != 0L) {\n if (a1 < b1)\n b1 %= a1\n else\n a1 %= b1\n }\n return a1 + b1\n}\nfun nok(a: Long, b: Long): Long = a * b / nod(a, b)\nfun min(a: Char, b: Char): Int {\n if (a < b)\n return a.toInt()\n return b.toInt()\n}\nfun max(a: Char, b: Char): Int {\n if (a > b)\n return a.toInt()\n return b.toInt()\n}"}, {"source_code": "\nimport java.io.*\nimport java.util.*\n\n\nfun solve() {\n\n var n = nextInt()\n var ans = 0\n while (n > 0) {\n n /= 2\n ans++\n }\n\n println(ans)\n}\n\n\n\n\nfun hasNext() : Boolean {\n while (!st.hasMoreTokens()) {\n st = StringTokenizer(input.readLine() ?: return false)\n }\n return true\n}\n\nfun next() = if (hasNext()) st.nextToken()!! else throw RuntimeException(\"No tokens\")\n\nfun nextInt() = next().toInt()\n\nfun nextLong() = next().toLong()\n\nfun nextDouble() = next().toDouble()\n\nfun nextLine() = if (hasNext()) st.nextToken(\"\\n\")!! else throw RuntimeException(\"No tokens\")\n\nfun nextArray(n : Int) = IntArray(n, { nextInt() })\n\nval ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n\nvar input = when(ONLINE_JUDGE) {\n true -> BufferedReader(InputStreamReader(System.`in`), 32768)\n else -> BufferedReader(FileReader(\"in.txt\"))\n}\n\nvar output = when(ONLINE_JUDGE) {\n true -> PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))\n else -> PrintWriter(BufferedWriter(FileWriter(\"out.txt\")))\n}\n\nvar st = StringTokenizer(\"\")\n\nfun main(args: Array) {\n val start = System.currentTimeMillis()\n solve()\n\n output.close()\n input.close()\n\n if (!ONLINE_JUDGE) {\n //System.err.println(\"${System.currentTimeMillis() - start} ms\")\n }\n}"}, {"source_code": "import kotlin.math.log2\n\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n println(log2(n.toDouble()).toInt() + 1)\n}"}, {"source_code": "import kotlin.math.*\n\nfun main() {\n val n = readInt()\n\n val ans = n.toBigInteger().bitLength()\n\n println(ans)\n}\n\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readStringSeq() = readLn().splitToSequence(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readIntSeq() = readStringSeq().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readDoubleSeq() = readStringSeq().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\nfun readLongSeq() = readStringSeq().map { it.toLong() }\n\nclass Output {\n val outputSb = StringBuilder()\n fun print(o: Any?) { outputSb.append(o) }\n fun println() { outputSb.append('\\n') }\n fun println(o: Any?) { outputSb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(outputSb) }\n}\ninline fun output(block: Output.()->Unit) { Output().apply(block).nowPrint() }"}, {"source_code": "import java.util.*\n\nfun main(args: Array ) {\n val sc = Scanner( System.`in` )\n var n = sc.nextInt()\n var s = 1\n var r = 0\n while ( n > 0 ) {\n n -= s\n s *= 2\n r ++\n }\n println( r )\n}\n"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n var s = 0L\n var i = 1\n var x = 0\n while(s < n) {\n s+=i\n i*=2\n x++\n }\n println(x)\n}\n"}], "negative_code": [{"source_code": "fun main() {\n val n = readLine()!!.toInt()\n var s = 0L\n var i = 1\n while(s < n) {\n s+=i\n i++\n }\n println(i-1)\n}\n"}], "src_uid": "95cb79597443461085e62d974d67a9a0"} {"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 java.time.LocalDate\n\nfun readString() = readLine()!!\nfun readStrings() = readString().split(\" \")\nfun readInt() = readString().toInt()\nfun readInts() = readStrings().map { it.toInt() }\nfun readLong() = readString().toLong()\nfun readLongs() = readStrings().map { it.toLong() }\nfun readDouble() = readString().toDouble()\nfun readDoubles() = readStrings().map { it.toDouble() }\n\nfun runTestCases(times: Int, block: () -> Unit) {\n for (i in 1..times)\n block()\n}\n\nfun main() {\n val s = readStrings()\n if (s[2] == \"month\") {\n if (s[0].toInt() <= 29)\n println(12)\n else if (s[0].toInt() <= 30)\n println(11)\n else\n println(7)\n }\n else {\n if (s[0].toInt() == 5 || s[0].toInt() == 6)\n println(53)\n else\n println(52)\n }\n}\n\nprivate fun toDecimal(str: String): Int {\n return str.toInt(2)\n}\n\nfun reverse(num: Int) =\n num.toString().reversed().toInt()\n\nprivate operator fun String.times(n: Int): String {\n val sb = StringBuilder()\n for (i in 1..n)\n sb.append(this)\n return sb.toString()\n}\n"}, {"source_code": "import java.lang.StringBuilder\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.max\n\nfun main() {\n var (num, i, key) = readLine()!!.split(' ')\n var number = num.toInt()\n if (!key.equals(\"week\")) {\n if (1 <= number && number <= 29) {\n println(12)\n } else if ((number == 30 || number == 29)) {\n println(11)\n } else if (number == 31) {\n println(7)\n }\n } else {\n if (number == 6 || number == 5) {\n println(53)\n } else {\n println(52)\n }\n\n }\n}"}, {"source_code": "fun main() {\n val text = readLine()!!\n print(\n when {\n text == \"30 of month\" -> 11\n text == \"31 of month\" -> 7\n text.endsWith(\"month\") -> 12\n text[0] == '5' -> 53\n text[0] == '6' -> 53\n else -> 52\n }\n )\n}"}], "negative_code": [{"source_code": "import java.time.LocalDate\n\nfun readString() = readLine()!!\nfun readStrings() = readString().split(\" \")\nfun readInt() = readString().toInt()\nfun readInts() = readStrings().map { it.toInt() }\nfun readLong() = readString().toLong()\nfun readLongs() = readStrings().map { it.toLong() }\nfun readDouble() = readString().toDouble()\nfun readDoubles() = readStrings().map { it.toDouble() }\n\nfun runTestCases(times: Int, block: () -> Unit) {\n for (i in 1..times)\n block()\n}\n\nfun main() {\n val s = readStrings()\n if (s[2] == \"month\") {\n if (s[0].toInt() >= 30)\n println(11)\n else\n println(12)\n }\n else {\n if (s[0].toInt() == 5 || s[0].toInt() == 6)\n println(53)\n else\n println(52)\n }\n}\n\nprivate fun toDecimal(str: String): Int {\n return str.toInt(2)\n}\n\nfun reverse(num: Int) =\n num.toString().reversed().toInt()\n\nprivate operator fun String.times(n: Int): String {\n val sb = StringBuilder()\n for (i in 1..n)\n sb.append(this)\n return sb.toString()\n}\n"}], "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b"} {"nl": {"description": "The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (https://en.wikipedia.org/wiki/Leap_year).", "input_spec": "The only line contains integer y (1000 ≤ y < 100'000) — the year of the calendar.", "output_spec": "Print the only integer y' — the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.", "sample_inputs": ["2016", "2000", "50501"], "sample_outputs": ["2044", "2028", "50507"], "notes": "NoteToday is Monday, the 13th of June, 2016."}, "positive_code": [{"source_code": "import java.util.*\nimport kotlin.collections.*\nimport kotlin.math.*\n\nprivate fun readLn() = readLine()!! // string\nprivate fun readInt() = readLn().toInt() // int\nprivate fun readStrings() = readLn().split(\" \") // string string\nprivate fun readInts() = readStrings().map { it.toInt() } // int int\n\nfun isLeapYear(y: Int) = ((y%400 == 0) || (y%4 == 0 && y%100 != 0))\n\nfun main() {\n var n = readInt()\n val isl = isLeapYear(n)\n var nextfake = 0\n var ans = n\n do {\n ans++\n nextfake = if (isLeapYear(ans) == true) (nextfake + 2)%7 else (nextfake + 1)%7\n //println(nextfake)\n } while (nextfake != 0 || isLeapYear(ans) != isl)\n print(ans)\n}\n"}], "negative_code": [], "src_uid": "565bbd09f79eb7bfe2f2da46647af0f2"} {"nl": {"description": "Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:qwertyuiopasdfghjkl;zxcvbnm,./Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input).We have a sequence of characters he has typed and we want to find the original message.", "input_spec": "First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it.", "output_spec": "Print a line that contains the original message.", "sample_inputs": ["R\ns;;upimrrfod;pbr"], "sample_outputs": ["allyouneedislove"], "notes": null}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n }\n\n var tok = StringTokenizer(\"\")\n\n fun close() { rd.close(); wr.close() }\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun readToken(): String {\n while (!tok.hasMoreTokens()) tok = StringTokenizer(rd.readLine())\n return tok.nextToken()\n }\n fun readInt() = readToken().toInt()\n fun readLong() = readToken().toLong()\n fun readLine() : String {\n tok = StringTokenizer(\"\")\n return rd.readLine()\n }\n}\n\nfun main(args: Array) {\n Thread({ val io = ProblemIO.console(); solve(io) ; io.close() }).start()\n}\n\nfun solve(io: ProblemIO) {\n val kbd = arrayOf(\"qwertyuiop\", \"asdfghjkl;\", \"zxcvbnm,./\")\n val lm = HashMap()\n val rm = HashMap()\n for (s in kbd) {\n for (i in s.indices) {\n if (i > 0) lm[s[i]] = s[i - 1]\n if (i < s.lastIndex) rm[s[i]] = s[i + 1]\n }\n }\n val d = io.readToken()\n val m = if (d == \"L\") rm else lm\n val s = io.readToken()\n io.println(s.map({ ch -> m[ch] }).joinToString(\"\"))\n}\n"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val len = r.readLine()!!.toInt()\n //val (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n val type = r.readLine()!!\n val str = \"qwertyuiopasdfghjkl;zxcvbnm,./\".split(\"\").filter { it.length > 0 }\n val before = r.readLine()!!\n before.forEach { \n var i = str.indexOf(it.toString())\n if (type==\"R\") i--\n else i++\n s.append(str[i])\n }\n println(s)\n}"}, {"source_code": "import java.lang.StringBuilder\n\nprivate const val layout = \"qwertyuiopasdfghjkl;zxcvbnm,./\"\n\nfun main(args: Array) {\n val direction = readLine()!!\n val message = readLine()!!\n val correction = if (direction == \"L\") 1 else -1\n val result = StringBuilder()\n for (char in message) {\n val currentIndex = layout.indexOf(char)\n val requiredCharIndex = currentIndex + correction\n val requiredChar = layout[requiredCharIndex]\n result.append(requiredChar)\n }\n print(result)\n}"}, {"source_code": "fun main() = Pair(readLine()!! == \"R\", readLine()!!)\n .let { (rightShifted, wrongMessage) ->\n val shiftedKeysMap = hashMapOf>().apply {\n \"qwertyuiopasdfghjkl;zxcvbnm,./\".let { keyboard ->\n keyboard.forEachIndexed { index, key ->\n put(\n key,\n Pair(keyboard.getOrNull(index - 1) ?: '*', keyboard.getOrNull(index + 1) ?: '*')\n )\n }\n }\n }\n wrongMessage\n .map { key -> shiftedKeysMap[key]!!.run { if (rightShifted) first else second } }\n .joinToString(\"\")\n }\n .run(::println)"}, {"source_code": "fun main() {\n val shift = readLine()!!\n val output = readLine()!!.map { getLetter(shift, it) }.joinToString(\"\")\n println(output)\n}\n\nfun getLetter(shift: String, char: Char): Char {\n val line = listOf(\n \"qwertyuiop\",\n \"asdfghjkl;\",\n \"zxcvbnm,./\"\n ).first { it.contains(char) }\n\n val position = line.indexOf(char)\n val shiftIndex = if (shift == \"L\") 1 else -1\n return line.get(position + shiftIndex)\n}"}, {"source_code": "fun main()\n{\n val abc=\"qwertyuiopasdfghjkl;zxcvbnm,./\"\n var dir = readLine().toString()\n var text = readLine().toString()\n val t = text.toCharArray()\n for(index in 0..text.length-1)\n {\n if (dir == \"R\") {\n val eindex: Int = abc.indexOf(t[index]) - 1\n t[index] = abc[eindex]\n\n } else {\n val eindex: Int = abc.indexOf(t[index]) + 1\n t[index] = abc[eindex]\n }\n\n }\n text = String(t)\n println(text)\n}\n\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.lang.StringBuilder\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val shifting = br.readLine()\n val s = br.readLine()\n val keys = (\"qwertyuiop\" + \"asdfghjkl;\" + \"zxcvbnm,./\").toList()\n val keysIndices = keys.zip(keys.indices).toMap()\n println(\n s.fold(StringBuilder()){acc, c ->\n acc.apply {\n append(\n if (shifting == \"R\") keys[keysIndices[c]!! - 1]\n else keys[keysIndices[c]!! + 1]\n )\n }\n }\n )\n}"}, {"source_code": "import java.math.BigInteger\n\n\nfun main() {\n var direction = readLine()!!\n var str = readLine()!!\n var ansStr = \"qwertyuiopasdfghjkl;zxcvbnm,./\"\n var ans =\"\"\n if (direction==\"R\"){\n for (i in str){\n var j = 1\n while (j) {\n val keyboard = \"qwertyuiopasdfghjkl;zxcvbnm,./\"\n val dir = if (readLine()!! == \"R\") -1 else 1\n val input = readLine()!!\n println(String(input.map { it -> keyboard[keyboard.indexOf(it) + dir] }.toCharArray()))\n}"}, {"source_code": "fun main(args:Array) {\n val a=\"qwertyuiopasdfghjkl;zxcvbnm,./\"\n val LR= readLine()!!\n var x= readLine()!!\n var result=\"\"\n var f=1\n if(LR==\"R\")\n f*=-1\n for(i in 0 until x.length){\n result+=a[a.indexOf(x[i])+f]\n }\n println(result)\n}"}, {"source_code": "import java.lang.AssertionError\nimport java.util.*\n \nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n \nprivate fun myAssert(x: Boolean) {\n if (!x) {\n throw AssertionError()\n }\n}\n\nfun main(args: Array) {\n// var s = Scanner(System.`in`)\n var cmd = readLn()\n var line = readLn()\n var map = mutableMapOf()\n var keyboard = \"qwertyuiopasdfghjkl;zxcvbnm,./\"\n if (cmd == \"R\") {\n for (i in 1..keyboard.length - 1) {\n map[keyboard[i]] = keyboard[i - 1]\n }\n for (i in 0..line.length - 1) {\n print(\"${map[line[i]]}\")\n }\n print(\"\\n\")\n } else {\n for (i in 0..keyboard.length - 2) {\n map[keyboard[i]] = keyboard[i + 1]\n }\n for (i in 0..line.length - 1) {\n print(\"${map[line[i]]}\")\n }\n print(\"\\n\")\n }\n}\n"}, {"source_code": "fun main() {\n val shift = if (readLine()!! == \"R\") -1 else 1\n val text = readLine()!!\n val map = mutableMapOf>()\n val lines = arrayOf(\"qwertyuiop\", \"asdfghjkl;\", \"zxcvbnm,./\")\n for (linePos in 0 until 3)\n for ((charPos, char) in lines[linePos].withIndex())\n map[char] = linePos to charPos\n val sb = StringBuilder()\n for (c in text) {\n val (linePos, charPos) = map[c]!!\n sb.append(lines[linePos][charPos + shift])\n }\n print(sb.toString())\n}"}, {"source_code": "import java.util.TreeMap\n\ninterface LexicographicComparable : Comparable {\n fun num_fields() : Int\n fun compare_field(i : Int, other : T) : Int\n\n override fun compareTo(other : T) : Int {\n val n = num_fields()\n for (i in 0 .. (n - 1)) {\n val c = compare_field(i, other)\n if (c == 0) {\n // Do nothing ...\n } else {\n return c\n }\n }\n return 0\n }\n}\n\nclass KeyboardCharacter : LexicographicComparable {\n val row : Int\n val index : Int\n\n constructor(row : Int, index : Int) {\n this.row = row\n this.index = index\n }\n\n fun neighbor(l_or_r : String) : KeyboardCharacter {\n when (l_or_r) {\n \"L\" -> return KeyboardCharacter(this.row, this.index + 1)\n \"R\" -> return KeyboardCharacter(this.row, this.index - 1)\n else -> throw Exception(\"Unknown neighbor.\")\n }\n }\n\n override fun num_fields() : Int {\n return 2\n }\n\n override fun compare_field(i : Int, other : KeyboardCharacter) : Int {\n when (i) {\n 0 -> return this.row.compareTo(other.row)\n 1 -> return this.index.compareTo(other.index)\n else -> throw Exception(\"Invalid field!\")\n }\n }\n\n override fun toString() : String {\n return \"(${this.row}, ${this.index})\"\n }\n}\n\nfun updateKeyboard(row : Int,\n keys : String,\n kbToChar : TreeMap,\n charToKb : TreeMap) {\n var index = 0\n for (char in keys) {\n val kb = KeyboardCharacter(row, index)\n kbToChar.put(kb, char)\n charToKb.put(char, kb)\n index = index + 1\n }\n}\n\nfun readString() : String {\n val str_nullable = readLine()\n if (str_nullable == null) {\n throw Exception(\"Could not read string!\")\n } else {\n val str = str_nullable\n return str\n }\n}\n\nfun main(args : Array) {\n val row_0 = \"qwertyuiop\"\n val row_1 = \"asdfghjkl;\"\n val row_2 = \"zxcvbnm,./\"\n val kbToChar = TreeMap()\n val charToKb = TreeMap()\n updateKeyboard(0, row_0, kbToChar, charToKb)\n updateKeyboard(1, row_1, kbToChar, charToKb)\n updateKeyboard(2, row_2, kbToChar, charToKb)\n // println(\"${kbToChar}\")\n // println(\"${charToKb}\")\n val l_or_r = readString()\n val str = readString()\n fun translate(c : Char) : Char {\n val kb_nullable = charToKb[c]\n if (kb_nullable == null) {\n throw Exception(\"1. Could not translate character!\")\n } else {\n val kb = kb_nullable\n val kb_nbr = kb.neighbor(l_or_r)\n val nbr_c_nullable = kbToChar[kb_nbr]\n if (nbr_c_nullable == null) {\n throw Exception(\"2. Could not translate character!\")\n } else {\n val nbr_c = nbr_c_nullable\n return nbr_c\n }\n }\n }\n str.forEach({c -> val t = translate(c)\n print(t) })\n println()\n}\n"}, {"source_code": "import java.util.*\n\n/**\n * Created by tux on 08.11.16.\n */\n\nfun main(args: Array) {\n val K = listOf(\"qwertyuiop\", \"asdfghjkl;\", \"zxcvbnm,./\")\n val M = HashMap>()\n for (j in 0..(K.size - 1)) {\n for (i in 0..(K[j].length - 1)) {\n M.put(K[j][i], Pair(j, i))\n }\n }\n\n val offset = if (readLine()!![0] == 'R') -1 else +1\n var ret = \"\"\n readLine()!!.forEach {\n val p = M[it]!!\n ret += K[p.first][p.second + offset]\n }\n println(ret)\n}\n"}, {"source_code": "\nfun main(args: Array) {\n\n val first = \"qwertyuiopasdfghjkl;zxcvbnm,./\"\n\n val command = readLine()!!\n\n val message = readLine()!!\n\n\n var result= \"\"\n \n message.forEach { c ->\n val position = first.indexOf(c)\n result += if (command == \"R\"){\n first[position - 1]\n }else{\n first[position + 1]\n }\n\n }\n\n println(result)\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.*\nimport kotlin.system.measureTimeMillis\n\nfun getMinimumAmountOfChangeFrom(amount: Int): Int {\n val changes = listOf(10, 5, 1)\n var availableAmount = amount\n var numOfCoins = 0\n for (change in changes) {\n while (availableAmount > 0 && availableAmount / change.toDouble() >= 1) {\n numOfCoins += 1\n availableAmount -= change\n }\n }\n return numOfCoins\n}\n\nfun getMaximumValueOfTheLootWith(\n W: Int,\n valuePerUnitAndWeight: List>\n): Double {\n var maximumLootValue = 0.0\n var availableWeight = W\n for (pair in valuePerUnitAndWeight) {\n var availableWeightOfLootItem = pair.second\n while (availableWeight > 0 && availableWeightOfLootItem > 0) {\n maximumLootValue += pair.first\n availableWeightOfLootItem -= 1\n availableWeight -= 1\n }\n }\n return maximumLootValue\n}\n\nfun getMinimumNumOfRefills(d: Int, m: Int, stops: List): Int {\n var availableDistance = d\n var minimumRefills = 0\n var currentRefill = 0\n var lastRefill = 0\n val realStops = listOf(0, *stops.toTypedArray(), d)\n while (availableDistance > 0 && currentRefill < realStops.size) {\n var movedForward = false\n while (currentRefill < realStops.size && (realStops[currentRefill] - realStops[lastRefill]) <= m) {\n if (realStops[currentRefill] - realStops[lastRefill] == 0) {\n movedForward = false\n currentRefill++\n } else {\n movedForward = true\n currentRefill++\n }\n }\n if (movedForward) {\n minimumRefills++\n currentRefill--\n availableDistance -= (realStops[currentRefill] - realStops[lastRefill])\n lastRefill = currentRefill\n } else {\n return -1\n }\n }\n return minimumRefills - 1\n}\n\nfun getMaximizedSumOfProduct(profitPerClick: List, averageNumberOfClicks: List): Long {\n var sum = 0L\n println(profitPerClick.toString())\n println(averageNumberOfClicks.toString())\n profitPerClick.forEachIndexed { index, profit ->\n sum += profit * averageNumberOfClicks[index]\n }\n return sum\n}\n\nfun getCommon(first: Int, last: Int, segments: MutableList>): String {\n var current = first\n val common = mutableListOf>()\n while (current <= last) {\n var numOfTimes = 0\n for (pair in segments) {\n if (current in pair.first..pair.second) {\n numOfTimes++\n }\n }\n if (numOfTimes > 1) {\n common.add(Pair(current, numOfTimes))\n }\n current++\n }\n common.sortByDescending { it -> it.second }\n if (common.first().second == segments.size) {\n return \"1\\n${common.first().first}\"\n }\n println(common)\n return \"${common.size}\\n${common.map { it.first }.joinToString(\" \")}\"\n}\n\nfun getMaximumSetOfPrizes(n: Int): String {\n var numbersOfN = \"\"\n var sumSoFar = 0\n if (n <= 2) {\n return \"1\\n$n\"\n }\n// println(\"2*square root of n = ${2 * sqrt(n.toDouble())}\")\n// for (i in 1..(2 * sqrt(n.toDouble()).toInt())){\n// if (i+sumSoFar<=n){\n// numbersOfN+=\"$i \"\n// sumSoFar+=i\n// }\n// }\n// var lastNumber = 1\n var currentNumber = 1\n while (((currentNumber + 1) + currentNumber) <= n - sumSoFar) {\n sumSoFar += currentNumber\n numbersOfN += \"$currentNumber \"\n currentNumber++\n }\n if (((n - currentNumber) + sumSoFar) == n || n - sumSoFar > 0) {\n currentNumber = n - sumSoFar\n sumSoFar += currentNumber\n numbersOfN += \"$currentNumber \"\n }\n// else if (n-sumSoFar>0){\n// currentNumber = n-sumSoFar\n// numbersOfN += \"$currentNumber \"\n// }\n return \"${numbersOfN.trim().split(\" \").size}\\n$numbersOfN\"\n}\n\n\nfun linelandMail(coordinates: List): String {\n val mins = mutableListOf()\n val maxs = mutableListOf()\n for (i in coordinates.indices) {\n if (i == 0) {\n mins.add(abs(coordinates[i] - coordinates[i + 1]))\n maxs.add(abs(coordinates[i] - coordinates[coordinates.size - 1]))\n } else if (i == coordinates.size - 1) {\n mins.add(abs(coordinates[i] - coordinates[i - 1]))\n maxs.add(abs(coordinates[i] - coordinates[0]))\n } else {\n if (abs(coordinates[i] - coordinates[i - 1])\n > abs(coordinates[i] - coordinates[i + 1])\n )\n mins.add(abs(coordinates[i] - coordinates[i + 1]))\n else\n mins.add(abs(coordinates[i] - coordinates[i - 1]))\n\n if (abs(coordinates[i] - coordinates[0])\n < abs(coordinates[i] - coordinates[coordinates.size - 1])\n )\n maxs.add(abs(coordinates[i] - coordinates[coordinates.size - 1]))\n else\n maxs.add(abs(coordinates[i] - coordinates[0]))\n }\n }\n return mins\n .zip(maxs)\n .map { pair -> \"${pair.first} ${pair.second}\" }\n .joinToString(\"\\n\")\n}\n\nfun snacktower(snacksWeights: List) {\n val n = snacksWeights.size\n var currentMax = n\n var current = 0\n var processed = mutableListOf()\n while (current < snacksWeights.size) {\n if (snacksWeights[current] < currentMax) {\n processed.add(snacksWeights[current])\n print(\"\\n\")\n current++\n } else {\n if (snacksWeights[current] == currentMax) {\n print(currentMax)\n currentMax--\n var currentProcessed = 0\n while (currentProcessed < processed.size) {\n var foundConsecutive = false\n if (processed[currentProcessed] == currentMax) {\n print(\" \")\n print(processed[currentProcessed])\n currentMax--\n foundConsecutive = true\n processed = processed.swap(currentProcessed, processed.size - 1).toMutableList()\n processed.removeAt(processed.size - 1)\n }\n if (!foundConsecutive) {\n currentProcessed++\n } else {\n currentProcessed = 0\n }\n }\n println()\n current++\n }\n }\n }\n}\n\nfun List.swap(a: Int, b: Int): List = this\n .toMutableList()\n .also {\n it[a] = this[b]\n it[b] = this[a]\n }\n\nfun `Oath of the Night's Watch`(stewardsStrengths: List) {\n val sortedStrengths = stewardsStrengths.sorted()\n var numberOfThoseWhoNeedSupport = 0\n for (strengthIndex in sortedStrengths.indices) {\n val precedingSteward = strengthIndex - 1\n val nextSteward = strengthIndex + 1\n if (precedingSteward>=0 && nextStewardsortedStrengths[strengthIndex]){\n numberOfThoseWhoNeedSupport++\n }\n }\n }\n println(numberOfThoseWhoNeedSupport)\n}\n\nfun pangram(characters: String){\n print(if (characters.toLowerCase().toSet().size==26) \"YES\" else \"NO\")\n}\n\nfun twins(coinsValues: List){\n val sortedValues = coinsValues.sortedDescending()\n var mySumSoFar = 0\n var numberOfCoinsIWillTake = 0\n for (index in sortedValues.indices){\n mySumSoFar+=sortedValues[index]\n numberOfCoinsIWillTake++\n if (mySumSoFar>sortedValues.subList(index+1,sortedValues.size).sum()){\n break\n }\n }\n println(numberOfCoinsIWillTake)\n}\n\nfun keyboard(handSlippedTo: Char, codedMessage: String){\n val hisKeyboard = \"qwertyuiopasdfghjkl;zxcvbnm,./\"\n for (char in codedMessage){\n when(handSlippedTo){\n 'R'->{\n print(hisKeyboard[hisKeyboard.indexOf(char)-1])\n }\n 'L'->{\n print(hisKeyboard[hisKeyboard.indexOf(char)+1])\n }\n }\n }\n}\nfun main() {\n\n// val scanner = Scanner(System.`in`)\n// val n = scanner.nextInt()\n// val snacksWeights = MutableList(n) { index -> 0 }\n// for (i in 0 until n) {\n// snacksWeights[i] = scanner.nextInt()\n// }\n// snacktower(snacksWeights)\n// val scanner = Scanner(System.`in`)\n// val n = scanner.nextInt()\n// val strengths = MutableList(n) { index -> 0 }\n// for (i in 0 until n) {\n// strengths[i] = scanner.nextInt()\n// }\n// `Oath of the Night's Watch`(strengths)\n val scanner = Scanner(System.`in`)\n val direction = scanner.next()\n val codedMessage = scanner.next()\n keyboard(direction[0],codedMessage)\n}\n\n\n// start of stress test\n// while (true) {\n// val n = Random.nextLong(1000000)\n// val m = Random.nextLong(100000)\n// if (m) {\n val strs = arrayOf(\"qwertyuiop\", \"asdfghjkl;\", \"zxcvbnm,./\")\n val R = mutableMapOf()\n val L = mutableMapOf()\n for (str in strs) {\n for (i in 1..str.length-1) {\n R.put(str[i-1], str[i])\n L.put(str[i], str[i-1])\n }\n }\n val dir = readLine()!![0]\n val s = readLine()!!\n for (c in s) {\n if (dir == 'R') {\n print(L[c])\n } else {\n print(R[c])\n }\n }\n print(\"\\n\")\n}\n"}, {"source_code": "fun main(args: Array) {\n val t = \"qwertyuiopasdfghjkl;zxcvbnm,./\"\n val s = readLine()\n val m = if (s==\"R\") -1\n else 1\n val z = readLine()!!.toString()\n for (c in z) print(t[t.indexOf(c)+m])\n}"}, {"source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n var Direction: String = input.next()\n var Word: String = input.next()\n var lettList = ArrayList()\n\n val keyboard = \"qwertyuiop[]asdfghjkl;'zxcvbnm,./\"\n\n for(letter in Word.indices) {\n for (checker in keyboard.indices) {\n if(Word.get(letter) == keyboard.get(checker)) {\n if(Direction.equals(\"R\")) {\n lettList.add(keyboard.get(checker-1))\n } else {\n lettList.add(keyboard.get(checker+1))\n }\n }\n }\n }\n\n var Res: String = lettList.joinToString(\"\")\n println(Res)\n}"}], "negative_code": [{"source_code": "fun main(args:Array) {\n val a=\"qwertyuiopsdfghjkl;zxcvbnm,./\"\n val LR= readLine()!!\n var x= readLine()!!\n var result=\"\"\n var f=1\n if(LR==\"R\")\n f*=-1\n for(i in 0 until x.length){\n result+=a[a.indexOf(x[i])+f]\n }\n println(result)\n}"}, {"source_code": "import java.lang.AssertionError\nimport java.util.*\n \nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n \nprivate fun myAssert(x: Boolean) {\n if (!x) {\n throw AssertionError()\n }\n}\n\nfun main(args: Array) {\n// var s = Scanner(System.`in`)\n var cmd = readLn()\n var line = readLn()\n var map = mutableMapOf()\n var keyboard = \"qwertyuiopasdfghjkl;zxcvbnm,./\"\n if (cmd == \"R\") {\n for (i in 1..keyboard.length - 1) {\n map[keyboard[i]] = keyboard[i - 1]\n }\n for (i in 0..line.length - 1) {\n print(\"${map[line[i]]}\")\n }\n print(\"\\n\")\n } else {\n for (i in 0..keyboard.length - 2) {\n map[keyboard[i]] = keyboard[i + 1]\n }\n for (i in 0..line.length - 1) {\n print(\"${map[line[i]]}\\n\")\n }\n print(\"\\n\")\n }\n}\n"}], "src_uid": "df49c0c257903516767fdb8ac9c2bfd6"} {"nl": {"description": "You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard.Initially, you have an empty string. Until you type the whole string, you may perform the following operation: add a character to the end of the string. Besides, at most once you may perform one additional operation: copy the string and append it to itself.For example, if you have to type string abcabca, you can type it in 7 operations if you type all the characters one by one. However, you can type it in 5 operations if you type the string abc first and then copy it and type the last character.If you have to type string aaaaaaaaa, the best option is to type 4 characters one by one, then copy the string, and then type the remaining character.Print the minimum number of operations you need to type the given string.", "input_spec": "The first line of the input containing only one integer number n (1 ≤ n ≤ 100) — the length of the string you have to type. The second line containing the string s consisting of n lowercase Latin letters.", "output_spec": "Print one integer number — the minimum number of operations you need to type the given string.", "sample_inputs": ["7\nabcabca", "8\nabcdefgh"], "sample_outputs": ["5", "8"], "notes": "NoteThe first test described in the problem statement.In the second test you can only type all the characters one by one."}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) {\n solve(System.`in`, System.out)\n}\n\nval MAX_N = (1e6 + 10).toInt()\nval INF = (1e9 + 7).toInt()\nval MOD = (1e9 + 7).toInt()\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val n = reader.nextInt()\n val s = reader.next()\n\n var ans = n\n\n for (l in (0 until n / 2).reversed()) {\n val pref = s.slice(0..l)\n val r = 2 * l + 1\n val nexts = s.slice(l + 1..r)\n\n if (pref == nexts) {\n val t = pref.length + 1 + (n - 2 * pref.length)\n ans = min(ans, t)\n }\n }\n writer.println(ans)\n}\n\nclass InputReader(stream: InputStream) {\n val reader: BufferedReader\n var tokenizer: StringTokenizer? = null\n\n init {\n reader = BufferedReader(InputStreamReader(stream), 32768)\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.*\n\nfun check(s: String, start: Int): Boolean {\n for (i in 0 until start) {\n if (start + i >= s.length || s[i] != s[start + i])\n return false\n }\n return true\n}\n\nfun main(args: Array) {\n Scanner(System.`in`.buffered()).use {\n val n = it.nextInt()\n val s = it.next()\n\n var ans = n\n for (i in 1 .. n / 2) {\n if (check(s, i))\n ans = min(ans, i + 1 + n - 2 * i)\n }\n\n println(ans)\n }\n}"}], "negative_code": [], "src_uid": "ed8725e4717c82fa7cfa56178057bca3"} {"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": "import kotlin.math.abs\n\nfun main() {\n var (n, pos, l, r) = readLine()!!.split(\" \").map(String::toInt)\n val toDelete = mutableListOf>()\n if (l > 1)\n toDelete.add(pos - l to l)\n if (r < n)\n toDelete.add(r - pos to r)\n toDelete.sortBy { it.first }\n var sol = 0\n for(tab in toDelete) {\n sol += abs(pos -tab.second) + 1\n pos = tab.second\n }\n print(sol)\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.min\n\n\nclass B {\n fun solve(input : InputStream, output : OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n val n = reader.nextInt()\n val pos = reader.nextInt()\n val l = reader.nextInt()\n val r = reader.nextInt()\n\n writer.println(solve(n, pos, l, r))\n\n writer.close()\n }\n\n fun range(a : Int, b : Int) : Int {\n return abs(a - b)\n }\n\n fun solve(n : Int, pos : Int, l : Int, r : Int) : Int {\n if (l == 1 && r == n) {\n return 0\n }\n if (l == 1) {\n return range(pos, r) + 1\n }\n if (r == n) {\n return range(pos, l) + 1\n }\n\n val leftFirst = range(pos, l) + 1 + range(l, r) + 1\n val rightFirst = range(pos, r) + 1 + range(l, r) + 1\n return min(leftFirst, rightFirst)\n }\n\n private class InputReader(stream: InputStream) {\n var reader: BufferedReader\n var tokenizer: StringTokenizer? = null\n\n init {\n reader = BufferedReader(InputStreamReader(stream), 32768)\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n }\n}\n\nfun main(args : Array) {\n B().solve(System.`in`, System.out)\n}"}, {"source_code": "import java.util.*\n\nfun abs(x: Int) = if (x >= 0) x else -x\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val n = nextInt(); val pos = nextInt()\n val l = nextInt(); val r = nextInt()\n\n val leftToRight = abs(pos - l) + 1 + (1 + r - l) * (if (r != n) 1 else 0)\n val rightToLeft = abs(r - pos) + 1 + (1 + r - l) * (if (l != 1) 1 else 0)\n\n if (l == 1 && r == n) {\n print(0)\n } else {\n print(minOf(leftToRight, rightToLeft))\n }\n}\n"}], "negative_code": [{"source_code": "fun main() {\n val (n, pos, l, r) = readLine()!!.split(\" \").map(String::toInt)\n val toDelete = mutableListOf()\n if (l > 1)\n toDelete.add(pos - l)\n if (r < n)\n toDelete.add(r - pos)\n toDelete.sort()\n var sol = 0\n when (toDelete.size) {\n 1 -> sol += toDelete[0] + 1\n 2 -> sol += toDelete[0] + 1 + toDelete[0] + toDelete[1] + 1\n }\n print(sol)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val n = nextInt(); val pos = nextInt()\n val l = nextInt(); val r = nextInt()\n\n val leftToRight = pos - l + 1 + (1 + r - l) * (if (r != n) 1 else 0)\n val rightToLeft = r - pos + 1 + (1 + r - l) * (if (l != 1) 1 else 0)\n\n if (l == 1 && r == n) {\n print(0)\n } else {\n print(minOf(leftToRight, rightToLeft))\n }\n}\n"}], "src_uid": "5deaac7bd3afedee9b10e61997940f78"} {"nl": {"description": "Today is Mashtali's birthday! He received a Hagh tree from Haj Davood as his birthday present!A directed tree is called a Hagh tree iff: The length of the longest directed path in it is exactly $$$n$$$. Every vertex has at most three edges attached to it independent of their orientation. Let's call vertices $$$u$$$ and $$$v$$$ friends if one of them has a directed path to the other. For every pair of vertices $$$u$$$ and $$$v$$$ that are not friends, there should exist a vertex $$$w$$$ that is friends with both $$$u$$$ and $$$v$$$ (a mutual friend). After opening his gift, Mashtali found out that the labels on the vertices were gone.Immediately, he asked himself: how many different unlabeled Hagh trees are there? That is, how many possible trees could he have received as his birthday present?At the first glance, the number of such trees seemed to be infinite since there was no limit on the number of vertices; but then he solved the problem and proved that there's a finite number of unlabeled Hagh trees!Amazed by this fact, he shared the task with you so that you could enjoy solving it as well. Since the answer can be rather large he asked you to find the number of different unlabeled Hagh trees modulo $$$998244353$$$.Here two trees are considered different, if they are not isomorphic: if there is no way to map nodes of one tree to the second tree, so that edges are mapped to edges preserving the orientation.Some examples for $$$n = 2$$$: Directed trees $$$D$$$ and $$$E$$$ are Hagh. $$$C$$$ is not Hagh because it has a vertex with $$$4$$$ edges attached to it. $$$A$$$ and $$$B$$$ are not Hagh because their longest directed paths are not equal to $$$n$$$. Also in $$$B$$$ the leftmost and rightmost vertices are not friends neither do they have a mutual friend.", "input_spec": "The first line of input contains a single integer $$$n$$$ $$$(1 \\le n \\le 10^6)$$$.", "output_spec": "Print a single integer, the answer to Mashtali's task modulo $$$998244353$$$.", "sample_inputs": ["1", "2", "344031"], "sample_outputs": ["5", "31", "272040628"], "notes": "NoteAll the five Hagh trees for $$$n = 1$$$: "}, "positive_code": [{"source_code": "// 2022.06.23 at 21:23:35 HKT\r\nimport java.io.BufferedInputStream\r\nimport java.io.File\r\nimport java.io.PrintWriter\r\nimport kotlin.system.measureTimeMillis\r\nimport java.util.TreeMap\r\nimport java.util.TreeSet\r\nimport kotlin.random.Random\r\nimport kotlin.random.nextInt\r\n\r\n// 1. Modded\r\nconst val p = 998244353L\r\nconst val pI = p.toInt()\r\nfun Int.adjust():Int{ if(this >= pI){ return this - pI }else if (this < 0){ return this + pI };return this }\r\nfun Int.snap():Int{ if(this >= pI){return this - pI} else return this}\r\ninfix fun Int.modM(b:Int):Int{ return ((this.toLong() * b) % pI).toInt() }\r\ninfix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }\r\nfun intPow(x:Int,e:Int,m:Int):Int{\r\n var X = x ; var E =e ; var Y = 1\r\n while(E > 0){\r\n if(E and 1 == 0){\r\n X = ((1L * X * X) % m).toInt()\r\n E = E shr 1\r\n }else{\r\n Y = ((1L * X * Y) % m).toInt()\r\n E -= 1\r\n }\r\n }\r\n return Y\r\n}\r\n// 2. DP initial values\r\nconst val plarge = 1_000_000_727\r\nconst val nlarge = -plarge\r\nconst val phuge = 2_727_000_000_000_000_000L\r\nconst val nhuge = -phuge\r\n// 3. conveniecen conversions\r\nval Boolean.chi:Int get() = if(this) 1 else 0 //characteristic function\r\nval Char.code :Int get() = this.toInt() - 'a'.toInt()\r\n//3. hard to write stuff\r\nfun IntArray.put(i:Int,v:Int){ this[i] = (this[i] + v).adjust() }\r\nval mint:MutableList get() = mutableListOf()\r\nval mong:MutableList get() = mutableListOf()\r\n//4. more outputs\r\nfun List.conca():String = this.joinToString(\"\")\r\nval CharArray.conca :String get() = this.joinToString(\"\")\r\nval IntArray.conca :String get() = this.joinToString(\" \")\r\n@JvmName(\"concaInt\")\r\nfun List.conca():String = this.joinToString(\" \")\r\nval LongArray.conca:String get() = this.joinToString(\" \")\r\n@JvmName(\"concaLong\")\r\nfun List.conca():String = this.joinToString(\" \")\r\n//5. Pair of ints\r\nconst val longmask = (1L shl 32) - 1\r\nfun makepair(a:Int, b:Int):Long = (a.toLong() shl 32) xor (longmask and b.toLong()) // remember positev sonly\r\nval Long.first get() = (this ushr 32).toInt()\r\nval Long.second get() = this.toInt()\r\n//6. strings\r\nval String.size get() = this.length\r\nconst val randCount = 100\r\n//7. bits\r\nfun Int.has(i:Int):Boolean = (this and (1 shl i) != 0)\r\nfun Long.has(i:Int):Boolean = (this and (1L shl i) != 0L)\r\n//8 TIME\r\ninline fun TIME(f:()->Unit){\r\n val t = measureTimeMillis(){\r\n f()\r\n }\r\n println(\"$t ms\")\r\n}\r\nobject Reader{\r\n private const val BS = 1 shl 16\r\n private const val NC = 0.toChar()\r\n private val buf = ByteArray(BS)\r\n private var bId = 0\r\n private var size = 0\r\n private var c = NC\r\n\r\n var warningActive = true\r\n var fakein = StringBuilder()\r\n\r\n private var IN: BufferedInputStream = BufferedInputStream(System.`in`, BS)\r\n val OUT: PrintWriter = PrintWriter(System.out)\r\n\r\n private val char: Char\r\n get() {\r\n while (bId == size) {\r\n size = IN.read(buf) // no need for checked exceptions\r\n if (size == -1) return NC\r\n bId = 0\r\n }\r\n return buf[bId++].toChar()\r\n }\r\n\r\n fun nextInt(): Int {\r\n var neg = false\r\n if (c == NC) c = char\r\n while (c < '0' || c > '9') {\r\n if (c == '-') neg = true\r\n c = char\r\n }\r\n var res = 0\r\n while (c in '0'..'9') {\r\n res = (res shl 3) + (res shl 1) + (c - '0')\r\n c = char\r\n }\r\n return if (neg) -res else res\r\n }\r\n fun nextLong(): Long {\r\n var neg = false\r\n if (c == NC) c = char\r\n while (c < '0' || c > '9') {\r\n if (c == '-') neg = true\r\n c = char\r\n }\r\n var res = 0L\r\n while (c in '0'..'9') {\r\n res = (res shl 3) + (res shl 1) + (c - '0')\r\n c = char\r\n }\r\n return if (neg) -res else res\r\n }\r\n fun nextString():String{\r\n val ret = StringBuilder()\r\n while (true){\r\n c = char\r\n if(!isWhitespace(c)){ break}\r\n }\r\n ret.append(c)\r\n while (true){\r\n c = char\r\n if(isWhitespace(c)){ break}\r\n ret.append(c)\r\n }\r\n return ret.toString()\r\n }\r\n fun isWhitespace(c:Char):Boolean{\r\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t'\r\n }\r\n fun rerouteInput(){\r\n if(warningActive){\r\n put(\"Custom test enabled\")\r\n println(\"Custom test enabled\")\r\n warningActive = false\r\n }\r\n val S = fakein.toString()\r\n println(\"New Case \")\r\n println(S.take(80))\r\n println(\"...\")\r\n fakein.clear()\r\n IN = BufferedInputStream(S.byteInputStream(),BS)\r\n }\r\n fun takeFile(name:String){\r\n IN = BufferedInputStream(File(name).inputStream(),BS)\r\n }\r\n}\r\nfun put(aa:Any){ Reader.OUT.println(aa)}\r\nfun done(){ Reader.OUT.close() }\r\nfun share(aa:Any){\r\n if(aa is IntArray){Reader.fakein.append(aa.joinToString(\" \"))}\r\n else if(aa is LongArray){Reader.fakein.append(aa.joinToString(\" \"))}\r\n else if(aa is List<*>){Reader.fakein.append(aa.toString())}\r\n else{Reader.fakein.append(aa.toString())}\r\n Reader.fakein.append(\"\\n\")\r\n}\r\n\r\nval getintfast:Int get() = Reader.nextInt()\r\nval getint:Int get(){ val ans = getlong ; if(ans > Int.MAX_VALUE) IntArray(1000000000); return ans.toInt() }\r\nval getlong:Long get() = Reader.nextLong()\r\nval getstr:String get() = Reader.nextString()\r\nfun getline(n:Int):IntArray{\r\n return IntArray(n){getint}\r\n}\r\nfun getlineL(n:Int):LongArray{\r\n return LongArray(n){getlong}\r\n}\r\nvar dmark = -1\r\ninfix fun Any.dei(a:Any){\r\n dmark++\r\n var str = \"<${dmark}> \"\r\n debug()\r\n if(this is String){ str += this\r\n }else if(this is Int){ str += this.toString()\r\n }else if(this is Long){ str += this.toString()\r\n }else{ str += this.toString()}\r\n if(a is List<*>){ println(\"$str : ${a.joinToString(\" \")}\")\r\n }else if(a is IntArray){ println(\"$str : ${a.joinToString(\" \")}\")\r\n }else if(a is LongArray){ println(\"$str : ${a.joinToString(\" \")}\")\r\n }else if(a is BooleanArray){ println(\"$str :${a.map{if(it)'1' else '0'}.joinToString(\" \")}\")\r\n }else if(a is Array<*>){\r\n println(\"$str : \")\r\n for(c in a){if(c is IntArray){println(c.joinToString(\" \"))}\r\n else if(c is LongArray){println(c.joinToString(\" \"))}\r\n else if(c is BooleanArray){println(c.map { if(it) '1' else '0' }.joinToString(\"\"))\r\n }\r\n }\r\n println()\r\n }else{ println(\"$str : $a\")\r\n }\r\n}\r\nval just = \" \"\r\nfun crash(){\r\n throw Exception(\"Bad programme\")}\r\nfun assert(a:Boolean){\r\n if(!a){\r\n throw Exception(\"Failed Assertion\")\r\n }}\r\nenum class solveMode {\r\n real, rand, tc\r\n}\r\nobject solve{\r\n var mode:solveMode = solveMode.real\r\n var tcNum:Int = 0\r\n var rand:()->Unit = {}\r\n var TC:MutableMapUnit> = mutableMapOf()\r\n var tn:Long = 0\r\n fun cases(onecase:()->Unit){\r\n val t = if(mode == solveMode.real){if(singleCase) 1 else getint} else if(mode == solveMode.tc){1 } else randCount\r\n if(pI != 998_244_353 && pI != 1_000_000_007){\r\n throw Exception(\"Not usual primes!\")\r\n }\r\n if(t == 1 && mode != solveMode.real){\r\n tn = System.currentTimeMillis()\r\n }\r\n repeat(t){\r\n if(mode == solveMode.tc){\r\n TC[tcNum]?.let { it() }\r\n Reader.rerouteInput()\r\n }else if(mode == solveMode.rand){\r\n rand()\r\n Reader.rerouteInput()\r\n }\r\n onecase()\r\n }\r\n if(t == 1 && mode != solveMode.real){\r\n val dt = System.currentTimeMillis() - tn\r\n println(\"Time $dt ms \")\r\n }\r\n }\r\n inline fun singleCase(a:solve.()->Unit){\r\n val t = if(mode != solveMode.rand){1} else randCount\r\n repeat(t) { a() }\r\n }\r\n fun rand(a:()->Unit){\r\n this.rand = a\r\n }\r\n fun tc(id:Int = 0,a:()->Unit){\r\n TC[id] = a\r\n }\r\n fun usetc(a:Int = 0 ){\r\n this.tcNum = a\r\n this.mode = solveMode.tc\r\n }\r\n fun userand(){\r\n this.mode = solveMode.rand\r\n }\r\n}\r\n\r\n\r\ninfix fun Long.modM(b:Long):Long{\r\n return (this * b) % p\r\n}\r\n//infix fun Int.modPlus(b:Int):Int{\r\n// val ans = this + b\r\n// return if(ans >= pI) ans - pI else ans\r\n//}\r\ninfix fun Int.modMinus(b:Int):Int{\r\n val ans = this - b\r\n return if(ans < 0) ans + pI else ans\r\n}\r\ninfix fun Int.modDivide(b:Int):Int{\r\n return this modM (b.inverse())\r\n}\r\nfun Int.additiveInverse():Int{\r\n return if(this == 0) 0 else pI - this\r\n}\r\n\r\nfun intPowEXP(x:Int,e:Long,m:Int):Int{\r\n var X = x\r\n var E =e\r\n var Y = 1\r\n while(E > 0){\r\n if(E % 2 == 0L){\r\n X = ((1L * X * X) % m).toInt()\r\n E = E shr 1\r\n }else{\r\n Y = ((1L * X * Y) % m).toInt()\r\n E -= 1\r\n }\r\n }\r\n return Y\r\n}\r\n\r\nfun pow(x:Long,e:Long,m:Long):Long{\r\n var X = x\r\n var E =e\r\n var Y = 1L\r\n while(E > 0){\r\n if(E % 2 == 0L){\r\n X = (X * X) % m\r\n E /= 2\r\n }else{\r\n Y = (X * Y) % m\r\n E -= 1\r\n }\r\n }\r\n return Y\r\n}\r\nfun Long.inverse():Long{\r\n return pow(this,p-2,p)\r\n}\r\nfun Int.inverse():Int{\r\n return intPow(this,pI-2,pI)\r\n}\r\nfun min_rem(m:Int, r:Int, c:Int):Int {\r\n if(c < 1){\r\n return Int.MIN_VALUE\r\n }else if(r == 0){\r\n return 0\r\n }else{\r\n val step = m % r\r\n val mx = ((1L * c * r) /m ).toInt()\r\n val t = max_rem(r,step,mx)\r\n return r- t\r\n }\r\n}\r\nfun max_rem(m:Int, r:Int, c:Int):Int {\r\n if(r == 0|| c <= m/r){\r\n return r * c\r\n }else{\r\n val step = m % r\r\n val mx = ((1L * (c+1) * r )/m).toInt()\r\n val t = min_rem(r,step,mx)\r\n return m - t\r\n }\r\n}\r\nfun Int.reconstruct():String{\r\n val num = min_rem(pI,this, 10000)\r\n val denom = (this modDivide num).inverse()\r\n return \"$num / $denom\"\r\n}\r\n\r\n//make this int instead\r\nclass FACT{\r\n companion object {\r\n var store = IntArray(0)\r\n var invStore = IntArray(0)\r\n\r\n var slowStore:IntArray = IntArray(0)\r\n\r\n fun preCal(upto:Int){\r\n store = IntArray(upto+1)\r\n invStore = IntArray(upto + 1 )\r\n store[0] = 1\r\n invStore[0] = 1\r\n\r\n for(i in 1..upto) {\r\n store[i] = store[i-1] modM i\r\n invStore[i] = invStore[i-1] modM (i.inverse())\r\n }\r\n }\r\n fun choose(n:Int,r:Int):Int{\r\n if(r < 0 || r > n) return 0\r\n val a = store[n]\r\n val b = invStore[n-r]\r\n val c = invStore[r]\r\n return (a modM b) modM c\r\n }\r\n\r\n fun bigChoose(n:Int,r:Int):Int{\r\n var ret = 1\r\n for(i in 0 until r){\r\n ret = ret modM (n - i)\r\n }\r\n ret = ret modM (invStore[r])\r\n return ret\r\n }\r\n\r\n }\r\n}\r\n\r\nfun debug(){}\r\nconst val singleCase = true\r\nfun main(){\r\n FACT.preCal(100)\r\n solve.cases{\r\n val n = getint\r\n val max = 1000001\r\n val root1 = IntArray(max)\r\n val root2 = IntArray(max)\r\n val root3 = IntArray(max)\r\n val onetwosum = IntArray(max)\r\n root1[1] = 1\r\n root2[1] = 1\r\n root3[1] = 1\r\n onetwosum[0] = 1\r\n onetwosum[1] = 3 // any length, from 0 upto i\r\n for(i in 2 until max){\r\n val base = onetwosum[i-1]\r\n val reject = onetwosum[i-2]\r\n root1[i] = base modMinus reject\r\n root2[i] = FACT.bigChoose(base + 1, 2) modMinus FACT.bigChoose(reject + 1,2)\r\n root3[i] = FACT.bigChoose(base + 2 , 3) modMinus FACT.bigChoose(reject + 2 , 3)\r\n onetwosum[i] = onetwosum[i-1] modPlus (root1[i] modPlus root2[i])\r\n }\r\n var fullret = 0\r\n for(anchor in 0..n){\r\n val right = n - anchor\r\n val left = anchor\r\n var ret = ( root1[left] modM root2[right])\r\n //(root1[right] modM root1[left]) modPlus (root1[right] modM root2[left]) modPlus\r\n fullret = ret modPlus fullret\r\n }\r\n fullret = fullret modPlus ((root3[n] modPlus root2[n] modPlus root1[n]) modM 2) modMinus root1[n]\r\n put(fullret)\r\n\r\n\r\n\r\n\r\n\r\n }\r\n done()\r\n}\r\n\r\n\r\n\r\n"}], "negative_code": [], "src_uid": "92939054045c089cd25c8f4e7b9ffcf2"} {"nl": {"description": "Mishka got a six-faced dice. It has integer numbers from $$$2$$$ to $$$7$$$ written on its faces (all numbers on faces are different, so this is an almost usual dice).Mishka wants to get exactly $$$x$$$ points by rolling his dice. The number of points is just a sum of numbers written at the topmost face of the dice for all the rolls Mishka makes.Mishka doesn't really care about the number of rolls, so he just wants to know any number of rolls he can make to be able to get exactly $$$x$$$ points for them. Mishka is very lucky, so if the probability to get $$$x$$$ points with chosen number of rolls is non-zero, he will be able to roll the dice in such a way. Your task is to print this number. It is guaranteed that at least one answer exists.Mishka is also very curious about different number of points to score so you have to answer $$$t$$$ independent queries.", "input_spec": "The first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 100$$$) — the number of queries. Each of the next $$$t$$$ lines contains one integer each. The $$$i$$$-th line contains one integer $$$x_i$$$ ($$$2 \\le x_i \\le 100$$$) — the number of points Mishka wants to get.", "output_spec": "Print $$$t$$$ lines. In the $$$i$$$-th line print the answer to the $$$i$$$-th query (i.e. any number of rolls Mishka can make to be able to get exactly $$$x_i$$$ points for them). It is guaranteed that at least one answer exists.", "sample_inputs": ["4\n2\n13\n37\n100"], "sample_outputs": ["1\n3\n8\n27"], "notes": "NoteIn the first query Mishka can roll a dice once and get $$$2$$$ points.In the second query Mishka can roll a dice $$$3$$$ times and get points $$$5$$$, $$$5$$$ and $$$3$$$ (for example).In the third query Mishka can roll a dice $$$8$$$ times and get $$$5$$$ points $$$7$$$ times and $$$2$$$ points with the remaining roll.In the fourth query Mishka can roll a dice $$$27$$$ times and get $$$2$$$ points $$$11$$$ times, $$$3$$$ points $$$6$$$ times and $$$6$$$ points $$$10$$$ times."}, "positive_code": [{"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n//https://www.javatpoint.com/kotlin-smart-cast\nfun main() {\n val read=Scanner(System.`in`);\n var test=read.nextInt();\n while((test--)>0){\n var x=read.nextInt();\n var cnt=0;\n if(x%2==1){\n x-=3;\n cnt+=1;\n }\n cnt+=x/2;\n println(cnt);\n }\n}\n"}, {"source_code": "import kotlin.math.sign\n\nfun main() {\n repeat(readInt()) {\n val n = readInt()\n println(n / 7 + (n % 7).sign)\n }\n}\n\nfun readInt() = readLine()?.toInt() ?: 0"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val T = readInt()\n for (t in 0..T-1) {\n val n = readInt()\n println(n / 2)\n }\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\n\n internal var br = BufferedReader(InputStreamReader(System.`in`))\n internal var st: StringTokenizer? = null\n internal var out = PrintWriter(System.out)\n\n @Throws(IOException::class)\n private fun solve() {\n val t = nextInt()\n for (i in 0 until t) {\n val x = nextInt()\n out.println(x / 2)\n }\n }\n\n internal fun next(): String {\n while (st == null || !st!!.hasMoreTokens()) {\n st = StringTokenizer(br.readLine())\n }\n return st!!.nextToken()\n }\n\n @Throws(IOException::class)\n internal fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n @Throws(IOException::class)\n internal fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n @Throws(IOException::class)\n private fun run() {\n solve()\n out.close()\n }\n\n\n fun main(args: Array) {\n run()\n }\n\n\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nobject programkt {\n @JvmStatic\n fun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val `in` = InputReader(inputStream)\n val out = OutputWriter(outputStream)\n val solver = Problem()\n solver.solve(`in`, out)\n out.close()\n }\n\n internal class Problem {\n fun solve(`in`: InputReader, out: OutputWriter) {\n val t = `in`.readInt()\n val x = IntArray(t)\n for (i in 0 until t) x[i] = `in`.readInt()\n for (i in 0 until t) out.printLine(x[i] / 2)\n }\n }\n\n internal class InputReader(private val stream: InputStream) {\n private val buf = ByteArray(1024)\n private var curChar: Int = 0\n private var numChars: Int = 0\n private val filter: SpaceCharFilter? = null\n\n fun read(): Int {\n if (numChars == -1)\n throw InputMismatchException()\n if (curChar >= numChars) {\n curChar = 0\n try {\n numChars = stream.read(buf)\n } catch (e: IOException) {\n throw InputMismatchException()\n }\n\n if (numChars <= 0)\n return -1\n }\n return buf[curChar++].toInt()\n }\n\n fun readInt(): Int {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n var sgn = 1\n if (c == '-'.toInt()) {\n sgn = -1\n c = read()\n }\n var res = 0\n do {\n if (c < '0'.toInt() || c > '9'.toInt())\n throw InputMismatchException()\n res *= 10\n res += c - '0'.toInt()\n c = read()\n } while (!isSpaceChar(c))\n return res * sgn\n }\n\n fun readLong(): Long {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n var sgn = 1\n if (c == '-'.toInt()) {\n sgn = -1\n c = read()\n }\n var res: Long = 0\n do {\n if (c < '0'.toInt() || c > '9'.toInt())\n throw InputMismatchException()\n res *= 10\n res += (c - '0'.toInt()).toLong()\n c = read()\n } while (!isSpaceChar(c))\n return res * sgn\n }\n\n fun readString(): String {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n val res = StringBuilder()\n do {\n res.appendCodePoint(c)\n c = read()\n } while (!isSpaceChar(c))\n return res.toString()\n }\n\n fun isSpaceChar(c: Int): Boolean {\n return filter?.isSpaceChar(c)\n ?: (c == ' '.toInt() || c == '\\n'.toInt() || c == '\\r'.toInt() || c == '\\t'.toInt() || c == -1)\n }\n\n operator fun next(): String {\n return readString()\n }\n\n interface SpaceCharFilter {\n fun isSpaceChar(ch: Int): Boolean\n }\n }\n\n internal class OutputWriter {\n private val writer: PrintWriter\n\n constructor(outputStream: OutputStream) {\n writer = PrintWriter(BufferedWriter(OutputStreamWriter(outputStream)))\n }\n\n constructor(writer: Writer) {\n this.writer = PrintWriter(writer)\n }\n\n fun print(vararg objects: Any) {\n for (i in objects.indices) {\n if (i != 0)\n writer.print(' ')\n writer.print(objects[i])\n }\n }\n\n fun printLine(vararg objects: Any) {\n print(*objects)\n writer.println()\n }\n\n fun close() {\n writer.close()\n }\n }\n}\n\n"}, {"source_code": "fun main() {\n val n = readInt()\n for (j in 1..n) {\n val v = readInt()\n println(v / 2)\n }\n}\n\nfun readln() = readLine()!!\nfun readlnByte() = readln().toByte()\nfun readlnShort() = readln().toShort()\nfun readlnInt() = readln().toInt()\nfun readlnLong() = readln().toLong()\nfun readlnFloat() = readln().toFloat()\nfun readlnDouble() = readln().toDouble()\nfun readlnBigInt(radix: Int = 10) = readln().toBigInteger(radix)\nfun readlnBigDecimal() = readln().toBigDecimal()\n\nfun lineSequence(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.constrainOnce().take(limit)\nfun readlnStrings() = readln().split(' ')\nfun readlnBytes() = readlnStrings().map { it.toByte() }\nfun readlnShorts() = readlnStrings().map { it.toShort() }\nfun readlnInts() = readlnStrings().map { it.toInt() }\nfun readlnLongs() = readlnStrings().map { it.toLong() }\nfun readlnFloats() = readlnStrings().map { it.toFloat() }\nfun readlnDoubles() = readlnStrings().map { it.toDouble() }\n\nfun readByteArray() = readlnStrings().run { ByteArray(size) { get(it).toByte() } }\nfun readShortArray() = readlnStrings().run { ShortArray(size) { get(it).toShort() } }\nfun readIntArray() = readlnStrings().run { IntArray(size) { get(it).toInt() } }\nfun readLongArray() = readlnStrings().run { LongArray(size) { get(it).toLong() } }\nfun readFloatArray() = readlnStrings().run { FloatArray(size) { get(it).toFloat() } }\nfun readDoubleArray() = readlnStrings().run { DoubleArray(size) { get(it).toDouble() } }\n\nfun readlnByteArray(n: Int) = ByteArray(n) { readlnByte() }\nfun readlnShortArray(n: Int) = ShortArray(n) { readlnShort() }\nfun readlnIntArray(n: Int) = IntArray(n) { readlnInt() }\nfun readlnLongArray(n: Int) = LongArray(n) { readlnLong() }\nfun readlnFloatArray(n: Int) = FloatArray(n) { readlnFloat() }\nfun readlnDoubleArray(n: Int) = DoubleArray(n) { readlnDouble() }\n\nfun readByteArray2d(rows: Int, cols: Int) = Array(rows) { readByteArray().also { require(it.size == cols) } }\nfun readShortArray2d(rows: Int, cols: Int) = Array(rows) { readShortArray().also { require(it.size == cols) } }\nfun readLongArray2d(rows: Int, cols: Int) = Array(rows) { readLongArray().also { require(it.size == cols) } }\nfun readIntArray2d(rows: Int, cols: Int) = Array(rows) { readIntArray().also { require(it.size == cols) } }\nfun readFloatArray2d(rows: Int, cols: Int) = Array(rows) { readFloatArray().also { require(it.size == cols) } }\nfun readDoubleArray2d(rows: Int, cols: Int) = Array(rows) { readDoubleArray().also { require(it.size == cols) } }\n\nfun isWhiteSpace(c: Char) = c in \" \\r\\n\\t\"\n\n// JVM-only targeting code follows next\n\n// readString() via sequence is still slightly faster than Scanner\nfun readString() = generateSequence { System.`in`.read().toChar() }\n .dropWhile { isWhiteSpace(it) }.takeWhile { !isWhiteSpace(it) }.joinToString(\"\")\n\nfun readByte() = readString().toByte()\nfun readShort() = readString().toShort()\nfun readInt() = readString().toInt()\nfun readLong() = readString().toLong()\nfun readFloat() = readString().toFloat()\nfun readDouble() = readString().toDouble()\nfun readBigInt(radix: Int = 10) = readString().toBigInteger(radix)\nfun readBigDecimal() = readString().toBigDecimal()\n\nfun readBytes(n: Int) = generateSequence { readByte() }.take(n)\nfun readShorts(n: Int) = generateSequence { readShort() }.take(n)\nfun readInts(n: Int) = generateSequence { readInt() }.take(n)\nfun readLongs(n: Int) = generateSequence { readLong() }.take(n)\nfun readFloats(n: Int) = generateSequence { readFloat() }.take(n)\nfun readDoubles(n: Int) = generateSequence { readDouble() }.take(n)\n\n"}, {"source_code": "import kotlin.math.sign\n\nclass DiceRolling {\n data class Problem(val id: Int, val target: Int)\n\n data class Solution(val count: Int) {\n override fun toString(): String {\n return \"$count\\n\"\n }\n }\n\n fun readProblem(problemId: Int): Problem {\n return Problem(problemId, readLine()!!.toInt())\n }\n\n fun solveProblem(problem: Problem): Solution {\n return Solution(problem.target / 7 + (problem.target % 7).sign)\n }\n}\n\nfun main() {\n val diceRolling = DiceRolling()\n val n = readLine()!!.toInt()\n (1..n).map(diceRolling::readProblem)\n .map(diceRolling::solveProblem)\n .onEach(::print)\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n var T = readInt()\n while(T>0) {\n var x = readInt()\n println(\"%d\".format(x/2))\n T--\n }\n\n}"}, {"source_code": "fun main(args : Array) {\n val numberOfQueries = readLine()!!.toInt()\n \n for (i in 1..numberOfQueries) {\n println(readLine()!!.toInt() / 2)\n }\n}\n"}, {"source_code": "fun readInt(separator: Char = ' ') = readLine()!!.toInt()\nfun main() {\n val n = readInt()\n for(i in 0 until n){\n val x = readInt()/2\n println(\"$x\")\n }\n}"}, {"source_code": "fun x()=readLine()!!.toInt()\nfun main()=repeat(x()){println(x()/2)}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n repeat(n) {\n val x = readLine()!!.toInt()\n val res = if (x > 7) {\n x/7 + 1\n } else 1\n println(res)\n }\n}"}, {"source_code": "import kotlin.math.min\n\nval dp = IntArray(103)\n\nfun main(){\n dp[0] = 0\n for(i in 1..100){\n dp[i] = Int.MAX_VALUE\n for(j in 2..7)\n if(i >= j && dp[i-j] != Int.MAX_VALUE)\n dp[i] = min(dp[i], 1 + dp[i-j])\n }\n val t = readLine()!!.toInt()\n repeat(t){\n val x = readLine()!!.toInt()\n println(dp[x])\n }\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\n\n internal var br = BufferedReader(InputStreamReader(System.`in`))\n internal var st: StringTokenizer? = null\n internal var out = PrintWriter(System.out)\n\n @Throws(IOException::class)\n private fun solve() {\n val t = nextInt()\n for (i in 0 until t) {\n val x = nextInt()\n out.println(x / 2)\n }\n }\n\n internal fun next(): String {\n while (st == null || !st!!.hasMoreTokens()) {\n st = StringTokenizer(br.readLine())\n }\n return st!!.nextToken()\n }\n\n @Throws(IOException::class)\n internal fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n @Throws(IOException::class)\n internal fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n @Throws(IOException::class)\n private fun run() {\n solve()\n out.close()\n }\n\n\n fun main(args: Array) {\n run()\n }\n\n\n"}, {"source_code": "import java.util.*\n\nfun main() {\n\n val scanner = Scanner(System.`in`)\n var t = scanner.nextInt()\n\n while (t > 0) {\n t--\n val num = scanner.nextInt()\n var idx=2\n while (idx<=7){\n val c = num % idx\n val c2 = num / idx\n if (c != 1) {\n if (c > 0) println(c2 + 1)\n else println(c2)\n break\n }\n idx++\n }\n }\n}"}, {"source_code": "fun main(args: Array)\n{\nval t=readLine()!!.toInt()\nrepeat(t)\n{\nval n=readLine()!!.toInt()\n\nprintln(n/2);\n\n}\n}"}, {"source_code": "fun main() {\n val n = Integer.valueOf(readLine()!!)\n\n repeat(n) {\n val x = Integer.valueOf(readLine()!!)\n if(x % 7 == 0) {\n println(x / 7)\n } else if(x % 7 == 1){\n println(x / 7 + 2)\n } else {\n println(x / 7 + 1)\n }\n }\n}"}, {"source_code": "fun main() {\n val n = readInt()\n for (j in 1..n) {\n val v = readInt()\n println(v / 2)\n }\n}\n\nfun readln() = readLine()!!\nfun readlnByte() = readln().toByte()\nfun readlnShort() = readln().toShort()\nfun readlnInt() = readln().toInt()\nfun readlnLong() = readln().toLong()\nfun readlnFloat() = readln().toFloat()\nfun readlnDouble() = readln().toDouble()\nfun readlnBigInt(radix: Int = 10) = readln().toBigInteger(radix)\nfun readlnBigDecimal() = readln().toBigDecimal()\n\nfun lineSequence(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.constrainOnce().take(limit)\nfun readlnStrings() = readln().split(' ')\nfun readlnBytes() = readlnStrings().map { it.toByte() }\nfun readlnShorts() = readlnStrings().map { it.toShort() }\nfun readlnInts() = readlnStrings().map { it.toInt() }\nfun readlnLongs() = readlnStrings().map { it.toLong() }\nfun readlnFloats() = readlnStrings().map { it.toFloat() }\nfun readlnDoubles() = readlnStrings().map { it.toDouble() }\n\nfun readByteArray() = readlnStrings().run { ByteArray(size) { get(it).toByte() } }\nfun readShortArray() = readlnStrings().run { ShortArray(size) { get(it).toShort() } }\nfun readIntArray() = readlnStrings().run { IntArray(size) { get(it).toInt() } }\nfun readLongArray() = readlnStrings().run { LongArray(size) { get(it).toLong() } }\nfun readFloatArray() = readlnStrings().run { FloatArray(size) { get(it).toFloat() } }\nfun readDoubleArray() = readlnStrings().run { DoubleArray(size) { get(it).toDouble() } }\n\nfun readlnByteArray(n: Int) = ByteArray(n) { readlnByte() }\nfun readlnShortArray(n: Int) = ShortArray(n) { readlnShort() }\nfun readlnIntArray(n: Int) = IntArray(n) { readlnInt() }\nfun readlnLongArray(n: Int) = LongArray(n) { readlnLong() }\nfun readlnFloatArray(n: Int) = FloatArray(n) { readlnFloat() }\nfun readlnDoubleArray(n: Int) = DoubleArray(n) { readlnDouble() }\n\nfun readByteArray2d(rows: Int, cols: Int) = Array(rows) { readByteArray().also { require(it.size == cols) } }\nfun readShortArray2d(rows: Int, cols: Int) = Array(rows) { readShortArray().also { require(it.size == cols) } }\nfun readLongArray2d(rows: Int, cols: Int) = Array(rows) { readLongArray().also { require(it.size == cols) } }\nfun readIntArray2d(rows: Int, cols: Int) = Array(rows) { readIntArray().also { require(it.size == cols) } }\nfun readFloatArray2d(rows: Int, cols: Int) = Array(rows) { readFloatArray().also { require(it.size == cols) } }\nfun readDoubleArray2d(rows: Int, cols: Int) = Array(rows) { readDoubleArray().also { require(it.size == cols) } }\n\nfun isWhiteSpace(c: Char) = c in \" \\r\\n\\t\"\n\n// JVM-only targeting code follows next\n\n// readString() via sequence is still slightly faster than Scanner\nfun readString() = generateSequence { System.`in`.read().toChar() }\n .dropWhile { isWhiteSpace(it) }.takeWhile { !isWhiteSpace(it) }.joinToString(\"\")\n\nfun readByte() = readString().toByte()\nfun readShort() = readString().toShort()\nfun readInt() = readString().toInt()\nfun readLong() = readString().toLong()\nfun readFloat() = readString().toFloat()\nfun readDouble() = readString().toDouble()\nfun readBigInt(radix: Int = 10) = readString().toBigInteger(radix)\nfun readBigDecimal() = readString().toBigDecimal()\n\nfun readBytes(n: Int) = generateSequence { readByte() }.take(n)\nfun readShorts(n: Int) = generateSequence { readShort() }.take(n)\nfun readInts(n: Int) = generateSequence { readInt() }.take(n)\nfun readLongs(n: Int) = generateSequence { readLong() }.take(n)\nfun readFloats(n: Int) = generateSequence { readFloat() }.take(n)\nfun readDoubles(n: Int) = generateSequence { readDouble() }.take(n)\n\n"}, {"source_code": "import java.util.*\n \nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = readLine()!!.toInt()\n for(x in 0..n-1){\n \tval tmp = readLine()!!.toInt()\n \tif(tmp <= 6) println(\"1\")\n \telse{\n \t\tprintln(tmp/6+1)\n \t}\n }\n \n}"}, {"source_code": "fun main() {\n for (i in 1..r())\n println(r() / 2)\n}\n\ninline fun r() = readLine()!!.toInt()"}, {"source_code": "fun main(){\n fun x()=readLine()!!.toInt()\n for(i in 1..x())println(x()/2)\n}"}, {"source_code": "fun readInt(): Int {\n return readLine()!!.toInt()\n}\n\nfun main() {\n val T = readInt()\n for(i in 1..T) {\n var result = 0\n var n = readInt()\n while(n > 0) {\n if(n % 7 == 1)\n n -= 4\n else if(n >= 7)\n n -= 7\n else\n n -= n % 7\n result++\n }\n println(result)\n }\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\n\n internal var br = BufferedReader(InputStreamReader(System.`in`))\n internal var st: StringTokenizer? = null\n internal var out = PrintWriter(System.out)\n\n @Throws(IOException::class)\n private fun solve() {\n val t = nextInt()\n for (i in 0 until t) {\n val x = nextInt()\n out.println(x / 2)\n }\n }\n\n internal fun next(): String {\n while (st == null || !st!!.hasMoreTokens()) {\n st = StringTokenizer(br.readLine())\n }\n return st!!.nextToken()\n }\n\n @Throws(IOException::class)\n internal fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n @Throws(IOException::class)\n internal fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n @Throws(IOException::class)\n private fun run() {\n solve()\n out.close()\n }\n\n\n fun main(args: Array) {\n run()\n }\n\n\n"}, {"source_code": "import java.io.FileInputStream\nimport java.util.*\n\nobject programkt {\n @JvmStatic fun main(args: Array) {\n if (args.size == 1)\n System.setIn(FileInputStream(args[0]))\n val sc = Scanner(System.`in`)\n val t = sc.nextInt()\n IntRange(1, t).forEach {\n val x = sc.nextInt()\n println(x / 2)\n }\n }\n}\n"}, {"source_code": "fun main(args : Array) {\n val numberOfQueries = readLine()!!.toInt()\n\n for (i in 1..numberOfQueries) {\n val points = readLine()!!.toInt()\n\n if (points % 2 == 0) {\n println(points / 2)\n } else {\n println((points - 3) / 2 + 1)\n }\n }\n}\n"}, {"source_code": "fun main() {\n for (i in 1..readLine()!!.toInt()) {\n println(readLine()!!.toInt() / 2)\n }\n}\n"}, {"source_code": "import kotlin.math.sign\n\nfun main() {\n repeat(readInt()) {\n val n = readInt()\n println(n / 7 + (n % 7).sign)\n }\n}\n\nfun readInt() = readLine()?.toInt() ?: 0"}, {"source_code": "//package com.happypeople.codeforces.c1093\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\n\nfun main(args: Array) {\n try {\n A().run()\n } catch (e: Throwable) {\n A.log(\"\" + e)\n }\n}\n\nclass A {\n fun run() {\n val sc = Scanner(systemIn())\n val n=sc.nextInt()\n (1..n).forEach {\n val i=sc.nextInt()\n val rolls=if(i==2) 1 else i/3\n println(\"$rolls\")\n }\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}"}, {"source_code": "import java.util.Scanner\n\nobject programkt {\n @JvmStatic fun main(args:Array) {\n val sc = Scanner(System.`in`)\n val t = sc.nextInt()\n for (i in 0 until t)\n {\n val x = sc.nextInt()\n if (x <= 7)\n {\n println(1)\n }\n else\n {\n println(x / 2)\n }\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n for (i in 1..n) {\n val t1 = readLine()!!.toInt()\n println(getCount(t1))\n }\n}\n\nfun getCount(x: Int): Int {\n var c = 0\n var s = x\n if (x % 2 != 0) {\n s -= 3\n c++\n }\n c += s / 2\n return c\n}"}, {"source_code": "fun main(args: Array) {\n val t = readLine()!!.toInt()\n repeat(t) {\n val x = readLine()!!.toInt()\n println((x + 6) / 7)\n }\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n for(i in 0 until n){\n val x = readLine()!!.toInt()\n println((x+6)/7)\n }\n}\n"}, {"source_code": "fun main(args: Array){\n var t:Int = readLine()?.toInt()?:0\n for(i in 1..t)\n {\n var b:Int = readLine()?.toInt()?:0\n var result = b/2;\n println(result)\n }\n}"}, {"source_code": "fun main() {\n val n = Integer.valueOf(readLine()!!)\n\n repeat(n) {\n val x = Integer.valueOf(readLine()!!)\n if(x % 7 == 0) {\n println(x / 7)\n } else if(x % 7 == 1){\n println(x / 7 + 2)\n } else {\n println(x / 7 + 1)\n }\n }\n}"}, {"source_code": "fun main(){\n fun x()=readLine()!!.toInt()\n for(i in 1..x())println(x()/2)\n}"}, {"source_code": "fun main() {\n\n val solver = Solver()\n// val res = solver.solve(13)\n// print(res)\n val parsed: List = Parser().parse()\n val res = parsed.map { x -> solver.solve(x) }\n res.forEach{x-> println(x)}\n}\n\nclass Solver {\n private val faces : List = listOf(2,3,4,5,6,7).reversed()\n\n fun solve(target: Int): Int {\n var currentTarget: Int = target\n var rollCount = 0\n while (currentTarget > 0) {\n val face = findNextFace(currentTarget)\n currentTarget -= face\n rollCount++\n }\n return rollCount\n }\n\n fun findNextFace(target : Int) : Int {\n val idx: Int = faces.size - 1\n var currentFace: Int = 0\n for (i: Int in 0..idx) {\n currentFace = faces[i]\n if (target >= currentFace) {\n return currentFace\n }\n }\n return currentFace\n }\n}\n\nclass Parser {\n private fun lineSequence(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.constrainOnce().take(limit)\n private fun readln() = readLine()!!\n private fun readlnInt() = readln().toInt()\n\n fun parse(): List {\n val queryNumber: Int = readlnInt()\n return lineSequence(queryNumber).map { x -> x.toInt() }.toList()\n }\n}"}, {"source_code": "/*\nfun main(args: Array) {\n val t = readLine()!!.toInt()\n repeat(t) {\n val x = readLine()!!.toInt()\n println((x + 6) / 7)\n }\n}\n*/\nfun main(args: Array){ \n var i = 1;\n var t: Int =Integer.valueOf(readLine())\n repeat(t)\n {\n var x: Int =Integer.valueOf(readLine())\n println((x-1)/7 + 1)\n }\n}"}, {"source_code": "fun main() {\n val t = readLine()!!.toInt()\n repeat((1..t).count()) {\n val n = readLine()!!.toInt()\n println(n/7 + if(n.rem(7) == 0) 0 else 1 )\n }\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n repeat (n) {\n val i = readLine()!!.toInt()\n println(1+i/7)\n }\n}"}, {"source_code": "fun main() {\n var n = readLine()!!.toInt()\n while (n > 0) {\n val t = readLine()!!.toInt()\n println(t / 2)\n n -= 1\n }\n}"}, {"source_code": "fun rollCount(score: Int, base: Int = 7): Int {\n if(score <= 7) {\n return 1\n }\n val ost = score % base\n val full = score / base\n return when(ost) {\n 0 -> full\n 1 -> (full-1) + rollCount(score - (full-1)*base, base-1)\n else -> full + 1\n }\n}\n\nfun main() {\n val count = readLine()!!.toInt()\n repeat(count) {\n val score = readLine()!!.toInt()\n println(rollCount(score))\n } \n}"}, {"source_code": "fun main(args: Array)\n{\nval t= readLine()!!.toInt()\nrepeat(t)\n{\nval x= readLine()!!.toInt()\nprintln(x/2)\n}\n\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n BufferedReader(InputStreamReader(System.`in`)).use { reader ->\n val count = reader.readLine().toInt()\n reader.lineSequence()\n .take(count)\n .map {\n it.toInt() / 2\n }.joinToString(separator = \"\\n\") {\n it.toString()\n }\n .let(::println)\n }\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val T = readInt()\n val output = mutableListOf()\n for (t in 0..T-1) {\n val n = readInt()\n output += \"${n/2}\"\n }\n println(output.joinToString(\"\\n\"))\n}\n"}, {"source_code": "fun main() {\n val numberOfQueries = readLine()!!.toInt()\n val output = mutableListOf()\n\n repeat(numberOfQueries) {\n val target = readLine()!!.toInt()\n\n val result = when {\n target < 8 -> 1\n target % 7 == 0 -> target / 7\n else -> ((target - (target % 7)) / 7) + 1\n }\n\n output.add(result)\n }\n\n output.forEach { x -> println(x) }\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.File\nimport kotlin.system.measureTimeMillis\n\nfun solve(input: BufferedReader) {\n val t = input.readLine().toInt()\n for (i in 0 until t) {\n val n = input.readLine().toInt()\n println(n / 2)\n }\n}\n\n\nfun main(args: Array) {\n System.err.println(\"time = ${measureTimeMillis {\n solve(System.`in`.bufferedReader())\n// solve(File(\"a.out\").`bufferedReader())\n }}ms\")\n}\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n repeat(scanner.nextInt()){\n println(scanner.nextInt()/2)\n }\n}"}, {"source_code": "fun main(args : Array) {\n val numberOfQueries = readLine()!!.toInt()\n\n for (i in 1..numberOfQueries) {\n val points = readLine()!!.toInt()\n\n if (points % 2 == 0) {\n println(points / 2)\n } else {\n println((points - 3) / 2 + 1)\n }\n }\n}\n"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val T = readInt()\n for (t in 0..T-1) {\n val n = readInt()\n println(n / 2)\n }\n}\n"}, {"source_code": "fun main(arg: Array){\n\tvar n = readLine()!!.toInt()\n\twhile (n > 0){\n\t\tval x = readLine()!!.toInt()\n\t\tval y = if(x.rem(7)==0) x/7 else x/7+1\n\t\tprintln(y)\n\t\tn = n - 1\n\t}\n}"}, {"source_code": "fun calcurate(sum: Int): Int {\n val quotient = sum / 7\n val mod = sum % 7 // 7で割った余り\n return when {\n /*\n * 1は出せないので割る数を減らす -> quotient - 1\n * 8余るので6で割る -> +1\n * 2余る -> +1\n * => quotient - 1 + 1 + 1\n */\n mod == 1 -> quotient + 1\n /*\n * 2〜6余る -> +1\n */\n else -> quotient + 1\n }\n}\n\nfun dice(input: Sequence): String {\n return input.drop(1)\n .mapNotNull{it?.toInt()}\n .map(::calcurate)\n .joinToString(\"\\n\")\n}\n\nfun main(args: Array) {\n print(dice(generateSequence(::readLine)))\n}\n"}, {"source_code": "import java.util.*\nimport java.io.*\nfun main(args:Array) {\n\tval sc = Scanner(System.`in`)\n\t// PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n\tvar x = sc.nextInt();\n\twhile (x-- > 0)\n\t{\n\t\tval t = sc.nextInt();\n\t\tval ans:Int\n\t\tif (t % 2 == 0)\n\t\t ans = t / 2\n\t\telse\n\t\t ans = (t - 3) / 2 + 1\n\t\tprintln(ans)\n\t\t// x -= 1;\n\t // out.write(ans);\n\t}\n// out.close();\n}\n"}, {"source_code": "import kotlin.math.sign\n\nfun main() {\n repeat(readInt()) {\n val n = readInt()\n println(n / 7 + (n % 7).sign)\n }\n}\n\nfun readInt() = readLine()?.toInt() ?: 0"}, {"source_code": "fun main(args: Array) {\n val out = generateSequence(::readLine)\n .drop(1)\n .mapNotNull{it?.toInt()}\n .map{it / 7 + 1}\n .joinToString(\"\\n\")\n\n print(out)\n}"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val numQueries = readInt()\n val sol = IntArray(numQueries)\n for (query in 0 until numQueries) {\n val x = readInt()\n sol[query] = x / 7 + if (x % 7 == 0) 0 else 1\n }\n print(sol.joinToString(System.lineSeparator()))\n}"}, {"source_code": "fun main() {\n val n = readInt()\n for (j in 1..n) {\n val v = readInt()\n println(v / 2)\n }\n}\n\nfun readln() = readLine()!!\nfun readlnByte() = readln().toByte()\nfun readlnShort() = readln().toShort()\nfun readlnInt() = readln().toInt()\nfun readlnLong() = readln().toLong()\nfun readlnFloat() = readln().toFloat()\nfun readlnDouble() = readln().toDouble()\nfun readlnBigInt(radix: Int = 10) = readln().toBigInteger(radix)\nfun readlnBigDecimal() = readln().toBigDecimal()\n\nfun lineSequence(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.constrainOnce().take(limit)\nfun readlnStrings() = readln().split(' ')\nfun readlnBytes() = readlnStrings().map { it.toByte() }\nfun readlnShorts() = readlnStrings().map { it.toShort() }\nfun readlnInts() = readlnStrings().map { it.toInt() }\nfun readlnLongs() = readlnStrings().map { it.toLong() }\nfun readlnFloats() = readlnStrings().map { it.toFloat() }\nfun readlnDoubles() = readlnStrings().map { it.toDouble() }\n\nfun readByteArray() = readlnStrings().run { ByteArray(size) { get(it).toByte() } }\nfun readShortArray() = readlnStrings().run { ShortArray(size) { get(it).toShort() } }\nfun readIntArray() = readlnStrings().run { IntArray(size) { get(it).toInt() } }\nfun readLongArray() = readlnStrings().run { LongArray(size) { get(it).toLong() } }\nfun readFloatArray() = readlnStrings().run { FloatArray(size) { get(it).toFloat() } }\nfun readDoubleArray() = readlnStrings().run { DoubleArray(size) { get(it).toDouble() } }\n\nfun readlnByteArray(n: Int) = ByteArray(n) { readlnByte() }\nfun readlnShortArray(n: Int) = ShortArray(n) { readlnShort() }\nfun readlnIntArray(n: Int) = IntArray(n) { readlnInt() }\nfun readlnLongArray(n: Int) = LongArray(n) { readlnLong() }\nfun readlnFloatArray(n: Int) = FloatArray(n) { readlnFloat() }\nfun readlnDoubleArray(n: Int) = DoubleArray(n) { readlnDouble() }\n\nfun readByteArray2d(rows: Int, cols: Int) = Array(rows) { readByteArray().also { require(it.size == cols) } }\nfun readShortArray2d(rows: Int, cols: Int) = Array(rows) { readShortArray().also { require(it.size == cols) } }\nfun readLongArray2d(rows: Int, cols: Int) = Array(rows) { readLongArray().also { require(it.size == cols) } }\nfun readIntArray2d(rows: Int, cols: Int) = Array(rows) { readIntArray().also { require(it.size == cols) } }\nfun readFloatArray2d(rows: Int, cols: Int) = Array(rows) { readFloatArray().also { require(it.size == cols) } }\nfun readDoubleArray2d(rows: Int, cols: Int) = Array(rows) { readDoubleArray().also { require(it.size == cols) } }\n\nfun isWhiteSpace(c: Char) = c in \" \\r\\n\\t\"\n\n// JVM-only targeting code follows next\n\n// readString() via sequence is still slightly faster than Scanner\nfun readString() = generateSequence { System.`in`.read().toChar() }\n .dropWhile { isWhiteSpace(it) }.takeWhile { !isWhiteSpace(it) }.joinToString(\"\")\n\nfun readByte() = readString().toByte()\nfun readShort() = readString().toShort()\nfun readInt() = readString().toInt()\nfun readLong() = readString().toLong()\nfun readFloat() = readString().toFloat()\nfun readDouble() = readString().toDouble()\nfun readBigInt(radix: Int = 10) = readString().toBigInteger(radix)\nfun readBigDecimal() = readString().toBigDecimal()\n\nfun readBytes(n: Int) = generateSequence { readByte() }.take(n)\nfun readShorts(n: Int) = generateSequence { readShort() }.take(n)\nfun readInts(n: Int) = generateSequence { readInt() }.take(n)\nfun readLongs(n: Int) = generateSequence { readLong() }.take(n)\nfun readFloats(n: Int) = generateSequence { readFloat() }.take(n)\nfun readDoubles(n: Int) = generateSequence { readDouble() }.take(n)\n\n"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n repeat (n) {\n val i = readLine()!!.toInt()\n println(1+i/7)\n }\n}"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n val n = scanner.nextInt()\n\n repeat(n){\n println(findNumberOfRoles(scanner.nextInt()))\n }\n }\n\n private fun findNumberOfRoles(q: Int): Int {\n return q/2\n }"}, {"source_code": "import java.io.FileInputStream\nimport java.util.*\n\nobject programkt {\n @JvmStatic fun main(args: Array) {\n if (args.size == 1)\n System.setIn(FileInputStream(args[0]))\n val sc = Scanner(System.`in`)\n val t = sc.nextInt()\n IntRange(1, t).forEach {\n val x = sc.nextInt()\n println(x / 2)\n }\n }\n}\n"}, {"source_code": "import java.util.Scanner\nfun main() {\n val read = Scanner(System.`in`)\n var t = read.nextInt()\n //var t : Int = 3\n while (t-- != 0) {\n var n = read.nextInt()\n var ans : Int = 0\n var i : Int\n for (i in 7 downTo 2) {\n if (n % i == 0) {\n ans = n / i\n } else if (n % i >= 2 && n % i < i) {\n ans = n / i + 1\n }\n }\n println(ans)\n }\n\n }"}, {"source_code": "/* https://codeforces.com/problemset/problem/1093/A */\n\nfun main() {\n val numOfQueries = readLine()!!.toInt()\n for (i in 1..numOfQueries) {\n val targetPoints = readLine()!!.toInt()\n val numOfRolls = targetPoints / 7 + 1\n println(numOfRolls)\n }\n}"}, {"source_code": "fun main() {\n var t = readLine()!!.toInt()\n for (i in 1..t) {\n var number = readLine()!!.toInt()\n if (number % 2 == 0) {\n println(number / 2)\n } else {\n println((number - 1) / 2)\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n for (i in 0 until n) {\n val t = readLine()!!.toInt()\n if (t <= 7) {\n println(1)\n continue\n }\n val s = t / 7\n val rem = t % 7\n if (rem == 0) {\n println(s)\n } else {\n println(s + 1)\n }\n }\n}"}, {"source_code": "/* https://codeforces.com/problemset/problem/1093/A */\n\nfun main() {\n val numOfQueries = readLine()!!.toInt()\n for (i in 1..numOfQueries) {\n val targetPoints = readLine()!!.toInt()\n val numOfRolls = targetPoints / 7 + 1\n println(numOfRolls)\n }\n}"}, {"source_code": "private fun readInt() = readLine()?.toInt()!!\n\nprivate fun rollTry(point: Int) =\n if (point in 2..7) 1\n else (point / 6) + if (point % 6 != 0) 1 else 0\n\n\nfun main() {\n\n val num = readInt()\n (1..num)\n .map { readInt() }\n .forEach { println(rollTry(it)) }\n}"}, {"source_code": "fun main() {\n\n val solver = Solver()\n// val res = solver.solve(13)\n// print(res)\n val parsed: List = Parser().parse()\n val res = parsed.map { x -> solver.solve(x) }\n res.forEach{x-> println(x)}\n}\n\nclass Solver {\n private val faces : List = listOf(2,3,4,5,6,7).reversed()\n\n fun solve(target: Int): Int {\n var currentTarget: Int = target\n var rollCount = 0\n while (currentTarget > 0) {\n val face = findNextFace(currentTarget)\n currentTarget -= face\n rollCount++\n }\n return rollCount\n }\n\n fun findNextFace(target : Int) : Int {\n val idx: Int = faces.size - 1\n var currentFace: Int = 0\n for (i: Int in 0..idx) {\n currentFace = faces[i]\n if (target >= currentFace) {\n return currentFace\n }\n }\n return currentFace\n }\n}\n\nclass Parser {\n private fun lineSequence(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.constrainOnce().take(limit)\n private fun readln() = readLine()!!\n private fun readlnInt() = readln().toInt()\n\n fun parse(): List {\n val queryNumber: Int = readlnInt()\n return lineSequence(queryNumber).map { x -> x.toInt() }.toList()\n }\n}"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n val n = scanner.nextInt()\n\n repeat(n){\n println(findNumberOfRoles(scanner.nextInt()))\n }\n }\n\n private fun findNumberOfRoles(q: Int): Int {\n return q/2\n }"}, {"source_code": "object programkt {\n\n @JvmStatic\n fun main(args: Array) {\n val t = readLine()!!.toInt()\n\n for (i in 0 until t) {\n val x = readLine()!!.toInt()\n println(x / 2)\n }\n }\n\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\n\n internal var br = BufferedReader(InputStreamReader(System.`in`))\n internal var st: StringTokenizer? = null\n internal var out = PrintWriter(System.out)\n\n @Throws(IOException::class)\n private fun solve() {\n val t = nextInt()\n for (i in 0 until t) {\n val x = nextInt()\n out.println(x / 2)\n }\n }\n\n internal fun next(): String {\n while (st == null || !st!!.hasMoreTokens()) {\n st = StringTokenizer(br.readLine())\n }\n return st!!.nextToken()\n }\n\n @Throws(IOException::class)\n internal fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n @Throws(IOException::class)\n internal fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n @Throws(IOException::class)\n private fun run() {\n solve()\n out.close()\n }\n\n\n fun main(args: Array) {\n run()\n }\n\n\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.File\nimport kotlin.system.measureTimeMillis\n\nfun solve(input: BufferedReader) {\n val t = input.readLine().toInt()\n for (i in 0 until t) {\n val n = input.readLine().toInt()\n println(n / 2)\n }\n}\n\n\nfun main(args: Array) {\n System.err.println(\"time = ${measureTimeMillis {\n solve(System.`in`.bufferedReader())\n// solve(File(\"a.out\").`bufferedReader())\n }}ms\")\n}\n"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n val n = scanner.nextInt()\n\n repeat(n){\n println(findNumberOfRoles(scanner.nextInt()))\n }\n }\n\n private fun findNumberOfRoles(q: Int): Int {\n return q/2\n }"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n repeat (n) {\n val i = readLine()!!.toInt()\n println(1+i/7)\n }\n}"}, {"source_code": "fun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\n\nfun main() {\n val testCases = readInt()\n for (i in 1..testCases) {\n val n = readInt()\n println((n / 7) + 1)\n }\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n\n val scanner = Scanner(System.`in`)\n var t = scanner.nextInt() \n\n while (t > 0) {\n t--\n var num = scanner.nextInt()\n for (i in 2..7) {\n var c = num % i\n var c2 = num / i\n if (c != 1) {\n if (c > 0) println(c2 + 1)\n else println(c2)\n break\n }\n }\n }\n\n}"}, {"source_code": "fun main() {\n for (i in 1..readLine()!!.toInt()) {\n val r: Int = readLine()!!.toInt() / 2\n println(r)\n }\n}"}, {"source_code": "import java.util.Scanner\n\nobject programkt {\n @JvmStatic fun main(args:Array) {\n val sc = Scanner(System.`in`)\n val t = sc.nextInt()\n for (i in 0 until t)\n {\n val x = sc.nextInt()\n if (x <= 7)\n {\n println(1)\n }\n else\n {\n println(x / 2)\n }\n }\n }\n}"}, {"source_code": "import kotlin.math.sign\n\ndata class Problem(val id: Int, val target: Int)\n\ndata class Solution(val count: Int) {\n override fun toString(): String {\n return \"$count\\n\"\n }\n}\n\nfun readProblem(problemId: Int): Problem {\n return Problem(problemId, readLine()!!.trim().toInt())\n}\n\nfun solveProblem(problem: Problem): Solution {\n return Solution(problem.target / 7 + (problem.target % 7).sign)\n}\n\nfun main(args: Array) {\n var n = readLine()!!.toInt()\n (1..n).map(::readProblem)\n .map(::solveProblem)\n .onEach(::print)\n}\n"}, {"source_code": "private fun readInt() = readLine()?.toInt()!!\n\nprivate fun rollTry(point: Int) =\n if (point in 2..7) 1\n else (point / 6) + if (point % 6 != 0) 1 else 0\n\n\nfun main() {\n\n val num = readInt()\n (1..num)\n .map { readInt() }\n .forEach { println(rollTry(it)) }\n}"}, {"source_code": "import java.util.Scanner\nfun main() {\n val read = Scanner(System.`in`)\n var t = read.nextInt()\n //var t : Int = 3\n while (t-- != 0) {\n var n = read.nextInt()\n var ans : Int = 0\n var i : Int\n for (i in 7 downTo 2) {\n if (n % i == 0) {\n ans = n / i\n } else if (n % i >= 2 && n % i < i) {\n ans = n / i + 1\n }\n }\n println(ans)\n }\n\n }"}, {"source_code": "fun main() {\n val nQueries = readLine()!!.toInt()\n for (i in 0 until nQueries) {\n val value = readLine()!!.toInt()\n println(value / 7 + 1)\n }\n}\n"}, {"source_code": "/*\nfun main(args: Array) {\n val t = readLine()!!.toInt()\n repeat(t) {\n val x = readLine()!!.toInt()\n println((x + 6) / 7)\n }\n}\n*/\nfun main(args: Array){ \n var i = 1;\n var t: Int =Integer.valueOf(readLine())\n repeat(t)\n {\n var x: Int =Integer.valueOf(readLine())\n println((x-1)/7 + 1)\n }\n}"}, {"source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n// var arr2 = readLine()!!.split(\" \").map { x -> x.toLong() }\n// var arr = readLine()!!.split(\" \").map { x -> x.toLong() }\n\n for (a in 0 until n) {\n var count = readLine()!!.toInt()\n if (count < 8) println (1)\n else println(count / 7 + 1)\n }\n\n}"}, {"source_code": "fun main() {\n val n = readInt()\n for (j in 1..n) {\n val v = readInt()\n println(v / 2)\n }\n}\n\nfun readln() = readLine()!!\nfun readlnByte() = readln().toByte()\nfun readlnShort() = readln().toShort()\nfun readlnInt() = readln().toInt()\nfun readlnLong() = readln().toLong()\nfun readlnFloat() = readln().toFloat()\nfun readlnDouble() = readln().toDouble()\nfun readlnBigInt(radix: Int = 10) = readln().toBigInteger(radix)\nfun readlnBigDecimal() = readln().toBigDecimal()\n\nfun lineSequence(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.constrainOnce().take(limit)\nfun readlnStrings() = readln().split(' ')\nfun readlnBytes() = readlnStrings().map { it.toByte() }\nfun readlnShorts() = readlnStrings().map { it.toShort() }\nfun readlnInts() = readlnStrings().map { it.toInt() }\nfun readlnLongs() = readlnStrings().map { it.toLong() }\nfun readlnFloats() = readlnStrings().map { it.toFloat() }\nfun readlnDoubles() = readlnStrings().map { it.toDouble() }\n\nfun readByteArray() = readlnStrings().run { ByteArray(size) { get(it).toByte() } }\nfun readShortArray() = readlnStrings().run { ShortArray(size) { get(it).toShort() } }\nfun readIntArray() = readlnStrings().run { IntArray(size) { get(it).toInt() } }\nfun readLongArray() = readlnStrings().run { LongArray(size) { get(it).toLong() } }\nfun readFloatArray() = readlnStrings().run { FloatArray(size) { get(it).toFloat() } }\nfun readDoubleArray() = readlnStrings().run { DoubleArray(size) { get(it).toDouble() } }\n\nfun readlnByteArray(n: Int) = ByteArray(n) { readlnByte() }\nfun readlnShortArray(n: Int) = ShortArray(n) { readlnShort() }\nfun readlnIntArray(n: Int) = IntArray(n) { readlnInt() }\nfun readlnLongArray(n: Int) = LongArray(n) { readlnLong() }\nfun readlnFloatArray(n: Int) = FloatArray(n) { readlnFloat() }\nfun readlnDoubleArray(n: Int) = DoubleArray(n) { readlnDouble() }\n\nfun readByteArray2d(rows: Int, cols: Int) = Array(rows) { readByteArray().also { require(it.size == cols) } }\nfun readShortArray2d(rows: Int, cols: Int) = Array(rows) { readShortArray().also { require(it.size == cols) } }\nfun readLongArray2d(rows: Int, cols: Int) = Array(rows) { readLongArray().also { require(it.size == cols) } }\nfun readIntArray2d(rows: Int, cols: Int) = Array(rows) { readIntArray().also { require(it.size == cols) } }\nfun readFloatArray2d(rows: Int, cols: Int) = Array(rows) { readFloatArray().also { require(it.size == cols) } }\nfun readDoubleArray2d(rows: Int, cols: Int) = Array(rows) { readDoubleArray().also { require(it.size == cols) } }\n\nfun isWhiteSpace(c: Char) = c in \" \\r\\n\\t\"\n\n// JVM-only targeting code follows next\n\n// readString() via sequence is still slightly faster than Scanner\nfun readString() = generateSequence { System.`in`.read().toChar() }\n .dropWhile { isWhiteSpace(it) }.takeWhile { !isWhiteSpace(it) }.joinToString(\"\")\n\nfun readByte() = readString().toByte()\nfun readShort() = readString().toShort()\nfun readInt() = readString().toInt()\nfun readLong() = readString().toLong()\nfun readFloat() = readString().toFloat()\nfun readDouble() = readString().toDouble()\nfun readBigInt(radix: Int = 10) = readString().toBigInteger(radix)\nfun readBigDecimal() = readString().toBigDecimal()\n\nfun readBytes(n: Int) = generateSequence { readByte() }.take(n)\nfun readShorts(n: Int) = generateSequence { readShort() }.take(n)\nfun readInts(n: Int) = generateSequence { readInt() }.take(n)\nfun readLongs(n: Int) = generateSequence { readLong() }.take(n)\nfun readFloats(n: Int) = generateSequence { readFloat() }.take(n)\nfun readDoubles(n: Int) = generateSequence { readDouble() }.take(n)\n\n"}, {"source_code": "fun main(args: Array)\n{\nval t= readLine()!!.toInt()\nrepeat(t)\n{\nval x= readLine()!!.toInt()\nprintln(x/2)\n}\n\n}"}, {"source_code": "fun main() {\n repeat(readLine()!!.toInt()) {\n val n = readLine()!!.toInt();\n println(\"${n/2}\");\n }\n}"}, {"source_code": "import java.io.File\n\nclass MyReader(fileName: String) {\n val file = File(fileName)\n\n\n val contents : List?\n\n init {\n contents = try {\n file.readLines()\n } catch (e : Throwable) {\n null\n }\n }\n\n\n val line : String\n get() {\n return if (contents != null) {\n contents[pointer++]\n } else {\n readLine()!!\n }\n }\n\n var pointer = 0\n}\n\nvar reader : MyReader = MyReader(\"src/inpsut.txt\")\n\nfun getLine() = reader.line\nfun readInt() = getLine().toInt()\nfun readInts() = getLine().split(\" \").map { it.toInt() }\n\nfun main() {\n val n = readInt()\n repeat(n) { i ->\n var num = readInt()\n var ans = 0\n if (num % 2 == 1) {\n ans = 1\n num -= 3\n }\n println(num / 2 + ans)\n }\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n for (i in 0 until n) {\n val x = readLine()!!.toInt()\n println(x/2)\n }\n}"}, {"source_code": "/*\nfun main(args: Array) {\n val t = readLine()!!.toInt()\n repeat(t) {\n val x = readLine()!!.toInt()\n println((x + 6) / 7)\n }\n}\n*/\nfun main(args: Array){ \n var i = 1;\n var t: Int =Integer.valueOf(readLine())\n repeat(t)\n {\n var x: Int =Integer.valueOf(readLine())\n println((x-1)/7 + 1)\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n var rows = input.nextInt()\n var row = 0\n do {\n row = input.nextInt()\n if (row < 8) {\n println(1)\n } else {\n println(row / 2)\n }\n --rows\n } while(rows > 0)\n}"}, {"source_code": "fun main()\n{ \n\tvar s= arrayOf(2,3,4,5,6,7)\n\tvar t=readLine()!!.toInt()\n\trepeat(t)\n\t{ var c: Int=0\n\t\tvar p: Int=readLine()!!.toInt()\n\t\twhile (p>0)\n\t\t\t{\n\t\t if(p>7)\n\t\t\t\t { p=p-s.random()\n\t\t\t\t\t c++\n\t\t\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t { c++\n\t\t\t\t\t p=0\n\t\t\t\t\t\t\t}\n\t }\n\t\tprintln(c)\n\t}\n}"}, {"source_code": "fun main() {\n readLine()?.toInt()?.let { \n repeat(it) {\n readLine()?.toInt()?.let {\n println(1 + it / 7)\n }\n }\n }\n}"}, {"source_code": "fun main() {\n var t = readLine()!!.toInt();\n while(t>0) {\n var x=readLine()!!.toInt();\n var ans=(x/7);\n var ans2=(x%7);\n if(ans2==0)\n println(ans);\n else\n println(ans+1);\n t--;\n }\n}"}, {"source_code": "fun main(args : Array) {\n val numberOfQueries = readLine()!!.toInt()\n \n for (i in 1..numberOfQueries) {\n println(readLine()!!.toInt() / 2)\n }\n}\n"}, {"source_code": "\nfun main(args: Array) {\n val count = readLine()!!.toInt()\n for (i in 0 until count) {\n val target = readLine()!!.toInt()\n val roll = Math.ceil(target / 7.0).toInt()\n println(roll)\n }\n}\n"}, {"source_code": "fun readInt(): Int {\n return readLine()!!.toInt()\n}\n\nfun main() {\n val T = readInt()\n for(i in 1..T) {\n var result = 0\n var n = readInt()\n while(n > 0) {\n if(n % 7 == 1)\n n -= 4\n else if(n >= 7)\n n -= 7\n else\n n -= n % 7\n result++\n }\n println(result)\n }\n}"}, {"source_code": "fun main(args: Array) {\n val t = readLine()!!.toInt()\n repeat(t) {\n val x = readLine()!!.toInt()\n if (x % 2 == 0){\n println(x / 2)\n }else{\n var a = x - 3\n println(a / 2 + 1)\n }\n }\n}"}, {"source_code": "fun main(args : Array) {\n val numberOfQueries = readLine()!!.toInt()\n \n for (i in 1..numberOfQueries) {\n println(readLine()!!.toInt() / 2)\n }\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\nimport java.lang.Math.*\n\nvar stok = StringTokenizer(\"\")\nvar br = BufferedReader(InputStreamReader(System.`in`))\n\nfun nextToken(): String? {\n while (!stok.hasMoreTokens()) {\n val s = br.readLine() ?: return null\n stok = StringTokenizer(s)\n }\n return stok.nextToken()\n}\n\nfun nextInt() = nextToken()!!.toInt()\nfun nextDouble() = nextToken()!!.toDouble()\nfun nextLong() = nextToken()!!.toLong()\n\nfun main(args: Array) {\n if (args.isNotEmpty()) br = BufferedReader(FileReader(\"input.txt\"))\n PrintWriter(System.out, false).use { it.solve() }\n}\n\nfun PrintWriter.solve() {\n val t = nextInt()\n for (it in 0 until t) {\n val x = nextInt()\n if (x <= 7) {\n println(1)\n } else if (x % 2 == 0) {\n println(x / 2)\n } else {\n println(1 + (x - 3) / 2)\n }\n }\n}"}, {"source_code": "fun main() {\n val t = readLine()!!.toInt()\n for (x in 0 until t) {\n val n=readLine()!!.toInt()\n println(n/2)\n }\n}"}, {"source_code": "fun main(){\n var t = readLine()!!.toInt()\n val answers = mutableListOf()\n while (t-- > 0){\n val x = readLine()!!.toInt()\n answers.add((x/2).toString())\n }\n\n println(answers.joinToString(\"\\n\"))\n}\n"}], "negative_code": [{"source_code": "fun main() {\n val tests = readLine()!!.toInt();\n repeat(tests) {\n val points = readLine()!!.toInt()\n print((points / 7) + 1)\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(){\n val scanner = Scanner(System.`in`)\n var queries = scanner.nextInt()\n var queryList = arrayListOf()\n\n if(queries<=100) {\n while (queries > 0) {\n val contest = scanner.nextInt()\n if(contest in 2..100)\n {queryList.add(contest)}\n queries--\n }\n }\n for(elem in queryList){\n rollDice(elem)\n }\n}\n\nval diceEyes = listOf(2,3,4,5,6,7)\n\nval evenEyes = listOf(2,4,6)\n\nfun rollDice(number: Int): List{\n val rolls = mutableListOf()\n var sum = 0\n var i = 0\n if(number % 2 == 0){\n i = evenEyes.size-1\n }else{\n i = diceEyes.size-1\n }\n while(sum != number && i >= 0){\n var tempSum = sum\n if(number % 2 == 0){\n tempSum+=evenEyes[i]\n }else{\n tempSum += diceEyes[i]\n }\n\n if(tempSum <= number){\n sum = tempSum\n rolls.add(diceEyes[i])\n }else{\n i--\n }\n }\n println(\"${rolls.size}\")\n return rolls\n}\n"}, {"source_code": "import kotlin.random.Random\n\nfun main(args: Array) {\n args.slice(1 until args.size).forEach{\n var number = it.toInt()\n var counter = 0\n while( number > 7 ){\n number -= Random.nextInt(2, 7)\n counter++\n }\n println(counter)\n }\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val T = readInt()\n for (t in 0..T-1) {\n val n = readInt()\n println((n + 1) / 2)\n }\n}\n"}, {"source_code": "fun main() {\n var t = Integer.parseInt(readLine())\n\n while(t > 0) {\n var res = solve(Integer.parseInt(readLine()))\n println(res)\n t--\n }\n\n}\n\nfun solve(n:Int):Int {\n var res = 0\n var m = n\n for(i in 7 downTo 2) {\n res += m/i\n m %= i\n }\n return res\n}\n"}, {"source_code": "fun main(){\n val roundCount = readLine()!!\n val length = roundCount.length\n if (length == 1){\n if (roundCount.toInt() == 2 || roundCount.toInt() == 3)\n println(\"1\")\n else\n println(\"2\")\n\n return\n }\n println(roundCount.substring(0, roundCount.length-1).toInt() * 2)\n\n}"}, {"source_code": "fun main() {\n val parsed: List = Parser().parse()\n val solver = Solver()\n val res = parsed.map { x -> solver.solve(x) }\n res.forEach{x-> println(x)}\n}\n\nclass Solver {\n private val faces : List = listOf(2,3,4,5,6,7)\n\n fun solve(target : Int) : Int {\n var idx: Int = faces.size - 1\n var rollCount = 1\n var currentTarget: Int = target\n for (i: Int in 0..idx) {\n val currentFace: Int = faces[idx]\n if (currentTarget < currentFace) {\n continue\n }\n currentTarget -= currentFace\n rollCount++\n }\n return rollCount\n }\n}\n\nclass Parser {\n private fun lineSequence(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.constrainOnce().take(limit)\n private fun readln() = readLine()!!\n private fun readlnInt() = readln().toInt()\n\n fun parse(): List {\n val queryNumber: Int = readlnInt()\n return lineSequence(queryNumber).map { x -> x.toInt() }.toList()\n }\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n var T = readInt()\n while(T>0) {\n var x = readInt()\n println(\"%d\".format(x/2+x%2))\n T--\n }\n\n}"}, {"source_code": "import java.util.*\n \nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = readLine()!!.toInt()\n for(x in 0..n-1){\n \tval tmp = readLine()!!.toInt()\n \tif(tmp <= 6) println(\"1\")\n \telse{\n \t\tprintln(tmp/6+tmp%6)\n \t}\n }\n \n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val sc = Scanner(System.`in`)\n val t = sc.nextInt()\n repeat(t) {\n val x = sc.nextInt()\n println((x-1)/2+1)\n }// \n}"}, {"source_code": "fun main(args: Array) = args.forEach { println(it) }"}, {"source_code": "\n\n\nfun calculate(target: Int): Int {\n var nums = listOf(7, 6, 5, 4, 3, 2)\n var currentTarget = target\n var throws = 0\n while (nums.isNotEmpty()) {\n while (currentTarget >= nums.first()) {\n currentTarget -= nums.first()\n throws++\n }\n nums = nums.drop(1)\n }\n return throws\n}\n\n\nfun main(args: Array) {\n repeat(readLine()!!.toInt()) {\n println(calculate(readLine()!!.toInt()))\n }\n}\n"}, {"source_code": "import java.util.*\n\nfun main(){\n val scanner = Scanner(System.`in`)\n var queries = scanner.nextInt()\n if(queries<=100) {\n while (queries > 0) {\n val contest = scanner.nextInt()\n if(contest in 2..100)\n {rollDice(contest)}\n queries--\n }\n }\n}\n\nval diceEyes = listOf(2,3,4,5,6,7)\n\nfun rollDice(number: Int): List{\n val rolls = mutableListOf()\n var sum = 0\n var i = diceEyes.size-1\n while(sum != number && i >= 0){\n var tempSum = sum\n tempSum += diceEyes[i]\n if(tempSum <= number){\n sum = tempSum\n rolls.add(diceEyes[i])\n }else{\n i--\n }\n }\n println(\"${rolls.size}\")\n return rolls\n}\n"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n for (i in 0 until n) {\n val x = readLine()!!.toInt()\n val t = x / 2\n if (t*2 == x) {\n println(t)\n } else {\n println(t+1)\n }\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(){\n val scanner = Scanner(System.`in`)\n var queries = scanner.nextInt()\n while (queries >0){\n rollDice(scanner.nextInt())\n queries--\n }\n}\n\nval diceEyes = listOf(2,3,4,5,6,7)\n\nfun rollDice(number: Int): List{\n val rolls = mutableListOf()\n var sum = 0\n var i = diceEyes.size-1\n while(sum != number && i >= 0){\n var tempSum = sum\n tempSum += diceEyes[i]\n if(tempSum <= number){\n sum = tempSum\n rolls.add(diceEyes[i])\n }else{\n i--\n }\n }\n println(\"${rolls.size}\")\n return rolls\n}\n"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n repeat (n) {\n readLine()!!.toInt()\n println(n)\n }\n}"}, {"source_code": "fun main()\n{\n val t = readLine()!!.toInt()\n for (i in 1 .. t)\n {\n println(treatTestCase())\n }\n}\n\nfun treatTestCase(): String\n{\n val x = readLine()!!.toInt()\n\n // if even, return divided by 2\n // else if its 3 return 1\n // else remove three then return divided by 2 + 1\n\n return when\n {\n x % 2 == 0 ->\n {\n println(\"Roll 2 ${x / 2} times\")\n (x / 2).toString()\n }\n x == 3 ->\n {\n println(\"Roll 3 once\")\n (1).toString()\n }\n else ->\n {\n println(\"Roll 3 once and 2 ${(x - 3) / 2} times\")\n ((x - 3) / 2 + 1).toString()\n }\n }\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n BufferedReader(InputStreamReader(System.`in`)).lineSequence().drop(1).map {\n it.toInt() / 2\n }.joinToString {\n it.toString()\n }.let(::println)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val t = nextInt()\n val x = nextInt()\n println(x)\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n repeat (n) {\n readLine()!!.toInt()\n println(n)\n }\n}"}, {"source_code": "fun main(){\n val roundCount = readLine()!!\n val length = roundCount.length\n if (length == 1){\n if (roundCount.toInt() == 2 || roundCount.toInt() == 3)\n println(\"1\")\n else\n println(\"2\")\n\n return\n }\n println(roundCount.substring(0, roundCount.length-1).toInt() * 2)\n\n}"}, {"source_code": "fun main(args: Array) {\n val numOfLines = readLine()!!.toInt()\n\n (0 until numOfLines)\n .map { readLine()!!.toInt() }\n .forEach {query ->\n val answer = query % 7 + 1\n println(answer)\n }\n\n}\n"}, {"source_code": "fun main(args : Array){\n if (args.isNotEmpty()) {\n for (i in 1..args[0].toInt()) {\n println(args[i].toInt() / 7)\n }\n }\n}"}, {"source_code": "fun main()\n{\n var n = readLine()!!.toInt()\n \n for (i in 1..n)\n {\n var x = readLine()!!.toInt()\n \n var j = 0\n \n while (x >= 6)\n {\n j++\n x -= 6\n }\n \n \n \n } \n}\n"}, {"source_code": "fun main() {\n var t = Integer.parseInt(readLine())\n\n while(t > 0) {\n var res = solve(Integer.parseInt(readLine()))\n println(res)\n t--\n }\n\n}\n\nfun solve(n:Int):Int {\n var res = 0\n var m = n\n for(i in 7 downTo 2) {\n res += m/i\n m %= i\n }\n return res\n}\n"}, {"source_code": "fun main(args: Array) {\n val numOfLines = readLine()!!.toInt()\n\n (0 until numOfLines)\n .map { readLine()!!.toInt() }\n .forEach {query ->\n val answer = query % 7 + 1\n println(answer)\n }\n\n}\n"}, {"source_code": "fun main() {\n\n val queries = readLine()!!.toInt()\n\n for (i in 0 until queries) {\n val points = readLine()!!.toInt()\n\n val maxRolls = Math.ceil(points / 2.0)\n\n println(maxRolls.toInt())\n }\n\n}"}, {"source_code": "val sides = arrayOf(2, 3, 4, 5, 6, 7)\nval output = mutableListOf()\n\nfun main() {\n\n val requestCounts = readInt()\n for (i in 0 until requestCounts) {\n val number: Int = readInt()\n calculateAttemptCounts(number)\n }\n\n for (out in output) {\n println(out)\n }\n}\n\nfun readInt(): Int {\n return readLine()!!.toInt()\n}\n\nfun calculateAttemptCounts(number: Int) {\n var tempNumber = number\n var attemptCounts = 0\n for (side in sides.reversedArray()) {\n val tempCount: Int = tempNumber / side\n\n if (tempCount == 0) continue\n\n attemptCounts += tempCount\n\n if (tempNumber % side == 0) {\n output.add(attemptCounts)\n break\n }\n\n tempNumber %= side\n }\n}"}, {"source_code": "fun main() {\n val MIN_VAL = 2\n val MAX_VAL = 7\n val N = readLine()!!.toInt()\n val scores: MutableList = ArrayList()\n for (i in 0 until N) {\n scores.add(readLine()!!.toInt())\n }\n val answer: MutableList = ArrayList()\n\n scores.forEach {\n var currentScore = MAX_VAL\n var currentAmountScore = it\n var amountSteps = 0\n\n while (currentAmountScore >= 0 && currentScore >= MIN_VAL) {\n while (currentScore <= currentAmountScore) {\n currentAmountScore -= currentScore\n amountSteps++\n }\n currentScore--\n }\n answer.add(amountSteps)\n }\n answer.forEach(::println)\n}\n"}, {"source_code": "fun getInputs(): List {\n val count = readLine()!!\n return List(count.toInt()) { readLine()!!.toInt() }\n}\n\n\nfun calculate(target: Int): Int {\n var nums = listOf(7, 6, 5, 4, 3, 2)\n var currentTarget = target\n var throws = 0\n while (nums.isNotEmpty()) {\n while (currentTarget >= nums.first()) {\n currentTarget -= nums.first()\n throws++\n }\n nums = nums.drop(1)\n }\n return throws\n}\n\n\nfun main(args: Array) {\n val queries = getInputs()\n queries.forEach { println(calculate(it)) }\n}\n"}, {"source_code": "import java.util.Scanner\nfun main(args:Array) {\n val read = Scanner(System.`in`)\n val n:Int = read.nextInt()\n val ans = n/2 + n%2\n println(\"$ans\")\n\n}"}, {"source_code": "fun main() {\n val solver = Solver()\n val res = solver.solve(100)\n println(res)\n}\n\nclass Solver {\n private val faces : List = listOf(2,3,4,5,6,7)\n\n fun solve(target : Int) : Int {\n var idx: Int = faces.size - 1\n var rollCount = 1\n var currentTarget: Int = target\n for (i: Int in 0..idx) {\n val currentFace: Int = faces[idx]\n if (currentTarget < currentFace) {\n continue\n }\n currentTarget -= currentFace\n rollCount++\n }\n return rollCount\n }\n}\n\nclass Parser {\n private fun lineSequence(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.constrainOnce().take(limit)\n private fun readln() = readLine()!!\n private fun readlnInt() = readln().toInt()\n\n fun parse(): List {\n val queryNumber: Int = readlnInt()\n return lineSequence(queryNumber).map { x -> x.toInt() }.toList()\n }\n}"}, {"source_code": "fun main(args: Array) {\n val countLine = readLine()\n println(countLine)\n}"}, {"source_code": "fun main(){\n val points = readLine()!!.toInt()\n print((points/7)+1)\n}"}, {"source_code": "fun main(){\n val roundCount = readLine()?.toIntOrNull()\n roundCount?.let {count->\n val arrayOfPoints = Array(3){\n readLine()?.toIntOrNull()\n }\n arrayOfPoints.forEach {\n it?.let {\n println(it/2)\n }\n }\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(){\n val scanner = Scanner(System.`in`)\n var queries = scanner.nextInt()\n if(queries<=100) {\n while (queries > 0) {\n rollDice(scanner.nextInt())\n queries--\n }\n }\n}\n\nval diceEyes = listOf(2,3,4,5,6,7)\n\nfun rollDice(number: Int): List{\n val rolls = mutableListOf()\n var sum = 0\n var i = diceEyes.size-1\n while(sum != number && i >= 0){\n var tempSum = sum\n tempSum += diceEyes[i]\n if(tempSum <= number){\n sum = tempSum\n rolls.add(diceEyes[i])\n }else{\n i--\n }\n }\n println(\"${rolls.size}\")\n return rolls\n}\n"}, {"source_code": "fun getInputs(): List {\n val count = readLine()!!\n return List(count.toInt()) { readLine()!!.toInt() }\n}\n\n\nfun calculate(target: Int): Int {\n var nums = listOf(7, 6, 5, 4, 3, 2)\n var currentTarget = target\n var throws = 0\n while (nums.isNotEmpty()) {\n while (currentTarget >= nums.first()) {\n currentTarget -= nums.first()\n throws++\n }\n nums = nums.drop(1)\n }\n return throws\n}\n\n\nfun main(args: Array) {\n val queries = getInputs()\n queries.forEach { println(calculate(it)) }\n}\n"}, {"source_code": "import java.util.Scanner\nobject programkt {\n @JvmStatic fun main(args:Array) {\n val sc = Scanner(System.`in`)\n val tc = sc.nextInt()\n for (i in 1..tc)\n {\n val n = sc.nextInt()\n println(n)\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n for (i in 1..n) {\n val x = readLine()!!.toInt()\n when {\n x < 8 -> print(1)\n x % 2 == 0 -> print(x / 2)\n else -> print((x - 3) / 2 + 1)\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n args.slice(1 until args.size).forEach{\n var number = it.toInt()\n var counter = 0\n while( number > 0 ){\n number -= 7\n counter++\n }\n println(counter)\n }\n}"}, {"source_code": "import com.sun.org.apache.xpath.internal.operations.Bool\n\nfun main(args: Array) {\n val scanner = java.util.Scanner(System.`in`)\n var inputCount = scanner.nextLine()\n val count = inputCount.toInt()\n var inputList = ArrayList(count)\n\n val minBoneValue = 2\n val maxBoneValue = 7\n val minValue = 1\n\n for (x in minValue..count) {\n var value = scanner.nextLine()\n inputList.add(value.toInt())\n }\n\n for (x in inputList) {\n if(x >= minBoneValue && x <= maxBoneValue){\n println(minValue)\n }\n else {\n var throwsCount = (x/maxBoneValue)\n val remainder = x%maxBoneValue\n if(remainder != minValue)\n throwsCount++\n println(throwsCount)\n }\n }\n}\n\n\n"}, {"source_code": "fun main(args : Array) {\n if (args.isNotEmpty()) {\n Array(args[0].toInt()) { i ->(args[i+1].toInt()/7)+1 }.forEach(::println)\n }\n}"}, {"source_code": "fun main() {\n diceRolling()\n}\n\nval mins = mapOf(\n 2 to 1,\n 3 to 1,\n 4 to 1,\n 5 to 1,\n 6 to 1,\n 7 to 1,\n 8 to 2,\n 9 to 2,\n 10 to 2,\n 11 to 2,\n 12 to 2,\n 13 to 2,\n 14 to 2,\n 15 to 3,\n 16 to 3,\n 17 to 3,\n 18 to 3,\n 19 to 3,\n 20 to 3,\n 21 to 3,\n 22 to 4,\n 23 to 4,\n 24 to 4,\n 25 to 4,\n 26 to 4,\n 27 to 4,\n 28 to 4,\n 29 to 5,\n 30 to 5,\n 31 to 5,\n 32 to 5,\n 33 to 5,\n 34 to 5,\n 35 to 5,\n 36 to 6,\n 37 to 6,\n 38 to 6,\n 39 to 6,\n 40 to 6,\n 41 to 6,\n 42 to 6,\n 43 to 7,\n 44 to 7,\n 45 to 7,\n 46 to 7,\n 47 to 7,\n 48 to 7,\n 49 to 7,\n 50 to 8,\n 51 to 8,\n 52 to 8,\n 53 to 8,\n 54 to 8,\n 55 to 8,\n 56 to 8,\n 57 to 9,\n 58 to 9,\n 59 to 9,\n 60 to 9,\n 61 to 9,\n 62 to 9,\n 63 to 9,\n 64 to 10,\n 65 to 10,\n 66 to 10,\n 67 to 10,\n 68 to 10,\n 69 to 10,\n 70 to 10,\n 71 to 11,\n 72 to 11,\n 73 to 11,\n 74 to 11,\n 75 to 11,\n 76 to 11,\n 77 to 11,\n 78 to 12,\n 79 to 12,\n 80 to 12,\n 81 to 12,\n 82 to 12,\n 83 to 12,\n 84 to 12,\n 85 to 13,\n 86 to 13,\n 87 to 13,\n 88 to 13,\n 89 to 13,\n 90 to 13,\n 91 to 13,\n 92 to 14,\n 93 to 14,\n 94 to 14,\n 95 to 14,\n 96 to 14,\n 97 to 14,\n 98 to 14,\n 99 to 15,\n 100 to 15\n)\n\nfun diceRolling() {\n// val units = listOf(7, 6, 5, 4, 3, 2)\n val inputCount = readLine()!!.toInt()\n \n for (i in 0 until inputCount) {\n println(mins[i])\n }\n\n// (2..100).forEach {\n// println(\"$it to ${compute(it, units)}\")\n// }\n}\n\n//fun compute(target: Int, units: List): Int {\n// if (target in units) return 1\n// if (target == units.max()!! + 1) return 2\n// return 1 + compute(target - units.max()!!, units)\n//}\n"}, {"source_code": "val scan = java.util.Scanner(System.`in`)\nfun main(args: Array) {\n var t = scan.nextInt()\n repeat(t) {\n var n = scan.nextInt()\n var f = IntArray(n + 7, {0})\n f[0] = 0\n f[1] = 1\n for (i in 2..6) {\n f[i] = 1\n }\n for (i in 7..n) {\n f[i] = Math.min(Math.min(Math.min(f[i - 2], f[i - 3]), Math.min(f[i - 4], f[i - 5])), f[i - 6]) + 1\n }\n print(f[n])\n }\n}"}, {"source_code": "fun main() {\n println(numRolls(2))\n println(numRolls(13))\n println(numRolls(37))\n println(numRolls(100))\n}\n\nprivate fun numRolls(points: Int): Int {\n var numRolls = 0\n var remainingPoints = points\n for (i in 2..7) {\n var rolls = remainingPoints / i\n while (rolls > 0) {\n numRolls += rolls\n remainingPoints %= i\n rolls = remainingPoints / i\n }\n }\n return numRolls\n}"}, {"source_code": "fun main(args : Array){\n if (args.isNotEmpty()) {\n for (i in 1..args[0].toInt()) {\n println(args[i].toInt() / 7)\n }\n }\n}"}, {"source_code": "fun main() {\n val t = readInt()\n for (i in 1..t) {\n val summ = readLine()!!.toInt()\n recCal(summ)\n }\n }\n\nfun recCal(value: Int): Int {\n return when {\n value in 2..7 -> 1\n value == 8 -> 2\n else -> 1 + recCal(value - 7)\n \n }\n}\nfun check(value: Int, m: Int) = (value / m) * m + (value % m)\nfun readInt() = readLine()!!.toInt()"}, {"source_code": "fun main() {\n val tests = readLine()!!.toInt();\n repeat(tests) {\n val points = readLine()!!.toInt()\n print((points / 7) + 1)\n }\n}"}, {"source_code": "fun main(args: Array) {\n args.slice(1 until args.size).forEach{\n var number = it.toInt()\n var counter = 0\n while( number > 0 ){\n number -= 7\n counter++\n }\n println(counter)\n }\n}"}, {"source_code": "val sides = arrayOf(2, 3, 4, 5, 6, 7)\nval output = mutableListOf()\n\nfun main() {\n\n val requestCounts = readInt()\n for (i in 0 until requestCounts) {\n val number: Int = readInt()\n calculateAttemptCounts(number)\n }\n\n for (out in output) {\n println(out)\n }\n}\n\nfun readInt(): Int {\n return readLine()!!.toInt()\n}\n\nfun calculateAttemptCounts(number: Int) {\n var tempNumber = number\n var attemptCounts = 0\n for (side in sides.reversedArray()) {\n val tempCount: Int = tempNumber / side\n\n if (tempCount == 0) continue\n\n attemptCounts += tempCount\n\n if (tempNumber % side == 0) {\n output.add(attemptCounts)\n break\n }\n\n tempNumber %= side\n }\n}"}, {"source_code": "val sides = arrayOf(2, 3, 4, 5, 6, 7)\nval output = mutableListOf()\n\nfun main() {\n\n val requestCounts = readInt()\n for (i in 0 until requestCounts) {\n val number: Int = readInt()\n calculateAttemptCounts(number)\n }\n\n output.forEachIndexed { index, i ->\n if (index == output.lastIndex) print(i)\n else println(i)\n }\n}\n\nfun readInt(): Int {\n return readLine()!!.toInt()\n}\n\nfun calculateAttemptCounts(number: Int) {\n var tempNumber = number\n var attemptCounts = 0\n for (side in sides.reversedArray()) {\n val tempCount: Int = tempNumber / side\n\n if (tempCount == 0) continue\n\n attemptCounts += tempCount\n\n if (tempNumber % side == 0) {\n output.add(attemptCounts)\n break\n }\n\n tempNumber %= side\n }\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n var T = readInt()\n while(T>0) {\n var x = readInt()\n println(\"%d\".format(x))\n T--\n }\n\n}"}, {"source_code": "import java.util.Scanner\nfun main(args:Array) {\n val read = Scanner(System.`in`)\n val t:Int = read.nextInt()\n for (i in 1..t)\n {\n val n:Int = read.nextInt()\n val ans = n/2 + n%2\n println(\"$ans\")\n }\n\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val reader = Scanner(System.`in`)\n val queries = reader.nextInt()\n println(queries)\n val output = IntArray(queries)\n for (i in 0 until queries) {\n val point = reader.nextInt()\n output[i] = getCount(point)\n }\n output.forEach {\n println(it)\n }\n}\n\nfun getCount(point: Int): Int {\n return if (point in 2..7) {\n 1\n } else {\n val rem = point % 7\n if (rem == 0) {\n point / 7\n } else {\n (point / 7) + 1\n }\n }\n}"}, {"source_code": "fun main(){\n val roundCount = readLine()?.toIntOrNull()\n roundCount?.let {count->\n val arrayOfPoints = Array(3){\n readLine()?.toIntOrNull()\n }\n arrayOfPoints.forEach {\n it?.let {\n println(it/2)\n }\n }\n }\n}"}, {"source_code": "fun main(args : Array){\n if (args.isNotEmpty()) {\n Array(args[0].toInt()) { i ->(args[i+1].toInt()/7)+1 }.forEach(::print)\n }\n}"}, {"source_code": "import java.util.*\n \nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = readLine()!!.toInt()\n for(x in 0..n-1){\n \tval tmp = readLine()!!.toInt()\n \tprintln(tmp)\n }\n \n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n repeat (n) {\n readLine()!!.toInt()\n println(n)\n }\n}"}, {"source_code": "fun main(){\n val points = readLine()!!.toInt()\n println((points/7)+1)\n}"}, {"source_code": "fun main() {\n val MIN_VAL = 2\n val MAX_VAL = 7\n val N = readLine()!!.toInt()\n val scores: MutableList = ArrayList()\n for (i in 0 until N) {\n scores.add(readLine()!!.toInt())\n }\n val answer: MutableList = ArrayList()\n\n scores.forEach {\n var currentScore = MAX_VAL\n var currentAmountScore = it\n var amountSteps = 0\n\n while (currentAmountScore >= 0 && currentScore >= MIN_VAL) {\n while (currentScore <= currentAmountScore) {\n currentAmountScore -= currentScore\n amountSteps++\n }\n currentScore--\n }\n answer.add(amountSteps)\n }\n answer.forEach(::println)\n}\n"}, {"source_code": "import java.io.*\nimport java.math.*\nimport java.text.*\nimport java.util.*\nimport java.util.regex.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val t = scan.nextInt()\n for (i in 1..t) {\n val num = scan.nextInt()\n if( num%2==0)\n print(\"1\\n\")\n else\n print(\"2\\n\")\n }\n}"}, {"source_code": "fun main()\n{\n val t = readLine()!!.toInt()\n for (i in 1 .. t)\n {\n println(treatTestCase())\n }\n}\n\nfun treatTestCase(): String\n{\n val x = readLine()!!.toInt()\n\n // if even, return divided by 2\n // else if its 3 return 1\n // else remove three then return divided by 2 + 1\n\n return when\n {\n x % 2 == 0 ->\n {\n println(\"Roll 2 ${x / 2} times\")\n (x / 2).toString()\n }\n x == 3 ->\n {\n println(\"Roll 3 once\")\n (1).toString()\n }\n else ->\n {\n println(\"Roll 3 once and 2 ${(x - 3) / 2} times\")\n ((x - 3) / 2 + 1).toString()\n }\n }\n}"}, {"source_code": "fun main() {\n readLine()?.toInt()?.let { numCases ->\n for (case in 0 until numCases) {\n readLine()?.toInt()?.let { println(numRolls(it)) }\n }\n }\n}\n\nprivate fun numRolls(points: Int): Int {\n var numRolls = 0\n var remainingPoints = points\n for (i in 7 downTo 2) {\n var rolls = remainingPoints / i\n while (rolls > 0) {\n numRolls += rolls\n remainingPoints %= i\n rolls = remainingPoints / i\n }\n }\n return numRolls\n}"}, {"source_code": "fun main()\n{\n val t = readLine()!!.toInt()\n for (i in 1 .. t)\n {\n println(treatTestCase())\n }\n}\n\nfun treatTestCase(): String\n{\n val x = readLine()!!.trim().toInt()\n\n // if even, return divided by 2\n // else if its 3 return 1\n // else remove three then return divided by 2 + 1\n\n return when\n {\n x % 2 == 0 ->\n {\n println(\"Roll 2 ${x / 2} times\")\n (x / 2).toString()\n }\n x == 3 ->\n {\n println(\"Roll 3 once\")\n (1).toString()\n }\n else ->\n {\n println(\"Roll 3 once and 2 ${(x - 3) / 2} times\")\n ((x - 3) / 2 + 1).toString()\n }\n }\n}"}, {"source_code": "private fun main() {\n\n val t = readInt()\n val mas = mutableListOf()\n (0 until t).forEach {\n mas += readInt()\n }\n\n mas.forEach { num ->\n if (num == 2) {\n println(1)\n\n } else if (num % 2 == 0) {\n println(num / 2)\n } else {\n println((num - 1) / 2 + 1)\n }\n }\n}\n\n////////////////////////////////////////////////// STUFF ///////////////////////////////////////////////////////////////\n\n// input\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n\n// algorithms\n\n// binomial coefficients C^n_k\n\nprivate fun cN2(n: Int): Int {\n if (n <= 1)\n throw IllegalArgumentException(\"n must be positive integer >= 2\")\n\n return n * (n - 1) / 2\n}"}, {"source_code": "fun main(args: Array) {\n args.forEach{\n println(it)\n }\n}"}, {"source_code": "fun main() {\n var t = Integer.parseInt(readLine())\n\n while(t > 0) {\n var res = solve(Integer.parseInt(readLine()))\n println(res)\n t--\n }\n\n}\n\nfun solve(n:Int):Int {\n var res = 0\n var m = n\n for(i in 7 downTo 2) {\n res += m/i\n m %= i\n }\n return res\n}\n"}, {"source_code": "fun main(){\n val points = readLine()!!.toInt()\n println((points/7)+1)\n}"}, {"source_code": "fun main() {\n val t = readLine()!!.toInt()\n for (i in 1..t) {\n val x = readLine()!!.toInt()\n println (x / 2 + x % 2)\n }\n}"}, {"source_code": "fun main() {\n var t = Integer.parseInt(readLine())\n\n while(t > 0) {\n var res = solve(Integer.parseInt(readLine()))\n println(res)\n t--\n }\n\n}\n\nfun solve(n:Int):Int {\n var res = 0\n var m = n\n for(i in 7 downTo 2) {\n res += m/i\n m %= i\n }\n return res\n}\n"}, {"source_code": "fun main(args: Array) {\n args.slice(1 until args.size).forEach{\n var number = it.toInt()\n var counter = 0\n while( number > 0 ){\n number -= 7\n counter++\n }\n println(counter)\n }\n}"}, {"source_code": "fun main()\n{\n var n = readLine()!!.toInt()\n \n for (i in 1..n)\n {\n var x = readLine()!!.toInt()\n \n var j = 0\n \n while (x >= 6)\n {\n j++\n x -= 6\n }\n \n println(j)\n \n } \n}\n"}, {"source_code": "fun main()\n{\n val n = readLine()!!.toInt() / 2\n println(n)\n}"}, {"source_code": "fun main() {\n readLine()?.toInt()?.let { numCases ->\n for (case in 0 until numCases) {\n readLine()?.toInt()?.let { println(numRolls(it)) }\n }\n }\n}\n\nprivate fun numRolls(points: Int): Int {\n var numRolls = 0\n var remainingPoints = points\n for (i in 7 downTo 2) {\n var rolls = remainingPoints / i\n while (rolls > 0) {\n numRolls += rolls\n remainingPoints %= i\n rolls = remainingPoints / i\n }\n }\n return numRolls\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n for (i in 0 until sc.nextInt()) {\n val n = sc.nextInt()\n val q = n / 2\n val p = n % 2\n println(q - p)\n }\n}\n"}, {"source_code": "fun main(args: Array) {\n\n val diceNumbers = 7 downTo 2\n val rounds = readLine()!!.toInt()\n\n val queriedNumbers = (1..rounds).asSequence()\n .map { readLine() }\n .filterNotNull()\n .map { it.toInt() }\n .toList()\n\n for (queriedNumber in queriedNumbers)\n {\n var rolls = 0\n var remaining = queriedNumber\n\n for (diceNumber in diceNumbers)\n {\n val rollsWithCurrentNumber = remaining / diceNumber\n\n rolls += rollsWithCurrentNumber\n remaining -= rollsWithCurrentNumber * diceNumber\n\n if (remaining == 0)\n {\n break\n }\n }\n\n println(rolls)\n }\n}\n\n"}, {"source_code": "class DiceRolling {\n fun all(points: List): List {\n val results = mutableListOf()\n points.forEach { results.add(one(it)) }\n return results\n }\n\n // 2, 3, 4, 5, 6, 7\n fun one(point: Int): Int {\n return if (point <= 7) 1\n else {\n 1 + one(point - 6)\n }\n }\n}\n\nfun main(args: Array) {\n val points = args.drop(1).map { Integer.parseInt(it) }\n println(DiceRolling().all(points))\n}"}, {"source_code": "fun main() {\n val t = readLine()!!.toInt()\n for (i in 1..t) {\n val x = readLine()!!.toInt()\n println (x / 2 - x % 2)\n }\n}"}, {"source_code": "fun main(args: Array) {\n val scanner = java.util.Scanner(System.`in`)\n var inputCount = scanner.nextLine()\n val count = inputCount.toInt()\n var inputList = ArrayList(count)\n\n val minBoneValue = 2\n val maxBoneValue = 7\n val minValue = 1\n\n for (x in minValue..count) {\n var value = scanner.nextLine()\n inputList.add(value.toInt())\n }\n\n for (x in inputList) {\n if(x >= minBoneValue && x <= maxBoneValue){\n println(minValue)\n }\n else {\n var throwsCount = (x/maxBoneValue)\n val remainder = x%maxBoneValue\n if(remainder > minValue)\n throwsCount++\n println(throwsCount)\n }\n }\n}\n\n\n"}, {"source_code": "fun main()\n{\n val t = readLine()!!.toInt()\n for (i in 1 .. t)\n {\n println(treatTestCase())\n }\n}\n\nfun treatTestCase(): String\n{\n var x = readLine()!!.toInt()\n\n var c = 7\n var count = 0\n\n while (x > 0 && c > 1)\n {\n if (x >= c)\n {\n val remainder = x % c\n count += (x - remainder) / c\n x = remainder\n }\n\n c--\n }\n\n return count.toString()\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\nfun main() {\n val read=Scanner(System.`in`);\n var test=read.nextInt();\n while((test--)>0){\n var x=read.nextInt();\n println(x);\n var cnt=0;\n\n for (i in 7 downTo 2){\n\n if(x==0)break;\n cnt+=x/i;\n x %= i;\n }\n println(cnt);\n }\n}\n"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val T = readInt()\n for (t in 0..T-1) {\n val n = readInt()\n println((n + 1) / 2)\n }\n}\n"}, {"source_code": "import java.util.*\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readLong() = readLn().toLong()\n// etc for other types you'd use in your solutions\nfun main(args: Array){\n val t = readInt()\n for(i in 1..t){\n var x = readInt()\n var total: Int=0\n for(j in 7 downTo 2){\n total += x/j\n x = x%j\n }\n println(\"$total\")\n }\n}"}, {"source_code": "\n\nimport java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)){\n\n val dice = arrayOf(7,6,5,4,3,2)\n\n val t = nextInt()\n val points = IntArray(t)\n for (count in 0 until t)\n points[count] = nextInt()\n\n for(point in points){\n var rolls = 0\n var tempPoint = point\n for(num in dice)\n if(num <= tempPoint)\n {\n rolls += (tempPoint/num)\n tempPoint %= num\n }\n println(rolls)\n }\n}"}, {"source_code": "fun main(args: Array) {\n val countLine = readLine()\n println(countLine)\n}"}, {"source_code": "import java.util.*\n\nfun main(){\n val scanner = Scanner(System.`in`)\n var queries = scanner.nextInt()\n var queryList = arrayListOf()\n\n if(queries<=100) {\n while (queries > 0) {\n val contest = scanner.nextInt()\n if(contest in 2..100)\n {queryList.add(contest)}\n queries--\n }\n }\n for(elem in queryList){\n rollDice(elem)\n }\n}\n\nval diceEyes = listOf(2,3,4,5,6,7)\n\nval evenEyes = listOf(2,4,6)\n\nfun rollDice(number: Int): List{\n val rolls = mutableListOf()\n var sum = 0\n var i = 0\n if(number % 2 == 0){\n i = evenEyes.size-1\n }else{\n i = diceEyes.size-1\n }\n while(sum != number && i >= 0){\n var tempSum = sum\n if(number % 2 == 0){\n tempSum+=evenEyes[i]\n }else{\n tempSum += diceEyes[i]\n }\n\n if(tempSum <= number){\n sum = tempSum\n rolls.add(diceEyes[i])\n }else{\n i--\n }\n }\n println(\"${rolls.size}\")\n return rolls\n}\n"}, {"source_code": "fun main() {\n val MIN_VAL = 2\n val MAX_VAL = 7\n val N = readLine()!!.toInt()\n val scores: MutableList = ArrayList()\n for (i in 0 until N) {\n scores.add(readLine()!!.toInt())\n }\n val answer: MutableList = ArrayList()\n\n scores.forEach {\n var currentScore = MAX_VAL\n var currentAmountScore = it\n var amountSteps = 0\n\n while (currentAmountScore >= 0 && currentScore >= MIN_VAL) {\n while (currentScore <= currentAmountScore) {\n currentAmountScore -= currentScore\n amountSteps++\n }\n currentScore--\n }\n answer.add(amountSteps)\n }\n answer.forEach(::println)\n}\n"}, {"source_code": "fun main() {\n val parsed: List = Parser().parse()\n val solver = Solver()\n val res = parsed.map { x -> solver.solve(x) }\n res.forEach{x-> println(x)}\n}\n\nclass Solver {\n private val faces : List = listOf(2,3,4,5,6,7)\n\n fun solve(target : Int) : Int {\n var idx: Int = faces.size - 1\n var rollCount = 1\n var currentTarget: Int = target\n for (i: Int in 0..idx) {\n val currentFace: Int = faces[idx]\n if (currentTarget < currentFace) {\n continue\n }\n currentTarget -= currentFace\n rollCount++\n }\n return rollCount\n }\n}\n\nclass Parser {\n private fun lineSequence(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.constrainOnce().take(limit)\n private fun readln() = readLine()!!\n private fun readlnInt() = readln().toInt()\n\n fun parse(): List {\n val queryNumber: Int = readlnInt()\n return lineSequence(queryNumber).map { x -> x.toInt() }.toList()\n }\n}"}, {"source_code": "import com.sun.org.apache.xpath.internal.operations.Bool\n\nfun main(args: Array) {\n val scanner = java.util.Scanner(System.`in`)\n var inputCount = scanner.nextLine()\n val count = inputCount.toInt()\n var inputList = ArrayList(count)\n\n val minBoneValue = 2\n val maxBoneValue = 7\n val minValue = 1\n\n for (x in minValue..count) {\n var value = scanner.nextLine()\n inputList.add(value.toInt())\n }\n\n for (x in inputList) {\n if(x >= minBoneValue && x <= maxBoneValue){\n println(minValue)\n }\n else {\n var throwsCount = (x/maxBoneValue)\n val remainder = x%maxBoneValue\n if(remainder != minValue)\n throwsCount++\n println(throwsCount)\n }\n }\n}\n\n\n"}, {"source_code": "import java.io.*\nimport java.math.*\nimport java.text.*\nimport java.util.*\nimport java.util.regex.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val t = scan.nextInt()\n for (i in 1..t) {\n val num = scan.nextInt()\n if( num%2==0)\n print(\"1\\n\")\n else\n print(\"2\\n\")\n }\n}"}, {"source_code": "fun readInts(separator: Char = ' ') = readLine()!!.split(separator).map(String::toInt)\nfun main() {\n val A = readInts()\n for(i in 1..A.size-1){\n val x = A[i]/2\n println(\"$x\")\n }\n}"}, {"source_code": "fun main() {\n var t = Integer.parseInt(readLine())\n\n while(t > 0) {\n var res = solve(Integer.parseInt(readLine()))\n println(res)\n t--\n }\n\n}\n\nfun solve(n:Int):Int {\n var res = 0\n var m = n\n for(i in 7 downTo 2) {\n res += m/i\n m %= i\n }\n return res\n}\n"}, {"source_code": "import java.io.*\nimport java.math.*\nimport java.text.*\nimport java.util.*\nimport java.util.regex.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val t = scan.nextInt()\n for (i in 1..t) {\n val num = scan.nextInt()\n if( num%2==0)\n print(\"1\\n\")\n else\n print(\"2\\n\")\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(){\n val scanner = Scanner(System.`in`)\n var queries = scanner.nextInt()\n if(queries<=100) {\n while (queries > 0) {\n rollDice(scanner.nextInt())\n queries--\n }\n }\n}\n\nval diceEyes = listOf(2,3,4,5,6,7)\n\nfun rollDice(number: Int): List{\n val rolls = mutableListOf()\n var sum = 0\n var i = diceEyes.size-1\n while(sum != number && i >= 0){\n var tempSum = sum\n tempSum += diceEyes[i]\n if(tempSum <= number){\n sum = tempSum\n rolls.add(diceEyes[i])\n }else{\n i--\n }\n }\n println(\"${rolls.size}\")\n return rolls\n}\n"}, {"source_code": "fun main() {\n println(5)\n}"}, {"source_code": "import kotlin.random.Random\n\nfun main(args: Array) {\n args.slice(1 until args.size).forEach{\n var number = it.toInt()\n var counter = 0\n while( number > 7 ){\n number -= Random.nextInt(2, 7)\n counter++\n }\n println(counter)\n }\n}"}, {"source_code": "import java.util.*\n \nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = readLine()!!.toInt()\n for(x in 0..n-1){\n \tval tmp = readLine()!!.toInt()\n \tif(tmp <= 6) println(\"1\")\n \telse{\n \t\tprintln(tmp/6+tmp%6)\n \t}\n }\n \n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n for (i in 0 until n) {\n val x = readLine()!!.toInt()\n val t = x / 2\n if (t*2 == x) {\n println(t)\n } else {\n println(t+1)\n }\n }\n}"}, {"source_code": "fun main() {\n var t = Integer.parseInt(readLine())\n\n while(t > 0) {\n var res = solve(Integer.parseInt(readLine()))\n println(res)\n t--\n }\n\n}\n\nfun solve(n:Int):Int {\n var res = 0\n var m = n\n for(i in 7 downTo 2) {\n res += m/i\n m %= i\n }\n return res\n}\n"}, {"source_code": "fun main() {\n diceRolling()\n}\n\nval mins = mapOf(\n 2 to 1,\n 3 to 1,\n 4 to 1,\n 5 to 1,\n 6 to 1,\n 7 to 1,\n 8 to 2,\n 9 to 2,\n 10 to 2,\n 11 to 2,\n 12 to 2,\n 13 to 2,\n 14 to 2,\n 15 to 3,\n 16 to 3,\n 17 to 3,\n 18 to 3,\n 19 to 3,\n 20 to 3,\n 21 to 3,\n 22 to 4,\n 23 to 4,\n 24 to 4,\n 25 to 4,\n 26 to 4,\n 27 to 4,\n 28 to 4,\n 29 to 5,\n 30 to 5,\n 31 to 5,\n 32 to 5,\n 33 to 5,\n 34 to 5,\n 35 to 5,\n 36 to 6,\n 37 to 6,\n 38 to 6,\n 39 to 6,\n 40 to 6,\n 41 to 6,\n 42 to 6,\n 43 to 7,\n 44 to 7,\n 45 to 7,\n 46 to 7,\n 47 to 7,\n 48 to 7,\n 49 to 7,\n 50 to 8,\n 51 to 8,\n 52 to 8,\n 53 to 8,\n 54 to 8,\n 55 to 8,\n 56 to 8,\n 57 to 9,\n 58 to 9,\n 59 to 9,\n 60 to 9,\n 61 to 9,\n 62 to 9,\n 63 to 9,\n 64 to 10,\n 65 to 10,\n 66 to 10,\n 67 to 10,\n 68 to 10,\n 69 to 10,\n 70 to 10,\n 71 to 11,\n 72 to 11,\n 73 to 11,\n 74 to 11,\n 75 to 11,\n 76 to 11,\n 77 to 11,\n 78 to 12,\n 79 to 12,\n 80 to 12,\n 81 to 12,\n 82 to 12,\n 83 to 12,\n 84 to 12,\n 85 to 13,\n 86 to 13,\n 87 to 13,\n 88 to 13,\n 89 to 13,\n 90 to 13,\n 91 to 13,\n 92 to 14,\n 93 to 14,\n 94 to 14,\n 95 to 14,\n 96 to 14,\n 97 to 14,\n 98 to 14,\n 99 to 15,\n 100 to 15\n)\n\nfun diceRolling() {\n// val units = listOf(7, 6, 5, 4, 3, 2)\n val inputCount = readLine()!!.toInt()\n \n for (i in 0 until inputCount) {\n println(mins[i])\n }\n\n// (2..100).forEach {\n// println(\"$it to ${compute(it, units)}\")\n// }\n}\n\n//fun compute(target: Int, units: List): Int {\n// if (target in units) return 1\n// if (target == units.max()!! + 1) return 2\n// return 1 + compute(target - units.max()!!, units)\n//}\n"}], "src_uid": "a661b6ce166fe4b2bbfd0ace56a7dc2c"} {"nl": {"description": "Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that this player lost.As soon as Sereja's friends heard of the game, they wanted to play it. Sereja, on the other hand, wanted to find out whether his friends can play the game in such a way that there are no losers. You are given the volumes of all mugs and the cup. Also, you know that Sereja has (n - 1) friends. Determine if Sereja's friends can play the game so that nobody loses.", "input_spec": "The first line contains integers n and s (2 ≤ n ≤ 100; 1 ≤ s ≤ 1000) — the number of mugs and the volume of the cup. The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 10). Number ai means the volume of the i-th mug.", "output_spec": "In a single line, print \"YES\" (without the quotes) if his friends can play in the described manner, and \"NO\" (without the quotes) otherwise.", "sample_inputs": ["3 4\n1 1 1", "3 4\n3 1 3", "3 4\n4 4 4"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "positive_code": [{"source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`), {\n var (n, s) = readLine()!!.split(\" \").map { it.toInt() }\n var mx = 0\n var sum = 0\n for (i in 1..n) {\n sum += nextInt().apply { mx = Math.max(mx, this) }\n }\n if (sum - mx <= s) print(\"YES\") else print(\"NO\")\n})"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (_, s) = readInts()\n val a = readInts()\n print(if (a.sum() - a.max()!! <= s) \"YES\" else \"NO\")\n}"}, {"source_code": "import java.util.*\n \nfun min(a:Double,b:Double) = if (ab) a else b \nfun min(a:Int,b:Int) = if (ab) a else b \nfun printD(d: Double) { print(d) }\nfun printI(d:Int) { print(d) }\nfun printS(d: String) { print(d) }\nfun printL(d: Long) { print(d) }\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readInts() = readLn().split(\" \").map{it.toInt()}\nfun readLong() = readLn().toLong()\nclass pair (var first:Int, var second:Int) \n \nfun solve() {\n val cin = Scanner(System.`in`)\n \n /* \n map[q] <=> map.getOrDefault(q,0) \n Сортировка вектора пар - k=v.sortedWith(compareBy({it.first},{it.second})); \n print(\"${k[i].second}\"); - вывод аргумента пары \n var m=ArrayList (); <=> vector \n getline(cin,a) <=> readLine()!!.last()\n \n readInt() - одно число \n readInts() - несколько чисел \n \n */ \n \n \n \n /* --------- */ \n \n var (a,b)=readInts();\n var q=readInts(); \n var sum=0; \n var max1=0; \n for (i in q) {\n max1=max(max1,i); sum+=i; }\n if (b>=sum-max1) print(\"YES\"); else print(\"NO\"); \n /* --------- */ \n \n}\n \n fun main() {\n val cin = Scanner(System.`in`)\n \n var T=1; \n //T=readLine()!!.toInt(); \n \n for (i55555 in 1..T) solve()\n}\n "}], "negative_code": [], "src_uid": "496baae594b32c5ffda35b896ebde629"} {"nl": {"description": "Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that si = b. Of course, you are the person he asks for a help.", "input_spec": "The first line of the input contain three integers a, b and c ( - 109 ≤ a, b, c ≤ 109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.", "output_spec": "If b appears in the sequence s print \"YES\" (without quotes), otherwise print \"NO\" (without quotes).", "sample_inputs": ["1 7 3", "10 10 0", "1 -4 5", "0 60 50"], "sample_outputs": ["YES", "YES", "NO", "NO"], "notes": "NoteIn the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.In the third sample all elements of the sequence are greater than Vasya's favorite integer.In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer."}, "positive_code": [{"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val (s, n) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val n = r.readLine()!!.toInt()\n val (a, b, c) = r.readLine()!!.split(\" \").map { it.toLong() }\n when {\n c == 0L && a != b -> println(\"NO\")\n c == 0L -> println(\"YES\")\n else -> println(if ((b - a) % c == 0L && ((b >= a&&c>0)||(b<=a&&c<0))) \"YES\" else \"NO\")\n }\n}"}, {"source_code": "import java.io.*\nimport java.math.BigDecimal\nimport java.math.BigInteger\nimport java.util.StringTokenizer\nimport java.util.Stack\nimport java.util.TreeMap\n\nobject programkt {\n interface Scanner {\n fun changeInputStream(inputStream: InputStream)\n fun nextInt(): Int\n fun nextLong(): Long\n fun nextDouble(): Double\n fun nextChar(): Char\n fun nextString(): String\n fun nextLine(): String\n fun nextBigInteger(): BigInteger\n fun nextBigDecimal(): BigDecimal\n }\n\n abstract class Task {\n //KT Extensions\n fun > min(a: T, b: T) = if (a > b) b else a\n fun > max(a: T, b: T) = if (a < b) b else a\n fun abs(a: Int) = if (a > 0) a else -(a)\n fun abs(a: Long) = if (a > 0) a else -(a)\n fun abs(a: Float) = if (a > 0) a else -(a)\n fun abs(a: Double) = if (a > 0) a else -(a)\n operator fun Iterable.invoke(function: (it: T) -> Unit) { this.forEach(function) }\n private fun String.prefix(pi: Array): Array {\n pi[0] = 0\n (1 until this.length) {\n var j = pi[it - 1]\n while (j > 0 && this[it] != this[j]) {\n j = pi[j - 1]\n }\n if(this[it] == this[j]) {\n j++\n }\n pi[it] = j\n }\n return pi\n }\n private fun String.kmpFind(pattern: String): Int {\n val m = pattern.length\n val dfa = Array(256) { IntArray(m) }\n dfa[pattern[0].toInt()][0] = 1\n var x = 0\n var j = 1\n while (j < m) {\n for (c in 0 until 256) {\n dfa[c][j] = dfa[c][x] // Copy mismatch cases.\n }\n dfa[pattern[j].toInt()][j] = j + 1 // Set match case.\n x = dfa[pattern[j].toInt()][x] // Update restart state.\n j++\n }\n\n val n = this.length\n var i: Int = 0\n j = 0\n while (i < n && j < m) {\n j = dfa[this[i].toInt()][j]\n i++\n }\n if (j == m) return i - m // found\n return n // not found\n }\n fun fuckExceptions(invoker: () -> Unit) = try { invoker.invoke() } catch (_: Throwable) {}\n\n enum class EdgeType {\n DIRECTED,\n UNDIRECTED\n }\n data class Vertex>(\n val data: T\n ) {\n override fun toString(): String = \"V:$data\"\n }\n data class Edge>(\n var source: Vertex,\n var destination: Vertex,\n val weight: Double?\n )\n interface Graphable> {\n fun createVertex(data: T): Vertex\n fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double? = 0.0)\n fun weight(source: Vertex, destination: Vertex): Double?\n fun edges(source: Vertex): MutableList>?\n }\n class AdjacencyList>: Graphable {\n var adjacencyMap: MutableMap, MutableList>> = mutableMapOf()\n\n private fun addDirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n adjacencyMap[source]?.add(Edge(source = source, destination = destination, weight = weight))\n }\n\n private fun addUndirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n addDirectedEdge(source, destination, weight)\n addDirectedEdge(destination, source, weight)\n }\n\n override fun createVertex(data: T): Vertex {\n val vertex = Vertex(data = data)\n adjacencyMap[vertex] ?: run {\n adjacencyMap[vertex] = mutableListOf()\n }\n return vertex\n }\n\n override fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double?) = when(type) {\n EdgeType.DIRECTED -> addDirectedEdge(source, destination, weight)\n EdgeType.UNDIRECTED -> addUndirectedEdge(source, destination, weight)\n }\n\n override fun weight(source: Vertex, destination: Vertex): Double? {\n adjacencyMap[source]?.forEach {\n if(it.destination == destination) return it.weight\n }\n return null\n }\n\n override fun edges(source: Vertex): MutableList>? = adjacencyMap[source]\n\n override fun toString(): String {\n var result = \"\"\n for ((vertex, edges) in adjacencyMap) {\n var edgeString = \"\"\n for ((index, edge) in edges.withIndex()) {\n edgeString += if (index != edges.count() - 1) \"${edge.destination}, \"\n else \"${edge.destination}\"\n }\n result += \"$vertex ---> [ $edgeString ] \\n\"\n }\n return result\n }\n\n fun depthFirstSearch(start: Vertex, end: Vertex): Stack> {\n val visited: HashSet> = hashSetOf()\n val stack: Stack> = Stack()\n stack.push(start)\n visited.add(start)\n\n var currentVertex = stack.peek()\n loop@while (currentVertex != null && currentVertex != end) {\n val neighbors = edges(currentVertex)\n if(neighbors != null && neighbors.count() > 0) {\n for(edge in neighbors) {\n if(!visited.contains(edge.destination)) {\n visited.add(edge.destination)\n stack.push(edge.destination)\n currentVertex = stack.peek()\n continue@loop\n }\n }\n } else {\n stack.pop()\n currentVertex = stack.peek()\n continue\n }\n\n stack.pop()\n currentVertex = stack.peek()\n }\n\n return stack\n }\n\n fun breadthFirstSearch() {\n\n }\n\n fun floydWarshallAlgorythm(): Pair, Array> {\n val nVertices = this.adjacencyMap.size\n\n val weights = Array(nVertices) { Array(nVertices-1) { 0.0 } }\n this.adjacencyMap\n .asSequence()\n .map { it.value }\n .withIndex()\n .forEach { (index, weightsOfVertex) ->\n weightsOfVertex.asSequence()\n .withIndex()\n .forEach { (weightIndex, weight) ->\n weights[index][weightIndex] = weight.weight!!\n }\n }\n\n val dist = Array(nVertices) { DoubleArray(nVertices) { Double.POSITIVE_INFINITY } }\n for (w in weights) dist[(w[0] - 1).toInt()][(w[1] - 1).toInt()] = w[2]\n val next = Array(nVertices) { IntArray(nVertices) }\n for (i in 0 until next.size) {\n for (j in 0 until next.size) {\n if (i != j) next[i][j] = j + 1\n }\n }\n for (k in 0 until nVertices) {\n for (i in 0 until nVertices) {\n for (j in 0 until nVertices) {\n if (dist[i][k] + dist[k][j] < dist[i][j]) {\n dist[i][j] = dist[i][k] + dist[k][j]\n next[i][j] = next[i][k]\n }\n }\n }\n }\n return dist to next\n }\n }\n\n fun > TreeMap>.toAdjacencyList(type: EdgeType): AdjacencyList {\n val list = AdjacencyList()\n\n this.keys.forEach { list.createVertex(it) }\n this.entries\n .asSequence()\n .withIndex()\n .forEach { (x, edge) ->\n val vertex = list.createVertex(edge.key)\n edge.value\n .asSequence()\n .withIndex()\n .forEach { (y, weight) ->\n if(weight != .0 && y != x)\n list.add(type, vertex, list.createVertex(this.keys.elementAt(y)), weight)\n }\n }\n return list\n }\n\n open class Point, Y: Comparable>(open var x: X, open var y: Y) {\n operator fun component1() = x\n operator fun component2() = y\n override fun equals(other: Any?): Boolean = when {\n other == null -> false\n other !is Point<*, *> -> false\n other.x != this.x -> false\n other.y != this.y -> false\n else -> true\n }\n }\n\n class IntPoint(override var x: Int, override var y: Int): Point(x, y) {\n operator fun plus(point: IntPoint) = IntPoint(this.x + point.x, this.y + point.y)\n operator fun minus(point: IntPoint) = IntPoint(this.x - point.x, this.y - point.y)\n operator fun div(point: IntPoint) = IntPoint(this.x / point.x, this.y / point.y)\n operator fun times(point: IntPoint) = IntPoint(this.x * point.x, this.y * point.y)\n\n operator fun plus(coefficient: Int) = IntPoint(this.x + coefficient, this.y + coefficient)\n operator fun minus(coefficient: Int) = IntPoint(this.x - coefficient, this.y - coefficient)\n operator fun div(coefficient: Int) = IntPoint(this.x / coefficient, this.y / coefficient)\n operator fun times(coefficient: Int) = IntPoint(this.x * coefficient, this.y * coefficient)\n\n fun distanceTo(point: IntPoint) = Math.sqrt(((this.x - point.x) * (this.x - point.x) + (this.y-point.y) * (this.y - point.y)).toDouble())\n }\n class LongPoint(override var x: Long, override var y: Long): Point(x, y) {\n constructor(x: Int, y: Int): this(x.toLong(), y.toLong())\n\n operator fun plus(point: LongPoint) = LongPoint(this.x + point.x, this.y + point.y)\n operator fun minus(point: LongPoint) = LongPoint(this.x - point.x, this.y - point.y)\n operator fun div(point: LongPoint) = LongPoint(this.x / point.x, this.y / point.y)\n operator fun times(point: LongPoint) = LongPoint(this.x * point.x, this.y * point.y)\n\n operator fun plus(coefficient: Long) = LongPoint(this.x + coefficient, this.y + coefficient)\n operator fun plus(coefficient: Int) = LongPoint(this.x + coefficient, this.y + coefficient)\n operator fun minus(coefficient: Long) = LongPoint(this.x - coefficient, this.y - coefficient)\n operator fun minus(coefficient: Int) = LongPoint(this.x - coefficient, this.y - coefficient)\n operator fun div(coefficient: Long) = LongPoint(this.x / coefficient, this.y / coefficient)\n operator fun div(coefficient: Int) = LongPoint(this.x / coefficient, this.y / coefficient)\n operator fun times(coefficient: Long) = LongPoint(this.x * coefficient, this.y * coefficient)\n operator fun times(coefficient: Int) = LongPoint(this.x * coefficient, this.y * coefficient)\n\n fun distanceTo(point: LongPoint) = Math.sqrt(((this.x - point.x) * (this.x - point.x) + (this.y-point.y) * (this.y - point.y)).toDouble())\n }\n open class DoublePoint(override var x: Double, override var y: Double): Point(x, y) {\n constructor(x: Int, y: Int): this(x.toDouble(), y.toDouble())\n constructor(x: Long, y: Long): this(x.toDouble(), y.toDouble())\n\n operator fun plus(point: DoublePoint) = DoublePoint(this.x + point.x, this.y + point.y)\n operator fun minus(point: DoublePoint) = DoublePoint(this.x - point.x, this.y - point.y)\n operator fun div(point: DoublePoint) = DoublePoint(this.x / point.x, this.y / point.y)\n operator fun times(point: DoublePoint) = DoublePoint(this.x * point.x, this.y * point.y)\n\n operator fun plus(coefficient: Double) = DoublePoint(this.x + coefficient, this.y + coefficient)\n operator fun plus(coefficient: Long) = DoublePoint(this.x + coefficient, this.y + coefficient)\n operator fun plus(coefficient: Int) = DoublePoint(this.x + coefficient, this.y + coefficient)\n operator fun minus(coefficient: Double) = DoublePoint(this.x - coefficient, this.y - coefficient)\n operator fun minus(coefficient: Long) = DoublePoint(this.x - coefficient, this.y - coefficient)\n operator fun minus(coefficient: Int) = DoublePoint(this.x - coefficient, this.y - coefficient)\n operator fun div(coefficient: Double) = DoublePoint(this.x / coefficient, this.y / coefficient)\n operator fun div(coefficient: Long) = DoublePoint(this.x / coefficient, this.y / coefficient)\n operator fun div(coefficient: Int) = DoublePoint(this.x / coefficient, this.y / coefficient)\n operator fun times(coefficient: Double) = DoublePoint(this.x * coefficient, this.y * coefficient)\n operator fun times(coefficient: Long) = DoublePoint(this.x * coefficient, this.y * coefficient)\n operator fun times(coefficient: Int) = DoublePoint(this.x * coefficient, this.y * coefficient)\n\n fun distanceTo(point: DoublePoint) = Math.sqrt(((this.x - point.x) * (this.x - point.x) + (this.y-point.y) * (this.y - point.y)))\n fun polarAngle(): Double {\n val minPolarAngle = Math.atan2(y, x)\n return if(minPolarAngle < 0) minPolarAngle + 2 * Math.PI else minPolarAngle\n }\n }\n class Vector(x: Double, y: Double): DoublePoint(x, y) {\n constructor(x: Int, y: Int): this(x.toDouble(), y.toDouble())\n constructor(x: Long, y: Long): this(x.toDouble(), y.toDouble())\n\n fun length() = Math.sqrt(x*x + y*y)\n fun angleTo(vector: Vector): Double {\n val temp = this * vector\n return Math.acos((temp.x + temp.y) / this.length() / vector.length())\n }\n }\n //End KT Extensions\n\n abstract fun solve(scanner: Scanner, printer: PrintWriter)\n }\n\n class FastScanner: Scanner {\n var inputStream: InputStream? = null\n override fun changeInputStream(inputStream: InputStream) {\n this.inputStream = inputStream\n this.bufferedReader = BufferedReader(InputStreamReader(inputStream))\n }\n\n private lateinit var bufferedReader: BufferedReader\n private var stringTokenizer: StringTokenizer? = null\n\n private fun nextToken(): String? {\n while (stringTokenizer == null || !stringTokenizer!!.hasMoreTokens())\n stringTokenizer = StringTokenizer(bufferedReader.readLine() ?: return null)\n return stringTokenizer!!.nextToken()\n }\n\n override fun nextInt() = nextToken()!!.toInt()\n override fun nextLong() = nextToken()!!.toLong()\n override fun nextDouble() = nextToken()!!.toDouble()\n override fun nextChar() = bufferedReader.read().toChar()\n override fun nextString() = nextToken()!!\n override fun nextLine() = bufferedReader.readLine()!!\n override fun nextBigInteger() = BigInteger(nextToken()!!)\n override fun nextBigDecimal() = BigDecimal(nextToken()!!)\n }\n\n class TaskBuilder {\n private var task: Task? = null\n private var inputStream: InputStream? = null\n private var outputStream: OutputStream? = null\n private var scanner: Scanner? = null\n\n fun useInputSource(inputStream: InputStream): TaskBuilder {\n this.inputStream = inputStream\n return this\n }\n\n fun useOutputSource(outputStream: OutputStream): TaskBuilder {\n this.outputStream = outputStream\n return this\n }\n\n fun useInputFile(inputFileName: String): TaskBuilder {\n this.inputStream = FileInputStream(File(inputFileName))\n return this\n }\n\n fun useOutputFile(outputFileName: String): TaskBuilder {\n this.outputStream = FileOutputStream(File(outputFileName))\n return this\n }\n\n fun useScanner(scanner: Scanner): TaskBuilder {\n this.scanner = scanner\n return this\n }\n\n\n fun solveTask(task: Task): TaskBuilder {\n this.task = task\n return this\n }\n\n fun run() {\n when {\n task == null -> throw NullPointerException(\"Task cannot be null!\")\n inputStream == null -> throw NullPointerException(\"Input cannot be null!\")\n outputStream == null -> throw NullPointerException(\"Output cannot be null!\")\n scanner == null -> throw NullPointerException(\"Scanner cannot be null!\")\n }\n scanner!!.changeInputStream(inputStream!!)\n val printer = PrintWriter(outputStream)\n TaskRunnable(task!!, scanner!!, printer).run()\n\n inputStream!!.close()\n printer.close()\n }\n\n class TaskRunnable(\n private val task: Task,\n private val scanner: Scanner,\n private val printer: PrintWriter\n ) {\n fun run() {\n task.solve(scanner, printer)\n }\n }\n }\n\n @JvmStatic\n fun main(args: Array) = TaskBuilder()\n// .useInputSource(BufferedInputStream(FileInputStream(\"area1.in\")))\n// .useOutputSource(BufferedOutputStream(FileOutputStream(\"area1.out\")))\n .useInputSource(System.`in`)\n .useOutputSource(System.out)\n .useScanner(FastScanner())\n .solveTask(TaskF())\n .run()\n\n class TaskA: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val length = scanner.nextInt()\n val numbers = Array(length) { scanner.nextInt() }\n\n var maxOnesCount = -1\n\n (0 until length) { i ->\n (i until length) { j ->\n var currentCountOfOnes = 0\n (0 until length) {\n currentCountOfOnes += if((it in (i..j) && 1 - numbers[it] == 1) || (it !in (i..j) && numbers[it] == 1)) 1 else 0 }\n maxOnesCount = max(maxOnesCount, currentCountOfOnes)\n }\n }\n\n printer.println(maxOnesCount)\n }\n\n }\n\n class TaskD: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val length = scanner.nextLong()\n (length until 2 * length) { printer.print(\"$it \") }\n }\n\n }\n\n class TaskE: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val length = scanner.nextInt()\n val lineLengths = Array(length) { scanner.nextInt() }\n lineLengths.sort()\n for(it in (2 until length))\n if(lineLengths[it-2] + lineLengths[it-1] > lineLengths[it]) {\n printer.println(\"YES\")\n return\n }\n printer.println(\"NO\")\n }\n\n }\n\n class TaskF: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val (start, check, delta) = scanner.nextLine()\n .split(\" \")\n .map { it.toLong() }\n when {\n check < start && delta > 0 -> printer.println(\"NO\")\n check > start && delta < 0 -> printer.println(\"NO\")\n delta == 0L && start != check -> printer.println(\"NO\")\n delta == 0L && start == check -> printer.println(\"YES\")\n (check - start) % delta == 0L -> printer.println(\"YES\")\n else -> printer.println(\"NO\")\n }\n }\n\n }\n\n}\n"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n val initial = reader.nextLong()\n val desired = reader.nextLong()\n val seq = reader.nextLong()\n if (desired - initial == 0L) {\n println(\"YES\")\n return\n }\n if (seq == 0L) {\n println(\"NO\")\n return\n }\n if ((desired - initial) % seq == 0L && ((desired - initial) / seq) > 0)\n println(\"YES\")\n else println(\"NO\")\n}\n"}, {"source_code": "fun main() {\n val (a, b, c) = readLine()!!.split(\" \").map(String::toLong)\n print(when {\n a == b -> \"YES\"\n c == 0L -> \"NO\"\n b > a && c < 0 -> \"NO\"\n b < a && c > 0 -> \"NO\"\n (b - a) % c == 0L -> \"YES\"\n else -> \"NO\"\n })\n}"}, {"source_code": "import java.io.PrintWriter\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\nimport kotlin.math.*\n\nval n = 0\nval m = 0\nfun valid(i: Int, j: Int): Boolean {\n return i in 0 until n && j in 0 until m\n}\n\nfun sumRow(arr: IntArray): Int {\n var sum = 0\n for (element in arr) sum += element\n return sum\n}\n\nfun sumCol(twoDArr: Array, colNumber: Int): Int {\n var sum = 0\n for (element in twoDArr) {\n sum += element[colNumber]\n }\n return sum\n}\n\n@JvmField\nval INPUT = System.`in`\n@JvmField\nval OUTPUT = System.out\n\n@JvmField\nval _reader = INPUT.bufferedReader()\n\nfun readLine(): String? = _reader.readLine()!!\nfun readLn() = _reader.readLine()!!\n@JvmField\nvar _tokenizer: StringTokenizer = StringTokenizer(\"\")\n\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\n\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }.toMutableList().toLongArray()\n\n@JvmField\nval _writer = PrintWriter(OUTPUT, false)\n\ninline fun output(block: PrintWriter.() -> Unit) {\n _writer.apply(block).flush()\n}\n\nfun printArr(arr: IntArray, start: Int, end: Int) {\n for (i in start..end) {\n print(\"${arr[i]} \")\n }\n println()\n}\n\nfun printArr(arr: LongArray, start: Int, end: Int) {\n for (i in start..end) {\n print(\"${arr[i]} \")\n }\n println()\n}\n\nfun main() {\n val (a, b, c) = readLongs(3)\n if (a == b) println(\"YES\")\n else if (a < b && c > 0) if (c == 1L) println(\"YES\") else println(if ((b - a) % c == 0L) \"YES\" else \"NO\")\n else if (a > b && c < 0) if (c == -1L) println(\"YES\") else println(if ((b - a) % c == 0L) \"YES\" else \"NO\")\n else println(\"NO\")\n //TODO(\"KYS\")\n}\n\n\n\n"}], "negative_code": [{"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val (s, n) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val n = r.readLine()!!.toInt()\n val (a, b, c) = r.readLine()!!.split(\" \").map { it.toLong() }\n when {\n c == 0L && a != b -> println(\"NO\")\n c == 0L -> println(\"YES\")\n else -> println(if ((b - a) % c == 0L) \"YES\" else \"NO\")\n }\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val (s, n) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val n = r.readLine()!!.toInt()\n val (a, b, c) = r.readLine()!!.split(\" \").map { it.toLong() }\n if (c == 0L) println(\"NO\") else\n println(if ((b - a) % c == 0L) \"YES\" else \"NO\")\n}"}, {"source_code": "import java.io.*\nimport java.math.BigDecimal\nimport java.math.BigInteger\nimport java.util.StringTokenizer\nimport java.util.Stack\nimport java.util.TreeMap\n\nobject programkt {\n interface Scanner {\n fun changeInputStream(inputStream: InputStream)\n fun nextInt(): Int\n fun nextLong(): Long\n fun nextDouble(): Double\n fun nextChar(): Char\n fun nextString(): String\n fun nextLine(): String\n fun nextBigInteger(): BigInteger\n fun nextBigDecimal(): BigDecimal\n }\n\n abstract class Task {\n //KT Extensions\n fun > min(a: T, b: T) = if (a > b) b else a\n fun > max(a: T, b: T) = if (a < b) b else a\n fun abs(a: Int) = if (a > 0) a else -(a)\n fun abs(a: Long) = if (a > 0) a else -(a)\n fun abs(a: Float) = if (a > 0) a else -(a)\n fun abs(a: Double) = if (a > 0) a else -(a)\n operator fun Iterable.invoke(function: (it: T) -> Unit) { this.forEach(function) }\n private fun String.prefix(pi: Array): Array {\n pi[0] = 0\n (1 until this.length) {\n var j = pi[it - 1]\n while (j > 0 && this[it] != this[j]) {\n j = pi[j - 1]\n }\n if(this[it] == this[j]) {\n j++\n }\n pi[it] = j\n }\n return pi\n }\n private fun String.kmpFind(pattern: String): Int {\n val m = pattern.length\n val dfa = Array(256) { IntArray(m) }\n dfa[pattern[0].toInt()][0] = 1\n var x = 0\n var j = 1\n while (j < m) {\n for (c in 0 until 256) {\n dfa[c][j] = dfa[c][x] // Copy mismatch cases.\n }\n dfa[pattern[j].toInt()][j] = j + 1 // Set match case.\n x = dfa[pattern[j].toInt()][x] // Update restart state.\n j++\n }\n\n val n = this.length\n var i: Int = 0\n j = 0\n while (i < n && j < m) {\n j = dfa[this[i].toInt()][j]\n i++\n }\n if (j == m) return i - m // found\n return n // not found\n }\n fun fuckExceptions(invoker: () -> Unit) = try { invoker.invoke() } catch (_: Throwable) {}\n\n enum class EdgeType {\n DIRECTED,\n UNDIRECTED\n }\n data class Vertex>(\n val data: T\n ) {\n override fun toString(): String = \"V:$data\"\n }\n data class Edge>(\n var source: Vertex,\n var destination: Vertex,\n val weight: Double?\n )\n interface Graphable> {\n fun createVertex(data: T): Vertex\n fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double? = 0.0)\n fun weight(source: Vertex, destination: Vertex): Double?\n fun edges(source: Vertex): MutableList>?\n }\n class AdjacencyList>: Graphable {\n var adjacencyMap: MutableMap, MutableList>> = mutableMapOf()\n\n private fun addDirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n adjacencyMap[source]?.add(Edge(source = source, destination = destination, weight = weight))\n }\n\n private fun addUndirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n addDirectedEdge(source, destination, weight)\n addDirectedEdge(destination, source, weight)\n }\n\n override fun createVertex(data: T): Vertex {\n val vertex = Vertex(data = data)\n adjacencyMap[vertex] ?: run {\n adjacencyMap[vertex] = mutableListOf()\n }\n return vertex\n }\n\n override fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double?) = when(type) {\n EdgeType.DIRECTED -> addDirectedEdge(source, destination, weight)\n EdgeType.UNDIRECTED -> addUndirectedEdge(source, destination, weight)\n }\n\n override fun weight(source: Vertex, destination: Vertex): Double? {\n adjacencyMap[source]?.forEach {\n if(it.destination == destination) return it.weight\n }\n return null\n }\n\n override fun edges(source: Vertex): MutableList>? = adjacencyMap[source]\n\n override fun toString(): String {\n var result = \"\"\n for ((vertex, edges) in adjacencyMap) {\n var edgeString = \"\"\n for ((index, edge) in edges.withIndex()) {\n edgeString += if (index != edges.count() - 1) \"${edge.destination}, \"\n else \"${edge.destination}\"\n }\n result += \"$vertex ---> [ $edgeString ] \\n\"\n }\n return result\n }\n\n fun depthFirstSearch(start: Vertex, end: Vertex): Stack> {\n val visited: HashSet> = hashSetOf()\n val stack: Stack> = Stack()\n stack.push(start)\n visited.add(start)\n\n var currentVertex = stack.peek()\n loop@while (currentVertex != null && currentVertex != end) {\n val neighbors = edges(currentVertex)\n if(neighbors != null && neighbors.count() > 0) {\n for(edge in neighbors) {\n if(!visited.contains(edge.destination)) {\n visited.add(edge.destination)\n stack.push(edge.destination)\n currentVertex = stack.peek()\n continue@loop\n }\n }\n } else {\n stack.pop()\n currentVertex = stack.peek()\n continue\n }\n\n stack.pop()\n currentVertex = stack.peek()\n }\n\n return stack\n }\n\n fun breadthFirstSearch() {\n\n }\n\n fun floydWarshallAlgorythm(): Pair, Array> {\n val nVertices = this.adjacencyMap.size\n\n val weights = Array(nVertices) { Array(nVertices-1) { 0.0 } }\n this.adjacencyMap\n .asSequence()\n .map { it.value }\n .withIndex()\n .forEach { (index, weightsOfVertex) ->\n weightsOfVertex.asSequence()\n .withIndex()\n .forEach { (weightIndex, weight) ->\n weights[index][weightIndex] = weight.weight!!\n }\n }\n\n val dist = Array(nVertices) { DoubleArray(nVertices) { Double.POSITIVE_INFINITY } }\n for (w in weights) dist[(w[0] - 1).toInt()][(w[1] - 1).toInt()] = w[2]\n val next = Array(nVertices) { IntArray(nVertices) }\n for (i in 0 until next.size) {\n for (j in 0 until next.size) {\n if (i != j) next[i][j] = j + 1\n }\n }\n for (k in 0 until nVertices) {\n for (i in 0 until nVertices) {\n for (j in 0 until nVertices) {\n if (dist[i][k] + dist[k][j] < dist[i][j]) {\n dist[i][j] = dist[i][k] + dist[k][j]\n next[i][j] = next[i][k]\n }\n }\n }\n }\n return dist to next\n }\n }\n\n fun > TreeMap>.toAdjacencyList(type: EdgeType): AdjacencyList {\n val list = AdjacencyList()\n\n this.keys.forEach { list.createVertex(it) }\n this.entries\n .asSequence()\n .withIndex()\n .forEach { (x, edge) ->\n val vertex = list.createVertex(edge.key)\n edge.value\n .asSequence()\n .withIndex()\n .forEach { (y, weight) ->\n if(weight != .0 && y != x)\n list.add(type, vertex, list.createVertex(this.keys.elementAt(y)), weight)\n }\n }\n return list\n }\n\n open class Point, Y: Comparable>(open var x: X, open var y: Y) {\n operator fun component1() = x\n operator fun component2() = y\n override fun equals(other: Any?): Boolean = when {\n other == null -> false\n other !is Point<*, *> -> false\n other.x != this.x -> false\n other.y != this.y -> false\n else -> true\n }\n }\n\n class IntPoint(override var x: Int, override var y: Int): Point(x, y) {\n operator fun plus(point: IntPoint) = IntPoint(this.x + point.x, this.y + point.y)\n operator fun minus(point: IntPoint) = IntPoint(this.x - point.x, this.y - point.y)\n operator fun div(point: IntPoint) = IntPoint(this.x / point.x, this.y / point.y)\n operator fun times(point: IntPoint) = IntPoint(this.x * point.x, this.y * point.y)\n\n operator fun plus(coefficient: Int) = IntPoint(this.x + coefficient, this.y + coefficient)\n operator fun minus(coefficient: Int) = IntPoint(this.x - coefficient, this.y - coefficient)\n operator fun div(coefficient: Int) = IntPoint(this.x / coefficient, this.y / coefficient)\n operator fun times(coefficient: Int) = IntPoint(this.x * coefficient, this.y * coefficient)\n\n fun distanceTo(point: IntPoint) = Math.sqrt(((this.x - point.x) * (this.x - point.x) + (this.y-point.y) * (this.y - point.y)).toDouble())\n }\n class LongPoint(override var x: Long, override var y: Long): Point(x, y) {\n constructor(x: Int, y: Int): this(x.toLong(), y.toLong())\n\n operator fun plus(point: LongPoint) = LongPoint(this.x + point.x, this.y + point.y)\n operator fun minus(point: LongPoint) = LongPoint(this.x - point.x, this.y - point.y)\n operator fun div(point: LongPoint) = LongPoint(this.x / point.x, this.y / point.y)\n operator fun times(point: LongPoint) = LongPoint(this.x * point.x, this.y * point.y)\n\n operator fun plus(coefficient: Long) = LongPoint(this.x + coefficient, this.y + coefficient)\n operator fun plus(coefficient: Int) = LongPoint(this.x + coefficient, this.y + coefficient)\n operator fun minus(coefficient: Long) = LongPoint(this.x - coefficient, this.y - coefficient)\n operator fun minus(coefficient: Int) = LongPoint(this.x - coefficient, this.y - coefficient)\n operator fun div(coefficient: Long) = LongPoint(this.x / coefficient, this.y / coefficient)\n operator fun div(coefficient: Int) = LongPoint(this.x / coefficient, this.y / coefficient)\n operator fun times(coefficient: Long) = LongPoint(this.x * coefficient, this.y * coefficient)\n operator fun times(coefficient: Int) = LongPoint(this.x * coefficient, this.y * coefficient)\n\n fun distanceTo(point: LongPoint) = Math.sqrt(((this.x - point.x) * (this.x - point.x) + (this.y-point.y) * (this.y - point.y)).toDouble())\n }\n open class DoublePoint(override var x: Double, override var y: Double): Point(x, y) {\n constructor(x: Int, y: Int): this(x.toDouble(), y.toDouble())\n constructor(x: Long, y: Long): this(x.toDouble(), y.toDouble())\n\n operator fun plus(point: DoublePoint) = DoublePoint(this.x + point.x, this.y + point.y)\n operator fun minus(point: DoublePoint) = DoublePoint(this.x - point.x, this.y - point.y)\n operator fun div(point: DoublePoint) = DoublePoint(this.x / point.x, this.y / point.y)\n operator fun times(point: DoublePoint) = DoublePoint(this.x * point.x, this.y * point.y)\n\n operator fun plus(coefficient: Double) = DoublePoint(this.x + coefficient, this.y + coefficient)\n operator fun plus(coefficient: Long) = DoublePoint(this.x + coefficient, this.y + coefficient)\n operator fun plus(coefficient: Int) = DoublePoint(this.x + coefficient, this.y + coefficient)\n operator fun minus(coefficient: Double) = DoublePoint(this.x - coefficient, this.y - coefficient)\n operator fun minus(coefficient: Long) = DoublePoint(this.x - coefficient, this.y - coefficient)\n operator fun minus(coefficient: Int) = DoublePoint(this.x - coefficient, this.y - coefficient)\n operator fun div(coefficient: Double) = DoublePoint(this.x / coefficient, this.y / coefficient)\n operator fun div(coefficient: Long) = DoublePoint(this.x / coefficient, this.y / coefficient)\n operator fun div(coefficient: Int) = DoublePoint(this.x / coefficient, this.y / coefficient)\n operator fun times(coefficient: Double) = DoublePoint(this.x * coefficient, this.y * coefficient)\n operator fun times(coefficient: Long) = DoublePoint(this.x * coefficient, this.y * coefficient)\n operator fun times(coefficient: Int) = DoublePoint(this.x * coefficient, this.y * coefficient)\n\n fun distanceTo(point: DoublePoint) = Math.sqrt(((this.x - point.x) * (this.x - point.x) + (this.y-point.y) * (this.y - point.y)))\n fun polarAngle(): Double {\n val minPolarAngle = Math.atan2(y, x)\n return if(minPolarAngle < 0) minPolarAngle + 2 * Math.PI else minPolarAngle\n }\n }\n class Vector(x: Double, y: Double): DoublePoint(x, y) {\n constructor(x: Int, y: Int): this(x.toDouble(), y.toDouble())\n constructor(x: Long, y: Long): this(x.toDouble(), y.toDouble())\n\n fun length() = Math.sqrt(x*x + y*y)\n fun angleTo(vector: Vector): Double {\n val temp = this * vector\n return Math.acos((temp.x + temp.y) / this.length() / vector.length())\n }\n }\n //End KT Extensions\n\n abstract fun solve(scanner: Scanner, printer: PrintWriter)\n }\n\n class FastScanner: Scanner {\n var inputStream: InputStream? = null\n override fun changeInputStream(inputStream: InputStream) {\n this.inputStream = inputStream\n this.bufferedReader = BufferedReader(InputStreamReader(inputStream))\n }\n\n private lateinit var bufferedReader: BufferedReader\n private var stringTokenizer: StringTokenizer? = null\n\n private fun nextToken(): String? {\n while (stringTokenizer == null || !stringTokenizer!!.hasMoreTokens())\n stringTokenizer = StringTokenizer(bufferedReader.readLine() ?: return null)\n return stringTokenizer!!.nextToken()\n }\n\n override fun nextInt() = nextToken()!!.toInt()\n override fun nextLong() = nextToken()!!.toLong()\n override fun nextDouble() = nextToken()!!.toDouble()\n override fun nextChar() = bufferedReader.read().toChar()\n override fun nextString() = nextToken()!!\n override fun nextLine() = bufferedReader.readLine()!!\n override fun nextBigInteger() = BigInteger(nextToken()!!)\n override fun nextBigDecimal() = BigDecimal(nextToken()!!)\n }\n\n class TaskBuilder {\n private var task: Task? = null\n private var inputStream: InputStream? = null\n private var outputStream: OutputStream? = null\n private var scanner: Scanner? = null\n\n fun useInputSource(inputStream: InputStream): TaskBuilder {\n this.inputStream = inputStream\n return this\n }\n\n fun useOutputSource(outputStream: OutputStream): TaskBuilder {\n this.outputStream = outputStream\n return this\n }\n\n fun useInputFile(inputFileName: String): TaskBuilder {\n this.inputStream = FileInputStream(File(inputFileName))\n return this\n }\n\n fun useOutputFile(outputFileName: String): TaskBuilder {\n this.outputStream = FileOutputStream(File(outputFileName))\n return this\n }\n\n fun useScanner(scanner: Scanner): TaskBuilder {\n this.scanner = scanner\n return this\n }\n\n\n fun solveTask(task: Task): TaskBuilder {\n this.task = task\n return this\n }\n\n fun run() {\n when {\n task == null -> throw NullPointerException(\"Task cannot be null!\")\n inputStream == null -> throw NullPointerException(\"Input cannot be null!\")\n outputStream == null -> throw NullPointerException(\"Output cannot be null!\")\n scanner == null -> throw NullPointerException(\"Scanner cannot be null!\")\n }\n scanner!!.changeInputStream(inputStream!!)\n val printer = PrintWriter(outputStream)\n TaskRunnable(task!!, scanner!!, printer).run()\n\n inputStream!!.close()\n printer.close()\n }\n\n class TaskRunnable(\n private val task: Task,\n private val scanner: Scanner,\n private val printer: PrintWriter\n ) {\n fun run() {\n task.solve(scanner, printer)\n }\n }\n }\n\n @JvmStatic\n fun main(args: Array) = TaskBuilder()\n// .useInputSource(BufferedInputStream(FileInputStream(\"area1.in\")))\n// .useOutputSource(BufferedOutputStream(FileOutputStream(\"area1.out\")))\n .useInputSource(System.`in`)\n .useOutputSource(System.out)\n .useScanner(FastScanner())\n .solveTask(TaskF())\n .run()\n\n class TaskA: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val length = scanner.nextInt()\n val numbers = Array(length) { scanner.nextInt() }\n\n var maxOnesCount = -1\n\n (0 until length) { i ->\n (i until length) { j ->\n var currentCountOfOnes = 0\n (0 until length) {\n currentCountOfOnes += if((it in (i..j) && 1 - numbers[it] == 1) || (it !in (i..j) && numbers[it] == 1)) 1 else 0 }\n maxOnesCount = max(maxOnesCount, currentCountOfOnes)\n }\n }\n\n printer.println(maxOnesCount)\n }\n\n }\n\n class TaskD: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val length = scanner.nextLong()\n (length until 2 * length) { printer.print(\"$it \") }\n }\n\n }\n\n class TaskE: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val length = scanner.nextInt()\n val lineLengths = Array(length) { scanner.nextInt() }\n lineLengths.sort()\n for(it in (2 until length))\n if(lineLengths[it-2] + lineLengths[it-1] > lineLengths[it]) {\n printer.println(\"YES\")\n return\n }\n printer.println(\"NO\")\n }\n\n }\n\n class TaskF: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val (start, check, delta) = scanner.nextLine()\n .split(\" \")\n .map { it.toLong() }\n when {\n check < start -> printer.println(\"NO\")\n delta == 0L && start == check -> printer.println(\"YES\")\n (check - start) % delta == 0L -> printer.println(\"YES\")\n else -> printer.println(\"NO\")\n }\n }\n\n }\n\n}\n"}, {"source_code": "import java.io.PrintWriter\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\nimport kotlin.math.*\n\nval n = 0\nval m = 0\nfun valid(i: Int, j: Int): Boolean {\n return i in 0 until n && j in 0 until m\n}\n\nfun sumRow(arr: IntArray): Int {\n var sum = 0\n for (element in arr) sum += element\n return sum\n}\n\nfun sumCol(twoDArr: Array, colNumber: Int): Int {\n var sum = 0\n for (element in twoDArr) {\n sum += element[colNumber]\n }\n return sum\n}\n\n@JvmField\nval INPUT = System.`in`\n@JvmField\nval OUTPUT = System.out\n\n@JvmField\nval _reader = INPUT.bufferedReader()\n\nfun readLine(): String? = _reader.readLine()!!\nfun readLn() = _reader.readLine()!!\n@JvmField\nvar _tokenizer: StringTokenizer = StringTokenizer(\"\")\n\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\n\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }.toMutableList().toLongArray()\n\n@JvmField\nval _writer = PrintWriter(OUTPUT, false)\n\ninline fun output(block: PrintWriter.() -> Unit) {\n _writer.apply(block).flush()\n}\n\nfun printArr(arr: IntArray, start: Int, end: Int) {\n for (i in start..end) {\n print(\"${arr[i]} \")\n }\n println()\n}\n\nfun printArr(arr: LongArray, start: Int, end: Int) {\n for (i in start..end) {\n print(\"${arr[i]} \")\n }\n println()\n}\n\nfun main() {\n val (a, b, c) = readLongs(3)\n if (a == b) println(\"YES\")\n else if (a < b && c > 0) if (c == 1L) println(\"YES\") else println(if ((b - a) % c == 0L) \"YES\" else \"NO\")\n else if (a > b && c < 0) if (c == -1L) println(\"NO\") else println(if ((b - a) % c == 0L) \"YES\" else \"NO\")\n else println(\"NO\")\n //TODO(\"KYS\")\n}\n\n\n\n"}, {"source_code": "import java.io.PrintWriter\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\nimport kotlin.math.*\n\nval n = 0\nval m = 0\nfun valid(i: Int, j: Int): Boolean {\n return i in 0 until n && j in 0 until m\n}\n\nfun sumRow(arr: IntArray): Int {\n var sum = 0\n for (element in arr) sum += element\n return sum\n}\n\nfun sumCol(twoDArr: Array, colNumber: Int): Int {\n var sum = 0\n for (element in twoDArr) {\n sum += element[colNumber]\n }\n return sum\n}\n\n@JvmField\nval INPUT = System.`in`\n@JvmField\nval OUTPUT = System.out\n\n@JvmField\nval _reader = INPUT.bufferedReader()\n\nfun readLine(): String? = _reader.readLine()!!\nfun readLn() = _reader.readLine()!!\n@JvmField\nvar _tokenizer: StringTokenizer = StringTokenizer(\"\")\n\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\n\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }.toMutableList().toLongArray()\n\n@JvmField\nval _writer = PrintWriter(OUTPUT, false)\n\ninline fun output(block: PrintWriter.() -> Unit) {\n _writer.apply(block).flush()\n}\n\nfun printArr(arr: IntArray, start: Int, end: Int) {\n for (i in start..end) {\n print(\"${arr[i]} \")\n }\n println()\n}\n\nfun printArr(arr: LongArray, start: Int, end: Int) {\n for (i in start..end) {\n print(\"${arr[i]} \")\n }\n println()\n}\n\nfun main() {\n val (a, b, c) = readInts(3)\n if (a == b) println(\"YES\")\n else if (a < c && b > 0) if (b == 1) println(\"YES\") else println(if ((b - a) % c == 0) \"YES\" else \"NO\")\n else if (a > c && b < 0) if (b == -1) println(\"NO\") else println(if ((b - a) % c == 0) \"YES\" else \"NO\")\n else println(\"NO\")\n //TODO(\"KYS\")\n}\n\n\n\n"}, {"source_code": "import java.io.PrintWriter\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\nimport kotlin.math.*\n\nval n = 0\nval m = 0\nfun valid(i: Int, j: Int): Boolean {\n return i in 0 until n && j in 0 until m\n}\n\nfun sumRow(arr: IntArray): Int {\n var sum = 0\n for (element in arr) sum += element\n return sum\n}\n\nfun sumCol(twoDArr: Array, colNumber: Int): Int {\n var sum = 0\n for (element in twoDArr) {\n sum += element[colNumber]\n }\n return sum\n}\n\n@JvmField\nval INPUT = System.`in`\n@JvmField\nval OUTPUT = System.out\n\n@JvmField\nval _reader = INPUT.bufferedReader()\n\nfun readLine(): String? = _reader.readLine()!!\nfun readLn() = _reader.readLine()!!\n@JvmField\nvar _tokenizer: StringTokenizer = StringTokenizer(\"\")\n\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\n\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }.toMutableList().toLongArray()\n\n@JvmField\nval _writer = PrintWriter(OUTPUT, false)\n\ninline fun output(block: PrintWriter.() -> Unit) {\n _writer.apply(block).flush()\n}\n\nfun printArr(arr: IntArray, start: Int, end: Int) {\n for (i in start..end) {\n print(\"${arr[i]} \")\n }\n println()\n}\n\nfun printArr(arr: LongArray, start: Int, end: Int) {\n for (i in start..end) {\n print(\"${arr[i]} \")\n }\n println()\n}\n\nfun main() {\n val (a, b, c) = readLongs(3)\n if (a == b) println(\"YES\")\n else if (a < c && b > 0) if (b == 1L) println(\"YES\") else println(if ((b - a) % c == 0L) \"YES\" else \"NO\")\n else if (a > c && b < 0) if (b == -1L) println(\"NO\") else println(if ((b - a) % c == 0L) \"YES\" else \"NO\")\n else println(\"NO\")\n //TODO(\"KYS\")\n}\n\n\n\n"}, {"source_code": "import java.io.PrintWriter\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\nimport kotlin.math.*\n\nval n = 0\nval m = 0\nfun valid(i: Int, j: Int): Boolean {\n return i in 0 until n && j in 0 until m\n}\n\nfun sumRow(arr: IntArray): Int {\n var sum = 0\n for (element in arr) sum += element\n return sum\n}\n\nfun sumCol(twoDArr: Array, colNumber: Int): Int {\n var sum = 0\n for (element in twoDArr) {\n sum += element[colNumber]\n }\n return sum\n}\n\n@JvmField\nval INPUT = System.`in`\n@JvmField\nval OUTPUT = System.out\n\n@JvmField\nval _reader = INPUT.bufferedReader()\n\nfun readLine(): String? = _reader.readLine()!!\nfun readLn() = _reader.readLine()!!\n@JvmField\nvar _tokenizer: StringTokenizer = StringTokenizer(\"\")\n\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\n\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }.toMutableList().toLongArray()\n\n@JvmField\nval _writer = PrintWriter(OUTPUT, false)\n\ninline fun output(block: PrintWriter.() -> Unit) {\n _writer.apply(block).flush()\n}\n\nfun printArr(arr: IntArray, start: Int, end: Int) {\n for (i in start..end) {\n print(\"${arr[i]} \")\n }\n println()\n}\n\nfun printArr(arr: LongArray, start: Int, end: Int) {\n for (i in start..end) {\n print(\"${arr[i]} \")\n }\n println()\n}\n\nfun main() {\n val (a, b, c) = readInts(3)\n if (a == b) println(\"YES\")\n else if (a < c && b > 0) if (b == 1) println(\"YES\") else println(if ((b - a) % c == 0) \"YES\" else \"NO\")\n else if (a > c && b < 0) if (b == -1) println(\"NO\") else println(if ((b + a) % c == 0) \"YES\" else \"NO\")\n else println(\"NO\")\n //TODO(\"KYS\")\n}\n\n\n\n"}], "src_uid": "9edf42c20ddf22a251b84553d7305a7d"} {"nl": {"description": "The Duck songFor simplicity, we'll assume that there are only three types of grapes: green grapes, purple grapes and black grapes.Andrew, Dmitry and Michal are all grapes' lovers, however their preferences of grapes are different. To make all of them happy, the following should happen: Andrew, Dmitry and Michal should eat at least $$$x$$$, $$$y$$$ and $$$z$$$ grapes, respectively. Andrew has an extreme affinity for green grapes, thus he will eat green grapes and green grapes only. On the other hand, Dmitry is not a fan of black grapes — any types of grapes except black would do for him. In other words, Dmitry can eat green and purple grapes. Michal has a common taste — he enjoys grapes in general and will be pleased with any types of grapes, as long as the quantity is sufficient.Knowing that his friends are so fond of grapes, Aki decided to host a grape party with them. He has prepared a box with $$$a$$$ green grapes, $$$b$$$ purple grapes and $$$c$$$ black grapes.However, Aki isn't sure if the box he prepared contains enough grapes to make everyone happy. Can you please find out whether it's possible to distribute grapes so that everyone is happy or Aki has to buy some more grapes?It is not required to distribute all the grapes, so it's possible that some of them will remain unused.", "input_spec": "The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$1 \\le x, y, z \\le 10^5$$$) — the number of grapes Andrew, Dmitry and Michal want to eat. The second line contains three integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \\le a, b, c \\le 10^5$$$) — the number of green, purple and black grapes in the box.", "output_spec": "If there is a grape distribution that allows everyone to be happy, print \"YES\", otherwise print \"NO\".", "sample_inputs": ["1 6 2\n4 3 3", "5 1 1\n4 3 2"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first example, there is only one possible distribution:Andrew should take $$$1$$$ green grape, Dmitry should take $$$3$$$ remaining green grapes and $$$3$$$ purple grapes, and Michal will take $$$2$$$ out of $$$3$$$ available black grapes.In the second test, there is no possible distribution, since Andrew is not be able to eat enough green grapes. :("}, "positive_code": [{"source_code": "import java.util.*\n\nfun main() {\n with(Scanner(System.`in`)) {\n val req = nextLine().split(\" \").map{ it.toInt() }.toIntArray()\n val grapeCount = nextLine().split(\" \").map{ it.toInt() }.toIntArray()\n\n var remainingGrape = 0\n for (i in 0..2) {\n if (grapeCount[i] + remainingGrape < req[i]) {\n println(\"NO\")\n return\n }\n remainingGrape = grapeCount[i] + remainingGrape - req[i]\n }\n println(\"YES\")\n }\n}"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n val (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n\tif (x>a || (x+y)>(a+b) || (x+y+z)>(a+b+c)) println(\"NO\") else println(\"YES\")\n}"}, {"source_code": "fun main(args : Array) {\n\n val NT = 1//readLine()?.toInt() ?: 0\n\n\n for(test in 1..NT){\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n val (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n val ok = (a >= x) && (a + b >= x + y) && (a + b + c >= x + y + z)\n println(if(ok)\"YES\" else \"NO\")\n }\n\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main() {\n val tokenizer = BufferedReader(InputStreamReader(System.`in`)).use { StringTokenizer(it.readText()) }\n val a = Array(6) { tokenizer.nextInt() }\n if (a[3] >= a[0] && a[3] + a[4] >= a[0] + a[1] && a[3] + a[4] + a[5] >= a[0] + a[1] + a[2])\n println(\"YES\")\n else\n println(\"NO\")\n}\n\nfun StringTokenizer.nextInt() = nextToken().toInt()\nfun StringTokenizer.nextLong() = nextToken().toLong()\n"}, {"source_code": "fun main() {\n var (x, y, z) = readLine()!!.split(' ').map { it.toInt() }\n var (a, b, c) = readLine()!!.split(' ').map { it.toInt() }\n\n if (a < x) {\n print(\"NO\")\n return\n } else {\n a -= x\n x = 0\n }\n\n if (a > 0) {\n if (y > a) {\n y -= a\n a = 0\n } else {\n a -= y\n y = 0\n }\n }\n\n if (y > 0) {\n if (y > b) {\n print(\"NO\")\n return\n } else {\n b -= y\n y = 0\n }\n }\n\n if(a > 0){\n if (z > a) {\n z -= a\n } else {\n print(\"YES\")\n return\n }\n }\n\n if(b > 0){\n if (z > b) {\n z -= b\n } else {\n print(\"YES\")\n return\n }\n }\n\n if(c > 0){\n if (z > c) {\n print(\"NO\")\n return\n } else {\n print(\"YES\")\n return\n }\n }\n\n if(x == 0 && y ==0 && z ==0){\n print(\"YES\")\n }else{\n print(\"NO\")\n }\n}"}, {"source_code": "fun main() {\n var andrew = 0 // -> green\n var dmitry = 0 // -> green or purple\n var michal = 0\n readLine()!!.split(\" \").mapIndexed { index, s ->\n when (index) {\n 0 -> andrew = s.toInt()\n 1 -> dmitry = s.toInt()\n 2 -> michal = s.toInt()\n }\n }\n\n var green = 0\n var purple = 0\n var black = 0\n readLine()!!.split(\" \").mapIndexed { index, s ->\n when (index) {\n 0 -> green = s.toInt()\n 1 -> purple = s.toInt()\n 2 -> black = s.toInt()\n }\n }\n\n green -= andrew\n\n if (green < 0) {\n println(\"NO\")\n } else {\n green -= dmitry\n\n if (green < 0) {\n purple -= -green\n\n if (purple < 0) {\n println(\"NO\")\n } else {\n if (purple + black < michal) {\n println(\"NO\")\n } else {\n println(\"YES\")\n }\n }\n\n } else {\n if (green + purple + black < michal) {\n println(\"NO\")\n } else {\n println(\"YES\")\n }\n }\n }\n\n\n}"}, {"source_code": "import kotlin.system.exitProcess\n\nfun main(args: Array) {\n val (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n if (a > x) {\n print(\"NO\")\n exitProcess(0)\n }\n if (b <= y + x - a && c + b <= x - a + y + z) {\n print(\"YES\")\n } else {\n print(\"NO\")\n }\n\n}\n"}, {"source_code": "private fun readln() = readLine()!!\nprivate fun readlnStrings() = readln().split(' ')\nprivate fun readIntArray() = readlnStrings().run { IntArray(size) { get(it).toInt() } }\n\nfun main(args: Array) {\n\tval a = readIntArray()\n\tval b = readIntArray()\n\tif (a[0] > b[0]) {\n\t\tprintln(\"NO\")\n\t\treturn\n\t}\n\tb[1] += b[0] - a[0]\n\tif (a[1] > b[1]) {\n\t\tprintln(\"NO\")\n\t\treturn\n\t}\n\tb[2] += b[1] - a[1]\n\tif (a[2] > b[2]) println(\"NO\")\n\telse println(\"YES\")\n}"}, {"source_code": "fun main() {\n println(\n if (gotGrapes()) { \"YES\" } else { \"NO\" }\n )\n}\n\nfun gotGrapes() : Boolean {\n var (andrew, dimitry, michal) = readLine()!!.split(\" \").map(String::toInt)\n var (green, purple, black) = readLine()!!.split(\" \").map(String::toInt)\n\n green -= andrew\n\n if (green < 0) return false\n\n val g = kotlin.math.min(dimitry, green)\n dimitry -= g\n green -= g\n purple -= dimitry\n\n if (purple < 0) return false\n\n return (green + purple + black) >= michal\n}\n\n"}, {"source_code": "/**\n * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools\n */\n\nfun main() {\n val (x,y,z) = readInts()\n val (a,b,c) = readInts()\n val a1 = a - x\n val b1 = b + a1 - y\n val c1 = c + b1 - z\n val res = a1 >= 0 && b1 >= 0 && c1 >= 0\n println(if (res) \"YES\" else \"NO\")\n}\n\nprivate fun readInts() = readLine()!!.split(\" \").map { it.toInt() }"}, {"source_code": "fun readln() = readLine()!!.trim()\nfun readlnInt() = readln().toInt()\nfun readlnStrings() = readln().split(' ')\nfun readlnInts() = readlnStrings().map { it.toInt() }\nfun dbg(x: String) = System.err.println(x)\n\nfun solve(l: List, l2: List): String {\n\tvar (x, y, z) = l;\n\tvar (a, b, c) = l2;\n\n\tif (x > a) {\n\t\treturn \"NO\";\n\t}\n\tif (x + y > a + b) {\n\t\treturn \"NO\"\n\t}\n\tif (x + y + z > a + b + c) {\n\t\treturn \"NO\"\t\n\t}\n\n\treturn \"YES\"\n}\n\nfun main(args: Array) {\n\tvar l = readlnInts();\n\tvar l2 = readlnInts();\n\tvar res = solve(l, l2);\n\tprintln(res);\n}"}, {"source_code": "import kotlin.math.min\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main(args: Array) {\n var (x, y, z) = readInts()\n var (a, b, c) = readInts()\n a -= x\n if (a < 0) {\n println(\"NO\")\n return\n }\n var k = min(b, y)\n y -= k\n b -= k\n k = min(a, y)\n y -= k\n a -= k\n if (y > 0) {\n println(\"NO\")\n return\n }\n k = min(z, a)\n a -= k\n z -= k\n k = min(z, b)\n b -= k\n z -= k\n k = min(z, c)\n c -= k\n z -= k\n if (a < 0 || b < 0 || c < 0 || z > 0) {\n println(\"NO\")\n return\n }\n println(\"YES\")\n}"}, {"source_code": "import kotlin.math.min\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main(args: Array) {\n var (x, y, z) = readInts()\n var (a, b, c) = readInts()\n a -= x\n if (a < 0) {\n println(\"NO\")\n return\n }\n var k = min(b, y)\n y -= k\n b -= k\n k = min(a, y)\n y -= k\n a -= k\n if (y > 0) {\n println(\"NO\")\n return\n }\n k = min(z, a)\n a -= k\n z -= k\n k = min(z, b)\n b -= k\n z -= k\n k = min(z, c)\n c -= k\n z -= k\n if (a < 0 || b < 0 || c < 0 || z > 0) {\n println(\"NO\")\n return\n }\n println(\"YES\")\n}"}, {"source_code": "import java.util.Scanner\n fun bad() {\n println(\"NO\")\n System.exit(0)\n }\n\n\n fun main(args: Array) {\n val sc = Scanner(System.`in`)\n val x = sc.nextInt()\n var y = sc.nextInt()\n val z = sc.nextInt()\n var a = sc.nextInt()\n var b = sc.nextInt()\n val c = sc.nextInt()\n a -= x\n if (a < 0)\n bad()\n if (a > y) {\n a -= y\n y = 0\n } else {\n y -= a\n a = 0\n b -= y\n if (b < 0)\n bad()\n }\n if (a + b + c < z)\n bad()\n println(\"YES\")\n }\n"}, {"source_code": "import java.util.Scanner\nimport java.util.Arrays\nfun main(args:Array){\n\tval reader = Scanner(System.`in`)\n\tvar t:Int = reader.nextInt()\n\tvar t1:Int = reader.nextInt()\n\tvar t2:Int = reader.nextInt()\n\tvar g:Int = reader.nextInt()\n\tvar g1:Int = reader.nextInt()\n\tvar g2:Int = reader.nextInt()\n\tif(t<=g){\n\t\tg-=t\n\t\tif(t1<=g+g1){\n\t\t\tif(t2 <= (g-t1)+g1+g2){\n\t\t\t\tprintln(\"YES\")\n\t\t\t\t\n\t\t\t} else {\n\t\t\t\tprintln(\"NO\")\n\t\t\t}\n\t\t\t\n\t\t} else {\n\t\t\tprintln(\"NO\")\n\t\t}\n\t} else {\n\t\tprintln(\"NO\")\n\t}\n}"}, {"source_code": "fun anyGrapes(want:List, grapes:List){\n if(want[0].toInt() - grapes[0].toInt() > 0){\n println(\"NO\")\n }\n else {\n val greenRem = grapes[0].toInt() - want[0].toInt()\n val micha = if((want[2].toInt() - grapes[2].toInt()) < 0){\n 0\n }\n else {\n want[2].toInt() - grapes[2].toInt()\n }\n\n if(greenRem + grapes[1].toInt() >= (micha + want[1].toInt())){\n println(\"YES\")\n return\n }\n println(\"NO\")\n }\n}\n\nfun main(args:Array){\n val want = readLine()!!.split(\" \")\n val grapes = readLine()!!.split(\" \")\n anyGrapes(want, grapes)\n}"}, {"source_code": "//package com.happypeople.codeforces.c1114\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\n\nfun main(args: Array) {\n try {\n A1114().run()\n } catch (e: Throwable) {\n println(\"\")\n e.printStackTrace()\n }\n}\n\nclass A1114 {\n fun run() {\n val sc = Scanner(systemIn())\n val hGreen=sc.nextInt()\n val hNotBlack=sc.nextInt()\n val hAny=sc.nextInt()\n var green=sc.nextInt()\n var purple=sc.nextInt()\n var black=sc.nextInt()\n\n val m1=hGreen<=green\n green-=hGreen\n val m2=hNotBlack<=green+purple\n val m3=hAny<=green+purple+black-hNotBlack\n val ans =m1 and m2 and m3\n if(ans)\n println(\"YES\")\n else\n println(\"NO\")\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}\n"}, {"source_code": "const val GREEN = 0\nconst val PURPLE = 1\nconst val BLACK = 2\nconst val ANDREW = 0\nconst val DIMITRY = 1\nconst val MICHAEL = 2\nfun main() {\n val request = readLine()!!.split(\" \").map { it.toInt() }\n val box = readLine()!!.split(\" \").map { it.toInt() }\n\n if (request[ANDREW] > box[GREEN])\n print(\"NO\")\n else {\n val leftOfGreen = box[GREEN] - request[ANDREW]\n\n val leftOfGreenAndPurple = leftOfGreen + box[PURPLE]\n\n if (leftOfGreenAndPurple < request[DIMITRY]) {\n println(\"NO\")\n } else {\n\n val sumOfAllLeft = leftOfGreenAndPurple - request[DIMITRY] + box[BLACK]\n\n if (sumOfAllLeft < request[MICHAEL]) {\n print(\"NO\")\n } else {\n println(\"YES\")\n }\n\n }\n\n }\n\n}\n\n\n"}, {"source_code": "import kotlin.math.min\n\n/**\n * x=a\n * y=a+b\n * z=a+b+c\n */\nfun main() {\n var (x, y, z) = readLine()!!.split(' ').map(String::toInt)\n var (a, b, c) = readLine()!!.split(' ').map(String::toInt)\n\n if (a < x || a + b < y || a + b + c < z) return print(\"NO\")\n\n\n // ===== Andrew ===== //\n\n min(x, a).also {\n x -= it\n a -= it\n }\n\n if (x != 0) return println(\"NO\")\n\n\n // ===== Dmitry ===== //\n\n min(y, a).also {\n y -= it\n a -= it\n }\n\n min(y, b).also {\n y -= it\n b -= it\n }\n\n if (y != 0) return println(\"NO\")\n\n // ===== Michal ===== //\n\n min(z, a).also {\n z -= it\n a -= it\n }\n\n min(z, b).also {\n z -= it\n b -= it\n }\n\n min(z, c).also {\n z -= it\n c -= it\n }\n\n if (z != 0) return println(\"NO\")\n\n println(\"YES\")\n}\n"}, {"source_code": "fun main(args: Array) {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n var (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n\n if(a>=x && a-x+b >= y && a-x+b-y+c >= z ){\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n }"}, {"source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val x = sc.nextInt()\n val y = sc.nextInt()\n val z = sc.nextInt()\n var a = sc.nextInt()\n var b = sc.nextInt()\n var c = sc.nextInt()\n if (a >= x) {\n a -= x\n b += a\n } else {\n println(\"NO\")\n return\n }\n\n if (b >= y) {\n b -= y\n c += b\n } else {\n println(\"NO\")\n return\n }\n\n if (c >= z) {\n\n } else {\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n}\n"}, {"source_code": "fun main() {\n val targetGrapes = readLine()!!\n val nGrapes = readLine()!!\n println(getGoodString(targetGrapes.split(\" \"), nGrapes.split(\" \")))\n}\n\nfun getGoodString(targetGrapes: List, nGrapes: List): String {\n val targetAndrew = targetGrapes[0].toInt()\n val targetDmitry = targetGrapes[1].toInt()\n val targetMichal = targetGrapes[2].toInt()\n var nGreen = nGrapes[0].toInt()\n val nPurple = nGrapes[1].toInt()\n val nBlack = nGrapes[2].toInt()\n if (nGreen < targetAndrew) return \"NO\"\n nGreen -= targetAndrew\n if (nGreen + nPurple < targetDmitry) return \"NO\"\n val remaining = nGreen + nPurple + nBlack - targetDmitry\n if (remaining < targetMichal) return \"NO\"\n return \"YES\"\n}"}, {"source_code": "fun main() {\n println(\n if (gotGrapes()) { \"YES\" } else { \"NO\" }\n )\n}\n\nfun gotGrapes() : Boolean {\n var (andrew, dimitry, michal) = readLine()!!.split(\" \").map(String::toInt)\n var (green, purple, black) = readLine()!!.split(\" \").map(String::toInt)\n\n green -= andrew\n\n if (green < 0) return false\n\n val g = kotlin.math.min(dimitry, green)\n dimitry -= g\n green -= g\n purple -= dimitry\n\n if (purple < 0) return false\n\n return (green + purple + black) >= michal\n}\n\n"}, {"source_code": "import java.lang.Math.abs\n\nfun main() {\n val (a, d, m) = readLine()!!.split(' ').map(String::toInt)\n val (g, v, b) = readLine()!!.split(' ').map(String::toInt)\n print(check(a, d, m, g, v, b))\n}\n\n/*1 2 10\n10 2 1*/\n\nfun check(a: Int, d: Int, m: Int, g: Int, v: Int, b: Int): String {\n\n val v1 = v\n val b1 = b\n val a1 = a - g\n var d1 = d\n var m1 = m\n\n return if (a1 <= 0) {\n\n d1 -= abs(a1)\n if (d1 <= 0) {\n\n m1 -= abs(d1) + v1\n return if (m1 <= 0) \"YES\"\n else {\n m1 -= b1\n if (m1 <= 0) \"YES\" else \"NO\"\n }\n } else {\n d1 -= v1\n return if (d1 <= 0) {\n\n m1 -= abs(d1)\n if (m1 <= 0) \"YES\"\n else {\n m1 -= b1\n if (m1 <= 0) \"YES\" else \"NO\"\n }\n } else \"NO\"\n }\n } else \"NO\"\n}"}, {"source_code": "fun main(args: Array) {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n var (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n\n if(a>=x && a-x+b >= y && a-x+b-y+c >= z ){\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n }"}, {"source_code": "import kotlin.math.*\n\nfun read() = readLine()!!\nfun getInt() = read().toInt()\nfun getInts() = read().split(\" \").map(String::toInt)\n\nfun main() {\n var (x, y, z) = getInts()\n var (a, b, c) = getInts()\n var tmp = min(a, x)\n x -= tmp\n a -= tmp\n tmp = min(y, a)\n y -= tmp\n a -= tmp\n tmp = min(y, b)\n y -= tmp\n b -= tmp\n tmp = min(z, a)\n z -= tmp\n a -= tmp\n tmp = min(z, b)\n z -= tmp\n b -= tmp\n tmp = min(z, c)\n z -= tmp\n c -= tmp\n if (x > 0 || y > 0 || z > 0) {\n println(\"NO\")\n } else {\n println(\"YES\")\n }\n}"}, {"source_code": "fun main() {\n var (x, y, z) = readLine()!!.split(\" \").map{it.toInt()}\n var (a, b, c) = readLine()!!.split(\" \").map{it.toInt()}\n if (a < x) {\n println(\"NO\")\n return\n }\n val d = Math.min(y, a - x);\n a -= d + x\n y -= d\n if(b < y) {\n println(\"NO\")\n return\n }\n if(a + b + c >= z + y) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}"}, {"source_code": "fun main() {\n val needed = readLine()!!.split(' ').map { it.toInt() }\n val available = readLine()!!.split(' ').map { it.toInt() }\n var leftOver = 0\n for (i in 0..2) {\n if (leftOver + available[i] < needed[i]) {\n println(\"NO\")\n return\n } else {\n leftOver = leftOver + available[i] - needed[i]\n }\n }\n println(\"YES\")\n}\n"}, {"source_code": "import java.util.*\n\nfun main() {\n\n val sc = Scanner(System.`in`)\n val xyz = IntArray(3)\n val abc = IntArray(3)\n\n for (i in 0..2) xyz[i] = sc.nextInt()\n for (i in 0..2) abc[i] = sc.nextInt()\n\n if (abc[0] < xyz[0]) {\n print(\"NO\")\n return\n } else abc[1] += (abc[0] - xyz[0])\n\n if (abc[1] < xyz[1]) {\n print(\"NO\")\n return\n } else abc[2] += (abc[1] - xyz[1])\n\n if (abc[2] < xyz[2]) {\n print(\"NO\")\n return\n }\n\n print(\"YES\")\n\n}"}, {"source_code": "fun main() {\n val (wantA, wantB, wantC) = readLine()!!.split(\" \").map(String::toInt)\n val (green, purple, black) = readLine()!!.split(\" \").map(String::toInt)\n\n val forA = minOf(wantA, green)\n val forB = minOf(wantB, green + purple - forA)\n val forC = minOf(wantC, green + black + purple - forA - forB)\n\n if (wantA == forA && wantB == forB && wantC == forC)\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "fun main() {\n val require = readLine()!!.split(\" \").map { it.toInt() }.toMutableList()\n val exist = readLine()!!.split(\" \").map { it.toInt() }.toMutableList()\n\n when {\n require[0] > exist[0] -> \"NO\"\n require[1] > exist[0] - require[0] + exist[1] -> \"NO\"\n require[2] > exist[0] - require[0] + exist[1] - require[1] + exist[2] -> \"NO\"\n else -> \"YES\"\n }.run { println(this) }\n}\n"}, {"source_code": "fun main() {\n var (x, y, z) = readLine()!!.split(\" \").map{it.toInt()}\n var (a, b, c) = readLine()!!.split(\" \").map{it.toInt()}\n if (a < x) {\n println(\"NO\")\n return\n }\n val d = Math.min(y, a - x);\n a -= d + x\n y -= d\n if(b < y) {\n println(\"NO\")\n return\n }\n if(a + b + c >= z + y) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}"}, {"source_code": "/**\n * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools\n */\n\nfun main() {\n val (x,y,z) = readInts()\n val (a,b,c) = readInts()\n val a1 = a - x\n val b1 = b + a1 - y\n val c1 = c + b1 - z\n val res = a1 >= 0 && b1 >= 0 && c1 >= 0\n println(if (res) \"YES\" else \"NO\")\n}\n\nprivate fun readInts() = readLine()!!.split(\" \").map { it.toInt() }"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(\" \").map {it.toInt()}\n val (a, b, c) = readLine()!!.split(\" \").map {it.toInt()}\n if (x > a) {\n print(\"NO\")\n return\n }\n val r = a - x\n if (y > r + b) {\n print(\"NO\")\n return\n }\n if (z > c + r + b - y) {\n print(\"NO\")\n return\n }\n print(\"YES\")\n}"}, {"source_code": "fun main() {\n val targetGrapes = readLine()!!\n val nGrapes = readLine()!!\n println(getGoodString(targetGrapes.split(\" \"), nGrapes.split(\" \")))\n}\n\nfun getGoodString(targetGrapes: List, nGrapes: List): String {\n val targetAndrew = targetGrapes[0].toInt()\n val targetDmitry = targetGrapes[1].toInt()\n val targetMichal = targetGrapes[2].toInt()\n var nGreen = nGrapes[0].toInt()\n val nPurple = nGrapes[1].toInt()\n val nBlack = nGrapes[2].toInt()\n if (nGreen < targetAndrew) return \"NO\"\n nGreen -= targetAndrew\n if (nGreen + nPurple < targetDmitry) return \"NO\"\n val remaining = nGreen + nPurple + nBlack - targetDmitry\n if (remaining < targetMichal) return \"NO\"\n return \"YES\"\n}"}, {"source_code": "import kotlin.system.exitProcess\n\nfun main()\n{\n var (x,y,z)= readLine()!!.split(' ').map(String::toInt)\n var (a,b,c)= readLine()!!.split(' ').map(String::toInt)\n\n a-=x\n if(a<0 || a+b=y) a-=y\n else\n {\n y-=a\n a=0\n b-=y\n }\n if(z>a+b+c)\n {\n print(\"NO\")\n exitProcess(0)\n }\n print(\"YES\")\n}"}, {"source_code": "import java.lang.Math.min\n\nfun main(args : Array) {\n val want = IntArray(3)\n val have = IntArray(3)\n for (i in 0 until want.size) {\n want[i] = readInt()\n }\n for (i in 0 until have.size) {\n have[i] = readInt()\n }\n for (i in 0 until want.size) {\n var sum = 0\n for (j in 0 .. i) {\n sum += have[j]\n }\n if (sum < want[i]) {\n println(\"NO\")\n return\n }\n var rest = want[i]\n for (j in 0 .. i) {\n if (rest <= have[j]) {\n have[j] -= rest\n break\n } else {\n rest -= have[j]\n have[j] = 0\n }\n }\n }\n println(\"YES\")\n}\n\nprivate fun readln() = readLine()!!\nprivate fun readlnByte() = readln().toByte()\nprivate fun readlnShort() = readln().toShort()\nprivate fun readlnInt() = readln().toInt()\nprivate fun readlnLong() = readln().toLong()\nprivate fun readlnFloat() = readln().toFloat()\nprivate fun readlnDouble() = readln().toDouble()\nprivate fun readlnBigInt(radix: Int = 10) = readln().toBigInteger(radix)\nprivate fun readlnBigDecimal() = readln().toBigDecimal()\n\nprivate fun lineSequence(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.constrainOnce().take(limit)\nprivate fun readlnStrings() = readln().split(' ')\nprivate fun readlnBytes() = readlnStrings().map { it.toByte() }\nprivate fun readlnShorts() = readlnStrings().map { it.toShort() }\nprivate fun readlnInts() = readlnStrings().map { it.toInt() }\nprivate fun readlnLongs() = readlnStrings().map { it.toLong() }\nprivate fun readlnFloats() = readlnStrings().map { it.toFloat() }\nprivate fun readlnDoubles() = readlnStrings().map { it.toDouble() }\n\nprivate fun readByteArray() = readlnStrings().run { ByteArray(size) { get(it).toByte() } }\nprivate fun readShortArray() = readlnStrings().run { ShortArray(size) { get(it).toShort() } }\nprivate fun readIntArray() = readlnStrings().run { IntArray(size) { get(it).toInt() } }\nprivate fun readLongArray() = readlnStrings().run { LongArray(size) { get(it).toLong() } }\nprivate fun readFloatArray() = readlnStrings().run { FloatArray(size) { get(it).toFloat() } }\nprivate fun readDoubleArray() = readlnStrings().run { DoubleArray(size) { get(it).toDouble() } }\n\nprivate fun readlnByteArray(n: Int) = ByteArray(n) { readlnByte() }\nprivate fun readlnShortArray(n: Int) = ShortArray(n) { readlnShort() }\nprivate fun readlnIntArray(n: Int) = IntArray(n) { readlnInt() }\nprivate fun readlnLongArray(n: Int) = LongArray(n) { readlnLong() }\nprivate fun readlnFloatArray(n: Int) = FloatArray(n) { readlnFloat() }\nprivate fun readlnDoubleArray(n: Int) = DoubleArray(n) { readlnDouble() }\n\nprivate fun readByteArray2d(rows: Int, cols: Int) = Array(rows) { readByteArray().also { require(it.size == cols) } }\nprivate fun readShortArray2d(rows: Int, cols: Int) = Array(rows) { readShortArray().also { require(it.size == cols) } }\nprivate fun readLongArray2d(rows: Int, cols: Int) = Array(rows) { readLongArray().also { require(it.size == cols) } }\nprivate fun readIntArray2d(rows: Int, cols: Int) = Array(rows) { readIntArray().also { require(it.size == cols) } }\nprivate fun readFloatArray2d(rows: Int, cols: Int) = Array(rows) { readFloatArray().also { require(it.size == cols) } }\nprivate fun readDoubleArray2d(rows: Int, cols: Int) = Array(rows) { readDoubleArray().also { require(it.size == cols) } }\n\nprivate fun isWhiteSpace(c: Char) = c in \" \\r\\n\\t\"\n\n// JVM-only targeting code follows next\n\n// readString() via sequence is still slightly faster than Scanner\nprivate fun readString() = generateSequence { System.`in`.read().toChar() }\n .dropWhile { isWhiteSpace(it) }.takeWhile { !isWhiteSpace(it) }.joinToString(\"\")\nprivate fun readByte() = readString().toByte()\nprivate fun readShort() = readString().toShort()\nprivate fun readInt() = readString().toInt()\nprivate fun readLong() = readString().toLong()\nprivate fun readFloat() = readString().toFloat()\nprivate fun readDouble() = readString().toDouble()\nprivate fun readBigInt(radix: Int = 10) = readString().toBigInteger(radix)\nprivate fun readBigDecimal() = readString().toBigDecimal()\n\nprivate fun readBytes(n: Int) = generateSequence { readByte() }.take(n)\nprivate fun readShorts(n: Int) = generateSequence { readShort() }.take(n)\nprivate fun readInts(n: Int) = generateSequence { readInt() }.take(n)\nprivate fun readLongs(n: Int) = generateSequence { readLong() }.take(n)\nprivate fun readFloats(n: Int) = generateSequence { readFloat() }.take(n)\nprivate fun readDoubles(n: Int) = generateSequence { readDouble() }.take(n)"}, {"source_code": "import java.util.Scanner;\n\nfun main() {\n with(Scanner(System.`in`)) {\n var x = nextInt()\n var y = nextInt()\n var z = nextInt()\n var a = nextInt() // green\n var b = nextInt() // purple\n var c = nextInt() // black\n a = a - x\n if (a < 0) {\n println(\"NO\")!!\n return\n }\n if (b >= y) {\n b = b - y\n y = 0\n } else {\n y = y - b\n b = 0\n }\n if (a >= y) {\n a = a - y\n y = 0\n } else {\n y = y - a\n a = 0\n }\n if (y > 0) {\n println(\"NO\")!!\n return\n }\n if (a + b + c >= z) {\n println(\"YES\")!!\n } else {\n println(\"NO\")!!\n }\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n\n val reader = Scanner(System.`in`)\n val input1 = reader.nextLine()\n val input2 = reader.nextLine()\n\n val neededGrapes = input1.split(\" \")\n val andrewWants = neededGrapes[0].toInt()\n val dmitryWants = neededGrapes[1].toInt()\n val michalWants = neededGrapes[2].toInt()\n\n val totalAvailableGrapes = input2.split(\" \")\n\n var totalGreenGrapes = totalAvailableGrapes[0].toInt()\n var totalPurpleGrapes = totalAvailableGrapes[1].toInt()\n var totalBlackGrapes = totalAvailableGrapes[2].toInt()\n\n\n if (andrewWants > totalGreenGrapes) {\n println(\"NO\")\n return\n } else {\n totalGreenGrapes -= andrewWants;\n }\n\n if (dmitryWants > (totalGreenGrapes + totalPurpleGrapes)) {\n println(\"NO\")\n return\n } else {\n totalGreenGrapes -= dmitryWants\n if (totalGreenGrapes < 0) {\n totalPurpleGrapes += totalGreenGrapes\n totalGreenGrapes = 0\n }\n }\n\n if (michalWants > (totalGreenGrapes + totalPurpleGrapes + totalBlackGrapes)) {\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n\n}"}, {"source_code": "fun main() {\n val a=readInts().toIntArray()\n val b=readInts().toIntArray()\n if (a[0]>b[0]){\n println(\"NO\")\n return\n }\n b[1]+=b[0]-a[0]\n if (a[1]>b[1]) {\n println(\"NO\")\n return\n }\n b[2]+=b[1]-a[1]\n if (a[2]>b[2]) {\n println(\"NO\")\n return\n }\n println(\"YES\")\n}\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints"}, {"source_code": "\nimport java.util.Scanner\n\nfun main(args: Array) {\n exercise4()\n}\n\nfun exercise4(){\n val reader = Scanner(System.`in`)\n val andrew = reader.nextInt()\n var dimitri = reader.nextInt()\n val michael = reader.nextInt()\n\n var green = reader.nextInt()\n var purple = reader.nextInt()\n var black = reader.nextInt()\n\n green -= andrew\n if (green < 0){\n println(\"NO\")\n } else {\n if (green >= dimitri){\n green -= dimitri\n if (green < 0){\n println(\"NO\")\n } else {\n if (green + purple + black >= michael) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n }\n } else {\n dimitri -= green\n purple -= dimitri\n green = 0\n if (purple < 0){\n println(\"NO\")\n } else {\n if (green + purple + black >= michael) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n }\n }\n \n\n }\n\n}"}, {"source_code": "fun main(args : Array) {\n val (x1, y1, z1) = readLine()!!.split(' ')\n val (g1, p1, b1) = readLine()!!.split(' ')\n var x = x1.toInt()\n var y = y1.toInt()\n var z = z1.toInt()\n var g = g1.toInt()\n var p = p1.toInt()\n var b = b1.toInt()\n var d = 0\n var m = 0\n\n if(g>=x){\n d = g + p - x\n if(d>=y){\n m = g+p+b-x-y\n if(m>=z){\n println(\"YES\")\n }\n else{\n println(\"NO\")\n }\n }\n else{\n println(\"NO\")\n }\n\n }\n else{\n println(\"NO\")\n }\n\n}"}, {"source_code": "import java.util.Scanner\nimport java.util.Arrays\nfun main(args:Array){\n\tval reader = Scanner(System.`in`)\n\tvar t:Int = reader.nextInt()\n\tvar t1:Int = reader.nextInt()\n\tvar t2:Int = reader.nextInt()\n\tvar g:Int = reader.nextInt()\n\tvar g1:Int = reader.nextInt()\n\tvar g2:Int = reader.nextInt()\n\tif(t<=g && t1<=(g-t)+g1 &&t2 <= (g-t1-t)+g1+g2){\n\t\tprintln(\"YES\")\n\t} else {\n\t\tprintln(\"NO\")\n\t}\n}"}, {"source_code": "import java.io.*\nimport java.lang.Math.max\nimport java.lang.Math.min\nimport java.lang.StringBuilder\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n// val n = br.readLine()!!.toInt()\n\n// repeat(n)\n// {\n val (x,y,z) = br.readLine()!!.split(' ').map{it.toInt()}\n val (a,b,c) = br.readLine()!!.split(' ').map{it.toInt()}\n\n// val s = br.readLine()\n// solve1(a)\n// solve2(a,b,c)\n// solve3(s)\n solve4(x,y,z,a,b,c)\n// }\n\n}\n\nfun solve4(x: Int, y: Int, z: Int, a: Int, b: Int, c: Int) {\n // x -> only a\n // y -> not c\n // z -> anything\n\n val ret = if( a >= x && a - x + b >= y && a - x + b - y + c >= z) \"YES\" else \"NO\"\n println(ret)\n}\n\n\nfun solve3(s: String) {\n\n var ns = s.toCharArray().sorted()\n var sb = StringBuilder()\n for(ch in ns)\n {\n sb.append(ch)\n }\n var nss = sb.toString()\n\n if(nss.reversed() == nss)\n {\n println(-1)\n }\n else\n {\n println(nss)\n }\n}\n\nfun solve2(a: Int, b: Int, c: Int) {\n\n var m = min(a, b-1)\n m = min(m, c-2)\n println(3 * m + 3)\n}\n\nfun solve1(num : Int)\n{\n println(num/2)\n}\n\n\n"}, {"source_code": "fun anyGrapes(want:List, grapes:List){\n if(want[0].toInt() - grapes[0].toInt() > 0){\n println(\"NO\")\n }\n else {\n val greenRem = grapes[0].toInt() - want[0].toInt()\n val micha = if((want[2].toInt() - grapes[2].toInt()) < 0){\n 0\n }\n else {\n want[2].toInt() - grapes[2].toInt()\n }\n\n if(greenRem + grapes[1].toInt() >= (micha + want[1].toInt())){\n println(\"YES\")\n return\n }\n println(\"NO\")\n }\n}\n\nfun main(args:Array){\n val want = readLine()!!.split(\" \")\n val grapes = readLine()!!.split(\" \")\n anyGrapes(want, grapes)\n}"}, {"source_code": "import kotlin.system.exitProcess\n\nfun readInts() = readLine()!!.split(\" \").map { it.toInt() }\n\n\nfun main()\n{\n var (x, y, z) = readInts()\n var (a, b, c) = readInts()\n\n if (x > a){\n println(\"NO\")\n exitProcess(0)\n }\n\n a-=x\n a+=b\n\n if (a < y){\n println(\"NO\")\n exitProcess(0)\n }\n\n a-=y\n a+=c\n\n if (a < z){\n println(\"NO\")\n exitProcess(0)\n }\n\n println(\"YES\")\n}"}, {"source_code": "fun main(args: Array) {\n var (x,y,z)=readLine()!!.split(\" \").map{it.toInt()}\n var (a,b,c)=readLine()!!.split(\" \").map{it.toInt()}\n if(a, nGrapes: List): String {\n val targetAndrew = targetGrapes[0].toInt()\n val targetDmitry = targetGrapes[1].toInt()\n val targetMichal = targetGrapes[2].toInt()\n var nGreen = nGrapes[0].toInt()\n val nPurple = nGrapes[1].toInt()\n val nBlack = nGrapes[2].toInt()\n if (nGreen < targetAndrew) return \"NO\"\n nGreen -= targetAndrew\n if (nGreen + nPurple < targetDmitry) return \"NO\"\n val remaining = nGreen + nPurple + nBlack - targetDmitry\n if (remaining < targetMichal) return \"NO\"\n return \"YES\"\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array ) {\n val sc = Scanner(System.`in`)\n val want = IntArray( 3, { sc.nextInt() } )\n val have = IntArray( 3, { sc.nextInt() } )\n\n for ( i in want.indices.reversed() ) {\n want[i] -= have[i]\n if ( want[i] <= 0 ) continue\n for ( j in i - 1 downTo 0 ) {\n val take = Math.min(want[i], have[j])\n want[i] -= take\n have[j] -= take\n }\n if ( want[i] > 0 ) {\n println( \"NO\" )\n return\n }\n }\n println( \"YES\" )\n}"}, {"source_code": "fun main(){\n val (a,b,c)=readLine()!!.split(\" \").map{it.toInt()}\n val (x,y,z)=readLine()!!.split(\" \").map{it.toInt()}\n if(x green) {\n println(no)\n return\n }\n green -= and\n if (dm > green + purple) {\n println(no)\n return\n }\n\n if (dm > green) {\n dm -= green\n green = 0\n purple -= dm\n } else {\n green -= dm\n }\n\n println(if (green + purple + black >= mi) yes else no)\n}"}, {"source_code": "import kotlin.system.exitProcess\n\nfun main()\n{\n var (x, y, z) = readLine()!!.split(' ').map(String::toInt)\n \n var (a, b, c) = readLine()!!.split(' ').map(String::toInt)\n \n if (a < x)\n {\n println(\"NO\")\n exitProcess(0)\n }\n a -= x\n \n if (a + b < y)\n {\n println(\"NO\")\n exitProcess(0)\n }\n \n var remaining_grapes = a + b - y + c\n \n if (remaining_grapes < z)\n {\n println(\"NO\")\n exitProcess(0)\n }\n \n println(\"YES\")\n}\n \n"}, {"source_code": "fun main() {\n val a=readInts().toIntArray()\n val b=readInts().toIntArray()\n if (a[0]>b[0]){\n println(\"NO\")\n return\n }\n b[1]+=b[0]-a[0]\n if (a[1]>b[1]) {\n println(\"NO\")\n return\n }\n b[2]+=b[1]-a[1]\n if (a[2]>b[2]) {\n println(\"NO\")\n return\n }\n println(\"YES\")\n}\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints"}, {"source_code": "import java.util.Scanner\nimport java.util.Arrays\nfun main(args:Array){\n\tval reader = Scanner(System.`in`)\n\tvar t:Int = reader.nextInt()\n\tvar t1:Int = reader.nextInt()\n\tvar t2:Int = reader.nextInt()\n\tvar g:Int = reader.nextInt()\n\tvar g1:Int = reader.nextInt()\n\tvar g2:Int = reader.nextInt()\n\tif(t<=g){\n\t\tg-=t\n\t\tif(t1<=g+g1){\n\t\t\tg-=t1;\n\t\t\tif(g<0){\n\t\t\t\tg1+=g\n\t\t\t\tg = 0\n\t\t\t}\n\t\t\tif(t2 <= g+g1+g2){\n\t\t\t\tprintln(\"YES\")\n\t\t\t\t\n\t\t\t} else {\n\t\t\t\tprintln(\"NO\")\n\t\t\t}\n\t\t\t\n\t\t} else {\n\t\t\tprintln(\"NO\")\n\t\t}\n\t} else {\n\t\tprintln(\"NO\")\n\t}\n}"}, {"source_code": "import java.lang.System.exit\n\nfun main() {\n val (andrew, dmitry, michal) = readLine()!!.split(' ').map { it.toInt() }\n var (green, purple, black) = readLine()!!.split(' ').map { it.toInt() }\n green-=andrew\n if (green < 0) fail()\n val leftover = green + purple - dmitry\n if (leftover < 0) fail()\n if (leftover + black - michal < 0) fail()\n println(\"YES\")\n}\n\nfun fail() {\n println(\"NO\")\n exit(0)\n}"}, {"source_code": "fun main(args: Array) {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n var (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n if (a < x) {\n println(\"NO\")\n return\n }\n a -= x\n if (a + b < y) {\n println(\"NO\")\n return\n }\n c += a + b - y\n if (c < z) {\n println(\"NO\")\n return\n }\n println(\"YES\")\n}"}, {"source_code": "fun main() {\n println(\n if (gotGrapes()) { \"YES\" } else { \"NO\" }\n )\n}\n\nfun gotGrapes() : Boolean {\n var (andrew, dimitry, michal) = readLine()!!.split(\" \").map(String::toInt)\n var (green, purple, black) = readLine()!!.split(\" \").map(String::toInt)\n\n green -= andrew\n\n if (green < 0) return false\n\n val g = kotlin.math.min(dimitry, green)\n dimitry -= g\n green -= g\n purple -= dimitry\n\n if (purple < 0) return false\n\n return (green + purple + black) >= michal\n}\n\n"}, {"source_code": "fun isEnough(wish: List, grapes: List) {\n val enough = grapes[0] >= wish[0] &&\n grapes[0] + grapes[1] >= wish[1] + wish[0] &&\n grapes[0] + grapes[1] + grapes[2] >= wish[2] + wish[0] + wish[1]\n println(when(enough) {\n true -> \"YES\"\n else -> \"NO\"\n })\n}\n\nfun main() {\n val wish = readLine()!!.split(\" \").map { it.toInt() }\n val grapes = readLine()!!.split(\" \").map { it.toInt() }\n\n isEnough(wish, grapes)\n}"}, {"source_code": "fun main() {\n val(x,y,z) = readLine()!!.split(\" \").map{it.toInt()};\n val(a,b,c) = readLine()!!.split(\" \").map{it.toInt()};\n if((a>=x)&&(a+b>=x+y)&&(a+b+c>=x+y+z))\n println(\"YES\");\n else\n println(\"NO\");\n}"}, {"source_code": "\nfun good (a: CharArray) : Int {\n\n for (i in 0..a.size-1) {\n if (a[i] != a[a.size - i - 1])\n return 1\n }\n return 0\n}\n\nfun taskC() {\n var t = readLine()!!.toInt()\n while (t-- > 0) {\n var a = readLine()!!.toString()\n var arr = a.toCharArray()\n arr.sort()\n if (good(arr) == 1)\n println(arr.joinToString(\"\"))\n else\n println(-1)\n }\n}\nfun taskD() {\n var a = readLine()!!.split(\" \").map {it.toInt()}\n var b = readLine()!!.split(\" \").map {it.toInt()}\n var sum = 0\n for (i in 0..2) {\n sum += b[i]\n if (sum >= a[i]) {\n sum -= a[i]\n }\n else {\n print(\"NO\")\n return\n }\n }\n print(\"YES\")\n}\n\nfun main()\n{\n taskD()\n}\nfun taskB() {\n var (a, b, c) = readLine()!!.split(\" \").map{it.toInt()}\n var mn = Math.min (a, Math.min (b-1, c-2))\n print(mn + mn + 1 + mn + 2)\n}"}, {"source_code": "fun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readStrings() = readLn().split(\" \")\nfun readInts() = readStrings().map(String::toInt)\n\nfun main() {\n val (x, y, z) = readInts()\n val (a, b, c) = readInts()\n\n if (a < x || a + b < x + y || a + b + c < x + y + z)\n println(\"NO\")\n else\n println(\"YES\")\n}\n\n"}, {"source_code": "private val inputRegex = \"\"\"(\\d+)\\s(\\d+)\\s(\\d+)\"\"\".toRegex()\n\nfun main() {\n val (x, y, z) = inputRegex.find(readLine()!!)!!.destructured.toList().map { it.toInt() }\n val (a, b, c) = inputRegex.find(readLine()!!)!!.destructured.toList().map { it.toInt() }\n\n val result = if (satisfiedCondition(x, y, z, a, b, c)) \"YES\" else \"NO\"\n println(result)\n\n\n}\n\nfun satisfiedCondition(x: Int, y: Int, z: Int, a: Int, b: Int, c: Int): Boolean {\n if (a < x) return false\n val ab = a+b\n val xy = x+y\n if (ab < xy) return false\n if (ab + c < xy + z) return false\n\n return true\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (x, y, z) = readInts()\n val (green, purple, black) = readInts()\n print(if (green >= x && green + purple - x >= y && green + purple + black >= x + y + z) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main() {\n var (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n var (green, purple, black) = readLine()!!.split(\" \").map { it.toInt() }\n\n var condition = true\n\n if (!(green >= x && green - x + purple >= y && green - x + purple - y + black >= z)) {\n condition = false\n }\n\n println(if (condition) \"YES\" else \"NO\")\n}"}, {"source_code": "// contest/1171/problem/B Kotlin heroes training done\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n var canDo: Boolean\n val xyz = readInts()\n var (x,y,z) = xyz\n val abc = readInts()\n var (a,b,c) = abc\n if (a < x) {\n canDo = false\n } else {\n a -= x\n if (a+b < y) {\n canDo = false\n } else {\n if (a > y) {\n a -= y\n } else {\n b -= (y-a)\n a = 0\n }\n canDo = (a+b+c) >= z\n }\n }\n\n println( if (canDo) \"YES\" else \"NO\" )\n}\n"}, {"source_code": "import java.util.Scanner\nimport java.util.Arrays\n\nfun main(args: Array) {\n\tval reader = Scanner(System.`in`)\n\n\tvar x:Int = reader.nextInt()\n \tvar y:Int = reader.nextInt()\n \tvar z:Int = reader.nextInt()\n \n \tvar g:Int = reader.nextInt()\n \tvar p:Int = reader.nextInt()\n \tvar b:Int = reader.nextInt()\n\t\n\tvar aux:Int \n\n \tif(g>=x){\n\t\tg-=x\n\t\taux=g+p\n\t\tif(aux>=y){\n\t\t\taux-=y\n\t\t\taux+=b\n\t\t\tif(aux>=z){\n\t\t\t\tprintln(\"YES\")\n\t\t\t}\n\t\t\telse{\n\t\t\t\tprintln(\"NO\")\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tprintln(\"NO\")\n\t\t}\n \t}\n\telse{\n\t\tprintln(\"NO\")\n\t}\n}\n"}, {"source_code": "fun main() {\n val a=readInts().toIntArray()\n val b=readInts().toIntArray()\n if (a[0]>b[0]){\n println(\"NO\")\n return\n }\n b[1]+=b[0]-a[0]\n if (a[1]>b[1]) {\n println(\"NO\")\n return\n }\n b[2]+=b[1]-a[1]\n if (a[2]>b[2]) {\n println(\"NO\")\n return\n }\n println(\"YES\")\n}\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints"}, {"source_code": "fun main() {\n val(x,y,z) = readLine()!!.split(\" \").map{it.toInt()};\n val(a,b,c) = readLine()!!.split(\" \").map{it.toInt()};\n if((a>=x)&&(a+b>=x+y)&&(a+b+c>=x+y+z))\n println(\"YES\");\n else\n println(\"NO\");\n}"}, {"source_code": "fun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readStrings() = readLn().split(\" \")\nfun readInts() = readStrings().map(String::toInt)\n\nfun main() {\n val (x, y, z) = readInts()\n val (a, b, c) = readInts()\n\n if (a < x || a + b < x + y || a + b + c < x + y + z)\n println(\"NO\")\n else\n println(\"YES\")\n}\n\n"}, {"source_code": "private fun readln() = readLine()!!\nprivate fun readlnStrings() = readln().split(' ')\nprivate fun readIntArray() = readlnStrings().run { IntArray(size) { get(it).toInt() } }\n\nfun main(args: Array) {\n\tval a = readIntArray()\n\tval b = readIntArray()\n\tfor (i in 0..2) {\n\t\tif (a[i] > b[i]) {\n\t\t\tprintln(\"NO\")\n\t\t\treturn\n\t\t}\n\t\tif (i < 2) b[i+1] += b[i] - a[i]\n\t}\n\tprintln(\"YES\")\n}"}, {"source_code": "fun main() {\n var str = readLine().toString()\n var arr = str.split(\" \").toTypedArray()\n var a = arr[0].toInt()\n var d = arr[1].toInt()\n var m = arr[2].toInt()\n str = readLine().toString()\n arr = str.split(\" \").toTypedArray()\n var g = arr[0].toInt()\n var p = arr[1].toInt()\n var b = arr[2].toInt()\n if (((g-a) >= 0) && ((p+g-a-d) >= 0) && ((g+p+b) >= (a+d+m))) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}"}, {"source_code": "private fun readln() = readLine()!!\nprivate fun readlnStrings() = readln().split(' ')\nprivate fun readIntArray() = readlnStrings().run { IntArray(size) { get(it).toInt() } }\n\nfun main(args: Array) {\n\tval a = readIntArray()\n\tval b = readIntArray()\n\tif (a[0] > b[0]) {\n\t\tprintln(\"NO\")\n\t\treturn\n\t}\n\tb[1] += b[0] - a[0]\n\tif (a[1] > b[1]) {\n\t\tprintln(\"NO\")\n\t\treturn\n\t}\n\tb[2] += b[1] - a[1]\n\tif (a[2] > b[2]) println(\"NO\")\n\telse println(\"YES\")\n}"}, {"source_code": "import java.util.Scanner\nimport java.util.Arrays\nfun main(args:Array){\n\tval reader = Scanner(System.`in`)\n\tvar t:Int = reader.nextInt()\n\tvar t1:Int = reader.nextInt()\n\tvar t2:Int = reader.nextInt()\n\tvar g:Int = reader.nextInt()\n\tvar g1:Int = reader.nextInt()\n\tvar g2:Int = reader.nextInt()\n\tif(t<=g){\n\t\tg-=t\n\t\tif(t1<=g+g1){\n\t\t\tg-=t1;\n\t\t\tif(g<0){\n\t\t\t\tg1+=g\n\t\t\t\tg = 0\n\t\t\t}\n\t\t\tif(t2 <= g+g1+g2){\n\t\t\t\tprintln(\"YES\")\n\t\t\t\t\n\t\t\t} else {\n\t\t\t\tprintln(\"NO\")\n\t\t\t}\n\t\t\t\n\t\t} else {\n\t\t\tprintln(\"NO\")\n\t\t}\n\t} else {\n\t\tprintln(\"NO\")\n\t}\n}"}, {"source_code": "import java.util.*\n\n\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n\n var andrew = sc.nextInt()\n var dimitry = sc.nextInt()\n var michal = sc.nextInt()\n\n var green = sc.nextInt()\n var purple = sc.nextInt()\n var black = sc.nextInt()\n\n\n //Andrew\n if(green >= andrew){\n green -= andrew\n andrew = 0\n }\n\n\n //Dimitry\n if(green >= dimitry){\n green -= dimitry\n dimitry = 0\n } else if(dimitry > 0){\n dimitry -= green\n green = 0\n }\n\n if(purple >= dimitry){\n purple -= dimitry\n dimitry = 0\n } else if(dimitry > 0){\n dimitry -= purple\n purple = 0\n }\n\n\n\n\n if(green >= michal){\n green -= michal\n michal = 0\n } else if(michal > 0){\n michal -= green\n green = 0\n }\n\n if(purple >= michal){\n purple -= michal\n michal = 0\n } else if(michal > 0){\n michal -= purple\n purple = 0\n }\n\n if(black >= michal){\n black -= michal\n michal = 0\n } else if(michal > 0){\n michal -= black\n black = 0\n }\n\n\n\n println(if(andrew == 0 && dimitry == 0 && michal == 0) \"YES\" else \"NO\")\n}\n"}, {"source_code": "import java.io.*\nimport java.lang.Math.max\nimport java.lang.Math.min\nimport java.lang.StringBuilder\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n// val n = br.readLine()!!.toInt()\n\n// repeat(n)\n// {\n val (x,y,z) = br.readLine()!!.split(' ').map{it.toInt()}\n val (a,b,c) = br.readLine()!!.split(' ').map{it.toInt()}\n\n// val s = br.readLine()\n// solve1(a)\n// solve2(a,b,c)\n// solve3(s)\n solve4(x,y,z,a,b,c)\n// }\n\n}\n\nfun solve4(x: Int, y: Int, z: Int, a: Int, b: Int, c: Int) {\n // x -> only a\n // y -> not c\n // z -> anything\n\n val ret = if( a >= x && a - x + b >= y && a - x + b - y + c >= z) \"YES\" else \"NO\"\n println(ret)\n}\n\n\nfun solve3(s: String) {\n\n var ns = s.toCharArray().sorted()\n var sb = StringBuilder()\n for(ch in ns)\n {\n sb.append(ch)\n }\n var nss = sb.toString()\n\n if(nss.reversed() == nss)\n {\n println(-1)\n }\n else\n {\n println(nss)\n }\n}\n\nfun solve2(a: Int, b: Int, c: Int) {\n\n var m = min(a, b-1)\n m = min(m, c-2)\n println(3 * m + 3)\n}\n\nfun solve1(num : Int)\n{\n println(num/2)\n}\n\n\n"}, {"source_code": "import java.lang.Math.min\n\nfun main(args : Array) {\n val want = IntArray(3)\n val have = IntArray(3)\n for (i in 0 until want.size) {\n want[i] = readInt()\n }\n for (i in 0 until have.size) {\n have[i] = readInt()\n }\n for (i in 0 until want.size) {\n var sum = 0\n for (j in 0 .. i) {\n sum += have[j]\n }\n if (sum < want[i]) {\n println(\"NO\")\n return\n }\n var rest = want[i]\n for (j in 0 .. i) {\n if (rest <= have[j]) {\n have[j] -= rest\n break\n } else {\n rest -= have[j]\n have[j] = 0\n }\n }\n }\n println(\"YES\")\n}\n\nprivate fun readln() = readLine()!!\nprivate fun readlnByte() = readln().toByte()\nprivate fun readlnShort() = readln().toShort()\nprivate fun readlnInt() = readln().toInt()\nprivate fun readlnLong() = readln().toLong()\nprivate fun readlnFloat() = readln().toFloat()\nprivate fun readlnDouble() = readln().toDouble()\nprivate fun readlnBigInt(radix: Int = 10) = readln().toBigInteger(radix)\nprivate fun readlnBigDecimal() = readln().toBigDecimal()\n\nprivate fun lineSequence(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.constrainOnce().take(limit)\nprivate fun readlnStrings() = readln().split(' ')\nprivate fun readlnBytes() = readlnStrings().map { it.toByte() }\nprivate fun readlnShorts() = readlnStrings().map { it.toShort() }\nprivate fun readlnInts() = readlnStrings().map { it.toInt() }\nprivate fun readlnLongs() = readlnStrings().map { it.toLong() }\nprivate fun readlnFloats() = readlnStrings().map { it.toFloat() }\nprivate fun readlnDoubles() = readlnStrings().map { it.toDouble() }\n\nprivate fun readByteArray() = readlnStrings().run { ByteArray(size) { get(it).toByte() } }\nprivate fun readShortArray() = readlnStrings().run { ShortArray(size) { get(it).toShort() } }\nprivate fun readIntArray() = readlnStrings().run { IntArray(size) { get(it).toInt() } }\nprivate fun readLongArray() = readlnStrings().run { LongArray(size) { get(it).toLong() } }\nprivate fun readFloatArray() = readlnStrings().run { FloatArray(size) { get(it).toFloat() } }\nprivate fun readDoubleArray() = readlnStrings().run { DoubleArray(size) { get(it).toDouble() } }\n\nprivate fun readlnByteArray(n: Int) = ByteArray(n) { readlnByte() }\nprivate fun readlnShortArray(n: Int) = ShortArray(n) { readlnShort() }\nprivate fun readlnIntArray(n: Int) = IntArray(n) { readlnInt() }\nprivate fun readlnLongArray(n: Int) = LongArray(n) { readlnLong() }\nprivate fun readlnFloatArray(n: Int) = FloatArray(n) { readlnFloat() }\nprivate fun readlnDoubleArray(n: Int) = DoubleArray(n) { readlnDouble() }\n\nprivate fun readByteArray2d(rows: Int, cols: Int) = Array(rows) { readByteArray().also { require(it.size == cols) } }\nprivate fun readShortArray2d(rows: Int, cols: Int) = Array(rows) { readShortArray().also { require(it.size == cols) } }\nprivate fun readLongArray2d(rows: Int, cols: Int) = Array(rows) { readLongArray().also { require(it.size == cols) } }\nprivate fun readIntArray2d(rows: Int, cols: Int) = Array(rows) { readIntArray().also { require(it.size == cols) } }\nprivate fun readFloatArray2d(rows: Int, cols: Int) = Array(rows) { readFloatArray().also { require(it.size == cols) } }\nprivate fun readDoubleArray2d(rows: Int, cols: Int) = Array(rows) { readDoubleArray().also { require(it.size == cols) } }\n\nprivate fun isWhiteSpace(c: Char) = c in \" \\r\\n\\t\"\n\n// JVM-only targeting code follows next\n\n// readString() via sequence is still slightly faster than Scanner\nprivate fun readString() = generateSequence { System.`in`.read().toChar() }\n .dropWhile { isWhiteSpace(it) }.takeWhile { !isWhiteSpace(it) }.joinToString(\"\")\nprivate fun readByte() = readString().toByte()\nprivate fun readShort() = readString().toShort()\nprivate fun readInt() = readString().toInt()\nprivate fun readLong() = readString().toLong()\nprivate fun readFloat() = readString().toFloat()\nprivate fun readDouble() = readString().toDouble()\nprivate fun readBigInt(radix: Int = 10) = readString().toBigInteger(radix)\nprivate fun readBigDecimal() = readString().toBigDecimal()\n\nprivate fun readBytes(n: Int) = generateSequence { readByte() }.take(n)\nprivate fun readShorts(n: Int) = generateSequence { readShort() }.take(n)\nprivate fun readInts(n: Int) = generateSequence { readInt() }.take(n)\nprivate fun readLongs(n: Int) = generateSequence { readLong() }.take(n)\nprivate fun readFloats(n: Int) = generateSequence { readFloat() }.take(n)\nprivate fun readDoubles(n: Int) = generateSequence { readDouble() }.take(n)"}, {"source_code": "fun main() {\n\n val arr = readInts()\n val arr2 = readInts()\n\n\n val x = arr[0] // A - only G\n val y = arr[1] // D - G and F\n val z = arr[2] // M - any\n\n val a = arr2[0] // G\n val b = arr2[1] // F\n val c = arr2[2] // B\n\n\n val overleftAndrey = a - x\n\n if (overleftAndrey < 0) {\n println(\"NO\")\n return\n }\n\n val overleftDmitry = (overleftAndrey + b) - y\n\n if (overleftDmitry < 0) {\n println(\"NO\")\n return\n }\n\n val overleftMicha = (overleftDmitry + c) - z\n\n if (overleftMicha < 0) {\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n}\n\nfun readInts() = readLine()!!.split(' ').map { it.toInt() }"}, {"source_code": "fun main() {\n println(\n if (gotGrapes()) { \"YES\" } else { \"NO\" }\n )\n}\n\nfun gotGrapes() : Boolean {\n var (andrew, dimitry, michal) = readLine()!!.split(\" \").map(String::toInt)\n var (green, purple, black) = readLine()!!.split(\" \").map(String::toInt)\n\n green -= andrew\n\n if (green < 0) return false\n\n val g = kotlin.math.min(dimitry, green)\n dimitry -= g\n green -= g\n purple -= dimitry\n\n if (purple < 0) return false\n\n return (green + purple + black) >= michal\n}\n\n"}, {"source_code": "fun main(args: Array) {\n val (vA, vD, vM) = readLine()!!.split(' ').map(String::toInt)\n val (v1, v2, v3) = readLine()!!.split(' ').map(String::toInt)\n\n val o1 = v1 - vA\n if (o1 < 0) {\n println(\"NO\")\n return\n }\n val o12 = v2 + o1 - vD\n if (o12 < 0) {\n println(\"NO\")\n return\n }\n if (o12 + v3 ) {\n val sc = Scanner(System.`in`)\n val want = IntArray( 3, { sc.nextInt() } )\n val have = IntArray( 3, { sc.nextInt() } )\n\n for ( i in want.indices.reversed() ) {\n want[i] -= have[i]\n if ( want[i] <= 0 ) continue\n for ( j in i - 1 downTo 0 ) {\n val take = Math.min(want[i], have[j])\n want[i] -= take\n have[j] -= take\n }\n if ( want[i] > 0 ) {\n println( \"NO\" )\n return\n }\n }\n println( \"YES\" )\n}"}, {"source_code": "fun readInt(): Long = readLine()!!.toLong()\nfun readInts(): List = readLine().orEmpty().split(\" \").map { it.toLong() }\n\nfun main() {\n val x = readInts().cumsum()\n val y = readInts().cumsum()\n\n val yes = (x zip y).all { (a, b) -> a <= b }\n\n println(if (yes) \"YES\" else \"NO\")\n}\n\nfun Iterable.reductions(initial: R, operation: (acc: R, T) -> R): Sequence = sequence {\n var last = initial\n forEach {\n last = operation(last, it)\n yield(last)\n }\n}\n\nfun List.cumsum() = this.reductions(0L) { acc, l -> acc + l }.toList()"}, {"source_code": "const val GREEN = 0\nconst val PURPLE = 1\nconst val BLACK = 2\nconst val ANDREW = 0\nconst val DIMITRY = 1\nconst val MICHAEL = 2\nfun main() {\n val request = readLine()!!.split(\" \").map { it.toInt() }\n val box = readLine()!!.split(\" \").map { it.toInt() }\n\n if (request[ANDREW] > box[GREEN])\n print(\"NO\")\n else {\n val leftOfGreen = box[GREEN] - request[ANDREW]\n\n val leftOfGreenAndPurple = leftOfGreen + box[PURPLE]\n\n if (leftOfGreenAndPurple < request[DIMITRY]) {\n println(\"NO\")\n } else {\n\n val sumOfAllLeft = leftOfGreenAndPurple - request[DIMITRY] + box[BLACK]\n\n if (sumOfAllLeft < request[MICHAEL]) {\n print(\"NO\")\n } else {\n println(\"YES\")\n }\n\n }\n\n }\n\n}\n\n\n"}, {"source_code": "import kotlin.math.min\n\nfun readThree() = readLine()!!.split(\" \").map { it.toInt() }\nfun main() {\n var (andrew, dmitry, michal) = readThree()\n var (green, purple, black) = readThree()\n\n green -= andrew\n\n if (green < 0) println(\"NO\")\n else {\n val greenForDmitry = min(green, dmitry)\n green -= greenForDmitry\n dmitry -= greenForDmitry\n\n purple -= dmitry\n when {\n purple < 0 -> println(\"NO\")\n green + purple + black < michal -> println(\"NO\")\n else -> println(\"YES\")\n }\n }\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val scanner = Scanner(System.`in`)\n var x = scanner.nextInt()\n var y = scanner.nextInt()\n var z = scanner.nextInt()\n\n var a = scanner.nextInt()\n var b = scanner.nextInt()\n var c = scanner.nextInt()\n\n a -= x\n if (a < 0) {\n println(\"NO\")\n return\n }\n\n if (a > 0) {\n a -= y\n if (a < 0) {\n y = a * -1\n } else {\n y = 0\n }\n }\n\n b -= y\n if (b < 0) {\n println(\"NO\")\n return\n }\n\n if (a > 0) {\n a -= z\n if (a < 0) {\n z = a * -1\n } else {\n z = 0\n }\n }\n\n if (b > 0) {\n b -= z\n if (b < 0) {\n z = b * -1\n } else {\n z = 0\n }\n }\n\n c -= z\n if (c < 0) {\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun canEat(): Boolean {\n var x = inp.nextInt()\n var y = inp.nextInt()\n var z = inp.nextInt()\n\n var a = inp.nextInt()\n var b = inp.nextInt()\n var c = inp.nextInt()\n\n if (a < x) {\n return false\n }\n a -= x\n x = 0\n\n if (a + b < y) {\n return false\n }\n val remAB = a + b - y\n return remAB + c >= z\n}\n\nfun run() {\n val res: String = if (canEat()) \"YES\" else \"NO\"\n out.println(res)\n}\n\nprivate val inp = FastInput()\nprivate val out = FastOutput()\n\nfun main() {\n run()\n out.flush()\n out.close()\n}\n\ninternal class FastInput(private val bufferedReader: BufferedReader) {\n private var tokenizer: StringTokenizer? = null\n\n constructor() : this(System.`in`)\n constructor(stream: InputStream) : this(BufferedReader(InputStreamReader(stream)))\n constructor(file: File) : this(BufferedReader(FileReader(file)))\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(bufferedReader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int = next().toInt()\n fun nextLong(): Long = next().toLong()\n}\n\ninternal class FastOutput constructor(outputStream: OutputStream = System.out) {\n private val bufferedWriter = BufferedWriter(OutputStreamWriter(outputStream))\n\n private fun printOne(obj: T) {\n bufferedWriter.write(\"$obj\")\n }\n\n fun println(obj: T) = bufferedWriter.write(\"$obj\\n\")\n\n fun print(vararg objs: Any) = printd(\"\", *objs)\n\n fun printd(delimiter: String, vararg objs: Any) {\n for (i in 0 until objs.size) {\n printOne(objs[i])\n printOne(delimiter)\n }\n }\n\n fun flush() = bufferedWriter.flush()\n fun close() = bufferedWriter.close()\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val (x, y, z) = readInts()\n val (a, b, c) = readInts()\n val ok = a >= x && a + b >= x + y && a + b + c >= x + y + z\n println(if (ok) \"YES\" else \"NO\")\n}"}, {"source_code": "const val GREEN = 0\nconst val PURPLE = 1\nconst val BLACK = 2\nconst val ANDREW = 0\nconst val DIMITRY = 1\nconst val MICHAEL = 2\nfun main() {\n val request = readLine()!!.split(\" \").map { it.toInt() }\n val box = readLine()!!.split(\" \").map { it.toInt() }\n\n if (request[ANDREW] > box[GREEN])\n print(\"NO\")\n else {\n val leftOfGreen = box[GREEN] - request[ANDREW]\n\n val leftOfGreenAndPurple = leftOfGreen + box[PURPLE]\n\n if (leftOfGreenAndPurple < request[DIMITRY]) {\n println(\"NO\")\n } else {\n\n val sumOfAllLeft = leftOfGreenAndPurple - request[DIMITRY] + box[BLACK]\n\n if (sumOfAllLeft < request[MICHAEL]) {\n print(\"NO\")\n } else {\n println(\"YES\")\n }\n\n }\n\n }\n\n}\n\n\n"}, {"source_code": "fun main( )\n{\n var (x, y, z) = readLine()!!.split(' ').map(String::toInt)\n var (a, b, c) = readLine()!!.split(' ').map(String::toInt)\n if (a) {\n val (vA, vD, vM) = readLine()!!.split(' ').map(String::toInt)\n val (v1, v2, v3) = readLine()!!.split(' ').map(String::toInt)\n\n val o1 = v1 - vA\n if (o1 < 0) {\n println(\"NO\")\n return\n }\n val o12 = v2 + o1 - vD\n if (o12 < 0) {\n println(\"NO\")\n return\n }\n if (o12 + v3, l2: List): String {\n\tvar (x, y, z) = l;\n\tvar (a, b, c) = l2;\n\n\tif (x > a) {\n\t\treturn \"NO\";\n\t}\n\tif (x + y > a + b) {\n\t\treturn \"NO\"\n\t}\n\tif (x + y + z > a + b + c) {\n\t\treturn \"NO\"\t\n\t}\n\n\treturn \"YES\"\n}\n\nfun main(args: Array) {\n\tvar l = readlnInts();\n\tvar l2 = readlnInts();\n\tvar res = solve(l, l2);\n\tprintln(res);\n}"}, {"source_code": "private fun readLn() = readLine()!!\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n\nfun main() {\n val (x, y, z) = readInts()\n val (a, b, c) = readInts()\n\n println(f(x, y, z, a, b, c))\n}\n\nfun f(x: Int, y: Int, z: Int, a: Int, b: Int, c: Int): String {\n var a1 = a\n var y1 = y\n var b1 = b\n\n if (a1 < x) return \"NO\"\n a1 -= x\n\n if (a1 + b1 < y1) return \"NO\"\n if (a1 < y1) {\n y1 -= a1\n a1 -= a1\n b1 -= y1\n } else {\n a1 -= y1\n }\n\n return if (a1 + b1 + c < z) \"NO\" else \"YES\"\n}"}, {"source_code": "fun main() {\n val needed = readLine()!!.split(' ').map { it.toInt() }\n val available = readLine()!!.split(' ').map { it.toInt() }\n var leftOver = 0\n for (i in 0..2) {\n if (leftOver + available[i] < needed[i]) {\n println(\"NO\")\n return\n } else {\n leftOver = leftOver + available[i] - needed[i]\n }\n }\n println(\"YES\")\n}\n"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(' ').map { it.toInt() }\n val (a, b, c) = readLine()!!.split(' ').map { it.toInt() }\n if (a >= x && a - x + b >= y && a - x + b - y + c >= z) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}"}, {"source_code": "import kotlin.system.exitProcess\n\nfun main()\n{\n var (x, y, z) = readLine()!!.split(' ').map(String::toInt)\n \n var (a, b, c) = readLine()!!.split(' ').map(String::toInt)\n \n if (a < x)\n {\n println(\"NO\")\n exitProcess(0)\n }\n a -= x\n \n if (a + b < y)\n {\n println(\"NO\")\n exitProcess(0)\n }\n \n var remaining_grapes = a + b - y + c\n \n if (remaining_grapes < z)\n {\n println(\"NO\")\n exitProcess(0)\n }\n \n println(\"YES\")\n}\n \n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n\n val reader = Scanner(System.`in`)\n val input1 = reader.nextLine()\n val input2 = reader.nextLine()\n\n val neededGrapes = input1.split(\" \")\n val andrewWants = neededGrapes[0].toInt()\n val dmitryWants = neededGrapes[1].toInt()\n val michalWants = neededGrapes[2].toInt()\n\n val totalAvailableGrapes = input2.split(\" \")\n\n var totalGreenGrapes = totalAvailableGrapes[0].toInt()\n var totalPurpleGrapes = totalAvailableGrapes[1].toInt()\n var totalBlackGrapes = totalAvailableGrapes[2].toInt()\n\n\n if (andrewWants > totalGreenGrapes) {\n println(\"NO\")\n return\n } else {\n totalGreenGrapes -= andrewWants;\n }\n\n if (dmitryWants > (totalGreenGrapes + totalPurpleGrapes)) {\n println(\"NO\")\n return\n } else {\n totalGreenGrapes -= dmitryWants\n if (totalGreenGrapes < 0) {\n totalPurpleGrapes += totalGreenGrapes\n totalGreenGrapes = 0\n }\n }\n\n if (michalWants > (totalGreenGrapes + totalPurpleGrapes + totalBlackGrapes)) {\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n\n}"}, {"source_code": "fun main()\n{\n var (x, y, z) = readLine()!!.split(\" \").map{it.toInt()};\n var (a, b, c) = readLine()!!.split(\" \").map{it.toInt()};\n if (x>a)\n println(\"NO\");\n else\n {\n a-=x;\n if (y>a+b)\n println(\"NO\");\n else\n {\n var tot = a+b+c-y;\n if (z>tot)\n println(\"NO\");\n else\n println(\"YES\");\n }\n }\n}"}, {"source_code": "private val inputRegex = \"\"\"(\\d+)\\s(\\d+)\\s(\\d+)\"\"\".toRegex()\n\nfun main() {\n val (x, y, z) = inputRegex.find(readLine()!!)!!.destructured.toList().map { it.toInt() }\n val (a, b, c) = inputRegex.find(readLine()!!)!!.destructured.toList().map { it.toInt() }\n\n val result = if (satisfiedCondition(x, y, z, a, b, c)) \"YES\" else \"NO\"\n println(result)\n\n\n}\n\nfun satisfiedCondition(x: Int, y: Int, z: Int, a: Int, b: Int, c: Int): Boolean {\n if (a < x) return false\n if (a + b < x + y) return false\n if (a + b + c < x + y + z) return false\n\n return true\n}\n"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.split(\" \").map(String::toInt)\n val h = readLine()!!.split(\" \").map(String::toInt)\n println(if(h[0] >= n[0] && h[0] + h[1] >= n[0] + n[1] && h[0] + h[1] + h[2] >= n[0] + n[1] + n[2]) \"YES\" else \"NO\")\n}"}, {"source_code": "import java.util.*\n\n//2019-03-02\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val x = nextInt()\n val y = nextInt()\n val z = nextInt()\n\n val a = nextInt()\n val b = nextInt()\n val c = nextInt()\n\n val greenDiff = a - x\n if (greenDiff < 0) {\n print(\"NO\")\n return@with\n }\n\n val purpleDiff = greenDiff + b - y\n if (purpleDiff < 0) {\n print(\"NO\")\n return@with\n }\n\n val blackDiff = purpleDiff + c - z\n if (blackDiff < 0) {\n print(\"NO\")\n return@with\n }\n\n print(\"YES\")\n}"}, {"source_code": "import java.util.Scanner\nimport java.util.Arrays\nfun main(args:Array){\n\tval reader = Scanner(System.`in`)\n\tvar t:Int = reader.nextInt()\n\tvar t1:Int = reader.nextInt()\n\tvar t2:Int = reader.nextInt()\n\tvar g:Int = reader.nextInt()\n\tvar g1:Int = reader.nextInt()\n\tvar g2:Int = reader.nextInt()\n\tif(t<=g && t1<=(g-t)+g1 &&t2 <= (g-t1-t)+g1+g2){\n\t\tprintln(\"YES\")\n\t} else {\n\t\tprintln(\"NO\")\n\t}\n}"}], "negative_code": [{"source_code": "import java.util.*\n\n\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n\n var andrew = sc.nextInt()\n var dimitry = sc.nextInt()\n var michal = sc.nextInt()\n\n var green = sc.nextInt()\n var purple = sc.nextInt()\n var black = sc.nextInt()\n\n\n if(green > andrew){\n green -= andrew\n andrew = 0\n }\n\n\n\n if(green > dimitry){\n green -= dimitry\n dimitry = 0\n } else {\n dimitry -= green\n green = 0\n }\n\n if(purple > dimitry){\n purple -= dimitry\n dimitry = 0\n } else {\n dimitry -= purple\n purple = 0\n }\n\n\n\n\n if(green > michal){\n green -= michal\n michal = 0\n } else {\n michal -= green\n green = 0\n }\n\n if(purple > michal){\n purple -= michal\n michal = 0\n } else {\n michal -= purple\n purple = 0\n }\n\n if(black > michal){\n black -= michal\n michal = 0\n } else {\n michal -= black\n green = 0\n }\n\n\n\n println(if(andrew == 0 && dimitry == 0 && michal == 0) \"YES\" else \"NO\")\n}\n"}, {"source_code": "fun main(args: Array) {\n\n val (an, dm, mh) = readLine()!!\n .split(\" \")\n .map { Integer.valueOf(it)!! }\n\n var (green, purple, black) = readLine()!!\n .split(\" \")\n .map { Integer.valueOf(it)!! }\n if (green < an) {\n no()\n return\n } else {\n green -= an\n }\n\n if (green + purple < dm) {\n no()\n return\n }\n\n if (green + purple + black - dm - mh > 0) {\n println(\"YES\")\n } else {\n no()\n }\n}\n\nfun no() {\n println(\"NO\")\n}\n"}, {"source_code": "fun main()\n{\n var (x, y, z) = readLine()!!.split(\" \").map{it.toInt()};\n var (a, b, c) = readLine()!!.split(\" \").map{it.toInt()};\n if (x>a)\n println(\"NO\");\n else\n {\n a-=x;\n if (y>a+c)\n println(\"NO\");\n else\n {\n var tot = a+b+c-y;\n if (z>tot)\n println(\"NO\");\n else\n println(\"YES\");\n }\n }\n}"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(' ').map(String::toInt)\n val (green, purple, black) = readLine()!!.split(' ').map(String::toInt)\n\n if (x <= green && y <= green+purple && z <= green+purple+black)\n print(\"YES\")\n else\n print(\"NO\")\n}\n"}, {"source_code": "fun solve(x:Int, y:Int, z:Int, a:Int, b:Int, c:Int):Int {\n\tif (x > a || x+y > a+b+c || x+y+z > a+b+c)\n\t\treturn 1\n\telse\n\t\treturn 0\n}\n\nfun main() {\n\tval (x, y, z) = readLine()!!.split(' ').map(String::toInt)\n\tval (a, b, c) = readLine()!!.split(' ').map(String::toInt)\n\tval ans = solve(x, y, z, a, b, c);\n\tprint(arrayOf(\"YES\", \"NO\")[ans])\n}\n"}, {"source_code": "import java.util.Scanner\n\nval no = \"NO\"\nval yes = \"YES\"\n\nfun main() {\n val scanner = Scanner(System.`in`)\n\n val and = scanner.nextInt()\n var dm = scanner.nextInt()\n val mi = scanner.nextInt()\n\n var green = scanner.nextInt()\n var purple = scanner.nextInt()\n val black = scanner.nextInt()\n\n if (and > green) {\n println(no)\n return\n }\n green -= and\n if (dm > green + purple) {\n println(no)\n return\n }\n\n if (green >= dm) {\n green -= dm\n } else {\n dm -= green\n green = 0\n purple -= dm\n }\n\n println(if (green + purple + black > mi) yes else no)\n}"}, {"source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val xyz = readLine()!!.split(' ')\n val abc = readLine()!!.split(' ')\n\n val x = xyz[0].toInt() // only a\n val y = xyz[1].toInt() // not c\n val z = xyz[2].toInt() // any\n\n val a = abc[0].toInt()\n val b = abc[1].toInt()\n val c = abc[2].toInt()\n\n val a0 = a - x\n\n if (a0 < 0) {\n println(\"NO\")\n return\n }\n\n val y0 = max(a0 - y, 0)\n val a1 = a0 - y0\n val b0 = b - (y - y0)\n\n if (b0 < 0) {\n println(\"NO\")\n return\n }\n\n val c0 = (a1 + b0 + c) - z\n\n if (c0 < 0) {\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n}"}, {"source_code": "import java.util.Scanner\n\nval no = \"NO\"\nval yes = \"YES\"\n\nfun main() {\n val scanner = Scanner(System.`in`)\n\n val and = scanner.nextInt()\n var dm = scanner.nextInt()\n val mi = scanner.nextInt()\n\n var green = scanner.nextInt()\n var purple = scanner.nextInt()\n val black = scanner.nextInt()\n\n if (and >= green) {\n println(no)\n return\n }\n green -= and\n if (dm >= green + purple) {\n println(no)\n return\n }\n\n if (green >= dm) {\n green -= dm\n } else {\n dm -= green\n green = 0\n purple -= dm\n }\n\n println(if (green + purple + black >= mi) yes else no)\n}"}, {"source_code": "import java.io.*\nimport java.lang.Math.max\nimport java.lang.Math.min\nimport java.lang.StringBuilder\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n// val n = br.readLine()!!.toInt()\n\n// repeat(n)\n// {\n val (x,y,z) = br.readLine()!!.split(' ').map{it.toInt()}\n val (a,b,c) = br.readLine()!!.split(' ').map{it.toInt()}\n\n// val s = br.readLine()\n// solve1(a)\n// solve2(a,b,c)\n// solve3(s)\n solve4(x,y,z,a,b,c)\n// }\n\n}\n\nfun solve4(x: Int, y: Int, z: Int, a: Int, b: Int, c: Int) {\n // x -> only a\n // y -> not c\n // z -> anything\n\n var ret = \"YES\"\n\n if(x > a)\n {\n ret = \"NO\"\n }\n else\n {\n var newa = a - x\n\n var newz = max( z - c, 0)\n\n var newc = if(z < c) c - z else 0\n\n val left = b + newa + newc\n\n if(y + newz > left) ret = \"NO\"\n }\n\n println(ret)\n}\n\n\nfun solve3(s: String) {\n\n var ns = s.toCharArray().sorted()\n var sb = StringBuilder()\n for(ch in ns)\n {\n sb.append(ch)\n }\n var nss = sb.toString()\n\n if(nss.reversed() == nss)\n {\n println(-1)\n }\n else\n {\n println(nss)\n }\n}\n\nfun solve2(a: Int, b: Int, c: Int) {\n\n var m = min(a, b-1)\n m = min(m, c-2)\n println(3 * m + 3)\n}\n\nfun solve1(num : Int)\n{\n println(num/2)\n}\n\n\n"}, {"source_code": "fun main(args: Array) {\n val parts = readLine()!!.toString().split(\" \")\n val A : Int =parts.get(0).toInt()\n val D : Int= parts.get(1).toInt()\n val M : Int = parts.get(2).toInt()\n\n val grappe = readLine()!!.toString().split(\" \")\n val G : Int =grappe.get(0).toInt()\n val P : Int= grappe.get(1).toInt()\n val B : Int = grappe.get(2).toInt()\n\n var res : String =\"YES\"\n\n val restG = G - A\n\n if(restG<0){\n res = \"NO\"\n }else{\n\n val restPG = D - (restG + P)\n if( restPG < 0){\n res = \"NO\"\n }else{\n val restPGD = M - restPG\n if(restPGD < 0 ){\n res = \"NO\"\n }\n }\n\n }\n\n println(\"$res\")\n}"}, {"source_code": "fun anyGrapes(want:List, grapes:List){\n if(want[0].toInt() > grapes[0].toInt()){\n println(\"NO\")\n }\n else {\n val dymiCurr = want[1].toInt()\n val michCurr = want[2].toInt() - grapes[2].toInt() //Michael gets all black grapes\n val remainGrPu = (grapes[0].toInt() + grapes[1].toInt()) - (want[0].toInt()) //remaining green and purple grapes\n\n if (((dymiCurr+michCurr) - remainGrPu) > 0){\n println(\"NO\")\n return\n }\n println(\"YES\")\n }\n}\n\n\nfun main(args:Array){\n val want = readLine()!!.split(\" \")\n val grapes = readLine()!!.split(\" \")\n anyGrapes(want, grapes)\n}"}, {"source_code": "// contest/1171/problem/B Kotlin heroes training done\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n var canDo: Boolean\n val xyz = readInts()\n var (x,y,z) = xyz\n val abc = readInts()\n var (a,b,c) = abc\n if (a < x) {\n canDo = false\n } else {\n a -= x\n if (a+b < y) {\n canDo = false\n } else {\n if (a > y) {\n y -= a\n } else {\n b -= (y-a)\n a = 0\n }\n canDo = (a+b+c) >= z\n }\n }\n\n println( if (canDo) \"YES\" else \"NO\" )\n}\n"}, {"source_code": "import kotlin.math.min\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main(args: Array) {\n var (x, y, z) = readInts()\n var (a, b, c) = readInts()\n a -= x\n if (a < 0) {\n println(\"NO\")\n return\n }\n var k = min(a, y)\n y -= k\n a -= k\n if (y > 0) {\n c -= y\n }\n k = min(z, a)\n a -= k\n z -= k\n k = min(z, b)\n b -= k\n z -= k\n k = min(z, c)\n c -= k\n z -= k\n if (a < 0 || b < 0 || c < 0 || z > 0) {\n println(\"NO\")\n return\n }\n println(\"YES\")\n}"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(\" \").map(String::toInt)\n val (a, b, c) = readLine()!!.split(\" \").map(String::toInt)\n if (a >= x && a + b >= x + y && a + c + c >= x + y + z) print(\"YES\") else print(\"NO\")\n}\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array ) {\n val sc = Scanner(System.`in`)\n val want = IntArray( 3, { sc.nextInt() } )\n val have = IntArray( 3, { sc.nextInt() } )\n\n for ( i in want.indices.reversed() ) {\n want[i] -= have[i]\n if ( want[i] <= 0 ) continue\n for ( j in i - 1 downTo 0 ) {\n want[i] -= Math.min( want[i], have[j] )\n }\n if ( want[i] > 0 ) {\n println( \"NO\" )\n return\n }\n }\n println( \"YES\" )\n}"}, {"source_code": " fun main(args:Array){\n val (a, b, c) = readLine()!!.split(' ')\n var x1:Int = a.toInt()\n var y1:Int = b.toInt()\n var z1:Int = c.toInt()\n val (a1, b1, c1) = readLine()!!.split(' ')\n var x:Int = a1.toInt()\n var y:Int = b1.toInt()\n var z:Int = c1.toInt()\n var flag = 0\n if(x1 <= x && flag == 0) {x -= x1}\n else {flag = 1}\n \n if(y1 <= (y + x) && flag == 0) \n {if(y1 <= y) y -= y1\n else y = 0; x -= (y - y1)}\n else {flag = 1}\n \n if(z1 <= (x + y + z) && flag == 0) {flag = 0}\n else {flag = 1} \n \n if(flag == 0) {println(\"YES\")}\n else {println(\"NO\")}\n}"}, {"source_code": "import java.util.*\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main(args: Array) {\n\n var(x,y,z) =readInts()\n var(green,purple,black) =readInts()\n\n var temp:Int\n\n temp=green-x\n if(temp<0){\n println(\"NO\")\n return\n }else{\n green-x\n }\n temp=(green+purple)-y\n if(temp<0){\n println(\"NO\")\n return\n }else{\n val purp=y-green\n val gre=y-purple\n green-gre\n purple-purp\n }\n\n temp=(green+purple+black)-z\n\n if(temp<0){\n println(\"NO\")\n return\n }\n println(\"YES\")\n\n\n}\n\n"}, {"source_code": "fun main() {\n val targetGrapes = readLine()!!\n val nGrapes = readLine()!!\n println(getGoodString(targetGrapes.split(\" \"), nGrapes.split(\" \")))\n}\n\nfun getGoodString(targetGrapes: List, nGrapes: List): String {\n val targetAndrew = targetGrapes[0].toInt()\n val targetDmitry = targetGrapes[1].toInt()\n val targetMichael = targetGrapes[2].toInt()\n var nGreen = nGrapes[0].toInt()\n val nPurple = nGrapes[1].toInt()\n val nBlack = nGrapes[2].toInt()\n if (nGreen < targetAndrew) return \"NO\"\n nGreen -= targetAndrew\n if (nGreen + nPurple < targetDmitry) return \"NO\"\n val remaining = nGreen + nPurple + nBlack - targetDmitry\n if (remaining < targetMichael) return \"YES\"\n return \"NO\"\n}"}, {"source_code": "fun main()\n{\n var (x, y, z) = readLine()!!.split(\" \").map{it.toInt()};\n var (a, b, c) = readLine()!!.split(\" \").map{it.toInt()};\n if (x>a)\n println(\"NO\");\n else\n {\n a-=x;\n if (y>a+c)\n println(\"NO\");\n else\n {\n var tot = a+b+c-y;\n if (z>tot)\n println(\"NO\");\n else\n println(\"YES\");\n }\n }\n}"}, {"source_code": "fun main() {\n val want = readLine()!!.split(\" \").map{it.toInt()}\n val box = readLine()!!.split(\" \").map{it.toInt()}\n\n\n\n if (box[0]= y) {\n b = b - y\n y = 0\n } else {\n y = y - b\n b = 0\n }\n if (c >= y) {\n c = c - y\n y = 0\n } else {\n y = y - c\n c = 0\n }\n if (y > 0) {\n println(\"NO\")!!\n return\n }\n if (a + b + c >= z) {\n println(\"YES\")!!\n } else {\n println(\"NO\")!!\n }\n }\n}"}, {"source_code": "\nimport java.util.Scanner\n\nfun main(args: Array) {\n exercise4()\n}\n\nfun exercise4(){\n val reader = Scanner(System.`in`)\n val andrew = reader.nextInt()\n var dimitri = reader.nextInt()\n val michael = reader.nextInt()\n\n var green = reader.nextInt()\n var purple = reader.nextInt()\n var black = reader.nextInt()\n\n green -= andrew\n if (green < 0){\n println(\"NO\")\n } else {\n if (green >= dimitri){\n green -= dimitri\n } else {\n dimitri -= green\n purple -= dimitri\n green = 0\n if (purple < 0){\n println(\"NO\")\n } else {\n if (green + purple + black >= michael) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n }\n }\n }\n\n}"}, {"source_code": "\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val (x, y, z) = readInts() // num they want to eat\n val (g, p, b) = readInts()\n \n // x will only eat greens\n // y will only eat green or black\n // z eats all\n \n var greens = g\n greens -= x // x eats the green grapes he wants\n var notBlack = greens + p\n notBlack -= y\n var rest = greens + notBlack + b\n rest -= z\n \n if (greens >= 0 && notBlack >= 0 && rest >= 0)\n println(\"YES\")\n else \n println(\"NO\")\n}\n"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(' ').map(String::toInt)\n val (green, purple, black) = readLine()!!.split(' ').map(String::toInt)\n\n if (x <= green && y <= green+purple && z <= green+purple+black)\n print(\"YES\")\n else\n print(\"NO\")\n}\n"}, {"source_code": "\nfun main(args: Array) {\n val (andrew, dmitry, mischal) = readLine()!!.map { it.toInt() }\n val (green, purple, black) = readLine()!!.map { it.toInt() }\n\n if (green < andrew) {\n println(\"NO\")\n return\n }\n val remainGreen = green - andrew\n if (remainGreen + purple < dmitry) {\n println(\"NO\")\n return\n }\n val remain = remainGreen + purple - andrew\n if (remain + black < mischal) {\n println(\"NO\")\n return\n }\n println(\"YES\")\n}"}, {"source_code": "import kotlin.system.exitProcess\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n var (x, y, z) = readInts()\n var (a, b, c) = readInts()\n if (x+y+z>a+b+c || x>a || y>a-x+c) {\n println(\"NO\")\n } else {\n println(\"YES\")\n }\n}"}, {"source_code": "import java.util.*\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main(args: Array) {\n\n var(x,y,z) =readInts()\n var(green,purple,black) =readInts()\n\n var temp:Int\n\n temp=green-x\n if(temp<0){\n println(\"NO\")\n return\n }\n temp=(green+purple)-y\n if(temp<0){\n println(\"NO\")\n return\n }\n\n temp=(green+purple+black)-z\n\n if(temp<0){\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n\n\n}\n\n"}, {"source_code": "fun isEnough(wish: List, grapes: List) {\n val enough = grapes[0] >= wish[0] &&\n grapes[0] + grapes[1] >= wish[1] &&\n grapes[0] + grapes[1] + grapes[2] >= wish[2]\n println(when(enough) {\n true -> \"YES\"\n else -> \"NO\"\n })\n}\n\nfun main() {\n val wish = readLine()!!.split(\" \").map { it.toInt() }\n val grapes = readLine()!!.split(\" \").map { it.toInt() }\n\n isEnough(wish, grapes)\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //var (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n val (x, y, z) = r.readLine()!!.split(\" \").map { it.toInt() }\n val (a, b, c) = r.readLine()!!.split(\" \").map { it.toInt() }\n val ans = a>=x&&(x-a+b>=y)&&(x+y-a-b+c>=z)\n println(if (ans)\"YES\" else \"NO\")\n}"}, {"source_code": "// contest/1171/problem/B Kotlin heroes training done\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n var canDo: Boolean\n val xyz = readInts()\n var (x,y,z) = xyz\n val abc = readInts()\n var (a,b,c) = abc\n if (a < x) {\n canDo = false\n } else {\n a -= x\n if (a+b < y) {\n canDo = false\n } else {\n if (a > y) {\n y -= a\n } else {\n b -= (y-a)\n a = 0\n }\n canDo = (a+b+c) >= z\n }\n }\n\n println( if (canDo) \"YES\" else \"NO\" )\n}\n"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n val (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n if (x>a) println(\"NO\")\n if (x+y>a+b) println(\"NO\")\n if (x+y+z>a+b+c) println(\"NO\") else println(\"YES\")\n}"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n val (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n\n val grapesMap = mutableMapOf(\n \"green\" to a,\n \"purple\" to b,\n \"black\" to c\n )\n\n provideAndrew(grapesMap, x)\n provideDmitri(grapesMap, y)\n provideMichal(grapesMap, z)\n if (isValidDistribution(grapesMap)) println(\"YES\") else println(\"NO\")\n}\n\nprivate fun provideAndrew(grapesMap: MutableMap, wanted: Int) {\n grapesMap[\"green\"] = grapesMap[\"green\"]!!.minus(wanted)\n}\n\nprivate fun provideDmitri(grapesMap: MutableMap, wanted: Int) {\n val purple = grapesMap[\"purple\"]!!\n if (wanted <= purple) {\n grapesMap[\"purple\"] = purple.minus(wanted)\n return\n }\n grapesMap[\"purple\"] = 0\n grapesMap[\"green\"] = grapesMap[\"green\"]!!.minus(wanted - purple)\n}\n\nprivate fun provideMichal(grapesMap: MutableMap, wanted: Int) {\n grapesMap[\"black\"] = grapesMap[\"black\"]!!.minus(wanted)\n}\n\nprivate fun isValidDistribution(grapesMap: MutableMap): Boolean {\n return grapesMap.filter { it.value >= 0 }.size == grapesMap.size\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val (x, y, z) = scan.nextLine().split(\" \").map { it.toInt() }\n var (a, b, c) = scan.nextLine().split(\" \").map { it.toInt() }\n\n if (a < x) {\n println(\"NO\")\n return\n }\n\n a -= x // 3\n\n var greenAndPurple = a + b\n\n if(y < greenAndPurple) {\n println(\"NO\")\n return\n }\n\n greenAndPurple -= y\n\n val allGrapes = greenAndPurple + z\n if(allGrapes < z) {\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n}"}, {"source_code": "fun readInt(): Long = readLine()!!.toLong()\nfun readInts(): List = readLine().orEmpty().split(\" \").map { it.toLong() }\n\nfun main() {\n val x = readInts().cumsum()\n val y = readInts().cumsum()\n\n val yes = (x zip y).all { (a, b) -> a >= b }\n\n println(if (yes) \"YES\" else \"NO\")\n}\n\nfun Iterable.reductions(initial: R, operation: (acc: R, T) -> R): Sequence = sequence {\n var last = initial\n forEach {\n last = operation(last, it)\n yield(last)\n }\n}\n\nfun List.cumsum() = this.reductions(0L) { acc, l -> acc + l }.toList()"}, {"source_code": "fun main() {\n val want = readLine()!!.split(\" \").map{it.toInt()}\n val box = readLine()!!.split(\" \").map{it.toInt()}\n\n\n when {\n (box[0]+box[1]+box[2]-want[0]-want[1]) < want[2] -> println(\"NO\")\n box[0] println(\"NO\")\n box[0]-want[0]+box[2]-want[2]+box[1] println(\"NO\")\n else -> println(\"YES\")\n }\n\n}"}, {"source_code": "import java.util.*\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main(args: Array) {\n\n var (x, y, z) = readInts()\n var (green, purple, black) = readInts()\n\n var temp: Int\n\n temp = green-x\n if (temp < 0) {\n println(\"NO\")\n return\n } else {\n green -= x\n }\n temp = (green + purple)-y\n if (temp < 0) {\n println(\"NO\")\n return\n } else {\n val pur = y - green\n val gre = y - purple\n green -= gre\n purple -= pur\n }\n\n temp = (green + purple + black)-z\n\n if (temp < 0) {\n println(\"NO\")\n return\n }\n println(\"YES\")\n\n\n}\n\n"}, {"source_code": "import kotlin.system.exitProcess\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n var (x, y, z) = readInts()\n var (a, b, c) = readInts()\n if (x+y+z>a+b+c || x>a || y>a-x+c) {\n println(\"NO\")\n } else {\n println(\"YES\")\n }\n}"}, {"source_code": "fun main() {\n println(\n if (gotGrapes()) { \"YES\" } else { \"NO\" }\n )\n}\n\nfun gotGrapes() : Boolean {\n var (andrew, dimitry, michal) = readLine()!!.split(\" \").map(String::toInt)\n var (green, purple, black) = readLine()!!.split(\" \").map(String::toInt)\n\n green -= andrew\n\n if (green < 0) return false\n\n val i = kotlin.math.min(dimitry, green)\n dimitry -= i\n green -= i\n purple - dimitry\n\n if (purple < 0) return false\n\n return (green + purple + black) >= michal\n}"}, {"source_code": "fun main(args: Array) {\n solve()\n}\n\nprivate fun read(delimit: Char=' ') = readLine()!!.split(delimit)\n\nprivate fun solve() {\n var (a, d, m) = read().map(String::toInt)\n var (g, p, b) = read().map(String::toInt)\n var ans = \"YES\"\n if (g < a) ans = \"NO\"\n else if ((g + p) < (a + d)) ans = \"NO\"\n else if ((g + p + b) <= (a + d + m)) ans = \"NO\"\n println(ans)\n\n\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n\n val needs = nextLine()!!.split(\"\\\\s\".toRegex())\n val peopleNeeds = needs.map { it.toInt() }.toMutableList()\n val grapes = nextLine()!!.split(\"\\\\s\".toRegex()).map { it.toInt() }.toMutableList()\n\n val peopleGrapes = listOf(intArrayOf(0), intArrayOf(0, 1), intArrayOf(0, 1, 2))\n\n val enoughGrapes = hasEnoughtGrapes(peopleNeeds, grapes, peopleGrapes)\n\n if (enoughGrapes) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n\n}\n\nfun hasEnoughtGrapes(peopleNeeds: MutableList, grapes: MutableList, peopleGrapes: List): Boolean {\n\n peopleNeeds.forEachIndexed { personIndex, need ->\n\n peopleGrapes[personIndex].forEachIndexed { index, grapeIndex ->\n val grapeAmount = grapes[grapeIndex]\n if (grapeAmount >= need) {\n grapes[grapeIndex] -= need\n peopleNeeds[personIndex] = 0\n } else {\n grapes[grapeIndex] = 0\n peopleNeeds[personIndex] -= grapeAmount\n }\n }\n\n if (peopleNeeds[personIndex] > 0 ) {\n return false\n }\n }\n\n return true\n\n}\n"}, {"source_code": "fun main() {\n val (andrew, dimitry, michael) = readLine()!!.split(\" \").map(Integer::valueOf)\n var (green, purple, black) = readLine()!!.split(\" \").map(Integer::valueOf)\n var a = false\n var b = false\n var c = false\n\n if (green >= andrew) {\n green -= andrew\n a = true\n }\n\n if (green + purple >= dimitry) {\n var remaining = dimitry\n if (remaining - green >= 0) {\n val removed = green\n remaining -= green\n green -= removed\n\n }\n\n if (remaining != 0 && purple >= remaining) {\n val removed = remaining\n purple -= removed\n remaining = 0\n }\n\n if (remaining == 0) {\n b = true\n }\n }\n\n if (black + green + purple >= michael) {\n c = true\n }\n\n if (a && b && c) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(\" \").map {it.toInt()}\n val (a, b, c) = readLine()!!.split(\" \").map {it.toInt()}\n if (x > a) {\n print(\"NO\")\n return\n }\n val r = a - x\n if (y > r + b) {\n print(\"NO\")\n return\n }\n if (z > c) {\n print(\"NO\")\n return\n }\n print(\"YES\")\n}"}, {"source_code": "import kotlin.math.min\n\nfun main(){\n var (a, d, m) = readInts()\n var (g, p, b) = readInts()\n\n if (g < a) {\n println(\"NO\")\n return\n }\n g -= a\n\n if (g+p < d) {\n println(\"NO\")\n return\n }\n\n d -= g\n g = min(0, g-p)\n p -= d\n\n if (g+p+b < m) {\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n}\n\n\nprivate fun readLn(): String = readLine()!!\nprivate fun readInt(): Int = readLn().toInt()\nprivate fun readStrings(): List = readLn().split(\" \")\nprivate fun readInts(): List = readStrings().map { it.toInt() }\nprivate fun readLines(n: Int): List = (0 until n).map { readLn() }\nprivate fun readIntLines(n: Int): List = readLines(n).map { it.toInt() }\nprivate fun String.isPalindrome(): Boolean = this == this.reversed()\nprivate fun String.containsSameChar(): Boolean = this.toCharArray().groupBy { it }.size == 1\nprivate fun String.rotate(n: Int): String = drop(n % length) + take(n % length)\n"}, {"source_code": "fun main( args : Array) {\n\n val (x,y,z)=readLine()!!.split(\" \").map{it.toInt()}\n var (a,b,c)=readLine()!!.split(\" \").map{it.toInt()}\n\n\n if (x<=a){\n a-=x\n if (y<=a+b){\n c=c+a+b-y\n }else{\n println(\"NO\")\n }\n if (z>c){\n println(\"NO\")\n }\n println(\"YES\")\n }else{\n println(\"NO\")\n }\n\n}"}, {"source_code": "fun main() {\n val targetGrapes = readLine()!!\n val nGrapes = readLine()!!\n println(getGoodString(targetGrapes.split(\" \"), nGrapes.split(\" \")))\n}\n\nfun getGoodString(targetGrapes: List, nGrapes: List): String {\n val targetAndrew = targetGrapes[0].toInt()\n val targetDmitry = targetGrapes[1].toInt()\n val targetMichael = targetGrapes[2].toInt()\n var nGreen = nGrapes[0].toInt()\n val nPurple = nGrapes[1].toInt()\n val nBlack = nGrapes[2].toInt()\n if (nGreen < targetAndrew) return \"NO\"\n nGreen -= targetAndrew\n if (nGreen + nPurple < targetDmitry) return \"NO\"\n val remaining = nGreen + nPurple + nBlack - targetDmitry\n if (remaining < targetMichael) return \"YES\"\n return \"NO\"\n}"}, {"source_code": "fun main(args : Array) {\n\n val NT = 1//readLine()?.toInt() ?: 0\n\n\n for(test in 1..NT){\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n val (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n val ok = a >= x && a + b >= x + y && a + b + c >= z\n println(if(ok)\"YES\" else \"NO\")\n }\n\n}"}, {"source_code": "fun main() {\n val (a, d, m) = readLine()!!.split(' ').map(String::toInt)\n val (g, v, b) = readLine()!!.split(' ').map(String::toInt)\n\n //a - g\n //d - g v\n //m - g v b\n\n var g1 = g\n var v1 = v\n val a1: Int\n val d1: Int\n\n val m1 = m - b\n\n //misha check\n if (m1 > 0) {\n v1 = v - m1\n if (v1 < 0) {\n print(\"NO\")\n } else {\n //dima check\n d1 = d - v1\n if (d1 > 0) {\n g1 = g - d1\n if (g1 < 0) {\n print(\"NO\")\n } else {\n //g1 - зеленые остались\n //andrew check\n a1 = a - g1\n if (a1 > 0) {\n print(\"NO\")\n } else {\n print(\"YES\")\n }\n }\n }\n }\n } else {\n //dima check\n d1 = d - v1\n if (d1 > 0) {\n g1 = g - d1\n if (g1 < 0) {\n print(\"NO\")\n } else {\n //g1 - зеленые остались\n //andrew check\n a1 = a - g1\n if (a1 > 0) {\n print(\"NO\")\n } else {\n print(\"YES\")\n }\n }\n }else{\n //andrew check\n a1 = a - g1\n if (a1 > 0) {\n print(\"NO\")\n } else {\n print(\"YES\")\n }\n }\n }\n}\n\n"}, {"source_code": "import java.util.Scanner;\n\nfun main() {\n with(Scanner(System.`in`)) {\n var x = nextInt()\n var y = nextInt()\n var z = nextInt()\n var a = nextInt() // green\n var b = nextInt() // purple\n var c = nextInt() // black\n a = a - x\n if (a < 0) {\n println(\"NO\")!!\n return\n }\n if (b >= y) {\n b = b - y\n y = 0\n } else {\n y = y - b\n b = 0\n }\n if (c >= y) {\n c = c - y\n y = 0\n } else {\n y = y - c\n c = 0\n }\n if (y > 0) {\n println(\"NO\")!!\n return\n }\n if (a + b + c >= z) {\n println(\"YES\")!!\n } else {\n println(\"NO\")!!\n }\n }\n}"}, {"source_code": "fun main() {\n println(\n if (gotGrapes()) { \"YES\" } else { \"NO\" }\n )\n}\n\nfun gotGrapes() : Boolean {\n var (andrew, dimitry, michal) = readLine()!!.split(\" \").map(String::toInt)\n var (green, purple, black) = readLine()!!.split(\" \").map(String::toInt)\n\n green -= andrew\n\n if (green < 0) return false\n\n val i = kotlin.math.min(dimitry, green)\n dimitry -= i\n green -= i\n purple - dimitry\n\n if (purple < 0) return false\n\n return (green + purple + black) >= michal\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val (x, y, z) = scan.nextLine().split(\" \").map { it.toInt() }\n var (a, b, c) = scan.nextLine().split(\" \").map { it.toInt() }\n\n if (a < x) {\n println(\"NO\")\n return\n }\n\n a -= x // 3\n\n var greenAndPurple = a + b\n\n if(y < greenAndPurple) {\n println(\"NO\")\n return\n }\n\n greenAndPurple -= y\n\n val allGrapes = greenAndPurple + z\n if(allGrapes < z) {\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n}"}, {"source_code": "\nfun main(args : Array) {\n\n val NT = 1//readLine()?.toInt() ?: 0\n\n\n for(test in 1..NT){\n var (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n var (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n var ok = true\n a -= x\n if(a<0)ok = false\n y -= a\n if(y > 0)b-=y\n if(b < 0)ok = false\n z -= a + b\n c -= z\n if( c < 0)ok = false\n println(if(ok)\"YES\" else \"NO\")\n }\n\n}"}, {"source_code": "fun main() {\n val require = readLine()!!.split(\" \").map { it.toInt() }.toMutableList()\n val exist = readLine()!!.split(\" \").map { it.toInt() }.toMutableList()\n\n if (require[0] > exist[0]) {\n println(\"NO\"); return\n } else exist[1] += exist[0] - require[0]\n\n if (require[1] > exist[1]) {\n println(\"NO\"); return\n } else exist[2] += exist[1] - require[1]\n\n if(require[2] <= exist[2]) println(\"YES\")\n}"}, {"source_code": "\nconst val GREEN = 0\nconst val PURPLE = 1\nconst val BLACK = 2\nconst val ANDREW = 0\nconst val DIMITRY = 1\nconst val MICHAEL = 2\nfun main() {\n val request = readLine()!!.split(\" \").map { it.toInt() }\n val box = readLine()!!.split(\" \").map { it.toInt() }\n\n var green = box[GREEN]\n green -= request[ANDREW]\n\n if(green < 0){\n println(\"NO\")\n return\n }\n\n var greenAndPurple = box[PURPLE] + green\n greenAndPurple -= request[DIMITRY]\n\n if (greenAndPurple < 0)\n println(\"NO\")\n else if (greenAndPurple + request[BLACK] >= request[MICHAEL])\n println(\"YES\")\n\n\n}\n"}, {"source_code": "\nfun good (a: CharArray) : Int {\n\n for (i in 0..a.size-1) {\n if (a[i] != a[a.size - i - 1])\n return 1\n }\n return 0\n}\n\nfun taskC() {\n var t = readLine()!!.toInt()\n while (t-- > 0) {\n var a = readLine()!!.toString()\n var arr = a.toCharArray()\n arr.sort()\n if (good(arr) == 1)\n println(arr.joinToString(\"\"))\n else\n println(-1)\n }\n}\nfun taskD() {\n var a = readLine()!!.map {it.toInt()}\n var b = readLine()!!.map {it.toInt()}\n var sum = 0\n for (i in 0..2) {\n sum += b[i]\n if (sum >= a[i]) {\n sum -= a[i]\n }\n else {\n print(\"NO\")\n return\n }\n }\n print(\"YES\")\n}\n\nfun main()\n{\n taskD()\n return\n\n}\nfun taskB() {\n var (a, b, c) = readLine()!!.split(\" \").map{it.toInt()}\n var mn = Math.min (a, Math.min (b-1, c-2))\n print(mn + mn + 1 + mn + 2)\n}"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n val (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n if (x > a || x + y > a + b || z > c) println(\"NO\") else println(\"YES\")\n}\n"}, {"source_code": "const val GREEN = 0\nconst val PURPLE = 1\nconst val BLACK = 2\nconst val ANDREW = 0\nconst val DIMITRY = 1\nconst val MICHAEL = 2\nfun main() {\n val request = readLine()!!.split(\" \").map { it.toInt() }\n val box = readLine()!!.split(\" \").map { it.toInt() }\n\n var green = box[GREEN]\n green -= request[ANDREW]\n\n var greenAndPurple = box[PURPLE] + green\n greenAndPurple -= request[DIMITRY]\n\n if (green < 0 || greenAndPurple < 0)\n println(\"NO\")\n else if (green + greenAndPurple + request[BLACK] >= request[MICHAEL])\n println(\"YES\")\n\n\n}\n"}, {"source_code": "\nfun main(args: Array) {\n val (andrew, dmitry, mischal) = readLine()!!.map { it.toInt() }\n val (green, purple, black) = readLine()!!.map { it.toInt() }\n\n if (green < andrew) {\n println(\"NO\")\n return\n }\n val remainGreen = green - andrew\n if (remainGreen + purple < dmitry) {\n println(\"NO\")\n return\n }\n if (green + purple + black < andrew + dmitry + mischal) {\n println(\"NO\")\n return\n }\n println(\"YES\")\n}"}, {"source_code": "\nfun main() {\n var (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n var (green, purple, black) = readLine()!!.split(\" \").map { it.toInt() }\n\n var condition = true\n\n if (green < x) {\n condition = false\n }\n else {\n green -= x\n }\n\n if (green + purple < y) {\n condition = false\n }\n else {\n if (y >= purple) {\n y -= purple\n }\n else {\n purple -= y\n }\n\n if (y >= 0) {\n green -= y\n }\n }\n\n if (purple + green + black < z) {\n condition = false\n }\n\n println(if (condition) \"YES\" else \"NO\")\n}"}, {"source_code": "// https://kotlinlang.org/docs/tutorials/competitive-programming.html\n// https://stackoverflow.com/questions/41283393/reading-console-input-in-kotlin\n\nprivate fun readln() = readLine()!!\nprivate fun readlnByte() = readln().toByte()\nprivate fun readlnShort() = readln().toShort()\nprivate fun readlnInt() = readln().toInt()\nprivate fun readlnLong() = readln().toLong()\nprivate fun readlnFloat() = readln().toFloat()\nprivate fun readlnDouble() = readln().toDouble()\nprivate fun readlnBigInt(radix: Int = 10) = readln().toBigInteger(radix)\nprivate fun readlnBigDecimal() = readln().toBigDecimal()\n\nprivate fun lineSequence(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.constrainOnce().take(limit)\nprivate fun readlnStrings() = readln().split(' ')\nprivate fun readlnBytes() = readlnStrings().map { it.toByte() }\nprivate fun readlnShorts() = readlnStrings().map { it.toShort() }\nprivate fun readlnInts() = readlnStrings().map { it.toInt() }\nprivate fun readlnLongs() = readlnStrings().map { it.toLong() }\nprivate fun readlnFloats() = readlnStrings().map { it.toFloat() }\nprivate fun readlnDoubles() = readlnStrings().map { it.toDouble() }\n\nprivate fun readByteArray() = readlnStrings().run { ByteArray(size) { get(it).toByte() } }\nprivate fun readShortArray() = readlnStrings().run { ShortArray(size) { get(it).toShort() } }\nprivate fun readIntArray() = readlnStrings().run { IntArray(size) { get(it).toInt() } }\nprivate fun readLongArray() = readlnStrings().run { LongArray(size) { get(it).toLong() } }\nprivate fun readFloatArray() = readlnStrings().run { FloatArray(size) { get(it).toFloat() } }\nprivate fun readDoubleArray() = readlnStrings().run { DoubleArray(size) { get(it).toDouble() } }\n\nprivate fun readlnByteArray(n: Int) = ByteArray(n) { readlnByte() }\nprivate fun readlnShortArray(n: Int) = ShortArray(n) { readlnShort() }\nprivate fun readlnIntArray(n: Int) = IntArray(n) { readlnInt() }\nprivate fun readlnLongArray(n: Int) = LongArray(n) { readlnLong() }\nprivate fun readlnFloatArray(n: Int) = FloatArray(n) { readlnFloat() }\nprivate fun readlnDoubleArray(n: Int) = DoubleArray(n) { readlnDouble() }\n\nprivate fun readByteArray2d(rows: Int, cols: Int) = Array(rows) { readByteArray().also { require(it.size == cols) } }\nprivate fun readShortArray2d(rows: Int, cols: Int) = Array(rows) { readShortArray().also { require(it.size == cols) } }\nprivate fun readLongArray2d(rows: Int, cols: Int) = Array(rows) { readLongArray().also { require(it.size == cols) } }\nprivate fun readIntArray2d(rows: Int, cols: Int) = Array(rows) { readIntArray().also { require(it.size == cols) } }\nprivate fun readFloatArray2d(rows: Int, cols: Int) = Array(rows) { readFloatArray().also { require(it.size == cols) } }\nprivate fun readDoubleArray2d(rows: Int, cols: Int) =\n Array(rows) { readDoubleArray().also { require(it.size == cols) } }\n\n\nprivate fun isWhiteSpace(c: Char) = c in \" \\r\\n\\t\"\n\n// JVM-only targeting code follows next\n\n// readString() via sequence is still slightly faster than Scanner\nprivate fun readString() = generateSequence { System.`in`.read().toChar() }\n .dropWhile { isWhiteSpace(it) }.takeWhile { !isWhiteSpace(it) }.joinToString(\"\")\n\nprivate fun readByte() = readString().toByte()\nprivate fun readShort() = readString().toShort()\nprivate fun readInt() = readString().toInt()\nprivate fun readLong() = readString().toLong()\nprivate fun readFloat() = readString().toFloat()\nprivate fun readDouble() = readString().toDouble()\nprivate fun readBigInt(radix: Int = 10) = readString().toBigInteger(radix)\nprivate fun readBigDecimal() = readString().toBigDecimal()\n\nprivate fun readBytes(n: Int) = generateSequence { readByte() }.take(n)\nprivate fun readShorts(n: Int) = generateSequence { readShort() }.take(n)\nprivate fun readInts(n: Int) = generateSequence { readInt() }.take(n)\nprivate fun readLongs(n: Int) = generateSequence { readLong() }.take(n)\nprivate fun readFloats(n: Int) = generateSequence { readFloat() }.take(n)\nprivate fun readDoubles(n: Int) = generateSequence { readDouble() }.take(n)\n\nprivate fun printIntArray(a: IntArray) {\n println(a.joinToString(\", \"))\n}\n\nprivate fun printLongArray(a: LongArray) {\n println(a.joinToString(\", \"))\n}\n\nprivate fun printDoubleArray(a: DoubleArray) {\n println(a.joinToString(\", \"))\n}\n\nprivate fun printFloatArray(a: FloatArray) {\n println(a.joinToString(\", \"))\n}\n\nprivate fun printStringArray(a: Array) {\n println(a.joinToString(\", \"))\n}\n\nfun main() {\n val (x, y, z) = readlnInts()\n val (a, b, c) = readlnInts()\n\n if (a >= x && a + b >= x + y && a + b + c > x + y + z) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}"}, {"source_code": "import java.io.*\nimport java.lang.Math.max\nimport java.lang.Math.min\nimport java.lang.StringBuilder\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n// val n = br.readLine()!!.toInt()\n\n// repeat(n)\n// {\n val (x,y,z) = br.readLine()!!.split(' ').map{it.toInt()}\n val (a,b,c) = br.readLine()!!.split(' ').map{it.toInt()}\n\n// val s = br.readLine()\n// solve1(a)\n// solve2(a,b,c)\n// solve3(s)\n solve4(x,y,z,a,b,c)\n// }\n\n}\n\nfun solve4(x: Int, y: Int, z: Int, a: Int, b: Int, c: Int) {\n // x -> only a\n // y -> not c\n // z -> anything\n\n var ret = \"YES\"\n\n if(x > a)\n {\n ret = \"NO\"\n }\n else\n {\n var newa = a - x\n\n var newz = max( z - c, 0)\n\n var newc = if(z < c) c - z else 0\n\n val left = b + newa + newc\n\n if(y + newz > left) ret = \"NO\"\n }\n\n println(ret)\n}\n\n\nfun solve3(s: String) {\n\n var ns = s.toCharArray().sorted()\n var sb = StringBuilder()\n for(ch in ns)\n {\n sb.append(ch)\n }\n var nss = sb.toString()\n\n if(nss.reversed() == nss)\n {\n println(-1)\n }\n else\n {\n println(nss)\n }\n}\n\nfun solve2(a: Int, b: Int, c: Int) {\n\n var m = min(a, b-1)\n m = min(m, c-2)\n println(3 * m + 3)\n}\n\nfun solve1(num : Int)\n{\n println(num/2)\n}\n\n\n"}, {"source_code": "import java.lang.Integer.min\n\nfun main() {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n var (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n a -= x\n if (a < 0) {\n println(\"NO\")\n return\n }\n b -= y - a\n if (b < 0) {\n println(\"NO\")\n return\n }\n c -= z - b - a\n if (c < 0) {\n println(\"NO\")\n return\n }\n println(\"YES\")\n}\n"}, {"source_code": "\nimport java.util.Scanner\n\nfun main(args: Array) {\n exercise4()\n}\n\nfun exercise4(){\n val reader = Scanner(System.`in`)\n val andrew = reader.nextInt()\n var dimitri = reader.nextInt()\n val michael = reader.nextInt()\n\n var green = reader.nextInt()\n var purple = reader.nextInt()\n var black = reader.nextInt()\n\n green -= andrew\n if (green < 0){\n println(\"NO\")\n } else {\n if (green >= dimitri){\n green -= dimitri\n } else {\n dimitri -= green\n purple -= dimitri\n green = 0\n if (purple < 0){\n println(\"NO\")\n } else {\n if (green + purple + black > michael) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n }\n }\n }\n\n}"}, {"source_code": "//package com.happypeople.codeforces.c1114\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\n\nfun main(args: Array) {\n try {\n A1114().run()\n } catch (e: Throwable) {\n println(\"\")\n e.printStackTrace()\n }\n}\n\nclass A1114 {\n fun run() {\n val sc = Scanner(systemIn())\n val hGreen=sc.nextInt()\n val hNotBlack=sc.nextInt()\n val hAny=sc.nextInt()\n var green=sc.nextInt()\n var purple=sc.nextInt()\n var black=sc.nextInt()\n\n val m1=hGreen<=green\n green+=hGreen\n val m2=hNotBlack<=green+purple\n val m3=hAny<=green+purple+black-hNotBlack\n val ans =m1 and m2 and m3\n if(ans)\n println(\"YES\")\n else\n println(\"NO\")\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}\n"}, {"source_code": "\nconst val GREEN = 0\nconst val PURPLE = 1\nconst val BLACK = 2\nconst val ANDREW = 0\nconst val DIMITRY = 1\nconst val MICHAEL = 2\nfun main() {\n val request = readLine()!!.split(\" \").map { it.toInt() }\n val box = readLine()!!.split(\" \").map { it.toInt() }\n\n if (request[ANDREW] > box[GREEN])\n print(\"NO\")\n else {\n val leftOfGreen = box[GREEN] - request[ANDREW]\n\n val leftOfGreenAndPurple = leftOfGreen + box[PURPLE]\n\n if (leftOfGreenAndPurple < request[DIMITRY]) {\n println(\"NO\")\n } else {\n\n val sumOfAllLeft = leftOfGreenAndPurple - request[DIMITRY] + box[BLACK]\n\n if (sumOfAllLeft < request[MICHAEL]) {\n println(\"YES\")\n } else {\n print(\"NO\")\n }\n\n }\n\n }\n\n}\n"}, {"source_code": "import java.util.Scanner\nimport java.util.Arrays\n\nfun main(args: Array) {\n\tval reader = Scanner(System.`in`)\n\n\tvar x:Int = reader.nextInt()\n \tvar y:Int = reader.nextInt()\n \tvar z:Int = reader.nextInt()\n \n \tvar a:Int = reader.nextInt()\n \tvar b:Int = reader.nextInt()\n \tvar c:Int = reader.nextInt()\n\t\n\tvar aux:Int \n\n \tif(a>=x){\n\t\ta-=x;\n\t\taux=a+c;\n\t\tif(aux>=y){\n\t\t\taux-=y;\n\t\t\taux+=b;\n\t\t\tif(aux>=z){\n\t\t\t\tprintln(\"YES\");\n\t\t\t}\n\t\t\telse{\n\t\t\t\tprintln(\"NO\");\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tprintln(\"NO\");\n\t\t}\n \t}\n\telse{\n\t\tprintln(\"NO\");\n\t}\n}\n"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n val (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n if (x>a) println(\"NO\")\n if (x+y>a+b) println(\"NO\")\n if (x+y+z>a+b+c) println(\"NO\") else println(\"YES\")\n}"}, {"source_code": "fun main() {\n var in1 = readLine()!!\n var in2 = readLine()!!\n var x = in1[0].toInt()\n var y = in1[1].toInt()\n var z = in1[2].toInt()\n var a = in2[0].toInt()\n var b = in2[1].toInt()\n var c = in2[2].toInt()\n a -= x\n if (a < 0){\n println(\"NO\")\n }else{\n a += b-y\n if (a < 0){\n println(\"NO\")\n }else{\n a += c-z\n if (a < 0){\n println(\"NO\")\n }else{\n println(\"YES\")\n }\n }\n }\n}\n"}, {"source_code": "\nconst val GREEN = 0\nconst val PURPLE = 1\nconst val BLACK = 2\nconst val ANDREW = 0\nconst val DIMITRY = 1\nconst val MICHAEL = 2\nfun main() {\n val request = readLine()!!.split(\" \").map { it.toInt() }\n val box = readLine()!!.split(\" \").map { it.toInt() }\n\n if (request[ANDREW] > box[GREEN])\n print(\"NO\")\n else {\n val leftOfGreen = box[GREEN] - request[ANDREW]\n\n val leftOfGreenAndPurple = leftOfGreen + box[PURPLE]\n\n if (leftOfGreenAndPurple < request[DIMITRY]) {\n println(\"NO\")\n } else {\n\n val sumOfAllLeft = leftOfGreenAndPurple - request[DIMITRY] + box[BLACK]\n\n if (sumOfAllLeft < request[MICHAEL]) {\n println(\"YES\")\n } else {\n print(\"NO\")\n }\n\n }\n\n }\n\n}\n"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n val (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n if (x > a || x + y > a + b || z > c) println(\"NO\") else println(\"YES\")\n}\n"}, {"source_code": "import kotlin.math.min\n\nfun readThree() = readLine()!!.split(\" \").map { it.toInt() }\nfun main() {\n var (andrew, dmitry, michal) = readThree()\n var (green, purple, black) = readThree()\n\n green -= andrew\n\n if (green < 0) println(\"NO\")\n else {\n val greenForDmitry = min(green, dmitry)\n green -= greenForDmitry\n dmitry -= greenForDmitry\n\n purple -= dmitry\n when {\n purple < 0 -> println(\"NO\")\n green + purple + black <= michal -> println(\"NO\")\n else -> println(\"YES\")\n }\n }\n}"}, {"source_code": "import java.util.Scanner\n\nval no = \"NO\"\nval yes = \"YES\"\n\nfun main() {\n val scanner = Scanner(System.`in`)\n\n val and = scanner.nextInt()\n var dm = scanner.nextInt()\n val mi = scanner.nextInt()\n\n var green = scanner.nextInt()\n var purple = scanner.nextInt()\n val black = scanner.nextInt()\n\n if (and > green) {\n println(no)\n return\n }\n green -= and\n if (dm > green + purple) {\n println(no)\n return\n }\n if (dm > green) {\n dm -= green\n green = 0\n purple -= dm\n } else {\n dm -= green\n }\n\n println(if (green + purple + black > mi) yes else no)\n}"}, {"source_code": "import java.util.*\nfun main() {\n with(Scanner(System.`in`)) {\n val x = nextInt()\n val y = nextInt()\n val z = nextInt()\n val g = nextInt()\n val p = nextInt()\n val b = nextInt()\n when {\n g < x || x + y < g + p || x + y + z < g + p + b -> println(\"NO\")\n else -> println(\"YES\")\n }\n }\n}"}, {"source_code": "import java.util.*\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main(args: Array) {\n\n var(x,y,z) =readInts()\n var(green,purple,black) =readInts()\n\n var temp:Int\n\n temp=green-x\n if(temp<0){\n println(\"NO\")\n return\n }else{\n green-x\n }\n temp=(green+purple)-y\n if(temp<0){\n println(\"NO\")\n return\n }else{\n (green+purple)-y\n }\n\n temp=(green+purple+black)-z\n\n if(temp<0){\n println(\"NO\")\n return\n }\n println(\"YES\")\n\n\n}\n\n"}, {"source_code": "fun main(args: Array) {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n var (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n\n if (x > a) {\n print(\"NO\")\n return\n }\n a -= x\n if (y > b + c) {\n print(\"NO\")\n return\n }\n if (z > a + (b + c - y)) {\n print(\"NO\")\n } else {\n print(\"YES\")\n }\n }"}, {"source_code": "//package org.korifey.kalgo.codeforces.kotlinheroes\n\nimport java.util.*\nimport kotlin.math.min\nimport kotlin.reflect.KMutableProperty0\n\n\nfun exit(r: Boolean) {\n println(if (r) \"YES\" else \"NO\")\n}\n\nfun subtractMin(a: KMutableProperty0, b: KMutableProperty0) {\n val m = min(a.get(), b.get())\n\n a.set(a.get() - m)\n b.set(b.get() - m)\n}\n\n\nvar a : Int = 0\nvar b : Int = 0\nvar c : Int = 0\n\n\nvar ax : Int = 0\nvar bx : Int = 0\nvar cx : Int = 0\n\n\nfun main() {\n\n val scanner = Scanner(System.`in`)\n a = scanner.nextInt()\n b = scanner.nextInt()\n c = scanner.nextInt()\n\n ax = scanner.nextInt()\n bx = scanner.nextInt()\n cx = scanner.nextInt()\n\n\n subtractMin(::a, ::ax)\n\n if (a > 0)\n return exit(false)\n\n subtractMin(::b, ::ax)\n subtractMin(::b, ::bx)\n\n if (b > 0)\n return exit(false)\n\n\n subtractMin(::c, ::ax)\n subtractMin(::c, ::bx)\n subtractMin(::c, ::cx)\n\n\n if (b > 0)\n return exit(false)\n\n exit(true)\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val scanner = Scanner(System.`in`)\n var x = scanner.nextInt()\n var y = scanner.nextInt()\n var z = scanner.nextInt()\n\n var a = scanner.nextInt()\n var b = scanner.nextInt()\n var c = scanner.nextInt()\n\n a -= x\n if (a < 0) {\n println(\"NO\")\n return\n }\n\n if (a > 0) {\n a -= y\n if (a < 0) {\n y = a * -1\n }\n }\n\n b -= y\n if (b < 0) {\n println(\"NO\")\n return\n }\n\n if (b > 0) {\n b -= z\n if (b < 0) {\n z = b * -1\n }\n }\n\n c -= z\n if (c < 0) {\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val scanner = Scanner(System.`in`)\n var x = scanner.nextInt()\n var y = scanner.nextInt()\n var z = scanner.nextInt()\n\n var a = scanner.nextInt()\n var b = scanner.nextInt()\n var c = scanner.nextInt()\n\n a -= x\n if (a < 0) {\n println(\"NO\")\n return\n }\n\n if (a > 0) {\n a -= y\n if (a < 0) {\n y = a * -1\n } else {\n y = 0\n }\n }\n\n b -= y\n if (b < 0) {\n println(\"NO\")\n return\n }\n\n if (b > 0) {\n b -= z\n if (b < 0) {\n z = b * -1\n } else {\n z = 0\n }\n }\n\n c -= z\n if (c < 0) {\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n}"}, {"source_code": "import java.util.*\n\nfun main() = with(Scanner(System.`in`)) {\n val andrew = nextInt()\n val dmitry = nextInt()\n val michel = nextInt()\n\n var green = nextInt()\n var purple = nextInt()\n var black = nextInt()\n var total = green + purple + black\n\n if (green < andrew) {\n println(\"NO\")\n return@with\n }\n green -= andrew\n\n if (green + purple < dmitry) {\n println(\"NO\")\n return@with\n }\n total -= dmitry\n\n if (total < michel) {\n println(\"NO\")\n return@with\n }\n\n println(\"YES\")\n}\n\n"}, {"source_code": "import java.util.Scanner\n\nfun main() {\n val sc = Scanner(System.`in`)\n\n var x:Int = sc.nextInt()\n var y:Int = sc.nextInt()\n var z:Int = sc.nextInt()\n var a:Int = sc.nextInt()\n var b:Int = sc.nextInt()\n var c:Int = sc.nextInt()\n \n a -= x\n if (a > 0) {\n if (a + b >= y)\n if (a + b + c >= y + z)\n println(\"YES\")\n else\n println(\"NO\")\n else\n println(\"NO\")\n }\n else\n println(\"NO\")\n}"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(' ').map { it.toInt() }\n val (a, b, c) = readLine()!!.split(' ').map { it.toInt() }\n if (a >= x && a - x + b >= y && y - (a - x + b) + c >= z) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}"}, {"source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val xyz = readLine()!!.split(' ')\n val abc = readLine()!!.split(' ')\n\n val x = xyz[0].toInt() // only a\n val y = xyz[1].toInt() // not c\n val z = xyz[2].toInt() // any\n\n val a = abc[0].toInt()\n val b = abc[1].toInt()\n val c = abc[2].toInt()\n\n val a0 = a - x\n\n if (a0 < 0) {\n println(\"NO\")\n return\n }\n\n val y0 = max(a0 - y, 0)\n val a1 = a0 - y0\n val b0 = b - (y - y0)\n\n if (b0 < 0) {\n println(\"NO\")\n return\n }\n\n val c0 = (a1 + b0 + c) - z\n\n if (c0 < 0) {\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val (x, y, z) = scan.nextLine().split(\" \").map { it.toInt() }\n var (a, b, c) = scan.nextLine().split(\" \").map { it.toInt() }\n\n if (x > a) {\n println(\"NO\")\n return\n }\n\n a -= x // 3\n\n var greenAndPurple = a + b\n\n if(y > greenAndPurple) {\n println(\"NO\")\n return\n }\n\n greenAndPurple -= y\n\n val allGrapes = greenAndPurple + z\n if(z > allGrapes) {\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n}"}, {"source_code": "fun anyGrapes(want:List, grapes:List){\n if(want[0].toInt() > grapes[0].toInt()){\n println(\"NO\")\n }\n else {\n val dymiCurr = want[1].toInt()\n val michCurr = want[2].toInt() - grapes[2].toInt() //Michael gets all black grapes\n val remainGrPu = (grapes[0].toInt() + grapes[1].toInt()) - (want[0].toInt()) //remaining green and purple grapes\n\n if ( remainGrPu >= 0 &&((dymiCurr+michCurr) - remainGrPu) > 0){\n println(\"NO\")\n return\n }\n println(\"YES\")\n }\n}\n\n\nfun main(args:Array){\n val want = readLine()!!.split(\" \")\n val grapes = readLine()!!.split(\" \")\n anyGrapes(want, grapes)\n}"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(\" \").map(String::toInt)\n val (a, b, c) = readLine()!!.split(\" \").map(String::toInt)\n if (a >= x && a + b >= x + y && a + c + c >= x + y + z) print(\"YES\") else print(\"NO\")\n}\n"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n val (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n if (x > a || x + y > a + b || z > c) println(\"NO\") else println(\"YES\")\n}\n"}, {"source_code": "fun main() {\n val want = readLine()!!.split(\" \").map{it.toInt()}\n val box = readLine()!!.split(\" \").map{it.toInt()}\n\n\n when {\n (box[0]+box[1]+box[2]-want[0]-want[1]) < want[2] -> println(\"NO\")\n box[0] println(\"NO\")\n box[0]-want[0]+box[2]-want[2]+box[1] println(\"NO\")\n else -> println(\"YES\")\n }\n\n}"}, {"source_code": " fun main(args:Array){\n val (a, b, c) = readLine()!!.split(' ')\n var x1:Int = a.toInt()\n var y1:Int = b.toInt()\n var z1:Int = c.toInt()\n val (a1, b1, c1) = readLine()!!.split(' ')\n var x:Int = a1.toInt()\n var y:Int = b1.toInt()\n var z:Int = c1.toInt()\n var flag = 0\n if(x1 <= x && flag == 0) {x -= x1}\n else {flag = 1}\n \n if(y1 <= (y + x) && flag == 0) \n {if(y1 <= y) y -= y1\n else y = 0; x -= (y1 - y)}\n else {flag = 1}\n \n if(z1 <= (x + y + z) && flag == 0) {flag = 0}\n else {flag = 1} \n \n if(flag == 0) {println(\"YES\")}\n else {println(\"NO\")}\n}"}, {"source_code": "import java.util.Scanner\nimport java.util.Arrays\n\nfun main(args: Array) {\n\tval reader = Scanner(System.`in`)\n\n\tvar x:Int = reader.nextInt()\n \tvar y:Int = reader.nextInt()\n \tvar z:Int = reader.nextInt()\n \n \tvar a:Int = reader.nextInt()\n \tvar b:Int = reader.nextInt()\n \tvar c:Int = reader.nextInt()\n\t\n\tvar aux:Int \n\n \tif(a>=x){\n\t\ta-=x;\n\t\taux=a+c;\n\t\tif(aux>=y){\n\t\t\taux-=y;\n\t\t\taux+=b;\n\t\t\tif(aux>=z){\n\t\t\t\tprintln(\"YES\");\n\t\t\t}\n\t\t\telse{\n\t\t\t\tprintln(\"NO\");\n\t\t\t}\n\t\t}\n\t\telse{\n\t\t\tprintln(\"NO\");\n\t\t}\n \t}\n\telse{\n\t\tprintln(\"NO\");\n\t}\n}\n"}, {"source_code": "// contest/1171/problem/B Kotlin heroes training done\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n var canDo: Boolean\n val xyz = readInts()\n var (x,y,z) = xyz\n val abc = readInts()\n var (a,b,c) = abc\n if (a < x) {\n canDo = false\n } else {\n a -= x\n if (a+b < y) {\n canDo = false\n } else {\n if (a > y) {\n y -= a\n } else {\n b -= (y-a)\n a = 0\n }\n canDo = (a+b+c) >= z\n }\n }\n\n println( if (canDo) \"YES\" else \"NO\" )\n}\n"}, {"source_code": "\nfun main(args: Array) {\n val (andrew, dmitry, mischal) = readLine()!!.map { it.toInt() }\n val (green, purple, black) = readLine()!!.map { it.toInt() }\n\n if (green < andrew) {\n println(\"NO\")\n return\n }\n val remainGreen = green - andrew\n if (remainGreen + purple < dmitry) {\n println(\"NO\")\n return\n }\n val remain = remainGreen + purple - andrew\n if (remain + black < mischal) {\n println(\"NO\")\n return\n }\n println(\"YES\")\n}"}, {"source_code": "import kotlin.math.max\n\nfun main() {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n val (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n\n if (x > a) {\n println(\"NO\")\n return\n }\n\n val da1 = a - x\n if (y > da1 + b) {\n println(\"NO\")\n return\n }\n\n val da2 = max(0, da1 - y)\n val db1 = b + da1 - y\n if (z > da2 + db1 + c) {\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun canEat(): Boolean {\n var x = inp.nextInt()\n var y = inp.nextInt()\n var z = inp.nextInt()\n\n var a = inp.nextInt()\n var b = inp.nextInt()\n var c = inp.nextInt()\n\n if (x > a) {\n return false\n }\n a -= x\n x = 0\n\n val canYEatGreen = minOf(y, a)\n a -= canYEatGreen\n y -= canYEatGreen\n\n if (y > b) {\n return false\n }\n b -= y\n y = 0\n\n val canZEatFio = minOf(z, c)\n c -= canZEatFio\n z -= canZEatFio\n\n return c >= z\n}\n\nfun run() {\n val res: String = if (canEat()) \"YES\" else \"NO\"\n out.println(res)\n}\n\nprivate val inp = FastInput()\nprivate val out = FastOutput()\n\nfun main() {\n run()\n out.flush()\n out.close()\n}\n\ninternal class FastInput(private val bufferedReader: BufferedReader) {\n private var tokenizer: StringTokenizer? = null\n\n constructor() : this(System.`in`)\n constructor(stream: InputStream) : this(BufferedReader(InputStreamReader(stream)))\n constructor(file: File) : this(BufferedReader(FileReader(file)))\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(bufferedReader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int = next().toInt()\n fun nextLong(): Long = next().toLong()\n}\n\ninternal class FastOutput constructor(outputStream: OutputStream = System.out) {\n private val bufferedWriter = BufferedWriter(OutputStreamWriter(outputStream))\n\n private fun printOne(obj: T) {\n bufferedWriter.write(\"$obj\")\n }\n\n fun println(obj: T) = bufferedWriter.write(\"$obj\\n\")\n\n fun print(vararg objs: Any) = printd(\"\", *objs)\n\n fun printd(delimiter: String, vararg objs: Any) {\n for (i in 0 until objs.size) {\n printOne(objs[i])\n printOne(delimiter)\n }\n }\n\n fun flush() = bufferedWriter.flush()\n fun close() = bufferedWriter.close()\n}"}, {"source_code": "fun main(){\n var (x, y, z) = readLine()!!.split(\" \").map{ it.toInt() }\n var (a, b, c) = readLine()!!.split(\" \").map{ it.toInt() }\n\n var ok = true\n if(x > a) ok = false\n a -= x\n z -= minOf(z, c)\n if(a + b + c < y + z) ok = false\n\n println(if (ok) \"YES\" else \"NO\")\n\n}"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n val (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n\n val grapesMap = mutableMapOf(\n \"green\" to a,\n \"purple\" to b,\n \"black\" to c\n )\n\n provideAndrew(grapesMap, x)\n provideDmitri(grapesMap, y)\n provideMichal(grapesMap, z)\n if (isValidDistribution(grapesMap)) println(\"YES\") else println(\"NO\")\n}\n\nprivate fun provideAndrew(grapesMap: MutableMap, wanted: Int) {\n grapesMap[\"green\"] = grapesMap[\"green\"]!!.minus(wanted)\n}\n\nprivate fun provideDmitri(grapesMap: MutableMap, wanted: Int) {\n val purple = grapesMap[\"purple\"]!!\n if (wanted <= purple) {\n grapesMap[\"purple\"] = purple.minus(wanted)\n return\n }\n grapesMap[\"purple\"] = 0\n grapesMap[\"green\"] = grapesMap[\"green\"]!!.minus(wanted - purple)\n}\n\nprivate fun provideMichal(grapesMap: MutableMap, wanted: Int) {\n grapesMap[\"black\"] = grapesMap[\"black\"]!!.minus(wanted)\n}\n\nprivate fun isValidDistribution(grapesMap: MutableMap): Boolean {\n return grapesMap.filter { it.value >= 0 }.size == grapesMap.size\n}"}, {"source_code": "import java.util.*\nfun main() {\n with(Scanner(System.`in`)) {\n val x = nextInt()\n val y = nextInt()\n val z = nextInt()\n val g = nextInt()\n val p = nextInt()\n val b = nextInt()\n when {\n g < x || x + y < g + p || x + y + z < g + p + b -> println(\"NO\")\n else -> println(\"YES\")\n }\n }\n}"}, {"source_code": "fun main() {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n val (a, b, c) = readLine()!!.split(\" \").map { it.toInt() }\n if (x>a) println(\"No\")\n if (x+y>a+b) println(\"No\")\n if (x+y+z>a+b+c) println(\"No\") else println(\"Yes\")\n}"}, {"source_code": "\nimport java.util.Scanner\n\nfun main(args: Array) {\n exercise4()\n}\n\nfun exercise4(){\n val reader = Scanner(System.`in`)\n val andrew = reader.nextInt()\n var dimitri = reader.nextInt()\n val michael = reader.nextInt()\n\n var green = reader.nextInt()\n var purple = reader.nextInt()\n var black = reader.nextInt()\n\n green -= andrew\n if (green < 0){\n println(\"NO\")\n } else {\n if (green >= dimitri){\n green -= dimitri\n } else {\n dimitri -= green\n purple -= dimitri\n green = 0\n if (purple < 0){\n println(\"NO\")\n }\n }\n if (green + purple + black >= michael) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n \n }\n\n}"}, {"source_code": "fun isEnough(wish: List, grapes: List) {\n val enough = grapes[0] >= wish[0] &&\n grapes[0] + grapes[1] >= wish[1] &&\n grapes[1] + grapes[1] + grapes[2] >= wish[2]\n println(when(enough) {\n true -> \"YES\"\n else -> \"NO\"\n })\n}\n\nfun main() {\n val wish = readLine()!!.split(\" \").map { it.toInt() }\n val grapes = readLine()!!.split(\" \").map { it.toInt() }\n\n isEnough(wish, grapes)\n}"}, {"source_code": "fun main() {\n val (andrew, dimitry, michael) = readLine()!!.split(\" \").map(Integer::valueOf)\n var (green, purple, black) = readLine()!!.split(\" \").map(Integer::valueOf)\n var a = false\n var b = false\n var c = false\n\n if (green >= andrew) {\n green -= andrew\n a = true\n }\n\n if (green + purple >= dimitry) {\n var remaining = dimitry\n if (remaining - green >= 0) {\n val removed = green\n remaining -= green\n green -= removed\n\n }\n\n if (remaining != 0 && purple >= remaining) {\n val removed = remaining\n purple -= removed\n remaining = 0\n }\n\n if (remaining == 0) {\n b = true\n }\n }\n\n if (black + green + purple >= michael) {\n c = true\n }\n\n if (a && b && c) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}"}], "src_uid": "d54201591f7284da5e9ce18984439f4e"} {"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": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashSet\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val n = ir.nextInt()\n val a = IntArray(n)\n var total: Long = 0\n\n repeat(n) {\n a[it] = ir.nextInt()\n }\n\n Arrays.sort(a)\n\n total += a[n - 1]\n\n for (i in (n - 2) downTo 0) {\n if (a[i] >= a[i + 1])\n a[i] = Math.max((a[i + 1] - 1), 0)\n total += a[i]\n }\n\n pw.print(total)\n\n}\n\nprivate fun sort(array: IntArray, barray: IntArray, low: Int, high: Int) {\n\n var i = low\n var j = high\n val x = array[low + (high - low) / 2]\n\n do {\n while (array[i] < x) ++i\n while (array[j] > x) --j\n if (i <= j) {\n val tmp = array[i]\n array[i] = array[j]\n array[j] = tmp\n\n val pmt = barray[i]\n barray[i] = barray[j]\n barray[j] = pmt\n\n i++\n j--\n }\n } while (i <= j)\n\n if (low < j) sort(array, barray, low, j)\n if (i < high) sort(array, barray, i, high)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "fun main() {\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n readLine()\n val times = readLongs()\n val used = mutableSetOf()\n var sol = 0L\n for (option in times)\n for (i in option downTo 0)\n if (i !in used) {\n used.add(i)\n sol += i\n break\n }\n print(sol)\n}"}], "negative_code": [{"source_code": "import java.util.*\n\nfun main() {\n\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n val a = IntArray(n)\n var total = 0\n\n for (i in 0 until n) a[i] = sc.nextInt()\n\n Arrays.sort(a)\n\n for (i in (n - 1) downTo 1) {\n if (a[i] == a[i - 1]) {\n if (a[i] != 0) a[i - 1]--\n else a[i - 1] = 0\n }\n }\n\n for (i in 0 until n) total += a[i]\n\n print(total)\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashSet\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val n = ir.nextInt()\n val a = IntArray(n)\n var total: Long = 0\n\n repeat(n) {\n a[it] = ir.nextInt()\n }\n\n Arrays.sort(a)\n\n total += a[n - 1]\n\n for (i in (n - 2) downTo 0) {\n if (a[i] == a[i + 1])\n a[i]--\n total += a[i]\n }\n\n pw.print(total)\n\n}\n\nprivate fun sort(array: IntArray, barray: IntArray, low: Int, high: Int) {\n\n var i = low\n var j = high\n val x = array[low + (high - low) / 2]\n\n do {\n while (array[i] < x) ++i\n while (array[j] > x) --j\n if (i <= j) {\n val tmp = array[i]\n array[i] = array[j]\n array[j] = tmp\n\n val pmt = barray[i]\n barray[i] = barray[j]\n barray[j] = pmt\n\n i++\n j--\n }\n } while (i <= j)\n\n if (low < j) sort(array, barray, low, j)\n if (i < high) sort(array, barray, i, high)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashSet\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val n = ir.nextInt()\n val a = IntArray(n)\n var total: Long = 0\n\n repeat(n) {\n a[it] = ir.nextInt()\n }\n\n Arrays.sort(a)\n\n total += a[n - 1]\n\n for (i in (n - 2) downTo 0) {\n if (a[i] >= a[i + 1])\n a[i] = a[i + 1] - 1\n total += a[i]\n }\n\n pw.print(total)\n\n}\n\nprivate fun sort(array: IntArray, barray: IntArray, low: Int, high: Int) {\n\n var i = low\n var j = high\n val x = array[low + (high - low) / 2]\n\n do {\n while (array[i] < x) ++i\n while (array[j] > x) --j\n if (i <= j) {\n val tmp = array[i]\n array[i] = array[j]\n array[j] = tmp\n\n val pmt = barray[i]\n barray[i] = barray[j]\n barray[j] = pmt\n\n i++\n j--\n }\n } while (i <= j)\n\n if (low < j) sort(array, barray, low, j)\n if (i < high) sort(array, barray, i, high)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}], "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f"} {"nl": {"description": "Alice has a lovely piece of cloth. It has the shape of a square with a side of length $$$a$$$ centimeters. Bob also wants such piece of cloth. He would prefer a square with a side of length $$$b$$$ centimeters (where $$$b < a$$$). Alice wanted to make Bob happy, so she cut the needed square out of the corner of her piece and gave it to Bob. Now she is left with an ugly L shaped cloth (see pictures below).Alice would like to know whether the area of her cloth expressed in square centimeters is prime. Could you help her to determine it?", "input_spec": "The first line contains a number $$$t$$$ ($$$1 \\leq t \\leq 5$$$) — the number of test cases. Each of the next $$$t$$$ lines describes the $$$i$$$-th test case. It contains two integers $$$a$$$ and $$$b~(1 \\leq b < a \\leq 10^{11})$$$ — the side length of Alice's square and the side length of the square that Bob wants.", "output_spec": "Print $$$t$$$ lines, where the $$$i$$$-th line is the answer to the $$$i$$$-th test case. Print \"YES\" (without quotes) if the area of the remaining piece of cloth is prime, otherwise print \"NO\". You can print each letter in an arbitrary case (upper or lower).", "sample_inputs": ["4\n6 5\n16 13\n61690850361 24777622630\n34 33"], "sample_outputs": ["YES\nNO\nNO\nYES"], "notes": "NoteThe figure below depicts the first test case. The blue part corresponds to the piece which belongs to Bob, and the red part is the piece that Alice keeps for herself. The area of the red part is $$$6^2 - 5^2 = 36 - 25 = 11$$$, which is prime, so the answer is \"YES\". In the second case, the area is $$$16^2 - 13^2 = 87$$$, which is divisible by $$$3$$$. In the third case, the area of the remaining piece is $$$61690850361^2 - 24777622630^2 = 3191830435068605713421$$$. This number is not prime because $$$3191830435068605713421 = 36913227731 \\cdot 86468472991 $$$.In the last case, the area is $$$34^2 - 33^2 = 67$$$."}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val inp = InputReader(inputStream)\n val out = PrintWriter(outputStream)\n val solver = TaskB()\n solver.solve(inp, out)\n out.close()\n}\n\nclass TaskB {\n fun solve(inp: InputReader, out: PrintWriter) {\n val t = inp.nextInt()\n for (i in 1..t) {\n val a = inp.nextLong()\n val b = inp.nextLong()\n val d1 = a - b\n val d2 = a + b\n if (d1 == 1L) {\n if (isPrime(d2))\n out.println(\"YES\")\n else\n out.println(\"NO\")\n } else\n out.println(\"NO\")\n }\n }\n\n private fun isPrime(x: Long): Boolean {\n if (x == 1L)\n return false\n var d = 2L\n while (d * d <= x) {\n if (x % d == 0L)\n return false\n d++\n }\n return true\n }\n}\n\nclass InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return next().toLong()\n }\n}\n"}, {"source_code": "import java.io.FileInputStream\nimport java.util.*\n\nobject programkt {\n @JvmStatic fun main(args: Array) {\n if (args.size == 1)\n System.setIn(FileInputStream(args[0]))\n val sc = Scanner(System.`in`)\n val t = Integer.parseInt(sc.nextLine())\n IntRange(1, t).forEach {\n val a = sc.nextLong()\n val b = sc.nextLong()\n println(if (a - b == 1L && isPrime(a+b)) \"YES\" else \"NO\")\n }\n }\n\n private fun isPrime(n: Long): Boolean {\n var i = 2L\n while (i * i <= n) {\n if (n % i == 0L)\n return false\n i++\n }\n return true\n }\n}\n"}, {"source_code": "import kotlin.math.sqrt\n\n// unable to solve it by myself. Solution on tutorial: https://codeforces.com/blog/entry/62287\nfun main() {\n fun readInt() = readLine()!!.toInt()\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n nextQuery@ for (query in 0 until readInt()) {\n val (a, b) = readLongs()\n if (a - b != 1L) {\n println(\"NO\")\n continue@nextQuery\n }\n val goal = a + b\n if (goal % 2 == 0L) println(\"NO\")\n else {\n for (divisor in 3..sqrt(goal.toDouble()).toInt() step 2)\n if (goal % divisor == 0L) {\n println(\"NO\")\n continue@nextQuery\n }\n println(\"YES\")\n }\n }\n}"}, {"source_code": "fun check(a: Long, b: Long): Boolean {\n if (a - b > 1) return false\n val res = a + b\n for (i in 2..Math.sqrt(res.toDouble()).toInt()) {\n if (res % i == 0L) {\n return false\n }\n }\n return true\n}\n\nfun main(args: Array) {\n val t = readLine()!!.toInt()\n for (test in 0 until t) {\n val (a, b) = readLine()!!.split(\" \").map{it.toLong()}\n if (check(a, b)) println(\"YES\") else println(\"NO\")\n }\n}\n"}, {"source_code": "import kotlin.math.sqrt\n\nfun main() {\n repeat(readLine()!!.toInt()) {\n val (a,b)= readLine()!!.split(\" \").map { it.toLong() }\n if(a - b > 1) {\n println(\"NO\")\n } else {\n var isPrime = true\n for (i in 3..sqrt((a+b).toDouble()).toInt() step 2) {\n if((a+b).rem(i) == 0L) {\n isPrime = false\n break\n }\n }\n if(isPrime) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n\n }\n\n\n }\n\n\n\n\n}\n\n\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val t = sc.nextInt()\n repeat(t) {\n val a = sc.nextBigInteger()\n val b = sc.nextBigInteger()\n if ((a * a - b * b).isProbablePrime(100)) {\n println(\"YES\")\n }else{\n println(\"NO\")\n }\n }\n}"}], "negative_code": [{"source_code": "import java.io.FileInputStream\nimport java.util.*\n\nobject programkt {\n @JvmStatic fun main(args: Array) {\n if (args.size == 1)\n System.setIn(FileInputStream(args[0]))\n val sc = Scanner(System.`in`)\n val t = Integer.parseInt(sc.nextLine())\n IntRange(1, t).forEach {\n val a = sc.nextLong()\n val b = sc.nextLong()\n println(if (a - b == 1L) \"YES\" else \"NO\")\n }\n }\n}\n"}, {"source_code": "fun isPrime(n: Long): Boolean {\n var k: Long\n var upperBound = n / 2\n\n k = 3\n while (k <= upperBound) {\n upperBound = n / k\n if (n % k == 0L)\n return false\n k += 2\n }\n return true\n}\n\nfun main(args: Array) {\n val t = readLine()!!.toInt()\n for (test in 0 until t) {\n val (a, b) = readLine()!!.split(\" \").map{it.toLong()}\n val res = a * a - b * b\n if (isPrime(res)) println(\"YES\") else println(\"NO\")\n }\n}\n"}, {"source_code": "import kotlin.math.sqrt\n\nfun main() {\n repeat(readLine()!!.toInt()) {\n val (a,b)= readLine()!!.split(\" \").map { it.toLong() }\n if(a - b > 1) {\n println(\"NO\")\n } else {\n var isPrime = true\n for (i in 3..sqrt((a+b).toDouble()).toInt() step 2) {\n if(i.rem(a+b) == 0L) {\n isPrime = false\n break\n }\n }\n if(isPrime) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n\n }\n\n\n }\n\n\n\n\n}\n\n\n"}], "src_uid": "5a052e4e6c64333d94c83df890b1183c"} {"nl": {"description": "It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.", "input_spec": "The single line contains integer y (1000 ≤ y ≤ 9000) — the year number.", "output_spec": "Print a single integer — the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.", "sample_inputs": ["1987", "2013"], "sample_outputs": ["2013", "2014"], "notes": null}, "positive_code": [{"source_code": "fun main() {\n var x = readLine()!!.toInt()\n while (true){\n x += 1\n val a: Int = x / 1000\n val b: Int = x / 100 % 10\n val c: Int = x / 10 % 10\n val d: Int = x % 10\n if (a != b && a != c && a != d && b != c && b != d && c != d) {\n break\n }\n }\n print(x)\n}"}, {"source_code": "fun main() {\n var x = readLine()!!.toInt()\n for(i in x until 9015){\n var flag = 0; x++;\n val y = x.toString().toList().sorted()\n for(j in 0 until y.size-1){\n if (y[j] == y[j+1]){\n flag = 1\n break\n }\n }\n if(flag == 0){\n print(x.toString())\n break\n }\n }\n}"}, {"source_code": "fun main(args: Array) = println(generateSequence(readLine()!!.toInt() + 1) { it + 1 }.first { it.toString().toCharArray().toSet().size == 4 })"}, {"source_code": "fun main(args: Array) {\n val s = readLine()!!\n var n = s.toInt()\n while (true) {\n n++\n if (n.toString().toSet().size == 4) {\n println(n)\n break\n }\n }\n}"}, {"source_code": "// package codeforces\n\nfun main() {\n var y = readLine()!!.toInt() + 1\n while (y.toString().toSet().size < 4) {\n y++\n }\n println(y)\n}"}, {"source_code": "import java.util.*\nfun main(args: Array) {\n var sc = Scanner(System.`in`)\n var year = sc.nextInt()\n while(true){\n year++\n if (year.toString().length == year.toString().toSet().size){\n println(year)\n break\n }\n }\n}"}, {"source_code": "fun main(args : Array) {\n var num = readLine()!!.toInt()\n var distinc = false\n while (distinc == false){\n distinc = true\n num ++\n var s = (num.toString()).toCharArray()\n s.sort()\n for (i in 1..(s.size-1)) {\n if (s[i-1] == s[i]) {\n distinc = false\n }\n }\n }\n println(num)\n}"}, {"source_code": "// https://codeforces.com/problemset/problem/271/A\n\nfun main(args: Array) {\n val date = readLn()\n var dateInt = date.toInt()\n val actualSet = mutableSetOf()\n\n while (actualSet.size != 4) {\n dateInt++\n actualSet.clear()\n actualSet.addAll(dateInt.toString().toList())\n\n }\n\n print(dateInt)\n}\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings(del: String = \" \") = readLn().split(del) // list of strings\nprivate fun readInts(del: String = \" \") = readStrings(del).map { it.toInt() } // list of ints"}, {"source_code": "//package problem271A\n\nfun isUniqueYear(currentYear: Int): Boolean {\n val digits = BooleanArray(10)\n var year = currentYear\n\n while (year > 0) {\n val currentDigit = year % 10\n if (digits[currentDigit]) {\n return false\n }\n digits[currentDigit] = true\n year /= 10\n }\n return true\n}\n\nfun nextUniqueYear(startingYear: Int): Int {\n var currentYear = startingYear + 1\n\n while (!isUniqueYear(currentYear)) {\n ++currentYear\n }\n return currentYear\n}\n\nfun main() {\n val startingYear = readLine()!!.toInt()\n\n println(nextUniqueYear(startingYear))\n}\n"}, {"source_code": "import java.lang.reflect.Array\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nfun check(year : Int) : Boolean\n{\n var array = Array(10 , {0})\n var str = year.toString()\n for(i in 0 until str.length)\n {\n if(array[str[i].toInt()-48] >= 1)\n {\n return false\n }\n array[str[i].toInt()-48]++\n }\n return true\n}\nfun main() {\n var scanner = Scanner(System.`in`)\n var year = scanner.nextInt()\n year++\n while(check(year) == false) year++\n println(year)\n}\n\n"}, {"source_code": "fun main(args: Array) {\n var a = readLine()!!.toInt()\n\n while(true){\n a++\n if(check(a.toString().toCharArray())){\n print(a)\n return\n }\n }\n\n}\n\nfun check(elements : CharArray) : Boolean {\n return elements.toHashSet().size == elements.size\n}"}, {"source_code": "import java.util.*\nfun main() {\n val s = Scanner(System.`in`)\n var r = s.next()\n var x: Int = r.toInt()\n while (true){\n x++;\n r = x.toString()\n var n = r.length\n var q: Boolean = false\n var mp = hashMapOf()\n for (i in r) {\n if (mp[i] == 1) {\n q = true;\n } else\n mp[i] = 1\n }\n if (!q) {\n print(r)\n break\n }\n}\n}\n"}, {"source_code": "import kotlin.system.exitProcess\n\nfun main(args: Array) {\n val input = readLine()\n var n = 1000\n if (input != null) {\n n = input.toInt()\n }\n val digits = HashSet()\n for (i in n+1 .. 10000) {\n digits.clear()\n var temp = i\n while (temp != 0) {\n digits.add(temp % 10)\n temp /= 10\n }\n if (digits.size == 4) {\n println(i)\n exitProcess(0)\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n var year = readLine()!!.toInt()\n do {\n year++\n if (year.toString().toCharArray().toSet().size == 4) {\n println(year)\n break\n }\n } while (true)\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\nfun main(args: Array){\n val scan = Scanner(System.`in`)\n var startYear = scan.nextInt() + 1\n\n fun checkYear(yea: Int): Boolean{\n var year = yea\n val arr = ArrayList()\n while (year != 0){\n arr.add(year % 10)\n year /= 10\n }\n var bool = false\n for (i in 0 until arr.size){\n for (j in i+1 until arr.size) if (arr[i] == arr[j]) bool = true\n }\n return bool\n }\n while (checkYear(startYear)){\n startYear++\n }\n print(startYear)\n}"}, {"source_code": "fun check(a: Int): Boolean {\n return a.toString().length == a.toString().toSet().size\n}\n\nfun main() {\n var a = readLine()!!.toInt()\n do {\n a += 1\n } while (!check(a))\n println(a)\n}"}, {"source_code": "import kotlin.math.min\nimport kotlin.math.sign\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n var n = readInt()\n while (!isUnique(++n)){}\n println(n)\n\n}\n\nfun isUnique(x: Int): Boolean {\n val s = x.toString()\n return s.toCharArray().distinct().size == s.length\n}"}, {"source_code": "fun main() {\n var year = readLine()!!.toInt() + 1\n\n while (true) {\n val str = year.toString()\n if (str.toCharArray().toSet().size == str.length) {\n println(year)\n break\n }\n year++\n }\n}"}, {"source_code": "import java.util.*\nfun checkyear(year:Int):Boolean\n{\n return year.toString().length==year.toString().toSet().size\n}\n\nfun main (args:Array)\n{\nvar year= readLine()!!.toInt()\n do\n {\n year++\n }while(!checkyear(year))\n print(year)\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nval unique = { year: Int ->\n year.toString().toSet().size == 4\n}\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n var year = reader.readLine().toInt()\n while (!unique(++year));\n println(year)\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n var y = readLine()!!.toInt() + 1\n while(true) {\n var bitset = BitSet(10)\n var tmp = y\n var beautiful = true\n for(d in 1..4) {\n if(!bitset.get(tmp % 10))\n bitset.set(tmp%10)\n else {\n beautiful = false\n break\n }\n tmp /= 10\n }\n if(beautiful) {\n println(y)\n break\n }\n y++;\n }\n}"}, {"source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n n++\n while (true) {\n var s: MutableSet = mutableSetOf()\n val str = n.toString()\n for (c in str) {\n s.add(c)\n }\n if (s.size == 4)\n break\n n++\n }\n print(\"$n\\n\")\n}\n"}, {"source_code": "fun main(args: Array) {\n println(\n generateSequence(readLine()!!.toInt() + 1, Int::inc)\n .first {\n val string = it.toString()\n string.toSet().size == string.length\n }\n )\n}\n"}, {"source_code": "fun main() {\n\n var year = readLine()!!.toInt()\n\n while (true) {\n if (isBeautifulYear(++year)) {\n print(year)\n break\n }\n }\n}\n\nfun isBeautifulYear(x: Int): Boolean {\n\n val digitList = ArrayList()\n var year = x\n var digit: Int\n\n while (year > 0) {\n\n digit = year % 10\n if (digitList.contains(digit))\n return false\n digitList.add(digit)\n year /= 10\n }\n return true\n}\n\n\n"}, {"source_code": "fun main(args: Array) {\n val prev = readLine()!!.toInt()\n val reg = \"^(?:([0-9])(?!.*\\\\1))*\\$\".toRegex()\n\n for(i in prev+1 .. 9012){\n if (reg.matches(i.toString())) {\n println(i)\n return\n }\n }\n}"}, {"source_code": "fun main() {\n var input = Integer.parseInt(readLine().orEmpty()) + 1\n while (true) {\n if (checkNum(input)) {\n println(input)\n return\n }\n input+=1\n }\n}\n\nfun checkNum(i: Int): Boolean {\n var result = true\n val mas = i.toString().toCharArray().map { n -> Integer.valueOf(n.toString()) }\n for (ii in mas.indices) {\n for (j in ii + 1 until mas.size) {\n if (mas[ii] == mas[j]) {\n result = false\n break\n }\n }\n }\n return result\n}\n"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n\nfun Int.isDistinct(): Boolean {\n return toString().let { it.length == it.toList().distinct().size }\n}\n\nfun main() {\n val year = readInt()\n var newYear = year + 1\n\n while (!newYear.isDistinct()) {\n ++newYear\n }\n\n println(newYear)\n}\n"}, {"source_code": "fun main(args: Array) {\n var year = readLine()!!.toInt()\n while (true) {\n year++\n val s = year.toString().toSet()\n if (s.size == 4) {\n println(year)\n return\n }\n }\n}\n\n"}, {"source_code": "import java.util.*\n\nfun min(a:Double,b:Double) = if (ab) a else b\nfun min(a:Long,b:Long) = if (ab) a else b\n\nfun readLn() = readLine()!!\nfun readLong() = readLn().toLong()\nfun readLongs() = readLn().split(\" \").map{it.toLong()}\nvar nul=0.toLong();\nvar one=1.toLong();\nvar two=2.toLong();\nvar three=3.toLong();\nvar four=4.toLong();\nvar five=5.toLong();\nfun powmod(a:Long,b:Long,mod:Long):Long {\n\n if (b==1.toLong()) return a;\n var k=powmod(a,b/2,mod);\n if (b%2==0.toLong())\n { return (k*k)%mod }\n else { k=k*k; k=k%mod; k=k*a; k=k%mod; return k; }\n}\nfun prime (p:Long):Long {\n if (p==one) return 0.toLong();\n var i=two;\n while (i*i<=p) {if (p%i==nul) return i; i++; }\n return one;\n}\nfun inv (a:Long,mod:Long):Long {\nreturn powmod(a,mod-2,mod);\n}\n\nfun solve() {\n val cin = Scanner(System.`in`)\n\n /*\n var map=hashMapOf();\n map[q] <=> map.getOrDefault(q,0)\n Сортировка вектора пар - k=v.sortedWith(compareBy({it.first},{it.second}));\n prLong(\"${k[i].second}\"); - вывод аргумента пары\n var m=ArrayList (); <=> vector\n getline(cin,a) <=> readLine()!!.last()\n readLong() - одно число\n readLongs() - несколько чисел\n readLine()!!.toCharArray() - возвращает массив чаров из строки\n\n */\n /* --------- */\n // ВСЕГДА ПИСАТЬ В ЛОНГАХ\n var a=readLong();\n\n var check=one;\n\n while (check==one) {\n a=a+1;\n var map=hashMapOf();\n\n var q=a;\n var check1=one;\n while (q!=nul) {\n map[q%10]=map.getOrDefault(q%10,0)+1;\n if (map.getOrDefault(q%10,0)>one) check1=nul;\n q/=10; }\n if (check1==one) {check=two; print(a); }\n }\n\n /* --------- */\n\n}\n\nfun main() {\n val cin = Scanner(System.`in`)\n\n var T=one;\n //T=readLine()!!.toLong();\n for (i55555 in 1..T) solve()\n}\n"}, {"source_code": "fun main() {\n var x = readLine()!!.toInt()\n while (x++ < Integer.MAX_VALUE) {\n if (x.toString().split(\"\").distinct().count() == 5) {\n print(x)\n break\n }\n }\n}"}, {"source_code": "fun main(args:Array){\n var year = readLine()!!.toInt()\n\n do{\n year++\n }\n while (!isDigitsDifferent(year))\n\n print(year)\n}\n\nfun isDigitsDifferent(year:Int) : Boolean {\n val yearAsString = year.toString()\n var isDifferent = true;\n for (i in 0 until yearAsString.lastIndex){\n for (j in i+1..yearAsString.lastIndex){\n if(yearAsString[i] == yearAsString[j]){\n isDifferent = false\n }\n }\n }\n return isDifferent\n}"}, {"source_code": "fun solve(a: Int): Boolean {\n val used = mutableListOf()\n var mA = a\n\n for (i in 0 until 10) {\n used.add(0)\n }\n\n while (mA > 0) {\n if (used[mA % 10] > 0) {\n return false\n }\n used[mA % 10] = 1\n mA /= 10\n }\n \n return true\n}\n\nfun main() {\n var y = readLine()!!.toInt()\n\n while (true) {\n y++\n if (solve(y)) {\n println(y)\n return\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n\tval input: Int = readLine()!!.toInt()\n\tprintln(findNextDistinct(input))\n}\n\nfun findNextDistinct(input: Int): Int{\n\tvar no = input\n\twhile(true){\n\t\tno+=1\n\t\tif(isDistinct(no)){\n\t\t\treturn no\n\t\t}\n\t}\n}\n\nfun isDistinct(no: Int): Boolean{\n\tval set = hashSetOf()\n\tset.add(no % 10)\n\tset.add((no/10) % 10)\n\tset.add((no/100) % 10)\n\tset.add((no/1000) % 10)\n\treturn set.size == 4\n}"}, {"source_code": "fun readInt(): Int = readLine()!!.toInt()\nfun isBeautiful(year: Int): Boolean {\n val resultList = year.toString().flatMap {\n listOf(it to 1)\n }\n val resultSet = resultList.toSet()\n if(resultSet.size == resultList.size)\n {\n return true\n }\n return false\n}\nfun findNumber(startYear: Int): Int{\n var copyStartYear = startYear + 1\n while (!isBeautiful(copyStartYear)){\n copyStartYear++\n }\n return copyStartYear\n}\n\nfun main(){\n val inputValue = readInt()\n print(findNumber(inputValue))\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.*\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n var a = scanner.nextInt() + 1\n val arr = IntArray(10)\n while (true) {\n var flag = false\n for (i in a.toString()) {\n if (arr[i - '0'] == a) {\n flag = true\n break\n }\n arr[i - '0'] = a\n }\n a++\n if (flag)\n continue\n println(a - 1)\n return\n }\n\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\n//class Pair(var a: Int, var b: Int): Comparable {\n// override fun compareTo(other: Pair): Int {\n// return b - a - other.b + other.a\n// }\n//}"}, {"source_code": "fun main() {\n var year = readLine()!!\n var intYear = year.toInt()\n year = (++intYear).toString()\n while (true) {\n if (year.toSet().size == 4) {\n break\n } else {\n year = (++intYear).toString()\n }\n }\n println(intYear)\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n var tok = StringTokenizer(\"\")\n\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n fun files(inputFilename: String, outputFilename: String) = ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))\n }\n\n fun readToken(): String {\n while (!tok.hasMoreTokens()) {\n tok = StringTokenizer(rd.readLine())\n }\n return tok.nextToken()\n }\n\n fun readInt(): Int = readToken().toInt()\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun close() {\n rd.close()\n wr.close()\n }\n}\n\nfun solve() {\n fun check(y: Int): Boolean {\n val s = y.toString()\n return s.length == s.toSet().size\n }\n\n val io = ProblemIO.console()\n val n = io.readInt()\n for (y in n + 1 .. Integer.MAX_VALUE) {\n if (check(y)) {\n io.println(y)\n break\n }\n }\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n"}, {"source_code": "fun main()\n{\n var year = readLine()!!.toInt()\n while(true)\n {\n year ++\n if (year.toString().toCharArray().toSet().size == 4)\n {\n println(year)\n break\n }\n }\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n1 = r.readLine()!!.toInt()\n var n2 = n1+1\n fun dis(int: Int)= int.toString().split(\"\").filter { it.length>0 }.toSet().size\n while (dis(n2)!=4){\n n2++\n }\n println(n2)\n}"}, {"source_code": "import java.util.*\nimport java.math.*\nimport kotlin.math.*\n\nfun readLn()=readLine()!!\nfun readInt()=readLn().toInt()\nfun readInts()=readLn().split(\" \").map{it.toInt()}\nfun readLong()=readLn().toLong()\nfun readLongs()=readLn().split(\" \").map{it.toLong()}\n\nval out=mutableListOf()\nfun printLine(s:String){out.add(s)}\nfun output(){println(out.joinToString(\"\\n\"))}\n\nfun main(){\n var x=readInt()\n var y=x+1\n while(true){\n var st=ArrayList()\n var tmp=y\n while(tmp>0){\n st.add(tmp%10)\n tmp/=10\n }\n st.sort()\n var ok=true\n for(i in 1 until st.size){\n if(st[i]==st[i-1])ok=false\n }\n if(ok)break\n y++\n }\n printLine(\"$y\")\n output()\n}"}, {"source_code": "fun Int.isAllDifferent() = this.toString().toSet().size == this.toString().length\n\nfun main() {\n\tvar input = readLine()!!.toInt()\n\tdo { input++ }\n\twhile (!input.isAllDifferent())\n\tprintln(input)\n}\n"}, {"source_code": "fun main() {\n var y = readLine()!!.toInt()\n\n for (i in 1000 until 9001) {\n y++\n if (y.toString().split(\"\").distinct().size == 5)\n break\n }\n\n print(y)\n}"}, {"source_code": "\nfun solve(i: Int): Int {\n val a: Int = i % 10\n val b: Int = (i / 10) % 10\n val c: Int = (i / 100) % 10\n val d: Int = (i / 1000) % 10\n return if (a != b && a != c && a != d && b != c && b != d && c != d) {\n 1\n } else\n 0\n\n\n}\n\nfun main() {\n\n val n = readLine()?.toInt()!!\n var x: Int\n for (i in (n+1) until 9013) {\n x = solve(i)\n if(x==1){\n println(i)\n break\n }\n\n\n }\n\n\n}"}, {"source_code": "fun check(n : Int) : Boolean {\n return n.toString().length == n.toString().toSet().size\n}\n\nfun main(args : Array) {\n var n = readLine()!!.toInt() + 1\n while(!check(n)) n++\n \n println(n)\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val input = InputReader(inputStream)\n val output = PrintWriter(outputStream)\n val solver = Task()\n solver.solve(input, output)\n output.close()\n}\n\nprivate class Task {\n fun solve(input: InputReader, output: PrintWriter) {\n val inputYear = input.nextInt()\n\n var year = inputYear + 1\n\n while (year.toString().let { it.toSet().size != it.length }) year++\n\n output.print(year)\n }\n}\n\n\nprivate class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n\n operator fun next(): String {\n while (tokenizer == null || tokenizer?.hasMoreTokens()?.not() == true) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return next().toInt()\n }\n\n}"}, {"source_code": "import java.util.regex.Pattern\n\nfun main() {\n var line1 = readLine()!!.toInt()\n line1++\n while(true){\n var set = (\"\"+line1).toCharArray().toSet()\n if(set.size == (\"\"+line1).length){\n println(line1)\n return\n }\n line1++\n }\n}"}], "negative_code": [{"source_code": "fun main() {\n var x = readLine()!!.toInt()\n for(i in x until 9000){\n var flag = 0; x++;\n val y = x.toString().toList().sorted()\n for(j in 0 until y.size-1){\n if (y[j] == y[j+1]){\n flag = 1\n break\n }\n }\n if(flag == 0){\n print(x.toString())\n break\n }\n }\n}"}, {"source_code": "fun main(args: Array) = println(generateSequence(readLine()!!.toInt()) { it + 1 }.first { it.toString().toCharArray().toSet().size == 4 })"}, {"source_code": "fun main(args: Array) {\n val s = readLine()!!\n var n = s.toInt()\n while (n <= 9000) {\n n++\n if (n.toString().toSet().size == 4) {\n println(n)\n break\n }\n }\n}"}, {"source_code": "import kotlin.system.exitProcess\n\nfun main(args: Array) {\n val input = readLine()\n var n = 1000\n if (input != null) {\n n = input.toInt()\n }\n val digits = HashSet()\n for (i in n+1 .. 9000) {\n digits.clear()\n var temp = i\n while (temp != 0) {\n digits.add(temp % 10)\n temp /= 10\n }\n if (digits.size == 4) {\n println(i)\n exitProcess(0)\n }\n }\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val y = readLine()!!.toInt() + 1\n for(i in y..9000) {\n var bitset = BitSet(10)\n var tmp = i\n var beautiful = true\n for(d in 1..4) {\n if(!bitset.get(tmp % 10))\n bitset.set(tmp%10)\n else {\n beautiful = false\n break\n }\n tmp /= 10\n }\n if(beautiful) {\n println(i)\n break\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val prev = readLine()!!.toInt()\n val reg = \"^(?:([0-9])(?!.*\\\\1))*\\$\".toRegex()\n for (next in prev + 1 .. 9000){\n if (reg.matches(next.toString())) {\n println(next)\n break\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val prev = readLine()!!.toInt()\n val reg = \"^(?:([0-9])(?!.*\\\\1))*\\$\".toRegex()\n (prev + 1 until 9000).forEach{\n if (reg.matches(it.toString())) {\n println(it)\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val prev = readLine()!!.toInt()\n val reg = \"^(?:([0-9])(?!.*\\\\1))*\\$\".toRegex()\n (prev + 1 until 9000).forEach{\n if (reg.matches(it.toString())) {\n println(it)\n return\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val prev = readLine()!!.toInt()\n val reg = \"^(?:([0-9])(?!.*\\\\1))*\\$\".toRegex()\n for(i in prev+1 .. 9000){\n if (i > 9000) return\n if (reg.matches(i.toString())) {\n println(i)\n return\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val prev = readLine()!!.toInt()\n val reg = \"^(?:([0-9])(?!.*\\\\1))*\\$\".toRegex()\n\n for(i in prev+1 .. 9000){\n if (i <9000 && reg.matches(i.toString())) {\n println(i)\n return\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val prev = readLine()!!.toInt()\n val reg = \"^(?:([0-9])(?!.*\\\\1))*\\$\".toRegex()\n for(i in prev+1 .. 9000){\n if (reg.matches(i.toString())) {\n println(i)\n return\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n val prev = readLine()!!.toInt()\n val reg = \"^(?:([0-9])(?!.*\\\\1))*\\$\".toRegex()\n for(i in prev+1 .. 9000){\n if (i == 9000) return\n if (reg.matches(i.toString())) {\n println(i)\n return\n }\n }\n}"}, {"source_code": "fun main() {\n var x = readLine()!!.toInt()\n while (x++ < 0x2329) {\n if (x.toString().split(\"\").distinct().count() == 5) {\n print(x)\n break\n }\n }\n}"}, {"source_code": "fun main() {\n var x = readLine()!!.toInt()\n while (x++ < 0x2328) {\n if (x.toString().split(\"\").distinct().count()==5){\n print(x)\n break\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n\tval input: Int = readLine()!!.toInt()\n\tprintln(findNextDistinct(input))\n}\n\nfun findNextDistinct(input: Int): Int{\n\tvar no = input +1;\n\twhile(true){\n\t\tno+=1\n\t\tif(isDistinct(no)){\n\t\t\treturn no\n\t\t}\n\t}\n}\n\nfun isDistinct(no: Int): Boolean{\n\tval set = hashSetOf()\n\tset.add(no % 10)\n\tset.add((no/10) % 10)\n\tset.add((no/100) % 10)\n\tset.add((no/1000) % 10)\n\treturn set.size == 4\n}"}, {"source_code": "fun solve(i: Int): Int {\n val a: Int = i % 10\n val b: Int = (i / 10) % 10\n val c: Int = (i / 100) % 10\n val d: Int = (i / 1000) % 10\n return if (a != b && a != c && a != d && b != c && b != d && c != d) {\n 1\n } else\n 0\n\n\n}\n\nfun main() {\n\n val n = readLine()?.toInt()!!\n var x: Int\n for (i in (n+1) until 9001) {\n x = solve(i)\n if(x==1){\n println(i)\n break\n }\n\n\n }\n\n\n}"}], "src_uid": "d62dabfbec52675b7ed7b582ad133acd"} {"nl": {"description": "Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 2000, 2004, but years 1900 and 2018 are not leap.In this problem you are given n (1 ≤ n ≤ 24) integers a1, a2, ..., an, and you have to check if these integers could be durations in days of n consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is a1 days, duration of the next month is a2 days, and so on.", "input_spec": "The first line contains single integer n (1 ≤ n ≤ 24) — the number of integers. The second line contains n integers a1, a2, ..., an (28 ≤ ai ≤ 31) — the numbers you are to check.", "output_spec": "If there are several consecutive months that fit the sequence, print \"YES\" (without quotes). Otherwise, print \"NO\" (without quotes). You can print each letter in arbitrary case (small or large).", "sample_inputs": ["4\n31 31 30 31", "2\n30 30", "5\n29 31 30 31 30", "3\n31 28 30", "3\n31 31 28"], "sample_outputs": ["Yes", "No", "Yes", "No", "Yes"], "notes": "NoteIn the first example the integers can denote months July, August, September and October.In the second example the answer is no, because there are no two consecutive months each having 30 days.In the third example the months are: February (leap year) — March — April – May — June.In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO.In the fifth example the months are: December — January — February (non-leap year)."}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(args: Array) {\n val sc = FastScanner(System.`in`)\n\n val n = sc.nextInt()\n val d = Array(n) { sc.nextInt() }\n\n val year = listOf(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)\n val vis = listOf(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)\n\n\n if (check(year + year + year + vis, d) ||\n check(year + year + vis + year, d) ||\n check(year + vis + year + year, d) ||\n check(vis + year + year + year, d) ||\n check(year + year + year + year, d)) {\n println(\"YES\")\n }\n else {\n println(\"NO\")\n }\n\n\n}\n\nfun check(list: List, d: Array): Boolean {\n for(i in 0 until list.size){\n if(i + d.size > list.size) break\n\n if(list.subList(i, i + d.size) == d.toList()) return true\n }\n return false\n}\n\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}\n\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(args: Array) {\n val sc = FastScanner(System.`in`)\n\n val n = sc.nextInt()\n val d = Array(n) { sc.nextInt() }\n\n val year = listOf(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)\n val vis = listOf(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)\n\n if (check(year + year + year + vis + year + year + year + year, d)) println(\"YES\")\n else println(\"NO\")\n}\n\nfun check(list: List, d: Array) = (0 until list.size)\n .takeWhile { it + d.size <= list.size }\n .any { list.subList(it, it + d.size) == d.toList() }\n\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}\n\n\n"}, {"source_code": "fun main(args: Array){\n\tval y = \" 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31\"\n readLine()!!\n\tprintln(if(y.contains(readLine()!!)) \"YES\" else \"NO\")\n}"}, {"source_code": "import java.util.*\nimport java.util.Arrays\nimport java.util.Collections.indexOfSubList\nimport java.util.Collections.addAll\nimport java.util.ArrayList\n\n\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n\n val n = nextInt()\n val a = arrayOfNulls(n)\n for (i in 0 until n) {\n a[i] = nextInt()\n }\n val leap = arrayOf(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)\n val nonLeap = arrayOf(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)\n val l = ArrayList()\n l.addAll(Arrays.asList(*nonLeap))\n l.addAll(Arrays.asList(*nonLeap))\n l.addAll(Arrays.asList(*leap))\n l.addAll(Arrays.asList(*nonLeap))\n l.addAll(Arrays.asList(*nonLeap))\n val index = Collections.indexOfSubList(l, Arrays.asList(*a))\n if (index != -1) {\n println(\"Yes\")\n } else {\n println(\"No\")\n }\n}"}, {"source_code": "fun main() {\n var s = \"\"\n for (j in 0..15) {\n if (j == 0 || j == 4 || j == 12) {\n s += \"dbdcdcddcdcd\"\n } else {\n s += \"dadcdcddcdcd\"\n }\n }\n readLine()\n val t = readLine()!!.split(\" \").map { \"abcd\"[it.toInt() - 28] }.joinToString(\"\")\n println(if (s.contains(t)) \"yEs\" else \"nO\")\n}"}, {"source_code": "import java.io.*\nimport java.util.StringTokenizer\n\nval err = System.err\nval bf = BufferedReader(InputStreamReader(System.`in`))\nvar st = StringTokenizer(\"\")\n\nfun nxtstring(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(bf.readLine())\n return st.nextToken()\n}\n\nfun nxtint() = nxtstring().toInt()\n\nfun genyear(leap: Boolean) = intArrayOf(\n 31, 28 + if (leap) 1 else 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31\n)\n\nfun main(args: Array) {\n val n = nxtint()\n val a = IntArray(n)\n for (i in 0 until n) a[i] = nxtint()\n val dat = IntArray(12 * 8)\n var day = 0\n for (year in 0 until 8) {\n for (i in genyear(year == 3)) {\n dat[day++] = i\n //err.printf(\"%d \", i)\n }\n //err.println()\n }\n for (i in 0 until dat.size - n) {\n val b = dat.copyOfRange(i, i + n)\n //for (y in b) err.printf(\"%d \", y)\n //err.println()\n if (b contentEquals a) {\n println(\"YES\")\n System.exit(0)\n }\n }\n println(\"NO\")\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\n\nval months0 = arrayListOf(\n 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,\n 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,\n 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,\n 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,\n 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,\n 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,\n 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,\n 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,\n 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,\n 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)\n\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val count = reader.readLine().toInt()\n val days = reader.readLine().split(' ').map { it.toInt() }\n val result = contains(months0.toIntArray(), days.toIntArray())\n println(if (result) \"YES\" else \"NO\")\n}\n\nfun contains(set1: IntArray, set2: IntArray): Boolean {\n if (set1.size < set2.size) {\n return false\n }\n var numMatched = 0\n while (numMatched < set2.size && set1[numMatched] == set2[numMatched]) {\n numMatched++\n }\n\n if (numMatched == set2.size) {\n return true\n } else {\n val subset = Arrays.copyOfRange(set1, 1, set1.size)\n return contains(subset, set2)\n }\n}\n"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val ms = readLine()!!.split(\" \").map {\n when (it) {\n \"28\" -> \"a\"\n \"29\" -> \"b\"\n \"30\" -> \"c\"\n \"31\" -> \"d\"\n else -> null!!\n }\n }.reduce { c1, c2 -> \"$c1$c2\" }\n\n val y = listOf(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)\n val x = listOf(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)\n val aaa = y + y + x + y + y\n val bbb = aaa.map {\n when (it) {\n 28 -> \"a\"\n 29 -> \"b\"\n 30 -> \"c\"\n 31 -> \"d\"\n else -> null!!\n }\n }.reduce { c1, c2 -> \"$c1$c2\" }\n\n print(if (ms in bbb) \"YES\" else \"NO\")\n}"}], "negative_code": [{"source_code": "fun main(args: Array){\n\tval y = \" 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31\"\n readLine()!!\n\tprintln(if(y.contains(readLine()!!)) \"YES\" else \"NO\")\n}"}], "src_uid": "d60c8895cebcc5d0c6459238edbdb945"} {"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 java.util.*\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val input = scanner.next()\n\n if (input.isEmpty()) {\n println(0)\n return\n }\n\n val maxCarry = 5\n var currentCarry = 1\n var firstChar = input[0]\n var result = 1\n\n for (i in 1 until input.length) {\n val nextChar = input[i]\n currentCarry++\n\n if (firstChar != nextChar) {\n firstChar = nextChar\n currentCarry = 1\n }\n\n if (currentCarry == 1) {\n result++\n }\n\n if (currentCarry == maxCarry) {\n currentCarry = 0\n }\n }\n\n println(result)\n}"}, {"source_code": "fun main() {\n val s = readLine()!!\n var current = 'a'\n var count = 0\n var sol = 0\n for (c in s) {\n if (c == current && count < 5) count++\n else {\n sol++\n current = c\n count = 1\n }\n }\n print(sol)\n}"}], "negative_code": [{"source_code": "import java.util.*\n\nfun main () {\n val scanner = Scanner(System.`in`)\n val input = scanner.next()\n\n if (input.isEmpty()) {\n println(0)\n return\n }\n\n val maxCarry = 5\n var currentCarry = 1\n var firstChar = input[0]\n var result = 1\n var isFirst = true\n\n for (i in 1 until input.length) {\n val nextChar = input[i]\n\n if (firstChar != nextChar) {\n result++\n firstChar = nextChar\n currentCarry = 1\n } else {\n currentCarry++\n if (currentCarry == maxCarry) {\n if (isFirst) {\n isFirst = false\n } else {\n result++\n }\n currentCarry = 0\n } else if (i == input.length - 1) {\n if (!isFirst) {\n result++\n }\n }\n }\n }\n\n println(result)\n}"}], "src_uid": "5257f6b50f5a610a17c35a47b3a0da11"} {"nl": {"description": "Yura is a mathematician, and his cognition of the world is so absolute as if he have been solving formal problems a hundred of trillions of billions of years. This problem is just that!Consider all non-negative integers from the interval $$$[0, 10^{n})$$$. For convenience we complement all numbers with leading zeros in such way that each number from the given interval consists of exactly $$$n$$$ decimal digits.You are given a set of pairs $$$(u_i, v_i)$$$, where $$$u_i$$$ and $$$v_i$$$ are distinct decimal digits from $$$0$$$ to $$$9$$$.Consider a number $$$x$$$ consisting of $$$n$$$ digits. We will enumerate all digits from left to right and denote them as $$$d_1, d_2, \\ldots, d_n$$$. In one operation you can swap digits $$$d_i$$$ and $$$d_{i + 1}$$$ if and only if there is a pair $$$(u_j, v_j)$$$ in the set such that at least one of the following conditions is satisfied: $$$d_i = u_j$$$ and $$$d_{i + 1} = v_j$$$, $$$d_i = v_j$$$ and $$$d_{i + 1} = u_j$$$. We will call the numbers $$$x$$$ and $$$y$$$, consisting of $$$n$$$ digits, equivalent if the number $$$x$$$ can be transformed into the number $$$y$$$ using some number of operations described above. In particular, every number is considered equivalent to itself.You are given an integer $$$n$$$ and a set of $$$m$$$ pairs of digits $$$(u_i, v_i)$$$. You have to find the maximum integer $$$k$$$ such that there exists a set of integers $$$x_1, x_2, \\ldots, x_k$$$ ($$$0 \\le x_i < 10^{n}$$$) such that for each $$$1 \\le i < j \\le k$$$ the number $$$x_i$$$ is not equivalent to the number $$$x_j$$$.", "input_spec": "The first line contains an integer $$$n$$$ ($$$1 \\le n \\le 50\\,000$$$) — the number of digits in considered numbers. The second line contains an integer $$$m$$$ ($$$0 \\le m \\le 45$$$) — the number of pairs of digits in the set. Each of the following $$$m$$$ lines contains two digits $$$u_i$$$ and $$$v_i$$$, separated with a space ($$$0 \\le u_i < v_i \\le 9$$$). It's guaranteed that all described pairs are pairwise distinct.", "output_spec": "Print one integer — the maximum value $$$k$$$ such that there exists a set of integers $$$x_1, x_2, \\ldots, x_k$$$ ($$$0 \\le x_i < 10^{n}$$$) such that for each $$$1 \\le i < j \\le k$$$ the number $$$x_i$$$ is not equivalent to the number $$$x_j$$$. As the answer can be big enough, print the number $$$k$$$ modulo $$$998\\,244\\,353$$$.", "sample_inputs": ["1\n0", "2\n1\n0 1", "2\n9\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9"], "sample_outputs": ["10", "99", "91"], "notes": "NoteIn the first example we can construct a set that contains all integers from $$$0$$$ to $$$9$$$. It's easy to see that there are no two equivalent numbers in the set.In the second example there exists a unique pair of equivalent numbers: $$$01$$$ and $$$10$$$. We can construct a set that contains all integers from $$$0$$$ to $$$99$$$ despite number $$$1$$$."}, "positive_code": [{"source_code": "// $time$\nimport java.io.BufferedInputStream\nimport java.io.File\nimport java.io.PrintWriter\nimport kotlin.system.measureTimeMillis\n\n// 1. Modded\nconst val p = 998244353L\nconst val pI = p.toInt()\nfun Int.adjust():Int{ if(this >= pI){ return this - pI }else if (this < 0){ return this + pI };return this }\nfun Int.snap():Int{ if(this >= pI){return this - pI} else return this}\ninfix fun Int.modM(b:Int):Int{ return ((this.toLong() * b) % pI).toInt() }\ninfix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }\nfun intPow(x:Int,e:Int,m:Int):Int{\n var X = x ; var E =e ; var Y = 1\n while(E > 0){\n if(E and 1 == 0){\n X = ((1L * X * X) % m).toInt()\n E = E shr 1\n }else{\n Y = ((1L * X * Y) % m).toInt()\n E -= 1\n }\n }\n return Y\n}\n// 2. DP initial values\nconst val plarge = 1_000_000_727\nconst val nlarge = -plarge\nconst val phuge = 2_727_000_000_000_000_000L\nconst val nhuge = -phuge\n// 3. conveniecen conversions\nval Boolean.chi:Int get() = if(this) 1 else 0 //characteristic function\nval Char.code :Int get() = this.toInt() - 'a'.toInt()\n//3. hard to write stuff\nfun IntArray.put(i:Int,v:Int){ this[i] = (this[i] + v).adjust() }\nval mint:MutableList get() = mutableListOf()\nval mong:MutableList get() = mutableListOf()\n//4. more outputs\nfun List.conca():String = this.joinToString(\"\")\nval CharArray.conca :String get() = this.joinToString(\"\")\nval IntArray.conca :String get() = this.joinToString(\" \")\n@JvmName(\"concaInt\")\nfun List.conca():String = this.joinToString(\" \")\nval LongArray.conca:String get() = this.joinToString(\" \")\n@JvmName(\"concaLong\")\nfun List.conca():String = this.joinToString(\" \")\n//5. Pair of ints\nconst val longmask = (1L shl 32) - 1\nfun makepair(a:Int, b:Int):Long = (a.toLong() shl 32) xor (longmask and b.toLong()) // remember positev sonly\nval Long.first get() = (this ushr 32).toInt()\nval Long.second get() = this.toInt()\n//6. strings\nval String.size get() = this.length\nconst val randCount = 100\n//7. bits\nfun Int.has(i:Int):Boolean = (this and (1 shl i) != 0)\n//8 TIME\ninline fun TIME(f:()->Unit){\n val t = measureTimeMillis(){\n f()\n }\n println(\"$t ms\")\n}\nobject Reader{\n private const val BS = 1 shl 16\n private const val NC = 0.toChar()\n private val buf = ByteArray(BS)\n private var bId = 0\n private var size = 0\n private var c = NC\n\n var warningActive = true\n var fakein = StringBuilder()\n\n private var IN: BufferedInputStream = BufferedInputStream(System.`in`, BS)\n val OUT: PrintWriter = PrintWriter(System.out)\n\n private val char: Char\n get() {\n while (bId == size) {\n size = IN.read(buf) // no need for checked exceptions\n if (size == -1) return NC\n bId = 0\n }\n return buf[bId++].toChar()\n }\n\n fun nextInt(): Int {\n var neg = false\n if (c == NC) c = char\n while (c < '0' || c > '9') {\n if (c == '-') neg = true\n c = char\n }\n var res = 0\n while (c in '0'..'9') {\n res = (res shl 3) + (res shl 1) + (c - '0')\n c = char\n }\n return if (neg) -res else res\n }\n fun nextLong(): Long {\n var neg = false\n if (c == NC) c = char\n while (c < '0' || c > '9') {\n if (c == '-') neg = true\n c = char\n }\n var res = 0L\n while (c in '0'..'9') {\n res = (res shl 3) + (res shl 1) + (c - '0')\n c = char\n }\n return if (neg) -res else res\n }\n fun nextString():String{\n val ret = StringBuilder()\n while (true){\n c = char\n if(!isWhitespace(c)){ break}\n }\n ret.append(c)\n while (true){\n c = char\n if(isWhitespace(c)){ break}\n ret.append(c)\n }\n return ret.toString()\n }\n fun isWhitespace(c:Char):Boolean{\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t'\n }\n fun rerouteInput(){\n if(warningActive){\n put(\"Custom test enabled\")\n println(\"Custom test enabled\")\n warningActive = false\n }\n val S = fakein.toString()\n println(\"New Case \")\n println(S.take(80))\n println(\"...\")\n fakein.clear()\n IN = BufferedInputStream(S.byteInputStream(),BS)\n }\n fun takeFile(name:String){\n IN = BufferedInputStream(File(name).inputStream(),BS)\n }\n}\nfun put(aa:Any){ Reader.OUT.println(aa)}\nfun done(){ Reader.OUT.close() }\nfun share(aa:Any){\n if(aa is IntArray){Reader.fakein.append(aa.joinToString(\" \"))}\n else if(aa is LongArray){Reader.fakein.append(aa.joinToString(\" \"))}\n else if(aa is List<*>){Reader.fakein.append(aa.toString())}\n else{Reader.fakein.append(aa.toString())}\n Reader.fakein.append(\"\\n\")\n}\n\nval getintfast:Int get() = Reader.nextInt()\nval getint:Int get(){ val ans = getlong ; if(ans > Int.MAX_VALUE) IntArray(1000000000); return ans.toInt() }\nval getlong:Long get() = Reader.nextLong()\nval getstr:String get() = Reader.nextString()\nfun getline(n:Int):IntArray{\n return IntArray(n){getint}\n}\nfun getlineL(n:Int):LongArray{\n return LongArray(n){getlong}\n}\nvar dmark = -1\ninfix fun Any.dei(a:Any){\n dmark++\n var str = \"<${dmark}> \"\n debug()\n if(this is String){ str += this\n }else if(this is Int){ str += this.toString()\n }else if(this is Long){ str += this.toString()\n }else{ str += this.toString()}\n if(a is List<*>){ println(\"$str : ${a.joinToString(\" \")}\")\n }else if(a is IntArray){ println(\"$str : ${a.joinToString(\" \")}\")\n }else if(a is LongArray){ println(\"$str : ${a.joinToString(\" \")}\")\n }else if(a is BooleanArray){ println(\"$str :${a.map{if(it)'1' else '0'}.joinToString(\" \")}\")\n }else if(a is Array<*>){\n println(\"$str : \")\n for(c in a){if(c is IntArray){println(c.joinToString(\" \"))}\n else if(c is LongArray){println(c.joinToString(\" \"))}\n else if(c is BooleanArray){println(c.map { if(it) '1' else '0' }.joinToString(\"\"))\n }\n }\n println()\n }else{ println(\"$str : $a\")\n }\n}\nval just = \" \"\nfun crash(){\n throw Exception(\"Bad programme\")}\nfun assert(a:Boolean){\n if(!a){\n throw Exception(\"Failed Assertion\")\n }}\nenum class solveMode {\n real, rand, tc\n}\nobject solve{\n var mode:solveMode = solveMode.real\n var tcNum:Int = 0\n var rand:()->Unit = {}\n var TC:MutableMapUnit> = mutableMapOf()\n var tn:Long = 0\n fun cases(onecase:()->Unit){\n val t = if(mode == solveMode.real){if(singleCase) 1 else getint} else if(mode == solveMode.tc){1 } else randCount\n if(pI != 998_244_353 && pI != 1_000_000_007){\n throw Exception(\"Not usual primes!\")\n }\n if(t == 1 && mode != solveMode.real){\n tn = System.currentTimeMillis()\n }\n repeat(t){\n if(mode == solveMode.tc){\n TC[tcNum]?.let { it() }\n Reader.rerouteInput()\n }else if(mode == solveMode.rand){\n rand()\n Reader.rerouteInput()\n }\n onecase()\n }\n if(t == 1 && mode != solveMode.real){\n val dt = System.currentTimeMillis() - tn\n println(\"Time $dt ms \")\n }\n }\n inline fun singleCase(a:solve.()->Unit){\n val t = if(mode != solveMode.rand){1} else randCount\n repeat(t) { a() }\n }\n fun rand(a:()->Unit){\n this.rand = a\n }\n fun tc(id:Int = 0,a:()->Unit){\n TC[id] = a\n }\n fun usetc(a:Int = 0 ){\n this.tcNum = a\n this.mode = solveMode.tc\n }\n fun userand(){\n this.mode = solveMode.rand\n }\n}\nfun debug(){}\nconst val m = 10\nconst val singleCase = true\nfun main(){\n solve.cases{\n val n = getint\n val t = getint\n\n\n val can = Array(m){BooleanArray(m){false} }\n\n\n val enables = Array(m){BooleanArray(m){false} }\n val banned = Array(m){BooleanArray(m) }\n for(i in 0 until m) {\n for(j in i+1 until m) {\n banned[i][j] = true\n }\n }\n repeat(t){\n val a = getint\n val b = getint\n can[b][a] = true\n can[a][b] = true\n }\n for(i in 0 until m) {\n for(j in 0 until m) {\n if(!can[i][j]) {\n enables[i][j] = true\n }\n }\n }\n val enablemask = IntArray(m)\n val bannedmask = IntArray(m)\n\n for(i in 0 until m){\n for(j in 0 until m){\n if(enables[i][j]) {\n enablemask[i] += 1 shl j\n }\n if(banned[i][j]){\n bannedmask[i] += 1 shl j\n }\n }\n }\n\n\n var DP = IntArray(1 shl m)\n DP[(1 shl m) - 1 ] = 1\n repeat(n){\n val new = IntArray(1 shl m)\n for(left in 0 until (1 shl m)) {\n for(adding in 0 until m) {\n if(!left.has(adding)) continue\n val newmask = (left and ( bannedmask[adding]).inv()) or enablemask[adding]\n new[newmask] = new[newmask] modPlus DP[left]\n }\n }\n DP = new\n }\n var ret = 0\n for(a in DP) {\n ret = ret modPlus a\n }\n put(ret)\n /*\n how many classes\n\n */\n\n\n\n }\n done()\n}\n/*\n3\n3\n0 1\n0 2\n1 2\n */\n\n\n\n\n"}], "negative_code": [{"source_code": "// $time$\nimport java.io.BufferedInputStream\nimport java.io.File\nimport java.io.PrintWriter\nimport kotlin.system.measureTimeMillis\n\n// 1. Modded\nconst val p = 998244353L\nconst val pI = p.toInt()\nfun Int.adjust():Int{ if(this >= pI){ return this - pI }else if (this < 0){ return this + pI };return this }\nfun Int.snap():Int{ if(this >= pI){return this - pI} else return this}\ninfix fun Int.modM(b:Int):Int{ return ((this.toLong() * b) % pI).toInt() }\ninfix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }\nfun intPow(x:Int,e:Int,m:Int):Int{\n var X = x ; var E =e ; var Y = 1\n while(E > 0){\n if(E and 1 == 0){\n X = ((1L * X * X) % m).toInt()\n E = E shr 1\n }else{\n Y = ((1L * X * Y) % m).toInt()\n E -= 1\n }\n }\n return Y\n}\n// 2. DP initial values\nconst val plarge = 1_000_000_727\nconst val nlarge = -plarge\nconst val phuge = 2_727_000_000_000_000_000L\nconst val nhuge = -phuge\n// 3. conveniecen conversions\nval Boolean.chi:Int get() = if(this) 1 else 0 //characteristic function\nval Char.code :Int get() = this.toInt() - 'a'.toInt()\n//3. hard to write stuff\nfun IntArray.put(i:Int,v:Int){ this[i] = (this[i] + v).adjust() }\nval mint:MutableList get() = mutableListOf()\nval mong:MutableList get() = mutableListOf()\n//4. more outputs\nfun List.conca():String = this.joinToString(\"\")\nval CharArray.conca :String get() = this.joinToString(\"\")\nval IntArray.conca :String get() = this.joinToString(\" \")\n@JvmName(\"concaInt\")\nfun List.conca():String = this.joinToString(\" \")\nval LongArray.conca:String get() = this.joinToString(\" \")\n@JvmName(\"concaLong\")\nfun List.conca():String = this.joinToString(\" \")\n//5. Pair of ints\nconst val longmask = (1L shl 32) - 1\nfun makepair(a:Int, b:Int):Long = (a.toLong() shl 32) xor (longmask and b.toLong()) // remember positev sonly\nval Long.first get() = (this ushr 32).toInt()\nval Long.second get() = this.toInt()\n//6. strings\nval String.size get() = this.length\nconst val randCount = 100\n//7. bits\nfun Int.has(i:Int):Boolean = (this and (1 shl i) != 0)\n//8 TIME\ninline fun TIME(f:()->Unit){\n val t = measureTimeMillis(){\n f()\n }\n println(\"$t ms\")\n}\nobject Reader{\n private const val BS = 1 shl 16\n private const val NC = 0.toChar()\n private val buf = ByteArray(BS)\n private var bId = 0\n private var size = 0\n private var c = NC\n\n var warningActive = true\n var fakein = StringBuilder()\n\n private var IN: BufferedInputStream = BufferedInputStream(System.`in`, BS)\n val OUT: PrintWriter = PrintWriter(System.out)\n\n private val char: Char\n get() {\n while (bId == size) {\n size = IN.read(buf) // no need for checked exceptions\n if (size == -1) return NC\n bId = 0\n }\n return buf[bId++].toChar()\n }\n\n fun nextInt(): Int {\n var neg = false\n if (c == NC) c = char\n while (c < '0' || c > '9') {\n if (c == '-') neg = true\n c = char\n }\n var res = 0\n while (c in '0'..'9') {\n res = (res shl 3) + (res shl 1) + (c - '0')\n c = char\n }\n return if (neg) -res else res\n }\n fun nextLong(): Long {\n var neg = false\n if (c == NC) c = char\n while (c < '0' || c > '9') {\n if (c == '-') neg = true\n c = char\n }\n var res = 0L\n while (c in '0'..'9') {\n res = (res shl 3) + (res shl 1) + (c - '0')\n c = char\n }\n return if (neg) -res else res\n }\n fun nextString():String{\n val ret = StringBuilder()\n while (true){\n c = char\n if(!isWhitespace(c)){ break}\n }\n ret.append(c)\n while (true){\n c = char\n if(isWhitespace(c)){ break}\n ret.append(c)\n }\n return ret.toString()\n }\n fun isWhitespace(c:Char):Boolean{\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t'\n }\n fun rerouteInput(){\n if(warningActive){\n put(\"Custom test enabled\")\n println(\"Custom test enabled\")\n warningActive = false\n }\n val S = fakein.toString()\n println(\"New Case \")\n println(S.take(80))\n println(\"...\")\n fakein.clear()\n IN = BufferedInputStream(S.byteInputStream(),BS)\n }\n fun takeFile(name:String){\n IN = BufferedInputStream(File(name).inputStream(),BS)\n }\n}\nfun put(aa:Any){ Reader.OUT.println(aa)}\nfun done(){ Reader.OUT.close() }\nfun share(aa:Any){\n if(aa is IntArray){Reader.fakein.append(aa.joinToString(\" \"))}\n else if(aa is LongArray){Reader.fakein.append(aa.joinToString(\" \"))}\n else if(aa is List<*>){Reader.fakein.append(aa.toString())}\n else{Reader.fakein.append(aa.toString())}\n Reader.fakein.append(\"\\n\")\n}\n\nval getintfast:Int get() = Reader.nextInt()\nval getint:Int get(){ val ans = getlong ; if(ans > Int.MAX_VALUE) IntArray(1000000000); return ans.toInt() }\nval getlong:Long get() = Reader.nextLong()\nval getstr:String get() = Reader.nextString()\nfun getline(n:Int):IntArray{\n return IntArray(n){getint}\n}\nfun getlineL(n:Int):LongArray{\n return LongArray(n){getlong}\n}\nvar dmark = -1\ninfix fun Any.dei(a:Any){\n dmark++\n var str = \"<${dmark}> \"\n debug()\n if(this is String){ str += this\n }else if(this is Int){ str += this.toString()\n }else if(this is Long){ str += this.toString()\n }else{ str += this.toString()}\n if(a is List<*>){ println(\"$str : ${a.joinToString(\" \")}\")\n }else if(a is IntArray){ println(\"$str : ${a.joinToString(\" \")}\")\n }else if(a is LongArray){ println(\"$str : ${a.joinToString(\" \")}\")\n }else if(a is BooleanArray){ println(\"$str :${a.map{if(it)'1' else '0'}.joinToString(\" \")}\")\n }else if(a is Array<*>){\n println(\"$str : \")\n for(c in a){if(c is IntArray){println(c.joinToString(\" \"))}\n else if(c is LongArray){println(c.joinToString(\" \"))}\n else if(c is BooleanArray){println(c.map { if(it) '1' else '0' }.joinToString(\"\"))\n }\n }\n println()\n }else{ println(\"$str : $a\")\n }\n}\nval just = \" \"\nfun crash(){\n throw Exception(\"Bad programme\")}\nfun assert(a:Boolean){\n if(!a){\n throw Exception(\"Failed Assertion\")\n }}\nenum class solveMode {\n real, rand, tc\n}\nobject solve{\n var mode:solveMode = solveMode.real\n var tcNum:Int = 0\n var rand:()->Unit = {}\n var TC:MutableMapUnit> = mutableMapOf()\n var tn:Long = 0\n fun cases(onecase:()->Unit){\n val t = if(mode == solveMode.real){if(singleCase) 1 else getint} else if(mode == solveMode.tc){1 } else randCount\n if(pI != 998_244_353 && pI != 1_000_000_007){\n throw Exception(\"Not usual primes!\")\n }\n if(t == 1 && mode != solveMode.real){\n tn = System.currentTimeMillis()\n }\n repeat(t){\n if(mode == solveMode.tc){\n TC[tcNum]?.let { it() }\n Reader.rerouteInput()\n }else if(mode == solveMode.rand){\n rand()\n Reader.rerouteInput()\n }\n onecase()\n }\n if(t == 1 && mode != solveMode.real){\n val dt = System.currentTimeMillis() - tn\n println(\"Time $dt ms \")\n }\n }\n inline fun singleCase(a:solve.()->Unit){\n val t = if(mode != solveMode.rand){1} else randCount\n repeat(t) { a() }\n }\n fun rand(a:()->Unit){\n this.rand = a\n }\n fun tc(id:Int = 0,a:()->Unit){\n TC[id] = a\n }\n fun usetc(a:Int = 0 ){\n this.tcNum = a\n this.mode = solveMode.tc\n }\n fun userand(){\n this.mode = solveMode.rand\n }\n}\nfun debug(){}\nconst val singleCase = true\nfun main(){\n solve.cases{\n val n = getint\n val t = getint\n\n val can = Array(10){BooleanArray(10){true} }\n// for(i in 0 until 10) {\n// for(j in i until 10){\n// can[i][j] = true\n// }\n// }\n\n repeat(t){\n val a = getint\n val b = getint\n can[b][a] = false\n }\n var DP = IntArray(10){1}\n repeat(n-1){\n val new = IntArray(10)\n for(i in 0 until 10){\n for(j in 0 until 10){\n if(can[i][j]) {\n new[j] = new[j] modPlus DP[i]\n }\n }\n }\n DP = new\n }\n var ret = 0\n for(a in DP) {\n ret = ret modPlus a\n }\n put(ret)\n /*\n how many classes\n\n */\n\n\n\n }\n done()\n}\n\n\n\n\n"}], "src_uid": "60955fc2caa6ec99c7dcc1da5d36b1f8"} {"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 java.io.InputStream\nimport java.math.BigDecimal\nimport java.math.BigInteger\n\nfun main(args: Array) = input.run {\n val n = nextInt()\n val k = nextInt()\n val a = nextInts(n)\n val b = nextInts(k)\n b.sort()\n b.reverse()\n val ans = solve(a, b)\n println(if (ans) \"Yes\" else \"No\")\n}\n\nfun solve(a: IntArray, b: IntArray): Boolean {\n var i = 0\n a.indices.forEach {\n if (a[it] == 0) {\n a[it] = b[i++]\n }\n }\n return (1 until a.size).any {\n a[it] < a[it - 1]\n }\n}\n\nval input = FastScanner()\n\nfun String.toBigInteger() = BigInteger(this)\nfun String.toBigDecimal() = BigDecimal(this)\n\nclass FastScanner(private val input: InputStream = System.`in`) {\n private val sb = StringBuilder()\n private val buffer = ByteArray(4096)\n private var pos = 0\n private var size = 0\n\n fun nextString(): String? {\n var c = skipWhitespace()\n if (c < 0) return null\n\n return sb.run {\n setLength(0)\n\n do {\n append(c.toChar())\n c = read()\n } while (c > ' '.toInt())\n\n toString()\n }\n }\n\n fun nextLine(): String? {\n var c = read()\n if (c < 0) return null\n\n return sb.run {\n setLength(0)\n\n while (c >= 0 && c != '\\n'.toInt()) {\n append(c.toChar())\n c = read()\n }\n\n toString()\n }\n }\n\n fun nextLong(): Long {\n var c = skipWhitespace()\n\n val sign = if (c == '-'.toInt()) {\n c = read()\n -1\n } else 1\n\n var ans = 0L\n\n while (c > ' '.toInt()) {\n ans = ans * 10 + c - '0'.toInt()\n c = read()\n }\n\n return sign * ans\n }\n\n fun nextInt() = nextLong().toInt()\n fun nextDouble() = nextString()?.toDouble() ?: 0.0\n fun nextBigInteger(): BigInteger = nextString()?.toBigInteger() ?: BigInteger.ZERO\n fun nextBigDecimal(): BigDecimal = nextString()?.toBigDecimal() ?: BigDecimal.ZERO\n\n fun nextStrings(n: Int) = Array(n) { nextString() ?: \"\" }\n fun nextInts(n: Int) = IntArray(n) { nextInt() }\n fun nextLongs(n: Int) = LongArray(n) { nextLong() }\n fun nextDoubles(n: Int) = DoubleArray(n) { nextDouble() }\n fun nextBigIntegers(n: Int) = Array(n) { nextBigInteger() }\n fun nextBigDecimals(n: Int) = Array(n) { nextBigDecimal() }\n\n fun nextStrings(n: Int, m: Int) = Array(n) { nextStrings(m) }\n fun nextInts(n: Int, m: Int) = Array(n) { nextInts(m) }\n fun nextLongs(n: Int, m: Int) = Array(n) { nextLongs(m) }\n fun nextDoubles(n: Int, m: Int) = Array(n) { nextDoubles(m) }\n fun nextBigIntegers(n: Int, m: Int) = Array(n) { nextBigIntegers(m) }\n fun nextBigDecimals(n: Int, m: Int) = Array(n) { nextBigDecimals(m) }\n\n private fun skipWhitespace(): Int {\n while (true) {\n val c = read()\n if (c > ' '.toInt() || c < 0) return c\n }\n }\n\n private fun read(): Int {\n while (pos >= size) {\n if (size < 0) return -1\n size = input.read(buffer, 0, buffer.size)\n pos = 0\n }\n return buffer[pos++].toInt()\n }\n}\n"}, {"source_code": "import java.io.File\nimport java.io.InputStream\nimport java.util.*\n\nfun solve(inp: InputReader) {\n val (n, k) = readLine()!!.split(\" \").map(String::toInt)\n val seqA = readLine()!!.split(\" \").map(String::toInt).toMutableList()\n val seqB = readLine()!!.split(\" \").map(String::toInt).toMutableList()\n\n if (k > 1) {\n println(\"Yes\")\n } else {\n seqA[seqA.indexOf(0)] = seqB[0]\n val isAscending = (1..n-1).all { i -> seqA[i] > seqA[i - 1] }\n println(if (isAscending) \"No\" else \"Yes\")\n }\n}\n\n\nfun main(args: Array) = solve(initIO(\"Mine\" in args))\n\nfun initIO(isLocal: Boolean) = when (isLocal) {\n true -> InputReader(File(\"input.txt\").inputStream())\n false -> InputReader(System.`in`)\n}\n\nclass InputReader(inputStream: InputStream) {\n val reader = inputStream.bufferedReader()\n var tokenizer = StringTokenizer(\"\")\n\n fun nextLine(): String = when {\n tokenizer.hasMoreTokens() -> tokenizer.nextToken(\"\")!!\n else -> reader.readLine()!!\n }\n\n fun nextWord(): String {\n while (!tokenizer.hasMoreTokens()) {\n tokenizer = StringTokenizer(nextLine())\n }\n return tokenizer.nextToken()!!\n }\n\n fun nextInt() = nextWord().toInt()\n\n fun nextLong() = nextWord().toLong()\n}\n\n"}, {"source_code": "import java.util.*\n\n/**\n * Created by Administrator on 2017/6/8.\n */\nfun isSort(a: Array, b: Int): Boolean {\n\n var last = 0\n for (i in 0..a.size-1){\n if(a[i]==0)\n a[i] = b\n if (0 == i){\n last = a[i]\n }else {\n \n if (a[i]) {\n\n var out = Scanner(System.`in`)\n var aLen = out.nextInt()\n var bLen = out.nextInt()\n var a = Array(aLen,{out.nextInt()})\n var b = Array(bLen,{out.nextInt()})\n // println(b[0])\n if (bLen>=2){\n println(\"Yes\")\n }else if (isSort(a,b[0])){\n println(\"No\")\n }else{\n println(\"Yes\")\n }\n\n}\n"}, {"source_code": "import java.util.*\n\nfun main(vararg args: String) {\n\n // TODO: KEEP\n// naturalOrder()\n fun IntArray.isOrdered() = if (size <= 1) true else (1 until size).all { this[it - 1] <= this[it] }\n\n with(Scanner(System.`in`)) {\n val n = nextInt()\n val k = nextInt()\n val a = IntArray(n) { nextInt() }\n val b = IntArray(k) { nextInt() }\n var r = k > 1\n if (!r) {\n a[a.indices.find { a[it] == 0 }!!] = b[0]\n r = !a.isOrdered()\n }\n println(if (r) \"Yes\" else \"No\")\n }\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nval LOCAL_MODE = true\n\nfun main(args: Array) {\n val input: InputReader\n val output: PrintWriter\n if (false) {\n input = InputReader(FileInputStream(\"input.txt\"))\n output = PrintWriter(FileOutputStream(\"output.txt\"))\n } else {\n input = InputReader(System.`in`)\n output = PrintWriter(System.out)\n }\n Solver(input, output).run()\n input.close()\n output.close()\n}\n\nfun debug(x: Any) {\n if (LOCAL_MODE) {\n System.err.println(x)\n }\n}\n\nclass Solver(val input: InputReader, val output: PrintWriter) {\n\n companion object {\n val MOD = (1e9 + 7).toInt()\n }\n\n fun run() {\n if (true) {\n read()\n// output.println(solve())\n } else {\n for (stress in generateSequence({ 1 }, { it + 1 })) {\n debug(\"Stress #$stress\")\n generateStress()\n printStress()\n val my = solve()\n val slow = slow()\n// require(my == slow, { \"$my != $slow\" })\n }\n }\n\n }\n\n private fun printStress() {\n }\n\n private fun generateStress() {\n }\n\n private var n: Int = 0\n private var k: Int = 0\n\n private fun read() {\n n = input.nextInt()\n k = input.nextInt()\n val a = (1..n).map { input.nextInt() }.toMutableList()\n val b = (1..k).map { input.nextInt() }.sortedDescending()\n var j = 0\n for (i in 0..n - 1) {\n if (a[i] == 0) {\n a[i] = b[j++]\n }\n }\n val sorted = a.sorted()\n if (a == sorted) {\n output.println(\"No\")\n } else {\n output.println(\"Yes\")\n }\n\n }\n\n private fun slow(): Int = 0\n\n private fun solve() {\n }\n\n\n}\n\n\nclass InputReader(val stream: InputStream) : Closeable {\n\n var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n\n var tokenizer: StringTokenizer? = null\n\n override fun close() {\n stream.close()\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int = next().toInt()\n\n fun nextLong(): Long = next().toLong()\n\n}"}, {"source_code": "fun main() {\n var (n, m) = readInts()\n var numbers = readInts().toMutableList()\n var toPut = readInts().sorted()\n if (toPut.size > 1 || n == m) {\n println(\"YES\")\n } else {\n for (i in 0 until numbers.size) {\n if (numbers[i] == 0) {\n numbers[i] = toPut[0]\n }\n }\n checkIsIcreasing(numbers)\n }\n}\n\nprivate fun checkIsIcreasing(a: List) {\n for (i in 1 until a.size) {\n if (a[i] < a[i - 1]) {\n println(\"YES\")\n return\n }\n }\n println(\"NO\")\n}\n\nprivate fun readInts(): List = readLine()!!.split(' ').map { it.toInt() }\nprivate fun readLongs(): List = readLine()!!.split(' ').map { it.toLong() }\nprivate fun readInt(): Int = readLine()!!.toInt()\nprivate fun readLong(): Long = readLine()!!.toLong()\nprivate fun readStr(): String? = readLine()!!"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (n, k) = readInts()\n if (k > 1) return print(\"Yes\")\n val a = readInts().toIntArray()\n for (pos in 0 until n)\n if (a[pos] == 0) {\n a[pos] = readInt()\n break\n }\n if (a.first() == a.last()) return print(\"Yes\")\n for (pos in 0 until n - 1)\n if (a[pos + 1] < a[pos]) return print(\"Yes\")\n print(\"No\")\n}"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (n, k) = readInts()\n if (k > 1) return print(\"Yes\")\n val a = mutableListOf(-1)\n a.addAll(readInts())\n val aArr = a.toIntArray()\n for (pos in 1..n) {\n if (aArr[pos] == 0) aArr[pos] = readInt()\n if (aArr[pos] < aArr[pos - 1]) return print(\"Yes\")\n }\n print(\"No\")\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.PrintWriter\nimport java.util.*\n\nclass Solver {\n\n fun input(inp: FastInputReader) {\n val n = inp.readInt()\n val k = inp.readInt()\n\n val a = inp.readIntArray(n)\n val b = inp.readIntArray(k)\n b.sortDescending()\n\n var j = 0\n for (i in a.indices)\n if (a[i] == 0)\n {\n a[i] = b[j]\n j++\n }\n for (i in 1..a.size - 1)\n if (a[i-1] >= a[i]) {\n println(\"Yes\")\n return\n }\n println(\"No\")\n }\n\n fun solve() {\n\n }\n\n}\n\nobject Algorithms {\n\n tailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)\n tailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\n\n fun lcm(a: Int, b: Int): Int = a / gcd(a, b) * b\n fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b\n\n}\n\nclass FastInputReader {\n\n private val bufferedReader: BufferedReader = System.`in`.bufferedReader()\n private var stringTokenizer: StringTokenizer = StringTokenizer(\"\")\n\n fun nextLine(): String = bufferedReader.readLine()\n fun next(): String {\n while (!stringTokenizer.hasMoreTokens())\n stringTokenizer = StringTokenizer(nextLine())\n return stringTokenizer.nextToken()\n }\n\n fun readInt(): Int = next().toInt()\n fun readLong(): Long = next().toLong()\n fun readDouble(): Double = next().toDouble()\n\n fun readIntArray(size: Int) = IntArray(size, { readInt() })\n fun readLongArray(size: Int) = LongArray(size, { readLong() })\n fun readStringArray(size: Int) = Array(size, { next() })\n inline fun readTArray(size: Int, convert: (Int, String) -> T) = Array(size, { convert(it, next()) })\n\n fun readIntTable(rows: Int, cols: Int) = Array(rows, { readIntArray(cols) })\n fun readLongTable(rows: Int, cols: Int) = Array(rows, { readLongArray(cols) })\n fun readStringTable(rows: Int, cols: Int) = Array(rows, { readStringArray(cols) })\n inline fun readTTable(rows: Int, cols: Int, convert: (Int, Int, String) -> T) = Array(rows, { row -> readTArray(cols, { col, s -> convert(row, col, s) }) })\n\n}\n\nfun main(args: Array) {\n\n// val millis = measureTimeMillis(Solver()::solve)\n// System.err.println(\"Time spent: $millis\")\n val solver = Solver()\n solver.input(FastInputReader())\n solver.solve()\n\n}\n"}, {"source_code": "fun main(args: Array) {\n val (n, k) = readLine()!!.split(\" \").map(String::toInt)\n val a = readLine()!!.split(\" \").map(String::toInt).toIntArray()\n val b = readLine()!!.split(\" \").map(String::toInt)\n\n if (k > 1) {\n println(\"YES\")\n } else {\n (0..a.lastIndex)\n .filter { a[it] == 0 }\n .forEach { a[it] = b[0] }\n val yes = (1..a.lastIndex).any { a[it] < a[it - 1] }\n println(if (yes) \"YES\" else \"NO\")\n }\n\n}"}], "negative_code": [{"source_code": "import java.util.*\n\n/**\n * Created by Administrator on 2017/6/8.\n */\nfun isSort(a: Array): Boolean {\n\n var last = 0;\n for (i in 0..a.size){\n if (0 == i){\n last = a[i]\n }else if(a[i]!=0){\n if (a[i]>last)\n return false\n else last = a[i]\n }\n }\n return true\n}\n fun main(args: Array) {\n\n var out = Scanner(System.`in`)\n var aLen = out.nextInt()\n var bLen = out.nextInt()\n var a = Array(aLen,{out.nextInt()})\n var b = Array(bLen,{out.nextInt()})\n if (bLen>=2){\n println(\"Yes\")\n }else if (isSort(a)){\n println(\"No\")\n }else{\n println(\"Yes\")\n }\n\n}\n"}, {"source_code": "import java.util.*\n\n/**\n * Created by Administrator on 2017/6/8.\n */\nfun isSort(a: Array, b: Int): Boolean {\n\n var last = 0\n for (i in 0..a.size-1){\n if (0 == i){\n last = a[i]\n }else if(a[i]!=0){\n if (a[i]) {\n\n var out = Scanner(System.`in`)\n var aLen = out.nextInt()\n var bLen = out.nextInt()\n var a = Array(aLen,{out.nextInt()})\n var b = Array(bLen,{out.nextInt()})\n // println(b[0])\n if (bLen>=2){\n println(\"Yes\")\n }else if (isSort(a,b[0])){\n println(\"No\")\n }else{\n println(\"Yes\")\n }\n\n}"}, {"source_code": "\nimport java.util.*\n\nfun isSort(a: Array): Boolean {\n\n var last = 0;\n for (i in 0..a.size){\n if (0 == i){\n last = a[i]\n }else if(a[i]!=0){\n if (a[i]>last)\n return false\n else last = a[i]\n }\n }\n return true\n}\n fun main(args: Array) {\n\n var out = Scanner(System.`in`)\n var aLen = out.nextInt()\n var bLen = out.nextInt()\n var a = Array(aLen,{out.nextInt()})\n var b = Array(bLen,{out.nextInt()})\n if (bLen>=2){\n println(\"Yes\")\n }else if (isSort(a)){\n println(\"Yes\")\n }else{\n println(\"No\")\n }\n\n}\n\n\n\n\n\n"}, {"source_code": "import java.util.*\n\n/**\n * Created by Administrator on 2017/6/8.\n */\nfun isSort(a: Array, i: Int): Boolean {\n\n var last = 0;\n for (i in 0..a.size-1){\n if (0 == i){\n last = a[i]\n }else if(a[i]!=0){\n if (a[i]) {\n\n var out = Scanner(System.`in`)\n var aLen = out.nextInt()\n var bLen = out.nextInt()\n var a = Array(aLen,{out.nextInt()})\n var b = Array(bLen,{out.nextInt()})\n if (bLen>=2){\n println(\"Yes\")\n }else if (isSort(a,b[0])){\n println(\"No\")\n }else{\n println(\"Yes\")\n }\n\n}"}, {"source_code": "import java.util.*\n\n/**\n * Created by Administrator on 2017/6/8.\n */\nfun isSort(a: Array, b: Int): Boolean {\n\n var last = 0\n for (i in 0..a.size-1){\n if (0 == i){\n last = a[i]\n }else {\n if(a[i]==0)\n a[i] = b\n if (a[i]) {\n\n var out = Scanner(System.`in`)\n var aLen = out.nextInt()\n var bLen = out.nextInt()\n var a = Array(aLen,{out.nextInt()})\n var b = Array(bLen,{out.nextInt()})\n // println(b[0])\n if (bLen>=2){\n println(\"Yes\")\n }else if (isSort(a,b[0])){\n println(\"No\")\n }else{\n println(\"Yes\")\n }\n\n}"}, {"source_code": "\nimport java.util.*\n\nfun isSort(a: Array): Boolean {\n\n var last = 0;\n for (i in 0..a.size){\n if (0 == i){\n last = a[i]\n }else if(a[i]!=0){\n if (a[i]>last)\n return false\n else last = a[i]\n }\n }\n return true\n}\n fun main(args: Array) {\n \n var out = Scanner(System.`in`)\n var aLen = out.nextInt()\n var bLen = out.nextInt()\n var a = Array(aLen,{out.nextInt()})\n var b = Array(bLen,{out.nextInt()})\n if (bLen>=2){\n println(\"Yse\")\n }else if (isSort(a)){\n println(\"Yse\")\n }else{\n println(\"No\")\n }\n\n}\n\n\n\n\n\n"}, {"source_code": "import java.util.*\n\n/**\n * Created by Administrator on 2017/6/8.\n */\nfun isSort(a: Array): Boolean {\n\n var last = 0;\n for (i in 0..a.size-1){\n if (0 == i){\n last = a[i]\n }else if(a[i]!=0){\n if (a[i]) {\n\n var out = Scanner(System.`in`)\n var aLen = out.nextInt()\n var bLen = out.nextInt()\n var a = Array(aLen,{out.nextInt()})\n var b = Array(bLen,{out.nextInt()})\n if (bLen>=2){\n println(\"Yes\")\n }else if (isSort(a)){\n println(\"No\")\n }else{\n println(\"Yes\")\n }\n\n}"}, {"source_code": "fun main() {\n var (n, m) = readInts()\n var numbers = readInts()\n var toPut = readInts().sorted()\n if (toPut.size > 1) {\n println(\"YES\")\n } else {\n for (i in 0 until numbers.size) {\n if (numbers[i] == 0) {\n if (i != 0 && i != n - 1) {\n if (toPut[0] < numbers[i - 1] || toPut[0] > numbers[i + 1]) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n } else {\n if (i == 0) {\n if (toPut[0] > numbers[i + 1]) {\n println(\"YES\")\n } else {\n checkIsIcreasing(numbers)\n }\n } else {\n if (toPut[0] < numbers[n - 1]) {\n println(\"YES\")\n } else {\n checkIsIcreasing(numbers)\n }\n }\n }\n }\n }\n }\n}\n\nprivate fun checkIsIcreasing(a: List) {\n for (i in 1 until a.size) {\n if (a[i] < a[i - 1]) {\n println(\"YES\")\n return\n }\n println(\"NO\")\n }\n}\n\nprivate fun readInts(): List = readLine()!!.split(' ').map { it.toInt() }\nprivate fun readLongs(): List = readLine()!!.split(' ').map { it.toLong() }\nprivate fun readInt(): Int = readLine()!!.toInt()\nprivate fun readLong(): Long = readLine()!!.toLong()\nprivate fun readStr(): String? = readLine()!!"}, {"source_code": "fun main() {\n var (n, m) = readInts()\n var numbers = readInts().toMutableList()\n var toPut = readInts().sorted()\n if (toPut.size > 1) {\n println(\"YES\")\n } else {\n for (i in 0 until numbers.size) {\n if (numbers[i] == 0) {\n if (i != 0 && i != n - 1) {\n if (toPut[0] < numbers[i - 1] || toPut[0] > numbers[i + 1]) {\n println(\"YES\")\n } else {\n numbers.set(i, toPut[0])\n checkIsIcreasing(numbers)\n }\n } else {\n if (i == 0) {\n if (toPut[0] > numbers[i + 1]) {\n println(\"YES\")\n } else {\n checkIsIcreasing(numbers)\n }\n } else {\n if (toPut[0] < numbers[n - 1]) {\n println(\"YES\")\n } else {\n checkIsIcreasing(numbers)\n }\n }\n }\n }\n }\n }\n}\n\nprivate fun checkIsIcreasing(a: List) {\n for (i in 1 until a.size) {\n if (a[i] < a[i - 1]) {\n println(\"YES\")\n return\n }\n println(\"NO\")\n }\n}\n\nprivate fun readInts(): List = readLine()!!.split(' ').map { it.toInt() }\nprivate fun readLongs(): List = readLine()!!.split(' ').map { it.toLong() }\nprivate fun readInt(): Int = readLine()!!.toInt()\nprivate fun readLong(): Long = readLine()!!.toLong()\nprivate fun readStr(): String? = readLine()!!"}, {"source_code": "fun main() {\n var (n, m) = readInts()\n var numbers = readInts().toMutableList()\n var toPut = readInts().sorted()\n if (toPut.size > 1) {\n println(\"YES\")\n } else {\n for (i in 0 until numbers.size) {\n if (numbers[i] == 0) {\n if (i != 0 && i != n - 1) {\n if (toPut[0] < numbers[i - 1] || toPut[0] > numbers[i + 1]) {\n println(\"YES\")\n } else {\n numbers.set(i, toPut[0])\n checkIsIcreasing(numbers)\n }\n } else {\n if (i == 0) {\n if (toPut[0] > numbers[i + 1]) {\n println(\"YES\")\n } else {\n checkIsIcreasing(numbers)\n }\n } else {\n if (toPut[0] < numbers[n - 1]) {\n println(\"YES\")\n } else {\n checkIsIcreasing(numbers)\n }\n }\n }\n }\n }\n }\n}\n\nprivate fun checkIsIcreasing(a: List) {\n for (i in 1 until a.size) {\n if (a[i] < a[i - 1]) {\n println(\"YES\")\n return\n }\n println(\"NO\")\n return\n }\n}\n\nprivate fun readInts(): List = readLine()!!.split(' ').map { it.toInt() }\nprivate fun readLongs(): List = readLine()!!.split(' ').map { it.toLong() }\nprivate fun readInt(): Int = readLine()!!.toInt()\nprivate fun readLong(): Long = readLine()!!.toLong()\nprivate fun readStr(): String? = readLine()!!"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (n, k) = readInts()\n if (k > 1) return print(\"Yes\")\n val a = mutableListOf(-1)\n a.addAll(readInts())\n for (pos in 1..n)\n if (a[pos] == 0) {\n if (readInt() < a[pos - 1]) return print(\"Yes\")\n } else if (a[pos] < a[pos - 1]) return print(\"Yes\")\n print(\"No\")\n}"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (n, k) = readInts()\n if (k > 1) return print(\"Yes\")\n val a = mutableListOf(-1)\n a.addAll(readInts())\n for (pos in 1 until n)\n if (a[pos] == 0) {\n if (readInt() < a[pos - 1]) return print(\"Yes\")\n } else if (a[pos] < a[pos - 1]) return print(\"Yes\")\n print(\"No\")\n}"}], "src_uid": "40264e84c041fcfb4f8c0af784df102a"} {"nl": {"description": "Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.", "input_spec": "You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.", "output_spec": "Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.", "sample_inputs": ["000000", "123456", "111000"], "sample_outputs": ["0", "2", "1"], "notes": "NoteIn the first example the ticket is already lucky, so the answer is 0.In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required."}, "positive_code": [{"source_code": "import java.io.PrintWriter\nimport java.lang.StringBuilder\nimport kotlin.math.*\n\nfun main() {\n io.apply {\n\n val x = str(6).map { it - '0' }.toIntArray()\n var left = x.sliceArray(0..2).sortedArray()\n var right = x.sliceArray(3..5).sortedArray()\n\n var delta = right.sum() - left.sum()\n if (delta < 0) {\n val tmp = left\n left = right\n right = tmp\n delta = - delta\n }\n // left < right\n val deltas = ArrayList()\n left.forEach { deltas.add(9 - it) }\n right.forEach { deltas.add(it) }\n deltas.sortDescending()\n val ans = when {\n delta == 0 -> 0\n delta <= deltas[0] -> 1\n delta <= deltas[0] + deltas[1] -> 2\n else -> 3\n }\n\n cout .. ans .. nl\n\n\n }.cout.flush()\n}\n\n// @formatter:off\nprivate val io = object {\n private val `in` = System.`in`\n private fun ll(): Long {\n var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }\n do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n\n }\n val int get() = ll().toInt(); val long get() = ll()\n fun ints(n: Int = int): IntArray { return IntArray(n) { int } }\n fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }\n val cout = PrintWriter(System.out); val nl = \"\\n\"\n private var buf = CharArray(32)\n private var bufSize = 32\n fun str(expect: Int = 32): String {\n var ix = 0\n var x: Int\n if (bufSize < expect)\n buf = CharArray(expect)\n do x = `in`.read() while (x < 33)\n do {\n if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }\n buf[ix++] = x.toChar()\n x = `in`.read()\n } while (x > 32)\n return java.lang.String.copyValueOf(buf, 0, ix)\n }\n operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(\" \") }; return this }\n operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }\n} // @formatter:on\n\n/* ----------- */\n\n"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.*\n\nfun main(){\n\tval f = BufferedReader(InputStreamReader(System.`in`))\n\n\tval a = f.readLine().map{Character.getNumericValue(it)}.toIntArray()\n\n\tval sum1 = a[0] + a[1] + a[2]\n\tval sum2 = a[3] + a[4] + a[5]\n\n\tif(sum1 == sum2) println(0)\n\telse{\n\n\t\tval a1 = IntArray(3){a[it]}.sorted()\n\t\tval a2 = IntArray(3){a[it+3]}.sorted()\n\n\t\tval changes = IntArray(6)\n\t\t//check 1\n\t\tif(sum1 > sum2){\n\t\t\t//get max 3\n\t\t\tfor(k in 0 until 3){\n\t\t\t\tchanges[k] = a1[k]\n\t\t\t\tchanges[k+3] = 9-a2[k]\n\t\t\t}\n\t\t} else {\n\t\t\tfor(k in 0 until 3){\n\t\t\t\tchanges[k] = a2[k]\n\t\t\t\tchanges[k+3] = 9-a1[k]\n\t\t\t}\n\t\t}\n\n\t\tchanges.sort()\n\n\t\tval dif = Math.abs(sum1-sum2)\n\n\t\tvar sumdif = 0\n\t\tvar answer = 0\n\t\tvar i = 5\n\t\twhile(sumdif < dif){\n\t\t\tsumdif += changes[i]\n\t\t\ti--\n\t\t\tanswer++\n\t\t}\n\n\t\tprintln(answer)\n\t}\n}\n"}, {"source_code": "import kotlin.math.*\n\nval sc = java.util.Scanner(System.`in`)\nfun main(args: Array) {\n\tval n = sc.nextInt()\n\tvar ans = 6\n\tfor (i in 0..999999)\n\t\tif (islucky(i))\n\t\t\tans = min(ans, different(n, i))\n\tprintln(ans)\n}\n\nfun islucky(x: Int) =\n\t\tx % 10 + x / 10 % 10 + x / 100 % 10 ==\n\t\t\t\tx / 1000 % 10 + x / 10000 % 10 + x / 100000\n\nfun different(x: Int, y: Int): Int {\n\tvar ans = 0\n\tvar a = x\n\tvar b = y\n\tfor (i in 1..6) {\n\t\tif (a % 10 != b % 10)\n\t\t\tans++\n\t\ta /= 10\n\t\tb /= 10\n\t}\n\treturn ans;\n}"}, {"source_code": "import java.util.*\nfun main(args: Array) {\n val digits = readLine()!!.toCharArray().map { Character.getNumericValue(it) }\n\n val left = digits.take(3).toMutableList()\n val right = digits.takeLast(3).toMutableList()\n\n println(solve(left, right))\n}\n\ntailrec fun solve(left: MutableList, right: MutableList, steps: Int = 0): Int {\n val leftSum = left.sum()\n val rightSum = right.sum()\n if (leftSum == rightSum) return steps\n\n val delta = leftSum - rightSum\n var larger = if (delta>0) left else right\n val smaller = if (delta>0) right else left\n\n val largerDecreases = larger.sortedDescending()\n val smallerIncreases = smaller.map { 9-it }\n\n val maxDecrease = largerDecreases.max()!!\n val maxIncrease = smallerIncreases.max()!!\n\n if(Math.max(maxDecrease, maxIncrease) >= Math.abs(delta)) {\n return steps+1\n }\n\n fun getIndex(list: List, number: Int?): Int = if (number == null) 0 else list.indexOf(number)\n\n if (maxIncrease>maxDecrease) {\n smaller[getIndex(smaller, smaller.min())] = 9\n return solve(smaller, larger, steps+1)\n }\n larger[getIndex(larger, larger.max())] = 0\n return solve(smaller, larger, steps+1)\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.*\n\nfun main(){\n\tval f = BufferedReader(InputStreamReader(System.`in`))\n\n\tval a = f.readLine().map{Character.getNumericValue(it)}.toIntArray()\n\n\tval sum1 = a[0] + a[1] + a[2]\n\tval sum2 = a[3] + a[4] + a[5]\n\n\tif(sum1 == sum2) println(0)\n\telse{\n\n\t\tval a1 = IntArray(3){a[it]}.sorted()\n\t\tval a2 = IntArray(3){a[it+3]}.sorted()\n\n\t\tval changes = IntArray(6)\n\t\t//check 1\n\t\tif(sum1 > sum2){\n\t\t\t//get max 3\n\t\t\tfor(k in 0 until 3){\n\t\t\t\tchanges[k] = a1[k]\n\t\t\t\tchanges[k+3] = 9-a2[k]\n\t\t\t}\n\t\t} else {\n\t\t\tfor(k in 0 until 3){\n\t\t\t\tchanges[k] = a2[k]\n\t\t\t\tchanges[k+3] = 9-a1[k]\n\t\t\t}\n\t\t}\n\n\t\tchanges.sort()\n\n\t\tval dif = Math.abs(sum1-sum2)\n\n\t\tvar sumdif = 0\n\t\tvar answer = 0\n\t\tvar i = 5\n\t\twhile(sumdif < dif){\n\t\t\tsumdif += changes[i]\n\t\t\ti--\n\t\t\tanswer++\n\t\t}\n\n\t\tprintln(answer)\n\t}\n}\n"}], "negative_code": [{"source_code": "import kotlin.math.*\n\nval sc = java.util.Scanner(System.`in`)\nfun main(args: Array) {\n\tval n = sc.nextInt()\n\tvar ans = 6\n\tfor (i in 0..999999)\n\t\tif (islucky(i))\n\t\t\tans = min(ans, different(n, i))\n\tprintln(ans)\n}\n\nfun islucky(x: Int) =\n\t\tx % 1000 == x / 1000 % 10 + x / 10000 % 10 + x / 100000\n\nfun different(x: Int, y: Int): Int {\n\tvar ans = 0\n\tvar a = x\n\tvar b = y\n\tfor (i in 1..6) {\n\t\tif (a % 10 != b % 10)\n\t\t\tans++\n\t\ta /= 10\n\t\tb /= 10\n\t}\n\treturn ans;\n}"}], "src_uid": "09601fd1742ffdc9f822950f1d3e8494"} {"nl": {"description": "Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.There will be n problems. The i-th problem has initial score pi and it takes exactly ti minutes to solve it. Problems are sorted by difficulty — it's guaranteed that pi < pi + 1 and ti < ti + 1.A constant c is given too, representing the speed of loosing points. Then, submitting the i-th problem at time x (x minutes after the start of the contest) gives max(0,  pi - c·x) points.Limak is going to solve problems in order 1, 2, ..., n (sorted increasingly by pi). Radewoosh is going to solve them in order n, n - 1, ..., 1 (sorted decreasingly by pi). Your task is to predict the outcome — print the name of the winner (person who gets more points at the end) or a word \"Tie\" in case of a tie.You may assume that the duration of the competition is greater or equal than the sum of all ti. That means both Limak and Radewoosh will accept all n problems.", "input_spec": "The first line contains two integers n and c (1 ≤ n ≤ 50, 1 ≤ c ≤ 1000) — the number of problems and the constant representing the speed of loosing points. The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ 1000, pi < pi + 1) — initial scores. The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 1000, ti < ti + 1) where ti denotes the number of minutes one needs to solve the i-th problem.", "output_spec": "Print \"Limak\" (without quotes) if Limak will get more points in total. Print \"Radewoosh\" (without quotes) if Radewoosh will get more points in total. Print \"Tie\" (without quotes) if Limak and Radewoosh will get the same total number of points.", "sample_inputs": ["3 2\n50 85 250\n10 15 25", "3 6\n50 85 250\n10 15 25", "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76"], "sample_outputs": ["Limak", "Radewoosh", "Tie"], "notes": "NoteIn the first sample, there are 3 problems. Limak solves them as follows: Limak spends 10 minutes on the 1-st problem and he gets 50 - c·10 = 50 - 2·10 = 30 points. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85 - 2·25 = 35 points. He spends 25 minutes on the 3-rd problem so he submits it 10 + 15 + 25 = 50 minutes after the start. For this problem he gets 250 - 2·50 = 150 points. So, Limak got 30 + 35 + 150 = 215 points.Radewoosh solves problem in the reversed order: Radewoosh solves 3-rd problem after 25 minutes so he gets 250 - 2·25 = 200 points. He spends 15 minutes on the 2-nd problem so he submits it 25 + 15 = 40 minutes after the start. He gets 85 - 2·40 = 5 points for this problem. He spends 10 minutes on the 1-st problem so he submits it 25 + 15 + 10 = 50 minutes after the start. He gets max(0, 50 - 2·50) = max(0,  - 50) = 0 points. Radewoosh got 200 + 5 + 0 = 205 points in total. Limak has 215 points so Limak wins.In the second sample, Limak will get 0 points for each problem and Radewoosh will first solve the hardest problem and he will get 250 - 6·25 = 100 points for that. Radewoosh will get 0 points for other two problems but he is the winner anyway.In the third sample, Limak will get 2 points for the 1-st problem and 2 points for the 2-nd problem. Radewoosh will get 4 points for the 8-th problem. They won't get points for other problems and thus there is a tie because 2 + 2 = 4."}, "positive_code": [{"source_code": "import kotlin.math.max\n\n/* http://codeforces.com/problemset/problem/658/A */\n\nfun main() {\n val (_, losingRate) = readLine()!!.split(\" \").map { it.toInt() }\n val scores = readLine()!!.split(\" \").map { it.toInt() }\n val times = readLine()!!.split(\" \").map { it.toInt() }\n val timesPassed = times.sumPrefixes()\n val scoresReversed = scores.asReversed()\n val timesReversed = times.asReversed()\n val timesReversedPassed = timesReversed.sumPrefixes()\n val limakScore = scores.mapIndexed { index, score -> max(0, score - losingRate * timesPassed[index]) }.sum()\n val radewooshScore = scoresReversed.mapIndexed { index, score -> max(0, score - losingRate * timesReversedPassed[index]) }.sum()\n when {\n limakScore > radewooshScore -> println(\"Limak\")\n radewooshScore > limakScore -> println(\"Radewoosh\")\n else -> println(\"Tie\")\n }\n}\n\nprivate fun List.sumPrefixes(): List {\n if (this.isEmpty()) {\n return emptyList()\n }\n val resultList = ArrayList(this.size)\n resultList.add(this[0])\n for (i in 1 until this.size) {\n resultList.add(resultList[i - 1] + this[i])\n }\n return resultList\n}"}, {"source_code": "fun main(args: Array) {\n val reader = java.util.Scanner(System.`in`)\n val n = reader.nextInt()\n val c = reader.nextInt()\n val ps = ArrayList(n)\n val pssum = ArrayList(n)\n val pssumrev = ArrayList(n)\n\n val ts = ArrayList(n)\n for (i in 1..n) {\n ps.add(reader.nextInt())\n pssum.add(0)\n pssumrev.add(0)\n }\n\n for (i in 1..n)\n ts.add(reader.nextInt())\n\n var sum : Int=0\n var sumrev : Int = 0\n for (i in ts.indices) {\n sum += ts[i]\n sumrev += ts[n-i-1]\n pssum[i]=sum\n pssumrev[n-i-1]=sumrev\n }\n\n val a= ps.zip(pssum){a, b -> if (a if (ab) \"Limak\" else \"Radewoosh\"\n println(r)\n //println(\"Limak=$a Radewoosh=$b\")\n\n\n}"}, {"source_code": "import kotlin.math.max\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (_, constant) = readInts()\n val scores = readInts()\n val minutes = readInts()\n var limak = 0\n var radewoosh = 0\n var spentMinutes = 0\n for (pos in scores.indices) {\n spentMinutes += minutes[pos]\n limak += max(0, scores[pos] - constant * spentMinutes)\n }\n spentMinutes = 0\n for (pos in scores.indices.reversed()) {\n spentMinutes += minutes[pos]\n radewoosh += max(0, scores[pos] - constant * spentMinutes)\n }\n print(\n when {\n limak > radewoosh -> \"Limak\"\n limak == radewoosh -> \"Tie\"\n else -> \"Radewoosh\"\n }\n )\n}"}, {"source_code": "fun main(args: Array){\n\tvar tmpTime = 0\n\tvar Limak = 0\n\tvar Radewoosh = 0\n\n\tval (N,c) = readLine()!!.split(' ')\n\n\tval points = readLine()!!.split(' ').map { it.toInt() }\n\tval time = readLine()!!.split(' ').map { it.toInt() }\n\n\tfor(i in 0 until N.toInt()){\n\t\ttmpTime += time[i]\n\t\tif(points[i]-tmpTime*c.toInt() < 0){\n\t\t\tcontinue\n\t\t}else{\n\t\t\tLimak += points[i]-tmpTime*c.toInt()\n\t\t}\n\t}\n\ttmpTime = 0\n\tfor(i in N.toInt()-1 downTo 0){\n\t\ttmpTime += time[i]\n\t\tif(points[i]-tmpTime*c.toInt() < 0){\n\t\t\tcontinue\n\t\t}else{\n\t\t\tRadewoosh += points[i]-tmpTime*c.toInt()\n\t\t}\n\t}\n\twhen {\n\t\tLimak > Radewoosh -> println(\"Limak\")\n\t\tLimak < Radewoosh -> println(\"Radewoosh\")\n\t\telse -> println(\"Tie\")\n\t}\n\n}"}, {"source_code": "import kotlin.math.max\n\nfun score(p: Int, c: Int, x: Int) : Int {\n return max(0, p-c*x)\n}\n\nfun main(args: Array) {\n val (n, c) = readLine()!!.split(\" \").map(String::toInt)\n val p = readLine()!!.split(\" \").map(String::toInt)\n val t = readLine()!!.split(\" \").map(String::toInt)\n var (score_limak, score_radewoosh) = listOf(0, 0)\n var (time_limak, time_radewoosh) = listOf(0, 0)\n for(i in 0..n-1) {\n time_limak += t[i]\n score_limak += score(p[i], c, time_limak)\n }\n for(i in n-1 downTo 0) {\n time_radewoosh += t[i]\n score_radewoosh += score(p[i], c, time_radewoosh)\n }\n if(score_radewoosh == score_limak) println(\"Tie\")\n else if(score_radewoosh > score_limak) println(\"Radewoosh\")\n else println(\"Limak\")\n}\n"}], "negative_code": [{"source_code": "fun main(args: Array) {\n val reader = java.util.Scanner(System.`in`)\n val n = reader.nextInt()\n val c = reader.nextInt()\n val ps = ArrayList(n)\n val pssum = ArrayList(n)\n val pssumrev = ArrayList(n)\n\n val ts = ArrayList(n)\n for (i in 1..n) {\n ps.add(reader.nextInt())\n pssum.add(0)\n pssumrev.add(0)\n }\n\n for (i in 1..n)\n ts.add(reader.nextInt())\n\n var sum : Int=0\n var sumrev : Int = 0\n for (i in ts.indices) {\n sum += ts[i]\n sumrev += ts[n-i-1]\n pssum[i]=sum\n pssumrev[n-i-1]=sumrev\n }\n\n val a= ps.zip(pssum){a, b -> if (a if (a print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun readToken(): String {\n while (!tok.hasMoreTokens()) tok = StringTokenizer(rd.readLine())\n return tok.nextToken()\n }\n fun readLine(): String {\n tok = StringTokenizer(\"\")\n return rd.readLine()\n }\n fun readInt(): Int = readToken().toInt()\n fun readLong(): Long = readToken().toLong()\n}\n\nfun main(args: Array) {\n Thread({ val io = ProblemIO.console(); solve(io); io.close() }).start()\n}\n\nfun solve(io: ProblemIO) {\n val n = io.readInt()\n val a = IntArray(n, { io.readInt() })\n val l = a.last()\n val res = when {\n l == 15 -> \"DOWN\"\n l == 0 -> \"UP\"\n else -> when {\n a.size == 1 -> \"-1\"\n l > a[a.lastIndex - 1] -> \"UP\"\n l < a[a.lastIndex - 1] -> \"DOWN\"\n else -> \"-1\"\n }\n }\n io.println(res)\n}\n"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!.toInt()\n val v = r.readLine()!!.split(\" \").map { it.toInt() }\n if (n == 1) {\n when {\n v[0] == 0 -> println(\"UP\")\n v[0] == 15 -> println(\"DOWN\")\n else -> println(-1)\n }\n } else {\n val before = v[n - 2]\n val mid = v[n - 1]\n when {\n mid == 15 -> println(\"DOWN\")\n mid == 0 -> println(\"UP\")\n mid > before -> println(\"UP\")\n mid < before -> println(\"DOWN\")\n }\n }\n}"}, {"source_code": "import java.io.*\n\nval stdout = System.out;\nval stdin = FastScanner(System.`in`);\n\nfun solve() {\n val n = nextInt()\n val arr = nextIntArray(n)\n when {\n arr.last() == 15 -> print(\"DOWN\")\n arr.last() == 0 -> print(\"UP\")\n arr.size < 2 -> print(\"-1\")\n else -> if (arr[n - 1] > arr[n - 2]) print(\"UP\") else print(\"DOWN\")\n }\n}\n\ninline fun print(message: Any?) = stdout.print(message)\ninline fun print(message: Int) = stdout.print(message)\ninline fun print(message: Long) = stdout.print(message)\ninline fun print(message: Byte) = stdout.print(message)\ninline fun print(message: Short) = stdout.print(message)\ninline fun print(message: Char) = stdout.print(message)\ninline fun print(message: Boolean) = stdout.print(message)\ninline fun print(message: Float) = stdout.print(message)\ninline fun print(message: Double) = stdout.print(message)\ninline fun print(message: CharArray) = stdout.print(message)\ninline fun println(message: Any?) = stdout.println(message)\ninline fun println(message: Int) = stdout.println(message)\ninline fun println(message: Long) = stdout.println(message)\ninline fun println(message: Byte) = stdout.println(message)\ninline fun println(message: Short) = stdout.println(message)\ninline fun println(message: Char) = stdout.println(message)\ninline fun println(message: Boolean) = stdout.println(message)\ninline fun println(message: Float) = stdout.println(message)\ninline fun println(message: Double) = stdout.println(message)\ninline fun println(message: CharArray) = stdout.println(message)\ninline fun println() = stdout.println()\n\ninline fun nextInt() = stdin.nextInt()\ninline fun nextLong() = stdin.nextLong()\ninline fun nextChar() = stdin.nextChar()\ninline fun next() = stdin.next()\ninline fun nextLine() = stdin.nextLine()\ninline fun nextIntArray(n: Int) = IntArray(n, { nextInt() })\n\nclass FastScanner(ins: InputStream): Closeable {\n val BUFFER_SIZE = 65536;\n val br: BufferedReader\n var end = false\n\n var len: Int = 0\n val buffer = CharArray(BUFFER_SIZE)\n var it: Int = 0\n\n init {\n br = BufferedReader(InputStreamReader(ins), BUFFER_SIZE)\n }\n\n constructor(file: String): this(FileInputStream(file))\n\n inline fun isLineBreaker(c: Char) = c == '\\n'\n inline fun isDelimiter(c: Char) = c == ' ' || c == '\\n' || c == '\\r'\n\n inline fun ensureBuffer() {\n if (it == len) {\n it = 0\n len = br.read(buffer)\n if (len == -1) end = true\n }\n }\n\n inline fun moveNext() {\n while (!end) {\n ensureBuffer()\n if (!isDelimiter(buffer[it])) return\n while (it < len && isDelimiter(buffer[it])) it++;\n }\n }\n\n inline fun nextChar(): Char {\n moveNext()\n if (end) return (-1).toChar()\n return buffer[it++]\n }\n\n inline fun next(): String {\n moveNext()\n val sb = StringBuilder()\n while (!end) {\n val l = it\n while (++it < len && !isDelimiter(buffer[it]));\n sb.append(buffer, l, it - l)\n ensureBuffer()\n if (end || isDelimiter(buffer[it])) break;\n }\n return sb.toString()\n }\n\n inline fun nextInt(): Int {\n moveNext()\n var minus = true\n if (buffer[it] == '-') {\n it++\n minus = false\n }\n var result: Int = 0\n while (!end) {\n while (it < len && !isDelimiter(buffer[it])) {\n result *= 10\n result += (buffer[it] - '0').toInt()\n it++\n }\n ensureBuffer()\n if (end || isDelimiter(buffer[it])) break\n }\n return if (minus) result else -result\n }\n\n inline fun nextLong(): Long {\n moveNext()\n var minus = true\n if (buffer[it] == '-') {\n it++\n minus = false\n }\n var result: Long = 0\n while (!end) {\n while (it < len && !isDelimiter(buffer[it])) {\n result *= 10\n result += (buffer[it] - '0').toLong()\n it++\n }\n ensureBuffer()\n if (end || isDelimiter(buffer[it])) break\n }\n return if (minus) result else -result\n }\n\n inline fun nextLine(): String {\n moveNext()\n val sb = StringBuilder()\n while (!end) {\n val l = it\n while (++it < len && !isLineBreaker(buffer[it]));\n sb.append(buffer, l, it - l)\n ensureBuffer()\n if (end || isLineBreaker(buffer[it])) break;\n }\n return sb.toString()\n }\n\n override fun close() {\n br.close()\n }\n}\n\nfun main(args: Array) {\n solve()\n stdin.close()\n stdout.close();\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n readLine()\n val sizes = readInts()\n print(\n when {\n sizes.last() == 0 -> \"UP\"\n sizes.last() == 15 -> \"DOWN\"\n sizes.size == 1 -> \"-1\"\n sizes.last() > sizes[sizes.lastIndex - 1] -> \"UP\"\n else -> \"DOWN\"\n }\n )\n}"}], "negative_code": [{"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!.toInt()\n val v = r.readLine()!!.split(\" \").map { it.toInt() }\n if (n == 1) {\n println(-1)\n } else {\n val before = v[n - 2]\n val mid = v[n - 1]\n when {\n mid in (before + 1)..14 -> println(\"UP\")\n mid > before && mid == 15 -> println(\"DOWN\")\n mid in 1 until before -> println(\"DOWN\")\n mid < before && mid == 0 -> println(\"UP\")\n }\n }\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!.toInt()\n val v = r.readLine()!!.split(\" \").map { it.toInt() }\n if (n==1) {\n println(-1)\n } else{\n val before = v[n-2]\n val mid = v[n-1]\n when{\n mid in (before + 1)..14 -> println(\"UP\")\n mid println(\"DOWN\")\n mid in 1 until before -> println(\"DOWN\")\n mid println(\"UP\")\n }\n }\n}"}], "src_uid": "8330d9fea8d50a79741507b878da0a75"} {"nl": {"description": "Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. Initially, each hole has $$$a_i$$$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.Note that the counter-clockwise order means if the player takes the stones from hole $$$i$$$, he will put one stone in the $$$(i+1)$$$-th hole, then in the $$$(i+2)$$$-th, etc. If he puts a stone in the $$$14$$$-th hole, the next one will be put in the first hole.After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.", "input_spec": "The only line contains 14 integers $$$a_1, a_2, \\ldots, a_{14}$$$ ($$$0 \\leq a_i \\leq 10^9$$$) — the number of stones in each hole. It is guaranteed that for any $$$i$$$ ($$$1\\leq i \\leq 14$$$) $$$a_i$$$ is either zero or odd, and there is at least one stone in the board.", "output_spec": "Output one integer, the maximum possible score after one move.", "sample_inputs": ["0 1 1 0 0 0 0 0 0 7 0 0 0 0", "5 1 1 1 1 0 0 0 0 0 0 0 0 0"], "sample_outputs": ["4", "8"], "notes": "NoteIn the first test case the board after the move from the hole with $$$7$$$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $$$4$$$."}, "positive_code": [{"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val numStones = readInts()\n var bestSol = 0L\n for (hole in 0 until 14) {\n val initialStonesInHole = numStones[hole]\n val stonesEach = initialStonesInHole / 14\n val extraStones = initialStonesInHole % 14\n var sol = 0L\n for (otherHole in hole + 1..hole + extraStones) {\n val stonesInHole = numStones[otherHole % 14].toLong() + stonesEach + 1\n if (stonesInHole and 1 == 0L) sol += stonesInHole\n }\n for (otherHole in hole + extraStones + 1..hole + 13) {\n val stonesInHole = numStones[otherHole % 14].toLong() + stonesEach\n if (stonesInHole and 1 == 0L) sol += stonesInHole\n }\n if (stonesEach and 1 == 0) sol += stonesEach\n if (sol > bestSol) bestSol = sol\n }\n print(bestSol)\n}\n"}, {"source_code": "fun main(args: Array) {\n val a = System.`in`.reader().readText().trim().split(' ').map(String::toLong)\n println(a.mapIndexed { i, l ->\n a.mapIndexed { j, m ->\n if (i == j) m / 14\n else m + (l + (i - j + 14).rem(14)) / 14\n }.filter { it.rem(2) == 0L }.sum()\n }.max())\n}"}], "negative_code": [{"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val numStones = readInts()\n var bestSol = 0L\n for (hole in 0 until 14) {\n val initialStonesInHole = numStones[hole]\n val stonesEach = initialStonesInHole / 14\n val extraStones = initialStonesInHole % 14\n var sol = 0L\n for (otherHole in hole + 1..hole + extraStones) {\n val stonesInHole = numStones[otherHole % 14].toLong() + stonesEach + 1\n if (stonesInHole and 1 == 0L) sol += stonesInHole\n }\n for (otherHole in hole + extraStones..hole + 13) {\n val stonesInHole = numStones[otherHole % 14].toLong() + stonesEach\n if (stonesInHole and 1 == 0L) sol += stonesInHole\n }\n if (stonesEach and 1 == 0) sol += stonesEach\n if (sol > bestSol) bestSol = sol\n }\n print(bestSol)\n}\n"}], "src_uid": "1ac11153e35509e755ea15f1d57d156b"} {"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": "import kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main(args: Array) {\n val array: IntArray = readLine()!!.split(' ').map { it.toInt() }.toIntArray()\n val min = min(array[0], array[1])\n\n if(min + array[2] <= max(array[0], array[1])) println((min + array[2]).times(2))\n else println(max(array[0], array[1]).plus(array[2] - abs(array[0] - array[1]) shr 1).times(2))\n}"}, {"source_code": "import kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main(args: Array) {\n val array: IntArray = readLine()!!.split(' ').map { it.toInt() }.toIntArray()\n\n val min = min(array[0], array[1])\n val max = max(array[0], array[1])\n\n if(min + array[2] <= max){\n println((min + array[2]).times(2))\n } else {\n var ambOut = array[2] - abs(array[0] - array[1])\n println(if ((array[0] == 0 || array[1] == 0) && array[2] == 0) 0 else max(array[0], array[1]).plus(ambOut shr 1).times(2))\n }\n}"}, {"source_code": "import kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main(args: Array) {\n val array: IntArray = readLine()!!.split(' ').map { it.toInt() }.toIntArray()\n val min = min(array[0], array[1])\n\n if((array[0] == 0 || array[1] == 0) && array[2] == 0) println(0)\n else if(min + array[2] <= max(array[0], array[1])) println((min + array[2]).times(2))\n else println(max(array[0], array[1]).plus(array[2] - abs(array[0] - array[1]) shr 1).times(2))\n}"}, {"source_code": "import java.lang.Math.abs\nimport java.util.*\n\n/**\n * Created by SitaoLiao on 3/11/18.\n */\nfun main(args: Array) {\n val scanner = Scanner(System.`in`);\n\n val user_input = scanner.nextLine().split(\" \").map{ it.toInt() };\n\n var diff = user_input[0] - user_input[1];\n\n val ans: Int\n\n if( diff > 0 ){\n if( diff >= user_input[2] ){\n ans = user_input[1] + user_input[2]\n } else {\n ans = user_input[0] + (user_input[2]-diff)/2\n }\n } else {\n diff = abs(diff)\n if( diff >= user_input[2] ){\n ans = user_input[0] + user_input[2]\n } else {\n ans = user_input[1] + (user_input[2]-diff)/2\n }\n }\n\n println(ans*2)\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main(args: Array) {\n solve(System.`in`, System.out)\n}\n\nval MAX_N = (1e6 + 10).toInt()\nval INF = (1e9 + 7).toInt()\nval MOD = (1e9 + 7).toInt()\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val l = reader.nextInt()\n val r = reader.nextInt()\n val a = reader.nextInt()\n\n var ans = 0\n\n for (i in 0..a) {\n val t = min(l + i, r + a - i)\n ans = max(ans, t)\n }\n writer.println(2 * ans)\n}\n\nclass InputReader(stream: InputStream) {\n val reader: BufferedReader\n var tokenizer: StringTokenizer? = null\n\n init {\n reader = BufferedReader(InputStreamReader(stream), 32768)\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}"}, {"source_code": "fun min(a: Int, b:Int): Int{\n return if (a > b) b else a\n}\nfun main(args: Array){\n\n var (l,p,a) = readLine().toString().split(\" \").map{x -> x.toInt()}\n\n while(l!=p&&a>0){\n\n if(l1){\n l++\n p++\n a-=2\n }\n\n print(min(l,p)*2)\n\n\n}\n\n\n"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n var (l, r, a) = readInts()\n var (min, max) = if (l <= r) l to r else r to l\n if (min + a < max) {\n min += a\n a = 0\n } else {\n val diff = max - min\n min = max\n a -= diff\n }\n print((kotlin.math.min(min, max) + a / 2) * 2)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val line = BufferedReader(InputStreamReader(System.`in`)).readLine().split(' ')\n\n var l = line[0].toInt()\n var r = line[1].toInt()\n var a = line[2].toInt()\n\n while (a > 0 && r != l) {\n a--\n when {\n r > l -> l++\n l > r -> r++\n }\n }\n\n if (r == l) {\n while (a > 0) {\n a--\n if (a % 2 == 0) r++ else l++\n }\n }\n if (l == 0 || r == 0) return println(0)\n\n while (l != r) {\n when {\n l > r -> l--\n l < r -> r--\n }\n }\n\n println(l + r)\n}"}, {"source_code": "fun main(arg: Array){\n\tvar (L, R, A) = readLine().toString().split(\" \").map {x -> x.toInt()}\n\tvar teamN = 0\n\tval pmaxL = L + A\n\tval pmaxR = R + A\n\tval maxTeam = if (pmaxR > pmaxL) pmaxL else pmaxR\n\tif (maxTeam == 0){\n\t\tprintln(0)\n\t\treturn\n\t}\n//\tprintln(\"Max team is: $maxTeam\")\n\tvar teamL: Int = 0\n\tvar teamR: Int = 0\n\n\twhile((R+A>0) and (L+A>0)){\n//\t\tprintln(\"Before. R:$R, L:$L, A:$A, TL: $teamL, TR: $teamR\")\n\t\tif(L>R){\n\t\t\tif (R>0){\n\t\t\t\tteamR+=1\n\t\t\t\tR-=1\n\t\t\t}else{\n\t\t\t\tteamR+=1\n\t\t\t\tA-=1\n\t\t\t}\n\n\t\t\tif (L>0){\n\t\t\t\tteamL+=1\n\t\t\t\tL-=1\n\t\t\t}else{\n\t\t\t\tteamL+=1\n\t\t\t\tA-=1\n\t\t\t}\n\n\t\t}else{\n\t\t\tif (L>0){\n\t\t\t\tteamL+=1\n\t\t\t\tL-=1\n\t\t\t}else{\n\t\t\t\tteamL+=1\n\t\t\t\tA-=1\n\t\t\t}\n\n\t\t\tif (R>0){\n\t\t\t\tteamR+=1\n\t\t\t\tR-=1\n\t\t\t}else{\n\t\t\t\tteamR+=1\n\t\t\t\tA-=1\n\t\t\t}\n\n\t\t}\n\n\t\tif(A < 0){\n\t\t\tteamR -= 1\n\t\t\tteamL -= 1\n\t\t\tbreak\n\t\t}\n\n//\t\tprintln(\"Before. R:$R, L:$L, A:$A, TL: $teamL, TR: $teamR\")\n\n\t}\n\n\tprintln(teamL + teamR)\n}"}], "negative_code": [{"source_code": "import kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main(args: Array) {\n\n val array: IntArray = readLine()!!.split(' ').map { it.toInt() }.toIntArray()\n val min = min(array[0], array[1])\n\n if(array[0] == 0 || array[1] == 0 && array[2] == 0) println(0)\n else if(min + array[2] <= max(array[0], array[1])) println((min + array[2]).times(2))\n else println(max(array[0], array[1]).plus(array[2] - abs(array[0] - array[1]) shr 1).times(2))\n\n}"}, {"source_code": "import kotlin.math.abs\nimport kotlin.math.max\n\nfun main(args: Array) {\n val array: IntArray = readLine()!!.split(' ').map { it.toInt() }.toIntArray()\n var ambOut = array[2] - abs(array[0] - array[1])\n println(if((array[0] == 0 || array[1] == 0) && array[2] == 0) 0 else max(array[0], array[1]).plus(ambOut shr 1).times(2))\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val line = BufferedReader(InputStreamReader(System.`in`)).readLine().split(' ')\n\n var l = line[0].toInt()\n var r = line[1].toInt()\n var a = line[2].toInt()\n\n while (a > 0 && r != l) {\n a--\n if (r > l) l++ else if (l > r) r++\n }\n\n if (r == l) {\n while (a > 0) {\n a--\n if (a % 2 == 0) r++ else l++\n }\n }\n if (l == 0 || r == 0) return println(0)\n\n var result = l + r\n if (result % 2 != 0) result--\n println(result)\n}"}], "src_uid": "e8148140e61baffd0878376ac5f3857c"} {"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": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n val n = r.readLine()!!.toInt()\n //val (m, n) = r.readLine()!!.split(\" \").map { it.toInt() }\n val v = r.readLine()!!.split(\" \").map { it.toInt() }.map { if (it<0) -it else it }.sum()\n println(v)\n\n}"}, {"source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n var a = readLine()!!.split(' ')\n var B = 0\n var C = 0\n for (i in 0 until a.size){\n if (a[i].toInt() >= 0) {\n B += a[i].toInt()\n }\n else{\n C += a[i].toInt()\n }\n }\n print(B-C)\n}"}, {"source_code": "import java.io.PrintWriter\nimport kotlin.math.*\n\nfun main() {\n io.apply {\n\n val n = int\n val d = ints(n)\n val ans = d.map { abs(it) }.sum()\n cout .. ans .. nl\n \n }.cout.flush()\n}\n\n// @formatter:off\nprivate val io = object {\n private val `in` = System.`in`\n private fun ll(): Long {\n var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }\n do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n\n }\n val int get() = ll().toInt(); val long get() = ll()\n fun ints(n: Int = int): IntArray { return IntArray(n) { int } }\n fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }\n val cout = PrintWriter(System.out); val nl = \"\\n\"\n private var buf = CharArray(32)\n private var bufSize = 32\n fun str(expect: Int = 32): String {\n var ix = 0\n var x: Int\n if (bufSize < expect)\n buf = CharArray(expect)\n do x = `in`.read() while (x < 33)\n do {\n if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }\n buf[ix++] = x.toChar()\n x = `in`.read()\n } while (x > 32)\n return java.lang.String.copyValueOf(buf, 0, ix)\n }\n operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(\" \") }; return this }\n operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }\n} // @formatter:on\n\n/* ----------- */\n\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val n = reader.nextInt()\n val a = reader.nextArrayInt(n)\n val ans = a.filter { it > 0 }.sum() - a.filter { it < 0 }.sum()\n writer.println(ans)\n}\n\nclass InputReader(stream: InputStream) {\n val reader: BufferedReader\n var tokenizer: StringTokenizer? = null\n\n init {\n reader = BufferedReader(InputStreamReader(stream), 32768)\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}\n\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val n = reader.nextInt()\n val a = reader.nextArrayInt(n)\n val ans = a.map {\n if (it < 0) {\n -it\n } else {\n it\n }\n }.sum()\n// a.filter { it > 0 }.sum() - a.filter { it < 0 }.sum()\n writer.println(ans)\n}\n\nclass InputReader(stream: InputStream) {\n val reader: BufferedReader\n var tokenizer: StringTokenizer? = null\n\n init {\n reader = BufferedReader(InputStreamReader(stream), 32768)\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}\n\n"}, {"source_code": "import kotlin.math.abs\n\nfun main(args: Array) {\n val z = java.util.Scanner(System.`in`)\n val n = z.nextInt()\n var sum = 0\n var a = 0\n for (i in 1..n)\n sum+=abs(z.nextInt())\n println(sum)\n}"}, {"source_code": "import java.io.*\nimport java.util.*\nimport java.lang.Math.*\n\nfun PrintWriter.solve() {\n val n = nextInt()\n println((1..n).map { abs(nextInt()) }.sum())\n}\n\nfun main(args: Array) {\n PrintWriter(System.out, false).use { it.solve() }\n}\n\nval br = BufferedReader(InputStreamReader(System.`in`))\nvar stok = StringTokenizer(\"\")\n\nfun nextToken(): String? {\n while (!stok.hasMoreTokens()) {\n val s = br.readLine() ?: return null\n stok = StringTokenizer(s)\n }\n return stok.nextToken()\n}\n\nfun nextInt(): Int {\n return nextToken()!!.toInt()\n}\n\nfun nextLong(): Long {\n return nextToken()!!.toLong()\n}\n\nfun nextDouble(): Double {\n return nextToken()!!.toDouble()\n}\n"}, {"source_code": "\nfun main(args: Array) {\n System.`in`.bufferedReader().use {\n val n = it.readLine().toInt()\n val parts = it.readLine().split(' ')\n val a = IntArray(n, { i -> parts[i].toInt() })\n\n a.sort()\n\n var b = 0\n var c = 0\n var i = 0\n while (i < n && a[i] < 0)\n c += a[i++]\n while (i < n)\n b += a[i++]\n\n println(b - c)\n }\n}\n"}, {"source_code": "fun main(args: Array)\n{\n val n = readLine()!!.toInt()\n val inp = readLine()!!.split(' ').map(String::toInt)\n val sneg = inp.filter({i -> i < 0}).sum()\n val spos = inp.filter({i -> i > 0}).sum()\n println(spos - sneg)\n}"}, {"source_code": "import java.util.*\nfun main(args: Array) {\n \n\n var count = readLine()!!.toInt()\n var arr = readLine()!!.split(' ')\n var B = 0\n var C = 0\n var i = 0\n repeat(count)\n {\n val X = arr[i].toInt()\n if(X > 0) B += X\n else C += X\n i++\n }\n println(B - C)\n\n}"}, {"source_code": "import kotlin.math.absoluteValue\n\nfun main() {\n readLine()\n print(readLine()!!.split(\" \").map { it.toInt().absoluteValue }.sum())\n}"}, {"source_code": "fun main(args:Array) { \n val n = readLine()!! \n val (A,B) = (0..1).map { mutableListOf() } \n \n readLine()!!.split(\" \").map(String::toInt).map { \n if( it > 0 ) A.add(it) else B.add(it) \n } \n println( A.sum() - B.sum() ) \n}"}, {"source_code": "\nimport java.util.*\n\nclass A {\n fun run(scan: Scanner) {\n val count = scan.nextInt()\n var sumB = 0\n var sumC = 0\n repeat(count){\n val cur = scan.nextInt()\n if(cur > 0)\n sumB += cur\n else sumC += cur\n }\n println(sumB - sumC)\n }\n}\n\nfun main(args: Array) {\n A().run(Scanner(System.`in`))\n}"}, {"source_code": "import java.util.Scanner\nimport kotlin.math.abs\nimport kotlin.math.max\n\nfun main() {\n val reader = Scanner(System.`in`)\n\n val n = reader.nextInt()\n var arr = Array(n) {0}\n var sum = 0\n\n for(i in 0..n-1) {\n arr[i] = reader.nextInt()\n sum += abs(arr[i])\n }\n println(sum)\n}"}], "negative_code": [{"source_code": "import java.io.PrintWriter\nimport kotlin.math.*\n\nfun main() {\n io.apply {\n\n val n = int\n val d = ints(n)\n var cur = d.sum()\n var mx = abs(cur)\n for (i in n - 1 downTo 0) {\n cur -= d[i] * 2\n mx = max(abs(cur), mx)\n }\n\n cout .. mx .. nl\n\n }.cout.flush()\n}\n\n// @formatter:off\nprivate val io = object {\n private val `in` = System.`in`\n private fun ll(): Long {\n var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }\n do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n\n }\n val int get() = ll().toInt(); val long get() = ll()\n fun ints(n: Int = int): IntArray { return IntArray(n) { int } }\n fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }\n val cout = PrintWriter(System.out); val nl = \"\\n\"\n private var buf = CharArray(32)\n private var bufSize = 32\n fun str(expect: Int = 32): String {\n var ix = 0\n var x: Int\n if (bufSize < expect)\n buf = CharArray(expect)\n do x = `in`.read() while (x < 33)\n do {\n if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }\n buf[ix++] = x.toChar()\n x = `in`.read()\n } while (x > 32)\n return java.lang.String.copyValueOf(buf, 0, ix)\n }\n operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(\" \") }; return this }\n operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }\n} // @formatter:on\n\n/* ----------- */\n\n"}, {"source_code": "import java.io.PrintWriter\nimport kotlin.math.*\n\nfun main() {\n io.apply {\n\n val n = int\n val d = ints(n)\n var cur = d.sum()\n var mx = cur\n for (i in n - 1 downTo 0) {\n cur -= d[i] * 2\n mx = max(cur, mx)\n }\n\n cout .. mx .. nl\n\n }.cout.flush()\n}\n\n// @formatter:off\nprivate val io = object {\n private val `in` = System.`in`\n private fun ll(): Long {\n var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }\n do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n\n }\n val int get() = ll().toInt(); val long get() = ll()\n fun ints(n: Int = int): IntArray { return IntArray(n) { int } }\n fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }\n val cout = PrintWriter(System.out); val nl = \"\\n\"\n private var buf = CharArray(32)\n private var bufSize = 32\n fun str(expect: Int = 32): String {\n var ix = 0\n var x: Int\n if (bufSize < expect)\n buf = CharArray(expect)\n do x = `in`.read() while (x < 33)\n do {\n if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }\n buf[ix++] = x.toChar()\n x = `in`.read()\n } while (x > 32)\n return java.lang.String.copyValueOf(buf, 0, ix)\n }\n operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(\" \") }; return this }\n operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }\n} // @formatter:on\n\n/* ----------- */\n\n"}, {"source_code": "import java.io.*\nimport java.util.*\nimport java.lang.Math.*\n\nfun PrintWriter.solve() {\n val n = nextInt()\n println((1..n).map { nextInt() }.sum())\n}\n\nfun main(args: Array) {\n PrintWriter(System.out, false).use { it.solve() }\n}\n\nval br = BufferedReader(InputStreamReader(System.`in`))\nvar stok = StringTokenizer(\"\")\n\nfun nextToken(): String? {\n while (!stok.hasMoreTokens()) {\n val s = br.readLine() ?: return null\n stok = StringTokenizer(s)\n }\n return stok.nextToken()\n}\n\nfun nextInt(): Int {\n return nextToken()!!.toInt()\n}\n\nfun nextLong(): Long {\n return nextToken()!!.toLong()\n}\n\nfun nextDouble(): Double {\n return nextToken()!!.toDouble()\n}\n"}], "src_uid": "4b5d14833f9b51bfd336cc0e661243a5"} {"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.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007L\n\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val N = ni()\n val (L, R) = na2(N)\n\n var ans = 0.0\n\n for (i in 0 until N) {\n for (j in 0 until N) {\n if (i == j) continue\n for (x in L[j] .. R[j]) {\n var prob = 1.0\n for (k in 0 until N) {\n if (k == j) continue\n\n prob *= if (k == i) {\n val l = max(if (i < j) x else x + 1, L[i])\n val r = R[i]\n max(0, r - l + 1)\n } else {\n val l = L[k]\n val r = min(if (j < k) x else x - 1, R[k])\n max(0, r - l + 1)\n }\n }\n ans += prob * x\n }\n }\n }\n\n debug{\"ans:$ans\"}\n for (i in 0 until N) {\n ans /= (R[i] - L[i] + 1)\n }\n\n out.println(\"%.10f\".format(ans))\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl() + offset\n }\n return res\n }\n\n private fun na2(n: Int, offset: Int = 0): Array {\n val a = Array(2){IntArray(n)}\n for (i in 0 until n) {\n for (e in a) {\n e[i] = ni() + offset\n }\n }\n return a\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n private fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}"}], "negative_code": [], "src_uid": "5258ce738eb268b9750cfef309d265ef"} {"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 kotlin.math.abs\nimport kotlin.math.pow\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //val (n, time) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }\n val s1 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos1 = s1.count { it == \"+\" } * 2 - s1.size\n val s2 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos2 = s2.count { it == \"+\" } - s2.count { it == \"-\" }\n val unk = s2.count { it == \"?\" }\n when{\n unk == 0 -> println(if (pos1==pos2) 1.0 else 0.0)\n pos2+unkpos1-> println(0.0)\n else -> {\n val choose = (unk-abs(pos1-pos2))/2\n val ans = (unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i }/2.0.pow(unk)\n println(ans)\n //println((unk-choose+1..unk).fold(1L){acc, i -> acc*i })\n }\n }\n}"}, {"source_code": "fun getAllFinalDestinations(receivedPath: String) = arrayListOf().apply {\n \n fun checkFinalDestination(currentPosition: Int, index: Int) {\n if (index == receivedPath.length) {\n add(currentPosition)\n return\n }\n when(receivedPath[index]) {\n '+' -> checkFinalDestination(currentPosition + 1, index + 1)\n '-' -> checkFinalDestination(currentPosition - 1, index + 1)\n '?' -> {\n checkFinalDestination(currentPosition + 1, index + 1)\n checkFinalDestination(currentPosition - 1, index + 1)\n }\n }\n }\n \n checkFinalDestination(0, 0)\n}\n \nfun main() = readLine()!!\n .map { ch -> if (ch == '+') 1 else -1 }\n .sum()\n .let { destination -> Pair(destination, readLine()!!) }\n .let { (destination, receivedPath) -> Pair(destination, receivedPath.run(::getAllFinalDestinations)) }\n .let { (destination, allFinalDestinations) ->\n allFinalDestinations.count(destination::equals).toDouble() / allFinalDestinations.size.toDouble()\n }\n .let { percentage -> \"%.12f\".format(percentage) }\n .run(::println)"}, {"source_code": "import java.util.Scanner;\n\nfun final_location(cmds : String) : Pair {\n var loc = 0\n var num_unrecognized_cmds = 0\n for (cmd in cmds) {\n if (cmd == '+') {\n loc = loc + 1\n } else if (cmd == '-') {\n loc = loc - 1\n } else if (cmd == '?') {\n num_unrecognized_cmds = num_unrecognized_cmds + 1\n } else {\n throw Exception(\"Unknown input!\")\n }\n }\n return Pair(loc, num_unrecognized_cmds)\n}\n\nfun factorial(x : Int) : Int {\n var f = 1;\n for (i in 1 .. x) {\n f = f * i\n }\n return f\n}\n\nfun main(args : Array) {\n val scanner = Scanner(System.`in`)\n val sent_command = scanner.next()\n val recognized_command = scanner.next()\n // println(\"sent_command : ${sent_command}\") \n // println(\"recognized_command : ${recognized_command}\") \n val (loc_sent_cmd, _) = final_location(sent_command)\n val (loc_recognized_cmd, num_unrecognized_cmds) = final_location(recognized_command)\n // println(\"loc_sent_cmd : ${loc_sent_cmd}\")\n // println(\"loc_recognized_cmd : ${loc_recognized_cmd}\")\n // println(\"num_unrecognized_cmds : ${num_unrecognized_cmds}\")\n // p + m = num_unrecognized_cmds\n // p - m = loc_sent_cmd - loc_recognized_cmd\n val two_p = loc_sent_cmd - loc_recognized_cmd + num_unrecognized_cmds\n if ((two_p % 2) == 1) {\n println(\"0\")\n } else {\n val p = two_p / 2\n val m = num_unrecognized_cmds - p\n if ((p >= 0) && (m >= 0)) {\n val f_s = factorial(num_unrecognized_cmds).toDouble()\n val f_p = factorial(p).toDouble()\n val f_m = factorial(m).toDouble()\n val two : Double = 2.0\n val result = (f_s / (f_p * f_m)) * (1.0 / Math.pow(two, num_unrecognized_cmds.toDouble()))\n println(\"${result}\")\n } else {\n println(\"0\")\n }\n }\n}"}], "negative_code": [{"source_code": "import kotlin.math.abs\nimport kotlin.math.pow\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //val (n, time) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }\n val s1 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos1 = s1.count { it == \"+\" } * 2 - s1.size\n val s2 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos2 = s2.count { it == \"+\" } - s2.count { it == \"-\" }\n val unk = s2.count { it == \"?\" }\n when{\n unk == 0 -> println(1.0)\n abs(unk+pos2-pos1)%2==1 -> println(0.0)\n else -> {\n val choose = (unk-abs(pos1))/2\n val ans = (unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i }/2.0.pow(unk)\n println(ans)\n }\n }\n}"}, {"source_code": "import kotlin.math.abs\nimport kotlin.math.pow\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //val (n, time) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }\n val s1 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos1 = s1.count { it == \"+\" } * 2 - s1.size\n val s2 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos2 = s2.count { it == \"+\" } - s2.count { it == \"-\" }\n val unk = s2.count { it == \"?\" }\n when{\n unk == 0 -> println(1.0)\n pos2+unkpos1-> println(0.0)\n else -> {\n val choose = (unk-abs(pos1))/2\n val ans = (unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i }/2.0.pow(unk)\n println(ans)\n }\n }\n}"}, {"source_code": "import kotlin.math.abs\nimport kotlin.math.pow\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //val (n, time) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }\n val s1 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos1 = s1.count { it == \"+\" } * 2 - s1.size\n val s2 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos2 = s2.count { it == \"+\" } - s1.count { it == \"-\" }\n val unk = s2.count { it == \"?\" }\n when{\n abs(unk-pos1)%2==1 -> println(0.0)\n else -> {\n val choose = (unk-abs(pos1))/2\n val ans = (unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i }/2.0.pow(unk)\n println(ans)\n /*println((unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i })\n println((unk-choose+1..unk).fold(1L){acc, i -> acc*i })\n println(unk)*/\n }\n }\n}"}, {"source_code": "import kotlin.math.abs\nimport kotlin.math.pow\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //val (n, time) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }\n val s1 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos1 = s1.count { it == \"+\" } * 2 - s1.size\n val s2 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos2 = s2.count { it == \"+\" } - s2.count { it == \"-\" }\n val unk = s2.count { it == \"?\" }\n when{\n unk == 0 -> println(if (pos1==pos2) 1.0 else 0.0)\n pos2+unkpos1-> println(0.0)\n else -> {\n val choose = (unk-abs(pos1))/2\n val ans = (unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i }/2.0.pow(unk)\n println(ans)\n }\n }\n}"}, {"source_code": "import kotlin.math.abs\nimport kotlin.math.pow\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //val (n, time) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }\n val s1 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos1 = s1.count { it == \"+\" } * 2 - s1.size\n val s2 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos2 = s2.count { it == \"+\" } - s1.count { it == \"-\" }\n val unk = s2.count { it == \"?\" }\n when{\n unk == 0 -> println(1.0)\n abs(unk+pos2-pos1)%2==1 -> println(0.0)\n else -> {\n val choose = (unk-abs(pos1))/2\n val ans = (unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i }/2.0.pow(unk)\n println(ans)\n /*println((unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i })\n println((unk-choose+1..unk).fold(1L){acc, i -> acc*i })\n println(unk)*/\n }\n }\n}"}, {"source_code": "import kotlin.math.abs\nimport kotlin.math.pow\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //val (n, time) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }\n val s1 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos1 = s1.count { it == \"+\" } * 2 - s1.size\n val s2 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos2 = s2.count { it == \"+\" } - s1.count { it == \"-\" }\n val unk = s2.count { it == \"?\" }\n when{\n unk == 0 -> println(1.0)\n abs(unk-pos1)%2==1 -> println(0.0)\n else -> {\n val choose = (unk-abs(pos1))/2\n val ans = (unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i }/2.0.pow(unk)\n println(ans)\n /*println((unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i })\n println((unk-choose+1..unk).fold(1L){acc, i -> acc*i })\n println(unk)*/\n }\n }\n}"}], "src_uid": "f7f68a15cfd33f641132fac265bc5299"} {"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": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.StringTokenizer\n\n\nfun main(args: Array) {\n val sc = FastScanner(System.`in`)\n\n val x = sc.nextLong()\n val y = sc.nextLong()\n\n println(solve(x, y))\n}\n\nval mod = (1e9 + 7).toLong()\n\nval res = mutableMapOf()\n\ndata class par(val t: Long)\n\nprivate fun solve(x: Long, y: Long): Long {\n if (y % x != 0L) return 0L\n if (y < x) return 0L\n\n val t = y / x\n if (res.containsKey(par(t))) return res[par(t)] ?: throw Exception()\n\n var sum = 2L pow (t - 1)\n\n if (x != y) sum = (sum - 1 + mod) % mod\n\n var i = 2L\n while (i * i <= t) {\n if (t % i == 0L) {\n sum = (sum - solve(i, t) + mod) % mod\n\n if (t / i != i) {\n sum = (sum - solve(t / i, t) + mod) % mod\n }\n }\n i += 1\n }\n\n res[par(t)] = sum\n return sum\n}\n\n\nprivate infix fun Long.pow(n: Long): Long {\n var a = this\n var n = n % (mod - 1)\n var res = 1L\n while (n > 0) {\n if (n % 2 == 1L) res = res * a % mod\n a = a * a % mod\n n /= 2\n }\n return res\n}\n\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}\n\n\n"}], "negative_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.StringTokenizer\n\n\nfun main(args: Array) {\n val sc = FastScanner(System.`in`)\n\n val x = sc.nextLong()\n val y = sc.nextLong()\n\n println(solve(x, y))\n}\n\nval mod = (1e9 + 7).toLong()\n\nprivate fun solve(x: Long, y: Long): Long {\n if (y % x != 0L) return 0L\n\n val t = y / x\n\n var sum = 2L pow (t - 1)\n\n if (x != y) sum = (sum - 1 + mod) % mod\n\n var i = 2L\n while (i * i <= t) {\n if (t % i == 0L) sum = (sum - solve(i, t) + mod) % mod\n i += 1\n }\n\n return sum\n}\n\n\nprivate infix fun Long.pow(n: Long): Long {\n var a = this\n var n = n % (mod - 1)\n var res = 1L\n while (n > 0) {\n if (n % 2 == 1L) res = res * a % mod\n a = a * a % mod\n n /= 2\n }\n return res\n}\n\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}\n\n\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.StringTokenizer\n\n\nfun main(args: Array) {\n val sc = FastScanner(System.`in`)\n\n val x = sc.nextLong()\n val y = sc.nextLong()\n\n println(solve(x, y))\n}\n\nval mod = (1e9 + 7).toLong()\n\nprivate fun solve(x: Long, y: Long): Long {\n if (y % x != 0L) return 0L\n if( y < x) return 0L\n\n val t = y / x\n\n var sum = 2L pow (t - 1)\n\n if (x != y) sum = (sum - 1 + mod) % mod\n\n var i = 2L\n while (i * i <= t) {\n if (t % i == 0L) sum = (sum - solve(i, t) + mod) % mod\n i += 1\n }\n\n return sum\n}\n\n\n\nprivate infix fun Long.pow(n: Long): Long {\n var a = this\n var n = n % (mod - 1)\n var res = 1L\n while (n > 0) {\n if (n % 2 == 1L) res = res * a % mod\n a = a * a % mod\n n /= 2\n }\n return res\n}\n\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}\n\n\n"}], "src_uid": "de7731ce03735b962ee033613192f7bc"} {"nl": {"description": "After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.Formally, Alyona wants to count the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and equals 0.As usual, Alyona has some troubles and asks you to help.", "input_spec": "The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1 000 000).", "output_spec": "Print the only integer — the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and (x + y) is divisible by 5.", "sample_inputs": ["6 12", "11 14", "1 5", "3 8", "5 7", "21 21"], "sample_outputs": ["14", "31", "1", "5", "7", "88"], "notes": "NoteFollowing pairs are suitable in the first sample case: for x = 1 fits y equal to 4 or 9; for x = 2 fits y equal to 3 or 8; for x = 3 fits y equal to 2, 7 or 12; for x = 4 fits y equal to 1, 6 or 11; for x = 5 fits y equal to 5 or 10; for x = 6 fits y equal to 4 or 9. Only the pair (1, 4) is suitable in the third sample case."}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val (n, m) = br.readLine().split(\" \").map { it.toLong() }\n val minBound = min(n, m)\n val maxBound = max(n, m)\n println((1..minBound).fold(0L){acc, i ->\n acc + (maxBound + i)/5 - i/5\n })\n}"}, {"source_code": "import java.util.*\n \n \nfun main(args: Array){\n val ( n, m ) = readLine()!!.split(' ').map(String::toInt)\n var ans: Long = 0\n var cnt: IntArray = IntArray( 6 )\n for( i in 1 .. m ) cnt[i % 5]++\n for( i in 1 .. n ){\n ans += cnt[( 5 - i % 5 ) % 5]\n }\n print( ans )\n}"}, {"source_code": "fun main() {\n val (n, m) = readLine()!!.split(\" \").map { it.toLong() }\n var sol = 0L\n for (i in 1..n) {\n var j = 5L - i % 5L\n if (j == 0L) {\n j = 5L\n }\n j = m - j\n if (j >= 0L) {\n sol += 1L + j / 5L\n }\n }\n print(sol)\n}"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array){\n val ( n, m ) = readLine()!!.split(' ').map(String::toInt)\n var ans: Long = 0\n var cnt: IntArray = IntArray( 6 )\n for( i in 1 .. m ) cnt[i % 5]++\n for( i in 1 .. n ){\n ans += cnt[( 5 - i % 5 ) % 5]\n }\n print( ans )\n}"}, {"source_code": "import java.util.*\nimport java.io.*\nimport java.lang.Math.*\n\n\nprivate fun exit(msg: String) {\n println(msg)\n System.exit(0)\n}\nprivate fun exit(msg: Long) = exit(\"\"+msg)\n\n\nfun main(args: Array) {\n val scan = object {\n private val reader = BufferedReader(InputStreamReader(System.`in`))\n private var tokenizer: StringTokenizer? = null\n \n internal operator fun next(): String {\n var t = tokenizer\n while (t == null || !t.hasMoreTokens()) {\n t = StringTokenizer(line())\n }\n return t.nextToken().apply { tokenizer = t }\n }\n \n internal fun int(): Int = next().toInt()\n internal fun long(): Long = next().toLong()\n internal fun double() = next().toDouble()\n \n internal fun line() = reader.readLine()\n \n }\n\n val n = scan.int()\n val m = scan.int()\n\n val xi = {x:Int ->\n LongArray(5) {i -> x / 5L + if (x % 5 >= i % 5) 1 else 0}.apply { this[0] -- }\n }\n val ni = xi(n)\n val mi = xi(m)\n\n val res = ni.mapIndexed { index, x -> x * mi[(5-index) % 5] }.sum()\n exit(res)\n}\n\n "}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val (m, n) = r.readLine()!!.split(\" \").map { it.toLong() }\n var ans = 0L\n ans += (m - m % 5) * (n / 5)\n ans += n % 5 * (m / 5)\n ans += m % 5 * (n / 5)\n when {\n m%5==1L&&n%5==4L -> {\n ans++\n }\n m%5==2L&&n%5>=3L -> {\n ans+=(n%5)-2\n }\n m%5==3L&&n%5>=2L -> {\n ans+=(n%5)-1\n }\n m%5==4L&&n%5>=1L -> {\n ans+=(n%5)-0\n }\n }\n println(ans)\n}"}, {"source_code": "import java.io.*\nimport java.math.BigDecimal\nimport java.math.BigInteger\nimport java.util.*\nimport kotlin.collections.HashSet\n\n\nobject programkt {\n interface Scanner {\n fun changeInputStream(inputStream: InputStream)\n fun nextInt(): Int\n fun nextLong(): Long\n fun nextDouble(): Double\n fun nextChar(): Char\n fun nextString(): String\n fun nextLine(): String\n fun nextBigInteger(): BigInteger\n fun nextBigDecimal(): BigDecimal\n }\n\n abstract class Task {\n //KT Extensions\n fun > min(a: T, b: T) = if (a > b) b else a\n fun > max(a: T, b: T) = if (a < b) b else a\n fun abs(a: Int) = if (a > 0) a else -(a)\n fun abs(a: Long) = if (a > 0) a else -(a)\n fun abs(a: Float) = if (a > 0) a else -(a)\n fun abs(a: Double) = if (a > 0) a else -(a)\n operator fun Iterable.invoke(function: (it: T) -> Unit) { this.forEach(function) }\n private fun String.prefix(pi: Array): Array {\n pi[0] = 0\n (1 until this.length) {\n var j = pi[it - 1]\n while (j > 0 && this[it] != this[j]) {\n j = pi[j - 1]\n }\n if(this[it] == this[j]) {\n j++\n }\n pi[it] = j\n }\n return pi\n }\n private fun String.kmpFind(pattern: String): Int {\n val m = pattern.length\n val dfa = Array(256) { IntArray(m) }\n dfa[pattern[0].toInt()][0] = 1\n var x = 0\n var j = 1\n while (j < m) {\n for (c in 0 until 256) {\n dfa[c][j] = dfa[c][x] // Copy mismatch cases.\n }\n dfa[pattern[j].toInt()][j] = j + 1 // Set match case.\n x = dfa[pattern[j].toInt()][x] // Update restart state.\n j++\n }\n\n val n = this.length\n var i: Int = 0\n j = 0\n while (i < n && j < m) {\n j = dfa[this[i].toInt()][j]\n i++\n }\n if (j == m) return i - m // found\n return n // not found\n }\n fun fuckExceptions(invoker: () -> Unit) = try { invoker.invoke() } catch (_: Throwable) {}\n\n enum class EdgeType {\n DIRECTED,\n UNDIRECTED\n }\n data class Vertex>(\n val data: T\n ) {\n override fun toString(): String = \"V:$data\"\n }\n data class Edge>(\n var source: Vertex,\n var destination: Vertex,\n val weight: Double?\n )\n interface Graphable> {\n fun createVertex(data: T): Vertex\n fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double? = 0.0)\n fun weight(source: Vertex, destination: Vertex): Double?\n fun edges(source: Vertex): MutableList>?\n }\n class AdjacencyList>: Graphable {\n var adjacencyMap: MutableMap, MutableList>> = mutableMapOf()\n\n private fun addDirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n adjacencyMap[source]?.add(Edge(source = source, destination = destination, weight = weight))\n }\n\n private fun addUndirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n addDirectedEdge(source, destination, weight)\n addDirectedEdge(destination, source, weight)\n }\n\n override fun createVertex(data: T): Vertex {\n val vertex = Vertex(data = data)\n adjacencyMap[vertex] ?: run {\n adjacencyMap[vertex] = mutableListOf()\n }\n return vertex\n }\n\n override fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double?) = when(type) {\n EdgeType.DIRECTED -> addDirectedEdge(source, destination, weight)\n EdgeType.UNDIRECTED -> addUndirectedEdge(source, destination, weight)\n }\n\n override fun weight(source: Vertex, destination: Vertex): Double? {\n adjacencyMap[source]?.forEach {\n if(it.destination == destination) return it.weight\n }\n return null\n }\n\n override fun edges(source: Vertex): MutableList>? = adjacencyMap[source]\n\n override fun toString(): String {\n var result = \"\"\n for ((vertex, edges) in adjacencyMap) {\n var edgeString = \"\"\n for ((index, edge) in edges.withIndex()) {\n edgeString += if (index != edges.count() - 1) \"${edge.destination}, \"\n else \"${edge.destination}\"\n }\n result += \"$vertex ---> [ $edgeString ] \\n\"\n }\n return result\n }\n\n fun depthFirstSearch(start: Vertex, end: Vertex): Stack> {\n val visited: HashSet> = hashSetOf()\n val stack: Stack> = Stack()\n stack.push(start)\n visited.add(start)\n\n var currentVertex = stack.peek()\n loop@while (currentVertex != null && currentVertex != end) {\n val neighbors = edges(currentVertex)\n if(neighbors != null && neighbors.count() > 0) {\n for(edge in neighbors) {\n if(!visited.contains(edge.destination)) {\n visited.add(edge.destination)\n stack.push(edge.destination)\n currentVertex = stack.peek()\n continue@loop\n }\n }\n } else {\n stack.pop()\n currentVertex = stack.peek()\n continue\n }\n\n stack.pop()\n currentVertex = stack.peek()\n }\n\n return stack\n }\n\n fun breadthFirstSearch() {\n\n }\n }\n //End KT Extensions\n\n abstract fun solve(scanner: Scanner, printer: PrintWriter)\n }\n\n class FastScanner: Scanner {\n var inputStream: InputStream? = null\n override fun changeInputStream(inputStream: InputStream) {\n this.inputStream = inputStream\n this.bufferedReader = BufferedReader(InputStreamReader(inputStream))\n }\n\n private lateinit var bufferedReader: BufferedReader\n private var stringTokenizer: StringTokenizer? = null\n\n private fun nextToken(): String? {\n while (stringTokenizer == null || !stringTokenizer!!.hasMoreTokens())\n stringTokenizer = StringTokenizer(bufferedReader.readLine() ?: return null)\n return stringTokenizer!!.nextToken()\n }\n\n override fun nextInt() = nextToken()!!.toInt()\n override fun nextLong() = nextToken()!!.toLong()\n override fun nextDouble() = nextToken()!!.toDouble()\n override fun nextChar() = bufferedReader.read().toChar()\n override fun nextString() = nextToken()!!\n override fun nextLine() = bufferedReader.readLine()!!\n override fun nextBigInteger() = BigInteger(nextToken()!!)\n override fun nextBigDecimal() = BigDecimal(nextToken()!!)\n }\n\n class TaskBuilder {\n private var task: Task? = null\n private var inputStream: InputStream? = null\n private var outputStream: OutputStream? = null\n private var scanner: Scanner? = null\n\n fun useInputSource(inputStream: InputStream): TaskBuilder {\n this.inputStream = inputStream\n return this\n }\n\n fun useOutputSource(outputStream: OutputStream): TaskBuilder {\n this.outputStream = outputStream\n return this\n }\n\n fun useInputFile(inputFileName: String): TaskBuilder {\n this.inputStream = FileInputStream(File(inputFileName))\n return this\n }\n\n fun useOutputFile(outputFileName: String): TaskBuilder {\n this.outputStream = FileOutputStream(File(outputFileName))\n return this\n }\n\n fun useScanner(scanner: Scanner): TaskBuilder {\n this.scanner = scanner\n return this\n }\n\n\n fun solveTask(task: Task): TaskBuilder {\n this.task = task\n return this\n }\n\n fun run() {\n when {\n task == null -> throw NullPointerException(\"Task cannot be null!\")\n inputStream == null -> throw NullPointerException(\"Input cannot be null!\")\n outputStream == null -> throw NullPointerException(\"Output cannot be null!\")\n scanner == null -> throw NullPointerException(\"Scanner cannot be null!\")\n }\n scanner!!.changeInputStream(inputStream!!)\n val printer = PrintWriter(outputStream)\n TaskRunnable(task!!, scanner!!, printer).run()\n\n inputStream!!.close()\n printer.close()\n }\n\n class TaskRunnable(\n private val task: Task,\n private val scanner: Scanner,\n private val printer: PrintWriter\n ) {\n fun run() {\n task.solve(scanner, printer)\n }\n }\n }\n\n @JvmStatic\n fun main(args: Array) = TaskBuilder()\n .useInputSource(System.`in`)\n .useOutputSource(System.out)\n .useScanner(FastScanner())\n .solveTask(TaskI())\n .run()\n\n class TaskA: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val countOfRooms = scanner.nextInt()\n val rooms = Array(countOfRooms) { scanner.nextInt() to scanner.nextInt() }\n printer.println(rooms\n .map { it.second - it.first }\n .filter { it >= 2 }\n .count())\n }\n\n }\n\n class TaskB: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val firstName = scanner.nextLine()\n val secondName = scanner.nextLine()\n val mixedUpName = scanner.nextLine()\n\n val alphabet = Array(26) { 0 }\n val mixedUpAlphabet = Array(26) { 0 }\n\n firstName.forEach { alphabet[it - 'A']++ }\n secondName.forEach { alphabet[it - 'A']++ }\n mixedUpName.forEach { mixedUpAlphabet[it - 'A']++ }\n\n for (it in 0..25) {\n if (alphabet[it] != mixedUpAlphabet[it]) {\n printer.println(\"NO\")\n return\n }\n\n }\n printer.println(\"YES\")\n }\n\n }\n\n class TaskC: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val countOfCubes = scanner.nextInt()\n\n var cubeSum = 0\n var height = 0\n while(cubeSum <= countOfCubes) {\n height++\n cubeSum += (height * (height + 1)) / 2\n }\n printer.println(height - 1)\n }\n\n }\n\n class TaskD: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val stringLength = scanner.nextInt()\n\n var result = 0\n (0 until stringLength) {\n val char = scanner.nextChar()\n when(char) {\n '0' -> result++\n '1' -> result--\n }\n }\n printer.println(if (result < 0) -result else result)\n }\n\n }\n\n class TaskE: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val wordCount = scanner.nextInt()\n val compukterDelay = scanner.nextInt()\n val words = Array(100005) { 0 }\n var screenedWords = 1\n\n (1..wordCount) { words[it] = scanner.nextInt() }\n\n var it = wordCount - 1\n while (it >= 1) {\n if (words[it + 1] - words[it] > compukterDelay)\n break\n it--\n screenedWords++\n }\n printer.println(screenedWords)\n }\n\n }\n\n class TaskF: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val count = scanner.nextInt()\n val lengths = Array(count) { scanner.nextInt() }.sortedArray()\n\n var l = 0\n var b1 = 0\n var b2 = 0\n\n for (it in 0 until count) {\n if (it == count - 1 || lengths[it] != lengths[it + 1]) {\n b1 = Math.max(b1, it - l + 1)\n b2++\n l = it + 1\n }\n }\n printer.println(b1.toString() + \" \" + b2)\n }\n\n }\n\n class TaskG: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val aLength = scanner.nextInt()\n val bLength = scanner.nextInt()\n val k = scanner.nextInt()\n val m = scanner.nextInt()\n\n val a = Array(aLength) { scanner.nextInt() }\n val b = Array(bLength) { scanner.nextInt() }\n printer.println(if(a[k-1] firstWinCount++\n didFirstWin > didSecondWin -> secondWinCount++\n else -> nobodyWinCount++\n }\n }\n printer.println(\"$firstWinCount $nobodyWinCount $secondWinCount\")\n }\n\n }\n\n class TaskI: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val n = scanner.nextLong()\n val m = scanner.nextLong()\n\n var countOfPairs = 0L\n (1..n) {\n countOfPairs += (m + it % 5) / 5\n }\n printer.println(countOfPairs)\n }\n\n }\n\n class TaskJ: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val iqCount = scanner.nextInt()\n val iq = Array(iqCount) { scanner.nextInt() }\n\n val oddness = iq[0] % 2 + iq[1] % 2 + iq[2] % 2 >= 2\n (0 until iqCount) {\n if (iq[it] % 2 == 1 && !oddness)\n printer.println(it + 1)\n if (iq[it] % 2 == 0 && oddness)\n printer.println(it + 1)\n }\n }\n\n }\n\n class TaskK: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n scanner.nextLine().toLowerCase().forEach { when(it) {\n !in arrayOf('a', 'o', 'y', 'e', 'u', 'i') -> printer.print(\".$it\")\n } }\n }\n\n }\n\n class TaskL: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n \n }\n\n }\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val a = ir.nextInt()\n val b = ir.nextInt()\n\n val x = Math.min(a, b)\n val y = Math.max(a, b)\n\n var best: Long = 0\n var m = 5\n while (true) {\n val low = Math.max(1, m - y)\n val high = Math.min(x, m - 1)\n if (low > x) {\n pw.println(best)\n return\n }\n best += 0 + high - low + 1\n m += 5\n }\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val a = ir.nextInt()\n val b = ir.nextInt()\n\n val x = Math.min(a, b)\n val y = Math.max(a, b)\n\n var best: Long = 0\n var m = 5\n while (true) {\n val low = Math.max(1, m - y)\n val high = Math.min(x, m - 1)\n if (low > x) {\n pw.println(best)\n return\n }\n best += high - low + 1\n m += 5\n }\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}"}, {"source_code": "import java.util.*\n \n \nfun main(args: Array){\n val ( n, m ) = readLine()!!.split(' ').map(String::toInt)\n var ans: Long = 0\n var cnt: IntArray = IntArray( 6 )\n for( i in 1 .. m ) cnt[i % 5]++\n for( i in 1 .. n ){\n ans += cnt[( 5 - i % 5 ) % 5]\n }\n print( ans )\n}"}, {"source_code": "import java.util.*\n \n \nfun main(args: Array){\n val ( n, m ) = readLine()!!.split(' ').map(String::toInt)\n var ans: Long = 0\n var cnt: IntArray = IntArray( 6 )\n for( i in 1 .. m ) cnt[i % 5]++\n for( i in 1 .. n ){\n ans += cnt[( 5 - i % 5 ) % 5]\n }\n print( ans )\n}"}], "negative_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val (n, m) = br.readLine().split(\" \").map { it.toInt() }\n val minBound = min(n, m)\n val maxBound = max(n, m)\n println((1..minBound).fold(0){acc, i ->\n acc + (maxBound + i)/5 - i/5\n })\n}"}, {"source_code": "fun main() {\n val (n, m) = readLine()!!.split(\" \").map { it.toInt() }\n var sol = 0\n for (i in 1..n) {\n var j = 5 - i % 5\n if (j == 0) {\n j = 5\n }\n j = m - j\n if (j >= 0) {\n sol += 1 + j / 5\n }\n }\n print(sol)\n}"}, {"source_code": "import java.util.*\nimport java.io.*\nimport java.lang.Math.*\n\n\nprivate fun exit(msg: String) {\n println(msg)\n System.exit(0)\n}\nprivate fun exit(msg: Int) = exit(\"\"+msg)\n\n\nfun main(args: Array) {\n val scan = object {\n private val reader = BufferedReader(InputStreamReader(System.`in`))\n private var tokenizer: StringTokenizer? = null\n \n internal operator fun next(): String {\n var t = tokenizer\n while (t == null || !t.hasMoreTokens()) {\n t = StringTokenizer(line())\n }\n return t.nextToken().apply { tokenizer = t }\n }\n \n internal fun int(): Int = next().toInt()\n internal fun long(): Long = next().toLong()\n internal fun double() = next().toDouble()\n \n internal fun line() = reader.readLine()\n \n }\n\n val n = scan.int()\n val m = scan.int()\n\n val xi = {x:Int ->\n IntArray(5) {i -> x / 5 + if (x % 5 >= i % 5) 1 else 0}.apply { this[0] -- }\n }\n val ni = xi(n)\n val mi = xi(m)\n\n val res = ni.mapIndexed { index, x -> x * mi[(5-index) % 5] }.sum()\n exit(res)\n}\n\n "}], "src_uid": "df0879635b59e141c839d9599abd77d2"} {"nl": {"description": "We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1, 3, 2, 1} is 2.Diameter of multiset consisting of one point is 0.You are given n points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed d?", "input_spec": "The first line contains two integers n and d (1 ≤ n ≤ 100, 0 ≤ d ≤ 100) — the amount of points and the maximum allowed diameter respectively. The second line contains n space separated integers (1 ≤ xi ≤ 100) — the coordinates of the points.", "output_spec": "Output a single integer — the minimum number of points you have to remove.", "sample_inputs": ["3 1\n2 1 4", "3 0\n7 7 7", "6 3\n1 3 4 6 9 10"], "sample_outputs": ["1", "0", "3"], "notes": "NoteIn the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.In the second test case the diameter is equal to 0, so its is unnecessary to remove any points. In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3."}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val n = reader.nextInt()\n val d = reader.nextInt()\n\n val a = mutableMapOf().toSortedMap()\n for (i in 0 until n) {\n val x = reader.nextInt()\n a.put(x, a.getOrDefault(x, 0) + 1)\n }\n\n if (a.size == 1) {\n writer.print(\"0\")\n return\n }\n\n var ans = n\n for ((k, _) in a) {\n val c = a.filter { it.key < k || it.key > k + d }.map { it.value }.sum()\n ans = min(ans, c)\n }\n\n writer.print(ans)\n}\n\nclass InputReader(stream: InputStream) {\n val reader: BufferedReader\n var tokenizer: StringTokenizer? = null\n\n init {\n reader = BufferedReader(InputStreamReader(stream), 32768)\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}\n\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val s = Scanner(System.`in`)\n val n = s.nextInt()\n val desiredDiameter = s.nextInt()\n val numbers = Array(n, { _ -> 0 })\n\n for (i in 0..n-1) {\n numbers[i] = s.nextInt()\n }\n\n numbers.sort()\n\n var from = 0\n var to = 0\n var optimalRemoved = Int.MAX_VALUE\n while (to <= numbers.lastIndex) {\n val d = numbers[to] - numbers[from]\n\n if (d <= desiredDiameter) {\n optimalRemoved = minOf(from + (numbers.size - to - 1), optimalRemoved)\n }\n\n if (d <= desiredDiameter) {\n to++\n } else {\n from++\n }\n }\n\n println(optimalRemoved)\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n fun List.bsRight(value: Int): Int {\n var left = 0\n var right = this.lastIndex\n var pivot: Int\n while (left <= right) {\n pivot = (left + right) / 2\n if (this[pivot] > value) right = pivot - 1 else left = pivot + 1\n }\n return left - 1\n }\n\n val (numPoints, diameter) = readInts()\n val arr = readInts().sorted()\n val stop = arr.last() - diameter\n if (stop <= arr[0]) {\n print(0)\n return\n }\n var result = Integer.MAX_VALUE\n var left = -1\n var right: Int\n while (++left < numPoints && arr[left] <= stop) {\n right = arr.bsRight(arr[left] + diameter)\n val candidate = numPoints - right + left - 1\n if (candidate < result) result = candidate\n }\n if(left < numPoints) {\n right = arr.bsRight(arr[left] + diameter)\n val candidate = numPoints - right + left - 1\n if (candidate < result) result = candidate\n }\n print(result)\n}"}, {"source_code": "fun main(args:Array) {\n val (m,n) = readLine()!!.split(\" \").map(String::toInt)\n\n val target = readLine()!!.split(\" \").map(String::toInt).sorted()\n\n val ansbox = mutableListOf>()\n \n for( start in (0..target.size-1) ) {\n for( end in (start..target.size-1) ) {\n val delta = target[end] - target[start]\n if( n >= delta ) {\n val ans = target.size - (end-start + 1)\n ansbox.add(Pair(delta, ans))\n }\n }\n }\n //println(ansbox)\n if(ansbox.minBy{ it.second } == null)\n if( m <= n ) \n println(0)\n else if( n >= 1 ) \n println(target.size - 1)\n else\n println(0)\n else\n println(ansbox.minBy{ it.second }!!.second)\n}"}, {"source_code": "fun main(args: Array){\n\tval string1: String = readLine().toString()\n\tvar mnozh: List = readLine().toString().split(\" \").map{x -> x.toInt()}\n\tval N = string1.split(\" \")[0].toInt()\n\tval expD = string1.split(\" \")[1].toInt()\n\tmnozh = mnozh.sorted()\n\tval D = mnozh.last() - mnozh.first()\n\tif (D <= expD){\n\t\tprintln(0)\n\t}else{\n\t\t//println(\"Expected: $expD, real: $D\")\n\t\tvar realD: Int\n\t\tvar minDropped = 101\n\t\tvar dropped: Int\n\t\tfor (i in 0..N-1){\n\t\t\tfor (j in i..N-1){\n\t\t\t\trealD = mnozh[j]-mnozh[i]\n\t\t\t\tdropped = N - (j - i + 1)\n\t\t\t\tif((realD <= expD) and (dropped <= minDropped)){\n\t\t\t\t\tminDropped = dropped\n\t\t\t\t\t//println(\"i: $i, j: $j, Distance: $realD, dropped: $dropped\")\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tprintln(minDropped)\t\t\n\t}\n}\n"}], "negative_code": [{"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val n = reader.nextInt()\n val d = reader.nextInt()\n\n val a = mutableMapOf().toSortedMap()\n for (i in 0 until n) {\n val x = reader.nextInt()\n a.put(x, a.getOrDefault(x, 0) + 1)\n }\n\n if (a.size == 1) {\n writer.print(\"0\")\n return\n }\n\n var ans = n\n var v = a.map { it.key }\n for (i in 0 until v.lastIndex) {\n val c = a.filter { it.key < v[i] || it.key > v[i] + d }.map { it.value }.sum()\n ans = min(ans, c)\n }\n\n writer.print(ans)\n}\n\nclass InputReader(stream: InputStream) {\n val reader: BufferedReader\n var tokenizer: StringTokenizer? = null\n\n init {\n reader = BufferedReader(InputStreamReader(stream), 32768)\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}\n\n"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n fun List.bsRight(value: Int): Int {\n var left = 0\n var right = this.lastIndex\n var pivot: Int\n while (left <= right) {\n pivot = (left + right) / 2\n if (this[pivot] > value) right = pivot - 1 else left = pivot + 1\n }\n return left - 1\n }\n\n val (numPoints, diameter) = readInts()\n val arr = readInts().sorted()\n val stop = arr.last() - diameter\n if (stop <= arr[0]) {\n print(0)\n return\n }\n var result = Integer.MAX_VALUE\n var left = -1\n var right: Int\n while (++left < numPoints && arr[left] <= stop) {\n right = arr.bsRight(arr[left] + diameter)\n val candidate = numPoints - right + left - 1\n if (candidate < result) result = candidate\n }\n print(result)\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n fun List.bsRight(value: Int): Int {\n var left = 0\n var right = this.lastIndex\n var pivot: Int\n while (left <= right) {\n pivot = (left + right) / 2\n if (this[pivot] > value) right = pivot - 1 else left = pivot + 1\n }\n return left - 1\n }\n\n val (numPoints, diameter) = readInts()\n val arr = readInts().sorted()\n val stop = arr.last() - diameter\n var result = Integer.MAX_VALUE\n var left = -1\n var right: Int\n while (++left < numPoints && arr[left] <= stop) {\n right = arr.bsRight(arr[left] + diameter)\n val candidate = numPoints - right + left - 1\n if (candidate < result) result = candidate\n }\n print(result)\n}"}, {"source_code": "fun main(args:Array) {\n val (m,n) = readLine()!!.split(\" \").map(String::toInt)\n\n val target = readLine()!!.split(\" \").map(String::toInt).sorted()\n\n val ansbox = mutableListOf()\n \n for( start in (0..target.size-1) ) {\n for( end in (start..target.size-1) ) {\n val delta = target[end] - target[start]\n if( n == delta ) {\n val ans = target.size - (end-start + 1)\n ansbox.add(ans)\n }\n }\n }\n if(ansbox.min() == null)\n println(0)\n else\n println(ansbox.min()!!)\n}"}, {"source_code": "fun main(args:Array) {\n val (m,n) = readLine()!!.split(\" \").map(String::toInt)\n\n val target = readLine()!!.split(\" \").map(String::toInt).sorted()\n\n val ansbox = mutableListOf()\n \n for( start in (0..target.size-1) ) {\n for( end in (start..target.size-1) ) {\n val delta = target[end] - target[start]\n if( n == delta ) {\n val ans = target.size - (end-start + 1)\n ansbox.add(ans)\n }\n }\n }\n if(ansbox.min() == null)\n if( m <= n ) \n println(0)\n else if( n >= 1 ) \n println(target.size - 1)\n else\n println(0)\n else\n println(ansbox.min()!!)\n}"}, {"source_code": "\nfun main(args:Array) {\n val (m,n) = readLine()!!.split(\" \").map(String::toInt)\n\n val target = readLine()!!.split(\" \").map(String::toInt).sorted()\n\n val ansbox = mutableListOf()\n \n for( start in (0..target.size-1) ) {\n for( end in (start..target.size-1) ) {\n val delta = target[end] - target[start]\n if( n == delta ) {\n val ans = target.size - (end-start + 1)\n ansbox.add(ans)\n }\n }\n }\n if(ansbox.min() == null)\n if( n == 1 ) \n println(target.size - 1)\n else\n println(0)\n else\n println(ansbox.min()!!)\n}"}, {"source_code": "fun main(args:Array) {\n val (m,n) = readLine()!!.split(\" \").map(String::toInt)\n\n val target = readLine()!!.split(\" \").map(String::toInt).sorted()\n\n val ansbox = mutableListOf()\n \n for( start in (0..target.size-1) ) {\n for( end in (start..target.size-1) ) {\n val delta = target[end] - target[start]\n if( n == delta ) {\n val ans = target.size - (end-start + 1)\n ansbox.add(ans)\n }\n }\n }\n println(ansbox.min())\n}"}, {"source_code": "fun main(args:Array) {\n val (m,n) = readLine()!!.split(\" \").map(String::toInt)\n\n val target = readLine()!!.split(\" \").map(String::toInt).sorted()\n\n val ansbox = mutableListOf()\n \n for( start in (0..target.size-1) ) {\n for( end in (start..target.size-1) ) {\n val delta = target[end] - target[start]\n if( n == delta ) {\n val ans = target.size - (end-start + 1)\n ansbox.add(ans)\n }\n }\n }\n if(ansbox.min() == null)\n if( n >= 1 ) \n println(target.size - 1)\n else\n println(0)\n else\n println(ansbox.min()!!)\n}"}, {"source_code": "fun main(args:Array) {\n val (m,n) = readLine()!!.split(\" \").map(String::toInt)\n\n val target = readLine()!!.split(\" \").map(String::toInt).sorted()\n\n val ansbox = mutableListOf()\n \n for( start in (0..target.size-1) ) {\n for( end in (start..target.size-1) ) {\n val delta = target[end] - target[start]\n if( n == delta ) {\n val ans = target.size - (end-start + 1)\n ansbox.add(ans)\n }\n }\n }\n if(ansbox.min() == null)\n if( m < n ) \n println(0)\n else if( n >= 1 ) \n println(target.size - 1)\n else\n println(0)\n else\n println(ansbox.min()!!)\n}"}, {"source_code": "fun main(args: Array){\n\tval string1: String = readLine().toString()\n\tvar mnozh: List = readLine().toString().split(\" \").map{x -> x.toInt()}\n\tval N = string1.split(\" \")[0].toInt()\n\tval expD = string1.split(\" \")[1].toInt()\n\tmnozh = mnozh.sorted()\n\tval D = mnozh.last() - mnozh.first()\n\tif (D <= expD){\n\t\tprintln(0)\n\t}else{\n\t\t//println(\"Expected: $expD, real: $D\")\n\t\tvar realD: Int\n\t\tvar minDropped = 101\n\t\tvar dropped: Int\n\t\tfor (i in 0..N-2){\n\t\t\tfor (j in i+1..N-1){\n\t\t\t\trealD = mnozh[j]-mnozh[i]\n\t\t\t\tdropped = N - (j - i + 1)\n\t\t\t\tif((realD <= expD) and (dropped <= minDropped)){\n\t\t\t\t\tminDropped = dropped\n\t\t\t\t\t//println(\"i: $i, j: $j, Distance: $realD, dropped: $dropped\")\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tprintln(minDropped)\t\t\n\t}\n}\n"}], "src_uid": "6bcb324c072f796f4d50bafea5f624b2"} {"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": "import java.io.PrintWriter\nimport kotlin.math.*\n\nfun main() {\n io.apply {\n\n val d = ints()\n val i0 = d.indexOf(1)\n val i1 = d.indexOf(d.size)\n val m0 = min(i0, i1)\n val m1 = max(i0, i1)\n cout .. max(d.size - 1 - m0, m1) .. nl\n\n\n }.cout.flush()\n}\n\n// @formatter:off\nprivate val io = object {\n private val `in` = System.`in`\n private fun ll(): Long {\n var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }\n do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n\n }\n val int get() = ll().toInt(); val long get() = ll()\n fun ints(n: Int = int): IntArray { return IntArray(n) { int } }\n fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }\n val cout = PrintWriter(System.out); val nl = \"\\n\"\n private var buf = CharArray(32)\n private var bufSize = 32\n fun str(expect: Int = 32): String {\n var ix = 0\n var x: Int\n if (bufSize < expect)\n buf = CharArray(expect)\n do x = `in`.read() while (x < 33)\n do {\n if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }\n buf[ix++] = x.toChar()\n x = `in`.read()\n } while (x > 32)\n return java.lang.String.copyValueOf(buf, 0, ix)\n }\n operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(\" \") }; return this }\n operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }\n} // @formatter:on\n\n/* ----------- */\n\n"}, {"source_code": "import kotlin.math.min\n\nfun main() {\n val size = readLine()!!.toInt()\n val arr = readLine()!!.split(\" \").map { it.toInt() }\n val minPos = arr.indexOf(1)\n val maxPos = arr.indexOf(size)\n val closer = min(minPos, min(size - 1 - minPos, min(maxPos, size - 1 - maxPos)))\n print(size - 1 - closer)\n}"}, {"source_code": "import kotlin.math.min\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val size = readInt()\n val arr = readInts()\n val minPos = arr.indexOf(1)\n val maxPos = arr.indexOf(size)\n val closer = min(minPos, min(size - 1 - minPos, min(maxPos, size - 1 - maxPos)))\n print(size - 1 - closer)\n}"}, {"source_code": "import java.lang.Integer.max\nimport java.util.*\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n var minElement = Int.MAX_VALUE\n var maxElement = Int.MIN_VALUE\n var minElementPos = -1\n var maxElementPos = -1\n\n repeat (n) {\n val current = scanner.nextInt()\n if (current < minElement) {\n minElement = current\n minElementPos = it\n }\n\n if (current > maxElement) {\n maxElement = current\n maxElementPos = it\n }\n }\n\n if (minElementPos < maxElementPos) {\n println(max(maxElementPos, n - 1 - minElementPos))\n } else {\n println(max(minElementPos, n - 1 - maxElementPos))\n }\n}"}], "negative_code": [{"source_code": "import java.lang.Integer.max\nimport java.util.*\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n var minElement = Int.MAX_VALUE\n var maxElement = Int.MIN_VALUE\n var minElementPos = -1\n var maxElementPos = -1\n\n repeat (n) {\n val current = scanner.nextInt()\n if (current < minElement) {\n minElement = current\n minElementPos = it\n } else if (current > maxElement) {\n maxElement = current\n maxElementPos = it\n }\n }\n\n if (minElementPos < maxElementPos) {\n println(max(maxElementPos, n - 1 - minElementPos))\n } else {\n println(max(minElementPos, n - 1 - maxElementPos))\n }\n}"}], "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4"} {"nl": {"description": "You have two positive integers w and h. Your task is to count the number of rhombi which have the following properties: Have positive area. With vertices at integer points. All vertices of the rhombi are located inside or on the border of the rectangle with vertices at points (0, 0), (w, 0), (w, h), (0, h). In other words, for all vertices (xi, yi) of the rhombus the following conditions should fulfill: 0 ≤ xi ≤ w and 0 ≤ yi ≤ h. Its diagonals are parallel to the axis. Count the number of such rhombi.Let us remind you that a rhombus is a quadrilateral whose four sides all have the same length.", "input_spec": "The first line contains two integers w and h (1 ≤ w, h ≤ 4000) — the rectangle's sizes.", "output_spec": "Print a single number — the number of sought rhombi. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.", "sample_inputs": ["2 2", "1 2"], "sample_outputs": ["1", "0"], "notes": "NoteIn the first example there exists only one such rhombus. Its vertices are located at points (1, 0), (2, 1), (1, 2), (0, 1)."}, "positive_code": [{"source_code": "import java.util.*\n\nfun main() {\n\n val scanner = Scanner(System.`in`)\n\n val w = scanner.nextInt()\n val h = scanner.nextInt()\n\n var ans: Long = 0\n\n for (x in 0..w) {\n for (y in 0..h) {\n if (x % 2 == 0 && y % 2 == 0 && x > 0 && y > 0) {\n ans += (w - x + 1) * (h - y + 1)\n }\n }\n }\n\n println(ans)\n\n}\n\n"}, {"source_code": "\n\nimport java.util.*\n\nfun main() {\n var w: Int\n var h: Int\n\n with(Scanner(System.`in`)) {\n w = nextInt()\n h = nextInt()\n }\n\n var count = 0L\n\n for (i in w / 2 downTo 1 step 1) {\n for (j in h / 2 downTo 1 step 1) {\n count += (w - i * 2 + 1) * (h - j * 2 +1)\n }\n }\n print(count)\n}"}], "negative_code": [{"source_code": "\nimport java.util.*\n\nfun main() {\n var w: Int\n var h: Int\n\n with(Scanner(System.`in`)) {\n w = nextInt()\n h = nextInt()\n }\n\n var count = 0\n\n for (i in w / 2 downTo 1 step 1) {\n for (j in h / 2 downTo 1 step 1) {\n count += (w - i * 2 + 1) * (h - j * 2 +1)\n }\n }\n print(count)\n}"}], "src_uid": "42454dcf7d073bf12030367eb094eb8c"} {"nl": {"description": "Let's introduce some definitions that will be needed later.Let $$$prime(x)$$$ be the set of prime divisors of $$$x$$$. For example, $$$prime(140) = \\{ 2, 5, 7 \\}$$$, $$$prime(169) = \\{ 13 \\}$$$.Let $$$g(x, p)$$$ be the maximum possible integer $$$p^k$$$ where $$$k$$$ is an integer such that $$$x$$$ is divisible by $$$p^k$$$. For example: $$$g(45, 3) = 9$$$ ($$$45$$$ is divisible by $$$3^2=9$$$ but not divisible by $$$3^3=27$$$), $$$g(63, 7) = 7$$$ ($$$63$$$ is divisible by $$$7^1=7$$$ but not divisible by $$$7^2=49$$$). Let $$$f(x, y)$$$ be the product of $$$g(y, p)$$$ for all $$$p$$$ in $$$prime(x)$$$. For example: $$$f(30, 70) = g(70, 2) \\cdot g(70, 3) \\cdot g(70, 5) = 2^1 \\cdot 3^0 \\cdot 5^1 = 10$$$, $$$f(525, 63) = g(63, 3) \\cdot g(63, 5) \\cdot g(63, 7) = 3^2 \\cdot 5^0 \\cdot 7^1 = 63$$$. You have integers $$$x$$$ and $$$n$$$. Calculate $$$f(x, 1) \\cdot f(x, 2) \\cdot \\ldots \\cdot f(x, n) \\bmod{(10^{9} + 7)}$$$.", "input_spec": "The only line contains integers $$$x$$$ and $$$n$$$ ($$$2 \\le x \\le 10^{9}$$$, $$$1 \\le n \\le 10^{18}$$$) — the numbers used in formula.", "output_spec": "Print the answer.", "sample_inputs": ["10 2", "20190929 1605", "947 987654321987654321"], "sample_outputs": ["2", "363165664", "593574252"], "notes": "NoteIn the first example, $$$f(10, 1) = g(1, 2) \\cdot g(1, 5) = 1$$$, $$$f(10, 2) = g(2, 2) \\cdot g(2, 5) = 2$$$.In the second example, actual value of formula is approximately $$$1.597 \\cdot 10^{171}$$$. Make sure you print the answer modulo $$$(10^{9} + 7)$$$.In the third example, be careful about overflow issue."}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007\nfun factorize(a: Int): MutableMap {\n val res = mutableMapOf()\n var x = a\n loop@while(x > 1) {\n var i = 2\n while(i * i <= x) {\n if (x % i == 0) {\n res.merge(i, 1, Int::plus)\n x /= i\n continue@loop\n }\n i++\n }\n res.merge(x, 1, Int::plus)\n x = 0\n }\n return res\n}\nfun powMod(a: Int, n: Long, mod: Int): Long {\n if (n == 0L) return 1\n val res = powMod((a.toLong() * a % mod).toInt(), n / 2, mod)\n return if (n % 2 == 1L) res * a % mod else res\n}\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val X = ni()\n val N = nl()\n\n val fs = factorize(X)\n var ans = 1L\n for ((p, _) in fs) {\n var n = N\n while(n >= p) {\n n /= p\n ans = ans * powMod(p, n, MOD) % MOD\n }\n }\n\n out.println(ans)\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl() + offset\n }\n return res\n }\n\n private fun na2(n: Int, offset: Int = 0): Array {\n val a = Array(2){IntArray(n)}\n for (i in 0 until n) {\n for (e in a) {\n e[i] = ni() + offset\n }\n }\n return a\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.sqrt\n\nconst val mod = 1000000007L\n\nfun main() {\n val s = Scanner(System.`in`)\n val x = s.nextLong()\n val n = s.nextLong()\n\n var ans = 1L\n val primes = getPrimes(x)\n primes.forEach {\n var itt = it\n var cnt = 0L\n while (true) {\n cnt += n / itt\n if (itt <= n / it) // 如果直接itt*=it再判断itt<=n会爆Long\n itt *= it\n else\n break\n }\n ans = ans * fpow(it, cnt) % mod\n }\n print(ans)\n}\n\nfun getPrimes(x: Long): Set {\n val primes = MutableList(0) { 0L }\n\n val sqrtx = sqrt(x.toDouble()).toLong() + 5\n var xx = x\n var i = 2L\n while (xx > 1) {\n if (xx % i == 0L)\n primes.add(i)\n while (xx % i == 0L)\n xx /= i\n if (++i > sqrtx)\n break\n }\n if (xx > 1)\n primes.add(xx)\n\n return primes.toSet()\n}\nfun fpow(x: Long, n: Long, m: Long = mod): Long {\n if (n == 0L)\n return 1\n var ans = 1L\n var xx = x % mod\n var nn = n\n while (nn > 1) {\n if (nn % 2 == 1L)\n ans = ans * xx % mod\n nn /= 2\n xx = xx * xx % mod\n }\n return ans * xx % mod\n}"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() {\n output {\n val x = readInt()\n val n = readLong()\n\n val primes = x.factorize().distinct().toList()\n\n var ans = ModInt(1)\n\n for(p in primes) {\n var k = 0L\n var nn = n\n while(nn > 0) {\n nn /= p\n k += nn\n }\n ans *= ModInt(p).pow(k)\n }\n\n println(ans)\n }\n}\n\nfun Int.factorize() = sequence {\n var n = this@factorize\n\n for(p in 2..Int.MAX_VALUE) {\n if(p * p > n) break\n while(n % p == 0) {\n yield(p)\n n /= p\n }\n }\n\n if(n > 1) yield(n)\n}\n\nconst val BILLION7 = 1e9.toInt() + 7\nconst val MODINT_BASE = BILLION7\n\ninline infix fun Int.umod(base: Int) = Math.floorMod(this, base)\ninline infix fun Long.umod(base: Long) = Math.floorMod(this, base)\ninline infix fun Long.umod(base: Int) = Math.floorMod(this, base.toLong()).toInt()\n\nfun Int.mulMod(other: Int, mod: Int) = (toLong() * other).umod(mod)\n\nfun Int.powMod(exponent: Int, mod: Int): Int {\n var res = 1L\n var e = exponent\n var b = umod(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\n\ninline fun Int.toModInt() = ModInt(this umod MODINT_BASE)\ninline fun Long.toModInt() = ModInt(this umod MODINT_BASE)\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n companion object {\n /** can't seem to make these private or inlined without causing compiler issues */\n @JvmField val _invMemo = HashMap()\n fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }\n }\n\n inline operator fun plus(other: ModInt) = plus(other.int) // MODINT_BASE < 2^30\n inline operator fun plus(other: Int) = (int + other).toModInt() // careful of possible overflow\n inline operator fun inc() = plus(1)\n\n inline operator fun minus(other: ModInt) = minus(other.int)\n inline operator fun minus(other: Int) = (int - other).toModInt()\n inline operator fun dec() = minus(1)\n operator fun unaryMinus() = if(int == 0) this else ModInt(MODINT_BASE - int)\n\n inline operator fun times(other: ModInt) = times(other.int)\n inline operator fun times(other: Int) = ModInt(int.mulMod(other, MODINT_BASE))\n\n fun pow(exponent: Int): ModInt {\n val e = if(exponent < 0) exponent umod MODINT_BASE - 1 else exponent // assumes MODINT_BASE is prime\n return ModInt(int.powMod(e, MODINT_BASE))\n }\n\n fun pow(exponent: Long) = pow(exponent umod MODINT_BASE - 1) // assumes MODINT_BASE is prime\n\n inline fun inverse() = inv_memoized() /** NOTE: Change if necessary */\n\n fun inv_unmemoized(): ModInt {\n require(int != 0) { \"Can't invert/divide by 0\" }\n return pow(MODINT_BASE - 2) // assumes MODINT_BASE is prime\n }\n inline fun inv_memoized() = _invMemoized(this)\n\n operator fun div(other: ModInt) = times(other.inverse())\n inline operator fun div(other: Int) = div(other.toModInt())\n\n override fun toString() = int.toString()\n}\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n inline operator fun get(i: Int) = ModInt(intArray[i])\n inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override val size: Int get() = intArray.size\n inline val lastIndex get() = intArray.lastIndex\n\n override fun contains(element: ModInt): Boolean = any { it == element }\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override fun isEmpty(): Boolean = intArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): ModInt = get(index++)\n }\n}\nfun ModIntArray(capacity: Int) = ModIntArray(IntArray(capacity))\ninline fun ModIntArray(capacity: Int, init: (Int) -> ModInt) =\n ModIntArray(IntArray(capacity) { init(it).int })\n\n/** IO code start */\n@JvmField val _reader = System.`in`.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(System.out, false)\ninline fun output(block: PrintWriter.()->Unit) { _writer.apply(block).flush() }\nfun iprintln(o: Any?) { println(o) } // immediate println for interactive, bypasses output{} blocks"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.sqrt\n\n\nfun main() {\n val sc = Scanner.sysIn\n\n val x = sc.nextInt()\n val n = sc.nextLong()\n\n val primes = ArrayList()\n\n fun isPrime(k: Int): Boolean {\n if (k == 1) return false\n if (k == 2 || k == 3) return true\n for (i in 2..sqrt(k.toDouble()).toInt()) {\n if (k % i == 0) {\n return false\n }\n }\n return true\n\n }\n\n for (i in 2..sqrt(x.toDouble()).toInt()) {\n if (x % i == 0) {\n if (isPrime(i) && !primes.contains(x / i))\n primes += i\n if (isPrime(x / i) && !primes.contains(x / i))\n primes += x / i\n }\n }\n if (isPrime(x)) primes += x\n\n //primes.forEach { println(it) }\n\n val mod = 1000000007\n fun power(x: Long, p: Long): Long = when {\n p == 0L -> 1\n p == 1L -> x % mod\n p % 2 == 0L -> {\n val cur = power(x, p / 2)\n (cur * cur) % mod\n }\n else -> (power(x, p - 1) * x) % mod\n }\n\n var ans = 1L\n\n for (p in primes) {\n var curP = p.toLong()\n while (n / curP > 0) {\n //println(curP)\n ans = (ans * power(p.toLong(), n / curP)) % mod\n if ((curP * p) / p != curP) break\n curP *= p\n }\n }\n\n println(ans)\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n val br: BufferedReader = BufferedReader(InputStreamReader(s))\n\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextLine(): String {\n return br.readLine()\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n companion object {\n val sysIn = Scanner(System.`in`)\n }\n\n}\n\nval rnd = Random()\nfun IntArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}\n\nfun LongArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.HashSet\nimport kotlin.math.max\n\nfun readInts() = readLine()!!.split(\" \").map { it.toInt() }\nfun readLongs() = readLine()!!.split(\" \").map { it.toLong() }\nfun readInt() = readLine()!!.toInt()\nfun readLong() = readLine()!!.toLong()\nfun readLenAndInts() = readLine()!!.split(\" \").drop(1).map { it.toInt() }\n\nfun divisors(xx : Int) : List {\n var x = xx\n val res = mutableListOf()\n fun tryDiv(div : Int) {\n if (x % div == 0) {\n res.add(div)\n do {\n x /= div\n } while (x % div == 0)\n }\n }\n tryDiv(2)\n var div = 3\n while(div * div <= x) {\n tryDiv(div)\n div += 2\n }\n if (x != 1) {\n res.add(x)\n }\n return res\n}\n\nval mod = 1000000007L\nfun fastExp(a : Long, b : Long) : Long {\n //(a ^ b) % mod\n var res = 1L\n var x = a\n var e = b\n while(e > 0) {\n if (e % 2L == 1L) {\n res *= x\n res %= mod\n }\n x *= x\n x %= mod\n e /= 2\n }\n return res\n}\n\nfun main() {\n var (x,n) = readLongs()\n var res = 1L\n for(div in divisors(x.toInt())) {\n var times = 0L\n var nn = n\n while (nn > 0) {\n nn /= div\n times += nn\n }\n res *= fastExp(div.toLong(),times)\n res %= mod\n }\n println(res)\n}"}, {"source_code": "import kotlin.math.sqrt\n\nfun main() {\n val (x, n) = readLongs()\n val primes = primes(x.toInt())\n var result = 1L\n for (prime in primes) {\n var num = n\n var count = 0L\n while (num >= prime) {\n count += num / prime\n num /= prime\n }\n result = (result * pow(prime.toLong(), count)) % 1000000007\n }\n println(result)\n}\n\nfun primes(x: Int): IntArray {\n var num = x\n val result = mutableListOf()\n for (i in 2..sqrt(x.toDouble()).toInt()) {\n if (num % i == 0) {\n result.add(i)\n num /= i\n while (num % i == 0) {\n num /= i\n }\n }\n }\n if (num != 1) {\n result.add(num)\n }\n return result.toIntArray()\n}\n\nfun pow(x: Long, n: Long): Long {\n var num = x\n var count = n\n var result = 1L\n while (count > 0) {\n if (count and 1L == 1L) {\n result = (result * num) % 1000000007\n }\n num = (num * num) % 1000000007\n count = count shr 1\n }\n return result\n}\n\nprivate fun readString() = readLine()!!\n\nprivate fun readInt() = readString().toInt()\n\nprivate fun readInts() = readString().split(\" \").map { it.toInt() }\n\nprivate fun readLong() = readString().toLong()\n\nprivate fun readLongs() = readString().split(\" \").map { it.toLong() }\n"}], "negative_code": [{"source_code": "import java.util.*\nimport kotlin.math.sqrt\n\nconst val mod = 1000000007L\n\nfun main() {\n val s = Scanner(System.`in`)\n val x = s.nextLong()\n val n = s.nextLong()\n\n var ans = 1L\n val primes = getPrimes(x)\n primes.forEach {\n var itt = it\n var cnt = 0L\n while (true) {\n cnt += n / itt\n if (itt <= n / it) // 如果直接itt*=it再判断itt<=n会爆Long\n itt *= it\n else\n break\n }\n ans = ans * fpow(it, cnt) % mod\n }\n print(ans)\n}\n\nfun getPrimes(x: Long): Set {\n val primes = MutableList(0) { 0L }\n\n val sqrtx = sqrt(x.toDouble()).toLong()\n var xx = x\n var i = 2L\n while (xx in 2..sqrtx + 10) {\n if (xx % i == 0L)\n primes.add(i)\n while (xx % i == 0L)\n xx /= i\n i++\n }\n if (xx > 1)\n primes.add(xx)\n\n return primes.toSet()\n}\nfun fpow(x: Long, n: Long, m: Long = mod): Long {\n if (n == 0L)\n return 1\n var ans = 1L\n var xx = x % mod\n var nn = n\n while (nn > 1) {\n if (nn % 2 == 1L)\n ans = ans * xx % mod\n nn /= 2\n xx = xx * xx % mod\n }\n return ans * xx % mod\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.sqrt\n\n\nfun main() {\n val sc = Scanner.sysIn\n\n val x = sc.nextInt()\n val n = sc.nextLong()\n\n val primes = ArrayList()\n\n for (i in 2..sqrt(x.toDouble()).toInt() + 10) {\n if (x % i == 0) {\n var isPrime = true\n primes.forEach { if (i % it == 0) isPrime = false }\n if (isPrime)\n primes += i\n }\n }\n if (primes.isEmpty()) primes += x\n\n val mod = 1000000007\n fun power(x: Long, p: Long): Long = when {\n p == 0L -> 1\n p == 1L -> x % mod\n p % 2 == 0L -> {\n val cur = power(x, p / 2)\n (cur * cur) % mod\n }\n else -> (power(x, p - 1) * x) % mod\n }\n\n var ans = 1L\n\n for (p in primes) {\n //println(p)\n var num = 0L\n var curP = p.toLong()\n while (n / curP > 0) {\n //println(curP)\n num += n / curP\n if (curP * p / p != curP) break\n curP *= p\n }\n ans = ans * power(p.toLong(), num) % 1000000007\n }\n\n println(ans)\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n val br: BufferedReader = BufferedReader(InputStreamReader(s))\n\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextLine(): String {\n return br.readLine()\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n companion object {\n val sysIn = Scanner(System.`in`)\n }\n\n}\n\nval rnd = Random()\nfun IntArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}\n\nfun LongArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.sqrt\n\n\nfun main() {\n val sc = Scanner.sysIn\n\n val x = sc.nextInt()\n val n = sc.nextLong()\n\n val primes = ArrayList()\n\n for (i in 2..sqrt(x.toDouble()).toInt() + 1) {\n if (x % i == 0) {\n var isPrime = true\n primes.forEach { if (i % it == 0) isPrime = false }\n if (isPrime)\n primes += i\n }\n }\n if (primes.isEmpty()) primes += x\n\n //primes.forEach { println(it) }\n\n val mod = 1000000007\n fun power(x: Long, p: Long): Long = when {\n p == 0L -> 1\n p == 1L -> x % mod\n p % 2 == 0L -> {\n val cur = power(x, p / 2)\n (cur * cur) % mod\n }\n else -> (power(x, p - 1) * x) % mod\n }\n\n var ans = 1L\n\n for (p in primes) {\n var curP = p.toLong()\n while (n / curP > 0) {\n ans = (ans * power(p.toLong(), n / curP)) % mod\n if ((curP * p) / p != curP) break\n curP *= p\n }\n }\n\n println(ans)\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n val br: BufferedReader = BufferedReader(InputStreamReader(s))\n\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextLine(): String {\n return br.readLine()\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n companion object {\n val sysIn = Scanner(System.`in`)\n }\n\n}\n\nval rnd = Random()\nfun IntArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}\n\nfun LongArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.sqrt\n\n\nfun main() {\n val sc = Scanner.sysIn\n\n val x = sc.nextInt()\n val n = sc.nextLong()\n\n val primes = ArrayList()\n\n for (i in 2..sqrt(x.toDouble()).toInt() + 10) {\n if (x % i == 0) {\n var isPrime = true\n primes.forEach { if (i % it == 0) isPrime = false }\n if (isPrime)\n primes += i\n }\n }\n if (primes.isEmpty()) primes += x\n\n val mod = 1000000007\n fun power(x: Long, p: Long): Long = when {\n p == 0L -> 1\n p == 1L -> x % mod\n p % 2 == 0L -> {\n val cur = power(x, p / 2)\n (cur * cur) % mod\n }\n else -> (power(x, p - 1) * x) % mod\n }\n\n var ans = 1L\n\n for (p in primes) {\n //println(p)\n var num = 0L\n var curP = p.toLong()\n while (n / curP > 0) {\n println(curP)\n num += n / curP\n if (curP * p / p != curP) break\n curP *= p\n }\n ans = ans * power(p.toLong(), num) % 1000000007\n }\n\n println(ans)\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n val br: BufferedReader = BufferedReader(InputStreamReader(s))\n\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextLine(): String {\n return br.readLine()\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n companion object {\n val sysIn = Scanner(System.`in`)\n }\n\n}\n\nval rnd = Random()\nfun IntArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}\n\nfun LongArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.sqrt\n\n\nfun main() {\n val sc = Scanner.sysIn\n\n val x = sc.nextInt()\n val n = sc.nextLong()\n\n val primes = ArrayList()\n\n fun isPrime(k: Int): Boolean {\n if (k == 1) return false\n if (k == 2 || k == 3) return true\n for (i in 2..sqrt(k.toDouble()).toInt() + 1) {\n if (k % i == 0) {\n return false\n }\n }\n return true\n\n }\n\n for (i in 2..sqrt(x.toDouble()).toInt() + 1) {\n if (x % i == 0) {\n if (isPrime(i))\n primes += i\n if (isPrime(x / i))\n primes += x / i\n }\n }\n //if (isPrime(x)) primes += x\n\n primes.forEach { println(it) }\n\n val mod = 1000000007\n fun power(x: Long, p: Long): Long = when {\n p == 0L -> 1\n p == 1L -> x % mod\n p % 2 == 0L -> {\n val cur = power(x, p / 2)\n (cur * cur) % mod\n }\n else -> (power(x, p - 1) * x) % mod\n }\n\n var ans = 1L\n\n for (p in primes) {\n var curP = p.toLong()\n while (n / curP > 0) {\n //println(curP)\n ans = (ans * power(p.toLong(), n / curP)) % mod\n if ((curP * p) / p != curP) break\n curP *= p\n }\n }\n\n println(ans)\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n val br: BufferedReader = BufferedReader(InputStreamReader(s))\n\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextLine(): String {\n return br.readLine()\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n companion object {\n val sysIn = Scanner(System.`in`)\n }\n\n}\n\nval rnd = Random()\nfun IntArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}\n\nfun LongArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.sqrt\n\n\nfun main() {\n val sc = Scanner.sysIn\n\n val x = sc.nextInt()\n val n = sc.nextLong()\n\n val primes = ArrayList()\n\n fun isPrime(k: Int): Boolean {\n if (k == 1) return false\n if (k == 2 || k == 3) return true\n for (i in 2..sqrt(k.toDouble()).toInt() + 1) {\n if (k % i == 0) {\n return false\n }\n }\n return true\n\n }\n\n for (i in 2..sqrt(x.toDouble()).toInt() + 1) {\n if (x % i == 0) {\n if (isPrime(i))\n primes += i\n if (isPrime(x / i))\n primes += x / i\n }\n }\n if (isPrime(x)) primes += x\n\n //primes.forEach { println(it) }\n\n val mod = 1000000007\n fun power(x: Long, p: Long): Long = when {\n p == 0L -> 1\n p == 1L -> x % mod\n p % 2 == 0L -> {\n val cur = power(x, p / 2)\n (cur * cur) % mod\n }\n else -> (power(x, p - 1) * x) % mod\n }\n\n var ans = 1L\n\n for (p in primes) {\n var curP = p.toLong()\n while (n / curP > 0) {\n //println(curP)\n ans = (ans * power(p.toLong(), n / curP)) % mod\n if ((curP * p) / p != curP) break\n curP *= p\n }\n }\n\n println(ans)\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n val br: BufferedReader = BufferedReader(InputStreamReader(s))\n\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextLine(): String {\n return br.readLine()\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n companion object {\n val sysIn = Scanner(System.`in`)\n }\n\n}\n\nval rnd = Random()\nfun IntArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}\n\nfun LongArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.sqrt\n\n\nfun main() {\n val sc = Scanner.sysIn\n\n val x = sc.nextInt()\n val n = sc.nextLong()\n\n val primes = ArrayList()\n\n for (i in 2..sqrt(x.toDouble()).toInt() + 10) {\n if (x % i == 0) {\n var isPrime = true\n primes.forEach { if (i % it == 0) isPrime = false }\n if (isPrime)\n primes += i\n }\n }\n if (primes.isEmpty()) primes += x\n\n val mod = 1000000007\n fun power(x: Long, p: Long): Long = when {\n p == 0L -> 1\n p == 1L -> x % mod\n p % 2 == 0L -> {\n val cur = power(x, p / 2)\n (cur * cur) % mod\n }\n else -> (power(x, p - 1) * x) % mod\n }\n\n var ans = 1L\n\n for (p in primes) {\n //println(p)\n var curP = p.toLong()\n while (n / curP > 0) {\n //println(curP)\n ans = ans * power(p.toLong(), n / curP) % 1000000007\n if (curP * p / p != curP) break\n curP *= p\n }\n }\n\n println(ans)\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n val br: BufferedReader = BufferedReader(InputStreamReader(s))\n\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextLine(): String {\n return br.readLine()\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n companion object {\n val sysIn = Scanner(System.`in`)\n }\n\n}\n\nval rnd = Random()\nfun IntArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}\n\nfun LongArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}"}], "src_uid": "04610fbaa746c083dda30e21fa6e1a0c"} {"nl": {"description": "A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.", "input_spec": "The first line contains a single integer n (1 ≤ n ≤ 100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.", "output_spec": "Output \"YES\", if the string is a pangram and \"NO\" otherwise.", "sample_inputs": ["12\ntoosmallword", "35\nTheQuickBrownFoxJumpsOverTheLazyDog"], "sample_outputs": ["NO", "YES"], "notes": null}, "positive_code": [{"source_code": "fun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\n\nfun main(args: Array) {\n val n = readInt()\n val s = readLn()\n\n for (ch in 'a'..'z') {\n if (!s.contains(ch) && !s.contains(ch.toUpperCase())) {\n println(\"NO\")\n return\n }\n }\n\n println(\"YES\")\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n var tok = StringTokenizer(\"\")\n\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n fun files(inputFilename: String, outputFilename: String) =\n ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))\n }\n\n fun readToken(): String {\n while (!tok.hasMoreTokens()) {\n tok = StringTokenizer(rd.readLine())\n }\n return tok.nextToken()\n }\n\n fun readInt(): Int = readToken().toInt()\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun close() {\n rd.close()\n wr.close()\n }\n}\n\nfun solve() {\n val io = ProblemIO.console()\n val n = io.readInt()\n val t = io.readToken()\n val res = (t.toLowerCase().toSet().size == 26)\n io.println(if (res) \"YES\" else \"NO \")\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n"}, {"source_code": "fun main()\n{\n val lens = readLine()!!.toInt()\n val given = readLine()!!\n var c = 'A'\n var answer = \"YES\"\n while (c <= 'Z')\n {\n if (given.contains(c))\n {\n ++c\n continue\n }\n else if (given.contains(c.toLowerCase()))\n {\n ++c\n continue\n }\n else\n {\n answer = \"NO\"\n break\n }\n }\n println(answer)\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!\n val diff = r.readLine()!!.toLowerCase().split(\"\").groupBy { it }.size\n println(if (diff==27) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n var s = readLine()!!\n var c = 0\n s = s.toUpperCase()\n for (i in 'A'..'Z'){\n if (s.contains(i)){\n c++\n }\n }\n if (c >= 26){\n print(\"YES\")\n }\n else\n print(\"NO\")\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n val q = scanner.nextInt()\n var line = scanner.next().toLowerCase()\n\n var set = mutableSetOf()\n\n (0 until q).forEach { set.add(line[it]) }\n\n if (set.size == 26) println(\"YES\")\n else println(\"NO\")\n\n}"}, {"source_code": "import java.util.Scanner;\nimport java.util.Arrays;\nimport java.util.*; \nimport java.math.*;\nimport java.io.*;\n\nfun main(args: Array) {\nvar s = Scanner(System.`in`)\nvar numberofletters = s.nextInt()\nvar sentence = s.next()\nvar res = sentence.toLowerCase();\nvar charSentence = res.toCharArray()\nArrays.sort(charSentence)\nvar pangram = 0 \nvar start = 97\nfor(i in 0 until numberofletters){\nval charSentenceAsInt = charSentence[i].toInt()\nif(charSentenceAsInt==start){\npangram++\nstart++\n}\n}\nif(pangram == 26){\nprint(\"YES\")\n}else{\nprint(\"NO\")\n}\n\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.math.max\n\nfun main() {\n val scan = Scanner(System.`in`)\n val size = scan.nextInt()\n val list:Iterable = scan.next().asIterable()\n pangram(list)\n}\n\n// http://codeforces.com/contest/520/problem/A\nfun pangram(list: Iterable) {\n val set = mutableSetOf()\n for (c in list) {\n set.add(c.toLowerCase())\n }\n val result = if (set.size == 26) \"YES\" else \"NO\"\n println(result)\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val input = InputReader(inputStream)\n val output = PrintWriter(outputStream)\n val solver = Task()\n solver.solve(input, output)\n output.close()\n}\n\nprivate class Task {\n fun solve(input: InputReader, output: PrintWriter) {\n input.nextInt()\n\n ('a'..'z').toSet().let { set ->\n val s = input.next().toLowerCase()\n output.println(if (set.all { s.contains(it) }) \"YES\" else \"NO\")\n }\n }\n}\n\n\nprivate class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n\n operator fun next(): String {\n while (tokenizer == null || tokenizer?.hasMoreTokens()?.not() == true) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return next().toInt()\n }\n\n}"}, {"source_code": "\nfun main(){\n readLine()\n var set = readLine()!!.toString().toLowerCase().toCharArray().toSet()\n println( if(set.size == 26) \"YES\\n\" else \"NO\")\n}\n"}, {"source_code": "fun main(args: Array) {\n val n = readInt()\n val s = readLine()!!.toLowerCase().toCharArray().toSet().size\n println(if (s == 26) \"YES\" else \"NO\")\n}\n\nprivate fun readInt() = readLine()!!.toInt()"}, {"source_code": "import java.util.*\nfun main(args: Array) {\n var sc = Scanner(System.`in`)\n val n = sc.nextInt()\n val s = sc.next().toLowerCase()\n if (n < 26) println(\"NO\")\n else {\n var count = IntArray(26)\n for ( i in 0 .. n-1){\n count[s[i].toInt()- 'a'.toInt()]++\n }\n var test = true\n for (i in 0 .. 25){\n if (count[i] == 0 ){\n test= false\n break\n }\n }\n println(if (test) \"YES\" else \"NO\")\n }\n}"}, {"source_code": " fun main(args: Array) {\n readLine()\n var s=readLine()!!.toLowerCase().toSet()\n if(s.size==26)\n print(\"YES\")\n else\n print(\"NO\")\n\n \n \n }"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val alphabet = ('a'..'z').toList().toCharArray()\n\n val sc = Scanner(System.`in`)\n sc.nextLine()\n val line = sc.nextLine()\n\n println(if(pangram(line, alphabet)) \"YES\" else \"NO\")\n}\n\nfun pangram(line: String, alphabet: CharArray): Boolean {\n if (line.length < alphabet.size) {\n return false\n }\n\n val lowercase = line.toLowerCase()\n return alphabet.filter { it !in lowercase }.isEmpty()\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val n = br.readLine().toInt()\n val s = br.readLine().toLowerCase()\n println(\n if (s.toSet().size == 26) \"YES\" else \"NO\"\n )\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n if(n < 26) {\n println(\"NO\")\n } else {\n val word = readLine()!!.toLowerCase().toSortedSet()\n if(word.size >= 26) println(\"YES\")\n else println(\"NO\")\n }\n}"}, {"source_code": "fun main(args: Array) {\n val length = Integer.parseInt(readLine().toString())\n val sentence = readLine().toString().toLowerCase()\n if(isPangram(length,sentence)){\n println(\"YES\")\n }\n else{\n println(\"NO\")\n }\n}\nfun isPangram(inter:Int,input:String):Boolean {\n for (a in 'a'..'z'){\n val isChar: (Char) -> Boolean = {it == a}\n if(!input.any(predicate = isChar )) {\n return false }\n }\n return true\n }"}, {"source_code": "fun main(args: Array) {\n readLine()\n val s = readLine()!!.toLowerCase()\n println(if (('a'..'z').all { s.contains(it) }) \"YES\" else \"NO\")\n}"}, {"source_code": "import java.util.*\n\nfun main(){\n\n val scan = Scanner(System.`in`)\n\n val n = scan.nextInt()\n val arr = Array(26){ _ -> false}\n var c = 0\n val line = scan.next().toUpperCase()\n\n if (n<26){\n print(\"NO\")\n return\n }\n for (i in line){\n val tmp = i.toInt()\n arr[tmp-65] = true\n }\n\n for (i in arr) if (i) c++\n\n if (c == 26) print(\"YES\")\n else print(\"NO\")\n}"}, {"source_code": "fun main() {\n readLine()!!\n if (readLine()!!.asSequence().map { it.toLowerCase() }.toSet().size == 26)\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "import java.lang.AssertionError\nimport java.util.*\n \nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n \nprivate fun myAssert(x: Boolean) {\n if (!x) {\n throw AssertionError()\n }\n}\n\nfun main(args: Array) {\n// var s = Scanner(System.`in`)\n var n = readInt()\n var s = readLn().toLowerCase()\n var ss = mutableSetOf()\n for (i in 0..n - 1) {\n ss.add(s[i])\n }\n if (ss.size < 26) {\n println(\"NO\")\n } else {\n println(\"YES\")\n }\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.HashMap\n\n//author:Ismail moussi\nfun main()\n{\n val scan=Scanner(System.`in`)\n val n:Int=scan.nextInt()\n var s:String=scan.next()\n var map=HashMap()\n if(s.length<26)\n print(\"NO\")\n else {\n\n var ss= s.toUpperCase()\n for (i in 0 until s.length) {\n map.put(ss.get(i), 0)\n }\n// if(map.size<26)\n// println(\"NO\")else println(\"YES\")\n when(map.size)\n {\n in 1..25-> print(\"NO\")\n else -> print(\"YES\")\n }\n }\n}\n\n\n\n\n\n"}, {"source_code": "fun main() {\n readLine()\n val s = readLine()!!\n val chars = mutableSetOf()\n for (c in s) chars.add(c.toLowerCase())\n print(if (chars.size == 26) \"YES\" else \"NO\")\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.*\nimport kotlin.system.measureTimeMillis\n\nfun getMinimumAmountOfChangeFrom(amount: Int): Int {\n val changes = listOf(10, 5, 1)\n var availableAmount = amount\n var numOfCoins = 0\n for (change in changes) {\n while (availableAmount > 0 && availableAmount / change.toDouble() >= 1) {\n numOfCoins += 1\n availableAmount -= change\n }\n }\n return numOfCoins\n}\n\nfun getMaximumValueOfTheLootWith(\n W: Int,\n valuePerUnitAndWeight: List>\n): Double {\n var maximumLootValue = 0.0\n var availableWeight = W\n for (pair in valuePerUnitAndWeight) {\n var availableWeightOfLootItem = pair.second\n while (availableWeight > 0 && availableWeightOfLootItem > 0) {\n maximumLootValue += pair.first\n availableWeightOfLootItem -= 1\n availableWeight -= 1\n }\n }\n return maximumLootValue\n}\n\nfun getMinimumNumOfRefills(d: Int, m: Int, stops: List): Int {\n var availableDistance = d\n var minimumRefills = 0\n var currentRefill = 0\n var lastRefill = 0\n val realStops = listOf(0, *stops.toTypedArray(), d)\n while (availableDistance > 0 && currentRefill < realStops.size) {\n var movedForward = false\n while (currentRefill < realStops.size && (realStops[currentRefill] - realStops[lastRefill]) <= m) {\n if (realStops[currentRefill] - realStops[lastRefill] == 0) {\n movedForward = false\n currentRefill++\n } else {\n movedForward = true\n currentRefill++\n }\n }\n if (movedForward) {\n minimumRefills++\n currentRefill--\n availableDistance -= (realStops[currentRefill] - realStops[lastRefill])\n lastRefill = currentRefill\n } else {\n return -1\n }\n }\n return minimumRefills - 1\n}\n\nfun getMaximizedSumOfProduct(profitPerClick: List, averageNumberOfClicks: List): Long {\n var sum = 0L\n println(profitPerClick.toString())\n println(averageNumberOfClicks.toString())\n profitPerClick.forEachIndexed { index, profit ->\n sum += profit * averageNumberOfClicks[index]\n }\n return sum\n}\n\nfun getCommon(first: Int, last: Int, segments: MutableList>): String {\n var current = first\n val common = mutableListOf>()\n while (current <= last) {\n var numOfTimes = 0\n for (pair in segments) {\n if (current in pair.first..pair.second) {\n numOfTimes++\n }\n }\n if (numOfTimes > 1) {\n common.add(Pair(current, numOfTimes))\n }\n current++\n }\n common.sortByDescending { it -> it.second }\n if (common.first().second == segments.size) {\n return \"1\\n${common.first().first}\"\n }\n println(common)\n return \"${common.size}\\n${common.map { it.first }.joinToString(\" \")}\"\n}\n\nfun getMaximumSetOfPrizes(n: Int): String {\n var numbersOfN = \"\"\n var sumSoFar = 0\n if (n <= 2) {\n return \"1\\n$n\"\n }\n// println(\"2*square root of n = ${2 * sqrt(n.toDouble())}\")\n// for (i in 1..(2 * sqrt(n.toDouble()).toInt())){\n// if (i+sumSoFar<=n){\n// numbersOfN+=\"$i \"\n// sumSoFar+=i\n// }\n// }\n// var lastNumber = 1\n var currentNumber = 1\n while (((currentNumber + 1) + currentNumber) <= n - sumSoFar) {\n sumSoFar += currentNumber\n numbersOfN += \"$currentNumber \"\n currentNumber++\n }\n if (((n - currentNumber) + sumSoFar) == n || n - sumSoFar > 0) {\n currentNumber = n - sumSoFar\n sumSoFar += currentNumber\n numbersOfN += \"$currentNumber \"\n }\n// else if (n-sumSoFar>0){\n// currentNumber = n-sumSoFar\n// numbersOfN += \"$currentNumber \"\n// }\n return \"${numbersOfN.trim().split(\" \").size}\\n$numbersOfN\"\n}\n\n\nfun linelandMail(coordinates: List): String {\n val mins = mutableListOf()\n val maxs = mutableListOf()\n for (i in coordinates.indices) {\n if (i == 0) {\n mins.add(abs(coordinates[i] - coordinates[i + 1]))\n maxs.add(abs(coordinates[i] - coordinates[coordinates.size - 1]))\n } else if (i == coordinates.size - 1) {\n mins.add(abs(coordinates[i] - coordinates[i - 1]))\n maxs.add(abs(coordinates[i] - coordinates[0]))\n } else {\n if (abs(coordinates[i] - coordinates[i - 1])\n > abs(coordinates[i] - coordinates[i + 1])\n )\n mins.add(abs(coordinates[i] - coordinates[i + 1]))\n else\n mins.add(abs(coordinates[i] - coordinates[i - 1]))\n\n if (abs(coordinates[i] - coordinates[0])\n < abs(coordinates[i] - coordinates[coordinates.size - 1])\n )\n maxs.add(abs(coordinates[i] - coordinates[coordinates.size - 1]))\n else\n maxs.add(abs(coordinates[i] - coordinates[0]))\n }\n }\n return mins\n .zip(maxs)\n .map { pair -> \"${pair.first} ${pair.second}\" }\n .joinToString(\"\\n\")\n}\n\nfun snacktower(snacksWeights: List) {\n val n = snacksWeights.size\n var currentMax = n\n var current = 0\n var processed = mutableListOf()\n while (current < snacksWeights.size) {\n if (snacksWeights[current] < currentMax) {\n processed.add(snacksWeights[current])\n print(\"\\n\")\n current++\n } else {\n if (snacksWeights[current] == currentMax) {\n print(currentMax)\n currentMax--\n var currentProcessed = 0\n while (currentProcessed < processed.size) {\n var foundConsecutive = false\n if (processed[currentProcessed] == currentMax) {\n print(\" \")\n print(processed[currentProcessed])\n currentMax--\n foundConsecutive = true\n processed = processed.swap(currentProcessed, processed.size - 1).toMutableList()\n processed.removeAt(processed.size - 1)\n }\n if (!foundConsecutive) {\n currentProcessed++\n } else {\n currentProcessed = 0\n }\n }\n println()\n current++\n }\n }\n }\n}\n\nfun List.swap(a: Int, b: Int): List = this\n .toMutableList()\n .also {\n it[a] = this[b]\n it[b] = this[a]\n }\n\nfun `Oath of the Night's Watch`(stewardsStrengths: List) {\n val sortedStrengths = stewardsStrengths.sorted()\n var numberOfThoseWhoNeedSupport = 0\n for (strengthIndex in sortedStrengths.indices) {\n val precedingSteward = strengthIndex - 1\n val nextSteward = strengthIndex + 1\n if (precedingSteward>=0 && nextStewardsortedStrengths[strengthIndex]){\n numberOfThoseWhoNeedSupport++\n }\n }\n }\n println(numberOfThoseWhoNeedSupport)\n}\n\nfun pangram(characters: String){\n print(if (characters.toLowerCase().toSet().size==26) \"YES\" else \"NO\")\n}\n\nfun main() {\n\n// val scanner = Scanner(System.`in`)\n// val n = scanner.nextInt()\n// val snacksWeights = MutableList(n) { index -> 0 }\n// for (i in 0 until n) {\n// snacksWeights[i] = scanner.nextInt()\n// }\n// snacktower(snacksWeights)\n// val scanner = Scanner(System.`in`)\n// val n = scanner.nextInt()\n// val strengths = MutableList(n) { index -> 0 }\n// for (i in 0 until n) {\n// strengths[i] = scanner.nextInt()\n// }\n// `Oath of the Night's Watch`(strengths)\n val n = readLine()!!.toInt()\n val characters = readLine()!!\n pangram(characters)\n}\n\n\n// start of stress test\n// while (true) {\n// val n = Random.nextLong(1000000)\n// val m = Random.nextLong(100000)\n// if (m) {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n val arr = Array(26, {i -> 0})\n for (c in s) {\n if ('a' <= c && c <= 'z') {\n arr[c-'a'] = 1\n } else if ('A' <= c && c <= 'Z') {\n arr[c-'A'] = 1\n }\n }\n if (arr.all{it == 1})\n print(\"YES\\n\")\n else\n print(\"NO\\n\")\n}\n"}, {"source_code": "fun main(args: Array) {\n readLine()\n println(if (readLine()!!.toLowerCase().toSet().size >= 26) \"YES\" else \"NO\")\n}"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n\nval charRange = 'a'..'z'\n\nfun main() {\n readLn()\n val sentence = readLn()\n\n if(sentence.map { it.toLowerCase() }.containsAll(charRange.toList())) println(\"YES\") else println(\"NO\")\n}\n"}, {"source_code": "\nfun main(args: Array) {\n readLine() !!\n val count = readLine()!!.toLowerCase().toSet().size\n println(if (count == 26) \"YES\" else \"NO\")\n}"}, {"source_code": "import java.util.*\n\nfun min(a:Double,b:Double) = if (ab) a else b\nfun min(a:Long,b:Long) = if (ab) a else b\n\nfun readLn():String = readLine()!!.toString()\nfun readLong() = readLn().toLong()\nfun readLongs() = readLn().split(\" \").map{it.toLong()}\nvar nul=0.toLong();\nvar one=1.toLong();\nvar two=2.toLong();\nvar three=3.toLong();\nvar four=4.toLong();\nvar five=5.toLong();\nfun powmod(a:Long,b:Long,mod:Long):Long {\n\n if (b==1.toLong()) return a;\n var k=powmod(a,b/2,mod);\n if (b%2==0.toLong())\n { return (k*k)%mod }\n else { k=k*k; k=k%mod; k=k*a; k=k%mod; return k; }\n}\nfun prime (p:Long):Long {\n if (p==one) return 0.toLong();\n var i=two;\n while (i*i<=p) {if (p%i==nul) return i; i++; }\n return one;\n}\nfun inv (a:Long,mod:Long):Long {\nreturn powmod(a,mod-2,mod);\n}\n\nfun solve() {\n val cin = Scanner(System.`in`)\n\n /*\n var map=hashMapOf();\n map[q] <=> map.getOrDefault(q,0)\n Сортировка вектора пар - k=v.sortedWith(compareBy({it.first},{it.second}));\n prLong(\"${k[i].second}\"); - вывод аргумента пары\n var m=ArrayList (); <=> vector\n getline(cin,a) <=> readLine()!!.last()\n readLong() - одно число\n readLongs() - несколько чисел\n readLine()!!.toCharArray() - возвращает массив чаров из строки\n\n */\n /* --------- */\n // ВСЕГДА ПИСАТЬ В ЛОНГАХ\n var a=readLong();\n var s=readLine()!!;\n\n var mem=mutableSetOf();\n for (c in s) {var pog=c; if (c>='A' && c<='Z') { var code=pog.toInt(); code-='A'.toInt(); code+='a'.toInt(); pog=code.toChar(); }\n mem.add(pog); }\n if (mem.size>=26) print(\"YES\"); else print(\"NO\");\n\n /* --------- */\n\n}\n\nfun main() {\n val cin = Scanner(System.`in`)\n\n var T=one;\n //T=readLine()!!.toLong();\n for (i55555 in 1..T) solve()\n}\n"}, {"source_code": "fun main(args: Array) {\n \n var n = readLine()!!.toInt()\n var str = readLine()!!.toLowerCase()\n var ok = 0\n for(i in 'a'..'z')if(str.contains(i)) ok++\n if(ok == 26)print(\"YES\")\n else print(\"NO\")\n}"}], "negative_code": [{"source_code": " fun main(args: Array) {\n\n var s=readLine()!!.toLowerCase().toSet()\n if(s.size==26)\n print(\"YES\")\n else\n print(\"NO\")\n \n }"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\n//author:Ismail moussi\nfun main()\n{\n val scan=Scanner(System.`in`)\n val n:Int=scan.nextInt()\n var s:String=scan.next()\n var map=HashMap()\n if(s.length<26)\n {\n print(\"NO\")\n return\n }\n else\n {\n s.toLowerCase()\n for(i in 0 until s.length)\n {\n map.put(s.get(i),0)\n }\n }\n if(map.size<26)\n print(\"NO\")else\n print(\"YES\")\n}\n\n\n\n\n\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\n//author:Ismail moussi\nfun main()\n{\n val scan=Scanner(System.`in`)\n val n:Int=scan.nextInt()\n var s:String=scan.next()\n var map=HashMap()\n if(s.length<26)\n {\n print(\"NO\")\n return\n }\n else\n {\n s.toLowerCase()\n for(i in 0 until s.length)\n {\n map.put(s.get(i),0)\n }\n }\n if(map.size==26)\n print(\"YES\")else\n print(\"NO\")\n}\n\n\n\n\n\n"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\n//author:Ismail moussi\nfun main()\n{\n val scan=Scanner(System.`in`)\n val n:Int=scan.nextInt()\n var s:String=scan.next()\n var map=HashMap()\n if(s.length<26)\n print(\"NO\")\n else {\n s.toLowerCase()\n for (i in 0 until s.length) {\n map.put(s.get(i), 0)\n }\n\n when(map.size)\n {\n in 0..25-> print(\"NO\")\n else -> print(\"YES\")\n }\n\n// if (map.size == 26)\n// print(\"YES\") else\n// print(\"NO\")\n }\n}\n\n\n\n\n\n"}], "src_uid": "f13eba0a0fb86e20495d218fc4ad532d"} {"nl": {"description": "Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.Solve the problem to show that it's not a NP problem.", "input_spec": "The first line contains two integers l and r (2 ≤ l ≤ r ≤ 109).", "output_spec": "Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them.", "sample_inputs": ["19 29", "3 6"], "sample_outputs": ["2", "3"], "notes": "NoteDefinition of a divisor: https://www.mathsisfun.com/definitions/divisor-of-an-integer-.htmlThe first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}."}, "positive_code": [{"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!\n val (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n if (n==m) println(n)\n else println(2)\n}"}, {"source_code": "import java.util.*\n\n/**\n * Created by Igor on 7/17/2017.\n */\n\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val l = scanner.nextInt()\n val r = scanner.nextInt()\n\n if (l == r)\n println(l)\n else\n println(2)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array){\n var sc = Scanner(System.`in`)\n var l = sc.nextInt()\n var r = sc.nextInt()\n println(if(l == r) l else 2)\n}\n"}, {"source_code": "fun main(args: Array) {\n\tval (l,r) = readLine()!!.split(' ').map(String::toInt)\t\n\tval res = if ( r==l) l else 2;\n\tprintln(res)\n\t\n}\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n val left = reader.nextInt()\n val right = reader.nextInt()\n if (left == right && right % 3 == 0) println(3)\n else if (left == right && right % 2 != 0) println(right)\n else println(2)\n\n}\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n var(l, r) = readLine()!!.split(\" \").map(String::toInt)\n if (l == r) {\n println(l)\n } else {\n println(2)\n }\n}"}, {"source_code": "import kotlin.math.abs\n\nfun main() {\n var (l, r) = readLine()!!.split(' ').map { it.toInt() }\n if (abs(l-r)==0){\n println(l)\n }else{\n println(2)\n }\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (l, r) = readInts()\n print(if (l == r) l else 2)\n}\n\n//fun main() {\n// fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n//\n// val (l, r) = readLongs()\n// val divisorToTimes = mutableMapOf()\n// val composites = mutableSetOf()\n// for (candidate in 2L..r) {\n// if (candidate in composites) continue\n// divisorToTimes[candidate] = if (candidate in l..r) 1 else 0\n// for (number in candidate + candidate..r step candidate) {\n// if (number in l..r)\n// divisorToTimes[candidate] = divisorToTimes[candidate]!! + 1\n// composites.add(number)\n// }\n// }\n// print(divisorToTimes.maxBy { it.value }!!.key)\n//}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(args: Array) {\n val tokenizer = BufferedReader(InputStreamReader(System.`in`)).use { StringTokenizer(it.readText()) }\n val l = tokenizer.nextInt()\n val r = tokenizer.nextInt()\n if (l == r)\n println(l)\n else\n println(2)\n}\n\nfun StringTokenizer.nextInt() = Integer.parseInt(nextToken())\n\n"}, {"source_code": "fun main(args: Array) {\n val (l, r) = readLine()!!.split(' ').map(String::toInt)\n if (l == r)\n print(\"$l\\n\")\n else\n print(\"2\\n\")\n}\n"}, {"source_code": "fun main(args : Array)\n{\n var line: String = inputNotNull()\n var l: Long = line.split(\" \")[0].toLong()\n var r: Long = line.split(\" \")[1].toLong()\n var arr: Array = Array(Math.sqrt(r.toDouble()).toInt(),{i -> 0})\n\n if(r == 2L||r==4L){\n println(2)\n return\n }else if(r==3L){\n println(3)\n return\n }else if(l==r){\n println(l)\n return\n }\n\n println(2)\n\n}\n\nfun inputNotNull(): String\n{\n val line: String? = readLine()\n if (line == null) return \"\"\n return line.trim()\n}"}], "negative_code": [{"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!\n //val (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n println(2)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n val left = reader.nextInt()\n val right = reader.nextInt()\n if (left == right && right % 3 == 0) println(3)\n else println(2)\n\n}\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n var(l, r) = readLine()!!.split(\" \").map(String::toInt)\n println(2)\n}"}], "src_uid": "a8d992ab26a528f0be327c93fb499c15"} {"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": "import kotlin.math.max\n\nfun main() {\n val (numCitizens, numWizards, percentage) = readLine()!!.split(\" \").map(String::toInt)\n val total = numCitizens * percentage / 100 + if ((numCitizens * percentage) % 100 == 0) 0 else 1\n print(max(0, total - numWizards))\n}"}], "negative_code": [{"source_code": "fun main() {\n val (numCitizens, numWizards, percentage) = readLine()!!.split(\" \").map(String::toInt)\n val total = numCitizens * percentage / 100 + if ((numCitizens * percentage) % 100 == 0) 0 else 1\n print(total - numWizards)\n}"}], "src_uid": "7038d7b31e1900588da8b61b325e4299"} {"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": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.lang.AssertionError\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007L\n\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val MAX = if (isDebug) 100 else 100_000\n val flg = BooleanArray(MAX + 1){true}\n val primes = mutableListOf()\n flg[0] = false\n flg[1] = false\n\n for (i in 2 .. MAX) {\n if (!flg[i]) continue\n primes += i\n\n var j = i * 2\n while (j <= MAX) {\n flg[j] = false\n j += i\n }\n }\n\n fun isPrime(a: Int): Boolean {\n for (p in primes) {\n if (a <= p) return true\n if (a % p == 0) return false\n }\n return true\n }\n\n val N = ni()\n if (isPrime(N)) {\n out.println(1)\n out.println(\"$N\")\n return\n }\n\n var Pn = N - 2\n while(!isPrime(Pn)) {\n Pn--\n }\n\n val x = N - Pn\n if (isPrime(x)) {\n out.println(2)\n out.println(\"$Pn $x\")\n return\n }\n\n for (p in primes) {\n if (flg[x - p]) {\n out.println(3)\n out.println(\"$Pn $p ${x - p}\")\n return\n }\n }\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl() + offset\n }\n return res\n }\n\n private fun na2(n: Int, offset: Int = 0): Array {\n val a = Array(2){IntArray(n)}\n for (i in 0 until n) {\n for (e in a) {\n e[i] = ni() + offset\n }\n }\n return a\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private inline fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private inline fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private inline fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n\n private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()}\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}"}], "negative_code": [], "src_uid": "f2aaa149ce81bf332d0b5d80b2a13bc3"} {"nl": {"description": "Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange. Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!", "input_spec": "The first line of input contains an integer n (1 ≤ n ≤ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 ≤ ai ≤ 100) denotes the number of cubes in the i-th column.", "output_spec": "Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.", "sample_inputs": ["4\n3 2 1 2", "3\n2 3 8"], "sample_outputs": ["1 2 2 3", "2 3 8"], "notes": "NoteThe first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.In the second example case the gravity switch does not change the heights of the columns."}, "positive_code": [{"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n readLine()!!.split(\" \").map { it.toInt() }.sorted().forEach({ print(\"${it} \") })\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n var tok = StringTokenizer(\"\")\n\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n fun files(inputFilename: String, outputFilename: String) =\n ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))\n }\n\n fun readToken(): String {\n while (!tok.hasMoreTokens()) {\n tok = StringTokenizer(rd.readLine())\n }\n return tok.nextToken()\n }\n\n fun readInt(): Int = readToken().toInt()\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun close() {\n rd.close()\n wr.close()\n }\n}\n\nfun solve() {\n val io = ProblemIO.console()\n val n = io.readInt()\n val a = IntArray(n)\n for (i in a.indices) {\n a[i] = io.readInt()\n }\n a.sort()\n io.println(a.joinToString(\" \"))\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n"}, {"source_code": "fun main()\n{\n val ignore = readLine()!!.toInt()\n println(readLine()!!.split(\" \").map { it.toInt() }.sorted().joinToString(\" \"))\n\n}\n"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!.toInt()\n val l = r.readLine()!!.split(\" \").map { it.toInt() }.sorted()\n println(l.joinToString(\" \"))\n}"}, {"source_code": "fun main() {\n readLine()!!\n val cubes = readLine()!!.split(\" \").map(String::toInt)\n println(cubes.sorted().joinToString(separator = \" \").trim())\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n\n var max = 0\n val columns = Array(n, {\n val curr = scanner.nextInt()\n if (curr > max) {\n max = curr\n }\n curr\n })\n\n val tmp = IntArray(max, { 0 })\n\n columns.forEach {\n tmp[it - 1]++\n }\n\n var index = 0\n tmp.forEachIndexed { i, v ->\n for (j in 0 until v) {\n columns[index++] = i + 1\n }\n }\n\n println(columns.joinToString(\" \"))\n\n}"}, {"source_code": "fun main() {\n readLine()\n readLine()!!.split(' ').map(String::toInt).sorted().forEach { print(\"$it \") }\n}"}, {"source_code": "\n\nfun main(args: Array) {\n var count = readLine()!!.toInt()\n println(readLine()!!.split(\" \").map { it.toInt() }.sorted()\n .map {\n it.toString()\n }.joinToString (\" \"))\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.lang.StringBuilder\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n br.readLine()\n val row = br.readLine().split(\"\\\\s+\".toRegex())\n val sortedRow = row.sortedBy { i -> i.toInt() }\n val sb = StringBuilder()\n for (i in sortedRow)\n sb.append(\"$i \")\n sb.deleteCharAt(sb.length - 1)\n print(sb.toString())\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val input = InputReader(inputStream)\n val output = PrintWriter(outputStream)\n val solver = Task()\n solver.solve(input, output)\n output.close()\n}\n\nprivate class Task {\n fun solve(input: InputReader, output: PrintWriter) {\n val n = input.nextInt()\n\n val heights = (1..n).map { input.nextInt() }\n val maxHeight: Int = heights.max()!!\n\n val box = Array(maxHeight, { IntArray(n, { 0 }) })\n for (i in 0 until n) {\n for (j in 0 until heights[i]) {\n box[maxHeight - j - 1][i] = 1\n }\n }\n\n for (i in 0 until maxHeight) {\n for (j in n - 2 downTo 0) {\n for (k in j until n - 1) {\n if (box[i][k] == 1) {\n if (box[i][k + 1] == 0) {\n box[i][k + 1] = 1\n box[i][k] = 0\n }\n } else {\n break\n }\n }\n }\n }\n\n for (j in 0 until n) {\n var sum = 0\n for (i in 0 until maxHeight) {\n sum += box[i][j]\n }\n output.print(sum)\n output.print(\" \")\n }\n }\n}\n\n\nprivate class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n\n operator fun next(): String {\n while (tokenizer == null || tokenizer?.hasMoreTokens()?.not() == true) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return next().toInt()\n }\n\n}"}, {"source_code": "fun main() {\n readLine()\n println(readLine()!!.split(\" \").map(String::toInt).sorted().joinToString(\" \"))\n}"}, {"source_code": "fun main() {\n readLine()\n val input = readLine()!!.split(\" \").map(String::toInt).sorted()\n println(input.joinToString(\" \"))\n}"}, {"source_code": "import java.io.PrintWriter\nimport kotlin.math.*\n\nfun main() {\n io.apply {\n\n cout .. ints().sorted().toIntArray() .. nl\n\n }.cout.flush()\n}\n\n// @formatter:off\nprivate val io = object {\n private val `in` = System.`in`\n private fun ll(): Long {\n var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }\n do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n\n }\n val int get() = ll().toInt(); val long get() = ll()\n fun ints(n: Int = int): IntArray { return IntArray(n) { int } }\n fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }\n val cout = PrintWriter(System.out); val nl = \"\\n\"\n operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(\" \") }; return this }\n operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }\n} // @formatter:on\n\n/* ----------- */\n\n"}, {"source_code": "\nfun main() {\n var c = readLine()!!.toInt()\n var arr = readLine()!!.split(\" \").map { it.toInt() }.toIntArray()\n var matrex = Array(arr.max()!!.toInt()) { Array(c) { 0 } }\n var i = 0\n for (col in 0 until c) {\n for (row in (arr.max()!! - 1)downTo 0) {\n if(arr[i] < arr.max()!!){\n matrex[row][col] = 0\n arr[i]++\n }else\n matrex[row][col] = 1\n }\n i++\n }\n\n var res = Array(c){0}\n var index = 0\n for(i in 0 until arr.max()!!) {\n var lineArray = matrex[i]\n for(j in 0 until lineArray.size){\n if(lineArray[j] == 1) {\n res[index]++\n index++\n }\n }\n index = 0\n }\n for(i in res.size-1 downTo 0)\n print(\"${res[i]} \")\n}\n"}, {"source_code": "\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val s = readInt()\n\n val h = readInts().toMutableList()\n\n h.sort()\n\n println(h.joinToString(\" \"))\n}"}, {"source_code": "fun main(args: Array) {\n val n = readInt()\n println(readInts().sorted().joinToString(\" \"))\n}\n\nprivate fun readInt() = readLine()!!.toInt()\n\nprivate fun readInts() = readLine()!!.split(\" \").map { it.toInt() }"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n val a = readLine()!!.split(regex = \"\\\\s\".toRegex()).map { it.toInt() }.toTypedArray()\n .sorted()\n\n println(a.joinToString(separator = \" \"))\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n var n = reader.readLine().toInt()\n val nums = reader.readLine().split(\" \")\n .mapTo(mutableListOf(), { it.toInt() })\n\n var mismatch = true\n\n while (mismatch) {\n var counter = 0\n while (n - 1 != 0) {\n val difference = nums[n - 2] - nums[n - 1]\n if (difference > 0) {\n nums[n - 2] -= difference\n nums[n - 1] += difference\n counter++\n }\n n--\n }\n if(0 == counter) {\n mismatch = false\n }\n n = nums.size\n }\n nums.forEach({ print(\"$it \") })\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val n = br.readLine().toInt()\n val a = br.readLine().split(\" \").map { it.toInt() }\n val count = Array(101){0}\n for (a_i in a) {\n count[a_i]++\n }\n val ans = ArrayList()\n var i = 0\n while (i < count.size && ans.size < n) {\n if (count[i] > 0) {\n ans.add(i)\n count[i]--\n } else {\n i++\n }\n }\n println(ans.joinToString(\" \"))\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val n = br.readLine().toInt()\n val a = br.readLine().split(\" \").map { it.toInt() }\n val count = Array(105){0}\n for (a_i in a){\n count[a_i]++\n }\n\n val asorted = Array(n){0}\n var i = 0\n var j = 0\n\n while (i < count.size){\n if (count[i] != 0){\n asorted[j] = i\n count[i]--\n j++\n }else{\n i++\n }\n }\n println(asorted.joinToString(\" \"))\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.abs\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n var numOfCol = scan.nextInt()\n val list = mutableListOf()\n while (numOfCol-->0) {\n val s =scan.nextInt()\n list.add(s)\n }\n list.sort()\n list.forEach {\n print(\"$it \")\n\n }\n}"}, {"source_code": "import kotlin.math.abs\n\nfun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun findFlipCols(): List {\n val numCols = readInt()\n val colsVals = readInts()\n return colsVals.sorted()\n}\n\nfun main() {\n print(findFlipCols().joinToString(separator = \" \"))\n}\n"}, {"source_code": "fun main(args: Array) {\n gravityChange()\n}\nfun gravityChange(){\n readLine()\n readLine()?.split(\" \")?.map{ it.toInt()}?.sorted()?.forEach { print(\"$it \") }\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\nfun main() {\n var n = readLine()!!.toInt()\n var list = readLine()!!.split(' ').map { it.toInt() }\n\n Collections.sort(list)\n for (i in list){\n print(\"$i \")\n }\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val heights = readLine()!!.split(' ').map { it.toInt() }\n val freqs = IntArray(101)\n for (h in heights) {\n (1..h).forEach { freqs[it]++ }\n }\n for (i in 1..n) {\n print(\"${freqs.count { it >= n - i + 1 }} \")\n }\n println()\n}"}, {"source_code": "import java.util.*\n\nfun main(){\n val scan = Scanner(System.`in`)\n val n = scan.nextInt()\n val arr = IntArray(n)\n for (i in 0 until n) arr[i] = scan.nextInt()\n arr.sort()\n\n for (i in arr) print(\"$i \")\n}\n\n"}, {"source_code": "typealias int = Int\n\nfun main() {\n var n = readLine()!!.toInt()\n var arr : IntArray= readLine()!!.split(' ').map { it.toInt() }.toIntArray()\n arr.sort()\n\n for( idx in 0..arr.lastIndex) {\n print(\"${arr[idx]} \")\n }\n println()\n}"}, {"source_code": "fun main() {\n readLine()\n println(readLine()!!.split(\" \").map(String::toInt).sorted().joinToString(\" \"))\n}"}, {"source_code": "import java.lang.AssertionError\nimport java.util.*\n \nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n \nprivate fun myAssert(x: Boolean) {\n if (!x) {\n throw AssertionError()\n }\n}\n\nfun main(args: Array) {\n// var s = Scanner(System.`in`)\n var n = readInt()\n var l = readInts()\n l = l.sorted()\n println(l.joinToString(\" \"))\n}\n"}, {"source_code": "import java.util.Scanner\nimport java.util.Arrays\n\nfun main(args:Array)\n{\n var sc=Scanner(System.`in`)\n val n : Int = sc.nextInt()\n val a = IntArray(n)\n for(i in 0 until n)\n {\n a[i] = sc.nextInt()\n }\n Arrays.sort(a)\n for(i in 0 until n)\n {\n print(a[i])\n print(\" \")\n }\n}\n"}, {"source_code": "fun main(args: Array) {\n readLine()\n readLine()!!.split(' ').map(String::toInt).sorted().forEach {\n print(\"$it \")\n }\n print(\"\\n\")\n}\n"}, {"source_code": "fun main(args: Array) {\n readLine()\n readLine()!!.split(' ').map(String::toInt).toTypedArray().sorted().forEach {\n print(\"$it \")\n }\n print(\"\\n\")\n}\n"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val matrix = readLine()!!.split(' ').map { it.toInt() }.toMutableList()\n\n while ((n - 2 downTo 0).count {\n val delta = matrix[it] - matrix[it + 1]\n if (delta > 0) {\n matrix[it] -= delta\n matrix[it + 1] += delta\n }\n delta > 0\n } > 0){}\n\n println(matrix.joinToString(separator = \" \"))\n}"}, {"source_code": "fun main(args: Array) {\n readLine()!!.toInt()\n val array = readLine()!!.split(' ').map { it.toInt() }.sorted()\n println(array.joinToString(\" \"))\n}"}], "negative_code": [{"source_code": "fun main() {\n readLine()\n readLine()!!.split(' ').sorted().forEach { print(\"$it \") }\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.lang.StringBuilder\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n br.readLine()\n val row = br.readLine().split(\"\\\\s+\".toRegex())\n val sortedRow = row.sorted()\n val sb = StringBuilder()\n for (i in sortedRow)\n sb.append(\"$i \")\n sb.deleteCharAt(sb.length - 1)\n print(sb.toString())\n}"}, {"source_code": "\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val s = readInt()\n\n val h = readInts().toMutableList()\n\n var c = 0\n\n // 4\n //3 2 1 2\n\n while (c < s-1) { // no point for the last grid\n var i = c;\n var moved = false\n\n while (i < s-1) {\n if (h[i] > h[i+1]) {\n val t = h[i] - h[i + 1]\n h[i] = h[i] - t\n h[i + 1] = h[i+1] + t\n moved = true\n i++\n } else {\n moved = false\n break\n }\n }\n\n if (!moved) {\n c++\n }\n }\n\n println(h.joinToString(\" \"))\n}\n"}], "src_uid": "ae20712265d4adf293e75d016b4b82d8"} {"nl": {"description": "A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, .... The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.", "input_spec": "The first line of input contains two integers a and b (1 ≤ a, b ≤ 100). The second line contains two integers c and d (1 ≤ c, d ≤ 100).", "output_spec": "Print the first time Rick and Morty will scream at the same time, or  - 1 if they will never scream at the same time.", "sample_inputs": ["20 2\n9 19", "2 1\n16 12"], "sample_outputs": ["82", "-1"], "notes": "NoteIn the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82. In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time."}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nfun DataReader.solve(out: PrintWriter) {\n val a = nextInt()\n val b = nextInt()\n val c = nextInt()\n val d = nextInt()\n\n var answer = 100500\n\n for (i in 0..111) {\n for (j in 0..111) {\n if (b + a * i == d + c * j) {\n answer = Math.min(answer, b + a * i)\n }\n }\n }\n\n if (answer == 100500) {\n answer = -1\n }\n\n out.println(answer)\n}\n\n// Taken from `bintree`-s code.\nclass DataReader(private val reader: BufferedReader) {\n var st : StringTokenizer? = null\n companion object {\n fun createFromFile(name: String) = DataReader(BufferedReader(FileReader(name)))\n }\n\n fun next() : String? {\n while (st == null || !st!!.hasMoreTokens()) {\n val s = reader.readLine() ?: return null\n st = StringTokenizer(s)\n }\n\n return st?.nextToken()\n }\n\n fun nextToken() = next()!!\n\n fun nextInt() = nextToken().toInt()\n fun nextLong() = nextToken().toLong()\n fun readIntArray(n: Int) : IntArray {\n val result = IntArray(n)\n result.indices.forEach { i -> result[i] = nextInt() }\n return result\n }\n\n fun readLongArray(n: Int) : LongArray {\n val result = LongArray(n)\n result.indices.forEach { i -> result[i] = nextLong() }\n return result\n }\n\n fun nextLine() = reader.readLine()\n}\n\nfun main(args: Array) {\n val wr = PrintWriter(System.out);\n val re = BufferedReader(InputStreamReader(System.`in`));\n DataReader(re).solve(wr)\n wr.flush()\n}\n"}, {"source_code": "import kotlin.math.abs\n\nfun main() {\n val (a, b) = readLine()!!.split(\" \").map { it.toLong() }\n val (c, d) = readLine()!!.split(\" \").map { it.toLong() }\n val diffs = mutableSetOf()\n when {\n a % 2L == 0L && b % 2L == 0L && c % 2L == 0L && d % 2L != 0L -> print(-1)\n c % 2L == 0L && d % 2L == 0L && a % 2L == 0L && b % 2L != 0L -> print(-1)\n else -> {\n var first = b\n var second = d\n while (first != second) {\n if (diffs.contains(first - second)) {\n first = -1\n break\n } else diffs.add(first - second)\n if (first < second) first += a else second += c\n }\n print(first)\n }\n }\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\ntailrec fun gcd(a: Int, b: Int): Int {\n if (a != 0 && b != 0) {\n if (a > b) return gcd(a % b, b)\n else return gcd(b % a, a)\n }\n\n return a + b\n}\n\nfun gcde(a: Int, b: Int): Triple {\n if (a == 0) {\n return Triple(b, 0, 1)\n }\n\n val (d, x1, y1) = gcde(b % a, a)\n\n return Triple(d, y1 - (b / a) * x1, x1)\n}\n\nfun DataReader.solve(out: PrintWriter) {\n val b = nextInt()\n val a = nextInt()\n val d = nextInt()\n val c = nextInt()\n\n val q = c - a\n val (g) = gcde(b, -d)\n\n if (q % g != 0) {\n out.println(-1)\n return\n }\n\n for (i in 0..100000000) {\n val w = a + i * b - c\n\n if (w >= 0 && w % d == 0) {\n out.println(w + c)\n return\n }\n }\n\n//\n// val p = q / g\n//\n// val (g1, x, y) = gcde(b / g, -d / g)\n//\n// val (xr, yr) = x * p to y * p\n\n\n\n throw RuntimeException(\":(\")\n}\n\nfun Boolean.toYesNo() = if (this) \"YES\" else \"NO\"\n\nclass DataReader(private val reader: BufferedReader) {\n var st : StringTokenizer? = null\n companion object {\n fun createFromFile(name: String) = DataReader(BufferedReader(FileReader(name)))\n }\n\n fun next() : String? {\n while (st == null || !st!!.hasMoreTokens()) {\n val s = reader.readLine() ?: return null\n st = StringTokenizer(s)\n }\n\n return st?.nextToken()\n }\n\n fun nextToken() = next()!!\n\n fun nextInt() = nextToken().toInt()\n fun nextLong() = nextToken().toLong()\n fun readIntArray(n: Int) : IntArray {\n val result = IntArray(n)\n result.indices.forEach { i -> result[i] = nextInt() }\n return result\n }\n\n fun readLongArray(n: Int) : LongArray {\n val result = LongArray(n)\n result.indices.forEach { i -> result[i] = nextLong() }\n return result\n }\n\n fun nextLine() = reader.readLine()\n}\n\nfun main(args: Array) {\n val r: Reader\n val out: PrintWriter\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n r = FileReader(\"input.txt\")\n out = PrintWriter(\"output.txt\")\n } else {\n r = InputStreamReader(System.`in`)\n out = PrintWriter(System.out)\n }\n\n DataReader(BufferedReader(r)).solve(out)\n out.flush()\n}\n"}, {"source_code": "fun main(args: Array) {\n val (a, b) = readLine()!!.split(\" \").map(String::toInt)\n val (c, d) = readLine()!!.split(\" \").map(String::toInt)\n\n var ans = -1\n\n loop@ for (x in 0..99) {\n for (y in 0..99) {\n val t1 = b + x * a\n val t2 = d + y * c\n if (t1 == t2) {\n ans = t1\n break@loop\n }\n }\n }\n\n println(ans)\n}"}, {"source_code": "\nimport java.io.*\nimport java.util.*\nimport java.math.*\n\n//val inp = BufferedReader(FileReader ( \"input.txt\" ) )\nval inp = BufferedReader(InputStreamReader(System.`in`))\n\n\nfun solve() : Int {\n\tval a = ( inp.readLine() ?: return 1 ).split(\" \").map{ it.toInt() }\n\tval b = ( inp.readLine() ?: return 1 ).split(\" \").map{ it.toInt() }\n\tvar curA = a[1]\n\tvar curB = b[1]\n\tfor ( i in 1..1000000 ) {\n\t\tif ( curA == curB ) {\n\t\t\tprintln ( \"\" + curA )\n\t\t\treturn 0\n\t\t}\n\t\tif ( curA < curB ) curA += a[0]\n\t\telse curB += b[0]\n\t}\n\tprintln ( \"-1\" )\n\treturn 0\n}\n\nfun main ( args : Array ) {\n\twhile (solve()==0);\n}\n"}], "negative_code": [{"source_code": "import java.io.*\nimport java.util.*\n\n\nfun DataReader.solve(out: PrintWriter) {\n val b = nextInt()\n val a = nextInt()\n val d = nextInt()\n val c = nextInt()\n\n for (i in 1..1000000) {\n val q = a + i * b - c\n\n if (q >= 0 && q % d == 0) {\n out.println(q + c)\n return\n }\n }\n\n out.println(-1)\n}\n\nfun Boolean.toYesNo() = if (this) \"YES\" else \"NO\"\n\nclass DataReader(private val reader: BufferedReader) {\n var st : StringTokenizer? = null\n companion object {\n fun createFromFile(name: String) = DataReader(BufferedReader(FileReader(name)))\n }\n\n fun next() : String? {\n while (st == null || !st!!.hasMoreTokens()) {\n val s = reader.readLine() ?: return null\n st = StringTokenizer(s)\n }\n\n return st?.nextToken()\n }\n\n fun nextToken() = next()!!\n\n fun nextInt() = nextToken().toInt()\n fun nextLong() = nextToken().toLong()\n fun readIntArray(n: Int) : IntArray {\n val result = IntArray(n)\n result.indices.forEach { i -> result[i] = nextInt() }\n return result\n }\n\n fun readLongArray(n: Int) : LongArray {\n val result = LongArray(n)\n result.indices.forEach { i -> result[i] = nextLong() }\n return result\n }\n\n fun nextLine() = reader.readLine()\n}\n\nfun main(args: Array) {\n val r: Reader\n val out: PrintWriter\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n r = FileReader(\"input.txt\")\n out = PrintWriter(\"output.txt\")\n } else {\n r = InputStreamReader(System.`in`)\n out = PrintWriter(System.out)\n }\n\n DataReader(BufferedReader(r)).solve(out)\n out.flush()\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\ntailrec fun gcd(a: Int, b: Int): Int {\n if (a != 0 && b != 0) {\n if (a > b) return gcd(a % b, b)\n else return gcd(b % a, a)\n }\n\n return a + b\n}\n\nfun gcde(a: Int, b: Int): Triple {\n if (a == 0) {\n return Triple(b, 0, 1)\n }\n\n val (d, x1, y1) = gcde(b % a, a)\n\n return Triple(d, y1 - (b / a) * x1, x1)\n}\n\nfun DataReader.solve(out: PrintWriter) {\n val b = nextInt()\n val a = nextInt()\n val d = nextInt()\n val c = nextInt()\n\n val q = c - a\n val (g) = gcde(b, -d)\n\n if (q % g != 0) {\n out.println(-1)\n return\n }\n\n for (i in 1..100000000) {\n val w = a + i * b - c\n\n if (w >= 0 && w % d == 0) {\n out.println(w + c)\n return\n }\n }\n\n//\n// val p = q / g\n//\n// val (g1, x, y) = gcde(b / g, -d / g)\n//\n// val (xr, yr) = x * p to y * p\n\n\n\n out.println(-1)\n}\n\nfun Boolean.toYesNo() = if (this) \"YES\" else \"NO\"\n\nclass DataReader(private val reader: BufferedReader) {\n var st : StringTokenizer? = null\n companion object {\n fun createFromFile(name: String) = DataReader(BufferedReader(FileReader(name)))\n }\n\n fun next() : String? {\n while (st == null || !st!!.hasMoreTokens()) {\n val s = reader.readLine() ?: return null\n st = StringTokenizer(s)\n }\n\n return st?.nextToken()\n }\n\n fun nextToken() = next()!!\n\n fun nextInt() = nextToken().toInt()\n fun nextLong() = nextToken().toLong()\n fun readIntArray(n: Int) : IntArray {\n val result = IntArray(n)\n result.indices.forEach { i -> result[i] = nextInt() }\n return result\n }\n\n fun readLongArray(n: Int) : LongArray {\n val result = LongArray(n)\n result.indices.forEach { i -> result[i] = nextLong() }\n return result\n }\n\n fun nextLine() = reader.readLine()\n}\n\nfun main(args: Array) {\n val r: Reader\n val out: PrintWriter\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n r = FileReader(\"input.txt\")\n out = PrintWriter(\"output.txt\")\n } else {\n r = InputStreamReader(System.`in`)\n out = PrintWriter(System.out)\n }\n\n DataReader(BufferedReader(r)).solve(out)\n out.flush()\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\ntailrec fun gcd(a: Int, b: Int): Int {\n if (a != 0 && b != 0) {\n if (a > b) return gcd(a % b, b)\n else return gcd(b % a, a)\n }\n\n return a + b\n}\n\nfun gcde(a: Int, b: Int): Triple {\n if (a == 0) {\n return Triple(b, 0, 1)\n }\n\n val (d, x1, y1) = gcde(b % a, a)\n\n return Triple(d, y1 - (b / a) * x1, x1)\n}\n\nfun DataReader.solve(out: PrintWriter) {\n val b = nextInt()\n val a = nextInt()\n val d = nextInt()\n val c = nextInt()\n\n val q = c - a\n val (g) = gcde(b, -d)\n\n if (q % g != 0) {\n out.println(-1)\n return\n }\n\n for (i in 1..100000000) {\n val w = a + i * b - c\n\n if (w >= 0 && w % d == 0) {\n out.println(w + c)\n return\n }\n }\n\n//\n// val p = q / g\n//\n// val (g1, x, y) = gcde(b / g, -d / g)\n//\n// val (xr, yr) = x * p to y * p\n\n\n\n throw RuntimeException(\":(\")\n}\n\nfun Boolean.toYesNo() = if (this) \"YES\" else \"NO\"\n\nclass DataReader(private val reader: BufferedReader) {\n var st : StringTokenizer? = null\n companion object {\n fun createFromFile(name: String) = DataReader(BufferedReader(FileReader(name)))\n }\n\n fun next() : String? {\n while (st == null || !st!!.hasMoreTokens()) {\n val s = reader.readLine() ?: return null\n st = StringTokenizer(s)\n }\n\n return st?.nextToken()\n }\n\n fun nextToken() = next()!!\n\n fun nextInt() = nextToken().toInt()\n fun nextLong() = nextToken().toLong()\n fun readIntArray(n: Int) : IntArray {\n val result = IntArray(n)\n result.indices.forEach { i -> result[i] = nextInt() }\n return result\n }\n\n fun readLongArray(n: Int) : LongArray {\n val result = LongArray(n)\n result.indices.forEach { i -> result[i] = nextLong() }\n return result\n }\n\n fun nextLine() = reader.readLine()\n}\n\nfun main(args: Array) {\n val r: Reader\n val out: PrintWriter\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n r = FileReader(\"input.txt\")\n out = PrintWriter(\"output.txt\")\n } else {\n r = InputStreamReader(System.`in`)\n out = PrintWriter(System.out)\n }\n\n DataReader(BufferedReader(r)).solve(out)\n out.flush()\n}\n"}], "src_uid": "158cb12d45f4ee3368b94b2b622693e7"} {"nl": {"description": "HQ9+ is a joke programming language which has only four one-character instructions: \"H\" prints \"Hello, World!\", \"Q\" prints the source code of the program itself, \"9\" prints the lyrics of \"99 Bottles of Beer\" song, \"+\" increments the value stored in the internal accumulator.Instructions \"H\" and \"Q\" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.", "input_spec": "The input will consist of a single line p which will give a program in HQ9+. String p will contain between 1 and 100 characters, inclusive. ASCII-code of each character of p will be between 33 (exclamation mark) and 126 (tilde), inclusive.", "output_spec": "Output \"YES\", if executing the program will produce any output, and \"NO\" otherwise.", "sample_inputs": ["Hi!", "Codeforces"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first case the program contains only one instruction — \"H\", which prints \"Hello, World!\".In the second case none of the program characters are language instructions."}, "positive_code": [{"source_code": "fun main() {\n var r = readLine().toString()\n for(e in 0..r.length - 1){\n if(r[e] == 'H' || r[e] == 'Q' || r[e] == '9'){\n print(\"YES\")\n return\n }\n }\n print(\"NO\")\n return\n}\n"}, {"source_code": "fun main () {\n var str: String? = readLine()\n var isPrint: Boolean = false\n\n if(str == null) return\n\n str.forEach { n ->\n when(n){\n 'H','Q','9' -> {\n println(\"YES\")\n isPrint = true\n return\n }\n }\n }\n\n if(!isPrint) println(\"NO\")\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n var tok = StringTokenizer(\"\")\n\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n fun files(inputFilename: String, outputFilename: String) = ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))\n }\n\n fun readToken(): String {\n while (!tok.hasMoreTokens()) {\n tok = StringTokenizer(rd.readLine())\n }\n return tok.nextToken()\n }\n\n fun readInt(): Int = readToken().toInt()\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun close() {\n rd.close()\n wr.close()\n }\n}\n\nfun solve() {\n val io = ProblemIO.console()\n val t = io.readToken()\n var res = false\n for (ch in t) {\n when (ch) {\n 'H', 'Q', '9' -> res = true\n }\n }\n io.println(if (res) \"YES\" else \"NO\")\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n"}, {"source_code": "fun main()\n{\n val given = readLine()!!\n println( if (given.any() { \"HQ9\".contains(it)} ) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n var str = r.readLine()!!\n val list = listOf('H', 'Q', '9')\n var has = false\n str.forEach {\n if (it in list) has = true\n }\n println(if (has) \"YES\" else \"NO\")\n}"}, {"source_code": "import java.util.*\nimport java.math.*\nimport kotlin.math.*\n\nfun readLn()=readLine()!!\nfun readInt()=readLn().toInt()\nfun readInts()=readLn().split(\" \").map{it.toInt()}\nfun readLong()=readLn().toLong()\nfun readLongs()=readLn().split(\" \").map{it.toLong()}\n\nval out=mutableListOf()\nfun printLine(s:String){out.add(s)}\nfun output(){println(out.joinToString(\"\\n\"))}\n\nfun main(){\n var str=readLn()\n var ok=str.contains('H')||str.contains('Q')||str.contains('9')\n printLine(if(ok)\"YES\" else \"NO\")\n output()\n}"}, {"source_code": "fun main() {\n\tval commands = listOf('H', 'Q', '9')\n\tprintln(if (readLine()!!.any { it in commands }) \"YES\" else \"NO\")\n}\n"}, {"source_code": "fun main(args: Array){readLine()?.let{it.forEach{if(it=='H'||it=='Q'||it=='9'){println(\"YES\");return;}}};println(\"NO\")}\n"}, {"source_code": "\nfun main(args: Array)\n{\n\n var text = readLine()!!\n\n if(text.contains(\"[HQ9]+\".toRegex()))\n {\n print(\"YES\")\n }\n else\n {\n print(\"NO\")\n }\n}"}, {"source_code": "fun main(args: Array) {\n val input = readLine()!!\n val commands = listOf('H', 'Q', '9')\n for (i in 0 until input.length){\n val char = input[i]\n if (char in commands){\n print(\"YES\")\n return\n }\n }\n print(\"NO\")\n}"}, {"source_code": "fun main() {\n val a = readLine()\n for (i in 0 until a?.length!!) {\n if (a.get(i).equals('H') || a.get(i).equals('Q') || a.get(i).equals('9') ) {\n print(\"YES\")\n return\n }\n }\n print(\"NO\")\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val input = InputReader(inputStream)\n val output = PrintWriter(outputStream)\n val solver = Task()\n solver.solve(input, output)\n output.close()\n}\n\nprivate class Task {\n fun solve(input: InputReader, output: PrintWriter) {\n for (symbol in input.next()) {\n if (symbol == 'H' || symbol == 'Q' || symbol == '9') {\n output.print(\"YES\")\n return\n }\n }\n\n output.print(\"NO\")\n }\n}\n\n\nprivate class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n\n operator fun next(): String {\n while (tokenizer == null || tokenizer?.hasMoreTokens()?.not() == true) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return next().toInt()\n }\n\n}"}, {"source_code": "fun main() {\n val hasOutput = readLine()!!\n .any {\n when (it) {\n 'H','Q','9' -> true\n else -> false\n }\n }\n val answer = if (hasOutput) \"YES\" else \"NO\"\n println(answer)\n}"}, {"source_code": "import java.util.regex.Pattern\n\nfun main(){\n if(Pattern.compile(\"[QH9]\").matcher(readLine()).find()) println(\"YES\") else println(\"NO\")\n}\n"}, {"source_code": "fun main(args: Array) {\n val p = readLine()\n if (p!!.contains('H')||p!!.contains('Q')||p!!.contains('9')){\n println(\"YES\")\n }\n else{\n println(\"NO\")\n\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val s: Scanner = Scanner(System.`in`)\n val str: String = s.next()\n print(if (str.contains(\"H\") || str.contains(\"Q\") || str.contains(\"9\")) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main(args: Array) {\n\n readLine()!!.toString()\n .toCharArray()\n .filter {\n it == 'H' || it == 'Q' || it == '9'\n }\n .run {\n print(if (iterator().hasNext()) \"YES\" else \"NO\")\n }\n}"}, {"source_code": "fun main() {\n val s = readLine()!!\n println(if (\"[HQ9]+\".toRegex().containsMatchIn(s)) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main() {\n val i = setOf('H', 'Q', '9')\n println( if(readLine()!!.any { it in i }) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main(args : Array) {\n var line = readLine()!!\n if (line.contains('H') || line.contains('Q') || line.contains('9'))\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "import java.util.*\n\n fun main(){\n var input = Scanner(System.`in`)\n var inputString = input.nextLine()\n var array = intArrayOf(0,0,0,0)\n inputString.toCharArray().forEach {\n if(it == 'H'){\n array[0]++\n }\n\n if(it == 'Q'){\n array[1]++\n }\n if(it == '9'){\n array[2]++\n }\n\n }\n\n if(array[0] > 0 || array[1] > 0 || array[2] > 0){\n print(\"YES\")\n }else{\n print(\"NO\")\n }\n }\n\n\n\n\n\n\n\n\n"}, {"source_code": "fun main() {\n val prg = readLn()\n val ans = prg.any { it in \"HQ9\" }\n\n println(if(ans) \"YES\" else \"NO\")\n}\n\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }"}, {"source_code": "\n// https://codeforces.com/problemset/problem/133/A\n\nfun main(args: Array) {\n val code = readLn()\n val emptySet = setOf('H', 'Q', '9')\n\n var printCode = false\n for (character in code) {\n if (character in emptySet) {\n printCode = true\n break\n }\n }\n if (printCode)\n print(\"YES\")\n else\n print(\"NO\")\n\n}\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings(del: String = \" \") = readLn().split(del) // list of strings\nprivate fun readInts(del: String = \" \") = readStrings(del).map { it.toInt() } // list of ints"}, {"source_code": "//package problem133A\n\nfun main() {\n val program = readLine()!!\n\n println(if ('H' in program || 'Q' in program || '9' in program) \"YES\" else \"NO\")\n}\n"}, {"source_code": "/**\n * Created by Ahmed Ehab Hussein on 14/08/2017.\n */\n\nfun main (args:Array){\n var p = readLine()!!\n var flag:Int = 0\n for (ch in p)\n if(ch == 'H' || ch == 'Q' || ch == '9')\n flag += 1\n\n if(flag > 0){\n println(\"YES\")\n }else{\n println(\"NO\")\n }\n}"}, {"source_code": "fun main() {\n val s = readLine()!!\n println(if ('H' in s || 'Q' in s || '9' in s) \"YES\" else \"NO\")\n}\n"}, {"source_code": "import java.lang.reflect.Array\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\n\nfun main()\n{\n var scanner = Scanner(System.`in`)\n var str = scanner.nextLine()\n var flag : Boolean = false\n for(i in 0 until str.length)\n {\n if(str[i] == 'H' || str[i] == 'Q' || str[i] == '9' )\n flag = true\n }\n if(flag)\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "import java.lang.reflect.Array\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\n\nfun main()\n{\n var scanner = Scanner(System.`in`)\n var str = scanner.nextLine()\n if(str.any { it == 'H' || it == 'Q' ||it == '9' })\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "import java.util.*\nfun main() {\n val sc = Scanner(System.`in`)\n val s = sc.nextLine()\n if(\"H\" in s || \"Q\" in s || \"9\" in s){\n print(\"YES\")\n }\n else{\n print(\"NO\")\n }\n}"}, {"source_code": "fun main(args: Array) {\n val a = readLine()!!\n if (a.contains( \"H\") || a.contains( \"Q\") || a.contains( \"9\")){\n print(\"YES\")\n }\n else{\n print(\"NO\")\n }\n}\n"}, {"source_code": "fun main(args: Array) {\n val line = readLine()!!\n if (line.any { it in arrayOf('H', 'Q', '9') }) println(\"YES\") else println(\"NO\")\n}"}, {"source_code": "fun main() {\n var word: String? = readLine()\n var found=0;\n for (ch in word!!)\n {\n when(ch){\n 'H','Q','9'-> {\n found++;\n }\n }\n }\n\n if (found>0)\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array){\n val scan = Scanner(System.`in`)\n val b = scan.next().toCharArray()\n if (b.contains('H') or b.contains('Q') or b.contains('9')) print(\"YES\")\n else print(\"NO\")\n}"}, {"source_code": "fun main(args: Array) {\n val regex = \"[HQ9]\"\n println(if (Regex(regex).containsMatchIn(readLine()!!)) \"YES\" else \"NO\")\n}"}, {"source_code": "import java.util.*\nfun main(args: Array) {\n var s = Scanner(System.`in`).next()\n if (s.contains(\"H\") || s.contains(\"Q\") || s.contains(\"9\")) print(\"YES\")\n else print(\"NO\")\n}"}, {"source_code": "import java.io.BufferedInputStream\nimport java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(BufferedInputStream(System.`in`))\n val input = scanner.nextLine()\n if(ok(input)) print(\"YES\")\n else print(\"NO\")\n\n}\n\nfun ok(string: String): Boolean{\n for (c in string){\n if(c == 'H' || c == 'Q' || c == '9') return true\n }\n return false\n}"}, {"source_code": "import java.io.BufferedInputStream\nimport java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(BufferedInputStream(System.`in`))\n val input = scanner.nextLine()\n if('H' in input || 'Q' in input || '9' in input) print(\"YES\")\n else print(\"NO\")\n\n}"}, {"source_code": "fun main(args: Array) {\n\n val input = readLine()!!\n\n if (input.indexOf(\"H\") != -1 || input.indexOf(\"Q\") != -1 || input.indexOf(\"9\") != -1 ){\n println(\"YES\")\n }else{\n println(\"NO\")\n }\n\n}"}, {"source_code": "import java.util.*\n\nprivate val scan = Scanner(System.`in`)\n\nfun main(args: Array) {\n println(if (scan.next().contains(Regex(\"[HQ9]\"))) \"YES\" else \"NO\")\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val bufferedReader = BufferedReader(InputStreamReader(System.`in`))\n val line = bufferedReader.readLine()\n val contains = line.contains(Regex(\"[HQ9]\"))\n println(if (contains) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main() {\n if(readLine()!!.toCharArray().indexOfFirst{ c -> c == 'H' || c == 'Q' || c == '9' } >= 0)\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "fun main(args: Array) {\n println(\n if (readLine()!!.contains(Regex(\"[HQ9]\")))\n \"YES\"\n else\n \"NO\"\n )\n}\n"}, {"source_code": "fun main (args : Array){\n println(if (Regex(\"[HQ9]\").containsMatchIn(readLine()!!)) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main(args: Array) {\n if (readLine()!!.any { it == 'H' || it == 'Q' || it == '9' }) {\n println(\"YES\")\n }\n else {\n println(\"NO\")\n }\n\n}\n"}, {"source_code": "fun main() {\n print(if (readLine()!!.split(\"\").any { \"H,Q,9\".split(\",\").contains(it) }) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main(args: Array) {\n val p: String? = readLine()\n val list = listOf('H', 'Q', '9')\n var res = \"NO\"\n for (element in list) {\n if (p?.contains(element)!!) {\n res = \"YES\"\n break\n }\n }\n println(res)\n}"}, {"source_code": "import java.util.Scanner\nimport kotlin.io.*\nfun main(args:Array)=with (Scanner(System.`in`)){\n val reader = Scanner(System.`in`)\n var a : String?\n a = readLine();\n var b:Boolean = false;\n for(ch in a!!.toCharArray()){\n if(ch == 'H')b=true;\n if(ch == 'Q')b=true;\n if(ch == '9')b=true;\n }\n if(b)println(\"YES\")\n else println(\"NO\")\n}"}, {"source_code": "fun main(args: Array) {\n val s = readLine()!!\n\n print(if (s.contains(\"H\") || s.contains(\"Q\") || s.contains(\"9\")) \"YES\" else \"NO\")\n}"}], "negative_code": [{"source_code": "fun main()\n{\n val given = readLine()!!\n println( if (given.any() { \"HQ9+\".contains(it)} ) \"YES\" else \"NO\")\n}"}, {"source_code": "\nfun main(args: Array)\n{\n\n var text = readLine()!!\n\n if(text.contains(\"[HQ9+]+\".toRegex()))\n {\n print(\"YES\")\n }\n else\n {\n print(\"NO\")\n }\n}"}, {"source_code": "import java.util.regex.Pattern\n\nfun main(){\n if(Pattern.compile(\"[QH]\").matcher(readLine()).find()) println(\"YES\") else println(\"NO\")\n}\n"}, {"source_code": "fun main(args: Array) {\n val p = readLine()\n if (p!!.contains('H')||p!!.contains('Q')||p!!.contains('9')||p!!.contains('+')){\n println(\"YES\")\n }\n else{\n println(\"NO\")\n\n }\n}"}, {"source_code": "fun main(args: Array) {\n val p = readLine()\n if (p!!.contains('H')||p!!.contains('Q')||p!!.contains('9')||p!!.contains('+')){\n println(\"Yes\")\n }\n else{\n println(\"NO\")\n\n }\n}"}, {"source_code": "fun main(args: Array) {\n\n readLine()!!.toString()\n .toCharArray()\n .filter {\n it == 'H' || it == 'Q' || it == '9' || it == '+'\n }\n .run {\n print(if (iterator().hasNext()) \"YES\" else \"NO\")\n }\n}"}, {"source_code": "fun main(args : Array) {\n var line = readLine()!!\n if (line.contains('H') || line.contains('Q') || line.contains('9') || line.contains('+'))\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "import java.util.*\n\n fun main(){\n var input = Scanner(System.`in`)\n var inputString = input.nextLine()\n if(inputString.toCharArray().filter { it == 'H' || it == 'Q' || it == '9' || it == '+' }.isNotEmpty()){\n print(\"YES\")\n }else{\n print(\"NO\")\n }\n }\n\n\n\n\n\n\n\n\n"}, {"source_code": "import java.util.*\n\n fun main(){\n var input = Scanner(System.`in`)\n var inputString = input.nextLine()\n if(inputString.contains(\"H\") || inputString.contains(\"Q\") || inputString.contains(\"9\") || inputString.contains(\"+\")){\n print(\"YES\")\n }else{\n print(\"NO\")\n }\n }\n\n\n\n\n\n\n\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/133/A\n\nfun main(args: Array) {\n val code = readLn()\n val emptySet = setOf('H', 'Q', '9', '+')\n\n var printCode = false\n for (character in code) {\n if (character in emptySet) {\n printCode = true\n break\n }\n }\n if (printCode)\n print(\"YES\")\n else\n print(\"NO\")\n\n}\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings(del: String = \" \") = readLn().split(del) // list of strings\nprivate fun readInts(del: String = \" \") = readStrings(del).map { it.toInt() } // list of ints"}, {"source_code": "//package problem133A\n\nfun main() {\n val program = readLine()!!\n\n println(if ('H' in program || 'Q' in program) \"YES\" else \"NO\")\n}\n"}, {"source_code": "/**\n * Created by Ahmed Ehab Hussein on 14/08/2017.\n */\n\nfun main (args:Array){\n var p = readLine()!!\n var flag:Int = 0\n for (ch in p)\n if(ch == 'H' || ch == 'Q' || ch == '9' || ch == '+')\n flag += 1\n\n if(flag > 0){\n println(\"YES\")\n }else{\n println(\"NO\")\n }\n}"}, {"source_code": "import java.lang.reflect.Array\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\n\nfun main()\n{\n var scanner = Scanner(System.`in`)\n var str = scanner.nextLine()\n if(str.any { it == 'H' || it == 'Q' || it == '9' || it == '+' })\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "import java.lang.reflect.Array\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\n\nfun main()\n{\n var scanner = Scanner(System.`in`)\n var str = scanner.nextLine()\n var flag : Boolean = false\n for(i in 0 until str.length)\n {\n if(str[i] == 'H' || str[i] == 'Q' || str[i] == '9' || str[i] == '+')\n flag = true\n }\n if(flag)\n println(\"YES\")\n else\n println(\"NO\")\n}"}, {"source_code": "import java.util.*\nfun main() {\n val sc = Scanner(System.`in`)\n val s = sc.nextLine()\n if(\"H\" in s || \"Q\" in s || \"+\" in s || \"9\" in s){\n print(\"YES\")\n }\n else{\n print(\"NO\")\n }\n}"}, {"source_code": "import java.util.*\nfun main() {\n val sc = Scanner(System.`in`)\n val s = sc.nextLine()\n if(s.contains(\"H\") || s.contains(\"Q\") || s.contains(\"+\")||s.contains(\"9\")){\n print(\"YES\")\n }\n else{\n print(\"NO\")\n }\n}"}, {"source_code": "import java.util.*\nfun main() {\n val sc = Scanner(System.`in`)\n val s = sc.nextLine()\n if(\"HQ9+\" in s ){\n print(\"YES\")\n }\n else{\n print(\"NO\")\n }\n}"}, {"source_code": "import java.util.*\nfun main() {\n val sc = Scanner(System.`in`)\n val s = sc.nextLine()\n if(s.contains(\"H\") || s.contains(\"H\") || s.contains(\"H\")||s.contains(\"H\")){\n print(\"YES\")\n }\n else{\n print(\"NO\")\n }\n}"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array){\n val scan = Scanner(System.`in`)\n val b = scan.next().toCharArray()\n if (b.contains('H') or b.contains('Q') or b.contains('9') or b.contains('+')) print(\"YES\")\n else print(\"NO\")\n}"}, {"source_code": "fun main(args: Array) {\n val regex = \"[HG9+]\"\n println(if (Regex(regex).containsMatchIn(readLine()!!)) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main(args: Array) {\n val regex = \"[HG9]\"\n println(if (Regex(regex).containsMatchIn(readLine()!!)) \"YES\" else \"NO\")\n}"}, {"source_code": "import java.io.BufferedInputStream\nimport java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(BufferedInputStream(System.`in`))\n val input = scanner.nextLine()\n if('H' in input || 'Q' in input || '9' in input) print(\"Yes\")\n else print(\"No\")\n\n}"}, {"source_code": "fun main(args: Array) {\n val p: String? = readLine()\n val list = listOf('H', 'Q', '9', '+')\n var res = \"NO\"\n for (i in 0..3) {\n if (p?.contains(list[i])!!) {\n res = \"YES\"\n break\n }\n }\n println(res)\n}"}, {"source_code": "fun main() {\n var r = readLine().toString()\n for(e in 0..r.length - 1){\n if(r[e] == 'H' || r[e] == 'Q' || r[e] == '9'){\n print(\"yes\")\n return\n }\n }\n print(\"NO\")\n return\n}\n"}], "src_uid": "1baf894c1c7d5aeea01129c7900d3c12"} {"nl": {"description": "To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $$$s$$$ airplanes.A group of $$$k$$$ people decided to make $$$n$$$ airplanes each. They are going to buy several packs of paper, each of them containing $$$p$$$ sheets, and then distribute the sheets between the people. Each person should have enough sheets to make $$$n$$$ airplanes. How many packs should they buy?", "input_spec": "The only line contains four integers $$$k$$$, $$$n$$$, $$$s$$$, $$$p$$$ ($$$1 \\le k, n, s, p \\le 10^4$$$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.", "output_spec": "Print a single integer — the minimum number of packs they should buy.", "sample_inputs": ["5 3 2 3", "5 3 100 1"], "sample_outputs": ["4", "5"], "notes": "NoteIn the first sample they have to buy $$$4$$$ packs of paper: there will be $$$12$$$ sheets in total, and giving $$$2$$$ sheets to each person is enough to suit everyone's needs.In the second sample they have to buy a pack for each person as they can't share sheets."}, "positive_code": [{"source_code": "import java.util.*\n\nfun main(args: Array) {\n val inp = Scanner(System.`in`)\n\n val k = inp.nextInt()\n val n = inp.nextInt()\n val s = inp.nextInt()\n val p = inp.nextInt()\n\n val parersRequiredForPerson = Math.ceil(n.toDouble() / s.toDouble()).toInt()\n val allRequired = parersRequiredForPerson * k\n\n var curPaperBlocks = 0\n while (curPaperBlocks * p < allRequired) {\n curPaperBlocks++\n }\n print(curPaperBlocks)\n}"}, {"source_code": "\n\nfun main(args: Array) {\n val (k, n, s, p) = readLine()!!.split(\" \").map { a -> a.toDouble() }\n println(Math.ceil(Math.ceil(n / s) * k / p).toLong())\n\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numPeople, numPlanesEach, numPlanesPerSheet, numSheetsPerPack) = readInts()\n val sheetsPerPerson = numPlanesEach / numPlanesPerSheet + if (numPlanesEach % numPlanesPerSheet == 0) 0 else 1\n val totalSheets = sheetsPerPerson * numPeople\n print(totalSheets / numSheetsPerPack + if (totalSheets % numSheetsPerPack == 0) 0 else 1)\n}"}, {"source_code": "fun main(args: Array) {\n val (k, n, s, p) = readLine()!!.split(' ').map { it.toLong() }\n\n val sheets = (n + if (n % s == 0L) 0 else s) / s\n println((k * sheets + if ((k * sheets) % p == 0L) 0 else p ) / p)\n}"}, {"source_code": "import kotlin.math.*\nfun main(args: Array){\n\tval (k, n, s, p) = readLine().toString().split(\" \").map{it.toInt()}\n\tval sheetspp = ceil(n.toFloat()/s.toFloat())\n\t//val sol = ((n * k)/s)/p\n\tprintln(ceil(k.toFloat() * sheetspp/p.toFloat()).toInt())\n}"}], "negative_code": [], "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780"} {"nl": {"description": "You are given an integer sequence $$$1, 2, \\dots, n$$$. You have to divide it into two sets $$$A$$$ and $$$B$$$ in such a way that each element belongs to exactly one set and $$$|sum(A) - sum(B)|$$$ is minimum possible.The value $$$|x|$$$ is the absolute value of $$$x$$$ and $$$sum(S)$$$ is the sum of elements of the set $$$S$$$.", "input_spec": "The first line of the input contains one integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^9$$$).", "output_spec": "Print one integer — the minimum possible value of $$$|sum(A) - sum(B)|$$$ if you divide the initial sequence $$$1, 2, \\dots, n$$$ into two sets $$$A$$$ and $$$B$$$.", "sample_inputs": ["3", "5", "6"], "sample_outputs": ["0", "1", "1"], "notes": "NoteSome (not all) possible answers to examples:In the first example you can divide the initial sequence into sets $$$A = \\{1, 2\\}$$$ and $$$B = \\{3\\}$$$ so the answer is $$$0$$$.In the second example you can divide the initial sequence into sets $$$A = \\{1, 3, 4\\}$$$ and $$$B = \\{2, 5\\}$$$ so the answer is $$$1$$$.In the third example you can divide the initial sequence into sets $$$A = \\{1, 4, 5\\}$$$ and $$$B = \\{2, 3, 6\\}$$$ so the answer is $$$1$$$."}, "positive_code": [{"source_code": "private fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\n\nfun main() {\n\n val n = readInt()\n\n val cost = when (n % 4) {\n 1 -> 1\n 2 -> 1\n 3 -> 0\n else -> 0\n }\n println(\"$cost\")\n\n}\n\n"}, {"source_code": "import java.util.Scanner\n\nfun main(args : Array) {\n\n val reader = Scanner(System.`in`)\n var n: Int = reader.nextInt()\n\n var k = 0\n\n if(n%2==0){\n while(n!=0){\n n=n-2\n k++\n }\n }\n else {\n while(n!=1){\n n=n-2\n k++\n }\n }\n if(n%2==0 && k%2==0) {\n println(0)\n }\n else if(n%2==0 && k%2==1){\n println(1)\n }\n else if(n%2==1 && k%2==0) {\n println(1)\n }\n else if(n%2==1 && k%2==1){\n println(0)\n }\n}\n"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!.toInt()\n //val day = r.readLine()!!.split(\" \").map { it.toInt() }\n when(n%4){\n 0, 3 -> println(0)\n else -> println(1)\n }\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\n/**\n * Solution\n */\nfun main() {\n\n val n = nextInt()\n println(if (n % 4 == 0 || (n+1) % 4 == 0) 0 else 1)\n\n}\n\nprivate var st = StringTokenizer(\"\")\n\nprivate fun hasNext(): Boolean {\n while (!st.hasMoreTokens()) {\n st = StringTokenizer(input.readLine() ?: return false)\n }\n return true\n}\nprivate fun next() = if (hasNext()) st.nextToken()!! else throw RuntimeException(\"No tokens\")\nprivate fun nextInt() = next().toInt()\nprivate fun nextLong() = next().toLong()\nprivate fun nextDouble() = next().toDouble()\nprivate fun nextArray(n: Int) = IntArray(n) { nextInt() }\nprivate fun nextLine() = if (hasNext()) st.nextToken(\"\\n\")!! else throw RuntimeException(\"No tokens\")\n\nprivate val ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\nprivate var input = when (ONLINE_JUDGE) {\n true -> BufferedReader(InputStreamReader(System.`in`), 32768)\n else -> BufferedReader(FileReader(\"in.txt\"))\n}\n"}, {"source_code": "import java.util.*\nimport kotlin.math.max\n\nval readQueue = ArrayDeque()\n\nfun getInput(): String {\n if (readQueue.isEmpty()) readLine()!!.split(' ', '\\n').let { readQueue.addAll(it) }\n return readQueue.pop()\n}\n\nfun getInt() = getInput().toInt()\nfun getDouble() = getInput().toDouble()\nfun getString() = getInput()\nfun getLong() = getInput().toLong()\n\nfun printv(v: Collection) {\n v.forEachIndexed { i, t ->\n if (i != 0) print(\" \")\n print(t)\n }\n println()\n}\n\nfun > lsort(v: MutableList) {\n v.sort()\n}\n\nfun > gsort(v: MutableList) {\n v.sortDescending()\n}\n\nfun mp(t: T, u: U) = Pair(t, u)\n\nfun ifloor(a: Int, b: Int) = if (a xor b > 0) a / b else (a - b + 1) / b\nfun iceil(a: Int, b: Int) = if (a xor b > 0) (a + b - 1) / b else a / b\nfun ifloor(a: Long, b: Long) = if (a xor b > 0) a / b else (a - b + 1) / b\nfun iceil(a: Long, b: Long) = if (a xor b > 0) (a + b - 1) / b else a / b\n\ntypealias ll = Long\ntypealias pii = Pair\ntypealias pll = Pair\n\nval MOD = 1000000007L\nval MAX = 2147483647L\n\nfun List.binarySearchWith(condition: (T) -> Boolean): Int {\n return binarySearch {\n if (condition(it)) 1\n else -1\n }.let { -(it + 1) }\n}\n\nfun List.lowerBound(i: Int): Int {\n return binarySearchWith { it >= i }\n}\n\nfun List.upperBound(i: Int): Int {\n return binarySearchWith { it > i }\n}\n\nfun main() {\n\n var n = getInt()\n if(n == 1){\n println(1)\n return\n }\n if(n % 2 == 1) n -= 3;\n n /= 2;\n if(n % 2 == 1) println(1)\n else println(0)\n\n}"}, {"source_code": "fun main(args: Array){\n\tval n = readLine()!!.toLong()\n\tif (n > 0) println(((1 + n) * n / 2) % 2) else println(\"0\")\n}"}, {"source_code": "//package com.happypeople.codeforces.c1102\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\n\nfun main(args: Array) {\n try {\n A().run()\n } catch (e: Throwable) {\n A.log(\"\" + e)\n }\n}\n\nclass A {\n fun run() {\n val sc = Scanner(systemIn())\n val n = sc.nextInt()\n if(n==1 || n==2)\n println(\"1\")\n else if(n==3 || n==4)\n println(\"0\")\n else {\n val ans = ((n+1) / 2) % 2\n println(\"$ans\")\n }\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n var n = readLine()!!.toLong()\n\n if (n == 1L || n == 2L) {\n println(1)\n } else {\n\n if (n % 4L == 1L || n % 4 == 2L) {\n println(1)\n } else if (n % 4 == 0L || n % 4 == 3L) {\n println(0)\n }\n }\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n println(if (n % 4 == 3 || n % 4 == 0) 0 else 1)\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n println(if (n % 4 == 3 || n % 4 == 0) 0 else 1)\n}"}, {"source_code": "fun main() {\n val cases = intArrayOf(0, 1, 1, 0)\n println(cases[readLine()!!.toInt() % 4])\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toLong()\n print((n * (n + 1) / 2) % 2)\n}"}, {"source_code": "import java.util.*\nimport java.math.*\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\nfun main(args: Array){\n\tvar n = readInt();\n\tif(n%4 in 1..2) println(\"1\");\n\telse println(\"0\");\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.lang.Math.*\nimport java.util.*\n\nfun solve() {\n val n = sc!!.readLong();\n val sum = (1 + n) * n / 2;\n out!!.println(sum % 2)\n}\n\nvar sc : FastScanner? = null\nvar out : PrintWriter? = null\n\nfun init() {\n sc = FastScanner(System.`in`)\n out = PrintWriter(System.out)\n}\n\nfun main(args: Array) {\n init();\n solve();\n out!!.close();\n}\n\nclass FastScanner(s: InputStream) {\n val br = BufferedReader(InputStreamReader(s))\n var st = StringTokenizer(\"\")\n fun next(): String {\n if (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st.nextToken()\n }\n\n fun readInt() = next().toInt()\n fun readLong() = next().toLong()\n}"}, {"source_code": "fun main(arg: Array){\n\tval n = readLine()!!.toInt()\n\tval r = if ((n.rem(4)==0) or (n.rem(4)==3)) 0 else 1\n\tprintln(r)\n}"}, {"source_code": "import java.lang.Math.abs\nimport java.lang.Math.max\n\n\nfun printList(list: List ) {\n for(i in list){\n print(\"$i \")\n }\n print(\"\\n\")\n}\nfun main(args: Array) {\n var n = readLine()!!.toInt();\n if(n * (n + 1) % 4 == 0)\n println(0)\n else\n println(1)\n\n\n\n}\n\n\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val pw = PrintWriter(System.out)\n val n = sc.nextLong()\n val sum = n * (n + 1) / 2\n if (sum % 2 == 0L) {\n println(0)\n }else{\n println(1)\n }\n\n}\n\nclass FastScanner(s: InputStream) {\n val br = BufferedReader(InputStreamReader(s))\n var st = StringTokenizer(\"\")\n fun next(): String {\n if (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n\n}"}], "negative_code": [{"source_code": "import java.util.*\nimport kotlin.math.max\n\nval readQueue = ArrayDeque()\n\nfun getInput(): String {\n if (readQueue.isEmpty()) readLine()!!.split(' ', '\\n').let { readQueue.addAll(it) }\n return readQueue.pop()\n}\n\nfun getInt() = getInput().toInt()\nfun getDouble() = getInput().toDouble()\nfun getString() = getInput()\nfun getLong() = getInput().toLong()\n\nfun printv(v: Collection) {\n v.forEachIndexed { i, t ->\n if (i != 0) print(\" \")\n print(t)\n }\n println()\n}\n\nfun > lsort(v: MutableList) {\n v.sort()\n}\n\nfun > gsort(v: MutableList) {\n v.sortDescending()\n}\n\nfun mp(t: T, u: U) = Pair(t, u)\n\nfun ifloor(a: Int, b: Int) = if (a xor b > 0) a / b else (a - b + 1) / b\nfun iceil(a: Int, b: Int) = if (a xor b > 0) (a + b - 1) / b else a / b\nfun ifloor(a: Long, b: Long) = if (a xor b > 0) a / b else (a - b + 1) / b\nfun iceil(a: Long, b: Long) = if (a xor b > 0) (a + b - 1) / b else a / b\n\ntypealias ll = Long\ntypealias pii = Pair\ntypealias pll = Pair\n\nval MOD = 1000000007L\nval MAX = 2147483647L\n\nfun List.binarySearchWith(condition: (T) -> Boolean): Int {\n return binarySearch {\n if (condition(it)) 1\n else -1\n }.let { -(it + 1) }\n}\n\nfun List.lowerBound(i: Int): Int {\n return binarySearchWith { it >= i }\n}\n\nfun List.upperBound(i: Int): Int {\n return binarySearchWith { it > i }\n}\n\nfun main() {\n\n var n = getInt()\n if(n % 2 == 1) n -= 3;\n n /= 2;\n if(n % 2 == 1) println(1)\n else println(0)\n\n}"}, {"source_code": "fun main(args: Array){\n\tval n = readLine()!!.toInt()\n\tif (n > 0) println(((1 + n) * n / 2) % 2) else println(\"0\")\n}"}, {"source_code": "//package com.happypeople.codeforces.c1102\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\n\nfun main(args: Array) {\n try {\n A().run()\n } catch (e: Throwable) {\n A.log(\"\" + e)\n }\n}\n\nclass A {\n fun run() {\n val sc = Scanner(systemIn())\n val n = sc.nextInt()\n if(n==1 || n==2)\n println(\"1\")\n else if(n==3 || n==4)\n println(\"0\")\n else {\n val ans = if (((n / 2) % 2) == 0) 1 else 0\n println(\"$ans\")\n }\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}"}, {"source_code": "//package com.happypeople.codeforces.c1102\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\n\nfun main(args: Array) {\n try {\n A().run()\n } catch (e: Throwable) {\n A.log(\"\" + e)\n }\n}\n\nclass A {\n fun run() {\n val sc = Scanner(systemIn())\n val n = sc.nextInt()\n val ans = if (n == 3 || n == 4) 0 else 1\n println(\"$ans\")\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val n = readInt()\n print((n * (n + 1) / 2) % 2)\n}"}], "src_uid": "fa163c5b619d3892e33e1fb9c22043a9"} {"nl": {"description": "From beginning till end, this message has been waiting to be conveyed.For a given unordered multiset of n lowercase English letters (\"multi\" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation n - 1 times: Remove any two elements s and t from the set, and add their concatenation s + t to the set. The cost of such operation is defined to be , where f(s, c) denotes the number of times character c appears in string s.Given a non-negative integer k, construct any valid non-empty set of no more than 100 000 letters, such that the minimum accumulative cost of the whole process is exactly k. It can be shown that a solution always exists.", "input_spec": "The first and only line of input contains a non-negative integer k (0 ≤ k ≤ 100 000) — the required minimum cost.", "output_spec": "Output a non-empty string of no more than 100 000 lowercase English letters — any multiset satisfying the requirements, concatenated to be a string. Note that the printed string doesn't need to be the final concatenated string. It only needs to represent an unordered multiset of letters.", "sample_inputs": ["12", "3"], "sample_outputs": ["abababab", "codeforces"], "notes": "NoteFor the multiset {'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'}, one of the ways to complete the process is as follows: {\"ab\", \"a\", \"b\", \"a\", \"b\", \"a\", \"b\"}, with a cost of 0; {\"aba\", \"b\", \"a\", \"b\", \"a\", \"b\"}, with a cost of 1; {\"abab\", \"a\", \"b\", \"a\", \"b\"}, with a cost of 1; {\"abab\", \"ab\", \"a\", \"b\"}, with a cost of 0; {\"abab\", \"aba\", \"b\"}, with a cost of 1; {\"abab\", \"abab\"}, with a cost of 1; {\"abababab\"}, with a cost of 8. The total cost is 12, and it can be proved to be the minimum cost of the process."}, "positive_code": [{"source_code": "fun getN(input: Int): Int {\n val p: Double = (Math.sqrt(8.0 * input + 1) - 1.0) / 2.0\n return p.toInt() + 1\n}\n\nfun main(args: Array) {\n var k = readLine()?.toInt()!!\n var o = 'a'\n if (k == 0)\n print('a')\n else\n while (k != 0) {\n val p = getN(k)\n k -= ((p * (p - 1)) / 2)\n for (i in 1..p)\n print(o)\n o++\n }\n}"}], "negative_code": [{"source_code": "fun getN(input: Int): Int {\n val p: Double = (Math.sqrt(8.0 * input + 1) - 1.0) / 2.0\n return p.toInt() + 1\n}\n\nfun main(args: Array) {\n var k = readLine()?.toInt()!!\n var o = 'a'\n while (k != 0) {\n val p = getN(k)\n k -= ((p * (p - 1)) / 2)\n for (i in 1..p)\n print(o)\n o++\n }\n}"}], "src_uid": "b991c064562704b6106a6ff2a297e64a"} {"nl": {"description": "Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that.How many times can Artem give presents to Masha?", "input_spec": "The only line of the input contains a single integer n (1 ≤ n ≤ 109) — number of stones Artem received on his birthday.", "output_spec": "Print the maximum possible number of times Artem can give presents to Masha.", "sample_inputs": ["1", "2", "3", "4"], "sample_outputs": ["1", "1", "2", "3"], "notes": "NoteIn the first sample, Artem can only give 1 stone to Masha.In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again."}, "positive_code": [{"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n println(2*(n/3)+(n%3+1)/2)\n}"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val n = readInt()\n print(2 * (n / 3) + if (n % 3 == 0) 0 else 1)\n}"}], "negative_code": [], "src_uid": "a993069e35b35ae158d35d6fe166aaef"} {"nl": {"description": "Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.", "input_spec": "The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi, yi (1 ≤ xi, yi ≤ 6). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.", "output_spec": "Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print  - 1.", "sample_inputs": ["2\n4 2\n6 4", "1\n2 3", "3\n1 4\n2 3\n4 4"], "sample_outputs": ["0", "-1", "1"], "notes": "NoteIn the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8."}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.max\n\nfun main(args : Array) {\n Thread { run() }.start()\n}\n\nfun run() {\n\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n var up = 0\n var down = 0\n var q = false\n for (i in 0 until n) {\n val a = scanner.nextInt()\n val b = scanner.nextInt()\n up += a\n down += b\n if ((a % 2) != (b % 2))\n q = true\n }\n if (up % 2 == 0 && down % 2 == 0)\n println(0)\n else if (up % 2 == 1 && down % 2 == 1) {\n if (q)\n println(1)\n else\n println(-1)\n }\n else {\n println(-1)\n }\n\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\n\nfun IntArray.print() {\n println(Arrays.toString(this))\n}\n\nfun Array.print() {\n for (i in this)\n i.print()\n}"}, {"source_code": "import java.util.*\nval reader = Scanner(System.`in`)\nvar l = 0\nvar r = 0\nfun main(args: Array){\n val n = reader.nextInt()\n\n val arr = Array(n, { i -> Pair(reader.nextInt(),reader.nextInt()) })\n\n for(i in arr)\n {\n if(i.first % 2 != 0) l++\n if(i.second % 2 != 0) r++\n }\n\n if(l%2 == 0 && r%2 == 0)\n {\n print(0)\n }\n else if(l%2 == 0 || r%2 == 0)\n {\n print(-1)\n }\n else\n {\n for(i in arr)\n {\n if((i.first % 2 == 0 && i.second % 2 != 0) || (i.first % 2 != 0 && i.second % 2 == 0))\n {\n print(1)\n return\n }\n }\n print(-1)\n }\n}\n"}, {"source_code": "\nfun main() {\n val size = readLine()?.toInt() ?: return\n var swappableCount = 0\n var leftOdd = 0\n var rightOdd = 0\n for (i in 0.until(size)) {\n val values = readLine()?.split(' ') ?: return\n val left = values[0].toInt() % 2 == 0\n val right = values[1].toInt() % 2 == 0\n if (!left) {\n leftOdd++\n }\n if (!right) {\n rightOdd++\n }\n if (left != right) {\n swappableCount++\n }\n }\n // both even\n if (leftOdd % 2 == 0 && rightOdd % 2 == 0) {\n println(0)\n return\n }\n // odd and equal\n if (leftOdd == rightOdd) {\n if (swappableCount > 0) {\n println(1)\n return\n }\n else{\n println(-1)\n return\n }\n }\n if (leftOdd % 2 == 1 && rightOdd % 2 == 1) {\n println(1)\n return\n }\n else{\n println(-1)\n return\n }\n}\n"}], "negative_code": [{"source_code": "\nfun main() {\n val size = readLine()?.toInt() ?: return\n var swappableCount = 0\n var leftOdd = 0\n var rightOdd = 0\n for (i in 0.until(size)) {\n val values = readLine()?.split(' ') ?: return\n val left = values[0].toInt() % 2 == 0\n val right = values[1].toInt() % 2 == 0\n if (!left) {\n leftOdd++\n }\n if (!right) {\n rightOdd++\n }\n if (left != right) {\n swappableCount++\n }\n }\n // both even\n if (leftOdd % 2 == 0 && rightOdd % 2 == 0) {\n println(0)\n return\n }\n // odd and equal\n if (leftOdd == rightOdd) {\n if (swappableCount > 0) {\n println(1)\n return\n }\n }\n val diff = Math.abs(leftOdd - rightOdd)\n if (diff % 2 != 0) {\n println(-1)\n return\n }\n val swapCount = diff / 2\n if (swappableCount >= swapCount) {\n println(swapCount)\n return\n }\n println(-1)\n}\n"}, {"source_code": "\nfun main() {\n val size = readLine()?.toInt() ?: return\n var swappableCount = 0\n var leftOdd = 0\n var rightOdd = 0\n for (i in 0.until(size)) {\n val values = readLine()?.split(' ') ?: return\n val left = values[0].toInt() % 2 == 0\n val right = values[1].toInt() % 2 == 0\n if (!left) {\n leftOdd++\n }\n if (!right) {\n rightOdd++\n }\n if (left != right) {\n swappableCount++\n }\n }\n // both even\n if (leftOdd % 2 == 0 && rightOdd % 2 == 0) {\n println(0)\n return\n }\n // odd and equal\n if (leftOdd == rightOdd) {\n if (swappableCount > 0) {\n println(1)\n return\n }\n else{\n println(-1)\n return\n }\n }\n val diff = Math.abs(leftOdd - rightOdd)\n if (diff % 2 != 0) {\n println(-1)\n return\n }\n val swapCount = diff / 2\n if (swappableCount >= swapCount) {\n println(swapCount)\n return\n }\n println(-1)\n}\n"}], "src_uid": "f9bc04aed2b84c7dd288749ac264bb43"} {"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": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n var (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }.sorted()\n var ans = 0\n for (i in 0..1000){\n for (j in 0..1000){\n if (i*i+j==m&&i+j*j==n) ans++\n }\n }\n println(ans)\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n var (n, m) = readLine()!!.split(\" \").map { it.toLong() }\n var a = 0\n var ans = 0\n while (a*a<=n){\n var b = n-a*a\n if (a+b*b==m){\n ans++\n }\n a++\n }\n println(ans)\n}"}, {"source_code": "fun main() {\n val (n, m) = readLine()!!.split(\" \").map { it.toInt() }\n var ans = 0\n var a = -1\n while (++a * a <= n) {\n val b = n - a * a\n if (a + b * b == m) ans++\n }\n println(ans)\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (n, m) = readInts()\n var sol = 0\n var a = -1\n while (++a * a <= n) {\n val b = n - a * a\n if (a + b * b == m) sol++\n }\n print(sol)\n}"}, {"source_code": "import java.util.*\nimport java.math.*\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\nfun main(args: Array){\n\tvar inp = readInts();\n\tvar n = inp[0];\n\tvar m = inp[1];\n\tvar ans = 0;\n\tfor(a in 0..100){\n\t\tfor(b in 0..100){\n\t\t\tif(b + a*a == n && a + b*b == m) ans++;\n\t\t}\n\t}\n\tprintln(ans);\n}\n"}], "negative_code": [], "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd"} {"nl": {"description": "You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1, 2).Lara has already moved to a neighbouring cell k times. Can you determine her current position?", "input_spec": "The only line contains three integers n, m and k (2 ≤ n, m ≤ 109, n is always even, 0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!", "output_spec": "Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.", "sample_inputs": ["4 3 0", "4 3 11", "4 3 7"], "sample_outputs": ["1 1", "1 2", "3 2"], "notes": "NoteHere is her path on matrix 4 by 3: "}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.HashMap\nimport kotlin.math.min\n\nfun main(args: Array)\n = Thread { run() }.start()\n\nfun run() {\n\n val scanner = Scanner(System.`in`)\n val n = scanner.nextLong()\n val m = scanner.nextLong()\n var q = scanner.nextLong()\n if (q < n) {\n println(\"${q + 1} 1\")\n return\n }\n q -= n;\n val r = n - (q / (m - 1))\n if ((n - r) % 2 == 0L)\n println(\"$r ${2 + (q % (m - 1))}\")\n else\n println(\"$r ${m - (q % (m - 1))}\")\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\nclass Pair(var a: Int, var b: Int): Comparable {\n override fun compareTo(other: Pair): Int {\n return a - other.a\n }\n}"}, {"source_code": "\nimport java.util.*\n\nfun main(args: Array) {\n with(Scanner(System.`in`)) {\n val n = nextLong()\n val m = nextLong()\n val k = nextLong()\n val r = k % (m * n)\n if (r < n) {\n println(\"${r+1} 1\")\n } else {\n val r0 = r - n\n val t0 = r0 / (m-1)\n val t1 = r0 % (m-1)\n if (t0 % 2 == 0L) {\n println(\"${n-t0} ${2+t1}\")\n } else {\n println(\"${n-t0} ${1+m-1-t1}\")\n }\n }\n }\n}"}], "negative_code": [{"source_code": "\nimport java.util.*\n\nfun main(args: Array) {\n with(Scanner(System.`in`)) {\n val n = nextLong()\n val m = nextLong()\n val k = nextLong()\n val r = k % (m * n)\n if (r < n) {\n println(\"${r+1} 1\")\n } else {\n val r0 = r - n\n val t0 = r0 / (m-1)\n val t1 = r0 % (m-1)\n if (t0 % 2 == 0L) {\n println(\"${n-t0} ${1+t1}\")\n } else {\n println(\"${n-t0} ${1+m-1-t1}\")\n }\n }\n }\n}"}], "src_uid": "e88bb7621c7124c54e75109a00f96301"} {"nl": {"description": "Madoka wants to enter to \"Novosibirsk State University\", but in the entrance exam she came across a very difficult task:Given an integer $$$n$$$, it is required to calculate $$$\\sum{\\operatorname{lcm}(c, \\gcd(a, b))}$$$, for all triples of positive integers $$$(a, b, c)$$$, where $$$a + b + c = n$$$.In this problem $$$\\gcd(x, y)$$$ denotes the greatest common divisor of $$$x$$$ and $$$y$$$, and $$$\\operatorname{lcm}(x, y)$$$ denotes the least common multiple of $$$x$$$ and $$$y$$$.Solve this problem for Madoka and help her to enter to the best university!", "input_spec": "The first and the only line contains a single integer $$$n$$$ ($$$3 \\le n \\le 10^5$$$).", "output_spec": "Print exactly one interger — $$$\\sum{\\operatorname{lcm}(c, \\gcd(a, b))}$$$. Since the answer can be very large, then output it modulo $$$10^9 + 7$$$.", "sample_inputs": ["3", "5", "69228"], "sample_outputs": ["1", "11", "778304278"], "notes": "NoteIn the first example, there is only one suitable triple $$$(1, 1, 1)$$$. So the answer is $$$\\operatorname{lcm}(1, \\gcd(1, 1)) = \\operatorname{lcm}(1, 1) = 1$$$.In the second example, $$$\\operatorname{lcm}(1, \\gcd(3, 1)) + \\operatorname{lcm}(1, \\gcd(2, 2)) + \\operatorname{lcm}(1, \\gcd(1, 3)) + \\operatorname{lcm}(2, \\gcd(2, 1)) + \\operatorname{lcm}(2, \\gcd(1, 2)) + \\operatorname{lcm}(3, \\gcd(1, 1)) = \\operatorname{lcm}(1, 1) + \\operatorname{lcm}(1, 2) + \\operatorname{lcm}(1, 1) + \\operatorname{lcm}(2, 1) + \\operatorname{lcm}(2, 1) + \\operatorname{lcm}(3, 1) = 1 + 2 + 1 + 2 + 2 + 3 = 11$$$"}, "positive_code": [{"source_code": "// 2022.09.02 at 15:52:32 BST\r\nimport java.io.BufferedInputStream\r\nimport java.io.File\r\nimport java.io.PrintWriter\r\nimport kotlin.math.ln\r\nimport kotlin.system.measureTimeMillis\r\n\r\n// 1. Modded\r\nconst val p = 1000000007L\r\nconst val pI = p.toInt()\r\nfun Int.adjust():Int{ if(this >= pI){ return this - pI }else if (this < 0){ return this + pI };return this }\r\nfun Int.snap():Int{ if(this >= pI){return this - pI} else return this}\r\ninfix fun Int.modM(b:Int):Int{ return ((this.toLong() * b) % pI).toInt() }\r\ninfix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }\r\ninfix fun Int.modMinus(b:Int):Int{ val ans = this - b;return if(ans < 0) ans + pI else ans }\r\nfun Int.inverse():Int = intPow(this,pI-2,pI)\r\ninfix fun Int.modDivide(b:Int):Int{ return this modM (b.inverse()) }\r\nfun intPow(x:Int,e:Int,m:Int):Int{\r\n var X = x ; var E =e ; var Y = 1\r\n while(E > 0){\r\n if(E and 1 == 0){\r\n X = ((1L * X * X) % m).toInt()\r\n E = E shr 1\r\n }else{\r\n Y = ((1L * X * Y) % m).toInt()\r\n E -= 1\r\n }\r\n }\r\n return Y\r\n}\r\n// 2. DP initial values\r\nconst val plarge = 1_000_000_727\r\nconst val nlarge = -plarge\r\nconst val phuge = 2_727_000_000_000_000_000L\r\nconst val nhuge = -phuge\r\n// 3. convenience conversions\r\nval Boolean.chi:Int get() = if(this) 1 else 0 //characteristic function\r\nval BooleanArray.chiarray:IntArray get() = IntArray(this.size){this[it].chi}\r\nval Char.code :Int get() = this.toInt() - 'a'.toInt()\r\n//3. hard to write stuff\r\nfun IntArray.put(i:Int,v:Int){ this[i] = (this[i] + v).adjust() }\r\nval mint:MutableList get() = mutableListOf()\r\nval mong:MutableList get() = mutableListOf()\r\n//4. more outputs\r\nfun List.conca():String = this.joinToString(\"\")\r\nval CharArray.conca :String get() = this.joinToString(\"\")\r\nval IntArray.conca :String get() = this.joinToString(\" \")\r\n@JvmName(\"concaInt\")\r\nfun List.conca():String = this.joinToString(\" \")\r\nval LongArray.conca:String get() = this.joinToString(\" \")\r\n@JvmName(\"concaLong\")\r\nfun List.conca():String = this.joinToString(\" \")\r\n//5. Pair of ints\r\nconst val longmask = (1L shl 32) - 1\r\nfun makepair(a:Int, b:Int):Long = (a.toLong() shl 32) xor (longmask and b.toLong())\r\nval Long.first get() = (this ushr 32).toInt()\r\nval Long.second get() = this.toInt()\r\n//6. strings\r\nval String.size get() = this.length\r\nconst val randCount = 100\r\n//7. bits\r\nfun Int.has(i:Int):Boolean = (this and (1 shl i) != 0)\r\nfun Long.has(i:Int):Boolean = (this and (1L shl i) != 0L)\r\n//8 TIME\r\ninline fun TIME(f:()->Unit){\r\n val t = measureTimeMillis(){\r\n f()\r\n }\r\n println(\"$t ms\")\r\n}\r\n//9.ordered pair\r\nfun order(a:Int, b:Int):Pair{\r\n return Pair(minOf(a,b), maxOf(a,b))\r\n}\r\nconst val interactive = false\r\nobject Reader{\r\n private const val BS = 1 shl 16\r\n private const val NC = 0.toChar()\r\n private val buf = ByteArray(BS)\r\n private var bId = 0\r\n private var size = 0\r\n private var c = NC\r\n\r\n var warningActive = true\r\n var fakein = StringBuilder()\r\n\r\n private var IN: BufferedInputStream = BufferedInputStream(System.`in`, BS)\r\n val OUT: PrintWriter = PrintWriter(System.out)\r\n\r\n private val char: Char\r\n get() {\r\n if(interactive){\r\n return System.`in`.read().toChar()\r\n }\r\n while (bId == size) {\r\n size = IN.read(buf) // no need for checked exceptions\r\n if (size == -1) return NC\r\n bId = 0\r\n }\r\n return buf[bId++].toChar()\r\n }\r\n\r\n fun nextInt(): Int {\r\n var neg = false\r\n if (c == NC) c = char\r\n while (c < '0' || c > '9') {\r\n if (c == '-') neg = true\r\n c = char\r\n }\r\n var res = 0\r\n while (c in '0'..'9') {\r\n res = (res shl 3) + (res shl 1) + (c - '0')\r\n c = char\r\n }\r\n return if (neg) -res else res\r\n }\r\n fun nextLong(): Long {\r\n var neg = false\r\n if (c == NC) c = char\r\n while (c < '0' || c > '9') {\r\n if (c == '-') neg = true\r\n c = char\r\n }\r\n var res = 0L\r\n while (c in '0'..'9') {\r\n res = (res shl 3) + (res shl 1) + (c - '0')\r\n c = char\r\n }\r\n return if (neg) -res else res\r\n }\r\n fun nextString():String{\r\n val ret = StringBuilder()\r\n while (true){\r\n c = char\r\n if(!isWhitespace(c)){ break}\r\n }\r\n ret.append(c)\r\n while (true){\r\n c = char\r\n if(isWhitespace(c)){ break}\r\n ret.append(c)\r\n }\r\n return ret.toString()\r\n }\r\n fun isWhitespace(c:Char):Boolean{\r\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t'\r\n }\r\n fun rerouteInput(){\r\n if(warningActive){\r\n put(\"Custom test enabled\")\r\n println(\"Custom test enabled\")\r\n warningActive = false\r\n }\r\n val S = fakein.toString()\r\n println(\"New Case \")\r\n println(S.take(80))\r\n println(\"...\")\r\n fakein.clear()\r\n IN = BufferedInputStream(S.byteInputStream(),BS)\r\n }\r\n fun flush(){\r\n OUT.flush()\r\n }\r\n fun takeFile(name:String){\r\n IN = BufferedInputStream(File(name).inputStream(),BS)\r\n }\r\n}\r\nfun put(aa:Any){\r\n Reader.OUT.println(aa)\r\n if(interactive){ Reader.flush()}\r\n}\r\nfun done(){ Reader.OUT.close() }\r\nfun share(aa:Any){\r\n if(aa is IntArray){Reader.fakein.append(aa.joinToString(\" \"))}\r\n else if(aa is LongArray){Reader.fakein.append(aa.joinToString(\" \"))}\r\n else if(aa is List<*>){Reader.fakein.append(aa.toString())}\r\n else{Reader.fakein.append(aa.toString())}\r\n Reader.fakein.append(\"\\n\")\r\n}\r\n\r\nval getintfast:Int get() = Reader.nextInt()\r\nval getint:Int get(){ val ans = getlong ; if(ans > Int.MAX_VALUE) IntArray(1000000000); return ans.toInt() }\r\nval getlong:Long get() = Reader.nextLong()\r\nval getstr:String get() = Reader.nextString()\r\nfun getline(n:Int):IntArray{\r\n return IntArray(n){getint}\r\n}\r\nfun getlineL(n:Int):LongArray{\r\n return LongArray(n){getlong}\r\n}\r\nvar dmark = -1\r\ninfix fun Any.dei(a:Any){\r\n dmark++\r\n var str = \"<${dmark}> \"\r\n debug()\r\n if(this is String){ str += this\r\n }else if(this is Int){ str += this.toString()\r\n }else if(this is Long){ str += this.toString()\r\n }else{ str += this.toString()}\r\n if(a is List<*>){ println(\"$str : ${a.joinToString(\" \")}\")\r\n }else if(a is IntArray){ println(\"$str : ${a.joinToString(\" \")}\")\r\n }else if(a is LongArray){ println(\"$str : ${a.joinToString(\" \")}\")\r\n }else if(a is BooleanArray){ println(\"$str :${a.map{if(it)'1' else '0'}.joinToString(\" \")}\")\r\n }else if(a is Array<*>){\r\n println(\"$str : \")\r\n for(c in a){if(c is IntArray){println(c.joinToString(\" \"))}\r\n else if(c is LongArray){println(c.joinToString(\" \"))}\r\n else if(c is BooleanArray){println(c.map { if(it) '1' else '0' }.joinToString(\"\"))\r\n }\r\n }\r\n println()\r\n }else{ println(\"$str : $a\")\r\n }\r\n}\r\nval just = \" \"\r\nfun crash(){\r\n throw Exception(\"Bad programme\")}\r\nfun assert(a:Boolean){\r\n if(!a){\r\n throw Exception(\"Failed Assertion\")\r\n }}\r\nenum class solveMode {\r\n real, rand, tc\r\n}\r\nobject solve{\r\n var mode:solveMode = solveMode.real\r\n var tcNum:Int = 0\r\n var rand:()->Unit = {}\r\n var TC:MutableMapUnit> = mutableMapOf()\r\n var tn:Long = 0\r\n fun cases(onecase:()->Unit){\r\n val t = if(mode == solveMode.real){if(singleCase) 1 else getint} else if(mode == solveMode.tc){1 } else randCount\r\n if(pI != 998_244_353 && pI != 1_000_000_007){\r\n throw Exception(\"Not usual primes!\")\r\n }\r\n if(t == 1 && mode != solveMode.real){\r\n tn = System.currentTimeMillis()\r\n }\r\n repeat(t){\r\n if(mode == solveMode.tc){\r\n TC[tcNum]?.let { it() }\r\n Reader.rerouteInput()\r\n }else if(mode == solveMode.rand){\r\n rand()\r\n Reader.rerouteInput()\r\n }\r\n onecase()\r\n }\r\n if(t == 1 && mode != solveMode.real){\r\n val dt = System.currentTimeMillis() - tn\r\n println(\"Time $dt ms \")\r\n }\r\n }\r\n inline fun singleCase(a:solve.()->Unit){\r\n val t = if(mode != solveMode.rand){1} else randCount\r\n repeat(t) { a() }\r\n }\r\n fun rand(a:()->Unit){\r\n this.rand = a\r\n }\r\n fun tc(id:Int = 0,a:()->Unit){\r\n TC[id] = a\r\n }\r\n fun usetc(a:Int = 0 ){\r\n this.tcNum = a\r\n this.mode = solveMode.tc\r\n }\r\n fun userand(){\r\n this.mode = solveMode.rand\r\n }\r\n}\r\nfun debug(){}\r\n\r\n\r\nobject sieve{\r\n\r\n const val sieveMx = 200005\r\n val primeOf = IntArray(sieveMx + 1)\r\n var primeCounter = 0\r\n val primeUpperBound = maxOf(25,(sieveMx.toDouble()/(ln(sieveMx.toDouble()) -4)).toInt() +3)\r\n val primes = IntArray(primeUpperBound)\r\n var sieveCalculated = false\r\n val nextPrime = IntArray(sieveMx+1)\r\n val nextPrimePower = IntArray(sieveMx+1)\r\n val afterPrimePowerDivison = IntArray(sieveMx+1)\r\n var mobius = IntArray(0)\r\n\r\n var factors:List> = mutableListOf()\r\n\r\n fun calculateSieveFast(){\r\n if(sieveCalculated){\r\n return\r\n }\r\n sieveCalculated = true\r\n for(i in 2..sieveMx){\r\n if(primeOf[i] == 0 ){\r\n primeOf[i] = i\r\n primes[primeCounter] = i\r\n primeCounter += 1\r\n }\r\n for(j in 0 until primeCounter){\r\n val p = primes[j]\r\n val pd = p * i\r\n if(p <= i && pd <= sieveMx){\r\n primeOf[pd] = p\r\n }else{\r\n break\r\n }\r\n }\r\n }\r\n }\r\n fun preparePrimePower(){\r\n nextPrime[1] = -1\r\n nextPrimePower[1] = -1\r\n afterPrimePowerDivison[1] = 1\r\n for(i in 2..sieveMx){\r\n val p = primeOf[i]\r\n val new = i / p\r\n nextPrime[i] = p\r\n if(nextPrime[new] == p){\r\n nextPrimePower[i] = nextPrimePower[new]\r\n afterPrimePowerDivison[i] = afterPrimePowerDivison[new]\r\n }else{\r\n afterPrimePowerDivison[i] = new\r\n }\r\n nextPrimePower[i] += 1\r\n }\r\n }\r\n fun primeID():Pair{\r\n assert(sieveCalculated)\r\n var now =0\r\n val primes = IntArray(primeCounter)\r\n val id = IntArray(sieveMx) {\r\n if (it > 0 && primeOf[it] == it) {\r\n primes[now] = it\r\n return@IntArray now++\r\n } else -1}\r\n return Pair(primes,id)\r\n }\r\n fun prepareFactors(){\r\n // 700ms in 1M\r\n // shoudl not be used for 1M\r\n // 200ms codeforces for 200k\r\n factors = List(sieveMx + 1){ mutableListOf()}\r\n factors[1].add(1)\r\n\r\n for(i in 2..sieveMx){\r\n val p = nextPrime[i]\r\n val a = nextPrimePower[i]\r\n val old = afterPrimePowerDivison[i]\r\n\r\n var here = 1\r\n repeat(a+1){\r\n for(c in factors[old]){\r\n factors[i].add(c * here )\r\n }\r\n here *= p\r\n }\r\n// factors[1].ad\r\n// factors[i].addAll(i.factors())\r\n }\r\n }\r\n fun calculateMobius(){\r\n assert(sieveCalculated)\r\n mobius = IntArray(sieveMx + 1)\r\n mobius[1] = 1\r\n for(i in 2..sieveMx){\r\n val p = primeOf[i]\r\n if(p == primeOf[i/p]){\r\n mobius[i] = 0\r\n }else{\r\n mobius[i] = -1 * mobius[i/p]\r\n }\r\n }\r\n }\r\n}\r\ninline fun Int.eachPrimePower(act:(Int,Int)->Unit){\r\n assert(sieve.sieveCalculated)\r\n var here = this\r\n while(here > 1){\r\n act(sieve.nextPrime[here], sieve.nextPrimePower[here])\r\n here = sieve.afterPrimePowerDivison[here]\r\n }\r\n}\r\nfun Int.factors():List{\r\n val ret = mutableListOf(1)\r\n this.eachPrimePower { p, e ->\r\n val s = ret.toList()\r\n var now = 1\r\n repeat(e){\r\n now *= p\r\n ret.addAll(s.map{it * now})\r\n }\r\n }\r\n return ret\r\n}\r\nfun totient(a:Int):Int{\r\n var ret = a\r\n a.eachPrimePower{\r\n p, _ ->\r\n ret /= p\r\n ret *= (p-1)\r\n }\r\n return ret\r\n}\r\nfun Int.numOfDivisors():Int{\r\n var ret = 1\r\n this.eachPrimePower { _, e -> ret *= (e+1) }\r\n return ret\r\n}\r\nfun Int.factorLook():List{\r\n return sieve.factors[this]\r\n}\r\n\r\n\r\n\r\n\r\ntailrec fun gcd(a: Int, b: Int): Int {\r\n if(b == 0) return a\r\n return if (a % b == 0) Math.abs(b) else gcd(b, a % b)\r\n}\r\ntailrec fun gcd(a: Long, b: Long): Long {\r\n if(b == 0L) return a\r\n return if (a % b == 0L) Math.abs(b) else gcd(b, a % b)\r\n}\r\n\r\nfun lcm(a:Long, b:Long):Long{\r\n return a * b / (gcd(a,b))\r\n}\r\nconst val singleCase = true\r\nfun main(){\r\n sieve.calculateSieveFast()\r\n sieve.preparePrimePower()\r\n sieve.prepareFactors()\r\n solve.cases{\r\n val n = getint\r\n\r\n val phi = IntArray(n+1){if(it == 0) 0 else totient(it)}\r\n\r\n\r\n var ret = 0\r\n for(c in 1..n-2){\r\n val ab = n - c\r\n for(f in ab.factorLook()){\r\n if(f == ab) continue\r\n val options = phi[ab / f]\r\n\r\n// ab dei \"$f $options\"\r\n val extra = (lcm(c.toLong(),f.toLong()) % pI).toInt()\r\n ret = ret modPlus (extra modM options)\r\n }\r\n }\r\n\r\n put(ret)\r\n\r\n\r\n\r\n }\r\n done()\r\n}\r\n\r\n\r\n\r\n"}], "negative_code": [], "src_uid": "c3694a6ff95c64bef8cbe8834c3fd6cb"} {"nl": {"description": "A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.The tournament takes place in the following way (below, m is the number of the participants of the current round): let k be the maximal power of the number 2 such that k ≤ m, k participants compete in the current round and a half of them passes to the next round, the other m - k participants pass to the next round directly, when only one participant remains, the tournament finishes. Each match requires b bottles of water for each participant and one bottle for the judge. Besides p towels are given to each participant for the whole tournament.Find the number of bottles and towels needed for the tournament.Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).", "input_spec": "The only line contains three integers n, b, p (1 ≤ n, b, p ≤ 500) — the number of participants and the parameters described in the problem statement.", "output_spec": "Print two integers x and y — the number of bottles and towels need for the tournament.", "sample_inputs": ["5 2 3", "8 2 4"], "sample_outputs": ["20 15", "35 32"], "notes": "NoteIn the first example will be three rounds: in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), in the second round will be only one match, so we need another 5 bottles of water, in the third round will also be only one match, so we need another 5 bottles of water. So in total we need 20 bottles of water.In the second example no participant will move on to some round directly."}, "positive_code": [{"source_code": "\nfun main() {\n solve()\n}\n\nprivate fun solve() {\n var (n, b, p) = readInts()\n\n val noOfTowelRequired = p * n\n\n var totalBottlesRequired = 0\n while (n > 1) {\n\n var m = 1\n\n for (i in 0..n) {\n val result = m * 2\n if (result > n) {\n break\n } else {\n m = result\n }\n }\n totalBottlesRequired += (b * m) + (m / 2)\n n -= m / 2\n }\n println(\"$totalBottlesRequired $noOfTowelRequired\")\n}\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // li\nprivate fun readLongs() = readStrings().map { it.toLong() } // li"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n var (numParticipants, numBottles, numTowels) = readInts()\n val totalTowels = numParticipants * numTowels\n var totalBottles = 0\n while(numParticipants > 1) {\n var playing = 2\n while (playing * 2 <= numParticipants) playing *= 2\n val matches = playing / 2\n totalBottles += matches * (2 * numBottles + 1)\n numParticipants = matches + numParticipants - playing\n }\n print(\"$totalBottles $totalTowels\")\n}"}], "negative_code": [], "src_uid": "eb815f35e9f29793a120d120968cfe34"} {"nl": {"description": "On her way to programming school tiger Dasha faced her first test — a huge staircase! The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers. You need to check whether there is an interval of steps from the l-th to the r-th (1 ≤ l ≤ r), for which values that Dasha has found are correct.", "input_spec": "In the only line you are given two integers a, b (0 ≤ a, b ≤ 100) — the number of even and odd steps, accordingly.", "output_spec": "In the only line print \"YES\", if the interval of steps described above exists, and \"NO\" otherwise.", "sample_inputs": ["2 3", "3 1"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5."}, "positive_code": [{"source_code": "import kotlin.math.abs\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n var (a, b) = r.readLine()!!.split(\" \").map { it.toLong() }\n if (abs(a-b)<=1&&a+b>=1) println(\"YES\") else println(\"NO\")\n}"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n val even = reader.nextInt()\n val odd = reader.nextInt()\n if (even == 0 && odd == 0) {\n println(\"NO\")\n return\n }\n if (Math.abs(even - odd) > 1) println(\"NO\") else println(\"YES\")\n}\n"}, {"source_code": "//package codeforces.round394\n\nimport java.io.PrintWriter\nimport java.util.*\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val `in` = Scanner(inputStream)\n val out = PrintWriter(outputStream)\n solve(`in`, out)\n out.close()\n}\n\nprivate fun solve(scanner: Scanner, out: PrintWriter) {\n val even = scanner.nextInt()\n val odd = scanner.nextInt()\n\n if (Math.abs(even - odd) > 1 || (even == 0) && (odd == 0)) {\n out.println(\"NO\")\n } else {\n out.println(\"YES\")\n }\n}\n\n\n"}, {"source_code": "fun main(vararg args: String) {\n val (a, b) = readLine()!!.split(' ').map(String::toInt)\n println(if (!(a == 0 && b == 0) && Math.abs(a - b) <= 1) \"YES\" else \"NO\")\n}\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n val a = input.nextInt()\n val b = input.nextInt()\n\n if((a == b || a - 1 == b || b - 1 == a) && (a != 0 || b != 0)) {\n print(\"YES\")\n } else {\n print(\"NO\")\n }\n}"}, {"source_code": "import java.util.*\nimport java.io.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val a = sc.nextInt()\n val b = sc.nextInt()\n for (i in 1..200) {\n for (j in i..200) {\n var even = 0\n var odd = 0\n for (k in i..j) {\n if (k % 2 == 0) even++ else odd++\n }\n if (even == a && odd == b) {\n println(\"YES\")\n return;\n }\n }\n }\n println(\"NO\")\n}"}, {"source_code": "import kotlin.math.abs\n\nfun main() {\n var (a, b) = readLine()!!.split(' ').map { it.toInt() }\n if (a==b && a==0){\n println(\"NO\")\n return\n }\n var ans = abs(a-b)\n if (ans<=1){\n println(\"YES\")\n }else{\n println(\"NO\")\n }\n}"}, {"source_code": "fun main() {\n val (a, b) = readLine()!!.split(\" \").map(String::toInt)\n if (a == 0 && b == 0) print(\"NO\") else print(if (a - b in -1..1) \"YES\" else \"NO\")\n}"}], "negative_code": [{"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n var (a, b) = r.readLine()!!.split(\" \").map { it.toLong() }\n if (b-a<=1) println(\"YES\") else println(\"NO\")\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n var (a, b) = r.readLine()!!.split(\" \").map { it.toLong() }\n if (b-a<=1&&b>=a) println(\"YES\") else println(\"NO\")\n}"}, {"source_code": "import kotlin.math.abs\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n var (a, b) = r.readLine()!!.split(\" \").map { it.toLong() }\n if (abs(a-b)<=1) println(\"YES\") else println(\"NO\")\n}\n"}, {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n val even = reader.nextInt()\n val odd = reader.nextInt()\n if (Math.abs(even - odd) > 1) println(\"NO\") else println(\"YES\")\n}\n"}, {"source_code": "fun main(vararg args: String) {\n val (a, b) = readLine()!!.split(' ').map(String::toInt)\n println(if (Math.abs(a - b) <= 1 && !(a in 0..1 && b == 0)) \"YES\" else \"NO\")\n}\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n val a = input.nextInt()\n val b = input.nextInt()\n\n if(a == b || a - 1 == b || b - 1 == a) {\n print(\"YES\")\n } else {\n print(\"NO\")\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n val a = input.nextInt()\n val b = input.nextInt()\n\n if((a == b || a - 1 == b || b - 1 == a) && (a != 0 && b != 0)) {\n print(\"YES\")\n } else {\n print(\"NO\")\n }\n}"}, {"source_code": "import kotlin.math.abs\n\nfun main() {\n var (a, b) = readLine()!!.split(' ').map { it.toInt() }\n var ans = abs(a-b)\n if (ans<=1){\n println(\"YES\")\n }else{\n println(\"NO\")\n }\n}"}, {"source_code": "fun main() {\n val (a, b) = readLine()!!.split(\" \").map(String::toInt)\n print(if (a - b in -1..1) \"YES\" else \"NO\")\n}"}], "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037"} {"nl": {"description": "Ayoub had an array $$$a$$$ of integers of size $$$n$$$ and this array had two interesting properties: All the integers in the array were between $$$l$$$ and $$$r$$$ (inclusive). The sum of all the elements was divisible by $$$3$$$. Unfortunately, Ayoub has lost his array, but he remembers the size of the array $$$n$$$ and the numbers $$$l$$$ and $$$r$$$, so he asked you to find the number of ways to restore the array. Since the answer could be very large, print it modulo $$$10^9 + 7$$$ (i.e. the remainder when dividing by $$$10^9 + 7$$$). In case there are no satisfying arrays (Ayoub has a wrong memory), print $$$0$$$.", "input_spec": "The first and only line contains three integers $$$n$$$, $$$l$$$ and $$$r$$$ ($$$1 \\le n \\le 2 \\cdot 10^5 , 1 \\le l \\le r \\le 10^9$$$) — the size of the lost array and the range of numbers in the array.", "output_spec": "Print the remainder when dividing by $$$10^9 + 7$$$ the number of ways to restore the array.", "sample_inputs": ["2 1 3", "3 2 2", "9 9 99"], "sample_outputs": ["3", "1", "711426616"], "notes": "NoteIn the first example, the possible arrays are : $$$[1,2], [2,1], [3, 3]$$$.In the second example, the only possible array is $$$[2, 2, 2]$$$."}, "positive_code": [{"source_code": "import java.lang.ArithmeticException\n\nfun main() {\n val (n, l, r) = readInts()\n\n // number of possible elements for each modulo 3\n val ele = run {\n val sz = r - l + 1\n val quot = sz / 3\n val rem = sz - quot * 3\n IntArray(3) {\n quot + if((it - l) umod 3 < rem) 1 else 0\n }\n }\n\n\n var d = List(3) { ele[it].toModInt() }\n\n repeat(n-1) {\n val nd = List(3) { i ->\n d[i] * ele[0] +\n d[(i+1)%3] * ele[2] +\n d[(i+2)%3] * ele[1]\n }\n d = nd\n }\n\n println(d[0])\n}\n\ninfix fun Int.umod(base: Int) =\n (this % base).let { if(it >= 0) it else it + base }\n\ninfix fun Long.umod(base: Long) =\n (this % base).let { if(it >= 0) it else it + base }\n\ninfix fun Long.umod(base: Int) =\n (this % base).let { if(it >= 0) it else it + base }\n\nfun Int.modInv(base: Int): Int {\n var s = 0\n var os = 1\n var r = base\n var or = this\n\n while(r != 0) {\n val q = or / r\n or = r.also { r = or - q * r }\n os = s.also { s = os - q * s }\n }\n\n return if(or != 1) throw ArithmeticException(\"$this has no modulo inverse in base $base\")\n else os.let { if(it >= 0) it else it + base }\n}\n\n/** modint inline class, requires hardcoded mod base **/\nconst val MODBASE = 1_000_000_007\n\n@Suppress(\"DEPRECATION\")\ninline fun Int.toModInt() = ModInt(this umod MODBASE)\n@Suppress(\"DEPRECATION\")\ninline fun Long.toModInt() = ModInt((this umod MODBASE).toInt())\n\ninline class ModInt\n@Deprecated(\"use toModInt instead\") constructor(val int: Int) {\n operator fun plus(other: ModInt) = plus(other.int) // MODBASE < 2^30\n operator fun plus(other: Int) = (int + other).toModInt() // careful of possible overflow\n operator fun inc() = plus(1)\n\n operator fun minus(other: ModInt) = minus(other.int)\n operator fun minus(other: Int) = (int - other).toModInt()\n operator fun dec() = minus(1)\n\n operator fun times(other: ModInt) = times(other.int)\n operator fun times(other: Int) = (int.toLong() * other).toModInt()\n\n @Suppress(\"DEPRECATION\")\n fun inv() = ModInt(int.modInv(MODBASE))\n\n operator fun div(other: ModInt) = div(other.int)\n operator fun div(other: Int) = times(other.modInv(MODBASE))\n\n override fun toString() = int.toString()\n}\n\ninline class ModIntArray(val intArray: IntArray) {\n @Suppress(\"DEPRECATION\")\n operator fun get(i: Int) = ModInt(intArray[i])\n operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n}\nfun ModIntArray(capacity: Int) = ModIntArray(IntArray(capacity))\ninline fun ModIntArray(capacity: Int, init: (Int) -> ModInt) = ModIntArray(capacity).apply {\n repeat(capacity) { this[it] = init(it) }\n}\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit)\n { Output().apply(block).nowPrint() }\n"}, {"source_code": "import java.io.File\nimport java.lang.Exception\nimport java.util.*\n\nprivate const val MODULO = 1000000007L\n\nfun main() {\n// val scanner = Scanner(File(\"input.txt\"))\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n val l = scanner.nextInt()\n val r = scanner.nextInt()\n\n// val optionCount = when {\n// r - l >= 2 -> calculateAllPossible(n, l, r)\n// r - l == 1 -> calculateTwoNumbers(n, l, r)\n// r - l == 0 -> calculateOneNumber(n, l)\n// else -> throw Exception(\"Impossible\")\n// }\n println(calculateAllPossible(n, l, r))\n// println(optionCount)\n}\n\nprivate fun calculateAllPossible(n: Int, l: Int, r: Int): Int {\n val zeroOptions: Long = (r / 3 - (l - 1) / 3).toLong()\n val oneOptions = ((r + 2) / 3 + 1 - (l + 1) / 3 - 1).toLong()\n val twoOptions = ((r + 1) / 3 + 1 - (l) / 3 - 1).toLong()\n\n var zeroTotal: Long = 1L\n var oneTotal: Long = 0L\n var twoTotal: Long = 0L\n\n for (i in (0 until n)) {\n val nextOneTotal = zeroTotal * oneOptions + twoTotal * twoOptions + oneTotal * zeroOptions\n val nextTwoTotal = oneTotal * oneOptions + twoTotal * zeroOptions + zeroTotal * twoOptions\n val nextZeroTotal = oneTotal * twoOptions + twoTotal * oneOptions + zeroTotal * zeroOptions\n\n oneTotal = nextOneTotal\n twoTotal = nextTwoTotal\n zeroTotal = nextZeroTotal\n\n oneTotal %= MODULO\n twoTotal %= MODULO\n zeroTotal %= MODULO\n }\n// val numbers = r - l + 1\n// return ((pow(numbers, n - 1).toLong() * countThreeDividers(l, r).toLong()) % MODULO).toInt()\n return zeroTotal.toInt()\n}\n\nprivate fun calculateTwoNumbers(n: Int, l: Int, r: Int): Int {\n return when {\n n == 1 -> if (r % 3 == 0 || l % 3 == 0) 1 else 0\n n > 1 -> pow(2, n - 2)\n else -> throw Exception(\"Impossible\")\n }\n}\n\nprivate fun calculateOneNumber(n: Int, l: Int): Int {\n return when {\n l % 3 == 0 -> 1\n n % 3 == 0 -> 1\n else -> 0\n }\n}\n\nprivate fun countThreeDividers(l: Int, r: Int): Int {\n val size = r - l + 1\n return when (size % 3) {\n 0 -> size / 3\n 1 -> size / 3 + (if (r % 3 == 0) 1 else 0)\n 2 -> size / 3 + (if (l % 3 == 0) 1 else 0) + (if ((r - 1) % 3 == 0) 1 else 0)\n else -> throw Exception(\"Impossible\")\n }\n}\n\nprivate fun pow(value: Int, power: Int): Int {\n var result = 1L\n for (i in (0L until power.toLong())) {\n result = (result * value) % MODULO\n }\n return result.toInt()\n}"}, {"source_code": "import org.w3c.dom.html.HTMLScriptElement\nimport java.io.*\nimport java.util.*\nimport kotlin.collections.*\nimport java.util.TreeMap as Map\nimport java.util.TreeSet as Set\nimport java.util.HashMap as HMap\nimport java.util.HashSet as HSet\nimport java.util.ArrayList as List\nimport java.util.ArrayDeque as Deque\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val pw = PrintWriter(System.out)\n val n = sc.nextInt()\n val l = sc.nextLong()\n val r = sc.nextLong()\n val mod = longArrayOf(r / 3 - (l - 1) / 3, (r + 1) / 3 - l / 3, (r + 2) / 3 - (l + 1) / 3)\n val dp = Array(n) { LongArray(3) }\n dp[0] = mod\n for (i in 1 until n) {\n for (m1 in 0 until 3)\n for (m2 in 0 until 3) {\n dp[i][(m1 + m2) % 3] += dp[i - 1][m1] * mod[m2]\n dp[i][(m1 + m2) % 3] %= 1_000_000_007L\n }\n }\n println(dp[n-1][0])\n}\n"}], "negative_code": [], "src_uid": "4c4852df62fccb0a19ad8bc41145de61"} {"nl": {"description": "Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.Given the number of employees n, find in how many ways Fafa could choose the number of team leaders l in such a way that it is possible to divide employees between them evenly.", "input_spec": "The input consists of a single line containing a positive integer n (2 ≤ n ≤ 105) — the number of employees in Fafa's company.", "output_spec": "Print a single integer representing the answer to the problem.", "sample_inputs": ["2", "10"], "sample_outputs": ["1", "3"], "notes": "NoteIn the second sample Fafa has 3 ways: choose only 1 employee as a team leader with 9 employees under his responsibility. choose 2 employees as team leaders with 4 employees under the responsibility of each of them. choose 5 employees as team leaders with 1 employee under the responsibility of each of them. "}, "positive_code": [{"source_code": "import java.util.*\n\nfun main() {\n val s = Scanner(System.`in`)\n\n val n = s.nextInt()\n var ways = 0\n var leaders = 1\n repeat(n / 2) {\n if((n - leaders) % leaders == 0)\n ways++\n leaders++\n }\n println(ways)\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!.toInt()\n var ans = 0\n for (i in 1..n-1){\n if (n%i==0) ans++\n }\n println(ans)\n}"}, {"source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n var N = 0\n for(i in 1..n/2){\n if ((n - i) % i == 0) {\n N++\n }\n }\n println(N)\n\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n var ret = 0\n for(i in 1..n-1) {\n if((n-i) % i == 0) ret++\n }\n println(ret)\n}\n"}, {"source_code": "import java.util.*\nimport java.math.*\nimport kotlin.math.*\n\nfun readLn()=readLine()!!\nfun readInt()=readLn().toInt()\nfun readInts()=readLn().split(\" \").map{it.toInt()}\nfun readLong()=readLn().toLong()\nfun readLongs()=readLn().split(\" \").map{it.toLong()}\n\nval out=mutableListOf()\nfun printLine(s:String){out.add(s)}\nfun output(){println(out.joinToString(\"\\n\"))}\n\nfun main(){\n var n=readInt()\n var ans=0\n for(i in 1 until n)if(n%i==0)ans++\n printLine(\"$ans\")\n output()\n}"}, {"source_code": "fun main(args: Array){\n val n = readLine()!!.toInt()\n var ans = 1\n var i = 2\n while (i*i<=n) {\n if (n % i == 0) {\n if (i*i==n) ans += 1 else ans += 2\n }\n i++\n }\n println(ans)\n}"}, {"source_code": "fun main(args:Array){\n val n= readLine()!!.toInt()\n println((2..n).filter{n%it==0}.size)\n}"}, {"source_code": "/* https://codeforces.com/problemset/problem/935/A */\n\nfun main() {\n val numOfEmployees = readLine()!!.toInt()\n\n var numOfPossibilities = 0\n for (numOfLeaders in 1 until numOfEmployees) {\n val remainingEmployees = numOfEmployees - numOfLeaders\n if (remainingEmployees % numOfLeaders == 0) {\n numOfPossibilities++\n }\n }\n println(numOfPossibilities)\n}"}, {"source_code": "fun main() {\n val input = Integer.parseInt(readLine()!!)\n val output = (1..(input / 2))\n .filter {\n (input - it) % it == 0\n }\n .count()\n\n println(output)\n}"}, {"source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n val n = reader.nextInt()\n println((1..n/2).filter { it<=n-it && (n-it)%it==0 }.count())\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n\n var vaiants = 0\n for(i in 1 .. n / 2) {\n if(n % i == 0) {\n vaiants++\n }\n }\n\n print(vaiants)\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n var ans = 0\n var k = 1\n repeat(n / 2) {\n ans += (if ((n - k) % k == 0) 1 else 0)\n k++\n }\n println(ans)\n}\n"}, {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val n = readInt()\n println((1 until n).count { n % it == 0 })\n}\n\n\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun solve() {\n val n = nextInt()\n var ans = 0\n for(i in 1 until n) {\n val l = n - i\n if(n % l == 0) ans++\n }\n pw.println(ans)\n}\n\n\nfun hasNext() : Boolean {\n while (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine() ?: return false)\n return true\n}\n\nfun next() = if(hasNext()) st.nextToken()!! else throw RuntimeException(\"No tokens\")\n\nfun nextInt() = next().toInt()\n\nfun nextLong() = next().toLong()\n\nfun nextLine() = if(hasNext()) st.nextToken(\"\\n\")!! else throw RuntimeException(\"No tokens\")\n\nfun nextArray(n : Int) = IntArray(n,{nextInt()})\n\nval ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n\nvar br = when(ONLINE_JUDGE) {\n true -> BufferedReader(InputStreamReader(System.`in`))\n else -> BufferedReader(FileReader(\"in.txt\"))\n}\n\nvar pw = when(ONLINE_JUDGE) {\n true -> PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))\n else -> PrintWriter(BufferedWriter(FileWriter(\"out.txt\")))\n}\n\nvar st = StringTokenizer(\"\")\n\nfun main(args: Array) {\n var start = System.currentTimeMillis()\n solve()\n pw.close()\n br.close()\n if(!ONLINE_JUDGE)\n System.err.println(\"${System.currentTimeMillis() - start} ms\")\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val ways = (1..n/2).count {\n (n - it)%it == 0\n }\n println(ways)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val n = scan.nextInt()\n var res = 1\n for (i in 2 until n/2+1) {\n if (n%i == 0){\n res++\n }\n\n }\n print(res)\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n var l = 0\n\n var i = 1\n while (i <= n / 2) {\n\n if ((n - i) % i == 0) {\n l++\n }\n\n i++\n }\n\n println(l)\n\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n var ans = 0\n for (i in 1 until n) {\n val employees = n - i\n ans += if (employees % i == 0) 1 else 0\n }\n println(ans)\n}\n"}, {"source_code": "fun main() {\n val e = readLine()!!.toInt()\n print((1..e/2).asSequence().filter { e % it == 0}.count())\n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n var sum = 0\n \n for(i in 1 .. n) {\n if(n%i==0&&n!=i)sum++\n }\n print(sum)\n \n}"}, {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n print(\n (1 .. n).filter{\n (n%it==0&&n!=it)\n }.size\n )\n\n}"}, {"source_code": "fun main(args: Array) {\n\tval n = readLine()!!.toInt()\n\tvar temp = 0\n\tfor(i in 1..n-1){\n\tif((n - i) % i == 0) temp++\n\t}\n\tprintln(temp)\n}"}, {"source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n var count = 0\n for (i in 1..n/2) {\n if (n % i == 0)\n count++\n }\n println(count)\n return\n}"}, {"source_code": "fun main(args: Array) {\n\tval input = readLine()!!.toInt()\n\tprintln(getVariants(input))\n}\n\nfun getVariants(numberOfEmployee: Int): Int {\n\tvar numOfVariants = 0\n\n\tif (numberOfEmployee < 2) return 0\n\n\tfor (i in 1 until numberOfEmployee) {\n\t\tif ((numberOfEmployee - i) % i == 0) {\n\t\t\tnumOfVariants += 1\n\t\t}\n\t}\n\n\treturn numOfVariants\n}"}], "negative_code": [{"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val n = scan.nextInt()\n var res = 1\n for (i in 2 until n/2) {\n if (n%i == 0){\n res++\n if (n/i != i) res++\n }\n\n }\n print(res)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val n = scan.nextInt()\n var res = 1\n for (i in 2 until n/2) {\n if (n%i == 0) res += 2\n }\n print(res)\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val n = scan.nextInt()\n var res = 1\n for (i in 2 .. n/2) {\n if (n%i == 0){\n res++\n if (n/i != i) res++\n }\n\n }\n print(res)\n}"}, {"source_code": "fun main(args: Array) {\n\tval n = readLine()!!.toInt()\n\tvar temp = 0\n\tfor(i in 1..n-1){\n\tif((n - 1) % i == 0) temp++\n\t}\n\tprintln(temp)\n}"}, {"source_code": "fun main(args: Array) {\n\tval input = readLine()!!.toInt()\n\tprintln(getVariants(input))\n}\n\nfun getVariants(numberOfEmployee: Int): Int {\n\tvar numOfVariants = 0\n\n\tif (numberOfEmployee < 2) return 0\n\n\tif (numberOfEmployee % 3 != 0 && numberOfEmployee % 2 != 0) return 1\n\n\tfor (i in 1..numberOfEmployee) {\n\t\tif ((numberOfEmployee - i) % i == 0) {\n\t\t\tnumOfVariants += 1\n\t\t}\n\t}\n\n\treturn numOfVariants\n}"}, {"source_code": "fun main(args: Array) {\n\tval input = readLine()!!.toInt()\n\tprintln(getVariants(input))\n}\n\nfun getVariants(numberOfEmployee: Int): Int {\n\tvar numOfVariants = 0\n\n\tif (numberOfEmployee < 2) return 0\n\n\tif (numberOfEmployee % 3 != 0 && numberOfEmployee % 2 != 0) return 1\n\n\tfor (i in 1 until numberOfEmployee) {\n\t\tif ((numberOfEmployee - i) % i == 0) {\n\t\t\tnumOfVariants += 1\n\t\t}\n\t}\n\n\treturn numOfVariants\n}"}], "src_uid": "89f6c1659e5addbf909eddedb785d894"} {"nl": {"description": "Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia. For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs $$$n$$$ actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options: the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by $$$1$$$; the second option is to put candies in the box. In this case, Alya will put $$$1$$$ more candy, than she put in the previous time. Thus, if the box is empty, then it can only use the second option.For example, one possible sequence of Alya's actions look as follows: put one candy into the box; put two candies into the box; eat one candy from the box; eat one candy from the box; put three candies into the box; eat one candy from the box; put four candies into the box; eat one candy from the box; put five candies into the box; This way she will perform $$$9$$$ actions, the number of candies at the end will be $$$11$$$, while Alya will eat $$$4$$$ candies in total.You know the total number of actions $$$n$$$ and the number of candies at the end $$$k$$$. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given $$$n$$$ and $$$k$$$ the answer always exists.Please note, that during an action of the first option, Alya takes out and eats exactly one candy.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 10^9$$$; $$$0 \\le k \\le 10^9$$$) — the total number of moves and the number of candies in the box at the end. It's guaranteed, that for the given $$$n$$$ and $$$k$$$ the answer exists.", "output_spec": "Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data. ", "sample_inputs": ["1 1", "9 11", "5 0", "3 2"], "sample_outputs": ["0", "4", "3", "1"], "notes": "NoteIn the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate $$$0$$$ candies.In the second example the possible sequence of Alya's actions looks as follows: put $$$1$$$ candy, put $$$2$$$ candies, eat a candy, eat a candy, put $$$3$$$ candies, eat a candy, put $$$4$$$ candies, eat a candy, put $$$5$$$ candies. This way, she will make exactly $$$n=9$$$ actions and in the end the box will contain $$$1+2-1-1+3-1+4-1+5=11$$$ candies. The answer is $$$4$$$, since she ate $$$4$$$ candies in total."}, "positive_code": [{"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val n = r.readLine()!!.toLong()\n //val v = r.readLine()!!.split(\"\").filter { it.isNotEmpty() }\n fun put(l:Long) = (1+l)*l/2\n fun eat(l:Long) = l\n val (action, remain) = r.readLine()!!.split(\" \").map { it.toLong() }\n fun inbox(l:Long) = put(l)-eat(action-l)\n fun s(x:Long):Long{\n var le = 0L\n var ri = action+1\n while (le le = mi+1\n inbox(mi)>x -> ri = mi\n inbox(mi) == x -> return mi\n }\n }\n return -1\n }\n val ans = s(remain)\n println(action-ans)\n /*repeat(r.readLine()!!.toInt()) {\n //val len = r.readLine()!!.toInt()\n val (n, s, t) = r.readLine()!!.split(\" \").map { it.toLong() }\n val more = s+t-n\n println(minOf(n- minOf(s, t)+1, maxOf(s, t)+1))\n }*/\n}"}, {"source_code": "import kotlin.math.roundToInt\nimport kotlin.math.sqrt\n\nfun main() {\n val (n, k) = readDoubles()\n\n val ans = (n + (3 - sqrt(8*(n + k) + 9))/2).toInt()\n\n println(ans)\n}\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit)\n { Output().apply(block).nowPrint() }\n"}, {"source_code": "import kotlin.math.roundToInt\nimport kotlin.math.sqrt\n\nfun main() {\n val (n, k) = readDoubles()\n\n val ans = ((2*n + 3 - sqrt(8*(n + k) + 9))/2).toInt()\n\n println(ans)\n}\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit)\n { Output().apply(block).nowPrint() }\n"}, {"source_code": "import kotlin.math.roundToInt\nimport kotlin.math.sqrt\n\nfun main() {\n val (n, k) = readDoubles()\n\n val disc = sqrt(8*(n + k) + 9)\n val pr = 2*n + 3\n\n val ans = (if(disc <= pr) (pr - disc)/2 else (pr + disc)/2).toInt()\n\n println(ans)\n}\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit)\n { Output().apply(block).nowPrint() }\n"}, {"source_code": "fun main() {\n val (n, k) = readInts()\n\n val ans = (0 until n).binarySearch { x ->\n k.compareTo((n - x).toLong() * (n - x + 1) / 2 - x)\n }.value\n\n println(ans)\n}\n\nfun IntRange.binarySearch(signumFunc: (Int) -> Int): BinarySearchResult {\n var low = start\n var high = endInclusive\n\n while (low <= high) {\n val mid = low / 2 + high / 2 + (low % 2 + high % 2) / 2\n val cmp = signumFunc(mid)\n\n if (cmp < 0)\n low = mid + 1\n else if (cmp > 0)\n high = mid - 1\n else\n return BinarySearchResult(mid, true) // key found\n }\n return BinarySearchResult(low, false) // key not found\n}\ndata class BinarySearchResult(val value: T, val exactFound: Boolean)\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit)\n { Output().apply(block).nowPrint() }\n"}, {"source_code": "\nimport java.util.*\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toLong() } // list of ints\n\nfun main() {\n // read input\n val (n, k) = readInts()\n\n for (i in 0..n) {\n val totalK = i * (i + 1) / 2\n val totalAte = n - i\n if (totalK - k == totalAte) {\n print(totalAte)\n return\n }\n }\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\n\nfun PrintWriter.solve(sc: FastScanner) {\n val n = sc.nextLong()\n val k = sc.nextLong()\n println(n - (-3 + Math.sqrt(9.0 + 8 * (n + k)).toLong()) / 2)\n}\n\nfun main() {\n val writer = PrintWriter(System.out, false)\n writer.solve(FastScanner(System.`in`))\n writer.flush()\n}\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val jin = Scanner(System.`in`)\n val n = jin.nextLong()\n val k = jin.nextLong()\n for (answer: Long in n downTo 0L) {\n if ((((n - answer) * (n - answer + 1L)) / 2) - answer == k) {\n println(answer)\n return\n }\n }\n}"}, {"source_code": "fun main(){\n val (n, k) = readLine()!!.split(' ').map { it.toInt() }\n\n var step = 1\n var sum = 1\n while (step {\n left = current + 1\n }\n resultingCandies == candiesLeft -> return eaten.toInt()\n resultingCandies > candiesLeft -> {\n right = current - 1\n }\n }\n }\n throw IllegalArgumentException(\"solution not found\")\n}\n\nfun sumOf(willAdd: Long): Long = (willAdd * (willAdd + 1)) / 2\n\n\nfun main() {\n val (moves, candiesLeft) = readInts()\n println(sportMafia(moves.toLong(), candiesLeft.toLong()))\n}"}], "negative_code": [{"source_code": "import kotlin.math.roundToInt\nimport kotlin.math.sqrt\n\nfun main() {\n val (n, k) = readDoubles()\n\n val ans = ((sqrt(8 * (n+k) + 9) + 2*n + 3) / 2).toInt()\n\n println(ans)\n}\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit)\n { Output().apply(block).nowPrint() }\n"}, {"source_code": "fun main() {\n val (n, k) = readInts()\n\n val ans = (0 until n).binarySearch { x ->\n k.compareTo((n - x) * (n - x + 1) / 2 - x)\n }.value\n\n println(ans)\n}\n\nfun IntRange.binarySearch(signumFunc: (Int) -> Int): BinarySearchResult {\n var low = start\n var high = endInclusive\n\n while (low <= high) {\n val mid = low / 2 + high / 2 + (low % 2 + high % 2) / 2\n val cmp = signumFunc(mid)\n\n if (cmp < 0)\n low = mid + 1\n else if (cmp > 0)\n high = mid - 1\n else\n return BinarySearchResult(mid, true) // key found\n }\n return BinarySearchResult(low, false) // key not found\n}\ndata class BinarySearchResult(val value: T, val exactFound: Boolean)\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit)\n { Output().apply(block).nowPrint() }\n"}, {"source_code": "private fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n\nfun main() {\n val (turns, left) = readInts()\n val k = ((Math.sqrt((9 + 8 * turns + 8 * left).toDouble()).toInt()) - 3) / 2\n println(turns - k)\n\n}"}, {"source_code": "import kotlin.math.sqrt\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n\nfun main() {\n val (turns, left) = readInts()\n val disc = 9L + 8L * turns + 8L * left\n println(disc)\n val discSqrt = sqrt(disc.toDouble()).toLong()\n println(discSqrt)\n val k = (discSqrt - 3) / 2\n println(turns - k)\n}"}], "src_uid": "17b5ec1c6263ef63c668c2b903db1d77"} {"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": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n\n println(modify(sc.next()))\n}\n\nval vowels = \"AOYEUI\"\nfun modify(word: String) =\n word.filter { !vowels.contains(it.toUpperCase()) }\n .map { \".\" + it.toLowerCase() }\n .joinToString(\"\")\n"}, {"source_code": "// kotlin oj template code from uwi(Codeforces), and convert to kotlin by lety\nimport java.io.ByteArrayInputStream\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport java.util.InputMismatchException\n\nlateinit var `is`: InputStream\nlateinit var out: PrintWriter\nvar INPUT = \"\"\n\n//val oj = System.getProperty(\"ONLINE_JUDGE\") != null\nval oj = true\nval inbuf = ByteArray(1024)\nvar lenbuf = 0\nvar ptrbuf = 0\n\n\nfun solve() {\n val s = ns()\n\n s.forEach {\n if(it in \"aeiouyAEIOUY\")\n {\n }\n else\n {\n print('.')\n\n if(it.isUpperCase())\n {\n print(it.toLowerCase())\n }\n else\n {\n print(it)\n }\n }\n }\n\n}\n\nfun main() {\n `is` = if (oj) System.`in` else ByteArrayInputStream(INPUT.toByteArray())\n out = PrintWriter(System.out)\n\n val s = System.currentTimeMillis()\n solve()\n out.flush()\n tr((System.currentTimeMillis() - s).toString() + \"ms\")\n}\n\nprivate fun readByte(): Int {\n if (lenbuf == -1) throw InputMismatchException()\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0\n try {\n lenbuf = `is`.read(inbuf)\n } catch (e: IOException) {\n throw InputMismatchException()\n }\n\n if (lenbuf <= 0) return -1\n }\n return inbuf[ptrbuf++].toInt()\n}\n\nprivate fun isSpaceChar(c: Int): Boolean = !(c >= 33 && c <= 126)\n\nprivate fun skip(): Int {\n var b: Int = readByte()\n while (b != -1 && isSpaceChar(b)) {\n b = readByte()\n }\n return b\n}\n\n// using ns()\nprivate fun nd(): Double = ns().toDouble()\n\n// using ns()\nprivate fun nc(): Char = skip().toChar()\n\n// input until whitespace\nprivate fun ns(): String {\n var b = skip()\n val sb = StringBuilder()\n while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b)\n b = readByte()\n }\n return sb.toString()\n}\n\nprivate fun ns(n: Int): CharArray {\n val buf = CharArray(n)\n var b = skip()\n var p = 0\n while (p < n && !isSpaceChar(b)) {\n buf[p++] = b.toChar()\n b = readByte()\n }\n return if (n == p) buf else Arrays.copyOf(buf, p)\n}\n\n// matrix\nprivate fun nm(n: Int, m: Int): Array {\n val map = Array(n) { CharArray(m) }\n for (i in 0 until n) map[i] = ns(m)\n return map\n}\n\nprivate fun pm(matrix: Array) {\n val n = matrix.size\n val m = matrix[0].size\n repeat(n)\n {\n repeat(m)\n { jt ->\n out.print(matrix[it][jt])\n }\n out.println()\n }\n out.flush()\n}\n\n// int array\nprivate fun na(n: Int): IntArray {\n val a = IntArray(n)\n for (i in 0 until n) a[i] = ni()\n return a\n}\n\nprivate fun ni(): Int {\n var num = 0\n var b: Int = readByte()\n var minus = false\n while (b != -1 && !(b >= '0'.toInt() && b <= '9'.toInt() || b == '-'.toInt())) {\n b = readByte()\n }\n if (b == '-'.toInt()) {\n minus = true\n b = readByte()\n }\n\n while (true) {\n if (b >= '0'.toInt() && b <= '9'.toInt()) {\n num = num * 10 + (b - '0'.toInt())\n } else {\n return if (minus) -num else num\n }\n b = readByte()\n }\n}\n\nprivate fun nl(): Long {\n var num: Long = 0\n var b: Int = readByte()\n var minus = false\n while (b != -1 && !(b >= '0'.toInt() && b <= '9'.toInt() || b == '-'.toInt())) {\n b = readByte()\n }\n if (b == '-'.toInt()) {\n minus = true\n b = readByte()\n }\n\n while (true) {\n if (b >= '0'.toInt() && b <= '9'.toInt()) {\n num = num * 10 + (b - '0'.toInt())\n } else {\n return if (minus) -num else num\n }\n b = readByte()\n }\n}\n\nprivate fun tr(vararg o: Any) {\n// if (!oj) println(Arrays.deepToString(o))\n}\n\n"}, {"source_code": "fun main(args: Array) {\n\n val s = readLine()!!\n\n print(s.toLowerCase()\n .filter { it !in listOf('a', 'e', 'o', 'u', 'i', 'y') }.asIterable().joinToString(separator = \".\", prefix = \".\"))\n\n}"}, {"source_code": "\nfun main(args : Array) {\n val s = readLine()!!\n var list: MutableList = mutableListOf()\n var listc: MutableList = mutableListOf()\n\n val letter = arrayOf('a', 'o', 'y', 'e', 'i', 'u')\n for (char in s) {\n list.add(char)\n }\n\n for(j in 0..s.length-1){\n var c = 0\n for(k in 0..5){\n if(s[j].toLowerCase()!=letter[k]){\n c++\n }\n }\n if(c==6){\n listc.add('.')\n listc.add(s[j].toLowerCase())\n }\n }\n\n\n\n for (i in 0..listc.size-1) {\n print(listc[i])\n }\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array){\n val vwls = arrayOf(\"a\",\"o\",\"y\",\"e\",\"u\",\"i\");\n val sc = Scanner(System.`in`)\n var str = sc.nextLine().toLowerCase();\n\n var res = \"\";\n for (x in 0 until str.length){\n if (!vwls.contains(\"${str[x]}\")){\n res += \".${str[x]}\"\n }\n }\n print(res)\n}"}, {"source_code": "fun main()\n{\n val given = readLine()!!\n var answer = \"\"\n for (i in given)\n {\n if (! \"AEIOUYaeiouy\".contains(i))\n {\n answer += \".\"+i.toLowerCase()\n }\n }\n println(answer)\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val vowels = listOf(\"a\", \"e\", \"i\", \"o\", \"u\", \"y\")\n val str = readLine()!!.split(\"\").filter { it.length>0 && it.toLowerCase() !in vowels }.map { it.toLowerCase() }.joinToString(\".\")\n s.append(\".\")\n s.append(str)\n print(s)\n}"}, {"source_code": "fun main(args: Array) {\n var w = readLine()!!.toString()\n var W = w.toLowerCase()\n for (i in W){\n if (!(i == 'a' || i == 'o' || i == 'y' || i == 'e' || i == 'u' || i == 'i')) {\n print(\".$i\")\n }\n }\n }"}, {"source_code": "import java.util.*\n\nval scan = Scanner(System.`in`)\n\nfun main(args: Array){\n var s = scan.next().toLowerCase()\n var n = \"aoyeui\".split(\"\").subList(1,7)\n for (i in s){\n var a = i.toString()\n if (a !in n) {\n print(\".$i\")\n }\n }\n\n}\n\n"}, {"source_code": "import java.lang.StringBuilder\n\nfun main(args: Array) {\n val input = readLine() ?: \"\"\n val vowels = \"[aoyeui]\".toRegex()\n val noVowels = input.toLowerCase().replace(vowels,\"\")\n val sb = StringBuilder()\n noVowels.forEach { sb.append(\".$it\") }\n println(sb.toString())\n}"}, {"source_code": "//package codeforces.com.tasks.task118A\n\nfun main() {\n val vowels = setOf('a', 'o', 'y', 'e', 'u', 'i')\n val input = readLine()!!\n val letters = Array(input.length) { \"\" }\n var index = 0\n input.map {\n if (!vowels.contains(it.toLowerCase()))\n letters[index] = \".${it.toLowerCase()}\"; index++\n }\n println(letters.joinToString(\"\"))\n}"}, {"source_code": "fun main(args: Array)\n{\n\n var text = readLine()!!.trim()\n text = text.toLowerCase()\n var text1 = text\n var vowels =\"aouyei\"\n\n for (i in 0..(text.length-1))\n {\n if (vowels.contains(text.get(i)))\n {\n text1 = text1.replace(text.get(i)+\"\",\"\")\n }else\n {\n text1 = text1.replace(text.get(i)+\"\",\".\"+text.get(i))\n }\n text1 = text1.replace(\"..\",\".\")\n\n\n }\n\n\n print(text1)\n\n\n}"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\nfun main() { _writer.solve(); _writer.flush() }\n\nfun PrintWriter.solve() {\n var result = readLn()\n result = result.toLowerCase()\n result = result.replace(\"a\",\"\")\n result = result.replace(\"e\",\"\")\n result = result.replace(\"y\",\"\")\n result = result.replace(\"u\",\"\")\n result = result.replace(\"i\",\"\")\n result = result.replace(\"o\",\"\")\n var newChars = \"\"\n for (i in 0 until result.length) {\n newChars = newChars.plus(\".\").plus(result[i])\n }\n println(newChars.toString())\n}\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()"}, {"source_code": "fun main() {\n val vowel:Array = arrayOf('A', 'O', 'Y', 'E', 'U', 'I')\n val vowelLower:Array = arrayOf('a', 'o', 'y', 'e', 'u', 'i')\n val word:String = readLine()!!\n\n for (i in word.indices) {\n\n if (word[i] in vowel || word[i] in vowelLower)\n print(\"\")\n\n else {\n if (word[i] in 'A'..'Z')\n print(\".\" + word[i].toLowerCase())\n else\n print(\".\" + word[i])\n }\n }\n}"}, {"source_code": "import java.lang.StringBuilder\n\nprivate val vowels = listOf('a','o','y','e','u','i')\n\nfun main(args: Array) {\n val text = readLine()!!\n val newText = StringBuilder()\n val capVowels = vowels.map { it - 32 }\n for (char in text) {\n if (char in vowels || char in capVowels)\n continue\n val consonant = if (char.toInt() < 97) char + 32 else char\n newText.append(\".$consonant\")\n }\n print(newText)\n}"}, {"source_code": "import kotlin.collections.*\nimport kotlin.io.*\nimport kotlin.text.*\n\nfun readInts() = readLine()!!.split(' ').map { it.toInt() }\n\nfun main() {\n var s = readLine().toString()\n val vowels = arrayOf(\"a\", \"o\", \"y\", \"e\", \"u\", \"i\")\n for (i in vowels.indices) {\n s = s.replace(vowels[i], \"\", true)\n }\n s = s.toLowerCase()\n val s1 = s.split(\"\")\n\n var res = \"\"\n for (i in s1.indices) {\n res += if (s1[i] != \"\") \".\" else \"\"\n res += s1[i]\n }\n println(res)\n}\n"}, {"source_code": "fun main() {\n println(solution(readLine()!!))\n}\n\nfun solution(text: String): String{\n val syllables = setOf('A','O', 'Y', 'E', 'U', 'I')\n val res = mutableListOf()\n for (ch in text){\n if (syllables.contains(ch.toUpperCase())) {\n continue\n }\n res.addAll(listOf('.',ch.toLowerCase()))\n }\n return String(res.toCharArray())\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)){\n val word = nextLine()\n\n val wordArray = word.toCharArray()\n val finalArray = CharArray(word.length * 2)\n var counter = 0\n for(i in wordArray.indices){\n val c = wordArray[i]\n var isCharOk = true\n when(c){\n 'A','a',\n 'O','o',\n 'Y','y',\n 'E','e', \n 'U','u',\n 'I','i'-> isCharOk = false\n }\n if(!isCharOk){\n continue\n }\n finalArray[counter] = '.' \n counter++\n finalArray[counter] = Character.toLowerCase(c)\n counter++\n }\n println(String(finalArray,0,counter))\n}"}, {"source_code": "fun main(args: Array) {\n var inp = readLine()!!\n inp = inp.toLowerCase()\n val vovs = arrayOf('a','e','i','o','u','y')\n for (i in inp)\n {\n if (i in vovs)\n continue\n print(\".$i\")\n }\n}"}, {"source_code": "fun main(args: Array) {\n val input: String = readLine()!!\n val answer: ArrayList = arrayListOf()\n val vowels: ArrayList = arrayListOf('a', 'i', 'u', 'e', 'o', 'y')\n for (char in input.toCharArray()) {\n val currentChar = char.toLowerCase()\n if (!vowels.contains(currentChar)) {\n answer.add('.')\n answer.add(currentChar)\n }\n }\n for (char in answer) {\n print(char)\n }\n println()\n}"}, {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\nfun main(args: Array) {\n var scan = Scanner(System.`in`)\n var input = scan.nextLine()\n input.toCharArray()\n var len = input.length\n var i = 0\n var arr2 = ArrayList()\n while(i < len) {\n\n if(input[i].toUpperCase() !== 'A' && input[i].toUpperCase() !== 'E' && input[i].toUpperCase() !== 'I' && input[i].toUpperCase() !== 'O' && input[i].toUpperCase() !== 'U' && input[i].toUpperCase() !== 'Y'){\n arr2.add(\".\")\n arr2.add(input[i].toString())\n }\n i++\n }\n var output: String = \"\"\n arr2.forEach { output += it.toLowerCase()}\n println(output)\n}"}, {"source_code": "/**\n * We declare a package-level function main which returns Unit and takes\n * an Array of strings as a parameter. Note that semicolons are optional.\n */\nfun main(args: Array) {\n//\tval (l,r) = readLine()!!.split(' ').map(String::toInt)\t\n\tvar str = readLine()!!\n var c = \"aoyuie\";\n str = str.toLowerCase()\n var newStr = StringBuilder()\n for ( s in str ) {\n var a = 0\n\t\tfor (ch in c ) {\n if (!s.equals(ch)) {\n a+=1\n }\n }\n if (a==6) {\n newStr.append(\".\")\n newStr.append(s)\n \n }\n \n }\n println(newStr.toString())\n}\n"}, {"source_code": "fun main(args: Array) {\n val word = readLine()!!\n println(solve(word))\n}\n\nfun solve(word: String): String {\n val consonants = \"aeyoui\"\n return word.toLowerCase().map { c -> if (c in consonants) \"\" else \".$c\" }.joinToString(\"\")\n}\n\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val input = InputReader(inputStream)\n val output = PrintWriter(outputStream)\n val solver = Task()\n solver.solve(input, output)\n output.close()\n}\n\nprivate class Task {\n fun solve(input: InputReader, output: PrintWriter) {\n val string = input.next()\n\n val dot = '.'\n val vowels = setOf('a', 'o', 'y', 'e', 'u', 'i')\n\n for (char in string) {\n if (char.toLowerCase() !in vowels) {\n output.print(dot)\n output.print(char.toLowerCase())\n } else {\n continue\n }\n }\n }\n}\n\n\nprivate class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n\n operator fun next(): String {\n while (tokenizer == null || tokenizer?.hasMoreTokens()?.not() == true) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n}"}, {"source_code": "import java.util.*\nimport java.util.regex.Pattern\nimport kotlin.collections.ArrayList\n\nfun main(){\n var string = readLine()\n print(resulting(string!!))\n}\n\nfun resulting (str:String):String{\n var string = str.replace(Regex(\"[aoyeui]|[AOYEUI]\"), \"\")\n string = string.toLowerCase()\n var newString = \"\"\n for (i in 0..string.length-1)\n newString+=\".\"+string[i]\n return newString\n}\n\n"}, {"source_code": "fun main(args: Array) {\n var s= readLine()\n var s2=\"\"\n s= s!!.toLowerCase()\n for (i in 0..(s!!.length-1)){\n if (s.get(i)=='a'||s.get(i)=='e'||s.get(i)=='i'||s.get(i)=='o'||s.get(i)=='u'||s.get(i)=='y'){\n continue\n }\n else{\n s2=s2+\".\"+s.get(i)\n }\n }\n print(s2)\n\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val s: Scanner = Scanner(System.`in`)\n val str: String = s.next()\n val vowels: CharArray = charArrayOf('a', 'o', 'y', 'e', 'i', 'u')\n for (c in str) {\n val lc: Char = c.toLowerCase();\n if (lc in vowels) {\n continue\n } else {\n System.out.print(\".\" + lc.toString())\n }\n }\n}"}, {"source_code": "fun main(args: Array) {\n readLine()!!\n .toLowerCase()\n .replace(Regex(\"[aoyeui]\"), \"\")\n .forEach { print(\".$it\") }\n}\n"}, {"source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n Scanner(System.`in`).use {\n val result = it.next().formatWithDots()\n println(result)\n }\n}\n\nfun String.formatWithDots(): String {\n val builder = StringBuilder()\n val dot = \".\"\n for (char in this) {\n if (char.isVowel()) {\n continue\n }\n builder.append(dot).append(Character.toLowerCase(char))\n }\n return builder.toString()\n}\n\nfun Char.isVowel() = when (this) {\n 'a', 'A', 'o', 'O', 'e', 'E', 'u', 'U', 'i', 'I', 'y', 'Y' -> true\n else -> false\n}"}, {"source_code": "fun main(args: Array) {\n val a = readLine()!!\n val template = arrayOf(\"A\", \"O\", \"Y\", \"E\", \"U\", \"I\")\n\n val result = a\n .filter { !template.contains(it.toString().toUpperCase()) }\n .map { it.toLowerCase() }\n .joinToString(prefix = \".\", separator = \".\")\n\n println(result)\n}"}, {"source_code": "// codeforces problem 118 A\n\nfun main() {\n val vowels = setOf('a', 'e', 'i', 'o', 'u', 'y')\n val result = StringBuilder(readLine()!!.toLowerCase().filter { it !in vowels })\n for (i in result.length-1 downTo 0) {\n result.insert(i, '.')\n }\n println(result)\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val input = BufferedReader(InputStreamReader(System.`in`))\n val string = input.readLine()\n println(customReplace(string))\n}\n\nfun customReplace(string: String) = buildString {\n for (letter in string) {\n if (!letter.isVowel()) {\n append('.')\n append(letter.toLowerCase())\n }\n }\n}\n\nfun Char.isVowel(): Boolean {\n val ch = this.toLowerCase()\n return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y'\n}"}, {"source_code": "fun main(args: Array){\n var s = readLine()!!\n val arr = charArrayOf ('a', 'o', 'y', 'e', 'u', 'i')\n var len = s.length - 1\n val ans = mutableListOf()\n var add = true\n for(i in 0..len) {\n add = true\n for(j in 0..5) {\n if (s[i].toLowerCase() == arr[j])\n add = false\n }\n if (add) {\n ans.add('.')\n ans.add(s[i].toLowerCase())\n }\n\n\n }\n for(i in 0..(ans.size-1))\n print(ans[i])\n\n}"}, {"source_code": "\nimport java.util.*\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val input: String = scanner.nextLine().toLowerCase()\n val VOWELS = \"aoyeui\"\n val result = StringBuilder()\n input.filterNot { VOWELS.contains(it) }.forEach { result.append(\".$it\") }\n println(result)\n}\n"}, {"source_code": "import java.util.*\n\n fun main(){\n var input = Scanner(System.`in`)\n var programString = input.nextLine()\n var string =\"\"\n programString.toLowerCase().replace(\"a\",\"\")\n programString.toLowerCase().toCharArray().forEach {\n string =string+changeChar(it)\n }\n System.out.println(string)\n }\n\nfun changeChar(char : Char) : String{\n if(char == 'a' || char == 'e' || char == 'i' || char == 'o' || char == 'u' || char == 'y'){\n return \"\"\n }else{\n return \".${char}\"\n }\n}\n\n\n\n\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val forbidden = listOf('a', 'o', 'y', 'e', 'u', 'i')\n println(stringTask(\n Scanner(System.`in`).next(),\n forbidden\n ))\n}\n\nfun stringTask(input: String, forbidden: List): String {\n return input\n .toLowerCase()\n .filter { it !in forbidden }\n .map { \".$it\" }\n .joinToString(\"\")\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val vowels = hashSetOf('a', 'o', 'y', 'e', 'u', 'i', 'A', 'O', 'Y', 'E', 'U', 'I')\n val br = BufferedReader(InputStreamReader(System.`in`))\n val s = br.readLine()\n val newS = s.filter { c -> !(c in vowels) }\n .map { c -> if (c.isUpperCase()) c.toLowerCase() else c}\n .joinToString(\".\")\n println(\".$newS\")\n}"}, {"source_code": "private fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n\nfun main(args: Array) {\n val str = readLn()\n var result: String = \"\"\n\n for (c in str.toCharArray()) {\n val cl = c.toLowerCase()\n if(!isVowel(cl)) {\n result = \"${result}.${cl}\"\n }\n }\n println(result)\n}\n\nfun isVowel(c: Char): Boolean {\n return c == 'a' || c == 'o' || c == 'y' || c == 'e' || c == 'u' || c == 'i'\n}"}, {"source_code": "fun main(args: Array) {\n val str = readLine()!!.toLowerCase()\n var res = \"\"\n for (i in str) {\n if (i !in listOf('a', 'o', 'y', 'e', 'u', 'i')) {\n res += \".$i\"\n }\n }\n println(res)\n}"}, {"source_code": "//package problem118a\n\nimport java.lang.StringBuilder\n\nfun convertWord(word: String): String {\n val initialModifications = word.toLowerCase().filter { \"aeiouy\".indexOf(it) == -1 }\n\n val result = StringBuilder()\n for (char in initialModifications) {\n result.append(\".$char\")\n }\n\n return result.toString()\n}\n\nfun main() {\n val input = readLine()!!\n println(convertWord(input))\n}\n"}, {"source_code": "import java.util.Scanner;\nfun solve(s : String){\n for(it in s){\n if(it=='A'||it=='O'||it=='E'||it=='I'||it=='U'||it=='Y')\n print(\"\")\n else if(it=='a'||it=='o'||it=='e'||it=='i'||it=='u'||it=='y')\n print(\"\")\n else{\n if(it>='A'&&it<='Z')\n print(\".${it.toLowerCase()}\")\n else\n print(\".$it\")\n }\n }\n println()\n}\nfun main(){\n val read = Scanner(System.`in`)\n var s = read.nextLine()\n solve(s)\n}"}, {"source_code": "import java.util.*\n\nfun Test(str : String) : String{\n var my_map = mapOf('a' to false , 'o' to false , 'y' to false , 'e' to false ,'u' to false ,'i' to false )\n var s = str.toLowerCase()\n var result = \"\"\n for(i in 0 until str.length)\n {\n if(my_map[s[i]] == null)\n {\n result += s[i]\n }\n }\n var r = \"\"\n for(i in 0 until result.length)\n {\n r += \".\" + result[i]\n }\n return r\n}\nfun main()\n{\n var scanner = Scanner(System.`in`)\n var str : String= scanner.next()\n\n println(Test(str))\n}\n\n\n"}, {"source_code": "fun main(args: Array) {\n\n val otherStrings = arrayOf(\"a\", \"o\", \"y\", \"e\", \"u\", \"i\")\n val line = readLine()!!.toLowerCase()\n val chars = line.toCharArray()\n for (item in chars){\n if(!otherStrings.contains(\"\" + item)){\n print(\".\" + item)\n }\n }\n\n\n\n}"}, {"source_code": "val vowels = arrayOf('a', 'o', 'y', 'e', 'u', 'i')\n\nfun main(args: Array){\n val string = readLine() ?: \"\"\n var result = \"\"\n for(char in string){\n if (isConsonant(char))\n result += \".\" + char.toLowerCase()\n }\n println(result)\n}\n\nfun isConsonant(char: Char): Boolean{\n return !(char.toLowerCase() in vowels)\n}"}, {"source_code": "import java.lang.StringBuilder\nimport java.util.Scanner\n\n fun main() {\n val scanner = Scanner(System.`in`)\n val word: String = scanner.nextLine()\n val result = StringBuilder()\n\n for(char:Char in word.toLowerCase()) {\n if(!\"aoyeui\".contains(char)){\n result.append(\".$char\")\n }\n }\n print(result.toString())\n }"}, {"source_code": "fun main(arg: Array){\n val s = readLine()!!\n val b = arrayOf('a','e','y','u','i','o')\n println('.'+s.toLowerCase().filter { it !in b }.asIterable().joinToString(separator = \".\"))\n}"}, {"source_code": " fun main(args: Array) {\n val vowels = \"aAoOyYeEuUiI\"\n val str = readLine()!!\n var newStr = \"\"\n for (c: Char in str) {\n if (!(c in vowels)) {\n newStr += \".\" + c.toLowerCase()\n }\n }\n println(newStr)\n }"}, {"source_code": "import java.util.*\n\nfun main(আ : Array) {\n val দ: Scanner = Scanner(System.`in`)\n var ফ = arrayOf('a','e','i','o','u','y')\n var স = দ.nextLine()\n for (ম in স.toLowerCase()) {\n if(ম !in ফ) {\n print(\".$ম\")\n }\n }\n}"}, {"source_code": "fun main(args: Array)\n{\n val s = readLine()!!.toLowerCase()\n val glas = \"aoyeui\"\n var sb = StringBuilder()\n for (c in s)\n {\n if (c !in glas)\n sb.append(\".$c\")\n }\n println(sb)\n}"}, {"source_code": "fun main() {\n var str = readStr()!!.toLowerCase().toCharArray()\n\n var vowels = \"aoyeui\"\n\n for (i in str) {\n if (!vowels.contains(i)){\n print('.')\n print(i)\n }\n }\n}\n\n\nprivate fun readInts(): List = readLine()!!.split(' ').map { it.toInt() }\nprivate fun readLongs(): List = readLine()!!.split(' ').map { it.toLong() }\nprivate fun readInt(): Int = readLine()!!.toInt()\nprivate fun readLong(): Long = readLine()!!.toLong()\nprivate fun readStr(): String? = readLine()!!"}, {"source_code": "import java.io.BufferedOutputStream\nimport java.io.PrintWriter\nimport java.util.*\n\n\n\nfun fn1 (x : String) : String{\n var res = \"\"\n val v = setOf('a', 'e', 'i', 'o', 'u','y')\n for (w in x){\n if (v.contains(w.toLowerCase())){\n continue\n }\n res += \".${w.toLowerCase()}\"\n }\n return res\n}\n\nfun main() {\n val sc = Scanner(System.`in`)\n val out = PrintWriter(BufferedOutputStream(System.out))\n\n// val testCases = sc.nextInt()\n//\n// val a = mutableListOf>()\n//\n// for (i in 0..testCases) {\n// val word = sc.nextLine().split(\" \")\n// for (w in word) out.println(w)\n// a.add(word)\n// }\n val tescase = sc.nextLine()\n out.println(fn1(tescase))\n out.close()\n sc.close()\n}"}, {"source_code": "fun main(args: Array) {\n val vowels = arrayOf('a', 'o', 'e', 'u', 'i', 'y')\n val word = readLine()!!\n println(word.toLowerCase().filter { !vowels.contains(it) }.map { \".$it\" }.joinToString(separator = \"\"))\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n println(\".\" + sc.nextLine().toLowerCase().replace(\"a|e|o|i|u|y\".toRegex(),\"\").toCharArray().joinToString(\".\"))\n\n}\n\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array){\n val scan = Scanner(System.`in`)\n var word = scan.next().toLowerCase()\n val glas = arrayOf(\"a\", \"o\", \"y\", \"e\", \"u\", \"i\")\n val nGlas = arrayOf(\"b\", \"c\", \"d\", \"f\", \"g\", \"h\", \"j\", \"k\", \"l\", \"m\", \"n\", \"p\", \"q\", \"r\", \"s\", \"t\", \"v\", \"w\", \"x\", \"z\")\n\n for (i in glas){\n word = word.replace(i, \"\")\n }\n for (i in nGlas) word = word.replace(i,\".$i\")\n print(word)\n}"}, {"source_code": "fun main() {\n val word = readLine()\n\n println(word!!.toLowerCase()\n .replace(\"[aoyeui]\".toRegex(), \"\")\n .replace(\".\".toRegex()) { \".\" + it.value }\n )\n}"}, {"source_code": "import java.util.Scanner\n\n/**\n *Created by Kartik Patodi on 28-05-2017.\n **/\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n var s = sc.nextLine()\n s = s.stringTask()\n println(s)\n}\n\nfun String.stringTask() = this.replace(\"[aeiouyAEIOUY]+\".toRegex(), \"\").toLowerCase().replace(\"\", \".\").dropLast(1)\n\n"}, {"source_code": "fun main() {\n var s = readLine()!!\n s = s.toLowerCase()\n var arr = listOf('a', 'i', 'o', 'y', 'e', 'u')\n for (c in s) {\n if(c !in arr){\n print('.')\n print(c)\n }\n }\n}\n"}, {"source_code": "fun main() {\n println(readLine()!!.asSequence()\n .map { it.toLowerCase() }\n .filter { it !in setOf('a', 'e', 'i', 'o', 'u', 'y') }\n .map { \".$it\" }\n .joinToString(\"\"))\n}"}, {"source_code": "fun main(args: Array) {\n readLine()!!\n .toLowerCase()\n .replace(\"[aoyeui]\".toRegex(), \"\")\n .forEach { print(\".$it\") }\n}"}, {"source_code": "fun main(args: Array) {\n val vowels = arrayOf('a', 'o', 'y', 'e', 'u', 'i')\n val string = readLine()!!;\n println(string.toLowerCase().filter { it !in vowels }.map { \".$it\" }.joinToString(separator = \"\"))\n}"}, {"source_code": "fun main(args: Array) {\n val str = readLine()!!.toLowerCase().replace(Regex(\"[AaEeIiOoYyUu]\"), \"\")\n println(str.replace(Regex(\"(?i)([bcdfghjklmnpqrstvwxyz])\"), \".$1\"))\n}"}, {"source_code": "fun main(){\n var someInput = readLine()!!\n var glasnie = arrayOf(\"A\", \"O\", \"Y\", \"E\", \"U\", \"I\",\"a\",\"o\",\"y\",\"e\",\"u\",\"i\")\n var propisnie = arrayOf(\"Q\",\"W\",\"R\",\"T\",\"P\",\"S\",\"D\",\"F\",\"G\",\"H\",\"J\",\"K\",\"L\",\"Z\",\"X\",\"C\",\"V\",\"B\",\"N\",\"M\")\n var strochnie = arrayOf(\"q\",\"w\",\"r\",\"t\",\"p\",\"s\",\"d\",\"f\",\"g\",\"h\",\"j\",\"k\",\"l\",\"z\",\"x\",\"c\",\"v\",\"b\",\"n\",\"m\")\n var someOutput =\"\"\n var count = 0\n var count2 = 0\n\n for (i in (0..someInput.length-1)){\n count = 0\n for (element in glasnie) {\n if (someInput[i].toString() == element) count++\n }\n if (count == 0){\n count2 = 0\n for (j in 0..19){\n if (someInput[i].toString() == propisnie[j]){\n count2++\n someOutput =someOutput + \".\" + strochnie[j]\n }\n }\n if (count2 ==0) someOutput =someOutput + \".\" + someInput[i]\n }\n }\n println(someOutput)\n }\n"}, {"source_code": "fun main() = readLine()!!.toLowerCase().forEach { if (it !in arrayOf('a', 'e', 'o', 'u', 'i', 'y')) print(\".$it\") }"}, {"source_code": "import java.lang.StringBuilder\n\nfun main() {\n \n val input = readLine()\n\n if (input == null) {\n return\n }\n\n val vowels: String = \"AOYEUI\"\n\n val result: StringBuilder = StringBuilder()\n\n input.forEach {\n\n if (vowels.contains(it, ignoreCase = true) == false) {\n result.append(\".\" + it.toLowerCase())\n }\n\n }\n\n println(result.toString())\n\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n var s:String = br.readLine()!!.toLowerCase()\n var set = hashSetOf('a','e','o','y','u','i')\n var res:StringBuilder = StringBuilder()\n for(c in s.toCharArray())\n if(!set.contains(c))\n res.append(\".$c\")\n println(res)\n}"}, {"source_code": "fun main(args:Array){\n var str = readLine()!!.toLowerCase()\n\n for(i in 0 until str.length){\n if(str[i] != 'a' && str[i] != 'o' && str[i] != 'y' && str[i] != 'e' && str[i] != 'u' && str[i] != 'i') {\n print(\".\")\n print(str[i])\n }\n }\n}"}, {"source_code": "fun main() {\n val vowels = \"aoyeui\"\n var result = \"\"\n val input = readLine()!!\n input.forEach {\n val c = it.toLowerCase()\n if(c !in vowels) {\n result += \".$c\"\n }\n }\n println(result)\n}"}, {"source_code": "fun main(args: Array) {\n\n val letters = arrayListOf('a', 'o', 'y', 'e', 'u', 'i')\n var input = readLine()!!\n\n input = input.toLowerCase()\n\n var result = \"\"\n\n (0 until input.length)\n .filter { letters.indexOf(input[it]) == -1 }\n .forEach { result += \".\" + input[it] }\n\n println(result)\n}"}, {"source_code": "import java.util.*\n\nprivate val scan = Scanner(System.`in`)\n\nfun main(args: Array) {\n\n scan.next()\n .toLowerCase()\n .filter { it !in listOf('a', 'e', 'i', 'o', 'u', 'y') }\n .flatMap { listOf('.', it) }\n .joinToString(separator = \"\")\n .run { println(this) }\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val input = reader.readLine()\n println(process(input))\n}\n\nfun process(input: String): String {\n val stringBuilder = StringBuilder()\n val tmpStr = input.toLowerCase().replace(Regex(\"[aoyeui]\"), \"\")\n tmpStr.forEach {\n stringBuilder.append('.')\n stringBuilder.append(it)\n }\n return stringBuilder.toString()\n}\n"}, {"source_code": "fun main() {\n val vowels = setOf('a', 'o', 'y', 'e', 'u', 'i')\n val s = readLine()!!\n val result = s.toLowerCase().filterNot { it in vowels }.toList().joinToString(\".\", \".\")\n println(result)\n}\n"}, {"source_code": "fun main() {\n val x = readLine()!!.toLowerCase()\n println(x.replace(\"[aoyeui]+\".toRegex(), \"\").replace(\"(.)\".toRegex(), \".$1\"))\n}"}, {"source_code": "fun main(args: Array) {\n readLine()!!\n .toLowerCase()\n .replace(\"[aoyeui]\".toRegex(), \"\")\n .forEach { print(\".$it\") }\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n\n val chars = arrayListOf('a', 'o', 'y', 'e', 'u', 'i')\n\n val word = Scanner(System.`in`).nextLine()\n\n word.map { if (it.toLowerCase() in chars) \"\" else \".\" + it.toLowerCase() }\n .forEach { print(it) }\n}\n\n"}, {"source_code": "//https://www.google.com/search?q=codeforces+watermelon&oq=codeforces+water&aqs=chrome.0.69i59j69i57j0l6.1995j0j1&sourceid=chrome&ie=UTF-8\n\nfun main() {\n\tvar input = readLine()!!.toString() // read integer from the input\n println(convert(input)) // print answer to the output\n}\n\nval vowels = setOf('A', 'O', 'Y', 'E', 'U', 'I', 'a', 'o', 'y', 'e', 'u', 'i')\n\nfun convert(input: String): String {\n\tval builder = StringBuilder()\n\tinput.forEach label@ { c: Char ->\n\t\tif (vowels.contains(c)) {\n\t\t\treturn@label\n\t\t}\n\t\tbuilder.append('.')\n\t\tif (c.isUpperCase()) {\n\t\t\tbuilder.append(c.toLowerCase())\n\t\t} else {\n\t\t\tbuilder.append(c)\n\t\t}\n\t}\n\treturn builder.toString()\n}"}, {"source_code": "fun main(args: Array) {\n solve()\n}\n\nfun solve() {\n val vowels = arrayOf('a', 'o', 'y', 'e', 'u', 'i')\n val chars = readLine()!!\n chars.map {\n val ch = it.toLowerCase()\n if (ch !in vowels) {\n print(\".$ch\")\n }\n }\n}\n"}, {"source_code": "\nimport java.util.*\n\n/**\n * Created by AoEiuV020 on 2017/05/09.\n */\nfun main(vararg args: String) {\n val str = readLine()!!\n str.map {\n it.toLowerCase()\n }.filterNot {\n it in \"aoyeui\"\n }.forEach {\n print(\".$it\")\n }\n}\n"}, {"source_code": "fun main(){\n val input = readLine()!!.toLowerCase().replace(\"[aoyeui]\".toRegex(),\"\")\n for(i in input){\n print(\".$i\")\n }\n}"}, {"source_code": "import java.lang.StringBuilder\n\nfun main() {\n val s = readLine()!!.toLowerCase().replace(Regex(\"[aeyuio]\"), \"\")\n val result = StringBuilder()\n s.forEach { result.append(\".$it\") }\n println(result)\n}"}, {"source_code": "fun main()\n{\n\n var x = readLine()\n x = x!!.toLowerCase()\n var a : String = \"\"\n for (c in x)\n {\n if (c!='o' && c!='i' && c!='u'&&c!='e'&&c!='y' && c!='a')\n {\n a+=\".$c\"\n }\n }\n println(a)\n}"}, {"source_code": "fun main() {\n print(readLine()!!.toLowerCase().split(\"\").filter {\n !\"A,O,Y,E,U,I\".split(\",\").map(String::toLowerCase).contains(it)\n }.dropLast(1).joinToString(separator = \".\"))\n}"}, {"source_code": "fun main(args: Array) {\n var word = readLine()!!.toUpperCase().replace(\"A\", \"\")\n .replace(\"O\", \"\")\n .replace(\"Y\", \"\")\n .replace(\"E\", \"\")\n .replace(\"U\", \"\")\n .replace(\"I\", \"\")\n .toLowerCase()\n\n val array = word.toCharArray()\n var result = \"\"\n for (ch in array) {\n result += \".$ch\"\n }\n println(result)\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n var scanner = Scanner(System.`in`)\n var a = scanner.next()\n a = a.toLowerCase()\n for(i in a.length-1 downTo 0){\n if(a[i] == 'a' || a[i]=='o'|| a[i]=='y'|| a[i]=='e'|| a[i]=='u'|| a[i]=='i') a = a.replace(\"${a[i]}\",\" \")\n }\n a = a.replace(\" \", \"\")\n var b:String =\"\"\n for(c in a){\n b=b.plus('.').plus(c)\n }\n println(b)\n}\n"}, {"source_code": "/**\n * Created by rohit.jh on 21/01/18\n */\nfun applyOperations(a: Char): String {\n val x = a.toLowerCase()\n return if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u' || x == 'y') \"\"\n else \".$x\"\n}\n\nfun main(args: Array) {\n val str: String = readLine()!!\n for (i in 0 until str.length) {\n print(applyOperations(str[i]))\n }\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val token = StringTokenizer(br.readLine())\n val input = token.nextToken()\n\n val sb = StringBuilder()\n for (i in input.indices) {\n when (input[i]) {\n 'A', 'O', 'Y', 'E', 'U', 'I', 'a', 'o', 'y', 'e', 'u', 'i' -> {\n continue\n }\n else -> {\n sb.append('.')\n sb.append(input[i].toString().toLowerCase(Locale.ROOT))\n }\n }\n }\n println(sb)\n br.close()\n}"}, {"source_code": "import java.util.Scanner\n\n\nfun main(args: Array) {\n\tval inp = Scanner(System.`in`)\n\tvar word: String = inp.next().toLowerCase()\n\tvar charArray = word.toCharArray()\n\t\n\tfor(letter in charArray) {\n\t\tif(letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u' || letter == 'y') {\n\t\t\tcontinue\n\t\t} else {\n\t\t\tprint(\".$letter\")\n\t\t}\n\t}\n}\n"}, {"source_code": "fun main(args: Array) {\n var s = readLine()!!\n s = s.replace(Regex(\"[aeyuioAEYUOI]\"), \"\")\n\n var res = \"\"\n\n s.forEach {\n res += \".${it.toLowerCase()}\"\n }\n\n print(res)\n}"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() = output {\n val string = read()\n val result = string\n .toLowerCase()\n .replace(Regex(\"[aeiouy]\"), \"\")\n .replace(Regex(\".\")) {\n \".${it.value}\"\n }\n\n println(result)\n}\n\n@JvmField\nval INPUT = System.`in`\n\n@JvmField\nval OUTPUT = System.out\n\n@JvmField\nval _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n\n@JvmField\nvar _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\n\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField\nval _writer = PrintWriter(OUTPUT, false)\n\nfun output(block: PrintWriter.() -> Unit) {\n _writer.apply(block).flush()\n}\n\n\n"}, {"source_code": "fun main()\n{\n var s = readLine()!!.toString()\n for (p in s)\n {\n var c = p.toLowerCase()\n if(c!='a' && c!='e' && c!='i' && c!='o' && c!='u' && c!='y')\n print(\".$c\")\n }\n}"}, {"source_code": "\n\nfun main()\n{\n var st = readLine()!!\n st = st.toLowerCase()\n var s : String = \"\"\n val arr = arrayOf('a','o','y','e','u','i')\n for(i in st)\n {\n if(i !in arr)\n {\n s = s.plus(\".\"+i)\n }\n }\n println(s)\n}"}, {"source_code": "import java.util.*\n\n\nfun main(){\n\n val read = Scanner(System.`in`)\n val s = read.nextLine().toLowerCase()\n for(i in 0 until s.length) if((s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y'))\n continue\n else print(\".\"+s[i])\n }"}, {"source_code": "import java.util.*\n\nfun isVowel(c : Char): Boolean = c.toUpperCase() in \"AEIOUY\"\n\nfun main(args : Array) {\n val scan = Scanner (System.`in`)\n val s = scan.next()\n val r = StringBuilder()\n for ( c in s )\n if ( !isVowel(c) ){\n r.append('.')\n r.append(c.toLowerCase())\n }\n println(r)\n}"}, {"source_code": "fun main() {\n val input = readLine()!!\n val vowels = Regex(\"[aoyeui]\")\n val intermed = vowels.replace(input.toLowerCase(), \"\")\n var answer = \"\"\n for(i in 0..intermed.length - 1){\n answer += \".\" + intermed[i]\n }\n print(answer)\n}"}, {"source_code": "/* template start */\n// input\nprivate fun readString() = readLine()!!\nprivate fun readStrings() = readString().split(\" \")\nprivate fun readInt() = readString().toInt()\nprivate fun readDigits() = readString().map { it - '0' }\nprivate fun readInts() = readStrings().map { it.toInt() }\nprivate fun readLongs() = readStrings().map { it.toLong() }\n\n// output\nprivate fun T.print(map: (T) -> String = { it.toString() }) = println(map(this))\nprivate fun Iterable.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)\nprivate fun Array.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)\nprivate fun Sequence.print(sep: String? = null, map: ((T) -> String)? = null) =\n println(joinToString(sep ?: \"\", transform = map ?: { it.toString() }))\n\n// various\nprivate val Int.isEven: Boolean get() = this % 2 == 0\nprivate val Int.isOdd: Boolean get() = !this.isEven\nprivate fun queries(block: (Int) -> Unit) = repeat(readInt(), block)\n\n/* template end */\n\nfun main() {\n val input = readString()\n buildString {\n for (c in input) {\n val c = c.toLowerCase()\n if (c !in setOf('a', 'e', 'i', 'o', 'u','y')) {\n append('.')\n append(c)\n }\n }\n }.print()\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n\n val s = reader.readLine()\n println(s.toLowerCase()\n .replace(Regex(\"\"\"[aoyeui]\"\"\"), \"\")\n .replace(Regex(\"\"\"[a-z]\"\"\")) { \".\" + it.value })\n}"}], "negative_code": [{"source_code": "// kotlin oj template code from uwi(Codeforces), and convert to kotlin by lety\nimport java.io.ByteArrayInputStream\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport java.util.InputMismatchException\n\nlateinit var `is`: InputStream\nlateinit var out: PrintWriter\nvar INPUT = \"\"\n\n//val oj = System.getProperty(\"ONLINE_JUDGE\") != null\nval oj = true\nval inbuf = ByteArray(1024)\nvar lenbuf = 0\nvar ptrbuf = 0\n\n\nfun solve() {\n val s = ns()\n\n s.forEach {\n if(it in \"aeiou\")\n {\n }\n else\n {\n print('.')\n\n if(it.isUpperCase())\n {\n print(it.toLowerCase())\n }\n else\n {\n print(it)\n }\n }\n }\n\n}\n\nfun main() {\n `is` = if (oj) System.`in` else ByteArrayInputStream(INPUT.toByteArray())\n out = PrintWriter(System.out)\n\n val s = System.currentTimeMillis()\n solve()\n out.flush()\n tr((System.currentTimeMillis() - s).toString() + \"ms\")\n}\n\nprivate fun readByte(): Int {\n if (lenbuf == -1) throw InputMismatchException()\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0\n try {\n lenbuf = `is`.read(inbuf)\n } catch (e: IOException) {\n throw InputMismatchException()\n }\n\n if (lenbuf <= 0) return -1\n }\n return inbuf[ptrbuf++].toInt()\n}\n\nprivate fun isSpaceChar(c: Int): Boolean = !(c >= 33 && c <= 126)\n\nprivate fun skip(): Int {\n var b: Int = readByte()\n while (b != -1 && isSpaceChar(b)) {\n b = readByte()\n }\n return b\n}\n\n// using ns()\nprivate fun nd(): Double = ns().toDouble()\n\n// using ns()\nprivate fun nc(): Char = skip().toChar()\n\n// input until whitespace\nprivate fun ns(): String {\n var b = skip()\n val sb = StringBuilder()\n while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b)\n b = readByte()\n }\n return sb.toString()\n}\n\nprivate fun ns(n: Int): CharArray {\n val buf = CharArray(n)\n var b = skip()\n var p = 0\n while (p < n && !isSpaceChar(b)) {\n buf[p++] = b.toChar()\n b = readByte()\n }\n return if (n == p) buf else Arrays.copyOf(buf, p)\n}\n\n// matrix\nprivate fun nm(n: Int, m: Int): Array {\n val map = Array(n) { CharArray(m) }\n for (i in 0 until n) map[i] = ns(m)\n return map\n}\n\nprivate fun pm(matrix: Array) {\n val n = matrix.size\n val m = matrix[0].size\n repeat(n)\n {\n repeat(m)\n { jt ->\n out.print(matrix[it][jt])\n }\n out.println()\n }\n out.flush()\n}\n\n// int array\nprivate fun na(n: Int): IntArray {\n val a = IntArray(n)\n for (i in 0 until n) a[i] = ni()\n return a\n}\n\nprivate fun ni(): Int {\n var num = 0\n var b: Int = readByte()\n var minus = false\n while (b != -1 && !(b >= '0'.toInt() && b <= '9'.toInt() || b == '-'.toInt())) {\n b = readByte()\n }\n if (b == '-'.toInt()) {\n minus = true\n b = readByte()\n }\n\n while (true) {\n if (b >= '0'.toInt() && b <= '9'.toInt()) {\n num = num * 10 + (b - '0'.toInt())\n } else {\n return if (minus) -num else num\n }\n b = readByte()\n }\n}\n\nprivate fun nl(): Long {\n var num: Long = 0\n var b: Int = readByte()\n var minus = false\n while (b != -1 && !(b >= '0'.toInt() && b <= '9'.toInt() || b == '-'.toInt())) {\n b = readByte()\n }\n if (b == '-'.toInt()) {\n minus = true\n b = readByte()\n }\n\n while (true) {\n if (b >= '0'.toInt() && b <= '9'.toInt()) {\n num = num * 10 + (b - '0'.toInt())\n } else {\n return if (minus) -num else num\n }\n b = readByte()\n }\n}\n\nprivate fun tr(vararg o: Any) {\n// if (!oj) println(Arrays.deepToString(o))\n}\n\n"}, {"source_code": "// kotlin oj template code from uwi(Codeforces), and convert to kotlin by lety\nimport java.io.ByteArrayInputStream\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport java.util.InputMismatchException\n\nlateinit var `is`: InputStream\nlateinit var out: PrintWriter\nvar INPUT = \"\"\n\n//val oj = System.getProperty(\"ONLINE_JUDGE\") != null\nval oj = true\nval inbuf = ByteArray(1024)\nvar lenbuf = 0\nvar ptrbuf = 0\n\n\nfun solve() {\n val s = ns()\n\n s.forEach {\n if(it in \"aeiouAEIOU\")\n {\n }\n else\n {\n print('.')\n\n if(it.isUpperCase())\n {\n print(it.toLowerCase())\n }\n else\n {\n print(it)\n }\n }\n }\n\n}\n\nfun main() {\n `is` = if (oj) System.`in` else ByteArrayInputStream(INPUT.toByteArray())\n out = PrintWriter(System.out)\n\n val s = System.currentTimeMillis()\n solve()\n out.flush()\n tr((System.currentTimeMillis() - s).toString() + \"ms\")\n}\n\nprivate fun readByte(): Int {\n if (lenbuf == -1) throw InputMismatchException()\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0\n try {\n lenbuf = `is`.read(inbuf)\n } catch (e: IOException) {\n throw InputMismatchException()\n }\n\n if (lenbuf <= 0) return -1\n }\n return inbuf[ptrbuf++].toInt()\n}\n\nprivate fun isSpaceChar(c: Int): Boolean = !(c >= 33 && c <= 126)\n\nprivate fun skip(): Int {\n var b: Int = readByte()\n while (b != -1 && isSpaceChar(b)) {\n b = readByte()\n }\n return b\n}\n\n// using ns()\nprivate fun nd(): Double = ns().toDouble()\n\n// using ns()\nprivate fun nc(): Char = skip().toChar()\n\n// input until whitespace\nprivate fun ns(): String {\n var b = skip()\n val sb = StringBuilder()\n while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b)\n b = readByte()\n }\n return sb.toString()\n}\n\nprivate fun ns(n: Int): CharArray {\n val buf = CharArray(n)\n var b = skip()\n var p = 0\n while (p < n && !isSpaceChar(b)) {\n buf[p++] = b.toChar()\n b = readByte()\n }\n return if (n == p) buf else Arrays.copyOf(buf, p)\n}\n\n// matrix\nprivate fun nm(n: Int, m: Int): Array {\n val map = Array(n) { CharArray(m) }\n for (i in 0 until n) map[i] = ns(m)\n return map\n}\n\nprivate fun pm(matrix: Array) {\n val n = matrix.size\n val m = matrix[0].size\n repeat(n)\n {\n repeat(m)\n { jt ->\n out.print(matrix[it][jt])\n }\n out.println()\n }\n out.flush()\n}\n\n// int array\nprivate fun na(n: Int): IntArray {\n val a = IntArray(n)\n for (i in 0 until n) a[i] = ni()\n return a\n}\n\nprivate fun ni(): Int {\n var num = 0\n var b: Int = readByte()\n var minus = false\n while (b != -1 && !(b >= '0'.toInt() && b <= '9'.toInt() || b == '-'.toInt())) {\n b = readByte()\n }\n if (b == '-'.toInt()) {\n minus = true\n b = readByte()\n }\n\n while (true) {\n if (b >= '0'.toInt() && b <= '9'.toInt()) {\n num = num * 10 + (b - '0'.toInt())\n } else {\n return if (minus) -num else num\n }\n b = readByte()\n }\n}\n\nprivate fun nl(): Long {\n var num: Long = 0\n var b: Int = readByte()\n var minus = false\n while (b != -1 && !(b >= '0'.toInt() && b <= '9'.toInt() || b == '-'.toInt())) {\n b = readByte()\n }\n if (b == '-'.toInt()) {\n minus = true\n b = readByte()\n }\n\n while (true) {\n if (b >= '0'.toInt() && b <= '9'.toInt()) {\n num = num * 10 + (b - '0'.toInt())\n } else {\n return if (minus) -num else num\n }\n b = readByte()\n }\n}\n\nprivate fun tr(vararg o: Any) {\n// if (!oj) println(Arrays.deepToString(o))\n}\n\n"}, {"source_code": "fun main()\n{\n val given = readLine()!!\n var answer = \"\"\n for (i in given)\n {\n if (! \"AEIOUaeiou\".contains(i))\n {\n answer += \".\"+i.toLowerCase()\n }\n }\n println(answer)\n}"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\nfun main() { _writer.solve(); _writer.flush() }\n\nfun PrintWriter.solve() {\n var result = readLn()\n result.toLowerCase()\n result = result.replace(\"a\",\"\")\n result = result.replace(\"e\",\"\")\n result = result.replace(\"y\",\"\")\n result = result.replace(\"u\",\"\")\n result = result.replace(\"i\",\"\")\n result = result.replace(\"o\",\"\")\n var newChars = \"\"\n for (i in 0 until result.length) {\n newChars = newChars.plus(\".\").plus(result[i])\n }\n println(newChars.toString())\n}\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\nfun main() { _writer.solve(); _writer.flush() }\n\nfun PrintWriter.solve() {\n var result = readLn()\n result.toLowerCase()\n result.removeVowels()\n var newChars = \"\"\n for (i in 0 until result.length) {\n newChars = \".\".plus(result[i])\n }\n println(newChars.toString())\n}\n\nfun String.removeVowels() {\n this.replace(\"a\",\"\",false)\n this.replace(\"e\",\"\",false)\n this.replace(\"y\",\"\",false)\n this.replace(\"u\",\"\",false)\n this.replace(\"i\",\"\",false)\n this.replace(\"o\",\"\",false)\n}\n\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\nfun main() { _writer.solve(); _writer.flush() }\n\nfun PrintWriter.solve() {\n var result = readLn()\n result.toLowerCase()\n result.removeVowels()\n var newChars = \"\"\n for (i in 0 until result.length) {\n newChars = \".\".plus(result[i])\n }\n println(result)\n}\n\nfun String.removeVowels() {\n this.replace(\"a\",\"\",false)\n this.replace(\"e\",\"\",false)\n this.replace(\"y\",\"\",false)\n this.replace(\"u\",\"\",false)\n this.replace(\"i\",\"\",false)\n this.replace(\"o\",\"\",false)\n}\n\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\nfun main() { _writer.solve(); _writer.flush() }\n\nfun PrintWriter.solve() {\n var result = readLn()\n result.toLowerCase()\n result = result.replace(\"a\",\"\")\n result = result.replace(\"e\",\"\")\n result = result.replace(\"y\",\"\")\n result = result.replace(\"u\",\"\")\n result = result.replace(\"i\",\"\")\n result = result.replace(\"o\",\"\")\n var newChars = \"\"\n for (i in 0 until result.length) {\n newChars = newChars.plus(\".\").plus(result[i])\n }\n println(result)\n}\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()"}, {"source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n Scanner(System.`in`).use {\n val result = it.next().formatWithDots()\n println(result)\n }\n}\n\nfun String.formatWithDots(): String {\n val builder = StringBuilder()\n val dot = \".\"\n for (char in this) {\n if (char.isVowel()) {\n continue\n }\n builder.append(dot).append(Character.toLowerCase(char))\n }\n return builder.toString()\n}\n\nfun Char.isVowel() = when (this) {\n 'a', 'A', 'o', 'O', 'e', 'E', 'u', 'U', 'i', 'I' -> true\n else -> false\n}"}, {"source_code": "import java.util.*\n\n fun main(){\n var input = Scanner(System.`in`)\n var programString = input.nextLine()\n var string =\"\"\n programString.toLowerCase().replace(\"a\",\"\")\n programString.toLowerCase().toCharArray().forEach {\n string =string+changeChar(it)\n }\n System.out.println(string)\n }\n\nfun changeChar(char : Char) : String{\n if(char == 'a' || char == 'e' || char == 'i' || char == 'o' || char == 'u'){\n return \"\"\n }else if(char == 'y' || char == 'z'){\n return char.toString()\n }else{\n return \".${char}\"\n }\n}\n\n\n\n\n"}, {"source_code": "import java.util.*\n\n fun main(){\n var input = Scanner(System.`in`)\n var programString = input.nextLine()\n var string =\"\"\n programString.toLowerCase().toCharArray().forEach {\n string =string+changeChar(it)\n }\n System.out.println(string)\n }\n\nfun changeChar(char : Char) : String{\n if(char == 'a' || char == 'e' || char == 'i' || char == 'o' || char == 'u'){\n return \"\"\n }else{\n return \".${char}\"\n }\n}\n\n\n\n\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val vowels = hashSetOf('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U')\n val br = BufferedReader(InputStreamReader(System.`in`))\n val s = br.readLine()\n val newS = s.filter { c -> !(c in vowels) }\n .map { c -> if (c.isUpperCase()) c.toLowerCase() else c}\n .joinToString(\".\")\n println(\".$newS\")\n}"}, {"source_code": "//package problem118a\n\nimport java.lang.StringBuilder\n\nfun convertWord(word: String): String {\n val initialModifications = word.toLowerCase().filter { \"aeiou\".indexOf(it) == -1 }\n\n val result = StringBuilder()\n for (char in initialModifications) {\n result.append(\".$char\")\n }\n\n return result.toString()\n}\n\nfun main() {\n val input = readLine()!!\n println(convertWord(input))\n}\n"}, {"source_code": "//package problem118a\n\nimport java.lang.StringBuilder\n\nfun convertWord(word: String): String {\n val initialModifications = word.filter { \"aeiou\".indexOf(it) == -1 }\n\n val result = StringBuilder()\n for (char in initialModifications) {\n result.append(\".$char\")\n }\n\n return result.toString().toLowerCase()\n}\n\nfun main() {\n val input = readLine()!!\n println(convertWord(input))\n}\n"}, {"source_code": "//package problem118a\n\nimport java.lang.StringBuilder\n\nfun convertWord(word: String): String {\n val initialModifications = word.filter { \"aeiouAEIOU\".indexOf(it) == -1 }\n\n val result = StringBuilder()\n for (char in initialModifications) {\n result.append(\".$char\")\n }\n\n return result.toString().toLowerCase()\n}\n\nfun main() {\n val input = readLine()!!\n println(convertWord(input))\n}\n"}, {"source_code": "fun main(args: Array) {\n\n val otherStrings = arrayOf(\"a\", \"o\", \"y\", \"e\", \"u\", \"i\")\n val line = readLine()!!.toLowerCase()\n val chars = line.toCharArray()\n for (item in chars){\n if(otherStrings.contains(\"\" + item)){\n print(\".\")\n }\n else {\n print(item)\n }\n }\n\n\n\n}"}, {"source_code": "import java.lang.StringBuilder\nimport java.util.Scanner\n\n fun main() {\n val scanner = Scanner(System.`in`)\n val word: String = scanner.nextLine()\n val result = StringBuilder()\n\n for(char:Char in word) {\n if(!\"aoyeui\".contains(char.toLowerCase())){\n result.append(\".$char\")\n }\n }\n print(result.toString())\n }"}, {"source_code": "fun main(arg: Array){\n val s = readLine()!!\n val b = arrayOf('a','e','y','u','i','o')\n println(s.toLowerCase().filter { it !in b }.asIterable().joinToString(separator = \".\"))\n}"}, {"source_code": "import java.io.BufferedOutputStream\nimport java.io.PrintWriter\nimport java.util.*\n\n\n\nfun fn1 (x : String) : String{\n var res = \"\"\n val v = setOf('a', 'e', 'i', 'o', 'u')\n for (w in x){\n if (v.contains(w)){\n continue\n }\n res += \".${w.toLowerCase()}\"\n }\n return res\n}\n\nfun main() {\n val sc = Scanner(System.`in`)\n val out = PrintWriter(BufferedOutputStream(System.out))\n\n// val testCases = sc.nextInt()\n//\n// val a = mutableListOf>()\n//\n// for (i in 0..testCases) {\n// val word = sc.nextLine().split(\" \")\n// for (w in word) out.println(w)\n// a.add(word)\n// }\n val tescase = sc.nextLine()\n out.println(fn1(tescase))\n out.close()\n sc.close()\n}"}, {"source_code": "import java.util.Scanner\n\n/**\n *Created by Kartik Patodi on 28-05-2017.\n **/\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n var s = sc.nextLine()\n s = s.stringTask().substring(0..s.length-1)\n println(s)\n}\n\nfun String.stringTask() = this.replace(\"[aeiouAEIOU]+\".toRegex(), \"\").toLowerCase().replace(\"\", \".\")\n\n"}, {"source_code": "import java.util.Scanner\n\n/**\n *Created by Kartik Patodi on 28-05-2017.\n **/\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n var s = sc.nextLine()\n s = s.stringTask()\n println(s)\n}\n\nfun String.stringTask() = this.replace(\"[aeiouAEIOU]+\".toRegex(), \"\").toLowerCase().replace(\"\", \".\").substring(0..this.length-2)\n\n"}, {"source_code": "import java.util.Scanner\n\n/**\n *Created by Kartik Patodi on 28-05-2017.\n **/\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n var s = sc.nextLine()\n s = s.stringTask()\n println(s)\n}\n\nfun String.stringTask() = this.replace(\"[aeiouAEIOU]+\".toRegex(), \"\").toLowerCase().replace(\"\", \".\").dropLast(1)\n\n"}, {"source_code": "import java.util.Scanner\n\n/**\n *Created by Kartik Patodi on 28-05-2017.\n **/\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n var s = sc.nextLine()\n s=s.stringTask()\n when(s){\n \".\" -> println(\"\")\n else -> println(s)\n }\n}\n\nfun String.stringTask() = this.replace(\"[aeiou]\".toRegex(),\"\").replace(\"\",\".\")\n\n"}, {"source_code": "import java.util.Scanner\n\n/**\n *Created by Kartik Patodi on 28-05-2017.\n **/\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n var s = sc.nextLine()\n s=s.stringTask()\n when(s){\n \".\" -> println(\"\")\n else -> println(s.substring(0 until s.length))\n }\n}\n\nfun String.stringTask() = this.replace(\"[aeiou]\".toRegex(),\"\").replace(\"\",\".\")\n\n"}, {"source_code": "fun main(args: Array) {\n val str = readLine()!!.toLowerCase().replace(Regex(\"[AaEeIiOoUu]\"), \"\")\n println(str.replace(Regex(\"(?i)([bcdfghjklmnpqrstvwxyz])\"), \".$1\"))\n}\n"}, {"source_code": "\nimport java.lang.StringBuilder\n \nfun main(args: Array) {\n \n val vowels: String = \"AOYEUI\"\n \n if (args.size < 1) {\n return\n }\n \n val input = args[0]\n \n val result: StringBuilder = StringBuilder()\n \n input.forEach {\n \n if (vowels.contains(it, ignoreCase = true) == false) {\n result.append(\".\" + it.toLowerCase())\n }\n \n }\n \n println(result.toString())\n \n}"}, {"source_code": "import java.lang.StringBuilder\n\nfun main(args: Array) {\n\n val vowels: String = \"AOYEUI\"\n\n if (args.size < 1) {\n return\n }\n\n val input = args[0]\n\n val result: StringBuilder = StringBuilder()\n\n input.forEach {\n\n if (vowels.contains(it, ignoreCase = true) == false) {\n result.append(\".\" + it.toLowerCase())\n }\n\n }\n\n print(result.toString())\n\n}"}, {"source_code": "import java.util.*\n\nprivate val scan = Scanner(System.`in`)\n\nfun main(args: Array) {\n\n scan.next()\n .toLowerCase()\n .filter { it !in listOf('a', 'e', 'i', 'o', 'u') }\n .flatMap { listOf('.', it) }\n .joinToString(separator = \"\")\n .run { println(this) }\n}\n"}, {"source_code": "fun main() {\n val x = readLine()!!.toLowerCase()\n println(x.replace(\"[aoyeui]+\".toRegex(), \"\").replace(\".\".toRegex()) { \".\" + it })\n}"}, {"source_code": "fun main() {\n val x = readLine()!!.toLowerCase()\n println(x.replace(\"[aoyeui]+\".toRegex(), \".\"))\n}"}, {"source_code": "fun main(args: Array) {\n val word = readLine()!!.toUpperCase()\n\n word.apply {\n replace(\"A\", \"\")\n replace(\"O\", \"\")\n replace(\"Y\", \"\")\n replace(\"E\", \"\")\n replace(\"U\", \"\")\n replace(\"I\", \"\")\n }\n var array = word.toCharArray()\n var result = \"\"\n for (ch in array) {\n result += \".$ch\"\n }\n println(result)\n}"}, {"source_code": "/**\n * Created by rohit.jh on 21/01/18\n */\nfun applyOperations(a:Char):String{\n val x = a.toLowerCase()\n return if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') \"\"\n else \".$x\"\n}\nfun main(args:Array){\n val str:String = readLine()!!\n for ( i in 0 until str.length){\n print(applyOperations(str[i]))\n }\n}"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() = output {\n val string = read()\n val result = string\n .toLowerCase()\n .replace(Regex(\"[aeiou]\"), \"\")\n .replace(Regex(\".\")) {\n \".${it.value}\"\n }\n\n println(result)\n}\n\n@JvmField\nval INPUT = System.`in`\n\n@JvmField\nval OUTPUT = System.out\n\n@JvmField\nval _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n\n@JvmField\nvar _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\n\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField\nval _writer = PrintWriter(OUTPUT, false)\n\nfun output(block: PrintWriter.() -> Unit) {\n _writer.apply(block).flush()\n}\n\n\n"}, {"source_code": "fun main()\n{\n var s = readLine()!!.toString()\n for (c in s)\n {\n if(c!='a' && c!='A' && c!='e' && c!='E' && c!='i' && c!='I' && c!='o' && c!='u' && c!='U' && c!='y' && c!='Y')\n print(\".$c\")\n }\n}"}, {"source_code": "\n\nfun main()\n{\n var st = readLine()!!\n st = st.toLowerCase()\n println(st)\n var s : String = \"\"\n val arr = arrayOf('a','o','y','e','u','i')\n for(i in st)\n {\n if(i !in arr)\n {\n s = s.plus(\".\"+i)\n }\n }\n println(s)\n}"}, {"source_code": "fun main() {\n val input = readLine()!!\n val vowels = Regex(\"[aeiou]\")\n val intermed = vowels.replace(input.toLowerCase(), \"\")\n var answer = \"\"\n for(i in 0..intermed.length - 1){\n answer += \".\" + intermed[i]\n }\n print(answer)\n}"}, {"source_code": "/* template start */\n// input\nprivate fun readString() = readLine()!!\nprivate fun readStrings() = readString().split(\" \")\nprivate fun readInt() = readString().toInt()\nprivate fun readDigits() = readString().map { it - '0' }\nprivate fun readInts() = readStrings().map { it.toInt() }\nprivate fun readLongs() = readStrings().map { it.toLong() }\n\n// output\nprivate fun T.print(map: (T) -> String = { it.toString() }) = println(map(this))\nprivate fun Iterable.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)\nprivate fun Array.print(sep: String? = null, map: ((T) -> String)? = null) = asSequence().print(sep, map)\nprivate fun Sequence.print(sep: String? = null, map: ((T) -> String)? = null) =\n println(joinToString(sep ?: \"\", transform = map ?: { it.toString() }))\n\n// various\nprivate val Int.isEven: Boolean get() = this % 2 == 0\nprivate val Int.isOdd: Boolean get() = !this.isEven\nprivate fun queries(block: (Int) -> Unit) = repeat(readInt(), block)\n\n/* template end */\n\nfun main() {\n val input = readString()\n buildString {\n for (c in input) {\n val c = c.toLowerCase()\n if (c !in setOf('a', 'e', 'i', 'o', 'u')) {\n append('.')\n append(c)\n }\n }\n }.print()\n}"}], "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b"} {"nl": {"description": "It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.The bus stop queue has n groups of people. The i-th group from the beginning has ai people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most m people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue.Your task is to determine how many buses is needed to transport all n groups to the dacha countryside.", "input_spec": "The first line contains two integers n and m (1 ≤ n, m ≤ 100). The next line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ m).", "output_spec": "Print a single integer — the number of buses that is needed to transport all n groups to the dacha countryside.", "sample_inputs": ["4 3\n2 3 2 1", "3 4\n1 2 1"], "sample_outputs": ["3", "1"], "notes": null}, "positive_code": [{"source_code": "fun main(args: Array) {\n val nm = readLine()!!.trim().split(\" \").map {it.trim().toInt()}.toIntArray()\n val a = readLine()!!.trim().split(\" \").map {it.trim().toInt()}.toIntArray()\n var result = 1\n var people=0\n for (i in 0 until nm[0]){\n if (people + a[i] <= nm[1]){\n people+=a[i]\n }\n else{\n result++\n people=a[i]\n }\n }\n println(result)\n\n}"}, {"source_code": "fun main() {\n var (n, m) = readLine()!!.split(\" \").map { it.toInt() }\n var list = readLine()!!.split(\" \").map { it.toInt() }\n\n var busSize = m\n var count = 1\n for (i in list) {\n if (i <= busSize) {\n busSize = busSize - i\n } else {\n count++\n busSize = m - i\n }\n }\n println(count)\n\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (_, busSize) = readInts()\n val groupsSizes = readInts()\n var currentSize = busSize\n var sol = 1\n for (groupSize in groupsSizes)\n if (groupSize <= currentSize)\n currentSize -= groupSize\n else {\n sol++\n currentSize = busSize - groupSize\n }\n print(sol)\n}"}], "negative_code": [{"source_code": "fun main(args: Array) {\n val groupBus = readLine()!!.trim().split(\" \").map {it.trim().toInt()}.toIntArray()\n val groupnums = readLine()!!.trim().split(\" \").map {it.trim().toInt()}.toIntArray()\n var countbuses = 0\n var carry=0\n var count =1\n for (i in 0 until groupBus[0]-1){\n carry=groupnums[i]\n for (j in i+1 until groupBus[0]){\n carry+=groupnums[j]\n if (carry>groupBus[1])break\n count++\n }\n countbuses++\n if (count == groupBus[0])break\n }\n println(countbuses)\n}"}, {"source_code": "fun main(args: Array) {\n val groupBus = readLine()!!.trim().split(\" \").map {it.trim().toInt()}.toIntArray()\n val groupnums = readLine()!!.trim().split(\" \").map {it.trim().toInt()}.toIntArray()\n var countbuses = 0\n var carry=0\n if (groupnums.sum()==groupBus[1])countbuses=1\n else {\n for (i in 0 until groupBus[0] - 1) {\n carry = groupnums[i]\n for (j in i + 1 until groupBus[0]) {\n carry += groupnums[j]\n if (carry > groupBus[1]) break\n }\n countbuses++\n }\n }\n println(countbuses)\n}"}, {"source_code": "fun main(args: Array) {\n val groupBus = readLine()!!.trim().split(\" \").map {it.trim().toInt()}.toIntArray()\n val groupnums = readLine()!!.trim().split(\" \").map {it.trim().toInt()}.toIntArray()\n var countbuses = 0\n var carry=0\n var count =0\n for (i in 0 until groupBus[0]-1){\n carry=groupnums[i]\n for (j in i+1 until groupBus[0]){\n carry+=groupnums[j]\n if (carry>groupBus[1])break\n count++\n }\n if (count == groupBus[0])break\n countbuses++\n }\n println(countbuses) \n}"}, {"source_code": "\nfun main(){\n var (n,m) = readLine()!!.split(\" \").map { it.toInt() }\n var list = readLine()!!.split(\" \").map { it.toInt() }.sum()\n\n if (list%m==0){\n println(list/m)\n }else{\n println(list/m+1)\n }\n\n}"}], "src_uid": "5c73d6e3770dff034d210cdd572ccf0f"} {"nl": {"description": "Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.There are $$$n$$$ kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.Also, there are $$$m$$$ boxes. All of them are for different people, so they are pairwise distinct (consider that the names of $$$m$$$ friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.Alice wants to pack presents with the following rules: She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of $$$n$$$ kinds, empty boxes are allowed); For each kind at least one present should be packed into some box. Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo $$$10^9+7$$$.See examples and their notes for clarification.", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$, separated by spaces ($$$1 \\leq n,m \\leq 10^9$$$) — the number of kinds of presents and the number of boxes that Alice has.", "output_spec": "Print one integer  — the number of ways to pack the presents with Alice's rules, calculated by modulo $$$10^9+7$$$", "sample_inputs": ["1 3", "2 2"], "sample_outputs": ["7", "9"], "notes": "NoteIn the first example, there are seven ways to pack presents:$$$\\{1\\}\\{\\}\\{\\}$$$$$$\\{\\}\\{1\\}\\{\\}$$$$$$\\{\\}\\{\\}\\{1\\}$$$$$$\\{1\\}\\{1\\}\\{\\}$$$$$$\\{\\}\\{1\\}\\{1\\}$$$$$$\\{1\\}\\{\\}\\{1\\}$$$$$$\\{1\\}\\{1\\}\\{1\\}$$$In the second example there are nine ways to pack presents:$$$\\{\\}\\{1,2\\}$$$$$$\\{1\\}\\{2\\}$$$$$$\\{1\\}\\{1,2\\}$$$$$$\\{2\\}\\{1\\}$$$$$$\\{2\\}\\{1,2\\}$$$$$$\\{1,2\\}\\{\\}$$$$$$\\{1,2\\}\\{1\\}$$$$$$\\{1,2\\}\\{2\\}$$$$$$\\{1,2\\}\\{1,2\\}$$$For example, the way $$$\\{2\\}\\{2\\}$$$ is wrong, because presents of the first kind should be used in the least one box."}, "positive_code": [{"source_code": "fun fastPow(a: Long, b: Long): Long {\n if (b==0L)\n return 1\n\n if (b==1L)\n return a\n\n if (b%2==0L)\n return fastPow((a*a)%1000000007, b/2)\n\n return a*fastPow(a, b-1)%1000000007\n}\n\nfun main() {\n val (n, m) = readLine()!!.split(\" \").map { it.toLong() }\n\n var numCombinationsOfEachKind = fastPow(2, m)-1\n var res = fastPow(numCombinationsOfEachKind, n)\n\n println(res)\n}"}, {"source_code": "fun main(args: Array) {\n val MOD = 1000000007L\n\n fun mod(x: Long) = (x % MOD + MOD) % MOD\n\n fun pow(x: Long, p: Long): Long {\n if (p == 0L) {\n return 1L\n }\n\n val halfPow = pow(x, p / 2)\n\n return if (p % 2L == 0L) mod(halfPow * halfPow) else mod(x * mod(halfPow * halfPow))\n }\n\n val (n, m) = readLine()!!.split(' ').map { it.toLong() }\n\n println(pow(mod(pow(2L, m) - 1L), n))\n}"}, {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\nimport java.util.TreeMap\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln // immediate println for interactive\n\nfun main() {\n output {\n val n = readInt()\n val m = readInt()\n\n val ans = (ModInt(2).pow(m) - 1).pow(n)\n\n println(ans.int)\n }\n}\n\nconst val BILLION7 = 1e9.toInt() + 7\nconst val MODINT_BASE = BILLION7\nconst val MODINT_TOTIENT = MODINT_BASE - 1 // assumes MODINT_BASE is prime\n\ninline infix fun Int.umod(base: Int) = Math.floorMod(this, base)\ninline infix fun Long.umod(base: Long) = Math.floorMod(this, base)\ninline infix fun Long.umod(base: Int) = Math.floorMod(this, base.toLong()).toInt()\n\nfun Int.mulMod(other: Int, mod: Int) = (toLong() * other).umod(mod)\n\nfun Int.powMod(exponent: Int, mod: Int): Int {\n var res = 1L\n var e = exponent\n var b = umod(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\n\ninline fun Int.toModInt() = ModInt(this umod MODINT_BASE)\ninline fun Long.toModInt() = ModInt(this umod MODINT_BASE)\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n companion object {\n /** can't seem to make these private or inlined without causing compiler issues */\n @JvmField val _invMemo = HashMap()\n fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }\n }\n\n inline operator fun plus(other: ModInt) = plus(other.int) // MODINT_BASE < 2^30\n inline operator fun plus(other: Int) = (int + other).toModInt() // careful of possible overflow\n inline operator fun inc() = plus(1)\n\n inline operator fun minus(other: ModInt) = minus(other.int)\n inline operator fun minus(other: Int) = (int - other).toModInt()\n inline operator fun dec() = minus(1)\n operator fun unaryMinus() = if(int == 0) this else ModInt(MODINT_BASE - int)\n\n inline operator fun times(other: ModInt) = times(other.int)\n inline operator fun times(other: Int) = ModInt(int.mulMod(other, MODINT_BASE))\n\n fun pow(exponent: Int): ModInt {\n val e = if(exponent < 0) exponent umod MODINT_TOTIENT else exponent\n return ModInt(int.powMod(e, MODINT_BASE))\n }\n\n fun pow(exponent: Long) = pow(exponent umod MODINT_TOTIENT)\n\n inline fun inverse() = inv_memoized() /** NOTE: Change if necessary */\n\n fun inv_unmemoized(): ModInt {\n require(int != 0) { \"Can't invert/divide by 0\" }\n return pow(MODINT_TOTIENT - 1)\n }\n inline fun inv_memoized() = _invMemoized(this)\n\n operator fun div(other: ModInt) = times(other.inverse())\n inline operator fun div(other: Int) = div(other.toModInt())\n\n override fun toString() = int.toString()\n}\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n inline operator fun get(i: Int) = ModInt(intArray[i])\n inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override val size: Int get() = intArray.size\n inline val lastIndex get() = intArray.lastIndex\n\n override fun contains(element: ModInt): Boolean = any { it == element }\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override fun isEmpty(): Boolean = intArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): ModInt = get(index++)\n }\n}\nfun ModIntArray(capacity: Int) = ModIntArray(IntArray(capacity))\ninline fun ModIntArray(capacity: Int, init: (Int) -> ModInt) =\n ModIntArray(IntArray(capacity) { init(it).int })\n\nfun Iterable.sum() = fold(ModInt(0), ModInt::plus)\nfun Sequence.sum() = fold(ModInt(0), ModInt::plus)\nfun Iterable.product() = fold(ModInt(1), ModInt::times)\nfun Sequence.product() = fold(ModInt(1), ModInt::times)\n\n/** IO code start */\n@JvmField val _reader = System.`in`.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(System.out, false)\ninline fun output(block: PrintWriter.()->Unit) { _writer.apply(block).flush() }\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun R._shuffle(rnd: Random, get: R.(Int) -> V, set: R.(Int, V) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, IntArray::get, IntArray::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, LongArray::get, LongArray::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, DoubleArray::get, DoubleArray::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, CharArray::get, CharArray::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.lang.StringBuilder\nimport java.util.*\n\nfun PrintWriter.solve(sc: FastScanner) {\n val n = sc.nextLong()\n val m = sc.nextLong()\n println((ModInt(2).pow(m)-ModInt(1)).pow(n))\n}\n\nfun main(args: Array) {\n val writer = PrintWriter(System.out, false)\n writer.solve(FastScanner(System.`in`))\n writer.flush()\n}\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}\n\nprivate class ModInt(x: Long) {\n\n companion object {\n const val MOD = 1e9.toLong() + 7\n }\n\n val x = (x % MOD + MOD) % MOD\n\n operator fun plus(other: ModInt): ModInt {\n return ModInt(x + other.x)\n }\n\n operator fun minus(other: ModInt): ModInt {\n return ModInt(x - other.x)\n }\n\n operator fun times(other: ModInt): ModInt {\n return ModInt(x * other.x)\n }\n\n operator fun div(other: ModInt): ModInt {\n return this * other.inv()\n }\n\n fun pow(exp: Long): ModInt {\n if (exp == 0L) return ModInt(1L)\n var a = pow(exp shr 1)\n a *= a\n if (exp and 1L == 0L) return a\n return this * a\n }\n\n fun inv(): ModInt {\n return this.pow(MOD - 2)\n }\n\n override fun equals(other: Any?): Boolean {\n if (this === other) return true\n if (javaClass != other?.javaClass) return false\n\n other as ModInt\n\n if (x != other.x) return false\n\n return true\n }\n\n override fun hashCode(): Int {\n return x.hashCode()\n }\n\n override fun toString(): String {\n return \"$x\"\n }\n}"}, {"source_code": "import java.math.BigInteger\n\nfun main() {\n val (numKinds, numFriends) = readLine()!!.split(\" \").map(String::toLong)\n print(\n BigInteger.valueOf(2L)\n .modPow(BigInteger.valueOf(numFriends), BigInteger.valueOf(1000000007L))\n .minus(BigInteger.ONE)\n .modPow(BigInteger.valueOf(numKinds), BigInteger.valueOf(1000000007L))\n )\n}"}, {"source_code": "fun main( args: Array ) {\n val modulo = 1000000007L\n fun modexp( aa: Long, nn: Long ): Long {\n var a = aa\n var n = nn\n var r = 1L\n while ( n > 0 ) {\n if ( n and 1L > 0L ) r = ( r * a ) % modulo\n a = ( a * a ) % modulo\n n /= 2\n }\n return r\n }\n val ( a, b ) = readLine()!!.split( \" \" ).map { it.toLong() }\n println( modexp( ( modexp( 2L, b ) - 1L ), a ) )\n}"}, {"source_code": "import java.util.ArrayList\nimport java.util.Arrays\nimport java.util.Scanner\n\n\n internal var mod = (1e9 + 7).toLong()\n\n\n \n fun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n val m = sc.nextInt()\n val sh = pow(2, m.toLong()) - 1\n print(pow(sh, n.toLong()))\n }\n\n private fun pow(a: Long, b: Long): Long {\n if (b == 0L) return 1L\n var p = pow(a, b / 2) % mod\n p = p * p % mod\n if (b and 1 != 0L) p = a * p % mod\n return p\n }\n\n\n\n"}, {"source_code": "val MOD = 1000000007\n\nfun pow(a: Long, n: Long): Long {\n if (n == 0L) return 1\n if (n % 2 == 1L) {\n val tmp = pow(a, n-1)\n return (tmp * a) % MOD\n } else {\n val c = pow(a, n / 2)\n return (c * c) % MOD\n }\n}\n\nfun main(args: Array) {\n var (n, m) = readLine()!!.split(' ').map { it.toLong() }\n print(pow((pow(2, m) - 1), n))\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007\n\nfun powMod(a: Int, n: Long, mod: Int): Long {\n if (n == 0L) return 1\n val res = powMod((a.toLong() * a % mod).toInt(), n / 2, mod)\n return if (n % 2 == 1L) res * a % mod else res\n}\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val n = nl()\n val m = nl()\n val p = (MOD + powMod(2, m, MOD) - 1) % MOD\n out.println(powMod(p.toInt(), n, MOD))\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl() + offset\n }\n return res\n }\n\n private fun na2(n: Int, offset: Int = 0): Array {\n val a = Array(2){IntArray(n)}\n for (i in 0 until n) {\n for (e in a) {\n e[i] = ni() + offset\n }\n }\n return a\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}"}], "negative_code": [], "src_uid": "71029e5bf085b0f5f39d1835eb801891"} {"nl": {"description": "Given an integer $$$x$$$, find 2 integers $$$a$$$ and $$$b$$$ such that: $$$1 \\le a,b \\le x$$$ $$$b$$$ divides $$$a$$$ ($$$a$$$ is divisible by $$$b$$$). $$$a \\cdot b>x$$$. $$$\\frac{a}{b}<x$$$. ", "input_spec": "The only line contains the integer $$$x$$$ $$$(1 \\le x \\le 100)$$$.", "output_spec": "You should output two integers $$$a$$$ and $$$b$$$, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print \"-1\" (without quotes).", "sample_inputs": ["10", "1"], "sample_outputs": ["6 3", "-1"], "notes": null}, "positive_code": [{"source_code": "\nfun main(args : Array) {\n\n val n1 = readLine()!!\n var n = n1.toInt()\n var a = 0\n var b = 0\n var c = 0\n\n if(n==1){\n c = 0\n }\n else{\n for(i in 1..n){\n for(j in 1..n){\n if(i%j==0 && i/jn){\n a = i\n b = j\n c++\n break\n }\n }\n }\n\n\n }\n\n if(c==0){\n println(-1)\n }\n else{\n print(a)\n print(\" \")\n print(b)\n }\n}"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!.toInt()\n println(if (n==1) -1 else \"$n $n\")\n}"}, {"source_code": "import java.io.*\nval br = BufferedReader(InputStreamReader(System.`in`))\nval bw = BufferedWriter(OutputStreamWriter(System.out))\nfun println(s: String) { bw.write(s + \"\\n\") }\nfun readLine() = br.readLine()!!\n\nfun main(args: Array) {\n solve()\n bw.close()\n}\n\nfun solve() {\n val r = readLine().toInt()\n for (a in 1..r) {\n for (b in 1..r) {\n if (a % b == 0 && a * b > r && a.toDouble() / b.toDouble() < r ) {\n println(\"$a $b\")\n return\n }\n }\n }\n println(\"-1\")\n\n}"}, {"source_code": "fun constructIntegers(n:Int):String{\n val a=n\n val b=n\n if(n > 1) {\n return a.toString()+\" \"+b.toString()\n }\n return \"-1\"\n }\n fun main(args : Array){\n println(constructIntegers(readLine()!!.toInt()))\n}"}, {"source_code": "fun main() {\n val x = readLine()!!.toInt()\n if (x == 1) {\n println(-1)\n } else {\n println(\"${x - (x and 1)} 2\")\n }\n}"}, {"source_code": "private fun read(delimit: Char = ' ') = readLine()!!.split(delimit)\n\nfun main(args: Array) {\n val (num) = read().map(String::toInt)\n\n var found = false\n\n for (x in 2..num) {\n val a = x\n val b = x/2\n\n if ((a%b == 0) && ((a/b) < num) && ((a*b) > num)) {\n print(\"$a $b\")\n found = true\n break\n }\n }\n\n if (!found) {\n for (x in 2..num) {\n val a = x\n val b = x\n\n if ((a%b == 0) && ((a/b) < num) && ((a*b) > num)) {\n print(\"$a $b\")\n found = true\n break\n }\n }\n }\n\n if (!found) {\n println(-1)\n }\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n var a = n\n var b = n\n if (n == 1) {\n println(-1)\n } else {\n println(\"$a $b\")\n }\n}\n\n"}, {"source_code": "import java.io.*\nimport kotlin.system.measureTimeMillis\n\nfun solve(input: BufferedReader) {\n val x = input.readLine().toInt()\n for (a in 1..x)\n for (b in 1..x)\n if (a % b == 0 && a / b < x && a * b > x) {\n print(\"%d %d\\n\".format(a, b))\n return\n }\n println(-1)\n}\n\n\nfun main(args: Array) {\n System.err.println(\"time = %dms\".format(measureTimeMillis {\n solve(System.`in`.bufferedReader())\n// solve(File(\"a.out\").bufferedReader())\n }))\n}\n"}, {"source_code": "import java.util.*\n \nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n var x = sc.nextInt()\n if(x == 1) println(-1)\n else print(\"${x} ${x}\")\n}\n"}, {"source_code": "fun main() {\n val x = readLine()!!.toInt()\n for (b in 1..x)\n for (a in b..x step b)\n if (a * b > x && a / b < x) return print(\"$a $b\")\n print(-1)\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val result = solve(n)\n if (result == null) {\n println(-1)\n } else {\n println(\"${result.first} ${result.second}\")\n }\n}\n\nfun solve(x: Int): Pair? {\n for (b in 1..x) {\n for (a in x downTo 1) {\n if (a % b == 0) {\n if (a * b > x) {\n if (a.toFloat()/b.toFloat() < x) {\n return a to b\n }\n }\n }\n }\n }\n\n return null\n}\n\n"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n Scanner(System.`in`).forEach {\n val x = it.toInt()\n for (a in 1..100) {\n for (b in 1..100) {\n if (a % b == 0 && b <= x && a * b > x && a / b < x) {\n println(\"$a $b\")\n return\n }\n }\n }\n println(\"-1\")\n return\n }\n\n}"}, {"source_code": "fun main(args: Array)\n{ var c: Int=0\n\tvar x= readLine()!!.toInt()\n\tfor(i in 1..x)\n\t\t{\n\t\t\tfor(j in 1..(i*x))\n\t\t\t\t{\n\t\t\t\t\tif((j*i)>x && (j%i)==0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tprintln(\"$j $i\")\n\t\t\t\t\t\t\tc++\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tif(c==1)break\n\t\t\t\t\n\t\t}\n\tif(c==0)println(\"-1\")\n\t\n}"}, {"source_code": "fun main()\n{ var c: Int=0\n\tvar x= readLine()!!.toInt()\n\tfor(i in 1..x)\n\t\t{\n\t\t\tfor(j in 1..(i*x))\n\t\t\t\t{\n\t\t\t\t\tif((j*i)>x && (j%i)==0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tprintln(\"$j $i\")\n\t\t\t\t\t\t\tc++\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tif(c==1)break\n\t\t\t\t\n\t\t}\n\tif(c==0)println(\"-1\")\n\t\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\nclass A {\n fun solve(x : Int) : Pair {\n if (x == 1) {\n return Pair(-1, -1)\n }\n if (x % 2 == 0) {\n return Pair(x, 2)\n } else {\n return Pair(x - 1, 2)\n }\n }\n\n fun solve(input : InputStream, output : OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n val x = reader.nextInt()\n val (a, b) = solve(x)\n if (a == -1) {\n writer.println(\"-1\")\n } else {\n writer.println(\"$a $b\")\n }\n\n writer.close()\n }\n\n private class InputReader(stream: InputStream) {\n var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n var tokenizer: StringTokenizer? = null\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n }\n}\n\nfun main(args : Array) {\n A().solve(System.`in`, System.out)\n}"}], "negative_code": [{"source_code": "fun constructIntegers(n:Int):String{\n var a = 0\n var b = 0\n if(n > 3) {\n for(i in n downTo 2){\n a = i\n for(j in a-1 downTo 2) {\n b = j\n if (a%b == 0 && a*b > n && a/b < n){\n return a.toString()+\" \"+b.toString()\n }\n }\n }\n }\n return \"-1\"\n }\n\n fun main(args: Array){\n println(constructIntegers(readLine()!!.toInt()))\n}"}, {"source_code": "fun main() {\n val x = readLine()!!.toInt()\n if (x == 1) {\n println(-1)\n } else {\n println(\"${x + (x and 1)} 2\")\n }\n}"}, {"source_code": "private fun read(delimit: Char = ' ') = readLine()!!.split(delimit)\n\nfun main(args: Array) {\n val (num) = read().map(String::toInt)\n\n var found = false\n\n for (x in 1..num) {\n if (x * 2 <= num) {\n print(\"$x ${x * 2}\")\n found = true\n break\n }\n }\n\n if (!found) {\n println(-1)\n }\n}"}, {"source_code": "private fun read(delimit: Char = ' ') = readLine()!!.split(delimit)\n\nfun main(args: Array) {\n val (num) = read().map(String::toInt)\n\n var found = false\n\n for (x in 2..num) {\n\n if ((x%2 == 0) && (x/2 < num) && (x*2 > num)) {\n print(\"$x ${x / 2}\")\n found = true\n break\n }\n }\n\n if (!found) {\n println(-1)\n }\n}"}, {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n var a = n/2\n var b = n/2\n while (!c(a,b,n)) {\n if (a <1 || a > n || b < 1 || b > n) {\n println(-1)\n return\n }\n a++\n b--\n }\n print(\"$a $b\")\n}\n\nfun c(a: Int, b: Int, n: Int) = a*b > n && a/b < n && a%b == 0\n\n"}, {"source_code": "fun main()\n{ var c: Int=0\n\tvar x= readLine()!!.toInt()\n\tfor(i in 1..x-1)\n\t\t{\n\t\t\tfor(j in 1..(i*x)-1)\n\t\t\t\t{\n\t\t\t\t\tif((j*i)>x && (j%i)==0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tprintln(\"$j $i\")\n\t\t\t\t\t\t\tc++\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tif(c==1)break\n\t\t\t\t\n\t\t}\n\tif(c==0)println(\"-1\")\n\t\n}"}], "src_uid": "883f67177474d23d7a320d9dbfa70dd3"} {"nl": {"description": "Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are n lanes of m desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to n from the left to the right, the desks in a lane are numbered from 1 to m starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture).The organizers numbered all the working places from 1 to 2nm. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. The picture illustrates the first and the second samples. Santa Clause knows that his place has number k. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!", "input_spec": "The only line contains three integers n, m and k (1 ≤ n, m ≤ 10 000, 1 ≤ k ≤ 2nm) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.", "output_spec": "Print two integers: the number of lane r, the number of desk d, and a character s, which stands for the side of the desk Santa Claus. The character s should be \"L\", if Santa Clause should sit on the left, and \"R\" if his place is on the right.", "sample_inputs": ["4 3 9", "4 3 24", "2 4 4"], "sample_outputs": ["2 2 L", "4 3 R", "1 2 R"], "notes": "NoteThe first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right."}, "positive_code": [{"source_code": "fun main(args: Array) {\n val (n, m, k) = readLine()!!.split(\" \").map(String::toInt)\n val lane = ((k-1) / (2 * m)) + 1\n val desk = (((k-1)/2) % m) + 1\n val side = if(k%2 == 1) \"L\" else \"R\"\n println(\"$lane $desk $side\")\n}"}, {"source_code": "fun findRow(k: Int, m: Int) = if ((k / 2) % m == 0) (k / 2) / m else (k / 2) / m + 1\n\nfun findDesk(k: Int, m: Int) = if ((k / 2) % m == 0) m else (k / 2) % m\n\nfun main(args: Array) {\n val (n, m, k) = readLine()!!.split(\" \").map(String::toInt)\n var side = 'R'\n var row: Int\n var desk: Int\n if (k % 2 == 0) {\n row = findRow(k, m)\n desk = findDesk(k, m)\n } else {\n row = findRow(k+1, m)\n desk = findDesk(k+1, m)\n side = 'L'\n }\n println(\"$row $desk $side\")\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (_, desksPerLane, santaPlace) = readInts()\n val lane = santaPlace / (2 * desksPerLane) + if (santaPlace % (2 * desksPerLane) == 0) 0 else 1\n val deskInLane = santaPlace - (lane - 1) * 2 * desksPerLane\n val numRow = (deskInLane + 1) / 2\n print(\"$lane $numRow ${if (santaPlace % 2 == 0) 'R' else 'L'}\")\n}"}], "negative_code": [], "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb"} {"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": "import kotlin.math.*\n\nprivate const val MOD = 998244353\n\nfun main(args: Array) {\n val (n, k) = readLine()!!.split(\" \").map { it.toInt() }\n val c = Array(n + 1) { IntArray(n + 1) }\n val d = Array(n + 1) { IntArray(n + 1) }\n c[0][0] = 1\n d[0][0] = 1\n for (x in 1..n) {\n for (m in 1..x) {\n c[x][m] = d[x - m][min(m, x - m)]\n for (l in 1 until m) {\n c[x][m] = add(c[x][m], c[x - l][m])\n }\n d[x][m] = add(c[x][m], d[x][m - 1])\n }\n }\n var sum = 0\n wl@ for (w in 1..n) {\n for (h in 1..n) {\n if (w * h >= k) continue@wl\n sum = add(sum, mul(c[n][w], c[n][h]))\n }\n }\n sum = mul(sum, 2)\n println(sum)\n}\n\nprivate fun add(a: Int, b: Int): Int = ((a.toLong() + b) % MOD).toInt()\nprivate fun mul(a: Int, b: Int): Int = ((a.toLong() * b) % MOD).toInt()\n"}, {"source_code": "import java.util.*\n\nval MOD = 998244353L\n\nfun main() {\n val jin = Scanner(System.`in`)\n val n = jin.nextInt()\n val k = jin.nextInt()\n val amts = LongArray(n + 1) {\n if (it == 0) {\n 0L\n } else {\n val dp = LongArray(n + 1)\n dp[0] = 1L\n var sum = 1L\n for (j in 1..n) {\n dp[j] = sum\n sum += dp[j]\n if (j >= it) {\n sum -= dp[j - it]\n }\n sum %= MOD\n }\n dp[n]\n }\n }\n for (j in n downTo 1) {\n amts[j] -= amts[j - 1]\n }\n var answer = 0L\n for (a in 1..n) {\n for (b in 1..n) {\n if (a * b < k) {\n answer += amts[a] * amts[b]\n answer %= MOD\n }\n }\n }\n answer *= 2\n println(((answer % MOD) + MOD) % MOD)\n}"}], "negative_code": [], "src_uid": "77177b1a2faf0ba4ca1f4d77632b635b"} {"nl": {"description": "Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: 1+2*3=7 1*(2+3)=5 1*2*3=6 (1+2)*3=9 Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.It's easy to see that the maximum value that you can obtain is 9.Your task is: given a, b and c print the maximum value that you can get.", "input_spec": "The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).", "output_spec": "Print the maximum value of the expression that you can obtain.", "sample_inputs": ["1\n2\n3", "2\n10\n3"], "sample_outputs": ["9", "60"], "notes": null}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n var tok = StringTokenizer(\"\")\n\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n fun files(inputFilename: String, outputFilename: String) = ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))\n }\n\n fun readToken(): String {\n while (!tok.hasMoreTokens()) {\n tok = StringTokenizer(rd.readLine())\n }\n return tok.nextToken()\n }\n\n fun readInt(): Int = readToken().toInt()\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun close() {\n rd.close()\n wr.close()\n }\n}\n\nfun solve() {\n val io = ProblemIO.console()\n val a = io.readInt()\n val b = io.readInt()\n val c = io.readInt()\n val v = intArrayOf(a * b * c, (a + b) * c, a * (b + c), a + b * c, a * b + c, a + b + c)\n io.println(v.max())\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val a = r.readLine()!!.toInt()\n val b = r.readLine()!!.toInt()\n val c = r.readLine()!!.toInt()\n val max1 = maxOf(a+b*c, (a+b)*c, a*b+c)\n val max2 = maxOf(a*(b+c), a*b*c, a+b+c)\n println(maxOf(max1, max2))\n}"}, {"source_code": "import java.util.*\nimport java.math.*\nimport kotlin.math.*\n\nfun readLn()=readLine()!!\nfun readInt()=readLn().toInt()\nfun readInts()=readLn().split(\" \").map{it.toInt()}\nfun readLong()=readLn().toLong()\nfun readLongs()=readLn().split(\" \").map{it.toLong()}\n\nval out=mutableListOf()\nfun printLine(s:String){out.add(s)}\nfun output(){println(out.joinToString(\"\\n\"))}\n\nfun main(){\n var a=readInt()\n var b=readInt()\n var c=readInt()\n var ans=a+b+c\n ans=max(ans,a+b*c)\n ans=max(ans,a*b+c)\n ans=max(ans,a*b*c)\n ans=max(ans,(a+b)*c)\n ans=max(ans,a*(b+c))\n printLine(\"$ans\")\n output()\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val a = sc.nextInt()\n val b = sc.nextInt()\n val c = sc.nextInt()\n val list = arrayListOf()\n // Manually declare all possible expression results\n list.add(a+b+c)\n list.add(a*b*c)\n list.add(a+b*c)\n list.add(a*b+c)\n list.add((a+b)*c)\n list.add(a*(b+c))\n // Print maximum\n println(list.max())\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n\n val a = scanner.nextLong()\n val b = scanner.nextLong()\n val c = scanner.nextLong()\n\n var res : Long = a + b + c\n\n res = Math.max(res, (a+b)*c)\n res = Math.max(res, a*(b+c))\n res = Math.max(res, a*b*c)\n res = Math.max(res, a+b*c)\n res = Math.max(res, a*b+c)\n\n System.out.print(res)\n\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val input = InputReader(inputStream)\n val output = PrintWriter(outputStream)\n val solver = Task()\n solver.solve(input, output)\n output.close()\n}\n\nprivate class Task {\n fun solve(input: InputReader, output: PrintWriter) {\n val a = input.nextInt()\n val b = input.nextInt()\n val c = input.nextInt()\n\n output.print(listOf(\n a * b * c,\n a + b * c,\n a * b + c,\n a + b + c,\n (a + b) * c,\n a * (b + c)).max()\n )\n\n }\n}\n\n\nprivate class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n\n operator fun next(): String {\n while (tokenizer == null || tokenizer?.hasMoreTokens()?.not() == true) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return next().toInt()\n }\n\n}"}, {"source_code": "import java.io.*\nimport java.util.*\n\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val input = InputReader(inputStream)\n val output = PrintWriter(outputStream)\n val solver = Task()\n solver.solve(input, output)\n output.close()\n}\n\nprivate class Task {\n fun solve(input: InputReader, output: PrintWriter) {\n val a = input.nextInt()\n val b = input.nextInt()\n val c = input.nextInt()\n\n output.print(listOf(a * b * c, a + b + c, a + b * c, a * b + c, (a + b) * c, a * (b + c)).max())\n }\n}\n\n\nprivate class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n\n operator fun next(): String {\n while (tokenizer == null || tokenizer?.hasMoreTokens()?.not() == true) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return next().toInt()\n }\n\n}\n"}, {"source_code": "import java.io.PrintWriter\nimport kotlin.math.*\n\nfun main() {\n io.apply {\n\n val a = int\n val b = int\n val c = int\n cout .. arrayOf(a + b + c, a * b + c, a * (b + c), (a + b) * c, a + b * c, a * b * c).max()!! .. nl\n\n }.cout.flush()\n}\n\n// @formatter:off\nprivate val io = object {\n private val `in` = System.`in`\n private fun ll(): Long {\n var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }\n do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n\n }\n val int get() = ll().toInt(); val long get() = ll()\n fun ints(n: Int = int): IntArray { return IntArray(n) { int } }\n fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }\n val cout = PrintWriter(System.out); val nl = \"\\n\"\n operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(\" \") }; return this }\n operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }\n} // @formatter:on\n\n/* ----------- */\n\n"}, {"source_code": "fun main() {\n var func :(Int , Int , Int) -> Unit = {n1,n2,n3 ->\n var arr = arrayOf(0,0,0,0)\n arr[0] = n1 + n2 + n3\n arr[1] = (n1 + n2) * n3\n arr[2] = n1 * (n2 + n3)\n arr[3] = n1 * n2 * n3\n println(arr.max())\n }\n func(readLine()!!.toInt() , readLine()!!.toInt() , readLine()!!.toInt())\n\n\n}"}, {"source_code": "import java.lang.Integer.max\n\nfun main(args: Array) {\n var first = readLine()!!.toInt()\n var second = readLine()!!.toInt()\n var third = readLine()!!.toInt()\n\n println(\n arrayOf(\n first * second * third,\n (first + second) * third,\n first * (second + third),\n first + second + third,\n first + second * third,\n first * second + third\n ).max()\n )\n}\n\n"}, {"source_code": "fun main(args: Array) = println(arrayOf(readLine()!!, readLine()!!, readLine()!!).map(String::toInt).let { (a, b, c) -> arrayOf(a + b + c, a * b * c, a + b * c, a * b + c, (a + b) * c, a * (b + c)).max() })"}, {"source_code": "fun main() {\n val a = readLine()!!.toInt()\n val b = readLine()!!.toInt()\n val c = readLine()!!.toInt()\n\n println(listOf(a*b*c, a*b+c, a*(b+c), a+b*c, (a+b)*c, a+b+c).max())\n}\n"}, {"source_code": "import java.util.*\n\n/**\n * Created by v.shipugin on 30/08/2018\n */\n\nfun main(args: Array) {\n Cont274().first()\n}\n\nclass Cont274 {\n\n fun first() {\n val scanner = Scanner(System.`in`)\n\n val a = scanner.nextInt()\n val b = scanner.nextInt()\n val c = scanner.nextInt()\n\n val fist = a + b + c\n val second = (a + b) * c\n val third = a * (b + c)\n val foufh = a * b * c\n\n println(\n Math.max(\n Math.max(fist, second),\n Math.max(third, foufh)\n )\n )\n }\n}"}, {"source_code": "fun main(args : Array) {\n var arr = IntArray(3)\n for (i in 0..2)\n arr[i] = readLine()!!.toInt()\n var ans1 = 0\n var ans2 = 0\n var max = arr[0] * arr[1]\n\n if (arr[0] + arr[1] > max)\n max = arr[0] + arr[1]\n\n if (max * arr[2] > max + arr[2])\n ans1 = max * arr[2]\n else\n ans1 = max * arr[2]\n\n max = arr[1] * arr[2]\n if (arr[1] + arr[2] > max)\n max = arr[1] + arr[2]\n if (max * arr[0] > max + arr[0])\n ans2 = max * arr[0]\n else\n ans2 = max + arr[0]\n\n if (ans1 > ans2)\n println(ans1)\n else\n println(ans2)\n}"}, {"source_code": "\nimport java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val a = scanner.nextInt()\n val b = scanner.nextInt()\n val c = scanner.nextInt()\n\n val case1 = (a + b) * c\n val case6 = a * b + c\n\n val case2 = a + b + c\n val case3 = a * b * c\n\n val case4 = a * b + c\n val case5 = a * (b + c)\n\n val result = arrayOf(case1, case2, case3, case4, case5, case6)\n\n\n println(result.max())\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val nums = Array(3){0}\n for (i in 0 until 3){\n nums[i] = br.readLine().toInt()\n }\n val a = nums[0]\n val b = nums[1]\n val c = nums[2]\n val options = listOf(\n a + b + c,\n a * b * c,\n (a + b)*c,\n a*(b + c),\n a*b + c,\n a + b*c\n )\n println(options.max())\n}"}, {"source_code": "//package problem479A\n\nfun main() {\n val numbers = listOf(readLine()!!, readLine()!!, readLine()!!).map { it.toInt() }\n\n val possibilities = mutableListOf(numbers.reduce { acc, i -> acc * i }, numbers.sum())\n possibilities.add(numbers[0] + numbers[1] * numbers[2])\n possibilities.add((numbers[0] + numbers[1]) * numbers[2])\n possibilities.add(numbers[0] * numbers[1] + numbers[2])\n possibilities.add(numbers[0] * (numbers[1] + numbers[2]))\n\n println(possibilities.max())\n}\n"}, {"source_code": "fun main(){\n val list=ArrayList()\n for(i in 0..2){\n list.add(readLine()!!.toInt())\n }\n val list2=ArrayList()\n list2.add((list[0]+list[1])*list[2])\n list2.add(list[0]+(list[1]*list[2]))\n list2.add(list[0]*list[1]*list[2])\n list2.add((list[0]*list[1])+list[2])\n list2.add(list[0]*(list[1]+list[2]))\n list2.add(list[0]+list[1]+list[2])\n print(list2.max())\n}"}, {"source_code": "import com.sun.xml.internal.fastinfoset.util.StringArray\nimport java.awt.List\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.min\n\nfun main() {\n var sc = Scanner(System.`in`)\n var a = sc.nextInt()\n var b = sc.nextInt()\n var c = sc.nextInt()\n\n var max = 0\n if (a * b * c > max) max = a * b * c\n if ((a + b) * c > max) max = (a + b) * c\n if (a * (b + c) > max) max = a * (b + c)\n if (a * b + c > max) max = a * b + c\n if (a + b + c > max) max = a + b + c\n\n println(max)\n}\n\n"}, {"source_code": "fun main(args: Array) {\n val (a, b, c) = (1..3).map { readLine()!!.toInt() }\n\n val m = arrayOf(a * b + c, a * (b + c), a + b * c, (a + b) * c, a + b + c, a * b * c).max()!!\n\n println(m)\n}\n"}, {"source_code": "import java.lang.Math.*\n\nfun main(){\n \n val a = readLine()?.toInt() ?: 1\n val b = readLine()?.toInt() ?: 1\n val c = readLine()?.toInt() ?: 1\n\n var answer = a + b + c\n answer = max(answer, a.plus(b).times(c))\n answer = max(answer, a.times(b.plus(c)))\n answer = max(answer, a.times(b).times(c))\n\n println(answer)\n}"}, {"source_code": "fun main() {\n val a = readLine()!!.toInt()\n val b = readLine()!!.toInt()\n val c = readLine()!!.toInt()\n\n println(arrayOf(\n a + b + c,\n a + b * c,\n a * b * c,\n a * b + c,\n a * (b + c),\n (a + b) * c\n ).max())\n}"}, {"source_code": " fun main()\n {\n //\n var a:Int= readLine()!!.toInt()\n var b:Int= readLine()!!.toInt()\n var c:Int= readLine()!!.toInt()\n var s=0\n if((a==0|| a==1) && (c==0|| c==1))\n {\n s=a+b+c\n print(s)\n return\n }\n if((b==0|| b==1))\n {\n s= maxOf(((a+b)*c),((c+b)*a))\n print(s)\n return\n }\n if((a!=0&& a!=1) && (c!=0&& c!=1)&& (b!=0 && b!=1))\n {\n s=a*b*c\n print(s)\n return\n }\n\n if((a==0|| a==1)&&((b!=0)&&(b!=1))&&((c!=0)&&(c!=1)))\n {\n s=(a+b)*c\n print(s)\n return\n }\n if((c==0|| c==1)&&((b!=0)&&(b!=1))&&((a!=0)&&(a!=1)))\n {\n s=a*(b+c)\n print(s)\n }\n }"}, {"source_code": "import java.util.*\n\n\nfun main (args:Array)\n{\n var a:Int= readLine()!!.toInt()\n var b: Int= readLine()!!.toInt()\n var c:Int= readLine()!!.toInt()\n var Max:Int=0\n if(a+b*c>Max)\n Max=a+b*c\n if(a*(b+c)>Max)\n Max=a*(b+c)\n if((a*b*c)>Max)\n Max=(a*b*c)\n if((a+b)*c>Max)\n Max=(a+b)*c\n if(a+b+c>Max)\n Max=a+b+c\nSystem.out.println(Max)\n}\n\n\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nval alg1 = { i1: Int, i2: Int, i3: Int -> i1 + i2 * i3 }\nval alg2 = { i1: Int, i2: Int, i3: Int -> i1 * (i2 + i3) }\nval alg3 = { i1: Int, i2: Int, i3: Int -> i1 * i2 * i3 }\nval alg4 = { i1: Int, i2: Int, i3: Int -> (i1 + i2) * i3 }\nval alg5 = { i1: Int, i2: Int, i3: Int -> i1 + i2 + i3 }\nval alg6 = { i1: Int, i2: Int, i3: Int -> i1 * i2 + i3 }\n\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val arg1 = reader.readLine().toInt()\n val arg2 = reader.readLine().toInt()\n val arg3 = reader.readLine().toInt()\n val answers = listOf(alg1(arg1, arg2, arg3),\n alg2(arg1, arg2, arg3),\n alg3(arg1, arg2, arg3),\n alg4(arg1, arg2, arg3),\n alg5(arg1, arg2, arg3),\n alg6(arg1, arg2, arg3))\n println(answers.max())\n}"}, {"source_code": "fun main(args: Array) {\n val (a,b,c) = Array(3, { readLine()!!.toInt()})\n println(arrayOf(a*b*c,(a+b)*c,a*(b+c),a+b+c).max())\n}"}, {"source_code": "fun main(args: Array) {\n val a = readLine()!!.toInt()\n val b = readLine()!!.toInt()\n val c = readLine()!!.toInt()\n\n fun addOrMultiply(x: Int, y: Int): Int {\n if (x == 1 || y == 1) {\n return x + y\n }\n else {\n return x * y\n }\n }\n\n val larger = maxOf(a, c)\n val smaller = minOf(a, c)\n println(addOrMultiply(addOrMultiply(smaller, b), larger))\n}"}, {"source_code": "import kotlin.math.max\n\nfun main(args : Array){\n\n var X = readLine()!!.toInt()\n var Y = readLine()!!.toInt()\n var Z = readLine()!!.toInt()\n\n println(MAX(X+Y+Z,X*Y*Z,(X+Y)*Z,X*(Y+Z)))\n\n }\n\nfun MAX(V:Int,X:Int,Y:Int,Z:Int) : Int {\n if (V > X && V > Y && V > Z)\n return V\n\n else if (X > V && X > Y && X > Z)\n return X\n\n else if (Y > V && Y > X && Y > Z)\n return Y\n\n else\n return Z\n }"}, {"source_code": "fun main(args: Array) {\n\tval a = readLine()!!.toInt()\n\tval b = readLine()!!.toInt()\n\tval c = readLine()!!.toInt()\n\tfindMaxVal(a, b, c)\n}\n\nfun findMaxVal(a: Int, b: Int, c: Int){\n\tval maxOfSumAllAndProductAll = Integer.max(a*b*c, a + b + c)\n\tval maxOfPartialSumAll = Integer.max(partialSum(a, b, c), partialSum(c, b, a))\n\tval maxOfPartialSumBracesAll = Integer.max(partialSumBraces(a, b, c), partialSumBraces(c, b, a))\n\tprintln(Integer.max(Integer.max(maxOfSumAllAndProductAll, maxOfPartialSumAll),maxOfPartialSumBracesAll))\n} \nfun partialSum(a: Int, b: Int, c: Int): Int {\n\treturn a+b*c\n} \nfun partialSumBraces(a: Int, b: Int, c: Int) = (a+b)*c "}, {"source_code": "import kotlin.math.max\nimport kotlin.math.min\n\n/**\n * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last\n * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of\n * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is\n * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.\n * Here are some ways of placing signs and brackets:\n * 1+2*3=7\n * 1*(2+3)=5\n * 1*2*3=6\n * (1+2)*3=9\n * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.\n * For instance, in the given sample you cannot get expression (1+3)*2.\n * It's easy to see that the maximum value that you can obtain is 9.\n * Your task is: given a, b and c print the maximum value that you can get.\n *\n * Input\n * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).\n *\n * Output\n * Print the maximum value of the expression that you can obtain.\n */\nfun readInt(): Int = readLine()!!.toInt()\n\nfun readInputs():MutableList {\n val inputList:MutableList = mutableListOf()\n for (i in 0..2){\n inputList += listOf(readInt())\n }\n return inputList\n}\n\nfun maxExp(list: MutableList): Int {\n val expr1 = list[0] + list[1] + list[2]\n val expr2 = list[0] * list[1] * list[2]\n val expr3 = list[0] + list[1] * list[2]\n val expr4 = list[0] * list[1] + list[2]\n val expr5 = list[0] * (list[1] + list[2])\n val expr6 = (list[0] + list[1]) * list[2]\n return max(max(max(max(max(expr1, expr2), expr3), expr4), expr5), expr6)\n}\n/*\nfun sum0and1(list: MutableList):List{\n if (list.contains(0)) {\n list.remove(0)\n }\n var counter = 0\n for (i in 0..2){\n if (list[i] == 1) counter++\n }\n return if(counter != 3) {\n if (list.contains(1)) {\n val index = list.indexOf(1)\n list.remove(1)\n if(index!=0 && index!=2) {\n val minValue = min(list[index], list[index - 1])\n if (minValue == list[index]) list[index]++ else list[index - 1]++\n }\n else if(index == 0){\n list[index]++\n }\n else{\n list[index-1]++\n }\n }\n list.toList()\n }\n else {\n listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())\n }\n}\n\nfun maxResult(list: List): Int = list.reduce { acc, i -> acc * i }\n*/\n\nfun main(){\n val inputValues = readInputs().toMutableList()\n /*\n val filteredList = sum0and1(inputValues)\n val result = maxResult(filteredList)\n */\n println(maxExp(inputValues))\n}"}], "negative_code": [{"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val a = r.readLine()!!.toInt()\n val b = r.readLine()!!.toInt()\n val c = r.readLine()!!.toInt()\n val max1 = maxOf(a+b*c, (a+b)*c)\n val max2 = maxOf(a*(b+c), a*b*c)\n println(maxOf(max1, max2))\n}"}, {"source_code": "fun main(args : Array) {\n var arr = IntArray(3)\n for (i in 0..2)\n arr[i] = readLine()!!.toInt()\n arr.sort()\n var max = arr[0] * arr[1]\n if (arr[0] + arr[1] > max)\n max = arr[0] + arr[1]\n if (max * arr[2] > max + arr[2])\n println(max * arr[2])\n else\n println(max + arr[2] )\n}"}, {"source_code": "fun main(args : Array) {\n var arr = IntArray(3)\n for (i in 0..2)\n arr[i] = readLine()!!.toInt()\n var max = arr[0] * arr[1]\n if (arr[0] + arr[1] > max)\n max = arr[0] + arr[1]\n if (max * arr[2] > max + arr[2])\n println(max * arr[2])\n else\n println(max + arr[2] )\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val abc = Array(3){0}\n for (i in 0 until 3){\n abc[i] = br.readLine().toInt()\n }\n val nums = abc.sorted()\n println(\n if (nums[0] == 1){\n (nums[0] + nums[1]) * nums[2]\n } else if (nums.fold(true){acc, x -> x == 1 && acc}){\n nums[0] + nums[1] + nums[2]\n } else{\n nums[0] * nums[1] * nums[2]\n }\n )\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val abc = Array(3){0}\n for (i in 0 until 3){\n abc[i] = br.readLine().toInt()\n }\n val nums = abc.sorted()\n println(\n if (nums.fold(true){acc, x -> x == 1 && acc}){\n (nums[0] + nums[1]) * nums[2]\n } else if (nums[0] == 1){\n nums[0] + nums[1] + nums[2]\n } else{\n nums[0] * nums[1] * nums[2]\n }\n )\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val nums = Array(3){0}\n for (i in 0 until 3){\n nums[i] = br.readLine().toInt()\n }\n println(\n if (nums.fold(true){acc, x -> x == 1 && acc}){\n nums[0] + nums[1] + nums[2]\n } else if (nums[0] == 1){\n (nums[0] + nums[1]) * nums[2]\n } else{\n nums[0] * nums[1] * nums[2]\n }\n )\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val abc = Array(3){0}\n for (i in 0 until 3){\n abc[i] = br.readLine().toInt()\n }\n val nums = abc.sorted()\n println(\n if (nums.fold(true){acc, x -> x == 1 && acc}){\n nums[0] + nums[1] + nums[2]\n } else if (nums[0] == 1){\n (nums[0] + nums[1]) * nums[2]\n } else{\n nums[0] * nums[1] * nums[2]\n }\n )\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val abc = Array(3){0}\n for (i in 0 until 3){\n abc[i] = br.readLine().toInt()\n }\n val nums = abc.sorted()\n println(\n if (nums[0] == 1){\n (nums[0] + nums[1]) * nums[2]\n } else{\n nums[0] * nums[1] * nums[2]\n }\n )\n}"}, {"source_code": "import java.lang.Math.*\n\nfun main(){\n \n val a = readLine()?.toInt() ?: 1\n val b = readLine()?.toInt() ?: 1\n val c = readLine()?.toInt() ?: 1\n\n if (a != 1 && b != 1 && c != 1)\n println(a.times(b).times(c))\n else if(a == 1 && b == 1 && c == 1)\n println(a.plus(b).plus(c))\n else{\n val x = min(a, min(b,c))\n val y = if (a == x) min(b,c) else if (b == x) min(a,c) else min(a, b)\n println(x.plus(y).times(max(a, max(b,c))))\n\n }\n}"}, {"source_code": " fun main()\n {\n //\n var a:Int= readLine()!!.toInt()\n var b:Int= readLine()!!.toInt()\n var c:Int= readLine()!!.toInt()\n var s=0\n if((a==0|| a==1) && (c==0|| c==1))\n {\n s=a+b+c\n print(s)\n return\n }\n if((b==0|| b==1))\n {\n s=a+b+c\n print(s)\n return\n }\n if((a!=0&& a!=1) && (c!=0&& c!=1)&& (b!=0 && b!=1))\n {\n s=a*b*c\n print(s)\n return\n }\n\n if((a==0|| a==1)&&((b!=0)&&(b!=1))&&((c!=0)&&(c!=1)))\n {\n s=(a+b)*c\n print(s)\n return\n }\n if((c==0|| c==1)&&((b!=0)&&(b!=1))&&((a!=0)&&(a!=1)))\n {\n s=a*(b+c)\n print(s)\n }\n }"}, {"source_code": " fun main()\n {\n //\n var a:Int= readLine()!!.toInt()\n var b:Int= readLine()!!.toInt()\n var c:Int= readLine()!!.toInt()\n var s=0\n if((a==0|| a==1) && (c==0|| c==1))\n {\n s=a+b+c\n print(s)\n return\n }\n if((b==0|| b==1))\n {\n s=a+b+c\n print(s)\n return\n }\n if((a!=0&& a!=1) && (c!=0&& c!=1)&& (b!=0 && b!=1))\n {\n s=a*b*c\n print(s)\n return\n }\n\n if((a==0|| a==1)&&((b!=0)&&(b!=1))&&((c!=0)&&(c!=1)))\n {\n s=a+(b*c)\n print(s)\n return\n }\n if((c==0|| c==1)&&((b!=0)&&(b!=1))&&((a!=0)&&(a!=1)))\n {\n s=(a*b)+c\n print(s)\n }\n }"}, {"source_code": "import java.util.*\n\n\nfun main (args:Array)\n{\n var a:Int= readLine()!!.toInt()\n var b: Int= readLine()!!.toInt()\n var c:Int= readLine()!!.toInt()\n var Max:Int=0\n if(a+b*c>Max)\n Max=a+b*c\n if(a*(b+c)>Max)\n Max=a*(b+c)\n if((a*b*c)>Max)\n Max=(a*b*c)\n if((a+b)*c>Max)\n Max=(a+b)*c\nSystem.out.println(Max)\n}\n\n\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nval alg1 = { i1: Int, i2: Int, i3: Int -> i1 + i2 * i3 }\nval alg2 = { i1: Int, i2: Int, i3: Int -> i1 * (i2 + i3) }\nval alg3 = { i1: Int, i2: Int, i3: Int -> i1 * i2 * i3 }\nval alg4 = { i1: Int, i2: Int, i3: Int -> (i1 + i2) * i3 }\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val arg1 = reader.readLine().toInt()\n val arg2 = reader.readLine().toInt()\n val arg3 = reader.readLine().toInt()\n val answers = listOf(alg1(arg1, arg2, arg3),\n alg2(arg1, arg2, arg3),\n alg3(arg1, arg2, arg3),\n alg4(arg1, arg2, arg3))\n println(answers.max())\n}"}, {"source_code": "fun main(args: Array) {\n val (a,b,c) = Array(3, { readLine()!!.toInt()})\n println(arrayOf(a*b*c,(a+b)*c,a*(b+c)).max())\n}"}, {"source_code": "fun main(args: Array) {\n val a = readLine()!!.toInt()\n val b = readLine()!!.toInt()\n val c = readLine()!!.toInt()\n\n fun addOrMultiply(x: Int, y: Int): Int {\n if (x == 1 || y == 1) {\n return x + y\n }\n else {\n return x * y\n }\n }\n\n println(addOrMultiply(addOrMultiply(a, b), c))\n}"}, {"source_code": "/**\n * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last\n * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of\n * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is\n * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.\n * Here are some ways of placing signs and brackets:\n * 1+2*3=7\n * 1*(2+3)=5\n * 1*2*3=6\n * (1+2)*3=9\n * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.\n * For instance, in the given sample you cannot get expression (1+3)*2.\n * It's easy to see that the maximum value that you can obtain is 9.\n * Your task is: given a, b and c print the maximum value that you can get.\n *\n * Input\n * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).\n *\n * Output\n * Print the maximum value of the expression that you can obtain.\n */\n\nfun readInt(): Int = readLine()!!.toInt()\n\nfun readInputs():MutableList {\n val inputList:MutableList = mutableListOf()\n for (i in 0..2){\n inputList += listOf(readInt())\n }\n return inputList\n}\n\nfun sum0and1(list: MutableList):List{\n if (list.contains(0)) {\n list.remove(0)\n }\n val checkList = list intersect listOf(1, 1)\n return if(checkList != listOf(1, 1) && checkList != listOf(1, 1, 1)) {\n if (list.contains(1)) {\n val index = list.indexOf(1)\n list.remove(1)\n list[index]++\n }\n list.toList()\n }\n else {\n listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())\n }\n}\n\nfun maxResult(list: List): Int = list.reduce { acc, i -> acc * i }\n\nfun main(){\n val inputValues = readInputs().toMutableList()\n val filteredList = sum0and1(inputValues)\n val result = maxResult(filteredList)\n println(result)\n}"}, {"source_code": "/**\n * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last\n * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of\n * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is\n * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.\n * Here are some ways of placing signs and brackets:\n * 1+2*3=7\n * 1*(2+3)=5\n * 1*2*3=6\n * (1+2)*3=9\n * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.\n * For instance, in the given sample you cannot get expression (1+3)*2.\n * It's easy to see that the maximum value that you can obtain is 9.\n * Your task is: given a, b and c print the maximum value that you can get.\n *\n * Input\n * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).\n *\n * Output\n * Print the maximum value of the expression that you can obtain.\n */\n\nfun readInt(): Int = readLine()!!.toInt()\n\nfun readInputs():MutableList {\n val inputList:MutableList = mutableListOf()\n for (i in 0..2){\n inputList += listOf(readInt())\n }\n return inputList\n}\n\nfun sum0and1(list: MutableList):List{\n if (list.contains(0)) {\n list.remove(0)\n }\n val checkList = list intersect listOf(1, 1, 1)\n return if(checkList.size < 2) {\n if (list.contains(1)) {\n val index = list.indexOf(1)\n list.remove(1)\n list[index]++\n }\n list.toList()\n }\n else {\n listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())\n }\n}\n\nfun maxResult(list: List): Int = list.reduce { acc, i -> acc * i }\n\nfun main(){\n val inputValues = readInputs().toMutableList()\n val filteredList = sum0and1(inputValues)\n val result = maxResult(filteredList)\n println(result)\n}"}, {"source_code": "import kotlin.math.min\n\n/**\n * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last\n * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of\n * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is\n * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.\n * Here are some ways of placing signs and brackets:\n * 1+2*3=7\n * 1*(2+3)=5\n * 1*2*3=6\n * (1+2)*3=9\n * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.\n * For instance, in the given sample you cannot get expression (1+3)*2.\n * It's easy to see that the maximum value that you can obtain is 9.\n * Your task is: given a, b and c print the maximum value that you can get.\n *\n * Input\n * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).\n *\n * Output\n * Print the maximum value of the expression that you can obtain.\n */\nfun readInt(): Int = readLine()!!.toInt()\n\nfun readInputs():MutableList {\n val inputList:MutableList = mutableListOf()\n for (i in 0..2){\n inputList += listOf(readInt())\n }\n return inputList\n}\n\nfun sum0and1(list: MutableList):List{\n if (list.contains(0)) {\n list.remove(0)\n }\n var counter = 0\n for (i in 0..2){\n if (list[i] == 1) counter++\n }\n return if(counter != 3) {\n if (list.contains(1)) {\n val index = list.indexOf(1)\n list.remove(1)\n if(index!=0 && index!=2) {\n val minValue = min(list[index], list[index - 1])\n if (minValue == list[index]) list[index]++ else list[index - 1]++\n }\n else if(index == 0){\n list[index]++\n }\n else{\n list[index-1]++\n }\n }\n list.toList()\n }\n else {\n listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())\n }\n}\n\nfun maxResult(list: List): Int = list.reduce { acc, i -> acc * i }\n\nfun main(){\n val inputValues = readInputs().toMutableList()\n val filteredList = sum0and1(inputValues)\n val result = maxResult(filteredList)\n println(result)\n}"}, {"source_code": "/**\n * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last\n * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of\n * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is\n * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.\n * Here are some ways of placing signs and brackets:\n * 1+2*3=7\n * 1*(2+3)=5\n * 1*2*3=6\n * (1+2)*3=9\n * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.\n * For instance, in the given sample you cannot get expression (1+3)*2.\n * It's easy to see that the maximum value that you can obtain is 9.\n * Your task is: given a, b and c print the maximum value that you can get.\n *\n * Input\n * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).\n *\n * Output\n * Print the maximum value of the expression that you can obtain.\n */\n\nfun readInt(): Int = readLine()!!.toInt()\n\nfun readInputs():MutableList {\n val inputList:MutableList = mutableListOf()\n for (i in 0..2){\n inputList += listOf(readInt())\n }\n return inputList\n}\n\nfun sum0and1(list: MutableList):List{\n if (list.contains(0)) {\n list.remove(0)\n }\n return if(list != listOf(1, 1, 1)) {\n if (list.contains(1)) {\n list.remove(1)\n list[list.lastIndex]++\n }\n list.toList()\n }\n else {\n listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())\n }\n}\n\nfun maxResult(list: List): Int = list.reduce { acc, i -> acc * i }\n\nfun main(){\n val inputValues = readInputs().toMutableList()\n val filteredList = sum0and1(inputValues)\n val result = maxResult(filteredList)\n println(result)\n}"}, {"source_code": "/**\n * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last\n * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of\n * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is\n * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.\n * Here are some ways of placing signs and brackets:\n * 1+2*3=7\n * 1*(2+3)=5\n * 1*2*3=6\n * (1+2)*3=9\n * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.\n * For instance, in the given sample you cannot get expression (1+3)*2.\n * It's easy to see that the maximum value that you can obtain is 9.\n * Your task is: given a, b and c print the maximum value that you can get.\n *\n * Input\n * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).\n *\n * Output\n * Print the maximum value of the expression that you can obtain.\n */\nfun readInt(): Int = readLine()!!.toInt()\n\nfun readInputs():MutableList {\n val inputList:MutableList = mutableListOf()\n for (i in 0..2){\n inputList += listOf(readInt())\n }\n return inputList\n}\n\nfun sum0and1(list: MutableList):List{\n if (list.contains(0)) {\n list.remove(0)\n }\n var counter = 0\n for (i in 0..2){\n if (list[i] == 1) counter++\n }\n return if(counter < 2) {\n if (list.contains(1)) {\n val index = list.indexOf(1)\n list.remove(1)\n list[index]++\n }\n list.toList()\n }\n else {\n listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())\n }\n}\n\nfun maxResult(list: List): Int = list.reduce { acc, i -> acc * i }\n\nfun main(){\n val inputValues = readInputs().toMutableList()\n val filteredList = sum0and1(inputValues)\n val result = maxResult(filteredList)\n println(result)\n}"}, {"source_code": "/**\n * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last\n * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of\n * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is\n * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.\n * Here are some ways of placing signs and brackets:\n * 1+2*3=7\n * 1*(2+3)=5\n * 1*2*3=6\n * (1+2)*3=9\n * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.\n * For instance, in the given sample you cannot get expression (1+3)*2.\n * It's easy to see that the maximum value that you can obtain is 9.\n * Your task is: given a, b and c print the maximum value that you can get.\n *\n * Input\n * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).\n *\n * Output\n * Print the maximum value of the expression that you can obtain.\n */\n\nfun readInt(): Int = readLine()!!.toInt()\n\nfun readInputs():MutableList {\n val inputList:MutableList = mutableListOf()\n for (i in 0..2){\n inputList += listOf(readInt())\n }\n return inputList\n}\n\nfun sum0and1(list: MutableList):List{\n if (list.contains(0)) {\n list.remove(0)\n }\n val checkList = list intersect listOf(1, 1, 1)\n return if(checkList != setOf(1, 1) && checkList != setOf(1, 1, 1)) {\n if (list.contains(1)) {\n val index = list.indexOf(1)\n list.remove(1)\n list[index]++\n }\n list.toList()\n }\n else {\n listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())\n }\n}\n\nfun maxResult(list: List): Int = list.reduce { acc, i -> acc * i }\n\nfun main(){\n val inputValues = readInputs().toMutableList()\n val filteredList = sum0and1(inputValues)\n val result = maxResult(filteredList)\n println(result)\n}"}, {"source_code": "/**\n * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last\n * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of\n * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is\n * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.\n * Here are some ways of placing signs and brackets:\n * 1+2*3=7\n * 1*(2+3)=5\n * 1*2*3=6\n * (1+2)*3=9\n * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.\n * For instance, in the given sample you cannot get expression (1+3)*2.\n * It's easy to see that the maximum value that you can obtain is 9.\n * Your task is: given a, b and c print the maximum value that you can get.\n *\n * Input\n * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).\n *\n * Output\n * Print the maximum value of the expression that you can obtain.\n */\n\nfun readInt(): Int = readLine()!!.toInt()\n\nfun readInputs():MutableList {\n val inputList:MutableList = mutableListOf()\n for (i in 0..2){\n inputList += listOf(readInt())\n }\n return inputList\n}\n\nfun sum0and1(list: MutableList):List{\n if (list.contains(0)) {\n list.remove(0)\n }\n return if(list != listOf(1, 1, 1)) {\n if (list.contains(1)) {\n val index = list.indexOf(1)\n list.remove(1)\n list[index]++\n }\n list.toList()\n }\n else {\n listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())\n }\n}\n\nfun maxResult(list: List): Int = list.reduce { acc, i -> acc * i }\n\nfun main(){\n val inputValues = readInputs().toMutableList()\n val filteredList = sum0and1(inputValues)\n val result = maxResult(filteredList)\n println(result)\n}"}, {"source_code": "/**\n * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last\n * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of\n * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is\n * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.\n * Here are some ways of placing signs and brackets:\n * 1+2*3=7\n * 1*(2+3)=5\n * 1*2*3=6\n * (1+2)*3=9\n * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.\n * For instance, in the given sample you cannot get expression (1+3)*2.\n * It's easy to see that the maximum value that you can obtain is 9.\n * Your task is: given a, b and c print the maximum value that you can get.\n *\n * Input\n * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).\n *\n * Output\n * Print the maximum value of the expression that you can obtain.\n */\n\nfun readInt(): Int = readLine()!!.toInt()\n\nfun readInputs():MutableList {\n val inputList:MutableList = mutableListOf()\n for (i in 0..2){\n inputList += listOf(readInt())\n }\n return inputList.sortedDescending().toMutableList()\n}\n\nfun sum0and1(list: MutableList):List{\n if (list.contains(0)) {\n list.remove(0)\n }\n if(list.contains(1)){\n list.remove(1)\n list[list.lastIndex] ++\n }\n return list.toList()\n}\n\nfun maxResult(list: List): Int = list.reduce { acc, i -> acc * i }\n\nfun main(){\n val inputValues = readInputs().toMutableList()\n val filteredList = sum0and1(inputValues)\n val result = maxResult(filteredList)\n println(result)\n}"}, {"source_code": "/**\n * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last\n * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of\n * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is\n * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.\n * Here are some ways of placing signs and brackets:\n * 1+2*3=7\n * 1*(2+3)=5\n * 1*2*3=6\n * (1+2)*3=9\n * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.\n * For instance, in the given sample you cannot get expression (1+3)*2.\n * It's easy to see that the maximum value that you can obtain is 9.\n * Your task is: given a, b and c print the maximum value that you can get.\n *\n * Input\n * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).\n *\n * Output\n * Print the maximum value of the expression that you can obtain.\n */\n\nfun readInt(): Int = readLine()!!.toInt()\n\nfun readInputs():MutableList {\n val inputList:MutableList = mutableListOf()\n for (i in 0..2){\n inputList += listOf(readInt())\n }\n return inputList.sortedDescending().toMutableList()\n}\n\nfun sum0and1(list: MutableList):List{\n if (list.contains(0)) {\n list.remove(0)\n }\n return if(list != listOf(1, 1, 1)) {\n if (list.contains(1)) {\n list.remove(1)\n list[list.lastIndex]++\n }\n list.toList()\n }\n else {\n listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())\n }\n}\n\nfun maxResult(list: List): Int = list.reduce { acc, i -> acc * i }\n\nfun main(){\n val inputValues = readInputs().toMutableList()\n val filteredList = sum0and1(inputValues)\n val result = maxResult(filteredList)\n println(result)\n}"}, {"source_code": "import kotlin.math.min\n\n/**\n * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last\n * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of\n * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is\n * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.\n * Here are some ways of placing signs and brackets:\n * 1+2*3=7\n * 1*(2+3)=5\n * 1*2*3=6\n * (1+2)*3=9\n * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.\n * For instance, in the given sample you cannot get expression (1+3)*2.\n * It's easy to see that the maximum value that you can obtain is 9.\n * Your task is: given a, b and c print the maximum value that you can get.\n *\n * Input\n * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).\n *\n * Output\n * Print the maximum value of the expression that you can obtain.\n */\nfun readInt(): Int = readLine()!!.toInt()\n\nfun readInputs():MutableList {\n val inputList:MutableList = mutableListOf()\n for (i in 0..2){\n inputList += listOf(readInt())\n }\n return inputList\n}\n\nfun sum0and1(list: MutableList):List{\n if (list.contains(0)) {\n list.remove(0)\n }\n var counter = 0\n for (i in 0..2){\n if (list[i] == 1) counter++\n }\n return if(counter < 2) {\n if (list.contains(1)) {\n val index = list.indexOf(1)\n list.remove(1)\n if(index!=0 && index!=2) {\n val minValue = min(list[index], list[index - 1])\n if (minValue == list[index]) list[index]++ else list[index - 1]++\n }\n else if(index == 0){\n list[index]++\n }\n else{\n list[index-1]++\n }\n }\n list.toList()\n }\n else {\n listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())\n }\n}\n\nfun maxResult(list: List): Int = list.reduce { acc, i -> acc * i }\n\nfun main(){\n val inputValues = readInputs().toMutableList()\n val filteredList = sum0and1(inputValues)\n val result = maxResult(filteredList)\n println(result)\n}"}], "src_uid": "1cad9e4797ca2d80a12276b5a790ef27"} {"nl": {"description": "There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3 × 3 with digits from 1 to 9.Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations.", "input_spec": "Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.».", "output_spec": "Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise.", "sample_inputs": ["XX.\n...\n.XX", "X.X\nX..\n..."], "sample_outputs": ["YES", "NO"], "notes": "NoteIf you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry"}, "positive_code": [{"source_code": "import java.util.Scanner\n\nfun main(args : Array) {\n\n var line1: MutableList = mutableListOf()\n var line2: MutableList = mutableListOf()\n var line3: MutableList = mutableListOf()\n val a = readLine()!!\n val b = readLine()!!\n val c = readLine()!!\n\n for (char in a) { line1.add(char) }\n for (char in b) { line2.add(char) }\n for (char in c) { line3.add(char) }\n\n\n if(line1[0]==line1[2] && line2[0]==line2[2] && line3[0]==line3[2] && line1[1]==line3[1]){\n println(\"YES\")\n }\n else if(line1[0]==line3[0] && line1[1]==line3[1] && line1[2]==line3[2] && line2[0]==line2[2]){\n println(\"YES\")\n }\n else if(line1[0]==line3[2] && line1[1]==line3[1] && line1[2]==line3[0] && line2[0]==line2[2]){\n println(\"YES\")\n }\n else {\n println(\"NO\")\n\n }\n\n}\n"}, {"source_code": "fun main(args: Array) {\n val a = Array(3) {readLine()}\n var bad = false\n for (i in 0 until 3)\n for (j in 0 until 3)\n bad = bad or (a[i]!![j] != a[2 - i]!![2 - j])\n println(if (bad) \"NO\" else \"YES\")\n}\n"}, {"source_code": "fun main() {\n val board = Array(3) { \"\" }\n board[0] = readLine()!!\n board[1] = readLine()!!\n board[2] = readLine()!!\n for (row in 0 until 2)\n for (column in 0 until 3)\n if (board[row][column] != board[2 - row][2 - column]) return print(\"NO\")\n print(\"YES\")\n}"}, {"source_code": "fun main(args: Array) {\n\n val matrix = Array(3){\"\"}\n for (x in 0 until 3) matrix[x] = readLine()!!\n when {\n matrix[0][0] != matrix[2][2] -> print(\"NO\")\n matrix[0][1] != matrix[2][1] -> print(\"NO\")\n matrix[0][2] != matrix[2][0] -> print(\"NO\")\n matrix[1][0] != matrix[1][2] -> print(\"NO\")\n else -> print(\"YES\")\n }\n}"}], "negative_code": [], "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9"} {"nl": {"description": "Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.You are asked to calculate the number of ways he can do it. Two ways to break chocolate are considered distinct if one of them contains a break between some two adjacent pieces and the other one doesn't. Please note, that if Bob doesn't make any breaks, all the bar will form one piece and it still has to have exactly one nut.", "input_spec": "The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of pieces in the chocolate bar. The second line contains n integers ai (0 ≤ ai ≤ 1), where 0 represents a piece without the nut and 1 stands for a piece with the nut.", "output_spec": "Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.", "sample_inputs": ["3\n0 1 0", "5\n1 0 1 0 1"], "sample_outputs": ["1", "4"], "notes": "NoteIn the first sample there is exactly one nut, so the number of ways equals 1 — Bob shouldn't make any breaks.In the second sample you can break the bar in four ways:10|10|11|010|110|1|011|01|01"}, "positive_code": [{"source_code": "fun main() {\n data class R(var t: Long, var m: Int, var f: Boolean)\n readLine()\n readLine()!!.split(\" \").fold(R(1, 1, true)) { acc, i ->\n if (i == \"1\") {\n if (!acc.f) acc.t *= acc.m\n acc.m = 1\n acc.f = false\n } else {\n acc.m++\n }\n acc\n }.run { print(if (f) 0 else t) }\n}"}], "negative_code": [{"source_code": "fun main() {\n data class R(var t: Long, var m: Int, var f: Boolean)\n readLine()\n readLine()!!.split(\" \").fold(R(1, 1, true)) { acc, i ->\n if (i == \"1\") {\n if (!acc.f) acc.t *= acc.m\n acc.m = 1\n acc.f = false\n } else {\n acc.m++\n }\n acc\n }.run { print(t) }\n}"}], "src_uid": "58242665476f1c4fa723848ff0ecda98"} {"nl": {"description": "The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square t. As the king is not in habit of wasting his time, he wants to get from his current position s to square t in the least number of moves. Help him to do this. In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).", "input_spec": "The first line contains the chessboard coordinates of square s, the second line — of square t. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.", "output_spec": "In the first line print n — minimum number of the king's moves. Then in n lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them. ", "sample_inputs": ["a8\nh1"], "sample_outputs": ["7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"], "notes": null}, "positive_code": [{"source_code": "import java.util.Scanner\n\nfun main(args : Array) {\n\n var coor1: MutableList = mutableListOf()\n var coor2: MutableList = mutableListOf()\n val n = readLine()!!\n val m = readLine()!!\n\n for(char in n){ coor1.add(char) }\n for(char in m){ coor2.add(char) }\n\n if(coor1[0]==coor2[0] && coor1[1]==coor2[1]){ println(0) }\n else if(coor1[0]==coor2[0] && coor1[1]>coor2[1]){\n println(coor1[1]-coor2[1])\n for(i in 1..(coor1[1]-coor2[1])){ println(\"D\") }\n }\n else if(coor1[0]==coor2[0] && coor1[1]coor2[0]){\n println(coor1[0]-coor2[0])\n for(i in 1..(coor1[0]-coor2[0])){ println(\"L\") }\n }\n else if(coor1[1](coor2[0]-coor1[0])){\n println((coor2[1]-coor1[1]))\n for(i in 1..(coor2[0]-coor1[0])){ println(\"RU\") }\n for(i in 1..(coor2[1]-coor1[1])-(coor2[0]-coor1[0])){ println(\"U\") }\n }\n else {\n println((coor2[1] - coor1[1]))\n for (i in 1..(coor2[0] - coor1[0])) { println(\"RU\") }\n }\n }\n else if(coor1[1]>coor2[1] && coor1[0](coor2[0]-coor1[0])){\n println((coor1[1]-coor2[1]))\n for(i in 1..(coor2[0]-coor1[0])){ println(\"RD\") }\n for(i in 1..(coor1[1]-coor2[1])-(coor2[0]-coor1[0])){ println(\"D\") }\n }\n else {\n println((coor1[1] - coor2[1]))\n for (i in 1..(coor1[1] - coor2[1])) { println(\"RD\") }\n }\n }\n else if(coor1[1]coor2[0]){\n if((coor2[1]-coor1[1])<(coor1[0]-coor2[0])){\n println((coor1[0]-coor2[0]))\n for(i in 1..(coor2[1]-coor1[1])){ println(\"LU\") }\n for(i in 1..(coor1[0]-coor2[0])-(coor2[1]-coor1[1])){ println(\"L\") }\n }\n else if((coor2[1]-coor1[1])>(coor1[0]-coor2[0])){\n println((coor2[1]-coor1[1]))\n for(i in 1..(coor1[0]-coor2[0])){ println(\"LU\") }\n for(i in 1..(coor2[1]-coor1[1])-(coor1[0]-coor2[0])){ println(\"U\") }\n }\n else {\n println((coor2[1] - coor1[1]))\n for (i in 1..(coor2[1] - coor1[1])) { println(\"LU\") }\n }\n }\n else if(coor1[1]>coor2[1] && coor1[0]>coor2[0]){\n if((coor1[1]-coor2[1])<(coor1[0]-coor2[0])){\n println((coor1[0]-coor2[0]))\n for(i in 1..(coor1[1]-coor2[1])){ println(\"LD\") }\n for(i in 1..(coor1[0]-coor2[0])-(coor1[1]-coor2[1])){ println(\"L\") }\n }\n else if((coor1[1]-coor2[1])>(coor1[0]-coor2[0])){\n println((coor1[1]-coor2[1]))\n for(i in 1..(coor1[0]-coor2[0])){ println(\"LD\") }\n for(i in 1..(coor1[1]-coor2[1])-(coor1[0]-coor2[0])){ println(\"D\") }\n }\n else {\n println((coor1[1] - coor2[1]))\n for (i in 1..(coor1[1] - coor2[1])) { println(\"LD\") }\n }\n }\n}"}, {"source_code": "import kotlin.math.abs\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val (s, n) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val n = r.readLine()!!.toInt()\n val st = r.readLine()!!\n val en = r.readLine()!!\n var right = en[0].toInt() - st[0].toInt()\n var up = en[1].toInt() - st[1].toInt()\n println(maxOf(abs(right), abs(up)))\n var ans = 0\n while (up != 0 || right != 0) {\n when {\n up != 0 && right != 0 -> {\n when {\n up > 0 && right > 0 -> {\n println(\"RU\")\n up--\n right--\n }\n up > 0 && right < 0 -> {\n println(\"LU\")\n up--\n right++\n }\n up < 0 && right > 0 -> {\n println(\"RD\")\n up++\n right--\n }\n up < 0 && right < 0 -> {\n println(\"LD\")\n up++\n right++\n }\n }\n }\n up == 0 -> if (right>0){\n println(\"R\")\n right--\n } else{\n println(\"L\")\n right++\n }\n right==0->if (up>0){\n println(\"U\")\n up--\n }else{\n println(\"D\")\n up++\n }\n }\n }\n}"}, {"source_code": "import java.util.*\nimport java.math.*\nimport kotlin.math.*\n\nfun readLn()=readLine()!!\nfun readInt()=readLn().toInt()\nfun readInts()=readLn().split(\" \").map{it.toInt()}\nfun readLong()=readLn().toLong()\nfun readLongs()=readLn().split(\" \").map{it.toLong()}\n\nval out=mutableListOf()\nfun printLine(s:String){out.add(s)}\nfun output(){println(out.joinToString(\"\\n\"))}\n\nfun main(){\n var a=readLn()\n var b=readLn()\n var x=abs(a[0]-b[0])\n var y=abs(a[1]-b[1])\n var ch1=if(a[0]>b[0])'L' else 'R'\n var ch2=if(a[1]>b[1])'D' else 'U'\n printLine(\"${max(x,y)}\")\n repeat(min(x,y)){printLine(\"$ch1$ch2\")}\n for(i in 1..x-y){printLine(\"$ch1\")}\n for(i in 1..y-x){printLine(\"$ch2\")}\n output()\n}"}, {"source_code": "import java.util.Scanner\nimport java.lang.Math.*\n\nclass Cell(s : String) {\n val col = s[0] - 'a'\n val row = s[1].toInt()\n}\n\nfun move(source: Cell, target: Cell) {\n var deltaCol = target.col - source.col\n var deltaRow = target.row - source.row\n val absoluteCol = abs(deltaCol)\n val absoluteRow = abs(deltaRow)\n val steps = max(absoluteCol, absoluteRow)\n println(steps)\n for (i in 0 until steps) {\n if (deltaCol > 0) {\n print('R')\n deltaCol--\n } else if (deltaCol < 0) {\n print('L')\n deltaCol++\n }\n\n if (deltaRow > 0) {\n print('U')\n deltaRow--\n } else if (deltaRow < 0) {\n print('D')\n deltaRow++\n }\n\n println()\n }\n}\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val source = Cell(scanner.nextLine())\n val target = Cell(scanner.nextLine())\n move(source, target)\n}"}, {"source_code": "fun a3() {\n var result = arrayOf()\n var first = \"\"\n var second = \"\"\n var intSize : Int\n var charSize : Int\n val loopSize : Int\n\n val start = readLine()!!\n val end = readLine()!!\n\n if (start[1].toInt() > end[1].toInt()) {\n intSize = start[1].toInt() - end[1].toInt()\n second = \"D\"\n } else {\n intSize = end[1].toInt() - start[1].toInt()\n second = \"U\"\n }\n\n if (start[0] > end[0]) {\n charSize = start[0] - end[0]\n first = \"L\"\n } else {\n charSize = end[0] - start[0]\n first = \"R\"\n }\n\n loopSize = if(intSize > charSize) intSize else charSize\n\n for (i in 0 until loopSize) {\n if(intSize <= 0) second = \"\"\n if(charSize <= 0) first = \"\"\n\n intSize--\n charSize--\n\n result += \"$first$second\"\n }\n\n println(loopSize)\n result.forEach {\n println(it)\n }\n}\n\nfun main() {\n a3()\n}"}, {"source_code": "import java.util.*\n\nfun main(args: Array) {\n main { readLine() }\n}\n\nfun main(readLine: () -> String?) {\n val problem = readProblem(readLine)\n val solution = solve(problem)\n printSolution(solution)\n}\n\n// READ\n\nfun readProblem(readLine: () -> String?): Problem {\n val start = Position.parse(readLine()!!.trim())\n val target = Position.parse(readLine()!!.trim())\n return Problem(start, target)\n}\n\nclass Position (val x: Int, val y: Int) {\n companion object {\n fun parse(str: String): Position {\n return Position(\n str[0].toInt() - 'a'.toInt(),\n str[1].toInt() - '0'.toInt()\n )\n }\n }\n\n override fun toString(): String {\n return \"($x - $y)\"\n }\n}\n\nclass Problem (val from: Position, val to: Position)\n\n// SOLVE PROBLEM\n\nfun solve(problem: Problem): Answer {\n val answer = Answer()\n var xd = problem.to.x - problem.from.x\n var yd = problem.to.y - problem.from.y\n when {\n (xd < 0 && yd < 0) -> {\n val len = if (-xd < -yd) { -xd } else { -yd }\n xd += len\n yd += len\n answer.go(Direction.LD, len)\n }\n (xd < 0 && yd > 0) -> {\n val len = if (-xd < yd) { -xd } else { yd }\n xd += len\n yd -= len\n answer.go(Direction.LU, len)\n }\n (xd > 0 && yd > 0) -> {\n val len = if (xd < yd) { xd } else { yd }\n xd -= len\n yd -= len\n answer.go(Direction.RU, len)\n }\n (xd > 0 && yd < 0) -> {\n val len = if (xd < -yd) { xd } else { -yd }\n xd -= len\n yd += len\n answer.go(Direction.RD, len)\n }\n }\n when {\n (xd < 0) -> {\n answer.go(Direction.L, -xd)\n }\n (xd > 0) -> {\n answer.go(Direction.R, xd)\n }\n (yd < 0) -> {\n answer.go(Direction.D, -yd)\n }\n (yd > 0) -> {\n answer.go(Direction.U, yd)\n }\n }\n return answer\n}\n\n// PRINT SOLUTION\n\nclass Answer () {\n private val segments: MutableList = ArrayList()\n\n fun go(dir: Direction, length: Int) {\n if (length > 0) {\n segments.add(Segment(dir, length))\n }\n }\n\n fun print(consumer: (String) -> Unit) {\n val length = segments.map { it.length } .sum()\n consumer(length.toString())\n for (seg in segments) {\n for (i in 1..seg.length) {\n consumer(seg.dir.name)\n }\n }\n }\n}\n\nclass Segment(val dir: Direction, val length: Int) {\n override fun toString(): String {\n val sb = StringBuilder()\n for (i in 1..length) {\n sb.append(dir)\n }\n return sb.toString()\n }\n}\n\nenum class Direction() {\n L, LD, D, RD, R, RU, U, LU\n}\n\nfun printSolution(solution: Answer) {\n solution.print { println(it) }\n}\n\n"}, {"source_code": "import kotlin.math.abs\nimport kotlin.math.max\n\nfun main() {\n val from = readLine()!!\n val to = readLine()!!\n var horizontal = from[0] - to[0]\n var vertical = from[1] - to[1]\n println(max(abs(horizontal), abs(vertical)))\n while (horizontal != 0 || vertical != 0) {\n when {\n horizontal < 0 -> {\n print('R'); horizontal++\n }\n horizontal > 0 -> {\n print('L'); horizontal--\n }\n }\n when {\n vertical < 0 -> {\n print('U'); vertical++\n }\n vertical > 0 -> {\n print('D'); vertical--\n }\n }\n println()\n }\n}"}, {"source_code": "import kotlin.math.abs\n\nprivate fun readLn() = readLine()!!\n\nfun main() {\n val s = readLn().toCharArray()\n val d = readLn().toCharArray()\n\n var dr: Int = abs(s[0] - d[0])\n var dw: Int = abs(s[1] - d[1])\n\n val n = maxOf(dr, dw)\n println(n)\n repeat(n) {\n if(dr>0) {\n if (s[0] > d[0]) {\n s[0]--\n print(\"L\")\n } else {\n s[0]++\n print(\"R\")\n }\n dr--\n }\n if(dw>0) {\n if (s[1] > d[1]) {\n s[1]--\n print(\"D\")\n } else {\n s[1]++\n print(\"U\")\n }\n dw--\n }\n println()\n }\n}"}, {"source_code": "fun main() {\n val s = readLine()!!.toCharArray()\n val d = readLine()!!.toCharArray()\n var hori = s[0] - d[0]\n var vert = s[1] - d[1]\n if (hori >= 0 && vert >= 0) { // a8 - h1 = 7 fin\n if (hori > vert) {\n println(hori)\n } else {\n println(vert)\n }\n } else if (hori <= 0 && vert >= 0) {\n if (-hori > vert) {\n println(-hori)\n } else {\n println(vert)\n }\n } else if (hori >= 0 && vert <= 0) {\n if (hori > -vert) {\n println(hori)\n } else {\n println(-vert)\n }\n } else { // hori and vert are negative , (-x,0)\n if (-hori < -vert) {\n println(-vert)\n } else {\n println(-hori)\n }\n }\n while (hori != 0 || vert != 0) { // add or sub until equals to 0\n //println(\"$hori $vert\")\n if (hori < 0) {\n print('R')\n hori++\n } else if (hori > 0) {\n print('L')\n hori--\n }\n if (vert < 0) {\n print('U')\n vert++\n } else if (vert > 0) {\n print('D')\n vert--\n }\n println()\n }\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\n\nfun main() {\n var reader = Scanner(System.`in`)\n\n var start = reader.nextLine().trim()\n var end = reader.nextLine().trim()\n\n var x = start[0] - end[0]\n var y = start[1] - end[1]\n\n val res = max(abs(x), abs(y))\n println(res)\n repeat(res) {\n if (x > 0) {\n print('L')\n x--\n }\n if (x < 0) {\n print('R')\n x++\n }\n if (y > 0) {\n print('D')\n y--\n }\n if (y < 0) {\n print('U')\n y++\n }\n println()\n }\n}"}, {"source_code": "fun readString1(): String\n{\n val line: String? = readLine()\n if (line == null) return \"\"\n return line.trim()\n}\n\nfun main (args: Array)\n{\n val first: String = readString1()\n val second: String = readString1()\n\n var x1: Int = 0\n var y1: Int = 0\n var x2: Int = 0\n var y2: Int = 0\n\n x1 = first.get(0).toInt() - 'a'.toInt()\n y1 = first.get(1).toString().toInt()-1\n\n\n x2 = second.get(0).toInt() - 'a'.toInt()\n y2 = second.get(1).toString().toInt()-1\n\n var c: Int = 0\n var r: MutableList = mutableListOf()\n\n while (!(x1==x2&&y1==y2))\n {\n\n var m: String = \"\"\n\n if(x1 > x2)\n {\n x1--\n m+=\"L\"\n }\n else if(x1 < x2)\n {\n x1++\n m+=\"R\"\n }\n\n if(y1 > y2)\n {\n y1--\n m+=\"D\"\n }\n else if(y1 < y2)\n {\n y1++\n m+=\"U\"\n }\n r.add(m)\n c++\n }\n print(r.joinToString(separator = \"\\n\",prefix = (\"$c\\n\")))\n\n}"}], "negative_code": [{"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val (s, n) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val n = r.readLine()!!.toInt()\n val st = r.readLine()!!\n val en = r.readLine()!!\n var right = en[0].toInt() - st[0].toInt()\n var up = en[1].toInt() - st[1].toInt()\n println(maxOf(right, up))\n var ans = 0\n while (up != 0 || right != 0) {\n when {\n up != 0 && right != 0 -> {\n when {\n up > 0 && right > 0 -> {\n println(\"RU\")\n up--\n right--\n }\n up > 0 && right < 0 -> {\n println(\"LU\")\n up--\n right++\n }\n up < 0 && right > 0 -> {\n println(\"RD\")\n up++\n right--\n }\n up < 0 && right < 0 -> {\n println(\"LD\")\n up++\n right++\n }\n }\n }\n up == 0 -> if (right>0){\n println(\"R\")\n right--\n } else{\n println(\"L\")\n right++\n }\n right==0->if (up>0){\n println(\"U\")\n up--\n }else{\n println(\"D\")\n up++\n }\n }\n }\n}"}, {"source_code": "fun main() {\n val s = readLine()!!.toCharArray()\n val d = readLine()!!.toCharArray()\n var hori = s[0]-d[0]\n var vert = s[1]-d[1]\n if(hori>0&&vert>0){ // a8 - h1 = 7 fin\n if(hori>vert){\n println(hori)\n }else{\n println(vert)\n }\n }else if(hori<0&&vert>0){\n if(-hori > vert){\n println(-hori)\n }else{\n println(vert)\n }\n }else if(hori>0&&vert<0){\n if(hori>-vert){\n println(hori)\n }else{\n println(-vert)\n }\n }else{ // hori and vert are negative\n if(hori>vert){\n println(-vert)\n }else{\n println(-hori)\n }\n }\n while (hori!=0||vert!=0){ // add or sub until equals to 0\n //println(\"$hori $vert\")\n if(hori<0){\n print('R')\n hori++\n }else if(hori > 0){\n print('L')\n hori--\n }\n if(vert<0){\n print('U')\n vert++\n }else if(vert > 0){\n print('D')\n vert--\n }\n println()\n }\n}"}, {"source_code": "fun main() {\n val s = readLine()!!.toCharArray()\n val d = readLine()!!.toCharArray()\n var hori = s[0]-d[0]\n var vert = s[1]-d[1]\n if(hori>0&&vert>0){ // a8 - h1 = 7 fin\n if(hori>vert){\n println(hori)\n }else{\n println(vert)\n }\n }else if(hori<0&&vert>0){\n if(-hori > vert){\n println(-hori)\n }else{\n println(vert)\n }\n }else if(hori>0&&vert<0){\n if(hori>-vert){\n println(hori)\n }else{\n println(-vert)\n }\n }else{ // hori and vert are negative\n if(hori>vert){\n println(-vert)\n }else{\n println(-hori)\n }\n }\n while (hori!=0&&vert!=0){\n if(hori<0){\n print('R')\n hori++\n }else{\n print('L')\n hori--\n }\n if(vert<0){\n print('D')\n vert++\n }else{\n print('U')\n vert--\n }\n println()\n }\n}"}, {"source_code": "import java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\n\nfun main() {\n var reader = Scanner(System.`in`)\n\n var start = reader.nextLine().trim()\n var end = reader.nextLine().trim()\n\n var x = start[0] - end[0]\n var y = start[1] - end[1]\n\n val res = max(abs(x), abs(y))\n println(res)\n repeat(res) {\n if (x > 0) {\n print('L')\n x--\n }\n if (x < 0) {\n print('R')\n x++\n }\n if (y > 0) {\n println('D')\n y--\n }\n if (y < 0) {\n println('U')\n y++\n }\n }\n}"}], "src_uid": "d25d454702b7755297a7a8e1f6f36ab9"} {"nl": {"description": "As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last n days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last n days, or not.", "input_spec": "The first line of input contains single integer n (2 ≤ n ≤ 100) — the number of days. The second line contains a string of length n consisting of only capital 'S' and 'F' letters. If the i-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.", "output_spec": "Print \"YES\" if you flew more times from Seattle to San Francisco, and \"NO\" otherwise. You can print each letter in any case (upper or lower).", "sample_inputs": ["4\nFSSF", "2\nSF", "10\nFFFFFFFFFF", "10\nSSFFSFFSFF"], "sample_outputs": ["NO", "YES", "NO", "YES"], "notes": "NoteIn the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is \"NO\".In the second example you just flew from Seattle to San Francisco, so the answer is \"YES\".In the third example you stayed the whole period in San Francisco, so the answer is \"NO\".In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though."}, "positive_code": [{"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!.toInt()\n //val v = r.readLine()!!.split(\" \").map { it.toLong() }\n val str = r.readLine()!!\n var sf = 0\n var fs = 0\n (0..n-2).forEach {\n when{\n str[it]=='S'&&str[it+1]=='F' -> sf++\n str[it]=='F'&&str[it+1]=='S' -> fs++\n }\n }\n println(if (sf>fs) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main(args: Array){\n val n = readLine()!!.toInt()\n val s = readLine()!!\n if (s[0]=='S' && s[n-1]=='F') println(\"YES\") else println(\"NO\")\n}"}, {"source_code": "fun main(args:Array)\n{\nvar n=readLine()!!\n var t=readLine()!!\n var switch=0\n var counter=0\n var counter1=0\n var flag=false\n var f=false\nfor(i in t) {\n if(i=='S')\n {\n f=true\n }\n if(i=='F'&&f)\n {\n f=false\n counter++;\n }\n}\n f=false\n for(i in t) {\n if(i=='F')\n {\n f=true\n }\n if(i=='S'&&f)\n {\n f=false\n counter1++;\n }\n }\n\n println(if(counter>counter1) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main(args: Array) {\n readLine()\n val input = readLine()!!\n val chars = input.toCharArray()\n\n var previousChar = chars.first()\n var i = 0\n var sf = 0\n var fs = 0\n\n for (char in chars) {\n if (i > 0 && char != previousChar) {\n if (char == 'S') {\n fs += 1\n } else {\n sf += 1\n }\n }\n previousChar = char\n i += 1\n }\n\n if (sf > fs) println(\"YES\") else println(\"NO\")\n}"}, {"source_code": "/* https://codeforces.com/problemset/problem/867/A */\n\nfun main() {\n readLine()!!.toInt() // read number of days\n val cityInitials = readLine()!!\n var tripsFromStoF = 0\n var tripsFromFtoS = 0\n var lastChar = '_'\n cityInitials.forEach {\n if (it == 'F' && lastChar == 'S') {\n tripsFromStoF++\n } else if (it == 'S' && lastChar == 'F') {\n tripsFromFtoS++\n }\n lastChar = it\n }\n println(if (tripsFromStoF > tripsFromFtoS) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main() {\n val nightCount = Integer.parseInt(readLine()!!)\n val cities = readLine()!!\n var sf = 0\n var fs = 0\n for(i in 0 until nightCount - 1) {\n val flight = cities.substring(i, i + 2)\n when (flight) {\n \"SF\" -> sf++\n \"FS\" -> fs++\n }\n }\n\n if (sf > fs) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}"}, {"source_code": "fun main() {\n var n = readLine()!!.toInt()\n val line = readLine()!!.toCharArray()\n var SF = 0\n var FS = 0\n for (i in 0 until line.size-1)\n {\n if (line[i] == 'S' && line[i+1] == 'F')\n SF++\n else if (line[i] == 'F' && line[i+1] == 'S')\n FS++\n }\n\n if (SF > FS)\n print(\"YES\")\n else\n print(\"NO\")\n\n}"}, {"source_code": "fun main() {\n readLine()\n val s = readLine()\n\n var franCount = 0\n var sietlCount = 0\n var last = s!![0]\n for (c in s!!) {\n if(last != c) {\n if(c == 'F') {\n franCount++\n } else {\n sietlCount++\n }\n last = c\n }\n }\n\n if(franCount > sietlCount) print(\"Yes\") else print(\"No\")\n}"}, {"source_code": "private fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n\nfun main() {\n readInt()\n val flights = readLn()\n var f = 0\n var s = 0\n for (i in 1 until flights.length) {\n if (flights[i] != flights[i - 1]) {\n if (flights[i] == 'S') s++\n else f++\n }\n }\n if (f > s) println(\"yes\") else println(\"no\")\n}\n"}, {"source_code": "/**\n * Problem Link: https://codeforces.com/problemset/problem/867/A\n * Difficulty: 600\n */\nfun main(args: Array) {\n readLine()!!\n val s = readLine()!!\n var lastChar = ' '\n var SF = 0\n var FS = 0\n s.forEach { c ->\n if (lastChar == 'F' && c == 'S') {\n FS++\n }\n if (lastChar == 'S' && c == 'F') {\n SF++\n }\n lastChar = c\n }\n println(\"${if (SF > FS) \"YES\" else \"NO\"}\")\n}"}, {"source_code": "import java.lang.StringBuilder\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.max\n\nfun main() {\n var sc = Scanner(System.`in`)\n var n = sc.nextInt()\n var str = sc.next()\n var s = 0\n\n for (i in 1..str.length - 1) {\n if (str[i] == 'F' && str[i - 1] == 'S') {\n s++\n } else if (str[i] == 'S' && str[i - 1] == 'F') {\n s--\n }\n }\n if (s > 0) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n\n}"}, {"source_code": "fun main() {\n readInteger()\n val s = readLine()!!\n var pre = s[0]\n var sCount = 0\n var fCount = 0\n for (i in 1 until s.length) {\n if (pre != s[i]){\n if (pre == 'S') {\n sCount++\n } else {\n fCount++\n }\n }\n\n pre = s[i]\n }\n\n val ans = if (sCount > fCount) {\n \"Yes\"\n } else {\n \"No\"\n }\n\n println(ans)\n}\n\nfun readInteger() = readLine()!!.toInt()\nfun readStrings() = readLine()!!.split(\" \")\nfun readIntegers() = readStrings().map(String::toInt)\n"}, {"source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n var String = readLine().toString()\n var dem1 = 0\n var dem2 = 0\n for (i in 0..(String.length-2)){\n if (String[i] == 'F' && String[i+1] == 'S')\n dem1 ++\n if (String[i+1] == 'F' && String[i] == 'S')\n dem2 ++\n }\n print( if (dem1>=dem2) \"NO\" else \"YES\")\n}\n"}, {"source_code": "fun main() {\n val numDays = readLine()!!.toInt()\n val cities = readLine()!!\n var counter = 0\n for (pos in 1 until numDays) {\n when {\n (cities[pos] == 'S' && cities[pos - 1] == 'F') -> counter--\n (cities[pos] == 'F' && cities[pos - 1] == 'S') -> counter++\n }\n }\n if (counter > 0) print(\"YES\") else print(\"NO\")\n}"}, {"source_code": " fun main(args: Array){\n var temp = 0\n val n = readLine()!!.toInt()\n val s = readLine()!!\n \n \n for(i in 0 until n-1){\n when {\n (s[i] == 'S' && s[i+1] == 'F') ->temp++\n (s[i] == 'F' && s[i+1] == 'S') ->temp--\n } \n }\n if(temp>0) print (\"YES\") else print(\"NO\")\n }\n"}, {"source_code": "private fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readLong() = readLn().toLong()\nprivate fun readDouble() = readLn().toDouble()\nprivate fun readStrings() = readLn().split(' ')\nprivate fun readInts() = readStrings().map { it.toInt() }\nprivate fun readLongs() = readStrings().map { it.toLong() }\nprivate fun readDoubles() = readStrings().map { it.toDouble() }\n\nfun main() {\n val n = readInt()\n val s = readLn()\n var cntSF = 0\n var cntFS = 0\n for (i in 1 until s.length) {\n when (s.subSequence(i - 1, i + 1)) {\n \"SF\" -> cntSF++\n \"FS\" -> cntFS++\n }\n }\n if (cntSF > cntFS) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}\n"}, {"source_code": "import java.util.Scanner\nimport kotlin.math.max\n\nfun main() {\n val reader = Scanner(System.`in`)\n\n var n = reader.nextInt()\n var s = reader.next()\n\n var win = 0\n var lose = 0\n for(i in 1..n-1){\n if (s[i] == 'F' && s[i-1] == 'S') {\n win++\n } else if (s[i] == 'S' && s[i-1] == 'F') {\n lose++\n }\n }\n if(win > lose) println(\"YES\")\n else println(\"NO\")\n}"}], "negative_code": [{"source_code": "fun main(args:Array)\n{\n\n var t=readLine()!!\n var switch=0\n var counter=0\n var counter1=0\n var flag=false\n var f=false\nfor(i in t) {\n if(i=='S')\n {\n f=true\n }\n if(i=='F'&&f)\n {\n f=false\n counter++;\n }\n}\n f=false\n for(i in t) {\n if(i=='F')\n {\n f=true\n }\n if(i=='S'&&f)\n {\n f=false\n counter1++;\n }\n }\n \n println(if(counter>counter1) \"YES\" else \"NO\")\n}"}, {"source_code": "fun main() {\n val nightCount = Integer.parseInt(readLine()!!)\n val cities = readLine()!!\n var sf = 0\n var fs = 0\n for(i in 0 until nightCount - 1) {\n val flight = cities.substring(i, i + 2)\n println(flight)\n when (flight) {\n \"SF\" -> sf++\n \"FS\" -> fs++\n }\n }\n\n if (sf > fs) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}"}], "src_uid": "ab8a2070ea758d118b3c09ee165d9517"} {"nl": {"description": "Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly n, based on the alphabet of size m. Any its substring with length equal to k is a palindrome. How many such strings exist? Your task is to find their quantity modulo 1000000007 (109 + 7). Be careful and don't miss a string or two!Let us remind you that a string is a palindrome if it can be read the same way in either direction, from the left to the right and from the right to the left.", "input_spec": "The first and only line contains three integers: n, m and k (1 ≤ n, m, k ≤ 2000).", "output_spec": "Print a single integer — the number of strings of the described type modulo 1000000007 (109 + 7).", "sample_inputs": ["1 1 1", "5 2 4"], "sample_outputs": ["1", "2"], "notes": "NoteIn the first sample only one string is valid: \"a\" (let's denote the only letter of our alphabet as \"a\").In the second sample (if we denote the alphabet letters as \"a\" and \"b\") the following strings are valid: \"aaaaa\" and \"bbbbb\"."}, "positive_code": [{"source_code": "import kotlin.math.*\nimport java.math.BigInteger\n\n\nfun pow(n: Long, exp: Int): Long {\n val maxValue = BigInteger.valueOf(10).pow(9) + BigInteger.valueOf(7)\n return (BigInteger.valueOf(n).pow(exp) % maxValue).toLong()\n}\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val input = r.readLine()!!.split(\" \").map { it.toLong() }\n\n if (input[2] == 1L || input[2] > input[0]) {\n println(pow(input[1], input[0].toInt()))\n } else if (input[0] == input[2]) {\n println(pow(input[1], (input[0] + 1).toInt() / 2))\n } else {\n val maxValue = 10.toDouble().pow(9).toLong() + 7\n if (input[2] % 2L == 0L) {\n println(input[1] % maxValue)\n } else {\n println((input[1]*input[1]) % maxValue)\n }\n }\n}\n"}], "negative_code": [{"source_code": "import kotlin.math.*\nimport java.math.BigInteger\n\n\nfun pow(n: Long, exp: Int): Long {\n val maxValue = BigInteger.valueOf(10).pow(9) + BigInteger.valueOf(7)\n return (BigInteger.valueOf(n).pow(exp) % maxValue).toLong()\n}\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val input = r.readLine()!!.split(\" \").map { it.toLong() }\n\n if (input[2] == 1L || input[2] > input[0]) {\n println(pow(input[1], input[0].toInt()))\n } else if (input[0] == input[2]) {\n println(pow(input[1], input[0].toInt()))\n } else {\n val maxValue = 10.toDouble().pow(9).toLong() + 7\n if (input[2] % 2L == 0L) {\n println(input[1] % maxValue)\n } else {\n println((input[1]*input[1]) % maxValue)\n }\n }\n}\n"}, {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val input = r.readLine()!!.split(\" \").map { it.toInt() }\n val length = input[0]\n val letters = input[1]\n val sublength = input[2]\n if (length < sublength) {\n println(0)\n } else {\n println(letters)\n }\n}\n"}, {"source_code": "import kotlin.math.*\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val input = r.readLine()!!.split(\" \").map { it.toInt() }\n val length = input[0]\n val letters = input[1]\n val sublength = input[2]\n val maxValue = 10.toDouble().pow(9).toLong() + 7;\n if (sublength == 1 || sublength > length) {\n println(letters.toDouble().pow(length).toLong() % maxValue)\n } else if (length == sublength) {\n println(letters.toDouble().pow(length).toLong() % maxValue)\n } else if (sublength % 2 == 0) {\n println((letters) % maxValue)\n } else {\n println((letters*letters) % maxValue)\n }\n}\n"}], "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d"} {"nl": {"description": "There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is \"R\", \"G\", or \"B\", the color of the corresponding stone is red, green, or blue, respectively.Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.Each instruction is one of the three types: \"RED\", \"GREEN\", or \"BLUE\". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.", "input_spec": "The input contains two lines. The first line contains the string s (1 ≤ |s| ≤ 50). The second line contains the string t (1 ≤ |t| ≤ 50). The characters of each string will be one of \"R\", \"G\", or \"B\". It is guaranteed that Liss don't move out of the sequence.", "output_spec": "Print the final 1-based position of Liss in a single line.", "sample_inputs": ["RGB\nRRR", "RRRBGBRBBB\nBBBRR", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB"], "sample_outputs": ["2", "3", "15"], "notes": null}, "positive_code": [{"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //val (n, k) = r.readLine()!!.split(\" \").map { it.toInt() }\n val s1 = r.readLine()!!\n val s2 = r.readLine()!!\n var i = 0\n s2.forEach {\n if (it==s1[i]) i++\n }\n println(i+1)\n}"}, {"source_code": "// Bismillahir Rahmanir Raheem\n\nimport java.util.Scanner\nfun main() {\n val sc = Scanner (System.`in`)\n\n var str: String = readLine()!!\n var stt: String = readLine()!!\n\n var j: Int = 0\n var s: Int = stt.length\n\n for (i in 0 .. s-1)\n if (str[j] == stt[i]) j++\n\n println (j+1)\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val sc = Scanner(System.`in`)\n var str = sc.nextLine()\n var cmd = sc.nextLine()\n var cnt = 1\n var i = 0\n for (ch in cmd) {\n if(ch == str[i]) {\n cnt++\n i++\n }\n }\n print(cnt)\n}"}, {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.pow\nimport kotlin.math.sqrt\n\n//private val INPUT = File(\"input.txt\").inputStream()\n//private val OUTPUT = File(\"output.txt\").outputStream()\nprivate val INPUT = System.`in`\nprivate val OUTPUT = System.out\n\nprivate val bufferedReader = INPUT.bufferedReader()\nprivate val outputWriter = PrintWriter(OUTPUT, false)\nprivate fun readLn() = bufferedReader.readLine()!!\n\nprivate fun readList() = readLn().split(' ')\nprivate var tokenizer = StringTokenizer(\"\")\nprivate fun read(): String {\n while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(readLn(), \" \")\n return tokenizer.nextToken()\n}\n\nprivate fun readInt() = read().toInt()\nprivate fun readLong() = read().toLong()\nprivate fun readDouble() = read().toDouble()\n\nprivate fun readIntList() = readList().map { it.toInt() }\nprivate fun readLongList() = readList().map { it.toLong() }\nprivate fun readDoubleList() = readList().map { it.toDouble() }\n\nprivate fun readIntArray(n: Int = 0) =\n if (n == 0) readList().run { IntArray(size) { get(it).toInt() } } else IntArray(n) { readInt() }\n\nprivate fun readLongArray(n: Int = 0) =\n if (n == 0) readList().run { LongArray(size) { get(it).toLong() } } else LongArray(n) { readLong() }\n\nprivate fun readDoubleArray(n: Int = 0) =\n if (n == 0) readList().run { DoubleArray(size) { get(it).toDouble() } } else DoubleArray(n) { readDouble() }\n\n\nprivate fun Int.modPositive(other: Int): Int = if (this % other < 0) ((this % other) + other) else (this % other)\n\n\nprivate class `CF265-D2-A` {\n fun solveTestCase(): Int {\n val s = read()\n val t = read()\n var pos = 0\n\n t.forEach {\n if (s[pos] == it) {\n pos++\n }\n }\n\n\n return pos + 1\n }\n}\n\nfun main(args: Array) {\n\n outputWriter.println(\n `CF265-D2-A`()\n .solveTestCase()\n )\n\n outputWriter.flush()\n}"}, {"source_code": "fun main() = Pair(readLine()!!, readLine()!!)\n .let { (stones, instructions) ->\n var currentPosition = 0\n for (instructionIndex in 0..instructions.lastIndex) {\n if (instructions[instructionIndex] == stones[currentPosition]) {\n currentPosition++\n }\n }\n currentPosition\n }\n .let(Int::inc)\n .run(::println)"}, {"source_code": "import java.util.Scanner;\nimport java.util.Arrays;\nimport java.util.*; \nimport java.math.*;\nimport java.io.*;\n\nfun main(args: Array) {\n val s = Scanner(System.`in`)\n val postion = s.next();\n val instrution = s.next();\n colorstone(postion,instrution)\n}\nfun colorstone (postion : String ,instrution : String ){\n\nval postions = postion.toCharArray();\nval instrutions = instrution.toCharArray();\nvar counter = 1\n\n for(i in instrutions.indices){\nif(postion[counter-1] == instrutions[i]){\n counter++\n}\n} \nprint(counter) \n}\n\n"}, {"source_code": "import java.util.*\nval reader = Scanner(System.`in`)\nvar ans = 1\nfun main(args: Array){\n val s = reader.next()\n val t = reader.next()\n\n for (i in t) {\n\n if(i == s[ans-1])\n ans++\n }\n\n print(ans)\n}\n"}, {"source_code": "fun solution (a:String, b:String) : Int {\n var pos = 0;\n for (i in b) {\n if (i == a[pos]) {\n pos++\n }\n }\n return pos+1\n}\n\nfun main(args: Array) {\n // myassert(2, solution(\"RGB\", \"RRR\"))\n // myassert(3, solution(\"RRRBGBRBBB\", \"BBBRR\"))\n // myassert(15, solution(\"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\",\n // \"BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\"))\n\n solution(readLine()!!, readLine()!!).let{print(it)}\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val s = br.readLine()\n val t = br.readLine()\n var pos = 0\n for (c in t) {\n if (c == s[pos]){\n pos++\n }\n }\n println(pos + 1)\n}"}, {"source_code": "import java.util.*\n\nfun main() {\n val reader = Scanner(System.`in`)\n val t = reader.nextLine()\n val c = reader.nextLine()\n var ci=0\n c.forEach {\n if (it==t[ci]){\n ci++\n }\n }\n println(ci+1)\n}\n\n"}, {"source_code": "fun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun findLissPos(): Int {\n\n val stones = readLn()\n val instructions = readLn()\n var curPos = 0\n for (i in 0 until instructions.length) {\n if (stones[curPos ] == instructions[i])\n curPos++\n }\n\n curPos++\n\n return curPos;\n}\n\n\nfun main() {\n print(findLissPos())\n}\n"}, {"source_code": "fun main() {\n var r : String = readLine()!!\n var q: String = readLine()!!\n var i : Int = 0;\n for(idx in 0..q.lastIndex) {\n if(q[idx] == r[i]) {\n i++;\n }\n }\n println(i + 1);\n}\n"}, {"source_code": "import java.lang.AssertionError\nimport java.util.*\n \nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n \nprivate fun myAssert(x: Boolean) {\n if (!x) {\n throw AssertionError()\n }\n}\n\nfun main(args: Array) {\n// var s = Scanner(System.`in`)\n var s = readLn()\n var t = readLn()\n var ans = 0\n var l = 0\n var r = 0\n while (r < t.length) {\n if (s[l] == t[r]) {\n l++\n r++\n } else {\n r++\n }\n }\n println(l + 1)\n}\n"}, {"source_code": "fun main() {\n val s = readLine()!!\n val t = readLine()!!\n var sPos = 0\n for(c in t)\n if(c == s[sPos]) sPos++\n print(sPos + 1)\n}"}], "negative_code": [], "src_uid": "f5a907d6d35390b1fb11c8ce247d0252"} {"nl": {"description": "ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice.Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?", "input_spec": "The first and only line of the input contains a single string s (1 ≤ |s| ≤ 50 000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.", "output_spec": "If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print  - 1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them.", "sample_inputs": ["ABC??FGHIJK???OPQR?TUVWXY?", "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO", "??????????????????????????", "AABCDEFGHIJKLMNOPQRSTUVW??M"], "sample_outputs": ["ABCDEFGHIJKLMNOPQRZTUVWXYS", "-1", "MNBVCXZLKJHGFDSAQPWOEIRUYT", "-1"], "notes": "NoteIn the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS.In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is  - 1.In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer."}, "positive_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(vararg params: String) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n\n val string = br.readLine().toList()\n\n if (string.size < 26) {\n println(-1)\n return\n }\n\n val countOfLetters = IntArray(26)\n fun Char.put() {\n if (this != '?')\n countOfLetters[toInt() - 65]++\n }\n\n fun Char.remove() {\n if (this != '?')\n countOfLetters[toInt() - 65]--\n }\n\n fun isOnlyOneOrZero() = countOfLetters.all { it < 2 }\n\n var begin = 0\n fun end() = begin + 25\n\n for (i in begin..end() - 1) {\n string[i].put()\n }\n\n while (end() < string.size) {\n string[end()].put()\n if (isOnlyOneOrZero()) {\n val sublist = processMissing(string.subList(begin, end() + 1))\n\n val fullString = string.subList(0, begin) + sublist + string.subList(end() + 1, string.size)\n\n println(fullString.map { if (it == '?') 'X' else it }.joinToString(separator = \"\") { \"$it\" })\n\n return\n }\n string[begin].remove()\n begin++\n }\n\n println(-1)\n\n}\n\nfun processMissing(list: List): List {\n val alphabet = ArrayList(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\".toList().filter { !list.contains(it) })\n return list.map { if (it == '?') alphabet.removeAt(0) else it }\n}\n"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readLong() = readLine()!!.toLong()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n val notPresent = mutableSetOf()\n for (c in 'A'..'Z')\n notPresent.add(c)\n val counts = IntArray(26)\n val s = readLine()!!.toCharArray()\n if (s.size< 26) {\n print(-1)\n return\n }\n var wildCards = 0\n for (i in 0..25) {\n if (s[i] == '?')\n wildCards++\n else {\n counts[s[i] - 'A']++\n notPresent.remove(s[i])\n }\n }\n var start = 0\n var end = 25\n while(end < s.size) {\n if(notPresent.size == wildCards) {\n while(start <= end) {\n if(s[start] == '?') {\n s[start] = notPresent.first()\n notPresent.remove(s[start])\n }\n start++\n }\n for(i in 0 until s.size) {\n if(s[i] == '?')\n s[i] = 'A'\n }\n print(s.joinToString(\"\"))\n return\n } else {\n if (s[start] == '?') wildCards-- else {\n counts[s[start] - 'A']--\n if(counts[s[start] - 'A'] == 0) notPresent.add(s[start])\n }\n start++\n end++\n if(end < s.size) {\n if (s[end] == '?') wildCards++ else {\n counts[s[end] - 'A']++\n notPresent.remove(s[end])\n }\n }\n }\n }\n print(-1)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.File\nimport java.io.PrintWriter\n\nfun main(args: Array) {\n val onlineJudge = System.getProperty(\"ONLINE_JUDGE\") == \"true\"\n val input = if (onlineJudge) System.`in`.bufferedReader() else File(\"input.txt\").bufferedReader()\n val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File(\"output.txt\"))\n\n solve(input, output)\n\n output.flush()\n output.close()\n}\n\nfun String.words() = split(\" \")\n\nfun String.toInts() = split(\" \").map { it.toInt() }\nfun String.toLongs() = split(\" \").map { it.toLong() }\n\nprivate fun solve(input: BufferedReader, output: PrintWriter) {\n val s = input.readLine()\n\n fun Char.toIndex() = this - 'A'\n\n val letterCount = IntArray(26)\n var wildcardsCount = 0\n var missingLetters = 26\n\n for (i in s.indices) {\n val c = s[i]\n when (c) {\n '?' -> ++wildcardsCount\n in 'A'..'Z' -> {\n if (letterCount[c.toIndex()] == 0)\n --missingLetters\n ++letterCount[c.toIndex()]\n }\n }\n\n if (i >= 26) {\n val q = s[i - 26]\n when (q) {\n '?' -> --wildcardsCount\n in 'A'..'Z' -> {\n if (letterCount[q.toIndex()] == 1)\n ++missingLetters\n --letterCount[q.toIndex()]\n }\n }\n }\n\n if (i >= 25 && missingLetters <= wildcardsCount) {\n val missingLettersList = letterCount.indices.filter { letterCount[it] == 0 }.map { 'A' + it }\n var currentMissingLetterIndex = 0\n val answer = s.toCharArray()\n for (j in answer.indices) {\n if (answer[j] == '?') {\n if (j in (i - 25..i)) {\n answer[j] = missingLettersList.getOrElse(currentMissingLetterIndex) { 'A' }\n ++currentMissingLetterIndex\n } else\n answer[j] = 'A'\n }\n }\n output.println(String(answer))\n return\n }\n }\n\n output.println(\"-1\")\n}"}], "negative_code": [{"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(vararg params: String) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n\n val string = br.readLine().toList()\n\n if (string.size < 26) {\n println(-1)\n return\n }\n\n val countOfLetters = IntArray(26)\n fun Char.put() {\n if (this != '?')\n countOfLetters[toInt() - 65]++\n }\n\n fun Char.remove() {\n if (this != '?')\n countOfLetters[toInt() - 65]--\n }\n\n fun isOnlyOneOrZero() = countOfLetters.all { it < 2 }\n\n var begin = 0\n fun end() = begin + 25\n\n for (i in begin..end() - 1) {\n string[i].put()\n }\n\n while (end() < string.size) {\n string[end()].put()\n if (isOnlyOneOrZero()) {\n processMissing(string.subList(begin, end() + 1))\n\n\n return\n }\n string[begin].remove()\n begin++\n }\n\n println(-1)\n\n}\n\nfun processMissing(list: List) {\n val alphabet = ArrayList(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\".toList().filter { !list.contains(it) })\n println(list.map { if (it == '?') alphabet.removeAt(0) else it }.joinToString(separator = \"\") { \"$it\" })\n}\n"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readLong() = readLine()!!.toLong()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n val notPresent = mutableSetOf()\n for (c in 'A'..'Z')\n notPresent.add(c)\n val counts = IntArray(26)\n val s = readLine()!!\n if (s.length < 26) {\n print(-1)\n return\n }\n var wildCards = 0\n for (i in 0..25) {\n if (s[i] == '?')\n wildCards++\n else {\n counts[s[i] - 'A']++\n notPresent.remove(s[i])\n }\n }\n var start = 0\n var end = 25\n while(end < s.length) {\n if(notPresent.size == wildCards) {\n val sb = StringBuilder()\n while(start <= end) {\n if(s[start] == '?') {\n sb.append(notPresent.first())\n notPresent.remove(sb.last())\n } else sb.append(s[start])\n start++\n }\n print(sb.toString())\n return\n } else {\n if (s[start] == '?') wildCards-- else {\n counts[s[start] - 'A']--\n if(counts[s[start] - 'A'] == 0) notPresent.add(s[start])\n }\n start++\n end++\n if(end < s.length) {\n if (s[end] == '?') wildCards++ else {\n counts[s[end] - 'A']++\n notPresent.remove(s[end])\n }\n }\n }\n }\n print(-1)\n}"}, {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readLong() = readLine()!!.toLong()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n val notPresent = mutableSetOf()\n for (c in 'A'..'Z')\n notPresent.add(c)\n val counts = IntArray(26)\n val s = readLine()!!.toCharArray()\n if (s.size< 26) {\n print(-1)\n return\n }\n var wildCards = 0\n for (i in 0..25) {\n if (s[i] == '?')\n wildCards++\n else {\n counts[s[i] - 'A']++\n notPresent.remove(s[i])\n }\n }\n var start = 0\n var end = 25\n while(end < s.size) {\n if(notPresent.size == wildCards) {\n while(start <= end) {\n if(s[start] == '?') {\n s[start] = notPresent.first()\n notPresent.remove(s[start])\n }\n start++\n }\n print(s.joinToString(\"\"))\n return\n } else {\n if (s[start] == '?') wildCards-- else {\n counts[s[start] - 'A']--\n if(counts[s[start] - 'A'] == 0) notPresent.add(s[start])\n }\n start++\n end++\n if(end < s.size) {\n if (s[end] == '?') wildCards++ else {\n counts[s[end] - 'A']++\n notPresent.remove(s[end])\n }\n }\n }\n }\n print(-1)\n}"}, {"source_code": "import java.io.BufferedReader\nimport java.io.File\nimport java.io.PrintWriter\n\nfun main(args: Array) {\n val onlineJudge = System.getProperty(\"ONLINE_JUDGE\") == \"true\"\n val input = if (onlineJudge) System.`in`.bufferedReader() else File(\"input.txt\").bufferedReader()\n val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File(\"output.txt\"))\n\n solve(input, output)\n\n output.flush()\n output.close()\n}\n\nfun String.words() = split(\" \")\n\nfun String.toInts() = split(\" \").map { it.toInt() }\nfun String.toLongs() = split(\" \").map { it.toLong() }\n\nprivate fun solve(input: BufferedReader, output: PrintWriter) {\n val s = input.readLine()\n\n fun Char.toIndex() = this - 'A'\n\n val letterCount = IntArray(26)\n var wildcardsCount = 0\n var missingLetters = 26\n\n for (i in s.indices) {\n val c = s[i]\n when (c) {\n '?' -> ++wildcardsCount\n in 'A'..'Z' -> {\n if (letterCount[c.toIndex()] == 0)\n --missingLetters\n ++letterCount[c.toIndex()]\n }\n }\n\n if (i >= 26) {\n val q = s[i - 26]\n when (q) {\n '?' -> --wildcardsCount\n in 'A'..'Z' -> {\n if (letterCount[q.toIndex()] == 1)\n ++missingLetters\n --letterCount[q.toIndex()]\n }\n }\n }\n\n if (i >= 25 && missingLetters <= wildcardsCount) {\n val missingLettersList = letterCount.indices.filter { letterCount[it] == 0 }\n var currentMissingLetterIndex = 0\n val answer = s.toCharArray()\n for (j in answer.indices) {\n if (answer[j] == '?') {\n answer[j] = 'A' + missingLettersList.getOrElse(currentMissingLetterIndex) { 0 }\n ++currentMissingLetterIndex\n }\n }\n output.println(String(answer))\n return\n }\n }\n\n output.println(\"-1\")\n}"}], "src_uid": "a249431a4b0b1ade652997fe0b82edf3"} {"nl": {"description": "A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle.  It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied.Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch.", "input_spec": "The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≤ n ≤ 1018) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space.", "output_spec": "Print one integer — the number of seconds Vasya has to wait until he gets his lunch.", "sample_inputs": ["1f", "2d", "4a", "5e"], "sample_outputs": ["1", "10", "11", "18"], "notes": "NoteIn the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10."}, "positive_code": [{"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args : Array) {\n //====== Input preparations ========================================================\n// val fin = BufferedReader(FileReader(\"b.in\"))\n val fin = BufferedReader(InputStreamReader(System.`in`))\n val fout = PrintWriter (System.out)\n var tokenizer = StringTokenizer(\"\")\n fun next() : String {\n while (!tokenizer.hasMoreTokens())\n tokenizer = StringTokenizer(fin.readLine())\n return tokenizer.nextToken()\n }\n fun nextInt() = next().toInt()\n fun nextPair() = nextInt() to nextInt()\n fun nextPairDec() = nextInt()-1 to nextInt()-1\n //====== Solution below ============================================================\n val s = next()\n val n = s.substring(0..s.length-2).toLong() - 1\n val q = (n % 4).toInt()\n val p = n / 4\n val num = arrayOf(4,5,6, 3,2,1)\n val numNum = arrayOf(0,1,0,1)\n val add = num[s.last() - 'a']\n fout.print(p * 16 + numNum[q] * 7 + add)\n fout.close()\n fin.close()\n}\n\n"}, {"source_code": "fun main(args: Array)\n{\n var pos: String = \"fedabc\"\n val size: Int = 5\n var s: Long = 0\n\n var read = readLine()!!\n var c = read.last()\n var n = read.dropLast(1).toLong()\n\n for(i in 0..size)\n if (c == pos[i]) s = i.toLong() + 1\n\n if (n % 2L == 0L)\n print(((n - 1) / 4) * 16 + s + 7)\n else\n print(((n - 1) / 4) * 16 + s)\n}\n\nfun String.toInts() = split(' ').map { it.toInt() }\nfun String.toLongs() = split(' ').map { it.toLong() }"}, {"source_code": "import java.io.BufferedReader\nimport java.io.File\nimport java.io.PrintWriter\n\nfun main(args: Array) {\n val onlineJudge = System.getProperty(\"ONLINE_JUDGE\") == \"true\"\n val input = if (onlineJudge) System.`in`.bufferedReader() else File(\"input.txt\").bufferedReader()\n val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File(\"output.txt\"))\n\n solve(input, output)\n\n output.flush()\n output.close()\n}\n\nprivate fun String.words() = split(\" \")\n\nprivate fun String.toInts() = split(\" \").map { it.toInt() }\nprivate fun String.toLongs() = split(\" \").map { it.toLong() }\n\nprivate fun solve(input: BufferedReader, output: PrintWriter) {\n val p = input.readLine()\n val c = p.last()\n val n = p.dropLast(1).toLong()\n\n var time = 0L\n val byFourRowsBefore = (n - 1) / 4\n time += byFourRowsBefore * 16\n val even = n % 2\n if (even == 0L)\n time += 7\n time += when (c) {\n 'f' -> 1\n 'e' -> 2\n 'd' -> 3\n 'a' -> 4\n 'b' -> 5\n 'c' -> 6\n else -> throw IllegalArgumentException()\n }\n output.println(time)\n}"}], "negative_code": [], "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45"} {"nl": {"description": "On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell.Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.", "input_spec": "The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.", "output_spec": "If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print \"YES\" (without quotes) in the only line of the input. Otherwise, print \"NO\" (without quotes).", "sample_inputs": ["5 2\n#G#T#", "6 1\nT....G", "7 3\nT..#..G", "6 2\n..GT.."], "sample_outputs": ["YES", "YES", "NO", "NO"], "notes": "NoteIn the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.In the third sample, the grasshopper can't make a single jump.In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect."}, "positive_code": [{"source_code": "fun main() {\n var (n, k) = readLine()!!.split(' ').map { it.toInt() }\n\n var str = readLine()!!\n var g = str.indexOf('G')\n var t = str.indexOf('T')\n\n var min = minOf(g, t) + k\n var max = maxOf(g, t)\n\n if (min > max) {\n println(\"NO\")\n return\n }\n\n while (min <= max) {\n if (str[min] == '#') {\n println(\"NO\")\n return\n }\n if (str[min] == 'T' || str[min] == 'G'){\n println(\"YES\")\n return\n }\n min += k\n\n }\n println(\"NO\")\n}"}, {"source_code": "fun main() {\n val (n, k) = readLine()!!.split(\" \").map(String::toInt)\n val s = readLine()!!\n var f = false\n var pos = 0\n for (i in 0 until s.length) {\n if (s[i] in setOf('T','G')) {\n if (f) {\n pos = (pos + 1) % k\n if (pos == 0) println(\"YES\")\n else println(\"NO\")\n return\n } else f = true\n } else if (f) {\n pos = (pos + 1) % k\n if ((pos == 0) && (s[i] != '.')) {\n println(\"NO\")\n return\n }\n }\n }\n println(\"YES\")\n}"}, {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (_, jumpLength) = readInts()\n val s = readLine()!!\n var grasshopper = s.indexOfFirst { it == 'G' }\n var target = s.indexOfFirst { it == 'T' }\n if (target < grasshopper) {\n val temp = grasshopper\n grasshopper = target\n target = temp\n }\n while (grasshopper < target) {\n if (s[grasshopper] == '#')\n return print(\"NO\")\n grasshopper += jumpLength\n }\n print(if (grasshopper == target) \"YES\" else \"NO\")\n}"}, {"source_code": "import java.util.*\nimport java.math.*\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\nfun main(args: Array){\n\topen class A(a: Int, b: Int) {\n\t\tpublic open var i: Int = a;\n\t\tpublic open var r: Int = b;\n\t}\n\tvar inp = readInts();\n\tvar n = inp[0];\n\tvar k = inp[1];\n\tvar s = readLn();\n\tvar j = 0;\n\tvar t = 0;\n\tfor(i in s.indices){\n\t\tif(s[i] == 'G'){\n\t\t\tj = i;\n\t\t}\n\t\tif(s[i] == 'T'){\n\t\t\tt = i;\n\t\t}\n\t}\n\tvar flag = false;\n\tfor(i in j..(s.length - 1) step k){\n\t\tif(s[i] == 'T'){\n\t\t\tflag = true;\n\t\t\tbreak;\n\t\t}\n\t\tif(s[i] == '#') break;\n\t}\n\tfor(i in t..(s.length - 1) step k){\n\t\tif(s[i] == 'G'){\n\t\t\tflag = true;\n\t\t\tbreak;\n\t\t}\n\t\tif(s[i] == '#') break;\n\t}\n\tif(flag){\n\t\tprintln(\"YES\");\n\t}else{\n\t\tprintln(\"NO\");\n\t}\n}\n"}, {"source_code": "import java.io.*\nimport java.util.*\n\nfun DataReader.solve(out: PrintWriter) {\n val n = nextInt()\n val k = nextInt()\n\n val s = nextToken()\n\n val used = BooleanArray(n)\n\n fun dfs(u: Int): Boolean {\n if (u < 0 || u >= n || used[u] || s[u] == '#') return false\n if (s[u] == 'T') return true\n used[u] = true\n\n return dfs(u - k) || dfs(u + k)\n }\n\n out.println(dfs(s.indexOf('G')).toYesNo())\n}\n\nfun Boolean.toYesNo() = if (this) \"YES\" else \"NO\"\n\nclass DataReader(private val reader: BufferedReader) {\n var st : StringTokenizer? = null\n companion object {\n fun createFromFile(name: String) = DataReader(BufferedReader(FileReader(name)))\n }\n\n fun next() : String? {\n while (st == null || !st!!.hasMoreTokens()) {\n val s = reader.readLine() ?: return null\n st = StringTokenizer(s)\n }\n\n return st?.nextToken()\n }\n\n fun nextToken() = next()!!\n\n fun nextInt() = nextToken().toInt()\n fun nextLong() = nextToken().toLong()\n fun readIntArray(n: Int) : IntArray {\n val result = IntArray(n)\n result.indices.forEach { i -> result[i] = nextInt() }\n return result\n }\n\n fun nextLine() = reader.readLine()\n}\n\nfun main(args: Array) {\n val r: Reader\n val out: PrintWriter\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n r = FileReader(\"input.txt\")\n out = PrintWriter(\"output.txt\")\n } else {\n r = InputStreamReader(System.`in`)\n out = PrintWriter(System.out)\n }\n\n DataReader(BufferedReader(r)).solve(out)\n out.flush()\n}\n"}, {"source_code": "import java.io.BufferedReader\nimport java.io.File\nimport java.io.PrintWriter\n\nfun main(args: Array) {\n val onlineJudge = System.getProperty(\"ONLINE_JUDGE\") == \"true\"\n val input = if (onlineJudge) System.`in`.bufferedReader() else File(\"input.txt\").bufferedReader()\n val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File(\"output.txt\"))\n\n solve(input, output)\n\n output.flush()\n output.close()\n}\n\nprivate fun String.words() = split(\" \")\n\nprivate fun String.toInts() = split(\" \").map { it.toInt() }\nprivate fun String.toLongs() = split(\" \").map { it.toLong() }\n\nprivate fun solve(input: BufferedReader, output: PrintWriter) {\n val (n, k) = input.readLine().toInts()\n val line = input.readLine()\n val indexOfG = line.indexOf(\"G\")\n val indexOfT = line.indexOf(\"T\")\n val rem = indexOfG % k\n val path = line\n .replaceRange(0..Math.min(indexOfG, indexOfT) - 1, String(CharArray(Math.min(indexOfG, indexOfT)) { '.' }))\n .replaceRange(Math.max(indexOfG, indexOfT) + 1, line.lastIndex + 1, String(CharArray(Math.min(indexOfG, indexOfT)) { '.' }))\n .filterIndexed { index, c -> index % k == rem }\n if (path.contains(\"G\") && path.contains(\"T\") && !path.contains(\"#\")) {\n output.println(\"YES\")\n } else {\n output.println(\"NO\")\n }\n}"}], "negative_code": [], "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41"} {"nl": {"description": "Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he gets 11311 (475 = 1·162 + 13·161 + 11·160). Alexander lived calmly until he tried to convert the number back to the decimal number system.Alexander remembers that he worked with little numbers so he asks to find the minimum decimal number so that by converting it to the system with the base n he will get the number k.", "input_spec": "The first line contains the integer n (2 ≤ n ≤ 109). The second line contains the integer k (0 ≤ k < 1060), it is guaranteed that the number k contains no more than 60 symbols. All digits in the second line are strictly less than n. Alexander guarantees that the answer exists and does not exceed 1018. The number k doesn't contain leading zeros.", "output_spec": "Print the number x (0 ≤ x ≤ 1018) — the answer to the problem.", "sample_inputs": ["13\n12", "16\n11311", "20\n999", "17\n2016"], "sample_outputs": ["12", "475", "3789", "594"], "notes": "NoteIn the first example 12 could be obtained by converting two numbers to the system with base 13: 12 = 12·130 or 15 = 1·131 + 2·130."}, "positive_code": [{"source_code": "import java.io.PrintWriter\n\n\nfun main() {\n io.apply {\n\n val base = int\n val num = str().reversed()\n\n var ptr = 0\n\n fun get(): Long {\n var pow = 1L\n var ans = 0L\n var ix = ptr\n ptr++\n while (ix < num.length) {\n val x = num[ix] - '0'\n if (pow < base && ans + x * pow < base) {\n ans += x * pow\n pow *= 10\n if (x != 0)\n ptr = ix + 1\n } else {\n return ans\n }\n ix++\n }\n return ans\n }\n\n var ans = 0L\n var b = 1L\n while (ptr < num.length) {\n val g = get()\n// cout .. g .. nl\n ans += b * g\n b *= base\n }\n\n cout .. ans .. nl\n\n\n }.cout.flush()\n}\n\n// @formatter:off\nprivate val io = object {\n private val `in` = System.`in`\n private fun ll(): Long {\n var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }\n do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n\n }\n val int get() = ll().toInt(); val long get() = ll()\n fun ints(n: Int = int): IntArray { return IntArray(n) { int } }\n fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }\n val cout = PrintWriter(System.out); val nl = \"\\n\"\n private var buf = CharArray(32)\n private var bufSize = 32\n fun str(expect: Int = 32): String {\n var ix = 0\n var x: Int\n if (bufSize < expect)\n buf = CharArray(expect)\n do x = `in`.read() while (x < 33)\n do {\n if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }\n buf[ix++] = x.toChar()\n x = `in`.read()\n } while (x > 32)\n return java.lang.String.copyValueOf(buf, 0, ix)\n }\n operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(\" \") }; return this }\n operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }\n} // @formatter:on\n\n/* ----------- */\n\n"}], "negative_code": [{"source_code": "import java.io.PrintWriter\n\n\nfun main() {\n io.apply {\n\n val base = int\n val num = str()\n\n var pow = 1L\n var cur = 0L\n\n var ans = 0L\n var b = 1L\n\n for (c in num.reversed()) {\n var x = c - '0'\n if (cur + x * pow >= base || pow >= base) {\n ans += cur * b\n b *= base\n cur = x.toLong()\n pow = 10\n } else {\n cur += x * pow\n pow *= 10\n }\n }\n ans += cur * b\n cout .. ans .. nl\n\n\n\n }.cout.flush()\n}\n\n// @formatter:off\nprivate val io = object {\n private val `in` = System.`in`\n private fun ll(): Long {\n var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }\n do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n\n }\n val int get() = ll().toInt(); val long get() = ll()\n fun ints(n: Int = int): IntArray { return IntArray(n) { int } }\n fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }\n val cout = PrintWriter(System.out); val nl = \"\\n\"\n private var buf = CharArray(32)\n private var bufSize = 32\n fun str(expect: Int = 32): String {\n var ix = 0\n var x: Int\n if (bufSize < expect)\n buf = CharArray(expect)\n do x = `in`.read() while (x < 33)\n do {\n if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }\n buf[ix++] = x.toChar()\n x = `in`.read()\n } while (x > 32)\n return java.lang.String.copyValueOf(buf, 0, ix)\n }\n operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(\" \") }; return this }\n operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }\n} // @formatter:on\n\n/* ----------- */\n\n"}], "src_uid": "be66399c558c96566a6bb0a63d2503e5"}