{"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 = readInt();\n\tif(n%4 in 1..2) println(\"1\");\n\telse println(\"0\");\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "bdbc0b2b06dafe2175163d8394df79eb", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(){\n var scanner = Scanner(System.`in`)\n var n = scanner.nextInt()\n var m = scanner.nextInt()\n var a = scanner.nextInt()\n var b = scanner.nextInt()\n var sum:Int = 0\n if(b >= a*m){\n println(a*n)\n }\n else if(n==m) println(m*b)\n else if(b<=a){\n while(n>0){\n sum+=b\n n-=m\n }\n println(sum)\n }\n else {\n while(n>0){\n if(n()\n while(reached.add(n)) n = solve(n+1)\n println(reached.size)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2f506503b62c7e0408cd16c9cecca69e", "src_uid": "055fbbde4b9ffd4473e6e716da6da899", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var s = readLine()!!\n var u = s.count{it == '4' || it == '7'}\n print(if (u == 4 || u == 7) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "f6292199faa73c8e6681defbca69f530", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// codeforces problem 118 A\n\nfun main() {\n val vowels = setOf('a', 'e', 'i', 'o', 'u', 'y')\n val result = StringBuilder(readLine()!!.toLowerCase().filter { it !in vowels })\n for (i in result.length-1 downTo 0) {\n result.insert(i, '.')\n }\n println(result)\n}\n", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "93ae3038149fe649a42c7a6ae2e09a2b", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.5", "source_code": "// Tourist's Kotlin template\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(\" \").toMutableList() // list of strings\r\nprivate fun readInts() = readStrings().map { it.toInt() }.toMutableList() // list of ints\r\nprivate fun readLongs() = readStrings().map { it.toLong() }.toMutableList() // list of longs\r\nprivate fun readDoubles() = readStrings().map { it.toDouble() }.toMutableList() // list of doubles\r\n \r\nprivate fun myAssert(x: Boolean) {\r\n if (!x) {\r\n throw AssertionError()\r\n }\r\n}\r\n \r\n \r\nfun main() {\r\n\tvar MOD : Long = 1000000007L\r\n\tvar n = readInt()\r\n\tvar ans: Long = 1\r\n\twhile (n-- > 1) {\r\n\t\tans *= (16 * ans) % MOD\r\n\t\tans %= MOD\r\n\t}\r\n\tans = (ans * 6) % MOD\r\n\tprintln(ans)\r\n}\r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n ", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "d60693503ab79fd4fae499199165c011", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "val MOD = 1000000007\n\nfun pow(a: Long, n: Long): Long {\n if (n == 0L) return 1\n if (n % 2 == 1L) {\n val tmp = pow(a, n-1)\n return (tmp * a) % MOD\n } else {\n val c = pow(a, n / 2)\n return (c * c) % MOD\n }\n}\n\nfun main(args: Array) {\n var (n, m) = readLine()!!.split(' ').map { it.toLong() }\n print(pow((pow(2, m) - 1), n))\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "196a1d8d14635214e974ea3416defec6", "src_uid": "71029e5bf085b0f5f39d1835eb801891", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.collections.*\nimport kotlin.io.*\nimport kotlin.math.*\nimport kotlin.Array\n\nclass Main{\n\n fun solve(inp : InputReader) {\n val (n,k) = inp.readlnInts()\n val a = inp.readlnInts().toIntArray()\n val lim = a[k - 1]\n val ans = a.filter{it > 0 && it >= lim}.count()\n print(ans)\n }\n\n class InputReader{\n public fun readln() = readLine()!!\n public fun readlnInt() = readln().toInt()\n public fun readlnLong() = readln().toLong()\n public fun readlnDouble() = readln().toDouble()\n\n public fun readlnStrings() = readln().split(\" \")\n public fun readlnInts() = readlnStrings().map{it.toInt()}\n public fun readlnLongs() = readlnStrings().map{it.toLong()}\n public fun readlnDoubles() = readlnStrings().map{it.toDouble()}\n }\n}\n\nfun main(args : Array ){\n Main().solve(Main.InputReader())\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "92b3aee48693b7187524a021980f1ba9", "src_uid": "193ec1226ffe07522caf63e84a7d007f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var sum = 0\n val (k, n, w) = readLine()!!.split(\" \").map { it.toInt() }\n\n for (i in 1..w) {\n sum += (k * i)\n }\n if (sum > n)\n print(sum - n)\n else\n print(0)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "313c7b8f9595518bf7361adbe736bcb5", "src_uid": "e87d9798107734a885fd8263e1431347", "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 n = sc.nextLong()\n val k = sc.nextLong()\n\n println(if ((n / k) % 2 == 0L) \"NO\" else \"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", "lang_cluster": "Kotlin", "tags": ["math", "games"], "code_uid": "e60e67704b6ea52f2dba763bcadb43e1", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50", "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 bills = listOf(100, 20, 10, 5, 1)\n var n = readInt()\n var result = 0\n\n var i = 0\n while (n != 0) {\n // was confused in >= and > for a long time, need to practise this problem more\n if (n >= bills[i]) {\n // O(1)\n result += n / bills[i]\n n %= bills[i]\n }\n i++\n }\n\n println(result)\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy", "dp"], "code_uid": "a82105e2632e908af1a4ea02a7b37eba", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc", "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 (k, r) = readInts()\n var i = 1\n while (true) {\n if ((i * k) % 10 == 0 || (i * k - r) % 10 == 0) {\n print(i)\n break\n }\n i++\n }\n}\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "addf96fc77bc88a09dd50763f1490c53", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(){\n val scan = Scanner(System.`in`)\n val n = scan.nextLong()\n val k = scan.nextLong()\n var d: Long\n \n d = if (n % 2 == 0L) n/2+1\n else n/2+2\n\n d = if (k < d) 1 + (k-1)*2\n else 2*(k-d+1)\n\n println(d)\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "3495fb6f5aea4693a827b162cfd94860", "src_uid": "1f8056884db00ad8294a7cc0be75fe97", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main()\n{\n var (n, k) = readLine()!!.split(\" \").map { it.toInt() }\n \n while (k > 0)\n {\n if (n % 10 == 0) n /= 10\n else n -= 1\n k -= 1\n }\n \n println(n)\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "657c9627433e0ad69e7a41b926ac8d81", "src_uid": "064162604284ce252b88050b4174ba55", "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() }\nprivate fun readLongs() = readStrings().map { it.toLong() }\n\nfun main() {\n val (w, h) = readInts()\n\n val mod = 998244353\n var res = 1L\n repeat(w + h) {\n res *= 2\n res %= mod\n }\n println(res)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "combinatorics"], "code_uid": "2b77e41e50628df217088448875adab6", "src_uid": "8b2a9ae21740c89079a6011a30cd6aee", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main()\n{\n val(nb_students, nb_puzzles)= readLine()!!.split(\" \").map { it.toInt()}\n val pieces = readLine()!!.split(\" \").map { it.toInt()}\n val sortedAsc = pieces.sorted()\n var res = Integer.MAX_VALUE\n for (i in 0 .. nb_puzzles - nb_students)\n {\n res = minOf(res, sortedAsc[i + nb_students - 1] - sortedAsc[i])\n }\n println(res)\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "36691d3c5ae55ab9234d666529f6a123", "src_uid": "7830aabb0663e645d54004063746e47f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var (a, b) = readLine()!!.split(' ').map { it.toInt() }\n\n for (i in 0..Int.MAX_VALUE)\n if (a > b) {\n println(i)\n return\n } else {\n a *= 3\n b *= 2\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "bd1f6db9069c5862ccc979f16b53b7a8", "src_uid": "a1583b07a9d093e887f73cc5c29e444a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (y, b, r) = readLine()!!.split(\" \").map { it.toInt() }\n\n val yVal = listOf(y, b - 1, r - 2).min()!!\n val bVal = listOf(y + 1, b, r - 1).min()!!\n val rVal = listOf(y + 2, b + 1, r).min()!!\n\n val result = yVal + bVal + rVal\n\n println(result)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "f601fb4898405c1c099a0df93b0cac5c", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun mergeSort(a : MutableList) {\n val n = a.size\n if (n == 1) {\n return\n }\n val f = a.take(n / 2).toMutableList()\n val s = a.takeLast(n - n / 2).toMutableList()\n mergeSort(f)\n mergeSort(s)\n var ptr1 = 0\n var ptr2 = 0\n var ptr = 0\n while (ptr1 < f.size && ptr2 < s.size) {\n if (f[ptr1] < s[ptr2]) {\n a[ptr++] = f[ptr1++]\n }\n else {\n a[ptr++] = s[ptr2++]\n }\n }\n while (ptr1 < f.size) {\n a[ptr++] = f[ptr1++]\n }\n while (ptr2 < s.size) {\n a[ptr++] = s[ptr2++]\n }\n}\n\nfun main() {\n val n = readLine()!!.toInt()\n val a = readLine()!!.split(' ').map { it.toInt() }.toMutableList()\n mergeSort(a)\n var ans = 0\n for (i in (1 until n) step 2) {\n ans += a[i] - a[i - 1]\n }\n print(ans)\n}", "lang_cluster": "Kotlin", "tags": ["sortings"], "code_uid": "01309464e5372ed56ae6938cc27ee302", "src_uid": "55485fe203a114374f0aae93006278d3", "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\nconst val nn = 1 shl 19\nval t = IntArray(nn * 2)\nval ti = IntArray(nn * 2)\n\nfun put(i: Int, value: Int) {\n var j = i + nn\n t[j] = value\n ti[j] = i\n while (true) {\n j /= 2\n if (j == 0) break\n if (t[2*j] > t[2*j+1]) {\n t[j] = t[2*j]\n ti[j] = ti[2*j]\n } else {\n t[j] = t[2*j+1]\n ti[j] = ti[2*j+1]\n }\n }\n}\n\nfun getMax(): Int = ti[1]\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) put(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 put(ft[a[i]], nexts[i])\n continue\n }\n val r = getMax()\n ft[f[r]] = -1\n f[r] = a[i]\n put(r, pos[a[i]])\n ft[a[i]] = r\n ans++\n }\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "15be2ae27515c91c0433a575f2be0126", "src_uid": "956228e31679caa9952b216e010f9773", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\n/**\n * Created by ramilagger on 6/15/17.\n *\n */\n\nfun sum(n: String): Int {\n var sum = 0\n for (i in n.indices)\n sum += Character.getNumericValue(n[i])\n return sum\n}\n\nfun f(n : Long) = n - sum(n.toString())\n\nfun solve(){\n val n = nextLong()\n val s = nextLong()\n var lo = 0L\n var hi = n\n while (lo <= hi) {\n val mid = lo + (hi - lo) / 2\n if(f(mid) < s) lo = mid + 1\n else hi = mid - 1\n }\n if(hi == -1L) pw.println(n)\n else {\n if (n != hi) pw.println(n - hi)\n else pw.println(if (f(n) < s) 0 else 1)\n }\n}\n\n\nfun hasNext() : Boolean {\n if(st.hasMoreTokens())\n else\n while (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine())\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\nval ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\nval br = if(ONLINE_JUDGE) BufferedReader(InputStreamReader(System.`in`)) else BufferedReader(FileReader(\"in.txt\"))\nval pw = if(ONLINE_JUDGE) PrintWriter(BufferedWriter(OutputStreamWriter(System.out))) else PrintWriter(BufferedWriter(FileWriter(\"out.txt\")))\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": ["brute force", "math", "dp", "binary search"], "code_uid": "0988722eaf7ff8dffbf5bd110ab120be", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val s = Scanner(System.`in`).useDelimiter(\"\\\\s\")\n val n = s.nextInt()\n val m = s.nextInt()\n val a = s.nextInt()\n val h = n / a + (if (n % a == 0) 0 else 1)\n val w = m / a + (if (m % a == 0) 0 else 1)\n System.out.print(h.toLong() * w.toLong())\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "98f7dc6e909803152a1a5c0a385944a7", "src_uid": "ef971874d8c4da37581336284b688517", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun steps(distance: Int): Int {\n return if (distance > 5)\n steps(distance - 5) + 1\n else 1\n}\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val s = reader.readLine().toInt()\n println(steps(s))\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "5129513efc69bc2f4a43537c2456c7f3", "src_uid": "4b3d65b1b593829e92c852be213922b6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var (w, h, k) = readLine()!!.split(\" \").map {it -> it.toInt()}\n var ans = 0\n for (i in 1..k) {\n ans += (w + h) * 2 - 4\n w -= 4\n h -= 4\n }\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "510f282d781927da2c09662827c1275c", "src_uid": "2c98d59917337cb321d76f72a1b3c057", "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 lane = ((k-1) / (2 * m)) + 1\n val desk = (((k-1)/2) % m) + 1\n val side = if(k%2 == 1) \"L\" else \"R\"\n println(\"$lane $desk $side\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "eaccd8a778846ad8592f5328830e0404", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val sum = readLine()!!.split(' ').map { it.toInt() }.reduce { total, next -> total + next }\n println(if (sum > 0 && sum % 5 == 0) sum / 5 else \"-1\")\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5e067c68e5551d30019efba16b374fdb", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20", "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 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\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[0, tree.size]!!.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 == 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 /* 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 * size) { identityValue } as Array\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 + 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 /** 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: T) {\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): T {\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): T {\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\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": "7262345af1aa117ad41bd3a087a356f0", "src_uid": "37bb4fe5f6cc2a173e97c033c6fde8c7", "difficulty": 3100.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 = br.readLine().toInt()\n val a = br.readLine().split(\" \").map { it.toInt() }\n val count = Array(105){0}\n for (a_i in a){\n count[a_i]++\n }\n\n val asorted = Array(n){0}\n var i = 0\n var j = 0\n\n while (i < count.size){\n if (count[i] != 0){\n asorted[j] = i\n count[i]--\n j++\n }else{\n i++\n }\n }\n println(asorted.joinToString(\" \"))\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "857e7e5e4683c85c2b8cc33d7f86ab0a", "src_uid": "ae20712265d4adf293e75d016b4b82d8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n\n var lines = readLine()!!.toInt()\n \n for (line in 1..lines) {\n var result = 0\n var candles = readLine()!!.toInt()\n if (candles > 2) {\n if (candles % 2 == 0) {\n result = candles / 2 - 1\n } else {\n result = candles / 2\n }\n }\n println(result)\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "ef7868c690bb4a0b0b1df0fa71783a8f", "src_uid": "b69170c8377623beb66db4706a02ffc6", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val inputReader = InputReader(inputStream)\n val out = PrintWriter(outputStream)\n\n val n = inputReader.nextInt()\n val k = inputReader.nextLong()\n val str = inputReader.next()\n\n val letters = BooleanArray(26)\n val list = ArrayList(n)\n for (i in 0 until str.length) {\n val char = str[i]\n val node = Node(char, i, n)\n if (letters[char - 'a']) {\n node.isSame = true\n } else {\n letters[char - 'a'] = true\n }\n list.add(node)\n }\n for (i in 0 until list.size) {\n val ai = list[i]\n for (j in i + 1 until list.size) {\n val aj = list[j]\n ai.addNext(aj.char - 'a', aj)\n }\n }\n\n for (node in list) {\n find(node)\n }\n\n val totalCountArray = LongArray(n)\n for (i in 0 until n) {\n for (node in list) {\n if (!node.isSame) {\n totalCountArray[i] += node.countArray[i]\n }\n }\n }\n\n var totalCost = 0L\n var selectCount = 0L\n for (i in n - 1 downTo 0) {\n if (selectCount + totalCountArray[i] < k) {\n totalCost += (n - 1 - i) * totalCountArray[i]\n selectCount += totalCountArray[i]\n } else {\n val over = (selectCount + totalCountArray[i]) - k\n totalCost += (n - 1 - i) * (totalCountArray[i] - over)\n selectCount += (totalCountArray[i] - over)\n break\n }\n }\n\n if (selectCount < k) {\n if (selectCount == k - 1) {\n println(totalCost + n)\n } else {\n println(-1)\n }\n } else {\n println(totalCost)\n }\n}\n\nprivate fun find(node: Node) {\n if (node.hasCul) {\n return\n }\n\n node.countArray[0]++\n for (next in node.nextList) {\n find(next)\n for (i in 0 until next.countArray.size) {\n if (next.countArray[i] > 0) {\n node.countArray[i + 1] += next.countArray[i]\n }\n }\n }\n\n node.hasCul = true\n}\n\nclass Node(var char: Char, var index: Int, n: Int) {\n private val nextArray: Array = arrayOfNulls(26)\n var hasCul = false\n var isSame = false\n var nextCount = 0\n val nextList = ArrayList()\n\n val countArray = LongArray(n)\n\n override fun toString(): String {\n return \"$char\"\n }\n\n fun addNext(index: Int, node: Node) {\n if (nextArray[index] == null) {\n nextCount++\n nextArray[index] = node\n nextList.add(node)\n }\n }\n}\n\nclass InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream))\n private var tokenizer = StringTokenizer(\"\")\n\n /** get next word */\n @Throws(IOException::class)\n operator fun next(): String {\n while (!tokenizer.hasMoreTokens()) {\n //TODO add check for eof if necessary\n tokenizer = StringTokenizer(\n reader.readLine()\n )\n }\n return tokenizer.nextToken()\n }\n\n fun nextLong() = next().toLong()\n fun nextInt() = next().toInt()\n fun nextDouble() = next().toDouble()\n fun nextFloat() = next().toFloat()\n}", "lang_cluster": "Kotlin", "tags": ["strings", "dp"], "code_uid": "45875e55913a05a2f9e2efaefd61614f", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b", "difficulty": 1900.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 lucky(x: Int): Boolean {\n var c = x\n while (c > 0) {\n val d = c % 10\n when (d) {\n 4, 7 -> {}\n else -> { return false }\n }\n c /= 10\n }\n return true\n }\n\n val io = ProblemIO.console()\n\n val n = io.readInt()\n val res = (1 .. 1000).filter({ x -> n % x == 0 && lucky(x) }).isNotEmpty()\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": ["brute force", "number theory"], "code_uid": "09400f6e6d536bccebe6954c522c7dc9", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d", "difficulty": 1000.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=readInt();n--\n var names=arrayOf(\"Sheldon\",\"Leonard\",\"Penny\",\"Rajesh\",\"Howard\")\n var sz=1\n while(sz*5<=n){\n n-=sz*5\n sz*=2\n }\n printLine(names[n/sz])\n output()\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "e8ca9b30521eff22a73db2419ceadce1", "src_uid": "023b169765e81d896cdc1184e5a82b22", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nfun main(arg: Array){\n\tval (w, h) = readLine()!!.toString().split(' ').map{it.toInt()}\n\tval (w1, h1) = readLine()!!.toString().split(' ').map{it.toInt()}\n\tval (w2, h2) = readLine()!!.toString().split(' ').map{it.toInt()}\n\tvar endW = w\n\tfor(i in 0..h){\n\t\tval ch = h - i\n\t\tendW += ch\n\t\tif(ch == h1){\n\t\t\tendW = max(0,endW-w1)\n\t\t}else if(ch == h2){\n\t\t\tendW = max(0,endW-w2)\n\t\t}\n\t}\n\tprintln(endW)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7111bf08fabe7bd18bcefed59576322d", "src_uid": "084a12eb3a708b43b880734f3ee51374", "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 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 for(case in 1..numCases) {\n //print(\"Case #$case: \")\n\n val k = readLong()\n val b = readLong()\n val n = readLong()\n val t = readLong()\n\n val ans = if(k == 1L) {\n val z = n*b + 1\n max(0, (z - t) divCeil b)\n } else {\n var num = k - 1 + b\n val den = t * (k - 1) + b\n\n var r = n\n while (r > 0 && num < den) {\n num *= k\n if (num <= den) r--\n }\n r\n }\n\n println(ans)\n }\n}\n\ninfix fun Long.divCeil(other: Long) =\n (this / other).let { if(xor(other) >= 0 && it * other != this) it+1 else 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\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": ["math", "implementation"], "code_uid": "55843d219e331ffcdc113e677cd699c8", "src_uid": "e2357a1f54757bce77dce625772e4f18", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n val aSide = reader.nextInt()\n val bSide = reader.nextInt()\n val cSide = reader.nextInt()\n val nums = intArrayOf(aSide, bSide, cSide)\n nums.sort()\n if (calc(nums) < 0) println(0)\n else println(calc(nums))\n\n\n}\n\nfun calc(nums: IntArray): Int {\n return nums.last() + 1 - nums[nums.lastIndex - 1] - nums[nums.lastIndex - 2]\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "geometry"], "code_uid": "cff54b7f8db6c56899ab099730816b3b", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\nimport kotlin.math.round\n\nfun main() {\n val scanner = Scanner(System.`in`)\n var sumIn:String = scanner.nextLine()\n var sumAux = IntArray(round((sumIn.count()/2).toDouble()).toInt() + 1)\n var sumOut:StringBuilder = StringBuilder()\n var count = 0\n\n for(num in sumIn.toCharArray()) {\n if(!num.equals('+') && count < round((sumIn.count()/2).toDouble()).toInt() + 1) {\n sumAux.set(count, num.toString().toInt())\n count++\n }\n }\n\n sumAux.sort()\n\n for(num in sumAux){\n sumOut.append(num.toString() + \"+\")\n }\n\n print(sumOut.toString().dropLast(1))\n\n }", "lang_cluster": "Kotlin", "tags": ["sortings", "strings", "implementation", "greedy"], "code_uid": "311d171e8c48588ad967907f36583984", "src_uid": "76c7312733ef9d8278521cf09d3ccbc8", "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: Int = ir.nextInt()\n val m: Int = ir.nextInt()\n var count = 0\n\n if (m % n == 0) {\n var num = m / n\n while (num % 2 == 0 || num % 3 == 0) {\n if (num % 2 == 0)\n num /= 2\n else\n num /= 3\n count++\n }\n\n if (num == 1)\n pw.print(count)\n else\n pw.print(-1)\n\n } else\n pw.print(-1)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "566b7b00bf118d42c7b22315162d2e1d", "src_uid": "3f9980ad292185f63a80bce10705e806", "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.*\n\nfun main(args: Array) {\n val sc = FastScanner(System.`in`)\n\n val n = sc.nextInt()\n val d = Array(n) { sc.nextInt() }\n\n val year = listOf(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)\n val vis = listOf(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)\n\n\n if (check(year + year + year + vis, d) ||\n check(year + year + vis + year, d) ||\n check(year + vis + year + year, d) ||\n check(vis + year + year + year, d) ||\n check(year + year + year + year, d)) {\n println(\"YES\")\n }\n else {\n println(\"NO\")\n }\n\n\n}\n\nfun check(list: List, d: Array): Boolean {\n for(i in 0 until list.size){\n if(i + d.size > list.size) break\n\n if(list.subList(i, i + d.size) == d.toList()) return true\n }\n return false\n}\n\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}\n\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8f9aeaef54b496cbf904ccd5e4bb29e1", "src_uid": "d60c8895cebcc5d0c6459238edbdb945", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport kotlin.math.abs\nimport kotlin.math.max\n\nfun main() {\n solve()\n}\n\nprivate fun solve() {\n val (x1, y1) = readLongs()\n val (x2, y2) = readLongs()\n val a = abs(x2 - x1)\n val b = abs(y2 - y1)\n println(max(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() } // li\nprivate fun readLongs() = readStrings().map { it.toLong() } // li", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "abb436cf66713b99aa5113164a306ba7", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/* https://codeforces.com/problemset/problem/59/A */\n\nfun main() {\n val word = readLine()!!\n val numOfLowerCaseChars = word.count { it.isLowerCase() }\n val numOfUpperCaseChars = word.length - numOfLowerCaseChars\n if (numOfLowerCaseChars >= numOfUpperCaseChars) {\n println(word.toLowerCase())\n } else {\n println(word.toUpperCase())\n }\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "adc781848f9d3d95aadaf5b37c5fed15", "src_uid": "b432dfa66bae2b542342f0b42c0a2598", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val name: String = readLine()!!\n val chars: MutableSet = name.toCharArray().toMutableSet()\n if (chars.count() %2 == 0) {\n print(\"CHAT WITH HER!\")\n } else {\n print(\"IGNORE HIM!\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "caede7748d090e5ce8a1f8ec933ed592", "src_uid": "a8c14667b94b40da087501fd4bdd7818", "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 (len, v1, v2, p1, p2) = r.readLine()!!.split(\" \").map { it.toInt() }\n val t1 = v1*len+2*p1\n val t2 = v2*len+2*p2\n when{\n t1 println(\"First\")\n t2 < t1 -> println(\"Second\")\n else -> println(\"Friendship\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "f2b93f8747b8b855aa91d84da066d02d", "src_uid": "10226b8efe9e3c473239d747b911a1ef", "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": "705a487fd9e1c3913f9cd622eeeab4eb", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val scaner = readLine()!!.toInt()\n var liner = readLine()!!.toString()\n var deleteSumbol = 0\n\n while(\"xxx\" in liner)\n {\n deleteSumbol++\n liner = liner.replaceFirst(\"xxx\", \"xx\", ignoreCase = true)\n }\n print(deleteSumbol)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "strings"], "code_uid": "0e8576ab8d72bb871df5bf563210fb64", "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 //val k = r.readLine()!!.toInt()\n val (a, b) = r.readLine()!!.split(\" \").map { it.toInt() }.sorted()\n val c = 7-b\n println(\"${c/ gcd(c, 6)}/${6/ gcd(c, 6)}\")\n\n}\n\ntailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)", "lang_cluster": "Kotlin", "tags": ["math", "probabilities"], "code_uid": "152604d6a242a5255599ee00d7aa1a9b", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414", "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 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 s = readLn()\n val cand = listOf(\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\")\n\n val ans = cand.find { c -> c.length == n && c.indices.all { i -> s[i] == '.' || c[i] == s[i] } }\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)\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": ["brute force", "strings", "implementation"], "code_uid": "a9da16bc575adab8fdf5967b6b8df31e", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "fun solve() {\r\n val n = readN()\r\n val ans = (1 shl n) - 1\r\n\r\n println(ans)\r\n}\r\n\r\nfun readN() = readln().toInt()\r\nfun readStrings() = readln().split(' ')\r\nfun readInts() = readStrings().map { it.toInt() }\r\n\r\nfun main() = repeat(readN()) { solve() }", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "871e421619f172ef0966235022d904f0", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.io.BufferedReader\r\nimport java.util.*\r\n\r\nval bin = System.`in`.bufferedReader()\r\nfun BufferedReader.readInts() = this.readLine()!!.split(' ').map { it.toInt() }.toIntArray()\r\n\r\nfun main() {\r\n// val t = measureTimeMillis {\r\n// solve(200000, 998244353)\r\n// }\r\n// println(\"Took $t ms\")\r\n\r\n// explore()\r\n val (n, m) = bin.readInts()\r\n println(solve(n, m))\r\n}\r\n\r\nfun solve(n: Int, m: Int): Int {\r\n val s = IntArray(n+1)\r\n s[n] = 1\r\n\r\n var sum = 0\r\n for (x in n downTo 2) {\r\n s[x] = (s[x] + sum) % m\r\n val v = s[x]\r\n\r\n var l = 1\r\n while (l*l <= x) {\r\n if (l != 1 && x/l != l) {\r\n s[x / l] = (s[x / l] + v) % m\r\n }\r\n val copies = x/l - x/(l+1)\r\n s[l] = ((s[l] + v.toLong() * copies) % m).toInt()\r\n l++\r\n }\r\n\r\n sum = (sum + v) % m\r\n }\r\n\r\n return (s[1] + sum) % m\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "dp", "data structures", "number theory"], "code_uid": "8ab97dc42b6c2c03771ec4df5a8465a4", "src_uid": "a524aa54e83fd0223489a19531bf0e79", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val mass = readLine()!!.split(\" \").map { it.toInt() }\n val f = mass.sum()\n if (f % 2 != 0) {\n print(\"NO\")\n } else {\n var stop = false\n for (i in 0..5) {\n for (j in 0..5) {\n for (k in 0..5) {\n if (i != j && i != k && j != k && (mass[i] + mass[j] + mass[k])* 2 == f) {\n print(\"YES\")\n stop = true\n break\n }\n }\n if (stop) {\n break\n }\n }\n if (stop) {\n break\n }\n }\n if (!stop) {\n print(\"NO\")\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "d727534154d4ce2fe2d2ba08046c0833", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (sh, sm) = readLine()!!.split(':').map { it.toInt() }\n val (eh, em) = readLine()!!.split(':').map { it.toInt() }\n\n val dm = ((eh - sh) * 60 + (em - sm)) / 2\n val hh = sh + ((sm + dm) / 60)\n val mm = (sm + (dm % 60)) % 60\n val hhs = if (hh < 10) \"0$hh\" else hh.toString()\n val mms = if (mm < 10) \"0$mm\" else mm.toString()\n println(\"$hhs:$mms\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7164bf31a27c1e8dbf06f86207655545", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\nfun main(args: Array){\n val input = Scanner(System.`in`)\n var pituus = readLine()!!\n var teksti = readLine()!!\n var maksimi: Int = 0\n var kirjaimet: String = \"\"\n for(i in 0..(teksti.length-2)){\n var kaksi: String = \"\" + teksti[i] + teksti[i+1]\n var luku: Int = 0\n for(j in 0..(teksti.length-2)){\n var uudetkaksi: String = \"\" + teksti[j] + teksti[j+1]\n if(kaksi.equals(uudetkaksi)){\n luku += 1\n }\n }\n if(luku > maksimi){\n maksimi = luku\n kirjaimet = kaksi\n }\n }\n println(kirjaimet)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "c2b1b0dd90a12b97e35f73ab286b9c31", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1", "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 var a = scanner.nextInt() + 1\n val arr = IntArray(10)\n while (true) {\n var flag = false\n for (i in a.toString()) {\n if (arr[i - '0'] == a) {\n flag = true\n break\n }\n arr[i - '0'] = a\n }\n a++\n if (flag)\n continue\n println(a - 1)\n return\n }\n\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\n//class Pair(var a: Int, var b: Int): Comparable {\n// override fun compareTo(other: Pair): Int {\n// return b - a - other.b + other.a\n// }\n//}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "2320b66c7d2ab747cca5732f13f4c940", "src_uid": "d62dabfbec52675b7ed7b582ad133acd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nval c=IntArray(1001,{0})\n\nfun main() {\n val scan = Scanner(System.`in`)\n var t:Int=scan.nextInt()\n while(t>0)\n {\n var n=scan.nextInt()\n for(i in 0 until n)\n {\n c[i]=scan.nextInt()\n }\n var currentTurn=0\n var currentEat=0\n var a=0\n var suma=0\n var b=0\n var sumb=0\n var index_a=0\n var index_b=n-1\n var sweets=n\n\n while(sweets>0)\n {\n if (currentTurn%2==0)\n {\n while(a<=currentEat)\n {\n if(sweets==0)\n break\n a+=c[index_a]\n c[index_a]=0\n sweets--\n index_a++\n\n }\n currentEat=a\n suma+=a\n }\n else\n {\n while(b<=currentEat)\n {\n if (sweets==0)\n break\n b+=c[index_b]\n c[index_b]=0\n sweets--\n index_b--\n\n }\n sumb+=b\n currentEat=b\n\n }\n currentTurn++\n a=0\n b=0\n // println(currentEat)\n }\n\n\n println(\"$currentTurn $suma $sumb\")\n\n\n t--\n }\n\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4ef141e2b15e386de5bf6e883d710b82", "src_uid": "d70ee6d3574e0f2cac3c683729e2979d", "difficulty": 1300.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\n if(n<0) {n =-n}\n var res = 0\n var tot = 0\n while(tot m * 9) {\n println(\"-1 -1\")\n return\n }\n var sum = s\n val maxX = List(m) {\n val x = min(sum, 9)\n sum -= x\n x\n }\n sum = s\n val minX = List(m) {index ->\n val x = if (index == m - 1) {\n sum\n } else {\n min(sum - 1, 9)\n }\n sum -= x\n x\n }.reversed()\n println(\"${minX.joinToString(\"\")} ${maxX.joinToString(\"\")}\")\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp", "implementation"], "code_uid": "7639b073239d5b15c98f27c274cd6a89", "src_uid": "75d062cece5a2402920d6706c655cad7", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n println(4 - readLine()!!.split(' ').toSet().size)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "0e2e3456adfd374a30fd857c2d8ef44c", "src_uid": "38c4864937e57b35d3cce272f655e20f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (a, b, c) = readLine()!!.split(\" \").map { it.toLong() }\n val min = Math.min(a, b)\n val max = Math.max(a, b)\n var ans = c * 2 + min * 2\n if (max > min) ans++\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "e03864e805f8fdfcfc9319442bb11fb7", "src_uid": "609f131325c13213aedcf8d55fc3ed77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nfun readln() = readLine()!!\nfun readint() = readln().toInt()\nfun readlong() = readln().toLong()\nfun readdouble() = readln().toDouble()\nfun readstrings() = readln().split(\" \")\nfun readints() = readstrings().map { it.toInt() }\nfun readlongs() = readstrings().map { it.toLong() }\nfun readdoubles() = readstrings().map { it.toDouble() }\n\nvar mod=998244353L\n\nfun pw(a:Long,b:Long):Long{\n var c=b\n var d=a\n var res=1L\n while(c>0){\n if((c and 1L)!=0L){\n res*=d\n res%=mod\n }\n d*=d\n d%=mod\n c/=2\n }\n return res\n}\n\nfun inv(a:Long):Long{\n return pw(a,mod-2L)\n}\n\nfun main() {\n var tt = 1\n var f=LongArray(500010){1L}\n for(i in 2..500000){\n f[i]=f[i-1]*i.toLong()%mod\n }\n while (tt-- > 0) {\n var (n,k)=readints()\n var ans=0L\n for(i in 1..n-k+1){\n var cnt=n/i\n if(cntUnit) { Output().apply(block).nowPrint() }", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "7045a6519bd267549db552248259234a", "src_uid": "ce220726392fb0cacf0ec44a7490084a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun readLn() = readLine()!! // string line\nfun readInt() = readLn().toInt() // single int\nfun readStrings() = readLn().split(\" \") // list of strings\nfun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun findLissPos(): Int {\n\n val stones = readLn()\n val instructions = readLn()\n var curPos = 0\n for (i in 0 until instructions.length) {\n if (stones[curPos ] == instructions[i])\n curPos++\n }\n\n curPos++\n\n return curPos;\n}\n\n\nfun main() {\n print(findLissPos())\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4d506b96bbc67d251655832b3a6c7e73", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252", "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\n/**\n * Created by cidgeedeng on 2019-09-23.\n */\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val inputReader = InputReader(inputStream)\n\n val k = inputReader.nextLong()\n var num = 0L\n var len = 0L\n\n while (len < k) {\n num++\n len += num.toString().length\n }\n\n val numStr = num.toString()\n print(numStr.subSequence(0, (numStr.length - (len - k)).toInt()).last())\n}\n\nclass InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream))\n private var tokenizer = StringTokenizer(\"\")\n\n /** get next word */\n @Throws(IOException::class)\n operator fun next(): String {\n while (!tokenizer.hasMoreTokens()) {\n tokenizer = StringTokenizer(\n reader.readLine()\n )\n }\n return tokenizer.nextToken()\n }\n\n fun nextLong() = next().toLong()\n fun nextInt() = next().toInt()\n fun nextDouble() = next().toDouble()\n fun nextFloat() = next().toFloat()\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2115b927361c0b023a93510bdebcb9d0", "src_uid": "1503d761dd4e129fb7c423da390544ff", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun Boolean.toInt() = if (this) 1 else 0\n val board = Array(4) { readLine()!! }\n for (r in 0..2)\n for (c in 0..2) {\n var counter = 0\n counter += (board[r][c] == board[r][c + 1]).toInt()\n counter += (board[r][c] == board[r + 1][c]).toInt()\n counter += (board[r][c] == board[r + 1][c + 1]).toInt()\n if (counter != 1) {\n print(\"YES\")\n return\n }\n }\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "1a8f448f3af8729a7f669090d6e7275b", "src_uid": "01b145e798bbdf0ca2ecc383676d79f3", "difficulty": 1100.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 str = readLine()!!\n\n var old: Char = ' '\n var ans = \"\"\n for(elem in str){\n if(elem != '/' || (old != '/')){\n ans += elem;\n }\n old = elem;\n }\n\n if (ans.length != 1 && ans.endsWith(\"/\")){\n ans = ans.substring(0 , ans.length - 1)\n }\n\n print(ans)\n\n}\n\nclass Pair(x: Long, y: Long) {\n var x: Long = x;\n var y: Long = y;\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "56f79fa10a87bc65c6782d720ee97ba1", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val jin = Scanner(System.`in`)\n val n = jin.nextLong()\n val k = jin.nextLong()\n for (answer: Long in n downTo 0L) {\n if ((((n - answer) * (n - answer + 1L)) / 2) - answer == k) {\n println(answer)\n return\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "binary search"], "code_uid": "2144b6759c53b2fb733e83359dfd779c", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77", "difficulty": 1000.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 s = inf.readLine()\n fun match(a: String, b: String) = a[0] == b[0] || a[1] == b[1]\n ouf.println(if (inf.readLine().split(' ').any { match(s, it) }) \"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", "implementation"], "code_uid": "8b6de2ac897391569afb0227e9668cc3", "src_uid": "699444eb6366ad12bc77e7ac2602d74b", "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 var (n, m, k) = jin.readLine().split(\" \").map { it.toInt() }\n var dir = jin.readLine().last() == 'l'\n val state = jin.readLine()\n var prev = mutableListOf(m)\n var answer = 0\n for (chara in state) {\n answer++\n val prevK = k\n if (k == 1) {\n dir = true\n } else if (k == n) {\n dir = false\n }\n if (dir) {\n k++\n } else {\n k--\n }\n val next = mutableSetOf()\n if (chara == '0') {\n for (x in prev) {\n if (x != k) {\n next.add(x)\n }\n if (x != 1 && x - 1 != prevK && x - 1 != k) {\n next.add(x - 1)\n }\n if (x != n && x + 1 != prevK && x + 1 != k) {\n next.add(x + 1)\n }\n }\n } else {\n next.addAll(1..n)\n next.remove(k)\n }\n if (next.isEmpty()) {\n println(\"Controller\")\n println(answer)\n return\n }\n prev = next.toMutableList()\n }\n println(\"Stowaway\")\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp", "games"], "code_uid": "d9c173e6089dc7053e60af39a02840d7", "src_uid": "2222ce16926fdc697384add731819f75", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)){\n val s = nextLine()\n val chars = s.toCharArray()\n val size= chars.size\n val middle = (size - 1) / 2\n\n val odd = size % 2 != 0\n\n var j = size - 1\n var i = 0\n var counter = 1\n\n var palindrom = true\n while(true){\n val begin = chars[i]\n val end = chars[j]\n if(begin != end){\n if (counter == 0){\n palindrom = false\n break\n }\n counter--\n }\n if (i == middle){\n break\n }\n i++\n j--\n }\n if((palindrom && counter == 0) ||( palindrom && counter == 1 && odd) ){\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}\n ", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "constructive algorithms"], "code_uid": "9be9ff35b661e3eb0c387e0eb45c0e49", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52", "difficulty": 1000.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\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of Longs\n\nfun main(){\n val n = readInt()\n val a = ArrayList()\n val b = ArrayList()\n val ta = readInts()\n ta.sorted().forEach{\n a.add(it)\n b.add(false)\n }\n var count = 0\n for(i in 0 until a.size) {\n if(b[i]) continue\n count++\n for(j in i+1 until a.size) {\n if(!b[j] && a[j] % a[i] == 0) {\n b[j] = true\n }\n }\n }\n println(count)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "fa4fee1d2f001aad68fa1f3ac4c3abb3", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd", "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 (vp, vd, t, f, c) = List(5){br.readLine().toDouble()}\n if (vp >= vd) println(0)\n else {\n var cnt = 0\n var p = vd*(vp*t/(vd - vp))\n while (p < c) {\n p = vd*(vp*(f + p/vd) + p)/(vd - vp)\n ++cnt\n }\n println(cnt)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "ec0d213b6a222309bcdcfd2976c089f8", "src_uid": "c9c03666278acec35f0e273691fe0fff", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(p: Array){\n val line = readLine()!!.split(\" \").map(String::toLong)\n val division = line[0] / line[1]\n val down = (line[0] - (division * line[1])) * line[3]\n val up = (((division + 1) * line[1]) - line[0]) * line[2]\n if (down > up){\n println(up)\n } else {\n println(down)\n }\n }", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "4075767c1c0499d1eded95e26a2e9927", "src_uid": "c05d753b35545176ad468b99ff13aa39", "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, k) = r.readLine()!!.split(\" \").map { it.toInt() }\n val n = r.readLine()!!.toInt()\n val v = List(1000){it+1}.joinToString(\"\")\n println(v[n-1])\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "bd89e5a890ccc9943f0290a49f96e25a", "src_uid": "2d46e34839261eda822f0c23c6e19121", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nclass A {\n fun start(scan: Scanner) {\n val bucketCount = scan.nextInt()\n val gardenLength = scan.nextInt()\n\n println(gardenLength / Array(bucketCount) { scan.nextInt() }\n .filter { gardenLength % it == 0 }\n .max()!!)\n }\n}\n\nfun main(args: Array) {\n A().start(Scanner(System.`in`).also { it.useDelimiter(\"[\\t\\n\\\\s]+\") })\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "b5d88ce2700b9be7df3122fe192129d8", "src_uid": "80520be9916045aca3a7de7bc925af1f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args:Array){\n var line = readLine()!!\n var dot = \"0000000\"\n var one = \"1111111\"\n if(dot in line ||one in line){\n println(\"YES\")\n }else{\n println(\"NO\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "5e2c895bc51f4d72beb03cbf952a8544", "src_uid": "ed9a763362abc6ed40356731f1036b38", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n fun main(args: Array) {\n val input = Scanner(System.`in`)\n val weight = input.nextInt()\n\n if (weight > 2 && weight % 2 == 0)\n print(\"YES\")\n else\n print(\"NO\")\n }", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "797764574b89975e104950b555468341", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.math.BigInteger\n\nfun readInt(): Int {\n return readLine()!!.toInt()\n}\n\nfun readLong(): Long {\n return readLine()!!.toLong()\n}\n\nfun readBigInt(): BigInteger {\n return readLine()!!.toBigInteger()\n}\n\nfun readInts(): List {\n return readLine()!!.split(\" \").map(String::toInt)\n}\n\nfun readLongs(): List {\n return readLine()!!.split(\" \").map(String::toLong)\n}\n\nfun readBigInts(): List {\n return readLine()!!.split(\" \").map(String::toBigInteger)\n}\n\nclass Solution(private val n: Int, private val b: Int, private val a: List) {\n fun solve() {\n var even = 0\n var odd = 0\n val possibleCuts = mutableListOf()\n for (i in a.indices) {\n if (a[i] % 2 == 0)\n even++\n else\n odd++\n if (even == odd && i + 1 < a.size)\n possibleCuts.add(kotlin.math.abs(a[i] - a[i + 1]))\n }\n if (even != odd)\n println(0)\n else {\n val possibleCutsArray = possibleCuts.toIntArray()\n possibleCutsArray.sort()\n var ans = 0\n var sum = 0\n for (cost in possibleCutsArray)\n if (sum + cost <= b) {\n sum += cost\n ans++\n }\n println(ans)\n }\n }\n}\n\nfun main() {\n val (n, b) = readInts()\n val a = readInts()\n val solution = Solution(n, b, a)\n solution.solve()\n}\n", "lang_cluster": "Kotlin", "tags": ["sortings", "dp", "greedy"], "code_uid": "aab4882b64b4c291dbc95fec1c2af40a", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\n\nfun main() {\n val br = System.`in`.bufferedReader()\n val sb = StringBuilder()\n val t = br.readInt()\n repeat(t) {\n val n = br.readInt()\n var i = 2\n var found = false\n while (i * i <= n) {\n if (n % i == 0) {\n found = true\n sb.append(n / i).append(' ').append(n - (n / i)).append('\\n')\n break\n }\n i++\n }\n if (!found) {\n sb.append(1).append(' ').append(n - 1).append('\\n')\n }\n }\n print(sb)\n}\n\nprivate const val SPACE_INT = ' '.toInt()\nprivate const val ZERO_INT = '0'.toInt()\nprivate const val NL_INT = '\\n'.toInt()\n\nprivate fun BufferedReader.readInt(): Int {\n var ret = read()\n while (ret <= SPACE_INT) {\n ret = read()\n }\n val neg = ret == '-'.toInt()\n if (neg) {\n ret = read()\n }\n ret -= ZERO_INT\n var read = read()\n while (read >= ZERO_INT) {\n ret *= 10\n ret += read - ZERO_INT\n read = read()\n }\n\n while (read <= SPACE_INT && read != -1 && read != NL_INT) {\n mark(1)\n read = read()\n }\n if (read > SPACE_INT) {\n reset()\n }\n return if (neg) -ret else ret\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "number theory"], "code_uid": "842de40d85c641fc4d49b0baa3823678", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5", "difficulty": 1300.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 mat = nextStrings(10)\n (0..9).forEach { r ->\n (0..9).forEach { c ->\n val ok = c + 5 <= 10 && checkSeq(CharArray(5) { mat[r][c + it] }) ||\n r + 5 <= 10 && checkSeq(CharArray(5) { mat[r + it][c] }) ||\n r + 5 <= 10 && c + 5 <= 10 && (\n checkSeq(CharArray(5) { mat[r + it][c + it] }) ||\n checkSeq(CharArray(5) { mat[r + it][c + 4 - it] })\n )\n if (ok) {\n println(\"YES\")\n return\n }\n }\n }\n println(\"NO\")\n}\n\nfun checkSeq(substring: CharArray): Boolean {\n val c = substring.count { it == 'X' }\n return c == 4 && substring.any { it == '.' }\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 nextStrings(n: Int) = Array(n) { nextString() ?: \"\" }\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": "4e634c4302d68a383500fedc398f0149", "src_uid": "d5541028a2753c758322c440bdbf9ec6", "difficulty": 1600.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 a = s[0]\n var b = s[1]\n var f = s[2]\n var k = s[3]\n var g = b\n var ans = 0\n for(i in 1..k){\n if(i % 2 == 1){\n if(g < f){\n print(-1)\n exitProcess(0)\n }\n g -= f\n if(g < a - f){\n ans += 1\n g = b\n }\n if(g < a - f){\n print(-1)\n exitProcess(0)\n }\n if(i == k)break\n if(g < 2 * (a - f)){\n ans += 1\n g = b\n }\n g -= a - f\n }\n else{\n if(g < a - f){\n print(-1)\n exitProcess(0)\n }\n g -= a - f\n if(g < f){\n ans += 1\n g = b\n }\n if(g < f){\n print(-1)\n exitProcess(0)\n }\n if(i == k)break\n if(g < 2 * f){\n ans += 1\n g = b\n }\n g -= f\n }\n }\n print(ans)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "090f24c37e6bcc04b36b918cdb63e566", "src_uid": "283aff24320c6518e8518d4b045e1eca", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val a = readLine()!!\n val b = readLine()!!\n println(a.zip(b).map { (i, j) -> if (i==j) '0' else '1'}.joinToString(separator = \"\"))\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4a7b083a621215eb1a0f7af94c97c96f", "src_uid": "3714b7596a6b48ca5b7a346f60d90549", "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, k) = r.readLine()!!.split(\" \").map { it.toInt() }\n var step = 0\n var gabage = 0\n while (n > 0 || gabage >= k) {\n step += n\n gabage += n\n n = gabage / k\n gabage = gabage % k\n }\n println(step)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "65cf44d956e97c3c1ee9928db115b2cb", "src_uid": "a349094584d3fdc6b61e39bffe96dece", "difficulty": 1000.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 groups = HashMap>()\n for((i, num) in curr.entries) {\n F[i].pollLast()?.also { f -> groups.getOrPut(f) { HashBag() }.add(i, num) }\n }\n for((_, group) in groups.entries) {\n val num = group.size\n if(num > n/2) {\n ans -= num - (n - num)\n curr = group\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": "059a4dff5ff9e9c83ab4cb55f5d66319", "src_uid": "40002052843ca0357dbd3158b16d59f4", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(){\nvar d:Int\nd=0\n var a = Array(101){0}\n var x=readLine()!!.split(' ').map(String::toInt)\n for(i in 0..4){\n a[x[i]]++;\n d+=x[i]\n }\n var c:Int\n c=d\n for(i in 1..100){\n if(a[i]>=3){\n if((d-3*i) 4) {\n f = true\n }\n cnt = 0\n }\n }\n if(cnt > 4) {\n f = true\n }\n }\n }\n if(f == true) {\n println(\"yes\")\n }else{\n println(\"no\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "c74c5d802218b6cc4e63651c91777cd3", "src_uid": "12d451eb1b401a8f426287c4c6909e4b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val s = readLine()!!\n var count = 0\n var pos = 0\n for (c in \"hello\") {\n while (pos < s.length) {\n if (c == s[pos]) {\n count++\n pos++\n break\n }\n pos++\n }\n }\n println(if (count == 5) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "strings"], "code_uid": "05a02ca384e3d639a3e7a45a5ef97bcf", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\n// `.-o-$:)//\n\nfun mult(x:Long):Long\n{\n if (x<10)\n {\n return maxOf(x,1)\n }\n return maxOf(x%10*mult(x/10),9*mult(x/10-1))\n}\nfun main()\n{\n var x= readLine()!!.toLong()\n println(mult(x))\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "173eec1c72f721f49d4178a37fc8ca8d", "src_uid": "38690bd32e7d0b314f701f138ce19dfb", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val NStr = readLine()!!\n val digits = NStr.length\n val results = ArrayList(digits)\n\n for (i in 0..digits-1) {\n val beginning = NStr.take(i)\n val ending = NStr.takeLast(digits-i).toLong()\n val newEnding = (ending / Math.pow(10.0, digits-i - 1.0).toLong() - 1) * Math.pow(10.0, digits-i - 1.0).toLong() +\n (digits-i.toLong() - 2 downTo 0).sumByLong { 9 * Math.pow(10.0, it.toDouble()).toLong() }\n if (newEnding<0) continue\n results.add(\"$beginning$newEnding\".toLong())\n }\n\n results.add(NStr.toLong())\n val maxSum = results.maxBy(Long::getSum)!!.getSum()\n val output = results.filter { it.getSum() == maxSum}.max()\n\n println(output)\n}\n\nfun Long.getSum(): Long {\n var sum = 0L\n var remainder = this\n while (remainder != 0L) {\n sum += remainder % 10\n remainder /= 10\n }\n return sum\n}\n\ninline fun Iterable.sumByLong(selector: (T) -> Long): Long {\n var sum: Long = 0L\n for (element in this) {\n sum += selector(element)\n }\n return sum\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "9032e5bd0865818d157fc5df7c305dfc", "src_uid": "e55b0debbf33c266091e6634494356b8", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val a = readLine()!!.split(\" \").map(String::toInt).sorted()\n println(a[2] - a[0])\n}", "lang_cluster": "Kotlin", "tags": ["math", "sortings", "implementation"], "code_uid": "b6f8a0fc15adb551e8a6de881661bf1e", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.InputStreamReader\nimport java.lang.Math.pow\nimport kotlin.math.abs\n\nfun main(args: Array) {\n val scanner = java.util.Scanner(InputStreamReader(System.`in`))\n val n: Double = scanner.nextDouble(); val m: Long = scanner.nextLong()\n\n var x = abs(m);\n val sqrt = x % (pow(2.0, n))\n println(sqrt.toInt())\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "32cca1bddc8be0e5f34fdd9873e9be72", "src_uid": "c649052b549126e600691931b512022f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun DataReader.solve(out: PrintWriter) {\n val n = nextInt()\n val next = readIntArray(n).map { it - 1 }\n val cycles = mutableListOf()\n\n val visited = BooleanArray(n)\n\n for (i in 0 until n) {\n if (visited[i]) continue\n var k = next[i]\n var l = 1\n while (k != i && !visited[k]) {\n visited[k] = true\n k = next[k]\n l++\n }\n\n if (k != i) {\n out.println(-1)\n return\n }\n\n val q = if (l % 2 == 0) l / 2 else l\n cycles.add(q.toLong())\n }\n\n out.println(cycles.fold(1L, ::lcm))\n}\n\nfun lcm(x: Long, y: Long) = x * y / gcd(x, y)\n\ntailrec fun gcd(x: Long, y: Long): Long {\n if (x == 0L || y == 0L) return x + y\n\n return if (x > y) gcd(x % y, y) else gcd(y % x, x)\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": ["dfs and similar", "math"], "code_uid": "7220f8a7e3e752e6ec2c173f8d6e51d3", "src_uid": "149221131a978298ac56b58438df46c9", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n //val data = System.`in`.bufferedReader().readLines().joinToString(\" \").split(\" \").iterator()\n val s = \"AEIOUY\"\n val t = readLine()!!.toCharArray()\n var i = t.size - 1\n while (t[i] == '?' || t[i] == ' ') {\n i--\n }\n println(if (s.contains(t[i].toUpperCase())) \"YES\" else \"NO\")\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a362cd8adcf71ee39565b53bd3518ae7", "src_uid": "dea7eb04e086a4c1b3924eff255b9648", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (n: Int, m: Int, k: Int) = readLine()!!.split(' ').map(String::toInt)\n\n if (m < n || k < n) {\n print(\"No\")\n } else {\n print(\"Yes\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "3dac4538c163360dcf75c0fe41467e3c", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "import java.io.BufferedReader\r\nimport java.io.PrintWriter\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\nfun main() {\r\n repeat(bin.readInt()) {\r\n val x = bin.readInt()\r\n val xs = bin.readInts()\r\n val opened = open(x, xs)\r\n println(if (opened.size == 3) \"YES\" else \"NO\")\r\n }\r\n}\r\n\r\nfun open(x: Int, xs: IntArray): Set {\r\n return if (x == 0) emptySet() else setOf(x) + open(xs[x-1], xs)\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation", "math"], "code_uid": "fcf717961bdd89720cfa34fea718ce2c", "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 (numRows, numCols, numViolas, minimumViolas) = readInts()\n val grid = Array(numRows) { BooleanArray(numCols) }\n repeat(numViolas) {\n val (row, col) = readInts()\n grid[row - 1][col - 1] = true\n }\n var sol = 0\n for (rowStart in 0 until numRows)\n for (rowEnd in 0 until numRows)\n for (colStart in 0 until numCols)\n for (colEnd in 0 until numCols) {\n var sum = 0\n for (row in rowStart..rowEnd)\n for (col in colStart..colEnd)\n if (grid[row][col]) sum++\n if (sum >= minimumViolas) sol++\n }\n print(sol)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "d80328715ae482fb2fb2d59aa4631b0c", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nvar arr = intArrayOf()\nfun sieve(n:Int)\n{\n var primes = Array(n+1, {i -> true})\n var p = 2\n while (p*p <= n)\n {\n for (i in p*p..n step p)\n primes[i] = false\n p++\n }\n\n for (i in 2..n)\n {\n if(primes[i])\n arr+=i\n }\n}\nval reader = Scanner(System.`in`)\nfun main(args: Array) {\n sieve(55)\n val n = reader.nextInt()\n val m = reader.nextInt()\n\n if (arr.indexOf(m) - arr.indexOf(n) == 1 )\n println(\"YES\")\n else\n println(\"NO\")\n\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "4cf28d418f7bd4395d32ba2814f0e3b9", "src_uid": "9d52ff51d747bb59aa463b6358258865", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toLong()\n if((n % 2).toLong() == 0.toLong())\n print(2)\n else\n print(1)\n }", "lang_cluster": "Kotlin", "tags": ["math", "games"], "code_uid": "c503afb9219b50f2eede84e0b39b644d", "src_uid": "816ec4cd9736f3113333ef05405b8e81", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package codeforces\n\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\n\n\nfun main() {\n val In = BufferedReader(InputStreamReader(System.`in`))\n var n = In.readLine()!!.toInt()\n var res :Int = 0\n while (n != 0) {\n if(n and 1 != 0) res +=1\n n = n shr 1\n }\n print(res)\n\n}", "lang_cluster": "Kotlin", "tags": ["bitmasks"], "code_uid": "2a41ac40045d260c979f8df4aeca03e5", "src_uid": "03e4482d53a059134676f431be4c16d2", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//Remove duplicates\n//https://codeforces.com/problemset/problem/978/A\n\nfun readInts() = readLine()!!.split(' ').map { it.toInt() }\n\nfun main(){\n val n = readInts()\n var s = readInts()\n var lst : MutableMap = mutableMapOf()\n\n s.forEachIndexed{ index, value -> (\n lst.put(value, index)\n )}\n println(lst.size)\n s.forEachIndexed{ index, value -> (\n if(lst.get(value) == index){\n print(\"$value \")\n }\n )}\n println()\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "1fd568bd752ff5fcd6aca5c4426273bc", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var n = readLine()!!.toInt() + 1\n val total = readLine()!!.split(\" \").map{ it.toInt() }.reduce{ sum, e -> sum + e }\n var count = 0\n for(i in 1..5) {\n if((i + total) % n != 1)\n count++\n }\n println(count)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "3eeed671f58ad5ce92185f0931b8c51a", "src_uid": "ff6b3fd358c758324c19a26283ab96a4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * http://codeforces.com/problemset/problem/811/A\n * @{tags: brute force, implementation}\n *\n * Created by vashzhong on 2017/5/30.\n */\n\nclass Solution_811A {\n fun solve(vladik: Long, valera: Long) {\n var firstGive = 1L\n val candies = arrayListOf(vladik, valera)\n var index = 0\n\n while (candies[index] >= firstGive) {\n candies[index] -= firstGive\n firstGive++\n when (index) {\n 0 -> index = 1\n 1 -> index = 0\n else -> throw IllegalStateException(\"Error State\")\n }\n }\n\n val result = when (index) {\n 0 -> \"Vladik\"\n 1 -> \"Valera\"\n else -> throw IllegalStateException(\"Error State\")\n }\n\n println(result)\n }\n}\n\nfun main(args: Array) {\n val (a, b) = readLine()!!.split(\" \").map { x -> x.toLong() }\n Solution_811A().solve(a, b)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "d214de6c123fffe9c94734741b9373c4", "src_uid": "87e37a82be7e39e433060fd8cdb03270", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// https://codeforces.com/problemset/problem/38/B Chess train\nimport kotlin.math.*;\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nenum class FigType {\n ROOK, KNIGHT\n}\n\nfun chessFromString(s : String, type:FigType):ChessPos {\n val xx = (s[0] - 'a').toInt()\n val yy = (s[1]+\"\").toInt() - 1\n return ChessPos(xx,yy,type)\n}\n\n/** chess position as two ints from 0 */\nclass ChessPos(val x:Int, val y:Int, val type : FigType) {\n\n fun beats(o:ChessPos) : Boolean {\n var b : Boolean\n if (type == FigType.KNIGHT) {\n b = ((abs(x - o.x) == 1) && (abs(y - o.y) == 2))\n b = b || (abs(x - o.x) == 2 && Math.abs(y - o.y) == 1)\n } else {\n b = x == o.x\n b = b || (y == o.y)\n }\n return b\n }\n\n fun equals(o:ChessPos) : Boolean {\n val b = (x == o.x) && (y == o.y)\n return b\n }\n}\n\nfun main() {\n var numWays = 0\n val rook = chessFromString(readLn(), FigType.ROOK)\n val knight = chessFromString(readLn(), FigType.KNIGHT)\n for (x in 0..7) {\n for (y in 0..7) {\n val f = ChessPos(x,y,FigType.KNIGHT)\n if (f.equals(rook) || f.equals(knight)) {\n continue\n }\n if (rook.beats(f) || knight.beats(f) || f.beats(rook)) {\n continue\n } else {\n numWays++\n }\n }\n }\n println(numWays)\n}\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "ad4547603852b0e6662cb48a463f9666", "src_uid": "073023c6b72ce923df2afd6130719cfc", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(arg: Array){\n\tval x = readLine()!!.toLong()\n\tval winner = if (x.rem(2L) == 0L) \"Mahmoud\" else \"Ehab\"\n\tprintln(winner)\n}", "lang_cluster": "Kotlin", "tags": ["math", "games"], "code_uid": "f9f30b2b53ff8354029ec1fc6071c94e", "src_uid": "5e74750f44142624e6da41d4b35beb9a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "const val MOD = 1000000007L\nconst val LIMIT = 500000\n\nfun main() {\n val factorial = LongArray(LIMIT + 1)\n factorial[0] = 1L\n for (j in 1..LIMIT) {\n factorial[j] = (j.toLong() * factorial[j - 1]) % MOD\n }\n val factInv = LongArray(LIMIT + 1) { factorial[it] pow -1 }\n fun choose(a: Int, b: Int) = if (a < 0 || b < 0 || b > a) 0L else (factorial[a] * ((factInv[b] * factInv[a - b]) % MOD)) % MOD\n val (a, b, k, t) = readLine()!!.split(\" \").map { it.toInt() }\n var answer = 0L\n for (lambda in 0..2 * t) {\n answer += (if (lambda % 2 == 0) 1L else -1L) * choose(2 * t, lambda) * (\n choose((4 * t * k) - (((2 * k) + 1) * lambda) + (2 * t), 2 * t) - choose((2 * t * k) + b - a - (((2 * k) + 1) * lambda) + (2 * t), 2 * t))\n answer %= MOD\n }\n answer += MOD\n answer %= MOD\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"], "code_uid": "dbf0fd56f27c233b0599acdbc2ef87e0", "src_uid": "8b8327512a318a5b5afd531ff7223bd0", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nvar cin = Scanner(System.`in`)\nval NO = \"NO\"\nval YES = \"YES\"\nfun main(args: Array) {\n var B = Array(4, {Array(4, {i -> cin.nextInt()})})\n\n var solve = fun(): String {\n for(i in 0..3) if(B[i][3] == 1) {\n for(j in 0..2) if(B[i][j] == 1) return YES\n if(B[(i+1)%4][0] == 1) return YES\n if(B[(i+2)%4][1] == 1) return YES\n if(B[(i+3)%4][2] == 1) return YES\n }\n return NO\n }\n println(solve())\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a286d738d776e4aa8a83dcf114b69314", "src_uid": "44fdf71d56bef949ec83f00d17c29127", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun min_2(a : Int, b : Int) : Int {\n return if (a < b) {\n a\n } else {\n b\n }\n}\n\nfun max_2(a : Int, b : Int) : Int {\n return if (a > b) {\n a\n } else {\n b\n }\n}\n\nfun main(args : Array) {\n val scanner = Scanner(System.`in`)\n val a = scanner.nextInt()\n val b = scanner.nextInt()\n val max_ab = max_2(a, b)\n val min_ab = min_2(a, b)\n val result_1 = min_ab \n val result_2 = (max_ab - min_ab) / 2\n println(\"${result_1} ${result_2}\")\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "78441a7c54270f0f1c74124457dd66dd", "src_uid": "775766790e91e539c1cfaa5030e5b955", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.*\n\nfun main() {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val writer = BufferedWriter(OutputStreamWriter(System.out))\n\n val t = reader.readLine().toInt()\n\n for (ts in 1..t) {\n var v = reader.readLine().toInt()\n val a = v % 10 - 1\n var b = 0\n val cc = intArrayOf(1,3,6,10)\n while (v > 0) {\n b++\n v /= 10\n }\n writer.write(\"${10*a+cc[b-1]}\\n\")\n }\n \n writer.flush()\n reader.close()\n writer.close()\n return\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "bfdfcdf848e23ddea34c6d91de4252c6", "src_uid": "289a55128be89bb86a002d218d31b57f", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n/**\n * Created by thuanle on 7/13/17.\n */\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextInt()\n var old = 0\n var step = 0\n repeat(n, {\n val x = sc.nextInt()\n when {\n old < x -> {\n if (step > 0) {\n println(\"NO\")\n return\n }\n }\n old == x -> {\n when (step) {\n 0 -> step = 1\n 2 -> {\n println(\"NO\")\n return\n }\n }\n }\n old > x -> {\n step = 2\n }\n }\n old = x\n })\n println(\"YES\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2527b088997232ea91ffbf28db7d9d3f", "src_uid": "5482ed8ad02ac32d28c3888299bf3658", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "fun solve() {\r\n val n = readln().toDouble()\r\n val squareRootN = Math.sqrt(n).toInt()\r\n val cubeRootN = Math.cbrt(n).toInt()\r\n val set = mutableSetOf()\r\n\r\n for (i in 1..squareRootN) set.add(i * i)\r\n for (i in 1..cubeRootN) set.add(i * i * i)\r\n\r\n println(set.size)\r\n}\r\n\r\nfun readN() = readln().toInt()\r\n\r\nfun main() = repeat(readN()) { solve() }", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "66382197840b7f1bf23464915807616a", "src_uid": "015afbefe1514a0e18fcb9286c7b6624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val sc = Scanner(System.`in`)\n val sf = sc.nextLong()\n var vc = 0L\n vc = if(sf % 2L == 0L) sf / 2 else ((sf - 1) / 2 ) - sf\n println(vc)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "f8b70606f88034145beb5debfbe8b516", "src_uid": "689e7876048ee4eb7479e838c981f068", "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\n val ans = fibonacci(n) * ModInt(2).pow(-n)\n\n println(ans)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nfun fibonacci(n: Long): ModInt {\n var a = ModInt(0)\n var b = ModInt(1)\n var c = ModInt(0)\n var d = ModInt(1)\n\n var e = n\n while(e > 0) {\n if(e and 1 == 1L) {\n a = (a * c + b * d).also {\n b = a * d + b * (c + d)\n }\n }\n e = e shr 1\n c = (c * c + d * d).also {\n d *= c + c + d\n }\n }\n\n return a\n}\ninline fun fibonacci(n: Int) = fibonacci(n.toLong())\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 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 ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n//const val PATH = \"src/main/resources/\"\n//@JvmField val INPUT = File(PATH + \"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(PATH + \"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\nconst val _BUFFER_SIZE = 1 shl 16\n@JvmField val _buffer = ByteArray(_BUFFER_SIZE)\n@JvmField var _bufferPt = 0\n@JvmField var _bytesRead = 0\n\ntailrec fun readChar(): Char {\n if(_bufferPt == _bytesRead) {\n _bufferPt = 0\n _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)\n }\n return if(_bytesRead < 0) Char.MIN_VALUE\n else {\n val c = _buffer[_bufferPt++].toChar()\n if (c == '\\r') readChar() else c\n }\n}\n\n/** @param skipNext Whether to skip the next character (usually whitespace), defaults to true */\nfun readCharArray(n: Int, skipNext: Boolean = true): CharArray {\n val res = CharArray(n) { readChar() }\n if(skipNext) readChar()\n return res\n}\n\nfun readLine(): String? {\n var c = readChar()\n return if(c == Char.MIN_VALUE) null\n else buildString {\n while(c != '\\n' && c != Char.MIN_VALUE) {\n append(c)\n c = readChar()\n }\n }\n}\nfun readLn() = readLine()!!\n\nfun read() = buildString {\n var c = readChar()\n while(c <= ' ') {\n if(c == Char.MIN_VALUE) return@buildString\n c = readChar()\n }\n do {\n append(c)\n c = readChar()\n } while(c > ' ')\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** sort overrides to avoid quicksort attacks */\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\ninline fun _mergeSort(a0: A, n: Int, tmp0: A, get: A.(Int) -> T, set: A.(Int, T) -> Unit, cmp: (T, T) -> Int) {\n var a = a0\n var tmp = tmp0\n var len = 1\n while(len < n) {\n var l = 0\n while(true) {\n val m = l + len\n if(m >= n) break\n val r = min(n, m + len)\n var i = l\n var j = m\n for(k in l until r) {\n if(i != m && (j == r || cmp(a.get(i), a.get(j)) <= 0)) {\n tmp.set(k, a.get(i++))\n } else tmp.set(k, a.get(j++))\n }\n l = r\n }\n for(i in l until n) tmp.set(i, a.get(i))\n val t = a; a = tmp; tmp = t\n len += len\n }\n if(a !== a0) for(i in 0 until n) a0.set(i, tmp0.get(i))\n}\n\ninline fun IntArray.sortWith(cmp: (Int, Int) -> Int) { _mergeSort(this, size, IntArray(size), IntArray::get, IntArray::set, cmp) }\ninline fun > IntArray.sortBy(func: (Int) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > IntArray.sortByDescending(func: (Int) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun IntArray.sort() { sortBy { it } }\nfun IntArray.sortDescending() { sortByDescending { it } }\n\ninline fun LongArray.sortWith(cmp: (Long, Long) -> Int) { _mergeSort(this, size, LongArray(size), LongArray::get, LongArray::set, cmp) }\ninline fun > LongArray.sortBy(func: (Long) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > LongArray.sortByDescending(func: (Long) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun LongArray.sort() { sortBy { it } }\nfun LongArray.sortDescending() { sortByDescending { it } }\n\ninline fun DoubleArray.sortWith(cmp: (Double, Double) -> Int) { _mergeSort(this, size, DoubleArray(size), DoubleArray::get, DoubleArray::set, cmp) }\ninline fun > DoubleArray.sortBy(func: (Double) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > DoubleArray.sortByDescending(func: (Double) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun DoubleArray.sort() { sortBy { it } }\nfun DoubleArray.sortDescending() { sortByDescending { it } }\n\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\n// import preserving junk function\n@Suppress(\"NonAsciiCharacters\") fun 雪花飄飄北風嘯嘯天地一片蒼茫() { iprintln(max(1, 2)) }\n\nfun IntArray.sumLong() = sumOf { it.toLong() }\n\nfun IntArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun IntArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun LongArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun LongArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun DoubleArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun DoubleArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun > Array.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun > Array.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\nfun > List.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }\nfun > List.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }\n\n// max/min Kotlin 1.6 -> 1.4 shim\nfun IntArray.max() = maxOf { it }\nfun IntArray.min() = minOf { it }\nfun LongArray.max() = maxOf { it }\nfun LongArray.min() = minOf { it }\nfun CharArray.max() = maxOf { it }\nfun CharArray.min() = minOf { it }\nfun > Iterable.max() = maxOf { it }\nfun > Iterable.min() = minOf { it }\nfun > Sequence.max() = maxOf { it }\nfun > Sequence.min() = minOf { it }", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "06bd15076a21b347160868ac8620e1d9", "src_uid": "cec37432956bb0a1ce62a0188fe2d805", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(){\n val n = readLine()!!.toInt()\n val k = 2*n-1\n var sum = k\n for (i in 1 until k step 2){\n sum+=2*i\n }\n println(sum)\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "implementation"], "code_uid": "0b8b59abc0b1006019f1a41c033846d6", "src_uid": "758d342c1badde6d0b4db81285be780c", "difficulty": 800.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)\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\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": "193ce720867dc4611e31013863159a31", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "private fun readChar(): Char = readString()[0]\r\nprivate fun readChars(): CharArray = readString().toCharArray()\r\nprivate fun readInt(): Int = readLine()!!.toInt()\r\nprivate fun readInts(): List = readLine()!!.trim().split(\" \").map(String::toInt)\r\nprivate fun readLong(): Long = readLine()!!.toLong()\r\nprivate fun readLongs(): List = readLine()!!.trim().split(\" \").map(String::toLong)\r\nprivate fun readString(): String = readLine()!!.trim()\r\nprivate fun readStrings() : List = readLine()!!.trim().split(\" \")\r\n\r\nfun main() {\r\n\tval T = readInt()\r\n\tval MOD = 1000000007L\r\n\r\n\tnextTest@for (t in 0 until T) {\r\n\t\tval (n, k) = readLongs()\r\n\r\n\t\t// answer is n^k\r\n\t\tvar result = 1L\r\n\t\tfor (e in 0 until k) {\r\n\t\t\tresult = (result * n) % MOD\r\n\t\t}\r\n\r\n\t\tprintln(result)\r\n\t}\r\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics", "bitmasks"], "code_uid": "28ecd6327c68b139b0df5cad045f09d1", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nvar n: Int = 0\nvar lights = emptyList()\n\n\nvar save = Array(102) { Array(102) { Array(102) { IntArray(2) { -1 } } } }\nfun dp(index: Int, odd: Int, even: Int, isOdd: Boolean): Int {\n if (index >= lights.size) {\n return 0\n }\n val oddIndex: Int = if (isOdd) 0 else 1\n if (save[index][odd][even][oddIndex] != -1) return save[index][odd][even][oddIndex]\n var min = Int.MAX_VALUE\n if (lights[index] == 0) {\n if (odd > 0) {\n min = Math.min(min, getCom(isOdd, true) + dp(index + 1, odd - 1, even, true))\n }\n if (even > 0) {\n min = Math.min(min, getCom(isOdd, false) + dp(index + 1, odd, even - 1, false))\n }\n } else {\n val curIsOdd = (lights[index] % 2) != 0\n min = getCom(isOdd, curIsOdd) + dp(index + 1, odd, even, curIsOdd)\n }\n save[index][odd][even][oddIndex] = min\n return min\n}\n\nfun getCom(odd: Boolean, odd2: Boolean): Int {\n return if (odd == odd2) {\n 0\n } else {\n 1\n }\n}\n\n\nfun main(args: Array) {\n n = readLine()!!.toInt()\n lights = readLine()!!.split(' ').map { it.toInt() }\n var odd = (n + 1) / 2\n var even = n / 2\n lights.forEach {\n if (it != 0) {\n if(it%2==0)even--\n else odd --\n }\n }\n val ans = Math.min(\n dp(0,odd, even, true),\n dp(0,odd, even, false)\n )\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "dp", "greedy"], "code_uid": "3c6fef69f03a3c0299060e0c4ba5b92b", "src_uid": "90db6b6548512acfc3da162144169dba", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n var Direction: String = input.next()\n var Word: String = input.next()\n var lettList = ArrayList()\n\n val keyboard = \"qwertyuiop[]asdfghjkl;'zxcvbnm,./\"\n\n for(letter in Word.indices) {\n for (checker in keyboard.indices) {\n if(Word.get(letter) == keyboard.get(checker)) {\n if(Direction.equals(\"R\")) {\n lettList.add(keyboard.get(checker-1))\n } else {\n lettList.add(keyboard.get(checker+1))\n }\n }\n }\n }\n\n var Res: String = lettList.joinToString(\"\")\n println(Res)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4b981d4f91e165908c0b4af62d546cbf", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!.toInt()\n val r = readLine()!!.split(\" \").map { it.toInt() }\n val b = readLine()!!.split(\" \").map { it.toInt() }\n var rWins = 0\n var bWins = 0\n for (i in 0 until n) {\n if (r[i] == 1 && b[i] == 0)\n ++rWins\n if (r[i] == 0 && b[i] == 1)\n ++bWins\n }\n if (rWins <= 0) {\n println(-1)\n return\n }\n\n if (bWins == 0) {\n println(1)\n return\n }\n\n println(bWins / rWins + 1)\n}\n\n", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "a914a553c8b6a7a8f496a030c8f44e81", "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07", "difficulty": 900.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 a = readInts()\n \n var cnt : Int = 0\n \n for (i in 0..n - 1) {\n if (a[i] > k) break\n else ++cnt\n }\n \n if (cnt == n) {\n println(cnt)\n return\n }\n \n for (i in n - 1 downTo 0) {\n if (a[i] > k) break\n else ++cnt\n }\n \n println(cnt)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "3dfd44ca65f3224069b2de9271135222", "src_uid": "ecf0ead308d8a581dd233160a7e38173", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var (a, b, x, y) = readLine()!!.split(' ').map {it.toInt()}\n val g = gcd(x, y)\n x /= g; y /= g\n val k = minOf(a / x, b / y)\n println(\"%d %d\".format(x * k, y * k))\n}\n\nfun gcd(x: Int, y: Int): Int = if (y == 0) x else gcd(y, x % y)\n", "lang_cluster": "Kotlin", "tags": ["binary search", "number theory"], "code_uid": "1a216c5e4e59003dc6bd5ca1683db257", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n\nfun main (args:Array)\n{\n var a:Int= readLine()!!.toInt()\n var b: Int= readLine()!!.toInt()\n var c:Int= readLine()!!.toInt()\n var Max:Int=0\n if(a+b*c>Max)\n Max=a+b*c\n if(a*(b+c)>Max)\n Max=a*(b+c)\n if((a*b*c)>Max)\n Max=(a*b*c)\n if((a+b)*c>Max)\n Max=(a+b)*c\n if(a+b+c>Max)\n Max=a+b+c\nSystem.out.println(Max)\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "b2ff32074f862f555ec102ffb12240c2", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27", "difficulty": 1000.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=readInt()\n var a=Array(n){Array(n){1L}}\n for(i in 1 until n){\n for(j in 1 until n){\n a[i][j]=a[i-1][j]+a[i][j-1]\n }\n }\n printLine(\"${a[n-1][n-1]}\")\n output()\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "f714053c72837f9e8deb631a0d305079", "src_uid": "2f650aae9dfeb02533149ced402b60dc", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.io.*\nimport java.util.*\n\nfun solve() {\n\n val n = nextInt()\n var s = next()\n\n for (d in 2..n) {\n if (n % d == 0) {\n val t = s.substring(0, d).reversed()\n s = s.replaceRange(0, d, t)\n }\n }\n\n print(s)\n}\n\n\n\n\nfun hasNext() : Boolean {\n while (!st.hasMoreTokens()) {\n st = StringTokenizer(input.readLine() ?: return false)\n }\n return true\n}\n\nfun next() = if (hasNext()) st.nextToken()!! else throw RuntimeException(\"No tokens\")\n\nfun nextInt() = next().toInt()\n\nfun nextLong() = next().toLong()\n\nfun nextDouble() = next().toDouble()\n\nfun nextLine() = if (hasNext()) st.nextToken(\"\\n\")!! else throw RuntimeException(\"No tokens\")\n\nfun nextArray(n : Int) = IntArray(n, { nextInt() })\n\nval ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n\nvar input = when(ONLINE_JUDGE) {\n true -> BufferedReader(InputStreamReader(System.`in`), 32768)\n else -> BufferedReader(FileReader(\"in.txt\"))\n}\n\nvar output = when(ONLINE_JUDGE) {\n true -> PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))\n else -> PrintWriter(BufferedWriter(FileWriter(\"out.txt\")))\n}\n\nvar st = StringTokenizer(\"\")\n\nfun main(args: Array) {\n val start = System.currentTimeMillis()\n solve()\n\n output.close()\n input.close()\n\n if (!ONLINE_JUDGE) {\n System.err.println(\"${System.currentTimeMillis() - start} ms\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "b607ecc3e3f4cbe3988182b440f28a5f", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package codeforces.greedyAlgorithm\n\nimport java.math.BigDecimal\nimport java.util.function.Consumer\n\nfun main() {\n val (peopleNumber, teamsNumber) = readLine()!!.split(\" \").map { it.toInt() }\n\n countMinMaxNumbers(\n peopleNumber,\n teamsNumber,\n minVal = { value -> print(\"$value \") },\n maxVal = { value -> print(\"$value\") }\n )\n}\n\nfun countMinMaxNumbers(peopleNumber: Int, teamsNumber: Int, minVal: Consumer, maxVal: Consumer) {\n val minTeam = (peopleNumber / teamsNumber).toBigDecimal()\n val remains = (peopleNumber % teamsNumber).toBigDecimal()\n val teams = teamsNumber.toBigDecimal()\n val people = peopleNumber.toBigDecimal()\n\n if (remains == 0.toBigDecimal()) {\n val pairCount = minTeam.getPairCombNumb()\n val pairSum = pairCount * teams\n\n minVal.accept(pairSum)\n } else {\n val sumWithRem = remains * (minTeam + 1.toBigDecimal()).getPairCombNumb()\n val sumOfMain = (teams - remains) * minTeam.getPairCombNumb()\n val totalSum = sumWithRem + sumOfMain\n\n minVal.accept(totalSum)\n }\n\n val maxTeam = people - (teams - 1.toBigDecimal())\n maxVal.accept(maxTeam.getPairCombNumb())\n}\n\nfun BigDecimal.getPairCombNumb() = (this * (this - 1.toBigDecimal())) / 2.toBigDecimal()", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms", "combinatorics"], "code_uid": "7af9e4c3e70c849feeeb605c8f0abcb6", "src_uid": "a081d400a5ce22899b91df38ba98eecc", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/* http://codeforces.com/problemset/problem/1173/A */\n\nfun main() {\n val (x, y, z) = readLine()!!.split(\" \").map { it.toInt() }\n if (x + z == y && y + z == x) {\n println(\"0\")\n } else if (x + z < y) {\n println(\"-\")\n } else if (x > y + z) {\n println(\"+\")\n } else {\n println(\"?\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "a1ad78aa2b08b0f431767828c0c97d52", "src_uid": "66398694a4a142b4a4e709d059aca0fa", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "val debug = false\n\nfun readInt() = readLine()!!.toInt()\nfun readInts() = readLine()!!.split(' ').map { it.toInt() }\n\nfun main() {\n val t = readInt()\n for (i in 1..t) {\n val (_, k, l) = readInts()\n val ds = readInts()\n println(if (solve(k, l, ds)) \"Yes\" else \"No\")\n }\n}\n\nfun tDepth(depth: Int, i: Int, k: Int): Int = if (i <= k) depth + i else depth + k - (i - k)\n\nfun solve(k: Int, l: Int, ds: List): Boolean {\n val n = ds.size\n val w = 2*k\n var s = Array(w) { true }\n\n for (p in n-1 downTo 0) {\n val depth = ds[p]\n\n var ns = Array(w) { true }\n for (i in 0 until w) {\n ns[i] = tDepth(depth, i, k) <= l && (s[(i + 1) % w])\n }\n for (i in w-1 downTo 0) {\n ns[i] = ns[i] || (tDepth(depth, i, k) <= l && ns[(i + 1) % w])\n }\n\n s = ns\n if (debug) println(\"p=$p, s=${s.contentToString()}, depth=$depth\")\n }\n\n return s.any { it }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "dp"], "code_uid": "11da4a7531b62eca9a70a81e816efc9c", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLine()!!.split(\" \").map { it.toInt() }\n val ms = mutableMapOf()\n s.forEach { ms.merge(it, 1, Int::plus) }\n val l = ms.values.sorted()\n when {\n l.size == 1 -> print(\"Elephant\")\n l.size == 2 && l[1] == 4 -> print(\"Elephant\")\n l.size == 2 && l[1] == 5 -> print(\"Bear\")\n l.size == 3 && l[2] == 4 && l[1] == 1 -> print(\"Bear\")\n else -> print(\"Alien\")\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "3a0826e1735784b19ea84cad8605263f", "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\nclass UnionFind(n: Int) {\n private val par = IntArray(n){it}\n val rank = IntArray(n){1} // 集合の要素数\n private val visits = IntArray(n) // 訪れた場所をfind毎に用意するのがもったいないのでつかいまわす\n\n fun find(x: Int): Int {\n var ptr = 0\n var i = x\n while(par[i] != i) {\n visits[ptr++] = i\n i = par[i]\n }\n\n for (j in 0 until ptr) {\n par[visits[j]] = i\n }\n return i\n }\n\n private fun merge(node: Int, rt: Int): Int {\n par[node] = rt\n rank[rt] += rank[node]\n return rt\n }\n\n fun unite(x: Int, y: Int): Boolean {\n val x1 = find(x)\n val y1 = find(y)\n return if (x1 == y1) false\n else {\n if (rank[x1] < rank[y1])\n merge(x1, y1)\n else\n merge(y1, x1)\n\n true\n }\n }\n\n fun isRoot(x: Int) = par[x] == x\n\n /**\n * xを解決する必要がないときは直にrankをみる\n */\n fun cntNodes(x: Int): Int = rank[find(x)]\n}\nfun lowerBound(A: LongArray, s: Int, x: Long): Int {\n var l = s - 1\n var h = A.size\n while(h - l > 1) {\n val m = (h + l) / 2\n if (A[m] >= x) h = m\n else l = m\n }\n return h\n}\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val N = ni()\n var K = nl() - 1\n val INF = 1e18.toLong() + 10\n val dp = LongArray(N + 10)\n dp[0] = 1\n for (n in 1 .. N) {\n var sum = 0L\n for (i in 1 .. n) {\n if (i > 1) {\n val uf = UnionFind(i)\n for (j in 0 until i) {\n uf.unite(j, i - 1 - j)\n }\n if (uf.cntNodes(0) != i) continue\n }\n\n sum += dp[n - i]\n if (sum >= INF) sum = INF\n }\n dp[n] = sum\n }\n debug(dp)\n\n val part = mutableListOf()\n var n = N\n while(n > 0) {\n val nums = LongArray(n + 1)\n for (i in 1 .. n) {\n nums[i] = dp[n - i]\n }\n for (i in 1 .. n) {\n nums[i] += nums[i - 1]\n if (nums[i] >= INF) nums[i] = INF\n }\n\n debug(nums)\n val num = lowerBound(nums, 0, K + 1)\n debug{\"K:$K num:$num\"}\n part += num\n n -= num\n K -= nums[num - 1]\n }\n\n debug{part.joinToString(\" \")}\n val ans = mutableListOf()\n var l = 0\n for (p in part) {\n for (i in l + p downTo l + 1) {\n ans.add(i)\n }\n l += p\n }\n\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 // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl() + offset\n }\n return res\n }\n\n private fun na2(n: Int, offset: Int = 0): Array {\n val a = Array(2){IntArray(n)}\n for (i in 0 until n) {\n for (e in a) {\n e[i] = ni() + offset\n }\n }\n return a\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n private fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "math", "combinatorics", "binary search", "greedy", "implementation"], "code_uid": "017927feb73e061a8b40f1f6a55e1298", "src_uid": "e03c6d3bb8cf9119530668765691a346", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n println(Math.floor(sc.nextInt() * sc.nextInt().toDouble() / 2.0).toInt())\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "6c13fabc9a0896463389caa8d012b678", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd", "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 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 = h(n)\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 val hi = h(i)\n for(j in 0..hi) for(k in 0..min(hi, 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/4*2 + min(2, n%4)\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 雪花飄飄北風嘯嘯天地一片蒼茫() { 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": "186c8e453d4568c738355031a7150853", "src_uid": "1f012349f4b229dc98faadf1ca732355", "difficulty": 2700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun inte(n: Int): Boolean {\n var s = 0\n var m = n\n while ( m!=0 ) {\n s = s + m%10\n m = m/10\n }\n return s % 4 == 0\n}\n\nfun main() {\n var n = readLine()!!.toInt()\n while ( !inte(n) ) {\n n = n+1\n }\n println(n)\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "1566ad84014222d2ca57039e7ae314c4", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val S = readLn()\n\n val ans = run {\n var next = 'a'\n for(c in S) {\n when(c.compareTo(next)) {\n 1 -> return@run false\n 0 -> next++\n }\n }\n true\n }\n\n println(if(ans) \"YES\" else \"NO\")\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", "strings", "implementation"], "code_uid": "9f02845ba2d3fb4261ac9d253d19468d", "src_uid": "c4551f66a781b174f95865fa254ca972", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (x, y, z) = readInts()\n val (green, purple, black) = readInts()\n print(if (green >= x && green + purple - x >= y && green + purple + black >= x + y + z) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "implementation"], "code_uid": "3229f93b66eaafc7f48908e04a019026", "src_uid": "d54201591f7284da5e9ce18984439f4e", "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: Int = ir.nextInt()\n val m: Int = ir.nextInt()\n val r: Int = ir.nextInt()\n var min = Int.MAX_VALUE\n var max = 0\n var total = 0\n\n for (i in 0 until n) {\n val num = ir.nextInt()\n if (min > num)\n min = num\n }\n\n for (i in 0 until m) {\n val num = ir.nextInt()\n if (max < num)\n max = num\n }\n\n if (min < max)\n total = ((r / min) * max) + (r % min)\n else\n total = r\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", "implementation"], "code_uid": "c8624892d3807deafced37a2525176ad", "src_uid": "42f25d492bddc12d3d89d39315d63cb9", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// kotlin oj template code from uwi(Codeforces), and convert to kotlin by lety\nimport java.io.ByteArrayInputStream\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.PrintWriter\nimport java.util.Arrays\nimport java.util.InputMismatchException\nimport kotlin.math.absoluteValue\n\nlateinit var `is`: InputStream\nlateinit var out: PrintWriter\nvar INPUT = \"\"\n\n//val oj = System.getProperty(\"ONLINE_JUDGE\") != null\nval oj = true\nval inbuf = ByteArray(1024)\nvar lenbuf = 0\nvar ptrbuf = 0\n\nlateinit var cum: Array\n\nfun solve()\n{\n val n = ni()\n val s = ns()\n var r = 0\n\n for(i in 1 until n)\n {\n if( s[i] == s[i-1] )\n {\n r++\n }\n }\n\n println(r)\n}\n\n\nfun main() {\n `is` = if (oj) System.`in` else ByteArrayInputStream(INPUT.toByteArray())\n out = PrintWriter(System.out)\n\n val s = System.currentTimeMillis()\n solve()\n out.flush()\n tr((System.currentTimeMillis() - s).toString() + \"ms\")\n}\n\nprivate fun readByte(): Int {\n if (lenbuf == -1) throw InputMismatchException()\n if (ptrbuf >= lenbuf) {\n ptrbuf = 0\n try {\n lenbuf = `is`.read(inbuf)\n } catch (e: IOException) {\n throw InputMismatchException()\n }\n\n if (lenbuf <= 0) return -1\n }\n return inbuf[ptrbuf++].toInt()\n}\n\nprivate fun isSpaceChar(c: Int): Boolean = !(c >= 33 && c <= 126)\n\nprivate fun skip(): Int {\n var b: Int = readByte()\n while (b != -1 && isSpaceChar(b)) {\n b = readByte()\n }\n return b\n}\n\n// using ns()\nprivate fun nd(): Double = ns().toDouble()\n\n// using ns()\nprivate fun nc(): Char = skip().toChar()\n\n// input until whitespace\nprivate fun ns(): String {\n var b = skip()\n val sb = StringBuilder()\n while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')\n sb.appendCodePoint(b)\n b = readByte()\n }\n return sb.toString()\n}\n\nprivate fun ns(n: Int): CharArray {\n val buf = CharArray(n)\n var b = skip()\n var p = 0\n while (p < n && !isSpaceChar(b)) {\n buf[p++] = b.toChar()\n b = readByte()\n }\n return if (n == p) buf else Arrays.copyOf(buf, p)\n}\n\n// matrix\nprivate fun nm(n: Int, m: Int): Array {\n val map = Array(n) { CharArray(m) }\n for (i in 0 until n) map[i] = ns(m)\n return map\n}\n\nprivate fun pm(matrix: Array) {\n val n = matrix.size\n val m = matrix[0].size\n repeat(n)\n {\n repeat(m)\n { jt ->\n out.print(matrix[it][jt])\n }\n out.println()\n }\n out.flush()\n}\n\n// int array\nprivate fun na(n: Int): IntArray {\n val a = IntArray(n)\n for (i in 0 until n) a[i] = ni()\n return a\n}\n\nprivate fun ni(): Int {\n var num = 0\n var b: Int = readByte()\n var minus = false\n while (b != -1 && !(b >= '0'.toInt() && b <= '9'.toInt() || b == '-'.toInt())) {\n b = readByte()\n }\n if (b == '-'.toInt()) {\n minus = true\n b = readByte()\n }\n\n while (true) {\n if (b >= '0'.toInt() && b <= '9'.toInt()) {\n num = num * 10 + (b - '0'.toInt())\n } else {\n return if (minus) -num else num\n }\n b = readByte()\n }\n}\n\nprivate fun nl(): Long {\n var num: Long = 0\n var b: Int = readByte()\n var minus = false\n while (b != -1 && !(b >= '0'.toInt() && b <= '9'.toInt() || b == '-'.toInt())) {\n b = readByte()\n }\n if (b == '-'.toInt()) {\n minus = true\n b = readByte()\n }\n\n while (true) {\n if (b >= '0'.toInt() && b <= '9'.toInt()) {\n num = num * 10 + (b - '0'.toInt())\n } else {\n return if (minus) -num else num\n }\n b = readByte()\n }\n}\n\nprivate fun tr(vararg o: Any) {\n// if (!oj) println(Arrays.deepToString(o))\n}\n\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5865165eb2eb2654478a82154c7facec", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main() {\n val (numExams, requiredSum) = readLine()!!.split(\" \").map(String::toInt)\n if (requiredSum <= 2* numExams) return print(numExams)\n print(max(0, 3 * numExams - requiredSum))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "d15e129c864bba6873976115ec2d437f", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun Char.distanceTo(that: Char) =\n minOf(abs(this - that), abs((123 - maxOf(this, that).toInt()) + (minOf(this, that).toInt() - 97)))\n\nfun main() = readLine()!!.let { word ->\n var distance = word.first().distanceTo('a')\n for (i in 1 until word.length) distance += word[i].distanceTo(word[i - 1])\n distance\n}.run(::print)", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "a98867ee56be30fb2d12048660d375c2", "src_uid": "ecc890b3bdb9456441a2a265c60722dd", "difficulty": 800.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 b = readInt()\n var g = readInt()\n var n = readInt()\n var ans = 0\n for (i in 0..n){\n if (i <= b && n - i <= g) ans++\n }\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "e4aad8247740c262c4b6f18286fe0dc5", "src_uid": "9266a69e767df299569986151852e7b1", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var word: String? = readLine()\n var found=0;\n for (ch in word!!)\n {\n when(ch){\n 'H','Q','9'-> {\n found++;\n }\n }\n }\n\n if (found>0)\n println(\"YES\")\n else\n println(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7a04b3ac6baedd94bb5beab2632f2951", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun solve(ts:Long){\n var (w1,h1,w2,h2) = readLine()!!.split(\" \").map{it.toLong()};\n if(w1==w2){\n println((w1+h1+h2)*2 + 4);\n } else {\n println(w1+w2 + (h1+h2)*2 + 5 + (w1-w2-1));\n }\n}\n\nfun main(){\n var t=1L;\n //t=readLine()!!.toLong();\n for(i in 1..t) solve(i);\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "be8be52b126ece19bc07ac6d305e10fd", "src_uid": "b5d44e0041053c996938aadd1b3865f6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\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 = s.length\n var i = 0\n while (i < s.length - 1) {\n if ((s[i] == 'U' && s[i + 1] == 'R') || (s[i] == 'R' && s[i + 1] == 'U')) {\n --ans\n i += 2\n } else\n i++\n }\n \n println(ans)\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "72a490c575bd627ee0604cd25197f005", "src_uid": "986ae418ce82435badadb0bd5588f45b", "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,t)=readInts()\n var str=readLn().toCharArray()\n repeat(t){\n var sw=false\n for(i in 1 until n){\n if(!sw&&str[i]=='G'&&str[i-1]=='B'){\n sw=true\n str[i]=str[i-1].also{str[i-1]=str[i]}\n }else sw=false\n }\n }\n printLine(str.joinToString(\"\"))\n output()\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation", "shortest paths", "graph matchings"], "code_uid": "02c25b526b2b5dadc3f8e84d4381d452", "src_uid": "964ed316c6e6715120039b0219cc653a", "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()!!.toInt()\n\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 {\n var num = i\n var sum = 0L\n while (num>0){\n sum += num%10\n num/=10\n }\n return sum == 10L\n }\n\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": "67a844078348d00ec9b889ed26e1482c", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nfun main() {\n val (n, a, b, c) = readInts()\n\n var ans = Int.MIN_VALUE\n for (i in 0.rangeTo(n / a + 1)) {\n for (j in 0.rangeTo(n / b + 1)) {\n val sum = a * i + b * j\n if (sum <= n && (n - sum) % c == 0) {\n val k = (n - sum) / c\n ans = max(i + j + k, ans)\n }\n }\n }\n println(ans)\n\n}\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "dp"], "code_uid": "0a1a500c3c6f7c508b513f2028c86227", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43", "difficulty": 1300.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 l = r.readLine()!!.split(\" \").map { it.toInt() }\n println(minOf(l[1]*l[2]/l[6], l[3]*l[4], l[5]/l[7])/l[0])\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "0878a06851864182b0c7d6ec72645797", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main(args : Array) {\n val input = System.`in`.bufferedReader()\n try {\n val s = input.readLine()\n var maxlen = 0\n for (i in 0 until s.length) {\n for (j in i + 1 until s.length) {\n val len = j - i + 1\n var p = i\n var q = j\n var ok = true;\n while (p <= q) {\n if (s[p] != s[q]) {\n ok = false\n break\n } else {\n ++p\n --q\n }\n }\n \n if (!ok)\n maxlen = max(maxlen, len)\n }\n }\n \n println(maxlen)\n } finally {\n input.close()\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "51526655225024c459ab4977b26e284a", "src_uid": "6c85175d334f811617e7030e0403f706", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// https://codeforces.com/problemset/problem/41/A\n\n\nfun main(args: Array) {\n val word = readLn()\n val translation = readLn()\n\n if (word.length != translation.length) {\n print(\"NO\")\n } else {\n\n var correct = true\n for ((index, value) in word.withIndex()) {\n if (value != translation[translation.length - 1 - index]) {\n correct = false\n }\n }\n\n if (correct) {\n print(\"YES\")\n } else {\n print(\"NO\")\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": ["strings", "implementation"], "code_uid": "ce0ef53b93401ab8fd0c792209d470ad", "src_uid": "35a4be326690b58bf9add547fb63a5a5", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val s = readLine()!!\n val words = mutableSetOf()\n for (start in s.indices)\n words.add(s.substring(start, s.length) + s.substring(0, start))\n print(words.size)\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "43e25a81f630a74659ef868ad479f672", "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n print(readLine()!!.toLong() / 2520)\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "73f4270faba4aae0fe3b15d93784821c", "src_uid": "8551308e5ff435e0fc507b89a912408a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\n\nfun solve(cin: FastReader, out: PrintWriter) {\n var s = cin.int()\n var n = cin.int()\n out.println((n + s - 1) / s)\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 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.close()\n}\n\nfun gcd(a: Int, b: Int): Int {\n if (a == 0)\n return b\n return gcd(b % a, a)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation"], "code_uid": "fe33c4ec0eb21d40aeab8db1a0f8e60a", "src_uid": "04c067326ec897091c3dbcf4d134df96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val inStr = readLine()!!.split(\" \").map { it.toInt() }\n var firstCharge=inStr[0]\n var secondCharge=inStr[1]\n var iter=0\n while (true){\n if((firstCharge<2 && secondCharge<2)||(firstCharge==0|| secondCharge==0))\n break\n else{\n if (firstCharge in 1..2 && secondCharge>1){\n firstCharge+=1\n secondCharge-=2\n }\n else{\n firstCharge-=2\n secondCharge+=1\n }\n iter+=1\n }\n }\n println(iter)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "dp", "implementation"], "code_uid": "ff05ac51b12c033a37a24d4cbf286757", "src_uid": "ba0f9f5f0ad4786b9274c829be587961", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun solve(): String {\n val a = readLine()!!.split(' ').map {it.toInt()}\n var ma = -1\n for (i in 0..3)\n for (j in 0..3)\n for (k in 0..3)\n if (i != j && j != k && k != i)\n ma = maxOf(ma, a[i] + a[j] + a[k] - 2 * maxOf(a[i], a[j], a[k]))\n return when {\n (ma > 0) -> \"TRIANGLE\"\n (ma == 0) -> \"SEGMENT\"\n else -> \"IMPOSSIBLE\"\n }\n}\n\nfun main(args: Array) {\n println(solve())\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "geometry"], "code_uid": "d5d1f10e2b4cd4fe5721eddb489dc8fc", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a", "difficulty": 900.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 print(3 * n / 2)\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "20e5500212029d159f09164f5c993a96", "src_uid": "031e53952e76cff8fdc0988bb0d3239c", "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()!!.toLong()\n //val v = r.readLine()!!.split(\"\").filter { it.isNotEmpty() }\n val list = \"c o d e f o r c e s\".split(\" \")\n val ans = IntArray(10) { 1 }\n var ind = 0\n while (ans.fold(1L) { acc, i -> acc * i }()){li, i -> li+ List(ans[i]){list[i]} }\n println(res.joinToString(\"\"))\n /*repeat(r.readLine()!!.toInt()) {\n //val len = r.readLine()!!.toInt()\n val (n, k) = r.readLine()!!.split(\" \").map { it.toLong() }\n }*/\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "math", "greedy", "strings"], "code_uid": "17d4066dcda86d6334262567d8736859", "src_uid": "8001a7570766cadcc538217e941b3031", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun solve() {\n var n = nextInt()\n var k = nextInt()\n val a = nextArray(n)\n var have = 0\n var given = 0\n var i = 0\n while(given < k) {\n if(i == n) {\n pw.print(-1)\n return\n }\n have += a[i++]\n val give = Math.min(have,8)\n given+= give\n have -= give\n }\n pw.println(i)\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\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": "982119fe9b7532dc61855e3ff59e440c", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(){\n\n val s= Scanner(System.`in`)\n var a=0\n var b=0\n var str=s.next()\n for(i in str)\n if(i=='a')\n a++\n else\n b++\n if(a>b)\n println(str.length)\n else\n println(a*2-1)\n\n\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "7914255466e48431f74fd0625fce6715", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219", "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 n = scanner.nextInt()\n val m = scanner.nextInt()\n\n val foods = mutableMapOf()\n repeat (m) {\n val food = scanner.nextInt()\n foods[food] = foods.getOrDefault(food, 0) + 1\n }\n\n var left = 0\n var right = m / n\n while (left < right) {\n val mid = (left + right + 1) / 2\n val canSurviveMid = canSurvive(mid, n, foods)\n if (canSurviveMid) {\n left = mid\n } else {\n right = mid - 1\n }\n }\n println(left)\n}\n\nfun canSurvive(day: Int, people: Int, foods: MutableMap): Boolean {\n var sumPeople = 0L\n for (food in foods) {\n sumPeople += food.value / day\n }\n\n return sumPeople >= people\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "binary search"], "code_uid": "8c8823b278c26099386d21a81807995d", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe", "difficulty": 1200.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": "2fd0ba105b40c7d4a0672d0ea2448941", "src_uid": "77443424be253352aaf2b6c89bdd4671", "difficulty": 1900.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 cout.print(\"YES\")\n else \n cout.print(\"NO\")\n \n \n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "aa6d75cce625c8104d3add1021f75129", "src_uid": "435b6d48f99d90caab828049a2c9e2a7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args : Array) {\n\n val (a, b) = readLine()!!.split(' ')\n var al = a.toInt()\n var ar = b.toInt()\n\n val (x, y) = readLine()!!.split(' ')\n var bl = x.toInt()\n var br = y.toInt()\n\n if(touch(al, br)==1){\n println(\"YES\")\n }\n else if(touch(ar, bl)==1){\n println(\"YES\")\n }\n else\n println(\"NO\")\n}\n\nfun touch(a:Int, b: Int): Int {\n if(a==b) {return 1}\n else if(a>b){\n if((a-b) < 2){\n return 1\n }\n else return 0\n }\n else if(a=b){\n return 1\n }\n else return 0\n }\n else return 0\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "aef0de0fd5f86e58bdbb1ac92fd2a2ce", "src_uid": "36b7478e162be6e985613b2dad0974dd", "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 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).let { if(invert) -it else it }\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": "7f1034964f9297ca6871fbada7f34c13", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun difficulty(a: IntArray): Int {\n var d = Int.MIN_VALUE\n for (i in 1 until a.size) d = maxOf(a[i] - a[i - 1], d)\n return d\n}\n\nfun taska(a: IntArray): Int {\n var d = Int.MAX_VALUE\n for (i in 1 until a.size - 1) {\n val aa = a.copyOf(i) + a.copyOfRange(i + 1, a.size)\n d = minOf(d, difficulty(aa))\n }\n return d\n}\n\nfun cfa() = with(Scanner(System.`in`)) {\n val n = nextInt()\n val a = IntArray(n) { nextInt() }\n println(taska(a))\n}\n\nfun main(args: Array) {\n cfa()\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "463902aa9c91fc30da0de0759fb459bf", "src_uid": "8a8013f960814040ac4bf229a0bd5437", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n\n val (problems, minutes) = readLine()!!.split(' ').map(String::toInt)\n val list = arrayListOf(5, 15, 30, 50, 75, 105, 140, 180, 225, 275)\n\n val index = 240 - minutes\n (0 until list.size).filter { list[it] > index }\n .forEach {\n if (it <= problems) {\n println(it)\n return\n } else {\n println(problems)\n return\n }\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation", "binary search"], "code_uid": "83fd74c7d0ab64de05e21c5bb2b2cfed", "src_uid": "41e554bc323857be7b8483ee358a35e2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var (a, b, n) = readLine()!!.split(' ').map { it.toInt() }\n\n fun gcd(x: Int, y: Int) = x.toBigInteger().gcd(y.toBigInteger()).toInt()\n\n while (true) {\n val ax = gcd(a, n)\n if (ax > n) {\n println(1)\n return\n }\n n -= ax\n val bx = gcd(b, n)\n if (bx > n) {\n println(0)\n return\n }\n n -= bx\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "80db0853ee0f76d898fff6e2936ce169", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nval FIRST = 'X'\nval SECOND = '0'\n\nfun main() {\n val reader = Scanner(System.`in`)\n\n val board = mutableListOf()\n repeat(3) { board.add(reader.nextLine().trim()) }\n\n val zeros = board.sumBy { row -> row.count { it == '0' } }\n val xs = board.sumBy { row -> row.count { it == 'X' } }\n\n fun won(c: Char): Boolean {\n for (i in 0 until 3) {\n if (board[i].all { it == c }) return true\n if (board.all { row -> row[i] == c }) return true\n }\n\n if ((0 until 3).map { board[it][it] }.all { it == c }) return true\n if ((0 until 3).map { board[it][2 - it] }.all { it == c }) return true\n\n return false\n }\n\n when (xs - zeros) {\n 1 -> when {\n won(SECOND) -> println(\"illegal\")\n won(FIRST) -> println(\"the first player won\")\n xs == 5 -> println(\"draw\")\n else -> println(\"second\")\n }\n 0 ->\n when {\n won(FIRST) -> println(\"illegal\")\n won(SECOND) -> println(\"the second player won\")\n else -> println(\"first\")\n }\n else -> println(\"illegal\")\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "games"], "code_uid": "730efef6e82b0f11cca94a55474e993e", "src_uid": "892680e26369325fb00d15543a96192c", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun maxDays(a:Int, b:Int, c:Int){\n val index = arrayOf(1,2,3,1,3,2,1)\n val fullWeeks = minOf(a/3,b/2,c/2) * 7\n var maxRemain = 0\n\n val newa = a - (fullWeeks/7)*3\n val newb = b - (fullWeeks/7)*2\n val newc = c - (fullWeeks/7)*2\n\n for(i in 0 until index.size){\n var ai = newa\n var bi = newb\n var ci = newc\n var cnt = 0\n var ind = i\n\n loop@ while(true){\n when(index[ind]){\n 1 -> {if(ai <= 0){\n break@loop\n }\n else ai--\n }\n 2 -> {if(bi <= 0){\n break@loop\n }\n else bi--\n }\n 3 -> {if(ci <= 0){\n break@loop\n }\n else ci--\n }\n }\n cnt++\n if(ind == index.size - 1){\n ind = 0\n }\n else {\n ind++\n }\n }\n maxRemain = max(cnt,maxRemain)\n }\n println(\"${fullWeeks+maxRemain}\")\n}\n\nfun main(args:Array){\n val l = readLine()!!.split(\" \")\n maxDays(l[0].toInt(), l[1].toInt(), l[2].toInt())\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "523cb0c195b31f36142f219c4f9275c8", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb", "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 var n = reader.nextInt()\n var a = reader.nextInt()\n var b = reader.nextInt()\n\n if (a > b) {\n val t = a\n a = b\n b = t\n }\n\n if (a % 2 == 1 && b % 2 == 0 && a + 1 == b) {\n writer.println(if (n == 2) \"Final!\" else \"1\")\n return\n }\n\n var ans = 1\n while (n != 1) {\n a = a / 2 + a % 2\n b = b / 2 + b % 2\n n /= 2\n ans++\n\n if (a % 2 == 1 && b % 2 == 0 && a + 1 == b) {\n break\n }\n }\n\n writer.println(if (n == 2) \"Final!\" else 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": ["constructive algorithms", "implementation"], "code_uid": "ecc49e38de29a9f5dca9e842abbd68dd", "src_uid": "a753bfa7bde157e108f34a28240f441f", "difficulty": 1200.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 = input.nextInt()\n val a = input.nextInt()\n val b = input.nextInt()\n\n val answer = a / k + b / k\n if(answer >= 1) {\n if (a % k != 0 && b < k) {\n print(-1)\n return\n } else if (b % k != 0 && a < k) {\n print(-1)\n return\n }\n print(answer)\n } else {\n print(-1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "acc9de5bd69362e97e42b6a5db0aae36", "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2", "difficulty": 1200.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\nval charRange = 'a'..'z'\n\nfun main() {\n readLn()\n val sentence = readLn()\n\n if(sentence.map { it.toLowerCase() }.containsAll(charRange.toList())) println(\"YES\") else println(\"NO\")\n}\n", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "a390933631a7ce013e6bcb1d4287dfb9", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n print(25)\n}", "lang_cluster": "Kotlin", "tags": ["number theory"], "code_uid": "1059931fcc7166f8f262bfed1a66a13a", "src_uid": "dcaff75492eafaf61d598779d6202c9d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.lang.Math.abs\nimport java.util.*\nimport kotlin.math.log2\nimport kotlin.math.max\nimport kotlin.math.sqrt\n\nfun main(args : Array) = Thread { run() }.start()\nval scanner = Scanner(System.`in`)\n\nfun run() {\n\n var n = scanner.nextInt()\n var q = 0\n while (n > 0) {\n q++\n n /= 2\n }\n println(q)\n\n}\n\nclass Parser(`in`: InputStream) {\n private val BUFFER_SIZE = 1 shl 16\n private val din: DataInputStream\n private val buffer: ByteArray\n private var bufferPointer: Int = 0\n private var bytesRead: Int = 0\n\n init {\n din = DataInputStream(`in`)\n buffer = ByteArray(BUFFER_SIZE)\n bytesRead = 0\n bufferPointer = bytesRead\n }\n\n fun nextString(maxSize: Int): String {\n val ch = ByteArray(maxSize)\n var point = 0\n try {\n var c = read()\n while (c == ' '.toByte() || c == '\\n'.toByte() || c == '\\r'.toByte())\n c = read()\n while (c != ' '.toByte() && c != '\\n'.toByte() && c != '\\r'.toByte()) {\n ch[point++] = c\n c = read()\n }\n } catch (e: Exception) {}\n\n return String(ch, 0, point)\n }\n\n fun nextInt(): Int {\n var ret = 0\n val neg: Boolean\n try {\n var c = read()\n while (c <= ' '.toByte())\n c = read()\n neg = c == '-'.toByte()\n if (neg)\n c = read()\n do {\n ret = ret * 10 + c - '0'.toInt()\n c = read()\n } while (c > ' '.toByte())\n\n if (neg) return -ret\n } catch (e: Exception) {}\n return ret\n }\n\n fun nextLong(): Long {\n var ret: Long = 0\n val neg: Boolean\n try {\n var c = read()\n while (c <= ' '.toByte())\n c = read()\n neg = c == '-'.toByte()\n if (neg)\n c = read()\n do {\n ret = ret * 10 + c - '0'.toLong()\n c = read()\n } while (c > ' '.toByte())\n\n if (neg) return -ret\n } catch (e: Exception) {}\n\n return ret\n }\n\n fun nextDouble(): Double\n = nextString(10000).toDouble()\n\n private fun fillBuffer() {\n try {\n bytesRead = din.read(buffer, 0, BUFFER_SIZE)\n } catch (e: Exception) {}\n if (bytesRead == -1) buffer[0] = -1\n }\n\n private fun read(): Byte {\n if (bufferPointer == bytesRead) fillBuffer()\n return buffer[bufferPointer++]\n }\n}\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\nfun IntArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun LongArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun BooleanArray.print() {\n println(Arrays.toString(this))\n}\nfun nod(a: Long, b: Long): Long {\n var a1 = a\n var b1 = b\n while (a1 != 0L && b1 != 0L) {\n if (a1 < b1)\n b1 %= a1\n else\n a1 %= b1\n }\n return a1 + b1\n}\nfun nok(a: Long, b: Long): Long = a * b / nod(a, b)\nfun min(a: Char, b: Char): Int {\n if (a < b)\n return a.toInt()\n return b.toInt()\n}\nfun max(a: Char, b: Char): Int {\n if (a > b)\n return a.toInt()\n return b.toInt()\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms"], "code_uid": "b6cff573b0260ce1761c382f910e6794", "src_uid": "95cb79597443461085e62d974d67a9a0", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (a, b) = readInts()\n var first = 0\n var second = 0\n for (result in 1..6) {\n when {\n abs(a - result) < abs(b - result) -> first++\n abs(a - result) > abs(b - result) -> second++\n }\n }\n print(\"$first ${6 - first - second} $second\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "1d5a867eb4060c07c02c40f882843360", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\n//2019-02-18\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val n = nextInt()\n val v = nextInt()\n var diff = v - (n - 1)\n if (diff >= 0) {\n print(n - 1)\n } else {\n diff *= -1\n print((2 + diff + 1) * diff / 2 + v)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "dp"], "code_uid": "d6bacc06ce60eb4a52e4a22536db5f67", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun String.remove(i: Int) = substring(0, i) + if (i + 1 != length) substring(i + 1) else \"\"\n\nfun main() {\n val s = readLine()!!.toInt()\n var str = readLine()!!\n for (ch in 'z' downTo 'b') {\n var index = 0\n while (index < str.length) {\n if (str[index] == ch) {\n if (index != 0 && str[index - 1] == ch - 1) {\n str = str.remove(index)\n } else if (index + 1 != str.length && str[index + 1] == ch - 1) {\n str = str.remove(index)\n } else index++\n } else {\n index++\n }\n }\n index = str.length - 1\n while (index >= 0) {\n if (str[index] == ch) {\n if (index != 0 && str[index - 1] == ch - 1) {\n str = str.remove(index)\n } else if (index + 1 != str.length && str[index + 1] == ch - 1) {\n str = str.remove(index)\n }\n }\n index--\n }\n }\n println(s - str.length)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy", "strings", "constructive algorithms"], "code_uid": "6d0cc4e30d51f34f5ff537c8746ecf9f", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38", "difficulty": 1600.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 print((n * n * (n - 1)) / 2 - (n * (n - 1) * (2 * n - 1)) / 6 + n)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "855b1c7f69073d51d74cf6e7f3dce416", "src_uid": "6df251ac8bf27427a24bc23d64cb9884", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n// Про награды\n\nfun main(args: Array) {\n\n val kubok = readLine()!!.trim().split(\" \")\n val medal = readLine()!!.trim().split(\" \")\n val n = readLine()!!.trim().toInt()\n\n val countA = kubok.asSequence().sumBy { s -> s.toInt() }\n val countB = medal.asSequence().sumBy { s -> s.toInt() }\n\n // println(countA)\n // println(countB)\n\n val needRowToA = if (countA % 5 == 0) countA/5 else countA/5+1\n val needRowToB = if (countB % 10 == 0) countB/10 else countB/10+1\n\n // println(needRowToA)\n // println(needRowToB)\n\n if (n - needRowToB - needRowToA >= 0){\n println(\"YES\")\n }else{\n println(\"NO\")\n }\n /*\n на одной полке не могут находиться кубки и медали одновременно;\n ни на какой полке не должно быть больше пяти кубков;\n ни на какой полке не должно быть больше десяти медалей.\n */\n\n\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "54a9d467ea2d050bc316012b0cbbf6b9", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e", "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\n val x = Math.min(a, b)\n val y = Math.max(a, b)\n\n var best: Long = 0\n var m = 5\n while (true) {\n val low = Math.max(1, m - y)\n val high = Math.min(x, m - 1)\n if (low > x) {\n pw.println(best)\n return\n }\n best += 0 + high - low + 1\n m += 5\n }\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "number theory"], "code_uid": "94ce5264187a56a7f9a5688554b5d818", "src_uid": "df0879635b59e141c839d9599abd77d2", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val a = readLine()!!\n val b = readLine()!!\n val c = (a.toInt() + b.toInt()).toString()\n var pos = 1\n var output = true\n while (pos <= c.length) {\n if (a.length - pos >= 0) {\n if (a[a.length - pos] == '0' && c[c.length - pos] != '0') {\n output = false\n break\n }\n if (a[a.length - pos] != '0' && c[c.length - pos] == '0') {\n output = false\n break\n }\n }\n if (b.length - pos >= 0) {\n if (b[b.length - pos] == '0' && c[c.length - pos] != '0') {\n output = false\n break\n }\n if (b[b.length - pos] != '0' && c[c.length - pos] == '0') {\n output = false\n break\n }\n }\n pos++\n }\n if (output) print(\"YES\") else print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5de85a3b1b3ddfc8e747e0e91c02623c", "src_uid": "ac6971f4feea0662d82da8e0862031ad", "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 val n = readInt()\n var a = 1\n var retA = 1\n var retB = n\n while(a * a <= n) {\n if(n%a == 0) {\n retA = a\n retB = n/a\n }\n a++\n }\n println(\"%d %d\".format(retA, retB))\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", "math"], "code_uid": "f7bdfe62f2a0918902ed6f375d23d113", "src_uid": "f52af273954798a4ae38a1378bfbf77a", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var z = 0;\n var a = readLine()!!.toInt()\n var b = readLine()!!.toInt()\n var c = readLine()!!.toInt()\n\n\n while (a != 0 && b >= 2 && c >= 4)\n {\n a--\n b = b - 2\n c = c - 4\n z += 7\n }\n print(z)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "bf47e0e8c8c9c5e5bea129919d43fd47", "src_uid": "82a4a60eac90765fb62f2a77d2305c01", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n print((readLine()!!.toInt() - 1) / 2)\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "constructive algorithms"], "code_uid": "b0f3e70900e137f7c83fc978a77c1ace", "src_uid": "dfe9446431325c73e88b58ba204d0e47", "difficulty": 1000.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()\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 isMul(a: Int, b: Int, c: Int, d: Int): Boolean {\n if (a == 0 && b == 0) return true\n if (c == 0 && d == 0) return false\n if (a.toLong()*d != b.toLong()*c) return false\n if (c != 0) {\n if (a%c != 0 || a/c < 0) return false\n } else {\n if (b%d != 0 || b/d < 0) return false\n }\n return true\n}\n\nfun solve() {\n val (a,b) = nextInts()\n val s = next()\n var (x,y) = arrayOf(0,0)\n for (c in s) {\n if (c == 'U') {\n y ++\n }\n if (c == 'D') {\n y --\n }\n if (c == 'L') {\n x --\n }\n if (c == 'R') {\n x ++\n }\n }\n var (X,Y) = arrayOf(0,0)\n for (c in s) {\n var (difx,dify) = arrayOf(a-X,b-Y)\n if (isMul(difx,dify,x,y)) {\n println(\"Yes\")\n System.exit(0)\n }\n if (c == 'U') {\n Y ++\n }\n if (c == 'D') {\n Y --\n }\n if (c == 'L') {\n X --\n }\n if (c == 'R') {\n X ++\n }\n }\n println(\"No\")\n}\n\nfun main(args: Array) {\n solve()\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "binary search"], "code_uid": "98d11515728ac4fc4f06a46409798215", "src_uid": "5d6212e28c7942e9ff4d096938b782bf", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() {\n output {\n var (a1, a2, k1, k2) = readInts(4)\n\n if(k1 > k2) {\n k1 = k2.also { k2 = k1 }\n a1 = a2.also { a2 = a1 }\n }\n\n val n = readInt()\n\n val min = maxOf(0, n - a1 * (k1 - 1) - a2 * (k2 - 1))\n val max1 = minOf(a1, n / k1)\n val max = max1 + minOf(a2, (n - max1*k1) / k2)\n\n println(\"$min $max\")\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", "greedy", "implementation"], "code_uid": "0346a10a7a632b06264d8cb23613c081", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91", "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\n val p = t.substring(1)\n val caps = p.all { c -> c.isUpperCase() }\n if (!caps) {\n io.println(t)\n } else {\n if (t[0].isUpperCase()) {\n io.println(t.toLowerCase())\n } else {\n io.print(t[0].toUpperCase())\n io.println(p.toLowerCase())\n }\n }\n io.close()\n}\n\nfun main(args: Array) {\n Thread({ solve() }).start()\n}\n", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "221ce741dca757baba28f11461bc0a0b", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Math.*\nimport java.util.*\n\n/**\n * Created by Administrator on 9/2/2019.\n */\n\n// for (i in 1..n) {}\n// for (i in 5 downTo 1)\n// for (i in 1..5 step 2)\n// println(n)\n// println(\"${ansList.size} $ans\")\n// val freq = mutableMapOf()\n// var places = mutableListOf()\n// class Place(val x: Int, val b: Int)\n// teams.sortWith(compareBy({it.size}));\n// val pq = PriorityQueue(Comparator{a1, a2 -> a2.money - a1.money})\n// var dp = Array(402, {IntArray(402)})\n// var adj = MutableList>(402) {_ -> mutableListOf()}\n// println(Arrays.toString(array))\n// println(Arrays.deepToString(array))\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of Longs\n\nvar dp = Array(402, {IntArray(402)})\nvar adj = MutableList>>(402) {_ -> mutableListOf()}\nvar dpAns = MutableList>>(402) {_ -> MutableList>(402){_ -> mutableListOf()}}\nvar size = IntArray(402){0}\n\nfun DP(at: Int, par: Int) {\n size[at] = 1\n dp[at] = IntArray(402) {-1}\n dp[at][1] = 0\n for (V in adj[at]) {\n val v = V.first\n if (par == v) continue\n DP(v, at)\n dp[v][0] = 1\n dpAns[v][0].add(V.second)\n var newDp = IntArray(402) {-1}\n var prev = IntArray(402) {-1}\n for (i in 1..size[at]) {\n for (j in 0..size[v]) {\n if (dp[at][i] == -1 || dp[v][j] == -1) continue\n val cur = dp[at][i] + dp[v][j]\n if (newDp[i + j] == -1 || newDp[i + j] > cur) {\n prev[i + j] = i\n newDp[i + j] = cur\n }\n }\n }\n dp[at] = newDp\n var newDpAns = MutableList>(402) {_ -> mutableListOf()}\n for (i in 0..size[at]+size[v]) {\n if (prev[i] != -1) {\n newDpAns[i].addAll(dpAns[at][prev[i]])\n newDpAns[i].addAll(dpAns[v][i - prev[i]])\n }\n }\n dpAns[at] = newDpAns\n size[at] += size[v]\n for (i in 1..size[v]) {\n dp[v][i]++\n dpAns[v][i].add(V.second)\n }\n }\n}\n\nfun main(args: Array) {\n val (n, k) = readInts()\n for (i in 1..n-1) {\n val (u, v) = readInts()\n adj[u].add(Pair(v, i))\n adj[v].add(Pair(u, i))\n }\n DP(1, 0)\n var best = -1\n var bestAns = MutableList(402) {-1}\n for (i in 1..n) {\n if (dp[i][k] == -1) continue\n if (best == -1 || best > dp[i][k]) {\n best = dp[i][k]\n bestAns = dpAns[i][k]\n }\n }\n println(best)\n for (i in bestAns) print(\"$i \")\n}", "lang_cluster": "Kotlin", "tags": ["dp", "trees"], "code_uid": "a4978692fa1612b1299fe67b853f55fd", "src_uid": "56168b28f9ab4830b3d3c5eeb7fc0d3c", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Integer.max\nimport java.lang.Integer.min\n\nfun main() {\n println(\n min(\n max(\n readString().compareTo(readString()),\n -1\n ),\n 1\n )\n )\n}\n\nprivate fun readString() = readLine()!!.toLowerCase()", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "1c724a9f922ae19e6416235d1df32da6", "src_uid": "ffeae332696a901813677bd1033cf01e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args : Array) {\n val l1 = readLine()!!\n val l2 = readLine()!!\n val l3 = readLine()!!\n var list1: MutableList = mutableListOf()\n var list2: MutableList = mutableListOf()\n var list3: MutableList = mutableListOf()\n\n for (char in l1) { list1.add(char) }\n for (char in l2) { list2.add(char) }\n for (char in l3) { list3.add(char) }\n\n var w1 = win(list1[0],list1[1],list1[2])\n var w2 = win(list2[0],list2[1],list2[2])\n var w3 = win(list3[0],list3[1],list3[2])\n\n\n if(w1!=w2 && w1!=w3 && w2!=w3){\n println(\"Impossible\")\n }\n else if(w1==w2){\n print(lose(list3[0],list3[1],list3[2]))\n print(win(list3[0],list3[1],list3[2]))\n print(w2)\n }\n else if(w1==w3){\n print(lose(list2[0],list2[1],list2[2]))\n print(win(list2[0],list2[1],list2[2]))\n print(w1)\n }\n else if(w3==w2){\n print(lose(list1[0],list1[1],list1[2]))\n print(win(list1[0],list1[1],list1[2]))\n print(w3)\n }\n}\n\nfun win(x:Char, s: Char, y: Char):Char{\n if(s=='>') {return x}\n else return y\n}\nfun lose(x:Char, s: Char, y: Char):Char{\n if(s=='<') {return x}\n else return y\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "051ff57b0acea235bb85ec15c65fe8ee", "src_uid": "97fd9123d0fb511da165b900afbde5dc", "difficulty": 1200.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 length = readInt()\n val row = readLine()!!\n val sol = mutableListOf()\n var blacks = 0\n for (c in row) {\n if (c == 'B')\n blacks++\n else {\n if (blacks > 0) {\n sol.add(blacks)\n blacks = 0\n }\n }\n }\n if (blacks > 0) {\n sol.add(blacks)\n }\n println(sol.size)\n print(sol.joinToString(\" \"))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "118ddd0036cc959ffb0b51a990369e32", "src_uid": "e4b3a2707ba080b93a152f4e6e983973", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main() {\n val reader = Scanner(System.`in`)\n var noToHold = reader.nextInt()\n val containersLength = reader.nextInt()\n val containers = mutableListOf>()\n for (i in 1..containersLength) {\n val key = reader.nextInt()\n val value = reader.nextInt()\n containers.add(Pair(key,value))\n }\n val sortedContainers = containers.toList()\n .sortedByDescending { (key, value) -> value }\n var total = 0\n for (container in sortedContainers) {\n if (noToHold != 0) {\n if (container.first <= noToHold) {\n noToHold -= container.first\n total += container.first * container.second\n } else {\n total += noToHold * container.second\n noToHold -= noToHold\n }\n }\n else\n break\n }\n print(total)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "28b3eb13dbffcdeb82be7883566d1c4a", "src_uid": "c052d85e402691b05e494b5283d62679", "difficulty": 900.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 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\nfun identity_matrix() : 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\nfun ant_matrix() : 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\nfun num_paths(n : Int) : Long {\n fun raise_to(t : TransitionMatrix, x : Int) : TransitionMatrix {\n if (x == 0) {\n val result = identity_matrix()\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 = ant_matrix()\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": "36082ec9eb1d0640c12a69ffa50bf557", "src_uid": "77627cc366a22e38da412c3231ac91a8", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val x = readLine()!!\n val n = x.length\n var result = (1 shl n) - 1\n for (i in (n - 1) downTo 0) {\n if (x[i] == '7') {\n result += 1 shl (n - 1 - i)\n }\n }\n println(result)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "combinatorics", "bitmasks"], "code_uid": "f2b453a2bdc29b44c9a733881db6e788", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n when (readLine()!!.toInt()) {\n 2 -> println(2)\n else -> println(1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "24e2c8a09ba900385c4fe6b6d939dcd5", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args:Array)\n{\n val input = readLine()!!.toString()\n val len : Int = input.length\n var qcount : Int = 0\n var acount : Int = 0\n var i : Int = 0\n var count : Int = 0\n var res : Int = 0\n while(i) {\n val (n, m) = readLine()!!.split(' ').map { it.toInt() }\n var socks = n\n var days = 0\n while (socks > 0) {\n socks--\n days++\n if (days % m == 0) {\n socks++\n }\n }\n\n println(days)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "3b0a1344fee64b6cd4e11398b06c9d1f", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (links, pearls) = readLine()!!.partition { it == '-' }\n if (pearls.isEmpty()) {\n println(\"YES\")\n } else {\n println(if (links.length % pearls.length == 0) \"YES\" else \"NO\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "0cabddb23f092a5674bc918661e3c7b0", "src_uid": "6e006ae3df3bcd24755358a5f584ec03", "difficulty": 900.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 var ans = n\n\n for(p in longPrimeSieve(sqrt)) {\n val sq = p * p\n while(ans % sq == 0L) ans /= p\n }\n\n println(ans)\n}\n\nfun Long.sqrtFloor() = sqrt(toDouble()).toLong()\n\nfun longPrimeSieve(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 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": "7dea8d68aaa02f1c183cbc1784153b11", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun solve() {\n var n = nextInt()\n var k = nextInt()\n var a = nextArray(k)\n var total = a.sum()\n var dordneferlik = n\n var ikineferlik = 2 * n\n for (i in a.indices){\n while (a[i] >= 3 && dordneferlik > 0) {\n dordneferlik--\n var minus = Math.min(a[i],4)\n a[i] -= minus\n total -= minus\n }\n }\n for (i in a.indices) {\n if(a[i] % 2 == 1) {\n if(dordneferlik > 0) {\n dordneferlik--\n ikineferlik++\n total--\n a[i]--\n }else break\n }\n }\n if (dordneferlik > 1) {\n for (i in a.indices) {\n if(dordneferlik >= 2) {\n if(a[i] >= 2) {\n dordneferlik -= 2\n ikineferlik += 2\n total -= 2\n a[i] -= 2\n }\n }else break\n }\n }\n if(dordneferlik == 1) ikineferlik++\n for (i in a.indices) {\n if(a[i] % 2 == 1) {\n ikineferlik--\n total--\n a[i]--\n }\n ikineferlik -= a[i] / 2\n total -= a[i]\n }\n if(ikineferlik < 0 || dordneferlik < 0 || total > 0) pw.print(\"NO\")\n else pw.print(\"YES\")\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\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", "greedy", "implementation"], "code_uid": "650304216b5c5903135e8259bff035e5", "src_uid": "d1f88a97714d6c13309c88fcf7d86821", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n var N = 0\n for(i in 1..n/2){\n if ((n - i) % i == 0) {\n N++\n }\n }\n println(N)\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "2523ca8a7b671d7e41b5b66a5767bc23", "src_uid": "89f6c1659e5addbf909eddedb785d894", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun solve() {\n val n = readInt()\n val m = readInt()\n val a = readInts()\n Arrays.sort(a)\n a.reverse()\n\n fun check(w : Int): Boolean {\n var ww = w\n var count = 0\n var ind = 1\n var nn = 0\n for (i in 0 until w)\n count += a[i]\n while (ww < n) {\n count += if (a[ww] - ind < 0) 0 else a[ww] - ind\n ww++\n nn++\n if (nn == w) {\n nn = 0\n ind++\n }\n }\n return count >= m\n }\n\n var left = 0\n var right = n\n while (right - left > 1) {\n var mid = (right + left) shr 1\n if (check(mid))\n right = mid\n else\n left = mid\n }\n\n out.println(if (check(right)) right else -1)\n}\n\nfun binmult(a : Long, b : Long, m : Long) : Long {\n if (a == 0L)\n return 0\n\n if (a % 2 == 1L) {\n val prev = binmult(a - 1, b, m)\n return (prev + b) % m\n } else {\n val half = binmult(a / 2, b, m)\n return (half + half) % m\n }\n}\n\nfun binpow(a: Long, n: Long, mod: Long): Long {\n var a = a\n var n = n\n var res: Long = 1\n while (n > 0) {\n if (n and 1 == 1L) {\n res = binmult(res, a, mod)\n res %= mod\n n--\n } else {\n a = binmult(a, a, mod)\n a %= mod\n n = n shr 1\n }\n }\n return res % mod\n}\n\ninline fun phi(n: Int): Int {\n var n = n\n var result = n\n var i = 2\n while (i * i <= n) {\n if (n % i == 0) {\n while (n % i == 0)\n n /= i;\n result -= result / i\n }\n ++i\n }\n if (n > 1)\n result -= result / n\n return result\n}\n\nvar out = PrintWriter(System.out)\nvar br = BufferedReader(InputStreamReader(System.`in`))\nvar st = StringTokenizer(\"\")\n\nfun main(args: Array) {\n solve()\n out.close()\n}\n\ninline fun readString(): String {\n if (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st.nextToken()\n}\n\ninline fun readLine() = br.readLine()\ninline fun readInt() = readString().toInt()\ninline fun readLong() = readString().toLong()\ninline fun readDouble() = readString().toDouble()\ninline fun readBool() = readString().toBoolean()\ninline fun readFloat() = readString().toFloat()\n\ninline fun readInts() = readLine().split(' ').map(String::toInt).toIntArray()", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy"], "code_uid": "7b9b8ba208ad68e61e538a72883d15ea", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d", "difficulty": 1700.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=readInt()\n if(n<0){\n n=-n\n n=min(n/10,n/100*10+n%10)\n n=-n;\n }\n printLine(\"$n\")\n output()\n}", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "b10723a4110262aec3f02a958ff138d6", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e", "difficulty": 900.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\nval map = IntArray(400_010)\n\nfun findZeroSum2(aPos: List, bPos: List, maxCount: Int, n: Int): Int {\n map.fill(-100, toIndex = 2 * maxCount + 2)\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": "ea5eaf1a0ef3b01580bbdb2778da47a5", "src_uid": "a06ebb2734365ec97d07cd1b6b3faeed", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n val sc = MyScanner()\n val out = PrintWriter(BufferedOutputStream(System.out))\n var t = 1\n while (t-- > 0) {\n val n = sc.nextInt()\n val x = sc.nextInt()\n val pos = sc.nextInt()\n val index = ArrayList()\n var l = 0\n var r = n\n while (l < r) {\n val mid = (l + r) / 2\n if (mid <= pos) {\n index.add(mid)\n l = mid + 1\n } else {\n index.add(mid)\n r = mid\n }\n }\n //for (Integer i : index) out.print(i + \" \");\n val res: Long = 1\n var less = 0\n var more = 0\n for (i in index) {\n if (i <= pos) less++ else more++\n }\n less--\n val totalLess = x - 1\n val totalAbove = n - x\n if (totalLess < less || totalAbove < more) {\n out.println(0)\n } else {\n initFac(n + 5.toLong())\n var a = nck(totalAbove, more)\n a = a * fac[more] % mod\n var b = nck(totalLess, less)\n b = b * fac[less] % mod\n a = a * b % mod\n val rem = fac[n - less - more - 1]\n a = a * rem % mod\n out.println(a)\n }\n }\n out.close()\n}\n\nvar fac: LongArray = LongArray((1e4 + 1).toInt());\nvar mod = 1e9.toLong() + 7\n\nfun initFac(n: Long) {\n fac[0] = 1\n for (i in 1..n) {\n fac[i.toInt()] = fac[(i - 1).toInt()] * i % mod\n }\n}\n\n\nfun nck(n: Int, k: Int): Long {\n if (n < k) return 0\n val den = inv((fac[k] * fac[n - k] % mod))\n return fac[n] * den % mod\n}\n\nfun pow(b: Long, e: Long): Long {\n var b = b\n var e = e\n var ans: Long = 1\n while (e > 0) {\n if (e % 2 == 1L) ans = ans * b % mod\n e = e shr 1\n b = b * b % mod\n }\n return ans\n}\n\nfun inv(x: Long): Long {\n return pow(x, mod - 2)\n}\n\n\n//-----------MyScanner class for faster input----------\nclass MyScanner {\n var br: BufferedReader\n var st: StringTokenizer? = null\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 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 = br.readLine()\n } catch (e: IOException) {\n e.printStackTrace()\n }\n return str\n }\n\n init {\n br = BufferedReader(InputStreamReader(System.`in`))\n }\n}", "lang_cluster": "Kotlin", "tags": ["binary search", "combinatorics"], "code_uid": "45c2acf37dd1ee61c4a58b4e39e026a4", "src_uid": "24e2f10463f440affccc2755f4462d8a", "difficulty": 1500.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 k = sc.nextInt()\n val a = IntArray( n, { sc.nextInt() } )\n var r = 0\n for ( s in 0 until k ) {\n val one = a.withIndex().count { ( it.index - s ) % k != 0 && it.value == 1 }\n val mone = a.withIndex().count { ( it.index - s ) % k != 0 && it.value == -1 }\n val diff = Math.abs( one - mone )\n r = Math.max( r, diff )\n }\n println( r )\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "63373eeb3f0448bad348eb561855466c", "src_uid": "6119258322e06fa6146e592c63313df3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!\n val nLong = n.toLong()\n\n fun recursion(sb: StringBuilder, fours: Int, sevens: Int): String? {\n if (fours == 0 && sevens == 0) {\n return if (sb.toString().toLong() >= nLong) sb.toString()\n else null\n } else {\n if (fours > 0) {\n sb.append('4')\n val option1 = recursion(sb, fours - 1, sevens)\n if (option1 != null) return option1\n sb.deleteCharAt(sb.lastIndex)\n }\n if (sevens > 0) {\n sb.append('7')\n val option2 = recursion(sb, fours, sevens - 1)\n if (option2 != null) return option2\n sb.deleteCharAt(sb.lastIndex)\n return null\n }\n return null\n }\n }\n\n for (length in n.length .. n.length + 2) {\n if (length % 2 == 1) continue\n val sb = StringBuilder()\n val sol = recursion(sb, length / 2, length / 2)\n if (sol != null) return print(sol)\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "binary search", "bitmasks"], "code_uid": "92a6b42d6ae1e6416c27c367ff5e6f07", "src_uid": "77b5f83cdadf4b0743618a46b646a849", "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 (m, n) = r.readLine()!!.split(\" \").map { it.toInt() }\n val v = r.readLine()!!.split(\" \").map { it.toInt() }.map { if (it<0) -it else it }.sum()\n println(v)\n\n}", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "de09033eb61b995e03fbd67fb663fb89", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5", "difficulty": 800.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 n = readLong()\n var k = readInt()\n val all = ArrayList()\n var i: Long = 1\n while (i * i <= n) {\n if (n % i == 0L) {\n all.add(i)\n if (i * i != n) all.add(n / i)\n }\n i++\n }\n Collections.sort(all)\n if (--k < all.size)\n pw!!.println(all[k])\n else\n pw!!.println(-1)\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": ["math", "number theory"], "code_uid": "edf4aa7dfe816cf4baf3c00515d07b2e", "src_uid": "6ba39b428a2d47b7d199879185797ffb", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport java.util.Queue\n\nfun main(){\n var scanner : Scanner = Scanner(System.`in`)\n var a : Long = scanner.nextLong()\n var b : Long = scanner.nextLong()\n var visited : MutableMap = mutableMapOf(\n a to true\n )\n var parent : MutableMap = mutableMapOf()\n var done : Boolean = false\n var bfs_q : Queue = LinkedList()\n bfs_q.add(a)\n parent[a] = a\n while(!bfs_q.isEmpty()){\n var curr : Long = bfs_q.peek()\n bfs_q.remove()\n\n if (curr == b){\n done = true\n break\n }\n\n var c1 : Long = curr * 2\n var c2 : Long = 10 * curr + 1\n\n if(c1 >= 0 && c1 <= 1e9 && !visited.containsKey(c1)){\n visited[c1] = true\n bfs_q.add(c1)\n parent[c1] = curr\n }\n if(c2 >= 0 && c2 <= 1e9 && !visited.containsKey(c2)){\n visited[c2] = true\n bfs_q.add(c2)\n parent[c2] = curr\n }\n }\n\n if(!done){\n print(\"NO\")\n } else {\n println(\"YES\")\n var steps : Stack = Stack()\n\n var currStep : Long = b\n while(currStep != a) {\n steps.push(currStep)\n currStep = parent[currStep]!!\n }\n steps.push(a)\n println(steps.size)\n while(!steps.isEmpty()){\n print(\"${steps.peek()} \")\n steps.pop()\n }\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "math", "brute force"], "code_uid": "11d4b0ff742a64c18e73009dc679e1ef", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!\n\n\n\n\n (Math.sqrt(n.toDouble()).toInt() downTo 1).forEach{\n\n val regex = Regex((it*it).toString().map { \"$it.*\" }.joinToString (separator = \"\"))\n\n\n if ( n.contains(regex)){\n println(n.length - (it*it).toString().length)\n return\n\n }\n }\n\n println(-1)\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "ac191f2eb6bafbf722117e0f2ac4d22e", "src_uid": "fa4b1de79708329bb85437e1413e13df", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun calcSubs2(n: Long): Long {\n return if (n % 2 == 0L) {\n n / 2\n } else {\n ((n - smallestPrimeDiv(n)) / 2) + 1\n }\n}\n\nfun smallestPrimeDiv(n: Long): Long {\n when (n) {\n in 1L..7L step 2 -> return n\n else -> for (i in 3..Math.sqrt(n.toDouble()).toLong() step 2) {\n if (n % i == 0L) {\n return i\n }\n }\n }\n return n\n}\n\nfun main(args: Array) {\n println(calcSubs2(readLine()!!.toLong()))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "ebb00c79f2c8efef9b2a156b25d88a97", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nclass PatternHandler(private val pattern: CharArray,\n private val alphabet: Int) {\n\n private val IMPOSSIBLE_MESSAGE = \"IMPOSSIBLE\"\n private val usedChars = BooleanArray(alphabet)\n\n init {\n for (symbol in pattern) {\n if (symbol != '?') {\n usedChars[getIndex(symbol)] = true\n }\n }\n }\n\n private fun getIndex(symbol: Char): Int = symbol - 'a'\n\n private fun getAppropriateLetter(): Char {\n val index = usedChars.lastIndexOf(false)\n val result: Char\n\n if (index == -1) {\n result = 'a'\n } else {\n result = 'a' + index\n }\n\n return result\n }\n\n private fun removeWildCardPairs() {\n var r = pattern.size / 2\n var l = r - (pattern.size + 1) % 2\n while (r - l + 1 <= pattern.size) {\n if (pattern[l] == '?' && pattern[r] == '?') {\n val letter = getAppropriateLetter()\n usedChars[getIndex(letter)] = true\n pattern[l] = letter\n pattern[r] = letter\n }\n\n r++\n l--\n }\n }\n\n private fun cleanAllWildCards(): String {\n var r = pattern.size / 2\n var l = r - (pattern.size + 1) % 2\n while (r - l + 1 <= pattern.size) {\n if (pattern[l] == '?') {\n pattern[l] = pattern[r]\n }\n\n if (pattern[r] == '?') {\n pattern[r] = pattern[l]\n }\n\n if (pattern[l] != pattern[r]) {\n return IMPOSSIBLE_MESSAGE\n }\n\n r++\n l--\n }\n\n if (usedChars.contains(false)) {\n return IMPOSSIBLE_MESSAGE\n }\n\n return pattern.joinToString(separator = \"\")\n }\n\n fun solve(): String {\n if (alphabet > pattern.size) {\n return IMPOSSIBLE_MESSAGE\n }\n\n removeWildCardPairs()\n return cleanAllWildCards()\n }\n}\n\nfun main(args: Array) {\n val k = Integer.parseInt(readLine())\n val pattern = readLine()!!\n val result = PatternHandler(pattern.toCharArray(), k).solve()\n print(result)\n}", "lang_cluster": "Kotlin", "tags": ["expression parsing"], "code_uid": "29ec60d5b8b519106bba238519e2a75a", "src_uid": "9d1dd9d722e5fe46823224334b3b208a", "difficulty": 1600.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 g = arrayOf('A', 'E', 'I', 'O', 'U', 'Y');\n\tvar str = readLn();\n\tvar pos = 1;\n\tvar maxPos = 1; \n\tfor(c in str){\n\t\tif(c !in g)pos++;\n\t\telse pos = 1;\n\t\tmaxPos = Math.max(pos, maxPos);\n\t}\n\tprintln(maxPos);\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "f1bd66c00c9939f5205c5b48db0000a4", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee", "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\nclass A 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() = st.nextToken(\"\\n\")\n\n private fun ni(offset: Int = 0) = next().toInt() + offset\n private fun nii(offset: Int = 0) = Pair(ni(offset), ni(offset))\n private fun niii(offset: Int = 0) = Triple(ni(offset), ni(offset), ni(offset))\n\n private fun nia(n: Int, offset: Int = 0) = IntArray(n) { ni(offset) }\n private fun niaa(m: Int, n: Int, offset: Int = 0) = Array(m) { nia(n, offset) }\n\n private fun nl(offset: Long = 0L) = next().toLong() + offset\n private fun nll(offset: Long = 0L) = Pair(nl(offset), nl(offset))\n private fun nlll(offset: Long = 0L) = Triple(nl(offset), nl(offset), nl(offset))\n\n private fun nla(n: Int, offset: Long = 0L) = LongArray(n, { nl(offset) })\n private fun nlaa(m: Int, n: Int, offset: Long = 0L) = Array(m) { nla(n, offset) }\n\n private fun nd(offset: Double = 0.0) = next().toDouble() + offset\n private fun ndd(offset: Double = 0.0) = Pair(nd(offset), nd(offset))\n private fun nddd(offset: Double = 0.0) = Triple(nd(offset), nd(offset), nd(offset))\n\n private fun nda(n: Int, offset: Double = 0.0) = DoubleArray(n) { nd(offset) }\n private fun ndaa(m: Int, n: Int, offset: Double = 0.0) = Array(m) { nda(n, offset) }\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 = \"\", range: IntRange? = arr?.indices) = log(name) { pln(arr, range = range) }\n inline fun log(arr: LongArray?, name: String = \"\", range: IntRange? = arr?.indices) = log(name) { pln(arr, range = range) }\n inline fun log(arr: DoubleArray?, name: String = \"\", range: IntRange? = arr?.indices) = log(name) { pln(arr, range = range) }\n inline fun log(arr: Array?, name: String = \"\", range: IntRange? = arr?.indices) = log(name) { pln(arr, range = range) }\n inline fun log(stack: Stack?, name: String = \"\", range: IntRange? = stack?.indices) = log(name) { pln(stack, range = range) }\n inline fun log(list: List?, name: String = \"\", range: IntRange? = list?.indices) = log(name) { pln(list, range = range) }\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 = \" \", range: IntRange? = arr?.indices) = this.also {\n range?.forEach { prep(it > 0, separator, arr?.get(it)) }\n }\n\n inline fun p(arr: LongArray?, separator: String = \" \", range: IntRange? = arr?.indices) = this.also {\n range?.forEach { prep(it > 0, separator, arr?.get(it)) }\n }\n\n inline fun p(arr: DoubleArray?, separator: String = \" \", range: IntRange? = arr?.indices) = this.also {\n range?.forEach { prep(it > 0, separator, arr?.get(it)) }\n }\n\n inline fun p(arr: Array?, separator: String = \" \", range: IntRange? = arr?.indices) = this.also {\n range?.forEach { prep(it > 0, separator, arr?.get(it)) }\n }\n\n inline fun p(list: List?, separator: String = \" \", range: IntRange? = list?.indices) = this.also {\n range?.forEach { prep(it > 0, separator, list?.get(it)) }\n }\n\n inline fun p(stack: Stack?, separator: String = \" \", range: IntRange? = stack?.indices) = this.also {\n range?.forEach { prep(it > 0, separator, stack?.get(it)) }\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 = \" \", range: IntRange? = arr?.indices) = p(arr, separator, range).pln()\n inline fun pln(arr: LongArray?, separator: String = \" \", range: IntRange? = arr?.indices) = p(arr, separator, range).pln()\n inline fun pln(arr: DoubleArray?, separator: String = \" \", range: IntRange? = arr?.indices) = p(arr, separator, range).pln()\n inline fun pln(arr: Array?, separator: String = \" \", range: IntRange? = arr?.indices) = p(arr, separator, range).pln()\n inline fun pln(list: List?, separator: String = \" \", range: IntRange? = list?.indices) = p(list, separator, range).pln()\n inline fun pln(stack: Stack?, separator: String = \" \", range: IntRange? = stack?.indices) = p(stack, separator, range).pln()\n\n inline fun flush() = out.flush()\n\n //////////////////////////////////////\n\n fun run() {\n val n = ni()\n val p = nia(n / 2, -1)\n p.sort()\n var chan = 0\n var count = 0\n for (pi in p) {\n chan += abs(pi - count)\n count += 2\n }\n\n var le = 0\n count = 1\n for (pi in p) {\n le += abs(pi - count)\n count += 2\n }\n pln(min(chan,le))\n }\n\n}\n\n//////////////////////////////////////\nfun main(args: Array) {\n val inp = File(\"A.txt\")\n if (A.ONLINE_JUDGE || !inp.isFile) {\n val a = A(System.`in`, PrintWriter(BufferedOutputStream(System.out)))\n a.run()\n a.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.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": "87a4a86a66d29afe38c25fc74bc0a2c9", "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun Int.isHit(list: List): Boolean {\n\tvar result = false\n\tfor (i: Int in list)\n\t\tif (this % i == 0)\n\t\t\tresult = true\n\treturn result\t\n}\n\nfun solve(): Int {\n\tval sc = Scanner(System.`in`)\n\tval dividers = listOf(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt())\n\tval total_dragons = sc.nextInt()\n\tif (dividers.any {it == 1}) return total_dragons\n\tvar damaged_dragons = 0\n\tfor (i: Int in 1..total_dragons)\n\t\tif (i.isHit(dividers)) damaged_dragons ++\n\treturn damaged_dragons\t\t\n}\n\nfun main() { println(solve()) }\n", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "d501f5e2842d62b1479b246306a38ef3", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\ndata class Team(val h: Byte, val o: Byte)\n\nfun main(){\n\n val scan = Scanner(System.`in`)\n val n = scan.nextInt()\n val teamArr = Array(n){_ -> Team(scan.nextByte(), scan.nextByte())}\n var c = 0\n\n\n for (i in 0 until n){\n for (j in 0 until n){\n if ((teamArr[i].h == teamArr[j].o)) c++\n }\n }\n\n print(c)\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "182d79de3258a7c898da261542d90762", "src_uid": "745f81dcb4f23254bf6602f9f389771b", "difficulty": 800.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 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 factorial(n: Int): Long {\n var res = 1L\n for(i in 1..n) {\n res *= i\n }\n return res\n }\n\n var n = readInt()\n var ways = factorial(n/2) / (n/2)\n if(n == 2 || n == 4) ways = 1\n\n var lim = 1\n for(i in 0 until n) {\n lim *= 2\n }\n\n var res = 0L\n for(mask in 0 until lim) {\n if(mask.countOneBits() != n/2) continue\n res += ways * ways;\n }\n res /= 2\n\n println(res)\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "59c729778e518c12fe461aff62179b14", "src_uid": "ad0985c56a207f76afa2ecd642f56728", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package com.happypeople.codeforces.c1136\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) {\n try {\n B1136().run()\n } catch (e: Throwable) {\n println(\"\")\n e.printStackTrace()\n }\n}\n\nclass B1136 {\n fun run() {\n val sc = Scanner(systemIn())\n val n=sc.nextInt()\n val k=sc.nextInt()\n\n val ans=\n if(n==2)\n 6\n else if(k==1 || k==n)\n n*3\n else {\n val m=min(k, n-k+1)\n m * 2 + (m - 1) * 2 + 1 + (n - m) * 3\n }\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", "constructive algorithms"], "code_uid": "3828098e83df5c087be4187511dd46d3", "src_uid": "24b02afe8d86314ec5f75a00c72af514", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun min(a: Int, b:Int): Int{\n return if (a > b) b else a\n}\nfun main(args: Array){\n\n var (l,p,a) = readLine().toString().split(\" \").map{x -> x.toInt()}\n\n while(l!=p&&a>0){\n\n if(l1){\n l++\n p++\n a-=2\n }\n\n print(min(l,p)*2)\n\n\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "9fa3acc7d59f3118e84fc59a7546f842", "src_uid": "e8148140e61baffd0878376ac5f3857c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun readInt() = readLine()!!.toInt()\nfun readInts() = readLine()!!.split(' ').map { it.toInt() }\n\n// R -> S\n// S -> P\n// P -> R\n\nfun main() {\n val n = readInt()\n val (aR, aS, aP) = readInts()\n val (bR, bS, bP) = readInts()\n\n val mn = max(0, aR - bR - bP) + max(0, aS - bS - bR) + max(0, aP - bS - bP)\n val mx = min(aR, bS) + min(aS, bP) + min(aP, bR)\n println(\"$mn $mx\")\n}\n\n// R S P\n// 0 1 1\n// 1 1 0\n\n// S -> R\n// P -> S", "lang_cluster": "Kotlin", "tags": ["brute force", "constructive algorithms", "flows", "math", "greedy"], "code_uid": "31eafb4fc6d4846b42b60a10c409de8f", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array){\n val N = readLine()!!.toInt()\n val Matrix = Array(N) {Array(N) {0}}\n for (i in 0 until N){\n Matrix[i] = readLine()!!.split(' ').map { it.toInt() }.toTypedArray()\n }\n var Score = 0\n for(i in 0 until N){\n for(j in 0 until N){\n //j == N - i - 1 для побочной диагонали\n // i == (N - 1)/2 для средней строки\n\n if( j == N - i - 1 || i == j || i == (N - 1)/2 || j == (N-1)/2) {\n Score +=Matrix[i][j]\n }\n }\n\n }\n println(Score)\n\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8f7193094ad50a9f15f433de7971025c", "src_uid": "5ebfad36e56d30c58945c5800139b880", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.min\n\nfun main() {\n var tokenizer = StringTokenizer(readLine()!!)\n val n = tokenizer.nextToken().toInt()\n var l = tokenizer.nextToken().toLong()\n tokenizer = StringTokenizer(readLine()!!)\n val costs = LongArray(31) { if (it < n) tokenizer.nextToken().toLong() else Long.MAX_VALUE }\n for (j in 1 until 31) {\n costs[j] = min(costs[j], 2L * costs[j - 1])\n }\n fun getAnswer(v: Long): Long {\n var res = 0L\n for (j in 0 until 31) {\n if ((v shr j) and 1L != 0L) {\n res += costs[j]\n }\n }\n return res\n }\n var answer = Long.MAX_VALUE\n while (l <= 1L shl 30) {\n answer = min(answer, getAnswer(l))\n l += l and -l\n }\n println(answer)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "dp", "bitmasks"], "code_uid": "1305ae9312faea44dafc9b29af574e65", "src_uid": "04ca137d0383c03944e3ce1c502c635b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val jin = Scanner(System.`in`)\n fun readRectangle(): Rectangle {\n val x1 = jin.nextLong()\n val y1 = jin.nextLong()\n val x2 = jin.nextLong()\n val y2 = jin.nextLong()\n return Rectangle(x1, x2, y1, y2)\n }\n val white = readRectangle()\n val black1 = readRectangle()\n val black2 = readRectangle()\n val rem = white.area() - white.intersection(black1).area() - white.intersection(black2).area() + white.intersection(black1).intersection(black2).area()\n println(if (rem > 0L) \"YES\" else \"NO\")\n}\n\ndata class Rectangle(val x1: Long, val x2: Long, val y1: Long, val y2: Long) {\n fun area() = (x2 - x1) * (y2 - y1)\n fun intersection(other: Rectangle): Rectangle {\n if (other.x1 >= x2 || x1 >= other.x2 || other.y1 >= y2 || y1 >= other.y2) {\n return Rectangle(-1L, -1L, -1L, -1L)\n }\n return Rectangle(max(x1, other.x1), min(x2, other.x2), max(y1, other.y1), min(y2, other.y2))\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "geometry"], "code_uid": "dda2d38e70388515cb21ae4f754b7505", "src_uid": "05c90c1d75d76a522241af6bb6af7781", "difficulty": 1700.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 readLine()\n val minutes = mutableListOf(0)\n minutes.addAll(readInts())\n minutes.add(90)\n for (pos in 0 until minutes.size - 1)\n if(minutes[pos] + 15 < minutes[pos + 1]) return print(minutes[pos] + 15)\n print(90)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "97e05ad7c22992c89fd12dd4cbeb560b", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.math.BigInteger\nimport java.util.*\n\nconst val M = 998244353L\nval MB = BigInteger.valueOf( M )\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n = sc.nextLong()\n val m = sc.nextLong()\n val k = sc.nextLong()\n if ( k == 0L ) {\n println( m )\n return\n }\n val C = Array( n.toInt(), { LongArray( it + 2 ) } )\n for ( i in C.indices ) {\n C[i][0] = 1\n for ( j in 1 .. i ) {\n C[i][j] = C[i - 1][j - 1] + C[i - 1][j]\n if ( C[i][j] >= M ) {\n C[i][j] -= M\n }\n }\n }\n println( BigInteger.valueOf( m - 1 ).modPow( BigInteger.valueOf( k ), MB ).multiply( BigInteger.valueOf( C[(n - 1).toInt()][k.toInt()] * m ) ).remainder( MB ) )\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "6cdb83180f9484789097c1e40d6d20f5", "src_uid": "b2b9bee53e425fab1aa4d5468b9e578b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.PrintWriter\nimport kotlin.math.abs\nimport kotlin.math.max\n\nfun main(args: Array) {\n io.apply {\n\n val n = int\n val ans = when(n) {\n 1 -> 1\n 2, 4, 5 -> 3\n 3, in 6..13 -> 5\n in 14..25 -> 7\n in 26..41 -> 9\n in 42..61 -> 11\n in 62..85 -> 13\n else -> 15\n }\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", "dp", "constructive algorithms"], "code_uid": "83f4f0b490eb1da7ad4b686389eddf08", "src_uid": "01eccb722b09a0474903b7e5abc4c47a", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main(args: Array) {\n val n = readLine()!!.toLong()\n var lo = 0L\n var hi = n\n while (lo < hi - 1) {\n val k = (lo + hi) / 2\n var cur = n\n var sum = 0L\n while (cur > 0) {\n val v = min(k, cur)\n sum += v\n cur -= v\n val p = cur / 10\n cur -= p\n }\n if (2 * sum >= n) {\n hi = k\n } else {\n lo = k\n }\n }\n println(hi)\n}", "lang_cluster": "Kotlin", "tags": ["implementation", "binary search"], "code_uid": "5afeef9e5b6066d9230def4292e1fb68", "src_uid": "db1a50da538fa82038f8db6104d2ab93", "difficulty": 1500.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 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 c()\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 val t = readInt()\n repeat(t) {\n val n = readInt()\n val e = readInts().sorted()\n\n var ans = 0\n\n var i = 0\n while (i < n) {\n var k = e[i]\n var j = 0\n\n while (j < k && i + j < n) {\n k = e[i + j]\n j++\n }\n\n if (j == k) {\n ans++\n }\n i += j\n }\n\n println(ans)\n }\n}\n\nfun b() {\n val t = readInt()\n repeat(t) {\n val n = readInt()\n\n val s = readInts()\n val d = IntArray(n + 1)\n\n d[1] = 1\n\n for (i in 2 until n + 1) {\n var j = 1\n d[i] = 1\n while (j * j <= i) {\n if (i % j == 0) {\n val k = i / j\n if (s[i - 1] > s[j - 1]) d[i] = maxOf(d[i], d[j] + 1)\n if (s[i - 1] > s[k - 1]) d[i] = maxOf(d[i], d[k] + 1)\n }\n j++\n }\n }\n\n println(d.max()!!)\n }\n}\n\nprivate fun dif(a: Int, b: Int, i: Int): Int {\n val ai = (i % a) % b\n val bi = (i % b) % a\n\n return if (ai != bi) 1 else 0\n}\n\nprivate fun fff(p: IntArray, x: Long): Long {\n val n = p.size\n val times = x / n\n val rem = (x % n).toInt()\n return times * p.last() + p[rem]\n}\n\n\nfun c() {\n val (a, b, c, d) = readLongs()\n\n var ans = 0L\n\n var aSide = a\n var bSide = b\n\n for (k in c..d) {\n while (aSide + bSide <= k && aSide < b) aSide++\n while (aSide + bSide <= k && bSide < c) bSide++\n\n if (aSide + bSide > k) {\n ans += (c - bSide + 1) * (b - aSide + 1)\n\n val aDiff = aSide - a\n val bDiff = c - bSide\n\n// println(\"aDiff = $aDiff, bDiff = $bDiff\")\n\n if (bDiff <= aDiff) {\n ans += bDiff * (bDiff + 1) / 2\n } else {\n val s = bDiff - aDiff\n ans += bDiff * (bDiff + 1) / 2 - s * (s + 1) / 2\n }\n// println(\"$k, $aSide, $bSide: $ans\")\n }\n }\n\n println(ans)\n}\n\n\nfun d() {\n val cost: IntArray = intArrayOf(4,3,2,5,6,7,2,5,5)\n val target: Int = 9\n// val cost: IntArray = intArrayOf(7,6,5,5,5,6,8,7,8)\n// val target: Int = 12\n// val cost: IntArray = intArrayOf(2,4,6,2,4,6,4,4,4)\n// val target: Int = 5\n// val cost: IntArray = intArrayOf(6,10,15,40,40,40,40,40,40)\n// val target: Int = 5000\n// val cost: IntArray = intArrayOf(1,1,1,1,1,1,1,1,1)\n// val target: Int = 5000\n\n val d = Array(target + 1) { IntArray(target + 1) { -1 } }\n d[0][0] = 0\n\n var lastTarget = 0\n for (i in 1 until target + 1) {\n for (j in i until target + 1) {\n d[i][j] = -1\n\n for (k in 8 downTo 0) {\n val c = cost[k]\n if (c <= j && d[i - 1][j - c] != -1) {\n d[i][j] = k + 1\n break\n }\n }\n }\n\n if (d[i][target] != -1) {\n lastTarget = i\n }\n }\n\n if (lastTarget == 0) {\n println(\"0\")\n return\n }\n val ans = IntArray(lastTarget)\n var j = target\n for (i in lastTarget downTo 1) {\n val k = d[i][j]\n ans[i - 1] = k\n j -= cost[k - 1]\n }\n\n ans.reverse()\n\n println(ans.joinToString(separator = \"\"))\n}\n\nprivate inline fun sqr(x: Int) = 1L * x * x\n\nfun e() {\n val (n, m) = readInts()\n val land = readInts().sorted()\n val (g, r) = readInts()\n\n val d = Array(m) { LongArray(g + 1) { Long.MAX_VALUE } }\n d[0][0] = 0\n\n val q = PriorityQueue>( compareBy { it.first } )\n\n q.add(Triple(0, 0, 0))\n\n while (q.isNotEmpty()) {\n var (len, i, j) = q.poll()\n\n// println(\"$len, $i, $j\")\n\n if (i == m - 1) break\n if (d[i][j] < len) continue\n\n if (j == g) {\n j = 0\n len += r\n if (d[i][j] < len) continue\n }\n\n if (i > 0) {\n val l = land[i] - land[i - 1]\n if (j + l <= g && d[i - 1][j + l] > len + l) {\n d[i - 1][j + l] = len + l\n q.add(Triple(len + l, i - 1, j + l))\n }\n }\n if (i < m - 1) {\n val l = land[i + 1] - land[i]\n if (j + l <= g && d[i + 1][j + l] > len + l) {\n d[i + 1][j + l] = len + l\n q.add(Triple(len + l, i + 1, j + l))\n }\n }\n }\n\n val ans = d[m - 1].min()!!\n println(if (ans < Long.MAX_VALUE) ans else -1)\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", "lang_cluster": "Kotlin", "tags": ["two pointers", "math", "implementation", "binary search"], "code_uid": "fa93a1e6eebdb46e46110b38cfe295f8", "src_uid": "4f92791b9ec658829f667fcea1faee01", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main() {\n readLine()\n val array = mutableListOf(0)\n array.addAll(readLine()!!.split(\" \").map(String::toInt))\n array.add(1001)\n var sol = 0\n var current = 0\n for (elementPos in 1 until array.size - 1) {\n if (array[elementPos - 1] + 1 == array[elementPos] &&\n array[elementPos] + 1 == array[elementPos + 1]\n )\n current++\n else\n current = 0\n sol = max(sol, current)\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "cc76c835d1b1e1095d88e8503967d94d", "src_uid": "858b5e75e21c4cba6d08f3f66be0c198", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n\n val n = sc.nextInt()\n val cubes = Array(n * 6, { _ -> HashSet()})\n var notz = false\n for (i in 0 until n) {\n for (j in 0 until 6) {\n val cur = sc.nextInt()\n if (cur != 0) {\n notz = true\n }\n cubes[i].add(cur)\n }\n }\n if (!notz) {\n println(0)\n } else {\n for (i in 1..1001) {\n if (i == 1000 || !aux(cubes, i)) {\n println(i - 1)\n break\n }\n }\n }\n}\n\nfun aux(pos: Array>, num: Int):Boolean {\n val hun = if (num / 100 > 0) num / 100 else null\n val ten = if ((num % 100) / 10 > 0) (num % 100) / 10 else null\n val one = num % 10\n if (ten == null && hun == null) {\n return one in pos[0] || one in pos[1] || one in pos[2]\n }\n if (hun == null) {\n return one in pos[0] && (ten in pos[1] || ten in pos[2]) ||\n one in pos[1] && (ten in pos[0] || ten in pos[2]) ||\n one in pos[2] && (ten in pos[0] || ten in pos[1])\n }\n return one in pos[0] && ten in pos[1] && hun in pos[2] ||\n one in pos[1] && ten in pos[0] && hun in pos[2] ||\n one in pos[0] && ten in pos[2] && hun in pos[1] ||\n one in pos[1] && ten in pos[2] && hun in pos[0] ||\n one in pos[2] && ten in pos[1] && hun in pos[0] ||\n one in pos[2] && ten in pos[0] && hun in pos[1]\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "859d87c67120a13d2a0350db388d3a05", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val n = readLine()!!.toInt()\n var num = readLine()!!.split(' ').map { it.toInt() }.toIntArray()\n var count = Array(100){0}\n for (i in num){\n count[i-1]++\n }\n var max = 0\n for ( i in count )\n max = if (i > max) i else max\n print(max)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "5370b7afe5c2ba612b08fd53c0acb97b", "src_uid": "f30329023e84b4c50b1b118dc98ae73c", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val t = readLine()!!.toInt()\n val output = IntArray(t)\n for(tc in 0 until t){\n val (n, k, d) = readLine()!!.split(' ').map(String::toInt)\n val a = readLine()!!.split(' ').map(String::toInt)\n var min = Int.MAX_VALUE\n for(i in 0..(n - d)) {\n val c = a.subList(i, i + d).distinct()\n if (c.size < min) {\n min = c.size\n }\n }\n output[tc] = min\n }\n println(output.joinToString(\"\\n\"))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "1bedc15b4627cc7f00860e9c702d7ba4", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun DataReader.solve(out: PrintWriter) {\n val n = nextInt()\n val k = nextInt()\n\n val s = nextToken()\n\n val used = BooleanArray(n)\n\n fun dfs(u: Int): Boolean {\n if (u < 0 || u >= n || used[u] || s[u] == '#') return false\n if (s[u] == 'T') return true\n used[u] = true\n\n return dfs(u - k) || dfs(u + k)\n }\n\n out.println(dfs(s.indexOf('G')).toYesNo())\n}\n\nfun Boolean.toYesNo() = if (this) \"YES\" else \"NO\"\n\nclass DataReader(private val reader: BufferedReader) {\n var st : StringTokenizer? = null\n companion object {\n fun createFromFile(name: String) = DataReader(BufferedReader(FileReader(name)))\n }\n\n fun next() : String? {\n while (st == null || !st!!.hasMoreTokens()) {\n val s = reader.readLine() ?: return null\n st = StringTokenizer(s)\n }\n\n return st?.nextToken()\n }\n\n fun nextToken() = next()!!\n\n fun nextInt() = nextToken().toInt()\n fun nextLong() = nextToken().toLong()\n fun readIntArray(n: Int) : IntArray {\n val result = IntArray(n)\n result.indices.forEach { i -> result[i] = nextInt() }\n return result\n }\n\n fun nextLine() = reader.readLine()\n}\n\nfun main(args: Array) {\n val r: Reader\n val out: PrintWriter\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n r = FileReader(\"input.txt\")\n out = PrintWriter(\"output.txt\")\n } else {\n r = InputStreamReader(System.`in`)\n out = PrintWriter(System.out)\n }\n\n DataReader(BufferedReader(r)).solve(out)\n out.flush()\n}\n", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "fb6678cedcaad6b6f894c118edd54369", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var numbers = readLine()!!.split(\" \").map { it.toInt() }.sorted().toIntArray()\n\n if(numbers[0] + numbers[3] == numbers[2] + numbers[1] ||\n numbers[3] == numbers[1] + numbers[2] + numbers[0]) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "9656b59aa6fc0a1b796dcc2cc1cd01e0", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.*\nfun main() {\n val fs = CodeForces.FastReader()\n var n = fs.nextLong()\n var k = fs.nextLong()\n var set = HashSet()\n var bool = true\n for (i in 1..k) {\n var rest = n%i\n if(!set.contains(rest)) set.add(rest)\n else{\n bool = false\n break;\n }\n }\n if(bool) println(\"Yes\") else println(\"No\")\n}\n\nclass CodeForces {\n internal class FastReader {\n private var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\n private 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 }\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 return str\n }\n\n fun readIntArray(n: Int): IntArray {\n val a = IntArray(n)\n for (i in 0 until n) a[i] = nextInt()\n return a\n }\n\n fun readLongArray(n: Int): LongArray {\n val a = LongArray(n)\n for (i in 0 until n) a[i] = nextLong()\n return a\n }\n\n fun readDoubleArray(n: Int): DoubleArray {\n val a = DoubleArray(n)\n for (i in 0 until n) a[i] = nextDouble()\n return a\n }\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "number theory"], "code_uid": "14cee42f18bc45b7b2cb8f1ba3dff33c", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2", "difficulty": 1600.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\n pw.print(\"1 \")\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": "9b9255fe6e7654d1726eac0d93608041", "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.*\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 C = nl()\n val happy = nal(2)\n val weight = nal(2)\n\n fun swap(A: LongArray) {\n val t = A[0]\n A[0] = A[1]\n A[1] = t\n }\n\n fun swap() {\n swap(happy)\n swap(weight)\n }\n\n if (weight.max()!! >= 100) {\n if (weight[0] < weight[1]) swap()\n // weight0 >= weight1 にする\n var ans = 0L\n var c0 = 0L\n while(c0 * weight[0] <= C) {\n val c1 = (C - c0 * weight[0]) / weight[1]\n ans = max(ans, c0 * happy[0] + c1 * happy[1])\n c0++\n }\n out.println(ans)\n } else {\n if (happy[0] * weight[1] < happy[1] * weight[0]) swap()\n // H0/W0 >= H1/W1 にする\n var ans = 0L\n var c1 = 0L\n while(c1 * weight[1] <= C && c1 <= weight[0] * weight[1]) {\n val c0 = (C - c1 * weight[1]) / weight[0]\n ans = max(ans, c0 * happy[0] + c1 * happy[1])\n c1++\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\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl() + offset\n }\n return res\n }\n\n private fun na2(n: Int, offset: Int = 0): Array {\n val a = Array(2){IntArray(n)}\n for (i in 0 until n) {\n for (e in a) {\n e[i] = ni() + offset\n }\n }\n return a\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n private fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "brute force"], "code_uid": "3c4367fb3e40f5889d512eff3438a671", "src_uid": "eb052ca12ca293479992680581452399", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.math.max\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n var a = reader.nextInt()\n var b = reader.nextInt()\n var c = reader.nextInt()\n var d = reader.nextInt()\n\n var mPoints = max((3*a)/10.0,a-(a/250.0)*c)\n var vPoints = max((3*b)/10.0,b-(b/250.0)*d)\n\n if(mPoints > vPoints) print(\"Misha\")\n else if (mPoints < vPoints) print(\"Vasya\")\n else print(\"Tie\")\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "def08d1fed2e0c5b49c80134f867534e", "src_uid": "95b19d7569d6b70bd97d46a8541060d0", "difficulty": 900.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 cntA = scanner.nextInt()\n val cntB = scanner.nextInt()\n var cntC = scanner.nextInt()\n val cntD = scanner.nextInt()\n\n if (cntA == cntD && (cntA != 0 || cntC <= 0)) {\n print(\"1\")\n }\n else {\n print(\"0\")\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "a1e9e7cc6f18311443b687dd11492bf8", "src_uid": "b99578086043537297d374dc01eeb6f8", "difficulty": 1100.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 m = readInt()\n\n val A = readIntArray(n+n)\n val B = readIntArray(m+m)\n\n val M = Array(n) { i ->\n IntArray(m) { j ->\n val a0 = A[i+i]\n val a1 = A[i+i+1]\n val b0 = B[j+j]\n val b1 = B[j+j+1]\n\n var cn = 0\n var res = -1\n\n if(a0 == b0) { cn++; res = a0 }\n if(a0 == b1) { cn++; res = a0 }\n if(a1 == b0) { cn++; res = a1 }\n if(a1 == b1) { cn++; res = a1 }\n\n if(cn > 1) -1 else res\n }\n }\n\n val ans = run ans@ {\n var ans = -1\n for (i in 0 until n) {\n var t = -1\n for (e in M[i]) if(e != -1) {\n when {\n t == -1 -> t = e\n t != e ->\n return@ans -1\n }\n }\n if(t == -1) continue\n when {\n ans == -1 -> ans = t\n ans != t -> ans = 0\n }\n }\n\n for (j in 0 until m) {\n var t = -1\n for (i in 0 until n) {\n val e = M[i][j]\n if(e != -1) when {\n t == -1 -> t = e\n t != e ->\n return@ans -1\n }\n }\n if(t == -1) continue\n when {\n ans == -1 -> ans = t\n ans != t -> ans = 0\n }\n }\n\n ans\n }\n\n println(ans)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\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 雪花飄飄北風嘯嘯天地一片蒼茫() { 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": ["brute force", "bitmasks"], "code_uid": "599e9af49e707c4a0c2092103e40052a", "src_uid": "cb4de190ae26127df6eeb7a1a1db8a6d", "difficulty": 1900.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 var a = 1\n var b = 1\n while(b<=n){\n\n if(b==n){\n println(\"YES\")\n break\n }\n else {\n a = a + 1\n b= b + a\n }\n }\n\n if(b!=n){\n println(\"NO\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "2b32a0b4a2c192143ef3d29b564b7a8b", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n import java.util.*\nfun main(args : Array)\n{\n\tval sc = Scanner(System.`in`)\n\t\n\tvar l = sc.nextLong()\n\tval r = sc.nextLong()\n\tvar cnt = 0\n\tfor(i in 0..32)\n\t{\n\t\tfor(j in 0..32)\n\t\t{\n\t\t\tvar temp = Math.pow(2.0,i*1.0)*Math.pow(3.0,j*1.0)\n\t\t\tif(temp >= l && temp<=r)\n\t\t\t\tcnt++\n\t\t\telse if(temp > r)\n\t\t\t\tbreak\n\t\t}\n\t}\n\tprintln(cnt)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "19626e9897fe3fdb4017ce41b278f0eb", "src_uid": "05fac54ed2064b46338bb18f897a4411", "difficulty": 1300.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 readLine()\n print(max(0, readInts().max()!! - 25))\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "1160ba3bf0cd1e957e56cd35132a68f9", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, k) = readLine()!!.split(' ').map(String::toInt)\n println(if (readLine()!!.groupBy { it }.values.map { it.size }.max()!! <= k) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "60354efd2f5e048d1cabc717207f76d6", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun readString(): String = readLine()!!.toString()\n\nfun main(){\n val input = readString()\n val result = input\n .replace(\"(WUB)+\".toRegex(), \" \")\n .trim()\n\n println(result)\n}", "lang_cluster": "Kotlin", "tags": ["strings"], "code_uid": "2620932973f70c26aecf30e6ae601a14", "src_uid": "edede580da1395fe459a480f6a0a548d", "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 t = reader.next()\n val m = getM(n)\n var j = 0\n for (i in 1..m) {\n writer.print(t[j])\n j += i\n }\n writer.println()\n}\n\nfun getM(n: Int): Int {\n for (i in 1..10) {\n if (i * (i + 1) == 2 * n) {\n return i\n }\n }\n return -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": ["implementation"], "code_uid": "6d71e34a669185e348054f2650a3a4b9", "src_uid": "08e8c0c37b223f6aae01d5609facdeaf", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val visited = mutableMapOf, Int>().withDefault { 0 }\n visited[0 to 0] = 1\n val instructionToMovement = mapOf('U' to (0 to 1), 'D' to (0 to -1), 'L' to (-1 to 0), 'R' to (1 to 0))\n readLine()\n var sol = 0\n var pos = 0 to 0\n for (c in readLine()!!) {\n val movement = instructionToMovement[c]!!\n pos = pos.first + movement.first to pos.second + movement.second\n sol += visited.getValue(pos)\n visited[pos] = visited.getValue(pos) + 1\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "0a7d233d92d4d478b38fce2df062b93b", "src_uid": "7bd5521531950e2de9a7b0904353184d", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun num_n_d_paths(n : Int, k : Int, d : Int) : Long {\n val modulo = 1000000007L\n val num_paths = Array(n + 1, {_ -> LongArray(k + 1)})\n for (i in 1 .. k) {\n if (i <= n) {\n num_paths[i][i] = 1L\n }\n }\n for (path_weight in 0 .. n) {\n for (max_weight_so_far in 1 .. k) {\n for (edge_weight in 1 .. k) {\n val new_path_weight = path_weight + edge_weight\n if (new_path_weight <= n) {\n if (max_weight_so_far >= edge_weight) {\n num_paths[new_path_weight][max_weight_so_far] =\n (num_paths[new_path_weight][max_weight_so_far] + num_paths[path_weight][max_weight_so_far]) % modulo\n } else {\n num_paths[new_path_weight][edge_weight] =\n (num_paths[new_path_weight][edge_weight] + num_paths[path_weight][max_weight_so_far]) % modulo\n }\n } else {\n break\n }\n }\n }\n }\n var result = 0L\n for (j in d .. k) {\n result = (result + num_paths[n][j]) % modulo\n }\n return result\n}\n\nfun main(args : Array) {\n val n_k_d_nullable_str = readLine()\n if (n_k_d_nullable_str == null) {\n // Do nothing ...\n } else {\n val n_k_d_str = n_k_d_nullable_str\n val n_k_d = n_k_d_str.split(' ').map(String::toInt)\n val n = n_k_d[0]\n val k = n_k_d[1]\n val d = n_k_d[2]\n val result = num_n_d_paths(n, k, d)\n println(\"${result}\")\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["dp", "implementation", "trees"], "code_uid": "8aa9a0170b487e7c2ceab0e4d0ed3b50", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun readInts(): List = readLine()!!\n .split(\" \")\n .map{it.toInt()}\n\nfun main(){\n val (n, m) = readInts()\n val players = mapOf(1 to \"Akshat\", 0 to \"Malvika\")\n val value = if (n > m) m else n\n val winner = value % 2\n println(players[winner])\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "ada5ecdf45b1f7f1a9a331549f78048a", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4", "difficulty": 900.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\nval F = MA.precomputeFactorials(200_000)\r\nfun Int.ma() = MA.ofInt(this)\r\n\r\nfun main() {\r\n// for (n in 1..5) {\r\n// for (k in 1..3) {\r\n// val s = solve(n, k).i\r\n// val sn = solveNaive(n, k)\r\n// if (s != sn) {\r\n// println(\"n=$n, k=$k, $s VS correct: $sn\")\r\n// }\r\n// }\r\n// }\r\n// println(\"OK\")\r\n\r\n repeat(bin.readInt()) {\r\n val (n, k) = bin.readInts()\r\n println(solve(n, k))\r\n }\r\n}\r\n\r\nfun solveNaive(n: Int, k: Int): Int {\r\n val nums = (0 until (1 shl k)).toList()\r\n\r\n fun combine(left: Int): List> {\r\n if (left == 0) return listOf(listOf())\r\n return combine(left-1).flatMap { tail ->\r\n nums.map { elt -> listOf(elt) + tail }\r\n }\r\n }\r\n\r\n var res = 0\r\n val opts = combine(n)\r\n for (v in opts) {\r\n if (wins(v)) res++\r\n }\r\n return res\r\n}\r\n\r\nfun wins(vs: List): Boolean {\r\n var ad = vs.first()\r\n var xr = vs.first()\r\n for (v in vs.drop(1)) {\r\n ad = ad and v\r\n xr = xr xor v\r\n }\r\n return ad >= xr\r\n}\r\n\r\nfun solve(n: Int, k: Int): IntMod {\r\n var eqb: IntMod = 0.ma()\r\n for (numOnes in 0..n step 2) {\r\n eqb += F.choose(n, numOnes)\r\n }\r\n\r\n return if (n % 2 == 0) {\r\n val eqc = Array(k+1) { 0.ma() }\r\n var eqv = 1.ma()\r\n for (i in 0..k) {\r\n eqc[i] = eqv\r\n eqv *= eqb - 1\r\n }\r\n val chooseAny = 2.ma().pow(n.toLong())\r\n\r\n var res = eqc[k]\r\n var rest = 1.ma()\r\n\r\n for (p in k-1 downTo 0) {\r\n res += eqc[p] * rest\r\n rest *= chooseAny\r\n }\r\n res\r\n } else {\r\n (eqb + 1).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", "dp", "combinatorics", "bitmasks", "matrices"], "code_uid": "05890f971a72ca56f047b41d68eed41c", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n readLine()\n val s = readLine()!!\n val sb = StringBuilder()\n if (s.contains('1')) sb.append('1')\n for (c in s) if (c == '0') sb.append('0')\n print(sb.toString())\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "69ce7326f112fc0782d5b0722dea750b", "src_uid": "ac244791f8b648d672ed3de32ce0074d", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "\r\nimport java.io.OutputStream\r\nimport java.io.PrintWriter\r\n\r\n// @author: noisegain\r\n\r\nfun main() = withFastOut(times = readInt()) {\r\n val s = Array(2) { readInts(2) }\r\n if (s.all { it == listOf(1, 1) }) {\r\n println(2)\r\n } else if (s.any { it.contains(1) }) {\r\n println(1)\r\n } else {\r\n println(0)\r\n }\r\n}\r\n/* Utilities */\r\nclass MyMap(\r\n private val back: MutableMap = mutableMapOf(),\r\n private val default: (K) -> V\r\n) : MutableMap by back {\r\n\r\n override tailrec fun get(key: K): V = if (key in back) back[key]!! else {\r\n put(key, default(key))\r\n get(key)\r\n }\r\n\r\n override fun equals(other: Any?) = back == other\r\n\r\n override fun hashCode() = back.hashCode()\r\n\r\n override fun toString() = back.toString()\r\n}\r\n\r\nfun , T2 : Comparable> pairCmp(): Comparator> = 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\nfun Boolean.toInt() = if (this) 1 else 0\r\n\r\n/* Output */\r\ninline fun withFastOut(\r\n out: OutputStream = System.out,\r\n times: Int = 1,\r\n fn: PrintWriter.() -> Unit\r\n) = PrintWriter(out).use { writer ->\r\n repeat(times) { fn(writer) }\r\n}\r\n\r\nfun PrintWriter.printVar(vararg x: Any?, sep: String = \" \") = println(x.joinToString(sep))\r\n\r\n/* Input */\r\nval INPUT = System.`in`\r\nconst val BUFFER_SIZE = 1 shl 16\r\nval buffer = ByteArray(BUFFER_SIZE)\r\nvar bufferPt = 0\r\nvar bytesRead = 0\r\n\r\ntailrec fun readChar(): Char {\r\n if (bufferPt == bytesRead) {\r\n bufferPt = 0\r\n bytesRead = INPUT.read(buffer, 0, BUFFER_SIZE)\r\n }\r\n return if (bytesRead < 0) Char.MIN_VALUE\r\n else {\r\n val c = buffer[bufferPt++].toChar()\r\n if (c == '\\r') readChar()\r\n else c\r\n }\r\n}\r\n\r\n\r\nfun readLine(): String? {\r\n var c = readChar()\r\n return if (c == Char.MIN_VALUE) null\r\n else buildString {\r\n while (true) {\r\n when (c) {\r\n '\\n', Char.MIN_VALUE -> return@buildString\r\n else -> {\r\n append(c)\r\n c = readChar()\r\n }\r\n }\r\n }\r\n }\r\n}\r\n\r\nfun readLn() = readLine()!!\r\n\r\nfun read() = buildString {\r\n var c = readChar()\r\n while (c <= ' ') {\r\n if (c == Char.MIN_VALUE) return@buildString\r\n c = readChar()\r\n }\r\n do {\r\n append(c)\r\n c = readChar()\r\n } while (c > ' ')\r\n}\r\n\r\nfun readInt() = read().toInt()\r\nfun readLong() = read().toLong()\r\nfun readInts(n: Int) = List(n) { readInt() }\r\nfun readLongs(n: Int) = List(n) { readLong() }\r\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\r\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "353d5f9d1b69d6c566229a81f4d6f7a7", "src_uid": "7336b8becd2438f0439240ee8f9610ec", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nval reader = Scanner(System.`in`)\nvar l=0\nvar r=0\nvar ans = 0\nvar flag = false\nfun main(args: Array){\n val n = reader.nextInt()\n\n val arr = Array(n,{i -> reader.nextInt()})\n\n arr.sort()\n\n\n /* arr.forEach { print(it)\n print(\" \")}*/\n\n r=n-1\n l=n-2\n while (true)\n {\n if(arr[r]>arr[l])\n {\n arr[r] = arr[r] - arr[l]\n flag = true\n }\n l--\n r--\n\n if(l==-1)\n {\n if (flag) {\n flag = false\n r = n - 1\n l = n - 2\n arr.sort()\n }\n else\n {\n arr.forEach { ans+=it }\n print(ans)\n return\n }\n }\n\n }\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "453ace428adda54bfc54f3068f9a3282", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (n, m, k) = readLine()!!.split(\" \").map(String::toInt)\n val a = readLine()!!.split(\" \").map(String::toInt)\n\n var i = 1\n\n while (true) {\n val p1 = m - 1 - i\n val p2 = m - 1 + i\n if (p1 >= 0 && a[p1] != 0 && a[p1] <= k || p2 < a.size && a[p2] != 0 && a[p2] <= k) {\n break\n }\n i++\n }\n\n println(i * 10)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "cbbb6773c2b4ebc0557273a3a47949c6", "src_uid": "57860e9a5342a29257ce506063d37624", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.math.BigDecimal\nimport java.math.BigInteger\nimport java.util.*\n\n\nobject programkt {\n interface Scanner {\n fun changeInputStream(inputStream: InputStream)\n fun nextInt(): Int\n fun nextLong(): Long\n fun nextDouble(): Double\n fun nextChar(): Char\n fun nextString(): String\n fun nextLine(): String\n fun nextBigInteger(): BigInteger\n fun nextBigDecimal(): BigDecimal\n }\n\n abstract class Task {\n //KT Extensions\n fun > min(a: T, b: T) = if (a > b) b else a\n fun > max(a: T, b: T) = if (a < b) b else a\n fun abs(a: Int) = if (a > 0) a else -(a)\n fun abs(a: Long) = if (a > 0) a else -(a)\n fun abs(a: Float) = if (a > 0) a else -(a)\n fun abs(a: Double) = if (a > 0) a else -(a)\n operator fun Iterable.invoke(function: (it: T) -> Unit) { this.forEach(function) }\n private fun String.prefix(pi: Array): Array {\n pi[0] = 0\n (1 until this.length) {\n var j = pi[it - 1]\n while (j > 0 && this[it] != this[j]) {\n j = pi[j - 1]\n }\n if(this[it] == this[j]) {\n j++\n }\n pi[it] = j\n }\n return pi\n }\n private fun String.kmpFind(pattern: String): Int {\n val m = pattern.length\n val dfa = Array(256) { IntArray(m) }\n dfa[pattern[0].toInt()][0] = 1\n var x = 0\n var j = 1\n while (j < m) {\n for (c in 0 until 256) {\n dfa[c][j] = dfa[c][x] // Copy mismatch cases.\n }\n dfa[pattern[j].toInt()][j] = j + 1 // Set match case.\n x = dfa[pattern[j].toInt()][x] // Update restart state.\n j++\n }\n\n val n = this.length\n var i: Int = 0\n j = 0\n while (i < n && j < m) {\n j = dfa[this[i].toInt()][j]\n i++\n }\n if (j == m) return i - m // found\n return n // not found\n }\n fun fuckExceptions(invoker: () -> Unit) = try { invoker.invoke() } catch (_: Throwable) {}\n\n enum class EdgeType {\n DIRECTED,\n UNDIRECTED\n }\n data class Vertex>(\n val data: T\n ) {\n override fun toString(): String = \"V:$data\"\n }\n data class Edge>(\n var source: Vertex,\n var destination: Vertex,\n val weight: Double?\n )\n interface Graphable> {\n fun createVertex(data: T): Vertex\n fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double? = 0.0)\n fun weight(source: Vertex, destination: Vertex): Double?\n fun edges(source: Vertex): MutableList>?\n }\n class AdjacencyList>: Graphable {\n var adjacencyMap: MutableMap, MutableList>> = mutableMapOf()\n\n private fun addDirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n adjacencyMap[source]?.add(Edge(source = source, destination = destination, weight = weight))\n }\n\n private fun addUndirectedEdge(source: Vertex, destination: Vertex, weight: Double?) {\n addDirectedEdge(source, destination, weight)\n addDirectedEdge(destination, source, weight)\n }\n\n override fun createVertex(data: T): Vertex {\n val vertex = Vertex(data = data)\n adjacencyMap[vertex] ?: run {\n adjacencyMap[vertex] = mutableListOf()\n }\n return vertex\n }\n\n override fun add(type: EdgeType, source: Vertex, destination: Vertex, weight: Double?) = when(type) {\n EdgeType.DIRECTED -> addDirectedEdge(source, destination, weight)\n EdgeType.UNDIRECTED -> addUndirectedEdge(source, destination, weight)\n }\n\n override fun weight(source: Vertex, destination: Vertex): Double? {\n adjacencyMap[source]?.forEach {\n if(it.destination == destination) return it.weight\n }\n return null\n }\n\n override fun edges(source: Vertex): MutableList>? = adjacencyMap[source]\n\n override fun toString(): String {\n var result = \"\"\n for ((vertex, edges) in adjacencyMap) {\n var edgeString = \"\"\n for ((index, edge) in edges.withIndex()) {\n edgeString += if (index != edges.count() - 1) \"${edge.destination}, \"\n else \"${edge.destination}\"\n }\n result += \"$vertex ---> [ $edgeString ] \\n\"\n }\n return result\n }\n\n fun depthFirstSearch(start: Vertex, end: Vertex): Stack> {\n val visited: HashSet> = hashSetOf()\n val stack: Stack> = Stack()\n stack.push(start)\n visited.add(start)\n\n var currentVertex = stack.peek()\n loop@while (currentVertex != null && currentVertex != end) {\n val neighbors = edges(currentVertex)\n if(neighbors != null && neighbors.count() > 0) {\n for(edge in neighbors) {\n if(!visited.contains(edge.destination)) {\n visited.add(edge.destination)\n stack.push(edge.destination)\n currentVertex = stack.peek()\n continue@loop\n }\n }\n } else {\n stack.pop()\n currentVertex = stack.peek()\n continue\n }\n\n stack.pop()\n currentVertex = stack.peek()\n }\n\n return stack\n }\n\n fun breadthFirstSearch() {\n\n }\n\n fun floydWarshallAlgorythm(): Pair, Array> {\n val nVertices = this.adjacencyMap.size\n\n val weights = Array(nVertices) { Array(nVertices-1) { 0.0 } }\n this.adjacencyMap\n .asSequence()\n .map { it.value }\n .withIndex()\n .forEach { (index, weightsOfVertex) ->\n weightsOfVertex.asSequence()\n .withIndex()\n .forEach { (weightIndex, weight) ->\n weights[index][weightIndex] = weight.weight!!\n }\n }\n\n val dist = Array(nVertices) { DoubleArray(nVertices) { Double.POSITIVE_INFINITY } }\n for (w in weights) dist[(w[0] - 1).toInt()][(w[1] - 1).toInt()] = w[2]\n val next = Array(nVertices) { IntArray(nVertices) }\n for (i in 0 until next.size) {\n for (j in 0 until next.size) {\n if (i != j) next[i][j] = j + 1\n }\n }\n for (k in 0 until nVertices) {\n for (i in 0 until nVertices) {\n for (j in 0 until nVertices) {\n if (dist[i][k] + dist[k][j] < dist[i][j]) {\n dist[i][j] = dist[i][k] + dist[k][j]\n next[i][j] = next[i][k]\n }\n }\n }\n }\n return dist to next\n }\n }\n\n fun > TreeMap>.toAdjacencyList(type: EdgeType): AdjacencyList {\n val list = AdjacencyList()\n\n this.keys.forEach { list.createVertex(it) }\n this.entries\n .asSequence()\n .withIndex()\n .forEach { (x, edge) ->\n val vertex = list.createVertex(edge.key)\n edge.value\n .asSequence()\n .withIndex()\n .forEach { (y, weight) ->\n if(weight != .0 && y != x)\n list.add(type, vertex, list.createVertex(this.keys.elementAt(y)), weight)\n }\n }\n return list\n }\n //End KT Extensions\n\n abstract fun solve(scanner: Scanner, printer: PrintWriter)\n }\n\n class FastScanner: Scanner {\n var inputStream: InputStream? = null\n override fun changeInputStream(inputStream: InputStream) {\n this.inputStream = inputStream\n this.bufferedReader = BufferedReader(InputStreamReader(inputStream))\n }\n\n private lateinit var bufferedReader: BufferedReader\n private var stringTokenizer: StringTokenizer? = null\n\n private fun nextToken(): String? {\n while (stringTokenizer == null || !stringTokenizer!!.hasMoreTokens())\n stringTokenizer = StringTokenizer(bufferedReader.readLine() ?: return null)\n return stringTokenizer!!.nextToken()\n }\n\n override fun nextInt() = nextToken()!!.toInt()\n override fun nextLong() = nextToken()!!.toLong()\n override fun nextDouble() = nextToken()!!.toDouble()\n override fun nextChar() = bufferedReader.read().toChar()\n override fun nextString() = nextToken()!!\n override fun nextLine() = bufferedReader.readLine()!!\n override fun nextBigInteger() = BigInteger(nextToken()!!)\n override fun nextBigDecimal() = BigDecimal(nextToken()!!)\n }\n\n class TaskBuilder {\n private var task: Task? = null\n private var inputStream: InputStream? = null\n private var outputStream: OutputStream? = null\n private var scanner: Scanner? = null\n\n fun useInputSource(inputStream: InputStream): TaskBuilder {\n this.inputStream = inputStream\n return this\n }\n\n fun useOutputSource(outputStream: OutputStream): TaskBuilder {\n this.outputStream = outputStream\n return this\n }\n\n fun useInputFile(inputFileName: String): TaskBuilder {\n this.inputStream = FileInputStream(File(inputFileName))\n return this\n }\n\n fun useOutputFile(outputFileName: String): TaskBuilder {\n this.outputStream = FileOutputStream(File(outputFileName))\n return this\n }\n\n fun useScanner(scanner: Scanner): TaskBuilder {\n this.scanner = scanner\n return this\n }\n\n\n fun solveTask(task: Task): TaskBuilder {\n this.task = task\n return this\n }\n\n fun run() {\n when {\n task == null -> throw NullPointerException(\"Task cannot be null!\")\n inputStream == null -> throw NullPointerException(\"Input cannot be null!\")\n outputStream == null -> throw NullPointerException(\"Output cannot be null!\")\n scanner == null -> throw NullPointerException(\"Scanner cannot be null!\")\n }\n scanner!!.changeInputStream(inputStream!!)\n val printer = PrintWriter(outputStream)\n TaskRunnable(task!!, scanner!!, printer).run()\n\n inputStream!!.close()\n printer.close()\n }\n\n class TaskRunnable(\n private val task: Task,\n private val scanner: Scanner,\n private val printer: PrintWriter\n ) {\n fun run() {\n task.solve(scanner, printer)\n }\n }\n }\n\n @JvmStatic\n fun main(args: Array) = TaskBuilder()\n .useInputSource(System.`in`)\n .useOutputSource(System.out)\n .useScanner(FastScanner())\n .solveTask(TaskA())\n .run()\n\n\n class TaskA: Task() {\n override fun solve(scanner: Scanner, printer: PrintWriter) {\n val (firstValency, secondValency, thirdValency) = scanner.nextLine()\n .split(\" \")\n .map { it.toLong() }\n val averageValency = (firstValency + secondValency + thirdValency) / 2\n\n if ((firstValency + secondValency + thirdValency) % 2 != 0L ) { printer.println(\"Impossible\"); return }\n\n val countOfConnectionsFirst = averageValency - thirdValency\n val countOfConnectionsSecond = averageValency - firstValency\n val countOfConnectionsThird = averageValency - secondValency\n\n when {\n countOfConnectionsFirst < 0 -> { printer.println(\"Impossible\"); return }\n countOfConnectionsSecond < 0 -> { printer.println(\"Impossible\"); return }\n countOfConnectionsThird < 0 -> { printer.println(\"Impossible\"); return }\n else -> printer.println(\"$countOfConnectionsFirst $countOfConnectionsSecond $countOfConnectionsThird\")\n }\n }\n\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "graphs"], "code_uid": "b372634d7a4a73334b707e220631f9c6", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc", "difficulty": 1200.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 r = scanner.nextLong()\n var g = scanner.nextLong()\n var b = scanner.nextLong()\n\n var ones = Math.min(r, Math.min(g, b))\n var ans = 0L\n r -= ones\n g -= ones\n b -= ones\n ans += r/3 + g/3 + b/3\n r %= 3\n g %= 3\n b %= 3\n\n while(ones > 0 && (r + g + b >= 4)){\n --ones\n r += 1\n g += 1\n b += 1\n ans += r/3 + g/3 + b/3\n r %= 3\n g %= 3\n b %= 3\n }\n\n\n //println(\"$r $g $b\")\n print(ans+ones)\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "fff9c411d503d8bce2a0429cd2a92bd1", "src_uid": "acddc9b0db312b363910a84bd4f14d8e", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport java.util.ArrayList\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n\n val pass: String = input.next()\n\n val n: Int = input.nextInt()\n val left = ArrayList()\n val right = ArrayList()\n\n for (i in 1..n) {\n val word = input.next()\n if (word == pass) {\n print(\"YES\")\n return\n }\n if (word[0] == pass[1]) {\n left.add(word)\n }\n if (word[1] == pass[0]) {\n right.add(word)\n }\n }\n\n if (left.size != 0 && right.size != 0) {\n print(\"YES\")\n return\n }\n\n print(\"NO\")\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "fe14b53da77c5393e5eb6d4f4db49634", "src_uid": "cad8283914da16bc41680857bd20fe9f", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.io.*\nimport java.util.*\n\nfun solve() {\n\n val n = nextInt()\n val g = nextArray(n)\n var playing1 = 1\n var playing2 = 2\n var nabl = 3\n var posible = true\n for (w in g.slice(0..g.size -1 )){\n if(w == playing1){\n val sw = nabl\n nabl = playing2\n playing2 = sw\n }else if(w == playing2){\n val sw = nabl\n nabl = playing1\n playing1 = sw\n } else{\n posible = false\n break\n }\n }\n println(if (posible) \"YES\" else \"NO\")\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 = 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": ["implementation"], "code_uid": "67c085f8407e3a0aae835995f7609d8a", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87", "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 k = sc.nextInt()\n val t = sc.nextInt()\n\n val min = Math.max(1, t - k + 1)\n val max = Math.min(n, t)\n\n println(max - min + 1)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "d8d68b2a0d525537b3e1e3392d0966e0", "src_uid": "7e614526109a2052bfe7934381e7f6c2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\n// 25 50 75 00\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val n = nextLine()\n val l = n.length\n val ref = ArrayList()\n\n var flag = false\n\n val _0 = n.count { it == '0' }\n val _2 = n.count { it == '2' }\n val _5 = n.count { it == '5' }\n val _7 = n.count { it == '7' }\n\n var leadingZeros = 0\n for (i in 1 until l) {\n if (n[i] == '0') {\n leadingZeros++\n } else {\n break\n }\n }\n\n if (_0 >= 2) { // ..00\n flag = true\n\n val i0a = n.lastIndexOf('0')\n val i0b = n.substring(0 until i0a).lastIndexOf('0')\n\n ref.add(2 * l - i0a - i0b - 3)\n }\n\n if (_2 >= 1 && _5 >= 1) if (leadingZeros != l - 2 || l == 2) { // ..25\n flag = true\n\n val i2 = n.lastIndexOf('2')\n val i5 = n.lastIndexOf('5')\n\n var r = 2 * l - i2 - i5 - 3\n if (i2 > i5) {\n if (i5 == 0) r += leadingZeros\n r += 1\n } else {\n if (i2 == 0) r += leadingZeros\n }\n\n ref.add(r)\n }\n\n if (_5 >= 1 && _0 >= 1) if (leadingZeros != l - 1 || l == 2) { // ..50\n flag = true\n var _leadingZeros = leadingZeros\n\n val i5 = n.lastIndexOf('5')\n val i0 = n.lastIndexOf('0')\n\n if (i0 == _leadingZeros) _leadingZeros--\n\n var r = 2 * l - i5 - i0 - 3\n if (i5 > i0) {\n r += 1\n } else {\n if (i5 == 0) r += _leadingZeros\n }\n\n ref.add(r)\n }\n\n if (_7 >= 1 && _5 >= 1) if (leadingZeros != l - 2 || l == 2) { // ..75\n flag = true\n\n val i7 = n.lastIndexOf('7')\n val i5 = n.lastIndexOf('5')\n\n var r = 2 * l - i7 - i5 - 3\n if (i7 > i5) {\n if (i5 == 0) r += leadingZeros\n r += 1\n } else {\n if (i7 == 0) r += leadingZeros\n }\n\n ref.add(r)\n }\n\n if (flag) {\n println(ref.min())\n } else {\n println(-1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy"], "code_uid": "22aeb5cd277ddd7bf9cb4603e2e627d7", "src_uid": "ea1c737956f88be94107f2565ca8bbfd", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var (n, m) = readLine()!!.split(\" \").map { it.toInt() }\n var steps = 0\n while (m > n){\n if (m % 2 == 0){\n m /= 2\n }else{\n m++\n }\n steps ++\n }\n println(steps + n - m)\n}", "lang_cluster": "Kotlin", "tags": ["dfs and similar", "shortest paths", "math", "graphs", "greedy", "implementation"], "code_uid": "f79189e0cf8fc26c396c4157a075da3a", "src_uid": "861f8edd2813d6d3a5ff7193a804486f", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.collections.*\nimport kotlin.io.*\nimport kotlin.math.*\nimport kotlin.Array\n\nclass Main{\n\n fun solve(inp : InputReader) {\n var (n,k) = inp.readlnInts()\n var lo = 0\n var hi = n\n var mid : Int = (lo + hi) / 2\n var ans = 2 * n \n while(lo <= hi){\n mid = (lo + hi) / 2\n var v : Int = 0\n var pw = 1\n while(pw <= mid){\n v += (mid / pw).toInt()\n if((n / k).toInt() >= pw){\n pw *= k\n } else {\n break\n }\n }\n if(v >= n){\n ans = min(ans,mid)\n hi = mid - 1\n } else {\n lo = mid + 1\n }\n }\n print(ans)\n }\n\n class InputReader{\n public fun readln() = readLine()!!\n public fun readlnInt() = readln().toInt()\n public fun readlnLong() = readln().toLong()\n public fun readlnDouble() = readln().toDouble()\n\n public fun readlnStrings() = readln().split(\" \")\n public fun readlnInts() = readlnStrings().map{it.toInt()}\n public fun readlnLongs() = readlnStrings().map{it.toLong()}\n public fun readlnDoubles() = readlnStrings().map{it.toDouble()}\n }\n}\n\nfun main(args : Array ){\n Main().solve(Main.InputReader())\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation", "binary search"], "code_uid": "77ece157e4ba31104588f5f0c7aa1a19", "src_uid": "41dfc86d341082dd96e089ac5433dc04", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Integer.max\nimport java.util.*\nimport kotlin.math.max\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val (yellowCristals, blueCristals) = arrayOf(nextLong(), nextLong())\n val(yellowBalls, greenBalls, blueBalls) = arrayOf(nextLong(), nextLong(), nextLong())\n val requitedYellowCristals = 2 * yellowBalls + greenBalls\n val requiredBlueCristals = greenBalls + 3 * blueBalls\n println(max(0, requiredBlueCristals - blueCristals) + max(0, requitedYellowCristals - yellowCristals))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "3fdf83fe021a29cb00e78eb5b09802e3", "src_uid": "35202a4601a03d25e18dda1539c5beba", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport java.io.*\n\nval MOD = 998244353L\n\nfun main()\n{\n\tThread(null, Main(), \"whatever\", 1 shl 28).start()\n}\n\nclass Main : Runnable {\n\n\toverride fun run()\n\t{\n\t\tval inputStream = System.`in`\n\t\tval outputStream = System.out\n\t\tval `in` = InputReader(inputStream)\n\t\tval out = PrintWriter(outputStream)\n\t\tval solver = TaskD()\n\t\tvar test = 1\n\t\t//test = `in`.nextInt()\n\t\tfor (t in 1..test)\n\t\t{\n\t\t\tsolver.solve(t, `in`, out)\n\t\t}\n\t\tout.close()\n\t}\n\n\tinternal class TaskD\n\t{\n\t\tfun solve(testNumber: Int, `in`: InputReader, out: PrintWriter) {\n\t\t\tval INF = 4000000000000000000L\n\t\t\tval dx = intArrayOf(-1, 1, 0, 0)\n\t\t\tval dy = intArrayOf(0, 0, -1, 1)\n\n\t\t\tvar n = `in`.nextLong()\n\t\t\tvar m = `in`.nextLong()\n\t\t\tvar L = `in`.nextLong()\n\t\t\tvar R = `in`.nextLong()\n\t\t\tvar len = R-L+1\n\t\t\t\n\t\t\tif (n*m%2 == 1L) return out.println(power(len, n*m, MOD))\n\n\t\t\tvar a = len/2\n\t\t\tvar b = len-a\n\t\t\tif (L%2 == 0L)\n\t\t\t{\n\t\t\t\tvar tmp = a\n\t\t\t\ta = b\n\t\t\t\tb = tmp\n\t\t\t}\n\n\t\t\tfun go(a: Long, b: Long, n: Long): Pair\n\t\t\t{\n\t\t\t\tif (n == 0L) return Pair(1, 0)\n\t\t\t\tvar (c, d) = go(a, b, n/2)\n\t\t\t\tvar (tc, td) = Pair((c*c+d*d)%MOD, (2*c*d)%MOD)\n\t\t\t\tc = tc\n\t\t\t\td = td\n\t\t\t\tif (n%2 == 1L)\n\t\t\t\t{\n\t\t\t\t\tvar (sc, sd) = Pair((a*c+b*d)%MOD, (a*d+b*c)%MOD)\n\t\t\t\t\tc = sc\n\t\t\t\t\td = sd\n\t\t\t\t}\n\t\t\t\treturn Pair(c, d)\n\t\t\t}\n\n\t\t\tvar (x, y) = go(a, b, n*m)\n\t\t\tout.println(x)\n\t\t}\n \n\t}\n\n\tinternal class InputReader(stream: InputStream) {\n\t\tvar reader: BufferedReader\n\t\tvar tokenizer: StringTokenizer? = null\n\n\t\tinit {\n\t\t\treader = BufferedReader(InputStreamReader(stream), 32768)\n\t\t\ttokenizer = null\n\t\t}\n\n\t\toperator fun next(): String {\n\t\t\twhile (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n\t\t\t\ttry {\n\t\t\t\t\ttokenizer = StringTokenizer(reader.readLine())\n\t\t\t\t} catch (e: IOException) {\n\t\t\t\t\tthrow RuntimeException(e)\n\t\t\t\t}\n\n\t\t\t}\n\t\t\treturn tokenizer!!.nextToken()\n\t\t}\n\n\t\tfun nextInt(): Int {\n\t\t\treturn Integer.parseInt(next())\n\t\t}\n\n\t\tfun nextLong(): Long {\n\t\t return next().toLong()\n\t\t}\n\n\t}\n}\n\nfun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a%b)\n\nfun power(a: Long, b: Long, p: Long): Long\n{\n\tif (b == 0L) return 1L\n\tvar t = power(a, b/2, p)\n\tt = t*t%p\n\tif (b%2 == 1L) t = t*a%p\n\treturn t\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "matrices", "constructive algorithms", "combinatorics"], "code_uid": "ecae9de3312a46f439a5842386fbec1d", "src_uid": "ded299fa1cd010822c60f2389a3ba1a3", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private fun readString() = readLine()!!\nprivate fun readInt() = readString().toInt()\nprivate fun readStrings() = readString().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n\nfun isBetter(current: Int, next: Int): Boolean = when(current) {\n 1 -> false\n 3 -> next == 1\n 2 -> next in setOf(1,3)\n 0 -> next != 4\n else -> throw IllegalArgumentException(\"Should never be more than 4, was $current\")\n}\n\n\nfun main() {\n val hp = readInt()\n var best = hp % 4\n var howMuch = 0\n for (i in 1..2) {\n val current = (hp + i) % 4\n if (isBetter(best, current)) {\n howMuch = i\n best = current\n }\n }\n print(howMuch)\n print(' ')\n println(\n when (best) {\n 0 -> 'D'\n 1 -> 'A'\n 2 -> 'C'\n 3 -> 'B'\n else -> throw IllegalArgumentException(\"Should never be more than 4, was $best\")\n }\n )\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "3c23e1927a07fb27ac6719284158be10", "src_uid": "488e809bd0c55531b0b47f577996627e", "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 (a, b, c, d) = r.readLine()!!.split(\" \").map { it.toInt() }\n val v256 = 256\n val v32 = 32\n val ans = minOf(a, c, d)*v256 + minOf(b, a- minOf(a, c, d))*v32\n println(ans)\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation", "brute force"], "code_uid": "ed8ff30c525a9517b93006e548d96056", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e", "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 n = scanner.nextInt()\n val x = Array(n) { scanner.nextInt() }\n val y = Array(n) { scanner.nextInt() }\n\n println(if (x.sum() >= y.sum()) \"YES\" else \"NO\")\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "1f391cd80a719ce5be25e6f51c05e09f", "src_uid": "e0ddac5c6d3671070860dda10d50c28a", "difficulty": 800.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// 所有函数的下标从 0 开始\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// 所有函数的下标从 0 开始\r\n// query(index): max[0, index]\r\n// udpate(index, x): 更新 [0, index] 之间的最大值,只能越来越大\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\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 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": "ec778129d58543dd0bb0505a7304e91f", "src_uid": "cedcc3cee864bf8684148df93804d029", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val hands = IntArray(3)\n val stringToNum = mapOf(\"rock\" to 1, \"paper\" to 2, \"scissors\" to 4)\n val posToWinner = \"FMS\"\n for (pos in 0..2) hands[pos] = stringToNum[readLine()!!]!!\n for (pos in 0..2)\n if (hands[pos] == (hands[(pos + 1) % 3] + hands[(pos + 2) % 3]) % 7) return print(posToWinner[pos])\n print('?')\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "70c74b0ff9fc0e5711ff76035805a990", "src_uid": "072c7d29a1b338609a72ab6b73988282", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (a, b, c, n) = readLine()!!.split(\" \").map { it.toInt() }\n if (c > a || c > b) {\n println(-1)\n return\n }\n val k = a + b - c\n if (k >= n) {\n println(-1)\n return\n }\n println(n - k)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "a1fb05a49b502f77dffbae85c5a60c3a", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce", "difficulty": 1000.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(!containsKey(k) || v < get(k)!!) put(k, v) }\n\n/** IO code start */\n@JvmField val _reader = System.`in`.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(System.out, false)\ninline fun output(block: PrintWriter.()->Unit) { _writer.apply(block).flush() }\nfun iprintln(o: Any?) { println(o) } // immediate println for interactive, bypasses output{} blocks", "lang_cluster": "Kotlin", "tags": ["brute force", "divide and conquer", "dfs and similar"], "code_uid": "d2855f85eaa1977341870afc6bd47ea3", "src_uid": "1b17a7b3b41077843ee1d6e0607720d6", "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.collections.ArrayList\nimport kotlin.math.sqrt\n\n\nfun main() {\n val sc = Scanner.sysIn\n\n val x = sc.nextInt()\n val n = sc.nextLong()\n\n val primes = ArrayList()\n\n fun isPrime(k: Int): Boolean {\n if (k == 1) return false\n if (k == 2 || k == 3) return true\n for (i in 2..sqrt(k.toDouble()).toInt()) {\n if (k % i == 0) {\n return false\n }\n }\n return true\n\n }\n\n for (i in 2..sqrt(x.toDouble()).toInt()) {\n if (x % i == 0) {\n if (isPrime(i) && !primes.contains(x / i))\n primes += i\n if (isPrime(x / i) && !primes.contains(x / i))\n primes += x / i\n }\n }\n if (isPrime(x)) primes += x\n\n //primes.forEach { println(it) }\n\n val mod = 1000000007\n fun power(x: Long, p: Long): Long = when {\n p == 0L -> 1\n p == 1L -> x % mod\n p % 2 == 0L -> {\n val cur = power(x, p / 2)\n (cur * cur) % mod\n }\n else -> (power(x, p - 1) * x) % mod\n }\n\n var ans = 1L\n\n for (p in primes) {\n var curP = p.toLong()\n while (n / curP > 0) {\n //println(curP)\n ans = (ans * power(p.toLong(), n / curP)) % mod\n if ((curP * p) / p != curP) break\n curP *= p\n }\n }\n\n println(ans)\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n val br: BufferedReader = BufferedReader(InputStreamReader(s))\n\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextLine(): String {\n return br.readLine()\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n companion object {\n val sysIn = Scanner(System.`in`)\n }\n\n}\n\nval rnd = Random()\nfun IntArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}\n\nfun LongArray.sort() {\n val n = this.size\n for (i in 0 until n - 1) {\n val randomPos = i + rnd.nextInt(n - i - 1) + 1\n this[i] = this[i] xor this[randomPos]\n this[randomPos] = this[randomPos] xor this[i]\n this[i] = this[i] xor this[randomPos]\n }\n Arrays.sort(this)\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "7ce8913db7b2da5e742ee214db1c4887", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.*\nfun main() {\n val fs = CodeForces.FastReader()\n var x = fs.nextInt()\n var y = fs.nextInt()\n if(x==0 && y==1) println(\"Yes\")\n else if(x==0 || y==0) println(\"No\")\n else if(x-y+1 >= 0 && (x-y-1)%2==0){\n if(y>=2 && x>=1) println(\"Yes\")\n else println(\"No\")\n }\n else println(\"No\")\n}\n\nclass CodeForces {\n internal class FastReader {\n private var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\n private 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 }\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 return str\n }\n\n fun readIntArray(n: Int): IntArray {\n val a = IntArray(n)\n for (i in 0 until n) a[i] = nextInt()\n return a\n }\n\n fun readLongArray(n: Int): LongArray {\n val a = LongArray(n)\n for (i in 0 until n) a[i] = nextLong()\n return a\n }\n\n fun readDoubleArray(n: Int): DoubleArray {\n val a = DoubleArray(n)\n for (i in 0 until n) a[i] = nextDouble()\n return a\n }\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "530544025d76a9ad4303ca8e0484121f", "src_uid": "1527171297a0b9c5adf356a549f313b9", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(vararg args: String) {\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 val (n, m, z) = readLine()!!.split(' ').map(String::toInt)\n println(z / nok(n, m))\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation"], "code_uid": "41204d8d0a21a6a374e1fdb7fef38f58", "src_uid": "e7ad55ce26fc8610639323af1de36c2d", "difficulty": 800.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)\n val Cnt = A.groupingBy { it }.eachCountTo(HashMap())\n val MAXN = A.max()!!\n val bit = BIT(MAXN)\n\n var ans = Int.MAX_VALUE\n\n for((a, cn) in Cnt) bit.add(a, cn)\n cnt@ for(a in 1..MAXN) {\n var need = k - (Cnt[a]?:0)\n var tot = 0\n var l = a\n var delta = 0\n var cost = 0\n\n while(need > 0) {\n l = l shl 1\n if(l > MAXN) continue@cnt\n cost++\n delta = (delta shl 1) + 1\n\n val get = minOf(need, bit.sum(l .. l + delta))\n need -= get\n tot += get * cost\n }\n\n if(tot < ans) ans = tot\n }\n\n println(ans)\n}\n\nclass BIT(val size: Int) {\n private val A = IntArray(size + 1)\n private val logn = generateSequence(size) { it shr 1 }.takeWhile { it > 1 }.count()\n\n // zeroes all the bits except the least significant one\n @Suppress(\"NOTHING_TO_INLINE\")\n private inline fun lsb(i: Int) = i and -i\n\n fun sum(end: Int): Int {\n var i = minOf(end, size)\n var sum = 0\n while(i > 0) {\n sum += A[i]\n i -= lsb(i)\n }\n return sum\n }\n\n fun sum(range: IntRange) = sum(range.last) - sum(range.first - 1)\n\n fun add(index: Int, value: Int) {\n var i = index // BIT is internally 1-indexed\n while(i <= size) {\n A[i] += value\n i += lsb(i)\n }\n }\n}\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": "8d928b89567e6601567ef77d14c10cad", "src_uid": "ed1a2ae733121af6486568e528fe2d84", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.sqrt\n\nfun main() {\n var n = readLine()!!.toLong()\n val coll = ArrayList()\n\n for (i in 2..sqrt(n.toDouble()).toLong() + 1) {\n if (n % i == 0L) {\n coll.add(i)\n\n n /= i\n\n while (n % i == 0L) {\n n /= i\n }\n }\n }\n\n if (!coll.any()) {\n println(n)\n } else if (coll.size == 1 && n == 1L) {\n println(coll[0])\n } else {\n println(1)\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["number theory"], "code_uid": "89d43977c0f0a03e274fede8060f5098", "src_uid": "f553e89e267c223fd5acf0dd2bc1706b", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package tasks\n\nfun deltaCount(array: List): Int {\n fun findBoundZeroIndices(array: List) =\n array.mapIndexedNotNull { i, v ->\n i.takeIf { v == -1 && (i == 0 || array[i - 1] == 1) }\n }\n\n val zeroBeginIndices = findBoundZeroIndices(array)\n val zeroEndIndices =\n findBoundZeroIndices(array.reversed())\n .map { array.size - it - 1 }.reversed()\n\n var target = Triple(1, 0, 0)\n for (i in zeroBeginIndices)\n for (j in zeroEndIndices)\n if (i <= j) {\n val count = array.subList(i, j + 1).sum()\n if (count < target.first)\n target = Triple(count, i, j)\n }\n val (_, left, right) = target\n\n return array\n .mapIndexed { i, v -> if (i in left..right) -v else v }\n .count { it == 1 }\n}\n\nfun main() {\n readLine()\n val array = readLine()!!.split(\" \").map { it.toInt() * 2 - 1 }\n val count = deltaCount(array)\n println(count)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "dp", "implementation"], "code_uid": "2d7c5cf082bb171012c5def52a929c52", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (k, p) = readLine()!!.split(\" \").map(String::toLong)\n var result = 0L\n for (i in 1..k) {\n result += (i.toString() + i.toString().reversed()).toLong()\n result %= p\n }\n print(result)\n}", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "593ca8e48745ba94667919a57978d31d", "src_uid": "00e90909a77ce9e22bb7cbf1285b0609", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.HashSet\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val g = Array(5) { IntArray(5) }\n var max = 0\n\n for (i in 0..4)\n for (j in 0..4)\n g[i][j] = ir.nextInt()\n\n for (a in 0..4)\n for (b in 0..4)\n for (c in 0..4)\n for (d in 0..4)\n for (e in 0..4) {\n var count = 0\n val x = HashSet()\n x.add(a)\n x.add(b)\n x.add(c)\n x.add(d)\n x.add(e)\n if (x.size == 5)\n count = g[a][b] + g[b][a] + 2 * (g[c][d] + g[d][c]) + g[b][c] + g[c][b] + 2 * (g[d][e] + g[e][d])\n max = Math.max(max, count)\n }\n\n pw.print(max)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextFloat(): Float {\n return java.lang.Float.parseFloat(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "f88e40b84b1fc181127cfddd200030ac", "src_uid": "be6d4df20e9a48d183dd8f34531df246", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (n, m,k) = readLine()!!.split(' ').map { it.toInt() }\n println(Math.min(n-m,k+1))\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "0ad93b9de1f06c9e7d79e5bcbe1f4433", "src_uid": "51a072916bff600922a77da0c4582180", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007\n\nfun main() {\n val (Hy, Ay, Dy) = readInts()\n val (Hm, Am, Dm) = readInts()\n val (H, A, D) = readLongs()\n\n var ans = 1e18.toLong()\n for (d in 0..max(0, Am - Dy)) {\n for (a in 0..200) { // 計算たいへん\n val rateM = max(0, Ay + a - Dm)\n val rateY = max(0, Am - Dy - d)\n if (rateM > 0 && rateY == 0) { // ダメージを受けない\n ans = min(ans, A * a + D * d)\n } else if (rateM > 0 && rateY > 0) {\n val turn = (Hm + rateM - 1) / rateM\n val healthNeeded = turn * rateY + 1\n val h = max(0, healthNeeded - Hy)\n ans = min(ans, H * h + A * a + D * d)\n }\n }\n }\n 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\nprivate val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n} catch (t: Throwable) {\n false\n}\n\nprivate fun readLn() = readLine()!!\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }.toIntArray()\nprivate fun readLongs() = readStrings().map { it.toLong() }.toLongArray()\nprivate inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n}\nprivate fun debug(a: LongArray) {\n debug{a.joinToString(\" \")}\n}\nprivate fun debug(a: IntArray) {\n debug{a.joinToString(\" \")}\n}\nprivate fun debug(a: BooleanArray) {\n debug{a.map{if(it) 1 else 0}.joinToString(\"\")}\n}\nprivate fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "binary search"], "code_uid": "d73f03190e3a64aeea6a6e9dc8a29e12", "src_uid": "bf8a133154745e64a547de6f31ddc884", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val pressed = arrayOf(\n readLine()!!.split(\" \").map { it.toInt() }.toIntArray(),\n readLine()!!.split(\" \").map { it.toInt() }.toIntArray(),\n readLine()!!.split(\" \").map { it.toInt() }.toIntArray()\n )\n val grid = arrayOf(\n booleanArrayOf(true, true, true),\n booleanArrayOf(true, true, true),\n booleanArrayOf(true, true, true)\n )\n for (i in pressed.indices) {\n for (j in pressed[i].indices) {\n if (pressed[i][j] and 1 == 1) {\n toggleGrid(i, j, grid)\n }\n }\n }\n for (i in grid.indices) {\n for (j in grid[i].indices) {\n if (grid[i][j]) print(1)\n else print(0)\n }\n println()\n }\n}\n\nprivate fun toggleGrid(i: Int, j: Int, grid: Array) {\n grid[i][j] = grid[i][j].not()\n if (i - 1 in 0..grid.lastIndex) grid[i - 1][j] = grid[i - 1][j].not()\n if (i + 1 in 0..grid.lastIndex) grid[i + 1][j] = grid[i + 1][j].not()\n if (j - 1 in 0..grid.lastIndex) grid[i][j - 1] = grid[i][j - 1].not()\n if (j + 1 in 0..grid.lastIndex) grid[i][j + 1] = grid[i][j + 1].not()\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "01330aa78ab8a7ef7edfe5b15c3d0e36", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "// 7/30/2020 3:10 PM\n\n//package p515\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\n\nval mapping = mapOf(Pair(\"0\", \"\"), Pair(\"1\", \"\"), Pair(\"2\", \"2\"), Pair(\"3\", \"3\"), Pair(\"4\", \"223\"), Pair(\"5\", \"5\"), Pair(\"6\", \"35\"), Pair(\"7\", \"7\"), Pair(\"8\", \"2227\"), Pair(\"9\", \"2337\"))\n\n\nfun main() {\n readInt()\n val a = readLn()\n var output = \"\"\n for (character in a) {\n output += mapping.get(character.toString())\n }\n output.toList().sorted().reversed().forEach { print(\"$it\") }\n println()\n// printMaxInteger(n)\n}\n\n\n\n//fun printMaxInteger(n: Long) {\n// var num = n\n// val allFactors = mutableListOf()\n// while (num > 0) {\n// allFactors.addAll(getFactorialFactors(num % 10))\n// num /= 10\n// }\n//\n// allFactors.sorted().reversed().forEach{ print(it) }\n// println()\n//}\n//\n//fun getFactorialFactors(n: Long) : List {\n// val result = mutableListOf()\n// for (i in n downTo 2)\n// result.addAll(getFactors(i))\n// return result\n//}\n//\n//fun getFactors(n: Long) : List {\n// val result = mutableListOf()\n// var num = n\n// for (div in 2..n) {\n// if (num < 2)\n// break\n// while (num % div == 0L) {\n// num /= div\n// result.add(div)\n// }\n// }\n// return result\n//}", "lang_cluster": "Kotlin", "tags": ["math", "sortings", "greedy"], "code_uid": "6a0aaeb3db1be1bbd69fc9ed29c93426", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398", "difficulty": 1400.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 a = nextInt()\n val b = nextInt()\n val min = Math.min(a, b)\n var ans = 1L\n (2..min).forEach {\n ans *= it\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": ["math", "implementation", "number theory"], "code_uid": "51dfaab85ba98aeed679529e1f6619ad", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\nfun main(args: Array ) {\n val sc = Scanner(System.`in`)\n val n = sc.nextLong()\n val b = sc.nextLong()\n// val random = Random()\n// while ( true ) {\n// val nn = Math.max( 1, Math.abs( random.nextLong() ) % 1e18.toLong() )\n// val bb = Math.max( 1, Math.abs( random.nextLong() ) % 1e12.toLong() )\n// println( \"$nn $bb\" )\n// solve( bb, nn )\n// System.out.flush()\n// }\n solve( b, n )\n}\n\nprivate fun solve( B: Long, n: Long ) {\n var b = B\n val p = ArrayList()\n val d = ArrayList()\n var i = 1L\n while ( ++ i * i <= b ) {\n if ( b % i != 0L ) continue\n p.add( i )\n var deg = 0\n while ( b % i == 0L ) {\n deg ++\n b /= i\n }\n d.add( deg )\n }\n if ( b > 1 ) {\n p.add( b )\n d.add( 1 )\n }\n\n var r = n\n for (j in p.indices) {\n var deg = 0L\n var t = n\n while (t > 0) {\n t /= p[j]\n deg += t\n }\n r = Math.min(r, deg / d[j])\n }\n\n println(r)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "implementation", "number theory"], "code_uid": "587114d23ba80b243c1ee7345885908d", "src_uid": "491748694c1a53771be69c212a5e0e25", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val k = readLine()!!.toInt()\n val a = readLine()!!.split(\" \").map { it.toInt() }\n\n var count = 0\n if (a.sortedDescending().fold(0, {acc, i ->\n if (acc >= k) {\n println(count)\n return\n } else {\n count++\n acc + i\n }\n }) >= k) println(count) else println(-1)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "cd318c6287b9f225c656894f9f75b85c", "src_uid": "59dfa7a4988375febc5dccc27aca90a8", "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 (numMarks, k) = readInts()\n val arr = readInts()\n print(max(0, ((arr.sum() - numMarks * (k - 0.5)) / -0.5).toInt()))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "500b0648075fa5e8484c2d095c0251f0", "src_uid": "f22267bf3fad0bf342ecf4c27ad3a900", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "// 2022.10.17 at 15:49:09 BST\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\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.mm(b:Int):Int{ return ((this.toLong() * b) % pI).toInt() }\r\ninfix fun Int.mp(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }\r\ninfix fun Int.ms(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 mm (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 eat(){ val st1 = TreeSet(); val st2 = TreeMap()}\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\nconst val 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\nconst val singleCase = true\r\nfun main(){\r\n solve.cases{\r\n\r\n val p1 = getint\r\n val t1 = getlong\r\n\r\n val p2 = getint\r\n val t2 = getlong\r\n\r\n val h = getint\r\n val s = getint\r\n\r\n val pack = LongArray(h+1){phuge }\r\n val finish = LongArray(h+1){phuge }\r\n pack[0] = 0\r\n\r\n finish[h] = 0L\r\n fun pack(damage:Int, cost:Long){\r\n\r\n// just dei \"$damage $cost\"\r\n for(i in 0..h){\r\n val next = minOf(damage + i,h)\r\n val cost = pack[i] + cost\r\n pack[next ]= minOf(pack[next], cost)\r\n }\r\n// just dei pack\r\n }\r\n\r\n var tnow = 0L\r\n var CD1 = t1\r\n var CD2 = t2\r\n var damagenow = 0\r\n\r\n while(true){\r\n val totalmove = maxOf(CD1,CD2)\r\n val tt = tnow + totalmove\r\n val dt = damagenow + (p1 + p2 - s)\r\n pack(dt, tt)\r\n\r\n if(damagenow > h)\r\n break\r\n\r\n\r\n val tmove = minOf(CD1,CD2)\r\n tnow += tmove\r\n CD1 -= tmove\r\n CD2 -= tmove\r\n if(CD1 == 0L && CD2 != 0L){\r\n CD1 = t1\r\n damagenow += p1 -s\r\n }else if(CD2 == 0L && CD1 != 0L){\r\n CD2 = t2\r\n damagenow += p2 - s\r\n }else if(CD1 == 0L && CD2 == 0L){\r\n CD1 = t1\r\n CD2 = t2\r\n damagenow += (p1 + p2 - s)\r\n }\r\n finish[maxOf(0,h-damagenow)] = minOf(finish[maxOf(0,h-damagenow)], tnow)\r\n }\r\n\r\n// just dei finish\r\n\r\n for(i in 0 until h){\r\n finish[i+1] = minOf(finish[i+1], finish[i])\r\n }\r\n// just dei finish\r\n// just dei pack\r\n\r\n var ret = phuge\r\n\r\n for(i in 0..h){\r\n ret = minOf(ret, finish[i] + pack[i])\r\n }\r\n put(ret)\r\n\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", "binary search"], "code_uid": "09597888c6ff39c0a7c73209f3a4f64e", "src_uid": "ca9d48e48e69b931236907a9ac262433", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var white = 0\n var black = 0\n repeat(8) {\n var str = readStr()\n\n for (i in str!!) {\n when (i) {\n 'q' -> black += 9\n 'Q' -> white += 9\n 'r' -> black += 5\n 'R' -> white += 5\n 'b' -> black += 3\n 'B' -> white += 3\n 'n' -> black += 3\n 'N' -> white += 3\n 'p' -> black += 1\n 'P' -> white += 1\n }\n }\n\n }\n if (black > white) {\n println(\"Black\")\n } else if (black == white) {\n println(\"Draw\")\n } else {\n println(\"White\")\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": ["implementation"], "code_uid": "0865a79f0e96ebc5497a4f5c86115778", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "@file:Suppress(\"NOTHING_TO_INLINE\")\n\nimport java.io.*\nimport java.lang.Math.*\nimport java.util.*\nimport kotlin.collections.HashMap\n\nprivate const val dev = false\n\nfun main() {\n Task1.apply {\n if (dev) {\n timed { solve() }\n } else {\n solve()\n }\n close()\n }\n}\n\nprivate object Task1 {\n\n private val testFile = if (!dev) \"\" else \"task1\"\n\n fun solve() {\n val a = nextInt()\n val b = nextInt()\n val c = nextInt()\n val d = nextInt()\n\n val lowest = min(a, min(b, c))\n val highest = max(a, max(b, c))\n\n val middle =\n when {\n a > b -> when {\n b > c -> b\n c > a -> a\n else -> c\n }\n else -> when {\n b < c -> b\n c < a -> a\n else -> c\n }\n }\n\n var toMove = 0\n val dist1 = abs(lowest - middle)\n if (dist1 < d) {\n toMove += (d - dist1)\n }\n\n val dist2 = abs(highest - middle)\n if (dist2 < d) {\n toMove += (d - dist2)\n }\n println(toMove)\n }\n\n private val reader: BufferedReader\n private val writer: PrintWriter\n private var tokenizer: StringTokenizer = StringTokenizer(\"\", \".\", false)\n\n init {\n if (testFile.isEmpty()) {\n reader = BufferedReader(InputStreamReader(System.`in`))\n writer = PrintWriter(System.out)\n } else {\n reader = BufferedReader(FileReader(\"$testFile.in\"))\n writer = PrintWriter(FileWriter(\"task.out\"))\n }\n }\n\n inline fun next(): String {\n while (!tokenizer.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer.nextToken()\n }\n\n inline fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n @Suppress(\"unused\")\n inline fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n @Suppress(\"unused\")\n inline fun print(obj: T) {\n writer.print(obj)\n }\n\n inline fun println(obj: T) {\n writer.println(obj)\n }\n\n fun close() {\n writer.flush()\n reader.close()\n }\n}\n\nprivate fun timed(block: () -> Unit) {\n val startTime = System.nanoTime()\n block()\n println(\"Took ${(System.nanoTime() - startTime) / 1_000_000}ms\")\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "0f2534b89d332bb110e7881add2c588a", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3", "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: Int = ir.nextInt()\n val c = ir.next().toCharArray()\n var min = 105\n\n for (i in 0 until (n - 3)) {\n var count = 0\n if (c[i] != 'A') {\n val num = (c[i] - 64).toInt()\n val n1 = Math.abs(27 - num)\n val n2 = Math.abs(1 - num)\n\n count += if (n1 <= n2)\n n1\n else\n n2\n }\n\n if (c[i + 1] != 'C') {\n val num = (c[i + 1] - 64).toInt()\n val n1 = Math.abs(29 - num)\n val n2 = Math.abs(3 - num)\n\n count += if (n1 <= n2)\n n1\n else\n n2\n }\n\n if (c[i + 2] != 'T') {\n val num = (c[i + 2] - 64).toInt()\n val n1 = Math.abs(6 + num)\n val n2 = Math.abs(20 - num)\n\n count += if (n1 <= n2)\n n1\n else\n n2\n }\n\n if (c[i + 3] != 'G') {\n val num = (c[i + 3] - 64).toInt()\n val n1 = Math.abs(33 - num)\n val n2 = Math.abs(7 - num)\n\n count += if (n1 <= n2)\n n1\n else\n n2\n }\n\n min = Math.min(count, min)\n }\n\n pw.println(min)\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", "strings"], "code_uid": "dffba9d1985a86ac0692f2d3540c6abe", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543", "difficulty": 1000.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 val n = nextInt()\n val a = nextInts(n)\n val dpA = IntArray(n + 1)\n val dpB = IntArray(n + 1)\n\n (1..n).forEach {\n val i = n - it\n dpA[it] = Math.max(a[i] + dpB[it - 1], dpA[it - 1])\n dpB[it] = Math.min(a[i] + dpB[it - 1], dpA[it - 1])\n }\n\n val alice = dpB[n]\n val bob = a.sum() - dpB[n]\n println(\"$alice $bob\")\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 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\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\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\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": ["dp", "games"], "code_uid": "8ef00234f26626f853b4cd1eb72ac756", "src_uid": "414540223db9d4cfcec6a973179a0216", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nfun main(){\n val scanner = Scanner(System.`in`)\n val l = scanner.nextLong().toString(2)\n val r = scanner.nextLong().toString(2)\n\n val diff = r.length - l.length\n var max = StringBuilder(\"\")\n var flag = false\n//797162752288318119 908416915938410706\n if(diff > 0){\n for(i in 1..diff)\n max.append(\"1\")\n flag = true\n }\n\n for(i in l.indices){\n if(flag){\n for(j in i + 1..l.length)\n max.append(\"1\")\n break\n }\n if(l[i] != r[i + diff]){\n if(l[i] == '1')\n continue\n max = StringBuilder(\"1\")\n flag = true\n }\n }\n if(!flag){\n max = StringBuilder(\"0\")\n }\n print(max.toString().toLong(2))\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "bitmasks", "greedy", "implementation"], "code_uid": "f01f435bc556b80c44acdc6e9620c787", "src_uid": "d90e99d539b16590c17328d79a5921e0", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(){\n readLine()!!\n val s = readLine()!!\n\n var d = 0\n for (c in s){\n if (c=='+'){\n d++\n }else{\n if (d==0) d=1\n d--\n }\n\n }\n println(d)\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "6eb1c293cfb8de95d5835960db6aac9d", "src_uid": "a593016e4992f695be7c7cd3c920d1ed", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val (s, n) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val n = r.readLine()!!.toInt()\n val (a, b, c) = r.readLine()!!.split(\" \").map { it.toLong() }\n when {\n c == 0L && a != b -> println(\"NO\")\n c == 0L -> println(\"YES\")\n else -> println(if ((b - a) % c == 0L && ((b >= a&&c>0)||(b<=a&&c<0))) \"YES\" else \"NO\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "a21cf5de81fba1081460ef926549a771", "src_uid": "9edf42c20ddf22a251b84553d7305a7d", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun readInt(): Int {\n val elements = readLine()!!.split(\" \").map(String::toInt)\n return elements[0]\n}\n\nfun ok(n: Int): Boolean {\n var two = 1\n for (i in 1..10) {\n two *= 2\n val value = (two - 1) * (two / 2)\n if (value == n) {\n return true\n }\n else if (value > n) {\n break\n }\n }\n return false\n}\n\nfun main(args: Array) {\n val n = readInt()\n var ans = 0\n var limit = 0\n while (limit * limit <= n) {\n limit += 1\n }\n\n for (i in 1..limit) {\n if (n % i == 0) {\n if (ok(i)) {\n ans = maxOf(ans, i)\n }\n if (ok(n/i)) {\n ans = maxOf(ans, n/i);\n }\n }\n }\n\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "0a7f7b942d2a7045d03b229d345b3933", "src_uid": "339246a1be81aefe19290de0d1aead84", "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 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}", "lang_cluster": "Kotlin", "tags": ["brute force", "sortings", "greedy"], "code_uid": "0d288a3034139a2d17150ffeefe8af8f", "src_uid": "6bcb324c072f796f4d50bafea5f624b2", "difficulty": 1200.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 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\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": "11e94f5709da83cda29519dfa0b394fb", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "// 2022.07.21 at 23:03:42 HKT\r\nimport FFT.Companion.modplus\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\nclass FFT {\r\n companion object{\r\n// val fftmod = 7340033\r\n// val root = 5\r\n// val root_1 = 4404020\r\n// val root_pw = 1 shl 20\r\n\r\n private const val maxPower = 19 // 262144\r\n private const val n = 1 shl maxPower\r\n public const val fftmod = 998244353\r\n private const val root = 15311432\r\n private const val root_1 = 469870224\r\n private const val root_level = 23\r\n private const val root_pw = 1 shl root_level\r\n\r\n const val FFTcut = 80\r\n\r\n\r\n private inline fun normalize(int: Int) = (int shr Int.SIZE_BITS - 1 and fftmod) + int\r\n infix fun Int.modm(other:Int) = (this.toLong() * other % fftmod).toInt()\r\n infix fun Int.modplus(other: Int) = normalize(this + other - fftmod) // overflow-safe even if MOD >= 2^30\r\n infix fun Int.modminus(other: Int) = normalize(this - other)\r\n\r\n val quickpower = Array(maxPower+1){p ->\r\n val base = intPow(root, 1 shl (root_level - p), fftmod)\r\n (0 until (1 shl p)).runningFold(1){a,b -> a modm base}.toIntArray()\r\n }\r\n\r\n\r\n private val rev = IntArray(n).also { rev ->\r\n var bit = 1\r\n var rbit = n shr 1\r\n while(bit < n) {\r\n for(i in 0 until bit) {\r\n rev[i or bit] = rbit or rev[i]\r\n }\r\n bit = bit shl 1\r\n rbit = rbit shr 1\r\n }\r\n }\r\n\r\n fun calculateRoot(){\r\n println(\"root :$root\")\r\n // intPow(3,7 * 17,fftmod)\r\n println(\"root_1 : $root_1\")\r\n // intPow(root,fftmod -2,fftmod)\r\n }\r\n\r\n fun fft(a:IntArray,invert:Boolean){\r\n val n = a.size\r\n kotlin.assert(n <= this.n)\r\n\r\n if(n <= 1) return\r\n val level = this.n.countTrailingZeroBits()\r\n val st = this.n / n\r\n for(i in 0 until n) {\r\n val j = rev[i * st]\r\n if(i < j) a[i] = a[j].also { a[j] = a[i] }\r\n }\r\n\r\n var len = 2\r\n var ang = 1 shl (level -1)\r\n if(invert) ang = -ang\r\n val pt = quickpower[level]\r\n while(len <= n){\r\n\r\n var i = 0\r\n val h = len shr 1\r\n while(i < n){\r\n var k = 0\r\n for(j in i until i+h){\r\n val u = a[j]\r\n val w = pt[k]\r\n val v = a[j+h] modm w\r\n a[j] = u modplus v\r\n a[j+h] = u modminus v\r\n k = k + ang and (1 shl level) - 1\r\n }\r\n i += len\r\n }\r\n len = len shl 1\r\n ang = ang shr 1\r\n }\r\n if(invert){\r\n val n_1 = pow(n.toLong(),(fftmod-2).toLong(),fftmod.toLong())\r\n for((i,x) in a.withIndex()){\r\n a[i] = (x.toLong() * n_1 % fftmod).toInt()\r\n }\r\n }\r\n }\r\n fun fullconvolution(at:IntArray,bt:IntArray):IntArray{\r\n return fullconvolutionOpt(at,bt,at.size,bt.size)\r\n }\r\n fun brute(A:IntArray,B:IntArray):IntArray{\r\n val ret = IntArray(A.size + B.size -1)\r\n for(i in A.indices){\r\n for(j in B.indices){\r\n ret[i+j] = ret[i+j] modplus (A[i] modm B[j])\r\n }\r\n }\r\n return ret\r\n }\r\n\r\n fun fullconvolutionOpt(at:IntArray,bt:IntArray,sizeA:Int,sizeB:Int):IntArray{\r\n // 1 shl 18 done in 77 ms\r\n if(sizeA <= FFTcut || sizeB <= FFTcut){\r\n return brute(at,bt)\r\n }\r\n\r\n val maxSize = (sizeA + sizeB).takeHighestOneBit() * 2\r\n kotlin.assert(maxSize <= (1 shl maxPower))\r\n val a = at.copyOf(maxSize)\r\n val b = bt.copyOf(maxSize)\r\n val expectedSize = at.size + bt.size - 1\r\n fft(a,false)\r\n fft(b,false)\r\n for(i in a.indices){\r\n a[i] = (a[i].toLong() * b[i] % fftmod).toInt()\r\n }\r\n fft(a,true)\r\n return a.copyOf(expectedSize)\r\n }\r\n }\r\n}\r\nclass rsqArrModded(val arr:IntArray){\r\n val ps = IntArray(arr.size + 1)\r\n init{\r\n for(i in 0 until arr.size){\r\n ps[i+1] = ps[i] modPlus arr[i]\r\n }\r\n }\r\n fun sumQuery(l:Int,r:Int): Int {\r\n val ll = maxOf(l,0)\r\n val rr = minOf(arr.lastIndex,r) + 1\r\n return ps[rr] modMinus ps[ll]\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 k = getint\r\n val f = getint\r\n\r\n var now = IntArray(f+2)\r\n for(i in 0..k){\r\n if(i in 0..f){\r\n now[i]++\r\n }else{\r\n now[f+1] ++\r\n }\r\n }\r\n\r\n// just dei now.sum()\r\n repeat(n-1){\r\n val extra = FFT.fullconvolution(now,now)\r\n val reduced = IntArray(f+2)\r\n for((i,v) in extra.withIndex()){\r\n if(i in 0..f){\r\n reduced[i] = reduced[i] modPlus v\r\n }else{\r\n reduced[f+1] = reduced[f+1] modPlus v\r\n }\r\n }\r\n// 1 dei reduced\r\n\r\n\r\n val QM = rsqArrModded(reduced)\r\n val new = IntArray(f+2)\r\n for(x in 0..k){\r\n if(x in 0..f){\r\n new[x] = new[x] modPlus QM.sumQuery(x,f+1)\r\n }else{\r\n new[f+1] = new[f+1] modPlus QM.sumQuery(minOf(f+1,x),f+1)\r\n }\r\n }\r\n for(x in 0..f){\r\n new[x] = new[x] modPlus (reduced[x] modM maxOf(0,k - x))\r\n }\r\n now = new\r\n// 3 dei new\r\n }\r\n val final = FFT.fullconvolution(now,now)\r\n put(final[f])\r\n\r\n\r\n\r\n\r\n }\r\n done()\r\n}\r\n\r\n/*\r\n\r\n\r\n3 2 1 3 2 1\r\n\r\n\r\n1 2\r\n */\r\n\r\n\r\n", "lang_cluster": "Kotlin", "tags": ["brute force", "flows", "math", "dp", "fft", "bitmasks", "graphs", "meet-in-the-middle", "trees"], "code_uid": "452a53a2d4ff88683c8a77aa5e0eac1f", "src_uid": "4b8161259545e44c7d1046be2e4fe014", "difficulty": 2500.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 if (max[i] - res[i] < n) {\n n = n - max[i] + res[i]\n res[i] = max[i]\n } else {\n res[i] += n\n break\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": "4f69edba5f66d9eff0a5226da674b197", "src_uid": "3cd092b6507079518cf206deab21cf97", "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_007\n\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val A = nl()\n val B = nl()\n var ans = 0L\n for (m in 1 until B) {\n val cum = A * (A + 1) / 2 % MOD\n val cnt = A\n ans += (m * cnt + m * B % MOD * cum) % MOD\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 // なんか本番でエラーでる\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 * 勝手にimport消されるのを防ぎたい\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"], "code_uid": "51c8ec476779edd8ae77b9a510ddf539", "src_uid": "cd351d1190a92d094b2d929bf1e5c44f", "difficulty": 1600.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(): 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 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 bound = 1000000\n val sqrtBound = 1000\n val arrdiv = IntArray(bound + 1)\n for (i in 1 .. sqrtBound) {\n ++arrdiv[i * i]\n for (j in i+1 .. bound) {\n val a = i * j\n if (a > bound) break\n arrdiv[a] += 2\n }\n }\n val a = ir.nextInt()\n val b = ir.nextInt()\n val c = ir.nextInt()\n var answer = 0\n for (i in 1 .. a) {\n for (j in 1 .. b) {\n for (k in 1 .. c) {\n answer += arrdiv[i * j * k]\n }\n }\n }\n ow.write(\"$answer\\n\")\n ow.flush()\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation", "number theory"], "code_uid": "f26c3a87af7d0b59cd3cec6330b596b1", "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401", "difficulty": 1300.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 var nr = 0\n for(i in 0..N-1) {\n val x = nextInt()\n if(!a[x] && x > 0) nr++;\n if(x > 0) a[x] = true\n }\n println(nr)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation"], "code_uid": "6dc6053fa7fdb186c0a238377c2c4f4a", "src_uid": "3b520c15ea9a11b16129da30dcfb5161", "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\nimport kotlin.math.min\nfun main(args : Array) {\n Thread { run() }.start()\n}\n\nfun run() {\n\n val scanner = Scanner(System.`in`)\n var a = scanner.nextInt()\n val m = scanner.nextInt()\n val arr = BooleanArray(m)\n a %= m\n while (a != 0) {\n if (arr[a]) {\n println(\"No\")\n return\n }\n arr[a] = true\n a += a % m\n a %= m\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}\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", "matrices", "implementation"], "code_uid": "8bd6024609c5bc721b74f674f5b4abf9", "src_uid": "f726133018e2149ec57e113860ec498a", "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 = 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 var a = ir.nextInt()\n val x = ir.nextInt()\n var b = ir.nextInt()\n val y = ir.nextInt()\n\n while (true) {\n if (a == b) {\n println(\"YES\")\n break\n }\n \n if (a == x || b == y) {\n println(\"NO\")\n break\n }\n\n a++\n b--\n if (a == n + 1)\n a = 1\n\n if (b == 0)\n b = n\n\n }\n\n}\n\nfun mergeSort(array : IntArray) {\n\n if(array.size == 1)\n return\n\n val first = IntArray(array.size / 2)\n val second = IntArray(array.size - first.size)\n System.arraycopy(array, 0, first, 0, first.size)\n System.arraycopy(array, first.size, second, 0, second.size)\n\n mergeSort(first)\n mergeSort(second)\n\n merge(first, second, array)\n\n}\n\nfun merge(first : IntArray, second : IntArray, result : IntArray) {\n var iFirst = 0\n var iSecond = 0\n var j = 0\n\n while (iFirst < first.size && iSecond < second.size) {\n if (first[iFirst] < second[iSecond]) {\n result[j] = first[iFirst]\n iFirst++\n } else {\n result[j] = second[iSecond]\n iSecond++\n }\n j++\n }\n System.arraycopy(first, iFirst, result, j, first.size - iFirst)\n System.arraycopy(second, iSecond, result, j, second.size - iSecond)\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", "implementation"], "code_uid": "89f03276470b5a54a5edf1fdff24f4fc", "src_uid": "5b889751f82c9f32f223cdee0c0095e4", "difficulty": 900.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 var n = scanner.nextLong()\n if (n < 10)\n println(n)\n else {\n var sum = 0L\n var i = 0\n while (n.toString().length > 1) {\n val diff = 9 * Math.pow(10.0, i.toDouble()).toLong()\n if (diff > n)\n break\n n -= diff\n sum += diff * (i+1)\n i++\n }\n sum += n * (i+1)\n println(sum)\n }\n\n /*\n * 999\n * 9*1 + 90*2 + 900*3\n *\n * 850\n * 9*1 + 90*2 + 751*3\n *\n * */\n\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "d0b321b8f56025cd3fa9b2136e20715b", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9", "difficulty": 1200.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 k = reader.nextInt()\n val x = reader.nextInt()\n val a = reader.nextArrayInt(n).reversed().toMutableList()\n for (i in 0 until k) {\n a[i] = x\n }\n writer.println(a.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": ["implementation"], "code_uid": "188c74eb8ee328a1da24dba0de2b2507", "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.abs\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 a = reader.nextInt()\n val b = reader.nextInt()\n\n val x = abs(a - b)\n val t1 = x / 2 + x % 2\n val t2 = x / 2\n\n val ans = t1 * (t1 + 1) / 2 + t2 * (t2 + 1) / 2\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": ["math", "greedy", "implementation", "brute force"], "code_uid": "3ac81564e7cb211a1dd6477e24c0c98a", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da", "difficulty": 800.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() - 1\n val x = ((sqrt((1 + 8 * n).toDouble()) - 1) / 2).toLong()\n print(1 + n - (x * (x + 1) / 2))\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "2130fdb71cd942ad7ee733ede1b7339a", "src_uid": "1db5631847085815461c617854b08ee5", "difficulty": 1000.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 pd = ModInt(2).pow(n)\n var ans = pd - 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 n..2*n) {\n ans += pd\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": "36c55b22b952064d706d1bed3321f2bb", "src_uid": "a18833c987fd7743e8021196b5dcdd1b", "difficulty": 1800.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(n*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)\n*/\n\n\nimport 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": "262f6dcab6bcd5a9509aaf5b327d95c1", "src_uid": "f54cc281033591315b037a400044f1cb", "difficulty": 2600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.math.BigInteger\nfun main(args: Array)\n{\n var ins:String\n var fact:BigInteger = BigInteger.valueOf(2)\n var ans:BigInteger = BigInteger.valueOf(0)\n var bb:BigInteger\n\n var nn:Int\n ins = readLine()!!\n nn = ins.toInt()\n ans = fact.pow(nn+1);\n ans = ans.subtract(fact)\n\n println(ans)\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "0112fc7ea2f59602d64dd1ebb2b29386", "src_uid": "f1b43baa14d4c262ba616d892525dfde", "difficulty": 1100.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 val n = nextInt()\n val m = Math.sqrt(n.toDouble()).toInt()\n val r = n - m * m\n if (r == 0) {\n println(4 * m)\n } else if (r <= m) {\n println(4 * m + 2)\n } else {\n println(4 * m + 4)\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 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\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\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\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", "geometry"], "code_uid": "2bd21dc0b2a533883304e84c864f5ba4", "src_uid": "414cc57550e31d98c1a6a56be6722a12", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var a = readLine()!!\n var ans = 0\n for (c in a){\n if (c.isDigit()){\n var cur = ((c.toInt())%2 == 1)\n if(cur){\n ans+=1\n }\n }else {\n if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){\n ans += 1\n }\n }\n }\n println(ans)\n\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "5aefb0893fcaf86686c4e6e3bf8fac03", "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.io.*\nimport java.util.Locale\n\n\nval filename = \"a\"\n\nfun solve() {\n val x = iread()\n val y = iread()\n val z = iread()\n val t1 = iread()\n val t2 = iread()\n val t3 = iread()\n\n val res1 = (Math.abs(x-y) + Math.abs(z-x))*t2 + t3*3;\n val res2 = Math.abs(x-y) * t1;\n\n if (res1 <= res2) {\n out.write(\"YES\\n\")\n }\n else\n out.write(\"NO\\n\")\n}\n\nfun iread() = readword().toInt()\n\nfun dread() = readword().toDouble()\n\nfun lread() = readword().toLong()\n\nfun readword(): String {\n val b = StringBuilder()\n var c: Int\n val space = ' '.toInt()\n c = `in`.read()\n while (c in 0..space)\n c = `in`.read()\n if (c < 0)\n return \"\"\n while (c > space.toInt()) {\n b.append(c.toChar())\n c = `in`.read()\n }\n return b.toString()\n}\n\nval `in`: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\nval out: BufferedWriter = BufferedWriter(OutputStreamWriter(System.out))\n//val `in` = BufferedReader(FileReader(filename+\".in\"));\n//val out = BufferedWriter(FileWriter(filename+\".out\"));\n\nfun run() {\n try {\n// var ntests = iread()\n// for (test in 0 until ntests) {\n solve()\n// }\n out.flush()\n } catch (e: Exception) {\n e.printStackTrace()\n System.exit(1)\n }\n}\n\nfun main(args: Array) {\n try {\n Locale.setDefault(Locale.US)\n } catch (e: Exception) {\n\n }\n Thread(null, { run() }, \"1\", (1 shl 25).toLong()).start()\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "97d281cbcf9c3cae491a63d5cc7a45e5", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val input = readLine()?.split(' ')?.map { it.toLong() } ?: return\n val a = input[0]\n val b = input[1]\n\n val result = when {\n a == b -> 1\n b - a > 5 -> 0\n else -> (a + 1..b)\n .map { it % 10 }\n .reduce { it1, it2 -> it1 * it2 } % 10\n }\n\n println(result)\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "7d2b06fc6030cc8e40d253b4963e9a4c", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60", "difficulty": 1100.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\tval s = f.readLine().toCharArray()\n\tval t = f.readLine().toCharArray()\n\n\tif(t[0] == t[1]){\n\t\t//make as much stuff t[0] as you can\n\t\tvar not = 0L\n\t\tfor(k in 0 until n){\n\t\t\tif(s[k] != t[0]) not++\n\t\t}\n\n\t\tvar have = (n-not).toLong()\n\t\thave += min(m.toLong(),not)\n\n\t\tval answer = have*(have-1)/2L\n\t\tprintln(answer)\n\t} else {\n\t\tval dp = Array(n){Array(m+1){LongArray(n+1){-1L}}}\n\t\tif(s[0] == t[0]){\n\t\t\tdp[0][0][1] = 0L\n\t\t} else {\n\t\t\tdp[0][0][0] = 0L\n\t\t\tif(m > 0) dp[0][1][1] = 0L\n\t\t}\n\n\t\tfor(k in 0 until n-1){\n\t\t\tfor(j in 0..m){\n\t\t\t\tfor(h in 0 until n){\n\t\t\t\t\tif(dp[k][j][h] == -1L) continue\n\t\t\t\t\t//don't change anything\n\t\t\t\t\tif(s[k+1]!=t[0] && s[k+1]!=t[1]){\n\t\t\t\t\t\tdp[k+1][j][h] = max(dp[k+1][j][h],dp[k][j][h])\n\t\t\t\t\t}\n\t\t\t\t\t//change next character to first character\n\t\t\t\t\tif(s[k+1] == t[0]){\n\t\t\t\t\t\tdp[k+1][j][h+1] = max(dp[k+1][j][h+1],dp[k][j][h])\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif(j < m){\n\t\t\t\t\t\t\tdp[k+1][j+1][h+1] = max(dp[k+1][j+1][h+1],dp[k][j][h])\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t//change next character to second character\n\t\t\t\t\tif(s[k+1] == t[1]){\n\t\t\t\t\t\tdp[k+1][j][h] = max(dp[k+1][j][h],dp[k][j][h]+h.toLong())\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif(j < m){\n\t\t\t\t\t\t\tdp[k+1][j+1][h] = max(dp[k+1][j+1][h],dp[k][j][h]+h.toLong())\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvar answer = 0L\n\t\tfor(j in 0..m){\n\t\t\tfor(h in 0..n){\n\t\t\t\tanswer = max(answer,dp[n-1][j][h])\n\t\t\t}\n\t\t}\n\n\t\tprintln(answer)\n\n\n\t}\n}\n", "lang_cluster": "Kotlin", "tags": ["strings", "dp"], "code_uid": "07abbcd05a5ca111ee57ef5482532ff7", "src_uid": "9c700390ac13942cbde7c3428965b18a", "difficulty": 2100.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 sc = Scanner(System.`in`)\n var n = sc.nextInt()\n var str = sc.next()\n var s = 0\n\n for (i in 1..str.length - 1) {\n if (str[i] == 'F' && str[i - 1] == 'S') {\n s++\n } else if (str[i] == 'S' && str[i - 1] == 'F') {\n s--\n }\n }\n if (s > 0) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "676cd7e713cd52f7a2603fbc6ffaf59c", "src_uid": "ab8a2070ea758d118b3c09ee165d9517", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "fun main() {\r\n repeat(readLine()!!.toInt()) {\r\n val (n, m, k) = readLine()!!.split(' ').map { it.toInt() }\r\n if (n % 2 == 0 && m % 2 == 1) return@repeat println(if (k % 2 == 0 && k + (n / 2) <= n * m / 2) \"YES\" else \"NO\")\r\n if (n % 2 == 0) return@repeat println(if (k % 2 == 0) \"YES\" else \"NO\")\r\n if (n % 2 == 1) return@repeat println(if (k % 2 == (m / 2) % 2 && k >= (m / 2)) \"YES\" else \"NO\")\r\n }\r\n}\r\n", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "393ce52ca7c97015f6a1b4dfb10afd94", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8", "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.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(r0 + 1)\n val s = g0 - h * (h-1) / 2 + r0\n var ok = false\n for(r in D.indices) {\n if(D[r].int == 0) continue\n val g = s - r\n if(r >= h) {\n Di[r-h] += D[r]\n ok = true\n }\n if(g >= h) {\n Di[r] += D[r]\n ok = true\n }\n }\n if(!ok) break\n D = Di\n }\n\n val ans = D.sum()\n\n println(ans.int)\n}\n\nfun MutableMap.add(state: Int, v: ModInt) {\n this[state] = (this[state] ?: ModInt(0)) + v\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": "67adabbb7fbdfef886ec1e83f59a0c9c", "src_uid": "34b6286350e3531c1fbda6b0c184addc", "difficulty": 2000.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 n = scanner.nextLong()\n val k = scanner.nextLong()\n\n if (k <= n + 1) {\n println((k - 1) / 2)\n return\n }\n\n if (k >= n * 2) {\n println(0)\n return\n }\n\n if (k % 2 == 1L) {\n println(n - k / 2)\n return\n } else {\n println(n - k / 2)\n return\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "d3100365ee060af86e7744595d1acefb", "src_uid": "98624ab2fcd2a50a75788a29e04999ad", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var n = readLine()!!.toInt()\n var s = readLine()!!.split(\" \");\n var d = s[1].toInt() - s[0].toInt();\n if (n > 2)\n for (i in 2 until s.count()) {\n if (s[i].toInt() - s[i - 1].toInt() != d) {\n print(s[s.lastIndex]);\n return;\n }\n }\n print(s.last().toInt() + d);\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "650cca49f5e3b0872f9bdb88dbe80783", "src_uid": "d04fa4322a1b300bdf4a56f09681b17f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main() {\n solve()\n}\n\nprivate fun solve() {\n val (a, b) = readInts()\n\n var totalCount = 0L\n for (i in a..b) {\n var tmp = i\n\n while (tmp > 0) {\n val digit = tmp % 10\n totalCount += digit.getSegmentLit()\n tmp /= 10\n }\n }\n println(totalCount)\n}\n\nprivate fun Int.getSegmentLit(): Int = when (this) {\n 0 -> 6\n 1 -> 2\n 2 -> 5\n 3 -> 5\n 4 -> 4\n 5 -> 5\n 6 -> 6\n 7 -> 3\n 8 -> 7\n 9 -> 6\n else -> throw IllegalArgumentException()\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": ["implementation"], "code_uid": "165b53db5514d1b73ea8a173611e614c", "src_uid": "1193de6f80a9feee8522a404d16425b9", "difficulty": 1000.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\nval MAX_N = (1e6 + 10).toInt()\nval INF = (1e9 + 7).toInt()\nval MOD = (1e9 + 7).toInt()\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val n = reader.nextInt()\n val s = reader.next()\n\n var ans = n\n\n for (l in (0 until n / 2).reversed()) {\n val pref = s.slice(0..l)\n val r = 2 * l + 1\n val nexts = s.slice(l + 1..r)\n\n if (pref == nexts) {\n val t = pref.length + 1 + (n - 2 * pref.length)\n ans = min(ans, t)\n }\n }\n writer.println(ans)\n}\n\nclass InputReader(stream: InputStream) {\n val reader: BufferedReader\n var tokenizer: StringTokenizer? = null\n\n init {\n reader = BufferedReader(InputStreamReader(stream), 32768)\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "019565eddf9f3ad1f783623083b17684", "src_uid": "ed8725e4717c82fa7cfa56178057bca3", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport java.io.*\nimport java.math.*\n\n/**\n * Auto-generated code below aims at helping you parse\n * the standard input according to the problem statement.\n **/\nfun main(args : Array) {\n val input = Scanner(System.`in`)\n\n val n = input.nextInt()\n val m = input.nextInt()\n\n val min = input.nextInt()\n val max = input.nextInt()\n\n val a = mutableListOf()\n\n for (i in 0 until m)\n {\n a.add(input.nextInt())\n }\n\n if ((n - m == 1 && a.min()!! != min && a.max()!! != max) || (a.min()!! < min || a.max()!! > max))\n {\n println(\"Incorrect\")\n }\n else\n {\n println(\"Correct\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "80bf19424e3b1c9f31ffd5caa6f09515", "src_uid": "99f9cdc85010bd89434f39b78f15b65e", "difficulty": 1200.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 var min = 2101\n var max = 2009\n\n for (i in 1..n) {\n val year = scanner.nextInt()\n if (year < min) min = year\n if (year > max) max = year\n }\n\n println((min + max) / 2)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation"], "code_uid": "180ad167b2bf4b7cb1ad859423528d63", "src_uid": "f03773118cca29ff8d5b4281d39e7c63", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n val inp = InputReader(System.`in`)\n val out = PrintWriter(System.out)\n TaskA().solve(inp, out)\n out.close()\n}\n\nclass TaskA {\n fun solve(inp: InputReader, out: PrintWriter) {\n val n = inp.nextInt()\n val ar = Array(n) { Pair(0, 0) }\n for (i in 0 until n)\n ar[i] = Pair(inp.nextInt(), inp.nextInt())\n if (n == 1)\n out.println(\"-1\")\n else {\n Arrays.sort(ar) { o1, o2 ->\n if (o1.first != o2.first)\n o1.first.compareTo(o2.first)\n else\n o1.second.compareTo(o2.second)\n }\n var s = 0\n val x1 = ar[0].first\n val y1 = ar[0].second\n val x2 = ar[1].first\n val y2 = ar[1].second\n when (n) {\n 2 -> {\n s = if (x1 == x2 || y1 == y2)\n -1\n else\n (x2 - x1) * Math.abs(y1 - y2)\n }\n 3 -> {\n val x3 = ar[2].first\n val y3 = ar[2].second\n s = if (x1 == x2)\n (y2 - y1) * (x3 - x1)\n else\n (x2 - x1) * (y3 - y2)\n }\n 4 -> {\n val x3 = ar[2].first\n s = (x3 - x1) * (y2 - y1)\n }\n }\n out.println(s)\n }\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": ["geometry", "implementation"], "code_uid": "15a3305560f172f27aaceeaaaf52a248", "src_uid": "ba49b6c001bb472635f14ec62233210e", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.4", "source_code": "private 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\r\nfun main() {\r\n val (n, MOD) = readInts()\r\n fun add (x : Long, y : Long) : Long = if (x + y < MOD) x + y else x + y - MOD\r\n fun sub (x : Long, y : Long) : Long = if (x < y) x - y + MOD else x - y\r\n val DP = Array(n + 1){LongArray(0){0}}\r\n DP[0] = LongArray(1){1}\r\n for (i in 1..n) {\r\n val dim = i * (i - 1) / 2\r\n DP[i] = LongArray(dim + 1){0}\r\n var sum = 0L\r\n for (j in 0..dim) {\r\n if (j < DP[i - 1].size) sum = add(sum, DP[i - 1][j])\r\n DP[i][j] = sum\r\n if (j >= i - 1) sum = sub(sum, DP[i - 1][j - i + 1])\r\n }\r\n }\r\n val pf = LongArray(n * n){0}\r\n var ans = 0L\r\n for (cut in 2 until n) {\r\n val dim = cut * (cut - 1) / 2\r\n for (i in 1..dim) pf[i] = add(pf[i - 1], DP[cut][i])\r\n fun range (l : Int, r : Int) : Long {\r\n if (l > minOf(r, dim)) return 0L\r\n return sub(pf[minOf(r, dim)], if (l > 0) pf[l - 1] else 0)\r\n }\r\n var (tot, aux, sum) = arrayOf(0L, 0L, 0L)\r\n for (x in dim downTo 0) {\r\n val yo = (range(x + cut + 1, dim) * (cut * (cut + 1) / 2) + sum) % MOD\r\n tot = add(tot, DP[cut][x] * yo % MOD)\r\n if (x + cut <= dim) sum = sub(sum, DP[cut][x + cut] * (cut * (cut + 1) / 2 - 1) % MOD)\r\n sum = add(sum, aux)\r\n if (x + cut - 1 <= dim) aux = sub(aux, DP[cut][x + cut - 1] * 2 % MOD)\r\n aux = add(aux, DP[cut][x] * (cut + 1) % MOD)\r\n aux = sub(aux, range(x, x + cut - 2))\r\n }\r\n for (i in (cut + 2)..n) tot = tot * i % MOD\r\n ans = add(ans, tot)\r\n }\r\n println(ans)\r\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "fft"], "code_uid": "a0bb1b0e08f291b314bac0d3058ad7ee", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a", "difficulty": 2400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main(args: Array) {\n var (n, k, x) = readLine()!!.split(\" \").map(String::toInt)\n val arr = readLine()!!.split(\" \").map(String::toInt).toIntArray()\n if(n == 1) {\n println(0)\n return\n }\n var i = 0\n\n var maxCount = 0\n while (i < n-1){\n if(arr[i] == x && arr[i+1] == x) {\n var count = 2\n var l = 1\n var r = 1\n while (i-l>0 && i+r+1 < n) {\n if(arr[i-l] == arr[i+r+1]) {\n if(i-l-1 >= 0) {\n if(i+r+2 < n) {\n if(arr[i-l] == arr[i-l-1] && arr[i+r+1] == arr[i+r+2]) {\n count+=4\n l+=2\n r+=2\n } else if(arr[i-l] == arr[i-l-1]) {\n count+=3\n l+=2\n r++\n } else if(arr[i+r+1] == arr[i+r+2]) {\n count+=3\n l++\n r+=2\n } else {\n break\n }\n } else {\n if(arr[i-l] == arr[i-l-1]) {\n count+=3\n l+=2\n r++\n } else {\n break\n }\n }\n } else {\n if(i+r+2 < n) {\n if(arr[i+r+1] == arr[i+r+2]) {\n count+=3\n l++\n r+=2\n }\n } else {\n break\n }\n }\n } else {\n break\n }\n }\n if (maxCount < count) maxCount = count\n i++\n }\n i++\n }\n println(maxCount)\n}", "lang_cluster": "Kotlin", "tags": ["two pointers", "brute force"], "code_uid": "a5f9be5a45631a6385e3af430e831ae5", "src_uid": "d73d9610e3800817a3109314b1e6f88c", "difficulty": 1400.0, "exec_outcome": "PASSED"} {"lang": "Kotlin 1.6", "source_code": "import java.util.*\n\nfun main() {\n val sc = Scanner(System.`in`)\n // var numberTest: Int = sc.nextInt()\n // while (numberTest-- != 0) {\n val n = sc.nextInt()\n when (n) {\n 1 -> println(3)\n 2 -> println(5)\n 3 -> println(7)\n else -> {\n if (n % 3 == 1) {\n println((n / 3 + 2) * (n / 3 + 2) - (n / 3) * (n / 3))\n }\n if (n % 3 == 0) {\n var a = n / 3\n var b = a + 2\n b = a + b\n a = b - 1\n println(b * b - a * a)\n }\n if (n % 3 == 2) {\n var a = n / 3\n var b = a + 2\n a = a + b\n b = a + 1\n println(b * b - a * a)\n }\n }\n }\n}\n\n/*\n 1,2-> 3\n 2,3-> 5\n 3,4-> 7\n\n 1,3 = 4 -> 8 %3=1\n\n 4,5-> 9 %3=2\n 5,6-> 11 %3=0\n\n 2,4=6-> 12\n\n 6,7-> 13\n 7,8-> 15\n\n 3,5-> 16\n\n 8,9-> 17\n 9,10-> 19\n\n 4,6 = 10 -> 20\n\n 10,11-> 21\n 11,12-> 23\n\n 5,7-> 24\n*/\n", "lang_cluster": "Kotlin", "tags": ["math", "geometry", "binary search"], "code_uid": "e7a38cf07992e9dd63b4f5bd2bb7f0ec", "src_uid": "d0a8604b78ba19ab769fd1ec90a72e4e", "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\nval MAX_N = (1e6 + 10).toInt()\nval INF = (1e9 + 7).toInt()\nval MOD = (1e9 + 7).toInt()\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val n = reader.nextInt()\n val s = reader.next()\n\n var ans = false\n for (i in 1 until n - 1) {\n val c1 = s[i - 1]\n val c2 = s[i]\n val c3 = s[i + 1]\n\n if (c2 == '?' && c3 == '?') {\n ans = true\n break\n }\n\n if (c2 == '?' && c1 == c3) {\n ans = true\n break\n }\n }\n\n if (s.first() == '?' || s.last() == '?') {\n ans = true\n }\n\n for (i in 0 until n - 1) {\n val c1 = s[i]\n val c2 = s[i + 1]\n if (c1 == c2 && c1 != '?') {\n ans = false\n break\n }\n }\n\n writer.println(if (ans) \"YES\" else \"NO\")\n}\n\nclass InputReader(stream: InputStream) {\n val reader: BufferedReader\n var tokenizer: StringTokenizer? = null\n\n init {\n reader = BufferedReader(InputStreamReader(stream), 32768)\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "7996bedfa6da26a59cd2dc38bd85af28", "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\nimport kotlin.math.pow\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //val (n, time) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }\n val s1 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos1 = s1.count { it == \"+\" } * 2 - s1.size\n val s2 = r.readLine()!!.split(\"\").filter { it.length > 0 }\n val pos2 = s2.count { it == \"+\" } - s2.count { it == \"-\" }\n val unk = s2.count { it == \"?\" }\n when{\n unk == 0 -> println(if (pos1==pos2) 1.0 else 0.0)\n pos2+unkpos1-> println(0.0)\n else -> {\n val choose = (unk-abs(pos1-pos2))/2\n val ans = (unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i }/2.0.pow(unk)\n println(ans)\n //println((unk-choose+1..unk).fold(1L){acc, i -> acc*i })\n }\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "dp", "combinatorics", "bitmasks", "probabilities"], "code_uid": "4eb6f6bcf6a87a31cf89af03273fa59e", "src_uid": "f7f68a15cfd33f641132fac265bc5299", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\nimport kotlin.math.sqrt\n\nfun main() {\n val (numVertices, numEdges) = readLine()!!.split(\" \").map(String::toLong)\n if(numEdges == 0L) {\n print(\"$numVertices $numVertices\")\n return\n }\n var minVerticesWithNumEdges = 1+sqrt((1+8*numEdges).toDouble())\n minVerticesWithNumEdges = minVerticesWithNumEdges / 2 + if(minVerticesWithNumEdges%2 == 0.0) 0 else 1\n print(\"${max(0, numVertices - 2 * numEdges)} ${max(0, numVertices - minVerticesWithNumEdges.toInt())}\")\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "graphs"], "code_uid": "9b89d8cfedb074b488101e756af6b0c6", "src_uid": "daf0dd781bf403f7c1bb668925caa64d", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args: Array) {\n val (a, b) = ex1(readLine()?.toInt() ?: return)\n println(\"$a $b\")\n}\n\nfun ex1(n: Int): Pair {\n var a = n / 2\n var b = n - a\n\n if (a == b) {\n a--\n b++\n }\n\n while(a != 1) {\n if (nod(a, b) == 1) return a to b\n a--\n b++\n }\n\n return a to b\n}\n\nfun nod(a: Int, b: Int): Int {\n var tmp: Int\n var valA = a\n var valB = b\n\n while(valB != 0) {\n tmp = valB\n valB = valA % valB\n valA = tmp\n }\n\n return valA\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms"], "code_uid": "94d0de5793a20030321c1584425abed6", "src_uid": "0af3515ed98d9d01ce00546333e98e77", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n var lo = readLine()!!.toLong()\n if(lo < 2) print(lo) else {\n if(++lo % 2L == 0L) print(lo/2)\n else print(lo)\n }\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "19e949894657dbcabcd9fd8e13e22167", "src_uid": "236177ff30dafe68295b5d33dc501828", "difficulty": 1000.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 (n, t, k, d) = readInts()\n // t minutes for an over to bake k carrot cakes\n // needs at least n cakes\n // d minutes to build a new oven\n // 8 6 4 5\n // 6 minutes to make 4 cakes, 5 minutes to build a new oven\n var tt = t\n var kk = k\n while (kk < n) {\n kk += k\n tt += t\n }\n if (t + d < tt) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "204405ba1a8b8918954169d3b1f89d93", "src_uid": "32c866d3d394e269724b4930df5e4407", "difficulty": 1100.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.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 H = sc.nextInt()\n var W = sc.nextInt()\n var A = Array>(H, {i -> Array(W, {j -> sc.nextInt()})})\n\n var solver = MinCostFlow(H*W+2)\n var s = H * W\n var t = H * W + 1\n\n var dx = arrayOf(0, 1)\n var dy = arrayOf(1, 0)\n\n for(y in 0 until H) for(x in 0 until W) for(i in 0 until 2) {\n var xx = x + dx[i]\n var yy = y + dy[i]\n if(xx < 0 || W <= xx || yy < 0 || H <= yy) continue\n\n var cost = 0\n if(A[y][x] != A[yy][xx]) cost = 1\n\n var a = y * W + x\n var b = yy * W + xx\n if((y + x) % 2 == 1) {\n var t = a\n a = b\n b = t\n }\n\n solver.addEdge(a, b, 1, cost)\n }\n\n for(y in 0 until H) for(x in 0 until W) {\n var a = y * W + x\n if((y + x) % 2 == 0) solver.addEdge(s, a, 1, 0)\n else solver.addEdge(a, t, 1, 0)\n }\n\n var ans = solver.minCostFlow(s, t, H * W / 2)\n println(ans)\n}\n\n\n\n\n\n\n\n\n\ninternal class MinCostFlow(var N: Int// 頂点数\n) {\n val INF = 1 shl 29\n var graph: ArrayList>\n\n init {\n this.graph = ArrayList>()\n for (i in 0..N - 1) {\n graph.add(ArrayList())\n }\n }\n\n fun addEdge(from: Int, to: Int, cap: Int, cost: Int) {\n graph[from].add(Edge(to, cap, cost, graph[to].size))\n graph[to].add(Edge(from, 0, -cost, graph[from].size - 1))\n }\n\n fun minCostFlow(start: Int, goal: Int, flow: Int): Int {\n var flow = flow\n val prevNode = IntArray(N)\n val prevEdge = IntArray(N)\n val potential = IntArray(N)// ポテンシャル(既にかかったコスト)\n var totalCost = 0\n while (flow > 0) {\n val dist = IntArray(N)\n Arrays.fill(dist, INF)\n dist[start] = 0\n\n val priorityQueue = PriorityQueue()\n priorityQueue.offer(Node(0, start))\n while (!priorityQueue.isEmpty()) {\n // キューから1番距離の近いノードを取り出す\n val node = priorityQueue.poll()\n val v = node.id\n if (dist[v] < node.dist) {\n // 暫定の最短距離よりも遠かったらスルー\n continue\n }\n\n for (i in 0..graph[v].size - 1) {\n val e = graph[v][i]\n\n if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + potential[v] - potential[e.to]) {\n dist[e.to] = dist[v] + e.cost + potential[v] - potential[e.to]\n priorityQueue.add(Node(dist[e.to], e.to))\n\n // 直前の経路を記憶しておく\n prevNode[e.to] = v\n prevEdge[e.to] = i\n }\n }\n }\n\n // そもそもゴールまで辿りつけない場合はどうしようもない\n if (dist[goal] == INF) {\n return -1\n }\n\n // 今回かかったコストをメモしておく\n for (v in 0..N - 1) {\n potential[v] += dist[v]\n }\n\n // startからgoalまで流せるだけ流す\n var minFlow = flow\n run {\n var now = goal\n while (now != start) {\n minFlow = Math.min(minFlow, graph[prevNode[now]][prevEdge[now]].cap)\n now = prevNode[now]\n }\n }\n flow -= minFlow\n totalCost += minFlow * potential[goal]\n\n var now = goal\n while (now != start) {\n val edge = graph[prevNode[now]][prevEdge[now]]\n edge.cap -= minFlow\n graph[now][edge.rev].cap += minFlow\n now = prevNode[now]\n }\n }\n return totalCost\n }\n\n internal inner class Node(var dist: Int, var id: Int) : Comparable {\n\n override fun compareTo(o: Node): Int {\n return this.dist - o.dist\n }\n }\n\n internal inner class Edge(var to: Int, var cap: Int, var cost: Int, var rev: Int)\n}\n\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": ["flows"], "code_uid": "71407ce6f775a76a0b71618a0dae1660", "src_uid": "1f0e8bbd5bf4fcdea927fbb505a8949b", "difficulty": 2200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val x = readLine()!!.toCharArray()\n var first = true\n print(x.asSequence().map {\n if ((!first || it != '9') && it > '4') {\n first = false\n '9' - it\n } else {\n first = false\n it\n }\n }.joinToString(\"\"))\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "c946b739b24cb9db21a5bb9038e90d88", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nfun main(args: Array) {\n val (n, k) = readLine()?.split(\" \")?.map(String::toLong) ?: return\n println(ex1(n, k))\n}\n\nfun ex1(n: Long, k: Long): Long {\n if (k == 1L) return 15 * n\n\n val red = roundUp(2 * n, k)\n val green = roundUp(5 * n, k)\n val blue = roundUp(8 * n, k)\n\n return red + green + blue\n}\n\nfun roundUp(num: Long, divisor: Long): Long {\n return (num + divisor - 1) / divisor\n}\n", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "d8aa1181a7c6748ab7abd15f0d0dc306", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39", "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 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 = IntArray(n, { io.readInt() })\n val l = a.last()\n val res = when {\n l == 15 -> \"DOWN\"\n l == 0 -> \"UP\"\n else -> when {\n a.size == 1 -> \"-1\"\n l > a[a.lastIndex - 1] -> \"UP\"\n l < a[a.lastIndex - 1] -> \"DOWN\"\n else -> \"-1\"\n }\n }\n io.println(res)\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "09ce75960e3d108af61dbcf95f7d6d62", "src_uid": "8330d9fea8d50a79741507b878da0a75", "difficulty": 1100.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.TreeSet\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\nfun main() {\n output {\n val n = readInt()\n val m = readInt()\n val K = readIntArray(n)\n\n val offers = MutableList(m) { Offer(readInt(), readInt() - 1) }\n offers.sortByDescending { it.day }\n\n val ksum = K.sum()\n\n val ans = (ksum..2 * ksum).bsFirst { lastDay ->\n val sub = offers.subList(offers.indices.bsFirst { offers[it].day <= lastDay }, m)\n .distinctBy { it.type }\n .asReversed()\n\n var krem = ksum\n var currDay = 0\n var money = 0\n\n for ((day, type) in sub) {\n money += day - currDay\n currDay = day\n\n val bought = min(money, K[type])\n money -= bought\n krem -= bought\n }\n\n money += lastDay - currDay\n money >= krem * 2\n }\n\n println(ans)\n }\n}\n\ndata class Offer(val day: Int, val type: Int)\n\nfun IntRange.bsFirst(predicate: (Int) -> Boolean): Int {\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 if(predicate(mid)) high = mid - 1\n else low = mid + 1\n }\n return low\n}\n\ninline fun IntRange.bsLast(crossinline predicate: (Int) -> Boolean) =\n bsFirst{ !predicate(it) } - 1\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": ["greedy", "binary search"], "code_uid": "ad3f0317c2fa6c7c29cd51b5bed02195", "src_uid": "2eb101dcfcc487fe6e44c9b4c0e4024d", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val (s, n) = r.readLine()!!.split(\" \").map { it.toInt() }\n val (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n when{\n n%2==1&&m>=n/2+1 -> println(maxOf(1, m-1))\n n%2==1 -> println(m+1)\n n%2==0&&m>n/2 -> println(m-1)\n else -> println(m+1)\n }\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "games", "math", "greedy", "implementation"], "code_uid": "ee362337d3ebecd2afaf9c0965f6cb1b", "src_uid": "f6a80c0f474cae1e201032e1df10e9f7", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\nimport java.util.Scanner\n\n//ndiff <= 3\n//1 win\n\n//2 one shift\n\n//3 middle shift, without mod\nfun main() {\n val scan = Scanner(System.`in`)\n scan.nextLine()\n val intArray = scan.nextLine()\n .split(\" \")\n .map {\n it.trim()\n .toInt()\n }\n .toIntArray()\n\n val set = intArray.toSet()\n\n val size = set.size\n when (size) {\n 0 -> println(0)\n 1 -> println(0)\n 2 -> {\n val max = set.max()!!\n val min = set.min()!!\n val diff = max - min\n if ((diff) % 2 == 0) {\n println(diff / 2)\n } else {\n println(set.max()!! - set.min()!!)\n }\n }\n 3 -> {\n val max = set.max()!!\n val min = set.min()!!\n val diff = max - min\n if ((diff) % 2 == 0) {\n val result = set.find { it != max && it != min }!!\n if (result == (diff / 2) + min) {\n println(diff / 2)\n return\n }\n }\n println(\"-1\")\n }\n else -> println(\"-1\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "df3e6e1f201b19f6ba9ba1591fe3ac54", "src_uid": "d486a88939c132848a7efdf257b9b066", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/*\n1. O(n) - count all identical nucleos subsequences lengths and record them by incrementing ith (length of subsequence)\n integer in an array of length 100 of map of nucleos\n2. go from top and increment number of inserts by 1 for each even length until max length is only uneven\n */\n\nprivate const val maxDnaLength = 101\n\nfun main() {\n val dna = readLine()!!\n var currentSequenceLength = 1\n var currentNucleo = dna[0]\n var inserts = 0\n for (i in 1 until dna.length) {\n if (dna[i] != currentNucleo) {\n if (currentSequenceLength % 2 == 0) inserts++\n currentSequenceLength = 1\n currentNucleo = dna[i]\n } else {\n currentSequenceLength++\n }\n }\n if (currentSequenceLength % 2 == 0) inserts++\n println(inserts)\n}", "lang_cluster": "Kotlin", "tags": ["two pointers", "implementation"], "code_uid": "9e12b261384921a2ef4054cb07e696c5", "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f", "difficulty": null, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val a = readLine()!!.split( \" \").map { it.toInt() }\n val c = IntArray(6)\n for (i in a) c[i]++\n var k = 2\n var res = 0\n var s = a.sum()\n while (10 * s < 45 * n) {\n while (c[k] == 0) k++\n s += 5 - k\n c[k]--\n res++\n }\n println(res)\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "greedy"], "code_uid": "2ae6c0d536a5ed97a996c98db3454491", "src_uid": "715608282b27a0a25b66f08574a6d5bd", "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 println(doIt(n, m))\n}\n\nfun doIt(n: Int, m: Int): Int {\n return if (m == 0) 1 else min(m, n - m)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "58b596cf5a4bf793cbbe039845f4ef0d", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.min\n\nfun main() {\n val (totalPages, initialSpeed, maxSpeed, acceleration, reRead) = readLine()!!.split(\" \").map(String::toInt)\n var pages = 0\n for (day in 0..totalPages) {\n pages += min(initialSpeed + day * acceleration, maxSpeed)\n if (pages >= totalPages) return print(day + 1)\n pages -= reRead\n }\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "4db3bdb0269570a9768d74faf89475ee", "src_uid": "b743110117ce13e2090367fd038d3b50", "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.*\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] += v\n dp[i][j] += MOD - v\n if (j + 1 <= t + 1) {\n dp[i][j + 1] += v\n dp[i][t + 1] += MOD - v\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 // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl() + offset\n }\n return res\n }\n\n private fun na2(n: Int, offset: Int = 0): Array {\n val a = Array(2){IntArray(n)}\n for (i in 0 until n) {\n for (e in a) {\n e[i] = ni() + offset\n }\n }\n return a\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}\n", "lang_cluster": "Kotlin", "tags": ["dp", "combinatorics"], "code_uid": "b2a4e3d7de1f7b1966aff78ce3d85ab9", "src_uid": "142b06ed43b3473513995de995e19fc3", "difficulty": 1900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "val MOD = 1000000007\n\nfun multiplyMatrices(firstMatrix: Array>, secondMatrix: Array>, r1: Int, c1: Int, c2: Int): Array> {\n val product = Array(r1) { IntArray(c2).toTypedArray() }\n for (i in 0 until r1) {\n for (j in 0 until c2) {\n for (k in 0 until c1) {\n product[i][j] = ((product[i][j].toLong() + firstMatrix[i][k].toLong() * secondMatrix[k][j].toLong()) % MOD).toInt()\n }\n }\n }\n\n return product\n}\n\nfun rise(matrix: Array>, p: Long): Array> {\n var ind = 0\n var multiArray = Array>(matrix.size) { Array(matrix.size) {0} }\n for (row in 0 until matrix.size) {\n multiArray[row][row] = 1\n }\n var factor = matrix\n while ((p shr ind) > 0) {\n if ((p shr ind) and 1L == 1L)\n multiArray = multiplyMatrices(multiArray, factor, matrix.size, matrix.size, matrix.size)\n factor = multiplyMatrices(factor, factor, matrix.size, matrix.size, matrix.size)\n ind++\n }\n return multiArray\n}\n\nfun main(args: Array) {\n val (n, ml) = readLine()!!.split(' ').map(String::toLong)\n val m = ml.toInt()\n val multiArray = Array>(m) { Array(m) {0} }\n for (row in 0 until m-1) {\n multiArray[row][row+1] = 1\n }\n multiArray[m-1][0] = 1\n multiArray[m-1][m-1] = 1\n\n val finar = rise(multiArray, n)\n\n val init = Array>(m) { Array(1) {1} }\n\n val result = multiplyMatrices(finar, init, m, m, 1)\n\n print(result[0][0])\n}", "lang_cluster": "Kotlin", "tags": ["math", "matrices", "dp"], "code_uid": "028306898367c80dd7bc2d2adf7a7974", "src_uid": "e7b9eec21d950f5d963ff50619c6f119", "difficulty": 2100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val field = mutableListOf>()\n for (i in 0 until 4) {\n readLine()?.toCharArray()?.toMutableList()?.let { field.add(it) }\n }\n\n\n for (y in 0 until 4) {\n for (x in 0 until 4) {\n if (field[y][x] == '.' && isWinPosition(x, y, field)) {\n println(\"YES\")\n return\n }\n }\n }\n println(\"NO\")\n\n\n}\n\nfun isWinPosition(x: Int, y: Int, field: List>): Boolean {\n return (isX(x - 1, y, field) && isX(x - 2, y, field)) ||\n (isX(x + 1, y, field) && isX(x + 2, y, field)) ||\n (isX(x - 1, y, field) && isX(x + 1, y, field)) ||\n (isX(x, y - 1, field) && isX(x, y - 2, field)) ||\n (isX(x, y + 1, field) && isX(x, y + 2, field)) ||\n (isX(x, y - 1, field) && isX(x, y + 1, field)) ||\n\n (isX(x - 1, y - 1, field) && isX(x - 2, y - 2, field)) ||\n (isX(x + 1, y + 1, field) && isX(x + 2, y + 2, field)) ||\n (isX(x - 1, y - 1, field) && isX(x + 1, y + 1, field)) ||\n\n (isX(x - 1, y + 1, field) && isX(x - 2, y + 2, field)) ||\n (isX(x + 1, y - 1, field) && isX(x + 2, y - 2, field)) ||\n (isX(x - 1, y + 1, field) && isX(x + 1, y - 1, field))\n}\n\nfun isX(x: Int, y: Int, field: List>): Boolean {\n return try {\n field[y][x] == 'x'\n } catch (e: Exception) {\n return false\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "dd3cd9da2aac9535a726f0c6298b2a30", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "var total = 0\n\nfun search(array: ArrayList, target: Int):Int{\n var low = 0\n var high = array.size-1\n\n while (low <= high){\n val mid = (low+high)/2;\n if (target>array[mid]){\n high=mid-1\n }else if(target, k: Int){\n //ищем куда вставить и вставляем\n //ищем место для вставки b\n total+=k\n b.add(search(b,k), k)\n}\n\nfun check(b: ArrayList, k: Int, m: Int): Int{\n var sum = total\n var steps = 0\n while (sum+k>m){\n sum-=b[steps]\n steps++\n }\n return steps\n}\n\nfun main(){\n val (n, m) = readLine()!!.split(' ').map { it.toInt() }\n val arr = readLine()!!.split(' ').map { it.toInt() }\n val b = arrayListOf()\n for (i in arr){\n print(\"${check(b, i, m)} \")\n put(b, i)\n }\n}", "lang_cluster": "Kotlin", "tags": ["sortings", "greedy"], "code_uid": "4938280c5fcb218af5d4c18c7c7ae8a9", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346", "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\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": "f18976ccb526712c03944c72a5342b09", "src_uid": "09601fd1742ffdc9f822950f1d3e8494", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.lang.System.exit\nimport java.util.*\n\n\nfun main(args: Array) {\n val offset = 96\n var n = 0 // участники\n var k = 0 // комплекты\n var a = charArrayOf()\n val bufferedReader = BufferedReader(System.`in`.bufferedReader())\n var lineNumber = 1\n while (true) {\n val line = (bufferedReader.readLine())\n val scanner = Scanner(line)\n when (lineNumber) {\n 1 -> {\n n = scanner.nextInt()\n k = scanner.nextInt()\n }\n 2 -> {\n var s = scanner.next()\n a = s.toCharArray()\n }\n }\n if (lineNumber == 2) break\n lineNumber++\n }\n\n a.sort()\n val rocket = CharArray(k)\n rocket[0] = a[0]\n var sum = a[0].toInt() - offset\n\n loop@ for (i in 1 until k) {\n for (j in 0 until a.size) {\n val currValue = a[j]\n if (currValue.toInt() == 0) continue\n if ((currValue - rocket[i - 1]) >= 2) {\n rocket[i] = currValue\n sum += currValue.toInt() - offset\n a[j] = 0.toChar()\n continue@loop\n }\n }\n print(-1)\n exit(0)\n }\n print(sum)\n}\n\n", "lang_cluster": "Kotlin", "tags": ["sortings", "implementation", "greedy"], "code_uid": "a1a01b8556913bef3f80c192eac0af94", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDouble() = readLn().toDouble() // single Double\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n\nfun derange(n: Int) : Int {\n when(n) {\n 0 -> return 1\n 1 -> return 0\n 2 -> return 1\n 3 -> return 2\n 4 -> return 9\n }\n return 0\n}\n\nfun ncr(n: Int, r: Int): Long {\n if (r > n || r < 0 || n < 0) return 0\n var ans = 1L\n\n for (i in 0 until r) ans *= n - i\n for (i in 1..r) ans /= i\n\n return ans\n}\n\nfun solve(){\n var (n, k) = readInts()\n var ans:Long = 0L\n\n for (i in 0..k) ans += ncr(n, i) * derange(i)\n\n println(ans)\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": ["math", "dp", "combinatorics"], "code_uid": "fbc3310b22cec0219b1895f154e729c2", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.*\nfun main() {\n val fs = CodeForces.FastReader()\n var n = fs.nextInt()\n var ans =0\n for (i in 1..n) {\n for (j in i..n) {\n var k = i xor j\n if(k in 1..n){\n var sum = i+j+k\n var max = max(max(i,j),k)\n var min = min(min(i,j),k)\n if(sum - max > max && sum - max - 2*min < max ){\n ans++\n }\n }\n }\n }\n println(ans/3)\n}\n\nclass CodeForces {\n internal class FastReader {\n private var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\n private 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 }\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 return str\n }\n\n fun readIntArray(n: Int): IntArray {\n val a = IntArray(n)\n for (i in 0 until n) a[i] = nextInt()\n return a\n }\n\n fun readLongArray(n: Int): LongArray {\n val a = LongArray(n)\n for (i in 0 until n) a[i] = nextLong()\n return a\n }\n\n fun readDoubleArray(n: Int): DoubleArray {\n val a = DoubleArray(n)\n for (i in 0 until n) a[i] = nextDouble()\n return a\n }\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force"], "code_uid": "aad0f0b6bbd1d0a4d19ddabdcf949859", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d", "difficulty": 1300.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) = readInts()\n val (x, y, z) = readInts()\n var necessary = max(0, x - a) + max(0, y - b) + max(0, z - c)\n necessary -= max(0, a - x) / 2 + max(0, b - y) / 2 + max(0, c - z) / 2\n print(if (necessary <= 0) \"Yes\" else \"No\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8521aa0471246f15f7a6f87b61c38948", "src_uid": "1db4ba9dc1000e26532bb73336cf12c3", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\nfun main() {\n\n val scanner = Scanner(System.`in`)\n\n val n = scanner.nextLine()\n val s = scanner.nextLine()\n\n val tmpList = mutableListOf()\n val posA = mutableListOf()\n\n for (i in 0 until s.length) {\n val ch = s[i]\n if (ch.isLowerCase()) {\n if (!tmpList.contains(ch)) {\n tmpList.add(ch)\n posA.add(tmpList.size)\n } else {\n\n }\n } else {\n tmpList.clear()\n }\n\n }\n\n if (posA.isEmpty()) {\n println(\"0\")\n } else {\n println(posA.sortedDescending()[0])\n }\n\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "strings", "implementation"], "code_uid": "f0ad92d184a7dda10c92217b6d6ca17d", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "const val MOD = 1000000007L\n\nfun main() {\n val n = readLine()!!.toInt()\n var answer = 1L\n for (j in 1L..n.toLong()) {\n answer *= j\n answer %= MOD\n }\n var subtractend = 1L\n for (j in 2..n) {\n subtractend *= 2L\n subtractend %= MOD\n }\n answer -= subtractend\n answer %= MOD\n answer += MOD\n answer %= MOD\n println(answer)\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "graphs"], "code_uid": "2a6b72873d597294b19770bfefdbacac", "src_uid": "3dc1ee09016a25421ae371fa8005fce1", "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.*\nimport kotlin.math.*\nfun main() {\n val fs = CodeForces.FastReader()\n var x = fs.nextInt()\n var y = fs.nextInt()\n var n = fs.nextInt()\n var a:Int=0\n var b:Int=0\n var min:Double = Double.MAX_VALUE\n for (i in 1..n) {\n var l = 0; var p = x\n var value:Double\n while (l <= p) {\n var k = (l+p)/2\n value = abs(x/y.toDouble() - k/i.toDouble())\n if(value < min && min-value > 0.000000000000001){\n min = value.also { a=k;b=i }\n }\n if(value > abs(x/y.toDouble() - (k-1)/i.toDouble())) p = k-1\n else l = k+1\n }\n }\n while (a % 2 == 0 && b % 2 == 0) {\n a /= 2\n b /= 2\n }\n println(\"$a/$b\")\n}\n\nclass CodeForces {\n internal class FastReader {\n private var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))\n private 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 }\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 return str\n }\n\n fun readIntArray(n: Int): IntArray {\n val a = IntArray(n)\n for (i in 0 until n) a[i] = nextInt()\n return a\n }\n\n fun readLongArray(n: Int): LongArray {\n val a = LongArray(n)\n for (i in 0 until n) a[i] = nextLong()\n return a\n }\n\n fun readDoubleArray(n: Int): DoubleArray {\n val a = DoubleArray(n)\n for (i in 0 until n) a[i] = nextDouble()\n return a\n }\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["two pointers", "implementation", "brute force"], "code_uid": "8b77651359479b9d90b4e863b1b7089f", "src_uid": "827bc6f120aff6a6f04271bc84e863ee", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.abs\n\nfun main() {\n var n = readLine()!!.toInt()\n var list1 = readLine()!!.split(' ').map { it.toInt() }\n var list2 = readLine()!!.split(' ').map { it.toInt() }\n\n var l = Array(6, { 0 })\n var r = Array(6, { 0 })\n\n list1.forEach {\n l[it]++\n }\n list2.forEach {\n r[it]++\n }\n var move = 0\n for (i in 1..5) {\n var diff = l[i] + r[i]\n if (diff % 2 == 1) {\n println(-1)\n return\n }\n var mayHave = diff / 2\n move += abs(l[i] - mayHave) + abs(r[i] - mayHave)\n }\n println(move / 4)\n\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms"], "code_uid": "9a57ebab68011ab771bbdb0efd26c222", "src_uid": "47da1dd95cd015acb8c7fd6ae5ec22a3", "difficulty": 1000.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 s = reader.next()\n for (i in 1 until s.length - 1) {\n if (s[i - 1] == '.' || s[i] == '.' || s[i + 1] == '.') {\n continue\n }\n\n if (s[i - 1] != s[i] && s[i - 1] != s[i + 1] && s[i] != s[i + 1]) {\n writer.println(\"yes\")\n return\n }\n }\n writer.println(\"no\")\n}\n\nfun gcd(a: Int, b: Int): Int {\n return if (b == 0) a else gcd(b, a % b)\n}\n\nclass InputReader(stream: InputStream) {\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}", "lang_cluster": "Kotlin", "tags": ["strings", "implementation"], "code_uid": "7342ce11d8711b91fef6d10ab6d586c2", "src_uid": "ba6ff507384570152118e2ab322dd11f", "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 s = br.readLine()\n val n = s.length\n println(\n if (s == \"0\") {\n 0\n } else if (s.filter { it == '1' }.length == 1) {\n n/2\n } else {\n (n + 1)/2\n }\n )\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "b5692fe6de1f2d5a9dd56a3d3a443dbe", "src_uid": "d8ca1c83b431466eff6054d3b422ab47", "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, c) = readInts()\n var dividend = 10 * (a % b)\n var quotient = dividend / b\n var sol = 1\n val visited = mutableSetOf()\n while (quotient != c) {\n sol++\n if (dividend in visited) return print(-1)\n visited.add(dividend)\n dividend = 10 * (dividend % b)\n quotient = dividend / b\n }\n print(sol)\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "802762b00778a92d31c8dd2007d6b192", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910", "difficulty": 1300.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 = readInt()\n\n if (n%2 != 0) {\n println(0)\n return\n }\n\n println(1 shl (n/2))\n}", "lang_cluster": "Kotlin", "tags": ["math", "dp"], "code_uid": "2dcb1ed841fdc3dadb7527eeff35aeae", "src_uid": "4b7ff467ed5907e32fd529fb39b708db", "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 //var (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val v = r.readLine()!!.split(\" \").map { it.toInt() }\n val str = r.readLine()\n val len = str.length\n var nexti = 0\n var ans = true\n while (ans && nexti < len) {\n //println(nexti)\n when (str[nexti]) {\n '1' -> when {\n nexti == len - 1 -> nexti++\n nexti == len - 2 && (str[nexti + 1] == '4' || str[nexti + 1] == '1') -> nexti += 2\n nexti == len - 3 && (str[nexti + 1] == '4' || str[nexti + 1] == '1') && (str[nexti + 2] == '4' || str[nexti + 2] == '1') -> nexti += 3\n nexti <= len - 3 && str[nexti + 1] == '4' && str[nexti + 2] == '4' -> nexti += 3\n nexti <= len - 2 && str[nexti + 1] == '4' -> nexti += 2\n else -> nexti++\n }\n else -> ans = false\n }\n }\n println(if (ans) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy"], "code_uid": "28d28c9dc2e9d8002a183c86a9787577", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(){\n repeat(8){\n var line = readLine()!!\n var flag =\n if (line.contains(\"WW\") || line.contains(\"BB\")){\n println(\"NO\")\n return\n }else{\n\n }\n }\n println(\"YES\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "strings"], "code_uid": "87ad6e22ed4ad81dd318cf9b7af93a15", "src_uid": "ca65e023be092b2ce25599f52acc1a67", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (n, ks) = readLine()!!.split(\" \")\n val k = ks.toInt()\n if (k == 0) return print(0)\n var sol = 0\n var numZeros = 0\n for (c in n.reversed()) {\n if (c == '0') numZeros++ else sol++\n if (numZeros == k) break\n }\n print(if (numZeros == k) sol else n.length - 1)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "greedy"], "code_uid": "bd659cbd3abe80acb5afa290bde34248", "src_uid": "7a8890417aa48c2b93b559ca118853f9", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Long.max\nimport java.util.*\nimport java.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=998244353L\nfun mul(x:Long,y:Long):Long=x*y%mod\nfun add(x:Long,y:Long):Long{\n val z=x+y\n if(z>=mod)return z-mod\n else return z\n}\nfun sub(x:Long,y:Long):Long{\n val z=x-y\n if(z<0L)return z+mod\n else return z\n}\nfun pw(_x:Long,_k:Long):Long{\n var ans=1L\n var k=_k\n var x=_x\n while(k>0){\n if(k%2L==1L)ans=mul(ans,x)\n x=mul(x,x)\n k/=2L\n }\n return ans;\n}\n\nfun main(){\n var (n,k)=readLongs()\n var F=LongArray((n+1).toInt()){1}\n var I=LongArray((n+1).toInt()){1}\n for(i in 1..n)F[i.toInt()]=mul(F[(i-1).toInt()],i)\n for(i in 2..n)I[i.toInt()]=mul((mod-mod/i),I[(mod%i).toInt()])\n for(i in 1..n)I[i.toInt()]=mul(I[i.toInt()],I[(i-1).toInt()])\n fun binom(n:Long,k:Long):Long{\n return mul(F[n.toInt()],mul(I[(n-k).toInt()],I[k.toInt()]))\n }\n if(k>=n)printLine(\"0\")\n else{\n var m=n-k\n var ans=0L\n var bsz=0L\n for(i in m downTo 1){\n bsz=binom(n-i,m-i)\n var now=mul(mul(binom(n,i),pw(i,n)),bsz)\n if((m-i)%2L==0L){\n ans=add(ans,now)\n }else{\n ans=sub(ans,now)\n }\n }\n if(k!=0L)ans=mul(ans,2)\n printLine(\"$ans\")\n }\n output()\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics", "fft"], "code_uid": "706b22c02744e0ca90fa7d7ac9676e63", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc", "difficulty": 2300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner\nimport java.util.Arrays\nfun main(){\n val input=Scanner(System.`in`)\n var x:Int=input.nextInt()\n var t:Int=input.nextInt()\n var a:Int=input.nextInt()\n var b:Int=input.nextInt()\n var c:Int=input.nextInt()\n var d:Int=input.nextInt()\n for(i in 0 until t){\n for(j in 0 until t){\n if(a-(i*c)+b-(j*d)==x||a-(i*c)==x||b-(j*d)==x||x==0){\n print(\"YES\")\n return\n }\n }\n }\n print(\"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "977418d341eddb36fa5146c9a555e91d", "src_uid": "f98168cdd72369303b82b5a7ac45c3af", "difficulty": 1200.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 com = sc.next()\n\n var x = 0\n var y = 0\n for (c in com) {\n when (c) {\n 'U' -> y += 1\n 'D' -> y -= 1\n 'L' -> x -= 1\n 'R' -> x += 1\n }\n\n }\n\n println(n - Math.abs(x) - Math.abs(y))\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", "lang_cluster": "Kotlin", "tags": ["greedy"], "code_uid": "33f9107655b94569dbb5ea80c5518604", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val a = Array(3) {readLine()}\n var bad = false\n for (i in 0 until 3)\n for (j in 0 until 3)\n bad = bad or (a[i]!![j] != a[2 - i]!![2 - j])\n println(if (bad) \"NO\" else \"YES\")\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "57a8a1647e3cf6d0611c75ca777aa889", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9", "difficulty": 800.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 sz = 1024 * 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 val n = nextLong()\n val k = nextLong()\n val m = nextLong()\n val d = nextInt()\n var ans = 0L\n for (i in 1..d) {\n val num1 = k * (i - 1) + 1\n val num2 = k * i\n if (num1 > n) break\n //x * num1 <= n <= x * (num2 + 1) - 1\n //n + 1 <= x * (num2 + 1)\n val xl = divup(n + 1, num2 + 1)\n val xr = n / num1\n if (m >= xl) ans = max(ans, min(xr, m) * i)\n }\n println(ans)\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 maxPair(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\n//val t = IntArray(2 * sz)\n//val t = Array(2 * sz) { ArrayList() }\n\n/*\nfun add(v: Int, vl: Int, vr: Int, x: Int, y: Int) {\n if (vl == vr) {\n t[v].add(y)\n return\n }\n val vm = (vl + vr) / 2\n if (x <= vm)\n add(v * 2 + 1, vl, vm, x, y)\n else\n add(v * 2 + 2, vm + 1, vr, x, y)\n}\n\nfun build() {\n //for (i in (sz - 1)..(2 * sz - 2)) t[i].sort()\n var i = sz - 2\n while (i >= 0) {\n val n1 = t[2 * i + 1].size\n val n2 = t[2 * i + 2].size\n var i1 = 0\n var i2 = 0\n for (j in 1..(n1 + n2)) {\n if (i1 == n1) {\n t[i].add(t[2 * i + 2][i2++])\n } else if (i2 == n2) {\n t[i].add(t[2 * i + 1][i1++])\n } else {\n if (t[2 * i + 1][i1] < t[2 * i + 2][i2])\n t[i].add(t[2 * i + 1][i1++])\n else\n t[i].add(t[2 * i + 2][i2++])\n }\n }\n i--\n }\n}\n\nfun query(v: Int, vl: Int, vr: Int, lx: Int, rx: Int): Int {\n if (vl > rx || lx > vr) return 0\n if (vl >= lx && vr <= rx) {\n if (t[v].isEmpty()) return 0\n //return upperBound(t[v], ry) - lowerBound(t[v], ly)\n return upperBound(t[v], rx)\n }\n val vm = (vl + vr) / 2\n return query(v * 2 + 1, vl, vm, lx, rx) +\n query(v * 2 + 2, vm + 1, vr, lx, rx)\n}\n\n */\n\n/*\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\n*/\n\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\n */\n\nfun upperBound(a: ArrayList, x: Int): Int {\n if (a[0] > x) return 0\n if (back(a) <= x) return a.size\n var l = 0\n var r = a.size - 1\n while (l != r) {\n val m = (l + r) / 2\n if (a[m] > x) r = m else l = m + 1\n }\n return l\n}\n\nfun lowerBound(a: ArrayList, x: Int): Int {\n if (back(a) < x) return a.size\n var l = 0\n var r = a.size - 1\n while (l != r) {\n val m = (l + r) / 2\n if (a[m] >= x) r = m else l = m + 1\n }\n return l\n}\n\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\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": ["math"], "code_uid": "c703801fd1b7ed196b37dc0f2c48d7dd", "src_uid": "ac2e795cd44061db8da13e3947ba791b", "difficulty": 2000.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 (len, k) = r.readLine()!!.split(\" \").map { it.toInt() }\n val (a, b, c) = r.readLine()!!.split(\" \").map { it.toInt() }\n val d = minOf(a+b+c, 2*a+2*b)\n val e = minOf(2*(a+c), 2*(b+c))\n println(minOf(d, e))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "b2f4bf4c909cfeeb314ce3f772468508", "src_uid": "26cd7954a21866dbb2824d725473673e", "difficulty": 800.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": "a39806f50979b3768c3780301c77e426", "src_uid": "11e6559cfb71b8f6ca88242094b17a2b", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(){\n var k = readLine()!!.toInt()\n var l = readLine()!!.toInt()\n var count = -1\n while (l>1){\n if (l%k!=0){\n println(\"NO\")\n return\n }else{\n count++\n l/=k\n }\n }\n println(\"YES\")\n println(count)\n\n\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "716f4dc6219bbf42169cc235e35c9a64", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (_, s) = readInts()\n val a = readInts()\n print(if (a.sum() - a.max()!! <= s) \"YES\" else \"NO\")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "b52fff150b03b51230f7aa8f42b9593c", "src_uid": "496baae594b32c5ffda35b896ebde629", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun solve(inn: InputReader, out: PrintWriter) {\n val S = inn.readString()\n\n val cnt = IntArray(10)\n for (ch in S) {\n ++cnt[(ch - '0').toInt()]\n }\n\n val fact = LongArray(20)\n fact[0] = 1\n for (i in 1..19) {\n fact[i] = i * fact[i - 1]\n }\n\n var result = 0L\n val way = mutableListOf()\n\n fun binom(n: Int, k: Int): Long {\n return fact[n] / (fact[k] * fact[n - k])\n }\n\n fun go(i: Int, way: MutableList, len: Int) {\n if (i == cnt.size) {\n if (len == 0) {\n return\n }\n var extra = fact[len]\n for (w in way) {\n extra /= fact[w]\n }\n\n if (cnt[0] == 0) {\n result += extra\n return\n }\n\n for (c in 1..cnt[0]) {\n val extra2 = binom(c + len - 1, c) * extra\n result += extra2\n }\n\n return\n }\n\n if (cnt[i] == 0) {\n go(i + 1, way, len)\n return\n }\n\n for (j in 1..cnt[i]) {\n way.add(j)\n go(i + 1, way, len + j)\n way.removeAt(way.size - 1)\n }\n }\n go(1, way, 0)\n\n out.print(result)\n}\n\nfun main(args: Array) {\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 val mReader = inputStream.bufferedReader()\n var mTokenizer: StringTokenizer? = null\n\n fun close() = mReader.close()\n\n fun readString(): String {\n if (mTokenizer == null || !mTokenizer!!.hasMoreTokens()) {\n mTokenizer = StringTokenizer(mReader.readLine())\n }\n\n return mTokenizer!!.nextToken()\n }\n\n fun readInt(): Int = readString().toInt()\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "combinatorics"], "code_uid": "fa5df11c46c3dbd9a1e05a282f786283", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "//package codeforces.round394\n\nimport java.io.PrintWriter\nimport java.util.*\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val `in` = Scanner(inputStream)\n val out = PrintWriter(outputStream)\n solve(`in`, out)\n out.close()\n}\n\nprivate fun solve(scanner: Scanner, out: PrintWriter) {\n val even = scanner.nextInt()\n val odd = scanner.nextInt()\n\n if (Math.abs(even - odd) > 1 || (even == 0) && (odd == 0)) {\n out.println(\"NO\")\n } else {\n out.println(\"YES\")\n }\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "constructive algorithms", "implementation"], "code_uid": "1ed7b686e8301337cdd686e751abf49e", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037", "difficulty": 1000.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 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\n val ans = (6..n).count {\n it.factorizeDistinct().take(3).count() == 2\n }\n\n println(ans)\n}\n\nfun Int.factorizeDistinct() = sequence {\n var n = this@factorizeDistinct\n\n for(p in 2..Int.MAX_VALUE) {\n if(p * p > n) break\n\n if(n % p == 0) {\n yield(p)\n do { n /= p } while(n % p == 0)\n }\n }\n\n if(n > 1) yield(n)\n}\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\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": ["number theory"], "code_uid": "465166d4d69236dfb609ac1654359ac2", "src_uid": "356666366625bc5358bc8b97c8d67bd5", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args: Array) {\n val (a, b) = readLine()!!.split(\" \").map(String::toInt)\n val (c, d) = readLine()!!.split(\" \").map(String::toInt)\n\n var ans = -1\n\n loop@ for (x in 0..99) {\n for (y in 0..99) {\n val t1 = b + x * a\n val t2 = d + y * c\n if (t1 == t2) {\n ans = t1\n break@loop\n }\n }\n }\n\n println(ans)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "d98019ca3839581e324ba3e33b0b6083", "src_uid": "158cb12d45f4ee3368b94b2b622693e7", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.*\n//tutorial\nfun main(){\n\tval f = BufferedReader(InputStreamReader(System.`in`))\n\n\tval n = f.readLine().toInt()\n\tval array = f.readLine().toCharArray()\n\n\tval dp = Array(n){IntArray(n){Int.MAX_VALUE}}\n\n\tfun calc(l : Int, r : Int) : Int{\n\n\t\tif(r < l) return 0\n\t\tif(l == r){\n\t\t\tdp[l][r] = 1\n\t\t\treturn 1\n\t\t}\n\t\tif(dp[l][r] != Int.MAX_VALUE) return dp[l][r]\n\n\t\tvar min = 1 + calc(l,r-1)\n\t\tfor(k in l until r){\n\t\t\tif(array[k] == array[r]){\n\t\t\t\tmin = min(min,calc(l,k) + calc(k+1,r-1))\n\t\t\t}\n\t\t}\n\n\t\tdp[l][r] = min\n\t\treturn dp[l][r]\n\t}\n\n\n\n\n\tval answer = calc(0,n-1)\n\t/*\n\tfor(k in 0 until n){\n\t\tprintln(dp[k].joinToString(\" \"))\n\t}*/\n\tprintln(answer)\n\n}\n", "lang_cluster": "Kotlin", "tags": ["dp"], "code_uid": "9b010677e09595f0ddc15b15bba2b799", "src_uid": "516a89f4d1ae867fc1151becd92471e6", "difficulty": 2000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "val MOD = 998244353\nval MAXN = 5000\n\nvar dp = Array(MAXN+5, { IntArray(MAXN+5) })\nfun D(a: Int, b: Int) : Int\n{\n if (a == 0 || b == 0) return 1;\n\n if (dp[a][b] == 0)\n {\n dp[a][b] = ((b.toLong() * D(a - 1, b - 1) + D(a - 1, b)) % MOD).toInt();\n }\n\n return dp[a][b];\n}\n\n\nfun main(args: Array) {\n val xs = readLine()!!.split(' ').map(String::toInt).sorted()\n val (a, b, c) = xs\n\n println(((D(a, b).toLong() * D(b, c).toLong()) % MOD * D(a, c).toLong()) % MOD);\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics"], "code_uid": "82b4559b160b9e44b053b8f14ce83889", "src_uid": "b6dc5533fbf285d5ef4cf60ef6300383", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDouble() = readLn().toDouble() // single Double\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n\nfun solve(){\n var (n, m) = readInts()\n var arr = readInts()\n var n1 = n / 2; var n2 = n - n1\n\n var ans = 0\n var left = TreeSet()\n var right = TreeSet()\n for (mask in 0 until (1 shl n1)) {\n var sum = 0\n for (i in 0 until n1) {\n if ((mask and (1 shl i)) == (1 shl i)) sum = (sum + arr[i])%m\n }\n left.add(sum)\n ans = Math.max(ans, sum)\n }\n\n for (mask in 0 until (1 shl n2)) {\n var sum = 0\n for (i in 0 until n2) {\n if ((mask and (1 shl i)) == (1 shl i)) sum = (sum + arr[i + n1])%m\n }\n right.add(sum)\n ans = Math.max(sum, ans)\n }\n\n\n for (x in left) {\n var req = m - x\n var it = right.lower(req)\n if (it != null) {\n ans = Math.max(ans, (it + x)%m)\n }\n it = right.lower(req + m)\n if (it != null) {\n ans = Math.max(ans, (it + x)%m)\n }\n }\n\n println(ans)\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": ["meet-in-the-middle", "divide and conquer", "bitmasks"], "code_uid": "92213a9c33934094cbc0573125e845a9", "src_uid": "d3a8a3e69a55936ee33aedd66e5b7f4a", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.lang.Math.*\nimport java.util.*\n\nval scanner = Scanner(System.`in`)\nval fastReader = BufferedReader(InputStreamReader(System.`in`))\nval output = StringBuilder()\nval INF = Long.MAX_VALUE\nval mod = 998244353L\nval N = 200005\n\nval fact = LongArray(N)\nfun fillFact() {\n fact[0] = 1\n for (i in 1 until N) {\n fact[i] = (fact[i - 1] * i) % mod\n }\n}\n\nfun mult(x: Long, y: Long) = (x * y) % mod\n\nfun binPow(x: Long, y: Long): Long {\n if (y == 0L) return 1\n return if (y % 2 == 0L) {\n val temp = binPow(x, y / 2)\n mult(temp, temp)\n } else mult(binPow(x, y - 1), x)\n}\n\nfun inv(x: Long) = binPow(x, mod - 2)\n\nfun divide(x: Long, y: Long) = mult(x, inv(y))\nfun readInt() = fastReader.readLine()!!.toInt()\nfun readInts() = fastReader.readLine()!!.split(\" \").map { it.toInt() }\nfun readLong() = fastReader.readLine()!!.toLong()\nfun readLongs() = fastReader.readLine()!!.split(\" \").map { it.toLong() }\nfun readDouble() = fastReader.readLine()!!.toDouble()\nfun readDoubles() = fastReader.readLine()!!.split(\" \").map { it.toDouble() }\n\nfun main() {\n fillFact()\n val n = scanner.nextInt()\n val m = scanner.nextInt()\n println(\n if (n == 2) 0 else mult(\n divide(fact[m], mult(fact[n - 1], fact[m - n + 1])),\n mult(n - 2L, binPow(2, n - 3L))\n )\n )\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "6603ec7294f97f79c52746472cce8edc", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport java.util.Collections.min\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\nimport kotlin.collections.HashSet\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\n\nfun main(args : Array) {\n val read = Scanner(System.`in`)\n val (n, h, m) = readInts()\n\n val a = IntArray(n) {h}\n\n for (i in 1..m)\n {\n val (l, r, x) = readInts()\n for(j in l-1 until r)\n {\n a[j] = min(a[j], x)\n }\n }\n\n var ans=0\n for(i in 0 until n)\n {\n ans += a[i]*a[i]\n }\n\n println(ans)\n return\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "63c09a32670fe246c47b1a6a87eaa86b", "src_uid": "f22b6dab443f63fb8d2d288b702f20ad", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.*\nimport java.util.*\n\nfun solve() {\n var l = nextInt()\n var r = nextInt()\n var x = nextInt()\n var y = nextInt()\n var k = nextInt()\n var ok = false\n for (b in x..y) {\n if(b * 1L * k in l..r) {\n ok = true\n }\n }\n pw.println(if(ok) \"yes\" else \"no\")\n}\n\nfun hasNext() : Boolean {\n while (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine() ?: return false)\n return true\n}\n\nfun next() = if(hasNext()) st.nextToken()!! else throw RuntimeException(\"No tokens\")\n\nfun nextInt() = next().toInt()\n\nfun nextLong() = next().toLong()\n\nfun nextLine() = if(hasNext()) st.nextToken(\"\\n\") else throw RuntimeException(\"No tokens\")\n\nfun nextArray(n : Int) = IntArray(n,{nextInt()})\n\nval ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n\nval br = when(ONLINE_JUDGE) {\n true -> BufferedReader(InputStreamReader(System.`in`))\n else -> BufferedReader(FileReader(\"in.txt\"))\n}\n\nval pw = when(ONLINE_JUDGE) {\n true -> PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))\n else -> PrintWriter(BufferedWriter(FileWriter(\"out.txt\")))\n}\n\nvar st = StringTokenizer(\"\")\n\nfun main(args: Array) {\n var start = System.currentTimeMillis()\n solve()\n pw.close()\n br.close()\n if(!ONLINE_JUDGE)\n System.err.println(\"${System.currentTimeMillis() - start} ms\")\n}", "lang_cluster": "Kotlin", "tags": ["two pointers", "brute force"], "code_uid": "b9ab1bd26c14553ddcb9ef4f83f462c6", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "/**\n * Created by enitihas on 20/6/17.\n */\nimport java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\n\n/**\n * Created by enitihas on 20/6/17.\n */\nfun main(args: Array) {\n val sc = Scanner(BufferedReader(InputStreamReader(System.`in`)))\n val pw = PrintWriter(System.out)\n solve(sc,pw)\n sc.close()\n pw.close()\n}\n\nfun solve(sc: Scanner, pw: PrintWriter) {\n val n = sc.nextInt()\n val x = sc.nextInt()\n var ans = -1\n val moves = n%6\n val balls = intArrayOf(0,0,0)\n balls[x] = 1\n for (i in moves downTo 1) {\n if(i%2==0) {\n val temp = balls[2]\n balls[2] = balls[1]\n balls[1] = temp\n }\n else {\n val temp = balls[1]\n balls[1] = balls[0]\n balls[0] = temp\n }\n }\n ans = balls.indexOf(1)\n println(ans)\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "implementation"], "code_uid": "2aa828f87b5be2eef09beef0c7802570", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0", "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\n\nfun main(args: Array) {\n val sc = FastScanner(System.`in`)\n\n val x = sc.nextLong()\n val y = sc.nextLong()\n\n println(solve(x, y))\n}\n\nval mod = (1e9 + 7).toLong()\n\nval res = mutableMapOf()\n\ndata class par(val t: Long)\n\nprivate fun solve(x: Long, y: Long): Long {\n if (y % x != 0L) return 0L\n if (y < x) return 0L\n\n val t = y / x\n if (res.containsKey(par(t))) return res[par(t)] ?: throw Exception()\n\n var sum = 2L pow (t - 1)\n\n if (x != y) sum = (sum - 1 + mod) % mod\n\n var i = 2L\n while (i * i <= t) {\n if (t % i == 0L) {\n sum = (sum - solve(i, t) + mod) % mod\n\n if (t / i != i) {\n sum = (sum - solve(t / i, t) + mod) % mod\n }\n }\n i += 1\n }\n\n res[par(t)] = sum\n return sum\n}\n\n\nprivate infix fun Long.pow(n: Long): Long {\n var a = this\n var n = n % (mod - 1)\n var res = 1L\n while (n > 0) {\n if (n % 2 == 1L) res = res * a % mod\n a = a * a % mod\n n /= 2\n }\n return res\n}\n\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["math", "dp", "combinatorics", "bitmasks", "number theory"], "code_uid": "27fc2b59db7ca5034b2c64a4df993264", "src_uid": "de7731ce03735b962ee033613192f7bc", "difficulty": 2000.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 = arrayListOf()\n for (i in 1..9) {\n a.add(sc.nextInt())\n }\n a[0] = (a[3] + 2 * a[5] - a[1]) / 2\n a[4] = a[2] - (a[3] - a[1]) / 2\n a[8] = (a[3] - a[1]) / 2 + a[1]\n var k = 0\n for (i in 1..3) {\n for (j in 1..3)\n print(a[k++].toString() + \" \")\n print(\"\\n\")\n }\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "00d271c36fd2b14e8883c4211784c235", "src_uid": "0c42eafb73d1e30f168958a06a0f9bca", "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\ndata class Player(val a: Int, val d: Int)\n\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val P = Array(4){Player(ni(), ni())}\n fun play(x1: Int) = run{\n (0 until 2).map { x2 ->\n val a1 = P[x1].a\n val d1 = P[1 xor x1].d\n val a2 = P[2 + x2].a\n val d2 = P[2 + (1 xor x2)].d\n\n if (a1 > d2 && d1 > a2) 0\n else if (a2 > d1 && d2 > a1) 2\n else 1\n }.max()!!\n }\n\n val res = min(play(0), play(1))\n val ans = when(res) {\n 0 -> \"Team 1\"\n 1 -> \"Draw\"\n 2 -> \"Team 2\"\n else -> \"\"\n }\n out.println(ans)\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl()\n }\n return res\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "0f356bf4babfa92c03a9d8b4f3d804f8", "src_uid": "1a70ed6f58028a7c7a86e73c28ff245f", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Integer.min\nimport kotlin.system.exitProcess\n\nfun readInts() = readLine()!!.split(' ').map(String::toInt)\n\nfun main(args: Array) {\n var n = readLine()!!.toInt()\n var sum = 0\n for(i in 2..(n - 1)){\n sum += i * (i + 1)\n }\n print(sum)\n}\n\n\n", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "dp"], "code_uid": "4e19495cba1186d3a5c2a210acbfe8aa", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a", "difficulty": 1200.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\n\nclass B {\n fun start(ins: Scanner) {\n val field = Array(3) { Array(3) { Array(3) { Array(3) { '.' } } } }\n ins.useDelimiter(\"[ \\t\\n\\\\r\\\\f]+\")\n for (i in 0..2) {\n for (j in 0..2) {\n for (k in 0..2) {\n val subField = ins.next()\n for (t in 0..2) {\n field[i][j][k][t] = subField[t]\n }\n }\n }\n }\n\n val x = ins.nextInt()\n val y = ins.nextInt()\n\n val sx = if (x % 3 == 0) 2 else (x - 1) % 3\n val sy = if (y % 3 == 0) 2 else (y - 1) % 3\n\n var isCan = false\n for (i in field[sx])\n for (j in i[sy].indices) {\n if (i[sy][j] == '.') {\n isCan = true\n i[sy][j] = '!'\n }\n }\n if (!isCan) {\n for (i in field) {\n for (j in i) {\n for (k in j) {\n for (t in k.indices) {\n if (k[t] == '.')\n k[t] = '!'\n }\n }\n }\n }\n }\n\n for (i in 0..2) {\n for (j in 0..2) {\n for (k in 0..2) {\n for (t in 0..2) {\n print(field[i][j][k][t])\n }\n print(' ')\n }\n print(\"\\n\")\n }\n print(\"\\n\")\n }\n }\n}\n\nfun main(args: Array) {\n B().start(Scanner(System.`in`))\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "2ed20ae2433c2bc8c29bf3af1abba635", "src_uid": "8f0fad22f629332868c39969492264d3", "difficulty": 1400.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 val mInv = mint(jin.nextInt()) pow -1\n val k = jin.nextInt()\n val dp = Array(k + 1) { LongArray(it + 2) }\n dp[0][0] = 1L\n for (x in 1..k) {\n for (y in 1..x) {\n dp[x][y] = ((n - y + 1).toLong() * dp[x - 1][y - 1]) + (y.toLong() * dp[x - 1][y])\n dp[x][y] %= MOD\n }\n }\n var answer = M0\n var power = M1\n for (y in 1..k) {\n power *= mInv\n answer += mint(dp[k][y] + MOD) * power\n }\n println(answer)\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", "dp", "combinatorics", "probabilities", "number theory"], "code_uid": "1004a33de976974c90b5fed8d7b555b0", "src_uid": "e6b3e559b5fd4e05adf9f1cd1b22126b", "difficulty": 2600.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.next().toInt()\n var s = scanner.next().toString()\n var digit: Int = 0\n s.forEach {\n when(it) {\n '1' -> digit++\n '0' -> {\n print(digit)\n digit = 0\n }\n }\n }\n print(digit)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "f28958ae5f43b696383f65251d048f9a", "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa", "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\n var quantityOfCubes = input.nextInt()\n var countCubes: Int = 0\n var n: Int = 0\n\n while (quantityOfCubes >= countCubes + Factorial(n + 1)) {\n n++\n countCubes += Factorial(n)\n }\n\n println(n)\n}\n\nfun Factorial(n: Int) : Int {\n var result: Int = 0\n\n for (i in 1..n) {\n result += i\n }\n\n return result\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8b39eb05ebc5a4ad37539d3803c0218a", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0", "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\nval inf = BufferedReader(InputStreamReader(System.`in`))\nval ouf = PrintWriter(System.out)\n\nfun main(args: Array) {\n val (n, m) = inf.readLine()!!.split(' ').map(String::toInt)\n val a = LongArray(m)\n for (q in 0 until m) {\n a[(q * q) % m] += (n / m + (if (q > 0 && q <= n % m) 1 else 0)).toLong()\n }\n var ans = 0L\n for (i in 0 until m) {\n for (j in 0 until m) {\n if ((i + j) % m == 0) ans += a[i] * a[j]\n }\n }\n ouf.println(ans)\n ouf.close()\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "3e1d1e33c331d00e28373929abb78ed0", "src_uid": "2ec9e7cddc634d7830575e14363a4657", "difficulty": 1600.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 (n1, n2, k1, k2) = IO.readFourInts()\n val dp = DP(n1, n2, k1,k2)\n IO.write(dp.dp(1, 0, 0, 0 ))\n\n IO.flushOutput()\n IO.closeOutput()\n}\n\nclass DP(val n1 : Int, val n2 : Int, val k1 : Int,val k2 : Int){\n\n\n val map = Array(201) { Array(101) { Array(11) { IntArray(11) { -1 } } } }\n val mod = 100000000\n\n fun dp(pos : Int, horses : Int, lastHorses : Int, lastMen : Int) : Int {\n //dp[pos][horses already placed][last placed horsed][last placed men] 200*100*10*10 ~ 2 million states , should be okay\n //possible optimisation if we get TLE dp[pos][horses already placed][last placed whom ?][quantity] 200*100*2*10 ~ 0.4 million states\n\n if (pos == n1 + n2 + 1) return 1\n\n if (map[pos][horses][lastHorses][lastMen] != -1) return map[pos][horses][lastHorses][lastMen]\n val horsesRemaingToBePlaced = n2 - horses\n val footMenRemainingToBePlaced = n1 - (pos - 1 - horses)\n\n var ways= 0\n\n if (horsesRemaingToBePlaced != 0 && lastHorses < k2){\n //horse can be placed\n ways+= dp(pos + 1, horses + 1, lastHorses + 1, 0 )\n }\n if (footMenRemainingToBePlaced != 0 && lastMen < k1){\n ways= (ways + dp(pos + 1, horses, 0, lastMen + 1))%mod\n }\n\n map[pos][horses][lastHorses][lastMen] = ways\n return ways\n }\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": ["dp"], "code_uid": "af7c0cb4f7470456c10d62af46d2eee4", "src_uid": "63aabef26fe008e4c6fc9336eb038289", "difficulty": 1700.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.lang.Integer.min\nimport kotlin.math.abs\nimport kotlin.math.roundToInt\nimport kotlin.math.sqrt\n\nfun main(args: Array) {\n// var str = readLine()!!\n var n = readLine()!!.toInt()\n// var ball = readLine()!!.split(\" \").map { x -> x.toInt() }\n var result = 0\n when (n) {\n 1 -> result = 2\n 2 -> result = 3\n 3 -> result = 4\n 4 -> result = 4\n 5 -> result = 5\n 6 -> result = 5\n else -> result = finds(n)\n }\n\n println(result)\n}\n\nfun finds(n: Int) : Int {\n var i = sqrt(n.toDouble()).roundToInt()\n while (true) {\n if (i*i >= n) return i*2\n else\n if (i*i+i >= n) return i*2+1\n i++\n }\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "binary search"], "code_uid": "84dee7f5e2a7426d5ebaee5de05a21bc", "src_uid": "eb8212aec951f8f69b084446da73eaf7", "difficulty": 1100.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\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 val m = scan.int()\n val (min, max) = min(n,m) to max(n,m)\n val sum = if (max > min*2) min*3 else min+max\n exit(sum/3)\n}\n\n ", "lang_cluster": "Kotlin", "tags": ["math", "greedy", "implementation", "number theory"], "code_uid": "bd2dff95b3991caac2521d99f5f192b8", "src_uid": "0718c6afe52cd232a5e942052527f31b", "difficulty": 1300.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "const val MOD = 1000000007L\n\nfun main() {\n val n = readLine()!!.toInt()\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 val factInv = LongArray(n + 1) { factorial[it] pow -1 }\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 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 *= arrange(1 shl e, 3) pow -1\n curr %= MOD\n curr *= arrange(3 * (1 shl (e - 1)), 2)\n curr %= MOD\n curr *= arrange(1 shl (e - 1), 2) pow -1\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": "77050f7e360b8f72b7195a2c670de016", "src_uid": "b2d59b1279d891dba9372a52364bced2", "difficulty": 2500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nval days = listOf(\"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\")\nval variations = listOf(0, 2, 3)\n\nval sequences = variations.flatMap { indexChange -> days.mapIndexed { i, d -> Pair(d, days[(days.size + i + indexChange) % days.size]) } }\n\nfun main(args: Array) {\n val br = BufferedReader(InputStreamReader(System.`in`))\n\n val findSequence = Pair(br.readLine(), br.readLine())\n\n println(if (sequences.contains(findSequence)) \"YES\" else \"NO\")\n}\n", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "89087b9a1086d0bbcdf61f20d50bb067", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35", "difficulty": 1000.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 val first: Int = (c / a) + 1\n val second: Int = (c / b) + 1\n\n for (i in 0 until first) {\n for (j in 0 until second) {\n if (a * i + b * j == c) {\n pw.print(\"Yes\")\n return\n }\n }\n }\n\n pw.print(\"No\")\n\n}\n\n\n\nprivate fun sort(array: IntArray, barray: IntArray, low: Int, high: Int) {\n\n var i = low\n var j = high\n val x = array[low + (high - low) / 2]\n\n do {\n while (array[i] < x) ++i\n while (array[j] > x) --j\n if (i <= j) {\n val tmp = array[i]\n array[i] = array[j]\n array[j] = tmp\n\n val pmt = barray[i]\n barray[i] = barray[j]\n barray[j] = pmt\n\n i++\n j--\n }\n } while (i <= j)\n\n if (low < j) sort(array, barray, low, j)\n if (i < high) sort(array, barray, i, high)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math", "number theory"], "code_uid": "cc0e8c8afa166f3ed7a11cff3c63afff", "src_uid": "e66ecb0021a34042885442b336f3d911", "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\n var x = scanner.nextLong()\n var y = scanner.nextLong()\n val m = scanner.nextLong()\n\n if (checkExcellent(x, y, m)) {\n System.out.println(0)\n return\n }\n\n if (x <= 0 && y <= 0) {\n// if (checkExcellent(x, y, m)) {\n// System.out.println(0)\n// } else {\n System.out.println(-1)\n// }\n return\n }\n\n if (x < y) {\n val temp = x\n x = y\n y = temp\n }\n\n var ans: Long = 0\n\n //System.out.println(\"$x $y\")\n\n if (y < 0) {\n val tmp = x - y\n ans += tmp / x\n y += ans * x\n }\n\n if (checkExcellent(x, y, m)) {\n System.out.println(ans)\n return\n }\n\n while (true) {\n if (x < y) {\n x += y\n ans++\n if (checkExcellent(x, y, m)) {\n System.out.println(ans)\n return\n }\n } else {\n y += x\n ans++\n if (checkExcellent(x, y, m)) {\n System.out.println(ans)\n return\n }\n }\n }\n\n\n}\n\nfun checkExcellent(x: Long, y: Long, m: Long): Boolean {\n return Math.max(x, y) >= m\n}\n\n\nenum class Type {\n OPEN, CLOSE\n}", "lang_cluster": "Kotlin", "tags": ["math", "greedy"], "code_uid": "da96d435a2c2fb76c024901490fd295d", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "\n\nimport java.util.*\n\nfun main() {\n var w: Int\n var h: Int\n\n with(Scanner(System.`in`)) {\n w = nextInt()\n h = nextInt()\n }\n\n var count = 0L\n\n for (i in w / 2 downTo 1 step 1) {\n for (j in h / 2 downTo 1 step 1) {\n count += (w - i * 2 + 1) * (h - j * 2 +1)\n }\n }\n print(count)\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "math"], "code_uid": "27561c37df7b3810992b338662758d8b", "src_uid": "42454dcf7d073bf12030367eb094eb8c", "difficulty": 1300.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.nextInt()\n var a = sc.nextInt()\n val arr= IntArray(n+1)\n for (i in 1 ..n )arr[i]=sc.nextInt()\n\n var count =0\n for ( i in 1 ..n){\n if(arr[i] == 1 ){\n if (!(2*a-i >= 1 && 2*a-i <= n && arr[2*a-i] == 0)) {\n count++\n }\n }\n }\n\n println(count)\n}", "lang_cluster": "Kotlin", "tags": ["constructive algorithms", "implementation"], "code_uid": "e573adb77d4f63da2c8c3e8ac496e5af", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n val (h, m) = readLn().split(':').map { it.toInt() }\n val a = readInt()\n\n val t = h * 60 + m + a\n\n val h1 = t / 60 % 24\n val m1 = t % 60\n\n val ans = \"%02d:%02d\".format(h1, m1)\n\n println(ans)\n}\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readStringSeq() = readLn().splitToSequence(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readIntSeq() = readStringSeq().map { it.toInt() }\nfun readIntArray(size: Int) = readIntSeq().iterator().let { i -> IntArray(size) { i.next() } }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readDoubleSeq() = readStringSeq().map { it.toDouble() }\nfun readDoubleArray(size: Int) = readDoubleSeq().iterator().let { i -> DoubleArray(size) { i.next() } }\nfun readLongs() = readStrings().map { it.toLong() }\nfun readLongSeq() = readStringSeq().map { it.toLong() }\nfun readLongArray(size: Int) = readLongSeq().iterator().let { i -> LongArray(size) { i.next() } }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit) { Output().apply(block).nowPrint() }", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "8f59939f4bbacea87fae9adcf003622b", "src_uid": "20c2d9da12d6b88f300977d74287a15d", "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()\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 = n / 2 + 1\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": ["math"], "code_uid": "1e361ec22e46a0076ba8cb8e1efef7e1", "src_uid": "5551742f6ab39fdac3930d866f439e3e", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n var (n, m) = readLine()!!.split(' ').take(3).map { it.toInt() }\n var sequence = readLine()!!.split(' ').take(n).map { it.toInt() }.toIntArray()\n var fingerPrints = readLine()!!.split(' ').take(m).map { it.toInt() }.toIntArray()\n for (i in sequence)\n if (fingerPrints.contains(i))\n print(\"$i \")\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "d006689a865c5736b3977b18340761a0", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72", "difficulty": 800.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 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 val (x, y) = readLongs()\n val arr = listOf(x, y, (y - x) % 1000000007L, -x, -y, (x - y) % 1000000007L)\n val n = readInt()\n val ans = ((if (n % 6 == 0) arr[5] else arr[(n % 6) - 1]) + 1000000007L)\n println(ans % 1000000007L)\n\n}\n\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "91a91fe80026d9cc1daf5659a611954d", "src_uid": "2ff85140e3f19c90e587ce459d64338b", "difficulty": 1300.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_007L\n\ntailrec fun gcd(a: Long, b: Long): Long {\n if (a < b) return gcd(b, a)\n if (b == 0L) return a\n return gcd(b, a % b)\n}\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val T = nl()\n val A = nl()\n val B = nl()\n\n fun answer(x: Long) {\n val d = gcd(x - 1, T)\n out.println(\"${(x - 1)/d}/${T/d}\")\n }\n\n if (A == B) {\n answer(T + 1)\n return\n }\n\n val a = A / gcd(A, B)\n if (a > T / B) {\n answer(min(T + 1, min(A, B)))\n return\n }\n val lcm = a * B\n val size = (T + 1)/ lcm\n val r = (T + 1) % lcm\n debug{\"$lcm $size $r\"}\n\n var ans = 0L\n ans += min(A, B) * size\n if (r != 0L) ans += min(r, min(A, B))\n debug{\"$ans\"}\n answer(ans)\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl() + offset\n }\n return res\n }\n\n private fun na2(n: Int, offset: Int = 0): Array {\n val a = Array(2){IntArray(n)}\n for (i in 0 until n) {\n for (e in a) {\n e[i] = ni() + offset\n }\n }\n return a\n }\n\n private inline fun map(n: Int, f: (Int) -> Int): IntArray {\n val res = IntArray(n)\n for (i in 0 until n) {\n res[i] = f(i)\n }\n return res\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n private inline fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private inline fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private inline fun debug(a: BooleanArray) {\n debug { a.map { if (it) 1 else 0 }.joinToString(\"\") }\n }\n\n private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手にimport消されるのを防ぎたい\n */\n private fun hoge() {\n min(1, 2)\n max(1, 2)\n abs(-10)\n }\n\n private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()}\n}\n\nfun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "4201729be0458e4f7d22acca08e2121a", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5", "difficulty": 1800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(args : Array) = with(java.util.Scanner(System.`in`)){\n var n = nextInt()\n var c : Int = 0\n var bi : Int = 0\n var b : Int = 0\n for(i in 0..n-1){\n var tmp = nextInt()\n if(i%3 ==0) c+=tmp\n else if(i%3 == 1) bi+=tmp\n else b+=tmp\n }\n var res = if(c> bi && c>b)\n \"chest\"\n else if(bi>c && bi>b)\n \"biceps\"\n else \"back\"\n println(res)\n}", "lang_cluster": "Kotlin", "tags": ["implementation"], "code_uid": "59fb28650fc9a957356af8136f0d9006", "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 (numSongs, duration) = readInts()\n val songsDurations = readInts().sum()\n print(if ((numSongs - 1) * 10 + songsDurations > duration) -1 else (duration - songsDurations) / 5)\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "2c7c0e59a8710940fc6071e7f146f227", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea", "difficulty": 900.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.math.MathContext\nimport java.util.Scanner\n\nfun main(args: Array) {\n val scan = Scanner(System.`in`)\n val a = scan.nextInt()\n val b = scan.nextInt()\n if (a==b || (a==2 && b==4) || (a==4 && b==2)) print (\"=\")\n else if (a==3) print (\">\")\n else if (b==3) print (\"<\")\n else if (a==1) print (\"<\")\n else if (b==1) print (\">\")\n else if (a>b) print (\"<\")\n else print (\">\")\n}", "lang_cluster": "Kotlin", "tags": ["math"], "code_uid": "1af138b7bce73ba7dd49f234f3febbb9", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\nimport java.util.Collections.min\nimport kotlin.math.min\n\nfun main() {\n val r = FastReader()\n val n = r.nextInt()\n print(solve(n))\n\n}\n\nfun isp(m:Int): Int {\n var i : Int= 2\n while(i * i <= m){\n if(m % i == 0){\n return 0\n }\n i ++\n }\n return 1\n}\n\nfun solve(n:Int):Int{\n var k = isp(n)\n if(k == 1) return k\n if(n%2 == 0) return 2\n if(isp(n-2) == 1) return 2\n return 3\n}\n@Suppress(\"MemberVisibilityCanBePrivate\")\ninternal class FastReader {\n private val br = BufferedReader(InputStreamReader(System.`in`))\n private var tokenizer: StringTokenizer? = null\n\n operator fun next(): String {\n var t = tokenizer\n while (t == null || !t.hasMoreElements())\n t = StringTokenizer(br.readLine())\n tokenizer = t\n return t.nextToken()\n }\n\n fun nextInt():Int= next().toInt()\n\n fun nextLong(): Long = next().toLong()\n\n fun nextDouble(): Double = next().toDouble()\n\n fun nextLine(): String = br.readLine()\n\n fun nextIntArr(n: Int): IntArray = IntArray(n) { nextInt() }\n\n fun nextDoubleArr(n: Int): DoubleArray = DoubleArray(n) { nextDouble() }\n\n fun nextLongArr(n: Int): LongArray = LongArray(n) { nextLong() }\n\n fun nextIntArr2(n: Int, m: Int): Array = Array(n) { IntArray(m) { nextInt() } }\n\n fun nextLongArr2(n: Int, m: Int): Array = Array(n) { LongArray(m) { nextLong() } }\n}", "lang_cluster": "Kotlin", "tags": ["math", "number theory"], "code_uid": "1bf8106f22be8988ac582436c7dc5801", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import 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 lights = scanner.nextLine().toCharArray().toList().map(Char::toString)\n val fours = lights.batch(4)\n val rIndex = findIndex(fours, \"R\")\n val bIndex = findIndex(fours, \"B\")\n val yIndex = findIndex(fours, \"Y\")\n val gIndex = findIndex(fours, \"G\")\n val pattern = mutableListOf(\"\", \"\", \"\", \"\")\n pattern[rIndex] = \"R\"\n pattern[bIndex] = \"B\"\n pattern[yIndex] = \"Y\"\n pattern[gIndex] = \"G\"\n val result = mutableMapOf(\"R\" to 0, \"B\" to 0, \"Y\" to 0, \"G\" to 0)\n fours.forEach {\n val diff = pattern.take(it.size) - it\n for (s in diff) {\n val count = result.getOrElse(s, { 0 })\n result[s] = count.inc()\n }\n }\n out.println(\"${result[\"R\"]} ${result[\"B\"]} ${result[\"Y\"]} ${result[\"G\"]}\")\n}\n\nprivate fun findIndex(fours: Sequence>, s: String): Int {\n return fours.find { it.contains(s) }?.indexOf(s) ?: -1\n}\n\nprivate class BatchingSequence(val source: Iterable, val batchSize: Int) : Sequence> {\n override fun iterator(): Iterator> = object : AbstractIterator>() {\n private val iterate = if (batchSize > 0) source.iterator() else emptyList().iterator()\n override fun computeNext() {\n if (iterate.hasNext()) setNext(iterate.asSequence().take(batchSize).toList())\n else done()\n }\n }\n}\n\n/**\n * Batch a sequence into a sequence of lists of max N size\n */\nfun Iterable.batch(n: Int): Sequence> {\n return BatchingSequence(this, n)\n}\n", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "number theory"], "code_uid": "cbff6896711ce2f6503b76c34508d956", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33", "difficulty": 1100.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.*\nimport java.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 INF=1000000000\n \nfun QPowMod(x:Long, y:Long, mod:Long):Long {\n\tvar res =1L\n\tvar a=x\n\tvar b=y\n\twhile(b>0) {\n\t\tif(b%2==1L) {\n\t\t\tres=res*a%mod\n\t\t}\n\t\ta=a*a%mod\n\t\tb/=2\n\t}\n\treturn res\n}\n \nfun RevMod(x:Long, mod:Long) = QPowMod(x,mod-2, mod)\n \n \n \nfun main(args: Array) {\n\tvar (n,m) = readInts()\n\tvar fact = LongArray(n+1)\n\tfact[0]=1\n\tfor(i in 1..n)\n\t\tfact[i]=fact[i-1]*i%m\n\t\n\tvar res = 0L\n\tfor(i in 1..n) {\n\t\tres+=(n.toLong()-i+1)*(n.toLong()-i+1)%m*fact[i]%m*fact[n-i]%m\n\t\tres%=m\n\t}\n\tprintln(res)\n}", "lang_cluster": "Kotlin", "tags": ["math", "combinatorics"], "code_uid": "93aab03ac689848624f978839aee6093", "src_uid": "020d5dae7157d937c3f58554c9b155f9", "difficulty": 1600.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main(vararg args: String) {\n val n = readLine()!!.toInt()\n println(if (n == 0) 1 else arrayOf(6, 8, 4, 2)[n % 4])\n}\n", "lang_cluster": "Kotlin", "tags": ["math", "implementation", "number theory"], "code_uid": "698ae5ab76e80b1da00e127ce29cc075", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import kotlin.math.max\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val numStudents = readInt()\n val votesAgaints = readInts()\n val totalVotesAgaints = votesAgaints.sum()\n var necessary = totalVotesAgaints + totalVotesAgaints + 1\n print(\n max(\n votesAgaints.max()!!,\n if (necessary % numStudents == 0) necessary / numStudents else necessary / numStudents + 1\n )\n )\n}", "lang_cluster": "Kotlin", "tags": ["math", "implementation"], "code_uid": "178a74259493590a6818e8ac39cdf3f2", "src_uid": "d215b3541d6d728ad01b166aae64faa2", "difficulty": 800.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.util.Scanner;\n\nval intReader = Scanner(System.`in`);\nvar valid:Boolean = false;\n\nfun solve(x:Int){\n\tif (x == 0) valid = true;\n\telse{\n\t\tif (x-3>=0) solve(x-3);\n\t\tif (x-7>=0) solve(x-7);\n\t}\n}\n\nfun main(){\n\tvar tc = intReader.nextInt();\n\twhile (tc > 0){\n\t\tvar x = intReader.nextInt();\n\t\tvalid = false;\n\t\tsolve(x);\n\t\tif (valid) print(\"YES\\n\");\n\t\telse print(\"NO\\n\");\n\t\ttc--;\n\t}\n\n\t\n}", "lang_cluster": "Kotlin", "tags": ["greedy", "implementation"], "code_uid": "1dc097b0453034ba90b815ba4df1afae", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452", "difficulty": 900.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 if(u < n) 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 雪花飄飄北風嘯嘯天地一片蒼茫() { 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": "579f5e902191216b6501e3fc2d7196b4", "src_uid": "ad014bde729222db14f38caa521e4167", "difficulty": 2600.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 = ni()\n val B = ni()\n if (B > A) {\n out.println(0)\n return\n }\n\n if (A == B) {\n out.println(\"infinity\")\n return\n }\n\n val mx = (A - B)\n var x = 1\n var ans = 0\n while(x * x <= mx) {\n if (mx % x == 0) {\n if (A % x == B) ans++\n if (x * x != mx && A % (mx / x) == B) ans++\n }\n x++\n }\n out.println(ans)\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return map(n, 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 * 勝手にimport消されるのを防ぎたい\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", "number theory"], "code_uid": "4d4b254c328697ec4ef04736233b45f9", "src_uid": "6e0715f9239787e085b294139abb2475", "difficulty": 1600.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 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 = 1//readInt()\n\n case@ for(case in 1..numCases) {\n // print(\"Case #$case: \")\n\n val n = readInt()\n val D = ModIntArray(n+1)\n for(i in 1..n) {\n var j = i\n while(j <= n) {\n D[j]++\n j += i\n }\n }\n\n var sum = ModInt(0)\n for(i in 1..n) {\n D[i] += sum\n sum += D[i]\n }\n\n val ans = D[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 = 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 雪花飄飄北風嘯嘯天地一片蒼茫() { 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": "2795dcc1d8e0388ff09c5906c2797e90", "src_uid": "09be46206a151c237dc9912df7e0f057", "difficulty": 1700.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 n = scanner.nextInt()\n if(ok(n)) print(\"YES\")\n else print(\"NO\")\n\n}\n\nfun ok(x: Int): Boolean{\n var a = 1\n var i = 1\n while(a < x){\n if(isTri(x-a)) return true\n ++i\n a += i\n }\n return false\n}\n\nfun isTri(a: Int): Boolean{\n val base = (Math.sqrt(8.0 * a + 1) - 1)/2\n return (Math.ceil(base) == Math.floor(base))\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation", "binary search"], "code_uid": "b4334f8660e18e69f4d7f92db22082cd", "src_uid": "245ec0831cd817714a4e5c531bffd099", "difficulty": 1300.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()\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(n)\n var l = 0\n while (l < n && a[l] == 0) {\n l++\n }\n if (l == n) {\n writer.println(n)\n return\n }\n\n var r = n - 1\n while (r >= l && a[r] == 1) {\n r--\n }\n\n if (r < l) {\n writer.println(n)\n return\n }\n\n val count0 = a.filterIndexed { index, value -> index in l..r && value == 0 }.count()\n var ans = n - min(r - l + 1 - count0, count0)\n for (i in 0 until n) {\n val x0 = a.filterIndexed { index, value -> index in 0..i && value == 0 }.count()\n val x1 = a.filterIndexed { index, value -> index in i+1 until n && value == 1 }.count()\n ans = max(ans, x0 + x1)\n }\n writer.println(ans)\n}\n\n/*\n\n6\n0 1 0 0 0 1\n\n100\n1 1 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 1 1 1 0 0 1 1 0 0 0 0 1\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": ["brute force", "implementation"], "code_uid": "e7928b68089a578ed18c580bcba0d649", "src_uid": "c7b1f0b40e310f99936d1c33e4816b95", "difficulty": 1500.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "fun main() {\n readLine()\n print(readLine()!!.split(\" \").mapIndexed { floor, habitants -> habitants.toInt() * 4 * floor }.sum())\n}", "lang_cluster": "Kotlin", "tags": ["brute force", "implementation"], "code_uid": "0130435d21b3bfd6056b899943b6c664", "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f", "difficulty": 1000.0, "exec_outcome": "PASSED"} {"lang": "Kotlin", "source_code": "import java.io.FileInputStream\n\n\nval MOD : Long = 1000000007L\nconst val mod : Int = (1e9 + 7).toInt();\n\n\nfun main(args: Array) {\n// System.setIn(FileInputStream(\"./B/input3\"));\n\n val (nRow, nCol, k) = readLine()!!.split(' ').map(String::toLong)\n\n if (k == -1L) {\n if ((nRow + nCol) % 2 == 1L) {\n println(0)\n return\n }\n }\n\n if (nRow < 2 || nCol < 2) {\n println(1)\n return\n }\n\n val dofRow = (nRow - 1)\n val dofCol = (nCol - 1)\n\n val x1 = qpow(2, dofCol)\n val x2 = qpow(x1, dofRow)\n// val x1 = powmod(2, dofCol)\n// val x2 = powmod(x1, dofRow)\n println(x2)\n}\n\nfun qpow(x: Long, exp: Long) : Long {\n var exp_ = exp % (MOD - 1)\n var res : Long = 1L\n var mult = x\n while (exp_ > 0) {\n if (exp_ % 2 == 1L) {\n res = (res * mult) % MOD\n }\n mult = (mult * mult) % MOD\n exp_ /= 2\n }\n return res % MOD\n}\n\n\nfun powmod(x: Long, y: Long) : Long {\n var ret = 1L;\n var y_ = y % (mod - 1)\n var x_ = x\n while( y_ > 0){\n if(1 == (y_ % 2).toInt()) {\n ret = (ret * x_) % mod\n }\n y_ /= 2\n x_ = (x_ * x_) % mod;\n }\n return ret;\n}", "lang_cluster": "Kotlin", "tags": ["math", "constructive algorithms", "combinatorics", "number theory"], "code_uid": "c713145d60ae923a6e1508c3e660b62d", "src_uid": "6b9eff690fae14725885cbc891ff7243", "difficulty": 1800.0, "exec_outcome": "PASSED"}