{"source_code": "import kotlin.system.exitProcess\n\n/** Codeforces contest\n * Kotlin compiler\n * @author MrFoxyGmFr\n */\n/*const val debug = false*/\nval scan = java.util.Scanner(/*if (debug) java.io.FileInputStream(\"input.txt\") else*/ System.`in`)\n/**--- CONST ---**/\nconst val MAXN = 150\n\nfun main(args: Array) {\n val n = scan.nextInt()\n val k = scan.nextInt()\n val a = IntArray(MAXN, { 0 })\n\n for (i in 1..n)\n a[scan.nextInt()]++\n\n var max = 0\n var types = 0\n for (i in 1..100)\n if (a[i] != 0) {\n if (a[i] > max)\n max = a[i]\n types ++\n }\n\n if (max % k != 0)\n max += k - max % k\n\n print(max * types - n)\n}\n\n/*\nfun debug(vararg info: Any) { if (debug) { print(\"DEBUG:\"); info.forEach { print(\" $it\") }; println() } }\nfun exit(vararg info: Any, sep: String = \" \") { info.forEach { print(\"$it$sep\") }; exitProcess(0) }*/\n", "src_uid": "c03ff0bc6a8c4ce5372194e8ea18527f"} {"source_code": "import java.util.*\n\nclass Main {\n}\n\nfun main() {\n var sc = Scanner (System.`in`)\n var n = sc.nextInt()\n var vis = BooleanArray(1050)\n var data = IntArray (n)\n for (i in 0..n-1) {\n data[i] = sc.nextInt()\n }\n var i = n\n var k = 0\n while (--i >= 0) {\n if (!vis[data[i]]) {\n vis[data[i]] = true\n k++\n } else {\n data[i] = -1\n\n }\n }\n println(k)\n for (i in data) {\n if (i != -1) {\n print (i.toString() + \" \")\n }\n }\n}\nclass D {\n\n}", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a"} {"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}", "src_uid": "0c42eafb73d1e30f168958a06a0f9bca"} {"source_code": "fun main() {\n val password = readLine()!!\n val binaryToDecimal = mutableMapOf()\n for (char in '0'..'9')\n binaryToDecimal[readLine()!!] = char\n val sol = StringBuilder()\n for (start in 0..70 step 10)\n sol.append(binaryToDecimal[password.substring(start..start + 9)]!!)\n print(sol.toString())\n}", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9"} {"source_code": "import java.io.PrintWriter\nimport java.util.*\n\nval sc = Scanner(System.`in`)\nval pw = PrintWriter(System.out)\n\ntailrec fun check(a: List, i: Int = 2): Boolean =\n when {\n i >= a.size -> true\n a[i] >= a[i - 1] + a[i - 2] -> false\n else -> check(a, i + 1)\n }\n\nfun swap(list: List, ind1: Int, ind2: Int): List {\n val newList = list as MutableList\n val tmp = list[ind1]\n newList[ind1] = list[ind2]\n newList[ind2] = tmp\n return newList\n}\n\nfun sort(a: List): List {\n if (a.size <= 1) return a\n val x = a.first()\n val (left, right) = a.filter { it < x } to a.filter { it > x }\n return sort(left) + listOf(x) + sort(right)\n}\n\nfun divUp(a: Long, b: Long) = (a + b - 1) / b;\nfun main() {\n val n = sc.nextLong()\n val m = sc.nextLong()\n val a = sc.nextLong()\n println(divUp(n, a) * divUp(m, a))\n}\n", "src_uid": "ef971874d8c4da37581336284b688517"} {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\n\nfun PrintWriter.solve(sc: FastScanner) {\n val n = sc.nextInt()\n val p = Array(n) { sc.nextInt() }\n var even = n / 2\n var odd = (n + 1) / 2\n for (i in 0 until n) {\n if (p[i] != 0) {\n if (p[i] % 2 == 0) even--\n else odd--\n }\n }\n var ans = 0\n val ee = mutableListOf()\n val eo = mutableListOf()\n val oo = mutableListOf()\n val e = mutableListOf()\n val o = mutableListOf()\n var streak = 0\n for (i in 0 until n) {\n if (p[i] == 0) streak++\n else {\n if (streak == i) {\n if (p[i] % 2 == 0) e.add(streak)\n else o.add(streak)\n } else {\n val j = i - streak - 1\n if (p[i] % 2 == 0 && p[j] % 2 == 0) ee.add(streak)\n else if (p[i] % 2 == 1 && p[j] % 2 == 1) oo.add(streak)\n else eo.add(streak)\n }\n streak = 0\n }\n }\n if (streak == n) {\n println(if (n == 1) 0 else 1)\n return\n }\n if (streak > 0) {\n val j = n - streak - 1\n if (p[j] % 2 == 0) e.add(streak)\n else o.add(streak)\n }\n ee.sort()\n oo.sort()\n e.sort()\n o.sort()\n for (s in ee) {\n val num = minOf(s, even)\n if (s > even) {\n ans += 2\n } else {\n even -= num\n odd -= s - num\n }\n }\n for (s in oo) {\n val num = minOf(s, odd)\n if (s > odd) {\n ans += 2\n } else {\n odd -= num\n even -= s - num\n }\n }\n for (s in e) {\n val num = minOf(s, even)\n if (s > even) {\n ans++\n } else {\n even -= num\n odd -= s - num\n }\n }\n for (s in o) {\n val num = minOf(s, odd)\n if (s > odd) {\n ans++\n } else {\n odd -= num\n even -= s - num\n }\n }\n ans += eo.count()\n println(ans)\n}\n\nfun main() {\n val writer = PrintWriter(System.out, false)\n writer.solve(FastScanner(System.`in`))\n writer.flush()\n}\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}\n", "src_uid": "90db6b6548512acfc3da162144169dba"} {"source_code": "fun main(){\n val s=readLine()!!\n var has = false\n var res=s.length\n for(i in 1..s.length-1){\n if(s[i]=='1')\n has=true\n }\n if(has)res++\n res/=2\n println(res)\n}", "src_uid": "d8ca1c83b431466eff6054d3b422ab47"} {"source_code": "import kotlin.math.*\n\nfun main() {\n val (n, b) = readLine()!!.split(' ').map { it.toLong() }\n var ans = Long.MAX_VALUE\n factor(b) { p, k ->\n ans = min(ans, pp(n, p) / k)\n }\n println(ans)\n}\n\nfun factor(x: Long, op: (p: Long, k: Int) -> Unit) {\n var rem = x\n var p = 2L\n while (p * p <= rem) {\n var k = 0\n while (rem % p == 0L) {\n rem /= p\n k++\n }\n if (k > 0) op(p, k)\n p++\n }\n if (rem > 1) op(rem, 1)\n}\n\nfun pp(n: Long, p: Long): Long {\n var ans = 0L\n var cur = p\n while (cur <= n) {\n ans += n / cur\n if (cur > (n + p - 1) / p) break\n cur *= p\n }\n return ans\n}", "src_uid": "491748694c1a53771be69c212a5e0e25"} {"source_code": "\nimport java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)){\n val n = nextLong()\n var i = 1\n var lucky = 4L\n while (true) {\n if(n == lucky){\n break\n }\n lucky = increaseLuckyNumber(lucky)\n //println(\"step: $i, increased: $lucky\")\n i++\n }\n println(i)\n}\n\nfun increaseLuckyNumber(luck: Long): Long{\n var chars = luck.toString().toCharArray()\n var i = chars.size - 1 \n while (true){\n val curr = chars[i]\n \n if (curr == '4'){\n chars[i] = '7'\n break\n }\n chars[i] = '4'\n if (i == 0){\n var newStr = String(chars)\n newStr = \"4$newStr\"\n //val newChars = CharArray(chars.size + 1)\n //newChars[0] = '4'\n //newChars.addAll(chars, chars.toCharArray())\n //chars = newChars\n chars = newStr.toCharArray()\n break\n }\n i--\n }\n return String(chars).toLong()\n}", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3"} {"source_code": "import java.util.*\nimport kotlin.system.exitProcess\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n var a = sc.nextInt()\n var b = sc.nextInt()\n var c = sc.nextInt()\n for(i in 1..100000) {\n a *= 10\n if(c == (a / b) % 10) {\n println(i)\n exitProcess(0)\n }\n a %= b\n }\n println(-1)\n}\n\n\n\n\n", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910"} {"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", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4"} {"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}", "src_uid": "d04fa4322a1b300bdf4a56f09681b17f"} {"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}", "src_uid": "f54cc281033591315b037a400044f1cb"} {"source_code": "import java.util.Scanner\nimport kotlin.math.max\n\nfun main() {\n var (ac, bc) = readLine()!!.split(' ').map(String:: toLong)\n var (y, g, b) = readLine()!!.split(' ').map(String:: toLong)\n\n var ans : Long = max(0, 2*y-ac)\n ac = max(0, ac-2*y)\n\n ans += max(0, g-ac)\n ans += max(0, g-bc)\n bc = max(0, bc-g)\n\n ans += max(0, 3*b-bc)\n println(ans)\n}", "src_uid": "35202a4601a03d25e18dda1539c5beba"} {"source_code": "import java.util.Scanner\r\n\r\nfun main() {\r\n val input = Scanner(System.`in`)\r\n val n = input.nextLong()\r\n val m = input.nextLong()\r\n val a: Long = 1\r\n\r\n if (m == a && n > a) {\r\n println(n - a)\r\n } else if (n == a && m > a) {\r\n println(m - a)\r\n } else {\r\n println(((m - a) * n))\r\n }\r\n}", "src_uid": "a91aab4c0618d036c81022232814ef44"} {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.StringTokenizer\n\nfun main(args: Array) {\n val sc = FastScanner(System.`in`)\n val n = sc.nextInt()\n var k = sc.nextInt()\n\n val s = sc.next()\n \n if(n == 1 && k>=1) {\n println(\"0\")\n return\n }\n\n println(\n buildString {\n for (x in s.withIndex()) {\n if (k > 0) {\n if (x.index == 0) {\n append(1)\n if (x.value != '1') k--\n } else {\n append(0)\n if (x.value != '0') k--\n }\n } else append(s[x.index])\n }\n }\n )\n\n\n}\n\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}\n\n\n", "src_uid": "0515ac888937a4dda30cad5e2383164f"} {"source_code": "private fun readLn() = readLine()!!\nprivate fun readString() = readLn().trim()\nprivate fun readInt() = readLn().toInt()\nprivate fun readLong() = readLn().toLong()\nprivate val regSpace = \"\\\\s+\".toRegex()\nprivate fun readSomeInts(): List {\n return readLn().trim().split(regSpace).map { it.toInt() }\n}\nprivate fun readSomeLongs(): List {\n return readLn().trim().split(regSpace).map { it.toLong() }\n}\n\ndata class Point(val row: Int, val col: Int)\n\nfun main() {\n val (n, m) = readSomeInts()\n\n fun neighbors(p: Point): List {\n val acc = mutableListOf()\n if (p.row > 0) {\n acc.add(Point(p.row - 1, p.col))\n }\n if (p.col > 0) {\n acc.add(Point(p.row, p.col - 1))\n }\n if (p.col < m - 1) {\n acc.add(Point(p.row, p.col + 1))\n }\n if (p.row < n - 1) {\n acc.add(Point(p.row + 1, p.col))\n }\n return acc\n }\n\n val field = mutableListOf().apply {\n repeat(n) {\n val s = readString()\n this.add(s)\n }\n }.toList()\n\n fun hasWolf(p: Point) = field[p.row][p.col] == 'W'\n\n val wolfNotHangry = Array(n) { BooleanArray(m) }\n\n var countEatenPigs = 0\n for (i in 0 until n) {\n for (j in 0 until m) {\n if (field[i][j] == 'P') {\n val pigPt = Point(i, j)\n val anyWolf = neighbors(pigPt)\n .firstOrNull { pt -> hasWolf(pt) && !wolfNotHangry[pt.row][pt.col] }\n if (anyWolf != null) {\n wolfNotHangry[anyWolf.row][anyWolf.col] = true\n countEatenPigs++\n }\n }\n }\n }\n println(countEatenPigs)\n}\n", "src_uid": "969b24ed98d916184821b2b2f8fd3aac"} {"source_code": "\nfun main(args : Array) {\n val n1 = readLine()!!\n var n = n1.toInt()\n val s = readLine()!!\n var a = 0\n var sum1 = 0\n var sum2 = 0\n for (i in 0..s.length - 1) {\n if (s[i] == '4' || s[i] == '7') {\n a++\n }\n }\n\n if(a==s.length){\n for(i in 0..n/2-1){\n sum1= sum1+s[i].toInt()\n }\n for(j in n/2..n-1){\n sum2= sum2+s[j].toInt()\n }\n if(sum1==sum2){\n println(\"YES\")\n }\n else{\n println(\"NO\")\n }\n }\n else{\n println(\"NO\")\n }\n\n\n}", "src_uid": "435b6d48f99d90caab828049a2c9e2a7"} {"source_code": "import java.util.*\nimport kotlin.math.log2\n\nfun main(args: Array) {\n cf()\n}\n\nprivate fun cf() = with(Scanner(System.`in`)) {\n val n = nextInt()\n val a = nextInt()\n val b = nextInt()\n\n val r = round(n, a, b)\n if (isFinal(r, n))\n println(\"Final!\")\n else\n println(r)\n}\n\nprivate fun isFinal(r: Int, n: Int): Boolean {\n return log2(n.toDouble()).toInt() == r\n}\n\nprivate fun round(n: Int, a_: Int, b_: Int): Int {\n var n = n\n var a = minOf(a_, b_)\n var b = maxOf(a_, b_)\n\n var games = 0\n\n while (true) {\n games++\n\n if (b % 2 == 0 && a + 1 == b) {\n return games\n }\n\n n /= 2\n a = (a + 1) / 2\n b = (b + 1) / 2\n }\n}", "src_uid": "a753bfa7bde157e108f34a28240f441f"} {"source_code": "\r\nfun main() {\r\n val (p1, t1) = readln().split(' ').let { (p, t) -> p.toInt() to t.toLong() }\r\n val (p2, t2) = readln().split(' ').let { (p, t) -> p.toInt() to t.toLong() }\r\n val (h, s) = readln().split(' ').let { (h, s) -> h.toInt() to s.toLong() }\r\n val minTime = LongArray(h + 1){Long.MAX_VALUE shr 1}.also { it[0] = 0L }\r\n for (c1 in 1 .. h) {\r\n val time = t1 * c1\r\n val c2 = time / t2\r\n val damage = p1 * c1 + p2 * c2 - s * if (c2 > 0) (c1 + c2 - 1) else (c1 + c2)\r\n for (i in minTime.indices) {\r\n val j = minOf(h.toLong(), i + damage).toInt()\r\n minTime[j] = minOf(minTime[j], minTime[i] + time)\r\n }\r\n }\r\n for (c2 in 1 .. h) {\r\n val time = t2 * c2\r\n val c1 = time / t1\r\n val damage = p1 * c1 + p2 * c2 - s * if (c1 > 0) (c1 + c2 - 1) else (c1 + c2)\r\n for (i in minTime.indices) {\r\n val j = minOf(h.toLong(), i + damage).toInt()\r\n minTime[j] = minOf(minTime[j], minTime[i] + time)\r\n }\r\n }\r\n val result = minTime[h]\r\n println(result)\r\n}", "src_uid": "ca9d48e48e69b931236907a9ac262433"} {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (r1, r2) = readInts()\n val (c1, c2) = readInts()\n val (d1, d2) = readInts()\n nextAttempt@ for (tl in 1..9) {\n val tr = r1 - tl\n val bl = c1 - tl\n val br = d1 - tl\n val all = setOf(tl, tr, bl, br)\n if (all.size != 4) continue\n for (gem in all) if (gem !in 1..9) continue@nextAttempt\n if (r2 != bl + br) continue\n if (c2 != tr + br) continue\n if (d2 != tr + bl) continue\n println(\"$tl $tr\")\n return print(\"$bl $br\")\n }\n print(-1)\n}", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3"} {"source_code": "import java.lang.StringBuilder\n\nfun main(){\n var line = readLine().toString()\n var cap = StringBuilder(line.toUpperCase())\n cap[0] = cap[0].toLowerCase()\n\n if(line.equals(line.toUpperCase()))\n println(line.toLowerCase())\n else if(line.equals(cap.toString())){\n cap = StringBuilder(line.toLowerCase())\n cap[0] = cap[0].toUpperCase()\n println(cap)\n }else\n println(line)\n\n\n}\n", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf"} {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n var sc = Scanner(System.`in`)\n\n var n = sc.nextInt()\n var m = sc.nextInt()\n var i = 0\n while (m >= 0) {\n var index = (i % n) + 1\n if (m < index) break\n m -= index\n i++\n }\n print(m)\n \n}", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb"} {"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", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8"} {"source_code": "fun main() {\n val numberOfTests = readLine()!!.toInt()\n repeat(numberOfTests) {\n val numberOfCandies = readLine()!!.split(' ')[0].toInt()\n println(if (numberOfCandies % 2 == 0) numberOfCandies / 2 - 1 else numberOfCandies / 2)\n }\n}", "src_uid": "b69170c8377623beb66db4706a02ffc6"} {"source_code": "import kotlin.math.*\nimport java.io.*\nimport java.util.*\n\nclass FS(stin: InputStream) {\n val read = BufferedReader(InputStreamReader(stin))\n var token = StringTokenizer(\"\")\n\n tailrec fun next(): String {\n if(token.hasMoreTokens()) return token.nextToken()\n token = StringTokenizer(read.readLine())\n return next()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextDouble() = next().toDouble()\n}\n\nval ko = PrintWriter(System.out)\nval ki = FS(System.`in`)\ntypealias Chi = Int\n\nfun main() {\n // for(i in 0 until ki.nextInt())\n solve()\n\n ko.close()\n}\n\nfun solve() {\n var n = ki.nextInt()\n val a = ki.nextInt(); val b = ki.nextInt(); val c = ki.nextInt()\n val x = ki.nextInt(); val y = ki.nextInt(); val z = ki.nextInt()\n\n val cap = Array(8, {IntArray(8, {0})})\n cap[6][0] = a; cap[6][1] = b; cap[6][2] = c\n cap[3][7] = x; cap[4][7] = y; cap[5][7] = z\n cap[0][3] = n; cap[0][5] = n\n cap[1][4] = n; cap[1][3] = n\n cap[2][5] = n; cap[2][4] = n\n val vis = BooleanArray(8, {false})\n fun dfs(x: Int, curr: Int): Int {\n if(x == 7) return curr\n if(vis[x]) return 0\n vis[x] = true\n for(i in 0..7) {\n val next = min(curr, cap[x][i])\n if(next != 0) {\n val add = dfs(i, next)\n if(add > 0) {\n cap[x][i] -= add\n cap[i][x] += add\n return add\n }\n }\n }\n return 0\n }\n var i = n\n while(true) {\n vis.fill(false)\n val d = dfs(6, n)\n if(d == 0) break\n i -= d\n }\n val j = min(a, y)+min(b, z)+min(c, x)\n ko.println(\"$i $j\")\n}", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402"} {"source_code": "var matrix: Array = arrayOf()\nvar bit: Array = arrayOf()\nvar n = 0\nvar m = 0\nval circle = arrayOf(\n Pair(0, 0),\n Pair(0, 1),\n Pair(0, 2),\n Pair(1, 2),\n Pair(2, 2),\n Pair(2, 1),\n Pair(2, 0),\n Pair(1, 0)\n)\n\n\nfun check(i: Int, j: Int, k: Int): Boolean {\n val x = circle[k].first\n val y = circle[k].second\n for (l in 0..7) {\n val new_x = i + circle[l].first - x\n val new_y = j + circle[l].second - y\n if (new_x in 0 until n && new_y in 0 until m && matrix[new_x][new_y] == '#') {\n } else return false\n }\n return true\n}\n\nfun find(): Boolean {\n val twoInt = readLine()!!.split(\" \").map { it.toInt() }\n n = twoInt[0]\n m = twoInt[1]\n bit = Array(n) { _ -> BooleanArray(m) { false } }\n for (i in 0 until n) {\n matrix += readLine()!!.toCharArray()\n }\n for (i in 0 until n) {\n for (j in 0 until m) {\n if (matrix[i][j] == '#' && !bit[i][j]) {\n var flag = false\n for (k in 0..7) {\n if (check(i, j, k)) {\n bit[i][j] = true\n flag = true\n break\n }\n }\n if (!flag) return false\n }\n }\n }\n return true\n}\n\nfun main(args: Array) {\n println(if (find()) \"YES\" else \"NO\")\n}\n\n", "src_uid": "49e5eabe8d69b3d27a251cccc001ab25"} {"source_code": "import java.io.*\nimport java.lang.Math.*\nimport java.util.*\n\n\nfun main() {\n init(System.`in`, System.out)\n val twos = LongArray(64) { i -> 1L shl i }\n val l = nextLong()\n val r = nextLong()\n var max = 0L\n for (i in 0 until 64) {\n if (twos[i] and l != twos[i] and r) {\n max = (1L shl i + 1) - 1\n }\n }\n pw.println(max)\n pw.close()\n}\n\nlateinit var br: BufferedReader\nlateinit var st: StringTokenizer\nlateinit var pw: PrintWriter\n\nfun init(`in`: InputStream, out: OutputStream) {\n br = BufferedReader(InputStreamReader(`in`))\n st = StringTokenizer(\"\")\n pw = PrintWriter(out)\n}\n\nfun init(`in`: File, out: File) {\n br = BufferedReader(FileReader(`in`))\n st = StringTokenizer(\"\")\n pw = PrintWriter(out)\n}\n\nfun next(): String {\n if (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st.nextToken()\n}\n\nfun nextInt() = next().toInt()\nfun nextLong() = next().toLong()\n", "src_uid": "d90e99d539b16590c17328d79a5921e0"} {"source_code": "import java.util.HashSet\n\nfun main() {\n var n = readLine()!!.toInt()\n var set = mutableSetOf()\n var list = mutableListOf()\n var num: Int\n for (i in 1..n) {\n num = readLine()!!.toInt()\n set.add(num)\n list.add(num)\n }\n var f = list[0]\n var s = -1\n var count = 0\n var count1 = 0\n if (set.size != 2) {\n println(\"NO\")\n } else {\n for (i in list) {\n if (i == f) {\n count++\n } else {\n s = i\n count1++\n }\n }\n if (count == count1) {\n println(\"YES\")\n println(\"$f $s\")\n } else {\n println(\"NO\")\n }\n }\n}", "src_uid": "2860b4fb22402ea9574c2f9e403d63d8"} {"source_code": "import kotlin.math.min\n\nfun main() {\n val board = Array(8) { CharArray(8) }\n for (numRow in 0 until 8)\n board[numRow] = readLine()!!.toCharArray()\n var bestB = Int.MAX_VALUE\n var bestW = Int.MAX_VALUE\n for (row in 0 until 8)\n loop@ for (column in 0 until 8) {\n when (board[row][column]) {\n 'B' -> {\n for (rowCheck in row + 1 until 8)\n if (board[rowCheck][column] == 'W') continue@loop\n bestB = min(bestB, 7 - row)\n }\n 'W' -> {\n for (rowCheck in row - 1 downTo 0)\n if (board[rowCheck][column] == 'B') continue@loop\n bestW = min(bestW, row)\n }\n }\n }\n print(if (bestB < bestW) 'B' else 'A')\n}", "src_uid": "0ddc839e17dee20e1a954c1289de7fbd"} {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007\n\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val R = ni()\n val G = ni()\n var H = 0\n while((H + 1) * (H + 2) / 2 <= R + G) H++\n val N = min(R, G)\n var cur = IntArray(1_000_000)\n var next = IntArray(1_000_000)\n cur[0] = 1\n var sum = 0L\n for (i in H - 1 downTo 0) {\n val size = min(N, H * (H + 1) / 2 - i * (i + 1) / 2)\n val nsize = min(N, H * (H + 1) / 2 - (i + 1) * (i + 2) / 2)\n for (j in 0 .. size) {\n next[j] = 0\n if (j <= nsize) next[j] += cur[j]\n val nj = j - (i + 1)\n if (nj in 0..nsize) {\n next[j] += cur[nj]\n }\n if (next[j] > MOD) next[j] -= MOD\n }\n// debug(next.take(10).toLongArray())\n val tmp = cur\n cur = next\n next = tmp\n sum += size\n }\n debug{\"sum:$sum\"}\n var ans = 0L\n val remain = R + G - H * (H + 1) / 2\n for (r in 0 .. remain) {\n val j = N - r\n if (j in cur.indices) ans += cur[j]\n }\n out.println(ans % MOD)\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\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", "src_uid": "34b6286350e3531c1fbda6b0c184addc"} {"source_code": "// kotlin tips b/c I'm bad\n\n/** useful links\n * https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html\n * https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-array-list/index.html\n * https://kotlinlang.org/docs/reference/ranges.html\n */\n\n/** valid ways to sort (don't use quicksort ...)\n * 1\n * val a = nextLongs().sorted() // a is mutable list\n * 2\n * val a = arrayListOf()\n * a.addAll(nextLongs())\n * a.sort()\n */\n\n/** declare 2D array\n * val ori = Array(n, {IntArray(n)})\n * val ori = arrayOf(\n intArrayOf(8, 9, 1, 13),\n intArrayOf(3, 12, 7, 5),\n intArrayOf(0, 2, 4, 11),\n intArrayOf(6, 10, 15, 14)\n )\n */\n\n/** printing variables:\n * println(\"${l+1} and $r\")\n * evidently print has high constant factor\n * print stringbuilder instead?\n */\n\n// ArrayList to Array: toArray\n\n// IntArray with size:\n// val arr = IntArray(1 shl 20, { 1 })\n\n// lower bound: use binary search\n// https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/binary-search.html\n\n// if/switch\n// https://kotlinlang.org/docs/reference/control-flow.html\n\n// swap:\n// https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/also.html\n// a = b.also { b = a }\n\n/** comparing pairs\n * val ed = ArrayList>>()\n ed.sortBy {it.first}\n * class CustomComparator : Comparator>> {\n override fun compare(o1: Pair>, o2: Pair>): Int {\n return o1.first.compareTo(o2.first)\n }\n }\n val v = ed.sortedWith(CustomComparator())\n *\n val v = ArrayList>()\n for (t in a) v.add(Pair(cat(t),t))\n val z = v.sortedWith(compareBy({ -it.first }, { it.second }))\n */\n\n/** hashmap\n * val h = HashMap()\n for (i in 0..n-2) {\n val w = s.substring(i,i+2)\n val c = h.getOrElse(w){0}\n h.put(w,c+1)\n }\n */\n\nimport java.util.*\n\nval MX = 1000005\nval MOD = 998244353\nval SZ = 1 shl 19\nval INF = (1e18).toLong()\n\nfun add(a: Int, b: Int) = (a + b) % MOD\nfun sub(a: Int, b: Int) = (a - b + MOD) % MOD\nfun mul(a: Int, b: Int) = ((a.toLong() * b) % MOD).toInt()\n\nfun next() = readLine()!!\nfun nextInt() = next().toInt()\nfun nextLong() = next().toLong()\nfun nextInts() = next().split(\" \").map { it.toInt() }\nfun nextLongs() = next().split(\" \").map { it.toLong() }\n\nvar n = 0\nvar k = 0\n\nval adj = Array(401,{ArrayList>()})\nval dp = Array(401,{ArrayList()})\nval pre = Array(401,{ArrayList()})\nval par = Array>(401,{Pair(0,0)})\n\nfun comb(a: ArrayList, b: ArrayList): ArrayList {\n val res = ArrayList()\n val sz = a.size+b.size-1\n for (i in 0..sz-1) res.add(MOD)\n res[0] = 1\n // a[1] ++\n // a[i]+b[j], i > 0, j > 0\n for (i in 1..a.size-1)\n for (j in 0..b.size-1)\n res[i+j] = minOf(res[i+j],a[i]+b[j])\n return res\n}\n\nfun dfs(x: Int) {\n dp[x] = arrayListOf(1,0)\n for (t in adj[x]) if (t.first != par[x].first) {\n par[t.first] = Pair(x,t.second)\n dfs(t.first)\n pre[t.first] = ArrayList(dp[x])\n dp[x] = comb(pre[t.first],dp[t.first])\n }\n // println(\"$x ${dp[x]}\")\n}\n\nval ans = ArrayList()\n\nfun genAns(x: Int, _lef: Int) {\n var lef = _lef\n if (lef == 0) {\n ans.add(par[x].second)\n return\n }\n adj[x].reverse()\n for (t in adj[x]) if (t.first != par[x].first) {\n if (lef == 1) {\n ans.add(t.second)\n } else {\n var done = false\n for (i in 1..pre[t.first].size-1) {\n for (j in 0..dp[t.first].size-1)\n if (i+j == lef && pre[t.first][i]+dp[t.first][j] == dp[x][lef]) {\n done = true\n lef = i\n genAns(t.first,j)\n break\n }\n if (done) break\n }\n assert(done)\n }\n dp[x] = ArrayList(pre[t.first])\n }\n assert(lef == 1)\n}\n\n\nfun finish(x: Int) {\n if (x != 1) {\n ans.add(par[x].second)\n }\n genAns(x,k)\n println(ans.size)\n for (t in ans) print(\"$t \")\n System.exit(0)\n}\n\nfun solve() {\n val (N,K) = nextInts()\n n = N\n k = K\n for (i in 1..n-1) {\n val (x,y) = nextInts()\n adj[x].add(Pair(y,i))\n adj[y].add(Pair(x,i))\n }\n dfs(1)\n var res = MOD\n for (i in 1..N) if (dp[i].size > k) {\n var v = dp[i][k]\n if (i != 1) v ++\n res = minOf(res,v)\n }\n for (i in 1..N) if (dp[i].size > k) {\n var v = dp[i][k]\n if (i != 1) v ++\n if (res == v) finish(i)\n }\n // println(res)\n}\n\nfun main(args: Array) {\n val T = 1\n for (i in 1..T) solve()\n}", "src_uid": "56168b28f9ab4830b3d3c5eeb7fc0d3c"} {"source_code": "\nimport java.io.BufferedInputStream\nimport java.io.File\nimport java.io.PrintWriter\nimport kotlin.math.ln\nimport kotlin.system.measureTimeMillis\n\ninline fun TIME(f:()->Unit){\n val t = measureTimeMillis(){\n f()\n }\n println(\"$t ms\")\n}\n\nobject IO{\n private const val BS = 1 shl 16\n private const val NC = 0.toChar()\n private val buf = ByteArray(BS)\n private var bId = 0\n private var size = 0\n private var c = NC\n\n var warningActive = true\n var fakein = StringBuilder()\n\n private var IN: BufferedInputStream = BufferedInputStream(System.`in`, BS)\n val OUT: PrintWriter = PrintWriter(System.out)\n\n private val char: Char\n get() {\n while (bId == size) {\n size = IN.read(buf) // no need for checked exceptions\n if (size == -1) return NC\n bId = 0\n }\n return buf[bId++].toChar()\n }\n\n fun nextInt(): Int {\n var neg = false\n if (c == NC) c = char\n while (c < '0' || c > '9') {\n if (c == '-') neg = true\n c = char\n }\n var res = 0\n while (c in '0'..'9') {\n res = (res shl 3) + (res shl 1) + (c - '0')\n c = char\n }\n return if (neg) -res else res\n }\n fun nextLong(): Long {\n var neg = false\n if (c == NC) c = char\n while (c < '0' || c > '9') {\n if (c == '-') neg = true\n c = char\n }\n var res = 0L\n while (c in '0'..'9') {\n res = (res shl 3) + (res shl 1) + (c - '0')\n c = char\n }\n return if (neg) -res else res\n }\n fun nextString():String{\n val ret = StringBuilder()\n while (true){\n c = char\n if(!isWhitespace(c)){ break}\n }\n ret.append(c)\n while (true){\n c = char\n if(isWhitespace(c)){ break}\n ret.append(c)\n }\n return ret.toString()\n }\n fun isWhitespace(c:Char):Boolean{\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t'\n }\n fun rerouteInput(){\n if(warningActive){\n put(\"You forgot to disable tests you digital dummy!\")\n println(\"You forgot to disable tests you digital dummy!\")\n warningActive = false\n }\n val S = fakein.toString()\n println(\"New Case \")\n println(S.take(80))\n println(\"...\")\n fakein.clear()\n IN = BufferedInputStream(S.byteInputStream(),BS)\n }\n fun takeFile(name:String){\n IN = BufferedInputStream(File(name).inputStream(),BS)\n }\n}\nfun put(aa:Any){ IO.OUT.println(aa)}\nfun done(){ IO.OUT.close() }\nfun share(aa:Any){\n if(aa is IntArray){IO.fakein.append(aa.joinToString(\" \"))}\n else if(aa is LongArray){IO.fakein.append(aa.joinToString(\" \"))}\n else if(aa is List<*>){IO.fakein.append(aa.toString())}\n else{IO.fakein.append(aa.toString())}\n IO.fakein.append(\"\\n\")\n}\n\nval getint:Int get() = IO.nextInt()\nval getlong:Long get() = IO.nextLong()\nval getstr:String get() = IO.nextString()\nfun getline(n:Int):IntArray{\n return IntArray(n){getint}\n}\nfun getlineL(n:Int):LongArray{\n return LongArray(n){getlong}\n}\nfun getbinary(n:Int):BooleanArray{\n val str = getstr\n return BooleanArray(n){str[it] == '1'}\n}\n\nval List.ret:String\nget() = this.joinToString(\"\")\ninfix fun Any.dei(a:Any){\n //does not stand for anything it is just easy to type, have to be infix because kotlin does not have custom prefix operators\n var str = \"\"\n if(this is String){ str = this\n }else if(this is Int){ str = this.toString()\n }else if(this is Long){ str = this.toString()\n }\n if(a is List<*>){ println(\"$str : ${a.joinToString(\" \")}\")\n }else if(a is IntArray){ println(\"$str : ${a.joinToString(\" \")}\")\n }else if(a is LongArray){ println(\"$str : ${a.joinToString(\" \")}\")\n }else{ println(\"$str : $a\")\n }\n}\nval just = \" \" // usage: just dei x , where x is the debug variable\nfun crash(){throw Exception(\"Bad programme\")} // because assertion does not work\nfun assert(a:Boolean){\n if(!a){throw Exception(\"Failed Assertion\")\n }}\nenum class solveMode {\n real, rand, tc\n}\nconst val withBruteForce = false\nconst val randCount = 100\nobject solve{\n var mode:solveMode = solveMode.real\n var tcNum:Int = 0\n var rand:()->Unit = {}\n var TC:MutableMapUnit> = mutableMapOf()\n var answersChecked = 0\n var tn:Long = 0\n fun cases(onecase:()->Unit){\n val t = if(mode == solveMode.real){if(singleCase) 1 else getint} else if(mode == solveMode.tc){1 } else randCount\n //safety checks\n if(pI != 998_244_353 && pI != 1_000_000_007){\n throw Exception(\"Modding a wrong prime!\")\n }\n\n if(t == 1 && mode != solveMode.real){\n tn = System.currentTimeMillis()\n }\n repeat(t){\n if(mode == solveMode.tc){\n TC[tcNum]?.let { it() }\n IO.rerouteInput()\n }else if(mode == solveMode.rand){\n rand()\n IO.rerouteInput()\n }\n currentAnswer = null\n currentBruteAnswer = null\n onecase()\n }\n if(withBruteForce){\n put(\"Checked ${answersChecked}\")\n }\n if(t == 1 && mode != solveMode.real){\n val dt = System.currentTimeMillis() - tn\n println(\"Time $dt ms \")\n }\n }\n inline fun singleCase(a:solve.()->Unit){\n val t = if(mode != solveMode.rand){1} else randCount\n repeat(t) { a() }\n }\n fun rand(a:()->Unit){\n this.rand = a\n }\n fun tc(id:Int = 0,a:()->Unit){\n TC[id] = a\n }\n inline fun brute(a:()->Unit){\n if(withBruteForce){\n a()\n }\n }\n fun usetc(a:Int = 0 ){\n this.tcNum = a\n this.mode = solveMode.tc\n }\n fun userand(){\n this.mode = solveMode.rand\n }\n\n\n var currentAnswer:String? = null\n var currentBruteAnswer:String? = null\n fun answer(a:Any){\n currentAnswer = a.toString()\n if(currentBruteAnswer != null){\n checkAnswer()\n }\n }\n fun put2(a:Any){answer(a);put(a) }\n\n fun bruteAnswer(a:Any){\n currentBruteAnswer = a.toString()\n if(currentAnswer != null){\n checkAnswer()\n }\n }\n fun checkAnswer(){\n if(currentAnswer != currentBruteAnswer){\n throw Exception(\"Failed Test: BF $currentBruteAnswer Current $currentAnswer\")\n }\n answersChecked ++\n }\n}\n// 1. Modded\nconst val p = 998244353L\nconst val pI = p.toInt()\nfun Int.adjust():Int{ if(this >= pI){ return this - pI }else if (this < 0){ return this + pI };return this }\nfun Int.snap():Int{ if(this >= pI){return this - pI} else return this}\ninfix fun Int.modM(b:Int):Int{ return ((this * 1L * b) % pI).toInt() }\ninfix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }\n// 2. DP initial values\nconst val plarge = 1_000_000_727\nconst val nlarge = -plarge\nconst val phuge = 2_727_000_000_000_000_000L\nconst val nhuge = -phuge\n// 3. conveniecen conversions\nval Boolean.chi:Int get() = if(this) 1 else 0 //characteristic function\nval Char.code :Int get() = this.toInt() - 'a'.toInt()\n//3. hard to write stuff\nfun IntArray.put(i:Int,v:Int){ this[i] = (this[i] + v).adjust() }\nval mint:MutableList get() = mutableListOf()\nval mong:MutableList get() = mutableListOf()\n\n\ninfix fun Int.divCeil(b:Int):Int{\n //Positives numbers only!\n if(this == 0) {\n return 0\n }\n return (this-1)/b + 1\n}\ninfix fun Long.divCeil(b:Long):Long{\n //Positives numbers only!\n if(this == 0L) {\n return 0\n }\n return (this-1)/b + 1\n}\n\ninfix fun Long.modM(b:Long):Long{\n return (this * b) % p\n}\n//infix fun Int.modPlus(b:Int):Int{\n// val ans = this + b\n// return if(ans >= pI) ans - pI else ans\n//}\ninfix fun Int.modMinus(b:Int):Int{\n val ans = this - b\n return if(ans < 0) ans + pI else ans\n}\ninfix fun Int.modDivide(b:Int):Int{\n return this modM (b.inverse())\n}\nfun Int.additiveInverse():Int{\n return if(this == 0) 0 else pI - this\n}\n\n\nfun intPow(x:Int,e:Int,m:Int):Int{\n var X = x\n var E =e\n var Y = 1\n while(E > 0){\n if(E % 2 == 0){\n X = ((1L * X * X) % m).toInt()\n E /= 2\n }else{\n Y = ((1L * X * Y) % m).toInt()\n E -= 1\n }\n }\n return Y\n}\n\nfun pow(x:Long,e:Long,m:Long):Long{\n var X = x\n var E =e\n var Y = 1L\n while(E > 0){\n if(E % 2 == 0L){\n X = (X * X) % m\n E /= 2\n }else{\n Y = (X * Y) % m\n E -= 1\n }\n }\n return Y\n}\nfun Long.inverse():Long{\n return pow(this,p-2,p)\n}\nfun Int.inverse():Int{\n return intPow(this,pI-2,pI)\n}\n//make this int instead\nclass FACT{\n companion object {\n var store = IntArray(0)\n var invStore = IntArray(0)\n\n var slowStore:IntArray = IntArray(0)\n\n fun preCal(upto:Int){\n store = IntArray(upto+1)\n invStore = IntArray(upto + 1 )\n store[0] = 1\n invStore[0] = 1\n\n for(i in 1..upto) {\n store[i] = store[i-1] modM i\n invStore[i] = invStore[i-1] modM (i.inverse())\n }\n }\n fun choose(n:Int,r:Int):Int{\n if(r < 0 || r > n) return 0\n val a = store[n]\n val b = invStore[n-r]\n val c = invStore[r]\n return (a modM b) modM c\n }\n\n fun bigChoose(n:Int,r:Int):Int{\n var ret = 1\n for(i in 0 until r){\n ret = ret modM (n - i)\n }\n ret = ret modM (invStore[r])\n return ret\n }\n\n }\n}\n\nclass FFT {\n companion object{\n // val fftmod = 7340033\n// val root = 5\n// val root_1 = 4404020\n// val root_pw = 1 shl 20\n private const val fftmod = 998244353\n private const val root = 15311432\n private const val root_1 = 469870224\n private const val root_pw = 1 shl 23\n\n fun calculateRoot(){\n println(\"root :$root\")\n // intPow(3,7 * 17,fftmod)\n println(\"root_1 : $root_1\")\n // intPow(root,fftmod -2,fftmod)\n }\n\n fun fft(a:IntArray,invert:Boolean){\n val n = a.size\n var j = 0\n\n\n for(i in 1 until n){\n var bit = n shr 1\n while(j and bit > 0){\n j = j xor bit\n bit = bit shr 1\n }\n j = j xor bit\n if(i < j){\n val temp = a[i]\n a[i] = a[j]\n a[j] = temp\n }\n }\n var len = 2\n while(len <= n){\n var wlen = if(invert) root_1 else root\n var i = len\n while(i < root_pw){\n wlen = (1L * wlen * wlen % fftmod).toInt()\n i = i shl 1\n }\n i = 0\n while(i < n){\n var w = 1\n for(j in 0 until len/2){\n val u = a[i+j]\n val v = (1L * a[i+j+len/2] * w % fftmod).toInt()\n a[i+j] = if(u+v < fftmod) u + v else u + v - fftmod\n a[i+j+len/2] = if(u-v >= 0) u-v else u-v+fftmod\n w = (1L * w * wlen % fftmod).toInt()\n }\n i += len\n }\n len = len shl 1\n }\n if(invert){\n val n_1 = pow(n.toLong(),(fftmod-2).toLong(),fftmod.toLong())\n for((i,x) in a.withIndex()){\n a[i] = (1L * x * n_1 % fftmod).toInt()\n }\n }\n }\n fun fullconvolution(at:IntArray,bt:IntArray):IntArray{\n return fullconvolutionOpt(at,bt,at.size,bt.size)\n }\n\n fun fullconvolutionOpt(at:IntArray,bt:IntArray,sizeA:Int,sizeB:Int):IntArray{\n // 1 shl 18 done in 77 ms\n val maxSize = (sizeA + sizeB).takeHighestOneBit() * 2\n val a = at.copyOf(maxSize)\n val b = bt.copyOf(maxSize)\n val expectedSize = at.size + bt.size - 1\n fft(a,false)\n fft(b,false)\n val new = IntArray(maxSize)\n for(i in new.indices){\n new[i] = (1L * a[i] * b[i] % fftmod).toInt()\n }\n fft(new,true)\n return new.copyOf(expectedSize)\n }\n }\n}\n\nfun stir(l:Int, r:Int):IntArray{\n if(l == r){\n return intArrayOf(l,1)\n }else{\n val mid = (l+r) shr 1\n return FFT.fullconvolution(stir(l,mid), stir(mid+1,r))\n }\n}\n\n\n\nobject sieve{\n\n const val sieveMx = 200005\n val primeOf = IntArray(sieveMx + 1)\n var primeCounter = 0\n val primeUpperBound = maxOf(25,(sieveMx.toDouble()/(ln(sieveMx.toDouble()) -4)).toInt() +3)\n val primes = IntArray(primeUpperBound)\n var sieveCalculated = false\n val nextPrime = IntArray(sieveMx+1)\n val nextPrimePower = IntArray(sieveMx+1)\n val afterPrimePowerDivison = IntArray(sieveMx+1)\n var mobius = IntArray(0)\n\n var factors:List> = mutableListOf()\n\n fun calculateSieveFast(){\n if(sieveCalculated){\n return\n }\n sieveCalculated = true\n for(i in 2..sieveMx){\n if(primeOf[i] == 0 ){\n primeOf[i] = i\n primes[primeCounter] = i\n primeCounter += 1\n }\n for(j in 0 until primeCounter){\n val p = primes[j]\n val pd = p * i\n if(p <= i && pd <= sieveMx){\n primeOf[pd] = p\n }else{\n break\n }\n }\n }\n }\n fun preparePrimePower(){\n nextPrime[1] = -1\n nextPrimePower[1] = -1\n afterPrimePowerDivison[1] = 1\n for(i in 2..sieveMx){\n val p = primeOf[i]\n val new = i / p\n nextPrime[i] = p\n if(nextPrime[new] == p){\n nextPrimePower[i] = nextPrimePower[new]\n afterPrimePowerDivison[i] = afterPrimePowerDivison[new]\n }else{\n afterPrimePowerDivison[i] = new\n }\n nextPrimePower[i] += 1\n }\n }\n fun prepareFactors(){\n // 700ms in 1M\n // shoudl not be used for 1M\n // 200ms codeforces for 200k\n factors = List(sieveMx + 1){ mutableListOf()}\n factors[1].add(1)\n\n for(i in 2..sieveMx){\n val p = nextPrime[i]\n val a = nextPrimePower[i]\n val old = afterPrimePowerDivison[i]\n\n var here = 1\n repeat(a+1){\n for(c in factors[old]){\n factors[i].add(c * here )\n }\n here *= p\n }\n// factors[1].ad\n// factors[i].addAll(i.factors())\n }\n }\n fun calculateMobius(){\n kotlin.assert(sieveCalculated)\n mobius = IntArray(sieveMx + 1)\n mobius[1] = 1\n for(i in 2..sieveMx){\n val p = primeOf[i]\n if(p == primeOf[i/p]){\n mobius[i] = 0\n }else{\n mobius[i] = -1 * mobius[i/p]\n }\n }\n }\n}\ninline fun Int.eachPrimePower(act:(Int,Int)->Unit){\n var here = this\n while(here > 1){\n act(sieve.nextPrime[here], sieve.nextPrimePower[here])\n here = sieve.afterPrimePowerDivison[here]\n }\n}\nfun GS(start:Int,ratio:Int,count:Int) = sequence {\n var ret = 1\n for(i in 1\n ..count){\n ret *= ratio\n yield(ret)\n }\n}\nfun Int.factors():List{\n val ret = mutableListOf(1)\n this.eachPrimePower { p, e ->\n val s = ret.toList()\n for(pn in GS(p,p,e)){\n ret.addAll(s.map{it * pn})\n }\n }\n return ret\n}\nfun totient(a:Int):Int{\n var ret = a\n a.eachPrimePower{\n p, _ ->\n ret /= p\n ret *= (p-1)\n }\n return ret\n}\nfun Int.numOfDivisors():Int{\n var ret = 1\n this.eachPrimePower { _, e -> ret *= (e+1) }\n return ret\n}\nfun Int.factorLook():List{\n return sieve.factors[this]\n}\n\n\nfun stirtry2(n:Int):IntArray {\n val A = IntArray(n+1){\n val x = FACT.invStore[it]\n if(it %2 == 0) x else x.additiveInverse()\n }\n val B = IntArray(n+1){\n intPow(it, n,pI) modM FACT.invStore[it]\n }\n val F = FFT.fullconvolution(A,B)\n\n return F\n}\nval recitations = mutableMapOf()\nfun getitdone(n:Int, k:Int):Int{\n if(recitations[n] != null){\n return recitations[n]!!\n }\n val that = stirtry2(n)\n var ret = 0\n for(i in 1..minOf(n,k)){\n ret = ret modPlus that[i]\n }\n// \"$n $k \" dei thatv\\\\\n\n val final = ret modMinus 1\n recitations[n] = final\n return final\n}\n\n\n\nvar n =0\nconst val singleCase = true\nfun main(){\n FACT.preCal(200005)\n sieve.calculateSieveFast()\n sieve.calculateMobius()\n\n// just dei stirtry2(6)\n solve.cases{\n n = getint\n val k = getint\n var ans = 0\n\n if(k == 1 || n ==1){\n put(1)\n return@cases\n\n }\n\n for(i in 1..n){\n val m = sieve.mobius[i].adjust()\n if(m == 0) continue\n\n val now = getitdone(n divCeil i,k)\n// i dei now\n ans = ans modPlus ( now modM m)\n }\n put(ans)\n }\n done()\n}\n/*\njust number of such patterns\n\n\n\nn\nn/2\nn/3\n\n */\n\n\n\n\n", "src_uid": "eb9d24070cc5b347d020189d803628ae"} {"source_code": "import java.util.Scanner;\n\nfun main(args: Array) {\n var scan = Scanner(System.`in`);\n var area: Int = scan.nextInt();\n\n var sqrt: Int = Math.floor(Math.sqrt(area.toDouble())).toInt();\n var p: Int = sqrt * 4;\n var a: Int = sqrt * sqrt;\n var d: Int = area - a;\n if (area == a) {\n System.out.println(p);\n } else if (d <= sqrt) {\n System.out.println(p + 2);\n } else {\n System.out.println(p+4);\n }\n}", "src_uid": "414cc57550e31d98c1a6a56be6722a12"} {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val (n, k) = readLine()!!.split(\" \").map(String::toInt)\n var tmp = n\n var d = 2\n val dividers = ArrayList()\n while (tmp >= d) {\n while (tmp % d == 0) {\n tmp /= d\n dividers.add(d)\n }\n d++\n }\n if (dividers.size >= k) {\n print(\"${dividers.subList(0, dividers.size - k + 1).fold(1) { a, b -> a * b }} \")\n dividers.subList(dividers.size - k + 1, dividers.size).forEach { print(\"$it \") }\n } else {\n println(-1)\n }\n}", "src_uid": "bd0bc809d52e0a17da07ccfd450a4d79"} {"source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val (n, m) = readLine()!!.split(\" \").map { it.toInt() }\n val big = max(m, n)\n val small = min(m, n)\n val diff = big - small\n if (diff > small) {\n print(small)\n } else {\n print((diff + (small - diff) * 2 / 3).toLong())\n }\n}", "src_uid": "0718c6afe52cd232a5e942052527f31b"} {"source_code": "import java.io.InputStream\nimport java.math.BigDecimal\nimport java.math.BigInteger\n\nfun main(args: Array) = input.run {\n val p = nextInt()\n var x = nextInt()\n val y = nextInt()\n var z = x\n while (z >= y) {\n if (ok(z, p)) {\n println(0)\n return\n }\n z -= 50\n }\n\n var ans = 1\n x += 100\n while (true) {\n if (ok(x, p) || x - 50 >= y && ok(x - 50, p)) {\n println(ans)\n return\n }\n x += 100\n ans++\n }\n}\n\nfun ok(s: Int, p: Int): Boolean {\n var i = (s / 50) % 475\n repeat(25) {\n i = (i * 96 + 42) % 475\n if (26 + i == p) {\n return true\n }\n }\n return false\n}\n\nval input = FastScanner()\n\nfun String.toBigInteger() = BigInteger(this)\nfun String.toBigDecimal() = BigDecimal(this)\n\nclass FastScanner(private val input: InputStream = System.`in`) {\n private val sb = StringBuilder()\n private val buffer = ByteArray(4096)\n private var pos = 0\n private var size = 0\n\n fun nextString(): String? {\n var c = skipWhitespace()\n if (c < 0) return null\n\n return sb.run {\n setLength(0)\n\n do {\n append(c.toChar())\n c = read()\n } while (c > ' '.toInt())\n\n toString()\n }\n }\n\n fun nextLine(): String? {\n var c = read()\n if (c < 0) return null\n\n return sb.run {\n setLength(0)\n\n while (c >= 0 && c != '\\n'.toInt()) {\n append(c.toChar())\n c = read()\n }\n\n toString()\n }\n }\n\n fun nextLong(): Long {\n var c = skipWhitespace()\n\n val sign = if (c == '-'.toInt()) {\n c = read()\n -1\n } else 1\n\n var ans = 0L\n\n while (c > ' '.toInt()) {\n ans = ans * 10 + c - '0'.toInt()\n c = read()\n }\n\n return sign * ans\n }\n\n fun nextInt() = nextLong().toInt()\n fun nextDouble() = nextString()?.toDouble() ?: 0.0\n fun nextBigInteger(): BigInteger = nextString()?.toBigInteger() ?: BigInteger.ZERO\n fun nextBigDecimal(): BigDecimal = nextString()?.toBigDecimal() ?: BigDecimal.ZERO\n\n fun nextStrings(n: Int) = Array(n) { nextString() ?: \"\" }\n fun nextInts(n: Int) = IntArray(n) { nextInt() }\n fun nextLongs(n: Int) = LongArray(n) { nextLong() }\n fun nextDoubles(n: Int) = DoubleArray(n) { nextDouble() }\n fun nextBigIntegers(n: Int) = Array(n) { nextBigInteger() }\n fun nextBigDecimals(n: Int) = Array(n) { nextBigDecimal() }\n\n fun nextStrings(n: Int, m: Int) = Array(n) { nextStrings(m) }\n fun nextInts(n: Int, m: Int) = Array(n) { nextInts(m) }\n fun nextLongs(n: Int, m: Int) = Array(n) { nextLongs(m) }\n fun nextDoubles(n: Int, m: Int) = Array(n) { nextDoubles(m) }\n fun nextBigIntegers(n: Int, m: Int) = Array(n) { nextBigIntegers(m) }\n fun nextBigDecimals(n: Int, m: Int) = Array(n) { nextBigDecimals(m) }\n\n private fun skipWhitespace(): Int {\n while (true) {\n val c = read()\n if (c > ' '.toInt() || c < 0) return c\n }\n }\n\n private fun read(): Int {\n while (pos >= size) {\n if (size < 0) return -1\n size = input.read(buffer, 0, buffer.size)\n pos = 0\n }\n return buffer[pos++].toInt()\n }\n}\n", "src_uid": "c9c22e03c70a94a745b451fc79e112fd"} {"source_code": "import java.util.Scanner;\n\nfun main(args: Array) {\n var scan = Scanner(System.`in`);\n\n var n = scan.nextInt();\n var s = IntArray(n);\n for (i in 0 until n) {\n s[i] = scan.nextInt();\n }\n\n var other = IntArray(n);\n var best = IntArray(n);\n best[n-1] = s[n-1];\n other[n-1] = 0;\n for (i in (n-2) downTo 0) {\n var takethis = s[i] + other[i+1];\n var givethis = best[i+1];\n if (takethis > givethis) {\n best[i] = takethis;\n other[i] = givethis;\n } else {\n best[i] = givethis;\n other[i] = takethis;\n }\n }\n System.out.printf(\"%d %d\\n\", other[0], best[0]);\n}", "src_uid": "414540223db9d4cfcec6a973179a0216"} {"source_code": "fun main() {\n val firstArr = readLine()!!.toCharArray().map { it.toInt() }\n val secArr = readLine()!!.toCharArray().map { it.toInt() }\n val result: MutableList = mutableListOf()\n\n for (i in 0 until firstArr.size) {\n if (firstArr[i] != secArr[i]) {\n result.add(\"1\")\n } else {\n result.add(\"0\")\n }\n }\n print(result.toString().removePrefix(\"[\").removeSuffix(\"]\").replace(\", \", \"\"))\n}", "src_uid": "3714b7596a6b48ca5b7a346f60d90549"} {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\nimport java.util.TreeMap\nimport java.util.TreeSet\nimport java.util.ArrayDeque\nimport java.util.PriorityQueue\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.system.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln // immediate println for interactive\n\nfun main() {\n output {\n val n = readInt()\n val A = readIntArray(n)\n\n val pos = A.count { it > 0 }\n val neg = A.count { it < 0 }\n val quota = (n+1) / 2\n\n val ans = when {\n pos >= quota -> 1\n neg >= quota -> -1\n else -> 0\n }\n\n println(ans)\n }\n}\n\n/** IO code start */\n@JvmField val _reader = System.`in`.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(System.out, false)\ninline fun output(block: PrintWriter.()->Unit) { _writer.apply(block).flush() }\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun R._shuffle(rnd: Random, get: R.(Int) -> V, set: R.(Int, V) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, IntArray::get, IntArray::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, LongArray::get, LongArray::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, DoubleArray::get, DoubleArray::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, CharArray::get, CharArray::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()", "src_uid": "a13cb35197f896cd34614c6c0b369a49"} {"source_code": "import kotlin.math.log10\nfun ffff(d : Int):Long\n{\n var s = 0L\n var d2 = d\n while(d2>0){\n s += Math.pow(10.0,(d2-1L).toDouble()).toLong()*9\n d2--\n }\n return s\n}\nfun main(args: Array) {\n val n = readLine()!!.toLong()\n val bas = log10(n.toDouble()).toInt() + 1\n //println(bas)\n val s1 = ffff(bas-1)\n var s2 = n-s1\n var t = 0\n //println(s2)\n while (s2>0)\n {\n t+=(s2 % 10L).toInt()\n s2/=10L\n }\n t += 9*(bas-1)\n println(t)\n}", "src_uid": "5c61b4a4728070b9de49d72831cd2329"} {"source_code": "\r\n\r\nimport java.io.PrintWriter\r\nimport java.util.Stack\r\nimport java.util.StringTokenizer\r\nimport kotlin.math.abs\r\nimport kotlin.math.max\r\nimport kotlin.math.min\r\n\r\nfun solveOneTask() {\r\n var my = readInt() - 1\r\n val a = readInts(3).map { it - 1 }.toMutableList()\r\n for (i in 0 until 2) {\r\n if (a[my] == -1) {\r\n println(\"NO\")\r\n return\r\n }\r\n val tmp = a[my]\r\n a[my] = -1\r\n my = tmp\r\n }\r\n println(\"YES\")\r\n\r\n}\r\n\r\nfun main() {\r\n val t = readInt()\r\n repeat(t) {\r\n solveOneTask()\r\n }\r\n}\r\n\r\nfun binarySearch(list: List, value: Int): Int {\r\n var l = -1\r\n var r = list.size\r\n while (r - l > 1) {\r\n val m = (l + r) ushr 1\r\n if (list[m] < value) l = m\r\n else r = m\r\n }\r\n return r\r\n}\r\n\r\nfun nextGreaterElement(list: List): List {\r\n\r\n if (list.isEmpty()) return emptyList()\r\n val stack = Stack>()\r\n stack.push(Pair(list.first(), 0))\r\n val result = MutableList(list.size) { list.size }\r\n for (i in 1 until list.size) {\r\n var prev = stack.peek()\r\n val cur = list[i]\r\n while (prev.first < cur && stack.isNotEmpty()) {\r\n result[prev.second] = i\r\n stack.pop()\r\n if (stack.isNotEmpty()) prev = stack.peek()\r\n }\r\n stack.push(Pair(cur, i))\r\n }\r\n return result\r\n}\r\n\r\ntypealias Number = Long\r\n\r\nfun segmentTreeFunction(a: Number, b: Number): Number = max(a, b)\r\n\r\nfun buildSegmentTree(elements: List): SegmentTreeNode {\r\n val leafs = elements.mapIndexed { ind, it ->\r\n SegmentTreeNode(it, null, ind, ind)\r\n }\r\n var curLevel = leafs\r\n while (curLevel.size > 1) {\r\n val nextLevel = mutableListOf()\r\n for (i in curLevel.indices step 2) {\r\n val node = if (i + 1 < curLevel.size) {\r\n SegmentTreeNode(\r\n segmentTreeFunction(curLevel[i].element, curLevel[i + 1].element),\r\n listOf(curLevel[i], curLevel[i + 1]),\r\n curLevel[i].start,\r\n curLevel[i + 1].finish\r\n )\r\n } else {\r\n SegmentTreeNode(\r\n curLevel[i].element, listOf(curLevel[i]), curLevel[i].start, curLevel[i].finish\r\n )\r\n }\r\n nextLevel.add(node)\r\n }\r\n curLevel = nextLevel\r\n }\r\n return curLevel.first()\r\n}\r\n\r\nclass SegmentTreeNode\r\n (\r\n val element: Number, val children: List? = null, val start: Int, val finish: Int\r\n) {\r\n fun query(l: Int, r: Int): Number {\r\n if (l == start && r == finish) {\r\n return element\r\n }\r\n val left = children!!.first()\r\n if (r <= left.finish) {\r\n return left.query(l, r)\r\n }\r\n val right = children[1]\r\n if (l >= right.start) {\r\n return right.query(l, r)\r\n }\r\n return segmentTreeFunction(left.query(l, left.finish), right.query(right.start, r))\r\n }\r\n}\r\n\r\nfun prefSums(base: Iterable): List {\r\n val prefSums = base.toMutableList()\r\n for (i in 1 until prefSums.size) {\r\n prefSums[i] += prefSums[i - 1]\r\n }\r\n return prefSums\r\n}\r\n\r\n\r\nfun gcd(a: Long, b: Long): Long {\r\n if (a == 0L) return b\r\n return gcd(b % a, a)\r\n}\r\n\r\n/**\r\n * least common multiply\r\n */\r\nfun lcm(a: Long, b: Long): Long {\r\n return abs(a.toLong() * b.toLong()) / gcd(a, b).toLong()\r\n}\r\n\r\nval primes by lazy { generatePrimes(2 * 1000_000).toSet() }\r\n\r\n\r\nfun factorize(x: Int): MutableMap {\r\n val mp = mutableMapOf()\r\n var xx = x\r\n\r\n for (prime in primes) {\r\n var count = 0\r\n while (xx % prime == 0) {\r\n xx /= prime\r\n count++\r\n }\r\n if (count > 0) {\r\n mp[prime] = count\r\n }\r\n if (primes.contains(xx)) {\r\n mp[xx] = 1\r\n break\r\n }\r\n }\r\n return mp\r\n\r\n}\r\n\r\n\r\nfun generatePrimes(n: Int): List {\r\n val prime = Array(n + 1) { true }\r\n var p = 2\r\n while (p * p <= n) {\r\n if (prime[p]) {\r\n var i = p * p\r\n while (i <= n) {\r\n prime[i] = false\r\n i += p\r\n }\r\n }\r\n p++\r\n }\r\n return (2..n).filter { prime[it] }\r\n}\r\n\r\n@JvmField\r\nval INPUT = System.`in`\r\n\r\n@JvmField\r\nval OUTPUT = System.out\r\n\r\n@JvmField\r\nval _reader = INPUT.bufferedReader()\r\n\r\nfun readLine(): String = _reader.readLine()!!\r\nfun readLn(): String? = _reader.readLine()\r\n\r\n@JvmField\r\nvar _tokenizer: StringTokenizer = StringTokenizer(\"\")\r\n\r\nfun read(): String {\r\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\r\n return _tokenizer.nextToken()\r\n}\r\n\r\nfun readInt() = read().toInt()\r\nfun readDouble() = read().toDouble()\r\nfun readLong() = read().toLong()\r\nfun readStrings(n: Int) = List(n) { read() }\r\nfun readLines(n: Int) = List(n) { readLn() }\r\nfun readInts(n: Int) = MutableList(n) { read().toInt() }\r\n\r\n//fun readIntArray(n: Int) = IntArray(n) { read().toInt() }\r\nfun readDoubles(n: Int) = MutableList(n) { read().toDouble() }\r\n\r\n//fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\r\nfun readLongs(n: Int) = MutableList(n) { read().toLong() }\r\n//fun readLongArray(n: Int) = LongArray(n) { read().toLong() }\r\n\r\n@JvmField\r\nval _writer = PrintWriter(OUTPUT, false)\r\n\r\ninline fun output(block: PrintWriter.() -> Unit) {\r\n _writer.apply(block).flush()\r\n}", "src_uid": "5cd113a30bbbb93d8620a483d4da0349"} {"source_code": "fun main() {\n val l = readLine()!!.length\n print(26 * (l + 1) - l)\n}", "src_uid": "556684d96d78264ad07c0cdd3b784bc9"} {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.InputStream\nimport java.util.*\n\nprivate class FScanner internal constructor(inputStream: InputStream = System.`in`) {\n internal val br = BufferedReader(InputStreamReader(inputStream))\n internal var st = StringTokenizer(\"\")\n\n internal fun hasNext(): Boolean {\n while (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine() ?: return false)\n return true\n }\n\n internal operator fun next() =\n if (hasNext()) st.nextToken()!!\n else throw RuntimeException(\"No tokens\")\n\n internal fun nextInt() = next().toInt()\n\n internal fun nextLong() = next().toLong()\n\n internal fun nextLine() =\n if (hasNext()) st.nextToken(\"\\n\")\n else throw RuntimeException(\"No tokens\")\n\n internal fun nextIntArray(n: Int) = IntArray(n, { nextInt() })\n\n internal fun nextLongArray(n: Int) = LongArray(n, { nextLong() })\n}\n\n\nfun main(args: Array) {\n val sc = FScanner()\n val n = sc.nextInt()\n val s = sc.nextLine()\n val b = sc.nextIntArray(n)\n\n val rev = PriorityQueue>(compareBy { it.second })\n var sum = b.sum()\n\n val remChar = IntArray(26)\n (0 until n / 2).forEach {\n val inv = n - it - 1\n if (s[it] == s[inv]) {\n// println(\"${s[it]} - ${b[it]} - ${b[n - it - 1]}\")\n if (b[it] < b[inv]) {\n remChar[s[it].toByte() - 'a'.toByte()]++\n// rev += Triple(s[inv], b[inv], s[it])\n sum -= b[it]\n } else {\n remChar[s[inv].toByte() - 'a'.toByte()]++\n// rev += Triple(s[it], b[it], s[inv])\n sum -= b[inv]\n }\n } else {\n rev += Triple(s[it], b[it], s[inv])\n rev += Triple(s[inv], b[inv], s[it])\n }\n }\n\n val remStat = PriorityQueue>(compareBy> { -it.second })\n remChar\n .forEachIndexed { index, i ->\n if (i > 0) {\n remStat += Pair((index + 'a'.toByte()).toChar(), i)\n }\n }\n\n// println(remStat.joinToString(\" \"))\n// println(sum)\n\n if (remStat.isNotEmpty()) {\n var x = remStat.poll()\n var oldx = x.first\n var xleft = x.second\n while (remStat.isNotEmpty()) {\n val y = remStat.poll()\n if (y.second <= xleft) {\n xleft -= y.second\n } else {\n xleft = y.second - xleft\n x = y\n }\n }\n// println(\"Need remove ${x.first} $xleft\")\n// println(rev.joinToString(\" \"))\n\n //find different x\n while (xleft > 0 && x.first == oldx) {\n val re = rev.poll()\n if (re.first != x.first && re.third != x.first) {\n// println(\"Remove $re\")\n xleft--\n sum -= re.second\n }\n }\n }\n \n println(sum)\n}\n\n", "src_uid": "896555ddb6e1c268cd7b3b6b063fce50"} {"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}", "src_uid": "a06ebb2734365ec97d07cd1b6b3faeed"} {"source_code": "import java.util.*\nimport kotlin.math.abs\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val a = nextInt()\n val b = nextInt()\n var res = IntArray(3)\n repeat(6) {\n when {\n abs(a - (it + 1)) < abs(b - (it + 1)) -> res[0]++\n abs(a - (it + 1)) > abs(b - (it + 1)) -> res[2]++\n else -> res[1]++\n }\n }\n res.forEach { s -> print(\"$s \") }\n}", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8"} {"source_code": "fun main() {\r\n\tval (n, m) = readInts()\r\n\tModular.M = m\r\n\tval primeDivisors = primeDivisors(n)\r\n\tval diff = Array(n + 1) { 1.toModular() }\r\n\tvar aLast = 2.toModular()\r\n\tfor (i in 3..n) {\r\n\t\tdiff[i] = 1 + aLast\r\n\t\tfor (r in divisorsOf(i, primeDivisors)) {\r\n\t\t\tif (r == 1 || r == i) continue\r\n\t\t\tdiff[i] += diff[r]\r\n\t\t}\r\n\t\taLast += diff[i]\r\n\t}\r\n\tprintln(aLast)\r\n}\r\n\r\nfun divisorsOf(n: Int, primeDivisors: IntArray): IntArray {\r\n\tif (n == 1) return intArrayOf(1)\r\n\tval p = primeDivisors[n]\r\n\tvar m = n / p\r\n\tvar count = 1\r\n\twhile (m % p == 0) {\r\n\t\tm /= p\r\n\t\tcount++\r\n\t}\r\n\tval that = divisorsOf(m, primeDivisors)\r\n\tval result = IntArray(that.size * (count + 1))\r\n\tfor (i in that.indices) {\r\n\t\tvar d = that[i]\r\n\t\tfor (j in 0..count) {\r\n\t\t\tresult[i * (count + 1) + j] = d\r\n\t\t\td *= p\r\n\t\t}\r\n\t}\r\n\treturn result\r\n}\r\n\r\nfun primeDivisors(n: Int): IntArray {\r\n\tval primeDivisors = IntArray(n + 1) { it }\r\n\tfor (i in 2..n) {\r\n\t\tif (primeDivisors[i] < i) continue\r\n\t\tvar j = i * i\r\n\t\tif (j > n) break\r\n\t\tdo {\r\n\t\t\tprimeDivisors[j] = i\r\n\t\t\tj += i\r\n\t\t} while (j <= n)\r\n\t}\r\n\treturn primeDivisors\r\n}\r\n\r\nfun Int.toModular() = Modular(this)//toDouble()\r\nclass Modular {\r\n\tcompanion object {\r\n\t\tvar M: Int = 0\r\n\t}\r\n\tval x: Int\r\n\t@Suppress(\"ConvertSecondaryConstructorToPrimary\")\r\n\tconstructor(value: Int) { x = (value % M).let { if (it < 0) it + M else it } }\r\n\toperator fun plus(that: Modular) = Modular((x + that.x) % M)\r\n\toperator fun minus(that: Modular) = Modular((x + M - that.x) % M)\r\n\toperator fun times(that: Modular) = (x.toLong() * that.x % M).toInt().toModular()\r\n\tfun modInverse() = Modular(x.toBigInteger().modInverse(M.toBigInteger()).toInt())\r\n\toperator fun div(that: Modular) = times(that.modInverse())\r\n\toverride fun toString() = x.toString()\r\n}\r\noperator fun Int.plus(that: Modular) = Modular(this) + that\r\noperator fun Int.minus(that: Modular) = Modular(this) - that\r\noperator fun Int.times(that: Modular) = Modular(this) * that\r\noperator fun Int.div(that: Modular) = Modular(this) / that\r\n\r\nprivate fun readLn() = readLine()!!\r\nprivate fun readInt() = readLn().toInt()\r\nprivate fun readStrings() = readLn().split(\" \")\r\nprivate fun readInts() = readStrings().map { it.toInt() }\r\n", "src_uid": "77443424be253352aaf2b6c89bdd4671"} {"source_code": "fun main(args: Array) {\n val data = readLine()?.split(\" \")?.map { it.toLong() } ?: return\n\n val flatCount = data[0]\n val neighborCount = data[1]\n\n val min = if (flatCount == neighborCount || neighborCount == 0L) 0 else 1\n val max = when {\n flatCount <= neighborCount * 3 -> flatCount - neighborCount\n else -> (neighborCount) * 2\n }\n\n println(\"$min $max\")\n}", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86"} {"source_code": "import java.io.InputStream\n\nval input = FastScanner()\n\nfun main(args: Array) = input.run {\n val m = nextInt()\n val b = nextInt()\n\n var ans = 0L\n\n (0..b).forEach { y ->\n val x = (b - y) * m\n var acc = 0L\n (0..y).forEach { yy ->\n acc += (x + 1) * yy.toLong() + x * (x + 1L) / 2\n }\n ans = ans.coerceAtLeast(acc)\n }\n\n println(ans)\n}\n\nclass FastScanner(private val input: InputStream = System.`in`) {\n private val sb = StringBuilder()\n private val buffer = ByteArray(4096)\n private var pos = 0\n private var size = 0\n\n fun nextLong(): Long {\n var c = skipWhitespace()\n\n val sign = if (c == '-'.toInt()) {\n c = read()\n -1\n } else 1\n\n var ans = 0L\n\n while (c > ' '.toInt()) {\n ans = ans * 10 + c - '0'.toInt()\n c = read()\n }\n\n return sign * ans\n }\n\n fun nextInt() = nextLong().toInt()\n\n private fun skipWhitespace(): Int {\n while (true) {\n val c = read()\n if (c > ' '.toInt() || c < 0) return c\n }\n }\n\n private fun read(): Int {\n while (pos >= size) {\n if (size < 0) return -1\n size = input.read(buffer, 0, buffer.size)\n pos = 0\n }\n return buffer[pos++].toInt()\n }\n}", "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2"} {"source_code": "fun main() {\n val n = readInt()\n\n val points = List(4*n + 1) { readInts().let { (x, y) -> Point(x, y) } }\n\n val xcnt = points.groupingBy { it.x }.eachCount()\n val ycnt = points.groupingBy { it.y }.eachCount()\n\n fun Map.squareBoundaries() = run {\n val f = keys.filter {\n this[it]!! >= n\n }\n listOf(f.min()!!, f.max()!!)\n }\n\n val xb = xcnt.squareBoundaries()\n val yb = ycnt.squareBoundaries()\n\n val ans = points.first {\n when {\n it.x in xb -> it.y in yb[0]..yb[1]\n it.y in yb -> it.x in xb[0]..xb[1]\n else -> false\n }.not()\n }\n\n println(\"${ans.x} ${ans.y}\")\n}\n\ndata class Point(val x: Int, val y: Int)\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit)\n { Output().apply(block).nowPrint() }\n", "src_uid": "1f9153088dcba9383b1a2dbe592e4d06"} {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\nfun main(args:Array) {\n val sc: Scanner = Scanner(System.`in`)\n val k = sc.nextInt()\n var x =0\n val r = sc.nextInt()\n for(i in 1..9)\n if(k*i%10==0||k*i%10==r) {\n println(i)\n break\n }\n}\n", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3"} {"source_code": "import java.io.*\nimport java.util.StringTokenizer\n\nval err = System.err\nval bf = BufferedReader(InputStreamReader(System.`in`))\nvar st = StringTokenizer(\"\")\n\nfun nxtstring(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(bf.readLine())\n return st.nextToken()\n}\n\nfun nxtint() = nxtstring().toInt()\n\nvar n: Long = 0\nval p10 = LongArray(11)\n\nfun findmax9(): Int {\n var ans = 0\n var num = 0L\n while (true) {\n val ldn = n / p10[ans] % 10\n val od = 9 - ldn\n num += p10[ans] * od\n if (num > n) break\n ++ans\n }\n return ans\n}\n\nfun main(args: Array) {\n n = nxtint().toLong()\n p10[0] = 1\n for (i in 1..10) p10[i] = p10[i - 1] * 10\n val max9 = findmax9()\n if (max9 == 0) {\n println(n * (n - 1) / 2)\n return\n }\n var t = 0\n var ans = 0L\n while (true) {\n var num = p10[max9] * t + p10[max9] - 1\n ++t\n var l = 1\n var r = n.toInt()\n while (l < r) {\n var mid: Int = l + (r - l) / 2\n if (num - mid > n) l = mid + 1\n else r = mid\n }\n //err.printf(\"%d %d\\n\", num, l)\n if (num - l <= l || num - l > n) break\n val cnt: Long = num - l - l + 1\n ans += cnt / 2\n }\n println(ans)\n}\n", "src_uid": "c20744c44269ae0779c5f549afd2e3f2"} {"source_code": "import kotlin.text.*\r\nprivate fun readLn() = readLine()!! // string line\r\nprivate fun readInt() = readLn().toInt() // single int\r\nprivate fun readStrings() = readLn().split(\" \") // list of strings\r\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\r\nprivate fun readLong() = readLn().toLong() // single long\r\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\r\n\r\nconst val MOD = 998244353\r\nconst val INF = (1e18).toLong()\r\n\r\nfun YN(b: Boolean) : String { return if (b) \"YES\" else \"NO\" }\r\nfun add(a: Int, b: Int): Int {\r\n var v = a+b\r\n if (v>=MOD) v-=MOD\r\n return v\r\n}\r\nfun sub(a: Int, b: Int): Int {\r\n var v = a-b\r\n if (v<0) v+=MOD\r\n return v\r\n}\r\nfun mul(a: Int, b: Int) = ((a.toLong()*b.toLong())%MOD.toLong()).toInt()\r\nfun gcd(a: Int, b: Int) : Int = if (b == 0) a else gcd(b,a%b)\r\nfun min(x: Int, y :Int) :Int = if(x>y) y else x\r\nfun max(x: Int, y :Int) :Int = if(x IntArray(26){-1}})\r\n var isend = Array(max, {i -> IntArray(26){-1}})\r\n fun getNext(cur: Int, v:Int):Int{\r\n return next[cur][v]\r\n }\r\n var ss = Array(n, {readLn()})\r\n for(i in 0..n-1){\r\n var s = ss[i]\r\n var cur:Int = 0\r\n var l = s.length\r\n if(l > 1) for(c in 0..l-2){\r\n var v = s[c].toByte().toInt()-'a'.toByte().toInt()\r\n if (next[cur][v] == -1) next[cur][v] = sz++\r\n cur = next[cur][v]\r\n } \r\n var v = s[l-1].toByte().toInt()-'a'.toByte().toInt()\r\n isend[cur][v] = 0\r\n }\r\n val L = 6\r\n var mat = Array(L*sz, {IntArray(L*sz, {0})})\r\n for(l in 1..L-1) for(a in 0..sz-1) mat[a+l*sz][a+(l-1)*sz] = 1\r\n for(a in 0..sz-1) for(ind in 0..n-1){\r\n var s = ss[ind]\r\n var l = s.length\r\n var dp = Array(l+1, {IntArray(sz, {0})})\r\n dp[0][a] = 1\r\n for(i in 0..l-1){\r\n var v = s[i].toByte().toInt()-'a'.toByte().toInt()\r\n for(cur in 0..sz-1){\r\n if (next[cur][v]!=-1) dp[i+1][next[cur][v]] += dp[i][cur]\r\n if (isend[cur][v]!=-1) dp[i+1][0] += dp[i][cur]\r\n }\r\n }\r\n for(cur in 0..sz-1) mat[a][cur+(l-1)*sz] += dp[l][cur]\r\n }\r\n //for(i in 0..sz*sz-1) println(mat[i].joinToString(\" \"))\r\n fun mul(A:Array, B:Array): Array{\r\n var n = A.size\r\n var C = Array(n, {i -> IntArray(n, {j -> 0})})\r\n for(i in 0..n-1) for(k in 0..n-1) if(A[i][k]!=0) for(j in 0..n-1) if(B[k][j]!=0){\r\n C[i][j] = add(C[i][j], mul(A[i][k], B[k][j]))\r\n }\r\n return C\r\n }\r\n \r\n var SZ = mat.size\r\n var ans = Array(SZ, {i -> IntArray(SZ, {j -> (if (i == j) 1 else 0) })})\r\n while(m>0){\r\n if (m%2==1){\r\n ans = mul(ans, mat)\r\n }\r\n m /= 2\r\n mat = mul(mat, mat)\r\n }\r\n println(ans[0][0])\r\n \r\n \r\n // for(i in 1..t){\r\n // var (a,b) = readInts()\r\n // println(a+b)\r\n // }\r\n\r\n// var qur = Array(q, {i -> Pair(-1, -1)})\r\n// var dec = IntArray(n+1){INF}\r\n// var inds = LongArray(n+1){-1}\r\n// var qq = qur.sortedWith(compareBy({ it.second }, { it.first }))\r\n// for(i in qur.indices){\r\n// val p = readInts()\r\n// qur[i] = Pair(i, p[1]-1)\r\n// st[i] = p[0] - 1\r\n// }\r\n \r\n\r\n \r\n \r\n\r\n// println(ans.joinToString(\" \"))\r\n\r\n}", "src_uid": "711d15e11016d0164fb2b0c3756e4857"} {"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\n\nfun main(args: Array) {\n val (n,k)=readLongs()\n if (k<=(n+1)/2) {\n println(k*2-1)\n } else {\n println(2*(k-(n+1)/2))\n }\n}", "src_uid": "1f8056884db00ad8294a7cc0be75fe97"} {"source_code": "fun main() {\n val req = listOf(FISH, FISH, RABBIT, CHICKEN, FISH, CHICKEN, RABBIT)\n val reqcnt = req.groupingBy { it }.eachCount()\n\n val pack = readLongSeq().toMutableList()\n\n val weeks = pack.indices.asSequence().map { pack[it] / reqcnt[it]!! }.min()!!\n\n for(i in pack.indices) pack[i] -= weeks * reqcnt[i]!!\n\n val rem = req.indices.asSequence().map { i ->\n val pack1 = pack.toMutableList()\n\n var res = 0\n\n for(j in req.indices) {\n val k = req[(i + j) % 7]\n pack1[k]--\n if(pack1[k] < 0) break\n res++\n }\n\n res\n }.max()!!\n\n val ans = weeks * 7 + rem\n\n println(ans)\n}\n\nconst val FISH = 0\nconst val RABBIT = 1\nconst val CHICKEN = 2\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readStringSeq() = readLn().splitToSequence(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readIntSeq() = readStringSeq().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readDoubleSeq() = readStringSeq().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\nfun readLongSeq() = readStringSeq().map { it.toLong() }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit) { Output().apply(block).nowPrint() }", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb"} {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n val percent = ModInt(100).inverse()\n\n val n = readInt()\n val pipes = List(n) { Pipe(readInt(), readInt(), percent * readInt()) }\n val tree = SegmentTree(n, null, nullIdentityCombiner(Seg::plus))\n\n tree.build { i ->\n Seg(\n ll = 1 - pipes[i].p,\n lr = ModInt(0),\n rl = ModInt(0),\n rr = pipes[i].p,\n ban = NONE\n )\n }\n\n val cols = ArrayList(n-1 shl 1)\n\n for(i in 0 until n-1) {\n val a = pipes[i]\n val b = pipes[i+1]\n\n val d = b.x - a.x\n cols.add(Collision(i, RL, d, a.v + b.v))\n if(a.v > b.v) cols.add(Collision(i, RR, d, a.v - b.v))\n else if(a.v < b.v) cols.add(Collision(i, LL, d, b.v - a.v))\n }\n\n cols.sortWith(Collision.comparator)\n\n val vi = ModIntArray(cols.size) { ModInt(cols[it].v) }.inverseOfEach()\n var currProb = ModInt(1)\n var ans = ModInt(0)\n for(i in cols.indices) {\n val (a, t, d) = cols[i]\n tree[a] = tree[a]!!.copy(ban = t)\n val prob = tree.root!!.sum\n ans += (currProb - prob) * d * vi[i]\n currProb = prob\n }\n\n println(ans.int)\n}\n\ndata class Pipe(val x: Int, val v: Int, val p: ModInt)\ndata class Collision(val a: Int, val type: CollisionType, val d: Int, val v: Int) {\n companion object {\n val comparator = Comparator { a, b ->\n (a.d.toLong() * b.v).compareTo(b.d.toLong() * a.v)\n }\n }\n}\n\ntypealias CollisionType = Byte\nconst val NONE: CollisionType = 0\nconst val LL: CollisionType = 1\nconst val RL: CollisionType = 2\nconst val RR: CollisionType = 3\n\ndata class Seg(val ll: ModInt, val lr: ModInt, val rl: ModInt, val rr: ModInt, val ban: CollisionType) {\n val sum get() = ll + lr + rl + rr\n\n operator fun plus(b: Seg): Seg {\n // LR never banned\n var cll = ll * b.rl\n var clr = ll * b.rr\n var crl = rl * b.rl\n var crr = rl * b.rr\n\n // any ban implies RL banned\n if(ban == NONE) {\n cll += lr * b.ll\n clr += lr * b.lr\n crl += rr * b.ll\n crr += rr * b.lr\n }\n\n if(ban != LL) {\n cll += ll * b.ll\n clr += ll * b.lr\n crl += rl * b.ll\n crr += rl * b.lr\n }\n\n if(ban != RR) {\n cll += lr * b.rl\n clr += lr * b.rr\n crl += rr * b.rl\n crr += rr * b.rr\n }\n\n return Seg(cll, clr, crl, crr, b.ban)\n }\n}\n\nclass SegmentTree(\n val size: Int,\n val identityValue: T,\n val combiner: (T, T) -> T) {\n\n private val tsize get() = if(size <= 1) size else Integer.highestOneBit(size - 1) shl 1\n\n /* degenericization helpers\n val identityValue: T = TODO()\n fun combiner(a: T, b: T): T = TODO()\n */\n\n @Suppress(\"UNCHECKED_CAST\")\n private val array = Array(tsize shl 1) { identityValue } as Array\n\n val root get() = array[1]\n\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n val asList: List by lazy {\n object : AbstractList() {\n override val size: Int get() = this@SegmentTree.size\n override fun get(index: Int): T = this@SegmentTree[index]\n }\n }\n\n fun build(generator: (Int) -> T) {\n for(i in 0 until size) {\n array[i + tsize] = generator(i)\n }\n for(i in tsize-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** instantiates values from an iterable, O(n) time */\n fun copyFrom(iterable: Iterable) {\n run {\n iterable.forEachIndexed { i, t ->\n if(i > lastIndex) return@run\n array[i + tsize] = t\n }\n }\n for(i in tsize-1 downTo 1) {\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Updates a value, O(log n) time */\n operator fun set(index: Int, value: T) {\n require(index in 0 until size)\n var i = index + tsize\n array[i] = value\n while(true) {\n i = i shr 1\n if(i <= 0) break\n array[i] = combiner(array[i shl 1], array[i shl 1 or 1])\n }\n }\n\n /** Gets a value by its index, O(1) time */\n operator fun get(index: Int): T {\n require(index in 0 until size)\n return array[index + tsize]\n }\n\n /** gets the result of applying the monoid operation to the values in the index range, O(log n) time */\n operator fun get(start: Int, endExclusive: Int): T {\n var l = maxOf(start, 0) + tsize\n var r = minOf(endExclusive, size) + tsize\n\n // two accumulators to support non-commutative monoids\n var lAcc = identityValue\n var rAcc = identityValue\n\n while(l < r) {\n if(l and 1 == 1) {\n lAcc = combiner(lAcc, array[l++])\n }\n if(r and 1 == 1) {\n rAcc = combiner(array[--r], rAcc)\n }\n\n l = l shr 1\n r = r shr 1\n }\n\n return combiner(lAcc, rAcc)\n }\n\n operator fun get(range: IntRange) = get(range.first, range.last + 1)\n}\n\n/** Converts a semigroup to a monoid by using null as the identity value. */\ninline fun nullIdentityCombiner(crossinline combiner: (T, T) -> T): (T?, T?) -> T? = { a, b ->\n when {\n a == null -> b\n b == null -> a\n else -> combiner(a, b)\n }\n}\n\nfun ModIntArray.inverseOfEach(): ModIntArray {\n if(isEmpty()) return this\n var acc = ModInt(1)\n val res = ModIntArray(size) { i ->\n acc *= this[i]\n acc\n }\n acc = res[lastIndex].inv_unmemoized()\n for(i in lastIndex downTo 1) {\n res[i] = acc * res[i-1]\n acc *= this[i]\n }\n res[0] = acc\n\n return res\n}\n\nconst val MOD = 998244353\nconst val TOTIENT = MOD - 1 // assumes MOD is prime\n\ninfix fun Int.umod(mod: Int): Int = (this % mod).let { (it shr Int.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Long) = (this % mod).let { (it shr Long.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Int) = umod(mod.toLong()).toInt()\n\nfun Int.mulMod(other: Int, mod: Int) = toLong() * other umod mod\n\nfun Int.powMod(exponent: Int, mod: Int): Int {\n if(exponent < 0) error(\"Inverse not implemented\")\n var res = 1L\n var e = exponent\n var b = umod(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\n\ninline fun Int.toModInt() = ModInt(this umod MOD)\ninline fun Long.toModInt() = ModInt(this umod MOD)\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n companion object {\n /** can't seem to make these private or inlined without causing compiler issues */\n @JvmField val _invMemo = HashMap()\n fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }\n }\n\n // normalizes an integer that's within range [-MOD, MOD) without branching\n private inline fun normalize(int: Int) = ModInt((int shr Int.SIZE_BITS - 1 and MOD) + int)\n\n operator fun plus(other: ModInt) = normalize(int + other.int - MOD) // overflow-safe even if MOD >= 2^30\n inline operator fun plus(other: Int) = plus(other.toModInt())\n operator fun inc() = normalize(int + (1 - MOD))\n\n operator fun minus(other: ModInt) = normalize(int - other.int)\n inline operator fun minus(other: Int) = minus(other.toModInt())\n operator fun dec() = normalize(int - 1)\n operator fun unaryMinus() = normalize(-int)\n\n operator fun times(other: ModInt) = ModInt((int.toLong() * other.int % MOD).toInt())\n inline operator fun times(other: Int) = ModInt(int.mulMod(other, MOD))\n\n fun pow(exponent: Int): ModInt {\n val e = if(exponent < 0) {\n require(int != 0) { \"Can't invert/divide by 0\" }\n exponent umod TOTIENT\n } else exponent\n return ModInt(int.powMod(e, MOD))\n }\n\n fun pow(exponent: Long) = if(int == 0) when {\n exponent > 0 -> this\n exponent == 0L -> ModInt(1)\n else -> error(\"Can't invert/divide by 0\")\n } else pow(exponent umod TOTIENT)\n\n inline fun inverse() = inv_memoized() /** NOTE: Change if necessary */\n\n fun inv_unmemoized(): ModInt {\n require(int != 0) { \"Can't invert/divide by 0\" }\n return pow(TOTIENT - 1)\n }\n inline fun inv_memoized() = _invMemoized(this)\n\n operator fun div(other: ModInt) = times(other.inverse())\n inline operator fun div(other: Int) = div(other.toModInt())\n\n override inline fun toString() = int.toString()\n}\n\ninline operator fun Int.plus(modInt: ModInt) = modInt + this\ninline operator fun Int.minus(modInt: ModInt) = toModInt() - modInt\ninline operator fun Int.times(modInt: ModInt) = modInt * this\ninline operator fun Int.div(modInt: ModInt) = modInt.inverse() * this\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n inline operator fun get(i: Int) = ModInt(intArray[i])\n inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override inline val size: Int get() = intArray.size\n inline val lastIndex get() = intArray.lastIndex\n inline val indices get() = intArray.indices\n\n override inline fun contains(element: ModInt): Boolean = element.int in intArray\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override inline fun isEmpty(): Boolean = intArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): ModInt = get(index++)\n }\n\n fun copyOf(newSize: Int) = ModIntArray(intArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun ModIntArray.copyInto(destination: ModIntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =\n ModIntArray(intArray.copyInto(destination.intArray, destinationOffset, startIndex, endIndex))\ninline fun ModIntArray(size: Int) = ModIntArray(IntArray(size))\ninline fun ModIntArray(size: Int, init: (Int) -> ModInt) = ModIntArray(IntArray(size) { init(it).int })\n\ninline fun ModIntArray.first() = get(0)\ninline fun ModIntArray.last() = get(lastIndex)\ninline fun ModIntArray.fold(init: R, op: (acc: R, ModInt) -> R) = intArray.fold(init) { acc, i -> op(acc, ModInt(i)) }\nfun ModIntArray.sum() = fold(ModInt(0), ModInt::plus)\nfun ModIntArray.product() = fold(ModInt(1), ModInt::times)\n\ninline fun Iterable.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Iterable.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\ninline fun Sequence.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Sequence.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\nfun Iterable.sum() = sumByModInt { it }\nfun Sequence.sum() = sumByModInt { it }\nfun Iterable.product() = productByModInt { it }\nfun Sequence.product() = productByModInt { it }\nfun Collection.toModIntArray() = ModIntArray(size).also { var i = 0; for(e in this) { it[i++] = e } }\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n//@JvmField var _random: Random? = null\nval random = Random(0x594E215C123 * System.nanoTime())\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}", "src_uid": "37bb4fe5f6cc2a173e97c033c6fde8c7"} {"source_code": "// 2022.07.31 at 20:35:58 HKT\r\nimport java.io.BufferedInputStream\r\nimport java.io.File\r\nimport java.io.PrintWriter\r\nimport kotlin.system.measureTimeMillis\r\nimport java.util.TreeMap\r\nimport java.util.TreeSet\r\nimport kotlin.random.Random\r\nimport kotlin.random.nextInt\r\n\r\n// 1. Modded\r\nconst val p = 1000000007L\r\nconst val pI = p.toInt()\r\nfun Int.adjust():Int{ if(this >= pI){ return this - pI }else if (this < 0){ return this + pI };return this }\r\nfun Int.snap():Int{ if(this >= pI){return this - pI} else return this}\r\ninfix fun Int.modM(b:Int):Int{ return ((this.toLong() * b) % pI).toInt() }\r\ninfix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }\r\nfun intPow(x:Int,e:Int,m:Int):Int{\r\n var X = x ; var E =e ; var Y = 1\r\n while(E > 0){\r\n if(E and 1 == 0){\r\n X = ((1L * X * X) % m).toInt()\r\n E = E shr 1\r\n }else{\r\n Y = ((1L * X * Y) % m).toInt()\r\n E -= 1\r\n }\r\n }\r\n return Y\r\n}\r\n// 2. DP initial values\r\nconst val plarge = 1_000_000_727\r\nconst val nlarge = -plarge\r\nconst val phuge = 2_727_000_000_000_000_000L\r\nconst val nhuge = -phuge\r\n// 3. conveniecen conversions\r\nval Boolean.chi:Int get() = if(this) 1 else 0 //characteristic function\r\nval BooleanArray.chiarray:IntArray get() = IntArray(this.size){this[it].chi}\r\nval Char.code :Int get() = this.toInt() - 'a'.toInt()\r\n//3. hard to write stuff\r\nfun IntArray.put(i:Int,v:Int){ this[i] = (this[i] + v).adjust() }\r\nval mint:MutableList get() = mutableListOf()\r\nval mong:MutableList get() = mutableListOf()\r\n//4. more outputs\r\nfun List.conca():String = this.joinToString(\"\")\r\nval CharArray.conca :String get() = this.joinToString(\"\")\r\nval IntArray.conca :String get() = this.joinToString(\" \")\r\n@JvmName(\"concaInt\")\r\nfun List.conca():String = this.joinToString(\" \")\r\nval LongArray.conca:String get() = this.joinToString(\" \")\r\n@JvmName(\"concaLong\")\r\nfun List.conca():String = this.joinToString(\" \")\r\n//5. Pair of ints\r\nconst val longmask = (1L shl 32) - 1\r\nfun makepair(a:Int, b:Int):Long = (a.toLong() shl 32) xor (longmask and b.toLong()) // remember positev sonly\r\nval Long.first get() = (this ushr 32).toInt()\r\nval Long.second get() = this.toInt()\r\n//6. strings\r\nval String.size get() = this.length\r\nconst val randCount = 100\r\n//7. bits\r\nfun Int.has(i:Int):Boolean = (this and (1 shl i) != 0)\r\nfun Long.has(i:Int):Boolean = (this and (1L shl i) != 0L)\r\n//8 TIME\r\ninline fun TIME(f:()->Unit){\r\n val t = measureTimeMillis(){\r\n f()\r\n }\r\n println(\"$t ms\")\r\n}\r\n//9.ordered pair\r\nfun order(a:Int, b:Int):Pair{\r\n return Pair(minOf(a,b), maxOf(a,b))\r\n}\r\nobject Reader{\r\n private const val BS = 1 shl 16\r\n private const val NC = 0.toChar()\r\n private val buf = ByteArray(BS)\r\n private var bId = 0\r\n private var size = 0\r\n private var c = NC\r\n\r\n var warningActive = true\r\n var fakein = StringBuilder()\r\n\r\n private var IN: BufferedInputStream = BufferedInputStream(System.`in`, BS)\r\n val OUT: PrintWriter = PrintWriter(System.out)\r\n\r\n private val char: Char\r\n get() {\r\n while (bId == size) {\r\n size = IN.read(buf) // no need for checked exceptions\r\n if (size == -1) return NC\r\n bId = 0\r\n }\r\n return buf[bId++].toChar()\r\n }\r\n\r\n fun nextInt(): Int {\r\n var neg = false\r\n if (c == NC) c = char\r\n while (c < '0' || c > '9') {\r\n if (c == '-') neg = true\r\n c = char\r\n }\r\n var res = 0\r\n while (c in '0'..'9') {\r\n res = (res shl 3) + (res shl 1) + (c - '0')\r\n c = char\r\n }\r\n return if (neg) -res else res\r\n }\r\n fun nextLong(): Long {\r\n var neg = false\r\n if (c == NC) c = char\r\n while (c < '0' || c > '9') {\r\n if (c == '-') neg = true\r\n c = char\r\n }\r\n var res = 0L\r\n while (c in '0'..'9') {\r\n res = (res shl 3) + (res shl 1) + (c - '0')\r\n c = char\r\n }\r\n return if (neg) -res else res\r\n }\r\n fun nextString():String{\r\n val ret = StringBuilder()\r\n while (true){\r\n c = char\r\n if(!isWhitespace(c)){ break}\r\n }\r\n ret.append(c)\r\n while (true){\r\n c = char\r\n if(isWhitespace(c)){ break}\r\n ret.append(c)\r\n }\r\n return ret.toString()\r\n }\r\n fun isWhitespace(c:Char):Boolean{\r\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t'\r\n }\r\n fun rerouteInput(){\r\n if(warningActive){\r\n put(\"Custom test enabled\")\r\n println(\"Custom test enabled\")\r\n warningActive = false\r\n }\r\n val S = fakein.toString()\r\n println(\"New Case \")\r\n println(S.take(80))\r\n println(\"...\")\r\n fakein.clear()\r\n IN = BufferedInputStream(S.byteInputStream(),BS)\r\n }\r\n fun takeFile(name:String){\r\n IN = BufferedInputStream(File(name).inputStream(),BS)\r\n }\r\n}\r\nfun put(aa:Any){ Reader.OUT.println(aa)}\r\nfun done(){ Reader.OUT.close() }\r\nfun share(aa:Any){\r\n if(aa is IntArray){Reader.fakein.append(aa.joinToString(\" \"))}\r\n else if(aa is LongArray){Reader.fakein.append(aa.joinToString(\" \"))}\r\n else if(aa is List<*>){Reader.fakein.append(aa.toString())}\r\n else{Reader.fakein.append(aa.toString())}\r\n Reader.fakein.append(\"\\n\")\r\n}\r\n\r\nval getintfast:Int get() = Reader.nextInt()\r\nval getint:Int get(){ val ans = getlong ; if(ans > Int.MAX_VALUE) IntArray(1000000000); return ans.toInt() }\r\nval getlong:Long get() = Reader.nextLong()\r\nval getstr:String get() = Reader.nextString()\r\nfun getline(n:Int):IntArray{\r\n return IntArray(n){getint}\r\n}\r\nfun getlineL(n:Int):LongArray{\r\n return LongArray(n){getlong}\r\n}\r\nvar dmark = -1\r\ninfix fun Any.dei(a:Any){\r\n dmark++\r\n var str = \"<${dmark}> \"\r\n debug()\r\n if(this is String){ str += this\r\n }else if(this is Int){ str += this.toString()\r\n }else if(this is Long){ str += this.toString()\r\n }else{ str += this.toString()}\r\n if(a is List<*>){ println(\"$str : ${a.joinToString(\" \")}\")\r\n }else if(a is IntArray){ println(\"$str : ${a.joinToString(\" \")}\")\r\n }else if(a is LongArray){ println(\"$str : ${a.joinToString(\" \")}\")\r\n }else if(a is BooleanArray){ println(\"$str :${a.map{if(it)'1' else '0'}.joinToString(\" \")}\")\r\n }else if(a is Array<*>){\r\n println(\"$str : \")\r\n for(c in a){if(c is IntArray){println(c.joinToString(\" \"))}\r\n else if(c is LongArray){println(c.joinToString(\" \"))}\r\n else if(c is BooleanArray){println(c.map { if(it) '1' else '0' }.joinToString(\"\"))\r\n }\r\n }\r\n println()\r\n }else{ println(\"$str : $a\")\r\n }\r\n}\r\nval just = \" \"\r\nfun crash(){\r\n throw Exception(\"Bad programme\")}\r\nfun assert(a:Boolean){\r\n if(!a){\r\n throw Exception(\"Failed Assertion\")\r\n }}\r\nenum class solveMode {\r\n real, rand, tc\r\n}\r\nobject solve{\r\n var mode:solveMode = solveMode.real\r\n var tcNum:Int = 0\r\n var rand:()->Unit = {}\r\n var TC:MutableMapUnit> = mutableMapOf()\r\n var tn:Long = 0\r\n fun cases(onecase:()->Unit){\r\n val t = if(mode == solveMode.real){if(singleCase) 1 else getint} else if(mode == solveMode.tc){1 } else randCount\r\n if(pI != 998_244_353 && pI != 1_000_000_007){\r\n throw Exception(\"Not usual primes!\")\r\n }\r\n if(t == 1 && mode != solveMode.real){\r\n tn = System.currentTimeMillis()\r\n }\r\n repeat(t){\r\n if(mode == solveMode.tc){\r\n TC[tcNum]?.let { it() }\r\n Reader.rerouteInput()\r\n }else if(mode == solveMode.rand){\r\n rand()\r\n Reader.rerouteInput()\r\n }\r\n onecase()\r\n }\r\n if(t == 1 && mode != solveMode.real){\r\n val dt = System.currentTimeMillis() - tn\r\n println(\"Time $dt ms \")\r\n }\r\n }\r\n inline fun singleCase(a:solve.()->Unit){\r\n val t = if(mode != solveMode.rand){1} else randCount\r\n repeat(t) { a() }\r\n }\r\n fun rand(a:()->Unit){\r\n this.rand = a\r\n }\r\n fun tc(id:Int = 0,a:()->Unit){\r\n TC[id] = a\r\n }\r\n fun usetc(a:Int = 0 ){\r\n this.tcNum = a\r\n this.mode = solveMode.tc\r\n }\r\n fun userand(){\r\n this.mode = solveMode.rand\r\n }\r\n}\r\n\r\nfun debug(){}\r\nconst val singleCase = true\r\nfun main(){\r\n solve.cases{\r\n val n = getint\r\n val m = getint\r\n var base = (n-1) * m.toLong() + 1\r\n\r\n val arr = BooleanArray((m+1) * 20)\r\n var taken = 0\r\n val ret = IntArray(21)\r\n for(level in 1..20){\r\n for(i in level..level * m step level){\r\n if(arr[i] == false){\r\n arr[i] = true\r\n taken ++\r\n }\r\n }\r\n ret[level] = taken\r\n }\r\n val checked = BooleanArray(n+1)\r\n for(p in 2..n){\r\n\r\n if(checked[p]){\r\n continue\r\n }\r\n var now =1\r\n var maxp = 0\r\n while(now * p.toLong() <= n){\r\n now *= p\r\n checked[now] = true\r\n maxp ++\r\n }\r\n val distinct = maxp.toLong() * m\r\n val actual = ret[maxp]\r\n base -= distinct\r\n base += actual\r\n }\r\n put(base)\r\n\r\n\r\n\r\n\r\n }\r\n done()\r\n}\r\n\r\n\r\n\r\n/*\r\n1 1\r\n2 4\r\n3 9\r\n4 16\r\n\r\n1000000 1000000\r\n */\r\n", "src_uid": "6ca310cb0b6fc4e62e63a731cd55aead"} {"source_code": "import java.lang.Exception\n\nfun main() {\n // 0 || X || .\n var num1 = 0 //The first player draws X goes\n var num2 = 0 //The second player draws 0 goes\n var spaceNum = 0 // space are '.'\n val table = arrayListOf(readLine()!!.toCharArray())\n var isFull = !table[0].any() { it == '.' }\n table.add(readLine()!!.toCharArray())\n isFull = isFull && !table[1].any() { it == '.' }\n table.add(readLine()!!.toCharArray())\n isFull = isFull && !table[2].any() { it == '.' }\n for (k in table.indices) {\n for (i in table[k].indices) {\n when {\n table[k][i] == 'X' -> {\n num1++\n }\n table[k][i] == '0' -> {\n num2++\n }\n table[k][i] == '.' -> {\n spaceNum++\n }\n }\n }\n }\n //println(\"num1 : $num1, num2 : $num2\")\n if (num1 - num2 != 0 && num1 - num2 != 1) {\n println(\"illegal\")\n return\n }\n val checkChar = arrayOf('X', '0')\n var won = arrayOf(0, 0)\n for (c in 0..1) {\n for (i in 0..2) { // fin\n if (checkChar[c] == table[i][0] && table[i][0] == table[i][1] && table[i][1] == table[i][2]) {\n won[c]++\n }\n if (checkChar[c] == table[0][i] && table[0][i] == table[1][i] && table[1][i] == table[2][i]) {\n won[c]++\n }\n }\n if (checkChar[c] == table[0][0] && table[0][0] == table[1][1] && table[1][1] == table[2][2]) {\n won[c]++\n }\n if (checkChar[c] == table[0][2] && table[0][2] == table[1][1] && table[1][1] == table[2][0]) {\n won[c]++\n }\n }\n //println(\"check : $checkChar\")\n // check number\n\n if (won[0] >= 1 && won[1] >= 1) {\n println(\"illegal\")\n return\n } else if (won[0] >= 1) {\n if(num1 - num2 != 1){\n println(\"illegal\")\n return\n }\n println(\"the first player won\")\n return\n } else if (won[1] >= 1) {\n if(num1 - num2 != 0){\n println(\"illegal\")\n return\n }\n println(\"the second player won\")\n return\n }\n\n if (!isFull) {\n if (num1 - num2 == 0) {\n println(\"first\")\n } else if (num1 - num2 == 1) {\n println(\"second\")\n }\n return\n } else {\n println(\"draw\")\n }\n}", "src_uid": "892680e26369325fb00d15543a96192c"} {"source_code": "import java.io.BufferedInputStream\nimport java.io.BufferedWriter\nimport java.io.OutputStreamWriter\nimport java.util.*\nimport kotlin.collections.HashMap\n\nfun main(args: Array) {\n val scanner = Scanner(BufferedInputStream(System.`in`))\n val output = BufferedWriter(OutputStreamWriter(System.`out`))\n\n var a = scanner.nextLong()\n var b = scanner.nextLong()\n\n while(a >= 2*b || b >= 2*a){\n if(a == 0L || b == 0L) break\n a %= (2*b)\n if(a != 0L) b %= (2*a)\n }\n\n output.write(\"$a $b\")\n\n output.flush()\n}", "src_uid": "1f505e430eb930ea2b495ab531274114"} {"source_code": "fun main() {\n val s = \"00\" + readLine()!!\n for (pos1 in 0 until s.length - 2)\n for (pos2 in pos1 + 1 until s.length - 1)\n for (pos3 in pos2 + 1 until s.length) {\n val candidate = (s[pos1] - '0') * 100 + (s[pos2] - '0') * 10 + (s[pos3] - '0')\n if (candidate % 8 == 0) {\n println(\"YES\")\n print(candidate)\n return\n }\n }\n print(\"NO\")\n}", "src_uid": "0a2a5927d24c70aca24fc17aa686499e"} {"source_code": "import java.io.*\nimport java.lang.Math.*\nimport java.math.BigInteger\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\nimport kotlin.math.sqrt\n\ntypealias IndexPair = Pair\ntypealias IntIndexPair = IndexPair\ntypealias IntIntPair = Pair\n\ntypealias IntMatrix = Array\ntypealias LongMatrix = Array\n\ntypealias ListArray = Array>\n\ntypealias Graph = IntMatrix\n\ntypealias Edge = Pair\ntypealias EdgeArray = Array\ntypealias WeightedGraph = Array\n\ntypealias TotalEdge = Triple\ntypealias TotalEdgeArray = Array\n\nfun init() { }\n\nconst val MODULO = 1000 * 1000 * 1000 + 7\n\nfun solve() {\n val (h, m) = readInts(\":\")\n val delay = readInt()\n\n val startTime = h * 60 + m\n val endTime = (startTime + delay) % (24 * 60)\n\n val endH = endTime / 60\n val endM = endTime % 60\n\n out.printf(\"${toTime(endH)}:${toTime(endM)}\")\n}\n\nfun toTime(x : Int) = (x + 100).toString().substring(1)\n\nfun stress() {\n val rnd = Random(1234)\n\n for (it in 0 until 100) {\n val expected = brute()\n val actual = fast()\n\n if (expected != actual) {\n System.err.println(\"Gotcha!\")\n System.err.println(\"$expected $actual\")\n\n break\n }\n }\n}\n\n\nfun fast() {\n\n}\n\nfun brute() {\n\n}\n\nfun Long.mod() : Long {\n var result = this % MODULO\n if (result < 0) result += MODULO\n return result\n}\n\ninfix fun Long.add(other : Long) = (this + other).mod()\ninfix fun Long.sub(other : Long) = this add -other.mod()\ninfix fun Long.mult(other : Long) = (this.mod() * other.mod()).mod()\n\nfun Long.even() = (this and 1L) == 0L\nfun Long.odd() = !even()\n\nfun Int.even() = (this and 1) == 0\nfun Int.odd() = !even()\n\ninfix fun Long.binpow(power : Long) : Long {\n if (power == 0L) return 1L\n\n val half = binpow(power shl 1)\n\n var result = half mult half\n if (power.odd()) {\n result = result mult this\n }\n\n return result\n}\n\nval stepsXY = arrayOf(\n arrayOf(0, -1),\n arrayOf(0, 1),\n arrayOf(-1, 0),\n arrayOf(1, 0)\n)\n\n\n\nclass IndexedWeightedGraph(private val n : Int, private val edges: TotalEdgeArray) {\n\n private val graph : Graph\n\n private fun buildGraphForEdges(\n edgeFilter : (index : Int, edge : TotalEdge) -> Boolean = { _, _ -> true }\n ) : Graph {\n val builder = GraphBuilder()\n edges\n .forEachIndexed { index, edge ->\n if (edgeFilter(index, edge)) {\n val (first, second, _ ) = edge\n\n builder.addDirectedEdge(first, index)\n builder.addDirectedEdge(second, index)\n }\n }\n\n return builder.build(n)\n }\n\n init {\n graph = buildGraphForEdges()\n }\n\n var root : Int = -1\n lateinit var inTree : BooleanArray\n lateinit var tree : Graph\n\n fun kruskalTree(root : Int) : Long {\n this.root = root\n\n inTree = BooleanArray(edges.size) { false }\n\n val dsu = DSU(n)\n\n edges\n .mapIndexed { index, (_, _, w) -> index to w }\n .sortedBy { it.second }\n .forEach {\n val edge = edges[it.first]\n inTree[it.first] = dsu.union(edge.first, edge.second)\n }\n\n tree = buildGraphForEdges { index, _ -> inTree[index] }\n\n return edges\n .mapIndexed { index, (_, _, w) -> if (inTree[index]) w.toLong() else 0L }\n .sum()\n }\n\n private fun to(from : Int, index : Int) : Int {\n val edge = edges[index]\n return if (from == edge.first) edge.second else edge.first\n }\n\n fun buildLca() {\n calculateTimes()\n calculateParents()\n calculatePathInfo()\n }\n\n lateinit var timesIn : IntArray\n lateinit var timesOut : IntArray\n private var time = -1\n\n private fun calculateTimes() {\n timesIn = IntArray(n) { -1 }\n timesOut = IntArray(n) { -1 }\n this.time = 0\n\n timeDfs(root)\n }\n\n private fun timeDfs(from : Int, parent : Int = -1) {\n timesIn[from] = time++\n\n for (index in tree[from]) {\n val to = to(from, index)\n if (to == parent) continue\n\n timeDfs(to, from)\n }\n\n timesOut[from] = time++\n }\n\n lateinit var parents : Array\n private val maxBit = 19\n\n private fun calculateParents() {\n parents = Array(maxBit) { IntArray(n) { -1 } }\n\n parentDfs(root, root)\n\n for (bit in 0 until maxBit - 1) {\n for (v in 0 until n) {\n val parent = parents[bit][v]\n parents[bit + 1][v] = parents[bit][parent]\n }\n }\n }\n\n private fun parentDfs(from : Int, parent : Int = -1) {\n parents[0][from] = parent\n\n for (index in tree[from]) {\n val to = to(from, index)\n if (to == parent) continue\n\n parentDfs(to, from)\n }\n }\n\n lateinit var maxEdges : Array\n\n private fun calculatePathInfo() {\n maxEdges = Array(maxBit) { IntArray(n) { -1 } }\n\n for (v in 0 until n){\n for (index in tree[v]) {\n val to = to(v, index)\n if (to == parents[0][v]) continue\n\n maxEdges[0][to] = edges[index].third\n }\n }\n\n for (bit in 0 until maxBit - 1) {\n for (v in 0 until n) {\n val parent = parents[bit][v]\n maxEdges[bit + 1][v] = max(\n maxEdges[bit][v],\n maxEdges[bit][parent]\n )\n }\n }\n }\n\n fun getOnPath(a : Int, b : Int) : Int {\n var answer = Int.MIN_VALUE\n\n answer = max(answer, getOnLcaPath(a, b))\n answer = max(answer, getOnLcaPath(b, a))\n\n return answer\n }\n\n private fun getOnLcaPath(start : Int, other : Int) : Int {\n var answer = Int.MIN_VALUE\n\n if (timesIn[start] <= timesIn[other] && timesOut[other] <= timesOut[start]) {\n return answer\n }\n\n var v = start\n for (bit in maxBit - 1 downTo 0) {\n val parent = parents[bit][v]\n if (timesIn[parent] > timesIn[other] || timesOut[other] > timesOut[parent]) {\n answer = max(answer, maxEdges[bit][v])\n v = parent\n }\n }\n\n answer = max(answer, maxEdges[0][v])\n\n return answer\n }\n}\n\nfun yesNo(yes : Boolean) {\n out.println(if (yes) \"YES\" else \"NO\")\n}\n\nfun run() {\n init()\n solve()\n out.close()\n}\n\nfun main(args: Array) {\n run()\n}\n\nval ONLINE_JUDGE = !File(\"input.txt\").exists()\n\nval input = BufferedReader(\n if (ONLINE_JUDGE) InputStreamReader(System.`in`) else FileReader(\"input.txt\")\n)\nval out =\n if (ONLINE_JUDGE) PrintWriter(System.out)\n else PrintWriter(\"output.txt\")\n\nfun readStrings(separator: String = \" \", emptyWords: Boolean = false) : Array {\n val line = input.readLine()\n\n val list = ArrayList()\n var builder = StringBuilder()\n\n for (i in 0..line.length) {\n if (i == line.length || separator.contains(line[i])) {\n if (emptyWords || builder.isNotEmpty()) {\n list.add(builder.toString())\n builder = StringBuilder()\n }\n } else {\n builder.append(line[i])\n }\n }\n\n return list.toTypedArray()\n}\n\nfun readString(separator: String = \" \") =\n readStrings(separator).first()\n\nfun readInts(separator: String = \" \") =\n readStrings(separator).map(String::toInt).toIntArray()\n\nfun readDecreasedInts(separator : String = \" \") =\n readInts(separator).map { it - 1 }.toIntArray()\n\nfun readSortedInts(separator: String = \" \") : IntArray {\n val a = readInts(separator)\n\n val aInteger = Array(a.size) { a[it] }\n Arrays.sort(aInteger)\n\n return aInteger.toIntArray()\n}\n\nfun readInt(separator: String = \" \") =\n readInts(separator).first()\n\nfun readLongs(separator: String = \" \") =\n readStrings(separator).map(String::toLong).toLongArray()\n\nfun readLong(separator: String = \" \") =\n readLongs(separator).first()\n\nfun readDoubles(separator: String = \" \") =\n readStrings(separator).map(String::toDouble).toDoubleArray()\n\nfun readDouble(separator: String = \" \") =\n readDoubles(separator).first()\n\nfun readBigIntegers(separator: String = \" \") =\n readStrings(separator).map { BigInteger(it) }.toTypedArray()\n\nfun readBigInteger(separator: String = \" \") =\n readBigIntegers(separator).first()\n\nfun readTree(n : Int, indexing : Int = 1) =\n readGraph(n, n - 1, true, indexing)\n\nfun readGraph(n: Int, m : Int,\n undirected : Boolean = true,\n indexing : Int = 1) : Graph {\n val builder = GraphBuilder()\n\n for (i in 1..m) {\n var (from, to) = readInts()\n\n from -= indexing\n to -= indexing\n\n if (undirected) builder.addEdge(from, to)\n else builder.addDirectedEdge(from, to)\n }\n\n return builder.build(n)\n}\n\nfun readWeightedGraph(n : Int, m : Int,\n undirected : Boolean = true,\n indexing : Int = 1) : WeightedGraph {\n val builder = GraphBuilder()\n\n for (i in 1..m) {\n var (from, to, weight) = readInts()\n\n from -= indexing\n to -= indexing\n\n if (undirected) builder.addEdge(from, to, weight)\n else builder.addDirectedEdge(from, to, weight)\n }\n\n return builder.buildWeighted(n)\n}\n\nfun readTotalEdges(m : Int, indexing : Int = 1) =\n TotalEdgeArray(m) {\n var (from, to, w) = readInts()\n\n from -= indexing\n to -= indexing\n\n Triple(from, to, w)\n }\n\nclass GraphBuilder {\n\n private val froms = ArrayList()\n private val tos = ArrayList()\n private val weights = ArrayList()\n\n fun addEdge(from : Int, to : Int, weight : Int = 1) {\n addDirectedEdge(from, to, weight)\n addDirectedEdge(to, from, weight)\n }\n\n fun addDirectedEdge(from : Int, to : Int, weight : Int = 1) {\n froms.add(from)\n tos.add(to)\n weights.add(weight)\n }\n\n private fun calculateFromSizes(n : Int) : IntArray {\n val sizes = IntArray(n) { 0 }\n froms.forEach { ++sizes[it] }\n return sizes\n }\n\n fun build(n : Int) : Graph {\n val sizes = calculateFromSizes(n)\n\n val graph = Graph(n) { IntArray(sizes[it]) { 0 } }\n\n for (i in 0 until n) {\n sizes[i] = 0\n }\n\n for (i in 0 until froms.size) {\n val from = froms[i]\n val to = tos[i]\n\n graph[from][sizes[from]++] = to\n }\n\n return graph\n }\n\n fun buildWeighted(n : Int) : WeightedGraph {\n val sizes = calculateFromSizes(n)\n\n val graph = WeightedGraph(n) { EdgeArray(sizes[it]) { -1 to 0 } }\n\n for (i in 0 until n) {\n sizes[i] = 0\n }\n\n for (i in 0 until froms.size) {\n val from = froms[i]\n val to = tos[i]\n val weight = weights[i]\n\n graph[from][sizes[from]++] = to to weight\n }\n\n return graph\n }\n}\n\nfun gcd(a : Int, b : Int) : Int =\n if (a == 0) b else gcd(b % a, a)\n\nfun gcd(a : Long, b : Long) : Long =\n if (a == 0L) b else gcd(b % a, a)\n\nfun getDivisors(x : Int) : MutableList {\n val divisors = ArrayList()\n\n var d = 1\n while (d * d <= x) {\n if (x % d == 0) {\n if (d != 1) divisors.add(d)\n if (x != d) divisors.add(x / d)\n }\n\n ++d\n }\n\n return divisors\n}\n\nfun getPrimeDivisors(xx : Int) : MutableList {\n val divisors = ArrayList()\n\n var d = 2\n var x = xx\n while (d * d <= x) {\n if (x % d == 0) {\n divisors.add(d)\n while (x % d == 0) {\n x /= d\n }\n }\n\n ++d\n }\n\n if (x > 1) divisors.add(x)\n\n return divisors\n}\n\nfun checkIndex(index : Int, size : Int) =\n 0 <= index && index < size\n\nfun checkCell(x : Int, n : Int, y : Int, m : Int) =\n checkIndex(x, n) && checkIndex(y, m)\n\nfun toChar(index : Int, start : Char) =\n (index + start.toInt()).toChar()\n\nclass DSU {\n\n var sizes : IntArray\n var ranks : IntArray\n var parents : IntArray\n\n constructor(n : Int)\n : this(\n IntArray(n) { 1 }\n )\n\n constructor(sizes : IntArray) {\n val size = sizes.size\n this.sizes = sizes\n this.ranks = IntArray(size) { 1 }\n this.parents = IntArray(size) { it }\n }\n\n operator fun get(v : Int) : Int {\n val parent = parents[v]\n if (parent == v) return v\n parents[v] = get(parent)\n return parents[v]\n }\n\n fun union(aUniting : Int, bUniting : Int) : Boolean {\n var a = get(aUniting)\n var b = get(bUniting)\n\n if (a == b) return false\n\n if (ranks[a] < ranks[b]) {\n val tmp = a\n a = b\n b = tmp\n }\n\n parents[b] = a\n sizes[a] += sizes[b]\n if (ranks[a] == ranks[b]) ++ranks[a]\n\n return true\n }\n\n fun size(v : Int) : Int = sizes[get(v)]\n}\n\nclass FenwickTree(n : Int) {\n\n val size = n + 1\n val tree = LongArray(size) { 0L }\n\n fun update(index : Int, delta : Int) {\n var x = index + 1\n while (x < size) {\n tree[x] = tree[x] + delta\n x += x and -x\n }\n }\n\n operator fun get(start : Int, end : Int) =\n get(end) - get(start - 1)\n\n operator fun get(index : Int) : Long {\n var result : Long = 0\n\n var x = index + 1\n while (x > 0) {\n result += tree[x]\n x -= x and -x\n }\n\n return result\n }\n}\n\n", "src_uid": "20c2d9da12d6b88f300977d74287a15d"} {"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", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4"} {"source_code": "import kotlin.math.abs\nimport kotlin.math.ceil\nimport kotlin.math.sqrt\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n fun readLong() = readLine()!!.toLong()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n val (r, x, y, x2, y2) = readLongs()\n val d = sqrt(((x - x2) * (x - x2) + (y - y2) * (y - y2)).toDouble())\n print(ceil(d / (r * 2)).toLong())\n}", "src_uid": "698da80c7d24252b57cca4e4f0ca7031"} {"source_code": "// package codeforces\n\nfun main() {\n var (s, t) = Pair(readLine()!!,readLine()!!)\n println( if(s.reversed() == t) \"YES\" else \"NO\" )\n}", "src_uid": "35a4be326690b58bf9add547fb63a5a5"} {"source_code": "fun main() {\n var (f, l) = readLine()!!.split(\" \")\n var j = 0\n var ans = f[0].toString()\n for (i in 1 until f.length) {\n if (f[i].toInt() < l[j].toInt()) {\n ans += f[i]\n }else{\n ans+=l[j]\n println(ans)\n return\n }\n }\n ans+=l[j]\n println(ans)\n}", "src_uid": "aed892f2bda10b6aee10dcb834a63709"} {"source_code": "fun main() {\n print(3 * readLine()!!.toInt() / 2)\n}", "src_uid": "031e53952e76cff8fdc0988bb0d3239c"} {"source_code": "import java.util.*\nimport kotlin.math.min\n\nfun main() {\n val jin = Scanner(System.`in`)\n val n = jin.nextInt()\n val m = jin.nextInt()\n val a = jin.nextInt()\n val b = jin.nextInt()\n var g = jin.nextLong()\n val x = jin.nextLong()\n val y = jin.nextLong()\n val z = jin.nextLong()\n val map = Array(n) { LongArray(m) {\n val res = g\n g = ((g * x) + y) % z\n res\n }}\n val mins = Array(n) { LongArray(m) }\n for (i in 0 until n) {\n val queue = LinkedList()\n for (j in 0 until b) {\n while (!queue.isEmpty() && map[i][queue.last] >= map[i][j]) {\n queue.removeLast()\n }\n queue.add(j)\n }\n for (j in 0..m - b) {\n if (queue.first < j) {\n queue.remove()\n }\n mins[i][j] = map[i][queue.first]\n if (j + b < m) {\n while (!queue.isEmpty() && map[i][queue.last] >= map[i][j + b]) {\n queue.removeLast()\n }\n queue.add(j + b)\n }\n }\n }\n var answer: Long = 0\n for (j in 0 until m) {\n val queue = LinkedList()\n for (i in 0 until a) {\n while (!queue.isEmpty() && mins[queue.last][j] >= mins[i][j]) {\n queue.removeLast()\n }\n queue.add(i)\n }\n for (i in 0..n - a) {\n if (queue.first < i) {\n queue.remove()\n }\n answer += mins[queue.first][j]\n if (i + a < n) {\n while (!queue.isEmpty() && mins[queue.last][j] >= mins[i + a][j]) {\n queue.removeLast()\n }\n queue.add(i + a)\n }\n }\n }\n println(answer)\n}", "src_uid": "4618fbffb2b9d321a6d22c11590a4773"} {"source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)){\n val n = nextInt()\n val k = nextLong()\n val arrSize = getArrSize(n.toLong())\n println(findTargetIndex(n.toLong(), arrSize, k - 1)) \n\n}\nfun findTargetIndex(step: Long, size: Long, targetIndex: Long): Long{\n if(size == 1L) {\n return 1L\n }\n val next = size / 2\n \n if(next == targetIndex) {\n return step\n }\n if(targetIndex > next) {\n return findTargetIndex(step - 1, next, targetIndex - next - 1)\n }\n return findTargetIndex(step - 1, next, targetIndex)\n}\n\nfun getArrSize(step: Long): Long { \n if(step <= 1L) {\n return 1\n }\n return (2 * getArrSize(step - 1)) + 1\n}", "src_uid": "0af400ea8e25b1a36adec4cc08912b71"} {"source_code": "fun main(args: Array) {\n val(n, k) = readLine()!!.split(' ').map(String::toLong)\n var d = (n / 2) / (k + 1)\n var g = d * k\n var l = n - (g + d)\n println(\"$d $g $l\")\n}", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80"} {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n readLine()\n val pairs = readInts()\n var sol = 0\n var home = true\n for ((pos, pair) in pairs.withIndex())\n if (pair == 1) {\n home = false\n sol++\n } else {\n if (!home && pos != pairs.lastIndex && pairs[pos + 1] == 1)\n sol++\n else\n home = true\n }\n print(sol)\n}", "src_uid": "2896aadda9e7a317d33315f91d1ca64d"} {"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", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2"} {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(args : Array) {\n Thread { run() }.start()\n}\n\nval scanner = Scanner(System.`in`)\nval n1 =scanner.nextInt()\nval n2 = scanner.nextInt()\nval k1 = scanner.nextInt()\nval k2 = scanner.nextInt()\nval arr = Array>>(n1 + 1) { Array>(n2 + 1) { Array(k1 + 1) { IntArray(k2 + 1) { -1 } } } }\nval mod = 100000000\n\nfun run() {\n\n println(Q(n1, n2, 0, 0))\n\n}\n\nfun Q(q1: Int, q2: Int, w1: Int, w2: Int): Int {\n if (arr[q1][q2][w1][w2] != -1)\n return arr[q1][q2][w1][w2]\n var res = 0\n if (q1 != 0 && w1 != k1)\n res += Q(q1 - 1, q2, w1 + 1, 0)\n if (q2 != 0 && w2 != k2)\n res += Q(q1, q2 - 1, 0, w2 + 1)\n if (q1 == 0 && q2 == 0)\n res = 1\n res %= mod\n arr[q1][q2][w1][w2] = res\n return res\n}\n\n//fun run() {\n//\n// val scanner = Scanner(System.`in`)\n// val n1 = scanner.nextInt()\n// val n2 = scanner.nextInt()\n// val k1 = scanner.nextInt()\n// val k2 = scanner.nextInt()\n// val arr = Array>>(n1 + 1) { Array>(n2 + 1) { Array(k1 + 1) { IntArray(k2 + 1) } } }\n// val mod = 100000000\n// arr[0][0][0][0] = 1\n// for (i1 in 0 until n1) {\n// for (i2 in 0 until n2) {\n// for (j1 in 0 until k1) {\n// for (j2 in 0 until k2) {\n// arr[i1][i2][j1][j2] %= mod\n// arr[i1 + 1][i2][j1 + 1][j2] += arr[i1][i2][j1][j2]\n// arr[i1][i2 + 1][j1][j2 + 1] += arr[i1][i2][j1][j2]\n// arr[i1][i2 + 1][j1][j2] += arr[i1][i2][j1][j2]\n// arr[i1 + 1][i2][j1][j2] += arr[i1][i2][j1][j2]\n// }\n// }\n// }\n// }\n// var res = 0\n// for (i in 0..k1) {\n// for (j in 0..k2) {\n// res += arr[n1][n2][i][j]\n// res %= mod\n// }\n// }\n// println(res)\n//}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\nfun IntArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun LongArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun BooleanArray.print() {\n println(Arrays.toString(this))\n}\nfun nod(a: Long, b: Long): Long {\n var a1 = a\n var b1 = b\n while (a1 != 0L && b1 != 0L) {\n if (a1 < b1)\n b1 %= a1\n else\n a1 %= b1\n }\n return a1 + b1\n}\nfun nok(a: Long, b: Long): Long = a * b / nod(a, b)", "src_uid": "63aabef26fe008e4c6fc9336eb038289"} {"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(args: Array) {\n val n = readInt()\n val s = readLn()\n var beg = 0\n var ans = 0\n while (beg < n) {\n if (s[beg] != 'x') {\n beg += 1\n continue\n }\n var end = beg\n while (end + 1 < n && s[end + 1] == 'x') {\n ++end\n }\n ans += maxOf(0, end - beg + 1 - 2)\n beg = end + 1\n }\n println(ans)\n}", "src_uid": "8de14db41d0acee116bd5d8079cb2b02"} {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toLong()\n val f = n / 2 - n.rem(2) * n\n println(f)\n}\n", "src_uid": "689e7876048ee4eb7479e838c981f068"} {"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}", "src_uid": "684ce84149d6a5f4776ecd1ea6cb455b"} {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main() {\n val br = BufferedReader(InputStreamReader(System.`in`))\n val (a, b) = br.readLine().split(\" \").map { it.toInt()}\n var i = a\n var candles = a\n while (i >= b){\n candles += i/b\n i = i/b + i % b\n }\n\n println(candles)\n}", "src_uid": "a349094584d3fdc6b61e39bffe96dece"} {"source_code": "import java.util.*\nimport kotlin.math.min\n\nfun main(args: Array) {\n with(Scanner(System.`in`)) {\n val X2 = nextInt()\n val mk = Array(X2 + 1, { true })\n val mf = Array(X2 + 1, { 0 })\n\n (2..X2).forEach {\n if (mk[it]) {\n mf[it] = it\n for (j in (it * 2)..X2 step it) {\n mk[j] = false\n mf[j] = it\n }\n }\n }\n\n val lo = fun(x: Int) = x - mf[x] + 1\n\n var ans = X2\n (lo(X2)..X2).forEach {\n if (!mk[it]) {\n val c = lo(it)\n if (c >= 3) {\n ans = min(ans, c)\n }\n }\n }\n println(ans)\n }\n}", "src_uid": "43ff6a223c68551eff793ba170110438"} {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\n\nval MOD = 998244353\nvar fact = IntArray(200010)\nvar ifact = IntArray(fact.size)\nfun mul(vararg n: Int): Int {\n return n.reduce { a,b -> (a * b.toLong()).rem(MOD).toInt() }\n}\nfun mpow(b: Int, e: Int): Int {\n if (e == 0) return 1\n val sq = mpow(b, e / 2)\n return mul(sq, sq, (if (e.rem(2) == 1) b else 1))\n}\nfun init() {\n fact[0] = 1\n for (i in 1 until fact.size) {\n fact[i] = mul(i, fact[i-1])\n }\n ifact[ifact.size - 1] = mpow(fact[ifact.size - 1], MOD - 2)\n for (i in (0 until ifact.size - 1).reversed()) {\n ifact[i] = mul(i+1, ifact[i+1])\n }\n}\nfun ncr(n: Int, r: Int): Int {\n return mul(fact[n], ifact[n-r], ifact[r])\n}\n\n\n\nfun main() {\n init()\n\n val (n, m) = readInts()\n var sm = 0\n for (mx in 2..m) {\n if (mx + 1 < n) continue\n val cnt = mul(mpow(2, n - 3), ncr(mx - 1, n - 2), n - 2)\n sm = (sm + cnt).rem(MOD)\n }\n print(sm)\n\n}\n\n/*\n1 1 5 -> 3\n1 5 1 -> 2\n5 1 1 -> 1\n */", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba"} {"source_code": "fun main() {\n fun String.isPalindrome(): Boolean {\n var left = -1\n var right = this.length\n while (++left <= --right)\n if (this[left] != this[right]) return false\n return true\n }\n\n val s = readLine()!!\n print(\n when {\n !s.isPalindrome() -> s.length\n s.toSet().size == 1 -> 0\n else -> s.length - 1\n }\n )\n}\n\n\n", "src_uid": "6c85175d334f811617e7030e0403f706"} {"source_code": "fun main() {\n val numberOfParties = readInt()\n\n val votes = readInts()\n val totalVotes = votes.sum()\n\n val aliceVotes = votes[0]\n\n val coalition = mutableListOf(1)\n for (i in 1 until numberOfParties) {\n if (aliceVotes >= 2 * votes[i]) coalition.add(i + 1)\n }\n\n var coalitionVotes = 0\n\n coalition.forEach { coalitionVotes += votes[it - 1] }\n\n if (coalitionVotes > totalVotes - coalitionVotes) {\n println(coalition.size)\n println(coalition.toString().replace(\"[\", \"\").replace(\"]\", \"\").replace(\", \", \" \"))\n } else println(0)\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\n\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n", "src_uid": "0a71fdaaf08c18396324ad762b7379d7"} {"source_code": "import java.util.Scanner\n\nfun main(args : Array) {\n val scanner = Scanner(System.`in`)\n var n = scanner.nextLong()\n var k = scanner.nextLong()\n var r: Long = n/k\n print(if (r%2==1L) \"YES\" else \"NO\")\n}", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50"} {"source_code": "import java.io.BufferedReader\nimport java.io.File\nimport java.io.PrintWriter\n\nfun main(args: Array) {\n val onlineJudge = System.getProperty(\"ONLINE_JUDGE\") == \"true\"\n val input = if (onlineJudge) System.`in`.bufferedReader() else File(\"input.txt\").bufferedReader()\n val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File(\"output.txt\"))\n\n solve(input, output)\n\n output.flush()\n output.close()\n}\n\nprivate fun String.words() = split(\" \")\n\nprivate fun String.toInts() = split(\" \").map { it.toInt() }\nprivate fun String.toLongs() = split(\" \").map { it.toLong() }\n\nprivate fun solve(input: BufferedReader, output: PrintWriter) {\n val (n) = input.readLine().toLongs()\n var nPrev = 1L // k = 0\n var nCur = 2L // k = 1\n var k = 1\n while (true) {\n val nNext = nCur + nPrev\n if (nNext > n) {\n output.println(k)\n return\n }\n ++k\n nPrev = nCur\n nCur = nNext\n }\n}", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14"} {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\n\nfun PrintWriter.solve(sc: FastScanner) {\n var a = sc.nextInt()\n var b = sc.nextInt()\n var c = sc.nextInt()\n var d = sc.nextInt()\n val e = sc.nextInt()\n val f = sc.nextInt()\n var ans = 0\n if (e < f) {\n val t = minOf(b, c, d)\n d -= t\n ans += f * t\n val u = minOf(a, d)\n ans += e * u\n } else {\n val u = minOf(a, d)\n d -= u\n ans += e * u\n val t = minOf(b, c, d)\n ans += f * t\n }\n println(ans)\n}\n\nfun main() {\n val writer = PrintWriter(System.out, false)\n writer.solve(FastScanner(System.`in`))\n writer.flush()\n}\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}", "src_uid": "84d9e7e9c9541d997e6573edb421ae0a"} {"source_code": "private fun solve(n: Int, m: Int = 1): Int = when(n) {\n\tm, m + 1 -> 1\n\tin 0 until m -> 0\n\telse -> solve(n, 2 * m + 1 + m % 2)\n}\n\nfun main() = println(solve(readInt()))\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\n", "src_uid": "821409c1b9bdcd18c4dcf35dc5116501"} {"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}", "src_uid": "11e6559cfb71b8f6ca88242094b17a2b"} {"source_code": "import java.util.*\n \nfun main(args: Array) {\n //val sc = Scanner(System.`in`)\n var res : Long = 0\n var p2 : Long = 1\n var p3 : Long = 1\n val (l, r) = readLine()!!.split(\" \").map(String::toLong)\n while (true) {\n\tvar cur = p2 * p3\n\tif (cur >= l && cur <= r) {\n\t\t//println(cur)\n\t\tres++\n\t}\n\tif (cur > r) {\n\t\tp2 = 1\n\t\tp3 *= 3\n\t}\n\telse {\n\t\tp2 *= 2\n\t}\n\tif (p3 > r) {\n\t\tbreak\n\t}\n }\n println(res)\n\n \n}", "src_uid": "05fac54ed2064b46338bb18f897a4411"} {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(args: Array) {\n val sc = Scanner()\n var n = sc.nxtInt()\n println(Integer.bitCount(n))\n}\n\nclass Scanner(){\n var br:BufferedReader?=null\n var st:StringTokenizer?=null\n init {\n br = BufferedReader(InputStreamReader(System.`in`))\n }\n private fun tokenize()\n {\n while(st==null || !st!!.hasMoreTokens())st = StringTokenizer(br!!.readLine())\n }\n fun readLine():String{\n return br!!.readLine()\n }\n fun nxt():String\n {\n tokenize()\n return st!!.nextToken()\n }\n\n fun nxtInt():Int{\n return nxt().toInt()\n }\n fun nxtDouble():Double\n {\n return nxt().toDouble()\n }\n fun nxtString():String\n {\n return nxt()\n }\n\n\n\n}", "src_uid": "03e4482d53a059134676f431be4c16d2"} {"source_code": "fun main() {\n val s = readLine()!!\n var questionMarks = 0L\n val characters = mutableSetOf()\n var multiplier = 10L\n for (c in s) if (c == '?') questionMarks++ else if (c in 'A'..'J') characters.add(c)\n var sol = 1L\n when (s.first()) {\n '?' -> {\n sol = 9L\n questionMarks--\n }\n in 'A'..'J' -> {\n sol = 9L\n characters.remove(s.first())\n multiplier--\n }\n }\n for (i in 0 until characters.size) sol *= multiplier--\n val sb = StringBuilder()\n sb.append(sol)\n for (i in 0 until questionMarks) sb.append('0')\n print(sb.toString())\n}", "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82"} {"source_code": "fun main() {\n var (n, m) = readLine()!!.split(\" \").map { it.toInt() }\n var ans = 0\n while (n > 0) {\n ans += 1\n if (ans % m != 0) n -= 1\n }\n print(ans)\n}", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0"} {"source_code": "import java.*\nimport java.util.*\nfun main(args: Array) {\n val `in` = Scanner(System.`in`)\n val n = `in`.nextInt()\n val m = `in`.nextInt()\n var maxIt = 0\n var maxChild = 0\n for (i in 0 until n) {\n val x = `in`.nextInt()\n val it = (x + (m - 1)) / m\n if (it >= maxIt) {\n maxIt = it\n maxChild = i\n }\n }\n println(maxChild + 1)\n\n\n }", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c"} {"source_code": "\nimport java.io.*\nimport java.lang.Math.pow\nimport java.util.*\n\nfun solve() {\n val n = nextInt()\n for (c in components(n)){\n if (isWonder(c)){\n println(c)\n break\n }\n }\n\n}\n\nfun components(a: Int) : List{\n return (a downTo 1).filter { a%it == 0}.toList()\n}\nfun isWonder(a: Int):Boolean{\n return (1..10).any {(pow(2.0, it.toDouble()) - 1) * pow(2.0, (it-1).toDouble()) == a.toDouble()}\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}", "src_uid": "339246a1be81aefe19290de0d1aead84"} {"source_code": "import java.util.Scanner\r\n\r\nfun main() {\r\n\tval sc = Scanner(System.`in`)\r\n\r\n\tval n = sc.nextInt()\r\n\tval m = sc.nextLong()\r\n\r\n\tval lim = 998244353L\r\n\r\n\t// calculating the number of all the possible arrays for each length from 1 to n\r\n\tvar currPow = 1L\r\n\tvar res = 0L\r\n\tfor (i in 1..n) {\r\n\t\tcurrPow = (currPow * (m % lim)) % lim\r\n\t\tcurrPow = (currPow + lim) % lim\r\n\r\n\t\tres = (res + currPow) % lim\r\n\t\tres = (res + lim) % lim\r\n\t}\r\n\r\n\t// calculate primes\r\n\tval primes = mutableListOf()\r\n\tval isPrime = MutableList(n + 1) { true }\r\n\tvar currPrime = 2L\r\n\twhile (currPrime <= n) {\r\n\t\tif (isPrime[currPrime.toInt()]) {\r\n\t\t\tprimes.add(currPrime.toInt())\r\n\r\n\t\t\tfor (nonPrime in currPrime * currPrime..n step currPrime) {\r\n\t\t\t\tisPrime[nonPrime.toInt()] = false\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tcurrPrime += 1L\r\n\t}\r\n\tisPrime.clear()\r\n\r\n\t// subtracting the number of all the 'bad' array for each array length from 1 to n\r\n\t// left with only the 'good' ones\r\n\r\n\tvar lastPrimeIdx = 0\r\n\tvar currPrimesMult = 1L\r\n\tvar toSubtract = 1L\r\n\r\n\tfor (currLength in 1..n) {\r\n\t\tif (lastPrimeIdx < primes.size && currLength >= primes[lastPrimeIdx]) {\r\n\t\t\tcurrPrimesMult *= primes[lastPrimeIdx]\r\n\t\t\t++lastPrimeIdx\r\n\t\t}\r\n\r\n\t\tif (m < currPrimesMult) {\r\n\t\t\tbreak\r\n\t\t}\r\n\r\n\t\tval newPart = (m / currPrimesMult) % lim\r\n\t\tif (newPart == 0L) {\r\n\t\t\tbreak\r\n\t\t}\r\n\r\n\t\ttoSubtract = (toSubtract * newPart) % lim\r\n\t\ttoSubtract = (toSubtract + lim) % lim\r\n\r\n\t\tres = (res - toSubtract) % lim\r\n\t\tres = (res + lim) % lim\r\n\t}\r\n\r\n\tprintln(res)\r\n\r\n}\r\n", "src_uid": "0fdd91ed33431848614075ebe9d2ee68"} {"source_code": "import java.util.*\n\nfun main() {\n val input = Scanner(System.`in`)\n\n// var t = input.nextInt()\n// while(t > 0){\n//\n// }\n\n var n = input.nextInt()\n if (n==2)print(1)\n else print((fact(n)/(n*n/2)))\n\n}\n\nfun fact(a: Int): Long{\n return if (a == 0) 1\n else a * fact(a-1)\n}", "src_uid": "ad0985c56a207f76afa2ecd642f56728"} {"source_code": "fun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readStrings() = readLn().split(\" \")\nfun readInts() = readStrings().map { it.toInt() }\n\nfun main(args: Array) {\n var a = listOf(1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210, 231, 253, 276, 300, 325, 351, 378, 406, 435, 465, 496, 528)\n var n = readInt().apply {\n if (this in a) print(\"YES\") else print(\"NO\")\n }\n}\n", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301"} {"source_code": "import java.util.*;\n\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\n\nfun readLine(): String? = _reader.readLine()\n\nfun readLn() = _reader.readLine()!!\n\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\n\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer =\n StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\n\nfun readInt() = read().toInt()\n\nfun readDouble() = read().toDouble()\n\nfun readLong() = read().toLong()\n\nfun readStrings(n: Int) = List(n) { read() }\n\nfun readLines(n: Int) = List(n) { readLn() }\n\nfun readInts(n: Int) = List(n) { read().toInt() }\n\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\n\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\n\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\n\nfun readLongs(n: Int) = List(n) { read().toLong() }\n\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\nfun main() {\n var n = readInt()\n val encrypt = readStrings(1)\n var s = \"\"\n var i = 0;\n var k = 0;\n while (i < n) {\n s += encrypt[0].get(i);\n k++;\n i += k;\n }\n println(s)\n}", "src_uid": "08e8c0c37b223f6aae01d5609facdeaf"} {"source_code": "import kotlin.math.min\nimport kotlin.math.max\nimport kotlin.math.sqrt\n\nprivate fun cin_ch() = readLine()!!.split(\" \").map{it.toInt()}\nprivate fun cin_array() = readLine()!!.split(\" \").map(String::toInt)\nprivate fun cin_string() = readLine()!!.split(\" \")\n\nfun main() {\nvar n = cin_ch()[0];\nvar ans = 0;\nfor (i in 3..n) {\nans+=i*(i-1);\n}\nprintln(ans);\nreturn;\n}", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a"} {"source_code": "import java.util.*\n\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val people = sc.nextInt()\n val food = sc.nextInt()\n val typescnt = 101\n\n val types = IntArray(typescnt, {0})\n for (i in 1..food) {\n types[sc.nextInt()] += 1\n }\n\n val eating = IntArray(typescnt, {0})\n\n for (i in 1..people) {\n var maxk = -1\n var maxkj = -1\n for (j in 1 until typescnt) {\n if (types[j] == 0)\n continue\n val coef = types[j] / (eating[j] + 1)\n if (coef > maxk) {\n maxk = coef\n maxkj = j\n }\n }\n if (maxkj != -1) {\n eating[maxkj] += 1\n }\n }\n\n var mind = 1000000\n\n for (i in 1 until typescnt) {\n if (eating[i] != 0) {\n val v = types[i] / eating[i]\n if (v < mind)\n mind = v\n }\n }\n\n if (mind == 1000000) {\n println(\"0\")\n } else {\n println(mind)\n }\n\n val a = 2\n\n}\n\n", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe"} {"source_code": "private fun readLn(): String = readLine()!!\nprivate fun readInt(): Int = readLn().toInt()\nprivate fun readDouble(): Double = readLn().toDouble()\nprivate fun readStrings(): List = readLn().split(\" \")\nprivate fun readInts(): List = readStrings().map { it.toInt() }\nprivate fun readDoubles(): List = readStrings().map { it.toDouble() }\nprivate fun readIntPair(): Pair {\n val (a, b) = readInts()\n return Pair(a, b)\n}\n\n\nfun main() {\n val n = readInt()\n val r = readInts()\n val b = readInts()\n val r_adv = r.zip(b).filter { it.first > it.second }\n val b_adv = r.zip(b).filter { it.first < it.second }\n // (r * pmax) > b_adv => ceil(b / r) = pmax\n val p = r_adv.count()\n val q = b_adv.count()\n if (p == 0) {\n println(-1)\n return\n }\n\n val ans = (q + p - 1)/p\n println(if (q % p == 0) ans+1 else ans)\n}", "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07"} {"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}", "src_uid": "f03773118cca29ff8d5b4281d39e7c63"} {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.lang.StringBuilder\nimport java.util.*\n\n// region\nclass ModInt(x: Long) {\n\n companion object {\n const val MOD = 998244353L\n }\n\n val x = (x % MOD + MOD) % MOD\n\n operator fun plus(other: ModInt): ModInt {\n return ModInt(x + other.x)\n }\n\n operator fun minus(other: ModInt): ModInt {\n return ModInt(x - other.x)\n }\n\n operator fun times(other: ModInt): ModInt {\n return ModInt(x * other.x)\n }\n\n operator fun div(other: ModInt): ModInt {\n return this * other.inv()\n }\n\n fun pow(exp: Long): ModInt {\n if (exp == 0L) return ModInt(1L)\n var a = pow(exp shr 1)\n a *= a\n if (exp and 1L == 0L) return a\n return this * a\n }\n\n fun inv(): ModInt {\n return this.pow(MOD - 2)\n }\n\n override fun equals(other: Any?): Boolean {\n if (this === other) return true\n if (javaClass != other?.javaClass) return false\n\n other as ModInt\n\n if (x != other.x) return false\n\n return true\n }\n\n override fun hashCode(): Int {\n return x.hashCode()\n }\n\n override fun toString(): String {\n return \"$x\"\n }\n\n}\n\nval fac = mutableListOf()\n\nfun fact(n: Long): ModInt {\n if (fac.count() == 0) fac.add(ModInt(1))\n while (fac.count() <= n) {\n fac.add(fac.last() * ModInt(fac.count().toLong()))\n }\n return fac[n.toInt()]\n}\n\nfun comb(n: Long, k: Long): ModInt {\n return fact(n) / fact(k) / fact(n - k)\n}\n\nfun comb2(n: Long, k: Long): ModInt {\n var ans = ModInt(1)\n for (i in 0 until k) {\n ans = ans * ModInt(n - i) / ModInt(k - i)\n }\n return ans\n}\n// endregion\n\nfun PrintWriter.solve(sc: FastScanner) {\n val n = sc.nextInt()\n val _k = sc.nextLong()\n if (_k >= n) {\n println(0)\n return\n }\n val k = _k.toInt()\n val c = (n - k).toLong()\n var ans = ModInt(c).pow(n.toLong())\n for (i in 0 until n - k - 1) {\n val v = comb(c, c - i - 1) * ModInt(c - i - 1).pow(n.toLong())\n if (i % 2 == 0) {\n ans -= v\n } else {\n ans += v\n }\n }\n ans *= comb(n.toLong(), c)\n if (k > 0) {\n ans *= ModInt(2)\n }\n println(ans)\n}\n\nfun main(args: Array) {\n val writer = PrintWriter(System.out, false)\n writer.solve(FastScanner(System.`in`))\n writer.flush()\n}\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}", "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc"} {"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}", "src_uid": "47da1dd95cd015acb8c7fd6ae5ec22a3"} {"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()", "src_uid": "2eb101dcfcc487fe6e44c9b4c0e4024d"} {"source_code": "import java.io.BufferedReader\nimport java.io.File\nimport java.io.PrintWriter\n\nfun main(args: Array) {\n val onlineJudge = System.getProperty(\"ONLINE_JUDGE\") == \"true\"\n val input = if (onlineJudge) System.`in`.bufferedReader() else File(\"input.txt\").bufferedReader()\n val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File(\"output.txt\"))\n\n solve(input, output)\n\n output.flush()\n output.close()\n}\n\nprivate fun String.words() = split(\" \")\n\nprivate fun String.toInts() = split(\" \").map { it.toInt() }\nprivate fun String.toLongs() = split(\" \").map { it.toLong() }\n\nprivate fun solve(input: BufferedReader, output: PrintWriter) {\n val n = input.readLine()\n val l = input.readLine()\n val r = \"ogo(go)*\".toRegex()\n val o = r.replace(l, \"***\")\n output.println(o)\n}", "src_uid": "619665bed79ecf77b083251fe6fe7eb3"} {"source_code": "var r = 0\nfun main(){\n var q = readLine()!!.split(' ').map { it.toInt() }\n var h = q[0]\n var w = q[1]\n var k = q[2]\n while(k > 0){\n r += (h + w) * 2 - 4\n h -= 4\n w -= 4\n k -= 1\n }\n println(r)\n}", "src_uid": "2c98d59917337cb321d76f72a1b3c057"} {"source_code": "fun main(args: Array){\n println(\"Karen\")\n}", "src_uid": "1649d2592eadaa8f8d076eae2866cffc"} {"source_code": "import java.io.*\nimport java.util.Comparator\nimport java.util.InputMismatchException\nimport java.util.TreeSet\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\nobject programkt {\n @JvmStatic\n fun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val `in` = InputReader(inputStream)\n val out = OutputWriter(outputStream)\n val solver = Segments()\n solver.solve(1, `in`, out)\n out.close()\n }\n\n internal class Segments {\n fun solve(testNumber: Int, `in`: InputReader, out: OutputWriter) {\n var n = `in`.nextInt()\n val ts = TreeSet(Comparator.comparingInt { x -> x.l })\n while (n-- > 0) {\n val l = `in`.nextInt()\n val r = `in`.nextInt()\n var add = Segments.Interval(l, r)\n while (true) {\n val qq = ts.floor(add)\n if (qq == null || qq.r < add.l) break\n ts.remove(qq)\n add = Segments.Interval(Math.min(qq.l, add.l), Math.max(qq.r, add.r))\n }\n while (true) {\n val qq = ts.ceiling(add)\n if (qq == null || qq.l > add.r) break\n ts.remove(qq)\n add = Segments.Interval(Math.min(qq.l, add.l), Math.max(qq.r, add.r))\n }\n ts.add(add)\n out.println(ts.size)\n }\n }\n\n internal class Interval(var l: Int, var r: Int) {\n\n\n override fun toString(): String {\n return \"Interval{\" +\n \"l=\" + l +\n \", r=\" + r +\n '}'\n }\n\n }\n\n }\n\n internal class InputReader(private val stream: InputStream) {\n private val buf = ByteArray(1 shl 16)\n private var curChar: Int = 0\n private var numChars: Int = 0\n\n fun read(): Int {\n if (this.numChars == -1) {\n throw InputMismatchException()\n } else {\n if (this.curChar >= this.numChars) {\n this.curChar = 0\n\n try {\n this.numChars = this.stream.read(this.buf)\n } catch (var2: IOException) {\n throw InputMismatchException()\n }\n\n if (this.numChars <= 0) {\n return -1\n }\n }\n\n return this.buf[this.curChar++].toInt()\n }\n }\n\n fun nextInt(): Int {\n var c: Int\n c = this.read()\n while (isSpaceChar(c)) {\n c = this.read()\n }\n\n var sgn: Byte = 1\n if (c == 45) {\n sgn = -1\n c = this.read()\n }\n\n var res = 0\n\n while (c >= 48 && c <= 57) {\n res *= 10\n res += c - 48\n c = this.read()\n if (isSpaceChar(c)) {\n return res * sgn\n }\n }\n\n throw InputMismatchException()\n }\n\n companion object {\n\n fun isSpaceChar(c: Int): Boolean {\n return c == 32 || c == 10 || c == 13 || c == 9 || c == -1\n }\n }\n\n }\n\n internal class OutputWriter {\n private val writer: PrintWriter\n\n constructor(outputStream: OutputStream) {\n writer = PrintWriter(BufferedWriter(OutputStreamWriter(outputStream)))\n }\n\n constructor(writer: Writer) {\n this.writer = PrintWriter(writer)\n }\n\n fun close() {\n writer.close()\n }\n\n fun println(i: Int) {\n writer.println(i)\n }\n\n }\n}", "src_uid": "3979abbe7bad0f3b5cab15c1cba19f6b"} {"source_code": "const val HOUR = 60\n\nfun main() {\n val t1 = readHM()\n val t2 = readHM()\n\n val mid = (t1 + t2) / 2\n\n val ans = \"%02d:%02d\".format(mid / HOUR, mid % HOUR)\n\n println(ans)\n}\n\nfun readHM() = readLn().split(':').map { it.toInt() }.let { (h, m) -> h*HOUR + m}\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() }", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50"} {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val numApples = readInt()\n val numSmall = readInts().count { it == 100 }\n print(\n when {\n numSmall == 0 && numApples and 1 == 1 -> \"NO\"\n numSmall and 1 == 1 -> \"NO\"\n else -> \"YES\"\n }\n )\n\n}", "src_uid": "9679acef82356004e47b1118f8fc836a"} {"source_code": "import java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n }\n\n var tok = StringTokenizer(\"\")\n\n fun close() { rd.close(); wr.close() }\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun readToken(): String {\n while (!tok.hasMoreTokens()) tok = StringTokenizer(rd.readLine())\n return tok.nextToken()\n }\n fun readInt() = readToken().toInt()\n fun readLong() = readToken().toLong()\n fun readLine() : String {\n tok = StringTokenizer(\"\")\n return rd.readLine()\n }\n}\n\nfun main(args: Array) {\n Thread({ val io = ProblemIO.console(); solve(io) ; io.close() }).start()\n}\n\nfun solve(io: ProblemIO) {\n val a = io.readInt()\n val b = io.readInt()\n val s = io.readInt()\n val mind = Math.abs(a) + Math.abs(b)\n val res = if (s < mind) false else (s - mind) % 2 == 0\n io.println(if (res) \"Yes\" else \"No\")\n}\n", "src_uid": "9a955ce0775018ff4e5825700c13ed36"} {"source_code": "import kotlin.math.sqrt\n\nfun main() {\n val n = readLong()\n\n val ans = n.factorize().distinct().fold(1L, Long::times)\n\n println(ans)\n}\n\nfun Long.sqrtFloor() = sqrt(toDouble()).toLong()\n\nfun Long.factorize() = sequence {\n val sqrt = sqrtFloor()\n var n = this@factorize\n\n for(p in sequenceOf(2L) + (3..sqrt step 2)) {\n while(n % p == 0L) {\n yield(p)\n n /= p\n }\n if(n == 1L) break\n }\n\n if(n > 1) yield(n)\n}\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readStringSeq() = readLn().splitToSequence(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readIntSeq() = readStringSeq().map { it.toInt() }\nfun readIntArray(size: Int) = readIntSeq().iterator().let { i -> IntArray(size) { i.next() } }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readDoubleSeq() = readStringSeq().map { it.toDouble() }\nfun readDoubleArray(size: Int) = readDoubleSeq().iterator().let { i -> DoubleArray(size) { i.next() } }\nfun readLongs() = readStrings().map { it.toLong() }\nfun readLongSeq() = readStringSeq().map { it.toLong() }\nfun readLongArray(size: Int) = readLongSeq().iterator().let { i -> LongArray(size) { i.next() } }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit) { Output().apply(block).nowPrint() }", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92"} {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val options = listOf(\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\")\n val length = readInt()\n val hint = readLine()!!\n nextOption@ for (option in options) {\n if (option.length != length) continue\n for (pos in option.indices) if (hint[pos] != '.' && hint[pos] != option[pos]) continue@nextOption\n return print(option)\n }\n}", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0"} {"source_code": "fun main(args: Array) {\n val s = readLine()!!\n var source = 0\n var target = s.length - 1\n if (s.length == 1) target = 0\n if (s.length % 2 == 0) target = s.length - 2\n val ar = CharArray(s.length)\n var modifier = -2\n while (source < s.length) {\n ar[target] = s[source]\n source++\n if (target == 0) {\n target = 1\n modifier = 2\n } else\n target += modifier\n }\n println(ar.joinToString(\"\"))\n}", "src_uid": "992ae43e66f1808f19c86b1def1f6b41"} {"source_code": "import java.util.*\n \nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val m = Math.min(sc.nextInt(), sc.nextInt())\n \n var fact: Long = 1\n \n for (i in 1..m) {\n \tfact *= i\n }\n \n println(fact)\n}", "src_uid": "7bf30ceb24b66d91382e97767f9feeb6"} {"source_code": "import kotlin.math.min\n\nfun main() {\n fun min(c: Char, c1: Char) = if (c <= c1) c else c1\n fun max(c: Char, c1: Char) = if (c >= c1) c else c1\n\n val n = readLine()!!.toInt()\n val s = readLine()!!\n val genome = \"ACTG\"\n var sol = Int.MAX_VALUE\n for (start in 0..n - 4) {\n var solCandidate = 0\n for (pos in 0..3) {\n val realPos = start + pos\n val (smaller, bigger) = min(genome[pos], s[realPos]) to max(genome[pos], s[realPos])\n solCandidate += min(bigger - smaller, smaller + 26 - bigger)\n }\n sol = min(sol, solCandidate)\n }\n print(sol)\n}\n", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543"} {"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}", "src_uid": "44fdf71d56bef949ec83f00d17c29127"} {"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", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20"} {"source_code": "\nimport java.util.*\n\n//https://codeforces.com/problemset/problem/723/B\n\nfun main(args: Array) = with(Scanner(System.`in`)){\n val n = nextLine()!!.toInt()\n \n val str = nextLine()!!.toString()\n// println(\"str: $str\")\n val chars = str.toCharArray()\n\n var pStart = false\n var undStart = false\n var wStart = false\n\n var longestW = 0\n var wordsInsideP = 0\n\n var currentWCount = 0\n\n val underScC = '_'\n val pStartC = '('\n val pEndC = ')'\n\n for(c in chars){\n// print(\"current: $c, \")\n if(c == underScC){\n if(wStart){\n wStart = false\n if(pStart){\n wordsInsideP++\n } else {\n if(longestW < currentWCount){\n longestW = currentWCount\n }\n currentWCount = 0\n }\n }\n } else if (c == pStartC){\n pStart = true\n if(wStart) {\n wStart = false\n if(longestW < currentWCount){\n longestW = currentWCount\n }\n currentWCount = 0\n }\n } else if(c == pEndC) {\n pStart = false\n if(wStart) {\n wStart = false\n wordsInsideP++\n }\n } else {\n wStart = true\n if(!pStart){\n currentWCount++\n }\n }\n }\n if(wStart){\n if(longestW < currentWCount){\n longestW = currentWCount\n currentWCount = 0\n }\n }\n println(\"$longestW $wordsInsideP\")\n}\n", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92"} {"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", "src_uid": "2a75f68a7374b90b80bb362c6ead9a35"} {"source_code": "import java.util.*\n\nfun main() {\n\n val scanner = Scanner(System.`in`)\n\n val t = scanner.nextLine().split(' ').map { it.toInt() }\n\n val first = t[0] * t[1] + 2 * t[3]\n val second = t[0] * t[2] + 2 * t[4]\n\n when {\n first < second -> println(\"First\")\n first > second -> println(\"Second\")\n else -> println(\"Friendship\")\n }\n\n\n}\n\n", "src_uid": "10226b8efe9e3c473239d747b911a1ef"} {"source_code": "// modPart is the value of \"x % k\" that minimizes \"x\"\nfun main() {\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n val (n, k) = readLongs()\n var modPart = k - 1\n while (n % modPart != 0L) modPart--\n print((n / modPart * k) + modPart)\n}", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57"} {"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}", "src_uid": "020d5dae7157d937c3f58554c9b155f9"} {"source_code": "\nfun getInt() = readLine()!!.toInt()\nfun getInts() = readLine()!!.split(\" \").map { it.toInt() }\nfun getLong() = readLine()!!.toLong()\nfun getLongs() = readLine()!!.split(\" \").map{ it.toLong()}\nfun getWord() = readLine()!!\nfun getWords() = readLine()!!.split(\" \")\n\n\n\nfun main()\n{\n var nb_moves = getInt()\n var ball_at = getInt()\n var answer = -1\n nb_moves %= 6\n var balls = intArrayOf(0,0,0)\n balls[ball_at] = 1\n for (i in nb_moves downTo 1)\n {\n if ( i % 2 == 0)\n {\n val curr = balls[2]\n balls[2] = balls[1]\n balls[1] = curr\n }\n else\n {\n val curr = balls[1]\n balls[1] = balls[0]\n balls[0] = curr\n }\n }\n answer = balls.indexOf(1)\n println(answer)\n}", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0"} {"source_code": "\n\nfun solution(n:Int,k:Int,l:Int,c:Int,d:Int,p:Int,nl:Int,np:Int) :Int {\n val m = arrayOf(k*l/nl,c*d,p/np).min()!!\n return m/n\n}\n\nfun main(args: Array) {50\n// myassert(solution(3,4,5,10,8,100,3,1),2)\n// myassert(solution(5,100,10,1,19,90,4,3),3)\n// myassert(solution(10,1000, 1000,25,23,1,50,1),0)\n \n val reader = java.util.Scanner(System.`in`)\n val n = reader.nextInt()\n val k = reader.nextInt()\n val l = reader.nextInt()\n val c = reader.nextInt()\n val d = reader.nextInt()\n val p = reader.nextInt()\n val nl = reader.nextInt()\n val np = reader.nextInt()\n\n println(solution(n,k,l,c,d,p,nl,np))\n}", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1"} {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nobject TaskA {\n val ir = InputReader\n\n fun solve() {\n val x = ir.nextInt()\n\n var hours = ir.nextInt()\n var minutes = ir.nextInt()\n\n var total = 0\n\n while (!isLucky(hours, minutes)) {\n if (minutes >= x) {\n minutes -= x\n } else {\n minutes = 60 - (x - minutes)\n\n if (hours > 0) {\n hours--\n } else {\n hours = 23\n }\n }\n\n total++\n }\n\n println(total)\n }\n\n fun isLucky(hours: Int, minutes: Int) =\n hours.toString().contains('7') || minutes.toString().contains('7')\n\n object InputReader {\n val br = BufferedReader(InputStreamReader(System.`in`))\n var st: StringTokenizer? = null\n\n fun next(): String {\n while (st?.hasMoreTokens() != true) {\n st = StringTokenizer(br.readLine())\n }\n\n return st!!.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextFloat() = next().toFloat()\n fun nextDouble() = next().toDouble()\n fun nextLine(): String = br.readLine()\n }\n}\n\nfun main(args: Array) = TaskA.solve()\n", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb"} {"source_code": "import java.util.HashMap\nimport java.util.Scanner\n fun main(args:Array) {\n val sc = Scanner(System.`in`)\n sc.nextInt()\n val s = sc.next()\n println(if (solve(s)) \"Yes\" else \"No\")\n sc.close()\n }\n internal fun solve(s:String):Boolean {\n val colorToCount = HashMap()\n for (color in s.toCharArray())\n {\n colorToCount.put(color, (colorToCount as java.util.Map).getOrDefault(color, 0) + 1)\n }\n return s.length == 1 || colorToCount.values.stream().anyMatch({ count-> count != 1 })\n }", "src_uid": "6b22e93f7e429693dcfe3c099346dcda"} {"source_code": "import java.util.Scanner\n\nfun main(args : Array) {\n val read = Scanner(System.`in`)\n\n val n = read.nextInt()\n if (n % 2 == 1) println(\"contest\")\n else println(\"home\")\n}\n", "src_uid": "51d1c79a52d3d4f80c98052b6ec77222"} {"source_code": "/**\n * Created by denis on 18.06.17.\n */\nfun main(args: Array){\n var (x, s) = readLine()!!.split(' ').map(String::toLong)\n var left: Long = 1\n var right: Long = x\n var f: Long\n if (x - num(x) < s) print(0)\n else {\n while(left < right){\n f = (left + right) / 2\n if(f - num(f) >= s) {\n right = f\n }\n else {\n if((f+1) - num(f+1) >= s){\n right = f + 1\n break\n }\n else\n left = f + 1\n }\n }\n print(x - right + 1)\n\n }\n\n }\npublic fun num(xx: Long): Long {\n var sum: Long = 0\n var x: Long = xx\n while(x > 0){\n sum += x % 10\n x /= 10\n }\n return sum\n}\n\n\n\n", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b"} {"source_code": "fun main() {\n val n = readInt()\n val ans = (n..Int.MAX_VALUE).first { it.toString().sumBy { it - '0' } % 4 == 0 }\n println(ans)\n}\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readLongs() = readStrings().map { it.toLong() }\n", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7"} {"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : InputReader, pw : PrintWriter) {\n\n val n : Int = ir.nextInt()\n val m : Int = ir.nextInt()\n val min : Int = ir.nextInt()\n val max : Int = ir.nextInt()\n val t = IntArray(m)\n var count = 0\n var myMin = 101\n var myMax = 0\n\n for (i in 0 until m)\n t[i] = ir.nextInt()\n\n for (i in 0 until m) {\n if (t[i] < myMin)\n myMin = t[i]\n\n if (t[i] > myMax)\n myMax = t[i]\n }\n\n if (myMax > max || myMin < min)\n pw.print(\"Incorrect\")\n else {\n if (myMax < max)\n count++\n if (myMin > min)\n count++\n\n if (n - m >= count)\n pw.print(\"Correct\")\n else\n pw.print(\"Incorrect\")\n }\n\n}\n\nclass InputReader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}", "src_uid": "99f9cdc85010bd89434f39b78f15b65e"} {"source_code": "import java.lang.Integer.max\nimport java.lang.Integer.min\nimport java.util.HashSet\n\nprivate fun readln() = readLine()!!\nprivate fun readInt() = readln().toInt()\nprivate fun readStrings() = readln().split(\" \")\nprivate fun readInts() = readStrings().map{ it.toInt() }\n\nfun main()\n{\n var n = readInt()\n while(n-- > 0) {\n var trash = readInt()\n var candles = readInts()\n\n var a = 0; var b = candles.size - 1\n var totalA = 0; var totalB = 0;\n var last = 1; var count = 0;\n var turns = 0;\n\n var turn = true\n while (a <= b) {\n if (turn) {\n totalA += candles[a]\n count += candles[a++]\n } else {\n totalB += candles[b]\n count += candles[b--]\n }\n if (count >= last){\n last = count + 1\n count = 0\n turn = !turn\n turns++\n }\n }\n if (count > 0) turns++\n println(\"%d %d %d\".format(turns, totalA, totalB))\n }\n}", "src_uid": "d70ee6d3574e0f2cac3c683729e2979d"} {"source_code": "/**\n * Description: Kotlin tips for dummies\n * Source: own\n */\n\n/* sorting\n * 1 (ok)\n val a = nextLongs().sorted() // a is mutable list\n * 2 (ok)\n val a = arrayListOf() // or ArrayList()\n a.addAll(nextLongs())\n a.sort()\n *.3 (ok)\n val A = nextLongs()\n val a = Array(n,{0})\n for (i in 0..n-1) a[i] = A[i]\n a.sort()\n * 4 (ok)\n val a = ArrayList(nextLongs())\n a.sort()\n * 5 (NOT ok)\n val a = LongArray(N) // or nextLongs().toLongArray()\n Arrays.sort(a)\n */\n/* 2D array\n * val ori = Array(n, {IntArray(n)})\n * val ori = arrayOf(\n intArrayOf(8, 9, 1, 13),\n intArrayOf(3, 12, 7, 5),\n intArrayOf(0, 2, 4, 11),\n intArrayOf(6, 10, 15, 14)\n )\n */\n/* printing variables:\n * println(\"${l+1} and $r\")\n * print d to 8 decimal places: String.format(\"%.8g%n\", d)\n * try to print one stringbuilder instead of multiple prints\n */\n/* comparing pairs\n val pq = PriorityQueue>({x,y -> x.first.compareTo(y.first)})\n val pq = PriorityQueue>(compareBy {it.first})\n val A = arrayListOf(Pair(1,3),Pair(3,2),Pair(2,3))\n val B = A.sortedWith(Comparator>{x,y -> x.first.compareTo(y.first)})\n sortBy\n */\n/* hashmap\n val h = HashMap()\n for (i in 0..n-2) {\n val w = s.substring(i,i+2)\n val c = h.getOrElse(w){0}\n h.put(w,c+1)\n }\n */\n/* basically switch, can be used as expression\n when (x) {\n 0,1 -> print(\"x <= 1\")\n 2 -> print(\"x == 2\")\n else -> { // Note the block\n print(\"x is neither 1 nor 2\")\n }\n }\n*/\n// swap : a = b.also { b = a }\n// arraylist remove element at index: removeAt, not remove ...\n// lower bound: use .binarySearch()\n\nimport java.util.*\n// import kotlin.math.*\n\nval MOD = 1000000007\nval SZ = 1 shl 18\nval INF = (1e18).toLong()\n\nfun add(a: Int, b: Int) = (a+b) % MOD // from tourist :o\nfun sub(a: Int, b: Int) = (a-b+MOD) % MOD\nfun mul(a: Int, b: Int) = ((a.toLong() * b) % MOD).toInt()\nfun po(a: Int, b: Int): Int {\n if (b == 0) return 1\n var res: Int = po(mul(a,a),b/2)\n if ((b and 1) == 1) res = mul(res,a)\n return res\n}\n\nfun next() = readLine()!!\nfun nextInt() = next().toInt()\nfun nextLong() = next().toLong()\nfun nextInts() = next().split(\" \").map { it.toInt() }\nfun nextLongs() = next().split(\" \").map { it.toLong() }\n\nval out = StringBuilder()\nfun YN(b: Boolean):String { return if (b) \"YES\" else \"NO\" }\n\nfun gcd(a: Int, b: Int): Int {\n return if (a == 0) b else gcd(b%a,a)\n}\n\nfun bad() {\n println(-1)\n System.exit(0)\n}\n\nfun ari(a: Int, b: Int): Long {\n return (a+b).toLong()*(b-a+1)/2\n}\n\nfun get(a: Int, b: Int): Long {\n if (a <= 0) return 1-a+ari(1,b)\n return ari(a,b)\n}\nfun get(n: Int, k: Int, mid: Int) : Long {\n var res: Long = mid.toLong()\n // println(\"HA ${cur}\")\n // cur-(k-1) to cur-1\n res += get(mid-(k-1),mid-1)\n res += get(mid-(n-k),mid-1)\n return res\n}\n\nfun solve() {\n val (n,m,k) = nextInts()\n var (lo, hi) = arrayOf(1,m)\n // println(get(n,k,5))\n while (lo < hi) {\n val mid = (lo+hi+1)/2\n if (get(n,k,mid) <= m) lo = mid\n else hi = mid-1\n }\n println(lo)\n}\n\nfun main(args: Array) {\n solve()\n}", "src_uid": "da9ddd00f46021e8ee9db4a8deed017c"} {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (_, length) = readInts()\n val segmentLengths = readInts().sortedDescending()\n for (segment in segmentLengths) {\n if (length % segment == 0) return print(length / segment)\n }\n}", "src_uid": "80520be9916045aca3a7de7bc925af1f"} {"source_code": "fun main() {\n val length = readLine()!!.toInt()\n val values = readLine()!!.toCharArray().map { it.toInt() - 48 }\n val total = values.sum()\n var sum = 0\n var result = false\n for (pos in 0 until length - 1) {\n sum += values[pos]\n if (sum != 0 && sum != total && total % sum == 0) {\n result = solve(values, length, sum, pos + 1)\n if (result) break\n }\n }\n print(if (result || (sum == 0 && total == 0)) \"YES\" else \"NO\")\n}\n\nfun solve(values: List, length: Int, sum: Int, initialPos: Int): Boolean {\n var otherSum = 0\n for (pos in initialPos until length) {\n otherSum += values[pos]\n if (otherSum == sum) {\n otherSum = 0\n } else if (otherSum > sum) {\n return false\n }\n }\n return otherSum == 0\n}\n", "src_uid": "410296a01b97a0a39b6683569c84d56c"} {"source_code": "\nimport java.io.BufferedInputStream\nimport java.io.File\nimport java.io.PrintWriter\nimport kotlin.system.measureTimeMillis\n\ninline fun TIME(f:()->Unit){\n val t = measureTimeMillis(){\n f()\n }\n println(\"$t ms\")\n}\n\nobject IO{\n private const val BS = 1 shl 16\n private const val NC = 0.toChar()\n private val buf = ByteArray(BS)\n private var bId = 0\n private var size = 0\n private var c = NC\n\n var warningActive = true\n var fakein = StringBuilder()\n\n private var IN: BufferedInputStream = BufferedInputStream(System.`in`, BS)\n val OUT: PrintWriter = PrintWriter(System.out)\n\n private val char: Char\n get() {\n while (bId == size) {\n size = IN.read(buf) // no need for checked exceptions\n if (size == -1) return NC\n bId = 0\n }\n return buf[bId++].toChar()\n }\n\n fun nextInt(): Int {\n var neg = false\n if (c == NC) c = char\n while (c < '0' || c > '9') {\n if (c == '-') neg = true\n c = char\n }\n var res = 0\n while (c in '0'..'9') {\n res = (res shl 3) + (res shl 1) + (c - '0')\n c = char\n }\n return if (neg) -res else res\n }\n fun nextLong(): Long {\n var neg = false\n if (c == NC) c = char\n while (c < '0' || c > '9') {\n if (c == '-') neg = true\n c = char\n }\n var res = 0L\n while (c in '0'..'9') {\n res = (res shl 3) + (res shl 1) + (c - '0')\n c = char\n }\n return if (neg) -res else res\n }\n fun nextString():String{\n val ret = StringBuilder()\n while (true){\n c = char\n if(!isWhitespace(c)){ break}\n }\n ret.append(c)\n while (true){\n c = char\n if(isWhitespace(c)){ break}\n ret.append(c)\n }\n return ret.toString()\n }\n fun isWhitespace(c:Char):Boolean{\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t'\n }\n fun rerouteInput(){\n if(warningActive){\n put(\"You forgot to disable tests you digital dummy!\")\n println(\"You forgot to disable tests you digital dummy!\")\n warningActive = false\n }\n val S = fakein.toString()\n println(\"New Case \")\n println(S.take(80))\n println(\"...\")\n fakein.clear()\n IN = BufferedInputStream(S.byteInputStream(),BS)\n }\n fun takeFile(name:String){\n IN = BufferedInputStream(File(name).inputStream(),BS)\n }\n}\nfun put(aa:Any){ IO.OUT.println(aa)}\nfun done(){ IO.OUT.close() }\nfun share(aa:Any){\n if(aa is IntArray){IO.fakein.append(aa.joinToString(\" \"))}\n else if(aa is LongArray){IO.fakein.append(aa.joinToString(\" \"))}\n else if(aa is List<*>){IO.fakein.append(aa.toString())}\n else{IO.fakein.append(aa.toString())}\n IO.fakein.append(\"\\n\")\n}\n\nval getint:Int get() = IO.nextInt()\nval getlong:Long get() = IO.nextLong()\nval getstr:String get() = IO.nextString()\nfun getline(n:Int):IntArray{\n return IntArray(n){getint}\n}\nfun getlineL(n:Int):LongArray{\n return LongArray(n){getlong}\n}\nfun getbinary(n:Int, asTrue:Char):BooleanArray{\n val str = getstr\n return BooleanArray(n){str[it] == asTrue}\n}\n\nval List.ret:String\nget() = this.joinToString(\"\")\nvar dmark = -1\ninfix fun Any.dei(a:Any){\n //does not stand for anything it is just easy to type, have to be infix because kotlin does not have custom prefix operators\n dmark++\n var str = \"<${dmark}> \"\n debug()\n if(this is String){ str += this\n }else if(this is Int){ str += this.toString()\n }else if(this is Long){ str += this.toString()\n }else{ str += this.toString()}\n if(a is List<*>){ println(\"$str : ${a.joinToString(\" \")}\")\n }else if(a is IntArray){ println(\"$str : ${a.joinToString(\" \")}\")\n }else if(a is LongArray){ println(\"$str : ${a.joinToString(\" \")}\")\n }else if(a is BooleanArray){ println(\"$str :${a.map{if(it)'1' else '0'}.joinToString(\" \")}\")\n }else if(a is Array<*>){\n println(\"$str : \")\n for(c in a){if(c is IntArray){println(c.joinToString(\" \"))}\n else if(c is LongArray){println(c.joinToString(\" \"))}\n else if(c is BooleanArray){println(c.map { if(it) '1' else '0' }.joinToString(\"\"))\n }\n\n }\n println()\n }else{ println(\"$str : $a\")\n }\n}\nval just = \" \" // usage: just dei x , where x is the debug variable\nfun crash(){\n throw Exception(\"Bad programme\")} // because assertion does not work\nfun assert(a:Boolean){\n if(!a){\n throw Exception(\"Failed Assertion\")\n }}\nenum class solveMode {\n real, rand, tc\n}\nobject solve{\n var mode:solveMode = solveMode.real\n var tcNum:Int = 0\n var rand:()->Unit = {}\n var TC:MutableMapUnit> = mutableMapOf()\n var answersChecked = 0\n var tn:Long = 0\n fun cases(onecase:()->Unit){\n val t = if(mode == solveMode.real){if(singleCase) 1 else getint} else if(mode == solveMode.tc){1 } else randCount\n //safety checks\n if(pI != 998_244_353 && pI != 1_000_000_007){\n throw Exception(\"Modding a wrong prime!\")\n }\n if(withBruteForce){\n println(\"Brute force is active\")\n }\n\n if(t == 1 && mode != solveMode.real){\n tn = System.currentTimeMillis()\n }\n repeat(t){\n if(mode == solveMode.tc){\n TC[tcNum]?.let { it() }\n IO.rerouteInput()\n }else if(mode == solveMode.rand){\n rand()\n IO.rerouteInput()\n }\n onecase()\n }\n if(t == 1 && mode != solveMode.real){\n val dt = System.currentTimeMillis() - tn\n println(\"Time $dt ms \")\n }\n }\n inline fun singleCase(a:solve.()->Unit){\n val t = if(mode != solveMode.rand){1} else randCount\n repeat(t) { a() }\n }\n fun rand(a:()->Unit){\n this.rand = a\n }\n fun tc(id:Int = 0,a:()->Unit){\n TC[id] = a\n }\n fun usetc(a:Int = 0 ){\n this.tcNum = a\n this.mode = solveMode.tc\n }\n fun userand(){\n this.mode = solveMode.rand\n }\n}\ninline fun T.alsoBrute(cal:() -> T){\n if(!withBruteForce) return\n val also = cal()\n if(this != also){\n println(\"Checking failed: Got ${this} Brute ${also}\")\n crash()\n }\n}\n// 1. Modded\nconst val p = 998244353L\nconst val pI = p.toInt()\nfun Int.adjust():Int{ if(this >= pI){ return this - pI }else if (this < 0){ return this + pI };return this }\nfun Int.snap():Int{ if(this >= pI){return this - pI} else return this}\ninfix fun Int.modM(b:Int):Int{ return ((this * 1L * b) % pI).toInt() }\ninfix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }\n// 2. DP initial values\nconst val plarge = 1_000_000_727\nconst val nlarge = -plarge\nconst val phuge = 2_727_000_000_000_000_000L\nconst val nhuge = -phuge\n// 3. conveniecen conversions\nval Boolean.chi:Int get() = if(this) 1 else 0 //characteristic function\nval Char.code :Int get() = this.toInt() - 'a'.toInt()\n//3. hard to write stuff\nfun IntArray.put(i:Int,v:Int){ this[i] = (this[i] + v).adjust() }\nval mint:MutableList get() = mutableListOf()\nval mong:MutableList get() = mutableListOf()\n//4. more outputs\nfun List.conca():String = this.joinToString(\"\")\nval CharArray.conca :String get() = this.joinToString(\"\")\nval IntArray.conca :String get() = this.joinToString(\" \")\n@JvmName(\"concaInt\")\nfun List.conca():String = this.joinToString(\" \")\nval LongArray.conca:String get() = this.joinToString(\" \")\n@JvmName(\"concaLong\")\nfun List.conca():String = this.joinToString(\" \")\n//5. Pair of ints\nconst val longmask = (1L shl 32) - 1\nfun makepair(a:Int, b:Int):Long = (a.toLong() shl 32) xor (longmask and b.toLong()) // remember positev sonly\nval Long.first get() = (this ushr 32).toInt()\nval Long.second get() = this.toInt()\n//6. strings\nval String.size get() = this.length\nconst val randCount = 100\n\n\n\ninfix fun Int.divCeil(b:Int):Int{\n //Positives numbers only!\n if(this == 0) {\n return 0\n }\n return (this-1)/b + 1\n}\ninfix fun Long.divCeil(b:Long):Long{\n //Positives numbers only!\n if(this == 0L) {\n return 0\n }\n return (this-1)/b + 1\n}\n\ninfix fun Long.modM(b:Long):Long{\n return (this * b) % p\n}\n//infix fun Int.modPlus(b:Int):Int{\n// val ans = this + b\n// return if(ans >= pI) ans - pI else ans\n//}\ninfix fun Int.modMinus(b:Int):Int{\n val ans = this - b\n return if(ans < 0) ans + pI else ans\n}\ninfix fun Int.modDivide(b:Int):Int{\n return this modM (b.inverse())\n}\nfun Int.additiveInverse():Int{\n return if(this == 0) 0 else pI - this\n}\n\n\nfun intPow(x:Int,e:Int,m:Int):Int{\n var X = x\n var E =e\n var Y = 1\n while(E > 0){\n if(E % 2 == 0){\n X = ((1L * X * X) % m).toInt()\n E = E shr 1\n }else{\n Y = ((1L * X * Y) % m).toInt()\n E -= 1\n }\n }\n return Y\n}\nfun intPowEXP(x:Int,e:Long,m:Int):Int{\n var X = x\n var E =e\n var Y = 1\n while(E > 0){\n if(E % 2 == 0L){\n X = ((1L * X * X) % m).toInt()\n E = E shr 1\n }else{\n Y = ((1L * X * Y) % m).toInt()\n E -= 1\n }\n }\n return Y\n}\n\nfun pow(x:Long,e:Long,m:Long):Long{\n var X = x\n var E =e\n var Y = 1L\n while(E > 0){\n if(E % 2 == 0L){\n X = (X * X) % m\n E /= 2\n }else{\n Y = (X * Y) % m\n E -= 1\n }\n }\n return Y\n}\nfun Long.inverse():Long{\n return pow(this,p-2,p)\n}\nfun Int.inverse():Int{\n return intPow(this,pI-2,pI)\n}\nfun min_rem(m:Int, r:Int, c:Int):Int {\n if(c < 1){\n return Int.MIN_VALUE\n }else if(r == 0){\n return 0\n }else{\n val step = m % r\n val mx = ((1L * c * r) /m ).toInt()\n val t = max_rem(r,step,mx)\n return r- t\n }\n}\nfun max_rem(m:Int, r:Int, c:Int):Int {\n if(r == 0|| c <= m/r){\n return r * c\n }else{\n val step = m % r\n val mx = ((1L * (c+1) * r )/m).toInt()\n val t = min_rem(r,step,mx)\n return m - t\n }\n}\nfun Int.reconstruct():String{\n val num = min_rem(pI,this, 10000)\n val denom = (this modDivide num).inverse()\n return \"$num / $denom\"\n}\n\n//make this int instead\nclass FACT{\n companion object {\n var store = IntArray(0)\n var invStore = IntArray(0)\n\n var slowStore:IntArray = IntArray(0)\n\n fun preCal(upto:Int){\n store = IntArray(upto+1)\n invStore = IntArray(upto + 1 )\n store[0] = 1\n invStore[0] = 1\n\n for(i in 1..upto) {\n store[i] = store[i-1] modM i\n invStore[i] = invStore[i-1] modM (i.inverse())\n }\n }\n fun choose(n:Int,r:Int):Int{\n if(r < 0 || r > n) return 0\n val a = store[n]\n val b = invStore[n-r]\n val c = invStore[r]\n return (a modM b) modM c\n }\n\n fun bigChoose(n:Int,r:Int):Int{\n var ret = 1\n for(i in 0 until r){\n ret = ret modM (n - i)\n }\n ret = ret modM (invStore[r])\n return ret\n }\n\n }\n}\n\nfun debug(){}\nconst val withBruteForce = false\nconst val singleCase = true\nfun main(){\n FACT.preCal(300)\n solve.cases{\n\n val n = getint\n val k = getint\n\n //phrases, MAX\n val DP = Array(n){IntArray(k+1)}\n val sum = Array(n){IntArray(k+1)}\n\n DP[0][0] = FACT.store[n-1]\n for(max in 0..k){\n sum[0][max] = FACT.store[n-1]\n }\n// sum[0][0] = FACT.store[n]\n\n for(p in 1 until n){\n for(max in 1..k){\n var now = 0\n var totalop = 0\n for(op in p-1 downTo 0 ){\n totalop += op\n now = now modPlus (sum[op][max-1] modM FACT.invStore[p-op] modM intPow(k-max+1,totalop,pI))\n }\n DP[p][max] = now\n }\n for(max in 0..k){\n sum[p][max] = DP[p][max]\n if(max > 0){\n sum[p][max] = sum[p][max-1] modPlus sum[p][max]\n }\n }\n }\n var ret = 0\n for(c in DP.last()){\n ret = ret modPlus c\n }\n\n put(ret)\n\n\n }\n done()\n}\n\n\n/*\n\n3 3\n\ncosts are\n1,1,2,..,n\n\n1 2 3 3 4 5\n1 2 3 3 4 5\n\n\n1 2\n2 1\n3 4\n4 3\nmax of hte two things then product\n\n */\n\n", "src_uid": "b2d7ac8e75cbdb828067aeafd803ac62"} {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val cubes = (1..n).map { readLine()!!.split(\" \").map(String::toInt) }\n val combination = mutableListOf()\n\n cubes\n .flatMap { it }\n .forEach { it -> combination += \"$it\" }\n\n for (i in cubes.indices) {\n for (j in (i + 1) until cubes.size) {\n for (x in 0 until 6) {\n for (y in 0 until 6) {\n combination += \"${cubes[i][x]}${cubes[j][y]}\"\n combination += \"${cubes[j][x]}${cubes[i][y]}\"\n }\n }\n }\n }\n\n if (cubes.size == 3)\n for (i in 0 until 6) {\n for (j in 0 until 6) {\n for (k in 0 until 6) {\n combination += \"${cubes[0][i]}${cubes[1][j]}${cubes[2][k]}\"\n combination += \"${cubes[2][i]}${cubes[0][j]}${cubes[1][k]}\"\n combination += \"${cubes[1][i]}${cubes[2][j]}${cubes[0][k]}\"\n combination += \"${cubes[0][i]}${cubes[2][j]}${cubes[1][k]}\"\n combination += \"${cubes[1][i]}${cubes[0][j]}${cubes[2][k]}\"\n combination += \"${cubes[2][i]}${cubes[1][j]}${cubes[0][k]}\"\n }\n }\n }\n\n (1..999).forEach {\n if (!combination.any { x -> x.toInt() == it }) {\n println(it - 1)\n return\n }\n }\n}", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b"} {"source_code": "import kotlin.math.min\n\n/* https://codeforces.com/problemset/problem/581/A */\n\nfun main() {\n val (numOfRedSocks, numOfBlueSocks) = readLine()!!.split(\" \").map { it.toInt() }\n val maxDaysWearingDiffSocks = min(numOfRedSocks, numOfBlueSocks)\n val daysWearingSameColorSocks = (numOfRedSocks + numOfBlueSocks - maxDaysWearingDiffSocks * 2) / 2\n println(\"$maxDaysWearingDiffSocks $daysWearingSameColorSocks\")\n}", "src_uid": "775766790e91e539c1cfaa5030e5b955"} {"source_code": "import java.io.InputStream\n\nconst val CODE_0 = '0'.toByte()\nconst val CODE_1 = '9'.toByte()\n\nclass Main {\n companion object {\n @JvmStatic\n fun main(args: Array) = with(FastScanner(System.`in`)) {\n val n = nextInt()\n val a = IntArray(n + 1)\n for (i in 1..n) a[i] = nextInt()\n\n val p = IntArray(n + 1)\n for (i in 1..n) p[i] = p[i - 1] + if (a[i] == 1) 1 else 0\n\n var m = 0\n val all = p[n] - p[0]\n for (i in 1..n) for (j in i..n) {\n val cut = p[j] - p[i - 1]\n val x = all - cut + (j - i + 1) - cut\n if (x > m) m = x\n }\n println(m)\n }\n }\n\n\n // -----------------------------------------------------------------------------------------------------------------\n\n private class FastScanner(private val iss: InputStream = System.`in`) {\n fun nextInt(): Int { // todo negative\n var v = 0\n var begin = false\n while (true) {\n val c = iss.read()\n if (c in CODE_0..CODE_1) {\n begin = true\n v *= 10\n v += c - CODE_0\n } else if (begin) {\n return v\n }\n }\n }\n }\n}\n\nfun main(args: Array) = Main.main(args)", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99"} {"source_code": "import kotlin.math.*\n\nprivate fun nextLine() = readLine()!!\nprivate fun nextInt() = nextLine().toInt()\nprivate fun nextToks() = nextLine().split(\" \")\nprivate fun nextInts() = nextToks().map{it.toInt()}\n\nfun h(x: Int, m: Int): Int {\n if (x >= m) return x - m\n if (m % 2 != 0) return 1 + h(x, m+1)\n return 1 + h(x, m / 2)\n}\n\nfun main() {\n val (n, m) = nextInts()\n println(h(n,m))\n}\n", "src_uid": "861f8edd2813d6d3a5ff7193a804486f"} {"source_code": "fun csort(lst: Array)\n{\n val arr = Array(3, {0})\n lst.forEach { arr[it - 1]++ }\n var cur = 0\n for (i in 0 until 3)\n for (j in 0 until arr[i])\n lst[cur++] = i + 1\n}\n\nfun main(args: Array)\n{\n val inp = readLine()!!.split('+').map(String::toInt).toTypedArray()\n csort(inp)\n for (i in inp.indices)\n {\n if (i > 0)\n print('+')\n print(inp[i])\n }\n println()\n}", "src_uid": "76c7312733ef9d8278521cf09d3ccbc8"} {"source_code": "import java.io.BufferedReader\nimport java.io.FileReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\nimport kotlin.math.abs\nimport java.util.Queue as Queue\n\nval INF = 2e9.toInt()\n\nfun solve(){\n val n = readInt()\n\n val map = mapOf(Pair('k', 0), Pair('o', 1), Pair('t', 2), Pair('l', 3), Pair('i', 4), Pair('n', 5))\n val g = Array(6, {i -> Array(6, {ArrayDeque()})})\n val cnt = Array(6, {Array(6, {0})})\n for(i in 0 until n){\n val ss = readString()\n val s = map[ss[0]]\n var e = map[ss.last()]\n if(s == null || e == null) continue\n e = (e + 1) % 6\n g[s][e].add(i)\n cnt[s][e]++\n }\n\n val st = ArrayDeque()\n st.push(0)\n\n val ans = ArrayList()\n\n while(!st.isEmpty()){\n val v = st.peek()\n var good = false\n for(u in 0 until 6){\n if(cnt[v][u] > 0){\n good = true\n st.push(u)\n cnt[v][u]--\n break\n }\n }\n if(!good){\n ans.add(v)\n st.pop()\n }\n }\n\n ans.reverse()\n val res = ArrayList()\n\n for(i in 1 until ans.size){\n val from = ans[i - 1]\n val to = ans[i]\n val id = g[from][to].poll()\n res.add(id + 1)\n }\n\n for(i in res) print(\"$i \")\n}\n\nfun main() {\n //var t = readInt()\n var t = 1\n while(t --> 0) solve()\n out.println()\n out.close()\n}\n\nval input = BufferedReader(\n InputStreamReader(System.`in`)\n)\nval out =\n PrintWriter(\"output.txt\")\n\nfun readNullableLine(): String? = input.readLine()\n\nclass MultipleTestsEndException: Exception()\n\nfun readLine(): String {\n val line = readNullableLine()\n if (null == line) {\n throw MultipleTestsEndException()\n } else {\n return line\n }\n}\n\nfun readStrings(separator: String = \" \", emptyWords: Boolean = false) : List =// val line = readLine()\n readLine().split(separator)\n\nfun readString(separator: String = \" \") =\n readStrings(separator).first()\n\nfun readInts(separator: String = \" \") =\n readStrings(separator).map(String::toInt).toIntArray()\n\nfun readInt(separator: String = \" \") =\n readInts(separator).first()\n\nfun readLongs(separator: String = \" \") =\n readStrings(separator).map(String::toLong).toLongArray()\n\nfun readLong(separator: String = \" \") =\n readLongs(separator).first()\n\nfun readDoubles(separator: String = \" \") =\n readStrings(separator).map(String::toDouble).toDoubleArray()\n\nfun readDouble(separator: String = \" \") =\n readDoubles(separator).first()\n", "src_uid": "a853ca8432d7b8966b12fc85c28ab979"} {"source_code": "import java.io.*\nimport java.util.*\n\nclass ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {\n companion object {\n fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))\n }\n\n var tok = StringTokenizer(\"\")\n\n fun close() { rd.close(); wr.close() }\n fun print(v: T) = wr.print(v)\n fun println(v: T) = wr.println(v)\n fun readToken(): String {\n while (!tok.hasMoreTokens()) tok = StringTokenizer(rd.readLine())\n return tok.nextToken()\n }\n fun readInt() = readToken().toInt()\n fun readLong() = readToken().toLong()\n fun readLine() : String {\n tok = StringTokenizer(\"\")\n return rd.readLine()\n }\n}\n\nfun main(args: Array) {\n Thread({ val io = ProblemIO.console(); solve(io) ; io.close() }).start()\n}\n\nfun solve(io: ProblemIO) {\n val n = io.readInt()\n val x = io.readInt()\n var r = 0\n for (i in 1 .. n) {\n val div = x / i\n var mod = x % i\n if (mod == 0 && div >= 1 && div <= n) {\n r += 1\n }\n }\n io.println(r)\n}\n", "src_uid": "c4b139eadca94201596f1305b2f76496"} {"source_code": "import java.io.*;\nimport java.io.BufferedReader\nimport java.util.*\nimport kotlin.math.min\nimport kotlin.math.max\n\nfun solve(){\n val (b,g,n) = readInts(3)\n print(min(n, b) - max(0, n - g) + 1)\n}\n\nfun main(args: Array) {\n if (args.isNotEmpty() && args.first() == \"file\") {\n reader = BufferedReader(FileReader(\"input.txt\"))\n out = PrintWriter(FileWriter(\"output.txt\"))\n do {\n solve()\n out.println(\"\\n\")\n out.flush()\n } while (reader.readLine() != null)\n } else {\n reader = BufferedReader(InputStreamReader(System.`in`))\n out = PrintWriter(OutputStreamWriter(System.out))\n solve()\n }\n reader.close()\n out.close()\n}\n\nlateinit var out:PrintWriter\nlateinit var reader: BufferedReader\nvar tokenizer: StringTokenizer? = null\nfun read(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(readLn())\n }\n return tokenizer!!.nextToken()\n}\nfun readInt() = read().toInt()\nfun readLong() = read().toLong()\nfun readLn() = reader.readLine()!!\nfun readInts() = readLn().split(\" \").map{it.toInt()}\nfun readInts(sz:Int) = Array(sz){readInt()}\nfun readLongs() = readLn().split(\" \").map{it.toLong()}\nfun readLongs(sz:Int) = Array(sz){readLong()}\nfun print(b:Boolean) = out.print(b)\nfun print(i:Int) = out.print(i)\nfun print(d:Double) = out.print(d)\nfun print(l:Long) = out.print(l)\nfun print(s:String) = out.print(s)\nfun print(message: Any?) = out.print(message)\nfun print(a: Array) = a.forEach { print(\"$it \") }\nfun print(a: Array) = a.forEach { print(\"$it \") }\nfun print(a: Collection) = a.forEach { print(\"$it \") }\nfun println(b:Boolean) = out.println(b)\nfun println(i:Int) = out.println(i)\nfun println(d:Double) = out.println(d)\nfun println(l:Long) = out.println(l)\nfun println(s:String) = out.println(s)\nfun println() = out.println()\nfun println(message: Any?) = out.println(message)\nfun println(a: Array) {\n a.forEach { print(\"$it \") }\n println()\n}\nfun println(a: Collection) {\n a.forEach { print(\"$it \") }\n println()\n}\nconst val M7 = 1000000007L\nconst val M9 = 1000000009L\nconst val MFFT = 998244353L\nfun zero(sz:Int) = IntArray(sz)\nfun zeroL(sz:Int) = LongArray(sz)\nfun init(vararg elements: T) = elements\nfun VI(n:Int = 0, init:Int = 0) = MutableList(n){init}\nfun VVI(n:Int = 0, m:Int = 0, init:Int = 0) = MutableList(n){VI(m,init)}\nfun, T2:Comparable> pairCmp(): Comparator> {\n return Comparator { a, b ->\n val res = a.first.compareTo(b.first);\n return@Comparator if (res == 0) a.second.compareTo(b.second) else res;\n }\n}\n", "src_uid": "9266a69e767df299569986151852e7b1"} {"source_code": "class MisterBReader(val c: Int,\n val v0: Int,\n val v1: Int,\n val a: Int,\n val l: Int\n) {\n var v = v0\n var readedPages = 0\n \n fun getDaysToRead() : Int {\n var days = 1\n readedPages += v\n while(readedPages < c) {\n readedPages -= l\n v = when {\n v >= v1 -> v\n v + a > v1 -> v1\n else -> v + a\n }\n readedPages += v\n days++\n }\n return days\n }\n}\n\n\nfun main(args: Array) {\n val(c, v0, v1, a, l) = readLine()!!.split(' ').map(String::toInt)\n println(MisterBReader(c, v0, v1, a, l).getDaysToRead())\n}", "src_uid": "b743110117ce13e2090367fd038d3b50"} {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val reader = Scanner(System.`in`)\n val nthNumber = reader.nextInt()\n var numbers = \"\"\n for (i in 1 until 1001)\n numbers += i\n println(numbers[nthNumber-1])\n}\n", "src_uid": "2d46e34839261eda822f0c23c6e19121"} {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numLights, _) = readInts()\n val buttons = readInts()\n val lights = IntArray(numLights)\n for (button in buttons) {\n for (pos in button - 1 until lights.size)\n if (lights[pos] == 0) lights[pos] = button\n }\n print(lights.joinToString(\" \"))\n}", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863"} {"source_code": "import java.util.Scanner\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n val m = scanner.nextInt()\n scanner.nextLine()\n val str = scanner.nextLine().toString()\n val pupils = str\n .split(\" \")\n .map { it.trim().toInt() }\n .toIntArray()\n\n val result = mutableListOf()\n val sorted = mutableListOf()\n\n pupils.forEach { p ->\n sorted.sortDescending()\n val sum = sorted.sum() + p\n\n if (sum <= m) {\n result.add(0)\n } else {\n var decrementSum = sum\n var skip = 0\n\n for (i in 0 until sorted.size) {\n decrementSum -= sorted[i]\n skip++\n if (decrementSum <= m) {\n result.add(skip)\n break\n }\n }\n\n }\n\n sorted.add(p)\n }\n\n result.forEach {\n print(it)\n print(\" \")\n }\n}", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346"} {"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", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881"} {"source_code": "const val MOD = 1000000007L\n\nfun main() {\n val (a, b, k, t) = readLine()!!.split(\" \").map { it.toInt() }\n val n = (2 * t * k) + 100\n var dpPrev = LongArray((2 * n) + 1)\n var dpNext = LongArray((2 * n) + 1)\n dpPrev[a - b + n] = 1L\n for (turn in 1..2 * t) {\n dpNext[0] = 0L\n for (j in 0..k) {\n dpNext[0] += dpPrev[j]\n }\n dpNext[0] %= MOD\n for (j in 1..2 * n) {\n dpNext[j] = dpNext[j - 1]\n if (j + k <= 2 * n) {\n dpNext[j] += dpPrev[j + k]\n }\n if (j - k > 0) {\n dpNext[j] -= dpPrev[j - k - 1]\n }\n dpNext[j] %= MOD\n }\n val temp = dpPrev\n dpPrev = dpNext\n dpNext = temp\n }\n var answer = 0L\n for (j in n + 1..2 * n) {\n answer += dpPrev[j]\n answer %= MOD\n }\n answer += MOD\n answer %= MOD\n println(answer)\n}", "src_uid": "8b8327512a318a5b5afd531ff7223bd0"} {"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 println(dangerous(s))\n}\n\nfun dangerous (s: String): String{\n tailrec fun go (s: String, cnt: Int, prev: Int): String =\n if (cnt == 7) \"YES\"\n else if (s.isEmpty()) \"NO\"\n else {\n val num = s.first() - '0'\n if (num == prev) go(s.drop(1), cnt + 1, num)\n else go(s.drop(1), 1, num)\n }\n return go(s.drop(1), 1, s.first() - '0')\n}", "src_uid": "ed9a763362abc6ed40356731f1036b38"} {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n\n val n = sc.nextInt()\n val s = sc.nextInt()\n println((s - 1) / n + 1)\n}\n", "src_uid": "04c067326ec897091c3dbcf4d134df96"} {"source_code": "import java.util.*\n\nfun main(args: Array) { var reader = Scanner(System.`in`)\n var n:Int = reader.nextInt()\n var array = Array(n, {IntArray(n)})\n var (Tcounter:Int,Scounter:Int)= arrayOf(0,0)\n for (i in 0 until n)\n {\n for (j in 0 until n)\n {\n array[i][j]= reader.nextInt()\n }\n }\n for (i in 0 until n)\n {\n for (j in 0 until n)\n {\n Tcounter+=array[i][j]\n }\n }\n for (i in 0 until n)\n {\n for (j in 0 until n)\n {\n if (i!=j && i!=(n-1)/2 && j!=(n-1)/2 && j!=n-1-i)\n Scounter+=array[i][j]\n }\n }\n print(Tcounter-Scounter)\n\n\n}", "src_uid": "5ebfad36e56d30c58945c5800139b880"} {"source_code": "fun main() {\n var n = readLine()!!.toInt()\n var m = readLine()!!.toInt()\n\n var i = 1\n var ans = 1\n var toPrint = 0\n var flag = true\n while (i <= n && flag) {\n ans *= 2\n if (ans > m) {\n toPrint = m\n flag = false\n }\n i++\n }\n if (flag){\n println(m%ans)\n }else{\n println(m)\n }\n\n\n}\n\n", "src_uid": "c649052b549126e600691931b512022f"} {"source_code": "import java.util.*\n\nfun main() {\n readLine()\n val a = readLine()!!.split(\" \").map{ x -> x.toLong() }.toMutableList()\n a.sort()\n\n val queue = LinkedList(a)\n var cnt = 0\n\n while (queue.isNotEmpty()) {\n val f = queue.first\n cnt++\n\n for (e in a) {\n if (e%f==0L) {\n queue.remove(e)\n }\n }\n }\n\n println(cnt)\n}", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd"} {"source_code": "@file:Suppress(\"EXPERIMENTAL_API_USAGE\")\r\n\r\nimport Utils.ArrayUtils.Companion.arrayOfNullsSafe\r\nimport Utils.ArrayUtils.Companion.makeDistinct\r\nimport Utils.ArrayUtils.Companion.toNotNulls\r\nimport Utils.ArrayUtils.Prints.Companion.println\r\nimport Utils.ArrayUtils.Sorts.Companion.countSort\r\nimport Utils.ArrayUtils.Sorts.Companion.shuffleSort\r\nimport Utils.ArrayUtils.Swaps.Companion.swap\r\nimport Utils.BinarySearchUtils.Companion.binarySearch\r\nimport Utils.BinarySearchUtils.Companion.binarySearchDouble\r\nimport Utils.BinarySearchUtils.Companion.binarySearchLong\r\nimport Utils.BitUtils.Companion.flip\r\nimport Utils.BitUtils.Companion.get\r\nimport Utils.BitUtils.Companion.set\r\nimport Utils.BitUtils.Companion.submaskOf\r\nimport Utils.FastReader\r\nimport Utils.GeneralUtils.Companion.catch\r\nimport Utils.GeneralUtils.Companion.length\r\nimport Utils.GeneralUtils.Companion.rnd\r\nimport Utils.MathUtils.Companion.compareDoubles\r\nimport Utils.MathUtils.Companion.gcd\r\nimport Utils.MathUtils.Companion.log2\r\nimport Utils.Pairs.Companion.ComparablePair\r\nimport Utils.Pairs.Companion.IntPair\r\nimport Utils.Pairs.Companion.LongPair\r\nimport java.io.*\r\nimport java.util.*\r\nimport kotlin.collections.ArrayDeque\r\nimport kotlin.math.*\r\nimport kotlin.random.Random\r\nimport kotlin.time.ExperimentalTime\r\n\r\n@ExperimentalStdlibApi\r\n@ExperimentalTime\r\n@ExperimentalUnsignedTypes\r\nfun main() {\r\n Locale.setDefault(Locale.US)\r\n System.setOut(PrintStream(BufferedOutputStream(System.out)))\r\n Task(FastReader()).solve()\r\n System.out.flush()\r\n}\r\n\r\nconst val eps = 1e-8\r\n\r\nconst val mod = 998244353\r\n\r\ndata class MInt(val x: Int) {\r\n operator fun plus(m: MInt) = MInt((x + m.x) % mod)\r\n operator fun minus(m: MInt) = MInt((x - m.x + mod) % mod)\r\n operator fun times(m: MInt) = MInt((x.toLong() * m.x % mod).toInt())\r\n operator fun div(m: MInt) = this * m.inv()\r\n\r\n fun inv() = inv(x)\r\n fun pow(p: Int): MInt {\r\n if (p == 0) return MInt(1)\r\n var r = pow(p / 2)\r\n r *= r\r\n if (p % 2 == 1) r *= this\r\n return r\r\n }\r\n\r\n override fun toString() = x.toString()\r\n\r\n companion object {\r\n private val facts = mutableListOf(MInt(1))\r\n private val invs = mutableListOf(MInt(0))\r\n private val invFacts = mutableListOf(MInt(1))\r\n fun Int.mod() = MInt(this)\r\n\r\n fun factorial(x: Int): MInt {\r\n while (x !in facts.indices) facts += facts.last() * facts.size.mod()\r\n return facts[x]\r\n }\r\n\r\n fun inv(x: Int): MInt {\r\n while (x !in invs.indices) invs.add(invs.size.mod().pow(mod - 2))\r\n return x.mod().pow(mod - 2)\r\n }\r\n\r\n fun invFact(x: Int): MInt {\r\n while (x !in invFacts.indices) invFacts += invFacts.last() * inv(invFacts.size)\r\n return invFacts[x]\r\n }\r\n }\r\n}\r\n\r\nfun c(n: Int, k: Int) = if (k in 0..n) MInt.factorial(n) * MInt.invFact(k) * MInt.invFact(n - k) else MInt(0)\r\n\r\n@ExperimentalTime\r\n@ExperimentalStdlibApi\r\nclass Task(private val fin: FastReader = FastReader()) {\r\n fun solve() {\r\n val n = fin.readInt()\r\n val maxHealth = fin.readInt()\r\n\r\n val cache = Array(n + 1) { IntArray(maxHealth + 1) { -1 } }\r\n fun go(alive: Int, damageGot: Int): MInt {\r\n if (alive == 0) return MInt(1)\r\n if (damageGot > maxHealth) return MInt(0)\r\n if (alive == 1) return MInt(0)\r\n cache[alive][damageGot].let { if (it != -1) return MInt(it) }\r\n var res = go(alive, damageGot + alive - 1)\r\n for (died in 1..alive) {\r\n val survived = alive - died\r\n val minWas = 1 + damageGot\r\n val maxWas = minOf(alive - 1 + damageGot, maxHealth)\r\n val numberOfWaysDied = c(alive, died)\r\n val healthForDied = MInt(maxWas - minWas + 1).pow(died)\r\n res += go(survived, damageGot + alive - 1) * numberOfWaysDied * healthForDied\r\n }\r\n cache[alive][damageGot] = res.x\r\n return res\r\n }\r\n\r\n val ans = go(n, 0)\r\n println(ans)\r\n }\r\n}\r\n\r\n@Suppress(\"MemberVisibilityCanBePrivate\", \"unused\")\r\n@ExperimentalStdlibApi\r\n@ExperimentalUnsignedTypes\r\nclass Utils {\r\n class GeneralUtils {\r\n companion object {\r\n val rnd = Random(239)\r\n val IntRange.length get() = maxOf(last - first + 1, 0)\r\n\r\n @Suppress(\"UNREACHABLE_CODE\", \"ControlFlowWithEmptyBody\")\r\n fun catch(throwMLE: Boolean = false, f: () -> R): R {\r\n try {\r\n return f()\r\n } catch (e: Exception) {\r\n if (throwMLE) throw OutOfMemoryError()\r\n while (true) {\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n class MathUtils {\r\n companion object {\r\n tailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)\r\n tailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\r\n fun lcm(a: Long, b: Long) = a / gcd(a, b) * b\r\n\r\n fun Int.log2(): Int {\r\n var log = 0\r\n while (1 shl log < this) log++\r\n return log\r\n }\r\n\r\n fun Long.log2(): Int {\r\n var log = 0\r\n while (1L shl log < this) log++\r\n return log\r\n }\r\n\r\n fun compareDoubles(x: Double, y: Double) =\r\n if (abs(x - y) < eps) 0 else if (x < y) -1 else +1\r\n\r\n fun isZero(x: Double) = abs(x) < eps\r\n }\r\n }\r\n\r\n class BitUtils {\r\n companion object {\r\n operator fun Int.get(bit: Int) = (this shr bit) and 1\r\n operator fun Long.get(bit: Int) = ((this shr bit) and 1).toInt()\r\n fun Int.set(bit: Int) = this or (1 shl bit)\r\n fun Long.set(bit: Int) = this or (1L shl bit)\r\n fun Int.flip(bit: Int) = this xor (1 shl bit)\r\n fun Long.flip(bit: Int) = this xor (1L shl bit)\r\n infix fun Int.submaskOf(x: Int) = (this and x) == this\r\n infix fun Long.submaskOf(x: Long) = (this and x) == this\r\n }\r\n }\r\n\r\n class ArrayUtils {\r\n companion object {\r\n fun > MutableList.makeDistinct() {\r\n if (size <= 1) return\r\n sort()\r\n var sz = 1\r\n for (i in 1 until size) {\r\n if (this[i] != this[i - 1]) {\r\n this[sz++] = this[i]\r\n }\r\n }\r\n while (size > sz) removeAt(lastIndex)\r\n }\r\n\r\n @Suppress(\"UNCHECKED_CAST\")\r\n fun Array.toNotNulls() = this as Array\r\n\r\n @Suppress(\"UNCHECKED_CAST\")\r\n inline fun arrayOfNullsSafe(size: Int): Array =\r\n arrayOfNulls(size).toNotNulls()\r\n }\r\n\r\n class Swaps {\r\n companion object {\r\n fun Array.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n }\r\n\r\n fun MutableList.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n }\r\n\r\n fun IntArray.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n }\r\n\r\n fun LongArray.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n }\r\n\r\n fun DoubleArray.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n sort()\r\n }\r\n\r\n fun CharArray.swap(i: Int, j: Int) {\r\n val x = this[i]\r\n this[i] = this[j]\r\n this[j] = x\r\n sort()\r\n }\r\n }\r\n }\r\n\r\n class Sorts {\r\n companion object {\r\n fun IntArray.shuffleSort() {\r\n for (i in 1 until size) swap(i, rnd.nextInt(i + 1))\r\n sort()\r\n }\r\n\r\n fun LongArray.shuffleSort() {\r\n for (i in 1 until size) swap(i, rnd.nextInt(i + 1))\r\n sort()\r\n }\r\n\r\n fun DoubleArray.shuffleSort() {\r\n for (i in 1 until size) swap(i, rnd.nextInt(i + 1))\r\n sort()\r\n }\r\n\r\n fun CharArray.shuffleSort() {\r\n for (i in 1 until size) swap(i, rnd.nextInt(i + 1))\r\n sort()\r\n }\r\n\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun Array.countSort(\r\n inPlace: Boolean = true,\r\n type: (T) -> Int = { (it as Number).toInt() }\r\n ): Array {\r\n if (isEmpty()) return if (inPlace) this else emptyArray()\r\n val types = IntArray(size) { type(this[it]) }\r\n val min = types.minOrNull()!!\r\n val max = types.maxOrNull()!!\r\n val count = IntArray(max - min + 1)\r\n for (t in types) count[t - min]++\r\n var sum = 0\r\n for (i in count.indices) {\r\n val shift = count[i]\r\n count[i] = sum\r\n sum += shift\r\n }\r\n val sorted = arrayOfNullsSafe(size)\r\n for (i in 0 until size) sorted[count[types[i] - min]++] = this[i]\r\n return if (inPlace) {\r\n this.also { sorted.copyInto(this) }\r\n } else {\r\n sorted\r\n }\r\n }\r\n\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun List.countSort(\r\n inPlace: Boolean = true,\r\n type: (T) -> Int = { (it as Number).toInt() }\r\n ): List {\r\n if (isEmpty()) return if (inPlace) this else emptyList()\r\n val types = IntArray(size) { type(this[it]) }\r\n val min = types.minOrNull()!!\r\n val max = types.maxOrNull()!!\r\n val count = IntArray(max - min + 1)\r\n for (t in types) count[t - min]++\r\n var sum = 0\r\n for (i in count.indices) {\r\n val shift = count[i]\r\n count[i] = sum\r\n sum += shift\r\n }\r\n val sorted = arrayOfNullsSafe(size)\r\n for (i in 0 until size) sorted[count[types[i] - min]++] = this[i]\r\n return if (inPlace) {\r\n return (this as MutableList).apply {\r\n for (i in indices) this[i] = sorted[i]\r\n }\r\n } else {\r\n sorted.asList()\r\n }\r\n }\r\n\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun IntArray.countSort(\r\n inPlace: Boolean = true,\r\n type: (Int) -> Int = { it -> it }\r\n ): IntArray {\r\n if (isEmpty()) return if (inPlace) this else intArrayOf()\r\n val types = IntArray(size) { type(this[it]) }\r\n val min = types.minOrNull()!!\r\n val max = types.maxOrNull()!!\r\n val count = IntArray(max - min + 1)\r\n for (t in types) count[t - min]++\r\n var sum = 0\r\n for (i in count.indices) {\r\n val shift = count[i]\r\n count[i] = sum\r\n sum += shift\r\n }\r\n val sorted = IntArray(size)\r\n for (i in 0 until size) sorted[count[types[i] - min]++] = this[i]\r\n return if (inPlace) {\r\n this.also { sorted.copyInto(this) }\r\n } else {\r\n sorted\r\n }\r\n }\r\n }\r\n }\r\n\r\n class Prints {\r\n companion object {\r\n fun println(a: IntArray) {\r\n if (a.isNotEmpty()) {\r\n print(a[0])\r\n for (i in 1 until a.size) {\r\n print(' ')\r\n print(a[i])\r\n }\r\n }\r\n println()\r\n }\r\n\r\n fun println(a: LongArray) {\r\n if (a.isNotEmpty()) {\r\n print(a[0])\r\n for (i in 1 until a.size) {\r\n print(' ')\r\n print(a[i])\r\n }\r\n }\r\n println()\r\n }\r\n\r\n fun println(a: CharArray, printSpace: Boolean = false) {\r\n if (a.isNotEmpty()) {\r\n print(a[0])\r\n for (i in 1 until a.size) {\r\n if (printSpace) print(' ')\r\n print(a[i])\r\n }\r\n }\r\n println()\r\n }\r\n\r\n fun println(a: Array<*>) {\r\n if (a.isNotEmpty()) {\r\n print(a[0])\r\n for (i in 1 until a.size) {\r\n print(' ')\r\n print(a[i])\r\n }\r\n }\r\n println()\r\n }\r\n\r\n fun println(a: List<*>) {\r\n if (a.isNotEmpty()) {\r\n print(a[0])\r\n for (i in 1 until a.size) {\r\n print(' ')\r\n print(a[i])\r\n }\r\n }\r\n println()\r\n }\r\n\r\n fun println(a: Iterable<*>) {\r\n val it = a.iterator()\r\n if (it.hasNext()) {\r\n print(it.next())\r\n while (it.hasNext()) {\r\n print(' ')\r\n print(it.next())\r\n }\r\n }\r\n println()\r\n }\r\n }\r\n }\r\n }\r\n\r\n class BinarySearchUtils {\r\n companion object {\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun binarySearch(from: Int, to: Int, f: (Int) -> Boolean): Int {\r\n var l = from\r\n var r = to + 1\r\n while (r - l > 1) {\r\n val m = (l + r) / 2\r\n if (f(m)) l = m\r\n else r = m\r\n }\r\n return l\r\n }\r\n\r\n inline fun binarySearch(from: Int = 0, f: (Int) -> Boolean): Int {\r\n var len = 1\r\n while (f(from + len)) len *= 2\r\n return binarySearch(from + len / 2, from + len - 1, f)\r\n }\r\n\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun binarySearchLong(from: Long, to: Long, f: (Long) -> Boolean): Long {\r\n var l = from\r\n var r = to + 1\r\n while (r - l > 1) {\r\n val m = (l + r) / 2\r\n if (f(m)) l = m\r\n else r = m\r\n }\r\n return l\r\n }\r\n\r\n inline fun binarySearchLong(from: Long = 0, f: (Long) -> Boolean): Long {\r\n var len = 1L\r\n while (f(from + len)) len *= 2\r\n return binarySearchLong(from + len / 2, from + len - 1, f)\r\n }\r\n\r\n @Suppress(\"DuplicatedCode\")\r\n inline fun binarySearchDouble(\r\n from: Double,\r\n to: Double,\r\n times: Int = 200,\r\n f: (Double) -> Boolean\r\n ): Double {\r\n var l = from\r\n var r = to\r\n repeat(times) {\r\n val m = (l + r) / 2\r\n if (f(m)) l = m\r\n else r = m\r\n }\r\n return l\r\n }\r\n\r\n inline fun binarySearchDouble(\r\n from: Double = 0.0,\r\n times: Int = 200,\r\n f: (Double) -> Boolean\r\n ): Double {\r\n var len = 1.0\r\n while (f(from + len)) len *= 2\r\n return binarySearchDouble(from, from + len, times, f)\r\n }\r\n }\r\n }\r\n\r\n class Pairs {\r\n companion object {\r\n data class ComparablePair, T2 : Comparable>(\r\n val first: T1,\r\n val second: T2\r\n ) :\r\n Comparable> {\r\n override fun compareTo(other: ComparablePair): Int {\r\n var c = first.compareTo(other.first)\r\n if (c == 0) c = second.compareTo(other.second)\r\n return c\r\n }\r\n }\r\n\r\n data class IntPair(val first: Int, val second: Int) : Comparable {\r\n override fun compareTo(other: IntPair): Int {\r\n var c = first.compareTo(other.first)\r\n if (c == 0) c = second.compareTo(other.second)\r\n return c\r\n }\r\n\r\n fun swap() = IntPair(second, first)\r\n }\r\n\r\n data class LongPair(val first: Long, val second: Long) : Comparable {\r\n override fun compareTo(other: LongPair): Int {\r\n var c = first.compareTo(other.first)\r\n if (c == 0) c = second.compareTo(other.second)\r\n return c\r\n }\r\n }\r\n }\r\n }\r\n\r\n class UtilsImports {\r\n fun importDependencies() {\r\n check(gcd(4, 6) == 2)\r\n check(rnd.nextInt(10) in 0 until 10)\r\n check(mutableListOf(1, 3, 2, 2, 1).apply { makeDistinct() } == listOf(1, 2, 3))\r\n check((5..10).length == 6)\r\n check(intArrayOf(3, 4).apply { swap(0, 1) }.contentEquals(intArrayOf(4, 3)))\r\n check(\r\n intArrayOf(5, 6, 2, 1, 5).apply { shuffleSort() }\r\n .contentEquals(intArrayOf(1, 2, 5, 5, 6))\r\n )\r\n check(binarySearch { it < 10 } == 9)\r\n check(binarySearchLong { it < 1e13.toLong() } == 1e13.toLong() - 1)\r\n binarySearchDouble { true }\r\n println(intArrayOf())\r\n ArrayDeque()\r\n abs(1)\r\n sin(1.0)\r\n cos(1.0)\r\n hypot(1.0, 1.0)\r\n catch {}\r\n ComparablePair(1, 2)\r\n IntPair(1, 2)\r\n arrayOfNulls(0).toNotNulls()\r\n arrayOfNullsSafe(0)\r\n 5.log2()\r\n @Suppress(\"ReplaceGetOrSet\")\r\n 5.get(3)\r\n 5.sign\r\n 5 submaskOf 3\r\n 5.set(3)\r\n 5.flip(3)\r\n compareDoubles(0.0, 1.0)\r\n arrayOf(1, 2).countSort { it.countOneBits() }\r\n LongPair(1, 2)\r\n }\r\n }\r\n\r\n class FastReader(fileName: String? = null) {\r\n @JvmField\r\n val br =\r\n BufferedReader(if (fileName != null) FileReader(fileName) else InputStreamReader(System.`in`))\r\n\r\n @JvmField\r\n var st = StringTokenizer(\"\")\r\n\r\n fun readString(): String {\r\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\r\n return st.nextToken()\r\n }\r\n\r\n fun readInt() = readString().toInt()\r\n fun readLong() = readString().toLong()\r\n fun readDouble() = readString().toDouble()\r\n\r\n fun readIntArray(n: Int) = IntArray(n) { readInt() }\r\n fun readLongArray(n: Int) = LongArray(n) { readLong() }\r\n fun readStringArray(n: Int) = Array(n) { readString() }\r\n fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() }\r\n\r\n fun readInts(n: Int) = MutableList(n) { readInt() }\r\n fun readLongs(n: Int) = MutableList(n) { readLong() }\r\n fun readStrings(n: Int) = MutableList(n) { readString() }\r\n fun readDoubles(n: Int) = MutableList(n) { readDouble() }\r\n }\r\n}", "src_uid": "1908d1c8c6b122a4c6633a7af094f17f"} {"source_code": "import kotlin.math.abs\n\n\nfun main() {\n\n val n = readLine()!!.toInt()\n val s = readLine()!!\n\n\n val countNull = s.count { it == '0' }\n val countOne = s.count { it == '1' }\n\n\n if (countOne > 0)\n print(1)\n (1..countNull).forEach {\n print(0)\n }\n\n}", "src_uid": "ac244791f8b648d672ed3de32ce0074d"} {"source_code": "// 2022.09.02 at 15:46:26 BST\r\nimport java.io.BufferedInputStream\r\nimport java.io.File\r\nimport java.io.PrintWriter\r\nimport kotlin.system.measureTimeMillis\r\n\r\n// 1. Modded\r\nconst val p = 1000000007L\r\nconst val pI = p.toInt()\r\nfun Int.adjust():Int{ if(this >= pI){ return this - pI }else if (this < 0){ return this + pI };return this }\r\nfun Int.snap():Int{ if(this >= pI){return this - pI} else return this}\r\ninfix fun Int.modM(b:Int):Int{ return ((this.toLong() * b) % pI).toInt() }\r\ninfix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }\r\nfun intPow(x:Int,e:Int,m:Int):Int{\r\n var X = x ; var E =e ; var Y = 1\r\n while(E > 0){\r\n if(E and 1 == 0){\r\n X = ((1L * X * X) % m).toInt()\r\n E = E shr 1\r\n }else{\r\n Y = ((1L * X * Y) % m).toInt()\r\n E -= 1\r\n }\r\n }\r\n return Y\r\n}\r\n// 2. DP initial values\r\nconst val plarge = 1_000_000_727\r\nconst val nlarge = -plarge\r\nconst val phuge = 2_727_000_000_000_000_000L\r\nconst val nhuge = -phuge\r\n// 3. convenience conversions\r\nval Boolean.chi:Int get() = if(this) 1 else 0 //characteristic function\r\nval BooleanArray.chiarray:IntArray get() = IntArray(this.size){this[it].chi}\r\nval Char.code :Int get() = this.toInt() - 'a'.toInt()\r\n//3. hard to write stuff\r\nfun IntArray.put(i:Int,v:Int){ this[i] = (this[i] + v).adjust() }\r\nval mint:MutableList get() = mutableListOf()\r\nval mong:MutableList get() = mutableListOf()\r\n//4. more outputs\r\nfun List.conca():String = this.joinToString(\"\")\r\nval CharArray.conca :String get() = this.joinToString(\"\")\r\nval IntArray.conca :String get() = this.joinToString(\" \")\r\n@JvmName(\"concaInt\")\r\nfun List.conca():String = this.joinToString(\" \")\r\nval LongArray.conca:String get() = this.joinToString(\" \")\r\n@JvmName(\"concaLong\")\r\nfun List.conca():String = this.joinToString(\" \")\r\n//5. Pair of ints\r\nconst val longmask = (1L shl 32) - 1\r\nfun makepair(a:Int, b:Int):Long = (a.toLong() shl 32) xor (longmask and b.toLong())\r\nval Long.first get() = (this ushr 32).toInt()\r\nval Long.second get() = this.toInt()\r\n//6. strings\r\nval String.size get() = this.length\r\nconst val randCount = 100\r\n//7. bits\r\nfun Int.has(i:Int):Boolean = (this and (1 shl i) != 0)\r\nfun Long.has(i:Int):Boolean = (this and (1L shl i) != 0L)\r\n//8 TIME\r\ninline fun TIME(f:()->Unit){\r\n val t = measureTimeMillis(){\r\n f()\r\n }\r\n println(\"$t ms\")\r\n}\r\n//9.ordered pair\r\nfun order(a:Int, b:Int):Pair{\r\n return Pair(minOf(a,b), maxOf(a,b))\r\n}\r\nconst val interactive = false\r\nobject Reader{\r\n private const val BS = 1 shl 16\r\n private const val NC = 0.toChar()\r\n private val buf = ByteArray(BS)\r\n private var bId = 0\r\n private var size = 0\r\n private var c = NC\r\n\r\n var warningActive = true\r\n var fakein = StringBuilder()\r\n\r\n private var IN: BufferedInputStream = BufferedInputStream(System.`in`, BS)\r\n val OUT: PrintWriter = PrintWriter(System.out)\r\n\r\n private val char: Char\r\n get() {\r\n if(interactive){\r\n return System.`in`.read().toChar()\r\n }\r\n while (bId == size) {\r\n size = IN.read(buf) // no need for checked exceptions\r\n if (size == -1) return NC\r\n bId = 0\r\n }\r\n return buf[bId++].toChar()\r\n }\r\n\r\n fun nextInt(): Int {\r\n var neg = false\r\n if (c == NC) c = char\r\n while (c < '0' || c > '9') {\r\n if (c == '-') neg = true\r\n c = char\r\n }\r\n var res = 0\r\n while (c in '0'..'9') {\r\n res = (res shl 3) + (res shl 1) + (c - '0')\r\n c = char\r\n }\r\n return if (neg) -res else res\r\n }\r\n fun nextLong(): Long {\r\n var neg = false\r\n if (c == NC) c = char\r\n while (c < '0' || c > '9') {\r\n if (c == '-') neg = true\r\n c = char\r\n }\r\n var res = 0L\r\n while (c in '0'..'9') {\r\n res = (res shl 3) + (res shl 1) + (c - '0')\r\n c = char\r\n }\r\n return if (neg) -res else res\r\n }\r\n fun nextString():String{\r\n val ret = StringBuilder()\r\n while (true){\r\n c = char\r\n if(!isWhitespace(c)){ break}\r\n }\r\n ret.append(c)\r\n while (true){\r\n c = char\r\n if(isWhitespace(c)){ break}\r\n ret.append(c)\r\n }\r\n return ret.toString()\r\n }\r\n fun isWhitespace(c:Char):Boolean{\r\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t'\r\n }\r\n fun rerouteInput(){\r\n if(warningActive){\r\n put(\"Custom test enabled\")\r\n println(\"Custom test enabled\")\r\n warningActive = false\r\n }\r\n val S = fakein.toString()\r\n println(\"New Case \")\r\n println(S.take(80))\r\n println(\"...\")\r\n fakein.clear()\r\n IN = BufferedInputStream(S.byteInputStream(),BS)\r\n }\r\n fun flush(){\r\n OUT.flush()\r\n }\r\n fun takeFile(name:String){\r\n IN = BufferedInputStream(File(name).inputStream(),BS)\r\n }\r\n}\r\nfun put(aa:Any){\r\n Reader.OUT.println(aa)\r\n if(interactive){ Reader.flush()}\r\n}\r\nfun done(){ Reader.OUT.close() }\r\nfun share(aa:Any){\r\n if(aa is IntArray){Reader.fakein.append(aa.joinToString(\" \"))}\r\n else if(aa is LongArray){Reader.fakein.append(aa.joinToString(\" \"))}\r\n else if(aa is List<*>){Reader.fakein.append(aa.toString())}\r\n else{Reader.fakein.append(aa.toString())}\r\n Reader.fakein.append(\"\\n\")\r\n}\r\n\r\nval getintfast:Int get() = Reader.nextInt()\r\nval getint:Int get(){ val ans = getlong ; if(ans > Int.MAX_VALUE) IntArray(1000000000); return ans.toInt() }\r\nval getlong:Long get() = Reader.nextLong()\r\nval getstr:String get() = Reader.nextString()\r\nfun getline(n:Int):IntArray{\r\n return IntArray(n){getint}\r\n}\r\nfun getlineL(n:Int):LongArray{\r\n return LongArray(n){getlong}\r\n}\r\nvar dmark = -1\r\ninfix fun Any.dei(a:Any){\r\n dmark++\r\n var str = \"<${dmark}> \"\r\n debug()\r\n if(this is String){ str += this\r\n }else if(this is Int){ str += this.toString()\r\n }else if(this is Long){ str += this.toString()\r\n }else{ str += this.toString()}\r\n if(a is List<*>){ println(\"$str : ${a.joinToString(\" \")}\")\r\n }else if(a is IntArray){ println(\"$str : ${a.joinToString(\" \")}\")\r\n }else if(a is LongArray){ println(\"$str : ${a.joinToString(\" \")}\")\r\n }else if(a is BooleanArray){ println(\"$str :${a.map{if(it)'1' else '0'}.joinToString(\" \")}\")\r\n }else if(a is Array<*>){\r\n println(\"$str : \")\r\n for(c in a){if(c is IntArray){println(c.joinToString(\" \"))}\r\n else if(c is LongArray){println(c.joinToString(\" \"))}\r\n else if(c is BooleanArray){println(c.map { if(it) '1' else '0' }.joinToString(\"\"))\r\n }\r\n }\r\n println()\r\n }else{ println(\"$str : $a\")\r\n }\r\n}\r\nval just = \" \"\r\nfun crash(){\r\n throw Exception(\"Bad programme\")}\r\nfun assert(a:Boolean){\r\n if(!a){\r\n throw Exception(\"Failed Assertion\")\r\n }}\r\nenum class solveMode {\r\n real, rand, tc\r\n}\r\nobject solve{\r\n var mode:solveMode = solveMode.real\r\n var tcNum:Int = 0\r\n var rand:()->Unit = {}\r\n var TC:MutableMapUnit> = mutableMapOf()\r\n var tn:Long = 0\r\n fun cases(onecase:()->Unit){\r\n val t = if(mode == solveMode.real){if(singleCase) 1 else getint} else if(mode == solveMode.tc){1 } else randCount\r\n if(pI != 998_244_353 && pI != 1_000_000_007){\r\n throw Exception(\"Not usual primes!\")\r\n }\r\n if(t == 1 && mode != solveMode.real){\r\n tn = System.currentTimeMillis()\r\n }\r\n repeat(t){\r\n if(mode == solveMode.tc){\r\n TC[tcNum]?.let { it() }\r\n Reader.rerouteInput()\r\n }else if(mode == solveMode.rand){\r\n rand()\r\n Reader.rerouteInput()\r\n }\r\n onecase()\r\n }\r\n if(t == 1 && mode != solveMode.real){\r\n val dt = System.currentTimeMillis() - tn\r\n println(\"Time $dt ms \")\r\n }\r\n }\r\n inline fun singleCase(a:solve.()->Unit){\r\n val t = if(mode != solveMode.rand){1} else randCount\r\n repeat(t) { a() }\r\n }\r\n fun rand(a:()->Unit){\r\n this.rand = a\r\n }\r\n fun tc(id:Int = 0,a:()->Unit){\r\n TC[id] = a\r\n }\r\n fun usetc(a:Int = 0 ){\r\n this.tcNum = a\r\n this.mode = solveMode.tc\r\n }\r\n fun userand(){\r\n this.mode = solveMode.rand\r\n }\r\n}\r\nfun debug(){}\r\n\r\n\r\n\r\ninfix fun Long.modM(b:Long):Long{\r\n return (this * b) % p\r\n}\r\n//infix fun Int.modPlus(b:Int):Int{\r\n// val ans = this + b\r\n// return if(ans >= pI) ans - pI else ans\r\n//}\r\ninfix fun Int.modMinus(b:Int):Int{\r\n val ans = this - b\r\n return if(ans < 0) ans + pI else ans\r\n}\r\ninfix fun Int.modDivide(b:Int):Int{\r\n return this modM (b.inverse())\r\n}\r\nfun Int.additiveInverse():Int{\r\n return if(this == 0) 0 else pI - this\r\n}\r\n\r\nfun intPowEXP(x:Int,e:Long,m:Int):Int{\r\n var X = x\r\n var E =e\r\n var Y = 1\r\n while(E > 0){\r\n if(E % 2 == 0L){\r\n X = ((1L * X * X) % m).toInt()\r\n E = E shr 1\r\n }else{\r\n Y = ((1L * X * Y) % m).toInt()\r\n E -= 1\r\n }\r\n }\r\n return Y\r\n}\r\n\r\nfun pow(x:Long,e:Long,m:Long):Long{\r\n var X = x\r\n var E =e\r\n var Y = 1L\r\n while(E > 0){\r\n if(E % 2 == 0L){\r\n X = (X * X) % m\r\n E /= 2\r\n }else{\r\n Y = (X * Y) % m\r\n E -= 1\r\n }\r\n }\r\n return Y\r\n}\r\nfun Long.inverse():Long{\r\n return pow(this,p-2,p)\r\n}\r\nfun Int.inverse():Int{\r\n return intPow(this,pI-2,pI)\r\n}\r\nfun min_rem(m:Int, r:Int, c:Int):Int {\r\n if(c < 1){\r\n return Int.MIN_VALUE\r\n }else if(r == 0){\r\n return 0\r\n }else{\r\n val step = m % r\r\n val mx = ((1L * c * r) /m ).toInt()\r\n val t = max_rem(r,step,mx)\r\n return r- t\r\n }\r\n}\r\nfun max_rem(m:Int, r:Int, c:Int):Int {\r\n if(r == 0|| c <= m/r){\r\n return r * c\r\n }else{\r\n val step = m % r\r\n val mx = ((1L * (c+1) * r )/m).toInt()\r\n val t = min_rem(r,step,mx)\r\n return m - t\r\n }\r\n}\r\nfun Int.reconstruct():String{\r\n val num = min_rem(pI,this, 10000)\r\n val denom = (this modDivide num).inverse()\r\n return \"$num / $denom\"\r\n}\r\n\r\n//make this int instead\r\nclass FACT{\r\n companion object {\r\n var store = IntArray(0)\r\n var invStore = IntArray(0)\r\n\r\n var slowStore:IntArray = IntArray(0)\r\n\r\n fun preCal(upto:Int){\r\n store = IntArray(upto+1)\r\n invStore = IntArray(upto + 1 )\r\n store[0] = 1\r\n invStore[0] = 1\r\n\r\n for(i in 1..upto) {\r\n store[i] = store[i-1] modM i\r\n invStore[i] = invStore[i-1] modM (i.inverse())\r\n }\r\n }\r\n fun choose(n:Int,r:Int):Int{\r\n if(r < 0 || r > n) return 0\r\n val a = store[n]\r\n val b = invStore[n-r]\r\n val c = invStore[r]\r\n return (a modM b) modM c\r\n }\r\n\r\n fun bigChoose(n:Int,r:Int):Int{\r\n var ret = 1\r\n for(i in 0 until r){\r\n ret = ret modM (n - i)\r\n }\r\n ret = ret modM (invStore[r])\r\n return ret\r\n }\r\n\r\n }\r\n}\r\n\r\n\r\nconst val singleCase = true\r\nfun main(){\r\n FACT.preCal(100005)\r\n solve.cases{\r\n\r\n val n = getint\r\n val k = getint\r\n\r\n var ret = 0\r\n for(i in 0..minOf(n,k)){\r\n ret = ret modPlus FACT.choose(n,i)\r\n }\r\n put(ret)\r\n\r\n\r\n\r\n\r\n\r\n }\r\n done()\r\n}\r\n\r\n\r\n\r\n\r\n/*\r\n1 5 3 7 2 6 4 8\r\n */", "src_uid": "dc7b887afcc2e95c4e90619ceda63071"} {"source_code": "import java.util.*;\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readDouble() = readLn().toDouble() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of ints\n\nfun main(args: Array) {\n solve()\n /*\n val t = readInt()\n repeat(t) {\n solve()\n }\n */\n}\n\nfun solve() {\n val g = arrayOf(readLn(), readLn(), readLn(), readLn())\n val dx = arrayOf(-1, -1, -1, 0, 0, 1, 1, 1)\n val dy = arrayOf(-1, 0, 1, -1, 1, -1, 0, 1)\n for(i in 0 until 4) {\n for(j in 0 until 4) {\n for(k in 0 until dx.size) {\n var good = 0\n var valid = true\n for(l in 0 until 3) {\n var nx = i + dx[k] * l\n var ny = j + dy[k] * l\n if(nx < 0 || nx >= 4 || ny < 0 || ny >= 4 || g[nx][ny] == 'o') valid = false\n if(valid && g[nx][ny] == 'x') good++\n }\n if(good == 2 && valid) {\n println(\"YES\")\n System.exit(0);\n }\n }\n }\n }\n println(\"NO\")\n}\n\n/*\nuseful things:\nJava: int[] dx = new int[]{-1,1,0,0}\nKotlin: val dx = arrayOf(-1, 1, 0, 0)\n*/", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917"} {"source_code": "fun readIntList() = readLine()!!.split(' ').map(String::toInt).toMutableList()\nfun readLongList() = readLine()!!.split(' ').map(String::toLong).toMutableList()\nfun readInt() = readLine()!!.toInt()\n\nfun main(args: Array) {\n val f = readLine()!!\n val m = readLine()!!\n val s = readLine()!!\n\n\n if (isGreaterThan(f, m) && isGreaterThan(f, s)) {\n println(\"F\")\n } else if (isGreaterThan(m, f) && isGreaterThan(m, s)) {\n println(\"M\")\n }else if (isGreaterThan(s, m) && isGreaterThan(s, f)) {\n println(\"S\")\n }else {\n println(\"?\")\n }\n\n}\n\nfun isGreaterThan(str1: String, str2: String): Boolean {\n return (str1 == \"scissors\" && str2 == \"paper\") || (str1 == \"paper\" && str2 == \"rock\") || (str1 == \"rock\" && str2 == \"scissors\")\n}", "src_uid": "072c7d29a1b338609a72ab6b73988282"} {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\nimport java.util.TreeMap\nimport java.util.TreeSet\nimport java.util.ArrayDeque\nimport java.util.PriorityQueue\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.system.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\n\nfun main() {\n output {\n val n = readLong()\n val p = readLong()\n val w = readInt()\n val d = readInt()\n\n var x = -1L\n var y = -1\n\n for(yy in 0 until w) {\n val num = p - yy.toLong() * d\n if(num < 0) break\n if(num % w == 0L) {\n val xx = num / w\n if(xx + yy <= n) {\n x = xx\n y = yy\n break\n }\n }\n }\n\n if(x >= 0) {\n val z = n - x - y\n println(\"$x $y $z\")\n } else println(-1)\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 readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(System.out, false)\ninline fun output(block: PrintWriter.()->Unit) { _writer.apply(block).flush() }\ninline fun iprintln(o: Any?) { println(o) } // immediate println for interactive, bypasses output{} blocks\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? = Random(System.nanoTime())\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()", "src_uid": "503116e144d19eb953954d99c5526a7d"} {"source_code": "//package codeforces.round614\n\nfun main() {\n\treadLn()\n\tval a = readInts()\n\tval aCount = a.groupBy { it }.mapValues { it.value.size }\n\tvar b = aCount.keys.toList()\n\tval (primes, factPrimes) = List(2) { MutableList(2) { listOf() } }\n\tfor (i in 2..b.max()!!) {\n\t\tval j = (2..i).first { i % it == 0 }\n\t\tprimes.add(primes[i / j].plus(j))\n\t\tfactPrimes.add(factPrimes[i - 1].plus(primes[i]).sortedDescending())\n\t}\n\tvar ans = aCount.map { factPrimes[it.key].size * 1L * it.value }.sum()\n\tfor (x in factPrimes.last().indices) {\n\t\tval groups = b.groupBy { factPrimes[it].getOrNull(x) }\n\t\tval win = groups.mapValues { entry -> 2 * entry.value.sumBy { aCount.getValue(it) } - a.size }\n\t\tval p = win.entries.firstOrNull { it.value > 0 }?.key ?: break\n\t\tans -= win.getValue(p)\n\t\tb = groups.getValue(p)\n\t}\n\tprintln(ans)\n}\n\nprivate fun readLn() = readLine()!!\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n", "src_uid": "40002052843ca0357dbd3158b16d59f4"} {"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}", "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f"} {"source_code": "fun main() {\n val (x1, x2) = readInts()\n val n = minOf(x1, x2)\n val m = maxOf(x1, x2)\n val fib = LongArray(m + 1)\n fib[0] = 1\n fib[1] = 1\n for(i in 2..m) {\n fib[i] = (fib[i - 1] + fib[i - 2]) % mod\n }\n val f0 = LongArray(n + 1)\n f0[1] = fib[m - n + 1]\n for (i in 2..n) {\n f0[i] = (f0[i - 1] + fib[i - 2] + fib[m - n + i - 2]) % mod\n }\n println((f0[n] * 2) % mod)\n}\n\nprivate val mod = 1000000007L\n\nprivate fun readString() = readLine()!!\n\nprivate fun readInt() = readString().toInt()\n\nprivate fun readInts() = readString().split(\" \").map { it.toInt() }\n\nprivate fun readLong() = readString().toLong()\n\nprivate fun readLongs() = readString().split(\" \").map { it.toLong() }\n", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b"} {"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\n val a = Array(n) { sc.nextInt() }\n val b = a.sortedArray()\n\n val res = Array(n) { 0 }\n\n for (i in 0 until n) {\n res[a.indexOf(b[i])] = b[(i + 1) % n]\n }\n\n println(res.joinToString(\" \"))\n}\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}\n\n\n", "src_uid": "e314642ca1f82be8f223e2eba00b5531"} {"source_code": "const val MOD = 1000000007L\n\nfun main() {\n for (c in 1..readLine()!!.toInt()) {\n val (n, k) = readLine()!!.split(\" \").map { it.toLong() }\n var answer = 1L\n for (j in 1L..k) {\n answer *= n\n answer %= MOD\n }\n println(answer)\n }\n}", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a"} {"source_code": "//package codeforces.com.tasks.task148A\n\nfun main() {\n val k = readLine()!!.toInt()\n val l = readLine()!!.toInt()\n val m = readLine()!!.toInt()\n val n = readLine()!!.toInt()\n val d = readLine()!!.toInt()\n var damagedDragonsCount = 0\n (1..d).map {\n if ( (it%k == 0) || (it%l == 0) || (it%m == 0) || (it%n == 0) )\n damagedDragonsCount++\n }\n println(damagedDragonsCount)\n}", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7"} {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val a: Int\n val b: Int\n\n if ((n % 2) == 0) {\n if ((n/2) % 2 == 0) {\n a = (n / 2) - 1\n b = (n / 2) + 1\n } else {\n a = (n / 2) - 2\n b = (n / 2) + 2\n }\n } else {\n a = n / 2\n b = (n / 2) + 1\n }\n\n println(\"$a $b\")\n}", "src_uid": "0af3515ed98d9d01ce00546333e98e77"} {"source_code": "private fun solve() {\n\tval n = readInt()\n\tval flag = readInts()\n\tval want = readInts()\n\tval changed = flag.zip(want) { a, b -> a != b }\n\tval nei = List(n) { mutableListOf() }\n\trepeat(n - 1) {\n\t\tval (a, b) = readInts().map { it - 1 }\n\t\tnei[a].add(b)\n\t\tnei[b].add(a)\n\t}\n\tval w = changed.indexOfFirst { it }\n\tif (w == -1) return println(\"Yes\\n0\")\n\tval p = MutableList(n) { 0 }\n\tval u = furthest(nei, p, changed, w)\n\tval v = furthest(nei, p, changed, u)\n\tval path = mutableListOf(v)\n\twhile (path.last() != u) path.add(p[path.last()])\n\tprintln(check(flag, want, path) ?: check(flag, want, path.reversed()) ?: \"No\")\n}\n\nprivate fun check(flag: List, want: List, path: List): String? {\n\tval f = flag.toMutableList()\n\tval save = f[path.first()]\n\tfor ((a, b) in path.zipWithNext()) {\n\t\tf[a] = f[b]\n\t}\n\tf[path.last()] = save\n\tif (f != want) return null\n\treturn \"Yes\\n\" + path.size.toString() + \"\\n\" + path.joinToString(\" \") { (it + 1).toString() }\n}\n\nprivate fun furthest(nei: List>, p: MutableList, cool: List, v: Int): Int {\n\tval t = dfs(nei, p, cool, v, -1)\n\treturn t.second\n}\n\nprivate fun dfs(nei: List>, p: MutableList, cool: List, v: Int, parent: Int): Pair {\n\tvar best = if (cool[v]) 0 to v else -nei.size to -1\n\tp[v] = parent\n\tfor (u in nei[v].minus(parent)) {\n\t\tval (dist, vertex) = dfs(nei, p, cool, u, v)\n\t\tif (dist + 1 > best.first) best = dist + 1 to vertex\n\t}\n\treturn best\n}\n\nfun main() = repeat(readInt()) { solve() }\n\nprivate fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n", "src_uid": "78f839ac8cd0a716a0f0211fe3219520"} {"source_code": "fun main() {\n val n = Integer.parseInt(readLine()!!)\n val matrix = Array(n) { IntArray(n) }\n\n for (i in 0 until n) {\n matrix[i][0] = 1\n }\n for (j in 1 until n) {\n matrix[0][j] = 1\n }\n\n\n for (i in 0 until n) {\n for (j in 0 until n) {\n if (matrix[i][j] == 0) {\n val value = matrix[i - 1][j] + matrix[i][j - 1]\n matrix[i][j] = value\n }\n }\n }\n \n println(matrix[n-1][n-1])\n}", "src_uid": "2f650aae9dfeb02533149ced402b60dc"} {"source_code": "fun main() {\n val n = readLine()?.toInt() ?: error(\"\")\n var position = 0\n\n repeat(n) {\n val (kmStr, dir) = readLine()?.split(\" \") ?: error(\"\")\n val km = kmStr.toInt()\n\n if (position == 0 && dir != \"South\") {\n print(\"NO\")\n return\n }\n\n if (position == 20_000 && dir != \"North\") {\n print(\"NO\")\n return\n }\n\n when (dir) {\n \"South\" -> position += km\n \"North\" -> position -= km\n }\n\n if (position < 0 || position > 20_000) {\n print(\"NO\")\n return\n }\n\n position %= 40_000\n }\n\n if (position == 0) {\n print(\"YES\")\n } else {\n print(\"NO\")\n }\n}", "src_uid": "11ac96a9daa97ae1900f123be921e517"} {"source_code": "fun main() {\n val input = readLine()!!.toInt()\n val output = when (input % 2) {\n 0 -> 1 shl input / 2\n else -> 0\n }\n println(output)\n}", "src_uid": "4b7ff467ed5907e32fd529fb39b708db"} {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (a, m) = readInts()\n var x = a\n val visited = mutableSetOf()\n while (x % m != 0) {\n if (x % m in visited) return print(\"No\")\n visited.add(x % m)\n x += x % m\n }\n print(\"Yes\")\n}", "src_uid": "f726133018e2149ec57e113860ec498a"} {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.max\nimport kotlin.math.min\nimport kotlin.math.sqrt\n\nfun main(args : Array) {\n Thread { run() }.start()\n}\n\n\nfun run() {\n val scanner = Scanner(System.`in`)\n val a = scanner.nextInt()\n val b = scanner.nextInt()\n val c = scanner.nextInt()\n val res = (a / 3) + (b / 3) + (c / 3) + min(min(a % 3, b % 3), c % 3) + if ((a % 3) * (a % 3) + (b % 3) * (b % 3) + (c % 3) * (c % 3) == 8 && a > 2 && b > 2 && c > 2) 1 else 0\n println(res)\n\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\nfun IntArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun LongArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun BooleanArray.print() {\n println(Arrays.toString(this))\n}", "src_uid": "acddc9b0db312b363910a84bd4f14d8e"} {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.lang.AssertionError\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007\nfun powMod(a: Long, n: Long, mod: Int): Long {\n if (n == 0L) return 1\n val res = powMod(a * a % mod, n / 2, mod)\n return if (n % 2 == 1L) res * a % mod else res\n}\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n\n fun solve() {\n val S = ns()\n val Ss = (0 until 10).map { S.replace('X', '0'+it) }.distinct()\n val ans = Ss.map(::solve2).sum()\n out.println(ans)\n }\n\n fun solve2(S: String): Int {\n debug{\"solve2($S)\"}\n val N = S.length\n if (N < 3) {\n return solve_naive(S)\n }\n\n val head = S.take(max(0, N - 2)) // 0かもしれない\n val fst = head.take(1)\n val snd = head.drop(1)\n val tail = S.drop(head.length)\n\n fun countTail(): Int {\n var cnt = 0\n for (num in 0 until 100) {\n if (num % 25 == 0 && accepts(tail, num) != null) cnt++\n }\n return cnt\n }\n\n fun countHead(): Int {\n if (fst.isEmpty()) return 1\n\n val c1 = when(fst[0]) {\n '_' -> 9\n '0' -> 0\n else -> 1\n }\n val underscores = snd.count { it == '_' }\n val c2 = powMod(10, underscores.toLong(), MOD).toInt()\n return c1 * c2\n }\n\n debug{\"countTail: ${countTail()} countHead${countHead()}\"}\n return countTail() * countHead()\n }\n\n fun solve_naive(S: String): Int {\n val N = S.length\n val max = powMod(10, N.toLong(), MOD).toInt()\n var cnt = 0\n for (num in 0 until max) {\n if (num % 25 != 0) continue\n val res = accepts(S, num) ?: continue\n if (res.length == 1 || res[0] != '0') cnt++\n }\n return cnt\n }\n\n fun accepts(S: String, num: Int): String? {\n val numStr = (\"00$num\").takeLast(S.length)\n val ok = numStr.indices.all { S[it] == '_' || S[it] == numStr[it] }\n return if (ok) numStr else null\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\n System.getenv(\"MY_DEBUG\") != null\n } catch (t: Throwable) {\n false\n }\n\n private var tokenizer: StringTokenizer? = null\n private fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = StringTokenizer(reader.readLine())\n }\n return tokenizer!!.nextToken()\n }\n\n private fun ni() = next().toInt()\n private fun nl() = next().toLong()\n private fun ns() = next()\n private fun na(n: Int, offset: Int = 0): IntArray {\n return IntArray(n) { ni() + offset }\n }\n private fun nal(n: Int, offset: Int = 0): LongArray {\n val res = LongArray(n)\n for (i in 0 until n) {\n res[i] = nl() + offset\n }\n return res\n }\n\n private fun na2(n: Int, offset: Int = 0): Array {\n val a = Array(2){IntArray(n)}\n for (i in 0 until n) {\n for (e in a) {\n e[i] = ni() + offset\n }\n }\n return a\n }\n\n private inline fun debug(msg: () -> String) {\n if (isDebug) System.err.println(msg())\n }\n\n /**\n * コーナーケースでエラー出たりするので、debug(dp[1])のように添え字付きの場合はdebug{}をつかうこと\n */\n private inline fun debug(a: LongArray) {\n debug { a.joinToString(\" \") }\n }\n\n private inline fun debug(a: IntArray) {\n debug { a.joinToString(\" \") }\n }\n\n private inline fun debug(a: BooleanArray) {\n debug { toString(a) }\n }\n\n private inline fun toString(a: BooleanArray) = run{a.map { if (it) 1 else 0 }.joinToString(\"\")}\n\n private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n private inline fun debugDim(A: Array) {\n if (isDebug) {\n for (a in A) {\n debug(a)\n }\n }\n }\n\n /**\n * 勝手に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 private inline fun assert(b: Boolean, f: () -> String) = run{if (!b) throw AssertionError(f())}\n\n companion object {\n // TestRunnerから呼びたいので単純なmainじゃだめ\n fun main() {\n val out = java.io.PrintWriter(System.out)\n Solver(System.`in`, out).solve()\n out.flush()\n }\n }\n}\n\n/**\n * judgeから呼ばれる\n */\nfun main() = Solver.main()", "src_uid": "4a905f419550a6c839992b40f1617af3"} {"source_code": "import java.io.PrintWriter\nimport java.util.*\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val `in` = Scanner(inputStream)\n val out = PrintWriter(outputStream)\n solve(`in`, out)\n out.close()\n}\n\nfun solve(scanner: Scanner, out: PrintWriter) {\n out.println(3)\n val points = (1..3).map {\n val point = scanner.nextInt() to scanner.nextInt()\n scanner.nextLine()\n point\n }\n listOf(points[1] + points[2] - points[0],\n points[0] + points[1] - points[2],\n points[2] + points[0] - points[1])\n .forEach{ out.println(\"${it.first} ${it.second}\") }\n}\n\nprivate infix operator fun Pair.plus(that: Pair): Pair {\n return (this.first + that.first) to (this.second + that.second)\n}\n\nprivate infix operator fun Pair.minus(that: Pair): Pair {\n return (this.first - that.first) to (this.second - that.second)\n}", "src_uid": "7725f9906a1b87bf4e866df03112f1e0"} {"source_code": "import kotlin.system.exitProcess\n\nfun main() {\n val (l, r) = readLine()!!.split(\" \").map(String::toInt)\n val set = HashSet()\n for (x in l..r) {\n set.clear()\n val str = x.toString()\n str.forEach { set.add(it) }\n if (set.size == str.length) {\n println(str)\n exitProcess(0)\n }\n }\n println(-1)\n}", "src_uid": "3041b1240e59341ad9ec9ac823e57dd7"} {"source_code": "fun main(args: Array) {\n val (n,m)=readLine()!!.split(' ').take(2).map { it.toInt() }\n val x = readLine()!!.toInt()\n val (r, c) = n - 2 * x to m - 2 * x\n fun ans(x: Int):Int {\n val (r, c) = n - 2 * (x - 1) to m - 2 * (x - 1)\n return if (r < 0 || c < 0)\n 0\n else\n ((r-(r / 2)) * ((c + 1) / 2)) + ((r / 2) * (c / 2))\n }\n println(ans(x) - ans(x+1))\n}", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb"} {"source_code": "\nfun main(args : Array) {\n val (a, b) = readLine()!!.split(' ')\n var n = a.toInt()\n var k = b.toInt()\n var total = 0\n var r = n*2\n var g = n*5\n var bl = n*8\n\n var rt = 0\n var gt = 0\n var blt = 0\n\n if(r%k==0){ rt = r/k }\n else{ rt = r/k+1 }\n\n if(g%k==0){ gt = g/k }\n else{ gt = g/k+1 }\n\n if(bl%k==0){ blt = bl/k }\n else{ blt = bl/k+1 }\n\n total = rt + gt + blt\n\n println(total)\n\n}", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39"} {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.*\nval arr = IntArray(10)\nvar s = 0\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n val n = scanner.next()\n for (i in n)\n arr[i - '0']++\n s = 0\n println(dfs(0))\n\n}\n\nfun dfs(v: Int): Long {\n if (v == 10)\n return get()\n if (arr[v] == 0)\n return dfs(v + 1)\n var res = 0L\n val q = arr[v]\n for (i in 1..q) {\n arr[v] = i\n s += i\n res += dfs(v + 1)\n s -= i\n }\n return res\n}\n\nfun get(): Long {\n var res = 1L\n for (i in 2 until s)\n res *= i\n res *= s - arr[0]\n for (i in 0 until 10)\n for (j in 2..arr[i])\n res /= j\n return res\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\n\nfun IntArray.print() {\n println(Arrays.toString(this))\n}\n\n//class Pair(var a: Int, var b: Int): Comparable {\n// override fun compareTo(other: Pair): Int {\n// return b - a - other.b + other.a\n// }\n//}", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2"} {"source_code": "import java.util.*\nimport java.text.SimpleDateFormat\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val a = sc.nextLine()\n val b = sc.nextLine()\n val c = SimpleDateFormat(\"HH:mm\")\n val d1 = c.parse(a)\n val d2 = c.parse(b)\n var e = d1.time - d2.time\n if (e < 0)\n e += 24 * 60 * 60 * 1000\n val h = e/(60 * 60 * 1000)\n val m = (e%(60 * 60 * 1000))/(60 * 1000)\n when {\n h<10&&m<10 -> println(\"0$h:0$m\")\n h>=10&&m<10 -> println(\"$h:0$m\")\n h<10&&m>=10 -> println(\"0$h:$m\")\n else -> println(\"$h:$m\")\n }\n}\n", "src_uid": "595c4a628c261104c8eedad767e85775"} {"source_code": "fun main(args: Array) {\n val pages = readLine()!!.toInt()\n val days = readLine()!!.splitToIntArray()\n val useful = days.indices.filter { days[it] > 0 }\n\n var cur = -1\n var done = 0\n\n while (done < pages) {\n cur = (cur + 1) % useful.size\n done += days[useful[cur]]\n }\n\n println(useful[cur] + 1)\n}\n\nprivate fun String.toLettersList(): List {\n return toCharArray().map { it.toString() }\n}\n\nprivate fun String.splitToIntArray(): IntArray {\n val n = length\n if (n == 0) return IntArray(0) // EMPTY\n var res = IntArray(4)\n var m = 0\n var i = 0\n while (true) {\n var cur = 0\n var neg = false\n var c = get(i) // expecting number, IOOB if there is no number\n if (c == '-') {\n neg = true\n i++\n c = get(i) // expecting number, IOOB if there is no number\n }\n while (true) {\n val d = c.toInt() - '0'.toInt()\n require(d >= 0 && d <= 9) { \"Unexpected character '$c' at $i\" }\n require(cur >= Integer.MIN_VALUE / 10) { \"Overflow at $i\" }\n cur = cur * 10 - d\n require(cur <= 0) { \"Overflow at $i\" }\n i++\n if (i >= n) break\n c = get(i)\n if (c == ' ') break\n }\n if (m >= res.size) res = res.copyOf(res.size * 2)\n res[m++] = if (neg) cur else (-cur).apply { require(this >= 0) { \"Overflow at $i\" } }\n if (i >= n) break\n i++\n }\n if (m < res.size) res = res.copyOf(m)\n return res\n}", "src_uid": "007a779d966e2e9219789d6d9da7002c"} {"source_code": "var _debug = false;\nfun debug(vararg vals: T): Unit {\n if (!_debug) { return }\n for (v in vals) { System.err.print(v); System.err.print(\" \") }\n System.err.println()\n}\n\nval MOD = 998244353\nval MAXN = 5000\n\n//fun getBinomTriangle() : List> {\nfun getBinomTriangle() : Array {\n var p = Array(MAXN+1, { LongArray(MAXN+1) })\n //debug(\"p\", p.size)\n p[0][0] = 1\n for (i in 1..MAXN) {\n p[i][0] = 1\n for (j in 1..i) {\n p[i][j]=(p[i-1][j-1]+p[i-1][j]) % MOD\n }\n }\n return p\n}\n\nfun getFactorialTable() : LongArray {\n var ft = LongArray(MAXN+1)\n ft[0] = 1\n for (i in 1..MAXN) {\n ft[i] = (ft[i-1] * i) % MOD\n }\n return ft\n}\n\nval btr = getBinomTriangle()\nval ft = getFactorialTable()\n\nfun calculateCombinationsOfTwo(x : Int, y : Int) : Long {\n var res = 0L\n\n val the_min = listOf(x,y).min()!!\n for (k in 0..the_min) {\n var summand = ft[k]\n summand = (summand * btr[x][k]) % MOD\n summand = (summand * btr[y][k]) % MOD\n debug(\"kxy\", k, x, y, \"ft\", ft[k], \"btr\", btr[x][k], btr[y][k])\n res = (res + summand) % MOD\n }\n //debug(\"calc\", res)\n return res\n}\n\nfun main(args: Array) {\n if (args.size > 0 && args[0] == \"-d\") {\n _debug = true;\n }\n\n val (a, b, c) = readLine()!!.split(' ').map(String::toInt)\n debug(\"abc\", a, b, c)\n val ab = calculateCombinationsOfTwo(a, b)\n val ac = calculateCombinationsOfTwo(a, c)\n val bc = calculateCombinationsOfTwo(b, c)\n\n debug(\"end\", ab, ac, bc)\n\n var res = ab\n res = (res * bc) % MOD\n res = (res * ac) % MOD\n\n println(res)\n}\n\n", "src_uid": "b6dc5533fbf285d5ef4cf60ef6300383"} {"source_code": "\nimport java.util.*\n\nfun main (args: Array) {\n val sc = Scanner(System.`in`)\n val a = sc.nextInt()\n val b = sc.nextInt()\n\n if (a == b) {\n println(\"=\")\n return\n }\n\n if (b == 1) {\n println(\">\")\n return\n }\n\n val v = b * (Math.log10(a.toDouble()) / Math.log10(b.toDouble()))\n\n when {\n v < a -> println(\"<\")\n v > a -> println(\">\")\n else -> {\n println(\"=\")\n }\n }\n\n}", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6"} {"source_code": "import java.util.*\nprivate fun solve( x: Long) : Boolean{\n\n var a = x\n while (a != 0L)\n //print(a%10)\n if(a%10 == 8L || a%10 == -8L) {\n return true\n }\n else {\n a /= 10L\n }\n return false\n}\nval reader = Scanner(System.`in`)\nvar ans: Long = 0\nvar i: Long = 0\nfun main(args: Array){\n var n = reader.nextLong()\n \n while (!solve(++n)) ans++\n print(ans+1)\n\n}", "src_uid": "4e57740be015963c190e0bfe1ab74cb9"} {"source_code": "// Star because this code solves the problem, but in the tutorial there is a better solution using GCD\n//fun main() {\n// fun readInt() = readLine()!!.toInt()\n// fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n//\n// val n = readInt()\n// val nums = readInts().toIntArray()\n// var minimum = nums.min()!!\n// do {\n// for (pos in 0 until n) {\n// nums[pos] %= minimum\n// if (nums[pos] == 0) nums[pos] = minimum\n// }\n// minimum = nums.min()!!\n// } while (minimum != nums.max()!!)\n// print(minimum * n)\n//}\n\n// solution from tutorial\nfun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n infix fun Int.maxMin(b: Int): Pair = if (this >= b) this to b else b to this\n fun gcd(a: Int, b: Int): Int {\n var (max, min) = a maxMin b\n while (min != 0) {\n val newMin = max % min\n max = min\n min = newMin\n }\n return max\n }\n\n val n = readInt()\n val nums = readInts()\n val gcdNums = nums.reduce(::gcd)\n print(gcdNums * n)\n}", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4"} {"source_code": "import kotlin.math.min\n\nfun main(args: Array) {\n\n val (n, m, np, mp) = readLine()!!.split(' ').map(String::toInt)\n println(if ((m * np) <= mp) n * np else min((((n / m) * mp) + ((n % m) * np)), (((n / m) * mp) + mp)))\n\n}", "src_uid": "faa343ad6028c5a069857a38fa19bb24"} {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n val (a, b, c) = r.readLine()!!.split(\" \").map { it.toLong() }\n //val n = r.readLine()!!.toInt()\n val ans = c*2+ minOf(a, b)*2+ minOf(1, maxOf(a, b)- minOf(a, b))\n println(ans)\n}", "src_uid": "609f131325c13213aedcf8d55fc3ed77"} {"source_code": "fun main() {\n var nominal: Int = readLine()!!.toInt()\n var greatestDivisor = 2\n while(nominal>1){\n println(nominal)\n while(nominal%greatestDivisor!=0) greatestDivisor++\n nominal/=greatestDivisor\n }\n println(1)\n}", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63"} {"source_code": "//package Round526\n\nimport java.io.*\nimport java.util.*\nimport java.lang.Math.*\nimport java.lang.StringBuilder\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val pw = PrintWriter(System.out)\n val n = sc.nextInt()\n val a = LongArray(n) { sc.nextLong() }\n var min = Long.MAX_VALUE\n for (x in 1..n) {\n var sum = 0L\n for (i in 0 until n)\n sum += a[i] * (abs((i + 1) - x) + (i) + (x - 1)) * 2\n min = min(min, sum)\n }\n pw.print(min)\n pw.close()\n}", "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f"} {"source_code": "import java.util.*\nfun main() {\n var scanner = Scanner(System.`in`)\n var n = scanner.nextInt()\n var a = scanner.nextInt()\n var b = scanner.nextInt()\n var c = scanner.nextInt()\n var cz:Int\n var result:Int = 0\n for(x in 0..n){\n for(y in 0..n){\n cz = n-a*x-b*y\n if(cz<0) break;\n else if(cz.toDouble()/c % 1.0 == 0.0 && (a*x+b*y+cz) == n){\n if((x+y+cz.toDouble()/c)>result) result = x+y +cz/c\n }\n }\n }\n println(result)\n}\n", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43"} {"source_code": "import java.util.*\nimport kotlin.math.min\n\n//2019-03-30\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val totalHatches = nextInt()\n val position = nextInt()\n\n val closestDistanceToTheEdge = min(totalHatches - position, position - 1)\n print(closestDistanceToTheEdge + 6 + (totalHatches - 2) * 3)\n\n // Move to nearest corner\n // move rock to the left\n // pick coin\n // move to right\n // move 2 rocks to right\n // pick coin\n // (n - 2) * (move to left + move the rock + pick the coin)\n}", "src_uid": "24b02afe8d86314ec5f75a00c72af514"} {"source_code": "import java.io.InputStream\nimport java.io.PrintStream\nimport java.math.BigDecimal\nimport java.math.BigInteger\n\nprivate val MOD = 1e9.toLong() + 7\n\nval input = FastScanner()\n\nfun main(args: Array) {\n val (h, m) = input.nextString()!!.split(':').map { it.toInt() }\n val time = h * 60 + m\n var ans = 0\n while (!palindrome(toStr(time + ans))) {\n ans++\n }\n println(ans)\n}\n\nfun palindrome(s: String): Boolean {\n return s[0] == s[4] && s[1] == s[3]\n}\n\nfun toStr(time: Int): String {\n return String.format(\"%02d:%02d\", time / 60 % 24, time % 60)\n}\n\nfun String.toBigInteger() = BigInteger(this)\nfun String.toBigDecimal() = BigDecimal(this)\n\nclass FastScanner(private val input: InputStream = System.`in`) {\n private val sb = StringBuilder()\n private val buffer = ByteArray(4096)\n private var pos = 0\n private var size = 0\n\n fun nextString(): String? {\n var c = skipWhitespace()\n if (c < 0) return null\n\n return sb.run {\n setLength(0)\n\n do {\n append(c.toChar())\n c = read()\n } while (c > ' '.toInt())\n\n toString()\n }\n }\n\n fun nextLine(): String? {\n var c = read()\n if (c < 0) return null\n\n return sb.run {\n setLength(0)\n\n while (c >= 0 && c != '\\n'.toInt()) {\n append(c.toChar())\n c = read()\n }\n\n toString()\n }\n }\n\n fun nextLong(): Long {\n var c = skipWhitespace()\n\n val sign = if (c == '-'.toInt()) {\n c = read()\n -1\n } else 1\n\n var ans = 0L\n\n while (c > ' '.toInt()) {\n ans = ans * 10 + c - '0'.toInt()\n c = read()\n }\n\n return sign * ans\n }\n\n fun nextInt() = nextLong().toInt()\n fun nextDouble() = nextString()?.toDouble() ?: 0.0\n fun nextBigInteger(): BigInteger = nextString()?.toBigInteger() ?: BigInteger.ZERO\n fun nextBigDecimal(): BigDecimal = nextString()?.toBigDecimal() ?: BigDecimal.ZERO\n\n fun nextStrings(n: Int) = Array(n) { nextString() ?: \"\" }\n fun nextInts(n: Int) = IntArray(n) { nextInt() }\n fun nextLongs(n: Int) = LongArray(n) { nextLong() }\n fun nextDoubles(n: Int) = DoubleArray(n) { nextDouble() }\n fun nextBigIntegers(n: Int) = Array(n) { nextBigInteger() }\n fun nextBigDecimals(n: Int) = Array(n) { nextBigDecimal() }\n\n fun nextStrings(n: Int, m: Int) = Array(n) { nextStrings(m) }\n fun nextInts(n: Int, m: Int) = Array(n) { nextInts(m) }\n fun nextLongs(n: Int, m: Int) = Array(n) { nextLongs(m) }\n fun nextDoubles(n: Int, m: Int) = Array(n) { nextDoubles(m) }\n fun nextBigIntegers(n: Int, m: Int) = Array(n) { nextBigIntegers(m) }\n fun nextBigDecimals(n: Int, m: Int) = Array(n) { nextBigDecimals(m) }\n\n private fun skipWhitespace(): Int {\n while (true) {\n val c = read()\n if (c > ' '.toInt() || c < 0) return c\n }\n }\n\n private fun read(): Int {\n while (pos >= size) {\n if (size < 0) return -1\n size = input.read(buffer, 0, buffer.size)\n pos = 0\n }\n return buffer[pos++].toInt()\n }\n}\n", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5"} {"source_code": "import java.util.*\nfun main(args: Array) { var reader = Scanner(System.`in`)\n var n:Int = reader.nextInt()\n var s:String =n.toString()\n var c = 0\n var arrL = arrayListOf()\n var arrR = arrayListOf()\n for (i in 0..s.length-1) arrL.add(s[i])\n for (i in s.length-1 downTo 0) {\n if (arrL[i]=='0')\n arrL.removeAt(i)\n else break\n }\n for (i in 0..arrL.size-1) arrR.add(arrL[(arrL.size-1)-i])\n for (i in 0..arrL.size-1) {\n if (arrL[i]==arrR[i])\n c++\n }\n if (c==arrL.size) println(\"YES\")\n else print(\"NO\")\n}", "src_uid": "d82278932881e3aa997086c909f29051"} {"source_code": "fun main(args: Array) {\n var (w, h) = readLine()!!.split(\" \").map{it.toInt()}\n\n val s1 = readLine()!!.split(\" \").map{it.toInt()}\n val s2 = readLine()!!.split(\" \").map{it.toInt()}\n\n for (i in h downTo 0) {\n w += i\n if (i == s1[1]) {\n if (s1[0] > w) w = 0\n else w -= s1[0]\n } else if (i == s2[1]) {\n if (s2[0] > w) w = 0\n else w -= s2[0]\n }\n }\n println(w)\n}", "src_uid": "084a12eb3a708b43b880734f3ee51374"} {"source_code": "import java.util.*\nimport kotlin.collections.ArrayList\n\nfun main() {\n var const = \"AEIOUY\"\n var str = readLine()!!.split(\"A\",\"E\",\"I\",\"O\",\"U\",\"Y\")\n var str1 = str.maxBy { it.length }\n println(str1!!.length+1)\n \n}", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee"} {"source_code": "import java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\n\nfun main() {\n val jin = Scanner(System.`in`)\n val x = LongArray(100)\n val y = LongArray(100)\n x[0] = jin.nextLong()\n y[0] = jin.nextLong()\n val ax = jin.nextLong()\n val ay = jin.nextLong()\n val bx = jin.nextLong()\n val by = jin.nextLong()\n val xs = jin.nextLong()\n val ys = jin.nextLong()\n val t = jin.nextLong()\n var j = 1\n while (true) {\n x[j] = (ax * x[j - 1]) + bx\n y[j] = (ay * y[j - 1]) + by\n if (x[j] + y[j] >= 30000000000000000) {\n break\n }\n j++\n }\n var answer = 0\n for (k1 in 0..j) {\n for (k2 in 0..j) {\n val d = (abs(xs - x[k1]) + abs(ys - y[k1])) + (abs(x[k2] - x[k1]) + abs(y[k2] - y[k1]))\n if (d <= t) {\n answer = max(answer, abs(k1 - k2) + 1)\n }\n }\n }\n println(answer)\n}", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28"} {"source_code": "fun main() {\n val n = readInt()\n val a = readLn()\n var ls = 0\n var rs = 0\n for(i in a.indices) {\n if (a[i] == 'L') ls++ else rs++\n }\n println(ls + rs + 1);\n}\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int", "src_uid": "098ade88ed90664da279fe8a5a54b5ba"} {"source_code": "fun main() {\n val (n, m) = readLine()!!.split(' ').map { it.toInt() }\n val b = readLine()!!.split(\" \").map{it.toInt()}.sorted()\n var min = 1001\n for (i in 0..m-n){\n if (b[i + n - 1] - b[i] < min) min = b[i + n - 1] - b[i]\n }\n print(min)\n}", "src_uid": "7830aabb0663e645d54004063746e47f"} {"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", "src_uid": "41dfc86d341082dd96e089ac5433dc04"} {"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//}", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398"} {"source_code": "import java.util.*\n\nfun pair(x: Int): Int {\n if (x >= 0) {\n return x xor 1\n } else {\n return x.inv() xor 2\n }\n}\n\nfun current(x: Int) = when {\n x >= 0 -> x\n else -> x.inv()\n}\n\nfun opposite(x: Int) = pair(x.inv())\n\nfun oppositePair(x: Int) = current(x) xor 3\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val opposite = arrayOf(arrayOf(0, 8), arrayOf(4, 20), arrayOf(12, 16))\n val other = arrayOf(arrayOf(4, 16, 20, 12), arrayOf(8, 16.inv(), 2, 13.inv()),\n arrayOf(0.inv(), 4.inv(), 8.inv(), 21.inv()))\n val a = IntArray(24) { nextInt() }\n loop@ for (op in opposite.indices) {\n for (i in opposite[op]) {\n for (j in 0..3) {\n if (a[i + j] != a[i]) {\n continue@loop\n }\n }\n }\n val x = other[op]\n for (i in 0..3) {\n if (a[current(x[i])] != a[pair(x[i])]) {\n continue@loop\n }\n if (a[opposite(x[i])] != a[oppositePair(x[i])]) {\n continue@loop\n }\n }\n if ((-1..1 step 2).any { delta ->\n !(0..3).any { a[current(x[it])] != a[opposite(x[(it + delta) and 3])] }\n }) {\n println(\"YES\")\n return\n }\n }\n println(\"NO\")\n}", "src_uid": "881a820aa8184d9553278a0002a3b7c4"} {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //val (n, time) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val t = r.readLine()!!.split(\" \").map { it.toInt() }\n val str = r.readLine()!!\n var nextStart = 0\n for (i in 0..str.length - 1) {\n if (i < nextStart) continue\n when (str[i]) {\n '.' -> {\n s.append(0)\n nextStart++\n }\n '-' -> {\n nextStart += 2\n when(str[i+1]){\n '.' -> s.append(1)\n '-' -> s.append(2)\n }\n }\n }\n }\n println(s)\n}", "src_uid": "46b5a1cd1bd2985f2752662b7dbb1869"} {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n val n = readInt()\n val k = readInt()\n val D = readIntArray(k)\n\n val deg = n/2 * D.max()!!\n val fft = ModFFT(deg)\n val P = ModIntArray(10)\n for(d in D) P[d] = ModInt(1)\n\n val F = fft(P, false)\n for(i in F.indices) F[i] = F[i].pow(n/2)\n fft.inPlace(F, true)\n\n val ans = (0..deg).sumByModInt { F[it] * F[it] }\n println(ans)\n}\n\ninline val PRIMITIVE_ROOT get() = ModInt(3)\nclass ModFFT(maxDeg: Int) {\n val n = getArrSize(maxDeg)\n private val ninv = ModInt(n).inv_unmemoized()\n\n private fun getArrSize(deg: Int) = Integer.highestOneBit(deg shl 1 or 1)\n fun prepare(arr: ModIntArray, deg: Int) = arr.copyOf(getArrSize(deg))\n\n // w[1] represents n-th root of unity e^(i * tau/n), w[k] = w[1]^k\n val w = PRIMITIVE_ROOT.pow(TOTIENT / n).powArray(n)\n\n // rev[i] is reversal of bits in i\n private val rev = IntArray(n).also { rev ->\n var bit = 1\n var rbit = n shr 1\n while(bit < n) {\n for(i in 0 until bit) {\n rev[i or bit] = rbit or rev[i]\n }\n bit = bit shl 1\n rbit = rbit shr 1\n }\n }\n\n operator fun invoke(a: ModIntArray, invert: Boolean): ModIntArray {\n val res = a.copyOf(n)\n inPlace(res, invert)\n return res\n }\n\n // in-place FFT. Precondition: a.size <= n, and a.size is a power of 2\n fun inPlace(a: ModIntArray, invert: Boolean) {\n val sz = a.size\n if(sz <= 1) return\n require(sz <= n && sz and -sz == sz) { \"Array size $sz must be less than $n and a power of 2\" }\n val st = n / sz\n for(i in 0 until sz) {\n val j = rev[i * st]\n if(i < j) a[i] = a[j].also { a[j] = a[i] }\n }\n\n var len = 2\n var ang = n shr 1 // = n / len, representing the angle tau / len\n if(invert) ang = -ang\n while(len <= sz) {\n for(i in 0 until sz step len) {\n var k = 0\n for(j in i until i+len.shr(1)) {\n val u = a[j]\n val v = a[j+len.shr(1)] * w[k]\n a[j] = u + v\n a[j+len.shr(1)] = u - v\n k = k + ang and n-1\n }\n }\n\n len = len shl 1\n ang = ang shr 1\n }\n\n if(invert) {\n val szinv = ninv * st\n for(i in 0 until sz) a[i] *= szinv\n }\n }\n\n fun mul(a: ModIntArray, b: ModIntArray): ModIntArray {\n val deg = a.lastIndex + b.lastIndex\n require(deg < n) { \"FFT capacity $n too small for polynomial of degree $deg\" }\n val a1 = prepare(a, deg)\n val b1 = prepare(b, deg)\n inPlace(a1, false)\n inPlace(b1, false)\n for(i in a1.indices) a1[i] *= b1[i]\n inPlace(a1, true)\n return a1//.copyOf(deg+1)\n }\n}\n\nconst val MOD = 998244353\nconst val TOTIENT = MOD - 1 // assumes MOD is prime\n\ninfix fun Int.umod(mod: Int): Int = (this % mod).let { (it shr Int.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Long) = (this % mod).let { (it shr Long.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.umod(mod: Int) = umod(mod.toLong()).toInt()\n\nfun Int.mulMod(other: Int, mod: Int) = toLong() * other umod mod\n\nfun Int.powMod(exponent: Int, mod: Int): Int {\n if(exponent < 0) error(\"Inverse not implemented\")\n var res = 1L\n var e = exponent\n var b = umod(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\n\ninline fun Int.toModInt() = ModInt(this umod MOD)\ninline fun Long.toModInt() = ModInt(this umod MOD)\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n companion object {\n /** can't seem to make these private or inlined without causing compiler issues */\n @JvmField val _invMemo = HashMap()\n fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }\n }\n\n // normalizes an integer that's within range [-MOD, MOD) without branching\n private inline fun normalize(int: Int) = ModInt((int shr Int.SIZE_BITS - 1 and MOD) + int)\n\n operator fun plus(other: ModInt) = normalize(int + other.int - MOD) // overflow-safe even if MOD >= 2^30\n inline operator fun plus(other: Int) = plus(other.toModInt())\n operator fun inc() = normalize(int + (1 - MOD))\n\n operator fun minus(other: ModInt) = normalize(int - other.int)\n inline operator fun minus(other: Int) = minus(other.toModInt())\n operator fun dec() = normalize(int - 1)\n operator fun unaryMinus() = normalize(-int)\n\n operator fun times(other: ModInt) = ModInt((int.toLong() * other.int % MOD).toInt())\n inline operator fun times(other: Int) = ModInt(int.mulMod(other, MOD))\n\n fun pow(exponent: Int): ModInt {\n val e = if(exponent < 0) {\n require(int != 0) { \"Can't invert/divide by 0\" }\n exponent umod TOTIENT\n } else exponent\n return ModInt(int.powMod(e, MOD))\n }\n\n fun pow(exponent: Long) = if(int == 0) when {\n exponent > 0 -> this\n exponent == 0L -> ModInt(1)\n else -> error(\"Can't invert/divide by 0\")\n } else pow(exponent umod TOTIENT)\n\n inline fun inverse() = inv_memoized() /** NOTE: Change if necessary */\n\n fun inv_unmemoized(): ModInt {\n require(int != 0) { \"Can't invert/divide by 0\" }\n return pow(TOTIENT - 1)\n }\n inline fun inv_memoized() = _invMemoized(this)\n\n operator fun div(other: ModInt) = times(other.inverse())\n inline operator fun div(other: Int) = div(other.toModInt())\n\n override inline fun toString() = int.toString()\n}\n\ninline operator fun Int.plus(modInt: ModInt) = modInt + this\ninline operator fun Int.minus(modInt: ModInt) = toModInt() - modInt\ninline operator fun Int.times(modInt: ModInt) = modInt * this\ninline operator fun Int.div(modInt: ModInt) = modInt.inverse() * this\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n inline operator fun get(i: Int) = ModInt(intArray[i])\n inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override inline val size: Int get() = intArray.size\n inline val lastIndex get() = intArray.lastIndex\n inline val indices get() = intArray.indices\n\n override inline fun contains(element: ModInt): Boolean = element.int in intArray\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override inline fun isEmpty(): Boolean = intArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): ModInt = get(index++)\n }\n\n fun copyOf(newSize: Int) = ModIntArray(intArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun ModIntArray.copyInto(destination: ModIntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =\n ModIntArray(intArray.copyInto(destination.intArray, destinationOffset, startIndex, endIndex))\ninline fun ModIntArray(size: Int) = ModIntArray(IntArray(size))\ninline fun ModIntArray(size: Int, init: (Int) -> ModInt) = ModIntArray(IntArray(size) { init(it).int })\n\nfun ModInt.powArray(n: Int): ModIntArray {\n val res = ModIntArray(n+1)\n res[0] = ModInt(1)\n for(i in 1..n) res[i] = res[i-1] * this\n return res\n}\n\ninline fun ModIntArray.first() = get(0)\ninline fun ModIntArray.last() = get(lastIndex)\ninline fun ModIntArray.fold(init: R, op: (acc: R, ModInt) -> R) = intArray.fold(init) { acc, i -> op(acc, ModInt(i)) }\nfun ModIntArray.sum() = fold(ModInt(0), ModInt::plus)\nfun ModIntArray.product() = fold(ModInt(1), ModInt::times)\n\ninline fun Array.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Iterable.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Iterable.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\ninline fun Sequence.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Sequence.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\nfun Iterable.sum() = sumByModInt { it }\nfun Sequence.sum() = sumByModInt { it }\nfun Iterable.product() = productByModInt { it }\nfun Sequence.product() = productByModInt { it }\nfun Collection.toModIntArray() = ModIntArray(size).also { var i = 0; for(e in this) { it[i++] = e } }\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _ln = \"\"\n@JvmField var _lnPtr = 0\nfun read(): String {\n while (_lnPtr >= _ln.length) {\n _ln = readLine() ?: return \"\"\n _lnPtr = 0\n }\n var j = _ln.indexOf(' ', _lnPtr)\n if(j < 0) j = _ln.length\n val res = _ln.substring(_lnPtr, j)\n _lnPtr = j + 1\n return res\n}\nfun readRem(): String /* reads remainder of current line */ =\n _ln.substring(min(_lnPtr, _ln.length)).also { _lnPtr = _ln.length }\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf"} {"source_code": "\nimport java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n scanner.nextLine()\n\n val ns: List = scanner.nextLine().split(\" \").map { it.toInt() }\n val ms: List = scanner.nextLine().split(\" \").map { it.toInt() }\n\n val nMin: Int = ns.min()!!\n val mMin: Int = ms.min()!!\n\n val equals: MutableList = mutableListOf()\n ns.filter { ms.contains(it) }.forEach { equals.add(it) }\n val equalsMin = equals.min()\n\n if (nMin == mMin) {\n ee(equalsMin, nMin)\n println(nMin)\n System.exit(0)\n }\n val minOfBothConcat = when {\n nMin < mMin -> \"$nMin$mMin\"\n else -> \"$mMin$nMin\"\n }.toInt()\n\n if (ms.contains(nMin)) {\n if (minOfBothConcat > nMin) {\n ee(equalsMin, nMin)\n println(nMin)\n System.exit(0)\n }\n }\n\n if (ns.contains(mMin)) {\n if (minOfBothConcat > mMin) {\n ee(equalsMin, mMin)\n println(mMin)\n System.exit(0)\n }\n }\n ee(equalsMin, minOfBothConcat)\n println(minOfBothConcat)\n}\n\nprivate fun ee(equalsMin: Int?, target: Int) {\n equalsMin?.let {\n if (target > it) {\n println(it)\n System.exit(0)\n }\n }\n}", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee"} {"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}", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219"} {"source_code": "import java.util.*\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextLong()\n val k = scanner.nextLong()\n val a = scanner.nextLong()\n val b = scanner.nextLong()\n\n tailrec fun gcd(i: Long, j: Long): Long =\n if (i % j == 0L) j\n else gcd(j, i % j)\n\n val m = n * k\n var min = m\n var max = 1L\n\n outer@ for (i in arrayOf(a + b, a - b, -a + b, -a - b)) {\n for (j in 0L..n) {\n val s = j * k + i\n if (s in 1..m) {\n val g = gcd(m, s)\n val c = m / g\n min = min(min, c)\n max = max(max, c)\n if (min == 1L && max == m) break@outer\n }\n }\n }\n\n println(\"$min $max\")\n}", "src_uid": "5bb4adff1b332f43144047955eefba0c"} {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.io.InputStream\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.log\n\nfun main(args: Array) {\n class Scanner(s: InputStream) {\n private var st: StringTokenizer? = null\n private var br: BufferedReader = BufferedReader(InputStreamReader(s))\n\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n }\n\n val scan = Scanner(System.`in`)\n\n val n = scan.nextInt()\n val b = scan.nextInt()\n\n val a = (0 until n).map { scan.nextInt() }\n\n println(bestCuts(a, b, 0, a.size - 1))\n\n}\n\ndata class Item(val start: Int, val end: Int, val budget: Int)\n\nval dp = mutableMapOf()\n\nfun bestCuts(a: List, b: Int, start: Int, end: Int): Int {\n val memoryAns = dp[Item(start, end, b)]\n if (memoryAns != null) return memoryAns\n\n val size = end - start + 1\n if (size <= 2) return 0\n\n var ans = 0\n var odds = 0\n var evens = 0\n for (index in start..end) {\n val item = a[index]\n\n if (item % 2 == 0) evens++\n else odds++\n\n if (evens == odds && index + 1 <= end && abs(a[index + 1] - a[index]) <= b) {\n val rightBest = bestCuts(a, b - abs(a[index + 1] - a[index]), index + 1, a.size - 1)\n\n val tempAns = 1 + rightBest\n if (tempAns > ans) {\n ans = tempAns\n }\n }\n }\n\n dp[Item(start, end, b)] = ans\n return ans\n}\n", "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e"} {"source_code": "import kotlin.math.sign\n\nfun main(args: Array) {\n val b = buildString {\n for (i in 1..8) append(readLine()!!)\n }\n\n println(when (b.sumBy {\n when (it.toLowerCase()) {\n 'q' -> 9\n 'r' -> 5\n 'b' -> 3\n 'n' -> 3\n 'p' -> 1\n else -> 0\n } * if (it.isUpperCase()) 1 else -1\n }.sign) {\n 1 -> \"White\"\n -1 -> \"Black\"\n else -> \"Draw\"\n })\n}", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442"} {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n var n = r.readLine()!!.toLong()\n var base = 5\n var ans = 1\n //val l = r.readLine()!!.split(\" \").map { it.toInt() }\n while (n > 0) {\n if (n%2 == 1L){\n ans = ans * base %100\n }\n base = base * base % 100\n n /= 2\n }\n println(ans)\n}", "src_uid": "dcaff75492eafaf61d598779d6202c9d"} {"source_code": "// 2022.09.22 at 23:19:37 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.modM(b:Int):Int{ return ((this.toLong() * b) % pI).toInt() }\r\ninfix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }\r\ninfix fun Int.modMinus(b:Int):Int{ val ans = this - b;return if(ans < 0) ans + pI else ans }\r\nfun Int.inverse():Int = intPow(this,pI-2,pI)\r\ninfix fun Int.modDivide(b:Int):Int{ return this modM (b.inverse()) }\r\nfun intPow(x:Int,e:Int,m:Int):Int{\r\n var X = x ; var E =e ; var Y = 1\r\n while(E > 0){\r\n if(E and 1 == 0){\r\n X = ((1L * X * X) % m).toInt()\r\n E = E shr 1\r\n }else{\r\n Y = ((1L * X * Y) % m).toInt()\r\n E -= 1\r\n }\r\n }\r\n return Y\r\n}\r\n// 2. DP initial values\r\nconst val plarge = 1_000_000_727\r\nconst val nlarge = -plarge\r\nconst val phuge = 2_727_000_000_000_000_000L\r\nconst val nhuge = -phuge\r\n// 3. convenience conversions\r\nval Boolean.chi:Int get() = if(this) 1 else 0 //characteristic function\r\nval BooleanArray.chiarray:IntArray get() = IntArray(this.size){this[it].chi}\r\nval Char.code :Int get() = this.toInt() - 'a'.toInt()\r\n//3. hard to write stuff\r\nfun IntArray.put(i:Int,v:Int){ this[i] = (this[i] + v).adjust() }\r\nval mint:MutableList get() = mutableListOf()\r\nval mong:MutableList get() = mutableListOf()\r\n//4. more outputs\r\nfun List.conca():String = this.joinToString(\"\")\r\nval CharArray.conca :String get() = this.joinToString(\"\")\r\nval IntArray.conca :String get() = this.joinToString(\" \")\r\n@JvmName(\"concaInt\")\r\nfun List.conca():String = this.joinToString(\" \")\r\nval LongArray.conca:String get() = this.joinToString(\" \")\r\n@JvmName(\"concaLong\")\r\nfun List.conca():String = this.joinToString(\" \")\r\n//5. Pair of ints\r\nconst val longmask = (1L shl 32) - 1\r\nfun makepair(a:Int, b:Int):Long = (a.toLong() shl 32) xor (longmask and b.toLong())\r\nval Long.first get() = (this ushr 32).toInt()\r\nval Long.second get() = this.toInt()\r\n//6. strings\r\nval String.size get() = this.length\r\nconst val randCount = 100\r\n//7. bits\r\nfun Int.has(i:Int):Boolean = (this and (1 shl i) != 0)\r\nfun Long.has(i:Int):Boolean = (this and (1L shl i) != 0L)\r\n//8 TIME\r\ninline fun TIME(f:()->Unit){\r\n val t = measureTimeMillis(){\r\n f()\r\n }\r\n println(\"$t ms\")\r\n}\r\n//9.ordered pair\r\nfun order(a:Int, b:Int):Pair{\r\n return Pair(minOf(a,b), maxOf(a,b))\r\n}\r\nconst val interactive = false\r\nobject Reader{\r\n private const val BS = 1 shl 16\r\n private const val NC = 0.toChar()\r\n private val buf = ByteArray(BS)\r\n private var bId = 0\r\n private var size = 0\r\n private var c = NC\r\n\r\n var warningActive = true\r\n var fakein = StringBuilder()\r\n\r\n private var IN: BufferedInputStream = BufferedInputStream(System.`in`, BS)\r\n val OUT: PrintWriter = PrintWriter(System.out)\r\n\r\n private val char: Char\r\n get() {\r\n if(interactive){\r\n return System.`in`.read().toChar()\r\n }\r\n while (bId == size) {\r\n size = IN.read(buf) // no need for checked exceptions\r\n if (size == -1) return NC\r\n bId = 0\r\n }\r\n return buf[bId++].toChar()\r\n }\r\n\r\n fun nextInt(): Int {\r\n var neg = false\r\n if (c == NC) c = char\r\n while (c < '0' || c > '9') {\r\n if (c == '-') neg = true\r\n c = char\r\n }\r\n var res = 0\r\n while (c in '0'..'9') {\r\n res = (res shl 3) + (res shl 1) + (c - '0')\r\n c = char\r\n }\r\n return if (neg) -res else res\r\n }\r\n fun nextLong(): Long {\r\n var neg = false\r\n if (c == NC) c = char\r\n while (c < '0' || c > '9') {\r\n if (c == '-') neg = true\r\n c = char\r\n }\r\n var res = 0L\r\n while (c in '0'..'9') {\r\n res = (res shl 3) + (res shl 1) + (c - '0')\r\n c = char\r\n }\r\n return if (neg) -res else res\r\n }\r\n fun nextString():String{\r\n val ret = StringBuilder()\r\n while (true){\r\n c = char\r\n if(!isWhitespace(c)){ break}\r\n }\r\n ret.append(c)\r\n while (true){\r\n c = char\r\n if(isWhitespace(c)){ break}\r\n ret.append(c)\r\n }\r\n return ret.toString()\r\n }\r\n fun isWhitespace(c:Char):Boolean{\r\n return c == ' ' || c == '\\n' || c == '\\r' || c == '\\t'\r\n }\r\n fun rerouteInput(){\r\n if(warningActive){\r\n put(\"Custom test enabled\")\r\n println(\"Custom test enabled\")\r\n warningActive = false\r\n }\r\n val S = fakein.toString()\r\n println(\"New Case \")\r\n println(S.take(80))\r\n println(\"...\")\r\n fakein.clear()\r\n IN = BufferedInputStream(S.byteInputStream(),BS)\r\n }\r\n fun flush(){\r\n OUT.flush()\r\n }\r\n fun takeFile(name:String){\r\n IN = BufferedInputStream(File(name).inputStream(),BS)\r\n }\r\n}\r\nfun 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\nval just = \" \"\r\nfun crash(){\r\n throw Exception(\"Bad programme\")}\r\nfun assert(a:Boolean){\r\n if(!a){\r\n throw Exception(\"Failed Assertion\")\r\n }}\r\nenum class solveMode {\r\n real, rand, tc\r\n}\r\nobject solve{\r\n var mode:solveMode = solveMode.real\r\n var tcNum:Int = 0\r\n var rand:()->Unit = {}\r\n var TC:MutableMapUnit> = mutableMapOf()\r\n var tn:Long = 0\r\n fun cases(onecase:()->Unit){\r\n val t = if(mode == solveMode.real){if(singleCase) 1 else getint} else if(mode == solveMode.tc){1 } else randCount\r\n if(pI != 998_244_353 && pI != 1_000_000_007){\r\n throw Exception(\"Not usual primes!\")\r\n }\r\n if(t == 1 && mode != solveMode.real){\r\n tn = System.currentTimeMillis()\r\n }\r\n repeat(t){\r\n if(mode == solveMode.tc){\r\n TC[tcNum]?.let { it() }\r\n Reader.rerouteInput()\r\n }else if(mode == solveMode.rand){\r\n rand()\r\n Reader.rerouteInput()\r\n }\r\n onecase()\r\n }\r\n if(t == 1 && mode != solveMode.real){\r\n val dt = System.currentTimeMillis() - tn\r\n println(\"Time $dt ms \")\r\n }\r\n }\r\n inline fun singleCase(a:solve.()->Unit){\r\n val t = if(mode != solveMode.rand){1} else randCount\r\n repeat(t) { a() }\r\n }\r\n fun rand(a:()->Unit){\r\n this.rand = a\r\n }\r\n fun tc(id:Int = 0,a:()->Unit){\r\n TC[id] = a\r\n }\r\n fun usetc(a:Int = 0 ){\r\n this.tcNum = a\r\n this.mode = solveMode.tc\r\n }\r\n fun userand(){\r\n this.mode = solveMode.rand\r\n }\r\n}\r\nfun debug(){}\r\n\r\n\r\nfun nullablePacker(a:IntArray,want:Int):BooleanArray?{\r\n\t//can have things being 0, will be skipped\r\n\t//returning guaraneted that 0 spots kept 0\r\n\tval size = want\r\n\tval DP = IntArray(size + 1){-1}\r\n\tDP[0] = -2\r\n\tfor((i,c) in a.withIndex()){\r\n\t\tif(c == 0) continue\r\n\t\tfor(left in size downTo 0){\r\n\t\t\tif(DP[left] == -1) continue\r\n\t\t\tval next = left + c\r\n\t\t\tif(next !in 0..size) continue\r\n\t\t\tif(DP[next] != -1) continue\r\n\t\t\tDP[next] = i\r\n\t\t}\r\n\t}\r\n\tif(DP[want] == -1) return null\r\n\tval ret = BooleanArray(a.size)\r\n\tvar now = want\r\n\twhile(now > 0){\r\n\t\tval next = DP[now]\r\n\t\tnow -= a[next]\r\n\t\tret[next] = true\r\n\t}\r\n// assert((0 until a.size).sumOf { if(ret[it]) a[it] else 0 } == want)\r\n\treturn ret\r\n}\r\nconst val singleCase = true\r\nfun main(){\r\n solve.cases{\r\n\t\tval n = getint\r\n\t\tval L = getline(n)\r\n\r\n\t\tval s = L.sum()\r\n\t\tif(s %2 == 1){\r\n\t\t\tput(0)\r\n\t\t\treturn@cases\r\n\t\t}\r\n\t\tif(nullablePacker(L,s/2) != null){\r\n\t\t\twhile(L.all { it %2 == 0 }){\r\n\t\t\t\tfor(i in 0 until n){\r\n\t\t\t\t\tL[i] /= 2\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tput(1)\r\n\t\t\tput(L.indexOfFirst { it %2 == 1 } + 1 )\r\n\t\t}else{\r\n\t\t\tput(0)\r\n\t\t\treturn@cases\r\n\t\t}\r\n\r\n\r\n\r\n\r\n }\r\n done()\r\n}\r\n\r\n\r\n\r\n", "src_uid": "29063ad54712b4911c6bf871969ee147"} {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.ArrayDeque\nimport java.util.StringTokenizer\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\nfun main() {\n output {\n val s = readLn()\n val t = readLn()\n\n val open = ArrayDeque()\n open.add(Entry(0, 0, 0, null))\n val closed = hashSetOf(State(0, 0, 0))\n\n val ans = run {\n while(true) {\n val (i, j, bal, path) = open.remove()\n if (i == s.length && j == t.length && bal == 0)\n return@run path.toString()\n for (c in \"()\") {\n val nbal = bal + if (c == '(') 1 else -1\n if (nbal !in 0..200) continue\n val ni = if (i < s.length && c == s[i]) i + 1 else i\n val nj = if (j < t.length && c == t[j]) j + 1 else j\n if (closed.add(State(ni, nj, nbal))) {\n open.add(Entry(ni, nj, nbal, path + c))\n }\n }\n }\n \"\"\n }\n\n println(ans)\n }\n}\n\ndata class State(val i: Int, val j: Int, val bal: Int) {\n override fun hashCode(): Int = i.times(201).plus(j).times(201).plus(bal)\n}\ndata class Entry(val i: Int, val j: Int, val bal: Int, val path: CharPathNode?)\n\nclass CharPathNode(val data: Char, val parent: CharPathNode? = null) {\n operator fun plus(childData: Char) = CharPathNode(childData, this)\n\n override fun toString() = buildString {\n var node = this@CharPathNode\n while(true) {\n append(node.data)\n node = node.parent ?: break\n }\n reverse()\n }\n}\n\noperator fun CharPathNode?.plus(childData: Char) = CharPathNode(childData, this)\nfun CharPathNode?.toString() = this?.toString().orEmpty()\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\ninline fun output(block: PrintWriter.() -> Unit) { _writer.apply(block).flush() }\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}", "src_uid": "cc222aab45b3ad3d0e71227592c883f1"} {"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", "src_uid": "142b06ed43b3473513995de995e19fc3"} {"source_code": "\n\nfun main(args: Array)\n{\n var reg=Regex(\" \")\n var s=readLine()!!.split(reg)\n var a=s[0].toInt()\n var b=s[1].toInt()\n var i=0\n var flag=0\n var demand=1\n while(true)\n {\n if(i%2==0)\n {\n if(a) {\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}", "src_uid": "fa4b1de79708329bb85437e1413e13df"} {"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}", "src_uid": "e7b9eec21d950f5d963ff50619c6f119"} {"source_code": "fun main() {\n var (n, a, x, b, y) = readInts()\n\n var ans = a == b\n while(a != x && b != y && !ans) {\n a = if(a == n) 1 else a + 1\n b = if(b == 1) n else b - 1\n\n ans = a == b\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 readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit)\n { Output().apply(block).nowPrint() }\n", "src_uid": "5b889751f82c9f32f223cdee0c0095e4"} {"source_code": "import java.lang.Long.max\nimport java.lang.Long.min\nimport java.util.*\n\n fun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val n: Int\n val m: Int\n val K: Int\n n = scanner.nextInt()\n m = scanner.nextInt()\n K = scanner.nextInt()\n val a = LongArray(n)\n val b = LongArray(m)\n val c = Array(n) { LongArray(m) }\n val d = LongArray(n + m + 1)\n val e = LongArray(n + m + 1)\n val f = LongArray(n + m + 1)\n var dc = 0\n val S: MutableSet = TreeSet()\n val map: MutableMap = HashMap()\n for (i in 0 until n) {\n a[i] = scanner.nextLong()\n S.add(a[i])\n }\n for (i in 0 until m) {\n b[i] = scanner.nextLong()\n S.add(b[i])\n }\n for (v in S) {\n d[++dc] = v\n map[v] = dc\n }\n for (i in 0 until n) {\n for (j in 0 until m) {\n c[i][j] = scanner.nextLong()\n val id = map[max(a[i], b[j])]!!\n e[id] = max(e[id], c[i][j])\n }\n }\n var ans = 0x3f3f3f3f3f3f3f3fL\n for (t in 1..dc) {\n e[t] += K.toLong()\n for (i in 1..dc) {\n f[i] = max(e[i], f[i - 1])\n }\n var cur: Long = 0\n var r: Long = 0\n var id = 1\n while (id < dc) {\n while (id < dc && cur >= d[id + 1]) {\n id++\n }\n if (id == dc) break\n val dif = d[id + 1] - cur\n val need = (dif + f[id] - 1) / f[id]\n r += need\n cur += need * f[id]\n }\n ans = min(ans, r)\n e[t] -= K.toLong()\n }\n println(ans)\n }", "src_uid": "309d0bc338fafcef050f336a7fa804c7"} {"source_code": "fun main(args: Array) {\n val firstString =readLine()!!.toLowerCase()\n val secondString =readLine()!!.toLowerCase()\n print(compareTo(firstString.compareTo(secondString)))\n}\n\nfun compareTo(int:Int): Int{\n return when {\n int in 1.. Int.MAX_VALUE -> 1\n int == 0 -> 0\n else -> -1\n }\n}", "src_uid": "ffeae332696a901813677bd1033cf01e"} {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n\n val n = sc.nextLong()\n val k = sc.nextInt()\n\n println(n.round(k))\n}\n\nfun Long.round(k: Int): Long {\n var t = this\n var doub = 0\n while (t % 2 == 0L) {\n doub += 1\n t /= 2\n }\n var five = 0\n while (t % 5 == 0L) {\n five += 1\n t /= 5\n }\n\n var res = this\n while (doub < k) {\n res *= 2\n doub += 1\n }\n while (five < k) {\n res *= 5\n five += 1\n }\n return res\n}\n", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3"} {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashSet\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val n: Int = ir.nextInt()\n val p: Int = ir.nextInt()\n val s = arrayOfNulls(n)\n var total: Long = 0\n var res = 0.0\n\n repeat(n) {\n s[it] = ir.next()\n }\n\n for (i in (n - 1) downTo 0) {\n total *= 2\n if (s[i] == \"halfplus\")\n total++\n res += (p * (total / 2.0))\n }\n\n pw.print(res.toLong())\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}", "src_uid": "6330891dd05bb70241e2a052f5bf5a58"} {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toLong()\n\n if(n > 0) {\n println(n)\n } else {\n val op1 = n / 10L\n val op2 = ((n / 100) * 10) + (n % 10)\n \n if(op1 > op2)\n println(op1)\n else\n println(op2)\n }\n}", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e"} {"source_code": "import java.util.*\n\n//2019-07-05\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val n = nextInt()\n nextLine()\n val l = nextLine()\n var zeros = 0\n var ones = 0\n for (c in l) {\n if (c == '0') zeros++ else ones++\n }\n\n if (l.length > 1 && zeros == ones) {\n println(2)\n println(l[0] + \" \" + l.substring(1))\n } else {\n println(1)\n println(l)\n }\n}", "src_uid": "4ebed264d40a449602a26ceef2e849d1"} {"source_code": "fun main(args: Array) {\n val (n) = readLine()!!.split(' ').map(String::toLong)\n println((3*n*n)+(3*n)+1)\n}", "src_uid": "c046895a90f2e1381a7c1867020453bd"} {"source_code": "import kotlin.properties.Delegates\n\nimport kotlin.reflect.KProperty\n\nclass Memorize(val func: (T) -> R) {\n val cache = mutableMapOf()\n\n operator fun getValue(thisRef: Any?, property: KProperty<*>) = { n: T ->\n cache.getOrPut(n) { func(n) }\n }\n}\n\nvar l by Delegates.notNull()\nlateinit var day:List\n\nval f:(Pair) -> Int by Memorize { (i, type) ->\n when{\n i == l-1 -> if (type==day[i]||day[i]==3) 0 else 1\n type==day[i]||day[i]==3 -> f(Pair(i+1, 3-type))\n else -> 1+ minOf(f(Pair(i+1, type)), f(Pair(i+1, 3-type)))\n }\n}\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n l = r.readLine()!!.toInt()\n day = r.readLine()!!.split(\" \").map { it.toInt() }\n println(minOf(f(Pair(0, 1)), f(Pair(0, 2))))\n}", "src_uid": "08f1ba79ced688958695a7cfcfdda035"} {"source_code": "//kotlinc kot.kt -include-runtime -d kot.jar\n//java -jar kot.jar\nimport kotlin.math.*\nimport java.util.ArrayList\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of ints\n\nfun main(){\n\tvar n = readInt()\n\tvar arr: ArrayList = ArrayList(n)\n\tvar x = readLine()!!.split((' ')).map(String::toInt)\n\tfor(i in 0..n-1){\n\t\tarr.add(x[i.toInt()])\n\t}\n\tvar cnt: ArrayList = ArrayList(20020)\n\tfor(i in 0..(20020-1)){\n\t\tcnt.add(0)\n\t}\n\tvar ans = 0\n\tfor(i in 0..n-1){\n\t\tvar aa = arr[i.toInt()]\n\t\tif( (arr[i.toInt()] > 0) && (cnt[aa] == 0) ) { \n\t\t\tans = ans + 1\n\t\t\tcnt[aa] = 1\n\t\t}\n\t}\n\tprintln(ans)\n}\n", "src_uid": "3b520c15ea9a11b16129da30dcfb5161"} {"source_code": "import kotlin.math.ceil\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val numGrades = readInt()\n val grades = readInts().sorted()\n var necessary = ceil(4.5 * numGrades - grades.sum())\n var sol = 0\n for (grade in grades)\n if (necessary <= 0) break else {\n sol++\n necessary -= 5 - grade\n }\n print(sol)\n}", "src_uid": "715608282b27a0a25b66f08574a6d5bd"} {"source_code": "fun main(args: Array) = with(java.util.Scanner(System.`in`)) {\n var a = nextInt()\n var b = nextInt()\n var c = nextInt()\n var d = minOf(a,minOf(b/2,c/4))\n println(7*d)\n}", "src_uid": "82a4a60eac90765fb62f2a77d2305c01"} {"source_code": "import kotlin.math.min\n\nfun readString() = readLine()!!\nfun readStrings() = readString().split(\" \")\nfun readInt() = readString().toInt()\nfun readInts() = readStrings().map { it.toInt() }\nfun readLong() = readString().toLong()\nfun readLongs() = readStrings().map { it.toLong() }\nfun readDouble() = readString().toDouble()\nfun readDoubles() = readStrings().map { it.toDouble() }\n\nfun main() {\n val (k2, k3, k5, k6) = readInts()\n print(256 * min(k2, min(k5, k6)) + 32 * min(k2 - min(k2, min(k5, k6)), k3))\n}\n\n", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e"} {"source_code": "\n\nimport java.util.*\n\n/**\n * Solution for codeforces.com/problemset/problem/59/C?locale=en.\n *\n * @param maxLetterNumber maximum letter number that must be used in the title\n * @param pattern approximate variant of the title\n */\nclass Problem59C(private val maxLetterNumber: Int, pattern: String) {\n private var answer: String? = null\n private var unusedLetter = 'a'\n private val pattern: CharArray = pattern.toCharArray()\n private val usedLetters = HashMap()\n\n /**\n * Returns lexicographically smallest correct title if it's possible, and [noSolutionAnswer] otherwise.\n */\n fun solve(): String {\n val answer = this.answer\n if (answer != null) {\n return answer\n }\n\n if (!completePattern()) {\n this.answer = noSolutionAnswer\n return noSolutionAnswer\n }\n markUsedLetters()\n\n val unusedLettersNumber = maxLetterNumber - usedLetters.size\n val lastIndex = pattern.size - 1\n val freePosNumber = (0..lastIndex / 2)\n .filter { pattern[it] == questionMark }\n .count()\n if (unusedLettersNumber > freePosNumber || unusedLettersNumber < 0) {\n this.answer = noSolutionAnswer\n return noSolutionAnswer\n }\n var difference = freePosNumber - unusedLettersNumber\n (0..lastIndex / 2)\n .asSequence()\n .filter { pattern[it] == '?' }\n .forEach {\n if (difference > 0) {\n pattern[it] = 'a'\n pattern[lastIndex - it] = 'a'\n difference--\n } else {\n updateUnusedLetter()\n pattern[it] = unusedLetter\n pattern[lastIndex - it] = unusedLetter\n usedLetters[unusedLetter] = true\n }\n }\n this.answer = pattern.joinToString(\"\")\n\n return pattern.joinToString(\"\")\n }\n\n /**\n * Replaces question marks with already determined by palindrome condition letters.\n *\n * @return true if the title can be palindrome, and false otherwise\n */\n private fun completePattern(): Boolean {\n val lastIndex = pattern.size - 1\n\n for (i in 0..lastIndex / 2) {\n when {\n pattern[i] == questionMark -> pattern[i] = pattern[lastIndex - i]\n pattern[lastIndex - i] == questionMark -> pattern[lastIndex - i] = pattern[i]\n pattern[i] != pattern[lastIndex - i] -> return false\n }\n }\n\n return true\n }\n\n /**\n * Marks used letters in [usedLetters].\n */\n private fun markUsedLetters() {\n val middle = (pattern.size - 1) / 2\n (0..middle)\n .filter { pattern[it] != questionMark }\n .forEach { usedLetters[pattern[it]] = true }\n }\n\n /**\n * Updates lexicographically smallest unused letter.\n */\n private fun updateUnusedLetter() {\n while (usedLetters[unusedLetter] == true) {\n unusedLetter = unusedLetter.inc()\n }\n }\n\n companion object {\n val noSolutionAnswer = \"IMPOSSIBLE\"\n val questionMark = '?'\n }\n\n}\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val maxLetterNumber = scanner.nextInt()\n val pattern = scanner.next()\n val problem = Problem59C(maxLetterNumber, pattern)\n print(problem.solve())\n}", "src_uid": "9d1dd9d722e5fe46823224334b3b208a"} {"source_code": "fun main() {\n val list = readLine()!!.split(\" \").map { it.toLong() }\n val q = (list[0]/list[1])\n val rem = (list[0] % list[1])\n val d=(list[0] - list[1])\n if (list[1] == 1L) {\n val a = (list[0]*(list[0] - 1)/2)\n println(\"$a $a\")\n }\n else if (d == 1L)\n println(\"1 1\")\n else{\n val max=d*(d+1)/2\n val min=((list[1]-rem)*(q)*(q-1)/2)+(rem)*(q)*(q+1)/2\n println(\"$min $max\")\n }\n}", "src_uid": "a081d400a5ce22899b91df38ba98eecc"} {"source_code": "import java.io.*\n\nval reader = BufferedReader(InputStreamReader(System.`in`))\nval writer = PrintWriter(System.out)\n\nconst val maxN = 55\n\n\nfun solve() {\n var (a, b, m) = reader.readLine()!!.split(\" \").map { it.toLong() }\n for (q in maxN downTo 1) {\n var coefficients = LongArray(q) { 1L }\n var r = LongArray(q) { 1L }\n r[0] = a\n for (i in 0 until q - 1) {\n coefficients[i] = (1L shl (q - i - 2))\n }\n var cur = 0L\n for (i in 0 until q) {\n cur += coefficients[i] * r[i]\n if (coefficients[i] * r[i] < 0) {\n cur = -1\n break\n }\n }\n if (cur < 0 || cur > b) {\n continue\n }\n for (i in 1 until q) {\n var rem = b - cur\n var addingValue = rem / coefficients[i]\n addingValue = Math.min(addingValue, m - 1 )\n r[i] += addingValue\n cur += addingValue * coefficients[i]\n }\n if (cur == b) {\n writer.print(\"$q \")\n var sum = 0L\n for (i in 0 until q) {\n var previousSum = sum\n sum += r[i]\n writer.print(\"$sum \")\n sum += previousSum\n }\n writer.print(\"\\n\")\n return\n } else {\n continue\n }\n }\n writer.print(\"-1\\n\")\n}\n\nfun main() {\n val q = reader.readLine()!!.toInt()\n for (i in 1..q) {\n solve()\n }\n writer.close()\n}", "src_uid": "c9d646762e2e78064bc0670ec7c173c6"} {"source_code": "import java.io.*\nimport java.util.*\n\nfun > max(a: T, b: T): T = if (b > a) b else a\nfun > min(a: T, b: T): T = if (b < a) b else a\nfun Number.isEven(): Boolean = if (this.toInt() and 1 == 0) true else false\nfun Number.isOdd(): Boolean = !this.isEven()\n\nfun main(args: Array) {\n if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))\n val br = BufferedReader(InputStreamReader(System.`in`))\n val bw = BufferedWriter(OutputStreamWriter(System.out))\n\n var st = StringTokenizer(br.readLine())\n val str = st.nextToken()\n var hasDigit = false; var hasLower = false; var hasUpper = false\n for (c in str) {\n if (c >= '0' && c <= '9') hasDigit = true\n else if (c >= 'a' && c <= 'z') hasLower = true\n else if (c >= 'A' && c <= 'Z') hasUpper = true\n }\n if (str.length >= 5 && hasDigit && hasLower && hasUpper) bw.write(\"Correct\")\n else bw.write(\"Too weak\")\n bw.newLine()\n bw.flush()\n}\n", "src_uid": "42a964b01e269491975965860ec92be7"} {"source_code": "import java.io.InputStream\nimport java.util.*\nimport kotlin.math.min\n\nconst val CODE_0 = '0'.toByte()\nconst val CODE_1 = '9'.toByte()\n\nvar s: String = \"\"\nvar n: Int = 0\nval dp = Array(500) { IntArray(500) }\n\nclass Main {\n companion object {\n @JvmStatic\n private fun ans(l: Int, r: Int): Int {\n dp[l][r] = when {\n dp[l][r] > 0 -> dp[l][r]\n l == r -> 1\n l > r -> 0\n else -> ((l + 1)..r).fold(1 + ans(l + 1, r)) { acc, i ->\n if (s[i] != s[l]) acc else min(acc, ans(l + 1, i - 1) + ans(i, r))\n }\n }\n return dp[l][r]\n }\n\n @JvmStatic\n fun main(args: Array) = with(Scanner(System.`in`)) {\n n = nextInt()\n s = next()\n println(ans(0, n - 1))\n }\n }\n\n\n // -----------------------------------------------------------------------------------------------------------------\n\n private class FastScanner(private val iss: InputStream = System.`in`) {\n fun nextInt(): Int {\n var v = 0\n var begin = false\n while (true) {\n val c = iss.read()\n if (c in CODE_0..CODE_1) {\n begin = true\n v *= 10\n v += c - CODE_0\n } else if (begin) {\n return v\n }\n }\n }\n }\n}\n\nfun main(args: Array) = Main.main(args)", "src_uid": "516a89f4d1ae867fc1151becd92471e6"} {"source_code": "\nfun main(){\n var (n,d) = readLine()!!.split(' ').map { it.toInt() }\n var list = readLine()!!.split(' ').map { it.toInt() }.sorted()\n var m = readLine()!!.toInt()\n\n if (m>=n){\n println(list.sum() - ((m-n)*d))\n }else{\n var ans = 0\n for (i in 0..m-1){\n ans+=list[i]\n }\n println(ans)\n }\n}", "src_uid": "5c21e2dd658825580522af525142397d"} {"source_code": "import kotlin.math.sqrt\n\n// unable to solve it by myself. Solution on the editorial: https://codeforces.com/blog/entry/62688\nfun main() {\n fun readLong() = readLine()!!.toLong()\n\n fun Long.factors(): MutableSet {\n val output = mutableSetOf()\n val endLoop = sqrt(this.toDouble()).toLong()\n for (i in 1L..endLoop) {\n if (this % i == 0L) {\n output.add(i)\n output.add(this / i)\n }\n }\n return output\n }\n\n print(readLong().factors().size)\n}", "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1"} {"source_code": "import java.util.*\n\nfun main() {\n val jin = Scanner(System.`in`)\n val xs = jin.nextInt()\n val ys = jin.nextInt()\n val n = jin.nextInt()\n val x = IntArray(n)\n val y = IntArray(n)\n for (j in 0 until n) {\n x[j] = jin.nextInt()\n y[j] = jin.nextInt()\n }\n val dp = IntArray(1 shl n) { 100000000 }\n val dpPrev = IntArray(1 shl n) { -1 }\n dp[0] = 0\n for (mask in 1 until (1 shl n)) {\n var j = 0\n while (((mask shr j) and 1) == 0) {\n j++\n }\n dp[mask] = ((x[j] - xs) * (x[j] - xs)) + ((y[j] - ys) * (y[j] - ys)) + dp[mask - (1 shl j)]\n for (k in j + 1 until n) {\n if (((mask shr k) and 1) != 0) {\n val value = ((x[j] - x[k]) * (x[j] - x[k])) + ((y[j] - y[k]) * (y[j] - y[k])) + dp[mask - (1 shl j) - (1 shl k)]\n if (value < dp[mask]) {\n dp[mask] = value\n dpPrev[mask] = k\n }\n }\n }\n }\n val way = mutableListOf()\n var mask = (1 shl n) - 1\n for (j in 0 until n) {\n if (((mask shr j) and 1) != 0) {\n val k = dpPrev[mask]\n //println(\"j = $j, k = $k\")\n way.add(0)\n way.add(j + 1)\n if (k != -1) {\n way.add(k + 1)\n }\n mask -= 1 shl j\n if (k != -1) {\n mask -= 1 shl k\n }\n }\n }\n way.add(0)\n var answer = 0\n for (j in 1 until way.size) {\n val x1 = if (way[j - 1] == 0) xs else x[way[j - 1] - 1]\n val y1 = if (way[j - 1] == 0) ys else y[way[j - 1] - 1]\n val x2 = if (way[j] == 0) xs else x[way[j] - 1]\n val y2 = if (way[j] == 0) ys else y[way[j] - 1]\n answer += ((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1))\n }\n println(answer)\n println(way.joinToString(\" \"))\n}", "src_uid": "2ecbac20dc5f4060bc873553946281bc"} {"source_code": "import java.io.*\nimport java.lang.Math.*\n\nval stdout = System.out;\nval stdin = FastScanner(System.`in`);\n\nfun solve() {\n val n = nextInt()\n val s = next()\n var i = 0\n val ans = mutableListOf()\n while (i < n) {\n if (s[i] == 'W') {\n i++\n continue\n }\n var j = 0\n while (i < n && s[i] == 'B') {\n i++\n j++\n }\n ans.add(j)\n }\n println(ans.size)\n for (i in ans) print(\"$i \")\n}\n\ninline fun print(message: Any?) = stdout.print(message)\ninline fun print(message: Int) = stdout.print(message)\ninline fun print(message: Long) = stdout.print(message)\ninline fun print(message: Byte) = stdout.print(message)\ninline fun print(message: Short) = stdout.print(message)\ninline fun print(message: Char) = stdout.print(message)\ninline fun print(message: Boolean) = stdout.print(message)\ninline fun print(message: Float) = stdout.print(message)\ninline fun print(message: Double) = stdout.print(message)\ninline fun print(message: CharArray) = stdout.print(message)\ninline fun println(message: Any?) = stdout.println(message)\ninline fun println(message: Int) = stdout.println(message)\ninline fun println(message: Long) = stdout.println(message)\ninline fun println(message: Byte) = stdout.println(message)\ninline fun println(message: Short) = stdout.println(message)\ninline fun println(message: Char) = stdout.println(message)\ninline fun println(message: Boolean) = stdout.println(message)\ninline fun println(message: Float) = stdout.println(message)\ninline fun println(message: Double) = stdout.println(message)\ninline fun println(message: CharArray) = stdout.println(message)\ninline fun println() = stdout.println()\n\ninline fun nextInt() = stdin.nextInt()\ninline fun nextLong() = stdin.nextLong()\ninline fun nextChar() = stdin.nextChar()\ninline fun next() = stdin.next()\ninline fun nextLine() = stdin.nextLine()\ninline fun nextIntArray(n: Int) = IntArray(n, { nextInt() })\n\nclass FastScanner(ins: InputStream): Closeable {\n val BUFFER_SIZE = 65536;\n val br: BufferedReader\n var end = false\n\n var len: Int = 0\n val buffer = CharArray(BUFFER_SIZE)\n var it: Int = 0\n\n init {\n br = BufferedReader(InputStreamReader(ins), BUFFER_SIZE)\n }\n\n constructor(file: String): this(FileInputStream(file))\n\n inline fun isLineBreaker(c: Char) = c == '\\n'\n inline fun isDelimiter(c: Char) = c == ' ' || c == '\\n' || c == '\\r'\n\n inline fun ensureBuffer() {\n if (it == len) {\n it = 0\n len = br.read(buffer)\n if (len == -1) end = true\n }\n }\n\n inline fun moveNext() {\n while (!end) {\n ensureBuffer()\n if (!isDelimiter(buffer[it])) return\n while (it < len && isDelimiter(buffer[it])) it++;\n }\n }\n\n inline fun nextChar(): Char {\n moveNext()\n if (end) return (-1).toChar()\n return buffer[it++]\n }\n\n inline fun next(): String {\n moveNext()\n val sb = StringBuilder()\n while (!end) {\n val l = it\n while (++it < len && !isDelimiter(buffer[it]));\n sb.append(buffer, l, it - l)\n ensureBuffer()\n if (end || isDelimiter(buffer[it])) break;\n }\n return sb.toString()\n }\n\n inline fun nextInt(): Int {\n moveNext()\n var minus = true\n if (buffer[it] == '-') {\n it++\n minus = false\n }\n var result: Int = 0\n while (!end) {\n while (it < len && !isDelimiter(buffer[it])) {\n result *= 10\n result += (buffer[it] - '0').toInt()\n it++\n }\n ensureBuffer()\n if (end || isDelimiter(buffer[it])) break\n }\n return if (minus) result else -result\n }\n\n inline fun nextLong(): Long {\n moveNext()\n var minus = true\n if (buffer[it] == '-') {\n it++\n minus = false\n }\n var result: Long = 0\n while (!end) {\n while (it < len && !isDelimiter(buffer[it])) {\n result *= 10\n result += (buffer[it] - '0').toLong()\n it++\n }\n ensureBuffer()\n if (end || isDelimiter(buffer[it])) break\n }\n return if (minus) result else -result\n }\n\n inline fun nextLine(): String {\n moveNext()\n val sb = StringBuilder()\n while (!end) {\n val l = it\n while (++it < len && !isLineBreaker(buffer[it]));\n sb.append(buffer, l, it - l)\n ensureBuffer()\n if (end || isLineBreaker(buffer[it])) break;\n }\n return sb.toString()\n }\n\n override fun close() {\n br.close()\n }\n}\n\nfun main(args: Array) {\n solve()\n stdin.close()\n stdout.close();\n}", "src_uid": "e4b3a2707ba080b93a152f4e6e983973"} {"source_code": "fun Boolean.toInt() = if (this) 1 else 0\n\nfun main(args: Array) {\n val l=readLine()!!.split(\" \").map(String::toInt)\n val x=l[0]/(2*l[1])\n if (l[1]>l[0]) print(-1)\n else print(x*l[1]+l[1]*(l[0]!=x*l[1]*2).toInt())\n}", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f"} {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val numVisits = readInt()\n val rabbitToOwl = readInt()\n val rabbitToEeyore = readInt()\n val owlToEeyore = readInt()\n var sol = 0\n var house = 0\n val moves = arrayOf(\n intArrayOf(Int.MAX_VALUE, rabbitToOwl, rabbitToEeyore),\n intArrayOf(rabbitToOwl, Int.MAX_VALUE, owlToEeyore),\n intArrayOf(rabbitToEeyore, owlToEeyore, Int.MAX_VALUE)\n )\n\n for (times in 1 until numVisits)\n sol += moves[house].min()!!.also { house = moves[house].indexOf(it) }\n print(sol)\n}\n\n//enum class House { RABBIT, OWL, EEYORE }\n//\n//fun main() {\n// fun readInt() = readLine()!!.toInt()\n//\n// val numVisits = readInt()\n// val rabbitToOwl = readInt()\n// val rabbitToEeyore = readInt()\n// val owlToEeyore = readInt()\n// var sol = 0\n// var state = House.RABBIT\n//\n// repeat(numVisits - 1) {\n// when (state) {\n// House.RABBIT -> if (rabbitToOwl <= rabbitToEeyore) {\n// state = House.OWL\n// sol += rabbitToOwl\n// } else {\n// state = House.EEYORE\n// sol += rabbitToEeyore\n// }\n// House.OWL -> if (rabbitToOwl <= owlToEeyore) {\n// state = House.RABBIT\n// sol += rabbitToOwl\n// } else {\n// state = House.EEYORE\n// sol += owlToEeyore\n// }\n// House.EEYORE -> if (rabbitToEeyore <= owlToEeyore) {\n// state = House.RABBIT\n// sol += rabbitToEeyore\n// } else {\n// state = House.OWL\n// sol += owlToEeyore\n// }\n// }\n// }\n// print(sol)\n//}", "src_uid": "6058529f0144c853e9e17ed7c661fc50"} {"source_code": "import java.io.PrintWriter\nimport java.util.*\nimport kotlin.math.min\n\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\n\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not())\n _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\n\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\ninline fun output(block: PrintWriter.() -> Unit) {\n _writer.apply(block).flush()\n}\n\nfun main() = output {\n repeat(readInt()) {\n val n = readInt()\n var k = readLong()\n val arr = Array(n) { Pair(readLong(), it) }.sortedDescending()\n\n val d = Array(n) { 0L }\n\n for (i in 1 until n) {\n d[arr[i].second] += min(k, arr[i - 1].first + d[arr[i - 1].second] - arr[i].first - 1)\n k -= d[arr[i].second]\n }\n\n for (i in 0 until n) {\n d[i] += k / n\n }\n k %= n\n\n for (i in 0 until k.toInt()) {\n d[arr[i].second]++\n }\n\n d.forEach { print(\"$it \") }.also { println() }\n }\n}\n\ndata class Pair, S : Comparable>(\n val first: F,\n val second: S\n) : Comparable> {\n\n override fun compareTo(other: Pair) = when {\n first < other.first -> -1\n first > other.first -> 1\n second < other.second -> -1\n second > other.second -> 1\n else -> 0\n }\n}", "src_uid": "685ecfc7293b4e762863be2e3368e576"} {"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}", "src_uid": "f6a80c0f474cae1e201032e1df10e9f7"} {"source_code": "fun main() {\n //println((4 or 6)xor(4 or 5))\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val (n, x, y) = r.readLine()!!.split(\" \").map { it.toInt() }\n val n1 = r.readLine()!!.toLong()\n val n2 = r.readLine()!!.toLong()\n val n3 = n1 + n2\n val n4 = n1.toString().split(\"\").filter { it.isNotEmpty() }.filter { it != \"0\" }.joinToString(\"\").toLong()\n val n5 = n2.toString().split(\"\").filter { it.isNotEmpty() }.filter { it != \"0\" }.joinToString(\"\").toLong()\n val n6 = n3.toString().split(\"\").filter { it.isNotEmpty() }.filter { it != \"0\" }.joinToString(\"\").toLong()\n println(if (n4+n5==n6) \"YES\" else \"NO\")\n}", "src_uid": "ac6971f4feea0662d82da8e0862031ad"} {"source_code": "\nimport java.util.*\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n\n val s = sc.next()\n var z = false\n var o = false\n var c = 0\n for (i in s.length - 1 downTo 0) {\n if (s[i] == '0') {\n c++\n }\n if (s[i] == '1' && z) {\n o = true\n }\n if (c >= 6) {\n z = true\n }\n }\n if (z && o) {\n println(\"yes\")\n } else {\n println(\"no\")\n }\n}\n", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca"} {"source_code": "import kotlin.math.sqrt\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n\n val n = readInt()\n val length = sqrt(n.toFloat()).toInt()\n print(\n length + length + when {\n length * length == n -> 0\n length * (length + 1) >= n -> 1\n else -> 2\n }\n )\n}", "src_uid": "eb8212aec951f8f69b084446da73eaf7"} {"source_code": "\nfun main() {\n solve()\n}\n\nprivate fun solve() {\n val n = readLong()\n\n if (n == 1L) {\n println(1)\n return\n }\n var counter = 1L\n\n var i = 1L\n var ans = 0L\n while (i <= n) {\n// println(i)\n if (i + counter >= n) {\n ans = 1 + (n - i)\n// break\n }\n\n i += counter\n counter++\n }\n println(ans)\n}\n\nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single int\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // li\nprivate fun readLongs() = readStrings().map { it.toLong() } // li", "src_uid": "1db5631847085815461c617854b08ee5"} {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val m = readLine()!!.toInt()\n var t = 0\n var maks = 0\n for (i in 1..n)\n {\n val a = readLine()!!.toInt()\n t+=a\n if (a > maks)\n maks = a\n }\n var mini = (t+m)/n\n if (mini * n < t+m)\n mini++\n if (maks > mini) \n mini = maks\n println(\"$mini ${maks+m}\")\n}", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d"} {"source_code": "import kotlin.math.sqrt\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!.toInt()\n val prime = mutableSetOf()\n fun isprime(i: Int) = (2..sqrt(i.toDouble()).toInt()).none { i % it == 0 }\n for (i in 2..3000){\n if (isprime(i)){\n prime += i\n }\n }\n fun fac(i:Int):List{\n val ans = mutableListOf()\n for (j in 2..sqrt(i.toDouble()).toInt()){\n if (i%j==0){\n ans+=j\n if (i/j>j){\n ans+=i/j\n }\n }\n }\n return ans\n }\n var ans = 0\n loop@for (j in 1..n){\n val divisor = fac(j)\n //println(\"$j ${divisor}\")\n var cnt = 0\n for (div in divisor){\n if (div in prime){\n cnt++\n if (cnt>2){\n continue@loop\n }\n }\n }\n if (cnt==2) {\n ans++\n //println(j)\n }\n }\n println(ans)\n}", "src_uid": "356666366625bc5358bc8b97c8d67bd5"} {"source_code": "import java.util.Scanner\n\nfun main(args : Array) {\n var list1: MutableList = mutableListOf()\n var list2: MutableList = mutableListOf()\n for (i in 0..7) {\n list1.add(readLine()!!)\n }\n\n var row = 0\n for (i in 0..7) {\n var col = 0\n for (char in list1[i]) {\n if (char == 'B') {\n col++\n }\n if (col == 8) {\n row++\n }\n }\n list2.add(col)\n }\n list2.sort()\n\n var c = row + list2[0]\n if(c==16){ println(8) }\n else { println(c)}\n\n}\n", "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0"} {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //val l = r.readLine()!!.split(\" \").map { it.toInt() }\n val str = r.readLine()!!\n var ans = 0\n var char = 'a'\n str.forEach {\n val min = minOf(it, char)\n val max = maxOf(it, char)\n ans += minOf(max-min, min+26-max)\n char = it\n }\n println(ans)\n}", "src_uid": "ecc890b3bdb9456441a2a265c60722dd"} {"source_code": "fun main() {\n val q = readInt()\n\n readMultiLineIntList(q) {\n val num = it.toString()[0].toString().toInt()\n orderln(when(it.toString().length) {\n 1 -> \"${((num - 1) * 10 + 1)}\"\n 2 -> \"${((num - 1) * 10 + 3)}\"\n 3 -> \"${((num - 1) * 10 + 6)}\"\n 4 -> \"${(num * 10)}\"\n else -> \"\"\n })\n }\n\n drop()\n}\n\n// region Technolib\n/*\n Author: Timofey Chicherin (TimDev, TwMicro)\n Collaborators: [no]\n License: Apache License 2.0\n GitHub: https://github.com/twmicro/technolib/\n*/\n\nvar toPrint = \"\"\n/*\n readLines -\n Reads a count of lines\n*/\n\n// Simple variant\nfun readLines(count: Int): MutableList {\n val lines = mutableListOf()\n for (i in 0 until count) lines.add(readLine()!!)\n return lines\n}\n\n// Inline variant, works like forEach\ninline fun readLines(count: Int, action: (String) -> Unit): MutableList {\n val lines = mutableListOf()\n for (i in 0 until count) {\n lines.add(readLine()!!)\n action.invoke(lines.last())\n }\n return lines\n}\n\n\n/*\n readMultiLineIntList -\n Reads a count of lines and converts it to MutableList\n*/\n\n// Simple variant\nfun readMultiLineIntList(count: Int): MutableList {\n val lines = mutableListOf()\n for (i in 0 until count) lines.add(readLine()!!.toInt())\n return lines\n}\n\n// Inline variant, works like forEach\ninline fun readMultiLineIntList(count: Int, action: (Int) -> Unit): MutableList {\n val lines = mutableListOf()\n for (i in 0 until count) {\n lines.add(readLine()!!.toInt())\n action.invoke(lines.last())\n }\n return lines\n}\n\n\n/*\n readIntList -\n Reads single line of integers\n*/\n\n// Simple variant\nfun readIntList(seperator: String = \" \"): MutableList = readLine()!!.split(seperator).toIntList()\n\n// Inline variant, works like forEach\nfun readIntList(seperator: String = \" \", action: (Int) -> Unit) = readIntList(seperator).forEach(action)\n\n/*\n List.toIntList -\n Converts string list to int list\n*/\n\nfun List.toIntList(): MutableList {\n val result = mutableListOf()\n forEach {\n result.add(it.toInt())\n }\n return result\n}\n\n/*\n order(ln) -\n Adds text to print stack. Don't forget to use drop() or dropln() in the end of your program!\n (ln) - adds \\n to the end of text\n*/\n\nfun order(text: String) {\n toPrint += text\n}\n\nfun orderln(text: String) {\n toPrint += text + \"\\n\"\n}\n\n/*\n drop(ln) -\n Prints all the text from the print stack\n*/\nfun drop() = print(toPrint)\nfun dropln() = println(toPrint)\n\n/*\n readInt -\n Shortcut for readLine()!!.toInt()\n*/\nfun readInt(): Int = readLine()!!.toInt()\n// endregion", "src_uid": "289a55128be89bb86a002d218d31b57f"} {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val n = readLine()!!.toInt()\n var s = readLine()!!.toMutableList()\n var count = 0\n while (true) {\n var index = -1\n val l = s.count()\n for (i in 0 until l) {\n if ((i > 0 && s[i] == s[i - 1] + 1) || (i < l - 1 && s[i] == s[i + 1] + 1)) {\n if ((index == -1) || (s[index] < s[i])) {\n index = i\n }\n }\n }\n if (index == -1) {\n break\n }\n s.removeAt(index)\n count++\n }\n println(count)\n}", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38"} {"source_code": "const val MOD = 1_000_000_007\n\nfun main(args: Array) {\n var (n, k) = readLine()!!.split(' ').map(String::toLong)\n\n var result = 1\n var d = 2L\n while (d * d <= n) {\n var deg = 0\n while (n % d == 0L) {\n n /= d\n ++deg\n }\n if (deg > 0) {\n result = mult(result, f(d, deg, k.toInt()))\n }\n ++d\n }\n if (n > 1) {\n result = mult(result, f(n, 1, k.toInt()))\n }\n println(result)\n}\n\nfun f(_p: Long, deg: Int, k: Int): Int {\n val dp = Array(k + 1) { IntArray(deg + 1) }\n dp[0][deg] = 1\n val inverses = IntArray(deg + 2) { inverse(it) }\n for (step in 1..k) {\n for (d in 0..deg) {\n for (nd in d..deg) {\n dp[step][d] = add(dp[step][d], mult(dp[step - 1][nd], inverses[nd + 1]))\n }\n }\n }\n var result = 0\n var pi = 1\n val p = (_p % MOD).toInt()\n for (i in 0..deg) {\n result = add(result, mult(dp[k][i], pi))\n pi = mult(pi, p)\n }\n return result\n}\n\nfun inverse(n: Int) = binPow(n, MOD - 2)\n\nfun binPow(x: Int, n: Int): Int {\n return when {\n n == 0 -> 1\n n % 2 == 1 -> mult(x, binPow(x, n - 1))\n else -> {\n val half = binPow(x, n / 2)\n mult(half, half)\n }\n }\n}\n\nfun add(a: Int, b: Int) = (a + b) % MOD\n\nfun mult(a: Int, b: Int) = ((a.toLong() * b) % MOD).toInt()", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2"} {"source_code": "import java.io.*\r\nimport java.util.*\r\nimport kotlin.math.absoluteValue\r\nimport kotlin.random.Random\r\nimport kotlin.system.measureTimeMillis\r\n\r\n// @formatter:off\r\n\r\nval local = System.getProperty(\"ONLINE_JUDGE\") == null\r\n//val local = false\r\n\r\nval INPUT: InputStream = if (local) FileInputStream(\"input.txt\") else System.`in`\r\n//val INPUT: InputStream = System.`in`\r\n\r\n//val OUTPUT: PrintStream = if (local) PrintStream(\"output.txt\") else System.out\r\nval OUTPUT: PrintStream = System.out\r\n\r\nval _reader = INPUT.bufferedReader()\r\nvar _tokenizer = StringTokenizer(\"\")\r\n\r\nfun readLine(): String? = _reader.readLine()\r\nfun readLn() = _reader.readLine()!!\r\nfun read(): String {\r\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\r\n return _tokenizer.nextToken()\r\n}\r\n\r\nfun readInt() = read().toInt()\r\nfun readDouble() = read().toDouble()\r\nfun readLong() = read().toLong()\r\nfun readStrings(n: Int) = List(n) { read() }\r\nfun readLines(n: Int) = List(n) { readLn() }\r\nfun readInts(n: Int) = List(n) { read().toInt() }\r\nfun readStrings() = readLn().split(\" \")\r\nfun readInts() = readStrings().map { it.toInt() }\r\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\r\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\r\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\r\nfun readLongs(n: Int) = List(n) { read().toLong() }\r\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\r\nfun PrintWriter.yesNo(p: Boolean) {\r\n if (p) this.println(\"YES\") else this.println(\"NO\")\r\n}\r\n\r\n@JvmField\r\nval _writer = PrintWriter(OUTPUT, true)\r\n// @formatter:on\r\n\r\nfun solve(a: Long, b: Long): Boolean {\r\n val set = mutableSetOf()\r\n set.add(a.toString(2))\r\n val q: Queue = LinkedList()\r\n q.add(a.toString(2))\r\n\r\n while (!q.isEmpty()) {\r\n val s = q.poll()\r\n var t: String\r\n\r\n t = s + \"0\"\r\n t = t.reversed()\r\n while (t.length > 1 && t[0] == '0') {\r\n t = t.substring(1)\r\n }\r\n\r\n if (t.length < 100) {\r\n if (set.contains(t).not()) {\r\n set.add(t)\r\n q.add(t)\r\n }\r\n }\r\n\r\n t = s + \"1\"\r\n t = t.reversed()\r\n if (t.length < 100) {\r\n if (set.contains(t).not()) {\r\n set.add(t)\r\n q.add(t)\r\n }\r\n }\r\n }\r\n return set.contains(b.toString(2))\r\n}\r\n\r\nfun PrintWriter.solve() {\r\n// val tcs = readInt()\r\n val tcs = 1\r\n for (tc in 1..tcs) {\r\n val a = readLong()\r\n val b = readLong()\r\n val res = solve(a, b)\r\n yesNo(res)\r\n }\r\n}\r\n\r\nfun main() {\r\n\r\n val elapsedMs = measureTimeMillis {\r\n _writer.solve()\r\n _writer.flush()\r\n }\r\n if (local) {\r\n println(\"\\n\\nElapsed $elapsedMs ms\")\r\n }\r\n\r\n}", "src_uid": "9f39a3c160087beb0efab2e3cb510e89"} {"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}", "src_uid": "758d342c1badde6d0b4db81285be780c"} {"source_code": "fun model(n: Long, k: Long): Long {\n var rem = n\n var ans = 0L\n\n while (rem > 0) {\n val vasyaCount = Math.min(rem, k)\n ans += vasyaCount\n rem -= vasyaCount\n rem -= rem / 10\n }\n\n return ans\n}\n\nfun check(vasyaCount: Long, n: Long) = 2 * vasyaCount >= n\n\nfun main(args: Array) {\n val n = readLine()!!.toLong()\n\n var a = 1L\n var b = n\n\n while (a <= b) {\n val c = (a + b) / 2\n\n if (check(vasyaCount = model(n = n, k = c), n = n)) {\n b = c - 1\n } else {\n a = c + 1\n }\n }\n\n if (check(vasyaCount = model(n = n, k = a), n = n)) {\n println(a)\n } else {\n println(a + 1)\n }\n}\n", "src_uid": "db1a50da538fa82038f8db6104d2ab93"} {"source_code": "import java.math.BigInteger\n\n\nfun main() {\n var rsult = intArrayOf(8, 4, 2, 6)\n var y = readLine()!!.toInt()\n print(if (y == 0) 1 else rsult[(y - 1) % 4])\n\n}\n", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f"} {"source_code": "fun main(arg: Array){\n\tval n = readLine()!!.toLong()\n\tval k = readLine()!!.toLong()\n\tval A = readLine()!!.toLong()\n\tval B = readLine()!!.toLong()\n\tvar x = n\n\tvar cost: Long = 0\n\twhile(x > 1){\n\t\t//println(\"Cost: $cost. X: $x. Remainder: ${x.rem(k)}\")\n\t\tif(k == 1L){\n\t\t\tcost = A*(x-1)\n\t\t\tx = 1\n\t\t}else if(x.rem(k) != 0L){\n\t\t//\tprintln(\"Substract for ${x.rem(k) * A}\")\n\t\t\tcost += if(x>k) x.rem(k)*A else A*(x-1)\n\t\t\tx -= if(x>k) x.rem(k) else x-1\n\t\t}else{\n\t\t\tif (B < (A*(x-x/k))){\n\t\t//\t\tprintln(\"Divide\")\n\t\t\t\tcost += B\n\t\t\t\tx = x/k\n\t\t\t}else{\n\t\t//\t\tprintln(\"Substract\")\n\t\t\t\tcost += A*(x-x/k)\n\t\t\t\tx = x/k\n\t\t\t}\n\t\t}\n\t}\n\tprintln(cost)\n}\n", "src_uid": "f838fae7c98bf51cfa0b9bd158650b10"} {"source_code": "import java.util.*\nfun main(){\n val s=Scanner(System.`in`)\n var r=s.next()\n var n=r.length\n var x:Int = -1\n var answer:String=\"\"\n for( i in 0..n-1){\n if(r[i]=='p'){\n answer += r[i]\n x=i\n break\n }\n else\n answer += r[i]\n }\n x++\n answer += \"://\"\n for (i in x..n-1){\n if(r[i]=='r' && r[i+1]=='u' && i!=x){\n answer+='.'\n answer+=\"ru\"\n x=i+1\n break\n }\n else\n answer+=r[i]\n }\n\n if(x!=n-1){\n x++\n answer+='/'\n for(i in x..n-1){\n answer+=r[i]\n }\n }\n print(answer)\n}\n", "src_uid": "4c999b7854a8a08960b6501a90b3bba3"} {"source_code": "fun main() {\n var r1 = readLine()!!.split(' ').map { it.toInt() }\n var r2 = readLine()!!.split(' ').map { it.toInt() }\n var r3 = readLine()!!.split(' ').map { it.toInt() }\n\n var a1 = Array(3, { 1 })\n var a2 = Array(3, { 1 })\n var a3 = Array(3, { 1 })\n\n if (r1[0] % 2 != 0 && r1[0] != 0) {\n a1[0] = 0\n a1[1] = 0\n a2[0] = 0\n }\n\n if (r1[1] % 2 != 0 && r1[1] != 0) {\n a1[0] = if (a1[0] == 0) 1 else 0\n a1[1] = if (a1[1] == 0) 1 else 0\n a1[2] = if (a1[2] == 0) 1 else 0\n a2[1] = if (a2[1] == 0) 1 else 0\n }\n\n if (r1[2] % 2 != 0 && r1[2] != 0) {\n a1[2] = if (a1[2] == 0) 1 else 0\n a2[2] = if (a2[2] == 0) 1 else 0\n a1[1] = if (a1[1] == 0) 1 else 0\n }\n\n ////////////////////\n if (r2[0] % 2 != 0 && r2[0] != 0) {\n a1[0] = if (a1[0] == 0) 1 else 0\n a2[0] = if (a2[0] == 0) 1 else 0\n a2[1] = if (a2[1] == 0) 1 else 0\n a3[0] = if (a3[0] == 0) 1 else 0\n }\n\n if (r2[1] % 2 != 0 && r2[1] != 0) {\n a3[1] = if (a3[1] == 0) 1 else 0//\n a1[1] = if (a1[1] == 0) 1 else 0//\n a2[2] = if (a2[2] == 0) 1 else 0//\n a2[0] = if (a2[0] == 0) 1 else 0//\n a2[1] = if (a2[1] == 0) 1 else 0//\n }\n\n if (r2[2] % 2 != 0 && r2[2] != 0) {\n a1[2] = if (a1[2] == 0) 1 else 0//\n a3[2] = if (a3[2] == 0) 1 else 0//\n a2[1] = if (a2[1] == 0) 1 else 0//\n a2[2] = if (a2[2] == 0) 1 else 0//\n }\n\n /////////////////////////////\n\n\n if (r3[0] % 2 != 0 && r3[0] != 0) {\n a2[0] = if (a2[0] == 0) 1 else 0\n a3[0] = if (a3[0] == 0) 1 else 0\n a3[1] = if (a3[1] == 0) 1 else 0\n }\n\n if (r3[1] % 2 != 0 && r3[1] != 0) {\n a3[0] = if (a3[0] == 0) 1 else 0//\n a3[2] = if (a3[2] == 0) 1 else 0//\n a3[1] = if (a3[1] == 0) 1 else 0//\n a2[1] = if (a2[1] == 0) 1 else 0//\n }\n\n if (r3[2] % 2 != 0 && r3[2] != 0) {\n a2[2] = if (a2[2] == 0) 1 else 0//\n a3[2] = if (a3[2] == 0) 1 else 0//\n a3[1] = if (a3[1] == 0) 1 else 0//\n }\n\n for (i in a1) {\n print(i)\n }\n println()\n for (i in a2) {\n print(i)\n }\n println()\n for (i in a3) {\n print(i)\n }\n}", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6"} {"source_code": "import java.util.*\n\nfun main(args: Array ) {\n val n = 10\n val sc = Scanner( System.`in` )\n val t = Array( n, { sc.nextLine().toCharArray() } )\n var found = false\n loop@for ( i in 0 until n ) {\n for ( j in 0 until n ) {\n for ( d in DX.indices ) {\n if ( find( i, j, t, DX[d], DY[d] ) ) {\n found = true\n break@loop\n }\n }\n }\n }\n println( if ( found ) \"YES\" else \"NO\" )\n}\n\nval DX = arrayOf( 0, 1, 1, 1 )\nval DY = arrayOf( 1, 0, 1, -1 )\n\nfun find( x0: Int, y0: Int, t: Array, dx: Int, dy: Int ): Boolean {\n var x = x0\n var y = y0\n var xN = 0\n var dotN = 0\n for ( i in 0 until 5 ) {\n if ( x < 0 || x >= t.size || y < 0 || y >= t[x].size ) return false\n if ( t[x][y] == 'X' ) {\n xN ++\n } else if ( t[x][y] == '.' ) {\n dotN ++\n } else {\n return false\n }\n x += dx\n y += dy\n }\n return xN == 4\n}\n", "src_uid": "d5541028a2753c758322c440bdbf9ec6"} {"source_code": "import kotlin.math.min\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (_, whiteSuitCost, blackSuitCost) = readInts()\n val colors = readInts()\n var sol = 0\n var left = -1\n var right = colors.size\n while (++left < --right)\n sol += when {\n colors[left] != 2 && colors[right] != 2 && colors[left] != colors[right] -> return print(-1)\n colors[left] != 2 && colors[right] != 2 -> 0\n colors[left] == 2 && colors[right] == 2 -> 2 * min(whiteSuitCost, blackSuitCost)\n colors[left] == 0 || colors[right] == 0 -> whiteSuitCost\n else -> blackSuitCost\n }\n if (left == right && colors[left] == 2) sol += min(whiteSuitCost, blackSuitCost)\n print(sol)\n}", "src_uid": "af07223819aeb5bd6ded4340c472b2b6"} {"source_code": "fun main(args: Array) {\n var n = readLine()\n var l = readLine()!!.split(\" \").count { it == \"0\" }\n println(if (l == n!!.toInt()) \"EASY\" else \"HARD\")\n}\n", "src_uid": "060406cd57739d929f54b4518a7ba83e"} {"source_code": "import java.util.*\nimport kotlin.collections.HashMap\n\nfun main(args : Array) {\n val input = Scanner(System.`in`)\n var city = HashMap()\n\n var j=0\n val n = input.nextInt()\n val u = input.nextInt()\n var sum = u\n if (n < u){\n println(n -1)\n } else {\n for (i in n downTo 1){\n city.put(i, j)\n if (j < u){\n j++\n } else {\n sum += i*1\n }\n }\n println(sum-1)\n }\n\n}", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7"} {"source_code": "import java.io.*\nimport java.lang.Math.*\nimport java.math.BigInteger\nimport java.util.*\nimport kotlin.collections.ArrayList\n\ntypealias IndexPair = Pair\ntypealias IntIndexPair = IndexPair\ntypealias IntIntPair = Pair\n\ntypealias IntMatrix = Array\ntypealias LongMatrix = Array\n\ntypealias ListArray = Array>\n\ntypealias Graph = IntMatrix\n\ntypealias Edge = Pair\ntypealias EdgeArray = Array\ntypealias WeightedGraph = Array\n\ntypealias TotalEdge = Triple\ntypealias TotalEdgeArray = Array\n\nfun init() { }\n\nconst val MODULO = 1000 * 1000 * 1000 + 7\n\nfun solve() {\n val segments = arrayOf(6, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n\n val (start, end) = readInts()\n val result = (start..end).sumBy {number -> \n number.toString().sumBy { segments[it - '0'] }\n }\n \n out.println(result)\n}\n\nfun stress() {\n val rnd = Random(1234)\n\n for (it in 0 until 100) {\n val expected = brute()\n val actual = fast()\n\n if (expected != actual) {\n System.err.println(\"Gotcha!\")\n System.err.println(\"$expected $actual\")\n\n break\n }\n }\n}\n\n\nfun fast() {\n\n}\n\nfun brute() {\n\n}\n\nfun Long.mod() : Long {\n var result = this % MODULO\n if (result < 0) result += MODULO\n return result\n}\n\ninfix fun Long.add(other : Long) = (this + other).mod()\ninfix fun Long.sub(other : Long) = this add -other.mod()\ninfix fun Long.mult(other : Long) = (this.mod() * other.mod()).mod()\n\nfun Long.even() = (this and 1L) == 0L\nfun Long.odd() = !even()\n\nfun Int.even() = (this and 1) == 0\nfun Int.odd() = !even()\n\ninfix fun Long.binpow(power : Long) : Long {\n if (power == 0L) return 1L\n\n val half = binpow(power shl 1)\n\n var result = half mult half\n if (power.odd()) {\n result = result mult this\n }\n\n return result\n}\n\nval stepsXY = arrayOf(\n arrayOf(0, -1),\n arrayOf(0, 1),\n arrayOf(-1, 0),\n arrayOf(1, 0)\n)\n\n\n\nclass IndexedWeightedGraph(private val n : Int, private val edges: TotalEdgeArray) {\n\n private val graph : Graph\n\n private fun buildGraphForEdges(\n edgeFilter : (index : Int, edge : TotalEdge) -> Boolean = { _, _ -> true }\n ) : Graph {\n val builder = GraphBuilder()\n edges\n .forEachIndexed { index, edge ->\n if (edgeFilter(index, edge)) {\n val (first, second, _ ) = edge\n\n builder.addDirectedEdge(first, index)\n builder.addDirectedEdge(second, index)\n }\n }\n\n return builder.build(n)\n }\n\n init {\n graph = buildGraphForEdges()\n }\n\n var root : Int = -1\n lateinit var inTree : BooleanArray\n lateinit var tree : Graph\n\n fun kruskalTree(root : Int) : Long {\n this.root = root\n\n inTree = BooleanArray(edges.size) { false }\n\n val dsu = DSU(n)\n\n edges\n .mapIndexed { index, (_, _, w) -> index to w }\n .sortedBy { it.second }\n .forEach {\n val edge = edges[it.first]\n inTree[it.first] = dsu.union(edge.first, edge.second)\n }\n\n tree = buildGraphForEdges { index, _ -> inTree[index] }\n\n return edges\n .mapIndexed { index, (_, _, w) -> if (inTree[index]) w.toLong() else 0L }\n .sum()\n }\n\n private fun to(from : Int, index : Int) : Int {\n val edge = edges[index]\n return if (from == edge.first) edge.second else edge.first\n }\n\n fun buildLca() {\n calculateTimes()\n calculateParents()\n calculatePathInfo()\n }\n\n lateinit var timesIn : IntArray\n lateinit var timesOut : IntArray\n private var time = -1\n\n private fun calculateTimes() {\n timesIn = IntArray(n) { -1 }\n timesOut = IntArray(n) { -1 }\n this.time = 0\n\n timeDfs(root)\n }\n\n private fun timeDfs(from : Int, parent : Int = -1) {\n timesIn[from] = time++\n\n for (index in tree[from]) {\n val to = to(from, index)\n if (to == parent) continue\n\n timeDfs(to, from)\n }\n\n timesOut[from] = time++\n }\n\n lateinit var parents : Array\n private val maxBit = 19\n\n private fun calculateParents() {\n parents = Array(maxBit) { IntArray(n) { -1 } }\n\n parentDfs(root, root)\n\n for (bit in 0 until maxBit - 1) {\n for (v in 0 until n) {\n val parent = parents[bit][v]\n parents[bit + 1][v] = parents[bit][parent]\n }\n }\n }\n\n private fun parentDfs(from : Int, parent : Int = -1) {\n parents[0][from] = parent\n\n for (index in tree[from]) {\n val to = to(from, index)\n if (to == parent) continue\n\n parentDfs(to, from)\n }\n }\n\n lateinit var maxEdges : Array\n\n private fun calculatePathInfo() {\n maxEdges = Array(maxBit) { IntArray(n) { -1 } }\n\n for (v in 0 until n){\n for (index in tree[v]) {\n val to = to(v, index)\n if (to == parents[0][v]) continue\n\n maxEdges[0][to] = edges[index].third\n }\n }\n\n for (bit in 0 until maxBit - 1) {\n for (v in 0 until n) {\n val parent = parents[bit][v]\n maxEdges[bit + 1][v] = max(\n maxEdges[bit][v],\n maxEdges[bit][parent]\n )\n }\n }\n }\n\n fun getOnPath(a : Int, b : Int) : Int {\n var answer = Int.MIN_VALUE\n\n answer = max(answer, getOnLcaPath(a, b))\n answer = max(answer, getOnLcaPath(b, a))\n\n return answer\n }\n\n private fun getOnLcaPath(start : Int, other : Int) : Int {\n var answer = Int.MIN_VALUE\n\n if (timesIn[start] <= timesIn[other] && timesOut[other] <= timesOut[start]) {\n return answer\n }\n\n var v = start\n for (bit in maxBit - 1 downTo 0) {\n val parent = parents[bit][v]\n if (timesIn[parent] > timesIn[other] || timesOut[other] > timesOut[parent]) {\n answer = max(answer, maxEdges[bit][v])\n v = parent\n }\n }\n\n answer = max(answer, maxEdges[0][v])\n\n return answer\n }\n}\n\nfun yesNo(yes : Boolean) {\n out.println(if (yes) \"YES\" else \"NO\")\n}\n\nfun run() {\n init()\n solve()\n out.close()\n}\n\nfun main(args: Array) {\n run()\n}\n\nval ONLINE_JUDGE = !File(\"input.txt\").exists()\n\nval input = BufferedReader(\n if (ONLINE_JUDGE) InputStreamReader(System.`in`) else FileReader(\"input.txt\")\n)\nval out =\n if (ONLINE_JUDGE) PrintWriter(System.out)\n else PrintWriter(\"output.txt\")\n\nfun readStrings(separator: String = \" \", emptyWords: Boolean = false) : Array {\n val line = input.readLine()\n\n val list = ArrayList()\n var builder = StringBuilder()\n\n for (i in 0..line.length) {\n if (i == line.length || separator.contains(line[i])) {\n if (emptyWords || builder.isNotEmpty()) {\n list.add(builder.toString())\n builder = StringBuilder()\n }\n } else {\n builder.append(line[i])\n }\n }\n\n return list.toTypedArray()\n}\n\nfun readString(separator: String = \" \") =\n readStrings(separator).first()\n\nfun readInts(separator: String = \" \") =\n readStrings(separator).map(String::toInt).toIntArray()\n\nfun readDecreasedInts(separator : String = \" \") =\n readInts(separator).map { it - 1 }.toIntArray()\n\nfun readSortedInts(separator: String = \" \") : IntArray {\n val a = readInts(separator)\n\n val aInteger = Array(a.size) { a[it] }\n Arrays.sort(aInteger)\n\n return aInteger.toIntArray()\n}\n\nfun readInt(separator: String = \" \") =\n readInts(separator).first()\n\nfun readLongs(separator: String = \" \") =\n readStrings(separator).map(String::toLong).toLongArray()\n\nfun readLong(separator: String = \" \") =\n readLongs(separator).first()\n\nfun readDoubles(separator: String = \" \") =\n readStrings(separator).map(String::toDouble).toDoubleArray()\n\nfun readDouble(separator: String = \" \") =\n readDoubles(separator).first()\n\nfun readBigIntegers(separator: String = \" \") =\n readStrings(separator).map { BigInteger(it) }.toTypedArray()\n\nfun readBigInteger(separator: String = \" \") =\n readBigIntegers(separator).first()\n\nfun readTree(n : Int, indexing : Int = 1) =\n readGraph(n, n - 1, true, indexing)\n\nfun readGraph(n: Int, m : Int,\n undirected : Boolean = true,\n indexing : Int = 1) : Graph {\n val builder = GraphBuilder()\n\n for (i in 1..m) {\n var (from, to) = readInts()\n\n from -= indexing\n to -= indexing\n\n if (undirected) builder.addEdge(from, to)\n else builder.addDirectedEdge(from, to)\n }\n\n return builder.build(n)\n}\n\nfun readWeightedGraph(n : Int, m : Int,\n undirected : Boolean = true,\n indexing : Int = 1) : WeightedGraph {\n val builder = GraphBuilder()\n\n for (i in 1..m) {\n var (from, to, weight) = readInts()\n\n from -= indexing\n to -= indexing\n\n if (undirected) builder.addEdge(from, to, weight)\n else builder.addDirectedEdge(from, to, weight)\n }\n\n return builder.buildWeighted(n)\n}\n\nfun readTotalEdges(m : Int, indexing : Int = 1) =\n TotalEdgeArray(m) {\n var (from, to, w) = readInts()\n\n from -= indexing\n to -= indexing\n\n Triple(from, to, w)\n }\n\nclass GraphBuilder {\n\n private val froms = ArrayList()\n private val tos = ArrayList()\n private val weights = ArrayList()\n\n fun addEdge(from : Int, to : Int, weight : Int = 1) {\n addDirectedEdge(from, to, weight)\n addDirectedEdge(to, from, weight)\n }\n\n fun addDirectedEdge(from : Int, to : Int, weight : Int = 1) {\n froms.add(from)\n tos.add(to)\n weights.add(weight)\n }\n\n private fun calculateFromSizes(n : Int) : IntArray {\n val sizes = IntArray(n) { 0 }\n froms.forEach { ++sizes[it] }\n return sizes\n }\n\n fun build(n : Int) : Graph {\n val sizes = calculateFromSizes(n)\n\n val graph = Graph(n) { IntArray(sizes[it]) { 0 } }\n\n for (i in 0 until n) {\n sizes[i] = 0\n }\n\n for (i in 0 until froms.size) {\n val from = froms[i]\n val to = tos[i]\n\n graph[from][sizes[from]++] = to\n }\n\n return graph\n }\n\n fun buildWeighted(n : Int) : WeightedGraph {\n val sizes = calculateFromSizes(n)\n\n val graph = WeightedGraph(n) { EdgeArray(sizes[it]) { -1 to 0 } }\n\n for (i in 0 until n) {\n sizes[i] = 0\n }\n\n for (i in 0 until froms.size) {\n val from = froms[i]\n val to = tos[i]\n val weight = weights[i]\n\n graph[from][sizes[from]++] = to to weight\n }\n\n return graph\n }\n}\n\nfun gcd(a : Int, b : Int) : Int =\n if (a == 0) b else gcd(b % a, a)\n\nfun gcd(a : Long, b : Long) : Long =\n if (a == 0L) b else gcd(b % a, a)\n\nfun getDivisors(x : Int) : MutableList {\n val divisors = ArrayList()\n\n var d = 1\n while (d * d <= x) {\n if (x % d == 0) {\n if (d != 1) divisors.add(d)\n if (x != d) divisors.add(x / d)\n }\n\n ++d\n }\n\n return divisors\n}\n\nfun getPrimeDivisors(xx : Int) : MutableList {\n val divisors = ArrayList()\n\n var d = 2\n var x = xx\n while (d * d <= x) {\n if (x % d == 0) {\n divisors.add(d)\n while (x % d == 0) {\n x /= d\n }\n }\n\n ++d\n }\n\n if (x > 1) divisors.add(x)\n\n return divisors\n}\n\nfun checkIndex(index : Int, size : Int) =\n 0 <= index && index < size\n\nfun checkCell(x : Int, n : Int, y : Int, m : Int) =\n checkIndex(x, n) && checkIndex(y, m)\n\nfun toChar(index : Int, start : Char) =\n (index + start.toInt()).toChar()\n\nclass DSU {\n\n var sizes : IntArray\n var ranks : IntArray\n var parents : IntArray\n\n constructor(n : Int)\n : this(\n IntArray(n) { 1 }\n )\n\n constructor(sizes : IntArray) {\n val size = sizes.size\n this.sizes = sizes\n this.ranks = IntArray(size) { 1 }\n this.parents = IntArray(size) { it }\n }\n\n operator fun get(v : Int) : Int {\n val parent = parents[v]\n if (parent == v) return v\n parents[v] = get(parent)\n return parents[v]\n }\n\n fun union(aUniting : Int, bUniting : Int) : Boolean {\n var a = get(aUniting)\n var b = get(bUniting)\n\n if (a == b) return false\n\n if (ranks[a] < ranks[b]) {\n val tmp = a\n a = b\n b = tmp\n }\n\n parents[b] = a\n sizes[a] += sizes[b]\n if (ranks[a] == ranks[b]) ++ranks[a]\n\n return true\n }\n\n fun size(v : Int) : Int = sizes[get(v)]\n}\n\nclass FenwickTree(n : Int) {\n\n val size = n + 1\n val tree = LongArray(size) { 0L }\n\n fun update(index : Int, delta : Int) {\n var x = index + 1\n while (x < size) {\n tree[x] = tree[x] + delta\n x += x and -x\n }\n }\n\n operator fun get(start : Int, end : Int) =\n get(end) - get(start - 1)\n\n operator fun get(index : Int) : Long {\n var result : Long = 0\n\n var x = index + 1\n while (x > 0) {\n result += tree[x]\n x -= x and -x\n }\n\n return result\n }\n}\n\n", "src_uid": "1193de6f80a9feee8522a404d16425b9"} {"source_code": "import kotlin.math.*\nimport java.util.*\n\n//var gr = MutableList>(2, MutableList(1, (1)));\n\nfun solve(fr : fastReader) {\n /*\n Кеки и приколы:\n Pair - Пара\n Pair(a, b) - создать пару\n будет ругаться и не выделять - забей\n \n в функцию (почему то ?) передается объект а не копия\n не изменяй ничего в функции!\n \n сортировать : arr.sort()\n если там пары/структуры и тд то \n arr.sortWith(compareBy({it.first}, {it.second})) или arr.sortWith(compareBy({it[0]}, {it[1]})) чо та такое\n\n\tъуъ до слез \n\tвектор это MutableList \n\tMutableList(n, {0}) \n\tpush_back = add\n\tpop_back = removeAt(lastIndex)\n\t\n\n\tо еще можно писать функции внутри функции чтобы не париться с глобальностью переменных )))\n */\n\n \tvar a = fr.getInt();\n \tvar b = fr.getInt();\n \tvar c = fr.getInt();\n\n \tfun gcd(a : Int, b : Int) : Int {\n \t\tif (b == 0) {\n \t\t\treturn a;\n \t\t} else {\n \t\t\treturn gcd(b, a % b);\n \t\t}\n \t}\n\n \tvar g = gcd(a, b);\n \ta *= b;\n \ta /= g;\n \tprint (c / a);\n\n}\n \nfun main(args: Array) {\n\tvar fr = fastReader();\n var T = 1\n //T = fr.getInt();\n for (i in 1..T) {\n \tsolve(fr)\n }\n print('\\n');\n}\n\nclass fastReader {\n\tvar buffer : String = \"\";\n\tvar pos : Int = 0;\n\tvar bufferSize : Int = 0;\n\n\tfun readBuffer() {\n\t\tbuffer = readLine()!!;\n\t\tbuffer += ' ';\n\t\tpos = 0;\n\t\tbufferSize = buffer.length;\n\t}\n\n\tfun getChar() : Char {\n\t\tif (pos == bufferSize) {\n\t\t\treadBuffer();\n\t\t}\n\t\treturn buffer[pos++];\n\t}\n\n\tfun getInt() : Int {\n\t\tvar ans : Int = 0;\n\t\tvar c : Char = ' ';\n\t\tvar minus : Boolean = false;\n\t\twhile ((c == ' ') or (c == '\\n'))\n\t\t\tc = getChar();\n\t\tif (c == '-') {\n\t\t\tminus = true;\n\t\t\tc = getChar();\n\t\t}\n\t\twhile ((c != ' ') and (c != '\\n')) {\n\t\t\tans = ans * 10 + c.toInt() - '0'.toInt();\n\t\t\tc = getChar();\n\t\t}\n\t\tif (minus) {\n\t\t\tans *= -1;\n\t\t}\n\t\treturn ans;\n\t}\n\n\tfun getLong() : Long {\n\t\tvar ans : Long = 0;\n\t\tvar c : Char = ' ';\n\t\tvar minus : Boolean = false;\n\t\twhile ((c == ' ') or (c == '\\n'))\n\t\t\tc = getChar();\n\t\tif (c == '-') {\n\t\t\tminus = true;\n\t\t\tc = getChar();\n\t\t}\n\t\twhile ((c != ' ') and (c != '\\n')) {\n\t\t\tans = ans * 10 + c.toInt() - '0'.toInt();\n\t\t\tc = getChar();\n\t\t}\n\t\tif (minus) {\n\t\t\tans *= -1;\n\t\t}\n\t\treturn ans;\n\t} \n\n\tfun getString() : String {\n\t\tvar c : Char = ' ';\n\t\tvar ans : String = \"\";\n\t\twhile ((c == ' ') or (c == '\\n'))\n\t\t\tc = getChar();\n\t\twhile ((c != ' ') and (c != '\\n')) {\n\t\t\tans += c;\n\t\t\tc = getChar();\n\t\t}\n\t\treturn ans;\n\t}\n\n\tfun getSpaceString() : String {\n\t\tvar ans : String = buffer;\n\t\treadBuffer();\n\t\treturn ans;\n\t}\n}\n", "src_uid": "e7ad55ce26fc8610639323af1de36c2d"} {"source_code": "import kotlin.math.*\nfun main(args: Array){\n\tval n = readLine()!!.toLong()\n\tprintln((n/2).toLong()+1)\n}", "src_uid": "5551742f6ab39fdac3930d866f439e3e"} {"source_code": "import kotlin.math.min\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n\n val n = readInt()\n val daysOffFullWeeks = 2 * (n / 7)\n print(\"${daysOffFullWeeks + if (n % 7 == 6) 1 else 0} ${daysOffFullWeeks + min(2, (n % 7))}\")\n}", "src_uid": "8152daefb04dfa3e1a53f0a501544c35"} {"source_code": "fun main() {\n var (a, b) = readLine()!!.split(\" \").map(String::toLong)\n var sol = 0L\n while (b != 0L) {\n sol+= a/b\n val c = a % b\n a = b\n b = c\n }\n print(sol)\n}", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83"} {"source_code": "import kotlin.math.ceil\nimport kotlin.math.max\nimport kotlin.math.min\n\nfun main() {\n val (x, y, m) = readStrings().map { it.toLong() }\n\n var biggest = max(x, y)\n if (biggest >= m) println(0)\n else if (biggest < m && biggest <= 0) println(-1)\n else {\n var smallest = min(x, y)\n var moves = 0L\n if (smallest < 0) {\n moves = ceil(-smallest.toDouble()/biggest).toLong()\n smallest += moves * biggest\n }\n\n while (max(smallest, biggest) < m) {\n biggest = max(smallest, biggest)\n smallest = min(smallest, biggest)\n// println(\"$biggest $smallest $moves\")\n smallest = biggest.also { biggest += smallest }\n moves++\n }\n println(moves)\n }\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\n\nprivate fun readStrings() = readLn().trim().split(\" \")\n", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821"} {"source_code": "import java.util.*\n\nfun main(args: Array) {\n var scan = Scanner(System.`in`)\n\n var word = scan.nextLine()\n println(word.replaceRange(0, 1, word[0].toUpperCase().toString()))\n}", "src_uid": "29e0fc0c5c0e136ac8e58011c91397e4"} {"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}", "src_uid": "77b5f83cdadf4b0743618a46b646a849"} {"source_code": "fun main(args: Array) {\n val s = readLine()!!\n val ans = s.subSequence(0, s.length / 2)\n .zip(s.subSequence(s.length / 2 + s.length % 2, s.length).reversed())\n .filter { it.first != it.second }\n .size\n println(if (ans == 1 || (ans == 0 && s.length % 2 == 1)) \"YES\" else \"NO\")\n}", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52"} {"source_code": "fun main() {\r\n val t = readln().toInt()\r\n repeat(t) {\r\n val n = readln().toInt()\r\n val numbers = HashSet()\r\n // Squares\r\n var i = 1\r\n while (i * i <= n) {\r\n numbers.add(i * i)\r\n i++\r\n }\r\n // Cubes\r\n i = 1\r\n while (i * i * i <= n) {\r\n numbers.add(i * i * i)\r\n i++\r\n }\r\n println(numbers.size)\r\n }\r\n}", "src_uid": "015afbefe1514a0e18fcb9286c7b6624"} {"source_code": "fun main(arg: Array){\n val size = readLine()!!.toInt()\n var arr = readLine()!!\n\n if (size == 1 && arr[0] == '0') {\n System.out.print(\"No\")\n return\n }\n for (i in 0 until size) {\n //System.out.print(\"\\ntooTight: \" + tooTight(arr, i))\n //System.out.print(\"canAdd\" + canAdd(arr, i))\n if (tooTight(arr, i) || tooFree(arr, i)) {\n System.out.print(\"No\")\n return\n }\n }\n System.out.print(\"Yes\")\n}\n\nfun tooTight(string: String, position: Int): Boolean {\n if (string[position] == '0') return false\n return (position - 1 >= 0 && string[position - 1] == '1') \n || (position + 1 < string.length && string[position + 1] == '1')\n}\n\nfun tooFree(string: String, position: Int): Boolean {\n if (string[position] == '1') return false\n return (position == 0 || string[position - 1] == '0') \n && (position == string.length - 1 || string[position + 1] == '0')\n}\n", "src_uid": "c14d255785b1f668d04b0bf6dcadf32d"} {"source_code": "fun main() {\n val princessSpeed = readLine()!!.toDouble()\n val dragonSpeed = readLine()!!.toDouble()\n val discoveryTime = readLine()!!.toInt()\n val timeWastedInCave = readLine()!!.toInt()\n val distanceToCastle = readLine()!!.toInt()\n var coinsCount = 0\n if (princessSpeed <= dragonSpeed) {\n var princessLocation = discoveryTime * princessSpeed\n var overtakeLocation = princessLocation + (princessSpeed * (princessLocation / (dragonSpeed - princessSpeed)))\n while (overtakeLocation < distanceToCastle) {\n princessLocation = overtakeLocation\n coinsCount++\n val bufferTime = (princessLocation / dragonSpeed) + timeWastedInCave\n princessLocation += bufferTime * princessSpeed\n overtakeLocation = princessLocation + (princessSpeed * (princessLocation / (dragonSpeed - princessSpeed)))\n }\n }\n println(coinsCount)\n}", "src_uid": "c9c03666278acec35f0e273691fe0fff"} {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.PriorityQueue\nimport java.util.StringTokenizer\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n var ans = readLn().replace(Regex(\"\"\"//+\"\"\"), \"/\")\n if(ans.length > 1) ans = ans.removeSuffix(\"/\")\n println(ans)\n}\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031"} {"source_code": "fun main(args: Array) {\n val r = java.util.Scanner(System.`in`)\n var n = r.nextInt()\n val a = r.nextInt()\n val b = r.nextInt()\n val c = Array(n,{0})\n var d : Int\n for (i in 1..a)\n c[r.nextInt()-1]=1\n for (i in 1..b) {\n val e = r.nextInt()-1\n if (c[e] == 0)\n c[e]=2\n }\n c.forEach { print(\"$it \") }\n}", "src_uid": "a35a27754c9c095c6f1b2d4adccbfe93"} {"source_code": "import java.io.PrintWriter\nimport kotlin.math.min\n\n\nfun main() {\n io.apply {\n\n val sum = int\n val k = int\n val wMin = int\n\n val M = 1000000007\n\n val dp0 = IntArray(sum + 1)\n val dp1 = IntArray(sum + 1)\n dp0[0] = 1\n for (i in 1..sum) {\n for (j in 1 .. k) {\n if (i - j >= 0) {\n dp1[i] = (dp1[i] + dp1[i - j]) % M\n if (j < wMin) {\n dp0[i] = (dp0[i] + dp0[i - j]) % M\n } else\n dp1[i] = (dp1[i] + dp0[i - j]) % M\n }\n }\n }\n\n cout .. dp1[sum] .. nl\n\n }.cout.flush()\n}\n\n// @formatter:off\nprivate val io = object {\n private val `in` = System.`in`\n private fun ll(): Long {\n var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }\n do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n\n }\n val int get() = ll().toInt(); val long get() = ll()\n fun ints(n: Int = int): IntArray { return IntArray(n) { int } }\n fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }\n val cout = PrintWriter(System.out); val nl = \"\\n\"\n private var buf = CharArray(32)\n private var bufSize = 32\n fun str(expect: Int = 32): String {\n var ix = 0\n var x: Int\n if (bufSize < expect)\n buf = CharArray(expect)\n do x = `in`.read() while (x < 33)\n do {\n if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }\n buf[ix++] = x.toChar()\n x = `in`.read()\n } while (x > 32)\n return java.lang.String.copyValueOf(buf, 0, ix)\n }\n operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(\" \") }; return this }\n operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }\n} // @formatter:on\n\n/* ----------- */\n\n", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d"} {"source_code": "import java.io.BufferedReader\nimport java.util.*\n\nclass Solver {\n\n fun input(inp: FastInputReader) {\n val (n, m, k) = inp.readIntArray(3)\n val a = inp.readIntArray(n)\n for (delta in 1..n) {\n for (mult in -1..1 step 2) {\n val nxt = m - 1 + delta * mult\n if (nxt in 0..n - 1 && a[nxt] in 1..k) {\n println(delta * 10)\n return\n }\n }\n }\n }\n\n fun solve() {\n\n }\n\n}\n\nobject Algorithms {\n\n tailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)\n tailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\n\n fun lcm(a: Int, b: Int): Int = a / gcd(a, b) * b\n fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b\n\n}\n\nclass FastInputReader {\n\n private val bufferedReader: BufferedReader = System.`in`.bufferedReader()\n private var stringTokenizer: StringTokenizer = StringTokenizer(\"\")\n\n fun nextLine(): String = bufferedReader.readLine()\n fun next(): String {\n while (!stringTokenizer.hasMoreTokens())\n stringTokenizer = StringTokenizer(nextLine())\n return stringTokenizer.nextToken()\n }\n\n fun readInt(): Int = next().toInt()\n fun readLong(): Long = next().toLong()\n fun readDouble(): Double = next().toDouble()\n\n fun readIntArray(size: Int) = IntArray(size, { readInt() })\n fun readLongArray(size: Int) = LongArray(size, { readLong() })\n fun readStringArray(size: Int) = Array(size, { next() })\n inline fun readTArray(size: Int, convert: (Int, String) -> T) = Array(size, { convert(it, next()) })\n\n fun readIntTable(rows: Int, cols: Int) = Array(rows, { readIntArray(cols) })\n fun readLongTable(rows: Int, cols: Int) = Array(rows, { readLongArray(cols) })\n fun readStringTable(rows: Int, cols: Int) = Array(rows, { readStringArray(cols) })\n inline fun readTTable(rows: Int, cols: Int, convert: (Int, Int, String) -> T) = Array(rows, { row -> readTArray(cols, { col, s -> convert(row, col, s) }) })\n\n}\n\nfun main(args: Array) {\n\n// val millis = measureTimeMillis(Solver()::solve)\n// System.err.println(\"Time spent: $millis\")\n val solver = Solver()\n solver.input(FastInputReader())\n solver.solve()\n\n}\n", "src_uid": "57860e9a5342a29257ce506063d37624"} {"source_code": "import java.io.BufferedReader\nimport java.io.InputStreamReader\n\nfun main(args: Array) {\n val reader = BufferedReader(InputStreamReader(System.`in`))\n val line = reader.readLine()\n val regex: Regex = Regex(\"h.*e.*l.*l.*o.*\")\n val contains = line.contains(regex)\n println(if (contains) \"YES\" else \"NO\")\n}", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838"} {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readStrings() = readLn().split(\" \") // list of strings\n\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of Longs\n\nvar n = 0\n\n\nfun main() {\n\n val m = readInts().sortedDescending()\n\n var balance = 0\n\n for (x in m) {\n if (balance <= 0) {\n balance += x\n } else {\n balance -= x\n }\n }\n\n if (balance == 0) {\n println(\"YES\")\n } else {\n println(\"NO\")\n }\n\n}\n", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37"} {"source_code": "import java.util.*\n\nfun main() {\n val sc = Scanner(System.`in`)\n val s = sc.next()\n val rev = s.substring(1) + s.substring(0, 1)\n val t = sc.next().toInt()\n val st = arrayOfNulls(t)\n for (i in 0 until t) {\n val cur = sc.next()\n if (cur == s || cur == rev) {\n println(\"YES\")\n System.exit(0)\n }\n st[i] = cur\n }\n for (i in 0 until t) {\n for (j in 0 until t) {\n if (i == j) {\n continue\n }\n if (s == st[i]!!.substring(1) + st[j]!!.substring(0, 1) || s == st[j]!!.substring(1) + st[i]!!.substring(0, 1)) {\n println(\"YES\")\n System.exit(0)\n }\n }\n }\n println(\"NO\")\n}", "src_uid": "cad8283914da16bc41680857bd20fe9f"} {"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}", "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96"} {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val num = scanner.next()\n val k = scanner.nextInt()\n var a = 0\n for (i in num.length - 1 downTo 0){\n if (Integer.parseInt(\"${num[i]}\") + a + 1 > k) {\n println(num.substring(0 until i) + (Integer.parseInt(\"${num[i]}\") - k + a))\n return\n }\n a += Integer.parseInt(\"${num[i]}\") + 1\n }\n}", "src_uid": "064162604284ce252b88050b4174ba55"} {"source_code": "import java.lang.StringBuilder\nimport java.util.*\n\nval scanner = Scanner(System.`in`)\n\nfun readInt() = scanner.nextInt()\n\nfun Int.toEasterEggs(): String = StringBuilder().let { builder ->\n repeat(this / 7) { builder.append(\"ROYGBIV\") }\n builder.append(\"GBIVGBI\".substring(0, (this % 7)))\n builder.toString()\n}\n\nfun main() = readInt().toEasterEggs().run(::print)", "src_uid": "dc3817c71b1fa5606f316e5e94732296"} {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n val n = r.readLine()!!.toInt()\n val v = r.readLine()!!.split(\" \").map { it.toInt() }.toSet().toList().sorted()\n when(v.size){\n 1 -> println(0)\n 2 -> println(if ((v[1]-v[0])%2==0) (v[1]-v[0])/2 else (v[1]-v[0]))\n 3 -> println(if (v[2]-v[1]==v[1]-v[0]) v[2]-v[1] else -1)\n else -> println(-1)\n }\n}\n", "src_uid": "d486a88939c132848a7efdf257b9b066"} {"source_code": "import kotlin.math.abs\n\nfun main(args: Array) {\n\tval matrix: MutableList> = mutableListOf()\n\tfor (i in 0 until 5) {\n\t\tval row = readLine()!!.split(' ').map(String::toInt)\n\t\tmatrix.add(row)\n\t}\n\tprintln(getResult(matrix))\n}\n\nfun getResult(matrix: List>): Int {\n\tval centerI = 2\n\tval centerJ = 2\n\tvar integerI = 0\n\tvar integerJ = 0\n\n\tloop@ for (i in 0 until matrix.size) {\n\t\tfor (j in 0 until matrix[i].size) {\n\t\t\tif (matrix[i][j] == 1) {\n\t\t\t\tintegerI = i\n\t\t\t\tintegerJ = j\n\t\t\t\tbreak@loop\n\t\t\t}\n\t\t}\t\n\t}\n\t\n\treturn abs(integerI - centerI) + abs(integerJ - centerJ)\n\t\n}", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9"} {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.lang.StringBuilder\nimport java.util.*\n\n// region\nclass ModInt(x: Long) {\n\n companion object {\n const val MOD = 998244353L\n }\n\n val x = (x % MOD + MOD) % MOD\n\n operator fun plus(other: ModInt): ModInt {\n return ModInt(x + other.x)\n }\n\n operator fun minus(other: ModInt): ModInt {\n return ModInt(x - other.x)\n }\n\n operator fun times(other: ModInt): ModInt {\n return ModInt(x * other.x)\n }\n\n operator fun div(other: ModInt): ModInt {\n return this * other.inv()\n }\n\n fun pow(exp: Long): ModInt {\n if (exp == 0L) return ModInt(1L)\n var a = pow(exp shr 1)\n a *= a\n if (exp and 1L == 0L) return a\n return this * a\n }\n\n fun inv(): ModInt {\n return this.pow(MOD - 2)\n }\n\n override fun equals(other: Any?): Boolean {\n if (this === other) return true\n if (javaClass != other?.javaClass) return false\n\n other as ModInt\n\n if (x != other.x) return false\n\n return true\n }\n\n override fun hashCode(): Int {\n return x.hashCode()\n }\n\n override fun toString(): String {\n return \"$x\"\n }\n\n}\n\nval fac = mutableListOf()\nval invfac = mutableListOf()\n\nfun fact(n: Long, b: Boolean): ModInt {\n if (fac.count() == 0) {\n fac.add(ModInt(1))\n invfac.add(ModInt(1))\n }\n while (fac.count() <= n) {\n fac.add(fac.last() * ModInt(fac.count().toLong()))\n invfac.add(fac.last().inv())\n }\n return if (b) {\n fac[n.toInt()]\n } else {\n invfac[n.toInt()]\n }\n}\n\nfun comb(n: Long, k: Long): ModInt {\n return fact(n, true) * fact(k, false) * fact(n - k, false)\n}\n\nfun comb2(n: Long, k: Long): ModInt {\n var ans = ModInt(1)\n for (i in 0 until k) {\n ans = ans * ModInt(n - i) / ModInt(k - i)\n }\n return ans\n}\n// endregion\n\nfun PrintWriter.solve(sc: FastScanner) {\n val n = sc.nextLong()\n val k = sc.nextLong()\n var ans = ModInt(0)\n for (a1 in 1..n) {\n val v = n / a1\n if (v < k) break\n ans += comb(v - 1, k - 1)\n }\n println(ans)\n}\n\nfun main(args: Array) {\n val writer = PrintWriter(System.out, false)\n writer.solve(FastScanner(System.`in`))\n writer.flush()\n}\n\nclass FastScanner(s: InputStream) {\n private var st = StringTokenizer(\"\")\n private val br = BufferedReader(InputStreamReader(s))\n\n fun next(): String {\n while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextLine() = br.readLine()\n fun nextDouble() = next().toDouble()\n fun ready() = br.ready()\n}", "src_uid": "8e8eb64a047cb970a549ee870c3d280d"} {"source_code": "import java.util.*\n\nfun main() {\n val (n, m) = readLine()!!.split(' ').map { it.toInt() }\n val initials = (0 until n).map {\n readLine()!!.split(' ').map { it.toInt() }\n }\n\n // key is 2 * mid, in other words start + end\n // the set contains starts\n val terminals = mutableMapOf>()\n\n repeat(m) {\n val (start, end) = readLine()!!.split(' ').map { it.toInt() }\n terminals.computeIfAbsent(start + end) { TreeSet() }.add(start)\n }\n\n // finds the segments with the same mid point\n // get the widest of it that is between the given points\n fun steps(start: Int, end: Int): Int? = terminals[start + end]?.ceiling(start)?.let { it - start }\n\n val answers = IntArray(n)\n initials.forEachIndexed { i, (start, end) ->\n val left = steps(start, end - 2)?.let { it + 1 } ?: Int.MAX_VALUE\n val middle = steps(start, end) ?: Int.MAX_VALUE\n val right = steps(start + 2, end)?.let { it + 1 } ?: Int.MAX_VALUE\n\n val result = maxOf(minOf(left, middle), minOf(middle, right))\n\n answers[i] = if (result == Int.MAX_VALUE) -1 else result\n }\n\n println(answers.joinToString(\" \"))\n}\n", "src_uid": "e93431a2908f8cdd367fe5cdfc863c80"} {"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args : Array) {\n //====== Input preparations ========================================================\n// val fin = BufferedReader(FileReader(\"b.in\"))\n val fin = BufferedReader(InputStreamReader(System.`in`))\n val fout = PrintWriter (System.out)\n var tokenizer = StringTokenizer(\"\")\n fun next() : String {\n while (!tokenizer.hasMoreTokens())\n tokenizer = StringTokenizer(fin.readLine())\n return tokenizer.nextToken()\n }\n fun nextInt() = next().toInt()\n fun nextPair() = nextInt() to nextInt()\n fun nextPairDec() = nextInt()-1 to nextInt()-1\n //====== Solution below ============================================================\n val s = next()\n val pos = charArrayOf('R', 'B', 'Y', 'G').map { s.indexOf(it) % 4 }\n val cnt = Array(4, {0})\n for ((i,c) in s.withIndex())\n if (c == '!')\n cnt[i%4]++\n for (i in 0..3)\n for (j in 0..3)\n if (pos[i] == j)\n fout.print(\"${cnt[j]} \")\n\n fout.close()\n fin.close()\n}\n\n", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33"} {"source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n fun gcd(x: Long, y: Long):Long = if (y == 0L) x else gcd(y, x % y)\n\n val a = nextLong()\n val b = nextLong()\n val x = nextLong()\n val y = nextLong()\n\n val g = gcd(x, y)\n val _x = x / g\n val _y = y / g\n\n println(Math.min(a / _x, b / _y))\n}", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d"} {"source_code": "fun num_good_sequences(n : Int, k : Int) : Long {\n val modulo = 1000000007L\n val num_ways = Array(n + 1, {_ -> LongArray(k + 1)}) \n for (i in 1 .. n) {\n num_ways[i][1] = 1L\n }\n for (j in 1 .. (k - 1)) {\n val j_plus_1 = j + 1\n for (i in 1 .. n) {\n var f = 1\n var fi = f * i\n while (fi <= n) {\n num_ways[fi][j_plus_1] = (num_ways[fi][j_plus_1] + num_ways[i][j]) % modulo\n f = f + 1\n fi = f * i\n }\n }\n }\n var result = 0L\n for (i in 1 .. n) {\n result = (result + num_ways[i][k]) % modulo\n }\n return result\n}\n\nfun main(args : Array) {\n val n_k_nullable_str = readLine()\n if (n_k_nullable_str == null) {\n // Do nothing ...\n } else {\n val n_k_str = n_k_nullable_str\n val n_k = n_k_str.split(' ').map(String::toInt)\n val n = n_k[0]\n val k = n_k[1]\n val result = num_good_sequences(n, k)\n println(\"${result}\")\n }\n}\n", "src_uid": "c8cbd155d9f20563d37537ef68dde5aa"} {"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}", "src_uid": "38690bd32e7d0b314f701f138ce19dfb"} {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n readLine()\n print(if (readInts().sum() >= readInts().sum()) \"Yes\" else \"No\")\n\n}", "src_uid": "e0ddac5c6d3671070860dda10d50c28a"} {"source_code": "fun main() {\n val s = readLn()\n val t = readLn()\n\n var ans = 0\n\n for(l in s.indices) {\n for(r in l+ans..s.lastIndex) {\n val n = s.substring(0, l) + s.substring(r+1, s.length)\n\n val ni = n.iterator()\n val ti = t.iterator()\n var tc = ti.nextChar()\n\n while(ni.hasNext()) {\n if(ni.nextChar() == tc) {\n if(ti.hasNext().not()) {\n ans = r-l+1\n break\n }\n tc = ti.nextChar()\n }\n }\n }\n }\n\n println(ans)\n}\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readStringSeq() = readLn().splitToSequence(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readIntSeq() = readStringSeq().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readDoubleSeq() = readStringSeq().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\nfun readLongSeq() = readStringSeq().map { it.toLong() }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit) { Output().apply(block).nowPrint() }", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f"} {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport java.math.BigInteger\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n// val startTime = System.nanoTime()\n\n val numCases = 1//readInt()\n case@ for(case in 1..numCases) {\n// print(\"Case #$case: \")\n\n val n = read().toBigInteger()\n\n val ones = Array(51) { one }\n for(i in 1..ones.lastIndex) ones[i] = (ones[i-1] * ten).inc()\n\n val heap = DijkHeap()\n heap.promote(n, 0)\n\n val ans = run ans@ {\n while(heap.isNotFinished()) {\n val x = heap.remove()\n val c = heap.cost(x)\n\n if(x == BigInteger.ZERO) return@ans c\n\n val i = ones.bsIndexOfLast { it <= x }\n heap.promote(x - ones[i], c + i + 1)\n heap.promote(ones[i+1] - x, c + i + 2)\n }\n\n -1\n }\n\n println(ans)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nval one = BigInteger.ONE\nval ten = BigInteger.TEN!!\n\nfun splitmix64(seed: Long): Long {\n var x = seed // * -7046029254386353131\n x = (x xor (x ushr 30)) * -4658895280553007687\n x = (x xor (x ushr 27)) * -7723592293110705685\n return (x xor (x ushr 31))\n}\n@JvmField val nonce64 = random.nextLong()\n@JvmField val gamma64 = random.nextLong() or 1\nfun Long.hash() = splitmix64((nonce64 xor this) * gamma64)\n\nfun BigInteger.hash(): Long = toByteArray().asUByteArray().run {\n var res = size.toLong()\n for(i in indices) {\n if(i and 7 == 0) res = res.hash()\n res = res xor get(i).toLong().shl(i.and(7) * 8)\n }\n\n return res//.hash()\n}\n\ninline fun bsFirst(first: Int, last: Int, predicate: (Int) -> Boolean): Int {\n var low = first\n var high = last\n\n while (low <= high) {\n val mid = low.and(high) + low.xor(high).shr(1)\n if(predicate(mid)) high = mid - 1\n else low = mid + 1\n }\n return low\n}\ninline fun IntRange.bsFirst(predicate: (Int) -> Boolean) = bsFirst(first, last, predicate)\n\ninline fun bsLast(first: Int, last: Int, predicate: (Int) -> Boolean) = bsFirst(first, last) { !predicate(it) } - 1\ninline fun IntRange.bsLast(predicate: (Int) -> Boolean) = bsLast(first, last, predicate)\n\ninline fun Array.bsIndexOfFirst(predicate: (T) -> Boolean) = bsFirst(0, lastIndex) { predicate(get(it)) }\ninline fun Array.bsFirst(predicate: (T) -> Boolean) = get(bsIndexOfFirst(predicate))\ninline fun Array.bsFirstOrNull(predicate: (T) -> Boolean) = getOrNull(bsIndexOfFirst(predicate))\ninline fun Array.bsIndexOfLast(predicate: (T) -> Boolean) = bsLast(0, lastIndex) { predicate(get(it)) }\ninline fun Array.bsLast(predicate: (T) -> Boolean) = get(bsIndexOfLast(predicate))\ninline fun Array.bsLastOrNull(predicate: (T) -> Boolean) = getOrNull(bsIndexOfLast(predicate))\n\nconst val inf = Int.MAX_VALUE\nclass DijkHeap {\n val h = intListOf(-1)\n val pos = IntList()\n val cost = IntList()\n val map = LongIntMap(nullValue = -1)\n val keys = mutableListOf()\n\n val inHeap get() = h.lastIndex\n\n private fun swap(i: Int, j: Int) {\n val hi = h[i]; val hj = h[j]\n h[j] = hi; h[i] = hj\n pos[hi] = j; pos[hj] = i\n }\n\n fun promote(key0: BigInteger, newCost: Int): Boolean {\n val key = run {\n val hash = key0.hash()\n map[hash].let { if(it != -1) return@run it }\n keys.size.also {\n map[hash] = it\n keys.add(key0)\n h.add(it)\n pos.add(inHeap)\n cost.add(inf)\n }\n }\n if(newCost >= cost[key]) return false\n var i = pos[key]\n\n while(i > 1) {\n val par = i shr 1\n if (newCost >= cost[h[par]]) break\n swap(i, par)\n i = par\n }\n\n cost[key] = newCost\n return true\n }\n\n val head get() = h[1]\n fun isNotFinished() = inHeap > 0\n\n fun remove() = head.let { hd ->\n swap(1, inHeap)\n pos[hd] = -1\n h.pop()\n\n var i = 1\n while(true) {\n val l = i shl 1\n if(l > inHeap) break\n val r = l or 1\n\n var best = l\n var p = cost[h[l]]\n if(r <= inHeap) {\n val pr = cost[h[r]]\n if(pr < p) {\n best = r\n p = pr\n }\n }\n\n if(cost[h[i]] <= p) break\n\n swap(i, best)\n i = best\n }\n\n keys[hd]\n }\n\n fun cost(key: BigInteger): Int {\n val hash = key.hash()\n val i = map[hash]\n return if(i == -1) inf else cost[i]\n }\n}\n\nclass IntList(initialCapacity: Int = 12) {\n private var arr = IntArray(initialCapacity)\n val _arr get() = arr\n private val capacity get() = arr.size\n var size = 0\n private set\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n\n constructor(copyFrom: IntArray): this(copyFrom.size) { copyFrom.copyInto(arr); size = copyFrom.size }\n constructor(copyFrom: Collection): this(copyFrom.size) { arr = copyFrom.toIntArray(); size = copyFrom.size }\n\n fun contentEquals(other: IntList): Boolean {\n return this === other || size == other.size && indices.all { this[it] == other[it] }\n }\n\n private fun grow(minCapacity: Int = 8) {\n val newCapacity = maxOf(minCapacity, capacity + (capacity shr 1))\n arr = arr.copyOf(newCapacity)\n }\n\n fun ensureCapacity(minCapacity: Int) { if(capacity < minCapacity) grow(minCapacity) }\n\n operator fun get(index: Int): Int {\n require(index in 0 until size)\n return arr[index]\n }\n\n operator fun set(index: Int, value: Int) {\n require(index in 0 until size)\n arr[index] = value\n }\n\n fun add(value: Int) {\n if(size == capacity) grow()\n arr[size++] = value\n }\n\n fun addAll(list: IntList) {\n ensureCapacity(size + list.size)\n list.arr.copyInto(arr, size, 0, list.size)\n size += list.size\n }\n\n fun add(index: Int, element: Int) {\n if(size == capacity) grow()\n arr.copyInto(arr, index + 1, index, size)\n size++\n set(index, element)\n }\n\n fun clear() { size = 0 }\n\n fun removeAt(index: Int): Int {\n val e = get(index)\n arr.copyInto(arr, index, index + 1, size)\n size--\n return e\n }\n\n fun indexOf(e: Int): Int {\n for(i in 0 until size) if(this[i] == e) return i\n return -1\n }\n\n fun remove(e: Int): Boolean {\n val i = indexOf(e)\n if(i == -1) return false\n removeAt(i)\n return true\n }\n\n operator fun iterator() = object: IntIterator() {\n private var pos = 0\n override fun hasNext() = pos < size\n override fun nextInt() = get(pos++)\n }\n\n inline fun isEmpty() = size == 0\n inline fun isNotEmpty() = size != 0\n\n fun pop() = arr[--size]\n\n fun popToSize(s: Int) {\n require(s >= 0)\n if(s < size) size = s\n }\n\n fun swap(i: Int, j: Int) { val t = this[i]; this[i] = this[j]; this[j] = t }\n fun reverse() {\n for(i in 0 until size / 2) swap(i, lastIndex - i)\n }\n\n fun shuffle(rnd: Random = random) { for(i in lastIndex downTo 1) swap(i, rnd.nextInt(i+1)) }\n\n inline fun sortWith(cmp: (Int, Int) -> Int) { _mergeSort(_arr, size, IntArray(size), IntArray::get, IntArray::set, cmp) }\n inline fun > sortBy(func: (Int) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\n inline fun > sortByDescending(func: (Int) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\n fun sort() { sortBy { it } }\n fun sortDescending() { sortByDescending { it } }\n\n fun joinToString(separator: CharSequence) = if(size == 0) \"\" else let {\n buildString {\n append(it[0])\n for (i in 1 until size) {\n append(separator).append(it[i])\n }\n }\n }\n\n override fun toString() = \"[\" + joinToString(\", \") + \"]\"\n\n fun toIntArray() = arr.copyOf(size)\n fun toList() = List(size, ::get)\n\n inline fun first() = get(0)\n inline fun last() = get(lastIndex)\n}\n\ninline fun IntList(size: Int, init: (Int) -> Int) = IntList(size).apply {\n for(i in 0 until size) { add(init(i)) }\n}\ninline fun IntArray.toIntList() = IntList(this)\ninline fun Collection.toIntList() = IntList(this)\ninline fun intListOf(vararg values: Int) = IntList(values)\n\nfun IntList.max() = (1 until size).fold(this[0]) { acc, i -> max(acc, this[i]) }\nfun IntList.min() = (1 until size).fold(this[0]) { acc, i -> min(acc, this[i]) }\nfun IntList.getOrNull(i: Int) = if(i in indices) get(i) else null\ninline fun IntList.count(predicate: (Int) -> Boolean) = indices.count { predicate(this[it]) }\nfun IntList.copyOf() = IntList(size, ::get)\n\ntypealias LongIntMap = _Ez_Long__Int_HashMap\ninline operator fun LongIntMap.set(key: Long, value: Int) { put(key, value) }\ninline operator fun LongIntMap.contains(key: Long) = containsKey(key)\n\nclass _Ez_Long__Int_HashMap(capacity: Int = DEFAULT_CAPACITY, val nullValue: Int = 0) :\n _Ez_Long__Int_Map {\n companion object {\n private const val DEFAULT_CAPACITY = 8\n // There are three invariants for size, removedCount and arraysLength:\n// 1. size + removedCount <= 1/2 arraysLength\n// 2. size > 1/8 arraysLength\n// 3. size >= removedCount\n// arraysLength can be only multiplied by 2 and divided by 2.\n// Also, if it becomes >= 32, it can't become less anymore.\n private const val REBUILD_LENGTH_THRESHOLD = 32\n private const val HASHCODE_INITIAL_VALUE = -0x7ee3623b\n private const val HASHCODE_MULTIPLIER = 0x01000193\n private const val FREE: Byte = 0\n private const val REMOVED: Byte = 1\n private const val FILLED: Byte = 2\n private val hashSeed = random.nextLong()\n private val gamma = random.nextLong() or 1\n }\n\n private lateinit var keys: LongArray\n private lateinit var values: IntArray\n private lateinit var status: ByteArray\n override var size = 0\n private set\n private var removedCount = 0\n private var mask = 0\n\n constructor(map: _Ez_Long__Int_Map) : this(map.size) {\n val it = map.iterator()\n while (it.hasNext()) {\n put(it.key, it.value)\n it.next()\n }\n }\n\n constructor(javaMap: Map) : this(javaMap.size) {\n for ((key, value) in javaMap) {\n put(key, value)\n }\n }\n\n private fun getStartPos(h: Long): Int {\n var x = (h xor hashSeed) * gamma\n x = (x xor (x ushr 30)) * -4658895280553007687\n x = (x xor (x ushr 27)) * -7723592293110705685\n return (x xor (x ushr 31)).toInt() and mask\n }\n\n override fun isEmpty(): Boolean = size == 0\n\n override fun containsKey(\n key: Long\n ): Boolean {\n var pos = getStartPos(key)\n while (status[pos] != FREE) {\n if (status[pos] == FILLED && keys[pos] == key) {\n return true\n }\n pos = pos + 1 and mask\n }\n return false\n }\n\n override fun get(\n key: Long\n ): Int {\n var pos = getStartPos(key)\n while (status[pos] != FREE) {\n if (status[pos] == FILLED && keys[pos] == key) {\n return values[pos]\n }\n pos = pos + 1 and mask\n }\n return nullValue\n }\n\n override fun put(\n key: Long,\n value: Int\n ): Int {\n var pos = getStartPos(key)\n while (status[pos] == FILLED) {\n if (keys[pos] == key) {\n val oldValue = values[pos]\n values[pos] = value\n return oldValue\n }\n pos = pos + 1 and mask\n }\n if (status[pos] == FREE) {\n status[pos] = FILLED\n keys[pos] = key\n values[pos] = value\n size++\n if ((size + removedCount) * 2 > keys.size) {\n rebuild(keys.size * 2) // enlarge the table\n }\n return nullValue\n }\n val removedPos = pos\n pos = pos + 1 and mask\n while (status[pos] != FREE) {\n if (status[pos] == FILLED && keys[pos] == key) {\n val oldValue = values[pos]\n values[pos] = value\n return oldValue\n }\n pos = pos + 1 and mask\n }\n status[removedPos] = FILLED\n keys[removedPos] = key\n values[removedPos] = value\n size++\n removedCount--\n return nullValue\n }\n\n override fun remove(\n key: Long\n ): Int {\n var pos = getStartPos(key)\n while (status[pos] != FREE) {\n if (status[pos] == FILLED && keys[pos] == key) {\n val removedValue = values[pos]\n status[pos] = REMOVED\n size--\n removedCount++\n if (keys.size > REBUILD_LENGTH_THRESHOLD) {\n if (8 * size <= keys.size) {\n rebuild(keys.size / 2) // compress the table\n } else if (size < removedCount) {\n rebuild(keys.size) // just rebuild the table\n }\n }\n return removedValue\n }\n pos = pos + 1 and mask\n }\n return nullValue\n }\n\n override fun clear() {\n if (keys.size > REBUILD_LENGTH_THRESHOLD) {\n initEmptyTable(REBUILD_LENGTH_THRESHOLD)\n } else {\n status.fill(FREE)\n size = 0\n removedCount = 0\n }\n }\n\n override fun keys(): LongArray {\n val result = LongArray(size)\n var i = 0\n var j = 0\n while (i < keys.size) {\n if (status[i] == FILLED) {\n result[j++] = keys[i]\n }\n i++\n }\n return result\n }\n\n override fun values(): IntArray {\n val result = IntArray(size)\n var i = 0\n var j = 0\n while (i < values.size) {\n if (status[i] == FILLED) {\n result[j++] = values[i]\n }\n i++\n }\n return result\n }\n\n override fun iterator(): _Ez_Long__Int_MapIterator {\n return _Ez_Long__Int_HashMapIterator()\n }\n\n private fun rebuild(newLength: Int) {\n val oldKeys = keys\n\n val oldValues = values\n val oldStatus = status\n initEmptyTable(newLength)\n for (i in oldKeys.indices) {\n if (oldStatus[i] == FILLED) {\n put(oldKeys[i], oldValues[i])\n }\n }\n }\n\n private fun initEmptyTable(length: Int) {\n keys = LongArray(length)\n values = IntArray(length)\n status = ByteArray(length)\n size = 0\n removedCount = 0\n mask = length - 1\n }\n\n fun contentEquals(that: _Ez_Long__Int_HashMap): Boolean {\n if (size != that.size) {\n return false\n }\n for (i in keys.indices) {\n if (status[i] == FILLED) {\n val thatValue = that[keys[i]]\n if (thatValue != values[i]) {\n return false\n }\n }\n }\n return true\n }\n\n override fun toString(): String {\n val sb = StringBuilder()\n sb.append('{')\n for (i in keys.indices) {\n if (status[i] == FILLED) {\n if (sb.length > 1) {\n sb.append(\", \")\n }\n sb.append(keys[i])\n sb.append('=')\n sb.append(values[i])\n }\n }\n sb.append('}')\n return sb.toString()\n }\n\n private inner class _Ez_Long__Int_HashMapIterator : _Ez_Long__Int_MapIterator {\n private var curIndex = 0\n override fun hasNext(): Boolean {\n return curIndex < status.size\n }\n\n\n override val key: Long\n\n get() {\n if (curIndex == keys.size) {\n throw NoSuchElementException(\"Iterator doesn't have more entries\")\n }\n return keys[curIndex]\n }\n\n\n override val value: Int\n\n get() {\n if (curIndex == values.size) {\n throw NoSuchElementException(\"Iterator doesn't have more entries\")\n }\n return values[curIndex]\n }\n\n override fun next() {\n if (curIndex == status.size) {\n return\n }\n curIndex++\n while (curIndex < status.size && status[curIndex] != FILLED) {\n curIndex++\n }\n }\n\n init {\n while (curIndex < status.size && status[curIndex] != FILLED) {\n curIndex++\n }\n }\n }\n\n init {\n require(capacity >= 0) { \"Capacity must be non-negative\" }\n val length = Integer.highestOneBit(4 * max(1, capacity) - 1)\n // Length is a power of 2 now\n initEmptyTable(length)\n }\n}\n\ninterface _Ez_Long__Int_Map {\n\n val size: Int\n\n fun isEmpty(): Boolean\n\n fun containsKey(\n key: Long\n ): Boolean\n\n operator fun get(\n key: Long\n ): Int\n\n fun put(\n key: Long,\n value: Int\n ): Int\n\n fun remove(\n key: Long\n ): Int\n\n fun clear()\n\n fun keys(): LongArray\n\n fun values(): IntArray\n\n operator fun iterator(): _Ez_Long__Int_MapIterator\n\n override fun toString(): String\n}\n\ninterface _Ez_Long__Int_MapIterator {\n operator fun hasNext(): Boolean\n\n val key: Long\n\n val value: Int\n\n operator fun next()\n}\n\ninline fun LongIntMap.forEach(act: (key: Long, value: Int) -> Unit) {\n val ite = iterator()\n while(ite.hasNext()) {\n act(ite.key, ite.value)\n ite.next()\n }\n}\n\n/** IO */\n//@JvmField val ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n//const val PATH = \"src/main/resources/\"\n//@JvmField val INPUT = File(PATH + \"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(PATH + \"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\nconst val _BUFFER_SIZE = 1 shl 16\n@JvmField val _buffer = ByteArray(_BUFFER_SIZE)\n@JvmField var _bufferPt = 0\n@JvmField var _bytesRead = 0\n\ntailrec fun readChar(): Char {\n if(_bufferPt == _bytesRead) {\n _bufferPt = 0\n _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)\n }\n return if(_bytesRead < 0) Char.MIN_VALUE\n else {\n val c = _buffer[_bufferPt++].toChar()\n if (c == '\\r') readChar() else c\n }\n}\n\n/** @param skipNext Whether to skip the next character (usually whitespace), defaults to true */\nfun readCharArray(n: Int, skipNext: Boolean = true): CharArray {\n val res = CharArray(n) { readChar() }\n if(skipNext) readChar()\n return res\n}\n\nfun readLine(): String? {\n var c = readChar()\n return if(c == Char.MIN_VALUE) null\n else buildString {\n while(c != '\\n' && c != Char.MIN_VALUE) {\n append(c)\n c = readChar()\n }\n }\n}\nfun readLn() = readLine()!!\n\nfun read() = buildString {\n var c = readChar()\n while(c <= ' ') {\n if(c == Char.MIN_VALUE) return@buildString\n c = readChar()\n }\n do {\n append(c)\n c = readChar()\n } while(c > ' ')\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** sort overrides to avoid quicksort attacks */\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\ninline fun _mergeSort(a0: A, n: Int, tmp0: A, get: A.(Int) -> T, set: A.(Int, T) -> Unit, cmp: (T, T) -> Int) {\n var a = a0\n var tmp = tmp0\n var len = 1\n while(len < n) {\n var l = 0\n while(true) {\n val m = l + len\n if(m >= n) break\n val r = min(n, m + len)\n var i = l\n var j = m\n for(k in l until r) {\n if(i != m && (j == r || cmp(a.get(i), a.get(j)) <= 0)) {\n tmp.set(k, a.get(i++))\n } else tmp.set(k, a.get(j++))\n }\n l = r\n }\n for(i in l until n) tmp.set(i, a.get(i))\n val t = a; a = tmp; tmp = t\n len += len\n }\n if(a !== a0) for(i in 0 until n) a0.set(i, tmp0.get(i))\n}\n\ninline fun IntArray.sortWith(cmp: (Int, Int) -> Int) { _mergeSort(this, size, IntArray(size), IntArray::get, IntArray::set, cmp) }\ninline fun > IntArray.sortBy(func: (Int) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > IntArray.sortByDescending(func: (Int) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun IntArray.sort() { sortBy { it } }\nfun IntArray.sortDescending() { sortByDescending { it } }\n\ninline fun LongArray.sortWith(cmp: (Long, Long) -> Int) { _mergeSort(this, size, LongArray(size), LongArray::get, LongArray::set, cmp) }\ninline fun > LongArray.sortBy(func: (Long) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > LongArray.sortByDescending(func: (Long) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun LongArray.sort() { sortBy { it } }\nfun LongArray.sortDescending() { sortByDescending { it } }\n\ninline fun DoubleArray.sortWith(cmp: (Double, Double) -> Int) { _mergeSort(this, size, DoubleArray(size), DoubleArray::get, DoubleArray::set, cmp) }\ninline fun > DoubleArray.sortBy(func: (Double) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > DoubleArray.sortByDescending(func: (Double) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun DoubleArray.sort() { sortBy { it } }\nfun DoubleArray.sortDescending() { sortByDescending { it } }\n\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\n// import preserving junk function\n@Suppress(\"NonAsciiCharacters\") fun 雪花飄飄北風嘯嘯天地一片蒼茫() { 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 }", "src_uid": "1961e7c9120ff652b15cad5dd5ca0907"} {"source_code": "fun main() {\r\n val T = 1;\r\n// val T=readLine()!!.toInt();\r\n repeat(T) {\r\n val n = readLine()!!.toInt()\r\n val mod = 998244353L\r\n var dp = LongArray(n+1)\r\n dp.fill(0)\r\n var sum = 0L\r\n for (i in 1 until n+1){\r\n for (j in i until n+1 step i){\r\n dp[j]++;\r\n }\r\n dp[i] = (sum + dp[i]) % mod\r\n sum = (sum + dp[i]) % mod\r\n }\r\n println(dp[n])\r\n }\r\n}\r\n// matrix :- val mat = List(row) { readLine()!!}\r\n// fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)", "src_uid": "09be46206a151c237dc9912df7e0f057"} {"source_code": "fun main() {\n var (n, k, t) = readLine()!!.split(\" \").map { it.toLong() }\n when (t) {\n in 1 until k -> print(t)\n in k..n -> print(k)\n else -> print(k - ((t % n) % k))\n }\n}\n// 966696824 346707476 1196846860", "src_uid": "7e614526109a2052bfe7934381e7f6c2"} {"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 }", "src_uid": "cb4de190ae26127df6eeb7a1a1db8a6d"} {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val n = r.readLine()!!.toInt()\n //var (n, m) = r.readLine()!!.split(\" \").map { it.toInt() }\n var len = r.readLine()!!.toLong()+1\n var ans = 1L\n var base = 2L\n while (len>0){\n if (len%2==1L){\n ans *= base\n }\n base *= base\n len/=2\n }\n println(ans-2)\n}", "src_uid": "f1b43baa14d4c262ba616d892525dfde"} {"source_code": "\n\nfun main(args: Array) {\n val spin = \"v<^>\"\n\n val line = readLine()!!\n val s = line.split(\" \")[0]\n val e = line.split(\" \")[1]\n\n val n = readLine()!!.toInt()\n\n when {\n n % 2 == 0 -> println(\"undefined\")\n n % 2 == 1 -> {\n if(spin[(spin.indexOf(s) + n) % 4] == e[0]) println(\"cw\")\n else println(\"ccw\")\n }\n }\n\n}", "src_uid": "fb99ef80fd21f98674fe85d80a2e5298"} {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007\nclass Comb(n: Int, val mod: Int) {\n\n val F = LongArray(n + 1)\n val I = LongArray(n + 1)\n init {\n F[0] = 1\n for (i in 1..n) {\n F[i] = F[i - 1] * i % mod\n }\n I[n] = powMod(F[n], (mod - 2).toLong(), mod)\n for (i in n - 1 downTo 0) {\n I[i] = I[i + 1] * (i + 1) % mod\n }\n }\n\n private fun powMod(a: Long, n: Long, mod: Int): Long {\n if (n == 0L) return 1\n val res = powMod(a * a % mod, n / 2, mod)\n return if (n % 2 == 1L) res * a % mod else res\n }\n\n fun comb(n: Int, k: Int): Long {\n return F[n] * I[k] % mod * I[n - k] % mod\n }\n\n fun inv(x: Int): Long {\n return I[x] * F[x - 1] % mod\n }\n\n /**\n * nのグループからk回重複ありで選ぶ組み合わせ数\n * n - 1のしきりとkの○で考える\n */\n fun H(n: Int, k: Int) = comb(n + k - 1, k)\n}\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val N = ni()\n val K = nl()\n val comb = Comb(N + 10, MOD)\n val powK = LongArray(N + 11)\n val powKK = LongArray(N + 11)\n powK[0] = 1\n powKK[0] = 1\n for (i in 0 until N + 10) {\n powK[i + 1] = powK[i] * K % MOD\n powKK[i + 1] = powKK[i] * (K - 1) % MOD\n }\n val dp = Array(N + 1){LongArray(N + 1)}\n dp[0][0] = 1\n for (i in 0 until N) {\n for (s in 0 .. N) {\n val cmb1 = (MOD + powK[s] - powKK[s]) % MOD // sの中に1がある\n val cmbAll = powK[s] // すべて\n for (add in 0 .. N - s) {\n val ns = s + add\n val cl = if (add == 0) cmb1 else cmbAll // s側の組み合わせ\n val cr1 = comb.comb(N - s, add) // addの1部分\n val crr = powKK[N - s - add] // addの1以外の部分\n val cmb = cl * cr1 % MOD * crr % MOD\n dp[i + 1][ns] = (dp[i + 1][ns] + dp[i][s] * cmb % MOD) % MOD\n }\n }\n debug(dp[i + 1])\n }\n\n out.println(dp[N][N])\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\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}", "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93"} {"source_code": "import java.lang.Integer.parseInt\nimport java.lang.Long.parseLong\nimport java.lang.Math.min\nimport java.lang.System.exit\nimport java.util.Arrays.binarySearch\nimport java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\nobject F {\ninternal var `in`:BufferedReader? = null\ninternal var out:PrintWriter? = null\ninternal var tok:StringTokenizer? = null\ninternal fun sort(a:IntArray, n:Int) {\nif (n == 0)\n{\nreturn\n}\nfor (i in 1 until n)\n{\nvar j = i\nvar ca = a[i]\ndo\n{\nvar nj = (j - 1) shr 1\nvar na = a[nj]\nif (ca <= na)\n{\nbreak\n}\na[j] = na\nj = nj\n}\nwhile (j != 0)\na[j] = ca\n}\nvar ca = a[0]\nfor (i in n - 1 downTo 1)\n{\nvar j = 0\nwhile ((j shl 1) + 2 + Integer.MIN_VALUE < i + Integer.MIN_VALUE)\n{\nj = j shl 1\nj += if ((a[j + 2] > a[j + 1])) 2 else 1\n}\nif ((j shl 1) + 2 == i)\n{\nj = (j shl 1) + 1\n}\nvar na = a[i]\na[i] = ca\nca = na\nwhile (j != 0 && a[j] < ca)\n{\nj = (j - 1) shr 1\n}\nwhile (j != 0)\n{\nna = a[j]\na[j] = ca\nca = na\nj = (j - 1) shr 1\n}\n}\na[0] = ca\n}\n@Throws(Exception::class)\ninternal fun solve() {\nvar n = scanInt()\nvar m = scanInt()\nvar k = scanInt()\nvar a = IntArray(n)\nfor (i in 0 until n)\n{\na[i] = scanInt()\n}\nsort(a, n)\nvar `as` = LongArray(n + 1)\nfor (i in 0 until n)\n{\n`as`[i + 1] = `as`[i] + a[i]\n}\nvar ans = java.lang.Long.MAX_VALUE\nfor (i in 0..n - m)\n{\nvar v = a[i + m / 2]\nvar up = v.toLong() * (m / 2).toLong() - (`as`[i + m / 2] - `as`[i])\nif (up <= k)\n{\nvar down = (`as`[i + m] - `as`[i + m / 2]) - v.toLong() * (m - m / 2).toLong()\nans = min(ans, up + down)\n}\nelse\n{\nvar l = a[i]\nvar r = v\nwhile (l + 1 < r)\n{\nv = (l + r) / 2\nvar p = binarySearch(a, i, i + m, v)\nif (p < 0)\n{\np = p.inv()\n}\nup = v.toLong() * (p - i).toLong() - (`as`[p] - `as`[i])\nif (up <= k)\n{\nl = v\n}\nelse\n{\nr = v\n}\n}\nv = l\nvar p = binarySearch(a, i, i + m, v)\nif (p < 0)\n{\np = p.inv()\n}\nup = v.toLong() * (p - i).toLong() - (`as`[p] - `as`[i])\nvar down = (`as`[i + m] - `as`[p]) - v.toLong() * (i + m - p).toLong()\nans = min(ans, up + down)\n}\n}\nout!!.print(ans)\n}\n@Throws(IOException::class)\ninternal fun scanInt():Int {\nreturn parseInt(scanString())\n}\n@Throws(IOException::class)\ninternal fun scanLong():Long {\nreturn parseLong(scanString())\n}\n@Throws(IOException::class)\ninternal fun scanString():String {\nwhile (tok == null || !tok!!.hasMoreTokens())\n{\ntok = StringTokenizer(`in`!!.readLine())\n}\nreturn tok!!.nextToken()\n}\n@JvmStatic fun main(args:Array) {\ntry\n{\n`in` = BufferedReader(InputStreamReader(System.`in`))\nout = PrintWriter(System.out)\nsolve()\n`in`!!.close()\nout!!.close()\n}\ncatch (e:Throwable) {\ne.printStackTrace()\nexit(1)\n}\n}\n}\nfun main() {\nF.main(arrayOf())\n}", "src_uid": "9c3abb6508c16d906d16f70acaf155ff"} {"source_code": "fun main() {\n var (a, b) = readLine()!!.split(' ').map { it.toInt() }\n var flag = false\n var colors = charArrayOf('W', 'B', 'G')\n (1..a).forEach {\n var str = readLine()!!\n if (str.contains('C') || str.contains('M') || str.contains('Y')) {\n flag = true\n }\n }\n if (flag) {\n println(\"#Color\")\n } else {\n println(\"#Black&White\")\n }\n\n\n}\n\n", "src_uid": "19c311c02380f9a73cd477e4fde27454"} {"source_code": "fun main(args:Array){\n println(stairsOrElevator())\n }\n\nfun stairsOrElevator():String{\n val s =readLine()?.split(\" \")\n val timeStairs = (Math.abs(Integer.parseInt(s!![0])- Integer.parseInt(s[1])))*Integer.parseInt(s[3])\n val timeElevator = (Math.abs(Integer.parseInt(s[0])- Integer.parseInt(s[1]))*Integer.parseInt(s[4]))+((Math.abs(Integer.parseInt(s[2])- Integer.parseInt(s[0])) * Integer.parseInt(s[4]))+(3*Integer.parseInt(s[5])))\n\n return if (timeElevator > timeStairs){\n \"NO\"\n } else {\n \"YES\"\n }\n}", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca"} {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashSet\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val b1 = ir.next()\n val b2 = ir.next()\n val e1 = ir.next()\n val e2 = ir.next()\n val arr1 = getArr(CharArray(3), b1, b2)\n val arr2 = getArr(CharArray(3), e1, e2)\n val arr3 = CharArray(6)\n arr3[0] = arr1[0]\n arr3[1] = arr1[1]\n arr3[2] = arr1[2]\n arr3[3] = arr1[0]\n arr3[4] = arr1[1]\n arr3[5] = arr1[2]\n\n for (i in 2..5)\n if (arr3[i - 2] == arr2[0] && arr3[i - 1] == arr2[1] && arr3[i] == arr2[2]) {\n pw.print(\"YES\")\n return\n }\n\n pw.print(\"NO\")\n\n}\n\nfun getArr(b: CharArray, b1: String, b2: String): CharArray {\n if (b1[0] == 'X') {\n b[0] = b1[1]\n b[1] = b2[1]\n b[2] = b2[0]\n } else if (b1[1] == 'X') {\n b[0] = b2[1]\n b[1] = b2[0]\n b[2] = b1[0]\n } else if (b2[0] == 'X') {\n b[0] = b1[0]\n b[1] = b1[1]\n b[2] = b2[1]\n } else {\n b[0] = b2[0]\n b[1] = b1[0]\n b[2] = b1[1]\n }\n\n return b\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}", "src_uid": "46f051f58d626587a5ec449c27407771"} {"source_code": "//package avito\n\nfun main(args: Array) {\n val input = readLine()!!.toInt()\n if(input<=2){\n println(input)\n }else{\n println(1)\n }\n}", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d"} {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numAvailableStages, numRocketStages) = readInts()\n val availableStages = readLine()!!.toCharArray()\n availableStages.sort()\n var last = 'Z'\n var sol = 0\n var availableStagesPos = 0\n for(pos in 0 until numRocketStages) {\n while (availableStagesPos < numAvailableStages && availableStages[availableStagesPos] - 2 < last)\n availableStagesPos++\n if (availableStagesPos == numAvailableStages) return print(-1)\n last = availableStages[availableStagesPos]\n sol += last - 'a' + 1\n }\n print(sol)\n}", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313"} {"source_code": "import kotlin.math.min\n\nfun main() {\n val(n, k) = readLine()!!.split(' ').map { it.toInt() }\n val a = readLine()!!.split(' ').map { it.toInt() }\n\n var data = mutableMapOf>()\n\n for(i in 0 until n) {\n var v = a[i]\n var count = 0\n while(v > 0) {\n data.putIfAbsent(v, mutableListOf())\n data[v]!!.add(count)\n v /= 2\n count++\n }\n }\n\n var sol = 1e9.toInt()\n for(list in data.values) {\n if(list.size < k) continue;\n list.sort()\n var sum = 0\n for(i in 0 until k)\n sum += list[i]\n sol = min(sol, sum)\n }\n\n println(sol)\n}", "src_uid": "ed1a2ae733121af6486568e528fe2d84"} {"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n if (args.size > 0) System.setIn(FileInputStream(args[0]))\n val br = BufferedReader(InputStreamReader(System.`in`))\n val bw = BufferedWriter(OutputStreamWriter(System.out))\n\n var st = StringTokenizer(br.readLine())\n val a = st.nextToken().toInt()\n var b = st.nextToken().toInt()\n val arr = mutableListOf(b)\n while (a < b) {\n if (b and 1 == 0) {\n b /= 2\n } else {\n val pb = (b - 1) / 10\n if (b == (pb * 10) + 1) b = pb\n else break\n }\n arr.add(b)\n }\n if (a == b) {\n bw.write(\"YES\\n${arr.size}\\n\")\n bw.write(arr.reversed().joinToString(separator = \" \"))\n }\n else bw.write(\"NO\")\n bw.newLine()\n bw.flush()\n}\n", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3"} {"source_code": "import java.io.BufferedReader\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.max\nimport kotlin.math.min\n\nval MOD = 1_000_000_007\n\nclass Solver(stream: InputStream, private val out: java.io.PrintWriter) {\n fun solve() {\n val A = na(3).map{it.toLong()}\n val S = A.sum()\n val remain = max(\n max(0, A[0] - 2 * (A[1] + A[2]))\n , max(\n max(0, A[1] - 2 * (A[0] + A[2]))\n , max(0, A[2] - 2 * (A[0] + A[1]))\n )\n )\n out.println((S - remain) / 3)\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\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}", "src_uid": "bae7cbcde19114451b8712d6361d2b01"} {"source_code": "import java.util.Scanner\nimport kotlin.math.min\n\nfun main(args : Array) {\n\n val reader = Scanner(System.`in`)\n var a: Int = reader.nextInt()\n var b: Int = reader.nextInt()\n var x: Int = reader.nextInt()\n var y: Int = reader.nextInt()\n\n var d = gcd(x,y)\n x = x / d\n y = y / d\n\n var m = min(a/x, b/y)\n\n print(m*x)\n print(\" \")\n print(m*y)\n\n}\n\nfun gcd(a:Int, b: Int):Int{\n if(b==0){\n return a\n }\n else{\n return gcd(b,a%b)\n }\n}", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a"} {"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", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a"} {"source_code": "import java.util.*\n\nfun main(args: Array)\n{\n val reader=Scanner(System.`in`)\n val a=reader.nextInt()\n val b=reader.nextInt()\n val c=reader.nextInt()\n val d=reader.nextInt()\n var ac=max(a,c)\n var bd=max(b,d)\n if(ac>bd)\n println(\"Misha\")\n else if(acf)\n return e\n else\n return f\n}", "src_uid": "95b19d7569d6b70bd97d46a8541060d0"} {"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n val inputStream = System.`in`\n val outputStream = System.out\n val inp = Main.InputReader(inputStream)\n val out = PrintWriter(outputStream)\n val solver = Main.TaskA()\n solver.solve(inp, out)\n out.close()\n}\n\nclass Main {\n internal class TaskA {\n fun solve(inp: InputReader, out: PrintWriter) {\n var n = inp.nextInt()\n val l = arrayListOf()\n var d = 1\n while (n > 0)\n if (d > n) {\n l[l.size - 1] += n\n break\n } else {\n l.add(d)\n n -= d\n d++\n }\n out.println(l.size)\n l.forEach { el -> out.print(\"$el \") }\n }\n }\n\n internal class InputReader(stream: InputStream) {\n private var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return next().toLong()\n }\n }\n}\n", "src_uid": "356a7bcebbbd354c268cddbb5454d5fc"} {"source_code": "import kotlin.math.max\nimport kotlin.math.min\n \nfun readIntList() = readLine()!!.split(' ').map(String::toInt).toMutableList()\nfun readInt() = readLine()!!.toInt()\n \n \nvar rects = mutableListOf()\n \nfun main(args: Array) {\n \n var (x1, y1, x2, y2) = readIntList()\n var (x3, y3, x4, y4) = readIntList()\n val (x5, y5, x6, y6) = readIntList()\n \n \n if (!(x1 > x4 || y1 > y4 || x2 < x3 || y2 < y3)) {\n \n x3 = max(x1, x3)\n y3 = max(y1, y3)\n x4 = min(x2, x4)\n y4 = min(y2, y4)\n \n \n var rect = Rect(x1, y1, x2, y3)\n rects.add(rect)\n y1 = y3\n \n \n rect = Rect(x1, y4, x2, y2)\n rects.add(rect)\n y2 = y4\n \n \n rect = Rect(x1, y1, x3, y2)\n rects.add(rect)\n x1 = x3\n \n \n rect = Rect(x4, y1, x2, y2)\n rects.add(rect)\n x2 = x4\n \n \n// if (x2 > x1 || y2 > y1) {\n// rect = Rect(x1, y1, x2, y2)\n// rects.add(rect)\n// }\n }else{\n val rect = Rect(x1, y1, x2, y2)\n rects.add(rect)\n }\n \n rects.forEach { elem ->\n val bool1 = !(x5 <= elem.x1 && elem.x2 <= x6 && y5 <= elem.y1 && elem.y2 <= y6)\n val bool2 = elem.x2 > elem.x1 && elem.y2 > elem.y1\n if (bool1 && bool2) {\n println(\"YES\")\n return\n }\n }\n println(\"NO\")\n \n \n}\n \nclass Rect(\n var x1: Int,\n var y1: Int,\n var x2: Int,\n var y2: Int\n)", "src_uid": "05c90c1d75d76a522241af6bb6af7781"} {"source_code": "fun main(args:Array) {\n val a = readLine()!!.trim().split(\" \").asSequence().sumBy { s -> s.toInt() }\n val b = readLine()!!.trim().split(\" \").asSequence().sumBy { s -> s.toInt() }\n val n = readLine()!!.toInt();\n if ((a + 4) / 5 + (b + 9) / 10 <= n) print(\"YES\") else print(\"NO\")\n}\n\n", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e"} {"source_code": "fun main() {\n val names = arrayOf(\"Danil\", \"Olya\", \"Slava\", \"Ann\", \"Nikita\")\n val text = readLine()!!\n var found = 0\n for (it in names) {\n var start = text.indexOf(it)\n if (start != -1) {\n found ++\n start = text.indexOf(it, start + 1)\n if (start != -1) found++\n }\n if (found > 1) break\n }\n if (found == 1) print(\"YES\") else print(\"NO\")\n}", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710"} {"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 xor = nl()\n val sum = nl()\n if (xor > sum || (sum - xor) % 2 == 1L) {\n out.println(-1)\n return\n }\n\n val A = LongArray(3)\n val shift = sum - xor\n for (i in 0 until 60) {\n if ((shift shr i + 1 and 1L) == 1L) {\n val v = 1L shl i\n A[0] = A[0] xor v\n A[1] = A[1] xor v\n }\n }\n\n for (i in 0 until 60) {\n if ((xor shr i and 1L) == 1L) {\n if ((A[0] shr i and 1L) == 1L) {\n A[2] = A[2] or (1L shl i)\n } else {\n A[0] = A[0] or (1L shl i)\n }\n }\n }\n\n val ans = A.filter { it != 0L }\n if (ans.isEmpty()) {\n out.println(0)\n } else {\n out.println(ans.size)\n out.println(ans.joinToString(\" \"))\n }\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n private val isDebug = try {\n // なんか本番でエラーでる\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}", "src_uid": "490f23ced6c43f9e12f1bcbecbb14904"} {"source_code": "fun main() {\n val chars = \"ABCD\"\n val lengths = IntArray(4)\n var minLengthPos = 0\n var maxLengthPos = 0\n for (pos in 0 until 4) {\n lengths[pos] = readLine()!!.length - 2\n if (lengths[pos] < lengths[minLengthPos]) minLengthPos = pos\n if (lengths[pos] > lengths[maxLengthPos]) maxLengthPos = pos\n }\n var minCounter = 0\n var maxCounter = 0\n for (pos in 0 until 4) {\n if (lengths[pos] / lengths[minLengthPos] < 2) minCounter++\n if (lengths[maxLengthPos] / lengths[pos] < 2) maxCounter++\n }\n if (minCounter < 2 && maxCounter >= 2) return print(chars[minLengthPos])\n if (maxCounter < 2 && minCounter >= 2) return print(chars[maxLengthPos])\n print('C')\n}", "src_uid": "30725e340dc07f552f0cce359af226a4"} {"source_code": "import kotlin.math.min\n\nfun main() {\n val s = readLine()!!\n val letters = mutableMapOf()\n for (c in s) {\n letters.compute(c) { _, v -> if (v == null) 1 else v+1 }\n }\n val tn = (letters['n'] ?: 0)\n\n val n = if (tn <= 3) tn/3 else (tn-1)/2\n val e = (letters['e'] ?: 0) / 3\n val t = letters['t'] ?: 0\n val i = letters['i'] ?: 0\n\n val words = min(n, min(e, min(t, i)))\n println(words)\n}\n\n\n", "src_uid": "bb433cdb8299afcf46cb2797cbfbf724"} {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val n = readInt()\n var left = 1L\n var right = 1L\n repeat(n) {\n right = left - right\n left *= 3\n if (right >= 1000000007) {\n right %= 1000000007\n while (left - 1000000007 >= right)\n left -= 1000000007\n }\n }\n print(right)\n}", "src_uid": "77627cc366a22e38da412c3231ac91a8"} {"source_code": "import java.io.*\nimport java.util.*\n\nfun > max(a: T, b: T): T = if (b > a) b else a\nfun > min(a: T, b: T): T = if (b < a) b else a\nfun Number.isEven(): Boolean = if (this.toInt() and 1 == 0) true else false\nfun Number.isOdd(): Boolean = !this.isEven()\n\ntailrec fun gcd(a: Int, b: Int): Int {\n if (a == 0) return b\n else return gcd(b % a, a)\n}\n\nfun lcm(a: Int, b: Int): Int {\n return (a / gcd(a, b)) * b\n}\n\nfun main(args: Array) {\n if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))\n val br = BufferedReader(InputStreamReader(System.`in`))\n val bw = BufferedWriter(OutputStreamWriter(System.out))\n\n var st = StringTokenizer(br.readLine())\n val n = st.nextToken().toInt()\n val arr = IntArray(n + 1)\n st = StringTokenizer(br.readLine())\n for (i in 1..n) {\n arr[i] = st.nextToken().toInt()\n }\n var answer = 1\n for (i in 1..n) {\n var loop = false\n val a = i\n var b = a\n for (j in 1..n) {\n b = arr[b]\n if (b == a) {\n loop = true\n if (j.isEven()) answer = lcm(answer, j/2)\n else answer = lcm(answer, j)\n break\n }\n }\n if (!loop) {\n answer = -1\n break\n }\n }\n bw.write(\"$answer\")\n bw.newLine()\n bw.flush()\n}\n", "src_uid": "149221131a978298ac56b58438df46c9"} {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStreamReader\nimport java.util.*\n\n\nfun main(args: Array) {\n TaskC().solve()\n}\n\nabstract class Solver {\n internal val scanner = MyScanner()\n abstract fun solve()\n}\n\nclass TaskC : Solver() {\n override fun solve() {\n val mod = 998244353\n val n = scanner.nextInt()\n val m = scanner.nextLong()\n val k = scanner.nextInt()\n\n var cnk = Array(n + 1) { IntArray(n + 1) }\n\n cnk[0][0] = 1\n for (i in 1..n) {\n cnk[i][0] = 1\n cnk[i][i] = 1\n for (j in 1 until n) {\n cnk[i][j] = (cnk[i - 1][j] + cnk[i - 1][j - 1]) % mod\n }\n }\n\n var ans = cnk[n - 1][k].toLong()\n ans = (ans *m) % mod\n for (i in 1..k){\n ans = (ans* (m-1))% mod\n }\n System.out.print(ans)\n\n\n }\n\n}\n\ninternal class MyScanner {\n private val `in` = BufferedReader(InputStreamReader(System.`in`))\n private var buffer: Array? = null\n private var pos = 0\n\n @Throws(IOException::class)\n fun nextInt(): Int {\n if (buffer == null) {\n buffer = `in`.readLine().split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n pos = 0\n }\n if (buffer!!.size <= pos) {\n buffer = `in`.readLine().split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n pos = 0\n }\n pos++\n return Integer.parseInt(buffer!![pos - 1])\n }\n\n @Throws(IOException::class)\n fun nextLong(): Long {\n if (buffer == null) {\n buffer = `in`.readLine().split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n pos = 0\n }\n if (buffer!!.size <= pos) {\n buffer = `in`.readLine().split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n pos = 0\n }\n pos++\n return (buffer!![pos - 1]).toLong()\n }\n\n @Throws(IOException::class)\n fun nextString(): String {\n if (buffer == null) {\n buffer = `in`.readLine().split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n pos = 0\n }\n if (buffer!!.size <= pos) {\n buffer = `in`.readLine().split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n pos = 0\n }\n pos++\n return buffer!![pos - 1]\n }\n\n @Throws(IOException::class)\n fun getIntList(n: Int): List {\n val result = mutableListOf()\n for (i in 0 until n)\n result.add(nextInt())\n return result\n }\n\n @Throws(IOException::class)\n fun getIntArray(n: Int): IntArray {\n val result = IntArray(n)\n for (i in 0 until n)\n result[i] = nextInt()\n return result\n }\n\n @Throws(IOException::class)\n fun getLongList(n: Int): List {\n val result = mutableListOf()\n for (i in 0 until n)\n result.add(nextLong())\n return result\n }\n\n @Throws(IOException::class)\n fun getLongArray(n: Int): LongArray {\n val result = LongArray(n)\n for (i in 0 until n)\n result[i] = nextLong()\n return result\n }\n\n @Throws(IOException::class)\n fun getStringList(n: Int): List {\n val result = mutableListOf()\n for (i in 0 until n)\n result.add(nextString())\n return result\n }\n\n}\n", "src_uid": "b2b9bee53e425fab1aa4d5468b9e578b"} {"source_code": "import kotlin.math.min\n\nfun main() {\n fun readLongs(): List {\n return readLine()!!.split(\" \").map(String::toLong)\n }\n\n val (n, a, b, c) = readLongs()\n when (n % 4) {\n 0L -> print(0)\n 1L -> print(min(3 * a, min(a + b, c)))\n 2L -> print(min(2 * a, min(b, 2*c)))\n 3L -> print(min(a, min(b+c, 3*c)))\n }\n}", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8"} {"source_code": "fun main(args: Array) {\n var s = readLine()!!\n var ok = false\n var n = s.length\n (0..n).forEach {\n i -> (i + 1..s.length).forEach {\n j -> ok = ok.or((s.substring(0, i) + s.substring(j)) == \"CODEFORCES\")\n }\n }\n println(if (ok) \"YES\" else \"NO\")\n}\n", "src_uid": "bda4b15827c94b526643dfefc4bc36e7"} {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n val forms = ArrayList>()\n (0 until n).forEach{readLine()!!.split(' ').map { it.toInt() }.let { forms.add(Pair(it[0], it[1])) }}\n\n var count = 0\n for (home in forms){\n count += forms.count{\n it != home && it.first == home.second\n }\n }\n println(count)\n}", "src_uid": "745f81dcb4f23254bf6602f9f389771b"} {"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() }", "src_uid": "c4551f66a781b174f95865fa254ca972"} {"source_code": "import java.util.Scanner\n\nfun main(args : Array) {\n\n //val reader = Scanner(System.`in`)\n //var n: Int = reader.nextInt()\n // var m: Int = reader.nextInt()\n\n val n = readLine()!!\n val m = readLine()!!\n var a: Int = n.toInt()\n var b: Int = m.toInt()\n\n var list1: MutableList = mutableListOf()\n var list2: MutableList = mutableListOf()\n\n\n if (n.length != m.length) println(\"WRONG_ANSWER\")\n else if(n.length == 1 && m.length == 1 && n!= m ) println(\"WRONG_ANSWER\")\n else if (n.length == 1 && m.length == 1 && n == m ) println(\"OK\")\n else if (a > 0 && b > 0) {\n while (a > 0) {\n list1.add(a % 10)\n a = a / 10\n }\n list1.sort()\n if (list1[0] == 0) {\n for (i in 1..list1.size - 1) {\n if (list1[i] != 0) {\n list1[0] = list1[i]\n list1[i] = 0\n break\n }\n }\n }\n\n while (b > 0) {\n list2.add(b % 10)\n b = b / 10\n }\n list2.reverse()\n\n if (list1 == list2) {\n println(\"OK\")\n } else {\n println(\"WRONG_ANSWER\")\n }\n }\n}\n\n", "src_uid": "d1e381b72a6c09a0723cfe72c0917372"} {"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 P = ni()\n for (i in 1 .. 60) {\n val X = N - i * P\n if (X <= 0) continue\n val mn = Integer.bitCount(X)\n val mx = X\n if (i in mn .. mx) {\n out.println(i)\n return\n }\n }\n out.println(-1)\n }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n 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", "src_uid": "9e86d87ce5a75c6a982894af84eb4ba8"} {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport java.util.PriorityQueue\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n// val startTime = System.nanoTime()\n\n val numCases = 1//readInt()\n case@ for(case in 1..numCases) {\n// print(\"Case #$case: \")\n\n val n = readInt()\n val m = readInt()\n val q = readInt()\n\n val U = IntArray(m)\n val V = IntArray(m) {\n U[it] = readInt()-1\n readInt()-1\n }\n\n val last = IntArray(m)\n val dsu = BipartiteDSU(n)\n\n var l2 = m-1\n dsu.persist()\n for(i in 0 until m) {\n if(!dsu.join(U[i], V[i], OPP)) {\n for(j in i+1 until m) last[j] = m\n l2 = i\n break\n }\n }\n dsu.rollback()\n\n fun rec(l1: Int, l2: Int, r1: Int, r2: Int) {\n if(l1 > l2) return\n val lm = (l1 + l2) / 2\n\n dsu.persist()\n\n for(i in l1 until lm) dsu.join(U[i], V[i], OPP)\n\n dsu.persist()\n\n var rm = r2\n val lim = max(lm-1, r1)\n while(rm > lim && dsu.join(U[rm], V[rm], OPP)) rm--\n last[lm] = rm\n\n dsu.rollback()\n\n dsu.join(U[lm], V[lm], OPP)\n rec(lm+1, l2, rm, r2)\n\n dsu.rollback()\n\n for(i in rm+1..r2) dsu.join(U[i], V[i], OPP)\n rec(l1, lm-1, r1, rm)\n }\n\n rec(0, l2, -1, m-1)\n\n repeat(q) {\n val l = readInt()-1\n val r = readInt()-1\n\n val ans = r < last[l]\n println(if(ans) \"YES\" else \"NO\")\n }\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nclass Rollback(val arr: IntArray) {\n val ihist = IntList()\n val vhist = IntList()\n val save = IntList()\n\n operator fun get(i: Int) = arr[i]\n operator fun set(i: Int, v: Int) {\n ihist.add(i)\n vhist.add(arr[i])\n arr[i] = v\n }\n\n fun persist() {\n save.add(ihist.size)\n }\n\n fun rollback() {\n val p = save.pop()\n while(ihist.size > p) {\n arr[ihist.pop()] = vhist.pop()\n }\n }\n}\n\nconst val SYN: Byte = 1\nconst val OPP: Byte = 2\nconst val NOR: Byte = 3\n\nclass BipartiteDSU(n: Int) {\n private val id = Rollback(IntArray(n) { it })\n private val sz = Rollback(IntArray(n) { 1 })\n private val opp = Rollback(IntArray(n) { -1 })\n\n fun relation(u: Int, v: Int): Byte {\n val ru = root(u)\n val rv = root(v)\n return when {\n ru == rv -> SYN\n opp[ru].let { it != -1 && root(it) == rv } -> OPP\n else -> NOR\n }\n }\n\n fun join(u: Int, v: Int, r: Byte): Boolean {\n val ru = root(u)\n val rv = root(v)\n val cr = relation(ru, rv)\n when {\n cr == r -> return true\n cr != NOR -> return false\n else -> {\n if(r == SYN) join(ru, rv)\n else {\n when {\n opp[ru] != -1 -> join(opp[ru], rv)\n opp[rv] != -1 -> join(opp[rv], ru)\n else -> {\n opp[ru] = rv\n opp[rv] = ru\n }\n }\n }\n return true\n }\n }\n }\n\n tailrec fun root(v: Int): Int =\n if(id[v] == v) v else root(id[v])\n\n /** @return false if the two vertices are already joined, true if the join operation is successful */\n private fun join(u: Int, v: Int): Boolean {\n var ru = root(u)\n var rv = root(v)\n if(ru == rv) return false\n if(sz[ru] < sz[rv]) ru = rv.also { rv = ru }\n id[rv] = ru\n sz[ru] += sz[rv]\n if(opp[ru] != -1 && opp[rv] != -1) join(opp[ru], opp[rv])\n if(opp[rv] != -1) opp[ru] = opp[rv]\n return true\n }\n\n fun size(v: Int) = sz[root(v)]\n\n fun persist() {\n id.persist()\n sz.persist()\n opp.persist()\n }\n\n fun rollback() {\n id.rollback()\n sz.rollback()\n opp.rollback()\n }\n}\n\nclass IntList(initialCapacity: Int = 12) {\n private var _arr = IntArray(initialCapacity)\n private val capacity get() = _arr.size\n var size = 0\n private set\n inline val lastIndex get() = size - 1\n inline val indices get() = 0 until size\n\n constructor(copyFrom: IntArray): this(copyFrom.size) { copyFrom.copyInto(_arr); size = copyFrom.size }\n constructor(copyFrom: Collection): this(copyFrom.size) { _arr = copyFrom.toIntArray(); size = copyFrom.size }\n\n fun contentEquals(other: IntList): Boolean {\n return this === other || size == other.size && indices.all { this[it] == other[it] }\n }\n\n private fun grow(minCapacity: Int = 8) {\n val newCapacity = maxOf(minCapacity, capacity + (capacity shr 1))\n _arr = _arr.copyOf(newCapacity)\n }\n\n fun ensureCapacity(minCapacity: Int) { if(capacity < minCapacity) grow(minCapacity) }\n\n operator fun get(index: Int): Int {\n require(index in 0 until size)\n return _arr[index]\n }\n\n operator fun set(index: Int, value: Int) {\n require(index in 0 until size)\n _arr[index] = value\n }\n\n fun add(value: Int) {\n if(size == capacity) grow()\n _arr[size++] = value\n }\n\n fun addAll(list: IntList) {\n ensureCapacity(size + list.size)\n list._arr.copyInto(_arr, size, 0, list.size)\n size += list.size\n }\n\n fun add(index: Int, element: Int) {\n if(size == capacity) grow()\n _arr.copyInto(_arr, index + 1, index, size)\n size++\n set(index, element)\n }\n\n fun clear() { size = 0 }\n\n fun removeAt(index: Int): Int {\n val e = get(index)\n _arr.copyInto(_arr, index, index + 1, size)\n size--\n return e\n }\n\n fun indexOf(e: Int): Int {\n for(i in 0 until size) if(this[i] == e) return i\n return -1\n }\n\n fun remove(e: Int): Boolean {\n val i = indexOf(e)\n if(i == -1) return false\n removeAt(i)\n return true\n }\n\n operator fun iterator() = object: IntIterator() {\n private var pos = 0\n override fun hasNext() = pos < size\n override fun nextInt() = get(pos++)\n }\n\n inline fun isEmpty() = size == 0\n inline fun isNotEmpty() = size != 0\n\n fun pop() = _arr[--size]\n\n fun popToSize(s: Int) {\n require(s >= 0)\n if(s < size) size = s\n }\n\n fun swap(i: Int, j: Int) { val t = this[i]; this[i] = this[j]; this[j] = t }\n fun reverse() {\n for(i in 0 until size / 2) swap(i, lastIndex - i)\n }\n\n fun shuffle(rnd: Random = random) { for(i in lastIndex downTo 1) swap(i, rnd.nextInt(i+1)) }\n fun sort() { shuffle(); _arr._sort(0, size) }\n fun sortDescending() { sort(); reverse() }\n\n fun joinToString(separator: CharSequence) = if(size == 0) \"\" else let {\n buildString {\n append(it[0])\n for (i in 1 until size) {\n append(separator).append(it[i])\n }\n }\n }\n\n override fun toString() = \"[\" + joinToString(\", \") + \"]\"\n\n fun toIntArray() = _arr.copyOf(size)\n fun toList() = List(size, ::get)\n\n inline fun first() = get(0)\n inline fun last() = get(lastIndex)\n}\n\ninline fun IntList(size: Int, init: (Int) -> Int) = IntList(size).apply {\n for(i in 0 until size) { add(init(i)) }\n}\ninline fun IntArray.toIntList() = IntList(this)\ninline fun Collection.toIntList() = IntList(this)\ninline fun intListOf(vararg values: Int) = IntList(values)\n\nfun IntList.max() = (1 until size).fold(this[0]) { acc, i -> max(acc, this[i]) }\nfun IntList.min() = (1 until size).fold(this[0]) { acc, i -> min(acc, this[i]) }\nfun IntList.getOrNull(i: Int) = if(i in indices) get(i) else null\ninline fun IntList.count(predicate: (Int) -> Boolean) = indices.count { predicate(this[it]) }\nfun IntList.copyOf() = IntList(size, ::get)\n\n/** IO */\n//const val PATH = \"src/main/resources/\"\n//@JvmField val INPUT = File(PATH + \"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(PATH + \"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\nconst val _BUFFER_SIZE = 1 shl 16\n@JvmField val _buffer = ByteArray(_BUFFER_SIZE)\n@JvmField var _bufferPt = 0\n@JvmField var _bytesRead = 0\n\ntailrec fun readChar(): Char {\n if(_bufferPt == _bytesRead) {\n _bufferPt = 0\n _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)\n }\n return if(_bytesRead < 0) Char.MIN_VALUE\n else {\n val c = _buffer[_bufferPt++].toChar()\n if (c == '\\r') readChar()\n else c\n }\n}\n\n/** @param skipNext Whether to skip the next character (usually whitespace), defaults to true */\nfun readCharArray(n: Int, skipNext: Boolean = true): CharArray {\n val res = CharArray(n) { readChar() }\n if(skipNext) readChar()\n return res\n}\n\nfun readLine(): String? {\n var c = readChar()\n return if(c == Char.MIN_VALUE) null\n else buildString {\n while(c != '\\n' && c != Char.MIN_VALUE) {\n append(c)\n c = readChar()\n }\n }\n}\nfun readLn() = readLine()!!\n\nfun read() = buildString {\n var c = readChar()\n while(c <= ' ') {\n if(c == Char.MIN_VALUE) return@buildString\n c = readChar()\n }\n do {\n append(c)\n c = readChar()\n } while(c > ' ')\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** sort overrides to avoid quicksort attacks */\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.sort() { shuffle(random); _sort() }\nfun IntArray.sortDescending() { shuffle(random); _sortDescending() }\n\nfun LongArray.sort() { shuffle(random); _sort() }\nfun LongArray.sortDescending() { shuffle(random); _sortDescending() }\n\nfun DoubleArray.sort() { shuffle(random); _sort() }\nfun DoubleArray.sortDescending() { shuffle(random); _sortDescending() }\n\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\n// import preserving junk function\n@Suppress(\"NonAsciiCharacters\") fun 雪花飄飄北風嘯嘯天地一片蒼茫() { 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 }", "src_uid": "57ad95bb938906f7550f7eb6422130f7"} {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readLong() = readLine()!!.toLong()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n\n val numCards = readInt()\n val soldier1 = readInts().toMutableList()\n val soldier2 = readInts().toMutableList()\n var pos = 0\n while (++pos < 1000 && pos < soldier1.size && pos < soldier2.size) {\n if (soldier1[pos] > soldier2[pos]) {\n soldier1.add(soldier2[pos])\n soldier1.add(soldier1[pos])\n } else {\n soldier2.add(soldier1[pos])\n soldier2.add(soldier2[pos])\n }\n }\n print(\n when (pos) {\n 1000 -> -1\n soldier1.size -> \"${pos - 1} 2\"\n else -> \"${pos - 1} 1\"\n }\n )\n}", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e"} {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n val m = scanner.nextInt()\n\n if (m == 1 || n == 1) {\n println(\"Akshat\")\n return\n }\n val min = Math.min(n, m)\n if(min%2==0) {\n println(\"Malvika\")\n } else {\n println(\"Akshat\")\n }\n}", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4"} {"source_code": "import java.util.*\n \nfun main(args: Array){\n //val ( n, m ) = readLine()!!.split(' ').map(String::toInt)\n var s = readLine()!!\n print( if( s[0] >= '5' && s[0] != '9' ) '9' - s[0] else s[0] )\n s = s.removeRange(0, 1)\n for( i in s ){\n print( if ( i >= '5' ) '9' - i else i )\n }\n}", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61"} {"source_code": "/* https://codeforces.com/problemset/problem/959/A */\n\nfun main() {\n val initialNumber = readLine()!!.toInt()\n val winner = if (initialNumber % 2 == 0) \"Mahmoud\" else \"Ehab\"\n println(winner)\n}", "src_uid": "5e74750f44142624e6da41d4b35beb9a"} {"source_code": "fun main() {\n val s = \"K\" + readLine()!! + \"V\"\n var answer = 0\n var addend = 0\n for (j in 0..s.length - 2) {\n if (s.substring(j, j + 2) == \"VK\") {\n answer++\n }\n if (j <= s.length - 3 && (s.substring(j, j + 3) == \"VVV\" || s.substring(j, j + 3) == (\"K\" + \"KK\"))) {\n addend = 1\n }\n }\n println(answer + addend)\n}", "src_uid": "578bae0fe6634882227ac371ebb38fc9"} {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextLong()\n if (n % 2 == 0L) {\n println(n / 2)\n } else {\n var i = 2L\n while (i * i <= n) {\n if (n % i == 0L) {\n println((n - i) / 2 + 1)\n return\n }\n i++\n }\n println(1)\n }\n}", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6"} {"source_code": "import java.io.PrintWriter\r\nimport java.util.StringTokenizer\r\nimport java.io.BufferedWriter\r\nimport java.io.OutputStreamWriter\r\nimport kotlin.math.*\r\nimport kotlin.random.*\r\nimport kotlin.collections.*\r\n\r\nprivate val INPUT = System.`in`\r\nprivate val OUTPUT = System.out\r\n\r\nprivate val bufferedReader = INPUT.bufferedReader()\r\nprivate val outputWriter = BufferedWriter( OutputStreamWriter(OUTPUT));\r\nprivate fun readLn() = bufferedReader.readLine()!!\r\n\r\nprivate fun readList() = readLn().split(' ')\r\nprivate var tokenizer = StringTokenizer(\"\")\r\nprivate fun read(): String {\r\n while(tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(readLn(), \" \")\r\n return tokenizer.nextToken()\r\n}\r\n\r\nprivate fun readInt() = read().toInt()\r\nprivate fun readLong() = read().toLong()\r\nprivate fun readDouble() = read().toDouble()\r\n\r\nprivate fun readIntList() = readList().map { it.toInt() }\r\nprivate fun readLongList() = readList().map { it.toLong() }\r\nprivate fun readDoubleList() = readList().map { it.toDouble() }\r\n\r\nprivate fun readIntArray(n: Int = 0) =\r\n if (n == 0) readList().run { IntArray(size) { get(it).toInt() } } else IntArray(n) { readInt() }\r\n\r\nprivate fun readLongArray(n: Int = 0) =\r\n if (n == 0) readList().run { LongArray(size) { get(it).toLong() } } else LongArray(n) { readLong() }\r\n\r\nprivate fun readDoubleArray(n: Int = 0) =\r\n if (n == 0) readList().run { DoubleArray(size) { get(it).toDouble() } } else DoubleArray(n) { readDouble() }\r\n\r\n\r\nprivate fun Int.modPositive(other: Int): Int = if (this % other < 0) ((this % other) + other) else (this % other)\r\n\r\n\r\n\r\nfun main() {\r\n var cases = readInt()\r\n repeat(cases) {\r\n var sum = 0\r\n for(i in 0 until 4) {\r\n sum += readInt()\r\n }\r\n if(sum == 0) {\r\n println(0)\r\n } else if(sum == 4) {\r\n println(2)\r\n } else {\r\n println(1)\r\n }\r\n }\r\n outputWriter.close()\r\n}\r\n\r\n", "src_uid": "7336b8becd2438f0439240ee8f9610ec"} {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.abs\nimport kotlin.math.ceil\nimport kotlin.math.min\nimport kotlin.math.sqrt\n\n\nfun main() {\n val out = PrintWriter(System.out, false)\n val bf = BufferedReader(InputStreamReader(System.`in`))\n var stok = StringTokenizer(\"\")\n fun read(): String {\n while (!stok.hasMoreTokens()) stok = StringTokenizer(bf.readLine())\n return stok.nextToken()\n }\n fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)\n fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b\n fun solve() {\n val a = read().toLong()\n val b = read().toLong()\n fun mceil(u: Long, v: Long) = ((u + v - 1) / v) * v\n var ans = lcm(a, b) to 0L\n val g = abs(a - b)\n for (i in 1..ceil(sqrt(g.toDouble())).toInt()) {\n if (abs(a - b) % i != 0L) continue\n val u = lcm(mceil(a, i.toLong()), mceil(b, i.toLong())) to mceil(a, i.toLong()) - a\n val v = lcm(mceil(a, g / i), mceil(b, g / i)) to mceil(a, g / i) - a\n ans = minOf(ans, u, v, compareBy({it.first}, {it.second}))\n }\n out.println(ans.second)\n }\n\n solve()\n out.flush()\n}\n\n\n", "src_uid": "414149fadebe25ab6097fc67663177c3"} {"source_code": "import java.util.*\n\nfun main() {\n val (n, k) = readInts()\n\n val s = readLn()\n\n val S = mutableSetOf()\n\n val queue = ArrayDeque()\n queue.add(s)\n\n var totalCost = 0\n\n fun String.successors() = indices.asSequence().map { del ->\n filterIndexed { index, _ -> index != del }\n }.distinct()\n\n while(S.size < k && queue.isNotEmpty()) {\n val curr = queue.remove()\n if(!S.add(curr)) continue\n totalCost += n - curr.length\n queue.addAll(curr.successors())\n }\n\n println(if(S.size < k) -1 else totalCost)\n\n}\n\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\n// helper for competitive programming; faster at printing many lines than repeated println calls\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n fun println() { sb.append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit) { Output().apply(block).nowPrint() }", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b"} {"source_code": "fun lucky(c: Char) : Boolean = c == '4' || c == '7'\n\nfun main() {\n val n = readLine()!!.count { c -> lucky(c) }\n println( if (n.toString().all { c -> lucky(c) }) \"YES\" else \"NO\" )\n}\n", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1"} {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashSet\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val n: Int = ir.nextInt()\n val h: Int = ir.nextInt()\n val m: Int = ir.nextInt()\n val a = IntArray(n)\n var total = 0\n\n repeat(n) {\n a[it] = h\n }\n\n repeat(m) {\n val l = ir.nextInt() - 1\n val r = ir.nextInt() - 1\n val x = ir.nextInt()\n\n for (i in l..r)\n a[i] = Math.min(x, a[i])\n }\n\n repeat(n) {\n total += (a[it] * a[it])\n }\n\n pw.print(total)\n\n}\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}", "src_uid": "f22b6dab443f63fb8d2d288b702f20ad"} {"source_code": "import java.util.*\n\ndata class ArrayViewer(val pos: Int, val array: IntArray) {\n\n fun empty() = pos >= array.size\n fun head() = array[pos]\n fun tail() = ArrayViewer(pos + 1, array)\n\n}\n\nfun IntArray.viewer() = ArrayViewer(0, this)\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n\n val a = nextLine()!!.map { it.toInt() - '0'.toInt() }.toIntArray()\n val b = nextLine()!!.map { it.toInt() - '0'.toInt() }.toIntArray()\n\n val counts = countDigits(a)\n\n if (a.size < b.size) {\n print(maxPossible(counts).fold(\"\") { str, digit ->\n str + digit.toString() })\n return\n } else {\n print(makeLess(counts, b.viewer())!!.fold(\"\") {\n str, digit ->\n str + digit.toString() })\n }\n\n}\n\nfun makeLess(counter: IntArray, value: ArrayViewer): List? {\n if (value.empty()) {\n return List(0){0}\n }\n\n val digit = value.head()\n val rest = value.tail()\n\n if (counter[digit] != 0) {\n var counterWithout = counter\n counterWithout[digit] -= 1\n\n val other = makeLess(counterWithout, rest)\n if (other != null) {\n return List(1){digit} + other\n }\n\n counterWithout[digit] += 1\n }\n\n for (nextDigit in (digit - 1) downTo 0) {\n if (counter[nextDigit] != 0) {\n var counterWithout = counter\n counterWithout[nextDigit] -= 1\n\n val other = maxPossible(counterWithout)\n return List(1){nextDigit} + other\n }\n }\n\n return null\n\n}\n\nfun maxPossible(counter: IntArray): List {\n var c = List(0) {0}\n\n for (digit in 9 downTo 0) {\n for (i in 1..counter[digit]) {\n c += digit\n }\n }\n\n return c\n}\n\nfun countDigits(array: IntArray): IntArray {\n var counter = IntArray(10){0}\n\n for (digit in array) {\n counter[digit] += 1\n }\n\n return counter\n}\n", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44"} {"source_code": "fun main(args: Array) {\n val a = Array(3) {readLine()!!}\n println(listOf(\"ABC\", \"ACB\", \"BAC\", \"BCA\", \"CAB\", \"CBA\").filter {\n s -> a.filter { x -> (s.indexOf(x[0]) > s.indexOf(x[2])) == (x[1] == '<')}.isEmpty()\n }.firstOrNull() ?: \"Impossible\")\n}\n", "src_uid": "97fd9123d0fb511da165b900afbde5dc"} {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val n = r.readLine()!!.toInt()\n val (n, time) = r.readLine()!!.split(\" \").map { it.toInt() }\n val t = r.readLine()!!.split(\" \").map { it.toInt() }\n var joke = (n-1)*2*5\n val leastTime = joke+t.sum()\n println(if (leastTime>time) -1 else joke/5+(time-leastTime)/5)\n}", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea"} {"source_code": "import java.io.*\nimport java.util.*\n\nfun main(args: Array) {\n val solver = Solver(System.`in`, System.out)\n solver.solve()\n solver.clear()\n}\n\nclass Solver(input: InputStream, output: OutputStream) {\n\n companion object {\n private const val MAX_N = (1e6 + 10).toInt()\n private const val INF = (1e9 + 7).toInt()\n private const val MOD = (1e9 + 7).toInt()\n private const val INF_F = 1e-6\n }\n\n private val reader = Reader(input)\n private val writer = Writer(output)\n\n fun solve() {\n val n = reader.nextInt()\n val a = reader.nextArrayInt(n)\n var ans = 0\n for (i in 1 until n) {\n when {\n a[i] == 2 && a[i - 1] == 3 || a[i] == 3 && a[i - 1] == 2 -> {\n writer.println(\"Infinite\")\n return\n }\n a[i] == 1 -> ans += if (a[i - 1] == 2) 3 else 4\n a[i] == 3 -> ans += 4\n a[i] == 2 -> {\n when {\n i == 1 -> ans += 3\n a[i - 2] == 2 -> ans += 3\n a[i - 2] == 3 -> ans += 2\n }\n }\n }\n }\n writer.println(\"Finite\")\n writer.println(ans)\n }\n\n fun clear() {\n writer.close()\n }\n\n private fun IntArray.gcd(): Int {\n var g = first()\n forEach { g = gcd(g, it) }\n return g\n }\n\n private fun LongArray.gcd(): Long {\n var g = first()\n forEach { g = gcd(g, it) }\n return g\n }\n\n private fun gcd(a: Int, b: Int): Int {\n return if (b == 0) a else gcd(b, a % b)\n }\n\n private fun gcd(a: Long, b: Long): Long {\n return if (b == 0L) a else gcd(b, a % b)\n }\n}\n\nclass Reader(input: InputStream) {\n private val reader = BufferedReader(InputStreamReader(BufferedInputStream(input)), 32768)\n private var tokenizer: StringTokenizer? = null\n\n fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt() = next().toInt()\n\n fun nextLong() = next().toLong()\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}\n\nclass Writer(output: OutputStream) {\n private val writer = PrintWriter(BufferedOutputStream(output))\n\n fun println() {\n writer.println()\n }\n\n fun println(t: T) {\n writer.println(t)\n }\n\n fun print(t: T) {\n writer.print(t)\n }\n\n fun printIntArray(array: IntArray) {\n array.forEach { writer.print(\"$it \") }\n writer.println()\n }\n\n fun printLongArray(array: LongArray) {\n array.forEach { writer.print(\"$it \") }\n writer.println()\n }\n\n fun printCharArray(array: CharArray) {\n array.forEach { writer.print(\"$it\") }\n writer.println()\n }\n\n fun close() {\n writer.close()\n }\n}", "src_uid": "6c8f028f655cc77b05ed89a668273702"} {"source_code": "import kotlin.math.abs\n\nfun main() {\n readLine()?.let {\n val string = it.split(\" \")\n checkMoney(\n k = string[0].toInt(),\n n = string[1].toInt(),\n w = string[2].toInt()\n )\n }\n}\n\nfun checkMoney(k: Int, n: Int, w: Int) {\n var sum = 0\n for (i in 1..w) {\n sum += i * k\n }\n val credit = n - sum\n println(if (credit < 0) abs(credit) else 0)\n}", "src_uid": "e87d9798107734a885fd8263e1431347"} {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n //val (n, t) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val book = r.readLine()!!.split(\" \").map { it.toLong() }\n val (n, a, b) = r.readLine()!!.split(\" \").map { it.toInt() }\n //val l1 = listOf(a..n-1)\n val l3 = List(n-a){a+it}\n //println(l3)\n //val l2 = listOf((n-b-1)..n-1)\n val l4 = List(b+1){n-b-1+it}\n //println(l4)\n var ans = 0\n for (i in l3){\n loop@for (j in l4){\n if (i==j){\n ans++\n break@loop\n }\n }\n }\n println(ans)\n}", "src_uid": "51a072916bff600922a77da0c4582180"} {"source_code": "import java.io.BufferedReader\r\nimport kotlin.math.min\r\n\r\nfun main() {\r\n fun modPow(n: Long, k: Int, mod: Long): Long {\r\n if (k == 0) {\r\n return 1L\r\n }\r\n var half = modPow(n, k shr 1, mod)\r\n half *= half\r\n if (k and 1 == 1) {\r\n half %= mod\r\n half *= n\r\n }\r\n return half % mod\r\n }\r\n\r\n\r\n val br = System.`in`.bufferedReader()\r\n val n = br.readInt()\r\n val m = br.readInt().toLong()\r\n\r\n val factorials = LongArray(n + 1) { 1L }\r\n for (x in 1..n) {\r\n factorials[x] = (x * factorials[x - 1]) % m\r\n }\r\n val inverseFactorials = LongArray(n + 1) { modPow(factorials[it], (m - 2L).toInt(), m) }\r\n fun bimnom(nC: Int, kC: Int, mod: Long): Long {\r\n var res = factorials[nC]\r\n res *= inverseFactorials[kC]\r\n res %= mod\r\n res *= inverseFactorials[nC - kC]\r\n return res % mod\r\n }\r\n\r\n\r\n val dp2 = LongArray(n) { modPow(2L, it, m) } //how many ways to manually turn on i + 1 computers in a row manually\r\n\r\n val dp = Array(n + 1) { LongArray(n + 1) }\r\n dp[0][0] = 1L\r\n for (i in 1..n) { // through the first i computers\r\n dp[i][i] = dp2[i - 1]\r\n for (j in (i - 1) downTo 0) { //with turning on j computers manually\r\n for (k in 1..min(j, i - 2)) {\r\n var l = (dp[i - k - 1][j - k] * dp2[k - 1]) % m\r\n l *= bimnom(j, k, m)\r\n l %= m\r\n dp[i][j] += l\r\n dp[i][j] %= m\r\n }\r\n }\r\n }\r\n var ans = 0L\r\n for (x in 1..n) {\r\n ans += dp[n][x]\r\n ans %= m\r\n }\r\n print(ans)\r\n}\r\n\r\nprivate const val SPACE_INT = ' '.toInt()\r\nprivate const val ZERO_INT = '0'.toInt()\r\nprivate const val NL_INT = '\\n'.toInt()\r\n\r\nprivate fun BufferedReader.readInt(): Int {\r\n var ret = read()\r\n while (ret <= SPACE_INT) {\r\n ret = read()\r\n }\r\n val neg = ret == '-'.toInt()\r\n if (neg) {\r\n ret = read()\r\n }\r\n ret -= ZERO_INT\r\n var read = read()\r\n while (read >= ZERO_INT) {\r\n ret *= 10\r\n ret += read - ZERO_INT\r\n read = read()\r\n }\r\n\r\n while (read <= SPACE_INT && read != -1 && read != NL_INT) {\r\n mark(1)\r\n read = read()\r\n }\r\n if (read > SPACE_INT) {\r\n reset()\r\n }\r\n return if (neg) -ret else ret\r\n}", "src_uid": "4f0e0d1deef0761a46b64de3eb98e774"} {"source_code": "import java.util.*\n\nfun main(args: Array) {\n with(Scanner(System.`in`)) {\n val p = nextInt()\n val y = nextInt()\n\n for (i in y downTo p+1) {\n val isPrime = fun(x: Int): Boolean {\n var j = 2\n while (j*j<=y && j<=p) {\n if (x%j == 0) return false\n j++\n }\n return true\n }\n if (isPrime(i)) {\n println(i)\n return\n }\n }\n println(-1)\n }\n}\n", "src_uid": "b533203f488fa4caf105f3f46dd5844d"} {"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}", "src_uid": "ca65e023be092b2ce25599f52acc1a67"} {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (w1, h1, w2, h2) = readInts()\n var sol = w1 + 2\n sol += 2 * h1\n sol += w1 + 2 - w2\n sol += 2 * (h2 - 1)\n sol += w2 + 2\n print(sol)\n}", "src_uid": "b5d44e0041053c996938aadd1b3865f6"} {"source_code": "import kotlin.math.*\n\nfun main(arg: Array){\n\tval (n, m, a, b) = readLine().toString().split(\" \").map {x -> x.toLong()}\n\tval nrem = n.rem(m)\n\tval deltaC = (m - nrem) * a\n\tval deltaD = nrem * b\n\tprintln(min(deltaC,deltaD))\n}\n", "src_uid": "c05d753b35545176ad468b99ff13aa39"} {"source_code": "import java.lang.Math.sqrt\nimport java.util.*\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n val a: Long = input.nextLong()\n var b: Long = input.nextLong()\n b -= 1\n val array1 = ArrayList()\n val array2 = ArrayList()\n val sqrt = sqrt(a.toDouble())\n for(i in 1..sqrt.toLong()) {\n if(a % i == 0L) {\n if(sqrt == i.toDouble()) {\n array1.add(i)\n continue\n }\n array1.add(i)\n if(a != 1L)\n array2.add(a / i)\n }\n }\n if(b >= array1.size) {\n b -= (array1.size)\n if(b < array2.size) {\n b = array2.size - 1 - b\n print(array2[b.toInt()])\n return\n }\n } else {\n print(array1[b.toInt()])\n return\n }\n print(-1)\n}\n", "src_uid": "6ba39b428a2d47b7d199879185797ffb"} {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\n\nimport java.io.PrintWriter\nimport java.lang.StringBuilder\nimport java.math.RoundingMode\nimport java.util.*\nimport kotlin.math.*\nimport kotlin.random.*\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 T = 1\n for (_t in 0 until T) {\n val n = readInt()\n val s = read()\n var res = Array(n, {0})\n var pre = 0\n for (i in 0 until n) {\n if (s[i].toInt() - 'a'.toInt() >= pre) {\n pre = s[i].toInt() - 'a'.toInt()\n res[i] = 1\n }\n }\n var tmp = 0\n var flag = 1\n for (i in 0 until n) {\n if (res[i] == 0) {\n if (tmp > s[i].toInt() - 'a'.toInt()) {\n flag = 0\n break\n } else {\n tmp = s[i].toInt() - 'a'.toInt()\n }\n }\n }\n if (flag == 1) {\n println(\"YES\")\n for (i in 0 until n) print(res[i])\n } else {\n println(\"NO\")\n }\n }\n}\n\ndata class Pos(val x: Int, val y: Int) {\n operator fun plus(b: Pos) = Pos(x + b.x, y + b.y)\n}\n\n/** IO code start */\n//@JvmField val INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}", "src_uid": "9bd31827cda83eacfcf5e46cdeaabe2b"} {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n\n fun isPrime(int: Int):Boolean = !(2..int-1).fold(false){notPrime, i -> notPrime||(int%i==0)}\n //val n = r.readLine()!!.toInt()\n var (n, k) = r.readLine()!!.split(\" \").map { it.toInt() }\n var next = n+1\n while (!isPrime(next)){\n next++\n }\n println(if (next==k) \"YES\" else \"NO\")\n}", "src_uid": "9d52ff51d747bb59aa463b6358258865"} {"source_code": "private fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\n\nfun main() {\n val (n, k) = readInts()\n val rem = 240 - k\n\n for (i in n downTo 0) {\n if (i * i + i <= rem * 2 / 5) {\n println(i)\n break\n }\n }\n}\n", "src_uid": "41e554bc323857be7b8483ee358a35e2"} {"source_code": "private fun readLn() = readLine()!!\nprivate fun readInt() = readLn().toInt()\nprivate fun readStrings() = readLn().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n\nfun main() {\n val tiles = readStrings()\n var min = 3\n val base = '0'.toInt()\n for (tile in tiles) {\n val toKoutsu = 3 - tiles.count { s -> s == tile }\n min = kotlin.math.min(toKoutsu, min)\n var toShuntsu = 2\n val next = (tile[0].toInt() -base + 1).toString() + tile[1]\n if (tiles.contains(next)) {\n toShuntsu--\n }\n val nextNext = (tile[0].toInt() - base + 2).toString() + tile[1]\n if (tiles.contains(nextNext)) {\n toShuntsu--\n }\n min = kotlin.math.min(toShuntsu, min)\n }\n println(min)\n}", "src_uid": "7e42cebc670e76ace967e01021f752d3"} {"source_code": "import kotlin.math.min\n\nfun main(args: Array) {\n val inp = readLine()!!.split(\" \")\n val n = inp[0].toLong()\n val k = inp[1].toLong()\n if (n <= k/2L)\n {\n println(\"0\")\n return\n }\n val bas = (k-1)/2L\n var son = (k-1)/2L + 1L\n if(k % 2L == 0L)\n son++\n println(min(bas, n - son + 1))\n\n}", "src_uid": "98624ab2fcd2a50a75788a29e04999ad"} {"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\nprivate val OUTPUT_LINES = mutableListOf()\nprivate fun outputLn(s: String) { OUTPUT_LINES += s }\n\nfun biggestSaw(A_: List) : List {\n val A = A_.sorted()\n fun getSaw(len: Int): List {\n val l = mutableListOf()\n // take big then small\n for (i in 0..len-1) {\n if (i % 2 == 0) {\n l += A[A.size - (len - len / 2) + (i / 2)]\n } else {\n l += A[i / 2]\n }\n }\n return l\n }\n\n fun isSaw(a: List): Boolean {\n for (i in 0..a.size-2) {\n if (a[i] == a[i + 1]) return false\n if (i % 2 == 0) {\n if (!(a[i] > a[i+1])) {\n return false\n }\n } else {\n if (!(a[i] < a[i+1])) {\n return false\n }\n }\n }\n return true\n }\n\n var mi = 0\n var ma = A.size + 1\n\n while (ma - mi > 1) {\n val md = (mi + ma) / 2\n val s = getSaw(md)\n if (isSaw(s)) {\n mi = md\n } else {\n ma = md\n }\n }\n\n return getSaw(mi)\n}\n\nfun main() {\n val T = readInt()\n for (t in 1..T) {\n val N = readInt()\n val A = readInts()\n\n val lpos = biggestSaw(A)\n val lneg = biggestSaw(A.map({-it})).map({-it})\n\n val l = if (lpos.size >= lneg.size) lpos else lneg\n outputLn(\"${l.size}\")\n outputLn(\"${l.joinToString(\" \")}\")\n }\n println(OUTPUT_LINES.joinToString(\"\\n\"))\n}\n", "src_uid": "4e679d176597052498b7b8f14d81f63f"} {"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}", "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2"} {"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", "src_uid": "ba49b6c001bb472635f14ec62233210e"} {"source_code": "import Output.print\nimport java.io.BufferedReader\nimport java.io.InputStreamReader\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.min\n\nobject Input {\n\n private val input = BufferedReader(InputStreamReader(System.`in`))\n private lateinit var tokenizer: StringTokenizer\n private val tokenizerValue: StringTokenizer get() {\n if (!this::tokenizer.isInitialized || !tokenizer.hasMoreTokens()) {\n tokenizer = StringTokenizer(input.readLine())\n }\n return tokenizer\n }\n\n val stringValue: String get() = tokenizerValue.nextToken()\n val intValue get() = tokenizerValue.nextToken().toInt()\n val longValue get() = tokenizerValue.nextToken().toLong()\n val floatValue get() = tokenizerValue.nextToken().toFloat()\n val doubleValue get() = tokenizerValue.nextToken().toDouble()\n val intLine get() = stringValue.toInt()\n val longLine get() = stringValue.toLong()\n val floatLine get() = stringValue.toFloat()\n val doubleLine get() = stringValue.toDouble()\n\n val intList get()= valuesList { it.toInt() }\n val longList get() = valuesList { it.toLong() }\n val floatList get() = valuesList { it.toFloat() }\n val doubleList get() = valuesList { it.toDouble() }\n val stringList get() = valuesList { it }\n\n private inline fun valuesList(fn: (String) -> T): List = mutableListOf().apply {\n val tokenizer = StringTokenizer(input.readLine())\n while (tokenizer.hasMoreTokens()) add(fn(tokenizer.nextToken()))\n }\n\n private fun initTokenizer() {\n if (!this::tokenizer.isInitialized || !tokenizer.hasMoreTokens()) {\n tokenizer = StringTokenizer(input.readLine())\n }\n }\n\n fun close() = input.close()\n}\n\nobject Output {\n\n private val output = PrintWriter(System.out)\n\n fun Number.println() = output.println(this)\n\n fun Number.print() = output.print(this)\n\n fun String.println() = output.println(this)\n\n fun String.print() = output.print(this)\n\n fun Collection.println(delimiter: CharSequence = \" \") = output.println(this.joinToString(delimiter))\n\n fun flush() = output.flush()\n\n fun close() = output.close()\n}\n\nfun close() {\n Output.flush()\n Input.close()\n Output.close()\n}\n\nfun solve() {\n val s = Input.stringValue\n\n if (s.length < 3) {\n \"0\".print()\n return\n }\n var ans = 0\n for (i in 0 until s.length - 2) {\n for (j in i + 1 until s.length - 1) {\n for (k in j + 1 until s.length) {\n if (s[i] == 'Q' && s[j] == 'A' && s[k] == 'Q') ans++\n }\n }\n }\n ans.print()\n}\n\nfun main() {\n// var tt = Input.intValue\n// while (tt-- != 0) {\n solve()\n// }\n Output.flush()\n}\n\n", "src_uid": "8aef4947322438664bd8610632fe0947"} {"source_code": "fun gcd(x: Int, y: Int): Int {\n if (x < y) return gcd(y, x)\n if (x % y == 0) return y\n return gcd(y, x % y)\n}\n\nfun main(args: Array) {\n var (l, r, t) = readLine()!!.split(\" \").map { it.toInt() }\n var (l2, r2, t2) = readLine()!!.split(\" \").map { it.toInt() }\n val g = gcd(t, t2)\n if (g == 1) {\n println(minOf(r - l + 1, r2 - l2 + 1))\n } else {\n var ans = 0\n if (l < l2) {\n var temp = (l2 - l) / g * g\n l += temp\n r += temp\n ans = maxOf(ans, minOf(r, r2) - maxOf(l, l2) + 1)\n l += g\n r += g\n ans = maxOf(ans, minOf(r, r2) - maxOf(l, l2) + 1)\n } else {\n var temp = (l - l2) / g * g\n l2 += temp\n r2 += temp\n ans = maxOf(ans, minOf(r, r2) - maxOf(l, l2) + 1)\n l2 += g\n r2 += g\n ans = maxOf(ans, minOf(r, r2) - maxOf(l, l2) + 1)\n }\n println(ans)\n }\n}", "src_uid": "faa75751c05c3ff919ddd148c6784910"} {"source_code": "import com.sun.org.apache.xpath.internal.operations.Bool\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashMap\nimport kotlin.math.max\nimport kotlin.math.min\nimport java.io.IOException\nimport jdk.nashorn.internal.runtime.ScriptingFunctions.readLine\nimport java.util.StringTokenizer\nimport java.io.InputStreamReader\nimport java.io.BufferedReader\nimport java.io.InputStream\nimport kotlin.math.abs\n\nfun main(args: Array) {\n Thread { solve() }.start()\n}\n\nfun solve() {\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n var k1 = -2\n var k2 = -1\n val arr = IntArray(n / 2) { scanner.nextInt() - 1 }.sorted()\n print(min(arr.sumBy { k1 += 2; abs(it - k1) }, arr.sumBy { k2 += 2; abs(it - k2) }))\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\n//class Pair(val a: Int, val b: Int): Comparable {\n// override fun compareTo(other: Pair): Int {\n// return a - other.a\n//", "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a"} {"source_code": "//package com.happypeople.codeforces.c1099\n\nimport java.io.ByteArrayInputStream\nimport java.io.InputStream\nimport java.util.*\n\nfun main(args: Array) {\n try {\n C().run()\n } catch (e: Throwable) {\n C.log(\"\" + e)\n }\n}\n\n// worst code ever :/\nclass C {\n fun run() {\n val sc = Scanner(systemIn())\n var str = sc.nextLine()!!.trim()\n val k = sc.nextInt()\n\n if(str.length==0) {\n if(k>0)\n println(\"Impossible\")\n else\n println()\n return\n }\n\n val specialCount = str.filter { it == '*' || it == '?' }.count()\n val minLen = str.length - (2 * specialCount)\n if (k < minLen) {\n println(\"Impossible\")\n return\n }\n\n if(!str.contains(\"*\")) {\n val maxLen=str.length-specialCount\n if(maxLen 0) {\n val repl = str[idx - 1]\n val repl1 = \"\" + repl + \"?\"\n val repl2 = \"\" + repl\n str = str.replaceFirst(repl1, repl2)\n len++\n } else\n break\n }\n log(\"after1: $str\")\n\n if (len < k) { // replace first * by as much as needed chars\n val idx = str.indexOf('*')\n // idx allways >=0\n val repl = str[idx - 1]\n val repl1 = \"\" + repl + \"*\"\n val repl2 = buildString(repl, k - len)\n log(\"seconds repl2: $repl2\")\n str = str.replaceFirst(repl1, repl2)\n }\n log(\"after2: $str\")\n\n while (str.contains(\"*\")) {\n val idx = str.indexOf('*')\n val repl = str[idx - 1]\n val repl1 = \"\" + repl + \"*\"\n str = str.replace(repl1, \"\")\n }\n log(\"removed *: $str\")\n while (str.contains(\"?\")) {\n val idx = str.indexOf('?')\n val repl = str[idx - 1]\n val repl1 = \"\" + repl + \"?\"\n str = str.replace(repl1, \"\")\n }\n log(\"len result: ${str.length}\")\n\n println(\"$str\")\n }\n\n fun buildString(c: Char, len: Int): String {\n var s = \"\" + c\n while (s.length < len)\n s = s + c\n return s\n }\n\n companion object {\n var inputStr: String? = null\n\n fun systemIn(): InputStream {\n if (inputStr != null)\n return ByteArrayInputStream(inputStr!!.toByteArray())\n else\n return System.`in`\n }\n\n var printLog = false\n fun log(str: String) {\n if (printLog)\n println(str)\n }\n }\n}", "src_uid": "90ad5e6bb5839f9b99a125ccb118a276"} {"source_code": "import java.util.*\n\nfun main() {\n var n = readLine()!!.toInt()\n var str = readLine()!!\n var ans = \"\"\n var rem = 0\n var flag = true\n if (str[0]=='1'){\n ans+='0'\n rem = 1\n }else{\n ans+='1'\n for (i in 1..str.length-1){\n ans+=str[i]\n flag = false\n }\n }\n var i = 1\n while (i) {\n val a = readLine()!!\n val b = a.count{it=='o'}\n val n = a.count{it=='-'}\n // --o--o--o\n if(n == 0 || b == 0) {\n print(\"YES\")\n } else print(\n if(n % b == 0) \"YES\" else \"NO\"\n )\n}\n\n\n\n\n\n\n", "src_uid": "6e006ae3df3bcd24755358a5f584ec03"} {"source_code": "fun main() {\n var n = readLine()!!.toInt()\n var ans = n / 100\n n %= 100\n while (n != 0) {\n when {\n n >= 20 -> n -= 20\n n >= 10 -> n -= 10\n n >= 5 -> n -= 5\n n >= 1 -> n -= 1\n }\n ans++\n }\n println(ans)\n}\n", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc"} {"source_code": "fun main(args: Array) {\n val str = readLine()!!\n\n val a = Array(str.length) { \"\" }\n a[0] = str\n for (i in 1..str.length - 1) {\n a[i] = a[i - 1].substring(1) + a[i - 1][0]\n }\n\n val ans = a.toSet().size\n println(ans)\n}", "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e"} {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val repeats = intArrayOf(0, 0, 0)\n readLine()\n for ((pos, exercise) in readInts().withIndex())\n repeats[pos % 3] += exercise\n print(\n when {\n repeats[0] > repeats[1] && repeats[0] > repeats[2] -> \"chest\"\n repeats[1] > repeats[0] && repeats[1] > repeats[2] -> \"biceps\"\n else -> \"back\"\n }\n )\n}", "src_uid": "579021de624c072f5e0393aae762117e"} {"source_code": "import java.util.HashSet\n\nfun main(args: Array) {\n val k = readLine()!!.toInt()\n val q = readLine() ?: \"\"\n\n if(k > q.length) {\n println(\"NO\")\n } else if(k < 2) {\n println(\"YES\")\n println(q)\n } else {\n val s = IntArray(k, { -1 })\n val ls = HashSet()\n var i = 0\n\n for(j in 0 until q.length) {\n if(q[j] !in ls) {\n s[i] = j\n ls.add(q[j])\n i++\n\n if(i == k) {\n println(\"YES\")\n for(n in 0 until k - 1) {\n println(q.subSequence(s[n], s[n + 1]))\n }\n\n println(q.subSequence(s[s.size - 1], q.length))\n\n\n return\n }\n }\n }\n\n println(\"NO\")\n }\n}", "src_uid": "c1b071f09ef375f19031ce99d10e90ab"} {"source_code": "fun main() {\n val (p, q) = readInts()\n\n fun sieve(n: Int): List {\n val isPrime = MutableList(n + 1) { true }\n isPrime[0] = false\n isPrime[1] = false\n for (x in 2..n) {\n if (!isPrime[x]) continue\n for (u in (2 * x)..n step x) isPrime[u] = false\n }\n\n return isPrime\n }\n\n fun isPalindrome(d: Int): Boolean {\n val num = d.toString()\n if (num.length == 1) return true\n else {\n for (i in num.indices) if (num[i] != num[num.length - i - 1]) return false\n return true\n }\n }\n\n val isPrime = sieve(2000000)\n\n var primes = 0L\n var palindromes = 0L\n\n var currNumber = 1\n var ans = 0\n while (currNumber < 2000000) {\n if (isPalindrome(currNumber)) palindromes++\n if (isPrime[currNumber]) primes++\n if (q * primes <= p * palindromes) {\n ans = currNumber\n// println(\"$currNumber -> $primes $palindromes\")\n }\n currNumber++\n }\n\n println(ans)\n}\n\n// Input Reader\nprivate fun readLn() = readLine()!!\n\nprivate fun readStrings() = readLn().trim().split(\" \")\nprivate fun readInts() = readStrings().map { it.toInt() }\n", "src_uid": "e6e760164882b9e194a17663625be27d"} {"source_code": "fun main(args: Array) {\n val words = readLine() !!.split(\"WUB\").filter { !it.isEmpty() }\n println(words.joinToString(separator = \" \"))\n}", "src_uid": "edede580da1395fe459a480f6a0a548d"} {"source_code": "import com.sun.xml.internal.fastinfoset.util.StringArray\nimport kotlin.math.min\n\nfun main() {\n var (n, l, r) = readLine()!!.split(\" \").map { it.toInt() }\n\n var minArray = mutableListOf()\n var maxArray = mutableListOf()\n (1..n - (l - 1)).forEach {\n minArray.add(1)\n }\n\n var j = 1\n (1..l-1).forEach{\n j*=2\n minArray.add(j)\n }\n\n var distinct = 1;\n var k = 1\n for (i in 1..n){\n if (distinct<=r-1){\n maxArray.add(k)\n k*=2\n distinct++\n }else{\n maxArray.add(k)\n }\n }\n println(\"${minArray.sum()} ${maxArray.sum()}\")\n}\n\n", "src_uid": "ce220726392fb0cacf0ec44a7490084a"} {"source_code": "fun main() {\n val input = readLine()!!.split(\" \").map(Integer::parseInt)\n var queue = readLine()!!\n val kids = input[0]\n val time = input[1]\n\n for (i in 0 until time) {\n queue = queue.replace(\"BG\", \"GB\")\n }\n println(queue)\n}", "src_uid": "964ed316c6e6715120039b0219cc653a"} {"source_code": "fun main() {\n val (n , m) = readLine()!!.split(' ').map { it.toInt() }\n\n println(doIt(n, m))\n}\n\nfun doIt(n: Int, m: Int): Int {\n if (n == m) return 0\n if (m == 0) return 1\n\n val remaining = n - m\n val adjust = (remaining * 2) - n\n\n if (adjust <= 0) return remaining\n\n return remaining - adjust\n}\n", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648"} {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n print(\n when (readInts().max()!!) {\n 1 -> \"1/1\"\n 2 -> \"5/6\"\n 3 -> \"2/3\"\n 4 -> \"1/2\"\n 5 -> \"1/3\"\n else -> \"1/6\"\n }\n )\n}", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414"} {"source_code": "fun main() {\n val s = readLine()!!\n val numFours = s.count { it == '4' }\n val numSevens = s.count { it == '7' }\n print(\n when {\n numFours == 0 && numSevens == 0 -> -1\n numFours >= numSevens -> 4\n else -> 7\n }\n )\n}", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a"} {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val n = readInt()\n if (n and 1 == 0) return print(\"No\")\n val arr = readInts()\n print(if (arr.first() and 1 == 1 && arr.last() and 1 == 1) \"Yes\" else \"No\")\n}", "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db"} {"source_code": "import kotlin.math.min\n\nfun main() {\n //for (t in 1..nextInt()) {\n println(solve(nextInt(), nextInt(), nextInt(), nextInt()))\n //}\n}\n\nfun solve(a: Int, b: Int, c: Int, d: Int): String {\n val count = LongArray(b + c + 2)\n for (i in a + b .. b + c) {\n count[i - 1] = min(i - a - b + 1L, b + c - i + 1L)\n count[i - 1] = min(count[i - 1], min(b - a + 1, c - b + 1).toLong())\n }\n for (i in b + c downTo 1) {\n count[i] += count[i + 1]\n }\n //println(count.joinToString(\" \"))\n var res = 0L\n for (i in c..d) {\n val t = min(i, b + c + 1)\n res += count[t]\n }\n return res.toString()\n}\n\nfun nextInt() = reader.nextInt()\n\nfun nextLong() = reader.nextLong()\n\nfun nextDouble() = reader.nextDouble()\n\nfun next() = reader.next()\n\nfun nextLine() = reader.nextLine()\n\nobject reader {\n\n private var tokens = listOf()\n private var index = 0\n\n fun nextInt() = this.next().toInt()\n\n fun nextLong() = this.next().toLong()\n\n fun nextDouble() = this.next().toDouble()\n\n fun next(): String {\n if (index == tokens.size) {\n tokens = this.nextLine().split(\" \")\n index = 0\n }\n return tokens[index++]\n }\n\n fun nextLine(): String {\n tokens = listOf()\n index = 0\n return readLine()!!\n }\n}\n", "src_uid": "4f92791b9ec658829f667fcea1faee01"} {"source_code": "/**\n * We declare a package-level function main which returns Unit and takes\n * an Array of strings as a parameter. Note that semicolons are optional.\n */\nfun main(args: Array) {\n\tval (n,m) = readLine()!!.split(' ').map(String::toInt)\n var r = if ((n*m)%2 == 0) n*m/2 else (n*m-1)/ 2\n println( r)\n \n}", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd"} {"source_code": "import java.lang.Long.min\r\nfun main(args: Array) {\r\n val a1:Long= readLine()!!.toLong()\r\n val a2:Long= readLine()!!.toLong()\r\n val k1:Long= readLine()!!.toLong()\r\n val k2:Long= readLine()!!.toLong()\r\n val n:Long = readLine()!!.toLong()\r\n var Min:Long=0\r\n var Max:Long=0\r\n var temp1:Long=0\r\n temp1+=n\r\n if(min(k1,k2)==k1){\r\n temp1-=(k1*a1)\r\n if(temp1<0){Max+=(n/k1)}\r\n else{Max+=a1}\r\n if(temp1>0){Max+=temp1/k2}\r\n }\r\n else{\r\n temp1-=(k2*a2)\r\n if(temp1<0){Max+=(n/k2)}\r\n else{Max+=a2}\r\n if(temp1>0){Max+=temp1/k1}\r\n }\r\n temp1=0\r\n temp1+=n\r\n temp1-=((k1-1)*a1)+((k2-1)*a2)\r\n if(temp1>0){\r\n Min+=temp1\r\n }\r\n println(\"$Min $Max\")\r\n\r\n}", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91"} {"source_code": "import kotlin.math.max\n\nfun main() {\n val item = readLine()!!.split(\" \").map { it.toInt() }\n val d = item.last()\n val (a, b, c) = item.dropLast(1).sorted()\n\n print(max(d - (b - a), 0) + max(d - (c - b), 0))\n}", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3"} {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.math.max\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 ans = a.filter { value -> value == 1 }.count()\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\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}", "src_uid": "c7b1f0b40e310f99936d1c33e4816b95"} {"source_code": "fun main() {\n\n var count = readLine()!!.toInt()\n\n for(c in 0 until count) {\n var (n, k, d) = readLine()!!.split(\" \").map { it.toInt() }\n var numbers = readLine()!!.split(\" \").map { it.toInt() }.toIntArray()\n\n var set = numbers.take(d).groupBy { it }.map { Pair(it.key, it.value.size) }.toMap().toMutableMap()\n var numNumber = set.size\n for(i in d until n) {\n var leftIndex = numbers[i-d]\n set[leftIndex] = set[leftIndex]!! - 1\n if(set[leftIndex] == 0) {\n set.remove(leftIndex)\n }\n\n var rightIndex = numbers[i]\n if(set.containsKey(rightIndex)) {\n set[rightIndex] = set[rightIndex]!! + 1\n } else {\n set.put(rightIndex, 1)\n }\n\n numNumber = numNumber.coerceAtMost(set.size)\n }\n\n println(numNumber)\n }\n}", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094"} {"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}", "src_uid": "6b9eff690fae14725885cbc891ff7243"} {"source_code": "\nfun mergeSort(list: List): List {\n if (list.size <= 1) {\n return list\n }\n\n val middle = list.size / 2\n var left = list.subList(0,middle);\n var right = list.subList(middle,list.size);\n return merge(mergeSort(left), mergeSort(right))\n}\nfun merge(left: List, right: List): List {\n var indexLeft = 0\n var indexRight = 0\n var newList : MutableList = mutableListOf()\n\n while (indexLeft < left.count() && indexRight < right.count()) {\n if (left[indexLeft] <= right[indexRight]) {\n newList.add(left[indexLeft])\n indexLeft++\n } else {\n newList.add(right[indexRight])\n indexRight++\n }\n }\n\n while (indexLeft < left.size) {\n newList.add(left[indexLeft])\n indexLeft++\n }\n\n while (indexRight < right.size) {\n newList.add(right[indexRight])\n indexRight++\n }\n\n return newList;\n}\nfun main(args : Array)\n{\n val n : Int = readLine()!!.toInt()\n val arr : MutableList = readLine()!!.split(' ').map{it.toInt()} as MutableList\n val sor = mergeSort(arr)\n var flag : Int = 0\n for(i in 0..n-3)\n {\n //println(\"${sor[i]} ${sor[i+1]} ${sor[i+2]}\")\n if(sor[i]+sor[i+1]>sor[i+2])\n {\n flag=1\n break\n }\n }\n if(flag==0)\n {\n println(\"NO\")\n }\n else\n {\n println(\"YES\")\n }\n}", "src_uid": "897bd80b79df7b1143b652655b9a6790"} {"source_code": "import java.io.BufferedReader\nimport java.io.FileInputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\n\nclass Task6 {\n\n lateinit var v: IntArray\n lateinit var commands: ArrayList\n lateinit var dsu: IntArray\n lateinit var children: Array>\n lateinit var e: ArrayList\n lateinit var usedInCommandEdges: BooleanArray\n lateinit var tIn: IntArray\n lateinit var tOut: IntArray\n\n lateinit var segTree: Array\n\n var n: Int = 0\n var m: Int = 0\n var q: Int = 0\n\n var time = 0\n\n fun solve() {\n val input = BufferedReader(InputStreamReader(System.`in`))\n// val input = BufferedReader(InputStreamReader(FileInputStream(\"input.txt\")))\n val nmq = input.readLine().split(' ')\n n = nmq[0].toInt()\n m = nmq[1].toInt()\n q = nmq[2].toInt()\n\n val tok = StringTokenizer(input.readLine())\n v = IntArray(2 * n + 10)\n for (i in 1..n) v[i] = tok.nextToken().toInt()\n\n e = ArrayList(m + 1)\n e.add(IntPair(0, 0))\n for (i in 1..m) {\n val edge = input.readLine().split(' ')\n e.add(IntPair(edge[0].toInt(), edge[1].toInt()))\n }\n\n usedInCommandEdges = BooleanArray(m + 1)\n commands = ArrayList(q)\n for (i in 0 until q) {\n val command = input.readLine().split(' ')\n val p = IntPair(command[0].toInt(), command[1].toInt())\n commands.add(p)\n if (p.f == 2) {\n usedInCommandEdges[p.s] = true\n }\n }\n\n\n dsu = IntArray(v.size) { it }\n children = Array(v.size) { ArrayList() }\n for (i in e.indices) {\n if (!usedInCommandEdges[i]) {\n val edge = e[i]\n union(edge.f, edge.s)\n }\n }\n\n for (command in commands.asReversed()) {\n if (command.f == 1) {\n command.s = findParent(command.s)\n } else {\n val edge = e[command.s]\n union(edge.s, edge.f)\n }\n }\n\n tIn = IntArray(v.size)\n tOut = IntArray(v.size)\n for (i in 1..n) {\n if (i == findParent(i)) {\n dfs(i)\n }\n }\n\n val dummy = IntPair(0, 0)\n segTree = Array(4 * v.size) { dummy }\n for (i in 1 until n) {\n segmentTreeUpdate(1, n, 1, tIn[i], IntPair(v[i], tIn[i]))\n }\n\n val ans = StringBuilder(q * 7)\n for (command in commands) {\n if (command.f == 2) continue\n\n val max = segmentTreeMax(1, n, 1, tIn[command.s], tOut[command.s])\n if (max.f > 0) {\n ans.appendln(max.f)\n segmentTreeUpdate(1, n, 1, max.s, IntPair(0, 0))\n } else {\n ans.appendln(0)\n }\n }\n\n System.out.println(ans.toString())\n }\n\n private fun findParent(a: Int): Int {\n if (dsu[a] == a) return a\n val p = findParent(dsu[a])\n dsu[a] = p\n return p\n }\n\n private fun union(a: Int, b: Int) {\n val pa = findParent(a)\n val pb = findParent(b)\n if (pa == pb) return\n\n val c = ++n\n dsu[c] = c\n dsu[pa] = c\n dsu[pb] = c\n children[c].add(pa)\n children[c].add(pb)\n }\n\n private fun dfs(v: Int) {\n tIn[v] = ++time\n for (child in children[v]) {\n dfs(child)\n }\n tOut[v] = time\n }\n\n private fun segmentTreeUpdate(l: Int, r: Int, tv: Int, vIndex: Int, value: IntPair) {\n if (l == r) {\n segTree[tv] = value\n return\n }\n\n val mid = (r + l) / 2\n if (vIndex <= mid) {\n segmentTreeUpdate(l, mid, tv * 2, vIndex, value)\n } else {\n segmentTreeUpdate(mid + 1, r, tv * 2 + 1, vIndex, value)\n }\n\n segTree[tv] = maxOf(segTree[tv * 2], segTree[tv * 2 + 1])\n }\n\n private fun segmentTreeMax(vl: Int, vr: Int, tv: Int, l: Int, r: Int): IntPair {\n if (vl >= l && vr <= r) return segTree[tv]\n\n val mid = (vr + vl) / 2\n\n if (r <= mid) {\n return segmentTreeMax(vl, mid, tv * 2, l, r)\n }\n\n if (l > mid) {\n return segmentTreeMax(mid + 1, vr, tv * 2 + 1, l, r)\n }\n\n return maxOf(segmentTreeMax(vl, mid, tv * 2, l, r), segmentTreeMax(mid + 1, vr, tv * 2 + 1, l, r))\n }\n\n data class IntPair(\n var f: Int,\n var s: Int\n ) : Comparable {\n override fun compareTo(other: IntPair): Int {\n return f.compareTo(other.f)\n }\n }\n}\n\nfun main() = Task6().solve()", "src_uid": "ad014bde729222db14f38caa521e4167"} {"source_code": "import kotlin.math.min\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val numChildren = readInt()\n val (min1, max1) = readInts()\n val (min2, max2) = readInts()\n val (min3, _) = readInts()\n var extras = numChildren - min1 - min2 - min3\n val sol1 = min(max1, min1 + extras)\n extras = numChildren - sol1 - min2 - min3\n val sol2 = min(max2, min2 + extras)\n print(\"$sol1 $sol2 ${numChildren - sol1 - sol2}\")\n}", "src_uid": "3cd092b6507079518cf206deab21cf97"} {"source_code": "import kotlin.math.absoluteValue\n\nfun main() {\n fun readInt() = readLine()!!.toInt()\n\n val a = readInt()\n val b = readInt()\n val diff = (a - b).absoluteValue\n val (d1, d2) = if (diff % 2 == 0) diff / 2 to diff / 2 else diff / 2 to diff / 2 + 1\n print((d1 * (d1 + 1)) / 2 + (d2 * (d2 + 1)) / 2)\n}", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da"} {"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}", "src_uid": "d3a8a3e69a55936ee33aedd66e5b7f4a"} {"source_code": "fun main(args:Array){val(x,y)=readLine()!!.split(' ');val a=x.toInt();val b=y.toInt();if(a<1&&b>0){print(\"Impossible\");return};print(\"${Math.max(a,b)} ${if(b>0)a+b-1 else a}\")}", "src_uid": "1e865eda33afe09302bda9077d613763"} {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n print((readInt() + 1) shr 1)\n}\n", "src_uid": "30e95770f12c631ce498a2b20c2931c7"} {"source_code": "import java.io.*\nimport java.util.*\nimport kotlin.random.Random\n\n\n\nfun main(args: Array) {\n val input = InputReader(System.`in`)\n val out = PrintWriter(BufferedOutputStream(System.out))\n\n for (k in 1..1){//input.nextInt()) {\n out.println(task(input, out))\n }\n\n out.close()\n}\n\nfun task(input: InputReader, out: PrintWriter): Long {\n val n = input.nextLong()\n val x = input.nextLong()\n val pos = input.nextLong()\n\n var small = 0\n var big = 0\n\n var l = 0L\n var r = n\n while (l < r) {\n var m = (l + r)/2\n if (m < pos) {\n small ++\n l = m + 1\n }\n else if (m > pos) {\n big++\n r = m\n }\n else {\n l = m + 1\n }\n }\n\n val mod = 1000000000L + 7\n var res = 1L\n var cur = x - 1\n for (i in 1..small) {\n if (cur == 0L)\n return 0\n\n res *= cur\n res %= mod\n cur --\n }\n\n cur = n - x\n for (i in 1..big) {\n if (cur == 0L)\n return 0\n\n res *= cur\n res %= mod\n cur --\n }\n for (i in 1..(n - small - big - 1)) {\n res *= i\n res %= mod\n }\n return res\n}\n\n\nfun PrintWriter.output(ans: IntArray) {\n val str = StringBuilder()\n for (an in ans) {\n str.append(an).append(' ')\n }\n println(str)\n}\nfun PrintWriter.output(ans: Array) {\n val str = StringBuilder()\n for (an in ans) {\n str.appendLine(an)\n }\n println(str)\n}\n\nclass InputReader(stream: InputStream?) {\n var reader = BufferedReader(InputStreamReader(stream), 32768)\n var tokenizer: StringTokenizer?\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n tokenizer = try {\n StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n }\n return tokenizer!!.nextToken()\n }\n\n fun randomIntArray(n: Int) : IntArray {\n return IntArray(n) { Random.nextInt(n) }\n }\n\n fun nextStringArray(n: Int): Array {\n return Array(n) { nextString() }\n }\n\n fun nextIntArray(n: Int): IntArray {\n return IntArray(n) { nextInt() }\n }\n\n fun nextLongArray(n: Int): LongArray {\n return LongArray(n) { nextLong() }\n }\n\n fun nextString(): String {\n return try {\n reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n }\n\n fun nextInt(): Int {\n return next().toInt()\n }\n\n fun nextLong(): Long {\n return next().toLong()\n }\n\n fun nextChar(): Char {\n return next()[0]\n }\n\n init {\n tokenizer = null\n }\n}\n\nfun binSearchR(list: IntArray, key: Int, start: Int, end: Int): Int {\n var l = start - 1\n var r = end\n while (l < r - 1) {\n val m = (l + r) / 2\n if (list[m] <= key) {\n l = m\n } else {\n r = m\n }\n }\n return l\n}\n\n\nfun binSearchL(list: IntArray, key: Int, start: Int, end: Int): Int {\n var l = start - 1\n var r = end\n while (l < r - 1) {\n val m = (l + r) / 2\n if (list[m] < key) {\n l = m\n } else {\n r = m\n }\n }\n return r\n}\n\nfun IntArray.my_shuffle(random: Random): Unit {\n for (i in lastIndex downTo 1) {\n val j = random.nextInt(i + 1)\n val copy = this[i]\n this[i] = this[j]\n this[j] = copy\n }\n}\n", "src_uid": "24e2f10463f440affccc2755f4462d8a"} {"source_code": "import java.util.*\n\nfun main() {\n var x = 0;\n var n = 0;\n var ctr = 1\n var scan = Scanner(System.`in`)\n var set = mutableSetOf()\n n = scan.nextInt()\n set.add(n)\n x = f(n)\n while (set.add(x)) {\n x = f(x)\n ctr++\n }\n print(ctr)\n}\n\nfun f(x: Int): Int {\n var d = x\n d++\n while (d % 10 == 0) {\n d /= 10\n }\n return d\n}", "src_uid": "055fbbde4b9ffd4473e6e716da6da899"} {"source_code": "import java.util.*\nval reader = Scanner(System.`in`)\nfun main(args: Array){\n val k = reader.nextBigInteger()\n val l = reader.nextBigInteger()\n\n var i = 0\n var po = k.pow(i)\n\n while (po < l)\n {\n po = k.pow(++i)\n if(po == l)\n {\n println(\"YES\")\n print(i-1)\n return\n }\n }\n\n print(\"NO\")\n}", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46"} {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n var s = \"\"\n do {\n s = readLine()!!\n } while (s.length != n)\n val r = s.replace(\"UR|RU\".toRegex(), \"D\")\n println(r.length)\n}", "src_uid": "986ae418ce82435badadb0bd5588f45b"} {"source_code": "var n:Int=0\nvar arr=Array(15){tuple(0,0,0)}\nfun main(args: Array){\n n= readLine()!!.toInt()\n for (i:Int in 0 until n){\n val inp=readLine()!!.split(' ')\n arr[i]=tuple(inp[0].toInt() , inp[1].toInt() , inp[2].toInt())\n }\n var ans=0\n var num_of_ans=0\n for(i:Int in 123..9876){\n if(!distinct(i)){\n continue\n }\n if(check(i)){\n ans=i\n num_of_ans++\n }\n }\n if(num_of_ans == 0){\n println(\"Incorrect data\")\n }else if(num_of_ans > 1){\n println(\"Need more data\")\n }else{\n if(ans/1000 == 0){\n print(0)\n print(ans)\n }else {\n print(ans)\n }\n }\n}\nfun distinct(x:Int):Boolean{\n var firstX:Int=x%10\n var secondX:Int=(x%100)/10\n var thirdX:Int=(x%1000)/100\n var fourthX:Int=x/1000\n if(firstX == secondX || firstX == thirdX || firstX == fourthX\n || secondX == thirdX || secondX == fourthX || thirdX == fourthX){\n return false\n }\n return true\n}\n\nfun check(num: Int):Boolean{\n for(i:Int in 0 until n){//bulls the same pos\n if(Bulls(arr[i].x , num) != arr[i].y ||\n Cows(arr[i].x , num) != arr[i].z){\n return false\n }\n }\n return true\n}\nfun Bulls(x:Int , y:Int):Int{\n var ans:Int=0\n if(x%10 == y%10){\n ans++\n }\n if ((x%100)/10 == (y%100)/10){\n ans++\n }\n if ((x%1000)/100 == (y%1000)/100){\n ans++\n }\n if(x/1000 == y/1000){\n ans++\n }\n return ans\n}\nfun Cows(x:Int , y:Int):Int{\n var ans=0\n var firstX:Int=x%10\n var secondX:Int=(x%100)/10\n var thirdX:Int=(x%1000)/100\n var fourthX:Int=x/1000\n\n var firstY:Int=y%10\n var secondY:Int=(y%100)/10\n var thirdY:Int=(y%1000)/100\n var fourthY:Int=y/1000\n if(firstX == secondY || firstX == thirdY || firstX == fourthY){\n ans++\n }\n if(secondX == firstY || secondX == thirdY || secondX == fourthY){\n ans++\n }\n if(thirdX == secondY || thirdX == firstY || thirdX == fourthY){\n ans++\n }\n if(fourthX == secondY || fourthX == thirdY || fourthX == firstY){\n ans++\n }\n return ans\n}\nclass tuple(x:Int , y:Int , z:Int){\n var x:Int=0\n var y:Int=0\n var z:Int=0\n init{\n this.x=x\n this.y=y\n this.z=z\n }\n}", "src_uid": "142e5f2f08724e53c234fc2379216b4c"} {"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", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d"} {"source_code": "fun main(args: Array) {\n val inp = readLine()!!.split(\" \")\n val n = inp[0].toLong()\n val m = inp[1].toLong()\n var min = n - 2*m\n if (min<0)\n min = 0\n var a = 0L\n for (i in 1..(n.toInt()))\n {\n a = i.toLong()\n if (i.toLong()*(i.toLong()-1L)/2L >= m)\n break\n }\n if (m == 0L)\n a = 0\n val max = n-a\n println(\"$min $max\")\n}", "src_uid": "daf0dd781bf403f7c1bb668925caa64d"} {"source_code": "import java.util.*\n\nfun main() {\n\n val scanner = Scanner(System.`in`)\n\n val destPoint = scanner.nextInt()\n val maxLitersCount = scanner.nextInt()\n val stationCoordinate = scanner.nextInt()\n val ridesCount = scanner.nextInt()\n\n var ans = 0\n\n var currentFuel = maxLitersCount\n var distanceToRide: Int\n\n if (maxLitersCount < stationCoordinate) {\n println(-1)\n return\n } else {\n currentFuel -= stationCoordinate\n }\n\n for (currentRideNumber in 0 until ridesCount) {\n distanceToRide = if (currentRideNumber.rem(2) == 0) {\n destPoint - stationCoordinate\n } else {\n stationCoordinate\n }\n if (currentRideNumber < ridesCount - 1) {\n distanceToRide *= 2\n }\n if (maxLitersCount < distanceToRide) {\n println(-1)\n return\n } else if (currentFuel < distanceToRide) {\n ans++\n currentFuel = maxLitersCount\n }\n\n currentFuel -= distanceToRide\n }\n\n println(ans)\n\n\n}\n", "src_uid": "283aff24320c6518e8518d4b045e1eca"} {"source_code": "fun main(args: Array) {\n\n var list = readLine()!!.split(' ').map(String::toInt)\n list = list.sorted()\n\n print(list[list.lastIndex] - list[0])\n}", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319"} {"source_code": "\nfun main(args : Array) {\n val t = readLine()!!\n val (a, b ) = readLine()!!.split(' ')\n val card = arrayOf('6','7','8','9','T','J','Q','K','A')\n\n\n if(t==a[1].toString()){\n\n if(t!=b[1].toString()){\n println(\"YES\")\n }\n else{\n var a1 = 0\n var b1 = 0\n\n for(i in 0..card.size-1) {\n if (a[0]==card[i]) {\n a1 = i\n }\n }\n for(j in 0..card.size-1) {\n if(b[0]==card[j]){\n b1 = j\n }\n }\n\n if(a1>b1){\n println(\"YES\")\n }\n else{\n println(\"NO\")\n }\n }\n\n }\n else if(a[1]!=b[1] && t!=a[1].toString()){\n println(\"NO\")\n }\n else if(a[1]==b[1] ){\n var a1 = 0\n var b1 = 0\n\n for(i in 0..card.size-1){\n if(card[i]==a[0]){\n a1 = i\n }\n if(card[i]==b[0]){\n b1 = i\n }\n }\n\n if(a1>b1){\n println(\"YES\")\n }\n else{\n println(\"NO\")\n }\n }\n\n}", "src_uid": "da13bd5a335c7f81c5a963b030655c26"} {"source_code": "fun main(args: Array) {\n val a = readLine()!!.split(\" \").map{ it.toInt() }.toMutableList()\n if (a[0] * 3 <= a[1]) {\n print(0)\n } else {\n print(a[0] * 3 - a[1])\n }\n}", "src_uid": "5a5e46042c3f18529a03cb5c868df7e8"} {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n// val startTime = System.nanoTime()\n\n val numCases = 1//readInt()\n\n case@ for(case in 1..numCases) {\n // print(\"Case #$case: \")\n\n val n = readInt()\n MOD = readInt()\n\n// val C = ModIntArray(n+1)\n// C[n]++\n// for(i in 1..n) {\n// for(j in n-i until n) C[j] += C[j+1]\n// }\n\n var ans = ModInt(0)\n val P = ModIntArray(n+1)\n P[0]++\n for(i in 0 until n) P[i+1] = P[i] * (n - i)\n\n var D = OffsetModIntArray(0, 0)\n D[0]++\n for(i in 1 until n) {\n for(j in 0 until D.arr.lastIndex) D.arr[j+1] += D.arr[j]\n var acc = ModInt(0)\n for(j in 1..i) acc += D.getPinned(-j-1) * (i - j + 1)\n\n ans += acc * P[n-i-1]\n\n acc = ModInt(0)\n val Di = OffsetModIntArray(D.firstIndex - i, D.lastIndex + i)\n for(j in Di.firstIndex .. Di.lastIndex) {\n acc += D.getPinned(j + i) - D.getPinned(j - 1)\n acc -= D.getPinned(j - 1) - D.getPinned(j - i - 2)\n Di[j] = acc\n }\n D = Di\n }\n\n println(ans.int)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nfun OffsetModIntArray.getPinned(i: Int) = if (i < firstIndex) ModInt(0) else get(min(i, lastIndex))\n\nclass OffsetModIntArray(val firstIndex: Int, val lastIndex: Int) {\n constructor(indices: IntRange): this(indices.first, indices.last)\n inline val indices get() = firstIndex .. lastIndex\n val arr = ModIntArray(lastIndex - firstIndex + 1)\n val size get() = arr.size\n\n operator fun get(i: Int) = arr[i - firstIndex]\n operator fun set(i: Int, v: ModInt) { arr[i - firstIndex] = v }\n fun last() = arr.last()\n}\n\nvar MOD = 998244353\n\ninfix fun Int.modulo(mod: Int): Int = (this % mod).let { (it shr Int.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.modulo(mod: Long) = (this % mod).let { (it shr Long.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.modulo(mod: Int) = modulo(mod.toLong()).toInt()\n\nfun Int.mulMod(other: Int, mod: Int) = toLong() * other modulo mod\n\nfun Int.powMod(exponent: Long, mod: Int): Int {\n if(exponent < 0) error(\"Inverse not implemented\")\n var res = 1L\n var e = exponent\n var b = modulo(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1L) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\nfun Int.powMod(exponent: Int, mod: Int) = powMod(exponent.toLong(), mod)\nfun Int.modPowArray(n: Int, mod: Int): IntArray {\n val res = IntArray(n+1)\n res[0] = 1\n for(i in 1..n) res[i] = mulMod(res[i-1], mod)\n return res\n}\n\ninline fun Int.toModInt() = ModInt(this modulo MOD)\ninline fun Long.toModInt() = ModInt(this modulo MOD)\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n\n // normalizes an integer that's within range [-MOD, MOD) without branching\n private inline fun normalize(int: Int) = ModInt((int shr Int.SIZE_BITS - 1 and MOD) + int)\n\n operator fun plus(other: ModInt) = normalize(int + other.int - MOD) // overflow-safe even if MOD >= 2^30\n inline operator fun plus(other: Int) = plus(other.toModInt())\n operator fun inc() = normalize(int + (1 - MOD))\n\n operator fun minus(other: ModInt) = normalize(int - other.int)\n inline operator fun minus(other: Int) = minus(other.toModInt())\n operator fun dec() = normalize(int - 1)\n operator fun unaryMinus() = normalize(-int)\n\n operator fun times(other: ModInt) = ModInt((int.toLong() * other.int % MOD).toInt())\n inline operator fun times(other: Int) = ModInt(int.mulMod(other, MOD))\n\n fun pow(exponent: Int): ModInt = ModInt(int.powMod(exponent, MOD))\n\n fun pow(exponent: Long) = ModInt(int.powMod(exponent, MOD))\n\n override inline fun toString() = int.toString()\n}\n\ninline operator fun Int.plus(modInt: ModInt) = modInt + this\ninline operator fun Int.minus(modInt: ModInt) = toModInt() - modInt\ninline operator fun Int.times(modInt: ModInt) = modInt * this\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n inline operator fun get(i: Int) = ModInt(intArray[i])\n inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override inline val size: Int get() = intArray.size\n inline val lastIndex get() = intArray.lastIndex\n inline val indices get() = intArray.indices\n\n override inline fun contains(element: ModInt): Boolean = element.int in intArray\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override inline fun isEmpty(): Boolean = intArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): ModInt = get(index++)\n }\n\n fun copyOf(newSize: Int) = ModIntArray(intArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun ModIntArray.copyInto(destination: ModIntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =\n ModIntArray(intArray.copyInto(destination.intArray, destinationOffset, startIndex, endIndex))\ninline fun ModIntArray(size: Int) = ModIntArray(IntArray(size))\ninline fun ModIntArray(size: Int, init: (Int) -> ModInt) = ModIntArray(IntArray(size) { init(it).int })\n\nfun ModInt.powArray(n: Int) = ModIntArray(int.modPowArray(n, MOD))\n\ninline fun ModIntArray.first() = get(0)\ninline fun ModIntArray.last() = get(lastIndex)\ninline fun ModIntArray.joinToString(separator: CharSequence) = intArray.joinToString(separator)\ninline fun ModIntArray.fold(init: R, op: (acc: R, ModInt) -> R) = intArray.fold(init) { acc, i -> op(acc, ModInt(i)) }\ninline fun ModIntArray.foldRight(init: R, op: (ModInt, acc: R) -> R) = intArray.foldRight(init) { i, acc -> op(ModInt(i), acc) }\nfun ModIntArray.sum() = fold(ModInt(0), ModInt::plus)\nfun ModIntArray.product() = fold(ModInt(1), ModInt::times)\n\ninline fun Iterable.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Iterable.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\ninline fun Sequence.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Sequence.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\ninline fun Array.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Array.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\nfun Iterable.sum() = sumByModInt { it }\nfun Sequence.sum() = sumByModInt { it }\nfun Iterable.product() = productByModInt { it }\nfun Sequence.product() = productByModInt { it }\nfun Collection.toModIntArray() = ModIntArray(size).also { var i = 0; for(e in this) { it[i++] = e } }\n\n\n\n/** IO */\n//@JvmField val ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n//const val PATH = \"src/main/resources/\"\n//@JvmField val INPUT = File(PATH + \"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(PATH + \"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\nconst val _BUFFER_SIZE = 1 shl 16\n@JvmField val _buffer = ByteArray(_BUFFER_SIZE)\n@JvmField var _bufferPt = 0\n@JvmField var _bytesRead = 0\n\ntailrec fun readChar(): Char {\n if(_bufferPt == _bytesRead) {\n _bufferPt = 0\n _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)\n }\n return if(_bytesRead < 0) Char.MIN_VALUE\n else {\n val c = _buffer[_bufferPt++].toChar()\n if (c == '\\r') readChar() else c\n }\n}\n\n/** @param skipNext Whether to skip the next character (usually whitespace), defaults to true */\nfun readCharArray(n: Int, skipNext: Boolean = true): CharArray {\n val res = CharArray(n) { readChar() }\n if(skipNext) readChar()\n return res\n}\n\nfun readLine(): String? {\n var c = readChar()\n return if(c == Char.MIN_VALUE) null\n else buildString {\n while(c != '\\n' && c != Char.MIN_VALUE) {\n append(c)\n c = readChar()\n }\n }\n}\nfun readLn() = readLine()!!\n\nfun read() = buildString {\n var c = readChar()\n while(c <= ' ') {\n if(c == Char.MIN_VALUE) return@buildString\n c = readChar()\n }\n do {\n append(c)\n c = readChar()\n } while(c > ' ')\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** sort overrides to avoid quicksort attacks */\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\ninline fun _mergeSort(a0: A, n: Int, tmp0: A, get: A.(Int) -> T, set: A.(Int, T) -> Unit, cmp: (T, T) -> Int) {\n var a = a0\n var tmp = tmp0\n var len = 1\n while(len < n) {\n var l = 0\n while(true) {\n val m = l + len\n if(m >= n) break\n val r = min(n, m + len)\n var i = l\n var j = m\n for(k in l until r) {\n if(i != m && (j == r || cmp(a.get(i), a.get(j)) <= 0)) {\n tmp.set(k, a.get(i++))\n } else tmp.set(k, a.get(j++))\n }\n l = r\n }\n for(i in l until n) tmp.set(i, a.get(i))\n val t = a; a = tmp; tmp = t\n len += len\n }\n if(a !== a0) for(i in 0 until n) a0.set(i, tmp0.get(i))\n}\n\ninline fun IntArray.sortWith(cmp: (Int, Int) -> Int) { _mergeSort(this, size, IntArray(size), IntArray::get, IntArray::set, cmp) }\ninline fun > IntArray.sortBy(func: (Int) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > IntArray.sortByDescending(func: (Int) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun IntArray.sort() { sortBy { it } }\nfun IntArray.sortDescending() { sortByDescending { it } }\n\ninline fun LongArray.sortWith(cmp: (Long, Long) -> Int) { _mergeSort(this, size, LongArray(size), LongArray::get, LongArray::set, cmp) }\ninline fun > LongArray.sortBy(func: (Long) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > LongArray.sortByDescending(func: (Long) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun LongArray.sort() { sortBy { it } }\nfun LongArray.sortDescending() { sortByDescending { it } }\n\ninline fun DoubleArray.sortWith(cmp: (Double, Double) -> Int) { _mergeSort(this, size, DoubleArray(size), DoubleArray::get, DoubleArray::set, cmp) }\ninline fun > DoubleArray.sortBy(func: (Double) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > DoubleArray.sortByDescending(func: (Double) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun DoubleArray.sort() { sortBy { it } }\nfun DoubleArray.sortDescending() { sortByDescending { it } }\n\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\n// import preserving junk function\n@Suppress(\"NonAsciiCharacters\") fun 雪花飄飄北風嘯嘯天地一片蒼茫() { 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 }", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a"} {"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}", "src_uid": "b2d59b1279d891dba9372a52364bced2"} {"source_code": "import java.math.BigInteger\r\nimport java.util.*\r\n\r\nfun main() {\r\n val sp = readLine()!!.split(\" \")\r\n val n = sp[0].toInt()\r\n val x = sp[1].toBigInteger()\r\n val bfs = LinkedList().apply { add(State(0, x)) }\r\n\r\n val visited = mutableSetOf()\r\n while (bfs.isNotEmpty()) {\r\n val state = bfs.pollFirst()\r\n val s = state.x.toString().toSet()\r\n if (state.x.toString().length >= n) {\r\n println(state.moves)\r\n return\r\n }\r\n\r\n for (digit in s) {\r\n val d = BigInteger((digit - '0').toString())\r\n val next = state.x.multiply(d)\r\n if (visited.contains(next)) continue\r\n\r\n bfs.addLast(State(state.moves + 1, next))\r\n visited.add(next)\r\n }\r\n }\r\n\r\n println(-1)\r\n}\r\n\r\ndata class State(val moves: Int, val x: BigInteger)\r\n", "src_uid": "cedcc3cee864bf8684148df93804d029"} {"source_code": "import java.util.Scanner\n\nfun main(args: Array)\n{\n val read = Scanner(System.`in`)\n val a = read.nextInt()\n val b = read.nextInt()\n val c = read.nextInt()\n if(a+b>c && a+c>b && b+c>a)\n {\n print(0)\n }\n else\n {\n if(a>b && a>c)\n {\n println(a-b-c+1)\n }\n else if(b>a && b>c)\n {\n println(b-a-c+1)\n }\n else\n {\n println(c-a-b+1)\n }\n }\n}", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09"} {"source_code": "import kotlin.math.max\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (_, _, bourles) = readInts()\n val buy = readInts().min()!!\n val sell = readInts().max()!!\n print(max(bourles, bourles % buy + sell * (bourles / buy)))\n}", "src_uid": "42f25d492bddc12d3d89d39315d63cb9"} {"source_code": "fun main(){\n var (n,a) = readLine()!!.split(' ')\n var a1 = a.toLong()\n var n1 = n.toLong()\n var otv_o:Long=a1-1;\n //println(n1-otv_o)\n if(a1==1L){\n if(n1!=0L){\n println(\"NO\")\n return\n }\n }\n if((n1-otv_o)%2L==0L && n1-otv_o>=0 && a1>=1){\n println(\"YES\")\n return\n }else{\n println(\"NO\")\n return\n }\n}", "src_uid": "1527171297a0b9c5adf356a549f313b9"} {"source_code": "import kotlin.math.max\n\nfun main() {\n val nums = readLine()!!.split(\" \").map { it.toInt() }.sorted()\n nums\n .subList(0, nums.size - 2)\n .foldIndexed(0) { index, acc, i ->\n max(\n acc,\n when {\n i + nums[index + 1] > nums[index + 2] -> 2\n i + nums[index + 1] == nums[index + 2] -> 1\n else -> 0\n }\n )\n }.let {\n print(\n when (it) {\n 1 -> \"SEGMENT\"\n 2 -> \"TRIANGLE\"\n else -> \"IMPOSSIBLE\"\n }\n )\n }\n}", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a"} {"source_code": "fun main()\r\n{\r\n val input = getInput()\r\n val output = calc(input)\r\n output.forEach { println(it) }\r\n}\r\n\r\nprivate fun getInput(): Array\r\n{\r\n val input = Array(readln().toInt()){0}\r\n for (i in input.indices)\r\n {\r\n input[i] = readln().toInt()\r\n }\r\n return input\r\n}\r\n\r\nprivate fun calc(input: Array): Array\r\n{\r\n val result = Array(input.size){0}\r\n for (i in input.indices)\r\n {\r\n val playersCount = calcPlayers(input[i])\r\n result[i] = playersCount - 1\r\n }\r\n return result\r\n}\r\n\r\nprivate fun calcPlayers(input: Int): Int\r\n{\r\n var result = 1\r\n for (i in 1..input)\r\n {\r\n result *= 2\r\n }\r\n return result\r\n}", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4"} {"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}", "src_uid": "ac2e795cd44061db8da13e3947ba791b"} {"source_code": "fun main() {\n readLine()\n val s = readLine()!!\n var b = 1L\n var res = 0L\n\n s.forEach {\n if (it == 'B') res += b\n b *= 2\n }\n print(res)\n}", "src_uid": "d86a1b5bf9fe9a985f7b030fedd29d58"} {"source_code": "import java.util.*\nimport kotlin.math.max\n\nval reader = InputReader()\nfun main(args: Array) {\n val n = reader.nextInt()\n val str = reader.next()\n\n var res = 0\n for (ch in str)\n if (ch == '-')\n res = max(res - 1, 0)\n else res++\n println(res)\n}\n\nclass InputReader {\n var tokens = StringTokenizer(readLine())\n\n fun next() : String {\n while (!tokens.hasMoreTokens()) {\n tokens = StringTokenizer(readLine())\n }\n return tokens.nextToken()\n }\n\n fun nextInt() = next().toInt()\n fun nextLong() = next().toLong()\n fun nextDouble() = next().toDouble()\n fun readIntArray(size: Int) = IntArray(size) { nextInt() }\n fun readLongArray(size: Int) = LongArray(size) { nextLong() }\n}", "src_uid": "a593016e4992f695be7c7cd3c920d1ed"} {"source_code": "// https://codeforces.com/problemset/problem/791/A\n\nfun main(args: Array){\n var (limak, bob) = readInts()\n var numberOfYears = 0;\n while(limak <= bob){\n limak *= 3\n bob *= 2\n numberOfYears++\n }\n print(numberOfYears)\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", "src_uid": "a1583b07a9d093e887f73cc5c29e444a"} {"source_code": "import java.io.PrintWriter\nimport java.util.StringTokenizer\n\nfun main() {\n val n = readInt()\n val D = readInts(n).sortedDescending()\n\n val x = D[0]\n val set = HashSet()\n val y = D.first { y ->\n x % y != 0 || !set.add(y)\n }\n\n println(\"$x $y\")\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() }", "src_uid": "868407df0a93085057d06367aecaf9be"} {"source_code": "import kotlin.math.min\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (n, k) = readInts()\n val arr = readInts()\n var sol = 0\n for (kPos in 0 until k) {\n var ones = 0\n var twos = 0\n for (pos in kPos until n step k) if (arr[pos] == 1) ones++ else twos++\n sol += min(ones, twos)\n }\n print(sol)\n}\n", "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281"} {"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", "src_uid": "2ff85140e3f19c90e587ce459d64338b"} {"source_code": "fun main() {\n print(if (readLine()!!.replace(\"(144|14|1)\".toRegex(), \"\").isEmpty()) \"YES\" else \"NO\")\n}", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5"} {"source_code": "import java.util.*\n\nfun main() {\n val reader = Scanner(System.`in`)\n var n: Int=reader.nextInt();\n var array = arrayOfNulls(n);\n for(i in 0..n-1){\n array[i] = reader.nextInt();\n }\n array.sort();\n var tot: Int=0;\n for(i in 1..n-1 step 2){\n tot += array[i]!!;\n tot -= array[i-1]!!;\n }\n\n println(tot);\n\n}\n\n", "src_uid": "55485fe203a114374f0aae93006278d3"} {"source_code": "import java.util.Scanner\n\nfun main() {\n\n val sc = Scanner(System.`in`)\n val x : Int = sc.nextInt()\n val t : Int = sc.nextInt()\n var a = sc.nextInt()\n var b = sc.nextInt()\n val da : Int = sc.nextInt()\n val db : Int = sc.nextInt()\n\n for (i in 0 until t) {\n for (j in 0 until t) {\n if ((a - i * da) + (b - j * db) == x || a - i * da == x || b - j * db == x || x == 0) {\n print(\"YES\")\n return\n }\n }\n }\n\n print(\"NO\")\n\n}", "src_uid": "f98168cdd72369303b82b5a7ac45c3af"} {"source_code": "import java.util.*\n\nprivate class ModInt(x: Long) {\n\n companion object {\n const val MOD = 1e9.toLong() + 7\n }\n\n val x = (x % MOD + MOD) % MOD\n\n operator fun plus(other: ModInt): ModInt {\n return ModInt(x + other.x)\n }\n\n operator fun minus(other: ModInt): ModInt {\n return ModInt(x - other.x)\n }\n\n operator fun times(other: ModInt): ModInt {\n return ModInt(x * other.x)\n }\n\n operator fun div(other: ModInt): ModInt {\n return this * other.inv()\n }\n\n fun pow(exp: Long): ModInt {\n if (exp == 0L) return ModInt(1L)\n var a = pow(exp shr 1)\n a *= a\n if (exp and 1L == 0L) return a\n return this * a\n }\n\n fun inv(): ModInt {\n return this.pow(MOD - 2)\n }\n\n override fun equals(other: Any?): Boolean {\n if (this === other) return true\n if (javaClass != other?.javaClass) return false\n\n other as ModInt\n\n if (x != other.x) return false\n\n return true\n }\n\n override fun hashCode(): Int {\n return x.hashCode()\n }\n\n override fun toString(): String {\n return \"$x\"\n }\n\n}\n\nprivate fun fact(n: ModInt): ModInt {\n return (2..n.x).fold(ModInt(1L)) { acc, l -> acc * ModInt(l) }\n}\n\nprivate fun comb(n: ModInt, k: ModInt): ModInt {\n return fact(n) / fact(k) / fact(n - k)\n}\n\nfun main(args: Array) {\n val t = readLine()!!.toLong()\n //var comb1 = ModInt(1)\n for (i in 1..t) {\n var n = readLine()!!.toInt()\n var a= readLine()!!.split(' ').map{it.toInt()}\n// var b=a.sorted()\n var b=a\n var mm=100000\n var ans=0\n var i:Int=0\n var r=0\n for (j in 0 until n){\n i=a[j]\n if (i>0){\n if (mm > i){\n mm = i\n r=j\n }\n ans+=i\n }\n else if (i <0){\n if (mm > -i){\n mm = -i\n r=j\n }\n }\n }\n ans-=mm\n println(ans)\n var s:String=\"\"\n for (j in 0 until n){\n if ((a[j]<0 && j!=r) || (a[j]>0 && j==r)){\n //s+='0'\n print('0')\n }\n else{\n //s+='1'\n print('1')\n }\n }\n println()\n }\n}\n", "src_uid": "52b86006d324475ffcd1259f8e68fc54"} {"source_code": "\nimport java.io.OutputStream\nimport java.io.IOException\nimport java.io.InputStream\nimport java.util.stream.IntStream\nimport java.util.Arrays\nimport java.util.HashMap\nimport java.util.ArrayList\nimport java.io.OutputStreamWriter\nimport java.io.UncheckedIOException\nimport java.util.stream.Stream\nimport java.io.Closeable\nimport java.io.Writer\nimport java.util.function.ToIntFunction\n\n/**\n * Built using CHelper plug-in\n * Actual solution is at the top\n */\nobject programkt {\n @Throws(Exception::class)\n @JvmStatic\n fun main(args: Array) {\n val thread = Thread(null, TaskAdapter(), \"\", (1 shl 27).toLong())\n thread.start()\n thread.join()\n }\n\n internal class TaskAdapter : Runnable {\n override fun run() {\n val inputStream = System.`in`\n val outputStream = System.out\n val `in` = FastInput(inputStream)\n val out = FastOutput(outputStream)\n val solver = GMNumbers()\n solver.solve(1, `in`, out)\n out.close()\n }\n }\n\n internal class GMNumbers {\n var inf = 1e9.toInt() + 1\n\n fun solve(testNumber: Int, `in`: FastInput, out: FastOutput) {\n val m = `in`.readInt()\n var k = `in`.readInt()\n\n var mm = m\n for (i in 2..9) {\n while (mm % i == 0) {\n mm /= i\n }\n }\n if (mm != 1) {\n out.println(-1)\n return\n }\n\n val factorList = ArrayList(10000)\n run {\n var i = 1\n while (i * i <= m) {\n if (m % i != 0) {\n i++\n continue\n }\n factorList.add(i)\n if (m / i != i) {\n factorList.add(m / i)\n }\n i++\n }\n }\n val factors = factorList.stream().mapToInt(ToIntFunction { it.toInt() }).toArray()\n Arrays.sort(factors)\n val valToIndex = HashMap(factors.size)\n for (i in factors.indices) {\n valToIndex[factors[i]] = i\n }\n val transfer = Array(factors.size) { IntArray(10) }\n for (i in factors.indices) {\n for (j in 0..9) {\n transfer[i][j] = -1\n }\n }\n for (i in factors.indices) {\n for (j in 1..9) {\n if (factors[i] % j == 0) {\n transfer[i][j] = valToIndex[factors[i] / j]!!\n }\n }\n }\n\n val dp = ArrayList(100000)\n val firstState = IntArray(factors.size)\n for (i in firstState.indices) {\n if (factors[i] < 10) {\n firstState[i] = 1\n } else {\n firstState[i] = 0\n }\n }\n dp.add(firstState)\n while (dp[dp.size - 1][factors.size - 1] < k) {\n k -= dp[dp.size - 1][factors.size - 1]\n val last = dp[dp.size - 1]\n val next = IntArray(factors.size)\n for (i in factors.indices) {\n for (j in 1..9) {\n if (transfer[i][j] != -1) {\n next[i] = Math.min(next[i] + last[transfer[i][j]], inf)\n }\n }\n next[i] = Math.min(next[i], inf)\n }\n dp.add(next)\n }\n\n var len = dp.size - 1\n var state = factors.size - 1\n while (len > 0) {\n val last = dp[len - 1]\n for (i in 1..9) {\n if (transfer[state][i] != -1) {\n if (last[transfer[state][i]] < k) {\n k -= last[transfer[state][i]]\n } else {\n state = transfer[state][i]\n len--\n out.append(i)\n break\n }\n }\n }\n }\n\n out.append(factors[state])\n }\n\n }\n\n internal class FastInput(private val `is`: InputStream) {\n private val buf = ByteArray(1 shl 20)\n private var bufLen: Int = 0\n private var bufOffset: Int = 0\n private var next: Int = 0\n\n private fun read(): Int {\n while (bufLen == bufOffset) {\n bufOffset = 0\n try {\n bufLen = `is`.read(buf)\n } catch (e: IOException) {\n bufLen = -1\n }\n\n if (bufLen == -1) {\n return -1\n }\n }\n return buf[bufOffset++].toInt()\n }\n\n fun skipBlank() {\n while (next >= 0 && next <= 32) {\n next = read()\n }\n }\n\n fun readInt(): Int {\n var sign = 1\n\n skipBlank()\n if (next == '+'.toInt() || next == '-'.toInt()) {\n sign = if (next == '+'.toInt()) 1 else -1\n next = read()\n }\n\n var `val` = 0\n if (sign == 1) {\n while (next >= '0'.toInt() && next <= '9'.toInt()) {\n `val` = `val` * 10 + next - '0'.toInt()\n next = read()\n }\n } else {\n while (next >= '0'.toInt() && next <= '9'.toInt()) {\n `val` = `val` * 10 - next + '0'.toInt()\n next = read()\n }\n }\n\n return `val`\n }\n\n }\n\n internal class FastOutput(private val os: Writer) : AutoCloseable, Closeable, Appendable {\n private val cache = StringBuilder(10 shl 20)\n\n override fun append(csq: CharSequence): FastOutput {\n cache.append(csq)\n return this\n }\n\n override fun append(csq: CharSequence, start: Int, end: Int): FastOutput {\n cache.append(csq, start, end)\n return this\n }\n\n constructor(os: OutputStream) : this(OutputStreamWriter(os)) {}\n\n override fun append(c: Char): FastOutput {\n cache.append(c)\n return this\n }\n\n fun append(c: Int): FastOutput {\n cache.append(c)\n return this\n }\n\n fun println(c: Int): FastOutput {\n cache.append(c)\n println()\n return this\n }\n\n fun println(): FastOutput {\n cache.append(System.lineSeparator())\n return this\n }\n\n fun flush(): FastOutput {\n try {\n os.append(cache)\n os.flush()\n cache.setLength(0)\n } catch (e: IOException) {\n throw UncheckedIOException(e)\n }\n\n return this\n }\n\n override fun close() {\n flush()\n try {\n os.close()\n } catch (e: IOException) {\n throw UncheckedIOException(e)\n }\n\n }\n\n override fun toString(): String {\n return cache.toString()\n }\n\n }\n}\n\n", "src_uid": "d38877179ddbc55028d8f0a4da43cd46"} {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\nfun main() {\n output {\n val n = readInt()\n val k0 = readInt()\n\n val H = readIntArray(n)\n\n val m = H.indices.count { H[it] != H[(it + 1) % n] }\n val mc = ArrayModCombinatorics(m)\n\n val k = k0.toModInt()\n val km2 = k - 2\n\n val fn0 = k.pow(n-m) * (0..m/2).fold(ModInt(0)) { acc, i ->\n acc + mc.C(m, i) * mc.C(m-i, i) * km2.pow(m - 2 * i)\n }\n\n val ans = (k.pow(n) - fn0) / 2\n\n println(ans.int)\n }\n}\n\nclass ArrayModCombinatorics(val maxn: Int) {\n val factorial = ModIntArray(maxn + 1).also {\n it[0] = ModInt(1)\n for(i in 1..it.lastIndex) {\n it[i] = it[i-1] * i\n }\n }\n\n val invf = ModIntArray(maxn + 1) {\n factorial[it].inv_unmemoized()\n }\n\n fun P(n: Int, k: Int) = factorial[n] * invf[n-k]\n fun C(n: Int, k: Int) = factorial[n] * invf[k] * invf[n-k]\n}\n\nconst val MODINT_BASE = 998244353\nconst val MODINT_TOTIENT = MODINT_BASE - 1 // assumes MODINT_BASE is prime\n\ninline infix fun Int.umod(base: Int) = Math.floorMod(this, base)\ninline infix fun Long.umod(base: Long) = Math.floorMod(this, base)\ninline infix fun Long.umod(base: Int) = Math.floorMod(this, base.toLong()).toInt()\n\nfun Int.mulMod(other: Int, mod: Int) = (toLong() * other).umod(mod)\n\nfun Int.powMod(exponent: Int, mod: Int): Int {\n var res = 1L\n var e = exponent\n var b = umod(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\n\ninline fun Int.toModInt() = ModInt(this umod MODINT_BASE)\ninline fun Long.toModInt() = ModInt(this umod MODINT_BASE)\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt( val int: Int) {\n companion object {\n /** can't seem to make these private or inlined without causing compiler issues */\n @JvmField val _invMemo = HashMap()\n fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }\n }\n\n 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) exponent umod MODINT_TOTIENT else exponent\n return ModInt(int.powMod(e, MODINT_BASE))\n }\n\n fun pow(exponent: Long) = pow(exponent umod MODINT_TOTIENT)\n\n inline fun inverse() = inv_memoized() /** NOTE: Change if necessary */\n\n fun inv_unmemoized(): ModInt {\n require(int != 0) { \"Can't invert/divide by 0\" }\n return pow(MODINT_TOTIENT - 1)\n }\n inline fun inv_memoized() = _invMemoized(this)\n\n operator fun div(other: ModInt) = times(other.inverse())\n inline operator fun div(other: Int) = div(other.toModInt())\n\n override 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 fun contains(element: ModInt): Boolean = any { it == element }\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}\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 INPUT = File(\"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(\"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\n@JvmField val _reader = INPUT.bufferedReader()\nfun readLine(): String? = _reader.readLine()\nfun readLn() = _reader.readLine()!!\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\ninline fun output(block: PrintWriter.() -> Unit) { _writer.apply(block).flush() }\n\n/** shuffles and sort overrides to avoid quicksort attacks */\nprivate inline fun R._shuffle(rnd: Random, get: R.(Int) -> V, set: R.(Int, V) -> Unit, size: Int) {\n // Fisher-Yates shuffle algorithm\n for (i in size - 1 downTo 1) {\n val j = rnd.nextInt(i + 1)\n val temp = get(i)\n set(i, get(j))\n set(j, temp)\n }\n}\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\nfun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, IntArray::get, IntArray::set, size)\nfun IntArray.sort() { shuffle(); _sort() }\nfun IntArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, LongArray::get, LongArray::set, size)\nfun LongArray.sort() { shuffle(); _sort() }\nfun LongArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, DoubleArray::get, DoubleArray::set, size)\nfun DoubleArray.sort() { shuffle(); _sort() }\nfun DoubleArray.sortDescending() { shuffle(); _sortDescending() }\n\nfun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, CharArray::get, CharArray::set, size)\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\nfun `please stop removing these imports IntelliJ`() {\n iprintln(max(1, 2))\n}", "src_uid": "63c4006a0a6284f9825aaabfc4c28fd1"} {"source_code": "import java.util.*\n\nfun main(args: Array) {\n //var bf=System.currentTimeMillis()\n var sc=FastScanner()\n var p1=Pair(sc.nextInt(),sc.nextInt())\n var p2=Pair(sc.nextInt()-p1.first,sc.nextInt()-p1.second)\n p1=Pair(sc.nextInt(),sc.nextInt())\n\n if(p2.first%p1.first==0 && p2.second%p1.second==0 && Math.abs(p2.first/p1.first)%2 == Math.abs(p2.second /p1.second)%2) print(\"Yes\")\n else print(\"No\")\n\n\n\n //println();var af=System.currentTimeMillis();print(af-bf)\n\n}\n//____________________________________________________________________________\nclass FastScanner (var a:StringTokenizer=StringTokenizer(\"\")){\n fun next():String{\n if(!a.hasMoreTokens())a= StringTokenizer(readLine())\n return a.nextToken()\n }\n fun nextInt()=next().toInt()\n fun nextLong()=next().toLong()\n fun nextDouble()=next().toDouble()\n}", "src_uid": "1c80040104e06c9f24abfcfe654a851f"} {"source_code": "import kotlin.math.sqrt\n\nfun main() {\n val r = System.`in`.bufferedReader()\n val s1 = StringBuilder()\n //val (s, n) = r.readLine()!!.split(\" \").map { it.toInt() }\n val (a, b, c) = r.readLine()!!.split(\" \").map { it.toDouble() }\n val x = sqrt(a*b/c).toInt()\n val y = sqrt(a*c/b).toInt()\n val z = sqrt(b*c/a).toInt()\n println(4*(x+y+z))\n}", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc"} {"source_code": "fun main(args: Array) {\n val (n, k) = readLine()!!.split(\" \").map(String::toLong)\n val ans = if (k == 1L) n else n.toString(2).replace('0', '1').toLong(2)\n println(ans)\n}", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9"} {"source_code": "\nfun main(args : Array){\n\n var n = readLine()\n var text = readLine() + \" \"\n var max = 0\n var count = 0\n\n for (c in text) {\n if (c.isUpperCase()) {\n ++count\n } else if (c.toString() == \" \") {\n max = if (count > max) count else max\n count = 0\n }\n }\n\n println(max)\n}", "src_uid": "d3929a9acf1633475ab16f5dfbead13c"} {"source_code": "fun main() {\n val n = readLine()!!.toInt()\n println(\"0 0 $n\")\n}", "src_uid": "db46a6b0380df047aa34ea6a8f0f93c1"} {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"UNUSED_VARIABLE\")\n\nimport java.io.BufferedReader\nimport java.io.FileReader\nimport java.io.InputStreamReader\nimport java.util.*\n\nval ONLINE = System.getProperty(\"ONLINE_JUDGE\") != null\nval inp = BufferedReader(if (ONLINE) InputStreamReader(System.`in`) else FileReader(\"in.txt\"))\n\ninline fun readTokens() = inp.readLine()!!.split(' ')\ninline fun readInt() = inp.readLine()!!.toInt()\ninline fun readInt2() = readTokens().map { it.toInt() }.let { it[0] to it[1] }\ninline fun readLine() = inp.readLine()!!\n\nfun main(args: Array) {\n val (n, k) = readInt2()\n val s = readLine()\n val a = IntArray('z' - 'a' + 1) { 0 }\n s.forEach { a[it - 'a']++ }\n val r = a.max() ?: 0\n// println(Arrays.toString(a))\n// println(\"r = $r, k = $k\")\n println(if (k >= r) \"YES\" else \"NO\")\n}", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be"} {"source_code": "fun main() {\n val (n, k) = readLine()!!.split(\" \").map(String::toLong)\n print((n / k + 1) * k)\n}", "src_uid": "75f3835c969c871a609b978e04476542"} {"source_code": "import java.util.Scanner\nfun main(args:Array)\n{\n val read = Scanner(System.`in`)\n /*var a1: Long = Integer.valueOf(readLine()).toLong()\n var a2: Long = Integer.valueOf(readLine()).toLong()*/\n var a1 = read.nextInt()\n var a2 = read.nextInt()\n var count=0\n /*if(a1.equals(1) || a2.equals(1))\n println(0)*/\n while(a1>0 && a2>0 && (a1+a2)>2)\n {\n if(a1>a2)\n {\n a1 -= 2\n a2 += 1\n count++\n }\n else\n {\n a2 -= 2\n a1 += 1\n count++\n }\n }\n println(count)\n /*val num = Scanner(System.`in`)\n println(num)*/\n //println(\"hello world\")\n //println(age)\n}\n\n\n", "src_uid": "ba0f9f5f0ad4786b9274c829be587961"} {"source_code": "\nimport java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(args : Array) {\n Thread { run() }.start()\n}\nval vowels = sortedSetOf('a', 'e', 'i', 'o', 'u', 'y')\nfun isVowel(c:Char):Boolean{\n for(x in vowels)\n if(x == c)\n return true\n return false\n}\nval sc = Scanner(System.`in`)\nfun run() {\n val n = sc.nextInt()\n val s = sc.next()\n var out = ArrayList()\n var ok = false\n for(i in 0 until n){\n if(ok && isVowel(s[i]))continue;\n out.add(s[i])\n ok = (isVowel(s[i]))\n }\n for(c in out)\n print(c)\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\nfun IntArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun LongArray.print() {\n println(Arrays.toString(this))\n}\nfun Array.print() {\n for (i in this)\n i.print()\n}\nfun BooleanArray.print() {\n println(Arrays.toString(this))\n}\nfun nod(a: Long, b: Long): Long {\n var a1 = a\n var b1 = b\n while (a1 != 0L && b1 != 0L) {\n if (a1 < b1)\n b1 %= a1\n else\n a1 %= b1\n }\n return a1 + b1\n}\nfun nok(a: Long, b: Long): Long = a * b / nod(a, b)", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690"} {"source_code": "import java.io.PrintWriter\nimport kotlin.math.*\n\nfun main() {\n io.apply {\n\n val (n, k) = int to int\n val d = ints(n)\n\n var given = 0\n var stock = 0\n for (i in 0 until n) {\n stock += d[i]\n val g = min(stock, 8)\n stock -= g\n given += g\n if (given >= k) {\n cout .. i + 1 .. nl\n break\n }\n }\n if (given < k)\n cout .. -1 .. nl\n\n }.cout.flush()\n}\n\n// @formatter:off\nprivate val io = object {\n private val `in` = System.`in`\n private fun ll(): Long {\n var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }\n do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n\n }\n val int get() = ll().toInt(); val long get() = ll()\n fun ints(n: Int = int): IntArray { return IntArray(n) { int } }\n fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }\n val cout = PrintWriter(System.out); val nl = \"\\n\"\n private var buf = CharArray(32)\n private var bufSize = 32\n fun str(expect: Int = 32): String {\n var ix = 0\n var x: Int\n if (bufSize < expect)\n buf = CharArray(expect)\n do x = `in`.read() while (x < 33)\n do {\n if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }\n buf[ix++] = x.toChar()\n x = `in`.read()\n } while (x > 32)\n return java.lang.String.copyValueOf(buf, 0, ix)\n }\n operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(\" \"); return this }\n operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(\" \") }; return this }\n operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }\n} // @formatter:on\n\n/* ----------- */\n\n", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a"} {"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}", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce"} {"source_code": "import kotlin.math.min\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numDays, sumTime) = readInts()\n val mins = IntArray(numDays)\n val maxs = IntArray(numDays)\n for (i in 0 until numDays) {\n val (min, max) = readInts()\n mins[i] = min\n maxs[i] = max\n }\n val sumMins = mins.sum()\n if (sumTime in sumMins..maxs.sum()) {\n println(\"YES\")\n var diff = sumTime - sumMins\n val sols = IntArray(numDays)\n for (day in 0 until numDays) {\n val extras = min(diff, maxs[day] - mins[day])\n sols[day] = mins[day] + extras\n diff -= extras\n }\n print(sols.joinToString(\" \"))\n } else print(\"NO\")\n}", "src_uid": "f48ff06e65b70f49eee3d7cba5a6aed0"} {"source_code": "import java.util.*\n\nfun main(args: Array) = with(Scanner(System.`in`)) {\n val res = IntArray(3, { nextInt() }).sortedArray().meetsConditions()\n print(res)\n}\n\nfun IntArray.meetsConditions(): String {\n return when {\n this[0] == 1 -> \"YES\"\n this[0] == 2 && this[1] == 2 -> \"YES\"\n this[0] == 2 && this[1] == 4 && this[2] == 4 -> \"YES\"\n this[0] == 3 && this[2] == 3 -> \"YES\"\n else -> \"NO\"\n }\n}\n\n", "src_uid": "df48af9f5e68cb6efc1214f7138accf9"} {"source_code": "import java.io.*\nimport java.util.*\n\nclass Solution : Runnable {\n override fun run() {\n solve()\n }\n\n fun start() {\n Thread(null, Solution(), \"whatever\", (1 shl 27).toLong()).start()\n }\n}\n\nfun main(args: Array) {\n Solution().start()\n}\n\n\nclass IO {\n companion object {\n\n private val reader: InputReader\n private val writer: OutputWriter\n\n init {\n if (System.getProperty(\"ONLINE_JUDGE\") == null) {\n reader = InputReader(FileInputStream(\"/Users/300041735/competitiveProgramming/src/codeforces/in.txt\"))\n writer = OutputWriter(FileOutputStream(\"/Users/300041735/competitiveProgramming/src/codeforces/out.txt\"))\n } else {\n reader = InputReader(System.`in`)\n writer = OutputWriter(System.`out`)\n }\n }\n\n private fun readMultipleInts(count: Int): List {\n val map = mutableListOf()\n repeat(count) {\n map.add(reader.readInt())\n }\n return map\n }\n\n fun readInt() = reader.readInt()\n fun readLong() = reader.readLong()\n fun readTwoInts() = readMultipleInts(2)\n fun readThreeInts() = readMultipleInts(3)\n fun readFourInts() = readMultipleInts(4)\n fun readFiveInts() = readMultipleInts(5)\n fun readSixInts() = readMultipleInts(6)\n fun readString() = reader.readString()\n fun readTree(n: Int): MutableMap> {\n val graph = mutableMapOf>()\n repeat(n - 1) {\n val u = reader.readInt()\n val v = reader.readInt()\n if (!graph.containsKey(u)) graph[u] = mutableListOf()\n if (!graph.containsKey(v)) graph[v] = mutableListOf()\n graph[u]!!.add(v)\n graph[v]!!.add(u)\n }\n return graph\n }\n\n fun readIntArray(n: Int): IntArray {\n return IntArray(n) { readInt() }\n }\n\n fun readLongArray(n: Int): Array {\n return Array(n) { readLong() }\n }\n\n fun write(obj: Any) {\n writer.printLine(obj)\n }\n\n fun flushOutput() {\n writer.flush()\n }\n\n fun closeOutput() {\n writer.close()\n }\n }\n}\n\n\nclass MATH {\n companion object {\n\n val mod = 1000000007\n var ispre = false\n\n val factMod = Array(300002) { 1 }\n\n fun pre() {\n for (i in 2 until 300001) {\n factMod[i] = ((factMod[i - 1] * i.toLong()) % MATH.mod).toInt()\n }\n }\n\n fun gcd(a: Int, b: Int): Int {\n if (b == 0)\n return a\n return gcd(b, a % b)\n }\n\n fun gcd(a: Long, b: Long): Long {\n if (b == 0L)\n return a\n return gcd(b, a % b)\n }\n\n fun inverseMod(a: Int): Int {\n return powMod(a, mod - 2)\n }\n\n fun powMod(a: Int, b: Int): Int {\n //calculate a to the power b mod m\n if (b == 0) return 1\n return if (b % 2 == 1) {\n prodMod(a, powMod(a, b - 1))\n } else {\n val p = powMod(a, b / 2)\n prodMod(p, p)\n }\n }\n\n fun ncr(n: Int, r: Int): Int {\n if (!ispre) pre(); ispre = true\n return ((factMod[n].toLong() * inverseMod(((factMod[r].toLong() * factMod[n - r]) % mod).toInt())) % mod).toInt()\n }\n\n fun prodMod(val1: Int, val2: Int): Int {\n return ((val1.toLong() * val2) % mod).toInt()\n }\n\n }\n}\n\nfun solve() {\n\n\n val n = IO.readInt()\n val m = IO.readInt()\n var k = IO.readLong()\n\n k = n*m.toLong() - k + 1\n\n //loop over the ans\n var ansL = 0L\n var ansH = n*m.toLong()\n while (ansH - ansL > 1){\n //find the largest ans such that numbers greater than it are >= k\n val mid = (ansL + ansH)/2\n val count = getCount(n, m , mid) //how many numbers are strictly greater than this number\n if (count >= k){\n //we can still go higher\n ansL = mid\n }else{\n ansH = mid - 1\n }\n }\n\n val count = getCount(n, m , ansH)\n if (count >= k){\n IO.write(ansH + 1)\n }else{\n IO.write(ansL + 1)\n }\n\n IO.flushOutput()\n IO.closeOutput()\n}\n\nfun getCount(n : Int, m : Int, search : Long) : Long{\n var count = 0L\n for(i in 1 until n + 1){\n //over each of the row\n //i*j find the smallest j such that i*j > search -> ceil(search/i)\n val ans = (search + i )/i\n if (ans <= m) {\n count += m - ans + 1\n }\n }\n return count\n}\n\n\n\nfun isBitSet(num : Long, i : Int) : Boolean{\n return (num.and(1L.shl(i)) > 0)\n}\n\ndata class Graph(val edges: MutableMap>)\n\n\nclass MinSegmentTree(\n input: Array\n) {\n private val tree: Array\n private val lazy: Array\n\n constructor(size: Int) : this(Array(size) { Int.MAX_VALUE })\n\n init {\n val size = nextPowerOfTwo(input.size)\n tree = Array(2 * size) { Int.MAX_VALUE }\n lazy = Array(2 * size) { Int.MAX_VALUE }\n for (i in 0 until input.size) {\n tree[i + size] = input[i]\n }\n for (i in (size - 1) downTo 1) {\n tree[i] = Math.min(tree[leftChild(i)], tree[rightChild(i)])\n }\n }\n\n private fun updateTree(lowerRange: Int, upperRange: Int, lowerBound: Int, upperBound: Int, index: Int, value: Int) {\n updateLazyNode(index, lowerBound, upperBound, lazy[index])\n if (noOverlap(lowerRange, upperRange, lowerBound, upperBound)) return\n else if (completeOverlap(lowerRange, upperRange, lowerBound, upperBound)) updateLazyNode(index, lowerBound, upperBound, value)\n else {\n updateTree(lowerRange, upperRange, lowerBound, midIndex(lowerBound, upperBound), leftChild(index), value)\n updateTree(lowerRange, upperRange, midIndex(lowerBound, upperBound) + 1, upperBound, rightChild(index), value)\n tree[index] = Math.min(tree[leftChild(index)], tree[rightChild(index)])\n }\n }\n\n private fun queryTree(lowerRange: Int, upperRange: Int, lowerBound: Int, upperBound: Int, index: Int): Int {\n updateLazyNode(index, lowerBound, upperBound, lazy[index])\n if (noOverlap(lowerRange, upperRange, lowerBound, upperBound)) return Int.MAX_VALUE\n else if (completeOverlap(lowerRange, upperRange, lowerBound, upperBound)) return tree[index]\n else {\n return Math.min(queryTree(lowerRange, upperRange, lowerBound, midIndex(lowerBound, upperBound), leftChild(index)),\n queryTree(lowerRange, upperRange, midIndex(lowerBound, upperBound) + 1, upperBound, rightChild(index)))\n }\n }\n\n private fun updateLazyNode(index: Int, lowerBound: Int, upperBound: Int, delta: Int) {\n tree[index] += delta\n if (lowerBound != upperBound) {\n lazy[leftChild(index)] += delta\n lazy[rightChild(index)] += delta\n }\n lazy[index] = 0\n }\n\n fun getElements(N: Int): List {\n return tree.copyOfRange(tree.size / 2, tree.size / 2 + N).asList()\n }\n\n fun update(lowerRange: Int, upperRange: Int, value: Int) {\n updateTree(lowerRange, upperRange, 1, lazy.size / 2, 1, value)\n }\n\n fun query(lowerRange: Int, upperRange: Int): Int {\n return queryTree(lowerRange, upperRange, 1, lazy.size / 2, 1)\n }\n\n private fun noOverlap(l: Int, u: Int, lb: Int, ub: Int): Boolean = (lb > u || ub < l)\n\n private fun completeOverlap(l: Int, u: Int, lb: Int, ub: Int): Boolean = (lb >= l && ub <= u)\n\n\n private fun nextPowerOfTwo(num: Int): Int {\n var exponent = 2\n while (true) {\n if (exponent >= num) {\n return exponent\n }\n exponent *= 2\n }\n }\n\n private fun midIndex(l: Int, r: Int) = (l + r) / 2\n private fun parent(i: Int) = i / 2\n private fun leftChild(i: Int) = 2 * i\n private fun rightChild(i: Int) = 2 * i + 1\n\n}\n\nclass InputReader(private val stream: InputStream) {\n private val buf = ByteArray(1024)\n private var curChar: Int = 0\n private var numChars: Int = 0\n private val filter: SpaceCharFilter? = null\n\n fun read(): Int {\n if (numChars == -1)\n throw InputMismatchException()\n if (curChar >= numChars) {\n curChar = 0\n try {\n numChars = stream.read(buf)\n } catch (e: IOException) {\n throw InputMismatchException()\n }\n\n if (numChars <= 0)\n return -1\n }\n return buf[curChar++].toInt()\n }\n\n fun readInt(): Int {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n var sgn = 1\n if (c == '-'.toInt()) {\n sgn = -1\n c = read()\n }\n var res = 0\n do {\n if (c < '0'.toInt() || c > '9'.toInt())\n throw InputMismatchException()\n res *= 10\n res += c - '0'.toInt()\n c = read()\n } while (!isSpaceChar(c))\n return res * sgn\n }\n\n fun readLong(): Long {\n var c = read()\n while (isSpaceChar(c)) {\n c = read()\n }\n var sgn: Long = 1\n if (c == '-'.toInt()) {\n sgn = -1\n c = read()\n }\n var number: Long = 0\n do {\n number *= 10L\n number += (c - '0'.toInt()).toLong()\n c = read()\n } while (!isSpaceChar(c))\n return number * sgn\n }\n\n fun readString(): String {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n val res = StringBuilder()\n do {\n res.appendCodePoint(c)\n c = read()\n } while (!isSpaceChar(c))\n return res.toString()\n }\n\n fun isSpaceChar(c: Int): Boolean {\n return filter?.isSpaceChar(c)\n ?: (c == ' '.toInt() || c == '\\n'.toInt() || c == '\\r'.toInt() || c == '\\t'.toInt() || c == -1)\n }\n\n operator fun next(): String {\n return readString()\n }\n\n interface SpaceCharFilter {\n fun isSpaceChar(ch: Int): Boolean\n }\n}\n\nclass OutputWriter {\n private val writer: PrintWriter\n\n constructor(outputStream: OutputStream) {\n writer = PrintWriter(BufferedWriter(OutputStreamWriter(outputStream)))\n }\n\n constructor(writer: Writer) {\n this.writer = PrintWriter(writer)\n }\n\n fun print(vararg objects: Any) {\n for (i in objects.indices) {\n if (i != 0)\n writer.print(' ')\n writer.print(objects[i])\n }\n }\n\n fun printLine(vararg objects: Any) {\n print(*objects)\n writer.println()\n }\n\n fun close() {\n writer.close()\n }\n\n fun flush() {\n writer.flush()\n }\n\n}\n\nclass DinitzMaxFlowSolver(val n: Int, val s: Int, val t: Int, val graph: MutableMap>, val edgeMap: MutableMap, Edge>) {\n\n private val level = IntArray(n + 1) { -1 } //storing levels of each vertex in level graph\n var maxFlow = 0L\n\n init {\n solve()\n }\n\n fun solve() {\n val next = IntArray(n + 1) { 0 }\n while (bfs()) {\n Arrays.fill(next, 0)\n var flow = 0L\n do {\n maxFlow += flow\n flow = dfs(s, next, Long.MAX_VALUE)\n } while (flow != 0L)\n }\n }\n\n private fun dfs(at: Int, next: IntArray, flow: Long): Long {\n if (at == t) return flow\n var size = 0\n if (graph.containsKey(at)) size = graph[at]!!.size\n while (next[at] < size) {\n val edge = graph[at]!!.get(next[at])\n if (edge.remainingCapacity() > 0 && level[edge.to] == level[at] + 1) {\n val bottleNeck = dfs(edge.to, next, Math.min(flow, edge.remainingCapacity()))\n if (bottleNeck > 0) {\n edgeMap[Pair(edge.from, edge.to)]!!.flow += bottleNeck\n edgeMap[Pair(edge.to, edge.from)]!!.flow -= bottleNeck\n return bottleNeck\n }\n }\n next[at]++\n }\n return 0\n }\n\n private fun bfs(): Boolean {\n Arrays.fill(level, -1)\n val curLevel = ArrayDeque()\n curLevel.add(s)\n level[s] = 0\n\n while (curLevel.isNotEmpty()) {\n val top = curLevel.poll()\n if (graph.containsKey(top)) {\n graph[top]!!.forEach {\n if (it.remainingCapacity() > 0 && level[it.to] == -1) {\n level[it.to] = level[top] + 1\n curLevel.offer(it.to)\n }\n }\n }\n }\n return level[t] != -1\n }\n\n\n}\n\nclass Edge(val from: Int, val to: Int, val capacity: Long) {\n var flow = 0L\n fun remainingCapacity(): Long {\n return capacity - flow\n }\n}", "src_uid": "13a918eca30799b240ceb9de47507a26"} {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.*\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n val r = scanner.nextInt()\n val c = scanner.nextInt()\n val arr1 = TreeSet()\n val arr2 = TreeSet()\n for (i in 0 until r) {\n val str = scanner.next()\n for (j in 0 until c) {\n if (str[j] == 'S') {\n arr1.add(i)\n arr2.add(j)\n }\n }\n }\n var res = 0\n for (i in 0 until r)\n for (j in 0 until c)\n if (!arr1.contains(i) || !arr2.contains(j))\n res++\n println(res)\n\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\n//class Pair(var a: Int, var b: Int): Comparable {\n// override fun compareTo(other: Pair): Int {\n// return b - a - other.b + other.a\n// }\n//}", "src_uid": "ebaf7d89c623d006a6f1ffd025892102"} {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val tokenizer = StringTokenizer(readLine())\n val n = tokenizer.nextToken().toInt()\n val x = tokenizer.nextToken().toInt()\n val arrayTokenizer = StringTokenizer(readLine())\n var steps = x\n generateSequence { arrayTokenizer.takeIf { it.hasMoreTokens() }?.nextToken()?.toInt() }.forEach {\n if (it < x) {\n steps--\n } else if (it == x) {\n steps++\n }\n }\n println(steps)\n}", "src_uid": "21f579ba807face432a7664091581cd8"} {"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 if(t<10)printLine(Array(n){if(it==0)t else 0}.joinToString(\"\"))\n else if(n==1)printLine(\"-1\")\n else printLine(Array(n-1){if(it==0)t else 0}.joinToString(\"\"))\n output()\n}", "src_uid": "77ffc1e38c32087f98ab5b3cb11cd2ed"} {"source_code": "fun main() {\n val r = System.`in`.bufferedReader()\n val s = StringBuilder()\n val n = r.readLine()!!.toInt()\n //val day = r.readLine()!!.split(\" \").map { it.toInt() }\n val value = r.readLine()!!.split(\" \").map { it.toInt() }\n val new = mutableListOf>()\n for (i in 0..n-1){\n new += Pair(i+1, value[i])\n }\n new.sortBy { it.second }\n var left = 0\n var right = n-1\n repeat(n/2){\n println(\"${new[left++].first} ${new[right--].first}\")\n }\n}", "src_uid": "6e5011801ceff9d76e33e0908b695132"} {"source_code": "//Командировка\n\nfun main(args: Array) {\n\n val k = readLine()!!.trim().toInt()\n\n val monthStr = readLine()!!.trim().split(\" \")\n\n if (k == 0){\n println(0)\n return\n }\n\n val month : Array = Array(monthStr.size, {i -> monthStr[i].toInt() })\n\n month.sort()\n\n var len = 0\n var monthCount = 0\n\n for (i in month.size -1 downTo 0 ){\n\n //print(month[i].toString() + \" \")\n\n len += month[i]\n monthCount++\n\n if (len >= k){\n break\n }\n }\n\n //println()\n\n if (len < k){\n println(-1)\n }else{\n println(monthCount)\n }\n\n}", "src_uid": "59dfa7a4988375febc5dccc27aca90a8"} {"source_code": "import java.util.*\n\nfun main(args: Array) {\n val input = Scanner(System.`in`)\n val count = input.nextInt()\n val length = input.nextInt()\n\n val array = Array(count){0}\n for(i in 0 until count)\n array[i] = input.nextInt()\n\n val array2 = Array(count){0}\n for(i in 0 until count)\n array2[i] = input.nextInt()\n\n for(i in 0 until length) {\n for(j in 0 until array.size) {\n if(array[j] > 0) array[j]--\n else if(array[j] == 0) array[j] = length - 1\n }\n if(equals(array, array2)) {\n print(\"YES\")\n return\n }\n }\n print(\"NO\")\n}\n\n\nfun equals(array: Array, array2: Array): Boolean {\n for(i in 0 until array.size) {\n if(!array.contains(array2[i])) {\n return false\n }\n }\n return true\n}", "src_uid": "3d931684ca11fe6141c6461e85d91d63"} {"source_code": "const val MOD = (1e9 + 7).toLong()\r\n\r\n\r\nfun main() {\r\n val k = readLine()!!.toLong()\r\n var ans = 6L\r\n var step = 4L\r\n for (i in 2..k) {\r\n step = (step * step) % MOD\r\n ans = (ans * step) % MOD\r\n }\r\n println(ans)\r\n}", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4"} {"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", "src_uid": "956228e31679caa9952b216e010f9773"} {"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", "src_uid": "43308fa25e8578fd9f25328e715d4dd6"} {"source_code": "import java.io.*\nimport java.util.*\n\n@Suppress(\"NOTHING_TO_INLINE\")\ninline fun Number.isEven(): Boolean = this.toInt() and 1 == 0\n@Suppress(\"NOTHING_TO_INLINE\")\ninline fun Number.isOdd (): Boolean = this.toInt() and 1 == 1\n\nclass InputReader(val stream: InputStream) {\n val buf = ByteArray(1024)\n var curChar: Int = 0\n var numChars: Int = 0\n\n fun read(): Int {\n if (numChars == -1)\n throw InputMismatchException()\n if (curChar >= numChars) {\n curChar = 0\n try {\n numChars = stream.read(buf)\n } catch (e: IOException) {\n throw InputMismatchException()\n }\n if (numChars <= 0)\n return -1\n }\n return buf[curChar++].toInt()\n }\n\n fun nextInt(): Int {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n var sgn = 1\n if (c == 45) {\n sgn = -1\n c = read()\n }\n var res = 0\n do {\n if (c < 48 || c > 57)\n throw InputMismatchException()\n res *= 10\n res += c and 15\n c = read()\n } while (!isSpaceChar(c))\n return res * sgn\n }\n\n fun nextLong(): Long {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n var sgn = 1\n if (c == 45) {\n sgn = -1\n c = read()\n }\n var res: Long = 0\n do {\n if (c < 48 || c > 57)\n throw InputMismatchException()\n res *= 10\n res += c and 15\n c = read()\n } while (!isSpaceChar(c))\n return res * sgn\n }\n\n fun nextString(): String {\n var c = read()\n while (isSpaceChar(c))\n c = read()\n val res = StringBuilder()\n do {\n res.appendCodePoint(c)\n c = read()\n } while (!isSpaceChar(c))\n return res.toString()\n }\n\n fun isSpaceChar(c: Int): Boolean {\n return c == 32 || c == 10 || c == 13 || c == 9 || c == -1\n }\n}\n\nclass OutputWriter(val stream: OutputStream) {\n val buf = ByteArray(65536)\n var curPos: Int = 0\n\n fun write(c: Char) {\n if (buf.size - curPos < 1) flush()\n buf[curPos++] = c.toByte()\n }\n\n fun write(s: String) {\n if (buf.size - curPos < s.length) flush()\n var idx = 0\n var remaining = s.length\n while (remaining > buf.size) {\n while (curPos < buf.size) buf[curPos++] = s[idx++].toByte()\n flush()\n remaining -= buf.size\n }\n while (idx < s.length) buf[curPos++] = s[idx++].toByte()\n }\n\n fun flush() {\n stream.write(buf, 0, curPos)\n curPos = 0\n }\n}\n\nfun countDivs(n: Int): Int {\n var res = 0\n var i = 2\n while (i * i <= n) {\n if (n % i == 0) ++res\n ++i\n }\n --i\n return if (i * i == n) res * 2 + 1 else res * 2 + 2\n}\n\nfun main(args: Array) {\n if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))\n val ir = InputReader(System.`in`)\n val ow = OutputWriter(System.out)\n\n val a = ir.nextInt()\n val b = ir.nextInt()\n val c = ir.nextInt()\n val arr = IntArray(1000001)\n var answer = 0\n for (i in 1 .. a) {\n for (j in 1 .. b) {\n for (k in 1 .. c) {\n val key = i * j * k\n if (arr[key] == 0) {\n arr[key] = countDivs(key)\n }\n answer += arr[key]\n }\n }\n }\n ow.write(\"$answer\\n\")\n ow.flush()\n}\n", "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401"} {"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : InputReader, pw : PrintWriter) {\n\n val r1 : Int = ir.nextInt()\n val c1 : Int = ir.nextInt()\n val r2 : Int = ir.nextInt()\n val c2 : Int = ir.nextInt()\n val dis1 : Int = Math.abs(r1 - r2)\n val dis2 : Int = Math.abs(c1 - c2)\n val rest : Int = Math.abs(dis1 - dis2)\n\n if (r1 != r2 && c1 != c2)\n pw.print(\"2 \")\n else if (r1 != r2 || c1 != c2)\n pw.print(\"1 \")\n else\n pw.print(\"0 \")\n\n if (dis1 % 2 == dis2 % 2) {\n when {\n dis1 != dis2 -> pw.print(\"2 \")\n dis1 == dis2 -> pw.print(\"1 \")\n else -> pw.print(\"0 \")\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}", "src_uid": "7dbf58806db185f0fe70c00b60973f4b"} {"source_code": "import java.util.*\nfun main() {\n val s = Scanner(System.`in`)\n val a=s.nextLong()\n val b=s.nextLong();\n if(a%2==0L)\n println(if(b-a<=1L||a+2>b)-1 else \"$a ${a+1} ${a+2}\")\n else\n println(if(b-a<=1L||a+3>b)-1 else \"${a+1} ${a+2} ${a+3}\")\n}", "src_uid": "6c1ad1cc1fbecff69be37b1709a5236d"} {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n@file:OptIn(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)\n\nimport java.io.PrintWriter\nimport kotlin.math.*\nimport kotlin.random.Random\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n// val startTime = System.nanoTime()\n\n val numCases = 1//readInt()\n case@ for(case in 1..numCases) {\n// print(\"Case #$case: \")\n\n val n = readInt()\n val C = readIntArray(26)\n\n val h = n.shr(2).shl(1) + min(2, n and 3)\n\n fun id(j: Int, k: Int, l: Int, m: Int) = j\n .times(h+1).plus(k)\n .times(3).plus(l)\n .times(3).plus(m)\n\n var D = ModIntArray(id(h, h, 2, 2)+1)\n\n for(l in 0..2) for(m in 0..2) {\n val j = (l == 0).toInt() + (m == 0).toInt()\n val k = (l == 1).toInt() + (m == 1).toInt()\n\n var d = ModInt(1)\n if(l == 2) d *= 24\n if(m == 2) d *= 24\n\n D[id(j, k, l, m)] = d\n }\n\n for(i in 2 until n) {\n val Di = ModIntArray(D.size)\n for(j in 0..min(h, i)) for(k in 0..min(h, i-j)) for(l in 0..2) for(m in 0..2) {\n val d = D[id(j, k, l, m)]\n if(d.int == 0) continue\n for(p in 0..2) {\n val dn = if(p == 2) {\n if(l == 2) d*23 else d*24\n } else {\n if(p == l) continue else d\n }\n\n val jn = j + (p == 0).toInt()\n val kn = k + (p == 1).toInt()\n Di[id(jn, kn, m, p)] += dn\n }\n }\n D = Di\n }\n\n val S = Array(h+2) { ModIntArray(h+2) }\n\n for(j in 0..h) for(k in 0..h) {\n S[j+1][k+1] = S[j+1][k] + S[j][k+1] - S[j][k]\n for(l in 0..2) for(m in 0..2) S[j+1][k+1] += D[id(j, k, l, m)]\n }\n\n fun S(a: Int, b: Int, c: Int, d: Int): ModInt {\n val a = min(h+1, a)\n val b = min(h+1, b)\n val c = min(h+1, c)\n val d = min(h+1, d)\n\n return S[c][d] - S[a][d] - S[c][b] + S[a][b]\n }\n\n var ans = S[h+1][h+1]\n\n for(i in 0 until 26) {\n ans -= S(C[i]+1, 0, n, n)\n for(j in i+1 until 26) {\n ans += S(C[i]+1, C[j]+1, n, n)\n }\n }\n\n println(ans.int)\n }\n\n// iprintln(\"Time: ${(System.nanoTime() - startTime) / 1000000} ms\")\n}\n\nfun h(n: Int) = n.shr(2).shl(1) + min(2, n and 3)\nfun Boolean.toInt() = if(this) 1 else 0\n\nconst val MOD = 998244353\nconst val TOTIENT = MOD - 1 // assumes MOD is prime\n\ninfix fun Int.modulo(mod: Int): Int = (this % mod).let { (it shr Int.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.modulo(mod: Long) = (this % mod).let { (it shr Long.SIZE_BITS - 1 and mod) + it }\ninfix fun Long.modulo(mod: Int) = modulo(mod.toLong()).toInt()\n\nfun Int.mulMod(other: Int, mod: Int) = toLong() * other modulo mod\n\nfun Int.powMod(exponent: Long, mod: Int): Int {\n if(exponent < 0) error(\"Inverse not implemented\")\n if(mod == 1) return 0\n var res = 1L\n var e = exponent\n var b = modulo(mod).toLong()\n\n while(e > 0) {\n if(e and 1 == 1L) {\n res = res * b % mod\n }\n e = e shr 1\n b = b * b % mod\n }\n return res.toInt()\n}\nfun Int.powMod(exponent: Int, mod: Int) = powMod(exponent.toLong(), mod)\nfun Int.modPowArray(n: Int, mod: Int): IntArray {\n val res = IntArray(n+1)\n res[0] = 1\n for(i in 1..n) res[i] = mulMod(res[i-1], mod)\n return res\n}\n\ninline fun Int.toModInt() = ModInt(this modulo MOD)\ninline fun Long.toModInt() = ModInt(this modulo MOD)\n\n/** note: Only use constructor for int within modulo range, otherwise use toModInt **/\ninline class ModInt(val int: Int) {\n companion object {\n /** can't seem to make these private or inlined without causing compiler issues */\n @JvmField val _invMemo = HashMap()\n fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }\n }\n\n // normalizes an integer that's within range [-MOD, MOD) without branching\n private inline fun normalize(int: Int) = ModInt((int shr Int.SIZE_BITS - 1 and MOD) + int)\n\n operator fun plus(other: ModInt) = normalize(int + other.int - MOD) // overflow-safe even if MOD >= 2^30\n inline operator fun plus(other: Int) = plus(other.toModInt())\n operator fun inc() = normalize(int + (1 - MOD))\n\n operator fun minus(other: ModInt) = normalize(int - other.int)\n inline operator fun minus(other: Int) = minus(other.toModInt())\n operator fun dec() = normalize(int - 1)\n operator fun unaryMinus() = normalize(-int)\n\n operator fun times(other: ModInt) = ModInt((int.toLong() * other.int % MOD).toInt())\n inline operator fun times(other: Int) = ModInt(int.mulMod(other, MOD))\n\n fun pow(exponent: Int): ModInt {\n val e = if(exponent < 0) {\n require(int != 0) { \"Can't invert/divide by 0\" }\n exponent modulo TOTIENT\n } else exponent\n return ModInt(int.powMod(e, MOD))\n }\n\n fun pow(exponent: Long) = if(int == 0) when {\n exponent > 0 -> this\n exponent == 0L -> ModInt(1)\n else -> error(\"Can't invert/divide by 0\")\n } else pow(exponent modulo TOTIENT)\n\n inline fun inverse() = inv_unmemoized() /** NOTE: Change if necessary */\n\n fun inv_unmemoized(): ModInt {\n require(int != 0) { \"Can't invert/divide by 0\" }\n return pow(TOTIENT - 1)\n }\n inline fun inv_memoized() = _invMemoized(this)\n\n operator fun div(other: ModInt) = times(other.inverse())\n inline operator fun div(other: Int) = div(other.toModInt())\n\n override inline fun toString() = int.toString()\n}\n\ninline operator fun Int.plus(modInt: ModInt) = modInt + this\ninline operator fun Int.minus(modInt: ModInt) = toModInt() - modInt\ninline operator fun Int.times(modInt: ModInt) = modInt * this\ninline operator fun Int.div(modInt: ModInt) = modInt.inverse() * this\n\ninline class ModIntArray(val intArray: IntArray): Collection {\n inline operator fun get(i: Int) = ModInt(intArray[i])\n inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }\n\n override inline val size: Int get() = intArray.size\n inline val lastIndex get() = intArray.lastIndex\n inline val indices get() = intArray.indices\n\n override inline fun contains(element: ModInt): Boolean = element.int in intArray\n\n override fun containsAll(elements: Collection): Boolean = elements.all(::contains)\n\n override inline fun isEmpty(): Boolean = intArray.isEmpty()\n\n override fun iterator(): Iterator = object: Iterator {\n var index = 0\n override fun hasNext(): Boolean = index < size\n override fun next(): ModInt = get(index++)\n }\n\n fun copyOf(newSize: Int) = ModIntArray(intArray.copyOf(newSize))\n fun copyOf() = copyOf(size)\n}\nfun ModIntArray.copyInto(destination: ModIntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =\n ModIntArray(intArray.copyInto(destination.intArray, destinationOffset, startIndex, endIndex))\ninline fun ModIntArray(size: Int) = ModIntArray(IntArray(size))\ninline fun ModIntArray(size: Int, init: (Int) -> ModInt) = ModIntArray(IntArray(size) { init(it).int })\n\nfun ModInt.powArray(n: Int) = ModIntArray(int.modPowArray(n, MOD))\n\ninline fun ModIntArray.first() = get(0)\ninline fun ModIntArray.last() = get(lastIndex)\ninline fun ModIntArray.joinToString(separator: CharSequence) = intArray.joinToString(separator)\ninline fun ModIntArray.fold(init: R, op: (acc: R, ModInt) -> R) = intArray.fold(init) { acc, i -> op(acc, ModInt(i)) }\ninline fun ModIntArray.foldRight(init: R, op: (ModInt, acc: R) -> R) = intArray.foldRight(init) { i, acc -> op(ModInt(i), acc) }\nfun ModIntArray.sum() = fold(ModInt(0), ModInt::plus)\nfun ModIntArray.product() = fold(ModInt(1), ModInt::times)\n\ninline fun Iterable.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Iterable.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\ninline fun Sequence.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Sequence.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\ninline fun Array.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }\ninline fun Array.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }\nfun Iterable.sum() = sumByModInt { it }\nfun Sequence.sum() = sumByModInt { it }\nfun Iterable.product() = productByModInt { it }\nfun Sequence.product() = productByModInt { it }\nfun Collection.toModIntArray() = ModIntArray(size).also { var i = 0; for(e in this) { it[i++] = e } }\n\n/** IO */\n//@JvmField val ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n//const val PATH = \"src/main/resources/\"\n//@JvmField val INPUT = File(PATH + \"input.txt\").inputStream()\n//@JvmField val OUTPUT = File(PATH + \"output.txt\").outputStream()\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n\nconst val _BUFFER_SIZE = 1 shl 16\n@JvmField val _buffer = ByteArray(_BUFFER_SIZE)\n@JvmField var _bufferPt = 0\n@JvmField var _bytesRead = 0\n\ntailrec fun readChar(): Char {\n if(_bufferPt == _bytesRead) {\n _bufferPt = 0\n _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)\n }\n return if(_bytesRead < 0) Char.MIN_VALUE\n else {\n val c = _buffer[_bufferPt++].toChar()\n if (c == '\\r') readChar() else c\n }\n}\n\n/** @param skipNext Whether to skip the next character (usually whitespace), defaults to true */\nfun readCharArray(n: Int, skipNext: Boolean = true): CharArray {\n val res = CharArray(n) { readChar() }\n if(skipNext) readChar()\n return res\n}\n\nfun readLine(): String? {\n var c = readChar()\n return if(c == Char.MIN_VALUE) null\n else buildString {\n while(c != '\\n' && c != Char.MIN_VALUE) {\n append(c)\n c = readChar()\n }\n }\n}\nfun readLn() = readLine()!!\n\nfun read() = buildString {\n var c = readChar()\n while(c <= ' ') {\n if(c == Char.MIN_VALUE) return@buildString\n c = readChar()\n }\n do {\n append(c)\n c = readChar()\n } while(c > ' ')\n}\nfun readInt() = read().toInt()\nfun readDouble() = read().toDouble()\nfun readLong() = read().toLong()\nfun readStrings(n: Int) = List(n) { read() }\nfun readLines(n: Int) = List(n) { readLn() }\nfun readInts(n: Int) = List(n) { read().toInt() }\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\nfun readLongs(n: Int) = List(n) { read().toLong() }\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\n\n/** sort overrides to avoid quicksort attacks */\n\n@JvmField var _random: Random? = null\nval random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }\n\ninline fun _mergeSort(a0: A, n: Int, tmp0: A, get: A.(Int) -> T, set: A.(Int, T) -> Unit, cmp: (T, T) -> Int) {\n var a = a0\n var tmp = tmp0\n var len = 1\n while(len < n) {\n var l = 0\n while(true) {\n val m = l + len\n if(m >= n) break\n val r = min(n, m + len)\n var i = l\n var j = m\n for(k in l until r) {\n if(i != m && (j == r || cmp(a.get(i), a.get(j)) <= 0)) {\n tmp.set(k, a.get(i++))\n } else tmp.set(k, a.get(j++))\n }\n l = r\n }\n for(i in l until n) tmp.set(i, a.get(i))\n val t = a; a = tmp; tmp = t\n len += len\n }\n if(a !== a0) for(i in 0 until n) a0.set(i, tmp0.get(i))\n}\n\ninline fun IntArray.sortWith(cmp: (Int, Int) -> Int) { _mergeSort(this, size, IntArray(size), IntArray::get, IntArray::set, cmp) }\ninline fun > IntArray.sortBy(func: (Int) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > IntArray.sortByDescending(func: (Int) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun IntArray.sort() { sortBy { it } }\nfun IntArray.sortDescending() { sortByDescending { it } }\n\ninline fun LongArray.sortWith(cmp: (Long, Long) -> Int) { _mergeSort(this, size, LongArray(size), LongArray::get, LongArray::set, cmp) }\ninline fun > LongArray.sortBy(func: (Long) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > LongArray.sortByDescending(func: (Long) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun LongArray.sort() { sortBy { it } }\nfun LongArray.sortDescending() { sortByDescending { it } }\n\ninline fun DoubleArray.sortWith(cmp: (Double, Double) -> Int) { _mergeSort(this, size, DoubleArray(size), DoubleArray::get, DoubleArray::set, cmp) }\ninline fun > DoubleArray.sortBy(func: (Double) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }\ninline fun > DoubleArray.sortByDescending(func: (Double) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }\nfun DoubleArray.sort() { sortBy { it } }\nfun DoubleArray.sortDescending() { sortByDescending { it } }\n\ninline fun CharArray.sort() { _sort() }\ninline fun CharArray.sortDescending() { _sortDescending() }\n\ninline fun > Array.sort() = _sort()\ninline fun > Array.sortDescending() = _sortDescending()\ninline fun > MutableList.sort() = _sort()\ninline fun > MutableList.sortDescending() = _sortDescending()\n\n// import preserving junk function\n@Suppress(\"NonAsciiCharacters\") fun 雪花飄飄北風嘯嘯天地一片蒼茫() { 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 }", "src_uid": "1f012349f4b229dc98faadf1ca732355"} {"source_code": "fun main() {\n val n = readLine()!!.toLong()\n print(if (n % 10L <= 5L) n - n % 10L else n + 10L - (n % 10L))\n}", "src_uid": "29c4d5fdf1328bbc943fa16d54d97aa9"} {"source_code": "fun main() {\n print((readLine()!!.toInt() - 1) / 2)\n}", "src_uid": "dfe9446431325c73e88b58ba204d0e47"} {"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}", "src_uid": "04ca137d0383c03944e3ce1c502c635b"} {"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() }", "src_uid": "a2fcad987e9b2bb3e6395654cd4fcfbb"} {"source_code": "fun main() {\n fun readInt() = readLine()!!.toInt()\n\n val numCases = readInt()\n val sols = BooleanArray(numCases)\n for (numCase in 0 until numCases) {\n val n = readInt()\n for (b in 0 .. n / 7)\n if ((n - 7 * b) % 3 == 0) {\n sols[numCase] = true\n break\n }\n }\n\n print(sols.joinToString(System.lineSeparator()) { b -> if (b) \"YES\" else \"NO\" })\n}", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452"} {"source_code": "import kotlin.math.max\n\n/**\n *\n *This solution works due to the small input, but the solution is O(n^2). A linear solution can be found here:\n * https://codeforces.com/contest/388/submission/8807640\n * This solution uses -~f, which is the same than (f+1). If f is 3, ~f is -4 and -~f is 4. Probably uses it to save\n * some characters. The kotlin version of this solution is below\n */\n\n//fun main() {\n// fun readInt() = readLine()!!.toInt()\n// fun readLong() = readLine()!!.toLong()\n// fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n// fun readLongs() = readLine()!!.split(\" \").map(String::toLong)\n//\n// val n = readInt()\n// var xs = readInts().sorted()\n// var sol = 0\n// while (xs.isNotEmpty()) {\n// sol++\n// var numElements = 0\n// val newXs = mutableListOf()\n// for (x in xs) {\n// if (x >= numElements) numElements++ else newXs.add(x)\n// }\n// xs = newXs\n// }\n// print(sol)\n//}\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n readLine()\n val xs = readInts().sorted()\n var sol = 0\n for((index, x) in xs.withIndex()) sol = max(sol, index / (x+1))\n print(sol + 1)\n}\n", "src_uid": "7c710ae68f27f140e7e03564492f7214"} {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.math.ceil\nimport kotlin.math.floor\nimport kotlin.math.log2\nimport kotlin.math.sqrt\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n val k = scanner.nextInt()\n val arr = IntArray(n) { scanner.nextInt() }\n var res = 0\n for (i in arr) {\n if (i > k)\n break\n res++\n }\n if (res == n) {\n print(n)\n return\n }\n for (i in arr.reversed()) {\n if (i > k)\n break\n res++\n }\n println(res)\n}\n\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\n//class Pair(var a: Int, var b: Int): Comparable {\n// override fun compareTo(other: Pair): Int {\n// return b - a - other.b + other.a\n// }\n//}", "src_uid": "ecf0ead308d8a581dd233160a7e38173"} {"source_code": "import kotlin.math.max\nimport kotlin.math.min\n\nfun readIntList() = readLine()!!.split(' ').map(String::toInt).toMutableList()\nfun readLongList() = readLine()!!.split(' ').map(String::toLong).toMutableList()\nfun readStringList() = readLine()!!.split(' ').toMutableList()\nfun readInt() = readLine()!!.toInt()\nfun readLong() = readLine()!!.toLong()\n\nfun main(args: Array) {\n\n val (n, k) = readIntList()\n val s = readLine()!!\n val alphabet = Array(26, { -1 })\n val lastAlphabet = Array(26, { -1 })\n s.forEachIndexed { index, ch ->\n lastAlphabet[ch - 'A'] = index\n }\n\n\n var count = 0\n var isSuccess = true\n s.forEachIndexed { index, ch ->\n val i = ch - 'A'\n if(alphabet[i] == -1)\n count ++\n\n if(count > k)\n isSuccess = false\n\n alphabet[i] = index\n if(lastAlphabet[i] == index)\n count --\n }\n\n if (isSuccess)\n println(\"NO\")\n else\n println(\"YES\")\n\n}\n\n\nclass Custom(\n val p: Int,\n val s: Int\n) {\n\n}", "src_uid": "216323563f5b2dd63edc30cb9b4849a5"} {"source_code": "import java.io.*\nimport java.lang.Math.abs\nimport java.util.*\n\nfun solve(cin: FastReader, out: PrintWriter) {\n val n = cin.int()\n val m = cin.int()\n var cnt = 0\n var part = 0\n for (i in 1..m)\n for (j in 1..m)\n if ((i * i.toLong() + j * j.toLong()) % m == 0.toLong())\n cnt++\n for (i in 1..(n % m))\n for (j in 1..(n % m))\n if ((i * i.toLong() + j * j.toLong()) % m == 0.toLong())\n part++\n var c = 0\n for (i in 1..m)\n for (j in 1..(n % m))\n if ((i * i.toLong() + j * j.toLong()) % m == 0.toLong())\n c++\n out.print((n / m).toLong() * (n / m).toLong() * cnt + part + (n / m).toLong() * 2 * c)\n}\n\n\n\nclass FastReader(input: InputStream) {\n private val br = BufferedReader(InputStreamReader(input))\n private var st = StringTokenizer(\"\")\n\n fun next(): String {\n while (!st.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n\n return st.nextToken()\n }\n\n fun int(): Int {\n return next().toInt()\n }\n\n fun double(): Double {\n return next().toDouble()\n }\n\n fun long(): Long {\n return next().toLong()\n }\n\n /**\n * Warning! Use carefully!\n */\n fun nextLine(): String {\n return br.readLine()\n }\n}\n\nfun main(args: Array) {\n val cin = FastReader(System.`in`)\n val out = PrintWriter(BufferedOutputStream(System.out))\n solve(cin, out)\n out.flush()\n}\n\n", "src_uid": "2ec9e7cddc634d7830575e14363a4657"} {"source_code": "import java.lang.String.format\nimport java.util.*\nimport kotlin.math.*\nimport kotlin.system.exitProcess\n \nprivate fun readLn() = readLine()!! // string line\nprivate fun readInt() = readLn().toInt() // single int\nprivate fun readLong() = readLn().toLong() // single long\nprivate fun readDouble() = readLn().toDouble() // single double\nprivate fun readStrings() = readLn().split(\" \") // list of strings\nprivate fun readInts() = readStrings().map { it.toInt() } // list of ints\nprivate fun readLongs() = readStrings().map { it.toLong() } // list of longs\nprivate fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles\nfun main(){\n val reader=Scanner(System.`in`)\n var (a,b,x)=readInts()\n var s=\"0\"\n var t=\"1\"\n if(a<=b){\n s=\"1\"\n t=\"0\"\n a=b.also{\n b=a\n }\n }\n for(i in 0 until x/2){\n print(s+t)\n a--\n b--\n }\n if(x%2==0){\n for(i in 0 until b){\n print(t)\n }\n for(i in 0 until a){\n print(s)\n }\n }\n else{\n for(i in 0 until a){\n print(s)\n }\n for(i in 0 until b){\n print(t)\n }\n }\n}", "src_uid": "ef4123b8f3f3b511fde8b79ea9a6b20c"} {"source_code": "import java.util.*\n\nfun main(args: Array) {\n\n val n:Int = readLine()!!.toInt()\n val a:ArrayList = readLine()!!.split(' ').map{ it -> it.toInt()} as ArrayList\n\n var ans = 1000000\n for(i in 1..n-2) {\n var b = ArrayList(a)\n b.removeAt(i)\n var mx = 0\n for(j in 1..b.size-1) {\n mx = Math.max(mx, b[j] - b[j-1])\n }\n ans = Math.min(ans, mx)\n }\n\n println(ans)\n\n\n}", "src_uid": "8a8013f960814040ac4bf229a0bd5437"} {"source_code": "import kotlin.math.max\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (numDays, numKilos) = readInts()\n val prices = readInts()\n var best = 0\n for (day in 0 until numDays - 1)\n best = max(best, prices[day] - prices[day + 1] - numKilos)\n print(best)\n}", "src_uid": "411539a86f2e94eb6386bb65c9eb9557"} {"source_code": "//rextester.com:1.1--codeforces.com:1.0.5-2\nfun main(args:Array){\n val a=readLine()!!.toInt()*2;var b=false\n for(i in 1..Math.sqrt(a.toDouble()).toInt()-1){\n val c=a-i*i-i;val d=Math.sqrt(c.toDouble()).toInt()\n if(d*(d+1)==c)b=true\n }\n print(\"${if(b)\"YES\" else \"NO\"}\")\n}", "src_uid": "245ec0831cd817714a4e5c531bffd099"} {"source_code": "@file:Suppress(\"NOTHING_TO_INLINE\", \"EXPERIMENTAL_FEATURE_WARNING\", \"OVERRIDE_BY_INLINE\")\n\nimport java.io.PrintWriter\nimport java.util.StringTokenizer\nimport kotlin.math.*\nimport kotlin.random.*\nimport kotlin.collections.sort as _sort\nimport kotlin.collections.sortDescending as _sortDescending\nimport kotlin.io.println as iprintln\n\n/** @author Spheniscine */\nfun main() { _writer.solve(); _writer.flush() }\nfun PrintWriter.solve() {\n val p = readPoint()\n val q = readPoint()\n val r = readPoint()\n\n val pq = p.perpendicularBisector(q)\n val qr = q.perpendicularBisector(r)\n val center = pq.intersection(qr)!! // circumcenter\n\n val (a, b, c) = listOf(p, q, r).map { (it - center).atan2() }\n\n val ab = (b - a) / tau\n val ac = (c - a) / tau\n\n val n = (3..100).first { (ab * it).isNearInteger() && (ac * it).isNearInteger() }\n val rad = center.distanceTo(p)\n\n val area = rad * rad * n * sin(tau / n) / 2\n println(area)\n}\n\nconst val eps = 1e-6\nconst val tau = 2 * PI\n\ninfix fun Double.isNear(other: Double) = isNear(other, eps)\nfun Double.isNear(other: Double, eps: Double): Boolean {\n if(abs(this - other) <= eps) return true\n if(abs(this) <= eps || abs(other) <= eps) return false\n return abs((this - other) / this) <= eps ||\n abs((this - other) / other) <= eps\n}\nfun Double.isNearInteger() = isNear(round(this))\n\ndata class Point(val x: Double, val y: Double) {\n fun lineTo(q: Point): Line {\n val a = q.y - y\n val b = x - q.x\n val c = a * x + b * y\n return Line(a, b, c)\n }\n\n fun perpendicularBisector(q: Point) : Line {\n val a = q.y - y\n val b = x - q.x\n\n val m = mid(q)\n\n return Line(-b, a, -b * m.x + a * m.y)\n }\n\n fun mid(q: Point) = Point((x + q.x)/2, (y + q.y)/2)\n\n operator fun minus(o: Point) = Point(x - o.x, y - o.y)\n\n fun atan2() = atan2(y, x)\n\n fun distanceTo(q: Point) = hypot(q.x - x, q.y - y)\n}\nfun readPoint() = Point(readDouble(), readDouble())\n\ndata class Line(val a: Double, val b: Double, val c: Double) {\n fun intersection(o: Line): Point? {\n val det = a * o.b - o.a * b\n if(det == 0.0) return null\n val x = o.b * c - b * o.c\n val y = a * o.c - o.a * c\n return Point(x/det, y/det)\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}", "src_uid": "980f4094b3cfc647d6f74e840b1bfb62"} {"source_code": "import java.io.BufferedReader\r\n\r\nfun main() {\r\n fun gcd(p: Int, q: Int): Int {\r\n return if (p == 0) q\r\n else if (q == 0) p\r\n else if (p and 1 == 0 && q and 1 == 0) gcd(p shr 1, q shr 1) shl 1\r\n else if (p and 1 == 0) gcd(p shr 1, q)\r\n else if (q and 1 == 0) gcd(p, q shr 1)\r\n else if (p > q) gcd((p - q) shr 1, q)\r\n else gcd(p, (q - p) shr 1)\r\n }\r\n\r\n val br = System.`in`.bufferedReader()\r\n val sb = StringBuilder()\r\n val t = br.readInt()\r\n repeat(t) {\r\n val p = br.readInt()\r\n sb.append(100 / gcd(100, p)).append(\"\\n\")\r\n }\r\n print(sb)\r\n}\r\n\r\nprivate const val SPACE_INT = ' '.toInt()\r\nprivate const val ZERO_INT = '0'.toInt()\r\nprivate const val NL_INT = '\\n'.toInt()\r\n\r\nprivate fun BufferedReader.readInt(): Int {\r\n var ret = read()\r\n while (ret <= SPACE_INT) {\r\n ret = read()\r\n }\r\n val neg = ret == '-'.toInt()\r\n if (neg) {\r\n ret = read()\r\n }\r\n ret -= ZERO_INT\r\n var read = read()\r\n while (read >= ZERO_INT) {\r\n ret *= 10\r\n ret += read - ZERO_INT\r\n read = read()\r\n }\r\n\r\n while (read <= SPACE_INT && read != -1 && read != NL_INT) {\r\n mark(1)\r\n read = read()\r\n }\r\n if (read > SPACE_INT) {\r\n reset()\r\n }\r\n return if (neg) -ret else ret\r\n}", "src_uid": "19a2bcb727510c729efe442a13c2ff7c"} {"source_code": "fun main(vararg args: String) {\n val n = readLine()!!.toInt()\n println(when (n) {\n in 1..9 -> 1\n else -> {\n val l = Math.log10(n.toDouble()).toInt()\n val p = Math.pow(10.0, l.toDouble()).toInt()\n// println(\"$l, $p\")\n p - n % p\n }\n })\n}\n", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e"} {"source_code": "import java.util.*;\n\nfun main() {\n\tfun len(x: Int): Long {\n\t\treturn x.toString().length.toLong()\n\t}\n\tfun get(x: Int): Long {\n\t\treturn (9*Math.pow(10.0, (x-1).toDouble())).toLong() \n\t}\n\tvar n = readLine()!!.toInt()\n\tvar totalLen = len(n)\n\tvar x = 0L\n\tvar ans = 0L\n\tfor(i in 1..totalLen-1) {\n\t\tvar curr = get(i.toInt())\n\t\tx += curr\n\t\tans += curr*i\n\t}\n\tans += (n-x)*totalLen\n\tprintln(ans)\n}\n", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9"} {"source_code": "import kotlin.math.*\n\nfun main() {\n val x = readLine()!!.toLong()\n val c = sqrt(x.toDouble()).toLong()\n for (i: Long in c downTo 1) {\n if (x % i == 0L && gcd(x / i, i) == 1L) {\n println(\"${i} ${x / i}\")\n break\n }\n }\n}\n\ntailrec fun gcd(a: Long, b: Long): Long {\n if (b == 0L) return a \n return gcd(b, a % b)\n}", "src_uid": "e504a04cefef3da093573f9df711bcea"} {"source_code": "fun main(args: Array) {\n var (n, a) = readLine()!!.split(\" \").map(String::toInt)\n val cities : List = readLine()!!.split(\" \").map(String::toInt)\n val ekvidistantniGradovi : MutableList> = MutableList(0) {Pair(0,0)}\n\n a--\n //parova ima min({0..a-1},{a+1..n}) i toliko ih spojim\n val parova = minOf((0 until a).count(),(a + 1 until n).count())\n (1..parova).mapTo(ekvidistantniGradovi) { Pair(cities[a - it], cities[a + it]) } //dodao sam parove\n\n //preostali \"visak\" sa lijeve ili desne strane dodam u paru sa -1\n //sto mi oznacava one sto su sigurni, ali nisu upareni\n if((0 until a).count() > (a + 1 until n).count())\n (0 until a-parova).mapTo(ekvidistantniGradovi) { Pair(cities[it], -1)}\n else\n (a+parova+1 until n).mapTo(ekvidistantniGradovi) { Pair(cities[it], -1)}\n\n var caught = 0\n //na kraju sabiram ako ima oba ili ako ima jedan, a drugi je -1\n ekvidistantniGradovi.forEach {\n if(it.first > 0 && it.second > 0) caught += it.first + it.second\n else if(it.first > 0 && it.second == -1) caught += it.first\n }\n println(caught + cities[a])\n}\n\n", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5"} {"source_code": "fun main(args: Array) {\n val arr = Array(101, {i -> 0})\n var total = 0\n readLine()!!.split(' ').map(String::toInt).forEach {\n arr[it]++\n total += it\n }\n var ans = total\n for (i in 1..100) {\n if (arr[i] > 3)\n arr[i] = 3\n if (arr[i] == 1)\n arr[i] = 0\n ans = if (total - i * arr[i] < ans) total - i * arr[i] else ans\n }\n print(\"$ans\\n\")\n}\n", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a"} {"source_code": "import java.io.BufferedReader\nimport java.io.IOException\nimport java.io.InputStream\nimport java.io.InputStreamReader\nimport java.util.*\n\nfun main(args: Array) {\n\n val scanner = Scanner(System.`in`)\n val n = scanner.nextInt()\n val m = scanner.nextInt()\n val arr = IntArray(n) { scanner.nextInt() }\n val arr1 = IntArray(m) { scanner.nextInt() }\n arr.forEach { if (arr1.contains(it)) print(\"$it \") }\n\n}\n\nclass Scanner(s: InputStream) {\n var st: StringTokenizer? = null\n var br: BufferedReader = BufferedReader(InputStreamReader(s))\n @Throws(IOException::class)\n operator fun next(): String {\n while (st == null || !st!!.hasMoreTokens())\n st = StringTokenizer(br.readLine())\n return st!!.nextToken()\n }\n @Throws(IOException::class)\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n @Throws(IOException::class)\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n @Throws(IOException::class)\n fun nextLine(): String {\n return br.readLine()\n }\n @Throws(IOException::class)\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n @Throws(IOException::class)\n fun ready(): Boolean {\n return br.ready()\n }\n}\n//class Pair(var a: Int, var b: Int): Comparable {\n// override fun compareTo(other: Pair): Int {\n// return b - a - other.b + other.a\n// }\n//}", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72"} {"source_code": "import java.io.*\nimport java.util.*\n\nconst val INPUT_FILE_NAME = \"input\"\nconst val OUTPUT_FILE_NAME = \"output\"\n\nfun main(args: Array) {\n solve(System.`in`, System.out)\n// solve(FileInputStream(\"$INPUT_FILE_NAME.txt\"), FileOutputStream(\"$OUTPUT_FILE_NAME.txt\"))\n}\n\nval MAX_N = (1e6 + 10).toInt()\nval INF = (1e9 + 7).toInt()\nval MOD = (1e9 + 7).toInt()\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = InputReader(BufferedInputStream(input))\n val writer = PrintWriter(BufferedOutputStream(output))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(reader: InputReader, writer: PrintWriter) {\n val n = reader.nextInt()\n val b = BooleanArray(1001)\n reader.nextArrayInt(n).forEach { b[it] = true }\n for (i in 1..998) {\n if (b[i] && b[i + 1] && b[i + 2]) {\n writer.println(\"YES\")\n return\n }\n }\n writer.println(\"NO\")\n}\n\nfun gcd(a: Int, b: Int): Int {\n return if (b == 0) a else gcd(b, a % b)\n}\n\nclass InputReader(stream: InputStream) {\n private val reader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n fun nextArrayInt(count: Int): IntArray {\n return nextArrayInt(0, count)\n }\n\n fun nextArrayInt(start: Int, count: Int): IntArray {\n val a = IntArray(start + count)\n for (i in start until start + count) {\n a[i] = nextInt()\n }\n return a\n }\n\n fun nextArrayLong(count: Int): LongArray {\n val a = LongArray(count)\n for (i in 0 until count) {\n a[i] = nextLong()\n }\n return a\n }\n}", "src_uid": "d6c876a84c7b92141710be5d76536eab"} {"source_code": "import java.io.*\nimport java.util.*\n\nclass Main internal constructor(inputStream: InputStream, val out: PrintWriter) {\n companion object {\n val ONLINE_JUDGE = System.getProperty(\"ONLINE_JUDGE\") != null\n }\n\n private val br = BufferedReader(InputStreamReader(inputStream))\n private var st = StringTokenizer(\"\")\n\n internal fun hasNext(): Boolean {\n while (!st.hasMoreTokens()) {\n val readLine = br.readLine() ?: return false\n st = StringTokenizer(readLine)\n }\n return true\n }\n\n private operator fun next() =\n if (hasNext()) st.nextToken()!!\n else throw RuntimeException(\"No tokens\")\n\n internal fun nline() =\n if (hasNext()) st.nextToken(\"\\n\")\n else throw RuntimeException(\"No tokens\")\n\n private fun ni() = next().toInt()\n private fun nii() = Pair(ni(), ni())\n private fun niii() = Triple(ni(), ni(), ni())\n private fun nia(n: Int) = IntArray(n) { ni() }\n private fun nia(m: Int, n: Int) = Array(m) { nia(n) }\n\n private fun nl() = next().toLong()\n private fun nll() = Pair(nl(), nl())\n private fun nlll() = Triple(nl(), nl(), nl())\n private fun nla(n: Int) = LongArray(n, { nl() })\n private fun nla(m: Int, n: Int) = Array(m) { nla(n) }\n\n private fun nd() = next().toDouble()\n private fun ndd() = Pair(nd(), nd())\n private fun nddd() = Triple(nd(), nd(), nd())\n private fun nda(n: Int) = DoubleArray(n) { nd() }\n private fun nda(m: Int, n: Int) = Array(m) { nda(n) }\n\n inline fun log(name: String, block: () -> Unit) {\n if (!ONLINE_JUDGE) {\n p(\"#$name: \")\n block()\n flush()\n }\n }\n\n inline fun log() = log(\"\") { pln() }\n inline fun log(message: Any?, name: String = \"\") = log(name) { pln(message) }\n inline fun log(arr: IntArray?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(arr: LongArray?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(arr: DoubleArray?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(arr: Array?, name: String = \"\") = log(name) { pln(arr) }\n inline fun log(stack: Stack?, name: String = \"\") = log(name) { pln(stack) }\n inline fun log(list: List?, name: String = \"\") = log(name) { pln(list) }\n\n //prefix print\n inline fun prep(prefix: Boolean, separator: String, message: Any?) {\n if (prefix) {\n p(separator)\n }\n p(message)\n }\n\n inline fun p(message: Any?) = this.also { out.print(message) }\n\n inline fun p(arr: IntArray?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(arr: LongArray?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(arr: DoubleArray?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(arr: Array?, separator: String = \" \") = this.also {\n arr?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(list: List?, separator: String = \" \") = this.also {\n list?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun p(stack: Stack?, separator: String = \" \") = this.also {\n stack?.fold(false, { prefix, t -> prep(prefix, separator, t); true })\n }\n\n inline fun pln() = this.also { out.println() }\n inline fun pln(message: Any?) = p(message).pln()\n inline fun pln(arr: IntArray?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(arr: LongArray?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(arr: DoubleArray?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(list: List?, separator: String = \" \") = p(list, separator).pln()\n inline fun pln(arr: Array?, separator: String = \" \") = p(arr, separator).pln()\n inline fun pln(stack: Stack?, separator: String = \" \") = p(stack, separator).pln()\n\n inline fun flush() = out.flush()\n\n //////////////////////////////////////\n\n fun run() {\n val n = ni()\n var next = 0\n var playing1 = 1\n var playing2 = 2\n val check = HashSet()\n var winner = 0;\n for (i in 0..n - 1) {\n next = ni();\n if(next!=playing1&&next!=playing2){\n pln(\"NO\")\n return\n }\n winner = next;\n for (i in 1..3) check.add(i)\n check.remove(playing1)\n check.remove(playing2)\n playing1=check.first();\n playing2=winner;\n }\n pln(\"YES\")\n }\n\n}\n\n//////////////////////////////////////\nfun main(args: Array) {\n val inp = File(\"input.txt\")\n if (Main.ONLINE_JUDGE || !inp.isFile) {\n val a = Main(System.`in`, PrintWriter(BufferedOutputStream(System.out)))\n a.run()\n a.flush()\n a.out.close()\n } else {\n val t = Main(FileInputStream(\"input.txt\"), PrintWriter(BufferedOutputStream(System.out)))\n while (t.hasNext()) {\n val name = t.nline()\n t.log(\"##### Test $name #####\")\n val startTime = System.currentTimeMillis()\n t.run()\n val endTime = System.currentTimeMillis()\n t.log(endTime - startTime, \"Total Time\")\n t.log()\n t.flush()\n }\n }\n}", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87"} {"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}", "src_uid": "0a98a6a15e553ce11cb468d3330fc86a"} {"source_code": "fun main(args: Array) {\n var str = arrayOf(\"\",\"\",\"\",\"\",\"\",\"\")\n for(i in 0..5) {\n str[i] = readLine()!!\n }\n var bx = 0\n var by = 0\n var bm = 0\n for(i in 0..5) {\n var ry = 0\n for(j in 0..7) {\n if(str[i][j] == '-')\n continue\n if(str[i][j] != '*') {\n var mark = 3 - (i / 2)\n if(ry == 2 || ry == 3)\n mark++\n if(mark > bm) {\n bm = mark\n bx = i\n by = j\n }\n }\n ry++\n }\n }\n for(i in 0..5) {\n for(j in 0..7) {\n if(i==bx && j == by) {\n print('P')\n } else {\n print(str[i][j])\n }\n }\n print(\"\\n\")\n }\n}", "src_uid": "35503a2aeb18c8c1b3eda9de2c6ce33e"} {"source_code": "import kotlin.math.min\n\nfun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n\n val (d1, d2, d3) = readInts()\n print(min(d1 + d2 + d3, min(d1 + d1 + d2 + d2, min(d1 + d1 + d3 + d3, d2 + d2 + d3 + d3))))\n}", "src_uid": "26cd7954a21866dbb2824d725473673e"} {"source_code": "fun main(args: Array) {\n val length = readLine()?.toLong()\n val numbers = readLine()?.split(' ')?.map { it.toInt() }\n if (length == null || numbers == null) return\n\n if (numbers.none { it != 0 }) {\n println(\"NO\")\n return\n }\n\n val notNullPositions = mutableListOf()\n numbers.mapIndexed { index, value -> if (value != 0) notNullPositions.add(index + 1) }\n\n println(\"YES\")\n println(notNullPositions.size)\n\n if (notNullPositions.size == 1) {\n println(\"1 ${numbers.size}\")\n } else {\n println(\"1 ${notNullPositions[0]}\")\n for (i in 1 until notNullPositions.size) {\n if (i < notNullPositions.size - 1)\n println(\"${notNullPositions[i - 1] + 1} ${notNullPositions[i]}\")\n else {\n println(\"${notNullPositions[i - 1] + 1} ${numbers.size}\")\n }\n }\n }\n}", "src_uid": "3a9258070ff179daf33a4515def9897a"} {"source_code": "import java.io.*\nimport java.util.*\n\nfun main() {\n solve(System.`in`, System.out)\n}\n\nfun solve(input: InputStream, output: OutputStream) {\n val reader = Reader(input) //Reader(FileInputStream(File(\"portals.in\")))\n val writer = PrintWriter(BufferedOutputStream(output)) //PrintWriter(FileOutputStream(File(\"output.txt\")))\n\n solve(reader, writer)\n writer.close()\n}\n\nfun solve(ir : Reader, pw : PrintWriter) {\n\n val k : Int = ir.nextInt()\n var a : Int = ir.nextInt()\n var b : Int = ir.nextInt()\n val v : Int = ir.nextInt()\n var result = 0\n\n while (a > 0) {\n result++\n val min = Math.min(b, k - 1)\n b -= min\n a -= (min + 1) * v\n }\n\n pw.print(result)\n\n /*val T : Int = ir.nextInt()\n\n for (t in 0 until T) {\n val n : Int = ir.nextInt()\n val a = ir.next().toCharArray()\n var start = 0\n var end = 0\n var count = 0\n\n for (i in 0 until n)\n if (a[i] == 's')\n start = i\n else if (a[i] == 'e')\n end = i\n\n if (end > start) {\n for (i in start..end) {\n if (a[i] == '#')\n break\n else if (a[i] == 'o') {\n var next = true\n for (k in (i + 1)..end)\n if (a[k] == '#') {\n next = false\n break\n }\n if (next)\n break\n }\n }\n } else {\n\n }*/\n\n\n }\n\n\n\nclass Reader(stream: InputStream) {\n private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)\n private var tokenizer: StringTokenizer? = null\n\n init {\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens())\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return tokenizer!!.nextToken()\n }\n\n fun nextLine(): String? {\n val fullLine: String\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n fullLine = reader.readLine()\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n return fullLine\n }\n return null\n }\n\n fun toArray(): Array {\n return nextLine()!!.split(\" \".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextDouble(): Double {\n return java.lang.Double.parseDouble(next())\n }\n\n fun nextLong(): Long {\n return java.lang.Long.parseLong(next())\n }\n\n}", "src_uid": "7cff20b1c63a694baca69bdf4bdb2652"} {"source_code": "fun main() {\n var word = readLine()\n var countU = 0\n var countL = 0\n for (i in 0 until word?.length!!) {\n if (word.get(i).isUpperCase()) {\n countU++\n } else {\n countL++\n }\n }\n if (countL >=countU) {\n word = word.toLowerCase()\n\n } else if (countU > countL) {\n word = word.toUpperCase()\n }\n print(word)\n}", "src_uid": "b432dfa66bae2b542342f0b42c0a2598"} {"source_code": "fun main() {\r\n\r\n val s = read()\r\n var merges = mutableMapOf, Pair>()\r\n var bestn = -1\r\n for (n in 2..1000) {\r\n var pos = 0\r\n merges = mutableMapOf, Pair>()\r\n fun getMergeData(left: Int, right: Int) {\r\n if (right - left <= 1) {\r\n return\r\n }\r\n val mid = (right + left) / 2\r\n getMergeData(left, mid)\r\n getMergeData(mid, right)\r\n\r\n val start = pos\r\n val leftLen = mid - left\r\n val rightLen = right - mid\r\n var count0 = 0\r\n var count1 = 0\r\n while (count0 < leftLen && count1 < rightLen) {\r\n if (s[pos++] == '0') {\r\n count0++\r\n } else {\r\n count1++\r\n }\r\n }\r\n\r\n merges[Pair(left, right)] = Pair(start, pos)\r\n }\r\n getMergeData(0, n)\r\n if (pos == s.length) {\r\n bestn = n\r\n break\r\n }\r\n }\r\n\r\n val n = bestn\r\n val result = IntArray(n)\r\n\r\n fun restoreAnswer(left: Int, right: Int, lst: List) {\r\n if (right - left <= 1) {\r\n if (right - left == 1) {\r\n result[left] = lst[0]\r\n }\r\n return\r\n }\r\n\r\n val mid = (left + right) / 2\r\n val leftLst = mutableListOf()\r\n val rightLst = mutableListOf()\r\n\r\n val mergeData = merges[Pair(left, right)]!!\r\n var sIdx = mergeData.first\r\n var idx = 0\r\n while (sIdx < mergeData.second) {\r\n if (s[sIdx++] == '0') {\r\n leftLst.add(lst[idx++])\r\n } else {\r\n rightLst.add(lst[idx++])\r\n }\r\n }\r\n\r\n while (leftLst.size < mid - left) {\r\n leftLst.add(lst[idx++])\r\n }\r\n\r\n while (rightLst.size < right - mid) {\r\n rightLst.add(lst[idx++])\r\n }\r\n\r\n restoreAnswer(left, mid, leftLst)\r\n restoreAnswer(mid, right, rightLst)\r\n }\r\n\r\n restoreAnswer(0, n, (1..n).toList())\r\n println(n)\r\n println(result.joinToString(\" \"))\r\n}\r\n\r\n@JvmField val INPUT = System.`in`\r\n@JvmField val OUTPUT = System.out\r\n\r\nconst val _BUFFER_SIZE = 1 shl 16\r\n@JvmField val _buffer = ByteArray(_BUFFER_SIZE)\r\n@JvmField var _bufferPt = 0\r\n@JvmField var _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\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\nfun readInt() = read().toInt()\r\nfun readDouble() = read().toDouble()\r\nfun readLong() = read().toLong()\r\nfun readStrings(n: Int) = List(n) { read() }\r\nfun readLines(n: Int) = List(n) { readLn() }\r\nfun readInts(n: Int) = List(n) { read().toInt() }\r\nfun readIntArray(n: Int) = IntArray(n) { read().toInt() }\r\nfun readDoubles(n: Int) = List(n) { read().toDouble() }\r\nfun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }\r\nfun readLongs(n: Int) = List(n) { read().toLong() }\r\nfun readLongArray(n: Int) = LongArray(n) { read().toLong() }\r\n\r\n", "src_uid": "b2ee84d23d73947fa84faaaebfde85c8"} {"source_code": "import java.util.*\n\n/**\n * Created by Borys Minaiev on 06.12.17.\n */\n\nfun main(args : Array) = with(Scanner(System.`in`)) {\n val n = nextInt()\n val a = List(n) {i -> nextInt()}\n var res = 360\n for (i in a.indices)\n for (j in i..a.lastIndex) {\n val sum = Math.abs(180 - a.subList(i, j).sum())\n res = Math.min(sum, res)\n }\n println(res * 2)\n}", "src_uid": "1b6a6aff81911865356ec7cbf6883e82"} {"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", "src_uid": "a18833c987fd7743e8021196b5dcdd1b"} {"source_code": "import java.util.regex.Pattern\n\nfun main() {\n var play = false\n val card = readLine() ?: \"\"\n val myCard = \" ${readLine()}\"\n val regex = Pattern.compile(\" ${card[0]}.| .${card[1]}\").matcher(myCard)\n while (regex.find()) {\n play = true\n break\n }\n println(if (play) \"YES\" else \"NO\")\n}", "src_uid": "699444eb6366ad12bc77e7ac2602d74b"} {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toLong()\n val (x, y) = readLine()!!.split(\" \").map {it.toLong()}\n var moveW = maxOf(x - 1, y - 1)\n var moveH = maxOf(n - x, n - y)\n if (moveW <= moveH) println(\"White\") else println(\"Black\")\n}\n", "src_uid": "b8ece086b35a36ca873e2edecc674557"} {"source_code": "import java.util.*\n\nfun main() {\n val input = Scanner(System.`in`)\n val stringValue : String = input.nextLine()\n\n for (index in stringValue.length-1 downTo 0){\n if (stringValue[index].isLetter()){\n when (stringValue[index].toUpperCase()) {\n 'A' -> println(\"YES\")\n 'E' -> println(\"YES\")\n 'I' -> println(\"YES\")\n 'O' -> println(\"YES\")\n 'U' -> println(\"YES\")\n 'Y' -> println(\"YES\")\n else ->{\n println(\"NO\")\n }\n }\n return\n }\n }\n}\n", "src_uid": "dea7eb04e086a4c1b3924eff255b9648"} {"source_code": "import java.io.*\nimport kotlin.concurrent.thread\nimport java.io.IOException\nimport java.io.BufferedReader\nimport java.io.InputStream\nimport kotlin.*\nimport java.*\nimport java.io.OutputStream\nimport java.io.PrintWriter\nimport java.lang.ArithmeticException\nimport java.lang.Exception\nimport java.math.BigInteger\nimport java.security.cert.TrustAnchor\nimport java.util.*\nimport kotlin.collections.ArrayList\nimport kotlin.collections.HashSet\nimport kotlin.system.exitProcess\n\nfun main() {\n val inputStream = System.`in`\n val outputStream = System.out\n val `in` = InputReader(inputStream)\n val out = PrintWriter(outputStream)\n\n val n=`in`.nextInt()\n val s=`in`.next()\n if (n%2==1||(s.map{if (it=='(') +1 else -1}.sum()!=0))\n out.println(\"0\\n1 1\")\n else\n {\n val a = IntArray(n)\n a[0]= if (s[0]=='(') +1 else -1\n for (i in 1..n-1){\n if (s[i]=='(')\n a[i]=a[i-1]+1\n else\n a[i]=a[i-1]-1\n }\n val mn=a.min()!!\n var pos=-1\n for (i in 0..n-1)\n if (a[i]==mn)\n {\n pos=i\n break\n }\n val kol=a.filter{it==mn}.size\n if (kol*2==n){\n out.println(kol)\n out.println(\"1 1\")\n } else {\n var now = 0\n var mx = 0\n var prv = -1\n var pos1 = -1\n var pos2 = -2\n for (I in pos..pos + n + 1) {\n val i = I % n\n if (a[i] == mn || a[i] == mn+1) {\n if (now > mx) {\n mx = now\n pos1 = (prv) % n\n pos2 = (I + n) % n\n }\n prv = i + 1\n now = 0\n } else if (a[i] == mn + 2) {\n ++now\n }\n }\n val mx1=mx+kol\n val a1=pos1+1\n val b1=pos2+1\n\n mx=0\n prv=-1\n now=0\n pos1=-1\n pos2=-1\n for (I in pos..pos + n + 1) {\n val i = I % n\n if (a[i] == mn) {\n if (now > mx) {\n mx = now\n pos1 = (prv) % n\n pos2 = (I + n) % n\n }\n prv = i + 1\n now = 0\n } else if (a[i] == mn + 1) {\n ++now\n }\n }\n\n if (mx>mx1) {\n out.println(mx)\n out.println((pos1 + 1).toString() + ' ' + (pos2 + 1))\n } else {\n out.println(mx1)\n out.println(a1.toString() + ' ' + b1)\n }\n\n\n /*out.println(mx)\n out.println((pos1 + 1).toString() + ' ' + (pos2 + 1))\n\n out.println(mx1)\n out.println(a1.toString() + ' ' + b1)*/\n }\n\n }\n\n out.close()\n\n}\n\n\ninternal class InputReader(stream: InputStream) {\n var reader: BufferedReader\n var tokenizer: StringTokenizer? = null\n\n init {\n reader = BufferedReader(InputStreamReader(stream), 32768)\n tokenizer = null\n }\n\n operator fun next(): String {\n while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {\n try {\n tokenizer = StringTokenizer(reader.readLine())\n } catch (e: IOException) {\n throw RuntimeException(e)\n }\n\n }\n return tokenizer!!.nextToken()\n }\n\n fun nextInt(): Int {\n return Integer.parseInt(next())\n }\n\n fun nextLong(): Long {\n return next().toLong()\n }\n\n}\n\n//)(()(()())()\n//)(())()()(()", "src_uid": "be820239276b5e1a346309f9dd21c5cb"} {"source_code": "import java.util.*\n\nfun main() {\n cases@for (c in 1..readLine()!!.toInt()) {\n val h = readLine()!!.toInt()\n val cache = mutableMapOf>()\n var answer = 0\n var queries = 0\n fun query(a: Int): List {\n if (a !in cache) {\n if (queries == 16) {\n answer = a\n return listOf()\n }\n queries++\n println(\"? $a\")\n readLine()\n val res = readLine()!!.split(\" \").map { it.toInt() }\n if (res.size == 2) {\n answer = a\n return listOf()\n }\n cache[a] = res\n }\n return cache[a]!!\n }\n val order = mutableListOf()\n fun dfs(a: Int) {\n var a = a\n while (true) {\n order.add(a)\n var b = 0\n for (c in query(a)) {\n if (c !in cache) {\n b = c\n break\n }\n }\n if (answer != 0) {\n return\n }\n if (b == 0) {\n return\n }\n a = b\n }\n }\n dfs(1)\n if (answer != 0) {\n println(\"! $answer\")\n continue@cases\n }\n order.reverse()\n order.removeAt(order.size - 1)\n dfs(1)\n if (answer != 0) {\n println(\"! $answer\")\n continue@cases\n }\n while ((order.size / 2) < h - 4) {\n val y = order.size / 2\n while (order.size > y + 1) {\n order.removeAt(order.size - 1)\n }\n var a = 0\n for (c in query(order.last())) {\n if (c !in cache) {\n a = c\n break\n }\n }\n dfs(a)\n if (answer != 0) {\n println(\"! $answer\")\n continue@cases\n }\n }\n val q = LinkedList()\n q.add(order[order.size / 2])\n while (q.isNotEmpty()) {\n val a = q.remove()\n for (b in query(a)) {\n if (b !in cache) {\n q.add(b)\n }\n }\n if (answer != 0) {\n println(\"! $answer\")\n continue@cases\n }\n }\n }\n}", "src_uid": "5c0db518fa326b1e405479313216426a"} {"source_code": "fun main(arg: Array){\n\tvar s = readLine()!!\n\tvar m = readLine()!!.toLong()\n\tvar l = s.length\n\tvar now = 0.toLong()\n\tvar Q = 1.toLong()\n\tfor(i in 0..l-1){\n\t\tnow = (now * 10 + (s[i].toInt() - 48))%m\n\t\tQ = Q * 10 % m\n\t}\n\tvar res = now\n\tfor(i in 0..l-1){\n\t\tvar x = s[i].toInt() - 48\n\t\tnow = (now * 10 + x - x * Q % m + m)%m\n\t\tif(i == l-1 || s[i+1] != '0'){\n\t\t\tif(now < res)res = now\n\t\t}\n\t}\n\tprintln(res)\n}\n", "src_uid": "d13c7b5b5fc5c433cc8f374ddb16ef79"} {"source_code": "import java.util.*;\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val n: Int = sc.nextInt()\n val k: Int = sc.nextInt()\n val arr = IntArray(n)\n for (i in 0..(n-1)) {\n arr[i] = sc.nextInt()\n }\n arr.sort()\n /*\n for (i in 0..(n-1)) {\n print(\"\" + i + \": \" + arr[i] + \"\\n\")\n }\n */\n\n val low: Int = arr[n-k]\n var ans: Int = 0\n for (i in 0..(n-1)) {\n if (arr[i] > 0 && arr[i] >= low) {\n ans = ans + 1\n }\n }\n print(\"\" + ans + \"\\n\")\n}\n", "src_uid": "193ec1226ffe07522caf63e84a7d007f"} {"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 m : Int = ir.nextInt()\n val c = IntArray(m)\n var first = 0\n var second = 0\n for (i in 0 until m) {\n c[i] = ir.nextInt()\n second += c[i]\n }\n val x : Int = ir.nextInt()\n val y : Int = ir.nextInt()\n\n for (i in 0 until m) {\n first += c[i]\n second -= c[i]\n\n if (first in x..y) {\n if (second in x..y) {\n pw.print(\"${i + 2}\")\n return\n }\n }\n }\n\n pw.print(0)\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}", "src_uid": "e595a1d0c0e4bbcc99454d3148b4557b"} {"source_code": "import java.util.StringTokenizer\nimport java.io.PrintWriter\n\nfun main() {\n for(t in 1..1) {\n val x = readString().toCharArray()\n val y = readString().toCharArray()\n var z = \"\"\n val l = x.size\n var f = false\n for(i in 0..l-1){\n if(x[i] == y[i]) z += \"z\"\n else if(x[i] < y[i]) {\n f = true\n }\n else z += y[i]\n }\n if(!f) wr(z)\n else wr(-1)\n }\n}\n\n@JvmField val INPUT = System.`in`\n@JvmField val OUTPUT = System.out\n@JvmField val _reader = INPUT.bufferedReader()\n\nfun readLine(): String? = _reader.readLine()\nfun readLn(): String = _reader.readLine()!!\n\n@JvmField var _tokenizer: StringTokenizer = StringTokenizer(\"\")\n\nfun read(): String {\n while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return \"\", \" \")\n return _tokenizer.nextToken()\n}\n\nfun readString() = readLn()\nfun readStrings() = readLn().split(\" \")\nfun readInt() = readLn().toInt()\nfun readInts() = readStrings().map { it.toInt() }\nfun readLong() = readLn().toLong()\nfun readLongs() = readStrings().map { it.toLong() }\n\nfun wr(a: String) = println(a)\nfun wr(a: Int) = println(a)\n\n@JvmField val _writer = PrintWriter(OUTPUT, false)\ninline fun output(block: PrintWriter.() -> Unit) { _writer.apply(block).flush() }", "src_uid": "ce0cb995e18501f73e34c76713aec182"} {"source_code": "const val s = \"codeforces\"\nfun main() {\n val k = readLine()!!.toLong()\n var pos = 0\n val a = MutableList(10) { 0L }\n while (a.reduce { x, y -> x * y } < k) {\n a[pos]++\n pos = (pos + 1) % 10\n }\n var res = \"\"\n for (i in 0 until 10)\n repeat(a[i].toInt()) {\n res += s[i]\n }\n println(res)\n}", "src_uid": "8001a7570766cadcc538217e941b3031"} {"source_code": "fun main() {\n val numVertices = readLine()!!.toLong()\n print(1 + 3 * (numVertices - 3) + (numVertices - 3) * (numVertices - 4))\n}", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b"} {"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}", "src_uid": "ea1c737956f88be94107f2565ca8bbfd"} {"source_code": "import java.io.StringBufferInputStream\n\nprivate fun solution() {\n val (n,m,k) = readIntList()\n if (m >= n && k >= n) println(\"Yes\") else println(\"No\")\n}\n//------------ Tests -------------------------\nprivate val tests: Array = arrayOf(\n \"\"\"5 8 6\"\"\",\n \"\"\"3 9 3\"\"\",\n \"\"\"8 5 20\"\"\"\n)\n//------------ Generated ---------------------\nfun main() {\n if (System.getProperty(systemFlag) != null) {\n solution()\n } else {\n println(\"Start testing ...\")\n for (i in tests.indices) {\n println(\"==== Test #${i+1} ==========\")\n val s = StringBufferInputStream(tests[i])\n System.setIn(s)\n solution()\n }\n }\n}\n\nprivate fun readString(): String = readLine()!!\nprivate fun readInt(): Int = readLine()!!.toInt()\nprivate fun readLong(): Long = readLine()!!.toLong()\nprivate fun readIntList(): List = readLine()!!.split(\" \").map{ it.toInt() }\nprivate fun readLongList(): List = readLine()!!.split(\" \").map{ it.toLong() }\nprivate const val systemFlag = \"ONLINE_JUDGE\"\n", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4"} {"source_code": "import java.util.*\n\nfun isLucky(num: Int) : Boolean {\n val lucky_numbers = listOf(4, 7, 47, 74, 44, 77, 444, 447, 474, 477, 744, 747, 774, 777)\n for (n: Int in lucky_numbers) {\n if (num % n == 0) return true\n }\n return false\n}\n\nfun main(args: Array) {\n val sc = Scanner(System.`in`)\n val number = sc.nextInt()\n println(if (isLucky(number)) \"YES\" else \"NO\")\n}\n", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d"} {"source_code": "fun main() {\n var arg = readLine()!!.split(\" \").map { it.toInt() }// read integer from the input\n val problem399 = Problem399()\n problem399.solve(arg)\n}\n\n\nclass Problem399 {\n fun solve(arg: List) {\n val n = arg.component1()\n val p = arg.component2()\n val k = arg.component3()\n val items = mutableListOf()\n if (p - k > 1)\n items.add(\"<<\")\n val start = if (p - k > 0) p - k else 1\n val end = if (n - p > k) p + k else n\n for (i in start..end) {\n if (i == p)\n items.add(\"($i)\")\n else\n items.add(\"$i\")\n }\n if (n - p > k)\n items.add(\">>\")\n print(items.joinToString(separator = \" \"))\n }\n}\n\n", "src_uid": "526e2cce272e42a3220e33149b1c9c84"} {"source_code": "import kotlin.math.max\n\nfun main() {\n var x = readInteger()\n var ans = 0\n\n for (i in 5 downTo 1) {\n ans += x / i\n x %= i\n }\n\n println(ans)\n}\n\nfun readInteger() = readLine()!!.toInt()\nfun readStrings() = readLine()!!.split(\" \")\nfun readIntegers() = readStrings().map(String::toInt)\n", "src_uid": "4b3d65b1b593829e92c852be213922b6"} {"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 max = a.max()!!\n println(Math.max(0, max - 25))\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}", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd"} {"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", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3"} {"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\nfun main() {\n var(n,k)=readints()\n var s=readln()\n var t=readln()\n if(t[0]==t[1]){\n var c=0\n for(i in 0..n-1){\n if(s[i]==t[0]){\n c++\n }\n }\n c=minOf(n,c+k)\n println(c*(c-1)/2)\n return\n }\n var dp = Array(n+2) { LongArray(k+2) { -100000000000000L } }\n dp[0][0]=0L\n for(i in 0..n-1){\n var ndp = Array(n+2) { LongArray(k+2) { -100000000000000L } }\n for(x in 0..i){\n for(y in 0..minOf(i,k)){\n ndp[x][y]=maxOf(ndp[x][y],dp[x][y])\n var ny=y\n if(s[i]!=t[0]){\n ny++\n }\n ndp[x+1][ny]=maxOf(ndp[x+1][ny],dp[x][y])\n ny=y\n if(s[i]!=t[1]){\n ny++\n }\n ndp[x][ny]=maxOf(ndp[x][ny],dp[x][y]+x)\n }\n }\n dp=ndp\n // for(x in 0..n){\n // println(dp[x].joinToString(\" \"));\n // }\n // println(\"\")\n }\n var ans=0L\n for(i in 0..n){\n for(j in 0..k){\n ans=maxOf(ans,dp[i][j])\n }\n }\n println(ans)\n} \n", "src_uid": "9c700390ac13942cbde7c3428965b18a"} {"source_code": "fun lastDigitInFactorialZone(lower: Long, upper:Long) : Long {\n var ret = 1L;\n for (i in (lower+1)..upper) {\n ret = (ret * i) % 10\n\n if (ret == 0L) break;\n }\n return ret\n}\n\nfun main(args: Array) {\n val (a, b) = readLine()!!.split(' ').map(String::toLong)\n\n val ret = lastDigitInFactorialZone(a, b)\n \n val retStr = ret.toString()\n println(retStr.last())\n}\n", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60"} {"source_code": "fun main() {\n val r = readLong()\n\n val ans = run {\n if(r % 2 == 0L) return@run \"NO\"\n val y = (r - 3) / 2\n if(y <= 0) \"NO\" else \"1 $y\"\n }\n\n println(ans)\n}\n\nfun readLn() = readLine()!!\nfun readInt() = readLn().toInt()\nfun readDouble() = readLn().toDouble()\nfun readLong() = readLn().toLong()\nfun readStrings() = readLn().split(' ')\nfun readInts() = readStrings().map { it.toInt() }\nfun readDoubles() = readStrings().map { it.toDouble() }\nfun readLongs() = readStrings().map { it.toLong() }\n\nclass Output {\n private val sb = StringBuilder()\n fun print(o: Any?) { sb.append(o) }\n fun println() { sb.append('\\n') }\n fun println(o: Any?) { sb.append(o).append('\\n') }\n @JvmName(\"_print\") fun Any?.print() = print(this)\n @JvmName(\"_println\") fun Any?.println() = println(this)\n fun nowPrint() { kotlin.io.print(sb) }\n}\ninline fun output(block: Output.()->Unit)\n { Output().apply(block).nowPrint() }\n", "src_uid": "3ff1c25a1026c90aeb14d148d7fb96ba"} {"source_code": "fun main() {\n fun readInts() = readLine()!!.split(\" \").map(String::toInt)\n fun sieve(limit: Int): List {\n val notPrimes = mutableSetOf()\n val primes = ArrayList()\n for (num in 2..limit) {\n if (num !in notPrimes) {\n primes.add(num)\n var notPrime = num + num\n while (notPrime <= limit) {\n notPrimes.add(notPrime)\n notPrime += num\n }\n }\n }\n return primes\n }\n val (n, k) = readInts()\n val primes = sieve(n)\n var sol = 0\n for (goal in primes)\n for (pos in 1 until primes.size)\n if (primes[pos] + primes[pos - 1] + 1 > goal) break\n else if (primes[pos] + primes[pos - 1] + 1 == goal) {\n sol++\n break\n }\n print(if (sol >= k) \"YES\" else \"NO\")\n}", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d"} {"source_code": "import java.util.Scanner\nfun main(args: Array){\n var numr=Scanner(System.`in`)\n var num:Int=numr.nextInt()\n if(num>2 && num%2==0){\n print(\"YES\")\n }\n else print(\"NO\")\n}\n", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2"} {"source_code": "import java.util.*\n\nfun main() {\n\n val sc = Scanner(System.`in`)\n val s = sc.next()\n val len : Int = s.length\n\n if (isPalindrome(s)) {\n if (len % 2 == 0) {\n print(s.substring(0, len / 2))\n print('a')\n print(s.substring(len / 2))\n } else {\n print(s.substring(0, (len / 2) + 1))\n print(s[len / 2])\n print(s.substring((len / 2) + 1))\n }\n return\n } else {\n for (i in 0 until len) {\n val line = s.substring(0, i) + s.substring(i + 1)\n if (isPalindrome(line)) {\n if (len % 2 == 0) {\n if (i < len / 2) {\n var ss = s.substring(0, (len / 2) + 1)\n for (k in len / 2 - 1 downTo 0) {\n ss += s[k]\n }\n print(ss)\n } else {\n var ss = s.substring(len / 2 - 1)\n for (k in len / 2 until len) {\n ss = s[k] + ss\n }\n print(ss)\n }\n return\n } else {\n if (i < len / 2) {\n var ss = s.substring(0, (len / 2) + 1)\n for (k in len / 2 downTo 0) {\n ss += s[k]\n }\n print(ss)\n } else {\n var ss = s.substring(len / 2)\n for (k in len / 2 until len) {\n ss = s[k] + ss\n }\n print(ss)\n }\n return\n }\n }\n }\n }\n\n print(\"NA\")\n\n}\n\nprivate fun isPalindrome(str: String): Boolean {\n val newStr = StringBuilder()\n for (i in str.length - 1 downTo 0) newStr.append(str[i])\n return newStr.toString() == str\n}", "src_uid": "24e8aaa7e3e1776adf342ffa1baad06b"} {"source_code": "import java.io.BufferedOutputStream\nimport java.io.PrintWriter\nimport java.util.*\n\ndata class Position(\n val nextPriliv: Boolean,\n val value: Long\n) {\n fun next(k: Long): Position {\n val nextValue = if (nextPriliv) value + 1 else value - 1\n return when (nextValue) {\n 0L -> Position(true, 0)\n k -> Position(false, k)\n else -> Position(nextPriliv, nextValue)\n }\n }\n}\n\nfun main() {\n val reader = Scanner(System.`in`)\n val out = PrintWriter(BufferedOutputStream(System.`out`))\n\n val t = reader.nextInt()\n repeat(t) {\n val n = reader.nextInt() // Distance\n val k = reader.nextLong() // Priliv time\n val l = reader.nextLong() // Max depth\n val depths = LongArray(n) { reader.nextLong() }\n\n val possibilities = Array(n + 1) { mutableSetOf() }\n for (i in 0L until k) {\n possibilities[0].add(Position(true, i))\n }\n for (i in k downTo 1L) {\n possibilities[0].add(Position(false, i))\n }\n\n for (i in 0 until n) {\n possibilities[i].forEach { position ->\n var nextPosition = position.next(k)\n while (depths[i] + nextPosition.value <= l) {\n possibilities[i + 1].add(nextPosition)\n if (position == nextPosition) {\n break\n }\n nextPosition = nextPosition.next(k)\n }\n }\n }\n if (possibilities[n].isNotEmpty()) {\n out.println(\"Yes\")\n } else {\n out.println(\"No\")\n }\n }\n\n out.flush()\n}\n", "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8"} {"source_code": "import java.io.PrintWriter\nimport java.util.*\n\nfun main() {\n val sc = Scanner(System.`in`)\n val pw = PrintWriter(System.out)\n val cnt1 = sc.nextInt()\n val cnt2 = sc.nextInt()\n val cnt3 = sc.nextInt()\n val cnt4 = sc.nextInt()\n if (cnt3 > 0 && cnt1 == 0) {\n println(0)\n return\n }\n if (cnt1 == cnt4) {\n println(1)\n } else {\n println(0)\n }\n pw.close()\n}\n", "src_uid": "b99578086043537297d374dc01eeb6f8"} {"source_code": "import java.util.Scanner\n\nfun main(args: Array) {\n val cin = Scanner(System.`in`)\n var n = cin.nextInt()\n var k = cin.nextInt()\n var ans = 1L\n var c = 1L\n var f = longArrayOf(1, 0, 1, 2, 9)\n for (i in 1..k) {\n c = c * (n - i + 1) / i;\n ans += c * f[i]\n }\n println(ans)\n}", "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f"} {"source_code": "fun main() {\n val inp = readLine()!!\n val x = inp.split(\" \")[0].toInt()\n val y = inp.split(\" \")[1].toInt()\n val z = inp.split(\" \")[2].toInt()\n if (x <= 100 && y <= 100 && z <= 100 && 0 <= x && 0 <= y && 0 <= z) {\n var originalStatus = if (x - y > 0) '+' else if (x - y < 0) '-' else '0'\n for (i in 1..z) {\n var newStatus = if (x - y + z > 0) '+' else if (x - y + z < 0) '-' else '0'\n if (newStatus == originalStatus) {\n newStatus = if (x - y - z > 0) '+' else if (x - y - z < 0) '-' else '0'\n if (newStatus != originalStatus) {\n originalStatus = '?'\n break\n }\n }\n else {\n originalStatus = '?'\n break\n }\n }\n println(originalStatus)\n }\n}", "src_uid": "66398694a4a142b4a4e709d059aca0fa"} {"source_code": "fun main() {\n var p:List = readLine()!!.split(\" \").map {x -> x.toLong()}\n var n :Long = p[0]\n var a :Long = p[1]\n var b :Long = p[2]\n var c :Long = p[3]\n var d :Long = p[4]\n var A :Long = 0\n var B :Long = a - d\n var C :Long = (B + b) - (c)\n var D :Long = (d + C) - (a)\n var mn :Long = listOf(A, B, C, D).min()!!.toLong()\n if(mn < 1) {\n mn -= 1\n A -= mn\n B -= mn\n C -= mn\n D -= mn\n }\n var mx :Long = listOf(A, B, C, D).max()!!.toLong()\n var res :Long = (n - mx + 1)*(n)\n if(res <= 0) {\n res = 0\n }\n println(res)\n}", "src_uid": "b732869015baf3dee5094c51a309e32c"} {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n\n (0 .. 10000).forEach {\n if (it * (it + 1) * (it + 2)/6 > n){\n println(it - 1)\n return\n }\n }\n}", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0"} {"source_code": "fun main(args:Array){\n //0,1,2,3,4,5,6,7,8,9\n val loop = listOf(1,0,0,0,1,0,1,0,2,1)\n var k= readLine()!!.toInt()\n if (k>36) println(-1)\n else{\n while(k>=2){\n print(8)\n k-=2\n }\n if (k==1) print(6)\n println()\n }\n}", "src_uid": "0c9973792c1976c5710f88e3520cda4e"} {"source_code": "fun readInt() = readLine()!!.toInt()\n\nval MA = ModuloArithmetic(998244353 )\nfun Int.ma() = MA.ofInt(this)\n\nfun main() {\n val n = readInt()\n\n val dpT = Array(n+3) { 0.ma() }\n val dpF = Array(n+3) { 0.ma() }\n dpT[n+1] = 1.ma()\n dpF[n+1] = 0.ma()\n dpT[n+2] = 1.ma()\n dpF[n+2] = 0.ma()\n for (p in n downTo 1) {\n val half = 1.ma() / 2\n val prob = half*dpT[p+1] + half*half*dpF[p+2]\n dpT[p] = prob\n dpF[p] = prob\n }\n\n println(dpT[1])\n}\n\nclass ModuloArithmetic(private val MOD: Int) {\n fun ofInt(x: Int) = IntMod(x, MOD)\n}\n\nclass IntMod(n: Int, private val MOD: Int) {\n val i = n % MOD\n\n fun ofInt(x: Int) = IntMod(x, MOD)\n fun ofLong(x: Long) = IntMod((x % MOD).toInt(), MOD)\n\n operator fun plus(other: IntMod): IntMod = IntMod(Math.floorMod(i + other.i, MOD), MOD)\n operator fun plus(other: Int): IntMod = this + ofInt(other)\n operator fun plus(other: Long): IntMod = this + ofLong(other)\n\n operator fun minus(other: IntMod): IntMod = IntMod(Math.floorMod(i - other.i, MOD), MOD)\n operator fun minus(other: Int): IntMod = this - ofInt(other)\n operator fun minus(other: Long): IntMod = this - ofLong(other)\n\n operator fun times(other: IntMod): IntMod = IntMod(Math.floorMod(i.toLong() * other.i, MOD.toLong()).toInt(), MOD)\n operator fun times(other: Int): IntMod = this * ofInt(other)\n operator fun times(other: Long): IntMod = this * ofLong(other)\n\n operator fun div(other: IntMod): IntMod = this * other.multiplicativeInverse()\n operator fun div(other: Int): IntMod = this / ofInt(other)\n operator fun div(other: Long): IntMod = this / ofLong(other)\n\n override fun toString(): String = i.toString()\n\n // i^n\n fun pow(n_in: Int): IntMod {\n var x = this\n var y = ofInt(1)\n var n = n_in\n // x^n\n while (n > 0) {\n if (n % 2L != 0L) y *= x\n n /= 2\n x *= x\n }\n return y\n }\n\n private fun multiplicativeInverse(): IntMod = pow(MOD -2)\n}\n", "src_uid": "cec37432956bb0a1ce62a0188fe2d805"} {"source_code": "fun main(args: Array) {\n val n = readLine()!!.toInt()\n for (i in Math.sqrt(n.toDouble()).toInt() downTo 0) {\n val x = n / i\n if (x * i == n) {\n println(\"$i $x\")\n break\n }\n }\n}", "src_uid": "f52af273954798a4ae38a1378bfbf77a"}