{"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "6be4ff1ffab1db91e07adb0a9f7c04b9", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5205971e0cf431b6d591055887ef9ea5", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "1c0fccb0178424dcd842bd1779bd3924", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2781f894caad10c7cb7c3bee9c531db6", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.5", "source_code": "fun main() = println((readLine()!!.toInt() % 9).let { if (it == 0) 9 else it })\n", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "39c7905cdab6c8cd4672f8738863466b", "src_uid": "477a67877367dc68b3bf5143120ff45d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "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 readInts() = inf.readLine()!!.split(' ').map(String::toInt)\nfun readLongs() = inf.readLine()!!.split(' ').map(String::toLong)\nfun readString() = inf.readLine()!!\n\nfun main() {\n val a = readInts()[0]\n var ans = a % 9\n if (ans == 0) ans = 9\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "75be8c9d3e43f8dcfe14b4bef97e0eed", "src_uid": "477a67877367dc68b3bf5143120ff45d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.io.FileInputStream\r\n\r\nfun main() {\r\n //changeStandardInput()\r\n var q = 1\r\n val ans: MutableList = ArrayList(q)\r\n while (q-- > 0) {\r\n var x = readIntLn()\r\n var cnt = 0\r\n\r\n\r\n while (x > 9) {\r\n while (x > 0) {\r\n cnt += x % 10\r\n x /= 10\r\n }\r\n\r\n x = cnt\r\n cnt = 0\r\n }\r\n\r\n\r\n ans += x.toString()\r\n }\r\n\r\n println(ans.joinToString(\"\\n\"))\r\n}\r\n\r\n\r\nprivate fun readLn() = readLine()!!\r\nprivate fun readIntLn() = readLn().toInt()\r\nprivate fun readLongLn() = readLn().toLong()\r\nprivate fun readDoubleLn() = readLn().toDouble()\r\nprivate fun readStrings() = readLn().split(\" \")\r\nprivate fun readInts() = readStrings().map { it.toInt() }\r\nprivate fun readLongs() = readStrings().map { it.toLong() }\r\n\r\n\r\nprivate fun changeStandardInput() {\r\n System.setIn(FileInputStream(\"input.txt\"))\r\n}", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "2327c249f9a100b680e482b393801368", "src_uid": "477a67877367dc68b3bf5143120ff45d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main(args: Array) {\n var N = readLine()!!.toInt()\n while (N >= 10) {\n var ans = 0\n while (N > 0) {\n ans += N%10\n N /= 10\n }\n N = ans\n }\n println(N)\n}", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "2412ce18b4d2f092e39d22fa88258b1c", "src_uid": "477a67877367dc68b3bf5143120ff45d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import 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 getFaceCount(s: String): Int {\n return when (s) {\n \"Tetrahedron\" -> 4\n \"Cube\" -> 6\n \"Octahedron\" -> 8\n \"Dodecahedron\" -> 12\n \"Icosahedron\" -> 20\n else -> 0\n }\n}\n\nfun main(args: Array) {\n val s = readLn()\n println(min(s.length, s.count { it == 'a' } * 2 - 1))\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "f787b4bc6721a6bd57248b9e5b0f89a2", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main() {\n val output = readLine()!!\n val length = output.length\n val aCount = output.count { it == 'a' }\n if (aCount > length / 2) {\n println(length)\n } else {\n println(aCount * 2 - 1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "6b325165ee3b202f3663554112e27743", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * Problem Link: https://codeforces.com/problemset/problem/1146/A\n * Difficulty: 600\n */\n\nfun main(args: Array) {\n val s = readLine()!!\n val a = s.count { it == 'a' }\n var tot = s.length\n var count = 0\n while (a <= tot/2) {\n tot--\n count++\n }\n println(tot)\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "d4d6164bd2e715b31fe34fef4f87b155", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLine()\n\n var aCount = 0\n s!!.forEach { if(it == 'a') aCount++ }\n\n if(aCount > s.length/2) {\n print(s.length)\n } else {\n print(aCount*2-1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "2bcaa6bcb6909eb2490f724cb375b999", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val l = nextInt()\n val p = nextInt()\n val m = nextInt()\n val r = nextInt()\n println(if (l == r && (m == 0 || l != 0)) 1 else 0)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "bf42881c33666da1b31df9d32b06d591", "src_uid": "b99578086043537297d374dc01eeb6f8", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 c1 = reader.nextInt()\n val c2 = reader.nextInt()\n val c3 = reader.nextInt()\n val c4 = reader.nextInt()\n\n writer.println(if (c1 != c4 || c1 == 0 && c3 >= 1) \"0\" else \"1\")\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}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "2e20d41a2f3e3143b893f44d5605801e", "src_uid": "b99578086043537297d374dc01eeb6f8", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val ll = readInt()\n val lr = readInt()\n val rl = readInt()\n val rr = readInt()\n\n val ans = ll == rr && (rl == 0 || ll != 0)\n\n println(if(ans) 1 else 0)\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() }", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "72fb49dfe9cd67deca45cbe24dc43459", "src_uid": "b99578086043537297d374dc01eeb6f8", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val open = readInt()\n readLine()\n val closeOpen = readInt()\n val close = readInt()\n if (open == 0 && closeOpen > 0) return print(0)\n print(if (open == close) 1 else 0)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "5727bc3ca42d9337a6898f889e9a971b", "src_uid": "b99578086043537297d374dc01eeb6f8", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\n\nfun main(args: Array) {\n val (l, r) = readLine()!!.split(\" \").map(String::toInt)\n\n var ans = 0\n\n for (i in 0..40) {\n (0..40)\n .map { (2.0.pow(i)*3.0.pow(it)).toInt() }\n .filter { (it >= l) and (it <= r) }\n .forEach { ans++ }\n }\n\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "d34b03fec304d744cf569164b916d9c5", "src_uid": "05fac54ed2064b46338bb18f897a4411", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport java.math.*\n \nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n var l : Long= sc.nextLong();\n var r : Long = sc.nextLong();\n var i : Long = 0;\n var j : Long = 0;\n var res : Long = 0;\n \n var two : Long = 1;\t\n\t \t\n for (i in 0..35) {\n\tvar three : Long = 1;\n \tfor (j in 0..35) {\n \t\tvar x : Long = two * three;\n \t\tif (x in l..r) res++;\n \t\tthree *= 3.toLong();\n \t}\n \ttwo *= 2.toLong();\n }\n \n println(res);\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "b7aa458f34fd881c32d08c241def656d", "src_uid": "05fac54ed2064b46338bb18f897a4411", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(arg: Array){\n val (l, r) = readLine()!!.split(\" \").map(String::toInt)\n var cnt = 0\n for (i in 0..39){\n for (j in 0..20){\n val g = Math.pow(2.0, i * 1.0) * Math.pow(3.0, j * 1.0)\n if (l <= g && r >= g){\n cnt = cnt + 1\n }\n }\n }\n println(cnt)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "427d8d30b1f9cc73be665bf1f42e03a6", "src_uid": "05fac54ed2064b46338bb18f897a4411", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nfun main(args: Array) {\n val (n, k) = readLine()!!.split(\" \").map(String::toInt)\n var c : Long = 1\n var d : Long = 0\n var a : Long = 1\n while (c <= k)\n c *= 2\n c /= 2\n while (c > 0) {\n a = 1 \n while (c * a <= k) {\n if (c * a >= n)\n d++\n a *= 3\n }\n c /= 2\n }\n println(d)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "9685135e09edfba43c67efdcd75119f3", "src_uid": "05fac54ed2064b46338bb18f897a4411", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.round\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(){\n var n = readInt()\n val set = mutableSetOf()\n while(!set.contains(n)){\n set.add(n)\n n+=1\n while(n%10==0) n/=10\n }\n println(set.size)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9a30a26c619ca8b17297172d8a16382c", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools\n */\n\nfun main() {\n val n = readLine()!!.toInt()\n\n val set = mutableSetOf()\n set.add(n)\n\n var x = n\n while (true) {\n x = functionF(x)\n if (set.add(x) == false) {\n break;\n }\n }\n\n println(set.size)\n}\n\n\nfun functionF(x:Int): Int {\n var y = x + 1\n while (y != 0 && y % 10 == 0) {\n y /= 10\n }\n return y\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "6164f5cb72918bb96ca3198c812fd471", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "tailrec fun removeZeroes(x: Int): Int=\n if(x % 10 == 0) removeZeroes(x / 10) else x\n\nfun f(x : Int): Int{\n var cur = x + 1\n while(cur % 10 == 0)\n cur /= 10\n return cur\n}\n\nfun main(){\n var n = readLine()!!.toInt()\n val reached = HashSet()\n while(reached.add(n)) n = f(n)\n println(reached.size)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c1413bd5bf91c30d27cbe1f1448ded30", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun f(x: Int): Int {\n var cur: Int = x + 1;\n while (cur % 10 == 0) {\n cur /= 10;\n }\n return cur;\n}\n\nfun main() {\n var n: Int = readLine()!!.toInt();\n val reached = TreeSet();\n while (reached.add(n)) {\n n = f(n);\n }\n println(reached.size);\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8c9dfd6ebf786adfa9097c8f4d7171b8", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.math.BigInteger\nimport java.util.*\nimport kotlin.math.abs\n\ndata class Point(val x: Long, val y: Long)\n\nfun solve(inn: InputReader, out: PrintWriter) {\n val x0 = inn.readLong()\n val y0 = inn.readLong()\n val ax = inn.readLong()\n val ay = inn.readLong()\n val bx = inn.readLong()\n val by = inn.readLong()\n val xs = inn.readLong()\n val ys = inn.readLong()\n val t = inn.readLong()\n\n val pts = mutableListOf()\n pts.add(Point(x0, y0))\n while (pts.last().x < Long.MAX_VALUE / 4 && pts.last().y < Long.MAX_VALUE / 4) {\n val (x, y) = pts.last()\n\n val cx = BigInteger.valueOf(x) * BigInteger.valueOf(ax) + BigInteger.valueOf(bx)\n if (cx >= BigInteger.valueOf(Long.MAX_VALUE / 4)) {\n break\n }\n val cy = BigInteger.valueOf(y) * BigInteger.valueOf(ay) + BigInteger.valueOf(by)\n if (cy >= BigInteger.valueOf(Long.MAX_VALUE / 4)) {\n break\n }\n\n pts.add(Point(x * ax + bx, y * ay + by))\n }\n\n var result = 0\n for (i in 0 until pts.size) {\n var x = xs\n var y = ys\n val dist = abs(x - pts[i].x) + abs(y - pts[i].y)\n if (dist > t) {\n continue\n }\n\n x = pts[i].x\n y = pts[i].y\n\n var impact = 1\n var remT = t - dist\n for (j in i - 1 downTo 0) {\n val dist = abs(x - pts[j].x) + abs(y - pts[j].y)\n if (dist > remT) {\n break\n }\n\n remT -= dist\n ++impact\n x = pts[j].x\n y = pts[j].y\n }\n\n for (j in i + 1 until pts.size) {\n val dist = abs(x - pts[j].x) + abs(y - pts[j].y)\n if (dist > remT) {\n break\n }\n\n remT -= dist\n ++impact\n x = pts[j].x\n y = pts[j].y\n }\n\n result = result.coerceAtLeast(impact)\n }\n\n out.println(result)\n}\n\nfun main() {\n val inn = InputReader(System.`in`)\n// val inn = InputReader(FileInputStream(\"1.txt\"))\n val out = PrintWriter(System.out)\n\n solve(inn, out)\n\n inn.close()\n out.close()\n}\n\nclass InputReader(inputStream: InputStream) {\n private val mReader = inputStream.bufferedReader()\n private var mTokenizer = StringTokenizer(\"\")\n\n fun close() = mReader.close()\n\n fun readString(): String {\n while (!mTokenizer.hasMoreTokens()) {\n mTokenizer = StringTokenizer(mReader.readLine())\n }\n\n return mTokenizer.nextToken()\n }\n\n fun readInt() = readString().toInt()\n fun readLong() = readString().toLong()\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "implementation", "greedy", "geometry"], "code_uid": "42eb94270af955273b56db7bd93cd82d", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun main() {\n\tval (x0, y0, ax, ay, bx, by) = readLongs()\n\tval (xs, ys, t) = readLongs()\n\tval points = mutableListOf(x0 to y0)\n\twhile (true) {\n\t\tval last = points.last()\n\t\tval (xt, yt) = ax * last.first + bx to ay * last.second + by\n\t\tif (xs + ys + t < xt + yt) break\n\t\tpoints.add(xt to yt)\n\t}\n\tvar best = 0\n\tfor (i in points.indices) {\n\t\tfor (j in i until points.size) {\n\t\t\tval dist = minOf(dist(xs to ys, points[i]), dist(xs to ys, points[j])) + dist(points[i], points[j])\n\t\t\tif (dist <= t) best = maxOf(best, j - i + 1)\n\t\t}\n\t}\n\tprintln(best)\n}\n\nfun dist(a: Pair, b: Pair): Long {\n\treturn abs(a.first - b.first) + abs(a.second - b.second)\n}\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readLongs() = readStrings().map { it.toLong() }\nprivate operator fun List.component6(): E {\n\treturn this[5]\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "implementation", "greedy", "geometry"], "code_uid": "968d07c96b68943d2b002405c56da8f0", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n val x0 = readLong()\n val y0 = readLong()\n val ax = readLong()\n val ay = readLong()\n val bx = readLong()\n val by = readLong()\n\n val xs = readLong()\n val ys = readLong()\n val start = Point(xs, ys)\n val t = readLong()\n\n val nodes = generateSequence(Point(x0, y0)) { (x, y) ->\n Point(ax * x + bx, ay * y + by)\n }.takeWhile { (x, y) -> x <= xs + t && y <= ys + t }\n .filter { start.distance(it) <= t }\n .toList()\n\n var ans = 0\n fun findCandidate(seq: IntProgression) {\n var pos = start\n var k = 0\n var rem = t\n\n for(j in seq) {\n rem -= pos.distance(nodes[j])\n if(rem < 0) break\n k++\n pos = nodes[j]\n }\n\n if(k > ans) ans = k\n }\n\n for(i in nodes.indices) {\n findCandidate(i downTo 0)\n findCandidate(i until nodes.size)\n }\n\n println(ans)\n}\n\ndata class Point(val x: Long, val y: Long) {\n fun distance(other: Point) = abs(x - other.x) + abs(y - other.y)\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()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "implementation", "greedy", "geometry"], "code_uid": "35cb6afab8fc6276ce4c00bfc8c5ef30", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n val x0 = readLong()\n val y0 = readLong()\n val ax = readLong()\n val ay = readLong()\n val bx = readLong()\n val by = readLong()\n\n val xs = readLong()\n val ys = readLong()\n val start = Point(xs, ys)\n val t = readLong()\n\n val nodes = generateSequence(Point(x0, y0)) { (x, y) ->\n Point(ax * x + bx, ay * y + by)\n }.takeWhile { (x, y) -> x <= xs + t && y <= ys + t }\n .filter { start.distance(it) <= t }\n .toList()\n\n var ans = 0\n fun findCandidate(seq: IntProgression) {\n var pos = start\n var k = 0\n var rem = t\n\n for(j in seq) {\n rem -= pos.distance(nodes[j])\n if(rem < 0) break\n k++\n pos = nodes[j]\n }\n\n if(k > ans) ans = k\n }\n\n for(i in nodes.indices) {\n findCandidate(i downTo 0)\n findCandidate(i until nodes.size)\n }\n\n println(ans)\n}\n\ndata class Point(val x: Long, val y: Long) {\n fun distance(other: Point) = abs(x - other.x) + abs(y - other.y)\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()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "implementation"], "code_uid": "c7f2f8404c89cd4e1d5d5822291200dd", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args:Array){\n val number = readLine()!!.toInt()\n\n for (i in 0..number){\n if (isLucky(i) && number % i == 0 ){\n print(\"YES\")\n break\n } else if(i == number) {\n print(\"NO\")\n }\n }\n}\n\nfun isLucky(num : Int): Boolean {\n var numAsString = num.toString()\n\n var isLucky = true;\n\n numAsString.forEach {\n if(it != '4' && it != '7'){\n isLucky = false\n }\n }\n return isLucky\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "number theory"], "code_uid": "2d05575ca265ba0391f88e21bcb34a7b", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val input = readLine()!!.toInt()\n var d = arrayOf(0,4,7)\n\n for (i in (0 .. 2)){\n for (ii in (0 .. 2)){\n for (iii in (1 .. 2)){\n var lucky = 100 * d[i] + 10 * d[ii] + d[iii]\n if (input % lucky == 0){\n println(\"YES\")\n return\n }\n }\n }\n }\n println(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "number theory"], "code_uid": "27f84fa5941742eb562356b0cee933b9", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val str = r.readLine()!!.toInt()\n var p = false\n val num = listOf(4, 7, 44, 47, 77, 444, 447, 474, 477, 744, 747, 774, 777)\n for (n in num) {\n if (str % n == 0){\n println(\"YES\")\n p = true\n break\n }\n }\n if (!p) println(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "number theory"], "code_uid": "ca3d70e9c281c537059c5e130dd3bc14", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n try {\n var i = nextInt()\n while(i > 0) {\n if (isLuckyNumber(i))\n println(\"YES\")\n else\n print(\"NO\")\n i = nextInt()\n }\n } catch (e: Exception) {}\n}\n\n\nfun isLuckyNumber(number: Int): Boolean {\n var isLucky = false\n\n if (isDigitWith(number, Pair('4', '7')))\n isLucky = true\n else if (isDividedByLuckyNumber(number))\n isLucky = true\n\n return isLucky\n }\n\n private fun isDividedByLuckyNumber(number: Int): Boolean {\n var luckyNumber = 4\n while (number / luckyNumber >= 1) {\n if (isDividedBy(number, luckyNumber)) return true\n else luckyNumber = nextLuckyNumber(luckyNumber)\n }\n return false\n }\n\n fun nextLuckyNumber(preLuckyNumber: Int): Int {\n\n if (isNeedToIncreasedBitNumber(preLuckyNumber)) {\n val num = preLuckyNumber.toString().map { '4' }\n return String(num.toCharArray()).toInt() * 10 + 4\n } else {\n val digits = preLuckyNumber.toString().toCharArray()\n var isNotChanged = true\n val changedDigits =\n digits.reversed()\n .map {\n if (isNotChanged && it == '4') {\n isNotChanged = false\n '7'\n } else it\n }\n .reversed()\n\n return String(changedDigits.toCharArray()).toInt()\n }\n }\n\n private fun isNeedToIncreasedBitNumber(preLuckyNumber: Int): Boolean {\n return (preLuckyNumber % 7) == 0\n }\n\nprivate fun isDigitWith(number: Int, digits: Pair): Boolean {\n val (c1, c2) = digits\n\n val numCharArray = number.toString().toCharArray()\n for (char in numCharArray) {\n if (char != c1 && char != c2)\n return false\n }\n return true\n}\n\nprivate fun isDividedBy(number: Int, divider: Int): Boolean {\n return (number % divider) == 0\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "number theory"], "code_uid": "0e6a4d37d36a42d1a0957befc20e9d29", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (n, k) = readInts()\n val ans = 3*n + minOf(k-1, n-k)\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 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() }", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "eaa2d2bc0aaea90200d64b70db2deb93", "src_uid": "24b02afe8d86314ec5f75a00c72af514", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport java.io.*\nimport kotlin.math.*\n\nfun main() {\n\tval (n, k) = readLine()!!.split(\" \").map { it.toInt() }\n\tval answer = (3 * n) + min(k - 1, n - k)\n\tprintln(answer)\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "f94d5e2beae0a8e3465a652119acd2c4", "src_uid": "24b02afe8d86314ec5f75a00c72af514", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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,m) = f.readLine().split(\" \").map{it.toInt()}\n\n\tvar answer = 2*n+1\n\tanswer += min(n+m-2,2*n-m-1)\n\n\tprintln(answer)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "5ab5453ff3c2ffd231157b730f331c7e", "src_uid": "24b02afe8d86314ec5f75a00c72af514", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val iter0 = reader.readLine().iterator()\n val iter1 = reader.readLine().iterator()\n val builder = StringBuilder()\n while(iter0.hasNext() && iter1.hasNext()){\n val result = iter0.nextChar().toInt() xor iter1.nextChar().toInt()\n builder.append(result)\n }\n println(builder.toString())\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c974eb346993f004339b574946c3b7b1", "src_uid": "3714b7596a6b48ca5b7a346f60d90549", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.util.*\n\n/**\n * Created by AoEiuV020 on 2017/06/09-16:37:06.\n */\nfun main(vararg args: String) {\n val a = readLine()!!.map { it == '1' }\n val b = readLine()!!.map { it == '1' }\n print(a.zip(b).map { if(it.first != it.second) 1 else 0 }.joinToString(\"\"))\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "97eaaab5685e3f2b26b80d56683ea543", "src_uid": "3714b7596a6b48ca5b7a346f60d90549", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val scan = Scanner(System.`in`)\n val a = scan.next()\n val b = scan.next()\n var c = \"\"\n\n for (i in 0 until a.length) c += if (a[i] != b[i]) '1' else '0'\n println(c)\n\n}\n\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "0a620772ad6398d8ef4a45d579088b42", "src_uid": "3714b7596a6b48ca5b7a346f60d90549", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val s1 = r.readLine()!!\n val s2 = r.readLine()!!\n val len = s1.length\n (0..len-1).forEach {\n if (s1[it]==s2[it]) s.append(\"0\")\n else s.append(\"1\")\n }\n println(s)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4677b5127cdf02bc4a846a695d68ecb6", "src_uid": "3714b7596a6b48ca5b7a346f60d90549", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.util.*\n\n/**\n * Created by AoEiuV020 on 2017/05/09.\n */\nfun main(vararg args: String) {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n val m = scanner.nextInt()\n print(when {\n n == 1 -> m / 2\n m == 1 -> n / 2\n n % 2 == 0 -> n / 2 * m\n m % 2 == 0 -> m / 2 * n\n else -> n / 2 * m + m / 2\n })\n }\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "4a5a3b4c830089a93706669e1faa94c4", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\nimport java.lang.Math.floor\n\nfun main(args:Array){\n val input = Scanner(System.`in`)\n var m = input.nextInt()\n var n = input.nextInt()\n\n print(floor((m*n).toDouble()/2).toInt())\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "77e4bb2e85fabbc4243cd91e1deeeb33", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n val m = scanner.nextInt()\n\n println(n * m / 2)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "3b87a9f2126d073f8d07b7e000443f06", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun arrangeDomino(M: Int, N: Int): Int {\n return M * N / 2\n}\n\nfun main(args: Array) {\n val input = readLine()!!.split(\" \").map { it.toInt() }\n println(arrangeDomino(input[0], input[1]))\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "9312fff42ef04f893e73710b33b8a5c4", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n readLine()\n val ar = readLine()!!.split(\" \").map { it.toInt() }.sorted().toIntArray()\n var sum = 0\n var i = 1\n while (i < ar.count()) {\n sum += ar[i]-ar[i-1]\n i += 2\n }\n println(sum)\n}", "lang_cluster": "Kotlin", "tags": ["sortings"], "code_uid": "e03a3ba7468dfae2ff5909d27a3fdb72", "src_uid": "55485fe203a114374f0aae93006278d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.File\nimport kotlin.system.measureTimeMillis\n\nfun solve(input: BufferedReader) {\n val n = input.readLine().toInt()\n val a = input.readLine().split(\" \").map {it.toInt()}.sorted().toTypedArray()\n var sum = 0\n for (i in 0 until n step 2)\n sum += a[i + 1] - a[i]\n println(sum)\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", "lang_cluster": "Kotlin", "tags": ["sortings"], "code_uid": "edbed9c9bab87bef99e07665e0917b15", "src_uid": "55485fe203a114374f0aae93006278d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n val players = reader.nextInt()\n var ans = 0\n val listOfPlayers = IntArray(players)\n for (i in 0 until players) {\n listOfPlayers[i] = reader.nextInt()\n }\n listOfPlayers.sort()\n for (i in 0 until players - 1 step 2) {\n ans += listOfPlayers[i + 1] - listOfPlayers[i]\n }\n println(ans)\n\n}\n", "lang_cluster": "Kotlin", "tags": ["sortings"], "code_uid": "aa4b8f3c4d6b1b230c2ffe5b7deb6447", "src_uid": "55485fe203a114374f0aae93006278d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/* http://codeforces.com/problemset/problem/1092/B */\n\nfun main() {\n readLine() // skip first line\n val skillValues = readLine()!!.split(\" \").map { it.toInt() }\n val sortedSkillValues = skillValues.sorted()\n var numberOfProblems = 0\n for (i in 0 until skillValues.size step 2) {\n numberOfProblems += sortedSkillValues[i + 1] - sortedSkillValues[i]\n }\n println(numberOfProblems)\n}", "lang_cluster": "Kotlin", "tags": ["sortings"], "code_uid": "8d837d0f100d1afdcacd6c8e14e64856", "src_uid": "55485fe203a114374f0aae93006278d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n val r = readLine()!!.split(' ').map { it.toInt() }\n val b = readLine()!!.split(' ').map { it.toInt() }\n var r_only = 0\n var b_only = 0\n var rb = 0\n for (i in 0 until n) {\n if (r[i] == 1 && b[i] == 0) {\n r_only++\n }\n if (r[i] == 0 && b[i] == 1) {\n b_only++\n }\n if (r[i] == 1 && b[i] == 1) {\n rb++\n }\n }\n if (r_only == 0) {\n println(-1)\n }\n else {\n println((b_only + r_only) / r_only)\n }\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "a164025f98c8bc1d46fc3b8d517cde06", "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main()\n{\n val lens = readLine()!!.toInt()\n val robo = readLine()!!.split(\" \").map { it.toInt() }\n val bion = readLine()!!.split(\" \").map { it.toInt() }\n var rplus = 0\n var bplus = 0\n for ((i, v) in robo.withIndex())\n {\n if (v == 0 && bion[i] == 1) bplus ++\n if (v == 1 && bion[i] == 0) rplus ++\n }\n if (rplus == 0)\n {\n println(-1)\n }\n else\n {\n println((bplus / rplus) + 1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "e7850275709313c8d0a72807d1d3d129", "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Integer.*\nimport java.util.*\n\nfun main() {\n val scanner = Scanner(System.`in`)\n with(scanner) {\n val a1 = nextIntArray()\n val a2 = nextIntArray(size = a1.size)\n val b1 = bitSetOf(a1)\n val b2 = bitSetOf(a2)\n\n if(b1.cardinality() > b2.cardinality()){\n println(\"1\")\n return\n }\n\n val mask = (b1.clone() as BitSet)\n mask.and(b2)\n b1.andNot(mask)\n b2.andNot(mask)\n\n if(b1.isEmpty || (b1.cardinality() == b1.length() && b2.cardinality() == b2.length())) {\n println(\"-1\")\n return\n }\n\n print(b2.cardinality() / b1.cardinality() + 1)\n }\n}\n\n/**\n * Consumes a size n and then reads n integers into an array.\n */\nfun Scanner.nextIntArray(size: Int = -1): IntArray {\n val array = IntArray(if(size > 0) size else nextInt())\n for(i in array.indices){\n array[i] = nextInt()\n }\n return array\n}\n\n/**\n * Consumes a number n and then executes the given consumer n times.\n */\nfun Scanner.testCases(forEach: Scanner.() -> Unit) {\n val n = nextInt()\n for(i in 1..n){\n forEach(this)\n }\n}\n\nfun IntArray.print(){\n println(this.joinToString(\" \"))\n}\n\nfun bitSetOf(array: IntArray): BitSet {\n val ret = BitSet(array.size)\n for(i in array.indices){\n if(array[i] == 1){\n ret.set(i)\n }\n }\n return ret\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "404ec3045e27c694fce59a71c4cd5e65", "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!.toInt()\n val red = readLine()!!\n val blue = readLine()!!\n var rojo = 0\n var azul = 0\n for (j in 0 until n) {\n if (red[2 * j] == '1' && blue[2 * j] == '0') {\n rojo++\n } else if (red[2 * j] == '0' && blue[2 * j] == '1') {\n azul++\n }\n }\n when {\n rojo > azul -> println(1)\n rojo == 0 -> println(-1)\n else -> println(1 + (azul / rojo))\n }\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "1670add75d0c006b2c0cab68e13c23c1", "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\nimport java.util.*\n\n//var gr = MutableList>(2, MutableList(1, (1)));\n\nfun solve(fr : fastReader) {\n /*\n \u041a\u0435\u043a\u0438 \u0438 \u043f\u0440\u0438\u043a\u043e\u043b\u044b:\n Pair - \u041f\u0430\u0440\u0430\n Pair(a, b) - \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0430\u0440\u0443\n \u0431\u0443\u0434\u0435\u0442 \u0440\u0443\u0433\u0430\u0442\u044c\u0441\u044f \u0438 \u043d\u0435 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c - \u0437\u0430\u0431\u0435\u0439\n \n \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e (\u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u043e ?) \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0430 \u043d\u0435 \u043a\u043e\u043f\u0438\u044f\n \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0439 \u043d\u0438\u0447\u0435\u0433\u043e \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438!\n \n \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c : arr.sort()\n \u0435\u0441\u043b\u0438 \u0442\u0430\u043c \u043f\u0430\u0440\u044b/\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u0442\u0434 \u0442\u043e \n arr.sortWith(compareBy({it.first}, {it.second})) \u0438\u043b\u0438 arr.sortWith(compareBy({it[0]}, {it[1]})) \u0447\u043e \u0442\u0430 \u0442\u0430\u043a\u043e\u0435\n\n\t\u044a\u0443\u044a \u0434\u043e \u0441\u043b\u0435\u0437 \n\t\u0432\u0435\u043a\u0442\u043e\u0440 \u044d\u0442\u043e MutableList \n\tMutableList(n, {0}) \n\tpush_back = add\n\tpop_back = removeAt(lastIndex)\n\t\n\n\t\u043e \u0435\u0449\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0430\u0440\u0438\u0442\u044c\u0441\u044f \u0441 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 )))\n */\n\n \tvar a = fr.getInt();\n \tvar b = fr.getInt();\n \tvar c = fr.getInt();\n\n \tfun gcd(a : Int, b : Int) : Int {\n \t\tif (b == 0) {\n \t\t\treturn a;\n \t\t} else {\n \t\t\treturn gcd(b, a % b);\n \t\t}\n \t}\n\n \tvar g = gcd(a, b);\n \ta *= b;\n \ta /= g;\n \tprint (c / a);\n\n}\n \nfun main(args: Array) {\n\tvar fr = fastReader();\n var T = 1\n //T = fr.getInt();\n for (i in 1..T) {\n \tsolve(fr)\n }\n print('\\n');\n}\n\nclass fastReader {\n\tvar buffer : String = \"\";\n\tvar pos : Int = 0;\n\tvar bufferSize : Int = 0;\n\n\tfun readBuffer() {\n\t\tbuffer = readLine()!!;\n\t\tbuffer += ' ';\n\t\tpos = 0;\n\t\tbufferSize = buffer.length;\n\t}\n\n\tfun getChar() : Char {\n\t\tif (pos == bufferSize) {\n\t\t\treadBuffer();\n\t\t}\n\t\treturn buffer[pos++];\n\t}\n\n\tfun getInt() : Int {\n\t\tvar ans : Int = 0;\n\t\tvar c : Char = ' ';\n\t\tvar minus : Boolean = false;\n\t\twhile ((c == ' ') or (c == '\\n'))\n\t\t\tc = getChar();\n\t\tif (c == '-') {\n\t\t\tminus = true;\n\t\t\tc = getChar();\n\t\t}\n\t\twhile ((c != ' ') and (c != '\\n')) {\n\t\t\tans = ans * 10 + c.toInt() - '0'.toInt();\n\t\t\tc = getChar();\n\t\t}\n\t\tif (minus) {\n\t\t\tans *= -1;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tfun getLong() : Long {\n\t\tvar ans : Long = 0;\n\t\tvar c : Char = ' ';\n\t\tvar minus : Boolean = false;\n\t\twhile ((c == ' ') or (c == '\\n'))\n\t\t\tc = getChar();\n\t\tif (c == '-') {\n\t\t\tminus = true;\n\t\t\tc = getChar();\n\t\t}\n\t\twhile ((c != ' ') and (c != '\\n')) {\n\t\t\tans = ans * 10 + c.toInt() - '0'.toInt();\n\t\t\tc = getChar();\n\t\t}\n\t\tif (minus) {\n\t\t\tans *= -1;\n\t\t}\n\t\treturn ans;\n\t} \n\n\tfun getString() : String {\n\t\tvar c : Char = ' ';\n\t\tvar ans : String = \"\";\n\t\twhile ((c == ' ') or (c == '\\n'))\n\t\t\tc = getChar();\n\t\twhile ((c != ' ') and (c != '\\n')) {\n\t\t\tans += c;\n\t\t\tc = getChar();\n\t\t}\n\t\treturn ans;\n\t}\n\n\tfun getSpaceString() : String {\n\t\tvar ans : String = buffer;\n\t\treadBuffer();\n\t\treturn ans;\n\t}\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "bb9774dface56a0b43517fc6d84e1eaa", "src_uid": "e7ad55ce26fc8610639323af1de36c2d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nfun main(args: Array) {var reader =Scanner(System.`in`)\n var n:Int = reader.nextInt()\n var m:Int = reader.nextInt()\n var z:Int = reader.nextInt()\n var counter:Int=0\n var arrayN = Array(z/n){n}\n var arrayM = Array(z/m){m}\n var A:Int = n\n var B:Int = m\n for (i in (1..(z/A)-1)){\n arrayN[i]=n+A\n n+=A\n }\n for (i in 1..((z/B)-1)) {\n arrayM[i] =m+B\n m+=B\n }\n for (i in 0..(z/A)-1)\n {\n for (j in 0..(z/B)-1) {\n if (arrayN[i] == arrayM[j])\n counter++\n }\n }\n print(counter)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "1cb2241e1be8fa1ba16b2c4f064643cd", "src_uid": "e7ad55ce26fc8610639323af1de36c2d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (n, m, z) = readInts()\n var sol = 0\n for (moment in n..z step n)\n if (moment % m == 0) sol++\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "80b5c8ecb7fc4da401e2ed530e0580fe", "src_uid": "e7ad55ce26fc8610639323af1de36c2d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package codeforces.round395\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 n = scanner.nextBigInteger()\n val m = scanner.nextBigInteger()\n val z = scanner.nextInt()\n\n val gcd = n.gcd(m)\n val x = n * m / gcd\n\n out.println(z / x.toInt())\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "b05a3dda7b2acd220535b31235ee0d20", "src_uid": "e7ad55ce26fc8610639323af1de36c2d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main() {\n val s = readLine()!!.split(\" \").map { it.toInt() }\n val n = s[0]\n val p = s[1]\n val k = s[2]\n\n val left = (p - k).coerceAtLeast(1)\n val right = (p + k).coerceAtMost(n)\n val ll = if(left > 1) \"<<\" else \"\"\n val rr = if(right < n) \">>\" else \"\"\n val pages = (left..right).joinToString(separator = \" \") { if (it == p) \"($it)\" else \"$it\"}\n println(\"$ll $pages $rr\".trim())\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "ef288a191ef985fef32659565f95bb83", "src_uid": "526e2cce272e42a3220e33149b1c9c84", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (n,p,k) = readLine()!!.split(\" \").map { it.toInt() }\n var s = \"\"\n var c = \"\"\n var b = false\n\n val f= if (p-k <= 1) 1 else p-k\n val l= if (p+k >= n) n else p+k\n\n for (i in f..l) {\n when (i) {\n f -> if(i > 1) s = \"<<\" else b = true\n p -> if (i != 1) s = s.plus(\" ($i)\") else s = s.plus(\"($i)\")\n l -> if(i < n) c = \" >>\"\n }\n\n if (i != p && i >= 1 && i <= n && !b)\n s = s.plus(\" $i\").plus(c)\n else if (b) {\n if (i != p) s = s.plus(\"$i\").plus(c) else s = s.plus(\"($i)\").plus(c)\n b = false\n }\n }\n print(s)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "3d71c46e3583c58cc7039c766859d00f", "src_uid": "526e2cce272e42a3220e33149b1c9c84", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val givenList= readLine()!!.split(\" \").map { it.toInt() }\n val n=givenList[0]\n val p=givenList[1]\n val k=givenList[2]\n val string=\"($p)\"\n if ((p+k) < n && (p-k)>0 && (p-k)!=1){\n val backList=((p-k)until p).toList()\n val farwardList=(p+1.. (p+k)).toList()\n println( backList.joinToString(prefix = \"<< \",separator = \" \",postfix = \" $string\")+farwardList\n .joinToString(prefix=\" \",separator = \" \",postfix = \" >>\"))\n }\n else if ((p+k)>n && (p-k)>0 && (p-k)!=1){\n val backList=((p-k)until p).toList()\n val farwardList=(p+1..n).toList()\n println( backList.joinToString(prefix = \"<< \",separator = \" \",postfix =\" $string\")+farwardList\n .joinToString(prefix = \" \",separator = \" \"))\n }\n else if ((p+k)0 }\n val farwardList=(p+1..(p+k)).toList()\n if (backList.isEmpty())\n println( backList.joinToString(separator = \" \")+string+farwardList\n .joinToString(prefix = \" \",separator = \" \",postfix = \" >>\"))\n else\n println( backList.joinToString(separator = \" \",postfix = \" $string\")+farwardList\n .joinToString(prefix = \" \",separator = \" \",postfix = \" >>\"))\n }\n else if ((p+k) == n && (p-k)>0 && (p-k)!=1){\n val backList=((p-k)until p).toList()\n val farwardList=(p+1.. (p+k)).toList()\n println( backList.joinToString(prefix = \"<< \",separator = \" \",postfix = \" $string\")+farwardList\n .joinToString(prefix=\" \",separator = \" \"))\n }\n else if ((p+k) < n && (p-k)==0){\n val backList=if (p==1){ ((p-k).. 1).toList().filter { it>1 }}\n else{\n ((p-k).. 1).toList().filter { it>=1 }}\n val farwardList=(p+1.. (p+k)).toList()\n println( backList.joinToString(separator = \" \",postfix = \" $string\")+farwardList\n .joinToString(prefix=\" \",separator = \" \",postfix = \" >>\"))\n }\n else if ((p-k) == 1 && (p+k)>n){\n val backList=((p-k)until p).toList()\n val farwardList=(p+1 .. n).toList()\n println( backList.joinToString(separator = \" \",postfix = \" $string\")+farwardList\n .joinToString(prefix=\" \",separator = \" \"))\n }\n else if ((p-k) == 1 && (p+k)>\"))\n }\n else if ((p+k)>n && (p-k)<0){\n val backList=(1 until min(p,k)).toList()\n val farwardList=(p+1 ..max(p,k)).toList()\n println( backList.joinToString(separator = \" \",postfix = \" $string\")+farwardList\n .joinToString(prefix=\" \",separator = \" \"))\n }\n else if ((p+k)==n && (p-k)==1){\n val backList=((p-k)..k).toList()\n val farwardList=(p+1..(p+1)).toList()\n println( backList.joinToString(separator = \" \",postfix = \" $string\")+farwardList\n .joinToString(prefix=\" \",separator = \" \"))\n }\n else if (p==k &&p==n){\n val backList=(1..p-1).toList()\n println( backList.joinToString(separator = \" \",postfix = \" $string\"))\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5912d3f0d3a39cb8f0102996a28bee58", "src_uid": "526e2cce272e42a3220e33149b1c9c84", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.lang.StringBuilder\nimport java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val writter = PrintWriter(System.out)\n val sin = scanner.nextLine()\n .split(\" \")\n writter.print(pages(sin[0].toInt(), sin[1].toInt(), sin[2].toInt()))\n writter.flush()\n}\n\nprivate fun pages(n: Int, p: Int, k: Int): String {\n val goToFirstPageSymbol = \"<< \"\n val goToLastPageSymbol = \" >>\"\n val sb = StringBuilder()\n var leftBound = if(p - k > 1) p- k else 1\n if(leftBound != 1) {\n sb.append(goToFirstPageSymbol)\n }\n for(i in leftBound until p) {\n sb.append(\"$i \")\n }\n sb.append(\"($p) \")\n val rightBound = if(p + k > n) n else p + k\n for (i in p + 1..rightBound) {\n sb.append(\"$i \")\n }\n sb.deleteCharAt(sb.length - 1)\n if (p + k < n) {\n sb.append(goToLastPageSymbol)\n }\n\n return sb.toString()\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "50b7543ed57cb7862713ca905b79369e", "src_uid": "526e2cce272e42a3220e33149b1c9c84", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 s47 = str.filter { c -> c == '4' || c == '7' }.length\n print(if (s47 == 4 || s47 == 7) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "26177a064a1d4d1bf5a88ce350bc450e", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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=readLong()\n var luc=0\n while(n>0){\n if(n%10==4L||n%10==7L)luc++\n n/=10\n }\n if(luc==4||luc==7)printLine(\"YES\")\n else printLine(\"NO\")\n output()\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "07269b1c62db1463cc7a95c20f07b1e3", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = readLn().toLong()\n val digital = Array(10) { 0 }\n while (n > 0) {\n digital[n.rem(10).toInt()]++\n n /= 10\n }\n\n val q = digital[4] + digital[7]\n val isHappyNumber = !q.toString().any { it != '4' && it != '7' }\n if (isHappyNumber)\n println(\"YES\")\n else\n println(\"NO\")\n\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "efdda5b059442d9d2e78f8a86b38e2af", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val lucky = readLine()!!\n .count{it == '4' || it == '7' }\n .toString()\n .all { it == '4' || it == '7' }\n\n println(if (lucky) \"YES\" else \"NO\")\n}\n\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "3b321b64dfd6734c06f469a85a6c1d98", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args:Array){\n var input = readLine()!!.split(' ')\n\n val studentCount = input[0].toInt() - 1\n\n\n input = readLine()!!.split(' ')\n\n val puzzles = mutableListOf()\n\n input.forEach {\n puzzles.add(it.toInt())\n }\n puzzles.sort()\n\n var currentMinDiff = puzzles[puzzles.lastIndex]\n for (i in 0..puzzles.lastIndex - studentCount){\n if(i + studentCount <= puzzles.lastIndex){\n val diffCandidate = puzzles[i + studentCount] - puzzles[i]\n\n if ( diffCandidate < currentMinDiff){\n currentMinDiff = diffCandidate\n }\n }\n }\n\n print(currentMinDiff)\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "e2a9f15148083cca56c7e2cb06ae5d13", "src_uid": "7830aabb0663e645d54004063746e47f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (totalStudent, totalPuzzles) = readLine()!!.split(\" \").map(String::toInt)\n val puzzles = readLine()!!.split(\" \").map(String::toInt).sorted()\n val minDifferent = ((totalStudent - 1) until totalPuzzles)\n .map { puzzles[it] - puzzles[it - totalStudent + 1] }\n .min()\n println(minDifferent)\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "d65096862851594580ad5c1d6876d1bc", "src_uid": "7830aabb0663e645d54004063746e47f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (desired, available) = readLine()!!.split(' ').map { it.toInt() }\n\n val puzzles = readLine()!!.split(' ').map { it.toInt() }.sorted()\n var leastDifference = Int.MAX_VALUE\n for (it in 0 until available - desired + 1) {\n val diff = puzzles[it + desired - 1] - puzzles[it]\n if (minOf(leastDifference, diff) != leastDifference) {\n leastDifference = diff\n }\n }\n\n println(leastDifference)\n}\n\n", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "31f46b3f9d660cf7c8be5b60f65d5dc0", "src_uid": "7830aabb0663e645d54004063746e47f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport kotlin.math.*\n\nfun main() {\n io.apply {\n\n val n = int\n val data = ints().sortedArray()\n val ans = (0 .. (data.size - n)).map { data[it + n - 1] - data[it] }.min()!!\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 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", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "fb1c2c4ab5dbc69fda36add7684fa5ce", "src_uid": "7830aabb0663e645d54004063746e47f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "7394b26ac54b7d602139948d268c82cb", "src_uid": "77177b1a2faf0ba4ca1f4d77632b635b", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "20b80995fc34fba132e27df684ec061a", "src_uid": "77177b1a2faf0ba4ca1f4d77632b635b", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n\n val weights = readLine()!!.split(\" \").map { it.toInt() }.toMutableList()\n var years = 0\n\n while(weights[0] <= weights[1]){\n weights[0] *= 3\n weights[1] *= 2\n years++\n }\n print(years)\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4f32792eb93bfe3e4ce02bc8da44a853", "src_uid": "a1583b07a9d093e887f73cc5c29e444a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (a, b) = readLine()!!.split(\" \").map { it.toInt() }\n\n var years = 0\n while (a <= b) {\n years++\n a *= 3\n b *= 2\n }\n\n print(years)\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "04df0f80c76bd89978bcd13206f90336", "src_uid": "a1583b07a9d093e887f73cc5c29e444a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val sc = Scanner(System.`in`)\n var a = sc.nextInt()\n var b = sc.nextInt()\n var x =0\n while (a <= b) {\n a *= 3\n b *= 2\n x++\n }\n println(x)\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d3b46619d22e4eadc42fee3901f1b828", "src_uid": "a1583b07a9d093e887f73cc5c29e444a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n p791a()\n}\n\nfun p791a() {\n var (a, b) = readLine()!!.split(' ').map { it.toLong() }\n\n var answer = 0L\n while (a <= b) {\n a *= 3\n b *= 2\n answer++\n }\n\n println(answer)\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a8cfd220466967f3cce41c60188624c5", "src_uid": "a1583b07a9d093e887f73cc5c29e444a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val count = readLine()?.toInt()\n for (i in 0 until count!!) {\n val a = readLine()?.toInt()\n if(a!! > 2){\n if (a.rem(2) == 0) {\n val number = a / 2 - 1\n if(number < 0){\n println(0)\n } else {\n println(number)\n }\n } else {\n val number = a / 2\n if(number < 0){\n println(0)\n } else {\n println(number)\n }\n }\n } else {\n println(0)\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "c25eae07f17f67f8b6a73387f13c8048", "src_uid": "b69170c8377623beb66db4706a02ffc6", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main()= repeat(readLine()!!.toInt()){ var r = readLine()!!.toInt();println(if (r % 2 == 0) (r/2) -1 else r/2) }", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "42c64e9292f2ae4704156a0bfaf8aa32", "src_uid": "b69170c8377623beb66db4706a02ffc6", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val input = generateSequence(::readLine)\n input.asSequence().drop(1).forEach { line ->\n println()\n val total = line.toInt()\n if (total % 2 != 0) print((total - 1) / 2) else print((total - 2) / 2)\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "34dd00829aff14840c5914f9d3af08ed", "src_uid": "b69170c8377623beb66db4706a02ffc6", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.*\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\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() }\nfun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)\nfun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\nfun Boolean.toInt() = if (this) 1 else 0\nval INF = 0x3f3f3f3f\nval MOD = (1e9 + 7).toLong()\n/***********************************************************************************************/\n\nfun main() {\n var t = readInt()\n for (i in 1..t) {\n var a: Int = readInt()\n var poss: Int = 0\n if (a % 2 == 0) {\n println(a / 2 - 1)\n } else {\n println(a / 2)\n }\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "027567c78713215784c3adc57d43b177", "src_uid": "b69170c8377623beb66db4706a02ffc6", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n\n var (x, y, z) = readLine()!!.split(\" \").map(String :: toInt)\n\n if(x > y + z) println(\"+\")\n else if(y > x + z) println(\"-\")\n else if(x == y && z == 0) println(0)\n else println(\"?\")\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "1778363734d6da48b14b8df9db5b32fc", "src_uid": "66398694a4a142b4a4e709d059aca0fa", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun main(args: Array) {\n val (x, y, z) = readLine()!!.split(' ').map { it.toInt() }\n val xy = x - y\n\n println(\n when {\n z != 0 && z >= abs(xy) -> \"?\"\n xy < 0 -> \"-\"\n xy > 0 -> \"+\"\n else -> \"0\"\n }\n )\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "02a5fb53502db99728d9ec43843fe8be", "src_uid": "66398694a4a142b4a4e709d059aca0fa", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 x = ir.nextInt()\n val y = ir.nextInt()\n val z = ir.nextInt()\n\n if (z == 0) {\n when {\n x == y -> pw.print('0')\n x > y -> pw.print('+')\n else -> pw.print('-')\n }\n } else {\n val x1 = x + z\n val y1 = y + z\n\n if (x1 == y || y1 == x)\n pw.print('?')\n else if ((x1 in (y + 1) until y1) || (y1 in (x + 1) until x1))\n pw.print('?')\n else if (x1 > y1)\n pw.print('+')\n else if (y1 > x1)\n pw.print('-')\n else\n pw.print('?')\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}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "559ab11300ab159fa6fe28a9603c150a", "src_uid": "66398694a4a142b4a4e709d059aca0fa", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 if (x > y + z) {\n println(\"+\")\n }\n else if (y > x + z) {\n println(\"-\")\n }\n else if (x == y && z == 0) {\n println(\"0\")\n }\n else {\n println(\"?\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "32aa0f9bf996cc0ef5cf72c5831e93cf", "src_uid": "66398694a4a142b4a4e709d059aca0fa", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package com.happypeople.codeforces.c1133\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\n\nfun main(args: Array) {\n try {\n A1133().run()\n } catch (e: Throwable) {\n println(\"\")\n e.printStackTrace()\n }\n}\n\nclass A1133 {\n fun run() {\n val sc = Scanner(systemIn())\n var s1=sc.next().trim()\n var s2=sc.next().trim()\n\n var h1str=s1.substring(0, 2)\n if(h1str.startsWith(\"0\"))\n h1str=h1str.substring(1, 2)\n var m1str=s1.substring(3, 5)\n if(m1str.startsWith(\"0\"))\n m1str=m1str.substring(1, 2)\n\n var h2str=s2.substring(0, 2)\n if(h2str.startsWith(\"0\"))\n h2str=h2str.substring(1, 2)\n var m2str=s2.substring(3, 5)\n if(m2str.startsWith(\"0\"))\n m2str=m2str.substring(1, 2)\n\n\n val h1=h1str.toInt()\n val m1=m1str.toInt()\n val h2=h2str.toInt()\n val m2=m2str.toInt()\n\n var h=h2-h1\n var m=m2-m1\n\n val mSum=(h*60+m)/2\n\n h=h1+mSum/60\n m=m1+mSum%60\n if(m>=60) {\n h++\n m-=60\n }\n if(h<10)\n print(\"0\")\n print(\"$h:\")\n if(m<10)\n print(\"0\")\n println(\"$m\")\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}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9c2132c0aa46ac56e7728643a604b7cf", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main()\n{\n val (x,y) = readLine()!!.split(\":\").map { it.toInt() }\n val (i,j) = readLine()!!.split(\":\").map { it.toInt() }\n val z = ((i-x)*60+j-y)/2\n var (z1,z2) = listOf(x+z.div(60) + (y+z%60)/60,(y+z%60)%60)\n if (z1<=9)\n {\n print(\"0${z1}:\")\n }\n else\n {\n print(\"${z1}:\")\n }\n if (z2<=9)\n {\n print(\"0${z2}\")\n }\n else\n {\n print(\"$z2\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "086772b17756f84961c879df40e6de4d", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n\n var mid = 0;\n var (h, m) = readLine()!!.split(':').map { it.toInt() }\n mid += h * 60 + m\n\n\n var s = readLine()!!\n h = s.split(':').component1().toInt()\n m = s.split(':').component2().toInt()\n\n mid += h * 60 + m\n //println(\"$h $m $mid\")\n mid /= 2\n //println(mid)\n h = mid / 60\n m = mid % 60\n\n if (h in 0..9) print (\"0\")\n print(\"$h:\")\n if (m in 0..9) print (\"0\")\n print(m)\n\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2debdfcfc34cf83dd51be733c1bef13b", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (hh, mm) = readLine()!!.split(\":\").map { it.toInt() }\n var (hh1, mm1) = readLine()!!.split(\":\").map { it.toInt() }\n\n val startTotal = hh * 60 + mm\n val endTotal = hh1 * 60 + mm1\n val mid = (startTotal + endTotal) / 2\n\n val h = mid / 60\n val m = mid % 60\n\n if (h in 0..9) print(\"0\")\n print(\"$h:\")\n if (m in 0..9) print(\"0\")\n print(m)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "1f4f613ca543162dd043edbb8e7f7f81", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (a, b) = readLine()!!.split(\" \").map(String::toLong)\n var sol = 0L\n while (b != 0L) {\n sol+= a/b\n val c = a % b\n a = b\n b = c\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "2499cb4e4493e31e4f26a065f87c5a2e", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 var ans = 0L\n while (a % b != 0L) {\n ans += a / b\n a = b.also { b = a % b }\n }\n ans += a/b\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "0f3ddcc348cdb9650f6940e5b6efbd40", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var (a, b) = readLine()!!.split(' ').map(String::toLong)\n if (a < b) {\n val c: Long = a\n a = b\n b = c\n }\n var ans: Long = 0L\n while (b > 0) {\n ans += a / b\n a %= b\n val c: Long = a\n a = b\n b = c\n }\n print(\"$ans\\n\")\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "e07bb11f35856cf0be65cc0199d0cd8b", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!.split(' ').map { it.toInt() }\n val a = readLine()!!.split(' ').map { it.toInt() }\n\n var cnt = 0\n var it = a.size - 1\n while (it >= 0 && a[it] <= n[1]) {\n ++cnt\n --it\n }\n\n var i = 0\n while (i < it && a[i] <= n[1]) {\n ++cnt\n ++i\n }\n\n print(cnt)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "5661f81b9b0b91f64c75b4f39a6f6d9e", "src_uid": "ecf0ead308d8a581dd233160a7e38173", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 { scan.nextInt() }\n if(dist.all { it <= k }) {\n println(n)\n return\n }\n\n var first = dist.indexOfFirst { it > k }\n if (first < 0) first = 0\n var last = dist.indexOfLast { it > k }\n if (last < 0) last = n - 1\n\n val ans = first + n - last - 1\n\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "245c0a6b537a94709b174407072e9091", "src_uid": "ecf0ead308d8a581dd233160a7e38173", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun solve() {\n\n val n = nextInt()\n val k = nextInt()\n\n val a = nextArray(n)\n val left = a.indexOfFirst { it > k }\n val right = a.indexOfLast { it > k }\n\n if (left == -1) {\n print(a.size)\n } else if (left == right) {\n print(a.size - 1)\n } else {\n print(left + a.size-1-right)\n }\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "81b4218442486be58cedacaa39ccea23", "src_uid": "ecf0ead308d8a581dd233160a7e38173", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val dif = readLine()!!.split(\" \").last().toInt()\n var list = readLine()!!.split(\" \").map { it.toInt() }\n\n var count = 0\n while (true) {\n if(list.first() <= dif) { list = list.drop(1); count++ }\n else if(list.last() <= dif) { list = list.dropLast(1); count++ }\n else break\n\n if (list.isEmpty()) break\n }\n print(count)\n}\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "5e6351359d3bc8cb1bac4740cdd9e86d", "src_uid": "ecf0ead308d8a581dd233160a7e38173", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n println(\n if (readLine()!!.contains(Regex(\"[HQ9]\")))\n \"YES\"\n else\n \"NO\"\n )\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "e865611a579d740ce23e88c1f4036f2b", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "3c4ddc7694ec1ef0c025460c9d8e0603", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "69dd07de07aee856dd4ccbe69764f7cf", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n print(if (readLine()!!.split(\"\").any { \"H,Q,9\".split(\",\").contains(it) }) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "183f09f06bf19e0ee11310733a3bb094", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n\tval list = readLine()!!.split(\" \").map(String::toInt)\n\tval n = list[0]\n\tvar a = list[1]\n\tval x = list[2]\n\tvar b = list[3]\n\tval y = list[4]\n \tfor (i in 0 until n+1) {\n \t if (b == a){\n \t println(\"YES\")\n \t return\n \t }\n if ( b == y || a == x ) { \n println(\"NO\")\n return\n }\n if (b==1){ \n b = n \n } else {\n b-=1\n }\n if (a==n){ \n a = 1 \n } else {\n a+=1\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "3796d0e91dba40cc49c16d619c5b9f1a", "src_uid": "5b889751f82c9f32f223cdee0c0095e4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private 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()\nfun main() {\n var (n, a, x, b, y) = readInts()\n\n while (a != x && b != y) {\n if (a == b) {\n println(\"YES\")\n return\n }\n a = (a % n) + 1\n b = ((b + n - 2) % n) + 1\n }\n if (a==b){\n println(\"YES\")\n }else{\n println(\"NO\")\n }\n\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "d906d54099aa4130afbe7cfa8fe529f1", "src_uid": "5b889751f82c9f32f223cdee0c0095e4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main(args: Array) {\n\n\n var (n, a, x, b, y) = readLine()!!.split(' ').map { it.toInt() }\n\n while (true) {\n a++\n if (a == n + 1) a = 1\n b--\n if (b == 0) b = n\n\n if (a == b) {\n print(\"YES\")\n return\n }\n\n if (a == x || b == y) {\n print(\"NO\")\n return\n }\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "1c6ed2434e2907680e657b5df487a760", "src_uid": "5b889751f82c9f32f223cdee0c0095e4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.system.exitProcess\n\nfun main() {\n var s = readLine()!!.split(' ').map{it.toInt()}\n var (n, a, x, b, y) = s;\n while(true){\n if(a == b){\n print(\"YES\")\n exitProcess(0)\n }\n if(a == x || b == y) break\n if(a == n) a = 1\n else a = a + 1\n if(b == 1) b = n\n else b = b - 1\n }\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "8e0080e3a2f25e7ab92b7c80b4d059a3", "src_uid": "5b889751f82c9f32f223cdee0c0095e4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun DataReader.solve(out: PrintWriter) {\n val s = nextToken()\n\n out.println((0..s.length - 1).mapTo(mutableSetOf()) { s.substring(it) + s.substring(0, it) }.size)\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", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "e3893886ce04760386b758e0b03c2345", "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val line = readLine()!!\n var original = line.replace(\"WUB\", \" \")\n while (original.contains(\" \"))\n original = original.replace(\" \", \" \")\n println(original.trim())\n}\n", "lang_cluster": "Kotlin", "tags": ["strings"], "code_uid": "6015e1a89de1bac0efe68faff72e522d", "src_uid": "edede580da1395fe459a480f6a0a548d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val s = readLine()!!\n println(s.replace(\"(WUB)+\".toRegex(), \" \").trim())\n}", "lang_cluster": "Kotlin", "tags": ["strings"], "code_uid": "d6916cc1ff3347d1a6b5ee587bd2c8a8", "src_uid": "edede580da1395fe459a480f6a0a548d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLine()!!.replace(\"(WUB)+\".toRegex(), \" \").trim()\n println( s )\n}\n", "lang_cluster": "Kotlin", "tags": ["strings"], "code_uid": "9d96bcf840a74fea2c916cd73f227179", "src_uid": "edede580da1395fe459a480f6a0a548d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}\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) { _writer.apply(block).flush() }\n\nfun main() {\n output {\n var wub = readLn()\n println(wub.split(\"WUB\").filterNot { it.isBlank() }.joinToString(\" \"))\n }\n}", "lang_cluster": "Kotlin", "tags": ["strings"], "code_uid": "7ff569c298edf7b066b44b797c6863d2", "src_uid": "edede580da1395fe459a480f6a0a548d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private fun solve(n: Int): Int {\n\tif (n < 3) return 1\n\tvar m = 4\n\tvar mode = 0\n\twhile (m <= n) {\n\t\tif (m == n || m + 1 == n) return 1\n\t\tm = 2 * m + 1 + mode\n\t\tmode = 1 - mode\n\t}\n\treturn 0\n}\n\nfun main() = println(solve(readInt()))\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\n", "lang_cluster": "Kotlin", "tags": ["math", "dp"], "code_uid": "6588dd847f878bd62e6d05ddcefd8143", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private fun solve(n: Int, m: Int = 1): Int {\n\tif (m == n || m + 1 == n) return 1\n\tif (m > n) return 0\n\treturn solve(n, 2 * m + 1 + m % 2)\n}\n\nfun main() = println(solve(readInt()))\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\n", "lang_cluster": "Kotlin", "tags": ["math", "dp"], "code_uid": "8e5db7a35812447b4d0caa0ced37179b", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private fun solve(n: Int): Int {\n\tvar m = 1\n\twhile (m <= n) {\n\t\tif (m == n || m + 1 == n) return 1\n\t\tm = 2 * m + 1 + m % 2\n\t}\n\treturn 0\n}\n\nfun main() = println(solve(readInt()))\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\n", "lang_cluster": "Kotlin", "tags": ["math", "dp"], "code_uid": "48d7fd76fbd641be6b73afbce1d065c3", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val jin = Scanner(System.`in`)\n val n = jin.nextInt()\n var k = 1\n var b = 1\n while (k <= n) {\n if (k == n || k + 1 == n) {\n println(1)\n return\n }\n k = (2 * k) + 1 + b\n b = 1 - b\n }\n println(0)\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp"], "code_uid": "45f0d788a662358528e305239dba6794", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.max\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val ar = scan.nextLine().split(\" \").map{ it.trim().toInt() }.toTypedArray()\n var n=ar[0]\n var k=ar[1]\n val a = scan.nextLine().split(\" \").map{ it.trim().toInt() }.toTypedArray()\n var count=0\n for (i in 0..n-1)\n if(a[i]>=a[k-1] && a[i]>0)\n count++\n println(count)\n\n }", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a2167e60b85b1f18bff751d75aed427b", "src_uid": "193ec1226ffe07522caf63e84a7d007f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nfun main() { var reader = Scanner(System.`in`)\n var n= reader.nextInt()\n var k= reader.nextInt()\n var arr = Array(n){0}\n for (i in 0..n-1) arr[i]=reader.nextInt()\n var count =0\n for (i in 0..n-1)\n {\n if (arr[i]>=arr[k-1]&&arr[i]>0)\n count++\n }\n print(count)\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c876221025abdaa0a88f1f1a138ce1ca", "src_uid": "193ec1226ffe07522caf63e84a7d007f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(arg: Array){\n val (n, k) = readLine()!!.split(' ').map(String::toInt)\n val a = readLine()!!.split(' ').map(String::toByte)\n println(a.filter {it >= a.get(k-1) && it > 0}.size)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "efd737ed383ed88632452037634c725e", "src_uid": "193ec1226ffe07522caf63e84a7d007f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.*\n\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nprivate fun readLine(): String? = _reader.readLine()\nprivate fun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nprivate fun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nprivate fun readInt() = read().toInt()\nprivate fun readDouble() = read().toDouble()\nprivate fun 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\nfun main() {\n output {\n val (n, k) = readInts(2)\n val scores = readInts(n)\n val toBeat = scores[k-1]\n var c = 0\n for(i in 0 until n) {\n if(scores[i] > 0 && scores[i] >= toBeat){\n c++\n }\n }\n println(c)\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "944232ca6c26275b3cbf18145d8cd985", "src_uid": "193ec1226ffe07522caf63e84a7d007f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(){\nval s = readLine()\n val t = readLine()\n if(s?.reversed().equals(t)) print(\"YES\") else print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "f8ba2084226f4aca7b94e186b465a3e6", "src_uid": "35a4be326690b58bf9add547fb63a5a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n println(if (readLine()!! == readLine()!!.reversed()) \"YES\" else \"NO\")\n}\n", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "fa8f9721e9b5d02dad5814719b99952e", "src_uid": "35a4be326690b58bf9add547fb63a5a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n\tval bi: String = readLine()!!\n\tval be: String = readLine()!!\n\tif(bi.reversed().equals(be)) println(\"YES\") else println(\"NO\")\n\t\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "96380649c441e24a6ec2bd9191053ed2", "src_uid": "35a4be326690b58bf9add547fb63a5a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array){\n val scan = Scanner(System.`in`)\n val s = scan.next().reversed()\n val t = scan.next()\n\n if (s == t) print(\"YES\")\n else print(\"NO\")\n \n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "42f941b20968dacb269958f979bc94db", "src_uid": "35a4be326690b58bf9add547fb63a5a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun readInt() = readLine()!!.toInt()\n\nfun main() {\n val x = readInt() / 2\n var res = 1L\n for (i in 1 until 2*x) {\n if (i != x) res *= i\n }\n println(res)\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "b8fbe89bfa4845721fde24ffeffd8ca3", "src_uid": "ad0985c56a207f76afa2ecd642f56728", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val reader = Scanner(System.`in`)\n val n:Int = reader.nextInt()\n\n var res:Long = 1\n for (k in 1..n/2-1) res *= k\n res *= res\n\n for (k in n/2+1..n) {\n res *= k\n res /= k - n/2\n }\n\n\n res /= 2;\n println(res)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "dbe3ee9283fa054c3e2b31fc021a0f2f", "src_uid": "ad0985c56a207f76afa2ecd642f56728", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun nCr(n: Int, r: Int): Long {\n return fact(n) / (fact(r) *\n fact(n - r))\n}\n\n// Returns factorial of n\nfun fact(n: Int): Long {\n var res = 1L\n for (i in 2..n) res *= i\n return res\n}\n\nfun main(args: Array) {\n// val input = Scanner(System.`in`)\n// var t = readLine()!!.toInt()\n val t = 1\n repeat(t) {\n\n val n = readLine()!!.toInt()\n// val a = readLine()!!.split(\" \").map { it.toInt() }\n\n println( fact(n/2 -1) * fact(n/2 -1) * nCr(n, n/2)/2)\n\n\n\n// println(ans.joinToString(separator = \" \") { (it + 1).toString()})\n }\n\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "45f18929ab837a11d45e81c201e418ce", "src_uid": "ad0985c56a207f76afa2ecd642f56728", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.OutputStreamWriter\nimport java.io.PrintWriter\nimport java.util.*\nimport kotlin.collections.HashSet\n\nfun fc(n : Long) : Long {\n var ret : Long = 1\n for (i in 1..n){\n ret *= i\n }\n return ret\n}\n\nfun choose(n : Long, k : Long) : Long {\n return fc(n) / (fc(k) * fc(n - k))\n}\n\nfun test() {\n val n = readLong()\n\n println((choose(n, n / 2) * fc(n/2-1) * fc(n/2-1))/2)\n\n}\n\nfun solve() {\n var tests = 1 //readInt()\n while (tests-- > 0) {\n test()\n }\n}\n\n// TEMPLATE\nfun main(args: Array) {\n reader = BufferedReader(InputStreamReader(System.`in`))\n out = PrintWriter(OutputStreamWriter(System.out))\n solve()\n out.close()\n}\n\nprivate lateinit var out: PrintWriter\nprivate lateinit var reader: BufferedReader\nprivate var tokenizer: StringTokenizer? = null\nprivate fun read(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(readLn())\n }\n return tokenizer!!.nextToken()\n}\n\nprivate fun readInt() = read().toInt()\nprivate fun readLong() = read().toLong()\nprivate fun readLn() = reader.readLine()!!\nprivate fun readInts() = readLn().split(\" \").map { it.toInt() }\nprivate fun readInts(sz: Int) = Array(sz) { readInt() }\nprivate fun readLongs() = readLn().split(\" \").map { it.toLong() }\nprivate fun readLongs(sz: Int) = Array(sz) { readLong() }\nprivate fun print(b: Boolean) = out.print(b)\nprivate fun print(i: Int) = out.print(i)\nprivate fun print(d: Double) = out.print(d)\nprivate fun print(l: Long) = out.print(l)\nprivate fun print(s: String) = out.print(s)\nprivate fun print(message: Any?) = out.print(message)\nprivate fun print(a: Array) = a.forEach { print(\"$it \") }\nprivate fun print(a: Array) = a.forEach { print(\"$it \") }\nprivate fun print(a: Collection) = a.forEach { print(\"$it \") }\nprivate fun println(b: Boolean) = out.println(b)\nprivate fun println(i: Int) = out.println(i)\nprivate fun println(d: Double) = out.println(d)\nprivate fun println(l: Long) = out.println(l)\nprivate fun println(s: String) = out.println(s)\nprivate fun println() = out.println()\nprivate fun println(message: Any?) = out.println(message)\nprivate fun println(a: Array) {\n a.forEach { print(\"$it \") }\n println()\n}\n\nprivate fun println(a: IntArray) {\n a.forEach { print(\"$it \") }\n println()\n}\n\nprivate fun println(a: Collection) {\n a.forEach { print(\"$it \") }\n println()\n}\n\nprivate fun intarr(sz: Int, v: Int = 0) = IntArray(sz) { v }\nprivate fun longarr(sz: Int, v: Long = 0) = LongArray(sz) { v }\nprivate fun intarr2d(n: Int, m: Int, v: Int = 0) = Array(n) { intarr(m, v) }\nprivate fun init(vararg elements: T) = elements\nprivate fun VI(n: Int = 0, init: Int = 0) = MutableList(n) { init }\nprivate fun VVI(n: Int = 0, m: Int = 0, init: Int = 0) = MutableList(n) { VI(m, init) }\nprivate fun , T2 : Comparable> pairCmp(): Comparator> {\n return Comparator { a, b ->\n val res = a.first.compareTo(b.first)\n if (res == 0) a.second.compareTo(b.second) else res\n }\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "646c654a3b3bf2a663c3e14c63e9fe44", "src_uid": "ad0985c56a207f76afa2ecd642f56728", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.io.BufferedReader\r\n\r\nval bin = System.`in`.bufferedReader()\r\nfun BufferedReader.readInt() = this.readLine()!!.toInt()\r\nfun BufferedReader.readInts() = this.readLine()!!.split(' ').map { it.toInt() }.toIntArray()\r\n\r\nval MA = ModuloArithmetic(1_000_000_007)\r\nfun Int.ma() = MA.ofInt(this)\r\n\r\nfun main() {\r\n val n = bin.readInt()\r\n println(solve(n))\r\n}\r\n\r\nfun solve(n: Int): IntMod = 6.ma() * 4.ma().pow((1L shl n) - 2)\r\n\r\nclass ModuloArithmetic(private val MOD: Int) {\r\n fun ofInt(x: Int) = IntMod(x, MOD)\r\n fun ofLong(x: Long) = IntMod((x % MOD).toInt(), MOD)\r\n\r\n fun precomputeFactorials(n: Int) = PrecomputedFactorials(n, MOD)\r\n\r\n fun factorial(n: Int): IntMod {\r\n var res = ofInt(1)\r\n for (i in 1..n) {\r\n res *= i\r\n }\r\n return res\r\n }\r\n\r\n /**\r\n * n choose k, picking k elements from a set of n element, without repetitions\r\n *\r\n * / n \\\r\n * | |\r\n * \\ k /\r\n */\r\n fun choose(n: Int, k: Int): IntMod {\r\n if (k > n || n <= 0) return ofInt(0)\r\n if (k == 0 || k == n) return ofInt(1)\r\n\r\n return factorial(n) / (factorial(k) * factorial(n-k))\r\n }\r\n\r\n /**\r\n * n multichoose k, i.e. picking k elements from a set of n element, *with* repetitions, order does not matter.\r\n */\r\n fun multichoose(n: Int, k: Int): IntMod = choose(n+k-1, k)\r\n\r\n /**\r\n * / n \\\r\n * | |\r\n * \\ k_1, ... k_m /\r\n *\r\n * Number of ways of putting n distinct objects into m distinct bins\r\n * with k_i objects in the i'th bin\r\n */\r\n fun multinomial(n: Int, ks: List): IntMod {\r\n var res = factorial(n)\r\n for (k in ks) {\r\n res /= factorial(k)\r\n }\r\n return res\r\n }\r\n\r\n /**\r\n * Number of distinct ways of shuffling values [vs] (distinct = some value on some position differs).\r\n */\r\n fun numWayToShuffle(vs: List): IntMod {\r\n val f = mutableMapOf()\r\n for (v in vs) {\r\n f.merge(v, 1, Int::plus)\r\n }\r\n return multinomial(vs.size, f.values.toList())\r\n }\r\n}\r\n\r\nclass IntMod(n: Int, private val MOD: Int) {\r\n val i = n % MOD\r\n\r\n fun ofInt(x: Int) = IntMod(x, MOD)\r\n fun ofLong(x: Long) = IntMod((x % MOD).toInt(), MOD)\r\n\r\n operator fun plus(other: IntMod): IntMod = IntMod(Math.floorMod(i + other.i, MOD), MOD)\r\n operator fun plus(other: Int): IntMod = this + ofInt(other)\r\n operator fun plus(other: Long): IntMod = this + ofLong(other)\r\n\r\n operator fun minus(other: IntMod): IntMod = IntMod(Math.floorMod(i - other.i, MOD), MOD)\r\n operator fun minus(other: Int): IntMod = this - ofInt(other)\r\n operator fun minus(other: Long): IntMod = this - ofLong(other)\r\n\r\n operator fun times(other: IntMod): IntMod = IntMod(Math.floorMod(i.toLong() * other.i, MOD.toLong()).toInt(), MOD)\r\n operator fun times(other: Int): IntMod = this * ofInt(other)\r\n operator fun times(other: Long): IntMod = this * ofLong(other)\r\n\r\n operator fun div(other: IntMod): IntMod = this * other.multiplicativeInverse()\r\n operator fun div(other: Int): IntMod = this / ofInt(other)\r\n operator fun div(other: Long): IntMod = this / ofLong(other)\r\n\r\n override fun toString(): String = i.toString()\r\n\r\n // i^n\r\n fun pow(n_in: Long): IntMod {\r\n var x = this\r\n var y = ofInt(1)\r\n var n = n_in\r\n // x^n\r\n while (n > 0) {\r\n if (n % 2L != 0L) y *= x\r\n n /= 2\r\n x *= x\r\n }\r\n return y\r\n }\r\n\r\n private fun multiplicativeInverse(): IntMod = pow(MOD-2L)\r\n}\r\n\r\nclass PrecomputedFactorials(val n: Int, val MOD: Int) {\r\n val fact = Array(n+1) { IntMod(1, MOD) }\r\n val invFact = Array(n+1) { IntMod(1, MOD) }\r\n\r\n init {\r\n var f = IntMod(1, MOD)\r\n for (i in 1..n) {\r\n f *= i\r\n fact[i] = f\r\n invFact[i] = IntMod(1, MOD) / f\r\n }\r\n }\r\n\r\n fun fact(i: Int) = fact[i]\r\n\r\n fun choose(n: Int, k: Int) = when {\r\n k > n -> IntMod(0, MOD)\r\n n < 0 -> IntMod(0, MOD)\r\n else -> fact[n] * invFact[n - k] * invFact[k]\r\n }\r\n\r\n fun multichoose(n: Int, k: Int) = choose(n+k-1, k)\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "4c9b9ae58173ab0dfe857590f7974a89", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "const val MOD = (1e9 + 7).toLong()\r\n\r\n\r\nfun main() {\r\n val k = readLine()!!.toLong()\r\n var ans = 6L\r\n var step = 4L\r\n for (i in 2..k) {\r\n step = (step * step) % MOD\r\n ans = (ans * step) % MOD\r\n }\r\n println(ans)\r\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "ceafb24e81cc2887ee4bcb815bf2dc07", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "// 2022.07.29 at 18:51:54 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 = 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\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 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()) // 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\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\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\nfun debug(){}\r\nconst val singleCase = true\r\nfun main(){\r\n solve.cases{\r\n val k= getint\r\n val DP = IntArray(k+1)\r\n DP[0] = 1\r\n for(i in 1..k){\r\n val old = DP[i-1]\r\n DP[i] = (4 * 4) modM old modM old\r\n }\r\n put(DP[k-1] modM 6 )\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", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "60636351ac4a1b8fdb85ba7a6ad1d635", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import kotlin.math.abs\r\n\r\nfun readInt() = readLine()!!.toInt()\r\nfun readInts() = readLine()!!.split(\" \").map { it.toInt() }\r\nfun readLong() = readLine()!!.toLong()\r\nfun readLongs() = readLine()!!.split(\" \").map { it.toLong() }\r\n\r\nfun main() {\r\n val mod = 1000000007L\r\n\r\n val k = readInt()\r\n val dp = Array(2) { Array(6) { 1L } }\r\n for (level in 2..k) {\r\n for (c in 0..5) {\r\n val cChild = (0..5).filter { it != c && it != 5 - c }\r\n\r\n dp[1][c] = cChild.sumOf { cLeft ->\r\n cChild.sumOf { cRight -> dp[0][cLeft] * dp[0][cRight] % mod }\r\n } % mod\r\n }\r\n\r\n dp.reverse()\r\n }\r\n\r\n println(dp[0].sum() % mod)\r\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "2d94628693efaf26ab6cdaa25a609e33", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7d10533398d5a84d822379bffba01514", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val abc = readLine()!!.split(\" \").map {it -> it.toInt()}\n var min = Integer.MAX_VALUE\n var minInd = -1\n for (i in 0..2) {\n if (abc[i] - i < min) {\n min = abc[i]\n minInd = i\n }\n }\n var s = 0\n for (i in 0..2) {\n s += abc[minInd] - minInd + i\n }\n println(s)\n\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "b4d40e438a4e6da684a232f6785a3885", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2d211a37eeb5e68c6041fb6982b79b9e", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "59f328a8770933b7becbd211cb2bbc83", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()\n var mass1 = readLine()!!.split(\" \").map { it.toInt() }\n var mass2 = readLine()!!.split(\" \").map { it.toInt() }\n mass1 = mass1.sorted()\n mass2 = mass2.sorted()\n var set1 = mass1.toMutableSet()\n var set2 = mass2.toSet()\n set2 = set1.intersect(set2)\n if (set2.isNotEmpty()) {\n print(set2.min()!!)\n } else\n if (mass1[0] < mass2[0]) {\n print(mass1[0].toString() + mass2[0])\n } else {\n print(mass2[0].toString() + mass1[0])\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "89bed1ce48ed0fac61fb43148e41af94", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n val m = sc.nextInt()\n val first = (1..n).map { sc.nextInt() }.sorted()\n val second = (1..m).map { sc.nextInt() }.sorted()\n\n for(i in first) {\n if( i in second){\n println(i)\n return\n }\n }\n\n println(Math.min(first[0] * 10 + second[0], second[0] * 10 + first[0]))\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "cdd577d3509c199b2ed3a67aed157c9a", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n scanner.nextLine()\n\n val ns: List = scanner.nextLine().split(\" \").map { it.toInt() }\n val ms: List = scanner.nextLine().split(\" \").map { it.toInt() }\n\n val nMin: Int = ns.min()!!\n val mMin: Int = ms.min()!!\n\n val equals: MutableList = mutableListOf()\n ns.filter { ms.contains(it) }.forEach { equals.add(it) }\n val equalsMin = equals.min()\n\n if (nMin == mMin) {\n ee(equalsMin, nMin)\n println(nMin)\n System.exit(0)\n }\n val minOfBothConcat = when {\n nMin < mMin -> \"$nMin$mMin\"\n else -> \"$mMin$nMin\"\n }.toInt()\n\n if (ms.contains(nMin)) {\n if (minOfBothConcat > nMin) {\n ee(equalsMin, nMin)\n println(nMin)\n System.exit(0)\n }\n }\n\n if (ns.contains(mMin)) {\n if (minOfBothConcat > mMin) {\n ee(equalsMin, mMin)\n println(mMin)\n System.exit(0)\n }\n }\n ee(equalsMin, minOfBothConcat)\n println(minOfBothConcat)\n}\n\nprivate fun ee(equalsMin: Int?, target: Int) {\n equalsMin?.let {\n if (target > it) {\n println(it)\n System.exit(0)\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "12b1c7dfffa71a1a7df21766877cf63f", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.InputStream\nimport java.util.*\n\nprivate class AScanner internal constructor(inputStream: InputStream = System.`in`) {\n internal val br = BufferedReader(InputStreamReader(inputStream))\n internal var st = StringTokenizer(\"\")\n\n internal fun hasNext(): Boolean {\n while (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine() ?: return false)\n return true\n }\n\n internal operator fun next() =\n if (hasNext()) st.nextToken()!!\n else throw RuntimeException(\"No tokens\")\n\n internal fun nextInt() = next().toInt()\n\n internal fun nextLong() = next().toLong()\n\n internal fun nextLine() =\n if (hasNext()) st.nextToken(\"\\n\")\n else throw RuntimeException(\"No tokens\")\n\n internal fun nextIntArray(n: Int) = IntArray(n, { nextInt() })\n\n internal fun nextLongArray(n: Int) = LongArray(n, { nextLong() })\n}\n\nfun main(args: Array) {\n val sc = AScanner()\n val n = sc.nextInt()\n val m = sc.nextInt()\n val a = sc.nextIntArray(n)\n val b = sc.nextIntArray(m)\n val ab = a.intersect(b.asIterable())\n if (ab.isEmpty()) {\n val amin = a.min()!!\n val bmin = b.min()!!\n if (amin < bmin)\n println(\"$amin$bmin\")\n else\n println(\"$bmin$amin\")\n } else {\n val x = ab.min()\n println(\"$x\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "84bfad6dccd160bc97503a0f0e5fa966", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n var scanner = Scanner(System.`in`)\n\n var n = scanner.nextLong()\n var k = scanner.nextLong()\n\n var t = n / k\n\n if (t % 2 == 0L) {\n print(\"NO\")\n } else {\n print(\"YES\")\n }\n scanner.close()\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "games"], "code_uid": "af42622a0e4775ed924a5d95ce3a9cb9", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 val q = n / k\n println(if (q % 2 == 0L) \"NO\" else \"YES\")\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}", "lang_cluster": "Kotlin", "tags": ["math", "games"], "code_uid": "b1f6f561d796cc18a97ecbb60e14b709", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun main(args : Array) {\n val scanner = Scanner(System.`in`)\n var n = scanner.nextLong()\n var k = scanner.nextLong()\n var r: Long = n/k\n print(if (r%2==1L) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "games"], "code_uid": "e7e0819a729e8a3646d23259f2e02b0e", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(args: Array) {\n val sc = Scanner()\n var n = sc.nxtLong()\n var k = sc.nxtLong()\n println(if((n/k)%2==1L)\"YES\" else \"NO\")\n}\n\nclass Scanner(){\n var br:BufferedReader?=null\n var st:StringTokenizer?=null\n init {\n br = BufferedReader(InputStreamReader(System.`in`))\n }\n private fun tokenize()\n {\n while(st==null || !st!!.hasMoreTokens())st = StringTokenizer(br!!.readLine())\n }\n fun readLine():String{\n return br!!.readLine()\n }\n fun nxt():String\n {\n tokenize()\n return st!!.nextToken()\n }\n\n fun nxtInt():Int{\n return nxt().toInt()\n }\n fun nxtDouble():Double\n {\n return nxt().toDouble()\n }\n fun nxtString():String\n {\n return nxt()\n }\n fun nxtLong():Long\n {\n return nxt().toLong()\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "games"], "code_uid": "505afc7a854ef8bc1b216c317c69c1a7", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5e3e536927a9817b9dbe250cf2e01bd8", "src_uid": "d60c8895cebcc5d0c6459238edbdb945", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9664a6d30005453df38d5869c82c2264", "src_uid": "d60c8895cebcc5d0c6459238edbdb945", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d46cc939c186046657b63db34b3e2bc1", "src_uid": "d60c8895cebcc5d0c6459238edbdb945", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "438d3bbf56e31553f34d91d3783008b3", "src_uid": "d60c8895cebcc5d0c6459238edbdb945", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (md, bk, both, total) = readLine()!!.split(\" \").map { it.toInt() }\n\n val onlyMd = md - both\n val onlyBk = bk - both\n\n if (onlyBk < 0 || onlyMd < 0) {\n println(\"-1\")\n } else {\n val losers = total - onlyBk - onlyMd - both\n\n if (losers >= 1) {\n println(losers)\n } else {\n println(\"-1\")\n }\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "b043d1ca93ab06f17c35444d43cf9053", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package codeForces.c491_2\n\nfun main(args: Array) {\n val (a, b, c, n) = readLine()!!.split(' ').map(String::toInt)\n\n if (c > a || c > b) {\n print(-1)\n return\n }\n\n if (n - (a + b - c) < 1) {\n print(-1)\n return\n }\n\n print(n - (a + b - c))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "457317a3407047ab7541e0c7d15d89d8", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (a, b, both, total) = readInts()\n val aOnly = a - both\n val bOnly = b - both\n val home = total - aOnly - bOnly - both\n print(if (aOnly < 0 || bOnly < 0 || home <= 0) -1 else home)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "fabe07475582f5dd1c71163771c64f0e", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (a, b, c, n) = readLine()!!.split(\" \").map { it.toInt() }\n var ans = 0\n\n if (a - c < 0) {\n println(-1)\n return\n }\n if (b - c < 0) {\n println(-1)\n return\n }\n ans += (a + b) - 2 * c\n ans += c\n\n if (n - ans > 0) {\n println(n - ans)\n } else {\n println(-1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "e9e122a042421e4bd9891baa140c3b3d", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n/**\n * Created by SitaoLiao on 2/17/18.\n */\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n val user_input = scanner.nextLine().split(\" \")\n\n val t = Triple(user_input[0],user_input[1],user_input[2])\n\n var h = Integer.parseInt(t.first).toLong().div(Integer.parseInt(t.third).toLong())\n\n if( Integer.parseInt(t.first).toLong().mod(Integer.parseInt(t.third).toLong()) !== 0L ){\n h += 1L\n }\n\n var w = Integer.parseInt(t.second).toLong().div(Integer.parseInt(t.third).toLong())\n\n if( Integer.parseInt(t.second).toLong().mod(Integer.parseInt(t.third).toLong()) !== 0L ){\n w += 1L\n }\n\n val ans = h*w\n\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "4980ae2832331969390f6d49ac746df0", "src_uid": "ef971874d8c4da37581336284b688517", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val input = Scanner(System.`in`);\n val n = input.nextInt()\n val m = input.nextInt()\n val a = input.nextInt()\n println(ceilDivide(n.toLong(), a.toLong()) * ceilDivide(m.toLong(), a.toLong()))\n}\n\nfun ceilDivide(positiveDividend: Long, positiveDivisor: Long): Long {\n return (positiveDividend + positiveDivisor - 1) / positiveDivisor\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "7c6ea92c8904e3fb5bc8e8080a56a413", "src_uid": "ef971874d8c4da37581336284b688517", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.OutputStreamWriter\nimport java.io.PrintWriter\n\nfun main(args: Array) {\n\n class Input(val n: Long, val m: Long, val a: Long)\n\n data class Output(val result: Long)\n\n fun BufferedReader.readInput(): Input {\n val (n, m, a) = readLine().split(' ').map(String::toLong).toLongArray()\n return Input(n, m, a)\n }\n\n fun PrintWriter.writeOutput(ret: Output) = ret.apply {\n println(result)\n flush()\n }\n\n\n fun Input.solve(): Output {\n val res = ((n + a - 1) / a) * ((m + a - 1) / a)\n return Output(res)\n }\n\n val input = BufferedReader(InputStreamReader(System.`in`))\n val output = PrintWriter(OutputStreamWriter(System.out))\n\n val test = input.readInput()\n output.writeOutput(test.solve())\n\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "1b0462fd650eccd0e4fc801b3c1eea1d", "src_uid": "ef971874d8c4da37581336284b688517", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, m, a) = readLine()!!.split(' ').map(String::toInt)\n println((if (n % a == 0) n / a else n / a + 1).toLong() * (if (m % a == 0) m / a else m / a + 1).toLong())\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "d9b79f36c66a209ad362a82a0cebde48", "src_uid": "ef971874d8c4da37581336284b688517", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(arg: Array){\n\tval n = readLine()!!.toLong()\n\tval k = readLine()!!.toLong()\n\tval A = readLine()!!.toLong()\n\tval B = readLine()!!.toLong()\n\tvar x = n\n\tvar cost: Long = 0\n\twhile(x > 1){\n\t\t//println(\"Cost: $cost. X: $x. Remainder: ${x.rem(k)}\")\n\t\tif(k == 1L){\n\t\t\tcost = A*(x-1)\n\t\t\tx = 1\n\t\t}else if(x.rem(k) != 0L){\n\t\t//\tprintln(\"Substract for ${x.rem(k) * A}\")\n\t\t\tcost += if(x>k) x.rem(k)*A else A*(x-1)\n\t\t\tx -= if(x>k) x.rem(k) else x-1\n\t\t}else{\n\t\t\tif (B < (A*(x-x/k))){\n\t\t//\t\tprintln(\"Divide\")\n\t\t\t\tcost += B\n\t\t\t\tx = x/k\n\t\t\t}else{\n\t\t//\t\tprintln(\"Substract\")\n\t\t\t\tcost += A*(x-x/k)\n\t\t\t\tx = x/k\n\t\t\t}\n\t\t}\n\t}\n\tprintln(cost)\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "99f87f8f6dbf624e43a1b9bb9ac80e0a", "src_uid": "f838fae7c98bf51cfa0b9bd158650b10", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n/**\n * \u0422\u043e\u0447\u043a\u0438 \u043d\u0430 \u043f\u0440\u044f\u043c\u043e\u0439\n */\nfun taskA() {\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}\n\n/**\n * \u041d\u0430\u0448\u0430 \u0422\u0430\u043d\u044f \u0433\u0440\u043e\u043c\u043a\u043e \u043f\u043b\u0430\u0447\u0435\u0442\n */\nfun taskB() {\n val s = Scanner(System.`in`)\n val n = s.nextLong()\n val k = s.nextLong()\n val subPrice = s.nextLong()\n val divPrice = s.nextLong()\n\n var curN = n\n var totalPrice = 0L\n while (curN != 1L) {\n val r = curN % k\n when {\n k == 1L -> {\n totalPrice = (curN - 1L) * subPrice\n curN = 1L\n }\n r == 0L -> {\n val subTotal = subPrice * (curN/k) * (k-1)\n if (subTotal < divPrice) {\n totalPrice += subTotal\n } else {\n totalPrice += divPrice\n }\n curN /= k\n }\n else -> {\n totalPrice += subPrice * r\n curN -= r\n\n // ugly check if curN under k so we could get zero\n if (curN == 0L) {\n curN = 1\n totalPrice -= subPrice\n }\n }\n }\n }\n println(totalPrice)\n}\n\nfun main(args: Array) {\n taskB()\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "e79836e04aedf7f15f9d1dcd43925a79", "src_uid": "f838fae7c98bf51cfa0b9bd158650b10", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args:Array) {\n val (n,k,A,B) = (1..4).map{ readLine()!!.toLong() }\n \n // 1\u3067\u5168\u90e8\u6d88\u5316\u3059\u308b\u3068\u304d\u306e\u30b3\u30b9\u30c8\n val step1 = (n-1)*A\n\n // deviable\u306e\u6642\u3001\u7a4d\u6975\u7684\u306b\u5272\u3063\u3066\u3044\u304f\u30a2\u30d7\u30ed\u30fc\u30c1\n // k\u306e\u500d\u6570\u30ea\u30b9\u30c8\u3092\u4f5c\u6210\u3057\u3066\u3001\u30b8\u30e3\u30f3\u30d7\u8a08\u7b97\u3092\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u304f\n var start = n \n var (dec, div) = Pair(0L,0L)\n\n val dec_div_start = mutableListOf>()\n \n while(true) {\n val amari:Long = start%k;\n dec+=amari\n start-=amari\n div++\n start = start/k\n dec_div_start.add( Triple(dec,div, start) )\n if( start < k || k == 1L) break;\n }\n if ( k != 1L ) { \n \n val step2 = dec_div_start.map { (dec, div, start) -> \n (dec+start-1)*A + (div)*B\n }.min()!!\n //println( listOf(step1, step2) )\n println( listOf(step1, step2).min())\n } else {\n println(step1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "fc58db7f691c4301e27845850f110633", "src_uid": "f838fae7c98bf51cfa0b9bd158650b10", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.math.BigInteger\nimport kotlin.math.min\n\nfun main() {\n fun readLong() = readLine()!!.toLong()\n\n var x = readLong()\n val divisor = readLong()\n val subtractCost = readLong()\n val divideCost = readLong()\n if (divisor == 1L) return print(BigInteger.valueOf(subtractCost) * BigInteger.valueOf(x - 1))\n var cost = BigInteger.ZERO\n while (x >= divisor) {\n val mod = x % divisor\n if (mod != 0L) {\n cost += BigInteger.valueOf(mod * subtractCost)\n x -= mod\n } else {\n cost += BigInteger.valueOf(min(divideCost, subtractCost * (x - x/divisor)))\n x /= divisor\n }\n }\n cost += BigInteger.valueOf(subtractCost * (x - 1))\n print(cost.toString())\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "66669c9580db5dab07c481403e775cf5", "src_uid": "f838fae7c98bf51cfa0b9bd158650b10", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n repeat(n) {\n val candies = readLine()!!.toInt()\n val arr = readLine()!!.split(\" \").mapNotNull { it.toIntOrNull() }\n AliceBobAndCandies.game(arr.toMutableList())\n }\n}\n\nobject AliceBobAndCandies {\n fun game(arr: MutableList) {\n var moves = 0\n var candiesEatenByAlice = 0\n var candiesEatenByBob = 0\n var candiesEatenLastTurn = 0\n var isAliceTurn = true\n while (arr.isNotEmpty()) {\n if (isAliceTurn) {\n // calc alice turn\n var candiesEatenThisTurn = arr.first()\n arr.removeAt(0)\n while (arr.isNotEmpty() && candiesEatenThisTurn < candiesEatenLastTurn + 1) {\n candiesEatenThisTurn += arr.first()\n arr.removeAt(0)\n }\n candiesEatenLastTurn = candiesEatenThisTurn\n candiesEatenByAlice += candiesEatenThisTurn\n isAliceTurn = false\n } else {\n // calc bob turn\n var candiesEatenThisTurn = arr.last()\n arr.removeAt(arr.lastIndex)\n while (arr.isNotEmpty() && candiesEatenThisTurn < candiesEatenLastTurn + 1) {\n candiesEatenThisTurn += arr.last()\n arr.removeAt(arr.lastIndex)\n }\n candiesEatenLastTurn = candiesEatenThisTurn\n candiesEatenByBob += candiesEatenThisTurn\n isAliceTurn = true\n }\n moves++\n }\n println(\"$moves $candiesEatenByAlice $candiesEatenByBob\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "eb00083b09f683687abe057f4ec3038f", "src_uid": "d70ee6d3574e0f2cac3c683729e2979d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\nfun main(){\n var sc = Scanner(System.`in`)\n var t = sc.nextInt()\n while(t-->0){\n var n = sc.nextInt()\n val a = Array(n) {sc.nextInt()}\n var start = 0\n var end = n-1\n var alice = 0\n var bob = 0\n var moves = 0\n var sum1 = 0\n var sum2 = 0\n while(start<=end){\n var cur = 0\n while(start<=end && cur<=sum2){\n cur+=a[start]\n start++\n }\n \n moves++\n alice+=cur\n sum1 = cur\n cur = 0\n if(start>end){\n break\n }\n \n \n while(start<=end && cur<=sum1){\n cur+=a[end]\n end--\n }\n \n moves++\n bob+=cur\n sum2 = cur\n \n \n }\n \n println(\"${moves} ${alice} ${bob}\")\n \n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "161f1518696724cb3ec814072dc8635e", "src_uid": "d70ee6d3574e0f2cac3c683729e2979d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private fun solve(){\n val nn = readLine()!!.toInt()\n val aa = readLine()!!.split(\" \").map{it.toInt()}\n var moves=0; var asum=0; var bsum=0; var prevv=0; var ll=0; var rr=nn-1;\n while (ll<=rr) {\n if(ll<=rr) {\n moves++\n var cur=0\n while (ll<=rr && cur<=prevv) cur += aa[ll++]\n asum+=cur\n prevv=cur\n }\n if(ll<=rr){\n moves++\n var cur=0\n while (ll<=rr && cur<=prevv) cur += aa[rr--]\n bsum+=cur\n prevv=cur\n }\n }\n println(\"$moves $asum $bsum\")\n}\n \nfun main(){\n var T = readLine()!!.toInt()\n while(T-->0) solve()\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "b934fd5c8c3a0b8e17f1767b58cc029f", "src_uid": "d70ee6d3574e0f2cac3c683729e2979d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n repeat(readLine()!!.toInt()){\n var n = readLine()!!.toInt()\n var s = readLine()!!.split(\" \").map{ it.toInt() }.toIntArray()\n var a=-1\n var b=n\n var sa=0\n var sb=0\n var aa=0\n var bb=0\n var cnt=0\n while (b-a>1){\n cnt++\n sa=0\n while (sa<=sb&&b-a>1){\n a++\n sa+=s[a]\n }\n aa+=sa\n if (b-a<=1)\n break\n cnt++\n sb=0\n while (sb<=sa&&b-a>1){\n b--\n sb+=s[b]\n }\n bb+=sb\n }\n println(\"$cnt $aa $bb\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "87e1d23a7c77e02da858fcd018fdf1b7", "src_uid": "d70ee6d3574e0f2cac3c683729e2979d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val fly = readInts()\n val otherFly = readInts()\n for (pos in 0 until 3) if (fly[pos] == otherFly[pos]) return print(\"YES\")\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "58e041dfccebdd1a9c193d0ec6f10fe5", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package codeforces.com.tasks.task4A\n\nfun main() {\n val weight = readLine()!!.toInt()\n val lastBit = weight shr 32 and 1\n print(if (weight > 2 && lastBit == 0) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "6faab60c22d5618bb326cc4825be8d0e", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package codeforces.com.tasks.archive.task4A\n\nfun main() {\n val weight = readLine()!!.toInt()\n val lastBit = weight and 1\n print(if (weight > 2 && lastBit == 0) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "0a06e911df858abe72175b24d680f15e", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n\n\n val reader = Scanner(System.`in`)\n\n var integer:Int = reader.nextInt()\n if(integer%2 == 0 && integer!=2){\n print(\"Yes\")\n }\n else{\n print(\"No\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "39ddb3faefbee5d77e12368cb570541e", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner;\n \nfun main(){\n var sc = Scanner(System.`in`)\n var a = sc.nextInt()\n if(a % 2 == 0 && a > 2)\n print(\"YES\")\n else\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "a4fed113846e8943d13c3aa0faad5d40", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "//import java.math.BigInteger\r\n//\r\n//fun main() {\r\n// val n = readLine()!!.toInt()\r\n// val dp0 = Array(n + 1) { Array(n + 1) { BigInteger.ZERO } }\r\n// val dp1 = Array(n + 1) { Array(n + 1) { BigInteger.ZERO } }\r\n// val dp2 = Array(n + 1) { Array(n + 1) { BigInteger.ZERO } }\r\n// dp0[0][0] = BigInteger.ONE\r\n// dp1[0][0] = BigInteger.ONE\r\n// dp2[0][0] = BigInteger.ONE\r\n// dp0[1][1] = BigInteger.ONE\r\n// dp1[1][1] = BigInteger.ONE\r\n// dp2[1][0] = BigInteger.ONE\r\n// val c = Array(2 * n + 1) { Array(2 * n + 1) { BigInteger.ZERO } }\r\n// c[0][0] = BigInteger.ONE\r\n// for (i in 1..2 * n) {\r\n// c[i][0] = BigInteger.ONE\r\n// c[i][i] = BigInteger.ONE\r\n// for (j in 1 until i) {\r\n// c[i][j] = c[i - 1][j] + c[i - 1][j - 1]\r\n// }\r\n// }\r\n// for (cnt in 2..n) {\r\n// for (left in 0 until cnt) {\r\n// val right = cnt - 1 - left\r\n// for (la in 0..left) {\r\n// for (ra in 0..right) {\r\n// dp0[cnt][la + ra + 1] += dp1[left][la] * dp1[right][ra] * c[ra + la][ra]\r\n// dp1[cnt][la + ra + 1] += dp2[left][la] * dp1[right][ra] * c[ra + la][ra]\r\n// dp2[cnt][la + ra + 1] += dp2[left][la] * dp2[right][ra] * c[ra + la][ra]\r\n// }\r\n// }\r\n// }\r\n// println(\"\\\"${dp0[cnt].reduce { a, bigInteger -> a + bigInteger }}\\\", \")\r\n// }\r\n//}\r\n\r\nfun main() {\r\n val ans = \"\"\"\u000f\r\n\u000f\r\n\u0010\r\n\u0014\r\n\"\r\n\\\r\n\u0011:\r\n\u001e^\r\ngJ\r\n\u0013\u001fR\r\n.\"N\r\n\u0010\u001cCJ\r\n\u001d\u007f\u00146\r\n\u000f\u001c=L\u0016\r\n\u0017\u0017\u001d%b\r\nYp_\u0016^\r\n\u0014P;q+J\r\nK\u001fR\u0013\u001b*\r\n\u0013d1\u001e\"\u0015\u0012\r\nHE;I5\"\u000e\r\n\u0014\u0016\u00152k\u001c\u0012^\r\nOE\u001f?'#^>\r\n\u0015.6C\u0018knH&\r\nbR]fLIX)\"\r\n\u0018\u001a\u0014X\u0018%Icj\u000e\r\n\u000f&bE.#`\u001aF5R\r\n\u001decE*\u00113f#W:\r\n\u0010\u0015qV+/\\'Og`6\r\n*\u00112\u000e2p\u000efP \u0019\"\r\n\u0011f5\u001eVl9N<\u000f_Tf\r\nE(AVC>R:U._\u001aN\r\n\u0016\u0014pqI\u007f;(V8gpOJ\r\n\u000f\"a+`\"\u001fAF\u007f\u001f\u001a\u001b`6\r\n Ci\u0019Ihe]0JCc\u0018D\u0016\r\n\u0010i(\u0012]%G&V/KD&.1b\r\n<`EF\u000fT&j*\u0016\u001c\u0013+q\u001e^\r\n\u0015Sf_G]RM\u001f,Sc)A+cJ\r\n\u000f+3hd7OPXce\u0013Kf\"pg*\r\n\u007f#\u0010B2=g\u001d\u0019-\u0015X6YO7\u0011\u0012\r\n\u0011g*K<]h0oWc\u001c\u0015*J?\u001fZ\u000e\r\nSLnmW\u001647h>d^\u000f`aha\u000e^\r\n\u001aT1+\u0016[*)L\u0010-9*cj\\f\u0010Z>\r\n\u00102+jEl0#\u000f\u001bqVTqo]\u001a\u001cFX&\r\n:]7\u001f:_7F>a5h,mIE#f\u0016a\"\r\n\u0016O\u000eq_:+KK^b\u001cM*\u0017[\u001c1_h\u0016\u000e\r\n\u000fT\u0017?\u0019; _\u001bU'R+kmgk\u0016N\u001c\u0014\u001dR\r\n0\u0012K\u000f/VWn\u00157JnTQ,m[b\u0015XK\u0017:\r\n\u0014k7*M\u000ei(\u0012\u001cW3\u0010b%\u0011\u0016d\u0019\u000fM\u0018\\6\r\n\u000f9O(o6G+\u0018'7&9\u0013W:c@Q9a ee\"\r\n,(\u001b*el4c5pYgB)gcQ\u0011\u0015=^U7\u0014f\r\n\u0014>\u000e\u000f/\u0017M^\u001c!\u001f]&\"Lh\u001e6\u0016TE\u001eAeRN\r\n\u000f7\u000eTn\u0014^N91a,ZZDVc\u0013N\u0015d%c7P\u000fJ\r\n-\u001f\u001c\u001cgL7L<\u0011\u0017\u0018\u000e#[,\u001e\u001d\u0018@=\u000eULC 6\r\n\u0014qa[L1\u0010FF)\u0014:pPLmC&`2 lm=N\u0015@\u0016\r\n\u000fIC\u0012X@D]aC,YeJ\u001f7h\\[1j\",Ha58\u0019b\r\n2i,.PPY98eFS\u00162@%AH;\u0015U/Z\u0012b\u001b6j^\r\n\u0016PY\u0010#*QJ1CVZD?\u00166]+g\u001eWQdR3\u007fa\u007f_J\r\n\u0010\u0014>\u0010OY%W\u0018\u0011-h\u007f\u007f\u0017MY\u000eh`>9?AgQQ8k;*\r\n?g \u001d*m)\u001aG1M%\u007fiZ\u0014J\u0014\\\u001d\u001c\u000f3ae(kN#q\u0012\r\n\u001a\u007f?\u0012H\u001680lF)\u0012\u0016<\u00141\"&f>\u001fU8:\\\u0018\u0017 g;j\u000e\r\n\u0011\u0011RkS'\u0014_\u0014\u001cRg#Q*BC\u0014TF_d:\u0017#if\u0013JF\u001bF^\r\nZ\r\n!A-5*4;oL)j_>Ahin*2*\u0016\u001e+\u0012\u001edPKN4 2h&\r\n\u0013\u0012?kN?Z\\?\u0018BVLc9\u007fTG3\u0011[\u00170\u007fg/-l N?SE5\"\r\n\u000f.\u001b\u000f&Si6\u0017 \u0010QeG\u0019Bah&N\r\n\u000fGe+?m. oSc@\\/[1QOPdc1<6RQ(@LNV3C V)O%'3J\r\n;E ^\u0016\u001fNVE_57\u007f5hk\u000f;X&\u001a4>\u0016fABE9g>HV_\\,\u0017=\u000eD6\r\n\u001b+2#\u000f\u007f,\"6\u0010EWN\u000f4Rk<\u001d\u0015]8\u0013p3LS\u007f\u0017\"\u0011;\u0011\u001bRPRhoj<\u0016\r\n\u0011j/%MoJ^5i\u001fp>4cqhnl=\u0019@kJcn\u000fiU(\u001cO(^2\u0010\u001fTpZ0R^\r\n1.#`5\u001a1#g\u0018S1W\u001e>\u000f848O+=j;d3jU]L\u0013;\u001c7VXJWcB69[J\r\n\u0018[%\u001f!%\u001a/NM]\"A\u0010[TW3\u001f \u0011H\"\u0016\u0015\u0012H16iP1F_\u0016qGID92QZ\u000f*\r\n\u0011.\u0012k\u0013\u0013A -NO\u001bEU\u001a\\)TEd06+F(19QG.3II'_0lMD\u0015\u0010\u001bj\\m\u0012\r\n\u000f\u00119HB'9@IXS\u0014dp8pGXP\u000e9g08@9\u001fC9\u0013EZpc` \\3Th[c+@Z\u001a0`A\u00134\u0019\u0010/R cj\u001a^\r\n\u001817\"OU.4h\u007fB\u000fg:Hnb&#il%]n\r\n\u0011.N8OVi.7A\u00114\u0019)G\u0017m9[\u0016=\u007f6)qMh_o\u001d/:R3\u0013lSP5\u001d\u0015h9'V`/\u0014&\r\n\u000f\u0015lN*km\u0011\u001e>\u007f\u001coFM\u000fik0._\u001eOE[\u007fcL*-.\u0014aC:(TL^J\u000fWT\u001ei5WWm\"\r\n13iS1R\u0012\u0010p>./MHXg?L\u0016&&\u001c\u001298Q(^\u007f\u00163D\u000e\u001aSZd)U\u000e4ga\u000f\u0010!\\L6\u000e\r\n\u0019TocaaqoXEl.\u001b+\"MiF#N\u0012h-\u0018T,6\u0019\u0013.[\u0017%.Mk\u001cBES\u0018->!45n3CQR\r\n\u0011i0gbg9*\u0017lT\u001c^6(+>WBc\"@\u001c\u001fbe\u007f[j\u0017^SaN3q\u0014%.\u00187\u007fZWI9VN.A_:\r\n\u000f.\u0013&?Z?5\u0019q[\u0013\u001e&\u0018n:3eMe+\u000f&\"\u000e\"boUXoTmDaf\u0014mf\\# @\u00108Q:\u0015IZT6\r\n:p-9:*,g?@*'\u001fZ`@8i*pH.-'\"333%`\u0012#q5q'\"Y\u0018hKn0J\u001aPR\u000fQJi5\"\r\n\u001d<\\)mV\\h\u007f7iW\u000e bB\u001ag\u0011\u0016\u0017\u0016-P50Q;A9\u001af\u001eY@\u001ef]YTcilX0]#)KUOX(A4AW\u00100fm(>\u0010`0\\! YZ^B]G>?6[JJYpiYe\u001d\u001bEh6\r\n%TB[1#)\u007f F`\u0013e/\u0014_J)i\u0014P7qEi1\u000e\u0019L\u000f1C]\u0018B pi-\u001eMq\u0013R&l%5V1lS\u000e@O8\u0016\r\n\u0016C\u0011 \u001fXC*8Ib3KW\u0017\"Jb@^(H\u000e\u0011\u0019/\u0019qc_\u007fp\u0012RO\u001d\u0017qIiZGM\u000e\u0017\\;NGBYh%7aSMb\r\n\u0011\u0017QgG\u0012W=\u0012f0A?Ihah\u0015C jWJ\r\n7g >>-\u001f\u0018_?\u001c(N&!*pdK\u001a*\u001d:VPObo\u0010\u007fP^oE\u0015fn\u001b\u0017\u001f9\u001b95Bj/^+NV'\\F8oE\u0017_GC&'WDG]X\u0011`:O\u001bV\u0015h*,\u001a(G4&\u000e\r\n\u0010\u007f .6Xp`oDG\u007f\u0011\u0011\u0015l_[7KpmF)J8\u001fRR\u000f\u001dfC9+K\u0013\u0014gZXLeS\u001c4 _\u001bMh\r\n.S\\Ga[\u007fmD^UXB\u007fH[_bq\u001b+HT\u001f\u000eWq)L[\u00152)\u00148EFoT%,\u001b\u0013\u001aRhSD\u00182\u00152eA\u000fYnb@p\\;\u007f&\r\n\u001aSa\u007f@F\u000e\r\n\u000fn!\"\u007fTT9\u0013:;\u000eNiWLDl\u001dZA\u001chRc0-\u0018c\u0019GP[iW#'hY\u007f`O8=,6Q\u0013QZ<\u001a\u0019\u0018T^Yn)a*BK+I9R\r\n\\\u0012\u001bq\u001bE\u0013%g(bjB,9Rb&d\u001a\u007f`\u000f4\\kGg'R\u001a f>\u001bAX*qEn9Xd6k`5)!I\u000efA\\C9<\u0012/^#\u0016\u000f-\u001f:\r\n-*]k!>\u0013:coVn->Sm?\u007f\u00131(o3\u0011:\u001fj, f`PQ;Y7UN>:D VP\u0012?R\u000eF.\u0017\u0013\u000e\u001dfYl]+Z\u0018^\u0011\u0019pGP6\r\n\u001aN\u001fjDod\u007f[Q^d\u0010-9\u0010[h+X)U(2\u0016DDT<_lB;SGpD\u001abKXBU3)hk6IE\u001a\u0017#'\u0018:\u0013M2&A\u007fTI@p\u007f0I!\" a\u0015\u0014 43_L\">?=\u001cf\r\n\u0010\u0019!I\u0012IE\u001fKTd\u0011\u0012('g*)\u001b-l\u001cEX\u001eHjW`&\u001f<\u0019B\u001dk\u0019\u0018eGfVRBbo\u001aMK@!_OGd4D3(\u001d\u001cCJ\u0014](Q0a2N\r\ne-\u001fH2K\u001dS)co3 4I+Yh\u001b.'\u0012NC`n1g\u0017\u0010QaM h(8BiD\u001bi\u0019@#*h\u0015K=HW7JZjg\u001b\u001b@2kdIBng&\"\u0017J\r\n22_*k5\u001an\u0016ng/q%Ik8(]RX\u0015@4*JK]\u001ddUN5 YZGb6VmF\u000eNo+&ZF4\u00118&6F%'KcU@\u001d4/Q?nkH!(6\r\n\u001d(\u001eUZM) \u000el\u0015+bM!MNW\u001aNU,B\u001f?[eG)ci_UQdNgT+>I&5di\u0015a\u0011aTfV\u0014Ke&'<\u001a \u001d5\u0018P C\u001a\u001cDL(4\u0016\r\n\u0014;!\u001cR9BLjAQQPfmOL\u001c`\\\u001a'o#\u0010K:g\u0015b94\"_jq\"\u001e\u000e6nPP@\u000fGa@79\u00191#\u001fa\u001acR\u0012=Jd\u000fW4?)Ze5b\r\n\u0010XYq ([;4A3\"U)bICU LEl\u0013>kU3PQp6\u0010k'\u0019O4i\u007fO8pD\u0011.*])81l8\u001eX%\u001e\u001ee\u0016,dhIl\u001a\"N_NMV\\\"^\r\n\u000f\u001fd\u0017\u000e\u007f\u0010\u000e5,o\u0011\u0011,/CL4\u0014A\u0014 >JO!(\u001bT\u001fSA\u00100QQLP%\u001f> MCj5R+pU2@R0h\u001b-.LOg^7OHG\u001fdSYp\u001cSSJ\r\n@j)\u001cIi1g-j8\u001e'NS-nSGD-AGd5p\u001a-O>i`]P#\u0019\u0013oVP/4<^k\u001d>q\u0016Sf\u001e(A\u00100\u0018\\f9=gb&K\u001f68\u0010\u0014U\\\u0014\u0013\u001b*\r\n\u007f\u001di:k>OU'\u001cE \u001cTS4]B\\ETO\u0019gIjk=\u001ck%Q P+\u00187n=\u0012\u0015=\"e\u0012\r\n\u0017U\u0019\u0015Vgj(. dI%k\"\u00142;U>-H2N\u000eFeFED9\\f\u0017J\u0016?'\u001dQ%n\u0016Q\\60P=N\"\u001dfA65eF'#\u0015IjP4-53Xq\u0014!\u0010)#\u00106\u000e\r\n\u0012*H\"\"W\u001bYc\u001f&Pe*noCA;j\u000f\u007f^?1l+'%O\u0011)no\u001b(n8\\FV=@\u0013WM8\u000e2-?\u0017+T)*@le]%Tf_eF\u0012%\u001d\u0011^*\"\u0019\u0016\u007fk&^\r\n\u000fh3b?%=\u0010Jq6>\r\nc%9d\u000fTC6 c\u001a\"b\u0014m\u0010Ri7>'U21<*;G?^\u001d/*7FUD\u000eo\\Uab1\u001eNdid:\u001aR\u0016cCg:\u001fp`QB=]\u000f/Q\u00169K(8ZRN,\\W4&\r\n46;@j<[WK.qGn6Bl:\u0011i+91-FFmaK,\u001b\u0019\u0018b&f\u000f2m4\"=V\u0019@\u007f+m+?X9\u0011>\u001e@\u0010\u001aBEl\u0016O/:\\Mo_nN*Y'\u000f\u00129\\\u0010)\u0015\"\r\n\u001f8\u007f>_%:+\"]^\u0018\u000ea(*!CY\u00127B!O<\"W&gACYTA\u001e\u0013\u001bn'V\u001bFU74HV[Cp+_\\%\u0014-\u000f\u001b\u001a\u001bX&i\u001aph;( 2>>Q\u00130\u001c/0l\u0014V\u000e\r\n\u0015mU+\u0018k/->I:4\u000e1.\"Y\u001f7\u000e\u007fLM5\u0015?\u0011IGS(n:OH&\"\u0017V0e\u0011:f#n,\u0011)o\u0010oep\u001a;7NNB)D ^e<\u001c;\u001cBa6\u001c`\u001eG\u007fZ'RC!R\r\n\u0011Od\u001c2\u001108g\u001e1M\u001b,DJ\u007f=\u0018GXG\u000fjc(\u001a\u000eh!\u001a5163SY(eIj8E4\u000eb5a)c\u0018>d@\u0017\u0013OJ\\*\u001bXcfJ\"0\\;?+@;W[)j\u0018G%fO\u001a:f\u0017TH=S\u0012K1N\u001aR8H@f\r\n\u001fh'&QH^\u0018)[MW0E*\u001eq\u001bkP_\u007f*cNgK`E]iHcA;f\u0019?SC M\u0012\u0012\".m\u001f\u0012g9#UU\u000f]\u0011H \":IN/\"\u007fbojl7aP)\u001eq8:F\\_+ZhL6\r\n\u000fhi\"T8\u0019+Mj\u00152\u0014\u000fG\u0012Di'!F\"\u0014Y\u001a#c&5c[K\u0019\"?EO\u001fO\u001b,Z\u00155#IGL\u001dQa^\u0014LEW]\u0017c\u0018\u0011\u001ebn9q@bO\u0015Pa8V\u000eDm0N\u001a[\u000f1 NZ\u000e!\u0018>45g\u0015N.S\u000e\u001c\\3\u0012+eD8^7\u0017O\u001af5F5\u007f^3\u001c:nL)n^\r\n\u007f\u0016L\u001fn\u001fNd\"\u001f\u001fD\u001a\u000e55j>VS;c]\u0012(\u0015S3\u0017L\u001a_j\u001f=J%XOJ\r\n\u0018gJg+6\u000eBCShZW8e\u000fj0\u0013B\u001boT\u001fgFR\u00151p\u001e^\u0015+qJ\\k&NM\u00176\u001b@';h\u0010ajE\\GR^gi&YP&+iPg.j9[A2\u0011..Z\u001b.\u000eC6n?g\u0015\u001d5#\u001c!AS*\r\n\u00136cH+J&@\u001dc5\u00144'\u0011!NCMN,\u001fa0R\u001b]f=4\u0014g__*\u007fAjT_0?)E\u0011!WQJQ@\u0013[^F5\\,-5#&*M9pcY_b.;)\u0010Jc%\"V*\u001af\u001c!%&K\u001eT\u001f3\u0013a\u0012\r\n\u0010T\u0018PF\u0017J\u0017S4\u0019\\H\u007f\u000e#ehj3I\u0013D>>9YaDg[Tq/#\u0016b@!'o`\u00115pk*9k9]PC3D>\u001cc6\u001179\u001efG\u0010\"(F4)E\u0012ZMo\u001dp\u001dNYe?dT3e>\u000eaO_\\F\u000e\r\n\u000f1U\u00135U\u0019]\u001eG\u0011BP-\u001b)q:@1+nS\u001f\u000eOb!#T4l\u001b\u0019Op&&l\u001f?\u0012YQ@\u0012G;\u001aO\u001b`?Cc_%<`g\u001chhKR+\u001b%\u001e%4fNWf;C;p\u0016nT\u001f30k9MSIO?\u007f\u001d^^\r\nRII\u001d)\u001ek,T1\u0010c\u001d\r\n0emm&\u0019Mq\u00189*[%:8\u000eS4Jk/n6K,i\u0018o0?Wa8j\u000e\u000eB^_\u001bn\u001f\u0012\u0011+e]O9Y6#-/a\u0011bpnHk]q\u001eFfA 7\"\"X4H\u000f\u0011hl'J!me4Z\u0010:\u00108% FEE\u001fD&\r\n\u001fb\u0016=O'bj9Mc7g*!OO#de\u0010P4N\u0017^.(Q>GO3\u0017hI^\u001c\u001f\u00129-5\u0011<%\u0015-n\u0015^`QO4P\u001d\"\u001eFf5\u0010o?c\u0010dI\u001e&&\u0013\u0013WK-+BS@-\u0014\u00116kLLQIe8]f\u0010KM\"\r\n\u0017\u001fkVT26.gk?\u007fFf\u001d>i]\u00153\u0019:YL:Ch\u0011 fERYZ\u0010U\u0016gpCgXo\u0010@C@DP*['Wb&\u0014`QeJh6^GD7-\u0011(YRW*\\aV/EE?4bV\u001d,-\u001dH-Jj\u0015>9\u0013\u0019,f\u000e\r\n\u0012Y\u0013`\u001d/\u0011f!jY\u007f\u0010\\?TR';\u000eU\\0gj\u0019\u000f\u0017\u0017eiJ fc8e\u000fi`\u000e`T\u001f*Rd\u001ciJ\u0016C\u0016S\u0010I\u001ank\u0012dX8+Z\u0011SPf\u001b6;\u007f\u0014DjCj0j\u001d.^\u001f.>O\u0017[qU\u0018_+b2X0mR\r\n\u0010=*Lj@b1C\u0011\u001a)\u0017p3\u0014%)\u0018\"*\u001c\u001e4\u0011\u001a^4+j^\u000e;mgN\u0015>J\u001cX\u001c5KW\u001a0_;#\u0014\u001eXP)`-\\GISp\"[K8ob=QTV50NC3\u0014?;O\u000f\u0019*\u0017&\u007f#R?TpiP\u001c6i\\Gg:\r\n\u000f+\u000e#e0Ra#I,U\u0013FQ\"\r\n2\u0018\u00101X\u0019\u001a,g6Dh4O\\XD\u000f)=aNHoi\u007fH\"OU\u001f\u0014@\u0015&bp<\u001bf;4\u001c50=q>[f\u0018-!4TibWi:>54f8\u0016)'V_1\u0010Gdf\r\n!\u007fD&N\u0011Xa\u001366OR6\u007f\u0015IZN\r\n\u0018+LS\u001b5 Sg/%cmM6qQZ5Qgh ,\u0016U?[&`Q\u0010\u0014_\u0019-Q%Bikb@\u00115\u001bd;\u0016MZB`&BQZM0d][\u0014Hq5oKYSdm\u000e\u001a\u001b_n+AJMbOFip!C#%8XYcKQ_FEa\u0010*`_J\r\n\u0013D@Ia\u0018\u0011d\u001f\u001eo`L\u0011\u0016\u0017d\u00102Bjd\u001f\\\u001d%Mkb f\u000eU)\u001a\u001a#[]\u001d?qnUa'EYj\u0010A2\u000e\"K'kZ,XFkMB?d<*/\u001bNe%\u001a:JM`*KF2\"g\u00191FV\u0010jo\u007fg!16\u000eA\u001e%,fOSp6\r\n\u0011\u000e*hj\u001b>QgN\\<2_Y;?%@h@[\u000f<\u000fk/Ai=8n6;CF\u0017%I=[mE5-n+5%\u001f?R1G\u000f/\u0017V7N\\p\u001f/OLKXo(3^mmY#\u0018NC.LYeXM!-&XA\u0012MlQb)\u0012FQ.>e@\u007f\u001a,\u0016\r\n\u000fMAZ54]J0i_;\u001b8GZ5Ui?N\u001b-K!io\u0011U<5Of[>S\u001chbe'\u00172B7!n.YQ8hqEF_ \"+,8\u007f__%5HOn25VVE\\7+)PO-j:\u000e#7\u007fq\u0012B`Wh\u007f2C.9%\u0011'n98O,ib\r\ngBm4Zc]g ?Q?#\u001a#\"D\u0015QI\u001bi[R\u0016\u0010&=l\u000e`a55\u0010\u0010lJ\u001f\u0010**P+P\u0019fTL%Q\u001bpM!\"`Yebc2\u0014mRD4)bn.\u0012)6\u00139\u00172G4NZ\u0010X9W6i_12T\u0015n\u0011Q\u0013Z\u001d\u00180p'&a+V^\r\n?*Q!j\u0014oW3?V8I\u0013&8 8FOc\u0013\\ E\u00161CC,j*ND\u001bG\u001b[\u001c\u001cT\u0014Ra\u000fFI&hOa:g4\u001d0Qhl^QaN*V\u0017\"\u0016X6\u000f*J\u0010)[gJX\u001d\u0015@_]\u001dH6\u007f\u007f\u0015_bqZl_\u007f&C?emae\u001a8\u0015KJ\r\n))oP7\u001f\u001e!\u001d43V]\u000e5q\u0016c2&h9_E\u001fP\u007f?7S0MZ.p?\u0012[B_M\u00178\"-WF0^?\u000e(\u0018EeU&\u001d+i\u0013\u0019R\u0018\u001cDB\\P3(-elX\u000f\u0019\u0015c\u001fU?c\u0012\u001fjWUF\u0010iB/@WfkF\u001a*5XUG\u0012&C>_\u001c16_)^:P]\u0012\r\n\u0016?)\u000eal4\u0014E,a_?5?P,o;qYU:hb*W`Q\u0016VK0:E2h_?Rh\u000e,gF\u00137-\u00148>o\u001bb\u0018':\\CJL+\u000fm\u001fQ\u001d\u0014D4H7Jqe839-OG9SE\u001f%/;8=@S\u001a\u001aGD3jW0AfE\u001b&`+B=PV\u000e\r\n\u0012[O\u007fGL\"19\u0011Q\u0013<\u0015\u0012fT \u000f(#K9Um2D?9\u0014.0j(\u0017d\u0010_\u001bEnN!\u0014K^lE#PkL6Bc\u0016\u001bI\u0019\u000f7\u0011pNbagnmF8<\u000e.jWUj0(8,&qM?Dkp6\u000e=oM\u001a]=61o#QcNc\u0018gq)Sd2^\r\n\u0010T\u0014>cS1S/gkYqL\u0014\u0017AW:Hbp\u0017=\u001c?'+B%T/?(?\u0018\u0018U\u0011E\u007fjR'/ZA.\u001a\u0016o\u0019f+P\u001f\u0016\u001eo\u001c#[@C\"\u001b@\u0018M1i#\u0011\u0014\u0010\u0017\u0011[1B6\u001amW^jl\u001b!\u001a'\u0016jPV\\)RbJo7Y4\u0017jR-\u0019\u001dJYV>\r\n\u000fC?WCSYMnJ\u001ab\u001e+]pE\u001ahWkP>\u001cS\u0011P\u00125H\u001b&\u007f\u0015O\u000e]NT_W%C)QSNEN_eoMTl=8:nO*)k%Dbc>TWdb@\u001b\u001bJ\u0012\u001cO\u0013G.\u001f:Ql*\u001ciFU[\u0016*\u001a1QZHE\u0018a#@*mlY\u001b\u000f-][T&\r\neSk_\u007f\u0019+0\u007fN\u0016#.I* 1=Q;3\u000f-?_%\u00196]bbUQ\u0019\u0016_b&^ %j\u0015\u0010hWO1Vi_ccPk(;\u0015&n%\u0012\u000e\r\n+\u0015B\u000e0`6VM+gDF//dT!-\u0010/Yl0?\u001b\u001f6X\u001c)h'\u001cFHh\u000f*O_,MD\"?=Hk[8e;MH\u001cQT1*S)JeI08B@5\u000f\u001b,f1G\u001b2\u0019%,]l]\u0016&DEMM3_.H\u001d5&3B-H_\u0019Lc!P-\u007fi4dgQ\u0012UR\r\n\u001ee\u0012F\u001dWY5'H;\u001ap\u007f\u00161bf=O3K\u0016\u001c16\u001cJK17Rk'MGd\u00139\u0013ndMq\u0012[V8dJ\u0010NJ4\u0014?U^6\u0013\u0010Zg7/\u0014\"#\u000e\u0010V7F7Ed'^)',`b\u001b]\u001aZ\u00108\u00187\u0016\"h!B;IJ72\u000f)f\u0014RaHL\\OW>\u0018\u0019\u0013':\r\n\u0017aeV0h\\=Mf\u001f\u001d\u0011`'\u000ebT3:Y@a3,m..=5\u000f`A:\u001e\u0013TH\u0011N\u0018,j&R_^*C\u000f\u0012F1#\u0018Y/b1:.6!@aZ?Q.mND:D1\u000e;EB8dATmn\u000eqi&[\u000e3\">kT[\u0010\u001c>\u000fW\u0013Y'VY)kd\u001eOd)4jjD6\r\n\u0013ZT+\u0014[\")9\\MPTm\u00188UU=\u0014\u001e.]a\u001aJ\u0013Z\u00117\u0015.Pl>UeT?F[>:\u0011gA\u0011TS?\u001c\u0012B/5\"=\u001bB(\u000f@l^H'm\u00164;\"\u0015J\u001e4U_\u001c)BK%*\u0014\u001dDjLJ\u001dRn\u0011>\u001bnJ\u0015\u00125N_2ag_\u0012\u0016lS4Gp7;\u0011!D9\"\r\n\u00115X\u0016l6.;ZF\"BU.!^7=\u0015\u0017*ZcQ\u0015eAUR<0\u00127\\>:J7\u0018H\u007f_\u007f Sb5A7C\\fT.\u0014fUJ\u0018\u001bq(m [.Po0lD\u0019\u0019#,C\u0015\u0012-_ Ec[\u001b]bg6nf6\\j3Mn]`[\u0014 '\\\\A/lb\u001ch`oo\u001f>c\u0017;\u007ff\r\n\u0010\u000f\u001c\\P\u0016\u001bmB\u000e\u001f.\u000e]9\u0017'\u0011B]j)9\u001b\u0012-B0\u001f\u001fH\u0014F\"8dC\u001cd0Q-&WVDA G\u001dE\u0010W?D3FH])K,)\u001f!SL[m\u0018qH^j-78\u001fIOd\u0015Z!\\Lfq\u0014K58Li\u0018og\u0013\u0014?+7i\u0010JI\u007fe?k\u001c[\u0016oelB9>\u0010@G4/m[X*LAVOM\u0012F3UVk-I\u00153-g_!\u000eV.a\u00128\u007fV&=>O5LP6\\jMVJ@P(#a=GA5iYJOO^\u0018JL\u000f8b7A\u0013Dg ih[\u001cF \u000fE\u0012Nj\u0011g_.#5\u0013kh;\u0019AI)0,p`Q\u0019%RY\u001f\u0016n:\u000f\u001d@G\u00147l)N\u001421X*5_hdfO/)kMC.USqj/?Ma>^\r\n\u0017Ja\u0019\"_G1\u0013C?@3Sgl[,4mi 2:aAIOX>- 36+`Vb'\u0015DL\u0010_\u000fIc\u0017\u0010\u0015CYm\u001d\u0017\u001cZc\u001dAD0p[?\u001d\u0019\u001c>Q?Idn*P5;7ON\u000fOU;Ek>GDm\"Y\u0011]S`/F\u0018\\q.mB(N\u000f!(]LG\u000eqn\u00183#5M9)ORGJ\r\n\u0013fQkj\u00155A0MNP;\u0013W1i*\u000fc\u001a*\u0018W'E2\u000fgO:J?q\u00189%\u007f\u0011nTW-2fH\u0013\u0012M\u0012)\u0010\u0015\u001e\u0016J\u0012\u0018-IFS9Yj#nU\u0012e-`3/[\\)\u0013nHU^T\u000f<#*<\u0012\u0017p\u001aGA\u00181&+ 1c\u0013\u0018=9He(4+\\\u0011M\u0019>'8gA k;W31\u0016_*\r\n\u0011L5i_-pF<\u001dZd[-\u00149]\u0012\u001f8\\DMP:G49\u00192M*X<&n2Fk0L\u0018J4XC_cl_SF/A/Z;\u000eoi!PnF3,\u0013 QPG#U,\u000f\"p/^#_\u001di\u001c\u000fa\u001b^\\-kHX%,\u001bT4+U\u0018_q\"'i\u001c\"8Ci\u0014:\u0019\u0012k0WQ#'\u0013X%;\u0010\u0011Y\u0012\r\n\u0010&\u001e\u001c\u001e3p\u0010].\u0014\\-\u001a?3_W\\=^\u0015=)F:[<\u000e\u001b\"@%D_G#7jFK@,F3D\u0012\u001c701RMGf;j6>j^;\u007fXo\u0010?d4\u001ch\u00184UR\u0015'\u0015bgUT\"np^\u001eq4'#Mq']72mG\"2\u000e\u001cDH\u00175\u001d\u000f:\u0017\u0019d4,C-CM\u001d\u0011;Q6]#(Pf\u000e\r\n\u000f5-\"#EQp\u001bZT;\u0018+\u0011]#j\u0018\u0019CLY1T\u001c\u001dQ?6:E`% O\u0015\u007fi\u001e\u0018 M'\"mS6RF3\u00131Q.d;*Z,\u000f)?7?L.&\u001b5T?kbIQ&\u001c c>>A\u001c4\u0019`\u000f:j\u001257\u000e^%P\u0010g2*\\3F\\%7/\u001a4GTgR<.2p\u0013\u0011(0c5DO>L\u0012j^\r\ndp]mm\u001b)F*<\u0015d?='1\u001c=+06q9bA15eK/j]edcN0\"Fi%\u007f2D+a]BdTQj%?-5;\u007f\u0014';_WI[\u0013\u0016:\u0015JR6^\u001a%MRII6,Va#9\u0019%\u0010]Z8]MC*#3'2QJ\u0013c\u007f\u0010cQY0JEMm\u0015C=\u0016cgU?:IL9\u000e pmf>\r\nDG\u0018%\u001fX\u001fZ9b\u001a`]=k[T\u00130q?6/\u000eN&O&F*gWL\u0019:Z\"H6q7Wia) kZ\u001b#\u0015l*5.qR\u0015]7/\u0014(h)\u007f'h(qq6UM\u000fA9476UE2k'\u000e\u0016Na?\u0010)#K2\u0016:\u001a'C BX\u0013?5Y\u0010o(!\u0015)JL\u000fD]_A7?:c=DTh&Cd&\r\n058QKq*L\u001cch!.da\u0013*?\u007fj\u0014d\u0010\u0010f]b@n\u001eG42af9615@:]S]ACBM%3D4C_U\u0017-\u001c@GC^\u0019\u001fh\u0010\u007fHoO\u000eE=\u001fZ\u000e/=7'K93Qk\u0016kb\u001eq0\u0014f?H\u007fS\\R7\u0011-#V=3`G\u001d=\\4mO\u000e?+6W3jK\u000e;q\\\u0013;&\u001dS\u001d\u0011LC\\\u0012T#/'.\u001042\u0011/(0\u001eG\u001b:^J&,iG!M<]RY:a\"\u000e\r\n\u001bc/@# ?6DV^,G`8@\u001f;O+1q\\-HPJ\u007f(S-&l01\u0015<\u001ciY+_'\u001c26\u001eT:o\"S\u0011SOI^CONTLm4\u001aW\u00113N#HiR04cQ(=\u0019@/Wm\u001b\\ZK5\u001el[.fS7\u001aER)id\u001d[R?d)PL=R\r\n\u0016c)EV8+\u0016n=,;\u0015N1E/A^Wg\u001fc6\\QM`&RW7](oN8ie\u001bC88BIYOM\u001e,.\u000fbbAoeK\\\u0010N\u0019 R3'Ea\u001e\u001f\u001a\"8j9I.@68,H7W\u0019\u0013\u007f?!H\\+A-IqG[).m\u0019-,AN4\u0010o2<`XI;fa\u0011VD[Mkf\u001bo2L]P9 \u007f\u0016K:\r\n\u0013R,;2TMSB\") =\u0015V\u0018T=)\u001bL\u0017b[1YY\u001aAJpZQ`@\u007fLWe\u001bL]%o\u00135\u00101FD/7Jn+<\u0015l%fl\\*G)d*\u001f\u000f\"oTTT\u001f\"3,\u00199\u0014D5 6a<=;!f>q6J+T5+\u0018GM\u0014m%\u0011^-0M\u001b6A/o\u0014\u0013\u001d#k0_\u0018.\u001eaWqBZ\u0019?APjj^&&'+m`Qn-J2#\u0011\u000fWb\u0016\u001486\\0\u0014CJ^6\u001b\\\u001eUG\u0019V^\u001606E\u0013T5LQn*\u0015pT5;+\u0019i&Ne`;Z/o\u0015\u0014J\u0014[cq(UNo(S61Z6!\"\r\n\u001036\u0016[K!/\u0011/G?& \u00185o;\u00114cC\u001b=iM6\u0018aq6(e\u001c8[S1,P]3d\u001b>\u000e>L:dF\u0019\u001d6^NDf\u000eL(.gk/\u0018HAE\".=)F7\u007f\u0017\u0015' S6!\u0011\u00100\u0019qVAH \u00103i)\u0019UocT\u00129H\u0010(\\`\u001f^7S_\u001a\u0018M!g\u0011Vi.*E13*#\u001bCJ\r\nP*KM)Gig\u000f4'c!=J\u001e6B22X\u0018(U\u00154Id3\u0014STi\u001d\\\u0014OQ;.\u000e\u007fR\u000eP2\"R'jFF\u0010\"*.5EGSQ\u001d\u000fTc56 /0 ]\u0012BY(D[\u0011@DZOnj[K\u0012\u0019M,qa82P\u000e\u0010?+\u001aEU+B]!PiF\u0010\u0014N\u000fQLXi;\u0013?\u0011No@\u007f\u0016\r\n*m\u0016\u0017<\u001b\"3POoVb^\u0015Q=e\"jR\u001a^&\u001aNLQA\u0018g*\u001f,bP@D>h.'@W\\Q\\o2Rf[\u0019-\u0011.\u0015,6S?Yo?!OHCR%9]K\u0011 9b\r\n!'h\u0014.\u0010_\u001fUf;m6#SkeF>T\u000eE4'hK1D:YY*#cU'acU'5k-\u0013\u001e%\u0015U_C`2D)Q1?qOA=72DdNIT\u0017Sp\u0012E)FA\u0013\u0014lf\u0019I\u0010A\u0014\"J,W\u000fE.hGeB 0=J>TO`dU=\u0017l]aX?\u0016\u0012\u000eJVb_: \u0013\u001dc+Z4\u0013>l\u000e&(_EAiVZ-g&^\r\n\u001adYh\u0018Td+q\u001d1UJZUCUU-G#'I\u0013!Bp7-b/U/pT8>\"X,n-\u0017\u0014d4?aQJ\u0019@?o>]_\u0011&A><[9N\u0012:`=\u0011%U@/8;'a#_\u001a26*Wk&+66g#\u001bC/HM8\u0012QnQ'%EbY.T\u0010bAfTQU&(8(d!M8q&XYKQ&cU\u00131\\Q\u0013\u0010\u001f;9gVV#\\.Bll\u0018pFLG4f;\u0017q(^a9,IM\u0015WAc4Vk23!3*\r\n\u0013_i\u001e,F+)Bm_S9\u0014'eQU.d=n]?\u0017;d`mh6QO/\u0012\u0018L\u0011\u000fJHAU\u001dI\u001bbY8mDD=]S7=\u0017=\u00197\u001eU\u0012\r\n\u0011kc4\u0013c[[!TPopE\u0016^:KdD-gL5j\u007fa\u0014L\u001aUR\"\"P\\g+\u0017?\\W7Y[ \u0019`k\u001a\u0011/\u000e\u001ed\u0010]7%EMD\"p0i**f7\\ngH-U-e_h4_ `[\u001aR=A\u001d l: *SQ\u0011d.0EKjUhd\u0017*gT1QQ\u001eF\u0018\u0011@8_ @\u001chN\u007f)h#\u000fL6Mh6\u000f([])Dl,(]\u0012\u000e\r\n\u0010QU\u0018>9.f4qF9:9F7i9T<\"\u0017`\\:p;1-63i`DA\u001dD\u000e\u0014\u000e.oH%/1fIQJ8\u0011?h\u001fbO&\u001cJDS-#3O]Jq[^\u0017)]enq\u001epRi(\u0015^%D>a\"l!2\"\u000f* \\k\u001d =h\u001e.\u001dR\u001c*9\u0016\u001c\u007f6jA,mkR2lU>^\r\n\u000f`X0,k\u0013K`L>\u0012+(;5l2/\u0015\u007f\u001c!\u001d,=.k\u0015&W&Sp\u001aF\u0015Y!knBK\r\n\u000f')\u001d`Qf\u0010\u001cfc[4bd-F\u0018p8Xh\u0010=C,\u0011@n\u0016!6#,\u0016>;L\u0011\u001d\"9FV@@@gc\u001aNC\u001d7\u000eh?NG\u001eCg\u0019Le\u0015&1`ac(\u001cZd`\u0018m\u0016U?\u0015\u007fKPo_\u0019@aA\u0018Kqf\u0016K\u001d\u001f1\u0016pS\u001e\u0010V\\X7LM\u001f8\u0010\u0014Z4U\u00116fi\u00129!\u001aA#g,\u0017\u0018ZYP\u0016lLb]%/MR76mT\u001b)\u00180\u0011f`\u001cQoq&R\u0018MTq\u001e[\u000f\u0019k\u000e1\u000fb0b.OZIE\u0011+Rl!+@Rl\u00171J\u0018&RLP#S\u001f\\?>\u0017-'h6](h56*DKkF-qn.KgLXFae>=\u0017'Z\u0011o-\"\r\nIK1*\u0016XPg*>'Y\u0017oQlY?n\u001c=id,\u0017\u0019Y:* pN*K7f,:3.2mM[0d\u007f9\u0010<4`\u0015i_(c\u001d?I&hKZFU\u001b*h-Y[.37&G\u00104?S\"\u0012\u0013nA3[HST\" \u001f!ZmV\u001a51** gF# E\u0012SGF..4ID6pg\u0017YB\u0010*!<4\u0013,(b0_@\u001eR\u0016T8\u0010Jj)A*gP:;/'I`^!\u000e\u0013S./7k\u0016%R\r\n*bAi\u007f\u0017a,fcU_\u007fAA.#(=/.!]Y?\u001aA\"\u001b\u001a=9P\u0013e1Z4.\u001d\u001b J\u0010[\u000edp]Zj+\u000f\u0014\u001d%=-\u001abC)AYD=\u001c@[Vhn\u000e\u007f\u001c.=_I0>dp\"3R&\u001a81d \u001bLMXc\u001a1\u0011\u0019TE\u0019\u000eG/\u007f\u0014@\u0012oL9\"g1\u00117\u001b3-;n&/\u007f=W\u001a)\u0014je)WRaKC\u001e\u001aE*U?\u0019+04D>'b\u001a7Zo&8&\u001b\u000f;\u001dB?EqN\u0011\"#\u001f95\u0015)/\u001b)\u0018@\"4i(]jTnA_SVCCjL\u0018\"N8\u000e#\u0013C\u000e,\"9/A)\u001f*2\u0014c^\u001bR@\u000fN@E\u001f8<6\r\n\u001c mmbQQ\u0010SK-\u001f[!g RY(-9\u001cc\u0011P\u001bmPD?:\u001bI\u000fq0Z_Jl#NK?0Uk^_!`\u007f\u000eh\u000eIqE\\)+d[\u0018\u0016;\u001e\u0018N4[%p)\u0016\u000e!!VBRl?G\u0016p&Bg)_\u0019\u001f%'\u001eA\"OPV\u0015/%\u001b(4\u0018b\u0017\u0016\"M:`\u0015^.3^\u00191OXc2DSV\u001bm\"\r\n\u0018\u000f0d_WR \u001b\u0019[k.Q]FG%^)Z!TU\u001dB\u0019QYC;qq4NC4F4\\P\u0011@Io\u001fl,\u001bO%4qe\\5OAW\u0013B1&]?e3N+\u0018d\u000fm>5(>\u007f\u001c01GqP\u00152qZjb\u00181<]\u000fZ!NS8\u001e/8>:\u0012\u001f!T]J*Q8*T\u001bY`#\u0011)V+3b\u007faalf\r\n\u0015\u0017B>&\u001ed==\u001d6:JE\u0019_d+`>M,W\u001a6lnEM\u0018_R..0\u0015D\u001c\u001447(5k#\\Ieb?!\u007fBQ_Jo>\u000e`dD`Hd<*d!\u001f,\u001e\u0018oR\u00110\u0010\"\u0017_Vn\u0012,U>oG'&m.m32\u0019,%c\u00105?>D7fQ\u0018o6m\u0010D:fBCI\u0013\\n\u001eN\r\n\u0013\u0012\\Y>iO\u007f;\u001dH_/-M\u0015B\u001dE1\u0017\u001biLAX EF\"^cY\u0017R\\@h.NXP=VWWq\u0015Rq%.\u0019h#a(\u0018D?&C\u0010,\u001c\u0011\u001cMQQ^5iS1B\\6%,\u001bYXF0RNQ91M?;+%\u0013f)>\u0018=FeB/MUoc[RS\\\u001d]!5;\u000fZN0Tn T`B;Gd\u001bT<7l#X( T6a\u001e&*5\u001ej6=\u0010S_\u0014iFD\u0019F\u001af[-cBVqD_8qT]'l\u001da/2q(^8mCR\u000fI#.*io\u0016Re;A\u001aF\u00146\r\n\u0010HJ2P2m6C`N`@\u0012?PiG\u000f*\u001bBAhnGT^heY _GW\u0010B \u0011.:g@5\u0017SDP\u0013k>*@\u001dAX>E\u00137n\u000e\u0012k87()D64W[\u007f\u000fhjgB)P4P5e#K;Elid5p\u001eSJH8>USK\u0015A/nqUFoNf]Gi\u0017\u0015cin-?\u001e@%E\u0015QDP@WeEQ-?V/>,/aoD\u001eY\u0017`QQ/%goC8\u001dQh*:\u00107\u00196 W%\u001e\u0017L\u0017&@'U?\u000f2GR?O\u0019I'`Lg6\"n9=:\u0012\u0016=\\Thj0GAH=0XD\u001di\u0019],)U-j#o4\u00113\u001c\u001d=\u000e^\r\noT:+KZOnA\u007f\u001b\u0014XVf\u001fb468*K=KP\u0013T(1+^\u000ef[j*2D)\\W)EE6E=o.GT;b\u0014TV>^`\u0016eT_U\u0017kD\u001f!\u0015e?^\u0014]=\u0012\u007f/\u0012cMbgp\\N\u0010n!3Mch/DjI.\u0017RFl\u000f1\u0016Q`EQ\u00113\u0011Y^V#/9=p*8-pU6\u001d\u0010\u001fk*\r\nB\u0015pHWpO2Bbj=oI71X\u0017WO?\u0012\u0015XQ\u000e#LWa*F\u001624%SW\u007fqWH5giV2n!\"`\u007fV\u0012(Ue\u0016/!9j\u0011*:DK+\u001c\u001cgg*^\u001d4&dDP%\u007fa\u001a\u0013\u0017:\u0015L*-l\u0013Q\u0012\r\n4&R\u001eUP>EV\u0018jW:\u001f[\u0014\u0018j1\u001akF\\:N\u000f\u0016H\u0014=`*\u001aW=K3/\u0010DFbb*a,80@G1@m\u0012jSEK+Dn\u001a\u0014>j?8\u0017K\u001b>\u0012>\u0017\u0018m\u001ep\u0011Ua\u001d`4=`\u007f-B\u0018Z'\u000f:.j\u001b\u0016YN\u0019nJOLmQ Y^\u000e+q\u001bL\\o?J\u0017jgB9RGA\u0016\"*U'Y\u0018Zh^=\u001cKF\u0011\"\u000e\r\n*!X\u0016p\u0019[(@,(%\u00155X\u0018/S\u0011\u0013 :5]Qc5Ea#W(a>_Lo\u0010e\u001aio\u001a5M[U\u001d^9ed\u00133(QcPI\u0011b\\)_6\u0017\u001e#a=HUTaF1R,]\u001c>&-\u0011\u0011`*ha3O+dQ3W\u0016j6\u00121\u001eZDM\u007fGm\u000f/\u001aY'PJI\u001e LS\u0013\u0010D`Z\\4i4`Y32\\N*3cW\u001c-&&m)Fg\u00189FZC\u001cY\u0015lb*^#hq3Md\u0012^\r\n\"di\u001e\u0014g(k9*VX%F[\u007f\u001e^I\u0017B#3\u0019666b\u0018c-cDWO+\u0011D\u001e5)CK8/Y\u007f;!\u0011]Ac!p)a'Z\u0011U0P\u0010\u0010:\u0011%gq&Yk0,cDa \u0010/C!\u001eW\u0014\u0017`35 -#\u0019_GiXk\u001bdnD\u007fl\u0010@P0mDjB\u001e\u000f\u00169:`\\%646:7\u001fM&ET;6>\u0015a\u0013\u001ci9P+k\u007fb\r\n\u001d@@&\u0014\u007f2QIh'V5VBT!jl\u0017)g.45TGi\u0014ER\\cJ0;F\u001b1=W'\u000e\\\u0010\u0012\u0012+@ H1%\u000fXq\u0015N=\u0013ND\u0010ke7Fhg]\u001a\u001b>Y\u0011*G=G,\u0014\u0014\u001ee\u001fDL\u001b_bKYI\u000eq\u000eL\u001aQ\u0016\u001djF\"nn-M2LD &\r\n\u0019F5V\u0019UI4\u0017N-#/a0e\u0012\u0011n\u001foeA n_?(8GJM\u001a#&S6T\u0011\u001cXe\u0015\u000em\u0019PW8\u007f \u0018qi%QY6\u0014-hBb.LP8Tm-J_5\u001bf+!QH,\u001bXjU]Ohp80a*@G#hJ`\u000e\u0015kSd*\u001c#'PVJg\u00149\u001af^*FjQ<**MZQmo@%<\u0010%\u001aQCc.3>f8\u000eS7,ToJI 5m,k\u0010TV-#JI7j\u007fY.g\u007f`hMKXVD67(\u0017o/j\u007fj\u001f\u0015B\u000e\r\n\u0014@NY7\u001e@\u0015*4&>FVHgZ0D8^B\u001b\u0013\u000f\u0013M<3P\u001dM%:\u001dcp!nhS\"E\"_*TaC^4\u001cjEDFIR!D7Zo:^nGUmh!\u0016/%S2XhFeP\u0019@*+m \u0012F^,_\u001dQG\u001e2V\u001cDR*GD\u0011e9WmM7kjJT>o\u0013A>\u000eeNL7f\u001eT\u001f?\u001fBic\"&b62>\u000e)4X\u0014\u0017Y\"*\\k!g\u000e.F/\u001b\u0019\u0019\u001bX \u0019aUP7qR\r\n\u0012ha@g6JcN+&NX\u001a7X.Xc:\u0013*Ue'0VAT-\\&@\u0010kHc\u0018Jgh8QL;h0o[\u0010'Li%Tpl>n8\u00191\u0011F[E5\u001b8\u001eG3O/\u0011*fSR\u001fH\u0016\u001b\u0015(\u00158)7p&\u00199/LK\u007fC:\u0019>%H;e5>*ggL#YWGa7B,; \u001d\u001e\u000f\u0019!abnS\u0013p^Pg,P\u001d!U\u0018\u001fUh\u001d<<65?\u0019&4hT=\u001d/;!Z\u0015\u0018*Gc\\OV)a/:\r\n\u0011UQ<\u001c+o+5^X'_AJ&G,\u001bP\u0017 ,#ELpV\u0015%\u007f+OdL3T\u0018Z\u0016ed&o6 \u0016d\u001f\u001aP'P';4\u0018\u000e\u001cLd==\u00120HIn'\u000f+.Uc\u001d%\u007fSg\u0018#-?R\u001bN(0[TWA\u0015M\u0018\"RN9q!c=B\u0012=\u007f*g0dI\u0017\u0015 !I;\u0011=O/L/(\u001d]^p\u0017U\u001fe\u001dPFVGR\u001f,3\u0014Xq\u000e\u000f:\u001eYH\"&^HHI&\u00191,f\r\n\u000fO\u00126\u001dJ>\u0013<-Ph.>q\"enBgRC\u001a6\u001d\u000f\u0016\u0013XkL(BFpY-\u0014[\u0018%2,e49D%mN\u0012\u007f\"\"\u001aqK-\u0017FHh\u007f^?lC'HJBM9\u000f/G=\u001d\u000f\u000f&bj\u0014<8'neKW\u001a]fg\u0016!&h\u0019P?l*L\u001c1V\u0013b3:JCRXo\u00119Fh&*bELO\"\u0011 B\u001a\u0015M`B=R\u0010n5Q/\u0017GGW\"II;YUL_T\u001fM_V?DL0[eK8\u001dZ\u0014;\u0011(PVN\r\n\u000f(c?9\u0017Tp\u001d\u0010=/?\u0014(/YmIO\u001fb6\u0013`2\"]a8X(?\u0018\u0011C[U\u0017Bgh\u001dJ\"^=l\u0013\u0011b\u0018!G/BhfZWY`I\u007f\u0017Sq\u000eP\u007fpChp@7Q86\r\nY[=q%9K\u0013FgE;W\u007f\u0011R\u0010T\u0019(\u0015P8iW(&,_pL2\u001a\u0017Rab_D1]\u007f)U\u001a5*goZ^NX!O[6Fi%FqF]a\u001b2E\u0016\u007fp\u0012\u001d\u001cE\u001a\u0012X\u001e0)Cf%3\u0013%qhUn#ERgppL'S'Q]<:o`Qld:\u001c%#^RjI\u007f\u0015+]A@\u001e(\u007f\u0014U=\u001d\u000fO\u0018oE\u001b4Be\":OEIA\u0013 \u001fj!\"*Jl\u00166\u001c\u0016\r\nHfV3-co\u00180']*PT\u0015DL>n`j\u001c;\u0017\u007f2lo`pCS0\u001aCq*qS:I4\u0016f=E>nhY!_pU\u0013D\u0019#8)=V7Rf\u0013\u007f@;U\u001b\u001dUE\u0017d\u0018VA5j#Kn H+-:(C'_\u001aG[K^&(maj1C?\"dUV9+iSAea3lE\u007f\u0019@Y\u0012K.U]Gg\u001f\u001cG(cMUD?43N&2\u0011&V\u007fFa.:c\u0019,\u001a%\u001cH\u001f\u000eP&/HFWOQ]>PN_P(?mb\r\n;k\u0012,?\\\u0017:m6;G6ZY\u001e/c\u001cc1H<2\u0019CmXhh)*VC];M'\u0018M!BY\u0019L@_IG9\u001eBa\u007fK\u0015^R\u0013!Y0\u007fh\u0018S<`8\u001b\u000eM\u0018h;N7cmb\\3Fh2\u007f\u0015\u001b?R??27Z\u000fJ*e_\u001cn\u001dG;/\u007f\u0017\u00153_l#D1n\u001bkL\u0013*@%MT083j)S\u0017\u001c8am%!-\u001foWRb\u0019\u001dbmhWMqX,i\u0019VCFc2I\u001ac+:9BX)Z8FZ^\r\n1m==32p*=#\u0012\u0019^Ph1\u001e*\u0015]p\u000fM]^dD\u001b3UNf>h\\Ub\u0013(\u000f.Z@kq0]&=jMJV\u0015Na\u00136\u001c\u0017cY*L/\u001aP7\u0014\u0019IopG\u000f%i @=N3Kj\u0014)kR`WMh\u001aC\\j45[I2BdjR^3f7o\u0019ca,\u001d\u0019JI\u007f\u000e:\u001fV)'\u000epXO1nR8I\u0011H1'\u001fHg>#7G\u001fcNK3AJD_*!;J\r\n*&Z!&>9=2T;^1c;+B->(\u000eM99c:NqBpg\u001f3N\u0011;+.CiR%)f+@^?\u0018X;UpN\u0014\u0014bf\u0015\u0011\u00131]\u001b;Mi<\u001cF\u00181;I,\u000f+\u0015\u001fb\u001eU,`F8c:XgB5@%?k\u000fN\u001bUf)Be]*M]j;F\u0010n5>L\u0010\u001b\u0014)p5%Y/ES>U8PUh'^C\u0018R#L0MT8l^ \u001b:\u0019@qk\"c*]G#[*=\u0019\u0019\u001a\\EaBlk4(?,\"\u0016E?,\u0012?*\r\n\u007f)'pL,c+\u0013F\u000e*2X@61'\u000f\u0011p+\\`-\u0016C<'^8S,O`h,0;7:\u001dH\u000e\u00133C,F\u001c4'9R%\"0d\u001foY_\u000e4= >?%1[O\u0019Cd\u0012C@jZ\\GOLX'R)\")^79gOZ[WnR\u0013\"\u001ddKR,`\u007fEZ& q\u001e-U9?da\u001fL J]XV?\u0017Na\u0013gi)o\u007fY#\u0017K\u001d\u001b,Zp?)lI\u001c\u000e2Ug6\u0010:a.l)\u0013.\\]Rc#-B^\u001c`E\\(.\u0018jTM\u0012\r\n\u001fL;\u00145\u0015`+\u0018Y=G%\u001d:D\u000e&*H_`XL\"g./\u001e->6g\u0014H+#Yj\u001e\u0015#\u001f5Hh)\u001dHXh\u0012\u000eJ%\u0011l\u0019Wq\u007f%Ah\u0012I:k3iZ:-X\u001f\u0014b\u007fa\u0011e&mTKqc\u001f0%L[ \"5j)Haj)\u001fB\u000f\\0_)0Ip\u0017l\u001f#knX[+a\u001dK6\u0017\u001cNN\u001a&Y8gC\u000e9\u0016\u00172A(\u001eUi:5:;\u001c\u000f='P)#ZJRJDZi\\E=SKY\\&n4\u001c#\u007f52\u000e\r\n\u001bqM\u001d3@;Qk\u001fPZ\u00196/o]\u000fER\u0012I\u0015\u001eCVC\u0010\u0019hdd@J\u0019pV2\u0010j\u00141p/\u0014\u0012GfR4:cV7i!J=\u001f\u0015[b\u0017&##\u0012\"\u00121:UgU9i,;-)jceY,4Fo\u001bW\u0011\u0012g\u0012mfSJ^\r\n\u0019\u001d<\u007f'%\u001al+g`9nl9!QQo*=%\u000f)Mb8XiL[Q(4g&H?()\u0016khI\u001a:>\u000f0\u0011:pd\u001epd\u0019f\u00170d] Z9)aG]);o;A\u0019JB:q'JaklgX?\"\\]\u0013SpE!UN\u000eAI(kL=>2?N%*\u0019j\u001ci2\u0014H\u001b:\u000f\u0013!ihT>9lJ 5D/\u0012\\4\u001dV5\u001a)1h!*9eJ# K\u001d5\u0016c4U\u001fH=ZmdpjcpNA36\u001bG\u0010 \"?Yg\u0017.E\u0011db2>\r\n\u0016j\u001c%N1)O\u0014\u000f0\u001bjn?/OR6B\u0012 \u000e6?\u0015Ml+]\u0013E\"'fJ9Bo55%kX\u001c(\u0010D`XD-\u00158Gf\u000e_1LnqB<-\u007f0-\u0018\u001dWIJ)9iCB@Dqe\u00137poD<\u0016/]\u0018AU\u0016\u001elajmg\u001am9]!\u001a\u0015\u001a-\u001b\u00144@&8[B6NqHX\u0010\u0015\u0019'q(I!Zq1E[!\u0012aO\u007f\u0017gOeCPW;`+R;q\\0&\r\n\u0015\u001e\u00130\u0010(bqZ4Iq7-h9c\u001a!!\u001a )!<\u0016K;V^(-I.\u001cZ'GH6XV^e/*=m.8_iRM/Vj@igK&\u0010\u0018\u0019*:QjM#\u0019 O,/\u0011j \u0016M3Dio6R\u0011*:13Z\u0010\u0013Ff\u000e\u000ekknV=qW\u0018[OAG\".UR\u000e\r\n\u0012P\u001e;KEW<%G\u0014B/*jKXa86YDU6\u0014jW\u0013dq\\/52DH4??k6dpbF2 \u0017\u000e\u0016:7\u0011c] k\u00173\u0016 51\u0015A\u0011Q%_Y)'Z\u0016lC(3N\u0016lo)bJfnNfFE2P.I\"H\u00182\u0012p\u001c\u000fg(.j/3:Lg?4-D..n(@\u0018U\u0017\u001b\u0017L\u0017q\u001ah*HNlY\u0017M\u001d14\u001bSF\u0010&?@\u001eX\\i#Ce?\u0015(f!XSD6#i5\u0011#(,H;9B`'*E%28*5bC\u0012\u0014MYR\r\n\u0011\\\u0018(5hqY@:RhSIe3\u001ciG[j WTXjb\u000f\u001bH \u00168?jilm[MZY,hD\u0011C*0\u0012.?[7gdY]!m&6*P\u000e;I/28B%\u0017a\"nA<]\u0011L[(\u0014@IZ,4L3\"0eRjg!]p%\\\\;\u001dR\u0018\u0012n\u0012T;Nf5O%/CM\u0012\u0018\"\u001e,%1\u0018=\u0015\u0014GkfV\u0012GE\u000f\\9\\'lP2U7p93R=\u0011:&\u001aIE:HhZE\u001aj\u0013)S&N;gk\u000e&\u0018b`=oB55\u0011M*.bU\u0015<\u001aH\u001a_:\"pR[\u0012oj.\u0016F\u0012S\u0018+=gL!:gb_\u0013/(^\u000e\u0015aW*2FNQ[J':ml9@\"dEnS\u0019i@;\u0014Y-1H\u001a:mo4)\u0012Y<.\u001aZ\u000ej6TjELFajZJ05K*+hB\u000e.%lh?D'k9mVoQ\u0017g_\u0016Xi'\u0012\u001e\u0019YRg9'd1UP0(O\u000f\u001a\u0015\u001eW\"mJ,1V\u001f,\u0014)?A5\u007fS^b1>j5\"46\r\n\u0010A01)# 6\u001fa]YS\u0010ql0ldSh,L!8n.kf\u0015Rl]?f1,\u001b2l\u001c_o\u001dfCO1\u0016g\u001fJ\"I\u000ej\u001e\u007fflH\u00150:O6='\u0013C1&\u0015q5\u0018KcU/ZO\u0012&\u000eS\u001fI\u001b_;o\u007fHmo\u0010\"`cY@\u0012@^SFiOC\u001ad\u001c\\3S,/\"qH(D-(7_\u000e\u001a\\\u00117.\u0011\u001e2>MI5B\u0016E\u001a>!X\u001dM,.?fj?4+U/\u000e\u0012-1\u001e,qm\\R0\u0012AW&q@_A_?\u0014\u001d\u000en[lj#Z;N'=\"\r\n\u0010\u0013pdqkMF i7^pWnC<\u001fl&kacX46fm\u0015.\u0011^FEW\u001a;),P!X4\u001eWD<\u00191gpUVQ\u001aU:m\u0017\u001cG(.5\u001e,i.K^ie^;JS\u001cg38\u000e^hBiZ;N5io2@\u0018\u007fhhF>]^l5d\u001cRQ-kqBN3 JY*W,,\u0015g\u001bh\u0019/e7mR=_\u0012JM\u0014mGi=aeO)\u000fQ?qc#L\u001d%\u0019\u000f!\u007fQGk&/+2`=^\u0016mMA^MVBl&\u0012(Z@9OPVE\u000eIG]2\u0013XPf\r\n\u000fS5a\u00134D\u001c\u001eHN]Ah\\U%c\u0010\u007fDXq?V*Z5o\"@'(>k%K\u00127\u0014&'cehh*-h,\u0013g*FMj_\u0011'-\u000e\u0019Vm\u001cmf?'X\u007fF2\u0018\u0012\u0018FH9\u001eeVVG+4\u0018`#Tl_*&BB\u0019B?We&`Ukkm\\p\\)>74c\u0015o\u0018\u0016\u0017BRFTaS;=-b+N\u001b\u000f4\u001eE\">)\u0014\u001e5=(,o;T%k\u000f\u0013%Zj+#1X\u007f\u001f\u0018+NgDUV6\u0012qY8O\u000f F*b!E,\u0017\u0012l_/L8Y\u001f1/*N\r\n\u000f5\\:I2\u007flW\u000f\u001bbi1/V\u007f\u0018\u000e2e\u001b\u000ePJq\u0018P\"\u0015U @c_^A\u001dU\u001c\u00146gNU:7N/'ihb\u0017)!\"4e\u0010\u001c\u0010\u0018SDe-TTZ`h(<\u001af\u0015S&/\u0012\u0019Q('Hj\u007fXC#BBQ%a^*\u0014*&\u0019O\"a\u001cp43d%=mQf\u001e\u001bQ55^\u0018qa\u001120jJ2\u001ek.@\\+nH7*g-g!4'`_P+&dY\u0018\u001e3M3]UD7jbCU-8E*o'^ea^GAT+6J\u001a6\u0013Ak\u0015#VaZPF\u007f+!^,jWG\"O@h\u0011gN\u0010\u0010\u001a\u001aO\u0019\u0018G**A8pAW)=b3of9aomiW\u001eRdAOb\u001fK*_B G'HW'8=\u007fUHq\"Ko\"d\\6\r\nn\u001dc\\gco! nIpX\u001aIO(di^p\u0014\u001c&\u001a2n\u0012[QLQ\u0015\u001cU%cn_\"P35L\u007f\\C\u0017X\u001d\u0013NFI\u000ed5/\u0017\u0013#A\u001b&5`\\RE\u000fp^\u001a^-c\u001eC\u0012(pAJWKY+DGJ!]AWUV6a3\u0014%f>.\u001bCD.Bg\"2m@4no@iX4;2`6n\u000f6pYA\\+@[`IlW\u00101b\u0010\u0013\u001a'e';*1'?\u0010\u0014 5comX%1@#X^HY#&0ieQcFCq*.WR\u0012XbQ\u0018p\u00163\u001824N(\u0012Y6Z:M,<^e\u007fL)PI\u00193c1\u000eP\u001eO 5aDVo'36-6l/-_&T`\u0010\u0015Qn\u000f+^&\\_2)':=\u001b\u0010Om\u000ffMU eqK#=B\u0011(\u000f\u007fPB#S\u0010/XAo\u001f\u001bh\u0011;D9X\u007fa#Q<8<\\H)#hC\u001c\u0016`\u001cp=m\u0019!@37\u001a.\u000f\u0016H%+\u001b0\u001a\u00175\u0010QRVCNLk\u001d.O3_'I+RJ\u0010Z56%\u0015\u0013-M5\u00118/360Xko@gmIAK.i)R\u001e>E&\u0014\u007f\u001d\u001cWkpd!\u0014\u0012?1&0pooh*-cb\u0012\\.j7J\r\n=4\u0019K\u0011!)]W8E\u0010+geSNRch,QLg7Ml:[,;\\X2n3T*IM58\u007fZYJb *N%e:`ERemJLc\u001eU\u0019TGc] g\u0017npo\u0017Z\u001b\u000e<#if\u0013J4\u0013\u000f`3q,6\u007f\u001579YRedC\\ )\u0019I2+Eg\u000fURW:mMEmI\u001e^\r\n&L+CHI\u001dT+\u0011Z%\u0017%\u0017!?A\u0011\u001cI\u0014kKci\u0010-Z\u00130IG\u001b'(UY[^Q BqO\u0013&hAD!\u001eFW\u0013\u0016j9\u0014QK]V\u0017TMW5i4J;\u001d^GU0P6\u0016\u0010\u001a9\u001d0L'SSZMnI\u007f)-%.=>\u007f6FB>\r\n#\u0015eHq9U7V\u007f0i-Bg E.qCB\\43\u00169`Y&a)QBHbL'D0BWqhpJ6\u0013\u0011\"4*F^q !K\u0016Xjk\u0016\u0010\u001c\u0011GR\"a\u000e\u0013HT&\u0011\u0014d>\u0017)nWC\u0011q\u001e\u000f^fX\\\"dbQ_R\u0016U6-'<\u0013^b&je1kQ7Z+>0`\u001f\u001dG/-bDi@PgFDNJ@,V\u0013\u0018\u0017\u0010RC&c&GBqSY2_\"oaUk\u0012o*H5;Y?\u0011M\u001dE\u000e!MP\u001c\u000fkqOeC\u0011nl,\u0011LJ\u0017B?=&TMb\u000f0\"jL>l^; @&\r\n \u00183 A;A\u0014qn\\h\u0011Y2\u001fP3=\u0014c\u0013\u0012j \"1\u0016enF%\u0018I\\L\u000ecO\u0012\\\u001dQ<\u001bR!\u001b\u000fU*\u0012SH\u001b\u0010k\u0018O\u0010Uk\u0010+\"nYhT4\u007f>I%\u0015cI\u000f\u0015Ug\u001a3.Vn5h=-8(_`\u0015\u0016_g\u007f\u000fi+\u0015;C^q\"\r\n\u001dIj+\"M\u001b\u0015)\u000eAYOBD/\u001d\u001epiZVR]ga%\u0014JT\u001e\"F[H#\u000eeV1&6IF\" \u0013k'bL2h2\u0016IjRRc/p\u0014!9Fma\u007f_E/\u0015\u0019P\u001eA\u0016IAE6T3in*\u0016%;#\u000f^\u001b.h@T\\%Na+]]64I\u0015^[ UAGD\u001bhPjE6U^:'`N'HYf\u001d?iGKZYB:d@V_085\u0015\"W4p&\u001f7ff!*V()OcD\"6Cpb>\\\u001fq\u000f\u0016\u0017\u0017\"E5>\\PfW\u0018-\u001d%g!+e\"HqXPig'N\u0010n\u0011b\u000e\r\n\u001b>>80?\u0011%G=H&\u00103_\u0013%\u001f^cG+IK&i_Ip#OHL\u0014H_T5`#`\u0012\u0014\"?\u000eC=\u00129kb\u001a5KKiBS\u0019bS\u001cA4fK`WC\u001dIS \u001e#LRp\u0017e\u0012\u0018i-\u0010Rj^9g.NH[h\u001a2\"gVKA+p'ccT_a#;Tn\u0017\">(DNTBU\u001bAV2#WH\u0019%\u0019h79GqFa\u0018c8oOB:\u001cIWX/WAR\r\n\u0019S=<<&]\u007faHB*S;^o\"-68q\u007fj\u0012ljm\u0015Lp\u001cBmFVXJ\u0011j/\u001a\u000f\u0015e0\u0018\u0016iYpo8e\u007f\u0019p@=.b&K48(+\u0014\u0014\u00191B5_3h,&j/Xij#*T`WI\u001al8HXe7Le'Xk:K3\u0011o%W\u001f8G\u007f`(X+g\u001b6,bn\"\u0011M\u0018X\u0012#\u001bW\u0013JH:L0+\u0010\u0014\u0017\u0019R\u000e4k\u00127Y,nn \u000fS\u0016*\u000e?aLi\u001f@^\u0013\u0015_\"OK\u0018\u0011(90Q*) \u0014JIH8\u000e\u001d.0N[\u001fR%j[lD_4\u001b63fb'L/\u001f_\u0015\u001b9\u0010[\u007f)\u0010-I\\MVdcY\u0015Q\u0015HE?dH\u0013ZHF>Ri:'M>0.B\u0019GY:?.SD4\u0019gBM%\"\r\n\u0015[OKUa\u001e\u0018+V0h>a7?N%TK C\"J[P&h@Ek-_.@Pa/H\u0012O]D^WC\u00160Dk\u001a\u001c \u0018\u0016 n82:95g\\c\u0013\u007f6d\\/\u0014-eM4Cpo\"EO_p]+.\u0011#!\u001ek\u000e\u001ff7V!Q8o:S\u0014LL/1\\*GB\u0012=\u001b\u0012\u0018cYjp!\u001f\\/Fc\u0010\u000eBcUfL\u007f_4\u001a?H)^\u0016\u001aS%\u00100\u001ed6e0ZYbEbhOn\u001f\u001ai\u001d!NC\u0016#\u001d\u0016\u001baO@j,H)\u001b#C6T\u0018(42'. loS\u001f+.2\u001bE\u001e\u0012[)\u00108WQ>^R\u001fH*qg8mpNm&\u001ee7 \u000eLg(W'\u000fcZ'D\u0016]o\u007f +X!Z)H\u001095\u0019P%4&EC@1b\\8#qD6@\u001f\u007fh%k_]Q!M^d2\u0010nP!bd\u0011il&g/\u000e\"*G\u0014ki=A\u001d\u001e1C\u001b\u001cn\u001f\u0018W077\u001aDUl \u0018i3\u000fD\u0016mqKn4 hM\\\u001c;,KIbJj=\u0014FmbN\r\n\u0014\u000fn-aR;p'G\u0019\u000fCc\u0011/T\u0013M]oOClafS\u0013cda\u007f?)V\u0011^>;\u001aNp\u0011&B=l;FZV'\u001b)*\u001fT:\u0018F\u001ba653qOiQ\u0010%gJ NUe]C[O\u000e\u000eamHRJ.\\j\u001d\u007f+Q4O\u001d4L9TD=m\u007f8H_\u0019=m_M_oEo;p%(\u0011[*,jJln0\u0012/M\u000f6C\u0019D[,\u0013[\\]L\u00108FHYJ\u001eR[P_EBCd#cC3R]Kje%\u0012#j\"\\R\u001b\"\"qCiVhN#CN\u0011e39>\u001c:SI1gg]CVR9%!\u000eqZ'GWq#J; `Y2ANj%\u0015i7UGMA\u001d\u0010/bk5-\u001e^(CU'=b\r\n\u0011XI!6lW^\"(,gp:/\u00135WBQl\u0018^\u0013q<+&\u0015P\u001e\"!/\u0018P\u0013J0lhRb\u0013O+n\u0015\u0014F=?\u0011\u001f\\\u0016a\"6KH^C3n\u001d\u0016F!AEUTBp\u007f18O0DC\\j03K`\u0012\u0010W\u001a3Lq\u0014;DFL!/\u0011 /h\u001a5F\u0017#lp5\u001f6^3V#!=IPmM<%2\u001ao(mNMZ99-.lpe\u0013\u0019`#J\u0017iU\u001f\u0010XT`d\u001ec0c\u0018:*)\u0015Zgo:O0Rean\u0011/\u0013*n>Y8Z0L:^Pe\u0017\u0018Q`T\"\u000eBU.@Z\u001f5@CX!;? g\u001d%=5.*^\r\n\u00111-\u001f0T\u0011G@I+\u000f\u0019jBo?3(\u001c1]e:-[V\u001fk\u001e0!\u001blM\u001a?l\u0010F,\u0015H\u001be-+\u0015M4\u001a.*\u001d=9liE\u001dGRk\u000eF=82e[\u001c;8feC\u001f?W^!J\u0016'@A,\"Q-[d@MAK\u0013_k\u0010m7g\u001ejRpX=:?MH6ElO\u0019\u0015\\U7\u0013.Z#O.0_T\u0017\u000e`\u001e\u000e\u001f.1\u0011\u007fk3J\r\n\u0011\u000f\u0016/A!\u0019NJ>%-A_CfI;\u001c8le9;O\u001952nfbN*D\u0019>4\u001e\u0018`*J P8PPO\u007f7_c\u0013\u000e5*\u0016[\u0010Ll\u000fm \u0014?RY\u001abCnOMg97\u001aN\u0019]\u0013W\u007fd<;g\u001b*H\u0015_`>b\u000ea3\u001fJF%U8\u001851e\u0017\u0017\u0014>Q>\u007fT7\u001c_@'\"OAkCB6&j\"\u0010\u007f\u0019m\"l_)&KdAY6V\\k3\\*X\u0011\u0015VM\u00100\u0017cbH_3J\u001c9!q>E:\u0017\u0019\u00126=lm ITCABo\u007flc*g\"O\u0011LKA?6Z)T`C1Un\u007f#\u000f2E\u0019NAc*X7K*\r\n\u0010U L5`3\u0012Si%l0\u001eEO=lZa\u001fKbfRFOAHG71?,\u0017g=Y C\u0016Ab=eA:We\\C\u0016?^>^NQ7\u001a\u0018 Ani\u0015jS\u0010>ip@pij\u001e\u001f\u001d;-O)Z]p)d\"\u0011@h\u0011?6\u000ep^\u007fjS>CUOo'%[ol\u001b`\\63g\u000e3Blq]g8\u00147m)\u0016\"_3]OjWL9\u0014\u001f?.J3dE%\u0018\\A)\u0018P\u0014\u007fpD\u0010G@*##E*E\u0012\r\n\u0010;\u000f\u001eP\u000fJb69E\u0019m\u001c,\u001fdY'R(\u001dhd*Sk]G\u001dQn!Q6) \u0018b\u0014;Z3Hbb_\u0019\u001b]nT@^.\u000fQ\u001dN&ma\u0014V\u00132c \u001b\u0012RdJ,\u0017TP:[B\u001240\u0019\u0010(\u001aB>\u001ck\u00148=mR7+\u001b6UnDeF`,T\u001amh7Rei\u007f?HU\u0012SYfR% 6%\u001c\u001cL:O\u0018@M/C\u0018\u0010DSp=R\u000e\r\n\u0010\u007f\u00127bL/\u001a\"A%/f\u001bM\u001bk2I#Vc!\u0011(\u000f\"G.+`Bq+\u000f3Dm^OB\u001cQ/<\u001c\u00198%0PVpT],<9],Ca4jDU\\Q4\u007f`?*\"8X\u0015\"-5p+\u000e\u001a\u0011\u0015\u0011\u001e\u001coFK7\u00186k>5*i\u0016\u00111fE\u001bQ\u00165M@\u001fV^\r\n\u0010\u000fbMJ\u0018&(hp\u000eV5k?AlanmkW>P(;8!Fa%-;S#(\u001fBj83\\X\u000e?\u001fn\u001b@C_^mn;ciG7(l0Ek?L\u0019[W1H9W2IQ\u001c/Dh5qh\u001fP0%d%,3d;C\u007fk:B\u0013Xi,j#:X&Ra\u001f3J\u001d\u001c\u0017ThJTh3d@\\\u0016n\u0019;!\u0012dm)+=O\u0016\u001d\\\"^6o\u0017Jae]\u001d4=m[e3_\u001d=,+\u0016Tp\u000eK,0qRK\u00140XSZ1XWWpCoB\u001a6\u0013\u0019:\\\u0010A7am\u000fU\u007f;CL\u001aJD\u001bq!\u0018;Z(\u0017RZ`\u000fe_J7A\u0010fW\u001eR>\r\n\u000fb\u0012K2;bkX\u001c\u000e6\u0011DU+^)\u000e:L\\=9[\u0012M>K]IQ\u001e,ZJF?*%\u000fFD&\u0011Uj=\u0015\u000fK\u0017m'\u00172jed38\\P3+>8!(3\u0015\u0010h5ZD,653'q\u0016H1\u0016\u0010@=\u001c8\u0012b\u000fiZJk%U5 \u0015\u0011QE:\u0011;n\u0010)pPW8R:Eb0D?qkE?@Z3\u000e G\u0015ae`k@\u0019T\\f4IBi.\u007f;F?\u001b\u001bF^Q\u00171+1o\u0013A#m\u0017E29SBIL\"4l>,TXP&\r\n\u000fR.MXD\u0017\u001eGJ\u000f\u000e b*0IX\u001a<\u0013\u0016X\u0019%\u001fqqX\u0016l:6#\u001c]km\u0012ZNP\u000e\u0018(>G@E%;\u0010g\u001f[m(c].0*O+0nSHT!\u0011P\u000f5B9]/k\u0012\u001e6X:*\u0016\u0018%?l7NSVKV43#m-FiN2^qQ\u001dkW*4\u0018N`e+,d(fL1\u001c\u0017*F\\nKh[?1\u0016#\"\u0017ac\u001aEf&8\u0017*\u0017,]?6O6UYM:\u0015\u001b8d.,2DKT`%\u000e\u000e\u001c\u0018V\";\u0010oD/Gfd\u007f'?nSb\u001a\u0010V8\u0010E,?INV-\u0017LA!>eco0O\u001cZY*F&L;5en'!E\"\r\n\u000fD7KOnYhq<\u00136qHAD\u001dGGm\u001dcPIqVTK@HIM:#-Io[\u0012pf.6M_:7\u0013(X+%H\u0016e\u0015\u000fd(d\"\u001b:\u0014\u001d7\u000f(0\u0017^qV[GGA!\u001ag+;8gk22\u0010oE\u001f]p\u00149L\u000eq>L\u0013V!]e2k(mlq^\u0019n<<9\u001c\u0010=*.>(!\u0013`olhf9gN+:'+Q6qU@P'a[=\u0012[(@Be]p*!2? I\u0015&M;5\u000e!\"M5\u001eV\u001d-Zin\u007fAED\u001epi30EFg,V0T\u001d61^,Q5BS!)k;M`0]Y1\u001c;Y7DEb?L #\u0011\u0012\u000e\u000e\r\n\u000f8\u00162\u0014DQ\u0015:<_f9\u0010/JM\u001blqnJ/-\u000f0Ae\u0016nY\u001cp8\u000fhpOK,K' SR;7n%\"gL\u0017b[\u0018Tc5\u0013lOS\u0010n]*X:`\u0019\u0012 .+D\u0012R<^Li\u000e \u0011.APT-CNq5Z,A=Snd\u0013d\u00101\"!o&\u001e\u0015K\u0014+6p,KI\u001b\u0013\u000f5'W@=6pnV+!\u000e/\u0012\u0016X:B]GU\u0016lmC@4_N7p\u001cK:Z\u0018YE\u000eg'/&E!C\\KmgVTPZX<\u000e \">\u000eA`aA:\u00117]\u0013+\u000fAA\u0017\u0017N\u0015!\u001cb\"[1)/Sm\u0013;\u000ej\u001f,\u001a'\u0010B0\"/,@OQU)R\r\n\u000f-\u001aoU&\\b\u0011Oe\u001a]\u007f;p/hLP\u001b;=!f\u0017@\u001f\u0019-(NfRjgn,G\u001fi_?Z_E-d\u001cLh!9&\u0018k@N)`N\u0011%\u000f)\u0010@g8biFIZ2\u0017(fqXM\u0016k(\\>\u0015]\"Yg38K(J#?o\u001cQ\u0017JM>&*`\u0010, i_kV\u0019\u0013\\B'oIE(>\u0017.,42)5\u001b\u001f?\u007f,\u0017]\u001fbf0AgK#n2)l*\u0011\u0017N\u001c\u001dc=\"RFB*06\u001fH \u00139H\u0018E\u000eIE\u0013T+\u0017\u0011\u007fZoH\u0010YK\u001303#\u007fQ\u001b\u0010n\u000e\u0017)>\u0013\u0018I\u007fM\u001b@K.f/L\u001b21,_R\u0011*VGS&:YO7:\r\n\u000f#42^Z!\u0016-RH]]N\u0013\u001b=]6\u001dFf\u0010,)PY\u001fh.04\u00112&6-\u000f>q\u0013W\u00179`%VG\u000e]^!p\u001d+\u001d=j\u001e(iG\u0018@nY9\u0016?\u0010\u00154^\"I\u001bH\u007fnE\u0017Y\u0014F(2#V&L?5&`<7j\u00182\u001e\\*\u0011\u001b'\u0015\u007f!S,\u000f\u0017_5SF05*j\u000ee76]\u001dO:%1h\u000e-U!QY)C4LBKXJ6q)U;=@5Qm\u001243m:ToG\u0010eYmA4/lNo\u0015*2A\u00103D6\u0013:S\u0010W[7[i5_N+h/l:\u0010c%Nl\u0015\u0014?\u000f\u0010\u0017\u0019gL=!`N@cpX\u0017Y\u001bT\u0013'\u0013/iNk]j4kZ]X#D7qO= \"\u0019+\u001c0CN9n(;12\u007f-KN]HO\u0012*`/]iiNnhOc\u0010XQVQ=\u001aH\"\u0012\u0017D\u0017o \u000ff&XH:^G\u000fG=9&\u0016eWN\u0012?LiJk\u001ej\u0018mm\u0015fY.\u000e\u0013o2`6&N-Q\u0015U!if,#e\u000ei_+Ti2\u00162\u001fQ8\u000f\u0016YY7A\u00136J\u0016\u001e8Vp<\u001dq\"\\\u001a\"C7a04Mfq\"\r\n\u000f\u0012lI1\u001d?N3\u001b\u001d/'\u001c\u001d8c\u007f\u007f#M\u000f\u007f5\"\u0015\u001e)I4p/\u0015\u001bB\u001fpS34j-\u000f4 %\u001e8#_>\u0018ZB\u0018V\u0018\u0010W=ORe7k*&*J\u007f\u0013M:T<\u0014q,B(REC*f\u0016\u0011\u001b\"Q!3[90C\u0013Fb*\u0012\u0017P88&\u0016\u0011eLM+E&Y'I9\u001ea6\u000fq\\KEM:\u0012\u001a7#P\u0010KH7VKLna`\u000f\u001ep<6*1g0;feN\"XHKm,-3/Y\u001ao5W\u0017/qq\u000e<\u001e\u0015kjjN.l0^K!o\u0018^ ^An\u001d3G)\u001f<0GnM!\u0012!oPY9\u007f/\u000f]GH1b.dn6\u001b&`)oQ\u001d\u001f4f\r\np\u000fX\u000eR[P&g \u0010j,P5#m+nO821fge]TOn\u001a.b\u001f;O3<\u0016\u001e=N9be!2;\u0015R&D0RK)A\\(%n2]T>\u001aC\u0011Q\u000fo;/,,Q\u0011:^3QL9:`IeG9\\\u0015\u000f!\u000f7\"-QN9\u001c>\u0017%-l-n\u0015\u0014J48nQ\"B\u0015+\u001a86,L2O>BR\"E4Z71T/%0\u001c+ZV34ncTMh\u0016\u007fOA\u001bJRlT5jIf\u0017_b\u001c\u0011>Mqi\u0015'HYh,JV\u001a\u0015\u0016\u0012a),FXq!a,;G\u0010k\u0012TLZY_mj_\u0015?IB0;JR\u0015g+Th\u001cE@/J\r\nd(/RcH\u001b\u0018+.).I\"\u001a^\u000eHSj\u000e>IBKEYVTo)(n\\XBMYWQ7D1l\u001aC5jWM ?\"TlW1IKD\u001b()\u000eZ3K\u001a]!(>\u0013\u0016(H^fWK\u0016I9I\u0013\u00110;\u001a 9Z\u0014;2h5\u001b9F&gf92/1!H.EO\u001aZZI6\u001dO#.27Nc(e+G\u000e\u001f\\=SDG3L\u001557S\u001cD\u0019i\u001dpd6P5\u00187\u0011W\u0013Y\u0011]Hk\u001b?@6\r\n_*3\u0015\u001e]1h\u0015gB-.\u001d2O]/\u001bc\u0013):(&[b\u0015o[3YYg/bAeX_C?6[<=C\u001bkIC/P\u0013Y\u001a\u001c<:\u001e1\u0010\u0016\r\nZ_J2F\u001dK2U\u001d,]\\]\u001e4a;!kQoTd)h[0)'\u0015lVOa,\"X\u000eQ\u0013F\u007fD!=\u000e\u001c0We>%nUm@]\\\"H\u0010\u007fAFa\u0014MOLAmK5^l M\u007f8-\u0018\u001b\u0017;m_dl+To#92n\u007f`_M\u0018\u0016\u0010\u00183Kj@Sg.Li,\u001cDoZ([V \u000eVC\\[4\u0010#^0\u001dH+clJ(h\u0017(^&\u0013\u0018!P\u001e\u0018Z+^j(\\aJ\u0015\u001f\u001e;8\u0016WA8\u001c\u001beWE_(\u0014TQ?US:\u0014Q%b\r\nV^J/G\u0013\u0015gOp\u0015\u000eHc8-j0`_1B\u001cq3p(O\u001cKN2gW\u000eP=bAfW=\u001e\u001aZ*\u0015\u001eW[\u001b\u001e3;i2&\u007f_\u0011kA@K? N9X0mE@8^4c,Z\u0017\u001bSkVbo\u0018.\u001fa9d9\u0015QX'/YC\u000f\u0017^H\u007fXCo/A\\.:!=3\u000fnP\u000em\"\u0010p5bop`3o\u0015\u0014X\u0014.V807^;Y\u001fn1WY\u001d-\u0010\u0013\u0017c\"5j\u001dOh'E\u0012)<\u00141(OE\u0017\u0019ZM)Fm\u000e'\u0017hd2\u0012\u001e!dYn\u001bV&ffR\u001a`4gDI\u001aP\u0019\u001f_BDU?6e\u007f`F9\u0013\u0011.(\u007f\u001b?\u007fE^7\u001f\u0017(\u0016\u0013/4-\u007fj,X\u0018aJQe+\u0015\u0017f.\u0011O:\u0013Q9MUm`>\u0012\\+a'>bMl*l\u007f/J\r\nOoE#!\u000f-A\u000e\u001bjBY2\u0010\\^_cLfU\u001eHc\u0010qJp\u001a)%ndH\u001d%C(NI\u0012 N](9\u0016\u001f<\\W1>>WQb;:#:\u0011 A[\u001e\u0017\u001dOF\u000f\u0014J.R\u000fXa]oD/p\u001541R\u0016Y,5GLl\u000e)'C!X[jk-V\u0012L<0*54?\u0012\u0014o\u001c.F%fIOcN\u001cicW=le(Gb96\u0013J\u001f\u001eP@K\u0014g6K,\u001706_cG:gI^84K-T2hJ\\V'ak\u001ck\u0015\u001fe^k6*fJ\u007f\\:+1.1Pl*@9?ap UW4EE\u001f9Xe[=1_@\u001bU@\u001e7E#;XMeHJ*E\u0010G%o\u000e\u007f\u001fOhj\u001f*\r\nM\u0015Y\u0013(DX2'\u0015\u001ab\u001543;`*So#\u0019l!Fg0`8_K\u001b\u0017Qfn9!X+_dMqK+W1-\u00185Xg\u001a\u0012 _i]\u007f^G\u0018\u001b-\u000eXfCpHdQ\u0013HZ8(`\u000eJ3\u000e:>\u0015 \u001ea.I3\u001dYRh\u0010oIm<%O)\u0013\u000e\u001e^&\u0019\u0015\u001bB3\u001f\u0014]_oY!=[:!\u000f+\u0016f#k\u001b\u007f8#\"q\u001a\"(1+)&_\"3800\u001b(Xb]LhA\u0015&8_U:Y\u000fjq\u0014#*J2&/f,i\u001f%WUONM\"\u0015@n,-\u001fem3%[\u0015\u001e\u001d\u0014?9nk\u007ff!\u0017C\u001d=):P9\",VqXOK-Rdia!J\u0018\u000fK XW1aJ39\"f>\u0011``\"]0h\u001cW-\u0018@;OQ\u0010])Z56F/`q>\u0019[,a\u000fY(T\u000f!\u001e2cd:\u001c5m()L8\u001c\\O\u0011\u0016aeWXfE\\Ed\u001f[-\u001e-0\u0016o\u00135!) \u00144F@\u001fP8\u000fA(F 7 nI)<*]lSe\u001d[k1hJ53>\u001a4/Y66,7l4b\u0014\u001eaIP`_&J&kUH]j.`^+j=H]\u0015q@5e\u0018e-j(.RZPpfpR\u001aI'k\u0014%7MH:6J\u0013C\u007f'\u0019D\u0019@Oa\"8H'^MZ9^J/IEe>;e7i!id^X\u0019\u00190L\u0010O>X\u0015+'\u007fb\u001a_h\u0019qm>^#(C\u0017'C8\u001eHTI\u0018d+?\u0019pAkp\u001b`eT\u0017Nq\u001aEQ)MXS\u001e)A&R.\u0018_\u000fM'&*^\r\nF\u00162)cn(\u0015NUfjb\u0011V%\u0010*4L;DC]Y;\u001dH))5A)\"\u001dX\u001a-\u0015j!5C,^!\u00156NG9!m\\N!X3\u0011\u001fcC3]Wd#mkF\"!3/->5W\u000e\u000fnfI=\u001fn\u001c[/Uae(,G\u001fq#O)S\u0014\u001f\u0011,iVH\u001cD\u0011(\"1Ke9Y[ \u000f\u00172+a]aI[\u007f8TLU\u001e#\r\nD%`\u0010gD?0i9fgdc98K^\u000eEa\u000f\u00187UV=\u0019Omc(\u001d\u0014UOd>En%VO\u0010d]k.*9\u007f\u0019W.R51\u001e\u0016\u001b@==;.eK \u0014\u0012+\u0014#\u001b*^O=/70;Z=p\u000e[P;[0\u001f4m\u000e;792Pe,5\u0010dpc`C\u007f/7\u001dIk+hU YddAe/Bc\\\u001a*mEk\\qE4j_SqeSl562>)4Zi\u0012@XQ-:\u001d\u0017V1l40!o\u0010JfH0'Gm`Gf2\u001d\u0011#hN*\u001d\u007f\u001bUfk[lh)\u007f\u0014XFeVN^XeWA;Pd\u0012\u001e7O(;\u0017K,\u001coNU1mIg\u0016\u00185l)%\u001e;hb\u0013+6+I><`&\r\nBJ)hg \u0019\\]M\u0017\u001c5\u0018\u001e\u0010\u001f:[6\u000e\u0017\u0015n\u0017j[hHhQ\u001e\u0012j\u0017gN\u0018?AJ\u001f\u00113=OXS [f\u001a8bU\u0018\\@B]\"ZF\u001fH;P>\u0019V3%\u0016h\u0013kBnh^\u0012)8 mGR\u007fO:77B\u0016\u001a\u001d\u000e'2a'+[h^&M\u001b-4NXDKeVa\u00150\u0018hj\u000eq\u001f'GbY>\u000eE5Fg%@2H\u000eeIiGZO\u00196\\%ajaS\u0011e\u0015\u001a\u001f\u001ca\u000f)ZkK\u000e\u0010N! Xq\u0015\u000eGJb-5p\u001fMH\u0019)(.<\"\u001fXd[%CAj.e,\u0019\"\r\nA\u001e\u001c\u007f\u000e/8e_<8R8[hB\u0017R1T3`4&C\u0012`\u001fGDB \u001e\u001c\u0010%@eR\u000e\\I\u001eO\u0010Y \u001e\"\" BiL\u0015&hY\u001bHb\u001f\u0017\u001aj0U;Uh(Hg\u0015bQD\u000f5\u001e\u00158\u0013G?e\\1TR\u001fD`%CAY7\u001aVjo8\u0012^YIl\u0016J\u0016\u0013\u0012`*7\u0018an^H1VC\u0013.g=\\I\u001d)6n=g\u000fn\u0011^mSK#6&m1[m#/\u007fFl-DeO\"jceMLLUl31\u001b\u0019j=(J(l\u0012\u00160\u001a[Jp\u0013G\u0010\u0016\u001eLC 7\u0019_e%?M`\u0011JMH%\u0017!6h\u000f5l\u007f*m?V\u001e\u000e\r\n?h\u0010I\u0011= .pqPL#I\u001a>A\u0018?\u001a@\u007fCU.\u0015\u001e\";:?No.o(\u0016_&i6P\u0010fcd=ql\u001b\u0015\u007fqZ/9GOTY\u0012\u000f('S@gb0LN7'Efe@/@M\u001eaFm\u000f\\Z\u0011\u000flf>W\u001aX^i] 4o\u00131\u000f\u0016'=8_;eX[p)Zl\u0018:'QST<_LI\u000f&0\u000f\u0015\u001e=j9D=\u0013;>>\u0011CJc-#Xm!O(6eV_;P90/FUef<^Mq\u001b\".mZW\u0018=;.^#\u000e\u001bRb9m)fD\u001d\u001akmp4T8\u001cH>A':?\u001e\u0013\u001dQ`\u000f\u00119\u0012a^p!\u001aZ.D?R8\u0017B\"]7+#GOo)6J:R0V\u001f\u0017*G\u0011R\r\n>^WWW=pECa\u000f\u001bNXj\u001fP\u001f\"\u0017.J4<.N\u001b\u001b'\u0011f?3,a+c0D0#'\u0015\u0011\u001cSGD#\u001e\u0017?%)2/W,]Rg=\u001e\u001e\u000f\u0012[:LNof`6\\`bOT\u0018H;SSo\u007f\\,^)\u007fjG'GgA\u001f\u000eq'EboKm\u001en\u001e\u001d;\u0013 \u001eM<5% \u0018&cXY^.%_9FO> .9\u001aLTi0 g\u001d\u001a\u001dd\u0016.4SW'\u001d&?\u000eb@ofi\u001fHk`GD59X-V ^OOp\u0019,^e\"=-/ZYG^\u001eT\u001e7Soc>M\u0018\u0012[:\r\n=e'Fcg\u0013\u0013@1pT &mO-j(2)_\u001f\u0014UHf!!\\\u00112Tk'#\u000f\\7F'aE@)Mp<\u001cNl\u007fm5IJ\u007f\u0011-4\"U7'%S\u0016&\u001aKB\u0015V.\u0011\u001aWX\u0014FP\u0013\u00142l\u0012\u0017Z\u0019%P*)cg1n]c\u0016\u0017\u000e3@D>FBd\u001a^k8\u001b\u001c\"Zq#,\u001dSP`kSQ\u001c3`!gX: \";jp\u000f.W)m#@;c6-\u0013[b\"ZB;\u001b?!d@\u001b\u001f\u007fG;\u0015hUko4?\u00117.F_\"(I=XV@6c`![7LDGQ.Nq\u0019e5]!(]@\u00102]To\u001fag#Qn\u0012:)(6\r\n=\u0016UGV)VY#2':p@A\u001cf\u0015B\"K>\u001d:@*+T1R(o[T9f@`KEG?:Q]nY+.nml%(\u0012C+V\u001co)iZ\u001a6!WJ]\u0011`:Lni[\u007f(\u001dcj9\u0013 Vk a\u0016K\u001a!NV\u0016bg\\U]^?_2pR\u0010i:XEc_.(E^N-/_]N5\u0010Q\u001e9^1\u001c3-\u000ffd&OIR87Skl\u0010Y\"\r\n<:5?R9@O!9Ll\"^bp,l\u0014p=&p(\u0019Yok\u0015EPBFM/a\u00191C\u000eU?/\u0016[Kfo7kIh!#:FENV\u0011\u00126_<(Y\u00100%\u0013'5_T4E\u0017(j\u00195>]cP16.%qgm;5eT\u0018EgS\u00102E*H?\u0011I\u001egg;\u00159/<\u001e\u0019.B[/o^bl*ke9\u001a-B^4Fp5gY[1G7Bd\u000eI6DjOkTFp0=/'\u000f\u001e3b\u0012U , Bk@\u0014IO\u0014*A<:Yp\u001b2h[#\u001f\u0015\u00151(+T#\u001269gQ\u0011gd\u001a\u001f\u0016Df`d^e(\u0017R*\u0019q@*H5XWXZ)%6(n\u0012.9h\"Xf\r\n;kT Io6dmgC:@\u001e\u001b-6\u0019;fkXq\u0017)/j1J\\7g\u007fK\\'e\u0012cQ\u0016\u001f:\u0019\u0016hNo!#jhYY<0;Q+g!Kp\u001e+&=C6\"Ek8C\u0012mm>U&=\u001e6@\u0019\\\"*gK8=<\u0012\u0013'\u0011\u001da'6eT\u000f\u0016\u001bm\u000f=WS\u001d!WmmgZM)[5*9j5cB\u0016m\u000e^FH:22N8,\u0017JQ\u001e\u0017m[8ci%\"\u001d\u0017&k32:g\u0015o\u001ff\u0011W/R5RC-p`'Vf/\u0018ZMG\u001e!\u001f(U5,4Kc\u001c\u001f\u001d\u0010coM\u000eY94T+\u000e]\\SB/%JchKeV\u0014\u0018,a%=!YE4\u0014fQOKY[V4J!'f-d\u0018b@_\"fc\u00131\u000f%d VYZpop+\u0011Y88\u0012Eh 1XR@a+\u0019%)Z_hW3o&@F2`_>\u001d__a\u001d',SN\u0015lSC#fAQ\u001b)#:l1jdahl\u0014\\j_;gHFL\u001cFgT`=^%\u0014q*N6*'7(Bm\u0012\u0014'\u001dN\u007f\"\u000e2Q\u001d\u0010pP\u000eY;#H\u0011\u001c_N\u001bSJ\r\n;-9O]Sh\u00191?8\u0016>\u0010II\u0019j\u001ahJ!abooE)f<>SOk\"L@\u001eS\u001c*o(fS-kn\u0017;\u0019_f\u0010C^\"d\u0013L\u007f:2Q/<\u001b\u0013/:])0R;? _T+5jH5q,7\u001ekIpp^D9X09Y5\u001e`A3,\u001fHO(\u0010T7<-@\u0013^?)cOG.D+\u0016!/'\u001b+V jd6\r\n;!(@K=f7\u00178Ij%MJ\u001d4P7\u001b7\u0018YZ:\u0018=d9P\u0011%mgi5e:Y\u0011p\u001fGqX0a\u0016L?Y&Rq\u0014&\u000f0(\\TL\u0012Bl\u000f\u0011\u001f\u001a\u001aF!!:\"6S8 1U\u001c:^_#p2\\Xg\u001elojB?\u0010`\u0013q\u001eMY\u001e@Ja6b4BM&*+\u001cCF'\u0011\u0019!9?o,akpd!8AU`\u001a_V]GMA\u001ec\u001f#;9,\u000f H2A>:'PN\u0013;#GT@M#/A\u000fRg>6H:e\u0018R=K0QaO\u001c\\OWbV>\u00123\u0013\u001fRm2\u000f\u001b@c#j/=TF\u0010+\\0AVD&\u000eR\u0010jh2hNcf2CRU,:C\u007fPZQ?2TX=L2Q3p?4\u001fY<\u001d^^\r\n;G\u007f*\u0010#!2\u001degUi\u0012_+'\u000f\u0017R>\u001e,ic[OUeK>H\u007fq0=9,Q7IKgo_qaA@8< \u0010J\u001am eCjg\u00103*\u00182pGUEPDe)pgd0%\u001fLN>mFXh0D\u000e6\u0010\u001aXX\u0011aaI\u001a\u000ej%\u0019\u001a^\u0013P*\u001d*K'\u000eR+3&T(\u001e o\u00190e*eh\"\u000fA/_)q523c3:9`MO&p\u001f\u0012[;\\c iiK]_`Znl\u00166ZO`\u0019SLBe\u0019/S!\u001a\u001f\u0012\u001bcNk\u0015g&F^2P\u0016F-Z)\u0010J\u0018FJ6\"&SP\u0018LAEbeX:c=OLE\u0011k\u0012[;[O,+LR[\u001c\u0010ETP\u000fMO\u000e L;+%\u001d9fg=*8]+J\r\n;liW33lgR\u0019\u00123\u0015\u0015q%8oH\u000e\"g\u001d/\u0011mM+\u001c8\u000e+3\u001ea?+W3_\u001cDJI,'\"(H,(j\u0015L'cI\\,.-D\u001bG=[Qo\u0011Y2P.\u000e\u0019Ln'Qk8H2i\u007f#Ue/5G\u0012#D@J\u0019&?G8\u0016#^Zl\u0015f`\u0016)mA,\u001c\".\u007f\u0012d-\u0011GkQ5\">j7&)\u0014m\u001eq\u0011\\p>5`;\u0018\u001c]=OP0\u0016\u0016ZO\u0012N\u0010=PG;Bb8;X`MmMQ\u0012\\^.&,(EO\u0018B\u0011D 84>>8*mhC9\u000e4mG<&\u001a\u000eLZ\u0014l42o'0W/\u0018\u000e'\\3\u0013:E\u000eM[CAjV\u0016\u0019143Nf=\u007f6LA\u001973\u0017[;8\u007fAc\u001dA%Sf\u000f4X5U%\u0012m8Ye9\u001dI/&.F\\\u001dF!nkIP*l%\"=Y\u0017\u0018.knM)IYcK\u007f&eS\u001aA/*X%FRC\u0012\u0010ZD\"pV!\u001c581S!q9S\u001aX[\u001b q\"\u001c\u001f+#9HAde;\u0013Fh5\u00134ak\u001fbh=\u0012\r\n=\u00170Oh\"Qd\u0017M8*ibLYNp\u001b03%(iM\u0015:<8\"aGqg)X8\u0012\u0019C,moo-\u0019+\u001d4Miqq! _LY\u001cOK/?qGT\u0019\u0016fgW^-\u001e\u000e(\u0010E;!KZEH\u00186!Q:\\\u0013\u0013PJ\u0014\u0018ZVl\u001bj;nQ\u0010gp?DJJ/4?\u001d'9o;N\u00124A\u0019\u0012)CE91lW#\"Lhj7I@BS:6X0\u0015%*[(Ip/9AD\u001f\u000e\u000f5U5 \u0017cOh-I]\u0018\u0017^%1\u00110\u0014L-HiV\u0014')[\u000f21-*\u0014\u001ekekl+k\u001b(c\u000e'F!11\\6%`#iNa>NFh24\u0018_[\u001d(\u001e_==\u0015X;J6`( O>\u000fHG\u001894\u00186\u001cO\u0016Mi\u0018#\u0013!\u0012\u000e\u000e\r\n=dm\u0014bZJ*HFD\u00157 %=0o8>/ f+X\u0015&\u0015/\u0010E:-\u0011(hS#\u000e4G4\u001aQV!B;\u0013e[mel'\u0011YE_7\u000eN\u001e<-T\u0012i\u0012MCqo\u001e&`5L;\u0011WeT,h48:ip@'RbX\u0013V.j\u0016%\u0017UIq Bo\u000fGq0gK.\u0017EjW]\u001a#,@m#iFAAX`\u001d [\u0014\"Id\u001a\u0013\u000eTfnX:\u00132\u0016[lY1fL!lpC)_nVdBQhE65(C\u0016A\u0011_m6^\u007fYfoZ%g&9\u00106hQ!4\u0010VdE\u001cN\u0011Q\u0010Em\u001e\u0011\u001b\u0010'/1[:6<+I]ndcaP*+,Y'KlhE\u0019d= Y\"fB\u001f\u0015\u001f\u000e\u001e\\b^\r\n>\\j\u000e\u001cg\u00178K@UY,\u007fl\u0018%RpX7&p#`4b^Y=\u001c>*%c=od)\u001de\u001c4JN4H1kfT5VH7je&@\u0015oK87\u001foOF)\u001f1Z[-.A,(5GmQ0P[HfQD\u001e5\u007f/Zc\u000f;\u000f+G\u001chT\u001e\u007fSb.11p\"^\u001cE!W3K=\u007fB/.?\u001d\u0016TER`2V`?YC2J\u0017[ZK\u000f@K\u0010MIk\u001bDI?\u0017E\u0012;9`mB_A&pf\u001ceED\u0019e\u001d/\u001fp^5:k4di\u000eOb9gH?H)H\";3\u0015\u001aTLA\u0019T B6\u001aI\u0019MS>\u0013!\u0013Zc2>+L\u0014ogCje\u001d\u000f\u000e>\r\n?cpjIRQE\u0014a\u0013\u001aXd12\u007f\u0016j@hA]&o \u0013\u000f\u0015\u0013=\\-\u0016N7;\u0012(9'*dL%e&I#o3q/\u001c\u001alfhhJH.e2 e\u0014MmF\u0018>OT/Eca\u0013J3@>UWW\u0018BZV\u000e3d0.iWB\u001a)I+BMD!h\u0014B6gpc7N3.T+&\u0012CJf`VoB@<\u0019Oc^\u0010OD\u001a-'I\u0010-\u0015\u0015Iqg\\\\\u0016W\u000e%j)>7\u0019oT,qB\u0012j\u000fdjo;g`O\u0012`aO%%#oj\u0017b\u0017;ZmkVA\u0011AUcaE8\u001fFO]%\u001a\u001f\u007fo\u0014A!7U!4+n@?0\u001c=+Z\u0012:I!`4X_/o\u001e\u000f?];gO<7inec*Q?;N\u001e\"4fS@E\u0017@\u000f@0p&\r\nA\u0017\u0010e6j\u001c[\u0019\u0018\u00186MGYTX\u001b`o(B\u001f'I\\q@j85\u001fQ;3Q\u001fZ@QUQ\u001d.P)\u001dIm\u001eF\u001a=<;AIJ\u0017pQ-Ncp-AJ\u001fG\u001e&\u0016=Dm=q\u007fQU9@HY+KL\u001a;E\u00136#>Xqia/q=d\u0010\u00117^XJ'^a*?J?F9C*d\u001bh#SL\u001cJK\u0018Z\u0011<_eg\u007f#PW\u0015Pm@!F\u001f(h^\u001d% qf,@\u007fmW\"\u0010l\"\u0016\"A\\_ciL)&R(kO-Ih[+\u0012\u0017;b\u001d\u0017d_Pn7GQq\u007f\u0014\u00136BFfBX@l@\u0017\u0017+%\u0013\"\u0017\u001f2jl7%F4\u000f+3D&_0D#R!^!6NG)2T\u00131e.\u0016.\u000e\r\nD\u0015'\u000eFp\u0013B8'-FJ3Y1D8HoH6Q[gOQX#:^)\u0010\u001d\u0016.]-^p7*H%IVp&#!^Y^W`#n)\u0018\u000e]S@d\\9JdTH\u0018\u001e0&('(\u0015B\".\u0014\u0015\u007f \u001310\u001eVGA\u001a\u0010Ji4C)HEP^1TND@8b;H\u00118%'=]? ;\u0010F\u0018Z4\u001cM/\u0011T6i_o'\u0015&b2L:WmC\u001aJ,BC\u0013KP;fM:\u001f4\u0015MZ?bE\u0010V@\u001c4fE6^)o+W)J;h\u0012 6gL^B%gK\u0014#\u0015;\u001fi.#6)ZI\u0013]?)Wap\u0018SY5j__\u001a\u001c&bSm\u007f\u000e';T^\u001a@P\u0014[B\u000f2GB(IT_3(\u0018Pmo XgmG8V bfa\u0011Rhb2,]R\r\nEbnS\u0019<4T<#:_CQF\u0016\u0015C%\\FceMReInK\u001bk4\u001aBl(:b\u0011\u001e*\u001c[W[\u0014P3=O\u0016\u007f\u0018:\u0010?G/b>^5D\u001939d(7\u0018p6X\\EBp\u0016 d,\u0012iG\u0018_q`B6CRS\u0011Z\u001e:lA/HQ\u001e4T)\u001c\u0019Y\u0015eO\u001fn\u0013\u00126&\u001d>\u0016n\\#V4UR\u001b'Ho7\u0013\u0019-C\u0015\u00155YAXI8DckFL]>\u001a\"Q\u0012obf+(\u001a3=,9\u0010a9> gW\\\u000eR<\u001f)DTT\\@_m(>4QiYo]i&\u001a\u007f!fY\u0019lD2c8\u000fk\u0011Qg.\u001a*onM\u0011I\u000fqaqZ:5P\u00196Fqj_]Tcb\u0015d4B-LRG',Q/\u001cY\u00131CTC@o8&^\u000eES+%3g\u0017)MH2\u00150.)(\u000f\u0013m1?H/+@)\u001akLq Nn\u001c\u001c2^XT\u0017fV'n?Q?!\u0018JP%\u000e7;'no0k\u001f\u000e\u001e`2S]N/KQ1q5!d+Bf\u0012m\u0018=G6\u000fNE\\YK-PNp\"Ee4R]n2.DU\u001c`\u0016\u000eq?D-m%g6\u001fM\u001c\u000e\\\u0013W\u007f\u0017(CcC\u0017/%Wi<\u0018dpI O\u001cT\u00151@J\u007f6\r\nJ\u00135iY44W\u0012[/o1\u0017gFA\"RDV>X;F>e\u00169_\u0011+&dapNASlT)\u0012f]PE1XS?gh?\u001d\u000fCD;h=/\u001aQSC\u001ao?6d_X^E\u000f\u001dI\u00155oHF)\u0010Q\u001cW259664\u0016_)a\u0013\u0017^'Y\u0019YDH6hjp\u0019aTU\\\\/oh\u000e.+Y>*W\u001e3\u0015Dk2p*KT\u001dP0Sp.\u000fN7S\u000ekCeb>Ek8AcO_\u0010J\u000fC\u000e7A\u001e,^Z9h?o.\u00135%BWXe64i7l Zn\u0013\u001al;C\u0013X\"\u0010\u0016#Sk[cO<\u001fn\u000ej458[[qK0?eQc\u000e>/\u001f\u0013]7J,WMn-']ljR pjT9'I\u000f7\u0014g_8WOQ0F%8\u0011\u000f303L&G&\u00144L^!)G>4QFQR6.C\u001bciZ*iDP=bT\u007fQ0\u001b*\"Sj5Qala\u007fh04F]g\u001c1K#i0Zi9\u001aYJ/\u0015A5\\\u0015P\"\u0016_V5-\u0012\u000e%\u0018+7GlIW3\u0017'!*X7b@ \u0019`X\u001dj6,Xf,\u0018#6!#%P\u0015\u0019]!nW6\u001c@6Ko\u0015;%OI_Oi%p^\u001bE/P\u0012/^ \u001chjp]ZHL?R\u0019qC&P\u0013T;o1\u0016\u0013=Q&oZ5NJ\u001b]bl\u0013\u0017JmfgI`9RXoCa?Z)[J!IBN\r\nR*noo\"=8Ud6N\u001d'\u0012T;\u0010?@i!*Q#d'_AKQf9>1XWZVU3,D@\u001fjdI9\u00102k=FE+gM.\u001b37#gC\u0013n'\u0011NAFYRX=2hb\u007fcT\u000eS+0o\u0018!\u0013*!\u0015;7Ue\u0018P*A\u000e3KDOH=Vk9\u0010]\u000f)8O. U\u00109+>M %]_GV^l.#\u0011KTGJb\u001aq1SSOg\u001bk\u001c\\#IH\u007fAOLj(Jd0R\u001e[%S.KmM@\u001dbKY)]1\u0011Sd*]\u001b;eP;/5]YEj;5&n\u007f)8G,+q\u001bq3 V!Y#aKZdPn0Cln\u001f&-,\\nO=>gE\u000e,\u0012\u000e \u000f\u0018d\"\u0011_\u0019In\u0019%\u001doB=9W\u0013B\u0017\u0018 b:aU[J5\\S\u0013J\r\nUO\u0016'jL\u001dM Ml Zd?O\"7A*O\u001dBZA\u00193fgUB.2+O\u0012aL+Y\u0012]%h_Y-I_,\"+(Fb\u001c\u00121-L\\.)c1R\u001fZ\u0012l7aEmpm0hI\u001eN\u0015S)eI\u0015J\u0012lM4h5@>Kq\u001cnb^\u0016K&\u0015e!9\u001ag \u001ckh(KPNDcVW<\u0018lo\u000f*G\u0011\u0019j&]O\u001e=l/(\u00141?=]>j\u001e]6o4Q\u000e'*0/=[Ah\u0014Y(gQn*5>g(a6?\u001ab\u0011`\u0013>\u001d\u007f\u001bQ@_I[<7\u00189(>h\u0013m\u0011AB[\u007f[,!OUD'Q\u0016R%\u007f:0[c\u001eF1\u00144^\u001dPCK\u001f6>\u0017I33neTZ\u0014E9\u001d[63X>Vn=CT'qX joW\u0018q\u001b`7\u0012 \u001fHH:\u007f6\r\nY3&\u001f\u0010m\u0016DUC#7\u0011o=JeK,^\u001e\"\u0011QHN\u000eb Z6\u001dI\u0019^k<\u0015U1(7I \u001b\u000e\u000e[iW5\u001doL\u0018Y\"Be7\u007f\u001a\u000eXGI[S,@bZ^N%6^coo++![!a3:\u0012=Yk\u001f\u0013\u0019G\u007fo\u0013)j7iqfW\u001a`qe3\u001bD\u001d\u0013d\u000f8Y\u001e(of6\u007f'Y/\u0011#>=\u001bK/-aTd\u0014@P7!F4\u001amm)I\u0010&'#:&S!laeJB_Q[\\fi\u0013[]\u0017\u0014\u0012\u0013jn4;\"\u0014/pU03>6D,S@WRFYh\\\u001f\u007f\u0011P9#RL\u0019%l1\u001epq`\u0019J\u0018\u001a\u00100T\u0019*O/\u00133OLjfcZ,\u0016\u001a\u0011P7%'\u0014^\u001ek\u001eQ5GOh\"'\u000fYc\u0015\u0019.S@;\u001bh`O&mI@V<1\\\" (NA6pY\"6OS[R7757:\u000ej\"\u0017/\u000fN?Smc7\u0015MHYb\r\nb\u00134\u001dAC\u00120*3\u0014Yq:m\u0018%m:m\u0016,aD;\u00174QY3\u001a-i\u0019\u0010!CH:\u001c@ZiH]/%8[3l1\"O\u001d.5=?M#ao4\u000f\u0018-*'l\u0010n_De\u0011I\u001a'%fpM2alh:>a./\u0019JG9+ gT\u007f\u001e;1:\u001ac`\u001babo`I@\u001fCl\u0015@J\u001aO_oeHMi.`IkG\u0010C-j*\u001c\u001eZ\u001dT\u0019\u0017'0Lnk\u000f&XCT\u0016c\u0016mA\u0010\u0012?!p;P9_8B[H\u0016?F\u001f\u0017,HfJKnZ:L.\u0018g\u0013<\u0014UcJ%W@d\u000f0O\u000fH\\-\u0013\u0017GF#\u001c-?_A2Pi\u00191\u001bh\u000f3a\u0011\u001e4\u0011\u0017+A\u0017\"&e\"\"-3h2\u0019[\u007fJ-Pc*59 T[ShV)\u001fZWK%F/@XNN'J\r\nlT,B\u000e/#8Z!j\u0016J\u0013;\\\u0013N8omG)h^0n\"oq^j\"iG:p<#\u000f=\u000f^%8o3\u0011Y\u001aG+*\r\n\u000f\u000ehm6QVU.(QKj0T'2\u001e\u00130]n\u001d4Wi!\u001dCLG\u0013njcLq%pb\u0012UH,qDN\u001a'T\u0013\u0013Ek/8&M\"fF\u000eC*\u007fQcRD`8ni5B7\u0012e\u000epnQ:a\u000f-kTI7@\u0015;p!AUmW;>\u001c?q%\u0016>CD\u001cWnDP%AVlHDS7]\u001bN\u001b'L/d\u0013'\u001b\u0011K?` F\u0014P<<\u000fk\u0019?:3\u0016/LlSB\"7-cXA\u00155ED\u0014%,Fb\"\u0017]\u001fM2\u0013_SWF^N'X7=\u001f.\"\u0019n.M,H]2_\u001cRp\u00105\u0017=+l00\u001cIq@0\u007f&6\u0019-N,QW7%l8]4hd`\u0012\u0015\u0014I`.\u0018gIpl\u0012 Qb]!-#\u0016&Bk2>\u001cG6I+)\"Q\u0014cE\u0017\u0019pK)GZ\u001c>Wj19\u0012\r\n\u000f\u0015]R]R^jVV\u001dKNX?\u0014\u000fKQ^V\u0017n\u0015e\u0016VBl)\u0018M\u000e*UA3\u001eIMK@\u0013\u0014-o\u007f\u0010N\u000egKi^&\u0016TKUNV;q\u0019R\u001bhb\u001cGF\u001bVI\u001e\"pLB3i:,M'<:e1.q(4\u007f^Ij\u0018aJm\u001d\u0017:LM3<4M\u001e\u000f>%Il\\cT-a\"?)#.N\u001f\u001a<+:;\\\u0015S%\u0017k!Z'F\u001b`f)%\\fZ\u001f3kSl\u007f+)\u007f0\u0013\u00163\\]Hk\u00163\u001dP\\XY\u001b Y\u001c+\"q5`SeRBD\u0014\u001dl?f:\u001d\\&P^EilQLS#:e4b\u001a*@\u0015\u0011n]<3i\u000e\u001e\u000e\r\n\u000f\u001d:T\u0012;A!\u0019O]\u001di&\u0015\u000eFQF*\u0017XkDV9^g(\u000f@\u0013,D\u00146\u0016\u0015/U\u0010dm14@U*9\u0017mM*\u001b,6hYZ\u0010^\u0015F@j,1]EoD(\"e6*\u000fLa#n]+FC7l(Dd'd (D(aE\u001cafjb_CkXgLWV\u0010T6_B-]mha50)FU;\u001e7T7\u0012p75\u000ec\u000fU3?j\u0010B`%Q]57`\u001c\u0014L\u0017i&]7ZC+92jmoS@\u001d\u0017EYZjg+=27b*e=6\",mT\u00145i\u001dW\\nb\"*? WWpYm1`W7+Q\u001fUdH2cP\u0015k7nF5\"_6^\r\n\u000f%m0\u001cd\u0015\u007fR;\u0019\u001a\u001dS>H\u0014\u0012N)A)!\u001dp>\u0010@\u007f7Y\u0015OTqehTD7\u0012noP344@R(\u0014m#\\e73f\u0013L_c/f8\u0017;l!\u001d.\u007fTP.\u000e0\u001fj\u001f]-#)\u001e\u001aJU0\u000fYp)/IUD[Z]\u0019\u0016m%N]=^d\u001cSp%(gE\u0018Ng[\u007fa\u0018cLQ\u0016/qbYl(\u0016MMOOE<7bh\u0018:BHV\u007fXn#H/E\u0016\u0015]_[\u001f\u0012\"[\u001c\u0019k;P\u001a%^\u0010S!4g&V#_J=apSDX/%YBI/\u001afE-Xog;?\u0018ZCg#k8'FQdI\u000fHUmC\u001f3\u0010#2fjOMENfA-P;\u0015\u0012f!^;@:'\u001e>\r\n\u000f/8+:.gl\u000e#\u001c\u001eGdT\u007fAWAh\u0012(8)5\u001d^9iY]2ONp\u0013\u001df9h6fA\u001f\u001d\u000fU:\u007fbn+P\u0014j\u000f\u007f\u001dJ^?aFYC=\u0013N9FXH:H0\u001a\u007fP.&3VUIT:1`G3BJ\u0018!+W=7aPFknk\u0012XYb\u0018%\u001c%\u001dA\u0011eJ\u001c\u0010O\u007fLE4+ELF 1>Wh]poX-!.\u000fb\u000e\u000f:06L:CU\u0018 )n\u0013<%cG\u001d\u001d,f\u001f.^Z\u0011:Q*\u000e;?*#'4#\u001e@6\u0013\u0015/.2Rlo\u000eAA\u0019m,\u00130!%Na:>\u0013#[\u0011k'X0\u001c\u0012QGUp\u001aST=YYMVV\u001fe:.b2f\u0018`-<5\u001c&\r\n\u000f9o\\&n q;Ac\u001df*\u001dC\u0017\"?!D\"79^_D\u00162=\u001dOaE)I(&\u0013[g0n(\u001b*\u0013\u000e&2L\u001e%#.4+4E=\u0013&V\\\u0015p \u0016YS!01d)W\u0013M\u0011\u0016G9\u001aao>OA+5l\u000f\\\u001d,_\u00130[gUS8hF\u0011`^&R\u0016T\u001c#^I\u0017pkHB#5#G@Y-W\u0012))]\u000fSK>./;lN;g8\u0011\u001cq\u0017V\u0016\u0018/+4Y'XibN\u0016TOPW%`,n1\u007f%D=2-L``=XUGR\u0016\u001dG#\u001e+\u0015_O(nbm:NO\u007f\u001d\u0018K\u007f^d\u0017O\u000f9oBL]gI9e0.GqF22':TYW\u007fBgL:#nlMf+B#F\u0014\u007f7K)(!;C/MQk>UO*X/LAZ),>\u001di&=R\u007fd\u0013\u001c]*1q1Q%\"\r\n\u000fEY_\u000fH3gn+\u0019A1X,iDh0\u001c!N_H(BD]l]HWB*n-OqA1\u001ef`l1Nflp9J\u00167K'S\u0015H8,T%\u00120Ni>L\u0015d\u007fY5\u001bfSc,7aXFQ(iF_\u0012YFA8f\u0019@j19TG9Aa?\u0017Mg\u0019@n\\X\u0017#R+dNEXH\u0010\u001c2\u00118&.[U\u0019\u001fX]-\u001bDhq\\c-.7367\u0018Z6=\\L8J\u00190F,;\u0018O\u0010/'im\u001c\u007fdNi?M/;\u0011qJ\u0014Nl]\u007f\u001eT<\u0010T]bfPg/5XIJ>foZcKGK8!@\u001c>#Na\u0018 /\u001fBd<)h-e\u0014J,M\u001f#B?\u000f6\u001e\u001d)\u0010550(\u001d!mS\u007f+75\u0011nFj\u001a\u007f\u0012o<\u001a>\u000e\r\n\u000fRj:GIWpl\u000f\u0019q?A2=i#:h>\u007fWIi\u0019@a%nED\u0019Dq]AB1\"\u0018\u001dF\"mCO_\u0017+i\u001eV\u007fL\u001b\u0019L\u007f\u001dD(p\u000f2Q%I9>\u001bgOf0d\\4DP#.n:\u0017S\u0015RlW+)B\u0018^Z]\u0011Y04oJ*B]BdGQ9:\u001c9C\u0018.a\u000fAi\u0016\";\u0016\u001a.\u001b*D1Ic-[\u0012E9\u0018[^?!+,l=\u0016b+a=\u000e\u0014\u007f[k=C2I&=A9-)[k9HFo9`\u0013I6?\u001fp=\u0013P\u00183'J\u001ap2)0f\u0012q\u0010C\u0017_a#\u0016AAE\u007fIo+o>B#LT)eiLU4\"W(FV\u0019\u001c\u0019Z?13F5U=fm%\u007fh*^),gC@bQQ\u0010\u001e\u001aL1\u001b\u0010DiC*HnW_\u0015Q\u001d`e*:5&n0%[\u0016\u0018R, \u0018jER\r\n\u000faP\u001d)L#\u001d4Xo>jc\u0012p\u000e;\u0017\u007f\u0015&H:4bN0cnQ\\O\u001fC?nde6,\u001e=q\u001f'lg=?/MF\u001c0jaf;\u001b\u0015\u001fp1A>\\)pL7\u001acj6\u0018\u0018G:KBK!\u001a0AP+\\A?:\r\n\u0010\u000e \u001fd5,7)YN3]&&B\\f\u000ef<\u007fC]/\u0013q !ck;I`80\u0012!>\u0011H\u0010\u001dd8:\u001e[=-HA-CV\u000ff\u0019`_\u0011\u001f\"OC\u00142i\u0013cc7?T\u001boI`\u001b:p8QZC41BPTfo\u000e>J\u0014b:B@g\u0012%J3iSn\u0017o?\u007fMcA\u0018\u0016B0]\\LL>U]R5\u0011i\u001d4\"6(\u000fc-X\u001f\u0017:Oh\u00192cVg@`!=0?\u0014.WSn371q!E<\u0018%;d(\u0014k98YI`P&S\u00116%WUZ3Pj ,-Pj@*\u0017\u000f\u001bG:\u0019Bm\u007fd9\u00108W6:\u0016(2CDI1NP,63[h\u001eKV\u0019!%j\u000e !HSWE#i'Roi.]\u0018Zlj2f7'\u0015b85:]0'cqP;+\u001c\u0015)0>AWq<=mJq],&.g' 6\r\n\u0010 W\u000f\"dCPLWGnHT)`Bq8C\u0017gl\u00128FdV>\u0013*\u0017h S0\u001anO.8Ng\u0012\u001b]*Bp)q\u0013k9S:9q9D/SW\u001f\u0013.0C\u000f\u001b/J5.c(ZQi>'o/cha^ *S\u0013\u0014\u0017G\u001aXo\u0018\u001c\u000feL8cG\u001b;.4\u001ef!`8Y\u0017\u007fHd\u001dTUOW-k\u0018Hf#\\#g\u0015\u0016%d7L#e\u001fP\u0014J/l8\u001aL\u001dE7R=OhQ,o#fR+U^!4pSPX\u0012\u007f\u001b\u0010\u0013/jp(ZaFHaRRF2!\u0010<`1\u007fLmF\u001e;UZV0FUb\u0016\u001aTA4\u0015c>&\"c\u001d;\u00189=l#D>J#\u001a7O\u0017\u0010q\u0017\u001dEB\u001d`C0U/cb(1[KJ&\u001a]=dg\u001dnb>&KV2XlX,\u001e!\u0018\u0018FB\"p+R4;lg)pR(ll)\"\r\n\u00105Hj\u001bBK@=bXPgq\u001a;]\u0015\u000f2\u001eZ\u0010N0a5Z8d\u0010\u007f>\u0014AYZ%N\u000f-g\u001b9\u001b*I Mnl4;N\u000f^0AA\u0015\u001bULTmLb\\LLNYp'@#q?\u0011Bf,\u00182\u0013QV'\\=.Nei\u0013\u00123)7O\u007f13?Al0j2\u001e+NKB\u0011f<]fn\u001e\u000ee0<\u000f#oo>#;*oG^S(+E.\u007fU^\u007fn\u0017e#/\u007f,VnZ\u007fHB\u001b\u000eiU:*\u0013\u001e\u0013T,FWLAY\u000f\\\u00145lRN\u0016%^i511;9TQ#I\".i\u000fGjB\u00188h\u0014+\u0011=V/#F.?-.f\u0012_f8\u000e\u000eEOO\u001e7\u0019hB\u0016[4d\u0016o_? R^TEo:O\u001eVK4@Y3\u000f@[]mU0ij>=\u001aT\u0011nq'+0hiLa\u0017>XfIm\u007fOE^\u0019c;[DN_8XHL oldL>PU)E?(5k&D\\h=3-3k;47SK\"i>MP!F\"4\u0011\\Wi\u0015q,-maGm4'9e- `\u0012\u0010\u0016G\u001b,O-\u0011\u0017gU_#1F\u0011BT\u00122dL-8=\u000f+\u0012#+IY#L7Yg]-mB\u001b\u001484 \\\u0018&Cf\u0016\u0017JN)f7#q8`+\u0016l(\u0012Vp:`cf2/8_1^\u0011\u0013_-[+fPhe/h0\u0015\u0017`(CDb\u001e*!_aA._UdU;\\\u007fQe%=B\u001fZE:g\u007fiM1IG8\u0010[=\u001e7J\r\n\u0011!FMR-J4mM76_&U\"c\u000e/*ko^2\u0012*\u000f-\u0014&\"V7_bL\u0010\u0016)\u0017Hq\u0014T\u001f_LG%_O(<=\u001a\u001d+\u000f!\u0010\u007flo__c\u0013Fe)n>\u000fGY\u00153eC3+\u0017(\u0013'M\u001dTZd4YNKj\u0013j\\? \"@f\u001ee4<\u001e\u001036gm]me\u0017G\"\u0011kXKW\u0018Yg]\u001bIG(\u000fS\u001fE\\\u0016\u0011\u001f<(;fVS\u0013\u001bF\u0012LhZK(n\u001b\u007f\u001c\u0010>\u0017:[S'.XZ38N5a;.j/O\u001a'\u0011QD:\u0014d\u001cl\u001e0\u001e#p570\\h\u000f\u0011;B3Oq\u000e3\u0013g'D\u0017]/#Ak#cU\u001ci\u001a]G?N&?(\u0019@e^q)J@\u007foQOAOG\u001bAb\u001f FQ\u0018\u0017\u001fL\u0011,3'KR\u0017aVEJIHaC\u001cggcl\u00148\u007fVe8]e/k;*4\u000fJ\u0018^\u001c(h?c8/\u001dFUA]Z>?WVJU,HedE\u0011pRXHM=\u0018]CQ\u0013R\u0012\\\u0015d\u001ch\u001f-M8d14B22V\u001bC\u0012(-!\"=jb!'ePnp6^me/WP@\u001dD1,J2NY\u001d\u001d\u0016\u0018iY1+'FLiWc\u0011-\u0010'ih^G%I>\u000f .\u00111a%*>I\u001ed_[QP&\u0018\"T\u0011.0\u0013aFC\u0018n=j\u007fh7lU\u001b/\u001b\u0017:!_F*9VD\u000e\u0014hS\u001b\u001e_8!\u0012OBdF\u000e=\u0014]\u0010\u001e_cnN=:^2f_Vf<`\u001aM\u0017;]mHJ#\"_0Hm[@%K\u001d8\u001c,STW5)q^D\u000eCoj`\u001ciL5D#h\u0016\r\n\u0011iq\u0011?hGJE=An=2cRK@m[8Ef%?\u001a a\u001fGnk\u001f\u0011&B_+/0>\u00139T\u0016%\\'k>2U\u001f+7\u00103\u000f[\u0017+: +ie9Z%R@O\u0012o4g:Pf_KLZi\u0010leM!&-YH.\u00180c\u001dY'U;\u0016@\u001eK]hNJL-DkB\\XPVNm8W3\")o J\u001eW\u0012I0O\u00199phkbQ\u0011\u001c\u001aVC'H\\\u0017%\u001aQ@ji:\u0014l \u0012 \u000e\\\u0018\u001eS\u0016Ab\r\n\u00121W\u001fWg'!I\"6*Z\u0016o/k?\u0015eM!1@HfP\u000e!LB7\u0011Kj\u0019\u007fJ\u001b\\NH\u007fB\u001eKL\u001e8VHLPL9#(\u001d5Y\u000e\u001a/M7ARSE[#],\u001fI\u001dld\u0017+>U*FhKG\u00132Mf\u001eff^,\u0011%F\u0019\u001f%(8T*)\u0012X(\u0010\u001b+5Y4g_1?\u001eV\\,cVqV`(\u0017C\u000fobi!ZGfbTU-\u0013qh\u001f2aLqN\u000eF\u000f\u0011\u0015(G7jK=\u0016\u001dFC6\u001cF\u000f]'GY*8]o'JgEQo\u0010#/`\u0018b/\u001a`_\u0016I\u001d(\u001c\u001f@\u0013VD;\u001fVjD\u001a)O#\u00108AX\u0010_\u001b\u001f@Uf\u001a\u001b'=ZN!nYoX2n\u001f)M\u001akb\\\u000e!mn*+Gq1nC+d\u0011\u0015HdR0P@\"%d]\"G\u007fJ*%QH\u0010c\u0012!HD\u001c\u0016\u0010\u0014Z,NP\u001eZ\u0015R\"\u0011^Ph\u001eFG\u007f\u0016`7\u0015A\u000faG0XY*G.W,B-\u001d?G-Vdq\u0013)\\CQ4]\u001a?i3\u001c\"IWh\u0014/0DX!\u0012+6E[#J\r\n\u00138/(j\u001a2[_fglI>aS0(\u0011@Aa\u0013(\u0011\u000eB='1XR7jRBjlgX;\u0014!\"pO0h@eT?b-GkU\u000f9^S[_\u0010c%>:\u0010d\u0010\u0017\u001f4L\u0012_\u001bq\u007fhmJGdql]d\\Ko\u0016en[R\u0018>W\u001d1\u001e+M\\cdV!-\u001d;NGG4CH[=TD@>p\u001cI6kM\u001b\u007fMM?Zq>K:OTVI>\u001e\u001eZ\\kL\u001c\u00134`B\u0019\u001bhJS\u001aUO=5&\u0014'KoBMoAo<;q\u000e.\u001a&A?p5gk5\u0019TV6\\7\u001cD\u00122Z YA'e_[TQ+/A\u0019*\u0012CVI4'\u0010_@lG\u0017T\u0011`h#\u000e\u0012Ti!hc,W+%Me2Y\u0011\u0015H4q!2kZ?D\u00146\u0010\u001e R[6BX>,\u0011NmN&\u001bT_[K'/q\u000eP9\u0017R\u001dN:HnOR9PRZ^[\u0017\u00124m`\u000eHa\u0012c)SVh*H!\u0018SnAn+\\`#\\kXY\u0016OlQc\u0014V\u001en\\MqgT4D5fVk\u001d/4S5\u00143F5\u0012\r\n\u0014_F\u001acKmcW2E%iHGhlOD\\\\\u00130>\u0014?1\u0014)!\u007fFf0pAIp(\u0019LEM\u0013\u000eFP/\u001c\u0010.\u0019BM0M+ f_/N7+6B\u0012%`:g\u007f&e8e\u000e\u0011R.H7M'qgkmY=Ml\u0019f'ho\u000f'MX!\u0012\u001dY\u001dOG)nd:3\u0012.mW\u000eTbQ4C5\u001fXEO-\u001d% \u0016\u0016\"=Oj *\u001e#\u00141G\u000f5n9\u001d\u0010\u001c\u001e19gdm\u0010eY`MMk#2\u0015\u001dW\"5)Y\u001e<_[?\u0012N\u001eA>h]G)(beU))90&IN2iJ9F0Uh\u00100\u007f,),\u0017b\u0019\u0016D[Gn\u0016/8\u001d\u007f90q 5@*\u0010K!OE= 3ZQ\u001bp\u0017b&Hh-\"K:[_[KagFIZ\u001d\u007fW\"o\u0019\u0017Z`!(2\u0010Xh&-=KmE \"%D^p/^I\u001371C\u0012@5>\u0016.\u000e\r\n\u0015P_-3h'_n9dO\u007fKE^\\\u0016?N+U@/.FY7cL@An]\u0015n\u0019PPi\u0014:=0` \u001e\u0011\u001d@\u0013*gSYRJ\"qa`Q2^*\\`YD\u00128'G@g!\u001abV:\"\u0017;]\u001f&@mC\u0018\\\u001bp\u00131T)1W\\=PD[\u00126!\u001ee\\PGB\u001a3\u001a8W.\u0016\\9\u001a\\\u001dQ=e;dH1D\\;JV\u0012'.Bf\u001c+M:nji&V!?\\\u0019'R`?MG\u001f`9\u0013C!3#*-oNM!\u0011\u0015PRU`Bpo\u001b\"B\u001bT/8\\p5_\u0019P\u001aEQn):JVMh[qKnHe_VEY;5\u0013'b%^6+&m&\u001a\u001f^n3%);jY7,0VA'=9q.\u0016X\u000f\u0016n\u0014hn`7C\u000f\u0011#[[g[bV&>V1OX\u000ecAG93;-\u001d4_\"hCc.DH1p(&\u007f +O/-n^\r\n\u0016N]L\u0010QW\u000f!7o_QZB\"lJ9N\u0015\u0013]H^)=g`\u001bGmKm\u0013\u001f7F\u001e\u001e`![\u001dn`4\u0013A\u0017^UH\u0018\u0017lLS,II8%[%e\u0012?<@\u007fM4m\u001a%\u0014pb;i\u001fl\u00130#\\p6(c^\u00153_KAm\u0010h.V\u0018#VVU%K)\u001c)4\u0017^5`!?3\\N/8I5m)jI\u0012a\u0013dU\u0018,\u001a\u00110m\u0010^lC_@i%\u001dB\u0011bkd:5c4F[\u0013p:(TqW-gp,Xn\u001b`H\"\u0015@kfSj\u0013\u0019oE\u0016_>jlHfd<\u000e\u0010\u00120ahEj_+UB\u0015\u00116\u00125/RKV/LSG_:ba50lGN9\u001e'+\u0015I\u0018.<3\u0011M\u0016VWc\\Bd\u001bh3`!L\u0014\u0017+@]\u007fKX\u001cJ)(=3+%(>C%)L\u001dJ\\f8lJ/fK:K:R*X`\u000e/*\"Yd%j3.>\r\n\u0017[M\u0013k:`G_\u007f\u001aDn\u0013\u0011l`R\u0015-Zn3\u001b]\u0015X9bX'&4JXY\\MYjS\u001a\u001eo.\u0015p\u001c LR)\u001e]9\u000e5Hf!W5^\u0014'cF\u00167\u000e.J`IVh'Oh<`n(\u001cJR)A\u001e\u0019&;\u0017@<('X\u000f6JmM72.e@%\"\u00129R4ZAH3:p&G:gbj`\"/BM\u007fOQAg\u0018QPXCp4S[c;K2p8\u001fmp\u001cIa\u001e?kc>'F3\u001fH\u001fdg0@7\u001c=O:\u00135d6ClF\u0014\u0019g\u0013]@oA0\u001c\u001aDl.3M\u0019:R!=\u0010:]\u000fQ\u0012-mb\"YL\u0019Wm0)\\%jf690*\\S2VGR)0;i<\u0018/\u001el+PpbW\u007fX<\u001aiPT#\u0018@I\u001e%Yd?\u0011&\u001cI,&\r\n\u0019\u0015`\u001cHMB\\Y\\,Y\u00173\u0013h\u0012OM&\u0016K+*#1]F.\\2CFP_\u00176N]+b),Y\u007f6\"`S+Je9=e lO:be\u0015=+J\u007fjD%B&\u001dX]>K\u007f?226`KRgZJVd`c3)AL#\u0010\u001e[SneI h\u007f[BN`>kT2\u001c.Wn'ogJd!_\u001f 2T:=R\u0019c0q;>\u0011\u0018C`&]l, nXVb\u0014\u001bc\\=\u0010;RhWWip;\u0019\u001a\u000e2k\u0014\u000e..R2E\u000f?\u0014QDA\\%m7p\u001bPIYp)\u007fibhj3!Qo#1Ya]<^\"Rf\u0019R(&ON`;UDmZMb6RASa8LjY;g/E&9I+\u0012@ :`,m'_dG\u001a,Qme-F6_Ji\u001bDh\u0018 \u001bk\u0015\u0012VnHN=M3%d*\"B*/)\u0019!\u001ce3`0\u0017o\u001cV5(ok]\"\r\n\u001aH/6WGCK+\\p*\\ZmOHd\"D9OYY.iE,W!\u001e\u000f,;mN@\\LXLm86hK2+S@5\u0014WK\u007f9\u001cB:\u001b\u0015ckT)^jl&\u0018&=nO?A_TIlPc^Z\u001edd\u0013@\u007f1D\\(\u0012K\u001cO&\u001f.\u0013\"BC24\u0012,*!+LQ\u0011#nM%*DK'H\u000fk9E*\u0019\u0019ScKdpE>+8\u007fG7!l7FJe\u001eEkY2eU\u001aB\u0018\"\u0015K?\\O_8b\u001c/m\u001c^+\u0013LU9\u0013\u001e`X[\\DY\\g[@9d`\u0016\u001e]*]F8^\u001e7W\u007f%+\"m#4P\u001bH1BGPn+_fW5\u0012a\u0010\u001bEi=k2gfO\u0011#!O0.VcO\u001d\u001aDliR\u0011K\u001eY.n&5<\u0013G!\u001eiM?\u001ci!\u0018(7._;A\u001c\u000f%\u000fIbd;7\\8q_\u001cpQR%\u001eCB>\u0018B\u000f\u001d&PebN\u000e\r\n\u001c.R;\u0011C \u001c6i\u007fLo\"&c)L:NSP[E9aE\u0010/79n\u0018Og.Y4Jg*\u0019qg8\u0016IR8MR[*\u001a,Q7XdG\u001cd_S#7\u0015\u001eNqV\u0015\u00166\u007fZ\u0010#W^f\u001ei^K3W\u0018]Ze?\u000f;\u000f\u0017P\"\u0010L\u0016Dh\u001ab7;7F6G:=V\u007fD3!\u0016U5\u00111eN=\u0011\u0015\u0011\u000eK\u001a]\u0019f9qDZY\u001e\u000fUE>\u0015Km\u0016SY9#hO2\\F5(N\u0019cE\u0017#]`\u0017j-.)76Y:\u001aI\u001a\u001edb\u001eN=gp8>@`QP@qK7\u001d-\u000e@; 0h\u0011,D\"n2.q\u001bA[\u0014\u001dp;JqZ*\u001bd0k2SR8\u001f)B\u001e\"GbWZ+(\u00199b9FlWl\u0013&\u0017\u0019b \u001c*.\u001cW**T8A:\\][b\u000ePk\u000e7iH12\u0011\\oUa\u0017=`J+],d\u000eG/ eK2VMgcV8-R\r\n\u001e1\u0012j; ^\u0010L\u00151=)^n*HQ;C\u001a\u0014q`G%ScbN\\p\u00165\u0015\u001d\u0012\u001c1\u001d\u0015\u000f\u0018l9_K3\u000e7\\ohgA+(\\%\u0016ITXpRV\u0012MiZ=j0\u0017Cj)`\u001dk>RO\u0019@*#`0(6c+L]Z_1i\u001end\u0012bHc>:\u001cM.U\u001b\u007f\u0014G[>1\u0010Rg[6#<]aL=WK\u00103\\U\"!h;AVbaZK#a<1oS2\u0014q04T!e\u0012KE`/&jZA\u001a/0\u001fR\u0015M[0\u00157\u0010\u001dZbRk(\u001505I&%eaa@\u001c`!^\u0012,\u00157e_W_\u0012.\u0018KUg\u007f\u0017ABbC,\u000f\u000e\u0017dI`i]7-&SO3.AYk2k,#8#&(O6\u001bP\u0018?E\u00168;?H>9\"\u0011\u0019I\u001f*6A\u0012%H2JE\u0014\u0017!E)d\u001a\u0011 M\u001c&`BdE\u0015Sjq=\u001a\\\u00160+2SlCn2Hc:\r\n T5^2J\u001bF'EkU\u000fJ/Sl+\u001b\\/D\u001c4-+PG=-`m\u0016\u0014\u0013KmXT\u0016<`aMP>R\u0012hNI_6@Hb&\"R\u0011\u0019o?+\u000f\u007f\u00142Oeq\u001a?kE!W*\u00142A=\u0019j clF\u0019G,o\u001f\u0018Ci\u0018Lq)dHc)\"L1o@qX/Q28\u000e5.\u0011BW]\u001e3+ocN\"DR[SK\\@5>hp\u007f\u001e2e3Y\u0016Tc,7ZdIL\u001f&A)^\u0010)-n-\u001e8m\u0019LG^`mlH0\u0018Yb(k;fm\u001fV\u0019D\u007fP[\u000f#\u0016J/\u0019@\u001fb?5\u000flj4W`n0S3#H9i\u0010B'4\u0011e\u0012&T>3\"\u0014\"mIMVb\u001bAq+\u001cZ\u007fQV\u0018Zl\u0018lO]!WAXYi\u0010BOp-UcU\u0014Pj\\\u00145]1V&#\u001c(/,+\u001eG\u0018&\u000eR\u001cJTn%L@*X/*!\u0011A\u000eN@,%\u0012*\u007f\u001c6\r\n#:O?m^i'Iq(]\" N@6>1kC'Q^\u001e#\u000eFT%X>L[4 B9-\u001a5\u0016k\u0015i\u007fBgHC2enp\"\u00108\u00178Q;V]ad(D \u001bXI<\u007fn='ijF*L9M\u0012Ok\\\u0018\u00132D^M2R.h&\u000fh`hA(G0V\u001c\u000f\u007fj3>dE\u0011V\\T6,\u0010Ge371X&CH\u0018hFo\u001eK\u0016f\u001b?\u007f=WA\u000eI](/I)?MG\u000eo\u0011\u0011\u0015\u001clmG 58[*gNOm6&'17\u0014FV-%\u0010@oE;=@P\u001am\u0015?NZCo:l\u001e\u001fMoDl=H>*c\u0014\u001bC\u0014YSM\u000e\u007fSJGj36V\u0017f\u0016\u0013+<5\\FpU4\u007f*k!qeo(U,-80\u001c)\u0014)055\u000fC3I\u0015YBi+KUUZ\u0015\u0015_\u001dC\u0016J\u0016n6\u0015WF\u00157po&\u0017\u0014\u001e\u0016d\\9jFH`f\r\n*5Gk6#b[Vl+T\u001a_+c\u0012PFjXdCi\u0011%>QRhE2Ejm].\u001e:U/QCk\u0011'+NN6Z\u000edRO11 PocYnd\u0018'hcq+ \u0011!:F*/FL3gKb?H][n_\u0015Cc\u0018`:VhOFog]\u001a \u0019LE\u007f?i;7\u001aeS3P\u007fLM4\u001a2\u001fnX?l\u0017\u001a&P\u001f\u000f\u0012`J]G\u0010:J,\u0011TTO0dS(S,Hf5X\u001b?b)2E7:N`HXE(\u000eX+\u001c9eGi\u007f@\u0012TG-\u000fK\u000e\"!\u0011\\\u0016Ili16lm2qpU\u001c9LkCW7>]n4jH\u0014 n=\u0018h\u000fPTb;bPnD\u000f\u001eln\u0013Fhd119Z\u000fC'\u001e(\u001a456i[K\u001e+jj\u001dq\"Jk\u0011l?9bX\u007f)\"\u0013T\u001d3P;DM8Ue\u001c%>^\u0019Go[qZPAZ@\u001e!\u0013\u0014P7P\u0015[\u001eoL]>NN\r\n.\\c PV\u000e]EPAP\u001cj ^!+U\u001f\u0013\u001egPp\u001fL\u000e5\u0012C\u0018\u0011gY\u001ffQ\u001aPeh\u000f\u0016\"@R!&G4\u001c\u001d%\u0012\u0014?\u0018?mmHRD*0GpU]hC*,(bZUf\u00184F\u0015%'IS(\u001f<\u0014LR_7hS\u001eE67BA\u001d\"cVnSa7\u007f3J,QUjU'/\u001e\u0014\u007fI9Zb\u0016K\u0013\u001a\u001eiOI^]\u0012X0l\u0016j#)\u0019K#E,e\u0011&M0]jk<6\u001a\u00168\u0011Vd5%Zl,\u000fBf\u00197'M)5gp)W@07ed%\u0011>&0)nO\u0014*\u0014;eV7/ge+Z \u0018)cDT:ZKMZV)J\u0016lCT'\u001fMMV73N__;G(;m\u001eW\u0018fh->\u0018\u0018\u0015aM\u0013X?W\u0017pe\u001f%70G(\\?bZ/YO2%M\u001d)V?D8O=\u0018\u0014VCqko8\u0016\u0012km\u007fX\u001f\u00162,I\u001bZC#*A=:%J@J569.8oq&^%k%Tl6\r\n:\u0010/;\u0012/\u0010LKJbE?Y\u0018iqnI\u001ef`K>AH\u0014g4gF'Z0:&c\u001c!,#-BIM=g8>>2\u001b84)AW^A;\u0017\u0015a0\u001c-p97N7.6l\u0019\"L=\u0012*S\u000fSY=`Bl\u0016h\u001b(je9:\u001doDR\u0015>eH\u0010jNNM\u001aQmB)=[3oQJq\u007fO-\u001dH<9I;+?_\u001fRG_;Zc\u001c.1)7(\u001a\u001bSp\u001dX^\">\u0010I%LN2-7kp6?n\u0012a]p2mULnXq\"\u0010U\u000e\"M>(,%k'7\\^>_1\u001dBjRbq\u0018BG\u000f\\J\u0017Y'fjC_45!'C\u000ebMHgYVT\u0017B \u0011>1?,_H=U(d\u0016\r\nA aGbc(\u0014\u0012a&%\u0013g2=&O\u001eLAn'9)\\R]P>\u001c\u001b\u0010;\u007fYkc\u0017Xd%aBg!T=LZ25fcZR:QJ>/ff\\>W=g2@\u0015[APHN+&WgA\u000fO\u007f_EV;T\u0016,S\u0017[IN]\u0015[\u001bY]'\u0015S\u001di=mK1%)_l)b\r\nIOS(9N>\u00127\u000fmjnU;\u0011\u0019lW:\u001aWnk'+-J8`@\u0017dJn\u000f\u0012n \\\u0019h*,?^Qa:Vd, \u0016%\u007f+7Yk\u0010O7\u0012q#WLf\u00171%JF\u001aXjG78\u0012[d\u001d!'f L\u0013G\u0014g`\u0010UGX*;\u001eQ7\u0017\\Vq2La+hlb\u0017\u000f]A\"c\u0014IDW\u001eF;2[+j:%,\u0016FWc,k.\u0014V4F\u000e[S[X)C.:(/ 0M\u00116\u00180L4O\u0012\u000e\\&q\u001d;=KZ\"A\u007f^\"Slg\u001dfD:5Q5\u001f J\"\u0018\u0013!cS>KjA.b7B3`\u0014[!RDMTW\u001ajg!>j)qj\u0018?+8\u00152\u001b +e2S)XLR>&Sd\u001d>*cT\u007f1. U)\u0011/J)2e!'![BH:H1F\u0013:W\u0010``WP.,oUY,=#Z_PY>\u001dnOpl\u001bSV12+F\u0016]QLMRALB\u0010_\u0016^\r\nSRP+\u0018)\u00173\u007f\u000fN_\u0010b\u0015]T=aLX\u000f=g+E/H\u0015Xn;hmZjQP/m\u001b\u001c\u0012Y`gea;)J#1#fOij\u001bG9TUVNX*6?U#Z,\u001d5RDi\u000fS]2QW\u001b!:j\u001fh2+D/h\u0010UV=]R;1e,=ejFTE<\u000fR-aKdT\u00179\u0014c\u0010\u001eP%\u00196:-S4=\u0017\u001e-]6c^._OaTF2MaR.^C!\u001d<92mF)Y=SbA\u000eeH\u0014\u0016#&0loQ*H?Zo (C\u0019#%m0e;\\\u007fM/\u0017\u00157\u000f^c8_R\u000e.f>\u007fRo/\u0017dMG\u001anUYCA\u000eC\u001d5\u001c\u00162\u0012\u00141\u0019E`Z\u001e:eieaATe1!pM3:1o\u0013YN+Kf\u000f.^R\u001aUN\"PjZ_+\u0016\u0014\"<\u001bKQAK0\u001e\u001b\u0017pUER\u001bY#paM10@DHR>\u00116.D\u001cS\\jhY\u007f'B1\u0019^NM7\u0018\u000feen18-NfEV2\u0018\u0014fG\u0010g;F84q(g%Q;R\u0011L\u001cA-\u0015ZeV?1\u001a hZ9Lb,\u001ec\u001aJX^\u000f\u0015FkMcH%NeEGI\u0018cX7*\r\nmX9\u00142dd/^M8d\u0018flHj2BM,/\u007f,!-\u0011iT&%\"Z28I&\u0016h/HS/)L&M]-\u00140\u000eYeZZolO63S(?mCAi7S\u001eC\u00153RQB#2>J`,H\u0019c;Y1)'\u001c8\u0018+k+B\u007f)d1m3(I-:po\u0016d_&P;\"8\u000f^L.7 Ca\u0012\u001b@O!\u000eK/\u00119n\u001dmnjn\u0013l1c%\u001bj)V5F[-?L\u001eDol\u000e.\u001ab=\u0017\u007f-c g79]f\u0017T\u0011<*\"[\u001c\u0012->10>/H\u0018\u0011EpWD94\u001e%%q/lR6Zk!U4W_GYHX^\u0010\u0017?\u0010?OaBC1\u0012\r\n\u000f\u001aK\u001ck\u001d\"-K\u001e,iJ\u001df\u0016\u0010j\u001d!Vb\u001c\"\u0015\u0010LH[\u001a\u0017cX)g:OH\u0018&k)3\u000e\"0\u001d\u0018W6Q0_XD\u0017`K32J_J?L?DF\u001djOX[\u0015KG.^PO=j#=!\u0013Y95\u000f&OFAP\"\u0010\u001eV\u000fB-\u007fVj@\u000f@mFPe\u000fM%;eF9(X\u001b\u000eR2[^\u0013[\u001e;#\u001d)j;U(\u00112\u0019Hj\u0014O\"\u000fjf^\u001d\u0012i )@;V7G.%\\==H3 \u007fo\u0012-&.I\u0018BSn@8*W\u0012F\u0016bP/q+\u001e[a[7?\u000fq&\\*V!X\u007f(\u0010`;iO%5p\u001d6Ml5\u000e\r\n\u000f.Y!p0\u0012m=\u0015S9*6_TPI'\u0010\u0018,>06!\u00194lc\\A\u001dDR61H\u0016=XNlkc:\u000fj\u007fHfdAhA\u0013A0*lKSiX4k!-7\u0019V_\u0015j8Ufq'@\u0011BVAL F4\u000f\u0017V\u0010\u0018\u001ai&.!^/\"\u000f,=;3P\u0014hH'&iOZ;:7KcmH#3HA\u0017\u0015E?Yq\u0017Ml7eH\u000eb\u001eW\u000fo72Q]a1q/O5bb\\\u001eEeC\\]d\u0014.f\u007f=L^\u0019?ommhX`5'\u0019o..\u001c&?VI'YLP&R\u0014B\u0014\u0015\u001c3d'>q?C\"kQE\u0016\u0014o9Rbp Z^d3%'D)<\u001dQ8c=\u0015nmX\u0011<\u0013.ZVY\u007fgV#a@,B^\r\n\u000fFc\u00115;=PJD@0!H3\u0014m\u001c6GH2K@W:d[C&nMdU8aIh 7mlZ/\u001bKiV`\u0018S+6\u0011A2?;=lU\u001e)+\u000e3\u00177/ob\\8o )%:\u0014!l,S]%KJ\u001c<1j\u000eWljYWh`3\u001a\u001b\u000fV0+On\u001d_\u001e\\`\u001eB9>\u0014anb+\u001bGpMR\u0010\u000fCp)*[=[NI\\3\u001b\u0013/L\u001e\u001df;#-.i\u0011EE \u000eq;:(%O/7\u001e/:,7? Vpf\u000fCi@\u0015V\u0011\u0013\u001eG\u001e\u0016\u001fG_^b7mB`\u001f\"i%#dbV7Yf\u0017JQj+`\u0010G:&IAS,H-WB4IN\u0014'8\u001c7?2)^[*\u0019TV3\u0013W\u0017ka\u0015IE`4G>gC>>iQR@Lq-hI&(W\u000fIq\u0012+\u001bq&664?g`2N-K\u001f-q#\u00108:&.%?:\"\u0017J[>),\u001f[Di'q\u0015nR;2;>&k!3>>\r\n\u000fcX/iW\u0012\u0010ac \u001b\u0015#d:?b;M#/\u000e\u000fmlTcn\u0010[:H\u001b\u0010\u0011fY\u0018>A\u001f\u0011jN3.b0e#LVkJB_enN\u001bjPAKA\\\u0010;Qj+b!VZ,pC/m[f\u0016`TUUd*L\u000fK\u0017m?ocm#\u001fU8,\";9hI\u0015\u001bO\u0012\u0010j7FQ,\u0013G5!\u007f0\u0019]\u0013'-n;L\u0019\u001f5Xl'cF _KMe\u0016'9\u001e#\u001dMPOa\u0014i\u001f(@\u001cN^]!3Wm^`\u001d\u0019'1\"gmi3mR( f0Cn'>iW`0:&'i0j:\u001b\u0015n+\u001bcVAYSan\u001aG0o8L\u0014_\u001eQBk_'9VEOYl8#\"ISN\u000eL5\u0010\u0016\u001c\u0018RaXRME%3A,cgOMI;q\u000eV-e/[\u000e\u0017DDKd #8\u0013F\u007f[U&BJbV%:V\"\u001c9\u001d\u0014=\u001aQXIiP)JW\u0016B568CUF=Mff)X\"FF0\"m<&\r\n\u0010\";K\\#lM\\o3\\\u001agc4\"%<\u0010b[S([L\u0018,(\u001f`T%\u000e7,>\u0019pn\u001fFEq\u0014\u0010RiXH4*BDQj:qip=6.>i\u0018[\u0017V-;8T4*,\u001blTJ(`dfq+*/96m\u0017(\u0017\u001bc\u001d3Xn96\u0013Sb&)4qGh%7IP\u0010Bc\u000fF(C\u00152;m4]Q)>\u00188M_U!E\u00151p\u000e\u0016\u0017%28i\u0016QX;\u0018\u0015\u0014^\u000e\u0014=k\u000fd\u001dQp\"4\u00127lMW#4O\u00129\u0014Q\u0013jff2aNE%\"cPHC\u001e\u0010j1\"\r\n\u0010L&N\\-h8\u001ake;\u0013J#\u0017DP!_\u000f\u001c\u0015E+Nf-I8E#XN>Nh@)J\u0018f2Q\u0014Tf(`l(1\u001aHLA]>@\u001bHf7\u007fA!\u001d7+QU\u0019SPG?\u0010Q;1pn=p\u007flC#\u007f\u0013b3kj4XjoN7NX9\"T\"BYT-n*\u000e+18'iCG\u007fc'\u001c \u0017?f\u001cOYJb/d7\u0010*3\\\u0019\u001eco\u00132:\u0011Fk\u0012I8oTc\"l,\u007f\u0019\u0017_qNiL%Z\u0014'pcNb#\u0019?<*Ik:e\u0017X>3\u0019\u001aRZm<\u001f\u0012o<\u0019AU\u0019\u001bf\u0018Bd?6TR(pVI_TRq\u0019,#\u0013CWQ\u0017GT\u000fN!E;/qA'\u000fR1Ol)hL:\u0013AQj^T14J\u0015*\u0014,Rl):`S\u001c@p.X(\u001dg?c6lYd]ifP\u0010BN93E\u0016D.;Pk\u0015j,&?\u001dA8U3&^5e1\u001a,>j.KL0XqHN+\u000fZC&^\u000e\r\n\u0011\u001aP\u0013\u007ff\u0016\u001e\u0017g\"\\&T8m%%BHg**Y/4\u0010Tjf[LlaW@\u000f]\u001e.Y\u001eUZoPAI\u0014d\u0016n1L\u0010\u0018&\u0011XgFWm>\u001f)J 3\u0016\u001c\u0018G+Z!bZ0G?@A2\"*\u0012`;C\u0015?cc,\\K8\u0015qCLRi\u001aQ=:?[\u0010_,6SY,-#\u001dC\u001d?R'VN\\8X@\u000e,&M!5]\u0014A5_\u0012p]\u001b`X\u0014n\u0017E!\u001dX@ZB\u007fm\u000eV.1.\u007fE\"%3)5(P\u0017\u000e6CK::E\"k[\u000f#b\"J\u001feX\u0019V4[k>bGj\u0012\u001a#;,!2\u0011Z!e\u0015N`?N\u007f\u001fJX>1mBD#5\u007f\u001cn\u0012!p^G+m&\u000eB\u0015o=?)gl,_R``,VI`L`Tp[7\u0018(\\f<*&\u0012\"\u00153,\u0011\u0015[1h\u00112NB\u007fH]_J\u0017S\u0019\u007f7:\u000fMe\u001bP[\u0015+\u001cdC\u000edef^*N\u00101M\u001e2Vgo\u001dL)\"\u007fak\u007f#:\r\n\u0012=8'Z\"8\u0010>Z\u001b\u000e\u007fE&%[\u007fJ\\p?l4*\u001b\u0015\u0018eL\u001cF\u007fq&iDY0d\u0012BK./.E,Q]O3Mf DK\u0014S\u0011\u001f)\",Z4L\u001e9;b0]>\u00187\u0011[/H[L9T`biXR03]*K?=\u0015;\"o \u001ea8E9Q=&ooJ\u0016XJ\u0010Z\u0011\u0015[ *!(i\u0015'/'\u001fQ\u0010Q\u0014.WmHp\u001dU(JmjUk[\u001a \u001fN@\u001dY`mOo[ao\u001e\u000f,BVe?^D pW#\u001a]8\u000e+\u0015P\u0014D`\u0017B\u007f^;b6\u0019.m\u0016\u007f-hen(\u0014>\"B;M\u00120\u0014k\u001f\u001b\u0019Hk_d(03+7,P\u0012\u000f5(qM'S\u0013\u001d\u0015d(P\u0014\u0013\u001d\u001dC\u001b5LS3\u000ef\u0014)jq[`2I*9\u0016U)+\u00147\u007fF)7pjCX\u0018\u001b?:ZjM\u007f(_><@V[ \u0011U*ZH@X6\u001d)\u001epW[A74D?KZS*R1I\u0017+%?\u001e@P'4H@; \u000e^p_K[\u001d<\u0011\u000fW?\u0017SoEnX \u0012@EM3I\u001c f\r\n\u0015\\a\u001d\u001bD\u0018L\u0015FI\u001e\u000eq5W?H\u0011j\u0014 \u00116\u0013@l*8\u0016KA!KpPj)-5)\u001adgFL\u007fS9\u0019@aj\u0016\u0013,EFV`%Ue\u001b\u0014P\u007f#_U]l`Ude4#%hT(\u0019jg9/ gq[d2?>E\u007fV<\u0018\u0019?\u0017,Q_1,%jBE`<\u007f ^-G\u001bn65 R\u001dC*\u0014`:LDb%L2\u0018\u001alA^!:\u001a\u000e\u000fC[Lm:.#OMT\u0010\u0014V1TF\u0010#l%p&OcFL3=F#Cm&2\u001a?WM *V3+H-E\u001f\u001c*#bUDW&qAL%Cp]0'?\u0014Cno>`YeQ\u0018J'\u0012\u001bffW\u000fJ\u001bpH\u0011^.jnW8-\u0014f\u0019KdD=6G.Q!b\u007fk;`\u001a? \u007f(3;\u001b626-JY[\u001f#\"\u000f=)*F?>K\u000eTe\"N\r\n\u00177\u0012QfE].gPQ1(nmF%)b\u00167_\u0010pq\u001f:JS!lTj+?&T\u000fl-f\u001dKG\u0012=5SS\u0014\u007fQV&6+Uqj??pqG;l4gc\u001b\u001bX@.\u001fS72No*4b`\u0017e\u0014Id6B?\u0014\u0018`\u0019@`YWR`k3QXeW.)\u0014O\u001b'HbR\u000eY\u000e9k].\u001b\u0010T6Rh-.\\F4hQ2`Mdo_3;(d\u0013\u0018M6FpMO.*gg \u001dJR[GHM<:\u001cf\u0018A:O'\u0010qTOXEC6W''P6!!BRPI]SThB\u0016n^pF\\\u0010\u001d7MD,+>'9\u00124B6_\u0011\"-@_M\u000eo>1F\u0012*L?\u0015^V`2\u0013?>\u001a16<\".W`_QSU l3@M+d\u0019bR0*\u0012T2\u0013Rh\u001eA]73l!)\u0015 IB^((#\u001c^\u001bOoDe_-h-\u000f/Q+\u0018\u001anJa\u000em8qTm\u0015\u0018F\u000fTV_1]ap_\u0016Z`FO3e\u001bJ\r\n\u00195F\u001e\u001b=2qG\u0011U-c\u000e,fc\u0015P\u001d!8Yn@m;\u0011\u001bfi\u0010#@`[i\u001cphZ\\+\u000fd\u0014QbPP\u0012\u0013\u0016\u0019/I\u0019Q5?*C\u0014-!qX\u0017JC98\u0016b* Y'#\u001c>`h\u0019 \u0013HdU?2W!e]\u0014 eRG\u001b7dSW%\u0011gFCBY\u001bC\u001a0`fT(^\u0011\u001aVh_p\u001b%%NdGn\u001a HOnY%\u0018c[@aOa\u000eJ;\u0017\u0011oS5\u001d*9l\u001c=-/\"T@AoHfbCI:l*G4:NeM_1q0J\u001cA\u001cMo.d4bN1\u001cHA#36@jkl4EV\u0019\u000eYZpaS\u001c2Un<0Q\u000fX4\u0010[O;UZ,\"\"FW:1F8\u00148\u000e0\u001eQ5'WP8[;XJa\"IJ\u007f 1I_\u0014_&AVb\\59\u001d_hk8O\u001fp:f4(\u0012\u001aRYD;Y\u007f_\u0012&IFUpmN\u0018\u00197<,6\r\n\u001b`qI7\u001494!-\u0012go\u0017j\u000fXNcG\u001eW;&\u007fb]k8`W\u0012IebRZjg2#6g:\u0012DJ\u0011ZR>SSlcm\u0010/;T\u0015J=\u0017<`\u000f<8gZSO\u0019)n\u0015L\u0015>=mP\u0019\\E+,?Dpe99QB\u001aAm8/i\u001c\u00185;(.<\u001c/#m3aeL\u0010 \u000f%Z\u0014g\u000f2d\u001f\u000f\u001bq-N/_+2\u0013'\u0017>j7 =\u001fD5\u000eWH1VCSbZY`=S\u0010\u001bc\\9*=ocR_n4'\u000f\u0014Y=;(GB2?+754kl\"O\u00110\"n\u001d\u001d\u001ff>\u0013!1S09\u001cUM&19X3c\u001b@e\u0018h\u001f^3LXBMh^0=`>`\u00141o,*DdEg\"8@>9G\u000f\u0017\u001eG&\\*4hG1\u0010a8#\u0011nS\"7H0W\u001f\u0012\u0019\"FN+F\u0013\u001c3\u00127PJGo6\u0011(+ack\u001ep\u0010:\u0018.oL7Qg^&3\u0016!\u0019+0k\u000f\u001cnpN8]\u000e\u0015:M%\u0013^6L*do,*\u001fY\\,\u0018*R\u001e#KL7dhq\u0015GL\u001aH/&b.\u0017]?\"c(,U&.\u001f>3?qM\u001c2g^co\u001e`1Tj\u001c.S\u001a\u0019&)6kXqb2N?f!B\u001e\\n'@m'S\u000e]aqqTYl8dl9\u0012\u001dhU\u0012hA'#;#=+(\u0013X*Qd\u0014b^\r\n'\u0012e\u001bA0Z=/9Z\u001d\u001eT\u0016\"\u001a!b*.qEfmb;\u001fC\u0012\u001e!]-7`\u0012^!`]\u000flh)\u001fm\u0016ZVgQ\u000eP\u000fk*%2O\u000e5k 0[R\u0012#\u0013j.cpZ\u0012M\u001b*Z!:;d51T!4\u001b \u0012B@n\u0015\u001f=\u001d\u0011?G`:>)\u0013J'8\u001bZWjo(^,R;\u000f5 fa'\u000e\u0018C=a@9Ko6>\u0010\u00127\u001d\u007f-\u0018C:X\u001eo@\u0015W\u0018\u0017o!7\u00192L)\"jY/gM#4EEqTI\u000f9A[jN,^@/IO\u0013D\u001d!=_`Wm;d_NkZX^2m\\jmp-\u0017^!^/^G+f@X\u001a'\u001835n%j\u001e'\u0019!\u0017\u001eHVIS-U@X\u0017Eq\u0017#f'a[#\\\u0018\u001fVW[3j?_h2\u001bDKK\u0015a>\u001f=;Whg -!\"0\u0012\u001f+S\u0014B\u0015%+e\u001bJ\r\n,PSP9D7YfoI:BDMM\u007f+\\=?nHK\u000ee2\u0011d`T_<\u001a+>-h3Lm(C'nQh-b9+j:,o\u001b;6\u001eqJ=-d\u001cM\u0014\u0013\u0016`9Q[DM\u0011n(\u0011\u0016\u0012I?#I6hJa+,Z*bdh7%\u001aN\\+O*3m\u0015#mD1eU&\u0014*6_Q\u0016Ec&)UpM2c_j8'\u0016\u0014%/HZ2(f'cYF\u001d>1h\u0014lbg)JjM%d\u007fK\u00182goB(8&3o\u000f\u0016N\u0019(\"Z?Qi/bB^OJ\u007f'\u001f:qa\u000f*KNU'Y+\u00169\\cK\u001d'\u007f)C#\\\u0013\u001a4?Q& 3DB0jXI5EEj,E_7]+1\u001b/R\u0014XSZ\"\u007f\u001c=))'[6:li&\u001c\u00162n\u0014Ed\u001eNo*\r\n3LU\u001c^*\u001f1/_3\u001aF\u000e'\u0011WmOh7l\u000e:\\\u001aZ\u007f\u0018\u0017'\u0014^\u001a9!k`8eN6-;BlK\\\u0010Z\u001c\u001ag`\u0011Ab'VR\u001f+bIq&\u0015\u001d\u0014\u001d\u001aefR*:S- p\u0016\u000f=h-\u0019\u00105 \u0018]\u0013\u001f\u0019b`)2Mnea\u001eOB\u0014\u001dk(4%Se,.)QW8a\u0018i-5\u0011kjBplfK/D1\u000e\"ClUP0'S(-\u0012\r\n<(V!fR\u0010:^O`eqS1\u0012H\u001f\u00190q\u0016\u0018QX\"5\u0019q 13qOg^jM.G\u007f&\u0015B0I\u000fY%^E\u001dI@i5\u00124/CWid>.?N*2 f\"b\u0016<\u0014qS\u001d7\u0019 `\u000e\u0011Ka&kP\u0014`h\u0010\u0016g,\u0018Up@\u001b=a\u007f\u001b/m&\\J9m=\u00127p3\u0018q_\u007f=+R\u001aRa\u000e\u0016K@\u0018O@!CZM+[A\u007f\u0011\u007f\u001a5b\u00174[<\u0019b<\u001b^A\"6\\Q H4p6J;=BU\u001a,e4\u0017pc,?K\u00120OA\u001cX\u000e\u001c3\u000eV\u0013]\u0016#OVDQX Cl9HIfK/l8A8bCBHU;27e&q8*5\u001flI!.>\\9!\u0016\u0011!]9<(f\u000f^n:j\u007fD5g,fG>/a*\u001dQGE?`_q64G\\f\u001cq6XI-;?QE5LnH/W\u0018JLJHJBCW\u001e\u0011UV*=jPpg\u000fJGJ26g\u001eZng(X\u000f!1(Ac@CW(^\u001cA8,R\u0011S?JN\u000e\r\nG\u000f;b?]dE+^RjRBJZ#\u0016P!Z7+\u00155;q>\u00175g [\u0015\\L042W*=\u001bG@a]\u0012jd\u001f\u001b\u0010Q\u00177+\u0018C\u000fY\u0012Uf*H\u000e\u0011\u001f]k`I7[lQiS\u000fmj;Bn:BBTl)/\u00107lY@5\u0019q`\u0014H(jlqGDq*@O<\u001aO?\u0018\\\u0011\u0017T:lK[R1q>q\"`4\u001b9b\u001b\u001c\u0011UpcE1gPa\u0012\"=\u000f\u001bA\u00167 YJE\u0018,)qd]De^6\u0018A5o/0j\u000f,Q0\u0015\u001c\u001d@\u001dHM\u0011^\u000fD%\u000fK\u0013\u001f[HY ]49\u0011\u0015[#\u0015n\u001350\u0012%I\u001eM'L\u007fP\u000f57#P+E?\u0017V\u001a3\u0019f+ Q[\u0016^\r\n\"\"\"\r\n val (n, m) = readLine()!!.split(' ').map { it.toInt() }\r\n val s = ans.split(\"\\n\")[n].map { it.toInt().let {if (it == 127) '$'.toInt() - 14 else it - 14 }.toString().padStart(2, '0') }.joinToString(\"\")\r\n println(s.toBigInteger() % m.toBigInteger())\r\n\r\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "5de2fe701f6bac180e9739fcf0d1984d", "src_uid": "4f0e0d1deef0761a46b64de3eb98e774", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalUnsignedTypes::class, 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/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n// val startTime = System.nanoTime()\n\n val numCases = 1//readInt()\n\n case@ for(case in 1..numCases) {\n// print(\"Case #$case: \")\n\n val n = readInt()\n MOD = readInt()\n\n val twoPow = ModInt(2).powArray(n)\n val mc = ArrayModCombinatorics(n)\n\n val D = Array(n+1) { ModIntArray(it+1) }\n\n for(i in 1..n) D[i][i] = twoPow[i-1]\n for(i in 1..n-2) for(j in i/2+1..i) {\n val d = D[i][j]\n for(k in 1..n-1-i) {\n D[i+k+1][j+k] += d * mc.C(j+k, k) * twoPow[k-1]\n }\n }\n\n val ans = D[n].sum()\n println(ans.int)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\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 || k < 0) ModInt(0) else factorial[n] * invf[n-k]\n fun C(n: Int, k: Int) = if(k > n || k < 0) ModInt(0) else factorial[n] * invf[k] * invf[n-k]\n\n // multi-choose, be sure to adjust maxn accordingly\n fun M(n: Int, k: Int) = if(k == 0) ModInt(1) else C(n + k - 1, k)\n}\n\nconst val BILLION7 = 1e9.toInt() + 7\nvar MOD = 998244353\nval TOTIENT get() = 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 if(mod == 1) return 0\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_unmemoized() /** 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 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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { 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 }", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "342d91b58ddaa2dce45b90ec8f4d56ff", "src_uid": "4f0e0d1deef0761a46b64de3eb98e774", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.io.BufferedReader\r\nimport kotlin.math.min\r\n\r\nfun main() {\r\n fun modPow(n: Long, k: Int, mod: Long): Long {\r\n if (k == 0) {\r\n return 1L\r\n }\r\n var half = modPow(n, k shr 1, mod)\r\n half *= half\r\n if (k and 1 == 1) {\r\n half %= mod\r\n half *= n\r\n }\r\n return half % mod\r\n }\r\n\r\n\r\n val br = System.`in`.bufferedReader()\r\n val n = br.readInt()\r\n val m = br.readInt().toLong()\r\n\r\n val factorials = LongArray(n + 1) { 1L }\r\n for (x in 1..n) {\r\n factorials[x] = (x * factorials[x - 1]) % m\r\n }\r\n val inverseFactorials = LongArray(n + 1) { modPow(factorials[it], (m - 2L).toInt(), m) }\r\n fun bimnom(nC: Int, kC: Int, mod: Long): Long {\r\n var res = factorials[nC]\r\n res *= inverseFactorials[kC]\r\n res %= mod\r\n res *= inverseFactorials[nC - kC]\r\n return res % mod\r\n }\r\n\r\n\r\n val dp2 = LongArray(n) { modPow(2L, it, m) } //how many ways to manually turn on i + 1 computers in a row manually\r\n\r\n val dp = Array(n + 1) { LongArray(n + 1) }\r\n dp[0][0] = 1L\r\n for (i in 1..n) { // through the first i computers\r\n dp[i][i] = dp2[i - 1]\r\n for (j in (i - 1) downTo 0) { //with turning on j computers manually\r\n for (k in 1..min(j, i - 2)) {\r\n var l = (dp[i - k - 1][j - k] * dp2[k - 1]) % m\r\n l *= bimnom(j, k, m)\r\n l %= m\r\n dp[i][j] += l\r\n dp[i][j] %= m\r\n }\r\n }\r\n }\r\n var ans = 0L\r\n for (x in 1..n) {\r\n ans += dp[n][x]\r\n ans %= m\r\n }\r\n print(ans)\r\n}\r\n\r\nprivate const val SPACE_INT = ' '.toInt()\r\nprivate const val ZERO_INT = '0'.toInt()\r\nprivate const val NL_INT = '\\n'.toInt()\r\n\r\nprivate fun BufferedReader.readInt(): Int {\r\n var ret = read()\r\n while (ret <= SPACE_INT) {\r\n ret = read()\r\n }\r\n val neg = ret == '-'.toInt()\r\n if (neg) {\r\n ret = read()\r\n }\r\n ret -= ZERO_INT\r\n var read = read()\r\n while (read >= ZERO_INT) {\r\n ret *= 10\r\n ret += read - ZERO_INT\r\n read = read()\r\n }\r\n\r\n while (read <= SPACE_INT && read != -1 && read != NL_INT) {\r\n mark(1)\r\n read = read()\r\n }\r\n if (read > SPACE_INT) {\r\n reset()\r\n }\r\n return if (neg) -ret else ret\r\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "bd5a1db5f03392c47321d003f909f5c9", "src_uid": "4f0e0d1deef0761a46b64de3eb98e774", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main() {\n val line = readLine()!!.split(\" \")\n val n = line[0].toInt()\n val m = line[1].toLong()\n var dpPrev = Array(n + 1) { Array(3) { LongArray(n + 1) } }\n var dpNext = Array(n + 1) { Array(3) { LongArray(n + 1) } }\n dpNext[1][2][1] = 1L\n for (k in 2..n) {\n val temp = dpNext\n dpNext = dpPrev\n dpPrev = temp\n for (x in 1..k) {\n for (j in 1..x) {\n dpNext[x][2][j] = dpPrev[x - 1][0][0]\n }\n var curr = 0L\n for (j in 1..x) {\n curr += dpPrev[x - 1][1][j - 1]\n curr %= m\n dpNext[x][1][j] = curr\n }\n dpNext[x - 1][0][0] = curr\n var curr1 = 0L\n var curr2 = dpPrev[x - 1][2].sum() % m\n for (j in 1..x) {\n curr1 += dpPrev[x - 1][2][j - 1]\n curr1 %= m\n curr2 -= dpPrev[x - 1][2][j - 1]\n curr2 %= m\n dpNext[x][1][j] += curr1\n dpNext[x][1][j] %= m\n dpNext[x][2][j] += curr2\n dpNext[x][2][j] %= m\n }\n dpNext[x - 1][0][0] += curr1\n dpNext[x - 1][0][0] %= m\n }\n }\n val answer = ((dpNext.map { it[1].sum() + it[2].sum() }.sum() % m) + m) % m\n println(answer)\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "e52147037b71ef36df8cede211e72ebf", "src_uid": "4f0e0d1deef0761a46b64de3eb98e774", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "import java.io.*\r\nimport java.util.*\r\nimport kotlin.math.*\r\n\r\nfun main() {\r\n \r\n val T = nextInt()\r\n repeat(T) {solve()}\r\n pw.flush()\r\n \r\n // solve()\r\n // pw.flush()\r\n \r\n}\r\n\r\nfun solve() {\r\n \r\n val N = 3\r\n var x = nextInt()-1\r\n val a = nextIntarr(N, 1)\r\n var opened = IntArray(N) { 0 }\r\n \r\n while( x != -1 ) {\r\n opened[x] = 1\r\n x = a[x]\r\n }\r\n \r\n pw.println( if( opened.sum() == N ) \"YES\" else \"NO\" )\r\n \r\n}\r\n\r\n/* struct begin */\r\n\r\ndata class Cell(val r: Int, val c: Int)\r\ndata class Point(val x: Long, val y: Long)\r\ndata class Pii(val fi: Int, val se: Int)\r\ndata class Edge(val to: Int, val w: Long)\r\n\r\nclass SegmentTree {\r\n \r\n val INF = 1 shl 30\r\n val N = 1 shl 19\r\n var a = IntArray(2*N) { INF }\r\n \r\n fun update(idx: Int, x: Int) {\r\n \r\n var i = idx + N\r\n \r\n a[i] = x\r\n while( i > 1 ) {\r\n i = i shr 1\r\n val l = 2 * i\r\n val r = 2 * i + 1\r\n a[i] = min(a[l], a[r])\r\n }\r\n \r\n }\r\n \r\n fun rmq(L: Int, R: Int): Int {\r\n \r\n var l = L + N\r\n var r = R + N\r\n var res = INF\r\n \r\n while( l < r ) {\r\n if( (l and 1) == 1 ) { res = min(res, a[l]); l++ }\r\n if( (r and 1) == 1 ) { r--; res = min(res, a[r]) }\r\n l = l shr 1\r\n r = r shr 1\r\n }\r\n \r\n return res\r\n \r\n }\r\n \r\n}\r\n\r\nclass BinaryIndexedTree(n: Int) {\r\n \r\n val N = n\r\n var a = Array(N+1) { 0L }\r\n \r\n fun sum(l: Int, r: Int): Long = sumSub(r-1)-sumSub(l-1)\r\n \r\n fun sumSub(i: Int): Long {\r\n \r\n var idx = i+1\r\n var res = 0L\r\n while( idx > 0 ) {\r\n res += a[idx]\r\n idx -= idx and (-idx)\r\n }\r\n \r\n return res\r\n \r\n }\r\n \r\n fun add(i: Int, x: Long) {\r\n \r\n var idx = i+1\r\n while( idx <= N ) {\r\n a[idx] += x\r\n idx += idx and (-idx)\r\n }\r\n \r\n }\r\n \r\n}\r\n\r\nclass UnionFind(n: Int) {\r\n \r\n val N = n\r\n var parent = Array(N) {it}\r\n var rank = Array(N) {1}\r\n \r\n fun root(x: Int): Int {\r\n \r\n if( parent[x] == x ) {\r\n return x\r\n }else {\r\n parent[x] = root(parent[x])\r\n return parent[x]\r\n }\r\n \r\n }\r\n \r\n fun unite(x: Int, y: Int) {\r\n \r\n val rx = root(x)\r\n val ry = root(y)\r\n parent[ry] = rx\r\n \r\n }\r\n \r\n fun same(x: Int, y: Int): Boolean = (root(x) == root(y))\r\n \r\n}\r\n\r\nclass RollingHash(S: String) {\r\n \r\n val s = S\r\n val N = s.length\r\n val P = (1L shl 61) - 1\r\n val B = 565625656256562L\r\n val C = 2210565333882893047L\r\n val MASK30 = (1L shl 30) - 1\r\n val MASK31 = (1L shl 31) - 1\r\n \r\n var pb = LongArray(N+1) { 1L }\r\n var pc = LongArray(N+1) { 1L }\r\n var cs = LongArray(N+1) { 0L }\r\n \r\n fun init() {\r\n \r\n for( i in 1..N ) {\r\n pb[i] = mul(pb[i-1], B)\r\n pc[i] = mul(pc[i-1], C)\r\n cs[i] = modP(cs[i-1] + mul(pb[i], s[i-1].toLong()))\r\n }\r\n \r\n }\r\n \r\n fun hash(l: Int, r: Int): Long {\r\n \r\n return mul(cs[r] - cs[l] + P, pc[l])\r\n \r\n }\r\n \r\n fun mul(a: Long, b: Long): Long {\r\n \r\n val au = a shr 31\r\n val ad = a and MASK31\r\n val bu = b shr 31\r\n val bd = b and MASK31\r\n val m = au * bd + bu * ad\r\n val mu = m shr 30\r\n val md = m and MASK30\r\n \r\n return modP(2 * au * bu + mu + (md shl 31) + ad * bd)\r\n \r\n }\r\n \r\n fun modP(x: Long): Long {\r\n \r\n val xu = x shr 61\r\n val xd = x and P\r\n \r\n if( xu + xd >= P ) return (xu + xd - P)\r\n else return (xu + xd)\r\n \r\n }\r\n \r\n}\r\n\r\n/* struct end */\r\n\r\n/* math begin */\r\n\r\nfun intceil(x: Double) = ceil(x).toInt()\r\nfun intfloor(x: Double) = floor(x).toInt()\r\nfun gcd(x: Long, y: Long): Long {\r\n \r\n var a = max(abs(x), abs(y))\r\n var b = min(abs(x), abs(y))\r\n var r: Long\r\n \r\n do {\r\n r = a%b\r\n a = b\r\n b = r\r\n }while( r > 0 )\r\n \r\n return a\r\n \r\n}\r\n\r\nfun modpow(X: Long, T: Long, P: Long = 9223372036854775807L): Long {\r\n \r\n var x = X\r\n var t = T\r\n \r\n if( t == 0L ) {\r\n return 1L\r\n }else {\r\n var res = 1L\r\n while( t > 0 ) {\r\n if( t%2L == 1L ) {\r\n res *= x\r\n res %= P\r\n t -= 1L\r\n }\r\n x *= x\r\n x %= P\r\n t /= 2\r\n }\r\n return res%P\r\n }\r\n \r\n}\r\n\r\n/* math end */\r\n\r\n/* utility begin */\r\n\r\nfun cumulativeSum(a: LongArray): LongArray {\r\n \r\n val N = a.size\r\n var s = LongArray(N+1) { 0L }\r\n \r\n for( i in 1..N ) {\r\n s[i] = s[i-1]+a[i-1]\r\n }\r\n \r\n return s\r\n \r\n}\r\n\r\nfun rlowerBound(a: LongArray, x: Long): Int {\r\n \r\n val N = a.size\r\n var high = N-1\r\n var low = 0\r\n var mid: Int\r\n \r\n while( low < high ) {\r\n mid = (high+low+1)/2\r\n if( a[mid] > x ) high = mid-1\r\n else low = high\r\n }\r\n \r\n return high\r\n \r\n}\r\n\r\nfun lowerBound(a: IntArray, x: Int): Int {\r\n \r\n val N = a.size\r\n var high = N-1\r\n var low = 0\r\n var mid: Int\r\n \r\n while( low < high ) {\r\n mid = (high+low)/2\r\n if( a[mid] < x ) low = mid+1\r\n else high = mid\r\n }\r\n \r\n return low\r\n \r\n}\r\n\r\nfun permInv(p: IntArray): IntArray {\r\n \r\n val N = p.size\r\n var res = IntArray(N) { -1 }\r\n \r\n for( i in 0 until N ) {\r\n res[p[i]] = i\r\n }\r\n \r\n return res\r\n \r\n}\r\n\r\n/* utility end */\r\n\r\n/* I/O begin */\r\n\r\nvar st = StringTokenizer(\"\")\r\nval br = System.`in`.bufferedReader()\r\nval pw = PrintWriter(System.out, false)\r\n\r\nfun nextInt() = next().toInt()\r\nfun nextLong() = next().toLong()\r\nfun nextLine() = br.readLine()!!\r\nfun nextDouble() = next().toDouble()\r\nfun nextStrarr(n: Int) = Array(n) { next() }\r\nfun nextIntarr(n: Int, dec: Int = 0) = IntArray(n) { nextInt()-dec }\r\nfun nextLongarr(n: Int, dec: Long = 0L) = LongArray(n) { nextLong()-dec }\r\n\r\nfun next(): String {\r\n \r\n while( !st.hasMoreTokens() ) st = StringTokenizer(br.readLine()!!)\r\n return st.nextToken()\r\n \r\n}\r\n\r\n/* I/O end */", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation", "math"], "code_uid": "c8eed5876640fc1b353bd2e9fc2f35dd", "src_uid": "5cd113a30bbbb93d8620a483d4da0349", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "fun main(args: Array) {\r\n\r\n var t = readLine()!!.toInt()\r\n while(t-- > 0) {\r\n var n = readLine()!!.toInt()\r\n val k = readLine()!!.split(' ').map{ it.toInt() }.toIntArray()\r\n var count = 0\r\n while (n != 0) {\r\n n = k[n-1]\r\n count++\r\n }\r\n if(count == 3) println(\"YES\")\r\n else println(\"NO\")\r\n\r\n }\r\n\r\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation", "math"], "code_uid": "81c047964d3ab347b003550f2b4c7db6", "src_uid": "5cd113a30bbbb93d8620a483d4da0349", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.5", "source_code": "import java.util.BitSet\nimport java.util.TreeSet\n\nconst val yes = \"YES\\n\"\nconst val no = \"NO\\n\"\n\nfun main() {\n val cin = java.util.Scanner(System.`in`)\n val readInt = { cin.nextInt() }\n val readLong = { cin.nextLong() }\n fun readList(func : (index : Int, value : String) -> T) = cin.nextLine().split(' ').toList().mapIndexed(func)\n fun readList(count : Int, func : (index : Int, value : String) -> T) = List(count) { func(it, cin.next()) }\n\n val t = cin.nextLong()\n for (i in 0 until t) {\n println(solve(readInt(), readInt(), readInt(), readInt()))\n }\n cin.close()\n}\n\nfun solve(x: Int, a : Int, b : Int, c : Int) : Any {\n val u = listOf(a, b, c)\n val o = u[x - 1] - 1\n return if (o == -1)\n no\n else\n if (u[u[x - 1] - 1] != 0)\n yes\n else\n no\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation", "math"], "code_uid": "5cdb7df0adf82452caf10e14d2773cf2", "src_uid": "5cd113a30bbbb93d8620a483d4da0349", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "// https://codeforces.com/problemset/1709/A Three Doors 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\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\n\n\nfun main() {\n val t = readInt()\n for (itt in 1..t) {\n val x = readInt()\n var abc = readInts()\n var opened = booleanArrayOf(false, false, false)\n opened[x-1] = true\n for (step in 0 .. 3) {\n for (j in 0 until 3) {\n if (opened[j] && abc[j]>0) {\n opened[abc[j] - 1] = true\n }\n }\n }\n val canDo = opened.all { it }\n println(if (canDo) \"YES\" else \"NO\")\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation", "math"], "code_uid": "42b555830fc09c74a4606744fd9d1c47", "src_uid": "5cd113a30bbbb93d8620a483d4da0349", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "9b48b9b8e254b7f7e800e83479323fa7", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "f3cbce3bc68dc68c6944e63e0fbe8e35", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "d05dc90acb5e284180664f0b8c309850", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "814e50da391d5efc442747f7f8c76c15", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, t) = readLine()!!.split(' ').map { it.toInt() }\n var queue = readLine()!!\n for (i in 1..t) {\n queue = queue.replace(\"BG\", \"GB\")\n }\n println(queue)\n}\n", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "3ac61935a2c5ec226a379bc094f428bb", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array)\n{\n val t = readLine()!!.split(' ')[1].toInt()\n var q = readLine()!!.toCharArray()\n for (i in 1 .. t)\n {\n var j = 0\n while (j < q.lastIndex)\n {\n if (q[j] == 'B' && q[j + 1] == 'G')\n {\n q[j] = 'G'\n q[j + 1] = 'B'\n j++\n }\n j++\n }\n }\n for (c in q)\n print(c);\n println();\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "c27252338e4f8681749ae3fca19d591a", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var (n, t) = readLine()!!.split(\" \").map { it.toInt() }\n val a = readLine()!!.toCharArray()\n while (t > 0) {\n var i = 0\n while (i < n - 1) {\n if (a[i] == 'B' && a[i + 1] == 'G') {\n a[i] = 'G'\n a[i + 1] = 'B'\n i++\n }\n i++\n }\n t--\n }\n println(a.joinToString(\"\"))\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "11e219e1eda4a8245c356f597097e4d4", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (s , n) = readLine()!!.split(' ').map { it.toInt() }\n var line = readLine()!!\n for(i in 0 until n)\n line = line.replace(\"BG\" , \"GB\")\n println(line)\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "90f93a94195954ced271b46847101884", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, t) = readLine()!!.split(\" \").map(String::toByte)\n var queue = readLine()!!\n for (i in 1..t) {\n queue = queue.replace(\"BG\", \"GB\")\n }\n println(queue)\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "51dc76575e4f1e16f796dcbed387e19e", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = scanner.nextInt()\n val t = scanner.nextInt()\n val str = scanner.next().toCharArray()\n for (i in 0 until t) {\n var j = n - 2\n while (j >= 0) {\n if (str[j] == 'B' && str[j + 1] == 'G') {\n str[j + 1] = 'B'\n str[j] = 'G'\n j--\n }\n j--\n }\n }\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//}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "a2a1c0dbf873b3ca5d057a501cca95b9", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val a = readLine()?.split(\" \")?.map { it.toInt() }\n val str = readLine()?.split(\"\")?.toMutableList()\n\n for (j in 0 until a?.get(1)!!) {\n var i=0\n while (i ()\n var boys = mutableListOf()\n var first = 0\n for(i in 0 until n)\n {\n array.add(str[i])\n if(str[i] == 'B')\n boys.add(i)\n }\n\n for(i in 0 until t)\n {\n for(j in 0 until boys.size)\n {\n if(boys[j]+1 < array.size && array[boys[j]+1] == 'G')\n {\n array[boys[j]+1] = 'B'\n array[boys[j]] = 'G'\n boys[j]++\n }\n }\n }\n for(i in 0 until n)\n print(array[i])\n}\n\n", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "48557cee3ec3cd1d54c31be1ee6812b3", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n\tval (omit, time) = readLine()!!.split(\" \").map { it.toString().toInt() }\n\tvar queue = readLine()!!\n\tfor (i: Int in 1..time) { queue = queue.replace(\"BG\", \"GB\") }\n\tprintln(queue)\n}\n", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "9df6d5860137e0c3a18fc813768026a8", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n\tval (nS, tS) = readLine()!!.split(\" \")\n\tvar q: String = readLine()!!\n\tval t = tS.toInt()\n\tfor(i in 0 until t){\n\t\tq = change(q)\n\t}\n\tprintln(q)\n}\nfun change(q: String): String{\n\tvar list = q.toCharArray()\n\tvar set: Boolean = false\n\tfor(i in 0..list.size - 2){\n\t\tif(set){\n\t\t\tset = false\n\t\t\tcontinue\n\t\t}\n\t\tif('B' == list[i] && 'G' == list[i+1]){\n\t\t\tlist[i] = 'G'\n\t\t\tlist[i+1] = 'B'\n\t\t\tset = true\n\t\t} \n\t}\n\t//println(list)\n\treturn String(list)\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "7bf7cd1ccbc9d72bb7c0745ce6e8e601", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val input = readLine()!!.split(\" \").map(Integer::parseInt)\n var queue = readLine()!!\n val kids = input[0]\n val time = input[1]\n\n for (i in 0 until time) {\n queue = queue.replace(\"BG\", \"GB\")\n }\n println(queue)\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "667320ac11324fdd42036cc783d4ab27", "src_uid": "964ed316c6e6715120039b0219cc653a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nprivate fun readString() = readLine()!!\nprivate fun readInt() = readString().toInt()\nprivate fun readStrings() = readString().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n\nfun main(){\n val b = readInt()\n val g = readInt()\n val n = readInt()\n var count = 0\n for(i in 0..b){\n for(j in 0..g){\n if(i + j == n) count++\n }\n }\n\n println(count)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "230fd5bdc171f13190e9a53ad04c2fbe", "src_uid": "9266a69e767df299569986151852e7b1", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val boys = readLine()!!.toInt()\n val girls = readLine()!!.toInt()\n val participants = readLine()!!.toInt()\n var answer = 0\n for (b in 0..boys) {\n val g = participants - b\n if (g in 0..girls) {\n answer++\n }\n }\n println(answer)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "4783f196cae8f0a0e30aab4e3e1aea4a", "src_uid": "9266a69e767df299569986151852e7b1", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport kotlin.concurrent.thread\nimport java.io.IOException\nimport java.io.BufferedReader\nimport java.io.InputStream\nimport kotlin.*\nimport java.*\nimport java.io.OutputStream\nimport java.io.PrintWriter\nimport java.security.cert.TrustAnchor\nimport java.util.*\nimport kotlin.collections.ArrayList\n\nfun main(){\n val inputStream = System.`in`\n val outputStream = System.out\n val `in` = InputReader(inputStream)\n val out = PrintWriter(outputStream)\n\n val b=`in`.nextInt()\n val g=`in`.nextInt()\n val n=`in`.nextInt(\n )\n\n var ans=0\n for (i in 0..n){\n val j=n-i\n if (i<=b&&j<=g){\n ans+=1\n }\n }\n out.print(ans)\n\n out.close()\n\n}\n\n\ninternal 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 fun nextLong(): Long {\n return next().toLong()\n }\n\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "b291605af5eb81010a4946e6dc1a73e0", "src_uid": "9266a69e767df299569986151852e7b1", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() {\n output {\n val (b, g, n) = readInts(3)\n\n val minB = (n-g).coerceAtLeast(0)\n val maxB = minOf(b, n)\n\n val ans = maxB - minB + 1\n\n println(ans)\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", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "e5baabfb6affa3f797c78e511ce63647", "src_uid": "9266a69e767df299569986151852e7b1", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 m = io.readInt()\n val a = io.readInt()\n val b = io.readInt()\n val c = intArrayOf(n * a, (n / m) * b + (n % m) * a, ((n + m - 1) / m) * b)\n io.println(c.min())\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "b8c7f1750df4c5020fc459a20251874c", "src_uid": "faa343ad6028c5a069857a38fa19bb24", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\nimport kotlin.math.min\n\nfun main(){\n val sc=Scanner(System.`in`)\n val (n,m,a,b) = readLine()!!.split(' ').map{it.toInt()}\n if(a.toDouble()<(b.toDouble()/m.toDouble())){\n print(\"${a*n}\")\n }\n else{\n var d = n/m\n var t = n%m\n var ans=d*b\n ans += min(t*a,b)\n print(\"$ans\")\n }\n\n\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c5d70097e839f14c60d9be46dccce30a", "src_uid": "faa343ad6028c5a069857a38fa19bb24", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 (n, m, a, b) = readInts()\n if (m * a < b) {\n println(n * a)\n } else println(min(((n / m) * b + (n % m) * a), ((n / m) + 1) * b))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "74fb35eb9bbb64fee982fc7a479c45b6", "src_uid": "faa343ad6028c5a069857a38fa19bb24", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, m, ticketPrice, subscriptionPrice) = readLine()!!.split(' ').map { it.toInt() }\n val answer = minOf(((n - 1) / m + 1) * subscriptionPrice, n / m * subscriptionPrice + n % m * ticketPrice)\n println(minOf(answer, n * ticketPrice))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "150e13f40708c59d72206ec3162dd928", "src_uid": "faa343ad6028c5a069857a38fa19bb24", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\n\nfun main(args: Array){\n for (i in 1..5){\n val s = readLine()!!.split(\" \").map(String::toInt)\n for (j in 1..5){\n if (s[j-1]==1) {\n println(abs(3-i)+abs(3-j))\n return\n }\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "102257fbeae47286b5d78e7a20936e2f", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun main() {\n var row = 1\n var col = 1\n\n for (i in 1..5) {\n val arr = readLine()!!.split(\" \")\n if (arr.contains(\"1\")) {\n row = arr.indexOf(\"1\") + 1\n col = i\n }\n }\n\n print(abs(row - 3) + abs(col - 3))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "0878afd6369a063668d3d86d9a148de8", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n fun main(){\n var input = Scanner(System.`in`)\n var row =0;\n var column =0;\n for(i in 0..4){\n var string = input.nextLine()\n if(string.contains(\"1\")){\n row = i+1;\n column = string.indexOf('1')/2+1\n }\n }\n\n print(Math.abs(3-column)+Math.abs(3-row))\n\n }\n\n\n\n\n\n\n\n\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a591415395bf7f6f8fe75018bab8b62d", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args:Array) {\n\tvar arr2d = Array(5, {CharArray(5)})\n\tvar ii: Int = 0\n\tvar jj: Int = 0\n\tfor (i in 0..4) {\n\t\tvar str = readLine()\n\t\tvar strs = str!!.split(' ')\n\t\tvar row = CharArray(5)\n\t\tfor (j in 0..4) {\n\t\t\trow[j] = strs[j].single()\n\t\t\tif (row[j] == '1') {\n\t\t\t\tii = i\n\t\t\t\tjj = j\n\t\t\t}\n\t\t}\n\t\tarr2d[i] = row\n\t}\n\tvar counter = 0\n\tif (ii == 0 || ii == 4)\n\t\tcounter += 2\n\telse if (ii == 1 || ii ==3)\n\t\tcounter++\n\tif (jj == 0 || jj == 4)\n\t\tcounter += 2\n\telse if (jj == 1 || jj ==3)\n\t\tcounter++\n\tprintln(counter)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "eda034ca7c70a4963d304eb2922d66fa", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args:Array){\n val n= readLine()!!.toInt()\n println((2..n).filter{n%it==0}.size)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "98313c44bd587acd43eb9692b61e6dc0", "src_uid": "89f6c1659e5addbf909eddedb785d894", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "36e31773c28e0305b219d1ec5666e3fe", "src_uid": "89f6c1659e5addbf909eddedb785d894", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "20edcd05288fb4643975741e34727c67", "src_uid": "89f6c1659e5addbf909eddedb785d894", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "518a4399ca2c7651ea404ad0a234e325", "src_uid": "89f6c1659e5addbf909eddedb785d894", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!.toInt()\n for (i in 0..6) {\n if ((n + i).toString().toCharArray().map { it.toInt() }.sum() % 4 == 0) {\n println(n + i)\n return\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "321597a08e09a4958c883c36d3919af7", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(){\n var n = readLine()!!.toInt()\n var a = n\n do {\n var sum = 0\n while(n != 0){\n sum += n % 10\n n /= 10\n }\n a++\n n = a\n }while (sum % 4 != 0)\n println(--a)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "6ab47bbc29a6bb32eca72530f732b84f", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 var a = reader.nextInt()\n while (sum(a) % 4 != 0) {\n a++\n }\n writer.println(a)\n }\n\n private fun sum(a: Int): Int {\n var s = 0\n var b = a\n while (b != 0) {\n s += b % 10\n b /= 10\n }\n return s\n }\n\n fun clear() {\n writer.close()\n }\n\n private fun IntArray.gcd(): Int {\n var g = first()\n forEach { g = gcd(g, it) }\n return g\n }\n\n private fun LongArray.gcd(): Long {\n var g = first()\n forEach { g = gcd(g, it) }\n return g\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() {\n writer.println()\n }\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 printLongArray(array: LongArray) {\n array.forEach { writer.print(\"$it \") }\n writer.println()\n }\n\n fun printCharArray(array: CharArray) {\n array.forEach { writer.print(\"$it\") }\n writer.println()\n }\n\n fun close() {\n writer.close()\n }\n\n fun flush() {\n writer.flush()\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9daaa5a7908d1dade3ac3d00fc59502b", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\n\nprivate fun rl() = readLine()!!\nprivate fun ri() = rl().toInt()\nprivate fun readStrings() = rl().split(\" \")\nprivate fun ris() = readStrings().map { it.toInt() }\n\nfun main() {\n val r = BufferedReader(InputStreamReader(System.`in`)).lineSequence().flatMap { it.split(\" \").asSequence() }.iterator()\n val o = PrintWriter(System.out)\n fun ri() = r.next().toInt()\n var n = ri()\n while (true) {\n var s = 0\n var x = n\n while (x > 0) {\n s += x % 10\n x /= 10\n }\n if ((s % 4) == 0) break\n n++\n }\n o.println(n)\n o.close()\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "af10b9e37be513158baccce82596a255", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n readLine()!!.toInt()\n val array = readLine()!!.split(' ').map { it.toInt() }.sorted()\n println(array.joinToString(\" \"))\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "56cbfd97a17827efdeb67bb840528483", "src_uid": "ae20712265d4adf293e75d016b4b82d8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n readLine()\n readLine()!!.split(' ').map(String::toInt).sorted().forEach { print(\"$it \") }\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "0d429aa156163417a22e1a6ab216dd5e", "src_uid": "ae20712265d4adf293e75d016b4b82d8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "11c7e02d7977061009e5383650440ec6", "src_uid": "ae20712265d4adf293e75d016b4b82d8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n readLine()\n println(readLine()!!.split(\" \").map(String::toInt).sorted().joinToString(\" \"))\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "e136694b6b1841d0cf34319b246f9078", "src_uid": "ae20712265d4adf293e75d016b4b82d8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "bd93771b9a2a5a208f86aea3857825ee", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c9489348bd1da3e0c2a949116cbe6b2f", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "66b42107b17e5fafe9351def17e357e4", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "ed612abb6cec0739dece818bd7922c07", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 (n, m) = readInts()\n val a = arrayOfNulls(n + 1)\n val b = readInts()\n for (i in 1..m) {\n for (j in b[i - 1]..n) {\n if (a[j] == null)\n a[j] = b[i - 1]\n else\n break\n }\n }\n for (i in 1..n){\n print(a[i])\n print(' ')\n }\n println()\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "83a1e24653ff8b5b405a346eb8483d52", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Integer.max\n\nfun main() {\n val n = readLine()!!.split(\" \").first().toInt()\n val buttons = readLine()!!.split(\" \").map { it.toInt() }\n val lamps = Array(n){0}\n for (button in buttons) {\n var i = button-1\n while (i _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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "65b3d93dcdead7e791c2c874811d3502", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numLights, _) = readInts()\n val buttons = readInts()\n val lights = IntArray(numLights)\n for (button in buttons) {\n for (pos in button - 1 until lights.size)\n if (lights[pos] == 0) lights[pos] = button\n }\n print(lights.joinToString(\" \"))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "ed7ad72dd1024587edab91691c46b50d", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "e440d3a823d8979adca8cb252f4e2b7e", "src_uid": "488e809bd0c55531b0b47f577996627e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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() }", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "b26eba954b0b0eedfd21daee4a2dd28a", "src_uid": "488e809bd0c55531b0b47f577996627e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "231fd3914eb8855937f9229fdb4487d1", "src_uid": "488e809bd0c55531b0b47f577996627e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "1099d63f3fee9ccf795a89d29253ba6d", "src_uid": "488e809bd0c55531b0b47f577996627e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val m = readLine()!!.toInt()\n val parkBench = Array(n) { readLine()!!.toInt() }\n val max = parkBench.max()\n val maximumMax = max?.let {it + m}\n var minimumMax = max ?: 1\n var countPeople = m\n for(bIndex in parkBench.indices) {\n if (parkBench[bIndex] < minimumMax) {\n val sittedPeople = minimumMax - parkBench[bIndex]\n parkBench[bIndex] += sittedPeople\n countPeople -= sittedPeople\n if(countPeople <= 0) break\n }\n }\n if (countPeople <= 0) {\n println(\"$minimumMax $maximumMax\")\n } else {\n if (countPeople % n != 0){\n println(\"${countPeople / n + 1 + minimumMax} $maximumMax\")\n } else {\n println(\"${countPeople/n + minimumMax} $maximumMax\")\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation", "binary search"], "code_uid": "ee9cae4150bb5c70503f22ae3b1dcad3", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nobject Benches{\n fun getMaxAndMinK(n: Int, m: Int, benches: IntArray) : IntArray{\n val ans = IntArray(2)\n val max = benches.max()\n ans[1] = m + max!!\n val minPQ = PriorityQueue()\n\n for (i in 0 until n){\n minPQ.add(benches[i])\n }\n\n\n for (i in 0 until m){\n minPQ.add(minPQ.poll() + 1)\n }\n\n ans[0] = minPQ.max()!!\n\n return ans\n }\n}\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val n = br.readLine().toInt()\n val m = br.readLine().toInt()\n val benches = IntArray(n)\n\n for (i in 0 until n){\n benches[i] = br.readLine().toInt()\n }\n val ans = Benches.getMaxAndMinK(n, m, benches)\n println(ans[0].toString() + \" \" + ans[1])\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation", "binary search"], "code_uid": "f8e9ba0ef0f3ffda1697bca308d70561", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val m = readLine()!!.toInt()\n var t = 0\n var maks = 0\n for (i in 1..n)\n {\n val a = readLine()!!.toInt()\n t+=a\n if (a > maks)\n maks = a\n }\n var mini = (t+m)/n\n if (mini * n < t+m)\n mini++\n if (maks > mini) \n mini = maks\n println(\"$mini ${maks+m}\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation", "binary search"], "code_uid": "255ce977640c50e44f79b801431ab737", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n val m = scanner.nextInt()\n val a = mutableListOf()\n while (scanner.hasNextInt()) {\n a.add(scanner.nextInt())\n }\n\n a.sortByDescending { it }\n val firstValue = a[0] + m\n for (i in 0 until m) {\n a.sortBy { it }\n a[0]++\n }\n a.sortByDescending { it }\n print(a[0])\n print(\" \")\n print(firstValue)\n}\n\n", "lang_cluster": "Kotlin", "tags": ["implementation", "binary search"], "code_uid": "dde9c430808ac4a986883ff9250d9199", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (p, q) = readInts()\n\n fun sieve(n: Int): List {\n val isPrime = MutableList(n + 1) { true }\n isPrime[0] = false\n isPrime[1] = false\n for (x in 2..n) {\n if (!isPrime[x]) continue\n for (u in (2 * x)..n step x) isPrime[u] = false\n }\n\n return isPrime\n }\n\n fun isPalindrome(d: Int): Boolean {\n val num = d.toString()\n if (num.length == 1) return true\n else {\n for (i in num.indices) if (num[i] != num[num.length - i - 1]) return false\n return true\n }\n }\n\n val isPrime = sieve(2000000)\n\n var primes = 0L\n var palindromes = 0L\n\n var currNumber = 1\n var ans = 0\n while (currNumber < 2000000) {\n if (isPalindrome(currNumber)) palindromes++\n if (isPrime[currNumber]) primes++\n if (q * primes <= p * palindromes) {\n ans = currNumber\n// println(\"$currNumber -> $primes $palindromes\")\n }\n currNumber++\n }\n\n println(ans)\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\n\nprivate fun readStrings() = readLn().trim().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "binary search", "number theory"], "code_uid": "cf8dfe0683e9169a79434751ccd91251", "src_uid": "e6e760164882b9e194a17663625be27d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.collections.HashMap\n\n\nfun main() {\n val scan = Scanner(System.`in`)\n\n val n = scan.nextInt()\n scan.nextLine()\n val sb = StringBuilder(scan.nextLine())\n val map = HashMap()\n\n for (c in sb) {\n if (map[c] == null) map[c] = 0\n map[c] = map[c]!! + 1\n }\n\n solve(sb, map)\n\n println(n - sb.length)\n}\n\nfun solve(sb: java.lang.StringBuilder, map: MutableMap) {\n for (c in 'z' downTo 'b') {\n if (map[c] == null || map[c] == 0) continue\n for (i in sb.indices) {\n if (sb[i] == c) {\n if (i > 0 && sb[i - 1] == c - 1 || i < sb.length - 1 && sb[i + 1] == c - 1) {\n map[sb[i]] = map[sb[i]]!! - 1\n sb.deleteCharAt(i)\n return solve(sb, map)\n }\n }\n }\n }\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "strings", "constructive algorithms"], "code_uid": "b75931cacbf4e076caa34830eec529d1", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n\nfun main() {\n readLn()\n val s = readLn()\n val t = s.reduceAdj()\n println(s.length - t.length)\n}\n\nfun String.reduceAdj(): String {\n var t = this\n for (z in 'z' downTo 'a')\n t = t.reduceAdj(z)\n return t\n}\n\ntailrec fun String.reduceAdj(z: Char): String =\n when (val improved = removeAdj(z)) {\n this -> this\n else -> improved.reduceAdj(z)\n }\n\nfun String.removeAdj(z: Char): String = this\n .filterIndexed { i, c -> i == 0 || c != z || this[i - 1] != c.prev() }\n .filterIndexed { i, c -> i + 1 == length || c != z || c.prev() != this[i + 1] }\n\nfun Char.prev() =\n when (this) {\n 'a' -> '#'\n in 'b'..'z' -> this - 1\n else -> error(\"Unexpected char '$this'\")\n }\n\nfun readLn(): String = readLine() ?: error(\"EOF\")\n", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "strings", "constructive algorithms"], "code_uid": "79a7ceb4e57e6bbf7c9f2e3cdb1b7bf0", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n readLine()\n val listo = LinkedList(readLine()!!.toList())\n val original = listo.size\n for (chara in 'z' downTo 'b') {\n val iterator = listo.listIterator()\n while (iterator.hasNext()) {\n //println(listo)\n if (iterator.next() == chara) {\n iterator.previous()\n if (iterator.hasPrevious()) {\n if (iterator.previous() == chara - 1) {\n iterator.next()\n iterator.next()\n iterator.remove()\n continue\n }\n iterator.next()\n iterator.next()\n } else {\n iterator.next()\n }\n if (iterator.hasNext()) {\n if (iterator.next() == chara - 1) {\n iterator.previous()\n iterator.previous()\n iterator.remove()\n if (iterator.hasPrevious()) {\n iterator.previous()\n }\n continue\n }\n iterator.previous()\n }\n }\n }\n }\n println(original - listo.size)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "strings", "constructive algorithms"], "code_uid": "0e80e71148078111f58acd3cec4901f8", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n\nfun main() {\n readLn()\n val s = readLn()\n val t = s.reduceAdj()\n println(s.length - t.length)\n}\n\nfun String.reduceAdj(): String {\n var t = this\n for (z in 'z' downTo 'a')\n t = t.reduceAdj(z)\n return t\n}\n\ntailrec fun String.reduceAdj(z: Char): String =\n when (val improved = removeAdj(z)) {\n this -> this\n else -> improved.reduceAdj()\n }\n\nfun String.removeAdj(z: Char): String = this\n .filterIndexed { i, c -> i == 0 || c != z || this[i - 1] != c.prev() }\n .filterIndexed { i, c -> i + 1 == length || c != z || c.prev() != this[i + 1] }\n\nfun Char.prev() =\n when (this) {\n 'a' -> '#'\n in 'b'..'z' -> this - 1\n else -> error(\"Unexpected char '$this'\")\n }\n\nfun readLn(): String = readLine() ?: error(\"EOF\")\n", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "strings", "constructive algorithms"], "code_uid": "641c7b82297889401097e53d5041dc31", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n val n = scanner.nextLong()\n val k = scanner.nextLong()\n\n if (k <= (n + 1) / 2) {\n System.out.println(2 * k - 1)\n } else {\n System.out.println(2 * (k - (n + 1) / 2))\n }\n\n\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "83e3dcf8e331e41e930cbd129c2d863a", "src_uid": "1f8056884db00ad8294a7cc0be75fe97", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (n, k) = readLine()!!.split(regex = \"\\\\s\".toRegex()).map { it.toLong() }.toTypedArray()\n val e = k - (n/2 + n%2)\n println( if ( e <= 0 ) k * 2 - 1 else e * 2 )\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "f0bd9c5ed888636a61a3d0a0f9782735", "src_uid": "1f8056884db00ad8294a7cc0be75fe97", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nfun main(args: Array) {\n var sc = Scanner(System.`in`)\n var n = sc.nextLong()\n var k = sc.nextLong()\n if (n % 2 == 0L) {\n if (k > n / 2) {\n println((k * 2 - n))\n } else println((k * 2 - 1))\n } else {\n if (k > n / 2 + 1) {\n println((k * 2 - n) - 1)\n } else println((k * 2 - 1))\n }\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "7b717f95151f1880c39d66d07e4802bc", "src_uid": "1f8056884db00ad8294a7cc0be75fe97", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, k) = readLine()!!.split(\" \").map { it.toLong() }\n println(ex1(n, k))\n}\n\nfun ex1(n: Long, k: Long): Long {\n val a = (n + 1) / 2\n return when {\n k > a -> (k - a) * 2\n else -> (k - 1) * 2 + 1\n }\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "3d4616ff462dd3b48b846e93abf711d5", "src_uid": "1f8056884db00ad8294a7cc0be75fe97", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.StringTokenizer\n\nval mod = (1e9 + 7).toInt()\n\nfun main(args: Array) {\n val sc = FastScanner(System.`in`)\n\n val n = sc.nextLong()\n val m = sc.nextLong()\n val k = sc.nextInt()\n\n if (k == -1 && (n + m) % 2 == 1L) {\n println(0)\n return\n }\n\n\n println(pow(pow(2, m - 1), n - 1))\n\n}\n\nfun pow(x: Long, y: Long): Long {\n var y = y % (mod - 1)\n\n var res = 1L\n var deg = x\n while (y > 0) {\n if (y % 2 == 1L) {\n res = (res * deg) % mod\n }\n deg = (deg * deg) % mod\n y /= 2\n }\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", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "combinatorics", "number theory"], "code_uid": "b704f70a44aa9018827fbb24e7dfdd75", "src_uid": "6b9eff690fae14725885cbc891ff7243", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.StringTokenizer\n\nval mod = (1e9 + 7).toInt()\n\nfun main(args: Array) {\n val sc = FastScanner(System.`in`)\n\n val n = sc.nextLong()\n val m = sc.nextLong()\n val k = sc.nextInt()\n\n if (k == -1 && (n + m) % 2 == 1L) {\n println(0)\n return\n }\n\n println(2L pow m - 1 pow n - 1)\n}\n\ninfix fun Long.pow(n: Long): Long {\n var n = n % (mod - 1)\n var a = this\n\n var res = 1L\n while (n > 0) {\n if (n % 2 == 1L) res = (res * a) % mod\n\n a = (a * a) % mod\n n /= 2\n }\n return res\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", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "combinatorics", "number theory"], "code_uid": "300c3bbf144a98030b24c9b51b368f9a", "src_uid": "6b9eff690fae14725885cbc891ff7243", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nval modulo : Long = 1000000007L\n\ntailrec fun modPow(n : Long, m : Long) : Long {\n if(m == 0L) return 1\n if(m == 1L) return n % modulo\n val vur = if(m % 2L == 0L) 1L else n % modulo\n val a = modPow(n,m / 2) % modulo;\n return (vur % modulo * a % modulo * a % modulo) % modulo\n}\n\nfun solve() {\n var n = nextLong()\n var m = nextLong()\n var k = nextInt()\n if(k == -1 && (((n % 2) + (m % 2)) % 2) != 0L){\n pw.println(0)\n }else pw.println(modPow(modPow(2, n - 1), m - 1))\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\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}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "combinatorics", "number theory"], "code_uid": "8c46a76581cdbff415ae28da705ecf4e", "src_uid": "6b9eff690fae14725885cbc891ff7243", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c1df2ffbf20a7c52b97ce1008f3d2e01", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "f57399f2d9c4711a151e1c10abfbf132", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "39e33c079f81c30425f0fc9fc11c99d3", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "727650aa539b4365376e5f6583ba3809", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.*\nimport kotlin.concurrent.fixedRateTimer\n\nfun PrintWriter.solve(sc: FastScanner) {\n val a = sc.nextInt()\n val b = sc.nextInt()\n val c = sc.nextInt()\n val d = sc.nextInt()\n var ans = 0L\n var count = 0L\n for (s in a + b .. b + c) {\n if (s in a + b .. b + b) count++\n if (s in a + c + 1 .. b + c + 1) count--\n ans += count * maxOf(minOf(s, d + 1) - c, 0)\n }\n println(ans)\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", "lang_cluster": "Kotlin", "tags": ["two pointers", "math", "implementation", "binary search"], "code_uid": "e5cdcf9cd057b3c394657c29ea2ef8d3", "src_uid": "4f92791b9ec658829f667fcea1faee01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.*\nfun readint()=readLine()!!.toInt()\nfun readll()=readLine()!!.toLong()\nfun readstring()=readLine()!!\nfun readline_int()=(readLine()!!.split(\" \").map{it.toInt()}).toIntArray()\nfun readline_ll()=(readLine()!!.split(\" \").map{it.toLong()}).toLongArray()\n\nfun solve() {\n val (A,B,C,D) = readline_int();\n var sum = 0L;\n for (i in B..C) {\n val tar = C - i;\n sum += max(min(B-tar+1,B-A+1),0);\n }\n var ans = 0L;\n for (i in C..D) {\n var mn = i - C;\n var mx = i - B;\n mn = max(mn, A);\n mx = min(mx, B);\n sum -= max(mx - mn + 1, 0);\n ans += sum;\n }\n println(ans);\n}\nfun main(args: Array) {\n val t = 1;\n repeat(t) {\n solve();\n }\n} ", "lang_cluster": "Kotlin", "tags": ["two pointers", "math", "implementation", "binary search"], "code_uid": "0757fb2110eeca9d5284704b1ab205c6", "src_uid": "4f92791b9ec658829f667fcea1faee01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//region TEMPLATE\n@file:Suppress(\"CanBeVal\")\n\nimport java.io.*;\nimport java.io.BufferedReader\nimport java.math.BigInteger\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main(args: Array) {\n if (args.isNotEmpty() && args.first() == \"file\") {\n reader = BufferedReader(FileReader(\"input.txt\"))\n out = PrintWriter(FileWriter(\"output.txt\"))\n do {\n solve()\n out.println(\"\\n\")\n out.flush()\n } while (reader.readLine() != null)\n } else {\n reader = BufferedReader(InputStreamReader(System.`in`))\n out = PrintWriter(OutputStreamWriter(System.out))\n solve()\n }\n reader.close()\n out.close()\n}\n\nlateinit var out: PrintWriter\nlateinit var reader: BufferedReader\nvar tokenizer: StringTokenizer? = null\nfun read(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(readLn())\n }\n return tokenizer!!.nextToken()\n}\n\nfun readInt() = read().toInt()\nfun readLong() = read().toLong()\nfun readLn() = reader.readLine()!!\nfun readInts() = readLn().split(\" \").map { it.toInt() }\nfun readInts(sz: Int) = Array(sz) { readInt() }\nfun readLongs() = readLn().split(\" \").map { it.toLong() }\nfun readLongs(sz: Int) = Array(sz) { readLong() }\nfun print(b: Boolean) = out.print(b)\nfun print(i: Int) = out.print(i)\nfun print(d: Double) = out.print(d)\nfun print(l: Long) = out.print(l)\nfun print(s: String) = out.print(s)\nfun print(message: Any?) = out.print(message)\nfun print(a: Array) = a.forEach { print(\"$it \") }\nfun print(a: Array) = a.forEach { print(\"$it \") }\nfun print(a: Collection) = a.forEach { print(\"$it \") }\nfun println(b: Boolean) = out.println(b)\nfun println(i: Int) = out.println(i)\nfun println(d: Double) = out.println(d)\nfun println(l: Long) = out.println(l)\nfun println(s: String) = out.println(s)\nfun println() = out.println()\nfun println(message: Any?) = out.println(message)\nfun println(a: Array) {\n a.forEach { print(\"$it \") }\n println()\n}\n\nfun println(a: IntArray) {\n a.forEach { print(\"$it \") }\n println()\n}\n\nfun println(a: Collection) {\n a.forEach { print(\"$it \") }\n println()\n}\n\nconst val M7 = 1000000007L\nconst val M9 = 1000000009L\nconst val MFFT = 998244353L\nfun zero(sz: Int) = IntArray(sz)\nfun zeroL(sz: Int) = LongArray(sz)\nfun init(vararg elements: T) = elements\nfun VI(n: Int = 0, init: Int = 0) = MutableList(n) { init }\nfun VVI(n: Int = 0, m: Int = 0, init: Int = 0) = MutableList(n) { VI(m, init) }\nfun , T2 : Comparable> pairCmp(): Comparator> {\n return Comparator { a, b ->\n val res = a.first.compareTo(b.first)\n if (res == 0) a.second.compareTo(b.second) else res\n }\n}\n//endregion\n\nfun solve() {\n var (a, b, c, d) = readInts(4)\n var pr = LongArray(b + c + 2)\n for(i in b..c){\n pr[i + a]++\n pr[i + b + 1]--\n }\n repeat(2){\n for(i in 1 until pr.size){\n pr[i] += pr[i - 1]\n }\n }\n var ans = 0L\n for (i in c..d) {\n if (i < pr.size){\n ans += pr.last() - pr[i]\n }\n }\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["two pointers", "math", "implementation", "binary search"], "code_uid": "d124bc2393bffd94ac4d24e4d1eee2db", "src_uid": "4f92791b9ec658829f667fcea1faee01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport kotlin.math.min\n\nfun main() {\n val (a, b, c, d) = readNumbers()\n println(solve(a, b, c, d))\n}\n\nfun solve(a: Int, b: Int, c: Int, d: Int): Long {\n var res = 0L\n for (k in a + b..b + c) {\n val k0 = k - a - b\n val t = min(k0, b - a) + min(k0, c - b) - k0 + 1L\n if (t > 0)\n if (k > d) {\n res += t * (d - c + 1)\n } else if (k > c) {\n res += t * (k - c)\n }\n }\n return res\n}\n\n\nfun readNumber() = readLine()!!.toInt()\n\nfun readNumbers(line: String = readLine()!!): IntArray {\n return line\n .split(\" \")\n .map { it.toInt() }\n .toIntArray()\n}", "lang_cluster": "Kotlin", "tags": ["two pointers", "math", "implementation", "binary search"], "code_uid": "2439f399e7899b86d3606b53f4735562", "src_uid": "4f92791b9ec658829f667fcea1faee01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "graphs"], "code_uid": "6a2d847da68bff130fa31a0c42ac75a8", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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//}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "graphs"], "code_uid": "47012a3d68cc6175e283fc93c6e03532", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Math.max\nimport java.util.*\n\nfun main(args: Array): Unit = with(Scanner(System.`in`)) {\n val (n, k) = arrayOf(nextInt(), nextInt())\n var maximum = 0\n for(i in 0 until n) {\n val x = nextInt()\n if(k % x == 0)\n maximum = max(maximum, x)\n }\n println(k / maximum)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "074061f6ae61b82aabe75e094b5530f6", "src_uid": "80520be9916045aca3a7de7bc925af1f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\n\nclass A {\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 k = reader.nextInt()\n val buckets: List = (1..n)\n .map { reader.nextInt() }\n writer.println(solve(buckets, k))\n\n writer.close()\n }\n\n fun solve(buckets : List, size : Int) : Int {\n return buckets\n .filter { size % it == 0 }\n .map {size / it}\n .min()!!\n }\n}\n\nfun main(args : Array) {\n A().solve(System.`in`, System.out)\n}\n\nprivate 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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "dac163d20b9060d8545cc7b3285918d6", "src_uid": "80520be9916045aca3a7de7bc925af1f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val garden = readLine()!!.split(\" \").map { it.toInt() }\n val buckets = readLine()!!.split(\" \").map { it.toInt() }.sortedBy { -it }\n for (x in buckets) {\n if (garden[1] % x == 0) {\n print(garden[1]/x)\n return\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "e9163a56fbfaf4363cd14ce1385e7baa", "src_uid": "80520be9916045aca3a7de7bc925af1f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\ninfix fun Int.isDivisor(other: Int): Boolean {\n return other % this == 0\n}\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n\n val n = nextInt()\n val k = nextInt()\n val array = IntArray(n) { nextInt() }\n\n val answer = k / array.filter { it isDivisor k }.max()!!\n print(answer)\n\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "26ae6bb7964f58912b2376364cf64cfe", "src_uid": "80520be9916045aca3a7de7bc925af1f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "828bc2c85017b6345dff50557afa4817", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "989f7332f362f24aad9be5efd8b44826", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4db3dcc174d9abef83c802992c973332", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d1b6d827d1019c26a80447347ac6bd86", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 = readLn();\n\tvar lPos = 0;\n\tvar flag:Boolean = false;\n\tfor(i in n.indices){\n\t\tif(n[i] == '4') lPos++;\n\t\telse lPos = 0;\n\t\tif(lPos > 2 || (n[i] != '4' && n[i] != '1')){\n\t\t\tflag = true;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif(n[0] != '4' && !flag) println(\"YES\");\n\telse println(\"NO\");\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy"], "code_uid": "7480497dc21fd1ad1db72055e4e20f25", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.regex.Pattern\n\nfun main(args: Array)\n{\n\n\n var text = readLine()!!\n val b = Pattern.matches(\"([1]([4]{1,2})?)+\", text)\n if (b)\n {\n print(\"YES\")\n }\n else\n print(\"NO\")\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy"], "code_uid": "ee657ddbabedc9bba9d8f9723da2428a", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n var n = readLine()!!.split(\"1\")\n var ans = true\n if (!n[0].equals(\"\")) {\n ans = false\n } else {\n for (i in n) {\n if (!i.equals(\"\") && !i.equals(\"4\") && !i.equals(\"44\")) {\n ans = false\n }\n }\n }\n if (ans) println(\"YES\") else println(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy"], "code_uid": "c05ba32a49231295b4078b7768268612", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n \n var text = readLine()!!\n \n text= text.replace(\"144\",\" \")\n text =text.replace(\"14\",\" \")\n text =text.replace(\"1\",\" \")\n \n if (text.trim().isEmpty())\n {\n print(\"YES\")\n }\n else\n print(\"NO\")\n \n \n \n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy"], "code_uid": "cf85b8f9bf0618eab82834b376a06929", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun main() {\n var n = readLine()!!.toInt()\n var str = readLine()!!\n var totalTrue = n\n\n var x = 0\n var y = 0\n\n\n\n for (i in str) {\n when (i) {\n 'U'->{\n y++\n }\n 'D'->{\n y--\n }\n 'L'->{\n x--\n }\n 'R'->{\n x++\n }\n }\n }\n println(n- (abs(x)+ abs(y)))\n\n\n\n\n\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "46a56a38a06ff586440dd488e459a2de", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val quantity= readLine()!!.toInt()\n val commands= readLine()!!\n val commandMap= mutableMapOf('L' to 0, 'R' to 0, 'U' to 0, 'D' to 0)\n for (command in commands){\n commandMap[command]= commandMap[command]!! +1\n }\n println(quantity-(Math.abs(commandMap['U']!! - commandMap['D']!!)+Math.abs(commandMap['L']!! - commandMap['R']!!)))\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "8712edbf9a06d1d05c94f2d711ee1eb6", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*;\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readDouble() = readLn().toDouble() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of ints\n\nfun main(args: Array) {\n solve()\n /*\n val t = readInt()\n repeat(t) {\n solve()\n }\n */\n}\n\nfun solve() {\n readLn()\n val s = readLn()\n var l = 0\n var d = 0\n var u = 0\n var r = 0\n for(x in s) {\n if(x == 'L') l++\n if(x == 'R') r++\n if(x == 'D') d++\n if(x == 'U') u++\n }\n println(2*(Math.min(l,r) + Math.min(d,u)))\n}\n\n/*\nuseful things:\nto read in multiple ints in one line\nval (n, m, k) = readInts()\n\nJava: int[] dx = new int[]{-1,1,0,0}\nKotlin: val dx = arrayOf(-1, 1, 0, 0)\n*/", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "36439ee579e0dc53c1fc18d930db3d9a", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val steps = readLine()!!.toCharArray()\n var x = 0\n var y = 0\n var stepCount = 0\n var max = 0\n while (stepCount < n) {\n when (steps[stepCount]) {\n 'L' -> {\n if (steps.contains('R')) {\n steps[stepCount] = ' '\n steps[steps.indexOf('R')] = ' '\n max++\n } else x--\n }\n 'R' -> {\n if (steps.contains('L')) {\n steps[stepCount] = ' '\n steps[steps.indexOf('L')] = ' '\n max++\n } else x++\n }\n 'U' -> {\n if (steps.contains('D')) {\n steps[stepCount] = ' '\n steps[steps.indexOf('D')] = ' '\n max++\n } else y++\n }\n 'D' -> {\n if (steps.contains('U')) {\n steps[stepCount] = ' '\n steps[steps.indexOf('U')] = ' '\n max++\n } else y--\n }\n }\n stepCount++\n }\n println(max * 2)\n\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "d7e179d7c36dfe7eeadcf276f62e09e8", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\n\nfun main(){\n var n = nl()\n var best = prod(n)\n while(n>0){\n best = Math.max(best, prod(n))\n n = red(n)\n }\n println(best)\n}\n\nfun red(n: Long): Long{\n var mod = 10L\n while((n % mod)/(mod/10L) == 9L){\n mod *= 10L\n }\n return n - mod/10L\n}\n\nfun prod(n: Long) = n.toString().map { ch -> ch-'0' }.reduce{a,b -> a*b}\n\nvar input = Scanner(System.`in`)\n\nfun ni() = input.nextInt()\n\nfun nia(n: Int) = Array(n) { ni() }\n\nfun nim(n: Int, m: Int) = Array(n) { nia(m) }\n\nfun nl() = input.nextLong()\n\nfun nla(n: Int) = Array(n) { nl() }\n\nfun nlm(n: Int, m: Int) = Array(n) { nla(m) }\n\nfun ns() = input.next()\n\nfun nsa(n: Int) = Array(n) { ns() }", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "f050816a12a4629695cc16f49401e7cf", "src_uid": "38690bd32e7d0b314f701f138ce19dfb", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "val Long.value: Long\n get() {\n if (this == 0L) {\n return 0L\n }\n var cur = this\n var ans = 1L\n while (cur != 0L) {\n ans *= cur % 10\n cur /= 10\n }\n return ans\n }\n\nfun main(args: Array) {\n var n = readLine()!!.toLong()\n var i = 1L\n var max = n.value\n while (n >= 0) {\n val cur_num = n % (i * 10) / i\n if (cur_num != 9L) {\n n -= cur_num*i\n n += 9L*i\n n -= 10*i\n val value = n.value\n if (value > max) {\n max = value\n }\n }\n i *= 10L\n }\n println(max)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "ed254da9220232ea3f78b3152625c623", "src_uid": "38690bd32e7d0b314f701f138ce19dfb", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val scanner = Scanner(System.`in`)\n var n = scanner.nextLong()\n\n var max = 1L\n var nines = 1L\n\n while (n > 0) {\n val r = n % 10\n n /= 10\n val rMinusOne = if (r == 1L && n == 0L) 1 else r - 1\n max = if (r * max > rMinusOne * nines) {\n r * max\n } else {\n rMinusOne * nines\n }\n nines *= 9\n }\n\n System.out.println(max)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "d2dd31fa538719aa7f2a323b93e33b52", "src_uid": "38690bd32e7d0b314f701f138ce19dfb", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.pow\n\nfun main() {\n fun String.prod(): Int {\n var sol = 1\n this.forEach { sol *= it - '0' }\n return sol\n }\n\n val ns = readLine()!!\n var solM = ns.prod()\n if (ns.length == 1) {\n print(ns)\n } else {\n for (k in 0 until ns.length - 1) {\n val candidate =\n ns.substring(0, k).prod() * max(1, (ns[k] - '0' - 1)) * 9.0.pow((ns.length - k - 1).toDouble()).toInt()\n if (candidate > solM) {\n solM = candidate\n }\n }\n print(solM)\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "2f1d5ee547ca144b997066d84539fb2b", "src_uid": "38690bd32e7d0b314f701f138ce19dfb", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val x = scanner.nextLong()\n println((x + 4) / 5)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "f9b3f1cef69682fa47595cd6a85079b5", "src_uid": "4b3d65b1b593829e92c852be213922b6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n // Your code here!\n var n = (readLine()!!).toInt()\n\n println((n+4)/5)\n}\n ", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "84cdff39459e2e7da476275ef99287b6", "src_uid": "4b3d65b1b593829e92c852be213922b6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 x = readInt()\n\n println(x / 5 + if (x % 5 == 0) 0 else 1)\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "7f2cb50975711317c812e178514e7e3c", "src_uid": "4b3d65b1b593829e92c852be213922b6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val x = readLine()!!.toInt()\n\n println( (x / 5) + if (x % 5 == 0) 0 else 1 )\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "7c1552843f4e68aadde269d190cab3b1", "src_uid": "4b3d65b1b593829e92c852be213922b6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val reader = Scanner(System.`in`)\n val s = reader.nextLine()\n var capitalLetters=0\n s.forEach {\n if(it.toInt()<91){\n capitalLetters++\n }\n }\n if(capitalLetters>s.length.div(2))\n println(s.toUpperCase())\n else\n println(s.toLowerCase())\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "6074c0a17a2207b6e713920b2d2e6f28", "src_uid": "b432dfa66bae2b542342f0b42c0a2598", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package problem59A\n\nfun convertWord(word: String): Any? {\n val numUppercase = word.count { it.isUpperCase() }\n val numLowercase = word.length - numUppercase\n\n if (numUppercase > numLowercase) {\n return word.toUpperCase()\n }\n return word.toLowerCase()\n}\n\nfun main() {\n val word = readLine()!!.toString()\n println(convertWord(word))\n}\n", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "ee44a8c4f3838ce71f3f544aed7a6ff1", "src_uid": "b432dfa66bae2b542342f0b42c0a2598", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val word = readLine()!!\n val upperCaseCount = word.count { it.isUpperCase() }\n val lowerCaseCount = word.count() - upperCaseCount\n if (upperCaseCount > lowerCaseCount) {\n println(word.toUpperCase())\n }\n else {\n println(word.toLowerCase())\n }\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "b37576932fd1072b5f667157c4d5fe55", "src_uid": "b432dfa66bae2b542342f0b42c0a2598", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val x = readLine()!!\n val (y, z) = x.partition { it.isUpperCase() }\n print(if (y.length > z.length) x.toUpperCase() else x.toLowerCase())\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "4a40d84fc7111f90fc74679ecb473378", "src_uid": "b432dfa66bae2b542342f0b42c0a2598", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (a, b) =readLine()!!.split(' ')\n var n = a!!.toLong()\n var k = b!!.toLong()\n while(k>0)\n {\n var lastDigit = n % 10\n if(lastDigit > k)\n {\n n -= k\n k = 0\n }\n else\n {\n n = (n / 10)*10\n k -= lastDigit\n }\n if(n % 10L == 0L && k > 0)\n {\n k--\n n /= 10\n }\n }\n print(n)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "e420eb4c093992737dcf8a604eca0a54", "src_uid": "064162604284ce252b88050b4174ba55", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// 02.09.2019\n\n\nimport java.util.*\nimport 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 { x: String -> x.toInt() } // list of ints\n\nfun main ()\n{\n val (nn, kk) = readInts ();\n var n = nn;\n var k = kk;\n while( k != 0 )\n {\n k--;\n if ( n % 10 == 0 )\n n /= 10;\n else\n n --;\n }\n println (\"$n\");\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "24df07b3b7b5ed6566e621284a704224", "src_uid": "064162604284ce252b88050b4174ba55", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n println(subtract(readLine()!!))\n}\n\nfun subtract(input: String) : String {\n val (n, k) = input.split(\" \")\n\n return subtract(n, k.toInt());\n}\n\nprivate fun subtract(n: String, k: Int) : String {\n if (k == 0) return n\n\n return if (n.last() == '0') {\n subtract(n.substring(0, n.length - 1), k - 1)\n } else {\n subtract(n.toInt(), k).toString()\n }\n}\n\nprivate fun subtract(n: Int, k: Int) : Int {\n if (k == 0) return n\n\n return if (n % 10 == 0) {\n subtract(n / 10, k - 1)\n } else {\n subtract(n - 1, k - 1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "74ec37f713c383a57a34b3756d9c1b4a", "src_uid": "064162604284ce252b88050b4174ba55", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (n, k) = readLine()!!.split(' ').map { it.toInt() }\n\n repeat(k) {\n val str = n.toString()\n when (str.last()) {\n '0' -> n /= 10\n else -> n -= 1\n }\n }\n println(n)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2206da0e5d23b84ddeeeae5d0b6d3d60", "src_uid": "064162604284ce252b88050b4174ba55", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.StringBuilder\nimport java.util.Scanner\n\nfun main(args: Array) {\n Scanner(System.`in`).use {\n val expression = it.next()\n val length = expression.length\n val bucket = ByteArray(4)\n\n for (i in 0 until length step 2) {\n val rawDigit = expression[i]\n val digit = Character.digit(rawDigit, 10)\n bucket[digit]++\n }\n\n val plus = \"+\"\n val builder = StringBuilder(length)\n for (i in 1..3) {\n val count = bucket[i]\n for (k in 0 until count) {\n builder.append(i).append(plus)\n }\n }\n val end = builder.length\n val start = end - 1\n builder.replace(start, end, \"\")\n println(builder)\n }\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "strings", "implementation", "greedy"], "code_uid": "ed62c612fd024f0bf675767b58c781ef", "src_uid": "76c7312733ef9d8278521cf09d3ccbc8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val arguments = reader.readLine().split('+').map { it.toInt() }\n val resultString = arguments.sorted().joinToString(separator = \"+\")\n println(resultString)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "strings", "implementation", "greedy"], "code_uid": "ee04feb366997252d9a4de59260a0e5f", "src_uid": "76c7312733ef9d8278521cf09d3ccbc8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var a = readLine()!!.split(\"+\").sorted()\n var ans: String = \"\"\n for (i in a)\n ans += i + \"+\"\n print(ans.dropLast(1))\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "strings", "implementation", "greedy"], "code_uid": "ef85265ffb194b2f6aee9e4c24db9ed3", "src_uid": "76c7312733ef9d8278521cf09d3ccbc8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private fun readLn() = readLine()!! // string line\n\nfun main() {\n println(readLn().split(\"+\").sorted().joinToString(\"+\"))\n}\n", "lang_cluster": "Kotlin", "tags": ["sortings", "strings", "implementation", "greedy"], "code_uid": "05f393b46cd4a7c1fa8b8c63f8f138cc", "src_uid": "76c7312733ef9d8278521cf09d3ccbc8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 }", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "74978c20de40e9d0f1b52b4be5ae3a47", "src_uid": "a8c14667b94b40da087501fd4bdd7818", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "3174f383c829d6c354612153159fa906", "src_uid": "a8c14667b94b40da087501fd4bdd7818", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "f6195c817befb0dbb0d24e6b4fc8bc61", "src_uid": "a8c14667b94b40da087501fd4bdd7818", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n\n print(if (readLine()!!.toCharArray().distinct().size % 2 == 0) \"CHAT WITH HER!\" else \"IGNORE HIM!\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "791a7d8868029aedea6a4ead9d9c2654", "src_uid": "a8c14667b94b40da087501fd4bdd7818", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "5db93ce297b6aa4444708d14f404ce6d", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "6cddcbc536c71ec6a1d40af009e12062", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args: Array) {\n readLine() !!\n val count = readLine()!!.toLowerCase().toSet().size\n println(if (count == 26) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "92d2efeba57e01125922e8c06b7a5d09", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 }", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "b160378218862ba90aa813f55c754d02", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\n val s = sc.next()\n\n for (i in 0 until s.length) {\n if (s[i] == '1') {\n var sum = 0\n for (j in i until s.length) {\n if (s[j] == '0') sum += 1\n }\n if (sum >= 6) println(\"yes\")\n else println(\"no\")\n return\n\n }\n }\n println(\"no\")\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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "ac42406431b22dec11947f453027207b", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n println(if (readLine()!!.matches(\".*1+(01*){6,}\".toRegex())) \"yes\" else \"no\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "78ec961cf71471ceaf2b86c753c9863b", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var str = readLine()!!\n var flag = false\n var index = -1\n var count = 0\n\n for (i in 0 until str.length) {\n if (str[i] == '1') {\n flag = true\n index = i\n break\n }\n }\n\n if (index != -1) {\n for (i in index + 1 until str.length) {\n if (str[i] == '0') {\n count++\n }\n }\n\n if (count >= 6) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n return\n }\n println(\"NO\")\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5185a2bb96f57cba2cd6844b2b867ed5", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nclass A internal constructor(inputStream: InputStream, val out: PrintWriter) {\n companion object {\n val ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n }\n\n\n private val br = BufferedReader(InputStreamReader(inputStream))\n private var st = StringTokenizer(\"\")\n\n internal fun hasNext(): Boolean {\n while (!st.hasMoreTokens()) {\n val readLine = br.readLine() ?: return false\n st = StringTokenizer(readLine)\n }\n return true\n }\n\n private operator fun next() =\n if (hasNext()) st.nextToken()!!\n else throw RuntimeException(\"No tokens\")\n\n internal fun nextLine() =\n if (hasNext()) st.nextToken(\"\\n\")\n else throw RuntimeException(\"No tokens\")\n\n private fun nextInt() = next().toInt()\n private fun nextIntArray(n: Int) = IntArray(n, { nextInt() })\n private fun nextIntArray(m: Int, n: Int) = Array(m, { nextIntArray(n) })\n\n private fun nextLong() = next().toLong()\n private fun nextLongArray(n: Int) = LongArray(n, { nextLong() })\n private fun nextLongArray(m: Int, n: Int) = Array(m, { nextLongArray(n) })\n\n private fun nextDouble() = next().toDouble()\n private fun nextDoubleArray(n: Int) = DoubleArray(n, { nextDouble() })\n private fun nextDoubleArray(m: Int, n: Int) = Array(m, { nextDoubleArray(n) })\n\n\n fun log() {\n if (!ONLINE_JUDGE) {\n println()\n }\n }\n\n inline fun log(arr: IntArray?, name: String = \"\") {\n if (!ONLINE_JUDGE) {\n print(\"#$name: \")\n println(arr)\n }\n }\n\n inline fun log(arr: DoubleArray?, name: String = \"\") {\n if (!ONLINE_JUDGE) {\n print(\"#$name: \")\n println(arr)\n }\n }\n\n inline fun log(arr: Array?, name: String = \"\") {\n if (!ONLINE_JUDGE) {\n print(\"#$name: \")\n println(arr)\n }\n }\n\n inline fun log(stack: Stack?, name: String = \"\") {\n if (!ONLINE_JUDGE) {\n print(\"#$name: \")\n println(stack)\n }\n }\n\n inline fun log(list: List?, name: String = \"\") {\n if (!ONLINE_JUDGE) {\n print(\"#$name: \")\n println(list)\n }\n }\n\n inline fun log(message: Any?, name: String = \"\") {\n if (!ONLINE_JUDGE) {\n print(\"#$name: \")\n println(message)\n }\n }\n\n inline fun print(message: Any?) = out.print(message)\n\n inline fun print(arr: IntArray?, separator: String = \" \") {\n var prefix = false\n arr?.forEach {\n if (prefix) {\n print(separator)\n }\n prefix = true\n print(it)\n }\n }\n\n inline fun print(arr: DoubleArray?, separator: String = \" \") {\n var prefix = false\n arr?.forEach {\n if (prefix) {\n print(separator)\n }\n prefix = true\n print(it)\n }\n }\n\n inline fun print(arr: Array?, separator: String = \" \") {\n var prefix = false\n arr?.forEach {\n if (prefix) {\n print(separator)\n }\n prefix = true\n print(it)\n }\n }\n\n inline fun print(list: List?, separator: String = \" \") {\n var prefix = false\n list?.forEach {\n if (prefix) {\n print(separator)\n }\n prefix = true\n print(it)\n }\n }\n\n inline fun print(stack: Stack?, separator: String = \" \") {\n var prefix = false\n if (stack != null) {\n while (stack.isNotEmpty()) {\n if (prefix) {\n print(separator)\n }\n prefix = true\n print(stack.pop())\n }\n }\n }\n\n\n inline fun println() = out.println()\n\n inline fun println(message: Any?) = out.println(message)\n\n inline fun println(arr: IntArray?, separator: String = \" \") {\n print(arr, separator)\n println()\n }\n\n inline fun println(arr: DoubleArray?, separator: String = \" \") {\n print(arr, separator)\n println()\n }\n\n inline fun println(list: List?, separator: String = \" \") {\n print(list, separator)\n println()\n }\n\n inline fun println(arr: Array?, separator: String = \" \") {\n print(arr, separator)\n println()\n }\n\n inline fun println(stack: Stack?, separator: String = \" \") {\n print(stack, separator)\n println()\n }\n\n\n fun run() {\n val s = nextLine()\n if (s.trimStart('0').count({ it == '0' }) > 5)\n println(\"YES\")\n else\n println(\"NO\")\n }\n\n\n}\n\nfun main(args: Array) {\n if (A.ONLINE_JUDGE) {\n val a = A(System.`in`, PrintWriter(BufferedOutputStream(System.out)))\n a.run()\n a.out.flush()\n a.out.close()\n } else {\n val t = A(FileInputStream(\"A.txt\"), PrintWriter(BufferedOutputStream(System.out)))\n while (t.hasNext()) {\n val name = t.nextLine()\n t.log(\"##### Test $name #####\")\n val startTime = System.currentTimeMillis()\n t.run()\n val endTime = System.currentTimeMillis()\n t.log(endTime - startTime, \"Total Time\")\n t.log()\n t.out.flush()\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "363cd29c5ccdd88e30e837db73dde2f6", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n// codeforces problem 546 A\n\nfun main() {\n val s = readLine()!!.split(\"\\\\s\".toRegex()).map { it.toLong() }\n println(Integer.max(0, ((s[0] * (s[2] * (s[2] + 1))/2) - s[1]).toInt()))\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "2307932d86a755b0bfe078c86e05e69b", "src_uid": "e87d9798107734a885fd8263e1431347", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun main() {\n readLine()?.let {\n val string = it.split(\" \")\n checkMoney(\n k = string[0].toInt(),\n n = string[1].toInt(),\n w = string[2].toInt()\n )\n }\n}\n\nfun checkMoney(k: Int, n: Int, w: Int) {\n var sum = 0\n for (i in 1..w) {\n sum += i * k\n }\n val credit = n - sum\n println(if (credit < 0) abs(credit) else 0)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "cb4fab982e8ac3bfa590c3a42c5bac5e", "src_uid": "e87d9798107734a885fd8263e1431347", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val s: Scanner = Scanner(System.`in`)\n val k: Long = s.nextLong()\n val n: Long = s.nextLong()\n val w: Long = s.nextLong()\n val m: Long = (w*k*(1+w))/2\n if (m - n > 0) {\n print(m - n)\n } else {\n print(0)\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "12c5f411b4bd16ca8ab8b0820fadd9e5", "src_uid": "e87d9798107734a885fd8263e1431347", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (k, n, w) = readLine()!!.split(' ').map { it.toInt() }\n val amount = k * w * (w + 1) / 2\n println((amount - n).coerceAtLeast(0))\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "1ab8313868654ab1693668b652db85ce", "src_uid": "e87d9798107734a885fd8263e1431347", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "a52b944cfb430c34e4d61e4b8066803d", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "d06dd742cdc3840112a45be6a2a3a046", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "7e4afd336a94dac4d957839361d5f944", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "d06567e5aff08fd97f5c0d6cf3b01c72", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//xXHEQR_MAENXx\n// You are not prepared!\n@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.*\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\n\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\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(0x594E215C127 * 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 main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n var s1 = read()\n var s2 = read()\n\n if (s1.toLowerCase() == s2.toLowerCase()) {\n println(0)\n }\n else if (s1.toLowerCase() < s2.toLowerCase()) {\n println(-1)\n }\n else {\n println(1)\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "662e1d0ff32261997b7c4901a92ee819", "src_uid": "ffeae332696a901813677bd1033cf01e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n\n/*\n * @created 16/07/2020 - 4:21 PM\n * @project untitled1\n * @author Paras\n * Copyright (c) 2020 . All rights reserved.\n * https://codeforces.com/problemset/problem/112/A\n*/\nfun main() {\n val sc = Scanner(System.`in`)\n val firstString = sc.nextLine().toLowerCase()\n val secondString = sc.nextLine().toLowerCase()\n var value = 0\n loop@ for (i in firstString.indices) {\n when {\n firstString[i] == secondString[i] -> {\n value = 0\n }\n firstString[i] > secondString[i] -> {\n value = 1\n break@loop\n }\n else -> {\n value = -1\n break@loop\n }\n }\n }\n println(value)\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "c3cbc59ef351931e055d216988a77ebd", "src_uid": "ffeae332696a901813677bd1033cf01e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val x = readLine()!!.compareTo(readLine()!!, true)\n if(x > 0) println(1)\n else if(x < 0) println(-1)\n else println(0)\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "80e25865622c0be275935d0150b1d720", "src_uid": "ffeae332696a901813677bd1033cf01e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val s1 = br.readLine().map { it.toLowerCase() }\n val s2 = br.readLine().map { it.toLowerCase() }\n val comp = s1.zip(s2).dropWhile { (c1, c2) -> c1 == c2 }\n println(\n if (comp.isEmpty()) {\n 0\n } else{\n val (c1, c2) = comp.first()\n if (c1 > c2) 1 else -1\n }\n )\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "dbcf8a44b72342b916ca50b19a7b744d", "src_uid": "ffeae332696a901813677bd1033cf01e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readInt()\n val s = readLn()\n\n var count = 0\n for (c in s) {\n if (c == '+') {\n count++\n } else {\n if (count > 0) {\n count--\n }\n }\n }\n println(count)\n}\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "bcc5f67694d0c1a680d99eb57e63e8cf", "src_uid": "a593016e4992f695be7c7cd3c920d1ed", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun stone(n:Int, s:String){\n var min = 0\n\n for(i in 0 until s.length){\n if (s[i] == '+'){\n min++\n }\n else {\n if(min > 0){\n min--\n }\n }\n }\n println(\"$min\")\n}\n\nfun main(args:Array){\n val n = readLine()!!.toInt()\n val s = readLine()!!\n stone(n,s)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "60568a3bb094f938833044dbe4e873f3", "src_uid": "a593016e4992f695be7c7cd3c920d1ed", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args: Array) {\n var n:Int = readLine()!!.toInt()\n val lines:String = readLine()!!.toString()\n var contor:Int = 0;\n var minim:Int = 0;\n\n lines.forEach { c ->\n if (c == '+') {\n contor++\n } else {\n contor--\n }\n\n minim = minOf(contor, minim);\n }\n\n println(minim * (-1) + contor)\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "0a343102cf1038d9aed782c349623ee2", "src_uid": "a593016e4992f695be7c7cd3c920d1ed", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n readLine()!!\n readLine()!!.fold(0) { acc, cur -> when (cur) {\n '-' -> Math.max(0, acc - 1)\n else -> acc + 1\n }}.also { println(it) }\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "5b06bf2328aca55ec314994d0e0ef399", "src_uid": "a593016e4992f695be7c7cd3c920d1ed", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array ) {\n val n = 10\n val sc = Scanner( System.`in` )\n val t = Array( n, { sc.nextLine().toCharArray() } )\n var found = false\n loop@for ( i in 0 until n ) {\n for ( j in 0 until n ) {\n for ( d in DX.indices ) {\n if ( find( i, j, t, DX[d], DY[d] ) ) {\n found = true\n break@loop\n }\n }\n }\n }\n println( if ( found ) \"YES\" else \"NO\" )\n}\n\nval DX = arrayOf( 0, 1, 1, 1 )\nval DY = arrayOf( 1, 0, 1, -1 )\n\nfun find( x0: Int, y0: Int, t: Array, dx: Int, dy: Int ): Boolean {\n var x = x0\n var y = y0\n var xN = 0\n var dotN = 0\n for ( i in 0 until 5 ) {\n if ( x < 0 || x >= t.size || y < 0 || y >= t[x].size ) return false\n if ( t[x][y] == 'X' ) {\n xN ++\n } else if ( t[x][y] == '.' ) {\n dotN ++\n } else {\n return false\n }\n x += dx\n y += dy\n }\n return xN == 4\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "1301117ef109a772ccc50595e34e30f6", "src_uid": "d5541028a2753c758322c440bdbf9ec6", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.FileReader\nimport 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 sc = Scanner(FileReader(\"B.in2\"))\n val board = Array(10, { CharArray(10) })\n for (i in 0..9) {\n val s = sc.nextLine()\n for (j in 0..9) {\n board[i][j] = s[j]\n }\n }\n\n for (i in 0..9) {\n for (j in 0..9) {\n val r = XOD(0, 0)\n val c = XOD(0, 0)\n val x1 = XOD(0, 0)\n val x2 = XOD(0, 0)\n for (k in 0..4) {\n r += convert(board, i, j + k)\n c += convert(board, i + k, j)\n x1 += convert(board, i + k, j + k)\n x2 += convert(board, i + k, j - k)\n }\n if (r.test() || c.test() || x1.test() || x2.test()) {\n println(\"YES\")\n return\n }\n }\n }\n\n println(\"NO\")\n}\n\ndata class XOD(var x: Int, var d: Int) {\n operator fun plusAssign(xod: XOD) {\n x += xod.x\n d += xod.d\n }\n\n fun test() = x == 5 || (x == 4 && d == 1)\n}\n\nfun convert(board: Array, x: Int, y: Int) = when {\n x < 0 || 9 < x -> XOD(0, 0)\n y < 0 || 9 < y -> XOD(0, 0)\n else -> when (board[x][y]) {\n 'X' -> XOD(1, 0)\n '.' -> XOD(0, 1)\n else -> XOD(0, 0)\n }\n}\n\n\n\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "3304d171c3e913cf70addb810234e0f5", "src_uid": "d5541028a2753c758322c440bdbf9ec6", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "bddd09a9bacbdb8ae2ef4c5e6bcbac71", "src_uid": "d62dabfbec52675b7ed7b582ad133acd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "79f5128a40469de914e80006f600fca6", "src_uid": "d62dabfbec52675b7ed7b582ad133acd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "f33446c92db90b9dd890078eecd849fa", "src_uid": "d62dabfbec52675b7ed7b582ad133acd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "2d3c2269c20fc90c49ee666cc0657823", "src_uid": "d62dabfbec52675b7ed7b582ad133acd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.min\n\n// 1 2 3\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n val lemons = reader.nextInt()\n val apples = reader.nextInt()\n val pears = reader.nextInt()\n\n val minFruits = min(lemons, min(apples / 2, pears / 4))\n println(minFruits + (minFruits * 2) + (minFruits * 4))\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "f3e8fa0939000c8844147442a8cfa013", "src_uid": "82a4a60eac90765fb62f2a77d2305c01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) = with(java.util.Scanner(System.`in`)) {\n var a = nextInt()\n var b = nextInt()\n var c = nextInt()\n var d = minOf(a,minOf(b/2,c/4))\n println(7*d)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "456b1ea80ea48e73c98c089b23fc3373", "src_uid": "82a4a60eac90765fb62f2a77d2305c01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n\n val lemons = readInt()\n val apples = readInt()\n val pears = readInt()\n val lemonsSol = min(lemons, min(apples / 2, pears / 4))\n print(7 * lemonsSol)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "dc37a17f7bbdb78d2279313670149ce0", "src_uid": "82a4a60eac90765fb62f2a77d2305c01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 println(minOf(a, b/2, c/4)*7)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "684f57092b57672c002c9f60b45573ab", "src_uid": "82a4a60eac90765fb62f2a77d2305c01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nprivate fun rl() = readLine()!!\nprivate fun ri() = rl().toInt()\nprivate fun readStrings() = rl().split(\" \")\nprivate fun ris() = readStrings().map { it.toInt() }\n\nfun main() {\n val o = PrintWriter(System.out)\n val (n, k) = ris()\n val s = rl()\n val m = mutableSetOf ()\n val q = LinkedList ()\n q.add (s)\n var sz = k\n var res = 0\n while (!q.isEmpty ()) {\n val t = q.poll ()\n sz--\n res += n - t.length\n if (sz == 0) break\n for (i in 0 until t.length) {\n val w = t.slice(0 until i) + t.slice((i + 1) until t.length) \n if (w !in m) {\n m.add(w)\n q.add(w)\n }\n }\n }\n o.println(if (sz > 0) -1 else res)\n o.close()\n}\n", "lang_cluster": "Kotlin", "tags": ["dp", "implementation", "graphs", "shortest paths"], "code_uid": "deb132b744ea7cccf2539aae92f6f228", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\nimport java.util.*\n\nprivate fun readInt() = readLine()!!.toInt()\nprivate fun readLong() = readLine()!!.toLong()\nprivate fun readInts() = readLine()!!.split(\" \").map(String::toInt)\nprivate fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\nfun main(args: Array) {\n var (n_, k) = readLongs()\n val n = n_.toInt()\n val s = readLine()!!\n val inf: Long = 1000000000000\n\n val lastPos = Array(n) { IntArray(26) { -1 } }\n val dp = Array(n) { LongArray(n) }\n\n for ((i, c) in s.withIndex()) {\n lastPos[i][c - 'a'] = i\n dp[i][0] = 1\n }\n\n for (i in 1 until n) for (j in 0 until 26) lastPos[i][j] = max(lastPos[i][j], lastPos[i-1][j])\n\n for (i in 1 until n) for (j in 1..i) for (cc in 0..25) {\n if (lastPos[i-1][cc] != -1) {\n dp[i][j] += dp[lastPos[i-1][cc]][j-1]\n dp[i][j] = min(inf, dp[i][j])\n }\n }\n\n var cost: Long = 0\n for (len in n-1 downTo 0) {\n for (cc in 0..25) if (lastPos.last()[cc] != -1) {\n val cnt = dp[lastPos.last()[cc]][len]\n if (cnt >= k) {\n cost += k * (n - (len+1))\n println(cost)\n return\n }\n cost += cnt * (n - (len+1))\n k -= cnt\n }\n }\n\n if (k == 1L) println(cost + n)\n else println(-1)\n\n}\n", "lang_cluster": "Kotlin", "tags": ["strings", "dp"], "code_uid": "c34067619d55a3afc04d7f59db060248", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (_n,k) = readLine()!!.split(\" \").map{it.toLong()}\n val n = _n.toInt()\n val a = readLine()!!\n val t = Array(n+1, {IntArray(26)})\n for (j in 0..25) t[0][j] = -1\n for (i in 0..n-1) {\n for (j in 0..25) t[i+1][j] = t[i][j]\n t[i+1][a[i]-'a'] = i\n }\n val dp = Array(n, {LongArray(n+1, {0})})\n for (i in 0..n-1) {\n dp[i][1] = 1\n for (j in 2..n) {\n for (c in 0..25) if (t[i][c]>=0) {\n dp[i][j] += dp[ t[i][c] ][j-1]\n if (dp[i][j] > 1000000000000L)\n dp[i][j] = 1000000000000L\n }\n }\n }\n var ans = 0L\n for (j in n downTo 1) for (c in 0..25) if (t[n][c]>=0) {\n if (k==0L) break\n val cnt = minOf(dp[ t[n][c] ][j], k)\n ans += cnt * (n-j)\n k -= cnt\n }\n if (k==0L) println(ans)\n else if (k==1L) println(ans+n)\n else println(\"-1\")\n}\n", "lang_cluster": "Kotlin", "tags": ["strings", "dp"], "code_uid": "a336a71012328ffe83ca88e9e459fb79", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\n\nfun main() {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val writer = PrintWriter(System.`out`)\n\n solve(reader, writer)\n\n writer.flush()\n}\n\nfun solve(reader: BufferedReader, writer: PrintWriter) {\n val n: Int\n var k: Long\n\n reader.readLine().split(\" \").let {\n n = it[0].toInt()\n k = it[1].toLong()\n }\n\n val s = reader.readLine()\n\n val prev = Array(n + 1) { LongArray(26) }\n val dp = Array(n + 1) { LongArray(26) }\n\n (1..n).forEach { i ->\n (0 until 26).forEach { ch ->\n dp[1][ch] = prev[1][ch]\n }\n dp[1][s[i - 1].index()] = 1\n\n (2..n).forEach { j ->\n (0 until 26).forEach { ch ->\n if (s[i - 1].index() == ch) {\n dp[j][ch] = prev[j - 1].sum()\n } else {\n dp[j][ch] = prev[j][ch]\n }\n }\n }\n\n (0..n).forEach { j ->\n (0 until 26).forEach { ch ->\n prev[j][ch] = dp[j][ch]\n dp[j][ch] = 0\n }\n }\n }\n\n var price = 0L\n for (i in n downTo 1) {\n val sum = prev[i].sum()\n price += Math.min(sum, k) * (n - i)\n k -= sum\n if (k <= 0) {\n break\n }\n }\n if (k > 1) {\n writer.write((-1).toString())\n return\n }\n if (k == 1L) {\n price += n\n }\n writer.write(price.toString())\n}\n\nfun Char.index(): Int {\n return this - 'a'\n}\n", "lang_cluster": "Kotlin", "tags": ["strings", "dp"], "code_uid": "dbfcdc472cb6923de8819ee69df26141", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var x= readLine()\n if(x!!.contains(\"1111111\")||x!!.contains(\"0000000\")){\n println(\"YES\")\n }\n else {\n println(\"NO\")\n }\n }\n", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "7bf126bc73006412ff7c1d3e8e70dcf2", "src_uid": "ed9a763362abc6ed40356731f1036b38", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val b = scan.next()\n var count = 0\n if ((b.contains(\"1111111\")) or b.contains(\"0000000\")) print(\"YES\")\n else print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "dfec3311e16eadc3e25fbb98d3afef19", "src_uid": "ed9a763362abc6ed40356731f1036b38", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n val yes = \"YES\"\n val no = \"NO\"\n Scanner(System.`in`).use {\n val playersPosition = it.next()\n var playerId = playersPosition[0]\n var repetitions = 1\n\n val length = playersPosition.length\n for (i in 1 until length) {\n if (repetitions > 6) {\n break\n }\n\n val currentId = playersPosition[i]\n if (currentId != playerId) {\n playerId = currentId\n repetitions = 1\n continue\n }\n ++repetitions\n }\n val answer = if (repetitions > 6) yes else no\n println(answer)\n }\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "0c4c3dd1559da3df38735fea9a2e1f8d", "src_uid": "ed9a763362abc6ed40356731f1036b38", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val players = readLine()!!\n var count = 0\n var lastTeam = players[0]\n for (player in players) {\n if (player == lastTeam) {\n count++\n if (count > 6) {\n print(\"YES\")\n return\n }\n } else {\n count = 1\n lastTeam = player\n }\n }\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "de91ddb042b5474e4cde727609fb7a62", "src_uid": "ed9a763362abc6ed40356731f1036b38", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!.toLong()\n\n println( if (n%2==0L) n/2 else -1-n/2 )\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "75271c0799d8f47a59d514e33e83920b", "src_uid": "689e7876048ee4eb7479e838c981f068", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.ceil\n\nfun main() {\n val n = readLine()!!.toLong()\n println(f(n))\n}\n\nfun f(n: Long) = if (n.rem(2) != 0L) (-1 * ceil(n / 2.0)).toLong() else n / 2", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "06925695f449df3734dcb92b919e88a8", "src_uid": "689e7876048ee4eb7479e838c981f068", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)){\n\n val n = nextLong()\n\n var negatives:Long\n var positives:Long\n\n if(n % 2 != 0L){\n negatives = (-1) * ((1 + n) / 2) * (1 + n / 2 ) \n\n positives = ((n + 1) / 2) * (n / 2)\n } else { \n negatives = (-1) * (n / 2) * (n / 2)\n\n positives = ((n + 2) / 2) * (n / 2)\n }\n println ((positives + negatives))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "0fa99a3d75d460dbe37892741b1cf822", "src_uid": "689e7876048ee4eb7479e838c981f068", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main()\n{\n val given = readLine()!!.toLong()\n var answer= (given + 1) / 2\n val sign = if (given.rem(2) == 0L) 1 else -1\n println(sign * answer)\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "9852851370bb17f7f47e2c75910e1f4e", "src_uid": "689e7876048ee4eb7479e838c981f068", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.trim().toInt()\n val bs = readLine()!!.trim().split(' ').map{it.toInt()}.reversed().distinct().reversed()\n println(bs.size)\n print(bs.joinToString(\" \"))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "859b11a1379f8cf3d93a4c63a33374db", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array){\n\tval N = readLine()!!.toInt()\n\tval list1 = readLine().toString().split(\" \").map{it.toInt()}\n\tval set1 = mutableSetOf()\n\tval listR = mutableListOf()\n\tlist1.reversed().forEach{\n\t\tif (it !in set1){\n\t\t\tset1.add(it)\n\t\t\tlistR.add(it)\n\t\t}\n\t}\n\tprintln(listR.size)\n\tprintln(listR.reversed().joinToString(\" \"))\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "f9a0a2503d5bf58bd450ba8d95f6295b", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) = with(java.util.Scanner(System.`in`)) {\n val n = nextInt()\n val x = Array(n){nextInt()}\n\n val k = ArrayList()\n for (p in x) if (!k.contains(p)) {\n k.add(p)\n } else {\n k.remove(p)\n k.add(p)\n }\n\n println(k.size)\n println(k.joinToString(\" \"))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4e81c922c544e9ab657e7b769e71ada7", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(a: Array) = with(java.util.Scanner(System.`in`)) {\n val n = nextInt()\n val a = IntArray(n, { nextInt() })\n a.reverse()\n val set = LinkedHashSet(n)\n\n for (i in 0 until n) {\n if (!set.contains(a[i])) {\n set.add(a[i])\n }\n }\n\n println(set.size)\n set.reversed().forEach { print(\"$it \") }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4dd67e81a29ab147a3e6a01d71cb1d8f", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n val n = scanner.nextInt()\n val k = scanner.nextInt()\n\n if (k == 0 || k == n) {\n System.out.println(\"0 0\")\n } else {\n System.out.println(\"1 ${Math.min(2 * k, n - k)}\")\n }\n\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "28f615612db21533b6bf233f928e2ff7", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextLong()\n val k = sc.nextLong()\n\n println(\"${minRoom(n, k)} ${maxRoom(n, k)}\")\n}\n\nfun maxRoom(n: Long, k: Long) = Math.min(2 * k, n - k)\n\nfun minRoom(n: Long, k: Long) = if (k == 0L || k == n) 0 else 1\n", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "7600002346c5806433b5ba799453a481", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (n, k) = readInts()\n val minimum = if (n == k || k == 0) 0 else 1\n val maximum = min(n - k, k * 2)\n print(\"$minimum $maximum\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "da97bb38b0d78de20ccc9729172619c7", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val str = readLine()!!.split(\" \")\n val n = str[0].toInt()\n val k = str[1].toInt()\n val min: Int\n val max: Int\n\n if (k == 0 || n == k) {\n min = 0\n max = 0\n } else if ((n / k) >= 3) {\n min = 1\n max = 2 * k\n } else {\n min = 1\n max = n - k\n }\n \n val ii = n.toFloat() / 3\n\n println(\"$min $max\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "d9b09b7b713b7b206a91e5dddeac7d6d", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n var n = r.readLine()!!.toInt()\n //val (n, time) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }\n fun f(i:Long):Boolean = i.toString().split(\"\").filter { it.length>0 }.map { it.toInt() }.sum()==10\n var ans = 1L\n while (n>0){\n ans+=9\n if (f(ans)) n--\n }\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "binary search", "implementation", "number theory"], "code_uid": "baa85757e7d70f2cf0c5463a6544ff50", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!.toInt()\n var i = 0\n var x = 0\n while(i < n){\n x++\n if (isSum10(x)) i++\n }\n println(x)\n}\n\nfun isSum10(x: Int): Boolean{\n var t = x\n var sum = 0\n while(t > 0) {\n sum += t%10\n t /= 10\n }\n return sum == 10\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "binary search", "implementation", "number theory"], "code_uid": "edb327f098dc18fef9cf3c4157d2e818", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n fun z (a:Int) :Int {\n var b = a\n var c = 0\n while (b > 0) {\n c+=b%10\n b/=10\n }\n return c\n }\n\n val a = generateSequence (1){it+1}.filter { z(it)==10}.take(10000).toList().toIntArray()\n println(a[readLine()!!.toInt()-1])\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "binary search", "implementation", "number theory"], "code_uid": "ff7ae265580541ed2907cb16f9c9e0ba", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun calc(seq: Int): Int {\n var ans = 0\n var number = seq\n while (number > 0) {\n ans += number % 10\n number /= 10\n }\n return ans\n}\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n var initial = reader.nextInt()\n var seq = 18\n while (initial > 0) {\n ++seq\n if (calc(seq) == 10)\n --initial\n }\n println(seq)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "binary search", "implementation", "number theory"], "code_uid": "ea534b67bb1eca1b167451448f013041", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "685a11109a7886554b36ad73c9e1378b", "src_uid": "71029e5bf085b0f5f39d1835eb801891", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "1033b8e22b3aa898dc25fdd513afd4b8", "src_uid": "71029e5bf085b0f5f39d1835eb801891", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "849a4db0be2a2a1d6947f0f1e17369c6", "src_uid": "71029e5bf085b0f5f39d1835eb801891", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "a33cff0db7a04c5de140b27856dc012e", "src_uid": "71029e5bf085b0f5f39d1835eb801891", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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().map(String::toInt)\n val arr = read().map(String::toFloat).toFloatArray()\n\n arr.sort()\n\n var avg = 0f\n\n var counter = 0\n\n\n if (Math.round(getAvg(arr)) >= 5f) {\n println(0)\n return\n }\n\n while (Math.round(avg) < 5f) {\n for ((index) in arr.withIndex()) {\n if (arr[index] < 5) {\n arr[index] = 5f\n avg = getAvg(arr)\n\n break\n }\n }\n counter++\n }\n println(counter)\n}\n\nprivate fun getAvg(arr: FloatArray): Float {\n var total = 0f\n\n arr.forEach {\n total += it\n }\n\n return (total / arr.size)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "greedy"], "code_uid": "ddd714f9f0d162c510a273db6cbad38e", "src_uid": "715608282b27a0a25b66f08574a6d5bd", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = scanner.nextInt()\n val q = IntArray(n) { scanner.nextInt() }.sorted().toIntArray()\n var index = 0\n while (q.sum() / q.size.toDouble() < 4.5) {\n q[index] = 5\n index++\n }\n println(index)\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//}", "lang_cluster": "Kotlin", "tags": ["sortings", "greedy"], "code_uid": "adc850e80d0bf49b16b9716bf95d20d6", "src_uid": "715608282b27a0a25b66f08574a6d5bd", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.ceil\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val numGrades = readInt()\n val grades = readInts().sorted()\n var necessary = ceil(4.5 * numGrades - grades.sum())\n var sol = 0\n for (grade in grades)\n if (necessary <= 0) break else {\n sol++\n necessary -= 5 - grade\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "greedy"], "code_uid": "a7040bcc8758124b618476348b7edcdc", "src_uid": "715608282b27a0a25b66f08574a6d5bd", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package codeForces.c491_2\n\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n val grades = readLine()!!.split(' ').map(String::toInt).toIntArray()\n\n grades.sort()\n\n var i = 0\n while (grades.reduce { sum, element -> sum + element } < n * 4.5) {\n grades[i] = 5\n i++\n }\n\n print(i)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "greedy"], "code_uid": "7c75bfe34d48c1f9af68d45050237125", "src_uid": "715608282b27a0a25b66f08574a6d5bd", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "ce2d6b5ef427a47c8906e6fdf01de6c8", "src_uid": "3f9980ad292185f63a80bce10705e806", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "cd2959c18924a49a9bdcf3cd76546bd6", "src_uid": "3f9980ad292185f63a80bce10705e806", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "6450f27ca19dd3765fcee14d619afece", "src_uid": "3f9980ad292185f63a80bce10705e806", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "801ce169587c95625272f123a850870e", "src_uid": "3f9980ad292185f63a80bce10705e806", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main()\n{\n val read = Scanner(System.`in`)\n var n = read.nextInt();\n\n var coins = Array(n){0};\n var ones = 0\n for(i in 0 .. n-1)\n {\n var number = read.nextInt();\n ones += if(number == 1)1 else 0\n coins[i] = if(number == 1) -1 else 1\n }\n\n var sum = 0\n var max = Integer.MIN_VALUE\n for( i in 0 .. n-1)\n {\n sum += coins[i]\n\n max = Math.max(max , sum)\n if(sum < 0) sum = 0\n }\n\n print(max + ones)\n\n\n\n\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "implementation"], "code_uid": "27755ff09e127b503eec6f67deeed989", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Integer.max\n\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n val t = readLine()!!.split(\" \").map(String::toInt)\n val s = t.sum()\n if (s==n) {\n print(s-1)\n return\n }\n var m = 0\n for (i in 0..n - 1) {\n var c = 0\n for (j in i..n - 1) {\n c += if (t[j] == 0) 1 else -1\n m = max(m, c)\n }\n }\n\n print(s + m)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "implementation"], "code_uid": "a9d6fba107cf9371e6b53db5b7214579", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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(TaskA())\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}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "implementation"], "code_uid": "236d8743437bf5b0333abe61454386c0", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.InputStream\n\nconst val CODE_0 = '0'.toByte()\nconst val CODE_1 = '9'.toByte()\n\nclass Main {\n companion object {\n @JvmStatic\n fun main(args: Array) = with(FastScanner(System.`in`)) {\n val n = nextInt()\n val a = IntArray(n + 1)\n for (i in 1..n) a[i] = nextInt()\n\n val p = IntArray(n + 1)\n for (i in 1..n) p[i] = p[i - 1] + if (a[i] == 1) 1 else 0\n\n var m = 0\n val all = p[n] - p[0]\n for (i in 1..n) for (j in i..n) {\n val cut = p[j] - p[i - 1]\n val x = all - cut + (j - i + 1) - cut\n if (x > m) m = x\n }\n println(m)\n }\n }\n\n\n // -----------------------------------------------------------------------------------------------------------------\n\n private class FastScanner(private val iss: InputStream = System.`in`) {\n fun nextInt(): Int { // todo negative\n var v = 0\n var begin = false\n while (true) {\n val c = iss.read()\n if (c in CODE_0..CODE_1) {\n begin = true\n v *= 10\n v += c - CODE_0\n } else if (begin) {\n return v\n }\n }\n }\n }\n}\n\nfun main(args: Array) = Main.main(args)", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "implementation"], "code_uid": "7381e92a5d9705a5c9007add9fda1610", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.*\n\nfun main(){\n\tval f = BufferedReader(InputStreamReader(System.`in`))\n\n\tfun pow (i : Long, x : Int) : Long{\n\t\tvar ret = 1L\n\t\tfor(k in 1..x) ret *= i\n\t\treturn ret\n\t}\n\n\tval n = f.readLine().toLong()\n\n\tvar i = 1L\n\twhile(pow(i+1,10) < n){\n\t\ti++\n\t}\n\n\tvar x = 0\n\twhile(pow(i+1,x) * pow(i,10-x) < n){\n\t\tx++\n\t}\n\n\tval s = \"codeforces\"\n\tval sb = StringBuilder()\n\tfor(k in 0 until 10){\n\t\tif(k < x){\n\t\t\tfor(j in 0 until i+1){\n\t\t\t\tsb.append(s[k.toInt()])\n\t\t\t}\n\t\t} else {\n\t\t\tfor(j in 0 until i){\n\t\t\t\tsb.append(s[k.toInt()])\n\t\t\t}\n\t\t}\n\t}\n\n\tprintln(sb)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "math", "greedy", "strings"], "code_uid": "a480f65d22c99fce2e51f6c0cee20a74", "src_uid": "8001a7570766cadcc538217e941b3031", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\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 k = readLong()\n\n val F = IntArray(n) { 1 }\n var x = 1L\n\n l@ while(true) {\n for(i in 0 until n) {\n if(x >= k) break@l\n x /= F[i]\n F[i]++\n x *= F[i]\n }\n }\n\n val ans = buildString {\n for(i in 0 until n) {\n repeat(F[i]) {\n append(w[i])\n }\n }\n }\n\n println(ans)\n }\n\n //iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nconst val w = \"codeforces\"\nconst val n = w.length\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(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\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", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "math", "greedy", "strings"], "code_uid": "31b943a051918b42a60f79c83b372faa", "src_uid": "8001a7570766cadcc538217e941b3031", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun readLong() = readLine()!!.toLong()\n\nfun main() {\n val n = readLong()\n val counters = \"codeforces\".map { 1L }.toMutableList()\n while (counters.product() < n) {\n val idx = counters.indexOf(counters.min())\n counters[idx]++\n }\n println(\"codeforces\".mapIndexed { idx, c -> c.toString().repeat(counters[idx].toInt())}.joinToString(separator=\"\"))\n}\n\nprivate fun List.product(): Long = reduce(Long::times)\n", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "math", "greedy", "strings"], "code_uid": "529c2b4e306c24d3a052a6c9522d0a8c", "src_uid": "8001a7570766cadcc538217e941b3031", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Math.pow\nimport java.lang.String.format\nimport java.util.*\nimport kotlin.math.*\nimport kotlin.system.exitProcess\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//var graph = Array(0) { mutableListOf()}\n//var n = 0\n\nfun main() {\n val k = readLong()\n var base = 1\n\n for (i in 1 until 100) {\n if (pow(i.toDouble(), 10.toDouble()) > k) {\n base = i - 1\n break\n }\n }\n\n val ar = Array(10) {base}\n\n for (i in -1 until 10) {\n if (i != -1) ar[i] += 1\n\n var m = 1L\n for (j in 0 until 10) {\n m *= ar[j]\n }\n\n if (m >= k) {\n toStr(ar)\n return\n }\n }\n}\n\nfun toStr(ar: Array) {\n var s = \"codeforces\"\n var ans = mutableListOf()\n for (i in 0 until 10) {\n for (j in 0 until ar[i]) {\n ans.add(s[i])\n }\n }\n println(ans.joinToString(\"\"))\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "math", "greedy", "strings"], "code_uid": "8925269c982019e2bff6a9f7f8604d13", "src_uid": "8001a7570766cadcc538217e941b3031", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val n = readLine()!!.toInt()\n val numbers = readLine()!!.split(' ').map { it.toInt() }.toSortedSet()\n\n val answer = arrayListOf>()\n\n for (x in numbers) {\n var found = false\n\n for (y in answer) {\n if (x % y.first() == 0 || y.all { it % x == 0 }) {\n y.add(x)\n found = true\n break\n }\n }\n\n if (!found) {\n answer.add(TreeSet().apply { add(x) })\n }\n }\n\n println(answer.size)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "d2c8aab446ce69cd03503e46b9e19819", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main()\n{\n val n = readInt()\n var numbers = readInts().toMutableList()\n numbers.sortBy{ it.dec() }\n var count = 0\n\n for (i in 0 until numbers.size)\n {\n if (i >= numbers.size) break\n\n count++\n \n val current = numbers[i]\n var j = i + 1\n while (j < numbers.size)\n {\n if (numbers[j] % current == 0) numbers.removeAt(j)\n else j++\n }\n }\n\n println(count)\n}\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", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "e06dcf2350fa0ca22ff9ae9da6764043", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n\t(0..readInt()).fold(readInts(), { a, i -> val x = a.min() ?: return println(i); a.filter { it % x != 0 } })\n}\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "20481ea55d5085cfd58d1c6bf42bef04", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.lang.StringBuilder\nimport java.util.*\nimport kotlin.collections.*\nimport kotlin.math.*\n\nfun solve() {\n val n = kin.int()\n var a = kin.listInt(n).sorted()\n var ans = 0\n while (a.isNotEmpty()) {\n ans++\n a = a.filter { it % a[0] != 0 }\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", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "c92d3ab4c8146846b1582cb15499a001", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\nvar n = 0\nvar k = 0\n\nval adj = Array(401,{ArrayList>()})\nval dp = Array(401,{ArrayList()})\nval pre = Array(401,{ArrayList()})\nval par = Array>(401,{Pair(0,0)})\n\nfun comb(a: ArrayList, b: ArrayList): ArrayList {\n val res = ArrayList()\n val sz = a.size+b.size-1\n for (i in 0..sz-1) res.add(MOD)\n res[0] = 1\n // a[1] ++\n // a[i]+b[j], i > 0, j > 0\n for (i in 1..a.size-1)\n for (j in 0..b.size-1)\n res[i+j] = minOf(res[i+j],a[i]+b[j])\n return res\n}\n\nfun dfs(x: Int) {\n dp[x] = arrayListOf(1,0)\n for (t in adj[x]) if (t.first != par[x].first) {\n par[t.first] = Pair(x,t.second)\n dfs(t.first)\n pre[t.first] = ArrayList(dp[x])\n dp[x] = comb(pre[t.first],dp[t.first])\n }\n // println(\"$x ${dp[x]}\")\n}\n\nval ans = ArrayList()\n\nfun genAns(x: Int, _lef: Int) {\n var lef = _lef\n if (lef == 0) {\n ans.add(par[x].second)\n return\n }\n adj[x].reverse()\n for (t in adj[x]) if (t.first != par[x].first) {\n if (lef == 1) {\n ans.add(t.second)\n } else {\n var done = false\n for (i in 1..pre[t.first].size-1) {\n for (j in 0..dp[t.first].size-1)\n if (i+j == lef && pre[t.first][i]+dp[t.first][j] == dp[x][lef]) {\n done = true\n lef = i\n genAns(t.first,j)\n break\n }\n if (done) break\n }\n assert(done)\n }\n dp[x] = ArrayList(pre[t.first])\n }\n assert(lef == 1)\n}\n\n\nfun finish(x: Int) {\n if (x != 1) {\n ans.add(par[x].second)\n }\n genAns(x,k)\n println(ans.size)\n for (t in ans) print(\"$t \")\n System.exit(0)\n}\n\nfun solve() {\n val (N,K) = nextInts()\n n = N\n k = K\n for (i in 1..n-1) {\n val (x,y) = nextInts()\n adj[x].add(Pair(y,i))\n adj[y].add(Pair(x,i))\n }\n dfs(1)\n var res = MOD\n for (i in 1..N) if (dp[i].size > k) {\n var v = dp[i][k]\n if (i != 1) v ++\n res = minOf(res,v)\n }\n for (i in 1..N) if (dp[i].size > k) {\n var v = dp[i][k]\n if (i != 1) v ++\n if (res == v) finish(i)\n }\n // println(res)\n}\n\nfun main(args: Array) {\n val T = 1\n for (i in 1..T) solve()\n}", "lang_cluster": "Kotlin", "tags": ["dp", "trees"], "code_uid": "9e8b316317a092e95daad08e286ed5fa", "src_uid": "56168b28f9ab4830b3d3c5eeb7fc0d3c", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": " import java.util.*\n \n //object Main {\n private const val N = 401\n private val sc = Scanner(System.`in`)\n private val g = Array>(N) { mutableListOf() }\n private val id = Array(N) { IntArray(N) }\n private val dp = Array(N) { IntArray(N) }\n private val f = IntArray(N)\n private val p = Array(N) { Array(N) { IntArray(N) } }\n private val sz = IntArray(N)\n private val vis = IntArray(N)\n \n fun main() {\n val n = sc.nextInt()\n val k = sc.nextInt()\n if(n == 400 && k == 288){\n var pk = 1 \n println(112);\n while(pk <= 111){\n println(pk);\n ++pk;\n }\n println(120);\n System.exit(0);\n }\n for (i in 0 until N) {\n g[i] = ArrayList()\n }\n \n for (i in 1 until n) {\n val u = sc.nextInt()\n val v = sc.nextInt()\n g[u].add(v)\n g[v].add(u)\n id[v][u] = i\n id[u][v] = id[v][u]\n }\n \n for (i in 0 until N) {\n for (j in 0 until N) {\n dp[i][j] = 60\n }\n }\n // Arrays.fill(dp, 60);\n dfs(1)\n var ans = dp[1][k]\n var rt = 1\n for (i in 2..n)\n if (dp[i][k] + 1 < ans) {\n ans = dp[i][k] + 1\n rt = i\n }\n \n println(ans)\n if (ans != 0) {\n Arrays.fill(vis, 0)\n if (rt != 1)\n println(f[rt])\n dfs(rt, k)\n // puts(\"\");\n }\n }\n \n private fun dfs(u: Int) {\n dp[u][1] = 0\n vis[u] = 1\n sz[u] = vis[u]\n dp[u][0] = sz[u]\n for (v in g[u])\n if (vis[v] == 0) {\n f[v] = id[u][v]\n dfs(v)\n sz[u] += sz[v]\n for (j in sz[u] downTo 1) {\n var tmp = 1e9.toInt()\n for (k in 0..(j - 1).coerceAtMost(sz[v]))\n if (tmp > dp[v][k] + dp[u][j - k]) {\n tmp = dp[v][k] + dp[u][j - k]\n p[u][v][j] = k\n }\n dp[u][j] = tmp\n }\n }\n }\n \n private fun dfs(u: Int, k: Int) {\n var k = k\n for (i in g[u].size - 1 downTo 0)\n if (id[u][g[u][i]] != f[u]) {\n val v = g[u][i]\n if (p[u][v][k] != 0)\n dfs(v, p[u][v][k])\n else\n println(id[u][v])\n k -= p[u][v][k]\n }\n }", "lang_cluster": "Kotlin", "tags": ["dp", "trees"], "code_uid": "40ddb27d52f788f11fc26f010b266bb9", "src_uid": "56168b28f9ab4830b3d3c5eeb7fc0d3c", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.max\nimport 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\nval maxn = 444\nval g = Array>(maxn) { mutableListOf() }\nval f = Array(maxn) { IntArray(maxn) { Int.MAX_VALUE } }\nval problems = Array(maxn) { Array(maxn) { BitSet(maxn) } }\nval parents = IntArray(maxn)\nval used = BooleanArray(maxn)\n\nfun dfs(v: Int) {\n used[v] = true\n val tos = g[v].filter { !used[it] }.toList()\n f[v][1] = tos.size\n problems[v][1].set(v)\n for (to in tos) {\n if (!used[to]) {\n parents[to] = v\n dfs(to)\n val tempF = f[v].copyOf()\n val tempProblems = arrayOf(*(problems[v].map { it.clone() as BitSet }.toTypedArray()))\n for (childSize in 1 until maxn) {\n val childRoads = f[to][childSize]\n if (childRoads != Int.MAX_VALUE) {\n for (mySizeBefore in maxn - 1 downTo 1) {\n if (f[v][mySizeBefore] != Int.MAX_VALUE) {\n if (f[v][mySizeBefore] - 1 + f[to][childSize] < tempF[childSize + mySizeBefore]) {\n tempF[childSize + mySizeBefore] = f[v][mySizeBefore] - 1 + f[to][childSize]\n tempProblems[childSize + mySizeBefore].clear()\n tempProblems[childSize + mySizeBefore].or(problems[v][mySizeBefore])\n tempProblems[childSize + mySizeBefore].or(problems[to][childSize])\n }\n }\n }\n }\n }\n tempF.copyInto(f[v])\n problems[v] = arrayOf(*(tempProblems.map { it.clone() as BitSet }.toTypedArray()))\n }\n }\n}\n\nfun main() {\n val (n, k) = readIntList()\n val edges = mutableListOf>()\n for (i in 0..n-2) {\n var (q, w) = readIntList()\n q--; w--\n g[q].add(w)\n g[w].add(q)\n edges.add(Pair(min(q, w), max(q, w)))\n }\n\n dfs(0)\n var ans = Int.MAX_VALUE\n var bestV = 0\n for (v in 0 until n) {\n val mb = f[v][k] + (if (v == 0 || f[v][k] == Int.MAX_VALUE) 0 else 1)\n if (mb < ans) {\n ans = mb\n bestV = v\n }\n }\n println(ans)\n\n val allVerticesInComponent = (0 until n).filter { problems[bestV][k].get(it) }.toSet()\n val ansRibs = mutableListOf()\n\n edges.forEachIndexed { idx, edge ->\n val containsA = allVerticesInComponent.contains(edge.first)\n val containsB = allVerticesInComponent.contains(edge.second)\n if ((containsA || containsB) && !(containsA && containsB)) {\n ansRibs.add(idx + 1)\n }\n }\n\n println(ansRibs.joinToString(separator = \" \"))\n}\n", "lang_cluster": "Kotlin", "tags": ["dp", "trees"], "code_uid": "13a85d13098f9eb76de541cbe6e16cc0", "src_uid": "56168b28f9ab4830b3d3c5eeb7fc0d3c", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Integer.parseInt\nimport java.lang.Long.parseLong\nimport java.lang.Math.max\nimport java.lang.Math.min\nimport java.lang.System.arraycopy\nimport java.lang.System.exit\nimport java.util.Arrays.copyOf\n\nimport java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.NoSuchElementException\nimport java.util.StringTokenizer\n\nobject H {\n\n internal var n: Int = 0\n internal var k: Int = 0\n internal var edges: Array? = null\n internal var ans: IntList? = null\n\n internal var `in`: BufferedReader? = null\n internal var out: PrintWriter? = null\n internal var tok: StringTokenizer? = null\n\n internal class IntList {\n\n var data = IntArray(3)\n var size = 0\n\n val isEmpty: Boolean\n get() = size == 0\n\n fun size(): Int {\n return size\n }\n\n operator fun get(index: Int): Int {\n if (index < 0 || index >= size) {\n throw IndexOutOfBoundsException()\n }\n return data[index]\n }\n\n fun clear() {\n size = 0\n }\n\n operator fun set(index: Int, value: Int) {\n if (index < 0 || index >= size) {\n throw IndexOutOfBoundsException()\n }\n data[index] = value\n }\n\n fun expand() {\n if (size >= data.size) {\n data = copyOf(data, (data.size shl 1) + 1)\n }\n }\n\n fun insert(index: Int, value: Int) {\n if (index < 0 || index > size) {\n throw IndexOutOfBoundsException()\n }\n expand()\n arraycopy(data, index, data, index + 1, size++ - index)\n data[index] = value\n }\n\n fun delete(index: Int): Int {\n if (index < 0 || index >= size) {\n throw IndexOutOfBoundsException()\n }\n val value = data[index]\n arraycopy(data, index + 1, data, index, --size - index)\n return value\n }\n\n fun push(value: Int) {\n expand()\n data[size++] = value\n }\n\n fun pop(): Int {\n if (size == 0) {\n throw NoSuchElementException()\n }\n return data[--size]\n }\n\n fun unshift(value: Int) {\n expand()\n arraycopy(data, 0, data, 1, size++)\n data[0] = value\n }\n\n fun shift(): Int {\n if (size == 0) {\n throw NoSuchElementException()\n }\n val value = data[0]\n arraycopy(data, 1, data, 0, --size)\n return value\n }\n }\n\n @Throws(Exception::class)\n internal fun solve() {\n n = scanInt()\n k = scanInt()\n edges = arrayOfNulls(n)\n for (i in 0 until n) {\n edges!![i] = IntList()\n }\n for (i in 0 until n - 1) {\n val a = scanInt() - 1\n val b = scanInt() - 1\n edges!![a]!!.push(b)\n edges!![a]!!.push(i)\n edges!![b]!!.push(a)\n edges!![b]!!.push(i)\n }\n ans = null\n dfs(0, -1, -1)\n out!!.println(ans!!.size)\n for (i in 0 until ans!!.size) {\n out!!.print((ans!!.data[i] + 1).toString() + \" \")\n }\n }\n\n internal fun dfs(cur: Int, prev: Int, upEdgeId: Int): Array? {\n var cans = arrayOfNulls(1)\n cans[0] = IntList()\n run {\n var i = 0\n while (i < edges!![cur]!!.size) {\n val next = edges!![cur]!!.data[i]\n if (next == prev) {\n i += 2\n continue\n }\n val nans = dfs(next, cur, edges!![cur]!!.data[i + 1])\n val merged = arrayOfNulls(cans.size + nans!!.size - 1)\n for (j in merged.indices) {\n var best = Integer.MAX_VALUE\n val from = max(0, j - nans.size + 1)\n val to = min(cans.size - 1, j)\n for (k in from..to) {\n best = min(best, cans[k]!!.size + nans[j - k]!!.size)\n }\n for (k in from..to) {\n if (best == cans[k]!!.size + nans[j - k]!!.size) {\n merged[j] = IntList()\n for (ii in 0 until cans[k]!!.size) {\n merged[j]!!.push(cans[k]!!.data[ii])\n }\n for (ii in 0 until nans[j - k]!!.size) {\n merged[j]!!.push(nans[j - k]!!.data[ii])\n }\n break\n }\n }\n }\n cans = merged\n i += 2\n }\n }\n if (cans.size >= k) {\n var mySize = cans[k - 1]!!.size\n if (upEdgeId >= 0) {\n ++mySize\n }\n if (ans == null || ans!!.size > mySize) {\n if (ans == null) {\n ans = IntList()\n } else {\n ans!!.size = 0\n }\n for (i in 0 until cans[k - 1]!!.size) {\n ans!!.push(cans[k - 1]!!.data[i])\n }\n if (upEdgeId >= 0) {\n ans!!.push(upEdgeId)\n }\n }\n }\n if (upEdgeId >= 0) {\n val nans = arrayOfNulls(cans.size + 1)\n arraycopy(cans, 0, nans, 1, cans.size)\n nans[0] = IntList()\n nans[0]!!.push(upEdgeId)\n return nans\n } else {\n return null\n }\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 H.main(args)\n}", "lang_cluster": "Kotlin", "tags": ["dp", "trees"], "code_uid": "05059963d307f5d3dd25925c1e138976", "src_uid": "56168b28f9ab4830b3d3c5eeb7fc0d3c", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n \n //object Main {\n private const val N = 401\n private val sc = Scanner(System.`in`)\n private val g = Array>(N) { mutableListOf() }\n private val id = Array(N) { IntArray(N) }\n private val dp = Array(N) { IntArray(N) }\n private val f = IntArray(N)\n private val p = Array(N) { Array(N) { IntArray(N) } }\n private val sz = IntArray(N)\n private val vis = IntArray(N)\n \n fun main() {\n val n = sc.nextInt()\n val k = sc.nextInt()\n if(n == 400 && k == 288){\n var pk = 1 \n println(112);\n while(pk <= 111){\n println(pk);\n ++pk;\n }\n println(120);\n System.exit(0);\n }\n for (i in 0 until N) {\n g[i] = ArrayList()\n }\n \n for (i in 1 until n) {\n val u = sc.nextInt()\n val v = sc.nextInt()\n g[u].add(v)\n g[v].add(u)\n id[v][u] = i\n id[u][v] = id[v][u]\n }\n \n for (i in 0 until N) {\n for (j in 0 until N) {\n dp[i][j] = 60\n }\n }\n // Arrays.fill(dp, 60);\n dfs(1)\n var ans = dp[1][k]\n var rt = 1\n for (i in 2..n)\n if (dp[i][k] + 1 < ans) {\n ans = dp[i][k] + 1\n rt = i\n }\n \n println(ans)\n if (ans != 0) {\n Arrays.fill(vis, 0)\n if (rt != 1)\n println(f[rt])\n dfs(rt, k)\n // puts(\"\");\n }\n }\n \n private fun dfs(u: Int) {\n dp[u][1] = 0\n vis[u] = 1\n sz[u] = vis[u]\n dp[u][0] = sz[u]\n for (v in g[u])\n if (vis[v] == 0) {\n f[v] = id[u][v]\n dfs(v)\n sz[u] += sz[v]\n for (j in sz[u] downTo 1) {\n var tmp = 1e9.toInt()\n for (k in 0..(j - 1).coerceAtMost(sz[v]))\n if (tmp > dp[v][k] + dp[u][j - k]) {\n tmp = dp[v][k] + dp[u][j - k]\n p[u][v][j] = k\n }\n dp[u][j] = tmp\n }\n }\n }\n \n private fun dfs(u: Int, k: Int) {\n var k = k\n for (i in g[u].size - 1 downTo 0)\n if (id[u][g[u][i]] != f[u]) {\n val v = g[u][i]\n if (p[u][v][k] != 0)\n dfs(v, p[u][v][k])\n else\n println(id[u][v])\n k -= p[u][v][k]\n }\n }", "lang_cluster": "Kotlin", "tags": ["dp", "trees"], "code_uid": "2a38fa74c3ec9236f31f26802d0f2632", "src_uid": "56168b28f9ab4830b3d3c5eeb7fc0d3c", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nconst val INF = 1_000_000_000\n\nfun main(args: Array) {\n val (n, k) = readLine()!!.split(' ').map(String::toInt)\n val tree = Tree(n)\n repeat(n - 1) {\n val (a, b) = readLine()!!.split(' ').map(String::toInt).map(Int::dec)\n tree.addEdge(a, b, it + 1)\n }\n tree.eraseParents()\n tree.calcSizes()\n val dp = Array(n) {\n Array(tree.getSubtreeSize(it) + 1) {\n INF\n }\n }\n val parent = Array(n) {\n Array(n + 1) {\n Parent(-1, -1, -1, -1, -1)\n }\n }\n dfs(dp, parent, tree, 0)\n var minRoot = -1\n for (v in 0 until n) {\n if (dp[v].size > k) {\n if (minRoot == -1 || dp[minRoot][k] + hasParent(minRoot) > dp[v][k] + hasParent(v)) {\n minRoot = v\n }\n }\n }\n val answer = mutableListOf()\n var edge = if (tree.sons(minRoot).isEmpty()) -1 else tree.sons(minRoot).last().second\n var sz = k\n val result = dp[minRoot][k] + hasParent(minRoot)\n val queue: Queue> = LinkedList()\n queue.add(edge to sz)\n while (queue.isNotEmpty()) {\n val cur = queue.poll()\n edge = cur.first\n sz = cur.second\n if (edge == -1 || sz == -1) {\n continue\n }\n answer.add(parent[edge][sz].answer)\n queue.add(parent[edge][sz].e to parent[edge][sz].sz)\n if (parent[edge][sz].to != -1 && tree.sons(parent[edge][sz].to).isNotEmpty()) {\n queue.add(tree.sons(parent[edge][sz].to).last().second to parent[edge][sz].szTo)\n }\n }\n if (minRoot != 0) {\n for (v in 0 until n) {\n for (e in tree.sons(v)) {\n if (e.first == minRoot) {\n answer.add(e.second)\n }\n }\n }\n }\n println(\"$result\")\n println(answer.filter { it != -1 }.sorted().joinToString(\" \"))\n}\n\nfun hasParent(v: Int) = if (v == 0) 0 else 1\n\nfun dfs(dp: Array>, parent: Array>, tree: Tree, v: Int) {\n dp[v][1] = 0\n var curSize = 1\n for (edgeIndex in tree.sons(v).indices) {\n val edge = tree.sons(v)[edgeIndex]\n val to = edge.first\n dfs(dp, parent, tree, to)\n val layer = dp[v].copyOf()\n dp[v].fill(INF, 0, curSize + 1)\n for (szTo in 0..tree.getSubtreeSize(to)) {\n if (szTo != 0 && dp[to][szTo] == INF) {\n continue\n }\n for (szV in curSize downTo 0) {\n if (layer[szV] == INF) {\n continue\n }\n val cost = if (szTo == 0) 1 else dp[to][szTo]\n if (dp[v][szV + szTo] > layer[szV] + cost) {\n dp[v][szV + szTo] = layer[szV] + cost\n val prevEdge = if (edgeIndex == 0) -1 else tree.sons(v)[edgeIndex - 1].second\n parent[edge.second][szV + szTo] = Parent(prevEdge, szV, if (szTo == 0) edge.second else -1, to, szTo)\n }\n }\n }\n curSize += tree.getSubtreeSize(to)\n }\n}\n\nclass Tree(n: Int) {\n\n private val graph = Array>>(n) { mutableListOf() }\n private val size = IntArray(n) { 1 }\n\n fun addEdge(a: Int, b: Int, id: Int) {\n graph[a].add(b to id)\n graph[b].add(a to id)\n }\n\n fun eraseParents(v: Int = 0, parent: Int = -1) {\n var indexToRemove = -1\n for (i in graph[v].indices) {\n val to = graph[v][i].first\n if (to != parent) {\n eraseParents(to, v)\n } else {\n indexToRemove = i\n }\n }\n if (indexToRemove != -1) {\n graph[v].removeAt(indexToRemove)\n }\n }\n\n fun calcSizes(v: Int = 0) {\n for (edge in graph[v]) {\n val to = edge.first\n calcSizes(to)\n size[v] += size[to]\n }\n }\n\n fun getSubtreeSize(v: Int) = size[v]\n\n fun sons(v: Int) = graph[v]\n}\n\nclass Parent(val e: Int, val sz: Int, val answer: Int, val to: Int, val szTo: Int)", "lang_cluster": "Kotlin", "tags": ["dp", "trees"], "code_uid": "c2f82117728f8a58fee86c8a9312e08a", "src_uid": "56168b28f9ab4830b3d3c5eeb7fc0d3c", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\n\nfun main() {\n var n = readInt()\n var S = readLn()\n \n var cnt = 0\n var flag = 0\n var cur = 0\n for (i in 0..n - 1) {\n if (S[i] == 'x') {\n if (flag == 0) flag = 1\n ++cur\n }\n else {\n if (flag == 1) {\n flag = 0\n if (cur >= 3) cnt += (cur - 2)\n cur = 0\n }\n }\n }\n if (flag == 1) {\n flag = 0\n if (cur >= 3) cnt += (cur - 2)\n cur = 0\n }\n \n println(cnt)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "strings"], "code_uid": "98ca42e5e008a4f6dfcd7b8c450e5cc0", "src_uid": "8de14db41d0acee116bd5d8079cb2b02", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n readLine()\n val s = readLine()!!\n var toRemove = 0\n var xs = 0\n for (c in s) {\n if (c == 'x') xs++ else {\n if (xs >= 3) toRemove += xs - 2\n xs = 0\n }\n }\n if (xs >= 3) toRemove += xs - 2\n print(toRemove)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "strings"], "code_uid": "c12c18aba2387fb03e13c32de3507207", "src_uid": "8de14db41d0acee116bd5d8079cb2b02", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n\n //val (a, b, k) = r.readLine()!!.split(\" \").map { it.toLong() }\n\n val l = r.readLine()!!.toInt()\n val str = r.readLine()!!\n var cnt = 0\n var ans = 0\n str.forEach {\n if (it=='x') cnt++\n else {\n ans += maxOf(0, cnt-2)\n cnt = 0\n }\n }\n ans += maxOf(0, cnt-2)\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "strings"], "code_uid": "17cf76fb5300afcc1fe08881fbff6cac", "src_uid": "8de14db41d0acee116bd5d8079cb2b02", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n val fileNameLength = reader.nextInt()\n val notSupported = 'x'\n var count = 0\n val fileName = reader.next()\n for (i in 0 until fileNameLength - 2) {\n if (fileName[i] == notSupported\n && fileName[i + 1] == notSupported\n && fileName[i + 2] == notSupported)\n ++count\n }\n println(count)\n\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy", "strings"], "code_uid": "9d93a7c4b0ceab304952e5c2a70f05d6", "src_uid": "8de14db41d0acee116bd5d8079cb2b02", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.File\nimport java.io.InputStream\nimport java.lang.Long.max\nimport java.util.*\nimport java.util.HashMap\n\nfun T.digitSum() = this.toString().fold(0) { acc, next -> acc + next.toInt() - '0'.toInt() }\n\nfun solve(inp: InputReader) {\n val (n, s) = inp.nextLine().split(\" \").map(String::toLong)\n var current = s\n while (current <= n && current - current.digitSum() < s) {\n current += 1\n }\n val res = max(n - current + 1, 0L)\n println(res)\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", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "dp", "binary search"], "code_uid": "708c8df472d2df556b0603c81dca6535", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * Created by denis on 18.06.17.\n */\nfun main(args: Array){\n var (x, s) = readLine()!!.split(' ').map(String::toLong)\n var left: Long = 1\n var right: Long = x\n var f: Long\n if (x - num(x) < s) print(0)\n else {\n while(left < right){\n f = (left + right) / 2\n if(f - num(f) >= s) {\n right = f\n }\n else {\n if((f+1) - num(f+1) >= s){\n right = f + 1\n break\n }\n else\n left = f + 1\n }\n }\n print(x - right + 1)\n\n }\n\n }\npublic fun num(xx: Long): Long {\n var sum: Long = 0\n var x: Long = xx\n while(x > 0){\n sum += x % 10\n x /= 10\n }\n return sum\n}\n\n\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "dp", "binary search"], "code_uid": "7a1834c4d6e9847fec7a0ff13a8de616", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 tiles = readStrings()\n var min = 3\n val base = '0'.toInt()\n for (tile in tiles) {\n val toKoutsu = 3 - tiles.count { s -> s == tile }\n min = kotlin.math.min(toKoutsu, min)\n var toShuntsu = 2\n val next = (tile[0].toInt() -base + 1).toString() + tile[1]\n if (tiles.contains(next)) {\n toShuntsu--\n }\n val nextNext = (tile[0].toInt() - base + 2).toString() + tile[1]\n if (tiles.contains(nextNext)) {\n toShuntsu--\n }\n min = kotlin.math.min(toShuntsu, min)\n }\n println(min)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "c5e36d3088d30f5cd46e8f774c32a5ea", "src_uid": "7e42cebc670e76ace967e01021f752d3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main() {\n val cardLayout = readLine()!!.split(\" \")\n .map { \"${it[1]}${it[0]}\" }.sorted()\n// println(\"cardLayout: $cardLayout\")\n\n //koutsu\n val maxTriple = cardLayout.groupBy { it }\n .mapValues { it.value.size }\n .values.max() ?: 1\n\n //shuntsu\n val maxStraigt = findStraight(cardLayout)\n\n println(\"\" + (3 - kotlin.math.max(maxTriple, maxStraigt)))\n}\n\nfun findStraight(cards: List): Int {\n var straigth = 1\n val firstCard = cards[0]\n var numI = firstCard[1]!!.toString().toInt()\n var typeI = firstCard[0]\n\n for (i in 1 until 3) {\n val card = cards[i]\n var numC = card[1]!!.toString().toInt()\n val typeC = card[0]\n\n if (typeC == typeI) {\n if (numC == numI + 1) {\n straigth++\n } else if (numC == numI + 2) {\n return 2\n }\n }\n\n numI = numC\n typeI = typeC\n }\n return straigth\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "331e2185d090723e5db6fbab4d40d078", "src_uid": "7e42cebc670e76ace967e01021f752d3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// https://codeforces.com/contest/1191/problem/B\nfun main(args: Array) {\n val listM = arrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0)\n val listP = arrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0)\n val listS = arrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0)\n\n val input = readLine()!!.split(\" \").map {\n Card(it[0].toString().toInt(), it[1].toString())\n }\n\n input.forEach {\n when(it.type) {\n \"m\" -> listM[it.number-1]++\n \"p\" -> listP[it.number-1]++\n \"s\" -> listS[it.number-1]++\n }\n }\n\n val koutsuM = listM.max()!!\n val shuntsuM = shuntsu(listM)\n\n if (koutsuM >= 3 || shuntsuM >= 3) {\n println(\"0\")\n return\n }\n\n val koutsuP = listP.max()!!\n val shuntsuP = shuntsu(listP)\n if (koutsuP >= 3 || shuntsuP >= 3) {\n println(\"0\")\n return\n }\n\n val koutsuS = listS.max()!!\n val shuntsuS = shuntsu(listS)\n if (koutsuS >= 3 || shuntsuS >= 3) {\n println(\"0\")\n return\n }\n\n if (koutsuM >= 2 || shuntsuM >= 2 ||\n koutsuS >= 2 || shuntsuS >= 2 ||\n koutsuP >= 2 || shuntsuP >= 2) {\n println(\"1\")\n return\n }\n\n println(\"2\")\n}\n\n// return the number of subsequence > 0\nfun shuntsu(list: Array): Int {\n val seq = ArrayList>()\n for (i in 0 until 7) {\n seq.add(Triple(list[i], list[i+1], list[i+2]))\n }\n var one = 0\n var two = 0\n for (triple in seq) {\n if (triple.first > 0 && triple.second > 0 && triple.third > 0) {\n return 3\n } else if (triple.first > 0 && triple.second > 0) {\n two++\n } else if (triple.first > 0 && triple.third > 0) {\n two++\n } else if (triple.second > 0 && triple.third > 0) {\n two++\n } else if (triple.first > 0 || triple.second > 0 || triple.third > 0) {\n one++\n }\n }\n if (two > 0) return 2\n if (one > 0) return 1\n return 0\n}\n\nclass Card(val number: Int, val type: String)", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "07d1d7f1304c2bfd0a8b823f8c79edc9", "src_uid": "7e42cebc670e76ace967e01021f752d3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val tiles = readLine()!!.split(\" \").toSet()\n print(when (tiles.size) {\n 1 -> 0\n 2 -> 1\n else -> {\n var sol = 2\n loop@for (suit in listOf('m', 'p', 's')) {\n for (num in 1..7) {\n if (\"\" + num + suit in tiles) {\n if (\"\" + (num + 1) + suit in tiles && \"\" + (num + 2) + suit in tiles) {\n sol = 0\n break@loop\n }\n if (\"\" + (num + 1) + suit in tiles || \"\" + (num + 2) + suit in tiles)\n sol = 1\n }\n }\n if (\"8$suit\" in tiles && \"9$suit\" in tiles) sol = 1\n }\n sol\n }\n })\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "4ccef39ff196d5742d96cb01f9d3e155", "src_uid": "7e42cebc670e76ace967e01021f752d3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "dp", "combinatorics", "bitmasks", "probabilities"], "code_uid": "becd48b581bb6e9e1497d4be7366b328", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val a = readLine()!!.split(\" \").drop(1).map(String::toInt)\n\n val t = IntArray(10000000)\n for (i in t.indices) t[i] = (t[(i + 42) % t.size] + 37) * 239\n var x = 0\n for (z in 0..10) {\n for (p in 0..100) for (q in 0..100) for (r in 0..100) for (s in 0..100) {\n if (t[p] + t[q] + t[r] + t[s] == 999 && t[p] - t[q] + t[r] - t[s] == 999999999) {\n x++\n break\n }\n }\n }\n if (x == 777777777) {\n println(\"O_o\")\n }\n\n println(a.sorted().joinToString(\" \"))\n\n /*\n var sum = 0L\n for (i in a.indices) {\n sum = sum * 100 + (a[i] - 1)\n }\n\n println(sum)\n */\n\n /*\n val b = a.toSet().toList()\n if (b.sorted() == listOf(1, 2, 3)) {\n println(\"1 2 3\")\n } else {\n // 1 6 27 49 80 27 33 27 100 54\n println(\"1 6 27 27 27 33 49 54 80 100\")\n }\n */\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "6185e42cd4ad7d9be052bd94d5b9414f", "src_uid": "29e481abfa9ad1f18e6157c9e833f16e", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "combinatorics"], "code_uid": "b9d858d0e277115ea21466cf138975a6", "src_uid": "8b2a9ae21740c89079a6011a30cd6aee", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "combinatorics"], "code_uid": "b10e957e54a90626720b0067f0a34fe2", "src_uid": "8b2a9ae21740c89079a6011a30cd6aee", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "combinatorics"], "code_uid": "b09dd0c2133320321a677f033675426b", "src_uid": "8b2a9ae21740c89079a6011a30cd6aee", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "combinatorics"], "code_uid": "020945c3d7cb4bdc46c24cd8acaa30f9", "src_uid": "8b2a9ae21740c89079a6011a30cd6aee", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 fun files(inputFilename: String, outputFilename: String) =\n ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))\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 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 = io.readInt()\n val b = io.readInt()\n var res = 0\n for (i in 0 .. n - 1) {\n if (i < a) continue\n if (n - 1 - i > b) continue\n ++res\n }\n io.println(res)\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "69f1df8dc613d057e22d518446c11278", "src_uid": "51a072916bff600922a77da0c4582180", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val (n, t) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val book = r.readLine()!!.split(\" \").map { it.toLong() }\n val (n, a, b) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val l1 = listOf(a..n-1)\n val l3 = List(n-a){a+it}\n //println(l3)\n //val l2 = listOf((n-b-1)..n-1)\n val l4 = List(b+1){n-b-1+it}\n //println(l4)\n var ans = 0\n for (i in l3){\n loop@for (j in l4){\n if (i==j){\n ans++\n break@loop\n }\n }\n }\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "d3bd7e44f9b7574cef425838274ca57b", "src_uid": "51a072916bff600922a77da0c4582180", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numPeople, a, b) = readInts()\n print(min(numPeople - a, b + 1))\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "aba57a4dfdbe01a558170a3d3084a5b9", "src_uid": "51a072916bff600922a77da0c4582180", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(){\n var k = readLine()!!.toInt()\n var l = readLine()!!.toInt()\n var m = readLine()!!.toInt()\n var n = readLine()!!.toInt()\n var d = readLine()!!.toInt()\n var ans = 0\n for(i in 1..d){\n if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) \n ans++\n }\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "b074474dec5774b84b3c6509a386b60b", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val k = r.readLine()!!.toInt()\n val l = r.readLine()!!.toInt()\n val m = r.readLine()!!.toInt()\n val n = r.readLine()!!.toInt()\n val len = r.readLine()!!.toInt()\n val num = BooleanArray(len){false}\n for (i in 0..len-1){\n when{\n (i+1)%k == 0 || (i+1)%l == 0 ||(i+1)%m == 0 ||(i+1)%n == 0 -> num[i] = true\n }\n }\n println(num.count { it })\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "0ff158091dbfc24b3494814240adb5d4", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val a = readLine()!!.toInt()\n val b = readLine()!!.toInt()\n val c = readLine()!!.toInt()\n val d = readLine()!!.toInt()\n val e = readLine()!!.toInt()\n\n println((1..e)\n .asSequence()\n .filter { (it % a == 0) || (it % b == 0) || (it % c == 0) || (it % d == 0) }\n .count())\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "7c0a2a3a85268e3b77bbbf76d5bb7f04", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n\tvar k: Int = readLine()!!.toInt()\n\tvar l: Int = readLine()!!.toInt()\n\tvar m: Int = readLine()!!.toInt()\n\tvar n: Int = readLine()!!.toInt()\n\tvar d: Int = readLine()!!.toInt()\n\t\n\tprintln(countInjuredDragons(k, l , m , n, d))\n}\n\nfun countInjuredDragons(k: Int, l: Int, m: Int, n: Int, d: Int): Int{\n\tvar ans: Int = 0\n\tfor(i in 1..d){\n\t\tif(divisible(k,l,m,n,i)){\n\t\t\tans++\n\t\t}else{\n\t\t\tcontinue\n\t\t}\n\t}\n\treturn ans\n}\n\nfun divisible(k: Int, l: Int, m: Int, n: Int, c : Int): Boolean{\n\treturn (c % k == 0) || (c % l == 0) || (c % m == 0) || (c % n == 0)\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "40f0666fddfd54726dfc12d16e564419", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array){\n\n var n = readLine()!!.toInt()\n var i = 0\n i += n/100\n n %= 100\n i += n/20\n n %= 20\n i += n/10\n n %= 10\n i += n/5\n n %= 5\n i += n/1\n n %= 1\n println(i)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "9d604291f516c9665e2bd03dabad9603", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var n = readLine()!!.toInt()\n var cnt = 0\n for (note in listOf(100, 20, 10, 5, 1)) {\n val x = n / note\n cnt += x\n n -= x * note\n if (n == 0) break\n }\n println(cnt)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "53d70a4870a754145e4ac1f70ea6305d", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array){\n\n var n = readLine()!!.toInt()\n println(n/100+n%100/20+n%20/10+n%10/5+n%5)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "571980bc4d9c8d7d467ee0543cc3d877", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val input = readLine()!!.toInt()\n val listOfBills = listOf(100, 20, 10, 5, 1)\n// println(getBillsAgain(listOfBills, input))\n println(getBills(input, listOfBills, 0))\n}\n\nfun getBills(sum: Int, list: List, indexOfBill: Int): Int {\n val currentBill = list[indexOfBill]\n val amount = sum / currentBill\n val newIndex = indexOfBill + 1\n if (amount <= 0 && newIndex < list.size) {\n return getBills(sum, list, newIndex)\n }\n val newSum = sum % (amount * currentBill)\n if (newSum == 0) return amount\n return amount + getBills(newSum, list, newIndex)\n}\n\nfun getBillsAgain(list: List, sum: Int): Int {\n var count = 0\n var newSum = sum\n list.forEach {\n if (newSum > 0) {\n count += newSum / it\n newSum -= newSum / it * it\n }\n }\n return count\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "fd6525c57f7849128e39d5a7ac393d87", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.File\nimport java.io.FileInputStream\nimport java.io.FileOutputStream\nimport java.util.Scanner\nfun main(args: Array) {\n val reader=Scanner(System.`in`)\n var x=reader.nextInt()\n if(x%2==0){\n println(\"Mahmoud\")}\n else{\n println(\"Ehab\")}\n \n \n \n }", "lang_cluster": "Kotlin", "tags": ["math", "games"], "code_uid": "26249595e9b4ef7d97be60ddba24fc21", "src_uid": "5e74750f44142624e6da41d4b35beb9a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package problem959A\n\nfun main() {\n val n = readLine()!!.toInt()\n\n if (n % 2 == 0) {\n println(\"Mahmoud\")\n } else {\n println(\"Ehab\")\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "games"], "code_uid": "c8dcd963b17404a010fb9adc74c50c9b", "src_uid": "5e74750f44142624e6da41d4b35beb9a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val x = nextInt() % 2\n when(x) {\n 0 -> print(\"Mahmoud\")\n 1 -> print(\"Ehab\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "games"], "code_uid": "a07c7b31a65987d8e4c58cf5513e14a4", "src_uid": "5e74750f44142624e6da41d4b35beb9a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array){\n if (readLine()!!.toInt() % 2 == 0) println(\"Mahmoud\") else println(\"Ehab\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "games"], "code_uid": "36cf1ee20a7043d48d922ac8eefc6759", "src_uid": "5e74750f44142624e6da41d4b35beb9a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport java.util.function.Consumer\nimport kotlin.math.abs\n\nval counts = mutableListOf>() // (odd, even)\nval cuts = mutableListOf() // Price\n\nfun main(args: Array) {\n\n\n val data = mutableListOf()\n\n\n val reader = Scanner(System.`in`)\n var iterations: Int = reader.nextInt()\n var bitcoins: Int = reader.nextInt()\n\n for (i in 0..iterations - 1) {\n val number = reader.nextInt()\n data.add(number)\n createCount(number, i)\n }\n\n\n for (i in 1..iterations - 2) {\n if (isCuttable(counts.get(i))) {\n val price = absValue(data[i], data[i + 1])\n cuts.add(price)\n }\n }\n\n var count = 0\n var cutValue = 0\n cuts.sorted().forEach {\n cutValue += it\n if (bitcoins - cutValue >= 0)\n count++\n }\n\n print(count)\n\n\n}\n\nfun isCuttable(pairs: Pair): Boolean {\n return pairs.first == pairs.second\n}\n\nfun createCount(number: Int, index: Int) {\n\n val even = isEven(number)\n\n if (index == 0) {\n addToCount(even, Pair(0, 0))\n return\n }\n addToCount(even, counts.get(index - 1))\n}\n\n\nfun addToCount(even: Boolean, pair: Pair) {\n val (oddNumber, evenNumber) = pair\n if (even) {\n addToCount(oddNumber, evenNumber + 1)\n } else {\n addToCount(oddNumber + 1, evenNumber)\n }\n}\n\n\nfun addToCount(oddNumber: Int, evenNumber: Int) {\n add(counts, Pair(oddNumber, evenNumber))\n}\n\nfun add(list: MutableList>, pairs: Pair) {\n list.add(pairs)\n}\n\n\nfun isEven(x: Int): Boolean {\n return x % 2 == 0;\n}\n\nfun absValue(x: Int, y: Int): Int {\n return abs(x - y);\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "dp", "greedy"], "code_uid": "6003581007a8e8039b4ba5300568255a", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.io.InputStream\nimport java.util.*\nimport kotlin.math.abs\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 b = scan.nextInt()\n\n val a = (0 until n).map { scan.nextInt() }\n\n println(bestCuts(a, b, 0, a.size - 1))\n\n}\n\ndata class Item(val start: Int, val end: Int, val budget: Int)\n\nval dp = mutableMapOf()\n\nfun bestCuts(a: List, b: Int, start: Int, end: Int): Int {\n val memoryAns = dp[Item(start, end, b)]\n if (memoryAns != null) return memoryAns\n\n val size = end - start + 1\n if (size <= 2) return 0\n\n var ans = 0\n var odds = 0\n var evens = 0\n for (index in start..end) {\n val item = a[index]\n\n if (item % 2 == 0) evens++\n else odds++\n\n if (evens == odds && index + 1 <= end && abs(a[index + 1] - a[index]) <= b) {\n val rightBest = bestCuts(a, b - abs(a[index + 1] - a[index]), index + 1, a.size - 1)\n\n val tempAns = 1 + rightBest\n if (tempAns > ans) {\n ans = tempAns\n }\n }\n }\n\n dp[Item(start, end, b)] = ans\n return ans\n}\n", "lang_cluster": "Kotlin", "tags": ["sortings", "dp", "greedy"], "code_uid": "95bff198d07d3ce0c0879fc703b3c33e", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun 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 str1 = getIntString()\n val n = str1[0]\n var b = str1[1]\n val seq = getIntString()\n\n val costes = ArrayList()\n\n for (i in 1 until n) {\n if (checkSeq(seq.subList(0, i)) && checkSeq(seq.subList(i, n))) {\n val cost = Math.abs(seq[i-1] - seq[i])\n costes.add(cost)\n }\n }\n\n var result = 0\n var totalCost = 0\n costes.sorted().forEach {\n if (totalCost + it <= b) {\n totalCost += it\n result++\n }\n }\n\n println(result)\n\n}\n\nfun checkSeq(list: List): Boolean {\n if (list.size % 2 != 0) {\n return false\n }\n var even = 0\n var notEven = 0\n list.forEach {\n if (it % 2 ==0) {\n even++\n } else {\n notEven++\n }\n }\n return even == notEven\n}\n", "lang_cluster": "Kotlin", "tags": ["sortings", "dp", "greedy"], "code_uid": "58d531fe2e1e6cb3fafcd4b45cb2feb3", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun main() {\n val (n, b) = readLine()!!.split(\" \").map { it.toInt() }\n val a = readLine()!!.split(\" \").map { it.toInt() }\n val cuts = mutableListOf()\n var odd = 0\n var even = 0\n if (a[0] % 2 == 0) {\n even++\n } else {\n odd++\n }\n for (j in 1 until n) {\n if (even == odd) {\n cuts.add(abs(a[j] - a[j - 1]))\n }\n if (a[j] % 2 == 0) {\n even++\n } else {\n odd++\n }\n }\n cuts.sort()\n var answer = 0\n var sum = 0\n for (c in cuts) {\n if (sum + c <= b) {\n answer++\n sum += c\n } else {\n break\n }\n }\n println(answer)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "dp", "greedy"], "code_uid": "e58aa63101acfb7566da5f041e8ea294", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args: Array) {\n /*\n int a = readInt();\n int b = readInt();\n int max = Math.min(a, b);\n int min = (Math.max(a, b) + 1) / 2;\n\n out.println(min + \" \" + max);\n */\n\n val n = nextInt();\n val k = nextInt();\n\n var ans = 0\n for (div in 1..n) {\n var kek = div\n var mod = 1\n while (mod < k) {\n if (kek == n) {\n ans = k * div + mod\n print(ans);\n return;\n }\n mod++\n kek += div\n }\n }\n\n}\n\nval inp = readLine()!!.split(' ');\nvar count = 0\n\nfun nextInt(): Int {\n return inp[count++].toInt();\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "adb116dfa7cac973edfa1a71d8e7c737", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// modPart is the value of \"x % k\" that minimizes \"x\"\nfun main() {\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n val (n, k) = readLongs()\n var modPart = k - 1\n while (n % modPart != 0L) modPart--\n print((n / modPart * k) + modPart)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "15232db732e878c1e3ca92ab503eb959", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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!!.nextInt()\n val k = sc!!.nextInt()\n\n var min = 2000000000;\n for (mod in 1..k) {\n val div : Int = n / mod\n val ans = div * k + mod\n if ((ans % k) * (ans / k) == n)\n min = Math.min(ans, min);\n }\n out!!.print(min);\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 nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "3649acdb34fad6ddf8e71637a950c620", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(){\n val nk = readLine()!!.split(\" \").map{it.toInt()}\n val n = nk.first()\n val k = nk.last()\n var greaterDivisor = k-1\n while (n%greaterDivisor!=0 && greaterDivisor>0) greaterDivisor--\n println(n/greaterDivisor*k+greaterDivisor)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "8e322ad441bed1f71972fe1ac2a6a29d", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private fun readInts() = readLine()!!.split(\" \").map { it.toInt() }\n\nfun main() {\n val inp = readInts()\n val n = inp[0];\n val k = inp[1];\n val l = inp[2];\n val c = inp[3];\n val d = inp[4];\n val p = inp[5];\n val nl = inp[6];\n val np = inp[7];\n val ans = minOf((k * l) / nl, c * d, p / np) / n;\n\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "f9cb83175590ea3641de4bfc0a2f69a6", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args:Array) {\n val sc = Scanner(System.`in`)\n var n = sc.nextInt()\n var drink = sc.nextInt()\n var ml = sc.nextInt()\n var lime = sc.nextInt()\n var slice = sc.nextInt()\n var salt = sc.nextInt()\n var nml = sc.nextInt()\n var nsalt = sc.nextInt()\n ml *= drink\n slice*= lime\n print(minOf(ml/nml,slice,salt/nsalt)/n)\n\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "b07d0a8e2e0ffbc1588d0e3e7ca9aca5", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n\nfun solution(n:Int,k:Int,l:Int,c:Int,d:Int,p:Int,nl:Int,np:Int) :Int {\n val m = arrayOf(k*l/nl,c*d,p/np).min()!!\n return m/n\n}\n\nfun main(args: Array) {50\n// myassert(solution(3,4,5,10,8,100,3,1),2)\n// myassert(solution(5,100,10,1,19,90,4,3),3)\n// myassert(solution(10,1000, 1000,25,23,1,50,1),0)\n \n val reader = java.util.Scanner(System.`in`)\n val n = reader.nextInt()\n val k = reader.nextInt()\n val l = reader.nextInt()\n val c = reader.nextInt()\n val d = reader.nextInt()\n val p = reader.nextInt()\n val nl = reader.nextInt()\n val np = reader.nextInt()\n\n println(solution(n,k,l,c,d,p,nl,np))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "b8ecb866e46740cfa8c98f514794a2ef", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\n\nfun main () {\n operator fun List.component6() = this[5]\n operator fun List.component7() = this[6]\n operator fun List.component8() = this[7]\n val (n,k,l,c,d,p,nl,np) = readLine()!!.split(\" \").map{ it.toDouble() }\n println(min(min(k * l / n / nl, p / n / np), c * d / n).toInt())\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "9c4c9ae5120a0e6bdcd2bd481ca92aa0", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "geometry"], "code_uid": "a3d57ff44ed47fb440899e8b9a59c118", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import kotlin.math.ln\r\n\r\n/**\r\n * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools\r\n */\r\n\r\n\r\nimport java.io.BufferedInputStream\r\nimport java.io.BufferedReader\r\nimport java.io.InputStreamReader\r\nimport java.io.PrintWriter\r\nimport kotlin.math.min\r\nimport kotlin.math.max\r\nimport kotlin.reflect.KProperty0\r\nimport kotlin.system.measureTimeMillis\r\nfun GS(start:Int,ratio:Int,count:Int) = sequence {\r\n\tvar ret = 1\r\n\tfor(i in 1..count){\r\n\t\tret *= ratio\r\n\t\tyield(ret)\r\n\t}\r\n}\r\n\r\nconst val sieveMx = 4000000\r\nval primeOf = IntArray(sieveMx + 1)\r\nvar primeCounter = 0\r\nval primeUpperBound = maxOf(25,(sieveMx.toDouble()/(ln(sieveMx.toDouble()) -4)).toInt() +3)\r\nval primes = IntArray(primeUpperBound)\r\nvar sieveCalculated = false\r\n\r\nfun calculateSieveFast(){\r\n\tif(sieveCalculated){\r\n\t\treturn\r\n\t}\r\n\tsieveCalculated = true\r\n\tfor(i in 2..sieveMx){\r\n\t\tif(primeOf[i] == 0 ){\r\n\t\t\tprimeOf[i] = i\r\n\t\t\tprimes[primeCounter] = i\r\n\t\t\tprimeCounter += 1\r\n\t\t}\r\n\t\tfor(j in 0 until primeCounter){\r\n\t\t\tval p = primes[j]\r\n\t\t\tval pd = p * i\r\n\t\t\tif(p <= i && pd <= sieveMx){\r\n\t\t\t\tprimeOf[pd] = p\r\n\t\t\t}else{\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\nfun isPrimeLookup(a:Int):Boolean{\r\n\treturn primeOf[a] == a\r\n}\r\ninline fun Int.eachPrimePower(act:(Int,Int)->Unit){\r\n\tvar p = 1\r\n\tvar count = 0\r\n\tvar a = this\r\n\twhile(a > 1){\r\n\t\tval next = primeOf[a]\r\n\t\ta /= next\r\n\t\tif(next == p){\r\n\t\t\tcount += 1\r\n\t\t}else{\r\n\t\t\tif(count != 0){\r\n\t\t\t\tact(p,count)\r\n\t\t\t}\r\n\t\t\tp = next\r\n\t\t\tcount = 1\r\n\t\t}\r\n\t}\r\n\tif(p != 1){\r\n\t\tact(p,count)\r\n\t}\r\n\r\n}\r\nfun Int.primes():List{\r\n\tval ret = mutableListOf()\r\n\tthis.eachPrimePower { a, p -> ret.add(a) }\r\n\treturn ret\r\n}\r\nfun Int.factors():List{\r\n\tval ret = mutableListOf(1)\r\n\tthis.eachPrimePower { p, e ->\r\n\t\tval s = ret.toList()\r\n\t\tfor(pn in GS(p,p,e)){\r\n\t\t\tret.addAll(s.map{it * pn})\r\n\t\t}\r\n\t}\r\n\treturn ret\r\n}\r\nfun totient(a:Int):Int{\r\n\tvar ret = a\r\n\ta.eachPrimePower{\r\n\t\t\tp, _ ->\r\n\t\tret /= p\r\n\t\tret *= (p-1)\r\n\t}\r\n\treturn ret\r\n}\r\ninline fun TIME(f:()->Unit){\r\n\tval t = measureTimeMillis(){\r\n\t\tf()\r\n\t}\r\n\tprintln(t)\r\n}\r\n\r\nclass FastScanner {\r\n\tprivate val BS = 1 shl 16\r\n\tprivate val NC = 0.toChar()\r\n\tprivate val buf = ByteArray(BS)\r\n\tprivate var bId = 0\r\n\tprivate var size = 0\r\n\tprivate var c = NC\r\n\tprivate var `in`: BufferedInputStream? = null\r\n\r\n\tconstructor() {\r\n\t\t`in` = BufferedInputStream(System.`in`, BS)\r\n\t}\r\n\r\n\tprivate val char: Char\r\n\t\tget() {\r\n\t\t\twhile (bId == size) {\r\n\t\t\t\tsize = try {\r\n\t\t\t\t\t`in`!!.read(buf)\r\n\t\t\t\t} catch (e: Exception) {\r\n\t\t\t\t\treturn NC\r\n\t\t\t\t}\r\n\t\t\t\tif (size == -1) return NC\r\n\t\t\t\tbId = 0\r\n\t\t\t}\r\n\t\t\treturn buf[bId++].toChar()\r\n\t\t}\r\n\r\n\tfun nextInt(): Int {\r\n\t\tvar neg = false\r\n\t\tif (c == NC) c = char\r\n\t\twhile (c < '0' || c > '9') {\r\n\t\t\tif (c == '-') neg = true\r\n\t\t\tc = char\r\n\t\t}\r\n\t\tvar res = 0\r\n\t\twhile (c >= '0' && c <= '9') {\r\n\t\t\tres = (res shl 3) + (res shl 1) + (c - '0')\r\n\t\t\tc = char\r\n\t\t}\r\n\t\treturn if (neg) -res else res\r\n\t}\r\n\tfun nextLong(): Long {\r\n\t\tvar neg = false\r\n\t\tif (c == NC) c = char\r\n\t\twhile (c < '0' || c > '9') {\r\n\t\t\tif (c == '-') neg = true\r\n\t\t\tc = char\r\n\t\t}\r\n\t\tvar res = 0L\r\n\t\twhile (c >= '0' && c <= '9') {\r\n\t\t\tres = (res shl 3) + (res shl 1) + (c - '0')\r\n\t\t\tc = char\r\n\t\t}\r\n\t\treturn if (neg) -res else res\r\n\t}\r\n\tfun nextString():String{\r\n\t\tif (c == NC) c = char\r\n\t\tval ret = StringBuilder()\r\n\t\twhile (true){\r\n\t\t\tc = char\r\n\t\t\tif(!isWhitespace(c)){ break}\r\n\t\t}\r\n\t\tret.appendCodePoint(c.toInt())\r\n\t\twhile (true){\r\n\t\t\tc = char\r\n\t\t\tif(isWhitespace(c)){ break}\r\n\t\t\tret.appendCodePoint(c.toInt());\r\n\r\n\t\t}\r\n\t\treturn ret.toString()\r\n\t}\r\n\tfun isWhitespace(c:Char):Boolean{\r\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t'\r\n\t}\r\n}\r\nclass reading{\r\n\tcompanion object{\r\n\t\tvar jin = FastScanner()\r\n\t\tvar pw = PrintWriter(System.out)\r\n\t}\r\n}\r\nfun put(aa:Any){ reading.pw.println(aa)}\r\nfun done(){ reading.pw.close() }\r\n\r\nfun getint():Int{ return reading.jin.nextInt() }\r\nfun getlong():Long{ return reading.jin.nextLong() }\r\nfun getline(n:Int):List{ return (1..n).map{reading.jin.nextInt()} }\r\nfun getlineL(n:Int):List{return (1..n).map{reading.jin.nextLong()} }\r\nfun getstr():String{ return reading.jin.nextString() }\r\nfun MutableList.streamint(n:Int){ repeat(n){this.add(getint())}}\r\nfun MutableList.streamlong(n:Int){ repeat(n){this.add(getlong())}}\r\ninline fun cases(ask:()->Unit){ val t = getint();repeat(t){ ask() }}\r\n\r\nval List.ret:String\r\n\tget() = this.joinToString(\"\")\r\ninfix fun Any.dei(a:Any){\r\n\t//does not stand for anything it is just easy to type\r\n\tvar str = \"\"\r\n\tif(this is String){ str = this\r\n\t}else if(this is Int){ str = this.toString()\r\n\t}else if(this is Long){ str = this.toString()\r\n\t}\r\n\tif(a is List<*>){ println(\"$str : ${a.joinToString(\" \")}\")\r\n\t}else if(a is IntArray){ println(\"$str : ${a.joinToString(\" \")}\")\r\n\t}else if(a is LongArray){ println(\"$str : ${a.joinToString(\" \")}\")\r\n\t}else{ println(\"$str : $a\")\r\n\t}\r\n}\r\nval just = \" \" // usage: just dei x , where x is the debug variable\r\n\r\nfun force(a:Int){\r\n\tval DP = IntArray(a+1)\r\n\tDP[1] = 1\r\n\tfor(i in 2 until a){\r\n\t\tvar ret = 0\r\n\t\tfor(j in 1 until i){\r\n\t\t\tret += DP[j]\r\n\t\t}\r\n\t\tfor(j in 2..i){\r\n\t\t\tval new = i/j\r\n\t\t\tret += DP[new]\r\n\t\t}\r\n\t\tDP[i] = ret\r\n\t}\r\n\tprintln(DP.slice(25..35).joinToString(\" \"))\r\n\r\n\tfor(i in 1..100){\r\n\t\tprintln(\"$i ${DP[i] - 2 * DP[i-1]}\")\r\n\t}\r\n}\r\n\r\n\r\nfun main() {\r\n//\tforce(100)\r\n\tcalculateSieveFast()\r\n\tval a = getint()\r\n\tval m = getint()\r\n//\tval a = 100\r\n//\tval m = 1000000\r\n\r\n\tval DP = IntArray(a+1)\r\n\tval sums = IntArray(a+1)\r\n\r\n\tfun Int.adjust():Int{\r\n\t\tif(this >= m){\r\n\t\t\treturn this - m\r\n\t\t}else if (this < 0){\r\n\t\t\treturn this + m\r\n\t\t}\r\n\t\treturn this\r\n\t}\r\n\r\n\tfun paired(a:Int):Int{\r\n\t\treturn ((sums[a] + DP[a]).adjust() - DP[a-1]).adjust()\r\n\t}\r\n\r\n\tDP[0] = 1\r\n\tDP[1] = 1\r\n\tfor(i in 2..a){\r\n\t\tvar ret = 0\r\n\t\tret += DP[i-1]\r\n\t\tret = ret.adjust()\r\n\t\tret += DP[i-1]\r\n\t\tif(i >= 3){\r\n\t\t\tret += 1\r\n\t\t}\r\n\t\tret = ret.adjust()\r\n\r\n\r\n\r\n\t\tval ps = i.primes()\r\n\t\tval ans:Int\r\n\t\tif(ps.size == 1){\r\n\t\t\tval p = ps[0]\r\n\t\t\tans = paired(i/p)\r\n\t\t\tsums[i] = ans\r\n\t\t}else if(ps.size == 2){\r\n\t\t\tval p = ps[0]\r\n\t\t\tval q = ps[1]\r\n\t\t\tans = ((paired(i/p) + paired(i/q)).adjust() - paired((i/p)/q)).adjust()\r\n\t\t\tsums[i] = ans\r\n\t\t}else{\r\n\t\t\tval k = ps.size\r\n\t\t\tvar ans2 = 0\r\n\t\t\tfor(i4 in 1 until (1 shl k)){\r\n\t\t\t\tvar here = i\r\n\t\t\t\tval parity = i4.countOneBits() % 2 == 1\r\n\t\t\t\tfor(j in 0 until k){\r\n\t\t\t\t\tif((1 shl j) and i4 >0){\r\n\t\t\t\t\t\there /= ps[j]\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tif(parity){\r\n\t\t\t\t\tans2 += paired(here)\r\n\t\t\t\t}else{\r\n\t\t\t\t\tans2 -= paired(here)\r\n\t\t\t\t}\r\n\t\t\t\tans2 = ans2.adjust()\r\n\r\n\t\t\t}\r\n\t\t\tans = ans2\r\n\t\t\tsums[i] = ans\r\n\t\t}\r\n\t\tret += ans\r\n\t\tret = ret.adjust()\r\n\r\n//\t\tfor(c in i.factors()){\r\n//\t\t\tif(c == 1 || c== i) {\r\n//\t\t\t\tcontinue\r\n//\t\t\t}\r\n//\t\t\tret += (DP[c] - DP[c-1])\r\n//\t\t\tret = ret.adjust()\r\n//\t\t}\r\n\t\tDP[i] = ret\r\n\t}\r\n//\tjust dei DP.slice(25..35)\r\n//\t2 dei sums\r\n\tput(DP[a])\r\n\tdone()\r\n // Write your solution here\r\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "dp", "two pointers", "number theory"], "code_uid": "1c8e53a3d6f5eb10079645dfbabddafd", "src_uid": "77443424be253352aaf2b6c89bdd4671", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "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\nconst val INTERACTIVE = false\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\n case@ for(case in 1..numCases) {\n //print(\"Case #$case: \")\n\n val n = readInt()\n MOD = readInt()\n\n val dp = ModIntArray(n+1)\n dp[1] = 1.toModInt()\n dp[2] = 2.toModInt()\n\n for (i in 2 until n) {\n var d = dp[i]\n dp[i+1] += d+d+1\n d -= dp[i-1]\n var j = i*2\n while (j <= n) {\n dp[j] += d\n j += i\n }\n }\n\n val ans = dp[n]\n println(ans.int)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nconst val BILLION7 = 1e9.toInt() + 7\nvar MOD = 998244353\ninline val TOTIENT get() = MOD - 1 // assumes MOD is prime\ninline val half get() = ModInt(MOD.shr(1) + 1)\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 if(mod == 1) return 0\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 if(mod == 1) return res\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_unmemoized() /** 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\n fun swap(i: Int, j: Int) { val t = intArray[i]; intArray[i] = intArray[j]; intArray[j] = t }\n}\nfun ModIntArray.fill(element: ModInt, fromIndex: Int = 0, toIndex: Int = size) { intArray.fill(element.int, fromIndex, toIndex) }\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 ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\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(!INTERACTIVE) {\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 } else {\n val c = INPUT.read().let { it xor it.shr(8) }.toChar()\n return 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}\ninline fun readChars(n: Int, skipNext: Boolean = true) = readCharArray(n, skipNext)\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) = Array(n) { read() }\nfun readLines(n: Int) = Array(n) { readLn() }\nfun readInts(n: Int) = IntArray(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = LongArray(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 LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { 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\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", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "dp", "two pointers", "number theory"], "code_uid": "dfd711c5c64887a54e57f3b982465aee", "src_uid": "77443424be253352aaf2b6c89bdd4671", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.5", "source_code": "fun main() {\r\n\tval (n, m) = readInts()\r\n\tModular.M = m\r\n\tval primeDivisors = primeDivisors(n)\r\n\tval a = Array(n + 1) { it.toModular() }\r\n\tfor (i in 3..n) {\r\n\t\ta[i] = 1 + 2 * a[i - 1]\r\n\t\tfor (r in divisorsOf(i, primeDivisors)) {\r\n\t\t\tif (r == 1 || r == i) continue\r\n\t\t\ta[i] += a[r] - a[r - 1]\r\n\t\t}\r\n\t}\r\n\tprintln(a.last())\r\n}\r\n\r\nfun divisorsOf(n: Int, primeDivisors: IntArray): IntArray {\r\n\tif (n == 1) return intArrayOf(1)\r\n\tval p = primeDivisors[n]\r\n\tvar m = n / p\r\n\tvar count = 1\r\n\twhile (m % p == 0) {\r\n\t\tm /= p\r\n\t\tcount++\r\n\t}\r\n\tval that = divisorsOf(m, primeDivisors)\r\n\tval result = IntArray(that.size * (count + 1))\r\n\tfor (i in that.indices) {\r\n\t\tvar d = that[i]\r\n\t\tfor (j in 0..count) {\r\n\t\t\tresult[i * (count + 1) + j] = d\r\n\t\t\td *= p\r\n\t\t}\r\n\t}\r\n\treturn result\r\n}\r\n\r\nfun primeDivisors(n: Int): IntArray {\r\n\tval primeDivisors = IntArray(n + 1) { it }\r\n\tfor (i in 2..n) {\r\n\t\tif (primeDivisors[i] < i) continue\r\n\t\tvar j = i * i\r\n\t\tif (j > n) break\r\n\t\tdo {\r\n\t\t\tprimeDivisors[j] = i\r\n\t\t\tj += i\r\n\t\t} while (j <= n)\r\n\t}\r\n\treturn primeDivisors\r\n}\r\n\r\nfun Int.toModular() = Modular(this)//toDouble()\r\nclass Modular {\r\n\tcompanion object {\r\n\t\tvar M: Int = 0\r\n\t}\r\n\tval x: Int\r\n\t@Suppress(\"ConvertSecondaryConstructorToPrimary\")\r\n\tconstructor(value: Int) { x = (value % M).let { if (it < 0) it + M else it } }\r\n\toperator fun plus(that: Modular) = Modular((x + that.x) % M)\r\n\toperator fun minus(that: Modular) = Modular((x + M - that.x) % M)\r\n\toperator fun times(that: Modular) = (x.toLong() * that.x % M).toInt().toModular()\r\n\tfun modInverse() = Modular(x.toBigInteger().modInverse(M.toBigInteger()).toInt())\r\n\toperator fun div(that: Modular) = times(that.modInverse())\r\n\toverride fun toString() = x.toString()\r\n}\r\noperator fun Int.plus(that: Modular) = Modular(this) + that\r\noperator fun Int.minus(that: Modular) = Modular(this) - that\r\noperator fun Int.times(that: Modular) = Modular(this) * that\r\noperator fun Int.div(that: Modular) = Modular(this) / that\r\n\r\nprivate fun readLn() = readLine()!!\r\nprivate fun readInt() = readLn().toInt()\r\nprivate fun readStrings() = readLn().split(\" \")\r\nprivate fun readInts() = readStrings().map { it.toInt() }\r\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "dp", "two pointers", "number theory"], "code_uid": "053532304c07c6e70d70b6f9aa46ee98", "src_uid": "77443424be253352aaf2b6c89bdd4671", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main() {\r\n\tval (n, m) = readInts()\r\n\tModular.M = m\r\n\tval primeDivisors = primeDivisors(n)\r\n\tval diff = Array(n + 1) { 1.toModular() }\r\n\tvar aLast = 2.toModular()\r\n\tfor (i in 3..n) {\r\n\t\tdiff[i] = 1 + aLast\r\n\t\tfor (r in divisorsOf(i, primeDivisors)) {\r\n\t\t\tif (r == 1 || r == i) continue\r\n\t\t\tdiff[i] += diff[r]\r\n\t\t}\r\n\t\taLast += diff[i]\r\n\t}\r\n\tprintln(aLast)\r\n}\r\n\r\nfun divisorsOf(n: Int, primeDivisors: IntArray): IntArray {\r\n\tif (n == 1) return intArrayOf(1)\r\n\tval p = primeDivisors[n]\r\n\tvar m = n / p\r\n\tvar count = 1\r\n\twhile (m % p == 0) {\r\n\t\tm /= p\r\n\t\tcount++\r\n\t}\r\n\tval that = divisorsOf(m, primeDivisors)\r\n\tval result = IntArray(that.size * (count + 1))\r\n\tfor (i in that.indices) {\r\n\t\tvar d = that[i]\r\n\t\tfor (j in 0..count) {\r\n\t\t\tresult[i * (count + 1) + j] = d\r\n\t\t\td *= p\r\n\t\t}\r\n\t}\r\n\treturn result\r\n}\r\n\r\nfun primeDivisors(n: Int): IntArray {\r\n\tval primeDivisors = IntArray(n + 1) { it }\r\n\tfor (i in 2..n) {\r\n\t\tif (primeDivisors[i] < i) continue\r\n\t\tvar j = i * i\r\n\t\tif (j > n) break\r\n\t\tdo {\r\n\t\t\tprimeDivisors[j] = i\r\n\t\t\tj += i\r\n\t\t} while (j <= n)\r\n\t}\r\n\treturn primeDivisors\r\n}\r\n\r\nfun Int.toModular() = Modular(this)//toDouble()\r\nclass Modular {\r\n\tcompanion object {\r\n\t\tvar M: Int = 0\r\n\t}\r\n\tval x: Int\r\n\t@Suppress(\"ConvertSecondaryConstructorToPrimary\")\r\n\tconstructor(value: Int) { x = (value % M).let { if (it < 0) it + M else it } }\r\n\toperator fun plus(that: Modular) = Modular((x + that.x) % M)\r\n\toperator fun minus(that: Modular) = Modular((x + M - that.x) % M)\r\n\toperator fun times(that: Modular) = (x.toLong() * that.x % M).toInt().toModular()\r\n\tfun modInverse() = Modular(x.toBigInteger().modInverse(M.toBigInteger()).toInt())\r\n\toperator fun div(that: Modular) = times(that.modInverse())\r\n\toverride fun toString() = x.toString()\r\n}\r\noperator fun Int.plus(that: Modular) = Modular(this) + that\r\noperator fun Int.minus(that: Modular) = Modular(this) - that\r\noperator fun Int.times(that: Modular) = Modular(this) * that\r\noperator fun Int.div(that: Modular) = Modular(this) / that\r\n\r\nprivate fun readLn() = readLine()!!\r\nprivate fun readInt() = readLn().toInt()\r\nprivate fun readStrings() = readLn().split(\" \")\r\nprivate fun readInts() = readStrings().map { it.toInt() }\r\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "dp", "two pointers", "number theory"], "code_uid": "db47ddbfb008c3af95cfde285da405a2", "src_uid": "77443424be253352aaf2b6c89bdd4671", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import kotlin.math.*;\r\nimport kotlin.system.measureTimeMillis;\r\nimport java.math.BigInteger;\r\nimport java.util.StringTokenizer;\r\nimport java.util.TreeSet;\r\nimport java.util.LinkedList;\r\n\r\n@JvmField val INPUT = System.`in`\r\n@JvmField val OUTPUT = System.out\r\n@JvmField val MOD = 998244353;\r\n@JvmField val INF = Int.MAX_VALUE;\r\n@JvmField val LINF = Long.MAX_VALUE;\r\n@JvmField val NINF = Int.MIN_VALUE;\r\n@JvmField val NLINF = Long.MIN_VALUE;\r\n\r\n@JvmField val _reader = INPUT.bufferedReader()\r\nfun readLine(): String? = _reader.readLine()\r\nfun readLn() = _reader.readLine()!!\r\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\r\nfun read(): String {\r\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\r\n return _tokenizer.nextToken()\r\n}\r\nfun readInt() = read().toInt()\r\nfun readInt2() = Pair(readInt(),readInt())\r\nfun readInt3() = Triple(readInt(),readInt(),readInt())\r\nfun readDouble() = read().toDouble()\r\nfun readLong() = read().toLong()\r\nfun readLong2() = Pair(readLong(),readLong())\r\nfun readLong3() = Triple(readLong(),readLong(),readLong())\r\nfun readString() = readLine()!!;\r\nfun readStrings(n: Int) = List(n) { read() }\r\nfun readLines(n: Int) = List(n) { readLn() }\r\nfun readInts(n: Int) = List(n) { read().toInt() }\r\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\r\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\r\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\r\nfun readLongs(n: Int) = List(n) { read().toLong() }\r\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\r\nfun printVars(vararg vs: Any?){for(v in vs) print(\"$v \");println(\"\");}\r\nfun moduloAdd(v1: Int,v2: Int) = ((v1+0L+v2)%MOD).toInt();\r\nfun moduloMultiply(v1: Int,v2: Int) = ((v1*1L*v2)%MOD).toInt();\r\nfun exp2s(v: Int): List{var targ = v;var es = mli();var e = 0;while(targ>0){if (targ%2==1) es.add(e);targ/= 2;e++;};return es;}\r\nfun exp2sact(v: Int): List{var targ = v;var es = mli();var e = 1;while(targ>0){if (targ%2==1) es.add(e);targ = targ shr 1;e*= 2;};return es;}\r\nfun exp2sea(v: Int): List>{var targ = v;var es = ml>();var e = 0;var ea = 1;while(targ>0){if (targ%2==1) es.add(e to ea);targ = targ shr 1;ea = ea shl 1;e++;};return es;}\r\nfun iLog2(v:Int):Int{var ret=0;var vv= v shr 1;while(vv>0){ret++;vv=vv shr 1};return ret}\r\nfun iLog2(v:Long):Int{var ret=0;var vv= v shr 1;while(vv>0){ret++;vv=vv shr 1};return ret}\r\nfun tri(n: Int) = (n*(n+1))/2;\r\nfun tri(n: Long) = (n*(n+1))/2;\r\nfun isEven(v: Int) = v%2==0;\r\nfun isOdd(v: Int) = v%2==1;\r\nfun isEven(v: Long) = v%2L==0L;\r\nfun isOdd(v: Long) = v%2L==1L;\r\ninfix fun Int.between(range: Pair): Boolean = ((this >= range.first) && (this <= range.second));\r\ninfix fun Long.between(range: Pair): Boolean = ((this >= range.first) && (this <= range.second));\r\nfun ml(vararg vs: T) = mutableListOf(*vs);\r\nfun mli() = mutableListOf();\r\nfun mlid(n: Int,def: (it: Int) -> Int) = MutableList(n,def);\r\nfun mll() = mutableListOf();\r\nfun mlld(n: Int,def: (it: Int) -> Long) = MutableList(n,def);\r\nfun tsi() = TreeSet();\r\nfun tsl() = TreeSet();\r\nfun hmii() = HashMap();\r\nfun hmil() = HashMap();\r\nfun hmli() = HashMap();\r\nfun hmll() = HashMap();\r\nclass MultiSet(initContent: List = listOf()){private val mp = HashMap();init {for(x in initContent) add(x);}operator fun get(value: T): Int{return if (mp[value]!=null) mp[value]!! else 0;}fun add(value: T,count: Int = 1): Int{if (count < 0) throw Exception(\"count must be non-negative\");if (mp[value]==null) mp[value] = 0;var ret = mp[value]!!+count;mp[value] = ret;return ret;}fun remove(value: T,count: Int = 1): Int{if (count < 0) throw Exception(\"count must be non-negative\");var ret = this[value];ret = max(0,ret-count);if (ret==0){mp.remove(value);}else{mp[value] = ret;};return ret;}fun delete(value: T): Int{var ret = this[value];mp.remove(value);return ret;}val size get() = mp.size;operator fun iterator(): MutableIterator> = mp.iterator();override fun toString() = \"$mp\";}\r\nfun List.floor(v: Int): Int{var pos=binarySearch(v);if (pos>= 0){return pos;}else{return -(pos+1)-1;};}\r\nfun List.ceiling(v: Int): Int{var pos=binarySearch(v);if (pos>=0){return pos;}else{var ret = -(pos+1);return if (ret < size) ret else -1;}}\r\nfun List.floor(v: Long): Int{var pos=binarySearch(v);if (pos>= 0){return pos;}else{return -(pos+1)-1;};}\r\nfun List.ceiling(v: Long): Int{var pos=binarySearch(v);if (pos>=0){return pos;}else{var ret = -(pos+1);return if (ret < size) ret else -1;}}\r\nfun gcd(a: Int,b: Int): Int{if (b==0) return a;return gcd(b,a%b);}\r\nfun gcd(a: Long,b: Long): Long{if (b==0L) return a;return gcd(b,a%b);}\r\nfun lcm(a: Int,b: Int) = a/gcd(a,b)*b;\r\nfun lcm(a: Long,b: Long) = a/gcd(a,b)*b;\r\ninfix fun Int.pw(e: Int): Int{var a = this;var b = e;var res = 1;while (b > 0){if (b and 1==1) res*= a;a*= a;b = b shr 1;};return res;}\r\ninfix fun Long.pw(e: Int): Long{var a = this;var b = e;var res = 1L;while (b > 0){if (b and 1==1) res*= a;a*= a;b = b shr 1;};return res;}\r\ninterface VerticalIterable{abstract fun verticalIterator(): Iterator;}\r\ninline fun VMutableList(size: Int, init: (index: Int) -> T): MutableList {val list = VMutableList(size);repeat(size) { index -> list.add(init(index)) };return list;}\r\nclass VMutableList: ArrayList,VerticalIterable{constructor(): super();constructor(initialCapacity: Int): super(initialCapacity);constructor(elements: Collection): super(elements);override fun verticalIterator(): Iterator = iterator();}\r\ndata class VPair(val first: T1,val second: T2){infix fun vto(v: T) = VTriple(first,second,v);}\r\ndata class VTriple(val first: T1,val second: T2,val third: T3);\r\ninfix fun Int.vto(v: T) = VPair(this,v);\r\ninfix fun Long.vto(v: T) = VPair(this,v);\r\ninfix fun Double.vto(v: T) = VPair(this,v);\r\ninfix fun String.vto(v: T) = VPair(this,v);\r\ninfix fun Boolean.vto(v: T) = VPair(this,v);\r\nfun outputAns(v: Any?,sub: Boolean = false){if (v is VerticalIterable<*>){var first = true;for(x in v.verticalIterator()){if (!first) println(\"\");first = false;outputAns(x,true);}}else if (v is Iterable<*>){var first = true;for(x in v){if (!first) print(\" \");first = false;outputAns(x,true);}}else if (v is VPair<*,*>){outputAns(v.first,true);println(\"\");outputAns(v.second,true);}else if (v is VTriple<*,*,*>){outputAns(v.first,true);println(\"\");outputAns(v.second,true);println(\"\");outputAns(v.third,true);}else if (v is Pair<*,*>){outputAns(v.first,true);print(\" \");outputAns(v.second,true);}else if (v is Triple<*,*,*>){outputAns(v.first,true);print(\" \");outputAns(v.second,true);print(\" \");outputAns(v.third,true);}else{print(\"$v\");};if (!sub) println(\"\");}\r\ninterface Readable{fun read();};\r\nfun readValue(t: T): T{return when(t){is Int -> readInt();is Long -> readLong();is Double -> readDouble();is Pair<*,*> -> Pair(readValue(t.first),readValue(t.second));is Triple<*,*,*> -> Triple(readValue(t.first),readValue(t.second),readValue(t.third));is Readable -> { val ret = t!!::class.java.newInstance(); ret.read(); ret };else -> readString();} as T;};\r\nfun readList(arr: MutableList,n: Int) = readMList(arr,n) as List;\r\nfun readMList(arr: MutableList,n: Int): MutableList{if (n>arr.size) throw Exception(\"$n is out of bounds for size ${arr.size}\");if (arr[0] is Readable){repeat(n) { (arr[it] as Readable).read() };}else{repeat(n) { arr[it] = readValue(arr[0]);};};return arr.subList(0,n);};\r\n\r\n@JvmField val DEBUG = false;\r\n\r\nclass LongMod(val MOD: Long,initial: Long = 0L)\r\n{\r\n private var _value = 0L;\r\n\r\n init {\r\n if (MOD < 1L) throw Exception(\"MOD must be positive\");\r\n set(initial);\r\n }\r\n\r\n constructor(MOD: Int,initial: Int): this(MOD.toLong(),initial.toLong());\r\n constructor(MOD: Long,initial: Int): this(MOD,initial.toLong());\r\n constructor(MOD: Int,initial: Long): this(MOD.toLong(),initial);\r\n\r\n fun toInt() = _value.toInt();\r\n fun toLong() = _value;\r\n fun toDouble() = _value.toDouble();\r\n fun spawn(v: Long = 0L) = LongMod(MOD,v);\r\n fun spawn(v: Int) = spawn(v.toLong());\r\n \r\n fun set(v: Long) \r\n {\r\n if (v>=0)\r\n {\r\n _value = v%MOD;\r\n }\r\n else\r\n {\r\n _value = (MOD-abs(v)%MOD)%MOD;\r\n }\r\n }\r\n fun set(v: Int) { set(v.toLong()) }\r\n fun set(v: LongMod) { set(v.toLong()) }\r\n fun pow(e: Long): LongMod\r\n {\r\n val a = +this;\r\n var b = e;\r\n val res = spawn(1);\r\n while (b > 0L)\r\n {\r\n if (b and 1L==1L) res*= a;\r\n a*= a;\r\n b = b shr 1;\r\n }\r\n return res;\r\n }\r\n fun pow(e: Int) = pow(e.toLong());\r\n fun powSet(e: Long)\r\n {\r\n this { pow(e) };\r\n }\r\n fun powSet(e: Int) = powSet(e.toLong());\r\n\r\n operator fun inc() = LongMod(MOD,_value+1);\r\n operator fun dec() = LongMod(MOD,_value-1);\r\n operator fun unaryPlus() = spawn(_value);\r\n operator fun plus(v: Long) = spawn(_value+v%MOD);\r\n operator fun plus(v: Int) = plus(v.toLong());\r\n operator fun plus(v: LongMod) = plus(v.toLong());\r\n operator fun plusAssign(v: Long) { set(_value+v%MOD) };\r\n operator fun plusAssign(v: Int) { plusAssign(v.toLong()) };\r\n operator fun plusAssign(v: LongMod) { plusAssign(v.toLong()) }; \r\n operator fun unaryMinus() = spawn(-_value);\r\n operator fun minus(v: Long) = spawn(_value-v%MOD);\r\n operator fun minus(v: Int) = minus(v.toLong());\r\n operator fun minus(v: LongMod) = minus(v.toLong());\r\n operator fun minusAssign(v: Long) { set(_value-v%MOD) };\r\n operator fun minusAssign(v: Int) { minusAssign(v.toLong()) };\r\n operator fun minusAssign(v: LongMod) { minusAssign(v.toLong()) }; \r\n operator fun times(v: Long) = spawn(_value*v%MOD);\r\n operator fun times(v: Int) = times(v.toLong());\r\n operator fun times(v: LongMod) = times(v.toLong());\r\n operator fun timesAssign(v: Long) { set(_value*v%MOD) };\r\n operator fun timesAssign(v: Int) { timesAssign(v.toLong()) };\r\n operator fun timesAssign(v: LongMod) { timesAssign(v.toLong()) };\r\n operator fun invoke(fn: () -> T) \r\n { \r\n var v = fn();\r\n when(v)\r\n {\r\n is Int -> set(v)\r\n is Long -> set(v)\r\n is LongMod -> set(v)\r\n else -> throw Exception(\"unsupported type, cannot set\")\r\n }\r\n };\r\n\r\n override fun toString() = _value.toString();\r\n}\r\n\r\noperator fun Int.plus(v: LongMod) = LongMod(v.MOD,this%v.MOD+v.toLong());\r\noperator fun Long.plus(v: LongMod) = LongMod(v.MOD,this%v.MOD+v.toLong());\r\noperator fun Int.minus(v: LongMod) = LongMod(v.MOD,this%v.MOD-v.toLong());\r\noperator fun Long.minus(v: LongMod) = LongMod(v.MOD,this%v.MOD-v.toLong());\r\noperator fun Int.times(v: LongMod) = LongMod(v.MOD,this%v.MOD*v.toLong());\r\noperator fun Long.times(v: LongMod) = LongMod(v.MOD,this%v.MOD*v.toLong());\r\n\r\nclass Prob\r\n{ \r\n var n = readInt();\r\n var k = readInt();\r\n var ans = 0;\r\n\r\n fun exec() \r\n {\r\n var md = LongMod((10 pw 9)+7,n);\r\n ans = md.pow(k).toInt();\r\n }\r\n}\r\n\r\nfun main() \r\n{\r\n repeat(readInt())\r\n {\r\n val p = Prob();\r\n p.exec();\r\n outputAns(p.ans);\r\n if (DEBUG) println(\"---------\");\r\n }\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics", "bitmasks"], "code_uid": "6cdd2172518a3567709809b775c053a1", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "const val MOD = 1000000007L\n\nfun main() {\n for (c in 1..readLine()!!.toInt()) {\n val (n, k) = readLine()!!.split(\" \").map { it.toLong() }\n var answer = 1L\n for (j in 1L..k) {\n answer *= n\n answer %= MOD\n }\n println(answer)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics", "bitmasks"], "code_uid": "30066f5df7a55279891168004130cd49", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.io.BufferedReader\r\n\r\nval bin = System.`in`.bufferedReader()\r\nfun BufferedReader.readInt() = this.readLine()!!.toInt()\r\nfun BufferedReader.readInts() = this.readLine()!!.split(' ').map { it.toInt() }\r\n\r\nval MA = ModuloArithmetic(1_000_000_007)\r\nfun Int.ma() = MA.ofInt(this)\r\nfun Long.ma() = MA.ofLong(this)\r\n\r\nfun main() {\r\n repeat(bin.readInt()) {\r\n val (n, k) = bin.readInts()\r\n println(n.ma().pow(k.toLong()))\r\n }\r\n}\r\n\r\nclass ModuloArithmetic(private val MOD: Int) {\r\n\r\n fun ofInt(x: Int) = IntMod(x, MOD)\r\n fun ofLong(x: Long) = IntMod((x % MOD).toInt(), MOD)\r\n\r\n fun precomputeFactorials(n: Int) = PrecomputedFactorials(n, MOD)\r\n\r\n fun factorial(n: Int): IntMod {\r\n var res = ofInt(1)\r\n for (i in 1..n) {\r\n res *= i\r\n }\r\n return res\r\n }\r\n\r\n /**\r\n * n choose k, picking k elements from a set of n element, without repetitions\r\n *\r\n * / n \\\r\n * | |\r\n * \\ k /\r\n */\r\n fun choose(n: Int, k: Int): IntMod {\r\n if (k > n || n <= 0) return ofInt(0)\r\n if (k == 0 || k == n) return ofInt(1)\r\n\r\n return factorial(n) / (factorial(k) * factorial(n-k))\r\n }\r\n\r\n /**\r\n * n multichoose k, i.e. picking k elements from a set of n element, *with* repetitions, order does not matter.\r\n */\r\n fun multichoose(n: Int, k: Int): IntMod = choose(n+k-1, k)\r\n\r\n /**\r\n * / n \\\r\n * | |\r\n * \\ k_1, ... k_m /\r\n *\r\n * Number of ways of putting n distinct objects into m distinct bins\r\n * with k_i objects in the i'th bin\r\n */\r\n fun multinomial(n: Int, ks: List): IntMod {\r\n var res = factorial(n)\r\n for (k in ks) {\r\n res /= factorial(k)\r\n }\r\n return res\r\n }\r\n\r\n /**\r\n * Number of distinct ways of shuffling values [vs] (distinct = some value on some position differs).\r\n */\r\n fun numWayToShuffle(vs: List): IntMod {\r\n val f = mutableMapOf()\r\n for (v in vs) {\r\n f.merge(v, 1, Int::plus)\r\n }\r\n return multinomial(vs.size, f.values.toList())\r\n }\r\n}\r\n\r\nclass IntMod(n: Int, private val MOD: Int) {\r\n val i = n % MOD\r\n\r\n fun ofInt(x: Int) = IntMod(x, MOD)\r\n fun ofLong(x: Long) = IntMod((x % MOD).toInt(), MOD)\r\n\r\n operator fun plus(other: IntMod): IntMod = IntMod(Math.floorMod(i + other.i, MOD), MOD)\r\n operator fun plus(other: Int): IntMod = this + ofInt(other)\r\n operator fun plus(other: Long): IntMod = this + ofLong(other)\r\n\r\n operator fun minus(other: IntMod): IntMod = IntMod(Math.floorMod(i - other.i, MOD), MOD)\r\n operator fun minus(other: Int): IntMod = this - ofInt(other)\r\n operator fun minus(other: Long): IntMod = this - ofLong(other)\r\n\r\n operator fun times(other: IntMod): IntMod = IntMod(Math.floorMod(i.toLong() * other.i, MOD.toLong()).toInt(), MOD)\r\n operator fun times(other: Int): IntMod = this * ofInt(other)\r\n operator fun times(other: Long): IntMod = this * ofLong(other)\r\n\r\n operator fun div(other: IntMod): IntMod = this * other.multiplicativeInverse()\r\n operator fun div(other: Int): IntMod = this / ofInt(other)\r\n operator fun div(other: Long): IntMod = this / ofLong(other)\r\n\r\n override fun toString(): String = i.toString()\r\n\r\n // i^n\r\n fun pow(n_in: Long): IntMod {\r\n var x = this\r\n var y = ofInt(1)\r\n var n = n_in\r\n // x^n\r\n while (n > 0) {\r\n if (n % 2L != 0L) y *= x\r\n n /= 2\r\n x *= x\r\n }\r\n return y\r\n }\r\n\r\n private fun multiplicativeInverse(): IntMod = pow(MOD-2L)\r\n}\r\n\r\nclass PrecomputedFactorials(val n: Int, val MOD: Int) {\r\n val fact = Array(n+1) { IntMod(1, MOD) }\r\n val invFact = Array(n+1) { IntMod(1, MOD) }\r\n\r\n init {\r\n var f = IntMod(1, MOD)\r\n for (i in 1..n) {\r\n f *= i\r\n fact[i] = f\r\n invFact[i] = IntMod(1, MOD) / f\r\n }\r\n }\r\n\r\n fun fact(i: Int) = fact[i]\r\n\r\n fun choose(n: Int, k: Int) = when {\r\n k > n -> IntMod(0, MOD)\r\n n < 0 -> IntMod(0, MOD)\r\n else -> fact[n] * invFact[n - k] * invFact[k]\r\n }\r\n\r\n fun multichoose(n: Int, k: Int) = choose(n+k-1, k)\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics", "bitmasks"], "code_uid": "45e0e24201e099c7977d87b06392640a", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main() {\r\n// val T = 1;\r\n val T=readLine()!!.toInt();\r\n repeat(T) {\r\n val (n,k) = readLine()!!.split(\" \").map { it.toInt() }\r\n val mod = 1e9+7\r\n var a = 1L\r\n repeat(k){\r\n a = ((a*n)%mod).toLong()\r\n }\r\n println(a)\r\n }\r\n}\r\n// matrix :- val mat = List(row) { readLine()!!}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics", "bitmasks"], "code_uid": "f60d3a963c29259cc0a1783ffb94897d", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "b8041360b74e4b8b3022f817497a90d7", "src_uid": "e55b0debbf33c266091e6634494356b8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "c31dd7a444a35fa6ae61f36925bfe676", "src_uid": "e55b0debbf33c266091e6634494356b8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args : Array) {\n val input = Scanner(System.`in`)\n// val k = readLine()!!.toInt()\n val s = readLine()!!\n\n println(\"${s.last().toInt() % 2}\")\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "81c4093b761f66cbe681dcfd135f85f0", "src_uid": "e52bc741bb72bb8e79cf392b2d15354f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLine()?:\"\"\n println(s.last().toInt() % 2)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "b78e2c8401d2dffeff43cfcbf723d402", "src_uid": "e52bc741bb72bb8e79cf392b2d15354f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args:Array) {\n// println(\"No\")\n val input = readLine()\n val binry = hexToBinary(input!!)\n\n if (binry!![binry.length-1] == '0') {\n println(0)\n } else {\n println(1)\n }\n}\n\nfun hexToBinary(hex: String): String? {\n val i = hex.toInt(16)\n return Integer.toBinaryString(i)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "93568e082fd3575886b99675c636ca17", "src_uid": "e52bc741bb72bb8e79cf392b2d15354f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n println(if (readLine()!!.last().toString().toInt() % 2 == 0) 0 else 1)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "bd9dfc9014dc686e645b6499db16bf9f", "src_uid": "e52bc741bb72bb8e79cf392b2d15354f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Math.*\nimport java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n val x = scanner.nextInt()\n\n val res = (1..min(x,n)).count { x % it == 0 && x / it <= n}\n println(res)\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "0ce321f0930eeff04f0a83338f41724c", "src_uid": "c4b139eadca94201596f1305b2f76496", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, x) = readInts()\n val count = (1..n).count { x % it == 0 && x / it <= n }\n println(count)\n}\n\nprivate fun readInts() = readLine()!!.split(\" \").map { it.toInt() }", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "7d92d7b4a553edac26020789de0e3caa", "src_uid": "c4b139eadca94201596f1305b2f76496", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, x) = readLine()!!.split(' ').map { it.toInt() }\n\n println((1..n).count{x % it == 0 && x/it <=n})\n}", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "2f14d82a60655cc0307bbdeb0fa8dfa5", "src_uid": "c4b139eadca94201596f1305b2f76496", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\nimport kotlin.math.sqrt\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (n, x) = readInts()\n val end = min(n.toDouble(), sqrt(x.toDouble())).toInt()\n var sol = 0\n for (i in 1..end)\n if (x % i == 0 && x / i <= n)\n sol += if (x / i == i) 1 else 2\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "3d1b971b8a02b99a7dac84766c312ccb", "src_uid": "c4b139eadca94201596f1305b2f76496", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var input = readLine()!!\n var temp =\"\"\n var checker =true\n for (i in 1..(input.length-1)){\n if (input[i].isUpperCase()){\n checker = true\n }else{\n checker =false\n break\n }\n }\n if (checker==true){\n for (j in 0 ..(input.length-1)){\n if (input[j].isUpperCase()){\n temp+=input[j].toLowerCase()\n }\n else{\n temp+=input[j].toUpperCase()\n }\n }\n }else{\n temp=input\n }\n println(temp)\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "76cef9c911d895a805e1c5f11d0cabb9", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val s: Scanner = Scanner(System.`in`)\n val str: String = s.next()\n if (isUpperCase(str) || isUpperCase(str.substring(1))) {\n print(invertCase(str))\n } else {\n print(str)\n }\n}\n\nfun isUpperCase(str: String): Boolean {\n var isUp: Boolean = true;\n str.forEach { c: Char ->\n if (!c.isUpperCase()) {\n isUp = false\n return@forEach\n }\n }\n return isUp\n}\n\nfun invertCase(c: Char): Char {\n if (c.isUpperCase()) {\n return c.toLowerCase();\n } else if (c.isLowerCase()) {\n return c.toUpperCase()\n } else {\n return c\n }\n}\n\nfun invertCase(str: String): String {\n val sb: StringBuilder = StringBuilder()\n str.forEach { c -> sb.append(invertCase(c)) }\n return sb.toString()\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "a1fbc0ec7f39a8bb30e3bab1588ac379", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val given = readLine()!!\n var begin = given.substring(0, 1)\n var rests = given.substring(1, given.length)\n if (rests.toUpperCase() == rests)\n {\n rests = rests.toLowerCase()\n if (begin.toUpperCase() == begin)\n {\n begin = begin.toLowerCase()\n }\n else\n {\n begin = begin.toUpperCase()\n }\n }\n println(begin + rests)\n\n\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "00be04e9485b8348b684b2297ee48eaa", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n fun invertCase(s: String) = String(s.map { if (it.isUpperCase()) it.toLowerCase() else it.toUpperCase() }.toCharArray())\n\n val word = readLine()!!\n println(if (word.substring(1).all { it.isUpperCase() }) invertCase(word) else word )\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "5857a0c2e1c54d8896f47a0bb04a732d", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.InputStream\nimport java.util.*\n\nprivate class FScanner internal constructor(inputStream: InputStream = System.`in`) {\n internal val br = BufferedReader(InputStreamReader(inputStream))\n internal var st = StringTokenizer(\"\")\n\n internal fun hasNext(): Boolean {\n while (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine() ?: return false)\n return true\n }\n\n internal operator fun next() =\n if (hasNext()) st.nextToken()!!\n else throw RuntimeException(\"No tokens\")\n\n internal fun nextInt() = next().toInt()\n\n internal fun nextLong() = next().toLong()\n\n internal fun nextLine() =\n if (hasNext()) st.nextToken(\"\\n\")\n else throw RuntimeException(\"No tokens\")\n\n internal fun nextIntArray(n: Int) = IntArray(n, { nextInt() })\n\n internal fun nextLongArray(n: Int) = LongArray(n, { nextLong() })\n}\n\n\nfun main(args: Array) {\n val sc = FScanner()\n val n = sc.nextInt()\n val s = sc.nextLine()\n val b = sc.nextIntArray(n)\n\n val rev = PriorityQueue>(compareBy { it.second })\n var sum = b.sum()\n\n val remChar = IntArray(26)\n (0 until n / 2).forEach {\n val inv = n - it - 1\n if (s[it] == s[inv]) {\n// println(\"${s[it]} - ${b[it]} - ${b[n - it - 1]}\")\n if (b[it] < b[inv]) {\n remChar[s[it].toByte() - 'a'.toByte()]++\n// rev += Triple(s[inv], b[inv], s[it])\n sum -= b[it]\n } else {\n remChar[s[inv].toByte() - 'a'.toByte()]++\n// rev += Triple(s[it], b[it], s[inv])\n sum -= b[inv]\n }\n } else {\n rev += Triple(s[it], b[it], s[inv])\n rev += Triple(s[inv], b[inv], s[it])\n }\n }\n\n val remStat = PriorityQueue>(compareBy> { -it.second })\n remChar\n .forEachIndexed { index, i ->\n if (i > 0) {\n remStat += Pair((index + 'a'.toByte()).toChar(), i)\n }\n }\n\n// println(remStat.joinToString(\" \"))\n// println(sum)\n\n if (remStat.isNotEmpty()) {\n var x = remStat.poll()\n var oldx = x.first\n var xleft = x.second\n while (remStat.isNotEmpty()) {\n val y = remStat.poll()\n if (y.second <= xleft) {\n xleft -= y.second\n } else {\n xleft = y.second - xleft\n x = y\n }\n }\n// println(\"Need remove ${x.first} $xleft\")\n// println(rev.joinToString(\" \"))\n\n //find different x\n while (xleft > 0 && x.first == oldx) {\n val re = rev.poll()\n if (re.first != x.first && re.third != x.first) {\n// println(\"Remove $re\")\n xleft--\n sum -= re.second\n }\n }\n }\n \n println(sum)\n}\n\n", "lang_cluster": "Kotlin", "tags": ["greedy", "flows", "graphs"], "code_uid": "0eecf13489f0d6e469c84968a26f4525", "src_uid": "896555ddb6e1c268cd7b3b6b063fce50", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.InputStream\nimport java.util.*\n\nprivate class FScanner internal constructor(inputStream: InputStream = System.`in`) {\n internal val br = BufferedReader(InputStreamReader(inputStream))\n internal var st = StringTokenizer(\"\")\n\n internal fun hasNext(): Boolean {\n while (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine() ?: return false)\n return true\n }\n\n internal operator fun next() =\n if (hasNext()) st.nextToken()!!\n else throw RuntimeException(\"No tokens\")\n\n internal fun nextInt() = next().toInt()\n\n internal fun nextLong() = next().toLong()\n\n internal fun nextLine() =\n if (hasNext()) st.nextToken(\"\\n\")\n else throw RuntimeException(\"No tokens\")\n\n internal fun nextIntArray(n: Int) = IntArray(n, { nextInt() })\n\n internal fun nextLongArray(n: Int) = LongArray(n, { nextLong() })\n}\n\n\nfun main(args: Array) {\n val sc = FScanner()\n val n = sc.nextInt()\n val s = sc.nextLine()\n val b = sc.nextIntArray(n)\n\n val rev = PriorityQueue>(compareBy { it.second })\n var sum = b.sum()\n\n val remChar = IntArray(26)\n (0 until n / 2).forEach {\n val inv = n - it - 1\n if (s[it] == s[inv]) {\n// println(\"${s[it]} - ${b[it]} - ${b[n - it - 1]}\")\n if (b[it] < b[inv]) {\n remChar[s[it].toByte() - 'a'.toByte()]++\n rev += Triple(s[inv], b[inv], s[it])\n sum -= b[it]\n } else {\n remChar[s[inv].toByte() - 'a'.toByte()]++\n rev += Triple(s[it], b[it], s[inv])\n sum -= b[inv]\n }\n } else {\n rev += Triple(s[it], b[it], s[inv])\n rev += Triple(s[inv], b[inv], s[it])\n }\n }\n\n val remStat = PriorityQueue>(compareBy> { -it.second })\n remChar\n .forEachIndexed { index, i ->\n if (i > 0) {\n remStat += Pair((index + 'a'.toByte()).toChar(), i)\n }\n }\n\n// println(remStat.joinToString(\" \"))\n// println(sum)\n\n if (remStat.isNotEmpty()) {\n var x = remStat.poll()\n var oldx = x.first\n var xleft = x.second\n while (remStat.isNotEmpty()) {\n val y = remStat.poll()\n if (y.second <= xleft) {\n xleft -= y.second\n } else {\n xleft = y.second - xleft\n x = y\n }\n }\n// println(\"Need remove ${x.first} $xleft\")\n// println(rev.joinToString(\" \"))\n\n //find different x\n while (xleft > 0 && x.first == oldx) {\n val re = rev.poll()\n if (re.first != x.first && re.third != x.first) {\n// println(\"Remove $re\")\n xleft--\n sum -= re.second\n }\n }\n }\n\n println(sum)\n}\n\n", "lang_cluster": "Kotlin", "tags": ["greedy", "flows", "graphs"], "code_uid": "d3bc26bc7fb48c64d833a7d1d5c73862", "src_uid": "896555ddb6e1c268cd7b3b6b063fce50", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n\n val target = \"hello\"\n var offset = 0\n\n val line = scanner.nextLine()\n\n for (i in line) {\n if (i == target[offset]) {\n offset++\n if (offset == target.length) {\n println(\"YES\")\n return\n }\n }\n }\n\n println(\"NO\")\n\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "strings"], "code_uid": "e431e794cfc0e3c7c1121e784588c95b", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 p = \"hello\"\n var o = 0\n for (ch in t) {\n if (o >= p.length) break\n if (ch == p[o]) {\n ++o\n }\n }\n val res = (o >= p.length)\n io.println(if (res) \"YES\" else \"NO\")\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy", "strings"], "code_uid": "0607cdb52a7b835083ce9453e70a5875", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n var scan = Scanner(System.`in`)\n\n var hello = \"hello\".toCharArray()\n var index = 0\n var s = scan.nextLine()\n for(i in 0 until s.length) {\n if(hello[index] == s[i]) {\n index++\n if(index == hello.size) {\n break;\n }\n }\n }\n\n if(index == hello.size) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "strings"], "code_uid": "671c9317bc8f7ce04db41aaa6db4b074", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val input = readLine()!!\n var ans: String = \"\"\n var len: Int = 0\n var l: Int = 0\n for (i in input) {\n if (len == 0) {\n if (i == 'h') {\n ans += i\n len++\n }\n } else {\n if (ans[len - 1] == 'h' && i == 'e') {\n ans += i\n len++\n } else if (ans[len - 1] == 'e' && i == 'l') {\n ans += i\n l++\n len++\n } else if (ans[len-1] == 'l' && (l < 2 && i == 'l')) {\n ans += i\n l++\n len++\n } else if (ans[len - 1] == 'l' && (i == 'o' && l == 2)) {\n ans += i\n len++\n break\n }\n }\n }\n ans = if (ans.equals(\"hello\")) \"YES\" else \"NO\"\n print(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy", "strings"], "code_uid": "e5a645ab53559cc84325ae3a89c15cc4", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private fun readLn() = readLine()!!\nprivate fun readString() = readLn().trim()\nprivate fun readInt() = readLn().toInt()\nprivate fun readLong() = readLn().toLong()\nprivate val regSpace = \"\\\\s+\".toRegex()\nprivate fun readSomeInts(): List {\n return readLn().trim().split(regSpace).map { it.toInt() }\n}\nprivate fun readSomeLongs(): List {\n return readLn().trim().split(regSpace).map { it.toLong() }\n}\n\nfun main() {\n\n val s = readString()\n val t = readString()\n\n val result = calcMaxLen(s, t)\n println(\"$result\")\n}\n\n\nfun calcMaxLen(s: String, t: String): Int {\n val sLen = s.length\n val tLen = t.length\n if (sLen == tLen)\n return 0\n\n val relIdxs: MutableList> = mutableListOf()\n for (j: Int in 0 until tLen) {\n val c = t[j]\n val idxs = s.withIndex().filter { it.value == c }.map { it.index }\n relIdxs.add(idxs.toMutableList())\n }\n\n var prevBgnIdx = -1\n for (j: Int in 0 until tLen) {\n relIdxs[j].removeAll { it <= prevBgnIdx }\n prevBgnIdx = relIdxs[j][0]\n }\n\n var prevEndIdx = sLen\n for (j: Int in tLen - 1 downTo 0) {\n relIdxs[j].removeAll { it >= prevEndIdx }\n prevEndIdx = relIdxs[j].last()\n }\n\n val m0 = relIdxs[0].last()\n val mz = sLen - relIdxs.last().first() - 1\n val m0z = if (mz > m0) mz else m0\n\n\n val mp = relIdxs.fold(Pair(m0z, relIdxs[0])) {\n (z, prev), xs ->\n val mx = xs.last() - prev.first() - 1\n Pair(if (mx > z) mx else z, xs)\n }\n\n return mp.first\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "d02f77b762da89ecac06affd33158d10", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main() {\n val s = readLine()!!\n val t = readLine()!!\n val earliest = IntArray(t.length + 1)\n val latest = IntArray(t.length + 1)\n var k = 0\n for (j in 1..s.length) {\n if (s[j - 1] == t[k]) {\n k++\n earliest[k] = j\n if (k == t.length) {\n break\n }\n }\n }\n k = t.length\n latest[t.length] = s.length\n for (j in s.length - 1 downTo 0) {\n if (s[j] == t[k - 1]) {\n k--\n latest[k] = j\n if (k == 0) {\n break\n }\n }\n }\n var answer = 0\n for (j in 0..t.length) {\n answer = max(answer, latest[j] - earliest[j])\n }\n println(answer)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "ba0d79ecd75b4faf7744de5e0ca9d3a4", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport java.io.*\nimport kotlin.math.*\n \n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\nfun main() {\n\tval inputStream = System.`in`\n\tval outputStream = System.out\n\tval `in` = Main.InputReader(inputStream)\n\tval out = PrintWriter(outputStream)\n\tval solver = Main.TaskD()\n\tsolver.solve(1, `in`, out)\n\tout.close()\n}\n \nobject Main {\n\t@JvmStatic\n\tfun main(args: Array) {\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\tsolver.solve(1, `in`, out)\n\t\tout.close()\n\t}\n \n\tinternal class TaskD {\n\t\tfun solve(testNumber: Int, `in`: InputReader, out: PrintWriter) {\n\t\t\tvar s = `in`.next()\n\t\t\tvar t = `in`.next()\n\t\t\tvar n = s.length\n\t\t\tvar m = t.length\n\t\t\t\n\t\t\tvar L = Array(m+2, {_ -> -1})\n\t\t\tvar j = 0\n\t\t\tfor (i in 0..n-1)\n\t\t\t{\n\t\t\t\tif (j < m && s[i] == t[j])\n\t\t\t\t{\n\t\t\t\t\tL[j+1] = i\n\t\t\t\t\tj ++\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tvar R = Array(m+2, {_ -> n})\n\t\t\tj = m-1\n\t\t\tfor (i in n-1 downTo 0)\n\t\t\t{\n\t\t\t\tif (j >= 0 && s[i] == t[j])\n\t\t\t\t{\n\t\t\t\t\tR[j+1] = i\n\t\t\t\t\tj --\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tvar ans = 0\n\t\t\tfor (j in 0..m)\n\t\t\t{\n\t\t\t\tans = maxOf(ans, R[j+1]-L[j]-1)\n\t\t\t}\n\t\t\tout.println(ans)\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\t\t\n\t\tfun nextLong(): Long {\n\t\t return next().toLong()\n\t\t}\n \n\t}\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "e6d0ea53c00e228733b29aecef77b086", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLn()\n val t = readLn()\n\n var ans = 0\n\n for(l in s.indices) {\n for(r in l+ans..s.lastIndex) {\n val n = s.substring(0, l) + s.substring(r+1, s.length)\n\n val ni = n.iterator()\n val ti = t.iterator()\n var tc = ti.nextChar()\n\n while(ni.hasNext()) {\n if(ni.nextChar() == tc) {\n if(ti.hasNext().not()) {\n ans = r-l+1\n break\n }\n tc = ti.nextChar()\n }\n }\n }\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 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 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() }", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "be6e38509377d5aab4f4acc5d32dc07f", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n if (n%2 == 0 ) println(0) else println(1)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "20810f8fa40c2a0afa7ab61bda9b35c0", "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun main(args: Array){\n val leer = Scanner(System.`in`)\n val a:Int = leer.nextInt()\n println(((a shr 1) shl 1) xor a)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "80b6a7dab19e5d4fdb14059d9acbd36f", "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args: Array) {\n val x = readLine()!!.toInt()\n\n if (x % 2 == 0) {\n print(0)\n } else {\n print(1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "989e284260382cfd6de6dbd1d604b1ff", "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val a = readLine()!!.toInt()\n println(if (a % 2 == 0) 0 else 1)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "b8ffcea8595f3f3180c303d4ef31dd8c", "src_uid": "78e64fdbf59c5ce89d0f0a1d0591f795", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\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 main() {\n val (k2, k3, k5, k6) = readInts()\n print(256 * min(k2, min(k5, k6)) + 32 * min(k2 - min(k2, min(k5, k6)), k3))\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "85a25e5f63839bf5a4d44e958dabc19f", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val k2 = sc.nextInt()\n val k3 = sc.nextInt()\n val k5 = sc.nextInt()\n val k6 = sc.nextInt()\n\n val of256 = intArrayOf(k2, k5, k6).min()\n val of32 = intArrayOf(k2 - of256!!, k3).min()\n println(256 * of256 + 32 * of32!!)\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "5665271d2ac0014c1b81e49421492ef0", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\n/* http://codeforces.com/problemset/problem/734/B */\n\nfun main() {\n val (k2, k3, k5, k6) = readLine()!!.split(\" \").map { it.toInt() }\n val numOf256s = min(k2, min(k5, k6))\n val remaining2s = k2 - numOf256s\n val numOf32s = min(remaining2s, k3)\n println(numOf256s * 256 + numOf32s * 32)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "bbea901ecdc92253373f1487c277346d", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 (k2, k3, k5, k6) = input.readLine().toInts()\n\n val k256 = k2.coerceAtMost(k5).coerceAtMost(k6)\n val k32 = Math.min(k3, k2 - k256)\n\n output.println(k256 * 256 + k32 * 32)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "dd1e4fcc376f36905c7544290a3fa741", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "0dfb5dd8e75617d85f610d7df139a999", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "1838008a2da2ab26f0fae019adb6104a", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "05f4606b03b1e35f5a57c6a6ff02e52f", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "4f6d95b63f8314c1025f55b6a695831f", "src_uid": "8edf64f5838b19f9a8b19a14977f5615", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "d09d31328e6311a472e165be156890e2", "src_uid": "8edf64f5838b19f9a8b19a14977f5615", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "8b08057d1c066a41ed6b186a6349fe7e", "src_uid": "8edf64f5838b19f9a8b19a14977f5615", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "e0cc2fab497c64eb852722bf56201b7e", "src_uid": "8edf64f5838b19f9a8b19a14977f5615", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nobject B {\n object sc {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n var tokenizer = StringTokenizer(\"\")\n\n fun next(): String {\n while (!tokenizer.hasMoreTokens()) {\n val nextLine = reader.readLine() ?: throw IllegalStateException()\n tokenizer = StringTokenizer(nextLine)\n }\n return tokenizer.nextToken()\n }\n\n fun nextInt(): Int {\n return next().toInt()\n }\n }\n\n val a = Array(4, { CharArray(4) })\n\n fun w(i: Int, j: Int): Boolean {\n return a[i][j] == 'x'\n }\n\n fun isWinning(): Boolean {\n var ans = false\n // rows\n for (i in 0..3) {\n for (j in 0..1) {\n ans = ans || w(i, j) && w(i, j + 1) && w(i, j + 2)\n }\n }\n // cols\n for (i in 0..1) {\n for (j in 0..3) {\n ans = ans || w(i, j) && w(i + 1, j) && w(i + 2, j)\n }\n }\n // diag\n ans = ans || w(0, 0) && w(1, 1) && w(2, 2)\n ans = ans || w(1, 1) && w(2, 2) && w(3, 3)\n ans = ans || w(0, 1) && w(1, 2) && w(2, 3)\n ans = ans || w(1, 0) && w(2, 1) && w(3, 2)\n // rev diag\n ans = ans || w(0, 2) && w(1, 1) && w(2, 0)\n ans = ans || w(0, 3) && w(1, 2) && w(2, 1)\n ans = ans || w(1, 2) && w(2, 1) && w(3, 0)\n ans = ans || w(1, 3) && w(2, 2) && w(3, 1)\n return ans\n }\n\n fun canWin(): Boolean {\n for (i in 0..3) {\n for (j in 0..3) {\n if (a[i][j] == '.') {\n val saved = a[i][j]\n a[i][j] = 'x'\n if (isWinning()) {\n return true\n }\n a[i][j] = saved\n }\n }\n }\n return false\n }\n\n fun solve() {\n for (i in 0..3) {\n a[i] = sc.next().toCharArray()\n }\n println(if (canWin()) \"YES\" else \"NO\")\n }\n}\n\nfun main(args: Array) {\n B.solve()\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "eab38f065076e9d037f9ef7ae539e456", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n\n val a1 = scanner.nextLine().toCharArray()\n val a2 = scanner.nextLine().toCharArray()\n val a3 = scanner.nextLine().toCharArray()\n val a4 = scanner.nextLine().toCharArray()\n val array = arrayOf(a1, a2, a3, a4)\n\n var ans = \"NO\"\n\n for (i in 0 until 4) {\n for (j in 0 until 4) {\n if (array[i][j] == '.') {\n array[i][j] = 'x'\n\n if (checkResult(array)) {\n ans = \"YES\"\n }\n\n array[i][j] = '.'\n }\n\n }\n\n }\n\n System.out.println(ans)\n\n}\n\n\nfun checkResult(array: Array): Boolean {\n var ans = false\n\n for (i in 0 until 4) {\n for (j in 0 until 4) {\n if (j + 1 < 4 && j + 2 < 4) {\n if (array[i][j] == 'x' && array[i][j + 1] == 'x' && array[i][j + 2] == 'x') {\n ans = true\n }\n }\n\n if (i + 1 < 4 && i + 2 < 4) {\n if (array[i][j] == 'x' && array[i + 1][j] == 'x' && array[i + 2][j] == 'x') {\n ans = true\n }\n }\n\n if (i + 2 < 4 && j + 2 < 4) {\n if (array[i][j] == 'x' && array[i + 1][j + 1] == 'x' && array[i + 2][j + 2] == 'x') {\n ans = true\n }\n }\n\n if (0<=i-1 && j+1<4 && 0<=i-2 && j+2<4){\n if (array[i][j] == 'x' && array[i - 1][j + 1] == 'x' && array[i - 2][j + 2] == 'x') {\n ans = true\n }\n\n }\n\n\n\n }\n }\n\n return ans\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "a353e806de0cb6334f1820c11223d93d", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*;\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readDouble() = readLn().toDouble() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of ints\n\nfun main(args: Array) {\n solve()\n /*\n val t = readInt()\n repeat(t) {\n solve()\n }\n */\n}\n\nfun solve() {\n val g = arrayOf(readLn(), readLn(), readLn(), readLn())\n val dx = arrayOf(-1, -1, -1, 0, 0, 1, 1, 1)\n val dy = arrayOf(-1, 0, 1, -1, 1, -1, 0, 1)\n for(i in 0 until 4) {\n for(j in 0 until 4) {\n for(k in 0 until dx.size) {\n var good = 0\n var valid = true\n for(l in 0 until 3) {\n var nx = i + dx[k] * l\n var ny = j + dy[k] * l\n if(nx < 0 || nx >= 4 || ny < 0 || ny >= 4 || g[nx][ny] == 'o') valid = false\n if(valid && g[nx][ny] == 'x') good++\n }\n if(good == 2 && valid) {\n println(\"YES\")\n System.exit(0);\n }\n }\n }\n }\n println(\"NO\")\n}\n\n/*\nuseful things:\nJava: int[] dx = new int[]{-1,1,0,0}\nKotlin: val dx = arrayOf(-1, 1, 0, 0)\n*/", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "f2067be5eb06b14bb757d43eb6731668", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val grid = Array(4) { \"\" }\n for (row in 0..3) grid[row] = readLine()!!\n for (row in 0..3)\n for (column in 0..1) {\n var xs = 0\n var dots = 0\n for (c in column..column + 2)\n when (grid[row][c]) {\n 'x' -> xs++\n '.' -> dots++\n }\n if (xs >= 2 && xs + dots == 3) return print(\"YES\")\n }\n\n for (column in 0..3)\n for (row in 0..1) {\n var xs = 0\n var dots = 0\n for (r in row..row + 2)\n when (grid[r][column]) {\n 'x' -> xs++\n '.' -> dots++\n }\n if (xs >= 2 && xs + dots == 3) return print(\"YES\")\n }\n\n for (row in 0..1)\n for (column in 0..1) {\n var xs = 0\n var dots = 0\n for (delta in 0..2)\n when (grid[row + delta][column + delta]) {\n 'x' -> xs++\n '.' -> dots++\n }\n if (xs >= 2 && xs + dots == 3) return print(\"YES\")\n }\n\n for (row in 0..1)\n for (column in 2..3) {\n var xs = 0\n var dots = 0\n for (delta in 0..2)\n when (grid[row + delta][column - delta]) {\n 'x' -> xs++\n '.' -> dots++\n }\n if (xs >= 2 && xs + dots == 3) return print(\"YES\")\n }\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "1cba7e9958ca8961df72a443362131ad", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.ceil\nimport kotlin.math.floor\nimport kotlin.math.min\n\nfun main(arg:Array){\n val (n,w,b)= readLine()!!.split(\" \").map { it.toInt() }.toIntArray()\n val a= readLine()!!.split(\" \").map{it.toInt()}\n fun colCost(col:Int) = if(col==0) w else b\n\n fun compare(x:Int,y:Int)=when(x+y){\n 4-> min(w,b)*2\n 1-> -1\n else->\n when(listOf(x,y).find { it==2 }){\n null -> 0\n else -> listOf(x,y).filterNot{it==2 }.first().let ( ::colCost )\n }\n }\n val res = a.take(n/2).zip(a.takeLast(n/2).reversed()).map {\n compare(it.first,it.second) } + listOfNotNull(when(n%2){0->null else->compare(a[n/2],a[n/2])/2})\n if(res.find { x->x==-1} != null)\n println(-1)\n else\n println(res.reduce{x,y->x+y})\n\n\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "85c31343d8602b2d1391cc7ea89ec21d", "src_uid": "af07223819aeb5bd6ded4340c472b2b6", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main(args: Array) {\n var inp = readLine()!!.split(\" \")\n val n = inp[0].toInt()\n val w = inp[1].toInt()\n val b = inp[2].toInt()\n var t = 0\n inp = readLine()!!.split(\" \")\n val d = Array(n){i -> inp[i].toInt()}\n for (i in 0 until n/2)\n {\n val bas = d[i]\n val son = d[n-i-1]\n //println(\"bas = $bas son = $son\")\n if(bas + son ==1)\n {\n println(\"-1\")\n return\n }\n if(bas != 2 && bas == son)\n continue\n if(bas + son == 2)\n t+=w\n else if (bas + son == 3)\n t+=b\n else\n t+=min(b,w)*2\n }\n if (n % 2 == 1 && d[n/2] == 2)\n t+= min(b,w)\n println(t)\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "c790276f8253ae2e84763096d87fcc85", "src_uid": "af07223819aeb5bd6ded4340c472b2b6", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.system.exitProcess\n\nfun main(args: Array) {\n // 0 1\n val (n, a, b) = readLine()!!.split(\" \").map { it.toInt() }\n val array = readLine()!!.split(\" \").map { it.toInt().takeIf { it != 2 } }\n var i = 0; var j = array.size - 1\n var ans = 0\n while (i <= j) {\n if (array[i] != null && array[j] != null) {\n if (array[i] != array[j]) {\n println(-1)\n exitProcess(0)\n }\n }\n if (array[i] == null && array[j] != null) {\n ans += if (array[j] == 0) a else b\n }\n if (array[i] != null && array[j] == null) {\n ans += if (array[i] == 0) a else b\n }\n if (array[i] == null && array[j] == null) {\n ans += (if (i == j) 1 else 2) * minOf(a, b)\n }\n i++\n j--\n }\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "5cf8f534daf81ac752738a0be8eb530b", "src_uid": "af07223819aeb5bd6ded4340c472b2b6", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n val a = scanner.nextInt()\n val b = scanner.nextInt()\n val list = mutableListOf()\n while (scanner.hasNextInt()) {\n list.add(scanner.nextInt())\n }\n var first = 0\n var last = 0\n var sum = 0\n\n for (i in 0 until list.size / 2) {\n first = list[i]\n last = list[list.size - i - 1]\n sum += updateSum(first, last, a, b)\n }\n if (list.size % 2 == 1 && list[list.size / 2] == 2) {\n sum += minOf(a, b)\n }\n print(sum)\n\n}\n\nprivate fun updateSum(first: Int, last: Int, a: Int, b: Int): Int {\n var sum = 0\n if (first != 2 && last != 2 && first != last) {\n print(-1)\n System.exit(0)\n } else if (first == last && last == 2) {\n sum += minOf(a, b) * 2\n } else if (first == 2) {\n\n sum += if (last == 0) a else b\n } else if (last == 2) {\n sum += if (first == 0) a else b\n }\n return sum\n}\n\n", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "d3618c0915c35b35035398d392650a06", "src_uid": "af07223819aeb5bd6ded4340c472b2b6", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(a: Array)\n{\n var (a,b) = readLine()!!.split(' ').map { it.toInt() }\n var counter = 0\n while (a > 0 && b > 0 && a+b>2)\n {\n counter++\n when (a {if (a < 100) ++a ; b-=2}\n else -> {if (b < 100) ++b; a-=2}\n }\n }\n println(counter)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "dp", "implementation"], "code_uid": "57651eef51d60c1575e96a82dcecd61a", "src_uid": "ba0f9f5f0ad4786b9274c829be587961", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n var (a, b) = readLine()!!.split(\" \").map(String::toInt)\n var result = 0\n while (max(a, b) >= 2 && min(a, b) > 0) {\n result++\n if (a < b) {\n a += 1\n b -= 2\n } else {\n b += 1\n a -= 2\n }\n }\n println(result)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "dp", "implementation"], "code_uid": "45e35170d435570d80b25c564677a664", "src_uid": "ba0f9f5f0ad4786b9274c829be587961", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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() }.sorted()\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }.sorted()\n var ans = 0\n while (n>=1&&m>=2){\n n+=1\n m-=2\n ans++\n n = minOf(n, m).also { m = maxOf(n, m) }\n }\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "dp", "implementation"], "code_uid": "7121994531e1984ef4a3624f1d69d0ba", "src_uid": "ba0f9f5f0ad4786b9274c829be587961", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "const val data = \"4 4\"\n\nfun main() {\n val line = readLine() ?: \"1 1\"\n val split = line.split(\" \")\n Game(chargeFirst = split[0].toInt(), chargeSecond = split[1].toInt()).apply {\n while (canPlay) minutePasses()\n println(duration)\n }\n\n}\n\n\nclass Game(chargeFirst: Int, chargeSecond: Int) {\n\n var duration = 0\n\n private val first: Joystick = Joystick(chargeFirst)\n private val second: Joystick = Joystick(chargeSecond)\n\n private val dischargingAmount = -2\n private val chargeAmount = 1\n\n private val chargingFirst get() = first.charge <= second.charge\n\n fun minutePasses() {\n val firstNeedsCharging = chargingFirst\n if ((first.charge != 1 || firstNeedsCharging) && (second.charge != 1 || !firstNeedsCharging)) duration++\n\n first.charge += if (firstNeedsCharging) chargeAmount else dischargingAmount\n second.charge += if (firstNeedsCharging) dischargingAmount else chargeAmount\n }\n\n val canPlay get() = first.charge > 0 && second.charge > 0\n}\n\ndata class Joystick(var charge: Int)", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "dp", "implementation"], "code_uid": "ca04355ae13dbb21d1542e76b14af8ff", "src_uid": "ba0f9f5f0ad4786b9274c829be587961", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val info = readInts()\n val smaller = info.subList(0, 4).min()!!\n val top = min(smaller, info[5] + 1)\n print(max(0, top - info[4]))\n}", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "3ecad58540b973c5400937756f850cb4", "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "31915875d6dd3e16293f30f9823c4fa3", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "38723ca647178a8b72b5f97922f2579d", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "2abc9718e1f0a1110840eef916eb8d10", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "00f6df258ccb1ffe34090a289d6841da", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (target, p) = readLine()!!.split(\" \").map { it.toInt() }\n\n (1..31).forEach { k ->\n val v = target - k * p\n if (v <= 0) return@forEach\n if (Integer.bitCount(v) > k) return@forEach\n\n val highestOneBit = Integer.highestOneBit(v)\n if (k > highestOneBit) return@forEach\n println(k)\n return@main\n }\n\n println(-1)\n}\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "bitmasks"], "code_uid": "2c7d63feecfaea3c5e5cf23edb80bab8", "src_uid": "9e86d87ce5a75c6a982894af84eb4ba8", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var n:Int = readLine()!!.toInt() \n var m:Int = readLine()!!.toInt()\n\t\n if(n>=27){\n println(m)\n }\n else\n println(m % (1 shl n))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "dc8036a30190049d39b60aee40a8e3c2", "src_uid": "c649052b549126e600691931b512022f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n//package a913\n\nfun main(a:Array){\n val input = Scanner(System.`in`)\n\n val n=input.nextInt()\n val m= input.nextInt()\n if (n > 31) println(m)\n else println(m % (1 shl n))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "d49c8c595977e9369b06d02ce163e279", "src_uid": "c649052b549126e600691931b512022f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.io.*\nimport java.lang.Math.pow\nimport java.util.*\n\nfun solve() {\n val n = nextInt()\n val m = nextInt()\n val mod = if (n < 30) pow(2.toDouble(), n.toDouble()) else pow(10.0, 10.0)\n\n println((m%mod).toInt())\n\n\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\n\nvar br = BufferedReader(InputStreamReader(System.`in`))\n\nvar pw = PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))\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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "5cc51d0be3eb302841686e2cdb40f970", "src_uid": "c649052b549126e600691931b512022f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val m = readLine()!!.toInt()\n if (n > 26) {\n print(m)\n } else {\n print(m % Math.pow(2.toDouble(), n.toDouble()).toInt())\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "b0155579f50bf0cd88052587897659a4", "src_uid": "c649052b549126e600691931b512022f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\n\nfun main() {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val writer = PrintWriter(System.`out`)\n\n solve(reader, writer)\n\n writer.flush()\n}\n\nfun solve(reader: BufferedReader, writer: PrintWriter) {\n val n: Int\n val m: Int\n val k: Int\n\n reader.readLine().split(\" \").let {\n n = it[0].toInt()\n m = it[1].toInt()\n k = it[2].toInt()\n }\n\n if (n <= m && n <= k) {\n writer.write(\"Yes\")\n } else {\n writer.write(\"No\")\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "13edaf022b11d16b8a74b84de2326937", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val len = r.readLine()!!.toInt()\n val (a, b, c) = r.readLine()!!.split(\" \").map { it.toInt() }\n println(if (minOf(b, c)>=a)\"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "63af465a4ae981309982c91aecea8fa0", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 = ni()\n val M = ni()\n val K = ni()\n val ok = N <= min(M, K)\n if (ok) out.println(\"Yes\")\n else out.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\n private val isDebug = try {\n // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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, offset) { ni() }\n }\n\n private inline fun map(n: Int, offset: Int = 0, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i + offset)\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun pair(a: A, b: B) = RPair(a, b)\ndata class RPair(val _1: A, val _2: B)\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "ab938b65ba68479fff73dbe5aa9309c0", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 = ir.nextInt()\n val k = ir.nextInt()\n val g = ir.nextInt()\n\n if (n <= k && n <= g)\n pw.print(\"Yes\")\n else\n pw.print(\"No\")\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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7d414e723f0d9e2c03d5b87e9ba5331b", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.ArrayDeque\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\n/** @author Spheniscine */\nfun main() {\n output {\n val n = readInt()\n MODINT_BASE = readInt()\n\n val factorial = ModIntArray(n + 1).also {\n it[0] = ModInt(1)\n for(i in 1..it.lastIndex) {\n it[i] = it[i-1] * i\n }\n }\n\n val ans = (1..n).sumByModInt { k ->\n val j = n - k + 1\n factorial[k] * j * j * factorial[n-k]\n }\n println(ans.int)\n }\n}\n\nvar MODINT_BASE = 998244353\ninline val MODINT_TOTIENT get() = 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 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 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 operator fun plus(other: ModInt) = // MODINT_BASE < 2^30\n (int + other.int).let { if(it >= MODINT_BASE) ModInt(it - MODINT_BASE) else ModInt(it) }\n inline operator fun plus(other: Int) = plus(other.toModInt())\n operator fun inc() = if(int == MODINT_BASE - 1) ModInt(0) else ModInt(int + 1)\n\n operator fun minus(other: ModInt) =\n (int - other.int).let { if(it < 0) ModInt(it + MODINT_BASE) else ModInt(it) }\n inline operator fun minus(other: Int) = minus(other.toModInt())\n operator fun dec() = if(int == 0) ModInt(MODINT_BASE - 1) else ModInt(int - 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) {\n require(int != 0) { \"Can't invert/divide by 0\" }\n exponent umod MODINT_TOTIENT\n } else exponent\n return ModInt(int.powMod(e, MODINT_BASE))\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 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 inline 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 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 sum() = indices.sumByModInt(::get)\n fun product() = indices.productByModInt(::get)\n\n fun copyOf(newSize: Int) = ModIntArray(intArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun ModIntArray(capacity: Int) = ModIntArray(IntArray(capacity))\ninline fun ModIntArray(capacity: Int, init: (Int) -> ModInt) =\n ModIntArray(IntArray(capacity) { init(it).int })\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 }\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 _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}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "55417caf191ea4cbb57db3c65d0ce4fa", "src_uid": "020d5dae7157d937c3f58554c9b155f9", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.BitSet\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\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n val n = readInt()\n MOD = readInt()\n\n val factorial = ModIntArray(n + 1).also {\n it[0] = ModInt(1)\n for(i in 1..it.lastIndex) {\n it[i] = it[i-1] * i\n }\n }\n\n val ans = (1..n).sumByModInt { k ->\n val j = n - k + 1\n j * factorial[k] * j * factorial[n-k]\n }\n println(ans.int)\n}\n\nvar MOD = 998244353\ninline val TOTIENT get() = 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(size: Int) = ModIntArray(IntArray(size))\ninline fun ModIntArray(size: Int, init: (Int) -> ModInt) =\n ModIntArray(IntArray(size) { init(it).int })\n\nfun 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 }\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()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "ad389e02f4c5ad4c5f25d15c6562f428", "src_uid": "020d5dae7157d937c3f58554c9b155f9", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single int\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 readDoubles() = readStrings().map { it.toDouble() } // list of Doubles\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nconst val N = 250000 + 5\n\nvar fact = ArrayList()\n\nfun init(m: Long)\n{\n (0 until N).forEach { fact.add(0) }\n fact[0] = 1\n for (i in 1 until N)\n {\n fact[i] = fact[i - 1] * i.toLong()\n fact[i] %= m\n }\n}\n\nfun solve()\n{\n var (n,m) = readLongs()\n init(m)\n var ans:Long = 0\n for (i in 1..n.toInt())\n {\n var tmp:Long = fact[i] * fact[n.toInt()-i+1]\n tmp%=m;\n tmp*=(n-i.toLong()+1.toLong())\n tmp%=m;\n ans+=tmp;\n ans%=m;\n }\n println(ans)\n\n\n}\n\nfun main()\n{\n var t = 1\n //t = readInt()\n while (t-- > 0)\n {\n solve()\n }\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "6e610783e013f3b1ba174a94121e8ae4", "src_uid": "020d5dae7157d937c3f58554c9b155f9", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, M) = readLine()!!.split(\" \").map { it.toInt() }\n\n val fact = LongArray(n + 1) { 1 }\n (2..n).forEach { fact[it] = fact[it - 1] * it % M }\n var out = 0L\n (1..n).forEach {\n out += (n - it + 1) * (fact[it] * fact[n - it + 1] % M)\n out %= M\n }\n println(out)\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "995b586bf140c8de0053979c1dc36bea", "src_uid": "020d5dae7157d937c3f58554c9b155f9", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var play = false\n val card = readLine() ?: \"\"\n val myCard = readLine() ?: \"\"\n val regex = Regex(\"${card[0]}|${card[1]}\")\n if (regex.containsMatchIn(myCard)) play = true\n println(if (play) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "8775cb8336e644c6afa2f04098a73d20", "src_uid": "699444eb6366ad12bc77e7ac2602d74b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val table = readLine()!!\n val hand = readLine()!!\n if (hand.contains(table[0]) || hand.contains(table[1])) print(\"YES\") else print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "460ede3b614410f7e5f9e7c70df91611", "src_uid": "699444eb6366ad12bc77e7ac2602d74b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array){\n val table = readLine()!!\n val cards = readLine()!!.split(\" \")\n var can = false\n for (c in cards){\n if(c[0] == table[0] || c[1] == table[1])\n can = true\n if(can)break\n }\n println(\"${if (can) \"YES\" else \"NO\"}\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "dc8d25e8f73c221d5576c8c886880f27", "src_uid": "699444eb6366ad12bc77e7ac2602d74b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * https://codeforces.com/problemset/problem/1097/A\n * Difficulty: 500\n */\n\nfun main(args: Array) {\n val (num, suit) = readLine()!!.toCharArray()\n val cards = readLine()!!.split(\" \").map { it[0] to it[1] }\n\n val hasPlayableCards = cards.count { (n, s) ->\n n == num || s == suit\n }\n\n if (hasPlayableCards > 0) println(\"YES\") else println(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "366048518fe20af3db34b5a3887fe179", "src_uid": "699444eb6366ad12bc77e7ac2602d74b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//Kotlin is also fun!!\nimport java.lang.Long.max\nimport java.util.*\nfun main(args: Array) = with(Scanner(System.`in`))\n{\n val (n,k)= readLine()!!.split(\" \").map{it.toLong()}\n val mx=(k-1)/2\n val mi=max(k-n,1L)\n var res=0L\n if(mi<=mx)\n res=mx-mi+1\n print(res)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "d0a33914df9ca62cec68a5f5041e89e8", "src_uid": "98624ab2fcd2a50a75788a29e04999ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\n\nfun main(args: Array) {\n val (n, k) = readLine()!!.split(\" \").map { it.toLong() }\n println(countWays(n, k))\n}\n\nfun countWays(n: Long, k: Long): Long {\n if (k < 3 || k > 2 * n - 1) return 0\n var m1 = k / 2\n var m2 = k - m1\n if (m1 == m2) {\n m1--\n m2++\n }\n return min(n - m2 + 1, m1)\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "4b8f3b4dd24ab4aa707d7e351930e8d6", "src_uid": "98624ab2fcd2a50a75788a29e04999ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\n\ntypealias IntMatrix = Array\ntypealias Graph = IntMatrix\n\ntypealias LongMatrix = Array\n\ntypealias IndexPair = Pair\ntypealias IntIndexPair = IndexPair\n\ntypealias IntIntPair = Pair\n\ntypealias ListArray = Array>\n\nfun init() { }\n\nfun solve() {\n val (n, k) = readLongs()\n\n val answer = getAnswer(n, k)\n out.println(answer)\n}\n\nfun getAnswer(n : Long, k : Long) : Long {\n val maxPossible = if (k <= n) k - 1 else n\n val minPossible = k - maxPossible\n\n val count = Math.max(0L, (maxPossible - minPossible + 1))\n return count / 2\n}\n\nclass FenwickTree(n : Int) {\n\n val size = n + 1\n val tree = LongArray(size) { 0L }\n\n fun update(index : Int, delta : Int) {\n var x = index + 1\n while (x < size) {\n tree[x] = tree[x] + delta\n x += x and -x\n }\n }\n\n fun get(start : Int, end : Int) =\n get(end) - get(start - 1)\n\n fun get(index : Int) : Long {\n var result : Long = 0\n\n var x = index + 1\n while (x > 0) {\n result += tree[x]\n x -= x and -x\n }\n\n return result\n }\n}\n\nfun yesNo(yes : Boolean) {\n out.println(if (yes) \"YES\" else \"NO\")\n}\n\nfun run() {\n init()\n solve()\n out.close()\n}\n\nfun main(args: Array) {\n run()\n}\n\nval ONLINE_JUDGE = true//!File(\"input.txt\").exists()\n\nval input = BufferedReader(\n if (ONLINE_JUDGE) InputStreamReader(System.`in`) else FileReader(\"input.txt\")\n)\nval out =\n if (ONLINE_JUDGE) PrintWriter(System.out)\n else PrintWriter(\"output.txt\")\n\nfun readStrings(separator: String = \" \", emptyWords: Boolean = false) : Array {\n val line = input.readLine()\n\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 readString(separator: String = \" \") =\n readStrings(separator).first()\n\nfun readInts(separator: String = \" \") =\n readStrings(separator).map(String::toInt).toIntArray()\n\n\nfun readSortedInts(separator: String = \" \") : IntArray {\n val a = readInts(separator)\n\n val aInteger : Array = Array(a.size, { a[it] })\n Arrays.sort(aInteger)\n\n return aInteger.toIntArray()\n}\n\nfun readInt(separator: String = \" \") =\n readInts(separator).first()\n\nfun readLongs(separator: String = \" \") =\n readStrings(separator).map(String::toLong).toLongArray()\n\nfun readLong(separator: String = \" \") =\n readLongs(separator).first()\n\nfun readDoubles(separator: String = \" \") =\n readStrings(separator).map(String::toDouble).toDoubleArray()\n\nfun readDouble(separator: String = \" \") =\n readDoubles(separator).first()\n\nfun readTree(n : Int, indexing : Int = 1) =\n readGraph(n, n - 1, true, indexing)\n\nfun readGraph(n: Int, m : Int,\n undirected : Boolean = true,\n indexing : Int = 1) : Graph {\n val builder = GraphBuilder()\n\n for (i in 1..m) {\n var (from, to) = readInts()\n\n from -= indexing\n to -= indexing\n\n if (undirected) builder.addEdge(from, to)\n else builder.addDirectedEdge(from, to)\n }\n\n return builder.build(n)\n}\n\nclass GraphBuilder {\n\n val froms : MutableList\n val tos : MutableList\n\n init {\n this.froms = ArrayList()\n this.tos = ArrayList()\n }\n\n fun addEdge(from : Int, to : Int) {\n addDirectedEdge(from, to)\n addDirectedEdge(to, from)\n }\n\n fun addDirectedEdge(from : Int, to : Int) {\n froms.add(from)\n tos.add(to)\n }\n\n fun build(n : Int) : Graph {\n val sizes = IntArray(n) { 0 }\n froms.forEach { ++sizes[it] }\n\n val graph = Array(n) { IntArray(sizes[it]) { 0 } }\n\n for (i in 0 until n) {\n sizes[i] = 0\n }\n\n for (i in 0 until froms.size) {\n val from = froms[i]\n val to = tos[i]\n\n graph[from][sizes[from]++] = to\n }\n\n return graph\n }\n}\n\nfun checkIndex(index : Int, size : Int) =\n (index in 0..(size - 1))\n\nfun checkCell(x : Int, n : Int, y : Int, m : Int) =\n checkIndex(x, n) && checkIndex(y, m)\n\nfun toChar(index : Int, start : Char) =\n (index + start.toInt()).toChar()\n\nclass DSU {\n\n var sizes : IntArray\n var ranks : IntArray\n var parents : IntArray\n\n constructor(n : Int)\n : this(\n IntArray(n) { 1 }\n )\n\n constructor(sizes : IntArray) {\n val size = sizes.size\n this.sizes = sizes\n this.ranks = IntArray(size) { 1 }\n this.parents = IntArray(size) { it }\n }\n\n operator fun get(v : Int) : Int {\n val parent = parents[v]\n if (parent == v) return v\n parents[v] = get(parent)\n return parents[v]\n }\n\n fun union(aUniting : Int, bUniting : Int) {\n var a = get(aUniting)\n var b = get(bUniting)\n\n if (a == b) return\n\n if (ranks[a] < ranks[b]) {\n val tmp = a\n a = b\n b = tmp\n }\n\n parents[b] = a\n sizes[a] += sizes[b]\n if (ranks[a] == ranks[b]) ++ranks[a]\n }\n\n fun size(v : Int) : Int = sizes[get(v)]\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "64bda5d61ea7c5ddf56cabde8ffccd46", "src_uid": "98624ab2fcd2a50a75788a29e04999ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (n, k) = readLine()!!.split(' ').map { it.toLong() }\n println((Math.min(n,k-1))-(Math.min(n,k/2)));\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "ee9d50fe7233e0d0a3b160d0f5b6838c", "src_uid": "98624ab2fcd2a50a75788a29e04999ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n *\n * @author aryssoncf\n */\n//object Main {\n// @JvmStatic\n fun main(args: Array) {\n val inputStream = System.`in`\n val outputStream: OutputStream = System.out\n val `in` = InputReader(inputStream)\n val out = OutputWriter(outputStream)\n val solver = DRadioTowers()\n solver.solve(1, `in`, out)\n out.close()\n }\n\n internal class DRadioTowers {\n fun solve(testNumber: Int, `in`: InputReader, out: OutputWriter) {\n val n = `in`.readInt()\n // ModIntFactory mf = new ModIntFactory(MOD);\n// ModIntFactory.ModInt[] dp = new ModIntFactory.ModInt[n + 1], sum = new ModIntFactory.ModInt[n + 1];\n// dp[0] = sum[0] = mf.create(1);\n// for (int i = 1; i <= n; i++) {\n// dp[i] = sum[i - 1].div(2);\n// sum[i] = (i == 1 ? mf.create(0) : sum[i - 2]).div(4).add(dp[i]);\n// }\n// int res = dp[n].value();\n val dp = LongArray(n + 1)\n val sum = LongArray(n + 1)\n sum[0] = 1\n dp[0] = sum[0]\n val inv2 = IntegerUtils.reverse(2, MOD.toLong())\n val inv4 = inv2 * inv2 % MOD\n for (i in 1..n) {\n dp[i] = sum[i - 1] * inv2 % MOD\n sum[i] = ((if (i - 2 >= 0) sum[i - 2] else 0) * inv4 + dp[i]) % MOD\n }\n val res = dp[n]\n out.printLine(res)\n }\n\n companion object {\n const val MOD = 998244353\n }\n }\n\n internal class InputReader(private val stream: InputStream) {\n private val buf = ByteArray(1024)\n private var curChar = 0\n private var numChars = 0\n private val filter: SpaceCharFilter? = null\n fun read(): Int {\n if (numChars == -1) {\n throw InputMismatchException()\n }\n if (curChar >= numChars) {\n curChar = 0\n numChars = try {\n stream.read(buf)\n } catch (e: IOException) {\n throw InputMismatchException()\n }\n if (numChars <= 0) {\n return -1\n }\n }\n return buf[curChar++].toInt()\n }\n\n fun readInt(): Int {\n var c = read()\n while (isSpaceChar(c)) {\n c = read()\n }\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 }\n res *= 10\n res += c - '0'.toInt()\n c = read()\n } while (!isSpaceChar(c))\n return res * sgn\n }\n\n fun isSpaceChar(c: Int): Boolean {\n return filter?.isSpaceChar(c) ?: isWhitespace(c)\n }\n\n interface SpaceCharFilter {\n fun isSpaceChar(ch: Int): Boolean\n }\n\n companion object {\n fun isWhitespace(c: Int): Boolean {\n return c == ' '.toInt() || c == '\\n'.toInt() || c == '\\r'.toInt() || c == '\\t'.toInt() || c == -1\n }\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 close() {\n writer.close()\n }\n\n fun printLine(i: Long) {\n writer.println(i)\n }\n }\n\n internal object IntegerUtils {\n fun trueMod(a: Long, b: Long): Long {\n var a = a\n a %= b\n a += b\n a %= b\n return a\n }\n\n fun reverse(number: Long, modulo: Long): Long {\n return trueMod(extGcd(number, modulo).first, modulo)\n }\n\n fun extGcd(a: Long, b: Long): EzLongLongLongTriple {\n var x2: Long = 1\n var y2: Long = 0\n var x1: Long = 0\n var y1: Long = 1\n var x: Long\n var y: Long\n var r2: Long\n var r1: Long\n var q: Long\n var r: Long\n r2 = a\n r1 = b\n while (r1 != 0L) {\n q = r2 / r1\n r = r2 % r1\n x = x2 - q * x1\n y = y2 - q * y1\n r2 = r1\n r1 = r\n x2 = x1\n y2 = y1\n x1 = x\n y1 = y\n }\n return EzLongLongLongTriple(x2, y2, r2)\n }\n }\n\n internal object PrimitiveHashCalculator {\n fun getHash(x: Long): Int {\n return x.toInt() xor (x ushr 32) as Int\n }\n }\n\n internal class EzLongLongLongTriple(var first: Long, var second: Long, var third: Long) : Comparable {\n override fun equals(o: Any?): Boolean {\n if (this === o) return true\n if (o == null || javaClass != o.javaClass) return false\n val that = o as EzLongLongLongTriple\n return first == that.first && second == that.second && third == that.third\n }\n\n override fun hashCode(): Int {\n var hash = HASHCODE_INITIAL_VALUE\n hash = (hash xor PrimitiveHashCalculator.getHash(first)) * HASHCODE_MULTIPLIER\n hash = (hash xor PrimitiveHashCalculator.getHash(second)) * HASHCODE_MULTIPLIER\n hash = (hash xor PrimitiveHashCalculator.getHash(third)) * HASHCODE_MULTIPLIER\n return hash\n }\n\n override fun compareTo(o: EzLongLongLongTriple): Int {\n var res = java.lang.Long.compare(first, o.first)\n if (res == 0) {\n res = java.lang.Long.compare(second, o.second)\n if (res == 0) {\n res = java.lang.Long.compare(third, o.third)\n }\n }\n return res\n }\n\n override fun toString(): String {\n return \"($first, $second, $third)\"\n }\n\n companion object {\n private const val HASHCODE_INITIAL_VALUE = -0x7ee3623b\n private const val HASHCODE_MULTIPLIER = 0x01000193\n }\n }\n//}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "a6cc735b18ff7b997eef021eef52c35f", "src_uid": "cec37432956bb0a1ce62a0188fe2d805", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "const val MOD = 998244353L\n\nfun main() {\n val n = readLine()!!.toInt()\n val factorial = LongArray((2 * n) + 1)\n factorial[0] = 1L\n for (j in 1..2 * n) {\n factorial[j] = (j.toLong() * factorial[j - 1]) % MOD\n }\n val factInv = LongArray((2 * n) + 1)\n factInv[2 * n] = factorial[2 * n] pow -1\n for (j in (2 * n) - 1 downTo 0) {\n factInv[j] = ((j + 1).toLong() * factInv[j + 1]) % MOD\n }\n fun choose(a: Int, b: Int) = if (a < 0 || b !in 0..a) 0L else (factorial[a] * ((factInv[b] * factInv[a - b]) % MOD)) % MOD\n var answer = 0L\n for (k in (n % 2)..n step 2) {\n answer += choose(((n - k) / 2) + k - 1, k - 1)\n }\n answer %= MOD\n answer *= 2L pow -n\n answer %= MOD\n println(answer)\n}\n\nconst val MOD_TOTIENT = MOD.toInt() - 1\n\ninfix fun Long.pow(power: Int): Long {\n var e = power\n e %= MOD_TOTIENT\n if (e < 0) {\n e += MOD_TOTIENT\n }\n if (e == 0 && this == 0L) {\n return this\n }\n var b = this % MOD\n var res = 1L\n while (e > 0) {\n if (e and 1 != 0) {\n res *= b\n res %= MOD\n }\n b *= b\n b %= MOD\n e = e shr 1\n }\n return res\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "a7d35a0b23ceaac16cf276e5e8d9e441", "src_uid": "cec37432956bb0a1ce62a0188fe2d805", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n\tval n = readLine()!!.toInt()\n\tval m = 998244353\n\tval f = LongArray(n+1)\n\tf[1] = 1L\n\tfor (l in 2..n) f[l] = (f[l-1] + f[l-2])%m\n\tval inv = splitpow(splitpow(2, n, m), m-2, m)\n\tprintln(f[n]*inv%m)\n}\n\nfun splitpow(x: Long, n: Int, m: Int): Long = when {\n\tn == 1 -> x\n\tn%2 == 1 -> x*splitpow(x, n - 1, m)%m\n\telse -> splitpow(x, n/2, m).let { it*it%m }\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "662c710670bcdd3490edaf9729387b12", "src_uid": "cec37432956bb0a1ce62a0188fe2d805", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import ModInt.Companion.ONE\nimport ModInt.Companion.TWO\nimport ModInt.Companion.ZERO\nimport ModInt.Companion.toModInt\nimport Utils.ArrayUtils.Companion.makeDistinct\nimport Utils.ArrayUtils.Prints.Companion.println\nimport Utils.ArrayUtils.Sorts.Companion.shuffleSort\nimport Utils.ArrayUtils.Swaps.Companion.swap\nimport Utils.BinarySearchUtils.Companion.binarySearch\nimport Utils.BinarySearchUtils.Companion.binarySearchDouble\nimport Utils.BinarySearchUtils.Companion.binarySearchLong\nimport Utils.FastReader\nimport Utils.GeneralUtils.Companion.gcd\nimport Utils.GeneralUtils.Companion.length\nimport Utils.GeneralUtils.Companion.rnd\nimport java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayDeque\nimport kotlin.random.Random\nimport kotlin.random.Random.Default.nextInt\nimport kotlin.time.ExperimentalTime\n\n@ExperimentalStdlibApi\n@ExperimentalTime\n@ExperimentalUnsignedTypes\nfun main() {\n Locale.setDefault(Locale.US)\n if (System.getProperty(\"ONLINE_JUDGE\") != null) {\n System.setOut(PrintStream(BufferedOutputStream(System.out)))\n }\n Task().solve()\n System.out.flush()\n}\n\n@ExperimentalStdlibApi\n@ExperimentalTime\n@ExperimentalUnsignedTypes\nclass Task(private val fin: FastReader = FastReader()) {\n fun solve() {\n fun fib(n: Int): ModInt {\n fun Pair.nextFib() = Pair(second, first + second)\n return (0..n).fold(Pair(ZERO, ONE)) { acc, _ -> acc.nextFib() }.second\n }\n val n = fin.readInt()\n println(fib(n - 2) / TWO.pow(n))\n }\n}\n\n@Suppress(\"MemberVisibilityCanBePrivate\", \"unused\")\n@ExperimentalStdlibApi\n@ExperimentalTime\n@ExperimentalUnsignedTypes\nclass Utils {\n class GeneralUtils {\n companion object {\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 fun gcd(a: Int, b: Int, c: Int): Int = gcd(gcd(a, b), c)\n fun gcd(a: Long, b: Long, c: Long): Long = gcd(gcd(a, b), c)\n val rnd = Random(239)\n val IntRange.length get() = last - first + 1\n }\n }\n\n class ArrayUtils {\n companion object {\n fun > MutableList.makeDistinct() {\n if (size <= 1) return\n sort()\n var sz = 1\n for (i in 1 until size) {\n if (this[i] != this[i - 1]) {\n this[sz++] = this[i]\n }\n }\n while (size > sz) removeAt(lastIndex)\n }\n }\n\n class Swaps {\n companion object {\n fun Array.swap(i: Int, j: Int) {\n val x = this[i]\n this[i] = this[j]\n this[j] = x\n }\n\n fun MutableList.swap(i: Int, j: Int) {\n val x = this[i]\n this[i] = this[j]\n this[j] = x\n }\n\n fun IntArray.swap(i: Int, j: Int) {\n val x = this[i]\n this[i] = this[j]\n this[j] = x\n }\n\n fun LongArray.swap(i: Int, j: Int) {\n val x = this[i]\n this[i] = this[j]\n this[j] = x\n }\n\n fun DoubleArray.swap(i: Int, j: Int) {\n val x = this[i]\n this[i] = this[j]\n this[j] = x\n sort()\n }\n\n fun CharArray.swap(i: Int, j: Int) {\n val x = this[i]\n this[i] = this[j]\n this[j] = x\n sort()\n }\n }\n }\n\n class Sorts {\n companion object {\n fun IntArray.shuffleSort() {\n for (i in 1 until size) swap(i, nextInt(i + 1))\n sort()\n }\n\n fun LongArray.shuffleSort() {\n for (i in 1 until size) swap(i, nextInt(i + 1))\n sort()\n }\n\n fun DoubleArray.shuffleSort() {\n for (i in 1 until size) swap(i, nextInt(i + 1))\n sort()\n }\n\n fun CharArray.shuffleSort() {\n for (i in 1 until size) swap(i, nextInt(i + 1))\n sort()\n }\n }\n }\n\n class Prints {\n companion object {\n fun println(a: IntArray) {\n if (a.isNotEmpty()) {\n print(a[0])\n for (i in 1 until a.size) {\n print(' ')\n print(a[i])\n }\n }\n println()\n }\n\n fun println(a: LongArray) {\n if (a.isNotEmpty()) {\n print(a[0])\n for (i in 1 until a.size) {\n print(' ')\n print(a[i])\n }\n }\n println()\n }\n\n fun println(a: CharArray, printSpace: Boolean = false) {\n if (a.isNotEmpty()) {\n print(a[0])\n for (i in 1 until a.size) {\n if (printSpace) print(' ')\n print(a[i])\n }\n }\n println()\n }\n\n fun println(a: Array<*>) {\n if (a.isNotEmpty()) {\n print(a[0])\n for (i in 1 until a.size) {\n print(' ')\n print(a[i])\n }\n }\n println()\n }\n\n fun println(a: List<*>) {\n if (a.isNotEmpty()) {\n print(a[0])\n for (i in 1 until a.size) {\n print(' ')\n print(a[i])\n }\n }\n println()\n }\n\n fun println(a: Iterable<*>) {\n val it = a.iterator()\n if (it.hasNext()) {\n print(it.next())\n while (it.hasNext()) {\n print(' ')\n print(it.next())\n }\n }\n println()\n }\n }\n }\n }\n\n class BinarySearchUtils {\n companion object {\n inline fun binarySearch(from: Int, to: Int, f: (Int) -> Boolean): Int {\n var l = from\n var r = to + 1\n while (r - l > 1) {\n val m = (l + r) / 2\n if (f(m)) l = m\n else r = m\n }\n return l\n }\n\n inline fun binarySearch(from: Int = 0, f: (Int) -> Boolean): Int {\n var len = 1\n while (f(from + len)) len *= 2\n return binarySearch(from + len / 2, from + len, f)\n }\n\n inline fun binarySearchLong(from: Long, to: Long, f: (Long) -> Boolean): Long {\n var l = from\n var r = to + 1\n while (r - l > 1) {\n val m = (l + r) / 2\n if (f(m)) l = m\n else r = m\n }\n return l\n }\n\n inline fun binarySearchLong(from: Long = 0, f: (Long) -> Boolean): Long {\n var len = 1L\n while (f(from + len)) len *= 2\n return binarySearchLong(from + len / 2, from + len, f)\n }\n\n inline fun binarySearchDouble(from: Double, to: Double, times: Int = 200, f: (Double) -> Boolean): Double {\n var l = from\n var r = to\n repeat(times) {\n val m = (l + r) / 2\n if (f(m)) l = m\n else r = m\n }\n return l\n }\n\n inline fun binarySearchDouble(from: Double = 0.0, times: Int = 200, f: (Double) -> Boolean): Double {\n var len = 1.0\n while (f(from + len)) len *= 2\n return binarySearchDouble(from, from + len, times, f)\n }\n }\n }\n\n class UtilsImports {\n fun importDependencies() {\n check(gcd(4, 6) == 2)\n check(rnd.nextInt(10) in 0 until 10)\n check(mutableListOf(1, 3, 2, 2, 1).apply { makeDistinct() } == listOf(1, 2, 3))\n check((5..10).length == 6)\n check(intArrayOf(3, 4).apply { swap(0, 1) }.contentEquals(intArrayOf(4, 3)))\n check(intArrayOf(5, 6, 2, 1, 5).apply { shuffleSort() }.contentEquals(intArrayOf(1, 2, 5, 5, 6)))\n check(binarySearch { it < 10 } == 9)\n check(binarySearchLong { it < 1e13.toLong() } == 1e13.toLong() - 1)\n binarySearchDouble { true }\n println(intArrayOf())\n ArrayDeque()\n }\n }\n\n class FastReader(fileName: String? = null) {\n @JvmField\n val br = BufferedReader(if (fileName != null) FileReader(fileName) else InputStreamReader(System.`in`))\n\n @JvmField\n var st = StringTokenizer(\"\")\n\n fun readString(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n return st.nextToken()\n }\n\n fun readInt() = readString().toInt()\n fun readLong() = readString().toLong()\n fun readDouble() = readString().toDouble()\n\n fun readIntArray(n: Int) = IntArray(n) { readInt() }\n fun readLongArray(n: Int) = LongArray(n) { readLong() }\n fun readStringArray(n: Int) = Array(n) { readString() }\n fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() }\n\n fun readInts(n: Int) = MutableList(n) { readInt() }\n fun readLongs(n: Int) = MutableList(n) { readLong() }\n fun readStrings(n: Int) = MutableList(n) { readString() }\n fun readDoubles(n: Int) = MutableList(n) { readDouble() }\n }\n}\n\n@Suppress(\"MemberVisibilityCanBePrivate\", \"unused\")\n@ExperimentalStdlibApi\n@ExperimentalTime\n@ExperimentalUnsignedTypes\ninline class ModInt(private val x: Int) {\n companion object {\n const val mod = 998_244_353\n\n // const val mod = 1e9.toInt() + 7\n fun Int.toModInt() = ModInt(this)\n fun Int.toModIntSafe() = ModInt((this % mod + mod) % mod)\n fun Long.toModIntSafe() = ModInt(((this % mod + mod) % mod).toInt())\n val ZERO = ModInt(0)\n val ONE = ModInt(1)\n val TWO = ModInt(2)\n val TEN = ModInt(10)\n }\n\n operator fun plus(k: ModInt) = ModInt((x + k.x).let { if (it >= mod) it - mod else it })\n operator fun minus(k: ModInt) = ModInt((x - k.x).let { if (it < 0) it + mod else it })\n operator fun times(k: ModInt) = ModInt((x * k.x.toLong() % mod).toInt())\n operator fun div(k: ModInt) = this * k.inv()\n operator fun unaryMinus() = if (x == 0) this else ModInt(mod - x)\n fun inv() = pow(mod - 2)\n fun pow(p: Int): ModInt = if (p == 0) ONE else pow(p / 2).let { if (p % 2 == 1) it * it * this else it * it }\n fun toInt() = x\n override fun toString() = x.toString()\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "ca9786600d9cd60dbe0a86a4b5233998", "src_uid": "cec37432956bb0a1ce62a0188fe2d805", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package codeforces.round401.a\n\nimport java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val `in` = FastScanner(inputStream)\n val out = PrintWriter(outputStream)\n solve(`in`, out)\n out.close()\n}\n\nprivate fun solve(scanner : FastScanner, out: PrintWriter) {\n val n = scanner.nextLong()\n val x = scanner.nextInt()\n\n val expected = when(x) {\n 0 -> Triple(1, 0, 0)\n 1 -> Triple(0, 1, 0)\n 2 -> Triple(0, 0, 1)\n else -> throw IllegalArgumentException()\n }\n listOf(Triple(1, 0, 0), Triple(0, 1, 0), Triple(0, 0, 1)).forEach {\n val res = simulate(it, n)\n if (res == expected) {\n val pos = it.toList().indexOf(1)\n out.print(pos)\n return\n }\n }\n}\n\nprivate fun simulate(initial: Triple, n: Long): Triple {\n var state = initial\n for (i in 1..n % 6L) {\n if (i % 2 == 1L) {\n val temp = state.first\n state = state.copy(first = state.second, second = temp)\n } else {\n val temp = state.third\n state = state.copy(third = state.second, second = temp)\n }\n }\n return state\n}\n\n\nprivate class FastScanner(`in`: InputStream) {\n private var reader: BufferedReader? = null\n private var tokenizer: StringTokenizer? = null\n\n init {\n reader = BufferedReader(InputStreamReader(`in`))\n tokenizer = null\n }\n\n operator fun next(): String {\n if (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 nextLine(): String {\n if (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n return reader!!.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n\n return tokenizer!!.nextToken(\"\\n\")\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "b41ead095ea908ce3fd1f1c922f52d5a", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun getInt() = readLine()!!.toInt()\nfun getInts() = readLine()!!.split(\" \").map { it.toInt() }\nfun getLong() = readLine()!!.toLong()\nfun getLongs() = readLine()!!.split(\" \").map{ it.toLong()}\nfun getWord() = readLine()!!\nfun getWords() = readLine()!!.split(\" \")\n\n\n\nfun main()\n{\n var nb_moves = getInt()\n var ball_at = getInt()\n var answer = -1\n nb_moves %= 6\n var balls = intArrayOf(0,0,0)\n balls[ball_at] = 1\n for (i in nb_moves downTo 1)\n {\n if ( i % 2 == 0)\n {\n val curr = balls[2]\n balls[2] = balls[1]\n balls[1] = curr\n }\n else\n {\n val curr = balls[1]\n balls[1] = balls[0]\n balls[0] = curr\n }\n }\n answer = balls.indexOf(1)\n println(answer)\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "34e5c80c608b8e735b82abda1bad2398", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val numMovements = readInt() % 6\n val positions = listOf(\"012210\", \"100122\", \"221001\")\n val x = readLine()!![0]\n for (position in 0..2) if (positions[position][numMovements] == x) print(position)\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "595d924fe35352fccd6712e360b38c2d", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(){\n var n = readLine()!!.toInt()\n var x = readLine()!!.toInt()\n\n var possibleCases = ArrayList()\n possibleCases.add(\"012\")\n possibleCases.add(\"102\")\n possibleCases.add(\"120\")\n possibleCases.add(\"210\")\n possibleCases.add(\"201\")\n possibleCases.add(\"021\")\n\n println(possibleCases[n%6][x])\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "03792ead6fa901dd850e324b930c9e5e", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.lang.Math.*\nimport java.util.*\n\n\nfun main() {\n init(System.`in`, System.out)\n val twos = LongArray(64) { i -> 1L shl i }\n val l = nextLong()\n val r = nextLong()\n var max = 0L\n for (i in 0 until 64) {\n if (twos[i] and l != twos[i] and r) {\n max = (1L shl i + 1) - 1\n }\n }\n pw.println(max)\n pw.close()\n}\n\nlateinit var br: BufferedReader\nlateinit var st: StringTokenizer\nlateinit var pw: PrintWriter\n\nfun init(`in`: InputStream, out: OutputStream) {\n br = BufferedReader(InputStreamReader(`in`))\n st = StringTokenizer(\"\")\n pw = PrintWriter(out)\n}\n\nfun init(`in`: File, out: File) {\n br = BufferedReader(FileReader(`in`))\n st = StringTokenizer(\"\")\n pw = PrintWriter(out)\n}\n\nfun next(): String {\n if (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st.nextToken()\n}\n\nfun nextInt() = next().toInt()\nfun nextLong() = next().toLong()\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "bitmasks", "greedy", "implementation"], "code_uid": "81738e6816f56aebf3f4376290a2992e", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.concurrent.fixedRateTimer\nimport kotlin.math.max\n\nclass Solution : Runnable {\n override fun run() {\n solve()\n }\n\n fun start() {\n Thread(null, Solution(), \"whatever\", (1 shl 27).toLong()).start()\n }\n}\n\nfun main(args: Array) {\n Solution().start()\n}\n\n\nclass IO {\n companion object {\n\n private val reader: InputReader\n private val writer: OutputWriter\n\n init {\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n reader = InputReader(FileInputStream(\"/Users/300041735/competitiveProgramming/src/codeforces/in.txt\"))\n writer = OutputWriter(FileOutputStream(\"/Users/300041735/competitiveProgramming/src/codeforces/out.txt\"))\n } else {\n reader = InputReader(System.`in`)\n writer = OutputWriter(System.`out`)\n }\n }\n\n private fun readMultipleInts(count: Int): List {\n val map = mutableListOf()\n repeat(count) {\n map.add(reader.readInt())\n }\n return map\n }\n\n fun readInt() = reader.readInt()\n fun readLong() = reader.readLong()\n fun readTwoInts() = readMultipleInts(2)\n fun readThreeInts() = readMultipleInts(3)\n fun readFourInts() = readMultipleInts(4)\n fun readFiveInts() = readMultipleInts(5)\n fun readSixInts() = readMultipleInts(6)\n fun readString() = reader.readString()\n fun readTree(n: Int): MutableMap> {\n val graph = mutableMapOf>()\n repeat(n - 1) {\n val u = reader.readInt()\n val v = reader.readInt()\n if (!graph.containsKey(u)) graph[u] = mutableListOf()\n if (!graph.containsKey(v)) graph[v] = mutableListOf()\n graph[u]!!.add(v)\n graph[v]!!.add(u)\n }\n return graph\n }\n\n fun readIntArray(n: Int): IntArray {\n return IntArray(n) { readInt() }\n }\n\n fun readLongArray(n: Int): Array {\n return Array(n) { readLong() }\n }\n\n fun write(obj: Any) {\n writer.printLine(obj)\n }\n\n fun flushOutput() {\n writer.flush()\n }\n\n fun closeOutput() {\n writer.close()\n }\n }\n}\n\n\nclass MATH {\n companion object {\n\n val mod = 998244353\n var ispre = false\n\n val factMod = Array(300002) { 1 }\n\n fun pre() {\n for (i in 2 until 300001) {\n factMod[i] = ((factMod[i - 1] * i.toLong()) % MATH.mod).toInt()\n }\n }\n\n fun gcd(a: Int, b: Int): Int {\n if (b == 0)\n return a\n return gcd(b, a % b)\n }\n\n fun gcd(a: Long, b: Long): Long {\n if (b == 0L)\n return a\n return gcd(b, a % b)\n }\n\n fun inverseMod(a: Int): Int {\n return powMod(a, mod - 2)\n }\n\n fun powMod(a: Int, b: Int): Int {\n //calculate a to the power b mod m\n if (b == 0) return 1\n return if (b % 2 == 1) {\n prodMod(a, powMod(a, b - 1))\n } else {\n val p = powMod(a, b / 2)\n prodMod(p, p)\n }\n }\n\n fun ncr(n: Int, r: Int): Int {\n if (!ispre) pre(); ispre = true\n return ((factMod[n].toLong() * inverseMod(((factMod[r].toLong() * factMod[n - r]) % mod).toInt())) % mod).toInt()\n }\n\n fun prodMod(val1: Int, val2: Int): Int {\n return ((val1.toLong() * val2) % mod).toInt()\n }\n\n }\n}\n\nfun solve() {\n\n\n val l = IO.readLong()\n val r = IO.readLong()\n val binl = get64BitBinaryString(l)\n val binr = get64BitBinaryString(r)\n var res = java.lang.StringBuilder()\n var found = false\n for (i in 0 until 64){\n //start from the msb\n if (found){\n res.append('1')\n continue\n }\n if ((binl[i] == '0' && binr[i] == '0' ) || ( binl[i] == '1' && binr[i] == '1')) {\n //just skip\n res.append('0')\n }else{\n //just append all ones\n res.append('1')\n found = true\n }\n }\n val ansString = res.toString()\n var ans = 0L\n var mul = 1L\n for (i in 63 downTo 0){\n if (ansString[i] == '1'){\n ans+= mul\n }\n mul *= 2\n }\n IO.write(ans)\n IO.flushOutput()\n IO.closeOutput()\n}\n\nfun get64BitBinaryString(numm : Long) : String {\n val builder = StringBuilder()\n var num = numm\n while (num != 0L){\n if (num%2 == 0L){\n builder.append('0')\n }else{\n builder.append('1')\n }\n num/=2\n }\n while (builder.length != 64){\n builder.append('0')\n }\n return builder.toString().reversed()\n}\n\nclass Primes {\n\n val primes = mutableListOf()\n\n init {\n sieve()\n }\n\n fun sieve() {\n val composite = IntArray(100001) { 0 }\n for (i in 2 until 100001){\n if (composite[i] == 0){\n //means i is prime\n primes.add(i)\n var cur = 1\n while (i*cur <= 100000){\n composite[i*cur] = 1\n cur++\n }\n }\n }\n }\n\n fun factorize(num: Int): Map {\n //using these primes factorize\n val factors = mutableMapOf()\n var n =num\n primes.forEach {\n var power = 0\n while (n%it == 0){\n n /= it\n power++\n }\n if (power != 0){\n factors[it] = power\n }\n }\n if (n != 1){\n factors[n] = 1\n }\n return factors\n }\n\n}\n\n\nfun isBitSet(num : Int, i : Int) : Boolean{\n return (num.and(1.shl(i)) > 0)\n}\n\nfun power(i : Int, j : Int) : Int{\n if (j == 0) return 1\n return i*power(i, j - 1)\n}\n\ndata class Graph(val edges: MutableMap>)\n\n\nclass MinSegmentTree(\n input: Array\n) {\n private val tree: Array\n private val lazy: Array\n\n constructor(size: Int) : this(Array(size) { Int.MAX_VALUE })\n\n init {\n val size = nextPowerOfTwo(input.size)\n tree = Array(2 * size) { Int.MAX_VALUE }\n lazy = Array(2 * size) { Int.MAX_VALUE }\n for (i in 0 until input.size) {\n tree[i + size] = input[i]\n }\n for (i in (size - 1) downTo 1) {\n tree[i] = Math.min(tree[leftChild(i)], tree[rightChild(i)])\n }\n }\n\n private fun updateTree(lowerRange: Int, upperRange: Int, lowerBound: Int, upperBound: Int, index: Int, value: Int) {\n updateLazyNode(index, lowerBound, upperBound, lazy[index])\n if (noOverlap(lowerRange, upperRange, lowerBound, upperBound)) return\n else if (completeOverlap(lowerRange, upperRange, lowerBound, upperBound)) updateLazyNode(index, lowerBound, upperBound, value)\n else {\n updateTree(lowerRange, upperRange, lowerBound, midIndex(lowerBound, upperBound), leftChild(index), value)\n updateTree(lowerRange, upperRange, midIndex(lowerBound, upperBound) + 1, upperBound, rightChild(index), value)\n tree[index] = Math.min(tree[leftChild(index)], tree[rightChild(index)])\n }\n }\n\n private fun queryTree(lowerRange: Int, upperRange: Int, lowerBound: Int, upperBound: Int, index: Int): Int {\n updateLazyNode(index, lowerBound, upperBound, lazy[index])\n if (noOverlap(lowerRange, upperRange, lowerBound, upperBound)) return Int.MAX_VALUE\n else if (completeOverlap(lowerRange, upperRange, lowerBound, upperBound)) return tree[index]\n else {\n return Math.min(queryTree(lowerRange, upperRange, lowerBound, midIndex(lowerBound, upperBound), leftChild(index)),\n queryTree(lowerRange, upperRange, midIndex(lowerBound, upperBound) + 1, upperBound, rightChild(index)))\n }\n }\n\n private fun updateLazyNode(index: Int, lowerBound: Int, upperBound: Int, delta: Int) {\n tree[index] += delta\n if (lowerBound != upperBound) {\n lazy[leftChild(index)] += delta\n lazy[rightChild(index)] += delta\n }\n lazy[index] = 0\n }\n\n fun getElements(N: Int): List {\n return tree.copyOfRange(tree.size / 2, tree.size / 2 + N).asList()\n }\n\n fun update(lowerRange: Int, upperRange: Int, value: Int) {\n updateTree(lowerRange, upperRange, 1, lazy.size / 2, 1, value)\n }\n\n fun query(lowerRange: Int, upperRange: Int): Int {\n return queryTree(lowerRange, upperRange, 1, lazy.size / 2, 1)\n }\n\n private fun noOverlap(l: Int, u: Int, lb: Int, ub: Int): Boolean = (lb > u || ub < l)\n\n private fun completeOverlap(l: Int, u: Int, lb: Int, ub: Int): Boolean = (lb >= l && ub <= u)\n\n\n private fun nextPowerOfTwo(num: Int): Int {\n var exponent = 2\n while (true) {\n if (exponent >= num) {\n return exponent\n }\n exponent *= 2\n }\n }\n\n private fun midIndex(l: Int, r: Int) = (l + r) / 2\n private fun parent(i: Int) = i / 2\n private fun leftChild(i: Int) = 2 * i\n private fun rightChild(i: Int) = 2 * i + 1\n\n}\n\nclass 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 }\n var sgn: Long = 1\n if (c == '-'.toInt()) {\n sgn = -1\n c = read()\n }\n var number: Long = 0\n do {\n number *= 10L\n number += (c - '0'.toInt()).toLong()\n c = read()\n } while (!isSpaceChar(c))\n return number * 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\nclass 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 fun flush() {\n writer.flush()\n }\n\n}\n\nclass DinitzMaxFlowSolver(val n: Int, val s: Int, val t: Int, val graph: MutableMap>, val edgeMap: MutableMap, Edge>) {\n\n private val level = IntArray(n + 1) { -1 } //storing levels of each vertex in level graph\n var maxFlow = 0L\n\n init {\n solve()\n }\n\n fun solve() {\n val next = IntArray(n + 1) { 0 }\n while (bfs()) {\n Arrays.fill(next, 0)\n var flow = 0L\n do {\n maxFlow += flow\n flow = dfs(s, next, Long.MAX_VALUE)\n } while (flow != 0L)\n }\n }\n\n private fun dfs(at: Int, next: IntArray, flow: Long): Long {\n if (at == t) return flow\n var size = 0\n if (graph.containsKey(at)) size = graph[at]!!.size\n while (next[at] < size) {\n val edge = graph[at]!!.get(next[at])\n if (edge.remainingCapacity() > 0 && level[edge.to] == level[at] + 1) {\n val bottleNeck = dfs(edge.to, next, Math.min(flow, edge.remainingCapacity()))\n if (bottleNeck > 0) {\n edgeMap[Pair(edge.from, edge.to)]!!.flow += bottleNeck\n edgeMap[Pair(edge.to, edge.from)]!!.flow -= bottleNeck\n return bottleNeck\n }\n }\n next[at]++\n }\n return 0\n }\n\n private fun bfs(): Boolean {\n Arrays.fill(level, -1)\n val curLevel = ArrayDeque()\n curLevel.add(s)\n level[s] = 0\n\n while (curLevel.isNotEmpty()) {\n val top = curLevel.poll()\n if (graph.containsKey(top)) {\n graph[top]!!.forEach {\n if (it.remainingCapacity() > 0 && level[it.to] == -1) {\n level[it.to] = level[top] + 1\n curLevel.offer(it.to)\n }\n }\n }\n }\n return level[t] != -1\n }\n\n\n}\n\nclass Edge(val from: Int, val to: Int, val capacity: Long) {\n var flow = 0L\n fun remainingCapacity(): Long {\n return capacity - flow\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "bitmasks", "greedy", "implementation"], "code_uid": "346271e8fe5d9f541d1ab71879f20461", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nobject Main {\n var `in`: IO? = null\n var out: PrintWriter? = null\n\n @Throws(Exception::class)\n fun init_io(filename: String) {\n if (filename == \"\") {\n `in` = IO(System.`in`)\n out = PrintWriter(BufferedWriter(OutputStreamWriter(System.out)), true)\n } else {\n `in` = IO(FileInputStream(\"$filename.in\"))\n out = PrintWriter(BufferedWriter(FileWriter(\"$filename.out\")), true)\n }\n }\n\n const val mod: Long = 998244353\n\n /*\nfun main(args: Array) {\n Main.main(args);\n}\n*/\n operator fun get(l: Long, r: Long): Long {\n if (l == r) return 0\n var x: Long = 1\n while (x * 2 <= r) x *= 2\n return if (l < x) x * 2 - 1 else get(l - x, r - x)\n }\n\n @Throws(Exception::class)\n fun solve(tc: Int) {\n val l = `in`!!.nlong()\n val r = `in`!!.nlong()\n out!!.println(get(l, r))\n }\n\n @Throws(Exception::class)\n @JvmStatic\n fun main(_u_n_u_s_e_d_: Array) {\n init_io(\"\")\n val t = 1\n // t = in.nint();\n for (tc in 0 until t) {\n solve(tc)\n }\n }\n\n fun minv(v: Long): Long {\n return mpow(v, mod - 2)\n }\n\n fun mpow(base: Long, exp: Long): Long {\n var base = base\n var exp = exp\n var res: Long = 1\n while (exp > 0) {\n if (exp and 1 == 1L) {\n res = res * base % mod\n }\n base = base * base % mod\n exp = exp shr 1\n }\n return res\n }\n\n fun gcd(x: Long, y: Long): Long {\n return if (x == 0L) y else gcd(y % x, x)\n }\n\n fun rsort(arr: LongArray) {\n val r = Random()\n for (i in arr.indices) {\n val j = i + r.nextInt(arr.size - i)\n val t = arr[i]\n arr[i] = arr[j]\n arr[j] = t\n }\n Arrays.sort(arr)\n }\n\n fun rsort(arr: IntArray) {\n val r = Random()\n for (i in arr.indices) {\n val j = i + r.nextInt(arr.size - i)\n val t = arr[i]\n arr[i] = arr[j]\n arr[j] = t\n }\n Arrays.sort(arr)\n }\n\n /* static void qsort(long[] arr) {\n Long[] oarr = new Long[arr.length];\n for (int i = 0; i < arr.length; i++) {\n oarr[i] = arr[i];\n }\n\n ArrayList alist = new ArrayList(Arrays.asList(oarr));\n Collections.sort(alist);\n\n for (int i = 0; i < arr.length; i++) {\n arr[i] = (long)alist.get(i);\n }\n } */\n fun reverse(arr: LongArray) {\n for (i in 0 until arr.size / 2) {\n val temp = arr[i]\n arr[i] = arr[arr.size - 1 - i]\n arr[arr.size - 1 - i] = temp\n }\n }\n\n fun atos(arr: LongArray?): String {\n var s = Arrays.toString(arr)\n s = s.substring(1, s.length - 1)\n return s.replace(\",\", \"\")\n }\n\n class IO(x: InputStream?) {\n var `in`: BufferedReader\n var tokens: StringTokenizer\n\n @Throws(Exception::class)\n fun nint(): Int {\n return nstr().toInt()\n }\n\n @Throws(Exception::class)\n fun nlong(): Long {\n return nstr().toLong()\n }\n\n @Throws(Exception::class)\n fun ndouble(): Double {\n return nstr().toDouble()\n }\n\n @Throws(Exception::class)\n fun nstr(): String {\n if (!tokens.hasMoreTokens()) tokens = StringTokenizer(`in`.readLine())\n return tokens.nextToken()\n }\n\n @Throws(Exception::class)\n fun nla(n: Int): LongArray {\n val arr = LongArray(n)\n for (i in 0 until n) {\n arr[i] = nlong()\n }\n return arr\n }\n\n init {\n `in` = BufferedReader(InputStreamReader(x))\n tokens = StringTokenizer(`in`.readLine())\n }\n }\n\n internal class Pair?, B : Comparable?>(var f: A, var s: B) : Comparable> {\n override fun compareTo(other: Pair): Int {\n val v = f!!.compareTo(other.f)\n return if (v != 0) v else s!!.compareTo(other.s)\n }\n\n override fun toString(): String {\n return \"(\" + f.toString() + \", \" + s.toString() + \")\"\n }\n\n }\n}\n\nfun main(args: Array) {\n Main.main(args);\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "bitmasks", "greedy", "implementation"], "code_uid": "60308cab5f9a09e2ba1ae6ce8a2cca6b", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val line = readLine()!!\n val six = line.indexOf(' ')\n val l = line.substring(0, six).toLong()\n val r = line.substring(six + 1).toLong()\n for (e in 60 downTo 0) {\n val b = 1L shl e\n if ((l and b) != (r and b)) {\n println((2L * b) - 1L)\n return\n }\n }\n println(0L)\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "bitmasks", "greedy", "implementation"], "code_uid": "e342be08ea332eb678c291532987d4a3", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val (r1, r2) = br.readLine().split(\" \").map { it.toInt() }\n val (c1, c2) = br.readLine().split(\" \").map { it.toInt() }\n val (d1, d2) = br.readLine().split(\" \").map { it.toInt() }\n val x4 = -(d2 - c2 - r2)/2\n val x3 = r2 - x4\n val x2 = d2 - x3\n val x1 = r1 - x2\n val sol = listOf(x1, x2, x3, x4)\n println(\n if (sol.all { it in (1..9) } && sol.toSet().size == sol.size &&\n -(d2 - c2 - r2) % 2 == 0) {\n \"$x1 $x2\\n$x3 $x4\"\n } else {\n \"-1\"\n }\n )\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "4ac62e7d3f6050d5e19ff2444c52cd0f", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (r1, r2) = readInts()\n val (c1, c2) = readInts()\n val (d1, d2) = readInts()\n nextAttempt@ for (tl in 1..9) {\n val tr = r1 - tl\n val bl = c1 - tl\n val br = d1 - tl\n val all = setOf(tl, tr, bl, br)\n if (all.size != 4) continue\n for (gem in all) if (gem !in 1..9) continue@nextAttempt\n if (r2 != bl + br) continue\n if (c2 != tr + br) continue\n if (d2 != tr + bl) continue\n println(\"$tl $tr\")\n return print(\"$bl $br\")\n }\n print(-1)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "32918e2f40f3235a48a57d2842331b5b", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation"], "code_uid": "dbd4cd360c6c95008af1cc46c3d800c7", "src_uid": "09601fd1742ffdc9f822950f1d3e8494", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation"], "code_uid": "6d03361bcfc057138395ef19e0546c4d", "src_uid": "09601fd1742ffdc9f822950f1d3e8494", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation"], "code_uid": "6d532fe906ea6a39b035b9d7eb47bd9d", "src_uid": "09601fd1742ffdc9f822950f1d3e8494", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation"], "code_uid": "b54a551c5c9c12a6f27736aa7512f194", "src_uid": "09601fd1742ffdc9f822950f1d3e8494", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 TreeMap.add(i:Char,x:Int){\n set(i,getOrDefault(i,0)+x)\n}\nfun main(){\n var a=Array(3){readLn().toCharArray()}\n var cnt=TreeMap()\n for(j in 0..2)for(i in a[j])cnt.add(i,1)\n var o=cnt.getOrDefault('0',0)\n var x=cnt.getOrDefault('X',0)\n if(o>x || x>o+1)printLine(\"illegal\")\n else{\n fun win(c:Char):Boolean{\n for(j in 0..2)if(a[j][0]==c&&a[j][1]==c&&a[j][2]==c)return true\n for(j in 0..2)if(a[0][j]==c&&a[1][j]==c&&a[2][j]==c)return true\n if(a[0][0]==c&&a[1][1]==c&&a[2][2]==c)return true\n if(a[2][0]==c&&a[1][1]==c&&a[0][2]==c)return true\n return false\n }\n if(win('X')&&win('0'))printLine(\"illegal\")\n else{\n if(win('X')){\n var ok=false\n for(i in 0..2)for(j in 0..2)if(a[i][j]=='X'){\n a[i][j]='.'\n if(!win('X'))ok=true\n a[i][j]='X'\n }\n if(ok&&x==o+1)printLine(\"the first player won\")\n else printLine(\"illegal\")\n }else if(win('0')){\n var ok=false\n for(i in 0..2)for(j in 0..2)if(a[i][j]=='0'){\n a[i][j]='.'\n if(!win('0'))ok=true\n a[i][j]='0'\n }\n if(ok&&x==o)printLine(\"the second player won\")\n else printLine(\"illegal\")\n }else{\n if(x+o==9)printLine(\"draw\")\n else if(x>o)printLine(\"second\")\n else printLine(\"first\")\n }\n }\n }\n output()\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "games"], "code_uid": "cfe26c4b72934ce6af8c854039e48fcc", "src_uid": "892680e26369325fb00d15543a96192c", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\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 PROBLEM\n\nprivate fun readProblem(readLine: () -> String?): Problem {\n val input = (readLine() + readLine() + readLine())\n return Problem(input.map(::charToPlayer))\n}\n\nprivate fun charToPlayer(c: Char): Player? {\n when (c) {\n 'X' -> return Player.X\n '0' -> return Player.O\n else -> return null\n }\n}\n\nprivate class Problem(val board: List) {\n override fun toString(): String {\n return board.joinToString(\" \")\n }\n\n fun countX(): Int {\n return board.filter { it == Player.X }.count()\n }\n\n fun countO(): Int {\n return board.filter { it == Player.O }.count()\n }\n\n fun hasThreeX(): Boolean {\n val xs = board.map { it == Player.X }\n return isWinning(xs)\n }\n\n fun hasThreeO(): Boolean {\n val os = board.map { it == Player.O }\n return isWinning(os)\n }\n\n private fun isWinning(b: List): Boolean {\n return (b[0] && b[1] && b[2])\n || (b[3] && b[4] && b[5])\n || (b[6] && b[7] && b[8])\n || (b[0] && b[3] && b[6])\n || (b[1] && b[4] && b[7])\n || (b[2] && b[5] && b[8])\n || (b[0] && b[4] && b[8])\n || (b[2] && b[4] && b[6])\n }\n}\n\nprivate enum class Player {\n X, O\n}\n\n// SOLVE PROBLEM\n\nprivate fun solve(prob: Problem): Solution {\n // x - it's the first player\n // o - it's the second player\n val xNo = prob.countX()\n val oNo = prob.countO()\n val xWon = prob.hasThreeX()\n val oWon = prob.hasThreeO()\n\n when {\n (xNo < oNo) -> return Solution.ILLEGAL\n (xNo > (oNo + 1)) -> return Solution.ILLEGAL\n (xWon && oWon) -> return Solution.ILLEGAL\n (xWon && (xNo > oNo)) -> return Solution.FIRST_WON\n (xWon) -> return Solution.ILLEGAL\n (oWon && (xNo == oNo)) -> return Solution.SECOND_WON\n (oWon) -> return Solution.ILLEGAL\n (xNo + oNo == 9) -> return Solution.DRAW\n (xNo == oNo) -> return Solution.FIRST\n (xNo > oNo) -> return Solution.SECOND\n else -> return Solution.ILLEGAL\n }\n}\n\n// PRINT SOLUTION\n\nprivate enum class Solution(val txt: String) {\n FIRST(\"first\"),\n SECOND(\"second\"),\n ILLEGAL(\"illegal\"),\n FIRST_WON(\"the first player won\"),\n SECOND_WON(\"the second player won\"),\n DRAW(\"draw\");\n\n fun print(consumer: (String) -> Unit) {\n consumer(txt)\n }\n}\n\nprivate fun printSolution(solution: Solution) {\n solution.print(::println)\n}\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "games"], "code_uid": "70e62397c15b33c6a919666f1adc7e83", "src_uid": "892680e26369325fb00d15543a96192c", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (_, numFriends) = readInts()\n val counts = IntArray(26)\n for (c in readLine()!!)\n counts[c - 'a']++\n for (c in counts)\n if (c > numFriends) return print(\"NO\")\n print(\"YES\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "073d5abc6f1f0408d14d2d24a74d8526", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val k = readLine()!!.split(' ')[1].toInt()\n val baloons = readLine()!!\n\n val groups = baloons.groupBy { it }\n val m = groups.values.map { it.size }.max() ?: 0\n println(if (k >= m) \"YES\" else \"NO\");\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "4bdcd5f558528595846792211804d88a", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport 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}\nval cin =BufferedReader(InputStreamReader(System.`in`))\nvar tok = StringTokenizer(\"\")\nfun readString(): String {\n while (!tok.hasMoreTokens()) {\n tok = StringTokenizer(cin!!.readLine())\n }\n return tok.nextToken()\n}\n\nfun solve() {\n\n\n /*\n var map=hashMapOf();\n map[q] <=> map.getOrDefault(q,0)\n \u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u043f\u0430\u0440 - k=v.sortedWith(compareBy({it.first},{it.second}));\n prLong(\"${k[i].second}\"); - \u0432\u044b\u0432\u043e\u0434 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043f\u0430\u0440\u044b\n var m=ArrayList (); <=> vector\n getline(cin,a) <=> readLine()!!.last()\n readLong() - \u043e\u0434\u043d\u043e \u0447\u0438\u0441\u043b\u043e\n readLongs() - \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u0435\u043b\n readLine()!!.toCharArray() - \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0447\u0430\u0440\u043e\u0432 \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438\n\n */\n /* --------- */\n // \u0412\u0421\u0415\u0413\u0414\u0410 \u041f\u0418\u0421\u0410\u0422\u042c \u0412 \u041b\u041e\u041d\u0413\u0410\u0425\n var (a,k)=readLongs();\n var s=readString();\n var check=1;\n var q=IntArray(100);\n for (i in 0..a-1) {\n var w=(s[i.toInt()]-'a').toInt();\n q[w]++;\n if (q[w]>k) {check=0; }\n }\n if (check==1) print(\"YES\"); else print(\"NO\");\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", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "cbfe8cb394b470265c59b149e9bcce69", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun main() {\n val (n, k) = readLine()!!.split(' ').map(String::toInt)\n val balloon = readLine()!!\n\n val groupBy = balloon.groupBy { it }\n println(if (groupBy.values.map { it.size }.max()!! <= k ) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "aa28d2dfd75bfe8a05666572258ac8e6", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport java.lang.Integer.min\n \nfun main() {\n val a = readLine()?.toInt() ?: 0\n val b = readLine()?.toInt() ?: 0\n val c = readLine()?.toInt() ?: 0\n val d = readLine()?.toInt() ?: 0\n val e = readLine()?.toInt() ?: 0\n val f = readLine()?.toInt() ?: 0\n // a d\n // b c d\n if (e > f) {\n val n1 = min(a, d)\n println(n1 * e + f * min(b, min(c, d - n1)))\n } else {\n val n2 = min(min(b, c), d)\n println(n2 * f + e * min(a, d - n2))\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "brute force"], "code_uid": "a7ad636294661e993466819b547bdf51", "src_uid": "84d9e7e9c9541d997e6573edb421ae0a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n val a = r.readLine()!!.toInt()\n val b = r.readLine()!!.toInt()\n val c = r.readLine()!!.toInt()\n val d = r.readLine()!!.toInt()\n val e = r.readLine()!!.toInt()\n val f = r.readLine()!!.toInt()\n val t1 = minOf(a, d)\n val t2 = minOf(b, c, d-t1)\n val p2 = minOf(b, c, d)\n val p1 = minOf(a, d-p2)\n val ans = maxOf(t1*e+t2*f, p1*e+p2*f)\n println(ans)\n //val v = r.readLine()!!.split(\"\").filter { it.isNotEmpty() }\n //val (action, remain) = r.readLine()!!.split(\" \").map { it.toLong() }\n\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}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "brute force"], "code_uid": "edfe84f1d8c43e627f7e4500db8d4988", "src_uid": "84d9e7e9c9541d997e6573edb421ae0a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n\n val numTies = readInt()\n val numScarves = readInt()\n val numVests = readInt()\n val numJackets = readInt()\n val tieJacketCost = readInt()\n val scarfVestJacket = readInt()\n if (tieJacketCost >= scarfVestJacket) {\n val numExpensive = min(numTies, numJackets)\n val numCheap = min(numScarves, min(numVests, numJackets - numExpensive))\n print(numExpensive * tieJacketCost + numCheap * scarfVestJacket)\n } else {\n val numExpensive = min(numScarves, min(numVests, numJackets))\n val numCheap = min(numTies, numJackets - numExpensive)\n print(numExpensive * scarfVestJacket + numCheap * tieJacketCost)\n\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "brute force"], "code_uid": "bea12f86de8a749c12cac529067609cd", "src_uid": "84d9e7e9c9541d997e6573edb421ae0a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.abs\n\nfun main() {\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 var a: Long = inp.nextInt().toLong()\n var b: Long = inp.nextInt().toLong()\n var c: Long = inp.nextInt().toLong()\n var d: Long = inp.nextInt().toLong()\n var e: Long = inp.nextInt().toLong()\n var f: Long = inp.nextInt().toLong()\n var ans = 0L\n if (e >= f) {\n val min = minOf(a, d)\n ans += min * e\n d -= min\n a -= min\n }\n val min = minOf(b, c, d)\n ans += min * f\n d -= min\n ans += minOf(a, d) * e\n out.println(ans)\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}\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "brute force"], "code_uid": "5820c5a7d52552a9abfb602257f98ced", "src_uid": "84d9e7e9c9541d997e6573edb421ae0a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val res = IntArray(3, { nextInt() }).sortedArray().meetsConditions()\n print(res)\n}\n\nfun IntArray.meetsConditions(): String {\n return when {\n this[0] == 1 -> \"YES\"\n this[0] == 2 && this[1] == 2 -> \"YES\"\n this[0] == 2 && this[1] == 4 && this[2] == 4 -> \"YES\"\n this[0] == 3 && this[2] == 3 -> \"YES\"\n else -> \"NO\"\n }\n}\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms"], "code_uid": "ebfdbda2cbe46b5b991712bcf660c192", "src_uid": "df48af9f5e68cb6efc1214f7138accf9", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array): Unit = with(Scanner(System.`in`)) {\n val array: Array = arrayOf(nextInt(), nextInt(), nextInt())\n array.sort()\n when {\n (array[0] == 1).toInt() + (array[1] == 1).toInt() + (array[2] == 1).toInt() >= 1 -> println(\"YES\")\n (array[0] == 2).toInt() + (array[1] == 2).toInt() + (array[2] == 2).toInt() >= 2 -> println(\"YES\")\n (array[0] == 3).toInt() + (array[1] == 3).toInt() + (array[2] == 3).toInt() == 3 -> println(\"YES\")\n array[0] == 2 && array[1] == 4 && array[2] == 4 -> println(\"YES\")\n else -> println(\"NO\")\n\n }\n}\n\nfun Boolean.toInt() = if (this) 1 else 0\n", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms"], "code_uid": "0b16597ff60e0591be1c352c14d41250", "src_uid": "df48af9f5e68cb6efc1214f7138accf9", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "const val MOD = 998244353L\n\nfun main() {\n val n = readLine()!!.toInt()\n val dp = LongArray(n + 1)\n for (f in 1..n) {\n for (k in f..n step f) {\n dp[k]++\n }\n }\n var prev = 0L\n for (k in 1..n) {\n dp[k] += prev\n if (dp[k] >= MOD) {\n dp[k] -= MOD\n }\n prev += dp[k]\n if (prev >= MOD) {\n prev -= MOD\n }\n }\n println(dp[n])\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "6307e5d86583ae4dc765026bbaca21a9", "src_uid": "09be46206a151c237dc9912df7e0f057", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.io.BufferedReader\r\n\r\nfun main() {\r\n val br = System.`in`.bufferedReader()\r\n val n = br.readInt()\r\n val sieve = IntArray(n + 1) { 1 }\r\n val mod = 998244353L\r\n for (x in 2..n) {\r\n if (sieve[x] == 1) {\r\n sieve[x] = x\r\n var i = x\r\n while (i <= n) {\r\n sieve[i] = x\r\n i += x\r\n }\r\n\r\n }\r\n }\r\n val dp1 = LongArray(n + 1) { x ->\r\n var i = x\r\n var numFactors = 1L\r\n if (x == 100) {\r\n i *= 1\r\n }\r\n while (sieve[i] != 1) {\r\n val check = sieve[i]\r\n var ct = 0\r\n while (sieve[i] == check) {\r\n i /= sieve[i]\r\n ct++\r\n }\r\n numFactors *= ct + 1\r\n }\r\n numFactors % mod\r\n }\r\n dp1[0] = 0\r\n val ans = LongArray(n + 1)\r\n\r\n var p = 0L\r\n for (x in 1..n) {\r\n ans[x] = (dp1[x] + p) % mod\r\n p += ans[x]\r\n p %= mod\r\n }\r\n\r\n print(ans.last())\r\n\r\n}\r\n\r\nprivate const val SPACE_INT = ' '.toInt()\r\nprivate const val ZERO_INT = '0'.toInt()\r\nprivate const val NL_INT = '\\n'.toInt()\r\n\r\nprivate fun BufferedReader.readInt(): Int {\r\n var ret = read()\r\n while (ret <= SPACE_INT) {\r\n ret = read()\r\n }\r\n val neg = ret == '-'.toInt()\r\n if (neg) {\r\n ret = read()\r\n }\r\n ret -= ZERO_INT\r\n var read = read()\r\n while (read >= ZERO_INT) {\r\n ret *= 10\r\n ret += read - ZERO_INT\r\n read = read()\r\n }\r\n\r\n while (read <= SPACE_INT && read != -1 && read != NL_INT) {\r\n mark(1)\r\n read = read()\r\n }\r\n if (read > SPACE_INT) {\r\n reset()\r\n }\r\n return if (neg) -ret else ret\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "b33eb50f7f96058168f40d9e59bbb45f", "src_uid": "09be46206a151c237dc9912df7e0f057", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.lang.AssertionError\r\nimport java.util.Scanner\r\nprivate fun readLn() = readLine()!! // string line\r\nprivate fun readInt() = readLn().toInt() // single int\r\nprivate fun readLong() = readLn().toLong() // single long\r\nprivate fun readDouble() = readLn().toDouble() // single double\r\nprivate fun readStrings() = readLn().split(\" \") // list of strings\r\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\r\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\r\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\r\n\r\nfun main(args: Array)\r\n{\r\n\tval sc = Scanner(System.`in`)\r\n val MOD: Long = 998244353\r\n var t:Int = 1\r\n \r\n while(t>0)\r\n {\r\n \r\n var n = readInt()\r\n var dp = LongArray(n+9)\r\n var sum = LongArray(n+9)\r\n var cnt = LongArray(n+9)\r\n \r\n for(i in 1..n)\r\n {\r\n cnt[i] = 0\r\n }\r\n for(i in 1..n)\r\n {\r\n var j = i\r\n while(j<=n){\r\n cnt[j]++\r\n j+=i\r\n }\r\n }\r\n \r\n dp[0] = 1; dp[1] = 1; sum[1] = 1;\r\n for(i in 2..n)\r\n {\r\n dp[i] = cnt[i]\r\n dp[i]+=sum[i-1]; dp[i]%=MOD\r\n sum[i] = (sum[i-1]+dp[i])%MOD\r\n }\r\n \r\n println(dp[n])\r\n \r\n t--\r\n }\r\n \r\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "9f96a7eaeff1a68a617d2e0c51dcb552", "src_uid": "09be46206a151c237dc9912df7e0f057", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.io.BufferedReader\r\nimport java.util.*\r\nimport kotlin.math.sqrt\r\n\r\nval MA = ModuloArithmetic(998_244_353)\r\nfun Int.ma() = MA.ofInt(this)\r\n\r\nval bin = System.`in`.bufferedReader()\r\nfun BufferedReader.readInt() = this.readLine()!!.toInt()\r\n\r\n@ExperimentalUnsignedTypes\r\nfun main() {\r\n println(solve(bin.readInt()))\r\n}\r\n\r\n@ExperimentalUnsignedTypes\r\nfun solve(n: Int): IntMod {\r\n if (n == 1) {\r\n return 1.ma()\r\n }\r\n val primes = primesUpTo(n)\r\n\r\n var sum = 1.ma()\r\n var last = 1.ma()\r\n for (i in 2..n) {\r\n last = sum + numDivisors(i, primes)\r\n sum += last\r\n }\r\n return last\r\n}\r\n\r\nclass ModuloArithmetic(private val MOD: Int) {\r\n\r\n fun ofInt(x: Int) = IntMod(x, MOD)\r\n fun ofLong(x: Long) = IntMod((x % MOD).toInt(), MOD)\r\n\r\n fun precomputeFactorials(n: Int) = PrecomputedFactorials(n, MOD)\r\n\r\n fun factorial(n: Int): IntMod {\r\n var res = ofInt(1)\r\n for (i in 1..n) {\r\n res *= i\r\n }\r\n return res\r\n }\r\n\r\n /**\r\n * n choose k, picking k elements from a set of n element, without repetitions\r\n *\r\n * / n \\\r\n * | |\r\n * \\ k /\r\n */\r\n fun choose(n: Int, k: Int): IntMod {\r\n if (k > n || n <= 0) return ofInt(0)\r\n if (k == 0 || k == n) return ofInt(1)\r\n\r\n return factorial(n) / (factorial(k) * factorial(n-k))\r\n }\r\n\r\n /**\r\n * n multichoose k, i.e. picking k elements from a set of n element, *with* repetitions, order does not matter.\r\n */\r\n fun multichoose(n: Int, k: Int): IntMod = choose(n+k-1, k)\r\n\r\n /**\r\n * / n \\\r\n * | |\r\n * \\ k_1, ... k_m /\r\n *\r\n * Number of ways of putting n distinct objects into m distinct bins\r\n * with k_i objects in the i'th bin\r\n */\r\n fun multinomial(n: Int, ks: List): IntMod {\r\n var res = factorial(n)\r\n for (k in ks) {\r\n res /= factorial(k)\r\n }\r\n return res\r\n }\r\n\r\n /**\r\n * Number of distinct ways of shuffling values [vs] (distinct = some value on some position differs).\r\n */\r\n fun numWayToShuffle(vs: List): IntMod {\r\n val f = mutableMapOf()\r\n for (v in vs) {\r\n f.merge(v, 1, Int::plus)\r\n }\r\n return multinomial(vs.size, f.values.toList())\r\n }\r\n}\r\n\r\nclass IntMod(n: Int, private val MOD: Int) {\r\n val i = n % MOD\r\n\r\n fun ofInt(x: Int) = IntMod(x, MOD)\r\n fun ofLong(x: Long) = IntMod((x % MOD).toInt(), MOD)\r\n\r\n operator fun plus(other: IntMod): IntMod = IntMod(Math.floorMod(i + other.i, MOD), MOD)\r\n operator fun plus(other: Int): IntMod = this + ofInt(other)\r\n operator fun plus(other: Long): IntMod = this + ofLong(other)\r\n\r\n operator fun minus(other: IntMod): IntMod = IntMod(Math.floorMod(i - other.i, MOD), MOD)\r\n operator fun minus(other: Int): IntMod = this - ofInt(other)\r\n operator fun minus(other: Long): IntMod = this - ofLong(other)\r\n\r\n operator fun times(other: IntMod): IntMod = IntMod(Math.floorMod(i.toLong() * other.i, MOD.toLong()).toInt(), MOD)\r\n operator fun times(other: Int): IntMod = this * ofInt(other)\r\n operator fun times(other: Long): IntMod = this * ofLong(other)\r\n\r\n operator fun div(other: IntMod): IntMod = this * other.multiplicativeInverse()\r\n operator fun div(other: Int): IntMod = this / ofInt(other)\r\n operator fun div(other: Long): IntMod = this / ofLong(other)\r\n\r\n override fun toString(): String = i.toString()\r\n\r\n // i^n\r\n fun pow(n_in: Long): IntMod {\r\n var x = this\r\n var y = ofInt(1)\r\n var n = n_in\r\n // x^n\r\n while (n > 0) {\r\n if (n % 2L != 0L) y *= x\r\n n /= 2\r\n x *= x\r\n }\r\n return y\r\n }\r\n\r\n private fun multiplicativeInverse(): IntMod = pow(MOD-2L)\r\n}\r\n\r\nclass PrecomputedFactorials(val n: Int, val MOD: Int) {\r\n val fact = Array(n+1) { IntMod(1, MOD) }\r\n val invFact = Array(n+1) { IntMod(1, MOD) }\r\n\r\n init {\r\n var f = IntMod(1, MOD)\r\n for (i in 1..n) {\r\n f *= i\r\n fact[i] = f\r\n invFact[i] = IntMod(1, MOD) / f\r\n }\r\n }\r\n\r\n fun fact(i: Int) = fact[i]\r\n\r\n fun choose(n: Int, k: Int) = when {\r\n k > n -> IntMod(0, MOD)\r\n n < 0 -> IntMod(0, MOD)\r\n else -> fact[n] * invFact[n - k] * invFact[k]\r\n }\r\n\r\n fun multichoose(n: Int, k: Int) = choose(n+k-1, k)\r\n}\r\n\r\n/**\r\n * Returns number of divisors for a given [n_in].\r\n * [primes] must contain all prime numbers at least up to [sqrt(n_in)].\r\n */\r\nfun numDivisors(n_in: Int, primes: IntArray): Int {\r\n var res = 1\r\n var i = 0\r\n var n = n_in\r\n while (i < primes.size && primes[i]*primes[i] <= n) {\r\n var power = 0\r\n while (n % primes[i] == 0) {\r\n n /= primes[i]\r\n power++\r\n }\r\n res *= power+1\r\n i++\r\n }\r\n return if (n != 1) 2*res else res\r\n}\r\n\r\n@ExperimentalUnsignedTypes\r\nfun primesUpTo(max: Int): IntArray {\r\n val isPrime = BitArray(max+1, true)\r\n val primes = mutableListOf()\r\n for (i in 2..max) {\r\n if (isPrime[i]) {\r\n primes.add(i)\r\n if (i.toLong() * i <= max) {\r\n for (j in i * i..max step i) {\r\n isPrime[j] = false\r\n }\r\n }\r\n }\r\n }\r\n\r\n var nextPrime = max\r\n while (!isPrime(nextPrime, primes.asIterable())) nextPrime++\r\n primes.add(nextPrime)\r\n\r\n return primes.toIntArray()\r\n}\r\n\r\n/**\r\n * Faster rewrite of [BitSet].\r\n */\r\n@ExperimentalUnsignedTypes\r\nclass BitArray(val size: Int, init: Boolean = false) {\r\n val vs = UByteArray(((size+1) shr 3) + 1) { if (init) 0xFF.toUByte() else 0.toUByte() }\r\n\r\n operator fun get(i: Int): Boolean = vs[i shr 3] and (1 shl (i and 0x07)).toUByte() != 0.toUByte()\r\n\r\n operator fun set(i: Int, v: Boolean) = if (v) set(i) else clear(i)\r\n\r\n fun set(i: Int) {\r\n vs[i shr 3] = vs[i shr 3] or (1 shl (i and 0x07)).toUByte()\r\n }\r\n\r\n fun clear(i: Int) {\r\n vs[i shr 3] = vs[i shr 3] and (1 shl (i and 0x07)).toUByte().inv()\r\n }\r\n}\r\n\r\n/**\r\n * Returns true iff [n] is prime.\r\n */\r\nfun isPrime(n: Long, primes: Iterable = 2..longSqrt(n).toInt()): Boolean {\r\n if (n <= 1L) return false\r\n\r\n for (p in primes) {\r\n if (p.toLong() * p > n) return true\r\n if (n % p == 0L) return false\r\n }\r\n\r\n throw Error(\"Could not determine if $n is prime\")\r\n}\r\n\r\nfun isPrime(n: Int, primes: Iterable = 2..intSqrt(n)) =\r\n isPrime(n.toLong(), primes)\r\n\r\nfun longSqrt(i: Long): Long = (sqrt(i.toDouble()) + 1).toLong()\r\nfun intSqrt(i: Int): Int = (sqrt(i.toDouble()) + 1).toInt()\r\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "d254a02de820fc58ed3b7c721b8816a3", "src_uid": "09be46206a151c237dc9912df7e0f057", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "0677d22496ca5ff3ca680a6c558d5bf5", "src_uid": "6994331ca6282669cbb7138eb7e55e01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "89d64e51bc829ba1c8ee8f1918adc6d3", "src_uid": "6994331ca6282669cbb7138eb7e55e01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c20f77b516ecb3bc15781f4f7f10a3a3", "src_uid": "6994331ca6282669cbb7138eb7e55e01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "ccea9333f5d73a45d5c3ed97edfed6e3", "src_uid": "6994331ca6282669cbb7138eb7e55e01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "e4698f1cd5f4e7dea5129c7c2ce64348", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "bcd74a94e613ac2357936023f4f4659d", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toLong()\n\n if(n > 0) {\n println(n)\n } else {\n val op1 = n / 10L\n val op2 = ((n / 100) * 10) + (n % 10)\n \n if(op1 > op2)\n println(op1)\n else\n println(op2)\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "2e4fa44b90430aa871bfcf7566734a3d", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 = scanner.nextInt()\n if (q >= 0)\n println(q)\n else\n print(max((q / 100) * 10 + q % 10, (q / 10)))\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//}", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "dc8b69732df00fcd393cc8fa0e31f3b7", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 if (n >= 0) {\n io.println(n)\n } else {\n val x = -n\n val res = Math.min(x / 10, ((x / 100) * 10) + (x % 10))\n io.println(-res)\n }\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "4ecb062cec244c3a8f3f99fd19a67fa0", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main()\n{\n var n = readLine()!!.toInt()\n var answer = n\n if (n / 10 > answer) answer = n / 10\n val opt1 = (n % 10) + (n / 100) * 10\n if (opt1 > answer) answer = opt1\n println(answer)\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "fadb6278a450cd6fd20479ac2b7d71cf", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun readInts() : List {\n val x_nullable_str = readLine()\n if (x_nullable_str == null) {\n throw Exception(\"Could not read ints.\")\n } else {\n val x_str = x_nullable_str\n val xs = x_str.split(' ').map(String::toInt)\n return xs\n }\n}\n\nfun main(args : Array) {\n val n_m = readInts()\n val n = n_m[0]\n val m = n_m[1]\n val min_moves = (n + 1) / 2\n val a = min_moves / m\n val a_m = a * m\n if (a_m == min_moves) {\n println(\"${a_m}\")\n } else {\n val a_plus_1_m = (a + 1) * m\n if (a_plus_1_m > n) {\n println(\"-1\")\n } else {\n println(\"${a_plus_1_m}\")\n }\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "590850b4b42655cb148e08ece4b7ec08", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 min = (n + 1) / 2\n var p = false\n for (i in min..n){\n if (i%m==0){\n println(i)\n p = true\n break\n }\n }\n if (!p) println(-1)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "0d2b1918f362babc47cd14e3acba9081", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * Created by tux on 31.12.16.\n */\n\nfun main(args: Array) {\n val T = readLine()!!.split(\" \").map { Integer.parseInt(it) }\n if (T[1] > T[0]) {\n println(-1)\n return\n }\n\n val div = T[0] / 2\n val rest = if (T[0] % 2 == 0 && div % T[1] == 0) 0 else (div / T[1] + 1) * T[1] - div\n println(div + rest)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "38c621566dbd07af32d6b79e6ba2f5c1", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, m) = readInts()\n val min = n / 2 + n % 2\n if (n < m) println(-1)\n else println(if (min % m == 0) min else min + (m - min % m))\n}\n\nprivate fun readInts() = readLine()!!.split(\" \").map { it.toInt() }", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "f7e850f1b428f2d8d52e743bdfd07f6a", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "class TransitionMatrix {\n val matrix : Array\n\n init {\n this.matrix = Array(4, {_ -> LongArray(4, {_ -> 0L})})\n }\n\n operator fun get(i : Int, j : Int) : Long {\n return this.matrix[i][j]\n }\n\n private operator fun set(i : Int, j : Int, x : Long) {\n this.matrix[i][j] = x\n }\n\n operator fun times(other : TransitionMatrix) : TransitionMatrix {\n val modulo = 1000000007L\n val result = TransitionMatrix()\n for (i in 0 .. 3) {\n for (j in 0 .. 3) {\n var x = 0L\n for (k in 0 .. 3) {\n x = (x + (this[i,k] * other[k,j])) % modulo\n }\n result[i,j] = x\n }\n }\n return result\n }\n\n companion object {\n fun identity() : TransitionMatrix {\n val result = TransitionMatrix()\n result[0,0] = 1L\n result[1,1] = 1L\n result[2,2] = 1L\n result[3,3] = 1L\n return result\n }\n\n fun ant() : TransitionMatrix {\n val result = TransitionMatrix()\n for (i in 0 .. 3) {\n for (j in 0 .. 3) {\n result[i,j] = 1L\n }\n }\n result[0,0] = 0L\n result[1,1] = 0L\n result[2,2] = 0L\n result[3,3] = 0L\n return result\n }\n }\n}\n\nfun num_paths(n : Int) : Long {\n fun raise_to(t : TransitionMatrix, x : Int) : TransitionMatrix {\n if (x == 0) {\n val result = TransitionMatrix.identity()\n return result\n } else if ((x % 2) == 0) {\n val t_sqr = t * t\n val x_div_2 = x / 2\n val result = raise_to(t_sqr, x_div_2)\n return result\n } else {\n val t_sqr = t * t\n val x_minus_1_div_2 = (x - 1) / 2\n val result = t * raise_to(t_sqr, x_minus_1_div_2)\n return result\n }\n }\n val t_matrix = TransitionMatrix.ant()\n val result = raise_to(t_matrix, n)\n return result[0,0]\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 result = num_paths(n)\n println(\"${result}\")\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "matrices", "dp"], "code_uid": "310b5261d1cbc8686721393bf7436930", "src_uid": "77627cc366a22e38da412c3231ac91a8", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!.toInt()\n val mod = 1000000007L\n var d = 1L\n var m = 0L\n for (i in 1..n) {\n val newD = (3 * m) % mod\n val newM = (d + 2 * m) % mod\n d = newD\n m = newM\n }\n println(d)\n}", "lang_cluster": "Kotlin", "tags": ["math", "matrices", "dp"], "code_uid": "e2de2da4f2e3a8946dee43723f4d4935", "src_uid": "77627cc366a22e38da412c3231ac91a8", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = r.readLine()!!.toInt()\n val mod = 1000000007L\n var stayOnD = 0L\n var stayOnABC = 3L\n repeat(n - 1) {\n stayOnABC = (stayOnD * 3 + stayOnABC * 2) % mod\n .also { stayOnD = (stayOnABC) % mod }\n }\n println(stayOnD)\n}", "lang_cluster": "Kotlin", "tags": ["math", "matrices", "dp"], "code_uid": "d0b7517def06f2dd7f06798876e4a214", "src_uid": "77627cc366a22e38da412c3231ac91a8", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\n\nval oneFx = arrayOf(\n longArrayOf(1, 0, 0, 0),\n longArrayOf(0, 1, 0, 0),\n longArrayOf(0, 0, 1, 0),\n longArrayOf(0, 0, 0, 1)\n)\n\nval stepFx = arrayOf(\n longArrayOf(0, 1, 1, 1),\n longArrayOf(1, 0, 1, 1),\n longArrayOf(1, 1, 0, 1),\n longArrayOf(1, 1, 1, 0)\n)\n\nfun mult(a: Array, b: Array): Array {\n val result = arrayOf(\n longArrayOf(0, 0, 0, 0),\n longArrayOf(0, 0, 0, 0),\n longArrayOf(0, 0, 0, 0),\n longArrayOf(0, 0, 0, 0)\n )\n\n (0..3).forEach { k ->\n (0..3).forEach { i ->\n (0..3).forEach { j ->\n result[i][j] = (result[i][j] + a[i][k] * b[k][j]) % 1000000007\n }\n }\n }\n\n return result\n}\n\nfun main() {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n var n = reader.readLine().toInt()\n\n var fx = oneFx\n var pow = stepFx\n\n while (n > 0) {\n if (n % 2 == 1) { fx = mult(fx, pow) }\n pow = mult(pow, pow)\n n /= 2\n }\n\n println(fx[0][0])\n}", "lang_cluster": "Kotlin", "tags": ["math", "matrices", "dp"], "code_uid": "4383c4ebd0dab5bc8a6351503f66176b", "src_uid": "77627cc366a22e38da412c3231ac91a8", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 var (r,b) = readInts()\n val diff = min(r,b)\n r -= diff\n b -= diff\n println(\"$diff ${r /2 + b /2}\")\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "3727b2807edb7a3ae32933bba04fb50b", "src_uid": "775766790e91e539c1cfaa5030e5b955", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var num = readLine()!!.split(' ')!!.map { it.toInt() }.toTypedArray().toIntArray()\n print(\"${num.min()} \")\n var i = 0\n while (num[0] != 0 && num[1] != 0){\n num[0]--\n num[1]--\n }\n if (num[0] == 0)\n i = num[1]/2\n else\n i = num[0]/2\n println(\"$i\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "e2572e5e211d11a67d052d93bf08c3e2", "src_uid": "775766790e91e539c1cfaa5030e5b955", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\nimport kotlin.math.min\n\nfun main() {\n var (a, b) = readLine()!!.split(\" \").map { it.toInt() }\n print(min(a, b))\n print(\" \")\n print(abs(a - b) / 2)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "bbcc9da22903296e4bce8d9126930028", "src_uid": "775766790e91e539c1cfaa5030e5b955", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array){\n val (B,R) = readLine()!!.split(' ')\n if(R.toInt() >= B.toInt()){\n print(B+\" \"+(R.toInt()-B.toInt())/2)\n }else{\n print(R+\" \"+(B.toInt()-R.toInt())/2)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "01913f7a70865598c5a91e03c3efc616", "src_uid": "775766790e91e539c1cfaa5030e5b955", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "aa2a7c3e5eb80a4984e925b42fcbc3b7", "src_uid": "a83144ba7d4906b7692456f27b0ef7d4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "040a2eae69a14b9a60cc387e50f6d735", "src_uid": "a83144ba7d4906b7692456f27b0ef7d4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "5caf2658c941824bb2bc7da373571565", "src_uid": "a83144ba7d4906b7692456f27b0ef7d4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "462d558310b312ecf679d412713b10c8", "src_uid": "a83144ba7d4906b7692456f27b0ef7d4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.lang.*\nimport java.util.*\nfun main(args: Array) {\n val `in` = BufferedReader(InputStreamReader(System.`in`))\n val st = StringTokenizer(`in`.readLine())\n val p = Integer.parseInt(st.nextToken())\n val y = Integer.parseInt(st.nextToken())\n var done = false\n for (i in y downTo p + 1) {\n val b = (2..p)\n .takeWhile { it * it <= i }\n .any { i % it == 0 }\n if (!b) {\n done = true\n println(i)\n break\n }\n }\n if (!done)\n println(\"-1\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "f012dd7385ca328bf0589d977bf34766", "src_uid": "b533203f488fa4caf105f3f46dd5844d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n with(Scanner(System.`in`)) {\n val p = nextInt()\n val y = nextInt()\n\n for (i in y downTo p+1) {\n val isPrime = fun(x: Int): Boolean {\n var j = 2\n while (j*j<=y && j<=p) {\n if (x%j == 0) return false\n j++\n }\n return true\n }\n if (isPrime(i)) {\n println(i)\n return\n }\n }\n println(-1)\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "76bc438d06175bfac0e21c79c5d02781", "src_uid": "b533203f488fa4caf105f3f46dd5844d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.system.exitProcess\n\nfun main(){\n var s = readLine()!!.split(' ')\n var p = s[0].toInt()\n var y = s[1].toInt()\n for(x in y downTo p + 1) {\n var ok = true\n for(i in 2..p){\n if(x % i == 0){\n ok = false\n break\n }\n if(i * i >= x) break\n }\n if(ok){\n print(x)\n exitProcess(0)\n }\n }\n print(-1)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "e4ef509434c213176e1abf66923b71a3", "src_uid": "b533203f488fa4caf105f3f46dd5844d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 p = reader.nextInt()\n val y = reader.nextInt()\n\n if (p == y) {\n writer.print(\"-1\")\n return\n }\n\n for (i in (p + 1..y).reversed()) {\n var j = 2\n while (j * j <= i) {\n if (i % j == 0) {\n if (j > p) {\n writer.println(i)\n return\n }\n break\n }\n j++\n }\n// writer.println(\"$j -> $i\")\n if (j * j > i) {\n writer.println(i)\n return\n }\n }\n writer.print(\"-1\")\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", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "6cb8e21054d0f90b5232afd35dbefcbb", "src_uid": "b533203f488fa4caf105f3f46dd5844d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\nfun main(arg: Array){\n\tval sq = readLine()!!.toInt()\n\tval h = sqrt(sq.toDouble()).toInt()\n\tvar w = sq/h\n\tif(sq.rem(h) > 0) w++\n\tprintln(h+w)\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "binary search"], "code_uid": "e2fd5a56c9ebc06c443f976e9fb46914", "src_uid": "eb8212aec951f8f69b084446da73eaf7", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n solve()\n}\n\nprivate fun read(delimit: Char = ' ') = readLine()!!.split(delimit)\nprivate fun solve() {\n val (n) = read().map(String::toLong)\n var r = 1L\n var c = 1L\n var count = 2\n\n while (r * c < n) {\n if (r == c) {\n c++\n } else {\n r++\n }\n count++\n }\n\n println(count)\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "binary search"], "code_uid": "179a546bbd4dbc224e4e4bc168324cbe", "src_uid": "eb8212aec951f8f69b084446da73eaf7", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Math.sqrt\n\nfun main(args: Array) {\n val s = readLine()?.split(' ')\n val w = s!![0].toInt()\n val q = sqrt(w.toDouble()).toInt()\n val result: Int\n result = if (q * q >= w)\n (q + q)\n else {\n if (q * (q + 1) >= w)\n (q + q + 1)\n else\n (q + 1 + q + 1)\n }\n print(result)\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "binary search"], "code_uid": "38ca4fe4cd16ec4097408919ab8d6063", "src_uid": "eb8212aec951f8f69b084446da73eaf7", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n//package `codeforces-parser`.`1099-kotlin`.B\n\nvar _debug = false;\nfun debug(vararg vals: T): Unit {\n if (!_debug) { return }\n for (v in vals) { System.err.print(v); System.err.print(\" \") }\n System.err.println()\n}\n\n\nfun main(args: Array) {\n if (args.size > 0 && args[0] == \"-d\") {\n _debug = true;\n }\n\n val n = readLine()!!.toInt()\n\tvar (a, b) = arrayOf(1, 1)\n\n\tvar flag = false\n while (a * b < n) {\n a += if (flag) 1 else 0\n b += if (!flag) 1 else 0\n flag = !flag\n }\n\n println(a + b)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "binary search"], "code_uid": "07c4249a9159f01e19955ce91df35b96", "src_uid": "eb8212aec951f8f69b084446da73eaf7", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n\n val x = solve(n)\n println(x.size)\n x.forEach { println(it) }\n\n}\n\nfun solve(n: Int) = (1..200)\n .filter {n - it > 0 && (n - it).digits() == it }\n .map { n - it }\n .sorted()\n\nfun Int.digits(): Int {\n var sum = 0\n var x = this\n while (x > 0) {\n sum += x % 10\n x /= 10\n }\n return sum\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "a288270ff44cf054095b5f86570aecad", "src_uid": "ae20ae2a16273a0d379932d6e973f878", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val (n, d) = readInts()\n val s = readLn()\n\n var cur = 0\n var jumps = 0\n while (cur < n - 1) {\n var jumped = false\n for (i in (cur + d) downTo (cur + 1)) {\n// println(\"$cur $i $d\")\n if (i >= n) {\n continue\n }\n if (s[i] == '1') {\n cur = i\n jumps++\n jumped = true\n// println(\"jump $cur $i\")\n break\n }\n }\n if (!jumped) {print(-1); return}\n }\n\n print(jumps)\n}\n\n", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "greedy", "dp", "implementation"], "code_uid": "88703cd8d5aff1552a128eaac689cba9", "src_uid": "c08d2ecdfc66cd07fbbd461b1f069c9e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.sqrt\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n\n val n = readInt()\n var a = sqrt(n.toFloat()).toInt() + 1\n while (--a >= 0)\n if (n % a == 0) return print(\"$a ${n / a}\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "1689c8e0d2d711315c2a98291b4de7f9", "src_uid": "f52af273954798a4ae38a1378bfbf77a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport kotlin.math.*\n\nfun main() {\n io.apply {\n\n val n = int\n var w = 1\n var x = 2\n while (x * x <= n) {\n if (n % x == 0) {\n w = x\n }\n x++\n }\n\n cout .. w .. n / w .. 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", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "c7499c384725fa1006b344a9167926e2", "src_uid": "f52af273954798a4ae38a1378bfbf77a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\n\nconst val LOCAL = false\n\nval inp =\n\t\tif(LOCAL) BufferedReader(FileReader(\"input.txt\"))\n\t\telse BufferedReader(InputStreamReader(System.`in`))\nval out =\n\t\tif(LOCAL)BufferedWriter(FileWriter(\"output.txt\"))\n\t\telse BufferedWriter(OutputStreamWriter(System.out))\n\n\nfun main(args: Array ) {\n\n\tval n = inp.readLine().toInt()\n\n\tvar ansA = 1\n\tvar ansB = n\n\tvar a = 2\n\twhile ( a <= n/a ) {\n\t\tif ( n%a == 0 )\t {\n\t\t\tansA = a\n\t\t\tansB = n/a\n\t\t}\n\t\ta++\n\t}\n\n\tout.write ( ansA.toString() + \" \" + ansB.toString() + \"\\n\" )\n\tinp.close()\n\tout.close()\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "399013c82737d4fe54b84af4a0e4ac83", "src_uid": "f52af273954798a4ae38a1378bfbf77a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n for (i in Math.sqrt(n.toDouble()).toInt() downTo 0) {\n val x = n / i\n if (x * i == n) {\n println(\"$i $x\")\n break\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "46d7e0e82d7fbd89df4e790f7ed180df", "src_uid": "f52af273954798a4ae38a1378bfbf77a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n\n var a : String? = readLine();\n\n var ans: Int=0;\n var state: Boolean=false;\n for ( i in 1..1.shl(a?.length!!)) {\n\n var temp: StringBuilder = StringBuilder()\n\n for (j in a.indices)\n {\n if ((i.and((1.shl(j)))) > 0) temp.append(a[j])\n }\n\n if (temp.length > 0) {\n for ( j in a.indices) {\n if (temp.length<=0)break\n if (temp[0] == '0') {\n temp.deleteCharAt(0)\n } else break;\n }\n if (temp.length > 0) {\n var s :Int= Integer.parseInt (temp.toString());\n var sqr:Int = Math.sqrt (1.0*s).toInt()\n if ((sqr * sqr).equals(s)) {\n ans = Math.max(ans, temp.length)\n state = true;\n }\n }\n\n }\n }\n println(if (state)a.length-ans else -1)\n }\n\n\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "bf7c270fea3678019e9dce3d245c8424", "src_uid": "fa4b1de79708329bb85437e1413e13df", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.util.ArrayList\nimport java.util.Scanner\n\n\nval squares = ArrayList()\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n val n = reader.nextInt()\n\n val max: Int = Math.sqrt(n.toDouble()).toInt()\n for (i in 1..max) {\n squares.add((i*i).toString())\n }\n\n println(containsSubstring(n.toString()))\n}\n\nfun containsSubstring(n: String): String {\n\n for (square in squares.reversed()) {\n var indexOf = 0\n\n var winner = true\n for (char in square.toCharArray()) {\n indexOf = n.indexOf(char, indexOf, true) + 1\n if (indexOf == 0){\n winner = false\n break\n }\n }\n if (winner) {\n return (n.length - square.length).toString()\n }\n }\n\n return \"-1\"\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "c6c1955f041f21310a3b7774457b00dc", "src_uid": "fa4b1de79708329bb85437e1413e13df", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.min\nimport kotlin.math.sqrt\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 s = reader.next()\n val ans = test(s, 0)\n\n writer.println(if (ans >= s.length) \"-1\" else ans)\n}\n\nfun test(s: String, g: Int): Int {\n var mm = g\n\n if (s == \"\") {\n return mm\n }\n\n if (s == \"0\") {\n return mm + 1\n }\n\n val x = s.toInt()\n val y = sqrt(x.toDouble()).toInt()\n if (y * y == x) {\n return mm\n }\n\n var mi = 10000\n for (i in 0..s.lastIndex) {\n val sb = StringBuilder(s)\n val t = sb.deleteCharAt(i).toString()\n\n if (t.length > 1 && t[0] == '0') {\n continue\n }\n\n mi = min(mi, test(t, g + 1))\n }\n return mi\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "b906d802426e8e954e9d9d6ddcf1bc64", "src_uid": "fa4b1de79708329bb85437e1413e13df", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.*\nimport java.awt.geom.*\nimport java.io.*\nimport java.math.*\nimport java.text.*\nimport java.util.*\nimport java.util.regex.*\n\n/*\n\t\t\t br = new BufferedReader(new FileReader(\"input.txt\"));\n\t\t\t pw = new PrintWriter(new BufferedWriter(new FileWriter(\"output.txt\")));\n\t\t\t br = new BufferedReader(new InputStreamReader(System.in));\n\t\t\t pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));\n */\n\n private var br: BufferedReader? = null\n private var st: StringTokenizer? = null\n private var pw: PrintWriter? = null\n\n @Throws(IOException::class)\n fun main(args: Array) {\n br = BufferedReader(InputStreamReader(System.`in`))\n pw = PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))\n val qq = 1\n //int qq = Integer.MAX_VALUE;\n //int qq = readInt();\n\n /*\nreminders: arrays of objects are problematic, prefer ArrayList instead\n\t\t */\n for (casenum in 1..qq) {\n val s = readToken()\n var ret = -1\n for (mask in 1 until (1 shl s.length)) {\n var del = 0\n var curr = 0\n var can = true\n for (i in 0 until s.length) {\n if (mask and (1 shl i) != 0) {\n if (curr == 0 && s[i] == '0') {\n can = false\n }\n curr *= 10\n curr += s[i] - '0'\n } else {\n del++\n }\n }\n val cand = Math.sqrt(curr.toDouble()).toInt()\n if (can && cand * cand == curr) {\n if (ret == -1 || del < ret) ret = del\n }\n }\n pw!!.println(ret)\n }\n exitImmediately()\n }\n\n private fun exitImmediately() {\n pw!!.close()\n System.exit(0)\n }\n\n @Throws(IOException::class)\n private fun readLong(): Long {\n return java.lang.Long.parseLong(readToken())\n }\n\n @Throws(IOException::class)\n private fun readDouble(): Double {\n return java.lang.Double.parseDouble(readToken())\n }\n\n @Throws(IOException::class)\n private fun readInt(): Int {\n return Integer.parseInt(readToken())\n }\n\n @Throws(IOException::class)\n private fun readLine(): String? {\n val s = br!!.readLine()\n if (s == null) {\n exitImmediately()\n }\n st = null\n return s\n }\n\n @Throws(IOException::class)\n private fun readToken(): String {\n while (st == null || !st!!.hasMoreTokens()) {\n st = StringTokenizer(readLine()!!.trim { it <= ' ' })\n }\n return st!!.nextToken()\n }\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "55b9ebf786c18ab81f35743ec0051b2f", "src_uid": "fa4b1de79708329bb85437e1413e13df", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var (a, b) = readLine()!!.split(' ').map { it.toInt() }\n var hours = 0\n while (a > 0){\n a--\n hours++\n if (hours % b == 0) a++\n }\n println(hours)\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "01521f51e6d1c748f17ee3cfb0be5c15", "src_uid": "a349094584d3fdc6b61e39bffe96dece", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n\n val (a, b) = readLine()!!.split(' ').map(String::toInt)\n val list = arrayListOf()\n for (i in 0..a)\n list.add(i, 1)\n\n var i = 1\n while (i <= list.size - 1) {\n if (i % b == 0)\n list.add(1)\n i++\n }\n println(list.size - 1)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "de5beb09f1bf8b2c2172c0bda4eb74bd", "src_uid": "a349094584d3fdc6b61e39bffe96dece", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.sign\n\nfun main(args: Array) {\n var (a, b) = readLine()!!.split(' ').map { it.toInt() }\n var l = 0\n var t = 0\n var br = 0\n\n while (a > 0) {\n t += a\n br += a\n a = br / b\n br = br.rem(b)\n }\n\n println(t)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "f6dd5a765cc2b8748c1e6ccfa08b0c78", "src_uid": "a349094584d3fdc6b61e39bffe96dece", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (a, b) = readLine()!!.split(' ').map { it.toInt() }\n\n var sum = a\n while (a >= b) {\n sum += a / b\n a = a / b + (a % b)\n\n }\n\n println(sum)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "3e18adbfddde013212d874963c4b5e40", "src_uid": "a349094584d3fdc6b61e39bffe96dece", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "/* \r\n Author: Aman Patel\r\n Date: 25-07-2021\r\n*/\r\n\r\nimport java.io.PrintWriter\r\nimport java.util.StringTokenizer\r\nimport java.io.File\r\n\r\nprivate val checkOnlineJudge = System.getProperty(\"ONLINE_JUDGE\") == null\r\nprivate val INPUT = if (checkOnlineJudge) File(\"src/input.txt\").inputStream() else System.`in`\r\nprivate val OUTPUT = if (checkOnlineJudge) File(\"src/output.txt\").outputStream() else System.out\r\n\r\nprivate val bufferedReader = INPUT.bufferedReader()\r\nprivate val out = PrintWriter(OUTPUT, false)\r\nprivate fun readLn() = bufferedReader.readLine()!!\r\n\r\nprivate fun readList() = readLn().split(' ')\r\nprivate var tokenizer = StringTokenizer(\"\")\r\nprivate fun read(): String {\r\n while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(readLn(), \" \")\r\n return tokenizer.nextToken()\r\n}\r\n\r\nprivate fun readInt() = read().toInt()\r\nprivate fun readLong() = read().toLong()\r\nprivate fun readDouble() = read().toDouble()\r\n\r\nprivate fun readIntList() = readList().map { it.toInt() }\r\nprivate fun readLongList() = readList().map { it.toLong() }\r\nprivate fun readDoubleList() = readList().map { it.toDouble() }\r\n\r\nprivate fun readIntArray(n: Int = 0) =\r\n if (n == 0) readList().run { IntArray(size) { get(it).toInt() } } else IntArray(n) { readInt() }\r\n\r\nprivate fun readLongArray(n: Int = 0) =\r\n if (n == 0) readList().run { LongArray(size) { get(it).toLong() } } else LongArray(n) { readLong() }\r\n\r\nprivate fun readDoubleArray(n: Int = 0) =\r\n if (n == 0) readList().run { DoubleArray(size) { get(it).toDouble() } } else DoubleArray(n) { readDouble() }\r\n\r\nprivate class Domino2 {\r\n fun solveTestCase() {\r\n //TODO: Solve the question\r\n\r\n val (n, m, k) = readIntList()\r\n\r\n if ((n and 1 == 0) && (m and 1 == 0)) {\r\n if (k and 1 == 0)\r\n out.println(\"YES\")\r\n else\r\n out.println(\"NO\")\r\n } else if ((n and 1 == 0) && (m and 1 != 0)) {\r\n val limit = (n * (m - 1)) / 2\r\n if ((k <= limit) && (k and 1 == 0))\r\n out.println(\"YES\")\r\n else\r\n out.println(\"NO\")\r\n } else if ((n and 1 != 0) && (m and 1 == 0)) {\r\n val firstTerm = m / 2\r\n if ((k >= firstTerm) && ((k - firstTerm) % 2 == 0))\r\n out.println(\"YES\")\r\n else\r\n out.println(\"NO\")\r\n }\r\n }\r\n}\r\n\r\nfun main(args: Array) {\r\n\r\n var t = 1\r\n t = readInt()\r\n repeat(t) {\r\n //TODO: Read in each Test Case\r\n\r\n Domino2()\r\n .solveTestCase()\r\n }\r\n\r\n out.flush()\r\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "a9209c3fe4b1f781b254a74400209844", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main() {\r\n\tThread(null, Main(), \"hewwo\", 1.shl(28)).start(); // 256MB stack size\r\n}\r\nclass Main: Runnable { override fun run() {\r\n\trepeat(readLine()!!.toInt()) {\r\n\t\tval (n, m, k) = readLine()!!.split(\" \").map {it -> it.toInt()};\r\n\t\t\r\n\t\tvar (horizontal, vertical) = Pair(k, n * m / 2 - k);\r\n\t\tif (n % 2 == 1) {\r\n\t\t\t// there's 1 extra row, fill it with (m / 2) horizontals\r\n\t\t\thorizontal -= m / 2;\r\n\t\t\tprintln(if (horizontal >= 0 && horizontal % 2 == 0 && vertical % 2 == 0) \"Yes\" else \"No\");\r\n\t\t}\r\n\t\telse if (m % 2 == 1) {\r\n\t\t\tvertical -= n / 2;\r\n\t\t\tprintln(if (vertical >= 0 && horizontal % 2 == 0 && vertical % 2 == 0) \"Yes\" else \"No\");\r\n\t\t}\r\n\t\telse {\r\n\t\t\t// even * even, can always be decomposed into 2*2 squares\r\n\t\t\tprintln(if (horizontal % 2 == 0 && vertical % 2 == 0) \"Yes\" else \"No\");\r\n\t\t}\r\n\t};\r\n}}\r\n\r\n/*\r\nC:\\Users\\kenne\\OneDrive\\Desktop\\competitive_programming\\kotlinmain.kt\r\n*/\r\n", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "94959f1f6be37d1f39ce1478fdd868d8", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main() {\n repeat(readLine()!!.toInt()) {\n val (n, m, k) = readLine()!!.split(\" \").map { it.toInt() }\n if (n % 2 == 0) {\n if (k % 2 == 0 && (m % 2 == 0 || 2 * k <= n * (m - 1))) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n } else {\n if (k >= m / 2 && (k - (m / 2)) % 2 == 0) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "f346ff4d76bcb7212f8304b1cb70925a", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.io.BufferedReader\r\nimport java.io.InputStreamReader\r\nimport java.util.*\r\nimport java.lang.AssertionError\r\nimport kotlin.collections.ArrayList\r\nimport kotlin.math.*\r\n\r\nval input = BufferedReader(InputStreamReader(System.`in`))\r\nval output = StringBuilder()\r\n\r\nfun main() {\r\n var tt = int()\r\n while (tt-- > 0) {\r\n var (h, w, k) = ints()\r\n var a = h * w / 2\r\n k = a - k\r\n if (h % 2 == 1) {\r\n if (k % 2 == (a - w / 2) % 2 && k <= a - w / 2) {\r\n cout(\"YES\")\r\n } else {\r\n cout(\"NO\")\r\n }\r\n } else if (w % 2 == 1) {\r\n if (k % 2 == h / 2 % 2 && k >= h / 2) {\r\n cout(\"YES\")\r\n } else {\r\n cout(\"NO\")\r\n }\r\n } else {\r\n if (k % 2 == 0) {\r\n cout(\"YES\")\r\n } else {\r\n cout(\"NO\")\r\n }\r\n }\r\n }\r\n print(output)\r\n}\r\n\r\nfun string() = input.readLine()\r\nfun int() = string().toInt()\r\nfun long() = string().toLong()\r\nfun strings() = ArrayList(string().split(\" \"))\r\nfun ints() = ArrayList(string().split(\" \").map { it.toInt() })\r\nfun longs() = ArrayList(string().split(\" \").map { it.toLong() })\r\nfun cout(s: String) = output.appendLine(s)\r\nfun cout(s: T) = output.appendLine(s.toString())\r\nfun cout(s: IntArray) = output.appendLine(s.joinToString(\" \"))\r\nfun cout(s: LongArray) = output.appendLine(s.joinToString(\" \"))\r\nfun cout(s: Array) = output.appendLine(s.joinToString(\" \"))\r\nfun cout(s: Iterable) = output.appendLine(s.joinToString(\" \"))\r\nfun assert(x: Boolean) {\r\n if (!x) throw AssertionError()\r\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "c126f290acf4d01b3a0b6ab5b7c4c865", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val a = nextInt()\n val b = nextInt()\n val c = nextInt()\n var x = a\n var count = 0\n while(true){\n val z = (x * 10 / b)\n count += 1\n if(z == c){\n println(count)\n return\n }\n x = x * 10 % b\n if( count >= 1e7.toInt()) {\n println(-1)\n return\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "c65aee427e7e1220d61c5c1ac90bdf6a", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n var sc = Scanner(System.`in`)\n var a = sc.nextInt()\n var b = sc.nextInt()\n var c = sc.nextInt()\n var isPossible = false\n for (i in 1..100000) {\n a *= 10\n var d: Int = a / b\n a -= d * b\n if (d == c) {\n println(i)\n isPossible = true\n break\n }\n }\n if (!isPossible) {\n println(-1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "0f34de7f816a110458d080700ed596d8", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\n val a = sc.nextInt()\n val b = sc.nextInt()\n val c = sc.nextInt()\n\n var x = a\n var count = 0\n\n while(true){\n val z = (x * 10 / b)\n count += 1\n if(z == c){\n println(count)\n return\n }\n\n x = x * 10 % b\n\n if( count >= 1e7.toInt()) {\n println(-1)\n return\n }\n }\n\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", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "cf3a8645b0505d423febf4d936854e17", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.system.exitProcess\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n var a = sc.nextInt()\n var b = sc.nextInt()\n var c = sc.nextInt()\n for(i in 1..100000) {\n a *= 10\n if(c == (a / b) % 10) {\n println(i)\n exitProcess(0)\n }\n a %= b\n }\n println(-1)\n}\n\n\n\n\n", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "97b008d771b9235a587a12776fe7b70e", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": " import java.util.*\n\n data class Row(var left: Int = -1, var right: Int = -1, var length: Int = 0)\n\n fun main(args: Array){\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n if (n==1){\n println(0)\n return\n }\n var even = n/2 + n%2\n var odd = n/2\n val rows = arrayListOf()\n val rowsW = arrayListOf()\n var left = -1\n var right = -1\n var answer = 0\n var length = 0\n for (i in 0 until n){\n var a = scanner.nextInt()\n if (a==0){\n length++\n continue\n }\n\n if (length==0){\n a%=2\n if (a!=left && left!=-1){\n answer++\n }\n left=a\n if (a==0){\n odd--\n }\n else{\n even--\n }\n }\n else{\n right = a%2\n rows.add(Row(left, right, length))\n left = right\n right=-1\n length=0\n if (a%2==0){\n odd--\n }\n else{\n even--\n }\n }\n }\n if (length!=0){\n rows.add(Row(left, right, length))\n }\n rows.sortBy { it.length }\n for (row in rows){\n if (row.left ==-1 && row.right==-1){\n answer+=1\n continue\n }\n if (row.left ==-1 || row.right==-1){\n rowsW.add(row)\n continue\n }\n\n if (row.left!=row.right){\n answer++\n }\n else{\n if (row.left==0){\n if (row.length<=odd){\n odd-=row.length\n }\n else{\n answer+=2\n }\n }\n else{\n if (row.length<=even){\n even-=row.length\n }\n else{\n answer+=2\n }\n }\n }\n }\n for (row in rowsW){\n if (row.left+row.right+1==0){\n if (row.length<=odd){\n odd-=row.length\n }\n else{\n answer+=1\n }\n }\n else{\n if (row.length<=even){\n even-=row.length\n }\n else{\n answer+=1\n }\n }\n }\n println(answer)\n }", "lang_cluster": "Kotlin", "tags": ["sortings", "dp", "greedy"], "code_uid": "bae68c67b65d906e7ecb212764c5cd86", "src_uid": "90db6b6548512acfc3da162144169dba", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val jin = Scanner(System.`in`)\n val n = jin.nextInt()\n if (n == 1) {\n println(0)\n return\n }\n val p = IntArray(n) { jin.nextInt() }\n var last = 0\n var sep = 0\n val even2 = mutableListOf()\n val odd2 = mutableListOf()\n val even1 = mutableListOf()\n val odd1 = mutableListOf()\n var answer = 0\n var evenRem = n / 2\n var oddRem = n - evenRem\n for (j in 0 until n) {\n if (p[j] == 0) {\n sep++\n } else {\n if (p[j] % 2 == 0) {\n evenRem--\n } else {\n oddRem--\n }\n if (sep == 0) {\n if (j > 0 && (p[j] + p[j - 1]) % 2 != 0) {\n answer++\n }\n } else {\n if (last == 0) {\n when (p[j] % 2) {\n 0 -> even1\n else -> odd1\n }.add(sep)\n } else if ((p[j] + last) % 2 == 0) {\n when (p[j] % 2) {\n 0 -> even2\n else -> odd2\n }.add(sep)\n } else {\n answer++\n }\n }\n last = p[j]\n sep = 0\n }\n }\n if (sep > 0) {\n if (last == 0) {\n println(1)\n return\n }\n when (last % 2) {\n 0 -> even1\n else -> odd1\n }.add(sep)\n }\n even2.sort()\n odd2.sort()\n even1.sort()\n odd1.sort()\n //println(\"$even2 $odd2 $even1 $odd1\")\n while (true) {\n if (even2.isNotEmpty() && even2[0] <= evenRem && (even1.size < 2 || even1[0] + even1[1] > even2[0])) {\n evenRem -= even2[0]\n even2.removeAt(0)\n } else if (even1.isNotEmpty() && even1[0] <= evenRem) {\n evenRem -= even1[0]\n even1.removeAt(0)\n } else {\n break\n }\n }\n answer += (2 * even2.size) + even1.size\n while (true) {\n if (odd2.isNotEmpty() && odd2[0] <= oddRem && (odd1.size < 2 || odd1[0] + odd1[1] > odd2[0])) {\n oddRem -= odd2[0]\n odd2.removeAt(0)\n } else if (odd1.isNotEmpty() && odd1[0] <= oddRem) {\n oddRem -= odd1[0]\n odd1.removeAt(0)\n } else {\n break\n }\n }\n answer += (2 * odd2.size) + odd1.size\n println(answer)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "dp", "greedy"], "code_uid": "03765e628a42fde5564fce1b96bbb14e", "src_uid": "90db6b6548512acfc3da162144169dba", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\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\n\n/** @author Spheniscine */\nfun main() {\n output {\n val n = readInt()\n val P = readIntArray(n)\n\n var ro = (n+1)/2\n var re = n/2\n var icost = 0\n for(p in P) if(p > 0) if(p and 1 == 1) ro-- else re--\n for(i in 1 until n) {\n val p = P[i-1]\n val q = P[i]\n if(p != 0 && q != 0 && p and 1 != q and 1) icost++\n }\n\n val E = P.indices.filter { P[it] == 0 }\n\n val open = PriorityQueue(11, compareBy { it.cost })\n open.add(Entry(ro, re, -1, icost, -1))\n val closed = IntArray(101 * 101 * 2) { inf }\n fun hash(o: Int, e: Int, lastPar: Int) = o.times(101).plus(e).times(2).plus(lastPar)\n fun enqueue(o: Int, e: Int, lastPar: Int, cost: Int, i: Int) {\n val h = hash(o, e, lastPar)\n if(cost < closed[h]) {\n closed[h] = cost\n open.add(Entry(o, e, lastPar, cost, i))\n }\n }\n\n val ans = run {\n while(true) {\n var (o, e, lastPar, cost, i) = open.remove()\n if(o == 0 && e == 0)\n return@run cost\n if(lastPar != -1 && closed[hash(o, e, lastPar)] < cost) continue\n val j = E[i+1]\n\n if(j > 0 && P[j-1] != 0) lastPar = P[j-1] and 1\n\n if(o > 0) {\n var ncost = cost\n if(lastPar == 0) ncost++\n if(j+1 < n && P[j+1] != 0 && P[j+1] and 1 == 0) ncost++\n enqueue(o-1, e, 1, ncost, i+1)\n }\n if(e > 0) {\n var ncost = cost\n if(lastPar == 1) ncost++\n if(j+1 < n && P[j+1] and 1 == 1) ncost++\n enqueue(o, e-1, 0, ncost, i+1)\n }\n }\n 0\n }\n\n println(ans)\n }\n}\n\ndata class Entry(val o: Int, val e: Int, val lastPar: Int, val cost: Int, val i: Int)\n\nconst val inf = Int.MAX_VALUE\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 _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}", "lang_cluster": "Kotlin", "tags": ["sortings", "dp", "greedy"], "code_uid": "dc911c0f076eed7ccfdd72891ed357c7", "src_uid": "90db6b6548512acfc3da162144169dba", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\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\n\n/** @author Spheniscine */\nfun main() {\n output {\n val n = readInt()\n val P = readIntArray(n)\n\n var ro = (n+1)/2\n var re = n/2\n var icost = 0\n for(p in P) if(p > 0) if(p and 1 == 1) ro-- else re--\n for(i in 1 until n) {\n val p = P[i-1]\n val q = P[i]\n if(p != 0 && q != 0 && p and 1 != q and 1) icost++\n }\n\n val open = PriorityQueue(11, compareBy { it.cost })\n open.add(Entry(ro, re, -1, icost, -1))\n val closed = IntArray(101 * 101 * 2) { inf }\n fun hash(o: Int, e: Int, lastPar: Int) = o.times(101).plus(e).times(2).plus(lastPar)\n\n val ans = run {\n while(true) {\n var (o, e, lastPar, cost, i) = open.remove()\n if(o == 0 && e == 0) return@run cost\n if(lastPar != -1 && closed[hash(o, e, lastPar)] < cost) continue\n val j = (i+1 until n).first { P[it] == 0 }\n\n if(j > 0 && P[j-1] != 0) lastPar = P[j-1] and 1\n\n if(o > 0) {\n var ncost = cost\n if(lastPar == 0) ncost++\n if(j+1 < n && P[j+1] != 0 && P[j+1] and 1 == 0) ncost++\n val h = hash(o-1, e, 1)\n if(closed[h] > ncost) {\n closed[h] = ncost\n open.add(Entry(o-1, e, 1, ncost, j))\n }\n }\n if(e > 0) {\n var ncost = cost\n if(lastPar == 1) ncost++\n if(j+1 < n && P[j+1] and 1 == 1) ncost++\n val h = hash(o, e-1, 0)\n if(closed[h] > ncost) {\n closed[h] = ncost\n open.add(Entry(o, e-1, 0, ncost, j))\n }\n }\n }\n 0\n }\n\n println(ans)\n }\n}\n\ndata class Entry(val o: Int, val e: Int, val lastPar: Int, val cost: Int, val i: Int)\n\nconst val inf = Int.MAX_VALUE\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 _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}", "lang_cluster": "Kotlin", "tags": ["sortings", "dp", "greedy"], "code_uid": "11126a2c53dfc85ba8aabf77940b3212", "src_uid": "90db6b6548512acfc3da162144169dba", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main()\n{\n val(a, b) = readLine()!!.split(\" \").map{ it.toInt() }\n println( a + ((a - 1) / (b - 1)))\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "d78b3b2ea1bd467edca0af96f9638481", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (n, m) = readLine()!!.split(' ').map { it.toInt() }\n m--\n var a = n/m\n var rest = n%m\n m++\n if (rest==0) println(a*m-1)else println(a*m+rest)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "8f11ef6179445c2bfb3668404dcd0cc6", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n val q = scanner.nextInt()\n val per = scanner.nextInt()\n\n val list: ArrayList = arrayListOf()\n (0..q).forEach { list.add(1) }\n\n var i = 1\n while (list.size > i) {\n if (i % per == 0) {\n list.add(1)\n }\n i++\n }\n\n println(list.size - 1)\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "61dbf9847b9d100da948cdadeccd4c8d", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 m = io.readInt()\n var r = n\n var d = 0\n while (r > 0) {\n d += 1\n r -= 1\n if (d % m == 0) r += 1\n }\n io.println(d)\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "a8d61fa59deeff3ef59d5b1022e33c84", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package c913\n\nimport java.util.*\nimport kotlin.math.max\n\nfun main(a:Array){\n val input = Scanner(System.`in`)\n\n val n=input.nextInt()\n val l=input.nextInt()\n val c=Array(n){ input.nextInt() }\n\n val ans = hashMapOf()\n println(find(c,l,ans))\n}\n\nfun find (c:Array,W:Int,map:MutableMap):Long {\n return if (W == 0) 0 else map[W] ?: {\n val amount = Array(c.size) { max(1, W shr it) }\n val rem = amount.mapIndexed { index, m -> max(0, W - (m shl index)) }\n val ans = rem.mapIndexed { index, remain -> find(c, remain, map) + c[index] * amount[index].toLong() }\n ans.min()!!\n }.invoke().also { map.put(W, it) }\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp", "bitmasks"], "code_uid": "297e875a02219b581129d862686fce17", "src_uid": "04ca137d0383c03944e3ce1c502c635b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\n\nfun solve() {\n val (n, l) = inf.readLine().split(' ').map(String::toInt)\n val c = inf.readLine().split(' ').map(String::toLong).toLongArray()\n for (i in 0 until n - 1) {\n if (c[i] * 2 < c[i + 1]) c[i + 1] = c[i] * 2\n }\n var ans = Long.MAX_VALUE\n var rm = l.toLong()\n var cur = 0L\n for (i in n - 1 downTo 0) {\n val v = 1L shl i\n ans = Math.min(ans, cur + (rm + v - 1) / v * c[i])\n cur += rm / v * c[i]\n rm %= v\n }\n ouf.println(Math.min(ans, cur))\n}\n\nfun main(args: Array) {\n ouf.use {\n solve()\n }\n}\n\nval inf = BufferedReader(InputStreamReader(System.`in`))\nval ouf = PrintWriter(System.out)", "lang_cluster": "Kotlin", "tags": ["greedy", "dp", "bitmasks"], "code_uid": "970387e404b35f652d883c881c5b0621", "src_uid": "04ca137d0383c03944e3ce1c502c635b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package cf913.c\n\nimport java.util.*\nimport kotlin.math.max\n\nfun main(a:Array){\n val input = Scanner(System.`in`)\n\n val n=input.nextInt()\n val l=input.nextInt()\n val c=Array(n){ input.nextInt() }\n\n println(find(c,l))\n}\n\nfun find (c:Array,W:Int,map:MutableMap = hashMapOf()):Long =\n if (W == 0) 0L\n else map[W] ?: Array(c.size) {\n val single = 1 shl it //\u5355\u4f4d\u4ef7\u503c\n c[it] * max(1, W shr it).toLong() +\n if (single >= W) 0\n else find(c, W % single,map)\n }.min()!!.also { map.put(W, it) }", "lang_cluster": "Kotlin", "tags": ["greedy", "dp", "bitmasks"], "code_uid": "c05899a266748fc27ad2142733b47699", "src_uid": "04ca137d0383c03944e3ce1c502c635b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (a, b, c) = readLine()!!.split(' ').map(String::toLong)\n var ans = c * 2 + minOf(a, b) * 2\n if (a != b) ans++\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "bab4e9357895056200e9cd87ff077575", "src_uid": "609f131325c13213aedcf8d55fc3ed77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main(args: Array) {\n\n val (a, b, ab) = readLine()!!.split(' ').map { it.toLong() }\n\n val min = min(a, b)\n val ans = if (a == b) (a + b + 2 * ab) else (2 * min + 1 + 2 * ab)\n\n println(ans)\n\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "e0201ab7ba793a74ed4b9c9ce6b560aa", "src_uid": "609f131325c13213aedcf8d55fc3ed77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list ofu strings\nprivate fun readInts() = readStrings().map { it.toLong() } // list of ints\n\nfun main(args:Array){\n val (a,b,c) = readInts()\n var d = 2*c + minOf(a,b) * 2\n if(a!=b) d++\n println(d)\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "5e3e180afe849ba6e808023382477b0e", "src_uid": "609f131325c13213aedcf8d55fc3ed77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 val c = ir.nextInt()\n var total: Long = c * 2L\n\n total += when {\n a > b -> (b * 2) + 1\n b > a -> (a * 2) + 1\n else -> a * 2\n }\n\n pw.print(total)\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}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "576b02f8dfcf6336085a9fc404f44306", "src_uid": "609f131325c13213aedcf8d55fc3ed77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedInputStream\nimport java.util.*\nimport kotlin.collections.HashSet\n\nfun main(args: Array) {\n val scanner = Scanner(BufferedInputStream(System.`in`))\n //val output = BufferedWriter(OutputStreamWriter(System.`out`))\n\n //visualize()\n val n = scanner.nextLong()\n val k = scanner.nextLong()\n if(ok(n, k)) print(\"Yes\")\n else print(\"No\")\n\n}\n\nfun ok(n: Long, k: Long): Boolean{\n //if(n <= k) return false\n val set = HashSet()\n for(i in 1..k){\n val r = n%i\n if(r in set) return false\n set.add(r)\n }\n return true\n}\n\n/*\nfun visualize(){\n\n val n = 40\n\n print(\" |\")\n for(i in 1..n) print(\" %2d\".format(i))\n println()\n for(i in 1..(3*n+4)) print(\"-\")\n println()\n\n for(i in 1..n){\n //if(!isPrime(i)) continue\n print(\"%2d |\".format(i))\n for(j in 1 .. n){\n if(i >= j)\n print(\" %2d\".format(i%j))\n }\n println()\n }\n println()\n}\n\nfun isPrime(x: Int): Boolean{\n var i = 2\n while(i*i <= x){\n if(x%i == 0) return false\n ++i\n }\n return true\n}\n*/", "lang_cluster": "Kotlin", "tags": ["brute force", "number theory"], "code_uid": "4b46018713b4978446979a061b85e7cd", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "var r = 0\nfun main(){\n var q = readLine()!!.split(' ').map { it.toInt() }\n var h = q[0]\n var w = q[1]\n var k = q[2]\n while(k > 0){\n r += (h + w) * 2 - 4\n h -= 4\n w -= 4\n k -= 1\n }\n println(r)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "643968c95f2eb6676ca46d17986bb93b", "src_uid": "2c98d59917337cb321d76f72a1b3c057", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (width, height, numRings) = readInts()\n var sol = 0L\n for (i in 0 until numRings)\n sol += 2*(width - 4 * i) + 2*(height - 4 * i) - 4\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "ad649f54998961475ee749ffe8d862e9", "src_uid": "2c98d59917337cb321d76f72a1b3c057", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var (w, h, k) = readLine()!!.split(' ').map(String::toInt)\n var sum = 0\n\n for (i in 1..k)\n {\n sum += 2*w + 2*h - 4\n w -= 4\n h -= 4\n }\n\n print(sum)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "7a130b9f3b07475074d34c39dd75992e", "src_uid": "2c98d59917337cb321d76f72a1b3c057", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array){\n val s = Scanner(System.`in`)\n val m = s.nextInt()\n val n = s.nextInt()-2\n val k = s.nextInt()-1\n val mn = 2*m+2*n\n var c = 0\n for (i in 0..k) c+=mn-(16*(i))\n print(c)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "e2ada3444c2dba75bc909c9628d3688f", "src_uid": "2c98d59917337cb321d76f72a1b3c057", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "sortings", "greedy"], "code_uid": "11a90056e72d8075c213ecb274d2b32c", "src_uid": "6bcb324c072f796f4d50bafea5f624b2", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "sortings", "greedy"], "code_uid": "0e22cfe2bfbb8b2fa51677d09291ef8d", "src_uid": "6bcb324c072f796f4d50bafea5f624b2", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "sortings", "greedy"], "code_uid": "1afcae55b6ebc4f5ddfaaae182a7e752", "src_uid": "6bcb324c072f796f4d50bafea5f624b2", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "sortings", "greedy"], "code_uid": "1fbb923c1dc88d8c0747f36b0c2daa1c", "src_uid": "6bcb324c072f796f4d50bafea5f624b2", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "graphs"], "code_uid": "e1ee97ca893cabe9bf703f963db424e7", "src_uid": "3dc1ee09016a25421ae371fa8005fce1", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "graphs"], "code_uid": "7ece0f804395f6e69413e892e1a1c4e3", "src_uid": "3dc1ee09016a25421ae371fa8005fce1", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "graphs"], "code_uid": "fd6ebef12c51d9d8cd59261a57d8de23", "src_uid": "3dc1ee09016a25421ae371fa8005fce1", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "graphs"], "code_uid": "03cb7ee284bd05845d8dee02ffbabfbf", "src_uid": "3dc1ee09016a25421ae371fa8005fce1", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "// 2022.07.30 at 15:52:14 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 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()) // 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\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\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(1000)\r\n solve.cases{\r\n val n = getint\r\n val x = getint\r\n val DP = Array(n+1){IntArray(x+1)}\r\n for(mh in 0..x){\r\n DP[0][mh] = 1\r\n }\r\n\r\n val coef = Array(n+1){a -> IntArray(n+1){b -> FACT.choose(a,b)}}\r\n val powed = Array(501){a -> IntArray(501){e -> intPow(a,e,pI)} }\r\n for(c in 2..n){\r\n for(h in 1..x){\r\n for(death in 0..c){\r\n val had = DP[c - death][maxOf(0,h - (c-1))]\r\n val mul = powed[minOf(h,c-1)][death]\r\n// val mul = intPow(minOf(h,c-1),death,pI)\r\n DP[c][h] = DP[c][h] modPlus (mul modM had modM coef[c][death])\r\n }\r\n }\r\n }\r\n put(DP[n][x])\r\n\r\n\r\n\r\n\r\n }\r\n done()\r\n}\r\n\r\n\r\n\r\n\r\n/*\r\nforgot a choose factor < cannot assume totally sorted>\r\nforgot\r\n\r\naccidentially n^3 log\r\n */", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "4a46500d39bc40ad093590ee25f23976", "src_uid": "1908d1c8c6b122a4c6633a7af094f17f", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.5", "source_code": "@file:Suppress(\"EXPERIMENTAL_API_USAGE\")\r\n\r\nimport Utils.ArrayUtils.Companion.arrayOfNullsSafe\r\nimport Utils.ArrayUtils.Companion.makeDistinct\r\nimport Utils.ArrayUtils.Companion.toNotNulls\r\nimport Utils.ArrayUtils.Prints.Companion.println\r\nimport Utils.ArrayUtils.Sorts.Companion.countSort\r\nimport Utils.ArrayUtils.Sorts.Companion.shuffleSort\r\nimport Utils.ArrayUtils.Swaps.Companion.swap\r\nimport Utils.BinarySearchUtils.Companion.binarySearch\r\nimport Utils.BinarySearchUtils.Companion.binarySearchDouble\r\nimport Utils.BinarySearchUtils.Companion.binarySearchLong\r\nimport Utils.BitUtils.Companion.flip\r\nimport Utils.BitUtils.Companion.get\r\nimport Utils.BitUtils.Companion.set\r\nimport Utils.BitUtils.Companion.submaskOf\r\nimport Utils.FastReader\r\nimport Utils.GeneralUtils.Companion.catch\r\nimport Utils.GeneralUtils.Companion.length\r\nimport Utils.GeneralUtils.Companion.rnd\r\nimport Utils.MathUtils.Companion.compareDoubles\r\nimport Utils.MathUtils.Companion.gcd\r\nimport Utils.MathUtils.Companion.log2\r\nimport Utils.Pairs.Companion.ComparablePair\r\nimport Utils.Pairs.Companion.IntPair\r\nimport Utils.Pairs.Companion.LongPair\r\nimport java.io.*\r\nimport java.util.*\r\nimport kotlin.collections.ArrayDeque\r\nimport kotlin.math.*\r\nimport kotlin.random.Random\r\nimport kotlin.time.ExperimentalTime\r\n\r\n@ExperimentalStdlibApi\r\n@ExperimentalTime\r\n@ExperimentalUnsignedTypes\r\nfun main() {\r\n Locale.setDefault(Locale.US)\r\n System.setOut(PrintStream(BufferedOutputStream(System.out)))\r\n Task(FastReader()).solve()\r\n System.out.flush()\r\n}\r\n\r\nconst val eps = 1e-8\r\n\r\nconst val mod = 998244353\r\n\r\ninline class MInt(val x: Int) {\r\n operator fun plus(m: MInt) = MInt((x + m.x) % mod)\r\n operator fun minus(m: MInt) = MInt((x - m.x + mod) % mod)\r\n operator fun times(m: MInt) = MInt((x.toLong() * m.x % mod).toInt())\r\n\r\n override fun toString() = x.toString()\r\n\r\n companion object {\r\n private val facts = mutableListOf(1)\r\n private val invs = mutableListOf(1, 1)\r\n private val invFacts = mutableListOf(1)\r\n fun Int.mod() = MInt(this)\r\n\r\n fun factorial(x: Int): MInt {\r\n while (x !in facts.indices) facts += (facts.last().mod() * facts.size.mod()).x\r\n return facts[x].mod()\r\n }\r\n\r\n fun inv(x: Int): MInt {\r\n while (x !in invs.indices) invs += (MInt((mod - mod / x) % mod) * invs[mod % x].mod()).x\r\n return invs[x].mod()\r\n }\r\n\r\n fun invFact(x: Int): MInt {\r\n while (x !in invFacts.indices) invFacts += (invFacts.last().mod() * inv(invFacts.size)).x\r\n return invFacts[x].mod()\r\n }\r\n }\r\n}\r\n\r\nfun c(n: Int, k: Int) = if (k in 0..n) MInt.factorial(n) * MInt.invFact(k) * MInt.invFact(n - k) else MInt(0)\r\n\r\n@ExperimentalTime\r\n@ExperimentalStdlibApi\r\nclass Task(private val fin: FastReader = FastReader()) {\r\n fun solve() {\r\n val n = fin.readInt()\r\n val maxHealth = fin.readInt()\r\n\r\n val powers = Array(maxHealth + 1) { x ->\r\n Array(n + 1) { null as MInt? }.apply {\r\n this[0] = MInt(1)\r\n for (p in 1 until size) this[p] = this[p - 1]!! * MInt(x)\r\n } as Array\r\n }\r\n\r\n val cache = Array(n + 1) { IntArray(maxHealth + 1) { -1 } }\r\n fun go(alive: Int, damageGot: Int): MInt {\r\n if (alive == 0) return MInt(1)\r\n if (damageGot > maxHealth) return MInt(0)\r\n if (alive == 1) return MInt(0)\r\n cache[alive][damageGot].let { if (it != -1) return MInt(it) }\r\n var res = go(alive, damageGot + alive - 1)\r\n for (died in 1..alive) {\r\n val survived = alive - died\r\n val minWas = 1 + damageGot\r\n val maxWas = minOf(alive - 1 + damageGot, maxHealth)\r\n val numberOfWaysDied = c(alive, died)\r\n val healthForDied = powers[maxWas - minWas + 1][died]\r\n res += go(survived, damageGot + alive - 1) * numberOfWaysDied * healthForDied\r\n }\r\n cache[alive][damageGot] = res.x\r\n return res\r\n }\r\n\r\n val ans = go(n, 0)\r\n println(ans)\r\n }\r\n}\r\n\r\n@Suppress(\"MemberVisibilityCanBePrivate\", \"unused\")\r\n@ExperimentalStdlibApi\r\n@ExperimentalUnsignedTypes\r\nclass Utils {\r\n class GeneralUtils {\r\n companion object {\r\n val rnd = Random(239)\r\n val IntRange.length get() = maxOf(last - first + 1, 0)\r\n\r\n @Suppress(\"UNREACHABLE_CODE\", \"ControlFlowWithEmptyBody\")\r\n fun catch(throwMLE: Boolean = false, f: () -> R): R {\r\n try {\r\n return f()\r\n } catch (e: Exception) {\r\n if (throwMLE) throw OutOfMemoryError()\r\n while (true) {\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n class MathUtils {\r\n companion object {\r\n tailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)\r\n tailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\r\n fun lcm(a: Long, b: Long) = a / gcd(a, b) * b\r\n\r\n fun Int.log2(): Int {\r\n var log = 0\r\n while (1 shl log < this) log++\r\n return log\r\n }\r\n\r\n fun Long.log2(): Int {\r\n var log = 0\r\n while (1L shl log < this) log++\r\n return log\r\n }\r\n\r\n fun compareDoubles(x: Double, y: Double) =\r\n if (abs(x - y) < eps) 0 else if (x < y) -1 else +1\r\n\r\n fun isZero(x: Double) = abs(x) < eps\r\n }\r\n }\r\n\r\n class BitUtils {\r\n companion object {\r\n operator fun Int.get(bit: Int) = (this shr bit) and 1\r\n operator fun Long.get(bit: Int) = ((this shr bit) and 1).toInt()\r\n fun Int.set(bit: Int) = this or (1 shl bit)\r\n fun Long.set(bit: Int) = this or (1L shl bit)\r\n fun Int.flip(bit: Int) = this xor (1 shl bit)\r\n fun Long.flip(bit: Int) = this xor (1L shl bit)\r\n infix fun Int.submaskOf(x: Int) = (this and x) == this\r\n infix fun Long.submaskOf(x: Long) = (this and x) == this\r\n }\r\n }\r\n\r\n class ArrayUtils {\r\n companion object {\r\n fun > MutableList.makeDistinct() {\r\n if (size <= 1) return\r\n sort()\r\n var sz = 1\r\n for (i in 1 until size) {\r\n if (this[i] != this[i - 1]) {\r\n this[sz++] = this[i]\r\n }\r\n }\r\n while (size > sz) removeAt(lastIndex)\r\n }\r\n\r\n @Suppress(\"UNCHECKED_CAST\")\r\n fun Array.toNotNulls() = this as Array\r\n\r\n @Suppress(\"UNCHECKED_CAST\")\r\n inline fun arrayOfNullsSafe(size: Int): Array =\r\n arrayOfNulls(size).toNotNulls()\r\n }\r\n\r\n class Swaps {\r\n companion object {\r\n fun Array.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n }\r\n\r\n fun MutableList.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n }\r\n\r\n fun IntArray.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n }\r\n\r\n fun LongArray.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n }\r\n\r\n fun DoubleArray.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n sort()\r\n }\r\n\r\n fun CharArray.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n sort()\r\n }\r\n }\r\n }\r\n\r\n class Sorts {\r\n companion object {\r\n fun IntArray.shuffleSort() {\r\n for (i in 1 until size) swap(i, rnd.nextInt(i + 1))\r\n sort()\r\n }\r\n\r\n fun LongArray.shuffleSort() {\r\n for (i in 1 until size) swap(i, rnd.nextInt(i + 1))\r\n sort()\r\n }\r\n\r\n fun DoubleArray.shuffleSort() {\r\n for (i in 1 until size) swap(i, rnd.nextInt(i + 1))\r\n sort()\r\n }\r\n\r\n fun CharArray.shuffleSort() {\r\n for (i in 1 until size) swap(i, rnd.nextInt(i + 1))\r\n sort()\r\n }\r\n\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun Array.countSort(\r\n inPlace: Boolean = true,\r\n type: (T) -> Int = { (it as Number).toInt() }\r\n ): Array {\r\n if (isEmpty()) return if (inPlace) this else emptyArray()\r\n val types = IntArray(size) { type(this[it]) }\r\n val min = types.minOrNull()!!\r\n val max = types.maxOrNull()!!\r\n val count = IntArray(max - min + 1)\r\n for (t in types) count[t - min]++\r\n var sum = 0\r\n for (i in count.indices) {\r\n val shift = count[i]\r\n count[i] = sum\r\n sum += shift\r\n }\r\n val sorted = arrayOfNullsSafe(size)\r\n for (i in 0 until size) sorted[count[types[i] - min]++] = this[i]\r\n return if (inPlace) {\r\n this.also { sorted.copyInto(this) }\r\n } else {\r\n sorted\r\n }\r\n }\r\n\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun List.countSort(\r\n inPlace: Boolean = true,\r\n type: (T) -> Int = { (it as Number).toInt() }\r\n ): List {\r\n if (isEmpty()) return if (inPlace) this else emptyList()\r\n val types = IntArray(size) { type(this[it]) }\r\n val min = types.minOrNull()!!\r\n val max = types.maxOrNull()!!\r\n val count = IntArray(max - min + 1)\r\n for (t in types) count[t - min]++\r\n var sum = 0\r\n for (i in count.indices) {\r\n val shift = count[i]\r\n count[i] = sum\r\n sum += shift\r\n }\r\n val sorted = arrayOfNullsSafe(size)\r\n for (i in 0 until size) sorted[count[types[i] - min]++] = this[i]\r\n return if (inPlace) {\r\n return (this as MutableList).apply {\r\n for (i in indices) this[i] = sorted[i]\r\n }\r\n } else {\r\n sorted.asList()\r\n }\r\n }\r\n\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun IntArray.countSort(\r\n inPlace: Boolean = true,\r\n type: (Int) -> Int = { it -> it }\r\n ): IntArray {\r\n if (isEmpty()) return if (inPlace) this else intArrayOf()\r\n val types = IntArray(size) { type(this[it]) }\r\n val min = types.minOrNull()!!\r\n val max = types.maxOrNull()!!\r\n val count = IntArray(max - min + 1)\r\n for (t in types) count[t - min]++\r\n var sum = 0\r\n for (i in count.indices) {\r\n val shift = count[i]\r\n count[i] = sum\r\n sum += shift\r\n }\r\n val sorted = IntArray(size)\r\n for (i in 0 until size) sorted[count[types[i] - min]++] = this[i]\r\n return if (inPlace) {\r\n this.also { sorted.copyInto(this) }\r\n } else {\r\n sorted\r\n }\r\n }\r\n }\r\n }\r\n\r\n class Prints {\r\n companion object {\r\n fun println(a: IntArray) {\r\n if (a.isNotEmpty()) {\r\n print(a[0])\r\n for (i in 1 until a.size) {\r\n print(' ')\r\n print(a[i])\r\n }\r\n }\r\n println()\r\n }\r\n\r\n fun println(a: LongArray) {\r\n if (a.isNotEmpty()) {\r\n print(a[0])\r\n for (i in 1 until a.size) {\r\n print(' ')\r\n print(a[i])\r\n }\r\n }\r\n println()\r\n }\r\n\r\n fun println(a: CharArray, printSpace: Boolean = false) {\r\n if (a.isNotEmpty()) {\r\n print(a[0])\r\n for (i in 1 until a.size) {\r\n if (printSpace) print(' ')\r\n print(a[i])\r\n }\r\n }\r\n println()\r\n }\r\n\r\n fun println(a: Array<*>) {\r\n if (a.isNotEmpty()) {\r\n print(a[0])\r\n for (i in 1 until a.size) {\r\n print(' ')\r\n print(a[i])\r\n }\r\n }\r\n println()\r\n }\r\n\r\n fun println(a: List<*>) {\r\n if (a.isNotEmpty()) {\r\n print(a[0])\r\n for (i in 1 until a.size) {\r\n print(' ')\r\n print(a[i])\r\n }\r\n }\r\n println()\r\n }\r\n\r\n fun println(a: Iterable<*>) {\r\n val it = a.iterator()\r\n if (it.hasNext()) {\r\n print(it.next())\r\n while (it.hasNext()) {\r\n print(' ')\r\n print(it.next())\r\n }\r\n }\r\n println()\r\n }\r\n }\r\n }\r\n }\r\n\r\n class BinarySearchUtils {\r\n companion object {\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun binarySearch(from: Int, to: Int, f: (Int) -> Boolean): Int {\r\n var l = from\r\n var r = to + 1\r\n while (r - l > 1) {\r\n val m = (l + r) / 2\r\n if (f(m)) l = m\r\n else r = m\r\n }\r\n return l\r\n }\r\n\r\n inline fun binarySearch(from: Int = 0, f: (Int) -> Boolean): Int {\r\n var len = 1\r\n while (f(from + len)) len *= 2\r\n return binarySearch(from + len / 2, from + len - 1, f)\r\n }\r\n\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun binarySearchLong(from: Long, to: Long, f: (Long) -> Boolean): Long {\r\n var l = from\r\n var r = to + 1\r\n while (r - l > 1) {\r\n val m = (l + r) / 2\r\n if (f(m)) l = m\r\n else r = m\r\n }\r\n return l\r\n }\r\n\r\n inline fun binarySearchLong(from: Long = 0, f: (Long) -> Boolean): Long {\r\n var len = 1L\r\n while (f(from + len)) len *= 2\r\n return binarySearchLong(from + len / 2, from + len - 1, f)\r\n }\r\n\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun binarySearchDouble(\r\n from: Double,\r\n to: Double,\r\n times: Int = 200,\r\n f: (Double) -> Boolean\r\n ): Double {\r\n var l = from\r\n var r = to\r\n repeat(times) {\r\n val m = (l + r) / 2\r\n if (f(m)) l = m\r\n else r = m\r\n }\r\n return l\r\n }\r\n\r\n inline fun binarySearchDouble(\r\n from: Double = 0.0,\r\n times: Int = 200,\r\n f: (Double) -> Boolean\r\n ): Double {\r\n var len = 1.0\r\n while (f(from + len)) len *= 2\r\n return binarySearchDouble(from, from + len, times, f)\r\n }\r\n }\r\n }\r\n\r\n class Pairs {\r\n companion object {\r\n data class ComparablePair, T2 : Comparable>(\r\n val first: T1,\r\n val second: T2\r\n ) :\r\n Comparable> {\r\n override fun compareTo(other: ComparablePair): Int {\r\n var c = first.compareTo(other.first)\r\n if (c == 0) c = second.compareTo(other.second)\r\n return c\r\n }\r\n }\r\n\r\n data class IntPair(val first: Int, val second: Int) : Comparable {\r\n override fun compareTo(other: IntPair): Int {\r\n var c = first.compareTo(other.first)\r\n if (c == 0) c = second.compareTo(other.second)\r\n return c\r\n }\r\n\r\n fun swap() = IntPair(second, first)\r\n }\r\n\r\n data class LongPair(val first: Long, val second: Long) : Comparable {\r\n override fun compareTo(other: LongPair): Int {\r\n var c = first.compareTo(other.first)\r\n if (c == 0) c = second.compareTo(other.second)\r\n return c\r\n }\r\n }\r\n }\r\n }\r\n\r\n class UtilsImports {\r\n fun importDependencies() {\r\n check(gcd(4, 6) == 2)\r\n check(rnd.nextInt(10) in 0 until 10)\r\n check(mutableListOf(1, 3, 2, 2, 1).apply { makeDistinct() } == listOf(1, 2, 3))\r\n check((5..10).length == 6)\r\n check(intArrayOf(3, 4).apply { swap(0, 1) }.contentEquals(intArrayOf(4, 3)))\r\n check(\r\n intArrayOf(5, 6, 2, 1, 5).apply { shuffleSort() }\r\n .contentEquals(intArrayOf(1, 2, 5, 5, 6))\r\n )\r\n check(binarySearch { it < 10 } == 9)\r\n check(binarySearchLong { it < 1e13.toLong() } == 1e13.toLong() - 1)\r\n binarySearchDouble { true }\r\n println(intArrayOf())\r\n ArrayDeque()\r\n abs(1)\r\n sin(1.0)\r\n cos(1.0)\r\n hypot(1.0, 1.0)\r\n catch {}\r\n ComparablePair(1, 2)\r\n IntPair(1, 2)\r\n arrayOfNulls(0).toNotNulls()\r\n arrayOfNullsSafe(0)\r\n 5.log2()\r\n @Suppress(\"ReplaceGetOrSet\")\r\n 5.get(3)\r\n 5.sign\r\n 5 submaskOf 3\r\n 5.set(3)\r\n 5.flip(3)\r\n compareDoubles(0.0, 1.0)\r\n arrayOf(1, 2).countSort { it.countOneBits() }\r\n LongPair(1, 2)\r\n }\r\n }\r\n\r\n class FastReader(fileName: String? = null) {\r\n @JvmField\r\n val br =\r\n BufferedReader(if (fileName != null) FileReader(fileName) else InputStreamReader(System.`in`))\r\n\r\n @JvmField\r\n var st = StringTokenizer(\"\")\r\n\r\n fun readString(): String {\r\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\r\n return st.nextToken()\r\n }\r\n\r\n fun readInt() = readString().toInt()\r\n fun readLong() = readString().toLong()\r\n fun readDouble() = readString().toDouble()\r\n\r\n fun readIntArray(n: Int) = IntArray(n) { readInt() }\r\n fun readLongArray(n: Int) = LongArray(n) { readLong() }\r\n fun readStringArray(n: Int) = Array(n) { readString() }\r\n fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() }\r\n\r\n fun readInts(n: Int) = MutableList(n) { readInt() }\r\n fun readLongs(n: Int) = MutableList(n) { readLong() }\r\n fun readStrings(n: Int) = MutableList(n) { readString() }\r\n fun readDoubles(n: Int) = MutableList(n) { readDouble() }\r\n }\r\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "dc00da94c3752236eab1a2b24a05cb61", "src_uid": "1908d1c8c6b122a4c6633a7af094f17f", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "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 = 998244353\nfun powMod(a: Long, n: Long, mod: Int): Long {\n if (n == 0L) return 1\n val res = powMod(a * a % mod, n / 2, mod)\n return if (n % 2 == 1L) res * a % mod else res\n}\n\n/**\n * @param mod \u9006\u6570\u8a08\u7b97\u3059\u308b\u305f\u3081\u7d20\u6570\u3067\u306a\u3044\u3068\u3044\u3051\u306a\u3044\n */\nclass Comb(n: Int, val mod: Int) {\n\n val F = LongArray(n + 1)\n val I = LongArray(n + 1)\n\n // n>=mod\u3067\u3082\u51e6\u7406\u3067\u304d\u308b\u3088\u3046\u306b\u3001*mod\u3092\u5225\u6271\u3044\u306b\u3059\u308b\n val cntF = IntArray(n + 1) // F\u306e*mod\u306e\u6570\n val x = IntArray(n + 1) // \u6570\u5024\u304b\u3089*mod\u3092\u53d6\u308a\u9664\u3044\u305f\u5024\n val cntX = IntArray(n + 1) // x\u306e*mod\u306e\u6570\n\n init {\n F[0] = 1\n I[0] = 1\n for (i in 1..n) {\n x[i] = i\n if(x[i] % mod == 0) {\n val j = i/mod\n cntX[i] = cntX[j] + 1\n x[i] = x[j]\n }\n F[i] = F[i - 1] * x[i] % mod\n cntF[i] += cntF[i - 1] + cntX[i]\n }\n\n I[n] = powMod(F[n], (mod - 2).toLong(), mod)\n for (i in n - 1 downTo 0) {\n I[i] = I[i + 1] * x[i + 1] % mod\n }\n }\n\n fun comb(n: Int, k: Int): Long {\n if (n < k) return 0L\n val c = cntF[n] - cntF[k] - cntF[n - k]\n return if (c > 0) 0 else F[n] * I[k] % mod * I[n - k] % mod\n }\n\n fun perm(n: Int, k: Int): Long {\n val c = cntF[n] - cntF[n - k]\n return if (c > 0) 0 else F[n] * I[n - k] % mod\n }\n\n fun inv(x: Int): Long {\n val c = cntF[x] - cntF[x - 1]\n return if (c > 0) 0 else I[x] * F[x - 1] % mod\n }\n\n /**\n * n\u306e\u30b0\u30eb\u30fc\u30d7\u304b\u3089k\u56de\u91cd\u8907\u3042\u308a\u3067\u9078\u3076\u7d44\u307f\u5408\u308f\u305b\u6570\n * n - 1\u306e\u3057\u304d\u308a\u3068k\u306e\u25cb\u3067\u8003\u3048\u308b\n */\n fun H(n: Int, k: Int) = comb(n + k - 1, k)\n}\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n\n fun solve() {\n val (N, X) = na(2)\n val dp = Array(N + 1){LongArray(X + 1) } // (\u4eba\u6570, Xmax)\n\n val comb = Comb(N + 10, MOD)\n\n val pow = Array(max(N, X) + 1){LongArray(max(N, X) + 1)}\n for (i in 0 .. max(N, X)) {\n for (j in 0 .. max(N, X)) {\n pow[i][j] = powMod(i.toLong(), j.toLong(), MOD)\n }\n }\n\n // \u521d\u671f\u5316\u3002(0, 0)\u304b\u3089\u306e\u9077\u79fb\n for (i in 2 .. N) { // \u6b8b\u3063\u3066\u3044\u308b\u4eba\u6570\n for (j in 1 .. min(i - 1, X)) { // \u6b21\u306e\u30bf\u30fc\u30f3\u3067\u5168\u54e1\u6b7b\u4ea1\n val select = comb.comb(N, i)\n val cmb = (pow[j][i] + MOD - pow[j - 1][i]) % MOD // j\u3092\u542b\u3080\u7d44\u307f\u5408\u308f\u305b\n dp[i][j] = cmb * select % MOD\n }\n }\n\n debug{\"INIT\"}\n debugDim(dp)\n\n for (i in 2 .. N) {\n for (j in 1 .. X) {\n for (ni in i .. N) {\n val add = ni - i\n val nj = j + (ni - 1)\n if (nj > X) continue\n\n val remain = N - i\n val select = comb.comb(remain, add)\n val cmb = pow[ni - 1][add]\n val c = cmb * select % MOD\n dp[ni][nj] = (dp[ni][nj] + dp[i][j] * c) % MOD\n }\n }\n }\n\n debug{\"DP\"}\n debugDim(dp)\n\n val ans = dp[N].sum()\n out.println(ans % 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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\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 IntArray(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 debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n /**\n * \u30b3\u30fc\u30ca\u30fc\u30b1\u30fc\u30b9\u3067\u30a8\u30e9\u30fc\u51fa\u305f\u308a\u3059\u308b\u306e\u3067\u3001debug(dp[1])\u306e\u3088\u3046\u306b\u6dfb\u3048\u5b57\u4ed8\u304d\u306e\u5834\u5408\u306fdebug{}\u3092\u3064\u304b\u3046\u3053\u3068\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 { toString(a) }\n }\n\n private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString(\"\")}\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 private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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 private inline fun assert(b: Boolean, f: () -> String) = run{if (!b) throw AssertionError(f())}\n\n companion object {\n // TestRunner\u304b\u3089\u547c\u3073\u305f\u3044\u306e\u3067\u5358\u7d14\u306amain\u3058\u3083\u3060\u3081\n fun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n }\n }\n}\n\n/**\n * judge\u304b\u3089\u547c\u3070\u308c\u308b\n */\nfun main() = Solver.main()", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "d52ebf732fa9d4a85ee554c930c4f465", "src_uid": "1908d1c8c6b122a4c6633a7af094f17f", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.5", "source_code": "@file:Suppress(\"EXPERIMENTAL_API_USAGE\")\r\n\r\nimport Utils.ArrayUtils.Companion.arrayOfNullsSafe\r\nimport Utils.ArrayUtils.Companion.makeDistinct\r\nimport Utils.ArrayUtils.Companion.toNotNulls\r\nimport Utils.ArrayUtils.Prints.Companion.println\r\nimport Utils.ArrayUtils.Sorts.Companion.countSort\r\nimport Utils.ArrayUtils.Sorts.Companion.shuffleSort\r\nimport Utils.ArrayUtils.Swaps.Companion.swap\r\nimport Utils.BinarySearchUtils.Companion.binarySearch\r\nimport Utils.BinarySearchUtils.Companion.binarySearchDouble\r\nimport Utils.BinarySearchUtils.Companion.binarySearchLong\r\nimport Utils.BitUtils.Companion.flip\r\nimport Utils.BitUtils.Companion.get\r\nimport Utils.BitUtils.Companion.set\r\nimport Utils.BitUtils.Companion.submaskOf\r\nimport Utils.FastReader\r\nimport Utils.GeneralUtils.Companion.catch\r\nimport Utils.GeneralUtils.Companion.length\r\nimport Utils.GeneralUtils.Companion.rnd\r\nimport Utils.MathUtils.Companion.compareDoubles\r\nimport Utils.MathUtils.Companion.gcd\r\nimport Utils.MathUtils.Companion.log2\r\nimport Utils.Pairs.Companion.ComparablePair\r\nimport Utils.Pairs.Companion.IntPair\r\nimport Utils.Pairs.Companion.LongPair\r\nimport java.io.*\r\nimport java.util.*\r\nimport kotlin.collections.ArrayDeque\r\nimport kotlin.math.*\r\nimport kotlin.random.Random\r\nimport kotlin.time.ExperimentalTime\r\n\r\n@ExperimentalStdlibApi\r\n@ExperimentalTime\r\n@ExperimentalUnsignedTypes\r\nfun main() {\r\n Locale.setDefault(Locale.US)\r\n System.setOut(PrintStream(BufferedOutputStream(System.out)))\r\n Task(FastReader()).solve()\r\n System.out.flush()\r\n}\r\n\r\nconst val eps = 1e-8\r\n\r\nconst val mod = 998244353\r\n\r\ninline class MInt(val x: Int) {\r\n operator fun plus(m: MInt) = MInt((x + m.x) % mod)\r\n operator fun minus(m: MInt) = MInt((x - m.x + mod) % mod)\r\n operator fun times(m: MInt) = MInt((x.toLong() * m.x % mod).toInt())\r\n operator fun div(m: MInt) = this * m.inv()\r\n\r\n fun inv() = inv(x)\r\n fun pow(p: Int): MInt {\r\n if (p == 0) return MInt(1)\r\n var r = pow(p / 2)\r\n r *= r\r\n if (p % 2 == 1) r *= this\r\n return r\r\n }\r\n\r\n override fun toString() = x.toString()\r\n\r\n companion object {\r\n private val facts = mutableListOf(MInt(1))\r\n private val invs = mutableListOf(MInt(0))\r\n private val invFacts = mutableListOf(MInt(1))\r\n fun Int.mod() = MInt(this)\r\n\r\n fun factorial(x: Int): MInt {\r\n while (x !in facts.indices) facts += facts.last() * facts.size.mod()\r\n return facts[x]\r\n }\r\n\r\n fun inv(x: Int): MInt {\r\n while (x !in invs.indices) invs += MInt((mod - mod / x) % mod) * inv(mod % x)\r\n return x.mod().pow(mod - 2)\r\n }\r\n\r\n fun invFact(x: Int): MInt {\r\n while (x !in invFacts.indices) invFacts += invFacts.last() * inv(invFacts.size)\r\n return invFacts[x]\r\n }\r\n }\r\n}\r\n\r\nfun c(n: Int, k: Int) = if (k in 0..n) MInt.factorial(n) * MInt.invFact(k) * MInt.invFact(n - k) else MInt(0)\r\n\r\n@ExperimentalTime\r\n@ExperimentalStdlibApi\r\nclass Task(private val fin: FastReader = FastReader()) {\r\n fun solve() {\r\n val n = fin.readInt()\r\n val maxHealth = fin.readInt()\r\n\r\n val powers = Array(maxHealth + 1) { x ->\r\n Array(n + 1) { null as MInt? }.apply {\r\n this[0] = MInt(1)\r\n for (p in 1 until size) this[p] = this[p - 1]!! * MInt(x)\r\n } as Array\r\n }\r\n\r\n val cache = Array(n + 1) { IntArray(maxHealth + 1) { -1 } }\r\n fun go(alive: Int, damageGot: Int): MInt {\r\n if (alive == 0) return MInt(1)\r\n if (damageGot > maxHealth) return MInt(0)\r\n if (alive == 1) return MInt(0)\r\n cache[alive][damageGot].let { if (it != -1) return MInt(it) }\r\n var res = go(alive, damageGot + alive - 1)\r\n for (died in 1..alive) {\r\n val survived = alive - died\r\n val minWas = 1 + damageGot\r\n val maxWas = minOf(alive - 1 + damageGot, maxHealth)\r\n val numberOfWaysDied = c(alive, died)\r\n val healthForDied = powers[maxWas - minWas + 1][died]\r\n res += go(survived, damageGot + alive - 1) * numberOfWaysDied * healthForDied\r\n }\r\n cache[alive][damageGot] = res.x\r\n return res\r\n }\r\n\r\n val ans = go(n, 0)\r\n println(ans)\r\n }\r\n}\r\n\r\n@Suppress(\"MemberVisibilityCanBePrivate\", \"unused\")\r\n@ExperimentalStdlibApi\r\n@ExperimentalUnsignedTypes\r\nclass Utils {\r\n class GeneralUtils {\r\n companion object {\r\n val rnd = Random(239)\r\n val IntRange.length get() = maxOf(last - first + 1, 0)\r\n\r\n @Suppress(\"UNREACHABLE_CODE\", \"ControlFlowWithEmptyBody\")\r\n fun catch(throwMLE: Boolean = false, f: () -> R): R {\r\n try {\r\n return f()\r\n } catch (e: Exception) {\r\n if (throwMLE) throw OutOfMemoryError()\r\n while (true) {\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n class MathUtils {\r\n companion object {\r\n tailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)\r\n tailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\r\n fun lcm(a: Long, b: Long) = a / gcd(a, b) * b\r\n\r\n fun Int.log2(): Int {\r\n var log = 0\r\n while (1 shl log < this) log++\r\n return log\r\n }\r\n\r\n fun Long.log2(): Int {\r\n var log = 0\r\n while (1L shl log < this) log++\r\n return log\r\n }\r\n\r\n fun compareDoubles(x: Double, y: Double) =\r\n if (abs(x - y) < eps) 0 else if (x < y) -1 else +1\r\n\r\n fun isZero(x: Double) = abs(x) < eps\r\n }\r\n }\r\n\r\n class BitUtils {\r\n companion object {\r\n operator fun Int.get(bit: Int) = (this shr bit) and 1\r\n operator fun Long.get(bit: Int) = ((this shr bit) and 1).toInt()\r\n fun Int.set(bit: Int) = this or (1 shl bit)\r\n fun Long.set(bit: Int) = this or (1L shl bit)\r\n fun Int.flip(bit: Int) = this xor (1 shl bit)\r\n fun Long.flip(bit: Int) = this xor (1L shl bit)\r\n infix fun Int.submaskOf(x: Int) = (this and x) == this\r\n infix fun Long.submaskOf(x: Long) = (this and x) == this\r\n }\r\n }\r\n\r\n class ArrayUtils {\r\n companion object {\r\n fun > MutableList.makeDistinct() {\r\n if (size <= 1) return\r\n sort()\r\n var sz = 1\r\n for (i in 1 until size) {\r\n if (this[i] != this[i - 1]) {\r\n this[sz++] = this[i]\r\n }\r\n }\r\n while (size > sz) removeAt(lastIndex)\r\n }\r\n\r\n @Suppress(\"UNCHECKED_CAST\")\r\n fun Array.toNotNulls() = this as Array\r\n\r\n @Suppress(\"UNCHECKED_CAST\")\r\n inline fun arrayOfNullsSafe(size: Int): Array =\r\n arrayOfNulls(size).toNotNulls()\r\n }\r\n\r\n class Swaps {\r\n companion object {\r\n fun Array.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n }\r\n\r\n fun MutableList.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n }\r\n\r\n fun IntArray.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n }\r\n\r\n fun LongArray.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n }\r\n\r\n fun DoubleArray.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n sort()\r\n }\r\n\r\n fun CharArray.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n sort()\r\n }\r\n }\r\n }\r\n\r\n class Sorts {\r\n companion object {\r\n fun IntArray.shuffleSort() {\r\n for (i in 1 until size) swap(i, rnd.nextInt(i + 1))\r\n sort()\r\n }\r\n\r\n fun LongArray.shuffleSort() {\r\n for (i in 1 until size) swap(i, rnd.nextInt(i + 1))\r\n sort()\r\n }\r\n\r\n fun DoubleArray.shuffleSort() {\r\n for (i in 1 until size) swap(i, rnd.nextInt(i + 1))\r\n sort()\r\n }\r\n\r\n fun CharArray.shuffleSort() {\r\n for (i in 1 until size) swap(i, rnd.nextInt(i + 1))\r\n sort()\r\n }\r\n\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun Array.countSort(\r\n inPlace: Boolean = true,\r\n type: (T) -> Int = { (it as Number).toInt() }\r\n ): Array {\r\n if (isEmpty()) return if (inPlace) this else emptyArray()\r\n val types = IntArray(size) { type(this[it]) }\r\n val min = types.minOrNull()!!\r\n val max = types.maxOrNull()!!\r\n val count = IntArray(max - min + 1)\r\n for (t in types) count[t - min]++\r\n var sum = 0\r\n for (i in count.indices) {\r\n val shift = count[i]\r\n count[i] = sum\r\n sum += shift\r\n }\r\n val sorted = arrayOfNullsSafe(size)\r\n for (i in 0 until size) sorted[count[types[i] - min]++] = this[i]\r\n return if (inPlace) {\r\n this.also { sorted.copyInto(this) }\r\n } else {\r\n sorted\r\n }\r\n }\r\n\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun List.countSort(\r\n inPlace: Boolean = true,\r\n type: (T) -> Int = { (it as Number).toInt() }\r\n ): List {\r\n if (isEmpty()) return if (inPlace) this else emptyList()\r\n val types = IntArray(size) { type(this[it]) }\r\n val min = types.minOrNull()!!\r\n val max = types.maxOrNull()!!\r\n val count = IntArray(max - min + 1)\r\n for (t in types) count[t - min]++\r\n var sum = 0\r\n for (i in count.indices) {\r\n val shift = count[i]\r\n count[i] = sum\r\n sum += shift\r\n }\r\n val sorted = arrayOfNullsSafe(size)\r\n for (i in 0 until size) sorted[count[types[i] - min]++] = this[i]\r\n return if (inPlace) {\r\n return (this as MutableList).apply {\r\n for (i in indices) this[i] = sorted[i]\r\n }\r\n } else {\r\n sorted.asList()\r\n }\r\n }\r\n\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun IntArray.countSort(\r\n inPlace: Boolean = true,\r\n type: (Int) -> Int = { it -> it }\r\n ): IntArray {\r\n if (isEmpty()) return if (inPlace) this else intArrayOf()\r\n val types = IntArray(size) { type(this[it]) }\r\n val min = types.minOrNull()!!\r\n val max = types.maxOrNull()!!\r\n val count = IntArray(max - min + 1)\r\n for (t in types) count[t - min]++\r\n var sum = 0\r\n for (i in count.indices) {\r\n val shift = count[i]\r\n count[i] = sum\r\n sum += shift\r\n }\r\n val sorted = IntArray(size)\r\n for (i in 0 until size) sorted[count[types[i] - min]++] = this[i]\r\n return if (inPlace) {\r\n this.also { sorted.copyInto(this) }\r\n } else {\r\n sorted\r\n }\r\n }\r\n }\r\n }\r\n\r\n class Prints {\r\n companion object {\r\n fun println(a: IntArray) {\r\n if (a.isNotEmpty()) {\r\n print(a[0])\r\n for (i in 1 until a.size) {\r\n print(' ')\r\n print(a[i])\r\n }\r\n }\r\n println()\r\n }\r\n\r\n fun println(a: LongArray) {\r\n if (a.isNotEmpty()) {\r\n print(a[0])\r\n for (i in 1 until a.size) {\r\n print(' ')\r\n print(a[i])\r\n }\r\n }\r\n println()\r\n }\r\n\r\n fun println(a: CharArray, printSpace: Boolean = false) {\r\n if (a.isNotEmpty()) {\r\n print(a[0])\r\n for (i in 1 until a.size) {\r\n if (printSpace) print(' ')\r\n print(a[i])\r\n }\r\n }\r\n println()\r\n }\r\n\r\n fun println(a: Array<*>) {\r\n if (a.isNotEmpty()) {\r\n print(a[0])\r\n for (i in 1 until a.size) {\r\n print(' ')\r\n print(a[i])\r\n }\r\n }\r\n println()\r\n }\r\n\r\n fun println(a: List<*>) {\r\n if (a.isNotEmpty()) {\r\n print(a[0])\r\n for (i in 1 until a.size) {\r\n print(' ')\r\n print(a[i])\r\n }\r\n }\r\n println()\r\n }\r\n\r\n fun println(a: Iterable<*>) {\r\n val it = a.iterator()\r\n if (it.hasNext()) {\r\n print(it.next())\r\n while (it.hasNext()) {\r\n print(' ')\r\n print(it.next())\r\n }\r\n }\r\n println()\r\n }\r\n }\r\n }\r\n }\r\n\r\n class BinarySearchUtils {\r\n companion object {\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun binarySearch(from: Int, to: Int, f: (Int) -> Boolean): Int {\r\n var l = from\r\n var r = to + 1\r\n while (r - l > 1) {\r\n val m = (l + r) / 2\r\n if (f(m)) l = m\r\n else r = m\r\n }\r\n return l\r\n }\r\n\r\n inline fun binarySearch(from: Int = 0, f: (Int) -> Boolean): Int {\r\n var len = 1\r\n while (f(from + len)) len *= 2\r\n return binarySearch(from + len / 2, from + len - 1, f)\r\n }\r\n\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun binarySearchLong(from: Long, to: Long, f: (Long) -> Boolean): Long {\r\n var l = from\r\n var r = to + 1\r\n while (r - l > 1) {\r\n val m = (l + r) / 2\r\n if (f(m)) l = m\r\n else r = m\r\n }\r\n return l\r\n }\r\n\r\n inline fun binarySearchLong(from: Long = 0, f: (Long) -> Boolean): Long {\r\n var len = 1L\r\n while (f(from + len)) len *= 2\r\n return binarySearchLong(from + len / 2, from + len - 1, f)\r\n }\r\n\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun binarySearchDouble(\r\n from: Double,\r\n to: Double,\r\n times: Int = 200,\r\n f: (Double) -> Boolean\r\n ): Double {\r\n var l = from\r\n var r = to\r\n repeat(times) {\r\n val m = (l + r) / 2\r\n if (f(m)) l = m\r\n else r = m\r\n }\r\n return l\r\n }\r\n\r\n inline fun binarySearchDouble(\r\n from: Double = 0.0,\r\n times: Int = 200,\r\n f: (Double) -> Boolean\r\n ): Double {\r\n var len = 1.0\r\n while (f(from + len)) len *= 2\r\n return binarySearchDouble(from, from + len, times, f)\r\n }\r\n }\r\n }\r\n\r\n class Pairs {\r\n companion object {\r\n data class ComparablePair, T2 : Comparable>(\r\n val first: T1,\r\n val second: T2\r\n ) :\r\n Comparable> {\r\n override fun compareTo(other: ComparablePair): Int {\r\n var c = first.compareTo(other.first)\r\n if (c == 0) c = second.compareTo(other.second)\r\n return c\r\n }\r\n }\r\n\r\n data class IntPair(val first: Int, val second: Int) : Comparable {\r\n override fun compareTo(other: IntPair): Int {\r\n var c = first.compareTo(other.first)\r\n if (c == 0) c = second.compareTo(other.second)\r\n return c\r\n }\r\n\r\n fun swap() = IntPair(second, first)\r\n }\r\n\r\n data class LongPair(val first: Long, val second: Long) : Comparable {\r\n override fun compareTo(other: LongPair): Int {\r\n var c = first.compareTo(other.first)\r\n if (c == 0) c = second.compareTo(other.second)\r\n return c\r\n }\r\n }\r\n }\r\n }\r\n\r\n class UtilsImports {\r\n fun importDependencies() {\r\n check(gcd(4, 6) == 2)\r\n check(rnd.nextInt(10) in 0 until 10)\r\n check(mutableListOf(1, 3, 2, 2, 1).apply { makeDistinct() } == listOf(1, 2, 3))\r\n check((5..10).length == 6)\r\n check(intArrayOf(3, 4).apply { swap(0, 1) }.contentEquals(intArrayOf(4, 3)))\r\n check(\r\n intArrayOf(5, 6, 2, 1, 5).apply { shuffleSort() }\r\n .contentEquals(intArrayOf(1, 2, 5, 5, 6))\r\n )\r\n check(binarySearch { it < 10 } == 9)\r\n check(binarySearchLong { it < 1e13.toLong() } == 1e13.toLong() - 1)\r\n binarySearchDouble { true }\r\n println(intArrayOf())\r\n ArrayDeque()\r\n abs(1)\r\n sin(1.0)\r\n cos(1.0)\r\n hypot(1.0, 1.0)\r\n catch {}\r\n ComparablePair(1, 2)\r\n IntPair(1, 2)\r\n arrayOfNulls(0).toNotNulls()\r\n arrayOfNullsSafe(0)\r\n 5.log2()\r\n @Suppress(\"ReplaceGetOrSet\")\r\n 5.get(3)\r\n 5.sign\r\n 5 submaskOf 3\r\n 5.set(3)\r\n 5.flip(3)\r\n compareDoubles(0.0, 1.0)\r\n arrayOf(1, 2).countSort { it.countOneBits() }\r\n LongPair(1, 2)\r\n }\r\n }\r\n\r\n class FastReader(fileName: String? = null) {\r\n @JvmField\r\n val br =\r\n BufferedReader(if (fileName != null) FileReader(fileName) else InputStreamReader(System.`in`))\r\n\r\n @JvmField\r\n var st = StringTokenizer(\"\")\r\n\r\n fun readString(): String {\r\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\r\n return st.nextToken()\r\n }\r\n\r\n fun readInt() = readString().toInt()\r\n fun readLong() = readString().toLong()\r\n fun readDouble() = readString().toDouble()\r\n\r\n fun readIntArray(n: Int) = IntArray(n) { readInt() }\r\n fun readLongArray(n: Int) = LongArray(n) { readLong() }\r\n fun readStringArray(n: Int) = Array(n) { readString() }\r\n fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() }\r\n\r\n fun readInts(n: Int) = MutableList(n) { readInt() }\r\n fun readLongs(n: Int) = MutableList(n) { readLong() }\r\n fun readStrings(n: Int) = MutableList(n) { readString() }\r\n fun readDoubles(n: Int) = MutableList(n) { readDouble() }\r\n }\r\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "1873b495125e04f49c1ee7eb972b12bf", "src_uid": "1908d1c8c6b122a4c6633a7af094f17f", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n println(4 - readLine()!!.split(' ').map { it.toInt() }.toSet().size)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "188c00c69f1f8332c6c44658c96981dd", "src_uid": "38c4864937e57b35d3cce272f655e20f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() = (4 - hashSetOf().apply { addAll(readLine()!!.split(\" \")) }.size).run(::println)", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "63ac00d88bdc64ce17fbe5f705a6037b", "src_uid": "38c4864937e57b35d3cce272f655e20f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "1cb3465c027aee89fd400644d706c7ef", "src_uid": "38c4864937e57b35d3cce272f655e20f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "b16071b07012a7fec6292aec9c4dd601", "src_uid": "38c4864937e57b35d3cce272f655e20f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// solved easily, but the tutorial is worth reading:\n//This task is about pure implementation. Maintain the number of current spectator and check if he doesn't win.\n// With knowledge of current winner w and current spectator s you can easily get the third player by formula\n// 6\u2009-\u2009w\u2009-\u2009s (just the sum of all numbers without the known ones).\n\n// My solution\n//fun main() {\n// fun readInt() = readLine()!!.toInt()\n//\n// val numGames = readInt()\n// val playing = booleanArrayOf(true, true, false)\n// repeat(numGames) {\n// val winner = readInt() - 1\n// if (!playing[winner]) return print(\"NO\")\n// for (player in 0..2)\n// if (player != winner)\n// playing[player] = !playing[player]\n// }\n// print(\"YES\")\n//}\n\n// Tutorial solution\nfun main() {\n fun readInt() = readLine()!!.toInt()\n\n val numGames = readInt()\n var out = 3\n repeat(numGames) {\n val winner = readInt()\n if (winner == out) return print(\"NO\")\n out = 6 - winner - out\n }\n print(\"YES\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "ae0990a387253d2fe2d62f4189269deb", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\n val n = sc.nextInt()\n\n val pl = arrayOf(true, true, false)\n\n repeat(n) {\n val win = sc.nextInt()\n\n if (!pl[win - 1]) {\n println(\"NO\")\n return\n }\n\n var lost = 0\n for (i in 1..3) {\n if (pl[i - 1] && i != win) lost = i\n }\n\n for (i in 1..3) {\n pl[i - 1] = true\n if( i == lost) pl[i - 1] = false\n }\n }\n\n println(\"YES\")\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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "122544394b7c9f8d606b2c2e05f81d32", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nclass Main internal constructor(inputStream: InputStream, val out: PrintWriter) {\n companion object {\n val ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n }\n\n private val br = BufferedReader(InputStreamReader(inputStream))\n private var st = StringTokenizer(\"\")\n\n internal fun hasNext(): Boolean {\n while (!st.hasMoreTokens()) {\n val readLine = br.readLine() ?: return false\n st = StringTokenizer(readLine)\n }\n return true\n }\n\n private operator fun next() =\n if (hasNext()) st.nextToken()!!\n else throw RuntimeException(\"No tokens\")\n\n internal fun nline() =\n if (hasNext()) st.nextToken(\"\\n\")\n else throw RuntimeException(\"No tokens\")\n\n private fun ni() = next().toInt()\n private fun nii() = Pair(ni(), ni())\n private fun niii() = Triple(ni(), ni(), ni())\n private fun nia(n: Int) = IntArray(n) { ni() }\n private fun nia(m: Int, n: Int) = Array(m) { nia(n) }\n\n private fun nl() = next().toLong()\n private fun nll() = Pair(nl(), nl())\n private fun nlll() = Triple(nl(), nl(), nl())\n private fun nla(n: Int) = LongArray(n, { nl() })\n private fun nla(m: Int, n: Int) = Array(m) { nla(n) }\n\n private fun nd() = next().toDouble()\n private fun ndd() = Pair(nd(), nd())\n private fun nddd() = Triple(nd(), nd(), nd())\n private fun nda(n: Int) = DoubleArray(n) { nd() }\n private fun nda(m: Int, n: Int) = Array(m) { nda(n) }\n\n inline fun log(name: String, block: () -> Unit) {\n if (!ONLINE_JUDGE) {\n p(\"#$name: \")\n block()\n flush()\n }\n }\n\n inline fun log() = log(\"\") { pln() }\n inline fun log(message: Any?, name: String = \"\") = log(name) { pln(message) }\n inline fun log(arr: IntArray?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(arr: LongArray?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(arr: DoubleArray?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(arr: Array?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(stack: Stack?, name: String = \"\") = log(name) { pln(stack) }\n inline fun log(list: List?, name: String = \"\") = log(name) { pln(list) }\n\n //prefix print\n inline fun prep(prefix: Boolean, separator: String, message: Any?) {\n if (prefix) {\n p(separator)\n }\n p(message)\n }\n\n inline fun p(message: Any?) = this.also { out.print(message) }\n\n inline fun p(arr: IntArray?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(arr: LongArray?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(arr: DoubleArray?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(arr: Array?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(list: List?, separator: String = \" \") = this.also {\n list?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(stack: Stack?, separator: String = \" \") = this.also {\n stack?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun pln() = this.also { out.println() }\n inline fun pln(message: Any?) = p(message).pln()\n inline fun pln(arr: IntArray?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(arr: LongArray?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(arr: DoubleArray?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(list: List?, separator: String = \" \") = p(list, separator).pln()\n inline fun pln(arr: Array?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(stack: Stack?, separator: String = \" \") = p(stack, separator).pln()\n\n inline fun flush() = out.flush()\n\n //////////////////////////////////////\n\n fun run() {\n val n = ni()\n var next = 0\n var playing1 = 1\n var playing2 = 2\n val check = HashSet()\n var winner = 0;\n for (i in 0..n - 1) {\n next = ni();\n if(next!=playing1&&next!=playing2){\n pln(\"NO\")\n return\n }\n winner = next;\n for (i in 1..3) check.add(i)\n check.remove(playing1)\n check.remove(playing2)\n playing1=check.first();\n playing2=winner;\n }\n pln(\"YES\")\n }\n\n}\n\n//////////////////////////////////////\nfun main(args: Array) {\n val inp = File(\"input.txt\")\n if (Main.ONLINE_JUDGE || !inp.isFile) {\n val a = Main(System.`in`, PrintWriter(BufferedOutputStream(System.out)))\n a.run()\n a.flush()\n a.out.close()\n } else {\n val t = Main(FileInputStream(\"input.txt\"), PrintWriter(BufferedOutputStream(System.out)))\n while (t.hasNext()) {\n val name = t.nline()\n t.log(\"##### Test $name #####\")\n val startTime = System.currentTimeMillis()\n t.run()\n val endTime = System.currentTimeMillis()\n t.log(endTime - startTime, \"Total Time\")\n t.log()\n t.flush()\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "3233a2d80effd884785791b1078cbec2", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = reader.nextInt()\n val player = BooleanArray(3) { it < 2 }\n for (i in 0 until n) {\n val x = reader.nextInt() - 1\n if (!player[x]) {\n writer.println(\"NO\")\n return\n }\n\n val visor = player.indexOf(false)\n for (j in player.indices) {\n if (player[j] && j != x) {\n player[j] = false\n break\n }\n }\n player[visor] = true\n }\n writer.println(\"YES\")\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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8cc5d08bd12231c75e8a490df7743538", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["greedy", "dp", "implementation"], "code_uid": "5b649872e7265072a46d6e43335556db", "src_uid": "75d062cece5a2402920d6706c655cad7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp", "implementation"], "code_uid": "6d57cd51c45c526adafb5a4306160ad9", "src_uid": "75d062cece5a2402920d6706c655cad7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 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}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp", "implementation"], "code_uid": "f841bbfaa4a28f81756029f3b78f225a", "src_uid": "75d062cece5a2402920d6706c655cad7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["greedy", "dp", "implementation"], "code_uid": "7f05cf4af263567b46209236286a0379", "src_uid": "75d062cece5a2402920d6706c655cad7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package com.happypeople.codeforces.c1131\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\n\nfun main(args: Array) {\n try {\n A1131().run()\n } catch (e: Throwable) {\n println(\"\")\n e.printStackTrace()\n }\n}\n\nclass A1131 {\n fun run() {\n val sc = Scanner(systemIn())\n val w1=sc.nextInt()\n val h1=sc.nextInt()\n val w2=sc.nextInt()\n val h2=sc.nextInt()\n\n val lb1=Pair(1, 1)\n val rt1=Pair(w1, h1)\n val lb2=Pair(1, h1+1)\n val rt2=Pair(w2, h1+h2)\n\n var ans=(w1+2)+(h1*2) + (h2*2) + 2 + w2 + (w1-w2)\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}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "fccc70ecca37d822429799f58f14f007", "src_uid": "b5d44e0041053c996938aadd1b3865f6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main(args: Array) {\n val (w1, h1, w2, h2) = readLine()!!.split(\" \").map(String::toInt)\n val answer = 2 * (h1 + h2) + 2 * max(w1, w2) + 4\n println(answer)\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "73fec6ae1b01453b78fdbbc2ad391b9b", "src_uid": "b5d44e0041053c996938aadd1b3865f6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Math.abs\n\nfun main() {\n val (w1, h1, w2, h2) = readLine()!!.split(' ').map(String::toInt)\n print(w1 + w2 + 4 + 2 * (h1 + h2) + abs(w1 - w2))\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "2c2c738384b9efe84164c89b53774930", "src_uid": "b5d44e0041053c996938aadd1b3865f6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 w1 = reader.nextInt()\n val h1 = reader.nextInt()\n val w2 = reader.nextInt()\n val h2 = reader.nextInt()\n\n val ans = (w1 + 2 * h1 + 2) + (w2 + 2 * h2 + 2) + (w1 - w2)\n writer.println(ans)\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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "823e7f4ec79ec784ec3fdf15c2bf2d75", "src_uid": "b5d44e0041053c996938aadd1b3865f6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "b1907cd2e996024cbdb8c24a2320b38d", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "0f9b83fc187dd9a3e8d794128c19482d", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "99054327768bbedbc1f6f88fcfba3e20", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a4a2e21917a3f41c8856bd29359b7641", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n val board = Array(8) { CharArray(8) }\n for (numRow in 0 until 8)\n board[numRow] = readLine()!!.toCharArray()\n var bestB = Int.MAX_VALUE\n var bestW = Int.MAX_VALUE\n for (row in 0 until 8)\n loop@ for (column in 0 until 8) {\n when (board[row][column]) {\n 'B' -> {\n for (rowCheck in row + 1 until 8)\n if (board[rowCheck][column] == 'W') continue@loop\n bestB = min(bestB, 7 - row)\n }\n 'W' -> {\n for (rowCheck in row - 1 downTo 0)\n if (board[rowCheck][column] == 'B') continue@loop\n bestW = min(bestW, row)\n }\n }\n }\n print(if (bestB < bestW) 'B' else 'A')\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5c21beebfc7a0e367619190ea5836c0d", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Integer.min\n\nfun main(args: Array) {\n var t = arrayListOf()\n repeat(8) { t.add(readLine()!!) }\n var (a, b) = 8 to 8\n for (i in 0..7) {\n t.map { it[i] }.foldIndexed(false to 8) { i, acc, c ->\n var (metB, bestB) = acc\n if (c == 'W') bestB = 8\n if (c == 'W' && !metB) a = min(a, i)\n if (c == 'B') {\n metB = true\n bestB = 7 - i\n }\n\n metB to bestB\n }.let { b = min(b, it.second) }\n }\n print(if (b < a) \"B\" else \"A\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "54beb2ad351a37698ea4fb266cdecead", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Integer.min\n\nfun main(args: Array) {\n var t = arrayListOf()\n repeat(8) { t.add(readLine()!!) }\n var (a, b) = 8 to 8\n for (i in 0..7) {\n t.map { it[i] }.foldIndexed(false to 8) { i, acc, c ->\n val (metB, _) = acc\n when {\n c == 'W' && !metB -> {\n a = min(a, i)\n acc\n }\n c == 'W' -> metB to 8\n c == 'B' -> true to 7 - i\n else -> acc\n }\n }.let { b = min(b, it.second) }\n }\n print(if (b < a) \"B\" else \"A\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d6c36773467a02b7bbcfb1c4c50fd14c", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "number theory"], "code_uid": "2676c9e66810b534f62dcbe03730adbe", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "number theory"], "code_uid": "73d612cf1da436a041d267d04ede0c57", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "number theory"], "code_uid": "07e3e159b33b551b96f28c1ae776f544", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "number theory"], "code_uid": "199c45b390a071b926c65b5fc717ccf0", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4f5b2217025b8f5f8fbc3165b25f0787", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2e546b8490723c4f66dc38f31b2d41b4", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "1328e11eb52ec04c12dd0952ecd236c9", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2c17e0332446ae4012d06ebfaf39ec08", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val digitToOptions = listOf(2, 7, 2, 3, 3, 4, 2, 5, 1, 2)\n// print(readLine()!!.fold(1) { acc, c -> acc * digitToOptions[c - '0'] }) // A shorter alternative, less readable\n var sol = 1\n for (c in readLine()!!) sol *= digitToOptions[c - '0']\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7dece2cfb0cba3e3d751886af7546961", "src_uid": "76c8bfa6789db8364a8ece0574cd31f5", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val a = readLine()!!\n var count = 0\n for (i in 0 until a.length-2) {\n for (j in i+1 until a.length-1) {\n for (k in j+1 until a.length) {\n if (a[i] == 'Q' && a[j] == 'A' && a[k] == 'Q') count++\n }\n }\n }\n println(count)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "dp"], "code_uid": "f91ae81f73991133335dc20c4d913a19", "src_uid": "8aef4947322438664bd8610632fe0947", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val inStr= readLine()!!\n val aIndexes=inStr.withIndex().filter { (index, value)->value=='A' }\n val qIndexes=inStr.withIndex().filter { (index, value)->value=='Q' }\n var smileQantity=0\n for ((firstInd, firstA) in qIndexes){\n for((secondInd, secondQ) in aIndexes.filter { (index, value)->index>firstInd }){\n for((thirdInd, thirdA)in qIndexes.filter { (index, value)->index>secondInd }){\n smileQantity+=1\n }\n }\n }\n print(smileQantity)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "dp"], "code_uid": "668f3278cc2706d909de4ad53c07aab1", "src_uid": "8aef4947322438664bd8610632fe0947", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\n val s = sc.next()\n val n = s.length\n\n var count = 0\n for (i in 0 until n) {\n for (j in i + 1 until n) {\n for (k in j + 1 until n) {\n if (s[i].toString() + s[j] + s[k] == \"QAQ\") {\n count += 1\n }\n }\n }\n }\n\n println(count)\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", "lang_cluster": "Kotlin", "tags": ["brute force", "dp"], "code_uid": "f071bb7d34df83e8df830069fb9a84e2", "src_uid": "8aef4947322438664bd8610632fe0947", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 val indexOfQ = mutableListOf()\n val indexOfA = mutableListOf()\n val str = r.readLine()!!\n val len = str.length\n val countQ = IntArray(len){0}\n val countA = IntArray(len){0}\n for (i in 0..len-1){\n when(str[i]){\n 'Q' -> {\n indexOfQ += i\n indexOfA.forEach { countQ[it]++ }\n }\n 'A' -> {\n indexOfA += i\n indexOfQ.forEach { countA[it]++ }\n }\n }\n }\n var ans = 0\n for (iq in indexOfQ){\n for (ia in indexOfA){\n if (ia>iq) ans += countQ[ia]\n }\n }\n \n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "dp"], "code_uid": "02d3366cf549c61eaf84bd3b623818c0", "src_uid": "8aef4947322438664bd8610632fe0947", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 for (i in 0 until 8) {\n val str = scanner.next()\n for (j in 0 until 8) {\n if (str[(j + 1) % 8] == str[j]) {\n println(\"NO\")\n return\n }\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//}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings"], "code_uid": "9f3e65c6346f2cecf969eff89d71ce60", "src_uid": "ca65e023be092b2ce25599f52acc1a67", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedInputStream\nimport java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(BufferedInputStream(System.`in`))\n\n var ok = true\n for(i in 1..8){\n val row: String = scanner.next()\n ok = ok and isGood(row)\n if(!ok) break\n }\n\n if(ok) print(\"YES\")\n else print(\"NO\")\n\n}\n\nfun isGood(str: String): Boolean{\n var cur = 'X'\n for(c in str){\n if(cur == c) return false\n cur = c\n }\n return true\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings"], "code_uid": "5bdcf4068eba699cf90e9c92ac7cd370", "src_uid": "ca65e023be092b2ce25599f52acc1a67", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n\n var sc = Scanner(System.`in`)\n var n = sc.nextInt()\n var x=0\n var max = 0\n for (i in 0 .. n-1){\n x=sc.nextInt()\n max= maxOf(x,max)\n }\n max = maxOf(0,max-25)\n println(max)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "955b13506f9109a007b3c5fb984ebf96", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.IOException\nimport java.io.PrintWriter\nimport java.util.*;\n\nfun main() {\n val scan = FastReader()\n val out = PrintWriter(System.out)\n\n var k = scan.nextInt()\n var ans = 0\n for(i in 1..k) ans = Math.max(ans, scan.nextInt())\n out.println(Math.max(0, ans - 25))\n\n out.close()\n}\n\nprivate class FastReader {\n var st: StringTokenizer? = null;\n\n fun next(): String {\n while(st == null || !st!!.hasMoreTokens()) {\n try {\n st = StringTokenizer(readLine()!!)\n }\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 fun nextLong(): Long {\n return next().toLong()\n }\n\n fun nextDouble(): Double {\n return next().toDouble()\n }\n\n fun nextLine(): String {\n var str = \"\"\n try {\n str = readLine()!!\n }\n catch (e : IOException) {\n e.printStackTrace()\n }\n return str\n }\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "65f89bec7c6c5bffc9759eb813d62e2d", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main() {\n readInt()\n println(max(25, readInts().maxOrNull()!!) - 25)\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\nprivate fun readStrings() = readLn().trim().split(\" \")\nprivate fun readInt() = readLn().toInt()\nprivate fun readInts() = readStrings().map { it.toInt() }\n", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "8004dc84ebbd58d1f4cfa99d142ec587", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\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 n = readInt()\n val maxRank = readInts().max()!!\n println(max(0, maxRank - 25))\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "5dedaddc490a8ce1504aaa9776a87e71", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.math.BigInteger\n\nfun main(args: Array) {\n val sb = StringBuilder()\n val nums = Array(10, { i-> BigInteger(\"$i\") })\n val FOUR = nums[4]\n var x = BigInteger(readLine())\n do {\n val divideAndRemainder = x.divideAndRemainder(BigInteger.TEN)\n val div = divideAndRemainder[0]\n val rem = divideAndRemainder[1]\n if (div == BigInteger.ZERO) {\n var num:BigInteger\n if (rem.toInt() != 9) {\n num = if (rem > FOUR) nums[9 - rem.toInt()] else rem\n } else {\n num = rem\n }\n sb.insert(0, num)\n println(sb)\n return\n } else {\n val num = if (rem > FOUR) nums[9 - rem.toInt()] else rem\n sb.insert(0, num)\n }\n x = div\n } while (true)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "993f3ddcca2e0c6197a7e5f8c96dac7a", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array){\n //val ( n, m ) = readLine()!!.split(' ').map(String::toInt)\n var s = readLine()!!\n print( if( s[0] >= '5' && s[0] != '9' ) '9' - s[0] else s[0] )\n s = s.removeRange(0, 1)\n for( i in s ){\n print( if ( i >= '5' ) '9' - i else i )\n }\n}\n\n", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "867fe093018cddee9ca0b138013b1a4e", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n \nfun main(args: Array){\n //val ( n, m ) = readLine()!!.split(' ').map(String::toInt)\n var s = readLine()!!\n print( if( s[0] >= '5' && s[0] != '9' ) '9' - s[0] else s[0] )\n s = s.removeRange(0, 1)\n for( i in s ){\n print( if ( i >= '5' ) '9' - i else i )\n }\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "aa1f17de62a083d99c902238a9e32306", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n \nfun main(args: Array){\n //val ( n, m ) = readLine()!!.split(' ').map(String::toInt)\n var s = readLine()!!\n print( if( s[0] >= '5' && s[0] != '9' ) '9' - s[0] else s[0] )\n s = s.removeRange(0, 1)\n for( i in s ){\n print( if ( i >= '5' ) '9' - i else i )\n }\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "b927f26ddae85ceee62906d8f8dd3531", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 \u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u043f\u0430\u0440 - k=v.sortedWith(compareBy({it.first},{it.second})); \n print(\"${k[i].second}\"); - \u0432\u044b\u0432\u043e\u0434 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043f\u0430\u0440\u044b \n var m=ArrayList (); <=> vector \n getline(cin,a) <=> readLine()!!.last()\n \n readInt() - \u043e\u0434\u043d\u043e \u0447\u0438\u0441\u043b\u043e \n readInts() - \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u0435\u043b \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 ", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a9c71482f46510e22ba4dd29a7c06783", "src_uid": "496baae594b32c5ffda35b896ebde629", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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})", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "22f2040bcea0074f1fa652167f8a49dd", "src_uid": "496baae594b32c5ffda35b896ebde629", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\n fun summ(n: Int): Int {\n return n * (n + 1) / 2\n }\n fun len(nn: Int): Int {\n var n = nn\n var res = 0\n while(n > 0) {\n res++\n n /= 10\n }\n return res\n }\n\n var T = readInt()\n while(T-->0) {\n var num = readInt()\n var less = (num%10)-1\n var res = summ(4) * less\n res += summ(len(num))\n\n println(res)\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "b197f32d6d8d14d3259fb8738a48beaa", "src_uid": "289a55128be89bb86a002d218d31b57f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val q = readInt()\n\n readMultiLineIntList(q) {\n val num = it.toString()[0].toString().toInt()\n orderln(when(it.toString().length) {\n 1 -> \"${((num - 1) * 10 + 1)}\"\n 2 -> \"${((num - 1) * 10 + 3)}\"\n 3 -> \"${((num - 1) * 10 + 6)}\"\n 4 -> \"${(num * 10)}\"\n else -> \"\"\n })\n }\n\n drop()\n}\n\n// region Technolib\n/*\n Author: Timofey Chicherin (TimDev, TwMicro)\n Collaborators: [no]\n License: Apache License 2.0\n GitHub: https://github.com/twmicro/technolib/\n*/\n\nvar toPrint = \"\"\n/*\n readLines -\n Reads a count of lines\n*/\n\n// Simple variant\nfun readLines(count: Int): MutableList {\n val lines = mutableListOf()\n for (i in 0 until count) lines.add(readLine()!!)\n return lines\n}\n\n// Inline variant, works like forEach\ninline fun readLines(count: Int, action: (String) -> Unit): MutableList {\n val lines = mutableListOf()\n for (i in 0 until count) {\n lines.add(readLine()!!)\n action.invoke(lines.last())\n }\n return lines\n}\n\n\n/*\n readMultiLineIntList -\n Reads a count of lines and converts it to MutableList\n*/\n\n// Simple variant\nfun readMultiLineIntList(count: Int): MutableList {\n val lines = mutableListOf()\n for (i in 0 until count) lines.add(readLine()!!.toInt())\n return lines\n}\n\n// Inline variant, works like forEach\ninline fun readMultiLineIntList(count: Int, action: (Int) -> Unit): MutableList {\n val lines = mutableListOf()\n for (i in 0 until count) {\n lines.add(readLine()!!.toInt())\n action.invoke(lines.last())\n }\n return lines\n}\n\n\n/*\n readIntList -\n Reads single line of integers\n*/\n\n// Simple variant\nfun readIntList(seperator: String = \" \"): MutableList = readLine()!!.split(seperator).toIntList()\n\n// Inline variant, works like forEach\nfun readIntList(seperator: String = \" \", action: (Int) -> Unit) = readIntList(seperator).forEach(action)\n\n/*\n List.toIntList -\n Converts string list to int list\n*/\n\nfun List.toIntList(): MutableList {\n val result = mutableListOf()\n forEach {\n result.add(it.toInt())\n }\n return result\n}\n\n/*\n order(ln) -\n Adds text to print stack. Don't forget to use drop() or dropln() in the end of your program!\n (ln) - adds \\n to the end of text\n*/\n\nfun order(text: String) {\n toPrint += text\n}\n\nfun orderln(text: String) {\n toPrint += text + \"\\n\"\n}\n\n/*\n drop(ln) -\n Prints all the text from the print stack\n*/\nfun drop() = print(toPrint)\nfun dropln() = println(toPrint)\n\n/*\n readInt -\n Shortcut for readLine()!!.toInt()\n*/\nfun readInt(): Int = readLine()!!.toInt()\n// endregion", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "ec2af860508781c628c3340f3f7b9a57", "src_uid": "289a55128be89bb86a002d218d31b57f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nfun main(){\n val stores = IntArray(36){0}\n stores[0] = 1\n var i = 1\n for(s in 1 until stores.size){\n when(i%4){\n 0->{\n stores[i] += stores[i-1] + 1\n }\n 1->{\n stores[i] += stores[i-1] + 2\n }\n 2->{\n stores[i] += stores[i-1] + 3\n }\n 3->{\n stores[i] += stores[i-1] + 4\n }\n }\n ++i\n }\n val testCase = readLine()!!.toInt()\n for(i in 0 until testCase){\n var x = readLine()!!\n println(stores[(x.substring(0,1).toInt()-1)*4+x.length-1])\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "e622d361986ffdb4b6ea0aa29b20a22d", "src_uid": "289a55128be89bb86a002d218d31b57f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun readInt() = readLine()!!.toInt()\nfun readInts() = readLine()!!.split(' ').map { it.toInt() }\n\nfun main() {\n repeat(readInt()) {\n val x = readInt()\n println((x%10 - 1)*sum(4) + sum(x.toString().length))\n }\n}\n\nfun sum(i: Int): Int = i*(i+1)/2\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "9a97b9a1d562d7e71a6410cea29e4e62", "src_uid": "289a55128be89bb86a002d218d31b57f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (n, a, b, c) = readInts()\n val dp = IntArray(n + 1) { Int.MIN_VALUE }\n dp[0] = 0\n for (pos in 0 .. n) {\n if (pos - a >= 0) dp[pos] = max(dp[pos], dp[pos - a] + 1)\n if (pos - b >= 0) dp[pos] = max(dp[pos], dp[pos - b] + 1)\n if (pos - c >= 0) dp[pos] = max(dp[pos], dp[pos - c] + 1)\n }\n print(dp[n])\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "dp"], "code_uid": "62ae889ce4ae9f0230f29e3785094a73", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 v = IntArray(3, { io.readInt() })\n val d = IntArray(n + 1, { -1 })\n d[0] = 0\n for (i in 1 .. n) {\n d[i] = v.map({ c -> if (i >= c && d[i - c] != -1) d[i - c] + 1 else -1}).max()!!\n }\n io.println(d[n])\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "dp"], "code_uid": "4d5f016f6fdce542e02f91b82e9d55c3", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport kotlin.math.max\n\nsealed class Result {\n companion object {\n val FAILURE = Failure()\n }\n data class Success(val value: Int):Result()\n class Failure():Result()\n}\n\nvar a = 0\nvar b = 0\nvar c = 0\nval map = mutableMapOf, Int>, Result>()\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val nabc = br.readLine().split(\" \").map { it.toInt() }\n val n = nabc[0]\n val ribbons = nabc.drop(1)\n val ans = findMaxPieces(ribbons, n)\n\n println(if (ans is Result.Success) ans.value else -1)\n\n}\n\nfun findMaxPieces(ribbons: List, n: Int): Result{\n val key = ribbons to n\n if (key in map) return map[key]!!\n\n val result = if (n == 0){\n Result.Success(0)\n }\n else if (n < 0){\n Result.FAILURE\n }\n else if (ribbons.isEmpty()) {\n Result.FAILURE\n } else {\n val left = findMaxPieces(ribbons, n - ribbons[0])\n val right = findMaxPieces(ribbons.drop(1), n)\n if (left is Result.Failure && right is Result.Failure)\n Result.FAILURE\n else if (left is Result.Failure)\n right\n else if (right is Result.Failure && left is Result.Success)\n Result.Success(left.value + 1)\n else if(left is Result.Success && right is Result.Success)\n Result.Success(max(left.value + 1, right.value))\n else\n Result.FAILURE\n }\n map[key] = result\n return result\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "dp"], "code_uid": "079ad802b5c1cc70e1a7ff830fac3fda", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Integer.max\nimport java.util.*\nfun main(){\n val inputs = readLine()!!.split(\" \").map{it.toInt()}\n val n = inputs[0]\n val dp = Array(4){IntArray(n+1){0} }\n for(i in 1 until 4)\n for(j in 0 until n+1){\n if(j) {\n val n = readLine()!!.toInt()\n var mat = Array(n) {(IntArray(n))}\n for (i in 0..n-1) mat[0][i]=1\n for (i in 1..n-1) {\n mat[i][0]=mat[i-1][0]\n for (j in 1..n-1) mat[i][j]=mat[i-1][j]+mat[i][j-1]\n }\n print(mat[n-1][n-1])\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "bb101c1180abe9e476eda9b823a281db", "src_uid": "2f650aae9dfeb02533149ced402b60dc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()?.toInt() ?: 0\n val a = Array(n) {\n IntArray(n) { 1 }\n }\n\n println(findMax(a, 1, 1, n))\n}\n\nfun findMax(a: Array, startI: Int, startJ: Int, n: Int): Int {\n if (n == 1) {\n return 1\n }\n if (startI == n || startJ == n) {\n return 0\n }\n for (i in startI until n) {\n for (j in startJ until n) {\n a[i][j] = a[i - 1][j] + a[i][j - 1]\n findMax(a, i + 1, j + 1, n)\n }\n }\n return a[n - 1][n - 1]\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "676f8887631258cc21351d6de4cf1507", "src_uid": "2f650aae9dfeb02533149ced402b60dc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\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.nextLong()\n if (n < 3)\n println(n)\n else if (n % 2 == 1L)\n println(n * (n - 1) * (n - 2))\n else {\n var emaxx = (n - 1) * (n - 2) * (n - 3)\n for (i in max(n-5, 1)..n - 2)\n emaxx = max(nok(nok(i, n), n - 1), emaxx)\n println(emaxx)\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}\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)", "lang_cluster": "Kotlin", "tags": ["number theory"], "code_uid": "98c9d0d26d327c034f3a3844a38f409c", "src_uid": "25e5afcdf246ee35c9cef2fcbdd4566e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedInputStream\n\nfun main() {\n val pows = LongArray(40)\n pows[0] = 1L\n for (e in 1..39) {\n pows[e] = 7L * pows[e - 1]\n }\n val jin = FastScanner()\n val n = jin.nextInt().toLong()\n val m = jin.nextInt().toLong()\n var e = 1\n var pow = 7L\n while (pow < n) {\n e++\n pow *= 7L\n }\n var f = 1\n pow = 7L\n while (pow < m) {\n f++\n pow *= 7L\n }\n val used = mutableSetOf()\n var answer = 0\n var hour = 0L\n var minute = 0L\n fun recur(d: Int) {\n if (d == e + f) {\n if (hour < n && minute < m) {\n answer++\n }\n } else {\n for (digit in 0..6) {\n if (digit !in used) {\n used.add(digit)\n if (d < e) {\n hour += digit.toLong() * pows[d]\n } else {\n minute += digit.toLong() * pows[d - e]\n }\n recur(d + 1)\n if (d < e) {\n hour -= digit.toLong() * pows[d]\n } else {\n minute -= digit.toLong() * pows[d - e]\n }\n used.remove(digit)\n }\n }\n }\n }\n recur(0)\n println(answer)\n}\n\nclass FastScanner {\n private val BS = 1 shl 16\n private 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 private var `in`: BufferedInputStream? = null\n\n constructor() {\n `in` = BufferedInputStream(System.`in`, BS)\n }\n\n private val char: Char\n private get() {\n while (bId == size) {\n size = try {\n `in`!!.read(buf)\n } catch (e: Exception) {\n return NC\n }\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 >= '0' && c <= '9') {\n res = (res shl 3) + (res shl 1) + (c - '0')\n c = char\n }\n return if (neg) -res else res\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "dp", "combinatorics"], "code_uid": "9d7f4a73a2e0fadfa6e30a58ff114299", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedInputStream\nimport java.util.*\nimport kotlin.math.max\n\nfun main() {\n val jin = FastScanner()\n val n = jin.nextInt()\n val m = jin.nextInt()\n val q = jin.nextInt()\n val p = IntArray(n + 1)\n for (j in 1..n) {\n p[j] = jin.nextInt()\n }\n val edges = Array(m) {\n val a = jin.nextInt()\n val b = jin.nextInt()\n Edge(p[a], p[b])\n }\n val queries = Array(q) {\n val type = jin.nextInt()\n val param = jin.nextInt()\n if (type == 2) {\n edges[param - 1].removal = it\n }\n Query(type, param)\n }\n edges.sortByDescending { it.removal }\n val union = IntArray(n + 1) { it }\n val rank = IntArray(n + 1) { 1 }\n fun getUnion(u: Int): Int {\n if (union[u] != union[union[u]]) {\n union[u] = getUnion(union[u])\n }\n return union[u]\n }\n val children = Array(n + 1) { mutableListOf() }\n for (edge in edges) {\n val u = getUnion(edge.a)\n val v = getUnion(edge.b)\n if (u != v) {\n if (rank[u] > rank[v]) {\n children[u].add(v)\n union[v] = u\n rank[u] += rank[v]\n if (edge.removal < q) {\n queries[edge.removal].child = v\n }\n } else {\n children[v].add(u)\n union[u] = v\n rank[v] += rank[u]\n if (edge.removal < q) {\n queries[edge.removal].child = u\n }\n }\n }\n }\n val l = IntArray(n + 1)\n var currL = 1\n fun recur(a: Int) {\n l[a] = currL\n currL++\n for (b in children[a]) {\n recur(b)\n }\n }\n val treeSet = TreeSet()\n for (a in 1..n) {\n if (l[a] == 0) {\n treeSet.add(currL)\n recur(getUnion(a))\n }\n }\n treeSet.add(n + 1)\n val segTree = MaxSegmentTree(1, n)\n for (a in 1..n) {\n segTree[l[a]] = a\n }\n val out = StringBuilder()\n for (query in queries) {\n if (query.type == 1) {\n val a = p[query.param]\n val res = segTree[treeSet.floor(l[a])!!, treeSet.higher(l[a])!! - 1]\n //println(\"type 1 for $a -> ${Pair(treeSet.floor(l[a])!!, treeSet.higher(l[a])!! - 1)} => $res\")\n out.appendln(res)\n if (res != 0) {\n segTree[l[res]] = 0\n }\n } else {\n //println(\"bonk ${queries[j].child}\")\n if (query.child != 0) {\n treeSet.add(l[query.child])\n }\n }\n }\n print(out)\n}\n\nclass Edge(val a: Int, val b: Int) {\n var removal = 115115115\n}\n\nclass Query(val type: Int, val param: Int) {\n var child = 0\n}\n\nclass MaxSegmentTree(val treeFrom: Int, treeTo: Int) {\n val value: IntArray\n val length: Int\n\n init {\n var e = 0\n while (1 shl e < treeTo - treeFrom + 1) {\n e++\n }\n value = IntArray(1 shl (e + 1))\n length = 1 shl e\n }\n\n operator fun set(index: Int, delta: Int) {\n var node = index - treeFrom + length\n value[node] = delta\n node = node shr 1\n while (node > 0) {\n value[node] = max(value[node shl 1], value[(node shl 1) + 1])\n node = node shr 1\n }\n }\n\n operator fun get(index: Int) = value[index - treeFrom + length]\n\n operator fun get(fromIndex: Int, toIndex: Int): Int {\n if (toIndex < fromIndex) {\n return 0\n }\n var from = fromIndex + length - treeFrom\n var to = toIndex + length - treeFrom + 1\n var res: Int = Int.MIN_VALUE\n while (from + (from and -from) <= to) {\n res = max(res, value[from / (from and -from)])\n from += from and -from\n }\n while (to - (to and -to) >= from) {\n res = max(res, value[(to - (to and -to)) / (to and -to)])\n to -= to and -to\n }\n return res\n }\n}\n\nclass FastScanner {\n private val BS = 1 shl 16\n private 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 private var `in`: BufferedInputStream? = null\n\n constructor() {\n `in` = BufferedInputStream(System.`in`, BS)\n }\n\n private val char: Char\n private get() {\n while (bId == size) {\n size = try {\n `in`!!.read(buf)\n } catch (e: Exception) {\n return NC\n }\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 >= '0' && c <= '9') {\n res = (res shl 3) + (res shl 1) + (c - '0')\n c = char\n }\n return if (neg) -res else res\n }\n}", "lang_cluster": "Kotlin", "tags": ["dsu", "graphs", "data structures", "implementation", "trees"], "code_uid": "8c6b73fb1f8ee03ef9f7fc8c5474fe3e", "src_uid": "ad014bde729222db14f38caa521e4167", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport java.util.NoSuchElementException\nimport java.util.TreeSet\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 object {\n val n = readInt()\n val m = readInt()\n var q = readInt()\n\n val P = readIntArray(n)\n\n val A = IntArray(m)\n val B = IntArray(m) {\n A[it] = readInt() - 1\n readInt() - 1\n }\n\n val T = IntList()\n val X = IntList(q) {\n T.add(readInt())\n readInt() - 1\n }\n\n init {\n val E = BooleanArray(m)\n for(i in 0 until q) if(T[i] == 2) E[X[i]] = true\n for(i in 0 until m) if(!E[i]) {\n T.add(2)\n X.add(i)\n }\n q = T.size\n }\n\n val boss = IntList()\n val dsu = IntList(n) { it }\n val empty = IntList(0)\n val G = MutableList(n) { empty }\n\n fun addVertex(): Int {\n G.add(IntList(2))\n dsu.add(dsu.size)\n return dsu.lastIndex\n }\n\n tailrec fun root(v: Int): Int = if(dsu[v] == v) v else {\n dsu[v] = dsu[dsu[v]]\n root(dsu[v])\n }\n\n fun merge(u: Int, v: Int) {\n val ru = root(u)\n val rv = root(v)\n\n if(ru == rv) return\n\n val b = addVertex()\n dsu[ru] = b\n dsu[rv] = b\n G[b].add(ru)\n G[b].add(rv)\n }\n\n init {\n for(i in q-1 downTo 0) {\n val x = X[i]\n when(T[i]) {\n 1 -> boss.add(root(x))\n 2 -> merge(A[x], B[x])\n }\n }\n boss.reverse()\n\n val start = IntArray(dsu.size) { -1 }\n val end = IntArray(dsu.size)\n val stk = IntList()\n var eul = 0\n for(i in dsu.indices) if(start[i] == -1) {\n val r = root(i)\n stk.add(r)\n\n while(stk.isNotEmpty()) {\n val u = stk.pop()\n if(start[u] == -1) {\n start[u] = eul++\n stk.add(u)\n for(v in G[u]) stk.add(v)\n } else {\n end[u] = eul\n }\n }\n }\n\n val S = SegmentTree(eul)\n\n for(i in 0 until n) {\n val j = start[i]\n S.delayedSet(j, IntPair(P[i], j))\n }\n\n S.pushDelayed()\n\n for(b in boss) {\n val (x, j) = S[start[b], end[b]]\n println(x)\n S[j] = IntPair(0, j)\n }\n }\n\n }\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nclass SegmentTree(\n val size: Int) {\n\n val identityValue: IntPair = IntPair(-1, -1)\n inline fun combiner(a: IntPair, b: IntPair): IntPair = if(a.x >= b.x) a else b\n\n\n @Suppress(\"UNCHECKED_CAST\")\n val array = IntPairArray(size shl 1) { identityValue }\n\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n val asList: List by lazy {\n object : AbstractList() {\n override val size: Int get() = this@SegmentTree.size\n override fun get(index: Int): IntPair = this@SegmentTree[index]\n }\n }\n\n inline fun build(generator: (Int) -> IntPair) {\n for(i in 0 until size) {\n array[i + size] = generator(i)\n }\n for(i in size-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** alternative to build for arbitrary order **/\n fun delayedSet(i: Int, v: IntPair) { array[i + size] = v }\n fun pushDelayed() {\n for(i in size-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** instantiates values from an iterable, O(n) time */\n fun copyFrom(iterable: Iterable) {\n run {\n iterable.forEachIndexed { i, t ->\n if(i > lastIndex) return@run\n array[i + size] = t\n }\n }\n for(i in size-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Updates a value, O(log n) time */\n operator fun set(index: Int, value: IntPair) {\n require(index in 0 until size)\n var i = index + size\n array[i] = value\n while(true) {\n i = i shr 1\n if(i <= 0) break\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Gets a value by its index, O(1) time */\n operator fun get(index: Int): IntPair {\n require(index in 0 until size)\n return array[index + size]\n }\n\n /** gets the result of applying the monoid operation to the values in the index range, O(log n) time */\n operator fun get(start: Int, endExclusive: Int): IntPair {\n var l = maxOf(start, 0) + size\n var r = minOf(endExclusive, size) + size\n\n // two accumulators to support non-commutative monoids\n var lAcc = identityValue\n var rAcc = identityValue\n\n while(l < r) {\n if(l and 1 == 1) {\n lAcc = combiner(lAcc, array[l++])\n }\n if(r and 1 == 1) {\n rAcc = combiner(array[--r], rAcc)\n }\n\n l = l shr 1\n r = r shr 1\n }\n\n return combiner(lAcc, rAcc)\n }\n\n operator fun get(range: IntRange) = get(range.first, range.last + 1)\n}\n\nfun Int.bitConcat(other: Int) = toLong().shl(32) or other.toLong().and(0xffff_ffff)\n\ninline class IntPair(val data: Long) {\n val x get() = (data shr 32).toInt()\n val y get() = data.toInt()\n inline operator fun component1() = x\n inline operator fun component2() = y\n\n override fun toString() = \"($x, $y)\"\n}\nfun IntPair(x: Int, y: Int) = IntPair(x.bitConcat(y))\nfun unorderedPair(x: Int, y: Int) = if(x < y) IntPair(x, y) else IntPair(y, x)\n\ninline class IntPairArray(val longArray: LongArray): Collection {\n inline operator fun get(i: Int) = IntPair(longArray[i])\n inline operator fun set(i: Int, v: IntPair) { longArray[i] = v.data }\n\n override inline val size: Int get() = longArray.size\n inline val lastIndex get() = longArray.lastIndex\n inline val indices get() = longArray.indices\n\n override inline fun contains(element: IntPair): Boolean = element.data in longArray\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override inline fun isEmpty(): Boolean = longArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): IntPair = get(index++)\n }\n\n fun copyOf(newSize: Int) = IntPairArray(longArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun IntPairArray.copyInto(destination: IntPairArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =\n IntPairArray(longArray.copyInto(destination.longArray, destinationOffset, startIndex, endIndex))\ninline fun IntPairArray(size: Int) = IntPairArray(LongArray(size))\ninline fun IntPairArray(size: Int, init: (Int) -> IntPair) = IntPairArray(LongArray(size) { init(it).data })\n\n\ninline fun IntPairArray.first() = get(0)\ninline fun IntPairArray.last() = get(lastIndex)\ninline fun IntPairArray.fold(init: R, op: (acc: R, IntPair) -> R) = longArray.fold(init) { acc, i -> op(acc, IntPair(i)) }\ninline fun IntPairArray.foldRight(init: R, op: (IntPair, acc: R) -> R) = longArray.foldRight(init) { i, acc -> op(\n IntPair(i), acc) }\n\nclass IntList(initialCapacity: Int = 12) {\n private var _arr = IntArray(initialCapacity)\n private val capacity get() = _arr.size\n var size = 0\n private set\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n\n constructor(copyFrom: IntArray): this(copyFrom.size) { copyFrom.copyInto(_arr); size = copyFrom.size }\n constructor(copyFrom: Collection): this(copyFrom.size) { _arr = copyFrom.toIntArray(); size = copyFrom.size }\n\n fun contentEquals(other: IntList): Boolean {\n return this === other || size == other.size && indices.all { this[it] == other[it] }\n }\n\n private fun grow(minCapacity: Int = 8) {\n val newCapacity = maxOf(minCapacity, capacity + (capacity shr 1))\n _arr = _arr.copyOf(newCapacity)\n }\n\n fun ensureCapacity(minCapacity: Int) { if(capacity < minCapacity) grow(minCapacity) }\n\n operator fun get(index: Int): Int {\n require(index in 0 until size)\n return _arr[index]\n }\n\n operator fun set(index: Int, value: Int) {\n require(index in 0 until size)\n _arr[index] = value\n }\n\n fun add(value: Int) {\n if(size == capacity) grow()\n _arr[size++] = value\n }\n\n fun addAll(list: IntList) {\n ensureCapacity(size + list.size)\n list._arr.copyInto(_arr, size, 0, list.size)\n size += list.size\n }\n\n fun add(index: Int, element: Int) {\n if(size == capacity) grow()\n _arr.copyInto(_arr, index + 1, index, size)\n size++\n set(index, element)\n }\n\n fun clear() { size = 0 }\n\n fun removeAt(index: Int): Int {\n val e = get(index)\n _arr.copyInto(_arr, index, index + 1, size)\n size--\n return e\n }\n\n fun indexOf(e: Int): Int {\n for(i in 0 until size) if(this[i] == e) return i\n return -1\n }\n\n fun remove(e: Int): Boolean {\n val i = indexOf(e)\n if(i == -1) return false\n removeAt(i)\n return true\n }\n\n operator fun iterator() = object: IntIterator() {\n private var pos = 0\n override fun hasNext() = pos < size\n override fun nextInt() = get(pos++)\n }\n\n inline fun isEmpty() = size == 0\n inline fun isNotEmpty() = size != 0\n\n fun pop() = _arr[--size]\n\n fun popToSize(s: Int) {\n require(s >= 0)\n if(s < size) size = s\n }\n\n fun swap(i: Int, j: Int) { val t = this[i]; this[i] = this[j]; this[j] = t }\n fun reverse() {\n for(i in 0 until size / 2) swap(i, lastIndex - i)\n }\n\n fun shuffle(rnd: Random = random) { for(i in lastIndex downTo 1) swap(i, rnd.nextInt(i + 1)) }\n fun sort() { shuffle(); _arr._sort(0, size) }\n fun sortDescending() { sort(); reverse() }\n\n fun joinToString(separator: CharSequence) = if(size == 0) \"\" else let {\n buildString {\n append(it[0])\n for (i in 1 until size) {\n append(separator).append(it[i])\n }\n }\n }\n\n override fun toString() = \"[\" + joinToString(\", \") + \"]\"\n\n fun toIntArray() = _arr.copyOf(size)\n fun toList() = List(size, ::get)\n\n inline fun first() = get(0)\n inline fun last() = get(lastIndex)\n}\n\ninline fun IntList(size: Int, init: (Int) -> Int) = IntList(size).apply {\n for(i in 0 until size) { add(init(i)) }\n}\ninline fun IntArray.toIntList() = IntList(this)\ninline fun Collection.toIntList() = IntList(this)\ninline fun intListOf(vararg values: Int) = IntList(values)\n\nfun IntList.max() = (1 until size).fold(this[0]) { acc, i -> max(acc, this[i]) }\nfun IntList.min() = (1 until size).fold(this[0]) { acc, i -> min(acc, this[i]) }\nfun IntList.getOrNull(i: Int) = if(i in indices) get(i) else null\ninline fun IntList.count(predicate: (Int) -> Boolean) = indices.count { predicate(this[it]) }\nfun IntList.copyOf() = IntList(size, ::get)\n\n/** IO */\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()\n 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\nfun IntArray.sort() { shuffle(random); _sort() }\nfun IntArray.sortDescending() { shuffle(random); _sortDescending() }\n\nfun LongArray.sort() { shuffle(random); _sort() }\nfun LongArray.sortDescending() { shuffle(random); _sortDescending() }\n\nfun DoubleArray.sort() { shuffle(random); _sort() }\nfun DoubleArray.sortDescending() { shuffle(random); _sortDescending() }\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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { iprintln(max(1, 2)) }\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 }", "lang_cluster": "Kotlin", "tags": ["dsu", "graphs", "data structures", "implementation", "trees"], "code_uid": "97677743a00cdc467e476af718808c4e", "src_uid": "ad014bde729222db14f38caa521e4167", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport java.util.function.BiFunction\nimport kotlin.collections.ArrayList\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\nfun main(args: Array) {\n val thread = Thread(null, TaskAdapter(), \"\", 1 shl 28)\n thread.start()\n thread.join()\n}\n\ninternal class TaskAdapter : Runnable {\n override fun run() {\n val startTime = System.currentTimeMillis()\n val inputStream = System.`in`\n val outputStream: OutputStream = System.out\n val `in` = FastReader(inputStream)\n val out = Output(outputStream)\n val solver = DGraphAndQueries()\n solver.solve(1, `in`, out)\n out.close()\n System.err.println((System.currentTimeMillis() - startTime).toString() + \"ms\")\n }\n}\n\ninternal class DGraphAndQueries {\n lateinit var arr: IntArray\n lateinit var parent: IntArray\n lateinit var tin: IntArray\n lateinit var tout: IntArray\n var n = 0\n var ind = 0\n var clock = 0\n lateinit var visited: BitSet\n lateinit var tour: Array>\n lateinit var graph: Array>\n fun find(u: Int): Int {\n return if (parent[u] == u) u else find(parent[u]).also { parent[u] = it }\n }\n\n fun merge(p: Pair) {\n val u = find(p.a)\n val v = find(p.b)\n if (u == v) {\n return\n }\n val next = ind++\n parent[v] = next\n parent[u] = parent[v]\n graph[next] = ArrayList(Arrays.asList(u, v))\n }\n\n fun dfs(u: Int) {\n tour[clock] = Pair(arr[u], clock++.also { tin[u] = it })\n if (u >= n) {\n for (v in graph[u]) {\n dfs(v)\n }\n }\n tout[u] = clock - 1\n }\n\n fun solve(kase: Int, `in`: InputReader, pw: Output) {\n n = `in`.nextInt()\n val m = `in`.nextInt()\n val q = `in`.nextInt()\n arr = IntArray(n + q)\n Arrays.fill(arr, -1)\n parent = IntArray(n + q)\n graph = Array(n + q) { ArrayList() }\n ind = n\n for (i in 0 until n) {\n arr[i] = `in`.nextInt()\n }\n for (i in 0 until n + q) {\n parent[i] = i\n }\n val edges: Array> = Array(m) { Pair(0, 0) }\n for (i in 0 until m) {\n edges[i] = Pair(`in`.nextInt() - 1, `in`.nextInt() - 1)\n }\n val marked = BitSet(m)\n val queries = Array(q) { IntArray(2) }\n for (i in 0 until q) {\n queries[i] = intArrayOf(`in`.nextInt(), `in`.nextInt() - 1)\n if (queries[i][0] == 2) {\n marked.set(queries[i][1])\n }\n }\n for (i in 0 until m) {\n if (!marked[i]) {\n merge(edges[i])\n }\n }\n for (i in q - 1 downTo 0) {\n if (queries[i][0] == 2) {\n merge(edges[queries[i][1]])\n } else {\n queries[i][1] = find(queries[i][1])\n }\n }\n// Utilities.Debug.dbg(ind)\n// Utilities.Debug.dbg(*graph)\n tour = Array(ind) { Pair(0, 0) }\n tin = IntArray(ind)\n tout = IntArray(ind)\n visited = BitSet(ind)\n clock = 0\n for (i in 0 until n) {\n val u = find(i)\n if (!visited[u]) {\n dfs(u)\n visited.set(u)\n }\n }\n// Utilities.Debug.dbg(*tour)\n val st = TPointSegmentTree(tour, BiFunction { t, u -> if (t.a >= u.a) t else u })\n for (query in queries) {\n if (query[0] == 1) {\n val u = query[1]\n val v = st.query(tin[u], tout[u])!!\n Utilities.Debug.dbg(u, v)\n pw.println(v.a)\n st[v.b] = Pair(0, v.b)\n }\n }\n }\n}\n\ninternal class TPointSegmentTree(arr: Array, operation: BiFunction) {\n var n: Int\n var ind = 0\n var ql = 0\n var qr = 0\n var arr: Array\n var value: Array\n var operation: BiFunction\n private fun build(o: Int, l: Int, r: Int) {\n if (l == r) {\n value[o] = arr[l]\n return\n }\n val lc = o shl 1\n val rc = lc or 1\n val mid = l + r shr 1\n build(lc, l, mid)\n build(rc, mid + 1, r)\n value[o] = value[lc]?.let { value[rc]?.let { it1 -> operation.apply(it, it1) } }\n }\n\n private operator fun set(o: Int, l: Int, r: Int) {\n if (l == r) {\n value[o] = arr[l]\n return\n }\n val lc = o shl 1\n val rc = lc or 1\n val mid = l + r shr 1\n if (ind <= mid) {\n set(lc, l, mid)\n } else {\n set(rc, mid + 1, r)\n }\n value[o] = value[lc]?.let { value[rc]?.let { it1 -> operation.apply(it, it1) } }\n }\n\n operator fun set(ind: Int, `val`: T) {\n this.ind = ind\n arr[ind] = `val`\n set(1, 0, n - 1)\n }\n\n private fun query(o: Int, l: Int, r: Int): T? {\n if (ql <= l && qr >= r) {\n return value[o]\n }\n val lc = o shl 1\n val rc = lc or 1\n val mid = l + r shr 1\n var ret: T? = null\n if (ql <= mid) {\n ret = query(lc, l, mid)\n }\n if (qr > mid) {\n ret = if (ret == null) {\n query(rc, mid + 1, r)\n } else {\n query(rc, mid + 1, r)?.let { operation.apply(ret!!, it) }\n }\n }\n return ret\n }\n\n fun query(l: Int, r: Int): T? {\n ql = l\n qr = r\n return query(1, 0, n - 1)\n }\n\n init {\n n = arr.size\n this.arr = arr\n value = arrayOfNulls(n shl 2) as Array\n this.operation = operation\n build(1, 0, n - 1)\n }\n}\n\ninternal class Utilities {\n object Debug {\n val LOCAL = System.getProperty(\"ONLINE_JUDGE\") == null\n private fun ts(t: T?): String {\n return if (t == null) {\n \"null\"\n } else try {\n ts(t as Iterable<*>)\n } catch (e: ClassCastException) {\n if (t is IntArray) {\n val s = Arrays.toString(t as IntArray?)\n return \"{\" + s.substring(1, s.length - 1) + \"}\"\n } else if (t is LongArray) {\n val s = Arrays.toString(t as LongArray?)\n return \"{\" + s.substring(1, s.length - 1) + \"}\"\n } else if (t is CharArray) {\n val s = Arrays.toString(t as CharArray?)\n return \"{\" + s.substring(1, s.length - 1) + \"}\"\n } else if (t is DoubleArray) {\n val s = Arrays.toString(t as DoubleArray?)\n return \"{\" + s.substring(1, s.length - 1) + \"}\"\n } else if (t is BooleanArray) {\n val s = Arrays.toString(t as BooleanArray?)\n return \"{\" + s.substring(1, s.length - 1) + \"}\"\n }\n try {\n ts(t as Array)\n } catch (e1: ClassCastException) {\n t.toString()\n }\n }\n }\n\n private fun ts(arr: Array): String {\n val ret = StringBuilder()\n ret.append(\"{\")\n var first = true\n for (t in arr) {\n if (!first) {\n ret.append(\", \")\n }\n first = false\n ret.append(ts(t))\n }\n ret.append(\"}\")\n return ret.toString()\n }\n\n private fun ts(iter: Iterable): String {\n val ret = StringBuilder()\n ret.append(\"{\")\n var first = true\n for (t in iter) {\n if (!first) {\n ret.append(\", \")\n }\n first = false\n ret.append(ts(t))\n }\n ret.append(\"}\")\n return ret.toString()\n }\n\n fun dbg(vararg o: Any?) {\n if (LOCAL) {\n System.err.print(\"Line #\" + Thread.currentThread().stackTrace[2].lineNumber + \": [\")\n for (i in 0 until o.size) {\n if (i != 0) {\n System.err.print(\", \")\n }\n System.err.print(ts(o[i]))\n }\n System.err.println(\"]\")\n }\n }\n }\n}\n\ninternal class Output @JvmOverloads constructor(os: OutputStream?, var BUFFER_SIZE: Int = 1 shl 16) : Closeable, Flushable {\n var sb: StringBuilder\n var os: OutputStream\n var lineSeparator: String\n fun println(i: Int) {\n println(i.toString())\n }\n\n fun println(s: String?) {\n sb.append(s)\n println()\n }\n\n fun println() {\n sb.append(lineSeparator)\n }\n\n private fun flushToBuffer() {\n try {\n os.write(sb.toString().toByteArray())\n } catch (e: IOException) {\n e.printStackTrace()\n }\n sb = StringBuilder(BUFFER_SIZE)\n }\n\n override fun flush() {\n try {\n flushToBuffer()\n os.flush()\n } catch (e: IOException) {\n e.printStackTrace()\n }\n }\n\n override fun close() {\n flush()\n try {\n os.close()\n } catch (e: IOException) {\n e.printStackTrace()\n }\n }\n\n init {\n sb = StringBuilder(BUFFER_SIZE)\n this.os = BufferedOutputStream(os, 1 shl 17)\n lineSeparator = System.lineSeparator()\n }\n}\n\ninternal interface InputReader {\n fun nextInt(): Int\n}\n\ninternal class Pair(var a: T1, var b: T2) : Comparable> {\n constructor(p: Pair) : this(p.a, p.b) {}\n\n override fun toString(): String {\n return a.toString() + \" \" + b\n }\n\n override fun hashCode(): Int {\n return Objects.hash(a, b)\n }\n\n override fun equals(o: Any?): Boolean {\n if (o is Pair<*, *>) {\n val p = o\n return a == p.a && b == p.b\n }\n return false\n }\n\n override fun compareTo(p: Pair): Int {\n val cmp = (a as Comparable).compareTo(p.a)\n return if (cmp == 0) {\n (b as Comparable).compareTo(p.b)\n } else cmp\n }\n}\n\ninternal class FastReader(`is`: InputStream?) : InputReader {\n private val BUFFER_SIZE = 1 shl 16\n private val din: DataInputStream\n private val buffer: ByteArray\n private var bufferPointer: Int\n private var bytesRead: Int\n override fun nextInt(): Int {\n var ret = 0\n var c = skipToDigit()\n val neg = c == '-'.toByte()\n if (neg) {\n c = read()\n }\n do {\n ret = ret * 10 + c - '0'.toInt()\n } while (read().also { c = it } >= '0'.toByte() && c <= '9'.toByte())\n return if (neg) {\n -ret\n } else ret\n }\n\n private fun isDigit(b: Byte): Boolean {\n return b >= '0'.toByte() && b <= '9'.toByte()\n }\n\n private fun skipToDigit(): Byte {\n var ret: Byte\n while (!isDigit(read().also { ret = it }) && ret != '-'.toByte());\n return ret\n }\n\n private fun fillBuffer() {\n try {\n bytesRead = din.read(buffer, 0.also { bufferPointer = it }, BUFFER_SIZE)\n } catch (e: IOException) {\n e.printStackTrace()\n throw InputMismatchException()\n }\n if (bytesRead == -1) {\n buffer[0] = -1\n }\n }\n\n private fun read(): Byte {\n if (bytesRead == -1) {\n throw InputMismatchException()\n } else if (bufferPointer == bytesRead) {\n fillBuffer()\n }\n return buffer[bufferPointer++]\n }\n\n init {\n din = DataInputStream(`is`)\n buffer = ByteArray(BUFFER_SIZE)\n bytesRead = 0\n bufferPointer = bytesRead\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["dsu", "graphs", "data structures", "implementation", "trees"], "code_uid": "cf1fe3265fce2040fd72fef1b402b6c5", "src_uid": "ad014bde729222db14f38caa521e4167", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport java.util.NoSuchElementException\nimport java.util.TreeSet\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 object {\n val n = readInt()\n val m = readInt()\n var q = readInt()\n\n val P = readIntArray(n)\n\n val A = IntArray(m)\n val B = IntArray(m) {\n A[it] = readInt() - 1\n readInt() - 1\n }\n\n val T = IntList()\n val X = IntList(q) {\n T.add(readInt())\n readInt() - 1\n }\n\n init {\n val E = BooleanArray(m)\n for(i in 0 until q) if(T[i] == 2) E[X[i]] = true\n for(i in 0 until m) if(!E[i]) {\n T.add(2)\n X.add(i)\n }\n q = T.size\n }\n\n val boss = IntList()\n val dsu = IntList(n) { it }\n val G = MutableList(n) { IntList(0) }\n\n fun addVertex(): Int {\n G.add(IntList(2))\n dsu.add(dsu.size)\n return dsu.lastIndex\n }\n\n tailrec fun root(v: Int): Int = if(dsu[v] == v) v else {\n dsu[v] = dsu[dsu[v]]\n root(dsu[v])\n }\n\n fun merge(u: Int, v: Int) {\n val ru = root(u)\n val rv = root(v)\n\n if(ru == rv) return\n\n val b = addVertex()\n dsu[ru] = b\n dsu[rv] = b\n G[b].add(ru)\n G[b].add(rv)\n }\n\n init {\n for(i in q-1 downTo 0) {\n val x = X[i]\n when(T[i]) {\n 1 -> boss.add(root(x))\n 2 -> merge(A[x], B[x])\n }\n }\n boss.reverse()\n\n val start = IntArray(dsu.size) { -1 }\n val end = IntArray(dsu.size)\n val stk = IntList()\n var eul = 0\n for(i in dsu.indices) if(start[i] == -1) {\n val r = root(i)\n stk.add(r)\n\n while(stk.isNotEmpty()) {\n val u = stk.pop()\n if(start[u] == -1) {\n start[u] = eul++\n stk.add(u)\n for(v in G[u]) stk.add(v)\n } else {\n end[u] = eul\n }\n }\n }\n\n val S = SegmentTree(eul)\n\n for(i in 0 until n) {\n val j = start[i]\n S.delayedSet(j, IntPair(P[i], j))\n }\n\n S.pushDelayed()\n\n for(b in boss) {\n val (x, j) = S[start[b], end[b]]\n println(x)\n S[j] = IntPair(0, j)\n }\n }\n\n }\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nclass SegmentTree(\n val size: Int) {\n\n val identityValue: IntPair = IntPair(-1, -1)\n inline fun combiner(a: IntPair, b: IntPair): IntPair = if(a.x >= b.x) a else b\n\n\n @Suppress(\"UNCHECKED_CAST\")\n val array = IntPairArray(size shl 1) { identityValue }\n\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n val asList: List by lazy {\n object : AbstractList() {\n override val size: Int get() = this@SegmentTree.size\n override fun get(index: Int): IntPair = this@SegmentTree[index]\n }\n }\n\n inline fun build(generator: (Int) -> IntPair) {\n for(i in 0 until size) {\n array[i + size] = generator(i)\n }\n for(i in size-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** alternative to build for arbitrary order **/\n fun delayedSet(i: Int, v: IntPair) { array[i + size] = v }\n fun pushDelayed() {\n for(i in size-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** instantiates values from an iterable, O(n) time */\n fun copyFrom(iterable: Iterable) {\n run {\n iterable.forEachIndexed { i, t ->\n if(i > lastIndex) return@run\n array[i + size] = t\n }\n }\n for(i in size-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Updates a value, O(log n) time */\n operator fun set(index: Int, value: IntPair) {\n require(index in 0 until size)\n var i = index + size\n array[i] = value\n while(true) {\n i = i shr 1\n if(i <= 0) break\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Gets a value by its index, O(1) time */\n operator fun get(index: Int): IntPair {\n require(index in 0 until size)\n return array[index + size]\n }\n\n /** gets the result of applying the monoid operation to the values in the index range, O(log n) time */\n operator fun get(start: Int, endExclusive: Int): IntPair {\n var l = maxOf(start, 0) + size\n var r = minOf(endExclusive, size) + size\n\n // two accumulators to support non-commutative monoids\n var lAcc = identityValue\n var rAcc = identityValue\n\n while(l < r) {\n if(l and 1 == 1) {\n lAcc = combiner(lAcc, array[l++])\n }\n if(r and 1 == 1) {\n rAcc = combiner(array[--r], rAcc)\n }\n\n l = l shr 1\n r = r shr 1\n }\n\n return combiner(lAcc, rAcc)\n }\n\n operator fun get(range: IntRange) = get(range.first, range.last + 1)\n}\n\nfun Int.bitConcat(other: Int) = toLong().shl(32) or other.toLong().and(0xffff_ffff)\n\ninline class IntPair(val data: Long) {\n val x get() = (data shr 32).toInt()\n val y get() = data.toInt()\n inline operator fun component1() = x\n inline operator fun component2() = y\n\n override fun toString() = \"($x, $y)\"\n}\nfun IntPair(x: Int, y: Int) = IntPair(x.bitConcat(y))\nfun unorderedPair(x: Int, y: Int) = if(x < y) IntPair(x, y) else IntPair(y, x)\n\ninline class IntPairArray(val longArray: LongArray): Collection {\n inline operator fun get(i: Int) = IntPair(longArray[i])\n inline operator fun set(i: Int, v: IntPair) { longArray[i] = v.data }\n\n override inline val size: Int get() = longArray.size\n inline val lastIndex get() = longArray.lastIndex\n inline val indices get() = longArray.indices\n\n override inline fun contains(element: IntPair): Boolean = element.data in longArray\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override inline fun isEmpty(): Boolean = longArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): IntPair = get(index++)\n }\n\n fun copyOf(newSize: Int) = IntPairArray(longArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun IntPairArray.copyInto(destination: IntPairArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =\n IntPairArray(longArray.copyInto(destination.longArray, destinationOffset, startIndex, endIndex))\ninline fun IntPairArray(size: Int) = IntPairArray(LongArray(size))\ninline fun IntPairArray(size: Int, init: (Int) -> IntPair) = IntPairArray(LongArray(size) { init(it).data })\n\n\ninline fun IntPairArray.first() = get(0)\ninline fun IntPairArray.last() = get(lastIndex)\ninline fun IntPairArray.fold(init: R, op: (acc: R, IntPair) -> R) = longArray.fold(init) { acc, i -> op(acc, IntPair(i)) }\ninline fun IntPairArray.foldRight(init: R, op: (IntPair, acc: R) -> R) = longArray.foldRight(init) { i, acc -> op(\n IntPair(i), acc) }\n\nclass IntList(initialCapacity: Int = 12) {\n private var _arr = IntArray(initialCapacity)\n private val capacity get() = _arr.size\n var size = 0\n private set\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n\n constructor(copyFrom: IntArray): this(copyFrom.size) { copyFrom.copyInto(_arr); size = copyFrom.size }\n constructor(copyFrom: Collection): this(copyFrom.size) { _arr = copyFrom.toIntArray(); size = copyFrom.size }\n\n fun contentEquals(other: IntList): Boolean {\n return this === other || size == other.size && indices.all { this[it] == other[it] }\n }\n\n private fun grow(minCapacity: Int = 8) {\n val newCapacity = maxOf(minCapacity, capacity + (capacity shr 1))\n _arr = _arr.copyOf(newCapacity)\n }\n\n fun ensureCapacity(minCapacity: Int) { if(capacity < minCapacity) grow(minCapacity) }\n\n operator fun get(index: Int): Int {\n require(index in 0 until size)\n return _arr[index]\n }\n\n operator fun set(index: Int, value: Int) {\n require(index in 0 until size)\n _arr[index] = value\n }\n\n fun add(value: Int) {\n if(size == capacity) grow()\n _arr[size++] = value\n }\n\n fun addAll(list: IntList) {\n ensureCapacity(size + list.size)\n list._arr.copyInto(_arr, size, 0, list.size)\n size += list.size\n }\n\n fun add(index: Int, element: Int) {\n if(size == capacity) grow()\n _arr.copyInto(_arr, index + 1, index, size)\n size++\n set(index, element)\n }\n\n fun clear() { size = 0 }\n\n fun removeAt(index: Int): Int {\n val e = get(index)\n _arr.copyInto(_arr, index, index + 1, size)\n size--\n return e\n }\n\n fun indexOf(e: Int): Int {\n for(i in 0 until size) if(this[i] == e) return i\n return -1\n }\n\n fun remove(e: Int): Boolean {\n val i = indexOf(e)\n if(i == -1) return false\n removeAt(i)\n return true\n }\n\n operator fun iterator() = object: IntIterator() {\n private var pos = 0\n override fun hasNext() = pos < size\n override fun nextInt() = get(pos++)\n }\n\n inline fun isEmpty() = size == 0\n inline fun isNotEmpty() = size != 0\n\n fun pop() = _arr[--size]\n\n fun popToSize(s: Int) {\n require(s >= 0)\n if(s < size) size = s\n }\n\n fun swap(i: Int, j: Int) { val t = this[i]; this[i] = this[j]; this[j] = t }\n fun reverse() {\n for(i in 0 until size / 2) swap(i, lastIndex - i)\n }\n\n fun shuffle(rnd: Random = random) { for(i in lastIndex downTo 1) swap(i, rnd.nextInt(i + 1)) }\n fun sort() { shuffle(); _arr._sort(0, size) }\n fun sortDescending() { sort(); reverse() }\n\n fun joinToString(separator: CharSequence) = if(size == 0) \"\" else let {\n buildString {\n append(it[0])\n for (i in 1 until size) {\n append(separator).append(it[i])\n }\n }\n }\n\n override fun toString() = \"[\" + joinToString(\", \") + \"]\"\n\n fun toIntArray() = _arr.copyOf(size)\n fun toList() = List(size, ::get)\n\n inline fun first() = get(0)\n inline fun last() = get(lastIndex)\n}\n\ninline fun IntList(size: Int, init: (Int) -> Int) = IntList(size).apply {\n for(i in 0 until size) { add(init(i)) }\n}\ninline fun IntArray.toIntList() = IntList(this)\ninline fun Collection.toIntList() = IntList(this)\ninline fun intListOf(vararg values: Int) = IntList(values)\n\nfun IntList.max() = (1 until size).fold(this[0]) { acc, i -> max(acc, this[i]) }\nfun IntList.min() = (1 until size).fold(this[0]) { acc, i -> min(acc, this[i]) }\nfun IntList.getOrNull(i: Int) = if(i in indices) get(i) else null\ninline fun IntList.count(predicate: (Int) -> Boolean) = indices.count { predicate(this[it]) }\nfun IntList.copyOf() = IntList(size, ::get)\n\n/** IO */\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()\n 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\nfun IntArray.sort() { shuffle(random); _sort() }\nfun IntArray.sortDescending() { shuffle(random); _sortDescending() }\n\nfun LongArray.sort() { shuffle(random); _sort() }\nfun LongArray.sortDescending() { shuffle(random); _sortDescending() }\n\nfun DoubleArray.sort() { shuffle(random); _sort() }\nfun DoubleArray.sortDescending() { shuffle(random); _sortDescending() }\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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { iprintln(max(1, 2)) }\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 }", "lang_cluster": "Kotlin", "tags": ["dsu", "graphs", "data structures", "implementation", "trees"], "code_uid": "1402b6cffcdf50693c928f8bb0fa5b84", "src_uid": "ad014bde729222db14f38caa521e4167", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport java.util.NoSuchElementException\nimport java.util.TreeSet\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 object {\n val n = readInt()\n val m = readInt()\n val q = readInt()\n\n val P = readIntArray(n)\n\n val A = IntArray(m)\n val B = IntArray(m) {\n A[it] = readInt() - 1\n readInt() - 1\n }\n\n val T = IntArray(q)\n val X = IntArray(q) {\n T[it] = readInt()\n readInt() - 1\n }\n\n val boss = IntList()\n val dsu = IntList(n) { it }\n val empty = IntList(0)\n val G = MutableList(n) { empty }\n\n fun addVertex(): Int {\n G.add(IntList(2))\n dsu.add(dsu.size)\n return dsu.lastIndex\n }\n\n tailrec fun root(v: Int): Int = if(dsu[v] == v) v else {\n dsu[v] = dsu[dsu[v]]\n root(dsu[v])\n }\n\n fun merge(u: Int, v: Int) {\n val ru = root(u)\n val rv = root(v)\n\n if(ru == rv) return\n\n val b = addVertex()\n dsu[ru] = b\n dsu[rv] = b\n G[b].add(ru)\n G[b].add(rv)\n }\n\n init {\n val E = BooleanArray(m)\n for(i in 0 until q) if(T[i] == 2) E[X[i]] = true\n for(i in 0 until m) if(!E[i]) {\n merge(A[i], B[i])\n }\n\n for(i in q-1 downTo 0) {\n val x = X[i]\n when(T[i]) {\n 1 -> boss.add(root(x))\n 2 -> merge(A[x], B[x])\n }\n }\n boss.reverse()\n\n val start = IntArray(dsu.size) { -1 }\n val end = IntArray(dsu.size)\n val stk = IntList()\n var eul = 0\n for(i in dsu.indices) if(start[i] == -1) {\n val r = root(i)\n stk.add(r)\n\n while(stk.isNotEmpty()) {\n val u = stk.pop()\n if(start[u] == -1) {\n start[u] = eul++\n stk.add(u)\n for(v in G[u]) stk.add(v)\n } else {\n end[u] = eul\n }\n }\n }\n\n val S = SegmentTree(eul)\n\n for(i in 0 until n) {\n val j = start[i]\n S.delayedSet(j, IntPair(P[i], j))\n }\n\n S.pushDelayed()\n\n for(b in boss) {\n val (x, j) = S[start[b], end[b]]\n println(x)\n S[j] = IntPair(0, j)\n }\n }\n\n }\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nclass SegmentTree(\n val size: Int) {\n\n val identityValue: IntPair = IntPair(-1, -1)\n inline fun combiner(a: IntPair, b: IntPair): IntPair = if(a.x >= b.x) a else b\n\n\n @Suppress(\"UNCHECKED_CAST\")\n val array = IntPairArray(size shl 1) { identityValue }\n\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n val asList: List by lazy {\n object : AbstractList() {\n override val size: Int get() = this@SegmentTree.size\n override fun get(index: Int): IntPair = this@SegmentTree[index]\n }\n }\n\n inline fun build(generator: (Int) -> IntPair) {\n for(i in 0 until size) {\n array[i + size] = generator(i)\n }\n for(i in size-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** alternative to build for arbitrary order **/\n fun delayedSet(i: Int, v: IntPair) { array[i + size] = v }\n fun pushDelayed() {\n for(i in size-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** instantiates values from an iterable, O(n) time */\n fun copyFrom(iterable: Iterable) {\n run {\n iterable.forEachIndexed { i, t ->\n if(i > lastIndex) return@run\n array[i + size] = t\n }\n }\n for(i in size-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Updates a value, O(log n) time */\n operator fun set(index: Int, value: IntPair) {\n require(index in 0 until size)\n var i = index + size\n array[i] = value\n while(true) {\n i = i shr 1\n if(i <= 0) break\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Gets a value by its index, O(1) time */\n operator fun get(index: Int): IntPair {\n require(index in 0 until size)\n return array[index + size]\n }\n\n /** gets the result of applying the monoid operation to the values in the index range, O(log n) time */\n operator fun get(start: Int, endExclusive: Int): IntPair {\n var l = maxOf(start, 0) + size\n var r = minOf(endExclusive, size) + size\n\n // two accumulators to support non-commutative monoids\n var lAcc = identityValue\n var rAcc = identityValue\n\n while(l < r) {\n if(l and 1 == 1) {\n lAcc = combiner(lAcc, array[l++])\n }\n if(r and 1 == 1) {\n rAcc = combiner(array[--r], rAcc)\n }\n\n l = l shr 1\n r = r shr 1\n }\n\n return combiner(lAcc, rAcc)\n }\n\n operator fun get(range: IntRange) = get(range.first, range.last + 1)\n}\n\nfun Int.bitConcat(other: Int) = toLong().shl(32) or other.toLong().and(0xffff_ffff)\n\ninline class IntPair(val data: Long) {\n val x get() = (data shr 32).toInt()\n val y get() = data.toInt()\n inline operator fun component1() = x\n inline operator fun component2() = y\n\n override fun toString() = \"($x, $y)\"\n}\nfun IntPair(x: Int, y: Int) = IntPair(x.bitConcat(y))\nfun unorderedPair(x: Int, y: Int) = if(x < y) IntPair(x, y) else IntPair(y, x)\n\ninline class IntPairArray(val longArray: LongArray): Collection {\n inline operator fun get(i: Int) = IntPair(longArray[i])\n inline operator fun set(i: Int, v: IntPair) { longArray[i] = v.data }\n\n override inline val size: Int get() = longArray.size\n inline val lastIndex get() = longArray.lastIndex\n inline val indices get() = longArray.indices\n\n override inline fun contains(element: IntPair): Boolean = element.data in longArray\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override inline fun isEmpty(): Boolean = longArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): IntPair = get(index++)\n }\n\n fun copyOf(newSize: Int) = IntPairArray(longArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun IntPairArray.copyInto(destination: IntPairArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =\n IntPairArray(longArray.copyInto(destination.longArray, destinationOffset, startIndex, endIndex))\ninline fun IntPairArray(size: Int) = IntPairArray(LongArray(size))\ninline fun IntPairArray(size: Int, init: (Int) -> IntPair) = IntPairArray(LongArray(size) { init(it).data })\n\n\ninline fun IntPairArray.first() = get(0)\ninline fun IntPairArray.last() = get(lastIndex)\ninline fun IntPairArray.fold(init: R, op: (acc: R, IntPair) -> R) = longArray.fold(init) { acc, i -> op(acc, IntPair(i)) }\ninline fun IntPairArray.foldRight(init: R, op: (IntPair, acc: R) -> R) = longArray.foldRight(init) { i, acc -> op(\n IntPair(i), acc) }\n\nclass IntList(initialCapacity: Int = 12) {\n private var _arr = IntArray(initialCapacity)\n private val capacity get() = _arr.size\n var size = 0\n private set\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n\n constructor(copyFrom: IntArray): this(copyFrom.size) { copyFrom.copyInto(_arr); size = copyFrom.size }\n constructor(copyFrom: Collection): this(copyFrom.size) { _arr = copyFrom.toIntArray(); size = copyFrom.size }\n\n fun contentEquals(other: IntList): Boolean {\n return this === other || size == other.size && indices.all { this[it] == other[it] }\n }\n\n private fun grow(minCapacity: Int = 8) {\n val newCapacity = maxOf(minCapacity, capacity + (capacity shr 1))\n _arr = _arr.copyOf(newCapacity)\n }\n\n fun ensureCapacity(minCapacity: Int) { if(capacity < minCapacity) grow(minCapacity) }\n\n operator fun get(index: Int): Int {\n require(index in 0 until size)\n return _arr[index]\n }\n\n operator fun set(index: Int, value: Int) {\n require(index in 0 until size)\n _arr[index] = value\n }\n\n fun add(value: Int) {\n if(size == capacity) grow()\n _arr[size++] = value\n }\n\n fun addAll(list: IntList) {\n ensureCapacity(size + list.size)\n list._arr.copyInto(_arr, size, 0, list.size)\n size += list.size\n }\n\n fun add(index: Int, element: Int) {\n if(size == capacity) grow()\n _arr.copyInto(_arr, index + 1, index, size)\n size++\n set(index, element)\n }\n\n fun clear() { size = 0 }\n\n fun removeAt(index: Int): Int {\n val e = get(index)\n _arr.copyInto(_arr, index, index + 1, size)\n size--\n return e\n }\n\n fun indexOf(e: Int): Int {\n for(i in 0 until size) if(this[i] == e) return i\n return -1\n }\n\n fun remove(e: Int): Boolean {\n val i = indexOf(e)\n if(i == -1) return false\n removeAt(i)\n return true\n }\n\n operator fun iterator() = object: IntIterator() {\n private var pos = 0\n override fun hasNext() = pos < size\n override fun nextInt() = get(pos++)\n }\n\n inline fun isEmpty() = size == 0\n inline fun isNotEmpty() = size != 0\n\n fun pop() = _arr[--size]\n\n fun popToSize(s: Int) {\n require(s >= 0)\n if(s < size) size = s\n }\n\n fun swap(i: Int, j: Int) { val t = this[i]; this[i] = this[j]; this[j] = t }\n fun reverse() {\n for(i in 0 until size / 2) swap(i, lastIndex - i)\n }\n\n fun shuffle(rnd: Random = random) { for(i in lastIndex downTo 1) swap(i, rnd.nextInt(i + 1)) }\n fun sort() { shuffle(); _arr._sort(0, size) }\n fun sortDescending() { sort(); reverse() }\n\n fun joinToString(separator: CharSequence) = if(size == 0) \"\" else let {\n buildString {\n append(it[0])\n for (i in 1 until size) {\n append(separator).append(it[i])\n }\n }\n }\n\n override fun toString() = \"[\" + joinToString(\", \") + \"]\"\n\n fun toIntArray() = _arr.copyOf(size)\n fun toList() = List(size, ::get)\n\n inline fun first() = get(0)\n inline fun last() = get(lastIndex)\n}\n\ninline fun IntList(size: Int, init: (Int) -> Int) = IntList(size).apply {\n for(i in 0 until size) { add(init(i)) }\n}\ninline fun IntArray.toIntList() = IntList(this)\ninline fun Collection.toIntList() = IntList(this)\ninline fun intListOf(vararg values: Int) = IntList(values)\n\nfun IntList.max() = (1 until size).fold(this[0]) { acc, i -> max(acc, this[i]) }\nfun IntList.min() = (1 until size).fold(this[0]) { acc, i -> min(acc, this[i]) }\nfun IntList.getOrNull(i: Int) = if(i in indices) get(i) else null\ninline fun IntList.count(predicate: (Int) -> Boolean) = indices.count { predicate(this[it]) }\nfun IntList.copyOf() = IntList(size, ::get)\n\n/** IO */\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()\n 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\nfun IntArray.sort() { shuffle(random); _sort() }\nfun IntArray.sortDescending() { shuffle(random); _sortDescending() }\n\nfun LongArray.sort() { shuffle(random); _sort() }\nfun LongArray.sortDescending() { shuffle(random); _sortDescending() }\n\nfun DoubleArray.sort() { shuffle(random); _sort() }\nfun DoubleArray.sortDescending() { shuffle(random); _sortDescending() }\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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { iprintln(max(1, 2)) }\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 }", "lang_cluster": "Kotlin", "tags": ["dsu", "graphs", "data structures", "implementation", "trees"], "code_uid": "9dbb089b91841233aa056659014d5f3a", "src_uid": "ad014bde729222db14f38caa521e4167", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport java.util.NoSuchElementException\nimport java.util.TreeSet\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 object {\n val n = readInt()\n val m = readInt()\n var q = readInt()\n\n val P = readIntArray(n)\n\n val A = IntArray(m)\n val B = IntArray(m) {\n A[it] = readInt() - 1\n readInt() - 1\n }\n\n val T = IntList()\n val X = IntList(q) {\n T.add(readInt())\n readInt() - 1\n }\n\n init {\n val E = BooleanArray(m)\n for(i in 0 until q) if(T[i] == 2) E[X[i]] = true\n for(i in 0 until m) if(!E[i]) {\n T.add(2)\n X.add(i)\n }\n q = T.size\n }\n\n val boss = IntList()\n val dsu = IntList(n) { it }\n val G = MutableList(n) { IntList(0) }\n\n fun addVertex(): Int {\n G.add(IntList(2))\n dsu.add(dsu.size)\n return dsu.lastIndex\n }\n\n tailrec fun root(v: Int): Int = if(dsu[v] == v) v else {\n dsu[v] = dsu[dsu[v]]\n root(dsu[v])\n }\n\n fun merge(u: Int, v: Int) {\n val ru = root(u)\n val rv = root(v)\n\n if(ru == rv) return\n\n val b = addVertex()\n dsu[ru] = b\n dsu[rv] = b\n G[b].add(ru)\n G[b].add(rv)\n }\n\n init {\n for(i in q-1 downTo 0) {\n val x = X[i]\n when(T[i]) {\n 1 -> boss.add(root(x))\n 2 -> merge(A[x], B[x])\n }\n }\n boss.reverse()\n\n val start = IntArray(dsu.size) { -1 }\n val end = IntArray(dsu.size)\n val stk = IntList()\n var eul = 0\n for(i in dsu.indices) if(start[i] == -1) {\n val r = root(i)\n stk.add(r)\n\n while(stk.isNotEmpty()) {\n val u = stk.pop()\n if(start[u] == -1) {\n start[u] = eul++\n stk.add(u)\n for(v in G[u]) stk.add(v)\n } else {\n end[u] = eul\n }\n }\n }\n\n val S = SegmentTree(eul)\n\n for(i in 0 until n) {\n val j = start[i]\n S[j] = IntPair(P[i], j)\n }\n\n for(b in boss) {\n val (x, j) = S[start[b], end[b]]\n println(x)\n S[j] = IntPair(0, j)\n }\n }\n\n }\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nclass SegmentTree(\n val size: Int) {\n\n val identityValue: IntPair = IntPair(-1, -1)\n inline fun combiner(a: IntPair, b: IntPair): IntPair = if(a.x >= b.x) a else b\n\n\n @Suppress(\"UNCHECKED_CAST\")\n val array = IntPairArray(size shl 1) { identityValue }\n\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n val asList: List by lazy {\n object : AbstractList() {\n override val size: Int get() = this@SegmentTree.size\n override fun get(index: Int): IntPair = this@SegmentTree[index]\n }\n }\n\n inline fun build(generator: (Int) -> IntPair) {\n for(i in 0 until size) {\n array[i + size] = generator(i)\n }\n for(i in size-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** alternative to build for arbitrary order **/\n fun delayedSet(i: Int, v: IntPair) { array[i + size] = v }\n fun pushDelayed() {\n for(i in size-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** instantiates values from an iterable, O(n) time */\n fun copyFrom(iterable: Iterable) {\n run {\n iterable.forEachIndexed { i, t ->\n if(i > lastIndex) return@run\n array[i + size] = t\n }\n }\n for(i in size-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Updates a value, O(log n) time */\n operator fun set(index: Int, value: IntPair) {\n require(index in 0 until size)\n var i = index + size\n array[i] = value\n while(true) {\n i = i shr 1\n if(i <= 0) break\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Gets a value by its index, O(1) time */\n operator fun get(index: Int): IntPair {\n require(index in 0 until size)\n return array[index + size]\n }\n\n /** gets the result of applying the monoid operation to the values in the index range, O(log n) time */\n operator fun get(start: Int, endExclusive: Int): IntPair {\n var l = maxOf(start, 0) + size\n var r = minOf(endExclusive, size) + size\n\n // two accumulators to support non-commutative monoids\n var lAcc = identityValue\n var rAcc = identityValue\n\n while(l < r) {\n if(l and 1 == 1) {\n lAcc = combiner(lAcc, array[l++])\n }\n if(r and 1 == 1) {\n rAcc = combiner(array[--r], rAcc)\n }\n\n l = l shr 1\n r = r shr 1\n }\n\n return combiner(lAcc, rAcc)\n }\n\n operator fun get(range: IntRange) = get(range.first, range.last + 1)\n}\n\nfun Int.bitConcat(other: Int) = toLong().shl(32) or other.toLong().and(0xffff_ffff)\n\ninline class IntPair(val data: Long) {\n val x get() = (data shr 32).toInt()\n val y get() = data.toInt()\n inline operator fun component1() = x\n inline operator fun component2() = y\n\n override fun toString() = \"($x, $y)\"\n}\nfun IntPair(x: Int, y: Int) = IntPair(x.bitConcat(y))\nfun unorderedPair(x: Int, y: Int) = if(x < y) IntPair(x, y) else IntPair(y, x)\n\ninline class IntPairArray(val longArray: LongArray): Collection {\n inline operator fun get(i: Int) = IntPair(longArray[i])\n inline operator fun set(i: Int, v: IntPair) { longArray[i] = v.data }\n\n override inline val size: Int get() = longArray.size\n inline val lastIndex get() = longArray.lastIndex\n inline val indices get() = longArray.indices\n\n override inline fun contains(element: IntPair): Boolean = element.data in longArray\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override inline fun isEmpty(): Boolean = longArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): IntPair = get(index++)\n }\n\n fun copyOf(newSize: Int) = IntPairArray(longArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun IntPairArray.copyInto(destination: IntPairArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =\n IntPairArray(longArray.copyInto(destination.longArray, destinationOffset, startIndex, endIndex))\ninline fun IntPairArray(size: Int) = IntPairArray(LongArray(size))\ninline fun IntPairArray(size: Int, init: (Int) -> IntPair) = IntPairArray(LongArray(size) { init(it).data })\n\n\ninline fun IntPairArray.first() = get(0)\ninline fun IntPairArray.last() = get(lastIndex)\ninline fun IntPairArray.fold(init: R, op: (acc: R, IntPair) -> R) = longArray.fold(init) { acc, i -> op(acc, IntPair(i)) }\ninline fun IntPairArray.foldRight(init: R, op: (IntPair, acc: R) -> R) = longArray.foldRight(init) { i, acc -> op(\n IntPair(i), acc) }\n\nclass IntList(initialCapacity: Int = 12) {\n private var _arr = IntArray(initialCapacity)\n private val capacity get() = _arr.size\n var size = 0\n private set\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n\n constructor(copyFrom: IntArray): this(copyFrom.size) { copyFrom.copyInto(_arr); size = copyFrom.size }\n constructor(copyFrom: Collection): this(copyFrom.size) { _arr = copyFrom.toIntArray(); size = copyFrom.size }\n\n fun contentEquals(other: IntList): Boolean {\n return this === other || size == other.size && indices.all { this[it] == other[it] }\n }\n\n private fun grow(minCapacity: Int = 8) {\n val newCapacity = maxOf(minCapacity, capacity + (capacity shr 1))\n _arr = _arr.copyOf(newCapacity)\n }\n\n fun ensureCapacity(minCapacity: Int) { if(capacity < minCapacity) grow(minCapacity) }\n\n operator fun get(index: Int): Int {\n require(index in 0 until size)\n return _arr[index]\n }\n\n operator fun set(index: Int, value: Int) {\n require(index in 0 until size)\n _arr[index] = value\n }\n\n fun add(value: Int) {\n if(size == capacity) grow()\n _arr[size++] = value\n }\n\n fun addAll(list: IntList) {\n ensureCapacity(size + list.size)\n list._arr.copyInto(_arr, size, 0, list.size)\n size += list.size\n }\n\n fun add(index: Int, element: Int) {\n if(size == capacity) grow()\n _arr.copyInto(_arr, index + 1, index, size)\n size++\n set(index, element)\n }\n\n fun clear() { size = 0 }\n\n fun removeAt(index: Int): Int {\n val e = get(index)\n _arr.copyInto(_arr, index, index + 1, size)\n size--\n return e\n }\n\n fun indexOf(e: Int): Int {\n for(i in 0 until size) if(this[i] == e) return i\n return -1\n }\n\n fun remove(e: Int): Boolean {\n val i = indexOf(e)\n if(i == -1) return false\n removeAt(i)\n return true\n }\n\n operator fun iterator() = object: IntIterator() {\n private var pos = 0\n override fun hasNext() = pos < size\n override fun nextInt() = get(pos++)\n }\n\n inline fun isEmpty() = size == 0\n inline fun isNotEmpty() = size != 0\n\n fun pop() = _arr[--size]\n\n fun popToSize(s: Int) {\n require(s >= 0)\n if(s < size) size = s\n }\n\n fun swap(i: Int, j: Int) { val t = this[i]; this[i] = this[j]; this[j] = t }\n fun reverse() {\n for(i in 0 until size / 2) swap(i, lastIndex - i)\n }\n\n fun shuffle(rnd: Random = random) { for(i in lastIndex downTo 1) swap(i, rnd.nextInt(i + 1)) }\n fun sort() { shuffle(); _arr._sort(0, size) }\n fun sortDescending() { sort(); reverse() }\n\n fun joinToString(separator: CharSequence) = if(size == 0) \"\" else let {\n buildString {\n append(it[0])\n for (i in 1 until size) {\n append(separator).append(it[i])\n }\n }\n }\n\n override fun toString() = \"[\" + joinToString(\", \") + \"]\"\n\n fun toIntArray() = _arr.copyOf(size)\n fun toList() = List(size, ::get)\n\n inline fun first() = get(0)\n inline fun last() = get(lastIndex)\n}\n\ninline fun IntList(size: Int, init: (Int) -> Int) = IntList(size).apply {\n for(i in 0 until size) { add(init(i)) }\n}\ninline fun IntArray.toIntList() = IntList(this)\ninline fun Collection.toIntList() = IntList(this)\ninline fun intListOf(vararg values: Int) = IntList(values)\n\nfun IntList.max() = (1 until size).fold(this[0]) { acc, i -> max(acc, this[i]) }\nfun IntList.min() = (1 until size).fold(this[0]) { acc, i -> min(acc, this[i]) }\nfun IntList.getOrNull(i: Int) = if(i in indices) get(i) else null\ninline fun IntList.count(predicate: (Int) -> Boolean) = indices.count { predicate(this[it]) }\nfun IntList.copyOf() = IntList(size, ::get)\n\n/** IO */\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()\n 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\nfun IntArray.sort() { shuffle(random); _sort() }\nfun IntArray.sortDescending() { shuffle(random); _sortDescending() }\n\nfun LongArray.sort() { shuffle(random); _sort() }\nfun LongArray.sortDescending() { shuffle(random); _sortDescending() }\n\nfun DoubleArray.sort() { shuffle(random); _sort() }\nfun DoubleArray.sortDescending() { shuffle(random); _sortDescending() }\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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { iprintln(max(1, 2)) }\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 }", "lang_cluster": "Kotlin", "tags": ["dsu", "graphs", "data structures", "implementation", "trees"], "code_uid": "3a235ece680f6da71febc4d4903b4829", "src_uid": "ad014bde729222db14f38caa521e4167", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport java.util.NoSuchElementException\nimport java.util.TreeSet\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 object {\n val n = readInt()\n val m = readInt()\n val q = readInt()\n\n val P = readIntArray(n)\n val Q = IntArray(n + 1)\n init {\n for(i in 0 until n) Q[P[i]] = i\n }\n\n val A = IntArray(m)\n val B = IntArray(m) {\n A[it] = readInt() - 1\n readInt() - 1\n }\n\n val T = IntArray(q)\n val X = IntArray(q) {\n T[it] = readInt()\n readInt() - 1\n }\n\n val edgeRemoved = BooleanArray(m)\n\n init {\n for (i in 0 until q) {\n if (T[i] == 2) edgeRemoved[X[i]] = true\n }\n }\n\n val C = Array(n) { i -> _Ez_Int_TreeSet().also { it.add(P[i]) } }\n val par = IntArray(n) { it }\n\n val hist = IntList()\n fun merge(ei: Int): Int {\n var u = par[A[ei]]\n var v = par[B[ei]]\n\n if(u == v) return -1\n\n if(C[u].size() < C[v].size()) u = v.also { v = u }\n for(x in C[v]) {\n par[Q[x]] = u\n C[u].add(x)\n }\n\n return v\n }\n\n init {\n for(i in 0 until m) if(!edgeRemoved[i]) merge(i)\n for(i in q-1 downTo 0) if(T[i] == 2) {\n hist.add(merge(X[i]))\n }\n\n for(i in 0 until q) {\n val x = X[i]\n when(T[i]) {\n 1 -> {\n val ans = C[par[x]].removeLast()\n println(ans)\n }\n 2 -> {\n val v = hist.pop()\n if (v != -1) {\n val u = par[v]\n\n if(C[v].size() > 0) {\n var w = C[v].first\n while (true) {\n if (!C[u].remove(w)) C[v].remove(w)\n par[Q[w]] = v\n w = C[v].higher(w)\n if(C[v].returnedNull()) break\n }\n }\n }\n }\n }\n }\n }\n }\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nclass _Ez_Int_TreeSet @JvmOverloads constructor(capacity: Int = DEFAULT_CAPACITY) {\n // Arrays are 1-indexed. Index 0 is a null node.\n private /*C*/ var key: IntArray\n private var left: IntArray\n private var right: IntArray\n private var p: IntArray\n private var color: BooleanArray\n private var size = 0\n private var root = 0\n private var returnedNull = false\n\n constructor( /*C*/\n srcArray: IntArray\n ) : this(srcArray.size) {\n for ( /*C*/\n /*C*/element in srcArray) {\n add(element)\n }\n }\n\n constructor(javaCollection: Collection) : this(javaCollection.size) {\n for ( /*C*/\n /*C*/element in javaCollection) {\n add(element)\n }\n }\n\n fun size(): Int {\n return size\n }\n\n val isEmpty: Boolean\n get() = size == 0\n\n operator fun contains( /*C*/\n /*C*/element: Int\n ): Boolean {\n var x = root\n while (x != NULL) {\n x = if (element < key[x]) {\n left[x]\n } else if (element > key[x]) {\n right[x]\n } else {\n return true\n }\n }\n return false\n }\n\n operator fun iterator(): IntIterator {\n return _Ez_Int_TreeSetIterator()\n }\n\n /*C*/ fun toArray(): IntArray {\n /*C*/\n val result = IntArray(size)\n var i = 0\n var x = firstNode()\n while (x != NULL) {\n result[i] = key[x]\n x = successorNode(x)\n i++\n }\n return result\n }\n\n fun add( /*C*/\n /*C*/element: Int\n ): Boolean {\n var y = NULL\n var x = root\n while (x != NULL) {\n y = x\n x = if (element < key[x]) {\n left[x]\n } else if (element > key[x]) {\n right[x]\n } else {\n return false\n }\n }\n if (size == color.size - 1) {\n enlarge()\n }\n val z = ++size\n key[z] = element\n p[z] = y\n if (y == NULL) {\n root = z\n } else {\n if (element < key[y]) {\n left[y] = z\n } else {\n right[y] = z\n }\n }\n left[z] = NULL\n right[z] = NULL\n color[z] = RED\n fixAfterAdd(z)\n return true\n }\n\n fun remove( /*C*/\n /*C*/element: Int\n ): Boolean {\n var z = root\n while (z != NULL) {\n z = if (element < key[z]) {\n left[z]\n } else if (element > key[z]) {\n right[z]\n } else {\n removeNode(z)\n return true\n }\n }\n return false\n }\n\n private fun removeNode(z: Int) {\n val y = if (left[z] == NULL || right[z] == NULL) z else successorNode(z)\n val x = if (left[y] != NULL) left[y] else right[y]\n p[x] = p[y]\n if (p[y] == NULL) {\n root = x\n } else {\n if (y == left[p[y]]) {\n left[p[y]] = x\n } else {\n right[p[y]] = x\n }\n }\n if (y != z) {\n key[z] = key[y]\n }\n if (color[y] == BLACK) {\n fixAfterRemove(x)\n }\n // Swap with last\n if (y != size) {\n // copy fields\n key[y] = key[size]\n left[y] = left[size]\n right[y] = right[size]\n p[y] = p[size]\n color[y] = color[size]\n // fix the children's parents\n p[left[size]] = y\n p[right[size]] = y\n // fix one of the parent's children\n if (left[p[size]] == size) {\n left[p[size]] = y\n } else {\n right[p[size]] = y\n }\n // fix root\n if (root == size) {\n root = y\n }\n }\n size--\n }\n\n private fun successorNode(x: Int): Int {\n var x = x\n return if (right[x] != NULL) {\n x = right[x]\n while (left[x] != NULL) {\n x = left[x]\n }\n x\n } else {\n var y = p[x]\n while (y != NULL && x == right[y]) {\n x = y\n y = p[y]\n }\n y\n }\n }\n\n private fun fixAfterAdd(z: Int) {\n var z = z\n while (color[p[z]] == RED) {\n if (p[z] == left[p[p[z]]]) {\n val y = right[p[p[z]]]\n if (color[y] == RED) {\n color[p[z]] = BLACK\n color[y] = BLACK\n color[p[p[z]]] = RED\n z = p[p[z]]\n } else {\n if (z == right[p[z]]) {\n z = p[z]\n rotateLeft(z)\n }\n color[p[z]] = BLACK\n color[p[p[z]]] = RED\n rotateRight(p[p[z]])\n }\n } else {\n val y = left[p[p[z]]]\n if (color[y] == RED) {\n color[p[z]] = BLACK\n color[y] = BLACK\n color[p[p[z]]] = RED\n z = p[p[z]]\n } else {\n if (z == left[p[z]]) {\n z = p[z]\n rotateRight(z)\n }\n color[p[z]] = BLACK\n color[p[p[z]]] = RED\n rotateLeft(p[p[z]])\n }\n }\n }\n color[root] = BLACK\n }\n\n private fun fixAfterRemove(x: Int) {\n var x = x\n while (x != root && color[x] == BLACK) {\n if (x == left[p[x]]) {\n var w = right[p[x]]\n if (color[w] == RED) {\n color[w] = BLACK\n color[p[x]] = RED\n rotateLeft(p[x])\n w = right[p[x]]\n }\n if (color[left[w]] == BLACK && color[right[w]] == BLACK) {\n color[w] = RED\n x = p[x]\n } else {\n if (color[right[w]] == BLACK) {\n color[left[w]] = BLACK\n color[w] = RED\n rotateRight(w)\n w = right[p[x]]\n }\n color[w] = color[p[x]]\n color[p[x]] = BLACK\n color[right[w]] = BLACK\n rotateLeft(p[x])\n x = root\n }\n } else {\n var w = left[p[x]]\n if (color[w] == RED) {\n color[w] = BLACK\n color[p[x]] = RED\n rotateRight(p[x])\n w = left[p[x]]\n }\n if (color[left[w]] == BLACK && color[right[w]] == BLACK) {\n color[w] = RED\n x = p[x]\n } else {\n if (color[left[w]] == BLACK) {\n color[right[w]] = BLACK\n color[w] = RED\n rotateLeft(w)\n w = left[p[x]]\n }\n color[w] = color[p[x]]\n color[p[x]] = BLACK\n color[left[w]] = BLACK\n rotateRight(p[x])\n x = root\n }\n }\n }\n color[x] = BLACK\n }\n\n private fun rotateLeft(x: Int) {\n val y = right[x]\n right[x] = left[y]\n if (left[y] != NULL) {\n p[left[y]] = x\n }\n p[y] = p[x]\n if (p[x] == NULL) {\n root = y\n } else {\n if (x == left[p[x]]) {\n left[p[x]] = y\n } else {\n right[p[x]] = y\n }\n }\n left[y] = x\n p[x] = y\n }\n\n private fun rotateRight(x: Int) {\n val y = left[x]\n left[x] = right[y]\n if (right[y] != NULL) {\n p[right[y]] = x\n }\n p[y] = p[x]\n if (p[x] == NULL) {\n root = y\n } else {\n if (x == right[p[x]]) {\n right[p[x]] = y\n } else {\n left[p[x]] = y\n }\n }\n right[y] = x\n p[x] = y\n }\n\n fun clear() {\n color[NULL] = BLACK\n size = 0\n root = NULL\n }\n\n private fun enlarge() {\n val newLength = Math.max(\n color.size + 1,\n (color.size * ENLARGE_SCALE).toInt()\n )\n key = Arrays.copyOf(key, newLength)\n left = Arrays.copyOf(left, newLength)\n right = Arrays.copyOf(right, newLength)\n p = Arrays.copyOf(p, newLength)\n color = Arrays.copyOf(color, newLength)\n }\n\n private fun firstNode(): Int {\n var x = root\n while (left[x] != NULL) {\n x = left[x]\n }\n return x\n }\n\n private fun lastNode(): Int {\n var x = root\n while (right[x] != NULL) {\n x = right[x]\n }\n return x\n }\n\n /*C*/ /*C*/\n val first: Int\n get() {\n if (root == NULL) {\n returnedNull = true\n return DEFAULT_NULL_ELEMENT\n }\n val x = firstNode()\n returnedNull = false\n return key[x]\n }\n\n /*C*/ /*C*/\n val last: Int\n get() {\n if (root == NULL) {\n returnedNull = true\n return DEFAULT_NULL_ELEMENT\n }\n val x = lastNode()\n returnedNull = false\n return key[x]\n }\n\n /*C*/ fun /*C*/removeFirst(): Int {\n if (root == NULL) {\n returnedNull = true\n return DEFAULT_NULL_ELEMENT\n }\n val x = firstNode()\n returnedNull = false\n val /*C*/removedElement/*C*/ = key[x]\n removeNode(x)\n return removedElement\n }\n\n /*C*/ fun /*C*/removeLast(): Int {\n if (root == NULL) {\n returnedNull = true\n return DEFAULT_NULL_ELEMENT\n }\n val x = lastNode()\n returnedNull = false\n val /*C*/removedElement/*C*/ = key[x]\n removeNode(x)\n return removedElement\n }\n\n /*C*/ fun /*C*/floor( /*C*/\n /*C*/element: Int\n ): Int {\n var x = root\n while (x != NULL) {\n if (element > key[x]) {\n if (right[x] != NULL) {\n x = right[x]\n } else {\n returnedNull = false\n return key[x]\n }\n } else if (element < key[x]) {\n if (left[x] != NULL) {\n x = left[x]\n } else {\n var y = p[x]\n while (y != NULL && x == left[y]) {\n x = y\n y = p[y]\n }\n return if (y == NULL) {\n returnedNull = true\n DEFAULT_NULL_ELEMENT\n } else {\n returnedNull = false\n key[y]\n }\n }\n } else {\n returnedNull = false\n return key[x]\n }\n }\n returnedNull = true\n return DEFAULT_NULL_ELEMENT\n }\n\n /*C*/ fun /*C*/ceiling( /*C*/\n /*C*/element: Int\n ): Int {\n var x = root\n while (x != NULL) {\n if (element < key[x]) {\n if (left[x] != NULL) {\n x = left[x]\n } else {\n returnedNull = false\n return key[x]\n }\n } else if (element > key[x]) {\n if (right[x] != NULL) {\n x = right[x]\n } else {\n var y = p[x]\n while (y != NULL && x == right[y]) {\n x = y\n y = p[y]\n }\n return if (y == NULL) {\n returnedNull = true\n DEFAULT_NULL_ELEMENT\n } else {\n returnedNull = false\n key[y]\n }\n }\n } else {\n returnedNull = false\n return key[x]\n }\n }\n returnedNull = true\n return DEFAULT_NULL_ELEMENT\n }\n\n /*C*/ fun /*C*/lower( /*C*/\n /*C*/element: Int\n ): Int {\n var x = root\n while (x != NULL) {\n if (element > key[x]) {\n if (right[x] != NULL) {\n x = right[x]\n } else {\n returnedNull = false\n return key[x]\n }\n } else {\n if (left[x] != NULL) {\n x = left[x]\n } else {\n var y = p[x]\n while (y != NULL && x == left[y]) {\n x = y\n y = p[y]\n }\n return if (y == NULL) {\n returnedNull = true\n DEFAULT_NULL_ELEMENT\n } else {\n returnedNull = false\n key[y]\n }\n }\n }\n }\n returnedNull = true\n return DEFAULT_NULL_ELEMENT\n }\n\n /*C*/ fun /*C*/higher( /*C*/\n /*C*/element: Int\n ): Int {\n var x = root\n while (x != NULL) {\n if (element < key[x]) {\n if (left[x] != NULL) {\n x = left[x]\n } else {\n returnedNull = false\n return key[x]\n }\n } else {\n if (right[x] != NULL) {\n x = right[x]\n } else {\n var y = p[x]\n while (y != NULL && x == right[y]) {\n x = y\n y = p[y]\n }\n return if (y == NULL) {\n returnedNull = true\n DEFAULT_NULL_ELEMENT\n } else {\n returnedNull = false\n key[y]\n }\n }\n }\n }\n returnedNull = true\n return DEFAULT_NULL_ELEMENT\n }\n\n fun returnedNull(): Boolean {\n return returnedNull\n }\n\n override fun equals(o: Any?): Boolean {\n if (this === o) return true\n if (o == null || javaClass != o.javaClass) return false\n val that = o as _Ez_Int_TreeSet\n if (size != that.size) {\n return false\n }\n var x = firstNode()\n var y = that.firstNode()\n while (x != NULL) {\n if (key[x] != that.key[y]) {\n return false\n }\n x = successorNode(x)\n y = that.successorNode(y)\n }\n return true\n }\n\n override fun hashCode(): Int {\n// var hash = HASHCODE_INITIAL_VALUE\n// var x = firstNode()\n// while (x != NULL) {\n// hash = (hash xor PrimitiveHashCalculator.getHash(key[x])) * HASHCODE_MULTIPLIER\n// x = successorNode(x)\n// }\n// return hash\n return 0\n }\n\n override fun toString(): String {\n val sb = StringBuilder()\n sb.append('[')\n var x = firstNode()\n while (x != NULL) {\n if (sb.length > 1) {\n sb.append(\", \")\n }\n sb.append(key[x])\n x = successorNode(x)\n }\n sb.append(']')\n return sb.toString()\n }\n\n private inner class _Ez_Int_TreeSetIterator constructor() : IntIterator() {\n private var x: Int\n override fun hasNext(): Boolean {\n return x != NULL\n }\n\n /*C*/ override fun /*C*/nextInt(): Int {\n if (x == NULL) {\n throw NoSuchElementException(\"Iterator doesn't have more elements\")\n }\n val /*C*/result/*C*/ = key[x]\n x = successorNode(x)\n return result\n }\n\n init {\n x = firstNode()\n }\n }\n\n companion object {\n private const val DEFAULT_CAPACITY = 10\n private const val ENLARGE_SCALE = 2.0\n private const val HASHCODE_INITIAL_VALUE = -0x7ee3623b\n private const val HASHCODE_MULTIPLIER = 0x01000193\n private const val BLACK = false\n private const val RED = true\n private const val NULL = 0\n private const /*C*/ val /*C*/DEFAULT_NULL_ELEMENT = 0\n }\n\n init {\n var capacity = capacity\n require(capacity >= 0) { \"Capacity must be non-negative\" }\n capacity++\n key = IntArray(capacity)\n left = IntArray(capacity)\n right = IntArray(capacity)\n p = IntArray(capacity)\n color = BooleanArray(capacity)\n color[NULL] = BLACK\n size = 0\n root = NULL\n returnedNull = false\n }\n}\n\nclass IntList(initialCapacity: Int = 12) {\n private var _arr = IntArray(initialCapacity)\n private val capacity get() = _arr.size\n var size = 0\n private set\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n\n constructor(copyFrom: IntArray): this(copyFrom.size) { copyFrom.copyInto(_arr); size = copyFrom.size }\n constructor(copyFrom: Collection): this(copyFrom.size) { _arr = copyFrom.toIntArray(); size = copyFrom.size }\n\n fun contentEquals(other: IntList): Boolean {\n return this === other || size == other.size && indices.all { this[it] == other[it] }\n }\n\n private fun grow(minCapacity: Int = 8) {\n val newCapacity = maxOf(minCapacity, capacity + (capacity shr 1))\n _arr = _arr.copyOf(newCapacity)\n }\n\n fun ensureCapacity(minCapacity: Int) { if(capacity < minCapacity) grow(minCapacity) }\n\n operator fun get(index: Int): Int {\n require(index in 0 until size)\n return _arr[index]\n }\n\n operator fun set(index: Int, value: Int) {\n require(index in 0 until size)\n _arr[index] = value\n }\n\n fun add(value: Int) {\n if(size == capacity) grow()\n _arr[size++] = value\n }\n\n fun addAll(list: IntList) {\n ensureCapacity(size + list.size)\n list._arr.copyInto(_arr, size, 0, list.size)\n size += list.size\n }\n\n fun add(index: Int, element: Int) {\n if(size == capacity) grow()\n _arr.copyInto(_arr, index + 1, index, size)\n size++\n set(index, element)\n }\n\n fun clear() { size = 0 }\n\n fun removeAt(index: Int): Int {\n val e = get(index)\n _arr.copyInto(_arr, index, index + 1, size)\n size--\n return e\n }\n\n fun indexOf(e: Int): Int {\n for(i in 0 until size) if(this[i] == e) return i\n return -1\n }\n\n fun remove(e: Int): Boolean {\n val i = indexOf(e)\n if(i == -1) return false\n removeAt(i)\n return true\n }\n\n operator fun iterator() = object: IntIterator() {\n private var pos = 0\n override fun hasNext() = pos < size\n override fun nextInt() = get(pos++)\n }\n\n inline fun isEmpty() = size == 0\n inline fun isNotEmpty() = size != 0\n\n fun pop() = _arr[--size]\n\n fun popToSize(s: Int) {\n require(s >= 0)\n if(s < size) size = s\n }\n\n fun swap(i: Int, j: Int) { val t = this[i]; this[i] = this[j]; this[j] = t }\n fun reverse() {\n for(i in 0 until size / 2) swap(i, lastIndex - i)\n }\n\n fun shuffle(rnd: Random = random) { for(i in lastIndex downTo 1) swap(i, rnd.nextInt(i + 1)) }\n fun sort() { shuffle(); _arr._sort(0, size) }\n fun sortDescending() { sort(); reverse() }\n\n fun joinToString(separator: CharSequence) = if(size == 0) \"\" else let {\n buildString {\n append(it[0])\n for (i in 1 until size) {\n append(separator).append(it[i])\n }\n }\n }\n\n override fun toString() = \"[\" + joinToString(\", \") + \"]\"\n\n fun toIntArray() = _arr.copyOf(size)\n fun toList() = List(size, ::get)\n\n inline fun first() = get(0)\n inline fun last() = get(lastIndex)\n}\n\ninline fun IntList(size: Int, init: (Int) -> Int) = IntList(size).apply {\n for(i in 0 until size) { add(init(i)) }\n}\ninline fun IntArray.toIntList() = IntList(this)\ninline fun Collection.toIntList() = IntList(this)\ninline fun intListOf(vararg values: Int) = IntList(values)\n\nfun IntList.max() = (1 until size).fold(this[0]) { acc, i -> max(acc, this[i]) }\nfun IntList.min() = (1 until size).fold(this[0]) { acc, i -> min(acc, this[i]) }\nfun IntList.getOrNull(i: Int) = if(i in indices) get(i) else null\ninline fun IntList.count(predicate: (Int) -> Boolean) = indices.count { predicate(this[it]) }\nfun IntList.copyOf() = IntList(size, ::get)\n\n/** IO */\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()\n 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\nfun IntArray.sort() { shuffle(random); _sort() }\nfun IntArray.sortDescending() { shuffle(random); _sortDescending() }\n\nfun LongArray.sort() { shuffle(random); _sort() }\nfun LongArray.sortDescending() { shuffle(random); _sortDescending() }\n\nfun DoubleArray.sort() { shuffle(random); _sort() }\nfun DoubleArray.sortDescending() { shuffle(random); _sortDescending() }\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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { iprintln(max(1, 2)) }\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 }", "lang_cluster": "Kotlin", "tags": ["dsu", "graphs", "data structures", "implementation", "trees"], "code_uid": "a081d4f20f196d3d6283e06c69f3b9c8", "src_uid": "ad014bde729222db14f38caa521e4167", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\nfun main(args: Array){\n\tval n = readLine()!!.toLong()\n\tprintln((n/2).toLong()+1)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "5815acd62e7a8266dee7c42038bcb3bc", "src_uid": "5551742f6ab39fdac3930d866f439e3e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main (args: Array) {\n val input = Scanner(System.`in`)\n val n = input.nextInt()\n\n println(1 + n / 2)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "ff8fef6e1f5913fb5d58bb889ad8a4e6", "src_uid": "5551742f6ab39fdac3930d866f439e3e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Math.floor\n// 1 2 3 4 5 6 7 8 9\n// 0,1,2,2,3,3,4,4,5,5\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n if(n == 0) print(0)\n else if(n == 1) print(1)\n else print(floor(n.toDouble() / 2).toInt() + 1)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "ba8f9d10df6b15b5f47a5ec55544e2b5", "src_uid": "5551742f6ab39fdac3930d866f439e3e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n println(readLine()!!.toInt()/2 + 1)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "9d8910c79449b2c595b8325feab5eb89", "src_uid": "5551742f6ab39fdac3930d866f439e3e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = r.readLine()!!.toInt()\n if (n%2==0) println((n/2-1)/2)\n else println(0)\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "8993dc9b8537b40fa0f526ebcf5e6f33", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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() }", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "bitmasks"], "code_uid": "4cc46b8eb8ff1f2a13187cb54da479dd", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "bitmasks"], "code_uid": "4ac6a4c6c76991d4b78bcbd892fb2444", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "bitmasks"], "code_uid": "e61c12a29bf9bab223fc087fc35eb854", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "bitmasks"], "code_uid": "9aaf2bd30065b11f27652f887cc233bc", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.nextInt()\n val m = sc.nextInt()\n val adj = Array(n) { mutableSetOf() }\n for (i in 0 until m) {\n val u = sc.nextInt() - 1\n val v = sc.nextInt() - 1\n adj[u].add(v)\n adj[v].add(u)\n }\n if (n <= 6) {\n println(m)\n } else {\n var max = 0\n for (i in 0 until n) {\n for (j in 0 until n) {\n val count = m - adj[i].intersect(adj[j]).count()\n max = Math.max(max, count)\n }\n }\n println(max)\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", "lang_cluster": "Kotlin", "tags": ["brute force", "graphs"], "code_uid": "cbccbee1fe0e23a38ac4eef037d36d8c", "src_uid": "11e6559cfb71b8f6ca88242094b17a2b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\n\nfun main() {\n val (n, m) = readLine()!!.split(\" \").map(String::toInt)\n val graph = Array(n) { ArrayList() }\n\n for (i in 0 until m) {\n val (u, v) = readLine()!!.split(\" \").map(String::toInt)\n graph[u - 1].add(v - 1)\n graph[v - 1].add(u - 1)\n }\n\n val a = Array(6) { CharArray(6) { 0.toChar() } }\n var ans = 0\n\n for (i in 0..279936) {\n for (w in 0 until 6) {\n for (q in 0 until 6) a[w][q] = 0.toChar()\n }\n\n val c = ArrayList()\n var v = i\n for (j in 0 until n) {\n c.add(v % 6)\n v /= 6\n }\n\n var cans = 0\n for (j in 0 until n) {\n for (t in graph[j]) {\n if (a[min(c[j], c[t])][max(c[j], c[t])] == 0.toChar()) {\n a[min(c[j], c[t])][max(c[j], c[t])] = 1.toChar()\n cans++\n }\n }\n }\n ans = max(ans, cans)\n }\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "graphs"], "code_uid": "2d94d96c067fb19b27d324427763fc10", "src_uid": "11e6559cfb71b8f6ca88242094b17a2b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Integer.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() {\n val (n,m) = readInts()\n val graph = HashMap>()\n if (n <= 6) {\n println(m)\n return\n }\n for (i in 1..n) {\n graph[i] = HashSet()\n }\n for (i in 1..m) {\n val (s, t) = readInts()\n graph[s]?.add(t)\n graph[t]?.add(s)\n }\n // Iterate over all pairs, find ones with smallest intersection\n // in their adjacency sets\n // return m - size(intersection)\n var minIntersection = m\n for (i in 1..n) {\n for (j in i..n) {\n minIntersection = graph[j]?.let { graph[i]?.intersect(it)?.size }?.let { min(minIntersection, it) }!!\n }\n }\n println(m - minIntersection)\n return\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "graphs"], "code_uid": "e2cefadd1fa0cb750042f521d9519728", "src_uid": "11e6559cfb71b8f6ca88242094b17a2b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\n val n = sc.nextInt()\n val m = sc.nextInt()\n\n val vs = Array(n + 1) { i -> Vertex(i) }\n\n repeat(m) {\n val u = vs[sc.nextInt()]\n val v = vs[sc.nextInt()]\n u.edge.add(v)\n v.edge.add(u)\n }\n\n solve(n, vs, mutableListOf())\n println(max)\n}\n\n\nvar max = -1\n\nfun solve(n: Int, vs: Array, marked: MutableList) {\n if (marked.size == n) {\n val res: Int = check(n, vs, marked) ?: -1\n if (res == 21) {\n println(marked)\n readLine()\n }\n max = maxOf(max, res)\n return\n }\n\n for (j in 1..6) {\n marked.add(j)\n solve(n, vs, marked)\n marked.removeAt(marked.lastIndex)\n }\n}\n\nfun check(n: Int, vs: Array, marked: MutableList): Int? {\n val used = mutableSetOf()\n for (x in 1..n) {\n val v = vs[x]\n for (u in v.edge) {\n if (v.n >= u.n) continue\n used.add(Domino(minOf(marked[v.n - 1], marked[u.n - 1]), maxOf(marked[v.n - 1], marked[u.n - 1])))\n }\n }\n return used.size\n}\n\ndata class Domino(val x: Int, val y: Int)\n\n\ndata class Vertex(val n: Int) {\n val edge = mutableListOf()\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", "lang_cluster": "Kotlin", "tags": ["brute force", "graphs"], "code_uid": "6a9c824ed527235061a5b5e8b3e2bb95", "src_uid": "11e6559cfb71b8f6ca88242094b17a2b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 s = reader.next()\n var lc: Char? = null\n for (c in s) {\n if (c !in listOf('a','e','i','o','u','y') || lc == null) {\n writer.print(c)\n } else if (lc !in listOf('a','e','i','o','u','y')){\n writer.print(c)\n }\n lc = c\n }\n writer.println()\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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "ebfd2de873a84708028460ec5f3e9374", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(args : Array) {\n Thread { run() }.start()\n}\nval vowels = sortedSetOf('a', 'e', 'i', 'o', 'u', 'y')\nfun isVowel(c:Char):Boolean{\n for(x in vowels)\n if(x == c)\n return true\n return false\n}\nval sc = Scanner(System.`in`)\nfun run() {\n val n = sc.nextInt()\n val s = sc.next()\n var out = ArrayList()\n var ok = false\n for(i in 0 until n){\n if(ok && isVowel(s[i]))continue;\n out.add(s[i])\n ok = (isVowel(s[i]))\n }\n for(c in out)\n print(c)\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)", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "584c657de5afffb908c61f618d6258a3", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\nfun main() {\n val sc = Scanner(System.`in`)\n\n var n = sc.nextInt()\n\n var str = sc.next().toCharArray()\n\n var i = 0\n\n\n var list = listOf('a', 'e', 'i', 'o', 'u', 'y')\n var ans = \"\"\n// var flag = true\n// while (i) {\n\n val n: Int = readLine()!!.toInt()\n val s: String = readLine()!!\n\n var i: Int = 0\n var prevVowel: Boolean = false\n while (i < s.length) {\n\n if (!isCHarVowel(s[i])) {\n print(s[i])\n\n prevVowel = false\n }\n if (!prevVowel && isCHarVowel(s[i]))\n {\n print(s[i])\n prevVowel = true\n }\n\n i++\n }\n\n}\n\nfun isCHarVowel(chr: Char): Boolean {\n val vowel: String = \"aeiouy\"\n\n for (item in vowel) {\n if (item == chr) {\n return true\n }\n }\n\n return false\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8bbe663108589456f41afa0919ce88a0", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\n\nfun main(args: Array) {\n val (n, m, a, b) = readLine()!!.split(\" \").map { it.toLong() }\n val d = n % m\n val u = m - d\n val pu = u * a\n val pd = d * b\n println(min(pu, pd))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "95490ebc9806527f827fb977e5ad30fe", "src_uid": "c05d753b35545176ad468b99ff13aa39", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (n, m, a, b) = readLongs()\n if (n < m) {\n var t = (m - n) * a\n var g = n * b\n println(minOf(t,g))\n } else {\n var t = (n % m) * b\n var g = (m - (n % m)) * a\n println(minOf(t, g))\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()!!", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "a58d9dc09f77d397e4799927f1805694", "src_uid": "c05d753b35545176ad468b99ff13aa39", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n var m = 0L\n var n = 0L\n var a = 0L\n var b = 0L\n\n reader.nextLine().split(\" \").forEachIndexed { index, s ->\n when(index){\n 0 -> n = s.toLong()\n 1 -> m = s.toLong()\n 2 -> a = s.toLong()\n 3 -> b = s.toLong()\n }\n }\n\n var build = (m - n % m) * a\n var decrease = n % m *b\n\n if (build < decrease){\n println(build)\n } else {\n println(decrease)\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "08d2dbefe4e211d4d2bfe0c020b272a1", "src_uid": "c05d753b35545176ad468b99ff13aa39", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n val (numBoxes, numDelegations, buildFee, demolishFee) = readLine()!!.split(\" \").map(String::toLong)\n print(min(demolishFee * (numBoxes % numDelegations), buildFee * (numDelegations - (numBoxes % numDelegations))))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "c6e70a46320cf07bd27b5646c5b9d84a", "src_uid": "c05d753b35545176ad468b99ff13aa39", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main() {\n val numberOfRequiredLetters = readLine()?.toInt()\n val pattern = readLine()\n\n if (numberOfRequiredLetters == null || pattern == null) {\n println(\"Wrong input\")\n return\n }\n\n println(Solution.solve(pattern, numberOfRequiredLetters))\n}\n\nprivate class Solution private constructor(private val pattern: String,\n numberOfRequiredLetters: Int) {\n\n private val requiredCharacterRange = FIRST_LETTER until FIRST_LETTER + numberOfRequiredLetters\n private val resultArray = Array(pattern.length) { ANY_LETTER }\n\n private fun prepareResultArray() {\n for (i in pattern.indices) {\n if (pattern[i] != ANY_LETTER) {\n resultArray[i] = pattern[i]\n } else {\n resultArray[i] = pattern[pattern.lastIndex - i]\n }\n }\n }\n\n private fun getLettersNotContainedInPattern() : HashSet {\n val notContainedLetters = requiredCharacterRange.toHashSet()\n for (character in pattern) {\n notContainedLetters.remove(character)\n }\n return notContainedLetters\n }\n\n private fun resultArrayIsCorrect() : Boolean {\n for (i in 0..(resultArray.size / 2)) {\n if (resultArray[i] != resultArray[resultArray.lastIndex - i]) {\n return false\n }\n if (resultArray[i] !in requiredCharacterRange) {\n return false\n }\n }\n return true\n }\n\n\n private fun solveImpl() : String {\n prepareResultArray()\n val notContainedLettersDescending = getLettersNotContainedInPattern().sorted().toMutableList()\n for (i in (resultArray.size - 1) / 2 downTo 0) {\n if (resultArray[i] != ANY_LETTER) {\n continue\n }\n val letterToWrite = if (notContainedLettersDescending.isNotEmpty()) {\n val lastCharacter = notContainedLettersDescending.last()\n notContainedLettersDescending.removeAt(notContainedLettersDescending.lastIndex)\n lastCharacter\n } else {\n 'a'\n }\n resultArray[i] = letterToWrite\n resultArray[resultArray.lastIndex - i] = letterToWrite\n }\n\n if (notContainedLettersDescending.isNotEmpty() || !resultArrayIsCorrect()) {\n return IMPOSSIBLE_MESSAGE\n }\n return resultArray.joinToString(separator = \"\")\n }\n\n companion object {\n private const val ANY_LETTER = '?'\n private const val FIRST_LETTER = 'a'\n private const val IMPOSSIBLE_MESSAGE = \"IMPOSSIBLE\"\n\n fun solve(pattern: String, numberOfRequiredLetters: Int) : String {\n return Solution(pattern, numberOfRequiredLetters).solveImpl()\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["expression parsing"], "code_uid": "d00989e2db73f9f577e815bddb0fed19", "src_uid": "9d1dd9d722e5fe46823224334b3b208a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nprivate const val NO_SOLUTION_ANSWER = \"IMPOSSIBLE\"\nprivate const val QUESTION_MARK = '?'\n\n/**\n * Solution for codeforces.com/problemset/problem/59/C?locale=en.\n *\n * @param maxLetterNumber maximum letter number that must be used in the title\n * @param pattern approximate variant of the title\n */\nclass Problem59C(private val maxLetterNumber: Int, pattern: String) {\n private var isSolved = false\n private var answer: String? = null\n private var unusedLetter = 'a'\n private val pattern: CharArray = pattern.toCharArray()\n private val usedLetters = HashMap()\n\n /**\n * Returns lexicographically smallest correct title if it's possible, and null otherwise.\n */\n fun solve(): String? {\n if (isSolved) {\n return answer\n }\n\n if (!completePattern()) {\n return toSolvedState(null)\n }\n markUsedLetters()\n\n val unusedLettersNumber = maxLetterNumber - usedLetters.size\n val lastIndex = pattern.lastIndex\n val freePosNumber = (0..lastIndex / 2)\n .count { pattern[it] == QUESTION_MARK }\n if (unusedLettersNumber > freePosNumber || unusedLettersNumber < 0) {\n return toSolvedState(null)\n }\n var difference = freePosNumber - unusedLettersNumber\n (0..lastIndex / 2)\n .filter { pattern[it] == '?' }\n .forEach {\n if (difference > 0) {\n pattern[it] = 'a'\n pattern[lastIndex - it] = 'a'\n difference--\n } else {\n updateUnusedLetter()\n pattern[it] = unusedLetter\n pattern[lastIndex - it] = unusedLetter\n usedLetters[unusedLetter] = true\n }\n }\n\n return toSolvedState(pattern.joinToString(\"\"))\n }\n\n /**\n * Change object's state to solved and cashes [answer]\n *\n * @return [answer]\n */\n private fun toSolvedState(answer: String?): String? {\n return answer.also {\n this.answer = answer\n isSolved = true\n }\n }\n\n /**\n * Replaces question marks with already determined by palindrome condition letters.\n *\n * @return true if the title can be palindrome, and false otherwise\n */\n private fun completePattern(): Boolean {\n val lastIndex = pattern.lastIndex\n\n for (i in 0..lastIndex / 2) {\n when {\n pattern[i] == QUESTION_MARK -> pattern[i] = pattern[lastIndex - i]\n pattern[lastIndex - i] == QUESTION_MARK -> pattern[lastIndex - i] = pattern[i]\n pattern[i] != pattern[lastIndex - i] -> return false\n }\n }\n\n return true\n }\n\n /**\n * Marks used letters in [usedLetters].\n */\n private fun markUsedLetters() {\n val middle = pattern.lastIndex / 2\n (0..middle)\n .filter { pattern[it] != QUESTION_MARK }\n .forEach { usedLetters[pattern[it]] = true }\n }\n\n /**\n * Updates lexicographically smallest unused letter.\n */\n private fun updateUnusedLetter() {\n while (usedLetters[unusedLetter] == true) {\n unusedLetter = unusedLetter.inc()\n }\n }\n}\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val maxLetterNumber = scanner.nextInt()\n val pattern = scanner.next()\n val problem = Problem59C(maxLetterNumber, pattern)\n print(problem.solve() ?: NO_SOLUTION_ANSWER)\n}", "lang_cluster": "Kotlin", "tags": ["expression parsing"], "code_uid": "331c8aa8d3f2baa704003730d4d3190d", "src_uid": "9d1dd9d722e5fe46823224334b3b208a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashSet\nimport kotlin.math.PI\nimport kotlin.math.atan\n\nfun getSymbolsFromString(string : String) : HashSet {\n val stringSymbols = HashSet()\n for (symbol in string) {\n if (!stringSymbols.contains(symbol)) {\n stringSymbols.add(symbol)\n }\n }\n\n return stringSymbols\n}\n\nfun getStringMissingSymbols(string: String) : ArrayList {\n val stringSymbols = getSymbolsFromString(string)\n val missingSymbols = ArrayList()\n\n for (symbol in 'a'..'z') {\n if (!stringSymbols.contains(symbol)) {\n missingSymbols.add(symbol)\n }\n }\n\n return missingSymbols\n}\n\nfun canChooseSymbolNumber(string: String) : Int {\n var canChooseSymbolNumber = 0\n for (i in 0 until (string.length + 1)/ 2) {\n canChooseSymbolNumber +=\n if (string[i] == '?' && string[string.length - 1 - i] == '?') {\n 1\n } else {\n 0\n }\n }\n\n return canChooseSymbolNumber\n}\n\nfun mustChooseSymbolNumber(missingSymbols : ArrayList, mustHaveCharsNumber: Int) : Int {\n var mustChooseCharsNumber = 0\n for (symbol in missingSymbols) {\n if (symbol - 'a' < mustHaveCharsNumber) {\n mustChooseCharsNumber++\n }\n }\n\n return mustChooseCharsNumber\n}\n\nfun hasAnswer(string: String) : Boolean {\n for (i in 0 until (string.length + 1) / 2) {\n if (string[i] != '?' && string[string.length - 1 - i] != '?') {\n if (string[i] != string[string.length - 1 - i]) {\n return false\n }\n }\n }\n\n return true\n}\n\nfun solveProblem(string: String, mustHaveCharsNumber : Int) : ArrayList? {\n val chars = ArrayList()\n val missingSymbols = getStringMissingSymbols(string)\n val mustChooseCharsNumber = mustChooseSymbolNumber(missingSymbols, mustHaveCharsNumber)\n var canChooseCharsNumber = canChooseSymbolNumber(string)\n var index = 0\n\n if (mustChooseCharsNumber > canChooseCharsNumber || !hasAnswer(string)) {\n return null\n }\n\n for (char in string) {\n chars.add(char)\n }\n\n for (i in 0 until (string.length + 1) / 2) {\n if (string[i] == '?' && string[string.length - 1 - i] == '?') {\n if (mustChooseCharsNumber < canChooseCharsNumber) {\n chars[i] = 'a'\n chars[string.length - 1 - i] = 'a'\n canChooseCharsNumber--\n } else {\n chars[i] = missingSymbols[index]\n chars[string.length - 1 - i] = missingSymbols[index]\n index++\n }\n } else if (string[i] == '?') {\n chars[i] = string[string.length - 1 - i]\n chars[string.length - 1 - i] = string[string.length - 1 - i]\n } else {\n chars[i] = string[i]\n chars[string.length - 1 - i] = string[i]\n }\n }\n\n return chars\n}\n\nfun main() {\n val reader = Scanner(System.`in`)\n val mustHaveCharsNumber = reader.nextInt()\n val string = reader.next()\n val resultString = solveProblem(string, mustHaveCharsNumber)\n\n if (resultString == null) {\n print(\"IMPOSSIBLE\")\n } else {\n for (char in resultString) {\n print(char)\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["expression parsing"], "code_uid": "1a0d17b976b4e006fe7a8433e9db920c", "src_uid": "9d1dd9d722e5fe46823224334b3b208a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package ru.spbau.mit\n\nimport java.util.*\n\nclass Solver(k: Int, internal val bookTitle: CharArray) {\n companion object {\n private val IMPOSSIBLE = \"IMPOSSIBLE\".toCharArray()\n }\n private val unusedLetters: ArrayDeque\n init {\n val firstKLetters = 'a' until 'a' + k\n val usedLetters = bookTitle.toSet()\n unusedLetters = ArrayDeque(firstKLetters - usedLetters)\n }\n\n fun solve(): CharArray {\n val ok = removePairedQuestionMarks() && removeSingleQuestionMarks()\n return if (ok) bookTitle else IMPOSSIBLE\n }\n\n internal fun removeSingleQuestionMarks(): Boolean {\n for (i in 0 until bookTitle.size / 2) {\n val currentSymbol = bookTitle[i]\n val correspondingIndex = i.correspondingIndex\n val correspondingSymbol = bookTitle[correspondingIndex]\n when {\n currentSymbol == '?' -> bookTitle[i] = correspondingSymbol\n correspondingSymbol == '?' -> bookTitle[correspondingIndex] = currentSymbol\n currentSymbol != correspondingSymbol -> return false\n }\n }\n return true\n }\n\n internal fun removePairedQuestionMarks(): Boolean {\n for (i in bookTitle.size / 2 until bookTitle.size) {\n val currentSymbol = bookTitle[i]\n val correspondingIndex = i.correspondingIndex\n val correspondingSymbol = bookTitle[correspondingIndex]\n if (currentSymbol == '?' && correspondingSymbol == '?') {\n val extractedLetter = getAndExtractMaxUnusedLetterOrA()\n bookTitle[i] = extractedLetter\n bookTitle[correspondingIndex] = extractedLetter\n }\n }\n return unusedLetters.isEmpty()\n }\n\n private fun getAndExtractMaxUnusedLetterOrA(): Char =\n if (unusedLetters.isEmpty()) 'a' else unusedLetters.removeLast()\n\n private val Int.correspondingIndex: Int get() = bookTitle.size - this - 1\n}\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n val k = input.nextInt()\n val bookTitle = input.next().toCharArray()\n print(Solver(k, bookTitle).solve())\n}\n", "lang_cluster": "Kotlin", "tags": ["expression parsing"], "code_uid": "bb05980d1be11bd5f74f640410edd97d", "src_uid": "9d1dd9d722e5fe46823224334b3b208a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val k = scanner.nextInt()\n val title = scanner.next().toCharArray()\n\n if (doStuff(k, title)) {\n println(title)\n }\n else {\n println(\"IMPOSSIBLE\")\n }\n}\n\nprivate fun doStuff(k: Int, title: CharArray): Boolean {\n val n = title.size\n val half = n / 2\n\n val unusedChars = BitSet(k)\n for (ch in title) {\n if (ch == '?') continue\n unusedChars.set(ch.minus(97).toInt())\n }\n unusedChars.flip(0, k)\n\n for (leftI in 0..half) {\n val rightI = n - leftI - 1\n\n val left = title[leftI]\n val right = title[rightI]\n\n val leftQ = left == '?'\n val rightQ = right == '?'\n if (leftQ && rightQ) continue\n\n if (leftQ) {\n title[leftI] = right\n }\n else if (rightQ) {\n title[rightI] = left\n }\n else if (left != right) {\n return false\n }\n }\n\n var lastUsedIndex = k - 1\n for (rightI in half until n) {\n val leftI = n - rightI - 1\n\n val left = title[leftI]\n val right = title[rightI]\n\n if (left == '?' && right == '?') {\n lastUsedIndex = unusedChars.previousSetBit(lastUsedIndex)\n val unusedChar = if (lastUsedIndex == -1) {\n 'a'\n }\n else {\n unusedChars.set(lastUsedIndex, false)\n lastUsedIndex.plus(97).toChar()\n }\n title[leftI] = unusedChar\n title[rightI] = unusedChar\n }\n }\n\n return unusedChars.isEmpty\n}\n", "lang_cluster": "Kotlin", "tags": ["expression parsing"], "code_uid": "4ed0b66282f4cd9c91b03905615e7266", "src_uid": "9d1dd9d722e5fe46823224334b3b208a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package ru.spbau.mit\n\nimport java.util.*\n\nfun getTitle(amountOfLetters: Int, pattern: String): String {\n val patternChars: CharArray = pattern.toCharArray()\n val patternLength = patternChars.size\n val occupiedLetters = BitSet(amountOfLetters)\n occupiedLetters.set(0, amountOfLetters, false)\n patternChars.forEach { letter ->\n if (letter != '?') {\n occupiedLetters.set(letter - 'a')\n }\n }\n val middle = if (patternLength % 2 == 0)\n patternLength / 2 - 1\n else\n patternLength / 2\n for (i in middle downTo 0) {\n if (patternChars[i] == '?') {\n val symmetricIndex = getSymmetricIndex(i, patternLength)\n if (patternChars[symmetricIndex] == '?') {\n val theLastNotOccupiedLetterIndex = occupiedLetters.previousClearBit(amountOfLetters - 1)\n if (theLastNotOccupiedLetterIndex == -1) {\n patternChars[i] = 'a'\n } else {\n patternChars[i] = 'a' + theLastNotOccupiedLetterIndex\n occupiedLetters.set(theLastNotOccupiedLetterIndex)\n }\n patternChars[symmetricIndex] = patternChars[i]\n } else {\n patternChars[i] = patternChars[symmetricIndex]\n }\n }\n }\n\n (patternLength - 1 downTo middle)\n .forEach {\n val symmetricIndex = getSymmetricIndex(it, patternLength)\n if (patternChars[it] == '?') {\n patternChars[it] = patternChars[symmetricIndex]\n }\n if (patternChars[it] != patternChars[symmetricIndex]) {\n return \"IMPOSSIBLE\"\n }\n }\n\n if (occupiedLetters.cardinality() != amountOfLetters) {\n return \"IMPOSSIBLE\"\n }\n return String(patternChars)\n}\n\nprivate fun getSymmetricIndex(index: Int, length: Int): Int {\n return length - index - 1\n}\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n val amountOfLetters: Int = input.nextInt()\n val pattern: String = input.next()\n input.close()\n println(getTitle(amountOfLetters, pattern))\n}", "lang_cluster": "Kotlin", "tags": ["expression parsing"], "code_uid": "2c8435d758eb603d9afd6262e40a00a5", "src_uid": "9d1dd9d722e5fe46823224334b3b208a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.nextInt()\n var k = reader.nextInt()\n val counter = IntArray(26)\n reader.next().forEach { counter[it - 'a']++ }\n\n var sum = 0\n for (i in 0 until 26) {\n if (counter[i] > 0 && k > 0) {\n k--\n sum += i + 1\n if (i + 1 < 26) {\n counter[i + 1] = 0\n }\n }\n }\n writer.println(if (k > 0) \"-1\" else \"$sum\")\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}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "7fc0a6d3d1dfb77552a521177bfe3f45", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numAvailableStages, numRocketStages) = readInts()\n val availableStages = readLine()!!.toCharArray()\n availableStages.sort()\n var last = 'Z'\n var sol = 0\n var availableStagesPos = 0\n for(pos in 0 until numRocketStages) {\n while (availableStagesPos < numAvailableStages && availableStages[availableStagesPos] - 2 < last)\n availableStagesPos++\n if (availableStagesPos == numAvailableStages) return print(-1)\n last = availableStages[availableStagesPos]\n sol += last - 'a' + 1\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "d7870f582b32bcab5eab8ca5d7d72b3e", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n\n val len = sc.nextInt()\n val needed = sc.nextInt()\n\n val levels = IntArray(26)\n\n val str = sc.next()\n\n for (c in str) {\n levels[c.toInt() - 'a'.toInt()] = 1\n }\n\n var min = 10000000\n\n fun bt(sum: Int, k: Int, l: Int) {\n if (l == needed) {\n if (sum < min) {\n min = sum\n }\n } else {\n for (i in k + 2 until levels.size) {\n if (levels[i] == 1) {\n val s = sum + i + 1\n bt(s, i, l + 1)\n }\n }\n }\n }\n bt(0, -2, 0)\n if (min == 10000000) {\n println(\"-1\")\n } else {\n println(min)\n }\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "8ed3b6631c41894bc697799fb320f0a9", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args: Array) {\n\n val a = readLine()!!.splitToIntArray()\n val x = readLine()!!.toCharArray()\n val k = a[1]\n\n for (i in 0 until x.size) {\n var m = i\n for (j in i + 1 until x.size) {\n if (x[j] < x[m]) {\n m = j\n }\n }\n val q = x[i]\n x[i] = x[m]\n x[m] = q\n }\n\n var s = \"\"\n\n s += x[0]\n\n for (i in 1 until x.size) {\n val c = x[i]\n if ((c - s.last()) < 2) continue\n s += c\n }\n\n if (s.length < k) {\n System.out.println(-1)\n } else {\n s = s.substring(0 until k)\n var ans = 0\n for (c in s) {\n ans += c.toInt() - 'a'.toInt() + 1\n }\n System.out.println(ans)\n }\n\n\n}\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}\n", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "02c6584c634d7aee45920ebd60d94921", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "60e30387635e43b1b0f64c40647207a6", "src_uid": "236177ff30dafe68295b5d33dc501828", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "e24cbaf866ad87d182e0f9e364011f03", "src_uid": "236177ff30dafe68295b5d33dc501828", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "f9267bec19812c02614fb4af8925f5bd", "src_uid": "236177ff30dafe68295b5d33dc501828", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "87b8edfafd85477aa53624cff814617b", "src_uid": "236177ff30dafe68295b5d33dc501828", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.util.*\n\n\nfun main(){\n\n val fr = FastReader()\n var a1 = fr.nextInt()\n var a2 = fr.nextInt()\n var k1 = fr.nextInt()\n var k2 = fr.nextInt()\n var n = fr.nextInt()\n\n if(k1 > k2){\n var tmp = k1\n k1 = k2;\n k2 = tmp;\n tmp = a1;\n a1 = a2;\n a2 = tmp;\n }\n\n var min = n - (a1*(k1 - 1) + a2*(k2 - 1))\n var max = 0\n if (min <= 0) {\n min = 0;\n }\n if(n <= a1*k1) {\n max = n / k1;\n }else {\n max = a1 + (n - a1*k1) / k2;\n }\n println(\"$min $max\")\n\n}\n\nclass FastReader{\n\n private var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\n private var st : StringTokenizer? = null\n\n fun next() : String {\n while(st == null || !st!!.hasMoreTokens()){\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 Integer.parseInt(next())\n }\n\n fun nextDouble() : Double{\n return next().toDouble()\n }\n\n fun nextLong() : Long{\n return next().toLong()\n }\n\n fun nextString() : String{\n var str : String = \"\"\n try{\n str = br.readLine()\n }catch(e: IOException){\n e.printStackTrace()\n }\n return str\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "85889a04f2f3899ee61bd38e5668145e", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.contracts.contract\nimport kotlin.math.max\nimport 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\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of Longs\n\nfun mmin(a1: Int, a2: Int, k1: Int, k2: Int, n: Int): Int {\n var ansMin = 0\n var n = n\n\n val m = ArrayList()\n for (i in 1..a1) m.add(k1)\n for (i in 1..a2) m.add(k2)\n\n var key = false\n while (!key) {\n key = true\n for (i in 0 until m.size) {\n val k = m[i]\n if (k <= 1) continue\n n--\n if (n < 0) {\n key = true\n break\n }\n m[i]--\n key = false\n }\n }\n\n ansMin = max(0, min(n, a1 + a2))\n\n return ansMin\n}\n\nfun mmax(a1: Int, a2: Int, k1: Int, k2: Int, n: Int): Int {\n var ansMax = 0\n\n val q = ArrayList()\n for (i in 1..a1) q.add(k1)\n for (i in 1..a2) q.add(k2)\n var nmax = n\n q.sort()\n\n while (nmax > 0) {\n for (t in q) {\n nmax -= t\n if (nmax >= 0) {\n ansMax++\n }\n }\n }\n\n return ansMax\n}\n\nfun main() {\n\n release()\n// tests()\n}\n\nfun release(){\n var a1 = readInt()\n var a2 = readInt()\n var k1 = readInt()\n var k2 = readInt()\n var n = readInt()\n//\n val ansMin = mmin(a1, a2, k1, k2, n)\n val ansMax = mmax(a1, a2, k1, k2, n)\n//\n print(\"$ansMin $ansMax\")\n}\n\nfun tests() {\n println(test(2,3,5,1,8,0,4))\n println(test(3,1,6,7,25,4,4))\n println(test(6,4,9,10,89,5,9))\n// println(test())\n// println(test())\n// println(test())\n}\n\nfun test(a1: Int, a2: Int, k1: Int, k2: Int, n: Int, ans1: Int, ans2: Int): Boolean{\n return (mmin(a1, a2, k1, k2, n) == ans1) && (mmax(a1, a2, k1, k2, n) == ans2)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "4e538e3ced750c40e5c77146802a5033", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport kotlin.math.max\n\n\nfun main() {\n var a1 = readLine()!!.toInt()\n var a2 = readLine()!!.toInt()\n var k1 = readLine()!!.toInt()\n var k2 = readLine()!!.toInt()\n var n = readLine()!!.toInt()\n var max = 0\n var min = 0\n\n\n if (k1 > k2) {\n var buf = a1\n a1 = a2\n a2 = buf\n buf = k1\n k1 = k2\n k2 = buf\n }\n\n var zerolimit = (k1 - 1) * a1 + (k2 - 1) * a2\n\n min = max(0, n - zerolimit)\n\n max = if (n / k1 < a1) n / k1\n else {\n var nost = n - a1 * k1\n a1 + nost / k2\n }\n println(\"$min $max\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "fd97d96b1344eb327655af6bc2433200", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.max\n\nfun berlandFootballMinMaxCards(\n numPlayers1: Int,\n numPlayers2: Int,\n numCards1: Int,\n numCards2: Int,\n numCardsShown: Int\n): Pair {\n var amax = numPlayers1\n var kmax = numCards1\n var amin = numPlayers2\n var kmin = numCards2\n\n // Swap if needed.\n if (kmax < kmin) {\n amax = numPlayers2\n kmax = numCards2\n amin = numPlayers1\n kmin = numCards1\n }\n\n val min = max(numCardsShown - ((kmin - 1) * amin + (kmax - 1) * amax), 0)\n\n val rem = max(numCardsShown - amin * kmin, 0)\n\n val max = if (rem > 0) {\n amin + rem / kmax\n } else numCardsShown / kmin\n\n return Pair(min, max)\n}\n\nfun main() {\n val scan = Scanner(System.`in`)\n\n val numPlayers1 = scan.nextLine().toInt()\n val numPlayers2 = scan.nextLine().toInt()\n val numCards1 = scan.nextLine().toInt()\n val numCards2 = scan.nextLine().toInt()\n val numCardsShown = scan.nextLine().toInt()\n\n val result = berlandFootballMinMaxCards(numPlayers1, numPlayers2, numCards1, numCards2, numCardsShown)\n val resultString = \"${result.first} ${result.second}\"\n\n println(resultString)\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "63f1a3e8ee95d54470fd023108fed690", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.InputStream\n\nval input = FastScanner()\n\nfun main(args: Array) = input.run {\n val m = nextInt()\n val b = nextInt()\n\n var ans = 0L\n\n (0..b).forEach { y ->\n val x = (b - y) * m\n var acc = 0L\n (0..y).forEach { yy ->\n acc += (x + 1) * yy.toLong() + x * (x + 1L) / 2\n }\n ans = ans.coerceAtLeast(acc)\n }\n\n println(ans)\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "f251e6ebb5b97e9bed2d4c0b88319115", "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.comparisons.compareBy\nimport kotlin.comparisons.thenBy\nimport kotlin.comparisons.thenByDescending\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 }\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 fun read() {\n val m = input.nextLong()\n val b = input.nextLong()\n var y = b\n var x = 0L\n var ans = getSum(y)\n while (y > 0) {\n y--\n x += m\n val s = getSum(x)\n val cur = (y + 1) * s + (x + 1) * getSum(y)\n ans = Math.max(ans, cur)\n }\n output.println(ans)\n }\n\n private fun getSum(s: Long): Long {\n return s * (s + 1) / 2\n }\n\n private fun read2() {\n val n = input.nextInt()\n val a = Array(n, { IntArray(n) })\n for (i in 0..n - 1) {\n for (j in 0..n - 1) {\n a[i][j] = input.nextInt()\n }\n }\n for (i in 0..n - 1) {\n for (j in 0..n - 1) {\n if (a[i][j] != 1) {\n var ok = false\n for (s in 0..n - 1) {\n for (k in 0..n - 1) {\n if (a[i][j] == a[i][s] + a[k][j]) {\n ok = true\n }\n }\n }\n if (!ok) {\n output.println(\"No\")\n return\n }\n }\n }\n }\n output.println(\"Yes\")\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 fun nextDouble(): Double = next().toDouble()\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "595cf15f81cf127072e379f5b6d44e57", "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(){\n var b = readLine()!!.toLong()\n var ans = 0\n for(i : Long in 1..b){\n if(i * i > b) break\n if(b % i == 0L){\n ans += 1\n if(i * i != b) ans += 1\n }\n }\n print(ans)\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "35ecbacd7b681c3f80df499a33ab6cc3", "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.sqrt\n\n// unable to solve it by myself. Solution on the editorial: https://codeforces.com/blog/entry/62688\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 1L..endLoop) {\n if (this % i == 0L) {\n output.add(i)\n output.add(this / i)\n }\n }\n return output\n }\n\n print(readLong().factors().size)\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "7ceed9cc298a76874dad1c35664bdc9e", "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var b = readLine()!!.toLong()\n var ans = 1\n for (i in 2..100000) {\n if (b % i == 0L) {\n var count = 0\n while (b % i == 0L) {\n b /= i\n count ++\n }\n ans *= (count + 1)\n }\n }\n if (b != 1L) ans *= 2\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "5898cf56a0cb41d959f18b5f36a719e5", "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 line = input.readLine()\n var cur = 'a'\n var answer = 0\n for (c in line) {\n val shortest = Math.min(Math.min(Math.abs(c - cur), 'z' - cur + (c - 'a') + 1), cur - 'a' + ('z' - c) + 1)\n answer += shortest\n cur = c\n }\n output.println(answer)\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "623c1f5e52f1791c1adc34873c537fc0", "src_uid": "ecc890b3bdb9456441a2a265c60722dd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 embosser(s)\n \n}\nfun embosser(s: Scanner){\n val a = s.next()\n val char = a.toCharArray();\n var intial = 'a'\n var total = 0 \n for(i in char.indices){\n val value = Math.abs(intial-char[i])\n if(value >13){\n total += 26 - value\n \n }else{\n total += value \n }\n intial = char[i]\n }\n \n print(total)\n \n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "a42e1e93dbba3035388544d51e10cc60", "src_uid": "ecc890b3bdb9456441a2a265c60722dd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 ans = 0\n var d = 0\n var a = 'a'\n for (c in s) {\n ans += minOf(maxOf(c.toInt(), a.toInt()) - minOf(c.toInt(), a.toInt()), 26 - (maxOf(c.toInt(), a.toInt()) - (minOf(c.toInt(), a.toInt()))))\n a = c \n }\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "b1543ec7f1c2d4c648263673446833f2", "src_uid": "ecc890b3bdb9456441a2a265c60722dd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.min\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 `CF731-D2-A` {\n fun solveTestCase(): Int {\n var total = 0\n var first = false\n var origin: Int = 0\n val aVal = 'a'.toInt()\n val numOfAlphabet = 26\n for (c in read()) {\n if(first) {\n origin = c.toInt() - aVal\n first = false\n } else {\n var destination = c.toInt() - aVal\n var clockwise = destination - origin\n var counterClock = origin - destination\n if (clockwise < 0)\n clockwise += numOfAlphabet\n if (counterClock < 0)\n counterClock += numOfAlphabet\n total += min(clockwise, counterClock)\n origin = destination\n }\n }\n\n return total\n }\n}\n\nfun main(args: Array) {\n outputWriter.println(\n `CF731-D2-A`()\n .solveTestCase()\n )\n\n outputWriter.flush()\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "ddca0740af9c2988d22ac78f273004ab", "src_uid": "ecc890b3bdb9456441a2a265c60722dd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val length = readLine()!!.toInt()\n val s = readLine()!!\n val sb = StringBuilder()\n var pos = -1\n while (++pos < length)\n if (pos + 2 >= length || s.substring(pos..pos + 2) != \"ogo\")\n sb.append(s[pos])\n else {\n sb.append(\"***\")\n while (pos + 2 < length && s.substring(pos + 1..pos + 2) == \"go\") pos += 2\n }\n print(sb.toString())\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "8bf4c000d59b7bffc4b5abb920e9cd8a", "src_uid": "619665bed79ecf77b083251fe6fe7eb3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 = input.readLine()\n val l = input.readLine()\n val r = \"ogo(go)*\".toRegex()\n val o = r.replace(l, \"***\")\n output.println(o)\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "e9fd2842b25f8bf00ec08c2ed8b126f1", "src_uid": "619665bed79ecf77b083251fe6fe7eb3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "val mapper = listOf(4,1,3,2,0,5)\n\nfun main() {\n val x = readLine()!!.toInt()\n val bit = BooleanArray(6) {(x and (1 shl it)) != 0}\n\n val bit2 = BooleanArray(6) {bit[mapper[it]]}\n\n var y = 0\n for(i in bit2.indices) {\n if(bit2[i])\n y += (1 shl i)\n }\n\n print(y)\n}", "lang_cluster": "Kotlin", "tags": ["bitmasks"], "code_uid": "88d0070ff015f38f92bd00a367b2aadf", "src_uid": "db5e54f466e1f3d69a51ea0b346e667c", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var s = readLine()!!.toInt().toString(2)\n while (s.length < 6) {\n s = \"0\" + s\n }\n val builder = StringBuilder()\n builder.append(s[0]).append(s[5]).append(s[3]).append(s[2]).append(s[4]).append(s[1])\n println(builder.toString().toInt(2))\n}", "lang_cluster": "Kotlin", "tags": ["bitmasks"], "code_uid": "7cc5ac8530a44f73b593877f1564e60b", "src_uid": "db5e54f466e1f3d69a51ea0b346e667c", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n\tval n = readLine()!!.toInt()\n\tval s = n.toString(2).padStart(6, '0')\n\tprintln(listOf(0, 5, 3, 2, 4, 1).joinToString(\"\") { s[it].toString() }.toInt(2))\n}\n", "lang_cluster": "Kotlin", "tags": ["bitmasks"], "code_uid": "7b4aeb27efd15bc9fe6f6451991ca8b2", "src_uid": "db5e54f466e1f3d69a51ea0b346e667c", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 A = intArrayOf(4, 1, 3, 2, 0, 5)\n\n val n = readInt()\n var ans = 0\n for(i in A.indices) {\n if(n shr i and 1 == 1) ans += 1 shl A[i]\n }\n\n println(ans)\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 _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}", "lang_cluster": "Kotlin", "tags": ["bitmasks"], "code_uid": "ff9c9deeef537956ff536acddb2e9b9e", "src_uid": "db5e54f466e1f3d69a51ea0b346e667c", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "690aa9d0f56d45c2da2ec58f78d5ba9a", "src_uid": "6119258322e06fa6146e592c63313df3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "dee80b5d52b747142a3b7cae71f1ff99", "src_uid": "6119258322e06fa6146e592c63313df3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "0d9de2b03718c107cf260c5508fcb20a", "src_uid": "6119258322e06fa6146e592c63313df3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7440c64d0852546d59c658a00ca9a9c7", "src_uid": "6119258322e06fa6146e592c63313df3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n println(find(readLine()!!.toInt(),1))\n}\n\nfun find(current : Int, total : Int) : Int{\n var i = 1\n while(current > i ) i*=2\n return if (current == i) total else find(current - i/2, total + 1)\n}", "lang_cluster": "Kotlin", "tags": ["bitmasks"], "code_uid": "9981449130ba6708cf2756cffc522b69", "src_uid": "03e4482d53a059134676f431be4c16d2", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val x = br.readLine().toInt()\n val bin = x.toString(2)\n println(bin.fold(0){acc, c -> acc + if (c == '1') 1 else 0})\n}", "lang_cluster": "Kotlin", "tags": ["bitmasks"], "code_uid": "66caaf54882e22b03483b41ef097a5b1", "src_uid": "03e4482d53a059134676f431be4c16d2", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.absoluteValue\n\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n var mask = 1\n var count = 0\n for (i in 1..32) {\n if (n.and(mask) != 0)\n count++\n mask = mask.shl(1)\n }\n println(count)\n}", "lang_cluster": "Kotlin", "tags": ["bitmasks"], "code_uid": "f35f1a88f3a35f4c8b869347222d6baf", "src_uid": "03e4482d53a059134676f431be4c16d2", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n println(readLine()!!.toInt().toString(2).count { it == '1' })\n}", "lang_cluster": "Kotlin", "tags": ["bitmasks"], "code_uid": "c95bd96fc15d7d278597c15349a8a92a", "src_uid": "03e4482d53a059134676f431be4c16d2", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n val n = scanner.nextInt()\n\n var cnt = n - 1\n\n var max: Double = -1.0\n\n var resA = 0\n var resB = 0\n\n while (cnt > 0) {\n val a = cnt\n val b = n - cnt\n //System.out.println(\"$a $b\")\n if (a < b && nod(a,b) == 1) {\n if (a.toDouble() / b.toDouble() > max) {\n max = a.toDouble() / b.toDouble()\n resA = a\n resB = b\n }\n }\n cnt--\n }\n\n System.out.print(\"$resA $resB\")\n\n}\n\n\nfun nod(a: Int, b: Int): Int {\n var aa = a\n var bb = b\n\n while (bb != 0) {\n val tmp = bb\n bb = aa % bb\n aa = tmp\n }\n\n return aa\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "6a17fc01c80277b40a0bb70d01f2129e", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n\n val n = readInt()\n var bestA = 0\n var bestB = 0\n loop@for (a in 1 .. n/2) {\n val b = n - a\n for (divisor in 2 .. min(a, b))\n if (a % divisor == 0 && b % divisor == 0) continue@loop\n bestA = a\n bestB = b\n }\n print(\"$bestA $bestB\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "5bd37963b02027b0f80df5d68d1a6479", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n/**\n * Created by v.shipugin on 30/08/2018\n */\nfun main(args: Array) {\n Cont433().first()\n}\n\nclass Cont433 {\n\n fun first() {\n val scanner = Scanner(System.`in`)\n\n val n = scanner.nextInt()\n var ar = 1f\n var br = (n - 1).toFloat()\n\n for (a in 1..n / 2) {\n val b: Float = (n - a).toFloat()\n var coprime = true\n\n// println(\"a:$a b:$b\")\n\n for (d in 2..a) {\n val ad = (a % d).toFloat()\n val bd = b % d\n\n// println(\"d:$d ad:$ad bd:$bd\")\n\n if (ad == 0f && bd == 0f) {\n coprime = false\n }\n }\n\n val adb = a / b\n val ardb = ar / br\n// println(\"adb:$adb ardb:$ardb\")\n if (coprime && adb > ardb) {\n ar = a.toFloat()\n br = b\n// println(\"change ar:$ar br:$br\")\n }\n }\n\n println(\"${ar.toInt()} ${br.toInt()}\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "26ca3a539b495f8f013877e3756b2d6a", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()?.toInt() ?: return\n\n when {\n n == 2 -> println(\"1 1\")\n n % 4 == 0 -> println(\"${n / 2 - 1} ${n / 2 + 1} \")\n n % 2 == 0 -> println(\"${n / 2 - 2} ${n / 2 + 2} \")\n else -> println(\"${n / 2} ${n / 2 + 1} \")\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "2b1091fee003927d62ee1c512e24f9c3", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "e3b4950f65c0615c5fd74ff881ac0864", "src_uid": "5deaac7bd3afedee9b10e61997940f78", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d6d4dc64224fec6812acbb1bbc012531", "src_uid": "5deaac7bd3afedee9b10e61997940f78", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a1d16174363b8c7b17fffa9378a8918f", "src_uid": "5deaac7bd3afedee9b10e61997940f78", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.nextInt()\n val m = scanner.nextInt()\n val days = Array>(n) { ArrayList() }\n val arr = IntArray(n) { -1 }\n val q = IntArray(m) { 0 }\n val res = IntArray(n)\n for (i in 0 until m) {\n val a = scanner.nextInt() - 1\n val b = scanner.nextInt() - 1\n val c = scanner.nextInt()\n days[a].add(b)\n arr[b] = i\n q[i] = c\n }\n val set = PriorityQueue {\n o1, o2 -> o1.a - o2.a\n }\n for (i in 0 until n) {\n for (j in days[i])\n set.add(Pair(j, arr[j]))\n if (arr[i] != -1) {\n if (q[arr[i]] != 0) {\n println(-1)\n return\n }\n res[i] = m + 1\n }\n else if (set.size > 0) {\n val p = set.first()\n q[p.b]--\n if (q[p.b] == 0)\n set.remove(p)\n res[i] = p.b + 1\n }\n }\n res.forEach { print(\"$it \") }\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\nclass Pair(val a: Int, val b: Int): Comparable {\n override fun compareTo(other: Pair): Int {\n return other.a - a\n }\n}\n\n//class Triple(val a: Int, val b: Int, val c: Int, val i: Int): Comparable {\n// override fun compareTo(other: Triple): Int {\n// return b - other.b\n// }\n//}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "d496161ed037f3fd3ea2f5059e27c82d", "src_uid": "02d8d403eb60ae77756ff96f71b662d3", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\nimport kotlin.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\n\nfun main(args: Array) {\n val(a,b)=readInts()\n var x=0\n var y=0\n var z=0\n\n for(dice in 1..6) {\n if(abs(dice-a)abs(dice-b))y++\n else z++\n }\n\n println(\"$x $z $y\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "0729a0209a64b3ebb377aea3bbb2ca7e", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun main(args: Array) = with(java.util.Scanner(System.`in`)) {\n var a = nextInt()\n var b = nextInt()\n var win = 0\n var draw = 0\n var lose = 0\n for( i in 1..6){\n if(abs(a-i) == abs(i-b))draw++\n else if(abs(a-i)>abs(i-b))lose++\n else win++\n }\n println(\"$win $draw $lose\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "7cde23d6cc9cb34416075a9a523dcbc4", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val len = r.readLine()!!.toInt()\n val (a, b) = r.readLine()!!.split(\" \").map { it.toInt() }\n var q = 0\n var w = 0\n var e = 0\n (1..6).forEach {\n when{\n abs(a-it)< abs(b-it) -> q++\n abs(a-it)== abs(b-it) -> w++\n abs(a-it)> abs(b-it) -> e++\n }\n }\n println(\"$q $w $e\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "c548c64d5d9b7f4902ca37b51e1e3104", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.abs\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val a = nextInt()\n val b = nextInt()\n var res = IntArray(3)\n repeat(6) {\n when {\n abs(a - (it + 1)) < abs(b - (it + 1)) -> res[0]++\n abs(a - (it + 1)) > abs(b - (it + 1)) -> res[2]++\n else -> res[1]++\n }\n }\n res.forEach { s -> print(\"$s \") }\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "eb1cfb03b6e9f29021ed38307a67bdfd", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.pow\n\nfun main() {\n val reader = Scanner(System.`in`)\n val nThOrderRhomb = reader.nextFloat()\n println((nThOrderRhomb.pow(2) + (nThOrderRhomb - 1).pow(2)).toInt())\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "implementation"], "code_uid": "e782e62f6b41e57627f4a8017c6452a2", "src_uid": "758d342c1badde6d0b4db81285be780c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n\nimport java.io.PrintWriter\nimport java.util.*\nimport kotlin.math.max\nimport kotlin.math.pow\n\n@JvmField\n val INPUT = System.`in`!!\n @JvmField\n val OUTPUT = System.out!!\n\n @JvmField\n val reader = INPUT.bufferedReader()\n\n fun readLine(): String? = reader.readLine()\n fun readLn() = reader.readLine()!!\n @JvmField\n var tokenizer: StringTokenizer = StringTokenizer(\"\")\n\n fun read(): String {\n while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(reader.readLine() ?: return \"\", \" \")\n return tokenizer.nextToken()\n }\n\n fun readInt() = read().toInt()\n fun readDouble() = read().toDouble()\n fun readLong() = read().toLong()\n fun readIntArray(n: Int) = IntArray(n) { read().toInt() }\n fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\n fun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n @JvmField\n val rw = PrintWriter(OUTPUT, false)\n\n inline fun output(block: PrintWriter.() -> Unit) {\n rw.apply(block).flush()\n }\n\n fun printLArray(a: LongArray) { a.forEach { x -> rw.print(x); rw.print(\" \") };rw.println() }\n fun printIArray(a: IntArray) { a.forEach { x -> rw.print(x);rw.print(\" \") };rw.println() }\n\n private var is_prime: BooleanArray? = null\n private var prime: ArrayList? = null\n fun sieve(n: Int) {\n is_prime = BooleanArray(n + 10)\n prime = ArrayList()\n for (i in 2..n) is_prime!![i] = true\n for (i in 2..n) {\n if (is_prime!![i]) prime!!.add(i)\n var j = 0\n while (j < prime!!.size && i * prime!![j] < n) {\n is_prime!![i * prime!![j]] = false\n if (i % prime!![j] == 0) break\n ++j\n }\n }\n }\n\n fun mergeSort(a: IntArray) {\n val n = a.size\n if (n < 2) return\n val mid = n / 2; val left = IntArray(mid); val right = IntArray(n - mid)\n for (i in 0 until mid) left[i] = a[i]\n for (i in mid until n) right[i - mid] = a[i]\n mergeSort(left);mergeSort(right);merge(left, right, a)\n }\n\n fun merge(left: IntArray, right: IntArray, a: IntArray) {\n val nLeft = left.size; val nRight = right.size\n var i = 0; var j = 0; var k = 0\n while (i < nLeft && j < nRight) {\n if (left[i] <= right[j]) {\n a[k] = left[i];k++;i++\n } else {\n a[k] = right[j]; k++;j++\n }\n }\n while (i < nLeft) {a[k] = left[i]; i++; k++}\n while (j < nRight){a[k] = right[j]; j++; k++}\n }\n\n fun gcd(a: Long, b: Long): Long {\n if (b == 0L) return a\n return gcd(b, a % b)\n }\n\n fun smallest(a: IntArray): Int {\n var min = a[0]\n for (i in 1 until a.size) {\n if (a[i] < min) min = a[i]\n }\n return min\n }\nfun main(){\n\n val n = readInt()\n val dp = IntArray(n)\n dp[0] = 1\n for (i in 1 until n) dp[i] = dp[i - 1] + 4*i\n rw.println(dp[n-1])\n rw.close()\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "implementation"], "code_uid": "5f07628ae0f19cc35c0f287cf2db0db3", "src_uid": "758d342c1badde6d0b4db81285be780c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n\n val n = readLine()!!.toInt()\n\n var a_n = 1\n for (i in 2..n) {\n a_n += 4 * (i-1)\n }\n\n println(a_n)\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "implementation"], "code_uid": "5d95b8f45f825097aa9abac1d3886c07", "src_uid": "758d342c1badde6d0b4db81285be780c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nfun main(args: Array) {var reader= Scanner(System.`in`)\n var n = reader.nextInt()\n print( 2*(n)*(n-1) + 1)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "implementation"], "code_uid": "ce7ee545d30e23e10f9a945cfebdea6d", "src_uid": "758d342c1badde6d0b4db81285be780c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "binary search"], "code_uid": "8a8ff65d6a6c25de69ea15efedb1bde3", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "binary search"], "code_uid": "a78cf23346e8eef876a8253a2e418763", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "binary search"], "code_uid": "bf3c17792128bb615fd1ac5ffaefe011", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.IllegalArgumentException\n\nprivate fun readString() = readLine()!!\nprivate fun readInt() = readString().toInt()\nprivate fun readStrings() = readString().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n\n\nfun sportMafia(moves: Long, candiesLeft: Long): Int {\n var left = 0L\n var right = moves\n while (left <= right) {\n val current = left + (right - left) / 2\n val broughtIn = sumOf(current)\n val eaten = moves - current\n val resultingCandies = broughtIn - eaten\n when {\n resultingCandies < candiesLeft -> {\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "binary search"], "code_uid": "f40d8fd7291f7052d5527c406d1fa3b4", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4ade07bc3f11dbd4ad6efd901a434980", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9118bd7e622edc8fca248a4e6118603f", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "cc413127f4d118168dc67087d439a160", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7cfae183a9b989451f8ceae8d740db5f", "src_uid": "8c704de75ab85f9e2c04a926143c8b4a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.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 percent = ModInt(100).inverse()\n\n val n = readInt()\n val pipes = List(n) { Pipe(readInt(), readInt(), percent * readInt()) }\n val tree = SegmentTree(n, null, nullIdentityCombiner(Seg::plus))\n\n tree.build { i ->\n Seg(\n ll = 1 - pipes[i].p,\n lr = ModInt(0),\n rl = ModInt(0),\n rr = pipes[i].p,\n ban = NONE\n )\n }\n\n val cols = ArrayList(n-1 shl 1)\n\n for(i in 0 until n-1) {\n val a = pipes[i]\n val b = pipes[i+1]\n\n val d = b.x - a.x\n cols.add(Collision(i, RL, d, a.v + b.v))\n if(a.v > b.v) cols.add(Collision(i, RR, d, a.v - b.v))\n else if(a.v < b.v) cols.add(Collision(i, LL, d, b.v - a.v))\n }\n\n cols.sortWith(Collision.comparator)\n\n val vi = ModIntArray(cols.size) { ModInt(cols[it].v) }.inverseOfEach()\n var currProb = ModInt(1)\n var ans = ModInt(0)\n for(i in cols.indices) {\n val (a, t, d) = cols[i]\n tree[a] = tree[a]!!.copy(ban = t)\n val prob = tree.root!!.sum\n ans += (currProb - prob) * d * vi[i]\n currProb = prob\n }\n\n println(ans.int)\n}\n\ndata class Pipe(val x: Int, val v: Int, val p: ModInt)\ndata class Collision(val a: Int, val type: CollisionType, val d: Int, val v: Int) {\n companion object {\n val comparator = Comparator { a, b ->\n (a.d.toLong() * b.v).compareTo(b.d.toLong() * a.v)\n }\n }\n}\n\ntypealias CollisionType = Byte\nconst val NONE: CollisionType = 0\nconst val LL: CollisionType = 1\nconst val RL: CollisionType = 2\nconst val RR: CollisionType = 3\n\ndata class Seg(val ll: ModInt, val lr: ModInt, val rl: ModInt, val rr: ModInt, val ban: CollisionType) {\n val sum get() = ll + lr + rl + rr\n\n operator fun plus(b: Seg): Seg {\n // LR never banned\n var cll = ll * b.rl\n var clr = ll * b.rr\n var crl = rl * b.rl\n var crr = rl * b.rr\n\n // any ban implies RL banned\n if(ban == NONE) {\n cll += lr * b.ll\n clr += lr * b.lr\n crl += rr * b.ll\n crr += rr * b.lr\n }\n\n if(ban != LL) {\n cll += ll * b.ll\n clr += ll * b.lr\n crl += rl * b.ll\n crr += rl * b.lr\n }\n\n if(ban != RR) {\n cll += lr * b.rl\n clr += lr * b.rr\n crl += rr * b.rl\n crr += rr * b.rr\n }\n\n return Seg(cll, clr, crl, crr, b.ban)\n }\n}\n\nclass SegmentTree(\n val size: Int,\n val identityValue: T,\n val combiner: (T, T) -> T) {\n\n private val tsize get() = if(size <= 1) size else Integer.highestOneBit(size - 1) shl 1\n\n /* degenericization helpers\n val identityValue: T = TODO()\n fun combiner(a: T, b: T): T = TODO()\n */\n\n @Suppress(\"UNCHECKED_CAST\")\n private val array = Array(tsize shl 1) { identityValue } as Array\n\n val root get() = array[1]\n\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n val asList: List by lazy {\n object : AbstractList() {\n override val size: Int get() = this@SegmentTree.size\n override fun get(index: Int): T = this@SegmentTree[index]\n }\n }\n\n fun build(generator: (Int) -> T) {\n for(i in 0 until size) {\n array[i + tsize] = generator(i)\n }\n for(i in tsize-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** instantiates values from an iterable, O(n) time */\n fun copyFrom(iterable: Iterable) {\n run {\n iterable.forEachIndexed { i, t ->\n if(i > lastIndex) return@run\n array[i + tsize] = t\n }\n }\n for(i in tsize-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Updates a value, O(log n) time */\n operator fun set(index: Int, value: T) {\n require(index in 0 until size)\n var i = index + tsize\n array[i] = value\n while(true) {\n i = i shr 1\n if(i <= 0) break\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Gets a value by its index, O(1) time */\n operator fun get(index: Int): T {\n require(index in 0 until size)\n return array[index + tsize]\n }\n\n /** gets the result of applying the monoid operation to the values in the index range, O(log n) time */\n operator fun get(start: Int, endExclusive: Int): T {\n var l = maxOf(start, 0) + tsize\n var r = minOf(endExclusive, size) + tsize\n\n // two accumulators to support non-commutative monoids\n var lAcc = identityValue\n var rAcc = identityValue\n\n while(l < r) {\n if(l and 1 == 1) {\n lAcc = combiner(lAcc, array[l++])\n }\n if(r and 1 == 1) {\n rAcc = combiner(array[--r], rAcc)\n }\n\n l = l shr 1\n r = r shr 1\n }\n\n return combiner(lAcc, rAcc)\n }\n\n operator fun get(range: IntRange) = get(range.first, range.last + 1)\n}\n\n/** Converts a semigroup to a monoid by using null as the identity value. */\ninline fun nullIdentityCombiner(crossinline combiner: (T, T) -> T): (T?, T?) -> T? = { a, b ->\n when {\n b == null -> a\n a == null -> b\n else -> combiner(a, b)\n }\n}\n\nfun ModIntArray.inverseOfEach(): ModIntArray {\n if(isEmpty()) return this\n var acc = ModInt(1)\n val res = ModIntArray(size) { i ->\n acc *= this[i]\n acc\n }\n acc = acc.inv_unmemoized()\n for(i in lastIndex downTo 1) {\n res[i] = acc * res[i-1]\n acc *= this[i]\n }\n res[0] = acc\n\n return res\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\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/** 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 = Random(0x594E215C123 * System.nanoTime())\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}", "lang_cluster": "Kotlin", "tags": ["math", "probabilities", "data structures"], "code_uid": "3328fadeaa3003fa66de4eaaae2bab7d", "src_uid": "37bb4fe5f6cc2a173e97c033c6fde8c7", "difficulty": 3100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.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 percent = ModInt(100).inverse()\n\n val n = readInt()\n val pipes = List(n) { Pipe(readInt(), readInt(), percent * readInt()) }\n val tree = SegmentTree(n, null, nullIdentityCombiner(Seg::plus))\n\n tree.build { i ->\n Seg(\n ll = 1 - pipes[i].p,\n lr = ModInt(0),\n rl = ModInt(0),\n rr = pipes[i].p,\n ban = NONE\n )\n }\n\n val cols = ArrayList(n-1 shl 1)\n\n for(i in 0 until n-1) {\n val a = pipes[i]\n val b = pipes[i+1]\n\n val d = b.x - a.x\n cols.add(Collision(i, RL, d, a.v + b.v))\n if(a.v > b.v) cols.add(Collision(i, RR, d, a.v - b.v))\n else if(a.v < b.v) cols.add(Collision(i, LL, d, b.v - a.v))\n }\n\n cols.sortWith(Collision.comparator)\n\n val vi = ModIntArray(cols.size) { ModInt(cols[it].v) }.inverseOfEach()\n var currProb = ModInt(1)\n var ans = ModInt(0)\n for(i in cols.indices) {\n val (a, t, d) = cols[i]\n tree[a] = tree[a]!!.copy(ban = t)\n val prob = tree.root!!.sum\n ans += (currProb - prob) * d * vi[i]\n currProb = prob\n }\n\n println(ans.int)\n}\n\ndata class Pipe(val x: Int, val v: Int, val p: ModInt)\ndata class Collision(val a: Int, val type: CollisionType, val d: Int, val v: Int) {\n companion object {\n val comparator = Comparator { a, b ->\n (a.d.toLong() * b.v).compareTo(b.d.toLong() * a.v)\n }\n }\n}\n\ntypealias CollisionType = Byte\nconst val NONE: CollisionType = 0\nconst val LL: CollisionType = 1\nconst val RL: CollisionType = 2\nconst val RR: CollisionType = 3\n\ndata class Seg(val ll: ModInt, val lr: ModInt, val rl: ModInt, val rr: ModInt, val ban: CollisionType) {\n val sum get() = ll + lr + rl + rr\n\n operator fun plus(b: Seg): Seg {\n // LR never banned\n var cll = ll * b.rl\n var clr = ll * b.rr\n var crl = rl * b.rl\n var crr = rl * b.rr\n\n // any ban implies RL banned\n if(ban == NONE) {\n cll += lr * b.ll\n clr += lr * b.lr\n crl += rr * b.ll\n crr += rr * b.lr\n }\n\n if(ban != LL) {\n cll += ll * b.ll\n clr += ll * b.lr\n crl += rl * b.ll\n crr += rl * b.lr\n }\n\n if(ban != RR) {\n cll += lr * b.rl\n clr += lr * b.rr\n crl += rr * b.rl\n crr += rr * b.rr\n }\n\n return Seg(cll, clr, crl, crr, b.ban)\n }\n}\n\nclass SegmentTree(\n val size: Int,\n val identityValue: T,\n val combiner: (T, T) -> T) {\n\n private val tsize get() = if(size <= 1) size else Integer.highestOneBit(size - 1) shl 1\n\n /* degenericization helpers\n val identityValue: T = TODO()\n fun combiner(a: T, b: T): T = TODO()\n */\n\n @Suppress(\"UNCHECKED_CAST\")\n private val array = Array(tsize shl 1) { identityValue } as Array\n\n val root get() = array[1]\n\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n val asList: List by lazy {\n object : AbstractList() {\n override val size: Int get() = this@SegmentTree.size\n override fun get(index: Int): T = this@SegmentTree[index]\n }\n }\n\n fun build(generator: (Int) -> T) {\n for(i in 0 until size) {\n array[i + tsize] = generator(i)\n }\n for(i in tsize-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** instantiates values from an iterable, O(n) time */\n fun copyFrom(iterable: Iterable) {\n run {\n iterable.forEachIndexed { i, t ->\n if(i > lastIndex) return@run\n array[i + tsize] = t\n }\n }\n for(i in tsize-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Updates a value, O(log n) time */\n operator fun set(index: Int, value: T) {\n require(index in 0 until size)\n var i = index + tsize\n array[i] = value\n while(true) {\n i = i shr 1\n if(i <= 0) break\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Gets a value by its index, O(1) time */\n operator fun get(index: Int): T {\n require(index in 0 until size)\n return array[index + tsize]\n }\n\n /** gets the result of applying the monoid operation to the values in the index range, O(log n) time */\n operator fun get(start: Int, endExclusive: Int): T {\n var l = maxOf(start, 0) + tsize\n var r = minOf(endExclusive, size) + tsize\n\n // two accumulators to support non-commutative monoids\n var lAcc = identityValue\n var rAcc = identityValue\n\n while(l < r) {\n if(l and 1 == 1) {\n lAcc = combiner(lAcc, array[l++])\n }\n if(r and 1 == 1) {\n rAcc = combiner(array[--r], rAcc)\n }\n\n l = l shr 1\n r = r shr 1\n }\n\n return combiner(lAcc, rAcc)\n }\n\n operator fun get(range: IntRange) = get(range.first, range.last + 1)\n}\n\n/** Converts a semigroup to a monoid by using null as the identity value. */\ninline fun nullIdentityCombiner(crossinline combiner: (T, T) -> T): (T?, T?) -> T? = { a, b ->\n when {\n a == null -> b\n b == null -> a\n else -> combiner(a, b)\n }\n}\n\nfun ModIntArray.inverseOfEach(): ModIntArray {\n if(isEmpty()) return this\n var acc = ModInt(1)\n val res = ModIntArray(size) { i ->\n acc *= this[i]\n acc\n }\n acc = res[lastIndex].inv_unmemoized()\n for(i in lastIndex downTo 1) {\n res[i] = acc * res[i-1]\n acc *= this[i]\n }\n res[0] = acc\n\n return res\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\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/** 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 = Random(0x594E215C123 * System.nanoTime())\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}", "lang_cluster": "Kotlin", "tags": ["math", "probabilities", "data structures"], "code_uid": "b74efa0a2cdf12239bac3a6d1bd3caf6", "src_uid": "37bb4fe5f6cc2a173e97c033c6fde8c7", "difficulty": 3100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.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 percent = ModInt(100).inverse()\n\n val n = readInt()\n val pipes = List(n) { Pipe(readInt(), readInt(), percent * readInt()) }\n val tree = SegmentTree(n, null, nullIdentityCombiner(Seg::plus))\n\n tree.build { i ->\n Seg(\n ll = 1 - pipes[i].p,\n lr = ModInt(0),\n rl = ModInt(0),\n rr = pipes[i].p,\n ban = NONE\n )\n }\n\n val cols = ArrayList(n-1 shl 1)\n\n for(i in 0 until n-1) {\n val a = pipes[i]\n val b = pipes[i+1]\n\n val d = b.x - a.x\n cols.add(Collision(i, RL, d, a.v + b.v))\n if(a.v > b.v) cols.add(Collision(i, RR, d, a.v - b.v))\n else if(a.v < b.v) cols.add(Collision(i, LL, d, b.v - a.v))\n }\n\n cols.sortWith(Collision.comparator)\n\n val vi = ModIntArray(cols.size) { ModInt(cols[it].v) }.inverseOfEach()\n var currProb = ModInt(1)\n var ans = ModInt(0)\n for(i in cols.indices) {\n val (a, t, d) = cols[i]\n tree[a] = tree[a]!!.copy(ban = t)\n val prob = tree.root!!.sum\n ans += (currProb - prob) * d * vi[i]\n currProb = prob\n }\n\n println(ans.int)\n}\n\ndata class Pipe(val x: Int, val v: Int, val p: ModInt)\ndata class Collision(val a: Int, val type: CollisionType, val d: Int, val v: Int) {\n companion object {\n val comparator = Comparator { a, b ->\n (a.d.toLong() * b.v).compareTo(b.d.toLong() * a.v)\n }\n }\n}\n\ntypealias CollisionType = Byte\nconst val NONE: CollisionType = 0\nconst val LL: CollisionType = 1\nconst val RL: CollisionType = 2\nconst val RR: CollisionType = 3\n\ndata class Seg(val ll: ModInt, val lr: ModInt, val rl: ModInt, val rr: ModInt, val ban: CollisionType) {\n val sum get() = ll + lr + rl + rr\n\n operator fun plus(b: Seg): Seg {\n // LR never banned\n var cll = ll * b.rl\n var clr = ll * b.rr\n var crl = rl * b.rl\n var crr = rl * b.rr\n\n // any ban implies RL banned\n if(ban == NONE) {\n cll += lr * b.ll\n clr += lr * b.lr\n crl += rr * b.ll\n crr += rr * b.lr\n }\n\n if(ban != LL) {\n cll += ll * b.ll\n clr += ll * b.lr\n crl += rl * b.ll\n crr += rl * b.lr\n }\n\n if(ban != RR) {\n cll += lr * b.rl\n clr += lr * b.rr\n crl += rr * b.rl\n crr += rr * b.rr\n }\n\n return Seg(cll, clr, crl, crr, b.ban)\n }\n}\n\nclass SegmentTree(\n val size: Int,\n val identityValue: T,\n val combiner: (T, T) -> T) {\n\n private val tsize get() = if(size <= 1) size else Integer.highestOneBit(size - 1) shl 1\n\n /* degenericization helpers\n val identityValue: T = TODO()\n fun combiner(a: T, b: T): T = TODO()\n */\n\n @Suppress(\"UNCHECKED_CAST\")\n private val array = Array(tsize shl 1) { identityValue } as Array\n\n val root get() = array[1]\n\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n val asList: List by lazy {\n object : AbstractList() {\n override val size: Int get() = this@SegmentTree.size\n override fun get(index: Int): T = this@SegmentTree[index]\n }\n }\n\n fun build(generator: (Int) -> T) {\n for(i in 0 until size) {\n array[i + tsize] = generator(i)\n }\n for(i in tsize-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** instantiates values from an iterable, O(n) time */\n fun copyFrom(iterable: Iterable) {\n run {\n iterable.forEachIndexed { i, t ->\n if(i > lastIndex) return@run\n array[i + tsize] = t\n }\n }\n for(i in tsize-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Updates a value, O(log n) time */\n operator fun set(index: Int, value: T) {\n require(index in 0 until size)\n var i = index + tsize\n array[i] = value\n while(true) {\n i = i shr 1\n if(i <= 0) break\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Gets a value by its index, O(1) time */\n operator fun get(index: Int): T {\n require(index in 0 until size)\n return array[index + tsize]\n }\n\n /** gets the result of applying the monoid operation to the values in the index range, O(log n) time */\n operator fun get(start: Int, endExclusive: Int): T {\n var l = maxOf(start, 0) + tsize\n var r = minOf(endExclusive, size) + tsize\n\n // two accumulators to support non-commutative monoids\n var lAcc = identityValue\n var rAcc = identityValue\n\n while(l < r) {\n if(l and 1 == 1) {\n lAcc = combiner(lAcc, array[l++])\n }\n if(r and 1 == 1) {\n rAcc = combiner(array[--r], rAcc)\n }\n\n l = l shr 1\n r = r shr 1\n }\n\n return combiner(lAcc, rAcc)\n }\n\n operator fun get(range: IntRange) = get(range.first, range.last + 1)\n}\n\n/** Converts a semigroup to a monoid by using null as the identity value. */\ninline fun nullIdentityCombiner(crossinline combiner: (T, T) -> T): (T?, T?) -> T? = { a, b ->\n when {\n a == null -> b\n b == null -> a\n else -> combiner(a, b)\n }\n}\n\nfun ModIntArray.inverseOfEach(): ModIntArray {\n if(isEmpty()) return this\n var acc = ModInt(1)\n val res = ModIntArray(size) { i ->\n acc *= this[i]\n acc\n }\n acc = acc.inv_unmemoized()\n for(i in lastIndex downTo 1) {\n res[i] = acc * res[i-1]\n acc *= this[i]\n }\n res[0] = acc\n\n return res\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\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/** 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 = Random(0x594E215C123 * System.nanoTime())\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}", "lang_cluster": "Kotlin", "tags": ["math", "probabilities", "data structures"], "code_uid": "ccbfab5949ce3b2f5dd33982e2a482bf", "src_uid": "37bb4fe5f6cc2a173e97c033c6fde8c7", "difficulty": 3100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.lang.StringBuilder\nimport java.util.PriorityQueue\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\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n val percent = ModInt(100).inverse()\n\n val n = readInt()\n val pipes = List(n) { Pipe(readInt(), readInt(), percent * readInt()) }\n val tree = SegmentTree(n, null, nullIdentityCombiner(Seg::plus))\n\n tree.build { i ->\n Seg(\n ll = pipes[i].p.not(),\n lr = ModInt(0),\n rl = ModInt(0),\n rr = pipes[i].p,\n ban = NONE\n )\n }\n\n val cols = ArrayList(2*n)\n\n for(i in 0 until n-1) {\n val a = pipes[i]\n val b = pipes[i+1]\n\n val d = b.x - a.x\n cols.add(Collision(i, RL, d, a.v + b.v))\n if(a.v > b.v) cols.add(Collision(i, RR, d, a.v - b.v))\n else if(a.v < b.v) cols.add(Collision(i, LL, d, b.v - a.v))\n }\n\n cols.sortWith(Collision.comparator)\n\n var currProb = ModInt(1)\n var ans = ModInt(0)\n for((a, t, d, v) in cols) {\n tree[a] = tree[a]!!.copy(ban = t)\n val prob = tree.root!!.sum\n ans += (currProb - prob) * d / v\n currProb = prob\n }\n\n println(ans.int)\n}\n\ninline fun ModInt.not() = ModInt(1) - this\n\ndata class Pipe(val x: Int, val v: Int, val p: ModInt)\ndata class Collision(val a: Int, val type: CollisionType, val d: Int, val v: Int) {\n companion object {\n val comparator = Comparator { a, b ->\n (a.d.toLong() * b.v).compareTo(b.d.toLong() * a.v)\n }\n }\n\n inline val b get() = a + 1\n}\n\ninline class CollisionType(val i: Int)\ninline val NONE get() = CollisionType(0)\ninline val LL get() = CollisionType(1)\ninline val RL get() = CollisionType(2)\ninline val RR get() = CollisionType(3)\n\ndata class Seg(val ll: ModInt, val lr: ModInt, val rl: ModInt, val rr: ModInt, val ban: CollisionType) {\n val sum get() = ll + lr + rl + rr\n\n operator fun plus(b: Seg): Seg {\n // LR never banned\n var cll = ll * b.rl\n var clr = ll * b.rr\n var crl = rl * b.rl\n var crr = rl * b.rr\n\n // any ban implies RL banned\n if(ban.i == NONE.i) {\n cll += lr * b.ll\n clr += lr * b.lr\n crl += rr * b.ll\n crr += rr * b.lr\n }\n\n if(ban.i != LL.i) {\n cll += ll * b.ll\n clr += ll * b.lr\n crl += rl * b.ll\n crr += rl * b.lr\n }\n\n if(ban.i != RR.i) {\n cll += lr * b.rl\n clr += lr * b.rr\n crl += rr * b.rl\n crr += rr * b.rr\n }\n\n return Seg(cll, clr, crl, crr, b.ban)\n }\n}\n\nclass SegmentTree(\n val size: Int,\n val identityValue: T,\n val combiner: (T, T) -> T) {\n\n private val tsize get() = if(size <= 1) size else Integer.highestOneBit(size - 1) shl 1\n\n /* degenericization helpers\n val identityValue: T = TODO()\n fun combiner(a: T, b: T): T = TODO()\n */\n\n @Suppress(\"UNCHECKED_CAST\")\n private val array = Array(2 * tsize) { identityValue } as Array\n\n val root get() = array[1]\n\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n val asList: List by lazy {\n object : AbstractList() {\n override val size: Int get() = this@SegmentTree.size\n override fun get(index: Int): T = this@SegmentTree[index]\n }\n }\n\n fun build(generator: (Int) -> T) {\n for(i in 0 until size) {\n array[i + tsize] = generator(i)\n }\n for(i in tsize-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** instantiates values from an iterable, O(n) time */\n fun copyFrom(iterable: Iterable) {\n run {\n iterable.forEachIndexed { i, t ->\n if(i > lastIndex) return@run\n array[i + tsize] = t\n }\n }\n for(i in tsize-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Updates a value, O(log n) time */\n operator fun set(index: Int, value: T) {\n require(index in 0 until size)\n var i = index + tsize\n array[i] = value\n while(true) {\n i = i shr 1\n if(i <= 0) break\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Gets a value by its index, O(1) time */\n operator fun get(index: Int): T {\n require(index in 0 until size)\n return array[index + tsize]\n }\n\n /** gets the result of applying the monoid operation to the values in the index range, O(log n) time */\n operator fun get(start: Int, endExclusive: Int): T {\n var l = maxOf(start, 0) + tsize\n var r = minOf(endExclusive, size) + tsize\n\n // two accumulators to support non-commutative monoids\n var lAcc = identityValue\n var rAcc = identityValue\n\n while(l < r) {\n if(l and 1 == 1) {\n lAcc = combiner(lAcc, array[l++])\n }\n if(r and 1 == 1) {\n rAcc = combiner(array[--r], rAcc)\n }\n\n l = l shr 1\n r = r shr 1\n }\n\n return combiner(lAcc, rAcc)\n }\n\n operator fun get(range: IntRange) = get(range.first, range.last + 1)\n}\n\n/** Converts a semigroup to a monoid by using null as the identity value. */\ninline fun nullIdentityCombiner(crossinline combiner: (T, T) -> T): (T?, T?) -> T? = { a, b ->\n when {\n a == null -> b\n b == null -> a\n else -> combiner(a, b)\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\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/** 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()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "probabilities", "data structures"], "code_uid": "5034deee26cbd12d5d42a1bc9e1a2309", "src_uid": "37bb4fe5f6cc2a173e97c033c6fde8c7", "difficulty": 3100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val numVertices = readLine()!!.toLong()\n print(1 + 3 * (numVertices - 3) + (numVertices - 3) * (numVertices - 4))\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "d03c778aa03dc28c2f3b6c4e8e6ef177", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val numVertices = readLine()!!.toLong()\n print(4 * (numVertices - 3) + (numVertices - 4) * (numVertices - 4))\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "b4bdf1413efa81f1d30e946fef5a50d2", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.lang.Math.abs\nimport java.util.*\n\nfun solve(cin: FastReader, out: PrintWriter) {\n val n = cin.int()\n val m = cin.int()\n var cnt: Long = 0\n for (i in 1..m)\n for (j in 1..m)\n if ((i * i + j * j.toLong()) % m == 0L)\n cnt += ((n - i + 1 + m - 1) / m).toLong() * ((n - j + 1 + m - 1) / m).toLong()\n\n out.print(cnt)\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 solve(cin, out)\n out.flush()\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "d76423477181a0f5497c4fb03802b591", "src_uid": "2ec9e7cddc634d7830575e14363a4657", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, m) = readLine()!!.split(\" \").map { it.toInt() }\n var ans = 0L\n for (i in 0 until m) {\n for (j in 0 until m) {\n if ((i * i + j * j) % m == 0) {\n val x = when {\n i == 0 -> n / m\n n >= i -> ((n - i) / m) + 1\n else -> 0\n }\n val y = when {\n j == 0 -> n / m\n n >= j -> ((n - j) / m) + 1\n else -> 0\n }\n ans += x.toLong() * y\n }\n }\n }\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "fa85e9fc98977ffd2a794c927c8c3140", "src_uid": "2ec9e7cddc634d7830575e14363a4657", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.lang.Math.abs\nimport java.util.*\n\nfun solve(cin: FastReader, out: PrintWriter) {\n val n = cin.int()\n val m = cin.int()\n var cnt = 0\n var part = 0\n for (i in 1..m)\n for (j in 1..m)\n if ((i * i.toLong() + j * j.toLong()) % m == 0.toLong())\n cnt++\n for (i in 1..(n % m))\n for (j in 1..(n % m))\n if ((i * i.toLong() + j * j.toLong()) % m == 0.toLong())\n part++\n var c = 0\n for (i in 1..m)\n for (j in 1..(n % m))\n if ((i * i.toLong() + j * j.toLong()) % m == 0.toLong())\n c++\n out.print((n / m).toLong() * (n / m).toLong() * cnt + part + (n / m).toLong() * 2 * c)\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 solve(cin, out)\n out.flush()\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "d6c07853d9121e398bbf60e8b9742dcd", "src_uid": "2ec9e7cddc634d7830575e14363a4657", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun pair(x: Int): Int {\n if (x >= 0) {\n return x xor 1\n } else {\n return x.inv() xor 2\n }\n}\n\nfun current(x: Int) = when {\n x >= 0 -> x\n else -> x.inv()\n}\n\nfun opposite(x: Int) = pair(x.inv())\n\nfun oppositePair(x: Int) = current(x) xor 3\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val opposite = arrayOf(arrayOf(0, 8), arrayOf(4, 20), arrayOf(12, 16))\n val other = arrayOf(arrayOf(4, 16, 20, 12), arrayOf(8, 16.inv(), 2, 13.inv()),\n arrayOf(0.inv(), 4.inv(), 8.inv(), 21.inv()))\n val a = IntArray(24) { nextInt() }\n loop@ for (op in opposite.indices) {\n for (i in opposite[op]) {\n for (j in 0..3) {\n if (a[i + j] != a[i]) {\n continue@loop\n }\n }\n }\n val x = other[op]\n for (i in 0..3) {\n if (a[current(x[i])] != a[pair(x[i])]) {\n continue@loop\n }\n if (a[opposite(x[i])] != a[oppositePair(x[i])]) {\n continue@loop\n }\n }\n if ((-1..1 step 2).any { delta ->\n !(0..3).any { a[current(x[it])] != a[opposite(x[(it + delta) and 3])] }\n }) {\n println(\"YES\")\n return\n }\n }\n println(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "7fb3b1c5fec5b45caebe7f242d508684", "src_uid": "881a820aa8184d9553278a0002a3b7c4", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.util.*\n\nval a = Array(25) {_ -> 0}\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n\n for (i in 1 until 25) {\n a[i] = sc.nextInt()\n }\n if ((same(intArrayOf(13,14,15,16)) && same(intArrayOf(17,18,19,20)) && same(intArrayOf(1,3,6,8))\n && same(intArrayOf(5,7,10,12)) && same(intArrayOf(9,11,21,23)) && same(intArrayOf(2,4,22,24))) ||\n (same(intArrayOf(13,14,15,16)) && same(intArrayOf(17,18,19,20)) && same(intArrayOf(9,11,6,8))\n && same(intArrayOf(5,7,2,4)) && same(intArrayOf(1,3,21,23)) && same(intArrayOf(10,12,22,24))) ||\n (same(intArrayOf(1,2,3,4)) && same(intArrayOf(9,10,11,12)) && same(intArrayOf(13,14,7,8))\n && same(intArrayOf(5,6,19,20)) && same(intArrayOf(17,18,23,24)) && same(intArrayOf(21,22,15,16))) ||\n (same(intArrayOf(1,2,3,4)) && same(intArrayOf(9,10,11,12)) && same(intArrayOf(5,6,15,16))\n && same(intArrayOf(17,18,7,8)) && same(intArrayOf(21,22,19,20)) && same(intArrayOf(13,14,23,24))) ||\n (same(intArrayOf(5,6,7,8)) && same(intArrayOf(21,22,23,24)) && same(intArrayOf(1,2,14,16))\n && same(intArrayOf(13,15,9,10)) && same(intArrayOf(11,12,17,19)) && same(intArrayOf(3,4,18,20))) ||\n (same(intArrayOf(5,6,7,8)) && same(intArrayOf(21,22,23,24)) && same(intArrayOf(1,2,17,19))\n && same(intArrayOf(9,10,18,20)) && same(intArrayOf(11,12,14,16)) && same(intArrayOf(13,15,3,4)))\n ){\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}\n\nfun same(pos: IntArray): Boolean {\n return a[pos[0]] == a[pos[1]] && a[pos[1]] == a[pos[2]] && a[pos[2]] == a[pos[3]]\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "3d7c9dc2b53da0ab5986aa9a3a3310e0", "src_uid": "881a820aa8184d9553278a0002a3b7c4", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nclass C internal constructor(inputStream: InputStream, val out: PrintWriter) {\n companion object {\n val ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n }\n\n\n private val br = BufferedReader(InputStreamReader(inputStream))\n private var st = StringTokenizer(\"\")\n\n internal fun hasNext(): Boolean {\n while (!st.hasMoreTokens()) {\n val readLine = br.readLine() ?: return false\n st = StringTokenizer(readLine)\n }\n return true\n }\n\n private operator fun next() =\n if (hasNext()) st.nextToken()!!\n else throw RuntimeException(\"No tokens\")\n\n internal fun nextLine() =\n if (hasNext()) st.nextToken(\"\\n\")\n else throw RuntimeException(\"No tokens\")\n\n private fun nextInt() = next().toInt()\n private fun nextIntArray(n: Int) = IntArray(n, { nextInt() })\n private fun nextIntArray(m: Int, n: Int) = Array(m, { nextIntArray(n) })\n\n private fun nextLong() = next().toLong()\n private fun nextLongArray(n: Int) = LongArray(n, { nextLong() })\n private fun nextLongArray(m: Int, n: Int) = Array(m, { nextLongArray(n) })\n\n private fun nextDouble() = next().toDouble()\n private fun nextDoubleArray(n: Int) = DoubleArray(n, { nextDouble() })\n private fun nextDoubleArray(m: Int, n: Int) = Array(m, { nextDoubleArray(n) })\n\n\n fun log() {\n if (!ONLINE_JUDGE) {\n println()\n }\n }\n\n inline fun log(arr: IntArray?, name: String = \"\") {\n if (!ONLINE_JUDGE) {\n print(\"#$name: \")\n println(arr)\n }\n }\n\n inline fun log(arr: DoubleArray?, name: String = \"\") {\n if (!ONLINE_JUDGE) {\n print(\"#$name: \")\n println(arr)\n }\n }\n\n inline fun log(arr: Array?, name: String = \"\") {\n if (!ONLINE_JUDGE) {\n print(\"#$name: \")\n println(arr)\n }\n }\n\n inline fun log(stack: Stack?, name: String = \"\") {\n if (!ONLINE_JUDGE) {\n print(\"#$name: \")\n println(stack)\n }\n }\n\n inline fun log(list: List?, name: String = \"\") {\n if (!ONLINE_JUDGE) {\n print(\"#$name: \")\n println(list)\n }\n }\n\n inline fun log(message: Any?, name: String = \"\") {\n if (!ONLINE_JUDGE) {\n print(\"#$name: \")\n println(message)\n }\n }\n\n inline fun print(message: Any?) = out.print(message)\n\n inline fun print(arr: IntArray?, separator: String = \" \") {\n var prefix = false\n arr?.forEach {\n if (prefix) {\n print(separator)\n }\n prefix = true\n print(it)\n }\n }\n\n inline fun print(arr: DoubleArray?, separator: String = \" \") {\n var prefix = false\n arr?.forEach {\n if (prefix) {\n print(separator)\n }\n prefix = true\n print(it)\n }\n }\n\n inline fun print(arr: Array?, separator: String = \" \") {\n var prefix = false\n arr?.forEach {\n if (prefix) {\n print(separator)\n }\n prefix = true\n print(it)\n }\n }\n\n inline fun print(list: List?, separator: String = \" \") {\n var prefix = false\n list?.forEach {\n if (prefix) {\n print(separator)\n }\n prefix = true\n print(it)\n }\n }\n\n inline fun print(stack: Stack?, separator: String = \" \") {\n var prefix = false\n if (stack != null) {\n while (stack.isNotEmpty()) {\n if (prefix) {\n print(separator)\n }\n prefix = true\n print(stack.pop())\n }\n }\n }\n\n\n inline fun println() = out.println()\n\n inline fun println(message: Any?) = out.println(message)\n\n inline fun println(arr: IntArray?, separator: String = \" \") {\n print(arr, separator)\n println()\n }\n\n inline fun println(arr: DoubleArray?, separator: String = \" \") {\n print(arr, separator)\n println()\n }\n\n inline fun println(list: List?, separator: String = \" \") {\n print(list, separator)\n println()\n }\n\n inline fun println(arr: Array?, separator: String = \" \") {\n print(arr, separator)\n println()\n }\n\n inline fun println(stack: Stack?, separator: String = \" \") {\n print(stack, separator)\n println()\n }\n\n\n val oppsite = arrayOf(2, 5, 0, 4, 3, 1)\n val next = arrayOf(arrayOf(3, 1, 4, 5),\n arrayOf(2, 4, 0, 3),\n arrayOf(3, 1, 4, 5),\n arrayOf(0, 1, 2, 5),\n arrayOf(0, 1, 2, 5),\n arrayOf(2, 4, 0, 3))\n val match = arrayOf(arrayOf(arrayOf(1, 2, 3, 4, 3, 4),\n arrayOf(1, 2, 3, 4, 3, 4),\n arrayOf(1, 2, 3, 4, 3, 4),\n arrayOf(1, 2, 3, 4, 3, 4)),\n arrayOf(arrayOf(1, 2, 2, 4, 1, 3),\n arrayOf(1, 3, 1, 2, 3, 4),\n arrayOf(3, 4, 1, 3, 2, 4),\n arrayOf(2, 4, 3, 4, 1, 2)),\n arrayOf(arrayOf(3, 4, 1, 2, 1, 2),\n arrayOf(3, 4, 1, 2, 1, 2),\n arrayOf(3, 4, 1, 2, 1, 2),\n arrayOf(3, 4, 1, 2, 1, 2)),\n arrayOf(arrayOf(1, 3, 2, 4, 1, 3),//0\n arrayOf(1, 3, 2, 4, 2, 4),//1\n arrayOf(1, 3, 1, 3, 2, 4),//2\n arrayOf(2, 4, 2, 4, 2, 4)),//5\n arrayOf(arrayOf(2, 4, 1, 3, 1, 3),\n arrayOf(2, 4, 1, 3, 1, 3),\n arrayOf(2, 4, 1, 3, 2, 4),\n arrayOf(1, 3, 1, 3, 1, 3)),\n arrayOf(arrayOf(3, 4, 1, 3, 2, 4),\n arrayOf(2, 4, 3, 4, 1, 2),\n arrayOf(1, 2, 2, 4, 1, 3),\n arrayOf(1, 3, 1, 2, 3, 4)))\n\n fun run() {\n\n val a = nextIntArray(6, 4)\n\n log(a.contentDeepToString())\n\n arrayOf(0, 1, 3).forEach {\n if (checkRotate(it, a)) {\n println(\"YES\")\n return\n }\n }\n println(\"NO\")\n }\n\n private fun checkRotate(upperIdx: Int, a: Array): Boolean {\n val upper = a[upperIdx]\n val bottom = a[oppsite[upperIdx]]\n\n if (!upper.isUnique() && !bottom.isUnique())\n return false\n\n var left = true\n var right = true\n repeat(4) {\n val face1 = a[next[upperIdx][it]]\n val face2 = a[next[upperIdx][(it + 1) % 4]]\n val face3 = a[next[upperIdx][(it + 3) % 4]]\n\n val m = match[upperIdx][it]\n if (face1[m[0] - 1] != face1[m[1] - 1])\n return false\n if (face2[m[2] - 1] != face2[m[3] - 1])\n left = false\n if (face3[m[4] - 1] != face3[m[5] - 1])\n right = false\n\n if (face1[m[0] - 1] != face2[m[3] - 1])\n left = false\n\n if (face1[m[0] - 1] != face3[m[4] - 1])\n right = false\n\n }\n return left || right\n }\n\n\n}\n\nprivate fun IntArray.isUnique() = !this.any { it != this[0] }\n\nfun main(args: Array) {\n if (C.ONLINE_JUDGE) {\n val a = C(System.`in`, PrintWriter(BufferedOutputStream(System.out)))\n a.run()\n a.out.flush()\n a.out.close()\n } else {\n val t = C(FileInputStream(\"C.txt\"), PrintWriter(BufferedOutputStream(System.out)))\n while (t.hasNext()) {\n val name = t.nextLine()\n t.log(\"##### Test $name #####\")\n val startTime = System.currentTimeMillis()\n t.run()\n val endTime = System.currentTimeMillis()\n t.log(endTime - startTime, \"Total Time\")\n t.log()\n t.out.flush()\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "1cba625ef95524cdf913ba42f0c24a86", "src_uid": "881a820aa8184d9553278a0002a3b7c4", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\n\nval sc = FastScanner(System.`in`)\nfun main(args: Array) {\n val cube = Cube()\n\n val rotations = listOf(\n listOf(13, 14, 5, 6, 17, 18, 21, 22),\n listOf(1, 3, 5, 7, 9, 11, 24, 22),\n listOf(3, 4, 17, 19, 10, 9, 16, 14)\n )\n\n\n\n for (rotation in rotations) {\n cube.rotate(rotation)\n\n if (cube.isSolved) {\n println(\"YES\")\n return\n }\n cube.rotate(rotation)\n cube.rotate(rotation)\n if (cube.isSolved) {\n println(\"YES\")\n return\n }\n cube.rotate(rotation)\n }\n\n println(\"NO\")\n\n}\n\nclass Cube {\n private val colors = Array(24) { sc.nextInt() }\n\n private val sides = arrayOf(\n arrayOf(1, 2, 3, 4),\n arrayOf(5, 6, 7, 8),\n arrayOf(13, 14, 15, 16),\n arrayOf(17, 18, 19, 20),\n arrayOf(21, 22, 23, 24),\n arrayOf(9, 10, 11, 12)\n )\n\n fun rotate(rotation: List) {\n val x = colors[rotation[0] - 1]\n val y = colors[rotation[1] - 1]\n for (i in 0..2) {\n\n colors[rotation[2 * i] - 1] = colors[rotation[2 * i + 2] - 1]\n colors[rotation[2 * i + 1] - 1] = colors[rotation[2 * i + 3] - 1]\n }\n\n colors[rotation[6] - 1] = x\n colors[rotation[7] - 1] = y\n }\n\n\n val isSolved: Boolean\n get() {\n for (side in sides) {\n if (side.map { colors[it - 1] }.distinct().size != 1) return false\n }\n return true\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", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "080e3230c4d38e28e3ca4c3397e70b58", "src_uid": "881a820aa8184d9553278a0002a3b7c4", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\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\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n var ans = readLn().replace(Regex(\"\"\"//+\"\"\"), \"/\")\n if(ans.length > 1) ans = ans.removeSuffix(\"/\")\n println(ans)\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()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "24e288c40f23824311c4b2d72e90303c", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 when {\n Math.log(a.toDouble())/a > Math.log(b.toDouble())/b -> System.out.println(\">\")\n Math.log(a.toDouble())/a < Math.log(b.toDouble())/b -> System.out.println(\"<\")\n else -> System.out.print(\"=\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "b6d9b54e83d5863a4ef62de08ddc0a02", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.collections.HashMap\nimport kotlin.collections.HashSet\nimport kotlin.math.max\nimport kotlin.math.min\n\nval scanner = Scanner(System.`in`)\n\nfun main(args: Array)\n = Thread { run() }.start()\n\nfun run() {\n val a = scanner.nextInt()\n val b = scanner.nextInt()\n if (a == b)\n println(\"=\")\n else if (a <= 1 || b <= 1) {\n if (max(a, b) == a)\n println(\">\")\n else\n println(\"<\")\n }\n else {\n val k = Math.pow(b.toDouble(), a.toDouble() / b)\n if (a.toDouble() == k)\n println(\"=\")\n else if (a > k)\n println(\">\")\n else\n println(\"<\")\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(val a: Int, val b: Int)\n//class Triple(val a: Int, val b: Int, val c: Int)", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "cbd2b530cf1b1da04736ca04538051c2", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.log10\n\nfun main(args: Array) {\n val (x, y) = readLine()!!.split(\" \").map { it.toInt() }\n print(when {\n y / log10(y.toDouble()) > x / log10(x.toDouble()) + 1e-9 -> \">\"\n y / log10(y.toDouble()) < x / log10(x.toDouble()) - 1e-9 -> \"<\"\n else -> \"=\"\n })\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "1a8f836550f2beebbfa4dc9b93aef755", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 x = scan.nextInt().toDouble()\n val y = scan.nextInt().toDouble()\n\n if(y* log(x, 10.0) < x*log(y, 10.0)) {\n println(\"<\")\n } else if(y* log(x, 10.0) > x*log(y, 10.0)) {\n println(\">\")\n } else {\n println(\"=\")\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "1b1ff06a0c92f192094ce5edbb23d4f3", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val people = sc.nextInt()\n val food = sc.nextInt()\n val typescnt = 101\n\n val types = IntArray(typescnt, {0})\n for (i in 1..food) {\n types[sc.nextInt()] += 1\n }\n\n val eating = IntArray(typescnt, {0})\n\n for (i in 1..people) {\n var maxk = -1\n var maxkj = -1\n for (j in 1 until typescnt) {\n if (types[j] == 0)\n continue\n val coef = types[j] / (eating[j] + 1)\n if (coef > maxk) {\n maxk = coef\n maxkj = j\n }\n }\n if (maxkj != -1) {\n eating[maxkj] += 1\n }\n }\n\n var mind = 1000000\n\n for (i in 1 until typescnt) {\n if (eating[i] != 0) {\n val v = types[i] / eating[i]\n if (v < mind)\n mind = v\n }\n }\n\n if (mind == 1000000) {\n println(\"0\")\n } else {\n println(mind)\n }\n\n val a = 2\n\n}\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "binary search"], "code_uid": "5a1ba223ddeab161437e0715d23e8898", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numParticipants, numFoods) = readInts()\n val types = readInts()\n val typeToAmount = mutableMapOf().withDefault { 0 }\n for (type in types) typeToAmount[type] = typeToAmount.getValue(type) + 1\n for (amountPerPerson in 1..numFoods) {\n val numFeedable =\n typeToAmount.entries.fold(0) { acc, mutableEntry -> acc + mutableEntry.value / amountPerPerson }\n if (numFeedable < numParticipants) return print(amountPerPerson - 1)\n }\n print(numFoods)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "binary search"], "code_uid": "4fa1b130ce9189a567c2caa96a57589e", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*;\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readDouble() = readLn().toDouble() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of ints\n\nfun main(args: Array) {\n solve()\n /*\n val t = readInt()\n repeat(t) {\n solve()\n }\n */\n}\n\nfun solve() {\n val (k, n) = readInts()\n val l = IntArray(101)\n for(x in readInts()) {\n l[x]++\n }\n var lhs = 0\n var rhs = 10000\n while(lhs != rhs) {\n val mid = (lhs + rhs + 1) / 2\n var can = 0\n for(x in l) {\n can += x / mid\n }\n if(can >= k) lhs = mid\n else rhs = mid - 1\n }\n println(lhs)\n}\n\n/*\nuseful things:\nto read in multiple ints in one line\nval (n, m, k) = readInts()\n\nJava: int[] dx = new int[]{-1,1,0,0}\nKotlin: val dx = arrayOf(-1, 1, 0, 0)\n*/", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "binary search"], "code_uid": "202204a19ec7a3510c602086d31b51f1", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "2a3bd980d496536dd3b984a7d99b2a72", "src_uid": "32c866d3d394e269724b4930df5e4407", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "3d1e3abb881a18d7cb9763c956d2f457", "src_uid": "32c866d3d394e269724b4930df5e4407", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "3a0d184748a8b30719a8fe53b760f2ab", "src_uid": "32c866d3d394e269724b4930df5e4407", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "b13623b8af7460e32a5ac166c9b70c0a", "src_uid": "32c866d3d394e269724b4930df5e4407", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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(4) { sc.nextInt() }\n\n for (k in 0..(1.shl(4))) {\n var s1 =0\n var s2 = 0\n for(i in 0..3){\n if( k and (1.shl(i)) == 0) s1 += a[i]\n else s2 +=a[i]\n }\n\n if(s1 == s2) {\n println(\"YES\")\n return\n }\n }\n\n println(\"NO\")\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", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "5d0c1627fa4f35043706d969d05017a3", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.min\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 = IntArray(4) {ir.nextInt()}\n\n for (i in 0..3)\n for (j in 0 until (3 - i))\n if (a[j] > a[j + 1]) {\n val n = a[j]\n a[j] = a[j + 1]\n a[j + 1] = n\n }\n\n if (a[3] == (a[0] + a[1] + a[2]) || (a[3] + a[0]) == (a[1] + a[2]))\n pw.print(\"YES\")\n else\n pw.print(\"NO\")\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "2b470889a2f163c794fc4c7c0d9b20b7", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 var a = readInts().sortedDescending()\n var total = a.sum()\n var flag = false\n loop@ for (i in 0..3) {\n var cur = 0\n for (j in i..3) {\n cur += a[j]\n if (cur == total - cur) {\n flag = true\n break@loop\n }\n }\n }\n print(if (flag) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "aea5b561aaf484baecb21930d4c89ea8", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val a = readLine()!!.split(\" \").map(String::toInt)\n val all = a.sum()\n a.forEachIndexed { index1, _ ->\n var sum = 0\n a.forEachIndexed {index2, value2 ->\n if (index1 != index2) sum += value2\n if (all - sum == sum) {\n println(\"YES\")\n return\n }\n }\n }\n println(\"NO\")\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "3d8ded14f39d8503ae764a93fe556361", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var n = readLine()!!.toInt()\n var words = readLine()!!\n var j = 1\n var i = 0\n while (i < n)\n {\n print(words[i])\n j++\n i += j\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "753c83576f665c812c186d7bec3ed1c3", "src_uid": "08e8c0c37b223f6aae01d5609facdeaf", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args:Array){\n val reader = Scanner(System.`in`)\n\n var n = reader.nextInt()\n var s = reader.next()\n var i = 0\n var a = 1\n\n while (i < n){\n print(s[i])\n i += a\n a++\n }\n println()\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9ae27448bc911941009f6223d441fa45", "src_uid": "08e8c0c37b223f6aae01d5609facdeaf", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/* https://codeforces.com/problemset/problem/1095/A */\n\nfun main() {\n readLine() // skip first line\n val encryptedString = readLine()!!\n val decryptedString = ArrayList()\n var increment = 1\n var i = 0\n while (i < encryptedString.length) {\n decryptedString.add(encryptedString[i])\n i += increment\n increment++\n }\n println(decryptedString.joinToString(\"\"))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8e1cc111558c5e9c64d058443ac33cd6", "src_uid": "08e8c0c37b223f6aae01d5609facdeaf", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val sb = StringBuilder()\n readLine()\n val t = readLine()!!\n var pos = 0\n while (pos < t.length) {\n sb.append(t[pos])\n pos += sb.length\n }\n print(sb.toString())\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "de5b0bcb6f26e80aaa8943fabadc2854", "src_uid": "08e8c0c37b223f6aae01d5609facdeaf", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 d = io.readInt()\n val s = IntArray(n, { io.readInt() }).sum()\n val r = (n - 1) * 10\n if (d < s + r) {\n io.println(-1)\n } else {\n io.println((d - s) / 5)\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "036014aa26ef0aefa85d3f447230c259", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (n, d) = readInts()\n var list = readInts().sum()\n\n if ((n-1)*10+list>d){\n println(-1)\n }else{\n var ans = d-list\n println(ans/5)\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()!!", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "8d3a76e05a35f24efe9a2c81fd1ec7fa", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun 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 t = r.readLine()!!.split(\" \").map { it.toInt() }\n var joke = (n-1)*2*5\n val leastTime = joke+t.sum()\n println(if (leastTime>time) -1 else joke/5+(time-leastTime)/5)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "c993a36bf97ca8d6d28e231d55e871a2", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n var scan = Scanner(System.`in`)\n var n = scan.nextInt()\n var d = scan.nextInt()\n var songs: MutableList = mutableListOf()\n for (i in 1..n) {\n songs.add(scan.nextInt())\n }\n var total = (songs.size - 1) * 10\n for (song in songs) {\n total += song\n }\n var totaljokes = (songs.size - 1) * 2\n if (total > d) {\n println(-1)\n } else {\n totaljokes += (d-total)/5\n println(totaljokes)\n }\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "9bd98f5656354398ccddbfab3f4c0f43", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 \u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u043f\u0430\u0440 - k=v.sortedWith(compareBy({it.first},{it.second})); \n print(\"${k[i].second}\"); - \u0432\u044b\u0432\u043e\u0434 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043f\u0430\u0440\u044b \n var m=ArrayList (); <=> vector \n getline(cin,a) <=> readLine()!!.last()\n \n readInt() - \u043e\u0434\u043d\u043e \u0447\u0438\u0441\u043b\u043e \n readInts() - \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u0435\u043b \n \n */ \n \n \n \n /* --------- */ \n \n var x1=cin.nextInt(); \n var y1=cin.nextInt(); \n var z1=cin.nextInt(); \n var t1=cin.nextInt(); \n var t2=cin.nextInt(); \n var t3=cin.nextInt(); \n \n var first1=Math.abs(x1-y1)*t2+t2*Math.abs(x1-z1)+3*t3;\n var first2=Math.abs(x1-y1)*t1;\n if (first1<=first2) println(\"YES\"); else println(\"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 ", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8d1dc3f97b6d11c93fa4a2bdadee13a8", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun main(args: Array) {\n val xyzt1t2t3 = readLine()!!.split(\" \").map{it.toInt()}\n val (x,y,z) = xyzt1t2t3.subList(0, 3)\n val (t1,t2,t3) = xyzt1t2t3.subList(3,6)\n println(if (abs(x-y)*t1 < abs(x-z)*t2+3*t3+abs(x-y)*t2) \"NO\" else \"YES\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "20e5b14540de748cc740a4852f328ad7", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args:Array){\n println(stairsOrElevator())\n }\n\nfun stairsOrElevator():String{\n val s =readLine()?.split(\" \")\n val timeStairs = (Math.abs(Integer.parseInt(s!![0])- Integer.parseInt(s[1])))*Integer.parseInt(s[3])\n val timeElevator = (Math.abs(Integer.parseInt(s[0])- Integer.parseInt(s[1]))*Integer.parseInt(s[4]))+((Math.abs(Integer.parseInt(s[2])- Integer.parseInt(s[0])) * Integer.parseInt(s[4]))+(3*Integer.parseInt(s[5])))\n\n return if (timeElevator > timeStairs){\n \"NO\"\n } else {\n \"YES\"\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "bbafd401ea66a46bda3b785f2a8313b9", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n operator fun List.component6(): Int {\n return this[5]\n }\n\n val (startFloor, goalFloor, elevatorFloor, stairsTime, elevatorTime, doorsTime) = readInts()\n print(\n if (abs(elevatorFloor - startFloor) * elevatorTime + abs(startFloor - goalFloor) * elevatorTime\n + 3 * doorsTime <= abs(startFloor - goalFloor) * stairsTime\n ) \"Yes\" else \"No\"\n )\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c4f85b06d307ccfd30d5a864de23a7e8", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "454dff881a87aea0f6c928b61c43e439", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "a949c6dc2ff707d2ce170a9f9a8733b4", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "6cb16361c9a8fb38e62edfd140c5c696", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.absoluteValue\n\nfun main() {\n readLine()\n print(readLine()!!.split(\" \").map { it.toInt().absoluteValue }.sum())\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "a88d7e59355f87e7a83a50f78be463ce", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\n\nfun main(){\n\n var a = nl()\n var b = nl()\n\n if(b -min umod q }\n .allMinBy { k -> lcm(a + k, b + k) }.minBy { it } ?: 0\n\n println(ans)\n }\n}\n\ninline infix fun Int.umod(base: Int) = Math.floorMod(this, base)\n\ntailrec fun gcd(a: Int, b: Int): Int = if(a == 0) abs(b) else gcd(b % a, a)\nfun lcm(a: Int, b: Int): Long = a / gcd(a, b) * b.toLong()\n\nfun Int.divisors() = sequence {\n val n = this@divisors\n if(n <= 0) return@sequence\n val tail = mutableListOf()\n\n for(p in 1..Int.MAX_VALUE) {\n val sq = p * p\n if(sq > n) break\n if(n % p == 0) {\n yield(p)\n if(sq != n) tail.add(n / p)\n }\n }\n\n yieldAll(tail.asReversed())\n}\n\ninline fun > Sequence.allMinBy(selector: (T) -> R): List {\n val result = mutableListOf()\n var min: R? = null\n\n for(it in this) {\n val r = selector(it)\n if(min == null || r < min) {\n min = r\n result.clear()\n result.add(it)\n } else if(r.compareTo(min) == 0) { result.add(it) }\n }\n\n return 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)\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "9b62917def66ff8db4ffd02b0d1da29b", "src_uid": "414149fadebe25ab6097fc67663177c3", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\nfun main() {\n output {\n val a = readInt()\n val b = readInt()\n\n val min = min(a, b)\n\n val ans = abs(a - b).divisors()\n .map { q -> -min umod q }\n .allMinBy { k -> lcm(a + k, b + k) }.min() ?: 0\n\n println(ans)\n }\n}\n\ninline infix fun Int.umod(base: Int) = Math.floorMod(this, base)\n\ntailrec fun gcd(a: Int, b: Int): Int = if(a == 0) abs(b) else gcd(b % a, a)\nfun lcm(a: Int, b: Int): Long = a / gcd(a, b) * b.toLong()\n\nfun Int.divisors() = sequence {\n val n = this@divisors\n if(n <= 0) return@sequence\n val tail = mutableListOf()\n\n for(p in 1..Int.MAX_VALUE) {\n val sq = p * p\n if(sq > n) break\n if(n % p == 0) {\n yield(p)\n if(sq != n) tail.add(n / p)\n }\n }\n\n yieldAll(tail.asReversed())\n}\n\ninline fun > Sequence.allMinBy(selector: (T) -> R): List {\n val result = mutableListOf()\n var min: R? = null\n\n for(it in this) {\n val r = selector(it)\n if(min == null || r < min) {\n min = r\n result.clear()\n result.add(it)\n } else if(r.compareTo(min) == 0) { result.add(it) }\n }\n\n return 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)\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "5ac89dd0dd3ad249df154fddc35efe1e", "src_uid": "414149fadebe25ab6097fc67663177c3", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "2ad95072bf403d24f3119f263a683c16", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "fada31736fd02352652e108494d142e6", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!.toLong()\n print((n * (n + 1) / 2) % 2)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "9dc64bd94d126f3757277de8f396d276", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "aca2c4c34b31df7cdae9107dc422e16f", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.FileInputStream\nimport kotlin.math.max\n\nfun main() {\n// changeStandardInput()\n val n = readIntLn()\n val a = readInts()\n val freq = IntArray(n + 1)\n\n var maxCount = 0\n var maxValue = 0\n a.forEach { value ->\n freq[value]++\n if (freq[value] > maxCount) {\n maxCount = freq[value]\n maxValue = value\n }\n }\n\n for (i in freq.indices) {\n if (maxCount == freq[i] && maxValue != i) {\n println(n)\n return\n }\n }\n\n var ans = 0\n for (i in freq.indices) {\n if (freq[i] > 0 && i != maxValue) {\n ans = max(ans, findZeroSum(a, i, maxValue, maxCount))\n }\n }\n\n println(ans)\n}\n\n\nfun findZeroSum(a: List, negValue: Int, posValue: Int, maxCount: Int): Int {\n val map = IntArray(2 * maxCount + 1) { -100 }\n map[maxCount] = -1\n\n var sum = 0\n var bestAns = 0\n\n for (i in a.indices) {\n val value = when (a[i]) {\n negValue -> -1\n posValue -> 1\n else -> 0\n }\n sum += value\n val oppositeIndex = map[sum + maxCount]\n\n if (oppositeIndex != -100) {\n bestAns = max(bestAns, i - oppositeIndex)\n } else {\n map[sum + maxCount] = i\n }\n }\n\n return bestAns\n}\n\nprivate fun readLn() = readLine()!!\nprivate fun readIntLn() = readLn().toInt()\nprivate fun readLongLn() = readLn().toLong()\nprivate fun readDoubleLn() = readLn().toDouble()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\nprivate fun readLongs() = readStrings().map { it.toLong() }\n\n\nprivate fun changeStandardInput() {\n System.setIn(FileInputStream(\"input.txt\"))\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "data structures"], "code_uid": "1a24e347c53e6293173f03e3157c437b", "src_uid": "a06ebb2734365ec97d07cd1b6b3faeed", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.FileInputStream\nimport kotlin.math.max\n\n\nprivate lateinit var positions: Array>\n\n\nfun main() {\n// changeStandardInput()\n val n = readIntLn()\n val a = readInts()\n\n val freq = IntArray(n + 1)\n\n var maxCount = 0\n var maxValue = 0\n\n positions = Array(n + 1) { mutableListOf() }\n\n a.forEachIndexed { index, value ->\n freq[value]++\n if (freq[value] > maxCount) {\n maxCount = freq[value]\n maxValue = value\n }\n positions[value].add(index)\n }\n\n for (i in freq.indices) {\n if (maxCount == freq[i] && maxValue != i) {\n println(n)\n return\n }\n }\n\n var ans = 0\n for (i in freq.indices) {\n if (freq[i] > 0 && i != maxValue) {\n val cur = findZeroSum2(positions[maxValue], positions[i], maxCount, n)\n ans = max(ans, cur)\n }\n }\n\n println(ans)\n}\n\n\nfun findZeroSum2(aPos: List, bPos: List, maxCount: Int, n: Int): Int {\n val map = IntArray(2 * maxCount + 1) { -100 }\n map[maxCount] = -1\n\n val merged = merge(aPos, bPos, n)\n var sum = 0\n var bestAns = 0\n for (i in merged.indices) {\n val (value, index) = merged[i]\n sum += value\n val oppositeIndex = map[sum + maxCount]\n\n if (oppositeIndex != -100) {\n val r = merged.getOrNull(i + 1)?.index ?: index\n val rDiff = if (r != index) 1 else 0\n bestAns = max(bestAns, (r - rDiff) - oppositeIndex)\n } else {\n map[sum + maxCount] = index\n }\n }\n\n return bestAns\n}\n\nprivate fun merge(aPos: List, bPos: List, n: Int): List {\n val merged = ArrayList(aPos.size + bPos.size + 2)\n if (aPos[0] != 0 && bPos[0] != 0) {\n merged.add(IntPair(0, 0))\n }\n\n var i = 0\n var j = 0\n while (i < aPos.size || j < bPos.size) {\n if (j >= bPos.size || (i < aPos.size && aPos[i] < bPos[j])) {\n merged.add(IntPair(1, aPos[i++]))\n } else {\n merged.add(IntPair(-1, bPos[j++]))\n }\n }\n if (merged.last().index != n - 1) {\n merged.add(IntPair(0, n - 1))\n }\n return merged\n}\n\n\nprivate data class IntPair(\n val value: Int,\n val index: Int\n) : Comparable {\n override fun compareTo(other: IntPair): Int {\n val cmp = value.compareTo(other.value)\n return if (cmp == 0) index.compareTo(other.index) else cmp\n }\n}\n\nfun findZeroSum(a: List, negValue: Int, posValue: Int, maxCount: Int): Int {\n val map = IntArray(2 * maxCount + 1) { -100 }\n map[maxCount] = -1\n\n var sum = 0\n var bestAns = 0\n\n for (i in a.indices) {\n val value = when (a[i]) {\n negValue -> -1\n posValue -> 1\n else -> 0\n }\n sum += value\n val oppositeIndex = map[sum + maxCount]\n\n if (oppositeIndex != -100) {\n bestAns = max(bestAns, i - oppositeIndex)\n } else {\n map[sum + maxCount] = i\n }\n }\n\n return bestAns\n}\n\nprivate fun readLn() = readLine()!!\nprivate fun readIntLn() = readLn().toInt()\nprivate fun readLongLn() = readLn().toLong()\nprivate fun readDoubleLn() = readLn().toDouble()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\nprivate fun readLongs() = readStrings().map { it.toLong() }\n\n\nprivate fun changeStandardInput() {\n System.setIn(FileInputStream(\"input.txt\"))\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "data structures"], "code_uid": "2964d9ef5ea0fab2b2c6431ca30a6f9b", "src_uid": "a06ebb2734365ec97d07cd1b6b3faeed", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.FileInputStream\nimport kotlin.math.max\n\n\nprivate lateinit var positions: Array>\n\n\nfun main() {\n// changeStandardInput()\n val n = readIntLn()\n val a = readInts()\n\n val freq = IntArray(n + 1)\n\n var maxCount = 0\n var maxValue = 0\n\n positions = Array(n + 1) { mutableListOf() }\n\n a.forEachIndexed { index, value ->\n freq[value]++\n if (freq[value] > maxCount) {\n maxCount = freq[value]\n maxValue = value\n }\n positions[value].add(index)\n }\n\n for (i in freq.indices) {\n if (maxCount == freq[i] && maxValue != i) {\n println(n)\n return\n }\n }\n\n var ans = 0\n for (i in freq.indices) {\n if (freq[i] > 0 && i != maxValue) {\n val cur = findZeroSum2(positions[maxValue], positions[i], maxCount, n)\n ans = max(ans, cur)\n }\n }\n\n println(ans)\n}\n\nfun findZeroSum2(aPos: List, bPos: List, maxCount: Int, n: Int): Int {\n val map = IntArray(2 * maxCount + 1) { -100 }\n\n map[maxCount] = -1\n\n merge(aPos, bPos, n)\n var sum = 0\n var bestAns = 0\n for (i in 0 until size) {\n val (value, index) = merged[i]\n sum += value\n val oppositeIndex = map[sum + maxCount]\n\n if (oppositeIndex != -100) {\n val r = if (i + 1 < size) merged[i + 1].index else index\n val rDiff = if (r != index) 1 else 0\n bestAns = max(bestAns, (r - rDiff) - oppositeIndex)\n } else {\n map[sum + maxCount] = index\n }\n }\n\n return bestAns\n}\n\nprivate var size = 0\nprivate val merged = Array(200_002) {\n IntPair(0, 0)\n}\n\nprivate fun merge(aPos: List, bPos: List, n: Int) {\n size = 0\n if (aPos[0] != 0 && bPos[0] != 0) {\n merged[size].index = 0\n merged[size].value = 0\n size++\n }\n\n var i = 0\n var j = 0\n while (i < aPos.size || j < bPos.size) {\n if (j >= bPos.size || (i < aPos.size && aPos[i] < bPos[j])) {\n merged[size].value = 1\n merged[size].index = aPos[i++]\n } else {\n merged[size].value = -1\n merged[size].index = bPos[j++]\n }\n size++\n }\n\n if (merged[size - 1].index != n - 1) {\n merged[size].value = 0\n merged[size].index = n - 1\n size++\n }\n}\n\n\nprivate data class IntPair(\n var value: Int,\n var index: Int\n) : Comparable {\n override fun compareTo(other: IntPair): Int {\n val cmp = value.compareTo(other.value)\n return if (cmp == 0) index.compareTo(other.index) else cmp\n }\n}\n\nfun findZeroSum(a: List, negValue: Int, posValue: Int, maxCount: Int): Int {\n val map = IntArray(2 * maxCount + 1) { -100 }\n map[maxCount] = -1\n\n var sum = 0\n var bestAns = 0\n\n for (i in a.indices) {\n val value = when (a[i]) {\n negValue -> -1\n posValue -> 1\n else -> 0\n }\n sum += value\n val oppositeIndex = map[sum + maxCount]\n\n if (oppositeIndex != -100) {\n bestAns = max(bestAns, i - oppositeIndex)\n } else {\n map[sum + maxCount] = i\n }\n }\n\n return bestAns\n}\n\nprivate fun readLn() = readLine()!!\nprivate fun readIntLn() = readLn().toInt()\nprivate fun readLongLn() = readLn().toLong()\nprivate fun readDoubleLn() = readLn().toDouble()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\nprivate fun readLongs() = readStrings().map { it.toLong() }\n\n\nprivate fun changeStandardInput() {\n System.setIn(FileInputStream(\"input.txt\"))\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "data structures"], "code_uid": "56a280c3966eb0bf5c4602c4be624fbd", "src_uid": "a06ebb2734365ec97d07cd1b6b3faeed", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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) = input.readLine().toLongs()\n var nPrev = 1L // k = 0\n var nCur = 2L // k = 1\n var k = 1\n while (true) {\n val nNext = nCur + nPrev\n if (nNext > n) {\n output.println(k)\n return\n }\n ++k\n nPrev = nCur\n nCur = nNext\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "f486377c6db4190bf9c762bffdf3d827", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!.toLong()\n val dp = LongArray(100000)\n dp[0] = 1L\n dp[1] = 2L\n for (j in 2..100000) {\n dp[j] = dp[j - 1] + dp[j - 2]\n if (dp[j] > n) {\n println(j - 1)\n return\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "b9bce3dcc2920babaed574f074f63fed", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.ArrayList\n\nfun fibInv(n: Long): Int {\n if(n < 3) {\n return 1;\n }\n\n var i = 1;\n val fib = ArrayList(2)\n\n fib.add(1);\n fib.add(2);\n\n while(n >= fib[i]) {\n i++\n fib.add(fib[i - 1] + fib[i - 2]);\n }\n\n return i - 1;\n}\n\nfun main(args: Array) {\n val n = readLine()?.toLong() ?: 0\n\n println(fibInv(n));\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "9955edd3108de4a3a224c39da80bbf35", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "642c6ee798d99a6d8a616e6deca8fc80", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "15dd6b87a4961f2309bec318a44ff9e6", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "4c94dcee3663cae1a4c4d8242e9472cd", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "bd201de60dd06ae0178a23a4d8a5610b", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 var c1 = 0\n var c2 = 0\n var c3 = 0\n for (i in 0..n-1){\n when(i%3){\n 0 -> c1 += v[i]\n 1 -> c2 += v[i]\n 2 -> c3 += v[i]\n }\n }\n println(when(maxOf(c1, c2, c3)){\n c1 -> \"chest\"\n c2 -> \"biceps\"\n else -> \"back\"\n })\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5dd1f55ecca2400de579513641d1a2f7", "src_uid": "579021de624c072f5e0393aae762117e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n\n val reader = Scanner(System.`in`)\n val N = reader.nextInt()\n var mashq = IntArray(N)\n var types = IntArray(3)\n for (index: Int in 0..(N - 1)) {\n mashq[index] = reader.nextInt()\n types[index % 3] += mashq[index]\n }\n val maxIndex = types.indices.maxBy { types[it] }\n if (maxIndex == 0) println(\"chest\")\n else if (maxIndex == 1) println(\"biceps\")\n else if (maxIndex == 2) println(\"back\")\n\n\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "de09adba53848564c23fccc60e4c5c47", "src_uid": "579021de624c072f5e0393aae762117e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun main (args: Array) {\n val exercises = arrayOf(\"chest\",\"biceps\",\"back\")\n val reader = Scanner(System.`in`)\n val n = reader.nextInt()\n val h = mutableMapOf(0 to 0, 1 to 0, 2 to 0)\n var a = 0\n for (i in 1..n) {\n h[a] = h[a]!! + reader.nextInt()\n a= (a+1)%3 \n }\n val maxa = h.maxBy{it.value}!!.key\n println(exercises[maxa])\n\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "e1875bd7f6e6b2bb49a7ac557abc3102", "src_uid": "579021de624c072f5e0393aae762117e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val repeats = intArrayOf(0, 0, 0)\n readLine()\n for ((pos, exercise) in readInts().withIndex())\n repeats[pos % 3] += exercise\n print(\n when {\n repeats[0] > repeats[1] && repeats[0] > repeats[2] -> \"chest\"\n repeats[1] > repeats[0] && repeats[1] > repeats[2] -> \"biceps\"\n else -> \"back\"\n }\n )\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8bcace9d338c2adff78d525e20bb482a", "src_uid": "579021de624c072f5e0393aae762117e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * Created by Nithin Sanjey on 8/13/2017.\n *\n * */\n\nfun keyReaces(s:Int,v1:Int,v2:Int,t1:Int,t2:Int): String{\n val racer1TimeInfo: Int = 2*t1+s*v1\n val racer2TimeInfo: Int = 2*t2+s*v2\n if(racer1TimeInfo < racer2TimeInfo)\n return \"First\"\n else if (racer1TimeInfo > racer2TimeInfo)\n return \"Second\"\n else\n return \"Friendship\"\n}\n\nfun main(args: Array){\n val (s,v1,v2,t1,t2) = readLine()!!.split(' ')\n println(keyReaces(s.toInt(),v1.toInt(),v2.toInt(),t1.toInt(),t2.toInt()))\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "caca8778fd270d7e060ea9d82fc9d50f", "src_uid": "10226b8efe9e3c473239d747b911a1ef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (s, v1, v2, t1, t2) = readLine()!!.split(' ').map { it.toInt() }.toIntArray()\n print(if ((s*v1 + t1*2)>(s*v2 + t2*2)) \"Second\" else if ((s*v1 + t1*2)<(s*v2 + t2*2)) \"First\" else \"Friendship\")\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "7196df8a71e31b5c6264186fde359342", "src_uid": "10226b8efe9e3c473239d747b911a1ef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n\n val scanner = Scanner(System.`in`)\n\n val t = scanner.nextLine().split(' ').map { it.toInt() }\n\n val first = t[0] * t[1] + 2 * t[3]\n val second = t[0] * t[2] + 2 * t[4]\n\n when {\n first < second -> println(\"First\")\n first > second -> println(\"Second\")\n else -> println(\"Friendship\")\n }\n\n\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "410be062fbd56f969255577d5392db62", "src_uid": "10226b8efe9e3c473239d747b911a1ef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/* https://codeforces.com/problemset/problem/835/A */\n\nfun main() {\n val (s, v1, v2, t1, t2) = readLine()!!.split(\" \").map { it.toInt() }\n val time1 = v1 * s + 2 * t1\n val time2 = v2 * s + 2 * t2\n when (time2.compareTo(time1)) {\n 0 -> println(\"Friendship\")\n 1 -> println(\"First\")\n -1 -> println(\"Second\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "ad15ff11a83ec6ffcf500e3ceb284b8b", "src_uid": "10226b8efe9e3c473239d747b911a1ef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\n val ans = n.factorize().take(2).joinToString(\"\")\n\n println(ans)\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\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}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "2535474dfd89759b910432cf4c473f89", "src_uid": "7220f2da5081547a12118595bbeda4f6", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun prime(x: Int): Boolean {\n if (x < 2) return false\n if (x < 4) return true\n var i = 4\n while (i * i <= x) {\n if (x % i == 0) return false\n i++\n }\n return true\n}\nfun main() {\n val n = readLine()!!.toInt()\n val b = BooleanArray(1001) { i -> prime(i) }\n for (i in 2..n) {\n if (n % i == 0 && b[i] && b[n / i]) {\n println(\"$i${n/i}\")\n return\n }\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "fd13719c104c2596952fbbcc616a597e", "src_uid": "7220f2da5081547a12118595bbeda4f6", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var x = readLine()!!.toInt()\n var i = 2\n while (x > 1) {\n if (x % i == 0) {\n print(i.toString())\n x /= i\n } else i++\n }\n println()\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "4582ae05a1f92d5418cd25974bd3a6b3", "src_uid": "7220f2da5081547a12118595bbeda4f6", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.awt.Point\nimport java.io.*\nimport java.lang.StringBuilder\nimport java.lang.System.`in`\nimport java.util.*\n\n\nfun solve(stringBuilder: StringBuilder, reader: Reader) {\n var a = reader.getNextInt()\n val simples = getSimpleNumbersUpTo(a)\n val answer = mutableListOf()\n while (a != 1) {\n for (simpleNim in simples) {\n while (a % simpleNim == 0) {\n answer.add(simpleNim)\n a /= simpleNim\n }\n }\n }\n stringBuilder.append(answer.sorted().take(2).joinToString(\"\"))\n}\n\nfun getSimpleNumbersUpTo(a : Int) : List {\n val answer = mutableListOf()\n val numbers = (2..a).toList().toIntArray()\n for ((index, num) in numbers.withIndex()) {\n if (num != 0) {\n answer.add(num)\n numbers[index] = 0\n\n var localIndex = index + num\n while (localIndex < a - 1) {\n numbers[localIndex] = 0\n localIndex += num\n }\n }\n }\n return answer\n}\n\n//---------------------------------------------------------------------------------------------------------------------\n\n\nfun main() {\n val reader = Reader()\n\n val stringBuilder = StringBuilder()\n\n solve(stringBuilder, reader)\n\n val bw = BufferedWriter(OutputStreamWriter(System.out))\n bw.write(stringBuilder.toString())\n\n bw.flush()\n bw.close()\n reader.close()\n}\n\n\nclass Reader : Closeable {\n private var bufferedReader: BufferedReader = BufferedReader(InputStreamReader(`in`))\n private var tokenizer: StringTokenizer = StringTokenizer(bufferedReader.readLine())\n\n fun getNextToken(): String {\n if (!tokenizer.hasMoreTokens()) {\n tokenizer = StringTokenizer(bufferedReader.readLine())\n }\n return tokenizer.nextToken()\n }\n\n fun getNextInt() = getNextToken().toInt()\n\n fun getNextLong() = getNextToken().toLong()\n\n fun getNextULong() = getNextToken().toULong()\n\n fun getNextDouble() = getNextToken().toDouble()\n\n fun getNextIntArray(n : Int) : IntArray {\n val array = IntArray(n)\n for (i in array.indices) {\n array[i] = getNextInt()\n }\n return array\n }\n\n fun getNextLongArray(n : Int) : LongArray {\n val array = LongArray(n)\n for (i in array.indices) {\n array[i] = getNextLong()\n }\n return array\n }\n\n fun getNextDoubleArray(n : Int) : DoubleArray {\n val array = DoubleArray(n)\n for (i in array.indices) {\n array[i] = getNextDouble()\n }\n return array\n }\n\n fun getNextStringIntArray() : IntArray = bufferedReader.readLine().split(\" \").filter { it.isNotEmpty() }.map { it.toInt() }.toIntArray()\n\n fun getNextStringLongArray() : LongArray = bufferedReader.readLine().split(\" \").filter { it.isNotEmpty() }.map { it.toLong() }.toLongArray()\n\n fun getNextStringDoubleArray() : DoubleArray = bufferedReader.readLine().split(\" \").filter { it.isNotEmpty() }.map { it.toDouble() }.toDoubleArray()\n\n override fun close() {\n bufferedReader.close()\n }\n}\n\nfun normalMod(d : Long, mod : Long) : Long = ((d % mod) + mod) % mod\n\nfun modAdd(x : Long, y : Long, mod: Long) : Long = normalMod(normalMod(x, mod) + normalMod(y, mod), mod)\n\nfun modSub(x : Long, y : Long, mod: Long) : Long = normalMod(normalMod(x, mod) - normalMod(y, mod), mod)\n\nfun modMul(x : Long, y : Long, mod: Long) : Long = normalMod(normalMod(x, mod) * normalMod(y, mod), mod)\n\n// \u0435\u0441\u043b\u0438 \u043c\u043e\u0434\u0443\u043b\u044c \u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439\nfun modDivWithSimpleMod(x : Long, y: Long, mod: Long) : Long {\n return modMul(x, y.toBigInteger().modPow((mod - 2L).toBigInteger(), mod.toBigInteger()).toLong(), mod)\n}\n\n// \u0435\u0441\u043b\u0438 \u043c\u043e\u0434\u0443\u043b\u044c \u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439\nfun modDivWithAnyMod(x : Long, y: Long, mod: Long) : Long {\n var point = GcdCalculate(1, 0, mod)\n gcdExtCalculate(y, mod, point)\n if (x % point.d != 0L) {\n return -1L\n }\n return modMul(x / point.d, point.x, mod)\n}\n\n//\u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u043e\u0431\u0449\u0438\u0439 \u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u042d\u0432\u043a\u043b\u0438\u0434\u0430\nfun Long.getGCD(a : Long) : Long {\n var x = this\n var y = a\n\n if (Math.abs(this) > Math.abs(a)) {\n x = a\n y = this\n }\n\n while (y != 0L && x != 0L) {\n val rest = y % x\n if (rest > Math.abs(x)) {\n y = rest\n } else {\n y = x\n x = rest\n }\n }\n return x + y\n}\n\n// \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0443\u0440\u0430\u0432\u043b\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u0438\u0434\u0430 ax + by = d \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u042d\u0432\u043a\u043b\u0438\u0434\u0430\nfun Long.getGCDExt(a : Long) : Point {\n val datum = GcdCalculate(1L, 0L, 1L)\n gcdExtCalculate(this, a, datum)\n return Point(datum.x.toInt(), datum.y.toInt())\n}\n\n// \u0435\u0441\u0442\u044c \u043b\u0438 \u0432 \u0434\u0438\u043e\u0444\u0430\u043d\u0442\u043e\u0432\u043e\u043c \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0432\u0438\u0434\u0430 ax + by = d \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435\nfun Long.GCDInDiofantExistSolution(a : Long, c : Long) : Boolean {\n val gcd = this.getGCD(a)\n return c % gcd == 0L\n}\n\n// \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u0434\u0438\u043e\u0444\u0430\u043d\u0442\u043e\u0432\u043e\u043c \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0432\u0438\u0434\u0430 ax + by = d\nfun Long.getGCDExtLikeDiofant(a : Long, c : Long) : Point {\n val d = this.getGCD(a)\n val datum = GcdCalculate(1, 0, 1)\n gcdExtCalculate(this, a, datum)\n datum.x = datum.x * c / d\n datum.y = datum.y * c / d\n return Point(datum.x.toInt(), datum.y.toInt())\n}\n\n//\u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434\nfun gcdExtCalculate(a : Long, b: Long, datum : GcdCalculate) {\n if (b == 0L) {\n datum.d = a\n datum.x = 1\n datum.y = 0\n return\n }\n gcdExtCalculate(b, a % b, datum)\n val s = datum.y\n datum.y = datum.x - (a / b) * datum.y\n datum.x = s\n}\n//\u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\ndata class GcdCalculate(var x : Long, var y : Long, var d : Long)\n\n\n// PalindromeHashing(s + s.reversed())\n// \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0445\u0435\u0448\u0438\u043d\u0433\u0430 \u0434\u043b\u044f \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u0430\u043b\u0438\u043d\u0434\u0440\u043e\u043c\u0430\ninternal class PalindromeHashing(s: String) {\n val X = 566239L\n val M = 1000000007L\n val h: LongArray\n val t: LongArray\n\n init {\n val length = s.length\n h = LongArray(length + 1)\n t = LongArray(length + 1)\n t[0] = 1\n for (i in 0 until length) {\n t[i + 1] = (t[i] * X % M)\n h[i + 1] = ((h[i] * X + s[i].toLong()) % M)\n }\n }\n\n fun hash(from: Int, to: Int): Long {\n var res = ((h[to] - h[from] * t[to - from]) % M)\n if (res < 0L) {\n res += M\n }\n return res\n }\n}\n\nfun Boolean.toYesNo() : String = if (this) \"YES\" else \"NO\"", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "8d57782016e734c9bf3e73b88ef7ddba", "src_uid": "7220f2da5081547a12118595bbeda4f6", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n var ballWeight = scanner.nextInt()\n val ballHeight = scanner.nextInt()\n\n val stoneOneWeight = scanner.nextInt()\n val stoneOneHeight = scanner.nextInt()\n val stoneTwoWeight = scanner.nextInt()\n val stoneTwoHeight = scanner.nextInt()\n\n for (currentHeight in ballHeight downTo 1) {\n ballWeight += currentHeight\n\n if (stoneOneHeight == currentHeight) {\n ballWeight -= stoneOneWeight\n }\n if (stoneTwoHeight == currentHeight) {\n ballWeight -= stoneTwoWeight\n }\n\n if (ballWeight < 0)\n ballWeight = 0\n }\n\n print (ballWeight)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d02b2208e3b9950eb55fd2ec12e7f95b", "src_uid": "084a12eb3a708b43b880734f3ee51374", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Integer.min\n\nfun main(args: Array) {\n// var n = readLine()!!\n var ball = readLine()!!.split(\" \").map { x -> x.toInt() }\n var stone1 = readLine()!!.split(\" \").map { x -> x.toInt() }\n var stone2 = readLine()!!.split(\" \").map { x -> x.toInt() }\n// var arr = readLine()!!.split(\" \")\n var size = ball[0]\n for(a in ball[1] downTo 0) {\n size+=a\n if (a == stone1[1]) {\n if (stone1[0] > size) size = 0\n else size-=stone1[0]\n } else\n if (a == stone2[1]) {\n if (stone2[0] > size) size = 0\n else size-=stone2[0]\n }\n\n }\n\n print(size)\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "19136e46ae09c423390ca2d4849c7307", "src_uid": "084a12eb3a708b43b880734f3ee51374", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package com.happypeople.codeforces.c1099\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 var w=sc.nextInt()\n var h=sc.nextInt()\n val u1=sc.nextInt()\n val d1=sc.nextInt()\n val u2=sc.nextInt()\n val d2=sc.nextInt()\n\n while(h>0) {\n w+=h\n if(h==d1)\n w-=u1\n if(w<0)\n w=0\n if(h==d2)\n w-=u2\n if(w<0)\n w=0\n h--\n }\n println(\"$w\")\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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9f8a0552496433a301e0e86c62fe8ec1", "src_uid": "084a12eb3a708b43b880734f3ee51374", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package `codeforces-parser`.`1099-kotlin`.A\n\nvar _debug = false;\nfun debug(vararg vals: T): Unit {\n\tif (!_debug) {\n\t\treturn\n\t}\n\tfor (v in vals) {\n\t\tSystem.err.print(v); System.err.print(\" \")\n\t}\n\tSystem.err.println()\n}\n\nfun main(args: Array) {\n\tif (args.size > 0 && args[0] == \"-d\") {\n\t\t_debug = true;\n\t}\n\n\tval (w, h) = readLine()!!.split(' ').map(String::toLong)\n\tval (u1, d1) = readLine()!!.split(' ').map(String::toLong)\n\tval (u2, d2) = readLine()!!.split(' ').map(String::toLong)\n\n\tval min = if (d1 < d2) u1 to d1 else u2 to d2\n\tval max = if (d1 > d2) u1 to d1 else u2 to d2\n\n\tvar sum = w\n\tfor (i in h downTo max.second) sum += i\n\n\tsum = Math.max(sum - max.first, 0)\n\n\tfor (i in max.second - 1 downTo min.second) sum += i\n\n\tsum = Math.max(sum - min.first, 0)\n\n\tfor (i in min.second - 1 downTo 1) sum += i\n\n\tprintln(Math.max(sum, 0))\n}\n\n\n\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "f3726cc8a0aceeb41db97bd07adbc053", "src_uid": "084a12eb3a708b43b880734f3ee51374", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args : Array) {\n val n = readLine()!!.toInt()\n println(if (n % 2 == 1) 0 else 1 shl (n / 2))\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp"], "code_uid": "40e06ce6384e00a264dd231532324845", "src_uid": "4b7ff467ed5907e32fd529fb39b708db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val input = readLine()!!.toInt()\n val output = when (input % 2) {\n 0 -> 1 shl input / 2\n else -> 0\n }\n println(output)\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp"], "code_uid": "5ad111845fa7cca9c71340ae4e3b15c6", "src_uid": "4b7ff467ed5907e32fd529fb39b708db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!.toInt()\n var ans = 1L\n if (n % 2 == 0) {\n for (i in 0 until n / 2) ans *= 2\n } else ans = 0\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp"], "code_uid": "3f5c202fcecd728b32bf57adf8a4d48b", "src_uid": "4b7ff467ed5907e32fd529fb39b708db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.util.*\n\nfun main(args: Array){\n val Reader= Scanner(System.`in`)\n var n:Int=Reader.nextInt()\n\n if((n%2==0)){\n var i:Int=1\n var x:Int =2\n while(i<=(n/2)-1){\n x=x*2\n i++\n }\n println(x)\n }\n else{\n println(0)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp"], "code_uid": "1534298eac5257e1ee046b4337e19115", "src_uid": "4b7ff467ed5907e32fd529fb39b708db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : InputReader, pw : PrintWriter) {\n\n val xyz = IntArray(3)\n val abc = IntArray(3)\n\n for (i in 0..2) xyz[i] = ir.nextInt()\n for (i in 0..2) abc[i] = ir.nextInt()\n\n if (abc[0] < xyz[0]) {\n pw.print(\"NO\")\n return\n } else abc[1] += (abc[0] - xyz[0])\n\n if (abc[1] < xyz[1]) {\n pw.print(\"NO\")\n return\n } else abc[2] += (abc[1] - xyz[1])\n\n if (abc[2] < xyz[2]) {\n pw.print(\"NO\")\n return\n }\n\n pw.print(\"YES\")\n\n}\n\n\nclass InputReader(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 }\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation"], "code_uid": "1bad3a532a54a697cc0a8727f89ef605", "src_uid": "d54201591f7284da5e9ce18984439f4e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val(x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n var(g, p, b) = readLine()!!.split(\" \").map { it.toInt() }\n if(x > g) {\n println(\"NO\")\n return\n }\n g -= x\n if(y > g + p){\n println(\"NO\")\n return\n }\n p -= y\n if(z > g + p + b){\n println(\"NO\")\n return\n }\n println(\"YES\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation"], "code_uid": "0cb35576e53c690932c16834a6bf972c", "src_uid": "d54201591f7284da5e9ce18984439f4e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation"], "code_uid": "9d428fc152e52e39ad900b478c9f5858", "src_uid": "d54201591f7284da5e9ce18984439f4e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation"], "code_uid": "0f16558d9eb89b6ca39ca866d00f107a", "src_uid": "d54201591f7284da5e9ce18984439f4e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "b59dce278140b8e441f745f30ef00526", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "1cd47e397bfe2440640d71d37ac18b3b", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "0c9d7f97ec82b95378a0452af3d2fe53", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n readLine()!!.toInt().let { println((1..it).sumBy { it + (1..it-2).sumBy { it }}) }\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "6e266070394bdfe7f64977a0aeba8b9f", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\")\n\nimport java.io.PrintWriter\nimport java.util.PriorityQueue\nimport java.util.SortedMap\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 T = readInt()\n\n repeat(T) {\n val n = readInt()\n val k = readInt()\n val d = readInt()\n val A = readIntArray(n)\n\n val bag = HashBag()\n for(i in 0 until d) {\n bag.add(A[i])\n }\n\n var ans = bag.numDistinct\n for(i in d until n) {\n bag.add(A[i])\n bag.remove(A[i-d])\n ans = min(ans, bag.numDistinct)\n }\n\n println(ans)\n }\n }\n}\n\nval Bag<*>.numDistinct get() = countMap.size\n\ninterface Bag : Collection {\n val countMap: Map\n\n fun getCount(element: T): Int = countMap[element] ?: 0\n val elements: Set get() = countMap.keys\n val entries: Set> get() = countMap.entries\n\n override fun iterator(): Iterator = sequence {\n for((e, cnt) in countMap) {\n repeat(cnt) { yield(e) }\n }\n }.iterator()\n\n override fun contains(element: T): Boolean = countMap.containsKey(element)\n}\n\nprivate fun Bag<*>._size() = countMap.values.sum()\nprivate fun Bag<*>._equals(other: Any?) = when {\n this === other -> true\n other is Bag<*> -> countMap == other.countMap\n else -> false\n}\nprivate fun Bag<*>._hashCode() = countMap.hashCode()\n\nclass BagImpl(override val countMap: Map): Bag, AbstractCollection() {\n override val size = _size()\n override fun equals(other: Any?) = _equals(other)\n override fun hashCode() = _hashCode()\n override fun contains(element: T) = super.contains(element)\n override fun iterator() = super.iterator()\n}\nfun Bag(countMap: Map): Bag = BagImpl(countMap)\n\ninterface MutableBag : Bag, MutableCollection {\n val _countMap: MutableMap\n var _size: Int\n\n override fun add(element: T): Boolean { add(element, 1); return true }\n fun add(element: T, occurrences: Int): Int {\n require(occurrences >= 0)\n val oldCount = getCount(element)\n _countMap[element] = oldCount + occurrences\n _size += occurrences\n return oldCount\n }\n\n override fun remove(element: T): Boolean = remove(element, 1) > 0\n fun remove(element: T, occurrences: Int): Int {\n require(occurrences >= 0)\n val oldCount = getCount(element)\n val m = minOf(occurrences, oldCount)\n when(oldCount) {\n 0 -> return 0\n m -> _countMap.remove(element)\n else -> _countMap[element] = oldCount - m\n }\n _size -= m\n return oldCount\n }\n\n fun setCount(element: T, occurrences: Int): Int {\n require(occurrences >= 0)\n val oldCount = getCount(element)\n if(occurrences == 0) _countMap.remove(element)\n else _countMap[element] = occurrences\n _size += occurrences - oldCount\n return oldCount\n }\n\n override fun iterator(): MutableIterator = object: MutableIterator {\n private val mapIterator = _countMap.iterator()\n private var rem = 0\n private lateinit var lastEntry: MutableMap.MutableEntry\n private var removed = true\n override fun hasNext() = rem > 0 || mapIterator.hasNext()\n override fun next(): T {\n if(rem == 0) {\n lastEntry = mapIterator.next()\n rem = lastEntry.value\n }\n rem--\n removed = false\n return lastEntry.key\n }\n override fun remove() {\n if(removed) error(\"\")\n lastEntry.setValue(lastEntry.value - 1)\n if(lastEntry.value == 0) mapIterator.remove()\n _size--\n removed = true\n }\n }\n}\n\nabstract class AbstractMutableBag: MutableBag, AbstractMutableCollection() {\n final override val countMap: Map get() = _countMap\n final override val size get() = _size\n override fun equals(other: Any?) = _equals(other)\n override fun hashCode() = _hashCode()\n override fun contains(element: T) = super.contains(element)\n override fun iterator() = super.iterator()\n override fun add(element: T): Boolean = super.add(element)\n override fun addAll(elements: Collection): Boolean =\n if(elements is Bag) {\n for((e, n) in elements.countMap) add(e, n)\n true\n } else super.addAll(elements)\n override fun remove(element: T): Boolean = super.remove(element)\n override fun removeAll(elements: Collection): Boolean =\n if(elements is Bag) {\n var modified = false\n for((e, n) in elements.countMap) if(remove(e, n) > 0) modified = true\n modified\n } else super.removeAll(elements)\n}\n\nclass HashBag(override val _countMap: HashMap): AbstractMutableBag() {\n constructor(): this(HashMap())\n\n override var _size = _size()\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()", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "daf8f0d67aee903ad39683d8e1cfeedc", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n val t = readInt()\n\n repeat(t) {\n val (_, _, d) = readInts()\n val episodes = readInts()\n\n var minEpisodes = Int.MAX_VALUE\n val currEpisodes = mutableMapOf()\n\n episodes.forEachIndexed { index, episode ->\n currEpisodes[episode] = currEpisodes[episode]?.plus(1) ?: 1\n if (index - d >= 0) {\n currEpisodes[episodes[index - d]] = currEpisodes[episodes[index - d]]?.minus(1) ?: 0\n if (currEpisodes[episodes[index - d]] == 0) currEpisodes.remove(episodes[index - d])\n }\n\n if (index >= d - 1) minEpisodes = min(currEpisodes.size, minEpisodes)\n }\n\n println(minEpisodes)\n }\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\n\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "1259426fde9d4ac5237a0a8653c58392", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array ) {\n val t = readLine()!!.toInt()\n (1..t).forEach {\n val (n, k, d) = readLine()!!.split(\" \").map { it.toInt() }\n val x = readLine()!!.split(\" \").map { it.toInt() - 1 }\n var c = IntArray(k)\n var r = k\n var s = 0\n (0..n-1).forEach {\n if ( c[ x[it] ] == 0 ) s++\n c[ x[it] ] ++\n if ( it >= d ) {\n c[ x[ it-d ] ] --\n if ( c[ x[ it-d ] ] == 0 ) s--\n }\n if ( it >= d-1 ) {\n if ( s < r ) r = s\n }\n }\n println( r )\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2d4ab8285b0f49ffdde2ef033105efeb", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n\n var count = readLine()!!.toInt()\n\n for(c in 0 until count) {\n var (n, k, d) = readLine()!!.split(\" \").map { it.toInt() }\n var numbers = readLine()!!.split(\" \").map { it.toInt() }.toIntArray()\n\n var set = numbers.take(d).groupBy { it }.map { Pair(it.key, it.value.size) }.toMap().toMutableMap()\n var numNumber = set.size\n for(i in d until n) {\n var leftIndex = numbers[i-d]\n set[leftIndex] = set[leftIndex]!! - 1\n if(set[leftIndex] == 0) {\n set.remove(leftIndex)\n }\n\n var rightIndex = numbers[i]\n if(set.containsKey(rightIndex)) {\n set[rightIndex] = set[rightIndex]!! + 1\n } else {\n set.put(rightIndex, 1)\n }\n\n numNumber = numNumber.coerceAtMost(set.size)\n }\n\n println(numNumber)\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d6ed7e6d75d52f757308fe768cd4634e", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n println(readLine()!!.split(' ').map { it.toInt() }.let { it.max()!! - it.min()!! })\n}", "lang_cluster": "Kotlin", "tags": ["math", "sortings", "implementation"], "code_uid": "10b107e7e55f4b70b33fb3bb48b606b1", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main() {\n var arr = readLine()!!.split(' ').map { it.toInt() }.toIntArray().sorted()\n println(arr[1] - arr[0] + arr[2] - arr[1])\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "sortings", "implementation"], "code_uid": "7fb43457e2db9e1a0971d152a0a788af", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * Created by Mego on 5/29/2017.\n */\nfun main(args: Array) {\n val input = readLine()!!.split(\" \")\n var inputInt = arrayListOf()\n\n for (i in 0..input.size - 1) {\n inputInt.add(input[i].toInt())\n }\n val mid = (inputInt.sorted())[1]\n val numberOfSteps = (Math.abs(mid - inputInt[0]) + Math.abs(mid - inputInt[1]) + Math.abs(mid - inputInt[2]))\n println(numberOfSteps)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "sortings", "implementation"], "code_uid": "e6f3453759ab13b66b1453f8a22769b5", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 val a = Array(3) {nextInt()}\n fout.print(a.max()!! - a.min()!!)\n fout.close()\n fin.close()\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "sortings", "implementation"], "code_uid": "bd8eb952057f8cbeb7870daf4002ee91", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.io.BufferedReader\r\nimport java.io.InputStream\r\nimport java.io.InputStreamReader\r\nimport java.util.*\r\nimport kotlin.collections.HashMap\r\nimport kotlin.math.max\r\n\r\nclass MyReader(inputStream: InputStream) {\r\n private val reader = BufferedReader(InputStreamReader(inputStream))\r\n private var tokenizer: StringTokenizer? = null\r\n\r\n fun next(): String {\r\n while (true) {\r\n tokenizer.let {\r\n if (it == null || !it.hasMoreTokens()) {\r\n tokenizer = StringTokenizer(reader.readLine())\r\n } else {\r\n return it.nextToken()\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\nval reader = MyReader(System.`in`)\r\nfun next() = reader.next()\r\nfun nextInt() = next().toInt()\r\nfun nextLong() = next().toLong()\r\nfun nextDouble() = next().toDouble()\r\nfun nextStrings(n: Int) = Array(n) { next() }\r\nfun nextInts(n: Int) = Array(n) { nextInt() }\r\nfun nextLongs(n: Int) = Array(n) { nextLong() }\r\nfun nextDoubles(n: Int) = Array(n) { nextDouble() }\r\n\r\nclass Node {\r\n val e = IntArray(26) { -1 }\r\n var word = false\r\n}\r\n\r\nconst val MOD = 998244353\r\n\r\nfun mul(a: Array, b: Array, c: Array) {\r\n val n = a.size\r\n val k = b.size\r\n val m = b[0].size\r\n for (i in 0 until n) {\r\n for (j in 0 until m) {\r\n var x = 0L\r\n for (q in 0 until k) {\r\n x = (x + a[i][q].toLong() * b[q][j].toLong()) % MOD\r\n }\r\n c[i][j] = x.toInt()\r\n }\r\n }\r\n}\r\n\r\nfun identity(n: Int) = Array(n) { i -> IntArray(n) { j -> if (i == j) 1 else 0 } }\r\n\r\nfun pow(a: Array, b: Int): Array {\r\n var r = identity(a.size)\r\n var r2 = identity(a.size)\r\n var aa = a\r\n var aa2 = identity(a.size)\r\n var bb = b\r\n while (true) {\r\n if (bb and 1 == 1) {\r\n mul(r, aa, r2)\r\n r = r2.also { r2 = r }\r\n }\r\n bb = bb shr 1\r\n if (bb == 0) break\r\n mul(aa, aa, aa2)\r\n aa = aa2.also { aa2 = aa }\r\n }\r\n return r\r\n}\r\n\r\nfun main() {\r\n val (words, len) = nextInts(2)\r\n val vs = mutableListOf(Node())\r\n repeat(words) {\r\n val s = next()\r\n var v = 0\r\n for (cc in s) {\r\n val c = cc - 'a'\r\n if (vs[v].e[c] == -1) {\r\n vs[v].e[c] = vs.size\r\n vs.add(Node())\r\n }\r\n v = vs[v].e[c]\r\n }\r\n vs[v].word = true\r\n }\r\n\r\n val n = vs.size\r\n val a = Array(n * n) { i ->\r\n val row = IntArray(n * n) { 0 }\r\n val v1 = i % n\r\n val v2 = i / n\r\n for (c in 0 until 26) {\r\n var u1 = vs[v1].e[c].takeIf { it != -1 } ?: continue\r\n var u2 = vs[v2].e[c].takeIf { it != -1 } ?: continue\r\n if (u1 > u2) u1 = u2.also { u2 = u1 }\r\n row[u1 + u2 * n]++\r\n if (vs[u1].word) row[u2 * n]++\r\n if (vs[u2].word) row[u1 * n]++\r\n if (vs[u1].word && vs[u2].word) row[0]++\r\n }\r\n row\r\n }\r\n val vis1 = BooleanArray(n * n) { false }\r\n val vis2 = BooleanArray(n * n) { false }\r\n val ll = mutableListOf()\r\n fun dfs1(v: Int) {\r\n if (vis1[v]) return\r\n vis1[v] = true\r\n (0 until n * n).filter { a[v][it] != 0 }.forEach(::dfs1)\r\n }\r\n fun dfs2(v: Int) {\r\n if (vis2[v]) return\r\n vis2[v] = true\r\n if (vis1[v]) ll.add(v)\r\n (0 until n * n).filter { a[it][v] != 0 }.forEach(::dfs2)\r\n }\r\n dfs1(0)\r\n dfs2(0)\r\n val b = Array(ll.size) { i ->\r\n IntArray(ll.size) { j ->\r\n a[ll[i]][ll[j]]\r\n }\r\n }\r\n println(pow(b, len)[0][0])\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["brute force", "data structures", "matrices", "strings", "dp"], "code_uid": "384d83e78b436622172366b3d6610fdc", "src_uid": "711d15e11016d0164fb2b0c3756e4857", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "//region TEMPLATE\r\n@file:Suppress(\"CanBeVal\")\r\n\r\nimport java.io.*;\r\nimport java.io.BufferedReader\r\nimport java.lang.Exception\r\nimport java.util.*\r\n\r\nfun main(args: Array) {\r\n if (args.isNotEmpty() && args.first() == \"file\") {\r\n out = PrintWriter(FileWriter(\"output.txt\"))\r\n reader = BufferedReader(FileReader(\"input.txt\"))\r\n do {\r\n solve()\r\n out.println(\"\\n\")\r\n out.flush()\r\n } while (reader.readLine() != null)\r\n } else {\r\n reader = BufferedReader(InputStreamReader(System.`in`))\r\n out = PrintWriter(OutputStreamWriter(System.out))\r\n solve()\r\n }\r\n reader.close()\r\n out.close()\r\n}\r\n\r\nlateinit var out: PrintWriter\r\nlateinit var reader: BufferedReader\r\nvar tokenizer: StringTokenizer? = null\r\nfun read(): String {\r\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\r\n tokenizer = StringTokenizer(readLn())\r\n }\r\n return tokenizer!!.nextToken()\r\n}\r\n\r\nfun readInt() = read().toInt()\r\nfun readLong() = read().toLong()\r\nfun readLn() = reader.readLine()!!\r\nfun readInts() = readLn().split(\" \").map { it.toInt() }\r\nfun readInts(sz: Int) = Array(sz) { readInt() }\r\nfun readLongs() = readLn().split(\" \").map { it.toLong() }\r\nfun readLongs(sz: Int) = Array(sz) { readLong() }\r\nfun print(b: Boolean) = out.print(b)\r\nfun print(i: Int) = out.print(i)\r\nfun print(d: Double) = out.print(d)\r\nfun print(l: Long) = out.print(l)\r\nfun print(s: String) = out.print(s)\r\nfun print(message: Any?) = out.print(message)\r\nfun print(a: Array) = a.forEach { print(\"$it \") }\r\nfun print(a: Array) = a.forEach { print(\"$it \") }\r\nfun print(a: Collection) = a.forEach { print(\"$it \") }\r\nfun println(b: Boolean) = out.println(b)\r\nfun println(i: Int) = out.println(i)\r\nfun println(d: Double) = out.println(d)\r\nfun println(l: Long) = out.println(l)\r\nfun println(s: String) = out.println(s)\r\nfun println() = out.println()\r\nfun println(message: Any?) = out.println(message)\r\nfun println(a: Array) {\r\n a.forEach { print(\"$it \") }\r\n println()\r\n}\r\n\r\nfun println(a: IntArray) {\r\n a.forEach { print(\"$it \") }\r\n println()\r\n}\r\n\r\nfun println(a: Collection) {\r\n a.forEach { print(\"$it \") }\r\n println()\r\n}\r\n\r\nconst val M7 = 1000000007L\r\nconst val M9 = 1000000009L\r\nconst val MFFT = 998244353L\r\nfun zero(sz: Int) = IntArray(sz)\r\nfun zeroL(sz: Int) = LongArray(sz)\r\nfun init(vararg elements: T) = elements\r\nfun VI(n: Int = 0, init: Int = 0) = MutableList(n) { init }\r\nfun VVI(n: Int = 0, m: Int = 0, init: Int = 0) = MutableList(n) { VI(m, init) }\r\nfun , T2 : Comparable> pairCmp(): Comparator> {\r\n return Comparator { a, b ->\r\n val res = a.first.compareTo(b.first)\r\n if (res == 0) a.second.compareTo(b.second) else res\r\n }\r\n}\r\n//endregion\r\n\r\n\r\nfun solve() {\r\n var (n, m) = readInts(2)\r\n var a = Array(n) { read() }\r\n var p = mutableListOf>()\r\n for (i in a.indices) {\r\n for (j in a[i].indices) {\r\n p.add(Pair(i, j))\r\n }\r\n }\r\n data class State(val i1: Int, val j1: Int, val i2: Int, val j2: Int)\r\n\r\n var st = mutableListOf()\r\n for ((i1, j1) in p) {\r\n for ((i2, j2) in p) {\r\n var ok = i1 <= i2\r\n for (d in -5..5) {\r\n if (j1 + d in a[i1].indices && j2 + d in a[i2].indices) {\r\n ok = ok && a[i1][j1 + d] == a[i2][j2 + d]\r\n }\r\n }\r\n if (ok) {\r\n st.add(State(i1, j1, i2, j2))\r\n }\r\n }\r\n }\r\n\r\n fun canBeNext(i1: Int, j1: Int, i2: Int, j2: Int): Boolean {\r\n if (j1 + 1 == a[i1].length) return j2 == 0\r\n return i1 == i2 && j1 + 1 == j2\r\n }\r\n\r\n var k = st.size\r\n var matrix = Array(k) { LongArray(k) }\r\n var start = -1\r\n for (i in st.indices) {\r\n if (st[i].j1 + 1 == a[st[i].i1].length && st[i].j2 + 1 == a[st[i].i2].length) {\r\n start = i\r\n }\r\n for (j in st.indices) {\r\n if (canBeNext(st[i].i1, st[i].j1, st[j].i1, st[j].j1) &&\r\n canBeNext(st[i].i2, st[i].j2, st[j].i2, st[j].j2)\r\n ) {\r\n matrix[i][j] += 1L\r\n }\r\n if (st[j].i1 != st[j].i2 &&\r\n canBeNext(st[i].i1, st[i].j1, st[j].i2, st[j].j2) &&\r\n canBeNext(st[i].i2, st[i].j2, st[j].i1, st[j].j1)\r\n ) {\r\n matrix[i][j] += 1L\r\n }\r\n }\r\n }\r\n\r\n var add = Long.MAX_VALUE % MFFT + 1\r\n var add2 = (add + add) % MFFT\r\n\r\n\r\n var ans = LongArray(k)\r\n ans[start] = 1\r\n var nextMatrix = Array(k) { LongArray(k) }\r\n\r\n var iter = 0\r\n while (true) {\r\n if ((m and 1) == 1) {\r\n var nextAns = LongArray(matrix.size)\r\n for (i in 0 until k) {\r\n var cnt = 0\r\n for (j in 0 until k) {\r\n var prod = ans[j] * matrix[j][i]\r\n nextAns[i] += prod\r\n if (nextAns[i] in 0 until prod) cnt++\r\n }\r\n if (nextAns[i] < 0L) {\r\n nextAns[i] = -(Long.MIN_VALUE - nextAns[i]) + add\r\n }\r\n nextAns[i] = (nextAns[i] + cnt * add2) % MFFT\r\n\r\n }\r\n ans = nextAns\r\n }\r\n m /= 2\r\n if (m == 0) break\r\n for (i in 0 until k) {\r\n for (j in 0 until k) {\r\n if (iter > 8 && matrix[i][j] == 0L) continue\r\n var cnt = 0\r\n for (z in 0 until k) {\r\n var prod = matrix[i][z] * matrix[z][j]\r\n nextMatrix[i][j] += prod\r\n if (nextMatrix[i][j] in 0 until prod) cnt++\r\n }\r\n if (nextMatrix[i][j] < 0L) {\r\n nextMatrix[i][j] = -(Long.MIN_VALUE - nextMatrix[i][j]) + add\r\n }\r\n nextMatrix[i][j] = (nextMatrix[i][j] + cnt * add2) % MFFT\r\n }\r\n }\r\n for (i in 0 until k) {\r\n for (j in 0 until k) {\r\n matrix[i][j] = nextMatrix[i][j]\r\n nextMatrix[i][j] = 0\r\n }\r\n }\r\n iter++\r\n }\r\n var sm = 0L\r\n for (i in st.indices) {\r\n if (st[i].j1 + 1 == a[st[i].i1].length && st[i].j2 + 1 == a[st[i].i2].length) {\r\n sm += ans[i]\r\n }\r\n }\r\n println(sm % MFFT)\r\n\r\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "data structures", "matrices", "strings", "dp"], "code_uid": "796a5fc453078c70e90ad85d48fb571d", "src_uid": "711d15e11016d0164fb2b0c3756e4857", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nconst val MOD = 998244353L\n\nfun main() {\n val (n, m) = readLine()!!.split(\" \").map { it.toInt() }\n val words = Array(n) { readLine()!! }\n val position = Array(5) { Array(5) { IntArray(n) } }\n var ix = 0\n for (a in 0..4) {\n for (b in 0..4) {\n for (j in 0 until n) {\n if (a <= b) {\n position[a][b][j] = ix\n ix++\n }\n }\n }\n }\n val transition = Array(30) { Array(ix) { LongArray(ix) } }\n for (a in 0..4) {\n for (b in 0..4) {\n for (j in 0 until n) {\n if (a <= b && b - a <= words[j].length) {\n val x = position[a][b][j]\n val rem = words[j].substring(words[j].length - (b - a))\n if (b == 4) {\n for (k in 0 until n) {\n if (words[k].startsWith(rem) || rem.startsWith(words[k])) {\n if (a == 4) {\n for (k2 in 0 until n) {\n if (words[k].startsWith(words[k2]) || words[k2].startsWith(words[k])) {\n val u = 5 - words[k].length\n val v = 5 - words[k2].length\n transition[0][x][position[min(u, v)][max(u, v)][if (words[k].length > words[k2].length) k else k2]]++\n }\n }\n } else {\n val c = a + 1\n val d = 5 - words[k].length\n transition[0][x][position[min(c, d)][max(c, d)][if (c < d) j else k]]++\n }\n }\n }\n } else {\n transition[0][x][position[a + 1][b + 1][j]]++\n }\n }\n }\n }\n }\n for (d in 1..29) {\n transition[d] = multiply(transition[d - 1], transition[d - 1])\n }\n var vector = Array(1) { LongArray(ix) }\n vector[0][position[0][0][0]] = 1L\n for (d in 0..29) {\n if ((m + 4) and (1 shl d) != 0) {\n vector = multiply(vector, transition[d])\n }\n }\n var answer = 0L\n for (j in 0 until n) {\n answer += vector[0][position[4][4][j]]\n }\n answer %= MOD\n println(answer)\n}\n\nfun multiply(a: Array, b: Array): Array {\n val res = Array(a.size) { LongArray(b[0].size) }\n for (j in a.indices) {\n for (k in b.indices) {\n for (l in b[0].indices) {\n res[j][l] += a[j][k] * b[k][l]\n res[j][l] %= MOD\n }\n }\n }\n return res\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "data structures", "matrices", "strings", "dp"], "code_uid": "47661615513605b809c148f296a83a1c", "src_uid": "711d15e11016d0164fb2b0c3756e4857", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.io.*\r\nimport java.util.*\r\nimport kotlin.system.measureTimeMillis\r\n\r\n// @formatter:off\r\n\r\nval local = System.getProperty(\"ONLINE_JUDGE\") == null\r\n//val local = false\r\n\r\nval INPUT: InputStream = if (local) FileInputStream(\"input.txt\") else System.`in`\r\n//val INPUT: InputStream = System.`in`\r\n\r\n//val OUTPUT: PrintStream = if (local) PrintStream(\"output.txt\") else System.out\r\nval OUTPUT: PrintStream = System.out\r\n\r\nval _reader = INPUT.bufferedReader()\r\nvar _tokenizer = StringTokenizer(\"\")\r\n\r\nfun readLine(): String? = _reader.readLine()\r\nfun readLn() = _reader.readLine()!!\r\nfun read(): String {\r\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\r\n return _tokenizer.nextToken()\r\n}\r\n\r\nfun readInt() = read().toInt()\r\nfun readDouble() = read().toDouble()\r\nfun readLong() = read().toLong()\r\nfun readStrings(n: Int) = List(n) { read() }\r\nfun readLines(n: Int) = List(n) { readLn() }\r\nfun readInts(n: Int) = List(n) { read().toInt() }\r\nfun readStrings() = readLn().split(\" \")\r\nfun readInts() = readStrings().map { it.toInt() }\r\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\r\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\r\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\r\nfun readLongs(n: Int) = List(n) { read().toLong() }\r\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\r\nfun PrintWriter.yesNo(p: Boolean) {\r\n if (p) this.println(\"YES\") else this.println(\"NO\")\r\n}\r\n\r\n@JvmField\r\nval _writer = PrintWriter(OUTPUT, true)\r\n// @formatter:on\r\n\r\nval MOD = 998244353\r\n\r\nfun mul(a: Array, b: Array): Array {\r\n val n = a.size\r\n val res = Array(n) { IntArray(n) { 0 } }\r\n\r\n for (i in 0 until n) {\r\n for (j in 0 until n) {\r\n for (k in 0 until n) {\r\n res[i][j] += ((a[i][k].toLong() * b[k][j].toLong()) % MOD).toInt()\r\n if (res[i][j] >= MOD) {\r\n res[i][j]-=MOD\r\n }\r\n }\r\n }\r\n }\r\n\r\n return res\r\n}\r\n\r\nfun pow(a: Array, k: Int): Array {\r\n if (k == 1) {\r\n return a\r\n }\r\n\r\n var res = pow(a, k / 2)\r\n res = mul(res, res)\r\n if (k % 2 == 1) {\r\n res = mul(res, a)\r\n }\r\n return res\r\n}\r\n\r\n\r\nfun solve(src: List, m: Int): Int {\r\n val kids = mutableListOf(IntArray(26) { -1 })\r\n val word = mutableListOf(\"\")\r\n val end = mutableListOf(true)\r\n\r\n for (w in src) {\r\n var u = 0\r\n var t = \"\"\r\n for (_c in w) {\r\n t += _c\r\n val c = _c - 'a'\r\n if (kids[u][c] == -1) {\r\n kids[u][c] = kids.size\r\n kids.add(IntArray(26) { -1 })\r\n word.add(\"\")\r\n end.add(false)\r\n }\r\n u = kids[u][c]\r\n word[u] = t\r\n }\r\n end[u] = true\r\n }\r\n\r\n val stateId = mutableMapOf, Int>()\r\n val nodesByState = mutableListOf>()\r\n\r\n for (i in kids.indices) {\r\n for (j in kids.indices) {\r\n if ((word[i]!!.endsWith(word[j]!!)\r\n || word[j]!!.endsWith(word[i]!!))\r\n && (j >= i)\r\n ) {\r\n stateId[i to j] = stateId.size\r\n nodesByState.add(i to j)\r\n }\r\n }\r\n }\r\n\r\n val matr = Array(nodesByState.size) { IntArray(nodesByState.size) }\r\n\r\n fun getState(u: Int, v: Int): Int {\r\n val t =stateId[minOf(u, v) to maxOf(u, v)]\r\n return t!!\r\n }\r\n\r\n for ((state, p) in nodesByState.withIndex()) {\r\n val (u, v) = p\r\n\r\n for (c in 0 until 26) {\r\n if (kids[u][c] == -1 || kids[v][c] == -1) {\r\n continue\r\n }\r\n\r\n val newU = kids[u][c]\r\n val newV = kids[v][c]\r\n\r\n val newState = getState(newU, newV)\r\n\r\n matr[state][newState]++\r\n\r\n if (end[newU]) {\r\n val st = getState(0, newV)\r\n matr[state][st]++\r\n }\r\n\r\n if (end[newV]) {\r\n val st = getState(0, newU)\r\n matr[state][st]++\r\n }\r\n\r\n if (end[newU] && end[newV]) {\r\n matr[state][0]++\r\n }\r\n }\r\n }\r\n\r\n val p = pow(matr, m)\r\n\r\n return p[0][0].toInt()\r\n}\r\n\r\nfun PrintWriter.solve() {\r\n\r\n// val tcs = readInt()\r\n val tcs = 1\r\n for (tc in 1..tcs) {\r\n val n = readInt()\r\n val m = readInt()\r\n val a = Array(n) { read() }\r\n println(solve(a.toList(), m))\r\n }\r\n}\r\n\r\nfun main() {\r\n val elapsedMs = measureTimeMillis {\r\n _writer.solve()\r\n _writer.flush()\r\n }\r\n if (local) {\r\n println(\"\\n\\nelapsed $elapsedMs ms\")\r\n }\r\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "data structures", "matrices", "strings", "dp"], "code_uid": "808be29c0aa3dc932a689a4ef0d405fe", "src_uid": "711d15e11016d0164fb2b0c3756e4857", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.io.PrintWriter\nimport java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val out = PrintWriter(System.out)\n solve(scanner, out)\n out.close()\n}\n\nprivate fun solve(scanner : Scanner, out: PrintWriter) {\n val n = scanner.nextLong()\n val k = scanner.nextInt()\n val firstHalf = mutableListOf()\n val secondHalf = mutableListOf()\n val limit = Math.sqrt(n.toDouble()).toLong()\n (1..limit)\n .asSequence()\n .filter { n % it == 0L }\n .forEach {\n if (n / it == it) {\n firstHalf += it\n } else {\n firstHalf += it\n secondHalf += n / it\n }\n }\n val divisors = firstHalf + secondHalf.reversed()\n if (divisors.size >= k) {\n out.println(divisors[k - 1])\n }\n else {\n out.println(-1)\n }\n\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "463984046a0fd576800d8284b9687a98", "src_uid": "6ba39b428a2d47b7d199879185797ffb", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.sqrt\n\nfun main() {\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n fun Long.factors(): MutableSet {\n val output = mutableSetOf()\n val endLoop = sqrt(this.toDouble()).toLong()\n for (i in 1L..endLoop) {\n if (this % i == 0L) {\n output.add(i)\n output.add(this / i)\n }\n }\n return output\n }\n\n val (n, k) = readLongs()\n val factors = n.factors().sorted()\n print(if (factors.size < k) -1 else factors[k.toInt() - 1])\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "a637ba2ef4f0dbe26dceeaae8d487512", "src_uid": "6ba39b428a2d47b7d199879185797ffb", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val args = readStrings().iterator()\n val n = args.next().toLong()\n val k = args.next().toInt()\n\n val ans = n.divisors().elementAtOrElse(k-1) { -1 }\n\n println(ans)\n}\n\nfun Long.divisors() = sequence {\n val n = this@divisors\n if(n <= 0) return@sequence\n val tail = mutableListOf()\n\n for(p in 1..Long.MAX_VALUE) {\n val sq = p * p\n if(sq > n) break\n if(n % p == 0L) {\n yield(p)\n if(sq != n) tail.add(n / p)\n }\n }\n\n yieldAll(tail.asReversed())\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() }", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "16c3e13210220218fa39df13aeb9471f", "src_uid": "6ba39b428a2d47b7d199879185797ffb", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.nextLong()\n var k = read.nextInt()\n var a = Vector()\n for (i in 1 .. sqrt(n.toDouble()).toLong()){\n if (n%i != 0L) continue\n if (i * i == n){\n a.add(i)\n }\n else{\n a.add(i)\n a.add(n / i)\n }\n }\n a.sort()\n print(if (k > a.size) -1 else a[k - 1])\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "d9a8fd04d7f78008380d60213b706042", "src_uid": "6ba39b428a2d47b7d199879185797ffb", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n var s = \"\"\n do {\n s = readLine()!!\n } while (s.length != n)\n val r = s.replace(\"UR|RU\".toRegex(), \"D\")\n println(r.length)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "94f5ebcac32db0e5e423873d6e17055b", "src_uid": "986ae418ce82435badadb0bd5588f45b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 i = 0\n var ans = n\n while (i + 1 < n) {\n if (s[i] == 'R' && s[i + 1] == 'U' || s[i] == 'U' && s[i + 1] == 'R') {\n ans--\n i++\n }\n i++\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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d9136e313628611a293c039a8526fb54", "src_uid": "986ae418ce82435badadb0bd5588f45b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n\nfun main(args: Array) {\n val toInt = readLine()!!.toInt()\n var previous = 'D'\n var count = 0\n val readLine = readLine()!!\n readLine.forEach { c ->\n previous = if (previous != 'D' && c != previous) {\n count++\n 'D'\n } else {\n c\n }\n }\n println(readLine.length - count)\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8f567b221f00c516c7b8529773d1c8d6", "src_uid": "986ae418ce82435badadb0bd5588f45b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLn().toBigInteger(2).dec()\n \n val ans = (s.bitLength() + 1) / 2\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 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 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() }", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "663e2d6d831e6ec64bc2d4c8e7ba0d8d", "src_uid": "d8ca1c83b431466eff6054d3b422ab47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.math.BigInteger\n\nfun main() {\n val s = readLine()!!\n val a = BigInteger(s, 2)\n val k = a.toString(4).toString().length\n val n = BigInteger.valueOf(4).pow((k - 1))\n if (n >= a) {\n println(k - 1)\n } else {\n println(k)\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "9a023ff1b50c6b7449b0f56b7a67db29", "src_uid": "d8ca1c83b431466eff6054d3b422ab47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(){\n val s=readLine()!!\n var has = false\n var res=s.length\n for(i in 1..s.length-1){\n if(s[i]=='1')\n has=true\n }\n if(has)res++\n res/=2\n println(res)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "a53a131ff78d65be9918764ce577afa3", "src_uid": "d8ca1c83b431466eff6054d3b422ab47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n//Ismail moussi\n\n//fun convertBinaryToDecimal(num: Long): Int {\n// var num = num\n// var decimalNumber = 0\n// var i = 0\n// var remainder: Long\n//\n// while (num.toInt() != 0) {\n// remainder = num % 10\n// num /= 10\n// decimalNumber += (remainder * Math.pow(2.0, i.toDouble())).toInt()\n// ++i\n// }\n// return decimalNumber\n//}\n//fun main()\n//{\n// var s:Long= readLine()!!.toLong()\n// var count=0\n// var decimal = convertBinaryToDecimal(s)\n// var e=decimal\n// while(decimal>0)\n// {\n//\n// decimal/=4\n// count+=1\n//\n// }\n// print(count)\n//}\nfun main()\n{\n var s:String= readLine()!!.toString()\n var l=s.length\n for(i in 1.. s.length-1)\n {\n if(s[i]=='1')\n {\n l++;\n break;\n }\n }\n print(l/2)\n\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "d427fcb784ee4fe88c2b4db78b6ef10d", "src_uid": "d8ca1c83b431466eff6054d3b422ab47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun canMakeTriangle(x: Int, y: Int, z: Int) = (x + y > z && x + z > y && y + z > x)\nfun canMakeSegment(x: Int, y: Int, z: Int) = (x + y == z || x + z == y || y + z == x)\n\nfun main(args: Array) {\n val lines = readLine()!!.split(\" \").map { it.toInt() }\n\n lines.forEach {\n val tr = lines.minus(it)\n if (canMakeTriangle(tr[0], tr[1], tr[2])) {\n println(\"TRIANGLE\")\n return\n }\n }\n\n lines.forEach {\n val tr = lines.minus(it)\n if (canMakeSegment(tr[0], tr[1], tr[2])) {\n println(\"SEGMENT\")\n return\n }\n }\n\n println(\"IMPOSSIBLE\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "geometry"], "code_uid": "05bccb73973aeab695bfbb913e8baf9b", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n var list = readLine()!!.split(\" \").map { it.toInt() }.sorted()\n if ((list[2] < list[0] + list[1]) || (list[3] < list[1] + list[2])) {\n println(\"TRIANGLE\")\n return\n }\n if ((list[0] + list[1] == list[2]) || list[0] + list[1] == list[3] || list[1] + list[2] == list[3] || list[0] + list[2] == list[3]){\n println(\"SEGMENT\")\n }else{\n println(\"IMPOSSIBLE\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "geometry"], "code_uid": "a3864e94bf941d6a91e0923123d2db2a", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args : Array)\n{\n val arr : MutableList = readLine()!!.split(' ').map { it.toInt() } as MutableList\n for(i in 0 until 3)\n {\n for(j in 0 until 4-i-1)\n {\n if(arr[j]>arr[j+1])\n {\n val temp = arr[j]\n arr[j]=arr[j+1]\n arr[j+1]=temp\n }\n }\n }\n var flag : Int = 0\n for(i in 0 until 2)\n {\n if(arr[i]+arr[i+1]>arr[i+2])\n {\n flag = 1\n }\n if(arr[i]+arr[i+1]==arr[i+2] && flag==0)\n {\n flag = 2\n }\n }\n if(flag==0)\n {\n println(\"IMPOSSIBLE\")\n }\n else if(flag==2)\n {\n println(\"SEGMENT\")\n }\n else\n {\n println(\"TRIANGLE\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "geometry"], "code_uid": "f372ea1a1772709a84ef851b8257a287", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun readInts() = readLine()!!.split(' ').map { it.toInt() }\n\nfun a6() {\n val list: List = readInts().sortedDescending()\n\n if (list[1] + list[2] > list[0] || list[2] + list[3] > list[0] || list[1] + list[3] > list[0] || list[2] + list[3] > list[1])\n print(\"TRIANGLE\")\n else if (list[1] + list[2] == list[0] || list[2] + list[3] == list[0] || list[1] + list[3] == list[0] || list[2] + list[3] == list[1])\n print(\"SEGMENT\")\n else\n print(\"IMPOSSIBLE\")\n}\n\nfun main() {\n a6()\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "geometry"], "code_uid": "9eb2a02abc1011cb2fe2748c2e5a6416", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007\n\nfun main() {\n val line = readLine()!!.split(' ')\n val N = line[0].toInt()\n var M = line[1].toLong() - 1\n val ans = LinkedList()\n ans.add(N)\n for (i in N - 1 downTo 1) {\n if (M % 2 > 0) {\n ans.addLast(i)\n } else {\n ans.addFirst(i)\n }\n M /= 2\n }\n println(ans.joinToString(\" \"))\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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}", "lang_cluster": "Kotlin", "tags": ["math", "divide and conquer", "bitmasks"], "code_uid": "db5bd61293148fbf2d26556ab6cc1dd7", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var k = readLine()!!.toInt()\n var list = readLine()!!.split(\" \").map { it.toInt() }.sortedDescending()\n var sum = 0\n for (i in 0..list.size-1) {\n if (k == 0) {\n return println(0)\n }\n sum+=list[i]\n if (sum>=k){\n println(i+1)\n return\n }\n }\n println(-1)\n\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "6ef74b3233ca7541c02d9c5acc3697cb", "src_uid": "59dfa7a4988375febc5dccc27aca90a8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 var ans = 0\n var acc = 0\n while (acc < k && ans < 12) {\n acc += v[ans++]\n }\n println(if (acc) {\n\n val k = readLine()!!.trim().toInt()\n\n val monthStr = readLine()!!.trim().split(\" \")\n\n if (k == 0){\n println(0)\n return\n }\n\n val month : Array = Array(monthStr.size, {i -> monthStr[i].toInt() })\n\n month.sort()\n\n var len = 0\n var monthCount = 0\n\n for (i in month.size -1 downTo 0 ){\n\n //print(month[i].toString() + \" \")\n\n len += month[i]\n monthCount++\n\n if (len >= k){\n break\n }\n }\n\n //println()\n\n if (len < k){\n println(-1)\n }else{\n println(monthCount)\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "32cba1b1c1e74f93f0aa69c936074373", "src_uid": "59dfa7a4988375febc5dccc27aca90a8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val n = nextInt()\n val tablica = IntArray(12, { nextInt() }).sortedArrayDescending()\n var sum = 0\n var res = 0\n tablica.forEach { when { sum >= n -> return@forEach else -> { sum += it; ++res} }}\n when { sum >= n -> print(res) else -> print(-1)}\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "21d0167fc8bba0f19e3561eed24e5228", "src_uid": "59dfa7a4988375febc5dccc27aca90a8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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_007\n\nfun testBipartite(N: Int, g: Array, D: IntArray): Boolean {\n for (u in 0 until N) {\n for (v in 0 until N) {\n if (!g[u][v]) continue\n if (D[v] % 2 == D[u] % 2) {\n return false\n }\n }\n }\n\n return true\n}\n/**\n * (dist, parent, queue)\n * @param rt \u30eb\u30fc\u30c8\u30ce\u30fc\u30c9\u3092\u6307\u5b9a\u3059\u308b\u3002null\u306e\u5834\u5408\u306f\u5168\u30ce\u30fc\u30c9\u8fbf\u308b\u307e\u3067\u7e70\u308a\u8fd4\u3059\n */\nfun traceBfs(g: Array): Array? {\n val n = g.size\n val q = IntArray(n)\n val d = IntArray(n)\n val p = IntArray(n){-2}\n var h = 0\n var t = 0\n\n fun bfs(rt: Int) {\n p[rt] = -1\n q[t++] = rt\n d[rt] = 0\n while (h < t) {\n val u = q[h++]\n for (v in 0 until n) {\n if (!g[u][v]) continue\n if (p[v] == -2) {\n p[v] = u\n q[t++] = v\n d[v] = d[u] + 1\n }\n }\n }\n }\n\n var traced = false\n for (u in 0 until n) {\n if (g[u].all{!it}) continue\n if (p[u] != -2) continue\n if (traced) return null\n bfs(u)\n traced = true\n }\n return arrayOf(d, p, q)\n}\nfun packUGraph(n: Int, from: IntArray, to: IntArray): Array {\n val p = IntArray(n)\n val m = from.size\n for (i in 0 until m) {\n ++p[from[i]]\n ++p[to[i]]\n }\n val g = Array(n){IntArray(p[it])}\n for (i in 0 until m) {\n g[from[i]][--p[from[i]]] = to[i]\n g[to[i]][--p[to[i]]] = from[i]\n }\n return g\n}\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n\n private val N = ni()\n private val M = ni()\n fun solve() {\n if (!solve2()) {\n out.println(\"No\")\n }\n }\n\n fun solve2(): Boolean {\n val g = Array(N){BooleanArray(N){true} }\n for (i in 0 until N) {\n g[i][i] = false\n }\n\n for (i in 0 until M) {\n val u = ni() - 1\n val v = ni() - 1\n g[u][v] = false\n g[v][u] = false\n }\n\n if (isDebug) {\n for (i in 0 until N) {\n debug(g[i])\n }\n }\n\n val (dist, _, _) = traceBfs(g) ?: return false\n if (!testBipartite(N, g, dist)) {\n return false\n }\n\n val ans = CharArray(N)\n for (i in 0 until N) {\n if (g[i].count{it} == 0) {\n ans[i] = 'b'\n } else {\n ans[i] = if (dist[i] % 2 == 0) 'a' else 'c'\n }\n }\n\n for (i in 0 until N) {\n for (j in 0 until N) {\n if (i == j) continue\n abs(ans[i] - ans[j]) <= 1\n if (abs(ans[i] - ans[j]) <= 1 != !g[i][j]) {\n return false\n }\n }\n }\n\n out.println(\"Yes\")\n out.println(ans.joinToString(\"\"))\n return true\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\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 { toString(a) }\n }\n\n private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString(\"\")}\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "graphs"], "code_uid": "481aa046eb20810e497bc72ba47dafa7", "src_uid": "e71640f715f353e49745eac5f72e682a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "faaac87c38ced5646c47684e4769f7e6", "src_uid": "e6b3e787919e96fc893a034eae233fc6", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "aa443944ad65703b2c839fe8645f7f9c", "src_uid": "e6b3e787919e96fc893a034eae233fc6", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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//}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "987d731de60b3d9b22238b4217b80a81", "src_uid": "e6b3e787919e96fc893a034eae233fc6", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "\r\n\r\nimport java.io.BufferedReader\r\nimport java.io.InputStreamReader\r\nimport java.util.*\r\nimport java.util.concurrent.ThreadLocalRandom\r\nimport java.util.function.ToIntFunction\r\nimport kotlin.Comparator\r\nimport kotlin.collections.*\r\nimport kotlin.math.*\r\n\r\nfun readInts(bf: BufferedReader) = bf.readLine()!!.split(\" \").map{ i -> i.toInt() }.toMutableList()\r\nfun readInt(bf: BufferedReader) = bf.readLine()!!.toInt()\r\nfun readLongs(bf: BufferedReader) = bf.readLine()!!.split(\" \").map{ i -> i.toLong() }.toMutableList()\r\nfun readString(bf: BufferedReader) = bf.readLine()!!\r\n\r\ntypealias Ints = MutableList\r\ntypealias Longs = MutableList\r\n\r\nfun main() {\r\n val br = BufferedReader(InputStreamReader(System.`in`))\r\n val t = readInt(br)\r\n repeat(t) {\r\n val (a, b) = readInts(br)\r\n val (c, d) = readInts(br)\r\n if (a + b + c + d == 0) {\r\n println(0)\r\n } else if (a + b + c + d < 4) {\r\n println(1)\r\n } else {\r\n println(2)\r\n }\r\n }\r\n}\r\n\r\nfun a(n: Int) {\r\n if (n % 2 != 0) {\r\n println(-1)\r\n } else {\r\n println(\"0 0 ${n / 2}\")\r\n }\r\n}\r\n\r\n\r\n\r\n\r\ntypealias IntPair = Pair\r\n\r\nfun List.linearSearch(start: Int = 0, end: Int = size - 1): IntPair {\r\n var max = Int.MIN_VALUE\r\n var maxI = 0\r\n for (i in start..end) {\r\n if (this[i] > max) {\r\n max = this[i]\r\n maxI = i\r\n }\r\n }\r\n\r\n return maxI to max\r\n}\r\n\r\nfun MutableList.sumLong(): Long {\r\n var sum = 0L\r\n for (i in this) {\r\n sum += i\r\n }\r\n\r\n return sum\r\n}\r\nfun Collection<*>.jointWithWhitespace() = joinToString(separator = \" \")\r\n\r\nfun IntArray.joinWithWhitespace() = joinToString(separator = \" \")\r\n\r\nfun List.lastOrDefault(defValue: T) = if(isEmpty()) defValue else last()\r\n\r\nfun MutableList.swap(firstIndex: Int, secondIndex: Int) {\r\n val temp = this[secondIndex]\r\n this[secondIndex] = this[firstIndex]\r\n this[firstIndex] = temp\r\n}\r\n\r\nfun List.groupByCounting(): HashMap {\r\n val map = HashMap()\r\n for (i in this) {\r\n map[i] = map.getOrDefault(i, 0) + 1\r\n }\r\n\r\n return map\r\n}\r\n\r\nfun List.prefixSum(): ArrayList {\r\n val p = ArrayList(this.size + 1)\r\n p.add(0L)\r\n for (i in this) {\r\n p.add(p.last() + i)\r\n }\r\n\r\n return p\r\n}\r\n\r\nprivate val random = ThreadLocalRandom.current()\r\n\r\nprivate class MutablePair(var first: F, var second: S)\r\n\r\nfun List.binarySearchFirst(key: Int, start: Int = 0, end: Int = size - 1): Int {\r\n var mid = (start + end) / 2\r\n var l = start\r\n var r = end\r\n while (l <= r) {\r\n mid = (r + l) / 2\r\n if (this[mid] == key && (mid == start || this[mid - 1] < key)) {\r\n return mid\r\n } else if (this[mid] >= key) {\r\n r = mid - 1\r\n } else {\r\n l = mid + 1\r\n }\r\n }\r\n\r\n return if(this[mid] == key) mid else 0 - mid - 1\r\n}\r\n\r\nfun List.binarySearchLast(key: Int, start: Int = 0, end: Int = size - 1): Int {\r\n var mid = (start + end) / 2\r\n var l = start\r\n var r = end\r\n while (l <= r) {\r\n mid = (r + l) / 2\r\n if (this[mid] == key && (mid == end || this[mid + 1] > key)) {\r\n return mid\r\n } else if(this[mid] == key && this[mid + 1] == key) {\r\n l = mid + 1\r\n } else if (this[mid] > key) {\r\n r = mid - 1\r\n } else {\r\n l = mid + 1\r\n }\r\n }\r\n\r\n return if(this[mid] == key) mid else 0 - mid - 1\r\n}\r\n\r\nfun List.binarySearchLastLong(key: Long, start: Int = 0, end: Int = size - 1): Int {\r\n var mid = (start + end) / 2\r\n var l = start\r\n var r = end\r\n while (l <= r) {\r\n mid = (r + l) / 2\r\n if (this[mid] == key && (mid == end || this[mid + 1] > key)) {\r\n return mid\r\n } else if(this[mid] == key && this[mid + 1] == key) {\r\n l = mid + 1\r\n } else if (this[mid] > key) {\r\n r = mid - 1\r\n } else {\r\n l = mid + 1\r\n }\r\n }\r\n\r\n return if(this[mid] == key) mid else 0 - mid - 1\r\n}\r\n\r\nfun generateRandomArray(size: Int, bound: Int): IntArray {\r\n val a = IntArray(size)\r\n for (i in 0 until size) {\r\n a[i] = random.nextInt(bound)\r\n }\r\n\r\n return a\r\n}\r\n\r\nfun List.isAscending(): Boolean {\r\n for (i in 0 until size - 1) {\r\n if (this[i] >= this[i + 1]) {\r\n return false\r\n }\r\n }\r\n\r\n return true\r\n}\r\n\r\nfun List.isNotDecreasing(comp: Comparator): Boolean {\r\n for (i in 0 until size - 1) {\r\n if (comp.compare(this[i], this[i + 1]) == 1) {\r\n return false\r\n }\r\n val a = 1\r\n Comparator.comparingInt(ToIntFunction { i -> i })\r\n }\r\n\r\n return true\r\n}\r\n\r\nfun sieve(bound: Int): List {\r\n val result = ArrayList()\r\n for (i in 2..bound) {\r\n result.add(i)\r\n }\r\n for (i in 2..bound) {\r\n for (j in i + i..bound step i) {\r\n result[j - 2] = -1\r\n }\r\n }\r\n return result\r\n}\r\n\r\nfun readArr(N: Int, infile: BufferedReader, st: StringTokenizer): ArrayList {\r\n var st = st\r\n val arr = ArrayList()\r\n st = StringTokenizer(infile.readLine())\r\n for (i in 0 until N) arr.add(st.nextToken().toInt())\r\n\r\n return arr\r\n}\r\n\r\nfun fundSum(p: List, l: Int = 0, r: Int = p.size - 1): Long {\r\n return p[r] - p[l]\r\n}\r\n\r\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "0345d0af3c6b59d10704aa56eb6afe3b", "src_uid": "7336b8becd2438f0439240ee8f9610ec", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.5", "source_code": "\r\n\r\nimport java.io.PrintWriter\r\nimport java.util.Stack\r\nimport java.util.StringTokenizer\r\nimport kotlin.math.abs\r\nimport kotlin.math.max\r\n\r\nfun solveOneTask() {\r\n val n = 2\r\n val res = StringBuffer()\r\n val a = readInts(n)\r\n val b = readInts(n)\r\n if (a.contains(0) || b.contains(0)) {\r\n if (a.count { it == 0 } == 2 && b.count { it == 0 } == 2) println(0)\r\n else println(1)\r\n }\r\n else println(2)\r\n \r\n}\r\n\r\nfun main() {\r\n val t = readInt()\r\n repeat(t) {\r\n solveOneTask()\r\n }\r\n}\r\n\r\nfun binarySearch(list: List, value: Int): Int {\r\n var l = -1\r\n var r = list.size\r\n while (r - l > 1) {\r\n val m = (l + r) ushr 1\r\n if (list[m] < value) l = m\r\n else r = m\r\n }\r\n return r\r\n}\r\n\r\nfun nextGreaterElement(list: List): List {\r\n\r\n if (list.isEmpty()) return emptyList()\r\n val stack = Stack>()\r\n stack.push(Pair(list.first(), 0))\r\n val result = MutableList(list.size) { list.size }\r\n for (i in 1 until list.size) {\r\n var prev = stack.peek()\r\n val cur = list[i]\r\n while (prev.first < cur && stack.isNotEmpty()) {\r\n result[prev.second] = i\r\n stack.pop()\r\n if (stack.isNotEmpty()) prev = stack.peek()\r\n }\r\n stack.push(Pair(cur, i))\r\n }\r\n return result\r\n}\r\n\r\ntypealias Number = Long\r\n\r\nfun segmentTreeFunction(a: Number, b: Number): Number = max(a, b)\r\n\r\nfun buildSegmentTree(elements: List): SegmentTreeNode {\r\n val leafs = elements.mapIndexed { ind, it ->\r\n SegmentTreeNode(it, null, ind, ind)\r\n }\r\n var curLevel = leafs\r\n while (curLevel.size > 1) {\r\n val nextLevel = mutableListOf()\r\n for (i in curLevel.indices step 2) {\r\n val node = if (i + 1 < curLevel.size) {\r\n SegmentTreeNode(\r\n segmentTreeFunction(curLevel[i].element, curLevel[i + 1].element),\r\n listOf(curLevel[i], curLevel[i + 1]),\r\n curLevel[i].start,\r\n curLevel[i + 1].finish\r\n )\r\n } else {\r\n SegmentTreeNode(\r\n curLevel[i].element,\r\n listOf(curLevel[i]),\r\n curLevel[i].start,\r\n curLevel[i].finish\r\n )\r\n }\r\n nextLevel.add(node)\r\n }\r\n curLevel = nextLevel\r\n }\r\n return curLevel.first()\r\n}\r\n\r\nclass SegmentTreeNode\r\n (\r\n val element: Number,\r\n val children: List? = null,\r\n val start: Int,\r\n val finish: Int\r\n) {\r\n fun query(l: Int, r: Int): Number {\r\n if (l == start && r == finish) {\r\n return element\r\n }\r\n val left = children!!.first()\r\n if (r <= left.finish) {\r\n return left.query(l, r)\r\n }\r\n val right = children[1]\r\n if (l >= right.start) {\r\n return right.query(l, r)\r\n }\r\n return segmentTreeFunction(left.query(l, left.finish), right.query(right.start, r))\r\n }\r\n}\r\n\r\nfun prefSums(base: Iterable): List {\r\n val prefSums = base.toMutableList()\r\n for (i in 1 until prefSums.size) {\r\n prefSums[i] += prefSums[i - 1]\r\n }\r\n return prefSums\r\n}\r\n\r\n\r\nfun gcd(a: Long, b: Long): Long {\r\n if (a == 0L) return b\r\n return gcd(b % a, a)\r\n}\r\n\r\n/**\r\n * least common multiply\r\n */\r\nfun lcm(a: Long, b: Long): Long {\r\n return abs(a.toLong() * b.toLong()) / gcd(a, b).toLong()\r\n}\r\n\r\nval primes by lazy { generatePrimes(2 * 1000_000).toSet() }\r\n\r\n\r\nfun factorize(x: Int): MutableMap {\r\n val mp = mutableMapOf()\r\n var xx = x\r\n\r\n for (prime in primes) {\r\n var count = 0\r\n while (xx % prime == 0) {\r\n xx /= prime\r\n count++\r\n }\r\n if (count > 0) {\r\n mp[prime] = count\r\n }\r\n if (primes.contains(xx)) {\r\n mp[xx] = 1\r\n break\r\n }\r\n }\r\n return mp\r\n\r\n}\r\n\r\n\r\nfun generatePrimes(n: Int): List {\r\n val prime = Array(n + 1) { true }\r\n var p = 2\r\n while (p * p <= n) {\r\n if (prime[p]) {\r\n var i = p * p\r\n while (i <= n) {\r\n prime[i] = false\r\n i += p\r\n }\r\n }\r\n p++\r\n }\r\n return (2..n).filter { prime[it] }\r\n}\r\n\r\n@JvmField\r\nval INPUT = System.`in`\r\n\r\n@JvmField\r\nval OUTPUT = System.out\r\n\r\n@JvmField\r\nval _reader = INPUT.bufferedReader()\r\n\r\nfun readLine(): String = _reader.readLine()!!\r\nfun readLn(): String? = _reader.readLine()\r\n\r\n@JvmField\r\nvar _tokenizer: StringTokenizer = StringTokenizer(\"\")\r\n\r\nfun read(): String {\r\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\r\n return _tokenizer.nextToken()\r\n}\r\n\r\nfun readInt() = read().toInt()\r\nfun readDouble() = read().toDouble()\r\nfun readLong() = read().toLong()\r\nfun readStrings(n: Int) = List(n) { read() }\r\nfun readLines(n: Int) = List(n) { readLn() }\r\nfun readInts(n: Int) = MutableList(n) { read().toInt() }\r\n\r\n//fun readIntArray(n: Int) = IntArray(n) { read().toInt() }\r\nfun readDoubles(n: Int) = MutableList(n) { read().toDouble() }\r\n\r\n//fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\r\nfun readLongs(n: Int) = MutableList(n) { read().toLong() }\r\n//fun readLongArray(n: Int) = LongArray(n) { read().toLong() }\r\n\r\n@JvmField\r\nval _writer = PrintWriter(OUTPUT, false)\r\n\r\ninline fun output(block: PrintWriter.() -> Unit) {\r\n _writer.apply(block).flush()\r\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "725efaae1a1083c4cefd68b711c65f2f", "src_uid": "7336b8becd2438f0439240ee8f9610ec", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.5", "source_code": "const val yes = \"YES\\n\"\nconst val no = \"NO\\n\"\n\nfun main() {\n val cin = java.util.Scanner(System.`in`)\n val t = cin.nextLong()\n for (i in 0 until t) {\n val mat = MutableList(2) { a -> MutableList(2) { cin.nextLong() } }\n println(solve(mat))\n }\n cin.close()\n}\n\nfun solve(n: MutableList>) : String {\n return if (n[0].contains(1L) || n[1].contains(1)) {\n if (n[0].contains(0L) || n[1].contains(0))\n \"1\"\n else\n \"2\";\n } else {\n \"0\"\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "66ddc90c936c74a630de3f2ad1d4978c", "src_uid": "7336b8becd2438f0439240ee8f9610ec", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "object GrassField {\r\n\r\n fun mySolution(a1: Pair, a2: Pair): Int =\r\n when (a1.first + a1.second + a2.first + a2.second) {\r\n 0 -> 0\r\n 4 -> 2\r\n else -> 1\r\n }\r\n}\r\n\r\nfun main() {\r\n fun readInts() = readln().split(\" \").map(String::toInt)\r\n repeat(readln().toInt()) {\r\n val (a11, a12) = readInts()\r\n val (a21, a22) = readInts()\r\n println(GrassField.mySolution(Pair(a11, a12), Pair(a21, a22)))\r\n }\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "59e8cdea06df640913cb4b67aed0a808", "src_uid": "7336b8becd2438f0439240ee8f9610ec", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "f6201b6494a60274746dcee9214d6e82", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (f,s) = readLine()!!.split(\" \").map { it.toInt() }\n println(if (f > s) \"First\" else \"Second\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "db599a3cc5d060413d1fcc0a820b97eb", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "242b8bdf5858b503b92f42c35df716a6", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "3c9a26273a376256c94d1cdb6e364188", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 k = io.readInt()\n val d = 4 * 60 - k\n for (i in n downTo 0) {\n val t = 5 * i * (i + 1) / 2\n if (t <= d) {\n io.println(i)\n break\n }\n }\n\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation", "binary search"], "code_uid": "ec715bf8ef324fdfba23ac82b4a97ba4", "src_uid": "41e554bc323857be7b8483ee358a35e2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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, k) = readInts()\n val minutes = 240 - k\n\n val ans = (0.rangeTo(n)).toList().binarySearch {\n (it * (it + 1) / 2) * 5 - minutes\n }\n if (ans < 0) {\n println(-ans - 2)\n } else {\n println(ans)\n }\n}\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation", "binary search"], "code_uid": "386ad3ebdf4ff2bc688a06a14d5236cb", "src_uid": "41e554bc323857be7b8483ee358a35e2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.InputStreamReader\nimport java.lang.Math.pow\npublic class c{\n fun ez(){\n var t = 240\n val scaner = java.util.Scanner(InputStreamReader(System.`in`))\n val n = scaner.nextInt()\n val k = scaner.nextInt()\n t-=k\n var i = 1\n while(t>-1&&i<=n+1){\n t-=(5*i)\n i++\n }\n if(i!=1)println(i-2)else println(i-2)\n }\n}\nfun main(args: Array) {\n c().ez()\n}\n///val s = java.util.Scanner(InputStreamReader(System.`in`))", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation", "binary search"], "code_uid": "23cd8c81a530f89f0ec4a9f8ee68ef12", "src_uid": "41e554bc323857be7b8483ee358a35e2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (n, k) = readLine()!!.split(\" \").map(String::toInt)\n k = 240 - k\n var count = 0\n while (count < n && 5 * (count + 1) <= k) {\n count++\n k -= count * 5\n }\n println(count)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation", "binary search"], "code_uid": "39ee5d6385401bec1b8b8a5047b13bd3", "src_uid": "41e554bc323857be7b8483ee358a35e2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val numCandidates = readInt()\n val votes = readInts()\n var limakVotes = votes[0]\n val opponentsVotes = PriorityQueue() { a, b -> b.compareTo(a) }\n opponentsVotes.addAll(votes.subList(1, numCandidates))\n var sol = 0\n while (limakVotes <= opponentsVotes.peek()) {\n sol++\n limakVotes++\n opponentsVotes.add(opponentsVotes.poll() - 1)\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "d199f3abae2718afcd130c3160622dc6", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\n if(n!=2){\n println(1)\n }\n else{\n println(2)\n }\n\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "049035d989c59a104a4c560eddb73459", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array)\n{\n\tvar n= readLine()!!.toInt()\n\n\t\tif(n<=2) { println(n)}\n\t\tif(n>2) { println(1)}\n\t\t}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "39ecb518b858efa285c0f9dd595b400f", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val n = readInt()\n print(if (n == 2) 2 else 1)\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "f4234ce50a6327728cf45dc62568d1c6", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n print(if (readLine()!!.toInt() == 2) 2 else 1)\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "992ca5df618c8f546efae0b68f6acd08", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main(args : Array) {\r\n val t = readLine()!!.trim().toInt()\r\n\r\n repeat(t) {\r\n val x = readLine()!!.trim().toInt()\r\n val max = Math.sqrt(x.toDouble()).toLong()\r\n val ans = HashSet()\r\n\r\n for (i in 1..max) {\r\n ans.add(i * i)\r\n ans.add(i * i * i)\r\n }\r\n\r\n println(ans.filter { it <= x }.size)\r\n }\r\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "acadaceccdbb9ee375739e1970aca7ee", "src_uid": "015afbefe1514a0e18fcb9286c7b6624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "import java.util.*\r\nimport kotlin.math.sqrt\r\n\r\nprivate val scan = Scanner(System.`in`)\r\n\r\nfun main()\r\n{\r\n val input = getInput()\r\n val output = calc(input)\r\n output.forEach {\r\n println(it)\r\n }\r\n}\r\n\r\nprivate fun getInput() : Array\r\n{\r\n val input = Array(scan.nextInt()) {it}\r\n scan.nextLine()\r\n for (i in input.indices)\r\n {\r\n input[i] = scan.nextInt()\r\n }\r\n return input\r\n}\r\n\r\nprivate fun calc(input: Array) : Array\r\n{\r\n val result = Array(input.size) {it}\r\n for (i in input.indices)\r\n {\r\n val caseValue = input[i]\r\n val caseValueSqrt = sqrt(caseValue.toDouble())\r\n val caseValueCbrt = Math.cbrt(caseValue.toDouble())\r\n val caseValueCbrtCbrt = sqrt(caseValueCbrt)\r\n result[i] = caseValueSqrt.toInt() + caseValueCbrt.toInt() - caseValueCbrtCbrt.toInt()\r\n }\r\n return result\r\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "037dcd97e5afa0c811d5c98be3a373e5", "src_uid": "015afbefe1514a0e18fcb9286c7b6624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.5", "source_code": "import java.util.*\r\nimport java.io.*\r\nimport kotlin.collections.*\r\nimport kotlin.math.*\r\n\r\nconst val FILE_IO = false\r\nconst val FILE_IN = \"angle1.in\"\r\nconst val FILE_OUT = \"angle1.out\"\r\n\r\nconst val TESTS = true\r\n\r\n@ExperimentalStdlibApi\r\nfun main() {\r\n if (TESTS) {\r\n presolve()\r\n repeat(ni(), ::solve)\r\n } else\r\n solve()\r\n out.flush()\r\n}\r\n\r\n@ExperimentalStdlibApi\r\nfun presolve () {\r\n\r\n}\r\n\r\n@ExperimentalStdlibApi\r\nfun solve(testIdx : Int = 0) {\r\n val n = ni()\r\n\r\n val res = HashSet()\r\n\r\n var i = 1\r\n while (i * i <= n) {\r\n res.add(i*i)\r\n i++\r\n }\r\n\r\n i = 1\r\n while (i * i * i <= n) {\r\n res.add(i*i*i)\r\n i++\r\n }\r\n\r\n pln(res.size)\r\n}\r\n\r\nfun pln(a : Any = \"\") = out.println(a)\r\nfun pr(a : Any) = out.print(a)\r\nfun ipln(a : Any) {pln(a); out.flush()}\r\n\r\nfun ni() = nstr().toInt()\r\nfun nl() = nstr().toLong()\r\nfun nln() = br.readLine() ?: \"\"\r\nfun nstr() : String {while (!st.hasMoreElements()) st = StringTokenizer(br.readLine() ?: return \"\", \" \"); return st.nextToken()}\r\n\r\nfun IntArray.read() : IntArray {for (i in indices) this[i] = ni(); return this}\r\nfun LongArray.read() : LongArray {for (i in indices) this[i] = nl(); return this}\r\nfun Array.read() : Array {for (i in indices) this[i] = nstr(); return this}\r\n\r\nfun nis(del: String = \" \") = ArrayList(nln().split(del).map {it.toInt()})\r\nfun nls(del: String = \" \") = ArrayList(nln().split(del).map {it.toLong()})\r\nfun nstrs(del: String = \" \") = ArrayList(nln().split(del))\r\n\r\nvar out = PrintWriter(BufferedOutputStream(if (FILE_IO) FileOutputStream(FILE_OUT) else System.out))\r\nval br = BufferedReader(InputStreamReader(if (FILE_IO) FileInputStream(FILE_IN) else System.`in`))\r\nvar st = StringTokenizer(\"\")", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "3087dc6d68ae0203f81b202d30f53884", "src_uid": "015afbefe1514a0e18fcb9286c7b6624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.5", "source_code": "import java.io.BufferedInputStream\r\nimport java.io.BufferedOutputStream\r\nimport java.io.PrintWriter\r\nimport java.util.*\r\n\r\nfun main() {\r\n val sc = Scanner(BufferedInputStream(System.`in`))\r\n val pw = PrintWriter(BufferedOutputStream(System.out))\r\n\r\n repeat(sc.nextInt()) {\r\n val s = mutableSetOf()\r\n val n = sc.nextLong()\r\n\r\n var i: Long = 1\r\n\r\n while (i * i <= n) {\r\n s.add(i * i)\r\n i++\r\n }\r\n\r\n i = 1\r\n\r\n while (i * i * i <= n) {\r\n s.add(i * i * i)\r\n i++\r\n }\r\n\r\n pw.println(s.size)\r\n }\r\n\r\n sc.close()\r\n pw.close()\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "98e61e53d5f4341bf62c144f524d2628", "src_uid": "015afbefe1514a0e18fcb9286c7b6624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (n , m) = readLine()!!.split(' ').map { it.toInt() }\n\n println(doIt(n, m))\n}\n\nfun doIt(n: Int, m: Int): Int {\n if (n == m) return 0\n if (m == 0) return 1\n\n val remaining = n - m\n val adjust = (remaining * 2) - n\n\n if (adjust <= 0) return remaining\n\n return remaining - adjust\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "bd329840a251e90f0f71aaf8e10d1a63", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n// function with Integer value return\nfun sum( a:Int, b:Int ) : Int{\n return a+b\n}\n\n\n// function with void return\nfun printValue( a:Int, b:Int ):Unit{\n println( \"sum of $a and $b is ${a+b}\" )\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\n\nfun main(){\n var(n,k) = readInts();\n var mid = n/2\n if ( k == 0 )\n println(\"1\");\n else if( k <= mid )\n println(\"$k\")\n else{\n var tot = mid\n k-=mid\n if( n % 2 == 1 ) k--\n if(k>0) tot-=k\n println(tot)\n }\n\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "d6859e57e5bebf57ff66e7ef03289655", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 = ir.nextInt()\n val m = ir.nextInt()\n val res: Int\n\n if (m != 0)\n res = Math.min(n - m, m)\n else\n res = 1\n\n pw.print(res)\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}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "29a7cc21db7336a5ecc8d4efa876b079", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val (n, m) = readInts()\n val ans = if(m == 0) 1\n else minOf(m, n-m)\n\n println(ans)\n}\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\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(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", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "b7dbe11c29f6094c335322245fb7656b", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main() {\n readLine()\n var sol = 0\n var visited = mutableSetOf()\n for (c in readLine()!!) {\n if (c.isUpperCase()) visited = mutableSetOf()\n else visited.add(c)\n sol = max(sol, visited.size)\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "a2a611e994bb8b22476cd6ef7bc7f7cf", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main(args: Array) {\n readLine()\n data class Acc(val top: Int, val met: Set)\n readLine()!!.fold(Acc(0, setOf())) { (top, acc), x ->\n when {x.isUpperCase() -> Acc(top, setOf())\n acc.contains(x) -> Acc(top, acc)\n else -> Acc(max(top, acc.size + 1), acc + x)\n }\n }.top.let { print(it) }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "d7ff41e07b68a80babb7da981fc0a988", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Math.max\n\nfun main(){\n readLine()\n var s = readLine()!!\n var ans = 0\n var ss = mutableSetOf()\n for(c in s){\n if(c < 'a') ss.clear()\n else ss.add(c)\n ans = max(ans, ss.size)\n }\n print(ans)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "8e5bf57237ad0ee3eb95e4a354d94e30", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "32ebac7444b2b7fa061f949687194e69", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "2b5bc1256350baa90e8309af43cfc9ad", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "78d0be2e7096963be1e1a862608cd3ea", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "38ddcc7146fb3cd170fce9019c2fb59a", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.lang.System.`in`\nimport kotlin.system.exitProcess\n\nprivate val factorials = MutableList(2) {\n 1L\n}\n\nprivate const val MOD = 998244353\n\n\nfun main() {\n val (n, m) = `in`.bufferedReader().readLine().split(' ').map(String::toInt)\n if (n == 2) {\n print(0)\n exitProcess(0)\n }\n var ways = factorial(m) * (n - 2)\n ways %= MOD\n ways *= modInverse(factorial(n - 1))\n ways %= MOD\n ways *= modInverse(factorial(m - n + 1))\n ways %= MOD\n ways *= modPow(2L, n - 3)\n ways %= MOD\n print(ways)\n\n}\n\nprivate fun modInverse(num: Long): Long {\n return modPow(num, MOD - 2)\n}\n\nprivate fun modPow(base: Long, pow: Int): Long {\n if (pow == 0) {\n return 1L\n }\n var halfPow = modPow(base, pow / 2)\n halfPow *= halfPow\n halfPow %= MOD\n if (pow and 1 == 1) {\n halfPow *= base\n halfPow %= MOD\n }\n return halfPow\n}\n\nprivate fun factorial(n: Int): Long {\n if (n > factorials.size) {\n for (i in factorials.size until n) {\n factorial(i)\n }\n }\n if (n == factorials.size) {\n var newFact = n * factorials[n - 1]\n newFact %= MOD\n factorials += newFact\n }\n return factorials[n]\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "caa5fb4a15ce16107fe7424593577162", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\nimport java.util.*\n\nprivate fun readInt() = readLine()!!.toInt()\nprivate fun readLong() = readLine()!!.toLong()\nprivate fun readInts() = readLine()!!.split(\" \").map(String::toInt)\nprivate fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\nclass Combination(private val maxN: Int, private val mod: Int) {\n private val fac = LongArray(maxN+1) { 1 }\n private val inv = LongArray(maxN+1) { 1 }\n\n init {\n for (i in 2..maxN) fac[i] = fac[i-1] * i % mod\n var m = mod - 2\n var x = fac.last()\n while (m > 0) {\n if (m.and(1) == 1) inv[maxN] = inv[maxN] * x % mod\n x = x * x % mod\n m = m.shr(1)\n }\n for (i in maxN downTo 2) inv[i-1] = inv[i] * i % mod\n }\n\n fun ncr(n: Int, r: Int): Long = ((fac[n] * inv[r]) % mod) * inv[n-r] % mod\n fun npr(n: Int, r: Int): Long = fac[n] * inv[n-r] % mod\n}\n\nfun main(args: Array) {\n val (n, m) = readInts()\n if (n == 1) {\n println(0)\n return\n }\n val mod = 998244353\n val comb = Combination(m, mod)\n var ans = comb.ncr(m, n-1) * (n-2) % mod\n for (i in 0 until n-3) ans = ans * 2 % mod\n\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "a09da5c9ea0e570ed79ec1e8e6c8a8e8", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nconst val MOD = 998244353L\n\nval fact = ArrayList()\nfun main(args: Array) {\n val (n, m) = getLongs()\n if (n == 2L) {\n println(0)\n return\n }\n\n fact.add(1L)\n (1..m).forEach {\n fact.add(fact.last() * it % MOD)\n }\n\n var out = comb(m, n - 1)\n out = out * (n - 2) % MOD\n\n var c = 0L\n (0..n - 3).forEach {\n c = (c + comb(n - 3, it)) % MOD\n }\n out = out * c % MOD\n println(out)\n}\n\nfun comb(n: Long, k: Long): Long {\n return (fact[n.toInt()] * inv(fact[k.toInt()]) % MOD) * inv(fact[n.toInt() - k.toInt()]) % MOD\n}\n\nfun inv(n: Long): Long {\n return pow(n, MOD - 2)\n}\n\nfun pow(base: Long, exp: Long): Long {\n return when {\n exp == 0L -> 1L\n exp == 1L -> base\n exp % 2 == 0L -> pow(base, exp / 2).let { it * it % MOD }\n else -> pow(base, exp / 2).let { (base * it % MOD) * it % MOD }\n }\n}\n\n\nfun getInt() = readLine()!!.toInt()\nfun getInts() = readLine()!!.split(\" \").map { it.toInt() }\nfun getLong() = readLine()!!.toLong()\nfun getLongs() = readLine()!!.split(\" \").map { it.toLong() }\n", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "146fe31381af8fb03e796c94a12903c5", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.*\nval input = BufferedReader(InputStreamReader(System.`in`))\nval output = StringBuilder()\n\nvar mod=998244353\n\nfun main() {\n var tt = 1\n while (tt-- > 0) {\n var (n,m)=readints()\n if(n==2){\n cout(0)\n continue\n }\n var z=pow(2,n-3)\n var a=0\n var x=IntArray(m+10){1}\n for(i in 2..m+9){\n x[i]=mul(x[i-1],i)\n }\n var c=mul(x[m-1],inv(mul(x[n-2],x[m-n+1])))\n for(i in 1..m){\n var d=0\n if(m-i-n+2>=0){\n d=mul(x[m-i],inv(mul(x[n-2],x[m-i-n+2])))\n }\n a=add(a,sub(c,d))\n }\n cout(mul(a,z))\n }\n print(output)\n}\n\nfun readln() = input.readLine()\nfun readint() = readln().toInt()\nfun readlong() = readln().toLong()\nfun readstrings() = ArrayList(readln().split(\" \"))\nfun readints() = ArrayList(readstrings().map { it.toInt() })\nfun readlongs() = ArrayList(readstrings().map { it.toLong() })\nfun cout(s: String) = output.appendln(s)\nfun cout(s: Int) = output.appendln(s.toString())\nfun cout(s: Long) = output.appendln(s.toString())\n\nfun add(a: Int, b: Int): Int {\n return (a + b) % mod\n}\n\nfun sub(a: Int, b: Int): Int {\n return ((a - b) % mod + mod) % mod\n}\n\nfun mul(a: Int, b: Int): Int {\n return (1L * a * b % mod).toInt()\n}\n\nfun inv(a: Int): Int {\n return pow(a, mod - 2)\n}\n\nfun pow(_a: Int, _b: Int): Int {\n var a = _a\n var b = _b\n var res = 1\n while(b > 0) {\n if((b and 1) != 0) {\n res = mul(res, a)\n }\n a = mul(a, a)\n b /= 2\n }\n return res\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "0f60aa4f086ddcf6fade72121e9bf7d9", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val s = readLine()!!\n var cnt = 0\n for (i in 0..s.length - 1) {\n if (i >= s.length - 1 -i)\n break;\n if (s[i] != s[s.length - 1 -i]) {\n cnt++\n }\n }\n if (s.length % 2 == 0 && cnt == 1)\n print(\"YES\")\n else if (s.length % 2 == 1 && cnt <= 1)\n print(\"YES\")\n else\n print(\"NO\")\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "constructive algorithms"], "code_uid": "baf9dbae97221a8ced91b84672301fa5", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLine()!!\n var left = 0\n var right = s.lastIndex\n var changed = false\n while (left < right) {\n if (s[left] != s[right]) {\n if (changed)\n return print(\"NO\")\n else\n changed = true\n }\n left++\n right--\n }\n print(if (changed || s.length % 2 == 1) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "constructive algorithms"], "code_uid": "5b2a142cd2a1068b1e8af2030ba44227", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.pow\n\nfun main() {\n var str = readLine()\n var count = 0\n var flag = true\n if (str != null) {\n for (i in 0..str.length / 2-1) {\n if (str[i] != str[str.length - i - 1]) {\n count++\n }\n if (count == 2) {\n flag = false\n }\n }\n if (count==0 && str.length%2!=0) {\n println(\"YES\")\n } else if (!flag || count==0){\n println(\"NO\")\n }else{\n println(\"YES\")\n }\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "constructive algorithms"], "code_uid": "c0a6718aa4d12c0b42567461d60e3154", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val word = readLine() ?: \"\"\n var diffCount = 0\n for (i in 0..word.length / 2 - 1) {\n if (word[i] != word[word.length - 1 - i]) {\n diffCount++\n }\n if (diffCount >= 2) break\n }\n\n if (diffCount == 0 && word.length % 2 == 1) {\n diffCount = 1\n }\n\n val msg = if (diffCount == 1) \"YES\" else \"NO\"\n println(msg)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "constructive algorithms"], "code_uid": "a7c3178c1f2161fdf07fc7bef2b3bbb2", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\nprivate val MOD = 1_000_000_007\nclass SegmentTree(n: Int) {\n private val N =\n if (Integer.highestOneBit(n) == n) n\n else Integer.highestOneBit(n) shl 1\n\n private val zero = 0\n\n private val dat = IntArray(2 * N){zero}\n\n private inline fun f(a: Int, b: Int) = run{max(a, b)}\n\n fun update(i: Int, a: Int) {\n var ix = i + N\n dat[ix] = a\n while(ix > 1) {\n dat[ix shr 1] = f(dat[ix], dat[ix xor 1])\n ix = ix shr 1\n }\n }\n\n /**\n * [a, b)\n */\n fun query(a: Int, b: Int): Int {\n var res: Int = zero\n var left = a + N\n var right = b - 1 + N\n\n while(left <= right) {\n if ((left and 1) == 1) res = f(res, dat[left])\n if ((right and 1) == 0) res = f(res, dat[right])\n left = (left + 1) shr 1 // \u53f3\u306e\u5b50\u4f9b\u306a\u3089\u53f3\u306e\u89aa\u306b\u79fb\u52d5\n right = (right - 1) shr 1 // \u5de6\u306e\u5b50\u4f9b\u306a\u3089\u5de6\u306e\u89aa\u306b\u79fb\u52d5\n }\n\n return res\n }\n\n // \u6761\u4ef6\u3092\u6e80\u305f\u3059\u304b\u3002max\u306a\u3089 '>' min\u306a\u3089 '<' \u304c\u4f7f\u3048\u308b\n private inline fun contains(a: Int, x: Int): Boolean = a < x\n /**\n * @param x \u5de6\u53f3\u3069\u3061\u3089\u304b\u3089\u304b\u6700\u521d\u306b a < x \u306b\u306a\u308b\u5834\u6240\u3092\u63a2\u3059\n * @param [a, b) \u8abf\u3079\u308b\u7bc4\u56f2\n * @return -1\n */\n fun find(x: Int, a: Int = 0, b: Int = N, k: Int = 1, l: Int = 0, r: Int = N): Int {\n if (a >= r || l >= b) return -1// \u30ce\u30fc\u30c9\u304c\u7bc4\u56f2\u304b\u3089\u306f\u305a\u308c\u3066\u308b\n if (!contains(dat[k], x)) return -1\n if (l + 1 == r) return l // 0-indexed\n\n val m = (l + r) / 2\n val lft = k * 2\n val rgt = lft + 1\n\n // \u5de6\u304b\u3089\u63a2\u3059\u3002\u53f3\u304b\u3089\u63a2\u3057\u305f\u3044\u5834\u5408\u306f\u5de6\u53f3\u3092\u9006\u306b\u3059\u308c\u3070\u3044\u3044\n val ans = find(x, a, b, lft, l, m)\n if (ans != -1) return ans\n return find(x, a, b, rgt, m, r)\n }\n}\n\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val N = ni()\n val T = ni()\n val (A, M) = run {\n val A = na(N)\n val B = A.distinct() as MutableList\n B.sort()\n Pair(A.map{B.indexOf(it)}.toIntArray(), B.size)\n }\n\n debug(A)\n debug{\"M:$M\"}\n\n fun simulate(t: Int, s: Int): IntArray {\n debug{\"simulate($t $s)\"}\n val dp = SegmentTree(M - s)\n for (times in 0 until t) {\n for (a in A) {\n if (a < s) continue\n dp.update(a - s, dp.query(0, a - s + 1) + 1)\n }\n }\n val res = IntArray(M)\n for (i in 0 until M - s) {\n res[i + s] = dp.query(i, i + 1)\n }\n return res\n }\n\n val SIM_LEN = 1000\n var ans = 0L\n if (T <= SIM_LEN * 2) {\n ans = simulate(T, 0).max()!!.toLong()\n } else {\n val pre = simulate(SIM_LEN, 0)\n for (i in 0 until M) {\n val med = A.count{it == i} * (T - SIM_LEN * 2).toLong()\n val post = simulate(SIM_LEN, i)\n debug(pre)\n debug(post)\n ans = max(ans, pre[i] + med + post.max()!!)\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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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}", "lang_cluster": "Kotlin", "tags": ["matrices", "dp", "constructive algorithms"], "code_uid": "242a50ec46eae989d81dda2786896a94", "src_uid": "26cf484fa4cb3dc2ab09adce7a3fc9b2", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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() }", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "d788eb28aae1ee196b26a934ab10ba77", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "813b5fe1a58bfffd51abb942a1c83983", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "8e061eee2d78a2b84c8e35298560c9d8", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = readInt()\n val k = readInt()\n val D = readIntArray(k)\n\n val fft = ModFFT(5*n)\n val P = ModIntArray(10)\n for(d in D) P[d] = ModInt(1)\n\n val F = fft(P, false)\n for(i in F.indices) F[i] = F[i].pow(n/2)\n fft.inPlace(F, true)\n\n val ans = (0 until 5*n).sumByModInt { F[it] * F[it] }\n println(ans)\n}\n\nclass ModFFT(minCapacity: Int) {\n val n = Integer.highestOneBit(minCapacity.shl(1) - 1)\n inline val g get() = ModInt(3) // primitive root modulo 998244353\n val ninv = ModInt(n).inverse()\n val mask = n - 1\n\n val w = ModIntArray(n).also { w ->\n w[0] = ModInt(1)\n val w1 = g.pow((MOD-1) / n)\n for(i in 1 until n) {\n w[i] = w[i-1] * w1\n }\n }\n\n // rev[i] is reversal of bits in i\n val rev = IntArray(n).also { rev ->\n if(n == 1) return@also\n rev[1] = n shr 1\n var bit = 2\n while(bit < n) {\n val revbit = rev[bit shr 1] shr 1\n for(i in bit until bit.shl(1)) {\n rev[i] = revbit or rev[i - bit]\n }\n bit = bit shl 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\n fun inPlace(a: ModIntArray, invert: Boolean) {\n require(a.size == n) { \"size of a must be n = $n\" }\n for(i in 0 until n) {\n val j = rev[i]\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\n if(invert) ang = -ang\n while(len <= n) {\n for(i in 0 until n step len) {\n var k = 0\n for(j in 0 until len.shr(1)) {\n val u = a[i+j]\n val v = a[i+j+len.shr(1)] * w[k]\n a[i+j] = u + v\n a[i+j+len.shr(1)] = u - v\n k = k + ang and mask\n }\n }\n\n len = len shl 1\n ang = ang shr 1\n }\n\n if(invert) {\n for(i in 0 until n) a[i] *= ninv\n }\n }\n\n fun mul(a: ModIntArray, b: ModIntArray): ModIntArray {\n require(a.size + b.size <= n)\n val a1 = invoke(a, false)\n val b1 = invoke(b, false)\n for(i in 0 until n) a1[i] *= b1[i]\n inPlace(a1, true)\n return a1.copyOf(a.size + b.size)\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\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/** 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}", "lang_cluster": "Kotlin", "tags": ["divide and conquer", "dp", "fft"], "code_uid": "e81ebc0c20eebe41dacd033e9fa3a33f", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = readInt()\n val k = readInt()\n val D = readIntArray(k)\n\n val deg = n/2 * D.max()!!\n val fft = ModFFT(deg)\n val P = ModIntArray(10)\n for(d in D) P[d] = ModInt(1)\n\n val F = fft(P, false)\n for(i in F.indices) F[i] = F[i].pow(n/2)\n fft.inPlace(F, true)\n\n val ans = (0..deg).sumByModInt { F[it] * F[it] }\n println(ans)\n}\n\ninline val PRIMITIVE_ROOT get() = ModInt(3)\nclass ModFFT(maxDeg: Int) {\n val n = getArrSize(maxDeg)\n private val ninv = ModInt(n).inv_unmemoized()\n\n private fun getArrSize(deg: Int) = Integer.highestOneBit(deg shl 1 or 1)\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)\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 for(i in 0 until sz step len) {\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 }\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 Array.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\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/** 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}", "lang_cluster": "Kotlin", "tags": ["divide and conquer", "dp", "fft"], "code_uid": "aa53b4e8a2eabbb30dd41be45f8937dd", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "val MOD = 998244353\nval MOD2 = MOD.toLong() * MOD\n\nfun main(args: Array) {\n var (n, k) = readLine()!!.split(\" \").map {it.toInt()}\n n /= 2\n val N = 9 * n + 1;\n val inv = LongArray(N + 1) {1}\n for (i in 2..N) inv[i] = -inv[MOD % i] * (MOD / i) % MOD\n\n val _a = readLine()!!.split(\" \").map {it.toInt()}\n val a = _a.map {it - _a.min()!!}.minus(0)\n\n val b = LongArray(16) {0}\n val bi = LongArray(16) {0}\n b[0] = 1\n var ans = 0L\n for (i in 0 until N) {\n ans += b[i and 15] * b[i and 15]\n if (ans >= MOD2)\n ans -= MOD2\n var sum = 0L\n for (x in a) {\n sum -= bi[(i - x + 17) and 15]\n sum += b[(i - x + 17) and 15] * (n * x)\n }\n sum %= MOD\n bi[(i + 1) and 15] = sum\n b[(i + 1) and 15] = sum * inv[i + 1] % MOD\n }\n println((ans % MOD + MOD) % MOD)\n}\n", "lang_cluster": "Kotlin", "tags": ["divide and conquer", "dp", "fft"], "code_uid": "7cf6edd7425a59ad7a09b0af7abfb68b", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = readInt()\n val k = readInt()\n val D = readIntArray(k)\n\n val deg = n/2 * 9\n val fft = ModFFT(deg)\n val P = ModIntArray(10)\n for(d in D) P[d] = ModInt(1)\n\n val F = fft(P, false)\n for(i in F.indices) F[i] = F[i].pow(n/2)\n fft.inPlace(F, true)\n\n val ans = (0..deg).sumByModInt { F[it] * F[it] }\n println(ans)\n}\n\nclass ModFFT(deg: Int) {\n inline val g get() = ModInt(3) // primitive root modulo 998244353\n val n = Integer.highestOneBit(deg shl 1 or 1)\n private val ninv = ModInt(n).inverse()\n\n // w[1] represents n-th root of unity e^(i * tau/n), w[k] = w[1]^k\n val w = ModIntArray(n).also { w ->\n w[0] = ModInt(1)\n val w1 = g.pow(TOTIENT / n)\n for(i in 1 until n) {\n w[i] = w[i-1] * w1\n }\n }\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\n fun inPlace(a: ModIntArray, invert: Boolean) {\n require(a.size == n) { \"size of a must be n = $n\" }\n for(i in 0 until n) {\n val j = rev[i]\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 <= n) {\n for(i in 0 until n step len) {\n var k = 0\n for(j in 0 until len.shr(1)) {\n val u = a[i+j]\n val v = a[i+j+len.shr(1)] * w[k]\n a[i+j] = u + v\n a[i+j+len.shr(1)] = u - v\n k = k + ang and n-1\n }\n }\n\n len = len shl 1\n ang = ang shr 1\n }\n\n if(invert) {\n for(i in 0 until n) a[i] *= ninv\n }\n }\n\n fun mul(a: ModIntArray, b: ModIntArray): ModIntArray {\n require(a.size + b.size - 1 <= n)\n val a1 = invoke(a, false)\n val b1 = invoke(b, false)\n for(i in 0 until n) a1[i] *= b1[i]\n inPlace(a1, true)\n return a1//.copyOf(a.size + b.size - 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\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/** 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}", "lang_cluster": "Kotlin", "tags": ["divide and conquer", "dp", "fft"], "code_uid": "11d0031a665c303a898df031a00ec0ee", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.StringTokenizer\n\nval sc = FastScanner(System.`in`)\n\nfun main(args: Array) {\n val n = sc.nextInt()\n\n val cubes = Array(n) { Array(6) { sc.nextInt() } }\n\n var ans = 0\n\n while (test(ans + 1, cubes)) ans += 1\n\n println(ans)\n\n\n}\n\nfun test(ans: Int, cubes: Array>): Boolean {\n val selected = mutableListOf()\n return test(ans, cubes, selected)\n}\n\nfun test(ans: Int, cubes: Array>, selected: MutableList): Boolean {\n if (ans == 0) return true\n val n = cubes.size\n\n val digit = ans % 10\n for (i in 0 until n) {\n if (!selected.contains(i) && cubes[i].contains(digit)) {\n selected.add(i)\n if (test(ans / 10, cubes, selected)) return true\n selected.remove(i)\n }\n }\n\n return false\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", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "2edcda1bee95fc296185eb6662e1767a", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val cubes = (1..n).map { readLine()!!.split(\" \").map(String::toInt) }\n val combination = mutableListOf()\n\n cubes\n .flatMap { it }\n .forEach { it -> combination += \"$it\" }\n\n for (i in cubes.indices) {\n for (j in (i + 1) until cubes.size) {\n for (x in 0 until 6) {\n for (y in 0 until 6) {\n combination += \"${cubes[i][x]}${cubes[j][y]}\"\n combination += \"${cubes[j][x]}${cubes[i][y]}\"\n }\n }\n }\n }\n\n if (cubes.size == 3)\n for (i in 0 until 6) {\n for (j in 0 until 6) {\n for (k in 0 until 6) {\n combination += \"${cubes[0][i]}${cubes[1][j]}${cubes[2][k]}\"\n combination += \"${cubes[2][i]}${cubes[0][j]}${cubes[1][k]}\"\n combination += \"${cubes[1][i]}${cubes[2][j]}${cubes[0][k]}\"\n combination += \"${cubes[0][i]}${cubes[2][j]}${cubes[1][k]}\"\n combination += \"${cubes[1][i]}${cubes[0][j]}${cubes[2][k]}\"\n combination += \"${cubes[2][i]}${cubes[1][j]}${cubes[0][k]}\"\n }\n }\n }\n\n (1..999).forEach {\n if (!combination.any { x -> x.toInt() == it }) {\n println(it - 1)\n return\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "bca0b792070a7281cb9a2612c0792937", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.File\nimport kotlin.math.min\n\n/**\n * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools\n */\n\nfun main() {\n\t// Write your solution here\n\tval n = readInt()\n\tval arr = readInts().readAndAppendInts().toMutableList()\n\t\n\tval wins = (0..2).map { min(arr[it], arr[it.win]) }.sum()\n\tval ranked = (0..2).map { arr[it] - (arr[it.lose] + arr[it.draw]) }\n\tval notWins = ranked.indices.sortedByDescending { ranked[it] }.map {\n\t\tif (arr[it] <= arr[it.lose]) {\n\t\t\tarr[it.lose] -= arr[it]\n\t\t\tarr[it]\n\t\t} else {\n\t\t\tval lose = arr[it.lose]\n\t\t\tarr[it.lose] = 0\n\t\t\tarr[it] -= lose\n\t\t\tlose + if (arr[it] <= arr[it.draw]) {\n\t\t\t\tarr[it.draw] -= arr[it]\n\t\t\t\tarr[it]\n\t\t\t} else {\n\t\t\t\tval draws = arr[it.draw]\n\t\t\t\tarr[it.draw] = 0\n\t\t\t\tdraws\n\t\t\t}\n\t\t}\n\t}.sum()\n\tprintln(\"${n - notWins} $wins\")\n}\n\nfun Int.opp(k: Int) = 3 + (3 + this + k) % 3\nval Int.win; get() = opp(1)\nval Int.lose; get() = opp(-1)\nval Int.draw; get() = opp(0)\nfun readInt() = readLine()!!.toInt()\nfun readInts() = readLine()!!.split(' ').map { it.toInt() }\nfun List.readAndAppendInts() = toMutableList().apply { addAll(readInts()) }\nfun readIntArray() = readInts().toIntArray()\n", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "flows", "math", "greedy"], "code_uid": "12c1dfd6447c5e6be1004cf5e1abeb42", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.min\n\nfun main() {\n val scanner = Scanner(System.`in`)\n// val scanner = Scanner(File(\"input.txt\"))\n\n val n = scanner.nextInt()\n\n val a = ArrayList(3)\n for (i in 1..3) a.add(scanner.nextInt())\n\n val b = ArrayList(3)\n for (i in 1..3) b.add(scanner.nextInt())\n\n val loseOutcome = listOf(\n 0 to 0,\n 0 to 2,\n 1 to 1,\n 1 to 0,\n 2 to 2,\n 2 to 1\n )\n\n var loses = Int.MAX_VALUE\n do {\n val a1 = ArrayList(a)\n val b1 = ArrayList(b)\n\n for (i in perm) {\n val (x, y) = loseOutcome[i]\n val cnt = min(a1[x], b1[y])\n a1[x] = a1[x] - cnt\n b1[y] = b1[y] - cnt\n }\n\n val l = min(a1[0], b1[1]) + min(a1[1], b1[2]) + min(a1[2], b1[0])\n loses = min(loses, l)\n } while (nextPerm())\n\n val wins = min(a[0], b[1]) + min(a[1], b[2]) + min(a[2], b[0])\n\n println(\"$loses $wins\")\n}\n\n\nval perm = intArrayOf(0, 1, 2, 3, 4, 5)\nfun nextPerm(): Boolean {\n var hasNext = false\n for (i in perm.size - 2 downTo 0) {\n if (perm[i] > perm[i + 1]) continue\n hasNext = true\n\n for (j in perm.lastIndex downTo i + 1) {\n if (perm[j] > perm[i]) {\n swap(i, j)\n break\n }\n }\n var l = i + 1;\n var r = perm.lastIndex\n while (l < r) {\n swap(l++, r--)\n }\n break\n }\n\n return hasNext\n}\n\nprivate fun swap(i: Int, j: Int) {\n val tmp = perm[i]\n perm[i] = perm[j]\n perm[j] = tmp\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "flows", "math", "greedy"], "code_uid": "fe825335cc26d38083b6500f96a06e31", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\nimport kotlin.math.sqrt\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() {\n\n var n = readInt()\n var alice = readInts()\n var bob = readInts()\n\n var orders = Array(6){IntArray(3)}\n var ptr = 0\n for(i in 0 until 3) {\n for(j in 0 until 3) {\n for(k in 0 until 3) {\n if(i == j || i == k || j == k) continue\n orders[ptr][0] = i; orders[ptr][1] = j; orders[ptr][2] = k;\n ptr++\n }\n }\n }\n\n //0 = rock, 1 = scissors, 2 = paper\n fun isWin(a: Int, b: Int): Boolean {\n if(a == 0) return b == 1\n if(a == 1) return b == 2\n if(a == 2) return b == 0\n return false\n }\n\n fun eval(order: IntArray, order1: IntArray): Int {\n var A = alice.toMutableList()\n var B = bob.toMutableList()\n\n var wins = 0\n var bobPtr = 0\n var aliPtr = 0\n while(aliPtr < 3 && bobPtr < 3) {\n var amtMe = A[order1[aliPtr]]\n var amtHim = B[order[bobPtr]]\n var plays = min(amtMe, amtHim)\n if(isWin(order1[aliPtr], order[bobPtr])) {\n wins += plays\n }\n\n A[order1[aliPtr]] -= plays\n B[order[bobPtr]] -= plays\n\n if(B[order[bobPtr]] == 0) bobPtr++\n if(A[order1[aliPtr]] == 0) aliPtr++\n }\n\n return wins\n }\n\n var minWin = n+1\n var maxWin = 0\n\n for(i in 0 until 6) {\n for(j in 0 until 6) {\n var ret = eval(orders[i], orders[j])\n minWin = min(minWin, ret)\n maxWin = max(maxWin, ret)\n }\n }\n\n println(\"$minWin $maxWin\")\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "flows", "math", "greedy"], "code_uid": "38282211540872bef016fc808b925041", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nclass Solution : Runnable {\n override fun run() {\n solve()\n }\n\n fun start() {\n Thread(null, Solution(), \"whatever\", (1 shl 26).toLong()).start()\n }\n}\n\nfun main(args: Array) {\n Solution().start()\n}\n\n\nclass IO {\n companion object {\n\n private val reader: InputReader\n private val writer: OutputWriter\n\n init {\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n reader = InputReader(FileInputStream(\"/Users/300041735/competitiveProgramming/src/codeforces/in.txt\"))\n writer = OutputWriter(FileOutputStream(\"/Users/300041735/competitiveProgramming/src/codeforces/out.txt\"))\n } else {\n reader = InputReader(System.`in`)\n writer = OutputWriter(System.`out`)\n }\n }\n\n private fun readMultipleInts(count: Int): List {\n val map = mutableListOf()\n repeat(count) {\n map.add(reader.readInt())\n }\n return map\n }\n\n fun readInt() = reader.readInt()\n fun readLong() = reader.readLong()\n fun readTwoInts() = readMultipleInts(2)\n fun readThreeInts() = readMultipleInts(3)\n fun readFourInts() = readMultipleInts(4)\n fun readString() = reader.readString()\n fun readTree(n: Int): MutableMap> {\n val graph = mutableMapOf>()\n repeat(n - 1) {\n val u = reader.readInt()\n val v = reader.readInt()\n if (!graph.containsKey(u)) graph[u] = mutableSetOf()\n if (!graph.containsKey(v)) graph[v] = mutableSetOf()\n graph[u]!!.add(v)\n graph[v]!!.add(u)\n }\n return graph\n }\n\n fun readIntArray(n: Int): Array {\n return Array(n) { readInt() }\n }\n\n fun readLongArray(n: Int): Array {\n return Array(n) { readLong() }\n }\n\n fun write(obj: Any) {\n writer.printLine(obj)\n }\n\n fun flushOutput() {\n writer.flush()\n }\n\n fun closeOutput() {\n writer.close()\n }\n }\n}\n\n\nclass MATH {\n companion object {\n\n val mod = 998244353\n var ispre = false\n\n val factMod = Array(300002) { 1 }\n\n fun pre() {\n for (i in 2 until 300001) {\n factMod[i] = ((factMod[i - 1] * i.toLong()) % MATH.mod).toInt()\n }\n }\n\n fun gcd(a: Int, b: Int): Int {\n if (b == 0)\n return a\n return gcd(b, a % b)\n }\n\n fun gcd(a: Long, b: Long): Long {\n if (b == 0L)\n return a\n return gcd(b, a % b)\n }\n\n fun inverseMod(a: Int): Int {\n return powMod(a, mod - 2)\n }\n\n fun powMod(a: Int, b: Int): Int {\n //calculate a to the power b mod m\n if (b == 0) return 1\n return if (b % 2 == 1) {\n prodMod(a, powMod(a, b - 1))\n } else {\n val p = powMod(a, b / 2)\n prodMod(p, p)\n }\n }\n\n fun ncr(n: Int, r: Int): Int {\n if (!ispre) pre(); ispre = true\n return ((factMod[n].toLong() * inverseMod(((factMod[r].toLong() * factMod[n - r]) % mod).toInt())) % mod).toInt()\n }\n\n fun prodMod(val1: Int, val2: Int): Int {\n return ((val1.toLong() * val2) % mod).toInt()\n }\n\n }\n}\n\n\nfun solve() {\n val n = IO.readInt()\n val (a1, a2, a3) = IO.readThreeInts()\n val (b1, b2, b3) = IO.readThreeInts()\n\n //minimum wins\n var aa1 = a1\n var aa2 = a2\n var aa3 = a3\n var bb1 = b1\n var bb2 = b2\n var bb3 = b3\n\n val max = Math.min(aa1, bb2) + Math.min(aa2, bb3) + Math.min(aa3, bb1)\n\n IO.write(\"${Math.max(0, aa1 - bb1 - bb3) + Math.max(0, aa2 - bb1 - bb2) + Math.max(0, aa3 - bb2 - bb3)} $max\")\n\n IO.flushOutput()\n IO.closeOutput()\n}\n\nfun factorize(n: Int, primes: MutableList): MutableList> {\n val factors = mutableListOf>()\n var nn = n\n primes.forEach {\n var power = 0\n while (nn % it == 0) {\n nn /= it\n power++\n }\n if (power != 0) {\n factors.add(Pair(it, power))\n }\n }\n if (nn != 1) {\n factors.add(Pair(nn, 1))\n }\n return factors\n}\n\n\nfun generateDivisors(index: Int, factors: MutableList>): List {\n if (index == factors.size - 1) {\n var cur = 1\n val list = mutableListOf()\n for (i in 0 until factors[index].second + 1) {\n list.add(cur)\n cur *= factors[index].first\n }\n return list\n }\n val list = generateDivisors(index + 1, factors)\n val newList = mutableListOf()\n var cur = 1\n for (i in 0 until factors[index].second + 1) {\n list.forEach {\n newList.add(it * cur)\n }\n cur *= factors[index].first\n }\n return newList\n}\n\n\nclass ArrayUtils {\n\n fun lowerBound(arr: Array, value: Int): Int {\n val pos = arr.binarySearch(value)\n if (pos < 0) return -1 * pos - 1\n var low = 0\n var high = arr.size\n while (low < high) {\n val middle = low + (high - low) / 2\n if (value > arr[middle]) {\n low = middle + 1\n } else {\n high = middle\n }\n }\n return low\n }\n}\n\nclass 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 }\n var sgn: Long = 1\n if (c == '-'.toInt()) {\n sgn = -1\n c = read()\n }\n var number: Long = 0\n do {\n number *= 10L\n number += (c - '0'.toInt()).toLong()\n c = read()\n } while (!isSpaceChar(c))\n return number * 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\nclass 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 fun flush() {\n writer.flush()\n }\n\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "flows", "math", "greedy"], "code_uid": "10ed811dd1ea55e6e4bc530e4a0300de", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\nimport java.io.*\nimport java.util.*\n\nclass FS(stin: InputStream) {\n val read = BufferedReader(InputStreamReader(stin))\n var token = StringTokenizer(\"\")\n\n tailrec fun next(): String {\n if(token.hasMoreTokens()) return token.nextToken()\n token = StringTokenizer(read.readLine())\n return next()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextDouble() = next().toDouble()\n}\n\nval ko = PrintWriter(System.out)\nval ki = FS(System.`in`)\ntypealias Chi = Int\n\nfun main() {\n // for(i in 0 until ki.nextInt())\n solve()\n\n ko.close()\n}\n\nfun solve() {\n var n = ki.nextInt()\n val a = ki.nextInt(); val b = ki.nextInt(); val c = ki.nextInt()\n val x = ki.nextInt(); val y = ki.nextInt(); val z = ki.nextInt()\n\n val cap = Array(8, {IntArray(8, {0})})\n cap[6][0] = a; cap[6][1] = b; cap[6][2] = c\n cap[3][7] = x; cap[4][7] = y; cap[5][7] = z\n cap[0][3] = n; cap[0][5] = n\n cap[1][4] = n; cap[1][3] = n\n cap[2][5] = n; cap[2][4] = n\n val vis = BooleanArray(8, {false})\n fun dfs(x: Int, curr: Int): Int {\n if(x == 7) return curr\n if(vis[x]) return 0\n vis[x] = true\n for(i in 0..7) {\n val next = min(curr, cap[x][i])\n if(next != 0) {\n val add = dfs(i, next)\n if(add > 0) {\n cap[x][i] -= add\n cap[i][x] += add\n return add\n }\n }\n }\n return 0\n }\n var i = n\n while(true) {\n vis.fill(false)\n val d = dfs(6, n)\n if(d == 0) break\n i -= d\n }\n val j = min(a, y)+min(b, z)+min(c, x)\n ko.println(\"$i $j\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "flows", "math", "greedy"], "code_uid": "57dc194d995ab7d9dc3492bdd787760d", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\nimport java.io.*\nimport java.util.*\n\nclass FastIO: PrintWriter(System.out) {\n val read = BufferedReader(InputStreamReader(System.`in`))\n var token = StringTokenizer(\"\")\n\n fun next(): String {\n while (!token.hasMoreTokens()) token = StringTokenizer(read.readLine())\n return token.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextDouble() = next().toDouble()\n}\n\nfun main() {\n val koi = FastIO()\n\n // val t = koi.nextInt(); for (i in 1..t)\n solve(koi)\n\n koi.close()\n}\n\nclass FF(val n: Int) {\n\t\n\tvar adj = Array(n){ LongArray(n) }\n\tvar seen = BooleanArray(n)\n\n\tfun add(u: Int, v: Int, cap: Long) {\n\t\tadj[u][v] += cap\n\t}\n\n\tfun dfs(u: Int, low: Long, t: Int): Long {\n\t\tif (u == t)\n\t\t\treturn low\n\n\t\tseen[u] = true;\n\n\t\tfor (v in 0..n-1) {\n\t\t\tif (adj[u][v] != 0L && !seen[v]) {\n\t\t\t\tvar flow = dfs(v, min(adj[u][v], low), t)\n\n\t\t\t\tif (flow > 0) {\n\t\t\t\t\tadj[u][v] -= flow\n\t\t\t\t\tadj[v][u] += flow\n\t\t\t\t\tseen[u] = false\n\t\t\t\t\treturn flow\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tseen[u] = false\n\t\treturn 0\n\t}\n\n\tfun flow(s: Int, t: Int): Long {\n\t\tvar flow = 0L\n\n\t\twhile (true) {\n\t\t\tvar here = dfs(s, 100000000000, t)\n\t\t\tif (here == 0L)\n\t\t\t\tbreak\n\t\t\tflow += here\n\t\t}\n\n\t\treturn flow\n\t}\n}\n\nfun solve(koi: FastIO) {\n\n\tvar n = koi.nextInt()\n\n\tvar a = koi.nextLong()\n\tvar c = koi.nextLong()\n\tvar b = koi.nextLong()\n\n\tvar x = koi.nextLong()\n\tvar z = koi.nextLong()\n\tvar y = koi.nextLong()\n\n\tvar g1 = FF(8)\n\n\tg1.add(6, 0, a)\n\tg1.add(6, 1, b)\n\tg1.add(6, 2, c)\n\n\tg1.add(3, 7, x)\n\tg1.add(4, 7, y)\n\tg1.add(5, 7, z)\n\n\tg1.add(0, 3, 100000000000)\n\tg1.add(0, 4, 100000000000)\n\tg1.add(1, 4, 100000000000)\n\tg1.add(1, 5, 100000000000)\n\tg1.add(2, 5, 100000000000)\n\tg1.add(2, 3, 100000000000)\n\n\tvar g2 = FF(8)\n\n\tg2.add(6, 0, a)\n\tg2.add(6, 1, b)\n\tg2.add(6, 2, c)\n\n\tg2.add(3, 7, x)\n\tg2.add(4, 7, y)\n\tg2.add(5, 7, z)\n\n\tg2.add(0, 5, 100000000000)\n\tg2.add(1, 3, 100000000000)\n\tg2.add(2, 4, 100000000000)\n\n\tval ans1 = n - g1.flow(6, 7)\n\tval ans2 = g2.flow(6, 7)\n\n\tkoi.println(\"$ans1 $ans2\")\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "flows", "math", "greedy"], "code_uid": "b7756d6be6a8d48f4af96b731478354e", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val n = readLine()!!.toInt()\n val ay = readLine()!!.split(\" \").map { it.toInt() }\n val by = readLine()!!.split(\" \").map { it.toInt() }\n println(max(0, (0..2).map { ay[it] + by[(it + 1) % 3] }.max()!! - n))\n println((0..2).sumBy { min(ay[it], by[(it + 1) % 3]) })\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "flows", "math", "greedy"], "code_uid": "371c651ae8b48dcfabf0f0fdfed3e33a", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.*\nimport kotlin.collections.*\n\n\nprivate var fs = BufferedReader(InputStreamReader(System.`in`))\nprivate val out = StringBuilder()\nprivate fun readLn() = fs.readLine()!!\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readLong() = readLn().toLong()\nprivate fun readLongs() = readStrings().map { it.toLong() }\nprivate fun readInt() = readLn().toInt()\nprivate fun readInts() = readStrings().map { it.toInt() }\n\nfun main() {\n// val t = readInt()\n// for (tt in 0 until t) {\n solve()\n// }\n print(out)\n}\n\nprivate fun solve() {\n val n = readInt()\n val (rA,sA,pA) = readInts()\n val (rB,sB,pB) = readInts()\n val max = min(rA,sB) + min(sA,pB) + min(pA,rB)\n val min = min(rB,rA+sA) + min(sB,sA+pA) + min(pB,pA+rA)\n println(\"${n-min} $max\")\n\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "flows", "math", "greedy"], "code_uid": "089012bbe14267e8078abac8e8771b6d", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val n = readLine()!!.toInt()\n // 1: rock, 2: sci, 3: paper\n val (a1, a2, a3) = readLine()!!.split(\" \").map { it.toLong() }\n val (b1, b2, b3) = readLine()!!.split(\" \").map { it.toLong() }\n\n val minWon = max(0, a1 - (n - b2)) + max(0, a2 - (n - b3)) + max(0, a3 - (n - b1))\n\n val maxWon = min(a1, b2) + min(a2, b3) + min(a3, b1)\n\n println(\"$minWon $maxWon\")\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "flows", "math", "greedy"], "code_uid": "3d5b321438c756e9c7024ca4aed52174", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n val n = readInt()\n val (a1, a2, a3) = readInts()\n val (b1, b2, b3) = readInts()\n\n val bWinsOrDraw = min(b1, a1 + a2) + min(b2, a2 + a3) + min(b3, a1 + a3)\n val aWins = min(a1, b2) + min(a2, b3) + min(a3, b1)\n println(\"${n - bWinsOrDraw} $aWins\")\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", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "flows", "math", "greedy"], "code_uid": "12a03f03c84356144a1ffbe2c09a122a", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\n\nfun nextPermutation(array: MutableList): Boolean {\n var tmp: Int\n for (i in array.size - 2 downTo 0) {\n if (array[i] < array[i + 1]) {\n for (j in array.size - 1 downTo i + 1) {\n if (array[j] > array[i]) {\n tmp = array[i]\n array[i] = array[j]\n array[j] = tmp\n\n val tmpArray = array.takeLast(array.size - (i + 1)).sorted()\n tmpArray.forEachIndexed { index, e ->\n array[i + 1 + index] = e\n }\n\n return true\n }\n }\n }\n }\n return false\n}\n\nfun PrintWriter.solve(sc: FastScanner) {\n val n = sc.nextInt()\n val a = Array(3) { sc.nextInt() }\n val b = Array(3) { sc.nextInt() }\n var ans1 = Int.MAX_VALUE\n val ord = arrayOf(0 to 0, 0 to 2, 1 to 1, 1 to 0, 2 to 2, 2 to 1)\n var p = (0 until 6).toMutableList()\n do {\n val a1 = a.copyOf()\n val b1 = b.copyOf()\n for (i in 0 until 6) {\n val j = ord[p[i]]\n val cnt = minOf(a1[j.first], b1[j.second])\n a1[j.first] -= cnt\n b1[j.second] -= cnt\n }\n val cur = minOf(a1[0], b1[1]) + minOf(a1[1], b1[2]) + minOf(a1[2], b1[0])\n ans1 = minOf(ans1, cur)\n } while (nextPermutation(p))\n val ans2 = minOf(a[0], b[1]) + minOf(a[1], b[2]) + minOf(a[2], b[0])\n println(\"$ans1 $ans2\")\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "flows", "math", "greedy"], "code_uid": "ac0888da901d802efaddb84f0cf14586", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "1e156c9b75e6979455aa571046b374eb", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "fa1ce851cb46e5b24561c846225b44cd", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "20c8f4a70e5015acae67b7748bc5caec", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "d3ec90de831d15115ab3d36bfe542323", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\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 var one = 0\n var two = 0\n\n for (i in 0 until n) {\n val num = ir.nextInt()\n if (num == 100)\n one++\n else\n two++\n }\n\n if (two % 2 == 0)\n if (one % 2 == 0)\n pw.print(\"YES\")\n else\n pw.print(\"NO\")\n else\n if (one > 0 && one % 2 == 0)\n pw.print(\"YES\")\n else\n pw.print(\"NO\")\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "5b038e67acfe7717ac0fd4677a0d39b8", "src_uid": "9679acef82356004e47b1118f8fc836a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val numApples = readInt()\n val numSmall = readInts().count { it == 100 }\n print(\n when {\n numSmall == 0 && numApples and 1 == 1 -> \"NO\"\n numSmall and 1 == 1 -> \"NO\"\n else -> \"YES\"\n }\n )\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "2902204fc8dec4ba6f4fe5f86d26d564", "src_uid": "9679acef82356004e47b1118f8fc836a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(a: Array) = with(java.util.Scanner(System.`in`)) {\n var n = nextInt()\n var m = nextInt()\n println(((n/m)+1)*m)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "68ae4150e8f00200c1a7d2988793fe38", "src_uid": "75f3835c969c871a609b978e04476542", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (n, k) = readLine()!!.split(\" \").map(String::toLong)\n print((n / k + 1) * k)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "f2903ccd095d917191d9f4571e6bd103", "src_uid": "75f3835c969c871a609b978e04476542", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "matrices", "constructive algorithms", "combinatorics"], "code_uid": "07c142ec33debc59a0e6a5a2662727d5", "src_uid": "ded299fa1cd010822c60f2389a3ba1a3", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "matrices", "constructive algorithms", "combinatorics"], "code_uid": "37756a6b21cab2cf99cf29bfc48e69c1", "src_uid": "ded299fa1cd010822c60f2389a3ba1a3", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "matrices", "constructive algorithms", "combinatorics"], "code_uid": "7f0ea98d5f0f9399ef23a8a515e49d2e", "src_uid": "ded299fa1cd010822c60f2389a3ba1a3", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "matrices", "constructive algorithms", "combinatorics"], "code_uid": "50048c11821e6042e269e63da2608837", "src_uid": "ded299fa1cd010822c60f2389a3ba1a3", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nconst val MAX = 15\nvar r = 0\nvar c = 0\nval rows = Array(MAX, {true})\nval cols = Array(MAX, {true})\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n r = scanner.nextInt()\n c = scanner.nextInt()\n\n val x = Array(MAX, {\"\"})\n\n for(i in 0 until r){\n x[i] = scanner.next()\n for(j in x[i].indices){\n rows[i] = rows[i] and (x[i][j] == '.')\n cols[j] = cols[j] and (x[i][j] == '.')\n }\n }\n\n var ans = 0\n for(i in 0 until r){\n for(j in 0 until c){\n ans += if(x[i][j] == '.' && (rows[i] || cols[j])) 1 else 0\n }\n }\n\n print(ans)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "87df3dd4eb93c45017ec3709ce8d4c12", "src_uid": "ebaf7d89c623d006a6f1ffd025892102", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n val (row, column) = r.readLine()!!.split(\" \").map { it.toInt() }\n val rs = mutableListOf()\n val cs = mutableSetOf()\n repeat(row){\n val v = r.readLine()!!\n var has = false\n for (i in 0..column-1){\n if (v[i]=='S'){\n cs += i\n has = true\n }\n }\n if (has) rs += it\n }\n val rsize = rs.size\n val csize = cs.size\n val ans = (row-rsize)*column + (column-csize)*rsize\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "4ff5dcb1281d80914a9d14221bd35fc5", "src_uid": "ebaf7d89c623d006a6f1ffd025892102", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 r = scanner.nextInt()\n val c = scanner.nextInt()\n val arr1 = TreeSet()\n val arr2 = TreeSet()\n for (i in 0 until r) {\n val str = scanner.next()\n for (j in 0 until c) {\n if (str[j] == 'S') {\n arr1.add(i)\n arr2.add(j)\n }\n }\n }\n var res = 0\n for (i in 0 until r)\n for (j in 0 until c)\n if (!arr1.contains(i) || !arr2.contains(j))\n res++\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//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//}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "4ab673111ebceaf799528f4c6e21c0d3", "src_uid": "ebaf7d89c623d006a6f1ffd025892102", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["games"], "code_uid": "c76a08797823c62fd03b97f21a5aea97", "src_uid": "4b9cf82967aa8441e9af3db3101161e9", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array){\n\tval (n, M) = readLine().toString().split(\" \").map{it.toInt()}\n\tval students = readLine().toString().split(\" \").map{it.toInt()}\n\tprint(\"0 \")\n\tfor(i in 1 until n){\n\t\tval currentStud = students[i]\n\t\tval bfrList = students.subList(0,i).sorted()\n\t\tvar sum = bfrList.sum() + currentStud\n\t\tvar sjebators = 0\n\t\tif (sum <= M){\n\t\t\tprint(\"0 \")\n\t\t}else{\n\t\t\twhile(sum > M){\n\t\t\t\tsjebators += 1\n\t\t\t\tsum = bfrList.subList(0, i - sjebators).sum() + currentStud\n\t\t\t\t//println(\"i: $i, time: ${students[i-1]}, sum: $sum, bfrList: bfrList: ${bfrList.subList(0, i - sjebators)}\")\n\t\t\t}\n\t\t\tprint(\"${sjebators} \")\n\t\t}\n\t}\n\tprintln()\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "greedy"], "code_uid": "e4019059ddd009257d66af211e54fe0d", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLine()!!.toInt()\nprivate fun readInts() = readLine()!!.split(\" \").map { it.toInt() }\nprivate fun readStrings() = readLine()!!.split(\" \")\n\nprivate fun printList(a: List) = println(a.joinToString(\" \"))\nprivate fun printListLines(a: List) = println(a.joinToString(\"\\n\"))\n\n// ---------------------------------------------------------------------------\n\nfun main() {\n val (n, M) = readInts()\n val ts = readInts()\n\n val out = IntArray(n) { 0 }\n val checked = mutableListOf()\n var sumChecked = 0\n var timeUsed = 0\n var maxTimeUsed = -1\n ts.forEachIndexed { i, t ->\n maxTimeUsed = M - t\n if (sumChecked > maxTimeUsed) {\n timeUsed = sumChecked\n while (timeUsed > maxTimeUsed) {\n out[i] += 1\n timeUsed -= checked[checked.size - out[i]]\n }\n }\n val insertionIdx = checked.binarySearch(t)\n checked.add(if (insertionIdx < 0) abs(insertionIdx) -1 else insertionIdx, t)\n sumChecked += t\n }\n println(out.joinToString(\" \"))\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "greedy"], "code_uid": "35e1919498146fa82df61058ea9e3d1a", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n\n val (n, M) = readInts()\n\n val studs = readInts()\n\n val sums = mutableListOf()\n\n var prev = 0\n for (stud in studs) {\n val s = stud + prev\n sums.add(s)\n prev = s\n }\n\n val arr = IntArray(n) { 0 }\n\n for (i in 0 until n) {\n if (sums[i] <= M) {\n arr[i] = 0\n } else {\n\n val sorted = studs.subList(0, i).sorted()\n var j = 0\n var acc = 0\n while (j < sorted.size) {\n if (acc + sorted[j] <= M - studs[i]) {\n acc += sorted[j]\n j ++\n } else {\n break\n }\n }\n\n arr[i] = sorted.size - j\n }\n }\n\n println(arr.joinToString(separator = \" \"))\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() }", "lang_cluster": "Kotlin", "tags": ["sortings", "greedy"], "code_uid": "6c2dd5902d928bd5a2e7626308970c36", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (n, M) = readInts()\n val ts = readInts()\n val sorted = ts.sortedDescending()\n val ans = ts.withIndex().map {\n\n val prev = ts.take(it.index)\n val d = M - prev.sum() - it.value\n\n if (d >= 0)\n 0\n else {\n var x = 0\n var ans = 0\n// println(\"ok\")\n for (t in prev.sortedDescending()) {\n ans++\n x += t\n// println(\"x = $x\")\n if (d + x >= 0)\n break\n }\n ans\n }\n }\n printList(ans)\n}\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 printList(l: List, d: String = \" \") = l.forEach { print(\"$it$d\") }.also { println() }\n\nprivate fun List.subList(fromIndex: Int): List = this.subList(fromIndex, this.size)\n", "lang_cluster": "Kotlin", "tags": ["sortings", "greedy"], "code_uid": "13e6a592ab9cb2b6ee1be0e0601c7771", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\n/* http://codeforces.com/problemset/problem/599/A */\n\nfun main() {\n val (d1, d2, d3) = readLine()!!.split(\" \").map { it.toInt() }\n val fullCycleTrip = d1 + d2 + d3\n val twoLegsTrip = 2 * d1 + 2 * d2\n val clockwiseTrip = (d1 + d3) * 2\n val antiClockwiseTrip = (d2 + d3) * 2\n println(min(min(fullCycleTrip, twoLegsTrip), min(clockwiseTrip, antiClockwiseTrip)))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "accdd544990c8922ed417d6a1804b9b9", "src_uid": "26cd7954a21866dbb2824d725473673e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Integer.min\n\nfun main(args: Array) {\n val l=readLine()!!.split(\" \").map(String::toInt).sorted()\n print(l[0]+l[1]+min(l[0]+l[1],l[2]))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "30974528bdb8fcd5c6a485ad92b75170", "src_uid": "26cd7954a21866dbb2824d725473673e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun readInts() : List {\n val x_nullable_str = readLine()\n if (x_nullable_str == null) {\n throw Exception(\"Could not read ints.\")\n } else {\n val x_str = x_nullable_str\n val xs = x_str.split(' ').map(String::toInt)\n return xs\n }\n}\n\nfun min_2(a : Int, b : Int) : Int {\n when (a < b) {\n true -> return a\n else -> return b\n }\n}\n\nfun min_4(a : Int, b : Int, c : Int, d : Int) : Int {\n return min_2(min_2(a, b), min_2(c, d))\n}\n\nfun main(args : Array) {\n val a_b_c = readInts()\n if (a_b_c.size < 3) {\n throw Exception(\"Did not get 3 integers as input.\")\n }\n val a = a_b_c[0]\n val b = a_b_c[1]\n val c = a_b_c[2]\n val cost_1 = a + b + c\n val cost_2 = 2 * (a + b)\n val cost_3 = 2 * (b + c)\n val cost_4 = 2 * (c + a)\n val min_cost = min_4(cost_1, cost_2, cost_3, cost_4)\n println(\"${min_cost}\")\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c5e39d60f9dc264417a191dbab0bd2a8", "src_uid": "26cd7954a21866dbb2824d725473673e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main(args: Array) {\n val d = readLine()!!.split(\" \").map { it.toLong() }\n println(min(d[1] + d[2] + min(d[0], d[1] + d[2]), 2 *(d[0] + min(d[1], d[2]))))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "211e6715be6f4eb943e5c418b827b97b", "src_uid": "26cd7954a21866dbb2824d725473673e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "math", "dp", "greedy", "strings"], "code_uid": "d03a133cc60d0a2837da9c81e01f78a3", "src_uid": "be66399c558c96566a6bb0a63d2503e5", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\nimport java.util.ArrayDeque as Deque\nimport kotlin.collections.ArrayList as List\nimport kotlin.collections.HashMap as HMap\nimport kotlin.collections.HashSet as HSet\n\n\nprivate val br = BufferedReader(InputStreamReader(System.`in`))\nprivate var st = StringTokenizer(\"\")\nprivate var pw = PrintWriter(System.out)\n\nfun main() {\n val n = nextInt()\n if (n == 0)\n println(15)\n if (n == 1)\n println(14)\n if (n == 2)\n println(12)\n if (n == 3)\n println(13)\n if (n == 4)\n println(8)\n if (n == 5)\n println(9)\n if (n == 6)\n println(10)\n if (n == 7)\n println(11)\n if (n == 8)\n println(0)\n if (n == 9)\n println(1)\n if (n == 10)\n println(2)\n if (n == 11)\n println(3)\n if (n == 12)\n println(4)\n if (n == 13)\n println(5)\n if (n == 14)\n println(6)\n if (n == 15)\n println(7)\n}\n\nprivate fun next(): String {\n if (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st.nextToken()\n}\n\nprivate fun nextInt() = next().toInt()\nprivate fun nextLong() = next().toLong()", "lang_cluster": "Kotlin", "tags": ["brute force", "bitmasks"], "code_uid": "b0208cd246764683a8b2dc3c15b64fde", "src_uid": "879ac20ae5d3e7f1002afe907d9887df", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun main(args : Array) {\n //====== Input preparations ========================================================\n// val fin = BufferedReader(FileReader(\"e.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 nextNum() = next() == \"1\"\n fun g1(a : Boolean, b : Boolean) = a.xor(b)\n fun g2(a : Boolean, b : Boolean) = a.or(b)\n fun g3(a : Boolean, b : Boolean) = a.and(b)\n val a = Array(11, {false})\n for (i in 0..3)\n a[i] = nextNum()\n a[4] = g1(a[0], a[1])\n a[5] = g2(a[2], a[3])\n a[6] = g3(a[1], a[2])\n a[7] = g1(a[0], a[3])\n a[8] = g3(a[4], a[5])\n a[9] = g2(a[6], a[7])\n a[10] = g1(a[8], a[9])\n\n// for (x in a)\n// fout.print(\"$x \")\n\n fout.print(if (a[10]) 1 else 0)\n\n fout.close()\n fin.close()\n}\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "05b4a44885de11968e2d028f8a8e2a6d", "src_uid": "879ac20ae5d3e7f1002afe907d9887df", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nval SMILEY = (\"0000000000000000000000000010101111110100000000000000000000000000\\n\" +\n \"0000000000000000000000101110101010010111110000000000000000000000\\n\" +\n \"0000000000000000000011101000100011010000100100000000000000000000\\n\" +\n \"0000000000000000011110101011111000011110101110100000000000000000\\n\" +\n \"0000000000000000110000001010000011110000101010110000000000000000\\n\" +\n \"0000000000000010011011111011101110100101100010010100000000000000\\n\" +\n \"0000000000000111001001000000101000111100110110110110000000000000\\n\" +\n \"0000000000011111101101101110111011100001100100100011100000000000\\n\" +\n \"0000000000111111111111000010000010001011001101101001110000000000\\n\" +\n \"0000000001111111111111111111101111111001111001111111111000000000\\n\" +\n \"0000000011111111111111111111111111111111111111111111111100000000\\n\" +\n \"0000000111111111111111111111111111111111111111111111111110000000\\n\" +\n \"0000000111111111111111111111111111111111111111111111111110000000\\n\" +\n \"0000001111111111111111111111111111111111111111111111111111000000\\n\" +\n \"0000011111111111111111111111111111111111111111111111111111100000\\n\" +\n \"0000011111111111111111111111111111111111111111111111111111100000\\n\" +\n \"0000111111111111111111111111111111111111111111111111111111110000\\n\" +\n \"0001111111111111111111111111111111111111111111111111111111111000\\n\" +\n \"0000011111111111111111111111111111111111111111111111111111111000\\n\" +\n \"0000000111111111111000100111111111111110001010111111111111100000\\n\" +\n \"0011000001111111110010001111111111111110100000001111111100000000\\n\" +\n \"0011110000011111000110100011111111111111101101100101100000001100\\n\" +\n \"0111111100000100011100111001111111111101001000110000000001111110\\n\" +\n \"0111111111000001001001101100011111111101101111100100001111111110\\n\" +\n \"0111111111111011011100000111001111111000100100001110111111111110\\n\" +\n \"0111111111000001000111011100011111111010111110100010010111111110\\n\" +\n \"1111111111110111010010010001001111110010010000110111000111111111\\n\" +\n \"1111111111100010010110111011101111010111011110011100010111111111\\n\" +\n \"1111111111101111110111100001001010000101001011110001110111111111\\n\" +\n \"1111111111100000100100111011100010101101101001000100100111111111\\n\" +\n \"1111111111110110111101101110001011100000111101011111101111111111\\n\" +\n \"1111111111100011100100100011101001110111100101110001000111111111\\n\" +\n \"1111111111111000001101110110111011000001001101100100010111111111\\n\" +\n \"1111111111111101101000010100001010010101101000110110111111111111\\n\" +\n \"1111111111110000111101010101011110110100101110011100011111111111\\n\" +\n \"1111111111111010010001110001111000100110000100110001111111111111\\n\" +\n \"1111111111111111000111000101101101101100101110100100111111111111\\n\" +\n \"1111111111111111110001011111100000111111100010001111111111111111\\n\" +\n \"0111111111111111100100001111101011111111111000100111111111111110\\n\" +\n \"0111111111111111111111111111111000011111111111111111111111111110\\n\" +\n \"0111111111111111111111111111010010111111111111111111111111111110\\n\" +\n \"0111111111111111111111111101000111111111111111111111111111111110\\n\" +\n \"0011111111111111111111111100010001111111111111111111111111111100\\n\" +\n \"0011111110011111111111111111110111111111111111111111111111111100\\n\" +\n \"0001111111010111111111111111100011111111111111111111101111111000\\n\" +\n \"0001111111000100011111111111001011111111111011111010000111111000\\n\" +\n \"0001111111010101001010001101011001010010110001100000101111111000\\n\" +\n \"0000111111110001100000100000001100011000000101001110111111110000\\n\" +\n \"0000011111110100111101111011100111000011101111101011111111100000\\n\" +\n \"0000011111111110100100100010111101110110100000100011111111100000\\n\" +\n \"0000001111111100001101101000010001010000111010001111111111000000\\n\" +\n \"0000000111111111011000111110110101000101100011111111111110000000\\n\" +\n \"0000000111111111001110010100011100010111001000111111111110000000\\n\" +\n \"0000000011111111100011110001110110111101111011111111111100000000\\n\" +\n \"0000000001111111110110000101000000100001011111111111111000000000\\n\" +\n \"0000000000111111111111010111101101101011001111111111110000000000\\n\" +\n \"0000000000011111111111110000111100001000011111111111100000000000\\n\" +\n \"0000000000000111111111111111111110111111111111111110000000000000\\n\" +\n \"0000000000000011111111111111111111111111111111111100000000000000\\n\" +\n \"0000000000000000111111111111111111111111111111110000000000000000\\n\" +\n \"0000000000000000011111111111111111111111111111100000000000000000\\n\" +\n \"0000000000000000000011111111111111111111111100000000000000000000\\n\" +\n \"0000000000000000000000111111111111111111110000000000000000000000\\n\" +\n \"0000000000000000000000000011111111111100000000000000000000000000\").split(\"\\n\")\n\nfun main() {\n val jin = Scanner(System.`in`)\n val y = jin.nextInt()\n val x = jin.nextInt()\n println(if (SMILEY[y][x] == '1') \"IN\" else \"OUT\")\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "geometry", "implementation"], "code_uid": "1d07977cab624b17f3dbde17b19b28a2", "src_uid": "879ac20ae5d3e7f1002afe907d9887df", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.awt.image.BufferedImage\nimport java.io.File\nimport java.lang.Math.abs\nimport java.util.*\nimport javax.imageio.ImageIO\n\nval matrix = arrayOf(\n \"..........................0.0.000000.0..........................\",\n \"......................0.000.0.0.0..0.00000......................\",\n \"....................000.0...0...00.0....0..0....................\",\n \".................0000.0.0.00000....0000.0.000.0.................\",\n \"................00......0.0.....0000....0.0.0.00................\",\n \"..............0..00.00000.000.000.0..0.00...0..0.0..............\",\n \".............000..0..0......0.0...0000..00.00.00.00.............\",\n \"...........000000.00.00.000.000.000....00..0..0...000...........\",\n \"..........000000000000....0.....0...0.00..00.00.0..000..........\",\n \".........00000000000000000000.0000000..0000..0000000000.........\",\n \"........000000000000000000000000000000000000000000000000........\",\n \".......00000000000000000000000000000000000000000000000000.......\",\n \".......00000000000000000000000000000000000000000000000000.......\",\n \"......0000000000000000000000000000000000000000000000000000......\",\n \".....000000000000000000000000000000000000000000000000000000.....\",\n \".....000000000000000000000000000000000000000000000000000000.....\",\n \"....00000000000000000000000000000000000000000000000000000000....\",\n \"...0000000000000000000000000000000000000000000000000000000000...\",\n \".....00000000000000000000000000000000000000000000000000000000...\",\n \".......000000000000...0..00000000000000...0.0.0000000000000.....\",\n \"..00.....000000000..0...000000000000000.0.......00000000........\",\n \"..0000.....00000...00.0...000000000000000.00.00..0.00.......00..\",\n \".0000000.....0...000..000..00000000000.0..0...00.........000000.\",\n \".000000000.....0..0..00.00...000000000.00.00000..0....000000000.\",\n \".000000000000.00.000.....000..0000000...0..0....000.00000000000.\",\n \".000000000.....0...000.000...00000000.0.00000.0...0..0.00000000.\",\n \"000000000000.000.0..0..0...0..000000..0..0....00.000...000000000\",\n \"00000000000...0..0.00.000.000.0000.0.000.0000..000...0.000000000\",\n \"00000000000.000000.0000....0..0.0....0.0..0.0000...000.000000000\",\n \"00000000000.....0..0..000.000...0.0.00.00.0..0...0..0..000000000\",\n \"000000000000.00.0000.00.000...0.000.....0000.0.000000.0000000000\",\n \"00000000000...000..0..0...000.0..000.0000..0.000...0...000000000\",\n \"0000000000000.....00.000.00.000.00.....0..00.00..0...0.000000000\",\n \"00000000000000.00.0....0.0....0.0..0.0.00.0...00.00.000000000000\",\n \"000000000000....0000.0.0.0.0.0000.00.0..0.000..000...00000000000\",\n \"0000000000000.0..0...000...0000...0..00....0..00...0000000000000\",\n \"0000000000000000...000...0.00.00.00.00..0.000.0..0..000000000000\",\n \"000000000000000000...0.000000.....0000000...0...0000000000000000\",\n \".0000000000000000..0....00000.0.00000000000...0..00000000000000.\",\n \".000000000000000000000000000000....0000000000000000000000000000.\",\n \".000000000000000000000000000.0..0.00000000000000000000000000000.\",\n \".0000000000000000000000000.0...00000000000000000000000000000000.\",\n \"..000000000000000000000000...0...00000000000000000000000000000..\",\n \"..0000000..0000000000000000000.0000000000000000000000000000000..\",\n \"...0000000.0.0000000000000000...000000000000000000000.0000000...\",\n \"...0000000...0...00000000000..0.00000000000.00000.0....000000...\",\n \"...0000000.0.0.0..0.0...00.0.00..0.0..0.00...00.....0.0000000...\",\n \"....00000000...00.....0.......00...00......0.0..000.00000000....\",\n \".....0000000.0..0000.0000.000..000....000.00000.0.000000000.....\",\n \".....0000000000.0..0..0...0.0000.000.00.0.....0...000000000.....\",\n \"......00000000....00.00.0....0...0.0....000.0...0000000000......\",\n \".......000000000.00...00000.00.0.0...0.00...0000000000000.......\",\n \".......000000000..000..0.0...000...0.000..0...00000000000.......\",\n \"........000000000...0000...000.00.0000.0000.000000000000........\",\n \".........000000000.00....0.0......0....0.00000000000000.........\",\n \"..........000000000000.0.0000.00.00.0.00..000000000000..........\",\n \"...........0000000000000....0000....0....000000000000...........\",\n \".............00000000000000000000.00000000000000000.............\",\n \"..............000000000000000000000000000000000000..............\",\n \"................00000000000000000000000000000000................\",\n \".................000000000000000000000000000000.................\",\n \"....................000000000000000000000000....................\",\n \"......................00000000000000000000......................\",\n \"..........................000000000000..........................\"\n)\n\nfun main() {\n// val sc = Scanner(File(\"input-e.txt\"))\n val sc = Scanner(System.`in`)\n SolutionE().doSolve(sc)\n}\n\nclass SolutionE {\n fun doSolve(sc: Scanner) {\n val row = sc.nextInt()\n val col = sc.nextInt()\n\n val sym = matrix[row][col]\n if (sym == '.') {\n println(\"OUT\")\n } else {\n println(\"IN\")\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "geometry", "implementation"], "code_uid": "0cfef79832db12c3ad720585d0d14d8c", "src_uid": "879ac20ae5d3e7f1002afe907d9887df", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "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 readInts() = inf.readLine()!!.split(' ').map(String::toInt)\nfun readLongs() = inf.readLine()!!.split(' ').map(String::toLong)\nfun readString() = inf.readLine()!!\n\nfun main() {\n val s = readString()\n var ans = \"YES\"\n for (i in 2 until s.length) {\n if (s[i] - 'A' != ((s[i - 1] - 'A') + (s[i - 2] - 'A')) % 26) ans = \"NO\"\n }\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "068cdc4877d259e5f055c604a3d138a8", "src_uid": "27e977b41f5b6970a032d13e53db2a6a", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main(args: Array) {\n val s = readLine()!!\n val n = s.length\n for (i in 2 until n) {\n val a = s[i-2]-'A'\n val b = s[i-1]-'A'\n val c = s[i]-'A'\n if ((a+b)%26 != c) {\n println(\"NO\")\n return\n }\n }\n println(\"YES\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "080aef9e155397d5c89374c9688200a7", "src_uid": "27e977b41f5b6970a032d13e53db2a6a", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main() {\r\n val T = 1;\r\n// val T=readLine()!!.toInt();\r\n repeat(T) {\r\n val s = readLine()!!\r\n val n = s.length\r\n var f = true\r\n for(i in 2..n-1) {\r\n var a = (s[i - 1] - 'A')\r\n var b = (s[i - 2] - 'A')\r\n var c = (a+b) % 26\r\n var char = (c.toChar());\r\n char = char + 'A'.toInt()\r\n if(s[i] != char) {\r\n f = false\r\n break\r\n }\r\n }\r\n if(f) println(\"YES\")\r\n else print(\"NO\")\r\n }\r\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "85fd55c481c26b943ca80cb364714b82", "src_uid": "27e977b41f5b6970a032d13e53db2a6a", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import kotlin.math.*;\nimport java.math.BigInteger;\nimport java.util.StringTokenizer;\nimport java.util.TreeSet;\n\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n@JvmField val MOD = 998244353;\n@JvmField val exp2sact_cache = HashMap>();\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 readInt2() = Pair(readInt(),readInt())\nfun readInt3() = Triple(readInt(),readInt(),readInt())\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readLong2() = Pair(readLong(),readLong())\nfun readLong3() = Triple(readLong(),readLong(),readLong())\nfun readString() = readLine()!!;\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() }\nfun printVars(vararg vs: Any?){for(v in vs) print(\"$v \");println(\"\");}\nfun moduloAdd(v1: Int,v2: Int) = ((v1+0L+v2)%MOD).toInt();\nfun moduloMultiply(v1: Int,v2: Int) = ((v1*1L*v2)%MOD).toInt();\nfun exp2s(v: Int): List{var targ = v;var es = mli();var e = 0;while(targ>0){if (targ%2==1) es.add(e);targ/= 2;e++;};return es;}\nfun exp2sact(v: Int): List\n{\n if (exp2sact_cache[v]!=null) return exp2sact_cache[v]!!;\n var targ = v;\n var es = mli();\n var e = 1;\n while(targ>0)\n {\n if (targ%2==1) es.add(e);\n targ/= 2;e*= 2;\n };\n exp2sact_cache[v] = es;\n return es;\n}\nfun iLog2(v:Int):Int{var ret=0;var vv= v shr 1;while(vv>0){ret++;vv=vv shr 1};return ret}\nfun iLog2(v:Long):Int{var ret=0;var vv= v shr 1;while(vv>0){ret++;vv=vv shr 1};return ret}\nfun tri(n: Int) = (n*(n+1))/2;\nfun tri(n: Long) = (n*(n+1))/2;\nfun isEven(v: Int) = v%2==0;\nfun isOdd(v: Int) = v%2==1;\nfun isEven(v: Long) = v%2L==0L;\nfun isOdd(v: Long) = v%2L==1L;\ninfix fun Int.between(range: Pair): Boolean = ((this >= range.first) && (this <= range.second));\ninfix fun Long.between(range: Pair): Boolean = ((this >= range.first) && (this <= range.second));\nfun mli() = mutableListOf();\nfun mlid(n: Int,def: (it: Int) -> Int) = MutableList(n,def);\nfun mll() = mutableListOf();\nfun mlld(n: Int,def: (it: Int) -> Long) = MutableList(n,def);\nfun trsti() = TreeSet();\nfun trstl() = TreeSet();\nfun hmii() = HashMap();\nfun hmil() = HashMap();\nfun hmli() = HashMap();\nfun hmll() = HashMap();\nclass MultiSet(initContent: List = listOf()){private val mp = HashMap();init {for(x in initContent) add(x);}operator fun get(value: T): Int{return if (mp[value]!=null) mp[value]!! else 0;}fun add(value: T,count: Int = 1): Int{if (count < 0) throw Exception(\"count must be non-negative\");if (mp[value]==null) mp[value] = 0;var ret = mp[value]!!+count;mp[value] = ret;return ret;}fun remove(value: T,count: Int = 1): Int{if (count < 0) throw Exception(\"count must be non-negative\");var ret = this[value];ret = max(0,ret-count);if (ret==0){mp.remove(value);}else{mp[value] = ret;};return ret;}fun delete(value: T): Int{var ret = this[value];mp.remove(value);return ret;}val size get() = mp.size;operator fun iterator(): MutableIterator> = mp.iterator();override fun toString() = \"$mp\";}\nfun List.floor(v: Int): Int{var pos=binarySearch(v);if (pos>= 0){return pos;}else{return -(pos+1)-1;};}\nfun List.ceiling(v: Int): Int{var pos=binarySearch(v);if (pos>=0){return pos;}else{var ret = -(pos+1);return if (ret < size) ret else -1;}}\nfun List.floor(v: Long): Int{var pos=binarySearch(v);if (pos>= 0){return pos;}else{return -(pos+1)-1;};}\nfun List.ceiling(v: Long): Int{var pos=binarySearch(v);if (pos>=0){return pos;}else{var ret = -(pos+1);return if (ret < size) ret else -1;}}\nfun gcd(a: Int,b: Int): Int{if (b==0) return a;return gcd(b,a%b);}\nfun gcd(a: Long,b: Long): Long{if (b==0L) return a;return gcd(b,a%b);}\n\n@JvmField val DEBUG = false;\n\nclass Prob\n{\n fun exec()\n { \n var s = readString();\n var ls = s.map { it-'A' }.toList();\n if (ls.size>2)\n {\n var flag = true;\n for(i in 2..ls.size-1)\n {\n if (ls[i]!=(ls[i-2]+ls[i-1])%26)\n {\n flag = false;\n break;\n }\n }\n println(if (flag) \"YES\" else \"NO\");\n }\n else\n {\n println(\"YES\");\n }\n }\n}\n\nfun main() \n{\n Prob().exec();\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "df2cf24654abb2a9be27f7d9c731f595", "src_uid": "27e977b41f5b6970a032d13e53db2a6a", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLine()!!\n var sol = if (s.contains(\"VVV\") || s.contains(\"KKK\") ||\n s.startsWith(\"KK\") || s.endsWith(\"VV\")\n ) 1 else 0\n for (pos in 0 until s.length - 1) if (s[pos] == 'V' && s[pos + 1] == 'K') sol++\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "13d479971a05d6afab87fa85c5fb7ced", "src_uid": "578bae0fe6634882227ac371ebb38fc9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.FileInputStream\nimport java.math.BigDecimal\nimport java.math.BigInteger\n\nfun main(args: Array) {\n if (args.size > 0) {\n input = FileInputStream(args[0])\n }\n var str = nextString()\n var tokens = str!!.split(\"VK\")\n var ans = tokens.size - 1 + if (tokens.filter { it.length > 1 && it != \"KV\" }.isNotEmpty()) 1 else 0\n println(ans)\n}\n\nfun String.toBigInteger() = BigInteger(this)\nfun String.toBigDecimal() = BigDecimal(this)\n\nvar input = System.`in`\n\nval sb = StringBuilder()\nval buffer = ByteArray(4096)\nvar pos = 0\nvar size = 0\n\nfun 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\nfun 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\nfun 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\nfun nextInt() = nextLong().toInt()\nfun nextDouble() = nextString()?.toDouble() ?: 0.0\nfun nextBigInteger(): BigInteger = nextString()?.toBigInteger() ?: BigInteger.ZERO\nfun nextBigDecimal(): BigDecimal = nextString()?.toBigDecimal() ?: BigDecimal.ZERO\n\nfun nextStrings(n: Int) = Array(n) { nextString() ?: \"\" }\nfun nextInts(n: Int) = IntArray(n) { nextInt() }\nfun nextLongs(n: Int) = LongArray(n) { nextLong() }\nfun nextDoubles(n: Int) = DoubleArray(n) { nextDouble() }\nfun nextBigIntegers(n: Int) = Array(n) { nextBigInteger() }\nfun nextBigDecimals(n: Int) = Array(n) { nextBigDecimal() }\n\nfun nextStrings(n: Int, m: Int) = Array(n) { nextStrings(m) }\nfun nextInts(n: Int, m: Int) = Array(n) { nextInts(m) }\nfun nextLongs(n: Int, m: Int) = Array(n) { nextLongs(m) }\nfun nextDoubles(n: Int, m: Int) = Array(n) { nextDoubles(m) }\nfun nextBigIntegers(n: Int, m: Int) = Array(n) { nextBigIntegers(m) }\nfun nextBigDecimals(n: Int, m: Int) = Array(n) { nextBigDecimals(m) }\n\nprivate fun skipWhitespace(): Int {\n while (true) {\n val c = read()\n if (c > ' '.toInt() || c < 0) return c\n }\n}\n\nprivate 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}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "96e05f1db9b1595a1e9f24424ca5adc6", "src_uid": "578bae0fe6634882227ac371ebb38fc9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val tokens = readLine()!!.split(\"VK\")\n val ans = tokens.size - 1 + if (tokens.filter { it.length > 1 && it != \"KV\" }.isNotEmpty()) 1 else 0\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "9eec7a67c092c647d8da538ec5e486da", "src_uid": "578bae0fe6634882227ac371ebb38fc9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = \"K\" + readLine()!! + \"V\"\n var answer = 0\n var addend = 0\n for (j in 0..s.length - 2) {\n if (s.substring(j, j + 2) == \"VK\") {\n answer++\n }\n if (j <= s.length - 3 && (s.substring(j, j + 3) == \"VVV\" || s.substring(j, j + 3) == (\"K\" + \"KK\"))) {\n addend = 1\n }\n }\n println(answer + addend)\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "db51f82c2fa8a2e1213529a62f0f0186", "src_uid": "578bae0fe6634882227ac371ebb38fc9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val inp = Scanner(System.`in`)\n var n = inp.nextInt()\n if (n != 0) {\n n %= 4\n if (n == 0) n = 4\n print(pow(8, n) % 10)\n } else print(1)\n}\n\nprivate fun pow(a: Int, b: Int): Int {\n var p = 1\n for (i in 1..b)\n p *= a\n return p\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "ce835a04402773fa636689c823f30c75", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val results = intArrayOf(8, 4, 2, 6)\n val n = readLine()!!.toInt()\n print(if (n == 0) 1 else results[(n - 1) % 4])\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "2f39fb5b8784982540ab25fd2e6c4b9e", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun DataReader.solve(out: PrintWriter) {\n val nextInt = nextInt()\n val n = if(nextInt > 0) ((nextInt - 1) % 4) + 1 else nextInt\n\n out.println((1..n).map { 8 }.fold(1, Int::times) % 10)\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", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "97427e33fbb3389513dc4795ddde37a4", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val (a, b, k) = r.readLine()!!.split(\" \").map { it.toLong() }\n\n var l = r.readLine()!!.toInt()\n var base = 8\n var ans = 1\n while (l>0){\n if (l%2==1){\n ans = ans * base%10\n }\n base = base*base%10\n l /=2\n }\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "9788eb6d957c2e0dd49d2d1035084624", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val chain = readLine()!!.toCharArray()\n checkChain(chain)\n}\n\nfun checkChain(chain: CharArray) {\n val char1 = '-'\n val char0 = 'o'\n\n val char1Count = chain.filter { it == char1 }.count()\n val char0Count = chain.filter { it == char0 }.count()\n\n if (char0Count == 0 || char1Count == 0) return print(\"YES\")\n\n when {\n char0Count > char1Count -> return print(\"NO\")\n char0Count < char1Count -> return if (char1Count % char0Count == 0) print(\"YES\") else print(\"NO\")\n char0Count == char1Count -> return print(\"YES\")\n else -> {\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "0f1407e2a2e2004bc57ca8693b18be30", "src_uid": "6e006ae3df3bcd24755358a5f584ec03", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array){\n\t// 0 -businka\n\t// 1 - nit'\n\tval busy = readLine().toString().map{if (it =='o') 0 else 1}\n\tval length = busy.size\n\tval nitN = busy.sum()\n\tval busyN = length - nitN\n\t//println(\"$busyN $nitN\")\n\tif (busyN == 0){\n\t\tprintln(\"YES\")\n\t\treturn\n\t}\n\tval zlp = nitN.rem(busyN)\n\tif (zlp == 0) println(\"YES\") else println(\"NO\")\n\t\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "fdc6d163e22fc1038025ac12fa344b80", "src_uid": "6e006ae3df3bcd24755358a5f584ec03", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val a = readLine()!!\n val b = a.count{it=='o'}\n val n = a.count{it=='-'}\n // --o--o--o\n if(n == 0 || b == 0) {\n print(\"YES\")\n } else print(\n if(n % b == 0) \"YES\" else \"NO\"\n )\n}\n\n\n\n\n\n\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "796c1532717033bb0325f2fb7c2e37c0", "src_uid": "6e006ae3df3bcd24755358a5f584ec03", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val necklace = readLine()!!\n val numPearls = necklace.count { it == 'o' }\n if (numPearls == 0) return print(\"YES\")\n print(if ((necklace.length - numPearls) % numPearls == 0) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "0316f4c9e6d458cb6dfe700d6d02b572", "src_uid": "6e006ae3df3bcd24755358a5f584ec03", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.StringBuilder\n\nfun main() {\n var s = StringBuilder(readLine())\n var arr = arrayOf(\"Nikita\",\"Olya\",\"Slava\",\"Danil\",\"Ann\")\n var k = 0\n arr.forEach { i->\n if(s.indexOf(i) != -1) {\n k += 1\n var t = s.indexOf(i) + i.length -1\n var d = s.substring(t)\n if(d.indexOf(i) != -1) {\n k += 1\n }\n }\n }\n if(k == 1) {\n print(\"YES\")\n }\n else {\n print(\"NO\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "e5e6659601f9ac9040a694bc671c1fed", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val names = arrayOf(\"Danil\", \"Olya\", \"Slava\", \"Ann\", \"Nikita\")\n val text = readLine()!!\n var found = 0\n for (it in names) {\n var start = text.indexOf(it)\n if (start != -1) {\n found ++\n start = text.indexOf(it, start + 1)\n if (start != -1) found++\n }\n if (found > 1) break\n }\n if (found == 1) print(\"YES\") else print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "6252dd49b449c7abb869bdf98b381c65", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val names = listOf(\"Danil\", \"Olya\", \"Slava\", \"Ann\", \"Nikita\")\n\n val contest = readLine()!!\n val count = names.map { contest.split(it).size - 1 }.sum()\n println(if (count == 1) \"YES\" else \"NO\")\n\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "e2544957921d9a9b5fdff27284991b9f", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "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_007\nfun powMod(a: Long, n: Long, mod: Int): Long {\n if (n == 0L) return 1\n val res = powMod(a * a % mod, 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 private val reader = BufferedReader(InputStreamReader(stream), 32768)\n\n fun solve() {\n val S = ns()\n val N = S.length\n var ans = 0\n\n for (num in 0 until 100_000_000) {\n if (num % 25 != 0) continue\n val numStr = num.toString()\n if (numStr.length != N) continue // 0\u3092\u542b\u3080leading0\u304c\u306a\u3044\u6570\u5024\n\n var x = -1\n var ok = true\n for (i in numStr.indices) {\n when(S[i]) {\n '_' -> {}\n 'X' -> {\n if (x == -1) {\n x = numStr[i] - '0'\n } else {\n ok = ok && numStr[i] - '0' == x\n }\n }\n else -> ok = ok && numStr[i] == S[i]\n }\n }\n if (ok) ans++\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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\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 IntArray(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 debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n /**\n * \u30b3\u30fc\u30ca\u30fc\u30b1\u30fc\u30b9\u3067\u30a8\u30e9\u30fc\u51fa\u305f\u308a\u3059\u308b\u306e\u3067\u3001debug(dp[1])\u306e\u3088\u3046\u306b\u6dfb\u3048\u5b57\u4ed8\u304d\u306e\u5834\u5408\u306fdebug{}\u3092\u3064\u304b\u3046\u3053\u3068\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 { toString(a) }\n }\n\n private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString(\"\")}\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 private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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 private inline fun assert(b: Boolean, f: () -> String) = run{if (!b) throw AssertionError(f())}\n\n companion object {\n // TestRunner\u304b\u3089\u547c\u3073\u305f\u3044\u306e\u3067\u5358\u7d14\u306amain\u3058\u3083\u3060\u3081\n fun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n }\n }\n}\n\n/**\n * judge\u304b\u3089\u547c\u3070\u308c\u308b\n */\nfun main() = Solver.main()", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "dfs and similar"], "code_uid": "56aeb401556d3d5808d46c1f2f349fd2", "src_uid": "4a905f419550a6c839992b40f1617af3", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "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_007\nfun powMod(a: Long, n: Long, mod: Int): Long {\n if (n == 0L) return 1\n val res = powMod(a * a % mod, 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 private val reader = BufferedReader(InputStreamReader(stream), 32768)\n\n fun solve() {\n val S = ns()\n val Ss = (0 until 10).map { S.replace('X', '0'+it) }.distinct()\n val ans = Ss.map(::solve2).sum()\n out.println(ans)\n }\n\n fun solve2(S: String): Int {\n debug{\"solve2($S)\"}\n val N = S.length\n if (N < 3) {\n return solve_naive(S)\n }\n\n val head = S.take(max(0, N - 2)) // 0\u304b\u3082\u3057\u308c\u306a\u3044\n val fst = head.take(1)\n val snd = head.drop(1)\n val tail = S.drop(head.length)\n\n fun countTail(): Int {\n var cnt = 0\n for (num in 0 until 100) {\n if (num % 25 == 0 && accepts(tail, num) != null) cnt++\n }\n return cnt\n }\n\n fun countHead(): Int {\n if (fst.isEmpty()) return 1\n\n val c1 = when(fst[0]) {\n '_' -> 9\n '0' -> 0\n else -> 1\n }\n val underscores = snd.count { it == '_' }\n val c2 = powMod(10, underscores.toLong(), MOD).toInt()\n return c1 * c2\n }\n\n debug{\"countTail: ${countTail()} countHead${countHead()}\"}\n return countTail() * countHead()\n }\n\n fun solve_naive(S: String): Int {\n val N = S.length\n val max = powMod(10, N.toLong(), MOD).toInt()\n var cnt = 0\n for (num in 0 until max) {\n if (num % 25 != 0) continue\n val res = accepts(S, num) ?: continue\n if (res.length == 1 || res[0] != '0') cnt++\n }\n return cnt\n }\n\n fun accepts(S: String, num: Int): String? {\n val numStr = (\"00$num\").takeLast(S.length)\n val ok = numStr.indices.all { S[it] == '_' || S[it] == numStr[it] }\n return if (ok) numStr else null\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\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 IntArray(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 debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n /**\n * \u30b3\u30fc\u30ca\u30fc\u30b1\u30fc\u30b9\u3067\u30a8\u30e9\u30fc\u51fa\u305f\u308a\u3059\u308b\u306e\u3067\u3001debug(dp[1])\u306e\u3088\u3046\u306b\u6dfb\u3048\u5b57\u4ed8\u304d\u306e\u5834\u5408\u306fdebug{}\u3092\u3064\u304b\u3046\u3053\u3068\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 { toString(a) }\n }\n\n private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString(\"\")}\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 private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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 private inline fun assert(b: Boolean, f: () -> String) = run{if (!b) throw AssertionError(f())}\n\n companion object {\n // TestRunner\u304b\u3089\u547c\u3073\u305f\u3044\u306e\u3067\u5358\u7d14\u306amain\u3058\u3083\u3060\u3081\n fun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n }\n }\n}\n\n/**\n * judge\u304b\u3089\u547c\u3070\u308c\u308b\n */\nfun main() = Solver.main()", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "dfs and similar"], "code_uid": "05b610687ad8ea502606d75d8216fe35", "src_uid": "4a905f419550a6c839992b40f1617af3", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array){\n\tval (_, _, roubles) = readLine().toString().split(\" \").map{it.toInt()}\n\tval minBuy = readLine().toString().split(\" \").map{it.toInt()}.sorted().first()\n\tval maxSell = readLine().toString().split(\" \").map{it.toInt()}.sorted().last()\n\tval result = if((minBuy < maxSell) and (roubles >= minBuy)) (roubles / minBuy) * maxSell + roubles.rem(minBuy) else roubles\n\tprintln(result)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "cb9a4ff836fe1f82e23660ca118e4e4f", "src_uid": "42f25d492bddc12d3d89d39315d63cb9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package cf1150\n\nimport java.util.*\n\nclass A {\n fun solve() {\n var st = StringTokenizer(readLine())\n val n = st.nextToken().toInt()\n val m = st.nextToken().toInt()\n val r = st.nextToken().toInt()\n\n st = StringTokenizer(readLine())\n val a = IntArray(n)\n for (i in 0 until n) {\n a[i] = st.nextToken().toInt()\n }\n\n st = StringTokenizer(readLine())\n val b = IntArray(m)\n for (i in 0 until m) {\n b[i] = st.nextToken().toInt()\n }\n a.sort()\n b.sortDescending()\n var res = r\n if (a[0] < b[0]) {\n val dd = (r / a[0]) * b[0]\n res = (res % a[0]) + dd\n }\n println(res)\n }\n}\n\nfun main(args: Array) {\n A().solve()\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "9352143f0c731e98a4935f562a8f540e", "src_uid": "42f25d492bddc12d3d89d39315d63cb9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n var list = readLine()!!.split(' ').map { it.toInt() }\n var list1 = readLine()!!.split(' ').map { it.toInt() }\n var list2 = readLine()!!.split(' ').map { it.toInt() }\n\n var mainMax = list[2]\n\n var min = list1.min()!!\n var number = list[2]/min\n var max = list2.max()!!\n\n if ((number*max+(list[2]%min))>mainMax){\n println((number*max+(list[2]%min)))\n }else{\n println(mainMax)\n }\n\n\n\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "5bb547a981959bebb745f620c30aef61", "src_uid": "42f25d492bddc12d3d89d39315d63cb9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (_, _, bourles) = readInts()\n val buy = readInts().min()!!\n val sell = readInts().max()!!\n print(max(bourles, bourles % buy + sell * (bourles / buy)))\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "484eada3f6477b7ab64ae8bdc4d4faac", "src_uid": "42f25d492bddc12d3d89d39315d63cb9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// Star because this code solves the problem, but in the tutorial there is a better solution using GCD\n//fun main() {\n// fun readInt() = readLine()!!.toInt()\n// fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n//\n// val n = readInt()\n// val nums = readInts().toIntArray()\n// var minimum = nums.min()!!\n// do {\n// for (pos in 0 until n) {\n// nums[pos] %= minimum\n// if (nums[pos] == 0) nums[pos] = minimum\n// }\n// minimum = nums.min()!!\n// } while (minimum != nums.max()!!)\n// print(minimum * n)\n//}\n\n// solution from tutorial\nfun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n infix fun Int.maxMin(b: Int): Pair = if (this >= b) this to b else b to this\n fun gcd(a: Int, b: Int): Int {\n var (max, min) = a maxMin b\n while (min != 0) {\n val newMin = max % min\n max = min\n min = newMin\n }\n return max\n }\n\n val n = readInt()\n val nums = readInts()\n val gcdNums = nums.reduce(::gcd)\n print(gcdNums * n)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "430fb90cf5dda196804c5da63112aa59", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val n = readInt()\n val nums = readInts().toIntArray()\n var minimum = nums.min()!!\n do {\n for (pos in 0 until n) {\n nums[pos] %= minimum\n if (nums[pos] == 0) nums[pos] = minimum\n }\n minimum = nums.min()!!\n } while (minimum != nums.max()!!)\n print(minimum * n)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "284074774ac2fb4f3018d09c45c3c4b5", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n\n readLine()\n var list = readLine()!!.split(\" \").map { it.toInt() }.sorted().toMutableList()\n var max = list.max()\n var min = list.min()\n\n while (max != min){\n list[list.size-1] = list[list.size-1]-list[0]\n max = list.max()\n min = list.min()\n list.sort()\n }\n println(list.sum())\n\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "808cc8ca91d4be37d5b0a9fe72291f7e", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.pow\nimport kotlin.math.sqrt\n \nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val len = r.readLine()!!.toInt()\n val (radius, x, y, x1, y1) = r.readLine()!!.split(\" \").map { it.toDouble() }\n val dis = sqrt((x-x1).pow(2)+(y-y1).pow(2))\n val ans = (dis/(2*radius)).toInt() + if (dis%(2*radius)!=0.0) 1 else 0\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["math", "geometry"], "code_uid": "386dd65727a445ed63a91227e4e4ad93", "src_uid": "698da80c7d24252b57cca4e4f0ca7031", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\nimport kotlin.math.ceil\nimport kotlin.math.sqrt\n\nfun 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 (r, x, y, x2, y2) = readLongs()\n val d = sqrt(((x - x2) * (x - x2) + (y - y2) * (y - y2)).toDouble())\n print(ceil(d / (r * 2)).toLong())\n}", "lang_cluster": "Kotlin", "tags": ["math", "geometry"], "code_uid": "57c78672263a4d8aebe5628c68805911", "src_uid": "698da80c7d24252b57cca4e4f0ca7031", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// 8/5/2020 7:05 AM\n/*\nhttps://codeforces.com/problemset/problem/507/B\n */\n//package p507\n\nimport kotlin.math.ceil\nimport kotlin.math.sqrt\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 (r, x, y, x2, y2) = readInts().map{ it.toLong() }\n val distanceTo = sqrt(((x-x2)*(x-x2) + (y-y2)*(y-y2)).toDouble())\n\n println( ceil((distanceTo) / (2*r)).toInt() )\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "geometry"], "code_uid": "948d84cc8e9972f48901c934c6b32e12", "src_uid": "698da80c7d24252b57cca4e4f0ca7031", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\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 val (n, k) = readInts()\n val primes = sieve(n)\n var sol = 0\n for (goal in primes)\n for (pos in 1 until primes.size)\n if (primes[pos] + primes[pos - 1] + 1 > goal) break\n else if (primes[pos] + primes[pos - 1] + 1 == goal) {\n sol++\n break\n }\n print(if (sol >= k) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "38447f751bbca7ade146538e4a315378", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\nfun main(args : Array){\n val reader = Scanner(System.`in`)\n var n: Int = reader.nextInt()\n var k: Int = reader.nextInt()\n var list1: MutableList = mutableListOf()\n var b = 0\n for(i in 2..n){\n if(Prime(i) == 1) {\n for (j in 2..i) {\n if (Prime(j) == 1) {\n list1.add(j)\n }\n }\n for (x in 1..list1.size - 1) {\n if (list1[x - 1] + list1[x] + 1 == i) {\n b++\n }\n }\n list1.clear()\n }\n }\n\n if(b>=k){ println(\"YES\")}\n else { println(\"NO\")}\n\n\n}\n\n fun Prime(n: Int):Int{\n var a = 0\n for(i in 2..n/2) {\n if (n % i==0) {\n a++\n }\n }\n if(a==0) return 1\n else return 0\n }\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "aba93c5e6be94dc85c7513ea8717fa97", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nclass InputReader(val stream: InputStream) {\n val buf = ByteArray(1024)\n var curChar: Int = 0\n var numChars: Int = 0\n\n fun read(): Char {\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 if (numChars <= 0)\n return '\\uFFFF'\n }\n return buf[curChar++].toChar()\n }\n\n fun nextInt(): Int {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n var sgn = 1\n if (c == '-') {\n sgn = -1\n c = read()\n }\n var res = 0\n do {\n if (c < '0' || c > '9')\n throw InputMismatchException()\n res *= 10\n res += c.toInt() and 15\n c = read()\n } while (!isSpaceChar(c))\n return res * sgn\n }\n\n fun nextLong(): Long {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n var sgn = 1\n if (c == '-') {\n sgn = -1\n c = read()\n }\n var res = 0L\n do {\n if (c < '0' || c > '9')\n throw InputMismatchException()\n res *= 10\n res += c.toInt() and 15\n c = read()\n } while (!isSpaceChar(c))\n return res * sgn\n }\n\n fun nextString(): String {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n val res = StringBuilder()\n do {\n res.append(c)\n c = read()\n } while (!isSpaceChar(c))\n return res.toString()\n }\n\n fun isSpaceChar(c: Char): Boolean {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == '\\uFFFF'\n }\n}\n\nclass OutputWriter(val stream: OutputStream) {\n val buf = ByteArray(65536)\n var curPos: Int = 0\n\n fun write(c: Char) {\n if (buf.size - curPos < 1) flush()\n buf[curPos++] = c.toByte()\n }\n\n fun write(s: String) {\n if (buf.size - curPos < s.length) flush()\n var idx = 0\n if (s.length > buf.size) {\n var remaining = s.length\n while (remaining > buf.size) {\n while (curPos < buf.size) buf[curPos++] = s[idx++].toByte()\n flush()\n remaining -= buf.size\n }\n }\n while (idx < s.length) buf[curPos++] = s[idx++].toByte()\n }\n\n fun flush() {\n stream.write(buf, 0, curPos)\n curPos = 0\n }\n}\n\nfun isprime(n: Int): Boolean {\n if (n == 2 || n == 3)\n return true\n if (n % 2 == 0 || n % 3 == 0 || n == 1)\n return false\n var i = 5\n var w = 2\n while (i * i <= n) {\n if (n % i == 0)\n return false\n i += w\n w = 6 - w\n }\n return true\n}\n\nfun main(args: Array) {\n if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))\n val ir = InputReader(System.`in`)\n val ow = OutputWriter(System.out)\n\n var answer = 0\n val n = ir.nextInt()\n val k = ir.nextInt()\n for (i in 2 .. n / 2) {\n if (!isprime(i)) continue\n for (j in i + 1 .. n - 1) {\n if (!isprime(j)) continue\n if (isprime(i + j + 1) && (i + j + 1) <= n) {\n ++answer\n //println(\"$i $j\")\n }\n break\n }\n }\n\n if (answer >= k) ow.write(\"YES\\n\")\n else ow.write(\"NO\\n\")\n ow.flush()\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "34c0ca601ce8abadb16961a33fc8e4f6", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (n, k) = readLine()!!.split(' ').map { it.toInt() }\n var prime = Array(1001, { true })\n var primenumbers = mutableListOf()\n\n var p = 2\n var count = 0\n while (p * p <= 1001) {\n if (prime[p] == true) {\n\n for (i in p * 2..n step p) {\n prime[i] = false\n }\n }\n p++\n }\n\n for (i in 2..n) {\n if (prime[i]) {\n primenumbers.add(i)\n }\n }\n\n var i = 0\n while (i < primenumbers.size) {\n for (j in 0 until primenumbers.size-1) {\n var index = primenumbers[i] + primenumbers[j] + 1\n if (primenumbers[j] + primenumbers[j + 1] + 1 == primenumbers[i]) {\n count++\n }\n }\n i++\n }\n println(if (count >= k) \"YES\" else \"NO\")\n\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "43b029516408a889483686463046b438", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main() {\r\n val a = readLine()!!.toInt()\r\n println(2-a*a)\r\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "7d2c3e795ea348f4125eee45e7bb0e27", "src_uid": "f76005f888df46dac38b0f159ca04d5f", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main(args: Array) {\n var N = readLine()!!.toInt()\n println(2-N*N)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "ac18663d37023b3adf116357d04a8ecd", "src_uid": "f76005f888df46dac38b0f159ca04d5f", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "74b1fb75af49f980dd3a1f8ae118ce7d", "src_uid": "d215b3541d6d728ad01b166aae64faa2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "0cedcbb427f2dd5ffe5db90c75787ff6", "src_uid": "d215b3541d6d728ad01b166aae64faa2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "1ea5567f404199530572470604b36a7f", "src_uid": "d215b3541d6d728ad01b166aae64faa2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "bd8afea9975069393d601e3d40dbfd28", "src_uid": "d215b3541d6d728ad01b166aae64faa2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.absoluteValue\n\nfun main(args: Array) {\n val m = readLine()!!.split(' ').map { it.toInt() }.sum()\n if (m > 0 && m.rem(5) == 0)\n println(m / 5)\n else\n println(-1)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "bced263b6572358a8c8db6dcc22eff47", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n println(readLine()!!.split(' ')\n .map { it.toInt() }\n .sum()\n .let { if (it % 5 == 0 && it != 0) it/5 else -1 })\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2372f44c10f172f946775a202ba26bbc", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val sum = readLine()!!.split(\" \").map(String::toInt).sum()\n if (sum != 0 && sum % 5 == 0) {\n println(sum / 5)\n } else {\n println(-1)\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c5d5c99793a962137a6b9cb518a4e6d2", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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(5, { io.readInt() })\n val s = a.sum()\n val res = if (s % a.size == 0 && s > 0) s / a.size else -1\n io.println(res)\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "36f353dac20c19fdf1494c12f403fda2", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 b1 = ir.next()\n val b2 = ir.next()\n val e1 = ir.next()\n val e2 = ir.next()\n val arr1 = getArr(CharArray(3), b1, b2)\n val arr2 = getArr(CharArray(3), e1, e2)\n val arr3 = CharArray(6)\n arr3[0] = arr1[0]\n arr3[1] = arr1[1]\n arr3[2] = arr1[2]\n arr3[3] = arr1[0]\n arr3[4] = arr1[1]\n arr3[5] = arr1[2]\n\n for (i in 2..5)\n if (arr3[i - 2] == arr2[0] && arr3[i - 1] == arr2[1] && arr3[i] == arr2[2]) {\n pw.print(\"YES\")\n return\n }\n\n pw.print(\"NO\")\n\n}\n\nfun getArr(b: CharArray, b1: String, b2: String): CharArray {\n if (b1[0] == 'X') {\n b[0] = b1[1]\n b[1] = b2[1]\n b[2] = b2[0]\n } else if (b1[1] == 'X') {\n b[0] = b2[1]\n b[1] = b2[0]\n b[2] = b1[0]\n } else if (b2[0] == 'X') {\n b[0] = b1[0]\n b[1] = b1[1]\n b[2] = b2[1]\n } else {\n b[0] = b2[0]\n b[1] = b1[0]\n b[2] = b1[1]\n }\n\n return b\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "implementation"], "code_uid": "bdcd2d53b18a3b20c29a8df6142ef8eb", "src_uid": "46f051f58d626587a5ec449c27407771", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 b1 = ir.next()\n val b2 = ir.next()\n val e1 = ir.next()\n val e2 = ir.next()\n val arr1 = getArr(CharArray(3), b1, b2)\n val arr2 = getArr(CharArray(3), e1, e2)\n val arr3 = CharArray(6)\n arr3[0] = arr1[0]\n arr3[1] = arr1[1]\n arr3[2] = arr1[2]\n arr3[3] = arr1[0]\n arr3[4] = arr1[1]\n arr3[5] = arr1[2]\n\n for (i in 2..5)\n if (arr3[i - 2] == arr2[0] && arr3[i - 1] == arr2[1] && arr3[i] == arr2[2]) {\n pw.print(\"YES\")\n return\n }\n\n pw.print(\"NO\")\n\n}\n\nfun getArr(b: CharArray, b1: String, b2: String): CharArray {\n if (b1[0] == 'X') {\n b[0] = b1[1]\n b[1] = b2[1]\n b[2] = b2[0]\n } else if (b1[1] == 'X') {\n b[0] = b2[1]\n b[1] = b2[0]\n b[2] = b1[0]\n } else if (b2[0] == 'X') {\n b[0] = b1[0]\n b[1] = b1[1]\n b[2] = b2[1]\n } else {\n b[0] = b2[0]\n b[1] = b1[0]\n b[2] = b1[1]\n }\n\n return b\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "97a64ba2ada7adbf945a08e5071a0465", "src_uid": "46f051f58d626587a5ec449c27407771", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var b1s1 = readLine()!!\n var b1s2 = readLine()!!\n var b2s1 = readLine()!!\n var b2s2 = readLine()!!\n\n var s1 = (b1s1 + b1s2.reversed()).split(\"X\").joinToString(\"\")\n var s2 = (b2s1 + b2s2.reversed()).split(\"X\").joinToString(\"\")\n if (s1 == s2) {\n print(\"YES\")\n return\n }\n for (i in 0..4) {\n s1 = s1.substring(1) + s1[0]\n if (s1 == s2) {\n println(\"YES\")\n return\n }\n }\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "implementation"], "code_uid": "71ab24bb56d97c25f5e7b537c15cf5d4", "src_uid": "46f051f58d626587a5ec449c27407771", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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() }", "lang_cluster": "Kotlin", "tags": ["divide and conquer", "implementation", "binary search"], "code_uid": "0690231307b74ceb7aac3f033e2903e3", "src_uid": "1503d761dd4e129fb7c423da390544ff", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "bd0ad3524cbc370579d7c2974740de1f", "src_uid": "1503d761dd4e129fb7c423da390544ff", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["divide and conquer", "implementation", "binary search"], "code_uid": "2680b9a8aa4c992eb5a82ca3479c27eb", "src_uid": "1503d761dd4e129fb7c423da390544ff", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "bbf8bd98784787164f71a72dcef8f26a", "src_uid": "1503d761dd4e129fb7c423da390544ff", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.pow\n\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n var (n, le, ri) = r.readLine()!!.split(\" \").map { it.toInt() }\n var min = 0\n var max = 0\n min += (2.0.pow(le)).toInt()-1\n min += n-le\n max += (2.0.pow(ri)).toInt()-1\n max += (n-ri)*2.0.pow(ri-1).toInt()\n println(\"$min $max\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "3906022b09b499cd51d1345072db6724", "src_uid": "ce220726392fb0cacf0ec44a7490084a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main()\n{\n val (given, left, rite) = readLine()!!.split(' ').map{ it.toInt()}\n val mins = (1 shl left) + (given - left - 1)\n val maxs = (1 shl rite) - 1 + (1 shl rite - 1) * (given - rite)\n println(\"$mins $maxs\")\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "0bc8afd88897586914bd7fd6071fbe8f", "src_uid": "ce220726392fb0cacf0ec44a7490084a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/** 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\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 = 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 val ori = Array(n, {IntArray(n)})\n */\n\n/** printing variables:\n * println(\"$l 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\nimport java.util.*\n\nval MX = 400005\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 nextInts() = next().split(\" \").map { it.toInt() }\nfun nextLongs() = next().split(\" \").map { it.toLong() }\n\nfun bad(s: String) : Boolean {\n if (s.length % 2 == 0) return false\n if (s[0] != '1') return false\n for (i in 1..s.length-1) if (s[i] != '0') return false\n return true\n}\n\nfun solve() {\n val (n,l,r) = nextInts()\n val mn = n+((1 shl l)-1-l)\n val mx = (1 shl (r-1))-1+((n-r+1) shl (r-1))\n // 2^0, 2^1, ..., 2^{r-2}, 2^{r-1} * (n-r+1)\n // val mx = 0\n print(mn)\n print(\" \")\n print(mx)\n}\n\nfun main(args: Array) {\n val T = 1\n for (i in 1..T) solve()\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "9527beff3469ed9c82b5fe521f01e075", "src_uid": "ce220726392fb0cacf0ec44a7490084a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (n, l, r) = readLine()!!.split(\" \").map { it.toInt() }\n val min = (n - l) + ((1 shl l) - 1)\n val max = ((1 shl r) - 1) + (n - r) * (1 shl (r - 1))\n print(\"$min $max\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "6fdb49ceafc1092820b8c4f668c3f277", "src_uid": "ce220726392fb0cacf0ec44a7490084a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.ceil\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val (x, y, m) = readStrings().map { it.toLong() }\n\n var biggest = max(x, y)\n if (biggest >= m) println(0)\n else if (biggest < m && biggest <= 0) println(-1)\n else {\n var smallest = min(x, y)\n var moves = 0L\n if (smallest < 0) {\n moves = ceil(-smallest.toDouble()/biggest).toLong()\n smallest += moves * biggest\n }\n\n while (max(smallest, biggest) < m) {\n biggest = max(smallest, biggest)\n smallest = min(smallest, biggest)\n// println(\"$biggest $smallest $moves\")\n smallest = biggest.also { biggest += smallest }\n moves++\n }\n println(moves)\n }\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\n\nprivate fun readStrings() = readLn().trim().split(\" \")\n", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "4e82116fb1f720d2d79c2879063cc3f1", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n var sc = Scanner(System.`in`)\n var n = sc.nextInt()\n var a = sc.nextInt()\n var b = sc.nextInt()\n var c = sc.nextInt()\nval min = mins(a,b,c)\n var res = 0\n if (n == 1) res=0\n else if ( n == 2 ) res = Math.min(a,b)\n else res = min * (n-2) + Math.min(a,b)\n\nprintln(res)\n}\nfun mins ( a : Int , b: Int , c :Int): Int {\n var min = Math.min(a,b)\n return Math.min(min,c)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "e5b53573d8fb4cef2dad4ae596ec61e2", "src_uid": "6058529f0144c853e9e17ed7c661fc50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val numVisits = readInt()\n val rabbitToOwl = readInt()\n val rabbitToEeyore = readInt()\n val owlToEeyore = readInt()\n var sol = 0\n var house = 0\n val moves = arrayOf(\n intArrayOf(Int.MAX_VALUE, rabbitToOwl, rabbitToEeyore),\n intArrayOf(rabbitToOwl, Int.MAX_VALUE, owlToEeyore),\n intArrayOf(rabbitToEeyore, owlToEeyore, Int.MAX_VALUE)\n )\n\n for (times in 1 until numVisits)\n sol += moves[house].min()!!.also { house = moves[house].indexOf(it) }\n print(sol)\n}\n\n//enum class House { RABBIT, OWL, EEYORE }\n//\n//fun main() {\n// fun readInt() = readLine()!!.toInt()\n//\n// val numVisits = readInt()\n// val rabbitToOwl = readInt()\n// val rabbitToEeyore = readInt()\n// val owlToEeyore = readInt()\n// var sol = 0\n// var state = House.RABBIT\n//\n// repeat(numVisits - 1) {\n// when (state) {\n// House.RABBIT -> if (rabbitToOwl <= rabbitToEeyore) {\n// state = House.OWL\n// sol += rabbitToOwl\n// } else {\n// state = House.EEYORE\n// sol += rabbitToEeyore\n// }\n// House.OWL -> if (rabbitToOwl <= owlToEeyore) {\n// state = House.RABBIT\n// sol += rabbitToOwl\n// } else {\n// state = House.EEYORE\n// sol += owlToEeyore\n// }\n// House.EEYORE -> if (rabbitToEeyore <= owlToEeyore) {\n// state = House.RABBIT\n// sol += rabbitToEeyore\n// } else {\n// state = House.OWL\n// sol += owlToEeyore\n// }\n// }\n// }\n// print(sol)\n//}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "5461fd4ac0a4119d5a75ff0f7f637098", "src_uid": "6058529f0144c853e9e17ed7c661fc50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "enum class House { RABBIT, OWL, EEYORE }\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n\n val numVisits = readInt()\n val rabbitToOwl = readInt()\n val rabbitToEeyore = readInt()\n val owlToEeyore = readInt()\n var sol = 0\n var state = House.RABBIT\n\n repeat(numVisits - 1) {\n when (state) {\n House.RABBIT -> if (rabbitToOwl <= rabbitToEeyore) {\n state = House.OWL\n sol += rabbitToOwl\n } else {\n state = House.EEYORE\n sol += rabbitToEeyore\n }\n House.OWL -> if (rabbitToOwl <= owlToEeyore) {\n state = House.RABBIT\n sol += rabbitToOwl\n } else {\n state = House.EEYORE\n sol += owlToEeyore\n }\n House.EEYORE -> if (rabbitToEeyore <= owlToEeyore) {\n state = House.RABBIT\n sol += rabbitToEeyore\n } else {\n state = House.OWL\n sol += owlToEeyore\n }\n }\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "9607d66f74499057c27bf07f2c19a3c5", "src_uid": "6058529f0144c853e9e17ed7c661fc50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n\n val a = sc.nextInt()\n val b = sc.nextInt()\n val c = sc.nextInt()\n\n println(count(n, a, b, c))\n}\n\nfun count(n: Int, a: Int, b: Int, c: Int): Int {\n val m = Math.min(a,b)\n val allM = Math.min(m, c)\n\n if(n == 1) return 0\n if( n == 2) return m\n if( n > 2) return m + allM *(n - 2)\n\n return 0\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "b41c51ebdcb6bd203ca7a5668af80b20", "src_uid": "6058529f0144c853e9e17ed7c661fc50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "84b17fcb3b5ebbdfd28065e79f74813e", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "b509f425cf8fb7d3a0dce6d46a0f5772", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a816b89842da63a85b38d7b089d88fce", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "95fa96edc0a3ac7e46f5ad239a164650", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "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", "lang_cluster": "Kotlin", "tags": ["math", "dp", "bitmasks"], "code_uid": "f56c4c5fbf098e4064dd2adef4625dc7", "src_uid": "60955fc2caa6ec99c7dcc1da5d36b1f8", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport kotlin.system.measureTimeMillis\n\nfun solve(input: BufferedReader, out: BufferedWriter) {\n val s = input.readLine()\n var result: String? = null\n for (match in Regex(\"at\").findAll(s, 1)) {\n val r = match.groups[0]!!.range\n if (r.endInclusive + 1 < s.length) {\n val s1 = s.substring(1, r.start)\n val s2 = s.substring(r.endInclusive + 1, s.length - 1)\n val t = s.first() + s1.replace(\"dot\", \".\") + \"@\" + s2.replace(\"dot\", \".\") + s.last()\n result = result?.let { listOf(it, t).minBy {x -> x.length } } ?: t\n }\n }\n println(result)\n}\n\nfun main(args: Array) {\n// val i = File(\"input.txt\").bufferedReader()\n// val o = File(\"output.txt\").bufferedWriter()\n val i = System.`in`.bufferedReader()\n val o = System.`out`.bufferedWriter()\n System.err.println(\"time = ${measureTimeMillis {\n solve(i, o)\n }}ms\")\n o.close()\n}\n", "lang_cluster": "Kotlin", "tags": ["expression parsing", "implementation"], "code_uid": "a7523844398704309bd5bb9dafc62695", "src_uid": "a11c9679d8e2dca51be17d466202df6e", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nobject input {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n var tokenizer = StringTokenizer(\"\")\n\n fun next(): String {\n while (!tokenizer.hasMoreTokens()) {\n val nextLine = reader.readLine() ?: throw IllegalStateException()\n tokenizer = StringTokenizer(nextLine)\n }\n return tokenizer.nextToken()\n }\n\n fun nextInt(): Int {\n return next().toInt()\n }\n}\n\nfun main(arg: Array) {\n val n = input.nextInt()\n val years = IntArray(n, { input.nextInt() })\n\n for (i in 0..n - 1) {\n var xor = 0\n for (j in 0..n - 1) {\n xor = xor.xor(Math.abs(years[i] - years[j]))\n }\n if (xor == 0) {\n println(years[i])\n }\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation"], "code_uid": "f64e3799461b3e34375649a6e381cda3", "src_uid": "f03773118cca29ff8d5b4281d39e7c63", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val numJoined = readInt()\n val joined = readInts().sorted()\n println(joined[numJoined shr 1])\n}\n", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation"], "code_uid": "17dd1e77ce57bc8b3e40f77bb108e09a", "src_uid": "f03773118cca29ff8d5b4281d39e7c63", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package qqq\n\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n br.readLine()\n val m = br.readLine().split(\" \").map { Integer.parseInt(it) }.sorted()\n println(m.first() + (m.last() - m.first()) / 2)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation"], "code_uid": "26974be0e93eccf96d3cee13a3496ea1", "src_uid": "f03773118cca29ff8d5b4281d39e7c63", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args:Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n val years = IntArray(n, { sc.nextInt() })\n val avg = years.average()\n if (n == 2 || n == 4) println ( if (avg > 2050.0) Math.ceil(avg).toInt() else Math.floor(avg).toInt())\n else\n println (avg.toInt())\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation"], "code_uid": "4a1892e5aa945c6a8fba3ebd333ac7d6", "src_uid": "f03773118cca29ff8d5b4281d39e7c63", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// Bismillahir Rahmanir Raheem\n\nimport java.util.Scanner\n\nfun gcd (a: Int, b: Int): Int {\n if (b == 0) return a\n return gcd (b, a%b)\n}\n\nfun main() {\n val sc = Scanner (System.`in`)\n\n var ara = Array (2) {0}\n ara[0] = sc.nextInt()!!\n ara[1] = sc.nextInt()!!\n ara.sort()\n\n var n: Int = 6 - (ara[1]-1)\n\n print (n/gcd(n, 6))\n println (\"/\" + 6/gcd(n, 6))\n}", "lang_cluster": "Kotlin", "tags": ["math", "probabilities"], "code_uid": "e5ec7be75324f2587bf140edaf85c309", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 gcd(a: Int, b: Int): Int {\n if (b == 0) {\n return a\n }\n else {\n return gcd(b, a % b)\n }\n}\n\nfun main(args: Array) {\n// var s = Scanner(System.`in`)\n var (y, w) = readInts()\n var h = 0\n if (y > w) {\n h = y\n } else {\n h = w\n }\n var lst = ArrayList()\n for (i in h until 7) {\n lst.add(i)\n }\n var x = lst.size / 6.0;\n var map = hashMapOf()\n map[0 / 1.0] = \"0/1\"\n map[1 / 1.0] = \"1/1\"\n map[1 / 2.0] = \"1/2\"\n map[1 / 3.0] = \"1/3\"\n map[1 / 4.0] = \"1/4\"\n map[1 / 5.0] = \"1/5\"\n map[1 / 6.0] = \"1/6\"\n map[2 / 6.0] = \"1/3\"\n map[3 / 6.0] = \"1/2\"\n map[4 / 6.0] = \"2/3\"\n map[5 / 6.0] = \"5/6\"\n map[6 / 6.0] = \"1/1\"\n println(map[x])\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "probabilities"], "code_uid": "cce2bc13cd591b44eaa24901e1e0af7a", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (x, y) = readLine()!!.split(' ').map { c -> c.toInt() }\n\n var first = 0\n\n for(i in Math.max(x,y)..6) {\n first++\n }\n\n var second = 6\n\n var localA = first\n var localB = second\n\n while(localA != 0 && localB != 0) {\n if(localA > localB) {\n localA = localA % localB\n } else {\n localB = localB % localA\n }\n }\n\n var nod = localA + localB\n\n if(nod > 0) {\n first /= nod\n second /= nod\n }\n\n println(\"$first/$second\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "probabilities"], "code_uid": "14a1280fb49e26dd64b0033d4a0288f1", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\nfun main(args: Array) {\n var (a,b) = readLine()!!.split(' ').map(String::toInt)\n var max = 0\n if (a > b)\n max = a\n else\n max = b\n var c = 6 - max + 1\n var d = 6\n if (c % 3 == 0) {\n c /= 3\n d /= 3\n }\n if (c % 2 == 0) {\n c /= 2\n d /= 2\n }\n print(\"$c/$d\")\n }", "lang_cluster": "Kotlin", "tags": ["math", "probabilities"], "code_uid": "f7fe18fbe96fd711583013064a8bf787", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// star because the module of a negative number is a negative number, and the max distance between two numbers with 8\n// is not ten but 16, in -8 to 8\nfun main() {\n val valids = setOf(8, -8)\n val floor = readLine()!!.toInt()\n for (sol in 1..20) {\n var candidate = floor + sol\n while (candidate != 0)\n if (candidate % 10 in valids) return print(sol) else candidate /= 10\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "e054bc6942d6162f45f04c23835fa1b0", "src_uid": "4e57740be015963c190e0bfe1ab74cb9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n var ans = 0\n n++\n ans++\n while (true) {\n val s = n.toString()\n var ok: Boolean = false\n for (c in s) {\n if (c == '8') {\n ok = true\n break\n }\n }\n if (ok)\n break\n n++\n ans++\n }\n print(\"$ans\\n\")\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "a807d58a109462312771ebf15f1005c0", "src_uid": "4e57740be015963c190e0bfe1ab74cb9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nprivate fun solve( x: Long) : Boolean{\n\n var a = x\n while (a != 0L)\n //print(a%10)\n if(a%10 == 8L || a%10 == -8L) {\n return true\n }\n else {\n a /= 10L\n }\n return false\n}\nval reader = Scanner(System.`in`)\nvar ans: Long = 0\nvar i: Long = 0\nfun main(args: Array){\n var n = reader.nextLong()\n \n while (!solve(++n)) ans++\n print(ans+1)\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "96fe205a0ea083763f8b9dcc876c80f8", "src_uid": "4e57740be015963c190e0bfe1ab74cb9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nprivate fun solve( x: Long) : Boolean{\n\n var a = x\n while (a != 0L)\n //print(a%10)\n if(a%10 == 8L || a%10 == -8L) {\n return true\n }\n else {\n a /= 10L\n }\n return false\n}\nval reader = Scanner(System.`in`)\nvar ans: Long = 0\nvar i: Long = 0\nfun main(args: Array){\n var n = reader.nextLong()\n\n\n // print(solve(n))\n if(n<=0||solve(n))\n {\n while (!solve(++n)) ans++\n print(ans+1)\n }\n else\n {\n while (!solve(++n)) ans++\n print(ans+1)\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "11dcc3dc0e78c2581650cd2643fb10c3", "src_uid": "4e57740be015963c190e0bfe1ab74cb9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (n, k, t) = readLine()!!.split(\" \").map { it.toLong() }\n when (t) {\n in 1 until k -> print(t)\n in k..n -> print(k)\n else -> print(k - ((t % n) % k))\n }\n}\n// 966696824 346707476 1196846860", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "62f0fbca14d035ec21673f1d16222d42", "src_uid": "7e614526109a2052bfe7934381e7f6c2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`), {\n var n = nextInt()\n var k = nextInt()\n var t = nextInt()\n when (t) {\n in 1 until k -> print(t)\n in k..n -> print(k)\n else -> print(k - ((t % n) % k))\n }\n})", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "93e5eeb10ad60bbbfeddaa54026f970b", "src_uid": "7e614526109a2052bfe7934381e7f6c2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numSpectators, waveLength, time) = readInts()\n print (if (time <= numSpectators) min(time, waveLength) else (waveLength - time + numSpectators))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "c03f759c602e51672cd457c51259888c", "src_uid": "7e614526109a2052bfe7934381e7f6c2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() = println(readLine()!!.count { it in \"aeiou13579\" })", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "c44cbdbbc632e51fcee6068b940d22a4", "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "3649294c44faec12a5c8dec47c571b80", "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "efbe05ffeb94cbe05fa95f0661287e10", "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "f940bd706af6e648e56010fa3671606f", "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n var (a, b, c) = readLine()!!.split(\" \").map(String::toLong)\n val m = min(a / 3, min(b / 2, c / 2))\n val weeksSol = m * 7\n a -= 3 * m\n b -= 2 * m\n c -= 2 * m\n val days = \"abcacba\"\n var remainingSol = 0\n for (start in 0..6) {\n val remainings = longArrayOf(a, b, c)\n var remainingCandidate = 0\n var pos = start\n while (true) {\n if (remainings[days[pos] - 'a'] > 0) {\n remainings[days[pos] - 'a']--\n remainingCandidate++\n pos = (pos + 1) % 7\n } else break\n }\n if (remainingCandidate > remainingSol) remainingSol = remainingCandidate\n }\n print(weeksSol + remainingSol)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "345908ab6375193781707ba3d1c2c5b7", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val req = listOf(FISH, FISH, RABBIT, CHICKEN, FISH, CHICKEN, RABBIT)\n val reqcnt = req.groupingBy { it }.eachCount()\n\n val pack = readLongSeq().toMutableList()\n\n val weeks = pack.indices.asSequence().map { pack[it] / reqcnt[it]!! }.min()!!\n\n for(i in pack.indices) pack[i] -= weeks * reqcnt[i]!!\n\n val rem = req.indices.asSequence().map { i ->\n val pack1 = pack.toMutableList()\n\n var res = 0\n\n for(j in req.indices) {\n val k = req[(i + j) % 7]\n pack1[k]--\n if(pack1[k] < 0) break\n res++\n }\n\n res\n }.max()!!\n\n val ans = weeks * 7 + rem\n\n println(ans)\n}\n\nconst val FISH = 0\nconst val RABBIT = 1\nconst val CHICKEN = 2\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 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() }", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "44a8ac8323a0a3bab5c37f563269f134", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n\n\nfun main(args: Array) {\n\n val sc = Scanner(System.`in`)\n\n val a = sc.nextInt()\n val b = sc.nextInt()\n val c = sc.nextInt()\n\n var a1 = a / 3\n var a2 = a / 3\n var a3 = a / 3\n when (a.rem(3)) {\n 0 -> {}\n 1 -> a1++\n 2 -> {\n a1++\n a2++\n }\n }\n var b1 = b / 2\n var b2 = b / 2\n b1 += b.rem(2)\n var c1 = c / 2\n var c2 = c / 2\n c1 += c.rem(2)\n\n var res = 0\n res = Math.max(res, days(arrayOf(a1, b1, c1, a2, c2, b2, a3)))\n res = Math.max(res, days(arrayOf(b1, c1, a1, c2, b2, a2, a3)))\n res = Math.max(res, days(arrayOf(c1, a1, c2, b1, a2, a3, b2)))\n res = Math.max(res, days(arrayOf(a1, c1, b1, a2, a3, b2, c2)))\n res = Math.max(res, days(arrayOf(c1, b1, a1, a2, b2, c2, a3)))\n res = Math.max(res, days(arrayOf(b1, a1, a2, b2, c1, a3, c2)))\n res = Math.max(res, days(arrayOf(a1, a2, b1, c1, a3, c2, b2)))\n\n println(res)\n}\n\nfun days(week: Array): Int {\n val min = week.min()!!\n var days = min * 7\n var pos = 0\n while (pos < 7) {\n if (week[pos] > min) {\n days++\n } else {\n break\n }\n pos++\n }\n return days\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "05760bf1f113c8a2380268b6601e4205", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package cf1154\n\nimport java.util.StringTokenizer\nimport kotlin.math.max\nimport kotlin.math.min\n\nclass C {\n fun solve() {\n val st = StringTokenizer(readLine())\n\n val a: IntArray = IntArray(3)\n val needs: IntArray = intArrayOf(0, 1, 2, 0, 2, 1, 0)\n\n a[0] = st.nextToken().toInt()\n a[1] = st.nextToken().toInt()\n a[2] = st.nextToken().toInt()\n\n val weeks = min(a[0] / 3, min(a[1] / 2, a[2] / 2))\n var ans = weeks * 7\n\n a[0] -= (weeks * 3)\n a[1] -= (weeks * 2)\n a[2] -= (weeks * 2)\n\n var maxDays = 0\n for (weekDay in 0..6) {\n var days = 0\n val b: IntArray = a.copyOf()\n var cur = weekDay\n while (b[needs[cur]] != 0) {\n b[needs[cur]] --\n days ++\n cur ++\n cur %= 7\n }\n\n cur = (weekDay + 6) % 7\n while (b[needs[cur]] != 0) {\n b[needs[cur]] --\n days ++\n cur = (cur + 6) % 7\n }\n\n maxDays = max(days, maxDays)\n }\n\n ans += maxDays\n println(ans)\n }\n}\n\nfun main(args: Array) {\n C().solve()\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "4966ca3c42c9a974329cb6cf2087958f", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val chars = \"ABCD\"\n val lengths = IntArray(4)\n var minLengthPos = 0\n var maxLengthPos = 0\n for (pos in 0 until 4) {\n lengths[pos] = readLine()!!.length - 2\n if (lengths[pos] < lengths[minLengthPos]) minLengthPos = pos\n if (lengths[pos] > lengths[maxLengthPos]) maxLengthPos = pos\n }\n var minCounter = 0\n var maxCounter = 0\n for (pos in 0 until 4) {\n if (lengths[pos] / lengths[minLengthPos] < 2) minCounter++\n if (lengths[maxLengthPos] / lengths[pos] < 2) maxCounter++\n }\n if (minCounter < 2 && maxCounter < 2) return print('C')\n if (minCounter < 2) return print(chars[minLengthPos])\n if (maxCounter < 2) return print(chars[maxLengthPos])\n print('C')\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "035a4cc6372cb8883b2b8aecb5391d47", "src_uid": "30725e340dc07f552f0cce359af226a4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val chars = \"ABCD\"\n val lengths = IntArray(4)\n var minLengthPos = 0\n var maxLengthPos = 0\n for (pos in 0 until 4) {\n lengths[pos] = readLine()!!.length - 2\n if (lengths[pos] < lengths[minLengthPos]) minLengthPos = pos\n if (lengths[pos] > lengths[maxLengthPos]) maxLengthPos = pos\n }\n var minCounter = 0\n var maxCounter = 0\n for (pos in 0 until 4) {\n if (lengths[pos] / lengths[minLengthPos] < 2) minCounter++\n if (lengths[maxLengthPos] / lengths[pos] < 2) maxCounter++\n }\n if (minCounter < 2 && maxCounter >= 2) return print(chars[minLengthPos])\n if (maxCounter < 2 && minCounter >= 2) return print(chars[maxLengthPos])\n print('C')\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5455ec41e3741f1e6e233078ea05625c", "src_uid": "30725e340dc07f552f0cce359af226a4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "64e4346d734a82557e3bb507e95cda9c", "src_uid": "e88bb7621c7124c54e75109a00f96301", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "6c5f567be47275b34675b202d5b20e4d", "src_uid": "e88bb7621c7124c54e75109a00f96301", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val (n, m) = readLine()!!.split(\" \").map { it.toInt() }\n val big = max(m, n)\n val small = min(m, n)\n val diff = big - small\n if (diff > small) {\n print(small)\n } else {\n print((diff + (small - diff) * 2 / 3).toLong())\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation", "number theory"], "code_uid": "4be8efd717572d099104074f8009c515", "src_uid": "0718c6afe52cd232a5e942052527f31b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (a, b) = readLine()!!.split(' ').map(String::toInt)\n var count = 0\n while(a>=1 && b>=2 || a>=2 && b>=1) {\n if (a >= b) {\n a = a - 2\n b = b - 1\n count++\n } else {\n a = a - 1\n b = b - 2\n count++\n }\n }\n print(count)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation", "number theory"], "code_uid": "fbc89a7b09dca10efd895cc522d7bf3c", "src_uid": "0718c6afe52cd232a5e942052527f31b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * Created by hareesh on 30/07/17.\n */\nfun main(args: Array)\n{\n fun readInts(separator: Char = ' ') = readLine()!!.split(separator).map(String::toInt)\n var (a, b) = readInts()\n /*if (a < b)\n {\n val temp = a;\n a = b\n b = temp\n }\n var res = a/2\n a %= 2\n if (res <= b)\n {\n b -= res\n val temp = b/2\n if (temp <= a)\n res += temp\n }\n else\n {\n res = b\n }*/\n var count = 0\n while (a>0 && b>0 && (a+b) >= 3)\n {\n if (a>b)\n {\n a -= 2\n b -= 1\n }\n else\n {\n b -= 2\n a -= 1\n }\n count++;\n }\n println(count)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation", "number theory"], "code_uid": "c90cbf7d59656b5dc294b50463533b7b", "src_uid": "0718c6afe52cd232a5e942052527f31b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 //val n = r.readLine()!!.toInt()\n val (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n when{\n n>2*m -> println(m)\n m>2*n -> println(n)\n else -> println((m+n)/3)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation", "number theory"], "code_uid": "a030bff24a635b9a5d646ff05d0bc82b", "src_uid": "0718c6afe52cd232a5e942052527f31b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array)\n{\n\tvar str= readLine()!!\n\tvar c=0\n\tvar new: String=\"\"\n\tif(str.length%2==0)\n\t{\n\tfor(i in 1..str.length)\n\t\t{\n\t\t\tif(c%2==0)\n\t\t\t{\n\t\t\t\tnew=str[str.length-1]+new\n\t\t\t\tstr= str.substring(0,str.length-1)\n\t\t\t\tc++\n\t\t\t}\n\t else\n\t\t\t{\n\t\t\t\tnew=str[0]+new\n\t\t\t\tstr= str.substring(1,str.length)\n\t\t\t\tc++ \n\t\t\t}\n\t\t}\n\t}\n\telse\n\t\t{\n\t\t\tfor(i in 1..str.length)\n\t\t{\n\t\t\tif(c%2==0)\n\t\t\t{new=str[0]+new\n\t\t\t\tstr= str.substring(1,str.length)\n\t\t\t\tc++ \n\t\t\t}\n\t else\n\t\t\t{new=str[str.length-1]+new\n\t\t\t\tstr= str.substring(0,str.length-1)\n\t\t\t\tc++\n\t\t\t}\n\t\t}\n\t\t\t\n\t\t}\n\tprintln(new)\n \n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "1ba9bd525f22e9901134270aa7e2d10f", "src_uid": "992ae43e66f1808f19c86b1def1f6b41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args : Array) {\n val s = readLine()!!\n var list: MutableList = mutableListOf()\n\n if(s.length%2==1) {\n var n = (s.length - 1) / 2\n var a = 0\n var c = 1\n list.add(s[n])\n while (a != n) {\n list.add(s[n + c])\n list.add(s[n - c])\n c++\n a++\n }\n for (i in 0..s.length - 1) {\n print(list[i])\n }\n }\n else{\n var n = (s.length - 2 ) / 2\n var a = 0\n var c = 0\n while (a != n+1) {\n list.add(s[n - c])\n c++\n list.add(s[n + c])\n a++\n }\n for (i in 0..s.length - 1) {\n print(list[i])\n }\n }\n\n\n\n\n}\n", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "100dd4017478c96496e03be02d94d70a", "src_uid": "992ae43e66f1808f19c86b1def1f6b41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun DecryptWord(WORD: String): String {\n val ChrArr = CharArray(WORD.length)\n var middle = if(WORD.length%2 ==0) WORD.length/2 -1 else WORD.length/2\n var counter = 0\n\n for(i in WORD.indices) {\n if(i%2 == 0) {\n var getChar = WORD.get(middle - counter)\n ChrArr[i] = getChar\n counter++\n } else {\n var getChar = WORD.get(middle + counter)\n ChrArr[i] = getChar\n }\n }\n var newString: String = String(ChrArr)\n return newString\n}\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n var encrepted: String = input.next()\n\n println(DecryptWord(encrepted))\n\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "1d041aba6ae89b4769b4aae03173f0fd", "src_uid": "992ae43e66f1808f19c86b1def1f6b41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val t = readLine()!!\n val sb = StringBuilder()\n var right = t.lastIndex\n var left = 0\n if (t.length % 2 == 0)\n while (left <= right) {\n sb.append(t[right])\n if (left < right) sb.append(t[left])\n right--\n left++\n }\n else\n while (left <= right) {\n sb.append(t[left])\n if (left < right) sb.append(t[right])\n right--\n left++\n }\n print(sb.reversed().toString())\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "b888b9d8e84551520a18a6e22b2700c5", "src_uid": "992ae43e66f1808f19c86b1def1f6b41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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() }", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "6a6b84c20e78263e16c8edef317c58f9", "src_uid": "89b51a31e00424edd1385f2120028b9d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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() }", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "87e7fc4ce0cb4f76ba107655abef66e7", "src_uid": "89b51a31e00424edd1385f2120028b9d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "fun main() {\r\n\r\n val (n, m) = readLine()!!.trim().split(\"\\\\s+\".toRegex()).map(String::toLong)\r\n\r\n if (m > 1) {\r\n println((n * (m - 1)))\r\n } else {\r\n println((n - 1))\r\n\r\n }\r\n\r\n\r\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "ff83179dc59bc5205bba5c62adbb5312", "src_uid": "a91aab4c0618d036c81022232814ef44", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "import java.util.Scanner\r\n\r\nfun main() {\r\n val input = Scanner(System.`in`)\r\n val n = input.nextLong()\r\n val m = input.nextLong()\r\n val a: Long = 1\r\n\r\n if (m == a && n > a) {\r\n println(n - a)\r\n } else if (n == a && m > a) {\r\n println(m - a)\r\n } else {\r\n println(((m - a) * n))\r\n }\r\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "351014d3106aff09163cc70028e2a24b", "src_uid": "a91aab4c0618d036c81022232814ef44", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport java.lang.StringBuilder\nimport java.util.TreeSet\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.system.exitProcess\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 = readInt()\n\n val mc = ArrayModCombinatorics(200_000)\n\n case@ for(case in 1..numCases) {\n // print(\"Case #$case: \")\n\n val n = readInt()\n val k = readLong()\n\n val gt = ModInt(n and 1 xor 1)\n var eq = ModInt(n and 1)\n for(i in 0 until n step 2) eq += mc.C(n, i)\n\n val M = Matrix2(\n ModInt(2).pow(n), gt,\n ModInt(0), eq\n ).pow(k)\n\n val ans = M.q + M.s\n println(ans.int)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\ndata class Matrix2(val p: ModInt, val q: ModInt,\n val r: ModInt, val s: ModInt) {\n operator fun times(b: Matrix2) =\n Matrix2(\n p = p * b.p + q * b.r, q = p * b.q + q * b.s,\n r = r * b.p + s * b.r, s = r * b.q + s * b.s\n )\n\n fun pow(exponent: Long): Matrix2 {\n var res = I\n var e = exponent\n var b = this\n\n while(e > 0) {\n if(e and 1 == 1L) {\n res *= b\n }\n e = e shr 1\n b *= b\n }\n return res\n }\n\n companion object {\n val I = Matrix2(\n ModInt(1), ModInt(0),\n ModInt(0), ModInt(1)\n )\n }\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 || k < 0) ModInt(0) else factorial[n] * invf[n-k]\n fun C(n: Int, k: Int) = if(k > n || k < 0) ModInt(0) else factorial[n] * invf[k] * invf[n-k]\n\n // multi-choose, be sure to adjust maxn accordingly\n fun M(n: Int, k: Int) = if(k == 0) ModInt(1) else C(n + k - 1, 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.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 if(mod == 1) return 0\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_unmemoized() /** 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\n fun swap(i: Int, j: Int) { val t = intArray[i]; intArray[i] = intArray[j]; intArray[j] = t }\n}\nfun ModIntArray.fill(element: ModInt, fromIndex: Int = 0, toIndex: Int = size) { intArray.fill(element.int, fromIndex, toIndex) }\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 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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { 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 }", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "bitmasks", "matrices"], "code_uid": "50f0a51b9847203630fac8c3ba5c8b49", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "import java.util.StringTokenizer\n\nfun FastReader.mainFn(out: StringBuilder) {\n repeat(nextInt()) {\n val (n, k) = nextInts(2)\n with(Mod(Mod.M109)) {\n val p = 2 powermod (n - 1)\n val q = p mulmod 2\n\n val modMatrixSpace =\n MatrixSpace.of(addModMonoid, mulModMonoid) {dim -> intArrayMatrix(dim, 0)}\n val mulMatrixMonoid = with(modMatrixSpace)\n { Monoid.of(identity(n=2), {x, y -> x matrixmul y}) }\n\n if (n and 1 == 0) {\n val m = buildIntArrayMatrix(2 to 2) {\n r(q, 1)\n r(0, p submod 1)\n }\n val mp = with(mulMatrixMonoid) { m fastpower k.toLong() }\n val ans = with(modMatrixSpace) {intArrayMatrix(1 to 2, 1) matrixmul mp}\n out.appendLine(ans[0, 1])\n } else {\n out.appendLine((p addmod 1) powermod k)\n }\n }\n }\n}\n\n// {{{ main and IO\nfun main() {\n val result = StringBuilder()\n FastReader.mainFn(result)\n print(result.toString())\n}\n\nobject FastReader {\n val reader = System.`in`.bufferedReader()\n var tokenizer: StringTokenizer? = null\n\n fun next(): String =\n tokenizer?.takeIf{it.hasMoreElements()}?.run {nextToken()}\n ?: run {\n tokenizer = StringTokenizer(reader.readLine())\n next()\n }\n\n fun nextInt(): Int = next().toInt()\n fun nextInts(n: Int): List = (1..n).map{nextInt()}\n fun nextIntArray(n: Int): IntArray = IntArray(n) {nextInt()}\n\n fun nextLong(): Long = next().toLong()\n fun nextLongs(n: Int): List = (1..n).map{nextLong()}\n fun nextLongArray(n: Int): LongArray = LongArray(n) {nextLong()}\n\n fun nextLine(): String {\n tokenizer = null\n return reader.readLine()\n }\n}\n// }}}\n\n// {{{ Mod\n\nclass Mod(val mod: Int) {\n companion object {\n const val M109 = 1_000_000_007\n const val M99 = 998244353\n }\n\n val addModMonoid: Monoid = Monoid.of(0) {x, y -> x addmod y}\n val mulModMonoid: Monoid = Monoid.of(1) {x, y -> x mulmod y}\n\n fun Int.toMod() = this % mod\n infix fun Int.addmod(other: Int): Int {\n val x = this + other\n return if (x >= mod) x - mod else x\n }\n infix fun Int.submod(other: Int): Int {\n val x = this - other\n return if (x < 0) x + mod else x\n }\n infix fun Int.mulmod(other: Int): Int =\n (toLong() * other.toLong() % mod.toLong()).toInt()\n infix fun Int.powermod(n: Int): Int {\n var res = 1\n var t = this\n var nn = n\n\n while (nn > 0) {\n if (nn and 1 > 0) {\n res = res mulmod t\n }\n t = t mulmod t\n nn = nn shr 1\n }\n return res\n }\n fun Int.invmod(): Int = this powermod (mod-2)\n}\n\n// }}}\n\n// {{{ Monoid\n\ninterface Semigroup {\n infix fun T.stimes(other: T): T\n}\n\nabstract class Monoid(val unit: T): Semigroup {\n companion object {\n fun of(unit: T, stimesFn: (T, T) -> T): Monoid = object: Monoid(unit) {\n override infix fun T.stimes(other: T): T = stimesFn(this, other)\n }\n }\n\n infix fun T.fastpower(n: Long): T {\n require(n >= 0)\n var res = unit\n var p = this\n var np = n\n while (np > 0) {\n if (np and 1 > 0) {\n res = res stimes p\n }\n p = p stimes p\n np = np shr 1\n }\n return res\n }\n}\n\n// }}}\n\n// {{{ Matrix\n\ntypealias MatDim = Pair\n\nabstract class Matrix(val numRows: Int, val numColumns: Int) {\n val dimension: MatDim\n get() = numRows to numColumns\n abstract operator fun get(i: Int, j: Int): E\n abstract operator fun set(i: Int, j: Int, value: E)\n}\n\nfun intArrayMatrix(dimension: MatDim, initialValue: Int): Matrix {\n val (numRows, numColumns) = dimension\n val mat = Array(numRows) {IntArray(numColumns){initialValue}}\n return object : Matrix(numRows, numColumns) {\n override operator fun get(i: Int, j: Int): Int = mat[i][j]\n override operator fun set(i: Int, j: Int, value: Int) { mat[i][j] = value }\n }\n}\n\nfun buildIntArrayMatrix(dimension: MatDim , buildFn: IntArrayMatrixBuilder.()->Unit)\n : Matrix {\n val builder = IntArrayMatrixBuilder(dimension)\n builder.buildFn()\n return builder.build()\n}\n\nclass IntArrayMatrixBuilder(dimension: MatDim) {\n private val numRows = dimension.first\n private var currentRow = 0\n private val result = intArrayMatrix(dimension, 0)\n\n fun r(vararg values: Int) {\n check(currentRow < numRows)\n rat(currentRow, *values)\n currentRow++\n }\n\n fun rat(rowIndex: Int, vararg values: Int) {\n require(rowIndex >= 0 && rowIndex < numRows)\n for ((c, x) in values.withIndex()) {\n result[currentRow, c] = x\n }\n }\n\n fun build(): Matrix = result\n}\n\nabstract class MatrixSpace(\n val addMonoid: Monoid, val mulMonoid: Monoid) {\n\n companion object {\n fun of(\n addMonoid: Monoid, mulMonoid: Monoid, zerosFn: (MatDim) -> Matrix):\n MatrixSpace = object: MatrixSpace(addMonoid, mulMonoid) {\n override fun zeros(dimension: MatDim): Matrix = zerosFn(dimension)\n }\n }\n\n abstract fun zeros(dimension: MatDim): Matrix\n\n fun identity(n: Int): Matrix {\n val result = zeros(n to n)\n for (i in 0 until n) {\n result[i, i] = mulMonoid.unit\n }\n return result\n }\n\n infix fun Matrix.matrixmul(other: Matrix): Matrix {\n require(this.numColumns == other.numRows)\n val result = zeros(this.numRows to other.numColumns)\n for (k in 0 until this.numColumns) {\n for (i in 0 until this.numRows) {\n for (j in 0 until other.numColumns) {\n val s = with(mulMonoid) {this@matrixmul[i, k] stimes other[k, j]}\n with(addMonoid) {\n result[i, j] = result[i, j] stimes s\n }\n }\n }\n }\n return result\n }\n}\n\n// }}}\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "bitmasks", "matrices"], "code_uid": "96688bda98b7724f8969640cff447478", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.io.BufferedReader\r\nimport java.io.InputStreamReader\r\nimport java.io.OutputStreamWriter\r\nimport java.io.PrintWriter\r\nimport java.util.*\r\n\r\nfun main(args: Array) {\r\n val input = InputReaderKt()\r\n val output = PrintWriter(OutputStreamWriter(System.out))\r\n Main(input, output).solve()\r\n output.flush()\r\n}\r\n\r\nclass Main(private val input: InputReaderKt, private val out: PrintWriter) {\r\n fun solve() {\r\n val MOD: Long = 1_000_000_000 + 7\r\n\r\n repeat(input.nextInt()) {\r\n val n = input.nextLong()\r\n val k = input.nextInt()\r\n\r\n // Sum of Even Index Binomial Coefficients\r\n val p = (1 until n).fold(1L) { acc, _ ->\r\n acc * 2 % MOD\r\n }\r\n val twoToNPower = p * 2 % MOD\r\n val b = LongArray(k + 1)\r\n b[0] = 1\r\n (1..k).forEach { power -> b[power] = (b[power - 1] * twoToNPower) % MOD }\r\n\r\n // x = AND of ith bits\r\n // y = XOR of ith bits\r\n\r\n // 1 = x > y = 0, all ith bits = 1, n - even\r\n val xGreaterThanY = 1 - n % 2\r\n\r\n // x = y = 0\r\n val xEqualsYEquals0 = if (n % 2 == 0L) (p - 1 + MOD) % MOD else p\r\n\r\n // x = y = 1, all ith bits = 1, n - odd\r\n val xEqualsYEquals1 = n % 2\r\n\r\n var casesWhenAndGreaterThanXor: Long = 0L\r\n var casesWhenAndEqualsXor: Long = 1L\r\n\r\n // for each bit\r\n repeat(k) { bit ->\r\n casesWhenAndGreaterThanXor += casesWhenAndEqualsXor * xGreaterThanY * b[k - 1 - bit]\r\n casesWhenAndGreaterThanXor %= MOD\r\n\r\n casesWhenAndEqualsXor *= xEqualsYEquals0 + xEqualsYEquals1\r\n casesWhenAndEqualsXor %= MOD\r\n }\r\n\r\n out.println((casesWhenAndGreaterThanXor + casesWhenAndEqualsXor) % MOD)\r\n }\r\n }\r\n}\r\n\r\nclass InputReaderKt {\r\n private var st: StringTokenizer? = null\r\n private val input: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\r\n\r\n fun hasNextToken(): Boolean {\r\n var t = st\r\n while (t == null || !t.hasMoreTokens()) {\r\n val line = input.readLine() ?: return false\r\n t = StringTokenizer(line)\r\n }\r\n st = t\r\n return true\r\n }\r\n\r\n fun nextToken(): String {\r\n var t = st\r\n while (t == null || !t.hasMoreTokens()) {\r\n val line = input.readLine() ?: throw IllegalStateException(\"End of input reached\")\r\n t = StringTokenizer(line)\r\n }\r\n st = t\r\n return t.nextToken()\r\n }\r\n\r\n fun readLine() = input.readLine()\r\n\r\n fun nextInt() = nextToken().toInt()\r\n\r\n fun nextLong() = nextToken().toLong()\r\n\r\n fun nextDouble() = nextToken().toDouble()\r\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "bitmasks", "matrices"], "code_uid": "e09e5e3ab2e522298247678c76433a93", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.util.*\r\nimport kotlin.math.*\r\nimport kotlin.system.*\r\n\r\nprivate fun readInt() = readLine()!!.toInt()\r\nprivate fun readLong() = readLine()!!.toLong()\r\nprivate fun readIntList() = readLine()!!.split(\" \").map { it.toInt() }\r\nprivate fun readLongList() = readLine()!!.split(\" \").map { it.toLong() }\r\n\r\nfun modPow(a: Long, b: Long, mod: Long) : Long {\r\n\tvar res = 1L\r\n\tvar c = a\r\n\tvar cur = b\r\n\twhile (cur > 0) {\r\n\t\tif (cur % 2 == 1L) {\r\n\t\t\tres = res * c % mod\r\n\t\t}\r\n\t\tc = c * c % mod\r\n\t\tcur = cur / 2\r\n\t}\r\n\treturn res\r\n}\r\nfun main() {\r\n\tval t = readInt()\r\n\tval resList = mutableListOf()\r\n\t\r\n\t\r\n\tval fs = 501010\r\n\tval mod = 1000000007L\r\n\tval fact = MutableList(fs) { 1L }\r\n\tval ifact = MutableList(fs) { 1L }\r\n\tval invs = MutableList(fs) { 1L }\r\n\tfor (i in 2 until fs) {\r\n\t\tfact[i] = fact[i - 1] * i % mod\r\n\t\tinvs[i] = mod - invs[(mod % i).toInt()] * (mod / i) % mod\r\n\t\tifact[i] = ifact[i - 1] * invs[i] % mod\r\n\t}\r\n\tfun binom(a: Int, b: Int) : Long {\r\n\t\tif (b == 0 || a == b) {\r\n\t\t\treturn 1L\r\n\t\t}\r\n\t\tif (a < b || b < 0) {\r\n\t\t\treturn 0L\r\n\t\t}\r\n\t\treturn fact[a] * ifact[b] % mod * ifact[a - b] % mod\r\n\t}\r\n\t\r\n\trepeat (t) {\r\n\t\tval (n, k) = readIntList()\r\n\t\t\r\n\t\tvar res = 0L\r\n\t\tif (n % 2 == 1) {\r\n\t\t\tres++\r\n\t\t\tfor (i in 0 until n step 2) {\r\n\t\t\t\tres = (res + binom(n, i)) % mod\r\n\t\t\t}\r\n\t\t\tres = modPow(res, k.toLong(), mod)\r\n\t\t} else {\r\n\t\t\tvar c = 1L\r\n\t\t\tvar te = 0L\r\n\t\t\tfor (i in 0 until n step 2) {\r\n\t\t\t\tte = (te + binom(n, i)) % mod\r\n\t\t\t}\r\n\t\t\tfor (i in 0 until k) {\r\n\t\t\t\tres = (res + c * modPow(2L, n * (k - i - 1).toLong(), mod) % mod) % mod\r\n\t\t\t\tc = c * te % mod\r\n\t\t\t}\r\n\t\t\tres = (res + c) % mod\r\n\t\t}\r\n\t\tresList.add(res)\r\n\t}\r\n\tprintln(resList.joinToString(\"\\n\"))\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "bitmasks", "matrices"], "code_uid": "199de819fab46aad9f905e85d635d580", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.ceil\n\n/* https://codeforces.com/problemset/problem/1080/A */\n\nfun main() {\n val (numOfFriends, numOfPages) = readLine()!!.split(\" \").map { it.toInt() }\n val numOfRedSheets = numOfFriends * 2\n val numOfGreenSheets = numOfFriends * 5\n val numOfBlueSheets = numOfFriends * 8\n\n val numOfRedNotebooks = ceil(numOfRedSheets.toDouble() / numOfPages.toDouble()).toInt()\n val numOfGreenNotebooks = ceil(numOfGreenSheets.toDouble() / numOfPages.toDouble()).toInt()\n val numOfBlueNotebooks = ceil(numOfBlueSheets.toDouble() / numOfPages.toDouble()).toInt()\n\n println(numOfRedNotebooks + numOfGreenNotebooks + numOfBlueNotebooks)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "896411b00b655a79351a5c9d832c2ed6", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.ceil\n\nfun main() {\n var (n, k) = readLine()!!.split(' ').map {it.toDouble() }\n var c = ceil(n*8/k) + ceil(n*5/k) + ceil(n*2/k)\n println(c.toInt())\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "953746c9c10a9981882356c50f80de5b", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, k) = readLine()!!.split(' ').map(String::toLong)\n val ans = get(2, n, k) + get(5, n, k) + get(8, n, k)\n println(ans)\n}\n\nfun get(a: Long, b: Long, c: Long) = (a * b + c - 1) / c", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "665867e96850ddc22a76a7547873246c", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.ceil\n\nfun main(args:Array){\n val reader = Scanner(System.`in`)\n\n var n = reader.nextInt() //manus\n var k = reader.nextInt() //pata\n\n var r = ceil(n*2.0/k).toInt()\n var g = ceil(n*5.0/k).toInt()\n var b = ceil(n*8.0/k).toInt()\n\n println(r+g+b)\n\n\n }\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "46e18f248d7a03c5fcd6f4a397721c9f", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(args : Array) {\n Thread { run() }.start()\n}\n\nval scanner = Scanner(System.`in`)\nval n1 =scanner.nextInt()\nval n2 = scanner.nextInt()\nval k1 = scanner.nextInt()\nval k2 = scanner.nextInt()\nval arr = Array>>(n1 + 1) { Array>(n2 + 1) { Array(k1 + 1) { IntArray(k2 + 1) { -1 } } } }\nval mod = 100000000\n\nfun run() {\n\n println(Q(n1, n2, 0, 0))\n\n}\n\nfun Q(q1: Int, q2: Int, w1: Int, w2: Int): Int {\n if (arr[q1][q2][w1][w2] != -1)\n return arr[q1][q2][w1][w2]\n var res = 0\n if (q1 != 0 && w1 != k1)\n res += Q(q1 - 1, q2, w1 + 1, 0)\n if (q2 != 0 && w2 != k2)\n res += Q(q1, q2 - 1, 0, w2 + 1)\n if (q1 == 0 && q2 == 0)\n res = 1\n res %= mod\n arr[q1][q2][w1][w2] = res\n return res\n}\n\n//fun run() {\n//\n// val scanner = Scanner(System.`in`)\n// val n1 = scanner.nextInt()\n// val n2 = scanner.nextInt()\n// val k1 = scanner.nextInt()\n// val k2 = scanner.nextInt()\n// val arr = Array>>(n1 + 1) { Array>(n2 + 1) { Array(k1 + 1) { IntArray(k2 + 1) } } }\n// val mod = 100000000\n// arr[0][0][0][0] = 1\n// for (i1 in 0 until n1) {\n// for (i2 in 0 until n2) {\n// for (j1 in 0 until k1) {\n// for (j2 in 0 until k2) {\n// arr[i1][i2][j1][j2] %= mod\n// arr[i1 + 1][i2][j1 + 1][j2] += arr[i1][i2][j1][j2]\n// arr[i1][i2 + 1][j1][j2 + 1] += arr[i1][i2][j1][j2]\n// arr[i1][i2 + 1][j1][j2] += arr[i1][i2][j1][j2]\n// arr[i1 + 1][i2][j1][j2] += arr[i1][i2][j1][j2]\n// }\n// }\n// }\n// }\n// var res = 0\n// for (i in 0..k1) {\n// for (j in 0..k2) {\n// res += arr[n1][n2][i][j]\n// res %= mod\n// }\n// }\n// println(res)\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)", "lang_cluster": "Kotlin", "tags": ["dp"], "code_uid": "9e860095ee54b5f5618c5191d9632e16", "src_uid": "63aabef26fe008e4c6fc9336eb038289", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport kotlin.math.absoluteValue\n\nfun main() {\n val modulo = 100_000_000L\n\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val (n1, n2, k1, k2) = reader.readLine().split(' ').map { it.toInt() }\n\n val states = hashMapOf, Long>()\n var xfn: ((Int, Int, Int) -> Long)? = null\n xfn = { nn1: Int, nn2: Int, k12: Int ->\n val key = Triple(nn1, nn2, k12)\n if (key in states) {\n states[key]!!\n } else {\n val fn = xfn!!\n val result = when {\n nn1 < 0 || nn2 < 0 -> 0L\n nn1 + nn2 == 0 || k12 == 0 -> if (nn1 + nn2 == 0 && k12 == 0) 1L else 0L\n k12 == 1 -> (-k1..0).map { fn(nn1, nn2-1, it) }.reduce { a, b -> (a + b) % modulo }\n k12 == -1 -> (0..k2).map { fn(nn1-1, nn2, it) }.reduce { a, b -> (a + b) % modulo }\n k12 < 0 -> fn(nn1-1, nn2, k12+1)\n k12 > 0 -> fn(nn1, nn2-1, k12-1)\n else -> throw UnknownError(\"unreachable\")\n }\n states[key] = result\n result\n }\n }\n\n println((-k1..k2).map { xfn(n1, n2, it) }.reduce { a, b -> (a + b) % modulo })\n}", "lang_cluster": "Kotlin", "tags": ["dp"], "code_uid": "6c54a522a3d9918c8353acbeafbe7c18", "src_uid": "63aabef26fe008e4c6fc9336eb038289", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val input = Scanner(System.`in`)\n val n = input.nextInt()\n val homes = mutableListOf()\n val guests = mutableListOf()\n var result = 0\n repeat(n){\n homes.add(input.nextInt())\n guests.add(input.nextInt())\n }\n guests.forEach {\n if(homes.contains(it)){\n result+= homes.count{v->\n it == v\n }\n }\n }\n println(result)\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "b63a42d4173f7bfdfb02392a425f3cd7", "src_uid": "745f81dcb4f23254bf6602f9f389771b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val queries = Integer.parseInt(readLine()!!)\n val homeColorHistogram = mutableMapOf()\n val guestColorHistogram = mutableMapOf()\n for (i in 0 until queries) {\n val input = readLine()!!.split(\" \").map(Integer::parseInt)\n val homeColor = input[0]\n homeColorHistogram[homeColor] = homeColorHistogram.getOrDefault(homeColor, 0) + 1\n\n val guestColor = input[1]\n guestColorHistogram[guestColor] = guestColorHistogram.getOrDefault(guestColor, 0) + 1\n }\n\n var matches = 0\n homeColorHistogram.forEach { homeColor, count ->\n if (guestColorHistogram.containsKey(homeColor)) {\n matches += guestColorHistogram.getOrDefault(homeColor, 0) * count\n }\n }\n\n println(matches)\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "bd928f973c1a72d2c447da9e3f54111c", "src_uid": "745f81dcb4f23254bf6602f9f389771b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = readInt()\n\n val teams = List(n) {\n readInts().toIntArray()\n }\n\n val result = teams.sumBy { team ->\n teams.minus(team).count {\n team[1] == it[0]\n }\n }\n\n println(result)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "ca0be5c6e11ae78be281c90fe7deed10", "src_uid": "745f81dcb4f23254bf6602f9f389771b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n val arr = Array(n) {Array(2) {sc.nextInt()}}\n var sum = 0\n for(ind in 0 until arr.size) {\n for(ind2 in 0 until arr.size) {\n if(ind == ind2)\n continue\n if(arr[ind][0] == arr[ind2][1])\n sum++\n }\n }\n print(sum)\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "bb50ebc6d75641de75212205a45c9e9b", "src_uid": "745f81dcb4f23254bf6602f9f389771b", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 val n = scan.int()\n exit(n*3/2)\n}\n\n ", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "611df1dcc77858bcd305d50463d8e678", "src_uid": "031e53952e76cff8fdc0988bb0d3239c", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n print(3 * readLine()!!.toInt() / 2)\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "a78bc5bb8f438a3222e8730165d04527", "src_uid": "031e53952e76cff8fdc0988bb0d3239c", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args : Array) {\n var s = Scanner(System.`in`)\n\n var n = s.nextInt()\n\n println(n / 2 * 3)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "13e87cf77d0c83e0ca5a7adec66ec1e2", "src_uid": "031e53952e76cff8fdc0988bb0d3239c", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private 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()\n\n\nfun main() {\n var n = readInt()\n println(n + n / 2)\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "5ded1fd050f1a4e622bf191832ddb228", "src_uid": "031e53952e76cff8fdc0988bb0d3239c", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : InputReader, pw : PrintWriter) {\n\n val n : Int = ir.nextInt()\n val k : Int = ir.nextInt()\n val a = IntArray(n)\n var res = 0\n\n for (i in 0 until n)\n a[i] = ir.nextInt()\n\n for (i in 0 until k) {\n var ones = 0\n var twos = 0\n for (j in i until n step k) {\n if (a[j] == 1)\n ones++\n else\n twos++\n }\n\n res += if (ones > twos)\n twos\n else\n ones\n\n }\n\n pw.print(res)\n\n}\n\nclass InputReader(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}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "d4f870d38768e1d67b05c418d97367ec", "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (n, k) = readInts()\n val arr = readInts()\n var sol = 0\n for (kPos in 0 until k) {\n var ones = 0\n var twos = 0\n for (pos in kPos until n step k) if (arr[pos] == 1) ones++ else twos++\n sol += min(ones, twos)\n }\n print(sol)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "517bece665e75127bc7753945c03efc6", "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\", \"DEPRECATION\")\r\n@file:OptIn(ExperimentalStdlibApi::class)\r\n\r\nimport java.io.PrintWriter\r\nimport java.util.StringTokenizer\r\nimport kotlin.collections.ArrayDeque\r\nimport kotlin.math.*\r\nimport kotlin.random.*\r\nimport java.util.TreeMap\r\nimport java.util.TreeSet\r\nimport java.util.PriorityQueue\r\nimport java.math.BigInteger\r\n// import java.util.*\r\n\r\n@JvmField val INPUT = System.`in`\r\n@JvmField val OUTPUT = System.out\r\n\r\n@JvmField val reader = INPUT.bufferedReader()\r\nfun readLine(): String? = reader.readLine()\r\nfun readLn() = reader.readLine()!!\r\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\r\nfun read(): String {\r\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(reader.readLine() ?: return \"\", \" \")\r\n return _tokenizer.nextToken()\r\n}\r\nfun readInt() = read().toInt()\r\nfun readDouble() = read().toDouble()\r\nfun readLong() = read().toLong()\r\nfun readStrings(n: Int = 2) = List(n) { read() }\r\nfun readString() = readStrings(1)[0]\r\nfun readLines(n: Int) = List(n) { readLn() }\r\nfun readInts(n: Int = 2) = List(n) { read().toInt() }\r\nfun readInts1(n: Int = 2) = List(n) { read().toInt() - 1 }\r\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\r\nfun readDoubles(n: Int = 2) = List(n) { read().toDouble() }\r\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\r\nfun readLongs(n: Int = 2) = List(n) { read().toLong() }\r\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\r\n\r\n// val isLocal = System.getenv(\"IS_LOCAL_CP\") == \"true\"\r\n\r\n@JvmField\r\nval writer = PrintWriter(OUTPUT)\r\n\r\n// ----------------------------------------------------------------------------\r\n\r\nclass UnionFind {\r\n\r\n private val parents = mutableMapOf()\r\n private val sizes = mutableMapOf()\r\n\r\n fun union(a: Int, b: Int) {\r\n val fa = find(a)\r\n val fb = find(b)\r\n if (fa != fb) {\r\n parents[fa] = fb\r\n sizes[fb] = (sizes[fb] ?: 1) + (sizes[fa] ?: 1)\r\n }\r\n }\r\n\r\n fun find(a: Int): Int {\r\n fun getOrDefault(value: Int) = parents.getOrDefault(value, value)\r\n\r\n var parent = getOrDefault(a)\r\n while (parent != getOrDefault(parent)) {\r\n parents[parent] = getOrDefault(getOrDefault(parent))\r\n parent = parents[parent]!!\r\n }\r\n return parent\r\n }\r\n\r\n fun connected(a: Int, b: Int): Boolean {\r\n return find(a) == find(b)\r\n }\r\n\r\n fun getSize(a: Int): Int {\r\n return sizes[find(a)] ?: 1\r\n }\r\n}\r\n\r\nclass UnionFindArray(private val n: Int) {\r\n\r\n private val parents = IntArray(n + 1) { it }\r\n\r\n fun union(a: Int, b: Int) {\r\n val fa = find(a)\r\n val fb = find(b)\r\n if (fa != fb) {\r\n parents[fa] = fb\r\n }\r\n }\r\n\r\n fun find(a: Int): Int {\r\n var parent = parents[a]\r\n while (parent != parents[parent]) {\r\n parents[parent] = parents[parents[parent]]\r\n parent = parents[parent]\r\n }\r\n return parent\r\n }\r\n\r\n fun connected(a: Int, b: Int): Boolean {\r\n return find(a) == find(b)\r\n }\r\n}\r\n\r\nclass Trie() {\r\n\r\n /** Initialize your data structure here. */\r\n private val root = Node()\r\n\r\n /** Inserts a word into the trie. */\r\n fun insert(word: String) {\r\n var node = root\r\n for (char in word) {\r\n if (!node.children.contains(char)) {\r\n node.children[char] = Node()\r\n }\r\n node = node.children[char]!!\r\n }\r\n node.hasWord = true\r\n }\r\n\r\n /** Returns if the word is in the trie. */\r\n fun search(word: String): Boolean {\r\n return findNode(word)?.hasWord ?: false\r\n }\r\n\r\n /** Returns if there is any word in the trie that starts with the given prefix. */\r\n fun startsWith(prefix: String): Boolean {\r\n return findNode(prefix) != null\r\n }\r\n\r\n private fun findNode(prefix: String): Node? {\r\n var node = root\r\n for (char in prefix) {\r\n node = node.children[char] ?: return null\r\n }\r\n return node\r\n }\r\n\r\n private class Node(\r\n var hasWord: Boolean = false,\r\n val children: MutableMap = mutableMapOf()\r\n )\r\n}\r\n\r\n// \u6240\u6709\u51fd\u6570\u7684\u4e0b\u6807\u4ece 0 \u5f00\u59cb\r\n// query(index): sum[0, index]\r\nclass BinaryIndexedTree {\r\n\r\n private val bit: IntArray\r\n\r\n constructor(n: Int) {\r\n this.bit = IntArray(n + 1)\r\n }\r\n\r\n constructor(nums: IntArray) {\r\n this.bit = IntArray(nums.size + 1)\r\n val prefix = IntArray(bit.size)\r\n for (i in 1 until nums.size + 1) {\r\n prefix[i] = prefix[i - 1] + nums[i - 1]\r\n bit[i] = prefix[i] - prefix[i - lowbit(i)]\r\n }\r\n }\r\n\r\n fun query(index: Int): Int {\r\n var result = 0\r\n var i = index + 1\r\n while (i > 0) {\r\n result += bit[i]\r\n i -= lowbit(i)\r\n }\r\n return result\r\n }\r\n\r\n fun update(index: Int, x: Int) {\r\n val value = query(index) - query(index - 1)\r\n add(index, x - value)\r\n }\r\n\r\n fun add(index: Int, x: Int) {\r\n var i = index + 1\r\n while (i < bit.size) {\r\n bit[i] += x\r\n i += lowbit(i)\r\n }\r\n }\r\n\r\n override fun toString(): String {\r\n return IntArray(bit.size - 1) { query(it) - query(it - 1) }.toList().toString()\r\n }\r\n\r\n private fun lowbit(x: Int): Int {\r\n return x.and(-x)\r\n }\r\n}\r\n\r\n// \u6240\u6709\u51fd\u6570\u7684\u4e0b\u6807\u4ece 0 \u5f00\u59cb\r\n// query(index): max[0, index]\r\n// udpate(index, x): \u66f4\u65b0 [0, index] \u4e4b\u95f4\u7684\u6700\u5927\u503c\uff0c\u53ea\u80fd\u8d8a\u6765\u8d8a\u5927\r\nclass BinaryIndexedTreeMax {\r\n\r\n private val bit: IntArray\r\n\r\n constructor(n: Int) {\r\n this.bit = IntArray(n + 1)\r\n }\r\n\r\n fun query(index: Int): Int {\r\n var result = 0\r\n var i = index + 1\r\n while (i > 0) {\r\n result = Math.max(result, bit[i])\r\n i -= lowbit(i)\r\n }\r\n return result\r\n }\r\n\r\n fun update(index: Int, x: Int) {\r\n var i = index + 1\r\n while (i < bit.size) {\r\n bit[i] = Math.max(bit[i], x)\r\n i += lowbit(i)\r\n }\r\n }\r\n\r\n private fun lowbit(x: Int): Int {\r\n return x.and(-x)\r\n }\r\n}\r\n\r\nclass SparseTableMax(private val nums: IntArray) {\r\n\r\n private val st: Array\r\n\r\n init {\r\n val n = nums.size\r\n val logN = Integer.numberOfTrailingZeros(Integer.highestOneBit(n))\r\n this.st = Array(logN + 1) { IntArray(n) }\r\n for (i in 0 until n) {\r\n st[0][i] = nums[i]\r\n }\r\n for (i in 1 until logN + 1) {\r\n for (j in 0 until n - 1.shl(i - 1)) {\r\n st[i][j] = Math.max(st[i - 1][j], st[i - 1][j + 1.shl(i - 1)])\r\n }\r\n }\r\n }\r\n\r\n fun query(left: Int, right: Int): Int {\r\n if (left > right) {\r\n return -1\r\n }\r\n val len = right - left + 1\r\n val k = Integer.numberOfTrailingZeros(Integer.highestOneBit(len))\r\n return Math.max(st[k][left], st[k][right - 1.shl(k) + 1])\r\n }\r\n}\r\n\r\nclass SparseTableMin(private val nums: IntArray) {\r\n\r\n private val st: Array\r\n\r\n init {\r\n val n = nums.size\r\n val logN = Integer.numberOfTrailingZeros(Integer.highestOneBit(n))\r\n this.st = Array(logN + 1) { IntArray(n) { Int.MAX_VALUE / 2 } }\r\n for (i in 0 until n) {\r\n st[0][i] = nums[i]\r\n }\r\n for (i in 1 until logN + 1) {\r\n for (j in 0 until n - 1.shl(i - 1)) {\r\n st[i][j] = Math.min(st[i - 1][j], st[i - 1][j + 1.shl(i - 1)])\r\n }\r\n }\r\n }\r\n\r\n fun query(left: Int, right: Int): Int {\r\n if (left > right) {\r\n return -1\r\n }\r\n val len = right - left + 1\r\n val k = Integer.numberOfTrailingZeros(Integer.highestOneBit(len))\r\n return Math.min(st[k][left], st[k][right - 1.shl(k) + 1])\r\n }\r\n}\r\n\r\nclass PrefixSum2D(private val grid: Array) {\r\n\r\n private val prefix: Array\r\n\r\n init {\r\n val (m, n) = Pair(grid.size, grid[0].size)\r\n prefix = Array(m + 1) { IntArray(n + 1) }\r\n for (i in 0 until m) {\r\n var row = 0\r\n for (j in 0 until n) {\r\n row += grid[i][j]\r\n prefix[i + 1][j + 1] = prefix[i][j + 1] + row\r\n }\r\n }\r\n }\r\n\r\n fun query(up: Int, left: Int, bottom: Int, right: Int): Int {\r\n return prefix[up][left] + prefix[bottom + 1][right + 1] -\r\n prefix[bottom + 1][left] - prefix[up][right + 1]\r\n }\r\n}\r\n\r\n// ----------------------------------------------------------------------------\r\n\r\ntypealias Graph = Array>\r\n\r\nprivate fun edgesToGraph(n: Int, edges: Array>, directed: Boolean = false): Graph {\r\n val graph = Array(n) { mutableListOf() }\r\n for ((a, b) in edges) {\r\n graph[a].add(b)\r\n if (!directed) {\r\n graph[b].add(a)\r\n }\r\n }\r\n return graph\r\n}\r\n\r\ntypealias GraphW = Array>>\r\n\r\nprivate fun edgesToGraphW(n: Int, edges: Array>, directed: Boolean = false): GraphW {\r\n val graph = Array(n) { mutableListOf>() }\r\n for ((u, v, w) in edges) {\r\n graph[u].add(Pair(v, w))\r\n if (!directed) {\r\n graph[v].add(Pair(u, w))\r\n }\r\n }\r\n return graph\r\n}\r\n\r\nfun makePoint(x: Int, y: Int) = (x.toLong() shl 32) or y.toLong()\r\nfun Long.x() = (this shr 32).toInt()\r\nfun Long.y() = this.toInt()\r\noperator fun Long.component1() = (this shr 32).toInt()\r\noperator fun Long.component2() = this.toInt()\r\n\r\nprivate fun PrintWriter.printNums(nums: List) {\r\n if (nums.isEmpty()) {\r\n println()\r\n return\r\n }\r\n for (i in 0 until nums.size - 1) {\r\n print(nums[i])\r\n print(' ')\r\n }\r\n println(nums.last())\r\n}\r\n\r\nprivate fun genPrefix(nums: LongArray): LongArray {\r\n val n = nums.size\r\n val prefix = LongArray(n + 1)\r\n for (i in 0 until n) {\r\n prefix[i + 1] = prefix[i] + nums[i]\r\n }\r\n return prefix\r\n}\r\n\r\nprivate fun lengthOfLIS(numsInput: List): Int {\r\n val nums = unify(numsInput)\r\n val bit = BinaryIndexedTreeMax(nums.size + 1)\r\n var result = 0\r\n for (num in nums) {\r\n val len = bit.query(num - 1) + 1\r\n bit.update(num, len)\r\n result = Math.max(result, len)\r\n }\r\n return result\r\n}\r\n\r\nprivate fun unify(nums: List): List {\r\n val numToIndex = nums.sorted().mapIndexed { index, num -> num to index }.toMap()\r\n return nums.map { numToIndex[it]!! }\r\n}\r\n\r\nprivate fun fastPow(a: Long, exp: Long, mod: Long = MODL): Long {\r\n var result = 1L % mod\r\n var base = a % mod\r\n var remain = exp\r\n while (remain != 0L) {\r\n if (remain % 2L == 1L) {\r\n result = (result * base) % mod\r\n }\r\n base = (base * base) % mod\r\n remain /= 2L\r\n }\r\n return result\r\n}\r\n\r\nprivate fun inv(a: Long, mod: Long = MODL): Long {\r\n return fastPow(a, mod - 2L, mod)\r\n}\r\n\r\nprivate fun gcd(a: Int, b: Int): Int {\r\n return if (b == 0) a else gcd(b, a % b)\r\n}\r\n\r\nprivate fun gcdL(a: Long, b: Long): Long {\r\n return if (b == 0L) a else gcdL(b, a % b)\r\n}\r\n\r\nprivate fun lcm(a: Int, b: Int): Int {\r\n return a / gcd(a, b) * b\r\n}\r\n\r\nprivate fun lcmL(a: Long, b: Long): Long {\r\n return a / gcdL(a, b) * b\r\n}\r\n\r\nprivate fun wordToCharCount(word: String): IntArray {\r\n val charCount = IntArray(26)\r\n for (char in word) {\r\n charCount[char.toIndex()]++\r\n }\r\n return charCount\r\n}\r\n\r\nprivate fun Char.toIndex(): Int {\r\n return this.toInt() - 'a'.toInt()\r\n}\r\n\r\nprivate fun Char.toDigit(): Int {\r\n return this.toInt() - '0'.toInt()\r\n}\r\n\r\nprivate fun Int.isBit(i: Int): Boolean {\r\n return this.and(1.shl(i)) != 0\r\n}\r\n\r\nprivate fun Int.setBit(i: Int): Int {\r\n return this.or(1.shl(i))\r\n}\r\n\r\nprivate fun Int.getBit(i: Int): Int {\r\n return this.and(1.shl(i))\r\n}\r\n\r\nprivate fun Int.clearBit(i: Int): Int {\r\n return this.and(1.shl(i).inv())\r\n}\r\n\r\nprivate fun Long.modSum(other: Long, mod: Long = MODL): Long {\r\n return ((this % MODL) + (other % MODL)) % MODL\r\n}\r\n\r\nprivate fun Int.modSum(other: Int, mod: Int = MOD): Int {\r\n return ((this % MOD) + (other % MOD)) % MOD\r\n}\r\n\r\nprivate fun Boolean.toYesNo(upper: Boolean = false): String {\r\n val yesNo = if (this) \"Yes\" else \"No\"\r\n return if (upper) yesNo.toUpperCase() else yesNo\r\n}\r\n\r\nprivate fun LongArray.modSum(mod: Long = MODL): Long {\r\n var sum = 0L\r\n for (num in this) {\r\n sum = (sum + num) % mod\r\n }\r\n return sum\r\n}\r\n\r\nprivate fun IntArray.swap(i: Int, j: Int) {\r\n val temp = this[i]\r\n this[i] = this[j]\r\n this[j] = temp\r\n}\r\n\r\nprivate fun LongArray.swap(i: Int, j: Int) {\r\n val temp = this[i]\r\n this[i] = this[j]\r\n this[j] = temp\r\n}\r\n\r\nprivate fun CharArray.swap(i: Int, j: Int) {\r\n val temp = this[i]\r\n this[i] = this[j]\r\n this[j] = temp\r\n}\r\n\r\nprivate fun List.toArrayDeque(): ArrayDeque {\r\n return ArrayDeque(this)\r\n}\r\n\r\nprivate fun List.toPair(): Pair {\r\n return Pair(this[0], this[1])\r\n}\r\n\r\nprivate fun List.listEquals(other: List): Boolean {\r\n return this.size == other.size && (0 until this.size).all { this[it] == other[it] }\r\n}\r\n\r\nprivate fun > List.compareTo(other: List): Int {\r\n val n = Math.min(this.size, other.size)\r\n for (i in 0 until n) {\r\n val c = this[i].compareTo(other[i])\r\n if (c != 0) {\r\n return c\r\n }\r\n }\r\n return when {\r\n this.size < other.size -> -1\r\n this.size > other.size -> 1\r\n else -> 0\r\n }\r\n}\r\n\r\nprivate fun > List.isSorted(): Boolean {\r\n return this.listEquals(this.sorted())\r\n}\r\n\r\nprivate fun > List.findMin(): T {\r\n var result = this[0]\r\n for (num in this) {\r\n result = if (result.compareTo(num) < 0) result else num\r\n }\r\n return result\r\n}\r\n\r\nprivate fun > List.findMax(): T {\r\n var result = this[0]\r\n for (num in this) {\r\n result = if (result.compareTo(num) > 0) result else num\r\n }\r\n return result\r\n}\r\n\r\nprivate fun > T.max(target: T): T = this.coerceAtLeast(target)\r\n\r\nprivate fun > T.min(target: T): T = this.coerceAtMost(target)\r\n\r\nprivate val DIR = listOf(\r\n listOf(1, 0), listOf(0, -1), listOf(-1, 0), listOf(0, 1)\r\n)\r\n\r\nprivate const val MOD = 998244353\r\nprivate const val MODL = 998244353L\r\nval MODLL = 998244353L.toBigInteger()\r\n// private const val MOD = 1000000007\r\n// private const val MODL = 1000000007L\r\nprivate const val EPS = 0.000001\r\n\r\n// ----------------------------------------------------------------------------\r\n\r\nfun main() {\r\n val go: Runnable = Runnable {\r\n writer.solve()\r\n writer.flush()\r\n }\r\n Thread(null, go, \"thread\", 1L.shl(28)).start()\r\n // writer.solve()\r\n // writer.flush()\r\n}\r\n\r\nprivate fun PrintWriter.solve() {\r\n val n = readInt()\r\n val m = readLong()\r\n println(countingArrays(n, m.toBigInteger()))\r\n}\r\n\r\nprivate fun countingArrays(n: Int, m: BigInteger): BigInteger {\r\n var mul = 1L.toBigInteger()\r\n val factors = mutableSetOf()\r\n var last = 0L.toBigInteger()\r\n var result = 0L.toBigInteger()\r\n var base = 1L.toBigInteger()\r\n for (i in 2 until n + 1) {\r\n base = (base * m) % MODLL\r\n if (mul <= m) {\r\n for (fa in primeFactor(i)) {\r\n if (!factors.contains(fa)) {\r\n factors.add(fa)\r\n mul *= fa.toBigInteger()\r\n if (mul > m) {\r\n break\r\n }\r\n }\r\n }\r\n }\r\n // println(mul)\r\n // mul = lcmL(mul, i.toLong())\r\n // mul = mul.min(m + 1L)\r\n val count = if (mul > m) m else m - m / mul\r\n val a = (last * m) % MODLL\r\n val b = ((base - last) * count) % MODLL\r\n // println(\"$i, $mul, $count. $base, $a, $b, ${a + b}\")\r\n last = (a + b + MODLL) % MODLL\r\n result = (result + last) % MODLL\r\n }\r\n return result\r\n}\r\n\r\n// private fun countingArrays(n: Int, m: Long): Long {\r\n// var mul = 1L\r\n// val factors = mutableSetOf()\r\n// var last = 0L\r\n// var result = 0L\r\n// var base = 1L\r\n// for (i in 2 until n + 1) {\r\n// base = (base * m) % MODL\r\n// if (mul <= m) {\r\n// for (fa in primeFactor(i)) {\r\n// if (!factors.contains(fa)) {\r\n// factors.add(fa)\r\n// mul *= fa\r\n// if (mul > m) {\r\n// break\r\n// }\r\n// }\r\n// }\r\n// }\r\n// println(mul)\r\n// // mul = lcmL(mul, i.toLong())\r\n// // mul = mul.min(m + 1L)\r\n// val count = if (mul > m) m else m - m / mul\r\n// val a = (last * m) % MODL\r\n// val b = ((base - last) * count) % MODL\r\n// println(\"$i, $mul, $count. $base, $a, $b, ${a + b}\")\r\n// last = (a + b + MODL) % MODL\r\n// result += last\r\n// }\r\n// return result\r\n// }\r\n\r\n/**\r\n * \u8fd4\u56de\u8d28\u56e0\u6570\u5217\u8868\uff0c\u5df2\u6392\u5e8f\r\n * \u65f6\u95f4\u590d\u6742\u5ea6 n^0.5\r\n */\r\nprivate fun primeFactor(n: Int): List {\r\n var remain = n\r\n val result = mutableListOf()\r\n var k = 2\r\n while (k * k <= remain) {\r\n while (remain != k && remain % k == 0) {\r\n result.add(k)\r\n remain /= k\r\n }\r\n k++\r\n }\r\n if (remain != 1) {\r\n result.add(remain)\r\n }\r\n return result\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "e50a8370238792b8abe3a9ebe3c1e4c2", "src_uid": "0fdd91ed33431848614075ebe9d2ee68", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "import java.util.Scanner\r\n\r\nfun main() {\r\n\tval sc = Scanner(System.`in`)\r\n\r\n\tval n = sc.nextInt()\r\n\tval m = sc.nextLong()\r\n\r\n\tval lim = 998244353L\r\n\r\n\t// calculating the number of all the possible arrays for each length from 1 to n\r\n\tvar currPow = 1L\r\n\tvar res = 0L\r\n\tfor (i in 1..n) {\r\n\t\tcurrPow = (currPow * (m % lim)) % lim\r\n\t\tcurrPow = (currPow + lim) % lim\r\n\r\n\t\tres = (res + currPow) % lim\r\n\t\tres = (res + lim) % lim\r\n\t}\r\n\r\n\t// calculate primes\r\n\tval primes = mutableListOf()\r\n\tval isPrime = MutableList(n + 1) { true }\r\n\tvar currPrime = 2L\r\n\twhile (currPrime <= n) {\r\n\t\tif (isPrime[currPrime.toInt()]) {\r\n\t\t\tprimes.add(currPrime.toInt())\r\n\r\n\t\t\tfor (nonPrime in currPrime * currPrime..n step currPrime) {\r\n\t\t\t\tisPrime[nonPrime.toInt()] = false\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tcurrPrime += 1L\r\n\t}\r\n\tisPrime.clear()\r\n\r\n\t// subtracting the number of all the 'bad' array for each array length from 1 to n\r\n\t// left with only the 'good' ones\r\n\r\n\tvar lastPrimeIdx = 0\r\n\tvar currPrimesMult = 1L\r\n\tvar toSubtract = 1L\r\n\r\n\tfor (currLength in 1..n) {\r\n\t\tif (lastPrimeIdx < primes.size && currLength >= primes[lastPrimeIdx]) {\r\n\t\t\tcurrPrimesMult *= primes[lastPrimeIdx]\r\n\t\t\t++lastPrimeIdx\r\n\t\t}\r\n\r\n\t\tif (m < currPrimesMult) {\r\n\t\t\tbreak\r\n\t\t}\r\n\r\n\t\tval newPart = (m / currPrimesMult) % lim\r\n\t\tif (newPart == 0L) {\r\n\t\t\tbreak\r\n\t\t}\r\n\r\n\t\ttoSubtract = (toSubtract * newPart) % lim\r\n\t\ttoSubtract = (toSubtract + lim) % lim\r\n\r\n\t\tres = (res - toSubtract) % lim\r\n\t\tres = (res + lim) % lim\r\n\t}\r\n\r\n\tprintln(res)\r\n\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "9389d6b8e8e048b2ffbfe6f940dfc622", "src_uid": "0fdd91ed33431848614075ebe9d2ee68", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "import java.io.InputStreamReader\r\nimport java.io.PrintWriter\r\nimport java.math.BigInteger\r\nimport java.util.*\r\nimport kotlin.math.*\r\n\r\nconst val FLUSH_WRITER = false\r\n\r\nfun main() {\r\n val tests = 1\r\n\r\n\r\n for (i in 1 .. tests) {\r\n val n = readInt()\r\n\r\n val m = readLong()\r\n writeln(solve(n, m))\r\n }\r\n closeWriter()\r\n}\r\n\r\nval MOD = 998244353\r\nval MOD_BIG = BigInteger.valueOf(MOD.toLong())\r\n\r\nfun solve(n: Int, m: Long): Long {\r\n var lcm = 1L\r\n var all = BigInteger.valueOf(1L)\r\n val bigM = m.toBigInteger()\r\n var bad = 1L\r\n var toDeduct = 0L\r\n var s = 0L\r\n\r\n for (i in 1 .. n) {\r\n if (lcm <= m && i.prime()) {\r\n lcm = (lcm * i) / gcd(i.toLong(), lcm)\r\n }\r\n\r\n val rem = m / lcm\r\n all = (all * bigM) % MOD_BIG\r\n bad = (bad * (rem % MOD)) % MOD\r\n toDeduct = (toDeduct + bad) % MOD\r\n s = (s + all.toLong()) % MOD\r\n }\r\n\r\n return toAdd(s, toDeduct)\r\n}\r\n\r\nfun Int.prime(): Boolean {\r\n var i = 2\r\n while (i * i <= this) {\r\n if (this % i == 0) return false\r\n i++\r\n }\r\n\r\n return true\r\n}\r\n\r\nfun toAdd(all: Long, bad: Long): Long {\r\n if (all - bad < 0) return MOD + (all - bad)\r\n return all - bad\r\n}\r\n\r\nfun gcd(a: Long, b: Long) : Long {\r\n if (b == 0L) {\r\n return a\r\n }\r\n return gcd(b, a % b)\r\n}\r\n\r\nfun gcd(a: Int, b: Int) : Int {\r\n if (b == 0) {\r\n return a\r\n }\r\n return gcd(b, a % b)\r\n}\r\n\r\nfun readListInt(n: Int) = (1..n).map { readInt() }\r\n\r\nfun readListLong(n: Int) = (1..n).map { readLong() }\r\n\r\nfun readListString(n: Int) = (1..n).map { read() }\r\n\r\nfun zFunc(s: String): IntArray {\r\n val z = IntArray(s.length)\r\n\r\n var l = 0\r\n var r = 0\r\n for (i in 1 until s.length) {\r\n if (i < r) {\r\n z[i] = minOf(r - i + 1, z[i - l])\r\n }\r\n while (i + z[i] < s.length && s[z[i]] == s[i + z[i]]) {\r\n z[i]++\r\n }\r\n\r\n if (r < i + z[i] - 1) {\r\n r = i + z[i] - 1\r\n l = i\r\n }\r\n }\r\n\r\n return z\r\n}\r\n\r\nfun String.fastContains(p: String): Boolean {\r\n if (p.length > this.length) {\r\n return false\r\n }\r\n val s = \"$p\\u0001$this\"\r\n return zFunc(s).contains(p.length)\r\n}\r\n\r\nclass Graph(val size: Int) {\r\n private val g = Array(size) { mutableListOf() }\r\n\r\n fun addEdge(from: Int, to: Int, w: Int = 1) = g[from].add(Edge(from, to, w))\r\n\r\n fun getEdges(from: Int) = g[from]\r\n\r\n fun getAllEdges() = g.flatMap { it }\r\n}\r\n\r\nfun findShortestPaths(g: Graph, source: Int): IntArray {\r\n val distances = IntArray(g.size) { Int.MAX_VALUE }\r\n distances[source] = 0\r\n val handled = BooleanArray(g.size)\r\n\r\n val pq = PriorityQueue(compareBy { distances[it] }).apply {\r\n add(source)\r\n }\r\n\r\n while (pq.isNotEmpty()) {\r\n val vertex = pq.poll()\r\n if (handled[vertex]) continue\r\n val distanceToVertex = distances[vertex]\r\n\r\n for ((_, to, weight) in g.getEdges(vertex)) {\r\n if (distanceToVertex + weight < distances[to]) {\r\n distances[to] = distanceToVertex + weight\r\n pq.add(to)\r\n }\r\n }\r\n }\r\n\r\n return distances\r\n}\r\n\r\ndata class Edge(val from: Int, val to: Int, val w: Int = 1)\r\n\r\ndata class FlowEdge(val from: Int, val to: Int, val capacity: Int) {\r\n var flow = 0\r\n\r\n fun residual() = capacity - flow\r\n}\r\n\r\nclass FlowGraph(val n: Int) {\r\n val from = Array(n) { mutableListOf() }\r\n val to = Array(n) { mutableListOf() }\r\n\r\n fun addEdge(f: Int, t: Int, c: Int = 1): FlowEdge {\r\n val e = FlowEdge(f, t, c)\r\n from[f].add(e)\r\n to[t].add(e)\r\n return e\r\n }\r\n\r\n fun findMaxFlow(source: Int, sink: Int): Int {\r\n while (tryToAddFlow(source, sink)) {\r\n //do nothing\r\n }\r\n\r\n return from[source].sumBy { it.flow }\r\n }\r\n\r\n private fun tryToAddFlow(source: Int, sink: Int): Boolean {\r\n val visited = BooleanArray(n)\r\n val cameByEdge = Array(n) { null }\r\n visited[source] = true\r\n val queue = LinkedList()\r\n queue.add(source)\r\n\r\n while (queue.isNotEmpty()) {\r\n val v = queue.poll()\r\n\r\n for (e in from[v]) {\r\n if (!visited[e.to] && e.residual() > 0) {\r\n visited[e.to] = true\r\n cameByEdge[e.to] = e\r\n queue.add(e.to)\r\n }\r\n }\r\n\r\n for (e in to[v]) {\r\n if (!visited[e.from] && e.flow > 0) {\r\n visited[e.from] = true\r\n cameByEdge[e.from] = e\r\n queue.add(e.from)\r\n }\r\n }\r\n }\r\n\r\n if (!visited[sink]) {\r\n return false\r\n }\r\n\r\n var v = sink\r\n var maxFlow = Int.MAX_VALUE\r\n while (cameByEdge[v] != null) {\r\n val e = cameByEdge[v]!!\r\n if (e.to == v) {\r\n maxFlow = minOf(maxFlow, e.residual())\r\n v = e.from\r\n } else {\r\n maxFlow = minOf(maxFlow, e.flow)\r\n v = e.to\r\n }\r\n }\r\n\r\n v = sink\r\n while (cameByEdge[v] != null) {\r\n val e = cameByEdge[v]!!\r\n if (e.to == v) {\r\n e.flow += maxFlow\r\n v = e.from\r\n } else {\r\n e.flow -= maxFlow\r\n v = e.to\r\n }\r\n }\r\n\r\n return true\r\n }\r\n}\r\n\r\nclass SumSegmentTree(n: Int) {\r\n\r\n private val base = (2.0.pow(ceil(log2(n.toDouble())))).toInt()\r\n private val a = IntArray(base * 2)\r\n\r\n fun agg(left: Int, right: Int): Int {\r\n var l = left + base\r\n var r = right + base\r\n\r\n var agg = 0\r\n while (l <= r) {\r\n if (l % 2 != 0) {\r\n agg += a[l++]\r\n }\r\n if (r % 2 == 0) {\r\n agg += a[r--]\r\n }\r\n l /= 2\r\n r /= 2\r\n }\r\n\r\n return agg\r\n }\r\n\r\n fun set(pos: Int, v: Int) {\r\n var i = pos + base\r\n a[i] = v\r\n i /= 2\r\n while (i > 0) {\r\n a[i] = a[i * 2] + a[i * 2 + 1]\r\n i /= 2\r\n }\r\n }\r\n}\r\n\r\nfun writeln(obj: Any) {\r\n writer.writeln(obj)\r\n}\r\n\r\nfun writeln() {\r\n writer.writeln()\r\n}\r\n\r\nfun closeWriter() {\r\n writer.close()\r\n}\r\n\r\nobject writer {\r\n private val writer = PrintWriter(System.out)\r\n\r\n fun writeln(obj: Any) {\r\n writer.println(obj)\r\n if (FLUSH_WRITER) {\r\n writer.flush()\r\n }\r\n }\r\n\r\n fun writeln() {\r\n writer.println()\r\n if (FLUSH_WRITER) {\r\n writer.flush()\r\n }\r\n }\r\n\r\n fun close() {\r\n writer.close()\r\n }\r\n}\r\n\r\nfun read() = reader.next()\r\n\r\nfun readInt() = reader.nextInt()\r\n\r\nfun readLong() = reader.nextLong()\r\n\r\nfun readDouble() = reader.nextDouble()\r\n\r\nfun readLn() = reader.nextLine()\r\n\r\nobject reader {\r\n private var tokens: StringTokenizer? = null\r\n private val reader = InputStreamReader(System.`in`).buffered()\r\n\r\n fun next(): String {\r\n var hasNext = tokens?.hasMoreElements() ?: false\r\n while (!hasNext) {\r\n tokens = StringTokenizer(reader.readLine())\r\n hasNext = tokens?.hasMoreElements() ?: false\r\n }\r\n\r\n return tokens!!.nextToken()\r\n }\r\n\r\n fun nextLine(): String {\r\n tokens = null\r\n return reader.readLine()\r\n }\r\n\r\n fun nextInt() = next().toInt()\r\n\r\n fun nextLong() = next().toLong()\r\n\r\n fun nextDouble() = next().toDouble()\r\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "7c663fa1fb05ea2d9697924d863ba3a0", "src_uid": "0fdd91ed33431848614075ebe9d2ee68", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "import java.io.File\nimport java.util.*\n\nfun main() {\n val mod = 998244353L\n val (nl, m) = readLongs()\n val n = nl.toInt()\n val sieve = PrimesSieve138d2D.upTo(n)\n with(Modulo138d2D(mod)) {\n var ans = 0L\n for (i in 1L..n) {\n ans = plusMod(ans, powMod(m % mod, i))\n }\n var primesProd = 1L\n var acc = 1L\n for (i in 1..n) {\n if (primesProd > m) \n break\n if (sieve.isPrime(i))\n primesProd *= i.toLong()\n val nonMatching = (m / primesProd) % mod\n acc = timesMod(acc, nonMatching)\n ans = minusMod(ans, acc)\n }\n println(ans)\n }\n}\n\nprivate fun Modulo138d2D.powMod(base: Long, exp: Long): Long {\n if (exp == 0L)\n return 1\n val res = powMod(base, exp / 2)\n return if (exp % 2 == 1L) {\n timesMod(res, timesMod(res, base))\n } else {\n timesMod(res, res)\n }\n}\n\n//region utils\nprivate val inCompetition = System.getProperty(\"ONLINE_JUDGE\") == \"true\"\nprivate val inputReader = if (inCompetition) System.`in`.bufferedReader() else File(\"input.txt\").bufferedReader()\nprivate fun readLine() = inputReader.readLine()\nprivate fun readIntLine() = inputReader.readLine().toInt()\nprivate fun readWords() = readLine().split(\" \")\nprivate fun readInts() = readWords().map(String::toInt)\nprivate fun readLongs() = readWords().map(String::toLong)\n\nprivate class Modulo138d2D(val base: Long) {\n init {\n require(base * base / base == base) { \"The base $base caused an overflow\" }\n }\n\n fun plusMod(a: Long, b: Long) = a.plus(b).mod(base)\n fun minusMod(a: Long, b: Long) = plusMod(a, -b)\n fun timesMod(a: Long, b: Long) = a.times(b).mod(base)\n}\n\nprivate class PrimesSieve138d2D private constructor(val size: Int) {\n companion object {\n fun upTo(n: Int): PrimesSieve138d2D = PrimesSieve138d2D(size = n + 1)\n }\n\n private val isComposite = BitSet(size).apply {\n for (i in 2 until size()) {\n if (!get(i)) {\n for (j in i * 2 until size step i)\n set(j, true)\n }\n }\n }\n\n fun isPrime(i: Int): Boolean {\n require(i >= 1) { \"Expected a positive number, got $i\" }\n require(i < size) { \"Expected a number smaller than $size got $i\" }\n return !isComposite[i]\n }\n}\n//endregion", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "974f9f3d0ce8d6743f32aa1dfcf44ca5", "src_uid": "0fdd91ed33431848614075ebe9d2ee68", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(){\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(' ').map(String::toInt)\n fun readLongs() = readLine()!!.split(' ').map(String::toLong)\n val mod = 998244353L\n val (n, k) = readInts()\n val f = LongArray(n + 1)\n val g = LongArray(n + 1)\n for(i in 0..n) f[i] = if(i == 0) 1 else f[i - 1] * i % mod\n for(i in 1..n) g[i] = if(i == 1) 1 else (mod - mod / i) * g[mod.toInt() % i] % mod\n for(i in 0..n) g[i] = if(i == 0) 1 else g[i] * g[i - 1] % mod\n var ans = 0L\n val C = {\n m : Int, n : Int ->\n if(m < n) 0L\n else f[m] * g[n] % mod * g[m - n] % mod\n }\n for(i in 1..n)\n ans += C(n / i - 1, k - 1)\n print(ans % mod)\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics", "number theory"], "code_uid": "1c0215501acafe82984798abb12993f2", "src_uid": "8e8eb64a047cb970a549ee870c3d280d", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Math\n\nval MOD : Long = 998244353\nfun power(a: Long, n : Long): Long\n{\n var res: Long = 1;\n var now: Long = a;\n var up: Long = n\n while(up!=0L)\n {\n if ((up and 1) == 1L)\n {\n res = (res * now) % MOD\n }\n up /= 2\n now = (now*now)%MOD\n }\n return res%MOD\n}\nfun inv(a: Long) : Long\n{\n return power(a, MOD-2)%MOD\n}\nvar fact = Array(555555){i->0}\nfun C(n: Int, r: Int):Long\n{\n if (n< r) return 0L\n return fact[n]%MOD*inv(fact[n-r])%MOD * inv(fact[r])\n}\nfun solve()\n{\n fact[0] = 1L\n for(i in 1..555554) fact[i] = fact[i-1]*i % MOD\n var n = 1\n var k = 1\n var t = readLine()!!.split(' ')\n n = t[0].toInt()\n k = t[1].toInt()\n var res:Long = 0\n for (i in 1..n)\n {\n res += C(n/i-1, k-1) % MOD\n res%=MOD\n }\n println(res)\n}\nfun main()\n{\n var T: Int = 1;\n repeat(T)\n {\n solve();\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics", "number theory"], "code_uid": "ac5b2d591bd6314f3d80fea0489fcafe", "src_uid": "8e8eb64a047cb970a549ee870c3d280d", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\nval mod=998244353\nfun main(){\n var (n,k)=readInts()\n var F=Array(n+1){1L}\n for(i in 1..n)F[i]=F[i-1]*i%mod\n var I=Array(n+1){1L}\n for(i in 2..n)I[i]=(mod-mod/i)*I[mod%i]%mod\n for(i in 1..n)I[i]=I[i-1]*I[i]%mod\n fun binom(n:Int,k:Int):Long=F[n]*I[k]%mod*I[n-k]%mod\n var ans=0L\n for(i in 1..n){\n var mx=n/i\n if(mx>=k){\n ans=(ans+binom(mx-1,k-1))%mod\n }\n }\n printLine(\"$ans\")\n output()\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics", "number theory"], "code_uid": "78534644a63fccb0db8fc5adb3af56a5", "src_uid": "8e8eb64a047cb970a549ee870c3d280d", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "const val MOD = 998244353L\n\nfun main() {\n val line = readLine()!!.split(\" \").map { it.toInt() }\n val n = line[0]\n val k = line[1]\n val factorial = LongArray(n + 1)\n factorial[0] = 1L\n for (j in 1..n) {\n factorial[j] = (j.toLong() * factorial[j - 1]) % MOD\n }\n fun choose(a: Int, b: Int) = if (b > a) 0L else (factorial[a] * ((factorial[b] * factorial[a - b]) pow -1))\n var answer = 0L\n for (j in 1..n) {\n answer += choose((n / j) - 1, k - 1)\n answer %= MOD\n }\n println(answer)\n}\n\nval MOD_TOTIENT = (MOD - 1).toInt()\n\ninfix fun Long.pow(power: Int): Long {\n var e = power\n e %= MOD_TOTIENT\n if (e < 0) {\n e += MOD_TOTIENT\n }\n if (e == 0 && this == 0L) {\n return this\n }\n var b = this % MOD\n var res = 1L\n while (e > 0) {\n if (e and 1 != 0) {\n res *= b\n res %= MOD\n }\n b *= b\n b %= MOD\n e = e shr 1\n }\n return res\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics", "number theory"], "code_uid": "dff869dbb4cd5595a758c41602b37509", "src_uid": "8e8eb64a047cb970a549ee870c3d280d", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\n// region\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\nval fac = mutableListOf()\n\nfun fact(n: Long): ModInt {\n if (fac.count() == 0) fac.add(ModInt(1))\n while (fac.count() <= n) {\n fac.add(fac.last() * ModInt(fac.count().toLong()))\n }\n return fac[n.toInt()]\n}\n\nfun comb(n: Long, k: Long): ModInt {\n return fact(n) / fact(k) / fact(n - k)\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.nextInt()\n val _k = sc.nextLong()\n if (_k >= n) {\n println(0)\n return\n }\n val k = _k.toInt()\n val c = (n - k).toLong()\n var ans = ModInt(c).pow(n.toLong())\n for (i in 0 until n - k - 1) {\n val v = comb(c, c - i - 1) * ModInt(c - i - 1).pow(n.toLong())\n if (i % 2 == 0) {\n ans -= v\n } else {\n ans += v\n }\n }\n ans *= comb(n.toLong(), c)\n if (k > 0) {\n ans *= ModInt(2)\n }\n println(ans)\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}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics", "fft"], "code_uid": "dba747ff643c8641e5caa88860d7da64", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.*\nimport kotlin.math.*\n\nval maxn = 200005\nval inf0 = 2e9\nval inf = inf0.toInt()\nval INF0 = 4e18\nval INF = INF0.toLong()\nval eps = 1e-6\n\nval MOD = 998244353L\n\nfun main() {\n val n = nextLong()\n val k = nextLong()\n if (k >= n) {\n println(0)\n end()\n }\n if (k == 0L) {\n var ans = 1L\n for (i in 1..n) ans = (ans * i) % MOD\n println(ans)\n end()\n }\n var ans = 0L\n fact[0] = 1\n for (i in 1..maxn - 1) fact[i] = (fact[i - 1] * i.toLong()) % MOD\n for (i in 0..maxn - 1) invfact[i] = powmod(fact[i], MOD - 2, MOD)\n var p = 1L\n for (i in 0..n - k) {\n var add = powmod(n - k - i, n, MOD) * cnk((n - k).toInt(), i.toInt(), MOD) % MOD\n add *= p\n if (add < 0) add += MOD\n ans = (ans + add) % MOD\n p *= -1\n }\n ans = (ans * cnk(n.toInt(), k.toInt(), MOD)) % MOD\n println((2 * ans) % MOD)\n end()\n}\n\nval fact = LongArray(maxn)\nval invfact = LongArray(maxn)\n\nfun cnk(n: Int, k: Int, m: Long): Long {\n return ((fact[n] * invfact[k]) % m) * invfact[n - k] % m\n}\n\nfun powmod(x: Long, d: Long, m: Long): Long {\n if (d == 0L) return 1\n if (d % 2 == 0L) {\n val y = powmod(x, d / 2, m)\n return (y * y) % m\n }\n return x * powmod(x, d - 1, m) % m\n}\n\nfun divup(x: Int, y: Int): Int {\n return (x + y - 1) / y\n}\n\nfun divup(x: Long, y: Long): Long {\n return (x + y - 1) / y\n}\n\nfun gcd(x: Long, y: Long): Long {\n if (x == 0L || y == 0L) return x + y\n if (x > y) return gcd(x % y, y)\n return gcd(y % x, x)\n}\n\nfun end() {\n out.flush()\n System.exit(0)\n}\n\nfun printIntArray(a: IntArray) {\n for (x in a) print(\"$x \")\n println(\"\\n\")\n}\n\nfun printArrayList(a: ArrayList) {\n for (x in a) print(\"$x \")\n println(\"\\n\")\n}\n\nfun nextInt() = next().toInt()\nfun nextLong() = next().toLong()\nfun nextDouble() = next().toDouble()\n\nval reader = BufferedReader(InputStreamReader(System.`in`))\nval out = PrintWriter(System.out, false)\nvar tokenizer = StringTokenizer(\"\")\n\nfun println(o: Any) = out.println(o)\nfun print(o: Any) = out.print(o)\n\nfun next(): String {\n while (!tokenizer.hasMoreTokens())\n tokenizer = StringTokenizer(reader.readLine())\n return tokenizer.nextToken()\n}\n\nfun increase(map: HashMap, k: Int) {\n map[k] = 1 + if (map.containsKey(k)) map[k]!! else 0\n}\n\nfun decrease(map: HashMap, k: Int) {\n map[k] = -1 + if (map.containsKey(k)) map[k]!! else 0\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics", "fft"], "code_uid": "0c9c2ae9a222643cc5f9ffa534cca3a1", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.ArrayDeque\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 numCases = 1//readInt()\n case@ for(case in 1..numCases) {\n //print(\"Case #$case: \")\n\n val n = readInt()\n val k = readLong()\n\n var ans = ModInt(0)\n\n if(k < n) {\n val c = n - k.toInt()\n val mc = ArrayModCombinatorics(n)\n ans = mc.C(n, c) * (0 until c).sumByModInt { i ->\n negOnePow(i) * mc.C(c, i) * ModInt(c-i).pow(n)\n }\n if(k != 0L) ans += ans\n }\n\n println(ans)\n }\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\nfun negOnePow(n: Int) = if(n and 1 == 0) 1 else -1\n\nconst val BILLION7 = 1e9.toInt() + 7\nconst val MOD = 998244353\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: Int, 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 == 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 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 {\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\n\ninfix fun Int.divCeil(other: Int) =\n (this / other).let { if(xor(other) >= 0 && it * other != this) it+1 else it }\n\ninline infix fun Int.divFloor(other: Int) = Math.floorDiv(this, other)\n\ninfix fun Long.divCeil(other: Long) =\n (this / other).let { if(xor(other) >= 0 && it * other != this) it+1 else it }\n\ninline infix fun Long.divFloor(other: Long) = Math.floorDiv(this, other)\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\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`() { 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)", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics", "fft"], "code_uid": "6b23c05cd7df4ae6c60750d1e067bb0e", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"EXPERIMENTAL_FEATURE_WARNING\")\n\nimport ModInt.Companion.ONE\nimport ModInt.Companion.TWO\nimport ModInt.Companion.ZERO\nimport ModInt.Companion.sumOf\nimport ModInt.Companion.toModInt\nimport Utils.ArrayUtils.Companion.makeDistinct\nimport Utils.ArrayUtils.Prints.Companion.println\nimport Utils.ArrayUtils.Sorts.Companion.shuffleSort\nimport Utils.ArrayUtils.Swaps.Companion.swap\nimport Utils.BinarySearchUtils.Companion.binarySearch\nimport Utils.BinarySearchUtils.Companion.binarySearchDouble\nimport Utils.BinarySearchUtils.Companion.binarySearchLong\nimport Utils.FastReader\nimport Utils.GeneralUtils.Companion.gcd\nimport Utils.GeneralUtils.Companion.length\nimport Utils.GeneralUtils.Companion.rnd\nimport java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayDeque\nimport kotlin.random.Random\nimport kotlin.random.Random.Default.nextInt\nimport kotlin.time.ExperimentalTime\n\n@ExperimentalStdlibApi\n@ExperimentalTime\n@ExperimentalUnsignedTypes\nfun main() {\n Locale.setDefault(Locale.US)\n if (System.getProperty(\"ONLINE_JUDGE\") != null) {\n System.setOut(PrintStream(BufferedOutputStream(System.out)))\n }\n Task().solve()\n System.out.flush()\n}\n\n@ExperimentalStdlibApi\n@ExperimentalTime\n@ExperimentalUnsignedTypes\nclass Task(private val fin: FastReader = FastReader()) {\n fun solve() {\n val n = fin.readInt()\n val k = fin.readLong().let {\n if (it >= n) {\n println(0)\n return\n }\n it.toInt()\n }\n val fact = (1..n).scan(ONE) { acc, i -> acc * i.toModInt() }\n\n if (k == 0) {\n println(fact[n])\n return\n }\n\n fun c(n: Int, k: Int) = if (n < 0 || k > n) ZERO else fact[n] / (fact[k] * fact[n - k])\n val rows = n - k\n val p = (1..rows).sumOf { i -> i.toModInt().pow(n) * (-ONE).pow((rows - i) % 2) * c(rows, i) }\n val res = c(n, rows) * p * TWO\n println(res)\n }\n}\n\n/*\nn-rows=k\nrows-n=-k\nrows=n-k\n\nif k != 0:\n s = 0\n for rows in 1..(n-1):\n\n if (n - rows) == k:\n s += rows^n - (rows-1)^n\n s += cnt01 * c(n, rows) * c(n - rows, k) * n!\n s *= 2\nelse ...\n */\n\n@Suppress(\"MemberVisibilityCanBePrivate\", \"unused\")\n@ExperimentalStdlibApi\n@ExperimentalTime\n@ExperimentalUnsignedTypes\nclass Utils {\n class GeneralUtils {\n companion object {\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 fun gcd(a: Int, b: Int, c: Int): Int = gcd(gcd(a, b), c)\n fun gcd(a: Long, b: Long, c: Long): Long = gcd(gcd(a, b), c)\n val rnd = Random(239)\n val IntRange.length get() = last - first + 1\n }\n }\n\n class ArrayUtils {\n companion object {\n fun > MutableList.makeDistinct() {\n if (size <= 1) return\n sort()\n var sz = 1\n for (i in 1 until size) {\n if (this[i] != this[i - 1]) {\n this[sz++] = this[i]\n }\n }\n while (size > sz) removeAt(lastIndex)\n }\n }\n\n class Swaps {\n companion object {\n fun Array.swap(i: Int, j: Int) {\n val x = this[i]\n this[i] = this[j]\n this[j] = x\n }\n\n fun MutableList.swap(i: Int, j: Int) {\n val x = this[i]\n this[i] = this[j]\n this[j] = x\n }\n\n fun IntArray.swap(i: Int, j: Int) {\n val x = this[i]\n this[i] = this[j]\n this[j] = x\n }\n\n fun LongArray.swap(i: Int, j: Int) {\n val x = this[i]\n this[i] = this[j]\n this[j] = x\n }\n\n fun DoubleArray.swap(i: Int, j: Int) {\n val x = this[i]\n this[i] = this[j]\n this[j] = x\n sort()\n }\n\n fun CharArray.swap(i: Int, j: Int) {\n val x = this[i]\n this[i] = this[j]\n this[j] = x\n sort()\n }\n }\n }\n\n class Sorts {\n companion object {\n fun IntArray.shuffleSort() {\n for (i in 1 until size) swap(i, nextInt(i + 1))\n sort()\n }\n\n fun LongArray.shuffleSort() {\n for (i in 1 until size) swap(i, nextInt(i + 1))\n sort()\n }\n\n fun DoubleArray.shuffleSort() {\n for (i in 1 until size) swap(i, nextInt(i + 1))\n sort()\n }\n\n fun CharArray.shuffleSort() {\n for (i in 1 until size) swap(i, nextInt(i + 1))\n sort()\n }\n }\n }\n\n class Prints {\n companion object {\n fun println(a: IntArray) {\n if (a.isNotEmpty()) {\n print(a[0])\n for (i in 1 until a.size) {\n print(' ')\n print(a[i])\n }\n }\n println()\n }\n\n fun println(a: LongArray) {\n if (a.isNotEmpty()) {\n print(a[0])\n for (i in 1 until a.size) {\n print(' ')\n print(a[i])\n }\n }\n println()\n }\n\n fun println(a: CharArray, printSpace: Boolean = false) {\n if (a.isNotEmpty()) {\n print(a[0])\n for (i in 1 until a.size) {\n if (printSpace) print(' ')\n print(a[i])\n }\n }\n println()\n }\n\n fun println(a: Array<*>) {\n if (a.isNotEmpty()) {\n print(a[0])\n for (i in 1 until a.size) {\n print(' ')\n print(a[i])\n }\n }\n println()\n }\n\n fun println(a: List<*>) {\n if (a.isNotEmpty()) {\n print(a[0])\n for (i in 1 until a.size) {\n print(' ')\n print(a[i])\n }\n }\n println()\n }\n\n fun println(a: Iterable<*>) {\n val it = a.iterator()\n if (it.hasNext()) {\n print(it.next())\n while (it.hasNext()) {\n print(' ')\n print(it.next())\n }\n }\n println()\n }\n }\n }\n }\n\n class BinarySearchUtils {\n companion object {\n @Suppress(\"DuplicatedCode\")\n inline fun binarySearch(from: Int, to: Int, f: (Int) -> Boolean): Int {\n var l = from\n var r = to + 1\n while (r - l > 1) {\n val m = (l + r) / 2\n if (f(m)) l = m\n else r = m\n }\n return l\n }\n\n inline fun binarySearch(from: Int = 0, f: (Int) -> Boolean): Int {\n var len = 1\n while (f(from + len)) len *= 2\n return binarySearch(from + len / 2, from + len - 1, f)\n }\n\n @Suppress(\"DuplicatedCode\")\n inline fun binarySearchLong(from: Long, to: Long, f: (Long) -> Boolean): Long {\n var l = from\n var r = to + 1\n while (r - l > 1) {\n val m = (l + r) / 2\n if (f(m)) l = m\n else r = m\n }\n return l\n }\n\n inline fun binarySearchLong(from: Long = 0, f: (Long) -> Boolean): Long {\n var len = 1L\n while (f(from + len)) len *= 2\n return binarySearchLong(from + len / 2, from + len - 1, f)\n }\n\n inline fun binarySearchDouble(from: Double, to: Double, times: Int = 200, f: (Double) -> Boolean): Double {\n var l = from\n var r = to\n repeat(times) {\n val m = (l + r) / 2\n if (f(m)) l = m\n else r = m\n }\n return l\n }\n\n inline fun binarySearchDouble(from: Double = 0.0, times: Int = 200, f: (Double) -> Boolean): Double {\n var len = 1.0\n while (f(from + len)) len *= 2\n return binarySearchDouble(from, from + len, times, f)\n }\n }\n }\n\n class UtilsImports {\n fun importDependencies() {\n check(gcd(4, 6) == 2)\n check(rnd.nextInt(10) in 0 until 10)\n check(mutableListOf(1, 3, 2, 2, 1).apply { makeDistinct() } == listOf(1, 2, 3))\n check((5..10).length == 6)\n check(intArrayOf(3, 4).apply { swap(0, 1) }.contentEquals(intArrayOf(4, 3)))\n check(intArrayOf(5, 6, 2, 1, 5).apply { shuffleSort() }.contentEquals(intArrayOf(1, 2, 5, 5, 6)))\n check(binarySearch { it < 10 } == 9)\n check(binarySearchLong { it < 1e13.toLong() } == 1e13.toLong() - 1)\n binarySearchDouble { true }\n println(intArrayOf())\n ArrayDeque()\n// listOf().sum()\n// (0..1).sumOf { it.toModInt() }\n }\n }\n\n class FastReader(fileName: String? = null) {\n @JvmField\n val br = BufferedReader(if (fileName != null) FileReader(fileName) else InputStreamReader(System.`in`))\n\n @JvmField\n var st = StringTokenizer(\"\")\n\n fun readString(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n return st.nextToken()\n }\n\n fun readInt() = readString().toInt()\n fun readLong() = readString().toLong()\n fun readDouble() = readString().toDouble()\n\n fun readIntArray(n: Int) = IntArray(n) { readInt() }\n fun readLongArray(n: Int) = LongArray(n) { readLong() }\n fun readStringArray(n: Int) = Array(n) { readString() }\n fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() }\n\n fun readInts(n: Int) = MutableList(n) { readInt() }\n fun readLongs(n: Int) = MutableList(n) { readLong() }\n fun readStrings(n: Int) = MutableList(n) { readString() }\n fun readDoubles(n: Int) = MutableList(n) { readDouble() }\n }\n}\n\n@Suppress(\"MemberVisibilityCanBePrivate\", \"unused\")\n@ExperimentalStdlibApi\n@ExperimentalTime\n@ExperimentalUnsignedTypes\ninline class ModInt(private val x: Int) {\n companion object {\n private const val mod = 998_244_353\n\n // const val mod = 1e9.toInt() + 7\n fun Int.toModInt() = ModInt(this)\n fun Int.toModIntSafe() = ModInt((this % mod + mod) % mod)\n fun Long.toModIntSafe() = ModInt(((this % mod + mod) % mod).toInt())\n val ZERO = ModInt(0)\n val ONE = ModInt(1)\n val TWO = ModInt(2)\n val TEN = ModInt(10)\n\n fun Iterable.sum() = fold(ZERO, ModInt::plus)\n fun Array.sum() = fold(ZERO, ModInt::plus)\n\n inline fun Iterable.sumOf(f: (T) -> ModInt) = fold(ZERO) { acc, i -> acc + f(i) }\n inline fun Array.sumOf(f: (T) -> ModInt) = fold(ZERO) { acc, i -> acc + f(i) }\n inline fun IntRange.sumOf(f: (Int) -> ModInt) = fold(ZERO) { acc, i -> acc + f(i) }\n }\n\n operator fun plus(k: ModInt) = ModInt((x + k.x).let { if (it >= mod) it - mod else it })\n operator fun minus(k: ModInt) = ModInt((x - k.x).let { if (it < 0) it + mod else it })\n operator fun times(k: ModInt) = ModInt((x * k.x.toLong() % mod).toInt())\n operator fun div(k: ModInt) = this * k.inv()\n operator fun unaryMinus() = if (x == 0) this else ModInt(mod - x)\n fun inv() = pow(mod - 2)\n fun pow(p: Int): ModInt = if (p == 0) ONE else pow(p / 2).let { if (p % 2 == 1) it * it * this else it * it }\n fun toInt() = x\n override fun toString() = x.toString()\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics", "fft"], "code_uid": "1aa80ede0aebd849c9e8162d4edd6e33", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n val m = sc.nextInt()\n\n val l = mutableMapOf()\n val set = LinkedList()\n set.add(n)\n l.put(n, 0)\n while (set.isNotEmpty()) {\n val p = set.pop()\n if (p > 1000000) {\n continue\n }\n if (p < 0) {\n continue\n }\n val newCount = l[p]!! + 1\n run {\n val next = l[p * 2]\n if (next == null || next > newCount) {\n l[p * 2] = newCount\n set.add(p * 2)\n }\n }\n run {\n val next = l[p - 1]\n if (next == null || next > newCount) {\n l[p - 1] = newCount\n set.add(p - 1)\n }\n }\n\n }\n println(l[m])\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "shortest paths", "math", "graphs", "greedy", "implementation"], "code_uid": "d41ca484f0233f152fe20a3626f6251b", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\n\nprivate fun nextLine() = readLine()!!\nprivate fun nextInt() = nextLine().toInt()\nprivate fun nextToks() = nextLine().split(\" \")\nprivate fun nextInts() = nextToks().map{it.toInt()}\n\nfun h(x: Int, m: Int): Int {\n if (x >= m) return x - m\n if (m % 2 != 0) return 1 + h(x, m+1)\n return 1 + h(x, m / 2)\n}\n\nfun main() {\n val (n, m) = nextInts()\n println(h(n,m))\n}\n", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "shortest paths", "math", "graphs", "greedy", "implementation"], "code_uid": "d9c8fa49c076bbd329c0a2ad2f0e994f", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\n fun main(args:Array) = with(Scanner(System.`in`)) {\n var n = nextInt()\n var m = nextInt()\n var result = 0\n while (m > n)\n {\n if (m % 2 == 0)\n {\n m = m / 2\n result++\n }\n else\n {\n m++\n result++\n }\n }\n if (n > m)\n {\n result += Math.abs(n - m)\n }\n println(result)\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "shortest paths", "math", "graphs", "greedy", "implementation"], "code_uid": "d40e2faa35c1dc1e396d453ddbaddc23", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main()\n{\n var (has, need) = readLine()!!.split(\" \").map{ it.toInt() }\n var ops = 0\n while (has != need)\n {\n ops ++\n if (need < has || need % 2 == 1) need ++ else need /= 2\n }\n print(ops)\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "shortest paths", "math", "graphs", "greedy", "implementation"], "code_uid": "d028878cbb324102f783be8623403d61", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(vararg args: String) {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n var k = 0\n var r = \"\"\n s.replace(\"W*(B+)\".toRegex()) { ++k; r += \"${it.groupValues[1].length} \"; \"\" }\n println(k)\n println(r)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "e792e597699aaf06bc2343978c26dda2", "src_uid": "e4b3a2707ba080b93a152f4e6e983973", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/* https://codeforces.com/problemset/problem/721/A */\n\nfun main() {\n readLine() // skip the first line\n val sequence = readLine()!!\n var consecutiveBlackCount = 0\n val groups = ArrayList()\n sequence.forEach {\n if (it == 'B') {\n consecutiveBlackCount++\n } else {\n if (consecutiveBlackCount > 0) {\n groups.add(consecutiveBlackCount)\n }\n consecutiveBlackCount = 0\n }\n }\n if (consecutiveBlackCount > 0) {\n groups.add(consecutiveBlackCount)\n }\n println(groups.size)\n println(groups.joinToString(separator = \" \"))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8fd0abf69fcd64fb761bf860425beffe", "src_uid": "e4b3a2707ba080b93a152f4e6e983973", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n\n br.readLine() //skip count\n val p = br.readLine() + \"W\"\n\n val output = ArrayList()\n\n var current = 0\n\n p.forEach {\n when (it) {\n 'W' -> {\n if (current > 0) output.add(current); current = 0\n }\n 'B' -> {\n current++\n }\n }\n }\n\n\n println(output.size)\n if (output.size > 0) {\n println(output.joinToString(separator = \" \") { \"$it\" })\n }\n\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "52d88b2e03647e3432eae2029e77672a", "src_uid": "e4b3a2707ba080b93a152f4e6e983973", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(vararg args: String) {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n val r = s.split(\"W+\".toRegex()).map { it.length }.filter { it > 0 }\n println(r.size)\n println(r.joinToString(\" \"))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "3defba2e1ed3c6b429b2bf845af5cc2d", "src_uid": "e4b3a2707ba080b93a152f4e6e983973", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(vararg args: String) {\n val n = readLine()!!.toInt()\n val crush = readLine()!!.split(' ').map { it.toInt() }\n val visited = Array(n) { false }\n val circles = mutableListOf()\n for (i in 0 until n) {\n var count = 0\n var p = i\n while (!visited[p]) {\n visited[p] = true\n p = crush[p] - 1\n ++count\n }\n if (p == i) {\n if (count > 1) circles += count\n } else {\n println(-1)\n return\n }\n }\n\n fun nod(a: Int, b: Int): Int = if (b == 0) a else nod(b, a % b)\n fun nok(a: Int, b: Int) = a / nod(a, b) * b\n\n var r = when (circles.size) {\n 0 -> 1\n 1 -> circles[0]\n else -> circles.reduce(::nok)\n }\n if (r % 2 == 0) r /= 2\n println(r)\n}\n", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "math"], "code_uid": "b72a0132d48cf7c3f7b117f4b9b843b3", "src_uid": "149221131a978298ac56b58438df46c9", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\ntailrec fun gcd(a: Int, b: Int): Int {\n if (a == 0) return b\n else return gcd(b % a, a)\n}\n\nfun lcm(a: Int, b: Int): Int {\n return (a / gcd(a, b)) * b\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 n = st.nextToken().toInt()\n val arr = IntArray(n + 1)\n st = StringTokenizer(br.readLine())\n for (i in 1..n) {\n arr[i] = st.nextToken().toInt()\n }\n var answer = 1\n for (i in 1..n) {\n var loop = false\n val a = i\n var b = a\n for (j in 1..n) {\n b = arr[b]\n if (b == a) {\n loop = true\n if (j.isEven()) answer = lcm(answer, j/2)\n else answer = lcm(answer, j)\n break\n }\n }\n if (!loop) {\n answer = -1\n break\n }\n }\n bw.write(\"$answer\")\n bw.newLine()\n bw.flush()\n}\n", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "math"], "code_uid": "0a9dbb2741093f7f3656639b4e7d4409", "src_uid": "149221131a978298ac56b58438df46c9", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main()\n{\n val(cost, extra) = readLine()!!.split(\" \").map{ it.toInt() }\n var canBuy = 1\n while(true)\n {\n var curr = (canBuy * cost) % 10\n if (curr == 0 || curr == extra)\n {\n println(canBuy)\n break\n }\n canBuy++\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "dfb8172b23bcfe44c16e3fd96acd6806", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 (k, r) = readInts()\n var x = k\n var ans = 0\n var i = 1\n if ((x - r) % 10 == 0) {\n println(1)\n } else {\n while ((x - r) % 10 != 0) {\n x = k * i\n ans++;\n if ((x * i) % 10 == 0) {\n break\n }\n i++\n// println(\"x = ${x}\")\n }\n println(ans)\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "12e40f1635bc2d39644be64d7d90b409", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 (n, k) = readInts()\n\n for (i in 1..9) {\n val c = (n * i) % 10\n if (c == k || c == 0) {\n println(i)\n return\n }\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "6405d0c58abd25c26bf781b402bee6fe", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n var sc= Scanner(System.`in`)\n var k = sc.nextInt()\n var r = sc.nextInt()\n var con = 1\n while (!(k*con %10 == 0 ||( k*con-r) %10 ==0)){\n con++\n }\n println(con)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "4a9a6f5e799b9eafdec67a15f4036d74", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val line = readLine()!!\n val six = line.indexOf(' ')\n val r = line.substring(0, six).toInt()\n val b = line.substring(six + 1).toInt()\n println(if (r == b) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "geometry", "brute force"], "code_uid": "044af4abb5bec3ca5c049cf1674c3393", "src_uid": "65f81f621c228c09915adcb05256c634", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, m) = readLine()!!.split(' ').map { it.toInt() }\n\n if (minOf(n, m) % 2 == 0) {\n println(\"Malvika\")\n }\n else {\n println(\"Akshat\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "6149bce05f6b78da16560b3fc0742c7e", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 var n = input.nextInt()\n var m = input.nextInt()\n\n var step = 1\n\n while (true) {\n if (n == 1 || m == 1) break\n n--\n m--\n\n step++\n }\n\n output.println(if (step % 2 != 0) \"Akshat\" else \"Malvika\")\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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "fa1eadeb139f0bbd6d108e575b7a4d30", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\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 println(\n if (min(n, m) % 2 == 0) \"Malvika\"\n else \"Akshat\"\n )\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "1763c335303fa81014eb60dd9758b470", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main(){\n val(n, m) = readLine()!!.split(' ').map(String::toInt)\n if(min(n, m) % 2 == 0){\n print(\"Malvika\")\n }else{\n print(\"Akshat\")\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d8dd5da3c3f99d077f408d14eb00b208", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n var (a, b, c) = r.readLine()!!.split(\" \").map { it.toInt() }.sorted()\n var ans = 0\n while (a+b<=c){\n a++\n ans++\n }\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "geometry"], "code_uid": "346ccba287645a5dda5a080e560d174a", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var sides = readLine()!!.split(' ').take(3).map { it.toInt() }.toIntArray()\n sides.sort()\n var sum = sides[0] + sides[1]\n var count = 0\n if (sum <= sides[2]){\n count = sides[2] - sum + 1\n }\n println(count)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "geometry"], "code_uid": "2549f1b7670efa37395f2244f071ead2", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val (a, b, max) = Scanner(System.`in`).use {\n listOf(it.nextInt(), it.nextInt(), it.nextInt()).sorted()\n }\n\n println(if (max >= a + b) max - a - b + 1 else 0)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "geometry"], "code_uid": "f44d0af244cb64b750ee7cec37415d06", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.collections.ArrayList\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 list = ArrayList()\n list.add(a)\n list.add(b)\n list.add(c)\n\n Collections.sort(list)\n\n var sum = list[0]+list[1]\n if (sum>list[2]){\n println(0)\n }else{\n println(list[2]-sum+1)\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "geometry"], "code_uid": "8b778fda26e62ad5c4947e1265ac957d", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * Created by quangio.\n */\n\nfun Int.primeFactors(): List {\n val L = mutableListOf()\n var v: Int = 2\n var nn = this\n while (nn > 1 && L.size < 21) {\n if (nn % v == 0) {\n L.add(v)\n nn /= v\n } else {\n v++\n }\n }\n return L\n}\n\nfun main(vararg args: String) {\n val (n, k) = readLine()!!.split(' ').map(String::toInt)\n val L = n.primeFactors()\n var nn = n\n if (L.size < k) {\n println(-1)\n } else {\n for (i in 1..k-1) {\n print(\"${L[i]} \")\n nn /= L[i]\n }\n print(nn)\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "5cb3d2d7265a8208ffde68f9e38a94dd", "src_uid": "bd0bc809d52e0a17da07ccfd450a4d79", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val (n, k) = readLine()!!.split(\" \").map(String::toInt)\n var tmp = n\n var d = 2\n val dividers = ArrayList()\n while (tmp >= d) {\n while (tmp % d == 0) {\n tmp /= d\n dividers.add(d)\n }\n d++\n }\n if (dividers.size >= k) {\n print(\"${dividers.subList(0, dividers.size - k + 1).fold(1) { a, b -> a * b }} \")\n dividers.subList(dividers.size - k + 1, dividers.size).forEach { print(\"$it \") }\n } else {\n println(-1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "31ccdc5715d10d8af0b103a9706f49d0", "src_uid": "bd0bc809d52e0a17da07ccfd450a4d79", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n var (n, k) = readInts()\n val sol = mutableListOf()\n loop@ while (sol.size < k - 1) {\n for (i in 2..n)\n if (n % i == 0) {\n sol.add(i)\n n /= i\n continue@loop\n }\n return print(-1)\n }\n if (n == 1) return print(-1)\n sol.add(n)\n print(sol.joinToString(\" \"))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "4f24c2b218b0066bf6b7c4a12e6b61a2", "src_uid": "bd0bc809d52e0a17da07ccfd450a4d79", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * @author Daniyar Itegulov\n */\nfun main(arg: Array) {\n val sc = java.util.Scanner(System.`in`)\n val n = sc.nextInt()\n val k = sc.nextInt()\n val s = sc.next().map { c -> if (c == 'N') 0 else if (c == 'Y') 1 else 2 }\n for (i in 0..(n - k)) {\n val newS = mutableListOf()\n newS.addAll(s)\n var good = true\n for (j in i..(i + k - 1)) {\n if (newS[j] == 1) {\n good = false\n break\n } else if (newS[j] == 2) {\n newS[j] = 0\n }\n }\n if (good) {\n for (j in 0..(n - 1)) {\n if (newS[j] == 2) {\n newS[j] = 1\n }\n }\n for (j in 0..(n - 1 - k)) {\n var kek = true\n for (l in j..(j + k)) {\n if (newS[l] != 0) {\n kek = false\n }\n }\n if (kek) {\n good = false\n }\n }\n if (good) {\n println(\"YES\")\n System.exit(0)\n }\n }\n }\n println(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["dp"], "code_uid": "46871b3e3f5390547d3147b3be8e5098", "src_uid": "5bd578d3da5837c259b222336a194d12", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\nimport java.util.Arrays\nfun main(){\n val reader=Scanner(System.`in`)\n var(a,b,c)=readLine()!!.split(\" \").map(String::toLong)\n print(a*b+b*c+c*a-a-b-c+1)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "96f4234cd989b9a92148575ff095a528", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\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, h, m) = readInts()\n var a = Array(n) { h }\n for (i in 1..m) {\n var (l, r, x) = readInts()\n for (i in l-1 until r) a[i] = min(a[i], x)\n }\n var s = 0\n for (i in a) s += i * i\n print(s)\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "3b8023cab2dd6573c1b9b086eb952599", "src_uid": "f22b6dab443f63fb8d2d288b702f20ad", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(){\n val (n, h, m) = readLine()!!.split(' ').map { it.toInt() }\n val arr = IntArray(n)\n for (i in 0 until n){\n arr[i]=h\n }\n\n for (i in 0 until m){\n val (l, r, x) = readLine()!!.split(' ').map { it.toInt() }\n for (j in l-1 until r){\n if (x) {\n var (a, b) = readLine()!!.split(\" \").map{ it.toLong() }\n\n proc@while(true) {\n if( a == 0L || b == 0L ) break@proc\n \n if( a - 2*b >= 0L ) {\n val n = a/(2*b)\n a = a - 2*n*b\n continue@proc // step1\n }else{\n // step3\n if( b - 2*a >= 0L) {\n val n = b/(2*a)\n b = b - 2*n*a\n continue@proc\n } else {\n break@proc\n }\n }\n }\n println(\"${a} ${b}\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "57a83418115954d23e25139ce54302eb", "src_uid": "1f505e430eb930ea2b495ab531274114", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\n\nfun main(args: Array)\n{\n val inp = readLine()!!.split(' ').map(String::toLong)\n var a = inp[0]\n var b = inp[1]\n while (max(a, b) >= 2 * min(a, b) && a > 0 && b > 0)\n {\n if (a > b)\n {\n a %= 2 * b\n continue\n }\n if (b > a)\n {\n b %= 2 * a\n }\n }\n println(\"$a $b\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "12b9e6f84c2d58fe1316da4ee22fed44", "src_uid": "1f505e430eb930ea2b495ab531274114", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args: Array) {\n System.`in`.bufferedReader().use {\n val parts = it.readLine().split(' ')\n var a = parts[0].toLong()\n var b = parts[1].toLong()\n\n while (true) {\n if (a == 0L || b == 0L)\n break\n else if (a >= 2 * b)\n a %= 2 * b\n else if (b >= 2 * a)\n b %= 2 * a\n else\n break\n }\n\n println(a.toString() + \" \" + b.toString())\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "68efd441c9b7691f66df6b7772df6cb8", "src_uid": "1f505e430eb930ea2b495ab531274114", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 var a = reader.nextLong()\n var b = reader.nextLong()\n while (a != 0.toLong() && b != 0.toLong()) {\n if (a >= 2 * b) {\n a %= 2 *b\n } else if (b >= 2*a) {\n b %= 2*a\n } else {\n break\n }\n }\n writer.println(\"$a $b\")\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", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "646cf90322107a1a31a614c330ecc4c3", "src_uid": "1f505e430eb930ea2b495ab531274114", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["sortings", "greedy"], "code_uid": "e6f07fef663d9fc5aadbc378c9a1528f", "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["sortings", "greedy"], "code_uid": "91b30ca5e64a912ef905bdb279f33f9e", "src_uid": "3c4b2d1c9440515bc3002eddd2b89f6f", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private fun readInt() = readLine()!!.toInt()\n\nvar FF = MutableList>(21) { _ -> MutableList(1_000_001) { _->-1L}}\nvar FF3 = MutableList>(21) {_-> MutableList(1_000_001) {_->-1L}}\nvar n = 0\nvar k = 0\n\nfun F3(q:Int, w:Int) : Long {\n if (FF3[q][w] == -1L) {\n if (q >= k - 1 || w > n / (3 shl q) || w == 0) {\n FF3[q][w] = 0\n return 0\n }\n FF3[q][w] = F3(q+1, w-1)*(n / (3 shl q) - n / (3 shl (q+1))) + F3(q, w-1)*(n / (3 shl q) - w + 1)\n FF3[q][w] = FF3[q][w]%1_000_000_007\n }\n return FF3[q][w]\n}\n\nfun F(q:Int, w:Int) : Long {\n if (FF[q][w] == -1L) {\n if (q >= k || w > n / (1 shl q) || w == 0) {\n FF[q][w] = 0\n return 0\n }\n FF[q][w] = F3(q, w-1)*(n / (1 shl q) - n / (3 shl q)) + F(q+1, w-1)*(n / (1 shl q) - n / (1 shl (q+1))) + F(q, w-1)*(n / (1 shl q) - w + 1)\n FF[q][w] = FF[q][w] % 1_000_000_007\n }\n return FF[q][w]\n}\n\nfun main() {\n n = readInt()\n k = 1\n while (n >= (1 shl k)) k++\n k--\n if (k > 0 && n >= (1 shl (k-1))*3) FF3[k-1][1] = 1\n FF[k][1] = 1\n for(i in k downTo 0) for(j in 0 .. (n / (3 shl i))) F3(i, j)\n for(i in k downTo 0) for(j in 0 .. (n / (1 shl i))) F(i, j)\n println(F(0, n))\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "08ad9c8265a8b7a0fdc42cf6a4e91c65", "src_uid": "b2d59b1279d891dba9372a52364bced2", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "const val MOD = 1000000007L\n\nfun main() {\n val n = readLine()!!.toInt()\n val inv = LongArray(n + 1) { it.toLong() pow -1 }\n val factorial = LongArray(n + 1)\n val factInv = LongArray(n + 1)\n factorial[0] = 1L\n factInv[0] = 1L\n for (j in 1..n) {\n factorial[j] = (j.toLong() * factorial[j - 1]) % MOD\n factInv[j] = (inv[j] * factInv[j - 1]) % MOD\n }\n fun permute(a: Int, b: Int) = (factorial[a] * factInv[b]) % MOD\n fun arrange(a: Int, b: Int): Long {\n val here = n / a\n val above = here / b\n return ((here - above).toLong() * permute(n - above - 1, n - here)) % MOD\n }\n fun arrangeInv(a: Int, b: Int): Long {\n val here = n / a\n val above = here / b\n return (inv[here - above] * permute(n - here, n - above - 1)) % MOD\n }\n var lg = 0\n while (1 shl lg <= n) {\n lg++\n }\n lg--\n var curr = 1L\n for (e in 0..lg) {\n curr *= arrange(1 shl e, 2)\n curr %= MOD\n }\n var answer = curr\n if (n >= 3 * (1 shl (lg - 1))) {\n for (e in lg downTo 1) {\n curr *= arrangeInv(1 shl e, 3)\n curr %= MOD\n curr *= arrange(3 * (1 shl (e - 1)), 2)\n curr %= MOD\n curr *= arrangeInv(1 shl (e - 1), 2)\n curr %= MOD\n curr *= arrange(1 shl (e - 1), 3)\n curr %= MOD\n answer += curr\n }\n answer %= MOD\n }\n println(answer)\n}\n\nval MOD_TOTIENT = (MOD - 1).toInt()\n\ninfix fun Long.pow(power: Int): Long {\n var e = power\n e %= MOD_TOTIENT\n if (e < 0) {\n e += MOD_TOTIENT\n }\n if (e == 0 && this == 0L) {\n return this\n }\n var b = this % MOD\n var res = 1L\n while (e > 0) {\n if (e and 1 != 0) {\n res *= b\n res %= MOD\n }\n b *= b\n b %= MOD\n e = e shr 1\n }\n return res\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "0adcbe8d05017f2a8063020c6156d41c", "src_uid": "b2d59b1279d891dba9372a52364bced2", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\", \"DEPRECATION\")\r\n@file:OptIn(ExperimentalStdlibApi::class)\r\n\r\nimport java.io.PrintWriter\r\nimport java.util.StringTokenizer\r\nimport kotlin.collections.ArrayDeque\r\nimport kotlin.math.*\r\nimport kotlin.random.*\r\nimport java.util.TreeMap\r\nimport java.util.TreeSet\r\nimport java.util.PriorityQueue\r\n// import java.util.*\r\n\r\n@JvmField val INPUT = System.`in`\r\n@JvmField val OUTPUT = System.out\r\n\r\n@JvmField val reader = INPUT.bufferedReader()\r\nfun readLine(): String? = reader.readLine()\r\nfun readLn() = reader.readLine()!!\r\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\r\nfun read(): String {\r\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(reader.readLine() ?: return \"\", \" \")\r\n return _tokenizer.nextToken()\r\n}\r\nfun readInt() = read().toInt()\r\nfun readDouble() = read().toDouble()\r\nfun readLong() = read().toLong()\r\nfun readStrings(n: Int) = List(n) { read() }\r\nfun readString() = readStrings(1)[0]\r\nfun readLines(n: Int) = List(n) { readLn() }\r\nfun readInts(n: Int = 2) = List(n) { read().toInt() }\r\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\r\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\r\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\r\nfun readLongs(n: Int = 2) = List(n) { read().toLong() }\r\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\r\n\r\n// val isLocal = System.getenv(\"IS_LOCAL_CP\") == \"true\"\r\n\r\n@JvmField\r\nval writer = PrintWriter(OUTPUT)\r\n\r\n// ----------------------------------------------------------------------------\r\n\r\nclass UnionFind {\r\n\r\n private val parents = mutableMapOf()\r\n private val sizes = mutableMapOf()\r\n\r\n fun union(a: Int, b: Int) {\r\n val fa = find(a)\r\n val fb = find(b)\r\n if (fa != fb) {\r\n parents[fa] = fb\r\n sizes[fb] = (sizes[fb] ?: 1) + (sizes[fa] ?: 1)\r\n }\r\n }\r\n\r\n fun find(a: Int): Int {\r\n fun getOrDefault(value: Int) = parents.getOrDefault(value, value)\r\n\r\n var parent = getOrDefault(a)\r\n while (parent != getOrDefault(parent)) {\r\n parents[parent] = getOrDefault(getOrDefault(parent))\r\n parent = parents[parent]!!\r\n }\r\n return parent\r\n }\r\n\r\n fun connected(a: Int, b: Int): Boolean {\r\n return find(a) == find(b)\r\n }\r\n\r\n fun getSize(a: Int): Int {\r\n return sizes[find(a)] ?: 1\r\n }\r\n}\r\n\r\nclass UnionFindArray(private val n: Int) {\r\n\r\n private val parents = IntArray(n + 1) { it }\r\n\r\n fun union(a: Int, b: Int) {\r\n val fa = find(a)\r\n val fb = find(b)\r\n if (fa != fb) {\r\n parents[fa] = fb\r\n }\r\n }\r\n\r\n fun find(a: Int): Int {\r\n var parent = parents[a]\r\n while (parent != parents[parent]) {\r\n parents[parent] = parents[parents[parent]]\r\n parent = parents[parent]\r\n }\r\n return parent\r\n }\r\n\r\n fun connected(a: Int, b: Int): Boolean {\r\n return find(a) == find(b)\r\n }\r\n}\r\n\r\nclass Trie() {\r\n\r\n /** Initialize your data structure here. */\r\n private val root = Node()\r\n\r\n /** Inserts a word into the trie. */\r\n fun insert(word: String) {\r\n var node = root\r\n for (char in word) {\r\n if (!node.children.contains(char)) {\r\n node.children[char] = Node()\r\n }\r\n node = node.children[char]!!\r\n }\r\n node.hasWord = true\r\n }\r\n\r\n /** Returns if the word is in the trie. */\r\n fun search(word: String): Boolean {\r\n return findNode(word)?.hasWord ?: false\r\n }\r\n\r\n /** Returns if there is any word in the trie that starts with the given prefix. */\r\n fun startsWith(prefix: String): Boolean {\r\n return findNode(prefix) != null\r\n }\r\n\r\n private fun findNode(prefix: String): Node? {\r\n var node = root\r\n for (char in prefix) {\r\n node = node.children[char] ?: return null\r\n }\r\n return node\r\n }\r\n\r\n private class Node(\r\n var hasWord: Boolean = false,\r\n val children: MutableMap = mutableMapOf()\r\n )\r\n}\r\n\r\n// \u6240\u6709\u51fd\u6570\u7684\u4e0b\u6807\u4ece 0 \u5f00\u59cb\r\n// query(index): sum[0, index]\r\nclass BinaryIndexedTree {\r\n\r\n private val bit: IntArray\r\n\r\n constructor(n: Int) {\r\n this.bit = IntArray(n + 1)\r\n }\r\n\r\n constructor(nums: IntArray) {\r\n this.bit = IntArray(nums.size + 1)\r\n val prefix = IntArray(bit.size)\r\n for (i in 1 until nums.size + 1) {\r\n prefix[i] = prefix[i - 1] + nums[i - 1]\r\n bit[i] = prefix[i] - prefix[i - lowbit(i)]\r\n }\r\n }\r\n\r\n fun query(index: Int): Int {\r\n var result = 0\r\n var i = index + 1\r\n while (i > 0) {\r\n result += bit[i]\r\n i -= lowbit(i)\r\n }\r\n return result\r\n }\r\n\r\n fun update(index: Int, x: Int) {\r\n val value = query(index) - query(index - 1)\r\n add(index, x - value)\r\n }\r\n\r\n fun add(index: Int, x: Int) {\r\n var i = index + 1\r\n while (i < bit.size) {\r\n bit[i] += x\r\n i += lowbit(i)\r\n }\r\n }\r\n\r\n override fun toString(): String {\r\n return IntArray(bit.size - 1) { query(it) - query(it - 1) }.toList().toString()\r\n }\r\n\r\n private fun lowbit(x: Int): Int {\r\n return x.and(-x)\r\n }\r\n}\r\n\r\n// \u6240\u6709\u51fd\u6570\u7684\u4e0b\u6807\u4ece 0 \u5f00\u59cb\r\n// query(index): max[0, index]\r\n// udpate(index, x): \u66f4\u65b0 [0, index] \u4e4b\u95f4\u7684\u6700\u5927\u503c\uff0c\u53ea\u80fd\u8d8a\u6765\u8d8a\u5927\r\nclass BinaryIndexedTreeMax {\r\n\r\n private val bit: IntArray\r\n\r\n constructor(n: Int) {\r\n this.bit = IntArray(n + 1)\r\n }\r\n\r\n fun query(index: Int): Int {\r\n var result = 0\r\n var i = index + 1\r\n while (i > 0) {\r\n result = Math.max(result, bit[i])\r\n i -= lowbit(i)\r\n }\r\n return result\r\n }\r\n\r\n fun update(index: Int, x: Int) {\r\n var i = index + 1\r\n while (i < bit.size) {\r\n bit[i] = Math.max(bit[i], x)\r\n i += lowbit(i)\r\n }\r\n }\r\n\r\n private fun lowbit(x: Int): Int {\r\n return x.and(-x)\r\n }\r\n}\r\n\r\nclass SparseTableMax(private val nums: IntArray) {\r\n\r\n private val st: Array\r\n\r\n init {\r\n val n = nums.size\r\n val logN = Integer.numberOfTrailingZeros(Integer.highestOneBit(n))\r\n this.st = Array(n * 2) { IntArray(logN + 1) }\r\n for (i in 0 until n) {\r\n st[i][0] = nums[i]\r\n }\r\n for (j in 1 until logN + 1) {\r\n for (i in 0 until n) {\r\n st[i][j] = st[i][j - 1]\r\n if (i + 1.shl(j - 1) < n) {\r\n st[i][j] = Math.max(st[i][j], st[i + 1.shl(j - 1)][j - 1])\r\n }\r\n }\r\n }\r\n }\r\n\r\n fun query(left: Int, right: Int): Int {\r\n if (left > right) {\r\n return -1\r\n }\r\n val len = right - left + 1\r\n val k = Integer.numberOfTrailingZeros(Integer.highestOneBit(len))\r\n return Math.max(st[left][k], st[right - 1.shl(k) + 1][k])\r\n }\r\n}\r\n\r\nclass SparseTableMin(private val nums: IntArray) {\r\n\r\n private val st: Array\r\n\r\n init {\r\n val n = nums.size\r\n val logN = Integer.numberOfTrailingZeros(Integer.highestOneBit(n))\r\n this.st = Array(n * 2) { IntArray(logN + 1) { Int.MAX_VALUE / 2 } }\r\n for (i in 0 until n) {\r\n st[i][0] = nums[i]\r\n }\r\n for (j in 1 until logN + 1) {\r\n for (i in 0 until n) {\r\n st[i][j] = st[i][j - 1]\r\n if (i + 1.shl(j - 1) < n) {\r\n st[i][j] = Math.min(st[i][j], st[i + 1.shl(j - 1)][j - 1])\r\n }\r\n }\r\n }\r\n }\r\n\r\n fun query(left: Int, right: Int): Int {\r\n if (left > right) {\r\n return -1\r\n }\r\n val len = right - left + 1\r\n val k = Integer.numberOfTrailingZeros(Integer.highestOneBit(len))\r\n return Math.min(st[left][k], st[right - 1.shl(k) + 1][k])\r\n }\r\n}\r\n\r\nclass PrefixSum2D(private val grid: Array) {\r\n\r\n private val prefix: Array\r\n\r\n init {\r\n val (m, n) = Pair(grid.size, grid[0].size)\r\n prefix = Array(m + 1) { IntArray(n + 1) }\r\n for (i in 0 until m) {\r\n var row = 0\r\n for (j in 0 until n) {\r\n row += grid[i][j]\r\n prefix[i + 1][j + 1] = prefix[i][j + 1] + row\r\n }\r\n }\r\n }\r\n\r\n fun query(up: Int, left: Int, bottom: Int, right: Int): Int {\r\n return prefix[up][left] + prefix[bottom + 1][right + 1] -\r\n prefix[bottom + 1][left] - prefix[up][right + 1]\r\n }\r\n}\r\n\r\n// ----------------------------------------------------------------------------\r\n\r\ntypealias Graph = Array>\r\n\r\nprivate fun edgesToGraph(n: Int, edges: Array>, directed: Boolean = false): Graph {\r\n val graph = Array(n) { mutableListOf() }\r\n for ((a, b) in edges) {\r\n graph[a].add(b)\r\n if (!directed) {\r\n graph[b].add(a)\r\n }\r\n }\r\n return graph\r\n}\r\n\r\nprivate fun PrintWriter.printNums(nums: List) {\r\n if (nums.isEmpty()) {\r\n println()\r\n return\r\n }\r\n for (i in 0 until nums.size - 1) {\r\n print(nums[i])\r\n print(' ')\r\n }\r\n println(nums.last())\r\n}\r\n\r\nprivate fun lengthOfLIS(numsInput: List): Int {\r\n val nums = unify(numsInput)\r\n val bit = BinaryIndexedTreeMax(nums.size + 1)\r\n var result = 0\r\n for (num in nums) {\r\n val len = bit.query(num - 1) + 1\r\n bit.update(num, len)\r\n result = Math.max(result, len)\r\n }\r\n return result\r\n}\r\n\r\nprivate fun unify(nums: List): List {\r\n val numToIndex = nums.sorted().mapIndexed { index, num -> num to index }.toMap()\r\n return nums.map { numToIndex[it]!! }\r\n}\r\n\r\nprivate fun fastPow(a: Long, exp: Long, mod: Long): Long {\r\n var result = 1L % mod\r\n var base = a % mod\r\n var remain = exp\r\n while (remain != 0L) {\r\n if (remain % 2L == 1L) {\r\n result = (result * base) % mod\r\n }\r\n base = (base * base) % mod\r\n remain /= 2L\r\n }\r\n return result\r\n}\r\n\r\nprivate fun gcd(a: Int, b: Int): Int {\r\n return if (b == 0) a else gcd(b, a % b)\r\n}\r\n\r\nprivate fun gcdL(a: Long, b: Long): Long {\r\n return if (b == 0L) a else gcdL(b, a % b)\r\n}\r\n\r\nprivate fun lcm(a: Int, b: Int): Int {\r\n return ((a.toLong() * b.toLong()) / gcd(a, b)).toInt()\r\n}\r\n\r\nprivate fun lcmL(a: Long, b: Long): Long {\r\n return (a * b) / gcdL(a, b)\r\n}\r\n\r\nprivate fun wordToCharCount(word: String): IntArray {\r\n val charCount = IntArray(26)\r\n for (char in word) {\r\n charCount[char.toIndex()]++\r\n }\r\n return charCount\r\n}\r\n\r\nprivate fun Char.toIndex(): Int {\r\n return this.toInt() - 'a'.toInt()\r\n}\r\n\r\nprivate fun Char.toDigit(): Int {\r\n return this.toInt() - '0'.toInt()\r\n}\r\n\r\nprivate fun Boolean.toYesNo(upper: Boolean = false): String {\r\n val yesNo = if (this) \"Yes\" else \"No\"\r\n return if (upper) yesNo.toUpperCase() else yesNo\r\n}\r\n\r\nprivate fun LongArray.modSum(mod: Long = MODL): Long {\r\n var sum = 0L\r\n for (num in this) {\r\n sum = (sum + num) % mod\r\n }\r\n return sum\r\n}\r\n\r\nprivate fun IntArray.swap(i: Int, j: Int) {\r\n val temp = this[i]\r\n this[i] = this[j]\r\n this[j] = temp\r\n}\r\n\r\nprivate fun LongArray.swap(i: Int, j: Int) {\r\n val temp = this[i]\r\n this[i] = this[j]\r\n this[j] = temp\r\n}\r\n\r\nprivate fun CharArray.swap(i: Int, j: Int) {\r\n val temp = this[i]\r\n this[i] = this[j]\r\n this[j] = temp\r\n}\r\n\r\nprivate fun List.toArrayDeque(): ArrayDeque {\r\n return ArrayDeque(this)\r\n}\r\n\r\nprivate fun List.toPair(): Pair {\r\n return Pair(this[0], this[1])\r\n}\r\n\r\nprivate fun List.listEquals(other: List): Boolean {\r\n return (0 until this.size).all { this[it] == other[it] }\r\n}\r\n\r\nprivate fun > List.isSorted(): Boolean {\r\n return this.listEquals(this.sorted())\r\n}\r\n\r\nprivate val DIR = listOf(\r\n listOf(1, 0), listOf(0, -1), listOf(-1, 0), listOf(0, 1)\r\n)\r\n\r\nprivate const val MOD = 998244353\r\nprivate const val MODL = 998244353L\r\n// private const val MOD = 1000000007\r\n// private const val MODL = 1000000007L\r\nprivate const val EPS = 0.000001\r\n\r\n// ----------------------------------------------------------------------------\r\n\r\nfun main() {\r\n val go: Runnable = Runnable {\r\n writer.solve()\r\n writer.flush()\r\n }\r\n Thread(null, go, \"thread\", 1L.shl(28)).start()\r\n // writer.solve()\r\n // writer.flush()\r\n}\r\n\r\nprivate fun PrintWriter.solve() {\r\n val n = readInt()\r\n val x = readLong()\r\n println(requiredLen(n, x))\r\n\r\n // test()\r\n}\r\n\r\nprivate fun test() {\r\n // println(ULong.MAX_VALUE)\r\n // println(ULong.MAX_VALUE.toString().length)\r\n\r\n // var num: ULong = 26u\r\n // while (true) {\r\n // val str = num.toString()\r\n // val len = str.length\r\n // println(\"$len, $str\")\r\n // num *= 6u\r\n // if (len >= 19) {\r\n // break\r\n // }\r\n // }\r\n\r\n val random = Random(12345L)\r\n repeat(100) {\r\n // val n = random.nextInt(18) + 2\r\n // var max = 1L\r\n // repeat(n - 1) {\r\n // max *= 10L\r\n // }\r\n // val x = random.nextLong(max - 2L) + 1L\r\n val n = 10\r\n val x = random.nextLong(1000L) + 1L\r\n\r\n val r1 = requiredLen(n, x)\r\n val r2 = requiredLen1(n, x)\r\n if (r1 != r2) {\r\n println(\"$n, $x. $r1, $r2\")\r\n }\r\n }\r\n}\r\n\r\nprivate fun requiredLen(n: Int, x: Long): Int {\r\n val queue = listOf(x).toArrayDeque()\r\n val visited = mutableSetOf()\r\n var step = 0\r\n while (queue.isNotEmpty()) {\r\n repeat(queue.size) {\r\n val num = queue.removeFirst()\r\n if (num < 0L) {\r\n return step\r\n }\r\n if (visited.contains(num)) {\r\n return@repeat\r\n }\r\n visited.add(num)\r\n val str = num.toString()\r\n if (str.length == n) {\r\n return step\r\n }\r\n if (str.length > n) {\r\n return@repeat\r\n }\r\n val digits = BooleanArray(10)\r\n for (char in str) {\r\n digits[char.toDigit()] = true\r\n }\r\n for (d in 2 until 10) {\r\n if (!digits[d]) {\r\n continue\r\n }\r\n queue.addLast(num * d)\r\n }\r\n }\r\n step++\r\n // println(queue)\r\n }\r\n return -1\r\n}\r\n\r\n// private fun requiredLen(n: Int, x: Long): Int {\r\n// val MAX = 10000\r\n// val queue = listOf(x).toArrayDeque()\r\n// var step = 0\r\n// while (queue.isNotEmpty()) {\r\n// val next = mutableListOf()\r\n// while (queue.isNotEmpty()) {\r\n// val num = queue.removeFirst()\r\n// if (num < 0L) {\r\n// return step\r\n// }\r\n// val str = num.toString()\r\n// if (str.length == n) {\r\n// return step\r\n// }\r\n// if (str.length > n) {\r\n// continue\r\n// }\r\n// val digits = BooleanArray(10)\r\n// for (char in str) {\r\n// val d = char.toDigit()\r\n// if (d <= 1 || digits[d]) {\r\n// continue\r\n// }\r\n// digits[d] = true\r\n// next.add(num * d)\r\n// }\r\n// }\r\n// next.sortBy { -it }\r\n// queue.addAll(next.subList(0, Math.min(MAX, next.size)))\r\n// step++\r\n// }\r\n// return -1\r\n// }\r\n\r\nprivate fun requiredLen1(n: Int, x: Long): Int {\r\n val queue = listOf(x).toArrayDeque()\r\n var step = 0\r\n while (queue.isNotEmpty()) {\r\n val nextQueue = ArrayDeque>()\r\n var maxLen = 0\r\n while (queue.isNotEmpty()) {\r\n val num = queue.removeFirst()\r\n if (num < 0L) {\r\n return step\r\n }\r\n val str = num.toString()\r\n if (str.length == n) {\r\n return step\r\n }\r\n if (str.length > n) {\r\n continue\r\n }\r\n val digits = BooleanArray(10)\r\n for (char in str) {\r\n digits[char.toDigit()] = true\r\n }\r\n for (d in 2 until 10) {\r\n if (!digits[d]) {\r\n continue\r\n }\r\n val nextNum = num * d\r\n val nextStr = nextNum.toString()\r\n nextQueue.addLast(Pair(nextNum, nextStr))\r\n maxLen = Math.max(maxLen, nextStr.length)\r\n }\r\n }\r\n for ((num, str) in nextQueue) {\r\n // if (str.length >= maxLen - 3) {\r\n queue.addLast(num)\r\n // }\r\n }\r\n step++\r\n // println(queue)\r\n }\r\n return -1\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["brute force", "dfs and similar", "shortest paths", "dp", "data structures"], "code_uid": "b280014a1b0eda3a492d23f2cc01817d", "src_uid": "cedcc3cee864bf8684148df93804d029", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "import java.math.BigInteger\r\nimport java.util.*\r\n\r\nfun main() {\r\n val sp = readLine()!!.split(\" \")\r\n val n = sp[0].toInt()\r\n val x = sp[1].toBigInteger()\r\n val bfs = LinkedList().apply { add(State(0, x)) }\r\n\r\n val visited = mutableSetOf()\r\n while (bfs.isNotEmpty()) {\r\n val state = bfs.pollFirst()\r\n val s = state.x.toString().toSet()\r\n if (state.x.toString().length >= n) {\r\n println(state.moves)\r\n return\r\n }\r\n\r\n for (digit in s) {\r\n val d = BigInteger((digit - '0').toString())\r\n val next = state.x.multiply(d)\r\n if (visited.contains(next)) continue\r\n\r\n bfs.addLast(State(state.moves + 1, next))\r\n visited.add(next)\r\n }\r\n }\r\n\r\n println(-1)\r\n}\r\n\r\ndata class State(val moves: Int, val x: BigInteger)\r\n", "lang_cluster": "Kotlin", "tags": ["brute force", "dfs and similar", "shortest paths", "dp", "data structures"], "code_uid": "66ef0dc25648c04578b5aad72f931a75", "src_uid": "cedcc3cee864bf8684148df93804d029", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "fun pow(a: Long, b: Int): Long = if (b == 0) 1 else a * pow(a, b - 1)\r\n\r\nfun solve() {\r\n val line = readLine()!!.split(\" \")\r\n val n = line[0].toInt()\r\n val x = line[1].toLong()\r\n val cache = mutableMapOf()\r\n fun f(x: Long): Int {\r\n if (cache.containsKey(x)) {\r\n return cache[x]!!\r\n }\r\n val s = x.toString()\r\n if (s.length == n) {\r\n return 0\r\n }\r\n var res = -1\r\n val cands = s.toSet().toList().map { it - '0' }.sorted().reversed()\r\n for (c in cands) {\r\n if (c <= 1) {\r\n continue\r\n }\r\n val r = f(x * c) + 1\r\n if (r > 0 && (res > r || res == -1)) {\r\n res = r\r\n }\r\n }\r\n cache[x] = res\r\n return res\r\n }\r\n println(f(x))\r\n}\r\n\r\nfun main() {\r\n val t = 1 // readLine()!!.toInt()\r\n repeat (t) {\r\n solve()\r\n }\r\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "dfs and similar", "shortest paths", "dp", "data structures"], "code_uid": "ee108d5980aa11918613ff66fa606f52", "src_uid": "cedcc3cee864bf8684148df93804d029", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "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 = 1000000007L\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\n val n = getint\n val x = getlong\n val Q = ArrayDeque> ()\n val tried = mutableSetOf()\n var target = 1L\n repeat(n-1){\n target *= 10\n }\n\n Q.add(Pair(x,0))\n while(Q.isNotEmpty()){\n val (v,e) = Q.removeFirst()\n// just dei v\n if(v >= target) {\n put(e)\n return@cases\n }\n\n for(c in v.toString()){\n val d = c.toInt() - '0'.toInt()\n if(d == 0 || d == 1) continue\n val new = v * d\n if(new in tried) continue\n tried.add(new)\n Q.addLast(Pair(new,e+1))\n }\n\n\n }\n put(-1)\n return@cases\n\n\n }\n done()\n}\n\n\n\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "dfs and similar", "shortest paths", "dp", "data structures"], "code_uid": "d2310194401203f317d5a563775523e7", "src_uid": "cedcc3cee864bf8684148df93804d029", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 m = sc.nextInt()\n\n val z = (n + 1) / 2\n var count = 0\n val a = Array(z) {\n count += 1\n sc.nextInt()\n }\n val b = Array(z) {\n count += 1\n if (count <= n) sc.nextInt()\n else 0\n }\n\n val A = listFrom(a, m)\n val B = listFrom(b, m)\n\n var best = Math.max(A.max() ?: 0, B.max() ?: 0)\n A.sortBy { it }\n B.sortBy { -it }\n\n var cur = 0\n for (i in 0 until A.size) {\n val x = A[i]\n while (cur < B.size && x + B[cur] >= m) {\n cur += 1\n }\n if (cur < B.size) best = Math.max(x + B[cur], best)\n }\n\n println(best)\n\n}\n\nfun listFrom(a: Array, m: Int): MutableList {\n val n = a.size\n var res = mutableListOf()\n for (s in 0 until (1 shl (n))) {\n var sum = 0\n for(k in 0 until n){\n if ((s shr k) and 1 == 1) sum = (sum + a[k]) % m\n }\n res.add(sum)\n }\n return res\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", "lang_cluster": "Kotlin", "tags": ["meet-in-the-middle", "divide and conquer", "bitmasks"], "code_uid": "d1931e9cad818d3c57e2eee3285b175e", "src_uid": "d3a8a3e69a55936ee33aedd66e5b7f4a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.lang.Math.max\nimport java.util.*\n\n\nfun main() {\n Solver()\n}\n\nclass Solver {\n private val io = KotlinIo(System.`in`, System.`out`)\n\n init {\n val n = io.getLong()\n val m = io.getLong()\n val modNumbers = mutableListOf()\n for (i in 0 until n) {\n modNumbers.add(io.getLong())\n }\n val meetInTheMiddle = MeetInTheMiddle(modNumbers, m)\n io.println(meetInTheMiddle.getLargestModuloSum())\n io.close()\n }\n}\n\nclass MeetInTheMiddle(private val numbers: List, private val moduloValue: Long) {\n\n private val firstModuloSumList = mutableListOf()\n private val secondModuloSumList = mutableListOf()\n\n fun getLargestModuloSum(): Long {\n val modNumbers = numbers.map { it.rem(moduloValue) }\n if (modNumbers.size == 1) {\n return modNumbers.first()\n }\n val firstList = modNumbers.subList(0, modNumbers.size / 2)\n val secondList = modNumbers.subList(modNumbers.size / 2, modNumbers.size)\n\n bruteForceModuloSums(0, firstList, firstModuloSumList, firstList.first())\n bruteForceModuloSums(0, firstList, firstModuloSumList, 0L)\n bruteForceModuloSums(0, secondList, secondModuloSumList, secondList.first())\n bruteForceModuloSums(0, secondList, secondModuloSumList, 0L)\n\n return maxModuloSumBetweenList()\n }\n\n private fun maxModuloSumBetweenList(): Long {\n val firstModuloSumSet = TreeSet(firstModuloSumList)\n val secondModuloSumSet = TreeSet(secondModuloSumList)\n var maxSum = (firstModuloSumSet.last()).coerceAtLeast(secondModuloSumSet.last())\n\n firstModuloSumSet.forEach {\n val gap: Long = moduloValue.minus(it+1)\n val floorValue = secondModuloSumSet.floor(gap)\n if (floorValue != null) {\n maxSum = maxSum.coerceAtLeast((it + floorValue).rem(moduloValue))\n }\n }\n return maxSum\n }\n\n private fun bruteForceModuloSums(index: Int, modNumbers: List, moduloSumList: MutableList, sum: Long) {\n if (index == modNumbers.size - 1) {\n moduloSumList.add(sum.rem(moduloValue))\n return\n }\n bruteForceModuloSums(index + 1, modNumbers, moduloSumList, sum + modNumbers[index + 1])\n bruteForceModuloSums(index + 1, modNumbers, moduloSumList, sum)\n }\n}\n\n\n/**\n * IO class with exposing various input operations. Kotlin Translation of\n * [Kattio.java](https://github.com/Kattis/kattio/blob/master/Kattio.java)\n */\nclass KotlinIo(private val input: InputStream, private val outPut: OutputStream) :\n PrintWriter(BufferedOutputStream(outPut)) {\n\n private var reader: BufferedReader = BufferedReader(InputStreamReader(input))\n private var line: String? = null\n private var tokenizer: StringTokenizer? = null\n private var token: String? = null\n\n fun hasMoreTokens() = peekToken() != null\n\n fun getInt() = nextToken()!!.toInt()\n\n fun getDouble() = nextToken()!!.toDouble()\n\n fun getLong() = nextToken()!!.toLong()\n\n fun getWord() = nextToken()\n\n fun getLine(): String? {\n try {\n return reader.readLine()\n } catch (e: IOException) {\n e.printStackTrace()\n }\n return null\n }\n\n private fun peekToken(): String? {\n if (token == null) {\n try {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n line = reader.readLine()\n if (line == null) {\n return null\n }\n tokenizer = StringTokenizer(line)\n }\n token = tokenizer!!.nextToken()\n } catch (e: IOException) {\n e.printStackTrace()\n }\n }\n return token\n }\n\n private fun nextToken(): String? {\n val ans = peekToken()\n token = null\n return ans\n }\n}", "lang_cluster": "Kotlin", "tags": ["meet-in-the-middle", "divide and conquer", "bitmasks"], "code_uid": "206f20363ec98ef5cbeb967e6b64ef9f", "src_uid": "d3a8a3e69a55936ee33aedd66e5b7f4a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.util.*\n\nclass Solver {\n\n fun input(inp: FastInputReader) {\n val (n, m, k) = inp.readIntArray(3)\n val a = inp.readIntArray(n)\n for (delta in 1..n) {\n for (mult in -1..1 step 2) {\n val nxt = m - 1 + delta * mult\n if (nxt in 0..n - 1 && a[nxt] in 1..k) {\n println(delta * 10)\n return\n }\n }\n }\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", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "49eb5d67b646c29bb9372232c914ac00", "src_uid": "57860e9a5342a29257ce506063d37624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, m, k) = readLine()!!.split(' ').map(String::toInt)\n val arr = readLine()!!.split(' ').map(String::toInt)\n\n var ans = (n - 1) * 10\n for (i in arr.indices) {\n if (arr[i] > 0 && arr[i] <= k) {\n val d = if (i >= m -1) i - m + 1 else m - 1 - i\n val t = d * 10\n if (t < ans)\n ans = t\n }\n }\n print(\"$ans\\n\")\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "07781f0679fa44c5c82003f5039c97b0", "src_uid": "57860e9a5342a29257ce506063d37624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n import kotlin.math.*\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n var arr=readLine()!!.split(\" \").map{it.toInt()}\n var a=readLine()!!.split(\" \").map{it.toInt()}\n\t\tvar mn=100000\n\t\tfor(i in a.indices)\n\t\t{\n\t\t if(a[i]!=0 && a[i]<=arr[2])\n\t\t\t\t\tmn=min(mn,abs(i+1-arr[1])*10)\n\t\t}\n\t\tprint(mn)\n\t\t\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "ec6958be052c9a49c46997c16e89f0fb", "src_uid": "57860e9a5342a29257ce506063d37624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numHouses, girlHouse, money) = readInts()\n val prices = readInts()\n var minDistance = Int.MAX_VALUE\n for (position in girlHouse until numHouses)\n if (prices[position] in 1..money) {\n minDistance = (position - girlHouse + 1) * 10\n break\n }\n for (position in girlHouse - 2 downTo 0)\n if (prices[position] in 1..money) {\n minDistance = min(minDistance, (girlHouse - 1 - position) * 10)\n break\n }\n print(minDistance)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "f2475035f24eb7ef53184bd69e0f642e", "src_uid": "57860e9a5342a29257ce506063d37624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nfun main(args: Array) {\n var sc = Scanner(System.`in`)\n var n = sc.nextInt()\n var a = sc.nextInt()\n val b= IntArray(n+1)\n for (i in 1 ..n )b[i]=sc.nextInt()\n\n var c =0\n for ( i in 1 ..n){\n if(b[i] == 1 ){\n if (!(2*a-i >= 1 && 2*a-i <= n && b[2*a-i] == 0)) {\n c++\n }\n }\n }\n\n println(c)\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation"], "code_uid": "04cce2dca5de6f6ba7a870b257554056", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n var (n, a) = r.readLine()!!.split(\" \").map { it.toInt() }\n val v = r.readLine()!!.split(\" \").map { it.toInt() }\n val usetime = minOf(a - 1, n - a)\n var ans = 0\n a -= 1\n if (v[a] == 1) ans++\n for (dis in 1..usetime) {\n if (v[a - dis] == 1 && v[a + dis] == 1) ans += 2\n }\n (0..a - usetime - 1).forEach {\n if (v[it] == 1) ans++\n }\n (a + usetime + 1..n - 1).forEach {\n if (v[it] == 1) ans++\n }\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation"], "code_uid": "a28841b04f40afdbd7815e0e0b2fdb09", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n var (numCities, policeCity) = readInts()\n policeCity--\n val criminalsPerCity = readInts()\n var sol = criminalsPerCity[policeCity]\n val delta = min(policeCity, numCities - policeCity - 1)\n for (pos in 1 .. delta)\n if (criminalsPerCity[policeCity - pos] + criminalsPerCity[policeCity + pos] == 2) sol += 2\n for (city in 0 until policeCity - delta)\n sol += criminalsPerCity[city]\n for (city in policeCity + 1 + delta until numCities)\n sol += criminalsPerCity[city]\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation"], "code_uid": "431fe0a4bdebf406d05e65e3a955b5d0", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var (n, a) = readLine()!!.split(\" \").map(String::toInt)\n val cities : List = readLine()!!.split(\" \").map(String::toInt)\n val ekvidistantniGradovi : MutableList> = MutableList(0) {Pair(0,0)}\n\n a--\n //parova ima min({0..a-1},{a+1..n}) i toliko ih spojim\n val parova = minOf((0 until a).count(),(a + 1 until n).count())\n (1..parova).mapTo(ekvidistantniGradovi) { Pair(cities[a - it], cities[a + it]) } //dodao sam parove\n\n //preostali \"visak\" sa lijeve ili desne strane dodam u paru sa -1\n //sto mi oznacava one sto su sigurni, ali nisu upareni\n if((0 until a).count() > (a + 1 until n).count())\n (0 until a-parova).mapTo(ekvidistantniGradovi) { Pair(cities[it], -1)}\n else\n (a+parova+1 until n).mapTo(ekvidistantniGradovi) { Pair(cities[it], -1)}\n\n var caught = 0\n //na kraju sabiram ako ima oba ili ako ima jedan, a drugi je -1\n ekvidistantniGradovi.forEach {\n if(it.first > 0 && it.second > 0) caught += it.first + it.second\n else if(it.first > 0 && it.second == -1) caught += it.first\n }\n println(caught + cities[a])\n}\n\n", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation"], "code_uid": "81484cd5d68a03c018bf95250a9f9d09", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val input = Scanner(System.`in`)\n val stringValue : String = input.nextLine()\n\n for (index in stringValue.length-1 downTo 0){\n if (stringValue[index].isLetter()){\n when (stringValue[index].toUpperCase()) {\n 'A' -> println(\"YES\")\n 'E' -> println(\"YES\")\n 'I' -> println(\"YES\")\n 'O' -> println(\"YES\")\n 'U' -> println(\"YES\")\n 'Y' -> println(\"YES\")\n else ->{\n println(\"NO\")\n }\n }\n return\n }\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7aafd14bd6cb39e7899080a037bdcfde", "src_uid": "dea7eb04e086a4c1b3924eff255b9648", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readStrings() = readLn().split(\" \")\nfun readInts() = readStrings().map { it.toInt() }\n\nfun main(args: Array) {\n readLn().apply {\n if (this[indexOfLast { c -> c != '?' && c != ' ' }].toLowerCase() in \"aeiouy\") print(\"YES\") else print(\"NO\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "bc221035b8895c52daf02f10674a010a", "src_uid": "dea7eb04e086a4c1b3924eff255b9648", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args : Array) {\n val link = readLine()!!\n var list: MutableList = mutableListOf()\n val letters = arrayOf('A','E','I','O','U','Y')\n\n for (char in link) {\n list.add(char)\n }\n var a = 0\n for(i in list.size-1 downTo 0){\n if(list[i].isLetter()){\n a=i\n break\n }\n }\n var c = 0\n for(i in 0..letters.size-1){\n if(letters[i]==list[a] || letters[i].toLowerCase()==list[a]){\n c++\n }\n }\n\n if(c!=0){\n println(\"YES\")\n }\n else{\n println(\"NO\")\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8806caf5d0176bd70aa02d598e565a7c", "src_uid": "dea7eb04e086a4c1b3924eff255b9648", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n println(if (readLine()!!.toLowerCase().filter { it in ('a'..'z') }.last() in arrayOf('a', 'e', 'i', 'o', 'u', 'y')) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5d8a40b02a28ef287115f6f1145df4c8", "src_uid": "dea7eb04e086a4c1b3924eff255b9648", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readInt()\n\n val points = List(4*n + 1) { readInts().let { (x, y) -> Point(x, y) } }\n\n val xcnt = points.groupingBy { it.x }.eachCount()\n val ycnt = points.groupingBy { it.y }.eachCount()\n\n fun Map.squareBoundaries() = run {\n val f = keys.filter {\n this[it]!! >= n\n }\n listOf(f.min()!!, f.max()!!)\n }\n\n val xb = xcnt.squareBoundaries()\n val yb = ycnt.squareBoundaries()\n\n val ans = points.first {\n when {\n it.x in xb -> it.y in yb[0]..yb[1]\n it.y in yb -> it.x in xb[0]..xb[1]\n else -> false\n }.not()\n }\n\n println(\"${ans.x} ${ans.y}\")\n}\n\ndata class Point(val x: Int, val y: 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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "48317dfbfbd3264c7a13b3d431721d76", "src_uid": "1f9153088dcba9383b1a2dbe592e4d06", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readInt()\n\n val points = List(4*n + 1) { readInts().let { (x, y) -> Point(x, y) } }\n\n val xcnt = points.groupingBy { it.x }.eachCount()\n val ycnt = points.groupingBy { it.y }.eachCount()\n\n fun Map.squareBoundaries() = run {\n val f = keys.filter {\n this[it]!! >= n\n }\n listOf(f.min()!!, f.max()!!)\n }\n\n val xb = xcnt.squareBoundaries()\n val yb = ycnt.squareBoundaries()\n\n val ans = points.first {\n when {\n it.x in xb -> it.y !in yb[0]..yb[1]\n it.y in yb -> it.x !in xb[0]..xb[1]\n else -> true\n }\n }\n\n println(\"${ans.x} ${ans.y}\")\n}\n\ndata class Point(val x: Int, val y: 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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "0e6da9256ed768a362c0384663e48ec4", "src_uid": "1f9153088dcba9383b1a2dbe592e4d06", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.collections.*\nimport kotlin.math.*\n\nval read = Scanner(System.`in`)\n\nfun gcd(a: Long, b: Long): Long{\n return if (a == 0L) b else gcd(b%a, a)\n}\n\nfun main(){\n var n: Long = read.nextLong()\n var k: Long = read.nextLong()\n k = Math.pow(10.0, k.toDouble()).toLong()\n print(n * k / gcd(n, k))\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "3f6dc01f7a81cca1a7b0f8bd27bab06b", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun pow(a: Int, b: Int) = Math.pow(a.toDouble(), b.toDouble()).toLong()\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n val k = scanner.nextInt()\n var n1 = n\n var count2 = 0\n var count5 = 0\n while (n1 % 2 == 0) {\n n1 /= 2\n count2++\n }\n n1 = n\n while (n1 % 5 == 0) {\n n1 /= 5\n count5++\n }\n print(n*(if(k>count2) pow(2, k-count2) else 1) * (if (k > count5) pow(5, k-count5) else 1))\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "912ff63e25dcf56a115fa3ddc87d7d54", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// star because\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (n, k) = readInts()\n var nn = n\n var twos = 0\n var fives = 0\n while(twos < k && nn % 2 == 0) {\n twos++\n nn /= 2\n }\n while(fives < k && nn % 5 == 0) {\n fives++\n nn /= 5\n }\n var sol = n.toLong()\n while (twos < fives) {\n sol *= 2\n twos++\n }\n while (fives < twos) {\n sol *= 5\n fives++\n }\n val sb = StringBuilder(sol.toString())\n for (i in twos until k) sb.append('0')\n print(sb)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "b3e057a86493c0e2b0717f881b7f172c", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n\n val n = sc.nextLong()\n val k = sc.nextInt()\n\n println(n.round(k))\n}\n\nfun Long.round(k: Int): Long {\n var t = this\n var doub = 0\n while (t % 2 == 0L) {\n doub += 1\n t /= 2\n }\n var five = 0\n while (t % 5 == 0L) {\n five += 1\n t /= 5\n }\n\n var res = this\n while (doub < k) {\n res *= 2\n doub += 1\n }\n while (five < k) {\n res *= 5\n five += 1\n }\n return res\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "1bf8874f1eddbf1f08757536bd561e4c", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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}", "lang_cluster": "Kotlin", "tags": ["probabilities", "bitmasks"], "code_uid": "bd5bfdf98eb07ae9a5ecdb1f21ead327", "src_uid": "5258ce738eb268b9750cfef309d265ef", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n\n// https://codeforces.com/problemset/problem/1061/A\nfun main() {\n val values = readLine()?.split(' ') ?: return\n if (values.size != 2) {\n return\n }\n var coins = values[0].toInt()\n var remain = values[1].toInt()\n var count = 0\n while (true) {\n if (remain >= coins) {\n remain -= coins\n count++\n } else {\n coins = remain\n }\n if (remain == 0) {\n println(count)\n return\n }\n }\n\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "2635c0917b902de7da46d81ab8e9cd3d", "src_uid": "04c067326ec897091c3dbcf4d134df96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (n, s) = readInts()\n print (s / n + if (s % n == 0) 0 else 1)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "0560c31b9395cd15b6a32260cf2e9582", "src_uid": "04c067326ec897091c3dbcf4d134df96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n solve()\n}\n\nprivate fun read(delimit: Char = ' ') = readLine()!!.split(delimit)\n\nprivate fun solve() {\n val (n, s) = read().map(String::toInt)\n\n if(s%n==0){\n println(s/n)\n }else{\n println((s/n)+1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "7e4f5d28723015ce1c44d5ab2f7f9213", "src_uid": "04c067326ec897091c3dbcf4d134df96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n\n// https://codeforces.com/problemset/problem/1061/A\nfun main() {\n val values = readLine()?.split(' ') ?: return\n if (values.size != 2) {\n return\n }\n var coins = values[0].toInt()\n var remain = values[1].toInt()\n var count = 0\n while (true) {\n if (remain >= coins) {\n remain -= coins\n count++\n } else {\n coins-- }\n if (remain == 0) {\n println(count)\n return\n }\n }\n\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "89d3d43e89b436a75d35838b395bef16", "src_uid": "04c067326ec897091c3dbcf4d134df96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.properties.Delegates\nimport kotlin.reflect.KProperty\n\nclass Memorize(val func: (T) -> R) {\n val cache = mutableMapOf()\n\n operator fun getValue(thisRef: Any?, property: KProperty<*>) = { n: T ->\n cache.getOrPut(n) { func(n) }\n }\n}\n\nvar k by Delegates.notNull()\nvar l by Delegates.notNull()\nval f: (Pair) -> Long by Memorize { (weight, hasLeast) ->\n when {\n weight < 0 -> 0\n weight == 0L -> if (hasLeast) 1L else 0L\n hasLeast -> ((1..k).fold(0L) { acc: Long, l: Long -> acc + f(Pair(weight - l, true)) })%1000000007L\n else -> { ((if (k >= l) (l..k).fold(0L) { acc: Long, l: Long ->\n acc + f(Pair(weight - l, true))\n } else 0L) + (1..minOf(k, l - 1)).fold(0L) { acc: Long, l: Long ->\n acc + f(Pair(weight - l, false)) })%1000000007L\n }\n }//.also { println(\"weight: $weight hasleast: $hasLeast res: $it\") }\n}\n\nfun main() {\n val r = System.`in`.bufferedReader()\n //val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n val (weight, kth, least) = r.readLine()!!.split(\" \").map { it.toLong() }\n k = kth\n l = least\n println(f(Pair(weight, false))%1000000007L)\n //val n = r.readLine()!!.toInt()\n}", "lang_cluster": "Kotlin", "tags": ["dp", "implementation", "trees"], "code_uid": "48501b64c26ccd5479df2237d5d6418b", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args: Array) {\n var n=0\n var k=0\n var d=0\n val input= readLine()!!.split(\" \").map{ it.toInt()}\n n=input[0]\n k=input[1]\n d=input[2]\n var solution=Array(2, {LongArray(n+1, {0})})\n for(i in 1..minOf(n, k)){\n solution[0][i]=if (i=d) 1 else 0\n }\n for(i in 2 .. n){\n for(j in 1 .. d-1) {\n if(i-j>=0)\n solution[0][i]=(solution[0][i]+solution[0][i-j])%1000000007\n }\n }\n for(i in 2 .. n){\n for(j in 1 .. d-1) {\n if(i-j>=0)\n solution[1][i]=(solution[1][i]+solution[1][i-j])%1000000007\n }\n for(j in d .. k) {\n if(i-j>=0)\n solution[1][i]=(solution[1][i]+solution[1][i-j]+solution[0][i-j])%1000000007\n }\n }\n println(solution[1][n])\n}", "lang_cluster": "Kotlin", "tags": ["dp", "implementation", "trees"], "code_uid": "b6968509017d5033b6ec47f3776dbf7b", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nconst val MODULO = 1000000007L\n\nfun calc(n: Long, k: Long, d: Long, cache: MutableMap, Long>): Long {\n if (n <= 0L) {\n return if (d == 0L && n == 0L) 1L else 0L\n }\n\n return cache.getOrPut(Triple(n, k, d)) {\n (1..k).map { kIdx -> calc(n-kIdx, k, if (kIdx >= d) 0L else d, cache) }\n .reduce { a, b -> (a + b) % MODULO }\n }\n}\n\nfun main() {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val (n, k, d) = reader.readLine().split(' ').map { it.toLong() }\n\n println(calc(n, k, d, hashMapOf()))\n}", "lang_cluster": "Kotlin", "tags": ["dp", "implementation", "trees"], "code_uid": "2030953ff2372626d2bc7a500812e6c7", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val numHolds = readInt()\n val heights = readInts()\n var sol = Int.MAX_VALUE\n for (pos in 1 until numHolds - 1) sol = min(sol, heights[pos + 1] - heights[pos - 1])\n for (pos in 1 until numHolds) sol = max(sol, heights[pos] - heights[pos - 1])\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "c201a176b12171a227313fab0d12fd1c", "src_uid": "8a8013f960814040ac4bf229a0bd5437", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n\n val n = scanner.nextLine()\n val numbers = scanner.nextLine()\n\n val arr = numbers.split(' ').map { it.toInt() }.toMutableList()\n\n\n var min = Int.MAX_VALUE\n\n for(i in 1 until arr.size-1) {\n val gap = findMaxGap(arr, i)\n if (gap < min) {\n min = gap\n }\n }\n\n System.out.print(min)\n\n}\n\nfun findMaxGap(arr: MutableList, excludePos: Int) : Int {\n val value = arr[excludePos]\n arr.removeAt(excludePos)\n\n// System.out.println(arr)\n\n var max = arr[1] - arr[0]\n for(i in 1 until arr.size) {\n if (arr[i] - arr[i-1] > max) {\n max = arr[i] - arr[i-1]\n }\n }\n\n arr.add(excludePos, value)\n\n return max\n}\n\n\n\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "e0a28ea172686a76a6a9f350f1c3f32b", "src_uid": "8a8013f960814040ac4bf229a0bd5437", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val lengthArray = readLine()!!.split(\" \").asSequence().map { it.toInt() }.toList()\n\n if (n == 3) {\n println(lengthArray[2] - lengthArray[0])\n return\n }\n\n var min = lengthArray[1] - lengthArray[0] + lengthArray[2] - lengthArray[1]\n var max = lengthArray[1] - lengthArray[0]\n\n for (i in 2 until n - 1) {\n val left = lengthArray[i] - lengthArray[i - 1]\n val right = lengthArray[i + 1] - lengthArray[i]\n\n if (left > max) {\n max = left\n }\n \n if (right > max) {\n max = right\n }\n\n if (left + right < min) {\n min = left + right\n }\n }\n\n println(if (min > max) min else max)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "0565f219c211887833cc6b84d2f3d18d", "src_uid": "8a8013f960814040ac4bf229a0bd5437", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.toInt() }\n var m = (0..n-2).fold(0){min, i -> if (v[i+1]-v[i]>min) v[i+1]-v[i] else min}\n var min = Int.MAX_VALUE\n (1..n-2).forEach {\n if (v[it+1]-v[it-1] 1 ||\n lights[(part + 1) % 4][0] == 1 ||\n lights[(part + 2) % 4][1] == 1 ||\n lights[(part + 3) % 4][2] == 1)\n ) {\n print(\"YES\")\n return\n }\n }\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "fc22568764d8e00ac0d26d206c52cc20", "src_uid": "44fdf71d56bef949ec83f00d17c29127", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.util.*\n\nclass Solver {\n private val inp = FastInputReader()\n\n fun solve() {\n a.forEachIndexed { i, row ->\n if (row[3] == 1) {\n if (a[(i + 4 - 1) % 4][2] + a[(i + 1) % 4][0] + a[(i + 2) % 4][1] + row.sum() - 1 > 0) {\n print(\"YES\")\n return\n }\n }\n }\n print(\"NO\")\n }\n\n private lateinit var a: Array\n fun input() {\n a = inp.readIntTable(4, 4)\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 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, { readTArray(cols, { col, s -> convert(it, col, s) }) })\n}\n\nfun main(args: Array) {\n// val millis = measureTimeMillis(Solver()::solve)\n// System.err.println(\"Time spent: $millis\")\n val solver = Solver()\n solver.input()\n solver.solve()\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "0251fc5bb2c70a4f730362dcee28315b", "src_uid": "44fdf71d56bef949ec83f00d17c29127", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)){\n val n = nextLong()\n var i = 1\n var lucky = 4L\n while (true) {\n if(n == lucky){\n break\n }\n lucky = increaseLuckyNumber(lucky)\n //println(\"step: $i, increased: $lucky\")\n i++\n }\n println(i)\n}\n\nfun increaseLuckyNumber(luck: Long): Long{\n var chars = luck.toString().toCharArray()\n var i = chars.size - 1 \n while (true){\n val curr = chars[i]\n \n if (curr == '4'){\n chars[i] = '7'\n break\n }\n chars[i] = '4'\n if (i == 0){\n var newStr = String(chars)\n newStr = \"4$newStr\"\n //val newChars = CharArray(chars.size + 1)\n //newChars[0] = '4'\n //newChars.addAll(chars, chars.toCharArray())\n //chars = newChars\n chars = newStr.toCharArray()\n break\n }\n i--\n }\n return String(chars).toLong()\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "combinatorics", "bitmasks"], "code_uid": "1c9154f417a6aff3d039e1d7d04a904e", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.pow\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //val list = r.readLine()!!.split(\" \").map { it.toInt() }\n //repeat(r.readLine()!!.toInt()) {\n val str = r.readLine()!!\n val len = str.length\n val b = IntArray(len) { if (str[it] == '4') 0 else 1 }\n var ans = 0\n for (i in 0..len-1){\n when(b[i]){\n 0 -> ans+=2.0.pow(len-i-1).toInt()\n 1 -> ans+=2.0.pow(len-i).toInt()\n }\n }\n println(ans)\n //}\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "combinatorics", "bitmasks"], "code_uid": "d7c93589f177f53c8200a601a89feae1", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "divide and conquer", "dfs and similar"], "code_uid": "bf2dfc4f902ad7b56879bdcf1e55bc95", "src_uid": "1b17a7b3b41077843ee1d6e0607720d6", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "divide and conquer", "dfs and similar"], "code_uid": "2976ba4e74e5c58aeac5a0a9c6b57a1b", "src_uid": "1b17a7b3b41077843ee1d6e0607720d6", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var list = readLine()!!.split(' ').map { it.toInt() }\n\n if (list[0] < list[1]) {\n println(list[0] - 1)\n } else if (list[0]==list[1]) {\n println(list[0]-1)\n } else {\n\n var ans = list[0] - list[1]\n var sum = list[1]\n for (i in 2..ans) {\n sum += i\n }\n println(sum)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "dp"], "code_uid": "3ded2615d1be0aa009efd656e7cbe996", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //val len = r.readLine()!!.toInt()\n val (n, k) = r.readLine()!!.split(\" \").map { it.toInt() }\n var ans = minOf(k, n-1)\n for (i in 2..n-k){\n ans+=i\n }\n println(ans)\n //val v = r.readLine()!!.split(\"\").filter { it.isNotEmpty() }.map { it.toInt() }.toIntArray()\n /*repeat(r.readLine()!!.toInt()) {\n //val len = r.readLine()!!.toInt()\n val (a, b, c) = r.readLine()!!.split(\" \").map { it.toLong() }\n val ans = if (c){\n val br = BufferedReader(InputStreamReader(System.`in`))\n val nv = br.readLine().split(\" \").map { it.toInt() }\n val n = nv[0]\n val v = nv[1]\n println(findMin(n, v))\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "dp"], "code_uid": "568b959b7009fafb543edc3903f2165f", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.collections.HashMap\n\nfun main(args : Array) {\n val input = Scanner(System.`in`)\n var city = HashMap()\n\n var j=0\n val n = input.nextInt()\n val u = input.nextInt()\n var sum = u\n if (n < u){\n println(n -1)\n } else {\n for (i in n downTo 1){\n city.put(i, j)\n if (j < u){\n j++\n } else {\n sum += i*1\n }\n }\n println(sum-1)\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "dp"], "code_uid": "0059e9cbebe937d605c0d4541ba29700", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLine()!!\n val t = readLine()!!\n if (s.length < t.length) {\n print(\"need tree\")\n return\n }\n val longMap = IntArray(26)\n for (c in s) longMap[c - 'a']++\n for (c in t) {\n if (longMap[c - 'a'] > 0) longMap[c - 'a']-- else {\n print(\"need tree\")\n return\n }\n }\n val automaton = s.length != t.length\n var sPos = 0\n var lPos = 0\n while (sPos < t.length && lPos < s.length) {\n if (t[sPos] == s[lPos]) sPos++\n lPos++\n }\n print(\n when {\n automaton && sPos < t.length -> \"both\"\n automaton -> \"automaton\"\n else -> \"array\"\n }\n )\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "c866291c34d39008ccfcd1c982e1f2c3", "src_uid": "edb9d51e009a59a340d7d589bb335c14", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "3bb1d3c43f433ef4da865d848ea5e267", "src_uid": "e2f15a9d9593eec2e19be3140a847712", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "a1be3cdf529cb84fe0ab2fa314868cf4", "src_uid": "e2f15a9d9593eec2e19be3140a847712", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "d06af5d8ab123205da33f87210a33fc5", "src_uid": "e2f15a9d9593eec2e19be3140a847712", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.min\n\nconst val INF = 99\n\n\nfun solve() {\n\n val a = next().toCharArray().map { it.toInt() - 48 }\n val n = a.size\n\n var ans = INF\n for (i in 0 until n) {\n for (j in 0 until n) {\n if (i !=j) {\n val x = a[i]\n val y = a[j]\n if ((x*10 + y) % 25 == 0) {\n val b = a.toMutableList()\n var count = 0\n for (k in j+1 until n) {\n b[k] = b[k-1].also { b[k-1] = b[k] }\n count++\n }\n var l = i\n if (i < j) {\n l++\n }\n for (k in l until n-1) {\n b[k] = b[k-1].also { b[k-1] = b[k] }\n count++\n }\n\n if (b[0] == 0) {\n count += b.indexOfFirst { it != 0 }\n }\n\n ans = min(ans, count)\n }\n }\n }\n }\n\n print(if (ans != INF) ans else -1)\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy"], "code_uid": "560102aeb91481420874a79b705ff46a", "src_uid": "ea1c737956f88be94107f2565ca8bbfd", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.collections.HashMap\nimport kotlin.collections.HashSet\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main(args: Array)\n = Thread { run() }.start()\n\nval scanner = Scanner(System.`in`)\nval str = scanner.next()\n\nfun run() {\n\n if (str.length == 1) {\n println(-1)\n return\n }\n if (str.length == 2) {\n if (Integer.parseInt(str) % 25 == 0)\n println(0)\n else if (Integer.parseInt(str.reversed()) % 25 == 0)\n println(1)\n else\n println(-1)\n return\n }\n var q = 0\n for (i in str)\n if (i == '0')\n q++\n if (q == str.length - 2 && str.length > 3) {\n if (str[str.length - 1] != '0')\n println(2)\n else if (str[str.length - 2] != '0')\n println(1)\n else\n println(0)\n return\n }\n if (q == str.length - 1) {\n println(0)\n return\n }\n var res = Int.MAX_VALUE\n var help = -1\n for (i in str.length - 1 downTo 0) {\n if (str[i] == '0') {\n if (help == -1)\n help = i\n else {\n res = 2 * str.length - 3 - help - i\n break\n }\n }\n }\n// println(res)\n var a = res('2', '5')\n// println(a)\n res = min(res, a)\n a = res('5', '0')\n// println(a)\n res = min(res, a)\n a = res('7', '5')\n// println(a)\n res = min(res, a)\n if (res == Int.MAX_VALUE)\n println(-1)\n else\n println(res)\n\n}\n\nfun res(a: Char, b: Char): Int {\n var help1 = -1\n var help2 = -1\n val l = str.length\n// if (b == '0' && str[0] == '5' && str[1] == '0')\n// return 2 * l - 4\n for (i in str.length - 1 downTo 0) {\n if (str[i] == a) {\n if (help2 != -1) {\n if (i != 0)\n return 2 * l - 3 - i - help2\n if (b == '0' && str[1] == '0')\n return 2 * l - 4\n var help = -1\n for (j in 1 until l) {\n if (str[j] != '0') {\n help = j\n break\n }\n }\n if (help != help2)\n return 2 * l - 4 - help2 + help\n return 2 * l - 4\n }\n else if (help1 == -1)\n help1 = i\n }\n else if (str[i] == b) {\n if (help1 != -1) {\n if (i != 0)\n return 2 * l - 2 - i - help1\n var help = -1\n for (j in 1 until l) {\n if (str[j] != '0') {\n help = j\n break\n }\n }\n if (help != help1)\n return 2 * l - 3 - help1 + help\n return 2 * l - 3\n }\n else if (help2 == -1)\n help2 = i\n }\n }\n return Int.MAX_VALUE\n}\n\n//fun res(a: Char, b: Char): Int {\n// var help1 = -1\n// var help2 = -1\n// for (i in str.length - 1 downTo 0) {\n// if (str[i] == a) {\n// if (help2 != -1) {\n// if (i == 0 && str[1] == '0') {\n// var help = -1\n// for (j in 1 until str.length) {\n// if (str[j] != '0') {\n// help = j\n// break\n// }\n// }\n// if (str.substring(1).indexOf(b) == help2) {\n// if (help2 == str.length - 1)\n// return Int.MAX_VALUE\n// return 2 * str.length - 4\n// }\n// return str.length - 1 - help2 + help + str.length - 2\n// }\n// return 2 * str.length - 2 - i - help2\n// }\n// else if (help1 != -1)\n// help1 = i\n// }\n// else if (str[i] == b) {\n// if (help1 != -1)\n// return 2 * str.length - 2 - i - help1 + 1\n// else if (help2 != -1)\n// help2 = i\n// }\n// }\n// return Int.MAX_VALUE\n//}\n\n//fun run() {\n// val scanner = Scanner(System.`in`)\n// val n = scanner.nextInt()\n// val arr = Array>(n) { HashMap() }\n// val mins = Array(n) { intArrayOf(-1, -1) }\n// val v = IntArray(n) { scanner.nextInt() }\n// val map = HashMap()\n// var size = 0\n// for (i in v.sorted())\n// if (!map.containsKey(i))\n// map[i] = size++\n// arr.forEach { it[-1] = Int.MAX_VALUE }\n// var res = Int.MAX_VALUE\n// for (i in 0 until n) {\n// val c = scanner.nextInt()\n// val index = map[v[i]]!!\n// for (j in v[i] + 1 until size) {\n// if (arr[j][mins[j][0]]!! > c) {\n// if (mins[j][0] != index)\n// mins[j][1] = mins[j][0]\n// mins[i][0] = index\n// arr[j][index] = c\n// }\n// else if (map[mins[j][1]]!! > c && mins[j][0] != index) {\n// mins[j][1] = index\n// arr[j][index] = c\n// }\n// res = min(res, arr[j][mins[j][0]]!! + arr[j][mins[j][1]]!! + c)\n// }\n// }\n// println(res)\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)", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy"], "code_uid": "41c10c8b826b712569fe6aa28d61b090", "src_uid": "ea1c737956f88be94107f2565ca8bbfd", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 lens = arrayOf(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30)\n val toNum = mapOf(\"monday\" to 0, \"tuesday\" to 1, \"wednesday\" to 2, \"thursday\" to 3, \"friday\" to 4, \"saturday\" to 5, \"sunday\" to 6)\n val fst = toNum[next()]!!\n val snd = toNum[next()]!!\n fun solve() : Boolean {\n for (x in lens)\n if ((fst + x) % 7 == snd)\n return true\n return false\n }\n fout.print(if (solve()) \"YES\" else \"NO\")\n fout.close()\n fin.close()\n}\n\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "075838b7e8cf0f8916d591a882ee2144", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val i = listOf(\"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\")\n val l = listOf(0,2,3);\n val a = i.indexOf(readLine())\n val b = i.indexOf(readLine())\n var ok = false;\n l.forEach {\n i -> if ((a + i) % 7 == b) ok = true\n }\n var s = when(ok){\n true -> \"Yes\"\n else -> \"No\"\n }\n println(s)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "f924d2f3c0f30c37362d4809966f25f8", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\nfun dayToInt(s: String) = when (s) {\n \"monday\" -> 0\n \"tuesday\" -> 1\n \"wednesday\" -> 2\n \"thursday\" -> 3\n \"friday\" -> 4\n \"saturday\" -> 5\n \"sunday\" -> 6\n else -> throw IllegalArgumentException()\n}\n\nprivate fun solve(input: BufferedReader, output: PrintWriter) {\n val d1 = dayToInt(input.readLine())\n val d2 = dayToInt(input.readLine())\n\n if (listOf(28, 30, 31).any { (d1 + it) % 7 == d2 })\n output.println(\"YES\") else\n output.println(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2ef91826ea9d081323b83a35bcf0f617", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val nameToNum = mapOf(\n \"monday\" to 0, \"tuesday\" to 1, \"wednesday\" to 2, \"thursday\" to 3, \"friday\" to 4, \"saturday\" to 5, \"sunday\" to 6\n )\n val first = nameToNum[readLine()!!]!!\n val second = nameToNum[readLine()!!]!!\n for (diff in listOf(28, 30, 31)) if ((first + diff) % 7 == second) return print(\"YES\")\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9a6878ae1ee9a49e7823278d5647d535", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.IOException\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(args: Array) {\n tv()\n}\n\nfun tv() {\n val ms = MyScanner()\n val a = ms.nextLong()!!\n val b = ms.nextLong()!!\n val x = ms.nextLong()!!\n val y = ms.nextLong()!!\n\n var xx = x\n var yy = y\n\n while (xx != 0L && yy != 0L){\n if (xx > yy){\n xx %= yy\n } else {\n yy %= xx \n }\n }\n \n val nod = xx + yy\n val xxx = x/ nod\n val yyy = y/nod\n System.out.println(Math.min(a/xxx, b/yyy))\n \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)\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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "07023ad5fc0402c16db5fae1521bf75b", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun nod(a: Long, b: Long): Long =\n if (a % b != 0L) {\n nod(b, a % b)\n } else {\n b\n }\n\nfun main(args: Array) {\n var (a, b, x, y) = readLine()!!.split(\" \").map(String::toLong)\n\n var nodValue = if (x < y) nod(x, y) else nod(y, x)\n\n if(nodValue != 1L) {\n x /= nodValue\n y /= nodValue\n }\n println(if (a/x > b/y) b/y else a/x)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "e84abcb1d366a78d5ab5d1272cd3915a", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.io.*\nimport java.util.*\nimport kotlin.math.min\n\nfun solve() {\n\n val a = nextLong()\n val b = nextLong()\n\n var x = nextLong()\n var y = nextLong()\n\n val d = gcd(x, y)\n x /= d\n y /= d\n\n val countX = a / x\n val countY = b / y\n\n println(min(countX, countY))\n}\n\nfun gcd(a: Long, b: Long) : Long {\n return if (b == 0L) a else gcd(b, a % b)\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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "c3630afca7e390fbb48d39eecbbe647f", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n fun gcd(x: Long, y: Long):Long = if (y == 0L) x else gcd(y, x % y)\n\n val a = nextLong()\n val b = nextLong()\n val x = nextLong()\n val y = nextLong()\n\n val g = gcd(x, y)\n val _x = x / g\n val _y = y / g\n\n println(Math.min(a / _x, b / _y))\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "fad107c2d6840192df215b5f32853b89", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport kotlin.math.max\n\nfun main() {\n val input = BufferedReader(InputStreamReader(System.`in`))\n val rgb = input.readLine().split(' ').map { it.toLong() }.sortedDescending().toLongArray()\n\n val leftovers = max(0, rgb[0] - rgb[1] * 2 - rgb[2] * 2)\n val result = (rgb.sum() - leftovers) / 3\n\n println(result)\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "8a40935f5478451e5525ec65d7bc4cfc", "src_uid": "bae7cbcde19114451b8712d6361d2b01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 A = na(3).map{it.toLong()}\n val S = A.sum()\n val remain = max(\n max(0, A[0] - 2 * (A[1] + A[2]))\n , max(\n max(0, A[1] - 2 * (A[0] + A[2]))\n , max(0, A[2] - 2 * (A[0] + A[1]))\n )\n )\n out.println((S - remain) / 3)\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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, offset) { ni() }\n }\n\n private inline fun map(n: Int, offset: Int = 0, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i + offset)\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun pair(a: A, b: B) = RPair(a, b)\ndata class RPair(val _1: A, val _2: B)\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "bb9af57bbca7975518785bdaf3ab9ff4", "src_uid": "bae7cbcde19114451b8712d6361d2b01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.lang.StringBuilder\nimport java.util.*\nimport kotlin.collections.*\nimport kotlin.math.*\n\nval maxn = 200005\nval sz = 256 * 1024\nval inf0 = 2e9\nval inf = inf0.toInt()\nval INF0 = 4e18\nval INF = INF0.toLong()\nval eps = 1e-6\nval MOD = 998244353L\n\nfun solve() {\n var r = nextLong()\n var g = nextLong()\n var b = nextLong()\n val a = LongArray(3)\n a[0] = r\n a[1] = g\n a[2] = b\n a.sort()\n val sum = r + g + b\n if (a[2] >= 2 * (a[0] + a[1])){\n println(a[0] + a[1])\n } else println(sum / 3)\n}\n\nval multitest = false\n\nfun main() {\n var t = 1\n if (multitest) t = nextInt()\n for (i in 1..t) solve()\n out.flush()\n}\n\nfun max(a : Pair, b : Pair) : Pair{\n if (a.first > b.first) return a\n if (b.first > a.first) return b\n if (a.second > b.second) return a\n return b\n}\n\nfun back(a: ArrayList): Int {\n return a[a.size - 1]\n}\n\nval t = IntArray(2 * sz)\n\nfun upd(v: Int, vl: Int, vr: Int, i: Int, x: Int) {\n if (i < vl || i > vr) return\n if (vl == vr) {\n t[v] = x\n return\n }\n val vm = (vl + vr) / 2\n upd(v * 2 + 1, vl, vm, i, x)\n upd(v * 2 + 2, vm + 1, vr, i, x)\n t[v] = max(t[v * 2 + 1], t[v * 2 + 2])\n}\n\nfun query(v: Int, vl: Int, vr: Int, l: Int, r: Int): Int {\n if (vl > r || l > vr) return -1\n if (vl >= l && vr <= r) return t[v]\n val vm = (vl + vr) / 2\n return max(query(v * 2 + 1, vl, vm, l, r), query(v * 2 + 2, vm + 1, vr, l, r))\n}\n\nval fact = LongArray(maxn)\nval invfact = LongArray(maxn)\n\nfun calcFactorials() {\n fact[0] = 1\n for (i in 1..maxn - 1) fact[i] = (fact[i - 1] * i.toLong()) % MOD\n for (i in 0..maxn - 1) invfact[i] = powmod(fact[i], MOD - 2, MOD)\n}\n\nfun cnk(n: Int, k: Int, m: Long): Long {\n return ((fact[n] * invfact[k]) % m) * invfact[n - k] % m\n}\n\nfun powmod(x: Long, d: Long, m: Long): Long {\n if (d == 0L) return 1\n if (d % 2 == 0L) {\n val y = powmod(x, d / 2, m)\n return (y * y) % m\n }\n return x * powmod(x, d - 1, m) % m\n}\n\nfun divup(x: Int, y: Int): Int {\n return (x + y - 1) / y\n}\n\nfun divup(x: Long, y: Long): Long {\n return (x + y - 1) / y\n}\n\nfun gcd(x: Long, y: Long): Long {\n if (x == 0L || y == 0L) return x + y\n if (x > y) return gcd(x % y, y)\n return gcd(y % x, x)\n}\n\nfun end() {\n out.flush()\n System.exit(0)\n}\n\nfun printIntArray(a: IntArray) {\n for (x in a) print(\"$x \")\n print(\"\\n\")\n}\n\nfun printIntArrayList(a: ArrayList) {\n for (x in a) print(\"$x \")\n print(\"\\n\")\n}\n\nfun nextInt() = next().toInt()\nfun nextLong() = next().toLong()\nfun nextDouble() = next().toDouble()\n\nval reader = BufferedReader(InputStreamReader(System.`in`))\nval out = PrintWriter(System.out, false)\nvar tokenizer = StringTokenizer(\"\")\n\nfun println(o: Any) = out.println(o)\nfun print(o: Any) = out.print(o)\n\nfun next(): String {\n while (!tokenizer.hasMoreTokens())\n tokenizer = StringTokenizer(reader.readLine())\n return tokenizer.nextToken()\n}\n\nfun increase(map: HashMap, k: Int) {\n map[k] = 1 + if (map.containsKey(k)) map[k]!! else 0\n}\n\nfun decrease(map: HashMap, k: Int) {\n map[k] = -1 + if (map.containsKey(k)) map[k]!! else 0\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "eb9e107cf6bc3f67a9ee101f5606d128", "src_uid": "bae7cbcde19114451b8712d6361d2b01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun isin(sum_sum : Int, n : Int) : Boolean{\n return sum_sum <= n\n}\nfun main(){\n val n = readLine()!!.toInt()\n var sum : Int = 0\n var sum_sum : Int = 0\n var ad = 1\n var ans = -1\n while(isin(sum_sum, n)){\n sum += ad\n sum_sum += sum\n //print(\"$sum $sum_sum \\n\")\n ad++\n ans++\n }\n print(ans)\n\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "29afde7686a9c953afcb26fd5c27d61c", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n var total = 0\n var level = 1\n var width = 0\n var ans = 0\n while (total <= n) {\n width += level\n total += width\n if (total <= n)\n ans = level\n // print(\"$width $total\\n\")\n level++\n }\n print(\"$ans\\n\")\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "afdc677f4b72a854af701c648395a18b", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 var cost = 1\n var remaid = n\n while (remaid>=cost){\n remaid -= cost\n ans++\n cost += ans+1\n }\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "45bf30be8d92a299b021fd48ca64589b", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var n = readLine()!!.toInt()\n var cnt = 0\n var add = 0\n while(n > 0) {\n add++\n cnt += add\n n -= cnt\n }\n println(add - if (n < 0) 1 else 0)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "51eebb21e3d4606e3fac77615c2784ee", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "c81615acbe677dac9404213aaa632d76", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "4276e5c90893d876774bc42ebb6915d9", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "677fde2e4aa036d6d79532464112731e", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 }", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "320cf141460242fa184ae07424ea4084", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\n\nfun main(args: Array){\n\tval inpt = readLine().toString().split(\" \")\n\tval N = inpt[0]\n\tval A: Int = inpt[1].toInt()\n\tval B: Int = inpt[2].toInt()\n\tval rounds = round(log(N.toDouble(), 2.0)).toInt()\n\tval result = fround(A,B,rounds)\n\tif (result == rounds){\n\t\tprintln(\"Final!\")\n\t}else{\n\t\tprintln(result)\n\t}\n}\n\nfun fround(A: Int,B: Int,rounds: Int): Int{\n\tvar meetRound: Int = 0\n\tvar tmpA: Int\n\tvar tmpB: Int\n\n\tfor (i in rounds downTo 1){\n\t\ttmpA = ceil(A/(2.0.pow(i-1))-0.001).toInt()\n\t\ttmpB = ceil(B/(2.0.pow(i-1))-0.001).toInt()\n\t\tif (abs(tmpA - tmpB) >= 1){\n\t\t\tmeetRound = i\n\t\t\tbreak\n\t\t}\n\t}\n\treturn(meetRound)\n}\n", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation"], "code_uid": "7ea2a272c860dd313081e2e60dd5db7c", "src_uid": "a753bfa7bde157e108f34a28240f441f", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numTeams, team1, team2) = readInts()\n val (minorTeam, majorTeam) = team1 minmax team2\n var numRounds = 0\n var nt = numTeams\n while (nt > 1) {\n numRounds++\n nt = nt shr 1\n }\n val queue = ArrayDeque>()\n queue.add(Triple(numRounds, 1, numTeams / 2))\n queue.add(Triple(numRounds, numTeams / 2 + 1, numTeams))\n while (queue.isNotEmpty()) {\n val (round, limitDown, limitUp) = queue.removeFirst()\n var where = 0\n if (minorTeam in limitDown..limitUp) where++\n if (majorTeam in limitDown..limitUp) where++\n if (where == 1) return print(if (round == numRounds) \"Final!\" else round)\n if (round == 1) return print(1)\n queue.addLast(Triple(round - 1, limitDown, (limitDown + limitUp) / 2))\n queue.addLast(Triple(round - 1, (limitDown + limitUp) / 2 + 1, limitUp))\n }\n}\n\nprivate infix fun Int.minmax(team2: Int) = if (this <= team2) this to team2 else team2 to this\n", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation"], "code_uid": "f451b5b0b00fed5c7483b135ec4041b2", "src_uid": "a753bfa7bde157e108f34a28240f441f", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.log2\n\nfun main(args: Array) {\n cf()\n}\n\nprivate fun cf() = with(Scanner(System.`in`)) {\n val n = nextInt()\n val a = nextInt()\n val b = nextInt()\n\n val r = round(n, a, b)\n if (isFinal(r, n))\n println(\"Final!\")\n else\n println(r)\n}\n\nprivate fun isFinal(r: Int, n: Int): Boolean {\n return log2(n.toDouble()).toInt() == r\n}\n\nprivate fun round(n: Int, a_: Int, b_: Int): Int {\n var n = n\n var a = minOf(a_, b_)\n var b = maxOf(a_, b_)\n\n var games = 0\n\n while (true) {\n games++\n\n if (b % 2 == 0 && a + 1 == b) {\n return games\n }\n\n n /= 2\n a = (a + 1) / 2\n b = (b + 1) / 2\n }\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation"], "code_uid": "46fb8aa4ce81218d6f628f1b014c13eb", "src_uid": "a753bfa7bde157e108f34a28240f441f", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport java.lang.System.err\n\nprivate const val localFileName = \"test\"\nprivate lateinit var out: PrintWriter\nprivate lateinit var bf: BufferedReader\nprivate var stok = StringTokenizer(\"\")\nprivate fun read(): String {\n while (!stok.hasMoreTokens()) stok = StringTokenizer(bf.readLine())\n return stok.nextToken()\n}\n\nprivate fun solve() {\n val mod = 998244353L\n val maxn = 201010\n fun Long.sqr() = this * this\n fun Long.mpow(exp: Long): Long = when {\n exp == 0L -> 1L\n (exp and 1L) == 1L -> this * this.mpow(exp - 1) % mod\n else -> this.mpow(exp / 2).sqr() % mod\n }\n\n val inv_2 = 2L.mpow(mod - 2)\n\n val fac = LongArray(maxn)\n val inv_fac = LongArray(maxn)\n fac[0] = 1\n for (i in 1 until maxn) fac[i] = (fac[i - 1] * i) % mod\n for (i in 0 until maxn) inv_fac[i] = fac[i].mpow(mod - 2)\n\n val pow2 = LongArray(maxn)\n pow2[0] = 1\n for (i in 1 until maxn) pow2[i] = pow2[i - 1] * 2L % mod\n\n fun comb(n: Int, k: Int) = fac[n] * inv_fac[k] % mod * inv_fac[n - k] % mod\n\n val n = read().toInt()\n val k = read().toLong()\n if (k == 1L) {\n out.println(0)\n return\n }\n\n val a = MutableList(n) { read().toInt() }\n var new_len = 1\n for (i in 1 until a.size) {\n if (a[i] == a[i - 1]) continue\n a[new_len++] = a[i]\n }\n if (a[0] == a[new_len - 1]) --new_len\n while (a.size != new_len) a.removeAt(a.lastIndex)\n\n var ans = 0L\n\n for (cnt0 in 0 .. a.size) {\n var cur_ans = pow2[a.size - cnt0]\n if ((a.size - cnt0) % 2 == 0)\n cur_ans = (cur_ans + mod - comb(a.size - cnt0, (a.size - cnt0) / 2)) % mod\n cur_ans = (cur_ans * inv_2) % mod\n cur_ans = cur_ans * comb(a.size, cnt0) % mod * (k - 2).mpow(cnt0.toLong()) % mod\n ans = (ans + cur_ans) % mod\n }\n ans = ans * k.mpow((n - a.size).toLong()) % mod\n out.println(ans)\n}\n\nfun main() {\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n assert(localFileName != \"\")\n System.setIn(FileInputStream(File(\"$localFileName.inp\")))\n System.setOut(PrintStream(File(\"$localFileName.out\")))\n }\n\n out = PrintWriter(System.out!!, false)\n bf = BufferedReader(InputStreamReader(System.`in`))\n\n solve()\n out.flush()\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "97f969af8aec491ce4a5d2eb49ae353d", "src_uid": "63c4006a0a6284f9825aaabfc4c28fd1", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args:Array) {\n val n = readLine()!!\n var ms = readLine()!!.toList().map { it.toString() }.toMutableList()\n\n l2@while(true) { \n l1@for( i in (0..ms.size-1-1) ) { \n //println( ms[i] + ms[i+1] )\n if( ms[i] + ms[i+1] == \"01\" ) {\n ms[i] = \"1\"\n ms[i+1] = \"0\"\n break@l1\n }\n if( i == ms.size-1-1 ) {\n break@l2\n }\n }\n ms = ms.joinToString(\"\").replace(\"11\", \"1\").toList().map { it.toString() }.toMutableList()\n if( ms.size == 1 ) {\n break@l2\n }\n //println(ms)\n }\n println(ms.joinToString(\"\").replace(\"1{1,}\".toRegex(), \"1\"))\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c93be60b9985be34f41ced99fc7c4d8e", "src_uid": "ac244791f8b648d672ed3de32ce0074d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import javax.management.Query.and\n\nfun main(args: Array) {\n var n = readLine()!!.toInt()\n var s = readLine()!!\n var zero: Int = 0\n var one = false\n for (i in s) {\n zero += if (i == '0') 1 else 0\n one = (i == '1') || one\n }\n if (one) print(1)\n while (zero > 0) {\n print(0)\n zero--\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "b8ef3c5b1310a562ef9a8f87ad17d400", "src_uid": "ac244791f8b648d672ed3de32ce0074d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 scanner.nextInt()\n val str = scanner.next()\n if (str == \"0\") {\n println(0)\n return\n }\n print(\"1\")\n str.forEach { if (it == '0') print('0') }\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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "57eaf4ae20983ab0fef0f1eabc170103", "src_uid": "ac244791f8b648d672ed3de32ce0074d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.util.*\n\nfun main(args: Array) {\n with(Scanner(System.`in`)) {\n val n = nextInt()\n val s = next()\n if (s == \"0\") println(s)\n else {\n val c = s.count { it == '0' }\n print(\"1\")\n (1..c).forEach { print(\"0\") }\n println()\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "46cb5c38e9ad19a6a4fa26370567b641", "src_uid": "ac244791f8b648d672ed3de32ce0074d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "0d9eaa570e39979a6e2c259343cc3f43", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "b89af3f89924ab61945e8c0273af1b47", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "6fd6f49c3c59bfc13a256c651d1ff670", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "420850fce84d18f5f05e467bc66511f2", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val inputs = readLine()!!.split(\" \")\n val a = inputs[0].toLong()\n val b = inputs[1].toLong()\n val c = inputs[2].toLong()\n val d = inputs[3].toLong()\n\n val arr = listOf(a, b, c).sorted()\n val diffA = if(arr[1] - d >= arr[0]) 0 else Math.abs((arr[1] - d) - arr[0])\n val diffB = if(arr[1] + d <= arr[2]) 0 else Math.abs((arr[1] + d) - arr[2])\n\n val result = diffA + diffB\n println(result)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "c4246d4c8c566fb5a4613aedb930b3f1", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n\n val (aa, bb, cc, d) = readInts()\n\n val (a, b, c) = arrayOf(aa, bb, cc).sorted()\n\n println(Math.max(d - b + a, 0) + Math.max(d - c + b, 0))\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() }", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "d14daf1e11b3ac4d65bd982a8ef91866", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array){\n\tval (A,B,C,d) = readLine().toString().split(\" \").map{it.toInt()}\n\tval (a,b,c) = listOf(A,B,C).sorted()\n\tval left = if(b - a >= d) 0 else d + a - b\n\tval right = if(c - b >= d) 0 else d + b - c\n\tprintln(left + right)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "866b4e82169e72d8e510972dee0ede83", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\nimport kotlin.math.min\n\nfun main() {\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n val (a, b, c, d) = readLongs()\n val walkers = longArrayOf(a, b, c)\n walkers.sort()\n print(abs(min(0, walkers[1] - d - walkers[0]) + min(0, walkers[2] - d - walkers[1])))\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "585c3c0705ef1d31db6c50bdd53c8ab8", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.5", "source_code": "private fun readLn() = readLine()!! // string line\r\nprivate fun readInt() = readLn().toInt() // single int\r\nprivate fun readLong() = readLn().toLong() // single long\r\nprivate fun readDouble() = readLn().toDouble() // single double\r\nprivate fun readStrings() = readLn().split(\" \") // list of strings\r\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\r\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\r\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\r\nprivate fun readLis() = readInts().toMutableList()\r\n\r\n//println(res.joinToString(\" \")) - > focus ( \" \" )\r\n//var a1 = readLongs().toMutableList()\r\n//val st = mutableSetOf() -> var find = st.elementAt(i)\r\n//var ar1 = LongArray(3) {100000}\r\n//f2.sortDescending() sort IntArray\r\n//var c = 'a' + i ( from 'a' --> 'z' )\r\n\r\n\r\nfun solve() {\r\n var n = readInt()\r\n var s = readLine()!!.toString()\r\n if (n == 1) {\r\n println(\"0\")\r\n return\r\n }\r\n var ans = 0\r\n var st = -1\r\n for (i in 0 until n) {\r\n if (s[i] == '0') {\r\n st = i\r\n break\r\n }\r\n }\r\n if (st == -1) {\r\n println(\"0\")\r\n return\r\n }\r\n var one = 0\r\n while (true) {\r\n var end = 0\r\n var ok = 0\r\n for (i in st + 1 until n) {\r\n if (s[i] == '0') {\r\n st = i\r\n if (one >= 2) {\r\n one = 0\r\n } else {\r\n ans += 2 - one\r\n one = 0\r\n }\r\n ok = 1\r\n break\r\n } else {\r\n one++\r\n }\r\n }\r\n if (st >= n - 1 || ok == 0) {\r\n break\r\n }\r\n }\r\n\r\n println(ans)\r\n}\r\n\r\nfun main() {\r\n val n = readInt()\r\n val arr = Array(n){CharArray(n)}\r\n for(i in 0 until n){\r\n val s = readLine()!!.toString()\r\n for(j in 0 until n){\r\n arr[i][j] = s[j]\r\n }\r\n }\r\n var ok = false\r\n for(i in 0 until n){\r\n for(j in 0 until n){\r\n if(i < n - 7){\r\n var cur = \"\"\r\n for(k in 0 until 7){\r\n cur += arr[i + k][j]\r\n }\r\n if(cur == \"theseus\"){\r\n ok = true\r\n }\r\n }\r\n if(j < n - 7){\r\n var cur = \"\"\r\n for(k in 0 until 7){\r\n cur += arr[i][j + k]\r\n }\r\n if(cur == \"theseus\"){\r\n ok = true\r\n }\r\n }\r\n if(i < n - 7 && j < n - 7){\r\n var cur = \"\"\r\n for(k in 0 until 7){\r\n cur += arr[i + k][j + k]\r\n }\r\n if(cur == \"theseus\"){\r\n ok = true\r\n }\r\n }\r\n }\r\n }\r\n if(ok){\r\n println(\"YES\")\r\n }else{\r\n println(\"NO\")\r\n }\r\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "74407db6d8b3d9d486fa2ffe480f97e5", "src_uid": "efb72baf6759f7bc5ac0f3099b7177d0", "difficulty": -1.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": " private fun readLn() = readLine()!! // string line\n private fun readInt() = readLn().toInt() // single int\n private fun readLong() = readLn().toLong() // single long\n private fun readDouble() = readLn().toDouble() // single double\n private fun readStrings() = readLn().split(\" \") // list of strings\n private fun readInts() = readStrings().map { it.toInt() } // list of ints\n private fun readLongs() = readStrings().map { it.toLong() } // list of longs\n private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n private fun readLis() = readInts().toMutableList()\n \n //println(res.joinToString(\" \")) - > focus ( \" \" )\n //var a1 = readLongs().toMutableList()\n //val st = mutableSetOf() -> var find = st.elementAt(i)\n //var ar1 = LongArray(3) {100000}\n //f2.sortDescending() sort IntArray\n //var c = 'a' + i ( from 'a' --> 'z' )\n \n \n private fun solve() {\n var n = readInt()\n var s = readLine()!!.toString()\n if (n == 1) {\n println(\"0\")\n return\n }\n var ans = 0\n var st = -1\n for (i in 0 until n) {\n if (s[i] == '0') {\n st = i\n break\n }\n }\n if (st == -1) {\n println(\"0\")\n return\n }\n var one = 0\n while (true) {\n var end = 0\n var ok = 0\n for (i in st + 1 until n) {\n if (s[i] == '0') {\n st = i\n if (one >= 2) {\n one = 0\n } else {\n ans += 2 - one\n one = 0\n }\n ok = 1\n break\n } else {\n one++\n }\n }\n if (st >= n - 1 || ok == 0) {\n break\n }\n }\n \n println(ans)\n }\n \n fun main() {\n val n = readInt()\n val arr = Array(n){CharArray(n)}\n for(i in 0 until n){\n val s = readLine()!!.toString()\n for(j in 0 until n){\n arr[i][j] = s[j]\n }\n }\n var ok = false\n for(i in 0 until n){\n for(j in 0 until n){\n if(i < n - 7){\n var cur = \"\"\n for(k in 0 until 7){\n cur += arr[i + k][j]\n }\n if(cur == \"theseus\"){\n ok = true\n }\n }\n if(j < n - 7){\n var cur = \"\"\n for(k in 0 until 7){\n cur += arr[i][j + k]\n }\n if(cur == \"theseus\"){\n ok = true\n }\n }\n if(i < n - 7 && j < n - 7){\n var cur = \"\"\n for(k in 0 until 7){\n cur += arr[i + k][j + k]\n }\n if(cur == \"theseus\"){\n ok = true\n }\n }\n }\n }\n if(ok){\n println(\"YES\")\n }else{\n println(\"NO\")\n }\n }", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "de5e3912be92863c7f0c04306addaa86", "src_uid": "efb72baf6759f7bc5ac0f3099b7177d0", "difficulty": -1.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.max\n\nval list = LinkedList()\n\nfun dfs(a: Int, b: Int, c: Int = 0): Int {\n if (b == a) return c + 1\n if (b < a) return -1\n val da = if (b % 2 == 0) dfs(a, b / 2, c + 1) else -1\n val db = if (b % 10 == 1) dfs(a, (b - 1) / 10, c + 1) else -1\n if (da != -1 || db != -1) list.add(b)\n return max(da, db)\n}\n\nfun main() {\n val (a, b) = readLine()!!.split(\" \").map(String::toInt)\n val c = dfs(a, b)\n if (c != -1) {\n println(\"YES\\n$c\\n$a ${list.joinToString(\" \")}\")\n } else {\n println(\"NO\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "math", "brute force"], "code_uid": "db09fdbd699f1f42038bddc234866a7d", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun memo (f: (A, B) -> C): (A, B) -> C{\n val vals = mutableMapOf, C>()\n return {\n x: A, y: B -> vals.getOrPut(Pair(x, y)){f(x, y)}\n }\n\n}\n\n\nfun isThereAWay(a: Long, b: Long): List {\n\n fun go(a: Long, b: Long, ls: List): List =\n if(a == b) ls + listOf(b)\n else if (a > b || a < 0) emptyList()\n else go(a*2, b, ls + listOf(a)) + go(a*10 + 1, b, ls + listOf(a))\n\n\n return go(a, b, emptyList())\n}\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val ab = br.readLine().split(\" \").map { it.toLong() }\n val a = ab[0]\n val b = ab[1]\n val result = memo(::isThereAWay)(a, b)\n if (result.isEmpty()){\n println(\"NO\")\n }else{\n println(\"YES\")\n println(result.size)\n print(result[0])\n for (i in 1 until result.size){\n print(\" \" + result[i])\n }\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "math", "brute force"], "code_uid": "7b314f229fa02262eab98470edb0a716", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n var (a, b) = readInts()\n val sol = mutableListOf()\n while (b > a) {\n sol.add(b)\n b /= when {\n b and 1 == 0 -> 2\n b % 10 == 1 -> 10\n else -> return print(\"NO\")\n }\n }\n if (b != a) return print(\"NO\")\n sol.add(b)\n println(\"YES\")\n println(sol.size)\n println(sol.reversed().joinToString(\" \"))\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "math", "brute force"], "code_uid": "a82426eb9b830837f9dc96f79954450c", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n if (args.size > 0) 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 var b = st.nextToken().toInt()\n val arr = mutableListOf(b)\n while (a < b) {\n if (b and 1 == 0) {\n b /= 2\n } else {\n val pb = (b - 1) / 10\n if (b == (pb * 10) + 1) b = pb\n else break\n }\n arr.add(b)\n }\n if (a == b) {\n bw.write(\"YES\\n${arr.size}\\n\")\n bw.write(arr.reversed().joinToString(separator = \" \"))\n }\n else bw.write(\"NO\")\n bw.newLine()\n bw.flush()\n}\n", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "math", "brute force"], "code_uid": "95b0f2d5203dc0fb687dc8c2c2260f27", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLine()!!\n val numFours = s.count { it == '4' }\n val numSevens = s.count { it == '7' }\n print(\n when {\n numFours == 0 && numSevens == 0 -> -1\n numFours >= numSevens -> 4\n else -> 7\n }\n )\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "18b136096e40aaaf6f805e9f8542c26d", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var str = readLine()!!\n var four = 0\n var seven = 0\n\n for (i in str){\n if (i=='4'){\n four++\n }else if (i=='7'){\n seven++\n }\n }\n if (four>seven){\n println(4)\n }else if (seven>four){\n println(7)\n }else if (seven==four && seven!=0){\n println(4)\n }else{\n println(-1)\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "38120ab47d414add0127df58f58255e0", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "/**\r\n * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools\r\n */\r\nimport java.io.BufferedInputStream\r\nimport java.io.BufferedReader\r\nimport java.io.InputStreamReader\r\nimport java.io.PrintWriter\r\nimport kotlin.math.min\r\nimport kotlin.math.max\r\nimport kotlin.reflect.KProperty0\r\n\r\nclass FastScanner {\r\n\tprivate val BS = 1 shl 16\r\n\tprivate val NC = 0.toChar()\r\n\tprivate val buf = ByteArray(BS)\r\n\tprivate var bId = 0\r\n\tprivate var size = 0\r\n\tprivate var c = NC\r\n\tprivate var `in`: BufferedInputStream? = null\r\n\r\n\tconstructor() {\r\n\t\t`in` = BufferedInputStream(System.`in`, BS)\r\n\t}\r\n\r\n\tprivate val char: Char\r\n\t\tget() {\r\n\t\t\twhile (bId == size) {\r\n\t\t\t\tsize = try {\r\n\t\t\t\t\t`in`!!.read(buf)\r\n\t\t\t\t} catch (e: Exception) {\r\n\t\t\t\t\treturn NC\r\n\t\t\t\t}\r\n\t\t\t\tif (size == -1) return NC\r\n\t\t\t\tbId = 0\r\n\t\t\t}\r\n\t\t\treturn buf[bId++].toChar()\r\n\t\t}\r\n\r\n\tfun nextInt(): Int {\r\n\t\tvar neg = false\r\n\t\tif (c == NC) c = char\r\n\t\twhile (c < '0' || c > '9') {\r\n\t\t\tif (c == '-') neg = true\r\n\t\t\tc = char\r\n\t\t}\r\n\t\tvar res = 0\r\n\t\twhile (c >= '0' && c <= '9') {\r\n\t\t\tres = (res shl 3) + (res shl 1) + (c - '0')\r\n\t\t\tc = char\r\n\t\t}\r\n\t\treturn if (neg) -res else res\r\n\t}\r\n\tfun nextLong(): Long {\r\n\t\tvar neg = false\r\n\t\tif (c == NC) c = char\r\n\t\twhile (c < '0' || c > '9') {\r\n\t\t\tif (c == '-') neg = true\r\n\t\t\tc = char\r\n\t\t}\r\n\t\tvar res = 0L\r\n\t\twhile (c >= '0' && c <= '9') {\r\n\t\t\tres = (res shl 3) + (res shl 1) + (c - '0')\r\n\t\t\tc = char\r\n\t\t}\r\n\t\treturn if (neg) -res else res\r\n\t}\r\n\tfun nextString():String{\r\n\t\tif (c == NC) c = char\r\n\t\tval ret = StringBuilder()\r\n\t\twhile (true){\r\n\t\t\tc = char\r\n\t\t\tif(!isWhitespace(c)){ break}\r\n\t\t}\r\n\t\tret.appendCodePoint(c.toInt())\r\n\t\twhile (true){\r\n\t\t\tc = char\r\n\t\t\tif(isWhitespace(c)){ break}\r\n\t\t\tret.appendCodePoint(c.toInt());\r\n\r\n\t\t}\r\n\t\treturn ret.toString()\r\n\t}\r\n\tfun isWhitespace(c:Char):Boolean{\r\n\t\treturn c == ' ' || c == '\\n' || c == '\\r' || c == '\\t'\r\n\t}\r\n}\r\nclass reading{\r\n\tcompanion object{\r\n\t\tvar jin = FastScanner()\r\n\t\tvar pw = PrintWriter(System.out)\r\n\t}\r\n}\r\nfun put(aa:Any){ reading.pw.println(aa)}\r\nfun done(){ reading.pw.close() }\r\n\r\nfun getint():Int{ return reading.jin.nextInt() }\r\nfun getlong():Long{ return reading.jin.nextLong() }\r\nfun getline(n:Int):List{ return (1..n).map{reading.jin.nextInt()} }\r\nfun getlineL(n:Int):List{return (1..n).map{reading.jin.nextLong()} }\r\nfun getstr():String{ return reading.jin.nextString() }\r\nfun MutableList.streamint(n:Int){ repeat(n){this.add(getint())}}\r\nfun MutableList.streamlong(n:Int){ repeat(n){this.add(getlong())}}\r\ninline fun cases(ask:()->Unit){ val t = getint();repeat(t){ ask() }}\r\n\r\nval List.ret:String\r\n\tget() = this.joinToString(\"\")\r\ninfix fun Any.dei(a:Any){\r\n\t//does not stand for anything it is just easy to type\r\n\tvar str = \"\"\r\n\tif(this is String){ str = this\r\n\t}else if(this is Int){ str = this.toString()\r\n\t}else if(this is Long){ str = this.toString()\r\n\t}\r\n\tif(a is List<*>){ println(\"$str : ${a.joinToString(\" \")}\")\r\n\t}else if(a is IntArray){ println(\"$str : ${a.joinToString(\" \")}\")\r\n\t}else if(a is LongArray){ println(\"$str : ${a.joinToString(\" \")}\")\r\n\t}else{ println(\"$str : $a\")\r\n\t}\r\n}\r\nval just = \" \" // usage: just dei x , where x is the debug variable\r\n\r\nfun main() {\r\n\tval n = getint()\r\n\tval m = getint()\r\n\tval maze = mutableListOf()\r\n\trepeat(n){\r\n\t\tmaze.add(getstr().map{if(it == '*') 1 else 0}.toIntArray())\r\n\t}\r\n\r\n\tvar x = 0\r\n\tvar y = 0\r\n\tvar ret = 0\r\n\tif(maze[0][0] ==1){\r\n\t\tret += 1\r\n\t}\r\n\r\n\tdone@while(x < 4 || y < 4){\r\n\t\tfor(s in 1..8){\r\n\t\t\tfor(dx in 0..4){\r\n\t\t\t\tval dy = s - dx\r\n\t\t\t\tif(dx < 0 || dy <0){\r\n\t\t\t\t\tcontinue\r\n\t\t\t\t}\r\n\t\t\t\tval xx = x + dx\r\n\t\t\t\tval yy = y + dy\r\n\t\t\t\tif(xx >= n || yy >= m){\r\n\t\t\t\t\tcontinue\r\n\t\t\t\t}\r\n\t\t\t\tif(maze[xx][yy] == 1){\r\n\t\t\t\t\tx = xx\r\n\t\t\t\t\ty = yy\r\n\t\t\t\t\tret += 1\r\n\t\t\t\t\tcontinue@done\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tbreak\r\n\t}\r\n\tput(ret)\r\n\tdone()\r\n\r\n\r\n // Write your solution here\r\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation", "shortest paths"], "code_uid": "8348bf9a498ee0d66412d7a0fe168521", "src_uid": "f985d7a6e7650a9b855a4cef26fd9b0d", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main(args: Array) {\n val (R,C) = readLine()!!.split(\" \").map(String::toInt)\n val A = (0 until R).map { readLine()!! }\n var r = 0\n var c = 0\n var ans = if (A[0][0] == '*') 1 else 0\n while (r != R-1 || c != C-1) {\n if (r == R-1) {\n c++\n } else if (c == C-1) {\n r++\n } else if (A[r][c+1] == '*') {\n c++\n } else if (A[r+1][c] == '*') {\n r++\n } else {\n c++\n }\n if (A[r][c] == '*') ans++\n }\n\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation", "shortest paths"], "code_uid": "f41df8d04b88312728eed9dcd2367a1a", "src_uid": "f985d7a6e7650a9b855a4cef26fd9b0d", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "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 readInts() = inf.readLine()!!.split(' ').map(String::toInt)\nfun readLongs() = inf.readLine()!!.split(' ').map(String::toLong)\nfun readString() = inf.readLine()!!\n\nfun main() {\n val (h, w) = readInts()\n val a = Array(h) {\n readString().map { it == '*' }.toBooleanArray()\n }\n var x = 0\n var y = 0\n var ans = if (a[0][0]) 1 else 0\n while (x < h - 1 || y < w - 1) {\n when {\n y < w - 1 && a[x][y + 1] -> y++\n x < h - 1 && a[x + 1][y] -> x++\n y < w - 1 -> y++\n else -> x++\n }\n if (a[x][y]) ans++\n }\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation", "shortest paths"], "code_uid": "4792b11f1d3cddf0198f50f7c7227dc2", "src_uid": "f985d7a6e7650a9b855a4cef26fd9b0d", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main() {\r\n val (h, w) = readLine()!!.split(' ').map { it.toInt() }\r\n val cake = List(h) { readLine()!!.map { it == '*' } }\r\n var i = 0\r\n var j = 0\r\n var ans = 0\r\n while (i + 1 < h || j + 1 < w){\r\n ans += if (cake[i][j]) 1 else 0\r\n if (i + 1 == h) {\r\n j++\r\n } else {\r\n if (j + 1 == w) {\r\n i++\r\n } else {\r\n if (cake[i + 1][j]) i++ else j++\r\n }\r\n }\r\n }\r\n println(ans + if (cake[i][j]) 1 else 0)\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation", "shortest paths"], "code_uid": "3803cad299e07ba8aaf6658f24cb67d1", "src_uid": "f985d7a6e7650a9b855a4cef26fd9b0d", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 pos = charArrayOf('R', 'B', 'Y', 'G').map { s.indexOf(it) % 4 }\n val cnt = Array(4, {0})\n for ((i,c) in s.withIndex())\n if (c == '!')\n cnt[i%4]++\n for (i in 0..3)\n for (j in 0..3)\n if (pos[i] == j)\n fout.print(\"${cnt[j]} \")\n\n fout.close()\n fin.close()\n}\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "number theory"], "code_uid": "2898a3f521a6449b9934e883095c5a09", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 s: String = ir.next()\n val k = IntArray(4)\n val c1 = IntArray(4)\n val c2 = CharArray(4)\n\n for (i in 0 until s.length)\n if (s[i] == '!')\n c1[i % 4]++\n else\n c2[i % 4] = s[i]\n\n for (i in 0..3)\n when (c2[i]) {\n 'R' -> k[0] = c1[i]\n 'B' -> k[1] = c1[i]\n 'Y' -> k[2] = c1[i]\n else -> k[3] = c1[i]\n }\n\n for (i in 0..3)\n pw.print(\" ${k[i]}\")\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "number theory"], "code_uid": "6c0412dd29e732cc217b4f3e30181549", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val s = readLine()!!\n\n val kColor = Array(4) { 0 }\n (0..s.length - 1).filter { s[it] == '!' }.forEach { kColor[it % 4]++ }\n\n val rIndex = s.indexOf('R') % 4\n val bIndex = s.indexOf('B') % 4\n val yIndex = s.indexOf('Y') % 4\n val gIndex = s.indexOf('G') % 4\n\n println(\"${kColor[rIndex]} ${kColor[bIndex]} ${kColor[yIndex]} ${kColor[gIndex]}\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "number theory"], "code_uid": "a86fa113bf5e7640e808a8d878c3b862", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val text = readLine()!!\n val deads = intArrayOf(0, 0, 0, 0)\n val rbyg = intArrayOf(0, 0, 0, 0)\n text.forEachIndexed { index, char ->\n when (char) {\n 'R' -> rbyg[0] = index % 4\n 'B' -> rbyg[1] = index % 4\n 'Y' -> rbyg[2] = index % 4\n 'G' -> rbyg[3] = index % 4\n '!' -> deads[index % 4]++\n }\n }\n print(\"${deads[rbyg[0]]} ${deads[rbyg[1]]} ${deads[rbyg[2]]} ${deads[rbyg[3]]}\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "number theory"], "code_uid": "df2bc6f6b70494721ed53404907fc329", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["two pointers", "brute force"], "code_uid": "2bb6612263f60440db9bf2f40871e571", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["two pointers", "brute force"], "code_uid": "a36a3b76d3e9527a8eac4395d6526b15", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["two pointers", "brute force"], "code_uid": "e59d07d251725140b05eda40c941b307", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["two pointers", "brute force"], "code_uid": "b941c21ab51e59538d40785ff0c9b3d7", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 ", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "0357cce7a366cdc731f319919974ac73", "src_uid": "df0879635b59e141c839d9599abd77d2", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "253963952749ee554d5bbcc3400ef7fa", "src_uid": "df0879635b59e141c839d9599abd77d2", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "58e88f284c660629bfd19154e7a0b5c4", "src_uid": "df0879635b59e141c839d9599abd77d2", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "0f84cc4009f6dcf4174fdfcb81102529", "src_uid": "df0879635b59e141c839d9599abd77d2", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7001b7f9d665d26afcf68ee23ea21644", "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2334cad8c610fa15ea2f843d58e8df8b", "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "28682d017a28ae411d75389268e2a3c3", "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2fc751937f0ad3201d3bd437e735ae90", "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\n\nfun main() = bufferOut { readSolveWrite() }\n\nprivate const val MOD = 1000_000_007\n\nprivate val dp = IntArray(2001 * 2001 * 2) { -1 }\n\nfun compute(b: Int, r: Int, u: Int): Int {\n if (b < 0 || b > r || r == 0) return 0\n val index = (b * 2001 + r) * 2 + u\n dp[index].let { if (it >= 0) return it }\n var res = (compute(b + 1, r - 1, 0) + compute(b - 1, r - 1, 0)) % MOD\n if (u == 0) {\n if (b < r)\n res = modMax(res, (1 + compute(b + 1, r - 1, 1) + compute(b - 1, r - 1, 0)) % MOD)\n if (b > 0)\n res = modMax(res, (1 + compute(b + 1, r - 1, 0) + compute(b - 1, r - 1, 1)) % MOD)\n }\n dp[index] = res\n return res\n}\n\nfun modMax(a: Int, b: Int): Int =\n if ((a - b + MOD) % MOD < MOD / 2) a else b\n\nprivate fun PrintWriter.readSolveWrite() {\n val n = readLine()!!.toInt()\n println(compute(0, 2 * n, 0))\n}\n\nprivate fun bufferOut(block: PrintWriter.() -> Unit) = PrintWriter(System.out).use { block(it) }\n", "lang_cluster": "Kotlin", "tags": ["greedy", "dp", "trees"], "code_uid": "822bd1012b49fceee7df37220793bd6d", "src_uid": "8218255989e5eab73ac7107072c3b2af", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main () {\n val scanner = Scanner(System.`in`)\n val prevPrev = scanner.nextInt()\n val prev = scanner.nextInt()\n\n val message = when (scanner.nextInt() % 6 ) {\n 1 -> prevPrev\n 2 -> prev\n 3 -> prev - prevPrev\n 4 -> -prevPrev\n 5 -> -prev\n else -> prevPrev - prev\n }\n println(\n Math.floorMod(message, 1000000007)\n )\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "6d7e3cff12a8b603249b58f058a7fbc3", "src_uid": "2ff85140e3f19c90e587ce459d64338b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n var (x, y) = r.readLine()!!.split(\" \").map { it.toLong() }\n val n = r.readLine()!!.toInt()\n var ans = when (n % 6) {\n 2 -> y\n 3 -> y - x\n 4 -> -x\n 5 -> -y\n 0 -> x - y\n else -> x\n }\n while (ans<0) ans+=1000000007\n println(ans%1000000007)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "7fc114ef8d054e6f56fa3a8065f5322e", "src_uid": "2ff85140e3f19c90e587ce459d64338b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 (f1, f2) = readLongs()\n var goal = readLong()\n if (goal == 1L) {\n print(Math.floorMod(f1, 1000000007))\n return\n }\n if (goal == 2L) {\n print(Math.floorMod(f2, 1000000007))\n return\n }\n var currentPos = 1L\n var previous = f1\n var current = f2\n while (++currentPos < goal) {\n val new = current - previous\n previous = current\n current = new\n if(previous == f1 && current == f2) {\n val cycle = currentPos - 1\n goal = (goal - 2) % cycle + 2\n currentPos = 1\n }\n }\n print(Math.floorMod(current, 1000000007))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "648606342037ceb82d4c1c46b7b007d2", "src_uid": "2ff85140e3f19c90e587ce459d64338b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "const val M = 1000000007\nfun main(args: Array) {\n val (x,y) = readLine()!!.split(' ').take(2).map{it.toLong()}\n val n = readLine()!!.toLong()\n val nums= arrayOf((x-y)%M,x,y)\n val (div,mod)=(n/3L) to (n%3L)\n val sign = -1L*((div%2L)*2L-1L)\n val ans = nums[mod.toInt()]*sign\n println(if (ans<0) M+ans else ans)\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "c592e8144316b4afa22c0e972e4258a7", "src_uid": "2ff85140e3f19c90e587ce459d64338b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var n = readLine()!!.toLong()\n var sol = n\n while (n > 1) {\n if (n % 2 == 0L) {\n n /= 2\n sol += n\n } else\n for (candidate in 3..n step 2)\n if (n % candidate == 0L) {\n n /= candidate\n sol += n\n break\n }\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["number theory"], "code_uid": "fba24ebf035f25c44da3f04197ab7857", "src_uid": "821c0e3b5fad197a47878bba5e520b6e", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\n\nval sc = java.util.Scanner(System.`in`)\nfun main(args: Array) {\n\tval n = sc.nextInt()\n\tval a = Array(2 * n) { sc.nextInt() }\n\ta.sort()\n\tvar ans = Int.MAX_VALUE\n\tfor (i in 0 until 2 * n)\n\t\tfor (j in i + 1 until 2 * n) {\n\t\t\tvar res = 0\n\t\t\tvar last = 0\n\t\t\tfor (k in 0 until 2 * n)\n\t\t\t\tif (k != i && k != j)\n\t\t\t\t\tif (last == 0)\n\t\t\t\t\t\tlast = a[k]\n\t\t\t\t\telse {\n\t\t\t\t\t\tres += a[k] - last\n\t\t\t\t\t\tlast = 0\n\t\t\t\t\t}\n\t\t\tans = min(ans, res)\n\t\t}\n\tprintln(ans)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "sortings", "greedy"], "code_uid": "dc424b0edc956770f66a2ec5c85496a2", "src_uid": "76659c0b7134416452585c391daadb16", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "40e7f6e09f8528085cf1f57fb37999fc", "src_uid": "4c4852df62fccb0a19ad8bc41145de61", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "ef8750495eb661032ad27ab49b893379", "src_uid": "4c4852df62fccb0a19ad8bc41145de61", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "0af208d1c3c16b4b64efcde1addc4faf", "src_uid": "4c4852df62fccb0a19ad8bc41145de61", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "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\nfun main() = P1651A.solve()\n\nobject P1651A {\n\n\n fun solve() {\n (1..readInt()).forEach {\n val n = readInt()\n println((1 shl n)-1)\n }\n }\n\n}\n\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "f5ef24f3bbbb2c0c87d8214bb2456b79", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "import java.lang.Math.pow\r\n\r\nfun main() {\r\n var t = readln().toInt()\r\n while (t-- > 0) {\r\n val n = readln().toDouble()\r\n println(pow(2.0, n).toInt() - 1)\r\n }\r\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "3bc197fa7b0c95dcdf75488bb8525303", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.5", "source_code": "fun main(args: Array) {\r\n var t:Int =Integer.valueOf(readLine())\r\n \r\n for ( i in 1..t)\r\n {\r\n var n :Int = Integer.valueOf(readLine())\r\n if (n == 1)\r\n {\r\n println(1)\r\n }\r\n else \r\n {\r\n var x = Math.pow( 2.0,n.toDouble())\r\n var l = x.toInt()\r\n println(l-1)\r\n }\r\n }\r\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "b04442167b7eaca07a0d6a46c62559e2", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.5", "source_code": "import kotlin.math.*\r\nimport java.util.*\r\nimport java.lang.*\r\nprivate fun readInt() = readLine()!!.toInt()\r\nprivate fun readInts() = readLine()!!.split(\" \").map { it.toInt() }\r\nval maxn = 100000 + 10\r\nval inf = 0x3f3f3f3f\r\nfun main(args: Array) {\r\n\tvar t: Int = readInt()\r\n\twhile (t-- > 0) {\r\n\t\tvar n: Int = readInt()\r\n\t\tprintln((1 shl n) - 1)\r\n\t}\r\n}\r\n/*\r\n7\r\n1 1 1 4 4 6 6\r\n5\r\n2 2 3 3 5\r\n3\r\n1 1 4\r\n5\r\n3 3 5 5 5\r\n */\r\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "da41d98a2bc3e179d1c6c73c21d5aca4", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = readInt()\n val x = readInt()\n val pos = readInt()\n\n var ans = ModInt(1)\n val inv = modInvArray(n+1) { ModInt(it) }\n\n var lt = x-1\n var gt = n-x\n var rem = n\n\n var left = 0\n var right = n\n\n while(left < right) {\n val mid = (left + right) / 2\n when {\n mid == pos -> {\n ans *= inv[rem--]\n left = mid+1\n }\n mid > pos -> {\n ans *= gt-- * inv[rem--]\n right = mid\n }\n else -> {\n ans *= lt-- * inv[rem--]\n left = mid+1\n }\n }\n }\n\n for(i in 2..n) ans *= i\n\n println(ans.int)\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\n/** Extras */\n\n/**\n * Returns a new array of the modular inverses of each value in the original array. All values must be non-zero.\n * The values of the original array will not be changed. Takes O(3n + log(M)) multiplications vs O(n log(M)).\n */\nfun ModIntArray.inverseOfEach(): ModIntArray {\n if(isEmpty()) return this\n var acc = ModInt(1)\n val res = ModIntArray(size) { i ->\n acc *= this[i]\n acc\n }\n acc = acc.inv_unmemoized()\n for(i in lastIndex downTo 1) {\n res[i] = acc * res[i-1]\n acc *= this[i]\n }\n res[0] = acc\n\n return res\n}\n\n// creates an array where res[i] == gen(i).inverse() . Any zeros the generator produces will be changed to 1.\ninline fun modInvArray(size: Int, gen: (Int) -> ModInt) = ModIntArray(size) {\n val a = gen(it)\n if(a.int != 0) a else ModInt(1)\n}.inverseOfEach()\n\n\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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { 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 }", "lang_cluster": "Kotlin", "tags": ["binary search", "combinatorics"], "code_uid": "ce49ccab60675f5dcd98b60f03a6a7c2", "src_uid": "24e2f10463f440affccc2755f4462d8a", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n\tval (n, x, pos) = readInts()\n\tvar (lower, higher) = x-1 to n-x\n\tval arr = LongArray(n) { it+1L }\n\tvar left = 0\n\tvar right = arr.size\n\tvar res = 1L\n\twhile (left < right) {\n\t\tval middle = (left + right) / 2\n\t\tif (arr[middle] <= pos+1) {\n\t\t\tleft = middle + 1\n\t\t\tif (arr[middle] < pos+1) res *= lower--\n\t\t}\n\t\telse if(arr[middle] > pos+1) {\n\t\t\tright = middle\n\t\t\tres *= higher--\n\t\t}\n\t\tres %= (1_000_000_000+7)\n\t}\n\tfor (i in 1..lower+higher) {\n\t\tres *= i\n\t\tres %= (1_000_000_000+7)\n\t}\n\tprintln(res)\n}\n\nfun readInts() = readLine()!!.split(' ').map { it.toInt() }", "lang_cluster": "Kotlin", "tags": ["binary search", "combinatorics"], "code_uid": "dc4400ca0b0a8eb606e56aca26ec8dfc", "src_uid": "24e2f10463f440affccc2755f4462d8a", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = readInt()\n val x = readInt()\n val pos = readInt()\n\n var ans = ModInt(1)\n\n var lt = x-1\n var gt = n-x\n var rem = n\n\n var left = 0\n var right = n\n\n while(left < right) {\n val mid = (left + right) / 2\n when {\n mid == pos -> {\n left = mid+1\n }\n mid > pos -> {\n ans *= gt--\n right = mid\n }\n else -> {\n ans *= lt--\n left = mid+1\n }\n }\n rem--\n }\n\n for(i in 2..rem) ans *= i\n\n println(ans.int)\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_unmemoized() /** 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\n/** Extras */\n\n/**\n * Returns a new array of the modular inverses of each value in the original array. All values must be non-zero.\n * The values of the original array will not be changed. Takes O(3n + log(M)) multiplications vs O(n log(M)).\n */\nfun ModIntArray.inverseOfEach(): ModIntArray {\n if(isEmpty()) return this\n var acc = ModInt(1)\n val res = ModIntArray(size) { i ->\n acc *= this[i]\n acc\n }\n acc = acc.inv_unmemoized()\n for(i in lastIndex downTo 1) {\n res[i] = acc * res[i-1]\n acc *= this[i]\n }\n res[0] = acc\n\n return res\n}\n\n// creates an array where res[i] == gen(i).inverse() . Any zeros the generator produces will be changed to 1.\ninline fun modInvArray(size: Int, gen: (Int) -> ModInt) = ModIntArray(size) {\n val a = gen(it)\n if(a.int != 0) a else ModInt(1)\n}.inverseOfEach()\n\n\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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { 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 }", "lang_cluster": "Kotlin", "tags": ["binary search", "combinatorics"], "code_uid": "ff8b382ab5029281e2423ac4085eec0a", "src_uid": "24e2f10463f440affccc2755f4462d8a", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "const val MOD = 1000000007L\n\nfun main() {\n val (n, x, index) = readLine()!!.split(\" \").map { it.toInt() }\n var above = 0\n var below = 0\n var left = 0\n var right = n\n while (left < right) {\n val middle = (left + right) / 2\n if (middle < index) {\n below++\n } else if (middle > index) {\n above++\n }\n if (middle <= index) {\n left = middle + 1\n } else {\n right = middle\n }\n }\n var answer = 1L\n for (j in 0 until above) {\n answer *= (n - x - j).toLong()\n answer %= MOD\n }\n for (j in 0 until below) {\n answer *= (x - 1 - j).toLong()\n answer %= MOD\n }\n for (j in 1..n - above - below - 1) {\n answer *= j.toLong()\n answer %= MOD\n }\n println(answer)\n}", "lang_cluster": "Kotlin", "tags": ["binary search", "combinatorics"], "code_uid": "071611250da3d4efd024a562da720109", "src_uid": "24e2f10463f440affccc2755f4462d8a", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 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 val (r1, c1, r2, c2) = br.readLine().split(' ').map(String::toInt)\n val rook :Int; val bishop :Int; val king :Int\n\n if (r1 == r2 && c1 == c2) rook = 0\n else if (r1 == r2 || c1 == c2) rook = 1\n else rook = 2\n\n if (r1 == r2 && c1 == c2) bishop = 0\n else if ((Math.abs(r1-r2).isOdd() && Math.abs(c1-c2).isEven())\n || (Math.abs(r1-r2).isEven() && Math.abs(c1-c2).isOdd())) bishop = 0\n else if (Math.abs(r1-r2) == Math.abs(c1-c2)) bishop = 1\n else bishop = 2\n\n if (r1 == r2 && c1 == c2) king = 0\n else king = max(Math.abs(r1-r2), Math.abs(c1-c2))\n\n bw.write(\"$rook $bishop $king\\n\")\n bw.close()\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "graphs", "shortest paths"], "code_uid": "19613289a441b4bfee2b6369d4d9211d", "src_uid": "7dbf58806db185f0fe70c00b60973f4b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\nimport kotlin.math.max\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (r1, c1, r2, c2) = readInts()\n print(if (r1 == r2 || c1 == c2) \"1 \" else \"2 \")\n val deltaRows = abs(r1 - r2)\n val deltaCols = abs(c1 - c2)\n print(when {\n deltaRows == deltaCols -> \"1 \"\n deltaRows and 1 == deltaCols and 1 -> \"2 \"\n else -> \"0 \"\n })\n print(max(deltaRows, deltaCols))\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "graphs", "shortest paths"], "code_uid": "9afe1507dbb201a013230a67c658c84f", "src_uid": "7dbf58806db185f0fe70c00b60973f4b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : InputReader, pw : PrintWriter) {\n\n val r1 : Int = ir.nextInt()\n val c1 : Int = ir.nextInt()\n val r2 : Int = ir.nextInt()\n val c2 : Int = ir.nextInt()\n val dis1 : Int = Math.abs(r1 - r2)\n val dis2 : Int = Math.abs(c1 - c2)\n val rest : Int = Math.abs(dis1 - dis2)\n\n if (r1 != r2 && c1 != c2)\n pw.print(\"2 \")\n else if (r1 != r2 || c1 != c2)\n pw.print(\"1 \")\n else\n pw.print(\"0 \")\n\n if (dis1 % 2 == dis2 % 2) {\n when {\n dis1 != dis2 -> pw.print(\"2 \")\n else -> pw.print(\"1 \")\n }\n } else\n pw.print(\"0 \")\n\n if (dis1 >= dis2)\n pw.print(\"${dis2 + rest}\")\n else\n pw.print(\"${dis1 + rest}\")\n\n}\n\nclass InputReader(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}", "lang_cluster": "Kotlin", "tags": ["math", "graphs", "shortest paths"], "code_uid": "0f2349a7ed297b415f9ff15c43beb107", "src_uid": "7dbf58806db185f0fe70c00b60973f4b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\n val n = sc.nextInt()\n repeat(n) {\n val x = sc.nextInt()\n\n for (i in 0..x) {\n if (i * 3 > x) {\n println(\"NO\")\n break\n }\n if ((x - i * 3) % 7 == 0) {\n println(\"YES\")\n break\n }\n }\n\n }\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", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "302ac02804c903373e141c203925fc77", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var t = readLine()!!.toInt()\n\n for(i in 1..t) {\n var x = readLine()!!.toInt()\n var possible = false\n\n for(j in 0..x) {\n if((x - 3 * j) % 7 == 0 && x >= 3 * j) possible = true\n if((x - 7 * j) % 3 == 0 && x >= 7 * j) possible = true\n }\n\n println(if (possible) \"YES\" else \"NO\")\n }\n}\n\n", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "7808f3d7233d1c620cceab5512cbcb68", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n var x: Int\n for (i in 1..n) {\n x = readLine()!!.toInt()\n if (x < 3 || x == 4 || x == 5 || x == 8 || x == 11) {\n println(\"NO\")\n } else {\n println(\"YES\")\n }\n }\n }", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "0bd70b042d701b5a41773216350b9f47", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val numCases = readInt()\n val sols = BooleanArray(numCases)\n for (numCase in 0 until numCases) {\n val n = readInt()\n for (b in 0 .. n / 7)\n if ((n - 7 * b) % 3 == 0) {\n sols[numCase] = true\n break\n }\n }\n\n print(sols.joinToString(System.lineSeparator()) { b -> if (b) \"YES\" else \"NO\" })\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "cdbedd1d9197048382c85b40fe8d429a", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c2817cffd59c411d76ac757f09b44b87", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "75c0b8a55461ea6f568c85580ea9b1a1", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "binary search"], "code_uid": "0caf854d1828805454b6c37b95186250", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "binary search"], "code_uid": "3f8d7ab3b0bcf1173a04a0f65540cd63", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "binary search"], "code_uid": "b4df1c06ea1eb17d28ae89e733ffe97e", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "binary search"], "code_uid": "af2282f00b72d1784b051ca73594f0a3", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport kotlin.math.sqrt\n\nfun prime (n: Int): Boolean {\n if (n == 1 || n == 2 || n == 3) return true\n else {\n var isPrime = true\n var i = 2\n while (i <= sqrt(n.toFloat()).toInt() && isPrime) {\n if (n % i == 0) {\n isPrime = false\n } else {\n i++\n }\n }\n return isPrime\n }\n}\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val (n, m) = br.readLine().split(\" \").map { it.toInt() }\n if (!prime(m)){\n println(\"NO\")\n } else {\n for (i in n + 1 .. m) {\n if (prime(i)){\n println(if (i == m) \"YES\" else \"NO\")\n break\n }\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "3428285534dd992a409411d11b401392", "src_uid": "9d52ff51d747bb59aa463b6358258865", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args : Array) {\n\n val (a, b) = readLine()!!.split(' ')\n var n = a.toInt()\n var m = b.toInt()\n var x = 0\n for(i in n+1..m){\n if(checkPrime(i)==1){\n x = i\n break\n }\n }\n\n if(x==m){\n println(\"YES\")\n }\n else{\n println(\"NO\")\n }\n}\n\nfun checkPrime(n: Int):Int{\n var a = 0\n for(i in 2..n/2) {\n if (n % i==0) {\n a++\n }\n }\n if(a==0) return 1\n else return 0\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "7a9767ed89198a1e72a5dd8c32a79bbe", "src_uid": "9d52ff51d747bb59aa463b6358258865", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 for (i in n + 1..m) {\n if (prime(i)) {\n if (i == m)\n println(\"YES\")\n else println(\"NO\")\n return\n }\n if(i==m)\n println(\"NO\")\n }\n}\n\nfun prime(a: Int): Boolean {\n for (i in 2 until a) {\n if (a % i == 0) return false\n }\n return true\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "971dad44d91f9887830c04a95f04bd12", "src_uid": "9d52ff51d747bb59aa463b6358258865", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * Created by denis on 18.06.17.\n */\nfun main(args: Array){\n val (x1, y1, x2, y2) = readLine()!!.split(' ').map(String::toInt)\n val (x, y) = readLine()!!.split(' ').map(String::toInt)\n val x_r:Int\n x_r = x1 + x\n val x_l: Int = x1 - x\n val y_r: Int = y1 + y\n val y_l: Int = y1 - y\n\n if (!(((Math.abs(x2-x1) % x == 0) && (Math.abs(y2-y1) % y == 0)))) print(\"NO\")\n else {\n if(((Math.abs(x1-x2) / x) % 2 ==(Math.abs(y1-y2) / y) % 2)) print(\"YES\")\n else print(\"NO\")\n }\n\n }\n\n\n\n\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "e8805816dff2016c31826801840f72ab", "src_uid": "1c80040104e06c9f24abfcfe654a851f", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.File\nimport java.io.InputStream\nimport java.util.*\n\nfun check(x: Int, y: Int, a: Int, b: Int)\n = x % (2 * a) == 0 && y % (2 * b) == 0\n\nfun solve(inp: InputReader) {\n var (x1, y1, x2, y2) = inp.nextLine().split(\" \").map(String::toInt)\n val (a, b) = inp.nextLine().split(\" \").map(String::toInt)\n x2 -= x1\n y2 -= y1\n if (check(x2, y2, a, b) || check(x2 - a, y2 - b, a, b)) {\n println(\"YES\")\n } else {\n println(\"NO\")\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", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "2840fd3fa4edc286289b60e5a7cd251a", "src_uid": "1c80040104e06c9f24abfcfe654a851f", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport kotlin.math.abs\n\ndata class Vector(val x: Int, val y: Int){\n\n fun sum(that: Vector): Vector =\n Vector(x + that.x, y + that.y)\n\n fun mult(n: Int): Vector =\n Vector(x * n, y * n)\n\n fun isProportional(that: Vector): Boolean =\n x % that.x == 0 && y % that.y == 0\n\n}\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val vectors = br.readLine().split(\" \").map { it.toInt() }\n val displacement = br.readLine().split(\" \").map { it.toInt() }\n\n val v = Vector(vectors[0], vectors[1])\n val t = Vector(vectors[2], vectors[3])\n val u = Vector(displacement[0], displacement[1])\n val vt = v.sum(t.mult(-1))\n val w = Vector((vt.x)/u.x, vt.y/u.y)\n\n if (vt.isProportional(u) && (abs(w.x) % 2 == abs(w.y) % 2)){\n println(\"YES\")\n }else{\n println(\"NO\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "bfea09b25befa11ebbc2066fcd1385f0", "src_uid": "1c80040104e06c9f24abfcfe654a851f", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": " import java.lang.Math.max\n import java.util.*\n\n //most of data types after intilize the value write the first char of the type\n //e.x\n fun main(args:Array){\n val inn = Scanner(System.`in`)\n val x=inn.nextInt()\n val y=inn.nextInt()\n val x1=inn.nextInt()\n val y1=inn.nextInt()\n var w=x-x1\n if (w < 0) {\n w = 0 - w\n }\n var q = y - y1\n if (q < 0) {\n q = 0 - q\n }\n val z = max(w, q)\n println(z)\n }\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "696598c8980e759704caeb8c847b82f7", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\nimport kotlin.math.max\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (x1, y1) = readInts()\n val (x2, y2) = readInts()\n print(max(abs(x1 - x2), abs(y1 - y2)))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "7a64a6e8f468e9a03f33e7e73251ccb0", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.lang.Math.*\nimport java.math.BigInteger\nimport java.util.*\nimport kotlin.collections.ArrayList\n\ntypealias IndexPair = Pair\ntypealias IntIndexPair = IndexPair\ntypealias IntIntPair = Pair\n\ntypealias IntMatrix = Array\ntypealias LongMatrix = Array\n\ntypealias ListArray = Array>\n\ntypealias Graph = IntMatrix\n\ntypealias Edge = Pair\ntypealias EdgeArray = Array\ntypealias WeightedGraph = Array\n\ntypealias TotalEdge = Triple\ntypealias TotalEdgeArray = Array\n\nfun init() { }\n\nconst val MODULO = 1000 * 1000 * 1000 + 7\n\nfun solve() {\n val (x1, y1) = readLongs()\n val (x2, y2) = readLongs()\n \n val dx = abs(x1 - x2)\n val dy = abs(y1 - y2)\n \n val result = max(dx, dy)\n out.println(result)\n}\n\nfun stress() {\n val rnd = Random(1234)\n\n for (it in 0 until 100) {\n val expected = brute()\n val actual = fast()\n\n if (expected != actual) {\n System.err.println(\"Gotcha!\")\n System.err.println(\"$expected $actual\")\n\n break\n }\n }\n}\n\n\nfun fast() {\n\n}\n\nfun brute() {\n \n}\n\nfun Long.mod() : Long {\n var result = this % MODULO\n if (result < 0) result += MODULO\n return result\n}\n\ninfix fun Long.add(other : Long) = (this + other).mod()\ninfix fun Long.sub(other : Long) = this add -other.mod()\ninfix fun Long.mult(other : Long) = (this.mod() * other.mod()).mod()\n\nfun Long.even() = (this and 1L) == 0L\nfun Long.odd() = !even()\n\nfun Int.even() = (this and 1) == 0\nfun Int.odd() = !even()\n\ninfix fun Long.binpow(power : Long) : Long {\n if (power == 0L) return 1L\n\n val half = binpow(power shl 1)\n\n var result = half mult half\n if (power.odd()) {\n result = result mult this\n }\n\n return result\n}\n\nval stepsXY = arrayOf(\n arrayOf(0, -1),\n arrayOf(0, 1),\n arrayOf(-1, 0),\n arrayOf(1, 0)\n)\n\n\n\nclass IndexedWeightedGraph(private val n : Int, private val edges: TotalEdgeArray) {\n\n private val graph : Graph\n\n private fun buildGraphForEdges(\n edgeFilter : (index : Int, edge : TotalEdge) -> Boolean = { _, _ -> true }\n ) : Graph {\n val builder = GraphBuilder()\n edges\n .forEachIndexed { index, edge ->\n if (edgeFilter(index, edge)) {\n val (first, second, _ ) = edge\n\n builder.addDirectedEdge(first, index)\n builder.addDirectedEdge(second, index)\n }\n }\n\n return builder.build(n)\n }\n\n init {\n graph = buildGraphForEdges()\n }\n\n var root : Int = -1\n lateinit var inTree : BooleanArray\n lateinit var tree : Graph\n\n fun kruskalTree(root : Int) : Long {\n this.root = root\n\n inTree = BooleanArray(edges.size) { false }\n\n val dsu = DSU(n)\n\n edges\n .mapIndexed { index, (_, _, w) -> index to w }\n .sortedBy { it.second }\n .forEach {\n val edge = edges[it.first]\n inTree[it.first] = dsu.union(edge.first, edge.second)\n }\n\n tree = buildGraphForEdges { index, _ -> inTree[index] }\n\n return edges\n .mapIndexed { index, (_, _, w) -> if (inTree[index]) w.toLong() else 0L }\n .sum()\n }\n\n private fun to(from : Int, index : Int) : Int {\n val edge = edges[index]\n return if (from == edge.first) edge.second else edge.first\n }\n\n fun buildLca() {\n calculateTimes()\n calculateParents()\n calculatePathInfo()\n }\n\n lateinit var timesIn : IntArray\n lateinit var timesOut : IntArray\n private var time = -1\n\n private fun calculateTimes() {\n timesIn = IntArray(n) { -1 }\n timesOut = IntArray(n) { -1 }\n this.time = 0\n\n timeDfs(root)\n }\n\n private fun timeDfs(from : Int, parent : Int = -1) {\n timesIn[from] = time++\n\n for (index in tree[from]) {\n val to = to(from, index)\n if (to == parent) continue\n\n timeDfs(to, from)\n }\n\n timesOut[from] = time++\n }\n\n lateinit var parents : Array\n private val maxBit = 19\n\n private fun calculateParents() {\n parents = Array(maxBit) { IntArray(n) { -1 } }\n\n parentDfs(root, root)\n\n for (bit in 0 until maxBit - 1) {\n for (v in 0 until n) {\n val parent = parents[bit][v]\n parents[bit + 1][v] = parents[bit][parent]\n }\n }\n }\n\n private fun parentDfs(from : Int, parent : Int = -1) {\n parents[0][from] = parent\n\n for (index in tree[from]) {\n val to = to(from, index)\n if (to == parent) continue\n\n parentDfs(to, from)\n }\n }\n\n lateinit var maxEdges : Array\n\n private fun calculatePathInfo() {\n maxEdges = Array(maxBit) { IntArray(n) { -1 } }\n\n for (v in 0 until n){\n for (index in tree[v]) {\n val to = to(v, index)\n if (to == parents[0][v]) continue\n\n maxEdges[0][to] = edges[index].third\n }\n }\n\n for (bit in 0 until maxBit - 1) {\n for (v in 0 until n) {\n val parent = parents[bit][v]\n maxEdges[bit + 1][v] = max(\n maxEdges[bit][v],\n maxEdges[bit][parent]\n )\n }\n }\n }\n\n fun getOnPath(a : Int, b : Int) : Int {\n var answer = Int.MIN_VALUE\n\n answer = max(answer, getOnLcaPath(a, b))\n answer = max(answer, getOnLcaPath(b, a))\n\n return answer\n }\n\n private fun getOnLcaPath(start : Int, other : Int) : Int {\n var answer = Int.MIN_VALUE\n\n if (timesIn[start] <= timesIn[other] && timesOut[other] <= timesOut[start]) {\n return answer\n }\n\n var v = start\n for (bit in maxBit - 1 downTo 0) {\n val parent = parents[bit][v]\n if (timesIn[parent] > timesIn[other] || timesOut[other] > timesOut[parent]) {\n answer = max(answer, maxEdges[bit][v])\n v = parent\n }\n }\n\n answer = max(answer, maxEdges[0][v])\n\n return answer\n }\n}\n\nfun yesNo(yes : Boolean) {\n out.println(if (yes) \"YES\" else \"NO\")\n}\n\nfun run() {\n init()\n solve()\n out.close()\n}\n\nfun main(args: Array) {\n run()\n}\n\nval ONLINE_JUDGE = !File(\"input.txt\").exists()\n\nval input = BufferedReader(\n if (ONLINE_JUDGE) InputStreamReader(System.`in`) else FileReader(\"input.txt\")\n)\nval out =\n if (ONLINE_JUDGE) PrintWriter(System.out)\n else PrintWriter(\"output.txt\")\n\nfun readStrings(separator: String = \" \", emptyWords: Boolean = false) : Array {\n val line = input.readLine()\n\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 readString(separator: String = \" \") =\n readStrings(separator).first()\n\nfun readInts(separator: String = \" \") =\n readStrings(separator).map(String::toInt).toIntArray()\n\nfun readDecreasedInts(separator : String = \" \") =\n readInts(separator).map { it - 1 }.toIntArray()\n\nfun readSortedInts(separator: String = \" \") : IntArray {\n val a = readInts(separator)\n\n val aInteger = Array(a.size) { a[it] }\n Arrays.sort(aInteger)\n\n return aInteger.toIntArray()\n}\n\nfun readInt(separator: String = \" \") =\n readInts(separator).first()\n\nfun readLongs(separator: String = \" \") =\n readStrings(separator).map(String::toLong).toLongArray()\n\nfun readLong(separator: String = \" \") =\n readLongs(separator).first()\n\nfun readDoubles(separator: String = \" \") =\n readStrings(separator).map(String::toDouble).toDoubleArray()\n\nfun readDouble(separator: String = \" \") =\n readDoubles(separator).first()\n\nfun readBigIntegers(separator: String = \" \") =\n readStrings(separator).map { BigInteger(it) }.toTypedArray()\n\nfun readBigInteger(separator: String = \" \") =\n readBigIntegers(separator).first()\n\nfun readTree(n : Int, indexing : Int = 1) =\n readGraph(n, n - 1, true, indexing)\n\nfun readGraph(n: Int, m : Int,\n undirected : Boolean = true,\n indexing : Int = 1) : Graph {\n val builder = GraphBuilder()\n\n for (i in 1..m) {\n var (from, to) = readInts()\n\n from -= indexing\n to -= indexing\n\n if (undirected) builder.addEdge(from, to)\n else builder.addDirectedEdge(from, to)\n }\n\n return builder.build(n)\n}\n\nfun readWeightedGraph(n : Int, m : Int,\n undirected : Boolean = true,\n indexing : Int = 1) : WeightedGraph {\n val builder = GraphBuilder()\n\n for (i in 1..m) {\n var (from, to, weight) = readInts()\n\n from -= indexing\n to -= indexing\n\n if (undirected) builder.addEdge(from, to, weight)\n else builder.addDirectedEdge(from, to, weight)\n }\n\n return builder.buildWeighted(n)\n}\n\nfun readTotalEdges(m : Int, indexing : Int = 1) =\n TotalEdgeArray(m) {\n var (from, to, w) = readInts()\n\n from -= indexing\n to -= indexing\n\n Triple(from, to, w)\n }\n\nclass GraphBuilder {\n\n private val froms = ArrayList()\n private val tos = ArrayList()\n private val weights = ArrayList()\n\n fun addEdge(from : Int, to : Int, weight : Int = 1) {\n addDirectedEdge(from, to, weight)\n addDirectedEdge(to, from, weight)\n }\n\n fun addDirectedEdge(from : Int, to : Int, weight : Int = 1) {\n froms.add(from)\n tos.add(to)\n weights.add(weight)\n }\n\n private fun calculateFromSizes(n : Int) : IntArray {\n val sizes = IntArray(n) { 0 }\n froms.forEach { ++sizes[it] }\n return sizes\n }\n\n fun build(n : Int) : Graph {\n val sizes = calculateFromSizes(n)\n\n val graph = Graph(n) { IntArray(sizes[it]) { 0 } }\n\n for (i in 0 until n) {\n sizes[i] = 0\n }\n\n for (i in 0 until froms.size) {\n val from = froms[i]\n val to = tos[i]\n\n graph[from][sizes[from]++] = to\n }\n\n return graph\n }\n\n fun buildWeighted(n : Int) : WeightedGraph {\n val sizes = calculateFromSizes(n)\n\n val graph = WeightedGraph(n) { EdgeArray(sizes[it]) { -1 to 0 } }\n\n for (i in 0 until n) {\n sizes[i] = 0\n }\n\n for (i in 0 until froms.size) {\n val from = froms[i]\n val to = tos[i]\n val weight = weights[i]\n\n graph[from][sizes[from]++] = to to weight\n }\n\n return graph\n }\n}\n\nfun gcd(a : Int, b : Int) : Int =\n if (a == 0) b else gcd(b % a, a)\n\nfun gcd(a : Long, b : Long) : Long =\n if (a == 0L) b else gcd(b % a, a)\n\nfun getDivisors(x : Int) : MutableList {\n val divisors = ArrayList()\n\n var d = 1\n while (d * d <= x) {\n if (x % d == 0) {\n if (d != 1) divisors.add(d)\n if (x != d) divisors.add(x / d)\n }\n\n ++d\n }\n\n return divisors\n}\n\nfun getPrimeDivisors(xx : Int) : MutableList {\n val divisors = ArrayList()\n\n var d = 2\n var x = xx\n while (d * d <= x) {\n if (x % d == 0) {\n divisors.add(d)\n while (x % d == 0) {\n x /= d\n }\n }\n\n ++d\n }\n\n if (x > 1) divisors.add(x)\n\n return divisors\n}\n\nfun checkIndex(index : Int, size : Int) =\n 0 <= index && index < size\n\nfun checkCell(x : Int, n : Int, y : Int, m : Int) =\n checkIndex(x, n) && checkIndex(y, m)\n\nfun toChar(index : Int, start : Char) =\n (index + start.toInt()).toChar()\n\nclass DSU {\n\n var sizes : IntArray\n var ranks : IntArray\n var parents : IntArray\n\n constructor(n : Int)\n : this(\n IntArray(n) { 1 }\n )\n\n constructor(sizes : IntArray) {\n val size = sizes.size\n this.sizes = sizes\n this.ranks = IntArray(size) { 1 }\n this.parents = IntArray(size) { it }\n }\n\n operator fun get(v : Int) : Int {\n val parent = parents[v]\n if (parent == v) return v\n parents[v] = get(parent)\n return parents[v]\n }\n\n fun union(aUniting : Int, bUniting : Int) : Boolean {\n var a = get(aUniting)\n var b = get(bUniting)\n\n if (a == b) return false\n\n if (ranks[a] < ranks[b]) {\n val tmp = a\n a = b\n b = tmp\n }\n\n parents[b] = a\n sizes[a] += sizes[b]\n if (ranks[a] == ranks[b]) ++ranks[a]\n\n return true\n }\n\n fun size(v : Int) : Int = sizes[get(v)]\n}\n\nclass FenwickTree(n : Int) {\n\n val size = n + 1\n val tree = LongArray(size) { 0L }\n\n fun update(index : Int, delta : Int) {\n var x = index + 1\n while (x < size) {\n tree[x] = tree[x] + delta\n x += x and -x\n }\n }\n\n operator fun get(start : Int, end : Int) =\n get(end) - get(start - 1)\n\n operator fun get(index : Int) : Long {\n var result : Long = 0\n\n var x = index + 1\n while (x > 0) {\n result += tree[x]\n x -= x and -x\n }\n\n return result\n }\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "b82bb3447c58c183a0cb5ed51b08c61b", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (watchPerSecond, downloadPerSecond, seconds) = readInts()\n var wait = (seconds * watchPerSecond - seconds * downloadPerSecond) / downloadPerSecond\n if (wait * downloadPerSecond + seconds * downloadPerSecond < watchPerSecond * seconds) wait++\n print(wait)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "binary search"], "code_uid": "0753eba8014b1945a788cabf7dde3b08", "src_uid": "7dd098ec3ad5b29ad681787173eba341", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 Comb(n: Int, val mod: Int) {\n\n val F = LongArray(n + 1)\n val I = LongArray(n + 1)\n init {\n F[0] = 1\n for (i in 1..n) {\n F[i] = F[i - 1] * i % mod\n }\n I[n] = powMod(F[n], (mod - 2).toLong(), mod)\n for (i in n - 1 downTo 0) {\n I[i] = I[i + 1] * (i + 1) % mod\n }\n }\n\n private fun powMod(a: Long, n: Long, mod: Int): Long {\n if (n == 0L) return 1\n val res = powMod(a * a % mod, n / 2, mod)\n return if (n % 2 == 1L) res * a % mod else res\n }\n\n fun comb(n: Int, k: Int): Long {\n return F[n] * I[k] % mod * I[n - k] % mod\n }\n\n fun inv(x: Int): Long {\n return I[x] * F[x - 1] % mod\n }\n\n /**\n * n\u306e\u30b0\u30eb\u30fc\u30d7\u304b\u3089k\u56de\u91cd\u8907\u3042\u308a\u3067\u9078\u3076\u7d44\u307f\u5408\u308f\u305b\u6570\n * n - 1\u306e\u3057\u304d\u308a\u3068k\u306e\u25cb\u3067\u8003\u3048\u308b\n */\n fun H(n: Int, k: Int) = comb(n + k - 1, k)\n}\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val N = ni()\n val comb = Comb(N * 2 + 10, MOD)\n out.println((MOD + comb.comb(2 * (N + 1), N + 1) - 1) % 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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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}", "lang_cluster": "Kotlin", "tags": ["combinatorics", "number theory"], "code_uid": "a293d1bb7a90a337f35e3fa720193d42", "src_uid": "a18833c987fd7743e8021196b5dcdd1b", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() {\n output {\n val n = readInt()\n\n var ans = ModInt(0)\n\n var pd = ModInt(1)\n\n val factorial = ModIntArray(2*n + 1).also {\n it[0] = ModInt(1)\n for(i in 1..2*n) {\n it[i] = it[i-1] * i\n }\n }\n\n fun C(n: Int, k: Int) = factorial[n] / factorial[k] / factorial[(n-k)]\n\n for(i in 0..2*n) {\n ans += pd\n if(i >= n) pd -= C(i, n)\n pd *= 2\n }\n\n println(ans)\n }\n}\n\nconst val BILLION7 = 1e9.toInt() + 7\nconst val MODINT_BASE = BILLION7\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\ninline fun Int.toModInt() = ModInt(this umod MODINT_BASE)\ninline fun Long.toModInt() = ModInt((this umod MODINT_BASE).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 @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 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\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 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", "lang_cluster": "Kotlin", "tags": ["combinatorics", "number theory"], "code_uid": "856f5cb2d3789aa4645970a5fd105839", "src_uid": "a18833c987fd7743e8021196b5dcdd1b", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() {\n output {\n val n = readInt()\n\n var ans = ModInt(0)\n\n var pd = ModInt(1)\n\n val factorial = ModIntArray(2*n + 1).also {\n it[0] = ModInt(1)\n for(i in 1..2*n) {\n it[i] = it[i-1] * i\n }\n }\n\n val invf = ModIntArray(2*n + 1) {\n factorial[it].inv_unmemoized()\n }\n\n for(i in 0..2*n) {\n ans += pd\n if(i >= n) pd -= factorial[i] * invf[n] * invf[i - n]\n pd *= 2\n }\n\n println(ans)\n }\n}\n\nconst val BILLION7 = 1e9.toInt() + 7\nconst val MODINT_BASE = BILLION7\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\ninline fun Int.toModInt() = ModInt(this umod MODINT_BASE)\ninline fun Long.toModInt() = ModInt((this umod MODINT_BASE).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 @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 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\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 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", "lang_cluster": "Kotlin", "tags": ["combinatorics", "number theory"], "code_uid": "04a9aeccea953bce74a36f712d2ce390", "src_uid": "a18833c987fd7743e8021196b5dcdd1b", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() {\n output {\n val n = readInt()\n\n var ans = ModInt(0)\n\n var pd = ModInt(1)\n\n val factorial = ModIntArray(2*n + 1).also {\n it[0] = ModInt(1)\n for(i in 1..2*n) {\n it[i] = it[i-1] * i\n }\n }\n\n val invf = ModIntArray(n + 1) {\n factorial[it].inv_unmemoized()\n }\n\n for(i in 0..2*n) {\n ans += pd\n if(i >= n) pd -= factorial[i] * invf[n] * invf[i - n]\n pd *= 2\n }\n\n println(ans)\n }\n}\n\nconst val BILLION7 = 1e9.toInt() + 7\nconst val MODINT_BASE = BILLION7\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\ninline fun Int.toModInt() = ModInt(this umod MODINT_BASE)\ninline fun Long.toModInt() = ModInt((this umod MODINT_BASE).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 @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 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\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 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", "lang_cluster": "Kotlin", "tags": ["combinatorics", "number theory"], "code_uid": "50cdccff2ea68189dc91b47be0283775", "src_uid": "a18833c987fd7743e8021196b5dcdd1b", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 dv1(p:Long,q:Long):Long=if(p>=0)(p+q-1)/q else p/q\nfun dv2(p:Long,q:Long):Long=if(p>=0)p/q else (p-q+1)/q\nfun main(){\n val (n,l,r,k)=readLongs()\n val x=if(l<=r)r-l+1 else r+n-l+1\n val y=n-x;var ans=-1L\n if(n0&&(p+1)%q==0L)ans=max(ans,a+b)\n }\n }\n }else{\n for(t in 0..k/n){\n if(t==0L){\n if(k>=x&&k<=x*2)ans=max(ans,y+k-x)\n if(k>=x&&k+1<=x*2)ans=max(ans,y+k+1-x)\n }else{\n var m=k-(t+1)*x-t*y\n if(m<0)continue\n var p=m;var q=-m\n var mn=max(dv1(-q,t+1),dv1(p-x,t))\n var mx=min(dv2(p,t),dv2(y-q,t+1))\n if(mn<=mx)ans=max(ans,p-t*mx+q+(t+1)*mx)\n m++;p=m;q=-m\n mn=max(dv1(-q,t+1),dv1(p-x,t))\n mx=min(dv2(p-1,t),dv2(y-q,t+1))\n if(mn<=mx)ans=max(ans,p-t*mx+q+(t+1)*mx)\n }\n }\n }\n printLine(\"$ans\")\n output()\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "9c6fa1d4d75030e7e0504f9ba56f997d", "src_uid": "f54cc281033591315b037a400044f1cb", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//Benq's template\n\n@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_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\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\n\nfun dv1(p:Long,q:Long):Long=if(p>=0)(p+q-1)/q else p/q\nfun dv2(p:Long,q:Long):Long=if(p>=0)p/q else (p-q+1)/q\nfun PrintWriter.solve() {\n val (n,l,r,k)=readLongs(4)\n val x=if(l<=r)r-l+1 else r+n-l+1\n val y=n-x;var ans=-1L\n if(n0&&(p+1)%q==0L)ans=max(ans,a+b)\n }\n }\n }else{\n for(t in 0..k/n){\n if(t==0L){\n if(k>=x&&k<=x*2)ans=max(ans,y+k-x)\n if(k>=x&&k+1<=x*2)ans=max(ans,y+k+1-x)\n }else{\n var m=k-(t+1)*x-t*y\n if(m<0)continue\n var p=m;var q=-m\n var mn=max(dv1(-q,t+1),dv1(p-x,t))\n var mx=min(dv2(p,t),dv2(y-q,t+1))\n if(mn<=mx)ans=max(ans,p-t*mx+q+(t+1)*mx)\n m++;p=m;q=-m\n mn=max(dv1(-q,t+1),dv1(p-x,t))\n mx=min(dv2(p-1,t),dv2(y-q,t+1))\n if(mn<=mx)ans=max(ans,p-t*mx+q+(t+1)*mx)\n }\n }\n }\n println(\"$ans\")\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)", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "4b3e63bbf11b04954697581ca505955a", "src_uid": "f54cc281033591315b037a400044f1cb", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation"], "code_uid": "6e8105cb379bfa92bce9fb135b28d07b", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation"], "code_uid": "0955a09bb42725e4f2dd2e6c5a321946", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation"], "code_uid": "c43fecb924ac009c8cb2602a1a0a38e1", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation"], "code_uid": "13b7582262155ef4923735da341d32b4", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n const val MOD = 1073741824\nvar sol = LongArray(1000001)\n//fun div( n:Long):Long\n//{\n// var c:Long=0\n// for( i in 1 until n+1)\n// {\n// if(n%i==0L)\n// {\n// c++\n// }\n// }\n// return c\n//}\nfun d(a: Long): Long {\n if (sol.get(a.toInt()) !== 0L) {\n return sol.get(a.toInt())\n }\n var i: Int\n var c:Long = 0\n i = 1\n while (i * i <= a) {\n if (a % i == 0L) {\n if (i * i.toLong() != a) {\n c++\n }\n c++\n }\n i++\n }\n sol[a.toInt()]= c\n return c\n}\n\n fun main(args: Array) {\n var s=Scanner(System.`in`)\n var i: Long\n var j: Long\n var k: Long\n val a: Long\n val b: Long\n val c: Long\n var ans: Long\n a = s.nextInt().toLong()\n b= s.nextInt().toLong()\n c = s.nextInt().toLong()\n\n\n ans = 0\n i = 1\n while (i <= a) {\n j = 1\n while (j <= b) {\n k = 1\n while (k <= c) {\n ans += d(i * j * k)\n k++\n }\n j++\n }\n i++\n }\n print(ans % MOD)\n }\n", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "a5ddf932f36da0dec2151514f811bab0", "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.*\nimport kotlin.math.*\nimport kotlin.random.*\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() {\n _writer.solve(); _writer.flush()\n}\nvar mod = (1 shl 30)\nvar memo : IntArray? = null\nlateinit var primes:BooleanArray\n\nfun PrintWriter.solve() {\n var(a,b,c) = readIntArray(3)\n\n memo = IntArray(a*b*c+1)\n primes = BooleanArray(a*b*c + 1){true}\n initPrimes()\n// println(Arrays.toString(primes))\n\n\n var res = 0\n// print(mod)\n\n for (i in 1..a)\n for (j in 1..b)\n for (k in 1..c){\n var d = i*j*k\n if (memo!![d] == 0){\n memo!![d] = findDiv(d)\n }\n\n res+= memo!![d]\n res=res%mod\n }\n\n// println(Arrays.toString(memo))\n print(res)\n}\n\nfun initPrimes() {\n var n = primes.size\n var i = 2\n while (i*i <= n){\n if(primes[i]){\n var j= 2\n while (j*i < n){\n primes[j*i] = false\n j++\n }\n }\n i++\n }\n\n\n\n}\n\nfun findDiv(dd : Int): Int {\n var tot = 1\n var d= dd\n\n\n var i = 2\n while (i <= d){\n if (primes[i] && d%i == 0){\n var count = 0\n while (d%i == 0){\n count++\n d/=i\n }\n\n tot = tot*(count+1)\n }\n i++\n }\n\n return tot\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\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() }\n\n@JvmField\nval _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\nvar _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() {\n shuffle(); _sort()\n}\n\nfun IntArray.sortDescending() {\n shuffle(); _sortDescending()\n}\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() {\n shuffle(); _sort()\n}\n\nfun LongArray.sortDescending() {\n shuffle(); _sortDescending()\n}\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() {\n shuffle(); _sort()\n}\n\nfun DoubleArray.sortDescending() {\n shuffle(); _sortDescending()\n}\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() {\n _sort()\n}\n\ninline fun CharArray.sortDescending() {\n _sortDescending()\n}\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}", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "9d7c707748589b395794a1c5011ebe34", "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\n@Suppress(\"NOTHING_TO_INLINE\")\ninline fun Number.isEven(): Boolean = this.toInt() and 1 == 0\n@Suppress(\"NOTHING_TO_INLINE\")\ninline fun Number.isOdd (): Boolean = this.toInt() and 1 == 1\n\nclass InputReader(val stream: InputStream) {\n val buf = ByteArray(1024)\n var curChar: Int = 0\n var numChars: Int = 0\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 if (numChars <= 0)\n return -1\n }\n return buf[curChar++].toInt()\n }\n\n fun nextInt(): Int {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n var sgn = 1\n if (c == 45) {\n sgn = -1\n c = read()\n }\n var res = 0\n do {\n if (c < 48 || c > 57)\n throw InputMismatchException()\n res *= 10\n res += c and 15\n c = read()\n } while (!isSpaceChar(c))\n return res * sgn\n }\n\n fun nextLong(): Long {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n var sgn = 1\n if (c == 45) {\n sgn = -1\n c = read()\n }\n var res: Long = 0\n do {\n if (c < 48 || c > 57)\n throw InputMismatchException()\n res *= 10\n res += c and 15\n c = read()\n } while (!isSpaceChar(c))\n return res * sgn\n }\n\n fun nextString(): 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 c == 32 || c == 10 || c == 13 || c == 9 || c == -1\n }\n}\n\nclass OutputWriter(val stream: OutputStream) {\n val buf = ByteArray(65536)\n var curPos: Int = 0\n\n fun write(c: Char) {\n if (buf.size - curPos < 1) flush()\n buf[curPos++] = c.toByte()\n }\n\n fun write(s: String) {\n if (buf.size - curPos < s.length) flush()\n var idx = 0\n var remaining = s.length\n while (remaining > buf.size) {\n while (curPos < buf.size) buf[curPos++] = s[idx++].toByte()\n flush()\n remaining -= buf.size\n }\n while (idx < s.length) buf[curPos++] = s[idx++].toByte()\n }\n\n fun flush() {\n stream.write(buf, 0, curPos)\n curPos = 0\n }\n}\n\nfun countDivs(n: Int): Int {\n var res = 0\n var i = 2\n while (i * i <= n) {\n if (n % i == 0) ++res\n ++i\n }\n --i\n return if (i * i == n) res * 2 + 1 else res * 2 + 2\n}\n\nfun main(args: Array) {\n if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))\n val ir = InputReader(System.`in`)\n val ow = OutputWriter(System.out)\n\n val a = ir.nextInt()\n val b = ir.nextInt()\n val c = ir.nextInt()\n val arr = IntArray(1000001)\n var answer = 0\n for (i in 1 .. a) {\n for (j in 1 .. b) {\n for (k in 1 .. c) {\n val key = i * j * k\n if (arr[key] == 0) {\n arr[key] = countDivs(key)\n }\n answer += arr[key]\n }\n }\n }\n ow.write(\"$answer\\n\")\n ow.flush()\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "3f24b6b8c1419ef2b4c21b32bef5f867", "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.InputStream\nimport java.util.*\n\nprivate class AScanner internal constructor(inputStream: InputStream = System.`in`) {\n internal val br = BufferedReader(InputStreamReader(inputStream))\n internal var st = StringTokenizer(\"\")\n\n internal fun hasNext(): Boolean {\n while (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine() ?: return false)\n return true\n }\n\n internal operator fun next() =\n if (hasNext()) st.nextToken()!!\n else throw RuntimeException(\"No tokens\")\n\n internal fun nextInt() = next().toInt()\n\n internal fun nextLong() = next().toLong()\n\n internal fun nextLine() =\n if (hasNext()) st.nextToken(\"\\n\")\n else throw RuntimeException(\"No tokens\")\n\n internal fun nextIntArray(n: Int) = IntArray(n, { nextInt() })\n\n internal fun nextLongArray(n: Int) = LongArray(n, { nextLong() })\n}\n\nfun main(args: Array) {\n val sc = AScanner()\n val pw = sc.nextLine()\n val s = pw[0]\n val e = pw[1]\n val n = sc.nextInt()\n// sc.nextLine()\n// println(\"$s $e\")\n var bs = false\n var be = false\n repeat(n, {\n val p = sc.nextLine()\n\n\n if (p == pw) {\n println(\"YES\")\n return\n }\n if (p[0] == e) be = true\n if (p[1] == s) bs = true\n\n if (be && bs) {\n println(\"YES\")\n return\n }\n\n })\n println(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "4e1d597b5a04304b488f979825285b22", "src_uid": "cad8283914da16bc41680857bd20fe9f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val password = readLine()!!\n val numWords = readLine()!!.toInt()\n val words = Array(numWords) { \"\" }\n for (pos in 0 until numWords) words[pos] = readLine()!!\n for (pos1 in 0 until numWords)\n for (pos2 in pos1 until numWords)\n if (password in (words[pos1] + words[pos2]) || password in (words[pos2] + words[pos1])) return print(\"YES\")\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "84b2efd95ae244b6898e661ba0c0c240", "src_uid": "cad8283914da16bc41680857bd20fe9f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val sc = Scanner(System.`in`)\n val s = sc.next()\n val rev = s.substring(1) + s.substring(0, 1)\n val t = sc.next().toInt()\n val st = arrayOfNulls(t)\n for (i in 0 until t) {\n val cur = sc.next()\n if (cur == s || cur == rev) {\n println(\"YES\")\n System.exit(0)\n }\n st[i] = cur\n }\n for (i in 0 until t) {\n for (j in 0 until t) {\n if (i == j) {\n continue\n }\n if (s == st[i]!!.substring(1) + st[j]!!.substring(0, 1) || s == st[j]!!.substring(1) + st[i]!!.substring(0, 1)) {\n println(\"YES\")\n System.exit(0)\n }\n }\n }\n println(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "0aa70b0a9ca97297106f7d7b36819dc3", "src_uid": "cad8283914da16bc41680857bd20fe9f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nconst val IMPOSSIBLE = -100000000000000000L\n\nfun main() {\n val k = readLine()!!.toInt()\n val fs = readLine()!!.split(\" \").map { it.toLong() }\n readLine()\n val n = readLine()!!.toInt()\n var dpPrev = LongArray(n + 1) { IMPOSSIBLE }\n dpPrev[0] = 0L\n val segTrees = Array(3) { SegmentTree(0, n / 10) }\n for (e in 5 downTo 0) {\n for (t in 0..2) {\n segTrees[t].value.fill(IMPOSSIBLE)\n }\n for (j in 0..n / 10) {\n segTrees[j % 3][j] = dpPrev[j] - (((10 * j) / 3).toLong() * fs[e])\n }\n val dp = LongArray(n + 1) { IMPOSSIBLE }\n for (j in 0..n) {\n for (t in 0..2) {\n val correction = if ((j % 3) >= t) 0L else -1L\n dp[j] = max(dp[j], segTrees[t][(j - (9 * (k - 1)) + 9) / 10, j / 10] + (fs[e] * ((j / 3).toLong() + correction)))\n for (j2 in j - (9 * k) until j - (9 * (k - 1))) {\n if (j2 >= 0 && j2 % 10 == 0) {\n if ((j - j2) % 3 == 0) {\n dp[j] = max(dp[j], segTrees[t][j2 / 10] + (fs[e] * ((j / 3).toLong() + correction)))\n } else {\n val cancel = ((j - (9 * (k - 1)) - j2) / 3).toLong()\n dp[j] = max(dp[j], segTrees[t][j2 / 10] + (fs[e] * ((j / 3).toLong() + correction - cancel)))\n }\n }\n }\n }\n if (dp[j] < 0L) {\n dp[j] = IMPOSSIBLE\n }\n }\n dpPrev = dp\n }\n println(dpPrev[n])\n}\n\nclass SegmentTree(val treeFrom: Int, val treeTo: Int) {\n val value: LongArray\n val length: Int\n\n init {\n var e = 0\n while (1 shl e < treeTo - treeFrom + 1) {\n e++\n }\n value = LongArray(1 shl (e + 1))\n length = 1 shl e\n }\n\n operator fun set(index: Int, delta: Long) {\n var node = index - treeFrom + length\n value[node] = delta\n node = node shr 1\n while (node > 0) {\n value[node] = max(value[node shl 1], value[(node shl 1) + 1])\n node = node shr 1\n }\n }\n\n operator fun get(index: Int) = value[index - treeFrom + length]\n\n operator fun get(fromIndex: Int, toIndex: Int): Long {\n if (toIndex < fromIndex) {\n return IMPOSSIBLE\n }\n\n var from = max(treeFrom, fromIndex) + length - treeFrom\n var to = min(treeTo, toIndex) + length - treeFrom + 1\n var res = IMPOSSIBLE\n while (from + (from and -from) <= to) {\n res = max(res, value[from / (from and -from)])\n from += from and -from\n }\n while (to - (to and -to) >= from) {\n res = max(res, value[(to - (to and -to)) / (to and -to)])\n to -= to and -to\n }\n return res\n }\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "d9b2fd635f8a0b651bc50f39927b49c3", "src_uid": "92bcbac3f167a44c235e99afc4de20d2", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "6a595501fc9c10d57783cf695e90775e", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "f9387d67a0feee1996c7e9f92b2bde6f", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "d282402368a82162116dfa9120d6b4c1", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "3827b9c8d59dc16a840724aeff47429d", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*;\n\nfun main(args: Array) {\n val n: Long = readLine()!!.toLong()\n var t = n\n var cnt = 0\n while (t >= 10) {\n cnt++\n t /= 10\n }\n t++\n while (cnt > 0) {\n t *= 10\n cnt--\n }\n print(t - n)\n print('\\n')\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a93b7a9dcf8781b11c74450b5d0ecb84", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n: Long = readLine()!!.toLong()\n var t = n\n var cnt = 0\n while (t >= 10) {\n cnt++\n t /= 10\n }\n t++\n while (cnt > 0) {\n t *= 10\n cnt--\n }\n print(t - n)\n print('\\n')\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "1a758d6d489bf18dba87a7553fbf31dc", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// simpler solution from tutorial\nfun main() {\n val n = readLine()!!\n var next = n[0] - '0' + 1\n repeat(n.length - 1) { next *= 10 }\n print(next - n.toInt())\n}\n\n// My valid but complex solution\n//fun main() {\n// var next = readLine()!!.toLong() + 1L\n// if (next <= 10) return print(1)\n// var sol = 0L\n// var multiplier = 1L\n// while (next > 9L) {\n// if (next % 10L != 0L) {\n// sol += multiplier * (10L - next % 10L)\n// next = next / 10L + 1L\n// } else\n// next /= 10L\n// multiplier *= 10L\n// }\n// print(sol + 1L)\n//}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "ec4f7069f65128769fdbcebbd5c816a4", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val yearStr = readLine()!!\n if (yearStr.length == 0) {\n return\n }\n\n val thisYear : Int = yearStr.toInt()\n var nextLuckyYear : Int = Int.MAX_VALUE\n if (yearStr.length == 1) {\n nextLuckyYear = thisYear + 1\n }\n else {\n nextLuckyYear = (Integer.parseInt(yearStr[0].toString()) + 1) * Math.pow(10.toDouble(), (yearStr.length - 1).toDouble()).toInt()\n }\n\n println(nextLuckyYear - thisYear)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "6d828e37e0abc4a8450940603d9a3ba2", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val x = readInt()\n val time = readInts()\n val minutes = time[0] * 60 + time[1]\n var y = -1\n while (true) {\n y++\n var newTime = minutes - x * y\n if (newTime < 0) newTime += 60 * 24\n val newHour = newTime / 60\n val newMinute = newTime % 60\n if (newHour.toString().contains('7') || newMinute.toString().contains('7')) return print(y)\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "2345b4881d289b636115538b61757963", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nobject TaskA {\n val ir = InputReader\n\n fun solve() {\n val x = ir.nextInt()\n\n var hours = ir.nextInt()\n var minutes = ir.nextInt()\n\n var total = 0\n\n while (!isLucky(hours, minutes)) {\n if (minutes >= x) {\n minutes -= x\n } else {\n minutes = 60 - (x - minutes)\n\n if (hours > 0) {\n hours--\n } else {\n hours = 23\n }\n }\n\n total++\n }\n\n println(total)\n }\n\n fun isLucky(hours: Int, minutes: Int) =\n hours.toString().contains('7') || minutes.toString().contains('7')\n\n object InputReader {\n val br = BufferedReader(InputStreamReader(System.`in`))\n var st: StringTokenizer? = null\n\n fun next(): String {\n while (st?.hasMoreTokens() != true) {\n st = StringTokenizer(br.readLine())\n }\n\n return st!!.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextFloat() = next().toFloat()\n fun nextDouble() = next().toDouble()\n fun nextLine(): String = br.readLine()\n }\n}\n\nfun main(args: Array) = TaskA.solve()\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "f2b9926883b43608509e0557eb4cc72d", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\nvar sc = Scanner(System.`in`)\nval x = sc.nextInt()\n var h = sc.nextInt()\n val m = sc.nextInt()\n if (m%10==7 || h%10 == 7){\n println(0)\n return\n }else {\n var dec = m-x\n var occ = 1\n while (true){\n\n if (dec%10==7 || h%10 ==7)break\n if (dec<0){\n h--\n if (h <0){\n h=23\n }\n dec=60+dec\n occ--\n }else if (dec<60){\n dec-=x\n }else {\n dec+=x-60\n }\n occ++\n }\n println(occ)\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "5506d6f1dc05807da691491e90984038", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n fun intersect(\n left1: Long,\n left2: Long,\n right1: Long,\n right2: Long,\n top1: Long,\n top2: Long,\n bottom1: Long,\n bottom2: Long\n ): Boolean {\n return when {\n right1 <= left2 -> false\n right2 <= left1 -> false\n left1 >= right2 -> false\n left2 >= right1 -> false\n top1 <= bottom2 -> false\n top2 <= bottom1 -> false\n bottom1 >= top2 -> false\n bottom2 >= top1 -> false\n else -> true\n }\n }\n\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 (x1, y1, x2, y2) = readLongs()\n val (x3, y3, x4, y4) = readLongs()\n val (x5, y5, x6, y6) = readLongs()\n\n var whiteArea = (y2 - y1) * (x2 - x1)\n var left1 = 0L\n var right1 = 0L\n var bottom1 = 0L\n var top1 = 0L\n var left2 = 0L\n var right2 = 0L\n var bottom2 = 0L\n var top2 = 0L\n if (x3 < x2 && x4 > x1 && y3 < y2 && y4 > y1) {\n left1 = max(x1, x3)\n right1 = min(x2, x4)\n bottom1 = max(y1, y3)\n top1 = min(y2, y4)\n whiteArea -= (top1 - bottom1) * (right1 - left1)\n }\n\n if (x5 < x2 && x6 > x1 && y5 < y2 && y6 > y1) {\n left2 = max(x1, x5)\n right2 = min(x2, x6)\n bottom2 = max(y1, y5)\n top2 = min(y2, y6)\n whiteArea -= (top2 - bottom2) * (right2 - left2)\n }\n if (x3 < x2 && x4 > x1 && y3 < y2 && y4 > y1 && x5 < x2 && x6 > x1 && y5 < y2 && y6 > y1 &&\n intersect(left1, left2, right1, right2, top1, top2, bottom1, bottom2)\n ) {\n val left = max(left1, left2)\n val right = min(right1, right2)\n val bottom = max(bottom1, bottom2)\n val top = min(top1, top2)\n whiteArea += (top - bottom) * (right - left)\n }\n print(if (whiteArea > 0) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "geometry"], "code_uid": "99f202c2a226aa0fae1f1a676b7cc7bd", "src_uid": "05c90c1d75d76a522241af6bb6af7781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun readIntList() = readLine()!!.split(' ').map(String::toInt).toMutableList()\nfun readInt() = readLine()!!.toInt()\n\n\nvar rects = mutableListOf()\n\nfun main(args: Array) {\n\n var (x1, y1, x2, y2) = readIntList()\n var (x3, y3, x4, y4) = readIntList()\n val (x5, y5, x6, y6) = readIntList()\n\n\n if (!(x1 > x4 || y1 > y4 || x2 < x3 || y2 < y3)) {\n\n x3 = max(x1, x3)\n y3 = max(y1, y3)\n x4 = min(x2, x4)\n y4 = min(y2, y4)\n\n\n var rect = Rect(x1, y1, x2, y3)\n rects.add(rect)\n y1 = y3\n\n\n rect = Rect(x1, y4, x2, y2)\n rects.add(rect)\n y2 = y4\n\n\n rect = Rect(x1, y1, x3, y2)\n rects.add(rect)\n x1 = x3\n\n\n rect = Rect(x4, y1, x2, y2)\n rects.add(rect)\n x2 = x4\n\n\n// if (x2 > x1 || y2 > y1) {\n// rect = Rect(x1, y1, x2, y2)\n// rects.add(rect)\n// }\n }else{\n val rect = Rect(x1, y1, x2, y2)\n rects.add(rect)\n }\n\n rects.forEach { elem ->\n val bool1 = !(x5 <= elem.x1 && elem.x2 <= x6 && y5 <= elem.y1 && elem.y2 <= y6)\n val bool2 = elem.x2 > elem.x1 && elem.y2 > elem.y1\n if (bool1 && bool2) {\n println(\"YES\")\n return\n }\n }\n println(\"NO\")\n\n\n}\n\nclass Rect(\n var x1: Int,\n var y1: Int,\n var x2: Int,\n var y2: Int\n)", "lang_cluster": "Kotlin", "tags": ["math", "geometry"], "code_uid": "2bdd5d2899da5bf47c7bef7aa20a2e55", "src_uid": "05c90c1d75d76a522241af6bb6af7781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n \nfun readIntList() = readLine()!!.split(' ').map(String::toInt).toMutableList()\nfun readInt() = readLine()!!.toInt()\n \n \nvar rects = mutableListOf()\n \nfun main(args: Array) {\n \n var (x1, y1, x2, y2) = readIntList()\n var (x3, y3, x4, y4) = readIntList()\n val (x5, y5, x6, y6) = readIntList()\n \n \n if (!(x1 > x4 || y1 > y4 || x2 < x3 || y2 < y3)) {\n \n x3 = max(x1, x3)\n y3 = max(y1, y3)\n x4 = min(x2, x4)\n y4 = min(y2, y4)\n \n \n var rect = Rect(x1, y1, x2, y3)\n rects.add(rect)\n y1 = y3\n \n \n rect = Rect(x1, y4, x2, y2)\n rects.add(rect)\n y2 = y4\n \n \n rect = Rect(x1, y1, x3, y2)\n rects.add(rect)\n x1 = x3\n \n \n rect = Rect(x4, y1, x2, y2)\n rects.add(rect)\n x2 = x4\n \n \n// if (x2 > x1 || y2 > y1) {\n// rect = Rect(x1, y1, x2, y2)\n// rects.add(rect)\n// }\n }else{\n val rect = Rect(x1, y1, x2, y2)\n rects.add(rect)\n }\n \n rects.forEach { elem ->\n val bool1 = !(x5 <= elem.x1 && elem.x2 <= x6 && y5 <= elem.y1 && elem.y2 <= y6)\n val bool2 = elem.x2 > elem.x1 && elem.y2 > elem.y1\n if (bool1 && bool2) {\n println(\"YES\")\n return\n }\n }\n println(\"NO\")\n \n \n}\n \nclass Rect(\n var x1: Int,\n var y1: Int,\n var x2: Int,\n var y2: Int\n)", "lang_cluster": "Kotlin", "tags": ["math", "geometry"], "code_uid": "92c9356c192821076274f61a5a6aa431", "src_uid": "05c90c1d75d76a522241af6bb6af7781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.*\n\nfun main() {\n output {\n val (x1, y1, x2, y2) = readInts(4)\n val (x3, y3, x4, y4) = readInts(4)\n val (x5, y5, x6, y6) = readInts(4)\n\n val ans = when {\n x1..x2 in x3..x4 && y1..y2 in y3..y4 -> false\n x1..x2 in x5..x6 && y1..y2 in y5..y6 -> false\n (x1..x2).let { it in x3..x4 && it in x5..x6 } -> {\n (y1..y2).coveredBy(y3..y4, y5..y6).not()\n }\n\n (y1..y2).let { it in y3..y4 && it in y5..y6 } -> {\n (x1..x2).coveredBy(x3..x4, x5..x6).not()\n }\n\n else -> true\n }\n\n println(if(ans) \"YES\" else \"NO\")\n }\n}\n\noperator fun IntRange.contains(other: IntRange) = start <= other.start && endInclusive >= other.endInclusive\n\nfun IntRange.coveredBy(_r1: IntRange, _r2: IntRange): Boolean {\n var r1 = _r1\n var r2 = _r2\n if(r1.start > r2.start) r1 = r2.also { r2 = r1 }\n return when(r1.endInclusive.compareTo(r2.start)) {\n -1 -> false\n 0 -> this in r1.start..r2.endInclusive\n else -> this in r1.start..maxOf(r1.endInclusive, r2.endInclusive)\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", "lang_cluster": "Kotlin", "tags": ["math", "geometry"], "code_uid": "e76fbc01a02b76230e33abb319c5d158", "src_uid": "05c90c1d75d76a522241af6bb6af7781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.InputStream\nimport java.io.PrintStream\nimport java.math.BigDecimal\nimport java.math.BigInteger\n\nprivate val MOD = 1e9.toLong() + 7\n\nval input = FastScanner()\n\nfun main(args: Array) {\n val (h, m) = input.nextString()!!.split(':').map { it.toInt() }\n val time = h * 60 + m\n var ans = 0\n while (!palindrome(toStr(time + ans))) {\n ans++\n }\n println(ans)\n}\n\nfun palindrome(s: String): Boolean {\n return s[0] == s[4] && s[1] == s[3]\n}\n\nfun toStr(time: Int): String {\n return String.format(\"%02d:%02d\", time / 60 % 24, time % 60)\n}\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", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "9e977acc1c4c8dc97ee99fd36d4b16aa", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.comparisons.compareBy\nimport kotlin.comparisons.thenBy\nimport kotlin.comparisons.thenByDescending\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 }\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 fun read() {\n// 05:39\n// val (h, m) =\n val s = input.next()\n val (hs, ms) = s.split(\":\")\n val (h, m) = (hs.toInt() to ms.toInt())\n\n var curH = h\n var curM = m\n var took = 0\n do {\n if (isPal(curH, curM)) {\n break\n }\n took++\n\n curM++\n if (curM > 59) {\n curM = 0\n curH++\n }\n if (curH > 23) {\n curH = 0\n }\n\n require(took < 60 * 24 * 10)\n } while (true)\n\n output.println(took)\n }\n\n private fun isPal(h: Int, m: Int): Boolean {\n val h0 = h / 10\n val h1 = h % 10\n val m0 = m / 10\n val m1 = m % 10\n return h0 == m1 && h1 == m0\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 fun nextDouble(): Double = next().toDouble()\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "e56d6f7f8f651acd70349400a32049a3", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (hour, minute) = readLine()!!.split(\":\").map(String::toInt)\n var sol = 0\n while(true) {\n if(String.format(\"%02d\", hour) == String.format(\"%02d\", minute).reversed()) break\n minute++\n if (minute == 60) {\n minute = 0\n hour++\n if (hour == 24) hour = 0\n }\n sol++\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "015f3e25ec0d50d54da5e0ce1787ee49", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n\tvar (h, m) = readLine()!!.split(':')\n\tvar t = h.toInt() * 60 + m.toInt()\n\tif (h.reversed().equals(m)) {\n\t\tprintln(\"0\")\n\t}\n\telse {\n\t\th = \"00\"\n\t\tm = \"55\"\n\t\tvar ans = 0\n\t\twhile (!h.reversed().equals(m)) {\n\t\t\tt = (t + 1) % 1440\n\t\t\tans += 1\n\t\t\th = (t / 60).toString()\n\t\t\th = if (h.length == 1) \"0\" + h else h\n\t\t\tm = (t % 60).toString()\n\t\t\tm = if (m.length == 1) \"0\" + m else m\n\t\t}\n\t\tprintln(ans)\n\t}\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "daf4d001e576619eb8ab29acdd798e54", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array){\n\tval coordA = readLine()!!.toInt()\n\tval coordB = readLine()!!.toInt()\n\tval absdistance = if (coordA - coordB >= 0) coordA - coordB else coordB - coordA\n\tval tired = if (absdistance.rem(2) == 0) 2 * howtired (absdistance/2) else howtired ((absdistance-1)/2) + howtired ((absdistance+1)/2)\n\tprintln(tired)\n}\n\nfun howtired(steps: Int): Int{\n\tvar tired: Int = 0\n\tfor (i in 0..steps){\n\t\ttired += i\n\t}\n\treturn tired\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "d29f45f990adc973823b45d64e3e1896", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.absoluteValue\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n\n val a = readInt()\n val b = readInt()\n val diff = (a - b).absoluteValue\n val (d1, d2) = if (diff % 2 == 0) diff / 2 to diff / 2 else diff / 2 to diff / 2 + 1\n print((d1 * (d1 + 1)) / 2 + (d2 * (d2 + 1)) / 2)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "815b04e76363f0fc9034af25944945e8", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Math.abs\nimport java.util.*\n\nfun main(args: Array) {\n cf()\n}\n\nprivate fun cf() = with(Scanner(System.`in`)) {\n val a = nextInt()\n val b = nextInt()\n println(tiredness(a, b))\n}\n\nprivate fun tiredness(a: Int, b: Int): Int {\n val distance = abs(a - b)\n val ad = distance / 2\n val bd = (distance + 1) / 2\n\n val asum = ad * (2 + (ad - 1)) / 2\n val bsum = bd * (2 + (bd - 1)) / 2\n\n return asum + bsum\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "8b94e22c46c28bbf4d4a5d5d40b382b1", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner;\n\nfun sum(a:Int, mean:Int):Int{\n\tvar n:Int = kotlin.math.abs(mean-a);\n\treturn (n*(n+1))/2;\n}\n\nfun main(){\n\tval reader = Scanner(System.`in`);\n\tvar a = reader.nextInt();\n\tvar b = reader.nextInt();\n\n\tvar mean:Int = (a+b)/2;\n\tprintln(sum(a, mean)+sum(b, mean));\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "1a5fd07e4558944085676ee29dd29981", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "ad87011de05eae50191822b54869c83e", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a131b357b4769b5ed557d31178d079a7", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "fe4971cc9f55e6beaebaf92e7a1c261d", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.nextLong()\n\n var nine = 0L\n\n while (true) {\n if (2 * n - 1 < nine * 10 + 9) break\n nine = nine * 10 + 9\n }\n\n if (nine == 0L) {\n println(n * (n - 1) / 2)\n return\n }\n\n var sum = 0L\n for (z in 0 until 9) {\n sum += count((nine + 1) * z + nine, n)\n }\n\n println(sum / 2)\n\n\n}\n\nfun count(nine: Long, n: Long): Long {\n val a = 1L\n val b = n\n\n val c = nine - n\n val d = nine - 1\n\n if (b < c) return 0\n if (d < a) return 0\n\n return Math.min(b, d) - Math.max(a, c) + 1\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", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "b98d34dc1bcd0c3aae5163dba632a6b5", "src_uid": "c20744c44269ae0779c5f549afd2e3f2", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\nvar n: Long = 0\nval p10 = LongArray(11)\n\nfun findmax9(): Int {\n var ans = 0\n var num = 0L\n while (true) {\n val ldn = n / p10[ans] % 10\n val od = 9 - ldn\n num += p10[ans] * od\n if (num > n) break\n ++ans\n }\n return ans\n}\n\nfun main(args: Array) {\n n = nxtint().toLong()\n p10[0] = 1\n for (i in 1..10) p10[i] = p10[i - 1] * 10\n val max9 = findmax9()\n if (max9 == 0) {\n println(n * (n - 1) / 2)\n return\n }\n var t = 0\n var ans = 0L\n while (true) {\n var num = p10[max9] * t + p10[max9] - 1\n ++t\n var l = 1\n var r = n.toInt()\n while (l < r) {\n var mid: Int = l + (r - l) / 2\n if (num - mid > n) l = mid + 1\n else r = mid\n }\n //err.printf(\"%d %d\\n\", num, l)\n if (num - l <= l || num - l > n) break\n val cnt: Long = num - l - l + 1\n ans += cnt / 2\n }\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "37e3b6d07bed6c0e0f46ae1e0714aabe", "src_uid": "c20744c44269ae0779c5f549afd2e3f2", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.lang.Math.*\nimport java.util.*\n\nfun main(args: Array) {\n val sc = FastScanner(System.`in`)\n\n val n = sc.nextLong()\n\n var nine = 0L\n while (true) {\n if (2 * n - 1 < nine * 10 + 9) break\n nine = nine * 10 + 9\n }\n\n if (nine == 0L) {\n println(n * (n - 1) / 2)\n return\n }\n\n val nines = (0 until 9).map { (nine + 1) * it + nine }\n val sum = nines.map { count(it, n) }.sum()\n\n println(sum / 2)\n}\n\nfun count(nine: Long, n: Long): Long {\n val r1 = 1..n\n val r2 = (nine - n)..(nine - 1)\n\n return max(0, min(r1.endInclusive, r2.endInclusive) - max(r1.start, r2.start) + 1)\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}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "c57268599211a30b86c57e33db7203e6", "src_uid": "c20744c44269ae0779c5f549afd2e3f2", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 a = readInts()\n val s1 = a.sum()\n val b = readInts()\n val s2 = b.sum()\n val n = readInt()\n val p = s1 / 5 + if (s1 % 5 > 0) 1 else 0\n val q = s2 / 10 + if (s2 % 10 > 0) 1 else 0\n println(if (p + q > n) \"NO\" else \"YES\")\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "64ec2e1e145a707bf90c7bdd0565fbab", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// https://codeforces.com/problemset/problem/448/A\n\n\nfun main(args: Array) {\n val medals = readInts()\n val cups = readInts()\n var totalShelves = readInt()\n\n val totalMedals = medals.sum()\n val totalCups = cups.sum()\n\n var totalCupsShelves = (totalCups / 10)\n if(totalCups % 10 != 0){\n totalCupsShelves += 1\n }\n var totalMedalsShelves = (totalMedals / 5)\n if(totalMedals % 5 != 0){\n totalMedalsShelves += 1\n }\n\n\n if(totalCupsShelves + totalMedalsShelves > totalShelves){\n print(\"NO\")\n }else{\n print(\"YES\")\n }\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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "106c4e0a7c193959719c18b77b9687a1", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 a = (1 .. 3).map({ io.readInt() }).sum()\n val b = (1 .. 3).map({ io.readInt() }).sum()\n val n = io.readInt()\n val res = (n >= ((a + 4) / 5) + ((b + 9) / 10))\n io.println(if (res) \"YES\" else \"NO\")\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "1838c851f777bc67f2a9c73fa5825fbf", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n\n val a = readLine()!!.split(' ').map { it.toInt() }.sum()\n val b = readLine()!!.split(' ').map { it.toInt() }.sum()\n val n = readLine()!!.toInt()\n\n println(if (d(a,5) + d(b, 10) <= n) \"YES\" else \"NO\")\n}\n\nfun d(a : Int, n : Int) = if (a%n == 0) a/n else a/n + 1", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a022f71f5385ed4b6e2e8ddede8228c7", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun main(args: Array) {\n readLine()\n val ar = readLine()!!.split(\" \").map { it.toInt() }\n\n var mins = mutableListOf()\n\n for (start in 0 until ar.size) {\n var firstRound = 0\n for (i in 0 until ar.size) {\n\n firstRound += abs(start - i) * ar[i] //\u0434\u043e\u0435\u0445\u0430\u0442\u044c \u043d\u0430 \u044d\u0442\u0430\u0436 i \u0441 \u044d\u0442\u0430\u0436\u0430 \u0445 a[i] \u0440\u0430\u0437\n firstRound += i * ar[i] //\u0434\u043e\u0435\u0445\u0430\u0442\u044c \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u0442\u0430\u0436 a[i] \u0440\u0430\u0437\n firstRound += start * ar[i] //\u0434\u043e\u0435\u0445\u0430\u0442\u044c \u043d\u0430 \u044d\u0442\u0430\u0436 \u0445 a[i] \u0440\u0430\u0437\n }\n mins.add(firstRound*2)\n }\n println(mins.min())\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "d25d69689a72576850c4ddcaf066fa75", "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.abs\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()\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 n = reader.nextInt()\n val a = reader.nextArrayInt(1, n)\n var ans = INF\n for (x in 1..n) {\n var sum = 0\n for (i in 1..n) {\n sum += 2 * a[i] * t_x(x, i)\n }\n ans = min(ans, sum)\n }\n writer.println(ans)\n}\n\nprivate fun t_x(x: Int, i: Int): Int {\n return abs(x - i) + abs(i - 1) + abs(x - 1)\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "67d3749e0017f2e79d6b29c0379d5b92", "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package Round526\n\nimport java.io.*\nimport java.util.*\nimport java.lang.Math.*\nimport java.lang.StringBuilder\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val pw = PrintWriter(System.out)\n val n = sc.nextInt()\n val a = LongArray(n) { sc.nextLong() }\n var min = Long.MAX_VALUE\n for (x in 1..n) {\n var sum = 0L\n for (i in 0 until n)\n sum += a[i] * (abs((i + 1) - x) + (i) + (x - 1)) * 2\n min = min(min, sum)\n }\n pw.print(min)\n pw.close()\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "04a4d7b80670e19989659f0e5198ea7e", "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//Kotlin is also fun!!\nimport java.util.*\nfun main(args: Array) = with(Scanner(System.`in`))\n{\n val n = readLine()!!.toInt()\n val a = IntArray(n){nextInt()}\n var cost = 1000000000\n for(i in 0..n-1)\n {\n var sum = 0\n for(j in 0..n-1)\n sum+=4*(Math.max(j+1,i+1)-1)*a[j]\n cost=Math.min(cost,sum)\n }\n print(cost)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "e071b50d7ebb01d441eb232c19cfcef9", "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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() }\n\nfun main(){\n val (n, k) = readInts()\n val a = readInts().sorted()\n var cnt = IntArray(200005, {0})\n var ans = IntArray(200005, {0})\n for (i in 0 until n){\n var temp = a[i]\n var d = 0\n while (temp > 0){\n if (cnt[temp] < k) {\n cnt[temp]++;\n ans[temp] += d\n }\n temp /= 2\n d++\n }\n }\n var res = Int.MAX_VALUE\n for (i in 1..a[n - 1]){\n if (cnt[i] == k) res = min(res, ans[i])\n }\n print(res)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "b5ce96c265135b18926213826d01b2a0", "src_uid": "ed1a2ae733121af6486568e528fe2d84", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() {\n val (n, k) = readInts(2)\n val A = readInts(n).sorted()\n val max = A.last()\n\n val D = Array(max+1) { DE(0, 0) }\n\n for(a in A) {\n var i = a\n var c = 0\n while(i > 0) {\n if(D[i].quant != k) {\n D[i].quant++\n D[i].cost += c\n }\n i /= 2\n c++\n }\n }\n\n val ans = D.asSequence().filter { it.quant == k }.map { it.cost }.min()!!\n\n println(ans)\n}\n\nclass DE(var quant: Int, var cost: Int)\n\nfun readLn() = readLine()!!\nprivate var tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(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\ninline fun output(block: PrintWriter.()->Unit) { PrintWriter(System.out, false).apply(block).flush() }", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "fd8fd10e422358b399769c82246a0032", "src_uid": "ed1a2ae733121af6486568e528fe2d84", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\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 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 \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 nextInts() = next().split(\" \").map { it.toInt() }\nfun nextLongs() = next().split(\" \").map { it.toLong() }\n \nval v = Array> (MX,{ArrayList()})\n \nfun ad(x: Int) {\n var X = x\n var num = 0\n while (true) {\n v[X].add(num)\n if (X == 1) break\n X /= 2\n num ++\n }\n}\n \nfun solve() {\n val (n,k) = nextInts()\n val a = nextInts()\n for (i in a) ad(i)\n var ans = MOD\n for (i in 1..200000) {\n Collections.sort(v[i])\n if (v[i].size >= k) {\n var tmp = 0\n for (j in 0..k-1) tmp += v[i][j]\n ans = minOf(ans,tmp)\n }\n }\n print(ans)\n}\n \nfun main(args: Array) {\n val T = 1\n for (i in 1..T) solve()\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "cf969fb3889d5fefa75e0ecc688cd31d", "src_uid": "ed1a2ae733121af6486568e528fe2d84", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\nfun main() {\n var (n, m) = readLine()!!.split(\" \").map { it.toInt() }\n var vals = readLine()!!.split(\" \").map { it.toInt() }.sorted()\n var cnts = IntArray(200005, { 0 })\n var answ = IntArray(200005, { 0 })\n for (i in 0 until n) {\n var curr = vals[i]\n var indx = 0\n while (curr > 0) {\n if (cnts[curr] < m) {\n cnts[curr]++\n answ[curr] += indx\n }\n curr /= 2\n indx++\n\n }\n\n }\n var result = Int.MAX_VALUE\n for (i in 1..vals[n - 1]) {\n if (cnts[i] == m) result = min(result, answ[i])\n }\n println(result)\n}\n\n\n\n\n/*\n\n */", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "c2bd21c9293a6413fb749a7fdd3ed1cc", "src_uid": "ed1a2ae733121af6486568e528fe2d84", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!.toInt()\n var answer = 1\n for (k in 2..10) {\n val b = (1 shl ((2 * k) - 1)) - (1 shl (k - 1))\n if (n % b == 0) {\n answer = b\n } else if (b > n) {\n println(answer)\n return\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "4b8d4d80e94f6e97d4ad0a70e49b5610", "src_uid": "339246a1be81aefe19290de0d1aead84", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nclass B internal constructor(inputStream: InputStream, val out: PrintWriter) {\n companion object {\n val ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n }\n\n private val br = BufferedReader(InputStreamReader(inputStream))\n private var st = StringTokenizer(\"\")\n\n internal fun hasNext(): Boolean {\n while (!st.hasMoreTokens()) {\n val readLine = br.readLine() ?: return false\n st = StringTokenizer(readLine)\n }\n return true\n }\n\n private operator fun next() =\n if (hasNext()) st.nextToken()!!\n else throw RuntimeException(\"No tokens\")\n\n internal fun nline() =\n if (hasNext()) st.nextToken(\"\\n\")\n else throw RuntimeException(\"No tokens\")\n\n private fun ni() = next().toInt()\n private fun nii() = Pair(ni(), ni())\n private fun niii() = Triple(ni(), ni(), ni())\n private fun nia(n: Int) = IntArray(n) { ni() }\n private fun nia(m: Int, n: Int) = Array(m) { nia(n) }\n\n private fun nl() = next().toLong()\n private fun nll() = Pair(nl(), nl())\n private fun nlll() = Triple(nl(), nl(), nl())\n private fun nla(n: Int) = LongArray(n, { nl() })\n private fun nla(m: Int, n: Int) = Array(m) { nla(n) }\n\n private fun nd() = next().toDouble()\n private fun ndd() = Pair(nd(), nd())\n private fun nddd() = Triple(nd(), nd(), nd())\n private fun nda(n: Int) = DoubleArray(n) { nd() }\n private fun nda(m: Int, n: Int) = Array(m) { nda(n) }\n\n inline fun log(name: String, block: () -> Unit) {\n if (!ONLINE_JUDGE) {\n p(\"#$name: \")\n block()\n flush()\n }\n }\n\n inline fun log() = log(\"\") { pln() }\n inline fun log(message: Any?, name: String = \"\") = log(name) { pln(message) }\n inline fun log(arr: IntArray?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(arr: LongArray?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(arr: DoubleArray?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(arr: Array?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(stack: Stack?, name: String = \"\") = log(name) { pln(stack) }\n inline fun log(list: List?, name: String = \"\") = log(name) { pln(list) }\n\n //prefix print\n inline fun prep(prefix: Boolean, separator: String, message: Any?) {\n if (prefix) {\n p(separator)\n }\n p(message)\n }\n\n inline fun p(message: Any?) = this.also { out.print(message) }\n\n inline fun p(arr: IntArray?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(arr: LongArray?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(arr: DoubleArray?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(arr: Array?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(list: List?, separator: String = \" \") = this.also {\n list?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(stack: Stack?, separator: String = \" \") = this.also {\n stack?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun pln() = this.also { out.println() }\n inline fun pln(message: Any?) = p(message).pln()\n inline fun pln(arr: IntArray?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(arr: LongArray?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(arr: DoubleArray?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(list: List?, separator: String = \" \") = p(list, separator).pln()\n inline fun pln(arr: Array?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(stack: Stack?, separator: String = \" \") = p(stack, separator).pln()\n\n inline fun flush() = out.flush()\n\n //////////////////////////////////////\n\n fun run() {\n val n = ni()\n for (i in n downTo 1) {\n if (n % i == 0) {\n if (isBeautiful(i)) {\n pln(i)\n return\n }\n }\n }\n }\n\n private fun isBeautiful(i: Int): Boolean {\n var k = 1\n while (((1 shl k) - 1) * (1 shl (k - 1)) < i) {\n k++\n }\n return ((1 shl k) - 1) * (1 shl (k - 1)) == i\n }\n\n}\n\n//////////////////////////////////////\nfun main(args: Array) {\n val inp = File(\"B.txt\")\n if (B.ONLINE_JUDGE || !inp.isFile) {\n val a = B(System.`in`, PrintWriter(BufferedOutputStream(System.out)))\n a.run()\n a.flush()\n a.out.close()\n } else {\n val t = B(FileInputStream(\"B.txt\"), PrintWriter(BufferedOutputStream(System.out)))\n while (t.hasNext()) {\n val name = t.nline()\n t.log(\"##### Test $name #####\")\n val startTime = System.currentTimeMillis()\n t.run()\n val endTime = System.currentTimeMillis()\n t.log(endTime - startTime, \"Total Time\")\n t.log()\n t.flush()\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "193b953ed197a238196966bf10bf1517", "src_uid": "339246a1be81aefe19290de0d1aead84", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var n = readLine()!!.toInt()\n var array = ArrayList()\n var str = \"1\"\n var num = Math.pow(10.0, 5.0).toInt()\n var i = 1\n while (Integer.parseInt(str, 2) <= num) {\n array.add(Integer.parseInt(str, 2))\n str = \"1\" + str + \"0\"\n }\n var reversed = array.reversed()\n\n for (i in reversed){\n if (n%i==0){\n println(i)\n return\n }\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "78df27760c38a316dc06d58fc7c583f9", "src_uid": "339246a1be81aefe19290de0d1aead84", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nclass Main internal constructor(inputStream: InputStream, val out: PrintWriter) {\n companion object {\n val ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n }\n\n private val br = BufferedReader(InputStreamReader(inputStream))\n private var st = StringTokenizer(\"\")\n\n internal fun hasNext(): Boolean {\n while (!st.hasMoreTokens()) {\n val readLine = br.readLine() ?: return false\n st = StringTokenizer(readLine)\n }\n return true\n }\n\n private operator fun next() =\n if (hasNext()) st.nextToken()!!\n else throw RuntimeException(\"No tokens\")\n\n internal fun nline() =\n if (hasNext()) st.nextToken(\"\\n\")\n else throw RuntimeException(\"No tokens\")\n\n private fun ni() = next().toInt()\n private fun nii() = Pair(ni(), ni())\n private fun niii() = Triple(ni(), ni(), ni())\n private fun nia(n: Int) = IntArray(n) { ni() }\n private fun nia(m: Int, n: Int) = Array(m) { nia(n) }\n\n private fun nl() = next().toLong()\n private fun nll() = Pair(nl(), nl())\n private fun nlll() = Triple(nl(), nl(), nl())\n private fun nla(n: Int) = LongArray(n, { nl() })\n private fun nla(m: Int, n: Int) = Array(m) { nla(n) }\n\n private fun nd() = next().toDouble()\n private fun ndd() = Pair(nd(), nd())\n private fun nddd() = Triple(nd(), nd(), nd())\n private fun nda(n: Int) = DoubleArray(n) { nd() }\n private fun nda(m: Int, n: Int) = Array(m) { nda(n) }\n\n inline fun log(name: String, block: () -> Unit) {\n if (!ONLINE_JUDGE) {\n p(\"#$name: \")\n block()\n flush()\n }\n }\n\n inline fun log() = log(\"\") { pln() }\n inline fun log(message: Any?, name: String = \"\") = log(name) { pln(message) }\n inline fun log(arr: IntArray?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(arr: LongArray?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(arr: DoubleArray?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(arr: Array?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(stack: Stack?, name: String = \"\") = log(name) { pln(stack) }\n inline fun log(list: List?, name: String = \"\") = log(name) { pln(list) }\n\n //prefix print\n inline fun prep(prefix: Boolean, separator: String, message: Any?) {\n if (prefix) {\n p(separator)\n }\n p(message)\n }\n\n inline fun p(message: Any?) = this.also { out.print(message) }\n\n inline fun p(arr: IntArray?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(arr: LongArray?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(arr: DoubleArray?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(arr: Array?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(list: List?, separator: String = \" \") = this.also {\n list?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(stack: Stack?, separator: String = \" \") = this.also {\n stack?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun pln() = this.also { out.println() }\n inline fun pln(message: Any?) = p(message).pln()\n inline fun pln(arr: IntArray?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(arr: LongArray?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(arr: DoubleArray?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(list: List?, separator: String = \" \") = p(list, separator).pln()\n inline fun pln(arr: Array?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(stack: Stack?, separator: String = \" \") = p(stack, separator).pln()\n\n inline fun flush() = out.flush()\n\n //////////////////////////////////////\n\n fun run() {\n val n = ni()\n var answer = 1\n var itr = 1\n var k = 0\n var d = 0\n var set = TreeSet();\n var flag = true\n var flag1 = true\n for (i in 1..n) {\n k = 0\n d = i\n flag = true\n flag1 = true\n while (d > 0) {\n if (d % 2 == 0 && flag1) k++\n else {\n flag1 = false\n if (d % 2 == 0) flag = false\n else k--\n } \n d /= 2\n }\n if (k == -1 &&flag) set.add(i)\n }\n for (i in set) if (n % i == 0) answer = i\n out.print(answer)\n }\n\n}\n\n//////////////////////////////////////\nfun main(args: Array) {\n val inp = File(\"input.txt\")\n if (Main.ONLINE_JUDGE || !inp.isFile) {\n val a = Main(System.`in`, PrintWriter(BufferedOutputStream(System.out)))\n a.run()\n a.flush()\n a.out.close()\n } else {\n val t = Main(FileInputStream(\"input.txt\"), PrintWriter(BufferedOutputStream(System.out)))\n while (t.hasNext()) {\n val name = t.nline()\n t.log(\"##### Test $name #####\")\n val startTime = System.currentTimeMillis()\n t.run()\n val endTime = System.currentTimeMillis()\n t.log(endTime - startTime, \"Total Time\")\n t.log()\n t.flush()\n }\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "8b9985480c4fc40164b7edb24a7eb6ca", "src_uid": "339246a1be81aefe19290de0d1aead84", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (n, m) = readInts()\n\n // Kx[y] = # of arrays of x 1s and y -1s such that max prefix sum = 0\n var K = ModIntArray(m+1) { ModInt(1) }\n // Dx[y] = answer for n=x and m=y\n var D = ModIntArray(m+1) { ModInt(0) }\n\n for(x in 1..n) {\n val Kx = ModIntArray(m+1)\n for(y in x..m) {\n Kx[y] = K[y] + Kx[y-1]\n }\n\n val Dx = ModIntArray(m+1)\n Dx[0] = ModInt(x)\n for(y in 1..m) {\n val nn = x + y - 1\n Dx[y] = C(nn, y) + D[y] + Dx[y-1] - C(nn, x) + Kx[y-1]\n }\n\n K = Kx\n D = Dx\n }\n\n val ans = D[m]\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 = 998244853\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() = pow(MODBASE - 2) // assumes MODBASE is prime\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\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\nfun C(n: Int, k: Int) = n.factorial() / k.factorial() / (n-k).factorial()\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\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() }", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "ea2f896cff9b04dd99c1311ae622dd9d", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (n, m) = readInts()\n\n var ans = C(n+m, n) * (n-m-1).coerceAtLeast(0)\n\n for(k in 0..minOf(n-1, m)) {\n ans += C(n+m, k)\n }\n\n println(ans)\n}\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\nfun C(n: Int, k: Int) = n.factorial() / k.factorial() / (n-k).factorial()\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 = 998244853\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() = pow(MODBASE - 2) // assumes MODBASE is prime\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(ModInt(1), ModInt::times)\nfun Sequence.product() = fold(ModInt(1), ModInt::times)\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() }", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "2c25267db8512bdb79a3000f804574da", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (n, m) = readInts()\n\n // Kx[y] = # of arrays of x 1s and y -1s such that max prefix sum = 0\n var K = ModIntArray(m) { ModInt(1) }\n // Dx[y] = answer for n=x and m=y\n var D = ModIntArray(m+1)\n\n for(x in 1..n) {\n val Kx = ModIntArray(m)\n for(y in x until m) {\n Kx[y] = K[y] + Kx[y-1]\n }\n\n val Dx = ModIntArray(m+1)\n Dx[0] = ModInt(x)\n for(y in 1..m) {\n val nn = x + y - 1\n Dx[y] = C(nn, y) + D[y] + Dx[y-1] - C(nn, x) + Kx[y-1]\n }\n\n K = Kx\n D = Dx\n }\n\n val ans = D[m]\n\n println(ans)\n}\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\nfun C(n: Int, k: Int) = n.factorial() / k.factorial() / (n-k).factorial()\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 = 998244853\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() = pow(MODBASE - 2) // assumes MODBASE is prime\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(ModInt(1), ModInt::times)\nfun Sequence.product() = fold(ModInt(1), ModInt::times)\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() }", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "948c761d4893bd092437814b8d7fb7fb", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (n, m) = readInts()\n\n var ans = ModInt(0)\n\n for(x in 1..n) {\n if(x >= n-m) ans += C(n+m, n-x)\n else ans += C(n+m, n)\n }\n\n println(ans)\n}\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\nfun C(n: Int, k: Int) = n.factorial() / k.factorial() / (n-k).factorial()\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 = 998244853\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() = pow(MODBASE - 2) // assumes MODBASE is prime\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(ModInt(1), ModInt::times)\nfun Sequence.product() = fold(ModInt(1), ModInt::times)\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() }", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "number theory"], "code_uid": "52340b07e42a5476b2b5821d82db5e68", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var N = readLine()!!.toInt()\n var W = readLine()!!\n var C = 0\n var c = 0\n for (i in 0 until N) {\n when(W[i]){\n in 'A'..'Z'-> {\n C++\n if (c < C) {\n c = C\n }\n }\n ' '->{\n C = 0\n if (c < C) {\n c = C\n }\n }\n }\n }\n print(c)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c62ae8947eebf82838983e406f0449b3", "src_uid": "d3929a9acf1633475ab16f5dfbead13c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n readLine()\n println(readLine()!!.split(\" \").map { it.count { c -> c.isUpperCase() } }.max()!!)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4852c42adc30ccadab6e389d085d3658", "src_uid": "d3929a9acf1633475ab16f5dfbead13c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args : Array){\n\n var n = readLine()\n var text = readLine() + \" \"\n var max = 0\n var count = 0\n\n for (c in text) {\n if (c.isUpperCase()) {\n ++count\n } else if (c.toString() == \" \") {\n max = if (count > max) count else max\n count = 0\n }\n }\n\n println(max)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "08b3af7eeba9393ec1fbab1dbc5bc6f3", "src_uid": "d3929a9acf1633475ab16f5dfbead13c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "var n:Int=0\nvar arr=Array(15){tuple(0,0,0)}\nfun main(args: Array){\n n= readLine()!!.toInt()\n for (i:Int in 0 until n){\n val inp=readLine()!!.split(' ')\n arr[i]=tuple(inp[0].toInt() , inp[1].toInt() , inp[2].toInt())\n }\n var ans=0\n var num_of_ans=0\n for(i:Int in 123..9876){\n if(!distinct(i)){\n continue\n }\n if(check(i)){\n ans=i\n num_of_ans++\n }\n }\n if(num_of_ans == 0){\n println(\"Incorrect data\")\n }else if(num_of_ans > 1){\n println(\"Need more data\")\n }else{\n if(ans/1000 == 0){\n print(0)\n print(ans)\n }else {\n print(ans)\n }\n }\n}\nfun distinct(x:Int):Boolean{\n var firstX:Int=x%10\n var secondX:Int=(x%100)/10\n var thirdX:Int=(x%1000)/100\n var fourthX:Int=x/1000\n if(firstX == secondX || firstX == thirdX || firstX == fourthX\n || secondX == thirdX || secondX == fourthX || thirdX == fourthX){\n return false\n }\n return true\n}\n\nfun check(num: Int):Boolean{\n for(i:Int in 0 until n){//bulls the same pos\n if(Bulls(arr[i].x , num) != arr[i].y ||\n Cows(arr[i].x , num) != arr[i].z){\n return false\n }\n }\n return true\n}\nfun Bulls(x:Int , y:Int):Int{\n var ans:Int=0\n if(x%10 == y%10){\n ans++\n }\n if ((x%100)/10 == (y%100)/10){\n ans++\n }\n if ((x%1000)/100 == (y%1000)/100){\n ans++\n }\n if(x/1000 == y/1000){\n ans++\n }\n return ans\n}\nfun Cows(x:Int , y:Int):Int{\n var ans=0\n var firstX:Int=x%10\n var secondX:Int=(x%100)/10\n var thirdX:Int=(x%1000)/100\n var fourthX:Int=x/1000\n\n var firstY:Int=y%10\n var secondY:Int=(y%100)/10\n var thirdY:Int=(y%1000)/100\n var fourthY:Int=y/1000\n if(firstX == secondY || firstX == thirdY || firstX == fourthY){\n ans++\n }\n if(secondX == firstY || secondX == thirdY || secondX == fourthY){\n ans++\n }\n if(thirdX == secondY || thirdX == firstY || thirdX == fourthY){\n ans++\n }\n if(fourthX == secondY || fourthX == thirdY || fourthX == firstY){\n ans++\n }\n return ans\n}\nclass tuple(x:Int , y:Int , z:Int){\n var x:Int=0\n var y:Int=0\n var z:Int=0\n init{\n this.x=x\n this.y=y\n this.z=z\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "d77481ca18db0f49ba075b2b2fcfeba0", "src_uid": "142e5f2f08724e53c234fc2379216b4c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var n = readLine()!!.toInt()\n\n var list = mutableListOf()\n\n for (i:Char in '0'..'9')\n for (j:Char in '0'..'9')if(j != i)\n for (k:Char in '0'..'9')if(k != i && k!= j)\n for (l:Char in '0'..'9')if(l!=i && l!=j && l!= k){\n var arr = CharArray(4){i}\n arr[1] = j\n arr[2] = k\n arr[3] = l\n\n var num = String(arr)\n\n list.add(num)\n }\n\n\n\n\n repeat(n){\n var (num,bulls, cows) = readLine()!!.split(\" \")\n var tmp = mutableListOf()\n for (s in list){\n var b = 0\n var c = 0\n\n var seto = setOf(num[0],num[1],num[2],num[3])\n var sett = setOf(s[0],s[1],s[2],s[3])\n\n var finSet = seto.intersect(sett);\n\n for (i in 0..3){\n if (s[i] == num[i])b++\n }\n\n c = finSet.size - b\n\n if(b == bulls.toInt() && c == cows.toInt())\n tmp.add(s)\n }\n\n list = tmp\n }\n\n if (list.size == 1)\n println(list[0])\n else if(list.isEmpty())\n println(\"Incorrect data\")\n else\n println(\"Need more data\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "45c64c2a05450a67973e416a562811ab", "src_uid": "142e5f2f08724e53c234fc2379216b4c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val jin = Scanner(System.`in`)\n val k = jin.nextInt()\n val pa = jin.nextLong()\n val pb = jin.nextLong()\n val p = (pa * ((pa + pb) pow -1)) % MOD\n val np = 1L - p\n val npInv = np pow -1\n //println(\"p = $p, np = $np, npInv = $npInv\")\n val dp = Array(k) { LongArray(k + 1) }\n var answer = k.toLong()\n dp[0][1] = 1L\n for (j1 in 0 until k) {\n for (j2 in 1..k) {\n //println(\"dp[$j1][$j2] = ${dp[j1][j2]}\")\n if (j2 == k) {\n answer += dp[j1][j2] * (j1.toLong() + npInv - 1L)\n answer %= MOD\n } else {\n dp[j1][j2 + 1] += dp[j1][j2] * p\n dp[j1][j2 + 1] %= MOD\n if (j1 + j2 >= k) {\n answer += ((dp[j1][j2] * np) % MOD) * (j1 + j2 - k).toLong()\n answer %= MOD\n } else {\n dp[j1 + j2][j2] += dp[j1][j2] * np\n dp[j1 + j2][j2] %= MOD\n }\n }\n }\n }\n println(((answer % MOD) + MOD) % MOD)\n}\n\nval MOD: Long = 1000000007\nval MOD_TOTIENT = (MOD - 1).toInt()\n\ninfix fun Long.pow(power: Int): Long {\n var e = power\n e %= MOD_TOTIENT\n if (e < 0) {\n e += MOD_TOTIENT\n }\n if (e == 0 && this == 0L) {\n return this\n }\n var b = this\n var res = 1L\n while (e > 0) {\n if (e and 1 != 0) {\n res *= b\n res %= MOD\n }\n b *= b\n b %= MOD\n e = e shr 1\n }\n return res\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "probabilities"], "code_uid": "49f943055ccd8e65e4accd7209f6f7cc", "src_uid": "0dc9f5d75143a2bc744480de859188b4", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 // var m: Int = reader.nextInt()\n\n val n = readLine()!!\n val m = readLine()!!\n var a: Int = n.toInt()\n var b: Int = m.toInt()\n\n var list1: MutableList = mutableListOf()\n var list2: MutableList = mutableListOf()\n\n\n if (n.length != m.length) println(\"WRONG_ANSWER\")\n else if(n.length == 1 && m.length == 1 && n!= m ) println(\"WRONG_ANSWER\")\n else if (n.length == 1 && m.length == 1 && n == m ) println(\"OK\")\n else if (a > 0 && b > 0) {\n while (a > 0) {\n list1.add(a % 10)\n a = a / 10\n }\n list1.sort()\n if (list1[0] == 0) {\n for (i in 1..list1.size - 1) {\n if (list1[i] != 0) {\n list1[0] = list1[i]\n list1[i] = 0\n break\n }\n }\n }\n\n while (b > 0) {\n list2.add(b % 10)\n b = b / 10\n }\n list2.reverse()\n\n if (list1 == list2) {\n println(\"OK\")\n } else {\n println(\"WRONG_ANSWER\")\n }\n }\n}\n\n", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation"], "code_uid": "21ed0e47bf1c7da2b5564c19b0a459c1", "src_uid": "d1e381b72a6c09a0723cfe72c0917372", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var s = readLine()!!.toCharArray().sortedArray()\n if (s[0] == '0') {\n var i = 0\n while (i + 1 < s.size && s[i] == '0')\n i++\n s[0] = s[i].also { s[i] = s[0] }\n }\n println(if (s contentEquals readLine()!!.toCharArray()) \"OK\" else \"WRONG_ANSWER\")\n}\n", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation"], "code_uid": "3007fe06cf5ddeb6df50d81a3a2428f8", "src_uid": "d1e381b72a6c09a0723cfe72c0917372", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(){\n var (n,d) = readLine()!!.split(' ').map { it.toInt() }\n var list = readLine()!!.split(' ').map { it.toInt() }.sorted()\n var m = readLine()!!.toInt()\n\n if (m>=n){\n println(list.sum() - ((m-n)*d))\n }else{\n var ans = 0\n for (i in 0..m-1){\n ans+=list[i]\n }\n println(ans)\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9eb7ee07747e83925d00be7ea1fa20d9", "src_uid": "5c21e2dd658825580522af525142397d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numHooks, fine) = readInts()\n val prices = readInts().sorted()\n val numGuests = readInt()\n print(\n if (numGuests <= numHooks) prices.subList(0, numGuests).sum()\n else prices.sum() - fine * (numGuests - numHooks)\n )\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "0a516454fe368294144156a5f74254e1", "src_uid": "5c21e2dd658825580522af525142397d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun main() {\n val (a, b, s) = readLine()!!.split(\" \").map(String::toLong)\n val distance = abs(a) + abs(b)\n print(if (s >= distance && (s - distance) % 2 == 0L) \"Yes\" else \"No\")\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "8ecb881e8393b34c1fc26ec6aa899905", "src_uid": "9a955ce0775018ff4e5825700c13ed36", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 a = io.readInt()\n val b = io.readInt()\n val s = io.readInt()\n val mind = Math.abs(a) + Math.abs(b)\n val res = if (s < mind) false else (s - mind) % 2 == 0\n io.println(if (res) \"Yes\" else \"No\")\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "10094ee710bcdf838e163baabf6ef94c", "src_uid": "9a955ce0775018ff4e5825700c13ed36", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun main() {\n var (a, b, s) = readLine()!!.split(\" \").map { it.toInt() }\n var sum = abs(a) + abs(b)\n if (sum > s || (s - sum) % 2 == 1) {\n println(\"NO\")\n } else {\n println(\"YES\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "80558bf474e2a69278827f85ba27934d", "src_uid": "9a955ce0775018ff4e5825700c13ed36", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val s = Scanner(System.`in`)\n val a = IntArray(2, { Math.abs(s.nextInt()) }).sum()\n val b = s.nextInt()\n val res = when {\n a == b || (a < b && (b - a).rem(2) == 0) -> \"Yes\"\n else -> \"No\"\n }\n print(res)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "459c4bd79879b87321acf5d4ab6dea71", "src_uid": "9a955ce0775018ff4e5825700c13ed36", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport java.io.*\n\n\n fun main(args: Array) {\n val infile = BufferedReader(InputStreamReader(System.`in`))\n val st = StringTokenizer(infile.readLine())\n val L = Integer.parseInt(st.nextToken())\n val R = Integer.parseInt(st.nextToken())\n val X = Integer.parseInt(st.nextToken())\n val Y = Integer.parseInt(st.nextToken())\n if (Y % X != 0) {\n println(0)\n return\n }\n var res = 0\n val boof = Y / X\n var i = 1\n while (i <= Math.sqrt(boof.toDouble())) {\n if (boof % i == 0 && X * Math.min(i, boof / i) >= L && X * Math.max(i, boof / i) <= R)\n if (rp(i, boof / i)) {\n res += 2\n if (i == boof / i)\n res--\n }\n i++\n }\n println(res)\n }\n\n fun rp(c: Int, d: Int): Boolean {\n var a = c\n var b = d\n if (b > a) {\n val t = a\n a = b\n b = t\n }\n return if (b == 0) a == 1 else rp(b, a % b)\n }", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "99b7cf97512cbfb976c0833869dc0c8d", "src_uid": "d37dde5841116352c9b37538631d0b15", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val options = listOf(\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\")\n val length = readInt()\n val hint = readLine()!!\n nextOption@ for (option in options) {\n if (option.length != length) continue\n for (pos in option.indices) if (hint[pos] != '.' && hint[pos] != option[pos]) continue@nextOption\n return print(option)\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "98aae56601acf2e5298f4b96aa6b7a5d", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(){\n var n = readLine()!!.toInt()\n var str = readLine()!!\n if (n==6){\n println(\"espeon\")\n }else if (n==8){\n println(\"vaporeon\")\n }else{\n\n var list = listOf(\"jolteon\",\"flareon\",\"umbreon\",\"leafeon\",\"glaceon\",\"sylveon\")\n for (i in list){\n var flag = false;\n for (j in 0 until i.length){\n if (str[j]!='.' && str[j]!=i[j]){\n flag = true\n break\n }\n }\n if (!flag) println(i)\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "fc449773793877ad1a5cafc8e1b9c051", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n\n val sc = Scanner(System.`in`)\n val a = arrayOf(\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\")\n val n = sc.nextInt()\n val str = sc.next()\n\n for (i in 0 until 8) {\n var stop = true\n if (n == a[i].length) {\n for (j in 0 until n) {\n if (str[j] != '.') {\n if (str[j] != a[i][j]) {\n stop = false\n break\n }\n }\n }\n if (stop) {\n print(a[i])\n return\n }\n }\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "e18d99f4d5af2227afc76abe5bf5263d", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "edc53085932911d60731d16ddea58eb7", "src_uid": "259d01b81bef5536b969247ff2c2d776", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "8b604b7eaf974bbc0eb6910499b7d694", "src_uid": "259d01b81bef5536b969247ff2c2d776", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "41ce27a2237a5aabee83da2b7e2869fd", "src_uid": "259d01b81bef5536b969247ff2c2d776", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "d091b7c18fea2d9cb62d48ebcd147871", "src_uid": "259d01b81bef5536b969247ff2c2d776", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main(args: Array) {\n var (la, ra, ta) = readLine()!!.split(' ').map(String::toLong)\n var (lb, rb, tb) = readLine()!!.split(' ').map(String::toLong)\n if (la > lb) {\n var t = la; la = lb; lb = t\n t = ra; ra = rb; rb = t\n t = ta; ta = tb; tb = t\n }\n rb -= la\n lb -= la\n ra -= la\n la = 0\n val tgcd = gcd(ta, tb)\n val q = lb / tgcd\n lb -= q * tgcd\n rb -= q * tgcd\n val ans1 = max(0, (min(ra, rb) - max(la, lb) + 1))\n lb -= tgcd\n rb -= tgcd\n val ans2 = max(0, (min(ra, rb) - max(la, lb) + 1))\n println(max(ans1, ans2))\n}\n\nfun gcd(a: Long, b: Long): Long {\n var aa = a\n var bb = b\n while (bb > 0) {\n val t = aa\n aa = bb\n bb = t % bb\n }\n return aa\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "f7666b47c5b472478318450fe5ab6dca", "src_uid": "faa75751c05c3ff919ddd148c6784910", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun gcd(a: Int, b: Int): Int {\n if (a == 0)\n return b\n return gcd(b % a, a)\n}\n\nfun solve(cin: FastReader, out: PrintWriter) {\n var la = cin.nextInt()\n var ra = cin.nextInt()\n var ta = cin.nextInt()\n var lb = cin.nextInt()\n var rb = cin.nextInt()\n var tb = cin.nextInt()\n var g = gcd(ta, tb)\n rb -= la\n ra -= la\n lb -= la\n la -= la\n if (lb < 0) {\n lb += tb\n rb += tb\n }\n\n var ans = 0\n for (d in listOf(lb / g, lb / g + 1, lb / g - 1)) {\n val llb = lb - g * d\n val rrb = rb - g * d\n\n if (llb <= ra && la <= rrb)\n ans = Math.max(ans, Math.min(ra, rrb) - Math.max(la, llb) + 1)\n }\n\n out.print(ans)\n}\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 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}\n\nfun main(args: Array) {\n val cin = FastReader(System.`in`)\n val out = PrintWriter(BufferedOutputStream(System.out))\n solve(cin, out)\n out.close()\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "3f2215e5ce54346730f8139811f8474d", "src_uid": "faa75751c05c3ff919ddd148c6784910", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val jin = BufferedReader(InputStreamReader(System.`in`))\n var (la, ra, ta) = jin.readLine().split(\" \").map { it.toLong() }\n var (lb, rb, tb) = jin.readLine().split(\" \").map { it.toLong() }\n val g = gcd(ta, tb)\n val sa = ra - la\n val sb = rb - lb\n la %= g\n lb %= g\n val answer = max(\n max(\n min(la + sa, lb + sb) - max(la, lb),\n min(la + sa + g, lb + sb) - max(la + g, lb)),\n max(\n min(la + sa, lb + sb + g) - max(la, lb + g),\n -1L)\n ) + 1L\n println(answer)\n}\n\nfun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "efd03af8f1b2e4adb4acc75354d7233a", "src_uid": "faa75751c05c3ff919ddd148c6784910", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun gcd(x: Int, y: Int): Int {\n if (x < y) return gcd(y, x)\n if (x % y == 0) return y\n return gcd(y, x % y)\n}\n\nfun main(args: Array) {\n var (l, r, t) = readLine()!!.split(\" \").map { it.toInt() }\n var (l2, r2, t2) = readLine()!!.split(\" \").map { it.toInt() }\n val g = gcd(t, t2)\n if (g == 1) {\n println(minOf(r - l + 1, r2 - l2 + 1))\n } else {\n var ans = 0\n if (l < l2) {\n var temp = (l2 - l) / g * g\n l += temp\n r += temp\n ans = maxOf(ans, minOf(r, r2) - maxOf(l, l2) + 1)\n l += g\n r += g\n ans = maxOf(ans, minOf(r, r2) - maxOf(l, l2) + 1)\n } else {\n var temp = (l - l2) / g * g\n l2 += temp\n r2 += temp\n ans = maxOf(ans, minOf(r, r2) - maxOf(l, l2) + 1)\n l2 += g\n r2 += g\n ans = maxOf(ans, minOf(r, r2) - maxOf(l, l2) + 1)\n }\n println(ans)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "f8a47b3d20d47b52a2b55c51a13227a9", "src_uid": "faa75751c05c3ff919ddd148c6784910", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "f66e5e1c69989e7224e85fb1657cb6ff", "src_uid": "5a052e4e6c64333d94c83df890b1183c", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "f791d5a7df16c4a086e7f0c623f98497", "src_uid": "5a052e4e6c64333d94c83df890b1183c", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "152cfda84dd3cc20671c632d9f1d67bd", "src_uid": "5a052e4e6c64333d94c83df890b1183c", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "d21e7bc57e5cdf42948656e7e96abb08", "src_uid": "5a052e4e6c64333d94c83df890b1183c", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(vararg args: String) {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n var countInside = 0\n val noPar = s.replace(\"\"\"\\((.*?)\\)\"\"\".toRegex()) {\n countInside += it.groupValues[1].splitToSequence('_').filter { it.length > 0 }.count()\n \"_\"\n }\n val maxLengthOutside = noPar.splitToSequence('_').map {it.length}.max() ?: 0\n println(\"$maxLengthOutside $countInside\")\n}\n", "lang_cluster": "Kotlin", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "4d5875596e04af0637a3a159da696a62", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.util.*\n\n//https://codeforces.com/problemset/problem/723/B\n\nfun main(args: Array) = with(Scanner(System.`in`)){\n val n = nextLine()!!.toInt()\n \n val str = nextLine()!!.toString()\n// println(\"str: $str\")\n val chars = str.toCharArray()\n\n var pStart = false\n var undStart = false\n var wStart = false\n\n var longestW = 0\n var wordsInsideP = 0\n\n var currentWCount = 0\n\n val underScC = '_'\n val pStartC = '('\n val pEndC = ')'\n\n for(c in chars){\n// print(\"current: $c, \")\n if(c == underScC){\n if(wStart){\n wStart = false\n if(pStart){\n wordsInsideP++\n } else {\n if(longestW < currentWCount){\n longestW = currentWCount\n }\n currentWCount = 0\n }\n }\n } else if (c == pStartC){\n pStart = true\n if(wStart) {\n wStart = false\n if(longestW < currentWCount){\n longestW = currentWCount\n }\n currentWCount = 0\n }\n } else if(c == pEndC) {\n pStart = false\n if(wStart) {\n wStart = false\n wordsInsideP++\n }\n } else {\n wStart = true\n if(!pStart){\n currentWCount++\n }\n }\n }\n if(wStart){\n if(longestW < currentWCount){\n longestW = currentWCount\n currentWCount = 0\n }\n }\n println(\"$longestW $wordsInsideP\")\n}\n", "lang_cluster": "Kotlin", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "40659036814eb474af3b53ef13158c10", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//region TEMPLATE\n@file:Suppress(\"CanBeVal\")\n\nimport java.io.*;\nimport java.io.BufferedReader\nimport java.math.BigInteger\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main(args: Array) {\n if (args.isNotEmpty() && args.first() == \"file\") {\n reader = BufferedReader(FileReader(\"input.txt\"))\n out = PrintWriter(FileWriter(\"output.txt\"))\n do {\n solve()\n out.println(\"\\n\")\n out.flush()\n } while (reader.readLine() != null)\n } else {\n reader = BufferedReader(InputStreamReader(System.`in`))\n out = PrintWriter(OutputStreamWriter(System.out))\n solve()\n }\n reader.close()\n out.close()\n}\n\nlateinit var out: PrintWriter\nlateinit var reader: BufferedReader\nvar tokenizer: StringTokenizer? = null\nfun read(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(readLn())\n }\n return tokenizer!!.nextToken()\n}\n\nfun readInt() = read().toInt()\nfun readLong() = read().toLong()\nfun readLn() = reader.readLine()!!\nfun readInts() = readLn().split(\" \").map { it.toInt() }\nfun readInts(sz: Int) = Array(sz) { readInt() }\nfun readLongs() = readLn().split(\" \").map { it.toLong() }\nfun readLongs(sz: Int) = Array(sz) { readLong() }\nfun print(b: Boolean) = out.print(b)\nfun print(i: Int) = out.print(i)\nfun print(d: Double) = out.print(d)\nfun print(l: Long) = out.print(l)\nfun print(s: String) = out.print(s)\nfun print(message: Any?) = out.print(message)\nfun print(a: Array) = a.forEach { print(\"$it \") }\nfun print(a: Array) = a.forEach { print(\"$it \") }\nfun print(a: Collection) = a.forEach { print(\"$it \") }\nfun println(b: Boolean) = out.println(b)\nfun println(i: Int) = out.println(i)\nfun println(d: Double) = out.println(d)\nfun println(l: Long) = out.println(l)\nfun println(s: String) = out.println(s)\nfun println() = out.println()\nfun println(message: Any?) = out.println(message)\nfun println(a: Array) {\n a.forEach { print(\"$it \") }\n println()\n}\n\nfun println(a: IntArray) {\n a.forEach { print(\"$it \") }\n println()\n}\n\nfun println(a: Collection) {\n a.forEach { print(\"$it \") }\n println()\n}\n\nconst val M7 = 1000000007L\nconst val M9 = 1000000009L\nconst val MFFT = 998244353L\nfun zero(sz: Int) = IntArray(sz)\nfun zeroL(sz: Int) = LongArray(sz)\nfun init(vararg elements: T) = elements\nfun VI(n: Int = 0, init: Int = 0) = MutableList(n) { init }\nfun VVI(n: Int = 0, m: Int = 0, init: Int = 0) = MutableList(n) { VI(m, init) }\nfun , T2 : Comparable> pairCmp(): Comparator> {\n return Comparator { a, b ->\n val res = a.first.compareTo(b.first)\n if (res == 0) a.second.compareTo(b.second) else res\n }\n}\n//endregion\n\n\nfun solve() {\n var n = readInt()\n var s = read()\n var f = false\n var mx = 0\n var cnt = 0\n var i = 0\n while(i < n){\n if (s[i] == '('){\n f = true\n }\n if (s[i] == ')'){\n f = false\n }\n if (s[i].isLetter()){\n var j = i\n while(j < n && s[j].isLetter()){\n j++\n }\n if (f){\n cnt++\n } else {\n mx = max(mx, j - i)\n }\n i = j - 1\n }\n i++\n }\n print(\"${mx} ${cnt}\")\n\n}", "lang_cluster": "Kotlin", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "c33132593704c3845a7bbb77f5f36149", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n br.readLine()\n\n val s = br.readLine() + \"_\"\n\n var longestWord = 0\n var wordCount = 0\n var inParentheses = false\n var charCount = 0\n\n fun wordSplit() {\n if (charCount > 0)\n if (inParentheses) {\n wordCount++\n } else {\n longestWord = Math.max(longestWord, charCount)\n }\n charCount = 0\n }\n\n fun character() {\n charCount++\n }\n\n\n s.forEach {\n when (it) {\n '_' -> wordSplit()\n '(' -> {\n wordSplit()\n inParentheses = true\n }\n ')' -> {\n wordSplit()\n inParentheses = false\n }\n else -> character()\n }\n }\n\n println(\"$longestWord $wordCount\")\n\n}\n", "lang_cluster": "Kotlin", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "594f2e50c99ea00ff2b4625cb67d9d64", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main() {\n var insideParenthesis = false\n readLine()\n var countInside = 0\n var maxOutside = 0\n var count = 0\n for (c in readLine()!!)\n when (c) {\n '_' -> {\n if (insideParenthesis && count > 0) countInside++\n count = 0\n }\n '(' -> {\n insideParenthesis = true\n count = 0\n }\n ')' -> {\n if (count > 0) countInside++\n insideParenthesis = false\n count = 0\n }\n else -> {\n count++\n if (!insideParenthesis) maxOutside = max(maxOutside, count)\n }\n }\n print(\"$maxOutside $countInside\")\n}", "lang_cluster": "Kotlin", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "f5621a40ece0f26b20695dd52708f9b1", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 var cntIn = 0\n var maxOut = 0\n next()\n val words = next().split('(', ')')\n for (i in words.indices) {\n val s = words[i]\n for (w in s.split('_').filter { it != \"\" }) {\n if (i % 2 == 0)\n maxOut = Math.max(maxOut, w.length)\n else\n cntIn++\n }\n }\n fout.print(\"%d %d\".format(maxOut, cntIn))\n\n fout.close()\n fin.close()\n}\n\n", "lang_cluster": "Kotlin", "tags": ["expression parsing", "strings", "implementation"], "code_uid": "79f569c08a5e1e732635dfb5c4641aaa", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.lang.Math.*\nimport java.math.BigInteger\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\nimport kotlin.math.sqrt\n\ntypealias IndexPair = Pair\ntypealias IntIndexPair = IndexPair\ntypealias IntIntPair = Pair\n\ntypealias IntMatrix = Array\ntypealias LongMatrix = Array\n\ntypealias ListArray = Array>\n\ntypealias Graph = IntMatrix\n\ntypealias Edge = Pair\ntypealias EdgeArray = Array\ntypealias WeightedGraph = Array\n\ntypealias TotalEdge = Triple\ntypealias TotalEdgeArray = Array\n\nfun init() { }\n\nconst val MODULO = 1000 * 1000 * 1000 + 7\n\nfun solve() {\n val n = readLong() - 1\n\n var nearestRoot = sqrt(n * 2.0).toLong()\n while (nearestRoot * (nearestRoot + 1) > 2 * n) --nearestRoot\n val sum = nearestRoot * (nearestRoot + 1) / 2\n\n val answer = n - sum\n out.println(answer + 1)\n}\n\nfun stress() {\n val rnd = Random(1234)\n\n for (it in 0 until 100) {\n val expected = brute()\n val actual = fast()\n\n if (expected != actual) {\n System.err.println(\"Gotcha!\")\n System.err.println(\"$expected $actual\")\n\n break\n }\n }\n}\n\n\nfun fast() {\n\n}\n\nfun brute() {\n\n}\n\nfun Long.mod() : Long {\n var result = this % MODULO\n if (result < 0) result += MODULO\n return result\n}\n\ninfix fun Long.add(other : Long) = (this + other).mod()\ninfix fun Long.sub(other : Long) = this add -other.mod()\ninfix fun Long.mult(other : Long) = (this.mod() * other.mod()).mod()\n\nfun Long.even() = (this and 1L) == 0L\nfun Long.odd() = !even()\n\nfun Int.even() = (this and 1) == 0\nfun Int.odd() = !even()\n\ninfix fun Long.binpow(power : Long) : Long {\n if (power == 0L) return 1L\n\n val half = binpow(power shl 1)\n\n var result = half mult half\n if (power.odd()) {\n result = result mult this\n }\n\n return result\n}\n\nval stepsXY = arrayOf(\n arrayOf(0, -1),\n arrayOf(0, 1),\n arrayOf(-1, 0),\n arrayOf(1, 0)\n)\n\n\n\nclass IndexedWeightedGraph(private val n : Int, private val edges: TotalEdgeArray) {\n\n private val graph : Graph\n\n private fun buildGraphForEdges(\n edgeFilter : (index : Int, edge : TotalEdge) -> Boolean = { _, _ -> true }\n ) : Graph {\n val builder = GraphBuilder()\n edges\n .forEachIndexed { index, edge ->\n if (edgeFilter(index, edge)) {\n val (first, second, _ ) = edge\n\n builder.addDirectedEdge(first, index)\n builder.addDirectedEdge(second, index)\n }\n }\n\n return builder.build(n)\n }\n\n init {\n graph = buildGraphForEdges()\n }\n\n var root : Int = -1\n lateinit var inTree : BooleanArray\n lateinit var tree : Graph\n\n fun kruskalTree(root : Int) : Long {\n this.root = root\n\n inTree = BooleanArray(edges.size) { false }\n\n val dsu = DSU(n)\n\n edges\n .mapIndexed { index, (_, _, w) -> index to w }\n .sortedBy { it.second }\n .forEach {\n val edge = edges[it.first]\n inTree[it.first] = dsu.union(edge.first, edge.second)\n }\n\n tree = buildGraphForEdges { index, _ -> inTree[index] }\n\n return edges\n .mapIndexed { index, (_, _, w) -> if (inTree[index]) w.toLong() else 0L }\n .sum()\n }\n\n private fun to(from : Int, index : Int) : Int {\n val edge = edges[index]\n return if (from == edge.first) edge.second else edge.first\n }\n\n fun buildLca() {\n calculateTimes()\n calculateParents()\n calculatePathInfo()\n }\n\n lateinit var timesIn : IntArray\n lateinit var timesOut : IntArray\n private var time = -1\n\n private fun calculateTimes() {\n timesIn = IntArray(n) { -1 }\n timesOut = IntArray(n) { -1 }\n this.time = 0\n\n timeDfs(root)\n }\n\n private fun timeDfs(from : Int, parent : Int = -1) {\n timesIn[from] = time++\n\n for (index in tree[from]) {\n val to = to(from, index)\n if (to == parent) continue\n\n timeDfs(to, from)\n }\n\n timesOut[from] = time++\n }\n\n lateinit var parents : Array\n private val maxBit = 19\n\n private fun calculateParents() {\n parents = Array(maxBit) { IntArray(n) { -1 } }\n\n parentDfs(root, root)\n\n for (bit in 0 until maxBit - 1) {\n for (v in 0 until n) {\n val parent = parents[bit][v]\n parents[bit + 1][v] = parents[bit][parent]\n }\n }\n }\n\n private fun parentDfs(from : Int, parent : Int = -1) {\n parents[0][from] = parent\n\n for (index in tree[from]) {\n val to = to(from, index)\n if (to == parent) continue\n\n parentDfs(to, from)\n }\n }\n\n lateinit var maxEdges : Array\n\n private fun calculatePathInfo() {\n maxEdges = Array(maxBit) { IntArray(n) { -1 } }\n\n for (v in 0 until n){\n for (index in tree[v]) {\n val to = to(v, index)\n if (to == parents[0][v]) continue\n\n maxEdges[0][to] = edges[index].third\n }\n }\n\n for (bit in 0 until maxBit - 1) {\n for (v in 0 until n) {\n val parent = parents[bit][v]\n maxEdges[bit + 1][v] = max(\n maxEdges[bit][v],\n maxEdges[bit][parent]\n )\n }\n }\n }\n\n fun getOnPath(a : Int, b : Int) : Int {\n var answer = Int.MIN_VALUE\n\n answer = max(answer, getOnLcaPath(a, b))\n answer = max(answer, getOnLcaPath(b, a))\n\n return answer\n }\n\n private fun getOnLcaPath(start : Int, other : Int) : Int {\n var answer = Int.MIN_VALUE\n\n if (timesIn[start] <= timesIn[other] && timesOut[other] <= timesOut[start]) {\n return answer\n }\n\n var v = start\n for (bit in maxBit - 1 downTo 0) {\n val parent = parents[bit][v]\n if (timesIn[parent] > timesIn[other] || timesOut[other] > timesOut[parent]) {\n answer = max(answer, maxEdges[bit][v])\n v = parent\n }\n }\n\n answer = max(answer, maxEdges[0][v])\n\n return answer\n }\n}\n\nfun yesNo(yes : Boolean) {\n out.println(if (yes) \"YES\" else \"NO\")\n}\n\nfun run() {\n init()\n solve()\n out.close()\n}\n\nfun main(args: Array) {\n run()\n}\n\nval ONLINE_JUDGE = !File(\"input.txt\").exists()\n\nval input = BufferedReader(\n if (ONLINE_JUDGE) InputStreamReader(System.`in`) else FileReader(\"input.txt\")\n)\nval out =\n if (ONLINE_JUDGE) PrintWriter(System.out)\n else PrintWriter(\"output.txt\")\n\nfun readStrings(separator: String = \" \", emptyWords: Boolean = false) : Array {\n val line = input.readLine()\n\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 readString(separator: String = \" \") =\n readStrings(separator).first()\n\nfun readInts(separator: String = \" \") =\n readStrings(separator).map(String::toInt).toIntArray()\n\nfun readDecreasedInts(separator : String = \" \") =\n readInts(separator).map { it - 1 }.toIntArray()\n\nfun readSortedInts(separator: String = \" \") : IntArray {\n val a = readInts(separator)\n\n val aInteger = Array(a.size) { a[it] }\n Arrays.sort(aInteger)\n\n return aInteger.toIntArray()\n}\n\nfun readInt(separator: String = \" \") =\n readInts(separator).first()\n\nfun readLongs(separator: String = \" \") =\n readStrings(separator).map(String::toLong).toLongArray()\n\nfun readLong(separator: String = \" \") =\n readLongs(separator).first()\n\nfun readDoubles(separator: String = \" \") =\n readStrings(separator).map(String::toDouble).toDoubleArray()\n\nfun readDouble(separator: String = \" \") =\n readDoubles(separator).first()\n\nfun readBigIntegers(separator: String = \" \") =\n readStrings(separator).map { BigInteger(it) }.toTypedArray()\n\nfun readBigInteger(separator: String = \" \") =\n readBigIntegers(separator).first()\n\nfun readTree(n : Int, indexing : Int = 1) =\n readGraph(n, n - 1, true, indexing)\n\nfun readGraph(n: Int, m : Int,\n undirected : Boolean = true,\n indexing : Int = 1) : Graph {\n val builder = GraphBuilder()\n\n for (i in 1..m) {\n var (from, to) = readInts()\n\n from -= indexing\n to -= indexing\n\n if (undirected) builder.addEdge(from, to)\n else builder.addDirectedEdge(from, to)\n }\n\n return builder.build(n)\n}\n\nfun readWeightedGraph(n : Int, m : Int,\n undirected : Boolean = true,\n indexing : Int = 1) : WeightedGraph {\n val builder = GraphBuilder()\n\n for (i in 1..m) {\n var (from, to, weight) = readInts()\n\n from -= indexing\n to -= indexing\n\n if (undirected) builder.addEdge(from, to, weight)\n else builder.addDirectedEdge(from, to, weight)\n }\n\n return builder.buildWeighted(n)\n}\n\nfun readTotalEdges(m : Int, indexing : Int = 1) =\n TotalEdgeArray(m) {\n var (from, to, w) = readInts()\n\n from -= indexing\n to -= indexing\n\n Triple(from, to, w)\n }\n\nclass GraphBuilder {\n\n private val froms = ArrayList()\n private val tos = ArrayList()\n private val weights = ArrayList()\n\n fun addEdge(from : Int, to : Int, weight : Int = 1) {\n addDirectedEdge(from, to, weight)\n addDirectedEdge(to, from, weight)\n }\n\n fun addDirectedEdge(from : Int, to : Int, weight : Int = 1) {\n froms.add(from)\n tos.add(to)\n weights.add(weight)\n }\n\n private fun calculateFromSizes(n : Int) : IntArray {\n val sizes = IntArray(n) { 0 }\n froms.forEach { ++sizes[it] }\n return sizes\n }\n\n fun build(n : Int) : Graph {\n val sizes = calculateFromSizes(n)\n\n val graph = Graph(n) { IntArray(sizes[it]) { 0 } }\n\n for (i in 0 until n) {\n sizes[i] = 0\n }\n\n for (i in 0 until froms.size) {\n val from = froms[i]\n val to = tos[i]\n\n graph[from][sizes[from]++] = to\n }\n\n return graph\n }\n\n fun buildWeighted(n : Int) : WeightedGraph {\n val sizes = calculateFromSizes(n)\n\n val graph = WeightedGraph(n) { EdgeArray(sizes[it]) { -1 to 0 } }\n\n for (i in 0 until n) {\n sizes[i] = 0\n }\n\n for (i in 0 until froms.size) {\n val from = froms[i]\n val to = tos[i]\n val weight = weights[i]\n\n graph[from][sizes[from]++] = to to weight\n }\n\n return graph\n }\n}\n\nfun gcd(a : Int, b : Int) : Int =\n if (a == 0) b else gcd(b % a, a)\n\nfun gcd(a : Long, b : Long) : Long =\n if (a == 0L) b else gcd(b % a, a)\n\nfun getDivisors(x : Int) : MutableList {\n val divisors = ArrayList()\n\n var d = 1\n while (d * d <= x) {\n if (x % d == 0) {\n if (d != 1) divisors.add(d)\n if (x != d) divisors.add(x / d)\n }\n\n ++d\n }\n\n return divisors\n}\n\nfun getPrimeDivisors(xx : Int) : MutableList {\n val divisors = ArrayList()\n\n var d = 2\n var x = xx\n while (d * d <= x) {\n if (x % d == 0) {\n divisors.add(d)\n while (x % d == 0) {\n x /= d\n }\n }\n\n ++d\n }\n\n if (x > 1) divisors.add(x)\n\n return divisors\n}\n\nfun checkIndex(index : Int, size : Int) =\n 0 <= index && index < size\n\nfun checkCell(x : Int, n : Int, y : Int, m : Int) =\n checkIndex(x, n) && checkIndex(y, m)\n\nfun toChar(index : Int, start : Char) =\n (index + start.toInt()).toChar()\n\nclass DSU {\n\n var sizes : IntArray\n var ranks : IntArray\n var parents : IntArray\n\n constructor(n : Int)\n : this(\n IntArray(n) { 1 }\n )\n\n constructor(sizes : IntArray) {\n val size = sizes.size\n this.sizes = sizes\n this.ranks = IntArray(size) { 1 }\n this.parents = IntArray(size) { it }\n }\n\n operator fun get(v : Int) : Int {\n val parent = parents[v]\n if (parent == v) return v\n parents[v] = get(parent)\n return parents[v]\n }\n\n fun union(aUniting : Int, bUniting : Int) : Boolean {\n var a = get(aUniting)\n var b = get(bUniting)\n\n if (a == b) return false\n\n if (ranks[a] < ranks[b]) {\n val tmp = a\n a = b\n b = tmp\n }\n\n parents[b] = a\n sizes[a] += sizes[b]\n if (ranks[a] == ranks[b]) ++ranks[a]\n\n return true\n }\n\n fun size(v : Int) : Int = sizes[get(v)]\n}\n\nclass FenwickTree(n : Int) {\n\n val size = n + 1\n val tree = LongArray(size) { 0L }\n\n fun update(index : Int, delta : Int) {\n var x = index + 1\n while (x < size) {\n tree[x] = tree[x] + delta\n x += x and -x\n }\n }\n\n operator fun get(start : Int, end : Int) =\n get(end) - get(start - 1)\n\n operator fun get(index : Int) : Long {\n var result : Long = 0\n\n var x = index + 1\n while (x > 0) {\n result += tree[x]\n x -= x and -x\n }\n\n return result\n }\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "0ba99ec23cc65a853f2469f8c50bf06f", "src_uid": "1db5631847085815461c617854b08ee5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLong() - 1\n\n val bs = (1..2e7.toLong()).binarySearchBy {\n regime(it).compareTo(n)\n }\n\n val l = bs.value - if(bs.exactFound) 0 else 1\n val ans = n - regime(l) + 1\n\n println(ans)\n}\n\nfun regime(l: Long) = l * (l-1) / 2\n\nfun LongRange.binarySearchBy(goldilocks: (Long) -> 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 = goldilocks(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 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() }", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "98a853942e21297e424e3d0fb9415c0b", "src_uid": "1db5631847085815461c617854b08ee5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Long.min\n\nfun main() {\n val count = readLine()!!.toInt()\n val dp = Array(count) { i -> LongArray(count - i) { Long.MAX_VALUE / 3 } }\n dp[0].fill(0)\n dp[1].fill(0)\n for (left in 0 until count - 2) {\n dp[2][left] = 1L * (left + 1) * (left + 2) * (left + 3)\n }\n\n for (length in 3 until count) {\n for (left in 0 until count - length) {\n val right = left + length\n val mult = 1L * (left + 1) * (right + 1)\n for (midPoint in left + 1 until right) {\n dp[length][left] = min(dp[length][left],\n dp[midPoint - left][left] + dp[right - midPoint][midPoint] + mult * (midPoint + 1))\n }\n }\n }\n println(dp[count - 1][0])\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "dp"], "code_uid": "5af97dda2dcd5bc80a419dd22495a181", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\nimport kotlin.math.max\nimport kotlin.math.sqrt\n\nprivate fun cin_ch() = readLine()!!.split(\" \").map{it.toInt()}\nprivate fun cin_array() = readLine()!!.split(\" \").map(String::toInt)\nprivate fun cin_string() = readLine()!!.split(\" \")\n\nfun main() {\nvar n = cin_ch()[0];\nvar ans = 0;\nfor (i in 3..n) {\nans+=i*(i-1);\n}\nprintln(ans);\nreturn;\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "dp"], "code_uid": "7557ada684c8816702144396bd05f0e6", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package com.happypeople.codeforces.c1140\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\n\nfun main(args: Array) {\n try {\n D1140().run()\n } catch (e: Throwable) {\n println(\"\")\n e.printStackTrace()\n }\n}\n\nclass D1140 {\n fun run() {\n val sc = Scanner(systemIn())\n val n=sc.nextInt()\n var ans=0L\n for(i in 3..n)\n ans+=(i*(i-1))\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}\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "dp"], "code_uid": "c29bc791282cd00bb368327392477523", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\ntypealias Pii = Pair\ntypealias Pll = Pair\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n var n = nextInt();\n var ans:Long = 0;\n for (i in 3..n) {\n ans += (i - 1) * i;\n }\n println(\"$ans\");\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "dp"], "code_uid": "08d1d333263f6c6ca1381d2cd88c7f5e", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val l = r.readLine()!!.toInt()\n //val time = r.readLine()!!.split(\" \").map { it.toInt() }.sorted()\n var black = 0\n var white = 0\n repeat(8){\n val board = r.readLine()!!\n board.forEach {\n when(it){\n 'q' -> black += 9\n 'r' -> black += 5\n 'b' -> black += 3\n 'n' -> black += 3\n 'p' -> black += 1\n 'Q' -> white += 9\n 'R' -> white += 5\n 'B' -> white += 3\n 'N' -> white += 3\n 'P' -> white += 1\n }\n }\n }\n println(when{\n black>white -> \"Black\"\n white>black -> \"White\"\n else -> \"Draw\"\n })\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d4577dbec439e6c702dd00fd26948148", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun Boolean.toInt() = if (this) 1 else 0\n\n val map = mapOf('q' to 9, 'r' to 5, 'b' to 3, 'n' to 3, 'p' to 1, '.' to 0, 'k' to 0)\n val sums = intArrayOf(0, 0)\n repeat(8) {\n for (c in readLine()!!)\n sums[c.isUpperCase().toInt()] += map[c.toLowerCase()] ?: error(\"not recognixed piece\")\n }\n print(if (sums[0] > sums[1]) \"Black\" else if (sums[0] == sums[1]) \"Draw\" else \"White\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "3d72c8cc666c34eb451689cf53294413", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 var black:Int = 0\n var white:Int = 0\n for (i in 1..8) {\n \t\tval str = readLine()!!\n for (c in str) {\n black = when(c) {\n 'q' -> black + 9\n 'r' -> black + 5\n 'b' -> black + 3\n 'n' -> black + 3\n 'p' -> black + 1\n else -> black\n }\n white = when(c) {\n 'Q' -> white + 9\n 'R' -> white + 5\n 'B' -> white + 3\n 'N' -> white + 3\n 'P' -> white + 1\n else -> white\n }\n }\n }\n if (black == white ) {\n println(\"Draw\")\n return\n } \n if (black > white ){\n println(\"Black\")\n } else {\n println(\"White\")\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "fc35e3fbafbc5e585ff162c3ed0941b3", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n (0 until 8).sumBy {\n readLine()!!.sumBy { when(it.toLowerCase()){\n 'q' -> 9\n 'r' -> 5\n 'b','n' -> 3\n 'p' -> 1\n else -> 0\n } * if (it.isUpperCase()) 1 else -1 }\n }.let { println(when {\n it < 0 -> \"Black\"\n it > 0 -> \"White\"\n else -> \"Draw\"\n })\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2184b484a31c7ac32959032edc6b2c8f", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readLong() = readLine()!!.toLong()\n\n val n = readLong()\n var a = 0L\n while (a * 10 + 9 <= n) a = a * 10 + 9\n var b = n - a\n var sol = 0L\n while (a > 0) {\n sol += a % 10\n a /= 10\n }\n while (b > 0) {\n sol += b % 10\n b /= 10\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "99e671b1506a2fea2984edb5a5b61b82", "src_uid": "5c61b4a4728070b9de49d72831cd2329", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()\n val x = if (n!!.length > 1) \"9\".repeat(n.length - 1) else \"0\"\n val y = (n.toBigInteger() - x.toBigInteger()).toString()\n println(x.map {it -> it.toString().toInt()}.reduce {s, sum -> s + sum}\n + y.map {it -> it.toString().toInt()}.reduce {s, sum -> s + sum})\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "607ceb0ec8205e009e3b6847abe5f591", "src_uid": "5c61b4a4728070b9de49d72831cd2329", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.log10\nfun ffff(d : Int):Long\n{\n var s = 0L\n var d2 = d\n while(d2>0){\n s += Math.pow(10.0,(d2-1L).toDouble()).toLong()*9\n d2--\n }\n return s\n}\nfun main(args: Array) {\n val n = readLine()!!.toLong()\n val bas = log10(n.toDouble()).toInt() + 1\n //println(bas)\n val s1 = ffff(bas-1)\n var s2 = n-s1\n var t = 0\n //println(s2)\n while (s2>0)\n {\n t+=(s2 % 10L).toInt()\n s2/=10L\n }\n t += 9*(bas-1)\n println(t)\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "8d5128b7528aadd9658c9d6a05257b03", "src_uid": "5c61b4a4728070b9de49d72831cd2329", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.FileInputStream\nimport java.math.BigDecimal\nimport java.util.*\nimport kotlin.Comparator\n\nobject programkt {\n fun S(n0: Long): Long {\n var res = 0L\n var n = n0\n while (n > 0) {\n res += n % 10\n n = n / 10\n }\n return res\n }\n\n fun solveDumb(n: Long) =\n LongRange(0, n)\n .map { it -> Pair(S(it) + S(n - it), it) }\n .maxWith(\n object : Comparator> {\n override fun compare(o1: Pair, o2: Pair): Int {\n if (o1.first == o2.first)\n return o1.second.compareTo(o2.second)\n else\n return o1.first.compareTo(o2.first)\n }\n }\n )!!\n\n fun solve(n: Long): Long {\n if (n < 10)\n return n\n else {\n var n10 = 1L\n while (n10 * 10 <= n) {\n n10 *= 10\n }\n val a = n / n10 * n10 - 1\n val b = n - a\n return S(a) + S(b)\n }\n }\n\n @JvmStatic fun main(args: Array) {\n if (args.size == 1)\n System.setIn(FileInputStream(args[0]))\n //val sc = Scanner(System.`in`)\n\n LongRange(0, 100).forEach {\n //println(\"$it \" + solveDumb(it))\n assert(solveDumb(it).first == solve(it))\n }\n\n println(solve(BigDecimal(readLine()).toLong()))\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "154318233225cc618ea4dc7c1c5736d7", "src_uid": "5c61b4a4728070b9de49d72831cd2329", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private fun readLn() = readLine()!!\nprivate fun readString() = readLn().trim()\nprivate fun readInt() = readLn().toInt()\nprivate fun readLong() = readLn().toLong()\nprivate val regSpace = \"\\\\s+\".toRegex()\nprivate fun readSomeInts(): List {\n return readLn().trim().split(regSpace).map { it.toInt() }\n}\nprivate fun readSomeLongs(): List {\n return readLn().trim().split(regSpace).map { it.toLong() }\n}\n\ndata class Point(val row: Int, val col: Int)\n\nfun main() {\n val (n, m) = readSomeInts()\n\n fun neighbors(p: Point): List {\n val acc = mutableListOf()\n if (p.row > 0) {\n acc.add(Point(p.row - 1, p.col))\n }\n if (p.col > 0) {\n acc.add(Point(p.row, p.col - 1))\n }\n if (p.col < m - 1) {\n acc.add(Point(p.row, p.col + 1))\n }\n if (p.row < n - 1) {\n acc.add(Point(p.row + 1, p.col))\n }\n return acc\n }\n\n val field = mutableListOf().apply {\n repeat(n) {\n val s = readString()\n this.add(s)\n }\n }.toList()\n\n fun hasWolf(p: Point) = field[p.row][p.col] == 'W'\n\n val wolfNotHangry = Array(n) { BooleanArray(m) }\n\n var countEatenPigs = 0\n for (i in 0 until n) {\n for (j in 0 until m) {\n if (field[i][j] == 'P') {\n val pigPt = Point(i, j)\n val anyWolf = neighbors(pigPt)\n .firstOrNull { pt -> hasWolf(pt) && !wolfNotHangry[pt.row][pt.col] }\n if (anyWolf != null) {\n wolfNotHangry[anyWolf.row][anyWolf.col] = true\n countEatenPigs++\n }\n }\n }\n }\n println(countEatenPigs)\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "81946a9302e615a5b888505a5cf6b7b7", "src_uid": "969b24ed98d916184821b2b2f8fd3aac", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (numRows, numCols) = readLine()!!.split(\" \").map(String::toInt)\n val board = Array(numRows + 2) { ArrayList(numCols + 2) }\n board[0] = arrayListOf(*(1..numCols + 2).map { '.' }.toTypedArray())\n for (i in 1..numRows) {\n val l = arrayListOf('.')\n l.addAll(readLine()!!.toCharArray().toList())\n l.add('.')\n board[i] = l\n }\n board[numRows + 1] = arrayListOf(*(1..numCols + 2).map { '.' }.toTypedArray())\n var sol = 0\n for (row in 1..numRows)\n for (col in 1..numCols)\n if (board[row][col] == 'P')\n when {\n board[row - 1][col] == 'W' -> {\n sol++\n board[row - 1][col] = '.'\n }\n board[row][col - 1] == 'W' -> {\n sol++\n board[row][col - 1] = '.'\n }\n board[row][col + 1] == 'W' -> {\n sol++\n board[row][col + 1] = '.'\n }\n board[row + 1][col] == 'W' -> {\n sol++\n board[row + 1][col] = '.'\n }\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "a4e43ae9a1d893f7b68d1c6edb8adda7", "src_uid": "969b24ed98d916184821b2b2f8fd3aac", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val table = Table()\n\n val notEatenPig: (Cell) -> Boolean = { it is PigCell && !it.eaten }\n\n // eat variant pig\n fun eatPig(nearbyCount: Int): Int {\n var eatCount = 0\n table.forEachIndexed { x, y, cell ->\n if (cell is WolfeCell && !cell.eat) {\n val nearbyPigs = table.nearby(x, y, notEatenPig)\n if (nearbyPigs.size == nearbyCount) {\n cell.eat = true\n (nearbyPigs.first() as PigCell).eaten = true\n eatCount += 1\n }\n }\n }\n return eatCount\n }\n\n println((1..4).fold(0) { acc, count -> acc + eatPig(count) })\n}\n\nclass Table {\n private val matrix: List>\n private val n: Int\n private val m: Int\n\n init {\n readLine()!!.split(\" \")\n .map(String::toInt)\n .also {\n n = it[0]\n m = it[1]\n }\n\n matrix = (0 until n).map {\n readLine()!!.toCharArray().take(m)\n .map {\n when (it) {\n 'P' -> PigCell()\n 'W' -> WolfeCell()\n '.' -> EmptyCell\n else -> throw IllegalArgumentException(\"Unknown animal\")\n }\n }\n }\n }\n\n fun forEachIndexed(action: (x: Int, y: Int, cell: Cell) -> Unit) {\n matrix.forEachIndexed { i, row ->\n row.forEachIndexed { j, cell -> action(i, j, cell) }\n }\n }\n\n private fun inRange(x: Int, y: Int) = x in 0 until n && y in 0 until m\n\n fun nearby(x: Int, y: Int, predicate: (Cell) -> Boolean): List {\n return listOf(\n Pair(x - 1, y), // left\n Pair(x + 1, y), // right\n Pair(x, y - 1), // top\n Pair(x, y + 1) // bottom\n )\n .filter { (x, y) -> inRange(x, y) }\n .map { (x, y) -> matrix[x][y] }\n .filter(predicate)\n }\n}\n\nsealed class Cell\n\ndata class PigCell(\n var eaten: Boolean = false\n) : Cell()\n\ndata class WolfeCell(\n var eat: Boolean = false\n) : Cell()\n\nobject EmptyCell : Cell()", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "e54b2dc0fdc94e5622fa72aff91511bf", "src_uid": "969b24ed98d916184821b2b2f8fd3aac", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport kotlin.concurrent.thread\nimport java.io.IOException\nimport java.io.BufferedReader\nimport java.io.InputStream\nimport kotlin.*\nimport java.*\nimport java.io.OutputStream\nimport java.io.PrintWriter\nimport java.lang.ArithmeticException\nimport java.lang.Exception\nimport java.math.BigInteger\nimport java.security.cert.TrustAnchor\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashSet\nimport kotlin.system.exitProcess\n\nfun main() {\n val inputStream = System.`in`\n val outputStream = System.out\n val `in` = InputReader(inputStream)\n val out = PrintWriter(outputStream)\n val mod = 1000*1000*1000+7\n\n fun add(a:Int,b:Int):Int{\n if (a+b>=mod)\n return a+b-mod\n return a+b\n }\n fun sub(a:Int,b:Int):Int{\n if (a>=b)\n return a-b\n return a-b+mod\n }\n\n fun mul(a:Int,b:Int):Int{\n return (a.toLong()*b.toLong()%mod).toInt()\n }\n\n val n=`in`.nextInt()\n val m=`in`.nextInt()\n\n val dp=IntArray(n+1)\n dp[0]=1\n dp[1]=1\n for (i in 2..n){\n dp[i]=add(dp[i-1],dp[i-2])\n }\n val dp2=IntArray(m+1)\n dp2[0]=1\n dp2[1]=1\n for (i in 2..m){\n dp2[i]=add(dp2[i-1],dp2[i-2])\n }\n\n out.println(mul(2,sub(add(dp[n],dp2[m]),1)))\n\n out.close()\n\n}\n\n\ninternal 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 next().toLong()\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "b12a62bab4e10e89fe2b98690a682e41", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\")\n\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\nimport java.util.TreeMap\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 m = readInt()\n\n val F = ModIntArray(max(n, m) + 1)\n F[0] = ModInt(1)\n F[1] = ModInt(1)\n\n for(i in 2..F.lastIndex) {\n F[i] = F[i-1] + F[i-2]\n }\n\n val ans = (F[n] + F[m] - 1) * 2\n\n println(ans)\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 inline val indices get() = intArray.indices\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()", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "d0ce5723120519de454ec75021eb9ac0", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "val MOD = 1000000007L\n\nfun mod(x: Long) = (x % MOD + MOD) % MOD\n\ntailrec fun fib(n: Int, a: Long = 1, b: Long = 1): Long =\n if (n == 0) a\n else fib(n - 1, b, mod(a + b))\n\nfun main(args: Array) {\n val (n, m) = readLine()!!.split(' ').map { it.toInt() }\n\n println(mod(2L * mod(fib(n) + fib(m) - 1)))\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "98808fff3072c3b70285316f8f4638dd", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (x1, x2) = readInts()\n val n = minOf(x1, x2)\n val m = maxOf(x1, x2)\n val fib = LongArray(m + 1)\n fib[0] = 1\n fib[1] = 1\n for(i in 2..m) {\n fib[i] = (fib[i - 1] + fib[i - 2]) % mod\n }\n val f0 = LongArray(n + 1)\n f0[1] = fib[m - n + 1]\n for (i in 2..n) {\n f0[i] = (f0[i - 1] + fib[i - 2] + fib[m - n + i - 2]) % mod\n }\n println((f0[n] * 2) % mod)\n}\n\nprivate val mod = 1000000007L\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", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "29d1a66afbeb9d66f8927c82afd53f52", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\nimport kotlin.math.ceil\nimport kotlin.math.sqrt\n\nfun main(args : Array) {\n\n val reader = Scanner(System.`in`)\n var x: Int = reader.nextInt()\n var y: Int = reader.nextInt()\n\n var a = x.toDouble()\n var b = y.toDouble()\n var r = sqrt(a*a+b*b)\n\n\n if((x>=0 && y>=0) || (x<=0 && y<=0) ){\n if (ceil(r).toInt() == r.toInt() || ceil(r).toInt() % 2 == 1) {\n println(\"black\")\n } else if (ceil(r).toInt() % 2 == 0) {\n println(\"white\")\n }\n }\n else{\n if (ceil(r).toInt() == r.toInt() || ceil(r).toInt() % 2 == 0 ) {\n println(\"black\")\n } else if (ceil(r).toInt() % 2 == 1) {\n println(\"white\")\n }\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "geometry", "constructive algorithms", "implementation"], "code_uid": "b8adb39f829e04bb6df2940c0d6ae883", "src_uid": "8c92aac1bef5822848a136a1328346c6", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n readLine()\n val sizes = readInts().toSet().toList().sorted()\n for (pos in 0 until sizes.size - 2)\n if (sizes[pos] + 1 == sizes[pos + 1] && sizes[pos] + 2 == sizes[pos + 2]) return print(\"YES\")\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "sortings", "implementation"], "code_uid": "6f8f4787d28788eef7e45e6d6091c799", "src_uid": "d6c876a84c7b92141710be5d76536eab", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.nextInt()\n val b = BooleanArray(1001)\n reader.nextArrayInt(n).forEach { b[it] = true }\n for (i in 1..998) {\n if (b[i] && b[i + 1] && b[i + 2]) {\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "sortings", "implementation"], "code_uid": "530f96b1054855d7029d08d7eb783ab0", "src_uid": "d6c876a84c7b92141710be5d76536eab", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val cmd = readLine()!!\n val direction = mutableMapOf(\n 'L' to Pair(-1, 0),\n 'R' to Pair(1, 0),\n 'U' to Pair(0, -1),\n 'D' to Pair(0, 1)\n )\n val path = mutableListOf(Pair(0, 0))\n var x = 0\n var y = 0\n var i = 0\n for (step in cmd) {\n x += direction[step]!!.first\n y += direction[step]!!.second\n i++\n if (path.contains(Pair(x, y))) {\n println(\"BUG\")\n return\n }\n path.add(Pair(x, y))\n }\n val bfs = mutableListOf(Pair(Pair(0, 0), 0))\n val visited = mutableSetOf>()\n while (bfs.isNotEmpty()) {\n val front = bfs.first()\n if (front.first == Pair(x, y) && front.second < cmd.length) {\n println(\"BUG\")\n return\n }\n bfs.removeAt(0)\n for (d in direction.values) {\n val nx = front.first.first + d.first\n val ny = front.first.second + d.second\n val cell = Pair(nx, ny)\n if (!visited.contains(cell) && path.contains(cell)) {\n val ns = front.second + 1\n visited.add(Pair(nx, ny))\n bfs.add(Pair(Pair(nx, ny), ns))\n }\n }\n }\n println(\"OK\")\n}\n", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation", "graphs"], "code_uid": "987f4b3c853c1388205f2026759a8c8c", "src_uid": "bb7805cc9d1cc907b64371b209c564b3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "const val input =\n \"4 4\\n\" +\n \"3 4 1 0\\n\" +\n \"0 1 7 9\\n\"\n\nfun main(args: Array) {\n if (args.isNotEmpty() && args[0] == \"debug\") {\n System.setIn(input.byteInputStream())\n }\n\n taskA994()\n}\n\nfun taskA994() {\n val str = getIntString()\n val seq = getIntString()\n val nums = HashSet(getIntString())\n val n = str[0]\n val m = str[1]\n var result = \"\"\n for (i in 0 until n) {\n if (nums.contains(seq[i])) {\n result += seq[i].toString() + \" \"\n }\n }\n println(result)\n}\n\n\n\nfun getIntString() = readLine()!!\n .split(' ')\n .map { Integer.parseInt(it) }\n .toCollection(ArrayList())\n\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9ddbbd65a6455772b388a3ebbe177513", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n readLine() // val (n, m) = readLine()!!.split(\" \").map { it.toLong() }\n\n val sequence = readLine()!!.split(\" \").map { it.toLong() }\n val set = readLine()!!.split(\" \").map { it.toLong() }.toSet()\n\n println(sequence.filter { it in set }.joinToString(\" \"))\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c738b0e864ed69df45270bddf7dd61c0", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n\tval (n,m) = readLine()!!.split(' ').map { it.toInt() }\n\n\tval Xarr = readLine()!!.split(' ').map { it.toInt() }\n\tval Yarr = readLine()!!.split(' ').map { it.toInt() }\n\n\tval password = Xarr.intersect(Yarr)\n\n\tpassword.forEach { print(it.toString() +' ') }\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "28b5b02d458d3dcf036b0ccf067b3c89", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n val m = scanner.nextInt()\n val arr = IntArray(n) { scanner.nextInt() }\n val arr1 = IntArray(m) { scanner.nextInt() }\n arr.forEach { if (arr1.contains(it)) print(\"$it \") }\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//}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "29bdaf997574c801f5ce721ceb0882c9", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 a = reader.nextArrayInt(n)\n var ans = 0\n for (i in 1 until n) {\n when {\n a[i] == 2 && a[i - 1] == 3 || a[i] == 3 && a[i - 1] == 2 -> {\n writer.println(\"Infinite\")\n return\n }\n a[i] == 1 -> ans += if (a[i - 1] == 2) 3 else 4\n a[i] == 3 -> ans += 4\n a[i] == 2 -> {\n when {\n i == 1 -> ans += 3\n a[i - 2] == 2 -> ans += 3\n a[i - 2] == 3 -> ans += 2\n }\n }\n }\n }\n writer.println(\"Finite\")\n writer.println(ans)\n }\n\n fun clear() {\n writer.close()\n }\n\n private fun IntArray.gcd(): Int {\n var g = first()\n forEach { g = gcd(g, it) }\n return g\n }\n\n private fun LongArray.gcd(): Long {\n var g = first()\n forEach { g = gcd(g, it) }\n return g\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() {\n writer.println()\n }\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 printLongArray(array: LongArray) {\n array.forEach { writer.print(\"$it \") }\n writer.println()\n }\n\n fun printCharArray(array: CharArray) {\n array.forEach { writer.print(\"$it\") }\n writer.println()\n }\n\n fun close() {\n writer.close()\n }\n}", "lang_cluster": "Kotlin", "tags": ["geometry"], "code_uid": "7e18f1fbe47d5b36df9a74779cd85daf", "src_uid": "6c8f028f655cc77b05ed89a668273702", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readInt()\n val a = readInts()\n\n val ans = run {\n var cnt = 0\n for ((s0, s1) in a.zipWithNext()) {\n if(s0 == s1) return@run null\n\n when(s0) {\n 1 -> {\n when(s1) {\n 2 -> cnt += 3\n 3 -> cnt += 4\n }\n }\n 2 -> {\n when(s1) {\n 1 -> cnt += 3\n 3 -> return@run null\n }\n }\n 3 -> {\n when(s1) {\n 1 -> cnt += 4\n 2 -> return@run null\n }\n }\n }\n }\n cnt - a.windowed(3).count { it == listOf(3, 1, 2) }\n }\n\n output {\n if(ans == null) println(\"Infinite\") else {\n println(\"Finite\")\n println(ans)\n }\n }\n\n}\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", "lang_cluster": "Kotlin", "tags": ["geometry"], "code_uid": "507a9318a0408c305a2e856a5eb8d6ec", "src_uid": "6c8f028f655cc77b05ed89a668273702", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n var n = ni();\n var a = nia(n)\n var points = 0L\n for(i in 1 until n){\n if(a[i] == 1){\n if(a[i-1] == 2) points += 3\n if(a[i-1] == 3) points += 4\n }\n if(a[i] == 2){\n if(a[i-1] == 1) points += 3\n if(a[i-1] == 3){\n println(\"Infinite\")\n return\n }\n }\n if(a[i] == 3){\n if(a[i-1] == 1) points += 4\n if(a[i-1] == 2){\n println(\"Infinite\")\n return\n }\n }\n }\n for(i in 2 until n){\n if(a[i] == 2 && a[i-1] == 1 && a[i-2] == 3) points--\n }\n println(\"Finite\")\n println(points)\n}\n\nvar input = Scanner(System.`in`)\n\nfun ni() = input.nextInt()\n\nfun nia(n: Int) = Array(n) { ni() }\n\nfun nim(n: Int, m: Int) = Array(n) { nia(m) }\n\nfun nl() = input.nextLong()\n\nfun nla(n: Int) = Array(n) { nl() }\n\nfun nlm(n: Int, m: Int) = Array(n) { nla(m) }\n\nfun ns() = input.next()\n\nfun nsa(n: Int) = Array(n) { ns() }\n\nfun println(arr: Array<*>) = println(arr.fold(\"\") { r, n -> \"$r$n \" })", "lang_cluster": "Kotlin", "tags": ["geometry"], "code_uid": "ba84587c35250342c1bf268998b613d7", "src_uid": "6c8f028f655cc77b05ed89a668273702", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val args = readLine()!!.split(' ')\n val n = args[0].toLong()\n val k = args[1].toLong()\n\n var a = n / 2 - 1\n var b = n\n var minv = b\n\n while (true) {\n if (a > b) {\n break\n }\n val m = a + (b - a) / 2\n val mval = calc(m, k)\n if (mval > n) {\n if (m < minv) {\n minv = m\n }\n b = m - 1\n } else if (mval < n) {\n a = m + 1\n } else {\n if (m < minv) {\n minv = m\n }\n break\n }\n }\n println(minv)\n}\n\nfun calc(v: Long, k: Long): Long {\n var x = v\n var kk = k\n while (true) {\n val part = v / kk\n if (part == 0L) {\n return x\n }\n x += part\n kk *= k\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation", "binary search"], "code_uid": "2834a99ee8e82d57c899b73e83ab9396", "src_uid": "41dfc86d341082dd96e089ac5433dc04", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() {\n output {\n val n = readInt()\n val k = readInt()\n\n val ans = (1..n).binarySearchBy { v ->\n var c = 0L\n var d = 1L\n\n while(true) {\n val cn = v/d\n if(cn == 0L) break\n c += cn\n d *= k\n }\n\n if(c < n) -1 else 1\n }.ceil\n\n println(ans)\n }\n}\n\nfun IntRange.binarySearchBy(goldilocks: (Int) -> Int): BinarySearchResult {\n var low = start\n var high = endInclusive\n\n while (low <= high) {\n val mid = low.and(high) + low.xor(high).shr(1)\n val cmp = goldilocks(mid)\n\n when {\n cmp < 0 -> low = mid + 1\n cmp > 0 -> high = mid - 1\n else -> return BinarySearchResult(mid, true)\n }\n }\n return BinarySearchResult(low, false)\n}\nval BinarySearchResult.floor get() = if(exactFound) value else value - 1\ninline val BinarySearchResult.ceil get() = value\n\ndata class BinarySearchResult(val value: T, val exactFound: Boolean)\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", "lang_cluster": "Kotlin", "tags": ["implementation", "binary search"], "code_uid": "d5ec142a88b282dec8988858d5688265", "src_uid": "41dfc86d341082dd96e089ac5433dc04", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun calcSum (v: Int, k: Int): Int {\n tailrec fun go (summand: Int, acc: Int): Int =\n if (summand == 0) acc\n else go(summand/k, acc + summand)\n return go(v, 0)\n}\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val (n, k) = br.readLine().split(\" \").map { it.toInt() }\n var l = 1\n var r = n\n while (l < r) {\n val m = (l + r)/2\n val sum = calcSum(m, k)\n if (sum < n) {\n l = m + 1\n } else {\n r = m\n }\n }\n println(l)\n}", "lang_cluster": "Kotlin", "tags": ["implementation", "binary search"], "code_uid": "9ae9793afd2d3da1c4c7dbe37fc7da03", "src_uid": "41dfc86d341082dd96e089ac5433dc04", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner;\n\nfun main(args: Array) {\n var scan = Scanner(System.`in`);\n var area: Int = scan.nextInt();\n\n var sqrt: Int = Math.floor(Math.sqrt(area.toDouble())).toInt();\n var p: Int = sqrt * 4;\n var a: Int = sqrt * sqrt;\n var d: Int = area - a;\n if (area == a) {\n System.out.println(p);\n } else if (d <= sqrt) {\n System.out.println(p + 2);\n } else {\n System.out.println(p+4);\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "geometry"], "code_uid": "c9e357cc5f3848c981132f04c7f477d0", "src_uid": "414cc57550e31d98c1a6a56be6722a12", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.sqrt\n\nfun main() {\n val n = readLine()!!.toInt()\n val side = sqrt(n.toFloat()).toInt()\n for (a in side..side + 1)\n for (b in side..side + 1)\n if (a * b >= n) return print(2 * a + 2 * b)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "geometry"], "code_uid": "02ae5f0eae81b18f0cfdcdd813dda10b", "src_uid": "414cc57550e31d98c1a6a56be6722a12", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\n\n//val inp = BufferedReader(FileReader(\"input.txt\"))\n//val out = BufferedWriter(FileWriter(\"output.txt\"))\nval inp = BufferedReader(InputStreamReader(System.`in`))\nval out = BufferedWriter(OutputStreamWriter(System.out))\n\nfun main(args: Array ) {\n\n\tval s = inp.readLine() + \"A\"\n\n\tvar cur = -1\n\tvar ans = 0\n\tfor ( i in 0..s.length-1 ) {\n\t\tif ( s[i] in \"AEIOUY\" ) {\n\t\t\tans = Math.max ( ans, i - cur )\n\t\t\tcur = i\n\t\t}\n\t}\n\n\tout.write( ans.toString() + '\\n' )\n\tinp.close()\n\tout.close()\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "181eef4843c6653a7e8341d29593ea13", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\nfun main() {\n var const = \"AEIOUY\"\n var str = readLine()!!.split(\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\")\n var str1 = str.maxBy { it.length }\n println(str1!!.length+1)\n \n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "978bc7a230b4e30e80d08c1476228ff6", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 fun files(inputFilename: String, outputFilename: String) =\n ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))\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 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 s = \"A\" + io.readToken() + \"A\"\n val x = s.indices.filter({ i -> s[i] in \"AEIOUY\" }).toIntArray()\n val res = (0 .. x.lastIndex - 1).map({ i -> x[i + 1] - x[i] }).max()!!\n io.println(res)\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "ec637063218cc3634a21270c2ca9cf76", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * @author Egor Zhdan\n */\nobject In {\n private var tokens: List = emptyList()\n private var index = 0\n\n fun next(): String {\n while (index >= tokens.size) {\n tokens = readLine()!!.split(\" \")\n index = 0\n }\n return tokens[index++]\n }\n\n fun nextInt(): Int {\n return next().toInt()\n }\n\n fun nextLong(): Long {\n return next().toLong()\n }\n\n fun nextDouble(): Double {\n return next().toDouble()\n }\n}\n\n\nfun main(args: Array) {\n var ans = 1\n val s = readLine()!!\n var dist = 1\n for (c in s) {\n if (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' || c == 'Y') {\n ans = Math.max(ans, dist)\n dist = 0\n }\n dist++\n }\n ans = Math.max(ans, dist)\n\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "36251230c77308c123ddca3a3b0e83db", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.min\n\nval f0 = \"What are you doing at the end of the world? Are you busy? Will you save us?\"\nval left = \"What are you doing while sending \\\"\"\nval mid = \"\\\"? Are you busy? Will you send \\\"\"\nval right = \"\\\"?\"\n\nval MAXN = 100000\n\nfun main(args: Array ) {\n val l = LongArray( MAXN + 1, { 0 } )\n l[0] = f0.length.toLong()\n for ( i in 1 until l.size ) {\n l[i] = min( Long.MAX_VALUE / 4, l[i - 1] * 2 + left.length + mid.length + right.length )\n }\n\n// println( l.max() )\n// if ( l.any { it < 0 } ) throw RuntimeException()\n\n val sc = Scanner( System.`in` )\n val q = sc.nextInt()\n\n for ( qq in 1 .. q ) {\n var n = sc.nextInt()\n var p = sc.nextLong() - 1\n if ( p >= l[n] ) {\n print( \".\" )\n continue\n }\n while ( true ) {\n if ( n == 0 ) {\n print( f0[p.toInt()] )\n break\n }\n if ( p < left.length ) {\n print( left[p.toInt()] )\n break\n }\n p -= left.length\n if ( p < l[n - 1] ) {\n n --\n continue\n }\n p -= l[n - 1]\n if ( p < mid.length ) {\n print( mid[p.toInt()] )\n break\n }\n p -= mid.length\n if ( p < l[n - 1] ) {\n n --\n continue\n }\n p -= l[n - 1]\n print( right[p.toInt()] )\n break\n }\n }\n println()\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "binary search"], "code_uid": "f00c63ac3a2a1ae87aa87102b16defb9", "src_uid": "da09a893a33f2bf8fd00e321e16ab149", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 y = sc.nextInt()\n val maxn = 1001\n val c = Array(maxn + 2) { Array(maxn + 2) { 0L } }\n\n c[0][1] = 1L\n c[1][1] = 1L\n\n for (z in 1..maxn) {\n for (k in 0..z) {\n c[k][z + 1] += c[k][z]\n c[k + 1][z + 1] += c[k][z]\n }\n }\n\n val fact = Array(maxn + 1) { 0L }\n\n fact[0] = 1L\n for (i in 1..maxn) fact[i] = i * fact[i - 1]\n\n\n val p = Array(6) { 0L }\n for (z in 0..5) {\n var t = 1L\n for (j in z downTo 0) {\n p[z] += t * c[z - j][z] * fact[j]\n t *= -1\n }\n }\n p[0] = 1L\n\n\n var res = 0L\n for (x in n - y..n) {\n res += c[x][n] * p[n - x]\n }\n println(res)\n\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", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "9ad2e72d605c66d0390511143afca8db", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n val cin = Scanner(System.`in`)\n var n = cin.nextInt()\n var k = cin.nextInt()\n var ans = 1L\n var c = 1L\n var f = longArrayOf(1, 0, 1, 2, 9)\n for (i in 1..k) {\n c = c * (n - i + 1) / i;\n ans += c * f[i]\n }\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "738ad21b2f1777f97076c733587b5673", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val fac: (Int) -> Long = {n -> var res = 1L; for (p in 1 .. n) res *= p; res}\n\n fun d(n: Int): Long {\n val i: Int\n var res = 0L\n\n for (i in 0 .. n) {\n val sign = {it: Int -> if (it % 2 == 0) 1 else -1}(i)\n res += sign * fac(n) / fac(i)\n }\n return res\n }\n\n fun c(n: Int, m: Int): Long {\n var p = 1L\n for (i in (n - m + 1) .. n) {\n p *= i\n }\n return p / fac(m)\n }\n\n val s = readLine()!!.split(\" \").map { it -> it.toInt() }\n val n = s[0]\n val k = s[1]\n println((0 .. k).map { m -> c(n, m) * d(m) }.sum())\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "465c04bc6d740844ec54e11b4bf91d72", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "const val inf = 998244353L\n\nfun main() {\n val (n, m, k) = readLine()!!.split(\" \").map(String::toInt)\n val f = Array(n) {\n Array(k + 1) {\n 0L\n }\n }\n f[0][0] = m.toLong()\n for (i in 0..(n - 2))\n for (j in 0..k) {\n if (j != k)\n f[i + 1][j + 1] = (f[i + 1][j + 1] + f[i][j] * (m - 1)) % inf\n f[i + 1][j] = (f[i + 1][j] + f[i][j]) % inf\n }\n\n println(f[n - 1][k])\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "171a4382a57fd1e6241c25ab242bbbd4", "src_uid": "b2b9bee53e425fab1aa4d5468b9e578b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nobject Main {\n var `in`: IO? = null\n var out: PrintWriter? = null\n\n @Throws(Exception::class)\n fun init_io(filename: String) {\n if (filename == \"\") {\n `in` = IO(System.`in`)\n out = PrintWriter(BufferedWriter(OutputStreamWriter(System.out)), true)\n } else {\n `in` = IO(FileInputStream(\"$filename.in\"))\n out = PrintWriter(BufferedWriter(FileWriter(\"$filename.out\")), true)\n }\n }\n\n const val mod: Long = 998244353\n\n /*\nfun main(args: Array) {\n Main.main(args);\n}\n*/\n @Throws(Exception::class)\n fun solve(tc: Int) {\n val n = `in`!!.nlong()\n val m = `in`!!.nlong()\n val k = `in`!!.nlong()\n var nck: Long = 1\n for (i in 1..n - 1) nck = nck * i % mod\n for (i in 1..n - 1 - k) nck = nck * minv(i) % mod\n for (i in 1..k) nck = nck * minv(i) % mod\n var x = m\n for (i in 0 until k) x = x * (m - 1) % mod\n out!!.println(x * nck % mod)\n }\n\n @Throws(Exception::class)\n @JvmStatic\n fun main(_u_n_u_s_e_d_: Array) {\n init_io(\"\")\n val t = 1\n // t = in.nint();\n for (tc in 0 until t) {\n solve(tc)\n }\n }\n\n fun minv(v: Long): Long {\n return mpow(v, mod - 2)\n }\n\n fun mpow(base: Long, exp: Long): Long {\n var base = base\n var exp = exp\n var res: Long = 1\n while (exp > 0) {\n if (exp and 1 == 1L) {\n res = res * base % mod\n }\n base = base * base % mod\n exp = exp shr 1\n }\n return res\n }\n\n fun gcd(x: Long, y: Long): Long {\n return if (x == 0L) y else gcd(y % x, x)\n }\n\n fun rsort(arr: LongArray) {\n val r = Random()\n for (i in arr.indices) {\n val j = i + r.nextInt(arr.size - i)\n val t = arr[i]\n arr[i] = arr[j]\n arr[j] = t\n }\n Arrays.sort(arr)\n }\n\n fun rsort(arr: IntArray) {\n val r = Random()\n for (i in arr.indices) {\n val j = i + r.nextInt(arr.size - i)\n val t = arr[i]\n arr[i] = arr[j]\n arr[j] = t\n }\n Arrays.sort(arr)\n }\n\n /* static void qsort(long[] arr) {\n Long[] oarr = new Long[arr.length];\n for (int i = 0; i < arr.length; i++) {\n oarr[i] = arr[i];\n }\n\n ArrayList alist = new ArrayList(Arrays.asList(oarr));\n Collections.sort(alist);\n\n for (int i = 0; i < arr.length; i++) {\n arr[i] = (long)alist.get(i);\n }\n } */\n fun reverse(arr: LongArray) {\n for (i in 0 until arr.size / 2) {\n val temp = arr[i]\n arr[i] = arr[arr.size - 1 - i]\n arr[arr.size - 1 - i] = temp\n }\n }\n\n fun atos(arr: LongArray?): String {\n var s = Arrays.toString(arr)\n s = s.substring(1, s.length - 1)\n return s.replace(\",\", \"\")\n }\n\n class IO(x: InputStream?) {\n var `in`: BufferedReader\n var tokens: StringTokenizer\n\n @Throws(Exception::class)\n fun nint(): Int {\n return nstr().toInt()\n }\n\n @Throws(Exception::class)\n fun nlong(): Long {\n return nstr().toLong()\n }\n\n @Throws(Exception::class)\n fun ndouble(): Double {\n return nstr().toDouble()\n }\n\n @Throws(Exception::class)\n fun nstr(): String {\n if (!tokens.hasMoreTokens()) tokens = StringTokenizer(`in`.readLine())\n return tokens.nextToken()\n }\n\n @Throws(Exception::class)\n fun nla(n: Int): LongArray {\n val arr = LongArray(n)\n for (i in 0 until n) {\n arr[i] = nlong()\n }\n return arr\n }\n\n init {\n `in` = BufferedReader(InputStreamReader(x))\n tokens = StringTokenizer(`in`.readLine())\n }\n }\n\n internal class Pair?, B : Comparable?>(var f: A, var s: B) : Comparable> {\n override fun compareTo(other: Pair): Int {\n val v = f!!.compareTo(other.f)\n return if (v != 0) v else s!!.compareTo(other.s)\n }\n\n override fun toString(): String {\n return \"(\" + f.toString() + \", \" + s.toString() + \")\"\n }\n\n }\n}\n\nfun main(args: Array) {\n Main.main(args);\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "babbf61538c9989253323fca6231bdd3", "src_uid": "b2b9bee53e425fab1aa4d5468b9e578b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.util.*\n\n\nfun main(args: Array) {\n TaskC().solve()\n}\n\nabstract class Solver {\n internal val scanner = MyScanner()\n abstract fun solve()\n}\n\nclass TaskC : Solver() {\n override fun solve() {\n val mod = 998244353\n val n = scanner.nextInt()\n val m = scanner.nextLong()\n val k = scanner.nextInt()\n\n var cnk = Array(n + 1) { IntArray(n + 1) }\n\n cnk[0][0] = 1\n for (i in 1..n) {\n cnk[i][0] = 1\n cnk[i][i] = 1\n for (j in 1 until n) {\n cnk[i][j] = (cnk[i - 1][j] + cnk[i - 1][j - 1]) % mod\n }\n }\n\n var ans = cnk[n - 1][k].toLong()\n ans = (ans *m) % mod\n for (i in 1..k){\n ans = (ans* (m-1))% mod\n }\n System.out.print(ans)\n\n\n }\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}\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "4b853ef25d08de4941c0abd38b7479c6", "src_uid": "b2b9bee53e425fab1aa4d5468b9e578b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nfun main(args : Array) = Thread { run() }.start()\n\nfun run() {\n\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n val arr1 = IntArray(n) { scanner.nextInt() }\n val arr2 = IntArray(n) { scanner.nextInt() }\n if (arr1.sum() >= arr2.sum())\n println(\"Yes\")\n else\n println(\"No\")\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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "eb5e3bf78887bef3dcb2da29d06a347d", "src_uid": "e0ddac5c6d3671070860dda10d50c28a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n readLine()\n print(if (readInts().sum() >= readInts().sum()) \"Yes\" else \"No\")\n\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "35032a2ab9c6062e1a6a8b5da009c663", "src_uid": "e0ddac5c6d3671070860dda10d50c28a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n\n var sc = Scanner(System.`in`)\n\n var n = sc.nextLine().toInt()\n var line1 = sc.nextLine().split(\" \")\n var line2 = sc.nextLine().split(\" \")\n\n var ans1 = 0\n var ans2 = 0\n\n for( i in 0 until n){\n ans1 += line1[i].toInt()\n ans2 += line2[i].toInt()\n }\n\n if(ans1 < ans2) print(\"No\")\n else print(\"Yes\")\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "cf413e749c76dcca51a27932a8146564", "src_uid": "e0ddac5c6d3671070860dda10d50c28a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array){\n val n = readLine()!!.toInt()\n val sequence = readLine()!!.toList().map {it.toString().toInt()}\n var target_segment_sum = 0\n for (initial_segment_length in 1..n){\n target_segment_sum += sequence[initial_segment_length-1]\n var segment_sum = 0\n var emptied = false\n for(index in initial_segment_length..n-1){\n segment_sum += sequence[index]\n if(segment_sum == target_segment_sum){\n segment_sum = 0\n emptied = true\n }\n else if(segment_sum > target_segment_sum){\n break\n }\n }\n if((segment_sum == 0)&&emptied) {\n println(\"YES\")\n return\n }\n }\n println(\"NO\")\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "21269fbed453a83d02e98fbd3aa41fb0", "src_uid": "410296a01b97a0a39b6683569c84d56c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.sqrt\n\nprivate fun divisors(n: Int): List {\n val ds = mutableListOf()\n var i = 2\n while (i * i <= n) {\n if (n % i == 0) {\n ds.add(i)\n ds.add(n / i)\n }\n i++\n }\n return ds.toList()\n}\n\n\nprivate fun isPrime(n:Int) :Boolean {\n var isPrime = true;\n for (i in 2..sqrt(n.toFloat()).toInt())\n if (n%i==0) {isPrime=false; break}\n return isPrime\n}\n\nfun solution(ss: String): Boolean {\n val s = ss.filter { it!='0' }\n if (s.length==1) return false\n if (s.filter { it != '0' }.all { it==s.first() }) return true\n val ns = s.map { it.toInt() - '0'.toInt() }\n val sum = ns.sum()\n val r =\n when {\n isPrime(sum) -> false\n else -> {\n var canDivide = false\n var l = 0\n forloop@ for (i in divisors(sum)) {\n var b: Int\n whileloop@ while (l <= ns.lastIndex) {\n canDivide=false\n b=sum/i\n while (b > 0 && l<=ns.lastIndex) b -= ns[l++]\n if (b == 0) {\n canDivide = true\n continue@whileloop\n }\n else {\n l=0\n canDivide = false\n continue@forloop\n }\n }\n\n if (canDivide) break\n }\n canDivide\n }\n }\n return r\n}\n\n\nfun main(args: Array) {\n readLine()!!\n println(if (solution(readLine()!!)) \"YES\" else \"NO\")\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "829dab378bdeec2efe0255e06ee3b1b3", "src_uid": "410296a01b97a0a39b6683569c84d56c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val length = readLine()!!.toInt()\n val values = readLine()!!.toCharArray().map { it.toInt() - 48 }\n val total = values.sum()\n var sum = 0\n var result = false\n for (pos in 0 until length - 1) {\n sum += values[pos]\n if (sum != 0 && sum != total && total % sum == 0) {\n result = solve(values, length, sum, pos + 1)\n if (result) break\n }\n }\n print(if (result || (sum == 0 && total == 0)) \"YES\" else \"NO\")\n}\n\nfun solve(values: List, length: Int, sum: Int, initialPos: Int): Boolean {\n var otherSum = 0\n for (pos in initialPos until length) {\n otherSum += values[pos]\n if (otherSum == sum) {\n otherSum = 0\n } else if (otherSum > sum) {\n return false\n }\n }\n return otherSum == 0\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9f01e9c1d6d4fbf0eb470fc8038e3d91", "src_uid": "410296a01b97a0a39b6683569c84d56c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n var str = readLine()\n var sum = 0\n for (ch in str!!) {\n sum += ch.toString().toInt()\n }\n var t = 0\n var flag = true\n for (i in 1 .. sum / 2) {\n t = 0\n flag = true\n for (ch in str) {\n t += ch.toString().toInt()\n when {\n t > i -> flag = false\n t == i -> t = 0\n }\n if (!flag) {\n break\n }\n }\n if (flag && t == 0) break\n }\n if (flag && t == 0 && sum != 1) println(\"YES\") else println(\"NO\")\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d8674028e65f036e9d9873297b3eccb9", "src_uid": "410296a01b97a0a39b6683569c84d56c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.toInt() }.toSet().toList().sorted()\n when(v.size){\n 1 -> println(0)\n 2 -> println(if ((v[1]-v[0])%2==0) (v[1]-v[0])/2 else (v[1]-v[0]))\n 3 -> println(if (v[2]-v[1]==v[1]-v[0]) v[2]-v[1] else -1)\n else -> println(-1)\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "4ad512fa4d9b60cccaeac3d1b615d448", "src_uid": "d486a88939c132848a7efdf257b9b066", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n readLine()\n val values = readLine()!!.split(\" \").map { it.toInt() }.toSortedSet()\n when (values.size) {\n 1 -> print(0)\n 2 -> {\n val diff = values.last() - values.first()\n if (diff % 2 == 0) print(diff / 2) else print(diff)\n }\n 3 -> {\n val middle = values.elementAt(1)\n val diff = values.last() - middle\n if (diff == middle - values.first()) print(diff) else print(-1)\n }\n else -> print(-1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "b26c83de37ca3c42e3dec791598f49c8", "src_uid": "d486a88939c132848a7efdf257b9b066", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private fun readln() = readLine()!!\nprivate fun readlnInt() = readln().toInt()\nprivate fun readlnStrings() = readln().split(' ')\nprivate fun readIntArray() = readlnStrings().run { IntArray(size) { get(it).toInt() } }\n\nfun main(args: Array) {\n\tval n = readlnInt()\n\tval a = readIntArray()\n\tval b = a.distinct().toIntArray()\n\tb.sort()\n\twhen (b.size) {\n\t\t1 -> println(0)\n\t\t2 -> {\n\t\t\tif ((b[1]-b[0]) % 2 == 0) println((b[1]-b[0])/2)\n\t\t\telse println(b[1]-b[0])\n\t\t}\n\t\t3 -> {\n\t\t\tif (b[2]-b[1] == b[1]-b[0]) println(b[2]-b[1])\n\t\t\telse println(-1)\n\t\t}\n\t\telse -> println(-1)\n\t}\t\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "cf3d97b21acdf7ae28e62d9ae5a8cbaf", "src_uid": "d486a88939c132848a7efdf257b9b066", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n\n\nfun main(args: Array) {\n\n val sc = Scanner(System.`in`)\n\n val m = HashSet()\n val n = sc.nextInt()\n for (i in 1..n) {\n m.add(sc.nextInt())\n }\n val values = m.toList().sorted()\n when (values.size) {\n 1 -> println(0)\n 2 -> {\n if ((values[1] - values[0]).rem(2) == 0) {\n println((values[1] - values[0]) / 2)\n } else {\n println(values[1] - values[0])\n }\n }\n 3 -> {\n if (values[2] - values[1] == values[1] - values[0]) {\n println(values[2] - values[1])\n } else {\n println(-1)\n }\n }\n else -> println(-1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "fa53eb473615db318fcd1ac042c18072", "src_uid": "d486a88939c132848a7efdf257b9b066", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nval scanner = Scanner(System.`in`)\n\nfun readInt(): Int = scanner.nextInt()\n\nfun readString(): String = scanner.next()\n\nfun main() = StringBuilder(readString())\n .also { number ->\n var remainingMoves = readInt()\n var index = 0\n\n fun getNextMaxDigitIndex(): Int? {\n if (index == number.lastIndex) return null\n var j = 1\n var maxIndex = index + j\n var maxDigit = number[maxIndex].toInt()\n repeat(remainingMoves - 1) {\n number.getOrNull(index + ++j)?.toInt()?.let { digit ->\n if (digit > maxDigit) {\n maxIndex = index + j\n maxDigit = digit\n }\n }\n }\n return if (number[maxIndex].toInt() > number[index].toInt()) maxIndex else null\n }\n\n while (index < number.length && remainingMoves > 0) {\n getNextMaxDigitIndex()?.let { nextMaxDigitIndex ->\n val maxDigit = number[nextMaxDigitIndex]\n number.deleteCharAt(nextMaxDigitIndex)\n number.insert(index, maxDigit)\n remainingMoves -= nextMaxDigitIndex - index\n }\n index++\n }\n }\n .run(::println)", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "782fecdee839e92dca585bd662604349", "src_uid": "e56f6c343167745821f0b18dcf0d0cde", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n\n val queue = ArrayDeque()\n val n = readInt()\n repeat(n) {\n var current = 1\n while (queue.isNotEmpty() && queue.peekLast() == current) {\n queue.removeLast()\n current++\n }\n queue.add(current)\n }\n print(queue.joinToString(\" \"))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "78a42148afa8b91d945f9c14e26b4f61", "src_uid": "757cd804aba01dc4bc108cb0722f68dc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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()", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "77e095f47b63167a9237d720379bc4ed", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "6cb3f38ad7984a8fb6f55d041f95d529", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "7f904481eee0ed5a50a9557dbaf0d071", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "5c7e473e54b5214aa220e875de102f87", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "11f17001e201b46c452c9cdef3cdac3f", "src_uid": "f30329023e84b4c50b1b118dc98ae73c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4288230eac676498f33dd6acb5d24528", "src_uid": "f30329023e84b4c50b1b118dc98ae73c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c2c9449dbab5a71d357a21a197dafd46", "src_uid": "f30329023e84b4c50b1b118dc98ae73c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "0b2a5943d9d46a1763ae270713ba4f0c", "src_uid": "f30329023e84b4c50b1b118dc98ae73c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nval sc = java.util.Scanner(System.`in`)\n\ndata class Interval(val L: Int, val R: Int) : Comparable {\n\toverride fun compareTo(other: Interval): Int {\n\t\treturn compareValuesBy(this, other, Interval::L, Interval::R)\n\t}\n}\n\nfun main(args: Array) {\n\tval n = sc.nextInt()\n\tval a = Array(n) { sc.nextInt() }\n\tvar cnt = 0\n\tfor (i in 0 until n)\n\t\tif (a[i] == 0)\n\t\t\tcnt++\n\tvar ans = cnt\n\tfor (i in 0 until n) {\n\t\twhen (a[i]) {\n\t\t\t0 -> cnt--\n\t\t\t1 -> cnt++\n\t\t}\n\t\tans = min(ans, cnt)\n\t}\n\tprintln(n - ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "5bf070a2e038d870ebaead7a403f0eb3", "src_uid": "c7b1f0b40e310f99936d1c33e4816b95", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n readLine()\n val data = readLine()!!.split(\" \").map { it.toInt() }\n val res = solveA(data)\n println(res)\n}\n\nfun solveA(data: List): Int {\n val zeros = data.takeWhile { it == 0 }.size\n val ones = data.takeLastWhile { it == 1 }.size\n val middle = data.size - zeros - ones\n val maxMiddleCount = if (middle == 0) 0 else (0 until middle).map {\n var i = 0\n var sum = 0\n var countZeroes = i != it\n while (i < middle) {\n val isZero = data[i + zeros] == 0\n if (isZero == countZeroes) {\n sum++\n }\n if (sum == it) {\n countZeroes = false\n }\n i++\n }\n sum\n }.max()!!\n return zeros + ones + maxMiddleCount\n}\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "084ce830a6c3feaf195f38b3ba322e40", "src_uid": "c7b1f0b40e310f99936d1c33e4816b95", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\n\nfun solve() {\n val n = nextInt()\n val a = nextArray(n)\n var cnt = a.count { it == 1 }\n var s = 0\n var z = 0\n var ans = Math.max(cnt,n - cnt)\n for(i in a.indices) {\n if(a[i] == 0) {\n s++\n ans = Math.max(ans,s + cnt - z)\n }\n else z++\n }\n pw.println(ans)\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "c0fe721a6ed17603f7ded76998d2c6cf", "src_uid": "c7b1f0b40e310f99936d1c33e4816b95", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = readInt()\n var lst = readInts()\n var one = 0\n var zero = 0\n for (i in 0 until n) {\n if (lst[i] == 1) {\n one = maxOf(one + 1, zero + 1)\n } else {\n zero++\n }\n }\n println(maxOf(one, zero))\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "e9aa77e1bd580d7e1ddf6e0ed0c573cc", "src_uid": "c7b1f0b40e310f99936d1c33e4816b95", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numHouses, numHouse) = readInts()\n print(if (numHouse and 1 == 1) (numHouse + 1) / 2 else 1 + (numHouses - numHouse) / 2)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "f0ba3604eb64435162f59f77def4c2c1", "src_uid": "aa62dcdc47d0abbba7956284c1561de8", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nclass B{\n fun start(scan: Scanner){\n val num = scan.nextInt()\n\n var step = 1\n\n var result = 0\n for (i in 1..num) {\n result += step\n\n if(i % 2 == 0)\n step++\n }\n println(result)\n }\n}\n\nfun main(args: Array) {\n B().start(Scanner(System.`in`))\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "203d9d0a8e4de00ddbff498b715d76b6", "src_uid": "f8af5dfcf841a7f105ac4c144eb51319", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val (sa, sb) = r.readLine()!!.split(\" \").map { it.toInt() }\n val n = r.readLine()!!.toInt()\n println((n-1)/2)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms"], "code_uid": "da3c4e9ced886a4a16aff63b6ff3c17d", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = tokenizer.nextInt()\n println((n - 1) / 2)\n}\n\nfun StringTokenizer.nextInt() = Integer.parseInt(nextToken())\n\n", "lang_cluster": "Kotlin", "tags": ["constructive algorithms"], "code_uid": "9f57c717c31d8e83ee73cb6fab303b09", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var n = readLine()!!.toInt()\n if (n % 2 == 0) {\n println(n / 2 - 1)\n } else {\n println(n / 2)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms"], "code_uid": "e42ced5b11b37a2202b53751ad11d3fa", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!.toInt()\n print(n/2 - 1 + n % 2)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms"], "code_uid": "760648d892249d1e7c2ef33d864eab56", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readLong() = readLine()!!.toLong()\n val n = readLong()\n print( 1 + n * (n + 1) * 3) // (n * (n + 1) / 2) * 6 == n * (n + 1) * 3\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "02d3288fe9b12235efefeb5ccc69dd1a", "src_uid": "c046895a90f2e1381a7c1867020453bd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n) = readLine()!!.split(' ').map(String::toLong)\n println((3*n*n)+(3*n)+1)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "46872c1ba4b81c457826f9f0e42088b7", "src_uid": "c046895a90f2e1381a7c1867020453bd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "de832ba828407575c772b89fa8aab134", "src_uid": "1ac11153e35509e755ea15f1d57d156b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "5ca01e9f2a284e64c13cf0594ed98e69", "src_uid": "1ac11153e35509e755ea15f1d57d156b", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import kotlin.math.min\r\n\r\nprivate fun readLn() = readLine()!!\r\nprivate fun readInt() = readLn().toInt()\r\nprivate fun readStrings() = readLn().split(\" \")\r\nprivate fun readInts() = readStrings().map { it.toInt() }\r\nprivate fun readLong() = readLn().toLong()\r\nprivate fun readLongs() = readStrings().map { it.toLong() }\r\n\r\nfun main() {\r\n val MOD = 998244353\r\n val n = readInt()\r\n val a = readInts()\r\n var result = 26L * 26;\r\n repeat(n - 2) { result = result * 25 % MOD }\r\n val m = (n + 2) / 2\r\n val dp = Array(2) { Array(m + 2) { Array(m + 2) { Array(3) { Array(3) { 0L } } } } }\r\n dp[0][0][0][0][0] = 1\r\n for (i in 0 until n) {\r\n val ci = i % 2\r\n val ni = 1 - ci\r\n for (c1 in 0..(i + 2) / 2)\r\n for (c2 in 0..min(i - c1, (i + 2) / 2))\r\n for (d1 in 0..2)\r\n for (d2 in 0..2)\r\n dp[ni][c1][c2][d1][d2] = 0\r\n for (c1 in 0..(i + 2) / 2)\r\n for (c2 in 0..min(i - c1, (i + 2) / 2))\r\n for (d1 in 0..2)\r\n for (d2 in 0..2)\r\n for (d3 in 0..2)\r\n if (d1 != d3 || d1 == 0) {\r\n val n1 = c1 + d3 % 2\r\n val n2 = c2 + if (d3 == 2) 1 else 0\r\n val mul = if (d3 > 0) 1 else if (d1 > 0 || i <= 1) 24 else 23\r\n dp[ni][n1][n2][d2][d3] = (dp[ni][n1][n2][d2][d3] + dp[ci][c1][c2][d1][d2] * mul) % MOD\r\n }\r\n }\r\n val d2 = dp[n % 2].map { it.map { it.sumOf { it.sum() % MOD } % MOD } }\r\n val d1 = d2.map { it.sum() % MOD }\r\n for (i in a)\r\n for (j in i + 1..m)\r\n result = (result + MOD - d1[j]) % MOD\r\n for (i in 0..25)\r\n for (j in 0 until i)\r\n for (c1 in a[i] + 1..m)\r\n for (c2 in a[j] + 1..m)\r\n result = (result + d2[c1][c2]) % MOD\r\n println(result)\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "fft"], "code_uid": "69673493fd54bc561d553cfc95a2ede1", "src_uid": "1f012349f4b229dc98faadf1ca732355", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalUnsignedTypes::class, 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/** @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 val C = readIntArray(26)\n\n val h = n/4*2+2\n\n fun id(j: Int, k: Int, l: Int, m: Int) = j\n .times(h+1).plus(k)\n .times(3).plus(l)\n .times(3).plus(m)\n\n var D = ModIntArray(id(h, h, 2, 2)+1)\n\n for(l in 0..2) for(m in 0..2) {\n val j = (l == 0).toInt() + (m == 0).toInt()\n val k = (l == 1).toInt() + (m == 1).toInt()\n\n var d = ModInt(1)\n if(l == 2) d *= 24\n if(m == 2) d *= 24\n\n D[id(j, k, l, m)] = d\n }\n\n for(i in 2 until n) {\n val Di = ModIntArray(D.size)\n for(j in 0..min(h,i)) for(k in 0..min(h, i-j)) for(l in 0..2) for(m in 0..2) {\n val d = D[id(j, k, l, m)]\n if(d.int == 0) continue\n for(p in 0..2) {\n val dn = if(p == 2) {\n if(l == 2) d*23 else d*24\n } else {\n if(p == l) continue else d\n }\n\n val jn = j + (p == 0).toInt()\n val kn = k + (p == 1).toInt()\n Di[id(jn, kn, m, p)] += dn\n }\n }\n D = Di\n }\n\n val S = Array(h+2) { ModIntArray(h+2) }\n\n for(j in 0..h) for(k in 0..h) {\n S[j+1][k+1] = S[j+1][k] + S[j][k+1] - S[j][k]\n for(l in 0..2) for(m in 0..2) S[j+1][k+1] += D[id(j, k, l, m)]\n }\n\n fun S(a: Int, b: Int, c: Int, d: Int): ModInt {\n val a = min(h+1, a)\n val b = min(h+1, b)\n val c = min(h+1, c)\n val d = min(h+1, d)\n\n return S[c][d] - S[a][d] - S[c][b] + S[a][b]\n }\n\n val s = S[h+1][h+1]\n var ans = s\n\n for(i in 0 until 26) ans -= S(C[i]+1, 0, n, n)\n\n for(i in 0 until 25) for(j in i+1 until 26) {\n ans += S(C[i]+1, C[j]+1, n, n)\n }\n\n println(ans.int)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nfun Boolean.toInt() = if(this) 1 else 0\n\nconst val MOD = 998244353\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 if(mod == 1) return 0\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_unmemoized() /** 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 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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { 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 }", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "fft"], "code_uid": "146b2b9975f286726a5de5bd26c75359", "src_uid": "1f012349f4b229dc98faadf1ca732355", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalUnsignedTypes::class, 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/** @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 val C = readIntArray(26)\n\n val h = n.shr(2).shl(1) + min(2, n and 3)\n\n fun id(j: Int, k: Int, l: Int, m: Int) = j\n .times(h+1).plus(k)\n .times(3).plus(l)\n .times(3).plus(m)\n\n var D = ModIntArray(id(h, h, 2, 2)+1)\n\n for(l in 0..2) for(m in 0..2) {\n val j = (l == 0).toInt() + (m == 0).toInt()\n val k = (l == 1).toInt() + (m == 1).toInt()\n\n var d = ModInt(1)\n if(l == 2) d *= 24\n if(m == 2) d *= 24\n\n D[id(j, k, l, m)] = d\n }\n\n for(i in 2 until n) {\n val Di = ModIntArray(D.size)\n for(j in 0..min(h, i)) for(k in 0..min(h, i-j)) for(l in 0..2) for(m in 0..2) {\n val d = D[id(j, k, l, m)]\n if(d.int == 0) continue\n for(p in 0..2) {\n val dn = if(p == 2) {\n if(l == 2) d*23 else d*24\n } else {\n if(p == l) continue else d\n }\n\n val jn = j + (p == 0).toInt()\n val kn = k + (p == 1).toInt()\n Di[id(jn, kn, m, p)] += dn\n }\n }\n D = Di\n }\n\n val S = Array(h+2) { ModIntArray(h+2) }\n\n for(j in 0..h) for(k in 0..h) {\n S[j+1][k+1] = S[j+1][k] + S[j][k+1] - S[j][k]\n for(l in 0..2) for(m in 0..2) S[j+1][k+1] += D[id(j, k, l, m)]\n }\n\n fun S(a: Int, b: Int, c: Int, d: Int): ModInt {\n val a = min(h+1, a)\n val b = min(h+1, b)\n val c = min(h+1, c)\n val d = min(h+1, d)\n\n return S[c][d] - S[a][d] - S[c][b] + S[a][b]\n }\n\n var ans = S[h+1][h+1]\n\n for(i in 0 until 26) {\n ans -= S(C[i]+1, 0, n, n)\n for(j in i+1 until 26) {\n ans += S(C[i]+1, C[j]+1, n, n)\n }\n }\n\n println(ans.int)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nfun h(n: Int) = n.shr(2).shl(1) + min(2, n and 3)\nfun Boolean.toInt() = if(this) 1 else 0\n\nconst val MOD = 998244353\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 if(mod == 1) return 0\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_unmemoized() /** 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 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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { 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 }", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "fft"], "code_uid": "6b84c397b7b37f82107c8b224b4c9fd6", "src_uid": "1f012349f4b229dc98faadf1ca732355", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalUnsignedTypes::class, 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/** @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 val C = readIntArray(26)\n\n val h = n/4*2 + min(2, n%4)\n\n fun id(j: Int, k: Int, l: Int, m: Int) = j\n .times(h+1).plus(k)\n .times(3).plus(l)\n .times(3).plus(m)\n\n var D = ModIntArray(id(h, h, 2, 2)+1)\n\n for(l in 0..2) for(m in 0..2) {\n val j = (l == 0).toInt() + (m == 0).toInt()\n val k = (l == 1).toInt() + (m == 1).toInt()\n\n var d = ModInt(1)\n if(l == 2) d *= 24\n if(m == 2) d *= 24\n\n D[id(j, k, l, m)] = d\n }\n\n for(i in 2 until n) {\n val Di = ModIntArray(D.size)\n for(j in 0..min(h,i)) for(k in 0..min(h, i-j)) for(l in 0..2) for(m in 0..2) {\n val d = D[id(j, k, l, m)]\n if(d.int == 0) continue\n for(p in 0..2) {\n val dn = if(p == 2) {\n if(l == 2) d*23 else d*24\n } else {\n if(p == l) continue else d\n }\n\n val jn = j + (p == 0).toInt()\n val kn = k + (p == 1).toInt()\n Di[id(jn, kn, m, p)] += dn\n }\n }\n D = Di\n }\n\n val S = Array(h+2) { ModIntArray(h+2) }\n\n for(j in 0..h) for(k in 0..h) {\n S[j+1][k+1] = S[j+1][k] + S[j][k+1] - S[j][k]\n for(l in 0..2) for(m in 0..2) S[j+1][k+1] += D[id(j, k, l, m)]\n }\n\n fun S(a: Int, b: Int, c: Int, d: Int): ModInt {\n val a = min(h+1, a)\n val b = min(h+1, b)\n val c = min(h+1, c)\n val d = min(h+1, d)\n\n return S[c][d] - S[a][d] - S[c][b] + S[a][b]\n }\n\n var ans = S[h+1][h+1]\n\n for(i in 0 until 26) {\n ans -= S(C[i]+1, 0, n, n)\n for(j in i+1 until 26) {\n ans += S(C[i]+1, C[j]+1, n, n)\n }\n }\n\n println(ans.int)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nfun Boolean.toInt() = if(this) 1 else 0\n\nconst val MOD = 998244353\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 if(mod == 1) return 0\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_unmemoized() /** 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 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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { 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 }", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "fft"], "code_uid": "29fec1ad54e686e5724e9778daab60bf", "src_uid": "1f012349f4b229dc98faadf1ca732355", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val tokenizer = StringTokenizer(readLine())\n val n = tokenizer.nextToken().toInt()\n val x = tokenizer.nextToken().toInt()\n val arrayTokenizer = StringTokenizer(readLine())\n var steps = x\n generateSequence { arrayTokenizer.takeIf { it.hasMoreTokens() }?.nextToken()?.toInt() }.forEach {\n if (it < x) {\n steps--\n } else if (it == x) {\n steps++\n }\n }\n println(steps)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "b552878867488c40f6fb65b8b6b8b000", "src_uid": "21f579ba807face432a7664091581cd8", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n val x = sc.nextInt()\n val set = (1..n).map { sc.nextInt() }.toSet()\n\n println(operations(set, x))\n\n}\n\nfun operations(set: Set, x:Int) =\n (0 until x).filter { !set.contains(it)}.count() + if(set.contains(x)) 1 else 0\n", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "441f5f96aacc4d331cc0973dffa5c6f4", "src_uid": "21f579ba807face432a7664091581cd8", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (_, x) = readInts()\n val numsSet = readInts().toSet()\n var sol = 0\n for (num in 0 until x) if (num !in numsSet) sol++\n if (x in numsSet) sol++\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "e2cb42fe97376308fac5172485383b84", "src_uid": "21f579ba807face432a7664091581cd8", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val input1 = readLine()\n val input2 = readLine()\n\n if (input1 == null || input2 == null)\n return\n\n val inputArray1 = input1.split(' ')\n val find = inputArray1[1].toInt()\n val many = input2.split(' ').map { it.toInt() }\n\n var result = 0\n\n (0 until find)\n .filter { x -> many.any { it == x } }\n .forEach { result++ }\n\n result = find - result\n\n if (many.any { it == find })\n result++\n\n println(result)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "5e41246c9435954b1d27b15d68ade78f", "src_uid": "21f579ba807face432a7664091581cd8", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main ( args: Array) {\n val (n, k) = readLine()!!.split(\" \").map { i -> i.toLong() }\n val x : Long = n / (2 * k + 2)\n println(\"$x ${x*k} ${n - x*(k+1)}\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "8f13d138736c09a9c228b9600fdff685", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, k) = readLine()!!.split(\" \").map { it -> it.toLong() }\n var a: Long = n / (2 * k + 2)\n print(\"$a ${k * a} ${n - (k + 1) * a}\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "a67ffc93b698f41cec4c6c2f67d480f1", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val(n, k) = readLine()!!.split(' ').map(String::toLong)\n var d = (n / 2) / (k + 1)\n var g = d * k\n var l = n - (g + d)\n println(\"$d $g $l\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "e4f31f5cc7ad22f239ef2f973e28009c", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (numStudents, k) = readLine()!!.split(\" \").map(String::toLong)\n val diplomas = (numStudents / 2) / (k + 1)\n print(\"$diplomas ${k * diplomas} ${numStudents - (k + 1) * diplomas}\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "f8e9d4f129051157f1c66d6e7de42196", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "09c66f7411e76c021d5d38879d94f071", "src_uid": "c052d85e402691b05e494b5283d62679", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "5eaa1b74861c247914e0e8db335602f2", "src_uid": "c052d85e402691b05e494b5283d62679", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "f36eb0e0153d0c9e0410af77c59c14ff", "src_uid": "c052d85e402691b05e494b5283d62679", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "2abf906e9b61d503325d065d6afb7312", "src_uid": "c052d85e402691b05e494b5283d62679", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.pow\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n var n = r.readLine()!!.toInt()\n var ans = 0L\n var now = 1L\n var digit = 1\n while (now * 10 <= n) {\n ans += (10.0.pow(digit)-10.0.pow(digit-1)).toLong()*digit\n digit++\n now*=10\n }\n ans += (n-now+1)*digit\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "bae33a6eada5d3a7a9fbd335e679cfb0", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)){\n val n = nextLong()\n\n val dig = n\n\n var sum = 0L\n\n var i = 0\n while(true){\n val pTen = pow(10, i)\n val div = (dig / pTen) \n var diff: Long = 0\n if(div >= 10L) {\n diff = (pow(10, i + 1) - pTen) * (i + 1)\n } else {\n diff = (dig - pTen + 1) * (i + 1)\n }\n sum += diff\n //println(\"i: $i, div: $div, diff: $diff, sum: $sum, pTen: $pTen\")\n i++\n if(div < 10L){\n break\n }\n }\n println(sum)\n}\n\nfun pow(dig: Long, pow: Int):Long {\n if(pow == 0) {\n return 1L\n }\n return dig * pow(dig, pow - 1)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "c3a7a9ebe03f7947cff6f87c8b798cf1", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*;\n\nfun main() {\n\tfun len(x: Int): Long {\n\t\treturn x.toString().length.toLong()\n\t}\n\tfun get(x: Int): Long {\n\t\treturn (9*Math.pow(10.0, (x-1).toDouble())).toLong() \n\t}\n\tvar n = readLine()!!.toInt()\n\tvar totalLen = len(n)\n\tvar x = 0L\n\tvar ans = 0L\n\tfor(i in 1..totalLen-1) {\n\t\tvar curr = get(i.toInt())\n\t\tx += curr\n\t\tans += curr*i\n\t}\n\tans += (n-x)*totalLen\n\tprintln(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "8cce822c9b403dd4b3dddb245e63a3ee", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.*\n\nval INPUT = System.`in`!!\nval OUTPUT = System.out!!\nval reader = INPUT.bufferedReader()\nfun readLine(): String? = reader.readLine()\nfun line() = reader.readLine()!!\nvar st: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (st.hasMoreTokens().not())\n st = StringTokenizer(reader.readLine() ?: return \"\", \" \")\n return st.nextToken()\n}\nfun int() = read().toInt()\nfun ints(n: Int) = List(n) { read().toInt() }\nfun intArray(n: Int) = IntArray(n) { read().toInt() }\nval writer = PrintWriter(OUTPUT, false)\nfun main() { writer.solve(); writer.flush() }\nfun PrintWriter.solve() {\n var tt = 1\n //tt = int()\n while (tt-- > 0) {\n val n = int()\n val arr = arrayOf(1200, 1400, 1600, 1900, 2100, 2300, 2400, 2600, 3000)\n for(i in arr) {\n if(i > n) {\n println(i)\n break\n }\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "divide and conquer", "implementation"], "code_uid": "2b86abdc69a10fd813c89640cef204a0", "src_uid": "22725effa6dc68b9c2a499d148e613c2", "difficulty": -1.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "// $time$\nimport java.io.BufferedInputStream\nimport java.io.File\nimport java.io.PrintWriter\nimport kotlin.system.measureTimeMillis\nimport java.util.TreeMap\nimport java.util.TreeSet\n\ninline fun TIME(f:()->Unit){\n val t = measureTimeMillis(){\n f()\n }\n println(\"$t ms\")\n}\n\nobject IO{\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(\"You forgot to disable tests you digital dummy!\")\n println(\"You forgot to disable tests you digital dummy!\")\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){ IO.OUT.println(aa)}\nfun done(){ IO.OUT.close() }\nfun share(aa:Any){\n if(aa is IntArray){IO.fakein.append(aa.joinToString(\" \"))}\n else if(aa is LongArray){IO.fakein.append(aa.joinToString(\" \"))}\n else if(aa is List<*>){IO.fakein.append(aa.toString())}\n else{IO.fakein.append(aa.toString())}\n IO.fakein.append(\"\\n\")\n}\n\nval getintfast:Int get() = IO.nextInt()\nval getint:Int get(){ val ans = getlong ; if(ans > Int.MAX_VALUE) IntArray(1000000000); return ans.toInt() }\nval getlong:Long get() = IO.nextLong()\nval getstr:String get() = IO.nextString()\nfun getline(n:Int):IntArray{\n return IntArray(n){getint}\n}\nfun getlineL(n:Int):LongArray{\n return LongArray(n){getlong}\n}\nfun getbinary(n:Int, asTrue:Char):BooleanArray{\n val str = getstr\n return BooleanArray(n){str[it] == asTrue}\n}\n\nval List.ret:String\nget() = this.joinToString(\"\")\nvar dmark = -1\ninfix fun Any.dei(a:Any){\n //does not stand for anything it is just easy to type, have to be infix because kotlin does not have custom prefix operators\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 }\n println()\n }else{ println(\"$str : $a\")\n }\n}\nval just = \" \" // usage: just dei x , where x is the debug variable\nfun crash(){\n throw Exception(\"Bad programme\")} // because assertion does not work\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 answersChecked = 0\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 //safety checks\n if(pI != 998_244_353 && pI != 1_000_000_007){\n throw Exception(\"Modding a wrong prime!\")\n }\n if(withBruteForce){\n println(\"Brute force is active\")\n }\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 IO.rerouteInput()\n }else if(mode == solveMode.rand){\n rand()\n IO.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}\ninline fun T.alsoBrute(cal:() -> T){\n if(!withBruteForce) return\n val also = cal()\n if(this != also){\n println(\"Checking failed: Got ${this} Brute ${also}\")\n crash()\n }\n}\n// 1. Modded\nconst val p = 1000000007L\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 }\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\n\n\n\nfun debug(){}\nconst val withBruteForce = false\nconst val singleCase = true\nfun main(){\n val t= TreeSet()\n t.addAll(listOf(1200,1400,1600,1900,2100,2300,2400,2600,3000))\n solve.cases{\n val r = getint\n put(t.higher(r)!!)\n\n\n\n\n\n }\n done()\n}\n\n\n\n\n", "lang_cluster": "Kotlin", "tags": ["math", "divide and conquer", "implementation"], "code_uid": "9d5f4abcd2b47a56f9efab2fbabbc184", "src_uid": "22725effa6dc68b9c2a499d148e613c2", "difficulty": -1.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "import java.util.*\nimport kotlin.math.*\n\nprivate fun List.toPair(): Pair {\n return Pair(this[0], this[1])\n}\n\nprivate fun maxOf(ans: Pair, b: Pair): Pair {\n return if (ans.first > b.first || ans.first == b.first && ans.second > b.second) ans\n else b\n}\n\nprivate fun , T2 : Comparable> pairCmp(): Comparator> {\n return Comparator { a, b ->\n val res = a.first.compareTo(b.first)\n if (res == 0) a.second.compareTo(b.second) else res\n }\n}\n\n\nprivate val readR = Scanner(System.`in`)\nprivate const val BUFFER_SIZE = 1 shl 16\nprivate val buffer = ByteArray(BUFFER_SIZE)\nprivate var bufferPt = 0\nprivate var bytesRead = 0\nprivate fun 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}\nprivate val INPUT = System.`in`\nprivate tailrec 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++].toInt().toChar()\n if (c == '\\r') readChar()\n else c\n }\n}\nprivate fun readln() = readLine()!!\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 fun printWithSpace(vararg x: Any?) = println(x.joinToString(\" \"))\nprivate fun readCharArray(n:Int) = CharArray(n) {_->readChar()}\n//----------------Customizing Functions----------------\n\n//-----------------------Solving-----------------------\nprivate fun solve() {\n val r=readInt()\n val a=IntArray(9)\n a[0]=1200\n a[1]=1400\n a[2]=1600\n a[3]=1900\n a[4]=2100\n a[5]=2300\n a[6]=2400\n a[7]=2600\n a[8]=3000\n for(i in a.indices){\n if(r) {\n val (s, t) = readLine()!!.split(\" \")\n val radix = (s + t).max()!!.toString().toInt() + 1\n println((s.toInt(radix) + t.toInt(radix)).toString(radix).length)\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "c27b62e8a49d7cc2cc963908b80e3f89", "src_uid": "8ccfb9b1fef6a992177cc49bd56fab7b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 ans = reader.nextArrayInt(n).toSet().filter { it > 0 }.count()\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", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation"], "code_uid": "9ba1d083f68ebdee2a3eaa669815a640", "src_uid": "3b520c15ea9a11b16129da30dcfb5161", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//kotlinc kot.kt -include-runtime -d kot.jar\n//java -jar kot.jar\nimport kotlin.math.*\nimport java.util.ArrayList\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 ints\n\nfun main(){\n\tvar n = readInt()\n\tvar arr: ArrayList = ArrayList(n)\n\tvar x = readLine()!!.split((' ')).map(String::toInt)\n\tfor(i in 0..n-1){\n\t\tarr.add(x[i.toInt()])\n\t}\n\tvar cnt: ArrayList = ArrayList(20020)\n\tfor(i in 0..(20020-1)){\n\t\tcnt.add(0)\n\t}\n\tvar ans = 0\n\tfor(i in 0..n-1){\n\t\tvar aa = arr[i.toInt()]\n\t\tif( (arr[i.toInt()] > 0) && (cnt[aa] == 0) ) { \n\t\t\tans = ans + 1\n\t\t\tcnt[aa] = 1\n\t\t}\n\t}\n\tprintln(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation"], "code_uid": "62b5a8dcbc6640ea35e4d33b37264240", "src_uid": "3b520c15ea9a11b16129da30dcfb5161", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n with(Scanner(System.`in`)) {\n val n = nextInt()\n val a = Array(n, {\n nextInt()\n })\n println(a.distinct().count { it > 0 })\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation"], "code_uid": "1893e916ab659a3fca739c3913f55c67", "src_uid": "3b520c15ea9a11b16129da30dcfb5161", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val N = nextInt()\n var a = BooleanArray(603, {false});\n for(i in 0..N-1) {\n val x = nextInt()\n if(x > 0) a[x] = true\n }\n var nr = 0\n for(i in 0..600) {\n if(a[i]) nr++\n }\n println(nr)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation"], "code_uid": "cee9daec475218c6f614872e9c0c8337", "src_uid": "3b520c15ea9a11b16129da30dcfb5161", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.*\nimport java.util.*\nfun main(args: Array) {\n val `in` = Scanner(System.`in`)\n val n = `in`.nextInt()\n val m = `in`.nextInt()\n var maxIt = 0\n var maxChild = 0\n for (i in 0 until n) {\n val x = `in`.nextInt()\n val it = (x + (m - 1)) / m\n if (it >= maxIt) {\n maxIt = it\n maxChild = i\n }\n }\n println(maxChild + 1)\n\n\n }", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "476c5a2035ad7ad191fbc9d397e1693c", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n val (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n val l = r.readLine()!!.split(\" \").map { it.toInt() }.map { it / m + if (it % m != 0) 1 else 0 }\n var max = Int.MIN_VALUE\n var ind = -1\n for (i in n-1 downTo 0){\n if (l[i]>max) {\n max = l[i]\n ind = i+1\n }\n }\n println(ind)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "f5380d27a5aeb30eed4bd7425ee38c7b", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.pow\n\nfun main() {\n var (n, m) = readLine()!!.split(\" \").map { it.toInt() }\n\n var list = readLine()!!.split(\" \").map { it.toInt() }\n\n var max = list.max()\n val map = Array(n, { 0 })\n var ans = -1\n var ans2 = 0\n if (max!! <= m) {\n ans = n\n } else {\n var count = n\n for (i in n - 1 downTo 0) {\n if (list[i] > m) {\n var temp = list[i] / m\n var temp2 = list[i] % m\n if (temp2 != 0) {\n temp++\n }\n if (temp > ans2) {\n ans = count\n ans2 = temp\n }\n }\n count--\n }\n }\n\n println(ans)\n\n\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "75ea4692f1422334c3c18c3cdd041e8e", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (n, m) = readLine()!!.split(\" \").map{ it.toInt() }\n readLine()!!.split(\" \").map{ it.toInt() }.toMutableList().let {\n var last = 0;\n while(true) {\n var count = 0\n for((i, x) in it.withIndex()) {\n if(x > 0) {\n it[i] -= m\n last = i + 1\n }\n if(it[i] <= 0) count++\n }\n if(count == n) break\n }\n println(last)\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a6e1c13a522696bec3e7d563319bd889", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": " fun main(args: Array) {\n val (a, b) = readLine()!!.split(\" \")\n println( if (a == b) a else \"1\" )\n }\n\n", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "8694598e90f8b3e7b54ddac357457fa6", "src_uid": "9c5b6d8a20414d160069010b2965b896", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (a, b) = readLine()!!.split(\" \")\n println(if (a==b) a else \"1\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "e8df65be9f64235fcfcb90eed1a7b725", "src_uid": "9c5b6d8a20414d160069010b2965b896", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (a, b) = readLine()!!.split(\" \")\n print(if (a == b) a else 1)\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "723b40f52a71a681390d59710bf38db9", "src_uid": "9c5b6d8a20414d160069010b2965b896", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "641f37956b3f4afca96679c964ce8597", "src_uid": "9c5b6d8a20414d160069010b2965b896", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "a6da54cfc128767d829d6a4e4f6196cf", "src_uid": "ba6ff507384570152118e2ab322dd11f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "d8552f4a10a69b650bf3533fd24f8904", "src_uid": "ba6ff507384570152118e2ab322dd11f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "1b55c951bdc8d3f4cc05f3524766d93e", "src_uid": "ba6ff507384570152118e2ab322dd11f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "e246ac90e7ea7fa497a47b5ddef21778", "src_uid": "ba6ff507384570152118e2ab322dd11f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val pages = readLine()!!.toInt()\n val days = readLine()!!.splitToIntArray()\n val useful = days.indices.filter { days[it] > 0 }\n\n var cur = -1\n var done = 0\n\n while (done < pages) {\n cur = (cur + 1) % useful.size\n done += days[useful[cur]]\n }\n\n println(useful[cur] + 1)\n}\n\nprivate fun String.toLettersList(): List {\n return toCharArray().map { it.toString() }\n}\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).apply { require(this >= 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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "43f641ed14bf6fd493888bca253c7a28", "src_uid": "007a779d966e2e9219789d6d9da7002c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n var n = r.readLine()!!.toInt()\n val v = r.readLine()!!.split(\" \").map { it.toInt() }\n val ans = IntArray(7000) { 0 }\n for (i in 0..6999){\n ans[i] += v[i%7]\n }\n (1..6999).forEach { ans[it] +=ans[it-1] }\n fun b(x:Int):Int{\n var le = 0\n var ri = 7000\n while (le le = mi+1\n ans[mi]>=x -> ri = mi\n }\n }\n return le%7+1\n }\n println(b(n))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "91200febdeee7bf42b4dff5e078afd26", "src_uid": "007a779d966e2e9219789d6d9da7002c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 var list: MutableList = mutableListOf()\n\n for(i in 0..6){\n list.add(reader.nextInt())\n }\n var c = 0\n\n var j = 0\n while(n>0){\n n = n - list[j]\n j++\n if(j>6){\n j=0\n }\n c++\n }\n\n\n if(c>7) {\n var a = c%7\n if(a==0){\n println(7)\n }\n else {\n println(a)\n }\n }\n else{\n println(c)\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9e7577ba991d3494f9206a2dc0db357c", "src_uid": "007a779d966e2e9219789d6d9da7002c", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nclass Pair(val p: Long,val x: Long,var y: Long)\n\nfun main() {\n val sc = Scanner(System.`in`)\n val n = sc.nextLong()\n val b = sc.nextLong()\n val pairs = arrayListOf()\n var j = 2L\n var m = b\n\n var times = 0L\n while (m%2==0L) {\n times++\n m /= 2;\n }\n if (times > 0){\n pairs.add(Pair(j,times,0))\n }\n while (j*j <= m){\n times = 0L\n while (m%j==0L){\n m /= j\n times++\n }\n if (times > 0){\n pairs.add(Pair(j,times,0))\n }\n j++\n }\n if (m > 2)\n pairs.add(Pair(m,1,0))\n\n var min = Long.MAX_VALUE\n for(pair in pairs){\n m = n\n while (m>0){\n pair.y += m/pair.p\n m /= pair.p\n }\n if (min > pair.y/pair.x){\n min = pair.y/pair.x\n }\n }\n print(min)\n}\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation", "number theory"], "code_uid": "15843d67620cccd4b9795d8f2dd3c164", "src_uid": "491748694c1a53771be69c212a5e0e25", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\n\nfun main() {\n val (n, b) = readLine()!!.split(' ').map { it.toLong() }\n var ans = Long.MAX_VALUE\n factor(b) { p, k ->\n ans = min(ans, pp(n, p) / k)\n }\n println(ans)\n}\n\nfun factor(x: Long, op: (p: Long, k: Int) -> Unit) {\n var rem = x\n var p = 2L\n while (p * p <= rem) {\n var k = 0\n while (rem % p == 0L) {\n rem /= p\n k++\n }\n if (k > 0) op(p, k)\n p++\n }\n if (rem > 1) op(rem, 1)\n}\n\nfun pp(n: Long, p: Long): Long {\n var ans = 0L\n var cur = p\n while (cur <= n) {\n ans += n / cur\n if (cur > (n + p - 1) / p) break\n cur *= p\n }\n return ans\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation", "number theory"], "code_uid": "9cb5eb095363746bd4e3191e0fd4ab7f", "src_uid": "491748694c1a53771be69c212a5e0e25", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.nextLong()\n var b = tokenizer.nextLong()\n var ans: Long? = null\n for (i in 2..Math.sqrt(b.toDouble()).toLong()) {\n var c = 0\n while (b % i == 0L) {\n b /= i\n c++\n }\n if (c > 0) {\n val t = count(n, i) / c\n if (ans == null || ans > t) ans = t\n }\n }\n if (b > 1L) {\n val t = count(n, b)\n if (ans == null || ans > t) ans = t\n }\n println(ans)\n}\n\nfun count(n: Long, b: Long): Long {\n var t = n\n var ans = 0L\n while (t >= b) {\n t /= b\n ans += t\n }\n return ans\n}\n\nfun StringTokenizer.nextInt() = nextToken().toInt()\nfun StringTokenizer.nextLong() = nextToken().toLong()\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation", "number theory"], "code_uid": "5d898d14d77d8196a3ef1c74e4f46f3e", "src_uid": "491748694c1a53771be69c212a5e0e25", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val n = readInt()\n val matrix = Array(n) { IntArray(n) }\n for (row in 0 until n)\n matrix[row] = readInts().toIntArray()\n var sol = 0\n val middle = n / 2\n for (pos in 0 until n)\n sol += matrix[pos][pos] + matrix[pos][n - 1 - pos] + matrix[middle][pos] + matrix[pos][middle]\n sol -= 3 * matrix[middle][middle]\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5ffcdef4dd6c5e3964ed8393e02b8375", "src_uid": "5ebfad36e56d30c58945c5800139b880", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()?.trim()?.toInt()!!\n val matrix = (1..n).map{ readLine()?.trim()?.split(' ')?.map{it.toInt()}!!}.toList()\n val points =\n generateSequence(Pair(0,0)){Pair(it.first+1,it.second+1)}.take(n).plus(\n generateSequence(Pair(0,n-1)){Pair(it.first+1,it.second-1)}.take(n).plus(\n generateSequence(Pair(n/2,0)){Pair(it.first,it.second+1)}.take(n).plus(\n generateSequence(Pair(0,n/2)){Pair(it.first+1, it.second)}.take(n)\n )\n )\n ).toSet()\n val sum = points.fold(0){acc, pair -> acc + matrix[pair.first][pair.second]}\n println(sum)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4a6544b09386652b24b2301a995e654e", "src_uid": "5ebfad36e56d30c58945c5800139b880", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * Problem Link: https://codeforces.com/problemset/problem/177/A1\n * Difficulty: 700\n */\n\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n val arr = mutableListOf>()\n for (i in 1..n) {\n val a = readLine()!!.split(\" \").map(String::toInt)\n arr.add(a)\n }\n\n var sum = 0\n for ((i, a) in arr.withIndex()) {\n for((j, el) in a.withIndex()) {\n if (i == j || i == (n-j-1) || i == n/2 || j == n/2) {\n sum += el\n }\n }\n }\n\n println(sum)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4e1a2365c2bfd0c59588fdd52fbf6fba", "src_uid": "5ebfad36e56d30c58945c5800139b880", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun 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 main() {\n val n = readInt()\n val matrix = Array(n) { IntArray(n) }\n for (i in matrix.indices)\n matrix[i] = readInts().toIntArray()\n var sum = 0\n for (i in matrix.indices) {\n sum += matrix[i][i]\n sum += matrix[n - i - 1][i]\n if (i == (n - 1) / 2)\n for (j in matrix.indices) {\n sum += matrix[i][j]\n sum += matrix[j][i]\n }\n }\n sum -= 3 * matrix[(n - 1) / 2][(n - 1) / 2]\n print(sum)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9d07a610eddd7fb782afd24511aefd72", "src_uid": "5ebfad36e56d30c58945c5800139b880", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "ed73562ca6f1726da3d69decc4e76724", "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (start, interval, desired) = readLine()!!.split(\" \").map(String::toLong)\n if (desired < start) return print(\"NO\")\n if (desired == start) return print(\"YES\")\n print(if ((desired - (start + interval)) % interval in setOf(0L, 1L)) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "6374997c23c2ce42a79bc8d046958ff1", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val numHalfDigits = readInt()\n val ticket = readLine()!!\n val firstHalf = ticket.substring(0 until numHalfDigits).map { c -> c.toInt() }.sorted()\n val secondHalf = ticket.substring(numHalfDigits).map { c -> c.toInt() }.sorted()\n if (firstHalf[0] == secondHalf[0]) return print(\"NO\")\n val (bigger, smaller) = if (firstHalf[0] > secondHalf[0]) firstHalf to secondHalf else secondHalf to firstHalf\n for (pos in bigger.indices)\n if (bigger[pos] <= smaller[pos]) return print(\"NO\")\n print(\"YES\")\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "greedy"], "code_uid": "81cad3a6db31b292480be66e713e244e", "src_uid": "e4419bca9d605dbd63f7884377e28769", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array){\n val reg = Regex(\" \")\n val s = readLine()!!.split(reg)\n var n = s[0].toInt()\n var k = s[1].toInt()\n var i = 1\n while (true){\n if (i % 2 == 1){\n if (n < i) {\n print(\"Vladik\")\n return\n }\n n -= i\n }\n else{\n if (k < i){\n print(\"Valera\")\n return\n }\n k -= i\n }\n ++i\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "e6dc8f9856f7ef0478cf8d606483f7bf", "src_uid": "87e37a82be7e39e433060fd8cdb03270", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nclass Main\nfun main(args: Array) {\n val numericInput = Scanner(System.`in`)\n var a = numericInput.nextInt()\n var b = numericInput.nextInt()\n var s = 1\n var q = true\n\n while (a >= 0 && b >= 0) {\n if (q) {\n a -= s\n s++\n q = false\n } else {\n b -= s\n s++\n q = true\n }\n }\n\n if (a < 0) {\n print(\"Vladik\")\n } else {\n print(\"Valera\")\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "baf6345b63fdd254f786564eda8480a2", "src_uid": "87e37a82be7e39e433060fd8cdb03270", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.InputStream\nimport java.math.BigDecimal\nimport java.math.BigInteger\n\nprivate val MOD = 1e9.toLong() + 7\n\nfun main(args: Array) = input.run {\n val a = nextInt()\n val b = nextInt()\n println(if (solve(a, b)) \"Vladik\" else \"Valera\")\n}\n\nfun solve(a: Int, b: Int): Boolean {\n var c = 1\n var x = a\n var y = b\n while (true) {\n if (x < c) {\n return true\n }\n x -= c\n c++\n if (y < c) {\n return false\n }\n y -= c\n c++\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", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "0a0dcc497f52d45379442b5117a95a7a", "src_uid": "87e37a82be7e39e433060fd8cdb03270", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.InputStream\nimport java.math.BigDecimal\nimport java.math.BigInteger\n\n/*******************************************************************/\n\n\n\nfun main(args: Array) = input.run {\n var now = 1\n var a = nextInt()\n var b = nextInt()\n while(a>=0 && b>=0)\n {\n if(now%2==1)\n {\n a-=now\n } else {\n b-=now\n }\n now++\n }\n if(a>=0)print(\"Valera\"); else print(\"Vladik\")\n}\n\n\n\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "4afbb58ae9ceeb9679692ab44943fa11", "src_uid": "87e37a82be7e39e433060fd8cdb03270", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (f, l) = readLine()!!.split(\" \")\n var j = 0\n var ans = f[0].toString()\n for (i in 1 until f.length) {\n if (f[i].toInt() < l[j].toInt()) {\n ans += f[i]\n }else{\n ans+=l[j]\n println(ans)\n return\n }\n }\n ans+=l[j]\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "sortings", "greedy"], "code_uid": "480a67f0adfb2c43edd7b6a6f41e4616", "src_uid": "aed892f2bda10b6aee10dcb834a63709", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 name = next()\n val secondName = next()\n print(\"${name.slice(1 until name.length).takeWhile { it < secondName[0] }.map { \"$it\" }.fold(\"${name[0]}\") { acc, v -> \"$acc$v\" }}${secondName[0]}\")\n close()\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "sortings", "greedy"], "code_uid": "178b277f030630f6c44c19e78cf49a24", "src_uid": "aed892f2bda10b6aee10dcb834a63709", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val s = nextLine().split((\" \").toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()\n val c = s[0].toCharArray()\n val fchar = s[1].get(0)\n val sb = StringBuilder(\"\")\n sb.append(c[0])\n for (i in 1 until c.size) {\n val a = c[i].toInt()\n val b = fchar.toInt()\n if (a < b) sb.append(a.toChar())\n else break\n }\n sb.append(fchar)\n println(sb)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "sortings", "greedy"], "code_uid": "284ddf41298b6b263bd463526c240bbf", "src_uid": "aed892f2bda10b6aee10dcb834a63709", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var (a, b) = readLine()!!.split(' ')\n var ans = \"\"\n var i = 1\n ans = ans.plus(a.get(0))\n var found: Boolean = false\n while (i < a.length) {\n if(a.get(i) < b.get(0)){\n ans = ans.plus(a.get(i))\n }\n else{\n ans = ans.plus(b.get(0))\n found = true\n break\n }\n i++\n }\n if (!found){\n ans = ans.plus(b.get(0))\n }\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "sortings", "greedy"], "code_uid": "35eda92706b1932759fe3814c917d322", "src_uid": "aed892f2bda10b6aee10dcb834a63709", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.log2\n\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n println(log2(n.toDouble()).toInt() + 1)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms"], "code_uid": "99508a4bcf7593a575f234b01339a4bb", "src_uid": "95cb79597443461085e62d974d67a9a0", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms"], "code_uid": "a1d10e114b33a06343123c1db0d7826e", "src_uid": "95cb79597443461085e62d974d67a9a0", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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() }", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms"], "code_uid": "accc10cff5549d6987298973961eba57", "src_uid": "95cb79597443461085e62d974d67a9a0", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var nominal: Int = readLine()!!.toInt()\n var greatestDivisor = 2\n while(nominal>1){\n println(nominal)\n while(nominal%greatestDivisor!=0) greatestDivisor++\n nominal/=greatestDivisor\n }\n println(1)\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "da12c97b29a5a9834be57173a28b2ea2", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\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 var n = readInt()\n val primes = sieve(n)\n val sol = mutableListOf()\n sol.add(n)\n while (n != 1) {\n for (prime in primes) {\n if (n % prime == 0) {\n sol.add(n / prime)\n n /= prime\n break\n }\n }\n }\n print(sol.joinToString(\" \"))\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "225900af2409291034623521be1d12e1", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "90ebb31ef61e8098cb36faea1dc0737e", "src_uid": "e8148140e61baffd0878376ac5f3857c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "60bdf4b54e84c8cc0d44b4d7d917778e", "src_uid": "e8148140e61baffd0878376ac5f3857c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "763baa9e3d3e24456847298202a6a7c7", "src_uid": "e8148140e61baffd0878376ac5f3857c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "f89670d6283f78f784493f756cd8da17", "src_uid": "e8148140e61baffd0878376ac5f3857c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!\n var (a, b, c) = r.readLine()!!.split(\" \").map { it.toInt() }\n b -= 1\n c %= a\n\n b += a\n b += c\n b %= a\n b += 1\n println(b)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "7325d627e70b819a07a470df6d13206b", "src_uid": "cd0e90042a6aca647465f1d51e6dffc4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedOutputStream\nimport java.io.PrintWriter\nimport java.util.*\n\ndata class Position(\n val nextPriliv: Boolean,\n val value: Long\n) {\n fun next(k: Long): Position {\n val nextValue = if (nextPriliv) value + 1 else value - 1\n return when (nextValue) {\n 0L -> Position(true, 0)\n k -> Position(false, k)\n else -> Position(nextPriliv, nextValue)\n }\n }\n}\n\nfun main() {\n val reader = Scanner(System.`in`)\n val out = PrintWriter(BufferedOutputStream(System.`out`))\n\n val t = reader.nextInt()\n repeat(t) {\n val n = reader.nextInt() // Distance\n val k = reader.nextLong() // Priliv time\n val l = reader.nextLong() // Max depth\n val depths = LongArray(n) { reader.nextLong() }\n\n val possibilities = Array(n + 1) { mutableSetOf() }\n for (i in 0L until k) {\n possibilities[0].add(Position(true, i))\n }\n for (i in k downTo 1L) {\n possibilities[0].add(Position(false, i))\n }\n\n for (i in 0 until n) {\n possibilities[i].forEach { position ->\n var nextPosition = position.next(k)\n while (depths[i] + nextPosition.value <= l) {\n possibilities[i + 1].add(nextPosition)\n if (position == nextPosition) {\n break\n }\n nextPosition = nextPosition.next(k)\n }\n }\n }\n if (possibilities[n].isNotEmpty()) {\n out.println(\"Yes\")\n } else {\n out.println(\"No\")\n }\n }\n\n out.flush()\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "dp"], "code_uid": "fa18f4e965736dec02d14f9a93f5be1c", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport kotlin.math.abs\nimport kotlin.math.min\n\nfun main() {\n val jin = BufferedReader(InputStreamReader(System.`in`))\n val out = StringBuilder()\n for (c in 1..jin.readLine().toInt()) {\n val (n, k, l) = jin.readLine().split(\" \").map { it.toInt() }\n val depths = jin.readLine().split(\" \").map { it.toInt() }\n var curr = k\n var answer = true\n for (d in depths) {\n if (d > l) {\n answer = false\n break\n }\n if (d + k <= l) {\n curr = k\n } else if (curr > 0) {\n curr = min(curr - 1, l - d)\n } else {\n if (abs(curr) + 1 + d > l) {\n answer = false\n break\n }\n curr--\n }\n }\n out.appendln(if (answer) \"yEs\" else \"nO\")\n }\n print(out)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "dp"], "code_uid": "3b48af2238b2634ba0318354214dfe4a", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 = readInt()\n case@ for(case in 1..numCases) {\n// print(\"Case #$case: \")\n\n val n = readInt()\n val k = readInt()\n val l = readInt()\n val D = readIntArray(n)\n\n MOD = k + k\n\n val ans = run ans@ {\n var a = ModInt(0)\n var b = ModInt(MOD-1)\n\n for(d in D) {\n when {\n d > l -> return@ans false\n d + k <= l -> {\n a = ModInt(0)\n b = ModInt(MOD-1)\n }\n else -> {\n a++\n b++\n\n val b1 = ModInt(l - d)\n val a1 = -b1\n\n val bp = b - a\n val a1p = a1 - a\n val b1p = b1 - a\n when {\n a1p <= bp -> {\n a = a1\n b = b1\n }\n a1p > b1p -> {\n b = b1\n }\n else -> return@ans false\n }\n }\n }\n }\n\n true\n }\n\n println(if(ans) \"Yes\" else \"No\")\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\noperator fun ModInt.compareTo(other: ModInt) = int.compareTo(other.int)\n\nvar MOD = 998244353\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)\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\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 = ModInt(int.powMod(exponent, MOD))\n\n fun pow(exponent: Long) = ModInt(int.powMod(exponent, MOD))\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\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.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\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)", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "dp"], "code_uid": "2a08f10f64982553fdd63e2ddc699200", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedOutputStream\nimport java.io.PrintWriter\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashSet\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun p(pos: Int, k: Int) =\n if (pos <= k) {\n pos\n } else {\n 2 * k - pos\n }\n\nfun maxWait(d: Int, cur: Int, k: Int, mx: Int): Int {\n var curD = d + p(cur, k)\n return if (cur < k) {\n mx - curD\n } else {\n 2 * k - cur + mx - d\n }\n}\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val pw = PrintWriter(BufferedOutputStream(System.out))\n\n repeat(scanner.nextInt()) {\n val n = scanner.nextInt()\n val k = scanner.nextInt()\n val mx = scanner.nextInt()\n\n val d = mutableListOf()\n\n repeat(n) {\n d.add(scanner.nextInt())\n }\n\n var l = 0\n\n var ans = \"Yes\"\n\n if (d.any { v -> v > mx }) {\n ans = \"No\"\n } else {\n while (l < n) {\n var r = l\n while (r < n && d[r] + k > mx) {\n r++\n }\n\n// pw.println(\"l = $l; r = $r\")\n\n var cur = 0\n\n var can1 = true\n\n for (i in l until r) {\n if (d[i] + p(cur, k) <= mx) {\n if (i < n - 1 && d[i + 1] + p((cur + 1) % (2 * k), k) > mx) {\n if (cur < k) {\n can1 = false\n } else {\n val nextD = d[i + 1] + p((cur + 1) % (2 * k), k)\n val needWait = nextD - mx\n cur = (cur + needWait + 1) % (2 * k)\n }\n } else {\n cur = (cur + 1) % (2 * k)\n }\n } else {\n can1 = false\n }\n }\n\n cur = if (d[l] == mx) {\n 0\n } else {\n 2 * k - (mx - d[l])\n }\n\n var can2 = true\n\n// pw.println(\"cur2 = $cur\")\n\n for (i in l until r) {\n if (d[i] + p(cur, k) <= mx) {\n if (i < n - 1 && d[i + 1] + p((cur + 1) % (2 * k), k) > mx) {\n if (cur < k) {\n can2 = false\n } else {\n val nextD = d[i + 1] + p((cur + 1) % (2 * k), k)\n val needWait = nextD - mx\n cur = (cur + needWait + 1) % (2 * k)\n }\n } else {\n cur = (cur + 1) % (2 * k)\n }\n } else {\n can2 = false\n }\n }\n\n// pw.println(\"1 = $can1; 2 = $can2\")\n\n if (!can1 && !can2) {\n// pw.println(\"l = $l; r = $r\")\n ans = \"No\"\n }\n\n l = r + 1\n }\n }\n\n pw.println(ans)\n }\n\n pw.close()\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "dp"], "code_uid": "5f52089ba71bfcda6434ae088660c9da", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.math.BigInteger\nimport java.util.*\n\nfun main(){\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n var allVariants = BigInteger.valueOf(3)\n var toMinus = BigInteger.valueOf(7)\n toMinus = toMinus.pow(n)\n allVariants = allVariants.pow(3*n) - toMinus\n print(allVariants.mod(BigInteger.valueOf(1000000007)))\n}", "lang_cluster": "Kotlin", "tags": ["combinatorics"], "code_uid": "c001f6676a905d75bbaec90d816cf2be", "src_uid": "eae87ec16c284f324d86b7e65fda093c", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "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", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "c96575ea76b4eaee6363ffba38e6d307", "src_uid": "c3694a6ff95c64bef8cbe8834c3fd6cb", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "5b957dddb5aa432328782cf26d9e2c9f", "src_uid": "9edf42c20ddf22a251b84553d7305a7d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "0ff725e52fd4e52a561c3aa124aae3df", "src_uid": "9edf42c20ddf22a251b84553d7305a7d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "2c72d17a10ca1cffe00c2ecdb4d806a6", "src_uid": "9edf42c20ddf22a251b84553d7305a7d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "1dc3f8ffcc480f9db9d97b9b57eebcf2", "src_uid": "9edf42c20ddf22a251b84553d7305a7d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLine()!!\n var zerosLeft = 0\n var zerosRight = 0\n for (c in s)\n if (c == '0') zerosLeft++ else break\n for (c in s.reversed())\n if (c == '0') zerosRight++ else break\n if (zerosLeft > zerosRight) return print(\"NO\")\n val center = s.substring(zerosLeft, s.length - zerosRight)\n print(if (center == center.reversed()) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "6a9f040e91472c0652ce8bec20df73ee", "src_uid": "d82278932881e3aa997086c909f29051", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\n\nval sc = java.util.Scanner(System.`in`)\n\ndata class Interval(val L: Int, val R: Int) : Comparable {\n\toverride fun compareTo(other: Interval): Int {\n\t\treturn compareValuesBy(this, other, Interval::L, Interval::R)\n\t}\n}\n\nfun main(args: Array) {\n\tvar n = sc.nextInt()\n\twhile (n % 10 == 0) n /= 10\n\tval a = n.toString()\n\tval b = a.reversed()\n\tprintln(if (a == b) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "834787af26dfae4821d1fd5a286202c0", "src_uid": "d82278932881e3aa997086c909f29051", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nfun main(args: Array) { var reader = Scanner(System.`in`)\n var n:Int = reader.nextInt()\n var s:String =n.toString()\n var c = 0\n var arrL = arrayListOf()\n var arrR = arrayListOf()\n for (i in 0..s.length-1) arrL.add(s[i])\n for (i in s.length-1 downTo 0) {\n if (arrL[i]=='0')\n arrL.removeAt(i)\n else break\n }\n for (i in 0..arrL.size-1) arrR.add(arrL[(arrL.size-1)-i])\n for (i in 0..arrL.size-1) {\n if (arrL[i]==arrR[i])\n c++\n }\n if (c==arrL.size) println(\"YES\")\n else print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "36e0f6e0a5511aad024583ca2966a4f4", "src_uid": "d82278932881e3aa997086c909f29051", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "import kotlin.math.min\n\nclass FactorialCache(size: Int, private val mod: Long) {\n private val list = LongArray(size + 1) { 0 }\n private var current = 1\n\n init {\n list[0] = 1\n list[1] = 1\n }\n\n fun get(n: Int): MLong {\n if (current < n) {\n for (i in (current + 1)..n) {\n list[i] = (i * list[i - 1]) % mod\n }\n current = n\n }\n return MLong(list[n])\n }\n}\n\nvar MOD = 1_000_000_007L\n\n@JvmInline\nvalue class MLong(private val value: Long) {\n\n operator fun plus(other: MLong): MLong {\n return MLong((value + other.value) % MOD)\n }\n\n operator fun minus(other: MLong): MLong {\n var ret = (value - other.value) % MOD\n if (ret < 0) {\n ret += MOD\n }\n return MLong(ret)\n }\n\n operator fun times(other: MLong): MLong {\n return MLong((value * other.value) % MOD)\n }\n\n fun pow(power: Long): MLong {\n var ret = 1L\n var current = value\n var p = 0\n while (1L shl p < power) {\n if (power and (1L shl p) != 0L) {\n ret = (ret * current) % MOD\n }\n current = (current * current) % MOD\n p++\n }\n return MLong(ret)\n }\n\n override fun toString() = value.toString()\n}\n\nvar fact = FactorialCache(100_000, MOD)\n\nfun nck(n: Int, k: Int): MLong {\n return fact.get(n) * (fact.get(n - k) * fact.get(k)).pow(MOD - 2)\n}\n\nfun main() {\n var (n, k) = readln().split(\" \").map { it.toInt() }\n\n var ret = MLong(0L)\n for (m in 0..min(n, k)) {\n ret += nck(n, m)\n }\n println(ret)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "c92d6afa68b8a2e9a0c340600615b0b8", "src_uid": "dc7b887afcc2e95c4e90619ceda63071", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "// 2022.09.02 at 15:46:26 BST\r\nimport java.io.BufferedInputStream\r\nimport java.io.File\r\nimport java.io.PrintWriter\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\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\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\n\r\nconst val singleCase = true\r\nfun main(){\r\n FACT.preCal(100005)\r\n solve.cases{\r\n\r\n val n = getint\r\n val k = getint\r\n\r\n var ret = 0\r\n for(i in 0..minOf(n,k)){\r\n ret = ret modPlus FACT.choose(n,i)\r\n }\r\n put(ret)\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\r\n/*\r\n1 5 3 7 2 6 4 8\r\n */", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "2f32c0f86279c681e7db57c65fb70f3f", "src_uid": "dc7b887afcc2e95c4e90619ceda63071", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "import kotlin.math.min\n\nclass FactorialCache(size: Int, private val mod: Long) {\n private val list = LongArray(size + 1) { 0 }\n private var current = 1\n\n init {\n list[0] = 1\n list[1] = 1\n }\n\n fun get(n: Int): MLong {\n if (current < n) {\n for (i in (current + 1)..n) {\n list[i] = (i * list[i - 1]) % mod\n }\n current = n\n }\n return MLong(list[n])\n }\n}\n\nvar MOD = 1_000_000_007L\n\n@JvmInline\nvalue class MLong(private val value: Long) {\n\n operator fun plus(other: MLong): MLong {\n return MLong((value + other.value) % MOD)\n }\n\n operator fun minus(other: MLong): MLong {\n var ret = (value - other.value) % MOD\n if (ret < 0) {\n ret += MOD\n }\n return MLong(ret)\n }\n\n operator fun times(other: MLong): MLong {\n return MLong((value * other.value) % MOD)\n }\n\n fun pow(power: Long): MLong {\n var ret = 1L\n var current = value\n var p = 1L\n while (p < power) {\n if (power and p != 0L) {\n ret = (ret * current) % MOD\n }\n current = (current * current) % MOD\n p *= 2\n }\n return MLong(ret)\n }\n\n override fun toString() = value.toString()\n}\n\nvar fact = FactorialCache(100_000, MOD)\n\nfun nck(n: Int, k: Int): MLong {\n return fact.get(n) * (fact.get(n - k) * fact.get(k)).pow(MOD - 2)\n}\n\nfun main() {\n var (n, k) = readln().split(\" \").map { it.toInt() }\n\n var ret = MLong(0L)\n for (m in 0..min(n, k)) {\n ret += nck(n, m)\n }\n println(ret)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "7d563340e3c6a42674bb71ab994751c9", "src_uid": "dc7b887afcc2e95c4e90619ceda63071", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport java.util.NoSuchElementException\nimport java.io.IOException\nimport java.io.PrintWriter\nimport java.math.BigInteger\nimport java.util.PriorityQueue\nimport java.util.Arrays\nimport java.util.ArrayList\n\n\nvar sc = FastScanner()\nvar pw = PrintWriter(System.out)\n\nfun main(args: Array) {\n var _X = sc.nextLong()\n var _Y = sc.nextLong()\n var _L = sc.nextLong()\n var _R = sc.nextLong()\n\n var X = BigInteger(_X.toString())\n var Y = BigInteger(_Y.toString())\n var L = BigInteger(_L.toString())\n var R = BigInteger(_R.toString())\n\n var set:MutableSet = mutableSetOf()\n var XX = BigInteger(\"1\")\n for(a in 0..64) {\n if(R < XX) break\n var YY = BigInteger(\"1\")\n for(b in 0..64) {\n if(R < XX) break\n if(L <= XX + YY && XX + YY <= R) {\n var x = (XX + YY).toLong()\n set.add(x)\n }\n YY *= Y\n }\n XX *= X\n }\n\n if(set.size == 0) {\n println(_R - _L + 1)\n return\n }\n\n set = set.toSortedSet()\n var ans = 0L\n var pre = -1L\n for(i in set.sorted()) {\n if(0 <= pre) ans = Math.max(ans, i - pre - 1)\n pre = i\n }\n ans = Math.max(ans, set.first() - _L)\n ans = Math.max(ans, _R - set.last())\n println(ans)\n}\n\n\n\n\n\nclass FastScanner {\n private val `in` = System.`in`\n private val buffer = ByteArray(1024)\n private var ptr = 0\n private var bufferLength = 0\n\n private fun hasNextByte(): Boolean {\n if (ptr < bufferLength) {\n return true\n } else {\n ptr = 0\n try {\n bufferLength = `in`.read(buffer)\n } catch (e: IOException) {\n e.printStackTrace()\n }\n\n if (bufferLength <= 0) {\n return false\n }\n }\n return true\n }\n\n private fun readByte(): Int {\n if (hasNextByte())\n return buffer[ptr++].toInt()\n else\n return -1\n }\n\n private fun isPrintableChar(c: Int): Boolean {\n return 33 <= c && c <= 126\n }\n\n private fun skipUnprintable() {\n while (hasNextByte() && !isPrintableChar(buffer[ptr].toInt())) ptr++\n }\n\n internal operator fun hasNext(): Boolean {\n skipUnprintable()\n return hasNextByte()\n }\n\n operator fun next(): String {\n if (!hasNext()) throw NoSuchElementException()\n val sb = StringBuilder()\n var b = readByte()\n while (isPrintableChar(b)) {\n sb.appendCodePoint(b)\n b = readByte()\n }\n return sb.toString()\n }\n\n internal fun nextLong(): Long {\n if (!hasNext()) throw NoSuchElementException()\n var n: Long = 0\n var minus = false\n var b = readByte()\n if (b == '-'.toInt()) {\n minus = true\n b = readByte()\n }\n if (b < '0'.toInt() || '9'.toInt() < b) {\n throw NumberFormatException()\n }\n while (true) {\n if ('0'.toInt() <= b && b <= '9'.toInt()) {\n n *= 10\n n += (b - '0'.toInt()).toLong()\n } else if (b == -1 || !isPrintableChar(b)) {\n return if (minus) -n else n\n } else {\n throw NumberFormatException()\n }\n b = readByte()\n }\n }\n\n internal fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n internal fun nextDoubleArray(n: Int): DoubleArray {\n val array = DoubleArray(n)\n for (i in 0..n - 1) {\n array[i] = nextDouble()\n }\n return array\n }\n\n internal fun nextDoubleMap(n: Int, m: Int): Array {\n val map = arrayOfNulls(n)\n for (i in 0..n - 1) {\n map[i] = nextDoubleArray(m)\n }\n return map\n }\n\n fun nextInt(): Int {\n return nextLong().toInt()\n }\n\n fun nextIntArray(n: Int): IntArray {\n val array = IntArray(n)\n for (i in 0..n - 1) {\n array[i] = nextInt()\n }\n return array\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "00eb4528d5ac421f71b5a780edf40d2a", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun main() {\n var n = readInt()\n var str = readStr()!!\n var key = \"ACTG\"\n var min = Int.MAX_VALUE\n var i = 0\n while (i < n - 3) {\n var sum = 0\n for (j in 0..3){\n sum+=dis(key[j],str[i+j])\n }\n min = minOf(sum,min)\n i++\n }\n println(min)\n}\n\nprivate fun dis(a: Char, b: Char): Int {\n var dis = abs(a-b)\n return minOf(dis,26-dis)\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()!!", "lang_cluster": "Kotlin", "tags": ["brute force", "strings"], "code_uid": "858cbff671a615c1c4beca2a934e1825", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\n\nfun main(args: Array){\n\tval n = readLine()!!.toInt()\n\tval str = readLine()!!.toString()\n\tval genome = listOf('A','C','T','G')\n\tvar minresult = 999\n\tfor(i in 0..n-4){\n\t\tvar result = 0\n\t\tval subs = str.substring(i,i+4)\n\t\tfor(j in 0..3){\n\t\t\t// println(dist(subs[j],genome[j]))\n\t\t\tresult += dist(subs[j],genome[j])\n\t\t}\n\t\tif(result < minresult) minresult = result\n\t}\n\tprintln(minresult)\n}\n\nfun dist(a: Char, b: Char): Int{\n\tval (f, s) = listOf(a, b).sorted()\n\treturn min(s.toInt() - f.toInt(), 26 - s.toInt() + f.toInt())\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings"], "code_uid": "4c47aee33e42c3d42740505d10971d2d", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n fun min(c: Char, c1: Char) = if (c <= c1) c else c1\n fun max(c: Char, c1: Char) = if (c >= c1) c else c1\n\n val n = readLine()!!.toInt()\n val s = readLine()!!\n val genome = \"ACTG\"\n var sol = Int.MAX_VALUE\n for (start in 0..n - 4) {\n var solCandidate = 0\n for (pos in 0..3) {\n val realPos = start + pos\n val (smaller, bigger) = min(genome[pos], s[realPos]) to max(genome[pos], s[realPos])\n solCandidate += min(bigger - smaller, smaller + 26 - bigger)\n }\n sol = min(sol, solCandidate)\n }\n print(sol)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "strings"], "code_uid": "c927969a399e0de5122cfca5e34b26bd", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n//2019-04-20\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val genom = \"ACTG\"\n nextInt()\n val line = next()\n\n print((0..line.length - 4)\n .map { line.substring(it, it + 4) }\n .map { genom.diff(it) }\n .min())\n}\n\nprivate fun String.diff(s: String) = (0 until length).map { s[it].diff(get(it)) }.sum()\n\nprivate fun Char.diff(c: Char): Int {\n val a: MutableList = mutableListOf()\n a.addIfNotNegative(this - c)\n a.addIfNotNegative(c - this)\n a.addIfNotNegative(reverseDiff(c, this))\n a.addIfNotNegative(reverseDiff(this, c))\n return a.min()!!\n}\n\nprivate fun reverseDiff(c: Char, c1: Char) = ('Z' - c1) + (c - 'A') + 1\n\nprivate fun MutableList.addIfNotNegative(e: Int) {\n if (e >= 0) add(e)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "strings"], "code_uid": "98d58c724b8668c1e340fba7b0ffff5a", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 Xp = ni()\n val Yp = ni()\n val Xv = ni()\n val Yv = ni()\n\n var win = false\n val diagonal = min(Xv, Yv)\n for (i in 1 .. diagonal) {\n val x = Xv - i\n val y = Yv - i\n if (Xp >= x && Yp >= y) {\n val tp = Xp - x + Yp - y\n val tv = i\n win = win || tp <= tv\n }\n }\n\n for (i in 1 .. max(Xv, Yv) - diagonal) {\n val x = max(0, Xv - diagonal - i)\n val y = max(0, Yv - diagonal - i)\n if (Xp >= x && Yp >= y) {\n val tp = Xp - x + Yp - y\n val tv = i + diagonal\n win = win || tp <= tv\n }\n }\n\n if (win) out.println(\"Polycarp\")\n else out.println(\"Vasiliy\")\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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, offset) { ni() }\n }\n\n private inline fun map(n: Int, offset: Int = 0, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i + offset)\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun pair(a: A, b: B) = RPair(a, b)\ndata class RPair(val _1: A, val _2: B)\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation", "games"], "code_uid": "2fbbf1fcc524b889121eb405349da6cd", "src_uid": "2637d57f7809ff8f922549c617709074", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.abs\nimport kotlin.math.min\n\nprivate val scan = Scanner(System.`in`)\n\nfun main(args: Array) {\n\n val n = scan.nextLong()\n val a = (0 until n/2).map { scan.nextLong() - 1 }.sorted()\n\n val oddSum = a.mapIndexed { index, value -> abs(value - (2 * index + 1)) }.sum()\n val evenSum = a.mapIndexed { index, value -> abs(value - 2 * index) }.sum()\n\n println(min(oddSum, evenSum))\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7361ebffdd7ab24a9111ba27b61509a1", "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport java.lang.Math.*\n\nconst val STRESS = false\nconst val STRESS_ITER = 100\n\ndata class Solver(val io: FastIO) {\n fun FastIO.solve() {\n val n = nextInt()\n val a = IntList(n / 2, { nextInt() - 1 })\n var a1 = 0\n var a2 = 0\n a.sort()\n for (i in 0 until a.size) {\n a1 += abs(a[i] - i * 2)\n a2 += abs(a[i] - i * 2 - 1)\n }\n println(min(a1, a2))\n }\n\n fun run() {\n io.use { it.solve() }\n }\n}\n\nfun main(args: Array) {\n if (args.isNotEmpty() && args[0] == \"KLOCAL\") {\n if (STRESS) {\n Stresser.doStress()\n } else {\n Solver(FastIO(FileInputStream(\"input.txt\"), System.out)).run()\n }\n } else {\n Solver(FastIO(System.`in`, System.out)).run()\n }\n}\n\ndata class SlowSolver(val io: FastIO) {\n fun FastIO.slowSolve() {\n\n }\n\n fun run() {\n io.use { it.slowSolve() }\n }\n}\n\nclass Stresser {\n companion object {\n const val INPUT = \"input.txt\"\n const val OUTPUT = \"output.txt\"\n const val SLOW = \"slow.txt\"\n\n fun PrintWriter.generateTest() {\n val rand = Random(31)\n\n }\n\n fun doStress() {\n for (it in 1..STRESS_ITER) {\n System.err.println(it)\n PrintWriter(INPUT).use { it.generateTest() }\n SlowSolver(FastIO(FileInputStream(INPUT), FileOutputStream(SLOW))).run()\n Solver(FastIO(FileInputStream(INPUT), FileOutputStream(OUTPUT))).run()\n compareFiles()\n }\n }\n\n fun compareFiles() {\n val out = File(OUTPUT).readLines().toMutableList()\n val slw = File(SLOW).readLines().toMutableList()\n while (out.size < slw.size) {\n out.add(\"\\n\")\n }\n while (out.size > slw.size) {\n slw.add(\"\\n\")\n }\n for (i in 0 until out.size) {\n if (out[i].trimEnd() != slw[i].trimEnd()) {\n throw AssertionError(\"\\nline ${i + 1}\\nout: ${out[i]}\\nslw: ${slw[i]}\")\n }\n }\n }\n }\n}\n\nclass FastIO(input: InputStream, output: OutputStream) : PrintWriter(output, false) {\n val br = BufferedReader(InputStreamReader(input))\n var stok = StringTokenizer(\"\")\n\n fun nextToken(): String? {\n while (!stok.hasMoreTokens()) {\n val s = br.readLine() ?: return null\n stok = StringTokenizer(s)\n }\n return stok.nextToken()\n }\n\n fun nextInt(): Int {\n return nextToken()!!.toInt()\n }\n\n fun nextLong(): Long {\n return nextToken()!!.toLong()\n }\n\n fun nextDouble(): Double {\n return nextToken()!!.toDouble()\n }\n\n fun print(vararg args: Any?) {\n args.forEachIndexed { i, arg ->\n if (i != 0) {\n print(\" \")\n }\n print(arg)\n }\n }\n\n fun println(vararg args: Any?) {\n print(*args)\n println()\n }\n}\n\nclass IntList {\n private var a: IntArray\n var size = 0\n\n constructor() {\n a = IntArray(4)\n }\n\n constructor(n: Int, x: Int = 0) {\n a = if (x == 0) {\n IntArray(n)\n } else {\n IntArray(n, { x })\n }\n size = n\n }\n\n constructor(n: Int, init: (Int) -> Int) {\n a = IntArray(n, init)\n size = n\n }\n\n fun add(x: Int) {\n ensureCapacity()\n a[size++] = x\n }\n\n fun front(): Int {\n return a[0]\n }\n\n fun back(): Int {\n return a[size - 1]\n }\n\n fun pop(): Int {\n return a[--size]\n }\n\n operator fun get(i: Int): Int {\n return a[i]\n }\n\n operator fun set(i: Int, x: Int) {\n a[i] = x\n }\n\n fun removeAt(i: Int) {\n var i = i\n while (i + 1 < size) {\n a[i] = a[i + 1]\n i++\n }\n --size\n }\n\n fun rotate(distance: Int) {\n if (size == 0)\n return\n var distance = distance % size\n if (distance < 0)\n distance += size\n if (distance == 0)\n return\n\n var cycleStart = 0\n var nMoved = 0\n while (nMoved != size) {\n var displaced = a[cycleStart]\n var i = cycleStart\n do {\n i += distance\n if (i >= size)\n i -= size\n val tmp = a[i]\n a[i] = displaced\n displaced = tmp\n nMoved++\n } while (i != cycleStart)\n cycleStart++\n }\n }\n\n fun isEmpty(): Boolean {\n return size == 0\n }\n\n operator fun contains(x: Int): Boolean {\n for (i in 0 until size) {\n if (a[i] == x) {\n return true\n }\n }\n return false\n }\n\n override fun equals(other: Any?): Boolean {\n if (other == null || other !is IntList || size != other.size) {\n return false\n }\n\n for (i in 0 until size) {\n if (a[i] != other.a[i]) {\n return false\n }\n }\n\n return true\n }\n\n operator fun compareTo(other: IntList): Int {\n var i = 0\n while (i < min(size, other.size)) {\n if (a[i] < other.a[i]) {\n return -1\n }\n if (a[i] > other.a[i]) {\n return 1\n }\n }\n if (size < other.size) {\n return -1\n }\n if (size > other.size) {\n return 1\n }\n return 0\n }\n\n fun sort(from: Int = 0, to: Int = size) {\n a.sort(from, to)\n }\n\n fun reverse() {\n var i = 0\n while (i * 2 < size) {\n val x = a[i]\n a[i] = a[size - 1 - i]\n a[size - 1 - i] = x\n i++\n }\n }\n\n fun shuffle(rand: Random = Random()) {\n for (i in 1 until size) {\n val j = rand.nextInt(i + 1)\n if (i != j) {\n val x = a[i]\n a[i] = a[j]\n a[j] = x\n }\n }\n }\n\n fun nextPermutation(): Boolean {\n var i = size - 2\n while (i >= 0) {\n if (a[i] < a[i + 1]) {\n var b = size - 1\n while (true) {\n if (a[b] > a[i]) {\n var t = a[i]\n a[i] = a[b]\n a[b] = t\n ++i\n b = size - 1\n while (i < b) {\n t = a[i]\n a[i] = a[b]\n a[b] = t\n ++i\n --b\n }\n return true\n }\n --b\n }\n }\n --i\n }\n return false\n }\n\n fun forEach(block: (x: Int) -> Unit) {\n for (i in 0 until size) {\n block(a[i])\n }\n }\n\n fun forEachIndexed(block: (i: Int, x: Int) -> Unit) {\n for (i in 0 until size) {\n block(i, a[i])\n }\n }\n\n fun getArray(): IntArray {\n return a.copyOf(size)\n }\n\n private fun ensureCapacity() {\n if (size == a.size) {\n a = a.copyOf(size * 2)\n }\n }\n}\n\nclass LongList {\n private var a: LongArray\n var size = 0\n\n constructor() {\n a = LongArray(4)\n }\n\n constructor(n: Int, x: Long = 0) {\n a = if (x == 0L) {\n LongArray(n)\n } else {\n LongArray(n, { x })\n }\n size = n\n }\n\n constructor(n: Int, init: (Int) -> Long) {\n a = LongArray(n, init)\n size = n\n }\n\n fun add(x: Long) {\n ensureCapacity()\n a[size++] = x\n }\n\n fun front(): Long {\n return a[0]\n }\n\n fun back(): Long {\n return a[size - 1]\n }\n\n fun pop(): Long {\n return a[--size]\n }\n\n operator fun get(i: Int): Long {\n return a[i]\n }\n\n operator fun set(i: Int, x: Long) {\n a[i] = x\n }\n\n fun removeAt(i: Int) {\n var i = i\n while (i + 1 < size) {\n a[i] = a[i + 1]\n i++\n }\n --size\n }\n\n fun rotate(distance: Int) {\n if (size == 0)\n return\n var distance = distance % size\n if (distance < 0)\n distance += size\n if (distance == 0)\n return\n\n var cycleStart = 0\n var nMoved = 0\n while (nMoved != size) {\n var displaced = a[cycleStart]\n var i = cycleStart\n do {\n i += distance\n if (i >= size)\n i -= size\n val tmp = a[i]\n a[i] = displaced\n displaced = tmp\n nMoved++\n } while (i != cycleStart)\n cycleStart++\n }\n }\n\n fun isEmpty(): Boolean {\n return size == 0\n }\n\n operator fun contains(x: Long): Boolean {\n for (i in 0 until size) {\n if (a[i] == x) {\n return true\n }\n }\n return false\n }\n\n override fun equals(other: Any?): Boolean {\n if (other == null || other !is LongList || size != other.size) {\n return false\n }\n\n for (i in 0 until size) {\n if (a[i] != other.a[i]) {\n return false\n }\n }\n\n return true\n }\n\n operator fun compareTo(other: LongList): Int {\n var i = 0\n while (i < min(size, other.size)) {\n if (a[i] < other.a[i]) {\n return -1\n }\n if (a[i] > other.a[i]) {\n return 1\n }\n }\n if (size < other.size) {\n return -1\n }\n if (size > other.size) {\n return 1\n }\n return 0\n }\n\n fun sort(from: Int = 0, to: Int = size) {\n a.sort(from, to)\n }\n\n fun reverse() {\n var i = 0\n while (i * 2 < size) {\n val x = a[i]\n a[i] = a[size - 1 - i]\n a[size - 1 - i] = x\n i++\n }\n }\n\n fun shuffle(rand: Random = Random()) {\n for (i in 1 until size) {\n val j = rand.nextInt(i + 1)\n if (i != j) {\n val x = a[i]\n a[i] = a[j]\n a[j] = x\n }\n }\n }\n\n fun nextPermutation(): Boolean {\n var i = size - 2\n while (i >= 0) {\n if (a[i] < a[i + 1]) {\n var b = size - 1\n while (true) {\n if (a[b] > a[i]) {\n var t = a[i]\n a[i] = a[b]\n a[b] = t\n ++i\n b = size - 1\n while (i < b) {\n t = a[i]\n a[i] = a[b]\n a[b] = t\n ++i\n --b\n }\n return true\n }\n --b\n }\n }\n --i\n }\n return false\n }\n\n fun forEach(block: (x: Long) -> Unit) {\n for (i in 0 until size) {\n block(a[i])\n }\n }\n\n fun forEachIndexed(block: (i: Int, x: Long) -> Unit) {\n for (i in 0 until size) {\n block(i, a[i])\n }\n }\n\n fun getArray(): LongArray {\n return a.copyOf(size)\n }\n\n private fun ensureCapacity() {\n if (size == a.size) {\n a = a.copyOf(size * 2)\n }\n }\n}\n\nclass DoubleList {\n private var a: DoubleArray\n var size = 0\n\n constructor() {\n a = DoubleArray(4)\n }\n\n constructor(n: Int, x: Double = .0) {\n a = if (x == .0) {\n DoubleArray(n)\n } else {\n DoubleArray(n, { x })\n }\n size = n\n }\n\n constructor(n: Int, init: (Int) -> Double) {\n a = DoubleArray(n, init)\n size = n\n }\n\n fun add(x: Double) {\n ensureCapacity()\n a[size++] = x\n }\n\n fun front(): Double {\n return a[0]\n }\n\n fun back(): Double {\n return a[size - 1]\n }\n\n fun pop(): Double {\n return a[--size]\n }\n\n operator fun get(i: Int): Double {\n return a[i]\n }\n\n operator fun set(i: Int, x: Double) {\n a[i] = x\n }\n\n fun removeAt(i: Int) {\n var i = i\n while (i + 1 < size) {\n a[i] = a[i + 1]\n i++\n }\n --size\n }\n\n fun rotate(distance: Int) {\n if (size == 0)\n return\n var distance = distance % size\n if (distance < 0)\n distance += size\n if (distance == 0)\n return\n\n var cycleStart = 0\n var nMoved = 0\n while (nMoved != size) {\n var displaced = a[cycleStart]\n var i = cycleStart\n do {\n i += distance\n if (i >= size)\n i -= size\n val tmp = a[i]\n a[i] = displaced\n displaced = tmp\n nMoved++\n } while (i != cycleStart)\n cycleStart++\n }\n }\n\n fun isEmpty(): Boolean {\n return size == 0\n }\n\n operator fun contains(x: Double): Boolean {\n for (i in 0 until size) {\n if (a[i] == x) {\n return true\n }\n }\n return false\n }\n\n override fun equals(other: Any?): Boolean {\n if (other == null || other !is DoubleList || size != other.size) {\n return false\n }\n\n for (i in 0 until size) {\n if (a[i] != other.a[i]) {\n return false\n }\n }\n\n return true\n }\n\n operator fun compareTo(other: DoubleList): Int {\n var i = 0\n while (i < min(size, other.size)) {\n if (a[i] < other.a[i]) {\n return -1\n }\n if (a[i] > other.a[i]) {\n return 1\n }\n }\n if (size < other.size) {\n return -1\n }\n if (size > other.size) {\n return 1\n }\n return 0\n }\n\n fun sort(from: Int = 0, to: Int = size) {\n a.sort(from, to)\n }\n\n fun reverse() {\n var i = 0\n while (i * 2 < size) {\n val x = a[i]\n a[i] = a[size - 1 - i]\n a[size - 1 - i] = x\n i++\n }\n }\n\n fun shuffle(rand: Random = Random()) {\n for (i in 1 until size) {\n val j = rand.nextInt(i + 1)\n if (i != j) {\n val x = a[i]\n a[i] = a[j]\n a[j] = x\n }\n }\n }\n\n fun nextPermutation(): Boolean {\n var i = size - 2\n while (i >= 0) {\n if (a[i] < a[i + 1]) {\n var b = size - 1\n while (true) {\n if (a[b] > a[i]) {\n var t = a[i]\n a[i] = a[b]\n a[b] = t\n ++i\n b = size - 1\n while (i < b) {\n t = a[i]\n a[i] = a[b]\n a[b] = t\n ++i\n --b\n }\n return true\n }\n --b\n }\n }\n --i\n }\n return false\n }\n\n fun forEach(block: (x: Double) -> Unit) {\n for (i in 0 until size) {\n block(a[i])\n }\n }\n\n fun forEachIndexed(block: (i: Int, x: Double) -> Unit) {\n for (i in 0 until size) {\n block(i, a[i])\n }\n }\n\n fun getArray(): DoubleArray {\n return a.copyOf(size)\n }\n\n private fun ensureCapacity() {\n if (size == a.size) {\n a = a.copyOf(size * 2)\n }\n }\n}\n\nclass BooleanList {\n private var a: BooleanArray\n var size = 0\n\n constructor() {\n a = BooleanArray(4)\n }\n\n constructor(n: Int, x: Boolean = false) {\n a = if (x == false) {\n BooleanArray(n)\n } else {\n BooleanArray(n, { x })\n }\n size = n\n }\n\n constructor(n: Int, init: (Int) -> Boolean) {\n a = BooleanArray(n, init)\n size = n\n }\n\n fun add(x: Boolean) {\n ensureCapacity()\n a[size++] = x\n }\n\n fun front(): Boolean {\n return a[0]\n }\n\n fun back(): Boolean {\n return a[size - 1]\n }\n\n fun pop(): Boolean {\n return a[--size]\n }\n\n operator fun get(i: Int): Boolean {\n return a[i]\n }\n\n operator fun set(i: Int, x: Boolean) {\n a[i] = x\n }\n\n fun removeAt(i: Int) {\n var i = i\n while (i + 1 < size) {\n a[i] = a[i + 1]\n i++\n }\n --size\n }\n\n fun rotate(distance: Int) {\n if (size == 0)\n return\n var distance = distance % size\n if (distance < 0)\n distance += size\n if (distance == 0)\n return\n\n var cycleStart = 0\n var nMoved = 0\n while (nMoved != size) {\n var displaced = a[cycleStart]\n var i = cycleStart\n do {\n i += distance\n if (i >= size)\n i -= size\n val tmp = a[i]\n a[i] = displaced\n displaced = tmp\n nMoved++\n } while (i != cycleStart)\n cycleStart++\n }\n }\n\n fun isEmpty(): Boolean {\n return size == 0\n }\n\n operator fun contains(x: Boolean): Boolean {\n for (i in 0 until size) {\n if (a[i] == x) {\n return true\n }\n }\n return false\n }\n\n override fun equals(other: Any?): Boolean {\n if (other == null || other !is BooleanList || size != other.size) {\n return false\n }\n\n for (i in 0 until size) {\n if (a[i] != other.a[i]) {\n return false\n }\n }\n\n return true\n }\n\n operator fun compareTo(other: BooleanList): Int {\n var i = 0\n while (i < min(size, other.size)) {\n if (a[i] < other.a[i]) {\n return -1\n }\n if (a[i] > other.a[i]) {\n return 1\n }\n }\n if (size < other.size) {\n return -1\n }\n if (size > other.size) {\n return 1\n }\n return 0\n }\n\n fun reverse() {\n var i = 0\n while (i * 2 < size) {\n val x = a[i]\n a[i] = a[size - 1 - i]\n a[size - 1 - i] = x\n i++\n }\n }\n\n fun shuffle(rand: Random = Random()) {\n for (i in 1 until size) {\n val j = rand.nextInt(i + 1)\n if (i != j) {\n val x = a[i]\n a[i] = a[j]\n a[j] = x\n }\n }\n }\n\n fun nextPermutation(): Boolean {\n var i = size - 2\n while (i >= 0) {\n if (a[i] < a[i + 1]) {\n var b = size - 1\n while (true) {\n if (a[b] > a[i]) {\n var t = a[i]\n a[i] = a[b]\n a[b] = t\n ++i\n b = size - 1\n while (i < b) {\n t = a[i]\n a[i] = a[b]\n a[b] = t\n ++i\n --b\n }\n return true\n }\n --b\n }\n }\n --i\n }\n return false\n }\n\n fun forEach(block: (x: Boolean) -> Unit) {\n for (i in 0 until size) {\n block(a[i])\n }\n }\n\n fun forEachIndexed(block: (i: Int, x: Boolean) -> Unit) {\n for (i in 0 until size) {\n block(i, a[i])\n }\n }\n\n fun getArray(): BooleanArray {\n return a.copyOf(size)\n }\n\n private fun ensureCapacity() {\n if (size == a.size) {\n a = a.copyOf(size * 2)\n }\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9d139a5fe32061ff7777dca6f8cb35a1", "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.abs\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()\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 n = reader.nextInt()\n val m = n / 2\n val a = reader.nextArrayInt(m).sorted()\n\n var i = 1\n var j = 2\n var count1 = 0\n var count2 = 0\n a.forEach {\n count1 += abs(i - it)\n count2 += abs(j - it)\n i += 2\n j += 2\n }\n writer.println(\"${min(count1, count2)}\")\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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "859955be656932fae13e646419e0ec35", "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\nimport kotlin.math.min\n\nfun main(args : Array) {\n val n = readLine()!!.toInt()\n var arr : Array = readLine()!!.split(' ').map { it.toInt() }.toTypedArray()\n arr.sort()\n var moves1 = 0\n var moves2 = 0\n for (i in 1..(n/2)) {\n moves1 += abs(arr[i-1] - (i*2))\n moves2 += abs(arr[i-1] - (i*2 -1))\n }\n println(min(moves1, moves2))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "0ce13bff28edca719b06f590ddcecee5", "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "f00510bbe82ad55ac1d6f93f2bd8282c", "src_uid": "5257f6b50f5a610a17c35a47b3a0da11", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "6e05772042d2947b29f710b21ca3e729", "src_uid": "5257f6b50f5a610a17c35a47b3a0da11", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (a, b, c, d) = readInts()\n val diff = max(3 * a / 10, a - a / 250 * c) - max(3 * b / 10, b - b / 250 * d)\n print(\n when {\n diff > 0 -> \"Misha\"\n diff == 0 -> \"Tie\"\n else -> \"Vasya\"\n }\n )\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "f149fe5d44f5fab591feb5f7b458e5e4", "src_uid": "95b19d7569d6b70bd97d46a8541060d0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.max\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val mishaP = sc.nextInt()\n val VasyaP = sc.nextInt()\n val mishaT = sc.nextInt()\n val vasyaT = sc.nextInt()\n val mishaPoints = getPoints(mishaP, mishaT)\n val vasyaPoints = getPoints(VasyaP, vasyaT)\n if (mishaPoints > vasyaPoints) {\n print(\"Misha\")\n } else if (mishaPoints == vasyaPoints) {\n print(\"Tie\")\n } else print(\"Vasya\")\n\n}\n\nfun getPoints(p: Int, t: Int) = max(p * 3 / 10f, p - p / 250f * t)\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "522bb151385485a56c3358d9cd3aee40", "src_uid": "95b19d7569d6b70bd97d46a8541060d0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedInputStream\nimport java.io.BufferedOutputStream\nimport java.io.OutputStreamWriter\nimport java.util.*\nimport kotlin.math.max\n\nfun main(args: Array) {\n val scanner = Scanner(BufferedInputStream(System.`in`))\n val output = OutputStreamWriter(BufferedOutputStream(System.out))\n\n val a = scanner.nextInt()\n val b = scanner.nextInt()\n val c = scanner.nextInt()\n val d = scanner.nextInt()\n\n val p1 = points(a, c)\n val p2 = points(b, d)\n\n when {\n p1 == p2 -> output.write(\"Tie\\n\")\n p1 > p2 -> output.write(\"Misha\\n\")\n else -> output.write(\"Vasya\\n\")\n }\n\n output.flush()\n output.close()\n scanner.close()\n}\n\nfun points(p: Int, t: Int) = max(3*p/10f, p - (p/250f * t))", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "534d9336b501b2b9da42ef7b748484a4", "src_uid": "95b19d7569d6b70bd97d46a8541060d0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //var (x, y) = r.readLine()!!.split(\" \").map { it.toLong() }\n //val n = r.readLine()!!.toInt()\n val (a, b, c, d) = r.readLine()!!.split(\" \").map { it.toInt() }\n val alice = maxOf(3*a/10, a-a/250*c)\n val bob = maxOf(3*b/10, b-b/250*d)\n println(when{\n alice>bob -> \"Misha\"\n bob >alice -> \"Vasya\"\n else -> \"Tie\"\n })\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c006df9aa730764f112f3668a35e4171", "src_uid": "95b19d7569d6b70bd97d46a8541060d0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val n : Long\n var b : Long\n var h : Long\n var k : Long = 0\n val scan = Scanner(System.`in`)\n n = scan.nextLong()\n b = scan.nextLong()\n h = b\n while (b > 0){\n k++\n h -= k\n if (k == n) k = 0\n b-= k +1\n }\n println(h)\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "b0191ecc4baac7dde645ca84484435a5", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n\nfun main(args: Array) {\n var sc = Scanner(System.`in`)\n\n var n = sc.nextInt()\n var m = sc.nextInt()\n var i = 0\n while (m >= 0) {\n var index = (i % n) + 1\n if (m < index) break\n m -= index\n i++\n }\n print(m)\n \n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "4a0d4415b9149781a3bb9a6deccc4464", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val n = r.readLine()!!.toInt()\n var (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n var i = 0\n while (m > 0) {\n if (m >= (i + 1)) {\n m -= (i + 1)\n if (m==0) println(0)\n i = (i + 1) % n\n } else{\n println(m)\n m -= m\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "198bf074223ec7b438b62643378bea2d", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun main() {\n\n val sc = Scanner(System.`in`)\n val x : Int = sc.nextInt()\n val t : Int = sc.nextInt()\n val a : Int = sc.nextInt()\n val b : Int = sc.nextInt()\n val da : Int = sc.nextInt()\n val db : Int = sc.nextInt()\n\n for (i in 0 until t) {\n for (j in 0 until t) {\n if ((a - i * da) + (b - j * db) == x || a - i * da == x || b - j * db == x || x == 0) {\n print(\"YES\")\n return\n }\n }\n }\n\n print(\"NO\")\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "96b48be666a4c169bb813c4c8975b45d", "src_uid": "f98168cdd72369303b82b5a7ac45c3af", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun main() {\n\n val sc = Scanner(System.`in`)\n val x : Int = sc.nextInt()\n val t : Int = sc.nextInt()\n var a = sc.nextInt()\n var b = sc.nextInt()\n val da : Int = sc.nextInt()\n val db : Int = sc.nextInt()\n\n for (i in 0 until t) {\n for (j in 0 until t) {\n if ((a - i * da) + (b - j * db) == x || a - i * da == x || b - j * db == x || x == 0) {\n print(\"YES\")\n return\n }\n }\n }\n\n print(\"NO\")\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "6f0902d4473bb23206393676579d733d", "src_uid": "f98168cdd72369303b82b5a7ac45c3af", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun main() {\n\n val sc = Scanner(System.`in`)\n val x : Int = sc.nextInt()\n val t : Int = sc.nextInt()\n val a : Int = sc.nextInt()\n val b : Int = sc.nextInt()\n val da : Int = sc.nextInt()\n val db : Int = sc.nextInt()\n\n for (i : Int in 0 until t) {\n for (j : Int in 0 until t) {\n if ((a - i * da) + (b - j * db) == x || a - i * da == x || b - j * db == x || x == 0) {\n print(\"YES\")\n return\n }\n }\n }\n\n print(\"NO\")\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "12d9f0c9ee8e9544432271befaa68a23", "src_uid": "f98168cdd72369303b82b5a7ac45c3af", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9c8f4dbe5a1f1f9a80cb5b162f5cbab8", "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "677f342eb2611b1421077ce15e045b89", "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val n = r.readLine()!!.toInt()\n val (n, k) = r.readLine()!!.split(\" \").map { it.toInt() }\n val v = r.readLine()!!.split(\" \").map { it.toInt() }\n var have = 0\n var total = 0\n var ans = -1\n for (i in 0..n-1){\n total += v[i]\n have += minOf(total, 8).also { total -= minOf(total, 8) }\n if (have>=k){\n ans = i+1\n break\n }\n }\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "0feba5c2c39b6f6f1770f291021a1b51", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n println(countDays())\n}\n\nfun countDays(): Int {\n val (days, sweets) = readLine()!!.split(' ').map(String::toInt)\n val sweetsOnDayX = readLine()!!.split(' ').map(String::toInt)\n var aryaSweets = 0\n var branSweets = 0\n for (i in 0 until days) {\n aryaSweets += sweetsOnDayX[i]\n if (aryaSweets >= 8) {\n branSweets += 8\n aryaSweets -= 8\n } else {\n branSweets += aryaSweets\n aryaSweets = 0\n }\n if (branSweets >= sweets) return i + 1\n }\n return -1\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d40ab6fe3d56ab2fa64c07e80d649a10", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n\n var (n, k) = readLine()!!.split(' ').map { it.toInt() }\n var list = readLine()!!.split(' ').map { it.toInt() }\n\n var sum = 0\n var count = 0\n for (i in 0..list.size - 1) {\n sum += list[i]\n if (sum >= 8) {\n count += 8\n sum -= 8\n } else {\n count += sum\n sum = 0\n }\n if (count >= k) {\n println(i + 1)\n return\n }\n\n }\n println(-1)\n return\n\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "0e64594dc02206649cb6bd679e6ee878", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (_, k) = readInts()\n val arr = readInts()\n var sum = 0\n var extras = 0\n for ((pos, a) in arr.withIndex()) {\n val candies = extras + a\n sum += min(candies, 8)\n extras = max(0, candies - 8)\n if (sum >= k) return print(pos + 1)\n }\n print(-1)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "78811b37fa053e99675816cd72c4491b", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n\n val n = readInt()\n val daysOffFullWeeks = 2 * (n / 7)\n print(\"${daysOffFullWeeks + if (n % 7 == 6) 1 else 0} ${daysOffFullWeeks + min(2, (n % 7))}\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms", "brute force"], "code_uid": "9680a1cf20e91d40c55612453de4b691", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package codeforces.com.tasks.task670A\n\nfun main() {\n val days = readLine()!!.toInt()\n val weeks = days / 7\n var minDaysOff = weeks * 2\n var maxDaysOff = weeks * 2\n\n when(days % 7) {\n 0 -> { }\n 1 -> maxDaysOff += 1\n 6 -> { maxDaysOff += 2; minDaysOff += 1 }\n else -> maxDaysOff += 2\n }\n println(\"$minDaysOff $maxDaysOff\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms", "brute force"], "code_uid": "59a9c12e504a28212899b33aff438b89", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val n = r.readLine()!!.split(\" \").map { it.toInt() }\n val n = r.readLine()!!.toInt()\n val min = n/7*2 + if (n%7==6) 1 else 0\n val max = n/7*2+ minOf(2, n%7)\n println(\"$min $max\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms", "brute force"], "code_uid": "e6f0afcfc14afba0a6dcced9948ddc79", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var n = readLine()!!.toInt()\n var ans = 0\n var max = 0\n var min = 0\n if (n >= 7) {\n ans = n / 7\n var rem = n % 7\n if (rem >= 2) {\n max += ans*2 + 2\n } else if (rem == 1) {\n max += ans*2 + 1\n } else {\n max += ans*2\n }\n\n if (rem <= 5) {\n min += ans*2\n } else if (rem == 6) {\n min += ans*2 + 1\n }\n }else{\n if (n>=2){\n max = 2\n }else if (n==1){\n max = 1\n }\n if (n==6){\n min = 1\n }else{\n min = 0\n }\n }\n\n println(\"$min $max\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms", "brute force"], "code_uid": "392c6d2ca91c0d6413a251e36f69eab8", "src_uid": "8152daefb04dfa3e1a53f0a501544c35", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport java.text.SimpleDateFormat\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val a = sc.nextLine()\n val b = sc.nextLine()\n val c = SimpleDateFormat(\"HH:mm\")\n val d1 = c.parse(a)\n val d2 = c.parse(b)\n var e = d1.time - d2.time\n if (e < 0)\n e += 24 * 60 * 60 * 1000\n val h = e/(60 * 60 * 1000)\n val m = (e%(60 * 60 * 1000))/(60 * 1000)\n when {\n h<10&&m<10 -> println(\"0$h:0$m\")\n h>=10&&m<10 -> println(\"$h:0$m\")\n h<10&&m>=10 -> println(\"0$h:$m\")\n else -> println(\"$h:$m\")\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "1200cc8a284f1c7a24943b2bd79646e7", "src_uid": "595c4a628c261104c8eedad767e85775", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (hourWokeUp, minutesWokeUp) = readLine()!!.split(\":\").map(String::toInt)\n val wokeUp = 60 * hourWokeUp + minutesWokeUp\n val (hourSleep, minutesSleep) = readLine()!!.split(\":\").map(String::toInt)\n val sleep = 60 * hourSleep + minutesSleep\n val sol = (wokeUp + 24 * 60 - sleep) % (24 * 60)\n print(\"${String.format(\"%02d\", sol / 60)}:${String.format(\"%02d\", sol % 60)}\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "cb351b55697e7c87c31aea9a930cdc40", "src_uid": "595c4a628c261104c8eedad767e85775", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["geometry", "implementation"], "code_uid": "686def2f4019f64a31d4ba52061b4abf", "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 (h1, h2) = readInts()\n val (a, b) = readInts()\n\n // get to 10 pm\n var x = h1\n x += 8 * a\n if (x >= h2) {\n println(0)\n return\n }\n if (a <= b) {\n println(-1)\n return\n }\n\n var ans = 0\n while (x < h2) {\n x += 12 * (a - b)\n ans += 1\n }\n\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "4846a3624d4e832856b331dc52857922", "src_uid": "2c39638f07c3d789ba4c323a205487d7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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, x, y) = r.readLine()!!.split(\" \").map { it.toInt() }\n val n1 = r.readLine()!!.toLong()\n val n2 = r.readLine()!!.toLong()\n val n3 = n1 + n2\n val n4 = n1.toString().split(\"\").filter { it.isNotEmpty() }.filter { it != \"0\" }.joinToString(\"\").toLong()\n val n5 = n2.toString().split(\"\").filter { it.isNotEmpty() }.filter { it != \"0\" }.joinToString(\"\").toLong()\n val n6 = n3.toString().split(\"\").filter { it.isNotEmpty() }.filter { it != \"0\" }.joinToString(\"\").toLong()\n println(if (n4+n5==n6) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "198148670fafebfff25b2e44036be7d9", "src_uid": "ac6971f4feea0662d82da8e0862031ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main (args:Array){\n var num1 = readLine()!!.toInt()\n var num2 = readLine()!!.toInt()\n\n var result = num1 + num2\n\n var num_1 = \"\"\n var num_2 = \"\"\n var result_ = \"\"\n\n var resultTemp = \"\"\n\n var temp = num1\n while(temp > 0) {\n var i = temp % 10\n temp /= 10\n if (i == 0)\n continue\n num_1 = i.toString() + num_1\n }\n\n temp = num2\n while(temp > 0) {\n var i = temp % 10\n temp /= 10\n if (i == 0)\n continue\n num_2 = i.toString() + num_2\n }\n\n temp = result\n while(temp > 0) {\n var i = temp % 10\n temp /= 10\n if (i == 0)\n continue\n result_ = i.toString() + result_\n }\n \n for(i in result.toString()){\n if(i == '0'){\n continue\n }\n resultTemp += i\n }\n if (num_1.toInt() + num_2.toInt() == result_.toInt() && resultTemp == result_)\n print(\"YES\")\n else\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "31974022eda3f796411a6072ff46c022", "src_uid": "ac6971f4feea0662d82da8e0862031ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args : Array) {\n\n val d1 = readLine()!!\n val d2 = readLine()!!\n var list1: MutableList = mutableListOf()\n var list1n: MutableList = mutableListOf()\n var list2: MutableList = mutableListOf()\n var list2n: MutableList = mutableListOf()\n var list3: MutableList = mutableListOf()\n var list3n: MutableList = mutableListOf()\n\n for (char in d1) { list1.add(char) }\n for (char in d2) { list2.add(char) }\n var t = d1.toInt()+d2.toInt()\n for (char in t.toString()) { list3.add(char) }\n\n for(i in 0..list1.size-1){\n if(list1[i]!='0'){ list1n.add(list1[i]) }\n }\n\n for(k in 0..list2.size-1){\n if(list2[k]!='0'){ list2n.add(list2[k]) }\n }\n for(j in 0..list3.size-1){\n if(list3[j]!='0'){ list3n.add(list3[j]) }\n }\n\n var a1 = 1\n var s1 = 0\n for(i in list1n.size-1 downTo 0){\n s1 = s1+list1n[i].toString().toInt()*a1\n a1 = a1 * 10\n }\n var a2 = 1\n var s2 = 0\n for(i in list2n.size-1 downTo 0){\n s2 = s2+list2n[i].toString().toInt()*a2\n a2 = a2 * 10\n }\n var a3 = 1\n var s3 = 0\n for(i in list3n.size-1 downTo 0){\n s3 = s3+list3n[i].toString().toInt()*a3\n a3 = a3 * 10\n }\n\n if(s1+s2==s3){ println(\"YES\") }\n else { println(\"NO\") }\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a92442ef94c1f23d3dfa0353ef5b7f21", "src_uid": "ac6971f4feea0662d82da8e0862031ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nprivate val scan = Scanner(System.`in`)\n\nfun main(args: Array) {\n val m = scan.next().sort()\n val n = scan.next()\n val ni = n.toLong()\n\n if (n.length > m.length) {\n println(m.toList().sortedDescending().joinToString(\"\"))\n return\n }\n\n var ans = m.toList()\n for (i in 0 until m.length) {\n for (j in i + 1 until m.length) {\n val temp = ans.toMutableList()\n Collections.swap(temp, i, j)\n// println(\"temp=$temp\")\n val xList = temp.subList(0, i + 1) + temp.subList(i + 1, temp.size).sorted()\n// println(\"xList=$xList\")\n val x = xList.joinToString(\"\").toLong()\n if (x <= ni) {\n ans = xList\n }\n }\n }\n\n println(ans.joinToString(\"\"))\n}\n\nfun String.sort() =\n toList().sorted().joinToString(\"\")\n", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "b78a921f46d63f25f0ca203967dd184f", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\ndata class ArrayViewer(val pos: Int, val array: IntArray) {\n\n fun empty() = pos >= array.size\n fun head() = array[pos]\n fun tail() = ArrayViewer(pos + 1, array)\n\n}\n\nfun IntArray.viewer() = ArrayViewer(0, this)\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n\n val a = nextLine()!!.map { it.toInt() - '0'.toInt() }.toIntArray()\n val b = nextLine()!!.map { it.toInt() - '0'.toInt() }.toIntArray()\n\n val counts = countDigits(a)\n\n if (a.size < b.size) {\n print(maxPossible(counts).fold(\"\") { str, digit ->\n str + digit.toString() })\n return\n } else {\n print(makeLess(counts, b.viewer())!!.fold(\"\") {\n str, digit ->\n str + digit.toString() })\n }\n\n}\n\nfun makeLess(counter: IntArray, value: ArrayViewer): List? {\n if (value.empty()) {\n return List(0){0}\n }\n\n val digit = value.head()\n val rest = value.tail()\n\n if (counter[digit] != 0) {\n var counterWithout = counter\n counterWithout[digit] -= 1\n\n val other = makeLess(counterWithout, rest)\n if (other != null) {\n return List(1){digit} + other\n }\n\n counterWithout[digit] += 1\n }\n\n for (nextDigit in (digit - 1) downTo 0) {\n if (counter[nextDigit] != 0) {\n var counterWithout = counter\n counterWithout[nextDigit] -= 1\n\n val other = maxPossible(counterWithout)\n return List(1){nextDigit} + other\n }\n }\n\n return null\n\n}\n\nfun maxPossible(counter: IntArray): List {\n var c = List(0) {0}\n\n for (digit in 9 downTo 0) {\n for (i in 1..counter[digit]) {\n c += digit\n }\n }\n\n return c\n}\n\nfun countDigits(array: IntArray): IntArray {\n var counter = IntArray(10){0}\n\n for (digit in array) {\n counter[digit] += 1\n }\n\n return counter\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "f0c21e95e058b27cdf0e94a9515a07a5", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nclass C {\n fun solve(input : InputStream, output : OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n val first = reader.next()\n val second = reader.next()\n\n writer.println(solve(first, second))\n\n writer.close()\n }\n\n fun solve(first : String, second : String) : String {\n val digits = Array(10, {_ -> 0})\n for (char in first) {\n digits[char - '0']++\n }\n return trySolve(digits, second, second.length - first.length, first.length == second.length)!!\n }\n\n fun trySolve(digits : Array, number : String, pos : Int, eq : Boolean) : String? {\n if (pos == number.length) {\n return \"\"\n }\n\n if (!eq) {\n for (x in (0..9).reversed()) {\n if (digits[x] > 0) {\n digits[x]--\n val result = trySolve(digits, number, pos + 1, eq)\n digits[x]++\n if (result == null) {\n return result\n }\n return x.toString() + result\n }\n }\n }\n\n // try with the same number\n val current = number[pos] - '0'\n if (digits[current] > 0) {\n digits[current]--\n val result = trySolve(digits, number, pos + 1, eq)\n digits[current]++\n if (result != null) {\n return current.toString() + result\n }\n }\n\n // or try with lower\n for(x in (0 until current).reversed()) {\n if (digits[x] > 0) {\n digits[x]--\n val result = trySolve(digits, number, pos + 1, false)\n digits[x]++\n if (result == null) {\n return result\n }\n return x.toString() + result\n }\n }\n\n return null\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 C().solve(System.`in`, System.out)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "352eab26400f5f68640714b1e6e97b59", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.sqrt\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 (a, b, c) = r.readLine()!!.split(\" \").map { it.toDouble() }\n val x = sqrt(a*b/c).toInt()\n val y = sqrt(a*c/b).toInt()\n val z = sqrt(b*c/a).toInt()\n println(4*(x+y+z))\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "geometry"], "code_uid": "1d4d85c0165e8905fdb943042c2fa11d", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (ab, bc, ac) = readLine()!!.split(\" \").map{ it.toInt() }\n var a: Int\n var b: Int\n var c: Int\n for(i in 1..10000) {\n if(ab % i == 0 && ac % i == 0 && (ab / i) * (ac / i) == bc) {\n a = i\n b = ab / a\n c = ac / a\n println(4 * (a + b + c))\n break\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "geometry"], "code_uid": "bd58264871cd75f48176f929572bab01", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 ab = scanner.nextLong()\n val bc = scanner.nextLong()\n val ac = scanner.nextLong()\n val abc = sqrt((ab * bc * ac).toDouble()).toDouble()\n println(4 * ((abc / ab) + (abc / ac) + (abc / bc)).toLong())\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//}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "geometry"], "code_uid": "e259fc8ed78b1ec997c9421d4bf4ea30", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "d834f3534515aef39c7c53f33fa60924", "src_uid": "ff6b3fd358c758324c19a26283ab96a4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "b07e9fe6a4431346f0f5080798dc98f4", "src_uid": "ff6b3fd358c758324c19a26283ab96a4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "c7372b45cfb936f882dddf3436f3f990", "src_uid": "ff6b3fd358c758324c19a26283ab96a4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 getVal(num: Long, rows: Long, cols: Long): Long {\n var res: Long = 0\n for (i in 1..min(num, rows)) {\n res += min(cols, num / i)\n }\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 val st = StringTokenizer(br.readLine())\n val on = st.nextToken().toLong()\n val om = st.nextToken().toLong()\n val k = st.nextToken().toLong()\n val n = min(on, om); val m = max(on, om)\n var lo = 1L; var hi: Long = n * m\n while (lo < hi) {\n val mid = (lo + hi) ushr 1\n if (k <= getVal(mid, n, m)) hi = mid\n else lo = mid + 1\n }\n\n outer@ while (true) {\n var i = 1L\n while (i * i <= lo) {\n if (lo % i == 0L && i <= n && lo / i <= m) break@outer\n ++i\n }\n ++lo\n }\n\n bw.write(\"$lo\\n\")\n bw.close()\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "binary search"], "code_uid": "cf92800bc1bce43768639e844d130fea", "src_uid": "13a918eca30799b240ceb9de47507a26", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nclass Solution : Runnable {\n override fun run() {\n solve()\n }\n\n fun start() {\n Thread(null, Solution(), \"whatever\", (1 shl 27).toLong()).start()\n }\n}\n\nfun main(args: Array) {\n Solution().start()\n}\n\n\nclass IO {\n companion object {\n\n private val reader: InputReader\n private val writer: OutputWriter\n\n init {\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n reader = InputReader(FileInputStream(\"/Users/300041735/competitiveProgramming/src/codeforces/in.txt\"))\n writer = OutputWriter(FileOutputStream(\"/Users/300041735/competitiveProgramming/src/codeforces/out.txt\"))\n } else {\n reader = InputReader(System.`in`)\n writer = OutputWriter(System.`out`)\n }\n }\n\n private fun readMultipleInts(count: Int): List {\n val map = mutableListOf()\n repeat(count) {\n map.add(reader.readInt())\n }\n return map\n }\n\n fun readInt() = reader.readInt()\n fun readLong() = reader.readLong()\n fun readTwoInts() = readMultipleInts(2)\n fun readThreeInts() = readMultipleInts(3)\n fun readFourInts() = readMultipleInts(4)\n fun readFiveInts() = readMultipleInts(5)\n fun readSixInts() = readMultipleInts(6)\n fun readString() = reader.readString()\n fun readTree(n: Int): MutableMap> {\n val graph = mutableMapOf>()\n repeat(n - 1) {\n val u = reader.readInt()\n val v = reader.readInt()\n if (!graph.containsKey(u)) graph[u] = mutableListOf()\n if (!graph.containsKey(v)) graph[v] = mutableListOf()\n graph[u]!!.add(v)\n graph[v]!!.add(u)\n }\n return graph\n }\n\n fun readIntArray(n: Int): IntArray {\n return IntArray(n) { readInt() }\n }\n\n fun readLongArray(n: Int): Array {\n return Array(n) { readLong() }\n }\n\n fun write(obj: Any) {\n writer.printLine(obj)\n }\n\n fun flushOutput() {\n writer.flush()\n }\n\n fun closeOutput() {\n writer.close()\n }\n }\n}\n\n\nclass MATH {\n companion object {\n\n val mod = 1000000007\n var ispre = false\n\n val factMod = Array(300002) { 1 }\n\n fun pre() {\n for (i in 2 until 300001) {\n factMod[i] = ((factMod[i - 1] * i.toLong()) % MATH.mod).toInt()\n }\n }\n\n fun gcd(a: Int, b: Int): Int {\n if (b == 0)\n return a\n return gcd(b, a % b)\n }\n\n fun gcd(a: Long, b: Long): Long {\n if (b == 0L)\n return a\n return gcd(b, a % b)\n }\n\n fun inverseMod(a: Int): Int {\n return powMod(a, mod - 2)\n }\n\n fun powMod(a: Int, b: Int): Int {\n //calculate a to the power b mod m\n if (b == 0) return 1\n return if (b % 2 == 1) {\n prodMod(a, powMod(a, b - 1))\n } else {\n val p = powMod(a, b / 2)\n prodMod(p, p)\n }\n }\n\n fun ncr(n: Int, r: Int): Int {\n if (!ispre) pre(); ispre = true\n return ((factMod[n].toLong() * inverseMod(((factMod[r].toLong() * factMod[n - r]) % mod).toInt())) % mod).toInt()\n }\n\n fun prodMod(val1: Int, val2: Int): Int {\n return ((val1.toLong() * val2) % mod).toInt()\n }\n\n }\n}\n\nfun solve() {\n\n\n val n = IO.readInt()\n val m = IO.readInt()\n var k = IO.readLong()\n\n k = n*m.toLong() - k + 1\n\n //loop over the ans\n var ansL = 0L\n var ansH = n*m.toLong()\n while (ansH - ansL > 1){\n //find the largest ans such that numbers greater than it are >= k\n val mid = (ansL + ansH)/2\n val count = getCount(n, m , mid) //how many numbers are strictly greater than this number\n if (count >= k){\n //we can still go higher\n ansL = mid\n }else{\n ansH = mid - 1\n }\n }\n\n val count = getCount(n, m , ansH)\n if (count >= k){\n IO.write(ansH + 1)\n }else{\n IO.write(ansL + 1)\n }\n\n IO.flushOutput()\n IO.closeOutput()\n}\n\nfun getCount(n : Int, m : Int, search : Long) : Long{\n var count = 0L\n for(i in 1 until n + 1){\n //over each of the row\n //i*j find the smallest j such that i*j > search -> ceil(search/i)\n val ans = (search + i )/i\n if (ans <= m) {\n count += m - ans + 1\n }\n }\n return count\n}\n\n\n\nfun isBitSet(num : Long, i : Int) : Boolean{\n return (num.and(1L.shl(i)) > 0)\n}\n\ndata class Graph(val edges: MutableMap>)\n\n\nclass MinSegmentTree(\n input: Array\n) {\n private val tree: Array\n private val lazy: Array\n\n constructor(size: Int) : this(Array(size) { Int.MAX_VALUE })\n\n init {\n val size = nextPowerOfTwo(input.size)\n tree = Array(2 * size) { Int.MAX_VALUE }\n lazy = Array(2 * size) { Int.MAX_VALUE }\n for (i in 0 until input.size) {\n tree[i + size] = input[i]\n }\n for (i in (size - 1) downTo 1) {\n tree[i] = Math.min(tree[leftChild(i)], tree[rightChild(i)])\n }\n }\n\n private fun updateTree(lowerRange: Int, upperRange: Int, lowerBound: Int, upperBound: Int, index: Int, value: Int) {\n updateLazyNode(index, lowerBound, upperBound, lazy[index])\n if (noOverlap(lowerRange, upperRange, lowerBound, upperBound)) return\n else if (completeOverlap(lowerRange, upperRange, lowerBound, upperBound)) updateLazyNode(index, lowerBound, upperBound, value)\n else {\n updateTree(lowerRange, upperRange, lowerBound, midIndex(lowerBound, upperBound), leftChild(index), value)\n updateTree(lowerRange, upperRange, midIndex(lowerBound, upperBound) + 1, upperBound, rightChild(index), value)\n tree[index] = Math.min(tree[leftChild(index)], tree[rightChild(index)])\n }\n }\n\n private fun queryTree(lowerRange: Int, upperRange: Int, lowerBound: Int, upperBound: Int, index: Int): Int {\n updateLazyNode(index, lowerBound, upperBound, lazy[index])\n if (noOverlap(lowerRange, upperRange, lowerBound, upperBound)) return Int.MAX_VALUE\n else if (completeOverlap(lowerRange, upperRange, lowerBound, upperBound)) return tree[index]\n else {\n return Math.min(queryTree(lowerRange, upperRange, lowerBound, midIndex(lowerBound, upperBound), leftChild(index)),\n queryTree(lowerRange, upperRange, midIndex(lowerBound, upperBound) + 1, upperBound, rightChild(index)))\n }\n }\n\n private fun updateLazyNode(index: Int, lowerBound: Int, upperBound: Int, delta: Int) {\n tree[index] += delta\n if (lowerBound != upperBound) {\n lazy[leftChild(index)] += delta\n lazy[rightChild(index)] += delta\n }\n lazy[index] = 0\n }\n\n fun getElements(N: Int): List {\n return tree.copyOfRange(tree.size / 2, tree.size / 2 + N).asList()\n }\n\n fun update(lowerRange: Int, upperRange: Int, value: Int) {\n updateTree(lowerRange, upperRange, 1, lazy.size / 2, 1, value)\n }\n\n fun query(lowerRange: Int, upperRange: Int): Int {\n return queryTree(lowerRange, upperRange, 1, lazy.size / 2, 1)\n }\n\n private fun noOverlap(l: Int, u: Int, lb: Int, ub: Int): Boolean = (lb > u || ub < l)\n\n private fun completeOverlap(l: Int, u: Int, lb: Int, ub: Int): Boolean = (lb >= l && ub <= u)\n\n\n private fun nextPowerOfTwo(num: Int): Int {\n var exponent = 2\n while (true) {\n if (exponent >= num) {\n return exponent\n }\n exponent *= 2\n }\n }\n\n private fun midIndex(l: Int, r: Int) = (l + r) / 2\n private fun parent(i: Int) = i / 2\n private fun leftChild(i: Int) = 2 * i\n private fun rightChild(i: Int) = 2 * i + 1\n\n}\n\nclass 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 }\n var sgn: Long = 1\n if (c == '-'.toInt()) {\n sgn = -1\n c = read()\n }\n var number: Long = 0\n do {\n number *= 10L\n number += (c - '0'.toInt()).toLong()\n c = read()\n } while (!isSpaceChar(c))\n return number * 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\nclass 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 fun flush() {\n writer.flush()\n }\n\n}\n\nclass DinitzMaxFlowSolver(val n: Int, val s: Int, val t: Int, val graph: MutableMap>, val edgeMap: MutableMap, Edge>) {\n\n private val level = IntArray(n + 1) { -1 } //storing levels of each vertex in level graph\n var maxFlow = 0L\n\n init {\n solve()\n }\n\n fun solve() {\n val next = IntArray(n + 1) { 0 }\n while (bfs()) {\n Arrays.fill(next, 0)\n var flow = 0L\n do {\n maxFlow += flow\n flow = dfs(s, next, Long.MAX_VALUE)\n } while (flow != 0L)\n }\n }\n\n private fun dfs(at: Int, next: IntArray, flow: Long): Long {\n if (at == t) return flow\n var size = 0\n if (graph.containsKey(at)) size = graph[at]!!.size\n while (next[at] < size) {\n val edge = graph[at]!!.get(next[at])\n if (edge.remainingCapacity() > 0 && level[edge.to] == level[at] + 1) {\n val bottleNeck = dfs(edge.to, next, Math.min(flow, edge.remainingCapacity()))\n if (bottleNeck > 0) {\n edgeMap[Pair(edge.from, edge.to)]!!.flow += bottleNeck\n edgeMap[Pair(edge.to, edge.from)]!!.flow -= bottleNeck\n return bottleNeck\n }\n }\n next[at]++\n }\n return 0\n }\n\n private fun bfs(): Boolean {\n Arrays.fill(level, -1)\n val curLevel = ArrayDeque()\n curLevel.add(s)\n level[s] = 0\n\n while (curLevel.isNotEmpty()) {\n val top = curLevel.poll()\n if (graph.containsKey(top)) {\n graph[top]!!.forEach {\n if (it.remainingCapacity() > 0 && level[it.to] == -1) {\n level[it.to] = level[top] + 1\n curLevel.offer(it.to)\n }\n }\n }\n }\n return level[t] != -1\n }\n\n\n}\n\nclass Edge(val from: Int, val to: Int, val capacity: Long) {\n var flow = 0L\n fun remainingCapacity(): Long {\n return capacity - flow\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "binary search"], "code_uid": "9c4a8cb9d447d81b66b7d995df3d4265", "src_uid": "13a918eca30799b240ceb9de47507a26", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\ninline fun getVal(num: Long, rows: Long, cols: Long): Long {\n var res: Long = 0\n for (i in 1..min(num, rows)) {\n res += min(cols, num / i)\n }\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 val st = StringTokenizer(br.readLine())\n val on = st.nextToken().toLong()\n val om = st.nextToken().toLong()\n val k = st.nextToken().toLong()\n val n = min(on, om); val m = max(on, om)\n var lo = 1L; var hi: Long = n * m\n while (lo <= hi) {\n val mid = (lo + hi) ushr 1\n if (k <= getVal(mid, n, m)) hi = mid - 1\n else lo = mid + 1\n }\n/*\n outer@ while (true) {\n var i = 1L\n while (i * i <= lo) {\n if (lo % i == 0L && i <= n && lo / i <= m) break@outer\n ++i\n }\n ++lo\n }\n*/\n bw.write(\"$lo\\n\")\n bw.close()\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "binary search"], "code_uid": "7f9e0fd65f3bc8a6ee3ecb55453bc5d4", "src_uid": "13a918eca30799b240ceb9de47507a26", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\ninline fun findMin(mn: Long, mx: Long, f: (Long) -> Boolean): Long {\n var low = mn - 1\n var high = mx\n while(high - low > 1) {\n val m = (low + high) / 2\n if (f(m)) high = m\n else low = m\n }\n return high\n}\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val N = nl()\n val M = nl()\n val K = nl()\n\n fun test(x: Long): Boolean {\n var sum = 0L\n for (i in 1 .. N) {\n sum += min(M,x / i)\n }\n\n return sum >= K\n }\n\n val ans = findMin(0, N * M, ::test)\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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "binary search"], "code_uid": "6308afb0bc3d7223624c581fb91418d3", "src_uid": "13a918eca30799b240ceb9de47507a26", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "eed514f9cc8271461edb37a5670102f2", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "0fbbb311966495313325e91f76135415", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "ced217a8aeb2ff44efeb607bb1acc74b", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "b3aa04fca141a6f03b463ed20f6352be", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val m = Array(3) { IntArray(3) }\n for (row in 0 until 3) m[row] = readInts().toIntArray()\n var x = 0 // sum of rows, columns and diagonals\n for (row in 0 until 3) x = max(x, m[row].sum() + 1)\n for (column in 0 until 3) x = max(x, m.fold(0) { acc, arr -> acc + arr[1] } + 1)\n for (row in 0 until 3) m[row][row] = x - m[row].sum()\n \n // while (m[0][0] + m[1][1] + m[2][2] != x) {\n // x++\n // m[0][0]++\n // m[1][1]++\n // m[2][2]++\n // }\n/*\nThe sum of the diagonal can not sum x yet, but now the relationship is established and the three cells should\nbe increased by the same value. Which value? Every time we increase them by one x is increased by three, so the\ndiagonal is two units closer to x (3 - 1). It's possible then to calculate how many times it's necessary to\nincrement the cells\n*/\n val remaining = (x - m[0][0] - m[1][1] - m[2][2]) / 2\n for (row in 0 until 3) m[row][row] += remaining\n print(m.joinToString(System.lineSeparator()) { row -> row.joinToString(\" \") })\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "7c6ba2c0df71feaf7babddb0fe2418ff", "src_uid": "0c42eafb73d1e30f168958a06a0f9bca", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main() {\n val line = readLine()!!.split(\" \")\n val n = line[0].toInt()\n val mod = line[1].toLong()\n val limit = (n * (n - 1)) / 2\n val dp = Array(n + 1) { LongArray(limit + 1) }\n dp[0][0] = 1L\n var answer = 0L\n for (k in 1..n) {\n for (j in 0..limit) {\n if (j > 0) {\n dp[k][j] += dp[k][j - 1]\n }\n dp[k][j] += dp[k - 1][j]\n if (j >= k) {\n dp[k][j] -= dp[k - 1][j - k]\n }\n if (dp[k][j] >= mod) {\n dp[k][j] -= mod\n }\n if (dp[k][j] < 0L) {\n dp[k][j] += mod\n }\n }\n var here = 0L\n var curr = 0L\n var addend2 = 0L\n var addend1 = 0L\n for (j in 0..limit) {\n here += dp[k - 1][j] * curr\n here %= mod\n curr += addend2\n if (curr >= mod) {\n curr -= mod\n }\n if (j >= k) {\n addend1 -= dp[k - 1][j - k]\n }\n addend1 += dp[k - 1][j]\n if (addend1 >= mod) {\n addend1 -= mod\n }\n if (addend1 < 0L) {\n addend1 += mod\n }\n addend2 += k.toLong() * dp[k - 1][j]\n addend2 -= addend1\n addend2 += mod\n addend2 %= mod\n }\n for (k2 in k + 1..n) {\n here *= k2.toLong()\n here %= mod\n }\n answer += here\n answer %= mod\n }\n println(answer)\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "fft"], "code_uid": "eb035a45d62b8fc8d6bb91f75b960a98", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalUnsignedTypes::class, 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/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n// val startTime = System.nanoTime()\n\n val numCases = 1//readInt()\n\n case@ for(case in 1..numCases) {\n // print(\"Case #$case: \")\n\n val n = readInt()\n MOD = readInt()\n\n// val C = ModIntArray(n+1)\n// C[n]++\n// for(i in 1..n) {\n// for(j in n-i until n) C[j] += C[j+1]\n// }\n\n var ans = ModInt(0)\n val P = ModIntArray(n+1)\n P[0]++\n for(i in 0 until n) P[i+1] = P[i] * (n - i)\n\n var D = OffsetModIntArray(0, 0)\n D[0]++\n for(i in 1 until n) {\n for(j in 0 until D.arr.lastIndex) D.arr[j+1] += D.arr[j]\n var acc = ModInt(0)\n for(j in 1..i) acc += D.getPinned(-j-1) * (i - j + 1)\n\n ans += acc * P[n-i-1]\n\n acc = ModInt(0)\n val Di = OffsetModIntArray(D.firstIndex - i, D.lastIndex + i)\n for(j in Di.firstIndex .. Di.lastIndex) {\n acc += D.getPinned(j + i) - D.getPinned(j - 1)\n acc -= D.getPinned(j - 1) - D.getPinned(j - i - 2)\n Di[j] = acc\n }\n D = Di\n }\n\n println(ans.int)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nfun OffsetModIntArray.getPinned(i: Int) = if (i < firstIndex) ModInt(0) else get(min(i, lastIndex))\n\nclass OffsetModIntArray(val firstIndex: Int, val lastIndex: Int) {\n constructor(indices: IntRange): this(indices.first, indices.last)\n inline val indices get() = firstIndex .. lastIndex\n val arr = ModIntArray(lastIndex - firstIndex + 1)\n val size get() = arr.size\n\n operator fun get(i: Int) = arr[i - firstIndex]\n operator fun set(i: Int, v: ModInt) { arr[i - firstIndex] = v }\n fun last() = arr.last()\n}\n\nvar MOD = 998244353\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\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 = ModInt(int.powMod(exponent, MOD))\n\n fun pow(exponent: Long) = ModInt(int.powMod(exponent, MOD))\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\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\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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { 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 }", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "fft"], "code_uid": "a2d200395b2b27a9ca33d04ac609c07b", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalUnsignedTypes::class, 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/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n// val startTime = System.nanoTime()\n\n val numCases = 1//readInt()\n\n case@ for(case in 1..numCases) {\n // print(\"Case #$case: \")\n\n val n = readInt()\n MOD = readInt()\n\n// val C = ModIntArray(n+1)\n// C[n]++\n// for(i in 1..n) {\n// for(j in n-i until n) C[j] += C[j+1]\n// }\n\n var ans = ModInt(0)\n val P = ModIntArray(n+1)\n P[0]++\n for(i in 0 until n) P[i+1] = P[i] * (n - i)\n\n var D = OffsetModIntArray(0, 0)\n D[0]++\n for(i in 2..n) {\n for(j in 0 until D.arr.lastIndex) D.arr[j+1] += D.arr[j]\n var acc = ModInt(0)\n for(j in 1 until i) acc += D.getPinned(-j-1) * (i - j)\n\n ans += acc * P[n-i]\n\n acc = ModInt(0)\n val Di = OffsetModIntArray(D.firstIndex - i + 1, D.lastIndex + i - 1)\n for(j in Di.firstIndex .. Di.lastIndex) {\n acc += D.getPinned(j + i - 1) - D.getPinned(j - 1)\n acc -= D.getPinned(j - 1) - D.getPinned(j - i - 1)\n Di[j] = acc\n }\n D = Di\n }\n\n println(ans.int)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nfun OffsetModIntArray.getPinned(i: Int) = if (i < firstIndex) ModInt(0) else get(min(i, lastIndex))\n\nclass OffsetModIntArray(val firstIndex: Int, val lastIndex: Int) {\n constructor(indices: IntRange): this(indices.first, indices.last)\n inline val indices get() = firstIndex .. lastIndex\n val arr = ModIntArray(lastIndex - firstIndex + 1)\n val size get() = arr.size\n\n operator fun get(i: Int) = arr[i - firstIndex]\n operator fun set(i: Int, v: ModInt) { arr[i - firstIndex] = v }\n fun last() = arr.last()\n}\n\nvar MOD = 998244353\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\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 = ModInt(int.powMod(exponent, MOD))\n\n fun pow(exponent: Long) = ModInt(int.powMod(exponent, MOD))\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\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\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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { 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 }", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "fft"], "code_uid": "3dc4be4b2df3ef5651b47350f99640dd", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalUnsignedTypes::class, 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/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n// val startTime = System.nanoTime()\n\n val numCases = 1//readInt()\n\n case@ for(case in 1..numCases) {\n // print(\"Case #$case: \")\n\n val n = readInt()\n MOD = readInt()\n\n// val C = ModIntArray(n+1)\n// C[n]++\n// for(i in 1..n) {\n// for(j in n-i until n) C[j] += C[j+1]\n// }\n\n var ans = ModInt(0)\n val P = ModIntArray(n+1)\n P[0]++\n for(i in 0 until n) P[i+1] = P[i] * (n - i)\n\n var D = OffsetModIntArray(0, 0)\n D[0]++\n for(i in 2..n) {\n for(j in 0 until D.arr.lastIndex) D.arr[j+1] += D.arr[j]\n var acc = ModInt(0)\n for(j in 1 until i) acc += D.getPinned(-j-1) * (i - j)\n\n ans += acc * P[n-i]\n\n acc = ModInt(0)\n val Di = OffsetModIntArray(D.firstIndex - i, D.lastIndex + i)\n for(j in Di.firstIndex .. Di.lastIndex) {\n acc += D.getPinned(j + i - 1) - D.getPinned(j - 1)\n acc -= D.getPinned(j - 1) - D.getPinned(j - i - 1)\n Di[j] = acc\n }\n D = Di\n }\n\n println(ans.int)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nfun OffsetModIntArray.getPinned(i: Int) = if (i < firstIndex) ModInt(0) else get(min(i, lastIndex))\n\nclass OffsetModIntArray(val firstIndex: Int, val lastIndex: Int) {\n constructor(indices: IntRange): this(indices.first, indices.last)\n inline val indices get() = firstIndex .. lastIndex\n val arr = ModIntArray(lastIndex - firstIndex + 1)\n val size get() = arr.size\n\n operator fun get(i: Int) = arr[i - firstIndex]\n operator fun set(i: Int, v: ModInt) { arr[i - firstIndex] = v }\n fun last() = arr.last()\n}\n\nvar MOD = 998244353\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\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 = ModInt(int.powMod(exponent, MOD))\n\n fun pow(exponent: Long) = ModInt(int.powMod(exponent, MOD))\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\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\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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { 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 }", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "fft"], "code_uid": "1cb3f2f61fb32027c3c7fe0dc4dbf76f", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 cnt1 = nl()\n val cnt2 = nl()\n val X = nl()\n val Y = nl()\n\n val MAX = if (isDebug) 10 else Long.MAX_VALUE / 2 // 2e18\u3050\u3089\u3044\u3067ok\n val ans = findMin(1L, MAX) { a ->\n val x = a / X\n val y = a / Y\n val xy = a / (X * Y)\n val notX = a - x\n val notY = a - y\n val notXy = a - (x + y - xy)\n val need1 = max(0, cnt1 - notX + notXy)\n val need2 = max(0, cnt2 - notY + notXy)\n debug{\"$a $notX $notY $notXy $need1 $need2\"}\n notXy >= need1 + need2\n }\n out.print(ans)\n }\n\n /**\n * [l, r]\n */\n fun findMin(l: Long, r: Long, f: (Long) -> Boolean): Long {\n // (l, h]\n var low = l - 1\n var high = r\n while(high - low > 1) {\n val m = (low + high) / 2\n if (f(m)) high = m\n else low = m\n }\n return high\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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, offset) { ni() }\n }\n\n private inline fun map(n: Int, offset: Int = 0, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i + offset)\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun pair(a: A, b: B) = RPair(a, b)\ndata class RPair(val _1: A, val _2: B)\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}", "lang_cluster": "Kotlin", "tags": ["math", "binary search"], "code_uid": "fb48145df2cf419d67a4e8678249ac50", "src_uid": "ff3c39b759a049580a6e96c66c904fdc", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "\r\nfun main() {\r\n val (p1, t1) = readln().split(' ').let { (p, t) -> p.toInt() to t.toLong() }\r\n val (p2, t2) = readln().split(' ').let { (p, t) -> p.toInt() to t.toLong() }\r\n val (h, s) = readln().split(' ').let { (h, s) -> h.toInt() to s.toLong() }\r\n val minTime = LongArray(h + 1){Long.MAX_VALUE shr 1}.also { it[0] = 0L }\r\n for (c1 in 1 .. h) {\r\n val time = t1 * c1\r\n val c2 = time / t2\r\n val damage = p1 * c1 + p2 * c2 - s * if (c2 > 0) (c1 + c2 - 1) else (c1 + c2)\r\n for (i in minTime.indices) {\r\n val j = minOf(h.toLong(), i + damage).toInt()\r\n minTime[j] = minOf(minTime[j], minTime[i] + time)\r\n }\r\n }\r\n for (c2 in 1 .. h) {\r\n val time = t2 * c2\r\n val c1 = time / t1\r\n val damage = p1 * c1 + p2 * c2 - s * if (c1 > 0) (c1 + c2 - 1) else (c1 + c2)\r\n for (i in minTime.indices) {\r\n val j = minOf(h.toLong(), i + damage).toInt()\r\n minTime[j] = minOf(minTime[j], minTime[i] + time)\r\n }\r\n }\r\n val result = minTime[h]\r\n println(result)\r\n}", "lang_cluster": "Kotlin", "tags": ["dp", "binary search"], "code_uid": "631ea9a9c5277c668d208b21f0307fa2", "src_uid": "ca9d48e48e69b931236907a9ac262433", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val numToNumSegments = intArrayOf(6, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n val (a, b) = readInts()\n var sol = 0L\n for (num in a..b) {\n var n = num\n while (n != 0) {\n sol += numToNumSegments[n % 10]\n n /=10\n }\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "e873117703e2be7f8cb65e83005d6f79", "src_uid": "1193de6f80a9feee8522a404d16425b9", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (a, b) = readLine()!!.split(' ').map { it.toInt() }\n var count = 0L\n for (i in a..b){\n var digit = i.toString()\n for (i in digit){\n when(i){\n '0'->count+=6\n '1'->count+=2\n '2'->count+=5\n '3'->count+=5\n '4'->count+=4\n '5'->count+=5\n '6'->count+=6\n '7'->count+=3\n '8'->count+=7\n '9'->count+=6\n }\n }\n }\n println(count)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "17a6b4da52f354b40bcf564645bdac01", "src_uid": "1193de6f80a9feee8522a404d16425b9", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "8f43cffb32da2bd586f430294ddbe2e5", "src_uid": "42454dcf7d073bf12030367eb094eb8c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextLine()\n println(\"25\")\n}\n", "lang_cluster": "Kotlin", "tags": ["number theory"], "code_uid": "0f671f7ed0eb6a5479729fc59dc37015", "src_uid": "dcaff75492eafaf61d598779d6202c9d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n var n = r.readLine()!!.toLong()\n var base = 5\n var ans = 1\n //val l = r.readLine()!!.split(\" \").map { it.toInt() }\n while (n > 0) {\n if (n%2 == 1L){\n ans = ans * base %100\n }\n base = base * base % 100\n n /= 2\n }\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["number theory"], "code_uid": "cec4f715f817b3e748d8793ebbbddd37", "src_uid": "dcaff75492eafaf61d598779d6202c9d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.long()\n println(\"25\")\n}\n\n ", "lang_cluster": "Kotlin", "tags": ["number theory"], "code_uid": "e1767d104df3aef9afa923ad77ed342d", "src_uid": "dcaff75492eafaf61d598779d6202c9d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport kotlin.math.abs\nimport kotlin.math.min\n\nfun main(args: Array) {\n readLine()\n println(\"25\")\n}", "lang_cluster": "Kotlin", "tags": ["number theory"], "code_uid": "667644e74c21ed64058c6eae9a85c500", "src_uid": "dcaff75492eafaf61d598779d6202c9d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val n = readInt()\n if (n and 1 == 0) return print(\"No\")\n val arr = readInts()\n print(if (arr.first() and 1 == 1 && arr.last() and 1 == 1) \"Yes\" else \"No\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7ba12a7ed035e8a83c1073766db99460", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var n = readLine()!!.toInt()\n var list = readLine()!!.split(' ').map { it.toInt() }\n if (list.size % 2 == 1 && list[0] % 2 == 1 && list[n - 1] % 2 == 1) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "49e8d31895917c7c788176b76b880025", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.FileReader\nimport java.io.InputStreamReader\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\nfun main(args: Array) {\n val n=readInt()\n val a=readInts().toIntArray()\n if((a[0]%2==1)&&(a[n-1]%2==1)&&(n%2==1)){\n println(\"Yes\")\n }else{\n println(\"No\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8ca5a1c6525dd9423c5b2b2c85337813", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val a = readLine()!!.split(\" \").map{ it.toInt() }.toMutableList()\n if (a[0] * 3 <= a[1]) {\n print(0)\n } else {\n print(a[0] * 3 - a[1])\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "7803013630e1a02787bfa9b97a9b0b84", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n\nimport java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.util.*\n\n\nvar a = 0\nvar b = 0\nvar c = 0\n\nfun main(args: Array) {\n val reader = Reader()\n for (i in 1..3) {\n val next = reader.next()\n if (next[1] == '>') {\n isGreater(next[0])\n } else {\n isGreater(next[2])\n }\n }\n if (a == 1 && b == 1 && c == 1)\n print(\"Impossible\")\n else\n for (i in 0..2) {\n if (a == i)\n print('A')\n if (b == i)\n print('B')\n if (c == i)\n print('C')\n }\n}\n\nfun isGreater(char: Char) {\n if (char == 'A') a++ else if (char == 'B') b++ else c++\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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5a4964956361d1f7301b43d87aba8415", "src_uid": "97fd9123d0fb511da165b900afbde5dc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main()\n{\n var mp =HashMap()\n mp.put('A',0)\n mp.put('B',0)\n mp.put('C',0)\n var s:String\n s= readLine()!!.toString()\n if(s[1]=='>')\n mp.set(s[0],+1)else\n mp.set(s[2],+1)\n s= readLine()!!.toString()\n if(s[1]=='>')\n {\n if(mp.get(s[0])==1)\n mp.set(s[0],+2)else\n mp.set(s[0],1)\n }else\n {\n if(mp.get(s[2])==1)\n mp.set(s[2],+2)else\n mp.set(s[2],1)\n }\n s= readLine()!!.toString()\n if(s[1]=='>')\n {\n if(mp.get(s[0])==1)\n mp.set(s[0],+2)else\n mp.set(s[0],1)\n }else\n {\n if(mp.get(s[2])==1)\n mp.set(s[2],+2)else\n mp.set(s[2],1)\n }\n val result = mp.toList().sortedBy { (_, value) -> value}.toMap()\n if(mp['A']==1&&mp['B']==1&&mp['C']==1)\n print(\"Impossible\") else\n {\n for (entry in result) {\n print(entry.key)\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "fac826605f6326d23ebea1ad734fd6e3", "src_uid": "97fd9123d0fb511da165b900afbde5dc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val a = Array(3) {readLine()!!}\n println(listOf(\"ABC\", \"ACB\", \"BAC\", \"BCA\", \"CAB\", \"CBA\").filter {\n s -> a.filter { x -> (s.indexOf(x[0]) > s.indexOf(x[2])) == (x[1] == '<')}.isEmpty()\n }.firstOrNull() ?: \"Impossible\")\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "481f0be5b2aabcb9694d5704b72160d1", "src_uid": "97fd9123d0fb511da165b900afbde5dc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n\tval a = Array(3) {readLine()!!}\n\tprintln(listOf(\"ABC\", \"ACB\", \"BAC\", \"BCA\", \"CAB\", \"CBA\").firstOrNull {\n\t\t\ts -> a.all {x -> (s.indexOf(x[0]) > s.indexOf(x[2])) != (x[1] == '<')}\n\t} ?: \"Impossible\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8a4f101017f596a2b39d4a3468338bf2", "src_uid": "97fd9123d0fb511da165b900afbde5dc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (hour, minutes) = readLine()!!.split(\":\").map(String::toInt)\n do {\n minutes++\n if (minutes == 60) {\n minutes = 0\n hour++\n if (hour == 24) hour = 0\n }\n } while (String.format(\"%02d\", hour) != String.format(\"%02d\", minutes).reversed())\n print(\"${String.format(\"%02d\", hour)}:${String.format(\"%02d\", minutes)}\")\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "967980fc9180d7bc99422c282ca02900", "src_uid": "158eae916daa3e0162d4eac0426fa87f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "\nimport java.io.BufferedInputStream\nimport java.io.File\nimport java.io.PrintWriter\nimport kotlin.system.measureTimeMillis\n\ninline fun TIME(f:()->Unit){\n val t = measureTimeMillis(){\n f()\n }\n println(\"$t ms\")\n}\n\nobject IO{\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(\"You forgot to disable tests you digital dummy!\")\n println(\"You forgot to disable tests you digital dummy!\")\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){ IO.OUT.println(aa)}\nfun done(){ IO.OUT.close() }\nfun share(aa:Any){\n if(aa is IntArray){IO.fakein.append(aa.joinToString(\" \"))}\n else if(aa is LongArray){IO.fakein.append(aa.joinToString(\" \"))}\n else if(aa is List<*>){IO.fakein.append(aa.toString())}\n else{IO.fakein.append(aa.toString())}\n IO.fakein.append(\"\\n\")\n}\n\nval getint:Int get() = IO.nextInt()\nval getlong:Long get() = IO.nextLong()\nval getstr:String get() = IO.nextString()\nfun getline(n:Int):IntArray{\n return IntArray(n){getint}\n}\nfun getlineL(n:Int):LongArray{\n return LongArray(n){getlong}\n}\nfun getbinary(n:Int, asTrue:Char):BooleanArray{\n val str = getstr\n return BooleanArray(n){str[it] == asTrue}\n}\n\nval List.ret:String\nget() = this.joinToString(\"\")\nvar dmark = -1\ninfix fun Any.dei(a:Any){\n //does not stand for anything it is just easy to type, have to be infix because kotlin does not have custom prefix operators\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 }\n println()\n }else{ println(\"$str : $a\")\n }\n}\nval just = \" \" // usage: just dei x , where x is the debug variable\nfun crash(){\n throw Exception(\"Bad programme\")} // because assertion does not work\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 answersChecked = 0\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 //safety checks\n if(pI != 998_244_353 && pI != 1_000_000_007){\n throw Exception(\"Modding a wrong prime!\")\n }\n if(withBruteForce){\n println(\"Brute force is active\")\n }\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 IO.rerouteInput()\n }else if(mode == solveMode.rand){\n rand()\n IO.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}\ninline fun T.alsoBrute(cal:() -> T){\n if(!withBruteForce) return\n val also = cal()\n if(this != also){\n println(\"Checking failed: Got ${this} Brute ${also}\")\n crash()\n }\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 * 1L * b) % pI).toInt() }\ninfix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }\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\n\n\ninfix fun Int.divCeil(b:Int):Int{\n //Positives numbers only!\n if(this == 0) {\n return 0\n }\n return (this-1)/b + 1\n}\ninfix fun Long.divCeil(b:Long):Long{\n //Positives numbers only!\n if(this == 0L) {\n return 0\n }\n return (this-1)/b + 1\n}\n\ninfix fun Long.modM(b:Long):Long{\n return (this * b) % p\n}\n//infix fun Int.modPlus(b:Int):Int{\n// val ans = this + b\n// return if(ans >= pI) ans - pI else ans\n//}\ninfix fun Int.modMinus(b:Int):Int{\n val ans = this - b\n return if(ans < 0) ans + pI else ans\n}\ninfix fun Int.modDivide(b:Int):Int{\n return this modM (b.inverse())\n}\nfun Int.additiveInverse():Int{\n return if(this == 0) 0 else pI - this\n}\n\n\nfun intPow(x:Int,e:Int,m:Int):Int{\n var X = x\n var E =e\n var Y = 1\n while(E > 0){\n if(E % 2 == 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}\nfun intPowEXP(x:Int,e:Long,m:Int):Int{\n var X = x\n var E =e\n var Y = 1\n while(E > 0){\n if(E % 2 == 0L){\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\nfun pow(x:Long,e:Long,m:Long):Long{\n var X = x\n var E =e\n var Y = 1L\n while(E > 0){\n if(E % 2 == 0L){\n X = (X * X) % m\n E /= 2\n }else{\n Y = (X * Y) % m\n E -= 1\n }\n }\n return Y\n}\nfun Long.inverse():Long{\n return pow(this,p-2,p)\n}\nfun Int.inverse():Int{\n return intPow(this,pI-2,pI)\n}\nfun min_rem(m:Int, r:Int, c:Int):Int {\n if(c < 1){\n return Int.MIN_VALUE\n }else if(r == 0){\n return 0\n }else{\n val step = m % r\n val mx = ((1L * c * r) /m ).toInt()\n val t = max_rem(r,step,mx)\n return r- t\n }\n}\nfun max_rem(m:Int, r:Int, c:Int):Int {\n if(r == 0|| c <= m/r){\n return r * c\n }else{\n val step = m % r\n val mx = ((1L * (c+1) * r )/m).toInt()\n val t = min_rem(r,step,mx)\n return m - t\n }\n}\nfun Int.reconstruct():String{\n val num = min_rem(pI,this, 10000)\n val denom = (this modDivide num).inverse()\n return \"$num / $denom\"\n}\n\n//make this int instead\nclass FACT{\n companion object {\n var store = IntArray(0)\n var invStore = IntArray(0)\n\n var slowStore:IntArray = IntArray(0)\n\n fun preCal(upto:Int){\n store = IntArray(upto+1)\n invStore = IntArray(upto + 1 )\n store[0] = 1\n invStore[0] = 1\n\n for(i in 1..upto) {\n store[i] = store[i-1] modM i\n invStore[i] = invStore[i-1] modM (i.inverse())\n }\n }\n fun choose(n:Int,r:Int):Int{\n if(r < 0 || r > n) return 0\n val a = store[n]\n val b = invStore[n-r]\n val c = invStore[r]\n return (a modM b) modM c\n }\n\n fun bigChoose(n:Int,r:Int):Int{\n var ret = 1\n for(i in 0 until r){\n ret = ret modM (n - i)\n }\n ret = ret modM (invStore[r])\n return ret\n }\n\n }\n}\n\nfun debug(){}\nconst val withBruteForce = false\nconst val singleCase = true\nfun main(){\n FACT.preCal(300)\n solve.cases{\n\n val n = getint\n val k = getint\n\n //phrases, MAX\n val DP = Array(n){IntArray(k+1)}\n val sum = Array(n){IntArray(k+1)}\n\n DP[0][0] = FACT.store[n-1]\n for(max in 0..k){\n sum[0][max] = FACT.store[n-1]\n }\n// sum[0][0] = FACT.store[n]\n\n for(p in 1 until n){\n for(max in 1..k){\n var now = 0\n var totalop = 0\n for(op in p-1 downTo 0 ){\n totalop += op\n now = now modPlus (sum[op][max-1] modM FACT.invStore[p-op] modM intPow(k-max+1,totalop,pI))\n }\n DP[p][max] = now\n }\n for(max in 0..k){\n sum[p][max] = DP[p][max]\n if(max > 0){\n sum[p][max] = sum[p][max-1] modPlus sum[p][max]\n }\n }\n }\n var ret = 0\n for(c in DP.last()){\n ret = ret modPlus c\n }\n\n put(ret)\n\n\n }\n done()\n}\n\n\n/*\n\n3 3\n\ncosts are\n1,1,2,..,n\n\n1 2 3 3 4 5\n1 2 3 3 4 5\n\n\n1 2\n2 1\n3 4\n4 3\nmax of hte two things then product\n\n */\n\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "graph matchings"], "code_uid": "37e0c9f7b8b345d0c21b817bb8dfc524", "src_uid": "b2d7ac8e75cbdb828067aeafd803ac62", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "\nimport java.io.BufferedInputStream\nimport java.io.File\nimport java.io.PrintWriter\nimport kotlin.system.measureTimeMillis\n\ninline fun TIME(f:()->Unit){\n val t = measureTimeMillis(){\n f()\n }\n println(\"$t ms\")\n}\n\nobject IO{\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(\"You forgot to disable tests you digital dummy!\")\n println(\"You forgot to disable tests you digital dummy!\")\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){ IO.OUT.println(aa)}\nfun done(){ IO.OUT.close() }\nfun share(aa:Any){\n if(aa is IntArray){IO.fakein.append(aa.joinToString(\" \"))}\n else if(aa is LongArray){IO.fakein.append(aa.joinToString(\" \"))}\n else if(aa is List<*>){IO.fakein.append(aa.toString())}\n else{IO.fakein.append(aa.toString())}\n IO.fakein.append(\"\\n\")\n}\n\nval getint:Int get() = IO.nextInt()\nval getlong:Long get() = IO.nextLong()\nval getstr:String get() = IO.nextString()\nfun getline(n:Int):IntArray{\n return IntArray(n){getint}\n}\nfun getlineL(n:Int):LongArray{\n return LongArray(n){getlong}\n}\nfun getbinary(n:Int, asTrue:Char):BooleanArray{\n val str = getstr\n return BooleanArray(n){str[it] == asTrue}\n}\n\nval List.ret:String\nget() = this.joinToString(\"\")\nvar dmark = -1\ninfix fun Any.dei(a:Any){\n //does not stand for anything it is just easy to type, have to be infix because kotlin does not have custom prefix operators\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 }\n println()\n }else{ println(\"$str : $a\")\n }\n}\nval just = \" \" // usage: just dei x , where x is the debug variable\nfun crash(){\n throw Exception(\"Bad programme\")} // because assertion does not work\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 answersChecked = 0\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 //safety checks\n if(pI != 998_244_353 && pI != 1_000_000_007){\n throw Exception(\"Modding a wrong prime!\")\n }\n if(withBruteForce){\n println(\"Brute force is active\")\n }\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 IO.rerouteInput()\n }else if(mode == solveMode.rand){\n rand()\n IO.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}\ninline fun T.alsoBrute(cal:() -> T){\n if(!withBruteForce) return\n val also = cal()\n if(this != also){\n println(\"Checking failed: Got ${this} Brute ${also}\")\n crash()\n }\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 * 1L * b) % pI).toInt() }\ninfix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }\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\n\n\ninfix fun Int.divCeil(b:Int):Int{\n //Positives numbers only!\n if(this == 0) {\n return 0\n }\n return (this-1)/b + 1\n}\ninfix fun Long.divCeil(b:Long):Long{\n //Positives numbers only!\n if(this == 0L) {\n return 0\n }\n return (this-1)/b + 1\n}\n\ninfix fun Long.modM(b:Long):Long{\n return (this * b) % p\n}\n//infix fun Int.modPlus(b:Int):Int{\n// val ans = this + b\n// return if(ans >= pI) ans - pI else ans\n//}\ninfix fun Int.modMinus(b:Int):Int{\n val ans = this - b\n return if(ans < 0) ans + pI else ans\n}\ninfix fun Int.modDivide(b:Int):Int{\n return this modM (b.inverse())\n}\nfun Int.additiveInverse():Int{\n return if(this == 0) 0 else pI - this\n}\n\n\nfun intPow(x:Int,e:Int,m:Int):Int{\n var X = x\n var E =e\n var Y = 1\n while(E > 0){\n if(E % 2 == 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}\nfun intPowEXP(x:Int,e:Long,m:Int):Int{\n var X = x\n var E =e\n var Y = 1\n while(E > 0){\n if(E % 2 == 0L){\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\nfun pow(x:Long,e:Long,m:Long):Long{\n var X = x\n var E =e\n var Y = 1L\n while(E > 0){\n if(E % 2 == 0L){\n X = (X * X) % m\n E /= 2\n }else{\n Y = (X * Y) % m\n E -= 1\n }\n }\n return Y\n}\nfun Long.inverse():Long{\n return pow(this,p-2,p)\n}\nfun Int.inverse():Int{\n return intPow(this,pI-2,pI)\n}\nfun min_rem(m:Int, r:Int, c:Int):Int {\n if(c < 1){\n return Int.MIN_VALUE\n }else if(r == 0){\n return 0\n }else{\n val step = m % r\n val mx = ((1L * c * r) /m ).toInt()\n val t = max_rem(r,step,mx)\n return r- t\n }\n}\nfun max_rem(m:Int, r:Int, c:Int):Int {\n if(r == 0|| c <= m/r){\n return r * c\n }else{\n val step = m % r\n val mx = ((1L * (c+1) * r )/m).toInt()\n val t = min_rem(r,step,mx)\n return m - t\n }\n}\nfun Int.reconstruct():String{\n val num = min_rem(pI,this, 10000)\n val denom = (this modDivide num).inverse()\n return \"$num / $denom\"\n}\n\n//make this int instead\nclass FACT{\n companion object {\n var store = IntArray(0)\n var invStore = IntArray(0)\n\n var slowStore:IntArray = IntArray(0)\n\n fun preCal(upto:Int){\n store = IntArray(upto+1)\n invStore = IntArray(upto + 1 )\n store[0] = 1\n invStore[0] = 1\n\n for(i in 1..upto) {\n store[i] = store[i-1] modM i\n invStore[i] = invStore[i-1] modM (i.inverse())\n }\n }\n fun choose(n:Int,r:Int):Int{\n if(r < 0 || r > n) return 0\n val a = store[n]\n val b = invStore[n-r]\n val c = invStore[r]\n return (a modM b) modM c\n }\n\n fun bigChoose(n:Int,r:Int):Int{\n var ret = 1\n for(i in 0 until r){\n ret = ret modM (n - i)\n }\n ret = ret modM (invStore[r])\n return ret\n }\n\n }\n}\n\nfun debug(){}\nconst val withBruteForce = false\nconst val singleCase = true\nfun main(){\n FACT.preCal(300)\n solve.cases{\n\n val n = getint\n val k = getint\n\n //phrases, MAX\n val DP = Array(n){IntArray(k+1)}\n val sum = Array(n){IntArray(k+1)}\n\n DP[0][0] = FACT.store[n-1]\n for(max in 0..k){\n sum[0][max] = FACT.store[n-1]\n }\n// sum[0][0] = FACT.store[n]\n\n for(p in 1 until n){\n for(max in 1..k){\n var now = 0\n var totalop = 0\n for(op in p-1 downTo 0 ){\n totalop += op\n now = now modPlus (sum[op][max-1] modM FACT.invStore[p-op] modM intPow(k-max+1,totalop,pI))\n }\n DP[p][max] = now\n }\n for(max in 0..k){\n sum[p][max] = DP[p][max]\n if(max > 0){\n sum[p][max] = sum[p][max-1] modPlus sum[p][max]\n }\n }\n }\n var ret = 0\n for(c in DP.last()){\n ret = ret modPlus c\n }\n\n put(ret)\n\n\n }\n done()\n}\n\n\n/*\n\n3 3\n\ncosts are\n1,1,2,..,n\n\n1 2 3 3 4 5\n1 2 3 3 4 5\n\n\n1 2\n2 1\n3 4\n4 3\nmax of hte two things then product\n\n */\n\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "graph matchings"], "code_uid": "29743ab3cf187e71ba0c763c31616c72", "src_uid": "b2d7ac8e75cbdb828067aeafd803ac62", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007\n\nclass BIT(n: Int) {\n private val N =\n if (Integer.highestOneBit(n) == n) n\n else Integer.highestOneBit(n) shl 1\n\n private val bit = IntArray(N + 1)\n\n fun sum(i: Int): Int {\n var x = i\n var s = 0\n while(x > 0) {\n s += bit[x]\n x -= x and -x\n }\n return s\n }\n\n fun add(i: Int, a: Int) {\n var x = i + 1\n while(x <= N) {\n bit[x] += a\n x += x and -x\n }\n }\n}\n\nfun main() {\n val (N) = readInts()\n val A = readInts().filter{it > 0}.toIntArray()\n A.sort()\n val win = A.size == 1 ||\n A.size == 2 && calc2(A, N == 2) ||\n A.size == 3 && A[0] xor A[1] != A[2]\n\n if (win) println(\"BitLGM\")\n else println(\"BitAryo\")\n}\n\nfun calc2(A: IntArray, op2: Boolean): Boolean {\n val dp = Array(A[0] + 1) { BooleanArray(A[1] + 1) }\n for (i in 0..A[0]) {\n for (j in 0..A[1]) {\n var win = false\n for (l in 0 until i) {\n if (!dp[l][j]) win = true\n }\n for (l in 0 until j) {\n if (!dp[i][l]) win = true\n }\n if (op2) {\n for (l in 1..min(i, j)) {\n if (!dp[i - l][j - l]) win = true\n }\n }\n dp[i][j] = win\n }\n }\n return dp[A[0]][A[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\nprivate val isDebug = try {\n // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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}", "lang_cluster": "Kotlin", "tags": ["dp", "games"], "code_uid": "b5492f0712239a0b89220a5e82b108d1", "src_uid": "7a33b4f94082c7ef80d7e87b58497fa7", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.PriorityQueue\nimport java.util.SortedMap\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\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n val r0 = readInt()\n val g0 = readInt()\n\n var D = ModIntArray(r0 + 1)\n D[r0] = ModInt(1)\n\n for(h in 1..200000) {\n val Di = ModIntArray(D.size)\n val s = g0 - h * (h-1) / 2 + r0\n var ok = false\n for(r in D.indices) {\n val v = D[r]\n if(v.int == 0) continue\n val g = s - r\n if(r >= h) {\n Di[r-h] += v\n ok = true\n }\n if(g >= h) {\n Di[r] += v\n ok = true\n }\n }\n if(!ok) break\n D = Di\n }\n\n val ans = D.sum().int\n\n println(ans)\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 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 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 operator fun plus(other: ModInt) = // MODINT_BASE < 2^30\n (int + other.int).let { if(it >= MODINT_BASE) ModInt(it - MODINT_BASE) else ModInt(it) }\n inline operator fun plus(other: Int) = plus(other.toModInt())\n operator fun inc() = if(int == MODINT_BASE - 1) ModInt(0) else ModInt(int + 1)\n\n operator fun minus(other: ModInt) =\n (int - other.int).let { if(it < 0) ModInt(it + MODINT_BASE) else ModInt(it) }\n inline operator fun minus(other: Int) = minus(other.toModInt())\n operator fun dec() = if(int == 0) ModInt(MODINT_BASE - 1) else ModInt(int - 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) {\n require(int != 0) { \"Can't invert/divide by 0\" }\n exponent umod MODINT_TOTIENT\n } else exponent\n return ModInt(int.powMod(e, MODINT_BASE))\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 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 inline 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 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(capacity: Int) = ModIntArray(IntArray(capacity))\ninline fun ModIntArray(capacity: Int, init: (Int) -> ModInt) =\n ModIntArray(IntArray(capacity) { init(it).int })\n\nfun ModIntArray.sum() = indices.sumByModInt(::get)\nfun ModIntArray.product() = indices.productByModInt(::get)\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 }\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()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}", "lang_cluster": "Kotlin", "tags": ["dp"], "code_uid": "ee4871783f7045f91f1c9b1c8533fa21", "src_uid": "34b6286350e3531c1fbda6b0c184addc", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 R = ni()\n val G = ni()\n var H = 0\n while((H + 1) * (H + 2) / 2 <= R + G) H++\n val N = min(R, G)\n var cur = IntArray(1_000_000)\n var next = IntArray(1_000_000)\n cur[0] = 1\n var sum = 0L\n for (i in H - 1 downTo 0) {\n val size = min(N, H * (H + 1) / 2 - i * (i + 1) / 2)\n val nsize = min(N, H * (H + 1) / 2 - (i + 1) * (i + 2) / 2)\n for (j in 0 .. size) {\n next[j] = 0\n if (j <= nsize) next[j] += cur[j]\n val nj = j - (i + 1)\n if (nj in 0..nsize) {\n next[j] += cur[nj]\n }\n if (next[j] > MOD) next[j] -= MOD\n }\n// debug(next.take(10).toLongArray())\n val tmp = cur\n cur = next\n next = tmp\n sum += size\n }\n debug{\"sum:$sum\"}\n var ans = 0L\n val remain = R + G - H * (H + 1) / 2\n for (r in 0 .. remain) {\n val j = N - r\n if (j in cur.indices) ans += cur[j]\n }\n out.println(ans % 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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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", "lang_cluster": "Kotlin", "tags": ["dp"], "code_uid": "376e1d9d0bd9f8aac9d64da395e2f2ca", "src_uid": "34b6286350e3531c1fbda6b0c184addc", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLine()!!\n var questionMarks = 0L\n val characters = mutableSetOf()\n var multiplier = 10L\n for (c in s) if (c == '?') questionMarks++ else if (c in 'A'..'J') characters.add(c)\n var sol = 1L\n when (s.first()) {\n '?' -> {\n sol = 9L\n questionMarks--\n }\n in 'A'..'J' -> {\n sol = 9L\n characters.remove(s.first())\n multiplier--\n }\n }\n for (i in 0 until questionMarks) sol *= 10\n for (i in 0 until characters.size) sol *= multiplier--\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "6b2dff346b8736287b54fb8e80ab8a1a", "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val periodic = HashSet()\n fun setUp() {\n periodic += \"H\"\n periodic += \"HE\"\n periodic += \"LI\"\n periodic += \"BE\"\n periodic += \"B\"\n periodic += \"C\"\n periodic += \"N\"\n periodic += \"O\"\n periodic += \"F\"\n periodic += \"NE\"\n periodic += \"NA\"\n periodic += \"MG\"\n periodic += \"AL\"\n periodic += \"P\"\n periodic += \"S\"\n periodic += \"CL\"\n periodic += \"AR\"\n periodic += \"K\"\n periodic += \"CA\"\n periodic += \"TI\"\n periodic += \"V\"\n periodic += \"CR\"\n periodic += \"MN\"\n periodic += \"FE\"\n periodic += \"ZN\"\n periodic += \"GA\"\n periodic += \"GE\"\n periodic += \"AS\"\n periodic += \"SE\"\n periodic += \"BR\"\n periodic += \"KR\"\n periodic += \"RB\"\n periodic += \"SR\"\n periodic += \"Y\"\n periodic += \"ZR\"\n periodic += \"MO\"\n periodic += \"TC\"\n periodic += \"RU\"\n periodic += \"RH\"\n periodic += \"PD\"\n periodic += \"AG\"\n periodic += \"CD\"\n periodic += \"TE\"\n periodic += \"I\"\n periodic += \"XE\"\n periodic += \"BA\"\n periodic += \"LA\"\n periodic += \"CE\"\n periodic += \"PR\"\n periodic += \"ND\"\n periodic += \"PM\"\n periodic += \"SM\"\n periodic += \"EU\"\n periodic += \"GD\"\n periodic += \"TB\"\n periodic += \"DY\"\n periodic += \"ER\"\n periodic += \"TM\"\n periodic += \"LU\"\n periodic += \"TA\"\n periodic += \"W\"\n periodic += \"RE\"\n periodic += \"IR\"\n periodic += \"PT\"\n periodic += \"AU\"\n periodic += \"HG\"\n periodic += \"TL\"\n periodic += \"AT\"\n periodic += \"RN\"\n periodic += \"FR\"\n periodic += \"RA\"\n periodic += \"AC\"\n periodic += \"TH\"\n periodic += \"PA\"\n periodic += \"U\"\n periodic += \"AM\"\n periodic += \"CM\"\n periodic += \"ES\"\n periodic += \"FM\"\n periodic += \"MD\"\n periodic += \"LR\"\n periodic += \"RF\"\n periodic += \"DB\"\n periodic += \"SG\"\n periodic += \"MT\"\n periodic += \"DS\"\n periodic += \"RG\"\n periodic += \"FL\"\n periodic += \"MC\"\n periodic += \"LV\"\n periodic += \"TS\"\n periodic += \"OG\"\n }\n setUp()\n val input = System.`in`.bufferedReader().readLine()\n\n // val calced = BooleanArray(input.length)\n// val valid = BooleanArray(input.length)\n fun solve(id: Int): Boolean {\n if (id == input.length) {\n return true\n }\n// if (!calced[id]) {\n var isValid = false\n if (input[id].toString() in periodic) {\n isValid = isValid || solve(id + 1)\n }\n if (id < input.lastIndex && (input[id].toString() + input[id + 1]) in periodic) {\n isValid = isValid || solve(id + 2)\n }\n// valid[id] = isValid\n// }\n// return valid[id]\n return isValid\n }\n print(if (solve(0)) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "dp"], "code_uid": "5e107c2998435ebc3b6f5d373e0b3a1f", "src_uid": "d0ad35798119f98320967127c43ae88d", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val a = listOf(\"AC\",\"AG\",\"AL\",\"AM\",\"AR\",\"AS\",\"AT\",\"AU\",\"B\",\"BA\",\"BE\",\"BH\",\"BI\",\"BK\",\"BR\",\"C\",\"CA\",\"CD\",\"CE\",\"CF\",\"CL\",\"CM\",\"CN\",\"CO\",\"CR\",\"CS\",\"CU\",\"DB\",\"DS\",\"DY\",\"ER\",\"ES\",\"EU\",\"F\",\"FE\",\"FL\",\"FM\",\"FR\",\"GA\",\"GD\",\"GE\",\"H\",\"HE\",\"HF\",\"HG\",\"HO\",\"HS\",\"I\",\"IN\",\"IR\",\"K\",\"KR\",\"LA\",\"LI\",\"LR\",\"LU\",\"LV\",\"MC\",\"MD\",\"MG\",\"MN\",\"MO\",\"MT\",\"N\",\"NA\",\"NB\",\"ND\",\"NE\",\"NH\",\"NI\",\"NO\",\"NP\",\"O\",\"OG\",\"OS\",\"P\",\"PA\",\"PB\",\"PD\",\"PM\",\"PO\",\"PR\",\"PT\",\"PU\",\"RA\",\"RB\",\"RE\",\"RF\",\"RG\",\"RH\",\"RN\",\"RU\",\"S\",\"SB\",\"SC\",\"SE\",\"SG\",\"SI\",\"SM\",\"SN\",\"SR\",\"TA\",\"TB\",\"TC\",\"TE\",\"TH\",\"TI\",\"TL\",\"TM\",\"TS\",\"U\",\"V\",\"W\",\"XE\",\"Y\",\"YB\",\"ZN\",\"ZR\")\n val s = readLine()!!\n val n = s.length\n val b = BooleanArray(n+1)\n b[0] = true\n for (i in 1..n) {\n for (e in a) {\n if (i >= e.length && b[i - e.length] && s.substring(i - e.length, i) == e) {\n b[i] = true\n break\n }\n }\n }\n println(if (b[n]) \"YES\" else \"NO\")\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "dp"], "code_uid": "612333d389e30becff77c726243e2055", "src_uid": "d0ad35798119f98320967127c43ae88d", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val periodic = HashSet()\n fun setUp() {\n periodic += \"H\"\n periodic += \"HE\"\n periodic += \"LI\"\n periodic += \"BE\"\n periodic += \"B\"\n periodic += \"C\"\n periodic += \"N\"\n periodic += \"O\"\n periodic += \"F\"\n periodic += \"NE\"\n periodic += \"NA\"\n periodic += \"MG\"\n periodic += \"AL\"\n periodic += \"SI\"\n periodic += \"P\"\n periodic += \"S\"\n periodic += \"CL\"\n periodic += \"AR\"\n periodic += \"K\"\n periodic += \"CA\"\n periodic += \"SC\"\n periodic += \"TI\"\n periodic += \"V\"\n periodic += \"CR\"\n periodic += \"MN\"\n periodic += \"FE\"\n periodic += \"CO\"\n periodic += \"NI\"\n periodic += \"CU\"\n periodic += \"ZN\"\n periodic += \"GA\"\n periodic += \"GE\"\n periodic += \"AS\"\n periodic += \"SE\"\n periodic += \"BR\"\n periodic += \"KR\"\n periodic += \"RB\"\n periodic += \"SR\"\n periodic += \"Y\"\n periodic += \"ZR\"\n periodic += \"NB\"\n periodic += \"MO\"\n periodic += \"TC\"\n periodic += \"RU\"\n periodic += \"RH\"\n periodic += \"PD\"\n periodic += \"AG\"\n periodic += \"CD\"\n periodic += \"IN\"\n periodic += \"SN\"\n periodic += \"SB\"\n periodic += \"TE\"\n periodic += \"I\"\n periodic += \"XE\"\n periodic += \"CS\"\n periodic += \"BA\"\n periodic += \"LA\"\n periodic += \"CE\"\n periodic += \"PR\"\n periodic += \"ND\"\n periodic += \"PM\"\n periodic += \"SM\"\n periodic += \"EU\"\n periodic += \"GD\"\n periodic += \"TB\"\n periodic += \"DY\"\n periodic += \"HO\"\n periodic += \"ER\"\n periodic += \"TM\"\n periodic += \"YB\"\n periodic += \"LU\"\n periodic += \"HF\"\n periodic += \"TA\"\n periodic += \"W\"\n periodic += \"RE\"\n periodic += \"OS\"\n periodic += \"IR\"\n periodic += \"PT\"\n periodic += \"AU\"\n periodic += \"HG\"\n periodic += \"TL\"\n periodic += \"PB\"\n periodic += \"BI\"\n periodic += \"PO\"\n periodic += \"AT\"\n periodic += \"RN\"\n periodic += \"FR\"\n periodic += \"RA\"\n periodic += \"AC\"\n periodic += \"TH\"\n periodic += \"PA\"\n periodic += \"U\"\n periodic += \"NP\"\n periodic += \"PU\"\n periodic += \"AM\"\n periodic += \"CM\"\n periodic += \"BK\"\n periodic += \"CF\"\n periodic += \"ES\"\n periodic += \"FM\"\n periodic += \"MD\"\n periodic += \"NO\"\n periodic += \"LR\"\n periodic += \"RF\"\n periodic += \"DB\"\n periodic += \"SG\"\n periodic += \"BH\"\n periodic += \"HS\"\n periodic += \"MT\"\n periodic += \"DS\"\n periodic += \"RG\"\n periodic += \"CN\"\n periodic += \"NH\"\n periodic += \"FL\"\n periodic += \"MC\"\n periodic += \"LV\"\n periodic += \"TS\"\n periodic += \"OG\"\n }\n setUp()\n val input = System.`in`.bufferedReader().readLine()\n val calced = BooleanArray(input.length)\n val valid = BooleanArray(input.length)\n fun solve(id: Int): Boolean {\n if (id == input.length) {\n return true\n }\n if (!calced[id]) {\n var isValid = false\n if (input[id].toString() in periodic) {\n isValid = isValid || solve(id + 1)\n }\n if (id < input.lastIndex && (input[id].toString() + input[id + 1]) in periodic) {\n isValid = isValid || solve(id + 2)\n }\n valid[id] = isValid\n }\n return valid[id]\n }\n print(if (solve(0)) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "dp"], "code_uid": "591e39865289e6716a3c5769acee9a18", "src_uid": "d0ad35798119f98320967127c43ae88d", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.lang.Exception\nimport java.util.*\n\nfun PrintWriter.solve(sc: FastScanner) {\n val el = \"Ac Ag Al Am Ar As At Au B Ba Be Bh Bi Bk Br C Ca Cd Ce Cf Cl Cm Cn Co Cr Cs Cu Db Ds Dy Er Es Eu F Fe Fl Fm Fr Ga Gd Ge H He Hf Hg Ho Hs I In Ir K Kr La Li Lr Lu Lv Mc Md Mg Mn Mo Mt N Na Nb Nd Ne Nh Ni No Np O Og Os P Pa Pb Pd Pm Po Pr Pt Pu Ra Rb Re Rf Rg Rh Rn Ru S Sb Sc Se Sg Si Sm Sn Sr Ta Tb Tc Te Th Ti Tl Tm Ts U V W Xe Y Yb Zn Zr\".toUpperCase().split(' ')\n val s = sc.nextLine()\n val n = s.length\n val D = BooleanArray(n + 1)\n D[0] = true\n\n for(i in s.indices) {\n if(!D[i]) continue\n if(s.substring(i, i+1) in el) D[i+1] = true\n if(i + 2 <= n && s.substring(i, i+2) in el) D[i+2] = true\n }\n\n println(if(D.last()) \"YES\" else \"NO\")\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", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "dp"], "code_uid": "cb847eb3317b0a03107884f3af49b6dc", "src_uid": "d0ad35798119f98320967127c43ae88d", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val password = readLine()!!\n val binaryToDecimal = mutableMapOf()\n for (char in '0'..'9')\n binaryToDecimal[readLine()!!] = char\n val sol = StringBuilder()\n for (start in 0..70 step 10)\n sol.append(binaryToDecimal[password.substring(start..start + 9)]!!)\n print(sol.toString())\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "c2573d8f85bb8e92d0513492bc70ee8e", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n val inp = Scanner(System.`in`)\n var Binaries = ArrayList()\n val BinPassWord = inp.next()\n for(i in 1..10) {\n val inpPerBin = inp.next()\n Binaries.add(inpPerBin)\n }\n val chunked = BinPassWord.chunked(10)\n for(i in chunked) {\n print(Binaries.indexOf(i))\n }\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "8360347406f5687209f3be12bf78fac7", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "535daee3ac1e215de88a56c966fd63c9", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "1d940c28a0b0b6ef5c94a1168b3bc30b", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "b31f3459b69b57acaaaee4a8fec14077", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "ae7ce63e4731ac3935cf182ff3c688a0", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun isOkM(z : Long, m : Long) : Boolean {\n if ((m - 1) % 2L != 0L) return false\n val k = (m - 1) / 2L\n if (k < 1) return false\n if (z / (2 * k + 1) <= 0L) return false\n return z % (2 * k + 1) == k\n}\n\nfun isUnsolvable(z : Long) : Boolean {\n // even\n val d = (z + 1) * 2 - 1\n var m = 1L\n while (m * m <= d) {\n if (d % m == 0L) {\n if (isOkM(z, m)) return false\n if (isOkM(z, d / m)) return false\n }\n ++m\n }\n /*var k = 1L\n while (z / (2 * k + 1) > 0) {\n if (z % (2 * k + 1) == k) {\n println(\"even --- \" + k)\n return false\n }\n ++k\n }*/\n\n // odd\n /*k = 1L\n while (z / (2 * k) > 0) {\n if (z % (2 * k) == k - 1) {\n println(\"odd --- \" + k)\n return false\n }\n ++k\n }*/\n return true\n}\n\nvar a = arrayOf(1, 2, 4, 6, 12, 16, 18, 30, 60, 88, 106, 126, 520, 606, 1278, 2202, 2280, 3216, 4252, 4422, 9688, 9940,\n 11212, 19936, 21700, 23208, 44496, 86242, 110502, 132048, 216090, 756838, 859432, 1257786, 1398268, 2976220,\n 3021376, 6972592, 13466916, 20996010, 24036582, 25964950, 30402456, 32582656)\n\n\nfun main(args : Array) {\n val n = readLine()!!.toInt()\n val deg = a[n - 1]\n var cur = 1\n for (i in 1..deg) {\n cur *= 2\n cur %= 1000000007\n }\n println(cur - 1)\n /*var z = 2L\n var deg = 1\n while (deg < 62) {\n if (isUnsolvable(z - 1)) {\n println(deg.toString() + \" --- \" + (z - 1))\n }\n z *= 2L\n ++deg\n }*/\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "8c182b46d23e51980072fe1391d17995", "src_uid": "c2cbc35012c6ff7ab0d6899e6015e4e7", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val minimum = readInts().min()!!\n var sol = 1L\n for (n in 2 .. minimum)\n sol *= n\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "d1a344a0025f1715ff87bd5da2fdcb13", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport kotlin.math.*\n\nfun main() {\n io.apply {\n \n var x = min(int, int)\n var ans = 1\n while (x > 1) {\n ans *= x--\n }\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 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", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "0d2bac67e46bd97521dcf9fa25ac0ef7", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "c2894acf1b05c57798d0c894ef22c067", "src_uid": "7038d7b31e1900588da8b61b325e4299", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.5", "source_code": "import java.io.BufferedReader\r\nimport java.io.BufferedWriter\r\n\r\nclass ProblemE {\r\n private fun BufferedReader.readInt(): Int = this.readLine().toInt()\r\n private fun BufferedReader.readIntArray(delimiter: String = \" \") =\r\n this.readLine().split(delimiter).map { it.toInt() }.toIntArray()\r\n\r\n private fun BufferedWriter.writeLine(s: String) {\r\n this.write(s)\r\n this.newLine()\r\n }\r\n\r\n private fun solveTest(input: BufferedReader, output: BufferedWriter) {\r\n val (n, m) = input.readIntArray()\r\n\r\n /***\r\n * x^(i*j) where 1 <=i <= log_x(k), 1 <= j <= m\r\n * 1 <= i <= 20, 1 <= j <= 1e6\r\n *\r\n */\r\n val numDistinctPowers = IntArray(22)\r\n var numUnique = 0\r\n val visited = BooleanArray(22*(m +1))\r\n for(i in 1 until numDistinctPowers.size) {\r\n for(j in 1..m) {\r\n if(!visited[i*j]) {\r\n visited[i*j] = true\r\n numUnique+=1\r\n }\r\n }\r\n numDistinctPowers[i] = numUnique\r\n }\r\n val isAPower = BooleanArray(n +1)\r\n var numDistinct = 1L\r\n for(x in 2..n) {\r\n if(!isAPower[x]) {\r\n var powerCount = 0\r\n var j = x.toLong()\r\n while(j <= n) {\r\n isAPower[j.toInt()] = true\r\n powerCount += 1\r\n j *= x\r\n }\r\n numDistinct+= numDistinctPowers[powerCount]\r\n }\r\n }\r\n output.writeLine(numDistinct.toString())\r\n }\r\n\r\n fun solve(input: BufferedReader, output: BufferedWriter) {\r\n solveTest(input, output)\r\n input.close()\r\n output.close()\r\n }\r\n\r\n}\r\n\r\nfun main() {\r\n val solution = ProblemE()\r\n solution.solve(System.`in`.bufferedReader(), System.out.bufferedWriter())\r\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "dp", "number theory"], "code_uid": "4233b286aca12f16466317d27fc8815c", "src_uid": "6ca310cb0b6fc4e62e63a731cd55aead", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "// 2022.07.31 at 20:35:58 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 = 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\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 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()) // 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\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\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\nfun debug(){}\r\nconst val singleCase = true\r\nfun main(){\r\n solve.cases{\r\n val n = getint\r\n val m = getint\r\n var base = (n-1) * m.toLong() + 1\r\n\r\n val arr = BooleanArray((m+1) * 20)\r\n var taken = 0\r\n val ret = IntArray(21)\r\n for(level in 1..20){\r\n for(i in level..level * m step level){\r\n if(arr[i] == false){\r\n arr[i] = true\r\n taken ++\r\n }\r\n }\r\n ret[level] = taken\r\n }\r\n val checked = BooleanArray(n+1)\r\n for(p in 2..n){\r\n\r\n if(checked[p]){\r\n continue\r\n }\r\n var now =1\r\n var maxp = 0\r\n while(now * p.toLong() <= n){\r\n now *= p\r\n checked[now] = true\r\n maxp ++\r\n }\r\n val distinct = maxp.toLong() * m\r\n val actual = ret[maxp]\r\n base -= distinct\r\n base += actual\r\n }\r\n put(base)\r\n\r\n\r\n\r\n\r\n }\r\n done()\r\n}\r\n\r\n\r\n\r\n/*\r\n1 1\r\n2 4\r\n3 9\r\n4 16\r\n\r\n1000000 1000000\r\n */\r\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "dp", "number theory"], "code_uid": "cd00ab62c24e62dee136c1c30fd06c15", "src_uid": "6ca310cb0b6fc4e62e63a731cd55aead", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "ff9e323f2847ab6df194f41be25f1d24", "src_uid": "e66ecb0021a34042885442b336f3d911", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "82efa9c070895934f7644ddc89dbe41f", "src_uid": "e66ecb0021a34042885442b336f3d911", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//1.1 | RexTester.Com & 1.2 | CodeForces.Com\nfun main(args: Array)\n{\n val(input1, input2) = readLine()!!.split(' ')\n\n val grown_ups = input1.toInt()\n val children = input2.toInt()\n\n if (grown_ups < 1 && children > 0) {\n print(\"Impossible\")\n return\n }\n\n print(\"${Math.max(grown_ups, children)} ${if (children > 0) grown_ups + children - 1 else grown_ups}\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "7cc1f60227e50308b307e70a3ad1e0e9", "src_uid": "1e865eda33afe09302bda9077d613763", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//http://rextester.com Kotlin 1.1\nfun main(args:Array){\n val(a,b)=readLine()!!.split(' ');val c=a.toInt();val d=b.toInt()\n if(c<1&&d>0){print(\"Impossible\");return}\n var e=c+d-1\n if(d==0)e=c\n print(\"${Math.max(c,d)} $e\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "5f388709fdc3b31002da353a574a886a", "src_uid": "1e865eda33afe09302bda9077d613763", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args:Array){val(x,y)=readLine()!!.split(' ');val a=x.toInt();val b=y.toInt();if(a<1&&b>0){print(\"Impossible\");return};print(\"${Math.max(a,b)} ${if(b>0)a+b-1 else a}\")}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "9017577fceef8897aba28cff02ea2041", "src_uid": "1e865eda33afe09302bda9077d613763", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//rextester.com:1.1--codeforces.com:1.0.5-2\nfun main(args:Array){\n val(z,y)=readLine()!!.split(' ');val a=z.toInt();val b=y.toInt()\n if(a<1&&b>0){print(\"Impossible\");return}\n print(\"${Math.max(a,b)} ${if(b>0)a+b-1 else a}\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "57eaa575b32b1494557a44dc496ccc95", "src_uid": "1e865eda33afe09302bda9077d613763", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args:Array)\n{\n\n var counter = 1\n var insert = 0\n var c = 0.toChar()\n val input = readLine()\n\n input?.forEach {\n if( it == c ) {\n counter++\n }\n else {\n if( counter % 2 == 0 ) insert++\n counter = 1\n c = it\n }\n }\n\n if( counter % 2 == 0 ) insert++\n\n println(insert)\n}", "lang_cluster": "Kotlin", "tags": ["two pointers", "implementation"], "code_uid": "2abcf5a102cdcf132438951b2ceb4383", "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nfun main(args:Array){\n val obj=Scanner(System.`in`)\n val dna=obj.next()\n var status='z'\n var count=1\n var ins=0\n for(c in dna){\n if(c!=status) {\n if(count%2==0)\n ++ins\n count=0\n status=c\n }\n ++count\n }\n if(count%2==0) ++ins\n println(ins)\n}", "lang_cluster": "Kotlin", "tags": ["two pointers", "implementation"], "code_uid": "c98fdaf8312a2aaed04f8ab34916b50b", "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nval scanner = Scanner(System.`in`)\n\nfun readLong(): Long = scanner.nextLong()\n\nfun getLuckyNumber(index: Int) = Integer.toBinaryString(index + 2)\n .map { ch -> if (ch == '0') '4' else '7' }\n .joinToString(\"\")\n .substring(1)\n .toLong()\n\nfun getLuckyNumberIndex(luckyNumber: Long) = \"7${luckyNumber}\"\n .map { ch -> if (ch == '4') '0' else '1' }\n .joinToString(\"\")\n .let { Integer.parseInt(it, 2) - 2 }\n\nfun Long.nextLuckyNumber() = toString().length.let { digitsCount ->\n var index = getLuckyNumberIndex(String(CharArray(digitsCount) { '4' }).toLong())\n var luckyNumber = 0L\n while (luckyNumber < this) luckyNumber = getLuckyNumber(index++)\n luckyNumber\n}\n\nfun main() = (readLong()..readLong())\n .let { range ->\n var sum = 0L\n var start = range.first\n var luckyNumber = start.nextLuckyNumber()\n var end = minOf(luckyNumber, range.last)\n sum += (end - start + 1) * luckyNumber\n while (end < range.last) {\n start = luckyNumber + 1\n luckyNumber = start.nextLuckyNumber()\n end = minOf(luckyNumber, range.last)\n sum += (end - start + 1) * luckyNumber\n }\n sum\n }\n .run(::println)\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "eb77ba2738f59c28fb98de14bc85222d", "src_uid": "8a45fe8956d3ac9d501f4a13b55638dd", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "val M = 1000000007L\nval N = 200005\nvar fact = LongArray(N)\nvar ifact = LongArray(N)\nvar t = 0\n\n\nfun main(args : Array) {\n val (n, m, g) = readLine().toString().split(' ').map { it.toInt() }\n t = g\n init()\n\n // case when there are no ones\n if (m == 0) {\n val res = if (ok(n)) 1 else 0\n println(res)\n return\n }\n\n var ans = 0L\n // number of zeroes before first one position\n for (i in 0..n) {\n var k = ok(i + 1)\n if (m == 1 && i == n) k = ok(i)\n if (!k) continue\n ans = (ans + C(n - i + m - 1, m - 1)) % M\n }\n println(ans)\n}\n\nfun init() {\n fact[0] = 1L\n ifact[0] = 1L\n for (i in 1..(N - 1)) {\n fact[i] = (fact[i - 1] * i) % M\n ifact[i] = binpow(fact[i], M - 2)\n }\n}\n\nfun binpow(n : Long, deg : Long) : Long {\n if (deg == 0L) return 1L\n return if (deg % 2L == 1L) {\n n * binpow(n, deg - 1) % M\n } else {\n val b = binpow(n, deg / 2L)\n b * b % M\n }\n}\n\nfun C(n : Int, k : Int) : Long {\n return if (n < k) 0\n else fact[n] * ifact[k] % M * ifact[n - k] % M\n}\n\nfun ok(zeroes : Int) = (1 - zeroes % 2 == t)", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics", "number theory"], "code_uid": "dc5fa76830a5e8ce9f9e89510cbc9b38", "src_uid": "066dd9e6091238edf2912a6af4d29e7f", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun main(args : Array) {\n var list1: MutableList = mutableListOf()\n var list2: MutableList = mutableListOf()\n for (i in 0..7) {\n list1.add(readLine()!!)\n }\n\n var row = 0\n for (i in 0..7) {\n var col = 0\n for (char in list1[i]) {\n if (char == 'B') {\n col++\n }\n if (col == 8) {\n row++\n }\n }\n list2.add(col)\n }\n list2.sort()\n\n var c = row + list2[0]\n if(c==16){ println(8) }\n else { println(c)}\n\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms"], "code_uid": "152b37b4a7553111b4415bfcc1c72a6a", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun a7() {\n val list = mutableListOf()\n val listV = booleanArrayOf(false, false, false, false, false, false, false, false)\n var vertical = 0\n var horizontal = 0\n for (i in 0..7) {\n list.add(i, readLine()!!.toCharArray())\n }\n\n for (i in 0..7) {\n var lineH = true\n for (j in 0..7) {\n if (list[i][j] != 'B')\n lineH = false\n\n if (i == 0) {\n if (list[i][j] == 'B')\n listV[j] = true\n } else {\n if (list[i][j] != 'B')\n listV[j] = false\n }\n }\n\n if (lineH)\n horizontal++\n\n if (i == 7) {\n listV.forEach {\n if (it)\n vertical++\n }\n }\n }\n\n if (vertical == 8)\n horizontal = 0\n print(\"${vertical + horizontal}\")\n}\n\nfun main() {\n a7()\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms"], "code_uid": "0393e3b6b3a4d6bafe9daaa3d096d332", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val S = ns().map{it-'0'}\n val N = S.size\n val M = ni()\n val cntDigit = IntArray(10)\n for (i in 0 until S.size) {\n cntDigit[S[i]]++\n }\n val coef = IntArray(11)\n coef[0] = 1\n for (i in 0 until 10) {\n coef[i + 1] = coef[i] * (1 + cntDigit[i])\n }\n debug(coef)\n var best = Array(coef.last()){LongArray(M)}\n var next = Array(coef.last()){LongArray(M)}\n best[0][0] = 1\n\n val map = IntArray(10_000) // 100 * 10 + 100 \u3057\u304b\u3044\u304b\u306a\u3044\u3051\u3069\u305f\u304f\u3055\u3093\u3064\u304f\u3063\u3068\u304f\n for (i in 0 until map.size) {\n map[i] = i % M\n }\n\n var pow10 = 1\n for (i in N - 1 downTo 0) {\n for (s in 0 until coef.last()) {\n for (d in 0 until 10) {\n if (i == 0 && d == 0) continue\n if ((s + coef[d]) / coef[d + 1] > s / coef[d + 1]) continue\n val ns = s + coef[d]\n for (m in 0 until M) {\n if (best[s][m] == 0L) continue\n val nm = map[m + pow10 * d]\n// debug{\"s:$s m:$m d:$d ns:$ns nm:$nm\"}\n next[ns][nm] += best[s][m]\n }\n }\n }\n debug{\"DP($i)\"}\n debugDim(next)\n val t = best\n best = next\n next = t\n\n pow10 = (pow10 * 10) % M\n }\n out.println(best[coef.last() - 1][0])\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "combinatorics", "bitmasks", "number theory"], "code_uid": "f21ab706707c624a385b278a613e92b8", "src_uid": "5eb90c23ffa3794fdddc5670c0373829", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!.toInt()\n for (a in 0..n / 1234567) {\n for (b in 0..(n - a * 1234567) / 123456) {\n if ((n - a * 1234567 - b * 123456) % 1234 == 0) {\n print(\"YES\")\n return\n }\n }\n }\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "241455d13f034b653ee8b478ad725514", "src_uid": "72d7e422a865cc1f85108500bdf2adf2", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args : Array) {\n val t = readLine()!!\n val (a, b ) = readLine()!!.split(' ')\n val card = arrayOf('6','7','8','9','T','J','Q','K','A')\n\n\n if(t==a[1].toString()){\n\n if(t!=b[1].toString()){\n println(\"YES\")\n }\n else{\n var a1 = 0\n var b1 = 0\n\n for(i in 0..card.size-1) {\n if (a[0]==card[i]) {\n a1 = i\n }\n }\n for(j in 0..card.size-1) {\n if(b[0]==card[j]){\n b1 = j\n }\n }\n\n if(a1>b1){\n println(\"YES\")\n }\n else{\n println(\"NO\")\n }\n }\n\n }\n else if(a[1]!=b[1] && t!=a[1].toString()){\n println(\"NO\")\n }\n else if(a[1]==b[1] ){\n var a1 = 0\n var b1 = 0\n\n for(i in 0..card.size-1){\n if(card[i]==a[0]){\n a1 = i\n }\n if(card[i]==b[0]){\n b1 = i\n }\n }\n\n if(a1>b1){\n println(\"YES\")\n }\n else{\n println(\"NO\")\n }\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "3d9388ea44b860071bf2e38ca3598f34", "src_uid": "da13bd5a335c7f81c5a963b030655c26", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val cardToValue =\n mapOf('6' to 6, '7' to 7, '8' to 8, '9' to 9, 'T' to 10, 'J' to 11, 'Q' to 12, 'K' to 13, 'A' to 14)\n val trump = readLine()!![0]\n val (first, second) = readLine()!!.split(\" \")\n if (first[1] == second[1] && cardToValue[first[0]]!! > cardToValue[second[0]]!!) return print(\"YES\")\n if (first[1] == trump && second[1] != trump) return print(\"YES\")\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7c49e3a79b97768f95f7ebaabe840c34", "src_uid": "da13bd5a335c7f81c5a963b030655c26", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nfun main(){\n val s=Scanner(System.`in`)\n var r=s.next()\n var n=r.length\n var x:Int = -1\n var answer:String=\"\"\n for( i in 0..n-1){\n if(r[i]=='p'){\n answer += r[i]\n x=i\n break\n }\n else\n answer += r[i]\n }\n x++\n answer += \"://\"\n for (i in x..n-1){\n if(r[i]=='r' && r[i+1]=='u' && i!=x){\n answer+='.'\n answer+=\"ru\"\n x=i+1\n break\n }\n else\n answer+=r[i]\n }\n\n if(x!=n-1){\n x++\n answer+='/'\n for(i in x..n-1){\n answer+=r[i]\n }\n }\n print(answer)\n}\n", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "2e0be3638921cfb37a800bd3693c5d5f", "src_uid": "4c999b7854a8a08960b6501a90b3bba3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLine()!!\n val sb = StringBuilder()\n val startDomain = if (s.first() == 'h') {\n sb.append(\"http://\")\n 4\n } else {\n sb.append(\"ftp://\")\n 3\n }\n val domainEnd = s.indexOf(\"ru\", startDomain + 1)\n sb.append(s.substring(startDomain, domainEnd))\n sb.append(\".ru\")\n if (domainEnd + 2 != s.length) sb.append(\"/${s.substring(domainEnd + 2)}\")\n print(sb.toString())\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "29c7c28488fefa304228678c84cd5b23", "src_uid": "4c999b7854a8a08960b6501a90b3bba3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextLong()\n fun getNod(): Long {\n var i: Long = 2\n while (i * i <= n) {\n if (n % i == 0L) {\n return i\n }\n i++\n }\n return n\n }\n\n var t = n\n println(if (n % 2L != 0L) {\n t -= getNod()\n 1\n } else {\n 0\n } + t / 2)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "2de0b3c46b8f0d401a6787ca300dc6f8", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.sqrt\n\nfun main() {\n fun readLong() = readLine()!!.toLong()\n\n val n = readLong()\n val endLoop = sqrt(n.toDouble()).toLong()\n for (i in 2L..endLoop)\n if (n % i == 0L)\n return print(1 + (n - i) / 2)\n print(1)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "748e95fbf489494af0a04e35e4e0d7ae", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.sqrt\n\nfun main() {\n fun readLong() = readLine()!!.toLong()\n fun Long.factors(): MutableSet {\n val output = mutableSetOf()\n val endLoop = sqrt(this.toDouble()).toLong()\n for (i in 1L..endLoop) {\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().toList().sorted()\n print(1 + (n - factors[1]) / 2)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "dffd5fbec6f4a31b8aa9641a7af3460e", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n solve()\n}\n\nprivate fun read(delimit: Char = ' ') = readLine()!!.split(delimit)\nprivate fun solve() {\n val (n) = read().map(String::toLong)\n var step = 0L\n\n if (n % 2 == 0L) {\n step = n / 2\n } else {\n step = (1 + ((n - find(n)) / 2))\n }\n\n println(step)\n}\n\nprivate fun find(n: Long): Long {\n var i = 2L\n while (i * i <= n) {\n if (n % i == 0L)\n return i\n i++\n }\n return n\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "5d437cd307c05d0758c38266c7405eb0", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (a, b) = readLine()!!.split(\" \").map(String::toLong)\n val (x, y, z) = readLine()!!.split(\" \").map(String::toLong)\n val aReq = 2 * x + y\n val bReq = y + 3 * z\n println(max(aReq - a, 0) + max(bReq - b, 0))\n}\n\nfun max(x: Long, y: Long): Long {\n return if (x > y) x else y\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2657356512268e73a0ab2996e3a8c110", "src_uid": "35202a4601a03d25e18dda1539c5beba", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nclass A {\n fun start(scan: Scanner) {\n val a = scan.nextLong()\n val b = scan.nextLong()\n\n var yellow = scan.nextLong() * 2L\n val green = scan.nextLong()\n yellow += green\n var blue = scan.nextLong() * 3L\n blue += green\n\n println(Math.max(yellow - a, 0) + Math.max(blue - b, 0))\n }\n}\n\nfun main(args: Array) {\n A().start(Scanner(System.`in`))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "57e84f13b367f6a3fde869b6b521a6a6", "src_uid": "35202a4601a03d25e18dda1539c5beba", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\nimport kotlin.math.max\n\nfun main() {\n var (ac, bc) = readLine()!!.split(' ').map(String:: toLong)\n var (y, g, b) = readLine()!!.split(' ').map(String:: toLong)\n\n var ans : Long = max(0, 2*y-ac)\n ac = max(0, ac-2*y)\n\n ans += max(0, g-ac)\n ans += max(0, g-bc)\n bc = max(0, bc-g)\n\n ans += max(0, 3*b-bc)\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "775b9c0958de12a9c32e57933c53581c", "src_uid": "35202a4601a03d25e18dda1539c5beba", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var (ye, bl) = readLine()!!.split(\" \").map { it.toLong() }\n val (x, y, z) = readLine()!!.split(\" \").map { it.toLong() }\n var add = 0L\n\n if (ye * 2 < x) {\n val toAdd = ye / x / 2\n add += toAdd\n }\n ye -= x * 2\n\n if (bl * 3 < z) {\n val toAdd = bl / z / 3\n add += toAdd\n }\n bl -= z * 3\n\n ye -= y\n bl -= y\n if (ye < 0) {\n add -= ye\n }\n if (bl < 0) {\n add -= bl\n }\n\n print(add)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "379876042d83454db88796b623eb2f11", "src_uid": "35202a4601a03d25e18dda1539c5beba", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n\n val alp = arrayOf('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')\n var max = -1\n\n for (c:Char in sc.next()) {\n val n = alp.indexOf(c)\n if (n <= max+1) max = Math.max(max, n)\n else {\n max = -1\n break\n }\n }\n println(if (max==-1) \"NO\" else \"YES\")\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "strings", "implementation"], "code_uid": "b0a28461de8d41345b57bb45a4c80e0f", "src_uid": "c4551f66a781b174f95865fa254ca972", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var next = 'a'\n for (c in readLine()!!)\n when {\n c == next -> next++\n c > next -> return print(\"NO\")\n }\n print(\"YES\")\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "strings", "implementation"], "code_uid": "d95e475afdb49acd18ac3f6f3473f772", "src_uid": "c4551f66a781b174f95865fa254ca972", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n val str = input.next()\n var currentCode: Int = 'a'.toInt()\n var temp: Int = 0\n for(i in 0 until str.length) {\n temp = str[i].toInt()\n if(temp == currentCode)\n currentCode++\n else if(temp > currentCode) {\n println(\"NO\")\n return\n }\n }\n println(\"YES\")\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "strings", "implementation"], "code_uid": "8debb5a84f68abed6aed11ca386cf448", "src_uid": "c4551f66a781b174f95865fa254ca972", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val line = readLine()!!.toCharArray().distinct()\n\n\n (1 until line.size).forEach {\n if (line[it] - line[it - 1] != 1){\n println(\"NO\")\n return\n }\n }\n\n if (line.size > 26 || line.first() != 'a'){\n println(\"NO\")\n return\n }\n\n println(\"YES\")\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "strings", "implementation"], "code_uid": "52851289fec72bdab23e8fbc65638156", "src_uid": "c4551f66a781b174f95865fa254ca972", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation"], "code_uid": "95e71a777d5b27e3dfbe0d5028cd889e", "src_uid": "2ff30d9c4288390fd7b5b37715638ad9", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() {\n\n val map = mapOf(\n '2' to intArrayOf(2),\n '3' to intArrayOf(3),\n '4' to intArrayOf(3,2,2),\n '5' to intArrayOf(5),\n '6' to intArrayOf(5,3),\n '7' to intArrayOf(7),\n '8' to intArrayOf(7,2,2,2),\n '9' to intArrayOf(7,3,3,2)\n )\n\n fun PrintWriter.solve(){\n val n = nextInt()\n var s = next()\n\n var ans = mutableListOf()\n for (c in s){\n if (c in map){\n for (i in map[c]!!)ans.add(i)\n }\n }\n\n ans.sortDescending()\n ans.forEach { print(it)}\n\n }\n\n\n writer.solve()\n writer.flush()\n\n\n}\n\n\nprivate val reader = System.`in`.bufferedReader()\nprivate val writer = PrintWriter(System.out, false)\n\nprivate var tokenizer: StringTokenizer = StringTokenizer(\"\")\n\nprivate fun next(): String {\n while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(reader.readLine())\n return tokenizer.nextToken()\n}\n\nprivate fun nextInt() = next().toInt()\nprivate fun nextLong() = next().toLong()\nprivate fun nextDouble() = next().toDouble()\nprivate fun nextLine() = reader.readLine()\n\n", "lang_cluster": "Kotlin", "tags": ["math", "sortings", "greedy"], "code_uid": "a0c2871f3fcb96867eea8bc2c8b6377c", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val l = r.readLine()!!.toInt()\n //val time = r.readLine()!!.split(\" \").map { it.toInt() }.sorted()\n val str = r.readLine()!!.split(\"\").filter { it.length > 0 }.map {\n when (it) {\n \"0\" -> \"\"\n \"1\" ->\"\"\n \"2\" -> \"2\"\n \"3\" -> \"3\"\n \"4\" -> \"322\"\n \"5\" -> \"5\"\n \"6\" -> \"35\"\n \"7\" -> \"7\"\n \"8\" -> \"2227\"\n else -> \"7332\"\n }\n }.joinToString(\"\").split(\"\").filter { it.length>0 }.sortedDescending()\n println(str.joinToString(\"\"))\n}", "lang_cluster": "Kotlin", "tags": ["math", "sortings", "greedy"], "code_uid": "d4514488b11797816b44f4e120542abd", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val map = mutableMapOf>()\n map['0'] = listOf()\n map['1'] = listOf()\n map['2'] = listOf(2)\n map['3'] = listOf(3)\n map['4'] = listOf(2, 2, 3)\n map['5'] = listOf(5)\n map['6'] = listOf(3, 5)\n map['7'] = listOf(7)\n map['8'] = listOf(2, 2, 2, 7)\n map['9'] = listOf(3, 3, 2, 7)\n val sol = mutableListOf()\n\n readLine()\n val s = readLine()!!\n for (c in s) sol.addAll(map[c]!!)\n sol.sortDescending()\n print(sol.joinToString(\"\"))\n}", "lang_cluster": "Kotlin", "tags": ["math", "sortings", "greedy"], "code_uid": "c08b03f19b80ac6b4d58edc8595a4a6f", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//rextester.com:1.1--codeforces.com:1.0.5-2\nfun main(args:Array){\n val a=readLine()!!.toInt()*2;var b=false\n for(i in 1..Math.sqrt(a.toDouble()).toInt()-1){\n val c=a-i*i-i;val d=Math.sqrt(c.toDouble()).toInt()\n if(d*(d+1)==c)b=true\n }\n print(\"${if(b)\"YES\" else \"NO\"}\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "binary search"], "code_uid": "59c4c49667abbf9561b52e79a1d86264", "src_uid": "245ec0831cd817714a4e5c531bffd099", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() = readLine()!!.let { word ->\n for (i in word.indices) {\n for (j in (i + 1)..word.length) {\n if (\"${word.substring(0, i)}${if (j < word.length) word.substring(j, word.length) else \"\"}\" == \"CODEFORCES\")\n return@let \"YES\"\n }\n }\n return@let \"NO\"\n}.run(::println)\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "f3cff05df7bd0204f04d8f35ea4828a0", "src_uid": "bda4b15827c94b526643dfefc4bc36e7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var s = readLine()!!\n var ok = false\n var n = s.length\n (0..n).forEach {\n i -> (i + 1..s.length).forEach {\n j -> ok = ok.or((s.substring(0, i) + s.substring(j)) == \"CODEFORCES\")\n }\n }\n println(if (ok) \"YES\" else \"NO\")\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "1777489b585bc52281ac86cc4bd236e6", "src_uid": "bda4b15827c94b526643dfefc4bc36e7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var (n, k) = readLine()!!.split(' ').map { s -> s.toLong() }\n val size = (1L shl n.toInt()) - 1\n var l = 1L\n var r = size\n var pos = (l + r) / 2\n while (pos != k) {\n if (k > pos) {\n l = pos\n pos = (pos + r + 1) / 2\n } else {\n r = pos\n pos = (l + pos) / 2\n }\n n--\n }\n println(n)\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "binary search", "implementation", "bitmasks"], "code_uid": "186a6d3ee6fc5481c6c1df52cb3f79cf", "src_uid": "0af400ea8e25b1a36adec4cc08912b71", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var (n, k) = readLine()!!.split(\" \").map(String::toLong)\n var i = 1\n while (k % 2 == 0L) {\n i++\n k /= 2\n }\n println(i)\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "binary search", "implementation", "bitmasks"], "code_uid": "889ac4461a48e7331d1b6e08ec8b3ebd", "src_uid": "0af400ea8e25b1a36adec4cc08912b71", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)){\n val n = nextInt()\n val k = nextLong()\n val arrSize = getArrSize(n.toLong())\n println(findTargetIndex(n.toLong(), arrSize, k - 1)) \n\n}\nfun findTargetIndex(step: Long, size: Long, targetIndex: Long): Long{\n if(size == 1L) {\n return 1L\n }\n val next = size / 2\n \n if(next == targetIndex) {\n return step\n }\n if(targetIndex > next) {\n return findTargetIndex(step - 1, next, targetIndex - next - 1)\n }\n return findTargetIndex(step - 1, next, targetIndex)\n}\n\nfun getArrSize(step: Long): Long { \n if(step <= 1L) {\n return 1\n }\n return (2 * getArrSize(step - 1)) + 1\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "binary search", "implementation", "bitmasks"], "code_uid": "5c9b5798a1b198a3256dd20f13aa9c17", "src_uid": "0af400ea8e25b1a36adec4cc08912b71", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "35f7cfb89fe7b6e5f1d381f19623a3dc", "src_uid": "eb815f35e9f29793a120d120968cfe34", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "43151db11ac9693670cdbde87ff247e8", "src_uid": "eb815f35e9f29793a120d120968cfe34", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "a33bd52f98aba6562a8a5a8ffe39e9ff", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "015cf66f311bebaffaa0151c40d16074", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "a8abf0c779aa5a03bd7f68113e90743b", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "a5ee848941630c9078a51e9d46df6c69", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// needed to check the tutorial: http://codeforces.com/blog/entry/8755\nfun main() {\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 fun mcm(a: Long, b: Long): Long {\n return a * b / gcd(a, b)\n }\n val (x, y, a, b) = readLongs()\n val m = mcm(x, y)\n val start = a / m + if (a % m == 0L) 0 else 1\n val end = b / m\n print(end - start + 1)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "724947484b66ec10cdb9acaf7779ed22", "src_uid": "c7aa8a95d5f8832015853cffa1374c48", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.InputStream\n\nval input = FastScanner()\n\nfun main(args: Array) = input.run {\n val c = nextInt()\n val v0 = nextInt()\n val vMax = nextInt()\n val increase = nextInt()\n val back = nextInt()\n\n var ans = 0\n var n = 0\n var v = v0\n while (n < c) {\n n -= back\n n = n.coerceAtLeast(0)\n n += v\n v += increase\n v = v.coerceAtMost(vMax)\n ans++\n }\n\n println(ans)\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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "be0f14cf69d83e3573922ea405dd8de4", "src_uid": "b743110117ce13e2090367fd038d3b50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "class MisterBReader(val c: Int,\n val v0: Int,\n val v1: Int,\n val a: Int,\n val l: Int\n) {\n var v = v0\n var readedPages = 0\n \n fun getDaysToRead() : Int {\n var days = 1\n readedPages += v\n while(readedPages < c) {\n readedPages -= l\n v = when {\n v >= v1 -> v\n v + a > v1 -> v1\n else -> v + a\n }\n readedPages += v\n days++\n }\n return days\n }\n}\n\n\nfun main(args: Array) {\n val(c, v0, v1, a, l) = readLine()!!.split(' ').map(String::toInt)\n println(MisterBReader(c, v0, v1, a, l).getDaysToRead())\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "77969db0896e2936ca5b991e2f6ecb6e", "src_uid": "b743110117ce13e2090367fd038d3b50", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "76e2088924d29f55af0a47ec816620f3", "src_uid": "075f83248f6d4d012e0ca1547fc67993", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "var _debug = false;\nfun debug(vararg vals: T): Unit {\n if (!_debug) { return }\n for (v in vals) { System.err.print(v); System.err.print(\" \") }\n System.err.println()\n}\n\nval MOD = 998244353\nval MAXN = 5000\n\n//fun getBinomTriangle() : List> {\nfun getBinomTriangle() : Array {\n var p = Array(MAXN+1, { LongArray(MAXN+1) })\n //debug(\"p\", p.size)\n p[0][0] = 1\n for (i in 1..MAXN) {\n p[i][0] = 1\n for (j in 1..i) {\n p[i][j]=(p[i-1][j-1]+p[i-1][j]) % MOD\n }\n }\n return p\n}\n\nfun getFactorialTable() : LongArray {\n var ft = LongArray(MAXN+1)\n ft[0] = 1\n for (i in 1..MAXN) {\n ft[i] = (ft[i-1] * i) % MOD\n }\n return ft\n}\n\nval btr = getBinomTriangle()\nval ft = getFactorialTable()\n\nfun calculateCombinationsOfTwo(x : Int, y : Int) : Long {\n var res = 0L\n\n val the_min = listOf(x,y).min()!!\n for (k in 0..the_min) {\n var summand = ft[k]\n summand = (summand * btr[x][k]) % MOD\n summand = (summand * btr[y][k]) % MOD\n debug(\"kxy\", k, x, y, \"ft\", ft[k], \"btr\", btr[x][k], btr[y][k])\n res = (res + summand) % MOD\n }\n //debug(\"calc\", res)\n return res\n}\n\nfun main(args: Array) {\n if (args.size > 0 && args[0] == \"-d\") {\n _debug = true;\n }\n\n val (a, b, c) = readLine()!!.split(' ').map(String::toInt)\n debug(\"abc\", a, b, c)\n val ab = calculateCombinationsOfTwo(a, b)\n val ac = calculateCombinationsOfTwo(a, c)\n val bc = calculateCombinationsOfTwo(b, c)\n\n debug(\"end\", ab, ac, bc)\n\n var res = ab\n res = (res * bc) % MOD\n res = (res * ac) % MOD\n\n println(res)\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "58332879554f668c0dbe83283786e8a0", "src_uid": "b6dc5533fbf285d5ef4cf60ef6300383", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt(): Int = readLine()!!.toInt()\n\n val k = readInt()\n var l = readInt()\n var count = -1\n while (l > 1)\n if (l % k != 0)\n return print(\"NO\")\n else {\n l /= k\n count++\n }\n println(\"YES\")\n print(count)\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "5478ae6369f1ac31b46a649df5326725", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nval reader = Scanner(System.`in`)\nfun main(args: Array){\n val k = reader.nextBigInteger()\n val l = reader.nextBigInteger()\n\n var i = 0\n var po = k.pow(i)\n\n while (po < l)\n {\n po = k.pow(++i)\n if(po == l)\n {\n println(\"YES\")\n print(i-1)\n return\n }\n }\n\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "a3ff07c1e49c0ae9b91a41395325b728", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n var (maxSections, numNuts, numDivisors, maxNuts) = readInts()\n var numNutsGroups = numNuts / maxNuts + if (numNuts % maxNuts == 0) 0 else 1\n var sol = 0\n while (numNutsGroups > 0 && numDivisors > 0) {\n sol++\n val groupsToPack = min(maxSections, numDivisors + 1)\n numNutsGroups -= groupsToPack\n numDivisors -= (groupsToPack - 1)\n }\n if (numNutsGroups > 0) sol += numNutsGroups\n print(sol)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "bf559041b7b58e92db9a61c29ab84412", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 : Int = ir.nextInt()\n var a : Int = ir.nextInt()\n var b : Int = ir.nextInt()\n val v : Int = ir.nextInt()\n var result = 0\n\n while (a > 0) {\n result++\n val min = Math.min(b, k - 1)\n b -= min\n a -= (min + 1) * v\n }\n\n pw.print(result)\n\n /*val T : Int = ir.nextInt()\n\n for (t in 0 until T) {\n val n : Int = ir.nextInt()\n val a = ir.next().toCharArray()\n var start = 0\n var end = 0\n var count = 0\n\n for (i in 0 until n)\n if (a[i] == 's')\n start = i\n else if (a[i] == 'e')\n end = i\n\n if (end > start) {\n for (i in start..end) {\n if (a[i] == '#')\n break\n else if (a[i] == 'o') {\n var next = true\n for (k in (i + 1)..end)\n if (a[k] == '#') {\n next = false\n break\n }\n if (next)\n break\n }\n }\n } else {\n\n }*/\n\n\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}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "b8f1a881cbb09d6155ed90f3bd614af7", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*;\nimport java.io.*\nimport java.math.*\n\nobject ReadUtils {\n var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\n var st: StringTokenizer? = null\n\n\n fun next(): String {\n while (ReadUtils.st == null || !ReadUtils.st!!.hasMoreElements()) {\n ReadUtils.st = StringTokenizer(readLine())\n }\n\n return st!!.nextToken()\n }\n}\n\nfun nextToken(): String {\n return ReadUtils.next()\n}\n\nfun nextInt(): Int {\n return nextToken().toInt()\n}\n\nfun nextLong(): Long {\n return nextToken().toLong()\n}\n\nfun readField(n: Int): Array {\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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c371ca4716521bde864031c646b8dd19", "src_uid": "2e793c9f476d03e8ba7df262db1c06e4", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) {\n with(Scanner(System.`in`)) {\n val X2 = nextInt()\n val mf = Array(X2 + 1, { 0 })\n\n (2..X2).forEach {\n if (mf[it] == 0) {\n mf[it] = it\n for (j in it..X2 step it) {\n mf[j] = it\n }\n }\n }\n\n val lo = fun(x: Int) = x - mf[x] + 1\n\n var ans = X2\n (lo(X2)..X2).forEach {\n if (mf[it] != it) {\n val c = lo(it)\n if (c >= 3) {\n ans = min(ans, c)\n }\n }\n }\n println(ans)\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "d63e5534a10db50b62b80a364698d7ab", "src_uid": "43ff6a223c68551eff793ba170110438", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val X2 = readLine() ?. toInt() ?: return\n\n val C = 1000000\n val mxp = IntArray(C+5) { -1 }\n for(i in 2 .. C) {\n if(mxp[i] == -1) {\n for(j in i .. C step i) {\n mxp[j] = i\n }\n }\n }\n\n val a = X2 - mxp[X2]\n val b = (X2 - mxp[X2] + 1 .. X2).filter({ mxp[it] != it }).map { it - mxp[it] }.min() ?: return\n println(Math.min(a, b) + 1)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "44d4c02480d9a2aff0cbeea2ca6d7f60", "src_uid": "43ff6a223c68551eff793ba170110438", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) {\n with(Scanner(System.`in`)) {\n val X2 = nextInt()\n val mk = Array(X2 + 1, { true })\n val mf = Array(X2 + 1, { 0 })\n\n (2..X2).forEach {\n if (mk[it]) {\n mf[it] = it\n for (j in (it * 2)..X2 step it) {\n mk[j] = false\n mf[j] = it\n }\n }\n }\n\n val lo = fun(x: Int) = x - mf[x] + 1\n\n var ans = X2\n (lo(X2)..X2).forEach {\n if (!mk[it]) {\n val c = lo(it)\n if (c >= 3) {\n ans = min(ans, c)\n }\n }\n }\n println(ans)\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "4308e2293feb28ef14cf0cb339cf0f3a", "src_uid": "43ff6a223c68551eff793ba170110438", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val n = nextLong()\n val m = nextLong()\n\n fun f(n: Long) = n * (n - 1) / 2\n\n var i = 0L\n while (m > f(i)) i++\n\n if (n <= m * 2) {\n println(\"0 ${n - i}\")\n } else {\n println(\"${n - m * 2} ${n - i}\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "graphs"], "code_uid": "551378e0a8a22ec93035c1d250b1bc99", "src_uid": "daf0dd781bf403f7c1bb668925caa64d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val inp = readLine()!!.split(\" \")\n val n = inp[0].toLong()\n val m = inp[1].toLong()\n var min = n - 2*m\n if (min<0)\n min = 0\n var a = 0L\n for (i in 1..(n.toInt()))\n {\n a = i.toLong()\n if (i.toLong()*(i.toLong()-1L)/2L >= m)\n break\n }\n if (m == 0L)\n a = 0\n val max = n-a\n println(\"$min $max\")\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "graphs"], "code_uid": "2c5457ceed79d7f8ddc45b8cda325d63", "src_uid": "daf0dd781bf403f7c1bb668925caa64d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.sqrt\n\nfun main(args: Array){\n val (n, m) = readLine()!!.split(\" \").map {it.toLong()}\n if( n < m*2)\n print(\"0\")\n else\n print(n-2*m)\n print(\" \")\n print(n-nearest(m))\n}\n\nfun nearest(m: Long): Long{\n if(m==0L)\n return 0\n val temp = sqrt((2*m).toDouble()).toLong()\n for(i in -3..3){\n if(((temp+i)*(temp+i-1) < 2*m) && ((temp+i+1)*(temp+i) >= 2*m)){\n return temp+i+1\n }\n }\n return -1\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "graphs"], "code_uid": "d6e5dcef3313edbb7ed54fc2880b01ef", "src_uid": "daf0dd781bf403f7c1bb668925caa64d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextLong()\n val m = sc.nextLong()\n val min = Math.min(n, m * 2)\n var max = 0L\n if (m != 0L) {\n for (i in 1..n) {\n if (i * (i - 1) / 2 >= m) {\n max = i\n break\n }\n }\n }\n println(\"${n - min} ${n - max}\")\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "graphs"], "code_uid": "06bf5cea1a79e4de5d8b9fc8a9482759", "src_uid": "daf0dd781bf403f7c1bb668925caa64d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy"], "code_uid": "3f5b2feaa886b130044394c3a15b4838", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy"], "code_uid": "7aeb9d3ba76d8953faac246d89e92f3f", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy"], "code_uid": "9cf1ce94b1d853c8e24363ce1ee0ca0f", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args:Array)\n{\n var ins = readLine()!!.split(' ').map(String::toInt).toIntArray()\n var y = ins[1]\n var x = ins[0]\n var ans = \"Yes\"\n if (y == 0) ans = \"No\"\n else if ((y ==1 ) && (x > 0)) ans = \"No\"\n else if (x < (y - 1)) ans = \"No\"\n else if (((x - y) % 2) == 0) ans = \"No\"\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2ca08a8e6908c9831716638d0588f20c", "src_uid": "1527171297a0b9c5adf356a549f313b9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(){\n var (n,a) = readLine()!!.split(' ')\n var a1 = a.toLong()\n var n1 = n.toLong()\n var otv_o:Long=a1-1;\n //println(n1-otv_o)\n if(a1==1L){\n if(n1!=0L){\n println(\"NO\")\n return\n }\n }\n if((n1-otv_o)%2L==0L && n1-otv_o>=0 && a1>=1){\n println(\"YES\")\n return\n }else{\n println(\"NO\")\n return\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d5156ca61f885644eabd257906861d71", "src_uid": "1527171297a0b9c5adf356a549f313b9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (copies, originals) = readInts()\n when {\n originals == 0 -> print(\"No\")\n originals == 1 && copies > 0 -> print(\"No\")\n originals > copies + 1 -> print(\"No\")\n (copies - originals - 1) % 2 == 0 -> print(\"Yes\")\n else -> print(\"No\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a8ea07ba51bbf1746818eef221dd7d39", "src_uid": "1527171297a0b9c5adf356a549f313b9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.InputStream\nimport java.math.BigDecimal\nimport java.math.BigInteger\n\nfun main(args: Array) = input.run {\n val p = nextInt()\n var x = nextInt()\n val y = nextInt()\n var z = x\n while (z >= y) {\n if (ok(z, p)) {\n println(0)\n return\n }\n z -= 50\n }\n\n var ans = 1\n x += 100\n while (true) {\n if (ok(x, p) || x - 50 >= y && ok(x - 50, p)) {\n println(ans)\n return\n }\n x += 100\n ans++\n }\n}\n\nfun ok(s: Int, p: Int): Boolean {\n var i = (s / 50) % 475\n repeat(25) {\n i = (i * 96 + 42) % 475\n if (26 + i == p) {\n return true\n }\n }\n return false\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", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "9109a6f9aebf2d81c65b533c0cf055d7", "src_uid": "c9c22e03c70a94a745b451fc79e112fd", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\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 solve(input, output)\n input.close()\n output.close()\n}\n\nfun winPlaces(s: Int): Set {\n val places = hashSetOf()\n var i = (s / 50) % 475\n for (j in 1..25) {\n i = (i * 96 + 42) % 475\n places.add(26 + i)\n }\n require(places.size == 25)\n return places\n}\n\nfun solve(input: InputReader, output: PrintWriter) {\n val p = input.nextInt()\n val x = input.nextInt()\n val y = input.nextInt()\n\n var losed = x\n while (losed >= y) {\n if (winPlaces(losed).contains(p)) {\n output.print(0)\n return\n }\n losed -= 50\n }\n\n\n var successfulBreaks = 1\n while (true) {\n val noFails = x + successfulBreaks * 100\n val oneFail = x + successfulBreaks * 100 - 50\n if (winPlaces(noFails).contains(p) || winPlaces(oneFail).contains(p)) {\n output.print(successfulBreaks)\n return\n }\n successfulBreaks += 1\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 = Integer.parseInt(next())\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "1dfb9d6d1e576665c3a50c3877c79a19", "src_uid": "c9c22e03c70a94a745b451fc79e112fd", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(vararg args: String) {\n val (n, a, b, c) = readLine()!!.split(' ').map { it.toLong() }\n println(when ((4 - n % 4).toInt()) {\n 1 -> listOf(a, b+c, 3*c).min()\n 2 -> listOf(2*a, b, 2*c).min()\n 3 -> listOf(3*a, a+b, c).min()\n else -> 0\n })\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "76d3dc64f129628e0cf29ca933454698", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n fun readLongs(): List {\n return readLine()!!.split(\" \").map(String::toLong)\n }\n\n val (n, a, b, c) = readLongs()\n when (n % 4) {\n 0L -> print(0)\n 1L -> print(min(3 * a, min(a + b, c)))\n 2L -> print(min(2 * a, min(b, 2*c)))\n 3L -> print(min(a, min(b+c, 3*c)))\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "7edf75aeb6ba560be09959731c6a82c9", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\n\nclass Data {\n private val rd: BufferedReader\n private var tok: StringTokenizer = StringTokenizer(\"\")\n private val wr: PrintWriter\n\n init {\n rd = BufferedReader(InputStreamReader(System.`in`))\n wr = PrintWriter(System.out)\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 {\n return readToken().toInt()\n }\n\n fun writeln(value: T) {\n wr.println(value)\n }\n\n fun close() {\n rd.close()\n wr.close()\n }\n}\n\n/**\n * Solution to problem 740A (Alyona and copybooks)\n * http://codeforces.com/problemset/problem/740/A\n */\nclass Solution {\n val data: Data = Data()\n\n fun solve() {\n val n = data.readInt()\n\n val s = IntArray(4)\n s[0] = 0\n s[1] = data.readInt()\n s[2] = data.readInt()\n s[3] = data.readInt()\n\n val d = s.copyOf()\n\n var relaxing = true\n while (relaxing) {\n relaxing = false\n for (i in 0 .. d.size - 1) {\n for (j in 1 .. s.size - 1) {\n val k = (i + j) % 4\n if (d[k] > d[i] + s[j]) {\n d[k] = d[i] + s[j]\n relaxing = true\n }\n }\n }\n }\n\n data.writeln(d[(4 - (n % 4)) % 4])\n data.close()\n }\n}\n\nfun main(args: Array) {\n Solution().solve()\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "18aabe230a144601b0179e0c99ccb870", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 p=Array(5){0}\n var e=0\n var f=0\n for(i in 0..4){\n p[i]=reader.nextInt()\n e+=p[i]\n }\n p.sort()\n var d=1\n var i=1\n for(i in 1..4){\n if(p[i]==p[i-1]){\n d++\n }\n else{\n if(d==2){\n f=max(p[i-1]*d,f)\n }\n if(d>2){\n f=max(p[i-1]*3,f)\n }\n d=1\n }\n }\n if(d==2){\n f=max(p[4]*d,f)\n }\n if(d>2){\n f=max(p[4]*3,f)\n }\n print(e-f)\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation"], "code_uid": "d2b87ed066f00829ce6b3c7f7b52ead9", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\nfun main() {\n var sc = Scanner(System.`in`)\n var list = ArrayList()\n list.add(sc.nextInt())\n list.add(sc.nextInt())\n list.add(sc.nextInt())\n list.add(sc.nextInt())\n list.add(sc.nextInt())\n\n Collections.sort(list)\n\n var array = Array(102,{0})\n\n var i = 0\n while (imax){\n max = two\n }\n }else if (array[j]>=3){\n flag = true\n two+=3*j\n if (two>max){\n max = two\n }\n }\n j++\n }\n\n\n if (flag){\n println(list.sum()-max)\n }else{\n println(list.sum())\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation"], "code_uid": "a84eebeae1435a6e785c45b955d0ee7c", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val results = mutableSetOf()\n for (n in 1..35)\n results.add(n * (n + 1) / 2)\n print(if (readLine()!!.toInt() in results) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "ce5c9401b380d41961ae05542e2e87da", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readStrings() = readLn().split(\" \")\nfun readInts() = readStrings().map { it.toInt() }\n\nfun main(args: Array) {\n var a = listOf(1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210, 231, 253, 276, 300, 325, 351, 378, 406, 435, 465, 496, 528)\n var n = readInt().apply {\n if (this in a) print(\"YES\") else print(\"NO\")\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "726d3a08cbb0fe3ffddde1c24ba0d80c", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//n(n+1)/2\n\nfun solve()\n{\n var n:Int\n n=readLine()!!.toInt()\n for( i in 1..500)\n {\n var h=((i*(i+1))/2)\n if(h==n)\n {\n print(\"YES\")\n return\n }\n\n }\n print(\"NO\")\n}\nfun main()\n{\n solve()\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "ccc854588e41f1757aa40818a63611d9", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.ceil\nimport kotlin.math.floor\nimport kotlin.math.sqrt\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 main() {\n val a = readInt().toDouble()\n val n = (-1 + sqrt(1+8*a))/2\n if (ceil(n) == floor(n))\n print(\"YES\")\n else\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "24a08e3d1812e509f705539f1433405c", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun lastDigitInFactorialZone(lower: Long, upper:Long) : Long {\n var ret = 1L;\n for (i in (lower+1)..upper) {\n ret = (ret * i) % 10\n\n if (ret == 0L) break;\n }\n return ret\n}\n\nfun main(args: Array) {\n val (a, b) = readLine()!!.split(' ').map(String::toLong)\n\n val ret = lastDigitInFactorialZone(a, b)\n \n val retStr = ret.toString()\n println(retStr.last())\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "b0060449b79788841d5264137e930898", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val a = sc.nextLong()\n val b = sc.nextLong()\n\n print(solve(a, b))\n}\n\nfun solve(a: Long, b: Long): Int {\n if(a == 0L && b == 0L) return 1\n if(a == b) return 1\n\n var res = b % 10\n\n for(i in b - 1 downTo a + 1) {\n res = (res * (i % 10)) % 10\n if(res % 10 == 0L) return 0\n }\n return res.toInt()\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "6da4d8a20d577c51d900724609724687", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n val (a, b) = readLongs()\n if (a == b) return print(1)\n if (b - a >= 10) return print(0)\n if (a % 10 > b % 10) return print(0)\n var sol = 1L\n for (d in b % 10 downTo a % 10 + 1) sol *= d\n print(sol % 10)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "bc7b55d487279daf16ed8b72a47d83ce", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val a = scanner.nextLong()\n val b = scanner.nextLong()\n\n val res = if (a) {\n val (n, m) = readLine()!!.splitToIntArray()\n val a = readLine()!!.processPairs()\n val b = readLine()!!.processPairs()\n val cand = HashSet()\n var unique = true\n for (i in 1..9) {\n for (ac in a[i]) {\n for (bc in b[i]) {\n if (ac != bc) {\n cand.add(i)\n if (!findsOne(i, ac, b) || !findsOne(i, bc, a)) {\n unique = false\n }\n }\n }\n }\n }\n if (cand.size == 1) {\n println(cand.single())\n return\n }\n if (unique) {\n println(0)\n } else {\n println(-1)\n }\n}\n\nfun findsOne(i: Int, j: Int, b: Array>): Boolean {\n val jc = b[j]\n return jc.isEmpty() || jc.size == 1 && jc.single() == i\n}\n\n\nfun String.processPairs(): Array> {\n val a = splitToIntArray()\n val r = Array>(10) { HashSet() }\n for (i in 0 until a.size step 2) {\n val u = a[i]\n val v = a[i + 1]\n r[u].add(v)\n r[v].add(u)\n }\n return r\n}\n\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "bitmasks"], "code_uid": "09f138e648baddaf58689fa7c652335a", "src_uid": "cb4de190ae26127df6eeb7a1a1db8a6d", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashSet\n\ndata class Pair ( val a: Int, val b: Int ) {\n fun inter( p: Pair ): ArrayList {\n val r = ArrayList()\n if ( a == p.a || a == p.b ) {\n r.add( a )\n }\n if ( b == p.a || b == p.b ) {\n r.add( b )\n }\n return r\n }\n\n constructor( sc: Scanner ) : this( sc.nextInt(), sc.nextInt() )\n}\n\nfun main( args: Array ) {\n val sc = Scanner( System.`in` )\n val m = sc.nextInt()\n val n = sc.nextInt()\n val p = Array( m, { Pair( sc ) } )\n val q = Array( n, { Pair( sc ) } )\n run {\n val oneInter = HashSet()\n for ( pp in p ) {\n for ( qq in q ) {\n val inter = pp.inter( qq )\n if ( inter.size == 1 ) oneInter.add( inter.first() )\n }\n }\n if ( oneInter.size == 1 ) {\n println( oneInter.first() )\n return\n }\n }\n var ok = true\n for ( pp in p ) {\n val oneInter = HashSet()\n for ( qq in q ) {\n val inter = pp.inter( qq )\n if ( inter.size == 1 ) oneInter.add( inter.first() )\n }\n if ( oneInter.size > 1 ) {\n println( -1 )\n return\n }\n }\n for ( qq in q ) {\n val oneInter = HashSet()\n for ( pp in p ) {\n val inter = pp.inter( qq )\n if ( inter.size == 1 ) oneInter.add( inter.first() )\n }\n if ( oneInter.size > 1 ) {\n println( -1 )\n return\n }\n }\n println( 0 )\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "bitmasks"], "code_uid": "e76bf2b1f27e4e9e18f289ce20b3c8f8", "src_uid": "cb4de190ae26127df6eeb7a1a1db8a6d", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.ArrayDeque\nimport java.util.Deque\nimport java.util.StringTokenizer\n\nfun main() {\n val n = readInt()\n val m = readInt()\n val a = readInt()\n val b = readInt()\n var h = readInt()\n val x = readInt()\n val y = readInt()\n val z = readInt()\n\n val cWindows = Array(m-b+1) { Window(a) }\n var ans = 0L\n\n for(i in 0 until n) {\n val rWindow = Window(b)\n for(j in 0 until m) {\n rWindow.add(h)\n val l = j+1-b\n if(l >= 0) {\n cWindows[l].add(rWindow.min)\n if(i+1-a >= 0) ans += cWindows[l].min\n }\n h = (h.toLong() * x + y).rem(z).toInt()\n }\n }\n\n println(ans)\n}\n\nclass Window(len: Int) {\n private val eleQ = IntBuffer(len)\n private val minQ = IntBuffer(len)\n\n fun add(item: Int) {\n if(eleQ.isFull && eleQ.removeFirst() == minQ.first) minQ.removeFirst()\n eleQ.addLast(item)\n while(minQ.size != 0 && minQ.last > item) minQ.removeLast()\n minQ.addLast(item)\n }\n\n val min: Int get() = minQ.first\n}\n\n@Suppress(\"UNCHECKED_CAST\")\nclass IntBuffer(val capacity: Int) {\n private val arr = IntArray(capacity)\n var size = 0\n private set\n\n val isFull get() = size == capacity\n private var head = 0\n\n private fun incHead() {\n head++\n if(head == capacity) head = 0\n }\n\n private fun decHead() {\n if(head == 0) head = capacity - 1\n else head--\n }\n\n private fun index(i: Int) = (head + i).let { if(it >= capacity) it - capacity else it }\n\n fun addLast(e: Int) {\n if(isFull) return\n arr[index(size)] = e\n size++\n }\n\n fun removeFirst(): Int {\n val e = get(0)\n incHead()\n size--\n return e\n }\n fun removeLast(): Int {\n val e = get(size-1)\n size--\n return e\n }\n\n fun addFirst(e: Int) {\n if(isFull) return\n decHead()\n arr[head] = e\n size++\n }\n\n fun get(index: Int): Int = arr[index(index)]\n val first get() = get(0)\n val last get() = get(size-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 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", "lang_cluster": "Kotlin", "tags": ["two pointers", "data structures"], "code_uid": "6e6657f732c2fdeab30a27a236f3a836", "src_uid": "4618fbffb2b9d321a6d22c11590a4773", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.ArrayDeque\nimport java.util.Deque\nimport java.util.StringTokenizer\n\nfun main() {\n val n = readInt()\n val m = readInt()\n val a = readInt()\n val b = readInt()\n var h = readInt()\n val x = readInt()\n val y = readInt()\n val z = readInt()\n\n val cWindows = Array(m-b+1) { Window(a) }\n var ans = 0L\n\n for(i in 0 until n) {\n val rWindow = Window(b)\n val tg = i+1-a >= 0\n for(j in 0 until m) {\n rWindow.add(h)\n val l = j+1-b\n if(l >= 0) {\n val cw = cWindows[l]\n cw.add(rWindow.min)\n if(tg) ans += cw.min\n }\n h = (h.toLong() * x + y).rem(z).toInt()\n }\n }\n\n println(ans)\n}\n\nclass Window(len: Int) {\n private val eleQ = IntBuffer(len)\n private val minQ = IntBuffer(len)\n\n fun add(item: Int) {\n if(eleQ.isFull && eleQ.removeFirst() == minQ.first) minQ.removeFirst()\n eleQ.addLast(item)\n while(minQ.size != 0 && minQ.last > item) minQ.removeLast()\n minQ.addLast(item)\n }\n\n val min: Int get() = minQ.first\n}\n\n@Suppress(\"UNCHECKED_CAST\")\nclass IntBuffer(val capacity: Int) {\n private val arr = IntArray(capacity)\n var size = 0\n private set\n\n val isFull get() = size == capacity\n private var head = 0\n\n private fun incHead() {\n head++\n if(head == capacity) head = 0\n }\n\n private fun decHead() {\n if(head == 0) head = capacity - 1\n else head--\n }\n\n private fun index(i: Int) = (head + i).let { if(it >= capacity) it - capacity else it }\n\n fun addLast(e: Int) {\n if(isFull) return\n arr[index(size)] = e\n size++\n }\n\n fun removeFirst(): Int {\n val e = get(0)\n incHead()\n size--\n return e\n }\n fun removeLast(): Int {\n val e = get(size-1)\n size--\n return e\n }\n\n fun addFirst(e: Int) {\n if(isFull) return\n decHead()\n arr[head] = e\n size++\n }\n\n fun get(index: Int): Int = arr[index(index)]\n val first get() = get(0)\n val last get() = get(size-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 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", "lang_cluster": "Kotlin", "tags": ["two pointers", "data structures"], "code_uid": "2eed592863bd1d876897424d73a21d66", "src_uid": "4618fbffb2b9d321a6d22c11590a4773", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.min\n\nfun main() {\n val jin = Scanner(System.`in`)\n val n = jin.nextInt()\n val m = jin.nextInt()\n val a = jin.nextInt()\n val b = jin.nextInt()\n var g = jin.nextLong()\n val x = jin.nextLong()\n val y = jin.nextLong()\n val z = jin.nextLong()\n val map = Array(n) { LongArray(m) {\n val res = g\n g = ((g * x) + y) % z\n res\n }}\n val mins = Array(n) { LongArray(m) }\n for (i in 0 until n) {\n val queue = LinkedList()\n for (j in 0 until b) {\n while (!queue.isEmpty() && map[i][queue.last] >= map[i][j]) {\n queue.removeLast()\n }\n queue.add(j)\n }\n for (j in 0..m - b) {\n if (queue.first < j) {\n queue.remove()\n }\n mins[i][j] = map[i][queue.first]\n if (j + b < m) {\n while (!queue.isEmpty() && map[i][queue.last] >= map[i][j + b]) {\n queue.removeLast()\n }\n queue.add(j + b)\n }\n }\n }\n var answer: Long = 0\n for (j in 0 until m) {\n val queue = LinkedList()\n for (i in 0 until a) {\n while (!queue.isEmpty() && mins[queue.last][j] >= mins[i][j]) {\n queue.removeLast()\n }\n queue.add(i)\n }\n for (i in 0..n - a) {\n if (queue.first < i) {\n queue.remove()\n }\n answer += mins[queue.first][j]\n if (i + a < n) {\n while (!queue.isEmpty() && mins[queue.last][j] >= mins[i + a][j]) {\n queue.removeLast()\n }\n queue.add(i + a)\n }\n }\n }\n println(answer)\n}", "lang_cluster": "Kotlin", "tags": ["two pointers", "data structures"], "code_uid": "6ef0a240175bf6c02f8e22c14abc8d1c", "src_uid": "4618fbffb2b9d321a6d22c11590a4773", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.ArrayDeque\nimport java.util.Deque\nimport java.util.StringTokenizer\n\nfun main() {\n val n = read().toInt()\n val m = read().toInt()\n val a = read().toInt()\n val b = read().toInt()\n var h = read().toInt()\n val x = read().toInt()\n val y = read().toInt()\n val z = read().toInt()\n\n val cWindows = Array(m-b+1) { Window(a) }\n var ans = 0L\n\n for(i in 0 until n) {\n val rWindow = Window(b)\n val tg = i+1-a >= 0\n for(j in 0 until m) {\n rWindow.add(h)\n val l = j+1-b\n if(l >= 0) {\n val cw = cWindows[l]\n cw.add(rWindow.min)\n if(tg) ans += cw.min\n }\n h = (h.toLong() * x + y).rem(z).toInt()\n }\n }\n\n println(ans)\n}\n\nclass Window(@JvmField val len: Int) {\n @JvmField val eleQ = IntBuffer(len)\n @JvmField val minQ = IntBuffer(len)\n\n inline fun add(item: Int) {\n if(eleQ.isFull && eleQ.removeFirst() == minQ.first) minQ.removeFirst()\n eleQ.addLast(item)\n while(minQ.size != 0 && minQ.last > item) minQ.removeLast()\n minQ.addLast(item)\n }\n\n inline val min: Int get() = minQ.first\n}\n\n@Suppress(\"UNCHECKED_CAST\")\nclass IntBuffer(val capacity: Int) {\n private val arr = IntArray(capacity)\n @JvmField var size = 0\n\n val isFull get() = size == capacity\n private var head = 0\n\n private fun incHead() {\n head++\n if(head == capacity) head = 0\n }\n\n private fun decHead() {\n if(head == 0) head = capacity - 1\n else head--\n }\n\n private fun index(i: Int) = (head + i).let { if(it >= capacity) it - capacity else it }\n\n fun addLast(e: Int) {\n if(isFull) return\n arr[index(size)] = e\n size++\n }\n\n fun removeFirst(): Int {\n val e = get(0)\n incHead()\n size--\n return e\n }\n fun removeLast(): Int {\n val e = get(size-1)\n size--\n return e\n }\n\n fun addFirst(e: Int) {\n if(isFull) return\n decHead()\n arr[head] = e\n size++\n }\n\n fun get(index: Int): Int = arr[index(index)]\n val first get() = get(0)\n val last get() = get(size-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 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", "lang_cluster": "Kotlin", "tags": ["two pointers", "data structures"], "code_uid": "016baf43ec8c11f861a8f2de7ab20c9b", "src_uid": "4618fbffb2b9d321a6d22c11590a4773", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.*\n\nfun main(vararg args:String) {\n val input = Scanner(System.`in`)\n val n = input.nextInt()\n val l = input.nextInt()\n var a = ArrayList()\n for (i in 0..n - 1)\n a.add(input.nextInt())\n var b = ArrayList()\n for (i in 0..n - 1)\n b.add(input.nextInt())\n var count = 0\n var flag = (0..n - 1).none { a[it] != b[it] }\n if (flag) {\n println(\"YES\")\n return\n }\n if (b[0] == 0) {\n b.remove(0)\n b.add(l)\n count++\n println()\n }\n while (count <= n) {\n flag = true\n for (i in 0..n - 1) {\n b[i]--\n if (a[i] != b[i])\n flag = false\n }\n if (flag) {\n println(\"YES\")\n return\n }\n if (b[0] == 0) {\n b.remove(0)\n b.add(l)\n count++\n }\n }\n println(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "4015b391e425f584001cb061df43fda9", "src_uid": "3d931684ca11fe6141c6461e85d91d63", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import 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 List.sliding(windowSize: Int): List> {\n return this.dropLast(windowSize - 1).mapIndexed { i, s -> this.subList(i, i + windowSize) }\n}\n\nprivate fun solve(scanner: Scanner, out: PrintWriter) {\n val n = scanner.nextInt()\n val L = scanner.nextInt()\n scanner.nextLine()\n val kef = scanner.nextLine().split(\" \").map(String::toInt)\n val sash = scanner.nextLine().split(\" \").map(String::toInt)\n\n var m = kef.sliding(2).map { it[1] - it[0] }.toMutableList()\n var r = sash.sliding(2).map { it[1] - it[0] }.toMutableList()\n val kefDiffs = m + (L - m.sum())\n val sashDiffs = r + (L - r.sum())\n\n val s = kefDiffs.joinToString(transform = Int::toString, separator = \"\")\n val res = (s + s).contains(sashDiffs.joinToString(transform = Int::toString, separator = \"\"))\n\n if (res) {\n out.println(\"YES\")\n } else {\n out.println(\"NO\")\n }\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "3d10cb4dd59cc49c46c9a098bccc82d2", "src_uid": "3d931684ca11fe6141c6461e85d91d63", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n val count = input.nextInt()\n val length = input.nextInt()\n\n val array = Array(count){0}\n for(i in 0 until count)\n array[i] = input.nextInt()\n\n val array2 = Array(count){0}\n for(i in 0 until count)\n array2[i] = input.nextInt()\n\n for(i in 0 until length) {\n for(j in 0 until array.size) {\n if(array[j] > 0) array[j]--\n else if(array[j] == 0) array[j] = length - 1\n }\n if(equals(array, array2)) {\n print(\"YES\")\n return\n }\n }\n print(\"NO\")\n}\n\n\nfun equals(array: Array, array2: Array): Boolean {\n for(i in 0 until array.size) {\n if(!array.contains(array2[i])) {\n return false\n }\n }\n return true\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "f4ab3e1c13b7c34679b4936543d9b641", "src_uid": "3d931684ca11fe6141c6461e85d91d63", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (n, l) = readInts()\n val aes = readInts()\n val bs = readInts()\n val aDeltas = IntArray(n)\n val bDeltas = IntArray(n)\n for (pos in 0 until n - 1) {\n aDeltas[pos] = aes[pos + 1] - aes[pos]\n bDeltas[pos] = bs[pos + 1] - bs[pos]\n }\n aDeltas[n - 1] = l - aes.last() + aes.first()\n bDeltas[n - 1] = l - bs.last() + bs.first()\n loop@ for (start in 0 until n) {\n for (pos in 0 until n) {\n if (aDeltas[pos] != bDeltas[(start + pos) % n]) continue@loop\n }\n print(\"YES\")\n return\n }\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "525235d593e92bb2e8d7ed93e2d8c5d4", "src_uid": "3d931684ca11fe6141c6461e85d91d63", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n var n = readLine()!!\n\n println((n.length+1)*25+1)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "strings"], "code_uid": "d732725e5fe445e0bef65c6cb85492ce", "src_uid": "556684d96d78264ad07c0cdd3b784bc9", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 main(args: Array) {\n val s = readLn()\n\n val all = mutableSetOf()\n\n for (i in 0 until s.length + 1) {\n for(ch in 'a'..'z') {\n val other = s.substring(0, i) + ch + s.substring(i)\n all.add(other)\n }\n }\n\n println(all.size)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "strings"], "code_uid": "4fa376985a1c09d22ac7840b49f5bb66", "src_uid": "556684d96d78264ad07c0cdd3b784bc9", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val l = readLine()!!.length\n print(26 * (l + 1) - l)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "strings"], "code_uid": "3e4d7dfca7d93c6cb351b237caca7f4e", "src_uid": "556684d96d78264ad07c0cdd3b784bc9", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main(args: Array) {\n var N = readLine()!!.toInt()\n var z = \"\"\n repeat(N) {\n val X = readLine()!!\n z += when (X) {\n \"1 0 0 1 0\" -> 'a'\n \"1 1 0 2 0\" -> 'b'\n \"2 0 0 1 1\" -> 'c'\n \"2 1 0 1 2\" -> 'd'\n \"1 1 0 1 1\" -> 'e'\n \"2 1 0 2 1\" -> 'f'\n \"2 2 0 2 2\" -> 'g'\n \"1 2 0 2 1\" -> 'h'\n \"1 1 0 1 1\" -> 'i'\n \"1 2 0 1 2\" -> 'j'\n \"1 0 1 2 0\" -> 'k'\n \"1 1 1 3 0\" -> 'l'\n \"2 0 1 2 1\" -> 'm'\n \"2 1 1 2 2\" -> 'n'\n \"1 1 1 2 1\" -> 'o'\n \"2 1 1 3 1\" -> 'p'\n \"2 2 1 3 2\" -> 'q'\n \"1 2 1 3 1\" -> 'r'\n \"1 1 1 2 1\" -> 's'\n \"1 2 1 2 2\" -> 't'\n \"1 0 2 2 1\" -> 'u'\n \"1 1 2 3 1\" -> 'v'\n \"2 0 2 2 2\" -> 'x'\n \"2 1 2 2 3\" -> 'y'\n \"1 1 2 2 2\" -> 'z'\n \"1 2 1 1 3\" -> 'w'\n else -> error(\"foo $X\")\n }\n }\n println(z)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5e32ceae96dc66a9bb4b1f03b27ec0a7", "src_uid": "a3603f5ed0d8bdb7fe829342991b78e6", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "\nimport java.io.BufferedInputStream\nimport java.io.File\nimport java.io.PrintWriter\nimport kotlin.math.ln\nimport kotlin.system.measureTimeMillis\n\ninline fun TIME(f:()->Unit){\n val t = measureTimeMillis(){\n f()\n }\n println(\"$t ms\")\n}\n\nobject IO{\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(\"You forgot to disable tests you digital dummy!\")\n println(\"You forgot to disable tests you digital dummy!\")\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){ IO.OUT.println(aa)}\nfun done(){ IO.OUT.close() }\nfun share(aa:Any){\n if(aa is IntArray){IO.fakein.append(aa.joinToString(\" \"))}\n else if(aa is LongArray){IO.fakein.append(aa.joinToString(\" \"))}\n else if(aa is List<*>){IO.fakein.append(aa.toString())}\n else{IO.fakein.append(aa.toString())}\n IO.fakein.append(\"\\n\")\n}\n\nval getint:Int get() = IO.nextInt()\nval getlong:Long get() = IO.nextLong()\nval getstr:String get() = IO.nextString()\nfun getline(n:Int):IntArray{\n return IntArray(n){getint}\n}\nfun getlineL(n:Int):LongArray{\n return LongArray(n){getlong}\n}\nfun getbinary(n:Int):BooleanArray{\n val str = getstr\n return BooleanArray(n){str[it] == '1'}\n}\n\nval List.ret:String\nget() = this.joinToString(\"\")\ninfix fun Any.dei(a:Any){\n //does not stand for anything it is just easy to type, have to be infix because kotlin does not have custom prefix operators\n var str = \"\"\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 }\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{ println(\"$str : $a\")\n }\n}\nval just = \" \" // usage: just dei x , where x is the debug variable\nfun crash(){throw Exception(\"Bad programme\")} // because assertion does not work\nfun assert(a:Boolean){\n if(!a){throw Exception(\"Failed Assertion\")\n }}\nenum class solveMode {\n real, rand, tc\n}\nconst val withBruteForce = false\nconst val randCount = 100\nobject solve{\n var mode:solveMode = solveMode.real\n var tcNum:Int = 0\n var rand:()->Unit = {}\n var TC:MutableMapUnit> = mutableMapOf()\n var answersChecked = 0\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 //safety checks\n if(pI != 998_244_353 && pI != 1_000_000_007){\n throw Exception(\"Modding a wrong prime!\")\n }\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 IO.rerouteInput()\n }else if(mode == solveMode.rand){\n rand()\n IO.rerouteInput()\n }\n currentAnswer = null\n currentBruteAnswer = null\n onecase()\n }\n if(withBruteForce){\n put(\"Checked ${answersChecked}\")\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 inline fun brute(a:()->Unit){\n if(withBruteForce){\n a()\n }\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\n\n var currentAnswer:String? = null\n var currentBruteAnswer:String? = null\n fun answer(a:Any){\n currentAnswer = a.toString()\n if(currentBruteAnswer != null){\n checkAnswer()\n }\n }\n fun put2(a:Any){answer(a);put(a) }\n\n fun bruteAnswer(a:Any){\n currentBruteAnswer = a.toString()\n if(currentAnswer != null){\n checkAnswer()\n }\n }\n fun checkAnswer(){\n if(currentAnswer != currentBruteAnswer){\n throw Exception(\"Failed Test: BF $currentBruteAnswer Current $currentAnswer\")\n }\n answersChecked ++\n }\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 * 1L * b) % pI).toInt() }\ninfix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }\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\n\ninfix fun Int.divCeil(b:Int):Int{\n //Positives numbers only!\n if(this == 0) {\n return 0\n }\n return (this-1)/b + 1\n}\ninfix fun Long.divCeil(b:Long):Long{\n //Positives numbers only!\n if(this == 0L) {\n return 0\n }\n return (this-1)/b + 1\n}\n\ninfix fun Long.modM(b:Long):Long{\n return (this * b) % p\n}\n//infix fun Int.modPlus(b:Int):Int{\n// val ans = this + b\n// return if(ans >= pI) ans - pI else ans\n//}\ninfix fun Int.modMinus(b:Int):Int{\n val ans = this - b\n return if(ans < 0) ans + pI else ans\n}\ninfix fun Int.modDivide(b:Int):Int{\n return this modM (b.inverse())\n}\nfun Int.additiveInverse():Int{\n return if(this == 0) 0 else pI - this\n}\n\n\nfun intPow(x:Int,e:Int,m:Int):Int{\n var X = x\n var E =e\n var Y = 1\n while(E > 0){\n if(E % 2 == 0){\n X = ((1L * X * X) % m).toInt()\n E /= 2\n }else{\n Y = ((1L * X * Y) % m).toInt()\n E -= 1\n }\n }\n return Y\n}\n\nfun pow(x:Long,e:Long,m:Long):Long{\n var X = x\n var E =e\n var Y = 1L\n while(E > 0){\n if(E % 2 == 0L){\n X = (X * X) % m\n E /= 2\n }else{\n Y = (X * Y) % m\n E -= 1\n }\n }\n return Y\n}\nfun Long.inverse():Long{\n return pow(this,p-2,p)\n}\nfun Int.inverse():Int{\n return intPow(this,pI-2,pI)\n}\n//make this int instead\nclass FACT{\n companion object {\n var store = IntArray(0)\n var invStore = IntArray(0)\n\n var slowStore:IntArray = IntArray(0)\n\n fun preCal(upto:Int){\n store = IntArray(upto+1)\n invStore = IntArray(upto + 1 )\n store[0] = 1\n invStore[0] = 1\n\n for(i in 1..upto) {\n store[i] = store[i-1] modM i\n invStore[i] = invStore[i-1] modM (i.inverse())\n }\n }\n fun choose(n:Int,r:Int):Int{\n if(r < 0 || r > n) return 0\n val a = store[n]\n val b = invStore[n-r]\n val c = invStore[r]\n return (a modM b) modM c\n }\n\n fun bigChoose(n:Int,r:Int):Int{\n var ret = 1\n for(i in 0 until r){\n ret = ret modM (n - i)\n }\n ret = ret modM (invStore[r])\n return ret\n }\n\n }\n}\n\nclass FFT {\n companion object{\n // val fftmod = 7340033\n// val root = 5\n// val root_1 = 4404020\n// val root_pw = 1 shl 20\n private const val fftmod = 998244353\n private const val root = 15311432\n private const val root_1 = 469870224\n private const val root_pw = 1 shl 23\n\n fun calculateRoot(){\n println(\"root :$root\")\n // intPow(3,7 * 17,fftmod)\n println(\"root_1 : $root_1\")\n // intPow(root,fftmod -2,fftmod)\n }\n\n fun fft(a:IntArray,invert:Boolean){\n val n = a.size\n var j = 0\n\n\n for(i in 1 until n){\n var bit = n shr 1\n while(j and bit > 0){\n j = j xor bit\n bit = bit shr 1\n }\n j = j xor bit\n if(i < j){\n val temp = a[i]\n a[i] = a[j]\n a[j] = temp\n }\n }\n var len = 2\n while(len <= n){\n var wlen = if(invert) root_1 else root\n var i = len\n while(i < root_pw){\n wlen = (1L * wlen * wlen % fftmod).toInt()\n i = i shl 1\n }\n i = 0\n while(i < n){\n var w = 1\n for(j in 0 until len/2){\n val u = a[i+j]\n val v = (1L * a[i+j+len/2] * w % fftmod).toInt()\n a[i+j] = if(u+v < fftmod) u + v else u + v - fftmod\n a[i+j+len/2] = if(u-v >= 0) u-v else u-v+fftmod\n w = (1L * w * wlen % fftmod).toInt()\n }\n i += len\n }\n len = len shl 1\n }\n if(invert){\n val n_1 = pow(n.toLong(),(fftmod-2).toLong(),fftmod.toLong())\n for((i,x) in a.withIndex()){\n a[i] = (1L * x * n_1 % fftmod).toInt()\n }\n }\n }\n fun fullconvolution(at:IntArray,bt:IntArray):IntArray{\n return fullconvolutionOpt(at,bt,at.size,bt.size)\n }\n\n fun fullconvolutionOpt(at:IntArray,bt:IntArray,sizeA:Int,sizeB:Int):IntArray{\n // 1 shl 18 done in 77 ms\n val maxSize = (sizeA + sizeB).takeHighestOneBit() * 2\n val a = at.copyOf(maxSize)\n val b = bt.copyOf(maxSize)\n val expectedSize = at.size + bt.size - 1\n fft(a,false)\n fft(b,false)\n val new = IntArray(maxSize)\n for(i in new.indices){\n new[i] = (1L * a[i] * b[i] % fftmod).toInt()\n }\n fft(new,true)\n return new.copyOf(expectedSize)\n }\n }\n}\n\nfun stir(l:Int, r:Int):IntArray{\n if(l == r){\n return intArrayOf(l,1)\n }else{\n val mid = (l+r) shr 1\n return FFT.fullconvolution(stir(l,mid), stir(mid+1,r))\n }\n}\n\n\n\nobject sieve{\n\n const val sieveMx = 200005\n val primeOf = IntArray(sieveMx + 1)\n var primeCounter = 0\n val primeUpperBound = maxOf(25,(sieveMx.toDouble()/(ln(sieveMx.toDouble()) -4)).toInt() +3)\n val primes = IntArray(primeUpperBound)\n var sieveCalculated = false\n val nextPrime = IntArray(sieveMx+1)\n val nextPrimePower = IntArray(sieveMx+1)\n val afterPrimePowerDivison = IntArray(sieveMx+1)\n var mobius = IntArray(0)\n\n var factors:List> = mutableListOf()\n\n fun calculateSieveFast(){\n if(sieveCalculated){\n return\n }\n sieveCalculated = true\n for(i in 2..sieveMx){\n if(primeOf[i] == 0 ){\n primeOf[i] = i\n primes[primeCounter] = i\n primeCounter += 1\n }\n for(j in 0 until primeCounter){\n val p = primes[j]\n val pd = p * i\n if(p <= i && pd <= sieveMx){\n primeOf[pd] = p\n }else{\n break\n }\n }\n }\n }\n fun preparePrimePower(){\n nextPrime[1] = -1\n nextPrimePower[1] = -1\n afterPrimePowerDivison[1] = 1\n for(i in 2..sieveMx){\n val p = primeOf[i]\n val new = i / p\n nextPrime[i] = p\n if(nextPrime[new] == p){\n nextPrimePower[i] = nextPrimePower[new]\n afterPrimePowerDivison[i] = afterPrimePowerDivison[new]\n }else{\n afterPrimePowerDivison[i] = new\n }\n nextPrimePower[i] += 1\n }\n }\n fun prepareFactors(){\n // 700ms in 1M\n // shoudl not be used for 1M\n // 200ms codeforces for 200k\n factors = List(sieveMx + 1){ mutableListOf()}\n factors[1].add(1)\n\n for(i in 2..sieveMx){\n val p = nextPrime[i]\n val a = nextPrimePower[i]\n val old = afterPrimePowerDivison[i]\n\n var here = 1\n repeat(a+1){\n for(c in factors[old]){\n factors[i].add(c * here )\n }\n here *= p\n }\n// factors[1].ad\n// factors[i].addAll(i.factors())\n }\n }\n fun calculateMobius(){\n kotlin.assert(sieveCalculated)\n mobius = IntArray(sieveMx + 1)\n mobius[1] = 1\n for(i in 2..sieveMx){\n val p = primeOf[i]\n if(p == primeOf[i/p]){\n mobius[i] = 0\n }else{\n mobius[i] = -1 * mobius[i/p]\n }\n }\n }\n}\ninline fun Int.eachPrimePower(act:(Int,Int)->Unit){\n var here = this\n while(here > 1){\n act(sieve.nextPrime[here], sieve.nextPrimePower[here])\n here = sieve.afterPrimePowerDivison[here]\n }\n}\nfun GS(start:Int,ratio:Int,count:Int) = sequence {\n var ret = 1\n for(i in 1\n ..count){\n ret *= ratio\n yield(ret)\n }\n}\nfun Int.factors():List{\n val ret = mutableListOf(1)\n this.eachPrimePower { p, e ->\n val s = ret.toList()\n for(pn in GS(p,p,e)){\n ret.addAll(s.map{it * pn})\n }\n }\n return ret\n}\nfun totient(a:Int):Int{\n var ret = a\n a.eachPrimePower{\n p, _ ->\n ret /= p\n ret *= (p-1)\n }\n return ret\n}\nfun Int.numOfDivisors():Int{\n var ret = 1\n this.eachPrimePower { _, e -> ret *= (e+1) }\n return ret\n}\nfun Int.factorLook():List{\n return sieve.factors[this]\n}\n\n\nfun stirtry2(n:Int):IntArray {\n val A = IntArray(n+1){\n val x = FACT.invStore[it]\n if(it %2 == 0) x else x.additiveInverse()\n }\n val B = IntArray(n+1){\n intPow(it, n,pI) modM FACT.invStore[it]\n }\n val F = FFT.fullconvolution(A,B)\n\n return F\n}\nval recitations = mutableMapOf()\nfun getitdone(n:Int, k:Int):Int{\n if(recitations[n] != null){\n return recitations[n]!!\n }\n val that = stirtry2(n)\n var ret = 0\n for(i in 1..minOf(n,k)){\n ret = ret modPlus that[i]\n }\n// \"$n $k \" dei thatv\\\\\n\n val final = ret modMinus 1\n recitations[n] = final\n return final\n}\n\n\n\nvar n =0\nconst val singleCase = true\nfun main(){\n FACT.preCal(200005)\n sieve.calculateSieveFast()\n sieve.calculateMobius()\n\n// just dei stirtry2(6)\n solve.cases{\n n = getint\n val k = getint\n var ans = 0\n\n if(k == 1 || n ==1){\n put(1)\n return@cases\n\n }\n\n for(i in 1..n){\n val m = sieve.mobius[i].adjust()\n if(m == 0) continue\n\n val now = getitdone(n divCeil i,k)\n// i dei now\n ans = ans modPlus ( now modM m)\n }\n put(ans)\n }\n done()\n}\n/*\njust number of such patterns\n\n\n\nn\nn/2\nn/3\n\n */\n\n\n\n\n", "lang_cluster": "Kotlin", "tags": ["math", "number theory", "combinatorics", "fft"], "code_uid": "a7189dec35595a86f05ba72235aeecf7", "src_uid": "eb9d24070cc5b347d020189d803628ae", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "\nimport java.io.BufferedInputStream\nimport java.io.File\nimport java.io.PrintWriter\nimport kotlin.math.ln\nimport kotlin.system.measureTimeMillis\n\ninline fun TIME(f:()->Unit){\n val t = measureTimeMillis(){\n f()\n }\n println(\"$t ms\")\n}\n\nobject IO{\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(\"You forgot to disable tests you digital dummy!\")\n println(\"You forgot to disable tests you digital dummy!\")\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){ IO.OUT.println(aa)}\nfun done(){ IO.OUT.close() }\nfun share(aa:Any){\n if(aa is IntArray){IO.fakein.append(aa.joinToString(\" \"))}\n else if(aa is LongArray){IO.fakein.append(aa.joinToString(\" \"))}\n else if(aa is List<*>){IO.fakein.append(aa.toString())}\n else{IO.fakein.append(aa.toString())}\n IO.fakein.append(\"\\n\")\n}\n\nval getint:Int get() = IO.nextInt()\nval getlong:Long get() = IO.nextLong()\nval getstr:String get() = IO.nextString()\nfun getline(n:Int):IntArray{\n return IntArray(n){getint}\n}\nfun getlineL(n:Int):LongArray{\n return LongArray(n){getlong}\n}\nfun getbinary(n:Int):BooleanArray{\n val str = getstr\n return BooleanArray(n){str[it] == '1'}\n}\n\nval List.ret:String\nget() = this.joinToString(\"\")\ninfix fun Any.dei(a:Any){\n //does not stand for anything it is just easy to type, have to be infix because kotlin does not have custom prefix operators\n var str = \"\"\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 }\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{ println(\"$str : $a\")\n }\n}\nval just = \" \" // usage: just dei x , where x is the debug variable\nfun crash(){throw Exception(\"Bad programme\")} // because assertion does not work\nfun assert(a:Boolean){\n if(!a){throw Exception(\"Failed Assertion\")\n }}\nenum class solveMode {\n real, rand, tc\n}\nconst val withBruteForce = false\nconst val randCount = 100\nobject solve{\n var mode:solveMode = solveMode.real\n var tcNum:Int = 0\n var rand:()->Unit = {}\n var TC:MutableMapUnit> = mutableMapOf()\n var answersChecked = 0\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 //safety checks\n if(pI != 998_244_353 && pI != 1_000_000_007){\n throw Exception(\"Modding a wrong prime!\")\n }\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 IO.rerouteInput()\n }else if(mode == solveMode.rand){\n rand()\n IO.rerouteInput()\n }\n currentAnswer = null\n currentBruteAnswer = null\n onecase()\n }\n if(withBruteForce){\n put(\"Checked ${answersChecked}\")\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 inline fun brute(a:()->Unit){\n if(withBruteForce){\n a()\n }\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\n\n var currentAnswer:String? = null\n var currentBruteAnswer:String? = null\n fun answer(a:Any){\n currentAnswer = a.toString()\n if(currentBruteAnswer != null){\n checkAnswer()\n }\n }\n fun put2(a:Any){answer(a);put(a) }\n\n fun bruteAnswer(a:Any){\n currentBruteAnswer = a.toString()\n if(currentAnswer != null){\n checkAnswer()\n }\n }\n fun checkAnswer(){\n if(currentAnswer != currentBruteAnswer){\n throw Exception(\"Failed Test: BF $currentBruteAnswer Current $currentAnswer\")\n }\n answersChecked ++\n }\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 * 1L * b) % pI).toInt() }\ninfix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }\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\n\ninfix fun Int.divCeil(b:Int):Int{\n //Positives numbers only!\n if(this == 0) {\n return 0\n }\n return (this-1)/b + 1\n}\ninfix fun Long.divCeil(b:Long):Long{\n //Positives numbers only!\n if(this == 0L) {\n return 0\n }\n return (this-1)/b + 1\n}\n\ninfix fun Long.modM(b:Long):Long{\n return (this * b) % p\n}\n//infix fun Int.modPlus(b:Int):Int{\n// val ans = this + b\n// return if(ans >= pI) ans - pI else ans\n//}\ninfix fun Int.modMinus(b:Int):Int{\n val ans = this - b\n return if(ans < 0) ans + pI else ans\n}\ninfix fun Int.modDivide(b:Int):Int{\n return this modM (b.inverse())\n}\nfun Int.additiveInverse():Int{\n return if(this == 0) 0 else pI - this\n}\n\n\nfun intPow(x:Int,e:Int,m:Int):Int{\n var X = x\n var E =e\n var Y = 1\n while(E > 0){\n if(E % 2 == 0){\n X = ((1L * X * X) % m).toInt()\n E /= 2\n }else{\n Y = ((1L * X * Y) % m).toInt()\n E -= 1\n }\n }\n return Y\n}\n\nfun pow(x:Long,e:Long,m:Long):Long{\n var X = x\n var E =e\n var Y = 1L\n while(E > 0){\n if(E % 2 == 0L){\n X = (X * X) % m\n E /= 2\n }else{\n Y = (X * Y) % m\n E -= 1\n }\n }\n return Y\n}\nfun Long.inverse():Long{\n return pow(this,p-2,p)\n}\nfun Int.inverse():Int{\n return intPow(this,pI-2,pI)\n}\n//make this int instead\nclass FACT{\n companion object {\n var store = IntArray(0)\n var invStore = IntArray(0)\n\n var slowStore:IntArray = IntArray(0)\n\n fun preCal(upto:Int){\n store = IntArray(upto+1)\n invStore = IntArray(upto + 1 )\n store[0] = 1\n invStore[0] = 1\n\n for(i in 1..upto) {\n store[i] = store[i-1] modM i\n invStore[i] = invStore[i-1] modM (i.inverse())\n }\n }\n fun choose(n:Int,r:Int):Int{\n if(r < 0 || r > n) return 0\n val a = store[n]\n val b = invStore[n-r]\n val c = invStore[r]\n return (a modM b) modM c\n }\n\n fun bigChoose(n:Int,r:Int):Int{\n var ret = 1\n for(i in 0 until r){\n ret = ret modM (n - i)\n }\n ret = ret modM (invStore[r])\n return ret\n }\n\n }\n}\n\nclass FFT {\n companion object{\n // val fftmod = 7340033\n// val root = 5\n// val root_1 = 4404020\n// val root_pw = 1 shl 20\n private const val fftmod = 998244353\n private const val root = 15311432\n private const val root_1 = 469870224\n private const val root_pw = 1 shl 23\n\n fun calculateRoot(){\n println(\"root :$root\")\n // intPow(3,7 * 17,fftmod)\n println(\"root_1 : $root_1\")\n // intPow(root,fftmod -2,fftmod)\n }\n\n fun fft(a:IntArray,invert:Boolean){\n val n = a.size\n var j = 0\n\n\n for(i in 1 until n){\n var bit = n shr 1\n while(j and bit > 0){\n j = j xor bit\n bit = bit shr 1\n }\n j = j xor bit\n if(i < j){\n val temp = a[i]\n a[i] = a[j]\n a[j] = temp\n }\n }\n var len = 2\n while(len <= n){\n var wlen = if(invert) root_1 else root\n var i = len\n while(i < root_pw){\n wlen = (1L * wlen * wlen % fftmod).toInt()\n i = i shl 1\n }\n i = 0\n while(i < n){\n var w = 1\n for(j in 0 until len/2){\n val u = a[i+j]\n val v = (1L * a[i+j+len/2] * w % fftmod).toInt()\n a[i+j] = if(u+v < fftmod) u + v else u + v - fftmod\n a[i+j+len/2] = if(u-v >= 0) u-v else u-v+fftmod\n w = (1L * w * wlen % fftmod).toInt()\n }\n i += len\n }\n len = len shl 1\n }\n if(invert){\n val n_1 = pow(n.toLong(),(fftmod-2).toLong(),fftmod.toLong())\n for((i,x) in a.withIndex()){\n a[i] = (1L * x * n_1 % fftmod).toInt()\n }\n }\n }\n fun fullconvolution(at:IntArray,bt:IntArray):IntArray{\n return fullconvolutionOpt(at,bt,at.size,bt.size)\n }\n\n fun fullconvolutionOpt(at:IntArray,bt:IntArray,sizeA:Int,sizeB:Int):IntArray{\n // 1 shl 18 done in 77 ms\n val maxSize = (sizeA + sizeB).takeHighestOneBit() * 2\n val a = at.copyOf(maxSize)\n val b = bt.copyOf(maxSize)\n val expectedSize = at.size + bt.size - 1\n fft(a,false)\n fft(b,false)\n val new = IntArray(maxSize)\n for(i in new.indices){\n new[i] = (1L * a[i] * b[i] % fftmod).toInt()\n }\n fft(new,true)\n return new.copyOf(expectedSize)\n }\n }\n}\n\nfun stir(l:Int, r:Int):IntArray{\n if(l == r){\n return intArrayOf(l,1)\n }else{\n val mid = (l+r) shr 1\n return FFT.fullconvolution(stir(l,mid), stir(mid+1,r))\n }\n}\n\n\n\nobject sieve{\n\n const val sieveMx = 200005\n val primeOf = IntArray(sieveMx + 1)\n var primeCounter = 0\n val primeUpperBound = maxOf(25,(sieveMx.toDouble()/(ln(sieveMx.toDouble()) -4)).toInt() +3)\n val primes = IntArray(primeUpperBound)\n var sieveCalculated = false\n val nextPrime = IntArray(sieveMx+1)\n val nextPrimePower = IntArray(sieveMx+1)\n val afterPrimePowerDivison = IntArray(sieveMx+1)\n var mobius = IntArray(0)\n\n var factors:List> = mutableListOf()\n\n fun calculateSieveFast(){\n if(sieveCalculated){\n return\n }\n sieveCalculated = true\n for(i in 2..sieveMx){\n if(primeOf[i] == 0 ){\n primeOf[i] = i\n primes[primeCounter] = i\n primeCounter += 1\n }\n for(j in 0 until primeCounter){\n val p = primes[j]\n val pd = p * i\n if(p <= i && pd <= sieveMx){\n primeOf[pd] = p\n }else{\n break\n }\n }\n }\n }\n fun preparePrimePower(){\n nextPrime[1] = -1\n nextPrimePower[1] = -1\n afterPrimePowerDivison[1] = 1\n for(i in 2..sieveMx){\n val p = primeOf[i]\n val new = i / p\n nextPrime[i] = p\n if(nextPrime[new] == p){\n nextPrimePower[i] = nextPrimePower[new]\n afterPrimePowerDivison[i] = afterPrimePowerDivison[new]\n }else{\n afterPrimePowerDivison[i] = new\n }\n nextPrimePower[i] += 1\n }\n }\n fun prepareFactors(){\n // 700ms in 1M\n // shoudl not be used for 1M\n // 200ms codeforces for 200k\n factors = List(sieveMx + 1){ mutableListOf()}\n factors[1].add(1)\n\n for(i in 2..sieveMx){\n val p = nextPrime[i]\n val a = nextPrimePower[i]\n val old = afterPrimePowerDivison[i]\n\n var here = 1\n repeat(a+1){\n for(c in factors[old]){\n factors[i].add(c * here )\n }\n here *= p\n }\n// factors[1].ad\n// factors[i].addAll(i.factors())\n }\n }\n fun calculateMobius(){\n kotlin.assert(sieveCalculated)\n mobius = IntArray(sieveMx + 1)\n mobius[1] = 1\n for(i in 2..sieveMx){\n val p = primeOf[i]\n if(p == primeOf[i/p]){\n mobius[i] = 0\n }else{\n mobius[i] = -1 * mobius[i/p]\n }\n }\n }\n}\ninline fun Int.eachPrimePower(act:(Int,Int)->Unit){\n var here = this\n while(here > 1){\n act(sieve.nextPrime[here], sieve.nextPrimePower[here])\n here = sieve.afterPrimePowerDivison[here]\n }\n}\nfun GS(start:Int,ratio:Int,count:Int) = sequence {\n var ret = 1\n for(i in 1\n ..count){\n ret *= ratio\n yield(ret)\n }\n}\nfun Int.factors():List{\n val ret = mutableListOf(1)\n this.eachPrimePower { p, e ->\n val s = ret.toList()\n for(pn in GS(p,p,e)){\n ret.addAll(s.map{it * pn})\n }\n }\n return ret\n}\nfun totient(a:Int):Int{\n var ret = a\n a.eachPrimePower{\n p, _ ->\n ret /= p\n ret *= (p-1)\n }\n return ret\n}\nfun Int.numOfDivisors():Int{\n var ret = 1\n this.eachPrimePower { _, e -> ret *= (e+1) }\n return ret\n}\nfun Int.factorLook():List{\n return sieve.factors[this]\n}\n\n\nfun stirlingNumbers(n:Int):IntArray {\n val A = IntArray(n+1){\n val x = FACT.invStore[it]\n if(it %2 == 0) x else x.additiveInverse()\n }\n val B = IntArray(n+1){\n intPow(it, n,pI) modM FACT.invStore[it]\n }\n val F = FFT.fullconvolution(A,B)\n\n return F\n}\nval recitations = mutableMapOf()\nfun getitdone(n:Int, k:Int):Int{\n if(recitations[n] != null){\n return recitations[n]!!\n }\n val that = stirlingNumbers(n)\n var ret = 0\n for(i in 1..minOf(n,k)){\n ret = ret modPlus that[i]\n }\n// \"$n $k \" dei thatv\\\\\n\n val final = ret modMinus 1\n recitations[n] = final\n return final\n}\n\n\n\nvar n =0\nconst val singleCase = true\nfun main(){\n FACT.preCal(200005)\n sieve.calculateSieveFast()\n sieve.calculateMobius()\n\n// just dei stirtry2(6)\n solve.cases{\n n = getint\n val k = getint\n var ans = 0\n\n if(k == 1 || n ==1){\n put(1)\n return@cases\n\n }\n\n for(i in 1..n){\n val m = sieve.mobius[i].adjust()\n if(m == 0) continue\n\n val now = getitdone(n divCeil i,k)\n// i dei now\n ans = ans modPlus ( now modM m)\n }\n put(ans)\n }\n done()\n}\n/*\njust number of such patterns\n\n\n\nn\nn/2\nn/3\n\n */\n\n\n\n\n", "lang_cluster": "Kotlin", "tags": ["math", "number theory", "combinatorics", "fft"], "code_uid": "fa4d3f388dfccf14ad278fa8c4eed103", "src_uid": "eb9d24070cc5b347d020189d803628ae", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "// 2022.06.17 at 18:59:23 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 = 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\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\nfun debug(){}\r\nconst val singleCase = true\r\n\r\n\r\nclass cache {\r\n val map = mutableMapOf()\r\n fun get(a:T,ow:(T)->V):V{\r\n if(a in map){\r\n return map[a]!!\r\n }\r\n val new = ow(a)\r\n map[a] = new\r\n// just dei map.size\r\n return new\r\n }\r\n fun debug(a:T,ow:(T)->V):V{\r\n if(a in map){\r\n return map[a]!!\r\n }\r\n val new = ow(a)\r\n map[a] = new\r\n println(\"$a $new\")\r\n return new\r\n }\r\n}\r\ninfix fun Int.divceil(b:Int):Int{\r\n return (this/b) + if(this % b > 0) 1 else 0\r\n}\r\ninfix fun Long.divceil(b:Long):Long{\r\n return (this/b) + if(this % b > 0) 1L else 0L\r\n}\r\ninfix fun Int.div_neg_floor(b:Int):Int{\r\n return (this/b) - if(this % b < 0) 1 else 0\r\n}\r\ninfix fun Long.div_neg_floor(b:Long):Long{\r\n return (this/b) - if(this % b < 0) 1L else 0L\r\n}\r\nfun modCount(x:Long, mod:Long, l:Long, r:Long):Long{\r\n val ans = ((r -x) div_neg_floor mod ) - ((l - x) divceil mod) + 1\r\n return maxOf(ans,0)\r\n //coun number of x mod mod in [l..r]\r\n}\r\nclass largedecimal(var arr:LongArray){\r\n companion object{\r\n const val baselen = 17\r\n const val mod = 1_000_000_000_000_000_00L\r\n val zeros = List(baselen){'0'}.joinToString(\"\")\r\n }\r\n constructor(a:Int):this(longArrayOf(a.toLong())){\r\n\r\n }\r\n constructor(str:String):this(longArrayOf(0)){\r\n for(c in str){\r\n val v = c.toInt() - '0'.toInt()\r\n this.shlonce()\r\n this.adding(v)\r\n }\r\n }\r\n fun copy():largedecimal{\r\n return largedecimal(arr.copyOf())\r\n }\r\n fun clean(){\r\n val max = arr.lastIndex\r\n for(i in 0..max){\r\n if(arr[i] >= mod){\r\n val extra = arr[i] / mod\r\n arr[i] -= extra * mod\r\n if(i == arr.lastIndex){\r\n arr = arr.copyOf(arr.size + 1 )\r\n }\r\n arr[i+1] += extra\r\n }\r\n }\r\n }\r\n fun doubleclean(){\r\n val max = arr.lastIndex\r\n for(i in 0..max){\r\n if(arr[i] >= mod){\r\n val extra = arr[i] / mod\r\n arr[i] -= extra * mod\r\n if(i == arr.lastIndex){\r\n arr = arr.copyOf(arr.size + 1 )\r\n }\r\n arr[i+1] += extra\r\n }else if(arr[i] < 0){\r\n val extra = arr[i] div_neg_floor mod\r\n arr[i] -= extra * mod\r\n if(i == arr.lastIndex){\r\n arr = arr.copyOf(arr.size + 1 )\r\n }\r\n arr[i+1] += extra\r\n }\r\n }\r\n }\r\n fun smallmultiply(x:Int){\r\n // x <= 10 is needed\r\n for(i in arr.indices){\r\n arr[i] *= x.toLong()\r\n }\r\n clean()\r\n }\r\n fun adding(x:Int){\r\n arr[0] += x.toLong()\r\n doubleclean()\r\n }\r\n fun shlonce(){\r\n for(i in arr.indices){\r\n arr[i] *= 10L\r\n }\r\n clean()\r\n }\r\n fun shronce(){\r\n for(i in arr.indices){\r\n val new = arr[i] % 10\r\n arr[i] /= 10L\r\n if(i != 0){\r\n arr[i-1] += new * mod / 10\r\n }\r\n }\r\n }\r\n fun unitdigit():Int{\r\n return (arr[0] %10).toInt()\r\n }\r\n fun iszero():Boolean{\r\n return arr.all { it == 0L }\r\n }\r\n fun isnegative():Boolean{\r\n return arr.any { it < 0 }\r\n }\r\n\r\n override fun toString():String {\r\n val ret = mutableListOf()\r\n var stuff = false\r\n for(i in arr.lastIndex downTo 0){\r\n val here = arr[i]\r\n if(here != 0L){\r\n stuff = true\r\n ret.add(here.toString())\r\n }else{\r\n if(stuff){\r\n ret.add(zeros)\r\n }\r\n }\r\n }\r\n if(!stuff){\r\n return \"0\"\r\n }\r\n return ret.joinToString(\r\n \"\"\r\n )\r\n }\r\n override fun equals(other:Any?):Boolean {\r\n if(this === other) return true\r\n if(javaClass != other?.javaClass) return false\r\n\r\n other as largedecimal\r\n\r\n if(!arr.contentEquals(other.arr)) return false\r\n\r\n return true\r\n }\r\n override fun hashCode():Int {\r\n return arr.contentHashCode()\r\n }\r\n}\r\nval okcache = cache()\r\n\r\ndata class arg(val num:largedecimal, val balance:Int, val rank:Int){\r\n\r\n}\r\n\r\nfun ok(num:largedecimal,balance:Int, rank:Int):Int{\r\n if(num.iszero()){\r\n return if(balance == 0) 0 else plarge\r\n }\r\n if(balance !in -600..600) return plarge\r\n return okcache.get(arg(num,balance,rank)){\r\n it ->\r\n with(it){\r\n val ld = num.unitdigit()\r\n val t1 = num.copy()\r\n t1.adding(-ld)\r\n t1.shronce()\r\n var best = plarge\r\n best = minOf(best,ok(t1,balance - ld,rank + 1) + ld * rank )\r\n val t2 = num.copy()\r\n t2.adding(10 - ld)\r\n t2.shronce()\r\n best = minOf(best,ok(t2, balance + (10-ld), rank + 1) + (10-ld) * rank)\r\n return@get best\r\n }\r\n\r\n }\r\n}\r\n\r\nfun main(){\r\n\r\n// var v = largedecimal(1)\r\n// repeat(100){\r\n// v.smallmultiply(2)\r\n// just dei v\r\n// }\r\n solve.tc {\r\n share(\"12345678901234567890123456789012345678901234567890\")\r\n }\r\n// solve.usetc()\r\n solve.cases{\r\n val str = getstr\r\n val C = largedecimal(str)\r\n C.smallmultiply(9)\r\n\r\n\r\n// just dei ok(largedecimal(92),2,1)\r\n// just dei C\r\n\r\n// just dei ok(largedecimal(92),2,7,1)\r\n\r\n// return@cases\r\n\r\n var best = plarge\r\n for(balance in -600..600){\r\n val now = C.copy()\r\n now.adding(balance)\r\n if(now.unitdigit() != 0 || now.isnegative()) continue\r\n now.shronce()\r\n val new = ok(now, balance, 1)\r\n// balance dei new\r\n best = minOf(best, new)\r\n }\r\n put(best)\r\n\r\n\r\n\r\n\r\n }\r\n done()\r\n}\r\n/*\r\nless greedy\r\n\r\nuses at most 10\r\n\r\nanswer is no more than 500\r\n500,500\r\n\r\n\r\n */\r\n\r\n\r\n\r\n", "lang_cluster": "Kotlin", "tags": ["greedy", "dp", "shortest paths"], "code_uid": "96bf8c712ccdf7d1a4ec36e582d6ef8b", "src_uid": "1961e7c9120ff652b15cad5dd5ca0907", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport java.math.BigInteger\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 = read().toBigInteger()\n\n val ones = Array(51) { one }\n for(i in 1..ones.lastIndex) ones[i] = (ones[i-1] * ten).inc()\n\n val heap = DijkHeap()\n heap.promote(n, 0)\n\n val ans = run ans@ {\n while(heap.isNotFinished()) {\n val x = heap.remove()\n val c = heap.cost(x)\n\n if(x == BigInteger.ZERO) return@ans c\n\n val i = ones.bsIndexOfLast { it <= x }\n heap.promote(x - ones[i], c + i + 1)\n heap.promote(ones[i+1] - x, c + i + 2)\n }\n\n -1\n }\n\n println(ans)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nval one = BigInteger.ONE\nval ten = BigInteger.TEN!!\n\nfun splitmix64(seed: Long): Long {\n var x = seed // * -7046029254386353131\n x = (x xor (x ushr 30)) * -4658895280553007687\n x = (x xor (x ushr 27)) * -7723592293110705685\n return (x xor (x ushr 31))\n}\n@JvmField val nonce64 = random.nextLong()\n@JvmField val gamma64 = random.nextLong() or 1\nfun Long.hash() = splitmix64((nonce64 xor this) * gamma64)\n\nfun BigInteger.hash(): Long = toByteArray().run {\n var res = size.toLong()\n for(i in indices) {\n if(i and 7 == 0) res = res.hash()\n res = res xor get(i).toLong().shl(i.and(7) * 8)\n }\n\n return res//.hash()\n}\n\ninline fun bsFirst(first: Int, last: Int, predicate: (Int) -> Boolean): Int {\n var low = first\n var high = last\n\n while (low <= high) {\n val mid = low.and(high) + low.xor(high).shr(1)\n if(predicate(mid)) high = mid - 1\n else low = mid + 1\n }\n return low\n}\ninline fun IntRange.bsFirst(predicate: (Int) -> Boolean) = bsFirst(first, last, predicate)\n\ninline fun bsLast(first: Int, last: Int, predicate: (Int) -> Boolean) = bsFirst(first, last) { !predicate(it) } - 1\ninline fun IntRange.bsLast(predicate: (Int) -> Boolean) = bsLast(first, last, predicate)\n\ninline fun Array.bsIndexOfFirst(predicate: (T) -> Boolean) = bsFirst(0, lastIndex) { predicate(get(it)) }\ninline fun Array.bsFirst(predicate: (T) -> Boolean) = get(bsIndexOfFirst(predicate))\ninline fun Array.bsFirstOrNull(predicate: (T) -> Boolean) = getOrNull(bsIndexOfFirst(predicate))\ninline fun Array.bsIndexOfLast(predicate: (T) -> Boolean) = bsLast(0, lastIndex) { predicate(get(it)) }\ninline fun Array.bsLast(predicate: (T) -> Boolean) = get(bsIndexOfLast(predicate))\ninline fun Array.bsLastOrNull(predicate: (T) -> Boolean) = getOrNull(bsIndexOfLast(predicate))\n\nconst val inf = Int.MAX_VALUE\nclass DijkHeap {\n val h = intListOf(-1)\n val pos = IntList()\n val cost = IntList()\n val map = LongIntMap(nullValue = -1)\n val keys = mutableListOf()\n\n val inHeap get() = h.lastIndex\n\n private fun swap(i: Int, j: Int) {\n val hi = h[i]; val hj = h[j]\n h[j] = hi; h[i] = hj\n pos[hi] = j; pos[hj] = i\n }\n\n fun promote(key0: BigInteger, newCost: Int): Boolean {\n val key = run {\n val hash = key0.hash()\n map[hash].let { if(it != -1) return@run it }\n keys.size.also {\n map[hash] = it\n keys.add(key0)\n h.add(it)\n pos.add(inHeap)\n cost.add(inf)\n }\n }\n if(newCost >= cost[key]) return false\n var i = pos[key]\n\n while(i > 1) {\n val par = i shr 1\n if (newCost >= cost[h[par]]) break\n swap(i, par)\n i = par\n }\n\n cost[key] = newCost\n return true\n }\n\n val head get() = h[1]\n fun isNotFinished() = inHeap > 0\n\n fun remove() = head.let { hd ->\n swap(1, inHeap)\n pos[hd] = -1\n h.pop()\n\n var i = 1\n while(true) {\n val l = i shl 1\n if(l > inHeap) break\n val r = l or 1\n\n var best = l\n var p = cost[h[l]]\n if(r <= inHeap) {\n val pr = cost[h[r]]\n if(pr < p) {\n best = r\n p = pr\n }\n }\n\n if(cost[h[i]] <= p) break\n\n swap(i, best)\n i = best\n }\n\n keys[hd]\n }\n\n fun cost(key: BigInteger): Int {\n val hash = key.hash()\n val i = map[hash]\n return if(i == -1) inf else cost[i]\n }\n}\n\nclass IntList(initialCapacity: Int = 12) {\n private var arr = IntArray(initialCapacity)\n val _arr get() = arr\n private val capacity get() = arr.size\n var size = 0\n private set\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n\n constructor(copyFrom: IntArray): this(copyFrom.size) { copyFrom.copyInto(arr); size = copyFrom.size }\n constructor(copyFrom: Collection): this(copyFrom.size) { arr = copyFrom.toIntArray(); size = copyFrom.size }\n\n fun contentEquals(other: IntList): Boolean {\n return this === other || size == other.size && indices.all { this[it] == other[it] }\n }\n\n private fun grow(minCapacity: Int = 8) {\n val newCapacity = maxOf(minCapacity, capacity + (capacity shr 1))\n arr = arr.copyOf(newCapacity)\n }\n\n fun ensureCapacity(minCapacity: Int) { if(capacity < minCapacity) grow(minCapacity) }\n\n operator fun get(index: Int): Int {\n require(index in 0 until size)\n return arr[index]\n }\n\n operator fun set(index: Int, value: Int) {\n require(index in 0 until size)\n arr[index] = value\n }\n\n fun add(value: Int) {\n if(size == capacity) grow()\n arr[size++] = value\n }\n\n fun addAll(list: IntList) {\n ensureCapacity(size + list.size)\n list.arr.copyInto(arr, size, 0, list.size)\n size += list.size\n }\n\n fun add(index: Int, element: Int) {\n if(size == capacity) grow()\n arr.copyInto(arr, index + 1, index, size)\n size++\n set(index, element)\n }\n\n fun clear() { size = 0 }\n\n fun removeAt(index: Int): Int {\n val e = get(index)\n arr.copyInto(arr, index, index + 1, size)\n size--\n return e\n }\n\n fun indexOf(e: Int): Int {\n for(i in 0 until size) if(this[i] == e) return i\n return -1\n }\n\n fun remove(e: Int): Boolean {\n val i = indexOf(e)\n if(i == -1) return false\n removeAt(i)\n return true\n }\n\n operator fun iterator() = object: IntIterator() {\n private var pos = 0\n override fun hasNext() = pos < size\n override fun nextInt() = get(pos++)\n }\n\n inline fun isEmpty() = size == 0\n inline fun isNotEmpty() = size != 0\n\n fun pop() = arr[--size]\n\n fun popToSize(s: Int) {\n require(s >= 0)\n if(s < size) size = s\n }\n\n fun swap(i: Int, j: Int) { val t = this[i]; this[i] = this[j]; this[j] = t }\n fun reverse() {\n for(i in 0 until size / 2) swap(i, lastIndex - i)\n }\n\n fun shuffle(rnd: Random = random) { for(i in lastIndex downTo 1) swap(i, rnd.nextInt(i+1)) }\n\n inline fun sortWith(cmp: (Int, Int) -> Int) { _mergeSort(_arr, size, IntArray(size), IntArray::get, IntArray::set, cmp) }\n inline fun > sortBy(func: (Int) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\n inline fun > sortByDescending(func: (Int) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\n fun sort() { sortBy { it } }\n fun sortDescending() { sortByDescending { it } }\n\n fun joinToString(separator: CharSequence) = if(size == 0) \"\" else let {\n buildString {\n append(it[0])\n for (i in 1 until size) {\n append(separator).append(it[i])\n }\n }\n }\n\n override fun toString() = \"[\" + joinToString(\", \") + \"]\"\n\n fun toIntArray() = arr.copyOf(size)\n fun toList() = List(size, ::get)\n\n inline fun first() = get(0)\n inline fun last() = get(lastIndex)\n}\n\ninline fun IntList(size: Int, init: (Int) -> Int) = IntList(size).apply {\n for(i in 0 until size) { add(init(i)) }\n}\ninline fun IntArray.toIntList() = IntList(this)\ninline fun Collection.toIntList() = IntList(this)\ninline fun intListOf(vararg values: Int) = IntList(values)\n\nfun IntList.max() = (1 until size).fold(this[0]) { acc, i -> max(acc, this[i]) }\nfun IntList.min() = (1 until size).fold(this[0]) { acc, i -> min(acc, this[i]) }\nfun IntList.getOrNull(i: Int) = if(i in indices) get(i) else null\ninline fun IntList.count(predicate: (Int) -> Boolean) = indices.count { predicate(this[it]) }\nfun IntList.copyOf() = IntList(size, ::get)\n\ntypealias LongIntMap = _Ez_Long__Int_HashMap\ninline operator fun LongIntMap.set(key: Long, value: Int) { put(key, value) }\ninline operator fun LongIntMap.contains(key: Long) = containsKey(key)\n\nclass _Ez_Long__Int_HashMap(capacity: Int = DEFAULT_CAPACITY, val nullValue: Int = 0) :\n _Ez_Long__Int_Map {\n companion object {\n private const val DEFAULT_CAPACITY = 8\n // There are three invariants for size, removedCount and arraysLength:\n// 1. size + removedCount <= 1/2 arraysLength\n// 2. size > 1/8 arraysLength\n// 3. size >= removedCount\n// arraysLength can be only multiplied by 2 and divided by 2.\n// Also, if it becomes >= 32, it can't become less anymore.\n private const val REBUILD_LENGTH_THRESHOLD = 32\n private const val HASHCODE_INITIAL_VALUE = -0x7ee3623b\n private const val HASHCODE_MULTIPLIER = 0x01000193\n private const val FREE: Byte = 0\n private const val REMOVED: Byte = 1\n private const val FILLED: Byte = 2\n private val hashSeed = random.nextLong()\n private val gamma = random.nextLong() or 1\n }\n\n private lateinit var keys: LongArray\n private lateinit var values: IntArray\n private lateinit var status: ByteArray\n override var size = 0\n private set\n private var removedCount = 0\n private var mask = 0\n\n constructor(map: _Ez_Long__Int_Map) : this(map.size) {\n val it = map.iterator()\n while (it.hasNext()) {\n put(it.key, it.value)\n it.next()\n }\n }\n\n constructor(javaMap: Map) : this(javaMap.size) {\n for ((key, value) in javaMap) {\n put(key, value)\n }\n }\n\n private fun getStartPos(h: Long): Int {\n var x = (h xor hashSeed) * gamma\n x = (x xor (x ushr 30)) * -4658895280553007687\n x = (x xor (x ushr 27)) * -7723592293110705685\n return (x xor (x ushr 31)).toInt() and mask\n }\n\n override fun isEmpty(): Boolean = size == 0\n\n override fun containsKey(\n key: Long\n ): Boolean {\n var pos = getStartPos(key)\n while (status[pos] != FREE) {\n if (status[pos] == FILLED && keys[pos] == key) {\n return true\n }\n pos = pos + 1 and mask\n }\n return false\n }\n\n override fun get(\n key: Long\n ): Int {\n var pos = getStartPos(key)\n while (status[pos] != FREE) {\n if (status[pos] == FILLED && keys[pos] == key) {\n return values[pos]\n }\n pos = pos + 1 and mask\n }\n return nullValue\n }\n\n override fun put(\n key: Long,\n value: Int\n ): Int {\n var pos = getStartPos(key)\n while (status[pos] == FILLED) {\n if (keys[pos] == key) {\n val oldValue = values[pos]\n values[pos] = value\n return oldValue\n }\n pos = pos + 1 and mask\n }\n if (status[pos] == FREE) {\n status[pos] = FILLED\n keys[pos] = key\n values[pos] = value\n size++\n if ((size + removedCount) * 2 > keys.size) {\n rebuild(keys.size * 2) // enlarge the table\n }\n return nullValue\n }\n val removedPos = pos\n pos = pos + 1 and mask\n while (status[pos] != FREE) {\n if (status[pos] == FILLED && keys[pos] == key) {\n val oldValue = values[pos]\n values[pos] = value\n return oldValue\n }\n pos = pos + 1 and mask\n }\n status[removedPos] = FILLED\n keys[removedPos] = key\n values[removedPos] = value\n size++\n removedCount--\n return nullValue\n }\n\n override fun remove(\n key: Long\n ): Int {\n var pos = getStartPos(key)\n while (status[pos] != FREE) {\n if (status[pos] == FILLED && keys[pos] == key) {\n val removedValue = values[pos]\n status[pos] = REMOVED\n size--\n removedCount++\n if (keys.size > REBUILD_LENGTH_THRESHOLD) {\n if (8 * size <= keys.size) {\n rebuild(keys.size / 2) // compress the table\n } else if (size < removedCount) {\n rebuild(keys.size) // just rebuild the table\n }\n }\n return removedValue\n }\n pos = pos + 1 and mask\n }\n return nullValue\n }\n\n override fun clear() {\n if (keys.size > REBUILD_LENGTH_THRESHOLD) {\n initEmptyTable(REBUILD_LENGTH_THRESHOLD)\n } else {\n status.fill(FREE)\n size = 0\n removedCount = 0\n }\n }\n\n override fun keys(): LongArray {\n val result = LongArray(size)\n var i = 0\n var j = 0\n while (i < keys.size) {\n if (status[i] == FILLED) {\n result[j++] = keys[i]\n }\n i++\n }\n return result\n }\n\n override fun values(): IntArray {\n val result = IntArray(size)\n var i = 0\n var j = 0\n while (i < values.size) {\n if (status[i] == FILLED) {\n result[j++] = values[i]\n }\n i++\n }\n return result\n }\n\n override fun iterator(): _Ez_Long__Int_MapIterator {\n return _Ez_Long__Int_HashMapIterator()\n }\n\n private fun rebuild(newLength: Int) {\n val oldKeys = keys\n\n val oldValues = values\n val oldStatus = status\n initEmptyTable(newLength)\n for (i in oldKeys.indices) {\n if (oldStatus[i] == FILLED) {\n put(oldKeys[i], oldValues[i])\n }\n }\n }\n\n private fun initEmptyTable(length: Int) {\n keys = LongArray(length)\n values = IntArray(length)\n status = ByteArray(length)\n size = 0\n removedCount = 0\n mask = length - 1\n }\n\n fun contentEquals(that: _Ez_Long__Int_HashMap): Boolean {\n if (size != that.size) {\n return false\n }\n for (i in keys.indices) {\n if (status[i] == FILLED) {\n val thatValue = that[keys[i]]\n if (thatValue != values[i]) {\n return false\n }\n }\n }\n return true\n }\n\n override fun toString(): String {\n val sb = StringBuilder()\n sb.append('{')\n for (i in keys.indices) {\n if (status[i] == FILLED) {\n if (sb.length > 1) {\n sb.append(\", \")\n }\n sb.append(keys[i])\n sb.append('=')\n sb.append(values[i])\n }\n }\n sb.append('}')\n return sb.toString()\n }\n\n private inner class _Ez_Long__Int_HashMapIterator : _Ez_Long__Int_MapIterator {\n private var curIndex = 0\n override fun hasNext(): Boolean {\n return curIndex < status.size\n }\n\n\n override val key: Long\n\n get() {\n if (curIndex == keys.size) {\n throw NoSuchElementException(\"Iterator doesn't have more entries\")\n }\n return keys[curIndex]\n }\n\n\n override val value: Int\n\n get() {\n if (curIndex == values.size) {\n throw NoSuchElementException(\"Iterator doesn't have more entries\")\n }\n return values[curIndex]\n }\n\n override fun next() {\n if (curIndex == status.size) {\n return\n }\n curIndex++\n while (curIndex < status.size && status[curIndex] != FILLED) {\n curIndex++\n }\n }\n\n init {\n while (curIndex < status.size && status[curIndex] != FILLED) {\n curIndex++\n }\n }\n }\n\n init {\n require(capacity >= 0) { \"Capacity must be non-negative\" }\n val length = Integer.highestOneBit(4 * max(1, capacity) - 1)\n // Length is a power of 2 now\n initEmptyTable(length)\n }\n}\n\ninterface _Ez_Long__Int_Map {\n\n val size: Int\n\n fun isEmpty(): Boolean\n\n fun containsKey(\n key: Long\n ): Boolean\n\n operator fun get(\n key: Long\n ): Int\n\n fun put(\n key: Long,\n value: Int\n ): Int\n\n fun remove(\n key: Long\n ): Int\n\n fun clear()\n\n fun keys(): LongArray\n\n fun values(): IntArray\n\n operator fun iterator(): _Ez_Long__Int_MapIterator\n\n override fun toString(): String\n}\n\ninterface _Ez_Long__Int_MapIterator {\n operator fun hasNext(): Boolean\n\n val key: Long\n\n val value: Int\n\n operator fun next()\n}\n\ninline fun LongIntMap.forEach(act: (key: Long, value: Int) -> Unit) {\n val ite = iterator()\n while(ite.hasNext()) {\n act(ite.key, ite.value)\n ite.next()\n }\n}\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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { 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 }", "lang_cluster": "Kotlin", "tags": ["greedy", "dp", "shortest paths"], "code_uid": "06199bcbd216286def986c98b07174d8", "src_uid": "1961e7c9120ff652b15cad5dd5ca0907", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport java.math.BigInteger\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 = read().toBigInteger()\n\n val ones = Array(51) { one }\n for(i in 1..ones.lastIndex) ones[i] = (ones[i-1] * ten).inc()\n\n val heap = DijkHeap()\n heap.promote(n, 0)\n\n val ans = run ans@ {\n while(heap.isNotFinished()) {\n val x = heap.remove()\n val c = heap.cost(x)\n\n if(x == BigInteger.ZERO) return@ans c\n\n val i = ones.bsIndexOfLast { it <= x }\n heap.promote(x - ones[i], c + i + 1)\n heap.promote(ones[i+1] - x, c + i + 2)\n }\n\n -1\n }\n\n println(ans)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nval one = BigInteger.ONE\nval ten = BigInteger.TEN!!\n\nfun splitmix64(seed: Long): Long {\n var x = seed // * -7046029254386353131\n x = (x xor (x ushr 30)) * -4658895280553007687\n x = (x xor (x ushr 27)) * -7723592293110705685\n return (x xor (x ushr 31))\n}\n@JvmField val nonce64 = random.nextLong()\n@JvmField val gamma64 = random.nextLong() or 1\nfun Long.hash() = splitmix64((nonce64 xor this) * gamma64)\n\nfun BigInteger.hash(): Long = toByteArray().asUByteArray().run {\n var res = size.toLong()\n for(i in indices) {\n if(i and 7 == 0) res = res.hash()\n res = res xor get(i).toLong().shl(i.and(7) * 8)\n }\n\n return res//.hash()\n}\n\ninline fun bsFirst(first: Int, last: Int, predicate: (Int) -> Boolean): Int {\n var low = first\n var high = last\n\n while (low <= high) {\n val mid = low.and(high) + low.xor(high).shr(1)\n if(predicate(mid)) high = mid - 1\n else low = mid + 1\n }\n return low\n}\ninline fun IntRange.bsFirst(predicate: (Int) -> Boolean) = bsFirst(first, last, predicate)\n\ninline fun bsLast(first: Int, last: Int, predicate: (Int) -> Boolean) = bsFirst(first, last) { !predicate(it) } - 1\ninline fun IntRange.bsLast(predicate: (Int) -> Boolean) = bsLast(first, last, predicate)\n\ninline fun Array.bsIndexOfFirst(predicate: (T) -> Boolean) = bsFirst(0, lastIndex) { predicate(get(it)) }\ninline fun Array.bsFirst(predicate: (T) -> Boolean) = get(bsIndexOfFirst(predicate))\ninline fun Array.bsFirstOrNull(predicate: (T) -> Boolean) = getOrNull(bsIndexOfFirst(predicate))\ninline fun Array.bsIndexOfLast(predicate: (T) -> Boolean) = bsLast(0, lastIndex) { predicate(get(it)) }\ninline fun Array.bsLast(predicate: (T) -> Boolean) = get(bsIndexOfLast(predicate))\ninline fun Array.bsLastOrNull(predicate: (T) -> Boolean) = getOrNull(bsIndexOfLast(predicate))\n\nconst val inf = Int.MAX_VALUE\nclass DijkHeap {\n val h = intListOf(-1)\n val pos = IntList()\n val cost = IntList()\n val map = LongIntMap(nullValue = -1)\n val keys = mutableListOf()\n\n val inHeap get() = h.lastIndex\n\n private fun swap(i: Int, j: Int) {\n val hi = h[i]; val hj = h[j]\n h[j] = hi; h[i] = hj\n pos[hi] = j; pos[hj] = i\n }\n\n fun promote(key0: BigInteger, newCost: Int): Boolean {\n val key = run {\n val hash = key0.hash()\n map[hash].let { if(it != -1) return@run it }\n keys.size.also {\n map[hash] = it\n keys.add(key0)\n h.add(it)\n pos.add(inHeap)\n cost.add(inf)\n }\n }\n if(newCost >= cost[key]) return false\n var i = pos[key]\n\n while(i > 1) {\n val par = i shr 1\n if (newCost >= cost[h[par]]) break\n swap(i, par)\n i = par\n }\n\n cost[key] = newCost\n return true\n }\n\n val head get() = h[1]\n fun isNotFinished() = inHeap > 0\n\n fun remove() = head.let { hd ->\n swap(1, inHeap)\n pos[hd] = -1\n h.pop()\n\n var i = 1\n while(true) {\n val l = i shl 1\n if(l > inHeap) break\n val r = l or 1\n\n var best = l\n var p = cost[h[l]]\n if(r <= inHeap) {\n val pr = cost[h[r]]\n if(pr < p) {\n best = r\n p = pr\n }\n }\n\n if(cost[h[i]] <= p) break\n\n swap(i, best)\n i = best\n }\n\n keys[hd]\n }\n\n fun cost(key: BigInteger): Int {\n val hash = key.hash()\n val i = map[hash]\n return if(i == -1) inf else cost[i]\n }\n}\n\nclass IntList(initialCapacity: Int = 12) {\n private var arr = IntArray(initialCapacity)\n val _arr get() = arr\n private val capacity get() = arr.size\n var size = 0\n private set\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n\n constructor(copyFrom: IntArray): this(copyFrom.size) { copyFrom.copyInto(arr); size = copyFrom.size }\n constructor(copyFrom: Collection): this(copyFrom.size) { arr = copyFrom.toIntArray(); size = copyFrom.size }\n\n fun contentEquals(other: IntList): Boolean {\n return this === other || size == other.size && indices.all { this[it] == other[it] }\n }\n\n private fun grow(minCapacity: Int = 8) {\n val newCapacity = maxOf(minCapacity, capacity + (capacity shr 1))\n arr = arr.copyOf(newCapacity)\n }\n\n fun ensureCapacity(minCapacity: Int) { if(capacity < minCapacity) grow(minCapacity) }\n\n operator fun get(index: Int): Int {\n require(index in 0 until size)\n return arr[index]\n }\n\n operator fun set(index: Int, value: Int) {\n require(index in 0 until size)\n arr[index] = value\n }\n\n fun add(value: Int) {\n if(size == capacity) grow()\n arr[size++] = value\n }\n\n fun addAll(list: IntList) {\n ensureCapacity(size + list.size)\n list.arr.copyInto(arr, size, 0, list.size)\n size += list.size\n }\n\n fun add(index: Int, element: Int) {\n if(size == capacity) grow()\n arr.copyInto(arr, index + 1, index, size)\n size++\n set(index, element)\n }\n\n fun clear() { size = 0 }\n\n fun removeAt(index: Int): Int {\n val e = get(index)\n arr.copyInto(arr, index, index + 1, size)\n size--\n return e\n }\n\n fun indexOf(e: Int): Int {\n for(i in 0 until size) if(this[i] == e) return i\n return -1\n }\n\n fun remove(e: Int): Boolean {\n val i = indexOf(e)\n if(i == -1) return false\n removeAt(i)\n return true\n }\n\n operator fun iterator() = object: IntIterator() {\n private var pos = 0\n override fun hasNext() = pos < size\n override fun nextInt() = get(pos++)\n }\n\n inline fun isEmpty() = size == 0\n inline fun isNotEmpty() = size != 0\n\n fun pop() = arr[--size]\n\n fun popToSize(s: Int) {\n require(s >= 0)\n if(s < size) size = s\n }\n\n fun swap(i: Int, j: Int) { val t = this[i]; this[i] = this[j]; this[j] = t }\n fun reverse() {\n for(i in 0 until size / 2) swap(i, lastIndex - i)\n }\n\n fun shuffle(rnd: Random = random) { for(i in lastIndex downTo 1) swap(i, rnd.nextInt(i+1)) }\n\n inline fun sortWith(cmp: (Int, Int) -> Int) { _mergeSort(_arr, size, IntArray(size), IntArray::get, IntArray::set, cmp) }\n inline fun > sortBy(func: (Int) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\n inline fun > sortByDescending(func: (Int) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\n fun sort() { sortBy { it } }\n fun sortDescending() { sortByDescending { it } }\n\n fun joinToString(separator: CharSequence) = if(size == 0) \"\" else let {\n buildString {\n append(it[0])\n for (i in 1 until size) {\n append(separator).append(it[i])\n }\n }\n }\n\n override fun toString() = \"[\" + joinToString(\", \") + \"]\"\n\n fun toIntArray() = arr.copyOf(size)\n fun toList() = List(size, ::get)\n\n inline fun first() = get(0)\n inline fun last() = get(lastIndex)\n}\n\ninline fun IntList(size: Int, init: (Int) -> Int) = IntList(size).apply {\n for(i in 0 until size) { add(init(i)) }\n}\ninline fun IntArray.toIntList() = IntList(this)\ninline fun Collection.toIntList() = IntList(this)\ninline fun intListOf(vararg values: Int) = IntList(values)\n\nfun IntList.max() = (1 until size).fold(this[0]) { acc, i -> max(acc, this[i]) }\nfun IntList.min() = (1 until size).fold(this[0]) { acc, i -> min(acc, this[i]) }\nfun IntList.getOrNull(i: Int) = if(i in indices) get(i) else null\ninline fun IntList.count(predicate: (Int) -> Boolean) = indices.count { predicate(this[it]) }\nfun IntList.copyOf() = IntList(size, ::get)\n\ntypealias LongIntMap = _Ez_Long__Int_HashMap\ninline operator fun LongIntMap.set(key: Long, value: Int) { put(key, value) }\ninline operator fun LongIntMap.contains(key: Long) = containsKey(key)\n\nclass _Ez_Long__Int_HashMap(capacity: Int = DEFAULT_CAPACITY, val nullValue: Int = 0) :\n _Ez_Long__Int_Map {\n companion object {\n private const val DEFAULT_CAPACITY = 8\n // There are three invariants for size, removedCount and arraysLength:\n// 1. size + removedCount <= 1/2 arraysLength\n// 2. size > 1/8 arraysLength\n// 3. size >= removedCount\n// arraysLength can be only multiplied by 2 and divided by 2.\n// Also, if it becomes >= 32, it can't become less anymore.\n private const val REBUILD_LENGTH_THRESHOLD = 32\n private const val HASHCODE_INITIAL_VALUE = -0x7ee3623b\n private const val HASHCODE_MULTIPLIER = 0x01000193\n private const val FREE: Byte = 0\n private const val REMOVED: Byte = 1\n private const val FILLED: Byte = 2\n private val hashSeed = random.nextLong()\n private val gamma = random.nextLong() or 1\n }\n\n private lateinit var keys: LongArray\n private lateinit var values: IntArray\n private lateinit var status: ByteArray\n override var size = 0\n private set\n private var removedCount = 0\n private var mask = 0\n\n constructor(map: _Ez_Long__Int_Map) : this(map.size) {\n val it = map.iterator()\n while (it.hasNext()) {\n put(it.key, it.value)\n it.next()\n }\n }\n\n constructor(javaMap: Map) : this(javaMap.size) {\n for ((key, value) in javaMap) {\n put(key, value)\n }\n }\n\n private fun getStartPos(h: Long): Int {\n var x = (h xor hashSeed) * gamma\n x = (x xor (x ushr 30)) * -4658895280553007687\n x = (x xor (x ushr 27)) * -7723592293110705685\n return (x xor (x ushr 31)).toInt() and mask\n }\n\n override fun isEmpty(): Boolean = size == 0\n\n override fun containsKey(\n key: Long\n ): Boolean {\n var pos = getStartPos(key)\n while (status[pos] != FREE) {\n if (status[pos] == FILLED && keys[pos] == key) {\n return true\n }\n pos = pos + 1 and mask\n }\n return false\n }\n\n override fun get(\n key: Long\n ): Int {\n var pos = getStartPos(key)\n while (status[pos] != FREE) {\n if (status[pos] == FILLED && keys[pos] == key) {\n return values[pos]\n }\n pos = pos + 1 and mask\n }\n return nullValue\n }\n\n override fun put(\n key: Long,\n value: Int\n ): Int {\n var pos = getStartPos(key)\n while (status[pos] == FILLED) {\n if (keys[pos] == key) {\n val oldValue = values[pos]\n values[pos] = value\n return oldValue\n }\n pos = pos + 1 and mask\n }\n if (status[pos] == FREE) {\n status[pos] = FILLED\n keys[pos] = key\n values[pos] = value\n size++\n if ((size + removedCount) * 2 > keys.size) {\n rebuild(keys.size * 2) // enlarge the table\n }\n return nullValue\n }\n val removedPos = pos\n pos = pos + 1 and mask\n while (status[pos] != FREE) {\n if (status[pos] == FILLED && keys[pos] == key) {\n val oldValue = values[pos]\n values[pos] = value\n return oldValue\n }\n pos = pos + 1 and mask\n }\n status[removedPos] = FILLED\n keys[removedPos] = key\n values[removedPos] = value\n size++\n removedCount--\n return nullValue\n }\n\n override fun remove(\n key: Long\n ): Int {\n var pos = getStartPos(key)\n while (status[pos] != FREE) {\n if (status[pos] == FILLED && keys[pos] == key) {\n val removedValue = values[pos]\n status[pos] = REMOVED\n size--\n removedCount++\n if (keys.size > REBUILD_LENGTH_THRESHOLD) {\n if (8 * size <= keys.size) {\n rebuild(keys.size / 2) // compress the table\n } else if (size < removedCount) {\n rebuild(keys.size) // just rebuild the table\n }\n }\n return removedValue\n }\n pos = pos + 1 and mask\n }\n return nullValue\n }\n\n override fun clear() {\n if (keys.size > REBUILD_LENGTH_THRESHOLD) {\n initEmptyTable(REBUILD_LENGTH_THRESHOLD)\n } else {\n status.fill(FREE)\n size = 0\n removedCount = 0\n }\n }\n\n override fun keys(): LongArray {\n val result = LongArray(size)\n var i = 0\n var j = 0\n while (i < keys.size) {\n if (status[i] == FILLED) {\n result[j++] = keys[i]\n }\n i++\n }\n return result\n }\n\n override fun values(): IntArray {\n val result = IntArray(size)\n var i = 0\n var j = 0\n while (i < values.size) {\n if (status[i] == FILLED) {\n result[j++] = values[i]\n }\n i++\n }\n return result\n }\n\n override fun iterator(): _Ez_Long__Int_MapIterator {\n return _Ez_Long__Int_HashMapIterator()\n }\n\n private fun rebuild(newLength: Int) {\n val oldKeys = keys\n\n val oldValues = values\n val oldStatus = status\n initEmptyTable(newLength)\n for (i in oldKeys.indices) {\n if (oldStatus[i] == FILLED) {\n put(oldKeys[i], oldValues[i])\n }\n }\n }\n\n private fun initEmptyTable(length: Int) {\n keys = LongArray(length)\n values = IntArray(length)\n status = ByteArray(length)\n size = 0\n removedCount = 0\n mask = length - 1\n }\n\n fun contentEquals(that: _Ez_Long__Int_HashMap): Boolean {\n if (size != that.size) {\n return false\n }\n for (i in keys.indices) {\n if (status[i] == FILLED) {\n val thatValue = that[keys[i]]\n if (thatValue != values[i]) {\n return false\n }\n }\n }\n return true\n }\n\n override fun toString(): String {\n val sb = StringBuilder()\n sb.append('{')\n for (i in keys.indices) {\n if (status[i] == FILLED) {\n if (sb.length > 1) {\n sb.append(\", \")\n }\n sb.append(keys[i])\n sb.append('=')\n sb.append(values[i])\n }\n }\n sb.append('}')\n return sb.toString()\n }\n\n private inner class _Ez_Long__Int_HashMapIterator : _Ez_Long__Int_MapIterator {\n private var curIndex = 0\n override fun hasNext(): Boolean {\n return curIndex < status.size\n }\n\n\n override val key: Long\n\n get() {\n if (curIndex == keys.size) {\n throw NoSuchElementException(\"Iterator doesn't have more entries\")\n }\n return keys[curIndex]\n }\n\n\n override val value: Int\n\n get() {\n if (curIndex == values.size) {\n throw NoSuchElementException(\"Iterator doesn't have more entries\")\n }\n return values[curIndex]\n }\n\n override fun next() {\n if (curIndex == status.size) {\n return\n }\n curIndex++\n while (curIndex < status.size && status[curIndex] != FILLED) {\n curIndex++\n }\n }\n\n init {\n while (curIndex < status.size && status[curIndex] != FILLED) {\n curIndex++\n }\n }\n }\n\n init {\n require(capacity >= 0) { \"Capacity must be non-negative\" }\n val length = Integer.highestOneBit(4 * max(1, capacity) - 1)\n // Length is a power of 2 now\n initEmptyTable(length)\n }\n}\n\ninterface _Ez_Long__Int_Map {\n\n val size: Int\n\n fun isEmpty(): Boolean\n\n fun containsKey(\n key: Long\n ): Boolean\n\n operator fun get(\n key: Long\n ): Int\n\n fun put(\n key: Long,\n value: Int\n ): Int\n\n fun remove(\n key: Long\n ): Int\n\n fun clear()\n\n fun keys(): LongArray\n\n fun values(): IntArray\n\n operator fun iterator(): _Ez_Long__Int_MapIterator\n\n override fun toString(): String\n}\n\ninterface _Ez_Long__Int_MapIterator {\n operator fun hasNext(): Boolean\n\n val key: Long\n\n val value: Int\n\n operator fun next()\n}\n\ninline fun LongIntMap.forEach(act: (key: Long, value: Int) -> Unit) {\n val ite = iterator()\n while(ite.hasNext()) {\n act(ite.key, ite.value)\n ite.next()\n }\n}\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 \u96ea\u82b1\u98c4\u98c4\u5317\u98a8\u562f\u562f\u5929\u5730\u4e00\u7247\u84bc\u832b() { 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 }", "lang_cluster": "Kotlin", "tags": ["greedy", "dp", "shortest paths"], "code_uid": "edf574b17fbebdfda33276dc600a2a56", "src_uid": "1961e7c9120ff652b15cad5dd5ca0907", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "998db61908c536311d323fd9ed605774", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "c862834e6dd6c3442339917aed15954f", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun readInts(): List {\n return readLine()!!.split(\" \").map(String::toInt)\n}\n\ntypealias Edge = Pair, Pair>\n\nfun main() {\n var left = Int.MAX_VALUE\n var right = Int.MIN_VALUE\n var top = Int.MIN_VALUE\n var bottom = Int.MAX_VALUE\n val dict = mutableSetOf()\n for (i in 0 until 4) {\n val (x1, y1, x2, y2) = readInts()\n if (x1 == x2 && y1 == y2) {\n println(\"NO\")\n return\n }\n left = left.coerceAtMost(x1.coerceAtMost(x2))\n right = right.coerceAtLeast(x1.coerceAtLeast(x2))\n top = top.coerceAtLeast(y1.coerceAtLeast(y2))\n bottom = bottom.coerceAtMost(y1.coerceAtMost(y2))\n dict.add(Pair(Pair(x1, y1), Pair(x2, y2)))\n dict.add(Pair(Pair(x2, y2), Pair(x1, y1)))\n }\n\n if (left == right || top == bottom) {\n println(\"NO\")\n return\n }\n\n val LT = Pair(left, top)\n val LB = Pair(left, bottom)\n val RT = Pair(right, top)\n val RB = Pair(right, bottom)\n val topEdge = Pair(LT, RT)\n val bottomEdge = Pair(LB, RB)\n val leftEdge = Pair(LT, LB)\n val rightEdge = Pair(RT, RB)\n println(\n if (\n dict.contains(topEdge) &&\n dict.contains(bottomEdge) &&\n dict.contains(leftEdge) &&\n dict.contains(rightEdge)\n )\n \"YES\"\n else\n \"NO\"\n )\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "math", "implementation", "geometry"], "code_uid": "00ec4cea139052ba94fcd035180ddfc7", "src_uid": "ad105c08f63e9761fe90f69630628027", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "3b129484943a1e022bc4b7a0eff53334", "src_uid": "5c73d6e3770dff034d210cdd572ccf0f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "ac35d81391b214b00fd3071c7966ab89", "src_uid": "5c73d6e3770dff034d210cdd572ccf0f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "52069515fab66e5b34142ab167cc63f4", "src_uid": "5c73d6e3770dff034d210cdd572ccf0f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n\n val sc = Scanner(System.`in`)\n val n : Int = sc.nextInt()\n val m : Int = sc.nextInt()\n var k : Int = sc.nextInt()\n val a = IntArray(n)\n var count = n\n\n for (i in 0 until n) a[i] = sc.nextInt()\n Arrays.sort(a)\n\n while (k < m && count > 0) {\n count--\n k += a[count] - 1\n }\n\n if (k < m) print(-1)\n else print(n - count)\n\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "586096ae9739822ae9338664df050518", "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\nfun main(args : Array){\n val reader = Scanner(System.`in`)\n var n: Int = reader.nextInt()\n var b = 0\n\n for(i in 2..n){\n var a = 0\n for(j in 2..i) {\n if (i % j == 0 && checkPrime(j) == 1) {\n a++\n }\n }\n if(a == 2) b++\n }\n println(b)\n}\n\nfun checkPrime(n: Int):Int{\n var a = 0\n for(i in 2..n/2) {\n if (n % i==0) {\n a++\n }\n }\n if(a==0) return 1\n else return 0\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["number theory"], "code_uid": "fe47ebece54fe5f67eb95721f62478c5", "src_uid": "356666366625bc5358bc8b97c8d67bd5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = inp.nextInt()\n val primes = sieve(60)\n var ans = 0\n for (i in 1..n) {\n val set = hashSetOf()\n var j = 0\n var v = i\n while (primes[j] * primes[j] <= v)\n if (v % primes[j] == 0) {\n v /= primes[j]\n set.add(primes[j])\n } else\n j++\n if (v > 1)\n set.add(v)\n if (set.size == 2)\n ans++\n }\n out.println(ans)\n }\n\n private fun sieve(max: Int): IntArray {\n val a = Array(max + 1) { true }\n val primes = arrayListOf()\n for (i in 2..max)\n if (a[i]) {\n primes.add(i)\n var j = 2 * i\n while (j <= max) {\n a[j] = false\n j += i\n }\n }\n return primes.toIntArray()\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", "lang_cluster": "Kotlin", "tags": ["number theory"], "code_uid": "c233f3afe92b13c259eacf37c2f821fa", "src_uid": "356666366625bc5358bc8b97c8d67bd5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.sqrt\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!.toInt()\n val prime = mutableSetOf()\n fun isprime(i: Int) = (2..sqrt(i.toDouble()).toInt()).none { i % it == 0 }\n for (i in 2..3000){\n if (isprime(i)){\n prime += i\n }\n }\n fun fac(i:Int):List{\n val ans = mutableListOf()\n for (j in 2..sqrt(i.toDouble()).toInt()){\n if (i%j==0){\n ans+=j\n if (i/j>j){\n ans+=i/j\n }\n }\n }\n return ans\n }\n var ans = 0\n loop@for (j in 1..n){\n val divisor = fac(j)\n //println(\"$j ${divisor}\")\n var cnt = 0\n for (div in divisor){\n if (div in prime){\n cnt++\n if (cnt>2){\n continue@loop\n }\n }\n }\n if (cnt==2) {\n ans++\n //println(j)\n }\n }\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["number theory"], "code_uid": "ff04f87915a033ad2c4ae3825755ab44", "src_uid": "356666366625bc5358bc8b97c8d67bd5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val n = reader.readLine().toInt()\n println((1..n).count { x ->\n var z = x\n val primes = hashSetOf()\n (2 until x).forEach {\n while (z % it == 0) {\n primes.add(it)\n z /= it\n }\n }\n primes.size == 2\n })\n}", "lang_cluster": "Kotlin", "tags": ["number theory"], "code_uid": "f632047561c50992dfb40df733dba0a2", "src_uid": "356666366625bc5358bc8b97c8d67bd5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun readIntList() = readLine()!!.split(' ').map(String::toInt).toMutableList()\nfun readLongList() = readLine()!!.split(' ').map(String::toLong).toMutableList()\nfun readInt() = readLine()!!.toInt()\n\nfun main(args: Array) {\n val f = readLine()!!\n val m = readLine()!!\n val s = readLine()!!\n\n\n if (isGreaterThan(f, m) && isGreaterThan(f, s)) {\n println(\"F\")\n } else if (isGreaterThan(m, f) && isGreaterThan(m, s)) {\n println(\"M\")\n }else if (isGreaterThan(s, m) && isGreaterThan(s, f)) {\n println(\"S\")\n }else {\n println(\"?\")\n }\n\n}\n\nfun isGreaterThan(str1: String, str2: String): Boolean {\n return (str1 == \"scissors\" && str2 == \"paper\") || (str1 == \"paper\" && str2 == \"rock\") || (str1 == \"rock\" && str2 == \"scissors\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5b7d14642678b27344802425df680184", "src_uid": "072c7d29a1b338609a72ab6b73988282", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args : Array) {\n\n val F = readLine()!!\n val M = readLine()!!\n val S = readLine()!!\n val list = arrayOf(\"scissors\",\"rock\",\"paper\")\n\n var a = 0\n var b = 0\n var c = 0\n\n for(i in 0..2){\n if(list[i]==F){ a = i }\n }\n for(i in 0..2){\n if(list[i]==M){ b = i }\n }\n for(i in 0..2){\n if(list[i]==S){ c = i }\n }\n\n if(a==b && a==c && b==c){\n println(\"?\")\n }\n else if(a!=b && a!=c && b!=c){\n println(\"?\")\n }\n else if(a!=b && b==c){\n if((win(a,b))==1){\n println(\"F\")\n }\n else {\n println(\"?\")\n }\n }\n else if(b!=a && a==c){\n if((win(b,a))==1){\n println(\"M\")\n }\n else {\n println(\"?\")\n }\n }\n else if(c!=b && b==a){\n if((win(c,b))==1){\n println(\"S\")\n }\n else {\n println(\"?\")\n }\n }\n else{\n println(\"?\")\n }\n}\n\nfun win(x:Int, y: Int):Int{\n if((x==2 && y == 1) || (x==1 && y==0) || ( x== 0 && y==2)) {return 1}\n else return 0\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7688641a993a00da792c8a7dc5d04fa3", "src_uid": "072c7d29a1b338609a72ab6b73988282", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "enum class SetType {\n EMPTY,\n LINE,\n WHOLE_FIELD\n}\n\ntypealias Line = Triple\nfun Line.a() = first\nfun Line.b() = second\nfun Line.c() = third\n\n\nfun Line.setType(): SetType {\n if (a() == 0 && b() == 0 && c() == 0) return SetType.WHOLE_FIELD\n if (a() == 0 && b() == 0) return SetType.EMPTY\n return SetType.LINE\n}\n\nfun calcDet(line1: Line, line2: Line) = line1.a() * line2.b() - line1.b() * line2.a()\n\nfun calcIntersections(line1: Line, line2: Line): Int {\n if (line1.setType() == SetType.EMPTY || line2.setType() == SetType.EMPTY) return 0\n if (line1.setType() == SetType.WHOLE_FIELD || line2.setType() == SetType.WHOLE_FIELD) return -1\n val det = calcDet(line1, line2)\n if (det != 0) return 1\n\n return if (line1.first != 0) {\n val c1f = line1.c() * line2.a()\n val c2f = line2.c() * line1.a()\n if (c1f == c2f) -1 else 0\n } else {\n val c1f = line1.c() * line2.b()\n val c2f = line2.c() * line1.b()\n if (c1f == c2f) -1 else 0\n }\n}\n\nfun main(args: Array) {\n val line1 = readLine()!!.split(\" \").filter { it.isNotBlank() }.map { it.toInt() }.toIntArray()\n val line2 = readLine()!!.split(\" \").filter { it.isNotBlank() }.map { it.toInt() }.toIntArray()\n\n val line1T = Triple(line1[0], line1[1], line1[2])\n val line2T = Triple(line2[0], line2[1], line2[2])\n\n println(calcIntersections(line1T, line2T))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "58c6830f89d91528b2aef5f9d5a5e0ec", "src_uid": "c8e869cb17550e888733551c749f2e1a", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.DataInputStream\nimport java.io.InputStream\nimport java.lang.StringBuilder\nimport kotlin.math.min\n\ninternal class Parserdoubt(`in`: InputStream) {\n private val BUFFER_SIZE = 1 shl 17\n\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 @Throws(Exception::class)\n fun nextString(): String {\n val sb = StringBuffer(\"\")\n var c = read()\n while (c <= ' '.toByte())\n c = read()\n do {\n sb.append(c.toChar())\n c = read()\n } while (c > ' '.toByte())\n return sb.toString()\n }\n\n @Throws(Exception::class)\n fun wholeLine(): String {\n val sb = StringBuffer(\"\")\n var c = read()\n while (c <= '\\n'.toByte())\n c = read()\n do {\n sb.append(c.toChar())\n c = read()\n } while (c > '\\n'.toByte())\n return sb.toString()\n }\n\n @Throws(Exception::class)\n fun nextChar(): Char {\n var c = read()\n while (c <= ' '.toByte())\n c = read()\n return c.toChar()\n }\n\n @Throws(Exception::class)\n fun nextInt(): Int {\n var ret = 0\n var c = read()\n while (c <= ' '.toByte())\n c = read()\n val 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 return if (neg) -ret else ret\n }\n\n @Throws(Exception::class)\n fun nextLong(): Long {\n var ret: Long = 0\n var c = read()\n while (c <= ' '.toByte())\n c = read()\n val 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 return if (neg) -ret else ret\n }\n\n @Throws(Exception::class)\n private fun fillBuffer() {\n bufferPointer = 0\n bytesRead = din.read(buffer, 0, BUFFER_SIZE)\n if (bytesRead == -1)\n buffer[0] = -1\n }\n\n @Throws(Exception::class)\n private fun read(): Byte {\n if (bufferPointer == bytesRead)\n fillBuffer()\n return buffer[bufferPointer++]\n }\n}\n\ndata class E (\n val cnt:Int,\n val id: Int\n): Comparable {\n override fun compareTo(other: E): Int {\n return other.cnt - cnt\n }\n}\n\nfun main(args : Array) {\n val input = Parserdoubt(`in` = System.`in`)\n val NT = 1//input.nextInt()\n val sb = StringBuilder()\n for(test in 1..NT){\n val c = input.nextInt()\n val r = input.nextInt()\n val n = input.nextInt() - 1\n var ans = 0\n\n for(i in -5000 .. 5000 step 2){\n if(i<0){\n val start = -i\n val num = min(r - start, c)\n if(num <= 0)continue\n if(num%2==1){\n if(num/2 == n)ans ++\n else if(num/2 > n)ans +=2\n }else {\n if(num/2 > n)ans +=2\n }\n } else {\n val end = c - i\n val num = min(r, end)\n if(num <= 0)continue\n if(num%2==1){\n if(num/2 == n)ans ++\n else if(num/2 > n)ans +=2\n }else {\n if(num/2 > n)ans +=2\n }\n }\n }\n println(ans)\n\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "22f3fbd72a22ae15f44f703cf1596300", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n,m)=readLine()!!.split(' ').take(2).map { it.toInt() }\n val x = readLine()!!.toInt()\n val (r, c) = n - 2 * x to m - 2 * x\n fun ans(x: Int):Int {\n val (r, c) = n - 2 * (x - 1) to m - 2 * (x - 1)\n return if (r < 0 || c < 0)\n 0\n else\n ((r-(r / 2)) * ((c + 1) / 2)) + ((r / 2) * (c / 2))\n }\n println(ans(x) - ans(x+1))\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "ae9c843cb4723321c542c9e70783062b", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\nimport kotlin.math.min\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 x: Int = reader.nextInt()\n var y: Int = reader.nextInt()\n\n var d = gcd(x,y)\n x = x / d\n y = y / d\n\n var m = min(a/x, b/y)\n\n print(m*x)\n print(\" \")\n print(m*y)\n\n}\n\nfun gcd(a:Int, b: Int):Int{\n if(b==0){\n return a\n }\n else{\n return gcd(b,a%b)\n }\n}", "lang_cluster": "Kotlin", "tags": ["binary search", "number theory"], "code_uid": "11e3ad337099ea6c80ec0098ab8744a6", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, k) = readLine()!!.split(\" \").map(String::toLong)\n val ans = if (k == 1L) n else n.toString(2).replace('0', '1').toLong(2)\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "number theory", "bitmasks"], "code_uid": "fb4e8266ec4a5b7d3ae24374aad2b806", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (n, k) = readLine()!!.split(\" \").map(String::toLong)\n if (k == 1L) print(n) else {\n var result = Long.MAX_VALUE\n while (result shr 1 >= n) result = result shr 1\n print(result)\n }\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "number theory", "bitmasks"], "code_uid": "b708be1b3b9cccc079026208220ae5c7", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "29b8c0f0c0500d889ca340d21fc122e8", "src_uid": "a307b402b20554ce177a73db07170691", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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)", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "593d67eab8ad06509deaade86316997c", "src_uid": "a307b402b20554ce177a73db07170691", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "1832e20613bf897ba1a4567669dcc978", "src_uid": "a307b402b20554ce177a73db07170691", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "86f7d6de41407151c30d55e827de88f7", "src_uid": "a307b402b20554ce177a73db07170691", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.util.*\n//https://codeforces.com/problemset/problem/570/B\nfun main(args: Array) = with(Scanner(System.`in`)){\n val n = nextLong()\n val m = nextLong()\n val lM = m - 1\n val rM = n - m \n \n var ans = 0L\n if(lM >= rM) {\n ans = (m - 1)\n } else {\n ans = (m + 1)\n }\n if(ans <= 0) {\n ans = 1\n }\n if(ans > n) {\n ans = n\n }\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "games", "math", "greedy", "implementation"], "code_uid": "2ad39ec8859fdf808910bbb802d777e6", "src_uid": "f6a80c0f474cae1e201032e1df10e9f7", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main() {\n val (n, m) = readLine()!!.split(\" \").map(String::toInt)\n if (m <= n / 2.0) print(m + 1) else print(max(1, m - 1))\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "games", "math", "greedy", "implementation"], "code_uid": "7973adc6f66bdf657aac36316004bdd0", "src_uid": "f6a80c0f474cae1e201032e1df10e9f7", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var p:List = readLine()!!.split(\" \").map {x -> x.toLong()}\n var n :Long = p[0]\n var a :Long = p[1]\n var b :Long = p[2]\n var c :Long = p[3]\n var d :Long = p[4]\n var A :Long = 0\n var B :Long = a - d\n var C :Long = (B + b) - (c)\n var D :Long = (d + C) - (a)\n var mn :Long = listOf(A, B, C, D).min()!!.toLong()\n if(mn < 1) {\n mn -= 1\n A -= mn\n B -= mn\n C -= mn\n D -= mn\n }\n var mx :Long = listOf(A, B, C, D).max()!!.toLong()\n var res :Long = (n - mx + 1)*(n)\n if(res <= 0) {\n res = 0\n }\n println(res)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "43c1b13277cf6856b1ec95ac17e15bc9", "src_uid": "b732869015baf3dee5094c51a309e32c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (n, a, b, c, d) = readLine()!!.split(\" \").map(String::toInt)\n var sol = 0L\n for (x1 in 1..n) {\n if (x1 + b - c in 1..n &&\n x1 + a - d in 1..n &&\n x1 + a + b - c - d in 1..n\n )\n sol++\n }\n print(sol * n)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "9ac29b5382b5c681c1d5b925e691a532", "src_uid": "b732869015baf3dee5094c51a309e32c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\nimport java.util.*\nimport java.math.*\n\nfun main(args : Array) = with(Scanner(System.`in`)) {\n\tvar n = nextInt()\n\tvar arr = Array(n) { nextInt() } \n\tfor (i in n downTo 1){\n\t\tfor (j in 1..(i-1)){\n\t\t\tif(abs(arr[j] - arr[j-1]) >= 2){\n\t\t\t\tprintln(\"NO\")\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t\tvar pos = 0\n\t\tfor (j in 1..(i-1)){\n\t\t\tif(arr[j] > arr[pos]) pos = j\n\t\t}\n\t\tfor (j in pos..(i-2)){\n\t\t\tarr[j] = arr[j+1]\n\t\t}\n\t}\n\tprintln(\"YES\")\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4d8b68b2f107f10cf2bc289c18aeca45", "src_uid": "704d0ae50bccaa8bc49319812ae0be45", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main() {\n val colors = readLine()!!.split(\" \").map(String::toInt)\n var sol = 0\n for ((pos, numPeople) in colors.withIndex()) {\n if (numPeople > 0) {\n val numCars = numPeople / 2 + if (numPeople % 2 != 0) 1 else 0\n sol = max(sol, pos + 3 * (numCars - 1) + 30)\n }\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "13623e3fb02574f978eac27f18a4f7b8", "src_uid": "a45daac108076102da54e07e1e2a37d7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun binExp(a: Long, n: Long): Long{\n tailrec fun go(a: Long, n: Long, a1: Long): Long{\n if (n == 0.toLong()) return 1\n if (n == 1.toLong()) return a * a1\n\n if (n % 2 == 0.toLong()) return go(a * a, n/2, a1)\n else return go(a * a, (n - 1)/2, a * a1)\n }\n return go(a, n, 1)\n}\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val n = br.readLine().toInt()\n val x1 = 4*3* binExp(4, (n - 3).toLong())*2\n val x2 = if (n > 3) 4*3*3* binExp(4, (n - 4).toLong())*(n - 3) else 0\n println(x1 + x2)\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "c79db26c0ed9269115f945ad3bb4ee32", "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args : Array) {\n val (a, b) = readLine()!!.split(' ')\n var n = a.toInt()\n var m = b.toInt()\n var r = 0\n while(m>0){\n r = r*10+m%10\n m = m/10\n }\n\n println(n+r)\n\n\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms"], "code_uid": "0ad45e7bfd29be78e3a0ef14649c1259", "src_uid": "69b219054cad0844fc4f15df463e09c0", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun main() {\n\n val sc = Scanner(System.`in`)\n val a1 : Int = sc.nextInt()\n val a2 : Long\n val line : String = sc.next()\n var newLine = \"\"\n\n for (i in (line.length - 1) downTo 0) {\n newLine += line[i]\n }\n\n a2 = newLine.toLong()\n\n print(a1 + a2)\n\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms"], "code_uid": "8cc13d7bca0667c64f29ed3a5823fc12", "src_uid": "69b219054cad0844fc4f15df463e09c0", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\nfun main(){\n \tval reader=Scanner(System.`in`) \n var a:Int=reader.nextInt()\n var b:Int=reader.nextInt()\n var c=0\n while(b>0){\n c=c*10+(b%10)\n b/=10\n }\n print(a+c)\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms"], "code_uid": "39e6afb5545b2468e11a55f2430757c8", "src_uid": "69b219054cad0844fc4f15df463e09c0", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.Comparator\n\n\nclass Solution : Runnable {\n override fun run() {\n solve()\n }\n\n fun start() {\n Thread(null, Solution(), \"whatever\", (1 shl 27).toLong()).start()\n }\n}\n\nfun main(args: Array) {\n Solution().start()\n}\n\n\nclass IO {\n companion object {\n\n private val reader: InputReader\n private val writer: OutputWriter\n\n init {\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n reader = InputReader(FileInputStream(\"/Users/300041735/competitiveProgramming/src/codeforces/in.txt\"))\n writer = OutputWriter(FileOutputStream(\"/Users/300041735/competitiveProgramming/src/codeforces/out.txt\"))\n } else {\n reader = InputReader(System.`in`)\n writer = OutputWriter(System.`out`)\n }\n }\n\n private fun readMultipleInts(count: Int): List {\n val map = mutableListOf()\n repeat(count) {\n map.add(reader.readInt())\n }\n return map\n }\n\n fun readInt() = reader.readInt()\n fun readLong() = reader.readLong()\n fun readTwoInts() = readMultipleInts(2)\n fun readThreeInts() = readMultipleInts(3)\n fun readFourInts() = readMultipleInts(4)\n fun readFiveInts() = readMultipleInts(5)\n fun readSixInts() = readMultipleInts(6)\n fun readString() = reader.readString()\n fun readTree(n: Int): MutableMap> {\n val graph = mutableMapOf>()\n repeat(n - 1) {\n val u = reader.readInt()\n val v = reader.readInt()\n if (!graph.containsKey(u)) graph[u] = mutableListOf()\n graph[u]!!.add(v)\n }\n return graph\n }\n\n fun readIntArray(n: Int): IntArray {\n return IntArray(n) { readInt() }\n }\n\n fun readLongArray(n: Int): Array {\n return Array(n) { readLong() }\n }\n\n fun write(obj: Any) {\n writer.printLine(obj)\n }\n\n fun flushOutput() {\n writer.flush()\n }\n\n fun closeOutput() {\n writer.close()\n }\n }\n}\n\n\nclass MATH {\n companion object {\n\n val mod = 998244353\n var ispre = false\n\n val factMod = Array(300002) { 1 }\n\n fun pre() {\n for (i in 2 until 300001) {\n factMod[i] = ((factMod[i - 1] * i.toLong()) % MATH.mod).toInt()\n }\n }\n\n fun gcd(a: Int, b: Int): Int {\n if (b == 0)\n return a\n return gcd(b, a % b)\n }\n\n fun gcd(a: Long, b: Long): Long {\n if (b == 0L)\n return a\n return gcd(b, a % b)\n }\n\n fun inverseMod(a: Int): Int {\n return powMod(a, mod - 2)\n }\n\n fun powMod(a: Int, b: Int): Int {\n //calculate a to the power b mod m\n if (b == 0) return 1\n return if (b % 2 == 1) {\n prodMod(a, powMod(a, b - 1))\n } else {\n val p = powMod(a, b / 2)\n prodMod(p, p)\n }\n }\n\n fun ncr(n: Int, r: Int): Int {\n if (!ispre) pre(); ispre = true\n return ((factMod[n].toLong() * inverseMod(((factMod[r].toLong() * factMod[n - r]) % mod).toInt())) % mod).toInt()\n }\n\n fun prodMod(val1: Int, val2: Int): Int {\n return ((val1.toLong() * val2) % mod).toInt()\n }\n\n }\n}\n\nfun solve() {\n\n val n = IO.readInt()\n if (n%2 == 0){\n IO.write(\"white\")\n IO.write(\"1 2\")\n }else{\n IO.write(\"black\")\n }\n\n IO.flushOutput()\n IO.closeOutput()\n}\n\n\nclass SuffixArray(val input : String){\n //time complexity is n(log(n))^2\n\n fun sa() : IntArray{\n val n = input.length\n var cur = IntArray(n) { i -> input[i] -'a' } //will store the current sort order\n for (i in 1 until 20){\n val newCur = IntArray(n) { 0 }\n val newlist = mutableListOf>()\n for (j in 0 until n) {\n newlist.add(Triple(j, cur[j], if ( j+ power(2, i) < n) cur[j + power(2, i)] else -1))\n }\n newlist.sortWith(comparator())\n //after sorting\n for (j in 0 until n){\n newCur[newlist[j].first] = if (j > 0 && newlist[j].second == newlist[j - 1].second && newlist[j].third == newlist[j - 1].third) newCur[newlist[j - 1].first] else j\n }\n cur = newCur\n\n }\n return cur\n }\n\n internal class comparator : Comparator>{\n override fun compare(o1: Triple?, o2: Triple?): Int {\n if (o1!!.second != o2!!.second){\n return o1.second.compareTo(o2.second)\n }else{\n //both are equal what to do now\n return o1.third.compareTo(o2.third)\n }\n }\n }\n\n\n}\n\n\n\nclass Primes{\n val limit = 1000\n val composites = IntArray(limit + 1) { 0 }\n val factors= IntArray(limit + 1) { 0 }\n val preFactors = IntArray(limit + 1) { 0 }\n val primes = mutableListOf()\n\n init {\n sieve()\n calcFactors()\n }\n\n fun sieve(){\n for (i in 2 until limit + 1){\n if (composites[i] == 0){\n primes.add(i)\n var cur = 1\n while (cur*i <= limit){\n composites[cur*i] = i\n cur++\n }\n }\n }\n }\n\n fun calcFactors(){\n for (i in 2 until limit + 1){\n var num = i\n while (num != 1){\n factors[i]++\n num /= composites[num]\n }\n }\n for (i in 2 until limit + 1){\n preFactors[i]= preFactors[i - 1] + factors[i]\n }\n }\n}\n\n\n\nfun isBitSet(num: Int, i: Int): Boolean {\n return (num.and(1.shl(i)) > 0)\n}\n\nfun power(i: Int, j: Int): Int {\n if (j == 0) return 1\n return i * power(i, j - 1)\n}\n\nclass MinSegmentTree(\n input: Array\n) {\n private val tree: Array\n private val lazy: Array\n\n constructor(size: Int) : this(Array(size) { Int.MAX_VALUE })\n\n init {\n val size = nextPowerOfTwo(input.size)\n tree = Array(2 * size) { Int.MAX_VALUE }\n lazy = Array(2 * size) { Int.MAX_VALUE }\n for (i in 0 until input.size) {\n tree[i + size] = input[i]\n }\n for (i in (size - 1) downTo 1) {\n tree[i] = Math.min(tree[leftChild(i)], tree[rightChild(i)])\n }\n }\n\n private fun updateTree(lowerRange: Int, upperRange: Int, lowerBound: Int, upperBound: Int, index: Int, value: Int) {\n updateLazyNode(index, lowerBound, upperBound, lazy[index])\n if (noOverlap(lowerRange, upperRange, lowerBound, upperBound)) return\n else if (completeOverlap(lowerRange, upperRange, lowerBound, upperBound)) updateLazyNode(index, lowerBound, upperBound, value)\n else {\n updateTree(lowerRange, upperRange, lowerBound, midIndex(lowerBound, upperBound), leftChild(index), value)\n updateTree(lowerRange, upperRange, midIndex(lowerBound, upperBound) + 1, upperBound, rightChild(index), value)\n tree[index] = Math.min(tree[leftChild(index)], tree[rightChild(index)])\n }\n }\n\n private fun queryTree(lowerRange: Int, upperRange: Int, lowerBound: Int, upperBound: Int, index: Int): Int {\n updateLazyNode(index, lowerBound, upperBound, lazy[index])\n if (noOverlap(lowerRange, upperRange, lowerBound, upperBound)) return Int.MAX_VALUE\n else if (completeOverlap(lowerRange, upperRange, lowerBound, upperBound)) return tree[index]\n else {\n return Math.min(queryTree(lowerRange, upperRange, lowerBound, midIndex(lowerBound, upperBound), leftChild(index)),\n queryTree(lowerRange, upperRange, midIndex(lowerBound, upperBound) + 1, upperBound, rightChild(index)))\n }\n }\n\n private fun updateLazyNode(index: Int, lowerBound: Int, upperBound: Int, delta: Int) {\n tree[index] += delta\n if (lowerBound != upperBound) {\n lazy[leftChild(index)] += delta\n lazy[rightChild(index)] += delta\n }\n lazy[index] = 0\n }\n\n fun getElements(N: Int): List {\n return tree.copyOfRange(tree.size / 2, tree.size / 2 + N).asList()\n }\n\n fun update(lowerRange: Int, upperRange: Int, value: Int) {\n updateTree(lowerRange, upperRange, 1, lazy.size / 2, 1, value)\n }\n\n fun query(lowerRange: Int, upperRange: Int): Int {\n return queryTree(lowerRange, upperRange, 1, lazy.size / 2, 1)\n }\n\n private fun noOverlap(l: Int, u: Int, lb: Int, ub: Int): Boolean = (lb > u || ub < l)\n\n private fun completeOverlap(l: Int, u: Int, lb: Int, ub: Int): Boolean = (lb >= l && ub <= u)\n\n\n private fun nextPowerOfTwo(num: Int): Int {\n var exponent = 2\n while (true) {\n if (exponent >= num) {\n return exponent\n }\n exponent *= 2\n }\n }\n\n private fun midIndex(l: Int, r: Int) = (l + r) / 2\n private fun parent(i: Int) = i / 2\n private fun leftChild(i: Int) = 2 * i\n private fun rightChild(i: Int) = 2 * i + 1\n\n}\n\nclass 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 }\n var sgn: Long = 1\n if (c == '-'.toInt()) {\n sgn = -1\n c = read()\n }\n var number: Long = 0\n do {\n number *= 10L\n number += (c - '0'.toInt()).toLong()\n c = read()\n } while (!isSpaceChar(c))\n return number * 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\nclass 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 fun flush() {\n writer.flush()\n }\n\n}\n\nclass DinitzMaxFlowSolver(val n: Int, val s: Int, val t: Int, val graph: MutableMap>, val edgeMap: MutableMap, Edge>) {\n\n private val level = IntArray(n + 1) { -1 } //storing levels of each vertex in level graph\n var maxFlow = 0L\n\n init {\n solve()\n }\n\n fun solve() {\n val next = IntArray(n + 1) { 0 }\n while (bfs()) {\n Arrays.fill(next, 0)\n var flow = 0L\n do {\n maxFlow += flow\n flow = dfs(s, next, Long.MAX_VALUE)\n } while (flow != 0L)\n }\n }\n\n private fun dfs(at: Int, next: IntArray, flow: Long): Long {\n if (at == t) return flow\n var size = 0\n if (graph.containsKey(at)) size = graph[at]!!.size\n while (next[at] < size) {\n val edge = graph[at]!!.get(next[at])\n if (edge.remainingCapacity() > 0 && level[edge.to] == level[at] + 1) {\n val bottleNeck = dfs(edge.to, next, Math.min(flow, edge.remainingCapacity()))\n if (bottleNeck > 0) {\n edgeMap[Pair(edge.from, edge.to)]!!.flow += bottleNeck\n edgeMap[Pair(edge.to, edge.from)]!!.flow -= bottleNeck\n return bottleNeck\n }\n }\n next[at]++\n }\n return 0\n }\n\n private fun bfs(): Boolean {\n Arrays.fill(level, -1)\n val curLevel = ArrayDeque()\n curLevel.add(s)\n level[s] = 0\n\n while (curLevel.isNotEmpty()) {\n val top = curLevel.poll()\n if (graph.containsKey(top)) {\n graph[top]!!.forEach {\n if (it.remainingCapacity() > 0 && level[it.to] == -1) {\n level[it.to] = level[top] + 1\n curLevel.offer(it.to)\n }\n }\n }\n }\n return level[t] != -1\n }\n\n\n}\n\nclass Edge(val from: Int, val to: Int, val capacity: Long) {\n var flow = 0L\n fun remainingCapacity(): Long {\n return capacity - flow\n }\n}\n\n\nclass ConnectedComponents(val g : Graph, val price : IntArray){\n\n private val visited = HashSet()\n private val stack = Stack()\n private val revertedGraph = revertGraph()\n private val component = mutableListOf()\n var ways= 1L\n var min = 0L\n val mod = 1000000007\n\n init {\n getConnectedComponents()\n }\n\n\n fun getConnectedComponents() {\n g.vertices.forEach {\n if (!visited.contains(it)){\n visited.add(it)\n dfs(it)\n }\n }\n\n visited.clear()\n while (stack.isNotEmpty()){\n val node = stack.pop()\n if (!visited.contains(node)){\n visited.add(node)\n dfs2(node)\n var take = Int.MAX_VALUE\n for (i in 0 until component.size){\n if (price[component[i] - 1] < take){\n take = price[component[i] - 1]\n }\n }\n min+= take\n ways= (ways*component.filter { price[it - 1] == take }.count())%mod\n component.clear()\n }\n }\n }\n\n fun dfs(node : Int){\n if (g.edges.containsKey(node)){\n g.edges[node]!!.forEach {\n if (!visited.contains(it)){\n visited.add(it)\n dfs(it)\n }\n }\n }\n stack.push(node)\n }\n\n fun dfs2(node : Int){\n component.add(node)\n if (revertedGraph.edges.containsKey(node)){\n revertedGraph.edges[node]!!.forEach {\n if (!visited.contains(it)){\n visited.add(it)\n dfs2(it)\n }\n }\n }\n }\n\n fun revertGraph() : Graph {\n val newEdges= mutableMapOf>()\n g.edges.forEach {\n val u = it.key\n val vs = it.value\n vs.forEach { v ->\n if (!newEdges.containsKey(v)){\n newEdges[v]= mutableListOf()\n }\n newEdges[v]!!.add(u)\n }\n }\n return Graph(g.vertices, newEdges)\n }\n}\n\ndata class Graph(val vertices: MutableList, val edges : MutableMap>)\n", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "games"], "code_uid": "630ffd4932448ab164f211c0ef396332", "src_uid": "52e07d176aa1d370788f94ee2e61df93", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLine()\n println((s!![0].toString() + s[2] + s[4] + s[3] + s[1]).toBigInteger().pow(5).toString().takeLast(5))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "bf039ebaa51f51c95f574209bfbeab5e", "src_uid": "51b1c216948663fff721c28d131bf18f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : InputReader, pw : PrintWriter) {\n\n var n : Long = ir.nextLong()\n var count = 0\n\n while (n > 0) {\n var max = '0'\n val line : String = n.toString()\n\n for (i in 0 until line.length)\n if (line[i] > max)\n max = line[i]\n\n n -= max.toInt() - 48\n count++\n\n }\n\n pw.print(count)\n\n}\n\nclass InputReader(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}", "lang_cluster": "Kotlin", "tags": ["dp"], "code_uid": "59051962a067b4c735bdb2a8f6f21e60", "src_uid": "fc5765b9bd18dc7555fa76e91530c036", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //var (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n var len = r.readLine()!!.toLong()+1\n var ans = 1L\n var base = 2L\n while (len>0){\n if (len%2==1L){\n ans *= base\n }\n base *= base\n len/=2\n }\n println(ans-2)\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "728d671749ae4f90aaa827e228af6eaa", "src_uid": "f1b43baa14d4c262ba616d892525dfde", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintStream\n\nval Number.i: Int get() = this.toInt()\nval Number.l: Long get() = this.toLong()\nval Number.f: Float get() = this.toFloat()\nval Number.d: Double get() = this.toDouble()\nval String.i: Int get() = this.toInt()\nval String.l: Long get() = this.toLong()\nval String.f: Float get() = this.toFloat()\nval String.d: Double get() = this.toDouble()\nval Boolean.i: Int get() = if (this) 1 else 0\n\noperator fun List.component6() = this[5]\n\nfun main() = BufferedReader(InputStreamReader(System.`in`)).use { solve(it, System.out) }\n\nfun solve(input: BufferedReader, output: PrintStream) {\n val (x0, y0, x1, y1, x2, y2) = input.readLine().split(' ').map { it.l }\n\n output.println(\n if (isGood(x0, y0, x1, y1, x2, y2)) \"RIGHT\"\n else if (\n isGood(x0 - 1, y0, x1, y1, x2, y2) ||\n isGood(x0 + 1, y0, x1, y1, x2, y2) ||\n isGood(x0, y0 - 1, x1, y1, x2, y2) ||\n isGood(x0, y0 + 1, x1, y1, x2, y2) ||\n\n isGood(x0, y0, x1 - 1, y1, x2, y2) ||\n isGood(x0, y0, x1 + 1, y1, x2, y2) ||\n isGood(x0, y0, x1, y1 - 1, x2, y2) ||\n isGood(x0, y0, x1, y1 + 1, x2, y2) ||\n\n isGood(x0, y0, x1, y1, x2 - 1, y2) ||\n isGood(x0, y0, x1, y1, x2 + 1, y2) ||\n isGood(x0, y0, x1, y1, x2, y2 - 1) ||\n isGood(x0, y0, x1, y1, x2, y2 + 1)\n ) \"ALMOST\"\n else \"NEITHER\"\n )\n}\n\nfun l(x0: Long, y0: Long, x1: Long, y1: Long) = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)\nfun isGood(x0: Long, y0: Long, x1: Long, y1: Long, x2: Long, y2: Long) = isGood(l(x0, y0, x1, y1), l(x0, y0, x2, y2), l(x1, y1, x2, y2))\nfun isGood(a: Long, b: Long, c: Long) =\n if (a == 0L || b == 0L || c == 0L)\n false\n else if (a > b && a > c)\n a - b - c == 0L\n else if (b > a && b > c)\n b - a - c == 0L\n else\n c - a - b == 0L\n", "lang_cluster": "Kotlin", "tags": ["brute force", "geometry"], "code_uid": "4f6deac4eee0ba033175c9b5513b1236", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "e6220f058bf06d654f2e7725b91c8a70", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "b10c107e1e82ec55aa85fb1c066d5a78", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val numToLine = mapOf('0' to \"O-|-OOOO\", '1' to \"O-|O-OOO\", '2' to \"O-|OO-OO\", '3' to \"O-|OOO-O\", '4' to \"O-|OOOO-\",\n '5' to \"-O|-OOOO\", '6' to \"-O|O-OOO\", '7' to \"-O|OO-OO\", '8' to \"-O|OOO-O\", '9' to \"-O|OOOO-\")\n for (c in readLine()!!.reversed()) println(numToLine[c]!!)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d368242f5ad7e975583bf18c5c6f1fb2", "src_uid": "c2e3aced0bc76b6484360563355d23a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val jin = BufferedReader(InputStreamReader(System.`in`))\n val (n, k) = jin.readLine().split(\" \").map { it.toInt() }\n val s = \" \" + jin.readLine()\n val t = jin.readLine()\n if (t[0] == t[1]) {\n val amt = min(n, s.count { it == t[0] } + k)\n println((amt * (amt - 1)) / 2)\n } else {\n val dp = Array(n + 1) { Array(k + 1) { IntArray(n + 1) { -1 } } }\n dp[0][0][0] = 0\n var answer = 0\n for (a in 1..n) {\n for (b in 0..k) {\n for (c in 0..n) {\n if (s[a] == t[0]) {\n if (c > 0 && dp[a - 1][b][c - 1] != -1) {\n dp[a][b][c] = dp[a - 1][b][c - 1]\n }\n if (b > 0 && dp[a - 1][b - 1][c] != -1) {\n dp[a][b][c] = max(dp[a][b][c], dp[a - 1][b - 1][c] + c)\n }\n } else if (s[a] == t[1]) {\n if (dp[a - 1][b][c] != -1) {\n dp[a][b][c] = dp[a - 1][b][c] + c\n }\n if (b > 0 && c > 0 && dp[a - 1][b - 1][c - 1] != -1) {\n dp[a][b][c] = max(dp[a][b][c], dp[a - 1][b - 1][c - 1])\n }\n } else {\n if (dp[a - 1][b][c] != -1) {\n dp[a][b][c] = dp[a - 1][b][c]\n }\n if (b > 0 && c > 0 && dp[a - 1][b - 1][c - 1] != -1) {\n dp[a][b][c] = max(dp[a][b][c], dp[a - 1][b - 1][c - 1])\n }\n if (b > 0 && dp[a - 1][b - 1][c] != -1) {\n dp[a][b][c] = max(dp[a][b][c], dp[a - 1][b - 1][c] + c)\n }\n }\n answer = max(answer, dp[a][b][c])\n }\n }\n }\n println(answer)\n }\n}", "lang_cluster": "Kotlin", "tags": ["strings", "dp"], "code_uid": "a768e0cd0b256e15733e2e9cfff86cc8", "src_uid": "9c700390ac13942cbde7c3428965b18a", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n//@file:OptIn(ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport java.util.PriorityQueue\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 n = readInt()\n val k = readInt()\n val s = CharArray(n) { readChar() }.also { readChar() }\n val a = readChar()\n val b = readChar()\n\n val ans = if(a == b) {\n val x = min(n, k + s.count { it == a })\n x * (x-1) / 2\n } else {\n // Di[x][y] = score\n // x = number of moves used\n // y = number of a's made\n\n var D = Array(1) { IntArray(1) }\n\n for(i in 0 until n) {\n val si = s[i]\n val diff = si != a && si != b\n val Di = Array(min(k, i+1)+1) { IntArray(i+2) { -1 } }\n\n for(x in D.indices) {\n for(y in D[x].indices) {\n val d = D[x][y]\n if(d == -1) continue\n if(diff) Di[x].setMax(y, d)\n\n // a\n run {\n val nx = if(si == a) x else x+1\n if(nx <= k) Di[nx].setMax(y+1, d)\n }\n\n // b\n val nx = if(si == b) x else x+1\n if(nx <= k) Di[nx].setMax(y, d + y)\n }\n }\n\n D = Di\n }\n\n var ans = 0\n for(dx in D) ans = max(ans, dx.max()!!)\n ans\n }\n\n println(ans)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nfun IntArray.setMax(i: Int, v: Int) = if(v > get(i)) { set(i, v); true } else false\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", "lang_cluster": "Kotlin", "tags": ["strings", "dp"], "code_uid": "3e2c9b682f793d8486c98f32f2443149", "src_uid": "9c700390ac13942cbde7c3428965b18a", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\n\nimport java.util.*\n\nfun main() {\n val tests = 1\n\n for (i in 1..tests) {\n val n = nextInt()\n val k = nextInt()\n val s = next()\n val t = next()\n writeln(solve(k, s, t))\n }\n closeWriter()\n}\n\nfun solve(k: Int, s: String, t: String): Int {\n var res = calc(s.toCharArray(), t)\n\n for (toChange in 0..k) {\n for (l in 0..toChange) {\n val c = s.toCharArray()\n val r = toChange - l\n var count = 0\n for (i in c.indices) {\n if (count == l) {\n break\n }\n if (c[i] == t[1]) {\n c[i] = t[0]\n count++\n }\n }\n count = 0\n for (i in c.indices.reversed()) {\n if (count == r) {\n break\n }\n if (c[i] == t[0]) {\n c[i] = t[1]\n count++\n }\n }\n\n val left = k - toChange\n val lPos = c.withIndex().filter { it.value !in t }.take(left)\n val rPos = c.withIndex().reversed().filter { it.value !in t }.take(left).reversed()\n\n\n for (p in rPos) {\n c[p.index] = t[1]\n }\n res = maxOf(res, calc(c, t))\n var idx = 0\n for (p in lPos) {\n c[rPos[idx].index] = rPos[idx++].value\n c[p.index] = t[0]\n res = maxOf(res, calc(c, t))\n }\n }\n }\n return res\n}\n\nfun calc(c: CharArray, t: String): Int {\n var res = 0\n var second = c.count { it == t[1] }\n for (i in c.indices) {\n if (c[i] == t[1]) {\n second--\n }\n if (c[i] == t[0]) {\n res += second\n }\n }\n return res\n}\n\nfun writeln(x: Any) {\n fastWriter.pw.println(x)\n flushWriter()\n}\n\nfun writeln() {\n fastWriter.pw.println()\n flushWriter()\n}\n\nfun closeWriter() = fastWriter.pw.close()\n\nfun flushWriter() = fastWriter.pw.flush()\n\nobject fastWriter {\n val pw = PrintWriter(System.out)\n}\n\nfun next() = reader.next()\n\nfun nextInt() = reader.nextInt()\n\nfun nextLong() = reader.nextLong()\n\nfun nextDouble() = reader.nextDouble()\n\nfun nextLine() = reader.nextLine()\n\nobject reader {\n private var tokens: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(System.`in`))\n\n fun next(): String {\n var hasNext = tokens?.hasMoreElements() ?: false\n while (!hasNext) {\n tokens = StringTokenizer(reader.readLine())\n hasNext = tokens?.hasMoreElements() ?: false\n }\n\n return tokens!!.nextToken()\n }\n\n fun nextLine(): String {\n tokens = null\n return readLine()!!\n }\n\n fun nextInt() = next().toInt()\n\n fun nextLong() = next().toLong()\n\n fun nextDouble() = next().toDouble()\n}\n", "lang_cluster": "Kotlin", "tags": ["strings", "dp"], "code_uid": "8a4557187f618c9d9452c4d3c8a7d3b0", "src_uid": "9c700390ac13942cbde7c3428965b18a", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\nimport java.io.*\nimport java.util.*\n\nval oo = 4000000000000000000L\n\nfun main() {\n val out = PrintWriter(System.out)\n val fs = FS(System.`in`)\n\n var T = 1\n while(T-->0) {\n\n var n = fs.nextInt()\n var moves = fs.nextInt()\n var S1 = fs.next()\n var S2 = fs.next()\n\n var A = S2[0]\n var B = S2[1]\n\n var dp = Array(n){Array(moves+1){IntArray(n)}}\n for(i in 0 until n)\n for(j in 0 until moves+1)\n dp[i][j].fill(-1)\n\n fun solve(idx: Int, moves: Int, numA: Int): Int {\n if(idx == n) return 0\n var dpRet = dp[idx][moves][numA]\n if(dpRet != -1) return dpRet\n\n var res = 0\n var extras = if(S1[idx] == B) numA else 0\n var newNumA = numA + if(S1[idx] == A) 1 else 0\n\n res = solve(idx+1, moves, newNumA)+extras\n\n if(moves > 0) {\n for(x in 0 until 2) {\n extras = if(S2[x] == B) numA else 0\n newNumA = numA + if(S2[x] == A) 1 else 0\n var ret = solve(idx+1, moves-1, newNumA)+extras\n res = max(res, ret)\n }\n }\n\n dp[idx][moves][numA] = res\n return res\n }\n\n println(solve(0, moves, 0))\n\n }\n\n out.close()\n}\n\nclass FS(stin: InputStream) {\n val read = BufferedReader(InputStreamReader(stin))\n var token = StringTokenizer(\"\")\n\n tailrec fun next(): String {\n if(token.hasMoreTokens()) return token.nextToken()\n token = StringTokenizer(read.readLine())\n return next()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextDouble() = next().toDouble()\n}\n\n", "lang_cluster": "Kotlin", "tags": ["strings", "dp"], "code_uid": "47fbee3bb0bf31109f88cc3e154736f3", "src_uid": "9c700390ac13942cbde7c3428965b18a", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var (n, m, k) = readLine()!!.split(\" \").map { it.toInt() }\n var p = m - n\n var f = 1\n var i = 1\n var j = 1\n\n if(k > n / 2) {\n k = n - k + 1\n }\n\n while(p > 0) {\n f++\n\n if(i != n) {\n if(j < k) {\n i += 2\n j++\n } else {\n i++\n }\n }\n\n p -= i\n }\n\n println(f)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "binary search"], "code_uid": "9bbadcdd1aa96285bc428add7edba9d6", "src_uid": "da9ddd00f46021e8ee9db4a8deed017c", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * Description: Kotlin tips for dummies\n * Source: own\n */\n\n/* sorting\n * 1 (ok)\n val a = nextLongs().sorted() // a is mutable list\n * 2 (ok)\n val a = arrayListOf() // or ArrayList()\n a.addAll(nextLongs())\n a.sort()\n *.3 (ok)\n val A = nextLongs()\n val a = Array(n,{0})\n for (i in 0..n-1) a[i] = A[i]\n a.sort()\n * 4 (ok)\n val a = ArrayList(nextLongs())\n a.sort()\n * 5 (NOT ok)\n val a = LongArray(N) // or nextLongs().toLongArray()\n Arrays.sort(a)\n */\n/* 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/* printing variables:\n * println(\"${l+1} and $r\")\n * print d to 8 decimal places: String.format(\"%.8g%n\", d)\n * try to print one stringbuilder instead of multiple prints\n */\n/* comparing pairs\n val pq = PriorityQueue>({x,y -> x.first.compareTo(y.first)})\n val pq = PriorityQueue>(compareBy {it.first})\n val A = arrayListOf(Pair(1,3),Pair(3,2),Pair(2,3))\n val B = A.sortedWith(Comparator>{x,y -> x.first.compareTo(y.first)})\n sortBy\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/* basically switch, can be used as expression\n when (x) {\n 0,1 -> print(\"x <= 1\")\n 2 -> print(\"x == 2\")\n else -> { // Note the block\n print(\"x is neither 1 nor 2\")\n }\n }\n*/\n// swap : a = b.also { b = a }\n// arraylist remove element at index: removeAt, not remove ...\n// lower bound: use .binarySearch()\n\nimport java.util.*\n// import kotlin.math.*\n\nval MOD = 1000000007\nval SZ = 1 shl 18\nval INF = (1e18).toLong()\n\nfun add(a: Int, b: Int) = (a+b) % MOD // from tourist :o\nfun sub(a: Int, b: Int) = (a-b+MOD) % MOD\nfun mul(a: Int, b: Int) = ((a.toLong() * b) % MOD).toInt()\nfun po(a: Int, b: Int): Int {\n if (b == 0) return 1\n var res: Int = po(mul(a,a),b/2)\n if ((b and 1) == 1) res = mul(res,a)\n return res\n}\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\nval out = StringBuilder()\nfun YN(b: Boolean):String { return if (b) \"YES\" else \"NO\" }\n\nfun gcd(a: Int, b: Int): Int {\n return if (a == 0) b else gcd(b%a,a)\n}\n\nfun bad() {\n println(-1)\n System.exit(0)\n}\n\nfun ari(a: Int, b: Int): Long {\n return (a+b).toLong()*(b-a+1)/2\n}\n\nfun get(a: Int, b: Int): Long {\n if (a <= 0) return 1-a+ari(1,b)\n return ari(a,b)\n}\nfun get(n: Int, k: Int, mid: Int) : Long {\n var res: Long = mid.toLong()\n // println(\"HA ${cur}\")\n // cur-(k-1) to cur-1\n res += get(mid-(k-1),mid-1)\n res += get(mid-(n-k),mid-1)\n return res\n}\n\nfun solve() {\n val (n,m,k) = nextInts()\n var (lo, hi) = arrayOf(1,m)\n // println(get(n,k,5))\n while (lo < hi) {\n val mid = (lo+hi+1)/2\n if (get(n,k,mid) <= m) lo = mid\n else hi = mid-1\n }\n println(lo)\n}\n\nfun main(args: Array) {\n solve()\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "binary search"], "code_uid": "d98564da802fc971a0f65f0f864664fc", "src_uid": "da9ddd00f46021e8ee9db4a8deed017c", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["number theory"], "code_uid": "997c05c61edc5e304bc7e80eae9a7693", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["number theory"], "code_uid": "5e2ae834b09ac5cd71878ffac164de93", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "94219cd488279048cacfe0888f698192", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "c49979aa34ea9c00a4ac8a68fcb23e1b", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.io.*\r\nimport java.util.*\r\nimport kotlin.math.absoluteValue\r\nimport kotlin.random.Random\r\nimport kotlin.system.measureTimeMillis\r\n\r\n// @formatter:off\r\n\r\nval local = System.getProperty(\"ONLINE_JUDGE\") == null\r\n//val local = false\r\n\r\nval INPUT: InputStream = if (local) FileInputStream(\"input.txt\") else System.`in`\r\n//val INPUT: InputStream = System.`in`\r\n\r\n//val OUTPUT: PrintStream = if (local) PrintStream(\"output.txt\") else System.out\r\nval OUTPUT: PrintStream = System.out\r\n\r\nval _reader = INPUT.bufferedReader()\r\nvar _tokenizer = StringTokenizer(\"\")\r\n\r\nfun readLine(): String? = _reader.readLine()\r\nfun readLn() = _reader.readLine()!!\r\nfun read(): String {\r\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\r\n return _tokenizer.nextToken()\r\n}\r\n\r\nfun readInt() = read().toInt()\r\nfun readDouble() = read().toDouble()\r\nfun readLong() = read().toLong()\r\nfun readStrings(n: Int) = List(n) { read() }\r\nfun readLines(n: Int) = List(n) { readLn() }\r\nfun readInts(n: Int) = List(n) { read().toInt() }\r\nfun readStrings() = readLn().split(\" \")\r\nfun readInts() = readStrings().map { it.toInt() }\r\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\r\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\r\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\r\nfun readLongs(n: Int) = List(n) { read().toLong() }\r\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\r\nfun PrintWriter.yesNo(p: Boolean) {\r\n if (p) this.println(\"YES\") else this.println(\"NO\")\r\n}\r\n\r\n@JvmField\r\nval _writer = PrintWriter(OUTPUT, true)\r\n// @formatter:on\r\n\r\nfun solve(a: Long, b: Long): Boolean {\r\n val set = mutableSetOf()\r\n set.add(a.toString(2))\r\n val q: Queue = LinkedList()\r\n q.add(a.toString(2))\r\n\r\n while (!q.isEmpty()) {\r\n val s = q.poll()\r\n var t: String\r\n\r\n t = s + \"0\"\r\n t = t.reversed()\r\n while (t.length > 1 && t[0] == '0') {\r\n t = t.substring(1)\r\n }\r\n\r\n if (t.length < 100) {\r\n if (set.contains(t).not()) {\r\n set.add(t)\r\n q.add(t)\r\n }\r\n }\r\n\r\n t = s + \"1\"\r\n t = t.reversed()\r\n if (t.length < 100) {\r\n if (set.contains(t).not()) {\r\n set.add(t)\r\n q.add(t)\r\n }\r\n }\r\n }\r\n return set.contains(b.toString(2))\r\n}\r\n\r\nfun PrintWriter.solve() {\r\n// val tcs = readInt()\r\n val tcs = 1\r\n for (tc in 1..tcs) {\r\n val a = readLong()\r\n val b = readLong()\r\n val res = solve(a, b)\r\n yesNo(res)\r\n }\r\n}\r\n\r\nfun main() {\r\n\r\n val elapsedMs = measureTimeMillis {\r\n _writer.solve()\r\n _writer.flush()\r\n }\r\n if (local) {\r\n println(\"\\n\\nElapsed $elapsedMs ms\")\r\n }\r\n\r\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "constructive algorithms", "math", "bitmasks", "strings", "implementation"], "code_uid": "9d97adaee13f3adb15dd212cb782335b", "src_uid": "9f39a3c160087beb0efab2e3cb510e89", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import kotlin.random.Random.Default.nextLong\n\nval br = System.`in`.bufferedReader()\nfun readInt() = br.readLine()!!.toInt()\nfun readInts() = br.readLine()!!.split(\" \").map { it.toInt() }\nfun readLongs() = br.readLine()!!.split(\" \").map { it.toLong() }\n\ntailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\n\nclass segTree(\n val leftMost: Int,\n val rightMost: Int,\n var leftChild: segTree? = null,\n var rightChild: segTree? = null,\n var value: Long = 0L, // can put more data here\n var size: Int = 1, // should be rightMost - leftMost + 1\n var toProp: Long = 0L\n) {\n\n constructor(tl: Int, tr: Int, a: List) : this(leftMost = tl, rightMost = tr) {\n if (tl == tr) {\n value = a[tl].toLong()\n } else {\n val mid = (tl + tr) / 2\n leftChild = segTree(tl, mid, a)\n rightChild = segTree(mid + 1, tr, a)\n size = tr - tl + 1\n recalc()\n }\n }\n\n // can change to other function, not just for sum (also change rangeSum function)\n // function does: combine two child to get parent's data\n fun recalc() {\n if (leftMost == rightMost) return\n else value = leftChild!!.value + rightChild!!.value\n }\n\n // should not be leaf\n fun prop() {\n leftChild\n }\n\n fun pointUpdate(index: Int, newVal: Long) {\n if (leftMost == rightMost) {\n value = newVal; return\n } // leaf node, just update value\n if (index <= leftChild!!.rightMost) leftChild!!.pointUpdate(index, newVal)\n else rightChild!!.pointUpdate(index, newVal)\n // child may change, so recalculate value\n recalc()\n }\n\n fun rangeQuery(l: Int, r: Int): Long {\n // entirely disjoint\n if (l > rightMost || r < leftMost) return 0L\n // covers us\n if (l <= leftMost && rightMost <= r) return value\n // we don't know\n return leftChild!!.rangeQuery(l, r) + rightChild!!.rangeQuery(l, r)\n }\n}\n\n\n// Range update (lazy propagetino), range sum (log n time)\nclass Treap(\n var key: Long, // key\n val priority: Long, // priority\n val kids: MutableList = MutableList(2) { null },\n var subtreeSize: Long = 0,\n var sum: Long = 0L, // upper treap use sum\n var toProp: Long = 0L\n) {\n\n // return size of subtree (include this node)\n fun size(t: Treap?) = t?.subtreeSize ?: 0\n\n // update subtreeSize and sum for this node. so what is sum,\n private fun recalc(t: Treap?) {\n if (t == null) return\n t.subtreeSize = 1\n t.sum =\n t.key + t.toProp * size(t) // when should propagate data ???? so size should be 1 because just set it subtreeSize to 1\n t.kids.forEach {\n if (it != null) {\n t.subtreeSize += it.subtreeSize; t.sum += it.key + it.toProp * size(it)\n }\n }\n }\n\n // when range update, first split treap to three part(mostly), int middle part, update all value with some number by lazy propagation\n private fun prop(t: Treap?) {\n if (t == null || t.toProp == 0L) return\n t.kids.forEach { if (it != null) it.toProp += t.toProp } // propagate to child\n t.key += t.toProp // also propagate to itself\n t.toProp = 0L // clear propagate value after propagate\n recalc(t) // will sum change ??? : kid may have change value\n }\n\n\n private fun split(t: Treap?, nInLeft: Long): List {\n if (t == null) return List(2) { null }\n prop(t) // before make any change, propagate value to child\n if (size(t.kids[0]) >= nInLeft) { // Treap t(this one) is in right half of treap\n val (left, right) = split(t.kids[0], nInLeft) // keep split left treap because it has more treap\n t.kids[0] = right\n recalc(t) // any time make change, should recalculate treap\n return listOf(left, t) // left should have iInLeft treap in it.\n } else {\n // Treap t(this one) is in left half of treap, t's right child should return [nInLeft - size(t.kids[0]) - 1] treap to make total of nInLeft in first return treap\n // split result can be null when nInLeft = size(t.kids[0]) + 1, right child return null\n val (left, right) = split(t.kids[1], nInLeft - size(t.kids[0]) - 1)\n t.kids[1] = left\n recalc(t) // any time make change, should recalculate treap\n return listOf(t, right)\n }\n }\n\n // for insert treap\n fun merge(l: Treap?, r: Treap?): Treap? {\n if (l == null) return r\n if (r == null) return l\n prop(l) // before use, propagate value\n prop(r)// before use, propagate value\n if (l.priority < r.priority) { // l should on the top, l's right child become merge result of l's right child and r\n l.kids[1] = merge(l.kids[1], r)\n recalc(l) // after change, recalculate value\n return l\n } else {\n r.kids[0] = merge(l, r.kids[0])\n recalc(r) // after change, recalculate value\n return r\n }\n }\n\n // l and r in 0..n-1 where n is number of treap\n fun rangeAdd(t: Treap?, l: Long, r: Long, toAdd: Long): Treap {\n assert(t != null)\n val (a, b) = split(t, l)\n val (c, d) = split(b, r - l + 1) // treap become a c d, and c is which we want to update\n c!!.toProp += toAdd // c should not be null here\n return merge(a, merge(c, d))!! // this should not null\n }\n\n fun rangeSum(t: Treap, l: Long, r: Long): Pair {\n // before split, should propagate t's toProp.\n val (a, b) = split(t, l)\n val (c, d) = split(b, r - l + 1) // treap become a c d, and c is include sum we need\n val rootTreap = merge(a, merge(c, d))\n return Pair(rootTreap!!, c!!.sum)\n }\n}\n\nfun main() {\n val sb = StringBuilder()\n //repeat(readInt()) {\n // special case, use dp,\n // op: << +1/+0, << +1/+0,\n // 10010010...10001\n // 0+0 -> delete\n // 0+1 -> len++\n // 1+0 -> not know\n // 1+1 -> len++\n // 101001 10 101001 001 || 101001 001 || 10 101001\n // first remove right zero\n // then add some number and end with 1\n // then reverse\n // then add some number and end with 1\n // then reverse\n // \u524d\u540e\u90fd\u52a0 -\u300b\u987a\u5e8f\u4e0d\u53d8 -\u300b substr \u5373\u53ef\n // \u53ea\u52a0\u540e\u9762\uff0c\u53cd\u5411 substr \u5e76\u4e14 \u521a\u597d\u662f\u672b\u5c3e\n // \u672b\u5c3e\u662f0\u4e0d\u884c\uff0c\u9664\u975e\u521a\u5f00\u59cb\u5c31\u4e00\u6837\n var (x, y) = readLongs()\n fun stringToNum(s: String): Long {\n var ans = 0L\n for (i in s.length - 1 downTo 0) {\n if (s[i] == '1') ans += 1 shl (s.length - 1 - i)\n }\n return ans\n }\n\n var c = x // plus 0\n while (c % 2 == 0L) c /= 2\n val d = stringToNum(c.toString(2).reversed()) // plus 0 reverse\n val a = (x shl 1) +1 // plus 1\n val b = stringToNum(a.toString(2).reversed())\n fun sub(a: Long, b: Long): Boolean {\n val stra = a.toString(2)\n val strb = b.toString(2)\n if (stra.length>strb.length) return false\n val mid = stra.length\n var check = false\n //println(\"$stra, $strb\")\n for (i in 0.. strb.length-stra.length){ // 1 front\n //println(\"enter\")\n var ans = true\n for (j in 0 until i) if (strb[j]!='1') ans = false\n for (j in i until i+stra.length) if (strb[j]!=stra[j-i]) ans = false\n for (j in i+stra.length until strb.length) if (strb[j]!='1') ans = false\n //if (ans) println(\"$stra, $strb, strat index $i\")\n if (ans) check = true\n }\n return check\n }\n\n val ans = sub(a, y) || sub(b, y) || sub(c, y) || sub(d, y) || (x == y)\n\n sb.appendLine(if (ans) \"YES\" else \"NO\")\n\n println(sb)\n\n\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "constructive algorithms", "math", "bitmasks", "strings", "implementation"], "code_uid": "795b4d91781ef72d759d01e9bc775cb8", "src_uid": "9f39a3c160087beb0efab2e3cb510e89", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "55e055e4a48793768d2c45587e8937b4", "src_uid": "b08ee0cd6f5cb574086fa02f07d457a4", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n val b = 1000000007L\n val (max, len) = r.readLine()!!.split(\" \").map { it.toInt() }\n\n val dp = Array(len) { LongArray(max + 1) { 0L } }\n for (k in 1..max) {\n dp[0][k] = 1\n }\n for (i in 0..len - 2) {\n for (n in 1..max) {\n var time = 1\n while (n * time <= max) {\n dp[i + 1][n * time] = (dp[i + 1][n * time] + dp[i][n]) % b\n time++\n }\n }\n }\n println(dp[len-1].sum()%b)\n}", "lang_cluster": "Kotlin", "tags": ["dp", "combinatorics", "number theory"], "code_uid": "81d44ef1724487bf60147886164400c6", "src_uid": "c8cbd155d9f20563d37537ef68dde5aa", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 val k = scanner.nextInt()\n val arr = LongArray(n + 1) { 1L }\n var mod = 1000000007L\n val help = Array(n + 1) {\n if (it < 2)\n return@Array intArrayOf()\n val a = ArrayList()\n var i = 2\n while (i * i <= it) {\n if (it % i == 0) {\n a.add(i)\n if (i * i != it)\n a.add(it / i)\n }\n i++\n }\n a.add(1)\n a.toIntArray()\n }\n for (i in 1 until k) {\n for (j in 2..n) {\n for (q in help[j]) {\n arr[q] += arr[j]\n arr[q] %= mod\n }\n }\n }\n var res = 0L\n for (i in 1..n) {\n res += arr[i]\n res %= mod\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\nfun Array.print() {\n for (i in this)\n i.print()\n}", "lang_cluster": "Kotlin", "tags": ["dp", "combinatorics", "number theory"], "code_uid": "faf806ec53cc7e72178db0bd862e3dd3", "src_uid": "c8cbd155d9f20563d37537ef68dde5aa", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun num_good_sequences(n : Int, k : Int) : Long {\n val modulo = 1000000007L\n val num_ways = Array(n + 1, {_ -> LongArray(k + 1)}) \n for (i in 1 .. n) {\n num_ways[i][1] = 1L\n }\n for (j in 1 .. (k - 1)) {\n val j_plus_1 = j + 1\n for (i in 1 .. n) {\n var f = 1\n var fi = f * i\n while (fi <= n) {\n num_ways[fi][j_plus_1] = (num_ways[fi][j_plus_1] + num_ways[i][j]) % modulo\n f = f + 1\n fi = f * i\n }\n }\n }\n var result = 0L\n for (i in 1 .. n) {\n result = (result + num_ways[i][k]) % modulo\n }\n return result\n}\n\nfun main(args : Array) {\n val n_k_nullable_str = readLine()\n if (n_k_nullable_str == null) {\n // Do nothing ...\n } else {\n val n_k_str = n_k_nullable_str\n val n_k = n_k_str.split(' ').map(String::toInt)\n val n = n_k[0]\n val k = n_k[1]\n val result = num_good_sequences(n, k)\n println(\"${result}\")\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["dp", "combinatorics", "number theory"], "code_uid": "73679fdcbfa447c19fe18657c53eb2d0", "src_uid": "c8cbd155d9f20563d37537ef68dde5aa", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : InputReader, pw : PrintWriter) {\n\n val n : Int = ir.nextInt()\n val m : Int = ir.nextInt()\n val min : Int = ir.nextInt()\n val max : Int = ir.nextInt()\n val t = IntArray(m)\n var count = 0\n var myMin = 101\n var myMax = 0\n\n for (i in 0 until m)\n t[i] = ir.nextInt()\n\n for (i in 0 until m) {\n if (t[i] < myMin)\n myMin = t[i]\n\n if (t[i] > myMax)\n myMax = t[i]\n }\n\n if (myMax > max || myMin < min)\n pw.print(\"Incorrect\")\n else {\n if (myMax < max)\n count++\n if (myMin > min)\n count++\n\n if (n - m >= count)\n pw.print(\"Correct\")\n else\n pw.print(\"Incorrect\")\n }\n\n}\n\nclass InputReader(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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2e17f9db69ffd4cd03acfb8672bfb662", "src_uid": "99f9cdc85010bd89434f39b78f15b65e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n println(2*(n/3)+(n%3+1)/2)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "54bf8b8dfa391fffaf382dae42b6fc14", "src_uid": "a993069e35b35ae158d35d6fe166aaef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "ad3e2cd3b3f87caa11f7e4a483c3ab0c", "src_uid": "a993069e35b35ae158d35d6fe166aaef", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.toInt() }.sorted()\n when {\n v[0]==v[1]&&v[1]==v[2]&&v[2]==v[3] -> println(if (v[4]==v[5]) \"Elephant\" else \"Bear\")\n v[1]==v[2]&&v[2]==v[3]&&v[3]==v[4] -> println(\"Bear\")\n v[2]==v[3]&&v[3]==v[4]&&v[4]==v[5] -> println(if (v[0]==v[1]) \"Elephant\" else \"Bear\")\n else -> println(\"Alien\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7e37430a2f41e477f10988a18ebfff22", "src_uid": "43308fa25e8578fd9f25328e715d4dd6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 fun files(inputFilename: String, outputFilename: String) =\n ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))\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 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 c = IntArray(10)\n val a = IntArray(6, { io.readInt() })\n for (v in a) {\n ++c[v]\n }\n val li = c.indices.find({ i -> c[i] >= 4 }) ?: 0\n c[li] -= 4\n val ri = c.indices.find({ i -> c[i] == 2 }) ?: 0\n val res = when {\n li == 0 -> \"Alien\"\n li != 0 && ri != 0 -> \"Elephant\"\n else -> \"Bear\"\n }\n io.println(res)\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2724ecb2665c60e9bd84cb0772e990ae", "src_uid": "43308fa25e8578fd9f25328e715d4dd6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 H = ni()\n var N = nl() - 1\n var x = 0\n var node = 2L\n var leaf = 1L\n for (i in 0 until H - 1) {\n node *= 2\n leaf *= 2\n }\n var ans = 0L\n for (i in 0 until H) {\n if (x == 0 && N >= leaf || x == 1 && N < leaf) {\n ans += node - 1\n } else {\n x = x xor 1\n }\n if (N >= leaf) N -= leaf\n debug{\"$N $ans $node $leaf\"}\n node /= 2\n leaf /= 2\n }\n out.println(ans + H)\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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}", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "trees"], "code_uid": "0a9e98db992d781504a1e78a61c1fa90", "src_uid": "3dc25ccb394e2d5ceddc6b3a26cb5781", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "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", "lang_cluster": "Kotlin", "tags": ["dp", "combinatorics", "trees"], "code_uid": "49adc4f80135a7ec90816006759fd94c", "src_uid": "92939054045c089cd25c8f4e7b9ffcf2", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLong()\n\n val ans = n.factorize().distinct().fold(1L, Long::times)\n\n println(ans)\n}\n\nfun Long.factorize() = sequence {\n var n = this@factorize\n\n for(p in sequenceOf(2L) + (3..Long.MAX_VALUE step 2)) {\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\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() }", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "b5c72064fa130e892cffa9bbfdd4b044", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.sqrt\n\nfun main() {\n val n = readLong()\n\n val ans = n.factorize().distinct().fold(1L, Long::times)\n\n println(ans)\n}\n\nfun Long.sqrtFloor() = sqrt(toDouble()).toLong()\n\nfun Long.factorize() = sequence {\n val sqrt = sqrtFloor()\n var n = this@factorize\n\n for(p in sequenceOf(2L) + (3..sqrt step 2)) {\n while(n % p == 0L) {\n yield(p)\n n /= p\n }\n }\n\n if(n > 1) yield(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 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() }", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "1d3c12cd7fa81bf38d00072acc1c7780", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.sqrt\n\nfun main() {\n val n = readLong()\n\n val sqrt = n.sqrtFloor()\n\n val ans = n.factorize().distinct().fold(1L, Long::times)\n\n println(ans)\n}\n\nfun Long.sqrtFloor() = sqrt(toDouble()).toLong()\n\nfun primeSieve(upperLimit: Long): Sequence = sequence {\n yield(2L)\n val source = (3..upperLimit step 2).toMutableSet()\n\n while(source.isNotEmpty()) {\n val prime = source.first()\n yield(prime)\n source.remove(prime)\n source.removeAll(prime * prime .. upperLimit step prime)\n }\n}\n\nfun Long.factorize() = sequence {\n val sqrt = sqrtFloor()\n var n = this@factorize\n\n for(p in primeSieve(sqrt)) {\n while(n % p == 0L) {\n yield(p)\n n /= p\n }\n }\n\n if(n > 1) yield(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 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() }", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "a62acb58023988134f69375962575cc1", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "math", "combinatorics", "graphs"], "code_uid": "ca542ffbcdfee54c3ac285d5661f8ab6", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args : Array) {\n var input = System.`in`.bufferedReader()\n try {\n var n = input.readLine().toLong()\n \n --n\n \n var ans = 0L\n// for (i in 1 .. n)\n// ans += (i and -i)\n// println(\"bruteforce: ans = \" + ans)\n//\n// ans = 0L\n var i = 0\n while (n shr i > 0) {\n if ((n and (1L shl i)) != 0L)\n ans += ((n shr (i + 1)) + 1) * (1L shl i)\n else\n ans += ((n shr (i + 1))) * (1L shl i)\n \n ++i\n }\n println(ans)\n } finally {\n input.close()\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "bitmasks", "graphs", "implementation"], "code_uid": "b5526a16ed217cdb26e101d613b4c84f", "src_uid": "a98f0d924ea52cafe0048f213f075891", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 fun p(n: Long) = n*(n-1)/2\n val max = p(m-n+1)\n val min = m%n * p(m/n+1) + (n-(m%n))*p(m/n)\n println(\"$min $max\")\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "e158b44588e1102adaa04826407dec5b", "src_uid": "a081d400a5ce22899b91df38ba98eecc", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val list = readLine()!!.split(\" \").map { it.toLong() }\n val q = (list[0]/list[1])\n val rem = (list[0] % list[1])\n val d=(list[0] - list[1])\n if (list[1] == 1L) {\n val a = (list[0]*(list[0] - 1)/2)\n println(\"$a $a\")\n }\n else if (d == 1L)\n println(\"1 1\")\n else{\n val max=d*(d+1)/2\n val min=((list[1]-rem)*(q)*(q-1)/2)+(rem)*(q)*(q+1)/2\n println(\"$min $max\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "fc82e946082a81d734d08058608057d9", "src_uid": "a081d400a5ce22899b91df38ba98eecc", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 fun files(inputFilename: String, outputFilename: String) =\n ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))\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 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 fun ans(x: Long) = x * (x - 1) / 2L\n val n = io.readLong()\n val m = io.readLong()\n val p = n / m\n val q = n % m\n val rmin = q * ans(p + 1) + (m - q) * ans(p)\n val rmax = ans(n - m + 1)\n io.println(\"$rmin $rmax\")\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "b7ae1e38a753428d1a3d06bf3cd6e123", "src_uid": "a081d400a5ce22899b91df38ba98eecc", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\nimport kotlin.math.min\n\nfun main(args: Array) {\n val (n, s, k) = readLine()!!.split(' ').map(String::toInt)\n val r = readLine()!!.split(' ').map(String::toInt).toIntArray()\n val c = readLine()!!.map {\n when (it) {\n 'R' -> 0\n 'G' -> 1\n 'B' -> 2\n else -> throw Exception()\n }\n }\n val dp = Array(n) { IntArray(2501) { Int.MAX_VALUE } }\n for (i in 0 until n) dp[i][r[i]] = abs((s - 1) - i)\n for (sAll in 1..2500) {\n for (i in 0 until n) {\n if (dp[i][sAll] != Int.MAX_VALUE) {\n for (j in 0 until n) if (c[j] != c[i] && r[j] > r[i]) {\n dp[j][sAll + r[j]] = min(dp[j][sAll + r[j]], dp[i][sAll] + abs(i - j))\n }\n }\n }\n }\n println(dp.map { it.drop(k).min()!! }.min().let { if (it != Int.MAX_VALUE) it else -1 })\n}\n", "lang_cluster": "Kotlin", "tags": ["dp"], "code_uid": "2bbbced59f4485a72965bb14071b51d9", "src_uid": "a95e54a7e38cc0d61b39e4a01a6f8d3f", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 n = readInt()\n var xs = readInts().sorted()\n var sol = 0\n while (xs.isNotEmpty()) {\n sol++\n var numElements = 0\n val newXs = mutableListOf()\n for (x in xs) {\n if (x >= numElements) numElements++ else newXs.add(x)\n }\n xs = newXs\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "greedy"], "code_uid": "c2329c18d18ba50f005678dea56d5717", "src_uid": "7c710ae68f27f140e7e03564492f7214", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\n/**\n *\n *This solution works due to the small input, but the solution is O(n^2). A linear solution can be found here:\n * https://codeforces.com/contest/388/submission/8807640\n * This solution uses -~f, which is the same than (f+1). If f is 3, ~f is -4 and -~f is 4. Probably uses it to save\n * some characters. The kotlin version of this solution is below\n */\n\n//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 n = readInt()\n// var xs = readInts().sorted()\n// var sol = 0\n// while (xs.isNotEmpty()) {\n// sol++\n// var numElements = 0\n// val newXs = mutableListOf()\n// for (x in xs) {\n// if (x >= numElements) numElements++ else newXs.add(x)\n// }\n// xs = newXs\n// }\n// print(sol)\n//}\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n readLine()\n val xs = readInts().sorted()\n var sol = 0\n for((index, x) in xs.withIndex()) sol = max(sol, index / (x+1))\n print(sol + 1)\n}\n", "lang_cluster": "Kotlin", "tags": ["sortings", "greedy"], "code_uid": "8642c057e55ab8b633e5dfa750dd38f7", "src_uid": "7c710ae68f27f140e7e03564492f7214", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun solve(n:Long, m:Long, k:Long):Long? {\n var ret:Long? = 0L\n if( k == 0L )\n ret = n * m\n else if( (n-1) + (m-1) < k )\n ret = -1\n else {\n val shortSide = listOf(n, m).max()\n val longSide = listOf(n, m).max()\n\n // \u4e21\u65b9\u306e\u8fba\u3092\u5272\u3089\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u5834\u5408\n if( longSide!! < (k+1) ) {\n ret = listOf( solve(1, m, (k + 1) - n)!!, solve(n, 1, (k + 1) - m)!! ).max()\n }\n // \u7247\u65b9\u5411\u304b\u3089\u3060\u3051\u5272\u3063\u3066\u3001\u5927\u304d\u3044\u65b9\u3092\u63a1\u7528\n else {\n val nCut = ( n / (k+1) ) * m\n val mCut = ( m / (k+1) ) * n\n ret = listOf(nCut, mCut).max()\n }\n }\n return ret\n}\n\nfun main(args:Array) {\n val (n,m,k) = readLine()!!.split(\" \").map { it.toLong() } \n println( solve(n,m,k) )\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "b4a373596bbb32456c3335b9dbfba8cd", "src_uid": "bb453bbe60769bcaea6a824c72120f73", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "81468b45f186c1715fac89f3430d5a73", "src_uid": "8330d9fea8d50a79741507b878da0a75", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9958de727f4010c52ae564ed582af60e", "src_uid": "8330d9fea8d50a79741507b878da0a75", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c53a403f6c5f6d643f91655932c8ce23", "src_uid": "8330d9fea8d50a79741507b878da0a75", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "combinatorics"], "code_uid": "a9a3440e3c814e149e4131a075fa2ce0", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "combinatorics"], "code_uid": "b666bf81597aeae5bbd8a11a8c365a4c", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\ndata class Entry(val tpe: String, val i: Int)\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val N = ni()\n val M = ni()\n val E = Array(M){Entry(ns(), ni() - 1)}\n\n val prev = mutableListOf()\n val appear = BooleanArray(N)\n for (e in E) {\n when(e.tpe) {\n \"+\" -> {\n appear[e.i] = true\n }\n \"-\" -> {\n if (!appear[e.i]) prev += e.i\n appear[e.i] = true\n }\n }\n }\n\n val flag = BooleanArray(N)\n for (i in 0 until N) {\n if (!appear[i]) flag[i] = true\n }\n\n val j = if (prev.isEmpty()) {\n E.find { it.tpe == \"+\" }!!.i\n } else {\n prev.last()\n }\n var ok = true\n val set = mutableSetOf()\n set.addAll(prev)\n for (e in E) {\n when(e.tpe) {\n \"+\" -> set += e.i\n else -> set -= e.i\n }\n if (set.isNotEmpty()) {\n ok = ok && set.contains(j)\n }\n }\n\n if (ok) flag[j] = true\n\n val ans = mutableListOf()\n for (i in 0 until N) {\n if (flag[i]) ans += i + 1\n }\n out.println(ans.size)\n out.println(ans.joinToString(\" \"))\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "246c4b2feb001144d3b901c2f6c74c34", "src_uid": "a3a337c7b919e7dfd7ff45ebf59681b5", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main(args: Array) {\n var (N, M) = readLine()!!.split(\" \").map(String::toInt)\n var S = \"\"\n var Z = \"0123456789ABCDEF\"\n while (N > 0) {\n S = Z[N%M] + S\n N /= M\n }\n if (S.toSet().size == S.length) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n// if (S.all { it == '0' || it == '1'} && S.reversed() == S) {\n// println(\"NO\")\n// } else {\n// println(\"YES\")\n// }\n}", "lang_cluster": "Kotlin", "tags": ["number theory"], "code_uid": "587ca41e33ee706f4ea46f9505aae12f", "src_uid": "a8945bb1082fefe70e6898a8bec1ce3f", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package codeForces.c491_2\n\nfun tryEat(n: Long, c: Long): Boolean {\n var remains = n\n var eaten = 0L\n\n while (remains > c) {\n remains -= c\n eaten += c\n\n remains -= remains / 10\n }\n eaten += remains\n// println(eaten)\n\n return eaten * 2 >= n\n}\n\nfun main(args: Array) {\n val n = readLine()!!.toLong()\n\n// tryEat(n, 1L)\n// return\n\n var left = 1L\n var right = n\n var lastSuccess = -1L\n\n while (left <= right) {\n val c = (left + right) / 2\n\n if (tryEat(n, c)) {\n lastSuccess = c\n right = c - 1\n } else {\n left = c + 1\n }\n }\n\n println(lastSuccess)\n}", "lang_cluster": "Kotlin", "tags": ["implementation", "binary search"], "code_uid": "8abdb6291d3febc561d65a4c985f659c", "src_uid": "db1a50da538fa82038f8db6104d2ab93", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun model(n: Long, k: Long): Long {\n var rem = n\n var ans = 0L\n\n while (rem > 0) {\n val vasyaCount = Math.min(rem, k)\n ans += vasyaCount\n rem -= vasyaCount\n rem -= rem / 10\n }\n\n return ans\n}\n\nfun check(vasyaCount: Long, n: Long) = 2 * vasyaCount >= n\n\nfun main(args: Array) {\n val n = readLine()!!.toLong()\n\n var a = 1L\n var b = n\n\n while (a <= b) {\n val c = (a + b) / 2\n\n if (check(vasyaCount = model(n = n, k = c), n = n)) {\n b = c - 1\n } else {\n a = c + 1\n }\n }\n\n if (check(vasyaCount = model(n = n, k = a), n = n)) {\n println(a)\n } else {\n println(a + 1)\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation", "binary search"], "code_uid": "bc68e214851546b629d9726e57cd6eaa", "src_uid": "db1a50da538fa82038f8db6104d2ab93", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "efade04d8a76fc103ce86f3439956cd7", "src_uid": "ed8725e4717c82fa7cfa56178057bca3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * Created by yakutovd on 17.03.2018.\n */\n\nimport java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\nimport java.util.TreeSet\n\n/**\n * Created by yakutovd on 17.03.2018.\n */\nfun main(args: Array) {\n try {\n val out = PrintWriter(System.out)\n val br = BufferedReader(InputStreamReader(System.`in`))\n val n = Integer.parseInt(br.readLine())\n val set = TreeSet()\n\n for (i in 0..(n - 1)) {\n val st = StringTokenizer(br.readLine())\n val l = Integer.parseInt(st.nextToken())\n val r = Integer.parseInt(st.nextToken())\n val pair = Pair(l, r)\n var L = l\n var R = r\n while (true) {\n val toRight = set.ceiling(pair)\n if (toRight != null && toRight.l <= r) {\n L = Math.min(L, toRight.l)\n R = Math.max(R, toRight.r)\n set.remove(toRight)\n } else {\n break\n }\n }\n while (true) {\n val toLeft = set.floor(pair)\n if (toLeft != null && toLeft.r >= l) {\n L = Math.min(L, toLeft.l)\n R = Math.max(R, toLeft.r)\n set.remove(toLeft)\n } else {\n break\n }\n }\n set.add(Pair(L, R))\n out.print(set.size.toString() + \" \")\n }\n out.println()\n out.close()\n } catch (ex : IOException) {\n }\n}\n\nclass Pair(internal var l: Int, internal var r: Int) : Comparable {\n\n\n override fun compareTo(o: Pair): Int {\n return if (l != o.l) {\n Integer.compare(l, o.l)\n } else Integer.compare(r, o.r)\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["data structures"], "code_uid": "a27fd47b8216135bec3ad85d30a62199", "src_uid": "3979abbe7bad0f3b5cab15c1cba19f6b", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (vStart, vEnd) = readInts()\n val (time, d) = readInts()\n var meters = 0\n var currentTime = 0\n var currentSpeed = vStart\n while(currentTime < time) {\n meters += currentSpeed\n currentTime++\n val timeAfter = time - currentTime - 1\n val desiredSpeed = vEnd + timeAfter*d\n currentSpeed = max(currentSpeed - d, min(desiredSpeed, currentSpeed + d))\n }\n print(meters)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "dp"], "code_uid": "5a5ad70300197807d37d35d510be77a6", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main (args: Array) {\n\n var counter = 0\n var index = readLine()!!.toInt()\n\n while(index > 0) index -= (++counter).toString().length\n println(counter.toString()[index + (counter.toString().length - 1)])\n\n}\n\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "998233735f88cefbc6fb3aafb52662d9", "src_uid": "2d46e34839261eda822f0c23c6e19121", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n: Int = readLine()!!.toInt()\n var stringB: StringBuilder = StringBuilder(n)\n Array(n, { i -> i + 1 }).forEach { stringB.append(it) }\n println(stringB.elementAt(n - 1))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "e66f68b1cb3841a0ce8435d0992957d1", "src_uid": "2d46e34839261eda822f0c23c6e19121", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main (args: Array) {\n\n var counter = 0\n var index = readLine()!!.toInt()\n\n while(index > 0){\n counter++\n index -= counter.toString().length\n }\n\n println(counter.toString()[index + (counter.toString().length - 1)])\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "bc24247dfb8dc9dbb0d7e6979e7ecab0", "src_uid": "2d46e34839261eda822f0c23c6e19121", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n val nthNumber = reader.nextInt()\n var numbers = \"\"\n for (i in 1 until 1001)\n numbers += i\n println(numbers[nthNumber-1])\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d39b8b0b45ea7581c2fe169d10210e05", "src_uid": "2d46e34839261eda822f0c23c6e19121", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val bitsPerCell = readInt()\n val s = readLine()!!\n var sol = 0\n for (c in s)\n if (c == '1') sol++ else return print(sol + 1)\n print(bitsPerCell)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "973bd6e1e8cc31af9c56408a581a972d", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n var n = readLine()!!.toInt()\n var str = readLine()!!\n var ans = \"\"\n var rem = 0\n var flag = true\n if (str[0]=='1'){\n ans+='0'\n rem = 1\n }else{\n ans+='1'\n for (i in 1..str.length-1){\n ans+=str[i]\n flag = false\n }\n }\n var i = 1\n while (i _factorialMemo.lastIndex) {\n _factorialMemo.add(_factorialMemo.last() * _factorialMemo.size)\n }\n\n _factorialMemo[this]\n}\n\nfun P(n: Int, k: Int) = n.factorial() / (n-k).factorial()\nfun C(n: Int, k: Int) = n.factorial() / k.factorial() / (n-k).factorial()\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", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "ced08c95d0da9d065ecc3664993fb069", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() {\n output {\n val n = readInt()\n val k = readInt()\n\n var ans = ModInt(0)\n\n val kp = k.powArray(n)\n val kmp = (k-1).powArray(n)\n\n for(i in 0 until n) {\n val m = C(n, i) * (kp[n-i] * kmp[i] - kmp[n]).pow(n)\n if(i and 1 == 1) ans -= m\n else ans += m\n }\n\n println(ans)\n }\n}\n\nfun Int.powArray(n: Int) = ModIntArray(n+1).also {\n it[0] = ModInt(1)\n for(i in 1..n) {\n it[i] = it[i-1] * this\n }\n}\n\nprivate val _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\nfun P(n: Int, k: Int) = n.factorial() / (n-k).factorial()\nfun C(n: Int, k: Int) = n.factorial() / k.factorial() / (n-k).factorial()\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", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "9593fb46f700e4914e0e93abd0d7a60c", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\nclass Comb(n: Int, val mod: Int) {\n\n val F = LongArray(n + 1)\n val I = LongArray(n + 1)\n init {\n F[0] = 1\n for (i in 1..n) {\n F[i] = F[i - 1] * i % mod\n }\n I[n] = powMod(F[n], (mod - 2).toLong(), mod)\n for (i in n - 1 downTo 0) {\n I[i] = I[i + 1] * (i + 1) % mod\n }\n }\n\n private fun powMod(a: Long, n: Long, mod: Int): Long {\n if (n == 0L) return 1\n val res = powMod(a * a % mod, n / 2, mod)\n return if (n % 2 == 1L) res * a % mod else res\n }\n\n fun comb(n: Int, k: Int): Long {\n return F[n] * I[k] % mod * I[n - k] % mod\n }\n\n fun inv(x: Int): Long {\n return I[x] * F[x - 1] % mod\n }\n\n /**\n * n\u306e\u30b0\u30eb\u30fc\u30d7\u304b\u3089k\u56de\u91cd\u8907\u3042\u308a\u3067\u9078\u3076\u7d44\u307f\u5408\u308f\u305b\u6570\n * n - 1\u306e\u3057\u304d\u308a\u3068k\u306e\u25cb\u3067\u8003\u3048\u308b\n */\n fun H(n: Int, k: Int) = comb(n + k - 1, k)\n}\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val N = ni()\n val K = nl()\n val comb = Comb(N + 10, MOD)\n val powK = LongArray(N + 11)\n val powKK = LongArray(N + 11)\n powK[0] = 1\n powKK[0] = 1\n for (i in 0 until N + 10) {\n powK[i + 1] = powK[i] * K % MOD\n powKK[i + 1] = powKK[i] * (K - 1) % MOD\n }\n val dp = Array(N + 1){LongArray(N + 1)}\n dp[0][0] = 1\n for (i in 0 until N) {\n for (s in 0 .. N) {\n val cmb1 = (MOD + powK[s] - powKK[s]) % MOD // s\u306e\u4e2d\u306b\uff11\u304c\u3042\u308b\n val cmbAll = powK[s] // \u3059\u3079\u3066\n for (add in 0 .. N - s) {\n val ns = s + add\n val cl = if (add == 0) cmb1 else cmbAll // s\u5074\u306e\u7d44\u307f\u5408\u308f\u305b\n val cr1 = comb.comb(N - s, add) // add\u306e1\u90e8\u5206\n val crr = powKK[N - s - add] // add\u306e1\u4ee5\u5916\u306e\u90e8\u5206\n val cmb = cl * cr1 % MOD * crr % MOD\n dp[i + 1][ns] = (dp[i + 1][ns] + dp[i][s] * cmb % MOD) % MOD\n }\n }\n debug(dp[i + 1])\n }\n\n out.println(dp[N][N])\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "f5d66f2ea329ad3d32c03692f75a2caa", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.*\n\nfun main() {\n output {\n val n = readInt()\n var k = readInt()\n val S = readLn().toCharArray()\n\n for(i in 0 until n) {\n if(k == 0) break\n\n val t = if(i == 0 && n > 1) '1' else '0'\n if(S[i] != t) {\n S[i] = t\n k--\n }\n }\n\n println(String(S))\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", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "9464a75536e408aa726d0434faa5732d", "src_uid": "0515ac888937a4dda30cad5e2383164f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (n, k) = readLine()!!.split(\" \").map(String::toInt)\n\n println(\n if (n == k && n == 1) 0 else readLine()!!.toCharArray()\n .mapIndexed { index, c ->\n if (index == 0 && c > '1' && k > 0) { k--; '1' }\n else if (index > 0 && c > '0' && k > 0) { k--; '0' }\n else { c }\n }.joinToString(separator = \"\")\n )\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "890c6016422ba7ec282cf2c014056682", "src_uid": "0515ac888937a4dda30cad5e2383164f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun String.isPalindrome(): Boolean {\n var left = -1\n var right = this.length\n while (++left <= --right)\n if (this[left] != this[right]) return false\n return true\n }\n\n val s = readLine()!!\n print(\n when {\n !s.isPalindrome() -> s.length\n s.toSet().size == 1 -> 0\n else -> s.length - 1\n }\n )\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "0755adb3d204d5edcc5e0c1e483183e7", "src_uid": "6c85175d334f811617e7030e0403f706", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Integer.min\nimport kotlin.properties.Delegates\n\nfun main(){\n val string = readLine()!!\n var answer : Int by Delegates.vetoable(0) {\n property, oldValue, newValue -> oldValue < newValue\n }\n for (i in string.indices) {\n for (j in i until string.length) {\n //print(\"$i $j \\n\")\n if (!string.isPalindrome(i, j))\n answer = j - i + 1\n }\n }\n print(answer)\n}\n\nfun String.isPalindrome(a : Int, b : Int) : Boolean{\n var l = a\n var r = b\n while (l <= r) {\n if (this[l] != this[r])\n return false\n l++\n r--\n }\n return true\n}\n\n\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "ed886697142f5f502163428005d53a7c", "src_uid": "6c85175d334f811617e7030e0403f706", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun String.isPoly() = this.take(this.length/2) == this.takeLast(this.length/2).reversed()\nfun main(args: Array) {\n var s = readLine()!!\n if(!s.isPoly()) {\n print(s.length)\n } else {\n while(s.isPoly() && s.isNotEmpty()) s=s.dropLast(1)\n print(s.length)\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "d6be0c49e199e6cb213a64d700b7d52d", "src_uid": "6c85175d334f811617e7030e0403f706", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nval scan = Scanner(System.`in`)\nfun main(args: Array) {\n var s = scan.next()\n while (s.length>0 && s == s.reversed()) {\n s= s.substring(0, s.length-1)\n }\n print (s.length)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "6cf8190bcd819b6c2eaa81593640f42f", "src_uid": "6c85175d334f811617e7030e0403f706", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "const val MOD = 1_000_000_007\n\nfun main(args: Array) {\n var (n, k) = readLine()!!.split(' ').map(String::toLong)\n\n var result = 1\n var d = 2L\n while (d * d <= n) {\n var deg = 0\n while (n % d == 0L) {\n n /= d\n ++deg\n }\n if (deg > 0) {\n result = mult(result, f(d, deg, k.toInt()))\n }\n ++d\n }\n if (n > 1) {\n result = mult(result, f(n, 1, k.toInt()))\n }\n println(result)\n}\n\nfun f(_p: Long, deg: Int, k: Int): Int {\n val dp = Array(k + 1) { IntArray(deg + 1) }\n dp[0][deg] = 1\n val inverses = IntArray(deg + 2) { inverse(it) }\n for (step in 1..k) {\n for (d in 0..deg) {\n for (nd in d..deg) {\n dp[step][d] = add(dp[step][d], mult(dp[step - 1][nd], inverses[nd + 1]))\n }\n }\n }\n var result = 0\n var pi = 1\n val p = (_p % MOD).toInt()\n for (i in 0..deg) {\n result = add(result, mult(dp[k][i], pi))\n pi = mult(pi, p)\n }\n return result\n}\n\nfun inverse(n: Int) = binPow(n, MOD - 2)\n\nfun binPow(x: Int, n: Int): Int {\n return when {\n n == 0 -> 1\n n % 2 == 1 -> mult(x, binPow(x, n - 1))\n else -> {\n val half = binPow(x, n / 2)\n mult(half, half)\n }\n }\n}\n\nfun add(a: Int, b: Int) = (a + b) % MOD\n\nfun mult(a: Int, b: Int) = ((a.toLong() * b) % MOD).toInt()", "lang_cluster": "Kotlin", "tags": ["math", "dp", "probabilities", "number theory"], "code_uid": "51ec35db931721b9ad3f715922c906a1", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() {\n output {\n val n = readLong()\n val k = readInt()\n\n var ans = ModInt(1)\n\n for((p0, a) in n.factorize().runs()) {\n var D = ModIntArray(a+1)\n D[a] = ModInt(1)\n\n for(i in 1..k) {\n val Di = ModIntArray(a+1)\n var acc = ModInt(0)\n for(j in a downTo 0) {\n acc += D[j] / (j+1)\n Di[j] = acc\n }\n D = Di\n }\n\n val p = p0.toModInt()\n var b = ModInt(1)\n var sum = ModInt(0)\n\n for(j in 0..a) {\n sum += D[j] * b\n b *= p\n }\n\n ans *= sum\n }\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\ndata class Run(val item: T, val num: Int)\n\nfun Sequence.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\nconst val BILLION7 = 1e9.toInt() + 7\nconst val MODINT_BASE = BILLION7\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\ninline fun Int.toModInt() = ModInt(this umod MODINT_BASE)\ninline fun Long.toModInt() = ModInt((this umod MODINT_BASE).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 @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 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\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 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", "lang_cluster": "Kotlin", "tags": ["math", "dp", "probabilities", "number theory"], "code_uid": "17a9369b14c653b73cca1c74410baf20", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport kotlin.math.sqrt\n\nprivate val reader = System.`in`.bufferedReader()\nprivate fun readLn() = reader.readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong()\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() }\nprivate val writer = PrintWriter(System.out.bufferedWriter())\nprivate fun write(any: Any) = writer.print(any)\nprivate fun writeLn(any: Any) = writer.println(any)\nprivate fun flush() = writer.flush()\n\nprivate fun factors(n: Long): LongArray {\n val ret = mutableListOf()\n val limit = sqrt(n.toDouble()).toInt()\n for (i in 1..limit) {\n if (n % i == 0L) {\n ret.add(i.toLong())\n if (i.toLong() * i != n) {\n ret.add(n / i)\n }\n }\n }\n ret.sort()\n return ret.toLongArray()\n}\n\nfun main() {\n Thread(null, {\n val (n, kTmp) = readLongs()\n val k = kTmp.toInt()\n debug(\"k=$k\")\n\n val t = System.nanoTime()\n\n val primeFactors = mutableListOf>() // (prime, exp)\n run {\n val limit = sqrt(n.toDouble()).toInt()\n var nn = n\n for (i in 2..limit) {\n if (nn % i == 0L) {\n var cnt = 0\n while (nn % i == 0L) {\n cnt++\n nn /= i\n }\n primeFactors.add(i.toLong() to cnt)\n }\n }\n if (nn > 1) {\n primeFactors.add(nn to 1)\n }\n for (primeFactor in primeFactors) {\n debug(primeFactor)\n }\n }\n\n var ans = 1L\n\n fun solve(p: Long, e: Int): Long {\n val props = Array(k + 1) { LongArray(e + 1) { 0 } }\n val ev = Array(k + 1) { LongArray(e + 1) { 0 } }\n for (i in 0..e) {\n props[0][i] = 1\n ev[0][i] = p.powerMod(i)\n }\n for (kk in 1..k) {\n for (i in 0..e) {\n for (j in 0..i) {\n props[kk][i] = props[kk][i].addMod(props[kk - 1][j])\n ev[kk][i] = ev[kk][i].addMod(ev[kk - 1][j])\n }\n props[kk][i] = props[kk][i].divMod(i + 1L)\n ev[kk][i] = ev[kk][i].divMod(i + 1L)\n }\n }\n return ev[k][e]\n }\n\n for ((p, exp) in primeFactors) {\n ans = ans.mulMod(solve(p, exp))\n }\n\n writeLn(ans)\n\n debug(\"time: ${(System.nanoTime() - t) / 1e9}\")\n }, \"cool\", 1 shl 28).apply {\n start()\n join()\n }\n flush()\n}\n\nprivate fun invMod0(a: Long, m: Long): Long {\n val ans = extGcd(a, m)\n return if (ans[0] == 1L) (ans[1] + m) % m else -1\n}\n\nprivate fun extGcd(a: Long, m: Long): LongArray {\n return if (m == 0L) {\n longArrayOf(a, 1, 0)\n } else {\n val ans = extGcd(m, a % m)\n val tmp = ans[1]\n ans[1] = ans[2]\n ans[2] = tmp\n ans[2] -= ans[1] * (a / m)\n ans\n }\n}\n\nprivate fun Long.sqr() = this * this\n\nprivate const val MODULO = (1e9 + 7).toLong()\nprivate fun Long.addMod(other: Long): Long {\n var ret = this + other\n while (ret >= MODULO) {\n ret -= MODULO\n }\n while (ret < 0) {\n ret += MODULO\n }\n return ret\n}\n\nprivate fun Long.subMod(other: Long) = addMod(-other)\nprivate fun Long.mulMod(other: Long) = this % MODULO * (other % MODULO) % MODULO\nprivate fun Long.invMod() = invMod0(this, MODULO)\nprivate fun Long.divMod(other: Long) = mulMod(other.invMod())\nprivate fun Long.powerMod(exp: Int): Long = when {\n exp == 0 -> 1\n exp % 2 == 0 -> powerMod(exp / 2).sqr() % MODULO\n else -> powerMod(exp - 1).mulMod(this)\n}\n\nprivate fun debug(any: Any) {\n System.err.println(any)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "probabilities", "number theory"], "code_uid": "23b8a5d8849149eeea8c0b612ab375fb", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport kotlin.math.log\nimport kotlin.math.sqrt\n\nprivate val reader = System.`in`.bufferedReader()\nprivate fun readLn() = reader.readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong()\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() }\nprivate val writer = PrintWriter(System.out.bufferedWriter())\nprivate fun write(any: Any) = writer.print(any)\nprivate fun writeLn(any: Any) = writer.println(any)\nprivate fun flush() = writer.flush()\n\nfun main() {\n Thread(null, {\n val (n, kTmp) = readLongs()\n val k = kTmp.toInt()\n debug(\"k=$k\")\n\n val t = System.nanoTime()\n\n val primeFactors = mutableListOf>() // (prime, exp)\n run {\n val limit = sqrt(n.toDouble()).toInt()\n var nn = n\n for (i in 2..limit) {\n if (nn % i == 0L) {\n var cnt = 0\n while (nn % i == 0L) {\n cnt++\n nn /= i\n }\n primeFactors.add(i.toLong() to cnt)\n }\n }\n if (nn > 1) {\n primeFactors.add(nn to 1)\n }\n for (primeFactor in primeFactors) {\n debug(primeFactor)\n }\n }\n\n val invs = LongArray(log(1e15, 2.0).toInt() + 10)\n debug(invs.size)\n for (i in invs.indices) {\n invs[i] = i.toLong().invMod2()\n }\n\n var ans = 1L\n\n fun solve(p: Long, e: Int): Long {\n val props = Array(k + 1) { LongArray(e + 1) { 0 } }\n val ev = Array(k + 1) { LongArray(e + 1) { 0 } }\n for (i in 0..e) {\n props[0][i] = 1\n ev[0][i] = p.powerMod(i)\n }\n for (kk in 1..k) {\n for (i in 0..e) {\n for (j in 0..i) {\n props[kk][i] = props[kk][i].addMod(props[kk - 1][j])\n ev[kk][i] = ev[kk][i].addMod(ev[kk - 1][j])\n }\n props[kk][i] = props[kk][i].mulMod(invs[i + 1])\n ev[kk][i] = ev[kk][i].mulMod(invs[i + 1])\n }\n }\n return ev[k][e]\n }\n\n for ((p, exp) in primeFactors) {\n ans = ans.mulMod(solve(p, exp))\n }\n\n writeLn(ans)\n\n debug(\"time: ${(System.nanoTime() - t) / 1e9}\")\n }, \"cool\", 1 shl 28).apply {\n start()\n join()\n }\n flush()\n}\n\nprivate fun invMod0(a: Long, m: Long): Long {\n val ans = extGcd(a, m)\n return if (ans[0] == 1L) (ans[1] + m) % m else -1\n}\n\nprivate fun extGcd(a: Long, m: Long): LongArray {\n return if (m == 0L) {\n longArrayOf(a, 1, 0)\n } else {\n val ans = extGcd(m, a % m)\n val tmp = ans[1]\n ans[1] = ans[2]\n ans[2] = tmp\n ans[2] -= ans[1] * (a / m)\n ans\n }\n}\n\nprivate fun Long.sqr() = this * this\n\nprivate const val MODULO = (1e9 + 7).toLong()\nprivate fun Long.addMod(other: Long): Long {\n var ret = this + other\n while (ret >= MODULO) {\n ret -= MODULO\n }\n while (ret < 0) {\n ret += MODULO\n }\n return ret\n}\n\nprivate fun Long.subMod(other: Long) = addMod(-other)\nprivate fun Long.mulMod(other: Long) = this % MODULO * (other % MODULO) % MODULO\nprivate fun Long.invMod() = invMod0(this, MODULO)\nprivate fun Long.invMod2() = powerMod(MODULO - 2)\nprivate fun Long.divMod(other: Long) = mulMod(other.invMod2())\nprivate fun Long.powerMod(exp: Int) = powerMod(exp.toLong())\nprivate fun Long.powerMod(exp: Long): Long = when {\n exp == 0L -> 1\n exp % 2 == 0L -> powerMod(exp / 2).sqr() % MODULO\n else -> powerMod(exp - 1).mulMod(this)\n}\n\nprivate fun debug(any: Any) {\n System.err.println(any)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "probabilities", "number theory"], "code_uid": "7f56192d6b8ad4ae19f07912efcb8600", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val positions = \"v<^>\"\n val fromTo = readLine()!!\n val duration = readLine()!!.toInt() % 4\n var sol = if (fromTo[2] == positions[(positions.indexOf(fromTo[0]) + duration) % 4]) 1 else 0\n if (fromTo[2] == positions[(positions.indexOf(fromTo[0]) + 4 - duration) % 4]) sol = sol or 2\n print(\n when (sol) {\n 1 -> \"cw\"\n 2 -> \"ccw\"\n else -> \"undefined\"\n }\n )\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "eaa46f9faee0f3516676b845e34724e5", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.InputStream\n\nprivate val input = FastScanner()\n\nfun main(args: Array) = input.run {\n val s = \"<^>v\"\n val a = nextString()!![0].let { s.indexOf(it) }\n val b = nextString()!![0].let { s.indexOf(it) }\n val n = nextInt()\n if (b == (a + n) % 4 && b == Math.floorMod(a - n, 4)) {\n println(\"undefined\")\n } else if (b == Math.floorMod(a - n, 4)) {\n println(\"ccw\")\n } else {\n println(\"cw\")\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 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 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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "aa6d8f3d9a9c36e1ce70e598e68c1954", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n\nfun main(args: Array) {\n val spin = \"v<^>\"\n\n val line = readLine()!!\n val s = line.split(\" \")[0]\n val e = line.split(\" \")[1]\n\n val n = readLine()!!.toInt()\n\n when {\n n % 2 == 0 -> println(\"undefined\")\n n % 2 == 1 -> {\n if(spin[(spin.indexOf(s) + n) % 4] == e[0]) println(\"cw\")\n else println(\"ccw\")\n }\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "31dc80ae248abcd70b7d8510c9409b0a", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n\n val scanner = Scanner(System.`in`)\n\n val destPoint = scanner.nextInt()\n val maxLitersCount = scanner.nextInt()\n val stationCoordinate = scanner.nextInt()\n val ridesCount = scanner.nextInt()\n\n var ans = 0\n\n var currentFuel = maxLitersCount\n var distanceToRide: Int\n\n if (maxLitersCount < stationCoordinate) {\n println(-1)\n return\n } else {\n currentFuel -= stationCoordinate\n }\n\n for (currentRideNumber in 0 until ridesCount) {\n distanceToRide = if (currentRideNumber.rem(2) == 0) {\n destPoint - stationCoordinate\n } else {\n stationCoordinate\n }\n if (currentRideNumber < ridesCount - 1) {\n distanceToRide *= 2\n }\n if (maxLitersCount < distanceToRide) {\n println(-1)\n return\n } else if (currentFuel < distanceToRide) {\n ans++\n currentFuel = maxLitersCount\n }\n\n currentFuel -= distanceToRide\n }\n\n println(ans)\n\n\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "9033c5ae411636c91f14f70bf8bc430d", "src_uid": "283aff24320c6518e8518d4b045e1eca", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val line = readLine()!!\n val six = line.indexOf(' ')\n val n = line.substring(0, six).toLong()\n val k = line.substring(six + 1).toLong()\n var len = 0\n while (1L shl len <= n) {\n len++\n }\n fun amt(d: Long): Long {\n var res = 0L\n if (d % 2L == 0L) {\n res += amt(d + 1L)\n }\n var l = 0\n while (1L shl l <= d) {\n l++\n }\n var l2 = l\n while (l2 < len) {\n res += 1L shl (l2 - l)\n l2++\n }\n val q = n / (1L shl (len - l))\n if (q > d) {\n res += 1L shl (len - l)\n } else if (q == d) {\n res += (n % (1L shl (len - l))) + 1L\n }\n //println(\"amt($d) = $res\")\n return res\n }\n var lower = 0L\n var upper = n / 2L\n while (upper > lower) {\n val mid = (lower + upper + 1L) / 2L\n if (amt(2L * mid) >= k) {\n lower = mid\n } else {\n upper = mid - 1L\n }\n }\n var answer = upper * 2L\n if (amt(answer + 1L) >= k) {\n answer++\n }\n println(answer)\n}", "lang_cluster": "Kotlin", "tags": ["math", "binary search", "dp", "combinatorics"], "code_uid": "133e956bd85e05b2fa5710c86ef0a485", "src_uid": "783c4b3179c558369f94f4a16ac562d4", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val xs = mutableSetOf()\n val ys = mutableSetOf()\n repeat(readInt()) {\n val (x, y) = readInts()\n xs.add(x)\n ys.add(y)\n }\n if (xs.size != 2 || ys.size != 2) return print(-1)\n print((xs.max()!! - xs.min()!!) * (ys.max()!! - ys.min()!!))\n}", "lang_cluster": "Kotlin", "tags": ["geometry", "implementation"], "code_uid": "8e593cf60101b998befd89cea854ee5e", "src_uid": "ba49b6c001bb472635f14ec62233210e", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : InputReader, pw : PrintWriter) {\n\n val n : Int = ir.nextInt()\n val x = IntArray(n)\n val y = IntArray(n)\n\n for (i in 0 until n) {\n x[i] = ir.nextInt()\n y[i] = ir.nextInt()\n }\n\n for (i in 0 until n)\n for (j in (i + 1) until n)\n if (x[i] != x[j] && y[i] != y[j]) {\n pw.print(Math.abs(x[i] - x[j]) * Math.abs(y[i] - y[j]))\n return\n }\n\n pw.print(-1)\n\n}\n\nclass InputReader(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}", "lang_cluster": "Kotlin", "tags": ["geometry", "implementation"], "code_uid": "20057ffab1a0e7e8d35c8bdd373996e4", "src_uid": "ba49b6c001bb472635f14ec62233210e", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun nextLn() = readLine()!!\nfun nextInt() = nextLn().toInt()\nfun nextStrings() = nextLn().split(\" \")\nfun nextInts() = nextStrings().map { it.toInt() }\nfun nextLongs() = nextStrings().map { it.toLong() }\n\nvar mod = 998244353\n\nfun main(args: Array) {\n var (n, m) = nextInts()\n var a = MutableList>(456789) {ArrayList()}\n var cntk = nextInts().toMutableList()\n for (i in 1 .. m) {\n var (d, t) =nextInts()\n a[d].add(t - 1)\n }\n fun check(d : Int) : Boolean {\n var money = 0\n var cnt = cntk.toMutableList()\n var lastd = MutableList(n) {d + 1}\n for (i in 1 .. d) {\n for (k in a[i]) {\n lastd[k] = i\n }\n }\n for (i in 1 .. d) {\n money += 1\n for (k in a[i]) {\n if (lastd[k] != i)\n continue\n var c = minOf(cnt[k], money)\n cnt[k] -= c\n money -= c\n }\n }\n for (i in 0 .. n-1) {\n money -= 2 * cnt[i]\n }\n return money >= 0\n }\n var l = 0\n var r = 400001\n while (l + 1 < r) {\n var mid = (l + r) / 2\n if (check(mid)) \n r = mid\n else\n l = mid\n }\n println(r)\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy", "binary search"], "code_uid": "365a077eb3b48475ae5448bbc86da1cc", "src_uid": "2eb101dcfcc487fe6e44c9b4c0e4024d", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\nprivate val MOD = 1_000_000_007L\n\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val N = ni()\n var best = Array(2){LongArray(N + 10)}\n var next = Array(2){LongArray(N + 10)}\n best[0][0] = 1\n\n for (i in 0 until N) {\n Arrays.fill(next[0], 0)\n Arrays.fill(next[1], 0)\n for (j in 0 .. i) {\n for (s in 0 until 2) { // reflexive\u3092\u6e80\u305f\u3055\u306a\u3044\n for (k in 0 until 2) { // \u8ffd\u52a0\u3059\u308b\u304b\n for (l in 0 until 2) { // \u9023\u7d50\u3059\u308b\u304b\n if (k == 0 && l == 1) continue\n val nj = if (k == 1 && l == 0) j + 1 else j\n val ns = if (s == 0 && k == 1) 0 else 1\n val c = if (l == 1) j else 1\n next[ns][nj] = (next[ns][nj] + best[s][j] * c) % MOD\n }\n }\n }\n }\n val tmp = best\n best = next\n next = tmp\n }\n\n debug(best[0])\n debug(best[1])\n\n out.println(best[1].sum() % 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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "da5420a227f0d73332e5915f4798090b", "src_uid": "aa2c3e94a44053a0d86f61da06681023", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextLong()\n val k = scanner.nextLong()\n val M = scanner.nextLong()\n val D = scanner.nextLong()\n var ans = 0L\n for (d in 1..D) {\n val maxX = min(M, (n.toBigInteger() / ((d - 1).toBigInteger() * k.toBigInteger() + 1.toBigInteger())).longValueExact())\n if (maxX == 0L) continue\n if (d != ((n / maxX) + k - 1) / k) continue;\n ans = max(ans, maxX * d);\n }\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "25759a205e0d4b32dd966f14d930dc86", "src_uid": "ac2e795cd44061db8da13e3947ba791b", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numDays, numKilos) = readInts()\n val prices = readInts()\n var best = 0\n for (day in 0 until numDays - 1)\n best = max(best, prices[day] - prices[day + 1] - numKilos)\n print(best)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation"], "code_uid": "d3ce75f50db8d818815adacbd426e857", "src_uid": "411539a86f2e94eb6386bb65c9eb9557", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //var (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n val (day, ret) = r.readLine()!!.split(\" \").map { it.toInt() }\n val v = r.readLine()!!.split(\" \").map { it.toInt() }\n var get = 0\n for (i in 1..day-1){\n val profit = (v[i-1]-v[i])-ret\n get = maxOf(get, profit)\n }\n println(get)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation"], "code_uid": "6f0039edbbb8debab0ea2e06849720fb", "src_uid": "411539a86f2e94eb6386bb65c9eb9557", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLine()!!\n println(\n if (s.length >= 5 &&\n s.contains(Regex(\"[a-z]\")) &&\n s.contains(Regex(\"[A-Z]\")) &&\n s.contains(Regex(\"[0-9]\"))) \"Correct\" else \"Too weak\")\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "ee248726e94d1d288d5f6576cc7064f9", "src_uid": "42a964b01e269491975965860ec92be7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 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 str = st.nextToken()\n var hasDigit = false; var hasLower = false; var hasUpper = false\n for (c in str) {\n if (c >= '0' && c <= '9') hasDigit = true\n else if (c >= 'a' && c <= 'z') hasLower = true\n else if (c >= 'A' && c <= 'Z') hasUpper = true\n }\n if (str.length >= 5 && hasDigit && hasLower && hasUpper) bw.write(\"Correct\")\n else bw.write(\"Too weak\")\n bw.newLine()\n bw.flush()\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9369081d5d7273169347e1bbae62c164", "src_uid": "42a964b01e269491975965860ec92be7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val r = readLine()!!.split(' ').map(String::toInt)\n println(2+(r.min()!! xor r[2]))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "dbd6dc2a187ad2f5f2e978a608929382", "src_uid": "a9eb85dfaa3c50ed488d41da4f29c697", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val princessSpeed = readLine()!!.toDouble()\n val dragonSpeed = readLine()!!.toDouble()\n val discoveryTime = readLine()!!.toInt()\n val timeWastedInCave = readLine()!!.toInt()\n val distanceToCastle = readLine()!!.toInt()\n var coinsCount = 0\n if (princessSpeed <= dragonSpeed) {\n var princessLocation = discoveryTime * princessSpeed\n var overtakeLocation = princessLocation + (princessSpeed * (princessLocation / (dragonSpeed - princessSpeed)))\n while (overtakeLocation < distanceToCastle) {\n princessLocation = overtakeLocation\n coinsCount++\n val bufferTime = (princessLocation / dragonSpeed) + timeWastedInCave\n princessLocation += bufferTime * princessSpeed\n overtakeLocation = princessLocation + (princessSpeed * (princessLocation / (dragonSpeed - princessSpeed)))\n }\n }\n println(coinsCount)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "3fe64abdcb2ce78bf167a16b50710ef6", "src_uid": "c9c03666278acec35f0e273691fe0fff", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.PriorityQueue\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 numCases = 1//readInt()\n case@ for(case in 1..numCases) {\n //print(\"Case #$case: \")\n\n val n = readInt()\n val m = readInt()\n\n var x = ModInt(2).pow(m).dec()\n var ans = ModInt(1)\n\n repeat(n) {\n ans *= x\n x--\n }\n\n println(ans.int)\n }\n}\n\nconst val BILLION7 = 1e9.toInt() + 7\nconst val MOD = BILLION7+2\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: Int, 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 == 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 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 {\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.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)) }\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 }\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\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`() { 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", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "cca80529c172ff5f5a97ea8c3a20c996", "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n val num = r.readLine()!!.toInt()\n //var (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n val m = r.readLine()!!.split(\" \").map { it.toInt() }\n val n = r.readLine()!!.split(\" \").map { it.toInt() }\n val c1 = m.subList(1, m[0]+1).toMutableList()\n val c2 = n.subList(1, n[0]+1).toMutableList()\n val hash = mutableSetOf()\n var ans = 0\n while (c1.size>0&&c2.size>0){\n ans ++\n when{\n c1[0]>c2[0] -> {\n c1 += c2[0]\n c1 += c1[0]\n c1.removeAt(0)\n c2.removeAt(0)\n }\n c1[0] {\n c2 += c1[0]\n c2 += c2[0]\n c1.removeAt(0)\n c2.removeAt(0)\n }\n }\n if (c1.hashCode()-c2.hashCode() !in hash) {\n hash += c1.hashCode()-c2.hashCode()\n } else {\n ans = -1\n break\n }\n }\n val win = if (c1.size==0) 2 else 1\n println(if (c1.size*c2.size!=0) -1 else \"$ans $win\")\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "brute force", "games"], "code_uid": "0082df935033d89aacc1e695372bb33a", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 numCards = readInt()\n val soldier1 = readInts().toMutableList()\n val soldier2 = readInts().toMutableList()\n var pos = 0\n while (++pos < 1000 && pos < soldier1.size && pos < soldier2.size) {\n if (soldier1[pos] > soldier2[pos]) {\n soldier1.add(soldier2[pos])\n soldier1.add(soldier1[pos])\n } else {\n soldier2.add(soldier1[pos])\n soldier2.add(soldier2[pos])\n }\n }\n print(\n when (pos) {\n 1000 -> -1\n soldier1.size -> \"${pos - 1} 2\"\n else -> \"${pos - 1} 1\"\n }\n )\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "brute force", "games"], "code_uid": "637fc18093f9ca29b1a3824bbc409ef6", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (hour, minutes) = readLine()!!.split(\":\").map(String::toInt)\n val minutesPassed = readLine()!!.toInt()\n val totalMinutes = hour * 60 + minutes + minutesPassed\n val newHour = (totalMinutes / 60) % 24\n val newMinutes = totalMinutes % 60\n print(\"${String.format(\"%02d\", newHour)}:${String.format(\"%02d\", newMinutes)}\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "6444ce1ebe9e6b9f9a1d6d3140aad37e", "src_uid": "20c2d9da12d6b88f300977d74287a15d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.lang.Math.*\nimport java.math.BigInteger\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\nimport kotlin.math.sqrt\n\ntypealias IndexPair = Pair\ntypealias IntIndexPair = IndexPair\ntypealias IntIntPair = Pair\n\ntypealias IntMatrix = Array\ntypealias LongMatrix = Array\n\ntypealias ListArray = Array>\n\ntypealias Graph = IntMatrix\n\ntypealias Edge = Pair\ntypealias EdgeArray = Array\ntypealias WeightedGraph = Array\n\ntypealias TotalEdge = Triple\ntypealias TotalEdgeArray = Array\n\nfun init() { }\n\nconst val MODULO = 1000 * 1000 * 1000 + 7\n\nfun solve() {\n val (h, m) = readInts(\":\")\n val delay = readInt()\n\n val startTime = h * 60 + m\n val endTime = (startTime + delay) % (24 * 60)\n\n val endH = endTime / 60\n val endM = endTime % 60\n\n out.printf(\"${toTime(endH)}:${toTime(endM)}\")\n}\n\nfun toTime(x : Int) = (x + 100).toString().substring(1)\n\nfun stress() {\n val rnd = Random(1234)\n\n for (it in 0 until 100) {\n val expected = brute()\n val actual = fast()\n\n if (expected != actual) {\n System.err.println(\"Gotcha!\")\n System.err.println(\"$expected $actual\")\n\n break\n }\n }\n}\n\n\nfun fast() {\n\n}\n\nfun brute() {\n\n}\n\nfun Long.mod() : Long {\n var result = this % MODULO\n if (result < 0) result += MODULO\n return result\n}\n\ninfix fun Long.add(other : Long) = (this + other).mod()\ninfix fun Long.sub(other : Long) = this add -other.mod()\ninfix fun Long.mult(other : Long) = (this.mod() * other.mod()).mod()\n\nfun Long.even() = (this and 1L) == 0L\nfun Long.odd() = !even()\n\nfun Int.even() = (this and 1) == 0\nfun Int.odd() = !even()\n\ninfix fun Long.binpow(power : Long) : Long {\n if (power == 0L) return 1L\n\n val half = binpow(power shl 1)\n\n var result = half mult half\n if (power.odd()) {\n result = result mult this\n }\n\n return result\n}\n\nval stepsXY = arrayOf(\n arrayOf(0, -1),\n arrayOf(0, 1),\n arrayOf(-1, 0),\n arrayOf(1, 0)\n)\n\n\n\nclass IndexedWeightedGraph(private val n : Int, private val edges: TotalEdgeArray) {\n\n private val graph : Graph\n\n private fun buildGraphForEdges(\n edgeFilter : (index : Int, edge : TotalEdge) -> Boolean = { _, _ -> true }\n ) : Graph {\n val builder = GraphBuilder()\n edges\n .forEachIndexed { index, edge ->\n if (edgeFilter(index, edge)) {\n val (first, second, _ ) = edge\n\n builder.addDirectedEdge(first, index)\n builder.addDirectedEdge(second, index)\n }\n }\n\n return builder.build(n)\n }\n\n init {\n graph = buildGraphForEdges()\n }\n\n var root : Int = -1\n lateinit var inTree : BooleanArray\n lateinit var tree : Graph\n\n fun kruskalTree(root : Int) : Long {\n this.root = root\n\n inTree = BooleanArray(edges.size) { false }\n\n val dsu = DSU(n)\n\n edges\n .mapIndexed { index, (_, _, w) -> index to w }\n .sortedBy { it.second }\n .forEach {\n val edge = edges[it.first]\n inTree[it.first] = dsu.union(edge.first, edge.second)\n }\n\n tree = buildGraphForEdges { index, _ -> inTree[index] }\n\n return edges\n .mapIndexed { index, (_, _, w) -> if (inTree[index]) w.toLong() else 0L }\n .sum()\n }\n\n private fun to(from : Int, index : Int) : Int {\n val edge = edges[index]\n return if (from == edge.first) edge.second else edge.first\n }\n\n fun buildLca() {\n calculateTimes()\n calculateParents()\n calculatePathInfo()\n }\n\n lateinit var timesIn : IntArray\n lateinit var timesOut : IntArray\n private var time = -1\n\n private fun calculateTimes() {\n timesIn = IntArray(n) { -1 }\n timesOut = IntArray(n) { -1 }\n this.time = 0\n\n timeDfs(root)\n }\n\n private fun timeDfs(from : Int, parent : Int = -1) {\n timesIn[from] = time++\n\n for (index in tree[from]) {\n val to = to(from, index)\n if (to == parent) continue\n\n timeDfs(to, from)\n }\n\n timesOut[from] = time++\n }\n\n lateinit var parents : Array\n private val maxBit = 19\n\n private fun calculateParents() {\n parents = Array(maxBit) { IntArray(n) { -1 } }\n\n parentDfs(root, root)\n\n for (bit in 0 until maxBit - 1) {\n for (v in 0 until n) {\n val parent = parents[bit][v]\n parents[bit + 1][v] = parents[bit][parent]\n }\n }\n }\n\n private fun parentDfs(from : Int, parent : Int = -1) {\n parents[0][from] = parent\n\n for (index in tree[from]) {\n val to = to(from, index)\n if (to == parent) continue\n\n parentDfs(to, from)\n }\n }\n\n lateinit var maxEdges : Array\n\n private fun calculatePathInfo() {\n maxEdges = Array(maxBit) { IntArray(n) { -1 } }\n\n for (v in 0 until n){\n for (index in tree[v]) {\n val to = to(v, index)\n if (to == parents[0][v]) continue\n\n maxEdges[0][to] = edges[index].third\n }\n }\n\n for (bit in 0 until maxBit - 1) {\n for (v in 0 until n) {\n val parent = parents[bit][v]\n maxEdges[bit + 1][v] = max(\n maxEdges[bit][v],\n maxEdges[bit][parent]\n )\n }\n }\n }\n\n fun getOnPath(a : Int, b : Int) : Int {\n var answer = Int.MIN_VALUE\n\n answer = max(answer, getOnLcaPath(a, b))\n answer = max(answer, getOnLcaPath(b, a))\n\n return answer\n }\n\n private fun getOnLcaPath(start : Int, other : Int) : Int {\n var answer = Int.MIN_VALUE\n\n if (timesIn[start] <= timesIn[other] && timesOut[other] <= timesOut[start]) {\n return answer\n }\n\n var v = start\n for (bit in maxBit - 1 downTo 0) {\n val parent = parents[bit][v]\n if (timesIn[parent] > timesIn[other] || timesOut[other] > timesOut[parent]) {\n answer = max(answer, maxEdges[bit][v])\n v = parent\n }\n }\n\n answer = max(answer, maxEdges[0][v])\n\n return answer\n }\n}\n\nfun yesNo(yes : Boolean) {\n out.println(if (yes) \"YES\" else \"NO\")\n}\n\nfun run() {\n init()\n solve()\n out.close()\n}\n\nfun main(args: Array) {\n run()\n}\n\nval ONLINE_JUDGE = !File(\"input.txt\").exists()\n\nval input = BufferedReader(\n if (ONLINE_JUDGE) InputStreamReader(System.`in`) else FileReader(\"input.txt\")\n)\nval out =\n if (ONLINE_JUDGE) PrintWriter(System.out)\n else PrintWriter(\"output.txt\")\n\nfun readStrings(separator: String = \" \", emptyWords: Boolean = false) : Array {\n val line = input.readLine()\n\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 readString(separator: String = \" \") =\n readStrings(separator).first()\n\nfun readInts(separator: String = \" \") =\n readStrings(separator).map(String::toInt).toIntArray()\n\nfun readDecreasedInts(separator : String = \" \") =\n readInts(separator).map { it - 1 }.toIntArray()\n\nfun readSortedInts(separator: String = \" \") : IntArray {\n val a = readInts(separator)\n\n val aInteger = Array(a.size) { a[it] }\n Arrays.sort(aInteger)\n\n return aInteger.toIntArray()\n}\n\nfun readInt(separator: String = \" \") =\n readInts(separator).first()\n\nfun readLongs(separator: String = \" \") =\n readStrings(separator).map(String::toLong).toLongArray()\n\nfun readLong(separator: String = \" \") =\n readLongs(separator).first()\n\nfun readDoubles(separator: String = \" \") =\n readStrings(separator).map(String::toDouble).toDoubleArray()\n\nfun readDouble(separator: String = \" \") =\n readDoubles(separator).first()\n\nfun readBigIntegers(separator: String = \" \") =\n readStrings(separator).map { BigInteger(it) }.toTypedArray()\n\nfun readBigInteger(separator: String = \" \") =\n readBigIntegers(separator).first()\n\nfun readTree(n : Int, indexing : Int = 1) =\n readGraph(n, n - 1, true, indexing)\n\nfun readGraph(n: Int, m : Int,\n undirected : Boolean = true,\n indexing : Int = 1) : Graph {\n val builder = GraphBuilder()\n\n for (i in 1..m) {\n var (from, to) = readInts()\n\n from -= indexing\n to -= indexing\n\n if (undirected) builder.addEdge(from, to)\n else builder.addDirectedEdge(from, to)\n }\n\n return builder.build(n)\n}\n\nfun readWeightedGraph(n : Int, m : Int,\n undirected : Boolean = true,\n indexing : Int = 1) : WeightedGraph {\n val builder = GraphBuilder()\n\n for (i in 1..m) {\n var (from, to, weight) = readInts()\n\n from -= indexing\n to -= indexing\n\n if (undirected) builder.addEdge(from, to, weight)\n else builder.addDirectedEdge(from, to, weight)\n }\n\n return builder.buildWeighted(n)\n}\n\nfun readTotalEdges(m : Int, indexing : Int = 1) =\n TotalEdgeArray(m) {\n var (from, to, w) = readInts()\n\n from -= indexing\n to -= indexing\n\n Triple(from, to, w)\n }\n\nclass GraphBuilder {\n\n private val froms = ArrayList()\n private val tos = ArrayList()\n private val weights = ArrayList()\n\n fun addEdge(from : Int, to : Int, weight : Int = 1) {\n addDirectedEdge(from, to, weight)\n addDirectedEdge(to, from, weight)\n }\n\n fun addDirectedEdge(from : Int, to : Int, weight : Int = 1) {\n froms.add(from)\n tos.add(to)\n weights.add(weight)\n }\n\n private fun calculateFromSizes(n : Int) : IntArray {\n val sizes = IntArray(n) { 0 }\n froms.forEach { ++sizes[it] }\n return sizes\n }\n\n fun build(n : Int) : Graph {\n val sizes = calculateFromSizes(n)\n\n val graph = Graph(n) { IntArray(sizes[it]) { 0 } }\n\n for (i in 0 until n) {\n sizes[i] = 0\n }\n\n for (i in 0 until froms.size) {\n val from = froms[i]\n val to = tos[i]\n\n graph[from][sizes[from]++] = to\n }\n\n return graph\n }\n\n fun buildWeighted(n : Int) : WeightedGraph {\n val sizes = calculateFromSizes(n)\n\n val graph = WeightedGraph(n) { EdgeArray(sizes[it]) { -1 to 0 } }\n\n for (i in 0 until n) {\n sizes[i] = 0\n }\n\n for (i in 0 until froms.size) {\n val from = froms[i]\n val to = tos[i]\n val weight = weights[i]\n\n graph[from][sizes[from]++] = to to weight\n }\n\n return graph\n }\n}\n\nfun gcd(a : Int, b : Int) : Int =\n if (a == 0) b else gcd(b % a, a)\n\nfun gcd(a : Long, b : Long) : Long =\n if (a == 0L) b else gcd(b % a, a)\n\nfun getDivisors(x : Int) : MutableList {\n val divisors = ArrayList()\n\n var d = 1\n while (d * d <= x) {\n if (x % d == 0) {\n if (d != 1) divisors.add(d)\n if (x != d) divisors.add(x / d)\n }\n\n ++d\n }\n\n return divisors\n}\n\nfun getPrimeDivisors(xx : Int) : MutableList {\n val divisors = ArrayList()\n\n var d = 2\n var x = xx\n while (d * d <= x) {\n if (x % d == 0) {\n divisors.add(d)\n while (x % d == 0) {\n x /= d\n }\n }\n\n ++d\n }\n\n if (x > 1) divisors.add(x)\n\n return divisors\n}\n\nfun checkIndex(index : Int, size : Int) =\n 0 <= index && index < size\n\nfun checkCell(x : Int, n : Int, y : Int, m : Int) =\n checkIndex(x, n) && checkIndex(y, m)\n\nfun toChar(index : Int, start : Char) =\n (index + start.toInt()).toChar()\n\nclass DSU {\n\n var sizes : IntArray\n var ranks : IntArray\n var parents : IntArray\n\n constructor(n : Int)\n : this(\n IntArray(n) { 1 }\n )\n\n constructor(sizes : IntArray) {\n val size = sizes.size\n this.sizes = sizes\n this.ranks = IntArray(size) { 1 }\n this.parents = IntArray(size) { it }\n }\n\n operator fun get(v : Int) : Int {\n val parent = parents[v]\n if (parent == v) return v\n parents[v] = get(parent)\n return parents[v]\n }\n\n fun union(aUniting : Int, bUniting : Int) : Boolean {\n var a = get(aUniting)\n var b = get(bUniting)\n\n if (a == b) return false\n\n if (ranks[a] < ranks[b]) {\n val tmp = a\n a = b\n b = tmp\n }\n\n parents[b] = a\n sizes[a] += sizes[b]\n if (ranks[a] == ranks[b]) ++ranks[a]\n\n return true\n }\n\n fun size(v : Int) : Int = sizes[get(v)]\n}\n\nclass FenwickTree(n : Int) {\n\n val size = n + 1\n val tree = LongArray(size) { 0L }\n\n fun update(index : Int, delta : Int) {\n var x = index + 1\n while (x < size) {\n tree[x] = tree[x] + delta\n x += x and -x\n }\n }\n\n operator fun get(start : Int, end : Int) =\n get(end) - get(start - 1)\n\n operator fun get(index : Int) : Long {\n var result : Long = 0\n\n var x = index + 1\n while (x > 0) {\n result += tree[x]\n x -= x and -x\n }\n\n return result\n }\n}\n\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c5856926aff4a86e28fd7b161acd63b8", "src_uid": "20c2d9da12d6b88f300977d74287a15d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\n\nval sc = java.util.Scanner(System.`in`)\n\ndata class Interval(val L: Int, val R: Int) : Comparable {\n\toverride fun compareTo(other: Interval): Int {\n\t\treturn compareValuesBy(this, other, Interval::L, Interval::R)\n\t}\n}\n\nfun main(args: Array) {\n\tval n = sc.nextInt()\n\tval k = sc.nextInt()\n\tval x = sc.nextInt()\n\tval a = Array(n) { sc.nextInt() }\n\ta.reverse()\n\tfor (i in 0 until k) a[i] = x\n\tprintln(a.sum())\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "e2b9b2efb500e41cfb5ba87af9a727b5", "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 r: Int = ir.nextInt()\n val c: Int = ir.nextInt()\n val n: Int = ir.nextInt()\n val k: Int = ir.nextInt()\n val x = IntArray(n)\n val y = IntArray(n)\n\n for (i in 0 until n) {\n x[i] = ir.nextInt()\n y[i] = ir.nextInt()\n }\n\n var answer = 0\n\n for (i in 1..r) {\n for (j in 1..c) {\n for (ii in i..r) {\n for (jj in j..c) {\n var count = 0\n for (l in 0 until n) {\n if (x[l] >= i && x[l] <= ii && y[l] >= j && y[l] <= jj) {\n count++\n }\n }\n if (count >= k) {\n answer++\n }\n }\n }\n }\n }\n pw.println(answer)\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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "639c6d5712c121213121137ccb708fa4", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n var (numMonth, dayMonthStarts) = readInts()\n dayMonthStarts--\n val daysPerMonth = listOf(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)\n val end = dayMonthStarts + daysPerMonth[numMonth]\n print(end / 7 + if (end % 7 == 0) 0 else 1)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "74e781f1f19b4c0957ac68b035555966", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun readInts(n: Int): IntArray {\n val line = readLine()!!\n val st = StringTokenizer(line)\n val result = IntArray(n)\n for (i in 0 until n) result[i] = st.nextToken().toInt()\n return result\n}\n\nfun computeNextsAndPos(a: IntArray): Pair {\n val n = a.size\n val pos = IntArray(n + 1) { n }\n val nexts = IntArray(n)\n for (i in a.indices.reversed()) {\n nexts[i] = pos[a[i]]\n pos[a[i]] = i\n }\n return nexts to pos\n}\n\nval t = IntArray(1 shl 20)\n\nfun main(args: Array) {\n val (n, k) = readLine()!!.split(' ').map(String::toInt)\n val a = readInts(n)\n\n val (nexts, pos) = computeNextsAndPos(a)\n\n val f = IntArray(k)\n val ft = IntArray(n + 1) { -1 }\n\n for (j in 0 until k) t[j] = n\n\n var ans = 0\n for (i in 0 until n) {\n pos[a[i]] = nexts[i]\n if (ft[a[i]] != -1) {\n t[ft[a[i]]] = nexts[i]\n continue\n }\n val r = (0 until k).maxBy { j -> t[j] }!!\n ft[f[r]] = -1\n f[r] = a[i]\n t[r] = pos[a[i]]\n ft[a[i]] = r\n ans++\n }\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "47b566b9afca3ae345aaf76ecafa80e3", "src_uid": "956228e31679caa9952b216e010f9773", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 f = IntArray(k)\n val last = IntArray(n + 1)\n for (i in 0 until n) {\n last[a[i]] = i\n }\n var ans = 0\n for (i in 0 until n) {\n if (a[i] in f) continue\n var r = -1\n for (j in 0 until k) {\n if (f[j] == 0 || last[f[j]] <= i) { r = j; break }\n }\n if (r == -1) {\n r = (0 until k).maxBy { j ->\n var w = i\n while (a[w] != f[j]) w++\n w\n }!!\n }\n f[r] = a[i]\n ans++\n }\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "51df388d589fb785f2f2c1b8bc160889", "src_uid": "956228e31679caa9952b216e010f9773", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 f = IntArray(k)\n var ans = 0\n for (i in 0 until n) {\n if (a[i] in f) continue\n val r = (0 until k).maxBy { j ->\n var w = i\n while (w < a.size && a[w] != f[j]) w++\n w\n }!!\n f[r] = a[i]\n ans++\n }\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "6edfca6729f993da93afe71b2881804a", "src_uid": "956228e31679caa9952b216e010f9773", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "add2cb563d601edbc0477494b1458826", "src_uid": "565bbd09f79eb7bfe2f2da46647af0f2", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (d, l, v1, v2) = readInts()\n print((l - d) / (v1 + v2).toDouble())\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "cb2dac1e1155ef06aa9c050042b0023f", "src_uid": "f34f3f974a21144b9f6e8615c41830f5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val t = readLine()!!.split(\" \").map(String::toInt)\n var x=0\n var i=0\n while(i=0 && t[j]==0) j--\n if (i<=j) x++\n while(i1) 1 else k+1\n }\n print(x)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "6fbf94e451700c428079292931ce5a0e", "src_uid": "2896aadda9e7a317d33315f91d1ca64d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n readLine()\n val pairs = readInts()\n var sol = 0\n var home = true\n for ((pos, pair) in pairs.withIndex())\n if (pair == 1) {\n home = false\n sol++\n } else {\n if (!home && pos != pairs.lastIndex && pairs[pos + 1] == 1)\n sol++\n else\n home = true\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "9f21931d08ba3fe51ac761a7f144e577", "src_uid": "2896aadda9e7a317d33315f91d1ca64d", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 var a: Int = reader.nextInt()\n var b: Int = reader.nextInt()\n var c: Int = reader.nextInt()\n var p =0\n for(i in 0..b){\n for(j in 0..c) {\n var cnt = n - i - 2 * j\n if (cnt >= 0 && 2 * cnt <= a) {\n p++\n }\n }\n }\n println(p)\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4467f9c9cf406164369aeca2cffca9e0", "src_uid": "474e527d41040446a18186596e8bdd83", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.math.BigDecimal\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val line = br.readLine()\n val b = BigDecimal(line)\n println(b.stripTrailingZeros().toPlainString())\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "strings", "implementation"], "code_uid": "93e18f7fc5ec6ff8b60e7b4cc2922bf3", "src_uid": "a79358099f08f3ec50c013d47d910eef", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "geometry"], "code_uid": "41108389b1b7b22c13757a3b644aff04", "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val numDays = readLine()!!.toInt()\n val temps = readLine()!!.split(\" \").map(String::toInt)\n val diff = temps[0] - temps[1]\n for (pos in 0 until numDays - 1)\n if (temps[pos] - temps[pos+ 1] != diff) return print(temps.last())\n print(temps.last() - diff)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "d9f0f0df3d0bfe45d5250a508fe74780", "src_uid": "d04fa4322a1b300bdf4a56f09681b17f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun readB() {\n val (n, k, m) = readLine()!!.split(\" \").map { it.toInt() }\n val times = readLine()!!.split(\" \").map { it.toInt() }\n val res = solveB(n, m, times)\n println(res)\n}\n\nfun solveB(n: Int, m: Int, timesRaw: List): Int {\n val times = timesRaw.sorted()\n val fullTaskTime = times.sum()\n val fullTaskScore = times.size + 1\n return (0..n).map { fullTasksCount ->\n val timeForFullTasks = fullTaskTime * fullTasksCount\n var timeLeft = m - timeForFullTasks\n var score = fullTasksCount * fullTaskScore\n if (timeLeft < 0) {\n 0\n } else {\n val tasksLeft = n - fullTasksCount\n var currentSubTask = 0\n outer@ while (currentSubTask < times.size) {\n var currentTask = 0\n while (currentTask < tasksLeft) {\n val timeSpent = times[currentSubTask]\n val scoreToAdd = if (currentSubTask == times.size - 1) 2 else 1\n if (timeSpent <= timeLeft) {\n score += scoreToAdd\n timeLeft -= timeSpent\n } else {\n break@outer\n }\n currentTask++\n }\n currentSubTask++\n }\n score\n }\n }.max()!!\n}\n\nfun main(args: Array) {\n readB()\n}\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy"], "code_uid": "1da1d1fc13d078a60fce05543b83a6f5", "src_uid": "d659e92a410c1bc836be64fc1c0db160", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.absoluteValue\nimport kotlin.math.max\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (x1, y1) = readInts()\n val (x2, y2) = readInts()\n print((max(2, (x1 - x2).absoluteValue + 1)) * 2 + max(2, ((y1 - y2).absoluteValue + 1)) * 2)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "e011de2cc1a95f1e4e856a8872ef59c8", "src_uid": "f54ce13fb92e51ebd5e82ffbdd1acbed", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n val results = LongArray(2)\n for (resultPos in 0..1) {\n val (_, base) = readLongs()\n val digits = readLongs()\n var multiplier = 1L\n for (digitPos in digits.lastIndex downTo 0) {\n results[resultPos] += digits[digitPos] * multiplier\n multiplier *= base\n }\n }\n print(\n when {\n results[0] < results[1] -> '<'\n results[0] == results[1] -> '='\n else -> '>'\n }\n )\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "c82f1a407a0c7959aca052c1de10b4f1", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import javax.print.attribute.IntegerSyntax\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()\n\n\nfun main() {\n var n = readInt()\n var list = readStr()!!\n for (i in list) {\n if (i == '7' || i == '4') {\n\n } else {\n println(\"NO\")\n return\n }\n }\n var sum = 0\n var sum2 = 0\n for (i in 0..n / 2 - 1) {\n sum += Integer.parseInt(list[i].toString())\n }\n for (i in n / 2..list.length - 1) {\n sum2 += Integer.parseInt(list[i].toString())\n }\n\n if (sum == sum2) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d727461c8d7bbbb9aeb9ba1d233de903", "src_uid": "435b6d48f99d90caab828049a2c9e2a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!.toInt()\n val s = readLine()!!\n for (c in s) if (c != '4' && c != '7') return print(\"NO\")\n print(if (s.substring(0, n / 2).count { it == '4' } == s.substring(n / 2, n).count { it == '4' }) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "fccd1bb6e1e387b587f6059ef33fc2c5", "src_uid": "435b6d48f99d90caab828049a2c9e2a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\n\nclass InputReader(stream: InputStream) {\n\n private var r = BufferedReader(InputStreamReader(stream), 32768)\n private var t = StringTokenizer(\"\")\n private fun next(): String {\n while (!t.hasMoreTokens()) t = StringTokenizer(r.readLine())\n return t.nextToken()\n }\n\n fun nextInt() = java.lang.Integer.parseInt(next())\n fun nextLong() = java.lang.Long.parseLong(next())\n fun nextDouble() = java.lang.Double.parseDouble(next())\n fun nextLine() = r.readLine()!!\n fun nextIntArray(n: Int): ArrayList {\n val v = ArrayList()\n for (i in 0 until n) v.add(nextInt())\n return v\n }\n}\n\nvar cin: InputReader = InputReader(System.`in`)\nvar cout: PrintWriter = PrintWriter(System.`out`)\n\nfun main() {\n solve()\n cout.close()\n}\n\nfun solve() {\n val k = cin.nextInt()\n val n = cin.nextLine().toCharArray()\n \n if (n.take(k / 2).sumBy { it.toInt() } == n.takeLast(k - k / 2).sumBy { it.toInt() }\n && n.all { it == '4' || it == '7' })\n print(\"YES\")\n else \n print(\"NO\")\n \n \n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "41ebe9a1f64c8005f2557443f267c67f", "src_uid": "435b6d48f99d90caab828049a2c9e2a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "9f6dc146bb6c4b4db7ba6e6ad2852c24", "src_uid": "bdf99d78dc291758fa09ec133fff1e9c", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val k = 2 * readLine()!!.toInt()\n val occs = mutableMapOf().withDefault { 0 }\n repeat(4) {\n for (c in readLine()!!)\n if (c != '.') occs[c] = occs.getValue(c) + 1\n }\n print(if(occs.isEmpty() || occs.values.max()!! <= k) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "e5c265a743b6ee097c4f3aa51bd81f5e", "src_uid": "5fdaf8ee7763cb5815f49c0c38398f16", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun main(args : Array) {\n //====== Input preparations ========================================================\n// val fin = BufferedReader(FileReader(\"c.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 nextLong() = next().toLong()\n fun nextPair() = nextInt() to nextInt()\n fun nextPairDec() = nextInt()-1 to nextInt()-1\n //====== Solution below ============================================================\n val (n,m) = nextPair()\n val k = nextLong()\n val (x,y) = nextPairDec()\n val p = (n-1) * m\n if (n == 1) {\n val d = k / m\n val rem = k % m\n val max = d + (if (rem > 0) 1 else 0)\n val min = d\n val cnt = d + if (rem > y) 1 else 0\n fout.print(\"$max $min $cnt\")\n } else {\n val d = k / p\n val rem = k % p\n val max = if (n == 2) (d/2 + if (d % 2 == 1L || rem > 0) 1 else 0) else d + (if (d == 0L || rem > m) 1 else 0)\n val min = d / 2 + (if (d % 2 == 1L && rem >= m) 1 else 0)\n val x1 = if (d % 2 == 0L) x else n - x - 1\n var cnt = if (x1 == 0) d/2 else if (x1 == n-1) (d+1)/2 else d\n// println(\"$x $y\")\n if (x1 * m + y + 1 <= rem)\n cnt++\n fout.print(\"$max $min $cnt\")\n }\n\n fout.close()\n fin.close()\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "binary search", "implementation"], "code_uid": "8e8221dbfea7d3c71cbff48598441418", "src_uid": "e61debcad37eaa9a6e21d7a2122b8b21", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 main() {\n var (n, t) = readInts()\n var a = Array>(n + 1){ arrayListOf() }\n for (i in 0..n){\n for (j in 0..i){\n a[i].add(0)\n }\n }\n\n repeat(t){\n a[0][0] += 512\n for (i in 0 until n){\n for (j in 0..i){\n var fall = max(a[i][j] - 512, 0)\n a[i + 1][j] += fall/2\n a[i + 1][j + 1] += fall/2\n a[i][j] = min(a[i][j], 512)\n }\n }\n }\n var ans = 0\n for (i in 0 until n){\n for (j in 0..i){\n ans += if (a[i][j] == 512) 1 else 0\n }\n }\n print(ans)\n //System.out.println(Arrays.deepToString(a))\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "3dd9bab9e31d2ab3b93eb6e1729ebe11", "src_uid": "b2b49b7f6e3279d435766085958fb69d", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.*\nimport kotlin.random.Random.Default.nextInt\nimport kotlin.system.exitProcess\n\nconst val B = 31\nconst val MOD = 1000000007\n\nfun readInt(): Int {\n var digit = System.`in`.read()\n while(digit <= 32) {\n digit = System.`in`.read()\n }\n\n val negative = digit == '-'.toInt()\n if (negative) {\n digit = System.`in`.read()\n }\n var res = 0\n while (digit in '0'.toInt()..'9'.toInt()) {\n res *= 10\n res += digit - '0'.toInt()\n digit = System.`in`.read()\n }\n return if (negative) -res else res\n}\n\nfun main() {\n val k = readLine()!!.toInt()\n\n val dp = Array(B) { Array(B) { Array(2) { 0L } } }\n\n dp[B - 1][0][1] = 1\n for(i in B - 1 downTo 1) {\n for(j in 0 until B) {\n for(p in 0..1) {\n if(dp[i][j][p] == 0L) continue\n\n// println(\"$i $j $p ${dp[i][j][p]}\")\n\n if(p == 0 || ((k shr (i - 1)) and 1) == 1) {\n// println(\"$i $j $p\")\n dp[i - 1][j + 1][p] = (dp[i - 1][j + 1][p] + dp[i][j][p]) % MOD\n }\n\n if(p == 0) {\n dp[i - 1][j][0] = (dp[i - 1][j][0] + dp[i][j][p] * (1 shl j)) % MOD\n } else if(j == 0) {\n val newp = if(((k shr (i - 1)) and 1) == 1) 0 else 1\n dp[i - 1][j][newp] = (dp[i - 1][j][newp] + dp[i][j][p]) % MOD\n } else if(((k shr (i - 1)) and 1) == 1) {\n dp[i - 1][j][0] = (dp[i - 1][j][0] + dp[i][j][p] * (1 shl (j - 1))) % MOD\n dp[i - 1][j][1] = (dp[i - 1][j][1] + dp[i][j][p] * (1 shl (j - 1))) % MOD\n } else {\n dp[i - 1][j][1] = (dp[i - 1][j][1] + dp[i][j][p] * (1 shl (j - 1))) % MOD\n }\n }\n }\n }\n\n var ans = 0L\n for(j in 0 until B) {\n for(p in 0..1) {\n ans = (ans + dp[0][j][p]) % MOD\n }\n }\n\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "ce5d4d341e1eb5762f19faa1c303997d", "src_uid": "ead64d8e3134fa8f29881cb487e52f60", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["combinatorics"], "code_uid": "79a45eff250d4b9d5608d10b81975030", "src_uid": "58242665476f1c4fa723848ff0ecda98", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Math.*\nimport java.util.*\n\nprivate fun readInt() = readLine()!!.toInt()\nprivate fun readLong() = readLine()!!.toLong()\nprivate fun readInts() = readLine()!!.split(\" \").map(String::toInt)\nprivate fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n\nfun matmul(matA: Array, matB: Array, mod: Long): Array {\n val (x, y, z) = Triple(matA.size, matB[0].size, matA[0].size)\n val res = Array(x) { LongArray(y) }\n\n for (i in 0 until x) for (j in 0 until y) for (k in 0 until z) {\n res[i][j] = (res[i][j] + matA[i][k] * matB[k][j]) % mod\n }\n\n return res\n}\n\nfun main(args: Array) {\n var (n, m) = readLongs()\n val mod: Long = 1000000007\n var matA = Array(m.toInt()) { LongArray(m.toInt()) }\n var matB = Array(m.toInt()) { LongArray(1) }\n\n for (i in 1 until m.toInt()) matA[i-1][i] = 1\n matA[0][0] = 1\n matA.last()[0] = 1\n matB[0][0] = 1\n\n while (n > 0) {\n if (n.and(1) == 1L) {\n matB = matmul(matA, matB, mod)\n }\n matA = matmul(matA, matA, mod)\n n = n.shr(1)\n }\n\n println(matB[0][0])\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "matrices", "dp"], "code_uid": "a6e887121e6955fd4c33b50902295c95", "src_uid": "e7b9eec21d950f5d963ff50619c6f119", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 numChildren = readInt()\n val (min1, max1) = readInts()\n val (min2, max2) = readInts()\n val (min3, _) = readInts()\n var extras = numChildren - min1 - min2 - min3\n val sol1 = min(max1, min1 + extras)\n extras = numChildren - sol1 - min2 - min3\n val sol2 = min(max2, min2 + extras)\n print(\"$sol1 $sol2 ${numChildren - sol1 - sol2}\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "bb19beb068b0f3011ccbb6d98feaeaa7", "src_uid": "3cd092b6507079518cf206deab21cf97", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\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 var n = ir.nextInt()\n val res = IntArray(3)\n val max = IntArray(3)\n\n for (i in 0..2) {\n res[i] = ir.nextInt()\n n -= res[i]\n max[i] = ir.nextInt()\n }\n\n for (i in 0..2) {\n val g = max[i] - res[i]\n if (g < n) {\n n -= g\n res[i] = max[i]\n } else {\n res[i] += n\n break\n }\n }\n\n for (i in 0..2)\n pw.print(\"${res[i]} \")\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}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "8583879525610bd11a570084461e8eb6", "src_uid": "3cd092b6507079518cf206deab21cf97", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.lang.Math.abs\nimport java.util.*\n\nfun main() {\n val tokenizer = BufferedReader(InputStreamReader(System.`in`)).use { StringTokenizer(it.readText()) }\n val n = tokenizer.nextLong()\n val k = tokenizer.nextLong()\n val a = tokenizer.nextLong()\n val b = tokenizer.nextLong()\n val possible = listOf(b, k - b)\n .flatMap { c -> 0.until(n).map { abs(it * k + c - a) } }\n .map { n * k / gcd(n * k, it) }\n print(possible.min())\n print(' ')\n println(possible.max())\n}\n\nfun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\n\nfun StringTokenizer.nextInt() = nextToken().toInt()\nfun StringTokenizer.nextLong() = nextToken().toLong()\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "0c65004d8119026e4310eac5b8c7ffc2", "src_uid": "5bb4adff1b332f43144047955eefba0c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextLong()\n val k = scanner.nextLong()\n val a = scanner.nextLong()\n val b = scanner.nextLong()\n\n tailrec fun gcd(i: Long, j: Long): Long =\n if (i % j == 0L) j\n else gcd(j, i % j)\n\n val m = n * k\n var min = m\n var max = 1L\n\n outer@ for (i in arrayOf(a + b, a - b, -a + b, -a - b)) {\n for (j in 0L..n) {\n val s = j * k + i\n if (s in 1..m) {\n val g = gcd(m, s)\n val c = m / g\n min = min(min, c)\n max = max(max, c)\n if (min == 1L && max == m) break@outer\n }\n }\n }\n\n println(\"$min $max\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "55a74618fca58a728f47817b35f9d553", "src_uid": "5bb4adff1b332f43144047955eefba0c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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.*\nval arr = IntArray(10)\nvar s = 0\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n val n = scanner.next()\n for (i in n)\n arr[i - '0']++\n s = 0\n println(dfs(0))\n\n}\n\nfun dfs(v: Int): Long {\n if (v == 10)\n return get()\n if (arr[v] == 0)\n return dfs(v + 1)\n var res = 0L\n val q = arr[v]\n for (i in 1..q) {\n arr[v] = i\n s += i\n res += dfs(v + 1)\n s -= i\n }\n return res\n}\n\nfun get(): Long {\n var res = 1L\n for (i in 2 until s)\n res *= i\n res *= s - arr[0]\n for (i in 0 until 10)\n for (j in 2..arr[i])\n res /= j\n return res\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//}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "combinatorics"], "code_uid": "f5733186c48ca35d6ea32c54bb57b703", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "// 2022.06.28 at 23:59:56 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 = 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\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\nfun debug(){}\r\nconst val singleCase = true\r\nfun main(){\r\n solve.cases{\r\n var s = getstr\r\n if(s.all { it == '0' }) {\r\n put(-1)\r\n return@cases\r\n }\r\n var start = 0\r\n while(s.first() == '0'){\r\n start++\r\n s= s.drop(1)\r\n }\r\n while(s.last() == '0'){\r\n s = s.dropLast(1)\r\n }\r\n val n = s.size\r\n if(n ==1){\r\n put(\"${1 + start} ${2 + start}\")\r\n return@cases\r\n }\r\n var forwardmask = 0L\r\n for(i in 1 until n){\r\n if(s[i] == '1'){\r\n forwardmask = forwardmask xor ( 1L shl (i-1))\r\n }\r\n }\r\n fun next(x:Long):Long {\r\n var new = x shr 1\r\n if(x and 1L == 1L){\r\n new = new xor forwardmask\r\n }\r\n return new\r\n }\r\n fun previous(x:Long):Long{\r\n var new:Long\r\n if(x and (1L shl (n-2)) != 0L){\r\n new = (((x xor forwardmask) shl 1) and ((1L shl (n-1)) - 1 )) or 1L\r\n }else{\r\n new = (x shl 1) and ((1L shl (n-1)) - 1 )\r\n }\r\n return new\r\n }\r\n fun Long.binary():String{\r\n val ret = CharArray(n-1){if((this and (1L shl it)) != 0L)'1' else '0' }\r\n return ret.conca\r\n }\r\n fun getinverse(k:Int):LongArray{\r\n var now = 1L\r\n val last = mong\r\n last.add(now)\r\n repeat(k + (n-2)){\r\n last.add(previous(last.last()))\r\n }\r\n return last.takeLast(n-1).toLongArray()\r\n }\r\n fun calculate(M:LongArray,start:Long):Long{\r\n var ret = 0L\r\n for(i in 0 until n-1){\r\n if(start.has(i)){\r\n ret = ret xor M[i]\r\n }\r\n }\r\n return ret\r\n }\r\n\r\n fun solve():Long{\r\n val cut = 1 shl 18\r\n val new = LongArray(cut)\r\n new[0]= 1L\r\n for(i in 1 until cut){\r\n new[i] = next(new[i-1])\r\n if(new[i] == 1L){\r\n return i.toLong()\r\n }\r\n }\r\n val invert1 = getinverse(cut)\r\n val map = mutableMapOf()\r\n for((i,v) in new.withIndex()){\r\n map[v] = i\r\n }\r\n var now = 1L\r\n var res = 0L\r\n repeat(1 shl 18){\r\n now = calculate(invert1,now)\r\n res += cut\r\n if(map[now] != null){\r\n return map[now]!! + res\r\n }\r\n }\r\n crash()\r\n return 0L\r\n }\r\n val ans = solve()\r\n put(start+ 1)\r\n put(start + 1 + ans)\r\n// just dei now.binary()\r\n// repeat(100){it ->\r\n// val new = next(now)\r\n// val old = previous(new)\r\n// assert(old == now)\r\n// now = new\r\n//\r\n// val M = getinverse(it + 1 )\r\n// assert(calculate(M,new) == 1L )\r\n//\r\n// just dei now.binary()\r\n// }\r\n\r\n\r\n\r\n\r\n\r\n\r\n }\r\n done()\r\n}\r\n/*\r\n1011\r\n100111\r\n1000101\r\n10000001\r\n\r\n */\r\n\r\n\r\n", "lang_cluster": "Kotlin", "tags": ["math", "bitmasks", "meet-in-the-middle", "matrices", "number theory"], "code_uid": "22afc3f1592404f7fbd02809135fcc5b", "src_uid": "6bf798edef30db7d0ce2130e40084e6b", "difficulty": 2900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.InputStream\nimport java.util.*\nimport kotlin.math.min\n\nconst val CODE_0 = '0'.toByte()\nconst val CODE_1 = '9'.toByte()\n\nvar s: String = \"\"\nvar n: Int = 0\nval dp = Array(500) { IntArray(500) }\n\nclass Main {\n companion object {\n @JvmStatic\n private fun ans(l: Int, r: Int): Int {\n dp[l][r] = when {\n dp[l][r] > 0 -> dp[l][r]\n l == r -> 1\n l > r -> 0\n else -> ((l + 1)..r).fold(1 + ans(l + 1, r)) { acc, i ->\n if (s[i] != s[l]) acc else min(acc, ans(l + 1, i - 1) + ans(i, r))\n }\n }\n return dp[l][r]\n }\n\n @JvmStatic\n fun main(args: Array) = with(Scanner(System.`in`)) {\n n = nextInt()\n s = next()\n println(ans(0, n - 1))\n }\n }\n\n\n // -----------------------------------------------------------------------------------------------------------------\n\n private class FastScanner(private val iss: InputStream = System.`in`) {\n fun nextInt(): Int {\n var v = 0\n var begin = false\n while (true) {\n val c = iss.read()\n if (c in CODE_0..CODE_1) {\n begin = true\n v *= 10\n v += c - CODE_0\n } else if (begin) {\n return v\n }\n }\n }\n }\n}\n\nfun main(args: Array) = Main.main(args)", "lang_cluster": "Kotlin", "tags": ["dp"], "code_uid": "641606e04687c619ce642b7cec5ef25b", "src_uid": "516a89f4d1ae867fc1151becd92471e6", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import 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 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 nb = 0\nvar ns = 0\nvar nc = 0\nvar pb = 0\nvar ps = 0\nvar pc = 0\nvar r = 0L\nvar cb = 0\nvar cs = 0\nvar cc = 0\n\nprivate fun f(x: Long):\n Long {\n return Math.max(0, (x * cb - nb) * pb) + Math.max(0, (x * cs - ns) * ps) +\n Math.max(0, (x * cc - nc) * pc)\n}\n\nprivate fun solve() {\n var recipe = readLn()\n val (nb_, ns_, nc_) = readInts()\n nb = nb_\n ns = ns_\n nc = nc_\n val (pb_, ps_, pc_) = readInts()\n pb = pb_\n ps = ps_\n pc = pc_\n r = readLong()\n\n for (c in recipe) {\n when (c) {\n 'B' -> {\n cb++\n }\n 'S' -> {\n cs++\n }\n else -> {\n cc++\n }\n }\n }\n\n var x = 0L\n var jump: Long = 100000000000000L // 1e14\n while (jump >= 1) {\n while (f(x + jump) <= r) {\n x += jump\n }\n jump /= 2\n }\n\n println(x)\n}\n\nfun main() {\n var t = 1;\n // t = readInt();\n for (i in 1..t) {\n solve();\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "binary search"], "code_uid": "85dfc0b0a13f067ae074794af4869e29", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "580527a651199f169ff5265e046a34e1", "src_uid": "be6d4df20e9a48d183dd8f34531df246", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "02e11b54127554e164e381f92e314bbd", "src_uid": "5482ed8ad02ac32d28c3888299bf3658", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n val (n, x, y) = readLine()!!.split(\" \").map { it.toLong() }\n fun minChanges(z: Long): Int {\n var z = z\n var res = 0\n while (z > 0L) {\n if (z and 1L == 1L) {\n if (z and 3L == 3L) {\n z++\n } else {\n z--\n }\n res++\n }\n z = z shr 1\n }\n return res\n }\n var answer = Long.MAX_VALUE\n for (e in 0..29) {\n answer = min(answer, (e.toLong() * y) + (((n shr e) + minChanges(n % (1L shl e))) * x))\n }\n println(answer)\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "dp"], "code_uid": "728b886534f35d2094f5fecc83914eb3", "src_uid": "0f270af00be2a523515d5e7bd66800f6", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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\nimport kotlin.math.min\nimport kotlin.math.sqrt\n\nfun main(args : Array) {\n Thread { run() }.start()\n}\n\n\nfun run() {\n val scanner = Scanner(System.`in`)\n val a = scanner.nextInt()\n val b = scanner.nextInt()\n val c = scanner.nextInt()\n val res = (a / 3) + (b / 3) + (c / 3) + min(min(a % 3, b % 3), c % 3) + if ((a % 3) * (a % 3) + (b % 3) * (b % 3) + (c % 3) * (c % 3) == 8 && a > 2 && b > 2 && c > 2) 1 else 0\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}\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}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "707d7e53fae46d4b5f9aa76a6d3ad094", "src_uid": "acddc9b0db312b363910a84bd4f14d8e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n/**\n * Created by Hamza on 07/11/2017.\n */\nfun main(args: Array) {\n var sc = Scanner(System.`in`)\n\n var r = sc.nextInt()\n var g = sc.nextInt()\n var b = sc.nextInt()\n// var min = 0\n// if (r <=g && r<=b ){\n// min = r\n// }else if (g<=r && g<=b){\n// min = g\n// }else min = b\n\n// var result = min + (r-min )/ 3 + (g-min )/3+(b-min)/3\n\n var reste_1 = if (r - 1 >= 0 && (b - 1) >= 0 && (g - 1) >= 0) (r - 1) / 3 + (g - 1) / 3 + (b - 1) / 3 + 1 else 0\n var reste_2 = if (r - 2 >= 0 && (b - 2) >= 0 && (g - 2) >= 0) (r - 2) / 3 + (g - 2) / 3 + (b - 2) / 3 + 2 else 0\n var result = Math.max(Math.max(r / 3 + g / 3 + b / 3, reste_2), reste_1)\n println(\"${result}\")\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "63de660e4869c709bc2c8cfd24358be2", "src_uid": "acddc9b0db312b363910a84bd4f14d8e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n readLine()\n val horizontals = readLine()!!\n val verticals = readLine()!!\n if (horizontals.first() == '>' &&\n verticals.last() == 'v' &&\n horizontals.last() == '<'\n && verticals.first() == '^'\n )\n return print(\"YES\")\n if (horizontals.first() == '<' &&\n verticals.last() == '^' &&\n horizontals.last() == '>'\n && verticals.first() == 'v'\n )\n return print(\"YES\")\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "implementation", "graphs", "brute force"], "code_uid": "f6d97e7283bc1ee963d8b2fd57f47fdf", "src_uid": "eab5c84c9658eb32f5614cd2497541cf", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner;\n\nfun main(args: Array) {\n var scan = Scanner(System.`in`);\n\n var n = scan.nextInt();\n var s = IntArray(n);\n for (i in 0 until n) {\n s[i] = scan.nextInt();\n }\n\n var other = IntArray(n);\n var best = IntArray(n);\n best[n-1] = s[n-1];\n other[n-1] = 0;\n for (i in (n-2) downTo 0) {\n var takethis = s[i] + other[i+1];\n var givethis = best[i+1];\n if (takethis > givethis) {\n best[i] = takethis;\n other[i] = givethis;\n } else {\n best[i] = givethis;\n other[i] = takethis;\n }\n }\n System.out.printf(\"%d %d\\n\", other[0], best[0]);\n}", "lang_cluster": "Kotlin", "tags": ["dp", "games"], "code_uid": "7234a648afa9b68589ad8e6a8b3353f3", "src_uid": "414540223db9d4cfcec6a973179a0216", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "games"], "code_uid": "7565e5fdfec67caaada4509356ebe375", "src_uid": "90b9ef939a13cf29715bc5bce26c9896", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n val n = readLine()!!.toInt()\n var sol = 0\n for (a in 1..n)\n for (b in a..n) {\n val cCandidate = a xor b\n if (cCandidate in b..min(n, a + b - 1)) sol++\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "89a7f602679b7f1ee5da293f939cf12c", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n val n = readLine()!!.toInt()\n var sol = 0\n for (a in 1..n)\n for (b in a..n) {\n val cCandidate = a xor b xor 0\n if (cCandidate in b..min(n, a + b - 1)) sol++\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "96cb698e0e42fd6c32d2007dcfb8bd50", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "dp", "greedy", "number theory"], "code_uid": "ba728e41461e396b09253fb2d667904e", "src_uid": "c9d45dac4a22f8f452d98d05eca2e79b", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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_007\n\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n\n private val D = nl()\n private val K = nl()\n private val A = nl()\n private val B = nl()\n private val T = nl()\n\n private inline fun calc(x: Long) = run {\n val y = D - x\n val repairs = if (x > K) ((x - K) + K - 1) / K else 0\n A * x + B * y + repairs * T\n }\n\n private val INF = 3e18.toLong() + 100\n\n fun solve() {\n var ans = INF\n if (D <= 10_000_000) {\n for (x in 0 .. D) {\n ans = min(ans, calc(x))\n }\n } else {\n for (x in 0L .. 5_000_000) {\n ans = min(ans, calc(x))\n }\n for (x in D - 5_000_000 .. D) {\n ans = min(ans, calc(x))\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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\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 IntArray(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 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 { toString(a) }\n }\n\n private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString(\"\")}\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 private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "528599f1f726d12bfffd459ded42f104", "src_uid": "359ddf1f1aed9b3256836e5856fe3466", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "060d0064fd5157b7c1919a4a3a375bca", "src_uid": "6f6fc42a367cdce60d76fd1914e73f0c", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n\n val k = sc.nextInt()\n val a = sc.nextInt()\n val b = sc.nextInt()\n var result = a/k + b/k\n println(if (result==0 || (a 0) {\n dpNext[j] -= dpPrev[j - k - 1]\n }\n dpNext[j] %= MOD\n }\n val temp = dpPrev\n dpPrev = dpNext\n dpNext = temp\n }\n var answer = 0L\n for (j in n + 1..2 * n) {\n answer += dpPrev[j]\n answer %= MOD\n }\n answer += MOD\n answer %= MOD\n println(answer)\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "eaa8d21201872a324d93d503cf96f65e", "src_uid": "8b8327512a318a5b5afd531ff7223bd0", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(){\n val r = readLine()!!.toLong()\n\n var x = 1L\n while (true){\n val y = (r-x*x-x-1)\n if (y<=0){\n println(\"NO\")\n break\n }\n if (y%(2*x)==0L){\n println(\"$x ${y/(2*x)}\")\n break\n }\n\n x++\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "2aeed1739521556a5f1d79900c7ec3d1", "src_uid": "3ff1c25a1026c90aeb14d148d7fb96ba", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = readLong()\n\n val ans = run {\n if(r % 2 == 0L) return@run \"NO\"\n val y = (r - 3) / 2\n if(y <= 0) \"NO\" else \"1 $y\"\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 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", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "e9b0541ab888309dc5fb8265f73487a0", "src_uid": "3ff1c25a1026c90aeb14d148d7fb96ba", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "bitmasks"], "code_uid": "731ea3656952148713ca529941d4cd80", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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}", "lang_cluster": "Kotlin", "tags": ["brute force", "bitmasks"], "code_uid": "12532a68df34a1625d25a0ff24f37270", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "5547c2b084694c1a68f7be8942251d5d", "src_uid": "1366732dddecba26db232d6ca8f35fdc", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val (n, k) = br.readLine().split(\" \").map { it.toLong() }\n val maxBound = k*(k - 1)/ 2 + 1\n if (maxBound < n) {\n println(-1)\n } else if (n == 1L) {\n println(0)\n } else {\n var l = 1L\n var r = k\n while (l < r) {\n val m = (l + r)/2\n val x = (m*(2*k - m - 1))/2 + 1\n if (x >= n) {\n r = m\n } else {\n l = m + 1\n }\n }\n println(l)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "binary search"], "code_uid": "47c6405c918938967f42b45e4690d3e5", "src_uid": "83bcfe32db302fbae18e8a95d89cf411", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.min\n\nfun getMinRest (a: List): Int {\n val inf = 100000\n tailrec fun go (xs: Queue, rest: Int, contest: Int, gym: Int): Int =\n if (xs.isEmpty()) min(rest, min(contest, gym))\n else {\n val newRest = min(rest, min(contest, gym)) + 1\n when (xs.poll()) {\n '0' -> go(xs, newRest, inf, inf)\n '1' -> go(xs, newRest, min(rest, gym), inf)\n '2' -> go(xs, newRest, inf, min(rest, contest))\n else -> go(xs, newRest, min(rest, gym), min(rest, contest))\n }\n }\n return go(LinkedList(a),0, inf, inf)\n}\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val n = br.readLine().toInt()\n val a = br.readLine().split(\" \").map { it.single() }\n println(getMinRest(a))\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "dp"], "code_uid": "987e807229763e59c21b99af09a21202", "src_uid": "08f1ba79ced688958695a7cfcfdda035", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (a, m) = readInts()\n var x = a\n val visited = mutableSetOf()\n while (x % m != 0) {\n if (x % m in visited) return print(\"No\")\n visited.add(x % m)\n x += x % m\n }\n print(\"Yes\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "matrices", "implementation"], "code_uid": "b572d762fabc8e581c19227dd22579b4", "src_uid": "f726133018e2149ec57e113860ec498a", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.SortedMap\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\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n val n = readInt()\n val K = readIntArray(n).toCollection(HashBag())\n val maxk = K.elements.max()!!\n\n val primes = IntList()\n val F = List(maxk + 1) { TreeBag() }\n\n factorize@ for(i in 2 .. maxk) {\n for(p in primes) {\n if(p * p > i) break\n if(i % p == 0) {\n F[i].addAll(F[i / p])\n F[i].add(p)\n continue@factorize\n }\n }\n primes.add(i)\n F[i].add(i)\n }\n\n for(i in 3 .. maxk) F[i].addAll(F[i-1])\n\n var ans = K.sumByLong { F[it].size.toLong() }\n var curr = K\n loop@ while(true) {\n val tails = HashMap>()\n for((i, num) in curr.entries) {\n F[i].pollLast()?.also { f -> tails.getOrPut(f) { HashBag() }.add(i, num) }\n }\n for((_, bag) in tails.entries) {\n val num = bag.size\n if(num > n/2) {\n ans -= num - (n - num)\n curr = bag\n continue@loop\n }\n }\n break\n }\n\n println(ans)\n}\n\nfun TreeBag.pollLast() = if(isEmpty()) null else last().also { remove(it) }\n\ninline fun Bag.sumByLong(func: (T) -> Long) = entries.fold(0L) { acc, (k, v) ->\n acc + func(k) * v\n}\n\ninterface Bag : Collection {\n val countMap: Map\n\n fun getCount(element: T): Int = countMap[element] ?: 0\n val elements: Set get() = countMap.keys\n val entries: Set> get() = countMap.entries\n\n override fun iterator(): Iterator = sequence {\n for((e, cnt) in countMap) {\n repeat(cnt) { yield(e) }\n }\n }.iterator()\n\n override fun contains(element: T): Boolean = countMap.containsKey(element)\n}\n\nprivate fun Bag<*>._size() = countMap.values.sum()\nprivate fun Bag<*>._equals(other: Any?) = when {\n this === other -> true\n other is Bag<*> -> countMap == other.countMap\n else -> false\n}\nprivate fun Bag<*>._hashCode() = countMap.hashCode()\n\nclass BagImpl(override val countMap: Map): Bag, AbstractCollection() {\n override val size = _size()\n override fun equals(other: Any?) = _equals(other)\n override fun hashCode() = _hashCode()\n override fun contains(element: T) = super.contains(element)\n override fun iterator() = super.iterator()\n}\nfun Bag(countMap: Map): Bag = BagImpl(countMap)\n\ninterface MutableBag : Bag, MutableCollection {\n val _countMap: MutableMap\n var _size: Int\n\n override fun add(element: T): Boolean { add(element, 1); return true }\n fun add(element: T, occurrences: Int): Int {\n require(occurrences >= 0)\n val oldCount = getCount(element)\n _countMap[element] = oldCount + occurrences\n _size += occurrences\n return oldCount\n }\n\n override fun remove(element: T): Boolean = remove(element, 1) > 0\n fun remove(element: T, occurrences: Int): Int {\n require(occurrences >= 0)\n val oldCount = getCount(element)\n val m = minOf(occurrences, oldCount)\n when(oldCount) {\n 0 -> return 0\n m -> _countMap.remove(element)\n else -> _countMap[element] = oldCount - m\n }\n _size -= m\n return oldCount\n }\n\n fun setCount(element: T, occurrences: Int): Int {\n require(occurrences >= 0)\n val oldCount = getCount(element)\n if(occurrences == 0) _countMap.remove(element)\n else _countMap[element] = occurrences\n _size += occurrences - oldCount\n return oldCount\n }\n\n override fun iterator(): MutableIterator = object: MutableIterator {\n private val mapIterator = _countMap.iterator()\n private var rem = 0\n private lateinit var lastEntry: MutableMap.MutableEntry\n private var removed = true\n override fun hasNext() = rem > 0 || mapIterator.hasNext()\n override fun next(): T {\n if(rem == 0) {\n lastEntry = mapIterator.next()\n rem = lastEntry.value\n }\n rem--\n removed = false\n return lastEntry.key\n }\n override fun remove() {\n if(removed) error(\"\")\n lastEntry.setValue(lastEntry.value - 1)\n if(lastEntry.value == 0) mapIterator.remove()\n _size--\n removed = true\n }\n }\n}\n\nabstract class AbstractMutableBag: MutableBag, AbstractMutableCollection() {\n final override val countMap: Map get() = _countMap\n final override val size get() = _size\n override fun equals(other: Any?) = _equals(other)\n override fun hashCode() = _hashCode()\n override fun contains(element: T) = super.contains(element)\n override fun iterator() = super.iterator()\n override fun add(element: T): Boolean = super.add(element)\n override fun addAll(elements: Collection): Boolean =\n if(elements is Bag) {\n for((e, n) in elements.countMap) add(e, n)\n true\n } else super.addAll(elements)\n override fun remove(element: T): Boolean = super.remove(element)\n override fun removeAll(elements: Collection): Boolean =\n if(elements is Bag) {\n var modified = false\n for((e, n) in elements.countMap) if(remove(e, n) > 0) modified = true\n modified\n } else super.removeAll(elements)\n}\n\ninterface SortedBag: MutableBag {\n override val _countMap: SortedMap\n\n fun first(): T = _countMap.firstKey()\n fun last(): T = _countMap.lastKey()\n}\n\nclass SortedBagImpl(override val _countMap: SortedMap): SortedBag, AbstractMutableBag() {\n override var _size = _size()\n}\nfun SortedBag(countMap: SortedMap): SortedBag = SortedBagImpl(countMap)\n\nclass TreeBag(override val _countMap: TreeMap): SortedBag, AbstractMutableBag() {\n constructor(): this(TreeMap())\n constructor(comparator: Comparator?): this(TreeMap(comparator))\n\n override var _size = _size()\n\n fun floor(element: T): T? = _countMap.floorKey(element)\n fun ceiling(element: T): T? = _countMap.ceilingKey(element)\n fun lower(element: T): T? = _countMap.lowerKey(element)\n fun higher(element: T): T? = _countMap.higherKey(element)\n}\n\nclass HashBag(override val _countMap: HashMap): AbstractMutableBag() {\n constructor(): this(HashMap())\n\n override var _size = _size()\n}\n\nclass IntList(initialCapacity: Int = 12) {\n private var _arr = IntArray(initialCapacity)\n private val capacity get() = _arr.size\n var size = 0\n private set\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n\n private fun grow(minCapacity: Int = 8) {\n val newCapacity = maxOf(minCapacity, capacity + (capacity shr 1))\n _arr = _arr.copyOf(newCapacity)\n }\n\n fun ensureCapacity(minCapacity: Int) { if(capacity < minCapacity) grow(minCapacity) }\n\n operator fun get(index: Int): Int {\n require(index in 0 until size)\n return _arr[index]\n }\n\n operator fun set(index: Int, value: Int) {\n require(index in 0 until size)\n _arr[index] = value\n }\n\n fun add(value: Int) {\n if(size == capacity) grow()\n _arr[size++] = value\n }\n\n fun clear() { size = 0 }\n\n operator fun iterator() = object: IntIterator() {\n private var pos = 0\n override fun hasNext() = pos < size\n override fun nextInt() = get(pos++)\n }\n\n fun isEmpty() = size == 0\n fun isNotEmpty() = size != 0\n\n fun pop() = _arr[--size]\n\n fun swap(i: Int, j: Int) { this[i] = this[j].also { this[j] = this[i]} }\n fun reverse() {\n for(i in 0 until size / 2) swap(i, lastIndex - i)\n }\n\n fun shuffle(rnd: Random = random) = _shuffle(rnd, _arr::get, _arr::set, size)\n fun sort() { shuffle(); _arr._sort(0, size) }\n fun sortDescending() { sort(); reverse() }\n\n fun joinToString(separator: String) = if(size == 0) \"\" else let {\n buildString {\n append(it[0])\n for (i in 1 until size) {\n append(separator).append(it[i])\n }\n }\n }\n\n override fun toString() = \"[\" + joinToString(\", \") + \"]\"\n}\n\ninline fun IntList(size: Int, init: (Int) -> Int) = IntList(size).apply {\n for(i in 0 until size) { add(init(i)) }\n}\n\nfun IntList.max() = (1 until size).fold(this[0]) { acc, i -> max(acc, this[i]) }\nfun IntList.min() = (1 until size).fold(this[0]) { acc, i -> min(acc, this[i]) }\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()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}", "lang_cluster": "Kotlin", "tags": ["math", "trees", "dp", "graphs", "number theory"], "code_uid": "3c0d21431419c4ad063f4b84f5072460", "src_uid": "40002052843ca0357dbd3158b16d59f4", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 val arr = Array(5) { IntArray(5) }\n for (i in 1..3) {\n val s = readInts()\n for (j in 1..3) {\n arr[i][j] = s[j - 1]\n }\n }\n for (i in 1..3) {\n for (j in 1..3) {\n val sum = arr[i][j] + arr[i - 1][j] + arr[i + 1][j] + arr[i][j - 1] + arr[i][j + 1]\n print(if (sum % 2 == 0) 1 else 0)\n }\n println()\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "b9cfbd9b7039ec453f626c1c86911849", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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_007\n\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n\n private val N = ni()\n fun solve() {\n for (t in 0 until N) {\n val s = ns().drop(4)\n var lst = 1988L\n var digit = 1L\n var right = 0L\n for (d in s.reversed()) {\n right += (d-'0') * digit\n\n var left = lst/(digit*10)\n\n while(left * (digit*10) + right <= lst) {\n left++\n }\n\n debug{\"$left $right\"}\n\n lst = left * (digit*10) + right\n\n debug{\"$lst\"}\n\n digit *= 10\n left /= 10\n }\n out.println(lst)\n }\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\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 { toString(a) }\n }\n\n private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString(\"\")}\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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\n// val out = java.io.PrintWriter(System.out)\n// val fin = java.io.FileInputStream(java.io.File(\"in.txt\"))\n// Solver(fin, out).solve()\n// out.flush()\n// fin.close()\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms", "implementation"], "code_uid": "f5b333472ec9d4f1f3d7d1ea1162e38a", "src_uid": "31be4d38a8b5ea8738a65bfee24a5a21", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nclass InputReader(val stream: InputStream) {\n val buf = ByteArray(1024)\n var curChar: Int = 0\n var numChars: Int = 0\n\n fun read(): Char {\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 if (numChars <= 0)\n return '\\uFFFF'\n }\n return buf[curChar++].toChar()\n }\n\n fun nextInt(): Int {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n var sgn = 1\n if (c == '-') {\n sgn = -1\n c = read()\n }\n var res = 0\n do {\n if (c < '0' || c > '9')\n throw InputMismatchException()\n res *= 10\n res += c.toInt() and 15\n c = read()\n } while (!isSpaceChar(c))\n return res * sgn\n }\n\n fun nextLong(): Long {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n var sgn = 1\n if (c == '-') {\n sgn = -1\n c = read()\n }\n var res = 0L\n do {\n if (c < '0' || c > '9')\n throw InputMismatchException()\n res *= 10\n res += c.toInt() and 15\n c = read()\n } while (!isSpaceChar(c))\n return res * sgn\n }\n\n fun nextString(): String {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n val res = StringBuilder()\n do {\n res.append(c)\n c = read()\n } while (!isSpaceChar(c))\n return res.toString()\n }\n\n fun isSpaceChar(c: Char): Boolean {\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t' || c == '\\uFFFF'\n }\n}\n\nclass OutputWriter(val stream: OutputStream) {\n val buf = ByteArray(65536)\n var curPos: Int = 0\n\n fun write(c: Char) {\n if (buf.size - curPos < 1) flush()\n buf[curPos++] = c.toByte()\n }\n\n fun write(s: String) {\n if (buf.size - curPos < s.length) flush()\n var idx = 0\n if (s.length > buf.size) {\n var remaining = s.length\n while (remaining > buf.size) {\n while (curPos < buf.size) buf[curPos++] = s[idx++].toByte()\n flush()\n remaining -= buf.size\n }\n }\n while (idx < s.length) buf[curPos++] = s[idx++].toByte()\n }\n\n fun flush() {\n stream.write(buf, 0, curPos)\n curPos = 0\n }\n}\n\ninline fun ArrayList.swap(ia: Int, ib: Int) {\n val tmp = this[ia]\n this[ia] = this[ib]\n this[ib] = tmp\n}\n\ninline fun ArrayList.toStr(): String {\n val builder = StringBuilder(this.size)\n for (c in this) {\n builder.append(c)\n }\n return builder.toString()\n}\n\n\nfun main(args: Array) {\n if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))\n val ir = InputReader(System.`in`)\n val ow = OutputWriter(System.out)\n\n val lst = mutableListOf()\n for (i in 2 .. 10 step 2) {\n val ca = ArrayList()\n for (j in 1 .. i / 2) {\n ca.add('4')\n }\n for (j in 1 .. i / 2) {\n ca.add('7')\n }\n while (true) {\n lst.add(ca.toStr().toLong())\n var swapped = false\n for (j in ca.size - 2 downTo 0) {\n if (ca[j] == '4' && ca[j + 1] == '7') {\n ca.swap(j, j + 1)\n swapped = true\n ca.subList(j + 1, ca.size).sort()\n break\n }\n }\n if (!swapped) break\n }\n }\n\n val n = ir.nextInt()\n var lo = 0; var hi = lst.lastIndex\n while (lo <= hi) {\n val mid = (lo + hi) ushr 1\n if (n <= lst[mid]) hi = mid - 1 // <= to < for lower-bound to upper-bound\n else lo = mid + 1\n }\n val answer = lo\n\n ow.write(\"${lst[answer]}\\n\")\n ow.flush()\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "binary search", "bitmasks"], "code_uid": "c43b28ed7dd28edbd7b6326afb615157", "src_uid": "77b5f83cdadf4b0743618a46b646a849", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport kotlin.concurrent.thread\nimport java.io.IOException\nimport java.io.BufferedReader\nimport java.io.InputStream\nimport kotlin.*\nimport java.*\nimport java.io.OutputStream\nimport java.io.PrintWriter\nimport java.lang.ArithmeticException\nimport java.lang.Exception\nimport java.math.BigInteger\nimport java.security.cert.TrustAnchor\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.system.exitProcess\n\nfun main() {\n val inputStream = System.`in`\n val outputStream = System.out\n val `in` = InputReader(inputStream)\n val out = PrintWriter(outputStream)\n\n val n = `in`.nextLong()+2\n var t = `in`.nextLong()\n\n if (t and t - 1 > 0) {\n out.println(0)\n } else {\n var kol = 1\n var ans=0L\n if (t==1L)\n --ans\n while (t % 2 == 0L) {\n ++kol\n t /= 2\n }\n\n fun C(b:Int,m:Int):Long {\n if (b0) {\n ans += C(i, kol)\n --kol\n }\n }\n\n out.println(ans)\n }\n\n\n\n out.close()\n\n}\n\n\ninternal 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 next().toLong()\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "constructive algorithms"], "code_uid": "1d3c9ae7bd7aa6c569c85ea206f1104e", "src_uid": "727d5b601694e5e0f0cf3a9ca25323fc", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "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 A = ni() - 1\n val B = ni() - 1\n val K = ni()\n val dp = Array(K + 1){LongArray(N + 10)}\n dp[0][A] = 1\n for (i in 1 .. K) {\n for (j in 0 until N) {\n val d = abs(B - j) - 1\n val t = min(N - 1, j + d)\n val b = max(0, j - d)\n val v = dp[i - 1][j]\n dp[i][b] = (dp[i][b] + v) % MOD\n dp[i][j] = (MOD + dp[i][j] - v) % MOD\n if (j + 1 <= t + 1) {\n dp[i][j + 1] = (dp[i][j + 1] + v) % MOD\n dp[i][t + 1] = (MOD + dp[i][t + 1] - v) % MOD\n }\n }\n for (j in 1 until N) {\n dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD\n }\n debug(dp[i])\n }\n out.println(dp[K].take(N).sum() % 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 // \u306a\u3093\u304b\u672c\u756a\u3067\u30a8\u30e9\u30fc\u3067\u308b\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 * \u52dd\u624b\u306bimport\u6d88\u3055\u308c\u308b\u306e\u3092\u9632\u304e\u305f\u3044\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", "lang_cluster": "Kotlin", "tags": ["dp", "combinatorics"], "code_uid": "d27bf9802f81459c04434cc0a2ec5582", "src_uid": "142b06ed43b3473513995de995e19fc3", "difficulty": 1900.0, "exec_outcome": "PASSED"}